Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1 | /* 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 | |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 38 | #define ZERO_STRUCT(struct_pointer) memset(struct_pointer, '\0', \ |
| 39 | sizeof(*(struct_pointer))) |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 40 | |
| 41 | #define LVL2_ASSERT(exp) LVL2_ASSERT_R(exp, return 0) |
| 42 | #define LVL2_ASSERT_R(exp, ret) \ |
| 43 | if (!(exp)) { \ |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 44 | fprintf(stderr, "LVL2 Assert failed %s %s:%d\n", #exp, \ |
| 45 | __FILE__, __LINE__); \ |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 46 | osmo_generate_backtrace(); \ |
| 47 | ret; \ |
| 48 | } |
| 49 | |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 50 | /* Convenience makro, note: only within this C file. */ |
| 51 | #define LOG(label) \ |
Neels Hofmeyr | 39da711 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 52 | { fprintf(stderr, "\n" label "\n"); \ |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 53 | printf(label "\n"); } |
| 54 | |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 55 | void gtphub_init(struct gtphub *hub); |
Neels Hofmeyr | 21d0873 | 2015-11-20 00:08:28 +0100 | [diff] [blame] | 56 | void gtphub_free(struct gtphub *hub); |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 57 | |
| 58 | void *osmo_gtphub_ctx; |
| 59 | |
| 60 | /* TODO copied from libosmo-abis/src/subchan_demux.c, remove dup */ |
| 61 | static int llist_len(struct llist_head *head) |
| 62 | { |
| 63 | struct llist_head *entry; |
| 64 | int i = 0; |
| 65 | |
| 66 | llist_for_each(entry, head) |
| 67 | i++; |
| 68 | |
| 69 | return i; |
| 70 | } |
| 71 | |
| 72 | static void nr_mapping_free(struct expiring_item *e) |
| 73 | { |
| 74 | struct nr_mapping *m = container_of(e, struct nr_mapping, |
| 75 | expiry_entry); |
| 76 | nr_mapping_del(m); |
| 77 | talloc_free(m); |
| 78 | } |
| 79 | |
| 80 | static struct nr_mapping *nr_mapping_alloc(void) |
| 81 | { |
| 82 | struct nr_mapping *m; |
| 83 | m = talloc(osmo_gtphub_ctx, struct nr_mapping); |
| 84 | nr_mapping_init(m); |
| 85 | m->expiry_entry.del_cb = nr_mapping_free; |
| 86 | return m; |
| 87 | } |
| 88 | |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 89 | static struct nr_mapping *nr_map_have(struct nr_map *map, void *origin, |
| 90 | nr_t orig, time_t now) |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 91 | { |
| 92 | struct nr_mapping *mapping; |
| 93 | |
| 94 | mapping = nr_map_get(map, origin, orig); |
| 95 | if (!mapping) { |
| 96 | mapping = nr_mapping_alloc(); |
| 97 | mapping->origin = origin; |
| 98 | mapping->orig = orig; |
| 99 | nr_map_add(map, mapping, now); |
| 100 | } |
| 101 | |
| 102 | return mapping; |
| 103 | } |
| 104 | |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 105 | static nr_t nr_map_verify(const struct nr_map *map, void *origin, nr_t orig, |
| 106 | nr_t expect_repl) |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 107 | { |
| 108 | struct nr_mapping *m; |
| 109 | m = nr_map_get(map, origin, orig); |
| 110 | |
| 111 | if (!m) { |
| 112 | printf("mapping not found for %p %d\n", origin, orig); |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | if (m->repl != expect_repl) { |
| 117 | printf("mapping found, but nr mismatches: expect %d, got %d\n", |
| 118 | (int)expect_repl, (int)m->repl); |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | return 1; |
| 123 | } |
| 124 | |
| 125 | static int nr_map_verify_inv(const struct nr_map *map, nr_t repl, |
| 126 | void *expect_origin, nr_t expect_orig) |
| 127 | { |
| 128 | struct nr_mapping *m; |
| 129 | m = nr_map_get_inv(map, repl); |
| 130 | if (!m) { |
| 131 | printf("mapping not found for %d\n", (int)repl); |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | if (m->origin != expect_origin) { |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 136 | printf("mapping found, but origin mismatches:" |
| 137 | " expect %p, got %p\n", |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 138 | expect_origin, m->origin); |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | if (m->orig != expect_orig) { |
| 143 | printf("mapping found, but nr mismatches: expect %d, got %d\n", |
| 144 | (int)expect_orig, (int)m->orig); |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | return 1; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | static void test_nr_map_basic(void) |
| 153 | { |
| 154 | struct nr_pool _pool; |
| 155 | struct nr_pool *pool = &_pool; |
| 156 | struct nr_map _map; |
| 157 | struct nr_map *map = &_map; |
| 158 | |
Neels Hofmeyr | 6a65a8f | 2015-11-17 14:30:37 +0100 | [diff] [blame] | 159 | nr_pool_init(pool, 1, 1000); |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 160 | nr_map_init(map, pool, NULL); |
| 161 | |
| 162 | OSMO_ASSERT(llist_empty(&map->mappings)); |
| 163 | |
| 164 | #define TEST_N_HALF 100 |
| 165 | #define TEST_N (2*TEST_N_HALF) |
| 166 | #define TEST_I 123 |
| 167 | uint32_t i, check_i; |
| 168 | uint32_t m[TEST_N]; |
| 169 | struct nr_mapping *mapping; |
| 170 | |
| 171 | /* create half of TEST_N mappings from one origin */ |
| 172 | void *origin1 = (void*)0x1234; |
| 173 | for (i = 0; i < TEST_N_HALF; i++) { |
| 174 | nr_t orig = TEST_I + i; |
| 175 | mapping = nr_map_have(map, origin1, orig, 0); |
| 176 | m[i] = mapping->repl; |
| 177 | OSMO_ASSERT(m[i] != 0); |
| 178 | OSMO_ASSERT(llist_len(&map->mappings) == (i+1)); |
| 179 | for (check_i = 0; check_i < i; check_i++) |
| 180 | OSMO_ASSERT(m[check_i] != m[i]); |
| 181 | } |
| 182 | OSMO_ASSERT(llist_len(&map->mappings) == TEST_N_HALF); |
| 183 | |
| 184 | /* create another TEST_N mappings with the same original numbers, but |
| 185 | * from a different origin */ |
| 186 | void *origin2 = (void*)0x5678; |
| 187 | for (i = 0; i < TEST_N_HALF; i++) { |
| 188 | int i2 = TEST_N_HALF + i; |
| 189 | nr_t orig = TEST_I + i; |
| 190 | mapping = nr_map_have(map, origin2, orig, 0); |
| 191 | m[i2] = mapping->repl; |
| 192 | OSMO_ASSERT(m[i2] != 0); |
| 193 | OSMO_ASSERT(llist_len(&map->mappings) == (i2+1)); |
| 194 | for (check_i = 0; check_i < i2; check_i++) |
| 195 | OSMO_ASSERT(m[check_i] != m[i2]); |
| 196 | } |
| 197 | OSMO_ASSERT(llist_len(&map->mappings) == TEST_N); |
| 198 | |
| 199 | /* verify mappings */ |
| 200 | for (i = 0; i < TEST_N_HALF; i++) { |
| 201 | nr_t orig = TEST_I + i; |
| 202 | { |
| 203 | OSMO_ASSERT(nr_map_verify(map, origin1, orig, m[i])); |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 204 | OSMO_ASSERT(nr_map_verify_inv(map, m[i], origin1, |
| 205 | orig)); |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 206 | } |
| 207 | { |
| 208 | int i2 = TEST_N_HALF + i; |
| 209 | OSMO_ASSERT(nr_map_verify(map, origin2, orig, m[i2])); |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 210 | OSMO_ASSERT(nr_map_verify_inv(map, m[i2], origin2, |
| 211 | orig)); |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | |
| 215 | /* remove all mappings */ |
| 216 | for (i = 0; i < TEST_N_HALF; i++) { |
| 217 | OSMO_ASSERT(llist_len(&map->mappings) == (TEST_N - 2*i)); |
| 218 | |
| 219 | nr_t orig = TEST_I + i; |
| 220 | nr_mapping_del(nr_map_get(map, origin1, orig)); |
| 221 | nr_mapping_del(nr_map_get(map, origin2, orig)); |
| 222 | } |
| 223 | OSMO_ASSERT(llist_empty(&map->mappings)); |
| 224 | #undef TEST_N |
| 225 | #undef TEST_I |
| 226 | } |
| 227 | |
| 228 | static int nr_map_is(struct nr_map *map, const char *str) |
| 229 | { |
| 230 | static char buf[4096]; |
| 231 | char *pos = buf; |
| 232 | size_t len = sizeof(buf); |
| 233 | struct nr_mapping *m; |
| 234 | llist_for_each_entry(m, &map->mappings, entry) { |
Neels Hofmeyr | 767804d | 2015-11-17 14:24:46 +0100 | [diff] [blame] | 235 | size_t wrote = snprintf(pos, len, "(%u->%u@%d), ", |
| 236 | m->orig, |
| 237 | m->repl, |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 238 | (int)m->expiry_entry.expiry); |
| 239 | OSMO_ASSERT(wrote < len); |
| 240 | pos += wrote; |
| 241 | len -= wrote; |
| 242 | } |
| 243 | *pos = '\0'; |
| 244 | |
| 245 | if (strncmp(buf, str, sizeof(buf)) != 0) { |
| 246 | printf("FAILURE: nr_map_is() mismatches expected value:\n" |
| 247 | "expected: \"%s\"\n" |
| 248 | "is: \"%s\"\n", |
| 249 | str, buf); |
| 250 | return 0; |
| 251 | } |
| 252 | return 1; |
| 253 | } |
| 254 | |
Neels Hofmeyr | 6a65a8f | 2015-11-17 14:30:37 +0100 | [diff] [blame] | 255 | static int test_nr_map_wrap_with(nr_t nr_min, nr_t nr_max, nr_t repl_last, |
| 256 | nr_t orig_start, int orig_n, |
| 257 | const char *expect) |
| 258 | { |
| 259 | struct nr_pool _pool; |
| 260 | struct nr_pool *pool = &_pool; |
| 261 | struct nr_map _map; |
| 262 | struct nr_map *map = &_map; |
| 263 | |
| 264 | nr_pool_init(pool, nr_min, nr_max); |
| 265 | nr_map_init(map, pool, NULL); |
| 266 | |
| 267 | pool->last_nr = repl_last; |
| 268 | |
| 269 | void *origin = (void*)0x1234; |
| 270 | |
| 271 | int i; |
| 272 | for (i = 0; i < orig_n; i++) |
| 273 | LVL2_ASSERT(nr_map_have(map, origin, orig_start + i, 0)); |
| 274 | |
| 275 | LVL2_ASSERT(nr_map_is(map, expect)); |
| 276 | |
| 277 | nr_map_clear(map); |
| 278 | return 1; |
| 279 | } |
| 280 | |
| 281 | static void test_nr_map_wrap(void) |
| 282 | { |
| 283 | OSMO_ASSERT(test_nr_map_wrap_with( |
| 284 | 0, UINT_MAX, UINT_MAX - 2, |
| 285 | 1, 5, |
| 286 | "(1->4294967294@0), " |
| 287 | "(2->4294967295@0), " |
| 288 | "(3->0@0), " |
| 289 | "(4->1@0), " |
| 290 | "(5->2@0), " |
| 291 | )); |
| 292 | OSMO_ASSERT(test_nr_map_wrap_with( |
| 293 | 5, 10, 8, |
| 294 | 1, 5, |
| 295 | "(1->9@0), (2->10@0), (3->5@0), (4->6@0), (5->7@0), " |
| 296 | )); |
| 297 | } |
| 298 | |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 299 | static void test_expiry(void) |
| 300 | { |
| 301 | struct expiry expiry; |
| 302 | struct nr_pool pool; |
| 303 | struct nr_map map; |
| 304 | int i; |
| 305 | |
| 306 | expiry_init(&expiry, 30); |
Neels Hofmeyr | 6a65a8f | 2015-11-17 14:30:37 +0100 | [diff] [blame] | 307 | nr_pool_init(&pool, 1, 1000); |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 308 | nr_map_init(&map, &pool, &expiry); |
| 309 | OSMO_ASSERT(nr_map_is(&map, "")); |
| 310 | |
| 311 | /* tick on empty map */ |
| 312 | OSMO_ASSERT(expiry_tick(&expiry, 10000) == 0); |
| 313 | OSMO_ASSERT(nr_map_is(&map, "")); |
| 314 | |
| 315 | #define MAP1 \ |
| 316 | "(10->1@10040), " \ |
| 317 | "" |
| 318 | |
| 319 | #define MAP2 \ |
| 320 | "(20->2@10050), " \ |
| 321 | "(21->3@10051), " \ |
| 322 | "(22->4@10052), " \ |
| 323 | "(23->5@10053), " \ |
| 324 | "(24->6@10054), " \ |
| 325 | "(25->7@10055), " \ |
| 326 | "(26->8@10056), " \ |
| 327 | "(27->9@10057), " \ |
| 328 | "" |
| 329 | |
| 330 | #define MAP3 \ |
| 331 | "(420->10@10072), " \ |
| 332 | "(421->11@10072), " \ |
| 333 | "(422->12@10072), " \ |
| 334 | "(423->13@10072), " \ |
| 335 | "(424->14@10072), " \ |
| 336 | "(425->15@10072), " \ |
| 337 | "(426->16@10072), " \ |
| 338 | "(427->17@10072), " \ |
| 339 | "" |
| 340 | |
| 341 | /* add mapping at time 10010. */ |
| 342 | nr_map_have(&map, 0, 10, 10010); |
| 343 | OSMO_ASSERT(nr_map_is(&map, MAP1)); |
| 344 | |
| 345 | /* tick on unexpired item. */ |
| 346 | OSMO_ASSERT(expiry_tick(&expiry, 10010) == 0); |
| 347 | OSMO_ASSERT(expiry_tick(&expiry, 10011) == 0); |
| 348 | OSMO_ASSERT(nr_map_is(&map, MAP1)); |
| 349 | |
| 350 | /* Spread mappings at 10020, 10021, ... 10027. */ |
| 351 | for (i = 0; i < 8; i++) |
| 352 | nr_map_have(&map, 0, 20 + i, 10020 + i); |
| 353 | OSMO_ASSERT(nr_map_is(&map, MAP1 MAP2)); |
| 354 | |
| 355 | /* tick on unexpired items. */ |
| 356 | OSMO_ASSERT(expiry_tick(&expiry, 10030) == 0); |
| 357 | OSMO_ASSERT(expiry_tick(&expiry, 10039) == 0); |
| 358 | OSMO_ASSERT(nr_map_is(&map, MAP1 MAP2)); |
| 359 | |
| 360 | /* expire the first item (from 10010). */ |
| 361 | OSMO_ASSERT(expiry_tick(&expiry, 10010 + 30) == 1); |
| 362 | OSMO_ASSERT(nr_map_is(&map, MAP2)); |
| 363 | |
| 364 | /* again nothing to expire */ |
| 365 | OSMO_ASSERT(expiry_tick(&expiry, 10041) == 0); |
| 366 | OSMO_ASSERT(nr_map_is(&map, MAP2)); |
| 367 | |
| 368 | /* Mappings all at the same time. */ |
| 369 | for (i = 0; i < 8; i++) |
| 370 | nr_map_have(&map, 0, 420 + i, 10042); |
| 371 | OSMO_ASSERT(nr_map_is(&map, MAP2 MAP3)); |
| 372 | |
| 373 | /* Eight to expire, were added further above to be chronologically |
| 374 | * correct, at 10020..10027. */ |
| 375 | OSMO_ASSERT(expiry_tick(&expiry, 10027 + 30) == 8); |
| 376 | OSMO_ASSERT(nr_map_is(&map, MAP3)); |
| 377 | |
| 378 | /* again nothing to expire */ |
| 379 | OSMO_ASSERT(expiry_tick(&expiry, 10027 + 30) == 0); |
| 380 | OSMO_ASSERT(nr_map_is(&map, MAP3)); |
| 381 | |
| 382 | /* Eight to expire, from 10042. Now at 10042 + 30: */ |
| 383 | OSMO_ASSERT(expiry_tick(&expiry, 10042 + 30) == 8); |
| 384 | OSMO_ASSERT(nr_map_is(&map, "")); |
| 385 | |
| 386 | #undef MAP1 |
| 387 | #undef MAP2 |
| 388 | #undef MAP3 |
| 389 | } |
| 390 | |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 391 | char resolve_ggsn_got_imsi[GSM_IMSI_LENGTH]; |
| 392 | char resolve_ggsn_got_ni[GSM_APN_LENGTH]; |
| 393 | |
| 394 | struct osmo_sockaddr resolved_ggsn_addr; |
| 395 | static int resolve_to_ggsn(const char *addr, uint16_t port) |
| 396 | { |
| 397 | LVL2_ASSERT(osmo_sockaddr_init_udp(&resolved_ggsn_addr, |
| 398 | addr, port) |
| 399 | == 0); |
| 400 | return 1; |
| 401 | } |
| 402 | |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 403 | struct osmo_sockaddr resolved_sgsn_addr; |
| 404 | static int resolve_to_sgsn(const char *addr, uint16_t port) |
| 405 | { |
| 406 | LVL2_ASSERT(osmo_sockaddr_init_udp(&resolved_sgsn_addr, |
| 407 | addr, port) |
| 408 | == 0); |
| 409 | return 1; |
| 410 | } |
| 411 | |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 412 | struct osmo_sockaddr sgsn_sender; |
| 413 | static int send_from_sgsn(const char *addr, uint16_t port) |
| 414 | { |
| 415 | LVL2_ASSERT(osmo_sockaddr_init_udp(&sgsn_sender, |
| 416 | addr, port) |
| 417 | == 0); |
| 418 | return 1; |
| 419 | } |
| 420 | |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 421 | struct osmo_sockaddr ggsn_sender; |
| 422 | static int send_from_ggsn(const char *addr, uint16_t port) |
| 423 | { |
| 424 | LVL2_ASSERT(osmo_sockaddr_init_udp(&ggsn_sender, |
| 425 | addr, port) |
| 426 | == 0); |
| 427 | return 1; |
| 428 | } |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 429 | |
| 430 | |
| 431 | /* override, requires '-Wl,--wrap=gtphub_resolve_ggsn_addr' */ |
Neels Hofmeyr | f16657a | 2015-11-08 20:34:47 +0100 | [diff] [blame] | 432 | struct gtphub_peer_port *__real_gtphub_resolve_ggsn_addr(struct gtphub *hub, |
| 433 | const char *imsi_str, |
| 434 | const char *apn_ni_str); |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 435 | |
Neels Hofmeyr | f16657a | 2015-11-08 20:34:47 +0100 | [diff] [blame] | 436 | struct gtphub_peer_port *__wrap_gtphub_resolve_ggsn_addr(struct gtphub *hub, |
| 437 | const char *imsi_str, |
| 438 | const char *apn_ni_str) |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 439 | { |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 440 | struct gsn_addr resolved_gsna; |
| 441 | uint16_t resolved_port; |
| 442 | |
| 443 | OSMO_ASSERT(gsn_addr_from_sockaddr(&resolved_gsna, &resolved_port, |
| 444 | &resolved_ggsn_addr) == 0); |
| 445 | |
Neels Hofmeyr | f16657a | 2015-11-08 20:34:47 +0100 | [diff] [blame] | 446 | struct gtphub_peer_port *pp; |
Neels Hofmeyr | 5da32ac | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 447 | pp = gtphub_port_have(hub, &hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL], |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 448 | &resolved_gsna, resolved_port); |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 449 | printf("- __wrap_gtphub_resolve_ggsn_addr():\n" |
| 450 | " returning GGSN addr from imsi %s ni %s: %s\n", |
Neels Hofmeyr | f16657a | 2015-11-08 20:34:47 +0100 | [diff] [blame] | 451 | imsi_str, apn_ni_str, gtphub_port_str(pp)); |
| 452 | |
| 453 | if (imsi_str) { |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 454 | strncpy(resolve_ggsn_got_imsi, imsi_str, |
| 455 | sizeof(resolve_ggsn_got_imsi)); |
Neels Hofmeyr | f16657a | 2015-11-08 20:34:47 +0100 | [diff] [blame] | 456 | resolve_ggsn_got_imsi[sizeof(resolve_ggsn_got_imsi) - 1] = '\0'; |
| 457 | } |
| 458 | else |
| 459 | strcpy(resolve_ggsn_got_imsi, "(null)"); |
| 460 | |
| 461 | if (apn_ni_str) { |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 462 | strncpy(resolve_ggsn_got_ni, apn_ni_str, |
| 463 | sizeof(resolve_ggsn_got_ni)); |
Neels Hofmeyr | f16657a | 2015-11-08 20:34:47 +0100 | [diff] [blame] | 464 | resolve_ggsn_got_ni[sizeof(resolve_ggsn_got_ni) - 1] = '\0'; |
| 465 | } |
| 466 | else |
| 467 | strcpy(resolve_ggsn_got_ni, "(null)"); |
| 468 | |
| 469 | return pp; |
| 470 | } |
| 471 | |
| 472 | #define was_resolved_for(IMSI,NI) _was_resolved_for(IMSI, NI, __FILE__, __LINE__) |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 473 | static int _was_resolved_for(const char *imsi, const char *ni, const char |
| 474 | *file, int line) |
Neels Hofmeyr | f16657a | 2015-11-08 20:34:47 +0100 | [diff] [blame] | 475 | { |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 476 | int cmp0 = strncmp(imsi, resolve_ggsn_got_imsi, |
| 477 | sizeof(resolve_ggsn_got_imsi)); |
Neels Hofmeyr | f16657a | 2015-11-08 20:34:47 +0100 | [diff] [blame] | 478 | |
| 479 | if (cmp0 != 0) { |
| 480 | printf("\n%s:%d: was_resolved_for(): MISMATCH for IMSI\n" |
| 481 | " expecting: '%s'\n" |
| 482 | " got: '%s'\n\n", |
| 483 | file, |
| 484 | line, |
| 485 | imsi, resolve_ggsn_got_imsi); |
| 486 | } |
| 487 | |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 488 | int cmp1 = strncmp(ni, resolve_ggsn_got_ni, |
| 489 | sizeof(resolve_ggsn_got_ni)); |
Neels Hofmeyr | f16657a | 2015-11-08 20:34:47 +0100 | [diff] [blame] | 490 | if (cmp1 != 0) { |
| 491 | printf("\n%s:%d: was_resolved_for(): MISMATCH for NI\n" |
| 492 | " expecting: '%s'\n" |
| 493 | " got: '%s'\n\n", |
| 494 | file, |
| 495 | line, |
| 496 | ni, resolve_ggsn_got_ni); |
| 497 | } |
| 498 | |
| 499 | return (cmp0 == 0) && (cmp1 == 0); |
| 500 | } |
| 501 | |
| 502 | /* override, requires '-Wl,--wrap=gtphub_ares_init' */ |
| 503 | int __real_gtphub_ares_init(struct gtphub *hub); |
| 504 | |
| 505 | int __wrap_gtphub_ares_init(struct gtphub *hub) |
| 506 | { |
| 507 | /* Do nothing. */ |
| 508 | return 0; |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 509 | } |
| 510 | |
Neels Hofmeyr | f6fe212 | 2015-12-02 15:43:10 +0100 | [diff] [blame] | 511 | /* override, requires '-Wl,--wrap=gtphub_write' */ |
| 512 | int __real_gtphub_write(const struct osmo_fd *to, |
| 513 | const struct osmo_sockaddr *to_addr, |
| 514 | const uint8_t *buf, size_t buf_len); |
| 515 | |
| 516 | int __wrap_gtphub_write(const struct osmo_fd *to, |
| 517 | const struct osmo_sockaddr *to_addr, |
| 518 | const uint8_t *buf, size_t buf_len) |
| 519 | { |
| 520 | printf("Out-of-band gtphub_write(%d):\n" |
| 521 | "to %s\n" |
| 522 | "%s\n", |
| 523 | (int)buf_len, |
| 524 | osmo_sockaddr_to_str(to_addr), |
| 525 | osmo_hexdump(buf, buf_len)); |
| 526 | return 0; |
| 527 | } |
| 528 | |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 529 | #define buf_len 1024 |
| 530 | static uint8_t buf[buf_len]; |
Neels Hofmeyr | a7c1015 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 531 | static uint8_t *reply_buf; |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 532 | |
| 533 | static unsigned int msg(const char *hex) |
| 534 | { |
| 535 | unsigned int l = osmo_hexparse(hex, buf, buf_len); |
| 536 | OSMO_ASSERT(l > 0); |
| 537 | return l; |
| 538 | } |
| 539 | |
| 540 | /* Compare static buf to given string constant. The amount of bytes is obtained |
| 541 | * from parsing the GTP header in buf. hex must match an osmo_hexdump() of the |
| 542 | * desired message. Return 1 if size and content match. */ |
Neels Hofmeyr | a7c1015 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 543 | #define reply_is(MSG) _reply_is(MSG, __FILE__, __LINE__) |
| 544 | static int _reply_is(const char *hex, const char *file, int line) |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 545 | { |
Neels Hofmeyr | a7c1015 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 546 | struct gtp1_header_long *h = (void*)reply_buf; |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 547 | int len = ntoh16(h->length) + 8; |
Neels Hofmeyr | a7c1015 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 548 | const char *dump = osmo_hexdump_nospc(reply_buf, len); |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 549 | int cmp = strcmp(dump, hex); |
| 550 | |
| 551 | if (cmp != 0) { |
Neels Hofmeyr | a7c1015 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 552 | printf("\n%s:%d: reply_is(): MISMATCH\n" |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 553 | " expecting:\n'%s'\n" |
| 554 | " got:\n'%s'\n\n", |
| 555 | file, |
| 556 | line, |
| 557 | hex, dump); |
| 558 | int i; |
| 559 | int l = strlen(hex); |
| 560 | int m = strlen(dump); |
| 561 | if (m < l) |
| 562 | l = m; |
| 563 | for (i = 0; i < l; i++) { |
| 564 | if (hex[i] != dump[i]) { |
| 565 | printf("First mismatch at position %d:\n" |
| 566 | " %s\n %s\n", i, hex + i, dump + i); |
| 567 | break; |
| 568 | } |
| 569 | } |
| 570 | } |
| 571 | return cmp == 0; |
| 572 | } |
| 573 | |
| 574 | #define same_addr(GOT, EXPECTED) _same_addr((GOT),(EXPECTED), __FILE__, __LINE__) |
| 575 | static int _same_addr(const struct osmo_sockaddr *got, |
| 576 | const struct osmo_sockaddr *expected, |
| 577 | const char *file, int line) |
| 578 | { |
| 579 | int cmp = osmo_sockaddr_cmp(got, expected); |
| 580 | if (!cmp) |
| 581 | return 1; |
| 582 | char buf[256]; |
| 583 | printf("\n%s:%d: addr_is(): MISMATCH\n" |
| 584 | " expecting: '%s'\n" |
| 585 | " got: '%s'\n\n", |
| 586 | file, line, |
| 587 | osmo_sockaddr_to_str(expected), |
| 588 | osmo_sockaddr_to_strb(got, buf, sizeof(buf))); |
| 589 | return 0; |
| 590 | } |
| 591 | |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 592 | |
| 593 | time_t now; |
| 594 | static struct gtphub _hub; |
| 595 | static struct gtphub *hub = &_hub; |
| 596 | |
| 597 | static int setup_test_hub() |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 598 | { |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 599 | /* Not really needed, but to make 100% sure... */ |
| 600 | ZERO_STRUCT(hub); |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 601 | |
| 602 | gtphub_init(hub); |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 603 | |
| 604 | /* Tell this mock gtphub its local address for this test. */ |
Neels Hofmeyr | 5da32ac | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 605 | LVL2_ASSERT(gsn_addr_from_str(&hub->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_CTRL].local_addr, |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 606 | "127.0.1.1") == 0); |
Neels Hofmeyr | 5da32ac | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 607 | LVL2_ASSERT(gsn_addr_from_str(&hub->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_USER].local_addr, |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 608 | "127.0.1.2") == 0); |
Neels Hofmeyr | 5da32ac | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 609 | LVL2_ASSERT(gsn_addr_from_str(&hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL].local_addr, |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 610 | "127.0.2.1") == 0); |
Neels Hofmeyr | 5da32ac | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 611 | LVL2_ASSERT(gsn_addr_from_str(&hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_USER].local_addr, |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 612 | "127.0.2.2") == 0); |
| 613 | |
Neels Hofmeyr | a7c1015 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 614 | hub->restart_counter = 0x23; |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 615 | now = 345; |
| 616 | LVL2_ASSERT(send_from_sgsn("192.168.42.23", 423)); |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 617 | LVL2_ASSERT(resolve_to_ggsn("192.168.43.34", 2123)); |
Neels Hofmeyr | 39da711 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 618 | LVL2_ASSERT(send_from_ggsn("192.168.43.34", 434)); |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 619 | LVL2_ASSERT(resolve_to_sgsn("192.168.42.23", 2123)); |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 620 | |
Neels Hofmeyr | 0b700e3 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 621 | #define GGSNS_CTRL_FD 1 |
| 622 | #define GGSNS_USER_FD 2 |
| 623 | #define SGSNS_CTRL_FD 3 |
| 624 | #define SGSNS_USER_FD 4 |
Neels Hofmeyr | 5da32ac | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 625 | hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL].ofd.priv_nr = GGSNS_CTRL_FD; |
| 626 | hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_USER].ofd.priv_nr = GGSNS_USER_FD; |
| 627 | hub->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_CTRL].ofd.priv_nr = SGSNS_CTRL_FD; |
| 628 | hub->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_USER].ofd.priv_nr = SGSNS_USER_FD; |
Neels Hofmeyr | 0b700e3 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 629 | |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 630 | return 1; |
| 631 | } |
| 632 | |
Neels Hofmeyr | 21d0873 | 2015-11-20 00:08:28 +0100 | [diff] [blame] | 633 | static int clear_test_hub() |
| 634 | { |
| 635 | /* expire all */ |
Neels Hofmeyr | 39da711 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 636 | gtphub_gc(hub, now + (60 * GTPH_EXPIRE_SLOWLY_MINUTES) + 1); |
Neels Hofmeyr | 21d0873 | 2015-11-20 00:08:28 +0100 | [diff] [blame] | 637 | |
| 638 | int plane_idx; |
| 639 | plane_idx = GTPH_PLANE_CTRL; |
Neels Hofmeyr | 5da32ac | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 640 | LVL2_ASSERT(llist_empty(&hub->to_gsns[GTPH_SIDE_GGSN][plane_idx].peers)); |
| 641 | LVL2_ASSERT(llist_empty(&hub->to_gsns[GTPH_SIDE_SGSN][plane_idx].peers)); |
Neels Hofmeyr | 21d0873 | 2015-11-20 00:08:28 +0100 | [diff] [blame] | 642 | plane_idx = GTPH_PLANE_USER; |
Neels Hofmeyr | 5da32ac | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 643 | LVL2_ASSERT(llist_empty(&hub->to_gsns[GTPH_SIDE_GGSN][plane_idx].peers)); |
| 644 | LVL2_ASSERT(llist_empty(&hub->to_gsns[GTPH_SIDE_SGSN][plane_idx].peers)); |
Neels Hofmeyr | 21d0873 | 2015-11-20 00:08:28 +0100 | [diff] [blame] | 645 | |
Neels Hofmeyr | 0fa507a | 2015-12-02 01:15:30 +0100 | [diff] [blame] | 646 | LVL2_ASSERT(llist_empty(&hub->tunnels)); |
| 647 | LVL2_ASSERT(llist_empty(&hub->pending_deletes)); |
| 648 | LVL2_ASSERT(llist_empty(&hub->ggsn_lookups)); |
| 649 | LVL2_ASSERT(llist_empty(&hub->resolved_ggsns)); |
| 650 | |
Neels Hofmeyr | 21d0873 | 2015-11-20 00:08:28 +0100 | [diff] [blame] | 651 | gtphub_free(hub); |
| 652 | return 1; |
| 653 | } |
| 654 | |
Neels Hofmeyr | 39da711 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 655 | static int tunnels_are(const char *expect) |
| 656 | { |
| 657 | static char buf[4096]; |
| 658 | char *pos = buf; |
| 659 | size_t len = sizeof(buf); |
| 660 | struct gtphub_tunnel *t; |
| 661 | llist_for_each_entry(t, &hub->tunnels, entry) { |
| 662 | size_t wrote = snprintf(pos, len, "%s @%d\n", |
| 663 | gtphub_tunnel_str(t), |
| 664 | (int)t->expiry_entry.expiry); |
| 665 | LVL2_ASSERT(wrote < len); |
| 666 | pos += wrote; |
| 667 | len -= wrote; |
| 668 | } |
| 669 | *pos = '\0'; |
| 670 | |
| 671 | if (strncmp(buf, expect, sizeof(buf)) != 0) { |
| 672 | fprintf(stderr, "FAILURE: tunnels_are() mismatches expected value:\n" |
| 673 | "EXPECTED:\n%s\n" |
| 674 | "IS:\n%s\n", |
| 675 | expect, buf); |
| 676 | LVL2_ASSERT("tunnels do not match expected listing."); |
| 677 | return 0; |
| 678 | } |
| 679 | return 1; |
| 680 | } |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 681 | |
| 682 | static void test_echo(void) |
| 683 | { |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 684 | LOG("test_echo"); |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 685 | OSMO_ASSERT(setup_test_hub()); |
| 686 | |
| 687 | now = 123; |
Neels Hofmeyr | f16657a | 2015-11-08 20:34:47 +0100 | [diff] [blame] | 688 | |
Neels Hofmeyr | 0b700e3 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 689 | struct osmo_fd *to_ofd; |
| 690 | struct osmo_sockaddr to_addr; |
| 691 | struct gtphub_peer_port *pp; |
| 692 | int send; |
| 693 | |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 694 | const char *gtp_ping_from_sgsn = |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 695 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */ |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 696 | "01" /* type 01: Echo request */ |
| 697 | "0004" /* length of 4 after header TEI */ |
| 698 | "00000000" /* header TEI == 0 in Echo */ |
Neels Hofmeyr | a7c1015 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 699 | "abcd" /* some 2 octet sequence nr */ |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 700 | "0000" /* N-PDU 0, no extension header (why is this here?) */ |
| 701 | ; |
| 702 | |
Neels Hofmeyr | a7c1015 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 703 | const char *gtp_pong_to_sgsn = |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 704 | "32" |
| 705 | "02" /* type 02: Echo response */ |
Neels Hofmeyr | a7c1015 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 706 | "0006" /* length of 6 after header TEI */ |
| 707 | "00000000" /* header TEI == 0 in Echo */ |
| 708 | "abcd" /* same sequence nr */ |
| 709 | "0000" |
| 710 | "0e23" /* Recovery with restart counter */ |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 711 | ; |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 712 | |
Neels Hofmeyr | 0b700e3 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 713 | to_ofd = NULL; |
| 714 | ZERO_STRUCT(&to_addr); |
Neels Hofmeyr | 5da32ac | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 715 | send = gtphub_handle_buf(hub, GTPH_SIDE_SGSN, GTPH_PLANE_CTRL, |
| 716 | &sgsn_sender, buf, msg(gtp_ping_from_sgsn), |
| 717 | now, &reply_buf, &to_ofd, &to_addr); |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 718 | OSMO_ASSERT(send > 0); |
Neels Hofmeyr | a7c1015 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 719 | OSMO_ASSERT(to_addr.l); |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 720 | OSMO_ASSERT(same_addr(&to_addr, &sgsn_sender)); |
Neels Hofmeyr | 0b700e3 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 721 | OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == SGSNS_CTRL_FD)); |
Neels Hofmeyr | a7c1015 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 722 | OSMO_ASSERT(reply_is(gtp_pong_to_sgsn)); |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 723 | |
Neels Hofmeyr | 5da32ac | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 724 | pp = gtphub_port_find_sa(&hub->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_CTRL], |
Neels Hofmeyr | 0b700e3 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 725 | &sgsn_sender); |
Neels Hofmeyr | a7c1015 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 726 | /* We don't record Echo peers. */ |
Neels Hofmeyr | 0b700e3 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 727 | OSMO_ASSERT(!pp); |
Neels Hofmeyr | a7c1015 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 728 | |
| 729 | const char *gtp_ping_from_ggsn = |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 730 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */ |
Neels Hofmeyr | a7c1015 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 731 | "01" /* type 01: Echo request */ |
| 732 | "0004" /* length of 4 after header TEI */ |
| 733 | "00000000" /* header TEI == 0 in Echo */ |
| 734 | "cdef" /* some 2 octet sequence nr */ |
| 735 | "0000" /* N-PDU 0, no extension header (why is this here?) */ |
| 736 | ; |
| 737 | |
| 738 | const char *gtp_pong_to_ggsn = |
| 739 | "32" |
| 740 | "02" /* type 02: Echo response */ |
| 741 | "0006" /* length of 6 after header TEI */ |
| 742 | "00000000" /* header TEI == 0 in Echo */ |
| 743 | "cdef" /* same sequence nr */ |
| 744 | "0000" |
| 745 | "0e23" /* Recovery with restart counter */ |
| 746 | ; |
| 747 | |
Neels Hofmeyr | 0b700e3 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 748 | to_ofd = NULL; |
| 749 | ZERO_STRUCT(&to_addr); |
Neels Hofmeyr | 5da32ac | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 750 | send = gtphub_handle_buf(hub, GTPH_SIDE_GGSN, GTPH_PLANE_CTRL, |
| 751 | &ggsn_sender, buf, msg(gtp_ping_from_ggsn), |
| 752 | now, &reply_buf, &to_ofd, &to_addr); |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 753 | OSMO_ASSERT(send > 0); |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 754 | OSMO_ASSERT(same_addr(&to_addr, &ggsn_sender)); |
Neels Hofmeyr | 0b700e3 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 755 | OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == GGSNS_CTRL_FD)); |
Neels Hofmeyr | a7c1015 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 756 | OSMO_ASSERT(reply_is(gtp_pong_to_ggsn)); |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 757 | |
Neels Hofmeyr | 5da32ac | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 758 | pp = gtphub_port_find_sa(&hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL], |
Neels Hofmeyr | 0b700e3 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 759 | &sgsn_sender); |
| 760 | OSMO_ASSERT(!pp); |
| 761 | |
| 762 | |
| 763 | /* And all the same on the user plane. */ |
| 764 | |
| 765 | to_ofd = NULL; |
| 766 | ZERO_STRUCT(&to_addr); |
Neels Hofmeyr | 5da32ac | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 767 | send = gtphub_handle_buf(hub, GTPH_SIDE_SGSN, GTPH_PLANE_USER, |
| 768 | &sgsn_sender, buf, msg(gtp_ping_from_sgsn), |
| 769 | now, &reply_buf, &to_ofd, &to_addr); |
Neels Hofmeyr | 0b700e3 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 770 | OSMO_ASSERT(send > 0); |
| 771 | OSMO_ASSERT(to_addr.l); |
| 772 | OSMO_ASSERT(same_addr(&to_addr, &sgsn_sender)); |
| 773 | OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == SGSNS_USER_FD)); |
| 774 | OSMO_ASSERT(reply_is(gtp_pong_to_sgsn)); |
| 775 | |
Neels Hofmeyr | 5da32ac | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 776 | pp = gtphub_port_find_sa(&hub->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_USER], |
Neels Hofmeyr | 0b700e3 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 777 | &sgsn_sender); |
| 778 | OSMO_ASSERT(!pp); |
| 779 | |
| 780 | to_ofd = NULL; |
| 781 | ZERO_STRUCT(&to_addr); |
Neels Hofmeyr | 5da32ac | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 782 | send = gtphub_handle_buf(hub, GTPH_SIDE_GGSN, GTPH_PLANE_USER, |
| 783 | &ggsn_sender, buf, msg(gtp_ping_from_ggsn), |
| 784 | now, &reply_buf, &to_ofd, &to_addr); |
Neels Hofmeyr | 0b700e3 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 785 | OSMO_ASSERT(send > 0); |
| 786 | OSMO_ASSERT(same_addr(&to_addr, &ggsn_sender)); |
| 787 | OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == GGSNS_USER_FD)); |
| 788 | OSMO_ASSERT(reply_is(gtp_pong_to_ggsn)); |
| 789 | |
Neels Hofmeyr | 5da32ac | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 790 | pp = gtphub_port_find_sa(&hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_USER], |
Neels Hofmeyr | 0b700e3 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 791 | &sgsn_sender); |
| 792 | OSMO_ASSERT(!pp); |
| 793 | |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 794 | |
Neels Hofmeyr | 21d0873 | 2015-11-20 00:08:28 +0100 | [diff] [blame] | 795 | OSMO_ASSERT(clear_test_hub()); |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | |
| 799 | #define MSG_PDP_CTX_REQ(len, seq, restart, imsi, tei_u, tei_c, apn, gsn_c, gsn_u) \ |
| 800 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr. */ \ |
| 801 | "10" /* type 16: Create PDP Context Request */ \ |
| 802 | len /* msg length = 8 + len (2 octets) */ \ |
| 803 | "00000000" /* No TEI yet */ \ |
| 804 | seq /* Sequence nr (2 octets) */ \ |
| 805 | "00" /* N-PDU 0 */ \ |
| 806 | "00" /* No extensions */ \ |
| 807 | /* IEs */ \ |
Neels Hofmeyr | 80ee391 | 2015-11-26 22:19:22 +0100 | [diff] [blame] | 808 | "0e" restart /* 14: Recovery (restart counter: 1 octet) */ \ |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 809 | "02" /* 2 = IMSI */ \ |
| 810 | imsi /* (8 octets) */ \ |
| 811 | "0f01" /* 15: Selection mode = MS provided APN, subscription not verified*/ \ |
| 812 | "10" /* 16: TEI Data I */ \ |
| 813 | tei_u /* (4 octets) */ \ |
| 814 | "11" /* 17: TEI Control Plane */ \ |
| 815 | tei_c /* (4 octets) */ \ |
| 816 | "1400" /* 20: NSAPI = 0*/ \ |
| 817 | "1a" /* 26: Charging Characteristics */ \ |
| 818 | "0800" \ |
| 819 | "80" /* 128: End User Address */ \ |
| 820 | "0002" /* length = 2: empty PDP Address */ \ |
| 821 | "f121" /* spare 0xf0, PDP organization 1, PDP type number 0x21 = 33 */ \ |
| 822 | "83" /* 131: Access Point Name */ \ |
| 823 | apn /* (2 octets length, N octets encoded APN-NI) */ \ |
| 824 | "84" /* 132: Protocol Configuration Options */ \ |
| 825 | "0015" /* length = 21 */ \ |
| 826 | "80c0231101010011036d69670868656d6d656c6967" \ |
| 827 | "85" /* 133: GSN Address */ \ |
| 828 | gsn_c /* (2 octets length, N octets addr) */ \ |
| 829 | "85" /* 133: GSN Address (second entry) */ \ |
| 830 | gsn_u /* (2 octets length, N octets addr) */ \ |
| 831 | "86" /* 134: MS International PSTN/ISDN Number (MSISDN) */ \ |
| 832 | "0007" /* length */ \ |
| 833 | "916407123254f6" /* 1946702123456(f) */ \ |
| 834 | "87" /* 135: Quality of Service (QoS) Profile */ \ |
| 835 | "0004" /* length */ \ |
| 836 | "00" /* priority */ \ |
| 837 | "0b921f" /* QoS profile data */ |
| 838 | |
| 839 | #define MSG_PDP_CTX_RSP(len, tei_h, seq, restart, tei_u, tei_c, gsn_c, gsn_u) \ |
| 840 | "32" \ |
| 841 | "11" /* Create PDP Context Response */ \ |
| 842 | len /* msg length = 8 + len (2 octets) */ \ |
| 843 | tei_h /* destination TEI (sent in req above) */ \ |
| 844 | seq /* mapped seq */ \ |
| 845 | "00" "00" \ |
| 846 | /* IEs */ \ |
| 847 | "01" /* 1: Cause */ \ |
| 848 | "80" /* value = 0b10000000 = response, no rejection. */ \ |
| 849 | "08" /* 8: Reordering Required */ \ |
| 850 | "00" /* not required. */ \ |
Neels Hofmeyr | 80ee391 | 2015-11-26 22:19:22 +0100 | [diff] [blame] | 851 | "0e" restart /* 14: Recovery */ \ |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 852 | "10" /* 16: TEI Data I */ \ |
| 853 | tei_u \ |
| 854 | "11" /* 17: TEI Control */ \ |
| 855 | tei_c \ |
| 856 | "7f" /* 127: Charging ID */ \ |
| 857 | "00000001" \ |
| 858 | "80" /* 128: End User Address */ \ |
| 859 | "0006" /* length = 6 */ \ |
| 860 | "f121" /* spare 0xf0, PDP organization 1, PDP type number 0x21 = 33 */ \ |
| 861 | "7f000002" \ |
| 862 | "84" /* 132: Protocol Configuration Options */ \ |
| 863 | "0014" /* len = 20 */ \ |
| 864 | "8080211002000010810608080808830600000000" \ |
| 865 | "85" /* 133: GSN Address (Ctrl) */ \ |
| 866 | gsn_c \ |
| 867 | "85" /* 133: GSN Address (User) */ \ |
| 868 | gsn_u \ |
| 869 | "87" /* 135: Quality of Service (QoS) Profile */ \ |
| 870 | "0004" /* length */ \ |
| 871 | "00" /* priority */ \ |
| 872 | "0b921f" /* QoS profile data */ |
| 873 | |
| 874 | #define msg_from_sgsn_c(A,B,C,D) msg_from_sgsn(GTPH_PLANE_CTRL, A,B,C,D) |
| 875 | #define msg_from_sgsn_u(A,B,C,D) msg_from_sgsn(GTPH_PLANE_USER, A,B,C,D) |
| 876 | static int msg_from_sgsn(int plane_idx, |
| 877 | struct osmo_sockaddr *_sgsn_sender, |
| 878 | struct osmo_sockaddr *ggsn_receiver, |
| 879 | const char *hex_from_sgsn, |
| 880 | const char *hex_to_ggsn) |
| 881 | { |
| 882 | struct osmo_fd *ggsn_ofd = NULL; |
| 883 | struct osmo_sockaddr ggsn_addr; |
| 884 | int send; |
Neels Hofmeyr | 5da32ac | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 885 | send = gtphub_handle_buf(hub, GTPH_SIDE_SGSN, plane_idx, _sgsn_sender, |
| 886 | buf, msg(hex_from_sgsn), now, |
| 887 | &reply_buf, &ggsn_ofd, &ggsn_addr); |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 888 | LVL2_ASSERT(send > 0); |
| 889 | LVL2_ASSERT(same_addr(&ggsn_addr, ggsn_receiver)); |
| 890 | LVL2_ASSERT(reply_is(hex_to_ggsn)); |
| 891 | return 1; |
| 892 | } |
| 893 | |
| 894 | #define msg_from_ggsn_c(A,B,C,D) msg_from_ggsn(GTPH_PLANE_CTRL, A,B,C,D) |
| 895 | #define msg_from_ggsn_u(A,B,C,D) msg_from_ggsn(GTPH_PLANE_USER, A,B,C,D) |
| 896 | static int msg_from_ggsn(int plane_idx, |
| 897 | struct osmo_sockaddr *ggsn_sender, |
| 898 | struct osmo_sockaddr *sgsn_receiver, |
| 899 | const char *msg_from_ggsn, |
| 900 | const char *msg_to_sgsn) |
| 901 | { |
| 902 | struct osmo_fd *sgsn_ofd; |
| 903 | struct osmo_sockaddr sgsn_addr; |
| 904 | int send; |
Neels Hofmeyr | 5da32ac | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 905 | send = gtphub_handle_buf(hub, GTPH_SIDE_GGSN, plane_idx, ggsn_sender, |
| 906 | buf, msg(msg_from_ggsn), now, |
| 907 | &reply_buf, &sgsn_ofd, &sgsn_addr); |
Neels Hofmeyr | f4906e5 | 2015-12-06 23:12:02 +0100 | [diff] [blame] | 908 | if (*msg_to_sgsn) { |
| 909 | LVL2_ASSERT(send > 0); |
| 910 | LVL2_ASSERT(same_addr(&sgsn_addr, sgsn_receiver)); |
| 911 | LVL2_ASSERT(reply_is(msg_to_sgsn)); |
| 912 | } |
| 913 | else |
| 914 | LVL2_ASSERT(send == 0); |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 915 | return 1; |
| 916 | } |
| 917 | |
| 918 | static int create_pdp_ctx() |
| 919 | { |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 920 | const char *gtp_req_from_sgsn = |
| 921 | MSG_PDP_CTX_REQ("0068", |
| 922 | "abcd", |
| 923 | "60", |
| 924 | "42000121436587f9", |
| 925 | "00000123", |
| 926 | "00000321", |
| 927 | "0009""08696e7465726e6574", /* "(8)internet" */ |
| 928 | "0004""c0a82a17", /* same as default sgsn_sender */ |
| 929 | "0004""c0a82a17" |
| 930 | ); |
| 931 | const char *gtp_req_to_ggsn = |
| 932 | MSG_PDP_CTX_REQ("0068", |
| 933 | "6d31", /* mapped seq ("abcd") */ |
Neels Hofmeyr | 80ee391 | 2015-11-26 22:19:22 +0100 | [diff] [blame] | 934 | "23", |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 935 | "42000121436587f9", |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 936 | "00000001", /* Data I: tunnel's TEI */ |
| 937 | "00000001", /* Control: tunnel's TEI */ |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 938 | "0009""08696e7465726e6574", |
| 939 | "0004""7f000201", /* replaced with gtphub's ggsn ctrl */ |
| 940 | "0004""7f000202" /* replaced with gtphub's ggsn user */ |
| 941 | ); |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 942 | |
| 943 | LVL2_ASSERT(msg_from_sgsn_c(&sgsn_sender, |
| 944 | &resolved_ggsn_addr, |
| 945 | gtp_req_from_sgsn, |
| 946 | gtp_req_to_ggsn)); |
| 947 | LVL2_ASSERT(was_resolved_for("240010123456789", "internet")); |
| 948 | |
Neels Hofmeyr | 39da711 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 949 | LVL2_ASSERT(tunnels_are( |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 950 | "TEI=1:" |
| 951 | " 192.168.42.23 (TEI C=321 U=123)" |
| 952 | " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)" |
Neels Hofmeyr | 39da711 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 953 | " @21945\n")); |
| 954 | |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 955 | const char *gtp_resp_from_ggsn = |
| 956 | MSG_PDP_CTX_RSP("004e", |
| 957 | "00000001", /* destination TEI (sent in req above) */ |
| 958 | "6d31", /* mapped seq */ |
| 959 | "01", /* restart */ |
| 960 | "00000567", /* TEI U */ |
| 961 | "00000765", /* TEI C */ |
| 962 | "0004""c0a82b22", /* GSN addresses */ |
| 963 | "0004""c0a82b22" /* (== resolved_ggsn_addr) */ |
| 964 | ); |
| 965 | const char *gtp_resp_to_sgsn = |
| 966 | MSG_PDP_CTX_RSP("004e", |
| 967 | "00000321", /* unmapped TEI ("001") */ |
| 968 | "abcd", /* unmapped seq ("6d31") */ |
Neels Hofmeyr | 80ee391 | 2015-11-26 22:19:22 +0100 | [diff] [blame] | 969 | "23", |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 970 | "00000001", /* mapped TEI from GGSN ("567") */ |
| 971 | "00000001", /* mapped TEI from GGSN ("765") */ |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 972 | "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */ |
| 973 | "0004""7f000102" /* gtphub's address towards SGSNs (User) */ |
| 974 | ); |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 975 | /* The response should go back to whichever port the request came from |
| 976 | * (unmapped by sequence nr) */ |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 977 | LVL2_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr, |
| 978 | &sgsn_sender, |
| 979 | gtp_resp_from_ggsn, |
| 980 | gtp_resp_to_sgsn)); |
| 981 | |
| 982 | return 1; |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 983 | } |
| 984 | |
Neels Hofmeyr | 3c6e053 | 2015-12-01 00:23:45 +0100 | [diff] [blame] | 985 | #define MSG_DEL_PDP_CTX_REQ(tei, seq) \ |
| 986 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr. */ \ |
| 987 | "14" /* type 20: Delete PDP Context Request */ \ |
| 988 | "0008" /* msg length = 8 + len (2 octets) */ \ |
| 989 | tei /* TEI Ctrl */ \ |
| 990 | seq /* Sequence nr (2 octets) */ \ |
| 991 | "00" /* N-PDU 0 */ \ |
| 992 | "00" /* No extensions */ \ |
| 993 | /* IEs */ \ |
| 994 | "13fe" /* 19: Teardown ind = 0 */ \ |
| 995 | "1400" /* 20: NSAPI = 0*/ \ |
| 996 | |
| 997 | #define MSG_DEL_PDP_CTX_RSP(tei, seq) \ |
| 998 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr. */ \ |
| 999 | "15" /* type 21: Delete PDP Context Response */ \ |
| 1000 | "0006" /* msg length = 8 + len (2 octets) */ \ |
| 1001 | tei /* TEI Ctrl */ \ |
| 1002 | seq /* Sequence nr (2 octets) */ \ |
| 1003 | "00" /* N-PDU 0 */ \ |
| 1004 | "00" /* No extensions */ \ |
| 1005 | /* IEs */ \ |
| 1006 | "01" /* 1: Cause */ \ |
| 1007 | "80" /* value = 0b10000000 = response, no rejection. */ \ |
| 1008 | |
Neels Hofmeyr | 200aff6 | 2015-12-01 01:01:16 +0100 | [diff] [blame] | 1009 | static int delete_pdp_ctx_from_sgsn(void) |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1010 | { |
Neels Hofmeyr | 3c6e053 | 2015-12-01 00:23:45 +0100 | [diff] [blame] | 1011 | now += GTPH_EXPIRE_QUICKLY_SECS + 1; |
| 1012 | gtphub_gc(hub, now); |
| 1013 | |
| 1014 | LVL2_ASSERT(tunnels_are( |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1015 | "TEI=1:" |
| 1016 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1017 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | 3c6e053 | 2015-12-01 00:23:45 +0100 | [diff] [blame] | 1018 | " @21945\n")); |
| 1019 | |
| 1020 | /* TEI Ctrl from above and next sequence after abcd. */ |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1021 | const char *gtp_req_from_sgsn = MSG_DEL_PDP_CTX_REQ("00000001", "abce"); |
Neels Hofmeyr | 3c6e053 | 2015-12-01 00:23:45 +0100 | [diff] [blame] | 1022 | const char *gtp_req_to_ggsn = MSG_DEL_PDP_CTX_REQ("00000765", "6d32"); |
| 1023 | |
| 1024 | LVL2_ASSERT(msg_from_sgsn_c(&sgsn_sender, |
| 1025 | &resolved_ggsn_addr, |
| 1026 | gtp_req_from_sgsn, |
| 1027 | gtp_req_to_ggsn)); |
| 1028 | |
| 1029 | /* 21945 + 31 = 21976 */ |
| 1030 | LVL2_ASSERT(tunnels_are( |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1031 | "TEI=1:" |
| 1032 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1033 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | 3c6e053 | 2015-12-01 00:23:45 +0100 | [diff] [blame] | 1034 | " @21976\n")); |
| 1035 | |
| 1036 | const char *gtp_resp_from_ggsn = |
| 1037 | MSG_DEL_PDP_CTX_RSP("00000001", "6d32"); |
| 1038 | const char *gtp_resp_to_sgsn = |
| 1039 | MSG_DEL_PDP_CTX_RSP("00000321", "abce"); |
| 1040 | |
| 1041 | /* The response should go back to whichever port the request came from |
| 1042 | * (unmapped by sequence nr) */ |
| 1043 | LVL2_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr, |
| 1044 | &sgsn_sender, |
| 1045 | gtp_resp_from_ggsn, |
| 1046 | gtp_resp_to_sgsn)); |
| 1047 | |
| 1048 | LVL2_ASSERT(tunnels_are("")); |
| 1049 | |
| 1050 | return 1; |
| 1051 | } |
| 1052 | |
Neels Hofmeyr | 200aff6 | 2015-12-01 01:01:16 +0100 | [diff] [blame] | 1053 | static int delete_pdp_ctx_from_ggsn(void) |
Neels Hofmeyr | 3c6e053 | 2015-12-01 00:23:45 +0100 | [diff] [blame] | 1054 | { |
Neels Hofmeyr | 200aff6 | 2015-12-01 01:01:16 +0100 | [diff] [blame] | 1055 | now += GTPH_EXPIRE_QUICKLY_SECS + 1; |
| 1056 | gtphub_gc(hub, now); |
| 1057 | |
| 1058 | LVL2_ASSERT(tunnels_are( |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1059 | "TEI=1:" |
| 1060 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1061 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | 200aff6 | 2015-12-01 01:01:16 +0100 | [diff] [blame] | 1062 | " @21945\n")); |
| 1063 | |
| 1064 | /* TEI Ctrl from above and next sequence after abcd. */ |
| 1065 | const char *gtp_req_from_ggsn = MSG_DEL_PDP_CTX_REQ("00000001", "5432"); |
| 1066 | const char *gtp_req_to_sgsn = MSG_DEL_PDP_CTX_REQ("00000321", "6d31"); |
| 1067 | |
| 1068 | LVL2_ASSERT(msg_from_ggsn_c(&ggsn_sender, |
| 1069 | &resolved_sgsn_addr, |
| 1070 | gtp_req_from_ggsn, |
| 1071 | gtp_req_to_sgsn)); |
| 1072 | |
| 1073 | /* 21945 + 31 = 21976 */ |
| 1074 | LVL2_ASSERT(tunnels_are( |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1075 | "TEI=1:" |
| 1076 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1077 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | 200aff6 | 2015-12-01 01:01:16 +0100 | [diff] [blame] | 1078 | " @21976\n")); |
| 1079 | |
| 1080 | const char *gtp_resp_from_sgsn = |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1081 | MSG_DEL_PDP_CTX_RSP("00000001", "6d31"); |
Neels Hofmeyr | 200aff6 | 2015-12-01 01:01:16 +0100 | [diff] [blame] | 1082 | const char *gtp_resp_to_ggsn = |
| 1083 | MSG_DEL_PDP_CTX_RSP("00000765", "5432"); |
| 1084 | |
| 1085 | /* The response should go back to whichever port the request came from |
| 1086 | * (unmapped by sequence nr) */ |
| 1087 | LVL2_ASSERT(msg_from_sgsn_c(&resolved_sgsn_addr, |
| 1088 | &ggsn_sender, |
| 1089 | gtp_resp_from_sgsn, |
| 1090 | gtp_resp_to_ggsn)); |
| 1091 | |
| 1092 | LVL2_ASSERT(tunnels_are("")); |
| 1093 | |
| 1094 | return 1; |
| 1095 | } |
| 1096 | |
| 1097 | static void test_one_pdp_ctx(int del_from_side) |
| 1098 | { |
| 1099 | if (del_from_side == GTPH_SIDE_SGSN) |
| 1100 | LOG("test_one_pdp_ctx (del from SGSN)") |
| 1101 | else LOG("test_one_pdp_ctx (del from GGSN)"); |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 1102 | OSMO_ASSERT(setup_test_hub()); |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1103 | |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 1104 | OSMO_ASSERT(create_pdp_ctx()); |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1105 | |
| 1106 | struct gtphub_peer_port *ggsn_port = |
Neels Hofmeyr | 5da32ac | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 1107 | gtphub_port_find_sa(&hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL], |
Neels Hofmeyr | 43283a3 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 1108 | &resolved_ggsn_addr); |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1109 | OSMO_ASSERT(ggsn_port); |
| 1110 | struct gtphub_peer *ggsn = ggsn_port->peer_addr->peer; |
| 1111 | /* now == 345; now + 30 == 375. |
| 1112 | * seq mapping from above: |
| 1113 | * 0xabcd == 43981 (sent in the packet) |
| 1114 | * 0x6d31 == 27953 (harcoded seq mapping start val) */ |
| 1115 | OSMO_ASSERT(nr_map_is(&ggsn->seq_map, "(43981->27953@375), ")); |
| 1116 | |
| 1117 | /* now == 345; now + (6 * 60 * 60) == 21600 + 345 == 21945. |
| 1118 | * 0x00000321 == 801 (TEI from SGSN Ctrl) |
| 1119 | * 0x00000123 == 291 (TEI from SGSN User) |
| 1120 | * 0x00000765 == 1893 (TEI from GGSN Ctrl) |
| 1121 | * 0x00000567 == 1383 (TEI from GGSN User) |
| 1122 | * Mapped TEIs should be 1 and 2. */ |
Neels Hofmeyr | 39da711 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1123 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1124 | "TEI=1:" |
| 1125 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1126 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | 39da711 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1127 | " @21945\n")); |
Neels Hofmeyr | 3c6e053 | 2015-12-01 00:23:45 +0100 | [diff] [blame] | 1128 | |
Neels Hofmeyr | 200aff6 | 2015-12-01 01:01:16 +0100 | [diff] [blame] | 1129 | if (del_from_side == GTPH_SIDE_SGSN) { |
| 1130 | OSMO_ASSERT(delete_pdp_ctx_from_sgsn()); |
| 1131 | } else { |
| 1132 | OSMO_ASSERT(delete_pdp_ctx_from_ggsn()); |
| 1133 | } |
Neels Hofmeyr | 3c6e053 | 2015-12-01 00:23:45 +0100 | [diff] [blame] | 1134 | OSMO_ASSERT(tunnels_are("")); |
| 1135 | |
Neels Hofmeyr | 21d0873 | 2015-11-20 00:08:28 +0100 | [diff] [blame] | 1136 | OSMO_ASSERT(clear_test_hub()); |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1137 | } |
| 1138 | |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1139 | static void test_user_data(void) |
| 1140 | { |
| 1141 | LOG("test_user_data"); |
| 1142 | |
| 1143 | OSMO_ASSERT(setup_test_hub()); |
| 1144 | |
| 1145 | OSMO_ASSERT(create_pdp_ctx()); |
| 1146 | |
Neels Hofmeyr | 39da711 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1147 | /* now == 345; now + (6 * 60 * 60) == 21600 + 345 == 21945. */ |
| 1148 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1149 | "TEI=1:" |
| 1150 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1151 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | 39da711 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1152 | " @21945\n")); |
| 1153 | |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1154 | LOG("- user data starts"); |
Neels Hofmeyr | 39da711 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1155 | /* Now expect default port numbers for User plane. */ |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1156 | resolve_to_ggsn("192.168.43.34", 2152); |
| 1157 | resolve_to_sgsn("192.168.42.23", 2152); |
| 1158 | |
Neels Hofmeyr | 39da711 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1159 | /* 10 minutes later */ |
| 1160 | now += 600; |
| 1161 | |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1162 | const char *u_from_ggsn = |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 1163 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */ |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1164 | "ff" /* type 255: G-PDU */ |
| 1165 | "0058" /* length: 88 + 8 octets == 96 */ |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1166 | "00000001" /* mapped TEI for SGSN from create_pdp_ctx() */ |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1167 | "0070" /* seq */ |
| 1168 | "0000" /* No extensions */ |
| 1169 | /* User data (ICMP packet), 96 - 12 = 84 octets */ |
| 1170 | "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8" |
| 1171 | "4156000000007241010000000000101112131415161718191a1b1c1d1e1f" |
| 1172 | "202122232425262728292a2b2c2d2e2f3031323334353637" |
| 1173 | ; |
| 1174 | const char *u_to_sgsn = |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 1175 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */ |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1176 | "ff" /* type 255: G-PDU */ |
| 1177 | "0058" /* length: 88 + 8 octets == 96 */ |
| 1178 | "00000123" /* unmapped User TEI */ |
| 1179 | "6d31" /* new mapped seq */ |
| 1180 | "0000" |
| 1181 | "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8" |
| 1182 | "4156000000007241010000000000101112131415161718191a1b1c1d1e1f" |
| 1183 | "202122232425262728292a2b2c2d2e2f3031323334353637" |
| 1184 | ; |
| 1185 | |
| 1186 | /* This depends on create_pdp_ctx() sending resolved_sgsn_addr as GSN |
| 1187 | * Address IEs in the GGSN's Create PDP Ctx Response. */ |
| 1188 | OSMO_ASSERT(msg_from_ggsn_u(&ggsn_sender, |
| 1189 | &resolved_sgsn_addr, |
| 1190 | u_from_ggsn, |
| 1191 | u_to_sgsn)); |
| 1192 | |
Neels Hofmeyr | 39da711 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1193 | /* Make sure the user plane messages have refreshed the TEI mapping |
| 1194 | * timeouts: 21945 + 600 == 22545. */ |
| 1195 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1196 | "TEI=1:" |
| 1197 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1198 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | 39da711 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1199 | " @22545\n")); |
| 1200 | |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1201 | const char *u_from_sgsn = |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 1202 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */ |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1203 | "ff" /* type 255: G-PDU */ |
| 1204 | "0058" /* length: 88 + 8 octets == 96 */ |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1205 | "00000001" /* mapped User TEI for GGSN from create_pdp_ctx() */ |
Neels Hofmeyr | d4abc82 | 2015-12-03 14:19:08 +0100 | [diff] [blame] | 1206 | "1234" /* unknown seq */ |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1207 | "0000" /* No extensions */ |
| 1208 | /* User data (ICMP packet), 96 - 12 = 84 octets */ |
| 1209 | "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8" |
| 1210 | "4156000000007241010000000000101112131415161718191a1b1c1d1e1f" |
| 1211 | "202122232425262728292a2b2c2d2e2f3031323334353637" |
| 1212 | ; |
| 1213 | const char *u_to_ggsn = |
Neels Hofmeyr | 2a1d61f | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 1214 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */ |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1215 | "ff" /* type 255: G-PDU */ |
| 1216 | "0058" /* length: 88 + 8 octets == 96 */ |
| 1217 | "00000567" /* unmapped User TEI */ |
Neels Hofmeyr | d4abc82 | 2015-12-03 14:19:08 +0100 | [diff] [blame] | 1218 | "6d31" /* unmapped seq */ |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1219 | "0000" |
| 1220 | "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8" |
| 1221 | "4156000000007241010000000000101112131415161718191a1b1c1d1e1f" |
| 1222 | "202122232425262728292a2b2c2d2e2f3031323334353637" |
| 1223 | ; |
| 1224 | |
Neels Hofmeyr | d4abc82 | 2015-12-03 14:19:08 +0100 | [diff] [blame] | 1225 | OSMO_ASSERT(msg_from_sgsn_u(&sgsn_sender, |
| 1226 | &resolved_ggsn_addr, |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1227 | u_from_sgsn, |
| 1228 | u_to_ggsn)); |
| 1229 | |
Neels Hofmeyr | 39da711 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1230 | /* Make sure the user plane messages have refreshed the TEI mapping |
| 1231 | * timeouts: 21945 + 600 == 22545. Both timeouts refreshed: */ |
| 1232 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1233 | "TEI=1:" |
| 1234 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1235 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | 39da711 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1236 | " @22545\n")); |
| 1237 | |
Neels Hofmeyr | 21d0873 | 2015-11-20 00:08:28 +0100 | [diff] [blame] | 1238 | OSMO_ASSERT(clear_test_hub()); |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1239 | } |
| 1240 | |
Neels Hofmeyr | 3a342cf | 2015-12-02 14:18:26 +0100 | [diff] [blame] | 1241 | static void test_reused_tei(void) |
| 1242 | { |
| 1243 | LOG("test_reused_tei"); |
| 1244 | |
| 1245 | OSMO_ASSERT(setup_test_hub()); |
| 1246 | |
| 1247 | OSMO_ASSERT(create_pdp_ctx()); |
| 1248 | |
| 1249 | const char *gtp_req_from_sgsn = |
| 1250 | MSG_PDP_CTX_REQ("0068", |
| 1251 | "abce", /* Next seq */ |
| 1252 | "60", |
| 1253 | "42000121436587f9", |
| 1254 | "00000123", /* Same TEIs as before */ |
| 1255 | "00000321", |
| 1256 | "0009""08696e7465726e6574", /* "(8)internet" */ |
| 1257 | "0004""c0a82a17", /* same as default sgsn_sender */ |
| 1258 | "0004""c0a82a17" |
| 1259 | ); |
| 1260 | const char *gtp_req_to_ggsn = |
| 1261 | MSG_PDP_CTX_REQ("0068", |
| 1262 | "6d32", /* mapped seq ("abce") */ |
| 1263 | "23", |
| 1264 | "42000121436587f9", |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1265 | "00000002", /* mapped TEI Data I ("123") */ |
| 1266 | "00000002", /* mapped TEI Control ("321") */ |
Neels Hofmeyr | 3a342cf | 2015-12-02 14:18:26 +0100 | [diff] [blame] | 1267 | "0009""08696e7465726e6574", |
| 1268 | "0004""7f000201", /* replaced with gtphub's ggsn ctrl */ |
| 1269 | "0004""7f000202" /* replaced with gtphub's ggsn user */ |
| 1270 | ); |
| 1271 | |
| 1272 | OSMO_ASSERT(msg_from_sgsn_c(&sgsn_sender, |
| 1273 | &resolved_ggsn_addr, |
| 1274 | gtp_req_from_sgsn, |
| 1275 | gtp_req_to_ggsn)); |
| 1276 | OSMO_ASSERT(was_resolved_for("240010123456789", "internet")); |
| 1277 | |
| 1278 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1279 | "TEI=2:" |
| 1280 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1281 | " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)" |
Neels Hofmeyr | 3a342cf | 2015-12-02 14:18:26 +0100 | [diff] [blame] | 1282 | " @21945\n")); |
| 1283 | |
| 1284 | const char *gtp_resp_from_ggsn = |
| 1285 | MSG_PDP_CTX_RSP("004e", |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1286 | "00000002", /* destination TEI (sent in req above) */ |
Neels Hofmeyr | 3a342cf | 2015-12-02 14:18:26 +0100 | [diff] [blame] | 1287 | "6d32", /* mapped seq */ |
| 1288 | "01", /* restart */ |
| 1289 | "00000567", /* TEI U */ |
| 1290 | "00000765", /* TEI C */ |
| 1291 | "0004""c0a82b22", /* GSN addresses */ |
| 1292 | "0004""c0a82b22" /* (== resolved_ggsn_addr) */ |
| 1293 | ); |
| 1294 | const char *gtp_resp_to_sgsn = |
| 1295 | MSG_PDP_CTX_RSP("004e", |
| 1296 | "00000321", /* unmapped TEI ("001") */ |
| 1297 | "abce", /* unmapped seq ("6d32") */ |
| 1298 | "23", |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1299 | "00000002", /* mapped TEI from GGSN ("567") */ |
| 1300 | "00000002", /* mapped TEI from GGSN ("765") */ |
Neels Hofmeyr | 3a342cf | 2015-12-02 14:18:26 +0100 | [diff] [blame] | 1301 | "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */ |
| 1302 | "0004""7f000102" /* gtphub's address towards SGSNs (User) */ |
| 1303 | ); |
| 1304 | /* The response should go back to whichever port the request came from |
| 1305 | * (unmapped by sequence nr) */ |
| 1306 | OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr, |
| 1307 | &sgsn_sender, |
| 1308 | gtp_resp_from_ggsn, |
| 1309 | gtp_resp_to_sgsn)); |
| 1310 | |
| 1311 | OSMO_ASSERT(clear_test_hub()); |
| 1312 | } |
| 1313 | |
Neels Hofmeyr | 6402bae | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1314 | static void test_peer_restarted(void) |
| 1315 | { |
| 1316 | LOG("test_peer_restarted"); |
| 1317 | |
| 1318 | OSMO_ASSERT(setup_test_hub()); |
| 1319 | |
| 1320 | OSMO_ASSERT(create_pdp_ctx()); |
| 1321 | |
| 1322 | now += 10; |
| 1323 | |
| 1324 | const char *gtp_req_from_sgsn = |
| 1325 | MSG_PDP_CTX_REQ("0068", |
| 1326 | "1234", /* brand new seq */ |
| 1327 | "61", /* DIFFERING restart counter */ |
| 1328 | "42000121436587f9", |
| 1329 | "00000abc", |
| 1330 | "00000cba", |
| 1331 | "0009""08696e7465726e6574", /* "(8)internet" */ |
| 1332 | "0004""c0a82a17", /* same as default sgsn_sender */ |
| 1333 | "0004""c0a82a17" |
| 1334 | ); |
| 1335 | const char *gtp_req_to_ggsn = |
| 1336 | MSG_PDP_CTX_REQ("0068", |
Neels Hofmeyr | fe43626 | 2015-12-02 15:44:34 +0100 | [diff] [blame] | 1337 | "6d33", /* mapped seq ("1234") */ |
Neels Hofmeyr | 6402bae | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1338 | "23", |
| 1339 | "42000121436587f9", |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1340 | "00000002", /* mapped TEI Data I ("123") */ |
| 1341 | "00000002", /* mapped TEI Control ("321") */ |
Neels Hofmeyr | 6402bae | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1342 | "0009""08696e7465726e6574", |
| 1343 | "0004""7f000201", /* replaced with gtphub's ggsn ctrl */ |
| 1344 | "0004""7f000202" /* replaced with gtphub's ggsn user */ |
| 1345 | ); |
| 1346 | |
| 1347 | OSMO_ASSERT(msg_from_sgsn_c(&sgsn_sender, |
| 1348 | &resolved_ggsn_addr, |
| 1349 | gtp_req_from_sgsn, |
| 1350 | gtp_req_to_ggsn)); |
| 1351 | OSMO_ASSERT(was_resolved_for("240010123456789", "internet")); |
| 1352 | |
| 1353 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1354 | "TEI=2:" |
| 1355 | " 192.168.42.23 (TEI C=cba U=abc)" |
| 1356 | " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)" |
Neels Hofmeyr | 6402bae | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1357 | " @21955\n" |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1358 | "TEI=1:" |
| 1359 | " (uninitialized) (TEI C=321 U=123)" |
| 1360 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | 6402bae | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1361 | " @21945\n" |
| 1362 | )); |
| 1363 | |
| 1364 | const char *gtp_resp_from_ggsn = |
| 1365 | MSG_PDP_CTX_RSP("004e", |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1366 | "00000002", /* destination TEI (sent in req above) */ |
Neels Hofmeyr | fe43626 | 2015-12-02 15:44:34 +0100 | [diff] [blame] | 1367 | "6d33", /* mapped seq */ |
Neels Hofmeyr | 6402bae | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1368 | "01", /* restart */ |
| 1369 | "00000def", /* TEI U */ |
| 1370 | "00000fde", /* TEI C */ |
| 1371 | "0004""c0a82b22", /* GSN addresses */ |
| 1372 | "0004""c0a82b22" /* (== resolved_ggsn_addr) */ |
| 1373 | ); |
| 1374 | const char *gtp_resp_to_sgsn = |
| 1375 | MSG_PDP_CTX_RSP("004e", |
| 1376 | "00000cba", /* unmapped TEI ("005") */ |
| 1377 | "1234", /* unmapped seq ("6d32") */ |
| 1378 | "23", |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1379 | "00000002", /* mapped TEI from GGSN ("567") */ |
| 1380 | "00000002", /* mapped TEI from GGSN ("765") */ |
Neels Hofmeyr | 6402bae | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1381 | "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */ |
| 1382 | "0004""7f000102" /* gtphub's address towards SGSNs (User) */ |
| 1383 | ); |
| 1384 | /* The response should go back to whichever port the request came from |
| 1385 | * (unmapped by sequence nr) */ |
| 1386 | OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr, |
| 1387 | &sgsn_sender, |
| 1388 | gtp_resp_from_ggsn, |
| 1389 | gtp_resp_to_sgsn)); |
| 1390 | |
| 1391 | OSMO_ASSERT(clear_test_hub()); |
| 1392 | } |
| 1393 | |
| 1394 | static void test_peer_restarted_reusing_tei(void) |
| 1395 | { |
| 1396 | LOG("test_peer_restarted_reusing_tei"); |
| 1397 | |
| 1398 | OSMO_ASSERT(setup_test_hub()); |
| 1399 | |
| 1400 | OSMO_ASSERT(create_pdp_ctx()); |
| 1401 | |
| 1402 | now += 10; |
| 1403 | |
| 1404 | const char *gtp_req_from_sgsn = |
| 1405 | MSG_PDP_CTX_REQ("0068", |
| 1406 | "1234", /* brand new seq */ |
| 1407 | "61", /* DIFFERING restart counter */ |
| 1408 | "42000121436587f9", |
| 1409 | "00000123", /* SAME TEI */ |
| 1410 | "00000321", |
| 1411 | "0009""08696e7465726e6574", /* "(8)internet" */ |
| 1412 | "0004""c0a82a17", /* same as default sgsn_sender */ |
| 1413 | "0004""c0a82a17" |
| 1414 | ); |
| 1415 | const char *gtp_req_to_ggsn = |
| 1416 | MSG_PDP_CTX_REQ("0068", |
Neels Hofmeyr | f4906e5 | 2015-12-06 23:12:02 +0100 | [diff] [blame] | 1417 | "6d33", /* seq 6d31 + 2, after "out-of-band" Delete PDP Ctx |
| 1418 | due to differing restart counter. */ |
Neels Hofmeyr | 6402bae | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1419 | "23", |
| 1420 | "42000121436587f9", |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1421 | "00000002", /* mapped TEI Data I ("123") */ |
| 1422 | "00000002", /* mapped TEI Control ("321") */ |
Neels Hofmeyr | 6402bae | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1423 | "0009""08696e7465726e6574", |
| 1424 | "0004""7f000201", /* replaced with gtphub's ggsn ctrl */ |
| 1425 | "0004""7f000202" /* replaced with gtphub's ggsn user */ |
| 1426 | ); |
| 1427 | |
| 1428 | OSMO_ASSERT(msg_from_sgsn_c(&sgsn_sender, |
| 1429 | &resolved_ggsn_addr, |
| 1430 | gtp_req_from_sgsn, |
| 1431 | gtp_req_to_ggsn)); |
| 1432 | OSMO_ASSERT(was_resolved_for("240010123456789", "internet")); |
| 1433 | |
| 1434 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | f4906e5 | 2015-12-06 23:12:02 +0100 | [diff] [blame] | 1435 | "TEI=2:" /* being established after restart */ |
| 1436 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1437 | " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)" |
| 1438 | " @21955\n" |
| 1439 | "TEI=1:" /* invalidated due to restart */ |
| 1440 | " (uninitialized) (TEI C=321 U=123)" |
| 1441 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
| 1442 | " @21945\n" |
| 1443 | )); |
| 1444 | |
| 1445 | /* An "out-of-band" delete request should have been sent to the GGSN |
| 1446 | * (checked by expected log output in gtphub_test.ok), and the GGSN |
| 1447 | * will (usually) send a Delete Response like this: */ |
| 1448 | const char *gtp_del_resp_from_ggsn = |
| 1449 | MSG_DEL_PDP_CTX_RSP("00000001", "6d32"); |
| 1450 | |
| 1451 | /* For this response (due to peer restart) we expect no forwarded |
| 1452 | * message. */ |
| 1453 | OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr, |
| 1454 | &sgsn_sender, |
| 1455 | gtp_del_resp_from_ggsn, |
| 1456 | "")); |
| 1457 | |
| 1458 | OSMO_ASSERT(tunnels_are( |
| 1459 | "TEI=2:" /* still being established after restart */ |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1460 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1461 | " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)" |
Neels Hofmeyr | 6402bae | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1462 | " @21955\n" |
| 1463 | )); |
| 1464 | |
| 1465 | const char *gtp_resp_from_ggsn = |
| 1466 | MSG_PDP_CTX_RSP("004e", |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1467 | "00000002", /* destination TEI (sent in req above) */ |
Neels Hofmeyr | f4906e5 | 2015-12-06 23:12:02 +0100 | [diff] [blame] | 1468 | "6d33", /* mapped seq */ |
Neels Hofmeyr | 6402bae | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1469 | "01", /* restart */ |
| 1470 | "00000def", /* TEI U */ |
| 1471 | "00000fde", /* TEI C */ |
| 1472 | "0004""c0a82b22", /* GSN addresses */ |
| 1473 | "0004""c0a82b22" /* (== resolved_ggsn_addr) */ |
| 1474 | ); |
| 1475 | const char *gtp_resp_to_sgsn = |
| 1476 | MSG_PDP_CTX_RSP("004e", |
| 1477 | "00000321", /* unmapped TEI ("005") */ |
Neels Hofmeyr | f4906e5 | 2015-12-06 23:12:02 +0100 | [diff] [blame] | 1478 | "1234", /* unmapped seq ("6d33") */ |
Neels Hofmeyr | 6402bae | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1479 | "23", |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1480 | "00000002", /* mapped TEI from GGSN ("567") */ |
| 1481 | "00000002", /* mapped TEI from GGSN ("765") */ |
Neels Hofmeyr | 6402bae | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1482 | "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */ |
| 1483 | "0004""7f000102" /* gtphub's address towards SGSNs (User) */ |
| 1484 | ); |
| 1485 | /* The response should go back to whichever port the request came from |
| 1486 | * (unmapped by sequence nr) */ |
| 1487 | OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr, |
| 1488 | &sgsn_sender, |
| 1489 | gtp_resp_from_ggsn, |
| 1490 | gtp_resp_to_sgsn)); |
| 1491 | |
Neels Hofmeyr | f4906e5 | 2015-12-06 23:12:02 +0100 | [diff] [blame] | 1492 | OSMO_ASSERT(tunnels_are( |
| 1493 | "TEI=2:" /* still being established after restart */ |
| 1494 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1495 | " <-> 192.168.43.34 (TEI C=fde U=def)" |
| 1496 | " @21955\n" |
| 1497 | )); |
| 1498 | |
Neels Hofmeyr | 6402bae | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1499 | OSMO_ASSERT(clear_test_hub()); |
| 1500 | } |
| 1501 | |
Neels Hofmeyr | 5aba0ec | 2015-12-03 14:29:48 +0100 | [diff] [blame] | 1502 | static void test_sgsn_behind_nat(void) |
| 1503 | { |
| 1504 | LOG("test_user_data"); |
| 1505 | |
| 1506 | OSMO_ASSERT(setup_test_hub()); |
| 1507 | hub->sgsn_use_sender = 1; /* <-- Main difference to test_user_data() */ |
| 1508 | resolve_to_sgsn("192.168.42.23", 423); /* Same as sender */ |
| 1509 | |
| 1510 | OSMO_ASSERT(create_pdp_ctx()); |
| 1511 | |
| 1512 | /* now == 345; now + (6 * 60 * 60) == 21600 + 345 == 21945. */ |
| 1513 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1514 | "TEI=1:" |
| 1515 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1516 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | 5aba0ec | 2015-12-03 14:29:48 +0100 | [diff] [blame] | 1517 | " @21945\n")); |
| 1518 | |
| 1519 | LOG("- user data starts"); |
| 1520 | /* Now expect default port numbers for User plane -- except SGSN. */ |
| 1521 | resolve_to_ggsn("192.168.43.34", 2152); |
| 1522 | |
| 1523 | /* 10 minutes later */ |
| 1524 | now += 600; |
| 1525 | |
| 1526 | const char *u_from_ggsn = |
| 1527 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */ |
| 1528 | "ff" /* type 255: G-PDU */ |
| 1529 | "0058" /* length: 88 + 8 octets == 96 */ |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1530 | "00000001" /* mapped User TEI for SGSN from create_pdp_ctx() */ |
Neels Hofmeyr | 5aba0ec | 2015-12-03 14:29:48 +0100 | [diff] [blame] | 1531 | "0070" /* seq */ |
| 1532 | "0000" /* No extensions */ |
| 1533 | /* User data (ICMP packet), 96 - 12 = 84 octets */ |
| 1534 | "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8" |
| 1535 | "4156000000007241010000000000101112131415161718191a1b1c1d1e1f" |
| 1536 | "202122232425262728292a2b2c2d2e2f3031323334353637" |
| 1537 | ; |
| 1538 | const char *u_to_sgsn = |
| 1539 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */ |
| 1540 | "ff" /* type 255: G-PDU */ |
| 1541 | "0058" /* length: 88 + 8 octets == 96 */ |
| 1542 | "00000123" /* unmapped User TEI */ |
| 1543 | "6d31" /* new mapped seq */ |
| 1544 | "0000" |
| 1545 | "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8" |
| 1546 | "4156000000007241010000000000101112131415161718191a1b1c1d1e1f" |
| 1547 | "202122232425262728292a2b2c2d2e2f3031323334353637" |
| 1548 | ; |
| 1549 | |
| 1550 | /* This depends on create_pdp_ctx() sending resolved_sgsn_addr as GSN |
| 1551 | * Address IEs in the GGSN's Create PDP Ctx Response. */ |
| 1552 | OSMO_ASSERT(msg_from_ggsn_u(&ggsn_sender, |
| 1553 | &resolved_sgsn_addr, |
| 1554 | u_from_ggsn, |
| 1555 | u_to_sgsn)); |
| 1556 | |
| 1557 | /* Make sure the user plane messages have refreshed the TEI mapping |
| 1558 | * timeouts: 21945 + 600 == 22545. */ |
| 1559 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1560 | "TEI=1:" |
| 1561 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1562 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | 5aba0ec | 2015-12-03 14:29:48 +0100 | [diff] [blame] | 1563 | " @22545\n")); |
| 1564 | |
| 1565 | const char *u_from_sgsn = |
| 1566 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */ |
| 1567 | "ff" /* type 255: G-PDU */ |
| 1568 | "0058" /* length: 88 + 8 octets == 96 */ |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1569 | "00000001" /* mapped User TEI for GGSN from create_pdp_ctx() */ |
Neels Hofmeyr | 5aba0ec | 2015-12-03 14:29:48 +0100 | [diff] [blame] | 1570 | "1234" /* unknown seq */ |
| 1571 | "0000" /* No extensions */ |
| 1572 | /* User data (ICMP packet), 96 - 12 = 84 octets */ |
| 1573 | "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8" |
| 1574 | "4156000000007241010000000000101112131415161718191a1b1c1d1e1f" |
| 1575 | "202122232425262728292a2b2c2d2e2f3031323334353637" |
| 1576 | ; |
| 1577 | const char *u_to_ggsn = |
| 1578 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */ |
| 1579 | "ff" /* type 255: G-PDU */ |
| 1580 | "0058" /* length: 88 + 8 octets == 96 */ |
| 1581 | "00000567" /* unmapped User TEI */ |
| 1582 | "6d31" /* unmapped seq */ |
| 1583 | "0000" |
| 1584 | "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8" |
| 1585 | "4156000000007241010000000000101112131415161718191a1b1c1d1e1f" |
| 1586 | "202122232425262728292a2b2c2d2e2f3031323334353637" |
| 1587 | ; |
| 1588 | |
| 1589 | OSMO_ASSERT(msg_from_sgsn_u(&sgsn_sender, |
| 1590 | &resolved_ggsn_addr, |
| 1591 | u_from_sgsn, |
| 1592 | u_to_ggsn)); |
| 1593 | |
| 1594 | /* Make sure the user plane messages have refreshed the TEI mapping |
| 1595 | * timeouts: 21945 + 600 == 22545. Both timeouts refreshed: */ |
| 1596 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1597 | "TEI=1:" |
| 1598 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1599 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | 5aba0ec | 2015-12-03 14:29:48 +0100 | [diff] [blame] | 1600 | " @22545\n")); |
| 1601 | |
| 1602 | OSMO_ASSERT(clear_test_hub()); |
| 1603 | } |
| 1604 | |
Neels Hofmeyr | 81d7519 | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1605 | void test_parallel_context_creation(void) |
| 1606 | { |
| 1607 | LOG("test_parallel_context_creation"); |
| 1608 | |
| 1609 | OSMO_ASSERT(setup_test_hub()); |
| 1610 | |
| 1611 | const char *gtp_req_from_sgsn1 = |
| 1612 | MSG_PDP_CTX_REQ("0068", |
| 1613 | "abcd", |
| 1614 | "60", |
| 1615 | "42000121436587f9", |
| 1616 | "00000123", |
| 1617 | "00000321", |
| 1618 | "0009""08696e7465726e6574", /* "(8)internet" */ |
| 1619 | "0004""c0a82a17", /* same as default sgsn_sender */ |
| 1620 | "0004""c0a82a17" |
| 1621 | ); |
| 1622 | const char *gtp_req_to_ggsn1 = |
| 1623 | MSG_PDP_CTX_REQ("0068", |
| 1624 | "6d31", /* mapped seq ("abcd") */ |
| 1625 | "23", |
| 1626 | "42000121436587f9", |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1627 | "00000001", /* mapped TEI Data I ("123") */ |
Neels Hofmeyr | 81d7519 | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1628 | "00000001", /* mapped TEI Control ("321") */ |
| 1629 | "0009""08696e7465726e6574", |
| 1630 | "0004""7f000201", /* replaced with gtphub's ggsn ctrl */ |
| 1631 | "0004""7f000202" /* replaced with gtphub's ggsn user */ |
| 1632 | ); |
| 1633 | |
| 1634 | OSMO_ASSERT(msg_from_sgsn_c(&sgsn_sender, |
| 1635 | &resolved_ggsn_addr, |
| 1636 | gtp_req_from_sgsn1, |
| 1637 | gtp_req_to_ggsn1)); |
| 1638 | |
| 1639 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1640 | "TEI=1:" |
| 1641 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1642 | " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)" |
Neels Hofmeyr | 81d7519 | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1643 | " @21945\n")); |
| 1644 | |
| 1645 | now ++; |
| 1646 | |
| 1647 | const char *gtp_req_from_sgsn2 = |
| 1648 | MSG_PDP_CTX_REQ("0068", |
| 1649 | "abce", |
| 1650 | "60", |
| 1651 | "42000121436588f9", |
| 1652 | "00000124", |
| 1653 | "00000322", |
| 1654 | "0009""08696e7465726e6574", /* "(8)internet" */ |
| 1655 | "0004""c0a82a17", /* same as default sgsn_sender */ |
| 1656 | "0004""c0a82a17" |
| 1657 | ); |
| 1658 | const char *gtp_req_to_ggsn2 = |
| 1659 | MSG_PDP_CTX_REQ("0068", |
| 1660 | "6d32", /* mapped seq ("abce") */ |
| 1661 | "23", |
| 1662 | "42000121436588f9", |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1663 | "00000002", /* mapped TEI Data I ("124") */ |
| 1664 | "00000002", /* mapped TEI Control ("322") */ |
Neels Hofmeyr | 81d7519 | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1665 | "0009""08696e7465726e6574", |
| 1666 | "0004""7f000201", /* replaced with gtphub's ggsn ctrl */ |
| 1667 | "0004""7f000202" /* replaced with gtphub's ggsn user */ |
| 1668 | ); |
| 1669 | |
| 1670 | OSMO_ASSERT(msg_from_sgsn_c(&sgsn_sender, |
| 1671 | &resolved_ggsn_addr, |
| 1672 | gtp_req_from_sgsn2, |
| 1673 | gtp_req_to_ggsn2)); |
| 1674 | |
| 1675 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1676 | "TEI=2:" |
| 1677 | " 192.168.42.23 (TEI C=322 U=124)" |
| 1678 | " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)" |
Neels Hofmeyr | 81d7519 | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1679 | " @21946\n" |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1680 | "TEI=1:" |
| 1681 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1682 | " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)" |
Neels Hofmeyr | 81d7519 | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1683 | " @21945\n" |
| 1684 | )); |
| 1685 | |
| 1686 | now ++; |
| 1687 | |
| 1688 | const char *gtp_resp_from_ggsn1 = |
| 1689 | MSG_PDP_CTX_RSP("004e", |
| 1690 | "00000001", /* destination TEI (sent in req above) */ |
| 1691 | "6d31", /* mapped seq */ |
| 1692 | "01", /* restart */ |
| 1693 | "00000567", /* TEI U */ |
| 1694 | "00000765", /* TEI C */ |
| 1695 | "0004""c0a82b22", /* GSN addresses */ |
| 1696 | "0004""c0a82b22" /* (== resolved_ggsn_addr) */ |
| 1697 | ); |
| 1698 | const char *gtp_resp_to_sgsn1 = |
| 1699 | MSG_PDP_CTX_RSP("004e", |
| 1700 | "00000321", /* unmapped TEI ("001") */ |
| 1701 | "abcd", /* unmapped seq ("6d31") */ |
| 1702 | "23", |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1703 | "00000001", /* mapped TEI from GGSN ("567") */ |
| 1704 | "00000001", /* mapped TEI from GGSN ("765") */ |
Neels Hofmeyr | 81d7519 | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1705 | "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */ |
| 1706 | "0004""7f000102" /* gtphub's address towards SGSNs (User) */ |
| 1707 | ); |
| 1708 | |
| 1709 | OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr, |
| 1710 | &sgsn_sender, |
| 1711 | gtp_resp_from_ggsn1, |
| 1712 | gtp_resp_to_sgsn1)); |
| 1713 | |
| 1714 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1715 | "TEI=2:" |
| 1716 | " 192.168.42.23 (TEI C=322 U=124)" |
| 1717 | " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)" |
Neels Hofmeyr | 81d7519 | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1718 | " @21946\n" |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1719 | "TEI=1:" |
| 1720 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1721 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | 81d7519 | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1722 | " @21947\n" |
| 1723 | )); |
| 1724 | |
| 1725 | now ++; |
| 1726 | |
| 1727 | const char *gtp_resp_from_ggsn2 = |
| 1728 | MSG_PDP_CTX_RSP("004e", |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1729 | "00000002", /* destination TEI (sent in req above) */ |
Neels Hofmeyr | 81d7519 | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1730 | "6d32", /* mapped seq */ |
| 1731 | "01", /* restart */ |
| 1732 | "00000568", /* TEI U */ |
| 1733 | "00000766", /* TEI C */ |
| 1734 | "0004""c0a82b22", /* GSN addresses */ |
| 1735 | "0004""c0a82b22" /* (== resolved_ggsn_addr) */ |
| 1736 | ); |
| 1737 | const char *gtp_resp_to_sgsn2 = |
| 1738 | MSG_PDP_CTX_RSP("004e", |
| 1739 | "00000322", /* unmapped TEI ("001") */ |
| 1740 | "abce", /* unmapped seq ("6d31") */ |
| 1741 | "23", |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1742 | "00000002", /* mapped TEI from GGSN ("567") */ |
| 1743 | "00000002", /* mapped TEI from GGSN ("765") */ |
Neels Hofmeyr | 81d7519 | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1744 | "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */ |
| 1745 | "0004""7f000102" /* gtphub's address towards SGSNs (User) */ |
| 1746 | ); |
| 1747 | |
| 1748 | OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr, |
| 1749 | &sgsn_sender, |
| 1750 | gtp_resp_from_ggsn2, |
| 1751 | gtp_resp_to_sgsn2)); |
| 1752 | |
| 1753 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1754 | "TEI=2:" |
| 1755 | " 192.168.42.23 (TEI C=322 U=124)" |
| 1756 | " <-> 192.168.43.34 (TEI C=766 U=568)" |
Neels Hofmeyr | 81d7519 | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1757 | " @21948\n" |
Neels Hofmeyr | a2217ec | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1758 | "TEI=1:" |
| 1759 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1760 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | 81d7519 | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1761 | " @21947\n" |
| 1762 | )); |
| 1763 | |
| 1764 | OSMO_ASSERT(clear_test_hub()); |
| 1765 | } |
| 1766 | |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1767 | |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1768 | static struct log_info_cat gtphub_categories[] = { |
| 1769 | [DGTPHUB] = { |
| 1770 | .name = "DGTPHUB", |
| 1771 | .description = "GTP Hub", |
| 1772 | .color = "\033[1;33m", |
Neels Hofmeyr | 39da711 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1773 | .enabled = 1, .loglevel = LOGL_DEBUG, |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1774 | }, |
| 1775 | }; |
| 1776 | |
| 1777 | static struct log_info info = { |
| 1778 | .cat = gtphub_categories, |
| 1779 | .num_cat = ARRAY_SIZE(gtphub_categories), |
| 1780 | }; |
| 1781 | |
| 1782 | int main(int argc, char **argv) |
| 1783 | { |
| 1784 | osmo_init_logging(&info); |
| 1785 | osmo_gtphub_ctx = talloc_named_const(NULL, 0, "osmo_gtphub"); |
| 1786 | |
| 1787 | test_nr_map_basic(); |
Neels Hofmeyr | 6a65a8f | 2015-11-17 14:30:37 +0100 | [diff] [blame] | 1788 | test_nr_map_wrap(); |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1789 | test_expiry(); |
| 1790 | test_echo(); |
Neels Hofmeyr | 200aff6 | 2015-12-01 01:01:16 +0100 | [diff] [blame] | 1791 | test_one_pdp_ctx(GTPH_SIDE_SGSN); |
| 1792 | test_one_pdp_ctx(GTPH_SIDE_GGSN); |
Neels Hofmeyr | e6078bc | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1793 | test_user_data(); |
Neels Hofmeyr | 3a342cf | 2015-12-02 14:18:26 +0100 | [diff] [blame] | 1794 | test_reused_tei(); |
Neels Hofmeyr | 6402bae | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1795 | test_peer_restarted(); |
| 1796 | test_peer_restarted_reusing_tei(); |
Neels Hofmeyr | 5aba0ec | 2015-12-03 14:29:48 +0100 | [diff] [blame] | 1797 | test_sgsn_behind_nat(); |
Neels Hofmeyr | 81d7519 | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1798 | test_parallel_context_creation(); |
Neels Hofmeyr | 9f79664 | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1799 | printf("Done\n"); |
| 1800 | |
| 1801 | talloc_report_full(osmo_gtphub_ctx, stderr); |
| 1802 | OSMO_ASSERT(talloc_total_blocks(osmo_gtphub_ctx) == 1); |
| 1803 | return 0; |
| 1804 | } |
| 1805 | |