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