blob: 7ecabe12182dfd0dbd7fb9b3a0e63baea663b7ad [file] [log] [blame]
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +02001/* 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
22extern "C" {
23#include <osmocom/core/talloc.h>
24#include <pcu_vty.h>
25}
26
Holger Hans Peter Freyther9d938382013-07-31 21:59:29 +020027#include "gprs_tests.h"
28
29
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +020030#include <gprs_bssgp_pcu.h>
31#include <gprs_rlcmac.h>
Holger Hans Peter Freyther67ed34e2013-10-17 17:01:54 +020032#include <bts.h>
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +020033
34#include <stdlib.h>
35#include <sys/types.h>
36#include <sys/socket.h>
37
Jacob Erlbeck0494c752015-05-04 09:34:00 +020038static size_t current_test;
Holger Hans Peter Freyther9d938382013-07-31 21:59:29 +020039
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +020040/* Extern data to please the underlying code */
41void *tall_pcu_ctx;
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +020042int16_t spoof_mnc = 0, spoof_mcc = 0;
Neels Hofmeyrbdc55fa2018-02-21 00:39:07 +010043bool spoof_mnc_3_digits = false;
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +020044
Holger Hans Peter Freyther741481d2013-07-28 21:14:51 +020045extern void test_replay_gprs_attach(struct gprs_bssgp_pcu *pcu);
Holger Hans Peter Freytherbc1e52c2013-08-22 08:44:38 +020046extern void test_replay_gprs_data(struct gprs_bssgp_pcu *, struct msgb *, struct tlv_parsed *);
Holger Hans Peter Freyther741481d2013-07-28 21:14:51 +020047
Holger Hans Peter Freyther9d938382013-07-31 21:59:29 +020048extern void test_pdp_activation_start(struct gprs_bssgp_pcu *pcu);
49extern void test_pdp_activation_data(struct gprs_bssgp_pcu *, struct msgb *, struct tlv_parsed*);
50
51struct gprs_test all_tests[] = {
52 gprs_test("gprs_attach_with_tmsi",
53 "A simple test that verifies that N(U) is "
54 "increasing across various messages. This makes "
55 "sure that no new LLE/LLME is created on the fly.",
56 test_replay_gprs_attach,
57 test_replay_gprs_data),
58 gprs_test("gprs_full_attach_pdp_activation",
59 "A simple test to do a GPRS attach and open a PDP "
60 "context. Then goes to sleep and waits for you to ping "
61 "the connection and hopefully re-produce a crash.",
62 test_pdp_activation_start,
63 test_pdp_activation_data),
64};
65
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +020066static void init_main_bts()
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +020067{
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +020068 struct gprs_rlcmac_bts *bts = bts_main_data();
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +020069 bts->fc_interval = 100;
70 bts->initial_cs_dl = bts->initial_cs_ul = 1;
71 bts->cs1 = 1;
72 bts->t3142 = 20;
73 bts->t3169 = 5;
74 bts->t3191 = 5;
75 bts->t3193_msec = 100;
76 bts->t3195 = 5;
77 bts->n3101 = 10;
78 bts->n3103 = 4;
79 bts->n3105 = 8;
80 bts->alpha = 0; /* a = 0.0 */
81
82 if (!bts->alloc_algorithm)
83 bts->alloc_algorithm = alloc_algorithm_b;
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +020084}
85
Holger Hans Peter Freyther741481d2013-07-28 21:14:51 +020086static void bvci_unblocked(struct gprs_bssgp_pcu *pcu)
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +020087{
88 printf("BVCI unblocked. We can begin with test cases.\n");
Holger Hans Peter Freyther9d938382013-07-31 21:59:29 +020089 all_tests[current_test].start(pcu);
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +020090}
91
Holger Hans Peter Freytherbc1e52c2013-08-22 08:44:38 +020092static void bssgp_data(struct gprs_bssgp_pcu *pcu, struct msgb *msg, struct tlv_parsed *tp)
93{
Holger Hans Peter Freyther9d938382013-07-31 21:59:29 +020094 all_tests[current_test].data(pcu, msg, tp);
Holger Hans Peter Freytherbc1e52c2013-08-22 08:44:38 +020095}
96
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +020097void create_and_connect_bssgp(struct gprs_rlcmac_bts *bts,
98 uint32_t sgsn_ip, uint16_t sgsn_port)
99{
100 struct gprs_bssgp_pcu *pcu;
101
102 pcu = gprs_bssgp_create_and_connect(bts, 0, sgsn_ip, sgsn_port,
Neels Hofmeyrbdc55fa2018-02-21 00:39:07 +0100103 20, 20, 20, 901, 99, false, 1, 0, 0);
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +0200104 pcu->on_unblock_ack = bvci_unblocked;
Holger Hans Peter Freytherbc1e52c2013-08-22 08:44:38 +0200105 pcu->on_dl_unit_data = bssgp_data;
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +0200106}
107
108int main(int argc, char **argv)
109{
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +0200110 tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile Emu-PCU context");
111 if (!tall_pcu_ctx)
112 abort();
113
Neels Hofmeyr78ce5912017-02-08 17:07:31 +0100114 msgb_talloc_ctx_init(tall_pcu_ctx, 0);
Neels Hofmeyr42f2d612018-04-01 16:54:40 +0200115 osmo_init_logging2(tall_pcu_ctx, &gprs_log_info);
Alexander Couzens5c3783b2019-05-25 05:41:18 +0200116
117 bssgp_nsi = gprs_ns_instantiate(&gprs_bssgp_ns_cb, tall_pcu_ctx);
118 if (!bssgp_nsi) {
119 LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n");
120 abort();
121 }
122
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +0200123 vty_init(&pcu_vty_info);
Pau Espin Pedrolcd2ac562019-08-05 14:30:44 +0200124 pcu_vty_init();
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +0200125
Jacob Erlbeck0494c752015-05-04 09:34:00 +0200126 current_test = 0;
127
Holger Hans Peter Freytherb6acfda2013-10-17 19:41:11 +0200128 init_main_bts();
129 create_and_connect_bssgp(bts_main_data(), INADDR_LOOPBACK, 23000);
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +0200130
131 for (;;)
132 osmo_select_main(0);
133
134 return EXIT_SUCCESS;
135}
136
Holger Hans Peter Freyther9d938382013-07-31 21:59:29 +0200137
138/*
139 * Test handling..
140 */
141void gprs_test_success(struct gprs_bssgp_pcu *pcu)
142{
143 current_test += 1;
144 if (current_test >= ARRAY_SIZE(all_tests)) {
145 printf("All tests executed.\n");
146 exit(EXIT_SUCCESS);
147 }
148
149 all_tests[current_test].start(pcu);
150}
151
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +0200152/*
153 * stubs that should not be reached
154 */
155extern "C" {
156void l1if_pdch_req() { abort(); }
157void l1if_connect_pdch() { abort(); }
158void l1if_close_pdch() { abort(); }
159void l1if_open_pdch() { abort(); }
160}