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