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