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