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 | |
Neels Hofmeyr | 396f2e6 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 31 | #include <osmocom/sgsn/debug.h> |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 32 | |
Neels Hofmeyr | 396f2e6 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 33 | #include <osmocom/sgsn/gtphub.h> |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 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 | |
Harald Welte | 9d550cb | 2020-04-20 19:47:19 +0200 | [diff] [blame] | 57 | extern void *osmo_gtphub_ctx; |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 58 | |
Neels Hofmeyr | c8a614d | 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 | 9cfe037 | 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 | c8a614d | 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 | 9cfe037 | 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 | c8a614d | 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 | 9cfe037 | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 123 | printf("mapping found, but origin mismatches:" |
| 124 | " expect %p, got %p\n", |
Neels Hofmeyr | c8a614d | 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 | e2ed8e6 | 2015-11-17 14:30:37 +0100 | [diff] [blame] | 146 | nr_pool_init(pool, 1, 1000); |
Neels Hofmeyr | c8a614d | 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 | b7f41d5 | 2017-01-11 00:43:26 +0100 | [diff] [blame] | 165 | OSMO_ASSERT(llist_count(&map->mappings) == (i+1)); |
Neels Hofmeyr | c8a614d | 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 | b7f41d5 | 2017-01-11 00:43:26 +0100 | [diff] [blame] | 169 | OSMO_ASSERT(llist_count(&map->mappings) == TEST_N_HALF); |
Neels Hofmeyr | c8a614d | 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 | b7f41d5 | 2017-01-11 00:43:26 +0100 | [diff] [blame] | 180 | OSMO_ASSERT(llist_count(&map->mappings) == (i2+1)); |
Neels Hofmeyr | c8a614d | 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 | b7f41d5 | 2017-01-11 00:43:26 +0100 | [diff] [blame] | 184 | OSMO_ASSERT(llist_count(&map->mappings) == TEST_N); |
Neels Hofmeyr | c8a614d | 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 | 9cfe037 | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 191 | OSMO_ASSERT(nr_map_verify_inv(map, m[i], origin1, |
| 192 | orig)); |
Neels Hofmeyr | c8a614d | 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 | 9cfe037 | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 197 | OSMO_ASSERT(nr_map_verify_inv(map, m[i2], origin2, |
| 198 | orig)); |
Neels Hofmeyr | c8a614d | 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 | b7f41d5 | 2017-01-11 00:43:26 +0100 | [diff] [blame] | 204 | OSMO_ASSERT(llist_count(&map->mappings) == (TEST_N - 2*i)); |
Neels Hofmeyr | c8a614d | 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 | 334af5d | 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 | c8a614d | 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 | e2ed8e6 | 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 | c8a614d | 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 | e2ed8e6 | 2015-11-17 14:30:37 +0100 | [diff] [blame] | 294 | nr_pool_init(&pool, 1, 1000); |
Neels Hofmeyr | c8a614d | 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 | d3fa84d | 2016-04-20 17:50:17 +0200 | [diff] [blame] | 378 | char resolve_ggsn_got_imsi[GSM23003_IMSI_MAX_DIGITS+1]; |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 379 | char resolve_ggsn_got_ni[GSM_APN_LENGTH]; |
| 380 | |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 381 | struct sgsn_sockaddr resolved_ggsn_addr; |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 382 | static int resolve_to_ggsn(const char *addr, uint16_t port) |
| 383 | { |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 384 | LVL2_ASSERT(sgsn_sockaddr_init_udp(&resolved_ggsn_addr, |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 385 | addr, port) |
| 386 | == 0); |
| 387 | return 1; |
| 388 | } |
| 389 | |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 390 | struct sgsn_sockaddr resolved_sgsn_addr; |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 391 | static int resolve_to_sgsn(const char *addr, uint16_t port) |
| 392 | { |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 393 | LVL2_ASSERT(sgsn_sockaddr_init_udp(&resolved_sgsn_addr, |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 394 | addr, port) |
| 395 | == 0); |
| 396 | return 1; |
| 397 | } |
| 398 | |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 399 | struct sgsn_sockaddr sgsn_sender; |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 400 | static int send_from_sgsn(const char *addr, uint16_t port) |
| 401 | { |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 402 | LVL2_ASSERT(sgsn_sockaddr_init_udp(&sgsn_sender, |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 403 | addr, port) |
| 404 | == 0); |
| 405 | return 1; |
| 406 | } |
| 407 | |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 408 | struct sgsn_sockaddr ggsn_sender; |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 409 | static int send_from_ggsn(const char *addr, uint16_t port) |
| 410 | { |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 411 | LVL2_ASSERT(sgsn_sockaddr_init_udp(&ggsn_sender, |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 412 | addr, port) |
| 413 | == 0); |
| 414 | return 1; |
| 415 | } |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 416 | |
| 417 | |
| 418 | /* override, requires '-Wl,--wrap=gtphub_resolve_ggsn_addr' */ |
Neels Hofmeyr | 30f7bcb | 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 | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 422 | |
Neels Hofmeyr | 30f7bcb | 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 | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 426 | { |
Neels Hofmeyr | c227594 | 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 | 30f7bcb | 2015-11-08 20:34:47 +0100 | [diff] [blame] | 433 | struct gtphub_peer_port *pp; |
Neels Hofmeyr | a9905a5 | 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 | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 435 | &resolved_gsna, resolved_port); |
Neels Hofmeyr | e921e32 | 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 | 30f7bcb | 2015-11-08 20:34:47 +0100 | [diff] [blame] | 438 | imsi_str, apn_ni_str, gtphub_port_str(pp)); |
| 439 | |
Neels Hofmeyr | 93bafb6 | 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 | 30f7bcb | 2015-11-08 20:34:47 +0100 | [diff] [blame] | 444 | |
Neels Hofmeyr | 93bafb6 | 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 | 30f7bcb | 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 | 9cfe037 | 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 | 30f7bcb | 2015-11-08 20:34:47 +0100 | [diff] [blame] | 456 | { |
Neels Hofmeyr | 9cfe037 | 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 | 30f7bcb | 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 | 9cfe037 | 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 | 30f7bcb | 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 | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 490 | } |
| 491 | |
Neels Hofmeyr | 996ec1d | 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, |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 494 | const struct sgsn_sockaddr *to_addr, |
Neels Hofmeyr | 996ec1d | 2015-12-02 15:43:10 +0100 | [diff] [blame] | 495 | const uint8_t *buf, size_t buf_len); |
| 496 | |
| 497 | int __wrap_gtphub_write(const struct osmo_fd *to, |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 498 | const struct sgsn_sockaddr *to_addr, |
Neels Hofmeyr | 996ec1d | 2015-12-02 15:43:10 +0100 | [diff] [blame] | 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, |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 505 | sgsn_sockaddr_to_str(to_addr), |
Neels Hofmeyr | 996ec1d | 2015-12-02 15:43:10 +0100 | [diff] [blame] | 506 | osmo_hexdump(buf, buf_len)); |
| 507 | return 0; |
| 508 | } |
| 509 | |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 510 | #define buf_len 1024 |
| 511 | static uint8_t buf[buf_len]; |
Neels Hofmeyr | bb3d678 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 512 | static uint8_t *reply_buf; |
Neels Hofmeyr | c8a614d | 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 | bb3d678 | 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 | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 526 | { |
Neels Hofmeyr | bb3d678 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 527 | struct gtp1_header_long *h = (void*)reply_buf; |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 528 | int len = ntoh16(h->length) + 8; |
Neels Hofmeyr | bb3d678 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 529 | const char *dump = osmo_hexdump_nospc(reply_buf, len); |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 530 | int cmp = strcmp(dump, hex); |
| 531 | |
Alexander Couzens | 68d9c5a | 2020-10-02 00:13:42 +0200 | [diff] [blame] | 532 | OSMO_ASSERT(dump && hex); |
| 533 | |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 534 | if (cmp != 0) { |
Neels Hofmeyr | bb3d678 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 535 | printf("\n%s:%d: reply_is(): MISMATCH\n" |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 536 | " expecting:\n'%s'\n" |
| 537 | " got:\n'%s'\n\n", |
| 538 | file, |
| 539 | line, |
| 540 | hex, dump); |
| 541 | int i; |
| 542 | int l = strlen(hex); |
| 543 | int m = strlen(dump); |
| 544 | if (m < l) |
| 545 | l = m; |
| 546 | for (i = 0; i < l; i++) { |
| 547 | if (hex[i] != dump[i]) { |
| 548 | printf("First mismatch at position %d:\n" |
| 549 | " %s\n %s\n", i, hex + i, dump + i); |
| 550 | break; |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | return cmp == 0; |
| 555 | } |
| 556 | |
| 557 | #define same_addr(GOT, EXPECTED) _same_addr((GOT),(EXPECTED), __FILE__, __LINE__) |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 558 | static int _same_addr(const struct sgsn_sockaddr *got, |
| 559 | const struct sgsn_sockaddr *expected, |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 560 | const char *file, int line) |
| 561 | { |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 562 | int cmp = sgsn_sockaddr_cmp(got, expected); |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 563 | if (!cmp) |
| 564 | return 1; |
| 565 | char buf[256]; |
| 566 | printf("\n%s:%d: addr_is(): MISMATCH\n" |
| 567 | " expecting: '%s'\n" |
| 568 | " got: '%s'\n\n", |
| 569 | file, line, |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 570 | sgsn_sockaddr_to_str(expected), |
| 571 | sgsn_sockaddr_to_strb(got, buf, sizeof(buf))); |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 572 | return 0; |
| 573 | } |
| 574 | |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 575 | |
| 576 | time_t now; |
| 577 | static struct gtphub _hub; |
| 578 | static struct gtphub *hub = &_hub; |
| 579 | |
| 580 | static int setup_test_hub() |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 581 | { |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 582 | /* Not really needed, but to make 100% sure... */ |
| 583 | ZERO_STRUCT(hub); |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 584 | |
| 585 | gtphub_init(hub); |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 586 | |
| 587 | /* Tell this mock gtphub its local address for this test. */ |
Neels Hofmeyr | a9905a5 | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 588 | 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] | 589 | "127.0.1.1") == 0); |
Neels Hofmeyr | a9905a5 | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 590 | 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] | 591 | "127.0.1.2") == 0); |
Neels Hofmeyr | a9905a5 | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 592 | 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] | 593 | "127.0.2.1") == 0); |
Neels Hofmeyr | a9905a5 | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 594 | 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] | 595 | "127.0.2.2") == 0); |
| 596 | |
Neels Hofmeyr | bb3d678 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 597 | hub->restart_counter = 0x23; |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 598 | now = 345; |
| 599 | LVL2_ASSERT(send_from_sgsn("192.168.42.23", 423)); |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 600 | LVL2_ASSERT(resolve_to_ggsn("192.168.43.34", 2123)); |
Neels Hofmeyr | e54cd15 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 601 | LVL2_ASSERT(send_from_ggsn("192.168.43.34", 434)); |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 602 | LVL2_ASSERT(resolve_to_sgsn("192.168.42.23", 2123)); |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 603 | |
Neels Hofmeyr | 6187e01 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 604 | #define GGSNS_CTRL_FD 1 |
| 605 | #define GGSNS_USER_FD 2 |
| 606 | #define SGSNS_CTRL_FD 3 |
| 607 | #define SGSNS_USER_FD 4 |
Neels Hofmeyr | a9905a5 | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 608 | hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_CTRL].ofd.priv_nr = GGSNS_CTRL_FD; |
| 609 | hub->to_gsns[GTPH_SIDE_GGSN][GTPH_PLANE_USER].ofd.priv_nr = GGSNS_USER_FD; |
| 610 | hub->to_gsns[GTPH_SIDE_SGSN][GTPH_PLANE_CTRL].ofd.priv_nr = SGSNS_CTRL_FD; |
| 611 | 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] | 612 | |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 613 | return 1; |
| 614 | } |
| 615 | |
Neels Hofmeyr | 20bd6bf | 2015-11-20 00:08:28 +0100 | [diff] [blame] | 616 | static int clear_test_hub() |
| 617 | { |
| 618 | /* expire all */ |
Neels Hofmeyr | e54cd15 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 619 | gtphub_gc(hub, now + (60 * GTPH_EXPIRE_SLOWLY_MINUTES) + 1); |
Neels Hofmeyr | 20bd6bf | 2015-11-20 00:08:28 +0100 | [diff] [blame] | 620 | |
| 621 | int plane_idx; |
| 622 | plane_idx = GTPH_PLANE_CTRL; |
Neels Hofmeyr | a9905a5 | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 623 | LVL2_ASSERT(llist_empty(&hub->to_gsns[GTPH_SIDE_GGSN][plane_idx].peers)); |
| 624 | 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] | 625 | plane_idx = GTPH_PLANE_USER; |
Neels Hofmeyr | a9905a5 | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 626 | LVL2_ASSERT(llist_empty(&hub->to_gsns[GTPH_SIDE_GGSN][plane_idx].peers)); |
| 627 | 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] | 628 | |
Neels Hofmeyr | 99a50b3 | 2015-12-02 01:15:30 +0100 | [diff] [blame] | 629 | LVL2_ASSERT(llist_empty(&hub->tunnels)); |
| 630 | LVL2_ASSERT(llist_empty(&hub->pending_deletes)); |
| 631 | LVL2_ASSERT(llist_empty(&hub->ggsn_lookups)); |
| 632 | LVL2_ASSERT(llist_empty(&hub->resolved_ggsns)); |
| 633 | |
Neels Hofmeyr | 20bd6bf | 2015-11-20 00:08:28 +0100 | [diff] [blame] | 634 | gtphub_free(hub); |
| 635 | return 1; |
| 636 | } |
| 637 | |
Neels Hofmeyr | e54cd15 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 638 | static int tunnels_are(const char *expect) |
| 639 | { |
| 640 | static char buf[4096]; |
| 641 | char *pos = buf; |
| 642 | size_t len = sizeof(buf); |
| 643 | struct gtphub_tunnel *t; |
| 644 | llist_for_each_entry(t, &hub->tunnels, entry) { |
| 645 | size_t wrote = snprintf(pos, len, "%s @%d\n", |
| 646 | gtphub_tunnel_str(t), |
| 647 | (int)t->expiry_entry.expiry); |
| 648 | LVL2_ASSERT(wrote < len); |
| 649 | pos += wrote; |
| 650 | len -= wrote; |
| 651 | } |
| 652 | *pos = '\0'; |
| 653 | |
| 654 | if (strncmp(buf, expect, sizeof(buf)) != 0) { |
| 655 | fprintf(stderr, "FAILURE: tunnels_are() mismatches expected value:\n" |
| 656 | "EXPECTED:\n%s\n" |
| 657 | "IS:\n%s\n", |
| 658 | expect, buf); |
| 659 | LVL2_ASSERT("tunnels do not match expected listing."); |
| 660 | return 0; |
| 661 | } |
| 662 | return 1; |
| 663 | } |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 664 | |
| 665 | static void test_echo(void) |
| 666 | { |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 667 | LOG("test_echo"); |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 668 | OSMO_ASSERT(setup_test_hub()); |
| 669 | |
| 670 | now = 123; |
Neels Hofmeyr | 30f7bcb | 2015-11-08 20:34:47 +0100 | [diff] [blame] | 671 | |
Neels Hofmeyr | 6187e01 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 672 | struct osmo_fd *to_ofd; |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 673 | struct sgsn_sockaddr to_addr; |
Neels Hofmeyr | 6187e01 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 674 | struct gtphub_peer_port *pp; |
| 675 | int send; |
| 676 | |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 677 | const char *gtp_ping_from_sgsn = |
Neels Hofmeyr | 9cfe037 | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 678 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */ |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 679 | "01" /* type 01: Echo request */ |
| 680 | "0004" /* length of 4 after header TEI */ |
| 681 | "00000000" /* header TEI == 0 in Echo */ |
Neels Hofmeyr | bb3d678 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 682 | "abcd" /* some 2 octet sequence nr */ |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 683 | "0000" /* N-PDU 0, no extension header (why is this here?) */ |
| 684 | ; |
| 685 | |
Neels Hofmeyr | bb3d678 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 686 | const char *gtp_pong_to_sgsn = |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 687 | "32" |
| 688 | "02" /* type 02: Echo response */ |
Neels Hofmeyr | bb3d678 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 689 | "0006" /* length of 6 after header TEI */ |
| 690 | "00000000" /* header TEI == 0 in Echo */ |
| 691 | "abcd" /* same sequence nr */ |
| 692 | "0000" |
| 693 | "0e23" /* Recovery with restart counter */ |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 694 | ; |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 695 | |
Neels Hofmeyr | 6187e01 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 696 | to_ofd = NULL; |
| 697 | ZERO_STRUCT(&to_addr); |
Neels Hofmeyr | a9905a5 | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 698 | send = gtphub_handle_buf(hub, GTPH_SIDE_SGSN, GTPH_PLANE_CTRL, |
| 699 | &sgsn_sender, buf, msg(gtp_ping_from_sgsn), |
| 700 | now, &reply_buf, &to_ofd, &to_addr); |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 701 | OSMO_ASSERT(send > 0); |
Neels Hofmeyr | bb3d678 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 702 | OSMO_ASSERT(to_addr.l); |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 703 | OSMO_ASSERT(same_addr(&to_addr, &sgsn_sender)); |
Neels Hofmeyr | 6187e01 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 704 | OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == SGSNS_CTRL_FD)); |
Neels Hofmeyr | bb3d678 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 705 | OSMO_ASSERT(reply_is(gtp_pong_to_sgsn)); |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 706 | |
Neels Hofmeyr | a9905a5 | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 707 | 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] | 708 | &sgsn_sender); |
Neels Hofmeyr | bb3d678 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 709 | /* We don't record Echo peers. */ |
Neels Hofmeyr | 6187e01 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 710 | OSMO_ASSERT(!pp); |
Neels Hofmeyr | bb3d678 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 711 | |
| 712 | const char *gtp_ping_from_ggsn = |
Neels Hofmeyr | 9cfe037 | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 713 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */ |
Neels Hofmeyr | bb3d678 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 714 | "01" /* type 01: Echo request */ |
| 715 | "0004" /* length of 4 after header TEI */ |
| 716 | "00000000" /* header TEI == 0 in Echo */ |
| 717 | "cdef" /* some 2 octet sequence nr */ |
| 718 | "0000" /* N-PDU 0, no extension header (why is this here?) */ |
| 719 | ; |
| 720 | |
| 721 | const char *gtp_pong_to_ggsn = |
| 722 | "32" |
| 723 | "02" /* type 02: Echo response */ |
| 724 | "0006" /* length of 6 after header TEI */ |
| 725 | "00000000" /* header TEI == 0 in Echo */ |
| 726 | "cdef" /* same sequence nr */ |
| 727 | "0000" |
| 728 | "0e23" /* Recovery with restart counter */ |
| 729 | ; |
| 730 | |
Neels Hofmeyr | 6187e01 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 731 | to_ofd = NULL; |
| 732 | ZERO_STRUCT(&to_addr); |
Neels Hofmeyr | a9905a5 | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 733 | send = gtphub_handle_buf(hub, GTPH_SIDE_GGSN, GTPH_PLANE_CTRL, |
| 734 | &ggsn_sender, buf, msg(gtp_ping_from_ggsn), |
| 735 | now, &reply_buf, &to_ofd, &to_addr); |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 736 | OSMO_ASSERT(send > 0); |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 737 | OSMO_ASSERT(same_addr(&to_addr, &ggsn_sender)); |
Neels Hofmeyr | 6187e01 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 738 | OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == GGSNS_CTRL_FD)); |
Neels Hofmeyr | bb3d678 | 2015-11-09 15:12:25 +0100 | [diff] [blame] | 739 | OSMO_ASSERT(reply_is(gtp_pong_to_ggsn)); |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 740 | |
Neels Hofmeyr | a9905a5 | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 741 | 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] | 742 | &sgsn_sender); |
| 743 | OSMO_ASSERT(!pp); |
| 744 | |
| 745 | |
| 746 | /* And all the same on the user plane. */ |
| 747 | |
| 748 | to_ofd = NULL; |
| 749 | ZERO_STRUCT(&to_addr); |
Neels Hofmeyr | a9905a5 | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 750 | send = gtphub_handle_buf(hub, GTPH_SIDE_SGSN, GTPH_PLANE_USER, |
| 751 | &sgsn_sender, buf, msg(gtp_ping_from_sgsn), |
| 752 | now, &reply_buf, &to_ofd, &to_addr); |
Neels Hofmeyr | 6187e01 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 753 | OSMO_ASSERT(send > 0); |
| 754 | OSMO_ASSERT(to_addr.l); |
| 755 | OSMO_ASSERT(same_addr(&to_addr, &sgsn_sender)); |
| 756 | OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == SGSNS_USER_FD)); |
| 757 | OSMO_ASSERT(reply_is(gtp_pong_to_sgsn)); |
| 758 | |
Neels Hofmeyr | a9905a5 | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 759 | 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] | 760 | &sgsn_sender); |
| 761 | OSMO_ASSERT(!pp); |
| 762 | |
| 763 | to_ofd = NULL; |
| 764 | ZERO_STRUCT(&to_addr); |
Neels Hofmeyr | a9905a5 | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 765 | send = gtphub_handle_buf(hub, GTPH_SIDE_GGSN, GTPH_PLANE_USER, |
| 766 | &ggsn_sender, buf, msg(gtp_ping_from_ggsn), |
| 767 | now, &reply_buf, &to_ofd, &to_addr); |
Neels Hofmeyr | 6187e01 | 2015-11-20 00:57:05 +0100 | [diff] [blame] | 768 | OSMO_ASSERT(send > 0); |
| 769 | OSMO_ASSERT(same_addr(&to_addr, &ggsn_sender)); |
| 770 | OSMO_ASSERT(to_ofd && (to_ofd->priv_nr == GGSNS_USER_FD)); |
| 771 | OSMO_ASSERT(reply_is(gtp_pong_to_ggsn)); |
| 772 | |
Neels Hofmeyr | a9905a5 | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 773 | 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] | 774 | &sgsn_sender); |
| 775 | OSMO_ASSERT(!pp); |
| 776 | |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 777 | |
Neels Hofmeyr | 20bd6bf | 2015-11-20 00:08:28 +0100 | [diff] [blame] | 778 | OSMO_ASSERT(clear_test_hub()); |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | |
| 782 | #define MSG_PDP_CTX_REQ(len, seq, restart, imsi, tei_u, tei_c, apn, gsn_c, gsn_u) \ |
| 783 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr. */ \ |
| 784 | "10" /* type 16: Create PDP Context Request */ \ |
| 785 | len /* msg length = 8 + len (2 octets) */ \ |
| 786 | "00000000" /* No TEI yet */ \ |
| 787 | seq /* Sequence nr (2 octets) */ \ |
| 788 | "00" /* N-PDU 0 */ \ |
| 789 | "00" /* No extensions */ \ |
| 790 | /* IEs */ \ |
Neels Hofmeyr | ba9e9f6 | 2015-11-26 22:19:22 +0100 | [diff] [blame] | 791 | "0e" restart /* 14: Recovery (restart counter: 1 octet) */ \ |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 792 | "02" /* 2 = IMSI */ \ |
| 793 | imsi /* (8 octets) */ \ |
| 794 | "0f01" /* 15: Selection mode = MS provided APN, subscription not verified*/ \ |
| 795 | "10" /* 16: TEI Data I */ \ |
| 796 | tei_u /* (4 octets) */ \ |
| 797 | "11" /* 17: TEI Control Plane */ \ |
| 798 | tei_c /* (4 octets) */ \ |
| 799 | "1400" /* 20: NSAPI = 0*/ \ |
| 800 | "1a" /* 26: Charging Characteristics */ \ |
| 801 | "0800" \ |
| 802 | "80" /* 128: End User Address */ \ |
| 803 | "0002" /* length = 2: empty PDP Address */ \ |
| 804 | "f121" /* spare 0xf0, PDP organization 1, PDP type number 0x21 = 33 */ \ |
| 805 | "83" /* 131: Access Point Name */ \ |
| 806 | apn /* (2 octets length, N octets encoded APN-NI) */ \ |
| 807 | "84" /* 132: Protocol Configuration Options */ \ |
| 808 | "0015" /* length = 21 */ \ |
| 809 | "80c0231101010011036d69670868656d6d656c6967" \ |
| 810 | "85" /* 133: GSN Address */ \ |
| 811 | gsn_c /* (2 octets length, N octets addr) */ \ |
| 812 | "85" /* 133: GSN Address (second entry) */ \ |
| 813 | gsn_u /* (2 octets length, N octets addr) */ \ |
| 814 | "86" /* 134: MS International PSTN/ISDN Number (MSISDN) */ \ |
| 815 | "0007" /* length */ \ |
| 816 | "916407123254f6" /* 1946702123456(f) */ \ |
| 817 | "87" /* 135: Quality of Service (QoS) Profile */ \ |
| 818 | "0004" /* length */ \ |
| 819 | "00" /* priority */ \ |
| 820 | "0b921f" /* QoS profile data */ |
| 821 | |
| 822 | #define MSG_PDP_CTX_RSP(len, tei_h, seq, restart, tei_u, tei_c, gsn_c, gsn_u) \ |
| 823 | "32" \ |
| 824 | "11" /* Create PDP Context Response */ \ |
| 825 | len /* msg length = 8 + len (2 octets) */ \ |
| 826 | tei_h /* destination TEI (sent in req above) */ \ |
| 827 | seq /* mapped seq */ \ |
| 828 | "00" "00" \ |
| 829 | /* IEs */ \ |
| 830 | "01" /* 1: Cause */ \ |
| 831 | "80" /* value = 0b10000000 = response, no rejection. */ \ |
| 832 | "08" /* 8: Reordering Required */ \ |
| 833 | "00" /* not required. */ \ |
Neels Hofmeyr | ba9e9f6 | 2015-11-26 22:19:22 +0100 | [diff] [blame] | 834 | "0e" restart /* 14: Recovery */ \ |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 835 | "10" /* 16: TEI Data I */ \ |
| 836 | tei_u \ |
| 837 | "11" /* 17: TEI Control */ \ |
| 838 | tei_c \ |
| 839 | "7f" /* 127: Charging ID */ \ |
| 840 | "00000001" \ |
| 841 | "80" /* 128: End User Address */ \ |
| 842 | "0006" /* length = 6 */ \ |
| 843 | "f121" /* spare 0xf0, PDP organization 1, PDP type number 0x21 = 33 */ \ |
| 844 | "7f000002" \ |
| 845 | "84" /* 132: Protocol Configuration Options */ \ |
| 846 | "0014" /* len = 20 */ \ |
| 847 | "8080211002000010810608080808830600000000" \ |
| 848 | "85" /* 133: GSN Address (Ctrl) */ \ |
| 849 | gsn_c \ |
| 850 | "85" /* 133: GSN Address (User) */ \ |
| 851 | gsn_u \ |
| 852 | "87" /* 135: Quality of Service (QoS) Profile */ \ |
| 853 | "0004" /* length */ \ |
| 854 | "00" /* priority */ \ |
| 855 | "0b921f" /* QoS profile data */ |
| 856 | |
| 857 | #define msg_from_sgsn_c(A,B,C,D) msg_from_sgsn(GTPH_PLANE_CTRL, A,B,C,D) |
| 858 | #define msg_from_sgsn_u(A,B,C,D) msg_from_sgsn(GTPH_PLANE_USER, A,B,C,D) |
| 859 | static int msg_from_sgsn(int plane_idx, |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 860 | struct sgsn_sockaddr *_sgsn_sender, |
| 861 | struct sgsn_sockaddr *ggsn_receiver, |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 862 | const char *hex_from_sgsn, |
| 863 | const char *hex_to_ggsn) |
| 864 | { |
| 865 | struct osmo_fd *ggsn_ofd = NULL; |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 866 | struct sgsn_sockaddr ggsn_addr; |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 867 | int send; |
Neels Hofmeyr | a9905a5 | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 868 | send = gtphub_handle_buf(hub, GTPH_SIDE_SGSN, plane_idx, _sgsn_sender, |
| 869 | buf, msg(hex_from_sgsn), now, |
| 870 | &reply_buf, &ggsn_ofd, &ggsn_addr); |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 871 | LVL2_ASSERT(send > 0); |
| 872 | LVL2_ASSERT(same_addr(&ggsn_addr, ggsn_receiver)); |
| 873 | LVL2_ASSERT(reply_is(hex_to_ggsn)); |
| 874 | return 1; |
| 875 | } |
| 876 | |
| 877 | #define msg_from_ggsn_c(A,B,C,D) msg_from_ggsn(GTPH_PLANE_CTRL, A,B,C,D) |
| 878 | #define msg_from_ggsn_u(A,B,C,D) msg_from_ggsn(GTPH_PLANE_USER, A,B,C,D) |
| 879 | static int msg_from_ggsn(int plane_idx, |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 880 | struct sgsn_sockaddr *ggsn_sender, |
| 881 | struct sgsn_sockaddr *sgsn_receiver, |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 882 | const char *msg_from_ggsn, |
| 883 | const char *msg_to_sgsn) |
| 884 | { |
| 885 | struct osmo_fd *sgsn_ofd; |
Alexander Couzens | dd930a2 | 2020-07-18 16:45:25 +0200 | [diff] [blame] | 886 | struct sgsn_sockaddr sgsn_addr; |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 887 | int send; |
Neels Hofmeyr | a9905a5 | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 888 | send = gtphub_handle_buf(hub, GTPH_SIDE_GGSN, plane_idx, ggsn_sender, |
| 889 | buf, msg(msg_from_ggsn), now, |
| 890 | &reply_buf, &sgsn_ofd, &sgsn_addr); |
Neels Hofmeyr | d010c49 | 2015-12-06 23:12:02 +0100 | [diff] [blame] | 891 | if (*msg_to_sgsn) { |
| 892 | LVL2_ASSERT(send > 0); |
| 893 | LVL2_ASSERT(same_addr(&sgsn_addr, sgsn_receiver)); |
| 894 | LVL2_ASSERT(reply_is(msg_to_sgsn)); |
| 895 | } |
| 896 | else |
| 897 | LVL2_ASSERT(send == 0); |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 898 | return 1; |
| 899 | } |
| 900 | |
| 901 | static int create_pdp_ctx() |
| 902 | { |
Neels Hofmeyr | 9cfe037 | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 903 | const char *gtp_req_from_sgsn = |
| 904 | MSG_PDP_CTX_REQ("0068", |
| 905 | "abcd", |
| 906 | "60", |
| 907 | "42000121436587f9", |
| 908 | "00000123", |
| 909 | "00000321", |
| 910 | "0009""08696e7465726e6574", /* "(8)internet" */ |
| 911 | "0004""c0a82a17", /* same as default sgsn_sender */ |
| 912 | "0004""c0a82a17" |
| 913 | ); |
| 914 | const char *gtp_req_to_ggsn = |
| 915 | MSG_PDP_CTX_REQ("0068", |
| 916 | "6d31", /* mapped seq ("abcd") */ |
Neels Hofmeyr | ba9e9f6 | 2015-11-26 22:19:22 +0100 | [diff] [blame] | 917 | "23", |
Neels Hofmeyr | 9cfe037 | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 918 | "42000121436587f9", |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 919 | "00000001", /* Data I: tunnel's TEI */ |
| 920 | "00000001", /* Control: tunnel's TEI */ |
Neels Hofmeyr | 9cfe037 | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 921 | "0009""08696e7465726e6574", |
| 922 | "0004""7f000201", /* replaced with gtphub's ggsn ctrl */ |
| 923 | "0004""7f000202" /* replaced with gtphub's ggsn user */ |
| 924 | ); |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 925 | |
| 926 | LVL2_ASSERT(msg_from_sgsn_c(&sgsn_sender, |
| 927 | &resolved_ggsn_addr, |
| 928 | gtp_req_from_sgsn, |
| 929 | gtp_req_to_ggsn)); |
| 930 | LVL2_ASSERT(was_resolved_for("240010123456789", "internet")); |
| 931 | |
Neels Hofmeyr | e54cd15 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 932 | LVL2_ASSERT(tunnels_are( |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 933 | "TEI=1:" |
| 934 | " 192.168.42.23 (TEI C=321 U=123)" |
| 935 | " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)" |
Neels Hofmeyr | e54cd15 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 936 | " @21945\n")); |
| 937 | |
Neels Hofmeyr | 9cfe037 | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 938 | const char *gtp_resp_from_ggsn = |
| 939 | MSG_PDP_CTX_RSP("004e", |
| 940 | "00000001", /* destination TEI (sent in req above) */ |
| 941 | "6d31", /* mapped seq */ |
| 942 | "01", /* restart */ |
| 943 | "00000567", /* TEI U */ |
| 944 | "00000765", /* TEI C */ |
| 945 | "0004""c0a82b22", /* GSN addresses */ |
| 946 | "0004""c0a82b22" /* (== resolved_ggsn_addr) */ |
| 947 | ); |
| 948 | const char *gtp_resp_to_sgsn = |
| 949 | MSG_PDP_CTX_RSP("004e", |
| 950 | "00000321", /* unmapped TEI ("001") */ |
| 951 | "abcd", /* unmapped seq ("6d31") */ |
Neels Hofmeyr | ba9e9f6 | 2015-11-26 22:19:22 +0100 | [diff] [blame] | 952 | "23", |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 953 | "00000001", /* mapped TEI from GGSN ("567") */ |
| 954 | "00000001", /* mapped TEI from GGSN ("765") */ |
Neels Hofmeyr | 9cfe037 | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 955 | "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */ |
| 956 | "0004""7f000102" /* gtphub's address towards SGSNs (User) */ |
| 957 | ); |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 958 | /* The response should go back to whichever port the request came from |
| 959 | * (unmapped by sequence nr) */ |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 960 | LVL2_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr, |
| 961 | &sgsn_sender, |
| 962 | gtp_resp_from_ggsn, |
| 963 | gtp_resp_to_sgsn)); |
| 964 | |
| 965 | return 1; |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 966 | } |
| 967 | |
Neels Hofmeyr | 10fc024 | 2015-12-01 00:23:45 +0100 | [diff] [blame] | 968 | #define MSG_DEL_PDP_CTX_REQ(tei, seq) \ |
| 969 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr. */ \ |
| 970 | "14" /* type 20: Delete PDP Context Request */ \ |
| 971 | "0008" /* msg length = 8 + len (2 octets) */ \ |
| 972 | tei /* TEI Ctrl */ \ |
| 973 | seq /* Sequence nr (2 octets) */ \ |
| 974 | "00" /* N-PDU 0 */ \ |
| 975 | "00" /* No extensions */ \ |
| 976 | /* IEs */ \ |
| 977 | "13fe" /* 19: Teardown ind = 0 */ \ |
| 978 | "1400" /* 20: NSAPI = 0*/ \ |
| 979 | |
| 980 | #define MSG_DEL_PDP_CTX_RSP(tei, seq) \ |
| 981 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr. */ \ |
| 982 | "15" /* type 21: Delete PDP Context Response */ \ |
| 983 | "0006" /* msg length = 8 + len (2 octets) */ \ |
| 984 | tei /* TEI Ctrl */ \ |
| 985 | seq /* Sequence nr (2 octets) */ \ |
| 986 | "00" /* N-PDU 0 */ \ |
| 987 | "00" /* No extensions */ \ |
| 988 | /* IEs */ \ |
| 989 | "01" /* 1: Cause */ \ |
| 990 | "80" /* value = 0b10000000 = response, no rejection. */ \ |
| 991 | |
Neels Hofmeyr | 7559910 | 2015-12-01 01:01:16 +0100 | [diff] [blame] | 992 | static int delete_pdp_ctx_from_sgsn(void) |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 993 | { |
Neels Hofmeyr | 10fc024 | 2015-12-01 00:23:45 +0100 | [diff] [blame] | 994 | now += GTPH_EXPIRE_QUICKLY_SECS + 1; |
| 995 | gtphub_gc(hub, now); |
| 996 | |
| 997 | LVL2_ASSERT(tunnels_are( |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 998 | "TEI=1:" |
| 999 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1000 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | 10fc024 | 2015-12-01 00:23:45 +0100 | [diff] [blame] | 1001 | " @21945\n")); |
| 1002 | |
| 1003 | /* TEI Ctrl from above and next sequence after abcd. */ |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1004 | 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] | 1005 | const char *gtp_req_to_ggsn = MSG_DEL_PDP_CTX_REQ("00000765", "6d32"); |
| 1006 | |
| 1007 | LVL2_ASSERT(msg_from_sgsn_c(&sgsn_sender, |
| 1008 | &resolved_ggsn_addr, |
| 1009 | gtp_req_from_sgsn, |
| 1010 | gtp_req_to_ggsn)); |
| 1011 | |
| 1012 | /* 21945 + 31 = 21976 */ |
| 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 | " @21976\n")); |
| 1018 | |
| 1019 | const char *gtp_resp_from_ggsn = |
| 1020 | MSG_DEL_PDP_CTX_RSP("00000001", "6d32"); |
| 1021 | const char *gtp_resp_to_sgsn = |
| 1022 | MSG_DEL_PDP_CTX_RSP("00000321", "abce"); |
| 1023 | |
| 1024 | /* The response should go back to whichever port the request came from |
| 1025 | * (unmapped by sequence nr) */ |
| 1026 | LVL2_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr, |
| 1027 | &sgsn_sender, |
| 1028 | gtp_resp_from_ggsn, |
| 1029 | gtp_resp_to_sgsn)); |
| 1030 | |
| 1031 | LVL2_ASSERT(tunnels_are("")); |
| 1032 | |
| 1033 | return 1; |
| 1034 | } |
| 1035 | |
Neels Hofmeyr | 7559910 | 2015-12-01 01:01:16 +0100 | [diff] [blame] | 1036 | static int delete_pdp_ctx_from_ggsn(void) |
Neels Hofmeyr | 10fc024 | 2015-12-01 00:23:45 +0100 | [diff] [blame] | 1037 | { |
Neels Hofmeyr | 7559910 | 2015-12-01 01:01:16 +0100 | [diff] [blame] | 1038 | now += GTPH_EXPIRE_QUICKLY_SECS + 1; |
| 1039 | gtphub_gc(hub, now); |
| 1040 | |
| 1041 | LVL2_ASSERT(tunnels_are( |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1042 | "TEI=1:" |
| 1043 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1044 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | 7559910 | 2015-12-01 01:01:16 +0100 | [diff] [blame] | 1045 | " @21945\n")); |
| 1046 | |
| 1047 | /* TEI Ctrl from above and next sequence after abcd. */ |
| 1048 | const char *gtp_req_from_ggsn = MSG_DEL_PDP_CTX_REQ("00000001", "5432"); |
| 1049 | const char *gtp_req_to_sgsn = MSG_DEL_PDP_CTX_REQ("00000321", "6d31"); |
| 1050 | |
| 1051 | LVL2_ASSERT(msg_from_ggsn_c(&ggsn_sender, |
| 1052 | &resolved_sgsn_addr, |
| 1053 | gtp_req_from_ggsn, |
| 1054 | gtp_req_to_sgsn)); |
| 1055 | |
| 1056 | /* 21945 + 31 = 21976 */ |
| 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 | " @21976\n")); |
| 1062 | |
| 1063 | const char *gtp_resp_from_sgsn = |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1064 | MSG_DEL_PDP_CTX_RSP("00000001", "6d31"); |
Neels Hofmeyr | 7559910 | 2015-12-01 01:01:16 +0100 | [diff] [blame] | 1065 | const char *gtp_resp_to_ggsn = |
| 1066 | MSG_DEL_PDP_CTX_RSP("00000765", "5432"); |
| 1067 | |
| 1068 | /* The response should go back to whichever port the request came from |
| 1069 | * (unmapped by sequence nr) */ |
| 1070 | LVL2_ASSERT(msg_from_sgsn_c(&resolved_sgsn_addr, |
| 1071 | &ggsn_sender, |
| 1072 | gtp_resp_from_sgsn, |
| 1073 | gtp_resp_to_ggsn)); |
| 1074 | |
| 1075 | LVL2_ASSERT(tunnels_are("")); |
| 1076 | |
| 1077 | return 1; |
| 1078 | } |
| 1079 | |
| 1080 | static void test_one_pdp_ctx(int del_from_side) |
| 1081 | { |
| 1082 | if (del_from_side == GTPH_SIDE_SGSN) |
| 1083 | LOG("test_one_pdp_ctx (del from SGSN)") |
| 1084 | else LOG("test_one_pdp_ctx (del from GGSN)"); |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 1085 | OSMO_ASSERT(setup_test_hub()); |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1086 | |
Neels Hofmeyr | c227594 | 2015-11-10 22:07:04 +0100 | [diff] [blame] | 1087 | OSMO_ASSERT(create_pdp_ctx()); |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1088 | |
| 1089 | struct gtphub_peer_port *ggsn_port = |
Neels Hofmeyr | a9905a5 | 2015-11-29 23:49:48 +0100 | [diff] [blame] | 1090 | 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] | 1091 | &resolved_ggsn_addr); |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1092 | OSMO_ASSERT(ggsn_port); |
| 1093 | struct gtphub_peer *ggsn = ggsn_port->peer_addr->peer; |
| 1094 | /* now == 345; now + 30 == 375. |
| 1095 | * seq mapping from above: |
| 1096 | * 0xabcd == 43981 (sent in the packet) |
| 1097 | * 0x6d31 == 27953 (harcoded seq mapping start val) */ |
| 1098 | OSMO_ASSERT(nr_map_is(&ggsn->seq_map, "(43981->27953@375), ")); |
| 1099 | |
| 1100 | /* now == 345; now + (6 * 60 * 60) == 21600 + 345 == 21945. |
| 1101 | * 0x00000321 == 801 (TEI from SGSN Ctrl) |
| 1102 | * 0x00000123 == 291 (TEI from SGSN User) |
| 1103 | * 0x00000765 == 1893 (TEI from GGSN Ctrl) |
| 1104 | * 0x00000567 == 1383 (TEI from GGSN User) |
| 1105 | * Mapped TEIs should be 1 and 2. */ |
Neels Hofmeyr | e54cd15 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1106 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1107 | "TEI=1:" |
| 1108 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1109 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | e54cd15 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1110 | " @21945\n")); |
Neels Hofmeyr | 10fc024 | 2015-12-01 00:23:45 +0100 | [diff] [blame] | 1111 | |
Neels Hofmeyr | 7559910 | 2015-12-01 01:01:16 +0100 | [diff] [blame] | 1112 | if (del_from_side == GTPH_SIDE_SGSN) { |
| 1113 | OSMO_ASSERT(delete_pdp_ctx_from_sgsn()); |
| 1114 | } else { |
| 1115 | OSMO_ASSERT(delete_pdp_ctx_from_ggsn()); |
| 1116 | } |
Neels Hofmeyr | 10fc024 | 2015-12-01 00:23:45 +0100 | [diff] [blame] | 1117 | OSMO_ASSERT(tunnels_are("")); |
| 1118 | |
Neels Hofmeyr | 20bd6bf | 2015-11-20 00:08:28 +0100 | [diff] [blame] | 1119 | OSMO_ASSERT(clear_test_hub()); |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1120 | } |
| 1121 | |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1122 | static void test_user_data(void) |
| 1123 | { |
| 1124 | LOG("test_user_data"); |
| 1125 | |
| 1126 | OSMO_ASSERT(setup_test_hub()); |
| 1127 | |
| 1128 | OSMO_ASSERT(create_pdp_ctx()); |
| 1129 | |
Neels Hofmeyr | e54cd15 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1130 | /* now == 345; now + (6 * 60 * 60) == 21600 + 345 == 21945. */ |
| 1131 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1132 | "TEI=1:" |
| 1133 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1134 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | e54cd15 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1135 | " @21945\n")); |
| 1136 | |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1137 | LOG("- user data starts"); |
Neels Hofmeyr | e54cd15 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1138 | /* Now expect default port numbers for User plane. */ |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1139 | resolve_to_ggsn("192.168.43.34", 2152); |
| 1140 | resolve_to_sgsn("192.168.42.23", 2152); |
| 1141 | |
Neels Hofmeyr | e54cd15 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1142 | /* 10 minutes later */ |
| 1143 | now += 600; |
| 1144 | |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1145 | const char *u_from_ggsn = |
Neels Hofmeyr | 9cfe037 | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 1146 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */ |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1147 | "ff" /* type 255: G-PDU */ |
| 1148 | "0058" /* length: 88 + 8 octets == 96 */ |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1149 | "00000001" /* mapped TEI for SGSN from create_pdp_ctx() */ |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1150 | "0070" /* seq */ |
| 1151 | "0000" /* No extensions */ |
| 1152 | /* User data (ICMP packet), 96 - 12 = 84 octets */ |
| 1153 | "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8" |
| 1154 | "4156000000007241010000000000101112131415161718191a1b1c1d1e1f" |
| 1155 | "202122232425262728292a2b2c2d2e2f3031323334353637" |
| 1156 | ; |
| 1157 | const char *u_to_sgsn = |
Neels Hofmeyr | 9cfe037 | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 1158 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */ |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1159 | "ff" /* type 255: G-PDU */ |
| 1160 | "0058" /* length: 88 + 8 octets == 96 */ |
| 1161 | "00000123" /* unmapped User TEI */ |
| 1162 | "6d31" /* new mapped seq */ |
| 1163 | "0000" |
| 1164 | "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8" |
| 1165 | "4156000000007241010000000000101112131415161718191a1b1c1d1e1f" |
| 1166 | "202122232425262728292a2b2c2d2e2f3031323334353637" |
| 1167 | ; |
| 1168 | |
| 1169 | /* This depends on create_pdp_ctx() sending resolved_sgsn_addr as GSN |
| 1170 | * Address IEs in the GGSN's Create PDP Ctx Response. */ |
| 1171 | OSMO_ASSERT(msg_from_ggsn_u(&ggsn_sender, |
| 1172 | &resolved_sgsn_addr, |
| 1173 | u_from_ggsn, |
| 1174 | u_to_sgsn)); |
| 1175 | |
Neels Hofmeyr | e54cd15 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1176 | /* Make sure the user plane messages have refreshed the TEI mapping |
| 1177 | * timeouts: 21945 + 600 == 22545. */ |
| 1178 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1179 | "TEI=1:" |
| 1180 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1181 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | e54cd15 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1182 | " @22545\n")); |
| 1183 | |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1184 | const char *u_from_sgsn = |
Neels Hofmeyr | 9cfe037 | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 1185 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */ |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1186 | "ff" /* type 255: G-PDU */ |
| 1187 | "0058" /* length: 88 + 8 octets == 96 */ |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1188 | "00000001" /* mapped User TEI for GGSN from create_pdp_ctx() */ |
Neels Hofmeyr | 1ae3ebd | 2015-12-03 14:19:08 +0100 | [diff] [blame] | 1189 | "1234" /* unknown seq */ |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1190 | "0000" /* No extensions */ |
| 1191 | /* User data (ICMP packet), 96 - 12 = 84 octets */ |
| 1192 | "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8" |
| 1193 | "4156000000007241010000000000101112131415161718191a1b1c1d1e1f" |
| 1194 | "202122232425262728292a2b2c2d2e2f3031323334353637" |
| 1195 | ; |
| 1196 | const char *u_to_ggsn = |
Neels Hofmeyr | 9cfe037 | 2015-11-16 14:52:05 +0100 | [diff] [blame] | 1197 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */ |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1198 | "ff" /* type 255: G-PDU */ |
| 1199 | "0058" /* length: 88 + 8 octets == 96 */ |
| 1200 | "00000567" /* unmapped User TEI */ |
Neels Hofmeyr | 1ae3ebd | 2015-12-03 14:19:08 +0100 | [diff] [blame] | 1201 | "6d31" /* unmapped seq */ |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1202 | "0000" |
| 1203 | "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8" |
| 1204 | "4156000000007241010000000000101112131415161718191a1b1c1d1e1f" |
| 1205 | "202122232425262728292a2b2c2d2e2f3031323334353637" |
| 1206 | ; |
| 1207 | |
Neels Hofmeyr | 1ae3ebd | 2015-12-03 14:19:08 +0100 | [diff] [blame] | 1208 | OSMO_ASSERT(msg_from_sgsn_u(&sgsn_sender, |
| 1209 | &resolved_ggsn_addr, |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1210 | u_from_sgsn, |
| 1211 | u_to_ggsn)); |
| 1212 | |
Neels Hofmeyr | e54cd15 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1213 | /* Make sure the user plane messages have refreshed the TEI mapping |
| 1214 | * timeouts: 21945 + 600 == 22545. Both timeouts refreshed: */ |
| 1215 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1216 | "TEI=1:" |
| 1217 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1218 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | e54cd15 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1219 | " @22545\n")); |
| 1220 | |
Neels Hofmeyr | 20bd6bf | 2015-11-20 00:08:28 +0100 | [diff] [blame] | 1221 | OSMO_ASSERT(clear_test_hub()); |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1222 | } |
| 1223 | |
Neels Hofmeyr | be4beba | 2015-12-02 14:18:26 +0100 | [diff] [blame] | 1224 | static void test_reused_tei(void) |
| 1225 | { |
| 1226 | LOG("test_reused_tei"); |
| 1227 | |
| 1228 | OSMO_ASSERT(setup_test_hub()); |
| 1229 | |
| 1230 | OSMO_ASSERT(create_pdp_ctx()); |
| 1231 | |
| 1232 | const char *gtp_req_from_sgsn = |
| 1233 | MSG_PDP_CTX_REQ("0068", |
| 1234 | "abce", /* Next seq */ |
| 1235 | "60", |
| 1236 | "42000121436587f9", |
| 1237 | "00000123", /* Same TEIs as before */ |
| 1238 | "00000321", |
| 1239 | "0009""08696e7465726e6574", /* "(8)internet" */ |
| 1240 | "0004""c0a82a17", /* same as default sgsn_sender */ |
| 1241 | "0004""c0a82a17" |
| 1242 | ); |
| 1243 | const char *gtp_req_to_ggsn = |
| 1244 | MSG_PDP_CTX_REQ("0068", |
| 1245 | "6d32", /* mapped seq ("abce") */ |
| 1246 | "23", |
| 1247 | "42000121436587f9", |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1248 | "00000002", /* mapped TEI Data I ("123") */ |
| 1249 | "00000002", /* mapped TEI Control ("321") */ |
Neels Hofmeyr | be4beba | 2015-12-02 14:18:26 +0100 | [diff] [blame] | 1250 | "0009""08696e7465726e6574", |
| 1251 | "0004""7f000201", /* replaced with gtphub's ggsn ctrl */ |
| 1252 | "0004""7f000202" /* replaced with gtphub's ggsn user */ |
| 1253 | ); |
| 1254 | |
| 1255 | OSMO_ASSERT(msg_from_sgsn_c(&sgsn_sender, |
| 1256 | &resolved_ggsn_addr, |
| 1257 | gtp_req_from_sgsn, |
| 1258 | gtp_req_to_ggsn)); |
| 1259 | OSMO_ASSERT(was_resolved_for("240010123456789", "internet")); |
| 1260 | |
| 1261 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1262 | "TEI=2:" |
| 1263 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1264 | " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)" |
Neels Hofmeyr | be4beba | 2015-12-02 14:18:26 +0100 | [diff] [blame] | 1265 | " @21945\n")); |
| 1266 | |
| 1267 | const char *gtp_resp_from_ggsn = |
| 1268 | MSG_PDP_CTX_RSP("004e", |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1269 | "00000002", /* destination TEI (sent in req above) */ |
Neels Hofmeyr | be4beba | 2015-12-02 14:18:26 +0100 | [diff] [blame] | 1270 | "6d32", /* mapped seq */ |
| 1271 | "01", /* restart */ |
| 1272 | "00000567", /* TEI U */ |
| 1273 | "00000765", /* TEI C */ |
| 1274 | "0004""c0a82b22", /* GSN addresses */ |
| 1275 | "0004""c0a82b22" /* (== resolved_ggsn_addr) */ |
| 1276 | ); |
| 1277 | const char *gtp_resp_to_sgsn = |
| 1278 | MSG_PDP_CTX_RSP("004e", |
| 1279 | "00000321", /* unmapped TEI ("001") */ |
| 1280 | "abce", /* unmapped seq ("6d32") */ |
| 1281 | "23", |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1282 | "00000002", /* mapped TEI from GGSN ("567") */ |
| 1283 | "00000002", /* mapped TEI from GGSN ("765") */ |
Neels Hofmeyr | be4beba | 2015-12-02 14:18:26 +0100 | [diff] [blame] | 1284 | "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */ |
| 1285 | "0004""7f000102" /* gtphub's address towards SGSNs (User) */ |
| 1286 | ); |
| 1287 | /* The response should go back to whichever port the request came from |
| 1288 | * (unmapped by sequence nr) */ |
| 1289 | OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr, |
| 1290 | &sgsn_sender, |
| 1291 | gtp_resp_from_ggsn, |
| 1292 | gtp_resp_to_sgsn)); |
| 1293 | |
| 1294 | OSMO_ASSERT(clear_test_hub()); |
| 1295 | } |
| 1296 | |
Neels Hofmeyr | 237fee6 | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1297 | static void test_peer_restarted(void) |
| 1298 | { |
| 1299 | LOG("test_peer_restarted"); |
| 1300 | |
| 1301 | OSMO_ASSERT(setup_test_hub()); |
| 1302 | |
| 1303 | OSMO_ASSERT(create_pdp_ctx()); |
| 1304 | |
| 1305 | now += 10; |
| 1306 | |
| 1307 | const char *gtp_req_from_sgsn = |
| 1308 | MSG_PDP_CTX_REQ("0068", |
| 1309 | "1234", /* brand new seq */ |
| 1310 | "61", /* DIFFERING restart counter */ |
| 1311 | "42000121436587f9", |
| 1312 | "00000abc", |
| 1313 | "00000cba", |
| 1314 | "0009""08696e7465726e6574", /* "(8)internet" */ |
| 1315 | "0004""c0a82a17", /* same as default sgsn_sender */ |
| 1316 | "0004""c0a82a17" |
| 1317 | ); |
| 1318 | const char *gtp_req_to_ggsn = |
| 1319 | MSG_PDP_CTX_REQ("0068", |
Neels Hofmeyr | c6d51f5 | 2015-12-02 15:44:34 +0100 | [diff] [blame] | 1320 | "6d33", /* mapped seq ("1234") */ |
Neels Hofmeyr | 237fee6 | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1321 | "23", |
| 1322 | "42000121436587f9", |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1323 | "00000002", /* mapped TEI Data I ("123") */ |
| 1324 | "00000002", /* mapped TEI Control ("321") */ |
Neels Hofmeyr | 237fee6 | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1325 | "0009""08696e7465726e6574", |
| 1326 | "0004""7f000201", /* replaced with gtphub's ggsn ctrl */ |
| 1327 | "0004""7f000202" /* replaced with gtphub's ggsn user */ |
| 1328 | ); |
| 1329 | |
| 1330 | OSMO_ASSERT(msg_from_sgsn_c(&sgsn_sender, |
| 1331 | &resolved_ggsn_addr, |
| 1332 | gtp_req_from_sgsn, |
| 1333 | gtp_req_to_ggsn)); |
| 1334 | OSMO_ASSERT(was_resolved_for("240010123456789", "internet")); |
| 1335 | |
| 1336 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1337 | "TEI=2:" |
| 1338 | " 192.168.42.23 (TEI C=cba U=abc)" |
| 1339 | " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)" |
Neels Hofmeyr | 237fee6 | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1340 | " @21955\n" |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1341 | "TEI=1:" |
| 1342 | " (uninitialized) (TEI C=321 U=123)" |
| 1343 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | 237fee6 | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1344 | " @21945\n" |
| 1345 | )); |
| 1346 | |
| 1347 | const char *gtp_resp_from_ggsn = |
| 1348 | MSG_PDP_CTX_RSP("004e", |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1349 | "00000002", /* destination TEI (sent in req above) */ |
Neels Hofmeyr | c6d51f5 | 2015-12-02 15:44:34 +0100 | [diff] [blame] | 1350 | "6d33", /* mapped seq */ |
Neels Hofmeyr | 237fee6 | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1351 | "01", /* restart */ |
| 1352 | "00000def", /* TEI U */ |
| 1353 | "00000fde", /* TEI C */ |
| 1354 | "0004""c0a82b22", /* GSN addresses */ |
| 1355 | "0004""c0a82b22" /* (== resolved_ggsn_addr) */ |
| 1356 | ); |
| 1357 | const char *gtp_resp_to_sgsn = |
| 1358 | MSG_PDP_CTX_RSP("004e", |
| 1359 | "00000cba", /* unmapped TEI ("005") */ |
| 1360 | "1234", /* unmapped seq ("6d32") */ |
| 1361 | "23", |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1362 | "00000002", /* mapped TEI from GGSN ("567") */ |
| 1363 | "00000002", /* mapped TEI from GGSN ("765") */ |
Neels Hofmeyr | 237fee6 | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1364 | "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */ |
| 1365 | "0004""7f000102" /* gtphub's address towards SGSNs (User) */ |
| 1366 | ); |
| 1367 | /* The response should go back to whichever port the request came from |
| 1368 | * (unmapped by sequence nr) */ |
| 1369 | OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr, |
| 1370 | &sgsn_sender, |
| 1371 | gtp_resp_from_ggsn, |
| 1372 | gtp_resp_to_sgsn)); |
| 1373 | |
| 1374 | OSMO_ASSERT(clear_test_hub()); |
| 1375 | } |
| 1376 | |
| 1377 | static void test_peer_restarted_reusing_tei(void) |
| 1378 | { |
| 1379 | LOG("test_peer_restarted_reusing_tei"); |
| 1380 | |
| 1381 | OSMO_ASSERT(setup_test_hub()); |
| 1382 | |
| 1383 | OSMO_ASSERT(create_pdp_ctx()); |
| 1384 | |
| 1385 | now += 10; |
| 1386 | |
| 1387 | const char *gtp_req_from_sgsn = |
| 1388 | MSG_PDP_CTX_REQ("0068", |
| 1389 | "1234", /* brand new seq */ |
| 1390 | "61", /* DIFFERING restart counter */ |
| 1391 | "42000121436587f9", |
| 1392 | "00000123", /* SAME TEI */ |
| 1393 | "00000321", |
| 1394 | "0009""08696e7465726e6574", /* "(8)internet" */ |
| 1395 | "0004""c0a82a17", /* same as default sgsn_sender */ |
| 1396 | "0004""c0a82a17" |
| 1397 | ); |
| 1398 | const char *gtp_req_to_ggsn = |
| 1399 | MSG_PDP_CTX_REQ("0068", |
Neels Hofmeyr | d010c49 | 2015-12-06 23:12:02 +0100 | [diff] [blame] | 1400 | "6d33", /* seq 6d31 + 2, after "out-of-band" Delete PDP Ctx |
| 1401 | due to differing restart counter. */ |
Neels Hofmeyr | 237fee6 | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1402 | "23", |
| 1403 | "42000121436587f9", |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1404 | "00000002", /* mapped TEI Data I ("123") */ |
| 1405 | "00000002", /* mapped TEI Control ("321") */ |
Neels Hofmeyr | 237fee6 | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1406 | "0009""08696e7465726e6574", |
| 1407 | "0004""7f000201", /* replaced with gtphub's ggsn ctrl */ |
| 1408 | "0004""7f000202" /* replaced with gtphub's ggsn user */ |
| 1409 | ); |
| 1410 | |
| 1411 | OSMO_ASSERT(msg_from_sgsn_c(&sgsn_sender, |
| 1412 | &resolved_ggsn_addr, |
| 1413 | gtp_req_from_sgsn, |
| 1414 | gtp_req_to_ggsn)); |
| 1415 | OSMO_ASSERT(was_resolved_for("240010123456789", "internet")); |
| 1416 | |
| 1417 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | d010c49 | 2015-12-06 23:12:02 +0100 | [diff] [blame] | 1418 | "TEI=2:" /* being established after restart */ |
| 1419 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1420 | " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)" |
| 1421 | " @21955\n" |
| 1422 | "TEI=1:" /* invalidated due to restart */ |
| 1423 | " (uninitialized) (TEI C=321 U=123)" |
| 1424 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
| 1425 | " @21945\n" |
| 1426 | )); |
| 1427 | |
| 1428 | /* An "out-of-band" delete request should have been sent to the GGSN |
| 1429 | * (checked by expected log output in gtphub_test.ok), and the GGSN |
| 1430 | * will (usually) send a Delete Response like this: */ |
| 1431 | const char *gtp_del_resp_from_ggsn = |
| 1432 | MSG_DEL_PDP_CTX_RSP("00000001", "6d32"); |
| 1433 | |
| 1434 | /* For this response (due to peer restart) we expect no forwarded |
| 1435 | * message. */ |
| 1436 | OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr, |
| 1437 | &sgsn_sender, |
| 1438 | gtp_del_resp_from_ggsn, |
| 1439 | "")); |
| 1440 | |
| 1441 | OSMO_ASSERT(tunnels_are( |
| 1442 | "TEI=2:" /* still being established after restart */ |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1443 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1444 | " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)" |
Neels Hofmeyr | 237fee6 | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1445 | " @21955\n" |
| 1446 | )); |
| 1447 | |
| 1448 | const char *gtp_resp_from_ggsn = |
| 1449 | MSG_PDP_CTX_RSP("004e", |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1450 | "00000002", /* destination TEI (sent in req above) */ |
Neels Hofmeyr | d010c49 | 2015-12-06 23:12:02 +0100 | [diff] [blame] | 1451 | "6d33", /* mapped seq */ |
Neels Hofmeyr | 237fee6 | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1452 | "01", /* restart */ |
| 1453 | "00000def", /* TEI U */ |
| 1454 | "00000fde", /* TEI C */ |
| 1455 | "0004""c0a82b22", /* GSN addresses */ |
| 1456 | "0004""c0a82b22" /* (== resolved_ggsn_addr) */ |
| 1457 | ); |
| 1458 | const char *gtp_resp_to_sgsn = |
| 1459 | MSG_PDP_CTX_RSP("004e", |
| 1460 | "00000321", /* unmapped TEI ("005") */ |
Neels Hofmeyr | d010c49 | 2015-12-06 23:12:02 +0100 | [diff] [blame] | 1461 | "1234", /* unmapped seq ("6d33") */ |
Neels Hofmeyr | 237fee6 | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1462 | "23", |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1463 | "00000002", /* mapped TEI from GGSN ("567") */ |
| 1464 | "00000002", /* mapped TEI from GGSN ("765") */ |
Neels Hofmeyr | 237fee6 | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1465 | "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */ |
| 1466 | "0004""7f000102" /* gtphub's address towards SGSNs (User) */ |
| 1467 | ); |
| 1468 | /* The response should go back to whichever port the request came from |
| 1469 | * (unmapped by sequence nr) */ |
| 1470 | OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr, |
| 1471 | &sgsn_sender, |
| 1472 | gtp_resp_from_ggsn, |
| 1473 | gtp_resp_to_sgsn)); |
| 1474 | |
Neels Hofmeyr | d010c49 | 2015-12-06 23:12:02 +0100 | [diff] [blame] | 1475 | OSMO_ASSERT(tunnels_are( |
| 1476 | "TEI=2:" /* still being established after restart */ |
| 1477 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1478 | " <-> 192.168.43.34 (TEI C=fde U=def)" |
| 1479 | " @21955\n" |
| 1480 | )); |
| 1481 | |
Neels Hofmeyr | 237fee6 | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1482 | OSMO_ASSERT(clear_test_hub()); |
| 1483 | } |
| 1484 | |
Neels Hofmeyr | f8c7010 | 2015-12-03 14:29:48 +0100 | [diff] [blame] | 1485 | static void test_sgsn_behind_nat(void) |
| 1486 | { |
| 1487 | LOG("test_user_data"); |
| 1488 | |
| 1489 | OSMO_ASSERT(setup_test_hub()); |
| 1490 | hub->sgsn_use_sender = 1; /* <-- Main difference to test_user_data() */ |
| 1491 | resolve_to_sgsn("192.168.42.23", 423); /* Same as sender */ |
| 1492 | |
| 1493 | OSMO_ASSERT(create_pdp_ctx()); |
| 1494 | |
| 1495 | /* now == 345; now + (6 * 60 * 60) == 21600 + 345 == 21945. */ |
| 1496 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1497 | "TEI=1:" |
| 1498 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1499 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | f8c7010 | 2015-12-03 14:29:48 +0100 | [diff] [blame] | 1500 | " @21945\n")); |
| 1501 | |
| 1502 | LOG("- user data starts"); |
| 1503 | /* Now expect default port numbers for User plane -- except SGSN. */ |
| 1504 | resolve_to_ggsn("192.168.43.34", 2152); |
| 1505 | |
| 1506 | /* 10 minutes later */ |
| 1507 | now += 600; |
| 1508 | |
| 1509 | const char *u_from_ggsn = |
| 1510 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */ |
| 1511 | "ff" /* type 255: G-PDU */ |
| 1512 | "0058" /* length: 88 + 8 octets == 96 */ |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1513 | "00000001" /* mapped User TEI for SGSN from create_pdp_ctx() */ |
Neels Hofmeyr | f8c7010 | 2015-12-03 14:29:48 +0100 | [diff] [blame] | 1514 | "0070" /* seq */ |
| 1515 | "0000" /* No extensions */ |
| 1516 | /* User data (ICMP packet), 96 - 12 = 84 octets */ |
| 1517 | "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8" |
| 1518 | "4156000000007241010000000000101112131415161718191a1b1c1d1e1f" |
| 1519 | "202122232425262728292a2b2c2d2e2f3031323334353637" |
| 1520 | ; |
| 1521 | const char *u_to_sgsn = |
| 1522 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */ |
| 1523 | "ff" /* type 255: G-PDU */ |
| 1524 | "0058" /* length: 88 + 8 octets == 96 */ |
| 1525 | "00000123" /* unmapped User TEI */ |
| 1526 | "6d31" /* new mapped seq */ |
| 1527 | "0000" |
| 1528 | "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8" |
| 1529 | "4156000000007241010000000000101112131415161718191a1b1c1d1e1f" |
| 1530 | "202122232425262728292a2b2c2d2e2f3031323334353637" |
| 1531 | ; |
| 1532 | |
| 1533 | /* This depends on create_pdp_ctx() sending resolved_sgsn_addr as GSN |
| 1534 | * Address IEs in the GGSN's Create PDP Ctx Response. */ |
| 1535 | OSMO_ASSERT(msg_from_ggsn_u(&ggsn_sender, |
| 1536 | &resolved_sgsn_addr, |
| 1537 | u_from_ggsn, |
| 1538 | u_to_sgsn)); |
| 1539 | |
| 1540 | /* Make sure the user plane messages have refreshed the TEI mapping |
| 1541 | * timeouts: 21945 + 600 == 22545. */ |
| 1542 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1543 | "TEI=1:" |
| 1544 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1545 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | f8c7010 | 2015-12-03 14:29:48 +0100 | [diff] [blame] | 1546 | " @22545\n")); |
| 1547 | |
| 1548 | const char *u_from_sgsn = |
| 1549 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */ |
| 1550 | "ff" /* type 255: G-PDU */ |
| 1551 | "0058" /* length: 88 + 8 octets == 96 */ |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1552 | "00000001" /* mapped User TEI for GGSN from create_pdp_ctx() */ |
Neels Hofmeyr | f8c7010 | 2015-12-03 14:29:48 +0100 | [diff] [blame] | 1553 | "1234" /* unknown seq */ |
| 1554 | "0000" /* No extensions */ |
| 1555 | /* User data (ICMP packet), 96 - 12 = 84 octets */ |
| 1556 | "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8" |
| 1557 | "4156000000007241010000000000101112131415161718191a1b1c1d1e1f" |
| 1558 | "202122232425262728292a2b2c2d2e2f3031323334353637" |
| 1559 | ; |
| 1560 | const char *u_to_ggsn = |
| 1561 | "32" /* 0b001'1 0010: version 1, protocol GTP, with seq nr */ |
| 1562 | "ff" /* type 255: G-PDU */ |
| 1563 | "0058" /* length: 88 + 8 octets == 96 */ |
| 1564 | "00000567" /* unmapped User TEI */ |
| 1565 | "6d31" /* unmapped seq */ |
| 1566 | "0000" |
| 1567 | "45000054daee40004001f7890a172a010a172a02080060d23f590071e3f8" |
| 1568 | "4156000000007241010000000000101112131415161718191a1b1c1d1e1f" |
| 1569 | "202122232425262728292a2b2c2d2e2f3031323334353637" |
| 1570 | ; |
| 1571 | |
| 1572 | OSMO_ASSERT(msg_from_sgsn_u(&sgsn_sender, |
| 1573 | &resolved_ggsn_addr, |
| 1574 | u_from_sgsn, |
| 1575 | u_to_ggsn)); |
| 1576 | |
| 1577 | /* Make sure the user plane messages have refreshed the TEI mapping |
| 1578 | * timeouts: 21945 + 600 == 22545. Both timeouts refreshed: */ |
| 1579 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1580 | "TEI=1:" |
| 1581 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1582 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | f8c7010 | 2015-12-03 14:29:48 +0100 | [diff] [blame] | 1583 | " @22545\n")); |
| 1584 | |
| 1585 | OSMO_ASSERT(clear_test_hub()); |
| 1586 | } |
| 1587 | |
Neels Hofmeyr | 23d09cc | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1588 | void test_parallel_context_creation(void) |
| 1589 | { |
| 1590 | LOG("test_parallel_context_creation"); |
| 1591 | |
| 1592 | OSMO_ASSERT(setup_test_hub()); |
| 1593 | |
| 1594 | const char *gtp_req_from_sgsn1 = |
| 1595 | MSG_PDP_CTX_REQ("0068", |
| 1596 | "abcd", |
| 1597 | "60", |
| 1598 | "42000121436587f9", |
| 1599 | "00000123", |
| 1600 | "00000321", |
| 1601 | "0009""08696e7465726e6574", /* "(8)internet" */ |
| 1602 | "0004""c0a82a17", /* same as default sgsn_sender */ |
| 1603 | "0004""c0a82a17" |
| 1604 | ); |
| 1605 | const char *gtp_req_to_ggsn1 = |
| 1606 | MSG_PDP_CTX_REQ("0068", |
| 1607 | "6d31", /* mapped seq ("abcd") */ |
| 1608 | "23", |
| 1609 | "42000121436587f9", |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1610 | "00000001", /* mapped TEI Data I ("123") */ |
Neels Hofmeyr | 23d09cc | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1611 | "00000001", /* mapped TEI Control ("321") */ |
| 1612 | "0009""08696e7465726e6574", |
| 1613 | "0004""7f000201", /* replaced with gtphub's ggsn ctrl */ |
| 1614 | "0004""7f000202" /* replaced with gtphub's ggsn user */ |
| 1615 | ); |
| 1616 | |
| 1617 | OSMO_ASSERT(msg_from_sgsn_c(&sgsn_sender, |
| 1618 | &resolved_ggsn_addr, |
| 1619 | gtp_req_from_sgsn1, |
| 1620 | gtp_req_to_ggsn1)); |
| 1621 | |
| 1622 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1623 | "TEI=1:" |
| 1624 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1625 | " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)" |
Neels Hofmeyr | 23d09cc | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1626 | " @21945\n")); |
| 1627 | |
| 1628 | now ++; |
| 1629 | |
| 1630 | const char *gtp_req_from_sgsn2 = |
| 1631 | MSG_PDP_CTX_REQ("0068", |
| 1632 | "abce", |
| 1633 | "60", |
| 1634 | "42000121436588f9", |
| 1635 | "00000124", |
| 1636 | "00000322", |
| 1637 | "0009""08696e7465726e6574", /* "(8)internet" */ |
| 1638 | "0004""c0a82a17", /* same as default sgsn_sender */ |
| 1639 | "0004""c0a82a17" |
| 1640 | ); |
| 1641 | const char *gtp_req_to_ggsn2 = |
| 1642 | MSG_PDP_CTX_REQ("0068", |
| 1643 | "6d32", /* mapped seq ("abce") */ |
| 1644 | "23", |
| 1645 | "42000121436588f9", |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1646 | "00000002", /* mapped TEI Data I ("124") */ |
| 1647 | "00000002", /* mapped TEI Control ("322") */ |
Neels Hofmeyr | 23d09cc | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1648 | "0009""08696e7465726e6574", |
| 1649 | "0004""7f000201", /* replaced with gtphub's ggsn ctrl */ |
| 1650 | "0004""7f000202" /* replaced with gtphub's ggsn user */ |
| 1651 | ); |
| 1652 | |
| 1653 | OSMO_ASSERT(msg_from_sgsn_c(&sgsn_sender, |
| 1654 | &resolved_ggsn_addr, |
| 1655 | gtp_req_from_sgsn2, |
| 1656 | gtp_req_to_ggsn2)); |
| 1657 | |
| 1658 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1659 | "TEI=2:" |
| 1660 | " 192.168.42.23 (TEI C=322 U=124)" |
| 1661 | " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)" |
Neels Hofmeyr | 23d09cc | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1662 | " @21946\n" |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1663 | "TEI=1:" |
| 1664 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1665 | " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)" |
Neels Hofmeyr | 23d09cc | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1666 | " @21945\n" |
| 1667 | )); |
| 1668 | |
| 1669 | now ++; |
| 1670 | |
| 1671 | const char *gtp_resp_from_ggsn1 = |
| 1672 | MSG_PDP_CTX_RSP("004e", |
| 1673 | "00000001", /* destination TEI (sent in req above) */ |
| 1674 | "6d31", /* mapped seq */ |
| 1675 | "01", /* restart */ |
| 1676 | "00000567", /* TEI U */ |
| 1677 | "00000765", /* TEI C */ |
| 1678 | "0004""c0a82b22", /* GSN addresses */ |
| 1679 | "0004""c0a82b22" /* (== resolved_ggsn_addr) */ |
| 1680 | ); |
| 1681 | const char *gtp_resp_to_sgsn1 = |
| 1682 | MSG_PDP_CTX_RSP("004e", |
| 1683 | "00000321", /* unmapped TEI ("001") */ |
| 1684 | "abcd", /* unmapped seq ("6d31") */ |
| 1685 | "23", |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1686 | "00000001", /* mapped TEI from GGSN ("567") */ |
| 1687 | "00000001", /* mapped TEI from GGSN ("765") */ |
Neels Hofmeyr | 23d09cc | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1688 | "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */ |
| 1689 | "0004""7f000102" /* gtphub's address towards SGSNs (User) */ |
| 1690 | ); |
| 1691 | |
| 1692 | OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr, |
| 1693 | &sgsn_sender, |
| 1694 | gtp_resp_from_ggsn1, |
| 1695 | gtp_resp_to_sgsn1)); |
| 1696 | |
| 1697 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1698 | "TEI=2:" |
| 1699 | " 192.168.42.23 (TEI C=322 U=124)" |
| 1700 | " <-> 192.168.43.34/(uninitialized) (TEI C=0 U=0)" |
Neels Hofmeyr | 23d09cc | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1701 | " @21946\n" |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1702 | "TEI=1:" |
| 1703 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1704 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | 23d09cc | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1705 | " @21947\n" |
| 1706 | )); |
| 1707 | |
| 1708 | now ++; |
| 1709 | |
| 1710 | const char *gtp_resp_from_ggsn2 = |
| 1711 | MSG_PDP_CTX_RSP("004e", |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1712 | "00000002", /* destination TEI (sent in req above) */ |
Neels Hofmeyr | 23d09cc | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1713 | "6d32", /* mapped seq */ |
| 1714 | "01", /* restart */ |
| 1715 | "00000568", /* TEI U */ |
| 1716 | "00000766", /* TEI C */ |
| 1717 | "0004""c0a82b22", /* GSN addresses */ |
| 1718 | "0004""c0a82b22" /* (== resolved_ggsn_addr) */ |
| 1719 | ); |
| 1720 | const char *gtp_resp_to_sgsn2 = |
| 1721 | MSG_PDP_CTX_RSP("004e", |
| 1722 | "00000322", /* unmapped TEI ("001") */ |
| 1723 | "abce", /* unmapped seq ("6d31") */ |
| 1724 | "23", |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1725 | "00000002", /* mapped TEI from GGSN ("567") */ |
| 1726 | "00000002", /* mapped TEI from GGSN ("765") */ |
Neels Hofmeyr | 23d09cc | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1727 | "0004""7f000101", /* gtphub's address towards SGSNs (Ctrl) */ |
| 1728 | "0004""7f000102" /* gtphub's address towards SGSNs (User) */ |
| 1729 | ); |
| 1730 | |
| 1731 | OSMO_ASSERT(msg_from_ggsn_c(&resolved_ggsn_addr, |
| 1732 | &sgsn_sender, |
| 1733 | gtp_resp_from_ggsn2, |
| 1734 | gtp_resp_to_sgsn2)); |
| 1735 | |
| 1736 | OSMO_ASSERT(tunnels_are( |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1737 | "TEI=2:" |
| 1738 | " 192.168.42.23 (TEI C=322 U=124)" |
| 1739 | " <-> 192.168.43.34 (TEI C=766 U=568)" |
Neels Hofmeyr | 23d09cc | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1740 | " @21948\n" |
Neels Hofmeyr | ee07e4f | 2015-12-06 19:11:45 +0100 | [diff] [blame] | 1741 | "TEI=1:" |
| 1742 | " 192.168.42.23 (TEI C=321 U=123)" |
| 1743 | " <-> 192.168.43.34 (TEI C=765 U=567)" |
Neels Hofmeyr | 23d09cc | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1744 | " @21947\n" |
| 1745 | )); |
| 1746 | |
| 1747 | OSMO_ASSERT(clear_test_hub()); |
| 1748 | } |
| 1749 | |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1750 | |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1751 | static struct log_info_cat gtphub_categories[] = { |
| 1752 | [DGTPHUB] = { |
| 1753 | .name = "DGTPHUB", |
| 1754 | .description = "GTP Hub", |
| 1755 | .color = "\033[1;33m", |
Neels Hofmeyr | e54cd15 | 2015-11-24 13:31:06 +0100 | [diff] [blame] | 1756 | .enabled = 1, .loglevel = LOGL_DEBUG, |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1757 | }, |
| 1758 | }; |
| 1759 | |
| 1760 | static struct log_info info = { |
| 1761 | .cat = gtphub_categories, |
| 1762 | .num_cat = ARRAY_SIZE(gtphub_categories), |
| 1763 | }; |
| 1764 | |
| 1765 | int main(int argc, char **argv) |
| 1766 | { |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1767 | osmo_gtphub_ctx = talloc_named_const(NULL, 0, "osmo_gtphub"); |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 1768 | void *log_ctx = talloc_named_const(osmo_gtphub_ctx, 0, "log"); |
| 1769 | osmo_init_logging2(log_ctx, &info); |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1770 | |
| 1771 | test_nr_map_basic(); |
Neels Hofmeyr | e2ed8e6 | 2015-11-17 14:30:37 +0100 | [diff] [blame] | 1772 | test_nr_map_wrap(); |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1773 | test_expiry(); |
| 1774 | test_echo(); |
Neels Hofmeyr | 7559910 | 2015-12-01 01:01:16 +0100 | [diff] [blame] | 1775 | test_one_pdp_ctx(GTPH_SIDE_SGSN); |
| 1776 | test_one_pdp_ctx(GTPH_SIDE_GGSN); |
Neels Hofmeyr | e921e32 | 2015-11-11 00:45:50 +0100 | [diff] [blame] | 1777 | test_user_data(); |
Neels Hofmeyr | be4beba | 2015-12-02 14:18:26 +0100 | [diff] [blame] | 1778 | test_reused_tei(); |
Neels Hofmeyr | 237fee6 | 2015-12-02 14:31:45 +0100 | [diff] [blame] | 1779 | test_peer_restarted(); |
| 1780 | test_peer_restarted_reusing_tei(); |
Neels Hofmeyr | f8c7010 | 2015-12-03 14:29:48 +0100 | [diff] [blame] | 1781 | test_sgsn_behind_nat(); |
Neels Hofmeyr | 23d09cc | 2015-12-06 19:02:43 +0100 | [diff] [blame] | 1782 | test_parallel_context_creation(); |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1783 | printf("Done\n"); |
| 1784 | |
| 1785 | talloc_report_full(osmo_gtphub_ctx, stderr); |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 1786 | talloc_free(log_ctx); |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1787 | OSMO_ASSERT(talloc_total_blocks(osmo_gtphub_ctx) == 1); |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame] | 1788 | talloc_free(osmo_gtphub_ctx); |
Neels Hofmeyr | c8a614d | 2015-09-24 17:32:30 +0200 | [diff] [blame] | 1789 | return 0; |
| 1790 | } |
| 1791 | |