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); |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 191 | dl_tbf->m_tlli = 0x23; |
| 192 | dl_tbf->m_tlli_valid = true; |
Jacob Erlbeck | e43460b | 2015-05-13 13:33:12 +0200 | [diff] [blame^] | 193 | dl_tbf->update_ms(dl_tbf->m_tlli); |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 194 | OSMO_ASSERT(dl_tbf); |
| 195 | dump_assignment(dl_tbf, "DL"); |
| 196 | |
| 197 | tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1); |
| 198 | OSMO_ASSERT(tfi >= 0); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 199 | ul_tbf = tbf_alloc_ul_tbf(bts, dl_tbf, tfi, trx_no, ms_class, 0); |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 200 | ul_tbf->m_tlli = 0x23; |
| 201 | ul_tbf->m_tlli_valid = true; |
Jacob Erlbeck | e43460b | 2015-05-13 13:33:12 +0200 | [diff] [blame^] | 202 | ul_tbf->update_ms(ul_tbf->m_tlli); |
Daniel Willmann | 7e994e3 | 2014-08-07 15:49:21 +0200 | [diff] [blame] | 203 | ul_tbf->m_contention_resolution_done = 1; |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 204 | OSMO_ASSERT(ul_tbf); |
| 205 | dump_assignment(ul_tbf, "UL"); |
| 206 | |
Holger Hans Peter Freyther | c7b998c | 2013-12-25 19:25:10 +0100 | [diff] [blame] | 207 | OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts); |
| 208 | |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 209 | /* now update the dl_tbf */ |
| 210 | dl_tbf->update(); |
| 211 | dump_assignment(dl_tbf, "DL"); |
Holger Hans Peter Freyther | c7b998c | 2013-12-25 19:25:10 +0100 | [diff] [blame] | 212 | 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] | 213 | |
| 214 | tbf_free(dl_tbf); |
| 215 | tbf_free(ul_tbf); |
| 216 | } |
| 217 | |
| 218 | /* Andreas osmocom-pcu example */ |
| 219 | { |
| 220 | BTS the_bts; |
| 221 | struct gprs_rlcmac_bts *bts; |
| 222 | struct gprs_rlcmac_trx *trx; |
| 223 | int tfi; |
Jacob Erlbeck | 1f33294 | 2015-05-04 08:21:17 +0200 | [diff] [blame] | 224 | uint8_t trx_no; |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 225 | |
| 226 | gprs_rlcmac_tbf *ul_tbf, *dl_tbf; |
| 227 | |
| 228 | printf("Testing jolly example\n"); |
| 229 | |
| 230 | bts = the_bts.bts_data(); |
| 231 | bts->alloc_algorithm = alloc_algorithm_b; |
| 232 | |
| 233 | trx = &bts->trx[0]; |
| 234 | trx->pdch[1].enable(); |
| 235 | trx->pdch[2].enable(); |
| 236 | trx->pdch[3].enable(); |
| 237 | trx->pdch[4].enable(); |
| 238 | |
| 239 | tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1); |
| 240 | OSMO_ASSERT(tfi >= 0); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 241 | 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] | 242 | OSMO_ASSERT(ul_tbf); |
| 243 | dump_assignment(ul_tbf, "UL"); |
| 244 | |
| 245 | /* assume final ack has not been sent */ |
| 246 | tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1); |
| 247 | OSMO_ASSERT(tfi >= 0); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 248 | 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] | 249 | OSMO_ASSERT(dl_tbf); |
| 250 | dump_assignment(dl_tbf, "DL"); |
| 251 | |
Holger Hans Peter Freyther | c7b998c | 2013-12-25 19:25:10 +0100 | [diff] [blame] | 252 | OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts); |
| 253 | |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 254 | tbf_free(dl_tbf); |
| 255 | tbf_free(ul_tbf); |
| 256 | } |
| 257 | } |
| 258 | |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 259 | #define ENABLE_PDCH(ts_no, enable_flag, trx) \ |
| 260 | if (enable_flag) \ |
| 261 | trx->pdch[ts_no].enable(); |
| 262 | |
| 263 | static void test_alloc_b(bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7, int ms_class) |
| 264 | { |
| 265 | /* we can test the allocation failures differently */ |
| 266 | if (!ts0 && !ts1 && !ts2 && !ts3 && !ts4 && !ts5 && !ts6 && !ts7) |
| 267 | return; |
| 268 | |
| 269 | printf("Mass test: TS0(%c%c%c%c%c%c%c%c)TS7 MS_Class=%d\n", |
| 270 | ts0 ? 'O' : 'x', |
| 271 | ts1 ? 'O' : 'x', |
| 272 | ts2 ? 'O' : 'x', |
| 273 | ts3 ? 'O' : 'x', |
| 274 | ts4 ? 'O' : 'x', |
| 275 | ts5 ? 'O' : 'x', |
| 276 | ts6 ? 'O' : 'x', |
| 277 | ts7 ? 'O' : 'x', ms_class); |
| 278 | fflush(stdout); |
| 279 | |
| 280 | { |
| 281 | BTS the_bts; |
| 282 | struct gprs_rlcmac_bts *bts; |
| 283 | struct gprs_rlcmac_trx *trx; |
| 284 | int tfi; |
Jacob Erlbeck | 1f33294 | 2015-05-04 08:21:17 +0200 | [diff] [blame] | 285 | uint8_t trx_no; |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 286 | |
| 287 | gprs_rlcmac_tbf *ul_tbf, *dl_tbf; |
| 288 | |
| 289 | bts = the_bts.bts_data(); |
| 290 | bts->alloc_algorithm = alloc_algorithm_b; |
| 291 | |
| 292 | trx = &bts->trx[0]; |
| 293 | ENABLE_PDCH(0, ts0, trx); |
| 294 | ENABLE_PDCH(1, ts1, trx); |
| 295 | ENABLE_PDCH(2, ts2, trx); |
| 296 | ENABLE_PDCH(3, ts3, trx); |
| 297 | ENABLE_PDCH(4, ts4, trx); |
| 298 | ENABLE_PDCH(5, ts5, trx); |
| 299 | ENABLE_PDCH(6, ts6, trx); |
| 300 | ENABLE_PDCH(7, ts7, trx); |
| 301 | |
| 302 | tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1); |
| 303 | |
| 304 | OSMO_ASSERT(tfi >= 0); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 305 | 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] | 306 | OSMO_ASSERT(ul_tbf); |
| 307 | |
| 308 | /* assume final ack has not been sent */ |
| 309 | tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1); |
| 310 | OSMO_ASSERT(tfi >= 0); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 311 | 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] | 312 | OSMO_ASSERT(dl_tbf); |
| 313 | |
| 314 | /* verify that both are on the same ts */ |
| 315 | OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts); |
| 316 | |
| 317 | tbf_free(dl_tbf); |
| 318 | tbf_free(ul_tbf); |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * Test with the other order.. first DL and then UL |
| 323 | */ |
| 324 | { |
| 325 | BTS the_bts; |
| 326 | struct gprs_rlcmac_bts *bts; |
| 327 | struct gprs_rlcmac_trx *trx; |
| 328 | int tfi; |
Jacob Erlbeck | 1f33294 | 2015-05-04 08:21:17 +0200 | [diff] [blame] | 329 | uint8_t trx_no; |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 330 | |
Daniel Willmann | 351a573 | 2014-08-07 12:57:44 +0200 | [diff] [blame] | 331 | gprs_rlcmac_ul_tbf *ul_tbf; |
| 332 | gprs_rlcmac_dl_tbf *dl_tbf; |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 333 | |
| 334 | bts = the_bts.bts_data(); |
| 335 | bts->alloc_algorithm = alloc_algorithm_b; |
| 336 | |
| 337 | trx = &bts->trx[0]; |
| 338 | ENABLE_PDCH(0, ts0, trx); |
| 339 | ENABLE_PDCH(1, ts1, trx); |
| 340 | ENABLE_PDCH(2, ts2, trx); |
| 341 | ENABLE_PDCH(3, ts3, trx); |
| 342 | ENABLE_PDCH(4, ts4, trx); |
| 343 | ENABLE_PDCH(5, ts5, trx); |
| 344 | ENABLE_PDCH(6, ts6, trx); |
| 345 | ENABLE_PDCH(7, ts7, trx); |
| 346 | |
| 347 | tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1); |
| 348 | OSMO_ASSERT(tfi >= 0); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 349 | 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] | 350 | OSMO_ASSERT(dl_tbf); |
| 351 | dl_tbf->m_tlli = 0x23; |
| 352 | dl_tbf->m_tlli_valid = true; |
Jacob Erlbeck | e43460b | 2015-05-13 13:33:12 +0200 | [diff] [blame^] | 353 | dl_tbf->update_ms(dl_tbf->m_tlli); |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 354 | |
| 355 | tfi = the_bts.tfi_find_free(GPRS_RLCMAC_UL_TBF, &trx_no, -1); |
| 356 | OSMO_ASSERT(tfi >= 0); |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 357 | 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] | 358 | OSMO_ASSERT(ul_tbf); |
| 359 | ul_tbf->m_tlli = 0x23; |
| 360 | ul_tbf->m_tlli_valid = true; |
Jacob Erlbeck | e43460b | 2015-05-13 13:33:12 +0200 | [diff] [blame^] | 361 | ul_tbf->update_ms(ul_tbf->m_tlli); |
Daniel Willmann | 7e994e3 | 2014-08-07 15:49:21 +0200 | [diff] [blame] | 362 | ul_tbf->m_contention_resolution_done = 1; |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 363 | |
| 364 | OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts); |
| 365 | |
| 366 | /* now update the dl_tbf */ |
| 367 | dl_tbf->update(); |
| 368 | OSMO_ASSERT(dl_tbf->first_common_ts == ul_tbf->first_common_ts); |
| 369 | |
| 370 | tbf_free(dl_tbf); |
| 371 | tbf_free(ul_tbf); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | static void test_all_alloc_b() |
| 376 | { |
| 377 | /* it is a bit crazy... */ |
| 378 | for (uint8_t ts0 = 0; ts0 < 2; ++ts0) |
| 379 | for (uint8_t ts1 = 0; ts1 < 2; ++ts1) |
| 380 | for (uint8_t ts2 = 0; ts2 < 2; ++ts2) |
| 381 | for (uint8_t ts3 = 0; ts3 < 2; ++ts3) |
| 382 | for (uint8_t ts4 = 0; ts4 < 2; ++ts4) |
| 383 | for (uint8_t ts5 = 0; ts5 < 2; ++ts5) |
| 384 | for (uint8_t ts6 = 0; ts6 < 2; ++ts6) |
| 385 | for (uint8_t ts7 = 0; ts7 < 2; ++ts7) |
| 386 | for (int ms_class = 0; ms_class < 30; ++ms_class) |
| 387 | test_alloc_b(ts0, ts1, ts2, ts3, ts4, ts5, ts6, ts7, ms_class); |
| 388 | } |
| 389 | |
Holger Hans Peter Freyther | c7b998c | 2013-12-25 19:25:10 +0100 | [diff] [blame] | 390 | static void test_alloc_b() |
| 391 | { |
| 392 | for (int i = 0; i < 30; ++i) |
| 393 | test_alloc_b(i); |
Holger Hans Peter Freyther | f3eec04 | 2013-12-26 10:19:18 +0100 | [diff] [blame] | 394 | |
| 395 | test_all_alloc_b(); |
Holger Hans Peter Freyther | c7b998c | 2013-12-25 19:25:10 +0100 | [diff] [blame] | 396 | } |
| 397 | |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 398 | int main(int argc, char **argv) |
| 399 | { |
| 400 | tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile AllocTest context"); |
| 401 | if (!tall_pcu_ctx) |
| 402 | abort(); |
| 403 | |
| 404 | msgb_set_talloc_ctx(tall_pcu_ctx); |
| 405 | osmo_init_logging(&gprs_log_info); |
| 406 | log_set_use_color(osmo_stderr_target, 0); |
| 407 | log_set_print_filename(osmo_stderr_target, 0); |
| 408 | |
| 409 | test_alloc_a(); |
Holger Hans Peter Freyther | 4af3053 | 2013-12-25 19:16:55 +0100 | [diff] [blame] | 410 | test_alloc_b(); |
Holger Hans Peter Freyther | bfdd5f2 | 2013-10-16 17:29:31 +0200 | [diff] [blame] | 411 | return EXIT_SUCCESS; |
| 412 | } |
| 413 | |
| 414 | /* |
| 415 | * stubs that should not be reached |
| 416 | */ |
| 417 | extern "C" { |
| 418 | void l1if_pdch_req() { abort(); } |
| 419 | void l1if_connect_pdch() { abort(); } |
| 420 | void l1if_close_pdch() { abort(); } |
| 421 | void l1if_open_pdch() { abort(); } |
| 422 | } |