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