blob: 2b542ddf8137a69ccd2ac1484be5b2f622d4476a [file] [log] [blame]
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001/* Test the GTP hub */
2
3/* (C) 2015 by sysmocom s.f.m.c. GmbH
4 * All Rights Reserved
5 *
6 * Author: Neels Hofmeyr <nhofmeyr@sysmcom.de>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#include <stdio.h>
24#include <string.h>
25#include <limits.h>
26#include <unistd.h>
27
28#include <osmocom/core/utils.h>
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +020029#include <osmocom/core/application.h>
30
31#include <openbsc/debug.h>
32
33#include <openbsc/gtphub.h>
34#include <gtp.h>
35#include <gtpie.h>
36
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +010037#define ZERO_STRUCT(struct_pointer) memset(struct_pointer, '\0', \
38 sizeof(*(struct_pointer)))
Neels Hofmeyrc2275942015-11-10 22:07:04 +010039
40#define LVL2_ASSERT(exp) LVL2_ASSERT_R(exp, return 0)
41#define LVL2_ASSERT_R(exp, ret) \
42 if (!(exp)) { \
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +010043 fprintf(stderr, "LVL2 Assert failed %s %s:%d\n", #exp, \
44 __FILE__, __LINE__); \
Neels Hofmeyrc2275942015-11-10 22:07:04 +010045 osmo_generate_backtrace(); \
46 ret; \
47 }
48
Neels Hofmeyre921e322015-11-11 00:45:50 +010049/* Convenience makro, note: only within this C file. */
50#define LOG(label) \
Neels Hofmeyre54cd152015-11-24 13:31:06 +010051 { fprintf(stderr, "\n" label "\n"); \
Neels Hofmeyre921e322015-11-11 00:45:50 +010052 printf(label "\n"); }
53
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +020054void gtphub_init(struct gtphub *hub);
Neels Hofmeyr20bd6bf2015-11-20 00:08:28 +010055void gtphub_free(struct gtphub *hub);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +020056
57void *osmo_gtphub_ctx;
58
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +020059static void nr_mapping_free(struct expiring_item *e)
60{
61 struct nr_mapping *m = container_of(e, struct nr_mapping,
62 expiry_entry);
63 nr_mapping_del(m);
64 talloc_free(m);
65}
66
67static struct nr_mapping *nr_mapping_alloc(void)
68{
69 struct nr_mapping *m;
70 m = talloc(osmo_gtphub_ctx, struct nr_mapping);
71 nr_mapping_init(m);
72 m->expiry_entry.del_cb = nr_mapping_free;
73 return m;
74}
75
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +010076static struct nr_mapping *nr_map_have(struct nr_map *map, void *origin,
77 nr_t orig, time_t now)
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +020078{
79 struct nr_mapping *mapping;
80
81 mapping = nr_map_get(map, origin, orig);
82 if (!mapping) {
83 mapping = nr_mapping_alloc();
84 mapping->origin = origin;
85 mapping->orig = orig;
86 nr_map_add(map, mapping, now);
87 }
88
89 return mapping;
90}
91
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +010092static nr_t nr_map_verify(const struct nr_map *map, void *origin, nr_t orig,
93 nr_t expect_repl)
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +020094{
95 struct nr_mapping *m;
96 m = nr_map_get(map, origin, orig);
97
98 if (!m) {
99 printf("mapping not found for %p %d\n", origin, orig);
100 return 0;
101 }
102
103 if (m->repl != expect_repl) {
104 printf("mapping found, but nr mismatches: expect %d, got %d\n",
105 (int)expect_repl, (int)m->repl);
106 return 0;
107 }
108
109 return 1;
110}
111
112static int nr_map_verify_inv(const struct nr_map *map, nr_t repl,
113 void *expect_origin, nr_t expect_orig)
114{
115 struct nr_mapping *m;
116 m = nr_map_get_inv(map, repl);
117 if (!m) {
118 printf("mapping not found for %d\n", (int)repl);
119 return 0;
120 }
121
122 if (m->origin != expect_origin) {
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100123 printf("mapping found, but origin mismatches:"
124 " expect %p, got %p\n",
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200125 expect_origin, m->origin);
126 return 0;
127 }
128
129 if (m->orig != expect_orig) {
130 printf("mapping found, but nr mismatches: expect %d, got %d\n",
131 (int)expect_orig, (int)m->orig);
132 return 0;
133 }
134
135 return 1;
136}
137
138
139static void test_nr_map_basic(void)
140{
141 struct nr_pool _pool;
142 struct nr_pool *pool = &_pool;
143 struct nr_map _map;
144 struct nr_map *map = &_map;
145
Neels Hofmeyre2ed8e62015-11-17 14:30:37 +0100146 nr_pool_init(pool, 1, 1000);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200147 nr_map_init(map, pool, NULL);
148
149 OSMO_ASSERT(llist_empty(&map->mappings));
150
151#define TEST_N_HALF 100
152#define TEST_N (2*TEST_N_HALF)
153#define TEST_I 123
154 uint32_t i, check_i;
155 uint32_t m[TEST_N];
156 struct nr_mapping *mapping;
157
158 /* create half of TEST_N mappings from one origin */
159 void *origin1 = (void*)0x1234;
160 for (i = 0; i < TEST_N_HALF; i++) {
161 nr_t orig = TEST_I + i;
162 mapping = nr_map_have(map, origin1, orig, 0);
163 m[i] = mapping->repl;
164 OSMO_ASSERT(m[i] != 0);
Neels Hofmeyrb7f41d52017-01-11 00:43:26 +0100165 OSMO_ASSERT(llist_count(&map->mappings) == (i+1));
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200166 for (check_i = 0; check_i < i; check_i++)
167 OSMO_ASSERT(m[check_i] != m[i]);
168 }
Neels Hofmeyrb7f41d52017-01-11 00:43:26 +0100169 OSMO_ASSERT(llist_count(&map->mappings) == TEST_N_HALF);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200170
171 /* create another TEST_N mappings with the same original numbers, but
172 * from a different origin */
173 void *origin2 = (void*)0x5678;
174 for (i = 0; i < TEST_N_HALF; i++) {
175 int i2 = TEST_N_HALF + i;
176 nr_t orig = TEST_I + i;
177 mapping = nr_map_have(map, origin2, orig, 0);
178 m[i2] = mapping->repl;
179 OSMO_ASSERT(m[i2] != 0);
Neels Hofmeyrb7f41d52017-01-11 00:43:26 +0100180 OSMO_ASSERT(llist_count(&map->mappings) == (i2+1));
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200181 for (check_i = 0; check_i < i2; check_i++)
182 OSMO_ASSERT(m[check_i] != m[i2]);
183 }
Neels Hofmeyrb7f41d52017-01-11 00:43:26 +0100184 OSMO_ASSERT(llist_count(&map->mappings) == TEST_N);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200185
186 /* verify mappings */
187 for (i = 0; i < TEST_N_HALF; i++) {
188 nr_t orig = TEST_I + i;
189 {
190 OSMO_ASSERT(nr_map_verify(map, origin1, orig, m[i]));
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100191 OSMO_ASSERT(nr_map_verify_inv(map, m[i], origin1,
192 orig));
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200193 }
194 {
195 int i2 = TEST_N_HALF + i;
196 OSMO_ASSERT(nr_map_verify(map, origin2, orig, m[i2]));
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100197 OSMO_ASSERT(nr_map_verify_inv(map, m[i2], origin2,
198 orig));
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200199 }
200 }
201
202 /* remove all mappings */
203 for (i = 0; i < TEST_N_HALF; i++) {
Neels Hofmeyrb7f41d52017-01-11 00:43:26 +0100204 OSMO_ASSERT(llist_count(&map->mappings) == (TEST_N - 2*i));
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200205
206 nr_t orig = TEST_I + i;
207 nr_mapping_del(nr_map_get(map, origin1, orig));
208 nr_mapping_del(nr_map_get(map, origin2, orig));
209 }
210 OSMO_ASSERT(llist_empty(&map->mappings));
211#undef TEST_N
212#undef TEST_I
213}
214
215static int nr_map_is(struct nr_map *map, const char *str)
216{
217 static char buf[4096];
218 char *pos = buf;
219 size_t len = sizeof(buf);
220 struct nr_mapping *m;
221 llist_for_each_entry(m, &map->mappings, entry) {
Neels Hofmeyr334af5d2015-11-17 14:24:46 +0100222 size_t wrote = snprintf(pos, len, "(%u->%u@%d), ",
223 m->orig,
224 m->repl,
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200225 (int)m->expiry_entry.expiry);
226 OSMO_ASSERT(wrote < len);
227 pos += wrote;
228 len -= wrote;
229 }
230 *pos = '\0';
231
232 if (strncmp(buf, str, sizeof(buf)) != 0) {
233 printf("FAILURE: nr_map_is() mismatches expected value:\n"
234 "expected: \"%s\"\n"
235 "is: \"%s\"\n",
236 str, buf);
237 return 0;
238 }
239 return 1;
240}
241
Neels Hofmeyre2ed8e62015-11-17 14:30:37 +0100242static int test_nr_map_wrap_with(nr_t nr_min, nr_t nr_max, nr_t repl_last,
243 nr_t orig_start, int orig_n,
244 const char *expect)
245{
246 struct nr_pool _pool;
247 struct nr_pool *pool = &_pool;
248 struct nr_map _map;
249 struct nr_map *map = &_map;
250
251 nr_pool_init(pool, nr_min, nr_max);
252 nr_map_init(map, pool, NULL);
253
254 pool->last_nr = repl_last;
255
256 void *origin = (void*)0x1234;
257
258 int i;
259 for (i = 0; i < orig_n; i++)
260 LVL2_ASSERT(nr_map_have(map, origin, orig_start + i, 0));
261
262 LVL2_ASSERT(nr_map_is(map, expect));
263
264 nr_map_clear(map);
265 return 1;
266}
267
268static void test_nr_map_wrap(void)
269{
270 OSMO_ASSERT(test_nr_map_wrap_with(
271 0, UINT_MAX, UINT_MAX - 2,
272 1, 5,
273 "(1->4294967294@0), "
274 "(2->4294967295@0), "
275 "(3->0@0), "
276 "(4->1@0), "
277 "(5->2@0), "
278 ));
279 OSMO_ASSERT(test_nr_map_wrap_with(
280 5, 10, 8,
281 1, 5,
282 "(1->9@0), (2->10@0), (3->5@0), (4->6@0), (5->7@0), "
283 ));
284}
285
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200286static void test_expiry(void)
287{
288 struct expiry expiry;
289 struct nr_pool pool;
290 struct nr_map map;
291 int i;
292
293 expiry_init(&expiry, 30);
Neels Hofmeyre2ed8e62015-11-17 14:30:37 +0100294 nr_pool_init(&pool, 1, 1000);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200295 nr_map_init(&map, &pool, &expiry);
296 OSMO_ASSERT(nr_map_is(&map, ""));
297
298 /* tick on empty map */
299 OSMO_ASSERT(expiry_tick(&expiry, 10000) == 0);
300 OSMO_ASSERT(nr_map_is(&map, ""));
301
302#define MAP1 \
303 "(10->1@10040), " \
304 ""
305
306#define MAP2 \
307 "(20->2@10050), " \
308 "(21->3@10051), " \
309 "(22->4@10052), " \
310 "(23->5@10053), " \
311 "(24->6@10054), " \
312 "(25->7@10055), " \
313 "(26->8@10056), " \
314 "(27->9@10057), " \
315 ""
316
317#define MAP3 \
318 "(420->10@10072), " \
319 "(421->11@10072), " \
320 "(422->12@10072), " \
321 "(423->13@10072), " \
322 "(424->14@10072), " \
323 "(425->15@10072), " \
324 "(426->16@10072), " \
325 "(427->17@10072), " \
326 ""
327
328 /* add mapping at time 10010. */
329 nr_map_have(&map, 0, 10, 10010);
330 OSMO_ASSERT(nr_map_is(&map, MAP1));
331
332 /* tick on unexpired item. */
333 OSMO_ASSERT(expiry_tick(&expiry, 10010) == 0);
334 OSMO_ASSERT(expiry_tick(&expiry, 10011) == 0);
335 OSMO_ASSERT(nr_map_is(&map, MAP1));
336
337 /* Spread mappings at 10020, 10021, ... 10027. */
338 for (i = 0; i < 8; i++)
339 nr_map_have(&map, 0, 20 + i, 10020 + i);
340 OSMO_ASSERT(nr_map_is(&map, MAP1 MAP2));
341
342 /* tick on unexpired items. */
343 OSMO_ASSERT(expiry_tick(&expiry, 10030) == 0);
344 OSMO_ASSERT(expiry_tick(&expiry, 10039) == 0);
345 OSMO_ASSERT(nr_map_is(&map, MAP1 MAP2));
346
347 /* expire the first item (from 10010). */
348 OSMO_ASSERT(expiry_tick(&expiry, 10010 + 30) == 1);
349 OSMO_ASSERT(nr_map_is(&map, MAP2));
350
351 /* again nothing to expire */
352 OSMO_ASSERT(expiry_tick(&expiry, 10041) == 0);
353 OSMO_ASSERT(nr_map_is(&map, MAP2));
354
355 /* Mappings all at the same time. */
356 for (i = 0; i < 8; i++)
357 nr_map_have(&map, 0, 420 + i, 10042);
358 OSMO_ASSERT(nr_map_is(&map, MAP2 MAP3));
359
360 /* Eight to expire, were added further above to be chronologically
361 * correct, at 10020..10027. */
362 OSMO_ASSERT(expiry_tick(&expiry, 10027 + 30) == 8);
363 OSMO_ASSERT(nr_map_is(&map, MAP3));
364
365 /* again nothing to expire */
366 OSMO_ASSERT(expiry_tick(&expiry, 10027 + 30) == 0);
367 OSMO_ASSERT(nr_map_is(&map, MAP3));
368
369 /* Eight to expire, from 10042. Now at 10042 + 30: */
370 OSMO_ASSERT(expiry_tick(&expiry, 10042 + 30) == 8);
371 OSMO_ASSERT(nr_map_is(&map, ""));
372
373#undef MAP1
374#undef MAP2
375#undef MAP3
376}
377
Harald Welted3fa84d2016-04-20 17:50:17 +0200378char resolve_ggsn_got_imsi[GSM23003_IMSI_MAX_DIGITS+1];
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100379char resolve_ggsn_got_ni[GSM_APN_LENGTH];
380
381struct osmo_sockaddr resolved_ggsn_addr;
382static int resolve_to_ggsn(const char *addr, uint16_t port)
383{
384 LVL2_ASSERT(osmo_sockaddr_init_udp(&resolved_ggsn_addr,
385 addr, port)
386 == 0);
387 return 1;
388}
389
Neels Hofmeyre921e322015-11-11 00:45:50 +0100390struct osmo_sockaddr resolved_sgsn_addr;
391static int resolve_to_sgsn(const char *addr, uint16_t port)
392{
393 LVL2_ASSERT(osmo_sockaddr_init_udp(&resolved_sgsn_addr,
394 addr, port)
395 == 0);
396 return 1;
397}
398
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100399struct osmo_sockaddr sgsn_sender;
400static int send_from_sgsn(const char *addr, uint16_t port)
401{
402 LVL2_ASSERT(osmo_sockaddr_init_udp(&sgsn_sender,
403 addr, port)
404 == 0);
405 return 1;
406}
407
Neels Hofmeyre921e322015-11-11 00:45:50 +0100408struct osmo_sockaddr ggsn_sender;
409static int send_from_ggsn(const char *addr, uint16_t port)
410{
411 LVL2_ASSERT(osmo_sockaddr_init_udp(&ggsn_sender,
412 addr, port)
413 == 0);
414 return 1;
415}
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200416
417
418/* override, requires '-Wl,--wrap=gtphub_resolve_ggsn_addr' */
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100419struct gtphub_peer_port *__real_gtphub_resolve_ggsn_addr(struct gtphub *hub,
420 const char *imsi_str,
421 const char *apn_ni_str);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200422
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100423struct gtphub_peer_port *__wrap_gtphub_resolve_ggsn_addr(struct gtphub *hub,
424 const char *imsi_str,
425 const char *apn_ni_str)
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200426{
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100427 struct gsn_addr resolved_gsna;
428 uint16_t resolved_port;
429
430 OSMO_ASSERT(gsn_addr_from_sockaddr(&resolved_gsna, &resolved_port,
431 &resolved_ggsn_addr) == 0);
432
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100433 struct gtphub_peer_port *pp;
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100434 pp = gtphub_port_have(hub, &hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL],
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100435 &resolved_gsna, resolved_port);
Neels Hofmeyre921e322015-11-11 00:45:50 +0100436 printf("- __wrap_gtphub_resolve_ggsn_addr():\n"
437 " returning GGSN addr from imsi %s ni %s: %s\n",
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100438 imsi_str, apn_ni_str, gtphub_port_str(pp));
439
440 if (imsi_str) {
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100441 strncpy(resolve_ggsn_got_imsi, imsi_str,
442 sizeof(resolve_ggsn_got_imsi));
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100443 resolve_ggsn_got_imsi[sizeof(resolve_ggsn_got_imsi) - 1] = '\0';
444 }
445 else
446 strcpy(resolve_ggsn_got_imsi, "(null)");
447
448 if (apn_ni_str) {
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100449 strncpy(resolve_ggsn_got_ni, apn_ni_str,
450 sizeof(resolve_ggsn_got_ni));
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100451 resolve_ggsn_got_ni[sizeof(resolve_ggsn_got_ni) - 1] = '\0';
452 }
453 else
454 strcpy(resolve_ggsn_got_ni, "(null)");
455
456 return pp;
457}
458
459#define was_resolved_for(IMSI,NI) _was_resolved_for(IMSI, NI, __FILE__, __LINE__)
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100460static int _was_resolved_for(const char *imsi, const char *ni, const char
461 *file, int line)
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100462{
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100463 int cmp0 = strncmp(imsi, resolve_ggsn_got_imsi,
464 sizeof(resolve_ggsn_got_imsi));
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100465
466 if (cmp0 != 0) {
467 printf("\n%s:%d: was_resolved_for(): MISMATCH for IMSI\n"
468 " expecting: '%s'\n"
469 " got: '%s'\n\n",
470 file,
471 line,
472 imsi, resolve_ggsn_got_imsi);
473 }
474
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100475 int cmp1 = strncmp(ni, resolve_ggsn_got_ni,
476 sizeof(resolve_ggsn_got_ni));
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100477 if (cmp1 != 0) {
478 printf("\n%s:%d: was_resolved_for(): MISMATCH for NI\n"
479 " expecting: '%s'\n"
480 " got: '%s'\n\n",
481 file,
482 line,
483 ni, resolve_ggsn_got_ni);
484 }
485
486 return (cmp0 == 0) && (cmp1 == 0);
487}
488
489/* override, requires '-Wl,--wrap=gtphub_ares_init' */
490int __real_gtphub_ares_init(struct gtphub *hub);
491
492int __wrap_gtphub_ares_init(struct gtphub *hub)
493{
494 /* Do nothing. */
495 return 0;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200496}
497
Neels Hofmeyr996ec1d2015-12-02 15:43:10 +0100498/* override, requires '-Wl,--wrap=gtphub_write' */
499int __real_gtphub_write(const struct osmo_fd *to,
500 const struct osmo_sockaddr *to_addr,
501 const uint8_t *buf, size_t buf_len);
502
503int __wrap_gtphub_write(const struct osmo_fd *to,
504 const struct osmo_sockaddr *to_addr,
505 const uint8_t *buf, size_t buf_len)
506{
507 printf("Out-of-band gtphub_write(%d):\n"
508 "to %s\n"
509 "%s\n",
510 (int)buf_len,
511 osmo_sockaddr_to_str(to_addr),
512 osmo_hexdump(buf, buf_len));
513 return 0;
514}
515
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200516#define buf_len 1024
517static uint8_t buf[buf_len];
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100518static uint8_t *reply_buf;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200519
520static unsigned int msg(const char *hex)
521{
522 unsigned int l = osmo_hexparse(hex, buf, buf_len);
523 OSMO_ASSERT(l > 0);
524 return l;
525}
526
527/* Compare static buf to given string constant. The amount of bytes is obtained
528 * from parsing the GTP header in buf. hex must match an osmo_hexdump() of the
529 * desired message. Return 1 if size and content match. */
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100530#define reply_is(MSG) _reply_is(MSG, __FILE__, __LINE__)
531static int _reply_is(const char *hex, const char *file, int line)
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200532{
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100533 struct gtp1_header_long *h = (void*)reply_buf;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200534 int len = ntoh16(h->length) + 8;
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100535 const char *dump = osmo_hexdump_nospc(reply_buf, len);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200536 int cmp = strcmp(dump, hex);
537
538 if (cmp != 0) {
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100539 printf("\n%s:%d: reply_is(): MISMATCH\n"
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200540 " expecting:\n'%s'\n"
541 " got:\n'%s'\n\n",
542 file,
543 line,
544 hex, dump);
545 int i;
546 int l = strlen(hex);
547 int m = strlen(dump);
548 if (m < l)
549 l = m;
550 for (i = 0; i < l; i++) {
551 if (hex[i] != dump[i]) {
552 printf("First mismatch at position %d:\n"
553 " %s\n %s\n", i, hex + i, dump + i);
554 break;
555 }
556 }
557 }
558 return cmp == 0;
559}
560
561#define same_addr(GOT, EXPECTED) _same_addr((GOT),(EXPECTED), __FILE__, __LINE__)
562static int _same_addr(const struct osmo_sockaddr *got,
563 const struct osmo_sockaddr *expected,
564 const char *file, int line)
565{
566 int cmp = osmo_sockaddr_cmp(got, expected);
567 if (!cmp)
568 return 1;
569 char buf[256];
570 printf("\n%s:%d: addr_is(): MISMATCH\n"
571 " expecting: '%s'\n"
572 " got: '%s'\n\n",
573 file, line,
574 osmo_sockaddr_to_str(expected),
575 osmo_sockaddr_to_strb(got, buf, sizeof(buf)));
576 return 0;
577}
578
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100579
580time_t now;
581static struct gtphub _hub;
582static struct gtphub *hub = &_hub;
583
584static int setup_test_hub()
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200585{
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100586 /* Not really needed, but to make 100% sure... */
587 ZERO_STRUCT(hub);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200588
589 gtphub_init(hub);
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100590
591 /* Tell this mock gtphub its local address for this test. */
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100592 LVL2_ASSERT(gsn_addr_from_str(&hub->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_CTRL].local_addr,
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100593 "127.0.1.1") == 0);
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100594 LVL2_ASSERT(gsn_addr_from_str(&hub->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_USER].local_addr,
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100595 "127.0.1.2") == 0);
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100596 LVL2_ASSERT(gsn_addr_from_str(&hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL].local_addr,
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100597 "127.0.2.1") == 0);
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100598 LVL2_ASSERT(gsn_addr_from_str(&hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_USER].local_addr,
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100599 "127.0.2.2") == 0);
600
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100601 hub->restart_counter = 0x23;
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100602 now = 345;
603 LVL2_ASSERT(send_from_sgsn("192.168.42.23", 423));
Neels Hofmeyre921e322015-11-11 00:45:50 +0100604 LVL2_ASSERT(resolve_to_ggsn("192.168.43.34", 2123));
Neels Hofmeyre54cd152015-11-24 13:31:06 +0100605 LVL2_ASSERT(send_from_ggsn("192.168.43.34", 434));
Neels Hofmeyre921e322015-11-11 00:45:50 +0100606 LVL2_ASSERT(resolve_to_sgsn("192.168.42.23", 2123));
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100607
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100608#define GGSNS_CTRL_FD 1
609#define GGSNS_USER_FD 2
610#define SGSNS_CTRL_FD 3
611#define SGSNS_USER_FD 4
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100612 hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL].ofd.priv_nr = GGSNS_CTRL_FD;
613 hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_USER].ofd.priv_nr = GGSNS_USER_FD;
614 hub->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_CTRL].ofd.priv_nr = SGSNS_CTRL_FD;
615 hub->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_USER].ofd.priv_nr = SGSNS_USER_FD;
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100616
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100617 return 1;
618}
619
Neels Hofmeyr20bd6bf2015-11-20 00:08:28 +0100620static int clear_test_hub()
621{
622 /* expire all */
Neels Hofmeyre54cd152015-11-24 13:31:06 +0100623 gtphub_gc(hub, now + (60 * GTPH_EXPIRE_SLOWLY_MINUTES) + 1);
Neels Hofmeyr20bd6bf2015-11-20 00:08:28 +0100624
625 int plane_idx;
626 plane_idx = GTPH_PLANE_CTRL;
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100627 LVL2_ASSERT(llist_empty(&hub->to_gsns[GTPH_SIDE_GGSN][plane_idx].peers));
628 LVL2_ASSERT(llist_empty(&hub->to_gsns[GTPH_SIDE_SGSN][plane_idx].peers));
Neels Hofmeyr20bd6bf2015-11-20 00:08:28 +0100629 plane_idx = GTPH_PLANE_USER;
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100630 LVL2_ASSERT(llist_empty(&hub->to_gsns[GTPH_SIDE_GGSN][plane_idx].peers));
631 LVL2_ASSERT(llist_empty(&hub->to_gsns[GTPH_SIDE_SGSN][plane_idx].peers));
Neels Hofmeyr20bd6bf2015-11-20 00:08:28 +0100632
Neels Hofmeyr99a50b32015-12-02 01:15:30 +0100633 LVL2_ASSERT(llist_empty(&hub->tunnels));
634 LVL2_ASSERT(llist_empty(&hub->pending_deletes));
635 LVL2_ASSERT(llist_empty(&hub->ggsn_lookups));
636 LVL2_ASSERT(llist_empty(&hub->resolved_ggsns));
637
Neels Hofmeyr20bd6bf2015-11-20 00:08:28 +0100638 gtphub_free(hub);
639 return 1;
640}
641
Neels Hofmeyre54cd152015-11-24 13:31:06 +0100642static int tunnels_are(const char *expect)
643{
644 static char buf[4096];
645 char *pos = buf;
646 size_t len = sizeof(buf);
647 struct gtphub_tunnel *t;
648 llist_for_each_entry(t, &hub->tunnels, entry) {
649 size_t wrote = snprintf(pos, len, "%s @%d\n",
650 gtphub_tunnel_str(t),
651 (int)t->expiry_entry.expiry);
652 LVL2_ASSERT(wrote < len);
653 pos += wrote;
654 len -= wrote;
655 }
656 *pos = '\0';
657
658 if (strncmp(buf, expect, sizeof(buf)) != 0) {
659 fprintf(stderr, "FAILURE: tunnels_are() mismatches expected value:\n"
660 "EXPECTED:\n%s\n"
661 "IS:\n%s\n",
662 expect, buf);
663 LVL2_ASSERT("tunnels do not match expected listing.");
664 return 0;
665 }
666 return 1;
667}
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100668
669static void test_echo(void)
670{
Neels Hofmeyre921e322015-11-11 00:45:50 +0100671 LOG("test_echo");
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100672 OSMO_ASSERT(setup_test_hub());
673
674 now = 123;
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100675
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100676 struct osmo_fd *to_ofd;
677 struct osmo_sockaddr to_addr;
678 struct gtphub_peer_port *pp;
679 int send;
680
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200681 const char *gtp_ping_from_sgsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100682 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200683 "01" /* type 01: Echo request */
684 "0004" /* length of 4 after header TEI */
685 "00000000" /* header TEI == 0 in Echo */
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100686 "abcd" /* some 2 octet sequence nr */
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200687 "0000" /* N-PDU 0, no extension header (why is this here?) */
688 ;
689
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100690 const char *gtp_pong_to_sgsn =
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200691 "32"
692 "02" /* type 02: Echo response */
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100693 "0006" /* length of 6 after header TEI */
694 "00000000" /* header TEI == 0 in Echo */
695 "abcd" /* same sequence nr */
696 "0000"
697 "0e23" /* Recovery with restart counter */
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200698 ;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200699
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100700 to_ofd = NULL;
701 ZERO_STRUCT(&to_addr);
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100702 send = gtphub_handle_buf(hub, GTPH_SIDE_SGSN, GTPH_PLANE_CTRL,
703 &sgsn_sender, buf, msg(gtp_ping_from_sgsn),
704 now, &reply_buf, &to_ofd, &to_addr);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200705 OSMO_ASSERT(send > 0);
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100706 OSMO_ASSERT(to_addr.l);
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100707 OSMO_ASSERT(same_addr(&to_addr, &sgsn_sender));
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100708 OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == SGSNS_CTRL_FD));
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100709 OSMO_ASSERT(reply_is(gtp_pong_to_sgsn));
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200710
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100711 pp = gtphub_port_find_sa(&hub->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_CTRL],
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100712 &sgsn_sender);
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100713 /* We don't record Echo peers. */
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100714 OSMO_ASSERT(!pp);
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100715
716 const char *gtp_ping_from_ggsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100717 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100718 "01" /* type 01: Echo request */
719 "0004" /* length of 4 after header TEI */
720 "00000000" /* header TEI == 0 in Echo */
721 "cdef" /* some 2 octet sequence nr */
722 "0000" /* N-PDU 0, no extension header (why is this here?) */
723 ;
724
725 const char *gtp_pong_to_ggsn =
726 "32"
727 "02" /* type 02: Echo response */
728 "0006" /* length of 6 after header TEI */
729 "00000000" /* header TEI == 0 in Echo */
730 "cdef" /* same sequence nr */
731 "0000"
732 "0e23" /* Recovery with restart counter */
733 ;
734
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100735 to_ofd = NULL;
736 ZERO_STRUCT(&to_addr);
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100737 send = gtphub_handle_buf(hub, GTPH_SIDE_GGSN, GTPH_PLANE_CTRL,
738 &ggsn_sender, buf, msg(gtp_ping_from_ggsn),
739 now, &reply_buf, &to_ofd, &to_addr);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200740 OSMO_ASSERT(send > 0);
Neels Hofmeyre921e322015-11-11 00:45:50 +0100741 OSMO_ASSERT(same_addr(&to_addr, &ggsn_sender));
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100742 OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == GGSNS_CTRL_FD));
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100743 OSMO_ASSERT(reply_is(gtp_pong_to_ggsn));
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200744
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100745 pp = gtphub_port_find_sa(&hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL],
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100746 &sgsn_sender);
747 OSMO_ASSERT(!pp);
748
749
750 /* And all the same on the user plane. */
751
752 to_ofd = NULL;
753 ZERO_STRUCT(&to_addr);
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100754 send = gtphub_handle_buf(hub, GTPH_SIDE_SGSN, GTPH_PLANE_USER,
755 &sgsn_sender, buf, msg(gtp_ping_from_sgsn),
756 now, &reply_buf, &to_ofd, &to_addr);
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100757 OSMO_ASSERT(send > 0);
758 OSMO_ASSERT(to_addr.l);
759 OSMO_ASSERT(same_addr(&to_addr, &sgsn_sender));
760 OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == SGSNS_USER_FD));
761 OSMO_ASSERT(reply_is(gtp_pong_to_sgsn));
762
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100763 pp = gtphub_port_find_sa(&hub->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_USER],
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100764 &sgsn_sender);
765 OSMO_ASSERT(!pp);
766
767 to_ofd = NULL;
768 ZERO_STRUCT(&to_addr);
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100769 send = gtphub_handle_buf(hub, GTPH_SIDE_GGSN, GTPH_PLANE_USER,
770 &ggsn_sender, buf, msg(gtp_ping_from_ggsn),
771 now, &reply_buf, &to_ofd, &to_addr);
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100772 OSMO_ASSERT(send > 0);
773 OSMO_ASSERT(same_addr(&to_addr, &ggsn_sender));
774 OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == GGSNS_USER_FD));
775 OSMO_ASSERT(reply_is(gtp_pong_to_ggsn));
776
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100777 pp = gtphub_port_find_sa(&hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_USER],
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100778 &sgsn_sender);
779 OSMO_ASSERT(!pp);
780
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200781
Neels Hofmeyr20bd6bf2015-11-20 00:08:28 +0100782 OSMO_ASSERT(clear_test_hub());
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100783}
784
785
786#define MSG_PDP_CTX_REQ(len, seq, restart, imsi, tei_u, tei_c, apn, gsn_c, gsn_u) \
787 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr. */ \
788 "10" /* type 16: Create PDP Context Request */ \
789 len /* msg length = 8 + len (2 octets) */ \
790 "00000000" /* No TEI yet */ \
791 seq /* Sequence nr (2 octets) */ \
792 "00" /* N-PDU 0 */ \
793 "00" /* No extensions */ \
794 /* IEs */ \
Neels Hofmeyrba9e9f62015-11-26 22:19:22 +0100795 "0e" restart /* 14: Recovery (restart counter: 1 octet) */ \
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100796 "02" /* 2 = IMSI */ \
797 imsi /* (8 octets) */ \
798 "0f01" /* 15: Selection mode = MS provided APN, subscription not verified*/ \
799 "10" /* 16: TEI Data I */ \
800 tei_u /* (4 octets) */ \
801 "11" /* 17: TEI Control Plane */ \
802 tei_c /* (4 octets) */ \
803 "1400" /* 20: NSAPI = 0*/ \
804 "1a" /* 26: Charging Characteristics */ \
805 "0800" \
806 "80" /* 128: End User Address */ \
807 "0002" /* length = 2: empty PDP Address */ \
808 "f121" /* spare 0xf0, PDP organization 1, PDP type number 0x21 = 33 */ \
809 "83" /* 131: Access Point Name */ \
810 apn /* (2 octets length, N octets encoded APN-NI) */ \
811 "84" /* 132: Protocol Configuration Options */ \
812 "0015" /* length = 21 */ \
813 "80c0231101010011036d69670868656d6d656c6967" \
814 "85" /* 133: GSN Address */ \
815 gsn_c /* (2 octets length, N octets addr) */ \
816 "85" /* 133: GSN Address (second entry) */ \
817 gsn_u /* (2 octets length, N octets addr) */ \
818 "86" /* 134: MS International PSTN/ISDN Number (MSISDN) */ \
819 "0007" /* length */ \
820 "916407123254f6" /* 1946702123456(f) */ \
821 "87" /* 135: Quality of Service (QoS) Profile */ \
822 "0004" /* length */ \
823 "00" /* priority */ \
824 "0b921f" /* QoS profile data */
825
826#define MSG_PDP_CTX_RSP(len, tei_h, seq, restart, tei_u, tei_c, gsn_c, gsn_u) \
827 "32" \
828 "11" /* Create PDP Context Response */ \
829 len /* msg length = 8 + len (2 octets) */ \
830 tei_h /* destination TEI (sent in req above) */ \
831 seq /* mapped seq */ \
832 "00" "00" \
833 /* IEs */ \
834 "01" /* 1: Cause */ \
835 "80" /* value = 0b10000000 = response, no rejection. */ \
836 "08" /* 8: Reordering Required */ \
837 "00" /* not required. */ \
Neels Hofmeyrba9e9f62015-11-26 22:19:22 +0100838 "0e" restart /* 14: Recovery */ \
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100839 "10" /* 16: TEI Data I */ \
840 tei_u \
841 "11" /* 17: TEI Control */ \
842 tei_c \
843 "7f" /* 127: Charging ID */ \
844 "00000001" \
845 "80" /* 128: End User Address */ \
846 "0006" /* length = 6 */ \
847 "f121" /* spare 0xf0, PDP organization 1, PDP type number 0x21 = 33 */ \
848 "7f000002" \
849 "84" /* 132: Protocol Configuration Options */ \
850 "0014" /* len = 20 */ \
851 "8080211002000010810608080808830600000000" \
852 "85" /* 133: GSN Address (Ctrl) */ \
853 gsn_c \
854 "85" /* 133: GSN Address (User) */ \
855 gsn_u \
856 "87" /* 135: Quality of Service (QoS) Profile */ \
857 "0004" /* length */ \
858 "00" /* priority */ \
859 "0b921f" /* QoS profile data */
860
861#define msg_from_sgsn_c(A,B,C,D) msg_from_sgsn(GTPH_PLANE_CTRL, A,B,C,D)
862#define msg_from_sgsn_u(A,B,C,D) msg_from_sgsn(GTPH_PLANE_USER, A,B,C,D)
863static int msg_from_sgsn(int plane_idx,
864 struct osmo_sockaddr *_sgsn_sender,
865 struct osmo_sockaddr *ggsn_receiver,
866 const char *hex_from_sgsn,
867 const char *hex_to_ggsn)
868{
869 struct osmo_fd *ggsn_ofd = NULL;
870 struct osmo_sockaddr ggsn_addr;
871 int send;
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100872 send = gtphub_handle_buf(hub, GTPH_SIDE_SGSN, plane_idx, _sgsn_sender,
873 buf, msg(hex_from_sgsn), now,
874 &reply_buf, &ggsn_ofd, &ggsn_addr);
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100875 LVL2_ASSERT(send > 0);
876 LVL2_ASSERT(same_addr(&ggsn_addr, ggsn_receiver));
877 LVL2_ASSERT(reply_is(hex_to_ggsn));
878 return 1;
879}
880
881#define msg_from_ggsn_c(A,B,C,D) msg_from_ggsn(GTPH_PLANE_CTRL, A,B,C,D)
882#define msg_from_ggsn_u(A,B,C,D) msg_from_ggsn(GTPH_PLANE_USER, A,B,C,D)
883static int msg_from_ggsn(int plane_idx,
884 struct osmo_sockaddr *ggsn_sender,
885 struct osmo_sockaddr *sgsn_receiver,
886 const char *msg_from_ggsn,
887 const char *msg_to_sgsn)
888{
889 struct osmo_fd *sgsn_ofd;
890 struct osmo_sockaddr sgsn_addr;
891 int send;
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100892 send = gtphub_handle_buf(hub, GTPH_SIDE_GGSN, plane_idx, ggsn_sender,
893 buf, msg(msg_from_ggsn), now,
894 &reply_buf, &sgsn_ofd, &sgsn_addr);
Neels Hofmeyrd010c492015-12-06 23:12:02 +0100895 if (*msg_to_sgsn) {
896 LVL2_ASSERT(send > 0);
897 LVL2_ASSERT(same_addr(&sgsn_addr, sgsn_receiver));
898 LVL2_ASSERT(reply_is(msg_to_sgsn));
899 }
900 else
901 LVL2_ASSERT(send == 0);
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100902 return 1;
903}
904
905static int create_pdp_ctx()
906{
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100907 const char *gtp_req_from_sgsn =
908 MSG_PDP_CTX_REQ("0068",
909 "abcd",
910 "60",
911 "42000121436587f9",
912 "00000123",
913 "00000321",
914 "0009""08696e7465726e6574", /* "(8)internet" */
915 "0004""c0a82a17", /* same as default sgsn_sender */
916 "0004""c0a82a17"
917 );
918 const char *gtp_req_to_ggsn =
919 MSG_PDP_CTX_REQ("0068",
920 "6d31", /* mapped seq ("abcd") */
Neels Hofmeyrba9e9f62015-11-26 22:19:22 +0100921 "23",
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100922 "42000121436587f9",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +0100923 "00000001", /* Data I: tunnel's TEI */
924 "00000001", /* Control: tunnel's TEI */
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100925 "0009""08696e7465726e6574",
926 "0004""7f000201", /* replaced with gtphub's ggsn ctrl */
927 "0004""7f000202" /* replaced with gtphub's ggsn user */
928 );
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100929
930 LVL2_ASSERT(msg_from_sgsn_c(&sgsn_sender,
931 &resolved_ggsn_addr,
932 gtp_req_from_sgsn,
933 gtp_req_to_ggsn));
934 LVL2_ASSERT(was_resolved_for("240010123456789", "internet"));
935
Neels Hofmeyre54cd152015-11-24 13:31:06 +0100936 LVL2_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +0100937 "TEI=1:"
938 " 192.168.42.23 (TEI C=321 U=123)"
939 " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)"
Neels Hofmeyre54cd152015-11-24 13:31:06 +0100940 " @21945\n"));
941
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100942 const char *gtp_resp_from_ggsn =
943 MSG_PDP_CTX_RSP("004e",
944 "00000001", /* destination TEI (sent in req above) */
945 "6d31", /* mapped seq */
946 "01", /* restart */
947 "00000567", /* TEI U */
948 "00000765", /* TEI C */
949 "0004""c0a82b22", /* GSN addresses */
950 "0004""c0a82b22" /* (== resolved_ggsn_addr) */
951 );
952 const char *gtp_resp_to_sgsn =
953 MSG_PDP_CTX_RSP("004e",
954 "00000321", /* unmapped TEI ("001") */
955 "abcd", /* unmapped seq ("6d31") */
Neels Hofmeyrba9e9f62015-11-26 22:19:22 +0100956 "23",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +0100957 "00000001", /* mapped TEI from GGSN ("567") */
958 "00000001", /* mapped TEI from GGSN ("765") */
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100959 "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */
960 "0004""7f000102" /* gtphub's address towards SGSNs (User) */
961 );
Neels Hofmeyre921e322015-11-11 00:45:50 +0100962 /* The response should go back to whichever port the request came from
963 * (unmapped by sequence nr) */
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100964 LVL2_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr,
965 &sgsn_sender,
966 gtp_resp_from_ggsn,
967 gtp_resp_to_sgsn));
968
969 return 1;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200970}
971
Neels Hofmeyr10fc0242015-12-01 00:23:45 +0100972#define MSG_DEL_PDP_CTX_REQ(tei, seq) \
973 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr. */ \
974 "14" /* type 20: Delete PDP Context Request */ \
975 "0008" /* msg length = 8 + len (2 octets) */ \
976 tei /* TEI Ctrl */ \
977 seq /* Sequence nr (2 octets) */ \
978 "00" /* N-PDU 0 */ \
979 "00" /* No extensions */ \
980 /* IEs */ \
981 "13fe" /* 19: Teardown ind = 0 */ \
982 "1400" /* 20: NSAPI = 0*/ \
983
984#define MSG_DEL_PDP_CTX_RSP(tei, seq) \
985 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr. */ \
986 "15" /* type 21: Delete PDP Context Response */ \
987 "0006" /* msg length = 8 + len (2 octets) */ \
988 tei /* TEI Ctrl */ \
989 seq /* Sequence nr (2 octets) */ \
990 "00" /* N-PDU 0 */ \
991 "00" /* No extensions */ \
992 /* IEs */ \
993 "01" /* 1: Cause */ \
994 "80" /* value = 0b10000000 = response, no rejection. */ \
995
Neels Hofmeyr75599102015-12-01 01:01:16 +0100996static int delete_pdp_ctx_from_sgsn(void)
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200997{
Neels Hofmeyr10fc0242015-12-01 00:23:45 +0100998 now += GTPH_EXPIRE_QUICKLY_SECS + 1;
999 gtphub_gc(hub, now);
1000
1001 LVL2_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001002 "TEI=1:"
1003 " 192.168.42.23 (TEI C=321 U=123)"
1004 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyr10fc0242015-12-01 00:23:45 +01001005 " @21945\n"));
1006
1007 /* TEI Ctrl from above and next sequence after abcd. */
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001008 const char *gtp_req_from_sgsn = MSG_DEL_PDP_CTX_REQ("00000001", "abce");
Neels Hofmeyr10fc0242015-12-01 00:23:45 +01001009 const char *gtp_req_to_ggsn = MSG_DEL_PDP_CTX_REQ("00000765", "6d32");
1010
1011 LVL2_ASSERT(msg_from_sgsn_c(&sgsn_sender,
1012 &resolved_ggsn_addr,
1013 gtp_req_from_sgsn,
1014 gtp_req_to_ggsn));
1015
1016 /* 21945 + 31 = 21976 */
1017 LVL2_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001018 "TEI=1:"
1019 " 192.168.42.23 (TEI C=321 U=123)"
1020 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyr10fc0242015-12-01 00:23:45 +01001021 " @21976\n"));
1022
1023 const char *gtp_resp_from_ggsn =
1024 MSG_DEL_PDP_CTX_RSP("00000001", "6d32");
1025 const char *gtp_resp_to_sgsn =
1026 MSG_DEL_PDP_CTX_RSP("00000321", "abce");
1027
1028 /* The response should go back to whichever port the request came from
1029 * (unmapped by sequence nr) */
1030 LVL2_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr,
1031 &sgsn_sender,
1032 gtp_resp_from_ggsn,
1033 gtp_resp_to_sgsn));
1034
1035 LVL2_ASSERT(tunnels_are(""));
1036
1037 return 1;
1038}
1039
Neels Hofmeyr75599102015-12-01 01:01:16 +01001040static int delete_pdp_ctx_from_ggsn(void)
Neels Hofmeyr10fc0242015-12-01 00:23:45 +01001041{
Neels Hofmeyr75599102015-12-01 01:01:16 +01001042 now += GTPH_EXPIRE_QUICKLY_SECS + 1;
1043 gtphub_gc(hub, now);
1044
1045 LVL2_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001046 "TEI=1:"
1047 " 192.168.42.23 (TEI C=321 U=123)"
1048 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyr75599102015-12-01 01:01:16 +01001049 " @21945\n"));
1050
1051 /* TEI Ctrl from above and next sequence after abcd. */
1052 const char *gtp_req_from_ggsn = MSG_DEL_PDP_CTX_REQ("00000001", "5432");
1053 const char *gtp_req_to_sgsn = MSG_DEL_PDP_CTX_REQ("00000321", "6d31");
1054
1055 LVL2_ASSERT(msg_from_ggsn_c(&ggsn_sender,
1056 &resolved_sgsn_addr,
1057 gtp_req_from_ggsn,
1058 gtp_req_to_sgsn));
1059
1060 /* 21945 + 31 = 21976 */
1061 LVL2_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001062 "TEI=1:"
1063 " 192.168.42.23 (TEI C=321 U=123)"
1064 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyr75599102015-12-01 01:01:16 +01001065 " @21976\n"));
1066
1067 const char *gtp_resp_from_sgsn =
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001068 MSG_DEL_PDP_CTX_RSP("00000001", "6d31");
Neels Hofmeyr75599102015-12-01 01:01:16 +01001069 const char *gtp_resp_to_ggsn =
1070 MSG_DEL_PDP_CTX_RSP("00000765", "5432");
1071
1072 /* The response should go back to whichever port the request came from
1073 * (unmapped by sequence nr) */
1074 LVL2_ASSERT(msg_from_sgsn_c(&resolved_sgsn_addr,
1075 &ggsn_sender,
1076 gtp_resp_from_sgsn,
1077 gtp_resp_to_ggsn));
1078
1079 LVL2_ASSERT(tunnels_are(""));
1080
1081 return 1;
1082}
1083
1084static void test_one_pdp_ctx(int del_from_side)
1085{
1086 if (del_from_side == GTPH_SIDE_SGSN)
1087 LOG("test_one_pdp_ctx (del from SGSN)")
1088 else LOG("test_one_pdp_ctx (del from GGSN)");
Neels Hofmeyrc2275942015-11-10 22:07:04 +01001089 OSMO_ASSERT(setup_test_hub());
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001090
Neels Hofmeyrc2275942015-11-10 22:07:04 +01001091 OSMO_ASSERT(create_pdp_ctx());
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001092
1093 struct gtphub_peer_port *ggsn_port =
Neels Hofmeyra9905a52015-11-29 23:49:48 +01001094 gtphub_port_find_sa(&hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL],
Neels Hofmeyrc2275942015-11-10 22:07:04 +01001095 &resolved_ggsn_addr);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001096 OSMO_ASSERT(ggsn_port);
1097 struct gtphub_peer *ggsn = ggsn_port->peer_addr->peer;
1098 /* now == 345; now + 30 == 375.
1099 * seq mapping from above:
1100 * 0xabcd == 43981 (sent in the packet)
1101 * 0x6d31 == 27953 (harcoded seq mapping start val) */
1102 OSMO_ASSERT(nr_map_is(&ggsn->seq_map, "(43981->27953@375), "));
1103
1104 /* now == 345; now + (6 * 60 * 60) == 21600 + 345 == 21945.
1105 * 0x00000321 == 801 (TEI from SGSN Ctrl)
1106 * 0x00000123 == 291 (TEI from SGSN User)
1107 * 0x00000765 == 1893 (TEI from GGSN Ctrl)
1108 * 0x00000567 == 1383 (TEI from GGSN User)
1109 * Mapped TEIs should be 1 and 2. */
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001110 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001111 "TEI=1:"
1112 " 192.168.42.23 (TEI C=321 U=123)"
1113 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001114 " @21945\n"));
Neels Hofmeyr10fc0242015-12-01 00:23:45 +01001115
Neels Hofmeyr75599102015-12-01 01:01:16 +01001116 if (del_from_side == GTPH_SIDE_SGSN) {
1117 OSMO_ASSERT(delete_pdp_ctx_from_sgsn());
1118 } else {
1119 OSMO_ASSERT(delete_pdp_ctx_from_ggsn());
1120 }
Neels Hofmeyr10fc0242015-12-01 00:23:45 +01001121 OSMO_ASSERT(tunnels_are(""));
1122
Neels Hofmeyr20bd6bf2015-11-20 00:08:28 +01001123 OSMO_ASSERT(clear_test_hub());
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001124}
1125
Neels Hofmeyre921e322015-11-11 00:45:50 +01001126static void test_user_data(void)
1127{
1128 LOG("test_user_data");
1129
1130 OSMO_ASSERT(setup_test_hub());
1131
1132 OSMO_ASSERT(create_pdp_ctx());
1133
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001134 /* now == 345; now + (6 * 60 * 60) == 21600 + 345 == 21945. */
1135 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001136 "TEI=1:"
1137 " 192.168.42.23 (TEI C=321 U=123)"
1138 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001139 " @21945\n"));
1140
Neels Hofmeyre921e322015-11-11 00:45:50 +01001141 LOG("- user data starts");
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001142 /* Now expect default port numbers for User plane. */
Neels Hofmeyre921e322015-11-11 00:45:50 +01001143 resolve_to_ggsn("192.168.43.34", 2152);
1144 resolve_to_sgsn("192.168.42.23", 2152);
1145
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001146 /* 10 minutes later */
1147 now += 600;
1148
Neels Hofmeyre921e322015-11-11 00:45:50 +01001149 const char *u_from_ggsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +01001150 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyre921e322015-11-11 00:45:50 +01001151 "ff" /* type 255: G-PDU */
1152 "0058" /* length: 88 + 8 octets == 96 */
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001153 "00000001" /* mapped TEI for SGSN from create_pdp_ctx() */
Neels Hofmeyre921e322015-11-11 00:45:50 +01001154 "0070" /* seq */
1155 "0000" /* No extensions */
1156 /* User data (ICMP packet), 96 - 12 = 84 octets */
1157 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
1158 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
1159 "202122232425262728292a2b2c2d2e2f3031323334353637"
1160 ;
1161 const char *u_to_sgsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +01001162 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyre921e322015-11-11 00:45:50 +01001163 "ff" /* type 255: G-PDU */
1164 "0058" /* length: 88 + 8 octets == 96 */
1165 "00000123" /* unmapped User TEI */
1166 "6d31" /* new mapped seq */
1167 "0000"
1168 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
1169 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
1170 "202122232425262728292a2b2c2d2e2f3031323334353637"
1171 ;
1172
1173 /* This depends on create_pdp_ctx() sending resolved_sgsn_addr as GSN
1174 * Address IEs in the GGSN's Create PDP Ctx Response. */
1175 OSMO_ASSERT(msg_from_ggsn_u(&ggsn_sender,
1176 &resolved_sgsn_addr,
1177 u_from_ggsn,
1178 u_to_sgsn));
1179
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001180 /* Make sure the user plane messages have refreshed the TEI mapping
1181 * timeouts: 21945 + 600 == 22545. */
1182 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001183 "TEI=1:"
1184 " 192.168.42.23 (TEI C=321 U=123)"
1185 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001186 " @22545\n"));
1187
Neels Hofmeyre921e322015-11-11 00:45:50 +01001188 const char *u_from_sgsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +01001189 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyre921e322015-11-11 00:45:50 +01001190 "ff" /* type 255: G-PDU */
1191 "0058" /* length: 88 + 8 octets == 96 */
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001192 "00000001" /* mapped User TEI for GGSN from create_pdp_ctx() */
Neels Hofmeyr1ae3ebd2015-12-03 14:19:08 +01001193 "1234" /* unknown seq */
Neels Hofmeyre921e322015-11-11 00:45:50 +01001194 "0000" /* No extensions */
1195 /* User data (ICMP packet), 96 - 12 = 84 octets */
1196 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
1197 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
1198 "202122232425262728292a2b2c2d2e2f3031323334353637"
1199 ;
1200 const char *u_to_ggsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +01001201 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyre921e322015-11-11 00:45:50 +01001202 "ff" /* type 255: G-PDU */
1203 "0058" /* length: 88 + 8 octets == 96 */
1204 "00000567" /* unmapped User TEI */
Neels Hofmeyr1ae3ebd2015-12-03 14:19:08 +01001205 "6d31" /* unmapped seq */
Neels Hofmeyre921e322015-11-11 00:45:50 +01001206 "0000"
1207 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
1208 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
1209 "202122232425262728292a2b2c2d2e2f3031323334353637"
1210 ;
1211
Neels Hofmeyr1ae3ebd2015-12-03 14:19:08 +01001212 OSMO_ASSERT(msg_from_sgsn_u(&sgsn_sender,
1213 &resolved_ggsn_addr,
Neels Hofmeyre921e322015-11-11 00:45:50 +01001214 u_from_sgsn,
1215 u_to_ggsn));
1216
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001217 /* Make sure the user plane messages have refreshed the TEI mapping
1218 * timeouts: 21945 + 600 == 22545. Both timeouts refreshed: */
1219 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001220 "TEI=1:"
1221 " 192.168.42.23 (TEI C=321 U=123)"
1222 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001223 " @22545\n"));
1224
Neels Hofmeyr20bd6bf2015-11-20 00:08:28 +01001225 OSMO_ASSERT(clear_test_hub());
Neels Hofmeyre921e322015-11-11 00:45:50 +01001226}
1227
Neels Hofmeyrbe4beba2015-12-02 14:18:26 +01001228static void test_reused_tei(void)
1229{
1230 LOG("test_reused_tei");
1231
1232 OSMO_ASSERT(setup_test_hub());
1233
1234 OSMO_ASSERT(create_pdp_ctx());
1235
1236 const char *gtp_req_from_sgsn =
1237 MSG_PDP_CTX_REQ("0068",
1238 "abce", /* Next seq */
1239 "60",
1240 "42000121436587f9",
1241 "00000123", /* Same TEIs as before */
1242 "00000321",
1243 "0009""08696e7465726e6574", /* "(8)internet" */
1244 "0004""c0a82a17", /* same as default sgsn_sender */
1245 "0004""c0a82a17"
1246 );
1247 const char *gtp_req_to_ggsn =
1248 MSG_PDP_CTX_REQ("0068",
1249 "6d32", /* mapped seq ("abce") */
1250 "23",
1251 "42000121436587f9",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001252 "00000002", /* mapped TEI Data I ("123") */
1253 "00000002", /* mapped TEI Control ("321") */
Neels Hofmeyrbe4beba2015-12-02 14:18:26 +01001254 "0009""08696e7465726e6574",
1255 "0004""7f000201", /* replaced with gtphub's ggsn ctrl */
1256 "0004""7f000202" /* replaced with gtphub's ggsn user */
1257 );
1258
1259 OSMO_ASSERT(msg_from_sgsn_c(&sgsn_sender,
1260 &resolved_ggsn_addr,
1261 gtp_req_from_sgsn,
1262 gtp_req_to_ggsn));
1263 OSMO_ASSERT(was_resolved_for("240010123456789", "internet"));
1264
1265 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001266 "TEI=2:"
1267 " 192.168.42.23 (TEI C=321 U=123)"
1268 " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)"
Neels Hofmeyrbe4beba2015-12-02 14:18:26 +01001269 " @21945\n"));
1270
1271 const char *gtp_resp_from_ggsn =
1272 MSG_PDP_CTX_RSP("004e",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001273 "00000002", /* destination TEI (sent in req above) */
Neels Hofmeyrbe4beba2015-12-02 14:18:26 +01001274 "6d32", /* mapped seq */
1275 "01", /* restart */
1276 "00000567", /* TEI U */
1277 "00000765", /* TEI C */
1278 "0004""c0a82b22", /* GSN addresses */
1279 "0004""c0a82b22" /* (== resolved_ggsn_addr) */
1280 );
1281 const char *gtp_resp_to_sgsn =
1282 MSG_PDP_CTX_RSP("004e",
1283 "00000321", /* unmapped TEI ("001") */
1284 "abce", /* unmapped seq ("6d32") */
1285 "23",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001286 "00000002", /* mapped TEI from GGSN ("567") */
1287 "00000002", /* mapped TEI from GGSN ("765") */
Neels Hofmeyrbe4beba2015-12-02 14:18:26 +01001288 "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */
1289 "0004""7f000102" /* gtphub's address towards SGSNs (User) */
1290 );
1291 /* The response should go back to whichever port the request came from
1292 * (unmapped by sequence nr) */
1293 OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr,
1294 &sgsn_sender,
1295 gtp_resp_from_ggsn,
1296 gtp_resp_to_sgsn));
1297
1298 OSMO_ASSERT(clear_test_hub());
1299}
1300
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001301static void test_peer_restarted(void)
1302{
1303 LOG("test_peer_restarted");
1304
1305 OSMO_ASSERT(setup_test_hub());
1306
1307 OSMO_ASSERT(create_pdp_ctx());
1308
1309 now += 10;
1310
1311 const char *gtp_req_from_sgsn =
1312 MSG_PDP_CTX_REQ("0068",
1313 "1234", /* brand new seq */
1314 "61", /* DIFFERING restart counter */
1315 "42000121436587f9",
1316 "00000abc",
1317 "00000cba",
1318 "0009""08696e7465726e6574", /* "(8)internet" */
1319 "0004""c0a82a17", /* same as default sgsn_sender */
1320 "0004""c0a82a17"
1321 );
1322 const char *gtp_req_to_ggsn =
1323 MSG_PDP_CTX_REQ("0068",
Neels Hofmeyrc6d51f52015-12-02 15:44:34 +01001324 "6d33", /* mapped seq ("1234") */
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001325 "23",
1326 "42000121436587f9",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001327 "00000002", /* mapped TEI Data I ("123") */
1328 "00000002", /* mapped TEI Control ("321") */
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001329 "0009""08696e7465726e6574",
1330 "0004""7f000201", /* replaced with gtphub's ggsn ctrl */
1331 "0004""7f000202" /* replaced with gtphub's ggsn user */
1332 );
1333
1334 OSMO_ASSERT(msg_from_sgsn_c(&sgsn_sender,
1335 &resolved_ggsn_addr,
1336 gtp_req_from_sgsn,
1337 gtp_req_to_ggsn));
1338 OSMO_ASSERT(was_resolved_for("240010123456789", "internet"));
1339
1340 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001341 "TEI=2:"
1342 " 192.168.42.23 (TEI C=cba U=abc)"
1343 " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)"
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001344 " @21955\n"
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001345 "TEI=1:"
1346 " (uninitialized) (TEI C=321 U=123)"
1347 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001348 " @21945\n"
1349 ));
1350
1351 const char *gtp_resp_from_ggsn =
1352 MSG_PDP_CTX_RSP("004e",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001353 "00000002", /* destination TEI (sent in req above) */
Neels Hofmeyrc6d51f52015-12-02 15:44:34 +01001354 "6d33", /* mapped seq */
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001355 "01", /* restart */
1356 "00000def", /* TEI U */
1357 "00000fde", /* TEI C */
1358 "0004""c0a82b22", /* GSN addresses */
1359 "0004""c0a82b22" /* (== resolved_ggsn_addr) */
1360 );
1361 const char *gtp_resp_to_sgsn =
1362 MSG_PDP_CTX_RSP("004e",
1363 "00000cba", /* unmapped TEI ("005") */
1364 "1234", /* unmapped seq ("6d32") */
1365 "23",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001366 "00000002", /* mapped TEI from GGSN ("567") */
1367 "00000002", /* mapped TEI from GGSN ("765") */
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001368 "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */
1369 "0004""7f000102" /* gtphub's address towards SGSNs (User) */
1370 );
1371 /* The response should go back to whichever port the request came from
1372 * (unmapped by sequence nr) */
1373 OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr,
1374 &sgsn_sender,
1375 gtp_resp_from_ggsn,
1376 gtp_resp_to_sgsn));
1377
1378 OSMO_ASSERT(clear_test_hub());
1379}
1380
1381static void test_peer_restarted_reusing_tei(void)
1382{
1383 LOG("test_peer_restarted_reusing_tei");
1384
1385 OSMO_ASSERT(setup_test_hub());
1386
1387 OSMO_ASSERT(create_pdp_ctx());
1388
1389 now += 10;
1390
1391 const char *gtp_req_from_sgsn =
1392 MSG_PDP_CTX_REQ("0068",
1393 "1234", /* brand new seq */
1394 "61", /* DIFFERING restart counter */
1395 "42000121436587f9",
1396 "00000123", /* SAME TEI */
1397 "00000321",
1398 "0009""08696e7465726e6574", /* "(8)internet" */
1399 "0004""c0a82a17", /* same as default sgsn_sender */
1400 "0004""c0a82a17"
1401 );
1402 const char *gtp_req_to_ggsn =
1403 MSG_PDP_CTX_REQ("0068",
Neels Hofmeyrd010c492015-12-06 23:12:02 +01001404 "6d33", /* seq 6d31 + 2, after "out-of-band" Delete PDP Ctx
1405 due to differing restart counter. */
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001406 "23",
1407 "42000121436587f9",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001408 "00000002", /* mapped TEI Data I ("123") */
1409 "00000002", /* mapped TEI Control ("321") */
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001410 "0009""08696e7465726e6574",
1411 "0004""7f000201", /* replaced with gtphub's ggsn ctrl */
1412 "0004""7f000202" /* replaced with gtphub's ggsn user */
1413 );
1414
1415 OSMO_ASSERT(msg_from_sgsn_c(&sgsn_sender,
1416 &resolved_ggsn_addr,
1417 gtp_req_from_sgsn,
1418 gtp_req_to_ggsn));
1419 OSMO_ASSERT(was_resolved_for("240010123456789", "internet"));
1420
1421 OSMO_ASSERT(tunnels_are(
Neels Hofmeyrd010c492015-12-06 23:12:02 +01001422 "TEI=2:" /* being established after restart */
1423 " 192.168.42.23 (TEI C=321 U=123)"
1424 " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)"
1425 " @21955\n"
1426 "TEI=1:" /* invalidated due to restart */
1427 " (uninitialized) (TEI C=321 U=123)"
1428 " <-> 192.168.43.34 (TEI C=765 U=567)"
1429 " @21945\n"
1430 ));
1431
1432 /* An "out-of-band" delete request should have been sent to the GGSN
1433 * (checked by expected log output in gtphub_test.ok), and the GGSN
1434 * will (usually) send a Delete Response like this: */
1435 const char *gtp_del_resp_from_ggsn =
1436 MSG_DEL_PDP_CTX_RSP("00000001", "6d32");
1437
1438 /* For this response (due to peer restart) we expect no forwarded
1439 * message. */
1440 OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr,
1441 &sgsn_sender,
1442 gtp_del_resp_from_ggsn,
1443 ""));
1444
1445 OSMO_ASSERT(tunnels_are(
1446 "TEI=2:" /* still being established after restart */
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001447 " 192.168.42.23 (TEI C=321 U=123)"
1448 " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)"
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001449 " @21955\n"
1450 ));
1451
1452 const char *gtp_resp_from_ggsn =
1453 MSG_PDP_CTX_RSP("004e",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001454 "00000002", /* destination TEI (sent in req above) */
Neels Hofmeyrd010c492015-12-06 23:12:02 +01001455 "6d33", /* mapped seq */
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001456 "01", /* restart */
1457 "00000def", /* TEI U */
1458 "00000fde", /* TEI C */
1459 "0004""c0a82b22", /* GSN addresses */
1460 "0004""c0a82b22" /* (== resolved_ggsn_addr) */
1461 );
1462 const char *gtp_resp_to_sgsn =
1463 MSG_PDP_CTX_RSP("004e",
1464 "00000321", /* unmapped TEI ("005") */
Neels Hofmeyrd010c492015-12-06 23:12:02 +01001465 "1234", /* unmapped seq ("6d33") */
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001466 "23",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001467 "00000002", /* mapped TEI from GGSN ("567") */
1468 "00000002", /* mapped TEI from GGSN ("765") */
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001469 "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */
1470 "0004""7f000102" /* gtphub's address towards SGSNs (User) */
1471 );
1472 /* The response should go back to whichever port the request came from
1473 * (unmapped by sequence nr) */
1474 OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr,
1475 &sgsn_sender,
1476 gtp_resp_from_ggsn,
1477 gtp_resp_to_sgsn));
1478
Neels Hofmeyrd010c492015-12-06 23:12:02 +01001479 OSMO_ASSERT(tunnels_are(
1480 "TEI=2:" /* still being established after restart */
1481 " 192.168.42.23 (TEI C=321 U=123)"
1482 " <-> 192.168.43.34 (TEI C=fde U=def)"
1483 " @21955\n"
1484 ));
1485
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001486 OSMO_ASSERT(clear_test_hub());
1487}
1488
Neels Hofmeyrf8c70102015-12-03 14:29:48 +01001489static void test_sgsn_behind_nat(void)
1490{
1491 LOG("test_user_data");
1492
1493 OSMO_ASSERT(setup_test_hub());
1494 hub->sgsn_use_sender = 1; /* <-- Main difference to test_user_data() */
1495 resolve_to_sgsn("192.168.42.23", 423); /* Same as sender */
1496
1497 OSMO_ASSERT(create_pdp_ctx());
1498
1499 /* now == 345; now + (6 * 60 * 60) == 21600 + 345 == 21945. */
1500 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001501 "TEI=1:"
1502 " 192.168.42.23 (TEI C=321 U=123)"
1503 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyrf8c70102015-12-03 14:29:48 +01001504 " @21945\n"));
1505
1506 LOG("- user data starts");
1507 /* Now expect default port numbers for User plane -- except SGSN. */
1508 resolve_to_ggsn("192.168.43.34", 2152);
1509
1510 /* 10 minutes later */
1511 now += 600;
1512
1513 const char *u_from_ggsn =
1514 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
1515 "ff" /* type 255: G-PDU */
1516 "0058" /* length: 88 + 8 octets == 96 */
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001517 "00000001" /* mapped User TEI for SGSN from create_pdp_ctx() */
Neels Hofmeyrf8c70102015-12-03 14:29:48 +01001518 "0070" /* seq */
1519 "0000" /* No extensions */
1520 /* User data (ICMP packet), 96 - 12 = 84 octets */
1521 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
1522 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
1523 "202122232425262728292a2b2c2d2e2f3031323334353637"
1524 ;
1525 const char *u_to_sgsn =
1526 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
1527 "ff" /* type 255: G-PDU */
1528 "0058" /* length: 88 + 8 octets == 96 */
1529 "00000123" /* unmapped User TEI */
1530 "6d31" /* new mapped seq */
1531 "0000"
1532 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
1533 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
1534 "202122232425262728292a2b2c2d2e2f3031323334353637"
1535 ;
1536
1537 /* This depends on create_pdp_ctx() sending resolved_sgsn_addr as GSN
1538 * Address IEs in the GGSN's Create PDP Ctx Response. */
1539 OSMO_ASSERT(msg_from_ggsn_u(&ggsn_sender,
1540 &resolved_sgsn_addr,
1541 u_from_ggsn,
1542 u_to_sgsn));
1543
1544 /* Make sure the user plane messages have refreshed the TEI mapping
1545 * timeouts: 21945 + 600 == 22545. */
1546 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001547 "TEI=1:"
1548 " 192.168.42.23 (TEI C=321 U=123)"
1549 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyrf8c70102015-12-03 14:29:48 +01001550 " @22545\n"));
1551
1552 const char *u_from_sgsn =
1553 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
1554 "ff" /* type 255: G-PDU */
1555 "0058" /* length: 88 + 8 octets == 96 */
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001556 "00000001" /* mapped User TEI for GGSN from create_pdp_ctx() */
Neels Hofmeyrf8c70102015-12-03 14:29:48 +01001557 "1234" /* unknown seq */
1558 "0000" /* No extensions */
1559 /* User data (ICMP packet), 96 - 12 = 84 octets */
1560 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
1561 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
1562 "202122232425262728292a2b2c2d2e2f3031323334353637"
1563 ;
1564 const char *u_to_ggsn =
1565 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
1566 "ff" /* type 255: G-PDU */
1567 "0058" /* length: 88 + 8 octets == 96 */
1568 "00000567" /* unmapped User TEI */
1569 "6d31" /* unmapped seq */
1570 "0000"
1571 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
1572 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
1573 "202122232425262728292a2b2c2d2e2f3031323334353637"
1574 ;
1575
1576 OSMO_ASSERT(msg_from_sgsn_u(&sgsn_sender,
1577 &resolved_ggsn_addr,
1578 u_from_sgsn,
1579 u_to_ggsn));
1580
1581 /* Make sure the user plane messages have refreshed the TEI mapping
1582 * timeouts: 21945 + 600 == 22545. Both timeouts refreshed: */
1583 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001584 "TEI=1:"
1585 " 192.168.42.23 (TEI C=321 U=123)"
1586 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyrf8c70102015-12-03 14:29:48 +01001587 " @22545\n"));
1588
1589 OSMO_ASSERT(clear_test_hub());
1590}
1591
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001592void test_parallel_context_creation(void)
1593{
1594 LOG("test_parallel_context_creation");
1595
1596 OSMO_ASSERT(setup_test_hub());
1597
1598 const char *gtp_req_from_sgsn1 =
1599 MSG_PDP_CTX_REQ("0068",
1600 "abcd",
1601 "60",
1602 "42000121436587f9",
1603 "00000123",
1604 "00000321",
1605 "0009""08696e7465726e6574", /* "(8)internet" */
1606 "0004""c0a82a17", /* same as default sgsn_sender */
1607 "0004""c0a82a17"
1608 );
1609 const char *gtp_req_to_ggsn1 =
1610 MSG_PDP_CTX_REQ("0068",
1611 "6d31", /* mapped seq ("abcd") */
1612 "23",
1613 "42000121436587f9",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001614 "00000001", /* mapped TEI Data I ("123") */
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001615 "00000001", /* mapped TEI Control ("321") */
1616 "0009""08696e7465726e6574",
1617 "0004""7f000201", /* replaced with gtphub's ggsn ctrl */
1618 "0004""7f000202" /* replaced with gtphub's ggsn user */
1619 );
1620
1621 OSMO_ASSERT(msg_from_sgsn_c(&sgsn_sender,
1622 &resolved_ggsn_addr,
1623 gtp_req_from_sgsn1,
1624 gtp_req_to_ggsn1));
1625
1626 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001627 "TEI=1:"
1628 " 192.168.42.23 (TEI C=321 U=123)"
1629 " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)"
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001630 " @21945\n"));
1631
1632 now ++;
1633
1634 const char *gtp_req_from_sgsn2 =
1635 MSG_PDP_CTX_REQ("0068",
1636 "abce",
1637 "60",
1638 "42000121436588f9",
1639 "00000124",
1640 "00000322",
1641 "0009""08696e7465726e6574", /* "(8)internet" */
1642 "0004""c0a82a17", /* same as default sgsn_sender */
1643 "0004""c0a82a17"
1644 );
1645 const char *gtp_req_to_ggsn2 =
1646 MSG_PDP_CTX_REQ("0068",
1647 "6d32", /* mapped seq ("abce") */
1648 "23",
1649 "42000121436588f9",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001650 "00000002", /* mapped TEI Data I ("124") */
1651 "00000002", /* mapped TEI Control ("322") */
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001652 "0009""08696e7465726e6574",
1653 "0004""7f000201", /* replaced with gtphub's ggsn ctrl */
1654 "0004""7f000202" /* replaced with gtphub's ggsn user */
1655 );
1656
1657 OSMO_ASSERT(msg_from_sgsn_c(&sgsn_sender,
1658 &resolved_ggsn_addr,
1659 gtp_req_from_sgsn2,
1660 gtp_req_to_ggsn2));
1661
1662 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001663 "TEI=2:"
1664 " 192.168.42.23 (TEI C=322 U=124)"
1665 " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)"
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001666 " @21946\n"
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001667 "TEI=1:"
1668 " 192.168.42.23 (TEI C=321 U=123)"
1669 " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)"
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001670 " @21945\n"
1671 ));
1672
1673 now ++;
1674
1675 const char *gtp_resp_from_ggsn1 =
1676 MSG_PDP_CTX_RSP("004e",
1677 "00000001", /* destination TEI (sent in req above) */
1678 "6d31", /* mapped seq */
1679 "01", /* restart */
1680 "00000567", /* TEI U */
1681 "00000765", /* TEI C */
1682 "0004""c0a82b22", /* GSN addresses */
1683 "0004""c0a82b22" /* (== resolved_ggsn_addr) */
1684 );
1685 const char *gtp_resp_to_sgsn1 =
1686 MSG_PDP_CTX_RSP("004e",
1687 "00000321", /* unmapped TEI ("001") */
1688 "abcd", /* unmapped seq ("6d31") */
1689 "23",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001690 "00000001", /* mapped TEI from GGSN ("567") */
1691 "00000001", /* mapped TEI from GGSN ("765") */
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001692 "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */
1693 "0004""7f000102" /* gtphub's address towards SGSNs (User) */
1694 );
1695
1696 OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr,
1697 &sgsn_sender,
1698 gtp_resp_from_ggsn1,
1699 gtp_resp_to_sgsn1));
1700
1701 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001702 "TEI=2:"
1703 " 192.168.42.23 (TEI C=322 U=124)"
1704 " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)"
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001705 " @21946\n"
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001706 "TEI=1:"
1707 " 192.168.42.23 (TEI C=321 U=123)"
1708 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001709 " @21947\n"
1710 ));
1711
1712 now ++;
1713
1714 const char *gtp_resp_from_ggsn2 =
1715 MSG_PDP_CTX_RSP("004e",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001716 "00000002", /* destination TEI (sent in req above) */
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001717 "6d32", /* mapped seq */
1718 "01", /* restart */
1719 "00000568", /* TEI U */
1720 "00000766", /* TEI C */
1721 "0004""c0a82b22", /* GSN addresses */
1722 "0004""c0a82b22" /* (== resolved_ggsn_addr) */
1723 );
1724 const char *gtp_resp_to_sgsn2 =
1725 MSG_PDP_CTX_RSP("004e",
1726 "00000322", /* unmapped TEI ("001") */
1727 "abce", /* unmapped seq ("6d31") */
1728 "23",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001729 "00000002", /* mapped TEI from GGSN ("567") */
1730 "00000002", /* mapped TEI from GGSN ("765") */
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001731 "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */
1732 "0004""7f000102" /* gtphub's address towards SGSNs (User) */
1733 );
1734
1735 OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr,
1736 &sgsn_sender,
1737 gtp_resp_from_ggsn2,
1738 gtp_resp_to_sgsn2));
1739
1740 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001741 "TEI=2:"
1742 " 192.168.42.23 (TEI C=322 U=124)"
1743 " <-> 192.168.43.34 (TEI C=766 U=568)"
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001744 " @21948\n"
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001745 "TEI=1:"
1746 " 192.168.42.23 (TEI C=321 U=123)"
1747 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001748 " @21947\n"
1749 ));
1750
1751 OSMO_ASSERT(clear_test_hub());
1752}
1753
Neels Hofmeyre921e322015-11-11 00:45:50 +01001754
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001755static struct log_info_cat gtphub_categories[] = {
1756 [DGTPHUB] = {
1757 .name = "DGTPHUB",
1758 .description = "GTP Hub",
1759 .color = "\033[1;33m",
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001760 .enabled = 1, .loglevel = LOGL_DEBUG,
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001761 },
1762};
1763
1764static struct log_info info = {
1765 .cat = gtphub_categories,
1766 .num_cat = ARRAY_SIZE(gtphub_categories),
1767};
1768
1769int main(int argc, char **argv)
1770{
1771 osmo_init_logging(&info);
1772 osmo_gtphub_ctx = talloc_named_const(NULL, 0, "osmo_gtphub");
1773
1774 test_nr_map_basic();
Neels Hofmeyre2ed8e62015-11-17 14:30:37 +01001775 test_nr_map_wrap();
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001776 test_expiry();
1777 test_echo();
Neels Hofmeyr75599102015-12-01 01:01:16 +01001778 test_one_pdp_ctx(GTPH_SIDE_SGSN);
1779 test_one_pdp_ctx(GTPH_SIDE_GGSN);
Neels Hofmeyre921e322015-11-11 00:45:50 +01001780 test_user_data();
Neels Hofmeyrbe4beba2015-12-02 14:18:26 +01001781 test_reused_tei();
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001782 test_peer_restarted();
1783 test_peer_restarted_reusing_tei();
Neels Hofmeyrf8c70102015-12-03 14:29:48 +01001784 test_sgsn_behind_nat();
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001785 test_parallel_context_creation();
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001786 printf("Done\n");
1787
1788 talloc_report_full(osmo_gtphub_ctx, stderr);
1789 OSMO_ASSERT(talloc_total_blocks(osmo_gtphub_ctx) == 1);
1790 return 0;
1791}
1792