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