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 | |
| 470 | #define CRCX_NO_LCO_NO_SDP_RET \ |
| 471 | "200 2 OK\r\n" \ |
| 472 | "I: %s\r\n" \ |
| 473 | "\r\n" \ |
| 474 | "v=0\r\n" \ |
| 475 | "o=- %s 23 IN IP4 0.0.0.0\r\n" \ |
| 476 | "s=-\r\n" \ |
| 477 | "c=IN IP4 0.0.0.0\r\n" \ |
| 478 | "t=0 0\r\n" \ |
| 479 | "m=audio 16008 RTP/AVP 0\r\n" \ |
| 480 | "a=ptime:20\r\n" |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 481 | |
| 482 | struct mgcp_test { |
| 483 | const char *name; |
| 484 | const char *req; |
| 485 | const char *exp_resp; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 486 | int ptype; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 487 | const char *extra_fmtp; |
| 488 | }; |
| 489 | |
| 490 | static const struct mgcp_test tests[] = { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 491 | {"AUEP1", AUEP1, AUEP1_RET}, |
| 492 | {"AUEP2", AUEP2, AUEP2_RET}, |
| 493 | {"MDCX1", MDCX_WRONG_EP, MDCX_ERR_RET}, |
| 494 | {"MDCX2", MDCX_UNALLOCATED, MDCX_RET}, |
| 495 | {"CRCX", CRCX, CRCX_RET, 97}, |
| 496 | {"MDCX3", MDCX3, MDCX3_RET, PTYPE_IGNORE}, |
| 497 | {"MDCX4", MDCX4, MDCX4_RET("18983216"), 99}, |
| 498 | {"MDCX4_PT1", MDCX4_PT1, MDCX4_RET("18983217"), 99}, |
| 499 | {"MDCX4_PT2", MDCX4_PT2, MDCX4_RET("18983218"), 99}, |
| 500 | {"MDCX4_PT3", MDCX4_PT3, MDCX4_RET("18983219"), 99}, |
| 501 | {"MDCX4_SO", MDCX4_SO, MDCX4_RET("18983220"), 99}, |
| 502 | {"MDCX4_RO", MDCX4_RO, MDCX4_RO_RET("18983221"), PTYPE_IGNORE}, |
| 503 | {"DLCX", DLCX, DLCX_RET, PTYPE_IGNORE}, |
| 504 | {"CRCX_ZYN", CRCX_ZYN, CRCX_ZYN_RET, 97}, |
| 505 | {"EMPTY", EMPTY, EMPTY_RET}, |
| 506 | {"SHORT1", SHORT, SHORT_RET}, |
| 507 | {"SHORT2", SHORT2, SHORT2_RET}, |
| 508 | {"SHORT3", SHORT3, SHORT2_RET}, |
| 509 | {"SHORT4", SHORT4, SHORT2_RET}, |
| 510 | {"RQNT1", RQNT, RQNT1_RET}, |
| 511 | {"RQNT2", RQNT2, RQNT2_RET}, |
| 512 | {"DLCX", DLCX, DLCX_RET, PTYPE_IGNORE}, |
| 513 | {"CRCX", CRCX, CRCX_FMTP_RET, 97,.extra_fmtp = "a=fmtp:126 0/1/2"}, |
| 514 | {"MDCX3", MDCX3, MDCX3_FMTP_RET, PTYPE_NONE,.extra_fmtp = |
| 515 | "a=fmtp:126 0/1/2"}, |
| 516 | {"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] | 517 | {"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] | 518 | {"CRCX", CRCX_X_OSMO_IGN, CRCX_X_OSMO_IGN_RET, 97}, |
Neels Hofmeyr | 5336f57 | 2018-09-03 22:05:48 +0200 | [diff] [blame] | 519 | {"MDCX_TOO_LONG_CI", MDCX_TOO_LONG_CI, MDCX_TOO_LONG_CI_RET}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 520 | }; |
| 521 | |
| 522 | static const struct mgcp_test retransmit[] = { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 523 | {"CRCX", CRCX, CRCX_RET}, |
| 524 | {"RQNT1", RQNT, RQNT1_RET}, |
| 525 | {"RQNT2", RQNT2, RQNT2_RET}, |
| 526 | {"MDCX3", MDCX3, MDCX3A_RET}, |
| 527 | {"DLCX", DLCX, DLCX_RET}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 528 | }; |
| 529 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 530 | static struct msgb *create_msg(const char *str, const char *conn_id) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 531 | { |
| 532 | struct msgb *msg; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 533 | int len; |
| 534 | |
| 535 | printf("creating message from statically defined input:\n"); |
| 536 | printf("---------8<---------\n%s\n---------8<---------\n", str); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 537 | |
| 538 | msg = msgb_alloc_headroom(4096, 128, "MGCP msg"); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 539 | if (conn_id && strlen(conn_id)) |
| 540 | len = sprintf((char *)msg->data, str, conn_id, conn_id); |
| 541 | else |
| 542 | len = sprintf((char *)msg->data, "%s", str); |
| 543 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 544 | msg->l2h = msgb_put(msg, len); |
| 545 | return msg; |
| 546 | } |
| 547 | |
| 548 | static int last_endpoint = -1; |
| 549 | |
| 550 | static int mgcp_test_policy_cb(struct mgcp_trunk_config *cfg, int endpoint, |
| 551 | int state, const char *transactio_id) |
| 552 | { |
| 553 | fprintf(stderr, "Policy CB got state %d on endpoint %d\n", |
| 554 | state, endpoint); |
| 555 | last_endpoint = endpoint; |
| 556 | return MGCP_POLICY_CONT; |
| 557 | } |
| 558 | |
| 559 | #define MGCP_DUMMY_LOAD 0x23 |
| 560 | static int dummy_packets = 0; |
| 561 | /* override and forward */ |
| 562 | 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] | 563 | const struct sockaddr *dest_addr, socklen_t addrlen) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 564 | { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 565 | uint32_t dest_host = |
| 566 | htonl(((struct sockaddr_in *)dest_addr)->sin_addr.s_addr); |
| 567 | int dest_port = htons(((struct sockaddr_in *)dest_addr)->sin_port); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 568 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 569 | if (len == 1 && ((const char *)buf)[0] == MGCP_DUMMY_LOAD) { |
| 570 | fprintf(stderr, |
| 571 | "Dummy packet to 0x%08x:%d, msg length %zu\n%s\n\n", |
| 572 | dest_host, dest_port, len, osmo_hexdump(buf, len)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 573 | dummy_packets += 1; |
| 574 | } |
| 575 | |
Philipp Maier | 3d9b656 | 2017-10-13 18:33:44 +0200 | [diff] [blame] | 576 | return len; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | static int64_t force_monotonic_time_us = -1; |
| 580 | /* override and forward */ |
| 581 | int clock_gettime(clockid_t clk_id, struct timespec *tp) |
| 582 | { |
| 583 | typedef int (*clock_gettime_t)(clockid_t clk_id, struct timespec *tp); |
| 584 | static clock_gettime_t real_clock_gettime = NULL; |
| 585 | |
| 586 | if (!real_clock_gettime) |
| 587 | real_clock_gettime = dlsym(RTLD_NEXT, "clock_gettime"); |
| 588 | |
| 589 | if (clk_id == CLOCK_MONOTONIC && force_monotonic_time_us >= 0) { |
| 590 | tp->tv_sec = force_monotonic_time_us / 1000000; |
| 591 | tp->tv_nsec = (force_monotonic_time_us % 1000000) * 1000; |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | return real_clock_gettime(clk_id, tp); |
| 596 | } |
| 597 | |
| 598 | #define CONN_UNMODIFIED (0x1000) |
| 599 | |
| 600 | static void test_values(void) |
| 601 | { |
| 602 | /* Check that NONE disables all output */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 603 | OSMO_ASSERT((MGCP_CONN_NONE & MGCP_CONN_RECV_SEND) == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 604 | |
| 605 | /* Check that LOOPBACK enables all output */ |
| 606 | OSMO_ASSERT((MGCP_CONN_LOOPBACK & MGCP_CONN_RECV_SEND) == |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 607 | MGCP_CONN_RECV_SEND); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 608 | } |
| 609 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 610 | /* Extract a connection ID from a response (CRCX) */ |
| 611 | static int get_conn_id_from_response(uint8_t *resp, char *conn_id, |
| 612 | unsigned int conn_id_len) |
| 613 | { |
| 614 | char *conn_id_ptr; |
| 615 | int i; |
Philipp Maier | 55295f7 | 2018-01-15 14:00:28 +0100 | [diff] [blame] | 616 | bool got_conn_id = false; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 617 | |
Philipp Maier | 55295f7 | 2018-01-15 14:00:28 +0100 | [diff] [blame] | 618 | /* First try to get the conn_id from the I: parameter */ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 619 | conn_id_ptr = strstr((char *)resp, "I: "); |
Philipp Maier | 55295f7 | 2018-01-15 14:00:28 +0100 | [diff] [blame] | 620 | if (conn_id_ptr) { |
| 621 | memset(conn_id, 0, conn_id_len); |
| 622 | memcpy(conn_id, conn_id_ptr + 3, 32); |
| 623 | got_conn_id = true; |
| 624 | } else { |
| 625 | /* Alternatively try to extract the conn_id from the o=- SDP |
| 626 | * parameter */ |
| 627 | conn_id_ptr = strstr((char *)resp, "o=- "); |
| 628 | if(conn_id_ptr) { |
| 629 | memset(conn_id, 0, conn_id_len); |
| 630 | memcpy(conn_id, conn_id_ptr + 4, 32); |
| 631 | got_conn_id = true; |
| 632 | } |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 633 | } |
| 634 | |
Philipp Maier | 55295f7 | 2018-01-15 14:00:28 +0100 | [diff] [blame] | 635 | if (got_conn_id) { |
| 636 | for (i = 0; i < conn_id_len; i++) { |
Neels Hofmeyr | b861db9 | 2018-08-28 16:19:25 +0200 | [diff] [blame] | 637 | if (!isxdigit(conn_id[i])) { |
Philipp Maier | 55295f7 | 2018-01-15 14:00:28 +0100 | [diff] [blame] | 638 | conn_id[i] = '\0'; |
Neels Hofmeyr | b861db9 | 2018-08-28 16:19:25 +0200 | [diff] [blame] | 639 | break; |
| 640 | } |
Philipp Maier | 55295f7 | 2018-01-15 14:00:28 +0100 | [diff] [blame] | 641 | } |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 642 | |
Philipp Maier | 55295f7 | 2018-01-15 14:00:28 +0100 | [diff] [blame] | 643 | /* A valid conn_id must at least contain one digit, and must |
| 644 | * not exceed a length of 32 digits */ |
| 645 | OSMO_ASSERT(strlen(conn_id) <= 32); |
| 646 | OSMO_ASSERT(strlen(conn_id) > 0); |
| 647 | |
| 648 | return 0; |
| 649 | } |
| 650 | return -EINVAL; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | /* Check response, automatically patch connection ID if needed */ |
| 654 | static int check_response(uint8_t *resp, const char *exp_resp) |
| 655 | { |
| 656 | char exp_resp_patched[4096]; |
| 657 | const char *exp_resp_ptr; |
| 658 | char conn_id[256]; |
| 659 | |
| 660 | printf("checking response:\n"); |
| 661 | |
| 662 | /* If the expected response is intened to be patched |
| 663 | * (%s placeholder inside) we will patch it with the |
| 664 | * connection identifier we just received from the |
| 665 | * real response. This is necessary because the CI |
| 666 | * is generated by the mgcp code on CRCX and we can |
| 667 | * not know it in advance */ |
| 668 | if (strstr(exp_resp, "%s")) { |
| 669 | if (get_conn_id_from_response(resp, conn_id, sizeof(conn_id)) == |
| 670 | 0) { |
| 671 | sprintf(exp_resp_patched, exp_resp, conn_id, conn_id); |
| 672 | exp_resp_ptr = exp_resp_patched; |
| 673 | printf |
| 674 | ("using message with patched conn_id for comparison\n"); |
| 675 | } else { |
| 676 | printf |
| 677 | ("patching conn_id failed, using message as statically defined for comparison\n"); |
| 678 | exp_resp_ptr = exp_resp; |
| 679 | } |
| 680 | } else { |
| 681 | printf("using message as statically defined for comparison\n"); |
| 682 | exp_resp_ptr = exp_resp; |
| 683 | } |
| 684 | |
| 685 | if (strcmp((char *)resp, exp_resp_ptr) != 0) { |
| 686 | printf("Unexpected response, please check!\n"); |
| 687 | printf |
| 688 | ("Got:\n---------8<---------\n%s\n---------8<---------\n\n", |
| 689 | resp); |
| 690 | printf |
| 691 | ("Expected:\n---------8<---------\n%s\n---------8<---------\n", |
| 692 | exp_resp_ptr); |
| 693 | return -EINVAL; |
| 694 | } |
| 695 | |
| 696 | printf("Response matches our expectations.\n"); |
| 697 | return 0; |
| 698 | } |
| 699 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 700 | static void test_messages(void) |
| 701 | { |
| 702 | struct mgcp_config *cfg; |
| 703 | struct mgcp_endpoint *endp; |
| 704 | int i; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 705 | struct mgcp_conn_rtp *conn = NULL; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 706 | char last_conn_id[256]; |
Philipp Maier | 7df419b | 2017-12-04 17:11:42 +0100 | [diff] [blame] | 707 | int rc; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 708 | |
| 709 | cfg = mgcp_config_alloc(); |
| 710 | |
Philipp Maier | fcd0655 | 2017-11-10 17:32:22 +0100 | [diff] [blame] | 711 | cfg->trunk.vty_number_endpoints = 64; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 712 | mgcp_endpoints_allocate(&cfg->trunk); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 713 | cfg->policy_cb = mgcp_test_policy_cb; |
| 714 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 715 | memset(last_conn_id, 0, sizeof(last_conn_id)); |
| 716 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 717 | mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1)); |
| 718 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 719 | for (i = 0; i < ARRAY_SIZE(tests); i++) { |
| 720 | const struct mgcp_test *t = &tests[i]; |
| 721 | struct msgb *inp; |
| 722 | struct msgb *msg; |
| 723 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 724 | printf("\n================================================\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 725 | printf("Testing %s\n", t->name); |
| 726 | |
| 727 | last_endpoint = -1; |
| 728 | dummy_packets = 0; |
| 729 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 730 | osmo_talloc_replace_string(cfg, &cfg->trunk.audio_fmtp_extra, |
| 731 | t->extra_fmtp); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 732 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 733 | inp = create_msg(t->req, last_conn_id); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 734 | msg = mgcp_handle_message(cfg, inp); |
| 735 | msgb_free(inp); |
| 736 | if (!t->exp_resp) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 737 | if (msg) { |
| 738 | printf("%s failed '%s'\n", t->name, |
| 739 | (char *)msg->data); |
| 740 | OSMO_ASSERT(false); |
| 741 | } |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 742 | } else if (check_response(msg->data, t->exp_resp) != 0) { |
| 743 | printf("%s failed.\n", t->name); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 744 | OSMO_ASSERT(false); |
| 745 | } |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 746 | |
Philipp Maier | 7df419b | 2017-12-04 17:11:42 +0100 | [diff] [blame] | 747 | if (msg) { |
| 748 | rc = get_conn_id_from_response(msg->data, last_conn_id, |
| 749 | sizeof(last_conn_id)); |
Neels Hofmeyr | 08e0704 | 2018-08-28 16:22:14 +0200 | [diff] [blame] | 750 | if (rc == 0) |
Philipp Maier | 7df419b | 2017-12-04 17:11:42 +0100 | [diff] [blame] | 751 | printf("(response contains a connection id)\n"); |
| 752 | else |
| 753 | printf("(response does not contain a connection id)\n"); |
| 754 | } |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 755 | |
Philipp Maier | a330b86 | 2017-12-04 17:16:16 +0100 | [diff] [blame] | 756 | if (msg) |
| 757 | msgb_free(msg); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 758 | |
| 759 | if (dummy_packets) |
| 760 | printf("Dummy packets: %d\n", dummy_packets); |
| 761 | |
| 762 | if (last_endpoint != -1) { |
| 763 | endp = &cfg->trunk.endpoints[last_endpoint]; |
| 764 | |
Philipp Maier | 01d24a3 | 2017-11-21 17:26:09 +0100 | [diff] [blame] | 765 | conn = mgcp_conn_get_rtp(endp, "1"); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 766 | if (conn) { |
| 767 | OSMO_ASSERT(conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 768 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 769 | if (conn->end.packet_duration_ms != -1) |
| 770 | printf("Detected packet duration: %d\n", |
| 771 | conn->end.packet_duration_ms); |
| 772 | else |
| 773 | printf("Packet duration not set\n"); |
| 774 | if (endp->local_options.pkt_period_min || |
| 775 | endp->local_options.pkt_period_max) |
| 776 | printf |
| 777 | ("Requested packetetization period: " |
| 778 | "%d-%d\n", |
| 779 | endp->local_options.pkt_period_min, |
| 780 | endp-> |
| 781 | local_options.pkt_period_max); |
| 782 | else |
| 783 | printf |
| 784 | ("Requested packetization period not set\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 785 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 786 | if ((conn->conn->mode & CONN_UNMODIFIED) == 0) { |
| 787 | printf("Connection mode: %d:%s%s%s%s\n", |
| 788 | conn->conn->mode, |
| 789 | !conn->conn->mode ? " NONE" : "", |
| 790 | conn->conn->mode & MGCP_CONN_SEND_ONLY |
| 791 | ? " SEND" : "", |
| 792 | conn->conn->mode & MGCP_CONN_RECV_ONLY |
| 793 | ? " RECV" : "", |
| 794 | conn->conn->mode & MGCP_CONN_LOOPBACK |
| 795 | & ~MGCP_CONN_RECV_SEND |
| 796 | ? " LOOP" : ""); |
| 797 | fprintf(stderr, |
| 798 | "RTP output %sabled, NET output %sabled\n", |
| 799 | conn->end.output_enabled |
| 800 | ? "en" : "dis", |
| 801 | conn->end.output_enabled |
| 802 | ? "en" : "dis"); |
| 803 | } else |
| 804 | printf("Connection mode not set\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 805 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 806 | OSMO_ASSERT(conn->end.output_enabled |
| 807 | == (conn->conn->mode & MGCP_CONN_SEND_ONLY ? 1 : 0)); |
| 808 | |
| 809 | conn->conn->mode |= CONN_UNMODIFIED; |
| 810 | |
| 811 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 812 | endp->local_options.pkt_period_min = 0; |
| 813 | endp->local_options.pkt_period_max = 0; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 814 | } |
| 815 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 816 | /* Check detected payload type */ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 817 | if (conn && t->ptype != PTYPE_IGNORE) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 818 | OSMO_ASSERT(last_endpoint != -1); |
| 819 | endp = &cfg->trunk.endpoints[last_endpoint]; |
| 820 | |
| 821 | fprintf(stderr, "endpoint %d: " |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 822 | "payload type %d (expected %d)\n", |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 823 | last_endpoint, |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 824 | conn->end.codec->payload_type, t->ptype); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 825 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 826 | if (t->ptype != PTYPE_IGNORE) |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 827 | OSMO_ASSERT(conn->end.codec->payload_type == |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 828 | t->ptype); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 829 | |
| 830 | /* Reset them again for next test */ |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 831 | conn->end.codec->payload_type = PTYPE_NONE; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 832 | } |
| 833 | } |
| 834 | |
| 835 | talloc_free(cfg); |
| 836 | } |
| 837 | |
| 838 | static void test_retransmission(void) |
| 839 | { |
| 840 | struct mgcp_config *cfg; |
| 841 | int i; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 842 | char last_conn_id[256]; |
Philipp Maier | 23b8e29 | 2017-12-04 16:48:45 +0100 | [diff] [blame] | 843 | int rc; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 844 | |
| 845 | cfg = mgcp_config_alloc(); |
| 846 | |
Philipp Maier | fcd0655 | 2017-11-10 17:32:22 +0100 | [diff] [blame] | 847 | cfg->trunk.vty_number_endpoints = 64; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 848 | mgcp_endpoints_allocate(&cfg->trunk); |
| 849 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 850 | memset(last_conn_id, 0, sizeof(last_conn_id)); |
| 851 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 852 | mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1)); |
| 853 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 854 | for (i = 0; i < ARRAY_SIZE(retransmit); i++) { |
| 855 | const struct mgcp_test *t = &retransmit[i]; |
| 856 | struct msgb *inp; |
| 857 | struct msgb *msg; |
| 858 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 859 | printf("\n================================================\n"); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 860 | printf("Testing %s\n", t->name); |
| 861 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 862 | inp = create_msg(t->req, last_conn_id); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 863 | msg = mgcp_handle_message(cfg, inp); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 864 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 865 | msgb_free(inp); |
Philipp Maier | 7cedfd7 | 2017-12-04 16:49:12 +0100 | [diff] [blame] | 866 | if (msg && check_response(msg->data, t->exp_resp) != 0) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 867 | printf("%s failed '%s'\n", t->name, (char *)msg->data); |
| 868 | OSMO_ASSERT(false); |
| 869 | } |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 870 | |
Philipp Maier | 23b8e29 | 2017-12-04 16:48:45 +0100 | [diff] [blame] | 871 | if (msg && strcmp(t->name, "CRCX") == 0) { |
| 872 | rc = get_conn_id_from_response(msg->data, last_conn_id, |
| 873 | sizeof(last_conn_id)); |
| 874 | OSMO_ASSERT(rc == 0); |
| 875 | } |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 876 | |
Philipp Maier | 7cedfd7 | 2017-12-04 16:49:12 +0100 | [diff] [blame] | 877 | if (msg) |
| 878 | msgb_free(msg); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 879 | |
| 880 | /* Retransmit... */ |
| 881 | printf("Re-transmitting %s\n", t->name); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 882 | inp = create_msg(t->req, last_conn_id); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 883 | msg = mgcp_handle_message(cfg, inp); |
| 884 | msgb_free(inp); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 885 | if (check_response(msg->data, t->exp_resp) != 0) { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 886 | printf("%s failed '%s'\n", t->name, (char *)msg->data); |
| 887 | OSMO_ASSERT(false); |
| 888 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 889 | msgb_free(msg); |
| 890 | } |
| 891 | |
| 892 | talloc_free(cfg); |
| 893 | } |
| 894 | |
| 895 | static int rqnt_cb(struct mgcp_endpoint *endp, char _tone) |
| 896 | { |
| 897 | ptrdiff_t tone = _tone; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 898 | endp->cfg->data = (void *)tone; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 899 | return 0; |
| 900 | } |
| 901 | |
| 902 | static void test_rqnt_cb(void) |
| 903 | { |
| 904 | struct mgcp_config *cfg; |
| 905 | struct msgb *inp, *msg; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 906 | char conn_id[256]; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 907 | |
| 908 | cfg = mgcp_config_alloc(); |
| 909 | cfg->rqnt_cb = rqnt_cb; |
| 910 | |
Philipp Maier | fcd0655 | 2017-11-10 17:32:22 +0100 | [diff] [blame] | 911 | cfg->trunk.vty_number_endpoints = 64; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 912 | mgcp_endpoints_allocate(&cfg->trunk); |
| 913 | |
| 914 | mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1)); |
| 915 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 916 | inp = create_msg(CRCX, NULL); |
| 917 | msg = mgcp_handle_message(cfg, inp); |
| 918 | OSMO_ASSERT(msg); |
| 919 | OSMO_ASSERT(get_conn_id_from_response(msg->data, conn_id, |
| 920 | sizeof(conn_id)) == 0); |
| 921 | msgb_free(msg); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 922 | msgb_free(inp); |
| 923 | |
| 924 | /* send the RQNT and check for the CB */ |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 925 | inp = create_msg(RQNT, conn_id); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 926 | msg = mgcp_handle_message(cfg, inp); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 927 | if (strncmp((const char *)msg->l2h, "200", 3) != 0) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 928 | printf("FAILED: message is not 200. '%s'\n", msg->l2h); |
| 929 | abort(); |
| 930 | } |
| 931 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 932 | if (cfg->data != (void *)'9') { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 933 | printf("FAILED: callback not called: %p\n", cfg->data); |
| 934 | abort(); |
| 935 | } |
| 936 | |
| 937 | msgb_free(msg); |
| 938 | msgb_free(inp); |
| 939 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 940 | inp = create_msg(DLCX, conn_id); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 941 | msgb_free(mgcp_handle_message(cfg, inp)); |
| 942 | msgb_free(inp); |
| 943 | talloc_free(cfg); |
| 944 | } |
| 945 | |
| 946 | struct pl_test { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 947 | int cycles; |
| 948 | uint16_t base_seq; |
| 949 | uint16_t max_seq; |
| 950 | uint32_t packets; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 951 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 952 | uint32_t expected; |
| 953 | int loss; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 954 | }; |
| 955 | |
| 956 | static const struct pl_test pl_test_dat[] = { |
| 957 | /* basic.. just one package */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 958 | {.cycles = 0,.base_seq = 0,.max_seq = 0,.packets = 1,.expected = |
| 959 | 1,.loss = 0}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 960 | /* some packages and a bit of loss */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 961 | {.cycles = 0,.base_seq = 0,.max_seq = 100,.packets = 100,.expected = |
| 962 | 101,.loss = 1}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 963 | /* wrap around */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 964 | {.cycles = 1 << 16,.base_seq = 0xffff,.max_seq = 2,.packets = |
| 965 | 4,.expected = 4,.loss = 0}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 966 | /* min loss */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 967 | {.cycles = 0,.base_seq = 0,.max_seq = 0,.packets = UINT_MAX,.expected = |
| 968 | 1,.loss = INT_MIN}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 969 | /* max loss, with wrap around on expected max */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 970 | {.cycles = INT_MAX,.base_seq = 0,.max_seq = UINT16_MAX,.packets = |
| 971 | 0,.expected = ((uint32_t) (INT_MAX) + UINT16_MAX + 1),.loss = INT_MAX}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 972 | }; |
| 973 | |
| 974 | static void test_packet_loss_calc(void) |
| 975 | { |
| 976 | int i; |
Philipp Maier | cede2a4 | 2018-07-03 14:14:21 +0200 | [diff] [blame] | 977 | struct mgcp_endpoint endp; |
| 978 | struct mgcp_trunk_config trunk; |
| 979 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 980 | printf("Testing packet loss calculation.\n"); |
| 981 | |
Philipp Maier | cede2a4 | 2018-07-03 14:14:21 +0200 | [diff] [blame] | 982 | memset(&endp, 0, sizeof(endp)); |
| 983 | memset(&trunk, 0, sizeof(trunk)); |
| 984 | |
| 985 | endp.type = &ep_typeset.rtp; |
| 986 | trunk.vty_number_endpoints = 1; |
| 987 | trunk.endpoints = &endp; |
| 988 | endp.tcfg = &trunk; |
| 989 | INIT_LLIST_HEAD(&endp.conns); |
| 990 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 991 | for (i = 0; i < ARRAY_SIZE(pl_test_dat); ++i) { |
| 992 | uint32_t expected; |
| 993 | int loss; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 994 | |
Philipp Maier | cede2a4 | 2018-07-03 14:14:21 +0200 | [diff] [blame] | 995 | struct mgcp_conn_rtp *conn = NULL; |
| 996 | struct mgcp_conn *_conn = NULL; |
| 997 | struct mgcp_rtp_state *state; |
| 998 | struct rate_ctr *packets_rx; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 999 | |
Philipp Maier | cede2a4 | 2018-07-03 14:14:21 +0200 | [diff] [blame] | 1000 | _conn = |
| 1001 | mgcp_conn_alloc(NULL, &endp, MGCP_CONN_TYPE_RTP, |
| 1002 | "test-connection"); |
| 1003 | conn = mgcp_conn_get_rtp(&endp, _conn->id); |
| 1004 | state = &conn->state; |
| 1005 | packets_rx = &conn->rate_ctr_group->ctr[RTP_PACKETS_RX_CTR]; |
| 1006 | |
| 1007 | state->stats.initialized = 1; |
| 1008 | state->stats.base_seq = pl_test_dat[i].base_seq; |
| 1009 | state->stats.max_seq = pl_test_dat[i].max_seq; |
| 1010 | state->stats.cycles = pl_test_dat[i].cycles; |
| 1011 | |
| 1012 | packets_rx->current = pl_test_dat[i].packets; |
| 1013 | calc_loss(conn, &expected, &loss); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1014 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1015 | if (loss != pl_test_dat[i].loss |
| 1016 | || expected != pl_test_dat[i].expected) { |
| 1017 | printf |
| 1018 | ("FAIL: Wrong exp/loss at idx(%d) Loss(%d vs. %d) Exp(%u vs. %u)\n", |
| 1019 | i, loss, pl_test_dat[i].loss, expected, |
| 1020 | pl_test_dat[i].expected); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1021 | } |
Philipp Maier | cede2a4 | 2018-07-03 14:14:21 +0200 | [diff] [blame] | 1022 | |
| 1023 | mgcp_conn_free_all(&endp); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1024 | } |
Philipp Maier | cede2a4 | 2018-07-03 14:14:21 +0200 | [diff] [blame] | 1025 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1026 | } |
| 1027 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1028 | int mgcp_parse_stats(struct msgb *msg, uint32_t *ps, uint32_t *os, |
| 1029 | uint32_t *pr, uint32_t *_or, int *loss, |
| 1030 | uint32_t *jitter) |
| 1031 | { |
| 1032 | char *line, *save; |
| 1033 | int rc; |
| 1034 | |
| 1035 | /* initialize with bad values */ |
| 1036 | *ps = *os = *pr = *_or = *jitter = UINT_MAX; |
| 1037 | *loss = INT_MAX; |
| 1038 | |
| 1039 | line = strtok_r((char *)msg->l2h, "\r\n", &save); |
| 1040 | if (!line) |
| 1041 | return -1; |
| 1042 | |
| 1043 | /* this can only parse the message that is created above... */ |
| 1044 | for_each_non_empty_line(line, save) { |
| 1045 | switch (line[0]) { |
| 1046 | case 'P': |
| 1047 | rc = sscanf(line, |
| 1048 | "P: PS=%u, OS=%u, PR=%u, OR=%u, PL=%d, JI=%u", |
| 1049 | ps, os, pr, _or, loss, jitter); |
| 1050 | return rc == 6 ? 0 : -1; |
| 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | return -1; |
| 1055 | } |
| 1056 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1057 | static void test_mgcp_stats(void) |
| 1058 | { |
| 1059 | printf("Testing stat parsing\n"); |
| 1060 | |
| 1061 | uint32_t bps, bos, pr, _or, jitter; |
| 1062 | struct msgb *msg; |
| 1063 | int loss; |
| 1064 | int rc; |
| 1065 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1066 | msg = create_msg(DLCX_RET, NULL); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1067 | rc = mgcp_parse_stats(msg, &bps, &bos, &pr, &_or, &loss, &jitter); |
| 1068 | printf("Parsing result: %d\n", rc); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1069 | if (bps != 0 || bos != 0 || pr != 0 || _or != 0 || loss != 0 |
| 1070 | || jitter != 0) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1071 | printf("FAIL: Parsing failed1.\n"); |
| 1072 | msgb_free(msg); |
| 1073 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1074 | msg = |
| 1075 | create_msg |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1076 | ("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] | 1077 | rc = mgcp_parse_stats(msg, &bps, &bos, &pr, &_or, &loss, &jitter); |
| 1078 | printf("Parsing result: %d\n", rc); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1079 | if (bps != 10 || bos != 20 || pr != 30 || _or != 40 || loss != -3 |
| 1080 | || jitter != 40) |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1081 | printf("FAIL: Parsing failed2.\n"); |
| 1082 | msgb_free(msg); |
| 1083 | } |
| 1084 | |
| 1085 | struct rtp_packet_info { |
| 1086 | float txtime; |
| 1087 | int len; |
| 1088 | char *data; |
| 1089 | }; |
| 1090 | |
| 1091 | struct rtp_packet_info test_rtp_packets1[] = { |
| 1092 | /* RTP: SeqNo=0, TS=0 */ |
| 1093 | {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] | 1094 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1095 | /* RTP: SeqNo=1, TS=160 */ |
| 1096 | {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] | 1097 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1098 | /* RTP: SeqNo=2, TS=320 */ |
| 1099 | {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] | 1100 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1101 | /* Repeat RTP timestamp: */ |
| 1102 | /* RTP: SeqNo=3, TS=320 */ |
| 1103 | {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] | 1104 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1105 | /* RTP: SeqNo=4, TS=480 */ |
| 1106 | {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] | 1107 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1108 | /* RTP: SeqNo=5, TS=640 */ |
| 1109 | {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] | 1110 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1111 | /* Double skip RTP timestamp (delta = 2*160): */ |
| 1112 | /* RTP: SeqNo=6, TS=960 */ |
| 1113 | {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] | 1114 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1115 | /* RTP: SeqNo=7, TS=1120 */ |
| 1116 | {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] | 1117 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1118 | /* RTP: SeqNo=8, TS=1280 */ |
| 1119 | {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] | 1120 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1121 | /* Non 20ms RTP timestamp (delta = 120): */ |
| 1122 | /* RTP: SeqNo=9, TS=1400 */ |
| 1123 | {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] | 1124 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1125 | /* RTP: SeqNo=10, TS=1560 */ |
| 1126 | {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] | 1127 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1128 | /* RTP: SeqNo=11, TS=1720 */ |
| 1129 | {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] | 1130 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1131 | /* SSRC changed to 0x10203040, RTP timestamp jump */ |
| 1132 | /* RTP: SeqNo=12, TS=34688 */ |
| 1133 | {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] | 1134 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1135 | /* RTP: SeqNo=13, TS=34848 */ |
| 1136 | {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] | 1137 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1138 | /* RTP: SeqNo=14, TS=35008 */ |
| 1139 | {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] | 1140 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1141 | /* Non 20ms RTP timestamp (delta = 120): */ |
| 1142 | /* RTP: SeqNo=15, TS=35128 */ |
| 1143 | {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] | 1144 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1145 | /* RTP: SeqNo=16, TS=35288 */ |
| 1146 | {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] | 1147 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1148 | /* RTP: SeqNo=17, TS=35448 */ |
| 1149 | {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] | 1150 | "\x01\x23\x45\x67\x8A\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1151 | /* SeqNo increment by 2, RTP timestamp delta = 320: */ |
| 1152 | /* RTP: SeqNo=19, TS=35768 */ |
| 1153 | {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] | 1154 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1155 | /* RTP: SeqNo=20, TS=35928 */ |
| 1156 | {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] | 1157 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1158 | /* RTP: SeqNo=21, TS=36088 */ |
| 1159 | {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] | 1160 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1161 | /* Repeat last packet */ |
| 1162 | /* RTP: SeqNo=21, TS=36088 */ |
| 1163 | {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] | 1164 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1165 | /* RTP: SeqNo=22, TS=36248 */ |
| 1166 | {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] | 1167 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1168 | /* RTP: SeqNo=23, TS=36408 */ |
| 1169 | {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] | 1170 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1171 | /* Don't increment SeqNo but increment timestamp by 160 */ |
| 1172 | /* RTP: SeqNo=23, TS=36568 */ |
| 1173 | {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] | 1174 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1175 | /* RTP: SeqNo=24, TS=36728 */ |
| 1176 | {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] | 1177 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1178 | /* RTP: SeqNo=25, TS=36888 */ |
| 1179 | {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] | 1180 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1181 | /* SSRC changed to 0x50607080, RTP timestamp jump, Delay of 1.5s, |
| 1182 | * SeqNo jump */ |
| 1183 | /* RTP: SeqNo=1000, TS=160000 */ |
| 1184 | {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] | 1185 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1186 | /* RTP: SeqNo=1001, TS=160160 */ |
| 1187 | {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] | 1188 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1189 | /* RTP: SeqNo=1002, TS=160320 */ |
| 1190 | {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] | 1191 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1192 | }; |
| 1193 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1194 | void mgcp_patch_and_count(struct mgcp_endpoint *endp, |
| 1195 | struct mgcp_rtp_state *state, |
| 1196 | struct mgcp_rtp_end *rtp_end, |
| 1197 | struct sockaddr_in *addr, char *data, int len); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1198 | |
| 1199 | static void test_packet_error_detection(int patch_ssrc, int patch_ts) |
| 1200 | { |
| 1201 | int i; |
| 1202 | |
| 1203 | struct mgcp_trunk_config trunk; |
| 1204 | struct mgcp_endpoint endp; |
| 1205 | struct mgcp_rtp_state state; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1206 | struct mgcp_rtp_end *rtp; |
| 1207 | struct sockaddr_in addr = { 0 }; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1208 | char buffer[4096]; |
| 1209 | uint32_t last_ssrc = 0; |
| 1210 | uint32_t last_timestamp = 0; |
| 1211 | uint32_t last_seqno = 0; |
Philipp Maier | 9e1d164 | 2018-05-09 16:26:34 +0200 | [diff] [blame] | 1212 | uint64_t last_in_ts_err_cnt = 0; |
| 1213 | uint64_t last_out_ts_err_cnt = 0; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1214 | struct mgcp_conn_rtp *conn = NULL; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1215 | struct mgcp_conn *_conn = NULL; |
Philipp Maier | 9e1d164 | 2018-05-09 16:26:34 +0200 | [diff] [blame] | 1216 | struct rate_ctr test_ctr_in; |
| 1217 | struct rate_ctr test_ctr_out; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1218 | |
| 1219 | printf("Testing packet error detection%s%s.\n", |
| 1220 | patch_ssrc ? ", patch SSRC" : "", |
| 1221 | patch_ts ? ", patch timestamps" : ""); |
| 1222 | |
| 1223 | memset(&trunk, 0, sizeof(trunk)); |
| 1224 | memset(&endp, 0, sizeof(endp)); |
| 1225 | memset(&state, 0, sizeof(state)); |
| 1226 | |
Philipp Maier | 9e1d164 | 2018-05-09 16:26:34 +0200 | [diff] [blame] | 1227 | memset(&test_ctr_in, 0, sizeof(test_ctr_in)); |
| 1228 | memset(&test_ctr_out, 0, sizeof(test_ctr_out)); |
| 1229 | state.in_stream.err_ts_ctr = &test_ctr_in; |
| 1230 | state.out_stream.err_ts_ctr = &test_ctr_out; |
| 1231 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1232 | endp.type = &ep_typeset.rtp; |
| 1233 | |
Philipp Maier | fcd0655 | 2017-11-10 17:32:22 +0100 | [diff] [blame] | 1234 | trunk.vty_number_endpoints = 1; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1235 | trunk.endpoints = &endp; |
| 1236 | trunk.force_constant_ssrc = patch_ssrc; |
| 1237 | trunk.force_aligned_timing = patch_ts; |
| 1238 | |
| 1239 | endp.tcfg = &trunk; |
| 1240 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1241 | INIT_LLIST_HEAD(&endp.conns); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1242 | _conn = mgcp_conn_alloc(NULL, &endp, MGCP_CONN_TYPE_RTP, |
| 1243 | "test-connection"); |
| 1244 | OSMO_ASSERT(_conn); |
| 1245 | conn = mgcp_conn_get_rtp(&endp, _conn->id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1246 | OSMO_ASSERT(conn); |
| 1247 | |
| 1248 | rtp = &conn->end; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1249 | |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1250 | OSMO_ASSERT(mgcp_codec_add(conn, PTYPE_UNDEFINED, "AMR/8000/1") == 0); |
| 1251 | rtp->codec = &rtp->codecs[0]; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1252 | |
| 1253 | for (i = 0; i < ARRAY_SIZE(test_rtp_packets1); ++i) { |
| 1254 | struct rtp_packet_info *info = test_rtp_packets1 + i; |
| 1255 | |
| 1256 | force_monotonic_time_us = round(1000000.0 * info->txtime); |
| 1257 | |
| 1258 | OSMO_ASSERT(info->len <= sizeof(buffer)); |
| 1259 | OSMO_ASSERT(info->len >= 0); |
| 1260 | memmove(buffer, info->data, info->len); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1261 | mgcp_rtp_end_config(&endp, 1, rtp); |
| 1262 | |
| 1263 | mgcp_patch_and_count(&endp, &state, rtp, &addr, |
| 1264 | buffer, info->len); |
| 1265 | |
| 1266 | if (state.out_stream.ssrc != last_ssrc) { |
| 1267 | printf("Output SSRC changed to %08x\n", |
| 1268 | state.out_stream.ssrc); |
| 1269 | last_ssrc = state.out_stream.ssrc; |
| 1270 | } |
| 1271 | |
| 1272 | printf("In TS: %d, dTS: %d, Seq: %d\n", |
| 1273 | state.in_stream.last_timestamp, |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1274 | state.in_stream.last_tsdelta, state.in_stream.last_seq); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1275 | |
| 1276 | printf("Out TS change: %d, dTS: %d, Seq change: %d, " |
Philipp Maier | 9e1d164 | 2018-05-09 16:26:34 +0200 | [diff] [blame] | 1277 | "TS Err change: in +%u, out +%u\n", |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1278 | state.out_stream.last_timestamp - last_timestamp, |
| 1279 | state.out_stream.last_tsdelta, |
| 1280 | state.out_stream.last_seq - last_seqno, |
Philipp Maier | 9e1d164 | 2018-05-09 16:26:34 +0200 | [diff] [blame] | 1281 | (unsigned int) (state.in_stream.err_ts_ctr->current - last_in_ts_err_cnt), |
| 1282 | (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] | 1283 | |
| 1284 | printf("Stats: Jitter = %u, Transit = %d\n", |
Harald Welte | 49e3d5a | 2017-12-25 09:47:57 +0100 | [diff] [blame] | 1285 | calc_jitter(&state), state.stats.transit); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1286 | |
Philipp Maier | 9e1d164 | 2018-05-09 16:26:34 +0200 | [diff] [blame] | 1287 | last_in_ts_err_cnt = state.in_stream.err_ts_ctr->current; |
| 1288 | last_out_ts_err_cnt = state.out_stream.err_ts_ctr->current; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1289 | last_timestamp = state.out_stream.last_timestamp; |
| 1290 | last_seqno = state.out_stream.last_seq; |
| 1291 | } |
| 1292 | |
| 1293 | force_monotonic_time_us = -1; |
Neels Hofmeyr | d20910c | 2017-11-18 21:27:50 +0100 | [diff] [blame] | 1294 | mgcp_conn_free_all(&endp); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | static void test_multilple_codec(void) |
| 1298 | { |
| 1299 | struct mgcp_config *cfg; |
| 1300 | struct mgcp_endpoint *endp; |
| 1301 | struct msgb *inp, *resp; |
| 1302 | struct in_addr addr; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1303 | struct mgcp_conn_rtp *conn = NULL; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1304 | char conn_id[256]; |
Philipp Maier | a74c0ea | 2018-08-02 11:59:09 +0200 | [diff] [blame] | 1305 | int i; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1306 | |
| 1307 | printf("Testing multiple payload types\n"); |
| 1308 | |
| 1309 | cfg = mgcp_config_alloc(); |
Philipp Maier | fcd0655 | 2017-11-10 17:32:22 +0100 | [diff] [blame] | 1310 | cfg->trunk.vty_number_endpoints = 64; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1311 | mgcp_endpoints_allocate(&cfg->trunk); |
| 1312 | cfg->policy_cb = mgcp_test_policy_cb; |
| 1313 | mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1)); |
| 1314 | |
| 1315 | /* Allocate endpoint 1@mgw with two codecs */ |
| 1316 | last_endpoint = -1; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1317 | inp = create_msg(CRCX_MULT_1, NULL); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1318 | resp = mgcp_handle_message(cfg, inp); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1319 | OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id, |
| 1320 | sizeof(conn_id)) == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1321 | msgb_free(inp); |
| 1322 | msgb_free(resp); |
| 1323 | |
| 1324 | OSMO_ASSERT(last_endpoint == 1); |
| 1325 | endp = &cfg->trunk.endpoints[last_endpoint]; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1326 | conn = mgcp_conn_get_rtp(endp, conn_id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1327 | OSMO_ASSERT(conn); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1328 | OSMO_ASSERT(conn->end.codec->payload_type == 18); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1329 | |
| 1330 | /* Allocate 2@mgw with three codecs, last one ignored */ |
| 1331 | last_endpoint = -1; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1332 | inp = create_msg(CRCX_MULT_2, NULL); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1333 | resp = mgcp_handle_message(cfg, inp); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1334 | OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id, |
| 1335 | sizeof(conn_id)) == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1336 | msgb_free(inp); |
| 1337 | msgb_free(resp); |
| 1338 | |
| 1339 | OSMO_ASSERT(last_endpoint == 2); |
| 1340 | endp = &cfg->trunk.endpoints[last_endpoint]; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1341 | conn = mgcp_conn_get_rtp(endp, conn_id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1342 | OSMO_ASSERT(conn); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1343 | OSMO_ASSERT(conn->end.codec->payload_type == 18); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1344 | |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1345 | /* Allocate 3@mgw with no codecs, check for PT == 0 */ |
| 1346 | /* Note: It usually makes no sense to leave the payload type list |
| 1347 | * out. However RFC 2327 does not clearly forbid this case and |
| 1348 | * it makes and since we already decided in OS#2658 that a missing |
| 1349 | * LCO should pick a sane default codec, it makes sense to expect |
| 1350 | * the same behaviour if SDP lacks proper payload type information */ |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1351 | last_endpoint = -1; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1352 | inp = create_msg(CRCX_MULT_3, NULL); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1353 | resp = mgcp_handle_message(cfg, inp); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1354 | OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id, |
| 1355 | sizeof(conn_id)) == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1356 | msgb_free(inp); |
| 1357 | msgb_free(resp); |
| 1358 | |
| 1359 | OSMO_ASSERT(last_endpoint == 3); |
| 1360 | endp = &cfg->trunk.endpoints[last_endpoint]; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1361 | conn = mgcp_conn_get_rtp(endp, conn_id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1362 | OSMO_ASSERT(conn); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1363 | OSMO_ASSERT(conn->end.codec->payload_type == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1364 | |
| 1365 | /* Allocate 4@mgw with a single codec */ |
| 1366 | last_endpoint = -1; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1367 | inp = create_msg(CRCX_MULT_4, NULL); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1368 | resp = mgcp_handle_message(cfg, inp); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1369 | OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id, |
| 1370 | sizeof(conn_id)) == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1371 | msgb_free(inp); |
| 1372 | msgb_free(resp); |
| 1373 | |
| 1374 | OSMO_ASSERT(last_endpoint == 4); |
| 1375 | endp = &cfg->trunk.endpoints[last_endpoint]; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1376 | conn = mgcp_conn_get_rtp(endp, conn_id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1377 | OSMO_ASSERT(conn); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1378 | OSMO_ASSERT(conn->end.codec->payload_type == 18); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1379 | |
| 1380 | /* Allocate 5@mgw at select GSM.. */ |
| 1381 | last_endpoint = -1; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1382 | inp = create_msg(CRCX_MULT_GSM_EXACT, NULL); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1383 | talloc_free(cfg->trunk.audio_name); |
| 1384 | cfg->trunk.audio_name = "GSM/8000"; |
| 1385 | cfg->trunk.no_audio_transcoding = 1; |
| 1386 | resp = mgcp_handle_message(cfg, inp); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1387 | OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id, |
| 1388 | sizeof(conn_id)) == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1389 | msgb_free(inp); |
| 1390 | msgb_free(resp); |
| 1391 | |
| 1392 | OSMO_ASSERT(last_endpoint == 5); |
| 1393 | endp = &cfg->trunk.endpoints[last_endpoint]; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1394 | conn = mgcp_conn_get_rtp(endp, conn_id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1395 | OSMO_ASSERT(conn); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1396 | OSMO_ASSERT(conn->end.codec->payload_type == 3); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1397 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1398 | inp = create_msg(MDCX_NAT_DUMMY, conn_id); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1399 | last_endpoint = -1; |
| 1400 | resp = mgcp_handle_message(cfg, inp); |
| 1401 | msgb_free(inp); |
| 1402 | msgb_free(resp); |
| 1403 | OSMO_ASSERT(last_endpoint == 5); |
| 1404 | endp = &cfg->trunk.endpoints[last_endpoint]; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1405 | conn = mgcp_conn_get_rtp(endp, conn_id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1406 | OSMO_ASSERT(conn); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1407 | OSMO_ASSERT(conn->end.codec->payload_type == 3); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1408 | OSMO_ASSERT(conn->end.rtp_port == htons(16434)); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1409 | memset(&addr, 0, sizeof(addr)); |
| 1410 | inet_aton("8.8.8.8", &addr); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1411 | OSMO_ASSERT(conn->end.addr.s_addr == addr.s_addr); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1412 | |
| 1413 | /* Check what happens without that flag */ |
| 1414 | |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1415 | /* Free the previous endpoint and the data and |
| 1416 | * check if the connection really vanished... */ |
Philipp Maier | 1355d7e | 2018-02-01 14:30:06 +0100 | [diff] [blame] | 1417 | mgcp_endp_release(endp); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1418 | talloc_free(endp->last_response); |
| 1419 | talloc_free(endp->last_trans); |
| 1420 | endp->last_response = endp->last_trans = NULL; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1421 | conn = mgcp_conn_get_rtp(endp, conn_id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1422 | OSMO_ASSERT(!conn); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1423 | |
| 1424 | last_endpoint = -1; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1425 | inp = create_msg(CRCX_MULT_GSM_EXACT, NULL); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1426 | cfg->trunk.no_audio_transcoding = 0; |
| 1427 | resp = mgcp_handle_message(cfg, inp); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1428 | OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id, |
| 1429 | sizeof(conn_id)) == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1430 | msgb_free(inp); |
| 1431 | msgb_free(resp); |
| 1432 | |
| 1433 | OSMO_ASSERT(last_endpoint == 5); |
| 1434 | endp = &cfg->trunk.endpoints[last_endpoint]; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1435 | conn = mgcp_conn_get_rtp(endp, conn_id); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1436 | OSMO_ASSERT(conn); |
Philipp Maier | bc0346e | 2018-06-07 09:52:16 +0200 | [diff] [blame] | 1437 | OSMO_ASSERT(conn->end.codec->payload_type == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1438 | |
Philipp Maier | a74c0ea | 2018-08-02 11:59:09 +0200 | [diff] [blame] | 1439 | for (i = 1; i < cfg->trunk.number_endpoints; i++) |
| 1440 | mgcp_endp_release(&cfg->trunk.endpoints[i]); |
| 1441 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1442 | talloc_free(cfg); |
| 1443 | } |
| 1444 | |
| 1445 | static void test_no_cycle(void) |
| 1446 | { |
| 1447 | struct mgcp_config *cfg; |
| 1448 | struct mgcp_endpoint *endp; |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1449 | struct mgcp_conn_rtp *conn = NULL; |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1450 | struct mgcp_conn *_conn = NULL; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1451 | |
| 1452 | printf("Testing no sequence flow on initial packet\n"); |
| 1453 | |
| 1454 | cfg = mgcp_config_alloc(); |
Philipp Maier | fcd0655 | 2017-11-10 17:32:22 +0100 | [diff] [blame] | 1455 | cfg->trunk.vty_number_endpoints = 64; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1456 | mgcp_endpoints_allocate(&cfg->trunk); |
| 1457 | |
| 1458 | endp = &cfg->trunk.endpoints[1]; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1459 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1460 | _conn = mgcp_conn_alloc(NULL, endp, MGCP_CONN_TYPE_RTP, |
| 1461 | "test-connection"); |
| 1462 | OSMO_ASSERT(_conn); |
| 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); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1465 | |
Harald Welte | 49e3d5a | 2017-12-25 09:47:57 +0100 | [diff] [blame] | 1466 | OSMO_ASSERT(conn->state.stats.initialized == 0); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1467 | |
| 1468 | mgcp_rtp_annex_count(endp, &conn->state, 0, 0, 2342); |
Harald Welte | 49e3d5a | 2017-12-25 09:47:57 +0100 | [diff] [blame] | 1469 | OSMO_ASSERT(conn->state.stats.initialized == 1); |
| 1470 | OSMO_ASSERT(conn->state.stats.cycles == 0); |
| 1471 | OSMO_ASSERT(conn->state.stats.max_seq == 0); |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1472 | |
| 1473 | mgcp_rtp_annex_count(endp, &conn->state, 1, 0, 2342); |
Harald Welte | 49e3d5a | 2017-12-25 09:47:57 +0100 | [diff] [blame] | 1474 | OSMO_ASSERT(conn->state.stats.initialized == 1); |
| 1475 | OSMO_ASSERT(conn->state.stats.cycles == 0); |
| 1476 | OSMO_ASSERT(conn->state.stats.max_seq == 1); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1477 | |
| 1478 | /* now jump.. */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1479 | mgcp_rtp_annex_count(endp, &conn->state, UINT16_MAX, 0, 2342); |
Harald Welte | 49e3d5a | 2017-12-25 09:47:57 +0100 | [diff] [blame] | 1480 | OSMO_ASSERT(conn->state.stats.initialized == 1); |
| 1481 | OSMO_ASSERT(conn->state.stats.cycles == 0); |
| 1482 | OSMO_ASSERT(conn->state.stats.max_seq == UINT16_MAX); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1483 | |
| 1484 | /* and wrap */ |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1485 | mgcp_rtp_annex_count(endp, &conn->state, 0, 0, 2342); |
Harald Welte | 49e3d5a | 2017-12-25 09:47:57 +0100 | [diff] [blame] | 1486 | OSMO_ASSERT(conn->state.stats.initialized == 1); |
| 1487 | OSMO_ASSERT(conn->state.stats.cycles == UINT16_MAX + 1); |
| 1488 | OSMO_ASSERT(conn->state.stats.max_seq == 0); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1489 | |
Philipp Maier | 1355d7e | 2018-02-01 14:30:06 +0100 | [diff] [blame] | 1490 | mgcp_endp_release(endp); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1491 | talloc_free(cfg); |
| 1492 | } |
| 1493 | |
| 1494 | static void test_no_name(void) |
| 1495 | { |
| 1496 | struct mgcp_config *cfg; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1497 | struct msgb *inp, *msg; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1498 | |
| 1499 | printf("Testing no rtpmap name\n"); |
| 1500 | cfg = mgcp_config_alloc(); |
| 1501 | |
Philipp Maier | fcd0655 | 2017-11-10 17:32:22 +0100 | [diff] [blame] | 1502 | cfg->trunk.vty_number_endpoints = 64; |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1503 | cfg->trunk.audio_send_name = 0; |
| 1504 | mgcp_endpoints_allocate(&cfg->trunk); |
| 1505 | |
| 1506 | cfg->policy_cb = mgcp_test_policy_cb; |
| 1507 | |
| 1508 | mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1)); |
| 1509 | |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1510 | inp = create_msg(CRCX, NULL); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1511 | msg = mgcp_handle_message(cfg, inp); |
Philipp Maier | ffd75e4 | 2017-11-22 11:44:50 +0100 | [diff] [blame] | 1512 | |
| 1513 | if (check_response(msg->data, CRCX_RET_NO_RTPMAP) != 0) { |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1514 | printf("FAILED: there should not be a RTPMAP: %s\n", |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1515 | (char *)msg->data); |
| 1516 | OSMO_ASSERT(false); |
| 1517 | } |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1518 | msgb_free(inp); |
| 1519 | msgb_free(msg); |
| 1520 | |
Philipp Maier | 1355d7e | 2018-02-01 14:30:06 +0100 | [diff] [blame] | 1521 | mgcp_endp_release(&cfg->trunk.endpoints[1]); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1522 | talloc_free(cfg); |
| 1523 | } |
| 1524 | |
| 1525 | static void test_osmux_cid(void) |
| 1526 | { |
| 1527 | int id, i; |
| 1528 | |
| 1529 | OSMO_ASSERT(osmux_used_cid() == 0); |
| 1530 | id = osmux_get_cid(); |
| 1531 | OSMO_ASSERT(id == 0); |
| 1532 | OSMO_ASSERT(osmux_used_cid() == 1); |
| 1533 | osmux_put_cid(id); |
| 1534 | OSMO_ASSERT(osmux_used_cid() == 0); |
| 1535 | |
| 1536 | for (i = 0; i < 256; ++i) { |
| 1537 | id = osmux_get_cid(); |
| 1538 | OSMO_ASSERT(id == i); |
| 1539 | OSMO_ASSERT(osmux_used_cid() == i + 1); |
| 1540 | } |
| 1541 | |
| 1542 | id = osmux_get_cid(); |
| 1543 | OSMO_ASSERT(id == -1); |
| 1544 | |
| 1545 | for (i = 0; i < 256; ++i) |
| 1546 | osmux_put_cid(i); |
| 1547 | OSMO_ASSERT(osmux_used_cid() == 0); |
| 1548 | } |
| 1549 | |
| 1550 | static const struct log_info_cat log_categories[] = { |
| 1551 | }; |
| 1552 | |
| 1553 | const struct log_info log_info = { |
Philipp Maier | 87bd9be | 2017-08-22 16:35:41 +0200 | [diff] [blame] | 1554 | .cat = log_categories, |
| 1555 | .num_cat = ARRAY_SIZE(log_categories), |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1556 | }; |
| 1557 | |
Philipp Maier | 3d7b58d | 2018-06-06 09:35:31 +0200 | [diff] [blame] | 1558 | static void test_get_lco_identifier(void) |
| 1559 | { |
| 1560 | char *test; |
| 1561 | printf("Testing get_lco_identifier()\n"); |
| 1562 | |
| 1563 | /* Normal case at the beginning */ |
| 1564 | test = "p:10, a:PCMU"; |
| 1565 | printf("%s -> %s\n", test, get_lco_identifier(test)); |
| 1566 | |
| 1567 | test = "p:10, a:PCMU"; |
| 1568 | printf("%s -> %s\n", test, get_lco_identifier(test)); |
| 1569 | |
| 1570 | /* Begin parsing in the middle of the value part of |
| 1571 | * the previous LCO option value */ |
| 1572 | test = "XXXX, p:10, a:PCMU"; |
| 1573 | printf("'%s' -> '%s'\n", test, get_lco_identifier(test)); |
| 1574 | |
| 1575 | test = "XXXX,p:10,a:PCMU"; |
| 1576 | printf("'%s' -> '%s'\n", test, get_lco_identifier(test)); |
| 1577 | |
| 1578 | test = "10,a:PCMU"; |
| 1579 | printf("'%s' -> '%s'\n", test, get_lco_identifier(test)); |
| 1580 | |
| 1581 | test = "10, a:PCMU"; |
| 1582 | printf("'%s' -> '%s'\n", test, get_lco_identifier(test)); |
| 1583 | |
| 1584 | test = "10,a: PCMU"; |
| 1585 | printf("'%s' -> '%s'\n", test, get_lco_identifier(test)); |
| 1586 | |
| 1587 | test = "10 ,a: PCMU"; |
| 1588 | printf("'%s' -> '%s'\n", test, get_lco_identifier(test)); |
| 1589 | |
| 1590 | /* Begin parsing right at the end of the previous LCO |
| 1591 | * option value */ |
| 1592 | test = ", a:PCMU"; |
| 1593 | printf("'%s' -> '%s'\n", test, get_lco_identifier(test)); |
| 1594 | |
| 1595 | test = " a:PCMU"; |
| 1596 | printf("'%s' -> '%s'\n", test, get_lco_identifier(test)); |
| 1597 | |
| 1598 | /* Empty string, result should be (null) */ |
| 1599 | test = ""; |
| 1600 | printf("'%s' -> '%s'\n", test, get_lco_identifier(test)); |
| 1601 | |
| 1602 | /* Missing colons, result should be (null) */ |
| 1603 | test = "p10, aPCMU"; |
| 1604 | printf("%s -> %s\n", test, get_lco_identifier(test)); |
| 1605 | |
| 1606 | /* Colon separated from the identifier, result should be (null) */ |
| 1607 | test = "10,a :PCMU"; |
| 1608 | printf("'%s' -> '%s'\n", test, get_lco_identifier(test)); |
| 1609 | } |
| 1610 | |
| 1611 | static void test_check_local_cx_options(void *ctx) |
| 1612 | { |
| 1613 | /* Legal cases */ |
| 1614 | OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:PCMU") == 0); |
| 1615 | OSMO_ASSERT(check_local_cx_options(ctx, "a:PCMU") == 0); |
| 1616 | OSMO_ASSERT(check_local_cx_options(ctx, "a:PCMU, p:10, IN:10") == 0); |
| 1617 | OSMO_ASSERT(check_local_cx_options(ctx, "one:AAA, two:BB, tree:C") == |
| 1618 | 0); |
| 1619 | OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:PCMU") == 0); |
| 1620 | OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:G726-32") == 0); |
| 1621 | OSMO_ASSERT(check_local_cx_options(ctx, "p:10-20, b:64") == 0); |
| 1622 | OSMO_ASSERT(check_local_cx_options(ctx, "b:32-64, e:off") == 0); |
| 1623 | OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:PCMU;G726-32") == 0); |
| 1624 | |
| 1625 | /* Illegal spaces before and after colon */ |
| 1626 | OSMO_ASSERT(check_local_cx_options(ctx, "a:PCMU, p :10") == -1); |
| 1627 | OSMO_ASSERT(check_local_cx_options(ctx, "a :PCMU, p:10") == -1); |
| 1628 | OSMO_ASSERT(check_local_cx_options(ctx, "p: 10, a:PCMU") == -1); |
| 1629 | |
| 1630 | /* Check if multiple appearances of LCOs are rejected */ |
| 1631 | OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:PCMU, p:10") == -1); |
| 1632 | OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:PCMU, a:PCMU, p:10") == |
| 1633 | -1); |
| 1634 | OSMO_ASSERT(check_local_cx_options(ctx, "p:10, p:10") == -1); |
| 1635 | |
| 1636 | /* Check if empty LCO are rejected */ |
| 1637 | OSMO_ASSERT(check_local_cx_options(ctx, "p: , a:PCMU") == -1); |
| 1638 | OSMO_ASSERT(check_local_cx_options(ctx, "p: , a: PCMU") == -1); |
| 1639 | OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a: PCMU") == -1); |
| 1640 | OSMO_ASSERT(check_local_cx_options(ctx, "p:, a:PCMU") == -1); |
| 1641 | OSMO_ASSERT(check_local_cx_options(ctx, "p:10, a:") == -1); |
| 1642 | |
| 1643 | /* Garbeled beginning and ends */ |
| 1644 | OSMO_ASSERT(check_local_cx_options(ctx, ":10, a:10") == -1); |
| 1645 | OSMO_ASSERT(check_local_cx_options(ctx, "10, a:PCMU") == -1); |
| 1646 | OSMO_ASSERT(check_local_cx_options(ctx, ", a:PCMU") == -1); |
| 1647 | OSMO_ASSERT(check_local_cx_options(ctx, " a:PCMU") == -1); |
| 1648 | OSMO_ASSERT(check_local_cx_options(ctx, "a:PCMU,") == -1); |
| 1649 | OSMO_ASSERT(check_local_cx_options(ctx, "a:PCMU, ") == -1); |
| 1650 | |
| 1651 | /* Illegal strings */ |
| 1652 | OSMO_ASSERT(check_local_cx_options(ctx, " ") == -1); |
| 1653 | OSMO_ASSERT(check_local_cx_options(ctx, "") == -1); |
| 1654 | OSMO_ASSERT(check_local_cx_options(ctx, "AAA") == -1); |
| 1655 | OSMO_ASSERT(check_local_cx_options(ctx, ":,") == -1); |
| 1656 | OSMO_ASSERT(check_local_cx_options(ctx, ",:") == -1); |
| 1657 | OSMO_ASSERT(check_local_cx_options(ctx, ",,,") == -1); |
| 1658 | } |
| 1659 | |
Philipp Maier | 6931f9a | 2018-07-26 09:29:31 +0200 | [diff] [blame] | 1660 | static void test_mgcp_codec_pt_translate_pars(struct mgcp_rtp_codec *c) |
| 1661 | { |
| 1662 | c->rate = 8000; |
| 1663 | c->channels = 1; |
| 1664 | c->frame_duration_num = 23; |
| 1665 | c->frame_duration_den = 42; |
| 1666 | } |
| 1667 | |
| 1668 | static void test_mgcp_codec_pt_translate(void) |
| 1669 | { |
| 1670 | struct mgcp_conn_rtp conn_src; |
| 1671 | struct mgcp_conn_rtp conn_dst; |
| 1672 | int pt_dst; |
| 1673 | |
| 1674 | /* Setup a realistic set of codec configurations on both |
| 1675 | * ends. AMR and HR will use different payload types. PCMU |
| 1676 | * must use 0 on both ends since this is not a dynamic payload |
| 1677 | * type */ |
| 1678 | test_mgcp_codec_pt_translate_pars(&conn_src.end.codecs[0]); |
| 1679 | test_mgcp_codec_pt_translate_pars(&conn_dst.end.codecs[0]); |
| 1680 | test_mgcp_codec_pt_translate_pars(&conn_src.end.codecs[1]); |
| 1681 | test_mgcp_codec_pt_translate_pars(&conn_dst.end.codecs[1]); |
| 1682 | test_mgcp_codec_pt_translate_pars(&conn_src.end.codecs[2]); |
| 1683 | test_mgcp_codec_pt_translate_pars(&conn_dst.end.codecs[2]); |
| 1684 | conn_src.end.codecs[0].payload_type = 112; |
| 1685 | conn_dst.end.codecs[0].payload_type = 96; |
| 1686 | conn_src.end.codecs[1].payload_type = 0; |
| 1687 | conn_dst.end.codecs[1].payload_type = 0; |
| 1688 | conn_src.end.codecs[2].payload_type = 111; |
| 1689 | conn_dst.end.codecs[2].payload_type = 97; |
| 1690 | conn_src.end.codecs[0].audio_name = "AMR/8000/1"; |
| 1691 | conn_dst.end.codecs[0].audio_name = "AMR/8000/1"; |
| 1692 | conn_src.end.codecs[1].audio_name = "PCMU/8000/1"; |
| 1693 | conn_dst.end.codecs[1].audio_name = "PCMU/8000/1"; |
| 1694 | conn_src.end.codecs[2].audio_name = "GSM-HR-08/8000/1"; |
| 1695 | conn_dst.end.codecs[2].audio_name = "GSM-HR-08/8000/1"; |
| 1696 | conn_src.end.codecs[0].subtype_name = "AMR"; |
| 1697 | conn_dst.end.codecs[0].subtype_name = "AMR"; |
| 1698 | conn_src.end.codecs[1].subtype_name = "PCMU"; |
| 1699 | conn_dst.end.codecs[1].subtype_name = "PCMU"; |
| 1700 | conn_src.end.codecs[2].subtype_name = "GSM-HR-08"; |
| 1701 | conn_dst.end.codecs[2].subtype_name = "GSM-HR-08"; |
| 1702 | conn_src.end.codecs_assigned = 3; |
| 1703 | conn_dst.end.codecs_assigned = 3; |
| 1704 | |
| 1705 | /* We expect the function to find the PT we must use when we send the |
| 1706 | * packet out to the destination. All we know is the context for both |
| 1707 | * connections and the payload type from the source packet */ |
| 1708 | pt_dst = |
| 1709 | mgcp_codec_pt_translate(&conn_src, &conn_dst, |
| 1710 | conn_src.end.codecs[0].payload_type); |
| 1711 | OSMO_ASSERT(pt_dst == conn_dst.end.codecs[0].payload_type); |
| 1712 | pt_dst = |
| 1713 | mgcp_codec_pt_translate(&conn_src, &conn_dst, |
| 1714 | conn_src.end.codecs[1].payload_type); |
| 1715 | OSMO_ASSERT(pt_dst == conn_dst.end.codecs[1].payload_type); |
| 1716 | pt_dst = |
| 1717 | mgcp_codec_pt_translate(&conn_src, &conn_dst, |
| 1718 | conn_src.end.codecs[2].payload_type); |
| 1719 | OSMO_ASSERT(pt_dst == conn_dst.end.codecs[2].payload_type); |
| 1720 | |
| 1721 | /* Try some constellations that must fail */ |
| 1722 | pt_dst = mgcp_codec_pt_translate(&conn_src, &conn_dst, 123); |
| 1723 | OSMO_ASSERT(pt_dst == -EINVAL); |
| 1724 | conn_src.end.codecs_assigned = 0; |
| 1725 | conn_dst.end.codecs_assigned = 3; |
| 1726 | pt_dst = |
| 1727 | mgcp_codec_pt_translate(&conn_src, &conn_dst, |
| 1728 | conn_src.end.codecs[0].payload_type); |
| 1729 | OSMO_ASSERT(pt_dst == -EINVAL); |
| 1730 | pt_dst = |
| 1731 | mgcp_codec_pt_translate(&conn_src, &conn_dst, |
| 1732 | conn_src.end.codecs[1].payload_type); |
| 1733 | OSMO_ASSERT(pt_dst == -EINVAL); |
| 1734 | pt_dst = |
| 1735 | mgcp_codec_pt_translate(&conn_src, &conn_dst, |
| 1736 | conn_src.end.codecs[2].payload_type); |
| 1737 | OSMO_ASSERT(pt_dst == -EINVAL); |
| 1738 | conn_src.end.codecs_assigned = 3; |
| 1739 | conn_dst.end.codecs_assigned = 0; |
| 1740 | pt_dst = |
| 1741 | mgcp_codec_pt_translate(&conn_src, &conn_dst, |
| 1742 | conn_src.end.codecs[0].payload_type); |
| 1743 | OSMO_ASSERT(pt_dst == -EINVAL); |
| 1744 | pt_dst = |
| 1745 | mgcp_codec_pt_translate(&conn_src, &conn_dst, |
| 1746 | conn_src.end.codecs[1].payload_type); |
| 1747 | OSMO_ASSERT(pt_dst == -EINVAL); |
| 1748 | pt_dst = |
| 1749 | mgcp_codec_pt_translate(&conn_src, &conn_dst, |
| 1750 | conn_src.end.codecs[2].payload_type); |
| 1751 | OSMO_ASSERT(pt_dst == -EINVAL); |
| 1752 | } |
| 1753 | |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1754 | int main(int argc, char **argv) |
| 1755 | { |
Neels Hofmeyr | 60f8e31 | 2018-03-30 23:01:07 +0200 | [diff] [blame] | 1756 | void *ctx = talloc_named_const(NULL, 0, "mgcp_test"); |
| 1757 | void *msgb_ctx = msgb_talloc_ctx_init(ctx, 0); |
| 1758 | osmo_init_logging2(ctx, &log_info); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1759 | |
| 1760 | test_strline(); |
| 1761 | test_values(); |
| 1762 | test_messages(); |
| 1763 | test_retransmission(); |
| 1764 | test_packet_loss_calc(); |
| 1765 | test_rqnt_cb(); |
| 1766 | test_mgcp_stats(); |
| 1767 | test_packet_error_detection(1, 0); |
| 1768 | test_packet_error_detection(0, 0); |
| 1769 | test_packet_error_detection(0, 1); |
| 1770 | test_packet_error_detection(1, 1); |
| 1771 | test_multilple_codec(); |
| 1772 | test_no_cycle(); |
| 1773 | test_no_name(); |
| 1774 | test_osmux_cid(); |
Philipp Maier | 3d7b58d | 2018-06-06 09:35:31 +0200 | [diff] [blame] | 1775 | test_get_lco_identifier(); |
| 1776 | test_check_local_cx_options(ctx); |
Philipp Maier | 6931f9a | 2018-07-26 09:29:31 +0200 | [diff] [blame] | 1777 | test_mgcp_codec_pt_translate(); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1778 | |
Neels Hofmeyr | 465446b | 2017-11-18 21:26:26 +0100 | [diff] [blame] | 1779 | OSMO_ASSERT(talloc_total_size(msgb_ctx) == 0); |
| 1780 | OSMO_ASSERT(talloc_total_blocks(msgb_ctx) == 1); |
| 1781 | talloc_free(msgb_ctx); |
Neels Hofmeyr | f83ec56 | 2017-09-07 19:18:40 +0200 | [diff] [blame] | 1782 | printf("Done\n"); |
| 1783 | return EXIT_SUCCESS; |
| 1784 | } |