Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1 | /* |
| 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 Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 22 | #include <osmocom/mgcp/mgcp.h> |
| 23 | #include <osmocom/mgcp/vty.h> |
Neels Hofmeyr | 6779354 | 2017-09-08 04:25:16 +0200 | [diff] [blame] | 24 | #include <osmocom/mgcp/mgcp_common.h> |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 25 | #include <osmocom/mgcp/mgcp_internal.h> |
| 26 | #include <osmocom/mgcp/mgcp_stat.h> |
| 27 | #include <osmocom/mgcp/mgcp_msg.h> |
Philipp Maier | 37d11c8 | 2018-02-01 14:38:12 +0100 | [diff] [blame] | 28 | #include <osmocom/mgcp/mgcp_endp.h> |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 29 | #include <osmocom/mgcp/mgcp_trunk.h> |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 30 | #include <osmocom/mgcp/mgcp_sdp.h> |
| 31 | #include <osmocom/mgcp/mgcp_codec.h> |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 32 | |
| 33 | #include <osmocom/core/application.h> |
| 34 | #include <osmocom/core/talloc.h> |
| 35 | #include <osmocom/core/utils.h> |
| 36 | #include <string.h> |
| 37 | #include <limits.h> |
| 38 | #include <dlfcn.h> |
| 39 | #include <time.h> |
| 40 | #include <math.h> |
Neels Hofmeyr | b861db9 | 2018-08-28 16:19:25 +0200 | [diff] [blame] | 41 | #include <ctype.h> |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 42 | |
| 43 | char *strline_r(char *str, char **saveptr); |
| 44 | |
| 45 | const char *strline_test_data = |
| 46 | "one CR\r" |
| 47 | "two CR\r" |
| 48 | "\r" |
| 49 | "one CRLF\r\n" |
| 50 | "two CRLF\r\n" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 51 | "\r\n" "one LF\n" "two LF\n" "\n" "mixed (4 lines)\r\r\n\n\r\n"; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 52 | |
| 53 | #define EXPECTED_NUMBER_OF_LINES 13 |
| 54 | |
| 55 | static void test_strline(void) |
| 56 | { |
| 57 | char *save = NULL; |
| 58 | char *line; |
| 59 | char buf[2048]; |
| 60 | int counter = 0; |
| 61 | |
| 62 | osmo_strlcpy(buf, strline_test_data, sizeof(buf)); |
| 63 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 64 | for (line = mgcp_strline(buf, &save); line; |
| 65 | line = mgcp_strline(NULL, &save)) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 66 | printf("line: '%s'\n", line); |
| 67 | counter++; |
| 68 | } |
| 69 | |
| 70 | OSMO_ASSERT(counter == EXPECTED_NUMBER_OF_LINES); |
| 71 | } |
| 72 | |
Philipp Maier | 12943ea | 2018-01-17 15:40:25 +0100 | [diff] [blame] | 73 | #define AUEP1 "AUEP 158663169 ds/e1-1/2@mgw MGCP 1.0\r\n" |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 74 | #define AUEP1_RET "500 158663169 FAIL\r\n" |
Philipp Maier | 12943ea | 2018-01-17 15:40:25 +0100 | [diff] [blame] | 75 | #define AUEP2 "AUEP 18983213 ds/e1-2/1@mgw MGCP 1.0\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 76 | #define AUEP2_RET "500 18983213 FAIL\r\n" |
| 77 | #define EMPTY "\r\n" |
| 78 | #define EMPTY_RET NULL |
| 79 | #define SHORT "CRCX \r\n" |
| 80 | #define SHORT_RET "510 000000 FAIL\r\n" |
| 81 | |
Philipp Maier | 12943ea | 2018-01-17 15:40:25 +0100 | [diff] [blame] | 82 | #define MDCX_WRONG_EP "MDCX 18983213 ds/e1-3/1@mgw MGCP 1.0\r\n" |
Harald Welte | abbb6b9 | 2017-12-28 13:13:50 +0100 | [diff] [blame] | 83 | #define MDCX_ERR_RET "500 18983213 FAIL\r\n" |
Philipp Maier | 12943ea | 2018-01-17 15:40:25 +0100 | [diff] [blame] | 84 | #define MDCX_UNALLOCATED "MDCX 18983214 ds/e1-1/2@mgw MGCP 1.0\r\n" |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 85 | #define MDCX_RET "500 18983214 FAIL\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 86 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 87 | #define MDCX3 \ |
| 88 | "MDCX 18983215 1@mgw MGCP 1.0\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 89 | "I: %s\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 90 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 91 | #define MDCX3_RET \ |
| 92 | "200 18983215 OK\r\n" \ |
Philipp Maier | c3cfae2 | 2018-01-22 12:03:03 +0100 | [diff] [blame] | 93 | "\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 94 | "v=0\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 95 | "o=- %s 23 IN IP4 0.0.0.0\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 96 | "s=-\r\n" \ |
| 97 | "c=IN IP4 0.0.0.0\r\n" \ |
| 98 | "t=0 0\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 99 | "m=audio 16002 RTP/AVP 97\r\n" \ |
| 100 | "a=rtpmap:97 GSM-EFR/8000\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 101 | "a=ptime:40\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 102 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 103 | #define MDCX3A_RET \ |
| 104 | "200 18983215 OK\r\n" \ |
Philipp Maier | c3cfae2 | 2018-01-22 12:03:03 +0100 | [diff] [blame] | 105 | "\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 106 | "v=0\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 107 | "o=- %s 23 IN IP4 0.0.0.0\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 108 | "s=-\r\n" \ |
| 109 | "c=IN IP4 0.0.0.0\r\n" \ |
| 110 | "t=0 0\r\n" \ |
| 111 | "m=audio 16002 RTP/AVP 97\r\n" \ |
| 112 | "a=rtpmap:97 GSM-EFR/8000\r\n" \ |
| 113 | "a=ptime:40\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 114 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 115 | #define MDCX3_FMTP_RET \ |
| 116 | "200 18983215 OK\r\n" \ |
Philipp Maier | c3cfae2 | 2018-01-22 12:03:03 +0100 | [diff] [blame] | 117 | "\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 118 | "v=0\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 119 | "o=- %s 23 IN IP4 0.0.0.0\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 120 | "s=-\r\n" \ |
| 121 | "c=IN IP4 0.0.0.0\r\n" \ |
| 122 | "t=0 0\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 123 | "m=audio 16006 RTP/AVP 97\r\n" \ |
| 124 | "a=rtpmap:97 GSM-EFR/8000\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 125 | "a=fmtp:126 0/1/2\r\n" \ |
| 126 | "a=ptime:40\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 127 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 128 | #define MDCX4 \ |
| 129 | "MDCX 18983216 1@mgw MGCP 1.0\r\n" \ |
| 130 | "M: sendrecv\r" \ |
| 131 | "C: 2\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 132 | "I: %s\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 133 | "L: p:20, a:AMR, nt:IN\r\n" \ |
| 134 | "\n" \ |
| 135 | "v=0\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 136 | "o=- %s 23 IN IP4 0.0.0.0\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 137 | "c=IN IP4 0.0.0.0\r\n" \ |
| 138 | "t=0 0\r\n" \ |
| 139 | "m=audio 4441 RTP/AVP 99\r\n" \ |
| 140 | "a=rtpmap:99 AMR/8000\r\n" \ |
| 141 | "a=ptime:40\r\n" |
| 142 | |
| 143 | #define MDCX4_RET(Ident) \ |
| 144 | "200 " Ident " OK\r\n" \ |
Philipp Maier | c3cfae2 | 2018-01-22 12:03:03 +0100 | [diff] [blame] | 145 | "\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 146 | "v=0\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 147 | "o=- %s 23 IN IP4 0.0.0.0\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 148 | "s=-\r\n" \ |
| 149 | "c=IN IP4 0.0.0.0\r\n" \ |
| 150 | "t=0 0\r\n" \ |
| 151 | "m=audio 16002 RTP/AVP 99\r\n" \ |
| 152 | "a=rtpmap:99 AMR/8000\r\n" \ |
| 153 | "a=ptime:40\r\n" |
| 154 | |
| 155 | #define MDCX4_RO_RET(Ident) \ |
| 156 | "200 " Ident " OK\r\n" \ |
Philipp Maier | c3cfae2 | 2018-01-22 12:03:03 +0100 | [diff] [blame] | 157 | "\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 158 | "v=0\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 159 | "o=- %s 23 IN IP4 0.0.0.0\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 160 | "s=-\r\n" \ |
| 161 | "c=IN IP4 0.0.0.0\r\n" \ |
| 162 | "t=0 0\r\n" \ |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 163 | "m=audio 16002 RTP/AVP 112\r\n" \ |
| 164 | "a=rtpmap:112 AMR\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 165 | "a=ptime:40\r\n" |
| 166 | |
| 167 | #define MDCX4_PT1 \ |
| 168 | "MDCX 18983217 1@mgw MGCP 1.0\r\n" \ |
Pau Espin Pedrol | 1705848 | 2019-06-26 12:23:02 +0200 | [diff] [blame] | 169 | "M: SENDRECV\r" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 170 | "C: 2\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 171 | "I: %s\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 172 | "L: p:20-40, a:AMR, nt:IN\r\n" \ |
| 173 | "\n" \ |
| 174 | "v=0\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 175 | "o=- %s 23 IN IP4 0.0.0.0\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 176 | "c=IN IP4 0.0.0.0\r\n" \ |
| 177 | "t=0 0\r\n" \ |
| 178 | "m=audio 4441 RTP/AVP 99\r\n" \ |
| 179 | "a=rtpmap:99 AMR/8000\r\n" \ |
| 180 | "a=ptime:40\r\n" |
| 181 | |
| 182 | #define MDCX4_PT2 \ |
| 183 | "MDCX 18983218 1@mgw MGCP 1.0\r\n" \ |
| 184 | "M: sendrecv\r" \ |
| 185 | "C: 2\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 186 | "I: %s\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 187 | "L: p:20-20, a:AMR, nt:IN\r\n" \ |
| 188 | "\n" \ |
| 189 | "v=0\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 190 | "o=- %s 23 IN IP4 0.0.0.0\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 191 | "c=IN IP4 0.0.0.0\r\n" \ |
| 192 | "t=0 0\r\n" \ |
| 193 | "m=audio 4441 RTP/AVP 99\r\n" \ |
| 194 | "a=rtpmap:99 AMR/8000\r\n" \ |
| 195 | "a=ptime:40\r\n" |
| 196 | |
| 197 | #define MDCX4_PT3 \ |
| 198 | "MDCX 18983219 1@mgw MGCP 1.0\r\n" \ |
| 199 | "M: sendrecv\r" \ |
| 200 | "C: 2\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 201 | "I: %s\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 202 | "L: a:AMR, nt:IN\r\n" \ |
| 203 | "\n" \ |
| 204 | "v=0\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 205 | "o=- %s 23 IN IP4 0.0.0.0\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 206 | "c=IN IP4 0.0.0.0\r\n" \ |
| 207 | "t=0 0\r\n" \ |
| 208 | "m=audio 4441 RTP/AVP 99\r\n" \ |
| 209 | "a=rtpmap:99 AMR/8000\r\n" \ |
| 210 | "a=ptime:40\r\n" |
| 211 | |
Pau Espin Pedrol | fe9a1fe | 2019-06-25 16:59:15 +0200 | [diff] [blame] | 212 | /* Test different upper/lower case in options */ |
| 213 | #define MDCX4_PT4 \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 214 | "MDCX 18983220 1@mgw MGCP 1.0\r\n" \ |
Pau Espin Pedrol | 0c6c3c1 | 2019-06-25 17:18:12 +0200 | [diff] [blame] | 215 | "m: sendrecv\r" \ |
| 216 | "c: 2\r\n" \ |
| 217 | "i: %s\r\n" \ |
Pau Espin Pedrol | 83fd8a5 | 2019-06-26 12:55:26 +0200 | [diff] [blame] | 218 | "l: A:amr, NT:IN\r\n" \ |
Pau Espin Pedrol | fe9a1fe | 2019-06-25 16:59:15 +0200 | [diff] [blame] | 219 | "\n" \ |
| 220 | "v=0\r\n" \ |
| 221 | "o=- %s 23 IN IP4 0.0.0.0\r\n" \ |
| 222 | "c=IN IP4 0.0.0.0\r\n" \ |
| 223 | "t=0 0\r\n" \ |
| 224 | "m=audio 4441 RTP/AVP 99\r\n" \ |
| 225 | "a=rtpmap:99 AMR/8000\r\n" \ |
| 226 | "a=ptime:40\r\n" |
| 227 | |
| 228 | #define MDCX4_SO \ |
| 229 | "MDCX 18983221 1@mgw MGCP 1.0\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 230 | "M: sendonly\r" \ |
| 231 | "C: 2\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 232 | "I: %s\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 233 | "L: p:20, a:AMR, nt:IN\r\n" \ |
| 234 | "\n" \ |
| 235 | "v=0\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 236 | "o=- %s 23 IN IP4 0.0.0.0\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 237 | "c=IN IP4 0.0.0.0\r\n" \ |
| 238 | "t=0 0\r\n" \ |
| 239 | "m=audio 4441 RTP/AVP 99\r\n" \ |
| 240 | "a=rtpmap:99 AMR/8000\r\n" \ |
| 241 | "a=ptime:40\r\n" |
| 242 | |
| 243 | #define MDCX4_RO \ |
Pau Espin Pedrol | fe9a1fe | 2019-06-25 16:59:15 +0200 | [diff] [blame] | 244 | "MDCX 18983222 1@mgw MGCP 1.0\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 245 | "M: recvonly\r" \ |
| 246 | "C: 2\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 247 | "I: %s\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 248 | "L: p:20, a:AMR, nt:IN\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 249 | |
Neels Hofmeyr | 5336f57 | 2018-09-03 22:05:48 +0200 | [diff] [blame] | 250 | #define MDCX_TOO_LONG_CI \ |
Pau Espin Pedrol | fe9a1fe | 2019-06-25 16:59:15 +0200 | [diff] [blame] | 251 | "MDCX 18983223 1@mgw MGCP 1.0\r\n" \ |
Neels Hofmeyr | 5336f57 | 2018-09-03 22:05:48 +0200 | [diff] [blame] | 252 | "I: 123456789012345678901234567890123\n" |
| 253 | |
Pau Espin Pedrol | fe9a1fe | 2019-06-25 16:59:15 +0200 | [diff] [blame] | 254 | #define MDCX_TOO_LONG_CI_RET "510 18983223 FAIL\r\n" |
Neels Hofmeyr | 5336f57 | 2018-09-03 22:05:48 +0200 | [diff] [blame] | 255 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 256 | #define SHORT2 "CRCX 1" |
| 257 | #define SHORT2_RET "510 000000 FAIL\r\n" |
| 258 | #define SHORT3 "CRCX 1 1@mgw" |
| 259 | #define SHORT4 "CRCX 1 1@mgw MGCP" |
| 260 | #define SHORT5 "CRCX 1 1@mgw MGCP 1.0" |
| 261 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 262 | #define CRCX \ |
| 263 | "CRCX 2 1@mgw MGCP 1.0\r\n" \ |
Pau Espin Pedrol | 0c6c3c1 | 2019-06-25 17:18:12 +0200 | [diff] [blame] | 264 | "m: recvonly\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 265 | "C: 2\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 266 | "L: p:20\r\n" \ |
| 267 | "\r\n" \ |
| 268 | "v=0\r\n" \ |
| 269 | "c=IN IP4 123.12.12.123\r\n" \ |
| 270 | "m=audio 5904 RTP/AVP 97\r\n" \ |
| 271 | "a=rtpmap:97 GSM-EFR/8000\r\n" \ |
| 272 | "a=ptime:40\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 273 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 274 | #define CRCX_RET \ |
| 275 | "200 2 OK\r\n" \ |
Philipp Maier | c3cfae2 | 2018-01-22 12:03:03 +0100 | [diff] [blame] | 276 | "I: %s\r\n" \ |
| 277 | "\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 278 | "v=0\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 279 | "o=- %s 23 IN IP4 0.0.0.0\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 280 | "s=-\r\n" \ |
| 281 | "c=IN IP4 0.0.0.0\r\n" \ |
| 282 | "t=0 0\r\n" \ |
| 283 | "m=audio 16002 RTP/AVP 97\r\n" \ |
| 284 | "a=rtpmap:97 GSM-EFR/8000\r\n" \ |
| 285 | "a=ptime:40\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 286 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 287 | #define CRCX_RET_NO_RTPMAP \ |
| 288 | "200 2 OK\r\n" \ |
Philipp Maier | c3cfae2 | 2018-01-22 12:03:03 +0100 | [diff] [blame] | 289 | "I: %s\r\n" \ |
| 290 | "\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 291 | "v=0\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 292 | "o=- %s 23 IN IP4 0.0.0.0\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 293 | "s=-\r\n" \ |
| 294 | "c=IN IP4 0.0.0.0\r\n" \ |
| 295 | "t=0 0\r\n" \ |
| 296 | "m=audio 16002 RTP/AVP 97\r\n" \ |
| 297 | "a=ptime:40\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 298 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 299 | #define CRCX_FMTP_RET \ |
| 300 | "200 2 OK\r\n" \ |
Philipp Maier | c3cfae2 | 2018-01-22 12:03:03 +0100 | [diff] [blame] | 301 | "I: %s\r\n" \ |
| 302 | "\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 303 | "v=0\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 304 | "o=- %s 23 IN IP4 0.0.0.0\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 305 | "s=-\r\n" \ |
| 306 | "c=IN IP4 0.0.0.0\r\n" \ |
| 307 | "t=0 0\r\n" \ |
| 308 | "m=audio 16006 RTP/AVP 97\r\n" \ |
| 309 | "a=rtpmap:97 GSM-EFR/8000\r\n" \ |
| 310 | "a=fmtp:126 0/1/2\r\n" \ |
| 311 | "a=ptime:40\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 312 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 313 | #define CRCX_ZYN \ |
| 314 | "CRCX 2 1@mgw MGCP 1.0\r" \ |
| 315 | "M: recvonly\r" \ |
| 316 | "C: 2\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 317 | "\n" \ |
| 318 | "v=0\r" \ |
| 319 | "c=IN IP4 123.12.12.123\r" \ |
| 320 | "m=audio 5904 RTP/AVP 97\r" \ |
| 321 | "a=rtpmap:97 GSM-EFR/8000\r" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 322 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 323 | #define CRCX_ZYN_RET \ |
| 324 | "200 2 OK\r\n" \ |
Philipp Maier | c3cfae2 | 2018-01-22 12:03:03 +0100 | [diff] [blame] | 325 | "I: %s\r\n" \ |
| 326 | "\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 327 | "v=0\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 328 | "o=- %s 23 IN IP4 0.0.0.0\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 329 | "s=-\r\n" \ |
| 330 | "c=IN IP4 0.0.0.0\r\n" \ |
| 331 | "t=0 0\r\n" \ |
| 332 | "m=audio 16004 RTP/AVP 97\r\n" \ |
| 333 | "a=rtpmap:97 GSM-EFR/8000\r\n" \ |
| 334 | "a=ptime:20\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 335 | |
Neels Hofmeyr | e6d8e91 | 2018-08-23 16:36:48 +0200 | [diff] [blame] | 336 | #define CRCX_X_OSMO_IGN \ |
| 337 | "CRCX 2 1@mgw MGCP 1.0\r\n" \ |
| 338 | "M: recvonly\r\n" \ |
| 339 | "C: 2\r\n" \ |
| 340 | "L: p:20\r\n" \ |
Neels Hofmeyr | f2388ea | 2018-08-26 23:36:53 +0200 | [diff] [blame] | 341 | "X-Osmo-IGN: C foo\r\n" \ |
Neels Hofmeyr | e6d8e91 | 2018-08-23 16:36:48 +0200 | [diff] [blame] | 342 | "\r\n" \ |
| 343 | "v=0\r\n" \ |
| 344 | "c=IN IP4 123.12.12.123\r\n" \ |
| 345 | "m=audio 5904 RTP/AVP 97\r\n" \ |
| 346 | "a=rtpmap:97 GSM-EFR/8000\r\n" \ |
| 347 | "a=ptime:40\r\n" |
| 348 | |
| 349 | #define CRCX_X_OSMO_IGN_RET \ |
| 350 | "200 2 OK\r\n" \ |
| 351 | "I: %s\r\n" \ |
| 352 | "\r\n" \ |
| 353 | "v=0\r\n" \ |
| 354 | "o=- %s 23 IN IP4 0.0.0.0\r\n" \ |
| 355 | "s=-\r\n" \ |
| 356 | "c=IN IP4 0.0.0.0\r\n" \ |
| 357 | "t=0 0\r\n" \ |
| 358 | "m=audio 16010 RTP/AVP 97\r\n" \ |
| 359 | "a=rtpmap:97 GSM-EFR/8000\r\n" \ |
| 360 | "a=ptime:40\r\n" |
| 361 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 362 | #define DLCX \ |
| 363 | "DLCX 7 1@mgw MGCP 1.0\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 364 | "I: %s\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 365 | "C: 2\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 366 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 367 | #define DLCX_RET \ |
| 368 | "250 7 OK\r\n" \ |
Pau Espin Pedrol | 2da99a2 | 2018-02-20 13:11:17 +0100 | [diff] [blame] | 369 | "P: PS=0, OS=0, PR=0, OR=0, PL=0, JI=0\r\n" |
| 370 | |
| 371 | #define DLCX_RET_OSMUX DLCX_RET \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 372 | "X-Osmo-CP: EC TI=0, TO=0\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 373 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 374 | #define RQNT \ |
| 375 | "RQNT 186908780 1@mgw MGCP 1.0\r\n" \ |
| 376 | "X: B244F267488\r\n" \ |
| 377 | "S: D/9\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 378 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 379 | #define RQNT2 \ |
| 380 | "RQNT 186908781 1@mgw MGCP 1.0\r\n" \ |
| 381 | "X: ADD4F26746F\r\n" \ |
| 382 | "R: D/[0-9#*](N), G/ft, fxr/t38\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 383 | |
| 384 | #define RQNT1_RET "200 186908780 OK\r\n" |
| 385 | #define RQNT2_RET "200 186908781 OK\r\n" |
| 386 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 387 | #define PTYPE_IGNORE 0 /* == default initializer */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 388 | #define PTYPE_NONE 128 |
| 389 | #define PTYPE_NYI PTYPE_NONE |
| 390 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 391 | #define CRCX_MULT_1 \ |
| 392 | "CRCX 2 1@mgw MGCP 1.0\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 393 | "M: recvonly\r\n" \ |
| 394 | "C: 2\r\n" \ |
| 395 | "X\r\n" \ |
| 396 | "L: p:20\r\n" \ |
| 397 | "\r\n" \ |
| 398 | "v=0\r\n" \ |
| 399 | "c=IN IP4 123.12.12.123\r\n" \ |
| 400 | "m=audio 5904 RTP/AVP 18 97\r\n" \ |
| 401 | "a=rtpmap:18 G729/8000\r\n" \ |
| 402 | "a=rtpmap:97 GSM-EFR/8000\r\n" \ |
| 403 | "a=ptime:40\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 404 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 405 | #define CRCX_MULT_2 \ |
| 406 | "CRCX 2 2@mgw MGCP 1.0\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 407 | "M: recvonly\r\n" \ |
| 408 | "C: 2\r\n" \ |
| 409 | "X\r\n" \ |
| 410 | "L: p:20\r\n" \ |
| 411 | "\r\n" \ |
| 412 | "v=0\r\n" \ |
| 413 | "c=IN IP4 123.12.12.123\r\n" \ |
| 414 | "m=audio 5904 RTP/AVP 18 97 101\r\n" \ |
| 415 | "a=rtpmap:18 G729/8000\r\n" \ |
| 416 | "a=rtpmap:97 GSM-EFR/8000\r\n" \ |
| 417 | "a=rtpmap:101 FOO/8000\r\n" \ |
| 418 | "a=ptime:40\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 419 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 420 | #define CRCX_MULT_3 \ |
| 421 | "CRCX 2 3@mgw MGCP 1.0\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 422 | "M: recvonly\r\n" \ |
| 423 | "C: 2\r\n" \ |
| 424 | "X\r\n" \ |
| 425 | "L: p:20\r\n" \ |
| 426 | "\r\n" \ |
| 427 | "v=0\r\n" \ |
| 428 | "c=IN IP4 123.12.12.123\r\n" \ |
| 429 | "m=audio 5904 RTP/AVP\r\n" \ |
| 430 | "a=rtpmap:18 G729/8000\r\n" \ |
| 431 | "a=rtpmap:97 GSM-EFR/8000\r\n" \ |
| 432 | "a=rtpmap:101 FOO/8000\r\n" \ |
| 433 | "a=ptime:40\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 434 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 435 | #define CRCX_MULT_4 \ |
| 436 | "CRCX 2 4@mgw MGCP 1.0\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 437 | "M: recvonly\r\n" \ |
| 438 | "C: 2\r\n" \ |
| 439 | "X\r\n" \ |
| 440 | "L: p:20\r\n" \ |
| 441 | "\r\n" \ |
| 442 | "v=0\r\n" \ |
| 443 | "c=IN IP4 123.12.12.123\r\n" \ |
| 444 | "m=audio 5904 RTP/AVP 18\r\n" \ |
| 445 | "a=rtpmap:18 G729/8000\r\n" \ |
| 446 | "a=rtpmap:97 GSM-EFR/8000\r\n" \ |
| 447 | "a=rtpmap:101 FOO/8000\r\n" \ |
| 448 | "a=ptime:40\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 449 | |
| 450 | #define CRCX_MULT_GSM_EXACT \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 451 | "CRCX 259260421 5@mgw MGCP 1.0\r\n" \ |
| 452 | "C: 1355c6041e\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 453 | "L: p:20, a:GSM, nt:IN\r\n" \ |
| 454 | "M: recvonly\r\n" \ |
| 455 | "\r\n" \ |
| 456 | "v=0\r\n" \ |
| 457 | "o=- 1439038275 1439038275 IN IP4 192.168.181.247\r\n" \ |
| 458 | "s=-\r\nc=IN IP4 192.168.181.247\r\n" \ |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 459 | "t=0 0\r\nm=audio 29084 RTP/AVP 0 8 3 18 4 96 97 101\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 460 | "a=rtpmap:0 PCMU/8000\r\n" \ |
| 461 | "a=rtpmap:8 PCMA/8000\r\n" \ |
| 462 | "a=rtpmap:3 gsm/8000\r\n" \ |
| 463 | "a=rtpmap:18 G729/8000\r\n" \ |
| 464 | "a=fmtp:18 annexb=no\r\n" \ |
| 465 | "a=rtpmap:4 G723/8000\r\n" \ |
| 466 | "a=rtpmap:96 iLBC/8000\r\n" \ |
| 467 | "a=fmtp:96 mode=20\r\n" \ |
| 468 | "a=rtpmap:97 iLBC/8000\r\n" \ |
| 469 | "a=fmtp:97 mode=30\r\n" \ |
| 470 | "a=rtpmap:101 telephone-event/8000\r\n" \ |
| 471 | "a=fmtp:101 0-15\r\n" \ |
| 472 | "a=recvonly\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 473 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 474 | #define MDCX_NAT_DUMMY \ |
| 475 | "MDCX 23 5@mgw MGCP 1.0\r\n" \ |
| 476 | "C: 1355c6041e\r\n" \ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 477 | "I: %s\r\n" \ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 478 | "\r\n" \ |
| 479 | "c=IN IP4 8.8.8.8\r\n" \ |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 480 | "m=audio 16434 RTP/AVP 3\r\n" |
| 481 | |
| 482 | #define CRCX_NO_LCO_NO_SDP \ |
| 483 | "CRCX 2 6@mgw MGCP 1.0\r\n" \ |
| 484 | "M: recvonly\r\n" \ |
| 485 | "C: 2\r\n" |
| 486 | |
Philipp Maier | 228e591 | 2019-03-05 13:56:59 +0100 | [diff] [blame] | 487 | #define CRCX_AMR_WITH_FMTP \ |
| 488 | "CRCX 2 7@mgw MGCP 1.0\r\n" \ |
| 489 | "M: recvonly\r\n" \ |
| 490 | "C: 2\r\n" \ |
| 491 | "X\r\n" \ |
| 492 | "L: p:20\r\n" \ |
| 493 | "\r\n" \ |
| 494 | "v=0\r\n" \ |
| 495 | "c=IN IP4 123.12.12.123\r\n" \ |
| 496 | "m=audio 5904 RTP/AVP 111\r\n" \ |
| 497 | "a=rtpmap:111 AMR/8000/1\r\n" \ |
| 498 | "a=ptime:20\r\n" \ |
| 499 | "a=fmtp:111 mode-change-capability=2; octet-align=1\r\n" \ |
| 500 | |
| 501 | #define CRCX_AMR_WITH_FMTP_RET \ |
| 502 | "200 2 OK\r\n" \ |
| 503 | "I: %s\r\n" \ |
| 504 | "\r\n" \ |
| 505 | "v=0\r\n" \ |
| 506 | "o=- %s 23 IN IP4 0.0.0.0\r\n" \ |
| 507 | "s=-\r\n" \ |
| 508 | "c=IN IP4 0.0.0.0\r\n" \ |
| 509 | "t=0 0\r\n" \ |
| 510 | "m=audio 16012 RTP/AVP 111\r\n" \ |
| 511 | "a=rtpmap:111 AMR/8000/1\r\n" \ |
| 512 | "a=fmtp:111 octet-align=1\r\n" \ |
| 513 | "a=ptime:20\r\n" |
| 514 | |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 515 | #define CRCX_NO_LCO_NO_SDP_RET \ |
| 516 | "200 2 OK\r\n" \ |
| 517 | "I: %s\r\n" \ |
| 518 | "\r\n" \ |
| 519 | "v=0\r\n" \ |
| 520 | "o=- %s 23 IN IP4 0.0.0.0\r\n" \ |
| 521 | "s=-\r\n" \ |
| 522 | "c=IN IP4 0.0.0.0\r\n" \ |
| 523 | "t=0 0\r\n" \ |
| 524 | "m=audio 16008 RTP/AVP 0\r\n" \ |
| 525 | "a=ptime:20\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 526 | |
| 527 | struct mgcp_test { |
| 528 | const char *name; |
| 529 | const char *req; |
| 530 | const char *exp_resp; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 531 | int ptype; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 532 | const char *extra_fmtp; |
| 533 | }; |
| 534 | |
| 535 | static const struct mgcp_test tests[] = { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 536 | {"AUEP1", AUEP1, AUEP1_RET}, |
| 537 | {"AUEP2", AUEP2, AUEP2_RET}, |
| 538 | {"MDCX1", MDCX_WRONG_EP, MDCX_ERR_RET}, |
| 539 | {"MDCX2", MDCX_UNALLOCATED, MDCX_RET}, |
| 540 | {"CRCX", CRCX, CRCX_RET, 97}, |
| 541 | {"MDCX3", MDCX3, MDCX3_RET, PTYPE_IGNORE}, |
| 542 | {"MDCX4", MDCX4, MDCX4_RET("18983216"), 99}, |
| 543 | {"MDCX4_PT1", MDCX4_PT1, MDCX4_RET("18983217"), 99}, |
| 544 | {"MDCX4_PT2", MDCX4_PT2, MDCX4_RET("18983218"), 99}, |
| 545 | {"MDCX4_PT3", MDCX4_PT3, MDCX4_RET("18983219"), 99}, |
Pau Espin Pedrol | fe9a1fe | 2019-06-25 16:59:15 +0200 | [diff] [blame] | 546 | {"MDCX4_PT4", MDCX4_PT4, MDCX4_RET("18983220"), 99}, |
| 547 | {"MDCX4_SO", MDCX4_SO, MDCX4_RET("18983221"), 99}, |
| 548 | {"MDCX4_RO", MDCX4_RO, MDCX4_RO_RET("18983222"), PTYPE_IGNORE}, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 549 | {"DLCX", DLCX, DLCX_RET, PTYPE_IGNORE}, |
| 550 | {"CRCX_ZYN", CRCX_ZYN, CRCX_ZYN_RET, 97}, |
| 551 | {"EMPTY", EMPTY, EMPTY_RET}, |
| 552 | {"SHORT1", SHORT, SHORT_RET}, |
| 553 | {"SHORT2", SHORT2, SHORT2_RET}, |
| 554 | {"SHORT3", SHORT3, SHORT2_RET}, |
| 555 | {"SHORT4", SHORT4, SHORT2_RET}, |
| 556 | {"RQNT1", RQNT, RQNT1_RET}, |
| 557 | {"RQNT2", RQNT2, RQNT2_RET}, |
| 558 | {"DLCX", DLCX, DLCX_RET, PTYPE_IGNORE}, |
| 559 | {"CRCX", CRCX, CRCX_FMTP_RET, 97,.extra_fmtp = "a=fmtp:126 0/1/2"}, |
| 560 | {"MDCX3", MDCX3, MDCX3_FMTP_RET, PTYPE_NONE,.extra_fmtp = |
| 561 | "a=fmtp:126 0/1/2"}, |
| 562 | {"DLCX", DLCX, DLCX_RET, PTYPE_IGNORE,.extra_fmtp = "a=fmtp:126 0/1/2"}, |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 563 | {"CRCX", CRCX_NO_LCO_NO_SDP, CRCX_NO_LCO_NO_SDP_RET, 97}, |
Neels Hofmeyr | e6d8e91 | 2018-08-23 16:36:48 +0200 | [diff] [blame] | 564 | {"CRCX", CRCX_X_OSMO_IGN, CRCX_X_OSMO_IGN_RET, 97}, |
Neels Hofmeyr | 5336f57 | 2018-09-03 22:05:48 +0200 | [diff] [blame] | 565 | {"MDCX_TOO_LONG_CI", MDCX_TOO_LONG_CI, MDCX_TOO_LONG_CI_RET}, |
Philipp Maier | 228e591 | 2019-03-05 13:56:59 +0100 | [diff] [blame] | 566 | {"CRCX", CRCX_AMR_WITH_FMTP, CRCX_AMR_WITH_FMTP_RET}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 567 | }; |
| 568 | |
| 569 | static const struct mgcp_test retransmit[] = { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 570 | {"CRCX", CRCX, CRCX_RET}, |
| 571 | {"RQNT1", RQNT, RQNT1_RET}, |
| 572 | {"RQNT2", RQNT2, RQNT2_RET}, |
| 573 | {"MDCX3", MDCX3, MDCX3A_RET}, |
| 574 | {"DLCX", DLCX, DLCX_RET}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 575 | }; |
| 576 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 577 | static struct msgb *create_msg(const char *str, const char *conn_id) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 578 | { |
| 579 | struct msgb *msg; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 580 | int len; |
| 581 | |
| 582 | printf("creating message from statically defined input:\n"); |
| 583 | printf("---------8<---------\n%s\n---------8<---------\n", str); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 584 | |
| 585 | msg = msgb_alloc_headroom(4096, 128, "MGCP msg"); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 586 | if (conn_id && strlen(conn_id)) |
| 587 | len = sprintf((char *)msg->data, str, conn_id, conn_id); |
| 588 | else |
| 589 | len = sprintf((char *)msg->data, "%s", str); |
| 590 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 591 | msg->l2h = msgb_put(msg, len); |
| 592 | return msg; |
| 593 | } |
| 594 | |
| 595 | static int last_endpoint = -1; |
| 596 | |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 597 | static int mgcp_test_policy_cb(struct mgcp_endpoint *endp, |
| 598 | int state, const char *transaction_id) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 599 | { |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 600 | unsigned int i; |
| 601 | struct mgcp_trunk *trunk; |
| 602 | |
| 603 | fprintf(stderr, "Policy CB got state %d on endpoint %s\n", |
| 604 | state, endp->name); |
| 605 | |
| 606 | trunk = endp->trunk; |
| 607 | last_endpoint = -1; |
| 608 | for (i = 0; i < trunk->vty_number_endpoints; i++) { |
| 609 | if (strcmp(endp->name, trunk->endpoints[i]->name) == 0) |
| 610 | last_endpoint = i; |
| 611 | } |
| 612 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 613 | return MGCP_POLICY_CONT; |
| 614 | } |
| 615 | |
| 616 | #define MGCP_DUMMY_LOAD 0x23 |
| 617 | static int dummy_packets = 0; |
| 618 | /* override and forward */ |
| 619 | ssize_t sendto(int sockfd, const void *buf, size_t len, int flags, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 620 | const struct sockaddr *dest_addr, socklen_t addrlen) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 621 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 622 | uint32_t dest_host = |
| 623 | htonl(((struct sockaddr_in *)dest_addr)->sin_addr.s_addr); |
| 624 | int dest_port = htons(((struct sockaddr_in *)dest_addr)->sin_port); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 625 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 626 | if (len == 1 && ((const char *)buf)[0] == MGCP_DUMMY_LOAD) { |
| 627 | fprintf(stderr, |
| 628 | "Dummy packet to 0x%08x:%d, msg length %zu\n%s\n\n", |
| 629 | dest_host, dest_port, len, osmo_hexdump(buf, len)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 630 | dummy_packets += 1; |
| 631 | } |
| 632 | |
Philipp Maier | 3d9b656 | 2017-10-13 18:33:44 +0200 | [diff] [blame] | 633 | return len; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | static int64_t force_monotonic_time_us = -1; |
| 637 | /* override and forward */ |
| 638 | int clock_gettime(clockid_t clk_id, struct timespec *tp) |
| 639 | { |
| 640 | typedef int (*clock_gettime_t)(clockid_t clk_id, struct timespec *tp); |
| 641 | static clock_gettime_t real_clock_gettime = NULL; |
| 642 | |
| 643 | if (!real_clock_gettime) |
| 644 | real_clock_gettime = dlsym(RTLD_NEXT, "clock_gettime"); |
| 645 | |
| 646 | if (clk_id == CLOCK_MONOTONIC && force_monotonic_time_us >= 0) { |
| 647 | tp->tv_sec = force_monotonic_time_us / 1000000; |
| 648 | tp->tv_nsec = (force_monotonic_time_us % 1000000) * 1000; |
| 649 | return 0; |
| 650 | } |
| 651 | |
| 652 | return real_clock_gettime(clk_id, tp); |
| 653 | } |
| 654 | |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 655 | static void mgcp_endpoints_release(struct mgcp_trunk *trunk) |
Pau Espin Pedrol | d071a30 | 2019-09-19 17:39:31 +0200 | [diff] [blame] | 656 | { |
| 657 | int i; |
| 658 | for (i = 1; i < trunk->number_endpoints; i++) |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 659 | mgcp_endp_release(trunk->endpoints[i]); |
Pau Espin Pedrol | d071a30 | 2019-09-19 17:39:31 +0200 | [diff] [blame] | 660 | } |
| 661 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 662 | #define CONN_UNMODIFIED (0x1000) |
| 663 | |
| 664 | static void test_values(void) |
| 665 | { |
| 666 | /* Check that NONE disables all output */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 667 | OSMO_ASSERT((MGCP_CONN_NONE & MGCP_CONN_RECV_SEND) == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 668 | |
| 669 | /* Check that LOOPBACK enables all output */ |
| 670 | OSMO_ASSERT((MGCP_CONN_LOOPBACK & MGCP_CONN_RECV_SEND) == |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 671 | MGCP_CONN_RECV_SEND); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 672 | } |
| 673 | |
Neels Hofmeyr | e28b673 | 2018-08-28 16:19:25 +0200 | [diff] [blame] | 674 | /* Extract a connection ID from a response and return in conn_id; |
| 675 | * if there is none, return -EINVAL and leave conn_id unchanged. */ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 676 | static int get_conn_id_from_response(uint8_t *resp, char *conn_id, |
Neels Hofmeyr | e28b673 | 2018-08-28 16:19:25 +0200 | [diff] [blame] | 677 | size_t conn_id_buflen) |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 678 | { |
Neels Hofmeyr | e28b673 | 2018-08-28 16:19:25 +0200 | [diff] [blame] | 679 | const char *conn_id_start; |
| 680 | const char *conn_id_end; |
| 681 | int conn_id_len; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 682 | |
Neels Hofmeyr | e28b673 | 2018-08-28 16:19:25 +0200 | [diff] [blame] | 683 | const char *header_I = "\r\nI: "; |
| 684 | const char *header_o = "\r\no=- "; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 685 | |
Neels Hofmeyr | e28b673 | 2018-08-28 16:19:25 +0200 | [diff] [blame] | 686 | /* Try to get the conn_id from the 'I:' or 'o=-' parameter */ |
| 687 | if ((conn_id_start = strstr((char *)resp, header_I))) { |
| 688 | conn_id_start += strlen(header_I); |
| 689 | conn_id_end = strstr(conn_id_start, "\r\n"); |
| 690 | } else if ((conn_id_start = strstr((char *)resp, header_o))) { |
| 691 | conn_id_start += strlen(header_o); |
| 692 | conn_id_end = strchr(conn_id_start, ' '); |
| 693 | } else |
| 694 | return -EINVAL; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 695 | |
Neels Hofmeyr | e28b673 | 2018-08-28 16:19:25 +0200 | [diff] [blame] | 696 | if (conn_id_end) |
| 697 | conn_id_len = conn_id_end - conn_id_start; |
| 698 | else |
| 699 | conn_id_len = strlen(conn_id_start); |
| 700 | OSMO_ASSERT(conn_id_len <= conn_id_buflen - 1); |
Philipp Maier | 55295f7 | 2018-01-15 14:00:28 +0100 | [diff] [blame] | 701 | |
Neels Hofmeyr | e28b673 | 2018-08-28 16:19:25 +0200 | [diff] [blame] | 702 | /* A valid conn_id must at least contain one digit, and must |
| 703 | * not exceed a length of 32 digits */ |
| 704 | OSMO_ASSERT(conn_id_len <= 32); |
| 705 | OSMO_ASSERT(conn_id_len > 0); |
| 706 | |
| 707 | strncpy(conn_id, conn_id_start, conn_id_len); |
| 708 | conn_id[conn_id_len] = '\0'; |
| 709 | return 0; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | /* Check response, automatically patch connection ID if needed */ |
| 713 | static int check_response(uint8_t *resp, const char *exp_resp) |
| 714 | { |
| 715 | char exp_resp_patched[4096]; |
| 716 | const char *exp_resp_ptr; |
| 717 | char conn_id[256]; |
| 718 | |
| 719 | printf("checking response:\n"); |
| 720 | |
| 721 | /* If the expected response is intened to be patched |
| 722 | * (%s placeholder inside) we will patch it with the |
| 723 | * connection identifier we just received from the |
| 724 | * real response. This is necessary because the CI |
| 725 | * is generated by the mgcp code on CRCX and we can |
| 726 | * not know it in advance */ |
| 727 | if (strstr(exp_resp, "%s")) { |
| 728 | if (get_conn_id_from_response(resp, conn_id, sizeof(conn_id)) == |
| 729 | 0) { |
| 730 | sprintf(exp_resp_patched, exp_resp, conn_id, conn_id); |
| 731 | exp_resp_ptr = exp_resp_patched; |
| 732 | printf |
| 733 | ("using message with patched conn_id for comparison\n"); |
| 734 | } else { |
| 735 | printf |
| 736 | ("patching conn_id failed, using message as statically defined for comparison\n"); |
| 737 | exp_resp_ptr = exp_resp; |
| 738 | } |
| 739 | } else { |
| 740 | printf("using message as statically defined for comparison\n"); |
| 741 | exp_resp_ptr = exp_resp; |
| 742 | } |
| 743 | |
| 744 | if (strcmp((char *)resp, exp_resp_ptr) != 0) { |
| 745 | printf("Unexpected response, please check!\n"); |
| 746 | printf |
| 747 | ("Got:\n---------8<---------\n%s\n---------8<---------\n\n", |
| 748 | resp); |
| 749 | printf |
| 750 | ("Expected:\n---------8<---------\n%s\n---------8<---------\n", |
| 751 | exp_resp_ptr); |
| 752 | return -EINVAL; |
| 753 | } |
| 754 | |
| 755 | printf("Response matches our expectations.\n"); |
| 756 | return 0; |
| 757 | } |
| 758 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 759 | static void test_messages(void) |
| 760 | { |
| 761 | struct mgcp_config *cfg; |
| 762 | struct mgcp_endpoint *endp; |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 763 | struct mgcp_trunk *trunk2; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 764 | int i; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 765 | struct mgcp_conn_rtp *conn = NULL; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 766 | char last_conn_id[256]; |
Philipp Maier | 7df419b | 2017-12-04 17:11:42 +0100 | [diff] [blame] | 767 | int rc; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 768 | |
| 769 | cfg = mgcp_config_alloc(); |
| 770 | |
Harald Welte | c39b1bf | 2020-03-08 11:29:39 +0100 | [diff] [blame] | 771 | cfg->virt_trunk->vty_number_endpoints = 64; |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 772 | mgcp_trunk_alloc_endpts(cfg->virt_trunk); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 773 | cfg->policy_cb = mgcp_test_policy_cb; |
| 774 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 775 | memset(last_conn_id, 0, sizeof(last_conn_id)); |
| 776 | |
Harald Welte | c39b1bf | 2020-03-08 11:29:39 +0100 | [diff] [blame] | 777 | trunk2 = mgcp_trunk_alloc(cfg, MGCP_TRUNK_E1, 1); |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 778 | mgcp_trunk_alloc_endpts(trunk2); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 779 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 780 | for (i = 0; i < ARRAY_SIZE(tests); i++) { |
| 781 | const struct mgcp_test *t = &tests[i]; |
| 782 | struct msgb *inp; |
| 783 | struct msgb *msg; |
| 784 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 785 | printf("\n================================================\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 786 | printf("Testing %s\n", t->name); |
| 787 | |
| 788 | last_endpoint = -1; |
| 789 | dummy_packets = 0; |
| 790 | |
Harald Welte | c39b1bf | 2020-03-08 11:29:39 +0100 | [diff] [blame] | 791 | osmo_talloc_replace_string(cfg, &cfg->virt_trunk->audio_fmtp_extra, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 792 | t->extra_fmtp); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 793 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 794 | inp = create_msg(t->req, last_conn_id); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 795 | msg = mgcp_handle_message(cfg, inp); |
| 796 | msgb_free(inp); |
| 797 | if (!t->exp_resp) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 798 | if (msg) { |
| 799 | printf("%s failed '%s'\n", t->name, |
| 800 | (char *)msg->data); |
| 801 | OSMO_ASSERT(false); |
| 802 | } |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 803 | } else if (check_response(msg->data, t->exp_resp) != 0) { |
| 804 | printf("%s failed.\n", t->name); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 805 | OSMO_ASSERT(false); |
| 806 | } |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 807 | |
Philipp Maier | 7df419b | 2017-12-04 17:11:42 +0100 | [diff] [blame] | 808 | if (msg) { |
| 809 | rc = get_conn_id_from_response(msg->data, last_conn_id, |
| 810 | sizeof(last_conn_id)); |
Neels Hofmeyr | 08e0704 | 2018-08-28 16:22:14 +0200 | [diff] [blame] | 811 | if (rc == 0) |
Philipp Maier | 7df419b | 2017-12-04 17:11:42 +0100 | [diff] [blame] | 812 | printf("(response contains a connection id)\n"); |
| 813 | else |
| 814 | printf("(response does not contain a connection id)\n"); |
| 815 | } |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 816 | |
Philipp Maier | a330b86 | 2017-12-04 17:16:16 +0100 | [diff] [blame] | 817 | if (msg) |
| 818 | msgb_free(msg); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 819 | |
| 820 | if (dummy_packets) |
| 821 | printf("Dummy packets: %d\n", dummy_packets); |
| 822 | |
| 823 | if (last_endpoint != -1) { |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 824 | endp = cfg->virt_trunk->endpoints[last_endpoint]; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 825 | |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 826 | conn = mgcp_conn_get_rtp(endp, "1"); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 827 | if (conn) { |
| 828 | OSMO_ASSERT(conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 829 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 830 | if (conn->end.packet_duration_ms != -1) |
| 831 | printf("Detected packet duration: %d\n", |
| 832 | conn->end.packet_duration_ms); |
| 833 | else |
| 834 | printf("Packet duration not set\n"); |
| 835 | if (endp->local_options.pkt_period_min || |
| 836 | endp->local_options.pkt_period_max) |
| 837 | printf |
| 838 | ("Requested packetetization period: " |
| 839 | "%d-%d\n", |
| 840 | endp->local_options.pkt_period_min, |
| 841 | endp-> |
| 842 | local_options.pkt_period_max); |
| 843 | else |
| 844 | printf |
| 845 | ("Requested packetization period not set\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 846 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 847 | if ((conn->conn->mode & CONN_UNMODIFIED) == 0) { |
| 848 | printf("Connection mode: %d:%s%s%s%s\n", |
| 849 | conn->conn->mode, |
| 850 | !conn->conn->mode ? " NONE" : "", |
| 851 | conn->conn->mode & MGCP_CONN_SEND_ONLY |
| 852 | ? " SEND" : "", |
| 853 | conn->conn->mode & MGCP_CONN_RECV_ONLY |
| 854 | ? " RECV" : "", |
| 855 | conn->conn->mode & MGCP_CONN_LOOPBACK |
| 856 | & ~MGCP_CONN_RECV_SEND |
| 857 | ? " LOOP" : ""); |
| 858 | fprintf(stderr, |
| 859 | "RTP output %sabled, NET output %sabled\n", |
| 860 | conn->end.output_enabled |
| 861 | ? "en" : "dis", |
| 862 | conn->end.output_enabled |
| 863 | ? "en" : "dis"); |
| 864 | } else |
| 865 | printf("Connection mode not set\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 866 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 867 | OSMO_ASSERT(conn->end.output_enabled |
| 868 | == (conn->conn->mode & MGCP_CONN_SEND_ONLY ? 1 : 0)); |
| 869 | |
| 870 | conn->conn->mode |= CONN_UNMODIFIED; |
| 871 | |
| 872 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 873 | endp->local_options.pkt_period_min = 0; |
| 874 | endp->local_options.pkt_period_max = 0; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 875 | } |
| 876 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 877 | /* Check detected payload type */ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 878 | if (conn && t->ptype != PTYPE_IGNORE) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 879 | OSMO_ASSERT(last_endpoint != -1); |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 880 | endp = cfg->virt_trunk->endpoints[last_endpoint]; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 881 | |
Pau Espin Pedrol | 9ecceb6 | 2018-10-16 15:35:58 +0200 | [diff] [blame] | 882 | fprintf(stderr, "endpoint 0x%x: " |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 883 | "payload type %d (expected %d)\n", |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 884 | last_endpoint, |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 885 | conn->end.codec->payload_type, t->ptype); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 886 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 887 | if (t->ptype != PTYPE_IGNORE) |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 888 | OSMO_ASSERT(conn->end.codec->payload_type == |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 889 | t->ptype); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 890 | |
| 891 | /* Reset them again for next test */ |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 892 | conn->end.codec->payload_type = PTYPE_NONE; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 893 | } |
| 894 | } |
| 895 | |
Pau Espin Pedrol | d071a30 | 2019-09-19 17:39:31 +0200 | [diff] [blame] | 896 | mgcp_endpoints_release(trunk2); |
Harald Welte | c39b1bf | 2020-03-08 11:29:39 +0100 | [diff] [blame] | 897 | mgcp_endpoints_release(cfg->virt_trunk); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 898 | talloc_free(cfg); |
| 899 | } |
| 900 | |
| 901 | static void test_retransmission(void) |
| 902 | { |
| 903 | struct mgcp_config *cfg; |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 904 | struct mgcp_trunk *trunk2; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 905 | int i; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 906 | char last_conn_id[256]; |
Philipp Maier | 23b8e29 | 2017-12-04 16:48:45 +0100 | [diff] [blame] | 907 | int rc; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 908 | |
| 909 | cfg = mgcp_config_alloc(); |
| 910 | |
Harald Welte | c39b1bf | 2020-03-08 11:29:39 +0100 | [diff] [blame] | 911 | cfg->virt_trunk->vty_number_endpoints = 64; |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 912 | mgcp_trunk_alloc_endpts(cfg->virt_trunk); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 913 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 914 | memset(last_conn_id, 0, sizeof(last_conn_id)); |
| 915 | |
Harald Welte | c39b1bf | 2020-03-08 11:29:39 +0100 | [diff] [blame] | 916 | trunk2 = mgcp_trunk_alloc(cfg, MGCP_TRUNK_E1, 1); |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 917 | mgcp_trunk_alloc_endpts(trunk2); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 918 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 919 | for (i = 0; i < ARRAY_SIZE(retransmit); i++) { |
| 920 | const struct mgcp_test *t = &retransmit[i]; |
| 921 | struct msgb *inp; |
| 922 | struct msgb *msg; |
| 923 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 924 | printf("\n================================================\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 925 | printf("Testing %s\n", t->name); |
| 926 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 927 | inp = create_msg(t->req, last_conn_id); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 928 | msg = mgcp_handle_message(cfg, inp); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 929 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 930 | msgb_free(inp); |
Philipp Maier | 7cedfd7 | 2017-12-04 16:49:12 +0100 | [diff] [blame] | 931 | if (msg && check_response(msg->data, t->exp_resp) != 0) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 932 | printf("%s failed '%s'\n", t->name, (char *)msg->data); |
| 933 | OSMO_ASSERT(false); |
| 934 | } |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 935 | |
Philipp Maier | 23b8e29 | 2017-12-04 16:48:45 +0100 | [diff] [blame] | 936 | if (msg && strcmp(t->name, "CRCX") == 0) { |
| 937 | rc = get_conn_id_from_response(msg->data, last_conn_id, |
| 938 | sizeof(last_conn_id)); |
| 939 | OSMO_ASSERT(rc == 0); |
| 940 | } |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 941 | |
Philipp Maier | 7cedfd7 | 2017-12-04 16:49:12 +0100 | [diff] [blame] | 942 | if (msg) |
| 943 | msgb_free(msg); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 944 | |
| 945 | /* Retransmit... */ |
| 946 | printf("Re-transmitting %s\n", t->name); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 947 | inp = create_msg(t->req, last_conn_id); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 948 | msg = mgcp_handle_message(cfg, inp); |
| 949 | msgb_free(inp); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 950 | if (check_response(msg->data, t->exp_resp) != 0) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 951 | printf("%s failed '%s'\n", t->name, (char *)msg->data); |
| 952 | OSMO_ASSERT(false); |
| 953 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 954 | msgb_free(msg); |
| 955 | } |
| 956 | |
Pau Espin Pedrol | d071a30 | 2019-09-19 17:39:31 +0200 | [diff] [blame] | 957 | mgcp_endpoints_release(trunk2); |
Harald Welte | c39b1bf | 2020-03-08 11:29:39 +0100 | [diff] [blame] | 958 | mgcp_endpoints_release(cfg->virt_trunk); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 959 | talloc_free(cfg); |
| 960 | } |
| 961 | |
| 962 | static int rqnt_cb(struct mgcp_endpoint *endp, char _tone) |
| 963 | { |
| 964 | ptrdiff_t tone = _tone; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 965 | endp->cfg->data = (void *)tone; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 966 | return 0; |
| 967 | } |
| 968 | |
| 969 | static void test_rqnt_cb(void) |
| 970 | { |
| 971 | struct mgcp_config *cfg; |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 972 | struct mgcp_trunk *trunk2; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 973 | struct msgb *inp, *msg; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 974 | char conn_id[256]; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 975 | |
| 976 | cfg = mgcp_config_alloc(); |
| 977 | cfg->rqnt_cb = rqnt_cb; |
| 978 | |
Harald Welte | c39b1bf | 2020-03-08 11:29:39 +0100 | [diff] [blame] | 979 | cfg->virt_trunk->vty_number_endpoints = 64; |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 980 | mgcp_trunk_alloc_endpts(cfg->virt_trunk); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 981 | |
Harald Welte | c39b1bf | 2020-03-08 11:29:39 +0100 | [diff] [blame] | 982 | trunk2 = mgcp_trunk_alloc(cfg, MGCP_TRUNK_E1, 1); |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 983 | mgcp_trunk_alloc_endpts(trunk2); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 984 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 985 | inp = create_msg(CRCX, NULL); |
| 986 | msg = mgcp_handle_message(cfg, inp); |
| 987 | OSMO_ASSERT(msg); |
| 988 | OSMO_ASSERT(get_conn_id_from_response(msg->data, conn_id, |
| 989 | sizeof(conn_id)) == 0); |
| 990 | msgb_free(msg); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 991 | msgb_free(inp); |
| 992 | |
| 993 | /* send the RQNT and check for the CB */ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 994 | inp = create_msg(RQNT, conn_id); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 995 | msg = mgcp_handle_message(cfg, inp); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 996 | if (strncmp((const char *)msg->l2h, "200", 3) != 0) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 997 | printf("FAILED: message is not 200. '%s'\n", msg->l2h); |
| 998 | abort(); |
| 999 | } |
| 1000 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1001 | if (cfg->data != (void *)'9') { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1002 | printf("FAILED: callback not called: %p\n", cfg->data); |
| 1003 | abort(); |
| 1004 | } |
| 1005 | |
| 1006 | msgb_free(msg); |
| 1007 | msgb_free(inp); |
| 1008 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1009 | inp = create_msg(DLCX, conn_id); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1010 | msgb_free(mgcp_handle_message(cfg, inp)); |
| 1011 | msgb_free(inp); |
Pau Espin Pedrol | d071a30 | 2019-09-19 17:39:31 +0200 | [diff] [blame] | 1012 | mgcp_endpoints_release(trunk2); |
Harald Welte | c39b1bf | 2020-03-08 11:29:39 +0100 | [diff] [blame] | 1013 | mgcp_endpoints_release(cfg->virt_trunk); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1014 | talloc_free(cfg); |
| 1015 | } |
| 1016 | |
| 1017 | struct pl_test { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1018 | int cycles; |
| 1019 | uint16_t base_seq; |
| 1020 | uint16_t max_seq; |
| 1021 | uint32_t packets; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1022 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1023 | uint32_t expected; |
| 1024 | int loss; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1025 | }; |
| 1026 | |
| 1027 | static const struct pl_test pl_test_dat[] = { |
| 1028 | /* basic.. just one package */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1029 | {.cycles = 0,.base_seq = 0,.max_seq = 0,.packets = 1,.expected = |
| 1030 | 1,.loss = 0}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1031 | /* some packages and a bit of loss */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1032 | {.cycles = 0,.base_seq = 0,.max_seq = 100,.packets = 100,.expected = |
| 1033 | 101,.loss = 1}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1034 | /* wrap around */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1035 | {.cycles = 1 << 16,.base_seq = 0xffff,.max_seq = 2,.packets = |
| 1036 | 4,.expected = 4,.loss = 0}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1037 | /* min loss */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1038 | {.cycles = 0,.base_seq = 0,.max_seq = 0,.packets = UINT_MAX,.expected = |
| 1039 | 1,.loss = INT_MIN}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1040 | /* max loss, with wrap around on expected max */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1041 | {.cycles = INT_MAX,.base_seq = 0,.max_seq = UINT16_MAX,.packets = |
| 1042 | 0,.expected = ((uint32_t) (INT_MAX) + UINT16_MAX + 1),.loss = INT_MAX}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1043 | }; |
| 1044 | |
| 1045 | static void test_packet_loss_calc(void) |
| 1046 | { |
| 1047 | int i; |
Philipp Maier | cede2a4 | 2018-07-03 14:14:21 +0200 | [diff] [blame] | 1048 | struct mgcp_endpoint endp; |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1049 | struct mgcp_endpoint *endpoints[1]; |
Oliver Smith | e36b775 | 2019-01-22 16:31:36 +0100 | [diff] [blame] | 1050 | struct mgcp_config cfg = {0}; |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1051 | struct mgcp_trunk trunk; |
Philipp Maier | cede2a4 | 2018-07-03 14:14:21 +0200 | [diff] [blame] | 1052 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1053 | printf("Testing packet loss calculation.\n"); |
| 1054 | |
Philipp Maier | cede2a4 | 2018-07-03 14:14:21 +0200 | [diff] [blame] | 1055 | memset(&endp, 0, sizeof(endp)); |
| 1056 | memset(&trunk, 0, sizeof(trunk)); |
| 1057 | |
Oliver Smith | e36b775 | 2019-01-22 16:31:36 +0100 | [diff] [blame] | 1058 | endp.cfg = &cfg; |
Philipp Maier | cede2a4 | 2018-07-03 14:14:21 +0200 | [diff] [blame] | 1059 | endp.type = &ep_typeset.rtp; |
| 1060 | trunk.vty_number_endpoints = 1; |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1061 | trunk.endpoints = endpoints; |
| 1062 | trunk.endpoints[0] = &endp; |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1063 | endp.trunk = &trunk; |
Philipp Maier | cede2a4 | 2018-07-03 14:14:21 +0200 | [diff] [blame] | 1064 | INIT_LLIST_HEAD(&endp.conns); |
| 1065 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1066 | for (i = 0; i < ARRAY_SIZE(pl_test_dat); ++i) { |
| 1067 | uint32_t expected; |
| 1068 | int loss; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1069 | |
Philipp Maier | cede2a4 | 2018-07-03 14:14:21 +0200 | [diff] [blame] | 1070 | struct mgcp_conn_rtp *conn = NULL; |
| 1071 | struct mgcp_conn *_conn = NULL; |
| 1072 | struct mgcp_rtp_state *state; |
| 1073 | struct rate_ctr *packets_rx; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1074 | |
Philipp Maier | cede2a4 | 2018-07-03 14:14:21 +0200 | [diff] [blame] | 1075 | _conn = |
| 1076 | mgcp_conn_alloc(NULL, &endp, MGCP_CONN_TYPE_RTP, |
| 1077 | "test-connection"); |
| 1078 | conn = mgcp_conn_get_rtp(&endp, _conn->id); |
| 1079 | state = &conn->state; |
| 1080 | packets_rx = &conn->rate_ctr_group->ctr[RTP_PACKETS_RX_CTR]; |
| 1081 | |
| 1082 | state->stats.initialized = 1; |
| 1083 | state->stats.base_seq = pl_test_dat[i].base_seq; |
| 1084 | state->stats.max_seq = pl_test_dat[i].max_seq; |
| 1085 | state->stats.cycles = pl_test_dat[i].cycles; |
| 1086 | |
| 1087 | packets_rx->current = pl_test_dat[i].packets; |
| 1088 | calc_loss(conn, &expected, &loss); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1089 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1090 | if (loss != pl_test_dat[i].loss |
| 1091 | || expected != pl_test_dat[i].expected) { |
| 1092 | printf |
| 1093 | ("FAIL: Wrong exp/loss at idx(%d) Loss(%d vs. %d) Exp(%u vs. %u)\n", |
| 1094 | i, loss, pl_test_dat[i].loss, expected, |
| 1095 | pl_test_dat[i].expected); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1096 | } |
Philipp Maier | cede2a4 | 2018-07-03 14:14:21 +0200 | [diff] [blame] | 1097 | |
| 1098 | mgcp_conn_free_all(&endp); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1099 | } |
Philipp Maier | cede2a4 | 2018-07-03 14:14:21 +0200 | [diff] [blame] | 1100 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1101 | } |
| 1102 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1103 | int mgcp_parse_stats(struct msgb *msg, uint32_t *ps, uint32_t *os, |
| 1104 | uint32_t *pr, uint32_t *_or, int *loss, |
| 1105 | uint32_t *jitter) |
| 1106 | { |
| 1107 | char *line, *save; |
| 1108 | int rc; |
| 1109 | |
| 1110 | /* initialize with bad values */ |
| 1111 | *ps = *os = *pr = *_or = *jitter = UINT_MAX; |
| 1112 | *loss = INT_MAX; |
| 1113 | |
| 1114 | line = strtok_r((char *)msg->l2h, "\r\n", &save); |
| 1115 | if (!line) |
| 1116 | return -1; |
| 1117 | |
| 1118 | /* this can only parse the message that is created above... */ |
| 1119 | for_each_non_empty_line(line, save) { |
| 1120 | switch (line[0]) { |
| 1121 | case 'P': |
| 1122 | rc = sscanf(line, |
| 1123 | "P: PS=%u, OS=%u, PR=%u, OR=%u, PL=%d, JI=%u", |
| 1124 | ps, os, pr, _or, loss, jitter); |
| 1125 | return rc == 6 ? 0 : -1; |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | return -1; |
| 1130 | } |
| 1131 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1132 | static void test_mgcp_stats(void) |
| 1133 | { |
| 1134 | printf("Testing stat parsing\n"); |
| 1135 | |
| 1136 | uint32_t bps, bos, pr, _or, jitter; |
| 1137 | struct msgb *msg; |
| 1138 | int loss; |
| 1139 | int rc; |
| 1140 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1141 | msg = create_msg(DLCX_RET, NULL); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1142 | rc = mgcp_parse_stats(msg, &bps, &bos, &pr, &_or, &loss, &jitter); |
| 1143 | printf("Parsing result: %d\n", rc); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1144 | if (bps != 0 || bos != 0 || pr != 0 || _or != 0 || loss != 0 |
| 1145 | || jitter != 0) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1146 | printf("FAIL: Parsing failed1.\n"); |
| 1147 | msgb_free(msg); |
| 1148 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1149 | msg = |
| 1150 | create_msg |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1151 | ("250 7 OK\r\nP: PS=10, OS=20, PR=30, OR=40, PL=-3, JI=40\r\n", NULL); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1152 | rc = mgcp_parse_stats(msg, &bps, &bos, &pr, &_or, &loss, &jitter); |
| 1153 | printf("Parsing result: %d\n", rc); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1154 | if (bps != 10 || bos != 20 || pr != 30 || _or != 40 || loss != -3 |
| 1155 | || jitter != 40) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1156 | printf("FAIL: Parsing failed2.\n"); |
| 1157 | msgb_free(msg); |
| 1158 | } |
| 1159 | |
| 1160 | struct rtp_packet_info { |
| 1161 | float txtime; |
| 1162 | int len; |
| 1163 | char *data; |
| 1164 | }; |
| 1165 | |
| 1166 | struct rtp_packet_info test_rtp_packets1[] = { |
| 1167 | /* RTP: SeqNo=0, TS=0 */ |
| 1168 | {0.000000, 20, "\x80\x62\x00\x00\x00\x00\x00\x00\x11\x22\x33\x44" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1169 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1170 | /* RTP: SeqNo=1, TS=160 */ |
| 1171 | {0.020000, 20, "\x80\x62\x00\x01\x00\x00\x00\xA0\x11\x22\x33\x44" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1172 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1173 | /* RTP: SeqNo=2, TS=320 */ |
| 1174 | {0.040000, 20, "\x80\x62\x00\x02\x00\x00\x01\x40\x11\x22\x33\x44" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1175 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1176 | /* Repeat RTP timestamp: */ |
| 1177 | /* RTP: SeqNo=3, TS=320 */ |
| 1178 | {0.060000, 20, "\x80\x62\x00\x03\x00\x00\x01\x40\x11\x22\x33\x44" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1179 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1180 | /* RTP: SeqNo=4, TS=480 */ |
| 1181 | {0.080000, 20, "\x80\x62\x00\x04\x00\x00\x01\xE0\x11\x22\x33\x44" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1182 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1183 | /* RTP: SeqNo=5, TS=640 */ |
| 1184 | {0.100000, 20, "\x80\x62\x00\x05\x00\x00\x02\x80\x11\x22\x33\x44" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1185 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1186 | /* Double skip RTP timestamp (delta = 2*160): */ |
| 1187 | /* RTP: SeqNo=6, TS=960 */ |
| 1188 | {0.120000, 20, "\x80\x62\x00\x06\x00\x00\x03\xC0\x11\x22\x33\x44" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1189 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1190 | /* RTP: SeqNo=7, TS=1120 */ |
| 1191 | {0.140000, 20, "\x80\x62\x00\x07\x00\x00\x04\x60\x11\x22\x33\x44" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1192 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1193 | /* RTP: SeqNo=8, TS=1280 */ |
| 1194 | {0.160000, 20, "\x80\x62\x00\x08\x00\x00\x05\x00\x11\x22\x33\x44" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1195 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1196 | /* Non 20ms RTP timestamp (delta = 120): */ |
| 1197 | /* RTP: SeqNo=9, TS=1400 */ |
| 1198 | {0.180000, 20, "\x80\x62\x00\x09\x00\x00\x05\x78\x11\x22\x33\x44" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1199 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1200 | /* RTP: SeqNo=10, TS=1560 */ |
| 1201 | {0.200000, 20, "\x80\x62\x00\x0A\x00\x00\x06\x18\x11\x22\x33\x44" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1202 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1203 | /* RTP: SeqNo=11, TS=1720 */ |
| 1204 | {0.220000, 20, "\x80\x62\x00\x0B\x00\x00\x06\xB8\x11\x22\x33\x44" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1205 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1206 | /* SSRC changed to 0x10203040, RTP timestamp jump */ |
| 1207 | /* RTP: SeqNo=12, TS=34688 */ |
| 1208 | {0.240000, 20, "\x80\x62\x00\x0C\x00\x00\x87\x80\x10\x20\x30\x40" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1209 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1210 | /* RTP: SeqNo=13, TS=34848 */ |
| 1211 | {0.260000, 20, "\x80\x62\x00\x0D\x00\x00\x88\x20\x10\x20\x30\x40" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1212 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1213 | /* RTP: SeqNo=14, TS=35008 */ |
| 1214 | {0.280000, 20, "\x80\x62\x00\x0E\x00\x00\x88\xC0\x10\x20\x30\x40" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1215 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1216 | /* Non 20ms RTP timestamp (delta = 120): */ |
| 1217 | /* RTP: SeqNo=15, TS=35128 */ |
| 1218 | {0.300000, 20, "\x80\x62\x00\x0F\x00\x00\x89\x38\x10\x20\x30\x40" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1219 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1220 | /* RTP: SeqNo=16, TS=35288 */ |
| 1221 | {0.320000, 20, "\x80\x62\x00\x10\x00\x00\x89\xD8\x10\x20\x30\x40" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1222 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1223 | /* RTP: SeqNo=17, TS=35448 */ |
| 1224 | {0.340000, 20, "\x80\x62\x00\x11\x00\x00\x8A\x78\x10\x20\x30\x40" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1225 | "\x01\x23\x45\x67\x8A\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1226 | /* SeqNo increment by 2, RTP timestamp delta = 320: */ |
| 1227 | /* RTP: SeqNo=19, TS=35768 */ |
| 1228 | {0.360000, 20, "\x80\x62\x00\x13\x00\x00\x8B\xB8\x10\x20\x30\x40" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1229 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1230 | /* RTP: SeqNo=20, TS=35928 */ |
| 1231 | {0.380000, 20, "\x80\x62\x00\x14\x00\x00\x8C\x58\x10\x20\x30\x40" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1232 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1233 | /* RTP: SeqNo=21, TS=36088 */ |
| 1234 | {0.380000, 20, "\x80\x62\x00\x15\x00\x00\x8C\xF8\x10\x20\x30\x40" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1235 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1236 | /* Repeat last packet */ |
| 1237 | /* RTP: SeqNo=21, TS=36088 */ |
| 1238 | {0.400000, 20, "\x80\x62\x00\x15\x00\x00\x8C\xF8\x10\x20\x30\x40" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1239 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1240 | /* RTP: SeqNo=22, TS=36248 */ |
| 1241 | {0.420000, 20, "\x80\x62\x00\x16\x00\x00\x8D\x98\x10\x20\x30\x40" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1242 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1243 | /* RTP: SeqNo=23, TS=36408 */ |
| 1244 | {0.440000, 20, "\x80\x62\x00\x17\x00\x00\x8E\x38\x10\x20\x30\x40" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1245 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1246 | /* Don't increment SeqNo but increment timestamp by 160 */ |
| 1247 | /* RTP: SeqNo=23, TS=36568 */ |
| 1248 | {0.460000, 20, "\x80\x62\x00\x17\x00\x00\x8E\xD8\x10\x20\x30\x40" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1249 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1250 | /* RTP: SeqNo=24, TS=36728 */ |
| 1251 | {0.480000, 20, "\x80\x62\x00\x18\x00\x00\x8F\x78\x10\x20\x30\x40" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1252 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1253 | /* RTP: SeqNo=25, TS=36888 */ |
| 1254 | {0.500000, 20, "\x80\x62\x00\x19\x00\x00\x90\x18\x10\x20\x30\x40" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1255 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1256 | /* SSRC changed to 0x50607080, RTP timestamp jump, Delay of 1.5s, |
| 1257 | * SeqNo jump */ |
| 1258 | /* RTP: SeqNo=1000, TS=160000 */ |
| 1259 | {2.000000, 20, "\x80\x62\x03\xE8\x00\x02\x71\x00\x50\x60\x70\x80" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1260 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1261 | /* RTP: SeqNo=1001, TS=160160 */ |
| 1262 | {2.020000, 20, "\x80\x62\x03\xE9\x00\x02\x71\xA0\x50\x60\x70\x80" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1263 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1264 | /* RTP: SeqNo=1002, TS=160320 */ |
| 1265 | {2.040000, 20, "\x80\x62\x03\xEA\x00\x02\x72\x40\x50\x60\x70\x80" |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1266 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1267 | }; |
| 1268 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1269 | void mgcp_patch_and_count(struct mgcp_endpoint *endp, |
| 1270 | struct mgcp_rtp_state *state, |
| 1271 | struct mgcp_rtp_end *rtp_end, |
| 1272 | struct sockaddr_in *addr, char *data, int len); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1273 | |
| 1274 | static void test_packet_error_detection(int patch_ssrc, int patch_ts) |
| 1275 | { |
| 1276 | int i; |
| 1277 | |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1278 | struct mgcp_trunk trunk; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1279 | struct mgcp_endpoint endp; |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1280 | struct mgcp_endpoint *endpoints[1]; |
Oliver Smith | e36b775 | 2019-01-22 16:31:36 +0100 | [diff] [blame] | 1281 | struct mgcp_config cfg = {0}; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1282 | struct mgcp_rtp_state state; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1283 | struct mgcp_rtp_end *rtp; |
| 1284 | struct sockaddr_in addr = { 0 }; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1285 | char buffer[4096]; |
| 1286 | uint32_t last_ssrc = 0; |
| 1287 | uint32_t last_timestamp = 0; |
| 1288 | uint32_t last_seqno = 0; |
Philipp Maier | 9e1d164 | 2018-05-09 16:26:34 +0200 | [diff] [blame] | 1289 | uint64_t last_in_ts_err_cnt = 0; |
| 1290 | uint64_t last_out_ts_err_cnt = 0; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1291 | struct mgcp_conn_rtp *conn = NULL; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1292 | struct mgcp_conn *_conn = NULL; |
Philipp Maier | 9e1d164 | 2018-05-09 16:26:34 +0200 | [diff] [blame] | 1293 | struct rate_ctr test_ctr_in; |
| 1294 | struct rate_ctr test_ctr_out; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1295 | |
| 1296 | printf("Testing packet error detection%s%s.\n", |
| 1297 | patch_ssrc ? ", patch SSRC" : "", |
| 1298 | patch_ts ? ", patch timestamps" : ""); |
| 1299 | |
| 1300 | memset(&trunk, 0, sizeof(trunk)); |
| 1301 | memset(&endp, 0, sizeof(endp)); |
| 1302 | memset(&state, 0, sizeof(state)); |
| 1303 | |
Philipp Maier | 9e1d164 | 2018-05-09 16:26:34 +0200 | [diff] [blame] | 1304 | memset(&test_ctr_in, 0, sizeof(test_ctr_in)); |
| 1305 | memset(&test_ctr_out, 0, sizeof(test_ctr_out)); |
| 1306 | state.in_stream.err_ts_ctr = &test_ctr_in; |
| 1307 | state.out_stream.err_ts_ctr = &test_ctr_out; |
| 1308 | |
Oliver Smith | e36b775 | 2019-01-22 16:31:36 +0100 | [diff] [blame] | 1309 | endp.cfg = &cfg; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1310 | endp.type = &ep_typeset.rtp; |
| 1311 | |
Philipp Maier | fcd0655 | 2017-11-10 17:32:22 +0100 | [diff] [blame] | 1312 | trunk.vty_number_endpoints = 1; |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1313 | trunk.endpoints = endpoints; |
| 1314 | trunk.endpoints[0] = &endp; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1315 | trunk.force_constant_ssrc = patch_ssrc; |
| 1316 | trunk.force_aligned_timing = patch_ts; |
| 1317 | |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1318 | endp.trunk = &trunk; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1319 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1320 | INIT_LLIST_HEAD(&endp.conns); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1321 | _conn = mgcp_conn_alloc(NULL, &endp, MGCP_CONN_TYPE_RTP, |
| 1322 | "test-connection"); |
| 1323 | OSMO_ASSERT(_conn); |
| 1324 | conn = mgcp_conn_get_rtp(&endp, _conn->id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1325 | OSMO_ASSERT(conn); |
| 1326 | |
| 1327 | rtp = &conn->end; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1328 | |
Philipp Maier | 228e591 | 2019-03-05 13:56:59 +0100 | [diff] [blame] | 1329 | OSMO_ASSERT(mgcp_codec_add(conn, PTYPE_UNDEFINED, "AMR/8000/1", NULL) == 0); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1330 | rtp->codec = &rtp->codecs[0]; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1331 | |
| 1332 | for (i = 0; i < ARRAY_SIZE(test_rtp_packets1); ++i) { |
| 1333 | struct rtp_packet_info *info = test_rtp_packets1 + i; |
| 1334 | |
| 1335 | force_monotonic_time_us = round(1000000.0 * info->txtime); |
| 1336 | |
| 1337 | OSMO_ASSERT(info->len <= sizeof(buffer)); |
| 1338 | OSMO_ASSERT(info->len >= 0); |
| 1339 | memmove(buffer, info->data, info->len); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1340 | mgcp_rtp_end_config(&endp, 1, rtp); |
| 1341 | |
| 1342 | mgcp_patch_and_count(&endp, &state, rtp, &addr, |
| 1343 | buffer, info->len); |
| 1344 | |
| 1345 | if (state.out_stream.ssrc != last_ssrc) { |
| 1346 | printf("Output SSRC changed to %08x\n", |
| 1347 | state.out_stream.ssrc); |
| 1348 | last_ssrc = state.out_stream.ssrc; |
| 1349 | } |
| 1350 | |
| 1351 | printf("In TS: %d, dTS: %d, Seq: %d\n", |
| 1352 | state.in_stream.last_timestamp, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1353 | state.in_stream.last_tsdelta, state.in_stream.last_seq); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1354 | |
| 1355 | printf("Out TS change: %d, dTS: %d, Seq change: %d, " |
Philipp Maier | 9e1d164 | 2018-05-09 16:26:34 +0200 | [diff] [blame] | 1356 | "TS Err change: in +%u, out +%u\n", |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1357 | state.out_stream.last_timestamp - last_timestamp, |
| 1358 | state.out_stream.last_tsdelta, |
| 1359 | state.out_stream.last_seq - last_seqno, |
Philipp Maier | 9e1d164 | 2018-05-09 16:26:34 +0200 | [diff] [blame] | 1360 | (unsigned int) (state.in_stream.err_ts_ctr->current - last_in_ts_err_cnt), |
| 1361 | (unsigned int) (state.out_stream.err_ts_ctr->current - last_out_ts_err_cnt)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1362 | |
| 1363 | printf("Stats: Jitter = %u, Transit = %d\n", |
Harald Welte | 49e3d5a | 2017-12-25 09:47:57 +0100 | [diff] [blame] | 1364 | calc_jitter(&state), state.stats.transit); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1365 | |
Philipp Maier | 9e1d164 | 2018-05-09 16:26:34 +0200 | [diff] [blame] | 1366 | last_in_ts_err_cnt = state.in_stream.err_ts_ctr->current; |
| 1367 | last_out_ts_err_cnt = state.out_stream.err_ts_ctr->current; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1368 | last_timestamp = state.out_stream.last_timestamp; |
| 1369 | last_seqno = state.out_stream.last_seq; |
| 1370 | } |
| 1371 | |
| 1372 | force_monotonic_time_us = -1; |
Neels Hofmeyr | d20910c | 2017-11-18 21:27:50 +0100 | [diff] [blame] | 1373 | mgcp_conn_free_all(&endp); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | static void test_multilple_codec(void) |
| 1377 | { |
| 1378 | struct mgcp_config *cfg; |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1379 | struct mgcp_trunk *trunk2; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1380 | struct mgcp_endpoint *endp; |
| 1381 | struct msgb *inp, *resp; |
| 1382 | struct in_addr addr; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1383 | struct mgcp_conn_rtp *conn = NULL; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1384 | char conn_id[256]; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1385 | |
| 1386 | printf("Testing multiple payload types\n"); |
| 1387 | |
| 1388 | cfg = mgcp_config_alloc(); |
Harald Welte | c39b1bf | 2020-03-08 11:29:39 +0100 | [diff] [blame] | 1389 | cfg->virt_trunk->vty_number_endpoints = 64; |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1390 | mgcp_trunk_alloc_endpts(cfg->virt_trunk); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1391 | cfg->policy_cb = mgcp_test_policy_cb; |
Pau Espin Pedrol | d071a30 | 2019-09-19 17:39:31 +0200 | [diff] [blame] | 1392 | |
Harald Welte | c39b1bf | 2020-03-08 11:29:39 +0100 | [diff] [blame] | 1393 | trunk2 = mgcp_trunk_alloc(cfg, MGCP_TRUNK_E1, 1); |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1394 | mgcp_trunk_alloc_endpts(trunk2); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1395 | |
| 1396 | /* Allocate endpoint 1@mgw with two codecs */ |
| 1397 | last_endpoint = -1; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1398 | inp = create_msg(CRCX_MULT_1, NULL); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1399 | resp = mgcp_handle_message(cfg, inp); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1400 | OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id, |
| 1401 | sizeof(conn_id)) == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1402 | msgb_free(inp); |
| 1403 | msgb_free(resp); |
| 1404 | |
| 1405 | OSMO_ASSERT(last_endpoint == 1); |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1406 | endp = cfg->virt_trunk->endpoints[last_endpoint]; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1407 | conn = mgcp_conn_get_rtp(endp, conn_id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1408 | OSMO_ASSERT(conn); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1409 | OSMO_ASSERT(conn->end.codec->payload_type == 18); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1410 | |
| 1411 | /* Allocate 2@mgw with three codecs, last one ignored */ |
| 1412 | last_endpoint = -1; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1413 | inp = create_msg(CRCX_MULT_2, NULL); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1414 | resp = mgcp_handle_message(cfg, inp); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1415 | OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id, |
| 1416 | sizeof(conn_id)) == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1417 | msgb_free(inp); |
| 1418 | msgb_free(resp); |
| 1419 | |
| 1420 | OSMO_ASSERT(last_endpoint == 2); |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1421 | endp = cfg->virt_trunk->endpoints[last_endpoint]; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1422 | conn = mgcp_conn_get_rtp(endp, conn_id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1423 | OSMO_ASSERT(conn); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1424 | OSMO_ASSERT(conn->end.codec->payload_type == 18); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1425 | |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1426 | /* Allocate 3@mgw with no codecs, check for PT == 0 */ |
| 1427 | /* Note: It usually makes no sense to leave the payload type list |
| 1428 | * out. However RFC 2327 does not clearly forbid this case and |
| 1429 | * it makes and since we already decided in OS#2658 that a missing |
| 1430 | * LCO should pick a sane default codec, it makes sense to expect |
| 1431 | * the same behaviour if SDP lacks proper payload type information */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1432 | last_endpoint = -1; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1433 | inp = create_msg(CRCX_MULT_3, NULL); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1434 | resp = mgcp_handle_message(cfg, inp); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1435 | OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id, |
| 1436 | sizeof(conn_id)) == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1437 | msgb_free(inp); |
| 1438 | msgb_free(resp); |
| 1439 | |
| 1440 | OSMO_ASSERT(last_endpoint == 3); |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1441 | endp = cfg->virt_trunk->endpoints[last_endpoint]; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1442 | conn = mgcp_conn_get_rtp(endp, conn_id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1443 | OSMO_ASSERT(conn); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1444 | OSMO_ASSERT(conn->end.codec->payload_type == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1445 | |
| 1446 | /* Allocate 4@mgw with a single codec */ |
| 1447 | last_endpoint = -1; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1448 | inp = create_msg(CRCX_MULT_4, NULL); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1449 | resp = mgcp_handle_message(cfg, inp); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1450 | OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id, |
| 1451 | sizeof(conn_id)) == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1452 | msgb_free(inp); |
| 1453 | msgb_free(resp); |
| 1454 | |
| 1455 | OSMO_ASSERT(last_endpoint == 4); |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1456 | endp = cfg->virt_trunk->endpoints[last_endpoint]; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1457 | conn = mgcp_conn_get_rtp(endp, conn_id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1458 | OSMO_ASSERT(conn); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1459 | OSMO_ASSERT(conn->end.codec->payload_type == 18); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1460 | |
Philipp Maier | 7f90ddb | 2020-06-02 21:52:53 +0200 | [diff] [blame] | 1461 | /* Allocate 5@mgw and let osmo-mgw pick a codec from the list */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1462 | last_endpoint = -1; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1463 | inp = create_msg(CRCX_MULT_GSM_EXACT, NULL); |
Harald Welte | c39b1bf | 2020-03-08 11:29:39 +0100 | [diff] [blame] | 1464 | cfg->virt_trunk->no_audio_transcoding = 1; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1465 | resp = mgcp_handle_message(cfg, inp); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1466 | OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id, |
| 1467 | sizeof(conn_id)) == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1468 | msgb_free(inp); |
| 1469 | msgb_free(resp); |
| 1470 | |
| 1471 | OSMO_ASSERT(last_endpoint == 5); |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1472 | endp = cfg->virt_trunk->endpoints[last_endpoint]; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1473 | conn = mgcp_conn_get_rtp(endp, conn_id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1474 | OSMO_ASSERT(conn); |
Philipp Maier | 7f90ddb | 2020-06-02 21:52:53 +0200 | [diff] [blame] | 1475 | OSMO_ASSERT(conn->end.codec->payload_type == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1476 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1477 | inp = create_msg(MDCX_NAT_DUMMY, conn_id); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1478 | last_endpoint = -1; |
| 1479 | resp = mgcp_handle_message(cfg, inp); |
| 1480 | msgb_free(inp); |
| 1481 | msgb_free(resp); |
| 1482 | OSMO_ASSERT(last_endpoint == 5); |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1483 | endp = cfg->virt_trunk->endpoints[last_endpoint]; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1484 | conn = mgcp_conn_get_rtp(endp, conn_id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1485 | OSMO_ASSERT(conn); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1486 | OSMO_ASSERT(conn->end.codec->payload_type == 3); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1487 | OSMO_ASSERT(conn->end.rtp_port == htons(16434)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1488 | memset(&addr, 0, sizeof(addr)); |
| 1489 | inet_aton("8.8.8.8", &addr); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1490 | OSMO_ASSERT(conn->end.addr.s_addr == addr.s_addr); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1491 | |
| 1492 | /* Check what happens without that flag */ |
| 1493 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1494 | /* Free the previous endpoint and the data and |
| 1495 | * check if the connection really vanished... */ |
Philipp Maier | 1355d7e | 2018-02-01 14:30:06 +0100 | [diff] [blame] | 1496 | mgcp_endp_release(endp); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1497 | talloc_free(endp->last_response); |
| 1498 | talloc_free(endp->last_trans); |
| 1499 | endp->last_response = endp->last_trans = NULL; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1500 | conn = mgcp_conn_get_rtp(endp, conn_id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1501 | OSMO_ASSERT(!conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1502 | |
| 1503 | last_endpoint = -1; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1504 | inp = create_msg(CRCX_MULT_GSM_EXACT, NULL); |
Harald Welte | c39b1bf | 2020-03-08 11:29:39 +0100 | [diff] [blame] | 1505 | cfg->virt_trunk->no_audio_transcoding = 0; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1506 | resp = mgcp_handle_message(cfg, inp); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1507 | OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id, |
| 1508 | sizeof(conn_id)) == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1509 | msgb_free(inp); |
| 1510 | msgb_free(resp); |
| 1511 | |
| 1512 | OSMO_ASSERT(last_endpoint == 5); |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1513 | endp = cfg->virt_trunk->endpoints[last_endpoint]; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1514 | conn = mgcp_conn_get_rtp(endp, conn_id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1515 | OSMO_ASSERT(conn); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1516 | OSMO_ASSERT(conn->end.codec->payload_type == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1517 | |
Pau Espin Pedrol | d071a30 | 2019-09-19 17:39:31 +0200 | [diff] [blame] | 1518 | mgcp_endpoints_release(trunk2); |
Harald Welte | c39b1bf | 2020-03-08 11:29:39 +0100 | [diff] [blame] | 1519 | mgcp_endpoints_release(cfg->virt_trunk); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1520 | talloc_free(cfg); |
| 1521 | } |
| 1522 | |
| 1523 | static void test_no_cycle(void) |
| 1524 | { |
| 1525 | struct mgcp_config *cfg; |
| 1526 | struct mgcp_endpoint *endp; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1527 | struct mgcp_conn_rtp *conn = NULL; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1528 | struct mgcp_conn *_conn = NULL; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1529 | |
| 1530 | printf("Testing no sequence flow on initial packet\n"); |
| 1531 | |
| 1532 | cfg = mgcp_config_alloc(); |
Harald Welte | c39b1bf | 2020-03-08 11:29:39 +0100 | [diff] [blame] | 1533 | cfg->virt_trunk->vty_number_endpoints = 64; |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1534 | mgcp_trunk_alloc_endpts(cfg->virt_trunk); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1535 | |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1536 | endp = cfg->virt_trunk->endpoints[1]; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1537 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1538 | _conn = mgcp_conn_alloc(NULL, endp, MGCP_CONN_TYPE_RTP, |
| 1539 | "test-connection"); |
| 1540 | OSMO_ASSERT(_conn); |
| 1541 | conn = mgcp_conn_get_rtp(endp, _conn->id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1542 | OSMO_ASSERT(conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1543 | |
Harald Welte | 49e3d5a | 2017-12-25 09:47:57 +0100 | [diff] [blame] | 1544 | OSMO_ASSERT(conn->state.stats.initialized == 0); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1545 | |
| 1546 | mgcp_rtp_annex_count(endp, &conn->state, 0, 0, 2342); |
Harald Welte | 49e3d5a | 2017-12-25 09:47:57 +0100 | [diff] [blame] | 1547 | OSMO_ASSERT(conn->state.stats.initialized == 1); |
| 1548 | OSMO_ASSERT(conn->state.stats.cycles == 0); |
| 1549 | OSMO_ASSERT(conn->state.stats.max_seq == 0); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1550 | |
| 1551 | mgcp_rtp_annex_count(endp, &conn->state, 1, 0, 2342); |
Harald Welte | 49e3d5a | 2017-12-25 09:47:57 +0100 | [diff] [blame] | 1552 | OSMO_ASSERT(conn->state.stats.initialized == 1); |
| 1553 | OSMO_ASSERT(conn->state.stats.cycles == 0); |
| 1554 | OSMO_ASSERT(conn->state.stats.max_seq == 1); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1555 | |
| 1556 | /* now jump.. */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1557 | mgcp_rtp_annex_count(endp, &conn->state, UINT16_MAX, 0, 2342); |
Harald Welte | 49e3d5a | 2017-12-25 09:47:57 +0100 | [diff] [blame] | 1558 | OSMO_ASSERT(conn->state.stats.initialized == 1); |
| 1559 | OSMO_ASSERT(conn->state.stats.cycles == 0); |
| 1560 | OSMO_ASSERT(conn->state.stats.max_seq == UINT16_MAX); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1561 | |
| 1562 | /* and wrap */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1563 | mgcp_rtp_annex_count(endp, &conn->state, 0, 0, 2342); |
Harald Welte | 49e3d5a | 2017-12-25 09:47:57 +0100 | [diff] [blame] | 1564 | OSMO_ASSERT(conn->state.stats.initialized == 1); |
| 1565 | OSMO_ASSERT(conn->state.stats.cycles == UINT16_MAX + 1); |
| 1566 | OSMO_ASSERT(conn->state.stats.max_seq == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1567 | |
Harald Welte | c39b1bf | 2020-03-08 11:29:39 +0100 | [diff] [blame] | 1568 | mgcp_endpoints_release(cfg->virt_trunk); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1569 | talloc_free(cfg); |
| 1570 | } |
| 1571 | |
| 1572 | static void test_no_name(void) |
| 1573 | { |
Philipp Maier | 14b27a8 | 2020-06-02 20:15:30 +0200 | [diff] [blame] | 1574 | struct mgcp_trunk *trunk2; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1575 | struct mgcp_config *cfg; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1576 | struct msgb *inp, *msg; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1577 | |
| 1578 | printf("Testing no rtpmap name\n"); |
| 1579 | cfg = mgcp_config_alloc(); |
| 1580 | |
Harald Welte | c39b1bf | 2020-03-08 11:29:39 +0100 | [diff] [blame] | 1581 | cfg->virt_trunk->vty_number_endpoints = 64; |
| 1582 | cfg->virt_trunk->audio_send_name = 0; |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1583 | mgcp_trunk_alloc_endpts(cfg->virt_trunk); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1584 | |
| 1585 | cfg->policy_cb = mgcp_test_policy_cb; |
| 1586 | |
Harald Welte | c39b1bf | 2020-03-08 11:29:39 +0100 | [diff] [blame] | 1587 | trunk2 = mgcp_trunk_alloc(cfg, MGCP_TRUNK_E1, 1); |
Philipp Maier | c66ab2c | 2020-06-02 20:55:34 +0200 | [diff] [blame] | 1588 | mgcp_trunk_alloc_endpts(trunk2); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1589 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1590 | inp = create_msg(CRCX, NULL); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1591 | msg = mgcp_handle_message(cfg, inp); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1592 | |
| 1593 | if (check_response(msg->data, CRCX_RET_NO_RTPMAP) != 0) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1594 | printf("FAILED: there should not be a RTPMAP: %s\n", |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1595 | (char *)msg->data); |
| 1596 | OSMO_ASSERT(false); |
| 1597 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1598 | msgb_free(inp); |
| 1599 | msgb_free(msg); |
| 1600 | |
Pau Espin Pedrol | d071a30 | 2019-09-19 17:39:31 +0200 | [diff] [blame] | 1601 | mgcp_endpoints_release(trunk2); |
Harald Welte | c39b1bf | 2020-03-08 11:29:39 +0100 | [diff] [blame] | 1602 | mgcp_endpoints_release(cfg->virt_trunk); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1603 | talloc_free(cfg); |
| 1604 | } |
| 1605 | |
| 1606 | static void test_osmux_cid(void) |
| 1607 | { |
| 1608 | int id, i; |
| 1609 | |
Pau Espin Pedrol | 8de58e7 | 2019-04-24 13:33:46 +0200 | [diff] [blame] | 1610 | OSMO_ASSERT(osmux_cid_pool_count_used() == 0); |
| 1611 | |
| 1612 | id = osmux_cid_pool_get_next(); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1613 | OSMO_ASSERT(id == 0); |
Pau Espin Pedrol | 8de58e7 | 2019-04-24 13:33:46 +0200 | [diff] [blame] | 1614 | OSMO_ASSERT(osmux_cid_pool_count_used() == 1); |
| 1615 | |
| 1616 | osmux_cid_pool_get(30); |
| 1617 | OSMO_ASSERT(osmux_cid_pool_count_used() == 2); |
| 1618 | osmux_cid_pool_get(30); |
| 1619 | OSMO_ASSERT(osmux_cid_pool_count_used() == 2); |
| 1620 | |
| 1621 | osmux_cid_pool_put(id); |
| 1622 | OSMO_ASSERT(osmux_cid_pool_count_used() == 1); |
| 1623 | osmux_cid_pool_put(30); |
| 1624 | OSMO_ASSERT(osmux_cid_pool_count_used() == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1625 | |
| 1626 | for (i = 0; i < 256; ++i) { |
Pau Espin Pedrol | 8de58e7 | 2019-04-24 13:33:46 +0200 | [diff] [blame] | 1627 | id = osmux_cid_pool_get_next(); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1628 | OSMO_ASSERT(id == i); |
Pau Espin Pedrol | 8de58e7 | 2019-04-24 13:33:46 +0200 | [diff] [blame] | 1629 | OSMO_ASSERT(osmux_cid_pool_count_used() == i + 1); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1630 | } |
| 1631 | |
Pau Espin Pedrol | 8de58e7 | 2019-04-24 13:33:46 +0200 | [diff] [blame] | 1632 | id = osmux_cid_pool_get_next(); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1633 | OSMO_ASSERT(id == -1); |
| 1634 | |
| 1635 | for (i = 0; i < 256; ++i) |
Pau Espin Pedrol | 8de58e7 | 2019-04-24 13:33:46 +0200 | [diff] [blame] | 1636 | osmux_cid_pool_put(i); |
| 1637 | OSMO_ASSERT(osmux_cid_pool_count_used() == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | static const struct log_info_cat log_categories[] = { |
| 1641 | }; |
| 1642 | |
| 1643 | const struct log_info log_info = { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1644 | .cat = log_categories, |
| 1645 | .num_cat = ARRAY_SIZE(log_categories), |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1646 | }; |
| 1647 | |
Philipp Maier | 3d7b58d | 2018-06-06 09:35:31 +0200 | [diff] [blame] | 1648 | static void test_get_lco_identifier(void) |
| 1649 | { |
| 1650 | char *test; |
| 1651 | printf("Testing get_lco_identifier()\n"); |
| 1652 | |
| 1653 | /* Normal case at the beginning */ |
| 1654 | test = "p:10, a:PCMU"; |
| 1655 | printf("%s -> %s\n", test, get_lco_identifier(test)); |
| 1656 | |
| 1657 | test = "p:10, a:PCMU"; |
| 1658 | printf("%s -> %s\n", test, get_lco_identifier(test)); |
| 1659 | |
| 1660 | /* Begin parsing in the middle of the value part of |
| 1661 | * the previous LCO option value */ |
| 1662 | test = "XXXX, p:10, a:PCMU"; |
| 1663 | printf("'%s' -> '%s'\n", test, get_lco_identifier(test)); |
| 1664 | |
| 1665 | test = "XXXX,p:10,a:PCMU"; |
| 1666 | printf("'%s' -> '%s'\n", test, get_lco_identifier(test)); |
| 1667 | |
| 1668 | test = "10,a:PCMU"; |
| 1669 | printf("'%s' -> '%s'\n", test, get_lco_identifier(test)); |
| 1670 | |
| 1671 | test = "10, a:PCMU"; |
| 1672 | printf("'%s' -> '%s'\n", test, get_lco_identifier(test)); |
| 1673 | |
| 1674 | test = "10,a: PCMU"; |
| 1675 | printf("'%s' -> '%s'\n", test, get_lco_identifier(test)); |
| 1676 | |
| 1677 | test = "10 ,a: PCMU"; |
| 1678 | printf("'%s' -> '%s'\n", test, get_lco_identifier(test)); |
| 1679 | |
| 1680 | /* Begin parsing right at the end of the previous LCO |
| 1681 | * option value */ |
| 1682 | test = ", a:PCMU"; |
| 1683 | printf("'%s' -> '%s'\n", test, get_lco_identifier(test)); |
| 1684 | |
| 1685 | test = " a:PCMU"; |
| 1686 | printf("'%s' -> '%s'\n", test, get_lco_identifier(test)); |
| 1687 | |
| 1688 | /* Empty string, result should be (null) */ |
| 1689 | test = ""; |
| 1690 | printf("'%s' -> '%s'\n", test, get_lco_identifier(test)); |
| 1691 | |
| 1692 | /* Missing colons, result should be (null) */ |
| 1693 | test = "p10, aPCMU"; |
| 1694 | printf("%s -> %s\n", test, get_lco_identifier(test)); |
| 1695 | |
| 1696 | /* Colon separated from the identifier, result should be (null) */ |
| 1697 | test = "10,a :PCMU"; |
| 1698 | printf("'%s' -> '%s'\n", test, get_lco_identifier(test)); |
| 1699 | } |
| 1700 | |
| 1701 | static void test_check_local_cx_options(void *ctx) |
| 1702 | { |
| 1703 | /* Legal cases */ |
| 1704 | OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:PCMU") == 0); |
| 1705 | OSMO_ASSERT(check_local_cx_options(ctx, "a:PCMU") == 0); |
| 1706 | OSMO_ASSERT(check_local_cx_options(ctx, "a:PCMU, p:10, IN:10") == 0); |
| 1707 | OSMO_ASSERT(check_local_cx_options(ctx, "one:AAA, two:BB, tree:C") == |
| 1708 | 0); |
| 1709 | OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:PCMU") == 0); |
| 1710 | OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:G726-32") == 0); |
| 1711 | OSMO_ASSERT(check_local_cx_options(ctx, "p:10-20, b:64") == 0); |
| 1712 | OSMO_ASSERT(check_local_cx_options(ctx, "b:32-64, e:off") == 0); |
| 1713 | OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:PCMU;G726-32") == 0); |
| 1714 | |
| 1715 | /* Illegal spaces before and after colon */ |
| 1716 | OSMO_ASSERT(check_local_cx_options(ctx, "a:PCMU, p :10") == -1); |
| 1717 | OSMO_ASSERT(check_local_cx_options(ctx, "a :PCMU, p:10") == -1); |
| 1718 | OSMO_ASSERT(check_local_cx_options(ctx, "p: 10, a:PCMU") == -1); |
| 1719 | |
| 1720 | /* Check if multiple appearances of LCOs are rejected */ |
| 1721 | OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:PCMU, p:10") == -1); |
| 1722 | OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:PCMU, a:PCMU, p:10") == |
| 1723 | -1); |
| 1724 | OSMO_ASSERT(check_local_cx_options(ctx, "p:10, p:10") == -1); |
| 1725 | |
| 1726 | /* Check if empty LCO are rejected */ |
| 1727 | OSMO_ASSERT(check_local_cx_options(ctx, "p: , a:PCMU") == -1); |
| 1728 | OSMO_ASSERT(check_local_cx_options(ctx, "p: , a: PCMU") == -1); |
| 1729 | OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a: PCMU") == -1); |
| 1730 | OSMO_ASSERT(check_local_cx_options(ctx, "p:, a:PCMU") == -1); |
| 1731 | OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:") == -1); |
| 1732 | |
| 1733 | /* Garbeled beginning and ends */ |
| 1734 | OSMO_ASSERT(check_local_cx_options(ctx, ":10, a:10") == -1); |
| 1735 | OSMO_ASSERT(check_local_cx_options(ctx, "10, a:PCMU") == -1); |
| 1736 | OSMO_ASSERT(check_local_cx_options(ctx, ", a:PCMU") == -1); |
| 1737 | OSMO_ASSERT(check_local_cx_options(ctx, " a:PCMU") == -1); |
| 1738 | OSMO_ASSERT(check_local_cx_options(ctx, "a:PCMU,") == -1); |
| 1739 | OSMO_ASSERT(check_local_cx_options(ctx, "a:PCMU, ") == -1); |
| 1740 | |
| 1741 | /* Illegal strings */ |
| 1742 | OSMO_ASSERT(check_local_cx_options(ctx, " ") == -1); |
| 1743 | OSMO_ASSERT(check_local_cx_options(ctx, "") == -1); |
| 1744 | OSMO_ASSERT(check_local_cx_options(ctx, "AAA") == -1); |
| 1745 | OSMO_ASSERT(check_local_cx_options(ctx, ":,") == -1); |
| 1746 | OSMO_ASSERT(check_local_cx_options(ctx, ",:") == -1); |
| 1747 | OSMO_ASSERT(check_local_cx_options(ctx, ",,,") == -1); |
| 1748 | } |
| 1749 | |
Neels Hofmeyr | d2f5e69 | 2019-08-08 21:59:26 +0200 | [diff] [blame] | 1750 | static const struct mgcp_codec_param amr_param_octet_aligned_true = { |
| 1751 | .amr_octet_aligned_present = true, |
| 1752 | .amr_octet_aligned = true, |
| 1753 | }; |
| 1754 | |
Neels Hofmeyr | d2f5e69 | 2019-08-08 21:59:26 +0200 | [diff] [blame] | 1755 | static const struct mgcp_codec_param amr_param_octet_aligned_false = { |
| 1756 | .amr_octet_aligned_present = true, |
| 1757 | .amr_octet_aligned = false, |
| 1758 | }; |
| 1759 | |
| 1760 | static const struct mgcp_codec_param amr_param_octet_aligned_unset = { |
| 1761 | .amr_octet_aligned_present = false, |
| 1762 | }; |
Neels Hofmeyr | d2f5e69 | 2019-08-08 21:59:26 +0200 | [diff] [blame] | 1763 | |
| 1764 | struct testcase_mgcp_codec_pt_translate_codec { |
| 1765 | int payload_type; |
| 1766 | const char *audio_name; |
| 1767 | const struct mgcp_codec_param *param; |
| 1768 | int expect_rc; |
| 1769 | }; |
| 1770 | |
| 1771 | struct testcase_mgcp_codec_pt_translate_expect { |
| 1772 | bool end; |
| 1773 | int payload_type_map[2]; |
| 1774 | }; |
| 1775 | |
| 1776 | struct testcase_mgcp_codec_pt_translate { |
| 1777 | const char *descr; |
| 1778 | /* two conns on an endpoint, each with N configured codecs */ |
| 1779 | struct testcase_mgcp_codec_pt_translate_codec codecs[2][10]; |
| 1780 | struct testcase_mgcp_codec_pt_translate_expect expect[32]; |
| 1781 | }; |
| 1782 | |
| 1783 | static const struct testcase_mgcp_codec_pt_translate test_mgcp_codec_pt_translate_cases[] = { |
| 1784 | { |
| 1785 | .descr = "same order, but differing payload type numbers", |
| 1786 | .codecs = { |
| 1787 | { |
| 1788 | { 112, "AMR/8000/1", &amr_param_octet_aligned_true, }, |
| 1789 | { 0, "PCMU/8000/1", NULL, }, |
| 1790 | { 111, "GSM-HR-08/8000/1", NULL, }, |
| 1791 | }, |
| 1792 | { |
| 1793 | { 96, "AMR/8000/1", &amr_param_octet_aligned_true, }, |
| 1794 | { 0, "PCMU/8000/1", NULL, }, |
| 1795 | { 97, "GSM-HR-08/8000/1", NULL, }, |
| 1796 | }, |
| 1797 | }, |
| 1798 | .expect = { |
| 1799 | { .payload_type_map = {112, 96}, }, |
| 1800 | { .payload_type_map = {0, 0}, }, |
| 1801 | { .payload_type_map = {111, 97} }, |
| 1802 | { .payload_type_map = {123, -EINVAL} }, |
| 1803 | { .end = true }, |
| 1804 | }, |
| 1805 | }, |
| 1806 | { |
Neels Hofmeyr | 2698540 | 2019-08-08 22:39:55 +0200 | [diff] [blame] | 1807 | .descr = "different order and different payload type numbers", |
| 1808 | .codecs = { |
| 1809 | { |
| 1810 | { 0, "PCMU/8000/1", NULL, }, |
| 1811 | { 111, "GSM-HR-08/8000/1", NULL, }, |
| 1812 | { 112, "AMR/8000/1", &amr_param_octet_aligned_true, }, |
| 1813 | }, |
| 1814 | { |
| 1815 | { 97, "GSM-HR-08/8000/1", NULL, }, |
| 1816 | { 0, "PCMU/8000/1", NULL, }, |
| 1817 | { 96, "AMR/8000/1", &amr_param_octet_aligned_true, }, |
| 1818 | }, |
| 1819 | }, |
| 1820 | .expect = { |
| 1821 | { .payload_type_map = {112, 96}, }, |
| 1822 | { .payload_type_map = {0, 0}, }, |
| 1823 | { .payload_type_map = {111, 97} }, |
| 1824 | { .payload_type_map = {123, -EINVAL} }, |
| 1825 | { .end = true }, |
| 1826 | }, |
| 1827 | }, |
| 1828 | { |
| 1829 | .descr = "both sides have the same payload_type numbers assigned to differing codecs", |
| 1830 | .codecs = { |
| 1831 | { |
| 1832 | { 0, "PCMU/8000/1", NULL, }, |
| 1833 | { 96, "GSM-HR-08/8000/1", NULL, }, |
| 1834 | { 97, "AMR/8000/1", &amr_param_octet_aligned_true, }, |
| 1835 | }, |
| 1836 | { |
| 1837 | { 97, "GSM-HR-08/8000/1", NULL, }, |
| 1838 | { 0, "PCMU/8000/1", NULL, }, |
| 1839 | { 96, "AMR/8000/1", &amr_param_octet_aligned_true, }, |
| 1840 | }, |
| 1841 | }, |
| 1842 | .expect = { |
| 1843 | { .payload_type_map = {96, 97}, }, |
| 1844 | { .payload_type_map = {97, 96}, }, |
| 1845 | { .payload_type_map = {0, 0}, }, |
| 1846 | { .end = true }, |
| 1847 | }, |
| 1848 | }, |
| 1849 | { |
Neels Hofmeyr | d2f5e69 | 2019-08-08 21:59:26 +0200 | [diff] [blame] | 1850 | .descr = "conn0 has no codecs", |
| 1851 | .codecs = { |
| 1852 | { |
| 1853 | /* no codecs */ |
| 1854 | }, |
| 1855 | { |
| 1856 | { 96, "AMR/8000/1", &amr_param_octet_aligned_true, }, |
| 1857 | { 0, "PCMU/8000/1", NULL, }, |
| 1858 | { 97, "GSM-HR-08/8000/1", NULL, }, |
| 1859 | }, |
| 1860 | }, |
| 1861 | .expect = { |
| 1862 | { .payload_type_map = {112, -EINVAL}, }, |
| 1863 | { .payload_type_map = {0, -EINVAL}, }, |
| 1864 | { .payload_type_map = {111, -EINVAL} }, |
| 1865 | { .end = true }, |
| 1866 | }, |
| 1867 | }, |
| 1868 | { |
| 1869 | .descr = "conn1 has no codecs", |
| 1870 | .codecs = { |
| 1871 | { |
| 1872 | { 112, "AMR/8000/1", &amr_param_octet_aligned_true, }, |
| 1873 | { 0, "PCMU/8000/1", NULL, }, |
| 1874 | { 111, "GSM-HR-08/8000/1", NULL, }, |
| 1875 | }, |
| 1876 | { |
| 1877 | /* no codecs */ |
| 1878 | }, |
| 1879 | }, |
| 1880 | .expect = { |
| 1881 | { .payload_type_map = {112, -EINVAL}, }, |
| 1882 | { .payload_type_map = {0, -EINVAL}, }, |
| 1883 | { .payload_type_map = {111, -EINVAL} }, |
| 1884 | { .end = true }, |
| 1885 | }, |
| 1886 | }, |
Neels Hofmeyr | 16b637b | 2019-08-08 22:47:10 +0200 | [diff] [blame] | 1887 | { |
| 1888 | .descr = "test AMR with differing octet-aligned settings", |
| 1889 | .codecs = { |
| 1890 | { |
| 1891 | { 111, "AMR/8000", &amr_param_octet_aligned_true, }, |
| 1892 | { 112, "AMR/8000", &amr_param_octet_aligned_false, }, |
| 1893 | }, |
| 1894 | { |
| 1895 | { 122, "AMR/8000", &amr_param_octet_aligned_false, }, |
| 1896 | { 121, "AMR/8000", &amr_param_octet_aligned_true, }, |
| 1897 | }, |
| 1898 | }, |
| 1899 | .expect = { |
| 1900 | { .payload_type_map = {111, 121}, }, |
| 1901 | { .payload_type_map = {112, 122} }, |
| 1902 | { .end = true }, |
| 1903 | }, |
| 1904 | }, |
| 1905 | { |
| 1906 | .descr = "test AMR with missing octet-aligned settings (defaults to 0)", |
| 1907 | .codecs = { |
| 1908 | { |
| 1909 | { 111, "AMR/8000", &amr_param_octet_aligned_true, }, |
| 1910 | { 112, "AMR/8000", &amr_param_octet_aligned_false, }, |
| 1911 | }, |
| 1912 | { |
| 1913 | { 122, "AMR/8000", &amr_param_octet_aligned_unset, }, |
| 1914 | }, |
| 1915 | }, |
| 1916 | .expect = { |
| 1917 | { .payload_type_map = {111, -EINVAL}, }, |
| 1918 | { .payload_type_map = {112, 122} }, |
| 1919 | { .end = true }, |
| 1920 | }, |
| 1921 | }, |
| 1922 | { |
| 1923 | .descr = "test AMR with NULL param (defaults to 0)", |
| 1924 | .codecs = { |
| 1925 | { |
| 1926 | { 111, "AMR/8000", &amr_param_octet_aligned_true, }, |
| 1927 | { 112, "AMR/8000", &amr_param_octet_aligned_false, }, |
| 1928 | }, |
| 1929 | { |
| 1930 | { 122, "AMR/8000", NULL, }, |
| 1931 | }, |
| 1932 | }, |
| 1933 | .expect = { |
| 1934 | { .payload_type_map = {111, -EINVAL}, }, |
| 1935 | { .payload_type_map = {112, 122} }, |
| 1936 | { .end = true }, |
| 1937 | }, |
| 1938 | }, |
Neels Hofmeyr | 683e05f | 2019-08-08 22:48:18 +0200 | [diff] [blame] | 1939 | { |
| 1940 | .descr = "match FOO/8000/1 and FOO/8000 as identical, single channel is implicit", |
| 1941 | .codecs = { |
| 1942 | { |
| 1943 | { 0, "PCMU/8000/1", NULL, }, |
| 1944 | { 111, "GSM-HR-08/8000/1", NULL, }, |
| 1945 | { 112, "AMR/8000/1", &amr_param_octet_aligned_true, }, |
| 1946 | }, |
| 1947 | { |
| 1948 | { 97, "GSM-HR-08/8000", NULL, }, |
| 1949 | { 0, "PCMU/8000", NULL, }, |
| 1950 | { 96, "AMR/8000", &amr_param_octet_aligned_true, }, |
| 1951 | }, |
| 1952 | }, |
| 1953 | .expect = { |
| 1954 | { .payload_type_map = {112, 96}, }, |
| 1955 | { .payload_type_map = {0, 0}, }, |
| 1956 | { .payload_type_map = {111, 97} }, |
| 1957 | { .payload_type_map = {123, -EINVAL} }, |
| 1958 | { .end = true }, |
| 1959 | }, |
| 1960 | }, |
| 1961 | { |
| 1962 | .descr = "match FOO/8000/1 and FOO as identical, 8k and single channel are implicit", |
| 1963 | .codecs = { |
| 1964 | { |
| 1965 | { 0, "PCMU/8000/1", NULL, }, |
| 1966 | { 111, "GSM-HR-08/8000/1", NULL, }, |
| 1967 | { 112, "AMR/8000/1", &amr_param_octet_aligned_true, }, |
| 1968 | }, |
| 1969 | { |
| 1970 | { 97, "GSM-HR-08", NULL, }, |
| 1971 | { 0, "PCMU", NULL, }, |
| 1972 | { 96, "AMR", &amr_param_octet_aligned_true, }, |
| 1973 | }, |
| 1974 | }, |
| 1975 | .expect = { |
| 1976 | { .payload_type_map = {112, 96}, }, |
| 1977 | { .payload_type_map = {0, 0}, }, |
| 1978 | { .payload_type_map = {111, 97} }, |
| 1979 | { .payload_type_map = {123, -EINVAL} }, |
| 1980 | { .end = true }, |
| 1981 | }, |
| 1982 | }, |
| 1983 | { |
| 1984 | .descr = "test whether channel number matching is waterproof", |
| 1985 | .codecs = { |
| 1986 | { |
| 1987 | { 111, "GSM-HR-08/8000", }, |
| 1988 | { 112, "GSM-HR-08/8000/2", .expect_rc = -22}, |
| 1989 | { 113, "GSM-HR-08/8000/3", .expect_rc = -22}, |
| 1990 | }, |
| 1991 | { |
| 1992 | { 122, "GSM-HR-08/8000/2", .expect_rc = -22}, |
| 1993 | { 121, "GSM-HR-08/8000/1", }, |
| 1994 | }, |
| 1995 | }, |
| 1996 | .expect = { |
| 1997 | { .payload_type_map = {111, 121}, }, |
| 1998 | { .payload_type_map = {112, -EINVAL} }, |
| 1999 | { .payload_type_map = {113, -EINVAL} }, |
| 2000 | { .end = true }, |
| 2001 | }, |
| 2002 | }, |
Neels Hofmeyr | d2f5e69 | 2019-08-08 21:59:26 +0200 | [diff] [blame] | 2003 | }; |
Philipp Maier | 6931f9a | 2018-07-26 09:29:31 +0200 | [diff] [blame] | 2004 | |
| 2005 | static void test_mgcp_codec_pt_translate(void) |
| 2006 | { |
Neels Hofmeyr | d2f5e69 | 2019-08-08 21:59:26 +0200 | [diff] [blame] | 2007 | int i; |
| 2008 | bool ok = true; |
| 2009 | printf("\nTesting mgcp_codec_pt_translate()\n"); |
Philipp Maier | 6931f9a | 2018-07-26 09:29:31 +0200 | [diff] [blame] | 2010 | |
Neels Hofmeyr | d2f5e69 | 2019-08-08 21:59:26 +0200 | [diff] [blame] | 2011 | for (i = 0; i < ARRAY_SIZE(test_mgcp_codec_pt_translate_cases); i++) { |
| 2012 | const struct testcase_mgcp_codec_pt_translate *t = &test_mgcp_codec_pt_translate_cases[i]; |
| 2013 | struct mgcp_conn_rtp conn[2] = {}; |
| 2014 | int rc; |
| 2015 | int conn_i; |
| 2016 | int c; |
Philipp Maier | 6931f9a | 2018-07-26 09:29:31 +0200 | [diff] [blame] | 2017 | |
Neels Hofmeyr | d2f5e69 | 2019-08-08 21:59:26 +0200 | [diff] [blame] | 2018 | printf("#%d: %s\n", i, t->descr); |
Philipp Maier | 6931f9a | 2018-07-26 09:29:31 +0200 | [diff] [blame] | 2019 | |
Neels Hofmeyr | d2f5e69 | 2019-08-08 21:59:26 +0200 | [diff] [blame] | 2020 | for (conn_i = 0; conn_i < 2; conn_i++) { |
| 2021 | printf(" - add codecs on conn%d:\n", conn_i); |
| 2022 | for (c = 0; c < ARRAY_SIZE(t->codecs[conn_i]); c++) { |
| 2023 | const struct testcase_mgcp_codec_pt_translate_codec *codec = &t->codecs[conn_i][c]; |
| 2024 | if (!codec->audio_name) |
| 2025 | break; |
| 2026 | |
| 2027 | rc = mgcp_codec_add(&conn[conn_i], codec->payload_type, codec->audio_name, codec->param); |
| 2028 | |
| 2029 | printf(" %2d: %3d %s%s -> rc=%d\n", c, codec->payload_type, codec->audio_name, |
| 2030 | codec->param ? |
| 2031 | (codec->param->amr_octet_aligned_present? |
| 2032 | (codec->param->amr_octet_aligned ? |
| 2033 | " octet-aligned=1" : " octet-aligned=0") |
| 2034 | : " octet-aligned=unset") |
| 2035 | : "", |
| 2036 | rc); |
| 2037 | if (rc != codec->expect_rc) { |
| 2038 | printf(" ERROR: expected rc=%d\n", codec->expect_rc); |
| 2039 | ok = false; |
| 2040 | } |
| 2041 | } |
| 2042 | if (!c) |
| 2043 | printf(" (none)\n"); |
| 2044 | } |
| 2045 | |
| 2046 | for (c = 0; c < ARRAY_SIZE(t->expect); c++) { |
| 2047 | const struct testcase_mgcp_codec_pt_translate_expect *expect = &t->expect[c]; |
| 2048 | int result; |
| 2049 | |
| 2050 | if (expect->end) |
| 2051 | break; |
| 2052 | |
| 2053 | result = mgcp_codec_pt_translate(&conn[0], &conn[1], expect->payload_type_map[0]); |
| 2054 | printf(" - mgcp_codec_pt_translate(conn0, conn1, %d) -> %d\n", |
| 2055 | expect->payload_type_map[0], result); |
| 2056 | if (result != expect->payload_type_map[1]) { |
| 2057 | printf(" ERROR: expected -> %d\n", expect->payload_type_map[1]); |
| 2058 | ok = false; |
| 2059 | } |
| 2060 | |
| 2061 | /* If the expected result is an error, don't do reverse map test */ |
| 2062 | if (expect->payload_type_map[1] < 0) |
| 2063 | continue; |
| 2064 | |
| 2065 | result = mgcp_codec_pt_translate(&conn[1], &conn[0], expect->payload_type_map[1]); |
| 2066 | printf(" - mgcp_codec_pt_translate(conn1, conn0, %d) -> %d\n", |
| 2067 | expect->payload_type_map[1], result); |
| 2068 | if (result != expect->payload_type_map[0]) { |
| 2069 | printf(" ERROR: expected -> %d\n", expect->payload_type_map[0]); |
| 2070 | ok = false; |
| 2071 | } |
| 2072 | } |
| 2073 | |
| 2074 | for (conn_i = 0; conn_i < 2; conn_i++) |
| 2075 | mgcp_codec_reset_all(&conn[conn_i]); |
| 2076 | } |
| 2077 | |
| 2078 | OSMO_ASSERT(ok); |
Philipp Maier | 6931f9a | 2018-07-26 09:29:31 +0200 | [diff] [blame] | 2079 | } |
| 2080 | |
Neels Hofmeyr | 6531726 | 2018-09-03 22:11:05 +0200 | [diff] [blame] | 2081 | void test_conn_id_matching() |
| 2082 | { |
| 2083 | struct mgcp_endpoint endp = {}; |
| 2084 | struct mgcp_conn *conn; |
| 2085 | struct mgcp_conn *conn_match; |
| 2086 | int i; |
| 2087 | const char *conn_id_generated = "000023AB"; |
| 2088 | const char *conn_id_request[] = { |
Neels Hofmeyr | a77eade | 2018-08-29 02:30:39 +0200 | [diff] [blame] | 2089 | "23AB", |
| 2090 | "0023AB", |
Neels Hofmeyr | 6531726 | 2018-09-03 22:11:05 +0200 | [diff] [blame] | 2091 | "000023AB", |
Neels Hofmeyr | a77eade | 2018-08-29 02:30:39 +0200 | [diff] [blame] | 2092 | "00000023AB", |
| 2093 | "23ab", |
| 2094 | "0023ab", |
Neels Hofmeyr | 6531726 | 2018-09-03 22:11:05 +0200 | [diff] [blame] | 2095 | "000023ab", |
Neels Hofmeyr | a77eade | 2018-08-29 02:30:39 +0200 | [diff] [blame] | 2096 | "00000023ab", |
Neels Hofmeyr | 6531726 | 2018-09-03 22:11:05 +0200 | [diff] [blame] | 2097 | }; |
| 2098 | |
| 2099 | printf("\nTesting %s\n", __func__); |
| 2100 | |
| 2101 | INIT_LLIST_HEAD(&endp.conns); |
| 2102 | |
| 2103 | conn = talloc_zero(NULL, struct mgcp_conn); |
| 2104 | OSMO_ASSERT(conn); |
| 2105 | osmo_strlcpy(conn->id, conn_id_generated, sizeof(conn->id)); |
| 2106 | llist_add(&conn->entry, &endp.conns); |
| 2107 | |
| 2108 | for (i = 0; i < ARRAY_SIZE(conn_id_request); i++) { |
| 2109 | const char *needle = conn_id_request[i]; |
| 2110 | printf("needle='%s' ", needle); |
| 2111 | conn_match = mgcp_conn_get(&endp, needle); |
| 2112 | OSMO_ASSERT(conn_match); |
| 2113 | printf("found '%s'\n", conn_match->id); |
| 2114 | OSMO_ASSERT(conn_match == conn); |
| 2115 | } |
| 2116 | |
| 2117 | llist_del(&conn->entry); |
| 2118 | talloc_free(conn); |
| 2119 | } |
| 2120 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 2121 | int main(int argc, char **argv) |
| 2122 | { |
Neels Hofmeyr | 60f8e31 | 2018-03-30 23:01:07 +0200 | [diff] [blame] | 2123 | void *ctx = talloc_named_const(NULL, 0, "mgcp_test"); |
| 2124 | void *msgb_ctx = msgb_talloc_ctx_init(ctx, 0); |
| 2125 | osmo_init_logging2(ctx, &log_info); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 2126 | |
| 2127 | test_strline(); |
| 2128 | test_values(); |
| 2129 | test_messages(); |
| 2130 | test_retransmission(); |
| 2131 | test_packet_loss_calc(); |
| 2132 | test_rqnt_cb(); |
| 2133 | test_mgcp_stats(); |
| 2134 | test_packet_error_detection(1, 0); |
| 2135 | test_packet_error_detection(0, 0); |
| 2136 | test_packet_error_detection(0, 1); |
| 2137 | test_packet_error_detection(1, 1); |
| 2138 | test_multilple_codec(); |
| 2139 | test_no_cycle(); |
| 2140 | test_no_name(); |
| 2141 | test_osmux_cid(); |
Philipp Maier | 3d7b58d | 2018-06-06 09:35:31 +0200 | [diff] [blame] | 2142 | test_get_lco_identifier(); |
| 2143 | test_check_local_cx_options(ctx); |
Philipp Maier | 6931f9a | 2018-07-26 09:29:31 +0200 | [diff] [blame] | 2144 | test_mgcp_codec_pt_translate(); |
Neels Hofmeyr | 6531726 | 2018-09-03 22:11:05 +0200 | [diff] [blame] | 2145 | test_conn_id_matching(); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 2146 | |
Neels Hofmeyr | 465446b | 2017-11-18 21:26:26 +0100 | [diff] [blame] | 2147 | OSMO_ASSERT(talloc_total_size(msgb_ctx) == 0); |
| 2148 | OSMO_ASSERT(talloc_total_blocks(msgb_ctx) == 1); |
| 2149 | talloc_free(msgb_ctx); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 2150 | printf("Done\n"); |
| 2151 | return EXIT_SUCCESS; |
| 2152 | } |