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