blob: 4b532246291b37a31515e648d9b440188cec29c6 [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"
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +020023#include "bts.h"
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020024
25#include <string.h>
26#include <stdio.h>
27
28extern "C" {
29#include <osmocom/core/application.h>
30#include <osmocom/core/msgb.h>
31#include <osmocom/core/talloc.h>
32#include <osmocom/core/utils.h>
33}
34
35/* globals used by the code */
36void *tall_pcu_ctx;
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +020037int16_t spoof_mnc = 0, spoof_mcc = 0;
38
Daniel Willmann48aa0b02014-07-16 18:54:10 +020039static gprs_rlcmac_tbf *tbf_alloc(struct gprs_rlcmac_bts *bts,
Jacob Erlbecke2e004e2015-06-18 17:16:26 +020040 GprsMs *ms, gprs_rlcmac_tbf_direction dir,
Jacob Erlbeck5879c642015-07-10 10:41:36 +020041 uint8_t use_trx,
Daniel Willmann48aa0b02014-07-16 18:54:10 +020042 uint8_t ms_class, uint8_t single_slot)
43{
44 if (dir == GPRS_RLCMAC_UL_TBF)
Jacob Erlbeck5879c642015-07-10 10:41:36 +020045 return tbf_alloc_ul_tbf(bts, ms, use_trx, ms_class, single_slot);
Daniel Willmann48aa0b02014-07-16 18:54:10 +020046 else
Jacob Erlbeck5879c642015-07-10 10:41:36 +020047 return tbf_alloc_dl_tbf(bts, ms, use_trx, ms_class, single_slot);
Daniel Willmann48aa0b02014-07-16 18:54:10 +020048}
49
Jacob Erlbeck61205a72015-07-09 11:35:50 +020050static void check_tfi_usage(BTS *the_bts)
51{
52 int pdch_no;
53 struct gprs_rlcmac_bts *bts = the_bts->bts_data();
54
55 struct gprs_rlcmac_tbf *tfi_usage[8][8][2][32] = {{{{NULL}}}};
56 struct llist_head *tbf_lists[2] = {
57 &bts->ul_tbfs,
58 &bts->dl_tbfs
59 };
60
61 gprs_rlcmac_tbf *tbf;
62 struct llist_pods *lpods;
63 unsigned list_idx;
64 struct gprs_rlcmac_tbf **tbf_var;
65
66 for (list_idx = 0; list_idx < ARRAY_SIZE(tbf_lists); list_idx += 1)
67 {
68
69 llist_pods_for_each_entry(tbf, tbf_lists[list_idx], list, lpods) {
70 for (pdch_no = 0; pdch_no < 8; pdch_no += 1) {
71 struct gprs_rlcmac_pdch *pdch = tbf->pdch[pdch_no];
72 if (pdch == NULL)
73 continue;
74
75 tbf_var = &tfi_usage
76 [tbf->trx->trx_no]
77 [pdch_no]
78 [tbf->direction]
79 [tbf->tfi()];
80
81 OSMO_ASSERT(*tbf_var == NULL);
82 if (tbf->direction == GPRS_RLCMAC_DL_TBF) {
83 OSMO_ASSERT(pdch->dl_tbf_by_tfi(
84 tbf->tfi()) == tbf);
Jacob Erlbeck61205a72015-07-09 11:35:50 +020085 OSMO_ASSERT(the_bts->dl_tbf_by_tfi(
86 tbf->tfi(),
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +020087 tbf->trx->trx_no,
88 pdch_no) == tbf);
Jacob Erlbeck61205a72015-07-09 11:35:50 +020089 } else {
90 OSMO_ASSERT(pdch->ul_tbf_by_tfi(
91 tbf->tfi()) == tbf);
Jacob Erlbeck61205a72015-07-09 11:35:50 +020092 OSMO_ASSERT(the_bts->ul_tbf_by_tfi(
93 tbf->tfi(),
Jacob Erlbeck3a10dbd2015-07-10 19:52:37 +020094 tbf->trx->trx_no,
95 pdch_no) == tbf);
Jacob Erlbeck61205a72015-07-09 11:35:50 +020096 }
97 *tbf_var = tbf;
Jacob Erlbeck47a57f62015-07-08 12:53:16 +020098 OSMO_ASSERT(pdch->assigned_tfi(tbf->direction) &
99 (1 << tbf->tfi()));
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200100 }
101 }
102 }
103}
104
Jacob Erlbeckfa464bb2015-06-29 12:45:11 +0200105static void test_alloc_a(gprs_rlcmac_tbf_direction dir,
106 uint8_t slots, const int count)
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200107{
108 int tfi;
Jacob Erlbeckfa464bb2015-06-29 12:45:11 +0200109 int i;
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200110 uint8_t used_trx, tmp_trx;
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200111 BTS the_bts;
112 struct gprs_rlcmac_bts *bts;
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200113 struct gprs_rlcmac_tbf *tbfs[32*8+1] = { 0, };
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200114
115 printf("Testing alloc_a direction(%d)\n", dir);
116
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200117 bts = the_bts.bts_data();
118 bts->alloc_algorithm = alloc_algorithm_a;
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200119
Holger Hans Peter Freyther34bd8bd2013-10-19 21:10:38 +0200120 struct gprs_rlcmac_trx *trx = &bts->trx[0];
Jacob Erlbeckfa464bb2015-06-29 12:45:11 +0200121 for (i = 0; i < 8; i += 1)
122 if (slots & (1 << i))
123 trx->pdch[i].enable();
124
125 OSMO_ASSERT(count >= 0 && count <= (int)ARRAY_SIZE(tbfs));
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200126
127 /**
128 * Currently alloc_a will only allocate from the first
129 * PDCH and all possible usf's. We run out of usf's before
130 * we are out of tfi's. Observe this and make sure that at
131 * least this part is working okay.
132 */
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200133 for (i = 0; i < (int)ARRAY_SIZE(tbfs); ++i) {
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200134 tbfs[i] = tbf_alloc(bts, NULL, dir, -1, 0, 0);
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200135 if (tbfs[i] == NULL)
136 break;
137
138 used_trx = tbfs[i]->trx->trx_no;
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200139 tfi = the_bts.tfi_find_free(dir, &tmp_trx, used_trx);
140 OSMO_ASSERT(tbfs[i]->tfi() != tfi);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200141 }
142
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200143 check_tfi_usage(&the_bts);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200144
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200145 OSMO_ASSERT(i == count);
146
147 for (i = 0; i < count; ++i)
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200148 if (tbfs[i])
149 tbf_free(tbfs[i]);
150
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200151 tbfs[tfi] = tbf_alloc(bts, NULL, dir, -1, 0, 0);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200152 OSMO_ASSERT(tbfs[tfi]);
153 tbf_free(tbfs[tfi]);
154}
155
156static void test_alloc_a()
157{
Jacob Erlbeckfa464bb2015-06-29 12:45:11 +0200158 /* slots 2 - 3 */
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200159 test_alloc_a(GPRS_RLCMAC_DL_TBF, 0x0c, 32*2);
Jacob Erlbeckec478752015-06-19 16:35:38 +0200160 test_alloc_a(GPRS_RLCMAC_UL_TBF, 0x0c, 14);
Jacob Erlbeckfa464bb2015-06-29 12:45:11 +0200161
162 /* slots 1 - 5 */
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200163 test_alloc_a(GPRS_RLCMAC_DL_TBF, 0x1e, 32*4);
Jacob Erlbeckec478752015-06-19 16:35:38 +0200164 test_alloc_a(GPRS_RLCMAC_UL_TBF, 0x1e, 28);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200165}
166
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100167static void dump_assignment(struct gprs_rlcmac_tbf *tbf, const char *dir)
168{
Jacob Erlbeck1f332942015-05-04 08:21:17 +0200169 for (size_t i = 0; i < ARRAY_SIZE(tbf->pdch); ++i)
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100170 if (tbf->pdch[i])
171 printf("PDCH[%d] is used for %s\n", i, dir);
172 printf("PDCH[%d] is control_ts for %s\n", tbf->control_ts, dir);
173 printf("PDCH[%d] is first common for %s\n", tbf->first_common_ts, dir);
174}
175
Holger Hans Peter Freytherc7b998c2013-12-25 19:25:10 +0100176static void test_alloc_b(int ms_class)
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100177{
Holger Hans Peter Freytherc7b998c2013-12-25 19:25:10 +0100178 printf("Going to test multislot assignment MS_CLASS=%d\n", ms_class);
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100179 /*
180 * PDCH is on TS 6,7,8 and we start with a UL allocation and
181 * then follow two DL allocations (once single, once normal).
182 *
183 * Uplink assigned and still available..
184 */
185 {
186 BTS the_bts;
187 struct gprs_rlcmac_bts *bts;
188 struct gprs_rlcmac_trx *trx;
Jacob Erlbeck1f332942015-05-04 08:21:17 +0200189 uint8_t trx_no;
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100190
191 gprs_rlcmac_tbf *ul_tbf, *dl_tbf;
192
193 printf("Testing UL then DL assignment.\n");
194
195 bts = the_bts.bts_data();
196 bts->alloc_algorithm = alloc_algorithm_b;
197
198 trx = &bts->trx[0];
199 trx->pdch[5].enable();
200 trx->pdch[6].enable();
201 trx->pdch[7].enable();
202
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200203 ul_tbf = tbf_alloc_ul_tbf(bts, NULL, -1, ms_class, 1);
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100204 OSMO_ASSERT(ul_tbf);
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200205 OSMO_ASSERT(ul_tbf->ms());
206 OSMO_ASSERT(ul_tbf->ms()->current_trx());
207 trx_no = ul_tbf->ms()->current_trx()->trx_no;
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100208 dump_assignment(ul_tbf, "UL");
209
210 /* assume final ack has not been sent */
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200211 dl_tbf = tbf_alloc_dl_tbf(bts, ul_tbf->ms(), trx_no, ms_class, 0);
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100212 OSMO_ASSERT(dl_tbf);
213 dump_assignment(dl_tbf, "DL");
214
Holger Hans Peter Freytherc7b998c2013-12-25 19:25:10 +0100215 OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
216
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200217 check_tfi_usage(&the_bts);
218
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100219 tbf_free(dl_tbf);
220 tbf_free(ul_tbf);
221 }
222
223 /**
224 * Test with the other order.. first DL and then UL
225 */
226 {
227 BTS the_bts;
228 struct gprs_rlcmac_bts *bts;
229 struct gprs_rlcmac_trx *trx;
Jacob Erlbeck1f332942015-05-04 08:21:17 +0200230 uint8_t trx_no;
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100231
Daniel Willmann351a5732014-08-07 12:57:44 +0200232 gprs_rlcmac_ul_tbf *ul_tbf;
233 gprs_rlcmac_dl_tbf *dl_tbf;
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100234
235 printf("Testing DL then UL assignment followed by update\n");
236
237 bts = the_bts.bts_data();
238 bts->alloc_algorithm = alloc_algorithm_b;
239
240 trx = &bts->trx[0];
241 trx->pdch[5].enable();
242 trx->pdch[6].enable();
243 trx->pdch[7].enable();
244
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200245 dl_tbf = tbf_alloc_dl_tbf(bts, NULL, -1, ms_class, 1);
Jacob Erlbeck767193e2015-05-20 12:06:46 +0200246 dl_tbf->update_ms(0x23, GPRS_RLCMAC_DL_TBF);
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100247 OSMO_ASSERT(dl_tbf);
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200248 OSMO_ASSERT(dl_tbf->ms());
249 OSMO_ASSERT(dl_tbf->ms()->current_trx());
250 trx_no = dl_tbf->ms()->current_trx()->trx_no;
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100251 dump_assignment(dl_tbf, "DL");
252
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200253 ul_tbf = tbf_alloc_ul_tbf(bts, dl_tbf->ms(), trx_no, ms_class, 0);
Jacob Erlbeck767193e2015-05-20 12:06:46 +0200254 ul_tbf->update_ms(0x23, GPRS_RLCMAC_UL_TBF);
Daniel Willmann7e994e32014-08-07 15:49:21 +0200255 ul_tbf->m_contention_resolution_done = 1;
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100256 OSMO_ASSERT(ul_tbf);
257 dump_assignment(ul_tbf, "UL");
258
Holger Hans Peter Freytherc7b998c2013-12-25 19:25:10 +0100259 OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
260
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100261 /* now update the dl_tbf */
262 dl_tbf->update();
263 dump_assignment(dl_tbf, "DL");
Holger Hans Peter Freytherc7b998c2013-12-25 19:25:10 +0100264 OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100265
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200266 check_tfi_usage(&the_bts);
267
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100268 tbf_free(dl_tbf);
269 tbf_free(ul_tbf);
270 }
271
272 /* Andreas osmocom-pcu example */
273 {
274 BTS the_bts;
275 struct gprs_rlcmac_bts *bts;
276 struct gprs_rlcmac_trx *trx;
277 int tfi;
Jacob Erlbeck1f332942015-05-04 08:21:17 +0200278 uint8_t trx_no;
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100279
280 gprs_rlcmac_tbf *ul_tbf, *dl_tbf;
281
282 printf("Testing jolly example\n");
283
284 bts = the_bts.bts_data();
285 bts->alloc_algorithm = alloc_algorithm_b;
286
287 trx = &bts->trx[0];
288 trx->pdch[1].enable();
289 trx->pdch[2].enable();
290 trx->pdch[3].enable();
291 trx->pdch[4].enable();
292
293 tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1);
294 OSMO_ASSERT(tfi >= 0);
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200295 ul_tbf = tbf_alloc_ul_tbf(bts, NULL, .1, ms_class, 0);
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100296 OSMO_ASSERT(ul_tbf);
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200297 OSMO_ASSERT(ul_tbf->ms());
298 OSMO_ASSERT(ul_tbf->ms()->current_trx());
299 trx_no = ul_tbf->ms()->current_trx()->trx_no;
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100300 dump_assignment(ul_tbf, "UL");
301
302 /* assume final ack has not been sent */
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200303 dl_tbf = tbf_alloc_dl_tbf(bts, ul_tbf->ms(), trx_no, ms_class, 0);
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100304 OSMO_ASSERT(dl_tbf);
305 dump_assignment(dl_tbf, "DL");
306
Holger Hans Peter Freytherc7b998c2013-12-25 19:25:10 +0100307 OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
308
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200309 check_tfi_usage(&the_bts);
310
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100311 tbf_free(dl_tbf);
312 tbf_free(ul_tbf);
313 }
314}
315
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100316#define ENABLE_PDCH(ts_no, enable_flag, trx) \
317 if (enable_flag) \
318 trx->pdch[ts_no].enable();
319
320static void test_alloc_b(bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7, int ms_class)
321{
322 /* we can test the allocation failures differently */
323 if (!ts0 && !ts1 && !ts2 && !ts3 && !ts4 && !ts5 && !ts6 && !ts7)
324 return;
325
326 printf("Mass test: TS0(%c%c%c%c%c%c%c%c)TS7 MS_Class=%d\n",
327 ts0 ? 'O' : 'x',
328 ts1 ? 'O' : 'x',
329 ts2 ? 'O' : 'x',
330 ts3 ? 'O' : 'x',
331 ts4 ? 'O' : 'x',
332 ts5 ? 'O' : 'x',
333 ts6 ? 'O' : 'x',
334 ts7 ? 'O' : 'x', ms_class);
335 fflush(stdout);
336
337 {
338 BTS the_bts;
339 struct gprs_rlcmac_bts *bts;
340 struct gprs_rlcmac_trx *trx;
Jacob Erlbeck1f332942015-05-04 08:21:17 +0200341 uint8_t trx_no;
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100342
343 gprs_rlcmac_tbf *ul_tbf, *dl_tbf;
344
345 bts = the_bts.bts_data();
346 bts->alloc_algorithm = alloc_algorithm_b;
347
348 trx = &bts->trx[0];
349 ENABLE_PDCH(0, ts0, trx);
350 ENABLE_PDCH(1, ts1, trx);
351 ENABLE_PDCH(2, ts2, trx);
352 ENABLE_PDCH(3, ts3, trx);
353 ENABLE_PDCH(4, ts4, trx);
354 ENABLE_PDCH(5, ts5, trx);
355 ENABLE_PDCH(6, ts6, trx);
356 ENABLE_PDCH(7, ts7, trx);
357
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200358 ul_tbf = tbf_alloc_ul_tbf(bts, NULL, -1, ms_class, 1);
359 OSMO_ASSERT(ul_tbf->ms());
360 OSMO_ASSERT(ul_tbf->ms()->current_trx());
361 trx_no = ul_tbf->ms()->current_trx()->trx_no;
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100362 OSMO_ASSERT(ul_tbf);
363
364 /* assume final ack has not been sent */
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200365 dl_tbf = tbf_alloc_dl_tbf(bts, ul_tbf->ms(), trx_no, ms_class, 0);
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100366 OSMO_ASSERT(dl_tbf);
367
368 /* verify that both are on the same ts */
369 OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
370
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200371 check_tfi_usage(&the_bts);
372
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100373 tbf_free(dl_tbf);
374 tbf_free(ul_tbf);
375 }
376
377 /**
378 * Test with the other order.. first DL and then UL
379 */
380 {
381 BTS the_bts;
382 struct gprs_rlcmac_bts *bts;
383 struct gprs_rlcmac_trx *trx;
Jacob Erlbeck1f332942015-05-04 08:21:17 +0200384 uint8_t trx_no;
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100385
Daniel Willmann351a5732014-08-07 12:57:44 +0200386 gprs_rlcmac_ul_tbf *ul_tbf;
387 gprs_rlcmac_dl_tbf *dl_tbf;
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100388
389 bts = the_bts.bts_data();
390 bts->alloc_algorithm = alloc_algorithm_b;
391
392 trx = &bts->trx[0];
393 ENABLE_PDCH(0, ts0, trx);
394 ENABLE_PDCH(1, ts1, trx);
395 ENABLE_PDCH(2, ts2, trx);
396 ENABLE_PDCH(3, ts3, trx);
397 ENABLE_PDCH(4, ts4, trx);
398 ENABLE_PDCH(5, ts5, trx);
399 ENABLE_PDCH(6, ts6, trx);
400 ENABLE_PDCH(7, ts7, trx);
401
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200402 dl_tbf = tbf_alloc_dl_tbf(bts, NULL, -1, ms_class, 1);
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100403 OSMO_ASSERT(dl_tbf);
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200404 OSMO_ASSERT(dl_tbf->ms());
405 OSMO_ASSERT(dl_tbf->ms()->current_trx());
406 trx_no = dl_tbf->ms()->current_trx()->trx_no;
Jacob Erlbeck767193e2015-05-20 12:06:46 +0200407 dl_tbf->update_ms(0x23, GPRS_RLCMAC_DL_TBF);
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100408
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200409 ul_tbf = tbf_alloc_ul_tbf(bts, dl_tbf->ms(), trx_no, ms_class, 0);
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100410 OSMO_ASSERT(ul_tbf);
Jacob Erlbeck767193e2015-05-20 12:06:46 +0200411 ul_tbf->update_ms(0x23, GPRS_RLCMAC_UL_TBF);
Daniel Willmann7e994e32014-08-07 15:49:21 +0200412 ul_tbf->m_contention_resolution_done = 1;
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100413
414 OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
415
416 /* now update the dl_tbf */
417 dl_tbf->update();
418 OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts);
419
Jacob Erlbeckbefc7602015-06-02 12:33:30 +0200420 OSMO_ASSERT(ul_tbf->ms_class() == ms_class);
421 OSMO_ASSERT(dl_tbf->ms_class() == ms_class);
422
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200423 check_tfi_usage(&the_bts);
424
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100425 tbf_free(dl_tbf);
426 tbf_free(ul_tbf);
427 }
428}
429
430static void test_all_alloc_b()
431{
432 /* it is a bit crazy... */
433 for (uint8_t ts0 = 0; ts0 < 2; ++ts0)
434 for (uint8_t ts1 = 0; ts1 < 2; ++ts1)
435 for (uint8_t ts2 = 0; ts2 < 2; ++ts2)
436 for (uint8_t ts3 = 0; ts3 < 2; ++ts3)
437 for (uint8_t ts4 = 0; ts4 < 2; ++ts4)
438 for (uint8_t ts5 = 0; ts5 < 2; ++ts5)
439 for (uint8_t ts6 = 0; ts6 < 2; ++ts6)
440 for (uint8_t ts7 = 0; ts7 < 2; ++ts7)
441 for (int ms_class = 0; ms_class < 30; ++ms_class)
442 test_alloc_b(ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7, ms_class);
443}
444
Holger Hans Peter Freytherc7b998c2013-12-25 19:25:10 +0100445static void test_alloc_b()
446{
447 for (int i = 0; i < 30; ++i)
448 test_alloc_b(i);
Holger Hans Peter Freytherf3eec042013-12-26 10:19:18 +0100449
450 test_all_alloc_b();
Holger Hans Peter Freytherc7b998c2013-12-25 19:25:10 +0100451}
452
Jacob Erlbecke5655642015-06-29 12:19:52 +0200453typedef int (*algo_t)(struct gprs_rlcmac_bts *bts,
454 struct GprsMs *ms,
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200455 struct gprs_rlcmac_tbf *tbf, uint32_t cust, uint8_t single,
456 int use_trx);
Jacob Erlbecke5655642015-06-29 12:19:52 +0200457
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200458static char get_dir_char(uint8_t mask, uint8_t tx, uint8_t rx, uint8_t busy)
Jacob Erlbecke5655642015-06-29 12:19:52 +0200459{
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200460 int offs = busy ? 32 : 0;
461 return (mask & tx & rx) ? 'C' + offs :
462 (mask & tx) ? 'U' + offs :
463 (mask & rx) ? 'D' + offs :
Jacob Erlbecke5655642015-06-29 12:19:52 +0200464 '.';
465}
466
467enum test_mode {
468 TEST_MODE_UL_ONLY,
469 TEST_MODE_DL_ONLY,
470 TEST_MODE_UL_AND_DL,
471 TEST_MODE_DL_AND_UL,
472 TEST_MODE_DL_AFTER_UL,
473 TEST_MODE_UL_AFTER_DL,
474};
475
476static GprsMs *alloc_tbfs(BTS *the_bts, GprsMs *ms, unsigned ms_class,
477 enum test_mode mode)
478{
479 struct gprs_rlcmac_bts *bts;
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200480 uint8_t trx_no = -1;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200481
482 bts = the_bts->bts_data();
483
484 gprs_rlcmac_tbf *tbf = NULL;
485
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200486 if (ms && ms->current_trx())
487 trx_no = ms->current_trx()->trx_no;
488
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200489 GprsMs::Guard guard1(ms);
490
Jacob Erlbecke5655642015-06-29 12:19:52 +0200491 /* Allocate what is needed first */
492 switch (mode) {
493 case TEST_MODE_UL_ONLY:
494 case TEST_MODE_DL_AFTER_UL:
495 case TEST_MODE_UL_AND_DL:
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200496 if (ms && ms->ul_tbf())
497 tbf_free(ms->ul_tbf());
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200498 tbf = tbf_alloc_ul_tbf(bts, ms, trx_no, ms_class, 0);
Jacob Erlbecke5655642015-06-29 12:19:52 +0200499 if (tbf == NULL)
500 return NULL;
501 break;
502 case TEST_MODE_DL_ONLY:
503 case TEST_MODE_UL_AFTER_DL:
504 case TEST_MODE_DL_AND_UL:
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200505 if (ms && ms->dl_tbf())
506 tbf_free(ms->dl_tbf());
Jacob Erlbeck5879c642015-07-10 10:41:36 +0200507 tbf = tbf_alloc_dl_tbf(bts, ms, trx_no, ms_class, 0);
Jacob Erlbecke5655642015-06-29 12:19:52 +0200508 if (tbf == NULL)
509 return NULL;
510 }
511
512 OSMO_ASSERT(tbf);
513 OSMO_ASSERT(tbf->ms());
514 OSMO_ASSERT(ms == NULL || ms == tbf->ms());
515 ms = tbf->ms();
516
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200517 GprsMs::Guard guard2(ms);
Jacob Erlbecke5655642015-06-29 12:19:52 +0200518
Jacob Erlbeck14376a72015-07-07 11:31:28 +0200519 /* Continue with what is needed next */
520 switch (mode) {
521 case TEST_MODE_UL_ONLY:
522 case TEST_MODE_DL_ONLY:
523 /* We are done */
524 break;
525
526 case TEST_MODE_DL_AFTER_UL:
527 case TEST_MODE_UL_AND_DL:
528 ms = alloc_tbfs(the_bts, ms, ms_class, TEST_MODE_DL_ONLY);
529 break;
530
531 case TEST_MODE_UL_AFTER_DL:
532 case TEST_MODE_DL_AND_UL:
533 ms = alloc_tbfs(the_bts, ms, ms_class, TEST_MODE_UL_ONLY);
534 break;
535 }
536
Jacob Erlbecke5655642015-06-29 12:19:52 +0200537 /* Optionally delete the TBF */
538 switch (mode) {
539 case TEST_MODE_DL_AFTER_UL:
540 case TEST_MODE_UL_AFTER_DL:
541 tbf_free(tbf);
Jacob Erlbeck0f352a62015-07-16 18:23:33 +0200542 tbf = NULL;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200543 break;
544
545 default:
546 break;
547 }
548
Jacob Erlbeck0f352a62015-07-16 18:23:33 +0200549 if (!ms && tbf)
550 tbf_free(tbf);
551
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200552 return guard2.is_idle() ? NULL : ms;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200553}
554
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200555static unsigned alloc_many_tbfs(BTS *the_bts, unsigned min_class,
556 unsigned max_class, enum test_mode mode)
Jacob Erlbecke5655642015-06-29 12:19:52 +0200557{
Jacob Erlbecke5655642015-06-29 12:19:52 +0200558 unsigned counter;
559 unsigned ms_class = min_class;
560
Jacob Erlbecke5655642015-06-29 12:19:52 +0200561 for (counter = 0; 1; counter += 1) {
562 gprs_rlcmac_tbf *ul_tbf, *dl_tbf;
563 uint8_t ul_slots = 0;
564 uint8_t dl_slots = 0;
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200565 uint8_t busy_slots = 0;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200566 unsigned i;
567 int tfi = -1;
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200568 int tfi2;
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200569 uint8_t trx_no2;
570 struct gprs_rlcmac_trx *trx;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200571 GprsMs *ms;
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200572 enum gprs_rlcmac_tbf_direction dir;
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200573 uint32_t tlli = counter + 0xc0000000;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200574
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200575 ms = the_bts->ms_by_tlli(tlli);
576
577 ms = alloc_tbfs(the_bts, ms, ms_class, mode);
Jacob Erlbecke5655642015-06-29 12:19:52 +0200578 if (!ms)
579 break;
580
Jacob Erlbeck69c9bfa2015-07-13 14:38:18 +0200581 ms->set_tlli(tlli);
582
Jacob Erlbecke5655642015-06-29 12:19:52 +0200583 ul_tbf = ms->ul_tbf();
584 dl_tbf = ms->dl_tbf();
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200585 trx = ms->current_trx();
586
587 OSMO_ASSERT(ul_tbf || dl_tbf);
Jacob Erlbecke5655642015-06-29 12:19:52 +0200588
589 if (ul_tbf) {
590 ul_slots = 1 << ul_tbf->first_common_ts;
591 tfi = ul_tbf->tfi();
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200592 dir = GPRS_RLCMAC_UL_TBF;
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200593 } else {
Jacob Erlbecke5655642015-06-29 12:19:52 +0200594 ul_slots = 1 << dl_tbf->first_common_ts;
595 tfi = dl_tbf->tfi();
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200596 dir = GPRS_RLCMAC_DL_TBF;
Jacob Erlbecke5655642015-06-29 12:19:52 +0200597 }
598
599 for (i = 0; dl_tbf && i < ARRAY_SIZE(dl_tbf->pdch); i += 1)
600 if (dl_tbf->pdch[i])
601 dl_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 &&
610 pdch->assigned_tfi(GPRS_RLCMAC_DL_TBF) != 0xffffffff)
611 continue;
612
613 if (dl_tbf &&
614 pdch->assigned_tfi(GPRS_RLCMAC_UL_TBF) != 0xffffffff)
615 continue;
616
617 busy_slots |= 1 << i;
618 }
619
Jacob Erlbecke5655642015-06-29 12:19:52 +0200620 printf(" TBF[%d] class %d reserves %c%c%c%c%c%c%c%c\n",
621 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) {
632 OSMO_ASSERT(ms->current_trx());
Jacob Erlbeckbf904222015-07-16 18:19:09 +0200633 tfi2 = the_bts->tfi_find_free(dir, &trx_no2,
Jacob Erlbeck61205a72015-07-09 11:35:50 +0200634 ms->current_trx()->trx_no);
635 OSMO_ASSERT(tfi != tfi2);
Jacob Erlbeck7b3675b2015-07-16 18:28:22 +0200636 OSMO_ASSERT(tfi2 < 0 ||
637 trx_no2 == ms->current_trx()->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{
652 BTS the_bts;
653 struct gprs_rlcmac_bts *bts;
654 struct gprs_rlcmac_trx *trx;
655 unsigned counter;
656
657 printf("Going to test assignment with many TBF, %s\n", text);
658
659 bts = the_bts.bts_data();
660 bts->alloc_algorithm = algo;
661
662 trx = &bts->trx[0];
663 trx->pdch[3].enable();
664 trx->pdch[4].enable();
665 trx->pdch[5].enable();
666 trx->pdch[6].enable();
667 trx->pdch[7].enable();
668
669 counter = alloc_many_tbfs(&the_bts, min_class, max_class, mode);
670
Jacob Erlbecke5655642015-06-29 12:19:52 +0200671 printf(" Successfully allocated %d UL TBFs\n", counter);
Jacob Erlbeck88fb6132015-07-16 15:01:38 +0200672 if (counter != expect_num)
673 fprintf(stderr, " Expected %d TBFs for %s\n", expect_num, text);
674
Jacob Erlbeckec478752015-06-19 16:35:38 +0200675 OSMO_ASSERT(counter == expect_num);
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200676
677 check_tfi_usage(&the_bts);
Jacob Erlbecke5655642015-06-29 12:19:52 +0200678}
679
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200680static void test_many_connections(algo_t algo, unsigned expect_num,
681 const char *text)
682{
683 BTS the_bts;
684 struct gprs_rlcmac_bts *bts;
685 struct gprs_rlcmac_trx *trx;
686 int counter1, counter2 = -1;
687 unsigned i;
688 enum test_mode mode_seq[] = {
689 TEST_MODE_DL_AFTER_UL,
690 TEST_MODE_UL_ONLY,
691 TEST_MODE_DL_AFTER_UL,
692 TEST_MODE_DL_ONLY,
693 };
694
695 printf("Going to test assignment with many connections, %s\n", text);
696
697 bts = the_bts.bts_data();
698 bts->alloc_algorithm = algo;
699
700 trx = &bts->trx[0];
701 trx->pdch[3].enable();
702 trx->pdch[4].enable();
703 trx->pdch[5].enable();
704 trx->pdch[6].enable();
705 trx->pdch[7].enable();
706
707 for (i = 0; i < ARRAY_SIZE(mode_seq); i += 1) {
708 counter1 = alloc_many_tbfs(&the_bts, 1, 29, mode_seq[i]);
709 fprintf(stderr, " Allocated %d TBFs (previously %d)\n",
710 counter1, counter2);
711
712 check_tfi_usage(&the_bts);
713
714 /* This will stop earlier due to USF shortage */
715 if (mode_seq[i] == TEST_MODE_UL_ONLY)
716 continue;
717
Jacob Erlbeck88fb6132015-07-16 15:01:38 +0200718 if (counter2 >= 0) {
719 if (counter1 < counter2)
720 fprintf(stderr, " Expected %d >= %d in %s\n",
721 counter1, counter2, text);
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200722 OSMO_ASSERT(counter1 >= counter2);
Jacob Erlbeck88fb6132015-07-16 15:01:38 +0200723 }
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200724
725 counter2 = counter1;
726 }
727
728 printf(" Successfully allocated %d TBFs\n", counter1);
Jacob Erlbeck88fb6132015-07-16 15:01:38 +0200729 if (counter1 != (int)expect_num)
730 fprintf(stderr, " Expected %d TBFs for %s\n", expect_num, text);
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200731
732 OSMO_ASSERT(expect_num == (unsigned)counter1);
733}
734
Jacob Erlbecke5655642015-06-29 12:19:52 +0200735static void test_successive_allocation()
736{
737 test_successive_allocation(alloc_algorithm_a, 1, 1, TEST_MODE_UL_AND_DL,
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200738 35, "algorithm A (UL and DL)");
Jacob Erlbecke5655642015-06-29 12:19:52 +0200739 test_successive_allocation(alloc_algorithm_b, 10, 10, TEST_MODE_UL_AND_DL,
Jacob Erlbeck16c6ecc2015-06-30 13:40:18 +0200740 32, "algorithm B class 10 (UL and DL)");
Jacob Erlbecke5655642015-06-29 12:19:52 +0200741 test_successive_allocation(alloc_algorithm_b, 12, 12, TEST_MODE_UL_AND_DL,
Jacob Erlbeck16c6ecc2015-06-30 13:40:18 +0200742 32, "algorithm B class 12 (UL and DL)");
Jacob Erlbecke5655642015-06-29 12:19:52 +0200743 test_successive_allocation(alloc_algorithm_b, 1, 12, TEST_MODE_UL_AND_DL,
Jacob Erlbecked46afd2015-07-01 12:19:40 +0200744 32, "algorithm B class 1-12 (UL and DL)");
Jacob Erlbecke5655642015-06-29 12:19:52 +0200745 test_successive_allocation(alloc_algorithm_b, 1, 29, TEST_MODE_UL_AND_DL,
Jacob Erlbeck16c6ecc2015-06-30 13:40:18 +0200746 32, "algorithm B class 1-29 (UL and DL)");
Jacob Erlbeck400ec022015-07-14 13:31:48 +0200747 test_successive_allocation(alloc_algorithm_dynamic, 1, 29, TEST_MODE_UL_AND_DL,
748 35, "algorithm dynamic class 1-29 (UL and DL)");
Jacob Erlbecke5655642015-06-29 12:19:52 +0200749
750 test_successive_allocation(alloc_algorithm_a, 1, 1, TEST_MODE_DL_AND_UL,
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200751 35, "algorithm A (DL and UL)");
Jacob Erlbecke5655642015-06-29 12:19:52 +0200752 test_successive_allocation(alloc_algorithm_b, 10, 10, TEST_MODE_DL_AND_UL,
Jacob Erlbeck16c6ecc2015-06-30 13:40:18 +0200753 32, "algorithm B class 10 (DL and UL)");
Jacob Erlbeck400ec022015-07-14 13:31:48 +0200754 test_successive_allocation(alloc_algorithm_dynamic, 10, 10, TEST_MODE_DL_AND_UL,
755 32, "algorithm dynamic class 10 (DL and UL)");
Jacob Erlbecke5655642015-06-29 12:19:52 +0200756
757 test_successive_allocation(alloc_algorithm_a, 1, 1, TEST_MODE_DL_AFTER_UL,
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200758 160, "algorithm A (DL after UL)");
Jacob Erlbecke5655642015-06-29 12:19:52 +0200759 test_successive_allocation(alloc_algorithm_b, 10, 10, TEST_MODE_DL_AFTER_UL,
Jacob Erlbeckec478752015-06-19 16:35:38 +0200760 32, "algorithm B class 10 (DL after UL)");
Jacob Erlbeck400ec022015-07-14 13:31:48 +0200761 test_successive_allocation(alloc_algorithm_dynamic, 10, 10, TEST_MODE_DL_AFTER_UL,
Jacob Erlbeck77da3552015-07-16 18:33:46 +0200762 95, "algorithm dynamic class 10 (DL after UL)");
Jacob Erlbecke5655642015-06-29 12:19:52 +0200763
764 test_successive_allocation(alloc_algorithm_a, 1, 1, TEST_MODE_UL_AFTER_DL,
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200765 35, "algorithm A (UL after DL)");
Jacob Erlbecke5655642015-06-29 12:19:52 +0200766 test_successive_allocation(alloc_algorithm_b, 10, 10, TEST_MODE_UL_AFTER_DL,
Jacob Erlbeck16c6ecc2015-06-30 13:40:18 +0200767 32, "algorithm B class 10 (UL after DL)");
Jacob Erlbeck400ec022015-07-14 13:31:48 +0200768 test_successive_allocation(alloc_algorithm_dynamic, 10, 10, TEST_MODE_UL_AFTER_DL,
769 35, "algorithm dynamic class 10 (UL after DL)");
Jacob Erlbecke5655642015-06-29 12:19:52 +0200770
771 test_successive_allocation(alloc_algorithm_a, 1, 1, TEST_MODE_UL_ONLY,
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200772 35, "algorithm A (UL only)");
Jacob Erlbecke5655642015-06-29 12:19:52 +0200773 test_successive_allocation(alloc_algorithm_b, 10, 10, TEST_MODE_UL_ONLY,
Jacob Erlbeck16c6ecc2015-06-30 13:40:18 +0200774 32, "algorithm B class 10 (UL only)");
Jacob Erlbeck400ec022015-07-14 13:31:48 +0200775 test_successive_allocation(alloc_algorithm_dynamic, 10, 10, TEST_MODE_UL_ONLY,
776 35, "algorithm dynamic class 10 (UL only)");
Jacob Erlbecke5655642015-06-29 12:19:52 +0200777
778 test_successive_allocation(alloc_algorithm_a, 1, 1, TEST_MODE_DL_ONLY,
Jacob Erlbecke0853cd2015-07-10 12:25:25 +0200779 160, "algorithm A (DL ONLY)");
Jacob Erlbecke5655642015-06-29 12:19:52 +0200780 test_successive_allocation(alloc_algorithm_b, 10, 10, TEST_MODE_DL_ONLY,
Jacob Erlbeckec478752015-06-19 16:35:38 +0200781 32, "algorithm B class 10 (DL ONLY)");
Jacob Erlbeck400ec022015-07-14 13:31:48 +0200782 test_successive_allocation(alloc_algorithm_dynamic, 10, 10, TEST_MODE_DL_ONLY,
783 101, "algorithm dynamic class 10 (DL ONLY)");
Jacob Erlbecke5655642015-06-29 12:19:52 +0200784}
785
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200786static void test_many_connections()
787{
788 test_many_connections(alloc_algorithm_a, 160, "algorithm A");
789 test_many_connections(alloc_algorithm_b, 32, "algorithm B");
Jacob Erlbeck77da3552015-07-16 18:33:46 +0200790 test_many_connections(alloc_algorithm_dynamic, 160, "algorithm dynamic");
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200791}
792
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200793int main(int argc, char **argv)
794{
795 tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile AllocTest context");
796 if (!tall_pcu_ctx)
797 abort();
798
799 msgb_set_talloc_ctx(tall_pcu_ctx);
800 osmo_init_logging(&gprs_log_info);
801 log_set_use_color(osmo_stderr_target, 0);
802 log_set_print_filename(osmo_stderr_target, 0);
Jacob Erlbeck9ec49e22015-06-29 13:00:20 +0200803 if (getenv("LOGL_DEBUG"))
804 log_set_log_level(osmo_stderr_target, LOGL_DEBUG);
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200805
806 test_alloc_a();
Holger Hans Peter Freyther4af30532013-12-25 19:16:55 +0100807 test_alloc_b();
Jacob Erlbecke5655642015-06-29 12:19:52 +0200808 test_successive_allocation();
Jacob Erlbecka8c2aaf2015-07-13 14:50:08 +0200809 test_many_connections();
Holger Hans Peter Freytherbfdd5f22013-10-16 17:29:31 +0200810 return EXIT_SUCCESS;
811}
812
813/*
814 * stubs that should not be reached
815 */
816extern "C" {
817void l1if_pdch_req() { abort(); }
818void l1if_connect_pdch() { abort(); }
819void l1if_close_pdch() { abort(); }
820void l1if_open_pdch() { abort(); }
821}