Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 1 | /* Code for a software PCU to test a SGSN.. */ |
| 2 | |
| 3 | /* (C) 2013 by Holger Hans Peter Freyther |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | extern "C" { |
| 23 | #include <osmocom/core/talloc.h> |
| 24 | #include <pcu_vty.h> |
| 25 | } |
| 26 | |
Holger Hans Peter Freyther | 9d93838 | 2013-07-31 21:59:29 +0200 | [diff] [blame] | 27 | #include "gprs_tests.h" |
| 28 | |
| 29 | |
Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 30 | #include <gprs_bssgp_pcu.h> |
| 31 | #include <gprs_rlcmac.h> |
Holger Hans Peter Freyther | 67ed34e | 2013-10-17 17:01:54 +0200 | [diff] [blame] | 32 | #include <bts.h> |
Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 33 | |
| 34 | #include <stdlib.h> |
| 35 | #include <sys/types.h> |
| 36 | #include <sys/socket.h> |
| 37 | |
Jacob Erlbeck | 0494c75 | 2015-05-04 09:34:00 +0200 | [diff] [blame] | 38 | static size_t current_test; |
Holger Hans Peter Freyther | 9d93838 | 2013-07-31 21:59:29 +0200 | [diff] [blame] | 39 | |
Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 40 | /* Extern data to please the underlying code */ |
| 41 | void *tall_pcu_ctx; |
Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 42 | int16_t spoof_mnc = 0, spoof_mcc = 0; |
| 43 | |
Holger Hans Peter Freyther | 741481d | 2013-07-28 21:14:51 +0200 | [diff] [blame] | 44 | extern void test_replay_gprs_attach(struct gprs_bssgp_pcu *pcu); |
Holger Hans Peter Freyther | bc1e52c | 2013-08-22 08:44:38 +0200 | [diff] [blame] | 45 | extern void test_replay_gprs_data(struct gprs_bssgp_pcu *, struct msgb *, struct tlv_parsed *); |
Holger Hans Peter Freyther | 741481d | 2013-07-28 21:14:51 +0200 | [diff] [blame] | 46 | |
Holger Hans Peter Freyther | 9d93838 | 2013-07-31 21:59:29 +0200 | [diff] [blame] | 47 | extern void test_pdp_activation_start(struct gprs_bssgp_pcu *pcu); |
| 48 | extern void test_pdp_activation_data(struct gprs_bssgp_pcu *, struct msgb *, struct tlv_parsed*); |
| 49 | |
| 50 | struct gprs_test all_tests[] = { |
| 51 | gprs_test("gprs_attach_with_tmsi", |
| 52 | "A simple test that verifies that N(U) is " |
| 53 | "increasing across various messages. This makes " |
| 54 | "sure that no new LLE/LLME is created on the fly.", |
| 55 | test_replay_gprs_attach, |
| 56 | test_replay_gprs_data), |
| 57 | gprs_test("gprs_full_attach_pdp_activation", |
| 58 | "A simple test to do a GPRS attach and open a PDP " |
| 59 | "context. Then goes to sleep and waits for you to ping " |
| 60 | "the connection and hopefully re-produce a crash.", |
| 61 | test_pdp_activation_start, |
| 62 | test_pdp_activation_data), |
| 63 | }; |
| 64 | |
Holger Hans Peter Freyther | b6acfda | 2013-10-17 19:41:11 +0200 | [diff] [blame] | 65 | static void init_main_bts() |
Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 66 | { |
Holger Hans Peter Freyther | b6acfda | 2013-10-17 19:41:11 +0200 | [diff] [blame] | 67 | struct gprs_rlcmac_bts *bts = bts_main_data(); |
Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 68 | bts->fc_interval = 100; |
| 69 | bts->initial_cs_dl = bts->initial_cs_ul = 1; |
| 70 | bts->cs1 = 1; |
| 71 | bts->t3142 = 20; |
| 72 | bts->t3169 = 5; |
| 73 | bts->t3191 = 5; |
| 74 | bts->t3193_msec = 100; |
| 75 | bts->t3195 = 5; |
| 76 | bts->n3101 = 10; |
| 77 | bts->n3103 = 4; |
| 78 | bts->n3105 = 8; |
| 79 | bts->alpha = 0; /* a = 0.0 */ |
| 80 | |
| 81 | if (!bts->alloc_algorithm) |
| 82 | bts->alloc_algorithm = alloc_algorithm_b; |
Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 83 | } |
| 84 | |
Holger Hans Peter Freyther | 741481d | 2013-07-28 21:14:51 +0200 | [diff] [blame] | 85 | static void bvci_unblocked(struct gprs_bssgp_pcu *pcu) |
Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 86 | { |
| 87 | printf("BVCI unblocked. We can begin with test cases.\n"); |
Holger Hans Peter Freyther | 9d93838 | 2013-07-31 21:59:29 +0200 | [diff] [blame] | 88 | all_tests[current_test].start(pcu); |
Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 89 | } |
| 90 | |
Holger Hans Peter Freyther | bc1e52c | 2013-08-22 08:44:38 +0200 | [diff] [blame] | 91 | static void bssgp_data(struct gprs_bssgp_pcu *pcu, struct msgb *msg, struct tlv_parsed *tp) |
| 92 | { |
Holger Hans Peter Freyther | 9d93838 | 2013-07-31 21:59:29 +0200 | [diff] [blame] | 93 | all_tests[current_test].data(pcu, msg, tp); |
Holger Hans Peter Freyther | bc1e52c | 2013-08-22 08:44:38 +0200 | [diff] [blame] | 94 | } |
| 95 | |
Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 96 | void create_and_connect_bssgp(struct gprs_rlcmac_bts *bts, |
| 97 | uint32_t sgsn_ip, uint16_t sgsn_port) |
| 98 | { |
| 99 | struct gprs_bssgp_pcu *pcu; |
| 100 | |
| 101 | pcu = gprs_bssgp_create_and_connect(bts, 0, sgsn_ip, sgsn_port, |
| 102 | 20, 20, 20, 0x901, 0x99, 1, 0, 0); |
| 103 | pcu->on_unblock_ack = bvci_unblocked; |
Holger Hans Peter Freyther | bc1e52c | 2013-08-22 08:44:38 +0200 | [diff] [blame] | 104 | pcu->on_dl_unit_data = bssgp_data; |
Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | int main(int argc, char **argv) |
| 108 | { |
Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 109 | tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile Emu-PCU context"); |
| 110 | if (!tall_pcu_ctx) |
| 111 | abort(); |
| 112 | |
| 113 | msgb_set_talloc_ctx(tall_pcu_ctx); |
| 114 | osmo_init_logging(&gprs_log_info); |
| 115 | vty_init(&pcu_vty_info); |
| 116 | pcu_vty_init(&gprs_log_info); |
| 117 | |
Jacob Erlbeck | 0494c75 | 2015-05-04 09:34:00 +0200 | [diff] [blame] | 118 | current_test = 0; |
| 119 | |
Holger Hans Peter Freyther | b6acfda | 2013-10-17 19:41:11 +0200 | [diff] [blame] | 120 | init_main_bts(); |
| 121 | create_and_connect_bssgp(bts_main_data(), INADDR_LOOPBACK, 23000); |
Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 122 | |
| 123 | for (;;) |
| 124 | osmo_select_main(0); |
| 125 | |
| 126 | return EXIT_SUCCESS; |
| 127 | } |
| 128 | |
Holger Hans Peter Freyther | 9d93838 | 2013-07-31 21:59:29 +0200 | [diff] [blame] | 129 | |
| 130 | /* |
| 131 | * Test handling.. |
| 132 | */ |
| 133 | void gprs_test_success(struct gprs_bssgp_pcu *pcu) |
| 134 | { |
| 135 | current_test += 1; |
| 136 | if (current_test >= ARRAY_SIZE(all_tests)) { |
| 137 | printf("All tests executed.\n"); |
| 138 | exit(EXIT_SUCCESS); |
| 139 | } |
| 140 | |
| 141 | all_tests[current_test].start(pcu); |
| 142 | } |
| 143 | |
Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 144 | /* |
| 145 | * stubs that should not be reached |
| 146 | */ |
| 147 | extern "C" { |
| 148 | void l1if_pdch_req() { abort(); } |
| 149 | void l1if_connect_pdch() { abort(); } |
| 150 | void l1if_close_pdch() { abort(); } |
| 151 | void l1if_open_pdch() { abort(); } |
| 152 | } |