blob: 12c9d7825ca4ddf0592d1887b4c062344c35b62d [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>
29#include <osmocom/core/msgb.h>
30#include <osmocom/core/application.h>
31
32#include <openbsc/debug.h>
33
34#include <openbsc/gtphub.h>
35#include <gtp.h>
36#include <gtpie.h>
37
38#define EXPIRE_ALL ((60 * GTPH_TEI_MAPPING_EXPIRY_MINUTES) + 1)
39
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +010040#define ZERO_STRUCT(struct_pointer) memset(struct_pointer, '\0', \
41 sizeof(*(struct_pointer)))
Neels Hofmeyrc2275942015-11-10 22:07:04 +010042
43#define LVL2_ASSERT(exp) LVL2_ASSERT_R(exp, return 0)
44#define LVL2_ASSERT_R(exp, ret) \
45 if (!(exp)) { \
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +010046 fprintf(stderr, "LVL2 Assert failed %s %s:%d\n", #exp, \
47 __FILE__, __LINE__); \
Neels Hofmeyrc2275942015-11-10 22:07:04 +010048 osmo_generate_backtrace(); \
49 ret; \
50 }
51
Neels Hofmeyre921e322015-11-11 00:45:50 +010052/* Convenience makro, note: only within this C file. */
53#define LOG(label) \
54 { LOGP(DGTPHUB, LOGL_NOTICE, "\n\n" label "\n"); \
55 printf(label "\n"); }
56
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +020057void gtphub_init(struct gtphub *hub);
58
59void *osmo_gtphub_ctx;
60
61/* TODO copied from libosmo-abis/src/subchan_demux.c, remove dup */
62static int llist_len(struct llist_head *head)
63{
64 struct llist_head *entry;
65 int i = 0;
66
67 llist_for_each(entry, head)
68 i++;
69
70 return i;
71}
72
73static void nr_mapping_free(struct expiring_item *e)
74{
75 struct nr_mapping *m = container_of(e, struct nr_mapping,
76 expiry_entry);
77 nr_mapping_del(m);
78 talloc_free(m);
79}
80
81static struct nr_mapping *nr_mapping_alloc(void)
82{
83 struct nr_mapping *m;
84 m = talloc(osmo_gtphub_ctx, struct nr_mapping);
85 nr_mapping_init(m);
86 m->expiry_entry.del_cb = nr_mapping_free;
87 return m;
88}
89
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +010090static struct nr_mapping *nr_map_have(struct nr_map *map, void *origin,
91 nr_t orig, time_t now)
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +020092{
93 struct nr_mapping *mapping;
94
95 mapping = nr_map_get(map, origin, orig);
96 if (!mapping) {
97 mapping = nr_mapping_alloc();
98 mapping->origin = origin;
99 mapping->orig = orig;
100 nr_map_add(map, mapping, now);
101 }
102
103 return mapping;
104}
105
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100106static nr_t nr_map_verify(const struct nr_map *map, void *origin, nr_t orig,
107 nr_t expect_repl)
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200108{
109 struct nr_mapping *m;
110 m = nr_map_get(map, origin, orig);
111
112 if (!m) {
113 printf("mapping not found for %p %d\n", origin, orig);
114 return 0;
115 }
116
117 if (m->repl != expect_repl) {
118 printf("mapping found, but nr mismatches: expect %d, got %d\n",
119 (int)expect_repl, (int)m->repl);
120 return 0;
121 }
122
123 return 1;
124}
125
126static int nr_map_verify_inv(const struct nr_map *map, nr_t repl,
127 void *expect_origin, nr_t expect_orig)
128{
129 struct nr_mapping *m;
130 m = nr_map_get_inv(map, repl);
131 if (!m) {
132 printf("mapping not found for %d\n", (int)repl);
133 return 0;
134 }
135
136 if (m->origin != expect_origin) {
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100137 printf("mapping found, but origin mismatches:"
138 " expect %p, got %p\n",
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200139 expect_origin, m->origin);
140 return 0;
141 }
142
143 if (m->orig != expect_orig) {
144 printf("mapping found, but nr mismatches: expect %d, got %d\n",
145 (int)expect_orig, (int)m->orig);
146 return 0;
147 }
148
149 return 1;
150}
151
152
153static void test_nr_map_basic(void)
154{
155 struct nr_pool _pool;
156 struct nr_pool *pool = &_pool;
157 struct nr_map _map;
158 struct nr_map *map = &_map;
159
160 nr_pool_init(pool);
161 nr_map_init(map, pool, NULL);
162
163 OSMO_ASSERT(llist_empty(&map->mappings));
164
165#define TEST_N_HALF 100
166#define TEST_N (2*TEST_N_HALF)
167#define TEST_I 123
168 uint32_t i, check_i;
169 uint32_t m[TEST_N];
170 struct nr_mapping *mapping;
171
172 /* create half of TEST_N mappings from one origin */
173 void *origin1 = (void*)0x1234;
174 for (i = 0; i < TEST_N_HALF; i++) {
175 nr_t orig = TEST_I + i;
176 mapping = nr_map_have(map, origin1, orig, 0);
177 m[i] = mapping->repl;
178 OSMO_ASSERT(m[i] != 0);
179 OSMO_ASSERT(llist_len(&map->mappings) == (i+1));
180 for (check_i = 0; check_i < i; check_i++)
181 OSMO_ASSERT(m[check_i] != m[i]);
182 }
183 OSMO_ASSERT(llist_len(&map->mappings) == TEST_N_HALF);
184
185 /* create another TEST_N mappings with the same original numbers, but
186 * from a different origin */
187 void *origin2 = (void*)0x5678;
188 for (i = 0; i < TEST_N_HALF; i++) {
189 int i2 = TEST_N_HALF + i;
190 nr_t orig = TEST_I + i;
191 mapping = nr_map_have(map, origin2, orig, 0);
192 m[i2] = mapping->repl;
193 OSMO_ASSERT(m[i2] != 0);
194 OSMO_ASSERT(llist_len(&map->mappings) == (i2+1));
195 for (check_i = 0; check_i < i2; check_i++)
196 OSMO_ASSERT(m[check_i] != m[i2]);
197 }
198 OSMO_ASSERT(llist_len(&map->mappings) == TEST_N);
199
200 /* verify mappings */
201 for (i = 0; i < TEST_N_HALF; i++) {
202 nr_t orig = TEST_I + i;
203 {
204 OSMO_ASSERT(nr_map_verify(map, origin1, orig, m[i]));
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100205 OSMO_ASSERT(nr_map_verify_inv(map, m[i], origin1,
206 orig));
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200207 }
208 {
209 int i2 = TEST_N_HALF + i;
210 OSMO_ASSERT(nr_map_verify(map, origin2, orig, m[i2]));
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100211 OSMO_ASSERT(nr_map_verify_inv(map, m[i2], origin2,
212 orig));
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200213 }
214 }
215
216 /* remove all mappings */
217 for (i = 0; i < TEST_N_HALF; i++) {
218 OSMO_ASSERT(llist_len(&map->mappings) == (TEST_N - 2*i));
219
220 nr_t orig = TEST_I + i;
221 nr_mapping_del(nr_map_get(map, origin1, orig));
222 nr_mapping_del(nr_map_get(map, origin2, orig));
223 }
224 OSMO_ASSERT(llist_empty(&map->mappings));
225#undef TEST_N
226#undef TEST_I
227}
228
229static int nr_map_is(struct nr_map *map, const char *str)
230{
231 static char buf[4096];
232 char *pos = buf;
233 size_t len = sizeof(buf);
234 struct nr_mapping *m;
235 llist_for_each_entry(m, &map->mappings, entry) {
236 size_t wrote = snprintf(pos, len, "(%d->%d@%d), ",
237 (int)m->orig,
238 (int)m->repl,
239 (int)m->expiry_entry.expiry);
240 OSMO_ASSERT(wrote < len);
241 pos += wrote;
242 len -= wrote;
243 }
244 *pos = '\0';
245
246 if (strncmp(buf, str, sizeof(buf)) != 0) {
247 printf("FAILURE: nr_map_is() mismatches expected value:\n"
248 "expected: \"%s\"\n"
249 "is: \"%s\"\n",
250 str, buf);
251 return 0;
252 }
253 return 1;
254}
255
256static void test_expiry(void)
257{
258 struct expiry expiry;
259 struct nr_pool pool;
260 struct nr_map map;
261 int i;
262
263 expiry_init(&expiry, 30);
264 nr_pool_init(&pool);
265 nr_map_init(&map, &pool, &expiry);
266 OSMO_ASSERT(nr_map_is(&map, ""));
267
268 /* tick on empty map */
269 OSMO_ASSERT(expiry_tick(&expiry, 10000) == 0);
270 OSMO_ASSERT(nr_map_is(&map, ""));
271
272#define MAP1 \
273 "(10->1@10040), " \
274 ""
275
276#define MAP2 \
277 "(20->2@10050), " \
278 "(21->3@10051), " \
279 "(22->4@10052), " \
280 "(23->5@10053), " \
281 "(24->6@10054), " \
282 "(25->7@10055), " \
283 "(26->8@10056), " \
284 "(27->9@10057), " \
285 ""
286
287#define MAP3 \
288 "(420->10@10072), " \
289 "(421->11@10072), " \
290 "(422->12@10072), " \
291 "(423->13@10072), " \
292 "(424->14@10072), " \
293 "(425->15@10072), " \
294 "(426->16@10072), " \
295 "(427->17@10072), " \
296 ""
297
298 /* add mapping at time 10010. */
299 nr_map_have(&map, 0, 10, 10010);
300 OSMO_ASSERT(nr_map_is(&map, MAP1));
301
302 /* tick on unexpired item. */
303 OSMO_ASSERT(expiry_tick(&expiry, 10010) == 0);
304 OSMO_ASSERT(expiry_tick(&expiry, 10011) == 0);
305 OSMO_ASSERT(nr_map_is(&map, MAP1));
306
307 /* Spread mappings at 10020, 10021, ... 10027. */
308 for (i = 0; i < 8; i++)
309 nr_map_have(&map, 0, 20 + i, 10020 + i);
310 OSMO_ASSERT(nr_map_is(&map, MAP1 MAP2));
311
312 /* tick on unexpired items. */
313 OSMO_ASSERT(expiry_tick(&expiry, 10030) == 0);
314 OSMO_ASSERT(expiry_tick(&expiry, 10039) == 0);
315 OSMO_ASSERT(nr_map_is(&map, MAP1 MAP2));
316
317 /* expire the first item (from 10010). */
318 OSMO_ASSERT(expiry_tick(&expiry, 10010 + 30) == 1);
319 OSMO_ASSERT(nr_map_is(&map, MAP2));
320
321 /* again nothing to expire */
322 OSMO_ASSERT(expiry_tick(&expiry, 10041) == 0);
323 OSMO_ASSERT(nr_map_is(&map, MAP2));
324
325 /* Mappings all at the same time. */
326 for (i = 0; i < 8; i++)
327 nr_map_have(&map, 0, 420 + i, 10042);
328 OSMO_ASSERT(nr_map_is(&map, MAP2 MAP3));
329
330 /* Eight to expire, were added further above to be chronologically
331 * correct, at 10020..10027. */
332 OSMO_ASSERT(expiry_tick(&expiry, 10027 + 30) == 8);
333 OSMO_ASSERT(nr_map_is(&map, MAP3));
334
335 /* again nothing to expire */
336 OSMO_ASSERT(expiry_tick(&expiry, 10027 + 30) == 0);
337 OSMO_ASSERT(nr_map_is(&map, MAP3));
338
339 /* Eight to expire, from 10042. Now at 10042 + 30: */
340 OSMO_ASSERT(expiry_tick(&expiry, 10042 + 30) == 8);
341 OSMO_ASSERT(nr_map_is(&map, ""));
342
343#undef MAP1
344#undef MAP2
345#undef MAP3
346}
347
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100348char resolve_ggsn_got_imsi[GSM_IMSI_LENGTH];
349char resolve_ggsn_got_ni[GSM_APN_LENGTH];
350
351struct osmo_sockaddr resolved_ggsn_addr;
352static int resolve_to_ggsn(const char *addr, uint16_t port)
353{
354 LVL2_ASSERT(osmo_sockaddr_init_udp(&resolved_ggsn_addr,
355 addr, port)
356 == 0);
357 return 1;
358}
359
Neels Hofmeyre921e322015-11-11 00:45:50 +0100360struct osmo_sockaddr resolved_sgsn_addr;
361static int resolve_to_sgsn(const char *addr, uint16_t port)
362{
363 LVL2_ASSERT(osmo_sockaddr_init_udp(&resolved_sgsn_addr,
364 addr, port)
365 == 0);
366 return 1;
367}
368
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100369struct osmo_sockaddr sgsn_sender;
370static int send_from_sgsn(const char *addr, uint16_t port)
371{
372 LVL2_ASSERT(osmo_sockaddr_init_udp(&sgsn_sender,
373 addr, port)
374 == 0);
375 return 1;
376}
377
Neels Hofmeyre921e322015-11-11 00:45:50 +0100378struct osmo_sockaddr ggsn_sender;
379static int send_from_ggsn(const char *addr, uint16_t port)
380{
381 LVL2_ASSERT(osmo_sockaddr_init_udp(&ggsn_sender,
382 addr, port)
383 == 0);
384 return 1;
385}
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200386
387
388/* override, requires '-Wl,--wrap=gtphub_resolve_ggsn_addr' */
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100389struct gtphub_peer_port *__real_gtphub_resolve_ggsn_addr(struct gtphub *hub,
390 const char *imsi_str,
391 const char *apn_ni_str);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200392
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100393struct gtphub_peer_port *__wrap_gtphub_resolve_ggsn_addr(struct gtphub *hub,
394 const char *imsi_str,
395 const char *apn_ni_str)
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200396{
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100397 struct gsn_addr resolved_gsna;
398 uint16_t resolved_port;
399
400 OSMO_ASSERT(gsn_addr_from_sockaddr(&resolved_gsna, &resolved_port,
401 &resolved_ggsn_addr) == 0);
402
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100403 struct gtphub_peer_port *pp;
404 pp = gtphub_port_have(hub, &hub->to_ggsns[GTPH_PLANE_CTRL],
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100405 &resolved_gsna, resolved_port);
Neels Hofmeyre921e322015-11-11 00:45:50 +0100406 printf("- __wrap_gtphub_resolve_ggsn_addr():\n"
407 " returning GGSN addr from imsi %s ni %s: %s\n",
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100408 imsi_str, apn_ni_str, gtphub_port_str(pp));
409
410 if (imsi_str) {
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100411 strncpy(resolve_ggsn_got_imsi, imsi_str,
412 sizeof(resolve_ggsn_got_imsi));
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100413 resolve_ggsn_got_imsi[sizeof(resolve_ggsn_got_imsi) - 1] = '\0';
414 }
415 else
416 strcpy(resolve_ggsn_got_imsi, "(null)");
417
418 if (apn_ni_str) {
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100419 strncpy(resolve_ggsn_got_ni, apn_ni_str,
420 sizeof(resolve_ggsn_got_ni));
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100421 resolve_ggsn_got_ni[sizeof(resolve_ggsn_got_ni) - 1] = '\0';
422 }
423 else
424 strcpy(resolve_ggsn_got_ni, "(null)");
425
426 return pp;
427}
428
429#define was_resolved_for(IMSI,NI) _was_resolved_for(IMSI, NI, __FILE__, __LINE__)
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100430static int _was_resolved_for(const char *imsi, const char *ni, const char
431 *file, int line)
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100432{
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100433 int cmp0 = strncmp(imsi, resolve_ggsn_got_imsi,
434 sizeof(resolve_ggsn_got_imsi));
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100435
436 if (cmp0 != 0) {
437 printf("\n%s:%d: was_resolved_for(): MISMATCH for IMSI\n"
438 " expecting: '%s'\n"
439 " got: '%s'\n\n",
440 file,
441 line,
442 imsi, resolve_ggsn_got_imsi);
443 }
444
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100445 int cmp1 = strncmp(ni, resolve_ggsn_got_ni,
446 sizeof(resolve_ggsn_got_ni));
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100447 if (cmp1 != 0) {
448 printf("\n%s:%d: was_resolved_for(): MISMATCH for NI\n"
449 " expecting: '%s'\n"
450 " got: '%s'\n\n",
451 file,
452 line,
453 ni, resolve_ggsn_got_ni);
454 }
455
456 return (cmp0 == 0) && (cmp1 == 0);
457}
458
459/* override, requires '-Wl,--wrap=gtphub_ares_init' */
460int __real_gtphub_ares_init(struct gtphub *hub);
461
462int __wrap_gtphub_ares_init(struct gtphub *hub)
463{
464 /* Do nothing. */
465 return 0;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200466}
467
468#define buf_len 1024
469static uint8_t buf[buf_len];
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100470static uint8_t *reply_buf;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200471
472static unsigned int msg(const char *hex)
473{
474 unsigned int l = osmo_hexparse(hex, buf, buf_len);
475 OSMO_ASSERT(l > 0);
476 return l;
477}
478
479/* Compare static buf to given string constant. The amount of bytes is obtained
480 * from parsing the GTP header in buf. hex must match an osmo_hexdump() of the
481 * desired message. Return 1 if size and content match. */
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100482#define reply_is(MSG) _reply_is(MSG, __FILE__, __LINE__)
483static int _reply_is(const char *hex, const char *file, int line)
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200484{
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100485 struct gtp1_header_long *h = (void*)reply_buf;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200486 int len = ntoh16(h->length) + 8;
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100487 const char *dump = osmo_hexdump_nospc(reply_buf, len);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200488 int cmp = strcmp(dump, hex);
489
490 if (cmp != 0) {
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100491 printf("\n%s:%d: reply_is(): MISMATCH\n"
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200492 " expecting:\n'%s'\n"
493 " got:\n'%s'\n\n",
494 file,
495 line,
496 hex, dump);
497 int i;
498 int l = strlen(hex);
499 int m = strlen(dump);
500 if (m < l)
501 l = m;
502 for (i = 0; i < l; i++) {
503 if (hex[i] != dump[i]) {
504 printf("First mismatch at position %d:\n"
505 " %s\n %s\n", i, hex + i, dump + i);
506 break;
507 }
508 }
509 }
510 return cmp == 0;
511}
512
513#define same_addr(GOT, EXPECTED) _same_addr((GOT),(EXPECTED), __FILE__, __LINE__)
514static int _same_addr(const struct osmo_sockaddr *got,
515 const struct osmo_sockaddr *expected,
516 const char *file, int line)
517{
518 int cmp = osmo_sockaddr_cmp(got, expected);
519 if (!cmp)
520 return 1;
521 char buf[256];
522 printf("\n%s:%d: addr_is(): MISMATCH\n"
523 " expecting: '%s'\n"
524 " got: '%s'\n\n",
525 file, line,
526 osmo_sockaddr_to_str(expected),
527 osmo_sockaddr_to_strb(got, buf, sizeof(buf)));
528 return 0;
529}
530
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100531
532time_t now;
533static struct gtphub _hub;
534static struct gtphub *hub = &_hub;
535
536static int setup_test_hub()
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200537{
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100538 /* Not really needed, but to make 100% sure... */
539 ZERO_STRUCT(hub);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200540
541 gtphub_init(hub);
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100542
543 /* Tell this mock gtphub its local address for this test. */
544 LVL2_ASSERT(gsn_addr_from_str(&hub->to_sgsns[GTPH_PLANE_CTRL].local_addr,
545 "127.0.1.1") == 0);
546 LVL2_ASSERT(gsn_addr_from_str(&hub->to_sgsns[GTPH_PLANE_USER].local_addr,
547 "127.0.1.2") == 0);
548 LVL2_ASSERT(gsn_addr_from_str(&hub->to_ggsns[GTPH_PLANE_CTRL].local_addr,
549 "127.0.2.1") == 0);
550 LVL2_ASSERT(gsn_addr_from_str(&hub->to_ggsns[GTPH_PLANE_USER].local_addr,
551 "127.0.2.2") == 0);
552
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100553 hub->restart_counter = 0x23;
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100554 now = 345;
555 LVL2_ASSERT(send_from_sgsn("192.168.42.23", 423));
Neels Hofmeyre921e322015-11-11 00:45:50 +0100556 LVL2_ASSERT(resolve_to_ggsn("192.168.43.34", 2123));
557 LVL2_ASSERT(send_from_ggsn("192.168.43.34", 321));
558 LVL2_ASSERT(resolve_to_sgsn("192.168.42.23", 2123));
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100559
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100560#define GGSNS_CTRL_FD 1
561#define GGSNS_USER_FD 2
562#define SGSNS_CTRL_FD 3
563#define SGSNS_USER_FD 4
564 hub->to_ggsns[GTPH_PLANE_CTRL].ofd.priv_nr = GGSNS_CTRL_FD;
565 hub->to_ggsns[GTPH_PLANE_USER].ofd.priv_nr = GGSNS_USER_FD;
566 hub->to_sgsns[GTPH_PLANE_CTRL].ofd.priv_nr = SGSNS_CTRL_FD;
567 hub->to_sgsns[GTPH_PLANE_USER].ofd.priv_nr = SGSNS_USER_FD;
568
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100569 return 1;
570}
571
572
573static void test_echo(void)
574{
Neels Hofmeyre921e322015-11-11 00:45:50 +0100575 LOG("test_echo");
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100576 OSMO_ASSERT(setup_test_hub());
577
578 now = 123;
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100579
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100580 struct osmo_fd *to_ofd;
581 struct osmo_sockaddr to_addr;
582 struct gtphub_peer_port *pp;
583 int send;
584
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200585 const char *gtp_ping_from_sgsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100586 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200587 "01" /* type 01: Echo request */
588 "0004" /* length of 4 after header TEI */
589 "00000000" /* header TEI == 0 in Echo */
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100590 "abcd" /* some 2 octet sequence nr */
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200591 "0000" /* N-PDU 0, no extension header (why is this here?) */
592 ;
593
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100594 const char *gtp_pong_to_sgsn =
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200595 "32"
596 "02" /* type 02: Echo response */
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100597 "0006" /* length of 6 after header TEI */
598 "00000000" /* header TEI == 0 in Echo */
599 "abcd" /* same sequence nr */
600 "0000"
601 "0e23" /* Recovery with restart counter */
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200602 ;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200603
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100604 to_ofd = NULL;
605 ZERO_STRUCT(&to_addr);
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100606 send = gtphub_from_sgsns_handle_buf(hub, GTPH_PLANE_CTRL, &sgsn_sender,
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200607 buf, msg(gtp_ping_from_sgsn), now,
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100608 &reply_buf, &to_ofd, &to_addr);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200609 OSMO_ASSERT(send > 0);
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100610 OSMO_ASSERT(to_addr.l);
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100611 OSMO_ASSERT(same_addr(&to_addr, &sgsn_sender));
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100612 OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == SGSNS_CTRL_FD));
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100613 OSMO_ASSERT(reply_is(gtp_pong_to_sgsn));
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200614
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100615 pp = gtphub_port_find_sa(&hub->to_sgsns[GTPH_PLANE_CTRL],
616 &sgsn_sender);
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100617 /* We don't record Echo peers. */
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100618 OSMO_ASSERT(!pp);
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100619
620 const char *gtp_ping_from_ggsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100621 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100622 "01" /* type 01: Echo request */
623 "0004" /* length of 4 after header TEI */
624 "00000000" /* header TEI == 0 in Echo */
625 "cdef" /* some 2 octet sequence nr */
626 "0000" /* N-PDU 0, no extension header (why is this here?) */
627 ;
628
629 const char *gtp_pong_to_ggsn =
630 "32"
631 "02" /* type 02: Echo response */
632 "0006" /* length of 6 after header TEI */
633 "00000000" /* header TEI == 0 in Echo */
634 "cdef" /* same sequence nr */
635 "0000"
636 "0e23" /* Recovery with restart counter */
637 ;
638
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100639 to_ofd = NULL;
640 ZERO_STRUCT(&to_addr);
Neels Hofmeyre921e322015-11-11 00:45:50 +0100641 send = gtphub_from_ggsns_handle_buf(hub, GTPH_PLANE_CTRL, &ggsn_sender,
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100642 buf, msg(gtp_ping_from_ggsn), now,
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100643 &reply_buf, &to_ofd, &to_addr);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200644 OSMO_ASSERT(send > 0);
Neels Hofmeyre921e322015-11-11 00:45:50 +0100645 OSMO_ASSERT(same_addr(&to_addr, &ggsn_sender));
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100646 OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == GGSNS_CTRL_FD));
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100647 OSMO_ASSERT(reply_is(gtp_pong_to_ggsn));
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200648
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100649 pp = gtphub_port_find_sa(&hub->to_ggsns[GTPH_PLANE_CTRL],
650 &sgsn_sender);
651 OSMO_ASSERT(!pp);
652
653
654 /* And all the same on the user plane. */
655
656 to_ofd = NULL;
657 ZERO_STRUCT(&to_addr);
658 send = gtphub_from_sgsns_handle_buf(hub, GTPH_PLANE_USER, &sgsn_sender,
659 buf, msg(gtp_ping_from_sgsn), now,
660 &reply_buf, &to_ofd, &to_addr);
661 OSMO_ASSERT(send > 0);
662 OSMO_ASSERT(to_addr.l);
663 OSMO_ASSERT(same_addr(&to_addr, &sgsn_sender));
664 OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == SGSNS_USER_FD));
665 OSMO_ASSERT(reply_is(gtp_pong_to_sgsn));
666
667 pp = gtphub_port_find_sa(&hub->to_sgsns[GTPH_PLANE_USER],
668 &sgsn_sender);
669 OSMO_ASSERT(!pp);
670
671 to_ofd = NULL;
672 ZERO_STRUCT(&to_addr);
673 send = gtphub_from_ggsns_handle_buf(hub, GTPH_PLANE_USER, &ggsn_sender,
674 buf, msg(gtp_ping_from_ggsn), now,
675 &reply_buf, &to_ofd, &to_addr);
676 OSMO_ASSERT(send > 0);
677 OSMO_ASSERT(same_addr(&to_addr, &ggsn_sender));
678 OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == GGSNS_USER_FD));
679 OSMO_ASSERT(reply_is(gtp_pong_to_ggsn));
680
681 pp = gtphub_port_find_sa(&hub->to_ggsns[GTPH_PLANE_USER],
682 &sgsn_sender);
683 OSMO_ASSERT(!pp);
684
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200685
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100686 now += EXPIRE_ALL;
687 gtphub_gc(hub, now);
688}
689
690
691#define MSG_PDP_CTX_REQ(len, seq, restart, imsi, tei_u, tei_c, apn, gsn_c, gsn_u) \
692 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr. */ \
693 "10" /* type 16: Create PDP Context Request */ \
694 len /* msg length = 8 + len (2 octets) */ \
695 "00000000" /* No TEI yet */ \
696 seq /* Sequence nr (2 octets) */ \
697 "00" /* N-PDU 0 */ \
698 "00" /* No extensions */ \
699 /* IEs */ \
700 "0e" restart /* 14: Recovery = 96 (restart counter: 1 octet) */ \
701 "02" /* 2 = IMSI */ \
702 imsi /* (8 octets) */ \
703 "0f01" /* 15: Selection mode = MS provided APN, subscription not verified*/ \
704 "10" /* 16: TEI Data I */ \
705 tei_u /* (4 octets) */ \
706 "11" /* 17: TEI Control Plane */ \
707 tei_c /* (4 octets) */ \
708 "1400" /* 20: NSAPI = 0*/ \
709 "1a" /* 26: Charging Characteristics */ \
710 "0800" \
711 "80" /* 128: End User Address */ \
712 "0002" /* length = 2: empty PDP Address */ \
713 "f121" /* spare 0xf0, PDP organization 1, PDP type number 0x21 = 33 */ \
714 "83" /* 131: Access Point Name */ \
715 apn /* (2 octets length, N octets encoded APN-NI) */ \
716 "84" /* 132: Protocol Configuration Options */ \
717 "0015" /* length = 21 */ \
718 "80c0231101010011036d69670868656d6d656c6967" \
719 "85" /* 133: GSN Address */ \
720 gsn_c /* (2 octets length, N octets addr) */ \
721 "85" /* 133: GSN Address (second entry) */ \
722 gsn_u /* (2 octets length, N octets addr) */ \
723 "86" /* 134: MS International PSTN/ISDN Number (MSISDN) */ \
724 "0007" /* length */ \
725 "916407123254f6" /* 1946702123456(f) */ \
726 "87" /* 135: Quality of Service (QoS) Profile */ \
727 "0004" /* length */ \
728 "00" /* priority */ \
729 "0b921f" /* QoS profile data */
730
731#define MSG_PDP_CTX_RSP(len, tei_h, seq, restart, tei_u, tei_c, gsn_c, gsn_u) \
732 "32" \
733 "11" /* Create PDP Context Response */ \
734 len /* msg length = 8 + len (2 octets) */ \
735 tei_h /* destination TEI (sent in req above) */ \
736 seq /* mapped seq */ \
737 "00" "00" \
738 /* IEs */ \
739 "01" /* 1: Cause */ \
740 "80" /* value = 0b10000000 = response, no rejection. */ \
741 "08" /* 8: Reordering Required */ \
742 "00" /* not required. */ \
743 "0e" restart /* 14: Recovery = 1 */ \
744 "10" /* 16: TEI Data I */ \
745 tei_u \
746 "11" /* 17: TEI Control */ \
747 tei_c \
748 "7f" /* 127: Charging ID */ \
749 "00000001" \
750 "80" /* 128: End User Address */ \
751 "0006" /* length = 6 */ \
752 "f121" /* spare 0xf0, PDP organization 1, PDP type number 0x21 = 33 */ \
753 "7f000002" \
754 "84" /* 132: Protocol Configuration Options */ \
755 "0014" /* len = 20 */ \
756 "8080211002000010810608080808830600000000" \
757 "85" /* 133: GSN Address (Ctrl) */ \
758 gsn_c \
759 "85" /* 133: GSN Address (User) */ \
760 gsn_u \
761 "87" /* 135: Quality of Service (QoS) Profile */ \
762 "0004" /* length */ \
763 "00" /* priority */ \
764 "0b921f" /* QoS profile data */
765
766#define msg_from_sgsn_c(A,B,C,D) msg_from_sgsn(GTPH_PLANE_CTRL, A,B,C,D)
767#define msg_from_sgsn_u(A,B,C,D) msg_from_sgsn(GTPH_PLANE_USER, A,B,C,D)
768static int msg_from_sgsn(int plane_idx,
769 struct osmo_sockaddr *_sgsn_sender,
770 struct osmo_sockaddr *ggsn_receiver,
771 const char *hex_from_sgsn,
772 const char *hex_to_ggsn)
773{
774 struct osmo_fd *ggsn_ofd = NULL;
775 struct osmo_sockaddr ggsn_addr;
776 int send;
777 send = gtphub_from_sgsns_handle_buf(hub, plane_idx, _sgsn_sender, buf,
778 msg(hex_from_sgsn), now,
779 &reply_buf, &ggsn_ofd, &ggsn_addr);
780 LVL2_ASSERT(send > 0);
781 LVL2_ASSERT(same_addr(&ggsn_addr, ggsn_receiver));
782 LVL2_ASSERT(reply_is(hex_to_ggsn));
783 return 1;
784}
785
786#define msg_from_ggsn_c(A,B,C,D) msg_from_ggsn(GTPH_PLANE_CTRL, A,B,C,D)
787#define msg_from_ggsn_u(A,B,C,D) msg_from_ggsn(GTPH_PLANE_USER, A,B,C,D)
788static int msg_from_ggsn(int plane_idx,
789 struct osmo_sockaddr *ggsn_sender,
790 struct osmo_sockaddr *sgsn_receiver,
791 const char *msg_from_ggsn,
792 const char *msg_to_sgsn)
793{
794 struct osmo_fd *sgsn_ofd;
795 struct osmo_sockaddr sgsn_addr;
796 int send;
797 send = gtphub_from_ggsns_handle_buf(hub, plane_idx, ggsn_sender, buf,
798 msg(msg_from_ggsn), now,
799 &reply_buf, &sgsn_ofd, &sgsn_addr);
800 LVL2_ASSERT(send > 0);
801 LVL2_ASSERT(same_addr(&sgsn_addr, sgsn_receiver));
802 LVL2_ASSERT(reply_is(msg_to_sgsn));
803 return 1;
804}
805
806static int create_pdp_ctx()
807{
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100808 const char *gtp_req_from_sgsn =
809 MSG_PDP_CTX_REQ("0068",
810 "abcd",
811 "60",
812 "42000121436587f9",
813 "00000123",
814 "00000321",
815 "0009""08696e7465726e6574", /* "(8)internet" */
816 "0004""c0a82a17", /* same as default sgsn_sender */
817 "0004""c0a82a17"
818 );
819 const char *gtp_req_to_ggsn =
820 MSG_PDP_CTX_REQ("0068",
821 "6d31", /* mapped seq ("abcd") */
822 "60",
823 "42000121436587f9",
824 "00000001", /* mapped TEI Data I ("123") */
825 "00000001", /* mapped TEI Control ("321") */
826 "0009""08696e7465726e6574",
827 "0004""7f000201", /* replaced with gtphub's ggsn ctrl */
828 "0004""7f000202" /* replaced with gtphub's ggsn user */
829 );
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100830
831 LVL2_ASSERT(msg_from_sgsn_c(&sgsn_sender,
832 &resolved_ggsn_addr,
833 gtp_req_from_sgsn,
834 gtp_req_to_ggsn));
835 LVL2_ASSERT(was_resolved_for("240010123456789", "internet"));
836
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100837 const char *gtp_resp_from_ggsn =
838 MSG_PDP_CTX_RSP("004e",
839 "00000001", /* destination TEI (sent in req above) */
840 "6d31", /* mapped seq */
841 "01", /* restart */
842 "00000567", /* TEI U */
843 "00000765", /* TEI C */
844 "0004""c0a82b22", /* GSN addresses */
845 "0004""c0a82b22" /* (== resolved_ggsn_addr) */
846 );
847 const char *gtp_resp_to_sgsn =
848 MSG_PDP_CTX_RSP("004e",
849 "00000321", /* unmapped TEI ("001") */
850 "abcd", /* unmapped seq ("6d31") */
851 "01",
852 "00000002", /* mapped TEI from GGSN ("567") */
853 "00000002", /* mapped TEI from GGSN ("765") */
854 "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */
855 "0004""7f000102" /* gtphub's address towards SGSNs (User) */
856 );
Neels Hofmeyre921e322015-11-11 00:45:50 +0100857 /* The response should go back to whichever port the request came from
858 * (unmapped by sequence nr) */
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100859 LVL2_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr,
860 &sgsn_sender,
861 gtp_resp_from_ggsn,
862 gtp_resp_to_sgsn));
863
864 return 1;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200865}
866
867static void test_create_pdp_ctx(void)
868{
Neels Hofmeyre921e322015-11-11 00:45:50 +0100869 LOG("test_create_pdp_ctx");
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100870 OSMO_ASSERT(setup_test_hub());
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200871
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100872 OSMO_ASSERT(create_pdp_ctx());
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200873
874 struct gtphub_peer_port *ggsn_port =
875 gtphub_port_find_sa(&hub->to_ggsns[GTPH_PLANE_CTRL],
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100876 &resolved_ggsn_addr);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200877 OSMO_ASSERT(ggsn_port);
878 struct gtphub_peer *ggsn = ggsn_port->peer_addr->peer;
879 /* now == 345; now + 30 == 375.
880 * seq mapping from above:
881 * 0xabcd == 43981 (sent in the packet)
882 * 0x6d31 == 27953 (harcoded seq mapping start val) */
883 OSMO_ASSERT(nr_map_is(&ggsn->seq_map, "(43981->27953@375), "));
884
885 /* now == 345; now + (6 * 60 * 60) == 21600 + 345 == 21945.
886 * 0x00000321 == 801 (TEI from SGSN Ctrl)
887 * 0x00000123 == 291 (TEI from SGSN User)
888 * 0x00000765 == 1893 (TEI from GGSN Ctrl)
889 * 0x00000567 == 1383 (TEI from GGSN User)
890 * Mapped TEIs should be 1 and 2. */
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100891 OSMO_ASSERT(nr_map_is(&hub->tei_map[GTPH_PLANE_CTRL],
892 "(801->1@21945), (1893->2@21945), "));
893 OSMO_ASSERT(nr_map_is(&hub->tei_map[GTPH_PLANE_USER],
894 "(291->1@21945), (1383->2@21945), "));
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200895
896 gtphub_gc(hub, now + EXPIRE_ALL);
897}
898
Neels Hofmeyre921e322015-11-11 00:45:50 +0100899static void test_user_data(void)
900{
901 LOG("test_user_data");
902
903 OSMO_ASSERT(setup_test_hub());
904
905 OSMO_ASSERT(create_pdp_ctx());
906
907 LOG("- user data starts");
908 /* Now expect default port numbers for User. */
909 resolve_to_ggsn("192.168.43.34", 2152);
910 resolve_to_sgsn("192.168.42.23", 2152);
911
912 const char *u_from_ggsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100913 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyre921e322015-11-11 00:45:50 +0100914 "ff" /* type 255: G-PDU */
915 "0058" /* length: 88 + 8 octets == 96 */
916 "00000001" /* mapped User TEI for SGSN from create_pdp_ctx() */
917 "0070" /* seq */
918 "0000" /* No extensions */
919 /* User data (ICMP packet), 96 - 12 = 84 octets */
920 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
921 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
922 "202122232425262728292a2b2c2d2e2f3031323334353637"
923 ;
924 const char *u_to_sgsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100925 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyre921e322015-11-11 00:45:50 +0100926 "ff" /* type 255: G-PDU */
927 "0058" /* length: 88 + 8 octets == 96 */
928 "00000123" /* unmapped User TEI */
929 "6d31" /* new mapped seq */
930 "0000"
931 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
932 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
933 "202122232425262728292a2b2c2d2e2f3031323334353637"
934 ;
935
936 /* This depends on create_pdp_ctx() sending resolved_sgsn_addr as GSN
937 * Address IEs in the GGSN's Create PDP Ctx Response. */
938 OSMO_ASSERT(msg_from_ggsn_u(&ggsn_sender,
939 &resolved_sgsn_addr,
940 u_from_ggsn,
941 u_to_sgsn));
942
943 const char *u_from_sgsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100944 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyre921e322015-11-11 00:45:50 +0100945 "ff" /* type 255: G-PDU */
946 "0058" /* length: 88 + 8 octets == 96 */
947 "00000002" /* mapped User TEI for GGSN from create_pdp_ctx() */
948 "6d31" /* mapped seq */
949 "0000" /* No extensions */
950 /* User data (ICMP packet), 96 - 12 = 84 octets */
951 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
952 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
953 "202122232425262728292a2b2c2d2e2f3031323334353637"
954 ;
955 const char *u_to_ggsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100956 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyre921e322015-11-11 00:45:50 +0100957 "ff" /* type 255: G-PDU */
958 "0058" /* length: 88 + 8 octets == 96 */
959 "00000567" /* unmapped User TEI */
960 "0070" /* unmapped seq */
961 "0000"
962 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
963 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
964 "202122232425262728292a2b2c2d2e2f3031323334353637"
965 ;
966
967 OSMO_ASSERT(msg_from_sgsn_u(&resolved_sgsn_addr,
968 &ggsn_sender,
969 u_from_sgsn,
970 u_to_ggsn));
971
972 gtphub_gc(hub, now + EXPIRE_ALL);
973}
974
975
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200976static struct log_info_cat gtphub_categories[] = {
977 [DGTPHUB] = {
978 .name = "DGTPHUB",
979 .description = "GTP Hub",
980 .color = "\033[1;33m",
981 .enabled = 1, .loglevel = LOGL_NOTICE,
982 },
983};
984
985static struct log_info info = {
986 .cat = gtphub_categories,
987 .num_cat = ARRAY_SIZE(gtphub_categories),
988};
989
990int main(int argc, char **argv)
991{
992 osmo_init_logging(&info);
993 osmo_gtphub_ctx = talloc_named_const(NULL, 0, "osmo_gtphub");
994
995 test_nr_map_basic();
996 test_expiry();
997 test_echo();
998 test_create_pdp_ctx();
Neels Hofmeyre921e322015-11-11 00:45:50 +0100999 test_user_data();
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001000 printf("Done\n");
1001
1002 talloc_report_full(osmo_gtphub_ctx, stderr);
1003 OSMO_ASSERT(talloc_total_blocks(osmo_gtphub_ctx) == 1);
1004 return 0;
1005}
1006