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