blob: c4cf548dba22f6d2de0096f72c7a82c5bdeb25d1 [file] [log] [blame]
Oliver Smithcfb63212019-09-05 17:13:33 +02001/* Copyright (C) 2019 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version 2
6 * of the License, or (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 */
17
18#include <cstdlib>
19#include <cstring>
20#include <assert.h>
21#include "gprs_rlcmac.h"
22#include "bts.h"
23
24extern "C" {
25#include <osmocom/vty/telnet_interface.h>
26#include <osmocom/vty/logging.h>
27#include <osmocom/core/utils.h>
28#include <osmocom/core/msgb.h>
29#include <osmocom/core/application.h>
30}
31
32using namespace std;
33gprs_rlcmac_dl_tbf *tbf1, *tbf2;
34GprsMs *ms1, *ms2;
35struct msgb *sched_app_info(struct gprs_rlcmac_tbf *tbf);
36
37/* globals used by the code */
38void *tall_pcu_ctx;
39int16_t spoof_mnc = 0, spoof_mcc = 0;
40bool spoof_mnc_3_digits = false;
41
42void test_enc_zero_len() {
43 struct gsm_pcu_if_app_info_req req = {0, 0, {0}};
44
45 fprintf(stderr, "--- %s ---\n", __func__);
46 assert(gprs_rlcmac_app_info_msg(&req) == NULL);
47 fprintf(stderr, "\n");
48}
49
50void test_enc() {
51 struct gsm_pcu_if_app_info_req req = {0, 15, {0xff, 0x00, 0xff}};
52 const char *exp = "03 fc 03 fc 00 00 00 00 00 00 00 00 00 00 00 00 "; /* shifted by two bits to the right */
53 struct msgb *msg;
54 char *msg_dump;
55
56 fprintf(stderr, "--- %s ---\n", __func__);
57 msg = gprs_rlcmac_app_info_msg(&req);
58 msg_dump = msgb_hexdump_c(tall_pcu_ctx, msg);
59
60 fprintf(stderr, "exp: %s\n", exp);
61 fprintf(stderr, "msg: %s\n", msg_dump);
62 assert(strcmp(msg_dump, exp) == 0);
63
64 msgb_free(msg);
65 talloc_free(msg_dump);
66 fprintf(stderr, "\n");
67}
68
69void test_pcu_rx_no_subscr_with_active_tbf()
70{
71 struct gsm_pcu_if pcu_prim = {PCU_IF_MSG_APP_INFO_REQ, };
72
73 fprintf(stderr, "--- %s ---\n", __func__);
74 pcu_rx(PCU_IF_MSG_APP_INFO_REQ, &pcu_prim);
75 fprintf(stderr, "\n");
76}
77
78void prepare_bts_with_two_dl_tbf_subscr()
79{
80 BTS *bts = BTS::main_bts();
81 struct gprs_rlcmac_bts *bts_data;
82 struct gprs_rlcmac_trx *trx;
83
84 fprintf(stderr, "--- %s ---\n", __func__);
85
86 bts_data = bts->bts_data();
87 bts_data->alloc_algorithm = alloc_algorithm_b;
88
89 trx = bts_data->trx;
90 trx->pdch[4].enable();
91 trx->pdch[5].enable();
92 trx->pdch[6].enable();
93 trx->pdch[7].enable();
94
95 ms1 = bts->ms_alloc(10, 11);
96 tbf1 = tbf_alloc_dl_tbf(bts_data, ms1, 0, 10, 11, false);
97 ms2 = bts->ms_alloc(12, 13);
98 tbf2 = tbf_alloc_dl_tbf(bts_data, ms2, 0, 12, 13, false);
99
100 fprintf(stderr, "\n");
101}
102
103void test_sched_app_info_ok()
104{
105 struct gsm_pcu_if pcu_prim = {PCU_IF_MSG_APP_INFO_REQ, };
106 struct msgb *msg;
107
108 fprintf(stderr, "--- %s ---\n", __func__);
109 pcu_prim.u.app_info_req = {0, 15, {0xff, 0x00, 0xff}};
110 pcu_rx(PCU_IF_MSG_APP_INFO_REQ, &pcu_prim);
111
112 msg = sched_app_info(tbf1);
113 assert(msg);
114 msgb_free(msg);
115
116 msg = sched_app_info(tbf2);
117 assert(msg);
118 msgb_free(msg);
119
120 fprintf(stderr, "\n");
121}
122
123void test_sched_app_info_missing_app_info_in_bts()
124{
125 struct gprs_rlcmac_bts *bts_data = BTS::main_bts()->bts_data();
126 struct gsm_pcu_if pcu_prim = {PCU_IF_MSG_APP_INFO_REQ, };
127
128 fprintf(stderr, "--- %s ---\n", __func__);
129 pcu_prim.u.app_info_req = {0, 15, {0xff, 0x00, 0xff}};
130 pcu_rx(PCU_IF_MSG_APP_INFO_REQ, &pcu_prim);
131
132 msgb_free(bts_data->app_info);
133 bts_data->app_info = NULL;
134
135 assert(sched_app_info(tbf1) == NULL);
136
137 fprintf(stderr, "\n");
138}
139
140void test_pcu_rx_overwrite_app_info()
141{
142 struct gsm_pcu_if pcu_prim = {PCU_IF_MSG_APP_INFO_REQ, };
143
144 fprintf(stderr, "--- %s ---\n", __func__);
145 pcu_prim.u.app_info_req = {0, 15, {0xff, 0x00, 0xff}};
146 pcu_rx(PCU_IF_MSG_APP_INFO_REQ, &pcu_prim);
147 pcu_rx(PCU_IF_MSG_APP_INFO_REQ, &pcu_prim);
148 fprintf(stderr, "\n");
149}
150
151void cleanup()
152{
153 fprintf(stderr, "--- %s ---\n", __func__);
154
155 BTS::main_bts()->cleanup();
156 talloc_free(tbf1);
157 talloc_free(tbf2);
158 /* FIXME: talloc report disabled, because bts->ms_alloc() in prepare_bts_with_two_dl_tbf_subscr() causes leak */
159 /* talloc_report_full(tall_pcu_ctx, stderr); */
160 talloc_free(tall_pcu_ctx);
161}
162
163int main(int argc, char *argv[])
164{
165 tall_pcu_ctx = talloc_named_const(NULL, 1, "AppInfoTest");
166 osmo_init_logging2(tall_pcu_ctx, &gprs_log_info);
167 log_set_use_color(osmo_stderr_target, 0);
168 log_set_print_filename(osmo_stderr_target, 0);
169 log_parse_category_mask(osmo_stderr_target, "DL1IF,1:DRLCMAC,3:DRLCMACSCHED,1");
170
171 test_enc_zero_len();
172 test_enc();
173 test_pcu_rx_no_subscr_with_active_tbf();
174
175 prepare_bts_with_two_dl_tbf_subscr();
176 test_sched_app_info_ok();
177 test_sched_app_info_missing_app_info_in_bts();
178 test_pcu_rx_overwrite_app_info();
179
180 cleanup();
181}
182
183/*
184 * stubs that should not be reached
185 */
186extern "C" {
187void l1if_pdch_req() { abort(); }
188void l1if_connect_pdch() { abort(); }
189void l1if_close_pdch() { abort(); }
190void l1if_open_pdch() { abort(); }
191}