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