blob: b68b856c9ae28a8cd7bfbaba9af02854dae9a186 [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>
32
33#include <stdlib.h>
34#include <sys/types.h>
35#include <sys/socket.h>
36
Holger Hans Peter Freyther9d938382013-07-31 21:59:29 +020037static int current_test;
38
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +020039/* Extern data to please the underlying code */
40void *tall_pcu_ctx;
41struct gprs_rlcmac_bts *gprs_rlcmac_bts;
42int16_t spoof_mnc = 0, spoof_mcc = 0;
43
Holger Hans Peter Freyther741481d2013-07-28 21:14:51 +020044extern void test_replay_gprs_attach(struct gprs_bssgp_pcu *pcu);
Holger Hans Peter Freytherbc1e52c2013-08-22 08:44:38 +020045extern void test_replay_gprs_data(struct gprs_bssgp_pcu *, struct msgb *, struct tlv_parsed *);
Holger Hans Peter Freyther741481d2013-07-28 21:14:51 +020046
Holger Hans Peter Freyther9d938382013-07-31 21:59:29 +020047extern void test_pdp_activation_start(struct gprs_bssgp_pcu *pcu);
48extern void test_pdp_activation_data(struct gprs_bssgp_pcu *, struct msgb *, struct tlv_parsed*);
49
50struct 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 Freyther4ea94072013-07-28 18:34:49 +020065struct gprs_rlcmac_bts *create_bts()
66{
67 struct gprs_rlcmac_bts *bts;
68
69 bts = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_bts);
70 if (!bts)
71 return NULL;
72 bts->fc_interval = 100;
73 bts->initial_cs_dl = bts->initial_cs_ul = 1;
74 bts->cs1 = 1;
75 bts->t3142 = 20;
76 bts->t3169 = 5;
77 bts->t3191 = 5;
78 bts->t3193_msec = 100;
79 bts->t3195 = 5;
80 bts->n3101 = 10;
81 bts->n3103 = 4;
82 bts->n3105 = 8;
83 bts->alpha = 0; /* a = 0.0 */
84
85 if (!bts->alloc_algorithm)
86 bts->alloc_algorithm = alloc_algorithm_b;
87
88 return bts;
89}
90
Holger Hans Peter Freyther741481d2013-07-28 21:14:51 +020091static void bvci_unblocked(struct gprs_bssgp_pcu *pcu)
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +020092{
93 printf("BVCI unblocked. We can begin with test cases.\n");
Holger Hans Peter Freyther9d938382013-07-31 21:59:29 +020094 all_tests[current_test].start(pcu);
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +020095}
96
Holger Hans Peter Freytherbc1e52c2013-08-22 08:44:38 +020097static void bssgp_data(struct gprs_bssgp_pcu *pcu, struct msgb *msg, struct tlv_parsed *tp)
98{
Holger Hans Peter Freyther9d938382013-07-31 21:59:29 +020099 all_tests[current_test].data(pcu, msg, tp);
Holger Hans Peter Freytherbc1e52c2013-08-22 08:44:38 +0200100}
101
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +0200102void create_and_connect_bssgp(struct gprs_rlcmac_bts *bts,
103 uint32_t sgsn_ip, uint16_t sgsn_port)
104{
105 struct gprs_bssgp_pcu *pcu;
106
107 pcu = gprs_bssgp_create_and_connect(bts, 0, sgsn_ip, sgsn_port,
108 20, 20, 20, 0x901, 0x99, 1, 0, 0);
109 pcu->on_unblock_ack = bvci_unblocked;
Holger Hans Peter Freytherbc1e52c2013-08-22 08:44:38 +0200110 pcu->on_dl_unit_data = bssgp_data;
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +0200111}
112
113int main(int argc, char **argv)
114{
115 struct gprs_rlcmac_bts *bts;
116
117 tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile Emu-PCU context");
118 if (!tall_pcu_ctx)
119 abort();
120
121 msgb_set_talloc_ctx(tall_pcu_ctx);
122 osmo_init_logging(&gprs_log_info);
123 vty_init(&pcu_vty_info);
124 pcu_vty_init(&gprs_log_info);
125
126 gprs_rlcmac_bts = create_bts();
127 if (!gprs_rlcmac_bts)
128 abort();
129
130 create_and_connect_bssgp(gprs_rlcmac_bts, INADDR_LOOPBACK, 23000);
131
132 for (;;)
133 osmo_select_main(0);
134
135 return EXIT_SUCCESS;
136}
137
Holger Hans Peter Freyther9d938382013-07-31 21:59:29 +0200138
139/*
140 * Test handling..
141 */
142void gprs_test_success(struct gprs_bssgp_pcu *pcu)
143{
144 current_test += 1;
145 if (current_test >= ARRAY_SIZE(all_tests)) {
146 printf("All tests executed.\n");
147 exit(EXIT_SUCCESS);
148 }
149
150 all_tests[current_test].start(pcu);
151}
152
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +0200153/*
154 * stubs that should not be reached
155 */
156extern "C" {
157void l1if_pdch_req() { abort(); }
158void l1if_connect_pdch() { abort(); }
159void l1if_close_pdch() { abort(); }
160void l1if_open_pdch() { abort(); }
161}