blob: 45dbfc46c8bbcc2675b27c51ae2ea1a1a2c80707 [file] [log] [blame]
Holger Hans Peter Freytherb8098662013-10-30 14:50:17 +01001/*
2 * TbfTest.cpp
3 *
4 * Copyright (C) 2013 by Holger Hans Peter Freyther
5 *
6 * All Rights Reserved
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 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 "bts.h"
24#include "tbf.h"
25#include "gprs_debug.h"
26
27extern "C" {
28#include <osmocom/core/application.h>
29#include <osmocom/core/msgb.h>
30#include <osmocom/core/talloc.h>
31#include <osmocom/core/utils.h>
32}
33
34void *tall_pcu_ctx;
35int16_t spoof_mnc = 0, spoof_mcc = 0;
36
Jacob Erlbeck08fe76a2015-02-23 15:10:20 +010037static void check_tbf(gprs_rlcmac_tbf *tbf)
38{
39 OSMO_ASSERT(tbf);
40 OSMO_ASSERT(tbf->m_new_tbf == NULL || tbf->m_new_tbf->m_old_tbf == tbf);
41 OSMO_ASSERT(tbf->m_old_tbf == NULL || tbf->m_old_tbf->m_new_tbf == tbf);
42}
43
Holger Hans Peter Freytherb8098662013-10-30 14:50:17 +010044static void test_tbf_tlli_update()
45{
46 BTS the_bts;
47 the_bts.bts_data()->alloc_algorithm = alloc_algorithm_a;
48 the_bts.bts_data()->trx[0].pdch[2].enable();
49 the_bts.bts_data()->trx[0].pdch[3].enable();
50
51 /*
52 * Make a uplink and downlink allocation
53 */
Daniel Willmann48aa0b02014-07-16 18:54:10 +020054 gprs_rlcmac_tbf *dl_tbf = tbf_alloc_dl_tbf(the_bts.bts_data(),
55 NULL, 0,
Holger Hans Peter Freytherb8098662013-10-30 14:50:17 +010056 0, 0, 0);
57 dl_tbf->update_tlli(0x2342);
58 dl_tbf->tlli_mark_valid();
59 dl_tbf->ta = 4;
60 the_bts.timing_advance()->remember(0x2342, dl_tbf->ta);
61
Daniel Willmann48aa0b02014-07-16 18:54:10 +020062 gprs_rlcmac_tbf *ul_tbf = tbf_alloc_ul_tbf(the_bts.bts_data(),
63 ul_tbf, 0,
Holger Hans Peter Freytherb8098662013-10-30 14:50:17 +010064 0, 0, 0);
65 ul_tbf->update_tlli(0x2342);
66 ul_tbf->tlli_mark_valid();
67
68
Daniel Willmannb59d61b2014-07-02 17:58:14 +020069 OSMO_ASSERT(the_bts.dl_tbf_by_tlli(0x2342) == dl_tbf);
70 OSMO_ASSERT(the_bts.ul_tbf_by_tlli(0x2342) == ul_tbf);
Holger Hans Peter Freytherb8098662013-10-30 14:50:17 +010071
72
73 /*
74 * Now check.. that DL changes and that the timing advance
75 * has changed.
76 */
77 dl_tbf->update_tlli(0x4232);
Daniel Willmannb59d61b2014-07-02 17:58:14 +020078 OSMO_ASSERT(!the_bts.dl_tbf_by_tlli(0x2342));
79 OSMO_ASSERT(!the_bts.ul_tbf_by_tlli(0x2342));
Holger Hans Peter Freytherb8098662013-10-30 14:50:17 +010080
81
Daniel Willmannb59d61b2014-07-02 17:58:14 +020082 OSMO_ASSERT(the_bts.dl_tbf_by_tlli(0x4232) == dl_tbf);
83 OSMO_ASSERT(the_bts.ul_tbf_by_tlli(0x4232) == ul_tbf);
Holger Hans Peter Freytherbc1626e2013-10-30 19:50:49 +010084
85 OSMO_ASSERT(the_bts.timing_advance()->recall(0x4232) == 4);
Holger Hans Peter Freytherb8098662013-10-30 14:50:17 +010086}
87
Daniel Willmann510d7d32014-08-15 18:19:41 +020088static uint8_t llc_data[200];
89
90int pcu_sock_send(struct msgb *msg)
91{
92 return 0;
93}
94
Jacob Erlbeck5e9f40d2015-02-23 14:26:59 +010095enum test_tbf_final_ack_mode {
96 TEST_MODE_STANDARD,
97 TEST_MODE_REVERSE_FREE
98};
99
100static void test_tbf_final_ack(enum test_tbf_final_ack_mode test_mode)
Daniel Willmann510d7d32014-08-15 18:19:41 +0200101{
102 BTS the_bts;
103 gprs_rlcmac_bts *bts;
104 gprs_rlcmac_trx *trx;
105 gprs_rlcmac_pdch * pdch;
106 int tfi, i;
107 uint8_t ts_no, trx_no;
108 uint8_t ms_class = 45;
109 uint32_t fn;
110
111 uint8_t rbb[64/8];
112
113 struct msgb *dl_msg;
114 gprs_rlcmac_dl_tbf *dl_tbf;
115 gprs_rlcmac_tbf *new_tbf;
116
117 bts = the_bts.bts_data();
118 bts->alloc_algorithm = alloc_algorithm_a;
119 trx = &bts->trx[0];
120
121 ts_no = 4;
122 trx->pdch[ts_no].enable();
123 pdch = &trx->pdch[ts_no];
124
125 tfi = the_bts.tfi_find_free(GPRS_RLCMAC_DL_TBF, &trx_no, -1);
126 OSMO_ASSERT(tfi >= 0);
127 dl_tbf = tbf_alloc_dl_tbf(bts, NULL, tfi, trx_no, ms_class, 1);
Jacob Erlbeck08fe76a2015-02-23 15:10:20 +0100128 check_tbf(dl_tbf);
129
Daniel Willmann510d7d32014-08-15 18:19:41 +0200130
131 /* "Establish" the DL TBF */
132 dl_tbf->dl_ass_state = GPRS_RLCMAC_DL_ASS_SEND_ASS;
133 dl_tbf->set_state(GPRS_RLCMAC_FLOW);
134 dl_tbf->m_wait_confirm = 0;
135 dl_tbf->set_new_tbf(dl_tbf);
Jacob Erlbeck08fe76a2015-02-23 15:10:20 +0100136 check_tbf(dl_tbf);
Daniel Willmann510d7d32014-08-15 18:19:41 +0200137
138 for (i = 0; i < sizeof(llc_data); i++)
139 llc_data[i] = i%256;
140
141 /* Schedule two blocks */
Daniel Willmann0f58af62014-09-19 11:57:21 +0200142 dl_tbf->append_data(ms_class, 1000, llc_data, sizeof(llc_data));
143 dl_tbf->append_data(ms_class, 1000, llc_data, sizeof(llc_data));
Daniel Willmann510d7d32014-08-15 18:19:41 +0200144
145
146 /* FIXME: Need correct frame number here? */
147 fn = 0;
148 for (; fn < 3; fn++) {
149 /* Request to send one block */
150 gprs_rlcmac_rcv_rts_block(bts, trx_no, ts_no, 0, fn, 0);
151 }
152
153 /* Queue a final ACK */
154 memset(rbb, 0, sizeof(rbb));
155 /* Receive a final ACK */
156 dl_tbf->rcvd_dl_ack(1, 1, rbb);
157
158 /* Clean up and ensure tbfs are in the correct state */
159 OSMO_ASSERT(dl_tbf->state_is(GPRS_RLCMAC_WAIT_RELEASE));
160 new_tbf = dl_tbf->new_tbf();
Jacob Erlbeck08fe76a2015-02-23 15:10:20 +0100161 check_tbf(new_tbf);
Daniel Willmann510d7d32014-08-15 18:19:41 +0200162 OSMO_ASSERT(new_tbf != dl_tbf);
163 OSMO_ASSERT(new_tbf->tfi() == 1);
Jacob Erlbeck08fe76a2015-02-23 15:10:20 +0100164 check_tbf(dl_tbf);
Daniel Willmann510d7d32014-08-15 18:19:41 +0200165 dl_tbf->dl_ass_state = GPRS_RLCMAC_DL_ASS_NONE;
Jacob Erlbeck5e9f40d2015-02-23 14:26:59 +0100166 if (test_mode == TEST_MODE_REVERSE_FREE) {
167 tbf_free(new_tbf);
Jacob Erlbeck08fe76a2015-02-23 15:10:20 +0100168 OSMO_ASSERT(dl_tbf->m_new_tbf != new_tbf);
169 check_tbf(dl_tbf);
Jacob Erlbeck5e9f40d2015-02-23 14:26:59 +0100170 tbf_free(dl_tbf);
171 } else {
172 tbf_free(dl_tbf);
173 OSMO_ASSERT(new_tbf->m_new_tbf != dl_tbf);
Jacob Erlbeck08fe76a2015-02-23 15:10:20 +0100174 check_tbf(new_tbf);
Jacob Erlbeck5e9f40d2015-02-23 14:26:59 +0100175 tbf_free(new_tbf);
176 }
Daniel Willmann510d7d32014-08-15 18:19:41 +0200177}
178
Daniel Willmann341689d2014-06-11 18:33:14 +0200179static const struct log_info_cat default_categories[] = {
180 {"DCSN1", "\033[1;31m", "Concrete Syntax Notation One (CSN1)", LOGL_INFO, 0},
181 {"DL1IF", "\033[1;32m", "GPRS PCU L1 interface (L1IF)", LOGL_DEBUG, 1},
182 {"DRLCMAC", "\033[0;33m", "GPRS RLC/MAC layer (RLCMAC)", LOGL_DEBUG, 1},
183 {"DRLCMACDATA", "\033[0;33m", "GPRS RLC/MAC layer Data (RLCMAC)", LOGL_DEBUG, 1},
184 {"DRLCMACDL", "\033[1;33m", "GPRS RLC/MAC layer Downlink (RLCMAC)", LOGL_DEBUG, 1},
185 {"DRLCMACUL", "\033[1;36m", "GPRS RLC/MAC layer Uplink (RLCMAC)", LOGL_DEBUG, 1},
186 {"DRLCMACSCHED", "\033[0;36m", "GPRS RLC/MAC layer Scheduling (RLCMAC)", LOGL_DEBUG, 1},
187 {"DRLCMACMEAS", "\033[1;31m", "GPRS RLC/MAC layer Measurements (RLCMAC)", LOGL_INFO, 1},
188 {"DBSSGP","\033[1;34m", "GPRS BSS Gateway Protocol (BSSGP)", LOGL_INFO , 1},
189 {"DPCU", "\033[1;35m", "GPRS Packet Control Unit (PCU)", LOGL_NOTICE, 1},
190};
191
192static int filter_fn(const struct log_context *ctx,
193 struct log_target *tar)
194{
195 return 1;
196}
197
198const struct log_info debug_log_info = {
199 filter_fn,
200 (struct log_info_cat*)default_categories,
201 ARRAY_SIZE(default_categories),
202};
203
Holger Hans Peter Freytherb8098662013-10-30 14:50:17 +0100204int main(int argc, char **argv)
205{
206 tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile TbfTest context");
207 if (!tall_pcu_ctx)
208 abort();
209
210 msgb_set_talloc_ctx(tall_pcu_ctx);
Daniel Willmann341689d2014-06-11 18:33:14 +0200211 osmo_init_logging(&debug_log_info);
Holger Hans Peter Freytherb8098662013-10-30 14:50:17 +0100212 log_set_use_color(osmo_stderr_target, 0);
213 log_set_print_filename(osmo_stderr_target, 0);
214
215 test_tbf_tlli_update();
Jacob Erlbeck5e9f40d2015-02-23 14:26:59 +0100216 test_tbf_final_ack(TEST_MODE_STANDARD);
217 test_tbf_final_ack(TEST_MODE_REVERSE_FREE);
Holger Hans Peter Freytherb8098662013-10-30 14:50:17 +0100218 return EXIT_SUCCESS;
219}
220
221/*
222 * stubs that should not be reached
223 */
224extern "C" {
225void l1if_pdch_req() { abort(); }
226void l1if_connect_pdch() { abort(); }
227void l1if_close_pdch() { abort(); }
228void l1if_open_pdch() { abort(); }
229}