Holger Hans Peter Freyther | b809866 | 2013-10-30 14:50:17 +0100 | [diff] [blame] | 1 | /* |
| 2 | * TbfTest.cpp |
| 3 | * |
| 4 | * Copyright (C) 2013 by Holger Hans Peter Freyther |
| 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU Affero General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Affero General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include "bts.h" |
| 24 | #include "tbf.h" |
| 25 | #include "gprs_debug.h" |
| 26 | |
| 27 | extern "C" { |
| 28 | #include <osmocom/core/application.h> |
| 29 | #include <osmocom/core/msgb.h> |
| 30 | #include <osmocom/core/talloc.h> |
| 31 | #include <osmocom/core/utils.h> |
| 32 | } |
| 33 | |
| 34 | void *tall_pcu_ctx; |
| 35 | int16_t spoof_mnc = 0, spoof_mcc = 0; |
| 36 | |
| 37 | static void test_tbf_tlli_update() |
| 38 | { |
| 39 | BTS the_bts; |
| 40 | the_bts.bts_data()->alloc_algorithm = alloc_algorithm_a; |
| 41 | the_bts.bts_data()->trx[0].pdch[2].enable(); |
| 42 | the_bts.bts_data()->trx[0].pdch[3].enable(); |
| 43 | |
| 44 | /* |
| 45 | * Make a uplink and downlink allocation |
| 46 | */ |
| 47 | gprs_rlcmac_tbf *dl_tbf = tbf_alloc(the_bts.bts_data(), |
| 48 | NULL, GPRS_RLCMAC_DL_TBF, 0, |
| 49 | 0, 0, 0); |
| 50 | dl_tbf->update_tlli(0x2342); |
| 51 | dl_tbf->tlli_mark_valid(); |
| 52 | dl_tbf->ta = 4; |
| 53 | the_bts.timing_advance()->remember(0x2342, dl_tbf->ta); |
| 54 | |
| 55 | gprs_rlcmac_tbf *ul_tbf = tbf_alloc(the_bts.bts_data(), |
| 56 | ul_tbf, GPRS_RLCMAC_UL_TBF, 0, |
| 57 | 0, 0, 0); |
| 58 | ul_tbf->update_tlli(0x2342); |
| 59 | ul_tbf->tlli_mark_valid(); |
| 60 | |
| 61 | |
| 62 | OSMO_ASSERT(the_bts.tbf_by_tlli(0x2342, GPRS_RLCMAC_DL_TBF) == dl_tbf); |
| 63 | OSMO_ASSERT(the_bts.tbf_by_tlli(0x2342, GPRS_RLCMAC_UL_TBF) == ul_tbf); |
| 64 | |
| 65 | |
| 66 | /* |
| 67 | * Now check.. that DL changes and that the timing advance |
| 68 | * has changed. |
| 69 | */ |
| 70 | dl_tbf->update_tlli(0x4232); |
| 71 | OSMO_ASSERT(!the_bts.tbf_by_tlli(0x2342, GPRS_RLCMAC_DL_TBF)); |
| 72 | OSMO_ASSERT(!the_bts.tbf_by_tlli(0x2342, GPRS_RLCMAC_UL_TBF)); |
| 73 | |
| 74 | |
| 75 | OSMO_ASSERT(the_bts.tbf_by_tlli(0x4232, GPRS_RLCMAC_DL_TBF) == dl_tbf); |
| 76 | OSMO_ASSERT(the_bts.tbf_by_tlli(0x4232, GPRS_RLCMAC_UL_TBF) == ul_tbf); |
Holger Hans Peter Freyther | bc1626e | 2013-10-30 19:50:49 +0100 | [diff] [blame] | 77 | |
| 78 | OSMO_ASSERT(the_bts.timing_advance()->recall(0x4232) == 4); |
Holger Hans Peter Freyther | b809866 | 2013-10-30 14:50:17 +0100 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | int main(int argc, char **argv) |
| 82 | { |
| 83 | tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile TbfTest context"); |
| 84 | if (!tall_pcu_ctx) |
| 85 | abort(); |
| 86 | |
| 87 | msgb_set_talloc_ctx(tall_pcu_ctx); |
| 88 | osmo_init_logging(&gprs_log_info); |
| 89 | log_set_use_color(osmo_stderr_target, 0); |
| 90 | log_set_print_filename(osmo_stderr_target, 0); |
| 91 | |
| 92 | test_tbf_tlli_update(); |
| 93 | return EXIT_SUCCESS; |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * stubs that should not be reached |
| 98 | */ |
| 99 | extern "C" { |
| 100 | void l1if_pdch_req() { abort(); } |
| 101 | void l1if_connect_pdch() { abort(); } |
| 102 | void l1if_close_pdch() { abort(); } |
| 103 | void l1if_open_pdch() { abort(); } |
| 104 | } |