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, |
| 40 | struct gprs_rlcmac_tbf *old_tbf, gprs_rlcmac_tbf_direction dir, |
| 41 | uint8_t tfi, uint8_t trx, |
| 42 | uint8_t ms_class, uint8_t single_slot) |
| 43 | { |
| 44 | if (dir == GPRS_RLCMAC_UL_TBF) |
| 45 | return tbf_alloc_ul_tbf(bts, old_tbf, tfi, trx, ms_class, single_slot); |
| 46 | else |
| 47 | return tbf_alloc_dl_tbf(bts, old_tbf, tfi, trx, ms_class, single_slot); |
| 48 | } |
| 49 | |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 50 | static void test_alloc_a(gprs_rlcmac_tbf_direction dir, const int count) |
| 51 | { |
| 52 | int tfi; |
| 53 | uint8_t used_trx; |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 54 | BTS the_bts; |
| 55 | struct gprs_rlcmac_bts *bts; |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 56 | struct gprs_rlcmac_tbf *tbfs[33] = { 0, }; |
| 57 | |
| 58 | printf("Testing alloc_a direction(%d)\n", dir); |
| 59 | |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 60 | bts = the_bts.bts_data(); |
| 61 | bts->alloc_algorithm = alloc_algorithm_a; |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 62 | |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 63 | struct gprs_rlcmac_trx *trx = &bts->trx[0]; |
Holger Hans Peter Freyther | 17b0d83 | 2013-10-19 17:37:48 +0200 | [diff] [blame] | 64 | trx->pdch[2].enable(); |
| 65 | trx->pdch[3].enable(); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * Currently alloc_a will only allocate from the first |
| 69 | * PDCH and all possible usf's. We run out of usf's before |
| 70 | * we are out of tfi's. Observe this and make sure that at |
| 71 | * least this part is working okay. |
| 72 | */ |
| 73 | for (int i = 0; i < count; ++i) { |
Holger Hans Peter Freyther | 70ddde6 | 2013-10-26 19:17:58 +0200 | [diff] [blame] | 74 | tfi = the_bts.tfi_find_free(dir, &used_trx, 0); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 75 | OSMO_ASSERT(tfi >= 0); |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 76 | tbfs[i] = tbf_alloc(bts, NULL, dir, tfi, used_trx, 0, 0); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /* Now check that there are still some TFIs */ |
Holger Hans Peter Freyther | 70ddde6 | 2013-10-26 19:17:58 +0200 | [diff] [blame] | 80 | tfi = the_bts.tfi_find_free(dir, &used_trx, 0); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 81 | switch (dir) { |
| 82 | case GPRS_RLCMAC_UL_TBF: |
| 83 | OSMO_ASSERT(tfi >= 0); |
| 84 | break; |
| 85 | case GPRS_RLCMAC_DL_TBF: |
| 86 | OSMO_ASSERT(tfi < 0); |
| 87 | break; |
| 88 | } |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 89 | OSMO_ASSERT(!tbf_alloc(bts, NULL, dir, tfi, used_trx, 0, 0)); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 90 | |
Jacob Erlbeck | 1f33294 | 2015-05-04 08:21:17 +0200 | [diff] [blame] | 91 | for (size_t i = 0; i < ARRAY_SIZE(tbfs); ++i) |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 92 | if (tbfs[i]) |
| 93 | tbf_free(tbfs[i]); |
| 94 | |
Holger Hans Peter Freyther | 70ddde6 | 2013-10-26 19:17:58 +0200 | [diff] [blame] | 95 | tfi = the_bts.tfi_find_free(dir, &used_trx, 0); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 96 | OSMO_ASSERT(tfi >= 0); |
| 97 | |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 98 | tbfs[tfi] = tbf_alloc(bts, NULL, dir, tfi, used_trx, 0, 0); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 99 | OSMO_ASSERT(tbfs[tfi]); |
| 100 | tbf_free(tbfs[tfi]); |
| 101 | } |
| 102 | |
| 103 | static void test_alloc_a() |
| 104 | { |
| 105 | test_alloc_a(GPRS_RLCMAC_DL_TBF, 32); |
| 106 | test_alloc_a(GPRS_RLCMAC_UL_TBF, 7); |
| 107 | } |
| 108 | |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 109 | static void dump_assignment(struct gprs_rlcmac_tbf *tbf, const char *dir) |
| 110 | { |
Jacob Erlbeck | 1f33294 | 2015-05-04 08:21:17 +0200 | [diff] [blame] | 111 | 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] | 112 | if (tbf->pdch[i]) |
| 113 | printf("PDCH[%d] is used for %s\n", i, dir); |
| 114 | printf("PDCH[%d] is control_ts for %s\n", tbf->control_ts, dir); |
| 115 | printf("PDCH[%d] is first common for %s\n", tbf->first_common_ts, dir); |
| 116 | } |
| 117 | |
Holger Hans Peter Freyther | c7b998c | 2013-12-25 19:25:10 +0100 | [diff] [blame] | 118 | static void test_alloc_b(int ms_class) |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 119 | { |
Holger Hans Peter Freyther | c7b998c | 2013-12-25 19:25:10 +0100 | [diff] [blame] | 120 | 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] | 121 | /* |
| 122 | * PDCH is on TS 6,7,8 and we start with a UL allocation and |
| 123 | * then follow two DL allocations (once single, once normal). |
| 124 | * |
| 125 | * Uplink assigned and still available.. |
| 126 | */ |
| 127 | { |
| 128 | BTS the_bts; |
| 129 | struct gprs_rlcmac_bts *bts; |
| 130 | struct gprs_rlcmac_trx *trx; |
| 131 | int tfi; |
Jacob Erlbeck | 1f33294 | 2015-05-04 08:21:17 +0200 | [diff] [blame] | 132 | uint8_t trx_no; |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 133 | |
| 134 | gprs_rlcmac_tbf *ul_tbf, *dl_tbf; |
| 135 | |
| 136 | printf("Testing UL then DL assignment.\n"); |
| 137 | |
| 138 | bts = the_bts.bts_data(); |
| 139 | bts->alloc_algorithm = alloc_algorithm_b; |
| 140 | |
| 141 | trx = &bts->trx[0]; |
| 142 | trx->pdch[5].enable(); |
| 143 | trx->pdch[6].enable(); |
| 144 | trx->pdch[7].enable(); |
| 145 | |
| 146 | tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1); |
| 147 | OSMO_ASSERT(tfi >= 0); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 148 | ul_tbf = tbf_alloc_ul_tbf(bts, NULL, tfi, trx_no, ms_class, 1); |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 149 | OSMO_ASSERT(ul_tbf); |
| 150 | dump_assignment(ul_tbf, "UL"); |
| 151 | |
| 152 | /* assume final ack has not been sent */ |
| 153 | tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1); |
| 154 | OSMO_ASSERT(tfi >= 0); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 155 | dl_tbf = tbf_alloc_dl_tbf(bts, ul_tbf, tfi, trx_no, ms_class, 0); |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 156 | OSMO_ASSERT(dl_tbf); |
| 157 | dump_assignment(dl_tbf, "DL"); |
| 158 | |
Holger Hans Peter Freyther | c7b998c | 2013-12-25 19:25:10 +0100 | [diff] [blame] | 159 | OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts); |
| 160 | |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 161 | tbf_free(dl_tbf); |
| 162 | tbf_free(ul_tbf); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Test with the other order.. first DL and then UL |
| 167 | */ |
| 168 | { |
| 169 | BTS the_bts; |
| 170 | struct gprs_rlcmac_bts *bts; |
| 171 | struct gprs_rlcmac_trx *trx; |
| 172 | int tfi; |
Jacob Erlbeck | 1f33294 | 2015-05-04 08:21:17 +0200 | [diff] [blame] | 173 | uint8_t trx_no; |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 174 | |
Daniel Willmann | 351a573 | 2014-08-07 12:57:44 +0200 | [diff] [blame] | 175 | gprs_rlcmac_ul_tbf *ul_tbf; |
| 176 | gprs_rlcmac_dl_tbf *dl_tbf; |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 177 | |
| 178 | printf("Testing DL then UL assignment followed by update\n"); |
| 179 | |
| 180 | bts = the_bts.bts_data(); |
| 181 | bts->alloc_algorithm = alloc_algorithm_b; |
| 182 | |
| 183 | trx = &bts->trx[0]; |
| 184 | trx->pdch[5].enable(); |
| 185 | trx->pdch[6].enable(); |
| 186 | trx->pdch[7].enable(); |
| 187 | |
| 188 | tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1); |
| 189 | OSMO_ASSERT(tfi >= 0); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 190 | dl_tbf = tbf_alloc_dl_tbf(bts, NULL, tfi, trx_no, ms_class, 1); |
Jacob Erlbeck | 767193e | 2015-05-20 12:06:46 +0200 | [diff] [blame] | 191 | dl_tbf->update_ms(0x23, GPRS_RLCMAC_DL_TBF); |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 192 | OSMO_ASSERT(dl_tbf); |
| 193 | dump_assignment(dl_tbf, "DL"); |
| 194 | |
| 195 | tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1); |
| 196 | OSMO_ASSERT(tfi >= 0); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 197 | ul_tbf = tbf_alloc_ul_tbf(bts, dl_tbf, tfi, trx_no, ms_class, 0); |
Jacob Erlbeck | 767193e | 2015-05-20 12:06:46 +0200 | [diff] [blame] | 198 | ul_tbf->update_ms(0x23, GPRS_RLCMAC_UL_TBF); |
Daniel Willmann | 7e994e3 | 2014-08-07 15:49:21 +0200 | [diff] [blame] | 199 | ul_tbf->m_contention_resolution_done = 1; |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 200 | OSMO_ASSERT(ul_tbf); |
| 201 | dump_assignment(ul_tbf, "UL"); |
| 202 | |
Holger Hans Peter Freyther | c7b998c | 2013-12-25 19:25:10 +0100 | [diff] [blame] | 203 | OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts); |
| 204 | |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 205 | /* now update the dl_tbf */ |
| 206 | dl_tbf->update(); |
| 207 | dump_assignment(dl_tbf, "DL"); |
Holger Hans Peter Freyther | c7b998c | 2013-12-25 19:25:10 +0100 | [diff] [blame] | 208 | 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] | 209 | |
| 210 | tbf_free(dl_tbf); |
| 211 | tbf_free(ul_tbf); |
| 212 | } |
| 213 | |
| 214 | /* Andreas osmocom-pcu example */ |
| 215 | { |
| 216 | BTS the_bts; |
| 217 | struct gprs_rlcmac_bts *bts; |
| 218 | struct gprs_rlcmac_trx *trx; |
| 219 | int tfi; |
Jacob Erlbeck | 1f33294 | 2015-05-04 08:21:17 +0200 | [diff] [blame] | 220 | uint8_t trx_no; |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 221 | |
| 222 | gprs_rlcmac_tbf *ul_tbf, *dl_tbf; |
| 223 | |
| 224 | printf("Testing jolly example\n"); |
| 225 | |
| 226 | bts = the_bts.bts_data(); |
| 227 | bts->alloc_algorithm = alloc_algorithm_b; |
| 228 | |
| 229 | trx = &bts->trx[0]; |
| 230 | trx->pdch[1].enable(); |
| 231 | trx->pdch[2].enable(); |
| 232 | trx->pdch[3].enable(); |
| 233 | trx->pdch[4].enable(); |
| 234 | |
| 235 | tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1); |
| 236 | OSMO_ASSERT(tfi >= 0); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 237 | ul_tbf = tbf_alloc_ul_tbf(bts, NULL, tfi, trx_no, ms_class, 0); |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 238 | OSMO_ASSERT(ul_tbf); |
| 239 | dump_assignment(ul_tbf, "UL"); |
| 240 | |
| 241 | /* assume final ack has not been sent */ |
| 242 | tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1); |
| 243 | OSMO_ASSERT(tfi >= 0); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 244 | dl_tbf = tbf_alloc_dl_tbf(bts, ul_tbf, tfi, trx_no, ms_class, 0); |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 245 | OSMO_ASSERT(dl_tbf); |
| 246 | dump_assignment(dl_tbf, "DL"); |
| 247 | |
Holger Hans Peter Freyther | c7b998c | 2013-12-25 19:25:10 +0100 | [diff] [blame] | 248 | OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts); |
| 249 | |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 250 | tbf_free(dl_tbf); |
| 251 | tbf_free(ul_tbf); |
| 252 | } |
| 253 | } |
| 254 | |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 255 | #define ENABLE_PDCH(ts_no, enable_flag, trx) \ |
| 256 | if (enable_flag) \ |
| 257 | trx->pdch[ts_no].enable(); |
| 258 | |
| 259 | static void test_alloc_b(bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7, int ms_class) |
| 260 | { |
| 261 | /* we can test the allocation failures differently */ |
| 262 | if (!ts0 && !ts1 && !ts2 && !ts3 && !ts4 && !ts5 && !ts6 && !ts7) |
| 263 | return; |
| 264 | |
| 265 | printf("Mass test: TS0(%c%c%c%c%c%c%c%c)TS7 MS_Class=%d\n", |
| 266 | ts0 ? 'O' : 'x', |
| 267 | ts1 ? 'O' : 'x', |
| 268 | ts2 ? 'O' : 'x', |
| 269 | ts3 ? 'O' : 'x', |
| 270 | ts4 ? 'O' : 'x', |
| 271 | ts5 ? 'O' : 'x', |
| 272 | ts6 ? 'O' : 'x', |
| 273 | ts7 ? 'O' : 'x', ms_class); |
| 274 | fflush(stdout); |
| 275 | |
| 276 | { |
| 277 | BTS the_bts; |
| 278 | struct gprs_rlcmac_bts *bts; |
| 279 | struct gprs_rlcmac_trx *trx; |
| 280 | int tfi; |
Jacob Erlbeck | 1f33294 | 2015-05-04 08:21:17 +0200 | [diff] [blame] | 281 | uint8_t trx_no; |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 282 | |
| 283 | gprs_rlcmac_tbf *ul_tbf, *dl_tbf; |
| 284 | |
| 285 | bts = the_bts.bts_data(); |
| 286 | bts->alloc_algorithm = alloc_algorithm_b; |
| 287 | |
| 288 | trx = &bts->trx[0]; |
| 289 | ENABLE_PDCH(0, ts0, trx); |
| 290 | ENABLE_PDCH(1, ts1, trx); |
| 291 | ENABLE_PDCH(2, ts2, trx); |
| 292 | ENABLE_PDCH(3, ts3, trx); |
| 293 | ENABLE_PDCH(4, ts4, trx); |
| 294 | ENABLE_PDCH(5, ts5, trx); |
| 295 | ENABLE_PDCH(6, ts6, trx); |
| 296 | ENABLE_PDCH(7, ts7, trx); |
| 297 | |
| 298 | tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1); |
| 299 | |
| 300 | OSMO_ASSERT(tfi >= 0); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 301 | ul_tbf = tbf_alloc_ul_tbf(bts, NULL, tfi, trx_no, ms_class, 1); |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 302 | OSMO_ASSERT(ul_tbf); |
| 303 | |
| 304 | /* assume final ack has not been sent */ |
| 305 | tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1); |
| 306 | OSMO_ASSERT(tfi >= 0); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 307 | dl_tbf = tbf_alloc_dl_tbf(bts, ul_tbf, tfi, trx_no, ms_class, 0); |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 308 | OSMO_ASSERT(dl_tbf); |
| 309 | |
| 310 | /* verify that both are on the same ts */ |
| 311 | OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts); |
| 312 | |
| 313 | tbf_free(dl_tbf); |
| 314 | tbf_free(ul_tbf); |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * Test with the other order.. first DL and then UL |
| 319 | */ |
| 320 | { |
| 321 | BTS the_bts; |
| 322 | struct gprs_rlcmac_bts *bts; |
| 323 | struct gprs_rlcmac_trx *trx; |
| 324 | int tfi; |
Jacob Erlbeck | 1f33294 | 2015-05-04 08:21:17 +0200 | [diff] [blame] | 325 | uint8_t trx_no; |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 326 | |
Daniel Willmann | 351a573 | 2014-08-07 12:57:44 +0200 | [diff] [blame] | 327 | gprs_rlcmac_ul_tbf *ul_tbf; |
| 328 | gprs_rlcmac_dl_tbf *dl_tbf; |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 329 | |
| 330 | bts = the_bts.bts_data(); |
| 331 | bts->alloc_algorithm = alloc_algorithm_b; |
| 332 | |
| 333 | trx = &bts->trx[0]; |
| 334 | ENABLE_PDCH(0, ts0, trx); |
| 335 | ENABLE_PDCH(1, ts1, trx); |
| 336 | ENABLE_PDCH(2, ts2, trx); |
| 337 | ENABLE_PDCH(3, ts3, trx); |
| 338 | ENABLE_PDCH(4, ts4, trx); |
| 339 | ENABLE_PDCH(5, ts5, trx); |
| 340 | ENABLE_PDCH(6, ts6, trx); |
| 341 | ENABLE_PDCH(7, ts7, trx); |
| 342 | |
| 343 | tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1); |
| 344 | OSMO_ASSERT(tfi >= 0); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 345 | dl_tbf = tbf_alloc_dl_tbf(bts, NULL, tfi, trx_no, ms_class, 1); |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 346 | OSMO_ASSERT(dl_tbf); |
Jacob Erlbeck | 767193e | 2015-05-20 12:06:46 +0200 | [diff] [blame] | 347 | dl_tbf->update_ms(0x23, GPRS_RLCMAC_DL_TBF); |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 348 | |
| 349 | tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1); |
| 350 | OSMO_ASSERT(tfi >= 0); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 351 | ul_tbf = tbf_alloc_ul_tbf(bts, dl_tbf, tfi, trx_no, ms_class, 0); |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 352 | OSMO_ASSERT(ul_tbf); |
Jacob Erlbeck | 767193e | 2015-05-20 12:06:46 +0200 | [diff] [blame] | 353 | ul_tbf->update_ms(0x23, GPRS_RLCMAC_UL_TBF); |
Daniel Willmann | 7e994e3 | 2014-08-07 15:49:21 +0200 | [diff] [blame] | 354 | ul_tbf->m_contention_resolution_done = 1; |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 355 | |
| 356 | OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts); |
| 357 | |
| 358 | /* now update the dl_tbf */ |
| 359 | dl_tbf->update(); |
| 360 | OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts); |
| 361 | |
Jacob Erlbeck | befc760 | 2015-06-02 12:33:30 +0200 | [diff] [blame] | 362 | OSMO_ASSERT(ul_tbf->ms_class() == ms_class); |
| 363 | OSMO_ASSERT(dl_tbf->ms_class() == ms_class); |
| 364 | |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 365 | tbf_free(dl_tbf); |
| 366 | tbf_free(ul_tbf); |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | static void test_all_alloc_b() |
| 371 | { |
| 372 | /* it is a bit crazy... */ |
| 373 | for (uint8_t ts0 = 0; ts0 < 2; ++ts0) |
| 374 | for (uint8_t ts1 = 0; ts1 < 2; ++ts1) |
| 375 | for (uint8_t ts2 = 0; ts2 < 2; ++ts2) |
| 376 | for (uint8_t ts3 = 0; ts3 < 2; ++ts3) |
| 377 | for (uint8_t ts4 = 0; ts4 < 2; ++ts4) |
| 378 | for (uint8_t ts5 = 0; ts5 < 2; ++ts5) |
| 379 | for (uint8_t ts6 = 0; ts6 < 2; ++ts6) |
| 380 | for (uint8_t ts7 = 0; ts7 < 2; ++ts7) |
| 381 | for (int ms_class = 0; ms_class < 30; ++ms_class) |
| 382 | test_alloc_b(ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7, ms_class); |
| 383 | } |
| 384 | |
Holger Hans Peter Freyther | c7b998c | 2013-12-25 19:25:10 +0100 | [diff] [blame] | 385 | static void test_alloc_b() |
| 386 | { |
| 387 | for (int i = 0; i < 30; ++i) |
| 388 | test_alloc_b(i); |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 389 | |
| 390 | test_all_alloc_b(); |
Holger Hans Peter Freyther | c7b998c | 2013-12-25 19:25:10 +0100 | [diff] [blame] | 391 | } |
| 392 | |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 393 | int main(int argc, char **argv) |
| 394 | { |
| 395 | tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile AllocTest context"); |
| 396 | if (!tall_pcu_ctx) |
| 397 | abort(); |
| 398 | |
| 399 | msgb_set_talloc_ctx(tall_pcu_ctx); |
| 400 | osmo_init_logging(&gprs_log_info); |
| 401 | log_set_use_color(osmo_stderr_target, 0); |
| 402 | log_set_print_filename(osmo_stderr_target, 0); |
| 403 | |
| 404 | test_alloc_a(); |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 405 | test_alloc_b(); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 406 | return EXIT_SUCCESS; |
| 407 | } |
| 408 | |
| 409 | /* |
| 410 | * stubs that should not be reached |
| 411 | */ |
| 412 | extern "C" { |
| 413 | void l1if_pdch_req() { abort(); } |
| 414 | void l1if_connect_pdch() { abort(); } |
| 415 | void l1if_close_pdch() { abort(); } |
| 416 | void l1if_open_pdch() { abort(); } |
| 417 | } |