blob: c67b9d53bbf556b460149f7ef6cf54d240373307 [file] [log] [blame]
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001/*
2 * (C) 2011-2012,2014 by Holger Hans Peter Freyther <zecke@selfish.org>
3 * (C) 2011-2012,2014 by On-Waves
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#undef _GNU_SOURCE
20#define _GNU_SOURCE
21
Philipp Maier87bd9be2017-08-22 16:35:41 +020022#include <osmocom/mgcp/mgcp.h>
23#include <osmocom/mgcp/vty.h>
Neels Hofmeyr67793542017-09-08 04:25:16 +020024#include <osmocom/mgcp/mgcp_common.h>
Philipp Maier87bd9be2017-08-22 16:35:41 +020025#include <osmocom/mgcp/mgcp_internal.h>
26#include <osmocom/mgcp/mgcp_stat.h>
27#include <osmocom/mgcp/mgcp_msg.h>
Philipp Maier37d11c82018-02-01 14:38:12 +010028#include <osmocom/mgcp/mgcp_endp.h>
Philipp Maierbc0346e2018-06-07 09:52:16 +020029#include <osmocom/mgcp/mgcp_sdp.h>
30#include <osmocom/mgcp/mgcp_codec.h>
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020031
32#include <osmocom/core/application.h>
33#include <osmocom/core/talloc.h>
34#include <osmocom/core/utils.h>
35#include <string.h>
36#include <limits.h>
37#include <dlfcn.h>
38#include <time.h>
39#include <math.h>
Neels Hofmeyrb861db92018-08-28 16:19:25 +020040#include <ctype.h>
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020041
42char *strline_r(char *str, char **saveptr);
43
44const char *strline_test_data =
45 "one CR\r"
46 "two CR\r"
47 "\r"
48 "one CRLF\r\n"
49 "two CRLF\r\n"
Philipp Maier87bd9be2017-08-22 16:35:41 +020050 "\r\n" "one LF\n" "two LF\n" "\n" "mixed (4 lines)\r\r\n\n\r\n";
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020051
52#define EXPECTED_NUMBER_OF_LINES 13
53
54static void test_strline(void)
55{
56 char *save = NULL;
57 char *line;
58 char buf[2048];
59 int counter = 0;
60
61 osmo_strlcpy(buf, strline_test_data, sizeof(buf));
62
Philipp Maier87bd9be2017-08-22 16:35:41 +020063 for (line = mgcp_strline(buf, &save); line;
64 line = mgcp_strline(NULL, &save)) {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020065 printf("line: '%s'\n", line);
66 counter++;
67 }
68
69 OSMO_ASSERT(counter == EXPECTED_NUMBER_OF_LINES);
70}
71
Philipp Maier12943ea2018-01-17 15:40:25 +010072#define AUEP1 "AUEP 158663169 ds/e1-1/2@mgw MGCP 1.0\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020073#define AUEP1_RET "200 158663169 OK\r\n"
Philipp Maier12943ea2018-01-17 15:40:25 +010074#define AUEP2 "AUEP 18983213 ds/e1-2/1@mgw MGCP 1.0\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020075#define AUEP2_RET "500 18983213 FAIL\r\n"
76#define EMPTY "\r\n"
77#define EMPTY_RET NULL
78#define SHORT "CRCX \r\n"
79#define SHORT_RET "510 000000 FAIL\r\n"
80
Philipp Maier12943ea2018-01-17 15:40:25 +010081#define MDCX_WRONG_EP "MDCX 18983213 ds/e1-3/1@mgw MGCP 1.0\r\n"
Harald Welteabbb6b92017-12-28 13:13:50 +010082#define MDCX_ERR_RET "500 18983213 FAIL\r\n"
Philipp Maier12943ea2018-01-17 15:40:25 +010083#define MDCX_UNALLOCATED "MDCX 18983214 ds/e1-1/2@mgw MGCP 1.0\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020084#define MDCX_RET "400 18983214 FAIL\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020085
Philipp Maier87bd9be2017-08-22 16:35:41 +020086#define MDCX3 \
87 "MDCX 18983215 1@mgw MGCP 1.0\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +010088 "I: %s\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020089
Philipp Maier87bd9be2017-08-22 16:35:41 +020090#define MDCX3_RET \
91 "200 18983215 OK\r\n" \
Philipp Maierc3cfae22018-01-22 12:03:03 +010092 "\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +020093 "v=0\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +010094 "o=- %s 23 IN IP4 0.0.0.0\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +020095 "s=-\r\n" \
96 "c=IN IP4 0.0.0.0\r\n" \
97 "t=0 0\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +010098 "m=audio 16002 RTP/AVP 97\r\n" \
99 "a=rtpmap:97 GSM-EFR/8000\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200100 "a=ptime:40\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200101
Philipp Maier87bd9be2017-08-22 16:35:41 +0200102#define MDCX3A_RET \
103 "200 18983215 OK\r\n" \
Philipp Maierc3cfae22018-01-22 12:03:03 +0100104 "\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200105 "v=0\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100106 "o=- %s 23 IN IP4 0.0.0.0\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200107 "s=-\r\n" \
108 "c=IN IP4 0.0.0.0\r\n" \
109 "t=0 0\r\n" \
110 "m=audio 16002 RTP/AVP 97\r\n" \
111 "a=rtpmap:97 GSM-EFR/8000\r\n" \
112 "a=ptime:40\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200113
Philipp Maier87bd9be2017-08-22 16:35:41 +0200114#define MDCX3_FMTP_RET \
115 "200 18983215 OK\r\n" \
Philipp Maierc3cfae22018-01-22 12:03:03 +0100116 "\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200117 "v=0\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100118 "o=- %s 23 IN IP4 0.0.0.0\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200119 "s=-\r\n" \
120 "c=IN IP4 0.0.0.0\r\n" \
121 "t=0 0\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100122 "m=audio 16006 RTP/AVP 97\r\n" \
123 "a=rtpmap:97 GSM-EFR/8000\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200124 "a=fmtp:126 0/1/2\r\n" \
125 "a=ptime:40\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200126
Philipp Maier87bd9be2017-08-22 16:35:41 +0200127#define MDCX4 \
128 "MDCX 18983216 1@mgw MGCP 1.0\r\n" \
129 "M: sendrecv\r" \
130 "C: 2\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100131 "I: %s\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200132 "L: p:20, a:AMR, nt:IN\r\n" \
133 "\n" \
134 "v=0\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100135 "o=- %s 23 IN IP4 0.0.0.0\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200136 "c=IN IP4 0.0.0.0\r\n" \
137 "t=0 0\r\n" \
138 "m=audio 4441 RTP/AVP 99\r\n" \
139 "a=rtpmap:99 AMR/8000\r\n" \
140 "a=ptime:40\r\n"
141
142#define MDCX4_RET(Ident) \
143 "200 " Ident " OK\r\n" \
Philipp Maierc3cfae22018-01-22 12:03:03 +0100144 "\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200145 "v=0\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100146 "o=- %s 23 IN IP4 0.0.0.0\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200147 "s=-\r\n" \
148 "c=IN IP4 0.0.0.0\r\n" \
149 "t=0 0\r\n" \
150 "m=audio 16002 RTP/AVP 99\r\n" \
151 "a=rtpmap:99 AMR/8000\r\n" \
152 "a=ptime:40\r\n"
153
154#define MDCX4_RO_RET(Ident) \
155 "200 " Ident " OK\r\n" \
Philipp Maierc3cfae22018-01-22 12:03:03 +0100156 "\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200157 "v=0\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100158 "o=- %s 23 IN IP4 0.0.0.0\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200159 "s=-\r\n" \
160 "c=IN IP4 0.0.0.0\r\n" \
161 "t=0 0\r\n" \
Philipp Maierbc0346e2018-06-07 09:52:16 +0200162 "m=audio 16002 RTP/AVP 112\r\n" \
163 "a=rtpmap:112 AMR\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200164 "a=ptime:40\r\n"
165
166#define MDCX4_PT1 \
167 "MDCX 18983217 1@mgw MGCP 1.0\r\n" \
168 "M: sendrecv\r" \
169 "C: 2\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100170 "I: %s\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200171 "L: p:20-40, a:AMR, nt:IN\r\n" \
172 "\n" \
173 "v=0\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100174 "o=- %s 23 IN IP4 0.0.0.0\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200175 "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"
180
181#define MDCX4_PT2 \
182 "MDCX 18983218 1@mgw MGCP 1.0\r\n" \
183 "M: sendrecv\r" \
184 "C: 2\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100185 "I: %s\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200186 "L: p:20-20, a:AMR, nt:IN\r\n" \
187 "\n" \
188 "v=0\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100189 "o=- %s 23 IN IP4 0.0.0.0\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200190 "c=IN IP4 0.0.0.0\r\n" \
191 "t=0 0\r\n" \
192 "m=audio 4441 RTP/AVP 99\r\n" \
193 "a=rtpmap:99 AMR/8000\r\n" \
194 "a=ptime:40\r\n"
195
196#define MDCX4_PT3 \
197 "MDCX 18983219 1@mgw MGCP 1.0\r\n" \
198 "M: sendrecv\r" \
199 "C: 2\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100200 "I: %s\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200201 "L: a:AMR, nt:IN\r\n" \
202 "\n" \
203 "v=0\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100204 "o=- %s 23 IN IP4 0.0.0.0\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200205 "c=IN IP4 0.0.0.0\r\n" \
206 "t=0 0\r\n" \
207 "m=audio 4441 RTP/AVP 99\r\n" \
208 "a=rtpmap:99 AMR/8000\r\n" \
209 "a=ptime:40\r\n"
210
Pau Espin Pedrolfe9a1fe2019-06-25 16:59:15 +0200211/* Test different upper/lower case in options */
212#define MDCX4_PT4 \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200213 "MDCX 18983220 1@mgw MGCP 1.0\r\n" \
Pau Espin Pedrol0c6c3c12019-06-25 17:18:12 +0200214 "m: sendrecv\r" \
215 "c: 2\r\n" \
216 "i: %s\r\n" \
217 "l: A:AMR, NT:IN\r\n" \
Pau Espin Pedrolfe9a1fe2019-06-25 16:59:15 +0200218 "\n" \
219 "v=0\r\n" \
220 "o=- %s 23 IN IP4 0.0.0.0\r\n" \
221 "c=IN IP4 0.0.0.0\r\n" \
222 "t=0 0\r\n" \
223 "m=audio 4441 RTP/AVP 99\r\n" \
224 "a=rtpmap:99 AMR/8000\r\n" \
225 "a=ptime:40\r\n"
226
227#define MDCX4_SO \
228 "MDCX 18983221 1@mgw MGCP 1.0\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200229 "M: sendonly\r" \
230 "C: 2\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100231 "I: %s\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200232 "L: p:20, a:AMR, nt:IN\r\n" \
233 "\n" \
234 "v=0\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100235 "o=- %s 23 IN IP4 0.0.0.0\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200236 "c=IN IP4 0.0.0.0\r\n" \
237 "t=0 0\r\n" \
238 "m=audio 4441 RTP/AVP 99\r\n" \
239 "a=rtpmap:99 AMR/8000\r\n" \
240 "a=ptime:40\r\n"
241
242#define MDCX4_RO \
Pau Espin Pedrolfe9a1fe2019-06-25 16:59:15 +0200243 "MDCX 18983222 1@mgw MGCP 1.0\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200244 "M: recvonly\r" \
245 "C: 2\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100246 "I: %s\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200247 "L: p:20, a:AMR, nt:IN\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200248
Neels Hofmeyr5336f572018-09-03 22:05:48 +0200249#define MDCX_TOO_LONG_CI \
Pau Espin Pedrolfe9a1fe2019-06-25 16:59:15 +0200250 "MDCX 18983223 1@mgw MGCP 1.0\r\n" \
Neels Hofmeyr5336f572018-09-03 22:05:48 +0200251 "I: 123456789012345678901234567890123\n"
252
Pau Espin Pedrolfe9a1fe2019-06-25 16:59:15 +0200253#define MDCX_TOO_LONG_CI_RET "510 18983223 FAIL\r\n"
Neels Hofmeyr5336f572018-09-03 22:05:48 +0200254
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200255#define SHORT2 "CRCX 1"
256#define SHORT2_RET "510 000000 FAIL\r\n"
257#define SHORT3 "CRCX 1 1@mgw"
258#define SHORT4 "CRCX 1 1@mgw MGCP"
259#define SHORT5 "CRCX 1 1@mgw MGCP 1.0"
260
Philipp Maier87bd9be2017-08-22 16:35:41 +0200261#define CRCX \
262 "CRCX 2 1@mgw MGCP 1.0\r\n" \
Pau Espin Pedrol0c6c3c12019-06-25 17:18:12 +0200263 "m: recvonly\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200264 "C: 2\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200265 "L: p:20\r\n" \
266 "\r\n" \
267 "v=0\r\n" \
268 "c=IN IP4 123.12.12.123\r\n" \
269 "m=audio 5904 RTP/AVP 97\r\n" \
270 "a=rtpmap:97 GSM-EFR/8000\r\n" \
271 "a=ptime:40\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200272
Philipp Maier87bd9be2017-08-22 16:35:41 +0200273#define CRCX_RET \
274 "200 2 OK\r\n" \
Philipp Maierc3cfae22018-01-22 12:03:03 +0100275 "I: %s\r\n" \
276 "\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200277 "v=0\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100278 "o=- %s 23 IN IP4 0.0.0.0\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200279 "s=-\r\n" \
280 "c=IN IP4 0.0.0.0\r\n" \
281 "t=0 0\r\n" \
282 "m=audio 16002 RTP/AVP 97\r\n" \
283 "a=rtpmap:97 GSM-EFR/8000\r\n" \
284 "a=ptime:40\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200285
Philipp Maier87bd9be2017-08-22 16:35:41 +0200286#define CRCX_RET_NO_RTPMAP \
287 "200 2 OK\r\n" \
Philipp Maierc3cfae22018-01-22 12:03:03 +0100288 "I: %s\r\n" \
289 "\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200290 "v=0\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100291 "o=- %s 23 IN IP4 0.0.0.0\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200292 "s=-\r\n" \
293 "c=IN IP4 0.0.0.0\r\n" \
294 "t=0 0\r\n" \
295 "m=audio 16002 RTP/AVP 97\r\n" \
296 "a=ptime:40\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200297
Philipp Maier87bd9be2017-08-22 16:35:41 +0200298#define CRCX_FMTP_RET \
299 "200 2 OK\r\n" \
Philipp Maierc3cfae22018-01-22 12:03:03 +0100300 "I: %s\r\n" \
301 "\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200302 "v=0\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100303 "o=- %s 23 IN IP4 0.0.0.0\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200304 "s=-\r\n" \
305 "c=IN IP4 0.0.0.0\r\n" \
306 "t=0 0\r\n" \
307 "m=audio 16006 RTP/AVP 97\r\n" \
308 "a=rtpmap:97 GSM-EFR/8000\r\n" \
309 "a=fmtp:126 0/1/2\r\n" \
310 "a=ptime:40\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200311
Philipp Maier87bd9be2017-08-22 16:35:41 +0200312#define CRCX_ZYN \
313 "CRCX 2 1@mgw MGCP 1.0\r" \
314 "M: recvonly\r" \
315 "C: 2\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200316 "\n" \
317 "v=0\r" \
318 "c=IN IP4 123.12.12.123\r" \
319 "m=audio 5904 RTP/AVP 97\r" \
320 "a=rtpmap:97 GSM-EFR/8000\r"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200321
Philipp Maier87bd9be2017-08-22 16:35:41 +0200322#define CRCX_ZYN_RET \
323 "200 2 OK\r\n" \
Philipp Maierc3cfae22018-01-22 12:03:03 +0100324 "I: %s\r\n" \
325 "\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200326 "v=0\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100327 "o=- %s 23 IN IP4 0.0.0.0\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200328 "s=-\r\n" \
329 "c=IN IP4 0.0.0.0\r\n" \
330 "t=0 0\r\n" \
331 "m=audio 16004 RTP/AVP 97\r\n" \
332 "a=rtpmap:97 GSM-EFR/8000\r\n" \
333 "a=ptime:20\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200334
Neels Hofmeyre6d8e912018-08-23 16:36:48 +0200335#define CRCX_X_OSMO_IGN \
336 "CRCX 2 1@mgw MGCP 1.0\r\n" \
337 "M: recvonly\r\n" \
338 "C: 2\r\n" \
339 "L: p:20\r\n" \
Neels Hofmeyrf2388ea2018-08-26 23:36:53 +0200340 "X-Osmo-IGN: C foo\r\n" \
Neels Hofmeyre6d8e912018-08-23 16:36:48 +0200341 "\r\n" \
342 "v=0\r\n" \
343 "c=IN IP4 123.12.12.123\r\n" \
344 "m=audio 5904 RTP/AVP 97\r\n" \
345 "a=rtpmap:97 GSM-EFR/8000\r\n" \
346 "a=ptime:40\r\n"
347
348#define CRCX_X_OSMO_IGN_RET \
349 "200 2 OK\r\n" \
350 "I: %s\r\n" \
351 "\r\n" \
352 "v=0\r\n" \
353 "o=- %s 23 IN IP4 0.0.0.0\r\n" \
354 "s=-\r\n" \
355 "c=IN IP4 0.0.0.0\r\n" \
356 "t=0 0\r\n" \
357 "m=audio 16010 RTP/AVP 97\r\n" \
358 "a=rtpmap:97 GSM-EFR/8000\r\n" \
359 "a=ptime:40\r\n"
360
Philipp Maier87bd9be2017-08-22 16:35:41 +0200361#define DLCX \
362 "DLCX 7 1@mgw MGCP 1.0\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100363 "I: %s\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200364 "C: 2\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200365
Philipp Maier87bd9be2017-08-22 16:35:41 +0200366#define DLCX_RET \
367 "250 7 OK\r\n" \
Pau Espin Pedrol2da99a22018-02-20 13:11:17 +0100368 "P: PS=0, OS=0, PR=0, OR=0, PL=0, JI=0\r\n"
369
370 #define DLCX_RET_OSMUX DLCX_RET \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200371 "X-Osmo-CP: EC TI=0, TO=0\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200372
Philipp Maier87bd9be2017-08-22 16:35:41 +0200373#define RQNT \
374 "RQNT 186908780 1@mgw MGCP 1.0\r\n" \
375 "X: B244F267488\r\n" \
376 "S: D/9\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200377
Philipp Maier87bd9be2017-08-22 16:35:41 +0200378#define RQNT2 \
379 "RQNT 186908781 1@mgw MGCP 1.0\r\n" \
380 "X: ADD4F26746F\r\n" \
381 "R: D/[0-9#*](N), G/ft, fxr/t38\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200382
383#define RQNT1_RET "200 186908780 OK\r\n"
384#define RQNT2_RET "200 186908781 OK\r\n"
385
Philipp Maier87bd9be2017-08-22 16:35:41 +0200386#define PTYPE_IGNORE 0 /* == default initializer */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200387#define PTYPE_NONE 128
388#define PTYPE_NYI PTYPE_NONE
389
Philipp Maier87bd9be2017-08-22 16:35:41 +0200390#define CRCX_MULT_1 \
391 "CRCX 2 1@mgw MGCP 1.0\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200392 "M: recvonly\r\n" \
393 "C: 2\r\n" \
394 "X\r\n" \
395 "L: p:20\r\n" \
396 "\r\n" \
397 "v=0\r\n" \
398 "c=IN IP4 123.12.12.123\r\n" \
399 "m=audio 5904 RTP/AVP 18 97\r\n" \
400 "a=rtpmap:18 G729/8000\r\n" \
401 "a=rtpmap:97 GSM-EFR/8000\r\n" \
402 "a=ptime:40\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200403
Philipp Maier87bd9be2017-08-22 16:35:41 +0200404#define CRCX_MULT_2 \
405 "CRCX 2 2@mgw MGCP 1.0\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200406 "M: recvonly\r\n" \
407 "C: 2\r\n" \
408 "X\r\n" \
409 "L: p:20\r\n" \
410 "\r\n" \
411 "v=0\r\n" \
412 "c=IN IP4 123.12.12.123\r\n" \
413 "m=audio 5904 RTP/AVP 18 97 101\r\n" \
414 "a=rtpmap:18 G729/8000\r\n" \
415 "a=rtpmap:97 GSM-EFR/8000\r\n" \
416 "a=rtpmap:101 FOO/8000\r\n" \
417 "a=ptime:40\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200418
Philipp Maier87bd9be2017-08-22 16:35:41 +0200419#define CRCX_MULT_3 \
420 "CRCX 2 3@mgw MGCP 1.0\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200421 "M: recvonly\r\n" \
422 "C: 2\r\n" \
423 "X\r\n" \
424 "L: p:20\r\n" \
425 "\r\n" \
426 "v=0\r\n" \
427 "c=IN IP4 123.12.12.123\r\n" \
428 "m=audio 5904 RTP/AVP\r\n" \
429 "a=rtpmap:18 G729/8000\r\n" \
430 "a=rtpmap:97 GSM-EFR/8000\r\n" \
431 "a=rtpmap:101 FOO/8000\r\n" \
432 "a=ptime:40\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200433
Philipp Maier87bd9be2017-08-22 16:35:41 +0200434#define CRCX_MULT_4 \
435 "CRCX 2 4@mgw MGCP 1.0\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200436 "M: recvonly\r\n" \
437 "C: 2\r\n" \
438 "X\r\n" \
439 "L: p:20\r\n" \
440 "\r\n" \
441 "v=0\r\n" \
442 "c=IN IP4 123.12.12.123\r\n" \
443 "m=audio 5904 RTP/AVP 18\r\n" \
444 "a=rtpmap:18 G729/8000\r\n" \
445 "a=rtpmap:97 GSM-EFR/8000\r\n" \
446 "a=rtpmap:101 FOO/8000\r\n" \
447 "a=ptime:40\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200448
449#define CRCX_MULT_GSM_EXACT \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200450 "CRCX 259260421 5@mgw MGCP 1.0\r\n" \
451 "C: 1355c6041e\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200452 "L: p:20, a:GSM, nt:IN\r\n" \
453 "M: recvonly\r\n" \
454 "\r\n" \
455 "v=0\r\n" \
456 "o=- 1439038275 1439038275 IN IP4 192.168.181.247\r\n" \
457 "s=-\r\nc=IN IP4 192.168.181.247\r\n" \
Philipp Maierbc0346e2018-06-07 09:52:16 +0200458 "t=0 0\r\nm=audio 29084 RTP/AVP 0 8 3 18 4 96 97 101\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200459 "a=rtpmap:0 PCMU/8000\r\n" \
460 "a=rtpmap:8 PCMA/8000\r\n" \
461 "a=rtpmap:3 gsm/8000\r\n" \
462 "a=rtpmap:18 G729/8000\r\n" \
463 "a=fmtp:18 annexb=no\r\n" \
464 "a=rtpmap:4 G723/8000\r\n" \
465 "a=rtpmap:96 iLBC/8000\r\n" \
466 "a=fmtp:96 mode=20\r\n" \
467 "a=rtpmap:97 iLBC/8000\r\n" \
468 "a=fmtp:97 mode=30\r\n" \
469 "a=rtpmap:101 telephone-event/8000\r\n" \
470 "a=fmtp:101 0-15\r\n" \
471 "a=recvonly\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200472
Philipp Maier87bd9be2017-08-22 16:35:41 +0200473#define MDCX_NAT_DUMMY \
474 "MDCX 23 5@mgw MGCP 1.0\r\n" \
475 "C: 1355c6041e\r\n" \
Philipp Maierffd75e42017-11-22 11:44:50 +0100476 "I: %s\r\n" \
Philipp Maier87bd9be2017-08-22 16:35:41 +0200477 "\r\n" \
478 "c=IN IP4 8.8.8.8\r\n" \
Philipp Maierbc0346e2018-06-07 09:52:16 +0200479 "m=audio 16434 RTP/AVP 3\r\n"
480
481#define CRCX_NO_LCO_NO_SDP \
482 "CRCX 2 6@mgw MGCP 1.0\r\n" \
483 "M: recvonly\r\n" \
484 "C: 2\r\n"
485
Philipp Maier228e5912019-03-05 13:56:59 +0100486#define CRCX_AMR_WITH_FMTP \
487 "CRCX 2 7@mgw MGCP 1.0\r\n" \
488 "M: recvonly\r\n" \
489 "C: 2\r\n" \
490 "X\r\n" \
491 "L: p:20\r\n" \
492 "\r\n" \
493 "v=0\r\n" \
494 "c=IN IP4 123.12.12.123\r\n" \
495 "m=audio 5904 RTP/AVP 111\r\n" \
496 "a=rtpmap:111 AMR/8000/1\r\n" \
497 "a=ptime:20\r\n" \
498 "a=fmtp:111 mode-change-capability=2; octet-align=1\r\n" \
499
500#define CRCX_AMR_WITH_FMTP_RET \
501 "200 2 OK\r\n" \
502 "I: %s\r\n" \
503 "\r\n" \
504 "v=0\r\n" \
505 "o=- %s 23 IN IP4 0.0.0.0\r\n" \
506 "s=-\r\n" \
507 "c=IN IP4 0.0.0.0\r\n" \
508 "t=0 0\r\n" \
509 "m=audio 16012 RTP/AVP 111\r\n" \
510 "a=rtpmap:111 AMR/8000/1\r\n" \
511 "a=fmtp:111 octet-align=1\r\n" \
512 "a=ptime:20\r\n"
513
Philipp Maierbc0346e2018-06-07 09:52:16 +0200514#define CRCX_NO_LCO_NO_SDP_RET \
515 "200 2 OK\r\n" \
516 "I: %s\r\n" \
517 "\r\n" \
518 "v=0\r\n" \
519 "o=- %s 23 IN IP4 0.0.0.0\r\n" \
520 "s=-\r\n" \
521 "c=IN IP4 0.0.0.0\r\n" \
522 "t=0 0\r\n" \
523 "m=audio 16008 RTP/AVP 0\r\n" \
524 "a=ptime:20\r\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200525
526struct mgcp_test {
527 const char *name;
528 const char *req;
529 const char *exp_resp;
Philipp Maier87bd9be2017-08-22 16:35:41 +0200530 int ptype;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200531 const char *extra_fmtp;
532};
533
534static const struct mgcp_test tests[] = {
Philipp Maier87bd9be2017-08-22 16:35:41 +0200535 {"AUEP1", AUEP1, AUEP1_RET},
536 {"AUEP2", AUEP2, AUEP2_RET},
537 {"MDCX1", MDCX_WRONG_EP, MDCX_ERR_RET},
538 {"MDCX2", MDCX_UNALLOCATED, MDCX_RET},
539 {"CRCX", CRCX, CRCX_RET, 97},
540 {"MDCX3", MDCX3, MDCX3_RET, PTYPE_IGNORE},
541 {"MDCX4", MDCX4, MDCX4_RET("18983216"), 99},
542 {"MDCX4_PT1", MDCX4_PT1, MDCX4_RET("18983217"), 99},
543 {"MDCX4_PT2", MDCX4_PT2, MDCX4_RET("18983218"), 99},
544 {"MDCX4_PT3", MDCX4_PT3, MDCX4_RET("18983219"), 99},
Pau Espin Pedrolfe9a1fe2019-06-25 16:59:15 +0200545 {"MDCX4_PT4", MDCX4_PT4, MDCX4_RET("18983220"), 99},
546 {"MDCX4_SO", MDCX4_SO, MDCX4_RET("18983221"), 99},
547 {"MDCX4_RO", MDCX4_RO, MDCX4_RO_RET("18983222"), PTYPE_IGNORE},
Philipp Maier87bd9be2017-08-22 16:35:41 +0200548 {"DLCX", DLCX, DLCX_RET, PTYPE_IGNORE},
549 {"CRCX_ZYN", CRCX_ZYN, CRCX_ZYN_RET, 97},
550 {"EMPTY", EMPTY, EMPTY_RET},
551 {"SHORT1", SHORT, SHORT_RET},
552 {"SHORT2", SHORT2, SHORT2_RET},
553 {"SHORT3", SHORT3, SHORT2_RET},
554 {"SHORT4", SHORT4, SHORT2_RET},
555 {"RQNT1", RQNT, RQNT1_RET},
556 {"RQNT2", RQNT2, RQNT2_RET},
557 {"DLCX", DLCX, DLCX_RET, PTYPE_IGNORE},
558 {"CRCX", CRCX, CRCX_FMTP_RET, 97,.extra_fmtp = "a=fmtp:126 0/1/2"},
559 {"MDCX3", MDCX3, MDCX3_FMTP_RET, PTYPE_NONE,.extra_fmtp =
560 "a=fmtp:126 0/1/2"},
561 {"DLCX", DLCX, DLCX_RET, PTYPE_IGNORE,.extra_fmtp = "a=fmtp:126 0/1/2"},
Philipp Maierbc0346e2018-06-07 09:52:16 +0200562 {"CRCX", CRCX_NO_LCO_NO_SDP, CRCX_NO_LCO_NO_SDP_RET, 97},
Neels Hofmeyre6d8e912018-08-23 16:36:48 +0200563 {"CRCX", CRCX_X_OSMO_IGN, CRCX_X_OSMO_IGN_RET, 97},
Neels Hofmeyr5336f572018-09-03 22:05:48 +0200564 {"MDCX_TOO_LONG_CI", MDCX_TOO_LONG_CI, MDCX_TOO_LONG_CI_RET},
Philipp Maier228e5912019-03-05 13:56:59 +0100565 {"CRCX", CRCX_AMR_WITH_FMTP, CRCX_AMR_WITH_FMTP_RET},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200566};
567
568static const struct mgcp_test retransmit[] = {
Philipp Maier87bd9be2017-08-22 16:35:41 +0200569 {"CRCX", CRCX, CRCX_RET},
570 {"RQNT1", RQNT, RQNT1_RET},
571 {"RQNT2", RQNT2, RQNT2_RET},
572 {"MDCX3", MDCX3, MDCX3A_RET},
573 {"DLCX", DLCX, DLCX_RET},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200574};
575
Philipp Maierffd75e42017-11-22 11:44:50 +0100576static struct msgb *create_msg(const char *str, const char *conn_id)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200577{
578 struct msgb *msg;
Philipp Maierffd75e42017-11-22 11:44:50 +0100579 int len;
580
581 printf("creating message from statically defined input:\n");
582 printf("---------8<---------\n%s\n---------8<---------\n", str);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200583
584 msg = msgb_alloc_headroom(4096, 128, "MGCP msg");
Philipp Maierffd75e42017-11-22 11:44:50 +0100585 if (conn_id && strlen(conn_id))
586 len = sprintf((char *)msg->data, str, conn_id, conn_id);
587 else
588 len = sprintf((char *)msg->data, "%s", str);
589
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200590 msg->l2h = msgb_put(msg, len);
591 return msg;
592}
593
594static int last_endpoint = -1;
595
596static int mgcp_test_policy_cb(struct mgcp_trunk_config *cfg, int endpoint,
597 int state, const char *transactio_id)
598{
Pau Espin Pedrol9ecceb62018-10-16 15:35:58 +0200599 fprintf(stderr, "Policy CB got state %d on endpoint 0x%x\n",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200600 state, endpoint);
601 last_endpoint = endpoint;
602 return MGCP_POLICY_CONT;
603}
604
605#define MGCP_DUMMY_LOAD 0x23
606static int dummy_packets = 0;
607/* override and forward */
608ssize_t sendto(int sockfd, const void *buf, size_t len, int flags,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200609 const struct sockaddr *dest_addr, socklen_t addrlen)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200610{
Philipp Maier87bd9be2017-08-22 16:35:41 +0200611 uint32_t dest_host =
612 htonl(((struct sockaddr_in *)dest_addr)->sin_addr.s_addr);
613 int dest_port = htons(((struct sockaddr_in *)dest_addr)->sin_port);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200614
Philipp Maier87bd9be2017-08-22 16:35:41 +0200615 if (len == 1 && ((const char *)buf)[0] == MGCP_DUMMY_LOAD) {
616 fprintf(stderr,
617 "Dummy packet to 0x%08x:%d, msg length %zu\n%s\n\n",
618 dest_host, dest_port, len, osmo_hexdump(buf, len));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200619 dummy_packets += 1;
620 }
621
Philipp Maier3d9b6562017-10-13 18:33:44 +0200622 return len;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200623}
624
625static int64_t force_monotonic_time_us = -1;
626/* override and forward */
627int clock_gettime(clockid_t clk_id, struct timespec *tp)
628{
629 typedef int (*clock_gettime_t)(clockid_t clk_id, struct timespec *tp);
630 static clock_gettime_t real_clock_gettime = NULL;
631
632 if (!real_clock_gettime)
633 real_clock_gettime = dlsym(RTLD_NEXT, "clock_gettime");
634
635 if (clk_id == CLOCK_MONOTONIC && force_monotonic_time_us >= 0) {
636 tp->tv_sec = force_monotonic_time_us / 1000000;
637 tp->tv_nsec = (force_monotonic_time_us % 1000000) * 1000;
638 return 0;
639 }
640
641 return real_clock_gettime(clk_id, tp);
642}
643
644#define CONN_UNMODIFIED (0x1000)
645
646static void test_values(void)
647{
648 /* Check that NONE disables all output */
Philipp Maier87bd9be2017-08-22 16:35:41 +0200649 OSMO_ASSERT((MGCP_CONN_NONE & MGCP_CONN_RECV_SEND) == 0);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200650
651 /* Check that LOOPBACK enables all output */
652 OSMO_ASSERT((MGCP_CONN_LOOPBACK & MGCP_CONN_RECV_SEND) ==
Philipp Maier87bd9be2017-08-22 16:35:41 +0200653 MGCP_CONN_RECV_SEND);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200654}
655
Neels Hofmeyre28b6732018-08-28 16:19:25 +0200656/* Extract a connection ID from a response and return in conn_id;
657 * if there is none, return -EINVAL and leave conn_id unchanged. */
Philipp Maierffd75e42017-11-22 11:44:50 +0100658static int get_conn_id_from_response(uint8_t *resp, char *conn_id,
Neels Hofmeyre28b6732018-08-28 16:19:25 +0200659 size_t conn_id_buflen)
Philipp Maierffd75e42017-11-22 11:44:50 +0100660{
Neels Hofmeyre28b6732018-08-28 16:19:25 +0200661 const char *conn_id_start;
662 const char *conn_id_end;
663 int conn_id_len;
Philipp Maierffd75e42017-11-22 11:44:50 +0100664
Neels Hofmeyre28b6732018-08-28 16:19:25 +0200665 const char *header_I = "\r\nI: ";
666 const char *header_o = "\r\no=- ";
Philipp Maierffd75e42017-11-22 11:44:50 +0100667
Neels Hofmeyre28b6732018-08-28 16:19:25 +0200668 /* Try to get the conn_id from the 'I:' or 'o=-' parameter */
669 if ((conn_id_start = strstr((char *)resp, header_I))) {
670 conn_id_start += strlen(header_I);
671 conn_id_end = strstr(conn_id_start, "\r\n");
672 } else if ((conn_id_start = strstr((char *)resp, header_o))) {
673 conn_id_start += strlen(header_o);
674 conn_id_end = strchr(conn_id_start, ' ');
675 } else
676 return -EINVAL;
Philipp Maierffd75e42017-11-22 11:44:50 +0100677
Neels Hofmeyre28b6732018-08-28 16:19:25 +0200678 if (conn_id_end)
679 conn_id_len = conn_id_end - conn_id_start;
680 else
681 conn_id_len = strlen(conn_id_start);
682 OSMO_ASSERT(conn_id_len <= conn_id_buflen - 1);
Philipp Maier55295f72018-01-15 14:00:28 +0100683
Neels Hofmeyre28b6732018-08-28 16:19:25 +0200684 /* A valid conn_id must at least contain one digit, and must
685 * not exceed a length of 32 digits */
686 OSMO_ASSERT(conn_id_len <= 32);
687 OSMO_ASSERT(conn_id_len > 0);
688
689 strncpy(conn_id, conn_id_start, conn_id_len);
690 conn_id[conn_id_len] = '\0';
691 return 0;
Philipp Maierffd75e42017-11-22 11:44:50 +0100692}
693
694/* Check response, automatically patch connection ID if needed */
695static int check_response(uint8_t *resp, const char *exp_resp)
696{
697 char exp_resp_patched[4096];
698 const char *exp_resp_ptr;
699 char conn_id[256];
700
701 printf("checking response:\n");
702
703 /* If the expected response is intened to be patched
704 * (%s placeholder inside) we will patch it with the
705 * connection identifier we just received from the
706 * real response. This is necessary because the CI
707 * is generated by the mgcp code on CRCX and we can
708 * not know it in advance */
709 if (strstr(exp_resp, "%s")) {
710 if (get_conn_id_from_response(resp, conn_id, sizeof(conn_id)) ==
711 0) {
712 sprintf(exp_resp_patched, exp_resp, conn_id, conn_id);
713 exp_resp_ptr = exp_resp_patched;
714 printf
715 ("using message with patched conn_id for comparison\n");
716 } else {
717 printf
718 ("patching conn_id failed, using message as statically defined for comparison\n");
719 exp_resp_ptr = exp_resp;
720 }
721 } else {
722 printf("using message as statically defined for comparison\n");
723 exp_resp_ptr = exp_resp;
724 }
725
726 if (strcmp((char *)resp, exp_resp_ptr) != 0) {
727 printf("Unexpected response, please check!\n");
728 printf
729 ("Got:\n---------8<---------\n%s\n---------8<---------\n\n",
730 resp);
731 printf
732 ("Expected:\n---------8<---------\n%s\n---------8<---------\n",
733 exp_resp_ptr);
734 return -EINVAL;
735 }
736
737 printf("Response matches our expectations.\n");
738 return 0;
739}
740
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200741static void test_messages(void)
742{
743 struct mgcp_config *cfg;
744 struct mgcp_endpoint *endp;
745 int i;
Philipp Maier87bd9be2017-08-22 16:35:41 +0200746 struct mgcp_conn_rtp *conn = NULL;
Philipp Maierffd75e42017-11-22 11:44:50 +0100747 char last_conn_id[256];
Philipp Maier7df419b2017-12-04 17:11:42 +0100748 int rc;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200749
750 cfg = mgcp_config_alloc();
751
Philipp Maierfcd06552017-11-10 17:32:22 +0100752 cfg->trunk.vty_number_endpoints = 64;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200753 mgcp_endpoints_allocate(&cfg->trunk);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200754 cfg->policy_cb = mgcp_test_policy_cb;
755
Philipp Maierffd75e42017-11-22 11:44:50 +0100756 memset(last_conn_id, 0, sizeof(last_conn_id));
757
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200758 mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1));
759
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200760 for (i = 0; i < ARRAY_SIZE(tests); i++) {
761 const struct mgcp_test *t = &tests[i];
762 struct msgb *inp;
763 struct msgb *msg;
764
Philipp Maierffd75e42017-11-22 11:44:50 +0100765 printf("\n================================================\n");
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200766 printf("Testing %s\n", t->name);
767
768 last_endpoint = -1;
769 dummy_packets = 0;
770
Philipp Maier87bd9be2017-08-22 16:35:41 +0200771 osmo_talloc_replace_string(cfg, &cfg->trunk.audio_fmtp_extra,
772 t->extra_fmtp);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200773
Philipp Maierffd75e42017-11-22 11:44:50 +0100774 inp = create_msg(t->req, last_conn_id);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200775 msg = mgcp_handle_message(cfg, inp);
776 msgb_free(inp);
777 if (!t->exp_resp) {
Philipp Maier87bd9be2017-08-22 16:35:41 +0200778 if (msg) {
779 printf("%s failed '%s'\n", t->name,
780 (char *)msg->data);
781 OSMO_ASSERT(false);
782 }
Philipp Maierffd75e42017-11-22 11:44:50 +0100783 } else if (check_response(msg->data, t->exp_resp) != 0) {
784 printf("%s failed.\n", t->name);
Philipp Maier87bd9be2017-08-22 16:35:41 +0200785 OSMO_ASSERT(false);
786 }
Philipp Maierffd75e42017-11-22 11:44:50 +0100787
Philipp Maier7df419b2017-12-04 17:11:42 +0100788 if (msg) {
789 rc = get_conn_id_from_response(msg->data, last_conn_id,
790 sizeof(last_conn_id));
Neels Hofmeyr08e07042018-08-28 16:22:14 +0200791 if (rc == 0)
Philipp Maier7df419b2017-12-04 17:11:42 +0100792 printf("(response contains a connection id)\n");
793 else
794 printf("(response does not contain a connection id)\n");
795 }
Philipp Maierffd75e42017-11-22 11:44:50 +0100796
Philipp Maiera330b862017-12-04 17:16:16 +0100797 if (msg)
798 msgb_free(msg);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200799
800 if (dummy_packets)
801 printf("Dummy packets: %d\n", dummy_packets);
802
803 if (last_endpoint != -1) {
804 endp = &cfg->trunk.endpoints[last_endpoint];
805
Philipp Maier01d24a32017-11-21 17:26:09 +0100806 conn = mgcp_conn_get_rtp(endp, "1");
Philipp Maier87bd9be2017-08-22 16:35:41 +0200807 if (conn) {
808 OSMO_ASSERT(conn);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200809
Philipp Maier87bd9be2017-08-22 16:35:41 +0200810 if (conn->end.packet_duration_ms != -1)
811 printf("Detected packet duration: %d\n",
812 conn->end.packet_duration_ms);
813 else
814 printf("Packet duration not set\n");
815 if (endp->local_options.pkt_period_min ||
816 endp->local_options.pkt_period_max)
817 printf
818 ("Requested packetetization period: "
819 "%d-%d\n",
820 endp->local_options.pkt_period_min,
821 endp->
822 local_options.pkt_period_max);
823 else
824 printf
825 ("Requested packetization period not set\n");
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200826
Philipp Maier87bd9be2017-08-22 16:35:41 +0200827 if ((conn->conn->mode & CONN_UNMODIFIED) == 0) {
828 printf("Connection mode: %d:%s%s%s%s\n",
829 conn->conn->mode,
830 !conn->conn->mode ? " NONE" : "",
831 conn->conn->mode & MGCP_CONN_SEND_ONLY
832 ? " SEND" : "",
833 conn->conn->mode & MGCP_CONN_RECV_ONLY
834 ? " RECV" : "",
835 conn->conn->mode & MGCP_CONN_LOOPBACK
836 & ~MGCP_CONN_RECV_SEND
837 ? " LOOP" : "");
838 fprintf(stderr,
839 "RTP output %sabled, NET output %sabled\n",
840 conn->end.output_enabled
841 ? "en" : "dis",
842 conn->end.output_enabled
843 ? "en" : "dis");
844 } else
845 printf("Connection mode not set\n");
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200846
Philipp Maier87bd9be2017-08-22 16:35:41 +0200847 OSMO_ASSERT(conn->end.output_enabled
848 == (conn->conn->mode & MGCP_CONN_SEND_ONLY ? 1 : 0));
849
850 conn->conn->mode |= CONN_UNMODIFIED;
851
852 }
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200853 endp->local_options.pkt_period_min = 0;
854 endp->local_options.pkt_period_max = 0;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200855 }
856
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200857 /* Check detected payload type */
Philipp Maierffd75e42017-11-22 11:44:50 +0100858 if (conn && t->ptype != PTYPE_IGNORE) {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200859 OSMO_ASSERT(last_endpoint != -1);
860 endp = &cfg->trunk.endpoints[last_endpoint];
861
Pau Espin Pedrol9ecceb62018-10-16 15:35:58 +0200862 fprintf(stderr, "endpoint 0x%x: "
Philipp Maier87bd9be2017-08-22 16:35:41 +0200863 "payload type %d (expected %d)\n",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200864 last_endpoint,
Philipp Maierbc0346e2018-06-07 09:52:16 +0200865 conn->end.codec->payload_type, t->ptype);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200866
Philipp Maier87bd9be2017-08-22 16:35:41 +0200867 if (t->ptype != PTYPE_IGNORE)
Philipp Maierbc0346e2018-06-07 09:52:16 +0200868 OSMO_ASSERT(conn->end.codec->payload_type ==
Philipp Maier87bd9be2017-08-22 16:35:41 +0200869 t->ptype);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200870
871 /* Reset them again for next test */
Philipp Maierbc0346e2018-06-07 09:52:16 +0200872 conn->end.codec->payload_type = PTYPE_NONE;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200873 }
874 }
875
876 talloc_free(cfg);
877}
878
879static void test_retransmission(void)
880{
881 struct mgcp_config *cfg;
882 int i;
Philipp Maierffd75e42017-11-22 11:44:50 +0100883 char last_conn_id[256];
Philipp Maier23b8e292017-12-04 16:48:45 +0100884 int rc;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200885
886 cfg = mgcp_config_alloc();
887
Philipp Maierfcd06552017-11-10 17:32:22 +0100888 cfg->trunk.vty_number_endpoints = 64;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200889 mgcp_endpoints_allocate(&cfg->trunk);
890
Philipp Maierffd75e42017-11-22 11:44:50 +0100891 memset(last_conn_id, 0, sizeof(last_conn_id));
892
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200893 mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1));
894
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200895 for (i = 0; i < ARRAY_SIZE(retransmit); i++) {
896 const struct mgcp_test *t = &retransmit[i];
897 struct msgb *inp;
898 struct msgb *msg;
899
Philipp Maierffd75e42017-11-22 11:44:50 +0100900 printf("\n================================================\n");
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200901 printf("Testing %s\n", t->name);
902
Philipp Maierffd75e42017-11-22 11:44:50 +0100903 inp = create_msg(t->req, last_conn_id);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200904 msg = mgcp_handle_message(cfg, inp);
Philipp Maier87bd9be2017-08-22 16:35:41 +0200905
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200906 msgb_free(inp);
Philipp Maier7cedfd72017-12-04 16:49:12 +0100907 if (msg && check_response(msg->data, t->exp_resp) != 0) {
Philipp Maier87bd9be2017-08-22 16:35:41 +0200908 printf("%s failed '%s'\n", t->name, (char *)msg->data);
909 OSMO_ASSERT(false);
910 }
Philipp Maierffd75e42017-11-22 11:44:50 +0100911
Philipp Maier23b8e292017-12-04 16:48:45 +0100912 if (msg && strcmp(t->name, "CRCX") == 0) {
913 rc = get_conn_id_from_response(msg->data, last_conn_id,
914 sizeof(last_conn_id));
915 OSMO_ASSERT(rc == 0);
916 }
Philipp Maierffd75e42017-11-22 11:44:50 +0100917
Philipp Maier7cedfd72017-12-04 16:49:12 +0100918 if (msg)
919 msgb_free(msg);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200920
921 /* Retransmit... */
922 printf("Re-transmitting %s\n", t->name);
Philipp Maierffd75e42017-11-22 11:44:50 +0100923 inp = create_msg(t->req, last_conn_id);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200924 msg = mgcp_handle_message(cfg, inp);
925 msgb_free(inp);
Philipp Maierffd75e42017-11-22 11:44:50 +0100926 if (check_response(msg->data, t->exp_resp) != 0) {
Philipp Maier87bd9be2017-08-22 16:35:41 +0200927 printf("%s failed '%s'\n", t->name, (char *)msg->data);
928 OSMO_ASSERT(false);
929 }
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200930 msgb_free(msg);
931 }
932
933 talloc_free(cfg);
934}
935
936static int rqnt_cb(struct mgcp_endpoint *endp, char _tone)
937{
938 ptrdiff_t tone = _tone;
Philipp Maier87bd9be2017-08-22 16:35:41 +0200939 endp->cfg->data = (void *)tone;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200940 return 0;
941}
942
943static void test_rqnt_cb(void)
944{
945 struct mgcp_config *cfg;
946 struct msgb *inp, *msg;
Philipp Maierffd75e42017-11-22 11:44:50 +0100947 char conn_id[256];
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200948
949 cfg = mgcp_config_alloc();
950 cfg->rqnt_cb = rqnt_cb;
951
Philipp Maierfcd06552017-11-10 17:32:22 +0100952 cfg->trunk.vty_number_endpoints = 64;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200953 mgcp_endpoints_allocate(&cfg->trunk);
954
955 mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1));
956
Philipp Maierffd75e42017-11-22 11:44:50 +0100957 inp = create_msg(CRCX, NULL);
958 msg = mgcp_handle_message(cfg, inp);
959 OSMO_ASSERT(msg);
960 OSMO_ASSERT(get_conn_id_from_response(msg->data, conn_id,
961 sizeof(conn_id)) == 0);
962 msgb_free(msg);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200963 msgb_free(inp);
964
965 /* send the RQNT and check for the CB */
Philipp Maierffd75e42017-11-22 11:44:50 +0100966 inp = create_msg(RQNT, conn_id);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200967 msg = mgcp_handle_message(cfg, inp);
Philipp Maier87bd9be2017-08-22 16:35:41 +0200968 if (strncmp((const char *)msg->l2h, "200", 3) != 0) {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200969 printf("FAILED: message is not 200. '%s'\n", msg->l2h);
970 abort();
971 }
972
Philipp Maier87bd9be2017-08-22 16:35:41 +0200973 if (cfg->data != (void *)'9') {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200974 printf("FAILED: callback not called: %p\n", cfg->data);
975 abort();
976 }
977
978 msgb_free(msg);
979 msgb_free(inp);
980
Philipp Maierffd75e42017-11-22 11:44:50 +0100981 inp = create_msg(DLCX, conn_id);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200982 msgb_free(mgcp_handle_message(cfg, inp));
983 msgb_free(inp);
984 talloc_free(cfg);
985}
986
987struct pl_test {
Philipp Maier87bd9be2017-08-22 16:35:41 +0200988 int cycles;
989 uint16_t base_seq;
990 uint16_t max_seq;
991 uint32_t packets;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200992
Philipp Maier87bd9be2017-08-22 16:35:41 +0200993 uint32_t expected;
994 int loss;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200995};
996
997static const struct pl_test pl_test_dat[] = {
998 /* basic.. just one package */
Philipp Maier87bd9be2017-08-22 16:35:41 +0200999 {.cycles = 0,.base_seq = 0,.max_seq = 0,.packets = 1,.expected =
1000 1,.loss = 0},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001001 /* some packages and a bit of loss */
Philipp Maier87bd9be2017-08-22 16:35:41 +02001002 {.cycles = 0,.base_seq = 0,.max_seq = 100,.packets = 100,.expected =
1003 101,.loss = 1},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001004 /* wrap around */
Philipp Maier87bd9be2017-08-22 16:35:41 +02001005 {.cycles = 1 << 16,.base_seq = 0xffff,.max_seq = 2,.packets =
1006 4,.expected = 4,.loss = 0},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001007 /* min loss */
Philipp Maier87bd9be2017-08-22 16:35:41 +02001008 {.cycles = 0,.base_seq = 0,.max_seq = 0,.packets = UINT_MAX,.expected =
1009 1,.loss = INT_MIN},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001010 /* max loss, with wrap around on expected max */
Philipp Maier87bd9be2017-08-22 16:35:41 +02001011 {.cycles = INT_MAX,.base_seq = 0,.max_seq = UINT16_MAX,.packets =
1012 0,.expected = ((uint32_t) (INT_MAX) + UINT16_MAX + 1),.loss = INT_MAX},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001013};
1014
1015static void test_packet_loss_calc(void)
1016{
1017 int i;
Philipp Maiercede2a42018-07-03 14:14:21 +02001018 struct mgcp_endpoint endp;
Oliver Smithe36b7752019-01-22 16:31:36 +01001019 struct mgcp_config cfg = {0};
Philipp Maiercede2a42018-07-03 14:14:21 +02001020 struct mgcp_trunk_config trunk;
1021
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001022 printf("Testing packet loss calculation.\n");
1023
Philipp Maiercede2a42018-07-03 14:14:21 +02001024 memset(&endp, 0, sizeof(endp));
1025 memset(&trunk, 0, sizeof(trunk));
1026
Oliver Smithe36b7752019-01-22 16:31:36 +01001027 endp.cfg = &cfg;
Philipp Maiercede2a42018-07-03 14:14:21 +02001028 endp.type = &ep_typeset.rtp;
1029 trunk.vty_number_endpoints = 1;
1030 trunk.endpoints = &endp;
1031 endp.tcfg = &trunk;
1032 INIT_LLIST_HEAD(&endp.conns);
1033
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001034 for (i = 0; i < ARRAY_SIZE(pl_test_dat); ++i) {
1035 uint32_t expected;
1036 int loss;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001037
Philipp Maiercede2a42018-07-03 14:14:21 +02001038 struct mgcp_conn_rtp *conn = NULL;
1039 struct mgcp_conn *_conn = NULL;
1040 struct mgcp_rtp_state *state;
1041 struct rate_ctr *packets_rx;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001042
Philipp Maiercede2a42018-07-03 14:14:21 +02001043 _conn =
1044 mgcp_conn_alloc(NULL, &endp, MGCP_CONN_TYPE_RTP,
1045 "test-connection");
1046 conn = mgcp_conn_get_rtp(&endp, _conn->id);
1047 state = &conn->state;
1048 packets_rx = &conn->rate_ctr_group->ctr[RTP_PACKETS_RX_CTR];
1049
1050 state->stats.initialized = 1;
1051 state->stats.base_seq = pl_test_dat[i].base_seq;
1052 state->stats.max_seq = pl_test_dat[i].max_seq;
1053 state->stats.cycles = pl_test_dat[i].cycles;
1054
1055 packets_rx->current = pl_test_dat[i].packets;
1056 calc_loss(conn, &expected, &loss);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001057
Philipp Maier87bd9be2017-08-22 16:35:41 +02001058 if (loss != pl_test_dat[i].loss
1059 || expected != pl_test_dat[i].expected) {
1060 printf
1061 ("FAIL: Wrong exp/loss at idx(%d) Loss(%d vs. %d) Exp(%u vs. %u)\n",
1062 i, loss, pl_test_dat[i].loss, expected,
1063 pl_test_dat[i].expected);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001064 }
Philipp Maiercede2a42018-07-03 14:14:21 +02001065
1066 mgcp_conn_free_all(&endp);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001067 }
Philipp Maiercede2a42018-07-03 14:14:21 +02001068
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001069}
1070
Philipp Maier87bd9be2017-08-22 16:35:41 +02001071int mgcp_parse_stats(struct msgb *msg, uint32_t *ps, uint32_t *os,
1072 uint32_t *pr, uint32_t *_or, int *loss,
1073 uint32_t *jitter)
1074{
1075 char *line, *save;
1076 int rc;
1077
1078 /* initialize with bad values */
1079 *ps = *os = *pr = *_or = *jitter = UINT_MAX;
1080 *loss = INT_MAX;
1081
1082 line = strtok_r((char *)msg->l2h, "\r\n", &save);
1083 if (!line)
1084 return -1;
1085
1086 /* this can only parse the message that is created above... */
1087 for_each_non_empty_line(line, save) {
1088 switch (line[0]) {
1089 case 'P':
1090 rc = sscanf(line,
1091 "P: PS=%u, OS=%u, PR=%u, OR=%u, PL=%d, JI=%u",
1092 ps, os, pr, _or, loss, jitter);
1093 return rc == 6 ? 0 : -1;
1094 }
1095 }
1096
1097 return -1;
1098}
1099
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001100static void test_mgcp_stats(void)
1101{
1102 printf("Testing stat parsing\n");
1103
1104 uint32_t bps, bos, pr, _or, jitter;
1105 struct msgb *msg;
1106 int loss;
1107 int rc;
1108
Philipp Maierffd75e42017-11-22 11:44:50 +01001109 msg = create_msg(DLCX_RET, NULL);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001110 rc = mgcp_parse_stats(msg, &bps, &bos, &pr, &_or, &loss, &jitter);
1111 printf("Parsing result: %d\n", rc);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001112 if (bps != 0 || bos != 0 || pr != 0 || _or != 0 || loss != 0
1113 || jitter != 0)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001114 printf("FAIL: Parsing failed1.\n");
1115 msgb_free(msg);
1116
Philipp Maier87bd9be2017-08-22 16:35:41 +02001117 msg =
1118 create_msg
Philipp Maierffd75e42017-11-22 11:44:50 +01001119 ("250 7 OK\r\nP: PS=10, OS=20, PR=30, OR=40, PL=-3, JI=40\r\n", NULL);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001120 rc = mgcp_parse_stats(msg, &bps, &bos, &pr, &_or, &loss, &jitter);
1121 printf("Parsing result: %d\n", rc);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001122 if (bps != 10 || bos != 20 || pr != 30 || _or != 40 || loss != -3
1123 || jitter != 40)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001124 printf("FAIL: Parsing failed2.\n");
1125 msgb_free(msg);
1126}
1127
1128struct rtp_packet_info {
1129 float txtime;
1130 int len;
1131 char *data;
1132};
1133
1134struct rtp_packet_info test_rtp_packets1[] = {
1135 /* RTP: SeqNo=0, TS=0 */
1136 {0.000000, 20, "\x80\x62\x00\x00\x00\x00\x00\x00\x11\x22\x33\x44"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001137 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001138 /* RTP: SeqNo=1, TS=160 */
1139 {0.020000, 20, "\x80\x62\x00\x01\x00\x00\x00\xA0\x11\x22\x33\x44"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001140 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001141 /* RTP: SeqNo=2, TS=320 */
1142 {0.040000, 20, "\x80\x62\x00\x02\x00\x00\x01\x40\x11\x22\x33\x44"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001143 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001144 /* Repeat RTP timestamp: */
1145 /* RTP: SeqNo=3, TS=320 */
1146 {0.060000, 20, "\x80\x62\x00\x03\x00\x00\x01\x40\x11\x22\x33\x44"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001147 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001148 /* RTP: SeqNo=4, TS=480 */
1149 {0.080000, 20, "\x80\x62\x00\x04\x00\x00\x01\xE0\x11\x22\x33\x44"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001150 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001151 /* RTP: SeqNo=5, TS=640 */
1152 {0.100000, 20, "\x80\x62\x00\x05\x00\x00\x02\x80\x11\x22\x33\x44"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001153 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001154 /* Double skip RTP timestamp (delta = 2*160): */
1155 /* RTP: SeqNo=6, TS=960 */
1156 {0.120000, 20, "\x80\x62\x00\x06\x00\x00\x03\xC0\x11\x22\x33\x44"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001157 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001158 /* RTP: SeqNo=7, TS=1120 */
1159 {0.140000, 20, "\x80\x62\x00\x07\x00\x00\x04\x60\x11\x22\x33\x44"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001160 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001161 /* RTP: SeqNo=8, TS=1280 */
1162 {0.160000, 20, "\x80\x62\x00\x08\x00\x00\x05\x00\x11\x22\x33\x44"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001163 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001164 /* Non 20ms RTP timestamp (delta = 120): */
1165 /* RTP: SeqNo=9, TS=1400 */
1166 {0.180000, 20, "\x80\x62\x00\x09\x00\x00\x05\x78\x11\x22\x33\x44"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001167 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001168 /* RTP: SeqNo=10, TS=1560 */
1169 {0.200000, 20, "\x80\x62\x00\x0A\x00\x00\x06\x18\x11\x22\x33\x44"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001170 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001171 /* RTP: SeqNo=11, TS=1720 */
1172 {0.220000, 20, "\x80\x62\x00\x0B\x00\x00\x06\xB8\x11\x22\x33\x44"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001173 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001174 /* SSRC changed to 0x10203040, RTP timestamp jump */
1175 /* RTP: SeqNo=12, TS=34688 */
1176 {0.240000, 20, "\x80\x62\x00\x0C\x00\x00\x87\x80\x10\x20\x30\x40"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001177 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001178 /* RTP: SeqNo=13, TS=34848 */
1179 {0.260000, 20, "\x80\x62\x00\x0D\x00\x00\x88\x20\x10\x20\x30\x40"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001180 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001181 /* RTP: SeqNo=14, TS=35008 */
1182 {0.280000, 20, "\x80\x62\x00\x0E\x00\x00\x88\xC0\x10\x20\x30\x40"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001183 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001184 /* Non 20ms RTP timestamp (delta = 120): */
1185 /* RTP: SeqNo=15, TS=35128 */
1186 {0.300000, 20, "\x80\x62\x00\x0F\x00\x00\x89\x38\x10\x20\x30\x40"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001187 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001188 /* RTP: SeqNo=16, TS=35288 */
1189 {0.320000, 20, "\x80\x62\x00\x10\x00\x00\x89\xD8\x10\x20\x30\x40"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001190 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001191 /* RTP: SeqNo=17, TS=35448 */
1192 {0.340000, 20, "\x80\x62\x00\x11\x00\x00\x8A\x78\x10\x20\x30\x40"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001193 "\x01\x23\x45\x67\x8A\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001194 /* SeqNo increment by 2, RTP timestamp delta = 320: */
1195 /* RTP: SeqNo=19, TS=35768 */
1196 {0.360000, 20, "\x80\x62\x00\x13\x00\x00\x8B\xB8\x10\x20\x30\x40"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001197 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001198 /* RTP: SeqNo=20, TS=35928 */
1199 {0.380000, 20, "\x80\x62\x00\x14\x00\x00\x8C\x58\x10\x20\x30\x40"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001200 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001201 /* RTP: SeqNo=21, TS=36088 */
1202 {0.380000, 20, "\x80\x62\x00\x15\x00\x00\x8C\xF8\x10\x20\x30\x40"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001203 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001204 /* Repeat last packet */
1205 /* RTP: SeqNo=21, TS=36088 */
1206 {0.400000, 20, "\x80\x62\x00\x15\x00\x00\x8C\xF8\x10\x20\x30\x40"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001207 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001208 /* RTP: SeqNo=22, TS=36248 */
1209 {0.420000, 20, "\x80\x62\x00\x16\x00\x00\x8D\x98\x10\x20\x30\x40"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001210 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001211 /* RTP: SeqNo=23, TS=36408 */
1212 {0.440000, 20, "\x80\x62\x00\x17\x00\x00\x8E\x38\x10\x20\x30\x40"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001213 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001214 /* Don't increment SeqNo but increment timestamp by 160 */
1215 /* RTP: SeqNo=23, TS=36568 */
1216 {0.460000, 20, "\x80\x62\x00\x17\x00\x00\x8E\xD8\x10\x20\x30\x40"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001217 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001218 /* RTP: SeqNo=24, TS=36728 */
1219 {0.480000, 20, "\x80\x62\x00\x18\x00\x00\x8F\x78\x10\x20\x30\x40"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001220 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001221 /* RTP: SeqNo=25, TS=36888 */
1222 {0.500000, 20, "\x80\x62\x00\x19\x00\x00\x90\x18\x10\x20\x30\x40"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001223 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001224 /* SSRC changed to 0x50607080, RTP timestamp jump, Delay of 1.5s,
1225 * SeqNo jump */
1226 /* RTP: SeqNo=1000, TS=160000 */
1227 {2.000000, 20, "\x80\x62\x03\xE8\x00\x02\x71\x00\x50\x60\x70\x80"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001228 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001229 /* RTP: SeqNo=1001, TS=160160 */
1230 {2.020000, 20, "\x80\x62\x03\xE9\x00\x02\x71\xA0\x50\x60\x70\x80"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001231 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001232 /* RTP: SeqNo=1002, TS=160320 */
1233 {2.040000, 20, "\x80\x62\x03\xEA\x00\x02\x72\x40\x50\x60\x70\x80"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001234 "\x01\x23\x45\x67\x89\xAB\xCD\xEF"},
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001235};
1236
Philipp Maier87bd9be2017-08-22 16:35:41 +02001237void mgcp_patch_and_count(struct mgcp_endpoint *endp,
1238 struct mgcp_rtp_state *state,
1239 struct mgcp_rtp_end *rtp_end,
1240 struct sockaddr_in *addr, char *data, int len);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001241
1242static void test_packet_error_detection(int patch_ssrc, int patch_ts)
1243{
1244 int i;
1245
1246 struct mgcp_trunk_config trunk;
1247 struct mgcp_endpoint endp;
Oliver Smithe36b7752019-01-22 16:31:36 +01001248 struct mgcp_config cfg = {0};
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001249 struct mgcp_rtp_state state;
Philipp Maier87bd9be2017-08-22 16:35:41 +02001250 struct mgcp_rtp_end *rtp;
1251 struct sockaddr_in addr = { 0 };
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001252 char buffer[4096];
1253 uint32_t last_ssrc = 0;
1254 uint32_t last_timestamp = 0;
1255 uint32_t last_seqno = 0;
Philipp Maier9e1d1642018-05-09 16:26:34 +02001256 uint64_t last_in_ts_err_cnt = 0;
1257 uint64_t last_out_ts_err_cnt = 0;
Philipp Maier87bd9be2017-08-22 16:35:41 +02001258 struct mgcp_conn_rtp *conn = NULL;
Philipp Maierffd75e42017-11-22 11:44:50 +01001259 struct mgcp_conn *_conn = NULL;
Philipp Maier9e1d1642018-05-09 16:26:34 +02001260 struct rate_ctr test_ctr_in;
1261 struct rate_ctr test_ctr_out;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001262
1263 printf("Testing packet error detection%s%s.\n",
1264 patch_ssrc ? ", patch SSRC" : "",
1265 patch_ts ? ", patch timestamps" : "");
1266
1267 memset(&trunk, 0, sizeof(trunk));
1268 memset(&endp, 0, sizeof(endp));
1269 memset(&state, 0, sizeof(state));
1270
Philipp Maier9e1d1642018-05-09 16:26:34 +02001271 memset(&test_ctr_in, 0, sizeof(test_ctr_in));
1272 memset(&test_ctr_out, 0, sizeof(test_ctr_out));
1273 state.in_stream.err_ts_ctr = &test_ctr_in;
1274 state.out_stream.err_ts_ctr = &test_ctr_out;
1275
Oliver Smithe36b7752019-01-22 16:31:36 +01001276 endp.cfg = &cfg;
Philipp Maier87bd9be2017-08-22 16:35:41 +02001277 endp.type = &ep_typeset.rtp;
1278
Philipp Maierfcd06552017-11-10 17:32:22 +01001279 trunk.vty_number_endpoints = 1;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001280 trunk.endpoints = &endp;
1281 trunk.force_constant_ssrc = patch_ssrc;
1282 trunk.force_aligned_timing = patch_ts;
1283
1284 endp.tcfg = &trunk;
1285
Philipp Maier87bd9be2017-08-22 16:35:41 +02001286 INIT_LLIST_HEAD(&endp.conns);
Philipp Maierffd75e42017-11-22 11:44:50 +01001287 _conn = mgcp_conn_alloc(NULL, &endp, MGCP_CONN_TYPE_RTP,
1288 "test-connection");
1289 OSMO_ASSERT(_conn);
1290 conn = mgcp_conn_get_rtp(&endp, _conn->id);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001291 OSMO_ASSERT(conn);
1292
1293 rtp = &conn->end;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001294
Philipp Maier228e5912019-03-05 13:56:59 +01001295 OSMO_ASSERT(mgcp_codec_add(conn, PTYPE_UNDEFINED, "AMR/8000/1", NULL) == 0);
Philipp Maierbc0346e2018-06-07 09:52:16 +02001296 rtp->codec = &rtp->codecs[0];
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001297
1298 for (i = 0; i < ARRAY_SIZE(test_rtp_packets1); ++i) {
1299 struct rtp_packet_info *info = test_rtp_packets1 + i;
1300
1301 force_monotonic_time_us = round(1000000.0 * info->txtime);
1302
1303 OSMO_ASSERT(info->len <= sizeof(buffer));
1304 OSMO_ASSERT(info->len >= 0);
1305 memmove(buffer, info->data, info->len);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001306 mgcp_rtp_end_config(&endp, 1, rtp);
1307
1308 mgcp_patch_and_count(&endp, &state, rtp, &addr,
1309 buffer, info->len);
1310
1311 if (state.out_stream.ssrc != last_ssrc) {
1312 printf("Output SSRC changed to %08x\n",
1313 state.out_stream.ssrc);
1314 last_ssrc = state.out_stream.ssrc;
1315 }
1316
1317 printf("In TS: %d, dTS: %d, Seq: %d\n",
1318 state.in_stream.last_timestamp,
Philipp Maier87bd9be2017-08-22 16:35:41 +02001319 state.in_stream.last_tsdelta, state.in_stream.last_seq);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001320
1321 printf("Out TS change: %d, dTS: %d, Seq change: %d, "
Philipp Maier9e1d1642018-05-09 16:26:34 +02001322 "TS Err change: in +%u, out +%u\n",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001323 state.out_stream.last_timestamp - last_timestamp,
1324 state.out_stream.last_tsdelta,
1325 state.out_stream.last_seq - last_seqno,
Philipp Maier9e1d1642018-05-09 16:26:34 +02001326 (unsigned int) (state.in_stream.err_ts_ctr->current - last_in_ts_err_cnt),
1327 (unsigned int) (state.out_stream.err_ts_ctr->current - last_out_ts_err_cnt));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001328
1329 printf("Stats: Jitter = %u, Transit = %d\n",
Harald Welte49e3d5a2017-12-25 09:47:57 +01001330 calc_jitter(&state), state.stats.transit);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001331
Philipp Maier9e1d1642018-05-09 16:26:34 +02001332 last_in_ts_err_cnt = state.in_stream.err_ts_ctr->current;
1333 last_out_ts_err_cnt = state.out_stream.err_ts_ctr->current;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001334 last_timestamp = state.out_stream.last_timestamp;
1335 last_seqno = state.out_stream.last_seq;
1336 }
1337
1338 force_monotonic_time_us = -1;
Neels Hofmeyrd20910c2017-11-18 21:27:50 +01001339 mgcp_conn_free_all(&endp);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001340}
1341
1342static void test_multilple_codec(void)
1343{
1344 struct mgcp_config *cfg;
1345 struct mgcp_endpoint *endp;
1346 struct msgb *inp, *resp;
1347 struct in_addr addr;
Philipp Maier87bd9be2017-08-22 16:35:41 +02001348 struct mgcp_conn_rtp *conn = NULL;
Philipp Maierffd75e42017-11-22 11:44:50 +01001349 char conn_id[256];
Philipp Maiera74c0ea2018-08-02 11:59:09 +02001350 int i;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001351
1352 printf("Testing multiple payload types\n");
1353
1354 cfg = mgcp_config_alloc();
Philipp Maierfcd06552017-11-10 17:32:22 +01001355 cfg->trunk.vty_number_endpoints = 64;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001356 mgcp_endpoints_allocate(&cfg->trunk);
1357 cfg->policy_cb = mgcp_test_policy_cb;
1358 mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1));
1359
1360 /* Allocate endpoint 1@mgw with two codecs */
1361 last_endpoint = -1;
Philipp Maierffd75e42017-11-22 11:44:50 +01001362 inp = create_msg(CRCX_MULT_1, NULL);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001363 resp = mgcp_handle_message(cfg, inp);
Philipp Maierffd75e42017-11-22 11:44:50 +01001364 OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id,
1365 sizeof(conn_id)) == 0);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001366 msgb_free(inp);
1367 msgb_free(resp);
1368
1369 OSMO_ASSERT(last_endpoint == 1);
1370 endp = &cfg->trunk.endpoints[last_endpoint];
Philipp Maierffd75e42017-11-22 11:44:50 +01001371 conn = mgcp_conn_get_rtp(endp, conn_id);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001372 OSMO_ASSERT(conn);
Philipp Maierbc0346e2018-06-07 09:52:16 +02001373 OSMO_ASSERT(conn->end.codec->payload_type == 18);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001374
1375 /* Allocate 2@mgw with three codecs, last one ignored */
1376 last_endpoint = -1;
Philipp Maierffd75e42017-11-22 11:44:50 +01001377 inp = create_msg(CRCX_MULT_2, NULL);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001378 resp = mgcp_handle_message(cfg, inp);
Philipp Maierffd75e42017-11-22 11:44:50 +01001379 OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id,
1380 sizeof(conn_id)) == 0);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001381 msgb_free(inp);
1382 msgb_free(resp);
1383
1384 OSMO_ASSERT(last_endpoint == 2);
1385 endp = &cfg->trunk.endpoints[last_endpoint];
Philipp Maierffd75e42017-11-22 11:44:50 +01001386 conn = mgcp_conn_get_rtp(endp, conn_id);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001387 OSMO_ASSERT(conn);
Philipp Maierbc0346e2018-06-07 09:52:16 +02001388 OSMO_ASSERT(conn->end.codec->payload_type == 18);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001389
Philipp Maierbc0346e2018-06-07 09:52:16 +02001390 /* Allocate 3@mgw with no codecs, check for PT == 0 */
1391 /* Note: It usually makes no sense to leave the payload type list
1392 * out. However RFC 2327 does not clearly forbid this case and
1393 * it makes and since we already decided in OS#2658 that a missing
1394 * LCO should pick a sane default codec, it makes sense to expect
1395 * the same behaviour if SDP lacks proper payload type information */
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001396 last_endpoint = -1;
Philipp Maierffd75e42017-11-22 11:44:50 +01001397 inp = create_msg(CRCX_MULT_3, NULL);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001398 resp = mgcp_handle_message(cfg, inp);
Philipp Maierffd75e42017-11-22 11:44:50 +01001399 OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id,
1400 sizeof(conn_id)) == 0);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001401 msgb_free(inp);
1402 msgb_free(resp);
1403
1404 OSMO_ASSERT(last_endpoint == 3);
1405 endp = &cfg->trunk.endpoints[last_endpoint];
Philipp Maierffd75e42017-11-22 11:44:50 +01001406 conn = mgcp_conn_get_rtp(endp, conn_id);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001407 OSMO_ASSERT(conn);
Philipp Maierbc0346e2018-06-07 09:52:16 +02001408 OSMO_ASSERT(conn->end.codec->payload_type == 0);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001409
1410 /* Allocate 4@mgw with a single codec */
1411 last_endpoint = -1;
Philipp Maierffd75e42017-11-22 11:44:50 +01001412 inp = create_msg(CRCX_MULT_4, NULL);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001413 resp = mgcp_handle_message(cfg, inp);
Philipp Maierffd75e42017-11-22 11:44:50 +01001414 OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id,
1415 sizeof(conn_id)) == 0);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001416 msgb_free(inp);
1417 msgb_free(resp);
1418
1419 OSMO_ASSERT(last_endpoint == 4);
1420 endp = &cfg->trunk.endpoints[last_endpoint];
Philipp Maierffd75e42017-11-22 11:44:50 +01001421 conn = mgcp_conn_get_rtp(endp, conn_id);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001422 OSMO_ASSERT(conn);
Philipp Maierbc0346e2018-06-07 09:52:16 +02001423 OSMO_ASSERT(conn->end.codec->payload_type == 18);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001424
1425 /* Allocate 5@mgw at select GSM.. */
1426 last_endpoint = -1;
Philipp Maierffd75e42017-11-22 11:44:50 +01001427 inp = create_msg(CRCX_MULT_GSM_EXACT, NULL);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001428 talloc_free(cfg->trunk.audio_name);
1429 cfg->trunk.audio_name = "GSM/8000";
1430 cfg->trunk.no_audio_transcoding = 1;
1431 resp = mgcp_handle_message(cfg, inp);
Philipp Maierffd75e42017-11-22 11:44:50 +01001432 OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id,
1433 sizeof(conn_id)) == 0);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001434 msgb_free(inp);
1435 msgb_free(resp);
1436
1437 OSMO_ASSERT(last_endpoint == 5);
1438 endp = &cfg->trunk.endpoints[last_endpoint];
Philipp Maierffd75e42017-11-22 11:44:50 +01001439 conn = mgcp_conn_get_rtp(endp, conn_id);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001440 OSMO_ASSERT(conn);
Philipp Maierbc0346e2018-06-07 09:52:16 +02001441 OSMO_ASSERT(conn->end.codec->payload_type == 3);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001442
Philipp Maierffd75e42017-11-22 11:44:50 +01001443 inp = create_msg(MDCX_NAT_DUMMY, conn_id);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001444 last_endpoint = -1;
1445 resp = mgcp_handle_message(cfg, inp);
1446 msgb_free(inp);
1447 msgb_free(resp);
1448 OSMO_ASSERT(last_endpoint == 5);
1449 endp = &cfg->trunk.endpoints[last_endpoint];
Philipp Maierffd75e42017-11-22 11:44:50 +01001450 conn = mgcp_conn_get_rtp(endp, conn_id);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001451 OSMO_ASSERT(conn);
Philipp Maierbc0346e2018-06-07 09:52:16 +02001452 OSMO_ASSERT(conn->end.codec->payload_type == 3);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001453 OSMO_ASSERT(conn->end.rtp_port == htons(16434));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001454 memset(&addr, 0, sizeof(addr));
1455 inet_aton("8.8.8.8", &addr);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001456 OSMO_ASSERT(conn->end.addr.s_addr == addr.s_addr);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001457
1458 /* Check what happens without that flag */
1459
Philipp Maier87bd9be2017-08-22 16:35:41 +02001460 /* Free the previous endpoint and the data and
1461 * check if the connection really vanished... */
Philipp Maier1355d7e2018-02-01 14:30:06 +01001462 mgcp_endp_release(endp);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001463 talloc_free(endp->last_response);
1464 talloc_free(endp->last_trans);
1465 endp->last_response = endp->last_trans = NULL;
Philipp Maierffd75e42017-11-22 11:44:50 +01001466 conn = mgcp_conn_get_rtp(endp, conn_id);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001467 OSMO_ASSERT(!conn);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001468
1469 last_endpoint = -1;
Philipp Maierffd75e42017-11-22 11:44:50 +01001470 inp = create_msg(CRCX_MULT_GSM_EXACT, NULL);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001471 cfg->trunk.no_audio_transcoding = 0;
1472 resp = mgcp_handle_message(cfg, inp);
Philipp Maierffd75e42017-11-22 11:44:50 +01001473 OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id,
1474 sizeof(conn_id)) == 0);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001475 msgb_free(inp);
1476 msgb_free(resp);
1477
1478 OSMO_ASSERT(last_endpoint == 5);
1479 endp = &cfg->trunk.endpoints[last_endpoint];
Philipp Maierffd75e42017-11-22 11:44:50 +01001480 conn = mgcp_conn_get_rtp(endp, conn_id);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001481 OSMO_ASSERT(conn);
Philipp Maierbc0346e2018-06-07 09:52:16 +02001482 OSMO_ASSERT(conn->end.codec->payload_type == 0);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001483
Philipp Maiera74c0ea2018-08-02 11:59:09 +02001484 for (i = 1; i < cfg->trunk.number_endpoints; i++)
1485 mgcp_endp_release(&cfg->trunk.endpoints[i]);
1486
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001487 talloc_free(cfg);
1488}
1489
1490static void test_no_cycle(void)
1491{
1492 struct mgcp_config *cfg;
1493 struct mgcp_endpoint *endp;
Philipp Maier87bd9be2017-08-22 16:35:41 +02001494 struct mgcp_conn_rtp *conn = NULL;
Philipp Maierffd75e42017-11-22 11:44:50 +01001495 struct mgcp_conn *_conn = NULL;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001496
1497 printf("Testing no sequence flow on initial packet\n");
1498
1499 cfg = mgcp_config_alloc();
Philipp Maierfcd06552017-11-10 17:32:22 +01001500 cfg->trunk.vty_number_endpoints = 64;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001501 mgcp_endpoints_allocate(&cfg->trunk);
1502
1503 endp = &cfg->trunk.endpoints[1];
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001504
Philipp Maierffd75e42017-11-22 11:44:50 +01001505 _conn = mgcp_conn_alloc(NULL, endp, MGCP_CONN_TYPE_RTP,
1506 "test-connection");
1507 OSMO_ASSERT(_conn);
1508 conn = mgcp_conn_get_rtp(endp, _conn->id);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001509 OSMO_ASSERT(conn);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001510
Harald Welte49e3d5a2017-12-25 09:47:57 +01001511 OSMO_ASSERT(conn->state.stats.initialized == 0);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001512
1513 mgcp_rtp_annex_count(endp, &conn->state, 0, 0, 2342);
Harald Welte49e3d5a2017-12-25 09:47:57 +01001514 OSMO_ASSERT(conn->state.stats.initialized == 1);
1515 OSMO_ASSERT(conn->state.stats.cycles == 0);
1516 OSMO_ASSERT(conn->state.stats.max_seq == 0);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001517
1518 mgcp_rtp_annex_count(endp, &conn->state, 1, 0, 2342);
Harald Welte49e3d5a2017-12-25 09:47:57 +01001519 OSMO_ASSERT(conn->state.stats.initialized == 1);
1520 OSMO_ASSERT(conn->state.stats.cycles == 0);
1521 OSMO_ASSERT(conn->state.stats.max_seq == 1);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001522
1523 /* now jump.. */
Philipp Maier87bd9be2017-08-22 16:35:41 +02001524 mgcp_rtp_annex_count(endp, &conn->state, UINT16_MAX, 0, 2342);
Harald Welte49e3d5a2017-12-25 09:47:57 +01001525 OSMO_ASSERT(conn->state.stats.initialized == 1);
1526 OSMO_ASSERT(conn->state.stats.cycles == 0);
1527 OSMO_ASSERT(conn->state.stats.max_seq == UINT16_MAX);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001528
1529 /* and wrap */
Philipp Maier87bd9be2017-08-22 16:35:41 +02001530 mgcp_rtp_annex_count(endp, &conn->state, 0, 0, 2342);
Harald Welte49e3d5a2017-12-25 09:47:57 +01001531 OSMO_ASSERT(conn->state.stats.initialized == 1);
1532 OSMO_ASSERT(conn->state.stats.cycles == UINT16_MAX + 1);
1533 OSMO_ASSERT(conn->state.stats.max_seq == 0);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001534
Philipp Maier1355d7e2018-02-01 14:30:06 +01001535 mgcp_endp_release(endp);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001536 talloc_free(cfg);
1537}
1538
1539static void test_no_name(void)
1540{
1541 struct mgcp_config *cfg;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001542 struct msgb *inp, *msg;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001543
1544 printf("Testing no rtpmap name\n");
1545 cfg = mgcp_config_alloc();
1546
Philipp Maierfcd06552017-11-10 17:32:22 +01001547 cfg->trunk.vty_number_endpoints = 64;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001548 cfg->trunk.audio_send_name = 0;
1549 mgcp_endpoints_allocate(&cfg->trunk);
1550
1551 cfg->policy_cb = mgcp_test_policy_cb;
1552
1553 mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1));
1554
Philipp Maierffd75e42017-11-22 11:44:50 +01001555 inp = create_msg(CRCX, NULL);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001556 msg = mgcp_handle_message(cfg, inp);
Philipp Maierffd75e42017-11-22 11:44:50 +01001557
1558 if (check_response(msg->data, CRCX_RET_NO_RTPMAP) != 0) {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001559 printf("FAILED: there should not be a RTPMAP: %s\n",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001560 (char *)msg->data);
1561 OSMO_ASSERT(false);
1562 }
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001563 msgb_free(inp);
1564 msgb_free(msg);
1565
Philipp Maier1355d7e2018-02-01 14:30:06 +01001566 mgcp_endp_release(&cfg->trunk.endpoints[1]);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001567 talloc_free(cfg);
1568}
1569
1570static void test_osmux_cid(void)
1571{
1572 int id, i;
1573
Pau Espin Pedrol8de58e72019-04-24 13:33:46 +02001574 OSMO_ASSERT(osmux_cid_pool_count_used() == 0);
1575
1576 id = osmux_cid_pool_get_next();
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001577 OSMO_ASSERT(id == 0);
Pau Espin Pedrol8de58e72019-04-24 13:33:46 +02001578 OSMO_ASSERT(osmux_cid_pool_count_used() == 1);
1579
1580 osmux_cid_pool_get(30);
1581 OSMO_ASSERT(osmux_cid_pool_count_used() == 2);
1582 osmux_cid_pool_get(30);
1583 OSMO_ASSERT(osmux_cid_pool_count_used() == 2);
1584
1585 osmux_cid_pool_put(id);
1586 OSMO_ASSERT(osmux_cid_pool_count_used() == 1);
1587 osmux_cid_pool_put(30);
1588 OSMO_ASSERT(osmux_cid_pool_count_used() == 0);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001589
1590 for (i = 0; i < 256; ++i) {
Pau Espin Pedrol8de58e72019-04-24 13:33:46 +02001591 id = osmux_cid_pool_get_next();
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001592 OSMO_ASSERT(id == i);
Pau Espin Pedrol8de58e72019-04-24 13:33:46 +02001593 OSMO_ASSERT(osmux_cid_pool_count_used() == i + 1);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001594 }
1595
Pau Espin Pedrol8de58e72019-04-24 13:33:46 +02001596 id = osmux_cid_pool_get_next();
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001597 OSMO_ASSERT(id == -1);
1598
1599 for (i = 0; i < 256; ++i)
Pau Espin Pedrol8de58e72019-04-24 13:33:46 +02001600 osmux_cid_pool_put(i);
1601 OSMO_ASSERT(osmux_cid_pool_count_used() == 0);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001602}
1603
1604static const struct log_info_cat log_categories[] = {
1605};
1606
1607const struct log_info log_info = {
Philipp Maier87bd9be2017-08-22 16:35:41 +02001608 .cat = log_categories,
1609 .num_cat = ARRAY_SIZE(log_categories),
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001610};
1611
Philipp Maier3d7b58d2018-06-06 09:35:31 +02001612static void test_get_lco_identifier(void)
1613{
1614 char *test;
1615 printf("Testing get_lco_identifier()\n");
1616
1617 /* Normal case at the beginning */
1618 test = "p:10, a:PCMU";
1619 printf("%s -> %s\n", test, get_lco_identifier(test));
1620
1621 test = "p:10, a:PCMU";
1622 printf("%s -> %s\n", test, get_lco_identifier(test));
1623
1624 /* Begin parsing in the middle of the value part of
1625 * the previous LCO option value */
1626 test = "XXXX, p:10, a:PCMU";
1627 printf("'%s' -> '%s'\n", test, get_lco_identifier(test));
1628
1629 test = "XXXX,p:10,a:PCMU";
1630 printf("'%s' -> '%s'\n", test, get_lco_identifier(test));
1631
1632 test = "10,a:PCMU";
1633 printf("'%s' -> '%s'\n", test, get_lco_identifier(test));
1634
1635 test = "10, a:PCMU";
1636 printf("'%s' -> '%s'\n", test, get_lco_identifier(test));
1637
1638 test = "10,a: PCMU";
1639 printf("'%s' -> '%s'\n", test, get_lco_identifier(test));
1640
1641 test = "10 ,a: PCMU";
1642 printf("'%s' -> '%s'\n", test, get_lco_identifier(test));
1643
1644 /* Begin parsing right at the end of the previous LCO
1645 * option value */
1646 test = ", a:PCMU";
1647 printf("'%s' -> '%s'\n", test, get_lco_identifier(test));
1648
1649 test = " a:PCMU";
1650 printf("'%s' -> '%s'\n", test, get_lco_identifier(test));
1651
1652 /* Empty string, result should be (null) */
1653 test = "";
1654 printf("'%s' -> '%s'\n", test, get_lco_identifier(test));
1655
1656 /* Missing colons, result should be (null) */
1657 test = "p10, aPCMU";
1658 printf("%s -> %s\n", test, get_lco_identifier(test));
1659
1660 /* Colon separated from the identifier, result should be (null) */
1661 test = "10,a :PCMU";
1662 printf("'%s' -> '%s'\n", test, get_lco_identifier(test));
1663}
1664
1665static void test_check_local_cx_options(void *ctx)
1666{
1667 /* Legal cases */
1668 OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:PCMU") == 0);
1669 OSMO_ASSERT(check_local_cx_options(ctx, "a:PCMU") == 0);
1670 OSMO_ASSERT(check_local_cx_options(ctx, "a:PCMU, p:10, IN:10") == 0);
1671 OSMO_ASSERT(check_local_cx_options(ctx, "one:AAA, two:BB, tree:C") ==
1672 0);
1673 OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:PCMU") == 0);
1674 OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:G726-32") == 0);
1675 OSMO_ASSERT(check_local_cx_options(ctx, "p:10-20, b:64") == 0);
1676 OSMO_ASSERT(check_local_cx_options(ctx, "b:32-64, e:off") == 0);
1677 OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:PCMU;G726-32") == 0);
1678
1679 /* Illegal spaces before and after colon */
1680 OSMO_ASSERT(check_local_cx_options(ctx, "a:PCMU, p :10") == -1);
1681 OSMO_ASSERT(check_local_cx_options(ctx, "a :PCMU, p:10") == -1);
1682 OSMO_ASSERT(check_local_cx_options(ctx, "p: 10, a:PCMU") == -1);
1683
1684 /* Check if multiple appearances of LCOs are rejected */
1685 OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:PCMU, p:10") == -1);
1686 OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:PCMU, a:PCMU, p:10") ==
1687 -1);
1688 OSMO_ASSERT(check_local_cx_options(ctx, "p:10, p:10") == -1);
1689
1690 /* Check if empty LCO are rejected */
1691 OSMO_ASSERT(check_local_cx_options(ctx, "p: , a:PCMU") == -1);
1692 OSMO_ASSERT(check_local_cx_options(ctx, "p: , a: PCMU") == -1);
1693 OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a: PCMU") == -1);
1694 OSMO_ASSERT(check_local_cx_options(ctx, "p:, a:PCMU") == -1);
1695 OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:") == -1);
1696
1697 /* Garbeled beginning and ends */
1698 OSMO_ASSERT(check_local_cx_options(ctx, ":10, a:10") == -1);
1699 OSMO_ASSERT(check_local_cx_options(ctx, "10, a:PCMU") == -1);
1700 OSMO_ASSERT(check_local_cx_options(ctx, ", a:PCMU") == -1);
1701 OSMO_ASSERT(check_local_cx_options(ctx, " a:PCMU") == -1);
1702 OSMO_ASSERT(check_local_cx_options(ctx, "a:PCMU,") == -1);
1703 OSMO_ASSERT(check_local_cx_options(ctx, "a:PCMU, ") == -1);
1704
1705 /* Illegal strings */
1706 OSMO_ASSERT(check_local_cx_options(ctx, " ") == -1);
1707 OSMO_ASSERT(check_local_cx_options(ctx, "") == -1);
1708 OSMO_ASSERT(check_local_cx_options(ctx, "AAA") == -1);
1709 OSMO_ASSERT(check_local_cx_options(ctx, ":,") == -1);
1710 OSMO_ASSERT(check_local_cx_options(ctx, ",:") == -1);
1711 OSMO_ASSERT(check_local_cx_options(ctx, ",,,") == -1);
1712}
1713
Philipp Maier6931f9a2018-07-26 09:29:31 +02001714static void test_mgcp_codec_pt_translate_pars(struct mgcp_rtp_codec *c)
1715{
1716 c->rate = 8000;
1717 c->channels = 1;
1718 c->frame_duration_num = 23;
1719 c->frame_duration_den = 42;
1720}
1721
1722static void test_mgcp_codec_pt_translate(void)
1723{
1724 struct mgcp_conn_rtp conn_src;
1725 struct mgcp_conn_rtp conn_dst;
1726 int pt_dst;
1727
1728 /* Setup a realistic set of codec configurations on both
1729 * ends. AMR and HR will use different payload types. PCMU
1730 * must use 0 on both ends since this is not a dynamic payload
1731 * type */
1732 test_mgcp_codec_pt_translate_pars(&conn_src.end.codecs[0]);
1733 test_mgcp_codec_pt_translate_pars(&conn_dst.end.codecs[0]);
1734 test_mgcp_codec_pt_translate_pars(&conn_src.end.codecs[1]);
1735 test_mgcp_codec_pt_translate_pars(&conn_dst.end.codecs[1]);
1736 test_mgcp_codec_pt_translate_pars(&conn_src.end.codecs[2]);
1737 test_mgcp_codec_pt_translate_pars(&conn_dst.end.codecs[2]);
1738 conn_src.end.codecs[0].payload_type = 112;
1739 conn_dst.end.codecs[0].payload_type = 96;
1740 conn_src.end.codecs[1].payload_type = 0;
1741 conn_dst.end.codecs[1].payload_type = 0;
1742 conn_src.end.codecs[2].payload_type = 111;
1743 conn_dst.end.codecs[2].payload_type = 97;
1744 conn_src.end.codecs[0].audio_name = "AMR/8000/1";
1745 conn_dst.end.codecs[0].audio_name = "AMR/8000/1";
1746 conn_src.end.codecs[1].audio_name = "PCMU/8000/1";
1747 conn_dst.end.codecs[1].audio_name = "PCMU/8000/1";
1748 conn_src.end.codecs[2].audio_name = "GSM-HR-08/8000/1";
1749 conn_dst.end.codecs[2].audio_name = "GSM-HR-08/8000/1";
1750 conn_src.end.codecs[0].subtype_name = "AMR";
1751 conn_dst.end.codecs[0].subtype_name = "AMR";
1752 conn_src.end.codecs[1].subtype_name = "PCMU";
1753 conn_dst.end.codecs[1].subtype_name = "PCMU";
1754 conn_src.end.codecs[2].subtype_name = "GSM-HR-08";
1755 conn_dst.end.codecs[2].subtype_name = "GSM-HR-08";
1756 conn_src.end.codecs_assigned = 3;
1757 conn_dst.end.codecs_assigned = 3;
1758
1759 /* We expect the function to find the PT we must use when we send the
1760 * packet out to the destination. All we know is the context for both
1761 * connections and the payload type from the source packet */
1762 pt_dst =
1763 mgcp_codec_pt_translate(&conn_src, &conn_dst,
1764 conn_src.end.codecs[0].payload_type);
1765 OSMO_ASSERT(pt_dst == conn_dst.end.codecs[0].payload_type);
1766 pt_dst =
1767 mgcp_codec_pt_translate(&conn_src, &conn_dst,
1768 conn_src.end.codecs[1].payload_type);
1769 OSMO_ASSERT(pt_dst == conn_dst.end.codecs[1].payload_type);
1770 pt_dst =
1771 mgcp_codec_pt_translate(&conn_src, &conn_dst,
1772 conn_src.end.codecs[2].payload_type);
1773 OSMO_ASSERT(pt_dst == conn_dst.end.codecs[2].payload_type);
1774
1775 /* Try some constellations that must fail */
1776 pt_dst = mgcp_codec_pt_translate(&conn_src, &conn_dst, 123);
1777 OSMO_ASSERT(pt_dst == -EINVAL);
1778 conn_src.end.codecs_assigned = 0;
1779 conn_dst.end.codecs_assigned = 3;
1780 pt_dst =
1781 mgcp_codec_pt_translate(&conn_src, &conn_dst,
1782 conn_src.end.codecs[0].payload_type);
1783 OSMO_ASSERT(pt_dst == -EINVAL);
1784 pt_dst =
1785 mgcp_codec_pt_translate(&conn_src, &conn_dst,
1786 conn_src.end.codecs[1].payload_type);
1787 OSMO_ASSERT(pt_dst == -EINVAL);
1788 pt_dst =
1789 mgcp_codec_pt_translate(&conn_src, &conn_dst,
1790 conn_src.end.codecs[2].payload_type);
1791 OSMO_ASSERT(pt_dst == -EINVAL);
1792 conn_src.end.codecs_assigned = 3;
1793 conn_dst.end.codecs_assigned = 0;
1794 pt_dst =
1795 mgcp_codec_pt_translate(&conn_src, &conn_dst,
1796 conn_src.end.codecs[0].payload_type);
1797 OSMO_ASSERT(pt_dst == -EINVAL);
1798 pt_dst =
1799 mgcp_codec_pt_translate(&conn_src, &conn_dst,
1800 conn_src.end.codecs[1].payload_type);
1801 OSMO_ASSERT(pt_dst == -EINVAL);
1802 pt_dst =
1803 mgcp_codec_pt_translate(&conn_src, &conn_dst,
1804 conn_src.end.codecs[2].payload_type);
1805 OSMO_ASSERT(pt_dst == -EINVAL);
1806}
1807
Neels Hofmeyr65317262018-09-03 22:11:05 +02001808void test_conn_id_matching()
1809{
1810 struct mgcp_endpoint endp = {};
1811 struct mgcp_conn *conn;
1812 struct mgcp_conn *conn_match;
1813 int i;
1814 const char *conn_id_generated = "000023AB";
1815 const char *conn_id_request[] = {
Neels Hofmeyra77eade2018-08-29 02:30:39 +02001816 "23AB",
1817 "0023AB",
Neels Hofmeyr65317262018-09-03 22:11:05 +02001818 "000023AB",
Neels Hofmeyra77eade2018-08-29 02:30:39 +02001819 "00000023AB",
1820 "23ab",
1821 "0023ab",
Neels Hofmeyr65317262018-09-03 22:11:05 +02001822 "000023ab",
Neels Hofmeyra77eade2018-08-29 02:30:39 +02001823 "00000023ab",
Neels Hofmeyr65317262018-09-03 22:11:05 +02001824 };
1825
1826 printf("\nTesting %s\n", __func__);
1827
1828 INIT_LLIST_HEAD(&endp.conns);
1829
1830 conn = talloc_zero(NULL, struct mgcp_conn);
1831 OSMO_ASSERT(conn);
1832 osmo_strlcpy(conn->id, conn_id_generated, sizeof(conn->id));
1833 llist_add(&conn->entry, &endp.conns);
1834
1835 for (i = 0; i < ARRAY_SIZE(conn_id_request); i++) {
1836 const char *needle = conn_id_request[i];
1837 printf("needle='%s' ", needle);
1838 conn_match = mgcp_conn_get(&endp, needle);
1839 OSMO_ASSERT(conn_match);
1840 printf("found '%s'\n", conn_match->id);
1841 OSMO_ASSERT(conn_match == conn);
1842 }
1843
1844 llist_del(&conn->entry);
1845 talloc_free(conn);
1846}
1847
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001848int main(int argc, char **argv)
1849{
Neels Hofmeyr60f8e312018-03-30 23:01:07 +02001850 void *ctx = talloc_named_const(NULL, 0, "mgcp_test");
1851 void *msgb_ctx = msgb_talloc_ctx_init(ctx, 0);
1852 osmo_init_logging2(ctx, &log_info);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001853
1854 test_strline();
1855 test_values();
1856 test_messages();
1857 test_retransmission();
1858 test_packet_loss_calc();
1859 test_rqnt_cb();
1860 test_mgcp_stats();
1861 test_packet_error_detection(1, 0);
1862 test_packet_error_detection(0, 0);
1863 test_packet_error_detection(0, 1);
1864 test_packet_error_detection(1, 1);
1865 test_multilple_codec();
1866 test_no_cycle();
1867 test_no_name();
1868 test_osmux_cid();
Philipp Maier3d7b58d2018-06-06 09:35:31 +02001869 test_get_lco_identifier();
1870 test_check_local_cx_options(ctx);
Philipp Maier6931f9a2018-07-26 09:29:31 +02001871 test_mgcp_codec_pt_translate();
Neels Hofmeyr65317262018-09-03 22:11:05 +02001872 test_conn_id_matching();
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001873
Neels Hofmeyr465446b2017-11-18 21:26:26 +01001874 OSMO_ASSERT(talloc_total_size(msgb_ctx) == 0);
1875 OSMO_ASSERT(talloc_total_blocks(msgb_ctx) == 1);
1876 talloc_free(msgb_ctx);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001877 printf("Done\n");
1878 return EXIT_SUCCESS;
1879}