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