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