Holger Hans Peter Freyther | f0bc075 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 1 | /* |
Holger Hans Peter Freyther | faa6793 | 2012-10-22 18:09:35 +0200 | [diff] [blame] | 2 | * (C) 2011-2012 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 3 | * (C) 2011-2012 by On-Waves |
Holger Hans Peter Freyther | f0bc075 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 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 | |
| 20 | #include <openbsc/mgcp.h> |
Holger Hans Peter Freyther | 49e170b | 2011-02-28 14:37:03 +0100 | [diff] [blame] | 21 | #include <openbsc/mgcp_internal.h> |
Holger Hans Peter Freyther | f0bc075 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 22 | |
Holger Hans Peter Freyther | 2d59cc6 | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 23 | #include <osmocom/core/application.h> |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 24 | #include <osmocom/core/talloc.h> |
Holger Hans Peter Freyther | f0bc075 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 25 | #include <string.h> |
Holger Hans Peter Freyther | faa6793 | 2012-10-22 18:09:35 +0200 | [diff] [blame] | 26 | #include <limits.h> |
Holger Hans Peter Freyther | f0bc075 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 27 | |
Jacob Erlbeck | e7060c4 | 2013-11-29 13:43:44 +0100 | [diff] [blame] | 28 | char *strline_r(char *str, char **saveptr); |
| 29 | |
| 30 | const char *strline_test_data = |
| 31 | "one CR\r" |
| 32 | "two CR\r" |
| 33 | "\r" |
| 34 | "one CRLF\r\n" |
| 35 | "two CRLF\r\n" |
| 36 | "\r\n" |
| 37 | "one LF\n" |
| 38 | "two LF\n" |
| 39 | "\n" |
| 40 | "mixed (4 lines)\r\r\n\n\r\n"; |
| 41 | |
| 42 | #define EXPECTED_NUMBER_OF_LINES 13 |
| 43 | |
| 44 | static void test_strline(void) |
| 45 | { |
| 46 | char *save = NULL; |
| 47 | char *line; |
| 48 | char buf[2048]; |
| 49 | int counter = 0; |
| 50 | |
| 51 | strncpy(buf, strline_test_data, sizeof(buf)); |
| 52 | |
| 53 | for (line = strline_r(buf, &save); line; |
| 54 | line = strline_r(NULL, &save)) { |
| 55 | printf("line: '%s'\n", line); |
| 56 | counter++; |
| 57 | } |
| 58 | |
| 59 | OSMO_ASSERT(counter == EXPECTED_NUMBER_OF_LINES); |
| 60 | } |
| 61 | |
Harald Welte | 834f3f1 | 2012-01-27 00:00:44 +0100 | [diff] [blame] | 62 | #define AUEP1 "AUEP 158663169 ds/e1-1/2@172.16.6.66 MGCP 1.0\r\n" |
Harald Welte | a7c9a92 | 2012-01-27 00:36:56 +0100 | [diff] [blame] | 63 | #define AUEP1_RET "200 158663169 OK\r\n" |
Harald Welte | 834f3f1 | 2012-01-27 00:00:44 +0100 | [diff] [blame] | 64 | #define AUEP2 "AUEP 18983213 ds/e1-2/1@172.16.6.66 MGCP 1.0\r\n" |
Harald Welte | a7c9a92 | 2012-01-27 00:36:56 +0100 | [diff] [blame] | 65 | #define AUEP2_RET "500 18983213 FAIL\r\n" |
Holger Hans Peter Freyther | 0a6455c | 2012-03-16 09:53:49 +0100 | [diff] [blame] | 66 | #define EMPTY "\r\n" |
| 67 | #define EMPTY_RET NULL |
| 68 | #define SHORT "CRCX \r\n" |
| 69 | #define SHORT_RET "510 000000 FAIL\r\n" |
| 70 | |
Holger Hans Peter Freyther | 74645f4 | 2012-12-10 12:54:57 +0100 | [diff] [blame] | 71 | #define MDCX_WRONG_EP "MDCX 18983213 ds/e1-3/1@172.16.6.66 MGCP 1.0\r\n" |
| 72 | #define MDCX_ERR_RET "510 18983213 FAIL\r\n" |
| 73 | #define MDCX_UNALLOCATED "MDCX 18983214 ds/e1-1/2@172.16.6.66 MGCP 1.0\r\n" |
| 74 | #define MDCX_RET "400 18983214 FAIL\r\n" |
| 75 | #define MDCX3 "MDCX 18983215 1@mgw MGCP 1.0\r\n" |
| 76 | #define MDCX3_RET "200 18983215 OK\r\n" \ |
| 77 | "I: 1\n" \ |
| 78 | "\n" \ |
| 79 | "v=0\r\n" \ |
| 80 | "o=- 1 23 IN IP4 0.0.0.0\r\n" \ |
| 81 | "c=IN IP4 0.0.0.0\r\n" \ |
| 82 | "t=0 0\r\n" \ |
| 83 | "m=audio 0 RTP/AVP 126\r\n" \ |
Jacob Erlbeck | e91324d | 2013-12-10 13:09:37 +0100 | [diff] [blame] | 84 | "a=rtpmap:126 AMR/8000\r\n" \ |
| 85 | "a=ptime:20\r\n" |
Jacob Erlbeck | fe9896f | 2013-11-29 13:43:45 +0100 | [diff] [blame] | 86 | #define MDCX4 "MDCX 18983216 1@mgw MGCP 1.0\r\n" \ |
| 87 | "C: 2\r\n" \ |
| 88 | "I: 1\r\n" \ |
| 89 | "L: p:20, a:AMR, nt:IN\r\n" \ |
| 90 | "\n" \ |
| 91 | "v=0\r\n" \ |
| 92 | "o=- 1 23 IN IP4 0.0.0.0\r\n" \ |
| 93 | "c=IN IP4 0.0.0.0\r\n" \ |
| 94 | "t=0 0\r\n" \ |
| 95 | "m=audio 4441 RTP/AVP 99\r\n" \ |
Jacob Erlbeck | 07a25f7 | 2013-12-10 13:09:37 +0100 | [diff] [blame] | 96 | "a=rtpmap:99 AMR/8000\r\n" \ |
| 97 | "a=ptime:40\r\n" |
| 98 | #define MDCX4_RET(Ident) "200 " Ident " OK\r\n" \ |
Jacob Erlbeck | fe9896f | 2013-11-29 13:43:45 +0100 | [diff] [blame] | 99 | "I: 1\n" \ |
| 100 | "\n" \ |
| 101 | "v=0\r\n" \ |
| 102 | "o=- 1 23 IN IP4 0.0.0.0\r\n" \ |
| 103 | "c=IN IP4 0.0.0.0\r\n" \ |
| 104 | "t=0 0\r\n" \ |
| 105 | "m=audio 0 RTP/AVP 126\r\n" \ |
Jacob Erlbeck | e91324d | 2013-12-10 13:09:37 +0100 | [diff] [blame] | 106 | "a=rtpmap:126 AMR/8000\r\n" \ |
| 107 | "a=ptime:20\r\n" |
Holger Hans Peter Freyther | 74645f4 | 2012-12-10 12:54:57 +0100 | [diff] [blame] | 108 | |
Jacob Erlbeck | 07a25f7 | 2013-12-10 13:09:37 +0100 | [diff] [blame] | 109 | #define MDCX4_PT1 "MDCX 18983217 1@mgw MGCP 1.0\r\n" \ |
| 110 | "C: 2\r\n" \ |
| 111 | "I: 1\r\n" \ |
| 112 | "L: p:20-40, a:AMR, nt:IN\r\n" \ |
| 113 | "\n" \ |
| 114 | "v=0\r\n" \ |
| 115 | "o=- 1 23 IN IP4 0.0.0.0\r\n" \ |
| 116 | "c=IN IP4 0.0.0.0\r\n" \ |
| 117 | "t=0 0\r\n" \ |
| 118 | "m=audio 4441 RTP/AVP 99\r\n" \ |
| 119 | "a=rtpmap:99 AMR/8000\r\n" \ |
| 120 | "a=ptime:40\r\n" |
| 121 | |
| 122 | #define MDCX4_PT2 "MDCX 18983218 1@mgw MGCP 1.0\r\n" \ |
| 123 | "C: 2\r\n" \ |
| 124 | "I: 1\r\n" \ |
| 125 | "L: p:20-20, a:AMR, nt:IN\r\n" \ |
| 126 | "\n" \ |
| 127 | "v=0\r\n" \ |
| 128 | "o=- 1 23 IN IP4 0.0.0.0\r\n" \ |
| 129 | "c=IN IP4 0.0.0.0\r\n" \ |
| 130 | "t=0 0\r\n" \ |
| 131 | "m=audio 4441 RTP/AVP 99\r\n" \ |
| 132 | "a=rtpmap:99 AMR/8000\r\n" \ |
| 133 | "a=ptime:40\r\n" |
| 134 | |
| 135 | #define MDCX4_PT3 "MDCX 18983219 1@mgw MGCP 1.0\r\n" \ |
| 136 | "C: 2\r\n" \ |
| 137 | "I: 1\r\n" \ |
| 138 | "L: a:AMR, nt:IN\r\n" \ |
| 139 | "\n" \ |
| 140 | "v=0\r\n" \ |
| 141 | "o=- 1 23 IN IP4 0.0.0.0\r\n" \ |
| 142 | "c=IN IP4 0.0.0.0\r\n" \ |
| 143 | "t=0 0\r\n" \ |
| 144 | "m=audio 4441 RTP/AVP 99\r\n" \ |
| 145 | "a=rtpmap:99 AMR/8000\r\n" \ |
| 146 | "a=ptime:40\r\n" |
| 147 | |
Holger Hans Peter Freyther | 0a6455c | 2012-03-16 09:53:49 +0100 | [diff] [blame] | 148 | #define SHORT2 "CRCX 1" |
| 149 | #define SHORT2_RET "510 000000 FAIL\r\n" |
| 150 | #define SHORT3 "CRCX 1 1@mgw" |
| 151 | #define SHORT4 "CRCX 1 1@mgw MGCP" |
| 152 | #define SHORT5 "CRCX 1 1@mgw MGCP 1.0" |
Harald Welte | a7c9a92 | 2012-01-27 00:36:56 +0100 | [diff] [blame] | 153 | |
Harald Welte | ca765cd | 2012-01-27 00:37:23 +0100 | [diff] [blame] | 154 | #define CRCX "CRCX 2 1@mgw MGCP 1.0\r\n" \ |
| 155 | "M: sendrecv\r\n" \ |
| 156 | "C: 2\r\n" \ |
Jacob Erlbeck | 07a25f7 | 2013-12-10 13:09:37 +0100 | [diff] [blame] | 157 | "L: p:20\r\n" \ |
Harald Welte | ca765cd | 2012-01-27 00:37:23 +0100 | [diff] [blame] | 158 | "\r\n" \ |
| 159 | "v=0\r\n" \ |
| 160 | "c=IN IP4 123.12.12.123\r\n" \ |
| 161 | "m=audio 5904 RTP/AVP 97\r\n" \ |
Jacob Erlbeck | 07a25f7 | 2013-12-10 13:09:37 +0100 | [diff] [blame] | 162 | "a=rtpmap:97 GSM-EFR/8000\r\n" \ |
| 163 | "a=ptime:40\r\n" |
Harald Welte | ca765cd | 2012-01-27 00:37:23 +0100 | [diff] [blame] | 164 | |
| 165 | #define CRCX_RET "200 2 OK\r\n" \ |
| 166 | "I: 1\n" \ |
| 167 | "\n" \ |
| 168 | "v=0\r\n" \ |
| 169 | "o=- 1 23 IN IP4 0.0.0.0\r\n" \ |
| 170 | "c=IN IP4 0.0.0.0\r\n" \ |
| 171 | "t=0 0\r\n" \ |
| 172 | "m=audio 0 RTP/AVP 126\r\n" \ |
Jacob Erlbeck | e91324d | 2013-12-10 13:09:37 +0100 | [diff] [blame] | 173 | "a=rtpmap:126 AMR/8000\r\n" \ |
| 174 | "a=ptime:20\r\n" |
Harald Welte | ca765cd | 2012-01-27 00:37:23 +0100 | [diff] [blame] | 175 | |
Harald Welte | ca765cd | 2012-01-27 00:37:23 +0100 | [diff] [blame] | 176 | #define CRCX_ZYN "CRCX 2 1@mgw MGCP 1.0\r" \ |
| 177 | "M: sendrecv\r" \ |
| 178 | "C: 2\r\r" \ |
| 179 | "v=0\r" \ |
| 180 | "c=IN IP4 123.12.12.123\r" \ |
| 181 | "m=audio 5904 RTP/AVP 97\r" \ |
| 182 | "a=rtpmap:97 GSM-EFR/8000\r" |
Harald Welte | a7c9a92 | 2012-01-27 00:36:56 +0100 | [diff] [blame] | 183 | |
Holger Hans Peter Freyther | 0e8e18e | 2012-12-07 14:42:03 +0100 | [diff] [blame] | 184 | #define CRCX_ZYN_RET "200 2 OK\r\n" \ |
| 185 | "I: 2\n" \ |
| 186 | "\n" \ |
| 187 | "v=0\r\n" \ |
| 188 | "o=- 2 23 IN IP4 0.0.0.0\r\n" \ |
| 189 | "c=IN IP4 0.0.0.0\r\n" \ |
| 190 | "t=0 0\r\n" \ |
| 191 | "m=audio 0 RTP/AVP 126\r\n" \ |
Jacob Erlbeck | e91324d | 2013-12-10 13:09:37 +0100 | [diff] [blame] | 192 | "a=rtpmap:126 AMR/8000\r\n" \ |
| 193 | "a=ptime:20\r\n" |
Holger Hans Peter Freyther | 0e8e18e | 2012-12-07 14:42:03 +0100 | [diff] [blame] | 194 | |
Holger Hans Peter Freyther | 8fc6d08 | 2012-09-14 17:18:12 +0200 | [diff] [blame] | 195 | #define DLCX "DLCX 7 1@mgw MGCP 1.0\r\n" \ |
| 196 | "C: 2\r\n" |
| 197 | |
| 198 | #define DLCX_RET "250 7 OK\r\n" \ |
Jacob Erlbeck | a2528da | 2013-11-25 12:53:28 +0100 | [diff] [blame] | 199 | "P: PS=0, OS=0, PR=0, OR=0, PL=0, JI=0\r\n" \ |
| 200 | "X-Osmo-CP: EC TIS=0, TOS=0, TIR=0, TOR=0\r\n" |
Holger Hans Peter Freyther | 8fc6d08 | 2012-09-14 17:18:12 +0200 | [diff] [blame] | 201 | |
Holger Hans Peter Freyther | 46880c2 | 2012-11-29 12:54:22 +0100 | [diff] [blame] | 202 | #define RQNT "RQNT 186908780 1@mgw MGCP 1.0\r\n" \ |
| 203 | "X: B244F267488\r\n" \ |
| 204 | "S: D/9\r\n" |
| 205 | |
Holger Hans Peter Freyther | cd25695 | 2012-12-07 15:04:07 +0100 | [diff] [blame] | 206 | #define RQNT2 "RQNT 186908781 1@mgw MGCP 1.0\r\n" \ |
Holger Hans Peter Freyther | 46880c2 | 2012-11-29 12:54:22 +0100 | [diff] [blame] | 207 | "X: ADD4F26746F\r\n" \ |
| 208 | "R: D/[0-9#*](N), G/ft, fxr/t38\r\n" |
| 209 | |
Holger Hans Peter Freyther | cd25695 | 2012-12-07 15:04:07 +0100 | [diff] [blame] | 210 | #define RQNT1_RET "200 186908780 OK\r\n" |
| 211 | #define RQNT2_RET "200 186908781 OK\r\n" |
Holger Hans Peter Freyther | 8fc6d08 | 2012-09-14 17:18:12 +0200 | [diff] [blame] | 212 | |
Jacob Erlbeck | fe9896f | 2013-11-29 13:43:45 +0100 | [diff] [blame] | 213 | #define PTYPE_IGNORE 0 /* == default initializer */ |
| 214 | #define PTYPE_NONE 128 |
| 215 | #define PTYPE_NYI PTYPE_NONE |
| 216 | |
Harald Welte | a7c9a92 | 2012-01-27 00:36:56 +0100 | [diff] [blame] | 217 | struct mgcp_test { |
| 218 | const char *name; |
| 219 | const char *req; |
| 220 | const char *exp_resp; |
Jacob Erlbeck | fe9896f | 2013-11-29 13:43:45 +0100 | [diff] [blame] | 221 | int exp_net_ptype; |
| 222 | int exp_bts_ptype; |
Harald Welte | a7c9a92 | 2012-01-27 00:36:56 +0100 | [diff] [blame] | 223 | }; |
| 224 | |
Holger Hans Peter Freyther | 0e8e18e | 2012-12-07 14:42:03 +0100 | [diff] [blame] | 225 | static const struct mgcp_test tests[] = { |
Harald Welte | a7c9a92 | 2012-01-27 00:36:56 +0100 | [diff] [blame] | 226 | { "AUEP1", AUEP1, AUEP1_RET }, |
| 227 | { "AUEP2", AUEP2, AUEP2_RET }, |
Holger Hans Peter Freyther | 74645f4 | 2012-12-10 12:54:57 +0100 | [diff] [blame] | 228 | { "MDCX1", MDCX_WRONG_EP, MDCX_ERR_RET }, |
| 229 | { "MDCX2", MDCX_UNALLOCATED, MDCX_RET }, |
Jacob Erlbeck | e3440c7 | 2013-11-29 13:43:49 +0100 | [diff] [blame] | 230 | { "CRCX", CRCX, CRCX_RET, 97, 126 }, |
Jacob Erlbeck | fe9896f | 2013-11-29 13:43:45 +0100 | [diff] [blame] | 231 | { "MDCX3", MDCX3, MDCX3_RET, PTYPE_NONE, 126 }, |
Jacob Erlbeck | 07a25f7 | 2013-12-10 13:09:37 +0100 | [diff] [blame] | 232 | { "MDCX4", MDCX4, MDCX4_RET("18983216"), 99, 126 }, |
| 233 | { "MDCX4_PT1", MDCX4_PT1, MDCX4_RET("18983217"), 99, 126 }, |
| 234 | { "MDCX4_PT2", MDCX4_PT2, MDCX4_RET("18983218"), 99, 126 }, |
| 235 | { "MDCX4_PT3", MDCX4_PT3, MDCX4_RET("18983219"), 99, 126 }, |
Jacob Erlbeck | fe9896f | 2013-11-29 13:43:45 +0100 | [diff] [blame] | 236 | { "DLCX", DLCX, DLCX_RET, -1, -1 }, |
Jacob Erlbeck | e3440c7 | 2013-11-29 13:43:49 +0100 | [diff] [blame] | 237 | { "CRCX_ZYN", CRCX_ZYN, CRCX_ZYN_RET, 97, 126 }, |
Holger Hans Peter Freyther | 0a6455c | 2012-03-16 09:53:49 +0100 | [diff] [blame] | 238 | { "EMPTY", EMPTY, EMPTY_RET }, |
| 239 | { "SHORT1", SHORT, SHORT_RET }, |
| 240 | { "SHORT2", SHORT2, SHORT2_RET }, |
| 241 | { "SHORT3", SHORT3, SHORT2_RET }, |
| 242 | { "SHORT4", SHORT4, SHORT2_RET }, |
Holger Hans Peter Freyther | cd25695 | 2012-12-07 15:04:07 +0100 | [diff] [blame] | 243 | { "RQNT1", RQNT, RQNT1_RET }, |
| 244 | { "RQNT2", RQNT2, RQNT2_RET }, |
Jacob Erlbeck | fe9896f | 2013-11-29 13:43:45 +0100 | [diff] [blame] | 245 | { "DLCX", DLCX, DLCX_RET, -1, -1 }, |
Holger Hans Peter Freyther | cd25695 | 2012-12-07 15:04:07 +0100 | [diff] [blame] | 246 | }; |
| 247 | |
| 248 | static const struct mgcp_test retransmit[] = { |
| 249 | { "CRCX", CRCX, CRCX_RET }, |
| 250 | { "RQNT1", RQNT, RQNT1_RET }, |
| 251 | { "RQNT2", RQNT2, RQNT2_RET }, |
| 252 | { "MDCX3", MDCX3, MDCX3_RET }, |
Holger Hans Peter Freyther | 8fc6d08 | 2012-09-14 17:18:12 +0200 | [diff] [blame] | 253 | { "DLCX", DLCX, DLCX_RET }, |
Harald Welte | a7c9a92 | 2012-01-27 00:36:56 +0100 | [diff] [blame] | 254 | }; |
Harald Welte | 834f3f1 | 2012-01-27 00:00:44 +0100 | [diff] [blame] | 255 | |
| 256 | static struct msgb *create_msg(const char *str) |
Holger Hans Peter Freyther | f0bc075 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 257 | { |
| 258 | struct msgb *msg; |
| 259 | |
| 260 | msg = msgb_alloc_headroom(4096, 128, "MGCP msg"); |
Holger Hans Peter Freyther | 0f3fa90 | 2013-12-12 13:06:57 +0100 | [diff] [blame] | 261 | int len = sprintf((char *)msg->data, "%s", str); |
Holger Hans Peter Freyther | f0bc075 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 262 | msg->l2h = msgb_put(msg, len); |
| 263 | return msg; |
| 264 | } |
| 265 | |
Jacob Erlbeck | fe9896f | 2013-11-29 13:43:45 +0100 | [diff] [blame] | 266 | static int last_endpoint = -1; |
| 267 | |
| 268 | static int mgcp_test_policy_cb(struct mgcp_trunk_config *cfg, int endpoint, |
| 269 | int state, const char *transactio_id) |
| 270 | { |
| 271 | fprintf(stderr, "Policy CB got state %d on endpoint %d\n", |
| 272 | state, endpoint); |
| 273 | last_endpoint = endpoint; |
| 274 | return MGCP_POLICY_CONT; |
| 275 | } |
| 276 | |
Holger Hans Peter Freyther | 06ce839 | 2012-03-16 09:45:13 +0100 | [diff] [blame] | 277 | static void test_messages(void) |
Holger Hans Peter Freyther | f0bc075 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 278 | { |
Holger Hans Peter Freyther | 38484aa | 2012-01-06 15:04:43 +0100 | [diff] [blame] | 279 | struct mgcp_config *cfg; |
Jacob Erlbeck | fe9896f | 2013-11-29 13:43:45 +0100 | [diff] [blame] | 280 | struct mgcp_endpoint *endp; |
Harald Welte | a7c9a92 | 2012-01-27 00:36:56 +0100 | [diff] [blame] | 281 | int i; |
Holger Hans Peter Freyther | 38484aa | 2012-01-06 15:04:43 +0100 | [diff] [blame] | 282 | |
| 283 | cfg = mgcp_config_alloc(); |
Harald Welte | a7c9a92 | 2012-01-27 00:36:56 +0100 | [diff] [blame] | 284 | |
Holger Hans Peter Freyther | ab56ce1 | 2011-02-28 00:56:17 +0100 | [diff] [blame] | 285 | cfg->trunk.number_endpoints = 64; |
Holger Hans Peter Freyther | 49e170b | 2011-02-28 14:37:03 +0100 | [diff] [blame] | 286 | mgcp_endpoints_allocate(&cfg->trunk); |
| 287 | |
Jacob Erlbeck | fe9896f | 2013-11-29 13:43:45 +0100 | [diff] [blame] | 288 | cfg->policy_cb = mgcp_test_policy_cb; |
| 289 | |
Holger Hans Peter Freyther | 49e170b | 2011-02-28 14:37:03 +0100 | [diff] [blame] | 290 | mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1)); |
Holger Hans Peter Freyther | f0bc075 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 291 | |
Jacob Erlbeck | fe9896f | 2013-11-29 13:43:45 +0100 | [diff] [blame] | 292 | /* reset endpoints */ |
| 293 | for (i = 0; i < cfg->trunk.number_endpoints; i++) { |
| 294 | endp = &cfg->trunk.endpoints[i]; |
| 295 | endp->net_end.payload_type = PTYPE_NONE; |
Jacob Erlbeck | 07a25f7 | 2013-12-10 13:09:37 +0100 | [diff] [blame] | 296 | endp->net_end.packet_duration_ms = -1; |
Jacob Erlbeck | fe9896f | 2013-11-29 13:43:45 +0100 | [diff] [blame] | 297 | } |
| 298 | |
Harald Welte | a7c9a92 | 2012-01-27 00:36:56 +0100 | [diff] [blame] | 299 | for (i = 0; i < ARRAY_SIZE(tests); i++) { |
| 300 | const struct mgcp_test *t = &tests[i]; |
| 301 | struct msgb *inp; |
| 302 | struct msgb *msg; |
Holger Hans Peter Freyther | f0bc075 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 303 | |
Harald Welte | a7c9a92 | 2012-01-27 00:36:56 +0100 | [diff] [blame] | 304 | printf("Testing %s\n", t->name); |
| 305 | |
Jacob Erlbeck | fe9896f | 2013-11-29 13:43:45 +0100 | [diff] [blame] | 306 | last_endpoint = -1; |
| 307 | |
Harald Welte | a7c9a92 | 2012-01-27 00:36:56 +0100 | [diff] [blame] | 308 | inp = create_msg(t->req); |
| 309 | msg = mgcp_handle_message(cfg, inp); |
| 310 | msgb_free(inp); |
Holger Hans Peter Freyther | 0a6455c | 2012-03-16 09:53:49 +0100 | [diff] [blame] | 311 | if (!t->exp_resp) { |
| 312 | if (msg) |
| 313 | printf("%s failed '%s'\n", t->name, (char *) msg->data); |
| 314 | } else if (strcmp((char *) msg->data, t->exp_resp) != 0) |
Harald Welte | a7c9a92 | 2012-01-27 00:36:56 +0100 | [diff] [blame] | 315 | printf("%s failed '%s'\n", t->name, (char *) msg->data); |
| 316 | msgb_free(msg); |
Jacob Erlbeck | fe9896f | 2013-11-29 13:43:45 +0100 | [diff] [blame] | 317 | |
Jacob Erlbeck | 07a25f7 | 2013-12-10 13:09:37 +0100 | [diff] [blame] | 318 | if (last_endpoint != -1) { |
| 319 | endp = &cfg->trunk.endpoints[last_endpoint]; |
| 320 | |
| 321 | if (endp->net_end.packet_duration_ms != -1) |
| 322 | printf("Detected packet duration: %d\n", |
| 323 | endp->net_end.packet_duration_ms); |
| 324 | else |
| 325 | printf("Packet duration not set\n"); |
Jacob Erlbeck | 91cf743 | 2013-12-09 14:32:03 +0100 | [diff] [blame] | 326 | if (endp->local_options.pkt_period_min || |
| 327 | endp->local_options.pkt_period_max) |
| 328 | printf("Requested packetetization period: " |
| 329 | "%d-%d\n", |
| 330 | endp->local_options.pkt_period_min, |
| 331 | endp->local_options.pkt_period_max); |
| 332 | else |
| 333 | printf("Requested packetization period not set\n"); |
Jacob Erlbeck | 07a25f7 | 2013-12-10 13:09:37 +0100 | [diff] [blame] | 334 | |
| 335 | endp->net_end.packet_duration_ms = -1; |
| 336 | } |
| 337 | |
| 338 | |
Jacob Erlbeck | fe9896f | 2013-11-29 13:43:45 +0100 | [diff] [blame] | 339 | /* Check detected payload type */ |
| 340 | if (t->exp_net_ptype != PTYPE_IGNORE || |
| 341 | t->exp_bts_ptype != PTYPE_IGNORE) { |
| 342 | OSMO_ASSERT(last_endpoint != -1); |
| 343 | endp = &cfg->trunk.endpoints[last_endpoint]; |
| 344 | |
| 345 | fprintf(stderr, "endpoint %d: " |
| 346 | "payload type BTS %d (exp %d), NET %d (exp %d)\n", |
| 347 | last_endpoint, |
| 348 | endp->bts_end.payload_type, t->exp_bts_ptype, |
| 349 | endp->net_end.payload_type, t->exp_net_ptype); |
| 350 | |
| 351 | if (t->exp_bts_ptype != PTYPE_IGNORE) |
| 352 | OSMO_ASSERT(endp->bts_end.payload_type == |
| 353 | t->exp_bts_ptype); |
| 354 | if (t->exp_net_ptype != PTYPE_IGNORE) |
| 355 | OSMO_ASSERT(endp->net_end.payload_type == |
| 356 | t->exp_net_ptype); |
| 357 | |
| 358 | /* Reset them again for next test */ |
| 359 | endp->net_end.payload_type = PTYPE_NONE; |
| 360 | } |
Harald Welte | a7c9a92 | 2012-01-27 00:36:56 +0100 | [diff] [blame] | 361 | } |
Holger Hans Peter Freyther | f0bc075 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 362 | |
| 363 | talloc_free(cfg); |
| 364 | } |
| 365 | |
Holger Hans Peter Freyther | cd25695 | 2012-12-07 15:04:07 +0100 | [diff] [blame] | 366 | static void test_retransmission(void) |
| 367 | { |
| 368 | struct mgcp_config *cfg; |
| 369 | int i; |
| 370 | |
| 371 | cfg = mgcp_config_alloc(); |
| 372 | |
| 373 | cfg->trunk.number_endpoints = 64; |
| 374 | mgcp_endpoints_allocate(&cfg->trunk); |
| 375 | |
| 376 | mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1)); |
| 377 | |
Jacob Erlbeck | e91324d | 2013-12-10 13:09:37 +0100 | [diff] [blame] | 378 | /* reset endpoints */ |
| 379 | for (i = 0; i < cfg->trunk.number_endpoints; i++) { |
| 380 | struct mgcp_endpoint *endp; |
| 381 | endp = &cfg->trunk.endpoints[i]; |
| 382 | endp->bts_end.packet_duration_ms = 20; |
| 383 | } |
| 384 | |
Holger Hans Peter Freyther | cd25695 | 2012-12-07 15:04:07 +0100 | [diff] [blame] | 385 | for (i = 0; i < ARRAY_SIZE(retransmit); i++) { |
| 386 | const struct mgcp_test *t = &retransmit[i]; |
| 387 | struct msgb *inp; |
| 388 | struct msgb *msg; |
| 389 | |
| 390 | printf("Testing %s\n", t->name); |
| 391 | |
| 392 | inp = create_msg(t->req); |
| 393 | msg = mgcp_handle_message(cfg, inp); |
| 394 | msgb_free(inp); |
| 395 | if (strcmp((char *) msg->data, t->exp_resp) != 0) |
| 396 | printf("%s failed '%s'\n", t->name, (char *) msg->data); |
| 397 | msgb_free(msg); |
| 398 | |
| 399 | /* Retransmit... */ |
| 400 | printf("Re-transmitting %s\n", t->name); |
| 401 | inp = create_msg(t->req); |
| 402 | msg = mgcp_handle_message(cfg, inp); |
| 403 | msgb_free(inp); |
| 404 | if (strcmp((char *) msg->data, t->exp_resp) != 0) |
| 405 | printf("%s failed '%s'\n", t->name, (char *) msg->data); |
| 406 | msgb_free(msg); |
| 407 | } |
| 408 | |
| 409 | talloc_free(cfg); |
| 410 | } |
| 411 | |
| 412 | static int rqnt_cb(struct mgcp_endpoint *endp, char _tone) |
Holger Hans Peter Freyther | 46880c2 | 2012-11-29 12:54:22 +0100 | [diff] [blame] | 413 | { |
| 414 | ptrdiff_t tone = _tone; |
| 415 | endp->cfg->data = (void *) tone; |
| 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | static void test_rqnt_cb(void) |
| 420 | { |
| 421 | struct mgcp_config *cfg; |
| 422 | struct msgb *inp, *msg; |
| 423 | |
| 424 | cfg = mgcp_config_alloc(); |
| 425 | cfg->rqnt_cb = rqnt_cb; |
| 426 | |
| 427 | cfg->trunk.number_endpoints = 64; |
| 428 | mgcp_endpoints_allocate(&cfg->trunk); |
| 429 | |
| 430 | mgcp_endpoints_allocate(mgcp_trunk_alloc(cfg, 1)); |
| 431 | |
| 432 | inp = create_msg(CRCX); |
| 433 | msgb_free(mgcp_handle_message(cfg, inp)); |
| 434 | msgb_free(inp); |
| 435 | |
| 436 | /* send the RQNT and check for the CB */ |
| 437 | inp = create_msg(RQNT); |
| 438 | msg = mgcp_handle_message(cfg, inp); |
| 439 | if (strncmp((const char *) msg->l2h, "200", 3) != 0) { |
| 440 | printf("FAILED: message is not 200. '%s'\n", msg->l2h); |
| 441 | abort(); |
| 442 | } |
| 443 | |
| 444 | if (cfg->data != (void *) '9') { |
| 445 | printf("FAILED: callback not called: %p\n", cfg->data); |
| 446 | abort(); |
| 447 | } |
| 448 | |
| 449 | msgb_free(msg); |
| 450 | msgb_free(inp); |
| 451 | |
| 452 | inp = create_msg(DLCX); |
| 453 | msgb_free(mgcp_handle_message(cfg, inp)); |
| 454 | msgb_free(inp); |
| 455 | talloc_free(cfg); |
| 456 | } |
| 457 | |
Holger Hans Peter Freyther | faa6793 | 2012-10-22 18:09:35 +0200 | [diff] [blame] | 458 | struct pl_test { |
| 459 | int cycles; |
| 460 | uint16_t base_seq; |
| 461 | uint16_t max_seq; |
| 462 | uint32_t packets; |
| 463 | |
| 464 | uint32_t expected; |
| 465 | int loss; |
| 466 | }; |
| 467 | |
| 468 | static const struct pl_test pl_test_dat[] = { |
| 469 | /* basic.. just one package */ |
| 470 | { .cycles = 0, .base_seq = 0, .max_seq = 0, .packets = 1, .expected = 1, .loss = 0}, |
| 471 | /* some packages and a bit of loss */ |
| 472 | { .cycles = 0, .base_seq = 0, .max_seq = 100, .packets = 100, .expected = 101, .loss = 1}, |
| 473 | /* wrap around */ |
| 474 | { .cycles = 1<<16, .base_seq = 0xffff, .max_seq = 2, .packets = 4, .expected = 4, .loss = 0}, |
| 475 | /* min loss */ |
| 476 | { .cycles = 0, .base_seq = 0, .max_seq = 0, .packets = UINT_MAX, .expected = 1, .loss = INT_MIN }, |
| 477 | /* max loss, with wrap around on expected max */ |
| 478 | { .cycles = INT_MAX, .base_seq = 0, .max_seq = UINT16_MAX, .packets = 0, .expected = ((uint32_t)(INT_MAX) + UINT16_MAX + 1), .loss = INT_MAX }, |
| 479 | }; |
| 480 | |
| 481 | static void test_packet_loss_calc(void) |
| 482 | { |
| 483 | int i; |
| 484 | printf("Testing packet loss calculation.\n"); |
| 485 | |
| 486 | for (i = 0; i < ARRAY_SIZE(pl_test_dat); ++i) { |
| 487 | uint32_t expected; |
| 488 | int loss; |
| 489 | struct mgcp_rtp_state state; |
| 490 | struct mgcp_rtp_end rtp; |
| 491 | memset(&state, 0, sizeof(state)); |
| 492 | memset(&rtp, 0, sizeof(rtp)); |
| 493 | |
| 494 | state.initialized = 1; |
| 495 | state.base_seq = pl_test_dat[i].base_seq; |
Jacob Erlbeck | a2528da | 2013-11-25 12:53:28 +0100 | [diff] [blame] | 496 | state.out_stream.last_seq = pl_test_dat[i].max_seq; |
Holger Hans Peter Freyther | faa6793 | 2012-10-22 18:09:35 +0200 | [diff] [blame] | 497 | state.cycles = pl_test_dat[i].cycles; |
| 498 | |
| 499 | rtp.packets = pl_test_dat[i].packets; |
| 500 | mgcp_state_calc_loss(&state, &rtp, &expected, &loss); |
| 501 | |
| 502 | if (loss != pl_test_dat[i].loss || expected != pl_test_dat[i].expected) { |
| 503 | printf("FAIL: Wrong exp/loss at idx(%d) Loss(%d vs. %d) Exp(%u vs. %u)\n", |
| 504 | i, loss, pl_test_dat[i].loss, |
| 505 | expected, pl_test_dat[i].expected); |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | |
Holger Hans Peter Freyther | 931d698 | 2012-10-24 21:53:40 +0200 | [diff] [blame] | 510 | static void test_mgcp_stats(void) |
| 511 | { |
| 512 | printf("Testing stat parsing\n"); |
| 513 | |
| 514 | uint32_t bps, bos, pr, _or, jitter; |
| 515 | struct msgb *msg; |
| 516 | int loss; |
| 517 | int rc; |
| 518 | |
| 519 | msg = create_msg(DLCX_RET); |
| 520 | rc = mgcp_parse_stats(msg, &bps, &bos, &pr, &_or, &loss, &jitter); |
| 521 | printf("Parsing result: %d\n", rc); |
| 522 | if (bps != 0 || bos != 0 || pr != 0 || _or != 0 || loss != 0 || jitter != 0) |
| 523 | printf("FAIL: Parsing failed1.\n"); |
| 524 | msgb_free(msg); |
| 525 | |
| 526 | msg = create_msg("250 7 OK\r\nP: PS=10, OS=20, PR=30, OR=40, PL=-3, JI=40\r\n"); |
| 527 | rc = mgcp_parse_stats(msg, &bps, &bos, &pr, &_or, &loss, &jitter); |
| 528 | printf("Parsing result: %d\n", rc); |
| 529 | if (bps != 10 || bos != 20 || pr != 30 || _or != 40 || loss != -3 || jitter != 40) |
| 530 | printf("FAIL: Parsing failed2.\n"); |
| 531 | msgb_free(msg); |
| 532 | } |
| 533 | |
Jacob Erlbeck | 4516a8a | 2013-11-25 12:53:29 +0100 | [diff] [blame] | 534 | struct rtp_packet_info { |
| 535 | float txtime; |
| 536 | int len; |
| 537 | char *data; |
| 538 | }; |
| 539 | |
| 540 | struct rtp_packet_info test_rtp_packets1[] = { |
| 541 | /* RTP: SeqNo=0, TS=0 */ |
| 542 | {0.000000, 20, "\x80\x62\x00\x00\x00\x00\x00\x00\x11\x22\x33\x44" |
| 543 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 544 | /* RTP: SeqNo=1, TS=160 */ |
| 545 | {0.020000, 20, "\x80\x62\x00\x01\x00\x00\x00\xA0\x11\x22\x33\x44" |
| 546 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 547 | /* RTP: SeqNo=2, TS=320 */ |
| 548 | {0.040000, 20, "\x80\x62\x00\x02\x00\x00\x01\x40\x11\x22\x33\x44" |
| 549 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 550 | /* Repeat RTP timestamp: */ |
| 551 | /* RTP: SeqNo=3, TS=320 */ |
| 552 | {0.060000, 20, "\x80\x62\x00\x03\x00\x00\x01\x40\x11\x22\x33\x44" |
| 553 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 554 | /* RTP: SeqNo=4, TS=480 */ |
| 555 | {0.080000, 20, "\x80\x62\x00\x04\x00\x00\x01\xE0\x11\x22\x33\x44" |
| 556 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 557 | /* RTP: SeqNo=5, TS=640 */ |
| 558 | {0.100000, 20, "\x80\x62\x00\x05\x00\x00\x02\x80\x11\x22\x33\x44" |
| 559 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 560 | /* Double skip RTP timestamp (delta = 2*160): */ |
| 561 | /* RTP: SeqNo=6, TS=960 */ |
| 562 | {0.120000, 20, "\x80\x62\x00\x06\x00\x00\x03\xC0\x11\x22\x33\x44" |
| 563 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 564 | /* RTP: SeqNo=7, TS=1120 */ |
| 565 | {0.140000, 20, "\x80\x62\x00\x07\x00\x00\x04\x60\x11\x22\x33\x44" |
| 566 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 567 | /* RTP: SeqNo=8, TS=1280 */ |
| 568 | {0.160000, 20, "\x80\x62\x00\x08\x00\x00\x05\x00\x11\x22\x33\x44" |
| 569 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 570 | /* Non 20ms RTP timestamp (delta = 120): */ |
| 571 | /* RTP: SeqNo=9, TS=1400 */ |
| 572 | {0.180000, 20, "\x80\x62\x00\x09\x00\x00\x05\x78\x11\x22\x33\x44" |
| 573 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 574 | /* RTP: SeqNo=10, TS=1560 */ |
| 575 | {0.200000, 20, "\x80\x62\x00\x0A\x00\x00\x06\x18\x11\x22\x33\x44" |
| 576 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 577 | /* RTP: SeqNo=11, TS=1720 */ |
| 578 | {0.220000, 20, "\x80\x62\x00\x0B\x00\x00\x06\xB8\x11\x22\x33\x44" |
| 579 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 580 | /* SSRC changed to 0x10203040, RTP timestamp jump */ |
| 581 | /* RTP: SeqNo=12, TS=34688 */ |
| 582 | {0.240000, 20, "\x80\x62\x00\x0C\x00\x00\x87\x80\x10\x20\x30\x40" |
| 583 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 584 | /* RTP: SeqNo=13, TS=34848 */ |
| 585 | {0.260000, 20, "\x80\x62\x00\x0D\x00\x00\x88\x20\x10\x20\x30\x40" |
| 586 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 587 | /* RTP: SeqNo=14, TS=35008 */ |
| 588 | {0.280000, 20, "\x80\x62\x00\x0E\x00\x00\x88\xC0\x10\x20\x30\x40" |
| 589 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Jacob Erlbeck | eb19f55 | 2013-12-03 12:48:07 +0100 | [diff] [blame] | 590 | /* Non 20ms RTP timestamp (delta = 120): */ |
| 591 | /* RTP: SeqNo=15, TS=35128 */ |
| 592 | {0.300000, 20, "\x80\x62\x00\x0F\x00\x00\x89\x38\x10\x20\x30\x40" |
| 593 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 594 | /* RTP: SeqNo=16, TS=35288 */ |
| 595 | {0.320000, 20, "\x80\x62\x00\x10\x00\x00\x89\xD8\x10\x20\x30\x40" |
| 596 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 597 | /* RTP: SeqNo=17, TS=35448 */ |
| 598 | {0.340000, 20, "\x80\x62\x00\x11\x00\x00\x8A\x78\x10\x20\x30\x40" |
| 599 | "\x01\x23\x45\x67\x8A\xAB\xCD\xEF"}, |
| 600 | /* SeqNo increment by 2, RTP timestamp delta = 320: */ |
| 601 | /* RTP: SeqNo=19, TS=35768 */ |
| 602 | {0.360000, 20, "\x80\x62\x00\x13\x00\x00\x8B\xB8\x10\x20\x30\x40" |
| 603 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 604 | /* RTP: SeqNo=20, TS=35928 */ |
| 605 | {0.380000, 20, "\x80\x62\x00\x14\x00\x00\x8C\x58\x10\x20\x30\x40" |
| 606 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 607 | /* RTP: SeqNo=21, TS=36088 */ |
Jacob Erlbeck | 1e9b28b | 2013-12-18 12:54:49 +0100 | [diff] [blame] | 608 | {0.380000, 20, "\x80\x62\x00\x15\x00\x00\x8C\xF8\x10\x20\x30\x40" |
| 609 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 610 | /* Repeat last packet */ |
| 611 | /* RTP: SeqNo=21, TS=36088 */ |
| 612 | {0.400000, 20, "\x80\x62\x00\x15\x00\x00\x8C\xF8\x10\x20\x30\x40" |
| 613 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 614 | /* RTP: SeqNo=22, TS=36248 */ |
| 615 | {0.420000, 20, "\x80\x62\x00\x16\x00\x00\x8D\x98\x10\x20\x30\x40" |
| 616 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 617 | /* RTP: SeqNo=23, TS=36408 */ |
| 618 | {0.440000, 20, "\x80\x62\x00\x17\x00\x00\x8E\x38\x10\x20\x30\x40" |
| 619 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 620 | /* Don't increment SeqNo but increment timestamp by 160 */ |
| 621 | /* RTP: SeqNo=23, TS=36568 */ |
| 622 | {0.460000, 20, "\x80\x62\x00\x17\x00\x00\x8E\xD8\x10\x20\x30\x40" |
| 623 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 624 | /* RTP: SeqNo=24, TS=36728 */ |
| 625 | {0.480000, 20, "\x80\x62\x00\x18\x00\x00\x8F\x78\x10\x20\x30\x40" |
| 626 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
| 627 | /* RTP: SeqNo=25, TS=36888 */ |
| 628 | {0.500000, 20, "\x80\x62\x00\x19\x00\x00\x90\x18\x10\x20\x30\x40" |
Jacob Erlbeck | eb19f55 | 2013-12-03 12:48:07 +0100 | [diff] [blame] | 629 | "\x01\x23\x45\x67\x89\xAB\xCD\xEF"}, |
Jacob Erlbeck | 4516a8a | 2013-11-25 12:53:29 +0100 | [diff] [blame] | 630 | }; |
| 631 | |
| 632 | void mgcp_patch_and_count(struct mgcp_endpoint *endp, struct mgcp_rtp_state *state, |
| 633 | struct mgcp_rtp_end *rtp_end, struct sockaddr_in *addr, |
| 634 | char *data, int len); |
| 635 | |
Jacob Erlbeck | eb19f55 | 2013-12-03 12:48:07 +0100 | [diff] [blame] | 636 | static void test_packet_error_detection(int patch_ssrc, int patch_ts) |
Jacob Erlbeck | 4516a8a | 2013-11-25 12:53:29 +0100 | [diff] [blame] | 637 | { |
| 638 | int i; |
| 639 | |
| 640 | struct mgcp_trunk_config trunk; |
| 641 | struct mgcp_endpoint endp; |
| 642 | struct mgcp_rtp_state state; |
Jacob Erlbeck | ac9f6ce | 2013-11-25 15:23:35 +0100 | [diff] [blame] | 643 | struct mgcp_rtp_end *rtp = &endp.net_end; |
Jacob Erlbeck | 4516a8a | 2013-11-25 12:53:29 +0100 | [diff] [blame] | 644 | struct sockaddr_in addr = {0}; |
| 645 | char buffer[4096]; |
Jacob Erlbeck | eb19f55 | 2013-12-03 12:48:07 +0100 | [diff] [blame] | 646 | uint32_t last_ssrc = 0; |
Jacob Erlbeck | 888fec6 | 2013-12-18 12:54:50 +0100 | [diff] [blame] | 647 | uint32_t last_timestamp = 0; |
| 648 | uint32_t last_seqno = 0; |
| 649 | int last_in_ts_err_cnt = 0; |
| 650 | int last_out_ts_err_cnt = 0; |
Jacob Erlbeck | 4516a8a | 2013-11-25 12:53:29 +0100 | [diff] [blame] | 651 | |
Jacob Erlbeck | eb19f55 | 2013-12-03 12:48:07 +0100 | [diff] [blame] | 652 | printf("Testing packet error detection%s%s.\n", |
| 653 | patch_ssrc ? ", patch SSRC" : "", |
| 654 | patch_ts ? ", patch timestamps" : ""); |
Jacob Erlbeck | 4516a8a | 2013-11-25 12:53:29 +0100 | [diff] [blame] | 655 | |
| 656 | memset(&trunk, 0, sizeof(trunk)); |
| 657 | memset(&endp, 0, sizeof(endp)); |
| 658 | memset(&state, 0, sizeof(state)); |
Jacob Erlbeck | 4516a8a | 2013-11-25 12:53:29 +0100 | [diff] [blame] | 659 | |
| 660 | trunk.number_endpoints = 1; |
| 661 | trunk.endpoints = &endp; |
Jacob Erlbeck | e5546cd | 2013-12-03 14:43:34 +0100 | [diff] [blame] | 662 | trunk.force_constant_ssrc = patch_ssrc; |
Jacob Erlbeck | f12c849 | 2013-12-18 12:54:51 +0100 | [diff] [blame] | 663 | trunk.force_aligned_timing = patch_ts; |
Jacob Erlbeck | e5546cd | 2013-12-03 14:43:34 +0100 | [diff] [blame] | 664 | |
Jacob Erlbeck | 4516a8a | 2013-11-25 12:53:29 +0100 | [diff] [blame] | 665 | endp.tcfg = &trunk; |
| 666 | |
Jacob Erlbeck | ac9f6ce | 2013-11-25 15:23:35 +0100 | [diff] [blame] | 667 | /* This doesn't free endp but resets/frees all fields of the structure |
| 668 | * and invokes mgcp_rtp_end_reset() for each mgcp_rtp_end. OTOH, it |
| 669 | * expects valid pointer fields (either NULL or talloc'ed), so the |
| 670 | * memset is still needed. It also requires that endp.tcfg and |
| 671 | * trunk.endpoints are set up properly. */ |
| 672 | mgcp_free_endp(&endp); |
| 673 | |
| 674 | rtp->payload_type = 98; |
Jacob Erlbeck | ac9f6ce | 2013-11-25 15:23:35 +0100 | [diff] [blame] | 675 | |
Jacob Erlbeck | 4516a8a | 2013-11-25 12:53:29 +0100 | [diff] [blame] | 676 | for (i = 0; i < ARRAY_SIZE(test_rtp_packets1); ++i) { |
| 677 | struct rtp_packet_info *info = test_rtp_packets1 + i; |
| 678 | |
| 679 | OSMO_ASSERT(info->len <= sizeof(buffer)); |
| 680 | OSMO_ASSERT(info->len >= 0); |
| 681 | memmove(buffer, info->data, info->len); |
| 682 | |
Jacob Erlbeck | e5546cd | 2013-12-03 14:43:34 +0100 | [diff] [blame] | 683 | mgcp_rtp_end_config(&endp, 1, rtp); |
| 684 | |
Jacob Erlbeck | ac9f6ce | 2013-11-25 15:23:35 +0100 | [diff] [blame] | 685 | mgcp_patch_and_count(&endp, &state, rtp, &addr, |
Jacob Erlbeck | 4516a8a | 2013-11-25 12:53:29 +0100 | [diff] [blame] | 686 | buffer, info->len); |
| 687 | |
Jacob Erlbeck | eb19f55 | 2013-12-03 12:48:07 +0100 | [diff] [blame] | 688 | if (state.out_stream.ssrc != last_ssrc) { |
| 689 | printf("Output SSRC changed to %08x\n", |
Jacob Erlbeck | 866a76d | 2013-12-03 15:47:04 +0100 | [diff] [blame] | 690 | state.out_stream.ssrc); |
Jacob Erlbeck | eb19f55 | 2013-12-03 12:48:07 +0100 | [diff] [blame] | 691 | last_ssrc = state.out_stream.ssrc; |
| 692 | } |
| 693 | |
Jacob Erlbeck | 888fec6 | 2013-12-18 12:54:50 +0100 | [diff] [blame] | 694 | printf("In TS: %d, dTS: %d, Seq: %d\n", |
| 695 | state.in_stream.last_timestamp, |
| 696 | state.in_stream.last_tsdelta, |
| 697 | state.in_stream.last_seq); |
| 698 | |
| 699 | printf("Out TS change: %d, dTS: %d, Seq change: %d, " |
| 700 | "TS Err change: in %+d, out %+d\n", |
| 701 | state.out_stream.last_timestamp - last_timestamp, |
Jacob Erlbeck | 4516a8a | 2013-11-25 12:53:29 +0100 | [diff] [blame] | 702 | state.out_stream.last_tsdelta, |
Jacob Erlbeck | 888fec6 | 2013-12-18 12:54:50 +0100 | [diff] [blame] | 703 | state.out_stream.last_seq - last_seqno, |
| 704 | state.in_stream.err_ts_counter - last_in_ts_err_cnt, |
| 705 | state.out_stream.err_ts_counter - last_out_ts_err_cnt); |
| 706 | |
| 707 | last_in_ts_err_cnt = state.in_stream.err_ts_counter; |
| 708 | last_out_ts_err_cnt = state.out_stream.err_ts_counter; |
| 709 | last_timestamp = state.out_stream.last_timestamp; |
| 710 | last_seqno = state.out_stream.last_seq; |
Jacob Erlbeck | 4516a8a | 2013-11-25 12:53:29 +0100 | [diff] [blame] | 711 | } |
| 712 | } |
| 713 | |
Holger Hans Peter Freyther | f0bc075 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 714 | int main(int argc, char **argv) |
| 715 | { |
Holger Hans Peter Freyther | 2d59cc6 | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 716 | osmo_init_logging(&log_info); |
Holger Hans Peter Freyther | f0bc075 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 717 | |
Jacob Erlbeck | e7060c4 | 2013-11-29 13:43:44 +0100 | [diff] [blame] | 718 | test_strline(); |
Holger Hans Peter Freyther | 06ce839 | 2012-03-16 09:45:13 +0100 | [diff] [blame] | 719 | test_messages(); |
Holger Hans Peter Freyther | cd25695 | 2012-12-07 15:04:07 +0100 | [diff] [blame] | 720 | test_retransmission(); |
Holger Hans Peter Freyther | faa6793 | 2012-10-22 18:09:35 +0200 | [diff] [blame] | 721 | test_packet_loss_calc(); |
Holger Hans Peter Freyther | 46880c2 | 2012-11-29 12:54:22 +0100 | [diff] [blame] | 722 | test_rqnt_cb(); |
Holger Hans Peter Freyther | 931d698 | 2012-10-24 21:53:40 +0200 | [diff] [blame] | 723 | test_mgcp_stats(); |
Jacob Erlbeck | eb19f55 | 2013-12-03 12:48:07 +0100 | [diff] [blame] | 724 | test_packet_error_detection(1, 0); |
| 725 | test_packet_error_detection(0, 0); |
| 726 | test_packet_error_detection(0, 1); |
| 727 | test_packet_error_detection(1, 1); |
Holger Hans Peter Freyther | 38484aa | 2012-01-06 15:04:43 +0100 | [diff] [blame] | 728 | |
| 729 | printf("Done\n"); |
| 730 | return EXIT_SUCCESS; |
Holger Hans Peter Freyther | f0bc075 | 2011-01-06 19:32:52 +0100 | [diff] [blame] | 731 | } |