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