blob: f983f06156e7846416c90b241348e414cf167ba2 [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
Neels Hofmeyre2ed8e62015-11-17 14:30:37 +0100160 nr_pool_init(pool, 1, 1000);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200161 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) {
Neels Hofmeyr334af5d2015-11-17 14:24:46 +0100236 size_t wrote = snprintf(pos, len, "(%u->%u@%d), ",
237 m->orig,
238 m->repl,
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200239 (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
Neels Hofmeyre2ed8e62015-11-17 14:30:37 +0100256static int test_nr_map_wrap_with(nr_t nr_min, nr_t nr_max, nr_t repl_last,
257 nr_t orig_start, int orig_n,
258 const char *expect)
259{
260 struct nr_pool _pool;
261 struct nr_pool *pool = &_pool;
262 struct nr_map _map;
263 struct nr_map *map = &_map;
264
265 nr_pool_init(pool, nr_min, nr_max);
266 nr_map_init(map, pool, NULL);
267
268 pool->last_nr = repl_last;
269
270 void *origin = (void*)0x1234;
271
272 int i;
273 for (i = 0; i < orig_n; i++)
274 LVL2_ASSERT(nr_map_have(map, origin, orig_start + i, 0));
275
276 LVL2_ASSERT(nr_map_is(map, expect));
277
278 nr_map_clear(map);
279 return 1;
280}
281
282static void test_nr_map_wrap(void)
283{
284 OSMO_ASSERT(test_nr_map_wrap_with(
285 0, UINT_MAX, UINT_MAX - 2,
286 1, 5,
287 "(1->4294967294@0), "
288 "(2->4294967295@0), "
289 "(3->0@0), "
290 "(4->1@0), "
291 "(5->2@0), "
292 ));
293 OSMO_ASSERT(test_nr_map_wrap_with(
294 5, 10, 8,
295 1, 5,
296 "(1->9@0), (2->10@0), (3->5@0), (4->6@0), (5->7@0), "
297 ));
298}
299
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200300static void test_expiry(void)
301{
302 struct expiry expiry;
303 struct nr_pool pool;
304 struct nr_map map;
305 int i;
306
307 expiry_init(&expiry, 30);
Neels Hofmeyre2ed8e62015-11-17 14:30:37 +0100308 nr_pool_init(&pool, 1, 1000);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200309 nr_map_init(&map, &pool, &expiry);
310 OSMO_ASSERT(nr_map_is(&map, ""));
311
312 /* tick on empty map */
313 OSMO_ASSERT(expiry_tick(&expiry, 10000) == 0);
314 OSMO_ASSERT(nr_map_is(&map, ""));
315
316#define MAP1 \
317 "(10->1@10040), " \
318 ""
319
320#define MAP2 \
321 "(20->2@10050), " \
322 "(21->3@10051), " \
323 "(22->4@10052), " \
324 "(23->5@10053), " \
325 "(24->6@10054), " \
326 "(25->7@10055), " \
327 "(26->8@10056), " \
328 "(27->9@10057), " \
329 ""
330
331#define MAP3 \
332 "(420->10@10072), " \
333 "(421->11@10072), " \
334 "(422->12@10072), " \
335 "(423->13@10072), " \
336 "(424->14@10072), " \
337 "(425->15@10072), " \
338 "(426->16@10072), " \
339 "(427->17@10072), " \
340 ""
341
342 /* add mapping at time 10010. */
343 nr_map_have(&map, 0, 10, 10010);
344 OSMO_ASSERT(nr_map_is(&map, MAP1));
345
346 /* tick on unexpired item. */
347 OSMO_ASSERT(expiry_tick(&expiry, 10010) == 0);
348 OSMO_ASSERT(expiry_tick(&expiry, 10011) == 0);
349 OSMO_ASSERT(nr_map_is(&map, MAP1));
350
351 /* Spread mappings at 10020, 10021, ... 10027. */
352 for (i = 0; i < 8; i++)
353 nr_map_have(&map, 0, 20 + i, 10020 + i);
354 OSMO_ASSERT(nr_map_is(&map, MAP1 MAP2));
355
356 /* tick on unexpired items. */
357 OSMO_ASSERT(expiry_tick(&expiry, 10030) == 0);
358 OSMO_ASSERT(expiry_tick(&expiry, 10039) == 0);
359 OSMO_ASSERT(nr_map_is(&map, MAP1 MAP2));
360
361 /* expire the first item (from 10010). */
362 OSMO_ASSERT(expiry_tick(&expiry, 10010 + 30) == 1);
363 OSMO_ASSERT(nr_map_is(&map, MAP2));
364
365 /* again nothing to expire */
366 OSMO_ASSERT(expiry_tick(&expiry, 10041) == 0);
367 OSMO_ASSERT(nr_map_is(&map, MAP2));
368
369 /* Mappings all at the same time. */
370 for (i = 0; i < 8; i++)
371 nr_map_have(&map, 0, 420 + i, 10042);
372 OSMO_ASSERT(nr_map_is(&map, MAP2 MAP3));
373
374 /* Eight to expire, were added further above to be chronologically
375 * correct, at 10020..10027. */
376 OSMO_ASSERT(expiry_tick(&expiry, 10027 + 30) == 8);
377 OSMO_ASSERT(nr_map_is(&map, MAP3));
378
379 /* again nothing to expire */
380 OSMO_ASSERT(expiry_tick(&expiry, 10027 + 30) == 0);
381 OSMO_ASSERT(nr_map_is(&map, MAP3));
382
383 /* Eight to expire, from 10042. Now at 10042 + 30: */
384 OSMO_ASSERT(expiry_tick(&expiry, 10042 + 30) == 8);
385 OSMO_ASSERT(nr_map_is(&map, ""));
386
387#undef MAP1
388#undef MAP2
389#undef MAP3
390}
391
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100392char resolve_ggsn_got_imsi[GSM_IMSI_LENGTH];
393char resolve_ggsn_got_ni[GSM_APN_LENGTH];
394
395struct osmo_sockaddr resolved_ggsn_addr;
396static int resolve_to_ggsn(const char *addr, uint16_t port)
397{
398 LVL2_ASSERT(osmo_sockaddr_init_udp(&resolved_ggsn_addr,
399 addr, port)
400 == 0);
401 return 1;
402}
403
Neels Hofmeyre921e322015-11-11 00:45:50 +0100404struct osmo_sockaddr resolved_sgsn_addr;
405static int resolve_to_sgsn(const char *addr, uint16_t port)
406{
407 LVL2_ASSERT(osmo_sockaddr_init_udp(&resolved_sgsn_addr,
408 addr, port)
409 == 0);
410 return 1;
411}
412
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100413struct osmo_sockaddr sgsn_sender;
414static int send_from_sgsn(const char *addr, uint16_t port)
415{
416 LVL2_ASSERT(osmo_sockaddr_init_udp(&sgsn_sender,
417 addr, port)
418 == 0);
419 return 1;
420}
421
Neels Hofmeyre921e322015-11-11 00:45:50 +0100422struct osmo_sockaddr ggsn_sender;
423static int send_from_ggsn(const char *addr, uint16_t port)
424{
425 LVL2_ASSERT(osmo_sockaddr_init_udp(&ggsn_sender,
426 addr, port)
427 == 0);
428 return 1;
429}
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200430
431
432/* override, requires '-Wl,--wrap=gtphub_resolve_ggsn_addr' */
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100433struct gtphub_peer_port *__real_gtphub_resolve_ggsn_addr(struct gtphub *hub,
434 const char *imsi_str,
435 const char *apn_ni_str);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200436
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100437struct gtphub_peer_port *__wrap_gtphub_resolve_ggsn_addr(struct gtphub *hub,
438 const char *imsi_str,
439 const char *apn_ni_str)
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200440{
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100441 struct gsn_addr resolved_gsna;
442 uint16_t resolved_port;
443
444 OSMO_ASSERT(gsn_addr_from_sockaddr(&resolved_gsna, &resolved_port,
445 &resolved_ggsn_addr) == 0);
446
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100447 struct gtphub_peer_port *pp;
448 pp = gtphub_port_have(hub, &hub->to_ggsns[GTPH_PLANE_CTRL],
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100449 &resolved_gsna, resolved_port);
Neels Hofmeyre921e322015-11-11 00:45:50 +0100450 printf("- __wrap_gtphub_resolve_ggsn_addr():\n"
451 " returning GGSN addr from imsi %s ni %s: %s\n",
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100452 imsi_str, apn_ni_str, gtphub_port_str(pp));
453
454 if (imsi_str) {
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100455 strncpy(resolve_ggsn_got_imsi, imsi_str,
456 sizeof(resolve_ggsn_got_imsi));
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100457 resolve_ggsn_got_imsi[sizeof(resolve_ggsn_got_imsi) - 1] = '\0';
458 }
459 else
460 strcpy(resolve_ggsn_got_imsi, "(null)");
461
462 if (apn_ni_str) {
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100463 strncpy(resolve_ggsn_got_ni, apn_ni_str,
464 sizeof(resolve_ggsn_got_ni));
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100465 resolve_ggsn_got_ni[sizeof(resolve_ggsn_got_ni) - 1] = '\0';
466 }
467 else
468 strcpy(resolve_ggsn_got_ni, "(null)");
469
470 return pp;
471}
472
473#define was_resolved_for(IMSI,NI) _was_resolved_for(IMSI, NI, __FILE__, __LINE__)
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100474static int _was_resolved_for(const char *imsi, const char *ni, const char
475 *file, int line)
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100476{
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100477 int cmp0 = strncmp(imsi, resolve_ggsn_got_imsi,
478 sizeof(resolve_ggsn_got_imsi));
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100479
480 if (cmp0 != 0) {
481 printf("\n%s:%d: was_resolved_for(): MISMATCH for IMSI\n"
482 " expecting: '%s'\n"
483 " got: '%s'\n\n",
484 file,
485 line,
486 imsi, resolve_ggsn_got_imsi);
487 }
488
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100489 int cmp1 = strncmp(ni, resolve_ggsn_got_ni,
490 sizeof(resolve_ggsn_got_ni));
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100491 if (cmp1 != 0) {
492 printf("\n%s:%d: was_resolved_for(): MISMATCH for NI\n"
493 " expecting: '%s'\n"
494 " got: '%s'\n\n",
495 file,
496 line,
497 ni, resolve_ggsn_got_ni);
498 }
499
500 return (cmp0 == 0) && (cmp1 == 0);
501}
502
503/* override, requires '-Wl,--wrap=gtphub_ares_init' */
504int __real_gtphub_ares_init(struct gtphub *hub);
505
506int __wrap_gtphub_ares_init(struct gtphub *hub)
507{
508 /* Do nothing. */
509 return 0;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200510}
511
512#define buf_len 1024
513static uint8_t buf[buf_len];
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100514static uint8_t *reply_buf;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200515
516static unsigned int msg(const char *hex)
517{
518 unsigned int l = osmo_hexparse(hex, buf, buf_len);
519 OSMO_ASSERT(l > 0);
520 return l;
521}
522
523/* Compare static buf to given string constant. The amount of bytes is obtained
524 * from parsing the GTP header in buf. hex must match an osmo_hexdump() of the
525 * desired message. Return 1 if size and content match. */
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100526#define reply_is(MSG) _reply_is(MSG, __FILE__, __LINE__)
527static int _reply_is(const char *hex, const char *file, int line)
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200528{
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100529 struct gtp1_header_long *h = (void*)reply_buf;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200530 int len = ntoh16(h->length) + 8;
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100531 const char *dump = osmo_hexdump_nospc(reply_buf, len);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200532 int cmp = strcmp(dump, hex);
533
534 if (cmp != 0) {
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100535 printf("\n%s:%d: reply_is(): MISMATCH\n"
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200536 " expecting:\n'%s'\n"
537 " got:\n'%s'\n\n",
538 file,
539 line,
540 hex, dump);
541 int i;
542 int l = strlen(hex);
543 int m = strlen(dump);
544 if (m < l)
545 l = m;
546 for (i = 0; i < l; i++) {
547 if (hex[i] != dump[i]) {
548 printf("First mismatch at position %d:\n"
549 " %s\n %s\n", i, hex + i, dump + i);
550 break;
551 }
552 }
553 }
554 return cmp == 0;
555}
556
557#define same_addr(GOT, EXPECTED) _same_addr((GOT),(EXPECTED), __FILE__, __LINE__)
558static int _same_addr(const struct osmo_sockaddr *got,
559 const struct osmo_sockaddr *expected,
560 const char *file, int line)
561{
562 int cmp = osmo_sockaddr_cmp(got, expected);
563 if (!cmp)
564 return 1;
565 char buf[256];
566 printf("\n%s:%d: addr_is(): MISMATCH\n"
567 " expecting: '%s'\n"
568 " got: '%s'\n\n",
569 file, line,
570 osmo_sockaddr_to_str(expected),
571 osmo_sockaddr_to_strb(got, buf, sizeof(buf)));
572 return 0;
573}
574
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100575
576time_t now;
577static struct gtphub _hub;
578static struct gtphub *hub = &_hub;
579
580static int setup_test_hub()
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200581{
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100582 /* Not really needed, but to make 100% sure... */
583 ZERO_STRUCT(hub);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200584
585 gtphub_init(hub);
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100586
587 /* Tell this mock gtphub its local address for this test. */
588 LVL2_ASSERT(gsn_addr_from_str(&hub->to_sgsns[GTPH_PLANE_CTRL].local_addr,
589 "127.0.1.1") == 0);
590 LVL2_ASSERT(gsn_addr_from_str(&hub->to_sgsns[GTPH_PLANE_USER].local_addr,
591 "127.0.1.2") == 0);
592 LVL2_ASSERT(gsn_addr_from_str(&hub->to_ggsns[GTPH_PLANE_CTRL].local_addr,
593 "127.0.2.1") == 0);
594 LVL2_ASSERT(gsn_addr_from_str(&hub->to_ggsns[GTPH_PLANE_USER].local_addr,
595 "127.0.2.2") == 0);
596
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100597 hub->restart_counter = 0x23;
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100598 now = 345;
599 LVL2_ASSERT(send_from_sgsn("192.168.42.23", 423));
Neels Hofmeyre921e322015-11-11 00:45:50 +0100600 LVL2_ASSERT(resolve_to_ggsn("192.168.43.34", 2123));
601 LVL2_ASSERT(send_from_ggsn("192.168.43.34", 321));
602 LVL2_ASSERT(resolve_to_sgsn("192.168.42.23", 2123));
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100603
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100604#define GGSNS_CTRL_FD 1
605#define GGSNS_USER_FD 2
606#define SGSNS_CTRL_FD 3
607#define SGSNS_USER_FD 4
608 hub->to_ggsns[GTPH_PLANE_CTRL].ofd.priv_nr = GGSNS_CTRL_FD;
609 hub->to_ggsns[GTPH_PLANE_USER].ofd.priv_nr = GGSNS_USER_FD;
610 hub->to_sgsns[GTPH_PLANE_CTRL].ofd.priv_nr = SGSNS_CTRL_FD;
611 hub->to_sgsns[GTPH_PLANE_USER].ofd.priv_nr = SGSNS_USER_FD;
612
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100613 return 1;
614}
615
616
617static void test_echo(void)
618{
Neels Hofmeyre921e322015-11-11 00:45:50 +0100619 LOG("test_echo");
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100620 OSMO_ASSERT(setup_test_hub());
621
622 now = 123;
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100623
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100624 struct osmo_fd *to_ofd;
625 struct osmo_sockaddr to_addr;
626 struct gtphub_peer_port *pp;
627 int send;
628
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200629 const char *gtp_ping_from_sgsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100630 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200631 "01" /* type 01: Echo request */
632 "0004" /* length of 4 after header TEI */
633 "00000000" /* header TEI == 0 in Echo */
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100634 "abcd" /* some 2 octet sequence nr */
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200635 "0000" /* N-PDU 0, no extension header (why is this here?) */
636 ;
637
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100638 const char *gtp_pong_to_sgsn =
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200639 "32"
640 "02" /* type 02: Echo response */
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100641 "0006" /* length of 6 after header TEI */
642 "00000000" /* header TEI == 0 in Echo */
643 "abcd" /* same sequence nr */
644 "0000"
645 "0e23" /* Recovery with restart counter */
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200646 ;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200647
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100648 to_ofd = NULL;
649 ZERO_STRUCT(&to_addr);
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100650 send = gtphub_from_sgsns_handle_buf(hub, GTPH_PLANE_CTRL, &sgsn_sender,
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200651 buf, msg(gtp_ping_from_sgsn), now,
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100652 &reply_buf, &to_ofd, &to_addr);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200653 OSMO_ASSERT(send > 0);
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100654 OSMO_ASSERT(to_addr.l);
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100655 OSMO_ASSERT(same_addr(&to_addr, &sgsn_sender));
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100656 OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == SGSNS_CTRL_FD));
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100657 OSMO_ASSERT(reply_is(gtp_pong_to_sgsn));
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200658
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100659 pp = gtphub_port_find_sa(&hub->to_sgsns[GTPH_PLANE_CTRL],
660 &sgsn_sender);
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100661 /* We don't record Echo peers. */
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100662 OSMO_ASSERT(!pp);
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100663
664 const char *gtp_ping_from_ggsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100665 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100666 "01" /* type 01: Echo request */
667 "0004" /* length of 4 after header TEI */
668 "00000000" /* header TEI == 0 in Echo */
669 "cdef" /* some 2 octet sequence nr */
670 "0000" /* N-PDU 0, no extension header (why is this here?) */
671 ;
672
673 const char *gtp_pong_to_ggsn =
674 "32"
675 "02" /* type 02: Echo response */
676 "0006" /* length of 6 after header TEI */
677 "00000000" /* header TEI == 0 in Echo */
678 "cdef" /* same sequence nr */
679 "0000"
680 "0e23" /* Recovery with restart counter */
681 ;
682
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100683 to_ofd = NULL;
684 ZERO_STRUCT(&to_addr);
Neels Hofmeyre921e322015-11-11 00:45:50 +0100685 send = gtphub_from_ggsns_handle_buf(hub, GTPH_PLANE_CTRL, &ggsn_sender,
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100686 buf, msg(gtp_ping_from_ggsn), now,
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100687 &reply_buf, &to_ofd, &to_addr);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200688 OSMO_ASSERT(send > 0);
Neels Hofmeyre921e322015-11-11 00:45:50 +0100689 OSMO_ASSERT(same_addr(&to_addr, &ggsn_sender));
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100690 OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == GGSNS_CTRL_FD));
Neels Hofmeyrbb3d6782015-11-09 15:12:25 +0100691 OSMO_ASSERT(reply_is(gtp_pong_to_ggsn));
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200692
Neels Hofmeyr6187e012015-11-20 00:57:05 +0100693 pp = gtphub_port_find_sa(&hub->to_ggsns[GTPH_PLANE_CTRL],
694 &sgsn_sender);
695 OSMO_ASSERT(!pp);
696
697
698 /* And all the same on the user plane. */
699
700 to_ofd = NULL;
701 ZERO_STRUCT(&to_addr);
702 send = gtphub_from_sgsns_handle_buf(hub, GTPH_PLANE_USER, &sgsn_sender,
703 buf, msg(gtp_ping_from_sgsn), now,
704 &reply_buf, &to_ofd, &to_addr);
705 OSMO_ASSERT(send > 0);
706 OSMO_ASSERT(to_addr.l);
707 OSMO_ASSERT(same_addr(&to_addr, &sgsn_sender));
708 OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == SGSNS_USER_FD));
709 OSMO_ASSERT(reply_is(gtp_pong_to_sgsn));
710
711 pp = gtphub_port_find_sa(&hub->to_sgsns[GTPH_PLANE_USER],
712 &sgsn_sender);
713 OSMO_ASSERT(!pp);
714
715 to_ofd = NULL;
716 ZERO_STRUCT(&to_addr);
717 send = gtphub_from_ggsns_handle_buf(hub, GTPH_PLANE_USER, &ggsn_sender,
718 buf, msg(gtp_ping_from_ggsn), now,
719 &reply_buf, &to_ofd, &to_addr);
720 OSMO_ASSERT(send > 0);
721 OSMO_ASSERT(same_addr(&to_addr, &ggsn_sender));
722 OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == GGSNS_USER_FD));
723 OSMO_ASSERT(reply_is(gtp_pong_to_ggsn));
724
725 pp = gtphub_port_find_sa(&hub->to_ggsns[GTPH_PLANE_USER],
726 &sgsn_sender);
727 OSMO_ASSERT(!pp);
728
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200729
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100730 now += EXPIRE_ALL;
731 gtphub_gc(hub, now);
732}
733
734
735#define MSG_PDP_CTX_REQ(len, seq, restart, imsi, tei_u, tei_c, apn, gsn_c, gsn_u) \
736 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr. */ \
737 "10" /* type 16: Create PDP Context Request */ \
738 len /* msg length = 8 + len (2 octets) */ \
739 "00000000" /* No TEI yet */ \
740 seq /* Sequence nr (2 octets) */ \
741 "00" /* N-PDU 0 */ \
742 "00" /* No extensions */ \
743 /* IEs */ \
744 "0e" restart /* 14: Recovery = 96 (restart counter: 1 octet) */ \
745 "02" /* 2 = IMSI */ \
746 imsi /* (8 octets) */ \
747 "0f01" /* 15: Selection mode = MS provided APN, subscription not verified*/ \
748 "10" /* 16: TEI Data I */ \
749 tei_u /* (4 octets) */ \
750 "11" /* 17: TEI Control Plane */ \
751 tei_c /* (4 octets) */ \
752 "1400" /* 20: NSAPI = 0*/ \
753 "1a" /* 26: Charging Characteristics */ \
754 "0800" \
755 "80" /* 128: End User Address */ \
756 "0002" /* length = 2: empty PDP Address */ \
757 "f121" /* spare 0xf0, PDP organization 1, PDP type number 0x21 = 33 */ \
758 "83" /* 131: Access Point Name */ \
759 apn /* (2 octets length, N octets encoded APN-NI) */ \
760 "84" /* 132: Protocol Configuration Options */ \
761 "0015" /* length = 21 */ \
762 "80c0231101010011036d69670868656d6d656c6967" \
763 "85" /* 133: GSN Address */ \
764 gsn_c /* (2 octets length, N octets addr) */ \
765 "85" /* 133: GSN Address (second entry) */ \
766 gsn_u /* (2 octets length, N octets addr) */ \
767 "86" /* 134: MS International PSTN/ISDN Number (MSISDN) */ \
768 "0007" /* length */ \
769 "916407123254f6" /* 1946702123456(f) */ \
770 "87" /* 135: Quality of Service (QoS) Profile */ \
771 "0004" /* length */ \
772 "00" /* priority */ \
773 "0b921f" /* QoS profile data */
774
775#define MSG_PDP_CTX_RSP(len, tei_h, seq, restart, tei_u, tei_c, gsn_c, gsn_u) \
776 "32" \
777 "11" /* Create PDP Context Response */ \
778 len /* msg length = 8 + len (2 octets) */ \
779 tei_h /* destination TEI (sent in req above) */ \
780 seq /* mapped seq */ \
781 "00" "00" \
782 /* IEs */ \
783 "01" /* 1: Cause */ \
784 "80" /* value = 0b10000000 = response, no rejection. */ \
785 "08" /* 8: Reordering Required */ \
786 "00" /* not required. */ \
787 "0e" restart /* 14: Recovery = 1 */ \
788 "10" /* 16: TEI Data I */ \
789 tei_u \
790 "11" /* 17: TEI Control */ \
791 tei_c \
792 "7f" /* 127: Charging ID */ \
793 "00000001" \
794 "80" /* 128: End User Address */ \
795 "0006" /* length = 6 */ \
796 "f121" /* spare 0xf0, PDP organization 1, PDP type number 0x21 = 33 */ \
797 "7f000002" \
798 "84" /* 132: Protocol Configuration Options */ \
799 "0014" /* len = 20 */ \
800 "8080211002000010810608080808830600000000" \
801 "85" /* 133: GSN Address (Ctrl) */ \
802 gsn_c \
803 "85" /* 133: GSN Address (User) */ \
804 gsn_u \
805 "87" /* 135: Quality of Service (QoS) Profile */ \
806 "0004" /* length */ \
807 "00" /* priority */ \
808 "0b921f" /* QoS profile data */
809
810#define msg_from_sgsn_c(A,B,C,D) msg_from_sgsn(GTPH_PLANE_CTRL, A,B,C,D)
811#define msg_from_sgsn_u(A,B,C,D) msg_from_sgsn(GTPH_PLANE_USER, A,B,C,D)
812static int msg_from_sgsn(int plane_idx,
813 struct osmo_sockaddr *_sgsn_sender,
814 struct osmo_sockaddr *ggsn_receiver,
815 const char *hex_from_sgsn,
816 const char *hex_to_ggsn)
817{
818 struct osmo_fd *ggsn_ofd = NULL;
819 struct osmo_sockaddr ggsn_addr;
820 int send;
821 send = gtphub_from_sgsns_handle_buf(hub, plane_idx, _sgsn_sender, buf,
822 msg(hex_from_sgsn), now,
823 &reply_buf, &ggsn_ofd, &ggsn_addr);
824 LVL2_ASSERT(send > 0);
825 LVL2_ASSERT(same_addr(&ggsn_addr, ggsn_receiver));
826 LVL2_ASSERT(reply_is(hex_to_ggsn));
827 return 1;
828}
829
830#define msg_from_ggsn_c(A,B,C,D) msg_from_ggsn(GTPH_PLANE_CTRL, A,B,C,D)
831#define msg_from_ggsn_u(A,B,C,D) msg_from_ggsn(GTPH_PLANE_USER, A,B,C,D)
832static int msg_from_ggsn(int plane_idx,
833 struct osmo_sockaddr *ggsn_sender,
834 struct osmo_sockaddr *sgsn_receiver,
835 const char *msg_from_ggsn,
836 const char *msg_to_sgsn)
837{
838 struct osmo_fd *sgsn_ofd;
839 struct osmo_sockaddr sgsn_addr;
840 int send;
841 send = gtphub_from_ggsns_handle_buf(hub, plane_idx, ggsn_sender, buf,
842 msg(msg_from_ggsn), now,
843 &reply_buf, &sgsn_ofd, &sgsn_addr);
844 LVL2_ASSERT(send > 0);
845 LVL2_ASSERT(same_addr(&sgsn_addr, sgsn_receiver));
846 LVL2_ASSERT(reply_is(msg_to_sgsn));
847 return 1;
848}
849
850static int create_pdp_ctx()
851{
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100852 const char *gtp_req_from_sgsn =
853 MSG_PDP_CTX_REQ("0068",
854 "abcd",
855 "60",
856 "42000121436587f9",
857 "00000123",
858 "00000321",
859 "0009""08696e7465726e6574", /* "(8)internet" */
860 "0004""c0a82a17", /* same as default sgsn_sender */
861 "0004""c0a82a17"
862 );
863 const char *gtp_req_to_ggsn =
864 MSG_PDP_CTX_REQ("0068",
865 "6d31", /* mapped seq ("abcd") */
866 "60",
867 "42000121436587f9",
868 "00000001", /* mapped TEI Data I ("123") */
869 "00000001", /* mapped TEI Control ("321") */
870 "0009""08696e7465726e6574",
871 "0004""7f000201", /* replaced with gtphub's ggsn ctrl */
872 "0004""7f000202" /* replaced with gtphub's ggsn user */
873 );
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100874
875 LVL2_ASSERT(msg_from_sgsn_c(&sgsn_sender,
876 &resolved_ggsn_addr,
877 gtp_req_from_sgsn,
878 gtp_req_to_ggsn));
879 LVL2_ASSERT(was_resolved_for("240010123456789", "internet"));
880
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100881 const char *gtp_resp_from_ggsn =
882 MSG_PDP_CTX_RSP("004e",
883 "00000001", /* destination TEI (sent in req above) */
884 "6d31", /* mapped seq */
885 "01", /* restart */
886 "00000567", /* TEI U */
887 "00000765", /* TEI C */
888 "0004""c0a82b22", /* GSN addresses */
889 "0004""c0a82b22" /* (== resolved_ggsn_addr) */
890 );
891 const char *gtp_resp_to_sgsn =
892 MSG_PDP_CTX_RSP("004e",
893 "00000321", /* unmapped TEI ("001") */
894 "abcd", /* unmapped seq ("6d31") */
895 "01",
896 "00000002", /* mapped TEI from GGSN ("567") */
897 "00000002", /* mapped TEI from GGSN ("765") */
898 "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */
899 "0004""7f000102" /* gtphub's address towards SGSNs (User) */
900 );
Neels Hofmeyre921e322015-11-11 00:45:50 +0100901 /* The response should go back to whichever port the request came from
902 * (unmapped by sequence nr) */
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100903 LVL2_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr,
904 &sgsn_sender,
905 gtp_resp_from_ggsn,
906 gtp_resp_to_sgsn));
907
908 return 1;
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200909}
910
911static void test_create_pdp_ctx(void)
912{
Neels Hofmeyre921e322015-11-11 00:45:50 +0100913 LOG("test_create_pdp_ctx");
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100914 OSMO_ASSERT(setup_test_hub());
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200915
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100916 OSMO_ASSERT(create_pdp_ctx());
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200917
918 struct gtphub_peer_port *ggsn_port =
919 gtphub_port_find_sa(&hub->to_ggsns[GTPH_PLANE_CTRL],
Neels Hofmeyrc2275942015-11-10 22:07:04 +0100920 &resolved_ggsn_addr);
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200921 OSMO_ASSERT(ggsn_port);
922 struct gtphub_peer *ggsn = ggsn_port->peer_addr->peer;
923 /* now == 345; now + 30 == 375.
924 * seq mapping from above:
925 * 0xabcd == 43981 (sent in the packet)
926 * 0x6d31 == 27953 (harcoded seq mapping start val) */
927 OSMO_ASSERT(nr_map_is(&ggsn->seq_map, "(43981->27953@375), "));
928
929 /* now == 345; now + (6 * 60 * 60) == 21600 + 345 == 21945.
930 * 0x00000321 == 801 (TEI from SGSN Ctrl)
931 * 0x00000123 == 291 (TEI from SGSN User)
932 * 0x00000765 == 1893 (TEI from GGSN Ctrl)
933 * 0x00000567 == 1383 (TEI from GGSN User)
934 * Mapped TEIs should be 1 and 2. */
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100935 OSMO_ASSERT(nr_map_is(&hub->tei_map[GTPH_PLANE_CTRL],
936 "(801->1@21945), (1893->2@21945), "));
937 OSMO_ASSERT(nr_map_is(&hub->tei_map[GTPH_PLANE_USER],
938 "(291->1@21945), (1383->2@21945), "));
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +0200939
940 gtphub_gc(hub, now + EXPIRE_ALL);
941}
942
Neels Hofmeyre921e322015-11-11 00:45:50 +0100943static void test_user_data(void)
944{
945 LOG("test_user_data");
946
947 OSMO_ASSERT(setup_test_hub());
948
949 OSMO_ASSERT(create_pdp_ctx());
950
951 LOG("- user data starts");
952 /* Now expect default port numbers for User. */
953 resolve_to_ggsn("192.168.43.34", 2152);
954 resolve_to_sgsn("192.168.42.23", 2152);
955
956 const char *u_from_ggsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100957 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyre921e322015-11-11 00:45:50 +0100958 "ff" /* type 255: G-PDU */
959 "0058" /* length: 88 + 8 octets == 96 */
960 "00000001" /* mapped User TEI for SGSN from create_pdp_ctx() */
961 "0070" /* seq */
962 "0000" /* No extensions */
963 /* User data (ICMP packet), 96 - 12 = 84 octets */
964 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
965 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
966 "202122232425262728292a2b2c2d2e2f3031323334353637"
967 ;
968 const char *u_to_sgsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100969 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyre921e322015-11-11 00:45:50 +0100970 "ff" /* type 255: G-PDU */
971 "0058" /* length: 88 + 8 octets == 96 */
972 "00000123" /* unmapped User TEI */
973 "6d31" /* new mapped seq */
974 "0000"
975 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
976 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
977 "202122232425262728292a2b2c2d2e2f3031323334353637"
978 ;
979
980 /* This depends on create_pdp_ctx() sending resolved_sgsn_addr as GSN
981 * Address IEs in the GGSN's Create PDP Ctx Response. */
982 OSMO_ASSERT(msg_from_ggsn_u(&ggsn_sender,
983 &resolved_sgsn_addr,
984 u_from_ggsn,
985 u_to_sgsn));
986
987 const char *u_from_sgsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +0100988 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyre921e322015-11-11 00:45:50 +0100989 "ff" /* type 255: G-PDU */
990 "0058" /* length: 88 + 8 octets == 96 */
991 "00000002" /* mapped User TEI for GGSN from create_pdp_ctx() */
992 "6d31" /* mapped seq */
993 "0000" /* No extensions */
994 /* User data (ICMP packet), 96 - 12 = 84 octets */
995 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
996 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
997 "202122232425262728292a2b2c2d2e2f3031323334353637"
998 ;
999 const char *u_to_ggsn =
Neels Hofmeyr9cfe0372015-11-16 14:52:05 +01001000 "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */
Neels Hofmeyre921e322015-11-11 00:45:50 +01001001 "ff" /* type 255: G-PDU */
1002 "0058" /* length: 88 + 8 octets == 96 */
1003 "00000567" /* unmapped User TEI */
1004 "0070" /* unmapped seq */
1005 "0000"
1006 "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8"
1007 "4156000000007241010000000000101112131415161718191a1b1c1d1e1f"
1008 "202122232425262728292a2b2c2d2e2f3031323334353637"
1009 ;
1010
1011 OSMO_ASSERT(msg_from_sgsn_u(&resolved_sgsn_addr,
1012 &ggsn_sender,
1013 u_from_sgsn,
1014 u_to_ggsn));
1015
1016 gtphub_gc(hub, now + EXPIRE_ALL);
1017}
1018
1019
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001020static struct log_info_cat gtphub_categories[] = {
1021 [DGTPHUB] = {
1022 .name = "DGTPHUB",
1023 .description = "GTP Hub",
1024 .color = "\033[1;33m",
1025 .enabled = 1, .loglevel = LOGL_NOTICE,
1026 },
1027};
1028
1029static struct log_info info = {
1030 .cat = gtphub_categories,
1031 .num_cat = ARRAY_SIZE(gtphub_categories),
1032};
1033
1034int main(int argc, char **argv)
1035{
1036 osmo_init_logging(&info);
1037 osmo_gtphub_ctx = talloc_named_const(NULL, 0, "osmo_gtphub");
1038
1039 test_nr_map_basic();
Neels Hofmeyre2ed8e62015-11-17 14:30:37 +01001040 test_nr_map_wrap();
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001041 test_expiry();
1042 test_echo();
1043 test_create_pdp_ctx();
Neels Hofmeyre921e322015-11-11 00:45:50 +01001044 test_user_data();
Neels Hofmeyrc8a614d2015-09-24 17:32:30 +02001045 printf("Done\n");
1046
1047 talloc_report_full(osmo_gtphub_ctx, stderr);
1048 OSMO_ASSERT(talloc_total_blocks(osmo_gtphub_ctx) == 1);
1049 return 0;
1050}
1051