Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 1 | /* 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. |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include "gprs_rlcmac.h" |
| 17 | #include "gprs_debug.h" |
| 18 | #include "tbf.h" |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 19 | #include "tbf_ul.h" |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 20 | #include "tbf_dl.h" |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 21 | #include "bts.h" |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 22 | #include "gprs_ms.h" |
Oliver Smith | 3f79470 | 2021-08-23 14:19:21 +0200 | [diff] [blame] | 23 | #include "bts_pch_timer.h" |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 24 | |
| 25 | #include <string.h> |
| 26 | #include <stdio.h> |
| 27 | |
| 28 | extern "C" { |
Max | 9f46071 | 2018-01-23 20:57:08 +0100 | [diff] [blame] | 29 | #include "mslot_class.h" |
Pau Espin Pedrol | ff7c581 | 2022-12-14 18:49:06 +0100 | [diff] [blame] | 30 | #include "alloc_algo.h" |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 31 | #include <osmocom/core/application.h> |
| 32 | #include <osmocom/core/msgb.h> |
| 33 | #include <osmocom/core/talloc.h> |
| 34 | #include <osmocom/core/utils.h> |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 35 | #include <osmocom/core/fsm.h> |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | /* globals used by the code */ |
| 39 | void *tall_pcu_ctx; |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 40 | int16_t spoof_mnc = 0, spoof_mcc = 0; |
Neels Hofmeyr | bdc55fa | 2018-02-21 00:39:07 +0100 | [diff] [blame] | 41 | bool spoof_mnc_3_digits = false; |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 42 | |
Pau Espin Pedrol | 4d36391 | 2023-04-21 19:32:16 +0200 | [diff] [blame] | 43 | /* override, requires '-Wl,--wrap=pcu_sock_send' */ |
| 44 | int __real_pcu_sock_send(struct msgb *msg); |
| 45 | extern "C" int __wrap_pcu_sock_send(struct msgb *msg) |
| 46 | { |
| 47 | return 0; |
| 48 | } |
| 49 | |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 50 | static gprs_rlcmac_tbf *tbf_alloc(struct gprs_rlcmac_bts *bts, |
Jacob Erlbeck | e2e004e | 2015-06-18 17:16:26 +0200 | [diff] [blame] | 51 | GprsMs *ms, gprs_rlcmac_tbf_direction dir, |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 52 | uint8_t use_trx, bool single_slot) |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 53 | { |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 54 | OSMO_ASSERT(ms != NULL); |
Pau Espin Pedrol | 17402a5 | 2020-05-08 17:44:33 +0200 | [diff] [blame] | 55 | |
Pau Espin Pedrol | 4d36391 | 2023-04-21 19:32:16 +0200 | [diff] [blame] | 56 | const struct alloc_resources_req req = { |
| 57 | .bts = bts, |
| 58 | .ms = ms, |
| 59 | .direction = dir, |
| 60 | .single = single_slot, |
| 61 | .use_trx = (int8_t)use_trx, |
| 62 | }; |
| 63 | struct alloc_resources_res res = {}; |
| 64 | int rc; |
| 65 | |
| 66 | rc = the_pcu->alloc_algorithm(&req, &res); |
| 67 | if (rc < 0) { |
| 68 | LOGPMS(ms, DTBF, LOGL_NOTICE, |
| 69 | "Timeslot Allocation failed: trx = %d, single_slot = %d\n", |
| 70 | req.use_trx, req.single); |
| 71 | bts_do_rate_ctr_inc(ms->bts, CTR_TBF_ALLOC_FAIL); |
| 72 | return NULL; |
| 73 | } |
| 74 | |
| 75 | /* Update MS, really allocate the resources */ |
| 76 | if (res.reserved_ul_slots != ms_reserved_ul_slots(ms) || |
| 77 | res.reserved_dl_slots != ms_reserved_dl_slots(ms)) { |
| 78 | /* The reserved slots have changed, update the MS */ |
| 79 | ms_set_reserved_slots(ms, res.trx, res.reserved_ul_slots, res.reserved_dl_slots); |
| 80 | } |
| 81 | ms_set_first_common_ts(ms, res.first_common_ts); |
| 82 | |
| 83 | if (dir == GPRS_RLCMAC_UL_TBF) { |
| 84 | struct gprs_rlcmac_ul_tbf *ul_tbf; |
| 85 | ul_tbf = ul_tbf_alloc(bts, ms); |
| 86 | ul_tbf_apply_allocated_resources(ul_tbf, &res); |
| 87 | ms_attach_tbf(ms, ul_tbf_as_tbf(ul_tbf)); |
| 88 | return ul_tbf; |
| 89 | } else { |
| 90 | struct gprs_rlcmac_dl_tbf *dl_tbf; |
| 91 | dl_tbf = dl_tbf_alloc(bts, ms); |
| 92 | dl_tbf_apply_allocated_resources(dl_tbf, &res); |
| 93 | ms_attach_tbf(ms, dl_tbf_as_tbf(dl_tbf)); |
| 94 | return dl_tbf; |
| 95 | } |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 96 | } |
| 97 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 98 | static void check_tfi_usage(struct gprs_rlcmac_bts *bts) |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 99 | { |
| 100 | int pdch_no; |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 101 | |
| 102 | struct gprs_rlcmac_tbf *tfi_usage[8][8][2][32] = {{{{NULL}}}}; |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 103 | struct llist_head *tbf_lists[2] = { |
Pau Espin Pedrol | 1a1557a | 2021-05-13 18:39:36 +0200 | [diff] [blame] | 104 | &bts->trx[0].ul_tbfs, |
| 105 | &bts->trx[0].dl_tbfs |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 106 | }; |
| 107 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 108 | struct llist_item *pos; |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 109 | gprs_rlcmac_tbf *tbf; |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 110 | unsigned list_idx; |
| 111 | struct gprs_rlcmac_tbf **tbf_var; |
| 112 | |
| 113 | for (list_idx = 0; list_idx < ARRAY_SIZE(tbf_lists); list_idx += 1) |
| 114 | { |
| 115 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 116 | llist_for_each_entry(pos, tbf_lists[list_idx], list) { |
| 117 | tbf = (struct gprs_rlcmac_tbf *)pos->entry; |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 118 | for (pdch_no = 0; pdch_no < 8; pdch_no += 1) { |
| 119 | struct gprs_rlcmac_pdch *pdch = tbf->pdch[pdch_no]; |
| 120 | if (pdch == NULL) |
| 121 | continue; |
| 122 | |
| 123 | tbf_var = &tfi_usage |
| 124 | [tbf->trx->trx_no] |
| 125 | [pdch_no] |
| 126 | [tbf->direction] |
| 127 | [tbf->tfi()]; |
| 128 | |
| 129 | OSMO_ASSERT(*tbf_var == NULL); |
| 130 | if (tbf->direction == GPRS_RLCMAC_DL_TBF) { |
| 131 | OSMO_ASSERT(pdch->dl_tbf_by_tfi( |
| 132 | tbf->tfi()) == tbf); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 133 | OSMO_ASSERT(bts_dl_tbf_by_tfi(bts, |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 134 | tbf->tfi(), |
Jacob Erlbeck | 3a10dbd | 2015-07-10 19:52:37 +0200 | [diff] [blame] | 135 | tbf->trx->trx_no, |
| 136 | pdch_no) == tbf); |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 137 | } else { |
| 138 | OSMO_ASSERT(pdch->ul_tbf_by_tfi( |
| 139 | tbf->tfi()) == tbf); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 140 | OSMO_ASSERT(bts_ul_tbf_by_tfi(bts, |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 141 | tbf->tfi(), |
Jacob Erlbeck | 3a10dbd | 2015-07-10 19:52:37 +0200 | [diff] [blame] | 142 | tbf->trx->trx_no, |
| 143 | pdch_no) == tbf); |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 144 | } |
| 145 | *tbf_var = tbf; |
Jacob Erlbeck | 47a57f6 | 2015-07-08 12:53:16 +0200 | [diff] [blame] | 146 | OSMO_ASSERT(pdch->assigned_tfi(tbf->direction) & |
| 147 | (1 << tbf->tfi())); |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | |
Jacob Erlbeck | fa464bb | 2015-06-29 12:45:11 +0200 | [diff] [blame] | 153 | static void test_alloc_a(gprs_rlcmac_tbf_direction dir, |
| 154 | uint8_t slots, const int count) |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 155 | { |
| 156 | int tfi; |
Jacob Erlbeck | fa464bb | 2015-06-29 12:45:11 +0200 | [diff] [blame] | 157 | int i; |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 158 | uint8_t used_trx, tmp_trx; |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 159 | struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0); |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 160 | GprsMs *ms; |
Jacob Erlbeck | e0853cd | 2015-07-10 12:25:25 +0200 | [diff] [blame] | 161 | struct gprs_rlcmac_tbf *tbfs[32*8+1] = { 0, }; |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 162 | |
| 163 | printf("Testing alloc_a direction(%d)\n", dir); |
| 164 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 165 | the_pcu->alloc_algorithm = alloc_algorithm_a; |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 166 | |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 167 | struct gprs_rlcmac_trx *trx = &bts->trx[0]; |
Jacob Erlbeck | fa464bb | 2015-06-29 12:45:11 +0200 | [diff] [blame] | 168 | for (i = 0; i < 8; i += 1) |
| 169 | if (slots & (1 << i)) |
| 170 | trx->pdch[i].enable(); |
| 171 | |
| 172 | OSMO_ASSERT(count >= 0 && count <= (int)ARRAY_SIZE(tbfs)); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 173 | |
| 174 | /** |
| 175 | * Currently alloc_a will only allocate from the first |
| 176 | * PDCH and all possible usf's. We run out of usf's before |
| 177 | * we are out of tfi's. Observe this and make sure that at |
| 178 | * least this part is working okay. |
| 179 | */ |
Jacob Erlbeck | e0853cd | 2015-07-10 12:25:25 +0200 | [diff] [blame] | 180 | for (i = 0; i < (int)ARRAY_SIZE(tbfs); ++i) { |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 181 | ms = ms_alloc(bts, __func__); |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 182 | tbfs[i] = tbf_alloc(bts, ms, dir, -1, 0); |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 183 | ms_unref(ms, __func__); |
Jacob Erlbeck | e0853cd | 2015-07-10 12:25:25 +0200 | [diff] [blame] | 184 | if (tbfs[i] == NULL) |
| 185 | break; |
| 186 | |
| 187 | used_trx = tbfs[i]->trx->trx_no; |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 188 | tfi = bts_tfi_find_free(bts, dir, &tmp_trx, used_trx); |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 189 | OSMO_ASSERT(tbfs[i]->tfi() != tfi); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 190 | } |
| 191 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 192 | check_tfi_usage(bts); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 193 | |
Jacob Erlbeck | e0853cd | 2015-07-10 12:25:25 +0200 | [diff] [blame] | 194 | OSMO_ASSERT(i == count); |
| 195 | |
Pau Espin Pedrol | 0dcbc07 | 2021-11-10 19:09:10 +0100 | [diff] [blame] | 196 | OSMO_ASSERT(bts_all_pdch_allocated(bts)); |
| 197 | |
Jacob Erlbeck | e0853cd | 2015-07-10 12:25:25 +0200 | [diff] [blame] | 198 | for (i = 0; i < count; ++i) |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 199 | if (tbfs[i]) |
| 200 | tbf_free(tbfs[i]); |
| 201 | |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 202 | ms = ms_alloc(bts, NULL); |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 203 | tbfs[0] = tbf_alloc(bts, ms, dir, -1, 0); |
Holger Hans Peter Freyther | f3f1bde | 2016-02-22 15:14:01 +0100 | [diff] [blame] | 204 | OSMO_ASSERT(tbfs[0]); |
| 205 | tbf_free(tbfs[0]); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 206 | talloc_free(bts); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | static void test_alloc_a() |
| 210 | { |
Jacob Erlbeck | fa464bb | 2015-06-29 12:45:11 +0200 | [diff] [blame] | 211 | /* slots 2 - 3 */ |
Jacob Erlbeck | e0853cd | 2015-07-10 12:25:25 +0200 | [diff] [blame] | 212 | test_alloc_a(GPRS_RLCMAC_DL_TBF, 0x0c, 32*2); |
Jacob Erlbeck | ec47875 | 2015-06-19 16:35:38 +0200 | [diff] [blame] | 213 | test_alloc_a(GPRS_RLCMAC_UL_TBF, 0x0c, 14); |
Jacob Erlbeck | fa464bb | 2015-06-29 12:45:11 +0200 | [diff] [blame] | 214 | |
| 215 | /* slots 1 - 5 */ |
Jacob Erlbeck | e0853cd | 2015-07-10 12:25:25 +0200 | [diff] [blame] | 216 | test_alloc_a(GPRS_RLCMAC_DL_TBF, 0x1e, 32*4); |
Jacob Erlbeck | ec47875 | 2015-06-19 16:35:38 +0200 | [diff] [blame] | 217 | test_alloc_a(GPRS_RLCMAC_UL_TBF, 0x1e, 28); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 218 | } |
| 219 | |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 220 | static void dump_assignment(struct gprs_rlcmac_tbf *tbf, const char *dir, bool verbose) |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 221 | { |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 222 | if (!verbose) |
| 223 | return; |
Pau Espin Pedrol | 345d9ad | 2022-12-12 19:22:44 +0100 | [diff] [blame] | 224 | const struct GprsMs *ms = tbf_ms(tbf); |
Pau Espin Pedrol | 9935d0d | 2022-12-13 18:29:25 +0100 | [diff] [blame] | 225 | const struct gprs_rlcmac_pdch *first_common = ms_first_common_ts(ms); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 226 | |
Jacob Erlbeck | 1f33294 | 2015-05-04 08:21:17 +0200 | [diff] [blame] | 227 | for (size_t i = 0; i < ARRAY_SIZE(tbf->pdch); ++i) |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 228 | if (tbf->pdch[i]) |
Neels Hofmeyr | d34646a | 2017-02-08 17:07:40 +0100 | [diff] [blame] | 229 | printf("PDCH[%zu] is used for %s\n", i, dir); |
Pau Espin Pedrol | e2ed40d | 2022-12-15 17:35:05 +0100 | [diff] [blame] | 230 | printf("%s is control_ts for %s\n", tbf->control_ts ? pdch_name(tbf->control_ts) : "(none)", dir); |
| 231 | printf("%s is first common for %s\n", first_common ? pdch_name(first_common) : "(none)", dir); |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 232 | } |
| 233 | |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 234 | #define ENABLE_PDCH(ts_no, enable_flag, trx) \ |
| 235 | if (enable_flag) \ |
| 236 | trx->pdch[ts_no].enable(); |
| 237 | |
| 238 | static inline void enable_ts_on_bts(struct gprs_rlcmac_bts *bts, |
| 239 | bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7) |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 240 | { |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 241 | struct gprs_rlcmac_trx *trx = &bts->trx[0]; |
| 242 | |
| 243 | ENABLE_PDCH(0, ts0, trx); |
| 244 | ENABLE_PDCH(1, ts1, trx); |
| 245 | ENABLE_PDCH(2, ts2, trx); |
| 246 | ENABLE_PDCH(3, ts3, trx); |
| 247 | ENABLE_PDCH(4, ts4, trx); |
| 248 | ENABLE_PDCH(5, ts5, trx); |
| 249 | ENABLE_PDCH(6, ts6, trx); |
| 250 | ENABLE_PDCH(7, ts7, trx); |
| 251 | } |
| 252 | |
| 253 | static inline bool test_alloc_b_ul_dl(bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7, |
| 254 | uint8_t ms_class, bool verbose) |
| 255 | { |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 256 | struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0); |
Pau Espin Pedrol | 17402a5 | 2020-05-08 17:44:33 +0200 | [diff] [blame] | 257 | GprsMs *ms; |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 258 | gprs_rlcmac_ul_tbf *ul_tbf; |
| 259 | gprs_rlcmac_dl_tbf *dl_tbf; |
| 260 | |
| 261 | if (verbose) |
| 262 | printf("Testing UL then DL assignment.\n"); |
| 263 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 264 | the_pcu->alloc_algorithm = alloc_algorithm_b; |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 265 | |
| 266 | enable_ts_on_bts(bts, ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7); |
| 267 | |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 268 | ms = ms_alloc(bts, __func__); |
Pau Espin Pedrol | bfc9756 | 2023-04-17 14:49:29 +0200 | [diff] [blame] | 269 | ms_set_ms_class(ms, ms_class); |
Pau Espin Pedrol | 1e00947 | 2021-01-11 20:40:19 +0100 | [diff] [blame] | 270 | /* Avoid delaying free to avoid tons of to-be-freed ms objects queuing */ |
Pau Espin Pedrol | b53230a | 2023-04-20 16:42:54 +0200 | [diff] [blame] | 271 | OSMO_ASSERT(osmo_tdef_set(the_pcu->T_defs, -2030, 0, OSMO_TDEF_S) == 0); |
Pau Espin Pedrol | 4d36391 | 2023-04-21 19:32:16 +0200 | [diff] [blame] | 272 | ul_tbf = (gprs_rlcmac_ul_tbf *)tbf_alloc(bts, ms, GPRS_RLCMAC_UL_TBF, -1, true); |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 273 | if (!ul_tbf) { |
| 274 | ms_unref(ms, __func__); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 275 | return false; |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 276 | } |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 277 | |
| 278 | OSMO_ASSERT(ul_tbf->ms()); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 279 | OSMO_ASSERT(ms_current_trx(ul_tbf->ms())); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 280 | |
| 281 | dump_assignment(ul_tbf, "UL", verbose); |
| 282 | |
| 283 | /* assume final ack has not been sent */ |
Pau Espin Pedrol | 4d36391 | 2023-04-21 19:32:16 +0200 | [diff] [blame] | 284 | dl_tbf = (gprs_rlcmac_dl_tbf *)tbf_alloc(bts, ms, GPRS_RLCMAC_DL_TBF, ms_current_trx(ms)->trx_no, false); |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 285 | if (!dl_tbf) { |
| 286 | ms_unref(ms, __func__); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 287 | return false; |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 288 | } |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 289 | |
| 290 | dump_assignment(dl_tbf, "DL", verbose); |
| 291 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 292 | check_tfi_usage(bts); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 293 | |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 294 | ms_unref(ms, __func__); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 295 | tbf_free(dl_tbf); |
| 296 | tbf_free(ul_tbf); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 297 | talloc_free(bts); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 298 | return true; |
| 299 | } |
| 300 | |
| 301 | static inline bool test_alloc_b_dl_ul(bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7, |
| 302 | uint8_t ms_class, bool verbose) |
| 303 | { |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 304 | struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0); |
Pau Espin Pedrol | 17402a5 | 2020-05-08 17:44:33 +0200 | [diff] [blame] | 305 | GprsMs *ms; |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 306 | gprs_rlcmac_ul_tbf *ul_tbf; |
| 307 | gprs_rlcmac_dl_tbf *dl_tbf; |
| 308 | |
| 309 | if (verbose) |
| 310 | printf("Testing DL then UL assignment followed by update\n"); |
| 311 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 312 | the_pcu->alloc_algorithm = alloc_algorithm_b; |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 313 | |
| 314 | enable_ts_on_bts(bts, ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7); |
| 315 | |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 316 | ms = ms_alloc(bts, __func__); |
Pau Espin Pedrol | bfc9756 | 2023-04-17 14:49:29 +0200 | [diff] [blame] | 317 | ms_set_ms_class(ms, ms_class); |
Pau Espin Pedrol | 1e00947 | 2021-01-11 20:40:19 +0100 | [diff] [blame] | 318 | /* Avoid delaying free to avoid tons of to-be-freed ms objects queuing */ |
Pau Espin Pedrol | b53230a | 2023-04-20 16:42:54 +0200 | [diff] [blame] | 319 | OSMO_ASSERT(osmo_tdef_set(the_pcu->T_defs, -2030, 0, OSMO_TDEF_S) == 0); |
Pau Espin Pedrol | 4d36391 | 2023-04-21 19:32:16 +0200 | [diff] [blame] | 320 | dl_tbf = (gprs_rlcmac_dl_tbf *)tbf_alloc(bts, ms, GPRS_RLCMAC_DL_TBF, -1, true); |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 321 | if (!dl_tbf) { |
| 322 | ms_unref(ms, __func__); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 323 | return false; |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 324 | } |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 325 | |
Pau Espin Pedrol | 8abe13c | 2022-10-21 18:49:48 +0200 | [diff] [blame] | 326 | ms_confirm_tlli(ms, 0x23); |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 327 | OSMO_ASSERT(dl_tbf->ms() == ms); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 328 | OSMO_ASSERT(ms_current_trx(dl_tbf->ms())); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 329 | |
| 330 | dump_assignment(dl_tbf, "DL", verbose); |
| 331 | |
Pau Espin Pedrol | 4d36391 | 2023-04-21 19:32:16 +0200 | [diff] [blame] | 332 | ul_tbf = (gprs_rlcmac_ul_tbf *)tbf_alloc(bts, ms, GPRS_RLCMAC_UL_TBF, ms_current_trx(ms)->trx_no, false); |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 333 | if (!ul_tbf) { |
| 334 | ms_unref(ms, __func__); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 335 | return false; |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 336 | } |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 337 | |
Pau Espin Pedrol | 8abe13c | 2022-10-21 18:49:48 +0200 | [diff] [blame] | 338 | ms_update_announced_tlli(ms, 0x23); |
Pau Espin Pedrol | 0f85956 | 2022-10-31 10:51:20 +0100 | [diff] [blame] | 339 | ul_tbf->m_contention_resolution_done = true; |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 340 | |
| 341 | dump_assignment(ul_tbf, "UL", verbose); |
| 342 | |
Pau Espin Pedrol | b7a2b59 | 2022-12-13 14:43:59 +0100 | [diff] [blame] | 343 | /* now upgrade the dl_tbf */ |
| 344 | OSMO_ASSERT(dl_tbf_upgrade_to_multislot(dl_tbf) == 0); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 345 | dump_assignment(dl_tbf, "DL", verbose); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 346 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 347 | check_tfi_usage(bts); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 348 | |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 349 | ms_unref(ms, __func__); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 350 | tbf_free(dl_tbf); |
| 351 | tbf_free(ul_tbf); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 352 | talloc_free(bts); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 353 | return true; |
| 354 | } |
| 355 | |
| 356 | static inline bool test_alloc_b_jolly(uint8_t ms_class) |
| 357 | { |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 358 | struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0); |
Pau Espin Pedrol | 17402a5 | 2020-05-08 17:44:33 +0200 | [diff] [blame] | 359 | GprsMs *ms; |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 360 | int tfi; |
| 361 | uint8_t trx_no; |
| 362 | gprs_rlcmac_tbf *ul_tbf, *dl_tbf; |
| 363 | |
| 364 | printf("Testing jolly example\n"); |
| 365 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 366 | the_pcu->alloc_algorithm = alloc_algorithm_b; |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 367 | |
| 368 | enable_ts_on_bts(bts, false, true, true, true, true, false, false, false); |
| 369 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 370 | tfi = bts_tfi_find_free(bts, GPRS_RLCMAC_UL_TBF, &trx_no, -1); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 371 | OSMO_ASSERT(tfi >= 0); |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 372 | ms = ms_alloc(bts, __func__); |
Pau Espin Pedrol | bfc9756 | 2023-04-17 14:49:29 +0200 | [diff] [blame] | 373 | ms_set_ms_class(ms, ms_class); |
Pau Espin Pedrol | 1e00947 | 2021-01-11 20:40:19 +0100 | [diff] [blame] | 374 | /* Avoid delaying free to avoid tons of to-be-freed ms objects queuing */ |
Pau Espin Pedrol | b53230a | 2023-04-20 16:42:54 +0200 | [diff] [blame] | 375 | OSMO_ASSERT(osmo_tdef_set(the_pcu->T_defs, -2030, 0, OSMO_TDEF_S) == 0); |
Pau Espin Pedrol | 4d36391 | 2023-04-21 19:32:16 +0200 | [diff] [blame] | 376 | ul_tbf = tbf_alloc(bts, ms, GPRS_RLCMAC_UL_TBF, -1, false); |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 377 | if (!ul_tbf) { |
| 378 | ms_unref(ms, __func__); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 379 | return false; |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 380 | } |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 381 | |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 382 | OSMO_ASSERT(ul_tbf->ms() == ms); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 383 | OSMO_ASSERT(ms_current_trx(ul_tbf->ms())); |
| 384 | trx_no = ms_current_trx(ms)->trx_no; |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 385 | dump_assignment(ul_tbf, "UL", true); |
| 386 | |
| 387 | /* assume final ack has not been sent */ |
Pau Espin Pedrol | 4d36391 | 2023-04-21 19:32:16 +0200 | [diff] [blame] | 388 | dl_tbf = tbf_alloc(bts, ms, GPRS_RLCMAC_DL_TBF, trx_no, false); |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 389 | if (!dl_tbf) { |
| 390 | ms_unref(ms, __func__); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 391 | return false; |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 392 | } |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 393 | |
| 394 | dump_assignment(dl_tbf, "DL", true); |
| 395 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 396 | check_tfi_usage(bts); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 397 | |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 398 | ms_unref(ms, __func__); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 399 | tbf_free(dl_tbf); |
| 400 | tbf_free(ul_tbf); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 401 | talloc_free(bts); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 402 | return true; |
| 403 | } |
| 404 | |
| 405 | static void test_alloc_b_for_ms(uint8_t ms_class) |
| 406 | { |
| 407 | bool rc; |
| 408 | |
Holger Hans Peter Freyther | c7b998c | 2013-12-25 19:25:10 +0100 | [diff] [blame] | 409 | printf("Going to test multislot assignment MS_CLASS=%d\n", ms_class); |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 410 | /* |
| 411 | * PDCH is on TS 6,7,8 and we start with a UL allocation and |
| 412 | * then follow two DL allocations (once single, once normal). |
| 413 | * |
| 414 | * Uplink assigned and still available.. |
| 415 | */ |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 416 | |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 417 | rc = test_alloc_b_ul_dl(false, false, false, false, false, true, true, true, ms_class, true); |
| 418 | if (!rc) |
| 419 | return; |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 420 | |
| 421 | /** |
| 422 | * Test with the other order.. first DL and then UL |
| 423 | */ |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 424 | rc = test_alloc_b_dl_ul(false, false, false, false, false, true, true, true, ms_class, true); |
| 425 | if (!rc) |
| 426 | return; |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 427 | |
| 428 | /* Andreas osmocom-pcu example */ |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 429 | test_alloc_b_jolly(ms_class); |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 430 | } |
| 431 | |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 432 | static 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 Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 433 | { |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 434 | bool rc; |
| 435 | |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 436 | /* we can test the allocation failures differently */ |
| 437 | if (!ts0 && !ts1 && !ts2 && !ts3 && !ts4 && !ts5 && !ts6 && !ts7) |
| 438 | return; |
| 439 | |
| 440 | printf("Mass test: TS0(%c%c%c%c%c%c%c%c)TS7 MS_Class=%d\n", |
| 441 | ts0 ? 'O' : 'x', |
| 442 | ts1 ? 'O' : 'x', |
| 443 | ts2 ? 'O' : 'x', |
| 444 | ts3 ? 'O' : 'x', |
| 445 | ts4 ? 'O' : 'x', |
| 446 | ts5 ? 'O' : 'x', |
| 447 | ts6 ? 'O' : 'x', |
| 448 | ts7 ? 'O' : 'x', ms_class); |
| 449 | fflush(stdout); |
| 450 | |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 451 | rc = test_alloc_b_ul_dl(ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7, ms_class, false); |
| 452 | if (!rc) |
| 453 | return; |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 454 | |
| 455 | /** |
| 456 | * Test with the other order.. first DL and then UL |
| 457 | */ |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 458 | test_alloc_b_dl_ul(ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7, ms_class, false); |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | static void test_all_alloc_b() |
| 462 | { |
| 463 | /* it is a bit crazy... */ |
| 464 | for (uint8_t ts0 = 0; ts0 < 2; ++ts0) |
| 465 | for (uint8_t ts1 = 0; ts1 < 2; ++ts1) |
| 466 | for (uint8_t ts2 = 0; ts2 < 2; ++ts2) |
| 467 | for (uint8_t ts3 = 0; ts3 < 2; ++ts3) |
| 468 | for (uint8_t ts4 = 0; ts4 < 2; ++ts4) |
| 469 | for (uint8_t ts5 = 0; ts5 < 2; ++ts5) |
| 470 | for (uint8_t ts6 = 0; ts6 < 2; ++ts6) |
| 471 | for (uint8_t ts7 = 0; ts7 < 2; ++ts7) |
Max | 9f46071 | 2018-01-23 20:57:08 +0100 | [diff] [blame] | 472 | for (int ms_class = 0; ms_class < mslot_class_max(); ++ms_class) |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 473 | test_alloc_mass(ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7, ms_class); |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 474 | } |
| 475 | |
Holger Hans Peter Freyther | c7b998c | 2013-12-25 19:25:10 +0100 | [diff] [blame] | 476 | static void test_alloc_b() |
| 477 | { |
Max | 9f46071 | 2018-01-23 20:57:08 +0100 | [diff] [blame] | 478 | for (int i = 0; i < mslot_class_max(); ++i) |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 479 | test_alloc_b_for_ms(i); |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 480 | |
| 481 | test_all_alloc_b(); |
Holger Hans Peter Freyther | c7b998c | 2013-12-25 19:25:10 +0100 | [diff] [blame] | 482 | } |
| 483 | |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 484 | static char get_dir_char(uint8_t mask, uint8_t tx, uint8_t rx, uint8_t busy) |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 485 | { |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 486 | int offs = busy ? 32 : 0; |
| 487 | return (mask & tx & rx) ? 'C' + offs : |
| 488 | (mask & tx) ? 'U' + offs : |
| 489 | (mask & rx) ? 'D' + offs : |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 490 | '.'; |
| 491 | } |
| 492 | |
| 493 | enum test_mode { |
| 494 | TEST_MODE_UL_ONLY, |
| 495 | TEST_MODE_DL_ONLY, |
| 496 | TEST_MODE_UL_AND_DL, |
| 497 | TEST_MODE_DL_AND_UL, |
| 498 | TEST_MODE_DL_AFTER_UL, |
| 499 | TEST_MODE_UL_AFTER_DL, |
| 500 | }; |
| 501 | |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 502 | static inline char *test_mode_descr(enum test_mode t) |
| 503 | { |
| 504 | switch (t) { |
| 505 | case TEST_MODE_UL_ONLY: return (char*)"UL only"; |
| 506 | case TEST_MODE_DL_ONLY: return (char*)"DL only"; |
| 507 | case TEST_MODE_UL_AND_DL: return (char*)"UL and DL"; |
| 508 | case TEST_MODE_DL_AND_UL: return (char*)"DL and UL"; |
| 509 | case TEST_MODE_DL_AFTER_UL: return (char*)"DL after UL"; |
| 510 | case TEST_MODE_UL_AFTER_DL: return (char*)"UL after DL"; |
| 511 | default: return NULL; |
| 512 | } |
| 513 | } |
| 514 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 515 | static GprsMs *alloc_tbfs(struct gprs_rlcmac_bts *bts, struct GprsMs *old_ms, enum test_mode mode) |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 516 | { |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 517 | struct GprsMs *ms, *new_ms; |
Jacob Erlbeck | 5879c64 | 2015-07-10 10:41:36 +0200 | [diff] [blame] | 518 | uint8_t trx_no = -1; |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 519 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 520 | OSMO_ASSERT(old_ms != NULL); |
Pau Espin Pedrol | 17402a5 | 2020-05-08 17:44:33 +0200 | [diff] [blame] | 521 | |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 522 | gprs_rlcmac_tbf *tbf = NULL; |
| 523 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 524 | if (ms_current_trx(old_ms)) |
| 525 | trx_no = ms_current_trx(old_ms)->trx_no; |
Jacob Erlbeck | 5879c64 | 2015-07-10 10:41:36 +0200 | [diff] [blame] | 526 | |
Pau Espin Pedrol | 403e048 | 2023-04-17 20:28:10 +0200 | [diff] [blame] | 527 | ms_ref(old_ms, __func__); |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 528 | |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 529 | /* Allocate what is needed first */ |
| 530 | switch (mode) { |
| 531 | case TEST_MODE_UL_ONLY: |
| 532 | case TEST_MODE_DL_AFTER_UL: |
| 533 | case TEST_MODE_UL_AND_DL: |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 534 | if (ms_ul_tbf(old_ms)) |
| 535 | tbf_free(ms_ul_tbf(old_ms)); |
Pau Espin Pedrol | 4d36391 | 2023-04-21 19:32:16 +0200 | [diff] [blame] | 536 | tbf = tbf_alloc(bts, old_ms, GPRS_RLCMAC_UL_TBF, trx_no, false); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 537 | if (tbf == NULL) { |
Pau Espin Pedrol | 0dcbc07 | 2021-11-10 19:09:10 +0100 | [diff] [blame] | 538 | OSMO_ASSERT(trx_no != -1 || bts_all_pdch_allocated(bts)); |
Pau Espin Pedrol | 403e048 | 2023-04-17 20:28:10 +0200 | [diff] [blame] | 539 | ms_unref(old_ms, __func__); |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 540 | return NULL; |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 541 | } |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 542 | break; |
| 543 | case TEST_MODE_DL_ONLY: |
| 544 | case TEST_MODE_UL_AFTER_DL: |
| 545 | case TEST_MODE_DL_AND_UL: |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 546 | if (ms_dl_tbf(old_ms)) |
| 547 | tbf_free(ms_dl_tbf(old_ms)); |
Pau Espin Pedrol | 4d36391 | 2023-04-21 19:32:16 +0200 | [diff] [blame] | 548 | tbf = tbf_alloc(bts, old_ms, GPRS_RLCMAC_DL_TBF, trx_no, false); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 549 | if (tbf == NULL) { |
Pau Espin Pedrol | 0dcbc07 | 2021-11-10 19:09:10 +0100 | [diff] [blame] | 550 | OSMO_ASSERT(trx_no != -1 || bts_all_pdch_allocated(bts)); |
Pau Espin Pedrol | 403e048 | 2023-04-17 20:28:10 +0200 | [diff] [blame] | 551 | ms_unref(old_ms, __func__); |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 552 | return NULL; |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 553 | } |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | OSMO_ASSERT(tbf); |
| 557 | OSMO_ASSERT(tbf->ms()); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 558 | OSMO_ASSERT(old_ms == tbf->ms()); |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 559 | ms = tbf->ms(); |
| 560 | |
Pau Espin Pedrol | 403e048 | 2023-04-17 20:28:10 +0200 | [diff] [blame] | 561 | ms_ref(ms, __func__); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 562 | new_ms = ms; |
Jacob Erlbeck | 14376a7 | 2015-07-07 11:31:28 +0200 | [diff] [blame] | 563 | /* Continue with what is needed next */ |
| 564 | switch (mode) { |
| 565 | case TEST_MODE_UL_ONLY: |
| 566 | case TEST_MODE_DL_ONLY: |
| 567 | /* We are done */ |
| 568 | break; |
| 569 | |
| 570 | case TEST_MODE_DL_AFTER_UL: |
| 571 | case TEST_MODE_UL_AND_DL: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 572 | new_ms = alloc_tbfs(bts, ms, TEST_MODE_DL_ONLY); |
Jacob Erlbeck | 14376a7 | 2015-07-07 11:31:28 +0200 | [diff] [blame] | 573 | break; |
| 574 | |
| 575 | case TEST_MODE_UL_AFTER_DL: |
| 576 | case TEST_MODE_DL_AND_UL: |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 577 | new_ms = alloc_tbfs(bts, ms, TEST_MODE_UL_ONLY); |
Jacob Erlbeck | 14376a7 | 2015-07-07 11:31:28 +0200 | [diff] [blame] | 578 | break; |
| 579 | } |
| 580 | |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 581 | /* Optionally delete the TBF */ |
| 582 | switch (mode) { |
| 583 | case TEST_MODE_DL_AFTER_UL: |
| 584 | case TEST_MODE_UL_AFTER_DL: |
| 585 | tbf_free(tbf); |
Jacob Erlbeck | 0f352a6 | 2015-07-16 18:23:33 +0200 | [diff] [blame] | 586 | tbf = NULL; |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 587 | break; |
| 588 | |
| 589 | default: |
| 590 | break; |
| 591 | } |
| 592 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 593 | if (!new_ms && tbf) |
Jacob Erlbeck | 0f352a6 | 2015-07-16 18:23:33 +0200 | [diff] [blame] | 594 | tbf_free(tbf); |
| 595 | |
Pau Espin Pedrol | 403e048 | 2023-04-17 20:28:10 +0200 | [diff] [blame] | 596 | ms_unref(old_ms, __func__); |
| 597 | ms_unref(ms, __func__); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 598 | return new_ms; |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 599 | } |
| 600 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 601 | static unsigned alloc_many_tbfs(struct gprs_rlcmac_bts *bts, unsigned min_class, |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 602 | unsigned max_class, enum test_mode mode) |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 603 | { |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 604 | unsigned counter; |
| 605 | unsigned ms_class = min_class; |
| 606 | |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 607 | for (counter = 0; 1; counter += 1) { |
| 608 | gprs_rlcmac_tbf *ul_tbf, *dl_tbf; |
| 609 | uint8_t ul_slots = 0; |
| 610 | uint8_t dl_slots = 0; |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 611 | uint8_t busy_slots = 0; |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 612 | unsigned i; |
| 613 | int tfi = -1; |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 614 | int tfi2; |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 615 | uint8_t trx_no2; |
| 616 | struct gprs_rlcmac_trx *trx; |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 617 | GprsMs *ms; |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 618 | enum gprs_rlcmac_tbf_direction dir; |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 619 | uint32_t tlli = counter + 0xc0000000; |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 620 | |
Pau Espin Pedrol | cde18c5 | 2023-04-17 18:16:48 +0200 | [diff] [blame] | 621 | ms = bts_get_ms_by_tlli(bts, tlli, GSM_RESERVED_TMSI); |
Pau Espin Pedrol | 17402a5 | 2020-05-08 17:44:33 +0200 | [diff] [blame] | 622 | if (!ms) |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 623 | ms = ms_alloc(bts, NULL); |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 624 | ms_set_ms_class(ms, ms_class); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 625 | ms = alloc_tbfs(bts, ms, mode); |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 626 | if (!ms) |
| 627 | break; |
| 628 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 629 | ms_set_tlli(ms, tlli); |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 630 | |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 631 | ul_tbf = ms_ul_tbf(ms); |
| 632 | dl_tbf = ms_dl_tbf(ms); |
| 633 | trx = ms_current_trx(ms); |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 634 | |
| 635 | OSMO_ASSERT(ul_tbf || dl_tbf); |
Pau Espin Pedrol | 9935d0d | 2022-12-13 18:29:25 +0100 | [diff] [blame] | 636 | OSMO_ASSERT(ms_first_common_ts(ms) != NULL); |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 637 | if (ul_tbf) { |
Pau Espin Pedrol | 9935d0d | 2022-12-13 18:29:25 +0100 | [diff] [blame] | 638 | ul_slots = 1 << (uint8_t)ms_first_common_ts(ms)->ts_no; |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 639 | tfi = ul_tbf->tfi(); |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 640 | dir = GPRS_RLCMAC_UL_TBF; |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 641 | } else { |
Pau Espin Pedrol | 9935d0d | 2022-12-13 18:29:25 +0100 | [diff] [blame] | 642 | ul_slots = 1 << (uint8_t)ms_first_common_ts(ms)->ts_no; |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 643 | tfi = dl_tbf->tfi(); |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 644 | dir = GPRS_RLCMAC_DL_TBF; |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | for (i = 0; dl_tbf && i < ARRAY_SIZE(dl_tbf->pdch); i += 1) |
| 648 | if (dl_tbf->pdch[i]) |
| 649 | dl_slots |= 1 << i; |
| 650 | |
Max | 5b0df1f | 2017-09-11 10:38:59 +0200 | [diff] [blame] | 651 | for (i = 0; ul_tbf && i < ARRAY_SIZE(ul_tbf->pdch); i += 1) |
| 652 | if (ul_tbf->pdch[i]) |
| 653 | ul_slots |= 1 << i; |
| 654 | |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 655 | for (i = 0; trx && i < ARRAY_SIZE(trx->pdch); i += 1) { |
| 656 | struct gprs_rlcmac_pdch *pdch = &trx->pdch[i]; |
| 657 | |
| 658 | if (ul_tbf && dl_tbf) |
| 659 | continue; |
| 660 | |
| 661 | if (ul_tbf && |
Max | d000d80 | 2017-09-20 17:55:28 +0200 | [diff] [blame] | 662 | pdch->assigned_tfi(GPRS_RLCMAC_DL_TBF) != NO_FREE_TFI) |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 663 | continue; |
| 664 | |
| 665 | if (dl_tbf && |
Max | d000d80 | 2017-09-20 17:55:28 +0200 | [diff] [blame] | 666 | pdch->assigned_tfi(GPRS_RLCMAC_UL_TBF) != NO_FREE_TFI) |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 667 | continue; |
| 668 | |
| 669 | busy_slots |= 1 << i; |
| 670 | } |
| 671 | |
Max | d000d80 | 2017-09-20 17:55:28 +0200 | [diff] [blame] | 672 | printf(" TBF[%d] class %d reserves " OSMO_BIT_SPEC "\n", |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 673 | tfi, ms_class, |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 674 | get_dir_char(0x01, ul_slots, dl_slots, busy_slots), |
| 675 | get_dir_char(0x02, ul_slots, dl_slots, busy_slots), |
| 676 | get_dir_char(0x04, ul_slots, dl_slots, busy_slots), |
| 677 | get_dir_char(0x08, ul_slots, dl_slots, busy_slots), |
| 678 | get_dir_char(0x10, ul_slots, dl_slots, busy_slots), |
| 679 | get_dir_char(0x20, ul_slots, dl_slots, busy_slots), |
| 680 | get_dir_char(0x40, ul_slots, dl_slots, busy_slots), |
| 681 | get_dir_char(0x80, ul_slots, dl_slots, busy_slots)); |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 682 | |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 683 | if (tfi >= 0) { |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 684 | OSMO_ASSERT(ms_current_trx(ms)); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 685 | tfi2 = bts_tfi_find_free(bts, dir, &trx_no2, |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 686 | ms_current_trx(ms)->trx_no); |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 687 | OSMO_ASSERT(tfi != tfi2); |
Jacob Erlbeck | 7b3675b | 2015-07-16 18:28:22 +0200 | [diff] [blame] | 688 | OSMO_ASSERT(tfi2 < 0 || |
Pau Espin Pedrol | da971ee | 2020-12-16 15:59:45 +0100 | [diff] [blame] | 689 | trx_no2 == ms_current_trx(ms)->trx_no); |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 690 | } |
| 691 | |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 692 | ms_class += 1; |
| 693 | if (ms_class > max_class) |
| 694 | ms_class = min_class; |
| 695 | } |
| 696 | |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 697 | return counter; |
| 698 | } |
| 699 | |
Pau Espin Pedrol | c85e093 | 2021-02-25 18:08:10 +0100 | [diff] [blame] | 700 | static void test_successive_allocation(alloc_algorithm_func_t algo, unsigned min_class, |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 701 | unsigned max_class, enum test_mode mode, |
| 702 | unsigned expect_num, const char *text) |
| 703 | { |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 704 | struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0); |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 705 | struct gprs_rlcmac_trx *trx; |
| 706 | unsigned counter; |
| 707 | |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 708 | printf("Going to test assignment with many TBF, algorithm %s class %u..%u (%s)\n", |
| 709 | text, min_class, max_class, test_mode_descr(mode)); |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 710 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 711 | the_pcu->alloc_algorithm = algo; |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 712 | |
| 713 | trx = &bts->trx[0]; |
| 714 | trx->pdch[3].enable(); |
| 715 | trx->pdch[4].enable(); |
| 716 | trx->pdch[5].enable(); |
| 717 | trx->pdch[6].enable(); |
| 718 | trx->pdch[7].enable(); |
| 719 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 720 | counter = alloc_many_tbfs(bts, min_class, max_class, mode); |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 721 | |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 722 | printf(" Successfully allocated %u UL TBFs, algorithm %s class %u..%u (%s)\n", |
| 723 | counter, text, min_class, max_class, test_mode_descr(mode)); |
Jacob Erlbeck | 88fb613 | 2015-07-16 15:01:38 +0200 | [diff] [blame] | 724 | if (counter != expect_num) |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 725 | fprintf(stderr, " Expected %u TBFs (got %u), algorithm %s class %u..%u (%s)\n", |
| 726 | expect_num, counter, text, min_class, max_class, test_mode_descr(mode)); |
Jacob Erlbeck | 88fb613 | 2015-07-16 15:01:38 +0200 | [diff] [blame] | 727 | |
Jacob Erlbeck | ec47875 | 2015-06-19 16:35:38 +0200 | [diff] [blame] | 728 | OSMO_ASSERT(counter == expect_num); |
Jacob Erlbeck | e0853cd | 2015-07-10 12:25:25 +0200 | [diff] [blame] | 729 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 730 | check_tfi_usage(bts); |
| 731 | talloc_free(bts); |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 732 | } |
| 733 | |
Pau Espin Pedrol | c85e093 | 2021-02-25 18:08:10 +0100 | [diff] [blame] | 734 | static void test_many_connections(alloc_algorithm_func_t algo, unsigned expect_num, |
Jacob Erlbeck | a8c2aaf | 2015-07-13 14:50:08 +0200 | [diff] [blame] | 735 | const char *text) |
| 736 | { |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 737 | struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0); |
Jacob Erlbeck | a8c2aaf | 2015-07-13 14:50:08 +0200 | [diff] [blame] | 738 | struct gprs_rlcmac_trx *trx; |
| 739 | int counter1, counter2 = -1; |
| 740 | unsigned i; |
| 741 | enum test_mode mode_seq[] = { |
| 742 | TEST_MODE_DL_AFTER_UL, |
| 743 | TEST_MODE_UL_ONLY, |
| 744 | TEST_MODE_DL_AFTER_UL, |
| 745 | TEST_MODE_DL_ONLY, |
| 746 | }; |
| 747 | |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 748 | printf("Going to test assignment with many connections, algorithm %s\n", text); |
Jacob Erlbeck | a8c2aaf | 2015-07-13 14:50:08 +0200 | [diff] [blame] | 749 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 750 | the_pcu->alloc_algorithm = algo; |
Jacob Erlbeck | a8c2aaf | 2015-07-13 14:50:08 +0200 | [diff] [blame] | 751 | |
| 752 | trx = &bts->trx[0]; |
| 753 | trx->pdch[3].enable(); |
| 754 | trx->pdch[4].enable(); |
| 755 | trx->pdch[5].enable(); |
| 756 | trx->pdch[6].enable(); |
| 757 | trx->pdch[7].enable(); |
| 758 | |
| 759 | for (i = 0; i < ARRAY_SIZE(mode_seq); i += 1) { |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 760 | counter1 = alloc_many_tbfs(bts, 1, mslot_class_max(), mode_seq[i]); |
Jacob Erlbeck | a8c2aaf | 2015-07-13 14:50:08 +0200 | [diff] [blame] | 761 | fprintf(stderr, " Allocated %d TBFs (previously %d)\n", |
| 762 | counter1, counter2); |
| 763 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 764 | check_tfi_usage(bts); |
Jacob Erlbeck | a8c2aaf | 2015-07-13 14:50:08 +0200 | [diff] [blame] | 765 | |
| 766 | /* This will stop earlier due to USF shortage */ |
| 767 | if (mode_seq[i] == TEST_MODE_UL_ONLY) |
| 768 | continue; |
| 769 | |
Jacob Erlbeck | 88fb613 | 2015-07-16 15:01:38 +0200 | [diff] [blame] | 770 | if (counter2 >= 0) { |
| 771 | if (counter1 < counter2) |
| 772 | fprintf(stderr, " Expected %d >= %d in %s\n", |
| 773 | counter1, counter2, text); |
Jacob Erlbeck | a8c2aaf | 2015-07-13 14:50:08 +0200 | [diff] [blame] | 774 | OSMO_ASSERT(counter1 >= counter2); |
Jacob Erlbeck | 88fb613 | 2015-07-16 15:01:38 +0200 | [diff] [blame] | 775 | } |
Jacob Erlbeck | a8c2aaf | 2015-07-13 14:50:08 +0200 | [diff] [blame] | 776 | |
| 777 | counter2 = counter1; |
| 778 | } |
| 779 | |
| 780 | printf(" Successfully allocated %d TBFs\n", counter1); |
Jacob Erlbeck | 88fb613 | 2015-07-16 15:01:38 +0200 | [diff] [blame] | 781 | if (counter1 != (int)expect_num) |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 782 | fprintf(stderr, " Expected %d TBFs (got %d) for algorithm %s\n", expect_num, counter1, text); |
Jacob Erlbeck | a8c2aaf | 2015-07-13 14:50:08 +0200 | [diff] [blame] | 783 | |
| 784 | OSMO_ASSERT(expect_num == (unsigned)counter1); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 785 | talloc_free(bts); |
Jacob Erlbeck | a8c2aaf | 2015-07-13 14:50:08 +0200 | [diff] [blame] | 786 | } |
| 787 | |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 788 | static inline void test_a_b_dyn(enum test_mode mode, uint8_t exp_A, uint8_t exp_B, uint8_t exp_dyn) |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 789 | { |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 790 | test_successive_allocation(alloc_algorithm_a, 1, 1, mode, exp_A, "A"); |
| 791 | test_successive_allocation(alloc_algorithm_b, 10, 10, mode, exp_B, "B"); |
| 792 | test_successive_allocation(alloc_algorithm_dynamic, 10, 10, mode, exp_dyn, "dynamic"); |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 793 | } |
| 794 | |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 795 | static void test_successive_allocations() |
Jacob Erlbeck | a8c2aaf | 2015-07-13 14:50:08 +0200 | [diff] [blame] | 796 | { |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 797 | test_successive_allocation(alloc_algorithm_a, 1, 1, TEST_MODE_UL_AND_DL, 35, "A"); |
Pau Espin Pedrol | ed2afa3 | 2021-02-22 17:20:15 +0100 | [diff] [blame] | 798 | test_successive_allocation(alloc_algorithm_b, 10, 10, TEST_MODE_UL_AND_DL, 15, "B"); |
| 799 | test_successive_allocation(alloc_algorithm_b, 12, 12, TEST_MODE_UL_AND_DL, 15, "B"); |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 800 | |
Pau Espin Pedrol | ed2afa3 | 2021-02-22 17:20:15 +0100 | [diff] [blame] | 801 | test_successive_allocation(alloc_algorithm_b, 1, 12, TEST_MODE_UL_AND_DL, 23, "B"); |
| 802 | test_successive_allocation(alloc_algorithm_b, 1, mslot_class_max(), TEST_MODE_UL_AND_DL, 17, "B"); |
| 803 | test_successive_allocation(alloc_algorithm_dynamic, 1, mslot_class_max(), TEST_MODE_UL_AND_DL, 17, "dynamic"); |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 804 | |
Pau Espin Pedrol | ed2afa3 | 2021-02-22 17:20:15 +0100 | [diff] [blame] | 805 | test_a_b_dyn(TEST_MODE_DL_AND_UL, 35, 15, 15); |
| 806 | test_a_b_dyn(TEST_MODE_DL_AFTER_UL, 160, 32, 101); |
| 807 | test_a_b_dyn(TEST_MODE_UL_AFTER_DL, 35, 15, 15); |
| 808 | test_a_b_dyn(TEST_MODE_UL_ONLY, 35, 15, 21); |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 809 | test_a_b_dyn(TEST_MODE_DL_ONLY, 160, 32, 101); |
Jacob Erlbeck | a8c2aaf | 2015-07-13 14:50:08 +0200 | [diff] [blame] | 810 | } |
| 811 | |
Aravind Sirsikar | e26ee01 | 2016-09-06 18:15:45 +0530 | [diff] [blame] | 812 | static void test_2_consecutive_dl_tbfs() |
| 813 | { |
Pau Espin Pedrol | d1049dc | 2021-01-18 17:14:14 +0100 | [diff] [blame] | 814 | struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0); |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 815 | GprsMs *ms; |
Aravind Sirsikar | e26ee01 | 2016-09-06 18:15:45 +0530 | [diff] [blame] | 816 | struct gprs_rlcmac_trx *trx; |
| 817 | uint8_t ms_class = 11; |
| 818 | uint8_t egprs_ms_class = 11; |
| 819 | gprs_rlcmac_tbf *dl_tbf1, *dl_tbf2; |
| 820 | uint8_t numTs1 = 0, numTs2 = 0; |
| 821 | |
| 822 | printf("Testing DL TS allocation for Multi UEs\n"); |
| 823 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 824 | the_pcu->alloc_algorithm = alloc_algorithm_b; |
Aravind Sirsikar | e26ee01 | 2016-09-06 18:15:45 +0530 | [diff] [blame] | 825 | |
| 826 | trx = &bts->trx[0]; |
| 827 | trx->pdch[4].enable(); |
| 828 | trx->pdch[5].enable(); |
| 829 | trx->pdch[6].enable(); |
| 830 | trx->pdch[7].enable(); |
| 831 | |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 832 | ms = ms_alloc(bts, NULL); |
Pau Espin Pedrol | bfc9756 | 2023-04-17 14:49:29 +0200 | [diff] [blame] | 833 | ms_set_ms_class(ms, ms_class); |
| 834 | ms_set_egprs_ms_class(ms, egprs_ms_class); |
Pau Espin Pedrol | 4d36391 | 2023-04-21 19:32:16 +0200 | [diff] [blame] | 835 | dl_tbf1 = tbf_alloc(bts, ms, GPRS_RLCMAC_DL_TBF, 0, false); |
Aravind Sirsikar | e26ee01 | 2016-09-06 18:15:45 +0530 | [diff] [blame] | 836 | OSMO_ASSERT(dl_tbf1); |
| 837 | |
| 838 | for (int i = 0; i < 8; i++) { |
| 839 | if (dl_tbf1->pdch[i]) |
| 840 | numTs1++; |
| 841 | } |
| 842 | OSMO_ASSERT(numTs1 == 4); |
| 843 | printf("TBF1: numTs(%d)\n", numTs1); |
| 844 | |
Pau Espin Pedrol | eae9147 | 2023-04-19 19:42:05 +0200 | [diff] [blame] | 845 | ms = ms_alloc(bts, NULL); |
Pau Espin Pedrol | bfc9756 | 2023-04-17 14:49:29 +0200 | [diff] [blame] | 846 | ms_set_ms_class(ms, ms_class); |
| 847 | ms_set_egprs_ms_class(ms, egprs_ms_class); |
Pau Espin Pedrol | 4d36391 | 2023-04-21 19:32:16 +0200 | [diff] [blame] | 848 | dl_tbf2 = tbf_alloc(bts, ms, GPRS_RLCMAC_DL_TBF, 0, false); |
Aravind Sirsikar | e26ee01 | 2016-09-06 18:15:45 +0530 | [diff] [blame] | 849 | OSMO_ASSERT(dl_tbf2); |
| 850 | |
| 851 | for (int i = 0; i < 8; i++) { |
| 852 | if (dl_tbf2->pdch[i]) |
| 853 | numTs2++; |
| 854 | } |
| 855 | |
| 856 | /* |
| 857 | * TODO: currently 2nd DL TBF gets 3 TS |
| 858 | * This behaviour will be fixed in subsequent patch |
| 859 | */ |
| 860 | printf("TBF2: numTs(%d)\n", numTs2); |
| 861 | OSMO_ASSERT(numTs2 == 3); |
| 862 | |
| 863 | tbf_free(dl_tbf1); |
| 864 | tbf_free(dl_tbf2); |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 865 | talloc_free(bts); |
Aravind Sirsikar | e26ee01 | 2016-09-06 18:15:45 +0530 | [diff] [blame] | 866 | } |
| 867 | |
Oliver Smith | 3f79470 | 2021-08-23 14:19:21 +0200 | [diff] [blame] | 868 | static void test_bts_pch_timer(void) |
| 869 | { |
| 870 | struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0); |
Pau Espin Pedrol | 13961c9 | 2021-11-08 17:38:47 +0100 | [diff] [blame] | 871 | struct osmo_mobile_identity mi_imsi1, mi_imsi2; |
Pau Espin Pedrol | 19b3392 | 2021-11-08 17:49:52 +0100 | [diff] [blame] | 872 | struct osmo_mobile_identity mi_tmsi1; |
Pau Espin Pedrol | 13961c9 | 2021-11-08 17:38:47 +0100 | [diff] [blame] | 873 | mi_imsi1.type = mi_imsi2.type = GSM_MI_TYPE_IMSI; |
Pau Espin Pedrol | 19b3392 | 2021-11-08 17:49:52 +0100 | [diff] [blame] | 874 | mi_tmsi1.type = GSM_MI_TYPE_TMSI; |
Pau Espin Pedrol | 13961c9 | 2021-11-08 17:38:47 +0100 | [diff] [blame] | 875 | OSMO_STRLCPY_ARRAY(mi_imsi1.imsi, "1234"); |
| 876 | OSMO_STRLCPY_ARRAY(mi_imsi2.imsi, "5678"); |
Pau Espin Pedrol | 19b3392 | 2021-11-08 17:49:52 +0100 | [diff] [blame] | 877 | mi_tmsi1.tmsi = 987654321; |
Oliver Smith | 3f79470 | 2021-08-23 14:19:21 +0200 | [diff] [blame] | 878 | |
| 879 | fprintf(stderr, "Testing bts_pch_timer dealloc on bts dealloc\n"); |
| 880 | log_set_category_filter(osmo_stderr_target, DPCU, 1, LOGL_DEBUG); |
| 881 | |
| 882 | fprintf(stderr, "Starting PCH timer for 2 IMSI\n"); |
Pau Espin Pedrol | 13961c9 | 2021-11-08 17:38:47 +0100 | [diff] [blame] | 883 | bts_pch_timer_start(bts, &mi_imsi1, mi_imsi1.imsi); |
| 884 | bts_pch_timer_start(bts, &mi_imsi2, mi_imsi2.imsi); |
Pau Espin Pedrol | 19b3392 | 2021-11-08 17:49:52 +0100 | [diff] [blame] | 885 | fprintf(stderr, "Starting PCH timer for 1 TMSI\n"); |
| 886 | bts_pch_timer_start(bts, &mi_tmsi1, "6666"); |
Oliver Smith | 3f79470 | 2021-08-23 14:19:21 +0200 | [diff] [blame] | 887 | |
| 888 | fprintf(stderr, "Deallocating BTS, expecting the PCH timer to be stopped and deallocated\n"); |
| 889 | talloc_free(bts); |
| 890 | } |
| 891 | |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 892 | int main(int argc, char **argv) |
| 893 | { |
| 894 | tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile AllocTest context"); |
| 895 | if (!tall_pcu_ctx) |
| 896 | abort(); |
| 897 | |
Neels Hofmeyr | 78ce591 | 2017-02-08 17:07:31 +0100 | [diff] [blame] | 898 | msgb_talloc_ctx_init(tall_pcu_ctx, 0); |
Neels Hofmeyr | 42f2d61 | 2018-04-01 16:54:40 +0200 | [diff] [blame] | 899 | osmo_init_logging2(tall_pcu_ctx, &gprs_log_info); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 900 | log_set_use_color(osmo_stderr_target, 0); |
Pau Espin Pedrol | 00f52cc | 2021-02-19 14:01:52 +0100 | [diff] [blame] | 901 | log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE); |
Pau Espin Pedrol | b18d2a5 | 2021-02-19 14:00:48 +0100 | [diff] [blame] | 902 | log_set_print_category(osmo_stderr_target, 0); |
| 903 | log_set_print_category_hex(osmo_stderr_target, 0); |
Philipp Maier | de0e558 | 2020-03-25 12:23:52 +0100 | [diff] [blame] | 904 | log_set_category_filter(osmo_stderr_target, DTBF, 1, LOGL_INFO); |
Jacob Erlbeck | 9ec49e2 | 2015-06-29 13:00:20 +0200 | [diff] [blame] | 905 | if (getenv("LOGL_DEBUG")) |
| 906 | log_set_log_level(osmo_stderr_target, LOGL_DEBUG); |
Pau Espin Pedrol | dc2aaac | 2021-05-14 12:50:46 +0200 | [diff] [blame] | 907 | osmo_fsm_log_addr(false); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 908 | |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 909 | the_pcu = gprs_pcu_alloc(tall_pcu_ctx); |
| 910 | |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 911 | test_alloc_a(); |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 912 | test_alloc_b(); |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 913 | test_successive_allocations(); |
| 914 | test_many_connections(alloc_algorithm_a, 160, "A"); |
Max | 01bd0cc | 2018-01-23 20:58:49 +0100 | [diff] [blame] | 915 | test_many_connections(alloc_algorithm_b, 32, "B"); |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 916 | test_many_connections(alloc_algorithm_dynamic, 160, "dynamic"); |
Aravind Sirsikar | e26ee01 | 2016-09-06 18:15:45 +0530 | [diff] [blame] | 917 | test_2_consecutive_dl_tbfs(); |
Oliver Smith | 3f79470 | 2021-08-23 14:19:21 +0200 | [diff] [blame] | 918 | test_bts_pch_timer(); |
Pau Espin Pedrol | ac3fd12 | 2021-01-13 18:54:38 +0100 | [diff] [blame] | 919 | |
| 920 | talloc_free(the_pcu); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 921 | return EXIT_SUCCESS; |
| 922 | } |
| 923 | |
| 924 | /* |
| 925 | * stubs that should not be reached |
| 926 | */ |
| 927 | extern "C" { |
| 928 | void l1if_pdch_req() { abort(); } |
| 929 | void l1if_connect_pdch() { abort(); } |
Philipp Maier | 72ed333 | 2023-02-27 15:32:00 +0100 | [diff] [blame] | 930 | void l1if_disconnect_pdch() { abort(); } |
Philipp Maier | 6ee8d13 | 2023-04-25 09:41:17 +0200 | [diff] [blame] | 931 | void l1if_close_trx() { abort(); } |
| 932 | void l1if_open_trx() { abort(); } |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 933 | } |