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