blob: 7d7673bc812a6e4682400312f04662152269a693 [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
59/* TODO copied from libosmo-abis/src/subchan_demux.c, remove dup */
60static int llist_len(struct llist_head *head)
61{
62 struct llist_head *entry;
63 int i = 0;
64
65 llist_for_each(entry, head)
66 i++;
67
68 return i;
69}
70
71static void nr_mapping_free(struct expiring_item *e)
72{
73 struct nr_mapping *m = container_of(e, struct nr_mapping,
74 expiry_entry);
75 nr_mapping_del(m);
76 talloc_free(m);
77}
78
79static struct nr_mapping *nr_mapping_alloc(void)
80{
81 struct nr_mapping *m;
82 m = talloc(osmo_gtphub_ctx, struct nr_mapping);
83 nr_mapping_init(m);
84 m->expiry_entry.del_cb = nr_mapping_free;
85 return m;
86}
87
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +010088static struct nr_mapping *nr_map_have(struct nr_map *map, void *origin,
89 nr_t orig, time_t now)
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +020090{
91 struct nr_mapping *mapping;
92
93 mapping = nr_map_get(map, origin, orig);
94 if (!mapping) {
95 mapping = nr_mapping_alloc();
96 mapping->origin = origin;
97 mapping->orig = orig;
98 nr_map_add(map, mapping, now);
99 }
100
101 return mapping;
102}
103
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100104static nr_t nr_map_verify(const struct nr_map *map, void *origin, nr_t orig,
105 nr_t expect_repl)
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200106{
107 struct nr_mapping *m;
108 m = nr_map_get(map, origin, orig);
109
110 if (!m) {
111 printf("mapping not found for %p %d\n", origin, orig);
112 return 0;
113 }
114
115 if (m->repl != expect_repl) {
116 printf("mapping found, but nr mismatches: expect %d, got %d\n",
117 (int)expect_repl, (int)m->repl);
118 return 0;
119 }
120
121 return 1;
122}
123
124static int nr_map_verify_inv(const struct nr_map *map, nr_t repl,
125 void *expect_origin, nr_t expect_orig)
126{
127 struct nr_mapping *m;
128 m = nr_map_get_inv(map, repl);
129 if (!m) {
130 printf("mapping not found for %d\n", (int)repl);
131 return 0;
132 }
133
134 if (m->origin != expect_origin) {
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100135 printf("mapping found, but origin mismatches:"
136 " expect %p, got %p\n",
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200137 expect_origin, m->origin);
138 return 0;
139 }
140
141 if (m->orig != expect_orig) {
142 printf("mapping found, but nr mismatches: expect %d, got %d\n",
143 (int)expect_orig, (int)m->orig);
144 return 0;
145 }
146
147 return 1;
148}
149
150
151static void test_nr_map_basic(void)
152{
153 struct nr_pool _pool;
154 struct nr_pool *pool = &_pool;
155 struct nr_map _map;
156 struct nr_map *map = &_map;
157
Neels Hofmeyre2ed8e62015-11-17 14:30:37 +0100158 nr_pool_init(pool, 1, 1000);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200159 nr_map_init(map, pool, NULL);
160
161 OSMO_ASSERT(llist_empty(&map->mappings));
162
163#define TEST_N_HALF 100
164#define TEST_N (2*TEST_N_HALF)
165#define TEST_I 123
166 uint32_t i, check_i;
167 uint32_t m[TEST_N];
168 struct nr_mapping *mapping;
169
170 /* create half of TEST_N mappings from one origin */
171 void *origin1 = (void*)0x1234;
172 for (i = 0; i < TEST_N_HALF; i++) {
173 nr_t orig = TEST_I + i;
174 mapping = nr_map_have(map, origin1, orig, 0);
175 m[i] = mapping->repl;
176 OSMO_ASSERT(m[i] != 0);
177 OSMO_ASSERT(llist_len(&map->mappings) == (i+1));
178 for (check_i = 0; check_i < i; check_i++)
179 OSMO_ASSERT(m[check_i] != m[i]);
180 }
181 OSMO_ASSERT(llist_len(&map->mappings) == TEST_N_HALF);
182
183 /* create another TEST_N mappings with the same original numbers, but
184 * from a different origin */
185 void *origin2 = (void*)0x5678;
186 for (i = 0; i < TEST_N_HALF; i++) {
187 int i2 = TEST_N_HALF + i;
188 nr_t orig = TEST_I + i;
189 mapping = nr_map_have(map, origin2, orig, 0);
190 m[i2] = mapping->repl;
191 OSMO_ASSERT(m[i2] != 0);
192 OSMO_ASSERT(llist_len(&map->mappings) == (i2+1));
193 for (check_i = 0; check_i < i2; check_i++)
194 OSMO_ASSERT(m[check_i] != m[i2]);
195 }
196 OSMO_ASSERT(llist_len(&map->mappings) == TEST_N);
197
198 /* verify mappings */
199 for (i = 0; i < TEST_N_HALF; i++) {
200 nr_t orig = TEST_I + i;
201 {
202 OSMO_ASSERT(nr_map_verify(map, origin1, orig, m[i]));
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100203 OSMO_ASSERT(nr_map_verify_inv(map, m[i], origin1,
204 orig));
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200205 }
206 {
207 int i2 = TEST_N_HALF + i;
208 OSMO_ASSERT(nr_map_verify(map, origin2, orig, m[i2]));
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100209 OSMO_ASSERT(nr_map_verify_inv(map, m[i2], origin2,
210 orig));
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200211 }
212 }
213
214 /* remove all mappings */
215 for (i = 0; i < TEST_N_HALF; i++) {
216 OSMO_ASSERT(llist_len(&map->mappings) == (TEST_N - 2*i));
217
218 nr_t orig = TEST_I + i;
219 nr_mapping_del(nr_map_get(map, origin1, orig));
220 nr_mapping_del(nr_map_get(map, origin2, orig));
221 }
222 OSMO_ASSERT(llist_empty(&map->mappings));
223#undef TEST_N
224#undef TEST_I
225}
226
227static int nr_map_is(struct nr_map *map, const char *str)
228{
229 static char buf[4096];
230 char *pos = buf;
231 size_t len = sizeof(buf);
232 struct nr_mapping *m;
233 llist_for_each_entry(m, &map->mappings, entry) {
Neels Hofmeyr334af5d2015-11-17 14:24:46 +0100234 size_t wrote = snprintf(pos, len, "(%u->%u@%d), ",
235 m->orig,
236 m->repl,
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200237 (int)m->expiry_entry.expiry);
238 OSMO_ASSERT(wrote < len);
239 pos += wrote;
240 len -= wrote;
241 }
242 *pos = '\0';
243
244 if (strncmp(buf, str, sizeof(buf)) != 0) {
245 printf("FAILURE: nr_map_is() mismatches expected value:\n"
246 "expected: \"%s\"\n"
247 "is: \"%s\"\n",
248 str, buf);
249 return 0;
250 }
251 return 1;
252}
253
Neels Hofmeyre2ed8e62015-11-17 14:30:37 +0100254static int test_nr_map_wrap_with(nr_t nr_min, nr_t nr_max, nr_t repl_last,
255 nr_t orig_start, int orig_n,
256 const char *expect)
257{
258 struct nr_pool _pool;
259 struct nr_pool *pool = &_pool;
260 struct nr_map _map;
261 struct nr_map *map = &_map;
262
263 nr_pool_init(pool, nr_min, nr_max);
264 nr_map_init(map, pool, NULL);
265
266 pool->last_nr = repl_last;
267
268 void *origin = (void*)0x1234;
269
270 int i;
271 for (i = 0; i < orig_n; i++)
272 LVL2_ASSERT(nr_map_have(map, origin, orig_start + i, 0));
273
274 LVL2_ASSERT(nr_map_is(map, expect));
275
276 nr_map_clear(map);
277 return 1;
278}
279
280static void test_nr_map_wrap(void)
281{
282 OSMO_ASSERT(test_nr_map_wrap_with(
283 0, UINT_MAX, UINT_MAX - 2,
284 1, 5,
285 "(1->4294967294@0), "
286 "(2->4294967295@0), "
287 "(3->0@0), "
288 "(4->1@0), "
289 "(5->2@0), "
290 ));
291 OSMO_ASSERT(test_nr_map_wrap_with(
292 5, 10, 8,
293 1, 5,
294 "(1->9@0), (2->10@0), (3->5@0), (4->6@0), (5->7@0), "
295 ));
296}
297
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200298static void test_expiry(void)
299{
300 struct expiry expiry;
301 struct nr_pool pool;
302 struct nr_map map;
303 int i;
304
305 expiry_init(&expiry, 30);
Neels Hofmeyre2ed8e62015-11-17 14:30:37 +0100306 nr_pool_init(&pool, 1, 1000);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200307 nr_map_init(&map, &pool, &expiry);
308 OSMO_ASSERT(nr_map_is(&map, ""));
309
310 /* tick on empty map */
311 OSMO_ASSERT(expiry_tick(&expiry, 10000) == 0);
312 OSMO_ASSERT(nr_map_is(&map, ""));
313
314#define MAP1 \
315 "(10->1@10040), " \
316 ""
317
318#define MAP2 \
319 "(20->2@10050), " \
320 "(21->3@10051), " \
321 "(22->4@10052), " \
322 "(23->5@10053), " \
323 "(24->6@10054), " \
324 "(25->7@10055), " \
325 "(26->8@10056), " \
326 "(27->9@10057), " \
327 ""
328
329#define MAP3 \
330 "(420->10@10072), " \
331 "(421->11@10072), " \
332 "(422->12@10072), " \
333 "(423->13@10072), " \
334 "(424->14@10072), " \
335 "(425->15@10072), " \
336 "(426->16@10072), " \
337 "(427->17@10072), " \
338 ""
339
340 /* add mapping at time 10010. */
341 nr_map_have(&map, 0, 10, 10010);
342 OSMO_ASSERT(nr_map_is(&map, MAP1));
343
344 /* tick on unexpired item. */
345 OSMO_ASSERT(expiry_tick(&expiry, 10010) == 0);
346 OSMO_ASSERT(expiry_tick(&expiry, 10011) == 0);
347 OSMO_ASSERT(nr_map_is(&map, MAP1));
348
349 /* Spread mappings at 10020, 10021, ... 10027. */
350 for (i = 0; i < 8; i++)
351 nr_map_have(&map, 0, 20 + i, 10020 + i);
352 OSMO_ASSERT(nr_map_is(&map, MAP1 MAP2));
353
354 /* tick on unexpired items. */
355 OSMO_ASSERT(expiry_tick(&expiry, 10030) == 0);
356 OSMO_ASSERT(expiry_tick(&expiry, 10039) == 0);
357 OSMO_ASSERT(nr_map_is(&map, MAP1 MAP2));
358
359 /* expire the first item (from 10010). */
360 OSMO_ASSERT(expiry_tick(&expiry, 10010 + 30) == 1);
361 OSMO_ASSERT(nr_map_is(&map, MAP2));
362
363 /* again nothing to expire */
364 OSMO_ASSERT(expiry_tick(&expiry, 10041) == 0);
365 OSMO_ASSERT(nr_map_is(&map, MAP2));
366
367 /* Mappings all at the same time. */
368 for (i = 0; i < 8; i++)
369 nr_map_have(&map, 0, 420 + i, 10042);
370 OSMO_ASSERT(nr_map_is(&map, MAP2 MAP3));
371
372 /* Eight to expire, were added further above to be chronologically
373 * correct, at 10020..10027. */
374 OSMO_ASSERT(expiry_tick(&expiry, 10027 + 30) == 8);
375 OSMO_ASSERT(nr_map_is(&map, MAP3));
376
377 /* again nothing to expire */
378 OSMO_ASSERT(expiry_tick(&expiry, 10027 + 30) == 0);
379 OSMO_ASSERT(nr_map_is(&map, MAP3));
380
381 /* Eight to expire, from 10042. Now at 10042 + 30: */
382 OSMO_ASSERT(expiry_tick(&expiry, 10042 + 30) == 8);
383 OSMO_ASSERT(nr_map_is(&map, ""));
384
385#undef MAP1
386#undef MAP2
387#undef MAP3
388}
389
Harald Welted3fa84d2016-04-20 17:50:17 +0200390char resolve_ggsn_got_imsi[GSM23003_IMSI_MAX_DIGITS+1];
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100391char resolve_ggsn_got_ni[GSM_APN_LENGTH];
392
393struct osmo_sockaddr resolved_ggsn_addr;
394static int resolve_to_ggsn(const char *addr, uint16_t port)
395{
396 LVL2_ASSERT(osmo_sockaddr_init_udp(&resolved_ggsn_addr,
397 addr, port)
398 == 0);
399 return 1;
400}
401
Neels Hofmeyre921e322015-11-11 00:45:50 +0100402struct osmo_sockaddr resolved_sgsn_addr;
403static int resolve_to_sgsn(const char *addr, uint16_t port)
404{
405 LVL2_ASSERT(osmo_sockaddr_init_udp(&resolved_sgsn_addr,
406 addr, port)
407 == 0);
408 return 1;
409}
410
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100411struct osmo_sockaddr sgsn_sender;
412static int send_from_sgsn(const char *addr, uint16_t port)
413{
414 LVL2_ASSERT(osmo_sockaddr_init_udp(&sgsn_sender,
415 addr, port)
416 == 0);
417 return 1;
418}
419
Neels Hofmeyre921e322015-11-11 00:45:50 +0100420struct osmo_sockaddr ggsn_sender;
421static int send_from_ggsn(const char *addr, uint16_t port)
422{
423 LVL2_ASSERT(osmo_sockaddr_init_udp(&ggsn_sender,
424 addr, port)
425 == 0);
426 return 1;
427}
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200428
429
430/* override, requires '-Wl,--wrap=gtphub_resolve_ggsn_addr' */
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100431struct gtphub_peer_port *__real_gtphub_resolve_ggsn_addr(struct gtphub *hub,
432 const char *imsi_str,
433 const char *apn_ni_str);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200434
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100435struct gtphub_peer_port *__wrap_gtphub_resolve_ggsn_addr(struct gtphub *hub,
436 const char *imsi_str,
437 const char *apn_ni_str)
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200438{
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100439 struct gsn_addr resolved_gsna;
440 uint16_t resolved_port;
441
442 OSMO_ASSERT(gsn_addr_from_sockaddr(&resolved_gsna, &resolved_port,
443 &resolved_ggsn_addr) == 0);
444
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100445 struct gtphub_peer_port *pp;
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100446 pp = gtphub_port_have(hub, &hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL],
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100447 &resolved_gsna, resolved_port);
Neels Hofmeyre921e322015-11-11 00:45:50 +0100448 printf("- __wrap_gtphub_resolve_ggsn_addr():\n"
449 " returning GGSN addr from imsi %s ni %s: %s\n",
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100450 imsi_str, apn_ni_str, gtphub_port_str(pp));
451
452 if (imsi_str) {
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100453 strncpy(resolve_ggsn_got_imsi, imsi_str,
454 sizeof(resolve_ggsn_got_imsi));
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100455 resolve_ggsn_got_imsi[sizeof(resolve_ggsn_got_imsi) - 1] = '\0';
456 }
457 else
458 strcpy(resolve_ggsn_got_imsi, "(null)");
459
460 if (apn_ni_str) {
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100461 strncpy(resolve_ggsn_got_ni, apn_ni_str,
462 sizeof(resolve_ggsn_got_ni));
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100463 resolve_ggsn_got_ni[sizeof(resolve_ggsn_got_ni) - 1] = '\0';
464 }
465 else
466 strcpy(resolve_ggsn_got_ni, "(null)");
467
468 return pp;
469}
470
471#define was_resolved_for(IMSI,NI) _was_resolved_for(IMSI, NI, __FILE__, __LINE__)
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100472static int _was_resolved_for(const char *imsi, const char *ni, const char
473 *file, int line)
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100474{
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100475 int cmp0 = strncmp(imsi, resolve_ggsn_got_imsi,
476 sizeof(resolve_ggsn_got_imsi));
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100477
478 if (cmp0 != 0) {
479 printf("\n%s:%d: was_resolved_for(): MISMATCH for IMSI\n"
480 " expecting: '%s'\n"
481 " got: '%s'\n\n",
482 file,
483 line,
484 imsi, resolve_ggsn_got_imsi);
485 }
486
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100487 int cmp1 = strncmp(ni, resolve_ggsn_got_ni,
488 sizeof(resolve_ggsn_got_ni));
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100489 if (cmp1 != 0) {
490 printf("\n%s:%d: was_resolved_for(): MISMATCH for NI\n"
491 " expecting: '%s'\n"
492 " got: '%s'\n\n",
493 file,
494 line,
495 ni, resolve_ggsn_got_ni);
496 }
497
498 return (cmp0 == 0) && (cmp1 == 0);
499}
500
501/* override, requires '-Wl,--wrap=gtphub_ares_init' */
502int __real_gtphub_ares_init(struct gtphub *hub);
503
504int __wrap_gtphub_ares_init(struct gtphub *hub)
505{
506 /* Do nothing. */
507 return 0;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200508}
509
Neels Hofmeyr996ec1d2015-12-02 15:43:10 +0100510/* override, requires '-Wl,--wrap=gtphub_write' */
511int __real_gtphub_write(const struct osmo_fd *to,
512 const struct osmo_sockaddr *to_addr,
513 const uint8_t *buf, size_t buf_len);
514
515int __wrap_gtphub_write(const struct osmo_fd *to,
516 const struct osmo_sockaddr *to_addr,
517 const uint8_t *buf, size_t buf_len)
518{
519 printf("Out-of-band gtphub_write(%d):\n"
520 "to %s\n"
521 "%s\n",
522 (int)buf_len,
523 osmo_sockaddr_to_str(to_addr),
524 osmo_hexdump(buf, buf_len));
525 return 0;
526}
527
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200528#define buf_len 1024
529static uint8_t buf[buf_len];
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100530static uint8_t *reply_buf;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200531
532static unsigned int msg(const char *hex)
533{
534 unsigned int l = osmo_hexparse(hex, buf, buf_len);
535 OSMO_ASSERT(l > 0);
536 return l;
537}
538
539/* Compare static buf to given string constant. The amount of bytes is obtained
540 * from parsing the GTP header in buf. hex must match an osmo_hexdump() of the
541 * desired message. Return 1 if size and content match. */
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100542#define reply_is(MSG) _reply_is(MSG, __FILE__, __LINE__)
543static int _reply_is(const char *hex, const char *file, int line)
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200544{
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100545 struct gtp1_header_long *h = (void*)reply_buf;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200546 int len = ntoh16(h->length) + 8;
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100547 const char *dump = osmo_hexdump_nospc(reply_buf, len);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200548 int cmp = strcmp(dump, hex);
549
550 if (cmp != 0) {
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100551 printf("\n%s:%d: reply_is(): MISMATCH\n"
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200552 " expecting:\n'%s'\n"
553 " got:\n'%s'\n\n",
554 file,
555 line,
556 hex, dump);
557 int i;
558 int l = strlen(hex);
559 int m = strlen(dump);
560 if (m < l)
561 l = m;
562 for (i = 0; i < l; i++) {
563 if (hex[i] != dump[i]) {
564 printf("First mismatch at position %d:\n"
565 " %s\n %s\n", i, hex + i, dump + i);
566 break;
567 }
568 }
569 }
570 return cmp == 0;
571}
572
573#define same_addr(GOT, EXPECTED) _same_addr((GOT),(EXPECTED), __FILE__, __LINE__)
574static int _same_addr(const struct osmo_sockaddr *got,
575 const struct osmo_sockaddr *expected,
576 const char *file, int line)
577{
578 int cmp = osmo_sockaddr_cmp(got, expected);
579 if (!cmp)
580 return 1;
581 char buf[256];
582 printf("\n%s:%d: addr_is(): MISMATCH\n"
583 " expecting: '%s'\n"
584 " got: '%s'\n\n",
585 file, line,
586 osmo_sockaddr_to_str(expected),
587 osmo_sockaddr_to_strb(got, buf, sizeof(buf)));
588 return 0;
589}
590
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100591
592time_t now;
593static struct gtphub _hub;
594static struct gtphub *hub = &_hub;
595
596static int setup_test_hub()
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200597{
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100598 /* Not really needed, but to make 100% sure... */
599 ZERO_STRUCT(hub);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200600
601 gtphub_init(hub);
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100602
603 /* Tell this mock gtphub its local address for this test. */
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100604 LVL2_ASSERT(gsn_addr_from_str(&hub->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_CTRL].local_addr,
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100605 "127.0.1.1") == 0);
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100606 LVL2_ASSERT(gsn_addr_from_str(&hub->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_USER].local_addr,
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100607 "127.0.1.2") == 0);
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100608 LVL2_ASSERT(gsn_addr_from_str(&hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL].local_addr,
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100609 "127.0.2.1") == 0);
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100610 LVL2_ASSERT(gsn_addr_from_str(&hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_USER].local_addr,
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100611 "127.0.2.2") == 0);
612
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100613 hub->restart_counter = 0x23;
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100614 now = 345;
615 LVL2_ASSERT(send_from_sgsn("192.168.42.23", 423));
Neels Hofmeyre921e322015-11-11 00:45:50 +0100616 LVL2_ASSERT(resolve_to_ggsn("192.168.43.34", 2123));
Neels Hofmeyre54cd152015-11-24 13:31:06 +0100617 LVL2_ASSERT(send_from_ggsn("192.168.43.34", 434));
Neels Hofmeyre921e322015-11-11 00:45:50 +0100618 LVL2_ASSERT(resolve_to_sgsn("192.168.42.23", 2123));
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100619
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100620#define GGSNS_CTRL_FD 1
621#define GGSNS_USER_FD 2
622#define SGSNS_CTRL_FD 3
623#define SGSNS_USER_FD 4
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100624 hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL].ofd.priv_nr = GGSNS_CTRL_FD;
625 hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_USER].ofd.priv_nr = GGSNS_USER_FD;
626 hub->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_CTRL].ofd.priv_nr = SGSNS_CTRL_FD;
627 hub->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_USER].ofd.priv_nr = SGSNS_USER_FD;
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100628
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100629 return 1;
630}
631
Neels Hofmeyr20bd6bf2015-11-20 00:08:28 +0100632static int clear_test_hub()
633{
634 /* expire all */
Neels Hofmeyre54cd152015-11-24 13:31:06 +0100635 gtphub_gc(hub, now + (60 * GTPH_EXPIRE_SLOWLY_MINUTES) + 1);
Neels Hofmeyr20bd6bf2015-11-20 00:08:28 +0100636
637 int plane_idx;
638 plane_idx = GTPH_PLANE_CTRL;
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100639 LVL2_ASSERT(llist_empty(&hub->to_gsns[GTPH_SIDE_GGSN][plane_idx].peers));
640 LVL2_ASSERT(llist_empty(&hub->to_gsns[GTPH_SIDE_SGSN][plane_idx].peers));
Neels Hofmeyr20bd6bf2015-11-20 00:08:28 +0100641 plane_idx = GTPH_PLANE_USER;
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100642 LVL2_ASSERT(llist_empty(&hub->to_gsns[GTPH_SIDE_GGSN][plane_idx].peers));
643 LVL2_ASSERT(llist_empty(&hub->to_gsns[GTPH_SIDE_SGSN][plane_idx].peers));
Neels Hofmeyr20bd6bf2015-11-20 00:08:28 +0100644
Neels Hofmeyr99a50b32015-12-02 01:15:30 +0100645 LVL2_ASSERT(llist_empty(&hub->tunnels));
646 LVL2_ASSERT(llist_empty(&hub->pending_deletes));
647 LVL2_ASSERT(llist_empty(&hub->ggsn_lookups));
648 LVL2_ASSERT(llist_empty(&hub->resolved_ggsns));
649
Neels Hofmeyr20bd6bf2015-11-20 00:08:28 +0100650 gtphub_free(hub);
651 return 1;
652}
653
Neels Hofmeyre54cd152015-11-24 13:31:06 +0100654static int tunnels_are(const char *expect)
655{
656 static char buf[4096];
657 char *pos = buf;
658 size_t len = sizeof(buf);
659 struct gtphub_tunnel *t;
660 llist_for_each_entry(t, &hub->tunnels, entry) {
661 size_t wrote = snprintf(pos, len, "%s @%d\n",
662 gtphub_tunnel_str(t),
663 (int)t->expiry_entry.expiry);
664 LVL2_ASSERT(wrote < len);
665 pos += wrote;
666 len -= wrote;
667 }
668 *pos = '\0';
669
670 if (strncmp(buf, expect, sizeof(buf)) != 0) {
671 fprintf(stderr, "FAILURE: tunnels_are() mismatches expected value:\n"
672 "EXPECTED:\n%s\n"
673 "IS:\n%s\n",
674 expect, buf);
675 LVL2_ASSERT("tunnels do not match expected listing.");
676 return 0;
677 }
678 return 1;
679}
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100680
681static void test_echo(void)
682{
Neels Hofmeyre921e322015-11-11 00:45:50 +0100683 LOG("test_echo");
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100684 OSMO_ASSERT(setup_test_hub());
685
686 now = 123;
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100687
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100688 struct osmo_fd *to_ofd;
689 struct osmo_sockaddr to_addr;
690 struct gtphub_peer_port *pp;
691 int send;
692
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200693 const char *gtp_ping_from_sgsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100694 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200695 "01" /* type 01: Echo request */
696 "0004" /* length of 4 after header TEI */
697 "00000000" /* header TEI == 0 in Echo */
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100698 "abcd" /* some 2 octet sequence nr */
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200699 "0000" /* N-PDU 0, no extension header (why is this here?) */
700 ;
701
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100702 const char *gtp_pong_to_sgsn =
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200703 "32"
704 "02" /* type 02: Echo response */
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100705 "0006" /* length of 6 after header TEI */
706 "00000000" /* header TEI == 0 in Echo */
707 "abcd" /* same sequence nr */
708 "0000"
709 "0e23" /* Recovery with restart counter */
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200710 ;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200711
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100712 to_ofd = NULL;
713 ZERO_STRUCT(&to_addr);
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100714 send = gtphub_handle_buf(hub, GTPH_SIDE_SGSN, GTPH_PLANE_CTRL,
715 &sgsn_sender, buf, msg(gtp_ping_from_sgsn),
716 now, &reply_buf, &to_ofd, &to_addr);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200717 OSMO_ASSERT(send > 0);
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100718 OSMO_ASSERT(to_addr.l);
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100719 OSMO_ASSERT(same_addr(&to_addr, &sgsn_sender));
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100720 OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == SGSNS_CTRL_FD));
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100721 OSMO_ASSERT(reply_is(gtp_pong_to_sgsn));
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200722
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100723 pp = gtphub_port_find_sa(&hub->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_CTRL],
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100724 &sgsn_sender);
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100725 /* We don't record Echo peers. */
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100726 OSMO_ASSERT(!pp);
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100727
728 const char *gtp_ping_from_ggsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100729 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100730 "01" /* type 01: Echo request */
731 "0004" /* length of 4 after header TEI */
732 "00000000" /* header TEI == 0 in Echo */
733 "cdef" /* some 2 octet sequence nr */
734 "0000" /* N-PDU 0, no extension header (why is this here?) */
735 ;
736
737 const char *gtp_pong_to_ggsn =
738 "32"
739 "02" /* type 02: Echo response */
740 "0006" /* length of 6 after header TEI */
741 "00000000" /* header TEI == 0 in Echo */
742 "cdef" /* same sequence nr */
743 "0000"
744 "0e23" /* Recovery with restart counter */
745 ;
746
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100747 to_ofd = NULL;
748 ZERO_STRUCT(&to_addr);
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100749 send = gtphub_handle_buf(hub, GTPH_SIDE_GGSN, GTPH_PLANE_CTRL,
750 &ggsn_sender, buf, msg(gtp_ping_from_ggsn),
751 now, &reply_buf, &to_ofd, &to_addr);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200752 OSMO_ASSERT(send > 0);
Neels Hofmeyre921e322015-11-11 00:45:50 +0100753 OSMO_ASSERT(same_addr(&to_addr, &ggsn_sender));
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100754 OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == GGSNS_CTRL_FD));
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100755 OSMO_ASSERT(reply_is(gtp_pong_to_ggsn));
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200756
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100757 pp = gtphub_port_find_sa(&hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL],
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100758 &sgsn_sender);
759 OSMO_ASSERT(!pp);
760
761
762 /* And all the same on the user plane. */
763
764 to_ofd = NULL;
765 ZERO_STRUCT(&to_addr);
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100766 send = gtphub_handle_buf(hub, GTPH_SIDE_SGSN, GTPH_PLANE_USER,
767 &sgsn_sender, buf, msg(gtp_ping_from_sgsn),
768 now, &reply_buf, &to_ofd, &to_addr);
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100769 OSMO_ASSERT(send > 0);
770 OSMO_ASSERT(to_addr.l);
771 OSMO_ASSERT(same_addr(&to_addr, &sgsn_sender));
772 OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == SGSNS_USER_FD));
773 OSMO_ASSERT(reply_is(gtp_pong_to_sgsn));
774
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100775 pp = gtphub_port_find_sa(&hub->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_USER],
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100776 &sgsn_sender);
777 OSMO_ASSERT(!pp);
778
779 to_ofd = NULL;
780 ZERO_STRUCT(&to_addr);
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100781 send = gtphub_handle_buf(hub, GTPH_SIDE_GGSN, GTPH_PLANE_USER,
782 &ggsn_sender, buf, msg(gtp_ping_from_ggsn),
783 now, &reply_buf, &to_ofd, &to_addr);
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100784 OSMO_ASSERT(send > 0);
785 OSMO_ASSERT(same_addr(&to_addr, &ggsn_sender));
786 OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == GGSNS_USER_FD));
787 OSMO_ASSERT(reply_is(gtp_pong_to_ggsn));
788
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100789 pp = gtphub_port_find_sa(&hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_USER],
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100790 &sgsn_sender);
791 OSMO_ASSERT(!pp);
792
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200793
Neels Hofmeyr20bd6bf2015-11-20 00:08:28 +0100794 OSMO_ASSERT(clear_test_hub());
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100795}
796
797
798#define MSG_PDP_CTX_REQ(len, seq, restart, imsi, tei_u, tei_c, apn, gsn_c, gsn_u) \
799 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr. */ \
800 "10" /* type 16: Create PDP Context Request */ \
801 len /* msg length = 8 + len (2 octets) */ \
802 "00000000" /* No TEI yet */ \
803 seq /* Sequence nr (2 octets) */ \
804 "00" /* N-PDU 0 */ \
805 "00" /* No extensions */ \
806 /* IEs */ \
Neels Hofmeyrba9e9f62015-11-26 22:19:22 +0100807 "0e" restart /* 14: Recovery (restart counter: 1 octet) */ \
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100808 "02" /* 2 = IMSI */ \
809 imsi /* (8 octets) */ \
810 "0f01" /* 15: Selection mode = MS provided APN, subscription not verified*/ \
811 "10" /* 16: TEI Data I */ \
812 tei_u /* (4 octets) */ \
813 "11" /* 17: TEI Control Plane */ \
814 tei_c /* (4 octets) */ \
815 "1400" /* 20: NSAPI = 0*/ \
816 "1a" /* 26: Charging Characteristics */ \
817 "0800" \
818 "80" /* 128: End User Address */ \
819 "0002" /* length = 2: empty PDP Address */ \
820 "f121" /* spare 0xf0, PDP organization 1, PDP type number 0x21 = 33 */ \
821 "83" /* 131: Access Point Name */ \
822 apn /* (2 octets length, N octets encoded APN-NI) */ \
823 "84" /* 132: Protocol Configuration Options */ \
824 "0015" /* length = 21 */ \
825 "80c0231101010011036d69670868656d6d656c6967" \
826 "85" /* 133: GSN Address */ \
827 gsn_c /* (2 octets length, N octets addr) */ \
828 "85" /* 133: GSN Address (second entry) */ \
829 gsn_u /* (2 octets length, N octets addr) */ \
830 "86" /* 134: MS International PSTN/ISDN Number (MSISDN) */ \
831 "0007" /* length */ \
832 "916407123254f6" /* 1946702123456(f) */ \
833 "87" /* 135: Quality of Service (QoS) Profile */ \
834 "0004" /* length */ \
835 "00" /* priority */ \
836 "0b921f" /* QoS profile data */
837
838#define MSG_PDP_CTX_RSP(len, tei_h, seq, restart, tei_u, tei_c, gsn_c, gsn_u) \
839 "32" \
840 "11" /* Create PDP Context Response */ \
841 len /* msg length = 8 + len (2 octets) */ \
842 tei_h /* destination TEI (sent in req above) */ \
843 seq /* mapped seq */ \
844 "00" "00" \
845 /* IEs */ \
846 "01" /* 1: Cause */ \
847 "80" /* value = 0b10000000 = response, no rejection. */ \
848 "08" /* 8: Reordering Required */ \
849 "00" /* not required. */ \
Neels Hofmeyrba9e9f62015-11-26 22:19:22 +0100850 "0e" restart /* 14: Recovery */ \
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100851 "10" /* 16: TEI Data I */ \
852 tei_u \
853 "11" /* 17: TEI Control */ \
854 tei_c \
855 "7f" /* 127: Charging ID */ \
856 "00000001" \
857 "80" /* 128: End User Address */ \
858 "0006" /* length = 6 */ \
859 "f121" /* spare 0xf0, PDP organization 1, PDP type number 0x21 = 33 */ \
860 "7f000002" \
861 "84" /* 132: Protocol Configuration Options */ \
862 "0014" /* len = 20 */ \
863 "8080211002000010810608080808830600000000" \
864 "85" /* 133: GSN Address (Ctrl) */ \
865 gsn_c \
866 "85" /* 133: GSN Address (User) */ \
867 gsn_u \
868 "87" /* 135: Quality of Service (QoS) Profile */ \
869 "0004" /* length */ \
870 "00" /* priority */ \
871 "0b921f" /* QoS profile data */
872
873#define msg_from_sgsn_c(A,B,C,D) msg_from_sgsn(GTPH_PLANE_CTRL, A,B,C,D)
874#define msg_from_sgsn_u(A,B,C,D) msg_from_sgsn(GTPH_PLANE_USER, A,B,C,D)
875static int msg_from_sgsn(int plane_idx,
876 struct osmo_sockaddr *_sgsn_sender,
877 struct osmo_sockaddr *ggsn_receiver,
878 const char *hex_from_sgsn,
879 const char *hex_to_ggsn)
880{
881 struct osmo_fd *ggsn_ofd = NULL;
882 struct osmo_sockaddr ggsn_addr;
883 int send;
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100884 send = gtphub_handle_buf(hub, GTPH_SIDE_SGSN, plane_idx, _sgsn_sender,
885 buf, msg(hex_from_sgsn), now,
886 &reply_buf, &ggsn_ofd, &ggsn_addr);
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100887 LVL2_ASSERT(send > 0);
888 LVL2_ASSERT(same_addr(&ggsn_addr, ggsn_receiver));
889 LVL2_ASSERT(reply_is(hex_to_ggsn));
890 return 1;
891}
892
893#define msg_from_ggsn_c(A,B,C,D) msg_from_ggsn(GTPH_PLANE_CTRL, A,B,C,D)
894#define msg_from_ggsn_u(A,B,C,D) msg_from_ggsn(GTPH_PLANE_USER, A,B,C,D)
895static int msg_from_ggsn(int plane_idx,
896 struct osmo_sockaddr *ggsn_sender,
897 struct osmo_sockaddr *sgsn_receiver,
898 const char *msg_from_ggsn,
899 const char *msg_to_sgsn)
900{
901 struct osmo_fd *sgsn_ofd;
902 struct osmo_sockaddr sgsn_addr;
903 int send;
Neels Hofmeyra9905a52015-11-29 23:49:48 +0100904 send = gtphub_handle_buf(hub, GTPH_SIDE_GGSN, plane_idx, ggsn_sender,
905 buf, msg(msg_from_ggsn), now,
906 &reply_buf, &sgsn_ofd, &sgsn_addr);
Neels Hofmeyrd010c492015-12-06 23:12:02 +0100907 if (*msg_to_sgsn) {
908 LVL2_ASSERT(send > 0);
909 LVL2_ASSERT(same_addr(&sgsn_addr, sgsn_receiver));
910 LVL2_ASSERT(reply_is(msg_to_sgsn));
911 }
912 else
913 LVL2_ASSERT(send == 0);
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100914 return 1;
915}
916
917static int create_pdp_ctx()
918{
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100919 const char *gtp_req_from_sgsn =
920 MSG_PDP_CTX_REQ("0068",
921 "abcd",
922 "60",
923 "42000121436587f9",
924 "00000123",
925 "00000321",
926 "0009""08696e7465726e6574", /* "(8)internet" */
927 "0004""c0a82a17", /* same as default sgsn_sender */
928 "0004""c0a82a17"
929 );
930 const char *gtp_req_to_ggsn =
931 MSG_PDP_CTX_REQ("0068",
932 "6d31", /* mapped seq ("abcd") */
Neels Hofmeyrba9e9f62015-11-26 22:19:22 +0100933 "23",
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100934 "42000121436587f9",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +0100935 "00000001", /* Data I: tunnel's TEI */
936 "00000001", /* Control: tunnel's TEI */
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100937 "0009""08696e7465726e6574",
938 "0004""7f000201", /* replaced with gtphub's ggsn ctrl */
939 "0004""7f000202" /* replaced with gtphub's ggsn user */
940 );
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100941
942 LVL2_ASSERT(msg_from_sgsn_c(&sgsn_sender,
943 &resolved_ggsn_addr,
944 gtp_req_from_sgsn,
945 gtp_req_to_ggsn));
946 LVL2_ASSERT(was_resolved_for("240010123456789", "internet"));
947
Neels Hofmeyre54cd152015-11-24 13:31:06 +0100948 LVL2_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +0100949 "TEI=1:"
950 " 192.168.42.23 (TEI C=321 U=123)"
951 " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)"
Neels Hofmeyre54cd152015-11-24 13:31:06 +0100952 " @21945\n"));
953
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100954 const char *gtp_resp_from_ggsn =
955 MSG_PDP_CTX_RSP("004e",
956 "00000001", /* destination TEI (sent in req above) */
957 "6d31", /* mapped seq */
958 "01", /* restart */
959 "00000567", /* TEI U */
960 "00000765", /* TEI C */
961 "0004""c0a82b22", /* GSN addresses */
962 "0004""c0a82b22" /* (== resolved_ggsn_addr) */
963 );
964 const char *gtp_resp_to_sgsn =
965 MSG_PDP_CTX_RSP("004e",
966 "00000321", /* unmapped TEI ("001") */
967 "abcd", /* unmapped seq ("6d31") */
Neels Hofmeyrba9e9f62015-11-26 22:19:22 +0100968 "23",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +0100969 "00000001", /* mapped TEI from GGSN ("567") */
970 "00000001", /* mapped TEI from GGSN ("765") */
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100971 "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */
972 "0004""7f000102" /* gtphub's address towards SGSNs (User) */
973 );
Neels Hofmeyre921e322015-11-11 00:45:50 +0100974 /* The response should go back to whichever port the request came from
975 * (unmapped by sequence nr) */
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100976 LVL2_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr,
977 &sgsn_sender,
978 gtp_resp_from_ggsn,
979 gtp_resp_to_sgsn));
980
981 return 1;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200982}
983
Neels Hofmeyr10fc0242015-12-01 00:23:45 +0100984#define MSG_DEL_PDP_CTX_REQ(tei, seq) \
985 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr. */ \
986 "14" /* type 20: Delete PDP Context Request */ \
987 "0008" /* 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 "13fe" /* 19: Teardown ind = 0 */ \
994 "1400" /* 20: NSAPI = 0*/ \
995
996#define MSG_DEL_PDP_CTX_RSP(tei, seq) \
997 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr. */ \
998 "15" /* type 21: Delete PDP Context Response */ \
999 "0006" /* msg length = 8 + len (2 octets) */ \
1000 tei /* TEI Ctrl */ \
1001 seq /* Sequence nr (2 octets) */ \
1002 "00" /* N-PDU 0 */ \
1003 "00" /* No extensions */ \
1004 /* IEs */ \
1005 "01" /* 1: Cause */ \
1006 "80" /* value = 0b10000000 = response, no rejection. */ \
1007
Neels Hofmeyr75599102015-12-01 01:01:16 +01001008static int delete_pdp_ctx_from_sgsn(void)
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001009{
Neels Hofmeyr10fc0242015-12-01 00:23:45 +01001010 now += GTPH_EXPIRE_QUICKLY_SECS + 1;
1011 gtphub_gc(hub, now);
1012
1013 LVL2_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001014 "TEI=1:"
1015 " 192.168.42.23 (TEI C=321 U=123)"
1016 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyr10fc0242015-12-01 00:23:45 +01001017 " @21945\n"));
1018
1019 /* TEI Ctrl from above and next sequence after abcd. */
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001020 const char *gtp_req_from_sgsn = MSG_DEL_PDP_CTX_REQ("00000001", "abce");
Neels Hofmeyr10fc0242015-12-01 00:23:45 +01001021 const char *gtp_req_to_ggsn = MSG_DEL_PDP_CTX_REQ("00000765", "6d32");
1022
1023 LVL2_ASSERT(msg_from_sgsn_c(&sgsn_sender,
1024 &resolved_ggsn_addr,
1025 gtp_req_from_sgsn,
1026 gtp_req_to_ggsn));
1027
1028 /* 21945 + 31 = 21976 */
1029 LVL2_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001030 "TEI=1:"
1031 " 192.168.42.23 (TEI C=321 U=123)"
1032 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyr10fc0242015-12-01 00:23:45 +01001033 " @21976\n"));
1034
1035 const char *gtp_resp_from_ggsn =
1036 MSG_DEL_PDP_CTX_RSP("00000001", "6d32");
1037 const char *gtp_resp_to_sgsn =
1038 MSG_DEL_PDP_CTX_RSP("00000321", "abce");
1039
1040 /* The response should go back to whichever port the request came from
1041 * (unmapped by sequence nr) */
1042 LVL2_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr,
1043 &sgsn_sender,
1044 gtp_resp_from_ggsn,
1045 gtp_resp_to_sgsn));
1046
1047 LVL2_ASSERT(tunnels_are(""));
1048
1049 return 1;
1050}
1051
Neels Hofmeyr75599102015-12-01 01:01:16 +01001052static int delete_pdp_ctx_from_ggsn(void)
Neels Hofmeyr10fc0242015-12-01 00:23:45 +01001053{
Neels Hofmeyr75599102015-12-01 01:01:16 +01001054 now += GTPH_EXPIRE_QUICKLY_SECS + 1;
1055 gtphub_gc(hub, now);
1056
1057 LVL2_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001058 "TEI=1:"
1059 " 192.168.42.23 (TEI C=321 U=123)"
1060 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyr75599102015-12-01 01:01:16 +01001061 " @21945\n"));
1062
1063 /* TEI Ctrl from above and next sequence after abcd. */
1064 const char *gtp_req_from_ggsn = MSG_DEL_PDP_CTX_REQ("00000001", "5432");
1065 const char *gtp_req_to_sgsn = MSG_DEL_PDP_CTX_REQ("00000321", "6d31");
1066
1067 LVL2_ASSERT(msg_from_ggsn_c(&ggsn_sender,
1068 &resolved_sgsn_addr,
1069 gtp_req_from_ggsn,
1070 gtp_req_to_sgsn));
1071
1072 /* 21945 + 31 = 21976 */
1073 LVL2_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001074 "TEI=1:"
1075 " 192.168.42.23 (TEI C=321 U=123)"
1076 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyr75599102015-12-01 01:01:16 +01001077 " @21976\n"));
1078
1079 const char *gtp_resp_from_sgsn =
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001080 MSG_DEL_PDP_CTX_RSP("00000001", "6d31");
Neels Hofmeyr75599102015-12-01 01:01:16 +01001081 const char *gtp_resp_to_ggsn =
1082 MSG_DEL_PDP_CTX_RSP("00000765", "5432");
1083
1084 /* The response should go back to whichever port the request came from
1085 * (unmapped by sequence nr) */
1086 LVL2_ASSERT(msg_from_sgsn_c(&resolved_sgsn_addr,
1087 &ggsn_sender,
1088 gtp_resp_from_sgsn,
1089 gtp_resp_to_ggsn));
1090
1091 LVL2_ASSERT(tunnels_are(""));
1092
1093 return 1;
1094}
1095
1096static void test_one_pdp_ctx(int del_from_side)
1097{
1098 if (del_from_side == GTPH_SIDE_SGSN)
1099 LOG("test_one_pdp_ctx (del from SGSN)")
1100 else LOG("test_one_pdp_ctx (del from GGSN)");
Neels Hofmeyrc2275942015-11-10 22:07:04 +01001101 OSMO_ASSERT(setup_test_hub());
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001102
Neels Hofmeyrc2275942015-11-10 22:07:04 +01001103 OSMO_ASSERT(create_pdp_ctx());
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001104
1105 struct gtphub_peer_port *ggsn_port =
Neels Hofmeyra9905a52015-11-29 23:49:48 +01001106 gtphub_port_find_sa(&hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL],
Neels Hofmeyrc2275942015-11-10 22:07:04 +01001107 &resolved_ggsn_addr);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001108 OSMO_ASSERT(ggsn_port);
1109 struct gtphub_peer *ggsn = ggsn_port->peer_addr->peer;
1110 /* now == 345; now + 30 == 375.
1111 * seq mapping from above:
1112 * 0xabcd == 43981 (sent in the packet)
1113 * 0x6d31 == 27953 (harcoded seq mapping start val) */
1114 OSMO_ASSERT(nr_map_is(&ggsn->seq_map, "(43981->27953@375), "));
1115
1116 /* now == 345; now + (6 * 60 * 60) == 21600 + 345 == 21945.
1117 * 0x00000321 == 801 (TEI from SGSN Ctrl)
1118 * 0x00000123 == 291 (TEI from SGSN User)
1119 * 0x00000765 == 1893 (TEI from GGSN Ctrl)
1120 * 0x00000567 == 1383 (TEI from GGSN User)
1121 * Mapped TEIs should be 1 and 2. */
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001122 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001123 "TEI=1:"
1124 " 192.168.42.23 (TEI C=321 U=123)"
1125 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001126 " @21945\n"));
Neels Hofmeyr10fc0242015-12-01 00:23:45 +01001127
Neels Hofmeyr75599102015-12-01 01:01:16 +01001128 if (del_from_side == GTPH_SIDE_SGSN) {
1129 OSMO_ASSERT(delete_pdp_ctx_from_sgsn());
1130 } else {
1131 OSMO_ASSERT(delete_pdp_ctx_from_ggsn());
1132 }
Neels Hofmeyr10fc0242015-12-01 00:23:45 +01001133 OSMO_ASSERT(tunnels_are(""));
1134
Neels Hofmeyr20bd6bf2015-11-20 00:08:28 +01001135 OSMO_ASSERT(clear_test_hub());
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001136}
1137
Neels Hofmeyre921e322015-11-11 00:45:50 +01001138static void test_user_data(void)
1139{
1140 LOG("test_user_data");
1141
1142 OSMO_ASSERT(setup_test_hub());
1143
1144 OSMO_ASSERT(create_pdp_ctx());
1145
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001146 /* now == 345; now + (6 * 60 * 60) == 21600 + 345 == 21945. */
1147 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001148 "TEI=1:"
1149 " 192.168.42.23 (TEI C=321 U=123)"
1150 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001151 " @21945\n"));
1152
Neels Hofmeyre921e322015-11-11 00:45:50 +01001153 LOG("- user data starts");
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001154 /* Now expect default port numbers for User plane. */
Neels Hofmeyre921e322015-11-11 00:45:50 +01001155 resolve_to_ggsn("192.168.43.34", 2152);
1156 resolve_to_sgsn("192.168.42.23", 2152);
1157
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001158 /* 10 minutes later */
1159 now += 600;
1160
Neels Hofmeyre921e322015-11-11 00:45:50 +01001161 const char *u_from_ggsn =
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 */
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001165 "00000001" /* mapped TEI for SGSN from create_pdp_ctx() */
Neels Hofmeyre921e322015-11-11 00:45:50 +01001166 "0070" /* seq */
1167 "0000" /* No extensions */
1168 /* User data (ICMP packet), 96 - 12 = 84 octets */
1169 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
1170 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
1171 "202122232425262728292a2b2c2d2e2f3031323334353637"
1172 ;
1173 const char *u_to_sgsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +01001174 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyre921e322015-11-11 00:45:50 +01001175 "ff" /* type 255: G-PDU */
1176 "0058" /* length: 88 + 8 octets == 96 */
1177 "00000123" /* unmapped User TEI */
1178 "6d31" /* new mapped seq */
1179 "0000"
1180 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
1181 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
1182 "202122232425262728292a2b2c2d2e2f3031323334353637"
1183 ;
1184
1185 /* This depends on create_pdp_ctx() sending resolved_sgsn_addr as GSN
1186 * Address IEs in the GGSN's Create PDP Ctx Response. */
1187 OSMO_ASSERT(msg_from_ggsn_u(&ggsn_sender,
1188 &resolved_sgsn_addr,
1189 u_from_ggsn,
1190 u_to_sgsn));
1191
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001192 /* Make sure the user plane messages have refreshed the TEI mapping
1193 * timeouts: 21945 + 600 == 22545. */
1194 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001195 "TEI=1:"
1196 " 192.168.42.23 (TEI C=321 U=123)"
1197 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001198 " @22545\n"));
1199
Neels Hofmeyre921e322015-11-11 00:45:50 +01001200 const char *u_from_sgsn =
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 */
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001204 "00000001" /* mapped User TEI for GGSN from create_pdp_ctx() */
Neels Hofmeyr1ae3ebd2015-12-03 14:19:08 +01001205 "1234" /* unknown seq */
Neels Hofmeyre921e322015-11-11 00:45:50 +01001206 "0000" /* No extensions */
1207 /* User data (ICMP packet), 96 - 12 = 84 octets */
1208 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
1209 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
1210 "202122232425262728292a2b2c2d2e2f3031323334353637"
1211 ;
1212 const char *u_to_ggsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +01001213 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyre921e322015-11-11 00:45:50 +01001214 "ff" /* type 255: G-PDU */
1215 "0058" /* length: 88 + 8 octets == 96 */
1216 "00000567" /* unmapped User TEI */
Neels Hofmeyr1ae3ebd2015-12-03 14:19:08 +01001217 "6d31" /* unmapped seq */
Neels Hofmeyre921e322015-11-11 00:45:50 +01001218 "0000"
1219 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
1220 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
1221 "202122232425262728292a2b2c2d2e2f3031323334353637"
1222 ;
1223
Neels Hofmeyr1ae3ebd2015-12-03 14:19:08 +01001224 OSMO_ASSERT(msg_from_sgsn_u(&sgsn_sender,
1225 &resolved_ggsn_addr,
Neels Hofmeyre921e322015-11-11 00:45:50 +01001226 u_from_sgsn,
1227 u_to_ggsn));
1228
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001229 /* Make sure the user plane messages have refreshed the TEI mapping
1230 * timeouts: 21945 + 600 == 22545. Both timeouts refreshed: */
1231 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001232 "TEI=1:"
1233 " 192.168.42.23 (TEI C=321 U=123)"
1234 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001235 " @22545\n"));
1236
Neels Hofmeyr20bd6bf2015-11-20 00:08:28 +01001237 OSMO_ASSERT(clear_test_hub());
Neels Hofmeyre921e322015-11-11 00:45:50 +01001238}
1239
Neels Hofmeyrbe4beba2015-12-02 14:18:26 +01001240static void test_reused_tei(void)
1241{
1242 LOG("test_reused_tei");
1243
1244 OSMO_ASSERT(setup_test_hub());
1245
1246 OSMO_ASSERT(create_pdp_ctx());
1247
1248 const char *gtp_req_from_sgsn =
1249 MSG_PDP_CTX_REQ("0068",
1250 "abce", /* Next seq */
1251 "60",
1252 "42000121436587f9",
1253 "00000123", /* Same TEIs as before */
1254 "00000321",
1255 "0009""08696e7465726e6574", /* "(8)internet" */
1256 "0004""c0a82a17", /* same as default sgsn_sender */
1257 "0004""c0a82a17"
1258 );
1259 const char *gtp_req_to_ggsn =
1260 MSG_PDP_CTX_REQ("0068",
1261 "6d32", /* mapped seq ("abce") */
1262 "23",
1263 "42000121436587f9",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001264 "00000002", /* mapped TEI Data I ("123") */
1265 "00000002", /* mapped TEI Control ("321") */
Neels Hofmeyrbe4beba2015-12-02 14:18:26 +01001266 "0009""08696e7465726e6574",
1267 "0004""7f000201", /* replaced with gtphub's ggsn ctrl */
1268 "0004""7f000202" /* replaced with gtphub's ggsn user */
1269 );
1270
1271 OSMO_ASSERT(msg_from_sgsn_c(&sgsn_sender,
1272 &resolved_ggsn_addr,
1273 gtp_req_from_sgsn,
1274 gtp_req_to_ggsn));
1275 OSMO_ASSERT(was_resolved_for("240010123456789", "internet"));
1276
1277 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001278 "TEI=2:"
1279 " 192.168.42.23 (TEI C=321 U=123)"
1280 " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)"
Neels Hofmeyrbe4beba2015-12-02 14:18:26 +01001281 " @21945\n"));
1282
1283 const char *gtp_resp_from_ggsn =
1284 MSG_PDP_CTX_RSP("004e",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001285 "00000002", /* destination TEI (sent in req above) */
Neels Hofmeyrbe4beba2015-12-02 14:18:26 +01001286 "6d32", /* mapped seq */
1287 "01", /* restart */
1288 "00000567", /* TEI U */
1289 "00000765", /* TEI C */
1290 "0004""c0a82b22", /* GSN addresses */
1291 "0004""c0a82b22" /* (== resolved_ggsn_addr) */
1292 );
1293 const char *gtp_resp_to_sgsn =
1294 MSG_PDP_CTX_RSP("004e",
1295 "00000321", /* unmapped TEI ("001") */
1296 "abce", /* unmapped seq ("6d32") */
1297 "23",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001298 "00000002", /* mapped TEI from GGSN ("567") */
1299 "00000002", /* mapped TEI from GGSN ("765") */
Neels Hofmeyrbe4beba2015-12-02 14:18:26 +01001300 "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */
1301 "0004""7f000102" /* gtphub's address towards SGSNs (User) */
1302 );
1303 /* The response should go back to whichever port the request came from
1304 * (unmapped by sequence nr) */
1305 OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr,
1306 &sgsn_sender,
1307 gtp_resp_from_ggsn,
1308 gtp_resp_to_sgsn));
1309
1310 OSMO_ASSERT(clear_test_hub());
1311}
1312
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001313static void test_peer_restarted(void)
1314{
1315 LOG("test_peer_restarted");
1316
1317 OSMO_ASSERT(setup_test_hub());
1318
1319 OSMO_ASSERT(create_pdp_ctx());
1320
1321 now += 10;
1322
1323 const char *gtp_req_from_sgsn =
1324 MSG_PDP_CTX_REQ("0068",
1325 "1234", /* brand new seq */
1326 "61", /* DIFFERING restart counter */
1327 "42000121436587f9",
1328 "00000abc",
1329 "00000cba",
1330 "0009""08696e7465726e6574", /* "(8)internet" */
1331 "0004""c0a82a17", /* same as default sgsn_sender */
1332 "0004""c0a82a17"
1333 );
1334 const char *gtp_req_to_ggsn =
1335 MSG_PDP_CTX_REQ("0068",
Neels Hofmeyrc6d51f52015-12-02 15:44:34 +01001336 "6d33", /* mapped seq ("1234") */
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001337 "23",
1338 "42000121436587f9",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001339 "00000002", /* mapped TEI Data I ("123") */
1340 "00000002", /* mapped TEI Control ("321") */
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001341 "0009""08696e7465726e6574",
1342 "0004""7f000201", /* replaced with gtphub's ggsn ctrl */
1343 "0004""7f000202" /* replaced with gtphub's ggsn user */
1344 );
1345
1346 OSMO_ASSERT(msg_from_sgsn_c(&sgsn_sender,
1347 &resolved_ggsn_addr,
1348 gtp_req_from_sgsn,
1349 gtp_req_to_ggsn));
1350 OSMO_ASSERT(was_resolved_for("240010123456789", "internet"));
1351
1352 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001353 "TEI=2:"
1354 " 192.168.42.23 (TEI C=cba U=abc)"
1355 " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)"
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001356 " @21955\n"
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001357 "TEI=1:"
1358 " (uninitialized) (TEI C=321 U=123)"
1359 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001360 " @21945\n"
1361 ));
1362
1363 const char *gtp_resp_from_ggsn =
1364 MSG_PDP_CTX_RSP("004e",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001365 "00000002", /* destination TEI (sent in req above) */
Neels Hofmeyrc6d51f52015-12-02 15:44:34 +01001366 "6d33", /* mapped seq */
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001367 "01", /* restart */
1368 "00000def", /* TEI U */
1369 "00000fde", /* TEI C */
1370 "0004""c0a82b22", /* GSN addresses */
1371 "0004""c0a82b22" /* (== resolved_ggsn_addr) */
1372 );
1373 const char *gtp_resp_to_sgsn =
1374 MSG_PDP_CTX_RSP("004e",
1375 "00000cba", /* unmapped TEI ("005") */
1376 "1234", /* unmapped seq ("6d32") */
1377 "23",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001378 "00000002", /* mapped TEI from GGSN ("567") */
1379 "00000002", /* mapped TEI from GGSN ("765") */
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001380 "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */
1381 "0004""7f000102" /* gtphub's address towards SGSNs (User) */
1382 );
1383 /* The response should go back to whichever port the request came from
1384 * (unmapped by sequence nr) */
1385 OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr,
1386 &sgsn_sender,
1387 gtp_resp_from_ggsn,
1388 gtp_resp_to_sgsn));
1389
1390 OSMO_ASSERT(clear_test_hub());
1391}
1392
1393static void test_peer_restarted_reusing_tei(void)
1394{
1395 LOG("test_peer_restarted_reusing_tei");
1396
1397 OSMO_ASSERT(setup_test_hub());
1398
1399 OSMO_ASSERT(create_pdp_ctx());
1400
1401 now += 10;
1402
1403 const char *gtp_req_from_sgsn =
1404 MSG_PDP_CTX_REQ("0068",
1405 "1234", /* brand new seq */
1406 "61", /* DIFFERING restart counter */
1407 "42000121436587f9",
1408 "00000123", /* SAME TEI */
1409 "00000321",
1410 "0009""08696e7465726e6574", /* "(8)internet" */
1411 "0004""c0a82a17", /* same as default sgsn_sender */
1412 "0004""c0a82a17"
1413 );
1414 const char *gtp_req_to_ggsn =
1415 MSG_PDP_CTX_REQ("0068",
Neels Hofmeyrd010c492015-12-06 23:12:02 +01001416 "6d33", /* seq 6d31 + 2, after "out-of-band" Delete PDP Ctx
1417 due to differing restart counter. */
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001418 "23",
1419 "42000121436587f9",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001420 "00000002", /* mapped TEI Data I ("123") */
1421 "00000002", /* mapped TEI Control ("321") */
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001422 "0009""08696e7465726e6574",
1423 "0004""7f000201", /* replaced with gtphub's ggsn ctrl */
1424 "0004""7f000202" /* replaced with gtphub's ggsn user */
1425 );
1426
1427 OSMO_ASSERT(msg_from_sgsn_c(&sgsn_sender,
1428 &resolved_ggsn_addr,
1429 gtp_req_from_sgsn,
1430 gtp_req_to_ggsn));
1431 OSMO_ASSERT(was_resolved_for("240010123456789", "internet"));
1432
1433 OSMO_ASSERT(tunnels_are(
Neels Hofmeyrd010c492015-12-06 23:12:02 +01001434 "TEI=2:" /* being established after restart */
1435 " 192.168.42.23 (TEI C=321 U=123)"
1436 " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)"
1437 " @21955\n"
1438 "TEI=1:" /* invalidated due to restart */
1439 " (uninitialized) (TEI C=321 U=123)"
1440 " <-> 192.168.43.34 (TEI C=765 U=567)"
1441 " @21945\n"
1442 ));
1443
1444 /* An "out-of-band" delete request should have been sent to the GGSN
1445 * (checked by expected log output in gtphub_test.ok), and the GGSN
1446 * will (usually) send a Delete Response like this: */
1447 const char *gtp_del_resp_from_ggsn =
1448 MSG_DEL_PDP_CTX_RSP("00000001", "6d32");
1449
1450 /* For this response (due to peer restart) we expect no forwarded
1451 * message. */
1452 OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr,
1453 &sgsn_sender,
1454 gtp_del_resp_from_ggsn,
1455 ""));
1456
1457 OSMO_ASSERT(tunnels_are(
1458 "TEI=2:" /* still being established after restart */
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001459 " 192.168.42.23 (TEI C=321 U=123)"
1460 " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)"
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001461 " @21955\n"
1462 ));
1463
1464 const char *gtp_resp_from_ggsn =
1465 MSG_PDP_CTX_RSP("004e",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001466 "00000002", /* destination TEI (sent in req above) */
Neels Hofmeyrd010c492015-12-06 23:12:02 +01001467 "6d33", /* mapped seq */
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001468 "01", /* restart */
1469 "00000def", /* TEI U */
1470 "00000fde", /* TEI C */
1471 "0004""c0a82b22", /* GSN addresses */
1472 "0004""c0a82b22" /* (== resolved_ggsn_addr) */
1473 );
1474 const char *gtp_resp_to_sgsn =
1475 MSG_PDP_CTX_RSP("004e",
1476 "00000321", /* unmapped TEI ("005") */
Neels Hofmeyrd010c492015-12-06 23:12:02 +01001477 "1234", /* unmapped seq ("6d33") */
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001478 "23",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001479 "00000002", /* mapped TEI from GGSN ("567") */
1480 "00000002", /* mapped TEI from GGSN ("765") */
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001481 "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */
1482 "0004""7f000102" /* gtphub's address towards SGSNs (User) */
1483 );
1484 /* The response should go back to whichever port the request came from
1485 * (unmapped by sequence nr) */
1486 OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr,
1487 &sgsn_sender,
1488 gtp_resp_from_ggsn,
1489 gtp_resp_to_sgsn));
1490
Neels Hofmeyrd010c492015-12-06 23:12:02 +01001491 OSMO_ASSERT(tunnels_are(
1492 "TEI=2:" /* still being established after restart */
1493 " 192.168.42.23 (TEI C=321 U=123)"
1494 " <-> 192.168.43.34 (TEI C=fde U=def)"
1495 " @21955\n"
1496 ));
1497
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001498 OSMO_ASSERT(clear_test_hub());
1499}
1500
Neels Hofmeyrf8c70102015-12-03 14:29:48 +01001501static void test_sgsn_behind_nat(void)
1502{
1503 LOG("test_user_data");
1504
1505 OSMO_ASSERT(setup_test_hub());
1506 hub->sgsn_use_sender = 1; /* <-- Main difference to test_user_data() */
1507 resolve_to_sgsn("192.168.42.23", 423); /* Same as sender */
1508
1509 OSMO_ASSERT(create_pdp_ctx());
1510
1511 /* now == 345; now + (6 * 60 * 60) == 21600 + 345 == 21945. */
1512 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001513 "TEI=1:"
1514 " 192.168.42.23 (TEI C=321 U=123)"
1515 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyrf8c70102015-12-03 14:29:48 +01001516 " @21945\n"));
1517
1518 LOG("- user data starts");
1519 /* Now expect default port numbers for User plane -- except SGSN. */
1520 resolve_to_ggsn("192.168.43.34", 2152);
1521
1522 /* 10 minutes later */
1523 now += 600;
1524
1525 const char *u_from_ggsn =
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 */
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001529 "00000001" /* mapped User TEI for SGSN from create_pdp_ctx() */
Neels Hofmeyrf8c70102015-12-03 14:29:48 +01001530 "0070" /* seq */
1531 "0000" /* No extensions */
1532 /* User data (ICMP packet), 96 - 12 = 84 octets */
1533 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
1534 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
1535 "202122232425262728292a2b2c2d2e2f3031323334353637"
1536 ;
1537 const char *u_to_sgsn =
1538 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
1539 "ff" /* type 255: G-PDU */
1540 "0058" /* length: 88 + 8 octets == 96 */
1541 "00000123" /* unmapped User TEI */
1542 "6d31" /* new mapped seq */
1543 "0000"
1544 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
1545 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
1546 "202122232425262728292a2b2c2d2e2f3031323334353637"
1547 ;
1548
1549 /* This depends on create_pdp_ctx() sending resolved_sgsn_addr as GSN
1550 * Address IEs in the GGSN's Create PDP Ctx Response. */
1551 OSMO_ASSERT(msg_from_ggsn_u(&ggsn_sender,
1552 &resolved_sgsn_addr,
1553 u_from_ggsn,
1554 u_to_sgsn));
1555
1556 /* Make sure the user plane messages have refreshed the TEI mapping
1557 * timeouts: 21945 + 600 == 22545. */
1558 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001559 "TEI=1:"
1560 " 192.168.42.23 (TEI C=321 U=123)"
1561 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyrf8c70102015-12-03 14:29:48 +01001562 " @22545\n"));
1563
1564 const char *u_from_sgsn =
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 */
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001568 "00000001" /* mapped User TEI for GGSN from create_pdp_ctx() */
Neels Hofmeyrf8c70102015-12-03 14:29:48 +01001569 "1234" /* unknown seq */
1570 "0000" /* No extensions */
1571 /* User data (ICMP packet), 96 - 12 = 84 octets */
1572 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
1573 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
1574 "202122232425262728292a2b2c2d2e2f3031323334353637"
1575 ;
1576 const char *u_to_ggsn =
1577 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
1578 "ff" /* type 255: G-PDU */
1579 "0058" /* length: 88 + 8 octets == 96 */
1580 "00000567" /* unmapped User TEI */
1581 "6d31" /* unmapped seq */
1582 "0000"
1583 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
1584 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
1585 "202122232425262728292a2b2c2d2e2f3031323334353637"
1586 ;
1587
1588 OSMO_ASSERT(msg_from_sgsn_u(&sgsn_sender,
1589 &resolved_ggsn_addr,
1590 u_from_sgsn,
1591 u_to_ggsn));
1592
1593 /* Make sure the user plane messages have refreshed the TEI mapping
1594 * timeouts: 21945 + 600 == 22545. Both timeouts refreshed: */
1595 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001596 "TEI=1:"
1597 " 192.168.42.23 (TEI C=321 U=123)"
1598 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyrf8c70102015-12-03 14:29:48 +01001599 " @22545\n"));
1600
1601 OSMO_ASSERT(clear_test_hub());
1602}
1603
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001604void test_parallel_context_creation(void)
1605{
1606 LOG("test_parallel_context_creation");
1607
1608 OSMO_ASSERT(setup_test_hub());
1609
1610 const char *gtp_req_from_sgsn1 =
1611 MSG_PDP_CTX_REQ("0068",
1612 "abcd",
1613 "60",
1614 "42000121436587f9",
1615 "00000123",
1616 "00000321",
1617 "0009""08696e7465726e6574", /* "(8)internet" */
1618 "0004""c0a82a17", /* same as default sgsn_sender */
1619 "0004""c0a82a17"
1620 );
1621 const char *gtp_req_to_ggsn1 =
1622 MSG_PDP_CTX_REQ("0068",
1623 "6d31", /* mapped seq ("abcd") */
1624 "23",
1625 "42000121436587f9",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001626 "00000001", /* mapped TEI Data I ("123") */
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001627 "00000001", /* mapped TEI Control ("321") */
1628 "0009""08696e7465726e6574",
1629 "0004""7f000201", /* replaced with gtphub's ggsn ctrl */
1630 "0004""7f000202" /* replaced with gtphub's ggsn user */
1631 );
1632
1633 OSMO_ASSERT(msg_from_sgsn_c(&sgsn_sender,
1634 &resolved_ggsn_addr,
1635 gtp_req_from_sgsn1,
1636 gtp_req_to_ggsn1));
1637
1638 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001639 "TEI=1:"
1640 " 192.168.42.23 (TEI C=321 U=123)"
1641 " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)"
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001642 " @21945\n"));
1643
1644 now ++;
1645
1646 const char *gtp_req_from_sgsn2 =
1647 MSG_PDP_CTX_REQ("0068",
1648 "abce",
1649 "60",
1650 "42000121436588f9",
1651 "00000124",
1652 "00000322",
1653 "0009""08696e7465726e6574", /* "(8)internet" */
1654 "0004""c0a82a17", /* same as default sgsn_sender */
1655 "0004""c0a82a17"
1656 );
1657 const char *gtp_req_to_ggsn2 =
1658 MSG_PDP_CTX_REQ("0068",
1659 "6d32", /* mapped seq ("abce") */
1660 "23",
1661 "42000121436588f9",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001662 "00000002", /* mapped TEI Data I ("124") */
1663 "00000002", /* mapped TEI Control ("322") */
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001664 "0009""08696e7465726e6574",
1665 "0004""7f000201", /* replaced with gtphub's ggsn ctrl */
1666 "0004""7f000202" /* replaced with gtphub's ggsn user */
1667 );
1668
1669 OSMO_ASSERT(msg_from_sgsn_c(&sgsn_sender,
1670 &resolved_ggsn_addr,
1671 gtp_req_from_sgsn2,
1672 gtp_req_to_ggsn2));
1673
1674 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001675 "TEI=2:"
1676 " 192.168.42.23 (TEI C=322 U=124)"
1677 " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)"
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001678 " @21946\n"
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001679 "TEI=1:"
1680 " 192.168.42.23 (TEI C=321 U=123)"
1681 " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)"
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001682 " @21945\n"
1683 ));
1684
1685 now ++;
1686
1687 const char *gtp_resp_from_ggsn1 =
1688 MSG_PDP_CTX_RSP("004e",
1689 "00000001", /* destination TEI (sent in req above) */
1690 "6d31", /* mapped seq */
1691 "01", /* restart */
1692 "00000567", /* TEI U */
1693 "00000765", /* TEI C */
1694 "0004""c0a82b22", /* GSN addresses */
1695 "0004""c0a82b22" /* (== resolved_ggsn_addr) */
1696 );
1697 const char *gtp_resp_to_sgsn1 =
1698 MSG_PDP_CTX_RSP("004e",
1699 "00000321", /* unmapped TEI ("001") */
1700 "abcd", /* unmapped seq ("6d31") */
1701 "23",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001702 "00000001", /* mapped TEI from GGSN ("567") */
1703 "00000001", /* mapped TEI from GGSN ("765") */
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001704 "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */
1705 "0004""7f000102" /* gtphub's address towards SGSNs (User) */
1706 );
1707
1708 OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr,
1709 &sgsn_sender,
1710 gtp_resp_from_ggsn1,
1711 gtp_resp_to_sgsn1));
1712
1713 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001714 "TEI=2:"
1715 " 192.168.42.23 (TEI C=322 U=124)"
1716 " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)"
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001717 " @21946\n"
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001718 "TEI=1:"
1719 " 192.168.42.23 (TEI C=321 U=123)"
1720 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001721 " @21947\n"
1722 ));
1723
1724 now ++;
1725
1726 const char *gtp_resp_from_ggsn2 =
1727 MSG_PDP_CTX_RSP("004e",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001728 "00000002", /* destination TEI (sent in req above) */
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001729 "6d32", /* mapped seq */
1730 "01", /* restart */
1731 "00000568", /* TEI U */
1732 "00000766", /* TEI C */
1733 "0004""c0a82b22", /* GSN addresses */
1734 "0004""c0a82b22" /* (== resolved_ggsn_addr) */
1735 );
1736 const char *gtp_resp_to_sgsn2 =
1737 MSG_PDP_CTX_RSP("004e",
1738 "00000322", /* unmapped TEI ("001") */
1739 "abce", /* unmapped seq ("6d31") */
1740 "23",
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001741 "00000002", /* mapped TEI from GGSN ("567") */
1742 "00000002", /* mapped TEI from GGSN ("765") */
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001743 "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */
1744 "0004""7f000102" /* gtphub's address towards SGSNs (User) */
1745 );
1746
1747 OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr,
1748 &sgsn_sender,
1749 gtp_resp_from_ggsn2,
1750 gtp_resp_to_sgsn2));
1751
1752 OSMO_ASSERT(tunnels_are(
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001753 "TEI=2:"
1754 " 192.168.42.23 (TEI C=322 U=124)"
1755 " <-> 192.168.43.34 (TEI C=766 U=568)"
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001756 " @21948\n"
Neels Hofmeyree07e4f2015-12-06 19:11:45 +01001757 "TEI=1:"
1758 " 192.168.42.23 (TEI C=321 U=123)"
1759 " <-> 192.168.43.34 (TEI C=765 U=567)"
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001760 " @21947\n"
1761 ));
1762
1763 OSMO_ASSERT(clear_test_hub());
1764}
1765
Neels Hofmeyre921e322015-11-11 00:45:50 +01001766
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001767static struct log_info_cat gtphub_categories[] = {
1768 [DGTPHUB] = {
1769 .name = "DGTPHUB",
1770 .description = "GTP Hub",
1771 .color = "\033[1;33m",
Neels Hofmeyre54cd152015-11-24 13:31:06 +01001772 .enabled = 1, .loglevel = LOGL_DEBUG,
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001773 },
1774};
1775
1776static struct log_info info = {
1777 .cat = gtphub_categories,
1778 .num_cat = ARRAY_SIZE(gtphub_categories),
1779};
1780
1781int main(int argc, char **argv)
1782{
1783 osmo_init_logging(&info);
1784 osmo_gtphub_ctx = talloc_named_const(NULL, 0, "osmo_gtphub");
1785
1786 test_nr_map_basic();
Neels Hofmeyre2ed8e62015-11-17 14:30:37 +01001787 test_nr_map_wrap();
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001788 test_expiry();
1789 test_echo();
Neels Hofmeyr75599102015-12-01 01:01:16 +01001790 test_one_pdp_ctx(GTPH_SIDE_SGSN);
1791 test_one_pdp_ctx(GTPH_SIDE_GGSN);
Neels Hofmeyre921e322015-11-11 00:45:50 +01001792 test_user_data();
Neels Hofmeyrbe4beba2015-12-02 14:18:26 +01001793 test_reused_tei();
Neels Hofmeyr237fee62015-12-02 14:31:45 +01001794 test_peer_restarted();
1795 test_peer_restarted_reusing_tei();
Neels Hofmeyrf8c70102015-12-03 14:29:48 +01001796 test_sgsn_behind_nat();
Neels Hofmeyr23d09cc2015-12-06 19:02:43 +01001797 test_parallel_context_creation();
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001798 printf("Done\n");
1799
1800 talloc_report_full(osmo_gtphub_ctx, stderr);
1801 OSMO_ASSERT(talloc_total_blocks(osmo_gtphub_ctx) == 1);
1802 return 0;
1803}
1804