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. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | */ |
| 19 | |
| 20 | #include "gprs_rlcmac.h" |
| 21 | #include "gprs_debug.h" |
| 22 | #include "tbf.h" |
Pau Espin Pedrol | 9d1cdb1 | 2019-09-25 17:47:02 +0200 | [diff] [blame] | 23 | #include "tbf_ul.h" |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 24 | #include "bts.h" |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 25 | |
| 26 | #include <string.h> |
| 27 | #include <stdio.h> |
| 28 | |
| 29 | extern "C" { |
Max | 9f46071 | 2018-01-23 20:57:08 +0100 | [diff] [blame] | 30 | #include "mslot_class.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> |
| 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 | |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 54 | static void check_tfi_usage(BTS *the_bts) |
| 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}}}}; |
Jacob Erlbeck | ed2dbf6 | 2015-12-28 19:15:40 +0100 | [diff] [blame] | 59 | LListHead<gprs_rlcmac_tbf> *tbf_lists[2] = { |
| 60 | &the_bts->ul_tbfs(), |
| 61 | &the_bts->dl_tbfs() |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 62 | }; |
| 63 | |
Jacob Erlbeck | ed2dbf6 | 2015-12-28 19:15:40 +0100 | [diff] [blame] | 64 | LListHead<gprs_rlcmac_tbf> *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 | |
Jacob Erlbeck | ed2dbf6 | 2015-12-28 19:15:40 +0100 | [diff] [blame] | 72 | llist_for_each(pos, tbf_lists[list_idx]) { |
| 73 | 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); |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 89 | OSMO_ASSERT(the_bts->dl_tbf_by_tfi( |
| 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); |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 96 | OSMO_ASSERT(the_bts->ul_tbf_by_tfi( |
| 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; |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 115 | BTS the_bts; |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 116 | GprsMs *ms; |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 117 | struct gprs_rlcmac_bts *bts; |
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 | |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 122 | bts = the_bts.bts_data(); |
| 123 | bts->alloc_algorithm = alloc_algorithm_a; |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 124 | |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 125 | struct gprs_rlcmac_trx *trx = &bts->trx[0]; |
Jacob Erlbeck | fa464bb | 2015-06-29 12:45:11 +0200 | [diff] [blame] | 126 | for (i = 0; i < 8; i += 1) |
| 127 | if (slots & (1 << i)) |
| 128 | trx->pdch[i].enable(); |
| 129 | |
| 130 | OSMO_ASSERT(count >= 0 && count <= (int)ARRAY_SIZE(tbfs)); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 131 | |
| 132 | /** |
| 133 | * Currently alloc_a will only allocate from the first |
| 134 | * PDCH and all possible usf's. We run out of usf's before |
| 135 | * we are out of tfi's. Observe this and make sure that at |
| 136 | * least this part is working okay. |
| 137 | */ |
Jacob Erlbeck | e0853cd | 2015-07-10 12:25:25 +0200 | [diff] [blame] | 138 | for (i = 0; i < (int)ARRAY_SIZE(tbfs); ++i) { |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 139 | ms = bts->bts->ms_alloc(0, 0); |
| 140 | tbfs[i] = tbf_alloc(bts, ms, dir, -1, 0); |
Jacob Erlbeck | e0853cd | 2015-07-10 12:25:25 +0200 | [diff] [blame] | 141 | if (tbfs[i] == NULL) |
| 142 | break; |
| 143 | |
| 144 | used_trx = tbfs[i]->trx->trx_no; |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 145 | tfi = the_bts.tfi_find_free(dir, &tmp_trx, used_trx); |
| 146 | OSMO_ASSERT(tbfs[i]->tfi() != tfi); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 147 | } |
| 148 | |
Jacob Erlbeck | e0853cd | 2015-07-10 12:25:25 +0200 | [diff] [blame] | 149 | check_tfi_usage(&the_bts); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 150 | |
Jacob Erlbeck | e0853cd | 2015-07-10 12:25:25 +0200 | [diff] [blame] | 151 | OSMO_ASSERT(i == count); |
| 152 | |
| 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 | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 157 | ms = bts->bts->ms_alloc(0, 0); |
| 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]); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | static void test_alloc_a() |
| 164 | { |
Jacob Erlbeck | fa464bb | 2015-06-29 12:45:11 +0200 | [diff] [blame] | 165 | /* slots 2 - 3 */ |
Jacob Erlbeck | e0853cd | 2015-07-10 12:25:25 +0200 | [diff] [blame] | 166 | test_alloc_a(GPRS_RLCMAC_DL_TBF, 0x0c, 32*2); |
Jacob Erlbeck | ec47875 | 2015-06-19 16:35:38 +0200 | [diff] [blame] | 167 | test_alloc_a(GPRS_RLCMAC_UL_TBF, 0x0c, 14); |
Jacob Erlbeck | fa464bb | 2015-06-29 12:45:11 +0200 | [diff] [blame] | 168 | |
| 169 | /* slots 1 - 5 */ |
Jacob Erlbeck | e0853cd | 2015-07-10 12:25:25 +0200 | [diff] [blame] | 170 | test_alloc_a(GPRS_RLCMAC_DL_TBF, 0x1e, 32*4); |
Jacob Erlbeck | ec47875 | 2015-06-19 16:35:38 +0200 | [diff] [blame] | 171 | test_alloc_a(GPRS_RLCMAC_UL_TBF, 0x1e, 28); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 172 | } |
| 173 | |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 174 | 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] | 175 | { |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 176 | if (!verbose) |
| 177 | return; |
| 178 | |
Jacob Erlbeck | 1f33294 | 2015-05-04 08:21:17 +0200 | [diff] [blame] | 179 | 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] | 180 | if (tbf->pdch[i]) |
Neels Hofmeyr | d34646a | 2017-02-08 17:07:40 +0100 | [diff] [blame] | 181 | printf("PDCH[%zu] is used for %s\n", i, dir); |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 182 | printf("PDCH[%d] is control_ts for %s\n", tbf->control_ts, dir); |
| 183 | printf("PDCH[%d] is first common for %s\n", tbf->first_common_ts, dir); |
| 184 | } |
| 185 | |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 186 | #define ENABLE_PDCH(ts_no, enable_flag, trx) \ |
| 187 | if (enable_flag) \ |
| 188 | trx->pdch[ts_no].enable(); |
| 189 | |
| 190 | static inline void enable_ts_on_bts(struct gprs_rlcmac_bts *bts, |
| 191 | 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] | 192 | { |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 193 | struct gprs_rlcmac_trx *trx = &bts->trx[0]; |
| 194 | |
| 195 | ENABLE_PDCH(0, ts0, trx); |
| 196 | ENABLE_PDCH(1, ts1, trx); |
| 197 | ENABLE_PDCH(2, ts2, trx); |
| 198 | ENABLE_PDCH(3, ts3, trx); |
| 199 | ENABLE_PDCH(4, ts4, trx); |
| 200 | ENABLE_PDCH(5, ts5, trx); |
| 201 | ENABLE_PDCH(6, ts6, trx); |
| 202 | ENABLE_PDCH(7, ts7, trx); |
| 203 | } |
| 204 | |
| 205 | static inline bool test_alloc_b_ul_dl(bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7, |
| 206 | uint8_t ms_class, bool verbose) |
| 207 | { |
| 208 | BTS the_bts; |
| 209 | struct gprs_rlcmac_bts *bts = the_bts.bts_data(); |
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 | |
| 217 | bts->alloc_algorithm = alloc_algorithm_b; |
| 218 | |
| 219 | enable_ts_on_bts(bts, ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7); |
| 220 | |
Pau Espin Pedrol | 17402a5 | 2020-05-08 17:44:33 +0200 | [diff] [blame] | 221 | ms = the_bts.ms_alloc(ms_class, 0); |
| 222 | ul_tbf = tbf_alloc_ul_tbf(bts, ms, -1, true); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 223 | if (!ul_tbf) |
| 224 | return false; |
| 225 | |
| 226 | OSMO_ASSERT(ul_tbf->ms()); |
| 227 | OSMO_ASSERT(ul_tbf->ms()->current_trx()); |
| 228 | |
| 229 | dump_assignment(ul_tbf, "UL", verbose); |
| 230 | |
| 231 | /* assume final ack has not been sent */ |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 232 | dl_tbf = tbf_alloc_dl_tbf(bts, ms, ms->current_trx()->trx_no, false); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 233 | if (!dl_tbf) |
| 234 | return false; |
| 235 | |
| 236 | dump_assignment(dl_tbf, "DL", verbose); |
| 237 | |
| 238 | OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts); |
| 239 | |
| 240 | check_tfi_usage(&the_bts); |
| 241 | |
| 242 | tbf_free(dl_tbf); |
| 243 | tbf_free(ul_tbf); |
| 244 | |
| 245 | return true; |
| 246 | } |
| 247 | |
| 248 | static inline bool test_alloc_b_dl_ul(bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7, |
| 249 | uint8_t ms_class, bool verbose) |
| 250 | { |
| 251 | BTS the_bts; |
| 252 | struct gprs_rlcmac_bts *bts = the_bts.bts_data(); |
Pau Espin Pedrol | 17402a5 | 2020-05-08 17:44:33 +0200 | [diff] [blame] | 253 | GprsMs *ms; |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 254 | gprs_rlcmac_ul_tbf *ul_tbf; |
| 255 | gprs_rlcmac_dl_tbf *dl_tbf; |
| 256 | |
| 257 | if (verbose) |
| 258 | printf("Testing DL then UL assignment followed by update\n"); |
| 259 | |
| 260 | bts->alloc_algorithm = alloc_algorithm_b; |
| 261 | |
| 262 | enable_ts_on_bts(bts, ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7); |
| 263 | |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 264 | ms = the_bts.ms_alloc(ms_class, 0); |
| 265 | dl_tbf = tbf_alloc_dl_tbf(bts, ms, -1, true); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 266 | if (!dl_tbf) |
| 267 | return false; |
| 268 | |
| 269 | dl_tbf->update_ms(0x23, GPRS_RLCMAC_DL_TBF); |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 270 | OSMO_ASSERT(dl_tbf->ms() == ms); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 271 | OSMO_ASSERT(dl_tbf->ms()->current_trx()); |
| 272 | |
| 273 | dump_assignment(dl_tbf, "DL", verbose); |
| 274 | |
Pau Espin Pedrol | 17402a5 | 2020-05-08 17:44:33 +0200 | [diff] [blame] | 275 | ul_tbf = tbf_alloc_ul_tbf(bts, ms, ms->current_trx()->trx_no, false); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 276 | if (!ul_tbf) |
| 277 | return false; |
| 278 | |
| 279 | ul_tbf->update_ms(0x23, GPRS_RLCMAC_UL_TBF); |
| 280 | ul_tbf->m_contention_resolution_done = 1; |
| 281 | |
| 282 | dump_assignment(ul_tbf, "UL", verbose); |
| 283 | |
| 284 | OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts); |
| 285 | |
| 286 | /* now update the dl_tbf */ |
| 287 | dl_tbf->update(); |
| 288 | dump_assignment(dl_tbf, "DL", verbose); |
| 289 | OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts); |
| 290 | |
| 291 | check_tfi_usage(&the_bts); |
| 292 | |
| 293 | tbf_free(dl_tbf); |
| 294 | tbf_free(ul_tbf); |
| 295 | |
| 296 | return true; |
| 297 | } |
| 298 | |
| 299 | static inline bool test_alloc_b_jolly(uint8_t ms_class) |
| 300 | { |
| 301 | BTS the_bts; |
| 302 | struct gprs_rlcmac_bts *bts = the_bts.bts_data(); |
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 | |
| 310 | bts->alloc_algorithm = alloc_algorithm_b; |
| 311 | |
| 312 | enable_ts_on_bts(bts, false, true, true, true, true, false, false, false); |
| 313 | |
| 314 | tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1); |
| 315 | OSMO_ASSERT(tfi >= 0); |
Pau Espin Pedrol | 17402a5 | 2020-05-08 17:44:33 +0200 | [diff] [blame] | 316 | ms = the_bts.ms_alloc(ms_class, 0); |
| 317 | ul_tbf = tbf_alloc_ul_tbf(bts, ms, -1, false); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 318 | if (!ul_tbf) |
| 319 | return false; |
| 320 | |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 321 | OSMO_ASSERT(ul_tbf->ms() == ms); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 322 | OSMO_ASSERT(ul_tbf->ms()->current_trx()); |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 323 | trx_no = ms->current_trx()->trx_no; |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 324 | dump_assignment(ul_tbf, "UL", true); |
| 325 | |
| 326 | /* assume final ack has not been sent */ |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 327 | dl_tbf = tbf_alloc_dl_tbf(bts, ms, trx_no, false); |
Max | 2ecf0fd | 2017-11-21 18:13:31 +0100 | [diff] [blame] | 328 | if (!dl_tbf) |
| 329 | return false; |
| 330 | |
| 331 | dump_assignment(dl_tbf, "DL", true); |
| 332 | |
| 333 | OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts); |
| 334 | |
| 335 | check_tfi_usage(&the_bts); |
| 336 | |
| 337 | tbf_free(dl_tbf); |
| 338 | tbf_free(ul_tbf); |
| 339 | |
| 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 | |
Max | e9fe0e3 | 2017-09-28 15:56:05 +0200 | [diff] [blame] | 422 | typedef int (*algo_t)(struct gprs_rlcmac_bts *bts, struct GprsMs *ms, struct gprs_rlcmac_tbf *tbf, bool single, |
| 423 | int8_t use_trx); |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 424 | |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 425 | 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] | 426 | { |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 427 | int offs = busy ? 32 : 0; |
| 428 | return (mask & tx & rx) ? 'C' + offs : |
| 429 | (mask & tx) ? 'U' + offs : |
| 430 | (mask & rx) ? 'D' + offs : |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 431 | '.'; |
| 432 | } |
| 433 | |
| 434 | enum test_mode { |
| 435 | TEST_MODE_UL_ONLY, |
| 436 | TEST_MODE_DL_ONLY, |
| 437 | TEST_MODE_UL_AND_DL, |
| 438 | TEST_MODE_DL_AND_UL, |
| 439 | TEST_MODE_DL_AFTER_UL, |
| 440 | TEST_MODE_UL_AFTER_DL, |
| 441 | }; |
| 442 | |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 443 | static inline char *test_mode_descr(enum test_mode t) |
| 444 | { |
| 445 | switch (t) { |
| 446 | case TEST_MODE_UL_ONLY: return (char*)"UL only"; |
| 447 | case TEST_MODE_DL_ONLY: return (char*)"DL only"; |
| 448 | case TEST_MODE_UL_AND_DL: return (char*)"UL and DL"; |
| 449 | case TEST_MODE_DL_AND_UL: return (char*)"DL and UL"; |
| 450 | case TEST_MODE_DL_AFTER_UL: return (char*)"DL after UL"; |
| 451 | case TEST_MODE_UL_AFTER_DL: return (char*)"UL after DL"; |
| 452 | default: return NULL; |
| 453 | } |
| 454 | } |
| 455 | |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 456 | static GprsMs *alloc_tbfs(BTS *the_bts, GprsMs *ms, enum test_mode mode) |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 457 | { |
| 458 | struct gprs_rlcmac_bts *bts; |
Jacob Erlbeck | 5879c64 | 2015-07-10 10:41:36 +0200 | [diff] [blame] | 459 | uint8_t trx_no = -1; |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 460 | |
Pau Espin Pedrol | 17402a5 | 2020-05-08 17:44:33 +0200 | [diff] [blame] | 461 | OSMO_ASSERT(ms != NULL); |
| 462 | |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 463 | bts = the_bts->bts_data(); |
| 464 | |
| 465 | gprs_rlcmac_tbf *tbf = NULL; |
| 466 | |
Jacob Erlbeck | 5879c64 | 2015-07-10 10:41:36 +0200 | [diff] [blame] | 467 | if (ms && ms->current_trx()) |
| 468 | trx_no = ms->current_trx()->trx_no; |
| 469 | |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 470 | GprsMs::Guard guard1(ms); |
| 471 | |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 472 | /* Allocate what is needed first */ |
| 473 | switch (mode) { |
| 474 | case TEST_MODE_UL_ONLY: |
| 475 | case TEST_MODE_DL_AFTER_UL: |
| 476 | case TEST_MODE_UL_AND_DL: |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 477 | if (ms->ul_tbf()) |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 478 | tbf_free(ms->ul_tbf()); |
Pau Espin Pedrol | 17402a5 | 2020-05-08 17:44:33 +0200 | [diff] [blame] | 479 | tbf = tbf_alloc_ul_tbf(bts, ms, trx_no, false); |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 480 | if (tbf == NULL) |
| 481 | return NULL; |
| 482 | break; |
| 483 | case TEST_MODE_DL_ONLY: |
| 484 | case TEST_MODE_UL_AFTER_DL: |
| 485 | case TEST_MODE_DL_AND_UL: |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 486 | if (ms->dl_tbf()) |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 487 | tbf_free(ms->dl_tbf()); |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 488 | tbf = tbf_alloc_dl_tbf(bts, ms, trx_no, false); |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 489 | if (tbf == NULL) |
| 490 | return NULL; |
| 491 | } |
| 492 | |
| 493 | OSMO_ASSERT(tbf); |
| 494 | OSMO_ASSERT(tbf->ms()); |
| 495 | OSMO_ASSERT(ms == NULL || ms == tbf->ms()); |
| 496 | ms = tbf->ms(); |
| 497 | |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 498 | GprsMs::Guard guard2(ms); |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 499 | |
Jacob Erlbeck | 14376a7 | 2015-07-07 11:31:28 +0200 | [diff] [blame] | 500 | /* Continue with what is needed next */ |
| 501 | switch (mode) { |
| 502 | case TEST_MODE_UL_ONLY: |
| 503 | case TEST_MODE_DL_ONLY: |
| 504 | /* We are done */ |
| 505 | break; |
| 506 | |
| 507 | case TEST_MODE_DL_AFTER_UL: |
| 508 | case TEST_MODE_UL_AND_DL: |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 509 | ms = alloc_tbfs(the_bts, ms, TEST_MODE_DL_ONLY); |
Jacob Erlbeck | 14376a7 | 2015-07-07 11:31:28 +0200 | [diff] [blame] | 510 | break; |
| 511 | |
| 512 | case TEST_MODE_UL_AFTER_DL: |
| 513 | case TEST_MODE_DL_AND_UL: |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 514 | ms = alloc_tbfs(the_bts, ms, TEST_MODE_UL_ONLY); |
Jacob Erlbeck | 14376a7 | 2015-07-07 11:31:28 +0200 | [diff] [blame] | 515 | break; |
| 516 | } |
| 517 | |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 518 | /* Optionally delete the TBF */ |
| 519 | switch (mode) { |
| 520 | case TEST_MODE_DL_AFTER_UL: |
| 521 | case TEST_MODE_UL_AFTER_DL: |
| 522 | tbf_free(tbf); |
Jacob Erlbeck | 0f352a6 | 2015-07-16 18:23:33 +0200 | [diff] [blame] | 523 | tbf = NULL; |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 524 | break; |
| 525 | |
| 526 | default: |
| 527 | break; |
| 528 | } |
| 529 | |
Jacob Erlbeck | 0f352a6 | 2015-07-16 18:23:33 +0200 | [diff] [blame] | 530 | if (!ms && tbf) |
| 531 | tbf_free(tbf); |
| 532 | |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 533 | return guard2.is_idle() ? NULL : ms; |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 534 | } |
| 535 | |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 536 | static unsigned alloc_many_tbfs(BTS *the_bts, unsigned min_class, |
| 537 | unsigned max_class, enum test_mode mode) |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 538 | { |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 539 | unsigned counter; |
| 540 | unsigned ms_class = min_class; |
| 541 | |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 542 | for (counter = 0; 1; counter += 1) { |
| 543 | gprs_rlcmac_tbf *ul_tbf, *dl_tbf; |
| 544 | uint8_t ul_slots = 0; |
| 545 | uint8_t dl_slots = 0; |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 546 | uint8_t busy_slots = 0; |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 547 | unsigned i; |
| 548 | int tfi = -1; |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 549 | int tfi2; |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 550 | uint8_t trx_no2; |
| 551 | struct gprs_rlcmac_trx *trx; |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 552 | GprsMs *ms; |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 553 | enum gprs_rlcmac_tbf_direction dir; |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 554 | uint32_t tlli = counter + 0xc0000000; |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 555 | |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 556 | ms = the_bts->ms_by_tlli(tlli); |
Pau Espin Pedrol | 17402a5 | 2020-05-08 17:44:33 +0200 | [diff] [blame] | 557 | if (!ms) |
| 558 | ms = the_bts->ms_alloc(0, 0); |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 559 | ms->set_ms_class(ms_class); |
| 560 | ms = alloc_tbfs(the_bts, ms, mode); |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 561 | if (!ms) |
| 562 | break; |
| 563 | |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 564 | ms->set_tlli(tlli); |
| 565 | |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 566 | ul_tbf = ms->ul_tbf(); |
| 567 | dl_tbf = ms->dl_tbf(); |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 568 | trx = ms->current_trx(); |
| 569 | |
| 570 | OSMO_ASSERT(ul_tbf || dl_tbf); |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 571 | |
| 572 | if (ul_tbf) { |
| 573 | ul_slots = 1 << ul_tbf->first_common_ts; |
| 574 | tfi = ul_tbf->tfi(); |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 575 | dir = GPRS_RLCMAC_UL_TBF; |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 576 | } else { |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 577 | ul_slots = 1 << dl_tbf->first_common_ts; |
| 578 | tfi = dl_tbf->tfi(); |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 579 | dir = GPRS_RLCMAC_DL_TBF; |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | for (i = 0; dl_tbf && i < ARRAY_SIZE(dl_tbf->pdch); i += 1) |
| 583 | if (dl_tbf->pdch[i]) |
| 584 | dl_slots |= 1 << i; |
| 585 | |
Max | 5b0df1f | 2017-09-11 10:38:59 +0200 | [diff] [blame] | 586 | for (i = 0; ul_tbf && i < ARRAY_SIZE(ul_tbf->pdch); i += 1) |
| 587 | if (ul_tbf->pdch[i]) |
| 588 | ul_slots |= 1 << i; |
| 589 | |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 590 | for (i = 0; trx && i < ARRAY_SIZE(trx->pdch); i += 1) { |
| 591 | struct gprs_rlcmac_pdch *pdch = &trx->pdch[i]; |
| 592 | |
| 593 | if (ul_tbf && dl_tbf) |
| 594 | continue; |
| 595 | |
| 596 | if (ul_tbf && |
Max | d000d80 | 2017-09-20 17:55:28 +0200 | [diff] [blame] | 597 | pdch->assigned_tfi(GPRS_RLCMAC_DL_TBF) != NO_FREE_TFI) |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 598 | continue; |
| 599 | |
| 600 | if (dl_tbf && |
Max | d000d80 | 2017-09-20 17:55:28 +0200 | [diff] [blame] | 601 | pdch->assigned_tfi(GPRS_RLCMAC_UL_TBF) != NO_FREE_TFI) |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 602 | continue; |
| 603 | |
| 604 | busy_slots |= 1 << i; |
| 605 | } |
| 606 | |
Max | d000d80 | 2017-09-20 17:55:28 +0200 | [diff] [blame] | 607 | printf(" TBF[%d] class %d reserves " OSMO_BIT_SPEC "\n", |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 608 | tfi, ms_class, |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 609 | get_dir_char(0x01, ul_slots, dl_slots, busy_slots), |
| 610 | get_dir_char(0x02, ul_slots, dl_slots, busy_slots), |
| 611 | get_dir_char(0x04, ul_slots, dl_slots, busy_slots), |
| 612 | get_dir_char(0x08, ul_slots, dl_slots, busy_slots), |
| 613 | get_dir_char(0x10, ul_slots, dl_slots, busy_slots), |
| 614 | get_dir_char(0x20, ul_slots, dl_slots, busy_slots), |
| 615 | get_dir_char(0x40, ul_slots, dl_slots, busy_slots), |
| 616 | get_dir_char(0x80, ul_slots, dl_slots, busy_slots)); |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 617 | |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 618 | if (tfi >= 0) { |
| 619 | OSMO_ASSERT(ms->current_trx()); |
Jacob Erlbeck | bf90422 | 2015-07-16 18:19:09 +0200 | [diff] [blame] | 620 | tfi2 = the_bts->tfi_find_free(dir, &trx_no2, |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 621 | ms->current_trx()->trx_no); |
| 622 | OSMO_ASSERT(tfi != tfi2); |
Jacob Erlbeck | 7b3675b | 2015-07-16 18:28:22 +0200 | [diff] [blame] | 623 | OSMO_ASSERT(tfi2 < 0 || |
| 624 | trx_no2 == ms->current_trx()->trx_no); |
Jacob Erlbeck | 61205a7 | 2015-07-09 11:35:50 +0200 | [diff] [blame] | 625 | } |
| 626 | |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 627 | ms_class += 1; |
| 628 | if (ms_class > max_class) |
| 629 | ms_class = min_class; |
| 630 | } |
| 631 | |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 632 | return counter; |
| 633 | } |
| 634 | |
| 635 | static void test_successive_allocation(algo_t algo, unsigned min_class, |
| 636 | unsigned max_class, enum test_mode mode, |
| 637 | unsigned expect_num, const char *text) |
| 638 | { |
| 639 | BTS the_bts; |
| 640 | struct gprs_rlcmac_bts *bts; |
| 641 | struct gprs_rlcmac_trx *trx; |
| 642 | unsigned counter; |
| 643 | |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 644 | printf("Going to test assignment with many TBF, algorithm %s class %u..%u (%s)\n", |
| 645 | text, min_class, max_class, test_mode_descr(mode)); |
Jacob Erlbeck | 69c9bfa | 2015-07-13 14:38:18 +0200 | [diff] [blame] | 646 | |
| 647 | bts = the_bts.bts_data(); |
| 648 | bts->alloc_algorithm = algo; |
| 649 | |
| 650 | trx = &bts->trx[0]; |
| 651 | trx->pdch[3].enable(); |
| 652 | trx->pdch[4].enable(); |
| 653 | trx->pdch[5].enable(); |
| 654 | trx->pdch[6].enable(); |
| 655 | trx->pdch[7].enable(); |
| 656 | |
| 657 | counter = alloc_many_tbfs(&the_bts, min_class, max_class, mode); |
| 658 | |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 659 | printf(" Successfully allocated %u UL TBFs, algorithm %s class %u..%u (%s)\n", |
| 660 | counter, text, min_class, max_class, test_mode_descr(mode)); |
Jacob Erlbeck | 88fb613 | 2015-07-16 15:01:38 +0200 | [diff] [blame] | 661 | if (counter != expect_num) |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 662 | fprintf(stderr, " Expected %u TBFs (got %u), algorithm %s class %u..%u (%s)\n", |
| 663 | expect_num, counter, text, min_class, max_class, test_mode_descr(mode)); |
Jacob Erlbeck | 88fb613 | 2015-07-16 15:01:38 +0200 | [diff] [blame] | 664 | |
Jacob Erlbeck | ec47875 | 2015-06-19 16:35:38 +0200 | [diff] [blame] | 665 | OSMO_ASSERT(counter == expect_num); |
Jacob Erlbeck | e0853cd | 2015-07-10 12:25:25 +0200 | [diff] [blame] | 666 | |
| 667 | check_tfi_usage(&the_bts); |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 668 | } |
| 669 | |
Jacob Erlbeck | a8c2aaf | 2015-07-13 14:50:08 +0200 | [diff] [blame] | 670 | static void test_many_connections(algo_t algo, unsigned expect_num, |
| 671 | const char *text) |
| 672 | { |
| 673 | BTS the_bts; |
| 674 | struct gprs_rlcmac_bts *bts; |
| 675 | struct gprs_rlcmac_trx *trx; |
| 676 | int counter1, counter2 = -1; |
| 677 | unsigned i; |
| 678 | enum test_mode mode_seq[] = { |
| 679 | TEST_MODE_DL_AFTER_UL, |
| 680 | TEST_MODE_UL_ONLY, |
| 681 | TEST_MODE_DL_AFTER_UL, |
| 682 | TEST_MODE_DL_ONLY, |
| 683 | }; |
| 684 | |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 685 | printf("Going to test assignment with many connections, algorithm %s\n", text); |
Jacob Erlbeck | a8c2aaf | 2015-07-13 14:50:08 +0200 | [diff] [blame] | 686 | |
| 687 | bts = the_bts.bts_data(); |
| 688 | bts->alloc_algorithm = algo; |
| 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) { |
Max | 9f46071 | 2018-01-23 20:57:08 +0100 | [diff] [blame] | 698 | counter1 = alloc_many_tbfs(&the_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 | |
| 702 | check_tfi_usage(&the_bts); |
| 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); |
| 723 | } |
| 724 | |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 725 | 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] | 726 | { |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 727 | test_successive_allocation(alloc_algorithm_a, 1, 1, mode, exp_A, "A"); |
| 728 | test_successive_allocation(alloc_algorithm_b, 10, 10, mode, exp_B, "B"); |
| 729 | test_successive_allocation(alloc_algorithm_dynamic, 10, 10, mode, exp_dyn, "dynamic"); |
Jacob Erlbeck | e565564 | 2015-06-29 12:19:52 +0200 | [diff] [blame] | 730 | } |
| 731 | |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 732 | static void test_successive_allocations() |
Jacob Erlbeck | a8c2aaf | 2015-07-13 14:50:08 +0200 | [diff] [blame] | 733 | { |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 734 | test_successive_allocation(alloc_algorithm_a, 1, 1, TEST_MODE_UL_AND_DL, 35, "A"); |
| 735 | test_successive_allocation(alloc_algorithm_b, 10, 10, TEST_MODE_UL_AND_DL, 32, "B"); |
| 736 | test_successive_allocation(alloc_algorithm_b, 12, 12, TEST_MODE_UL_AND_DL, 32, "B"); |
| 737 | |
Max | 9f46071 | 2018-01-23 20:57:08 +0100 | [diff] [blame] | 738 | test_successive_allocation(alloc_algorithm_b, 1, 12, TEST_MODE_UL_AND_DL, 32, "B"); |
Max | 01bd0cc | 2018-01-23 20:58:49 +0100 | [diff] [blame] | 739 | test_successive_allocation(alloc_algorithm_b, 1, mslot_class_max(), TEST_MODE_UL_AND_DL, 32, "B"); |
Max | 9f46071 | 2018-01-23 20:57:08 +0100 | [diff] [blame] | 740 | test_successive_allocation(alloc_algorithm_dynamic, 1, mslot_class_max(), TEST_MODE_UL_AND_DL, 35, "dynamic"); |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 741 | |
| 742 | test_a_b_dyn(TEST_MODE_DL_AND_UL, 35, 32, 32); |
| 743 | test_a_b_dyn(TEST_MODE_DL_AFTER_UL, 160, 32, 95); |
| 744 | test_a_b_dyn(TEST_MODE_UL_AFTER_DL, 35, 32, 35); |
| 745 | test_a_b_dyn(TEST_MODE_UL_ONLY, 35, 32, 35); |
| 746 | test_a_b_dyn(TEST_MODE_DL_ONLY, 160, 32, 101); |
Jacob Erlbeck | a8c2aaf | 2015-07-13 14:50:08 +0200 | [diff] [blame] | 747 | } |
| 748 | |
Aravind Sirsikar | e26ee01 | 2016-09-06 18:15:45 +0530 | [diff] [blame] | 749 | static void test_2_consecutive_dl_tbfs() |
| 750 | { |
| 751 | BTS the_bts; |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 752 | GprsMs *ms; |
Aravind Sirsikar | e26ee01 | 2016-09-06 18:15:45 +0530 | [diff] [blame] | 753 | struct gprs_rlcmac_bts *bts; |
| 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 | |
| 762 | bts = the_bts.bts_data(); |
| 763 | bts->alloc_algorithm = alloc_algorithm_b; |
| 764 | |
| 765 | trx = &bts->trx[0]; |
| 766 | trx->pdch[4].enable(); |
| 767 | trx->pdch[5].enable(); |
| 768 | trx->pdch[6].enable(); |
| 769 | trx->pdch[7].enable(); |
| 770 | |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 771 | ms = the_bts.ms_alloc(ms_class, egprs_ms_class); |
| 772 | dl_tbf1 = tbf_alloc_dl_tbf(bts, ms, 0, false); |
Aravind Sirsikar | e26ee01 | 2016-09-06 18:15:45 +0530 | [diff] [blame] | 773 | OSMO_ASSERT(dl_tbf1); |
| 774 | |
| 775 | for (int i = 0; i < 8; i++) { |
| 776 | if (dl_tbf1->pdch[i]) |
| 777 | numTs1++; |
| 778 | } |
| 779 | OSMO_ASSERT(numTs1 == 4); |
| 780 | printf("TBF1: numTs(%d)\n", numTs1); |
| 781 | |
Pau Espin Pedrol | 322456e | 2020-05-08 18:15:59 +0200 | [diff] [blame] | 782 | ms = the_bts.ms_alloc(ms_class, egprs_ms_class); |
| 783 | dl_tbf2 = tbf_alloc_dl_tbf(bts, ms, 0, false); |
Aravind Sirsikar | e26ee01 | 2016-09-06 18:15:45 +0530 | [diff] [blame] | 784 | OSMO_ASSERT(dl_tbf2); |
| 785 | |
| 786 | for (int i = 0; i < 8; i++) { |
| 787 | if (dl_tbf2->pdch[i]) |
| 788 | numTs2++; |
| 789 | } |
| 790 | |
| 791 | /* |
| 792 | * TODO: currently 2nd DL TBF gets 3 TS |
| 793 | * This behaviour will be fixed in subsequent patch |
| 794 | */ |
| 795 | printf("TBF2: numTs(%d)\n", numTs2); |
| 796 | OSMO_ASSERT(numTs2 == 3); |
| 797 | |
| 798 | tbf_free(dl_tbf1); |
| 799 | tbf_free(dl_tbf2); |
| 800 | } |
| 801 | |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 802 | int main(int argc, char **argv) |
| 803 | { |
| 804 | tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile AllocTest context"); |
| 805 | if (!tall_pcu_ctx) |
| 806 | abort(); |
| 807 | |
Neels Hofmeyr | 78ce591 | 2017-02-08 17:07:31 +0100 | [diff] [blame] | 808 | msgb_talloc_ctx_init(tall_pcu_ctx, 0); |
Neels Hofmeyr | 42f2d61 | 2018-04-01 16:54:40 +0200 | [diff] [blame] | 809 | osmo_init_logging2(tall_pcu_ctx, &gprs_log_info); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 810 | log_set_use_color(osmo_stderr_target, 0); |
| 811 | log_set_print_filename(osmo_stderr_target, 0); |
Philipp Maier | de0e558 | 2020-03-25 12:23:52 +0100 | [diff] [blame] | 812 | log_set_category_filter(osmo_stderr_target, DTBF, 1, LOGL_INFO); |
Jacob Erlbeck | 9ec49e2 | 2015-06-29 13:00:20 +0200 | [diff] [blame] | 813 | if (getenv("LOGL_DEBUG")) |
| 814 | log_set_log_level(osmo_stderr_target, LOGL_DEBUG); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 815 | |
| 816 | test_alloc_a(); |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 817 | test_alloc_b(); |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 818 | test_successive_allocations(); |
| 819 | test_many_connections(alloc_algorithm_a, 160, "A"); |
Max | 01bd0cc | 2018-01-23 20:58:49 +0100 | [diff] [blame] | 820 | test_many_connections(alloc_algorithm_b, 32, "B"); |
Max | c59ef12 | 2017-11-27 13:21:41 +0100 | [diff] [blame] | 821 | test_many_connections(alloc_algorithm_dynamic, 160, "dynamic"); |
Aravind Sirsikar | e26ee01 | 2016-09-06 18:15:45 +0530 | [diff] [blame] | 822 | test_2_consecutive_dl_tbfs(); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 823 | return EXIT_SUCCESS; |
| 824 | } |
| 825 | |
| 826 | /* |
| 827 | * stubs that should not be reached |
| 828 | */ |
| 829 | extern "C" { |
| 830 | void l1if_pdch_req() { abort(); } |
| 831 | void l1if_connect_pdch() { abort(); } |
| 832 | void l1if_close_pdch() { abort(); } |
| 833 | void l1if_open_pdch() { abort(); } |
| 834 | } |