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