blob: 249c2687cd7b51d6efeac43b0c90269c4801a491 [file] [log] [blame]
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +02001/* AllocTest.cpp
2 *
3 * Copyright (C) 2013 by Holger Hans Peter Freyther
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#include "gprs_rlcmac.h"
21#include "gprs_debug.h"
22#include "tbf.h"
Pau Espin Pedrol9d1cdb12019-09-25 17:47:02 +020023#include "tbf_ul.h"
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +020024#include "bts.h"
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020025
26#include <string.h>
27#include <stdio.h>
28
29extern "C" {
Max9f460712018-01-23 20:57:08 +010030#include "mslot_class.h"
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020031#include <osmocom/core/application.h>
32#include <osmocom/core/msgb.h>
33#include <osmocom/core/talloc.h>
34#include <osmocom/core/utils.h>
35}
36
37/* globals used by the code */
38void *tall_pcu_ctx;
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020039int16_t spoof_mnc = 0, spoof_mcc = 0;
Neels Hofmeyrbdc55fa2018-02-21 00:39:07 +010040bool spoof_mnc_3_digits = false;
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020041
Daniel Willmann48aa0b02014-07-16 18:54:10 +020042static gprs_rlcmac_tbf *tbf_alloc(struct gprs_rlcmac_bts *bts,
Jacob Erlbecke2e004e2015-06-18 17:16:26 +020043 GprsMs *ms, gprs_rlcmac_tbf_direction dir,
Pau Espin Pedrol322456e2020-05-08 18:15:59 +020044 uint8_t use_trx, bool single_slot)
Daniel Willmann48aa0b02014-07-16 18:54:10 +020045{
Pau Espin Pedrol322456e2020-05-08 18:15:59 +020046 OSMO_ASSERT(ms != NULL);
Pau Espin Pedrol17402a52020-05-08 17:44:33 +020047
Daniel Willmann48aa0b02014-07-16 18:54:10 +020048 if (dir == GPRS_RLCMAC_UL_TBF)
Pau Espin Pedrol17402a52020-05-08 17:44:33 +020049 return tbf_alloc_ul_tbf(bts, ms, use_trx, single_slot);
Daniel Willmann48aa0b02014-07-16 18:54:10 +020050 else
Pau Espin Pedrol322456e2020-05-08 18:15:59 +020051 return tbf_alloc_dl_tbf(bts, ms, use_trx, single_slot);
Daniel Willmann48aa0b02014-07-16 18:54:10 +020052}
53
Jacob Erlbeck61205a72015-07-09 11:35:50 +020054static void check_tfi_usage(BTS *the_bts)
55{
56 int pdch_no;
Jacob Erlbeck61205a72015-07-09 11:35:50 +020057
58 struct gprs_rlcmac_tbf *tfi_usage[8][8][2][32] = {{{{NULL}}}};
Jacob Erlbecked2dbf62015-12-28 19:15:40 +010059 LListHead<gprs_rlcmac_tbf> *tbf_lists[2] = {
60 &the_bts->ul_tbfs(),
61 &the_bts->dl_tbfs()
Jacob Erlbeck61205a72015-07-09 11:35:50 +020062 };
63
Jacob Erlbecked2dbf62015-12-28 19:15:40 +010064 LListHead<gprs_rlcmac_tbf> *pos;
Jacob Erlbeck61205a72015-07-09 11:35:50 +020065 gprs_rlcmac_tbf *tbf;
Jacob Erlbeck61205a72015-07-09 11:35:50 +020066 unsigned list_idx;
67 struct gprs_rlcmac_tbf **tbf_var;
68
69 for (list_idx = 0; list_idx < ARRAY_SIZE(tbf_lists); list_idx += 1)
70 {
71
Jacob Erlbecked2dbf62015-12-28 19:15:40 +010072 llist_for_each(pos, tbf_lists[list_idx]) {
73 tbf = pos->entry();
Jacob Erlbeck61205a72015-07-09 11:35:50 +020074 for (pdch_no = 0; pdch_no < 8; pdch_no += 1) {
75 struct gprs_rlcmac_pdch *pdch = tbf->pdch[pdch_no];
76 if (pdch == NULL)
77 continue;
78
79 tbf_var = &tfi_usage
80 [tbf->trx->trx_no]
81 [pdch_no]
82 [tbf->direction]
83 [tbf->tfi()];
84
85 OSMO_ASSERT(*tbf_var == NULL);
86 if (tbf->direction == GPRS_RLCMAC_DL_TBF) {
87 OSMO_ASSERT(pdch->dl_tbf_by_tfi(
88 tbf->tfi()) == tbf);
Jacob Erlbeck61205a72015-07-09 11:35:50 +020089 OSMO_ASSERT(the_bts->dl_tbf_by_tfi(
90 tbf->tfi(),
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +020091 tbf->trx->trx_no,
92 pdch_no) == tbf);
Jacob Erlbeck61205a72015-07-09 11:35:50 +020093 } else {
94 OSMO_ASSERT(pdch->ul_tbf_by_tfi(
95 tbf->tfi()) == tbf);
Jacob Erlbeck61205a72015-07-09 11:35:50 +020096 OSMO_ASSERT(the_bts->ul_tbf_by_tfi(
97 tbf->tfi(),
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +020098 tbf->trx->trx_no,
99 pdch_no) == tbf);
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200100 }
101 *tbf_var = tbf;
Jacob Erlbeck47a57f62015-07-08 12:53:16 +0200102 OSMO_ASSERT(pdch->assigned_tfi(tbf->direction) &
103 (1 << tbf->tfi()));
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200104 }
105 }
106 }
107}
108
Jacob Erlbeckfa464bb2015-06-29 12:45:11 +0200109static void test_alloc_a(gprs_rlcmac_tbf_direction dir,
110 uint8_t slots, const int count)
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200111{
112 int tfi;
Jacob Erlbeckfa464bb2015-06-29 12:45:11 +0200113 int i;
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200114 uint8_t used_trx, tmp_trx;
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100115 BTS the_bts(the_pcu);
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200116 GprsMs *ms;
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200117 struct gprs_rlcmac_bts *bts;
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200118 struct gprs_rlcmac_tbf *tbfs[32*8+1] = { 0, };
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200119
120 printf("Testing alloc_a direction(%d)\n", dir);
121
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200122 bts = the_bts.bts_data();
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100123 the_pcu->alloc_algorithm = alloc_algorithm_a;
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200124
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200125 struct gprs_rlcmac_trx *trx = &bts->trx[0];
Jacob Erlbeckfa464bb2015-06-29 12:45:11 +0200126 for (i = 0; i < 8; i += 1)
127 if (slots & (1 << i))
128 trx->pdch[i].enable();
129
130 OSMO_ASSERT(count >= 0 && count <= (int)ARRAY_SIZE(tbfs));
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200131
132 /**
133 * Currently alloc_a will only allocate from the first
134 * PDCH and all possible usf's. We run out of usf's before
135 * we are out of tfi's. Observe this and make sure that at
136 * least this part is working okay.
137 */
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200138 for (i = 0; i < (int)ARRAY_SIZE(tbfs); ++i) {
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200139 ms = bts->bts->ms_alloc(0, 0);
140 tbfs[i] = tbf_alloc(bts, ms, dir, -1, 0);
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200141 if (tbfs[i] == NULL)
142 break;
143
144 used_trx = tbfs[i]->trx->trx_no;
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200145 tfi = the_bts.tfi_find_free(dir, &tmp_trx, used_trx);
146 OSMO_ASSERT(tbfs[i]->tfi() != tfi);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200147 }
148
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200149 check_tfi_usage(&the_bts);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200150
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200151 OSMO_ASSERT(i == count);
152
153 for (i = 0; i < count; ++i)
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200154 if (tbfs[i])
155 tbf_free(tbfs[i]);
156
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200157 ms = bts->bts->ms_alloc(0, 0);
158 tbfs[0] = tbf_alloc(bts, ms, dir, -1, 0);
Holger Hans Peter Freytherf3f1bde2016-02-22 15:14:01 +0100159 OSMO_ASSERT(tbfs[0]);
160 tbf_free(tbfs[0]);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200161}
162
163static void test_alloc_a()
164{
Jacob Erlbeckfa464bb2015-06-29 12:45:11 +0200165 /* slots 2 - 3 */
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200166 test_alloc_a(GPRS_RLCMAC_DL_TBF, 0x0c, 32*2);
Jacob Erlbeckec478752015-06-19 16:35:38 +0200167 test_alloc_a(GPRS_RLCMAC_UL_TBF, 0x0c, 14);
Jacob Erlbeckfa464bb2015-06-29 12:45:11 +0200168
169 /* slots 1 - 5 */
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200170 test_alloc_a(GPRS_RLCMAC_DL_TBF, 0x1e, 32*4);
Jacob Erlbeckec478752015-06-19 16:35:38 +0200171 test_alloc_a(GPRS_RLCMAC_UL_TBF, 0x1e, 28);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200172}
173
Max2ecf0fd2017-11-21 18:13:31 +0100174static void dump_assignment(struct gprs_rlcmac_tbf *tbf, const char *dir, bool verbose)
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100175{
Max2ecf0fd2017-11-21 18:13:31 +0100176 if (!verbose)
177 return;
178
Jacob Erlbeck1f332942015-05-04 08:21:17 +0200179 for (size_t i = 0; i < ARRAY_SIZE(tbf->pdch); ++i)
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100180 if (tbf->pdch[i])
Neels Hofmeyrd34646a2017-02-08 17:07:40 +0100181 printf("PDCH[%zu] is used for %s\n", i, dir);
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100182 printf("PDCH[%d] is control_ts for %s\n", tbf->control_ts, dir);
183 printf("PDCH[%d] is first common for %s\n", tbf->first_common_ts, dir);
184}
185
Max2ecf0fd2017-11-21 18:13:31 +0100186#define ENABLE_PDCH(ts_no, enable_flag, trx) \
187 if (enable_flag) \
188 trx->pdch[ts_no].enable();
189
190static inline void enable_ts_on_bts(struct gprs_rlcmac_bts *bts,
191 bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7)
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100192{
Max2ecf0fd2017-11-21 18:13:31 +0100193 struct gprs_rlcmac_trx *trx = &bts->trx[0];
194
195 ENABLE_PDCH(0, ts0, trx);
196 ENABLE_PDCH(1, ts1, trx);
197 ENABLE_PDCH(2, ts2, trx);
198 ENABLE_PDCH(3, ts3, trx);
199 ENABLE_PDCH(4, ts4, trx);
200 ENABLE_PDCH(5, ts5, trx);
201 ENABLE_PDCH(6, ts6, trx);
202 ENABLE_PDCH(7, ts7, trx);
203}
204
205static inline bool test_alloc_b_ul_dl(bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7,
206 uint8_t ms_class, bool verbose)
207{
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100208 BTS the_bts(the_pcu);
Max2ecf0fd2017-11-21 18:13:31 +0100209 struct gprs_rlcmac_bts *bts = the_bts.bts_data();
Pau Espin Pedrol17402a52020-05-08 17:44:33 +0200210 GprsMs *ms;
Max2ecf0fd2017-11-21 18:13:31 +0100211 gprs_rlcmac_ul_tbf *ul_tbf;
212 gprs_rlcmac_dl_tbf *dl_tbf;
213
214 if (verbose)
215 printf("Testing UL then DL assignment.\n");
216
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100217 the_pcu->alloc_algorithm = alloc_algorithm_b;
Max2ecf0fd2017-11-21 18:13:31 +0100218
219 enable_ts_on_bts(bts, ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7);
220
Pau Espin Pedrol17402a52020-05-08 17:44:33 +0200221 ms = the_bts.ms_alloc(ms_class, 0);
Pau Espin Pedrol1e009472021-01-11 20:40:19 +0100222 /* Avoid delaying free to avoid tons of to-be-freed ms objects queuing */
223 ms_set_timeout(ms, 0);
Pau Espin Pedrol17402a52020-05-08 17:44:33 +0200224 ul_tbf = tbf_alloc_ul_tbf(bts, ms, -1, true);
Max2ecf0fd2017-11-21 18:13:31 +0100225 if (!ul_tbf)
226 return false;
227
228 OSMO_ASSERT(ul_tbf->ms());
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100229 OSMO_ASSERT(ms_current_trx(ul_tbf->ms()));
Max2ecf0fd2017-11-21 18:13:31 +0100230
231 dump_assignment(ul_tbf, "UL", verbose);
232
233 /* assume final ack has not been sent */
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100234 dl_tbf = tbf_alloc_dl_tbf(bts, ms, ms_current_trx(ms)->trx_no, false);
Max2ecf0fd2017-11-21 18:13:31 +0100235 if (!dl_tbf)
236 return false;
237
238 dump_assignment(dl_tbf, "DL", verbose);
239
240 OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
241
242 check_tfi_usage(&the_bts);
243
244 tbf_free(dl_tbf);
245 tbf_free(ul_tbf);
246
247 return true;
248}
249
250static inline bool test_alloc_b_dl_ul(bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7,
251 uint8_t ms_class, bool verbose)
252{
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100253 BTS the_bts(the_pcu);
Max2ecf0fd2017-11-21 18:13:31 +0100254 struct gprs_rlcmac_bts *bts = the_bts.bts_data();
Pau Espin Pedrol17402a52020-05-08 17:44:33 +0200255 GprsMs *ms;
Max2ecf0fd2017-11-21 18:13:31 +0100256 gprs_rlcmac_ul_tbf *ul_tbf;
257 gprs_rlcmac_dl_tbf *dl_tbf;
258
259 if (verbose)
260 printf("Testing DL then UL assignment followed by update\n");
261
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100262 the_pcu->alloc_algorithm = alloc_algorithm_b;
Max2ecf0fd2017-11-21 18:13:31 +0100263
264 enable_ts_on_bts(bts, ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7);
265
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200266 ms = the_bts.ms_alloc(ms_class, 0);
Pau Espin Pedrol1e009472021-01-11 20:40:19 +0100267 /* Avoid delaying free to avoid tons of to-be-freed ms objects queuing */
268 ms_set_timeout(ms, 0);
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200269 dl_tbf = tbf_alloc_dl_tbf(bts, ms, -1, true);
Max2ecf0fd2017-11-21 18:13:31 +0100270 if (!dl_tbf)
271 return false;
272
273 dl_tbf->update_ms(0x23, GPRS_RLCMAC_DL_TBF);
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200274 OSMO_ASSERT(dl_tbf->ms() == ms);
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100275 OSMO_ASSERT(ms_current_trx(dl_tbf->ms()));
Max2ecf0fd2017-11-21 18:13:31 +0100276
277 dump_assignment(dl_tbf, "DL", verbose);
278
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100279 ul_tbf = tbf_alloc_ul_tbf(bts, ms, ms_current_trx(ms)->trx_no, false);
Max2ecf0fd2017-11-21 18:13:31 +0100280 if (!ul_tbf)
281 return false;
282
283 ul_tbf->update_ms(0x23, GPRS_RLCMAC_UL_TBF);
284 ul_tbf->m_contention_resolution_done = 1;
285
286 dump_assignment(ul_tbf, "UL", verbose);
287
288 OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
289
290 /* now update the dl_tbf */
291 dl_tbf->update();
292 dump_assignment(dl_tbf, "DL", verbose);
293 OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
294
295 check_tfi_usage(&the_bts);
296
297 tbf_free(dl_tbf);
298 tbf_free(ul_tbf);
299
300 return true;
301}
302
303static inline bool test_alloc_b_jolly(uint8_t ms_class)
304{
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100305 BTS the_bts(the_pcu);
Max2ecf0fd2017-11-21 18:13:31 +0100306 struct gprs_rlcmac_bts *bts = the_bts.bts_data();
Pau Espin Pedrol17402a52020-05-08 17:44:33 +0200307 GprsMs *ms;
Max2ecf0fd2017-11-21 18:13:31 +0100308 int tfi;
309 uint8_t trx_no;
310 gprs_rlcmac_tbf *ul_tbf, *dl_tbf;
311
312 printf("Testing jolly example\n");
313
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100314 the_pcu->alloc_algorithm = alloc_algorithm_b;
Max2ecf0fd2017-11-21 18:13:31 +0100315
316 enable_ts_on_bts(bts, false, true, true, true, true, false, false, false);
317
318 tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1);
319 OSMO_ASSERT(tfi >= 0);
Pau Espin Pedrol17402a52020-05-08 17:44:33 +0200320 ms = the_bts.ms_alloc(ms_class, 0);
Pau Espin Pedrol1e009472021-01-11 20:40:19 +0100321 /* Avoid delaying free to avoid tons of to-be-freed ms objects queuing */
322 ms_set_timeout(ms, 0);
Pau Espin Pedrol17402a52020-05-08 17:44:33 +0200323 ul_tbf = tbf_alloc_ul_tbf(bts, ms, -1, false);
Max2ecf0fd2017-11-21 18:13:31 +0100324 if (!ul_tbf)
325 return false;
326
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200327 OSMO_ASSERT(ul_tbf->ms() == ms);
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100328 OSMO_ASSERT(ms_current_trx(ul_tbf->ms()));
329 trx_no = ms_current_trx(ms)->trx_no;
Max2ecf0fd2017-11-21 18:13:31 +0100330 dump_assignment(ul_tbf, "UL", true);
331
332 /* assume final ack has not been sent */
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200333 dl_tbf = tbf_alloc_dl_tbf(bts, ms, trx_no, false);
Max2ecf0fd2017-11-21 18:13:31 +0100334 if (!dl_tbf)
335 return false;
336
337 dump_assignment(dl_tbf, "DL", true);
338
339 OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
340
341 check_tfi_usage(&the_bts);
342
343 tbf_free(dl_tbf);
344 tbf_free(ul_tbf);
345
346 return true;
347}
348
349static void test_alloc_b_for_ms(uint8_t ms_class)
350{
351 bool rc;
352
Holger Hans Peter Freytherc7b998c2013-12-25 19:25:10 +0100353 printf("Going to test multislot assignment MS_CLASS=%d\n", ms_class);
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100354 /*
355 * PDCH is on TS 6,7,8 and we start with a UL allocation and
356 * then follow two DL allocations (once single, once normal).
357 *
358 * Uplink assigned and still available..
359 */
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100360
Max2ecf0fd2017-11-21 18:13:31 +0100361 rc = test_alloc_b_ul_dl(false, false, false, false, false, true, true, true, ms_class, true);
362 if (!rc)
363 return;
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100364
365 /**
366 * Test with the other order.. first DL and then UL
367 */
Max2ecf0fd2017-11-21 18:13:31 +0100368 rc = test_alloc_b_dl_ul(false, false, false, false, false, true, true, true, ms_class, true);
369 if (!rc)
370 return;
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100371
372 /* Andreas osmocom-pcu example */
Max2ecf0fd2017-11-21 18:13:31 +0100373 test_alloc_b_jolly(ms_class);
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100374}
375
Max2ecf0fd2017-11-21 18:13:31 +0100376static void test_alloc_mass(bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7, int ms_class)
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100377{
Max2ecf0fd2017-11-21 18:13:31 +0100378 bool rc;
379
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100380 /* we can test the allocation failures differently */
381 if (!ts0 && !ts1 && !ts2 && !ts3 && !ts4 && !ts5 && !ts6 && !ts7)
382 return;
383
384 printf("Mass test: TS0(%c%c%c%c%c%c%c%c)TS7 MS_Class=%d\n",
385 ts0 ? 'O' : 'x',
386 ts1 ? 'O' : 'x',
387 ts2 ? 'O' : 'x',
388 ts3 ? 'O' : 'x',
389 ts4 ? 'O' : 'x',
390 ts5 ? 'O' : 'x',
391 ts6 ? 'O' : 'x',
392 ts7 ? 'O' : 'x', ms_class);
393 fflush(stdout);
394
Max2ecf0fd2017-11-21 18:13:31 +0100395 rc = test_alloc_b_ul_dl(ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7, ms_class, false);
396 if (!rc)
397 return;
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100398
399 /**
400 * Test with the other order.. first DL and then UL
401 */
Max2ecf0fd2017-11-21 18:13:31 +0100402 test_alloc_b_dl_ul(ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7, ms_class, false);
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100403}
404
405static void test_all_alloc_b()
406{
407 /* it is a bit crazy... */
408 for (uint8_t ts0 = 0; ts0 < 2; ++ts0)
409 for (uint8_t ts1 = 0; ts1 < 2; ++ts1)
410 for (uint8_t ts2 = 0; ts2 < 2; ++ts2)
411 for (uint8_t ts3 = 0; ts3 < 2; ++ts3)
412 for (uint8_t ts4 = 0; ts4 < 2; ++ts4)
413 for (uint8_t ts5 = 0; ts5 < 2; ++ts5)
414 for (uint8_t ts6 = 0; ts6 < 2; ++ts6)
415 for (uint8_t ts7 = 0; ts7 < 2; ++ts7)
Max9f460712018-01-23 20:57:08 +0100416 for (int ms_class = 0; ms_class < mslot_class_max(); ++ms_class)
Max2ecf0fd2017-11-21 18:13:31 +0100417 test_alloc_mass(ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7, ms_class);
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100418}
419
Holger Hans Peter Freytherc7b998c2013-12-25 19:25:10 +0100420static void test_alloc_b()
421{
Max9f460712018-01-23 20:57:08 +0100422 for (int i = 0; i < mslot_class_max(); ++i)
Max2ecf0fd2017-11-21 18:13:31 +0100423 test_alloc_b_for_ms(i);
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100424
425 test_all_alloc_b();
Holger Hans Peter Freytherc7b998c2013-12-25 19:25:10 +0100426}
427
Maxe9fe0e32017-09-28 15:56:05 +0200428typedef int (*algo_t)(struct gprs_rlcmac_bts *bts, struct GprsMs *ms, struct gprs_rlcmac_tbf *tbf, bool single,
429 int8_t use_trx);
Jacob Erlbecke5655642015-06-29 12:19:52 +0200430
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200431static char get_dir_char(uint8_t mask, uint8_t tx, uint8_t rx, uint8_t busy)
Jacob Erlbecke5655642015-06-29 12:19:52 +0200432{
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200433 int offs = busy ? 32 : 0;
434 return (mask & tx & rx) ? 'C' + offs :
435 (mask & tx) ? 'U' + offs :
436 (mask & rx) ? 'D' + offs :
Jacob Erlbecke5655642015-06-29 12:19:52 +0200437 '.';
438}
439
440enum test_mode {
441 TEST_MODE_UL_ONLY,
442 TEST_MODE_DL_ONLY,
443 TEST_MODE_UL_AND_DL,
444 TEST_MODE_DL_AND_UL,
445 TEST_MODE_DL_AFTER_UL,
446 TEST_MODE_UL_AFTER_DL,
447};
448
Maxc59ef122017-11-27 13:21:41 +0100449static inline char *test_mode_descr(enum test_mode t)
450{
451 switch (t) {
452 case TEST_MODE_UL_ONLY: return (char*)"UL only";
453 case TEST_MODE_DL_ONLY: return (char*)"DL only";
454 case TEST_MODE_UL_AND_DL: return (char*)"UL and DL";
455 case TEST_MODE_DL_AND_UL: return (char*)"DL and UL";
456 case TEST_MODE_DL_AFTER_UL: return (char*)"DL after UL";
457 case TEST_MODE_UL_AFTER_DL: return (char*)"UL after DL";
458 default: return NULL;
459 }
460}
461
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100462static GprsMs *alloc_tbfs(BTS *the_bts, struct GprsMs *old_ms, enum test_mode mode)
Jacob Erlbecke5655642015-06-29 12:19:52 +0200463{
464 struct gprs_rlcmac_bts *bts;
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100465 struct GprsMs *ms, *new_ms;
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200466 uint8_t trx_no = -1;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200467
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100468 OSMO_ASSERT(old_ms != NULL);
Pau Espin Pedrol17402a52020-05-08 17:44:33 +0200469
Jacob Erlbecke5655642015-06-29 12:19:52 +0200470 bts = the_bts->bts_data();
471
472 gprs_rlcmac_tbf *tbf = NULL;
473
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100474 if (ms_current_trx(old_ms))
475 trx_no = ms_current_trx(old_ms)->trx_no;
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200476
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100477 ms_ref(old_ms);
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200478
Jacob Erlbecke5655642015-06-29 12:19:52 +0200479 /* Allocate what is needed first */
480 switch (mode) {
481 case TEST_MODE_UL_ONLY:
482 case TEST_MODE_DL_AFTER_UL:
483 case TEST_MODE_UL_AND_DL:
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100484 if (ms_ul_tbf(old_ms))
485 tbf_free(ms_ul_tbf(old_ms));
486 tbf = tbf_alloc_ul_tbf(bts, old_ms, trx_no, false);
487 if (tbf == NULL) {
488 ms_unref(old_ms);
Jacob Erlbecke5655642015-06-29 12:19:52 +0200489 return NULL;
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100490 }
Jacob Erlbecke5655642015-06-29 12:19:52 +0200491 break;
492 case TEST_MODE_DL_ONLY:
493 case TEST_MODE_UL_AFTER_DL:
494 case TEST_MODE_DL_AND_UL:
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100495 if (ms_dl_tbf(old_ms))
496 tbf_free(ms_dl_tbf(old_ms));
497 tbf = tbf_alloc_dl_tbf(bts, old_ms, trx_no, false);
498 if (tbf == NULL) {
499 ms_unref(old_ms);
Jacob Erlbecke5655642015-06-29 12:19:52 +0200500 return NULL;
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100501 }
Jacob Erlbecke5655642015-06-29 12:19:52 +0200502 }
503
504 OSMO_ASSERT(tbf);
505 OSMO_ASSERT(tbf->ms());
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100506 OSMO_ASSERT(old_ms == tbf->ms());
Jacob Erlbecke5655642015-06-29 12:19:52 +0200507 ms = tbf->ms();
508
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100509 ms_ref(ms);
510 new_ms = ms;
Jacob Erlbeck14376a72015-07-07 11:31:28 +0200511 /* Continue with what is needed next */
512 switch (mode) {
513 case TEST_MODE_UL_ONLY:
514 case TEST_MODE_DL_ONLY:
515 /* We are done */
516 break;
517
518 case TEST_MODE_DL_AFTER_UL:
519 case TEST_MODE_UL_AND_DL:
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100520 new_ms = alloc_tbfs(the_bts, ms, TEST_MODE_DL_ONLY);
Jacob Erlbeck14376a72015-07-07 11:31:28 +0200521 break;
522
523 case TEST_MODE_UL_AFTER_DL:
524 case TEST_MODE_DL_AND_UL:
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100525 new_ms = alloc_tbfs(the_bts, ms, TEST_MODE_UL_ONLY);
Jacob Erlbeck14376a72015-07-07 11:31:28 +0200526 break;
527 }
528
Jacob Erlbecke5655642015-06-29 12:19:52 +0200529 /* Optionally delete the TBF */
530 switch (mode) {
531 case TEST_MODE_DL_AFTER_UL:
532 case TEST_MODE_UL_AFTER_DL:
533 tbf_free(tbf);
Jacob Erlbeck0f352a62015-07-16 18:23:33 +0200534 tbf = NULL;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200535 break;
536
537 default:
538 break;
539 }
540
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100541 if (!new_ms && tbf)
Jacob Erlbeck0f352a62015-07-16 18:23:33 +0200542 tbf_free(tbf);
543
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100544 ms_unref(old_ms);
545 ms_unref(ms);
546 return new_ms;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200547}
548
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200549static unsigned alloc_many_tbfs(BTS *the_bts, unsigned min_class,
550 unsigned max_class, enum test_mode mode)
Jacob Erlbecke5655642015-06-29 12:19:52 +0200551{
Jacob Erlbecke5655642015-06-29 12:19:52 +0200552 unsigned counter;
553 unsigned ms_class = min_class;
554
Jacob Erlbecke5655642015-06-29 12:19:52 +0200555 for (counter = 0; 1; counter += 1) {
556 gprs_rlcmac_tbf *ul_tbf, *dl_tbf;
557 uint8_t ul_slots = 0;
558 uint8_t dl_slots = 0;
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200559 uint8_t busy_slots = 0;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200560 unsigned i;
561 int tfi = -1;
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200562 int tfi2;
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200563 uint8_t trx_no2;
564 struct gprs_rlcmac_trx *trx;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200565 GprsMs *ms;
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200566 enum gprs_rlcmac_tbf_direction dir;
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200567 uint32_t tlli = counter + 0xc0000000;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200568
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200569 ms = the_bts->ms_by_tlli(tlli);
Pau Espin Pedrol17402a52020-05-08 17:44:33 +0200570 if (!ms)
571 ms = the_bts->ms_alloc(0, 0);
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100572 ms_set_ms_class(ms, ms_class);
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200573 ms = alloc_tbfs(the_bts, ms, mode);
Jacob Erlbecke5655642015-06-29 12:19:52 +0200574 if (!ms)
575 break;
576
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100577 ms_set_tlli(ms, tlli);
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200578
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100579 ul_tbf = ms_ul_tbf(ms);
580 dl_tbf = ms_dl_tbf(ms);
581 trx = ms_current_trx(ms);
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200582
583 OSMO_ASSERT(ul_tbf || dl_tbf);
Jacob Erlbecke5655642015-06-29 12:19:52 +0200584
585 if (ul_tbf) {
586 ul_slots = 1 << ul_tbf->first_common_ts;
587 tfi = ul_tbf->tfi();
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200588 dir = GPRS_RLCMAC_UL_TBF;
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200589 } else {
Jacob Erlbecke5655642015-06-29 12:19:52 +0200590 ul_slots = 1 << dl_tbf->first_common_ts;
591 tfi = dl_tbf->tfi();
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200592 dir = GPRS_RLCMAC_DL_TBF;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200593 }
594
595 for (i = 0; dl_tbf && i < ARRAY_SIZE(dl_tbf->pdch); i += 1)
596 if (dl_tbf->pdch[i])
597 dl_slots |= 1 << i;
598
Max5b0df1f2017-09-11 10:38:59 +0200599 for (i = 0; ul_tbf && i < ARRAY_SIZE(ul_tbf->pdch); i += 1)
600 if (ul_tbf->pdch[i])
601 ul_slots |= 1 << i;
602
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200603 for (i = 0; trx && i < ARRAY_SIZE(trx->pdch); i += 1) {
604 struct gprs_rlcmac_pdch *pdch = &trx->pdch[i];
605
606 if (ul_tbf && dl_tbf)
607 continue;
608
609 if (ul_tbf &&
Maxd000d802017-09-20 17:55:28 +0200610 pdch->assigned_tfi(GPRS_RLCMAC_DL_TBF) != NO_FREE_TFI)
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200611 continue;
612
613 if (dl_tbf &&
Maxd000d802017-09-20 17:55:28 +0200614 pdch->assigned_tfi(GPRS_RLCMAC_UL_TBF) != NO_FREE_TFI)
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200615 continue;
616
617 busy_slots |= 1 << i;
618 }
619
Maxd000d802017-09-20 17:55:28 +0200620 printf(" TBF[%d] class %d reserves " OSMO_BIT_SPEC "\n",
Jacob Erlbecke5655642015-06-29 12:19:52 +0200621 tfi, ms_class,
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200622 get_dir_char(0x01, ul_slots, dl_slots, busy_slots),
623 get_dir_char(0x02, ul_slots, dl_slots, busy_slots),
624 get_dir_char(0x04, ul_slots, dl_slots, busy_slots),
625 get_dir_char(0x08, ul_slots, dl_slots, busy_slots),
626 get_dir_char(0x10, ul_slots, dl_slots, busy_slots),
627 get_dir_char(0x20, ul_slots, dl_slots, busy_slots),
628 get_dir_char(0x40, ul_slots, dl_slots, busy_slots),
629 get_dir_char(0x80, ul_slots, dl_slots, busy_slots));
Jacob Erlbecke5655642015-06-29 12:19:52 +0200630
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200631 if (tfi >= 0) {
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100632 OSMO_ASSERT(ms_current_trx(ms));
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200633 tfi2 = the_bts->tfi_find_free(dir, &trx_no2,
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100634 ms_current_trx(ms)->trx_no);
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200635 OSMO_ASSERT(tfi != tfi2);
Jacob Erlbeck7b3675b2015-07-16 18:28:22 +0200636 OSMO_ASSERT(tfi2 < 0 ||
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100637 trx_no2 == ms_current_trx(ms)->trx_no);
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200638 }
639
Jacob Erlbecke5655642015-06-29 12:19:52 +0200640 ms_class += 1;
641 if (ms_class > max_class)
642 ms_class = min_class;
643 }
644
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200645 return counter;
646}
647
648static void test_successive_allocation(algo_t algo, unsigned min_class,
649 unsigned max_class, enum test_mode mode,
650 unsigned expect_num, const char *text)
651{
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100652 BTS the_bts(the_pcu);
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200653 struct gprs_rlcmac_bts *bts;
654 struct gprs_rlcmac_trx *trx;
655 unsigned counter;
656
Maxc59ef122017-11-27 13:21:41 +0100657 printf("Going to test assignment with many TBF, algorithm %s class %u..%u (%s)\n",
658 text, min_class, max_class, test_mode_descr(mode));
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200659
660 bts = the_bts.bts_data();
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100661 the_pcu->alloc_algorithm = algo;
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200662
663 trx = &bts->trx[0];
664 trx->pdch[3].enable();
665 trx->pdch[4].enable();
666 trx->pdch[5].enable();
667 trx->pdch[6].enable();
668 trx->pdch[7].enable();
669
670 counter = alloc_many_tbfs(&the_bts, min_class, max_class, mode);
671
Maxc59ef122017-11-27 13:21:41 +0100672 printf(" Successfully allocated %u UL TBFs, algorithm %s class %u..%u (%s)\n",
673 counter, text, min_class, max_class, test_mode_descr(mode));
Jacob Erlbeck88fb6132015-07-16 15:01:38 +0200674 if (counter != expect_num)
Maxc59ef122017-11-27 13:21:41 +0100675 fprintf(stderr, " Expected %u TBFs (got %u), algorithm %s class %u..%u (%s)\n",
676 expect_num, counter, text, min_class, max_class, test_mode_descr(mode));
Jacob Erlbeck88fb6132015-07-16 15:01:38 +0200677
Jacob Erlbeckec478752015-06-19 16:35:38 +0200678 OSMO_ASSERT(counter == expect_num);
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200679
680 check_tfi_usage(&the_bts);
Jacob Erlbecke5655642015-06-29 12:19:52 +0200681}
682
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200683static void test_many_connections(algo_t algo, unsigned expect_num,
684 const char *text)
685{
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100686 BTS the_bts(the_pcu);
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200687 struct gprs_rlcmac_bts *bts;
688 struct gprs_rlcmac_trx *trx;
689 int counter1, counter2 = -1;
690 unsigned i;
691 enum test_mode mode_seq[] = {
692 TEST_MODE_DL_AFTER_UL,
693 TEST_MODE_UL_ONLY,
694 TEST_MODE_DL_AFTER_UL,
695 TEST_MODE_DL_ONLY,
696 };
697
Maxc59ef122017-11-27 13:21:41 +0100698 printf("Going to test assignment with many connections, algorithm %s\n", text);
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200699
700 bts = the_bts.bts_data();
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100701 the_pcu->alloc_algorithm = algo;
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200702
703 trx = &bts->trx[0];
704 trx->pdch[3].enable();
705 trx->pdch[4].enable();
706 trx->pdch[5].enable();
707 trx->pdch[6].enable();
708 trx->pdch[7].enable();
709
710 for (i = 0; i < ARRAY_SIZE(mode_seq); i += 1) {
Max9f460712018-01-23 20:57:08 +0100711 counter1 = alloc_many_tbfs(&the_bts, 1, mslot_class_max(), mode_seq[i]);
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200712 fprintf(stderr, " Allocated %d TBFs (previously %d)\n",
713 counter1, counter2);
714
715 check_tfi_usage(&the_bts);
716
717 /* This will stop earlier due to USF shortage */
718 if (mode_seq[i] == TEST_MODE_UL_ONLY)
719 continue;
720
Jacob Erlbeck88fb6132015-07-16 15:01:38 +0200721 if (counter2 >= 0) {
722 if (counter1 < counter2)
723 fprintf(stderr, " Expected %d >= %d in %s\n",
724 counter1, counter2, text);
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200725 OSMO_ASSERT(counter1 >= counter2);
Jacob Erlbeck88fb6132015-07-16 15:01:38 +0200726 }
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200727
728 counter2 = counter1;
729 }
730
731 printf(" Successfully allocated %d TBFs\n", counter1);
Jacob Erlbeck88fb6132015-07-16 15:01:38 +0200732 if (counter1 != (int)expect_num)
Maxc59ef122017-11-27 13:21:41 +0100733 fprintf(stderr, " Expected %d TBFs (got %d) for algorithm %s\n", expect_num, counter1, text);
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200734
735 OSMO_ASSERT(expect_num == (unsigned)counter1);
736}
737
Maxc59ef122017-11-27 13:21:41 +0100738static inline void test_a_b_dyn(enum test_mode mode, uint8_t exp_A, uint8_t exp_B, uint8_t exp_dyn)
Jacob Erlbecke5655642015-06-29 12:19:52 +0200739{
Maxc59ef122017-11-27 13:21:41 +0100740 test_successive_allocation(alloc_algorithm_a, 1, 1, mode, exp_A, "A");
741 test_successive_allocation(alloc_algorithm_b, 10, 10, mode, exp_B, "B");
742 test_successive_allocation(alloc_algorithm_dynamic, 10, 10, mode, exp_dyn, "dynamic");
Jacob Erlbecke5655642015-06-29 12:19:52 +0200743}
744
Maxc59ef122017-11-27 13:21:41 +0100745static void test_successive_allocations()
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200746{
Maxc59ef122017-11-27 13:21:41 +0100747 test_successive_allocation(alloc_algorithm_a, 1, 1, TEST_MODE_UL_AND_DL, 35, "A");
748 test_successive_allocation(alloc_algorithm_b, 10, 10, TEST_MODE_UL_AND_DL, 32, "B");
749 test_successive_allocation(alloc_algorithm_b, 12, 12, TEST_MODE_UL_AND_DL, 32, "B");
750
Max9f460712018-01-23 20:57:08 +0100751 test_successive_allocation(alloc_algorithm_b, 1, 12, TEST_MODE_UL_AND_DL, 32, "B");
Max01bd0cc2018-01-23 20:58:49 +0100752 test_successive_allocation(alloc_algorithm_b, 1, mslot_class_max(), TEST_MODE_UL_AND_DL, 32, "B");
Max9f460712018-01-23 20:57:08 +0100753 test_successive_allocation(alloc_algorithm_dynamic, 1, mslot_class_max(), TEST_MODE_UL_AND_DL, 35, "dynamic");
Maxc59ef122017-11-27 13:21:41 +0100754
755 test_a_b_dyn(TEST_MODE_DL_AND_UL, 35, 32, 32);
756 test_a_b_dyn(TEST_MODE_DL_AFTER_UL, 160, 32, 95);
757 test_a_b_dyn(TEST_MODE_UL_AFTER_DL, 35, 32, 35);
758 test_a_b_dyn(TEST_MODE_UL_ONLY, 35, 32, 35);
759 test_a_b_dyn(TEST_MODE_DL_ONLY, 160, 32, 101);
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200760}
761
Aravind Sirsikare26ee012016-09-06 18:15:45 +0530762static void test_2_consecutive_dl_tbfs()
763{
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100764 BTS the_bts(the_pcu);
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200765 GprsMs *ms;
Aravind Sirsikare26ee012016-09-06 18:15:45 +0530766 struct gprs_rlcmac_bts *bts;
767 struct gprs_rlcmac_trx *trx;
768 uint8_t ms_class = 11;
769 uint8_t egprs_ms_class = 11;
770 gprs_rlcmac_tbf *dl_tbf1, *dl_tbf2;
771 uint8_t numTs1 = 0, numTs2 = 0;
772
773 printf("Testing DL TS allocation for Multi UEs\n");
774
775 bts = the_bts.bts_data();
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100776 the_pcu->alloc_algorithm = alloc_algorithm_b;
Aravind Sirsikare26ee012016-09-06 18:15:45 +0530777
778 trx = &bts->trx[0];
779 trx->pdch[4].enable();
780 trx->pdch[5].enable();
781 trx->pdch[6].enable();
782 trx->pdch[7].enable();
783
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200784 ms = the_bts.ms_alloc(ms_class, egprs_ms_class);
785 dl_tbf1 = tbf_alloc_dl_tbf(bts, ms, 0, false);
Aravind Sirsikare26ee012016-09-06 18:15:45 +0530786 OSMO_ASSERT(dl_tbf1);
787
788 for (int i = 0; i < 8; i++) {
789 if (dl_tbf1->pdch[i])
790 numTs1++;
791 }
792 OSMO_ASSERT(numTs1 == 4);
793 printf("TBF1: numTs(%d)\n", numTs1);
794
Pau Espin Pedrol322456e2020-05-08 18:15:59 +0200795 ms = the_bts.ms_alloc(ms_class, egprs_ms_class);
796 dl_tbf2 = tbf_alloc_dl_tbf(bts, ms, 0, false);
Aravind Sirsikare26ee012016-09-06 18:15:45 +0530797 OSMO_ASSERT(dl_tbf2);
798
799 for (int i = 0; i < 8; i++) {
800 if (dl_tbf2->pdch[i])
801 numTs2++;
802 }
803
804 /*
805 * TODO: currently 2nd DL TBF gets 3 TS
806 * This behaviour will be fixed in subsequent patch
807 */
808 printf("TBF2: numTs(%d)\n", numTs2);
809 OSMO_ASSERT(numTs2 == 3);
810
811 tbf_free(dl_tbf1);
812 tbf_free(dl_tbf2);
813}
814
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200815int main(int argc, char **argv)
816{
817 tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile AllocTest context");
818 if (!tall_pcu_ctx)
819 abort();
820
Neels Hofmeyr78ce5912017-02-08 17:07:31 +0100821 msgb_talloc_ctx_init(tall_pcu_ctx, 0);
Neels Hofmeyr42f2d612018-04-01 16:54:40 +0200822 osmo_init_logging2(tall_pcu_ctx, &gprs_log_info);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200823 log_set_use_color(osmo_stderr_target, 0);
824 log_set_print_filename(osmo_stderr_target, 0);
Philipp Maierde0e5582020-03-25 12:23:52 +0100825 log_set_category_filter(osmo_stderr_target, DTBF, 1, LOGL_INFO);
Jacob Erlbeck9ec49e22015-06-29 13:00:20 +0200826 if (getenv("LOGL_DEBUG"))
827 log_set_log_level(osmo_stderr_target, LOGL_DEBUG);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200828
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100829 the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
830
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200831 test_alloc_a();
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100832 test_alloc_b();
Maxc59ef122017-11-27 13:21:41 +0100833 test_successive_allocations();
834 test_many_connections(alloc_algorithm_a, 160, "A");
Max01bd0cc2018-01-23 20:58:49 +0100835 test_many_connections(alloc_algorithm_b, 32, "B");
Maxc59ef122017-11-27 13:21:41 +0100836 test_many_connections(alloc_algorithm_dynamic, 160, "dynamic");
Aravind Sirsikare26ee012016-09-06 18:15:45 +0530837 test_2_consecutive_dl_tbfs();
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100838
839 talloc_free(the_pcu);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200840 return EXIT_SUCCESS;
841}
842
843/*
844 * stubs that should not be reached
845 */
846extern "C" {
847void l1if_pdch_req() { abort(); }
848void l1if_connect_pdch() { abort(); }
849void l1if_close_pdch() { abort(); }
850void l1if_open_pdch() { abort(); }
851}