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 | */ |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 47 | gprs_rlcmac_tbf *dl_tbf = tbf_alloc_dl_tbf(the_bts.bts_data(), |
| 48 | NULL, 0, |
Holger Hans Peter Freyther | b809866 | 2013-10-30 14:50:17 +0100 | [diff] [blame] | 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 | |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 55 | gprs_rlcmac_tbf *ul_tbf = tbf_alloc_ul_tbf(the_bts.bts_data(), |
| 56 | ul_tbf, 0, |
Holger Hans Peter Freyther | b809866 | 2013-10-30 14:50:17 +0100 | [diff] [blame] | 57 | 0, 0, 0); |
| 58 | ul_tbf->update_tlli(0x2342); |
| 59 | ul_tbf->tlli_mark_valid(); |
| 60 | |
| 61 | |
Daniel Willmann | b59d61b | 2014-07-02 17:58:14 +0200 | [diff] [blame] | 62 | OSMO_ASSERT(the_bts.dl_tbf_by_tlli(0x2342) == dl_tbf); |
| 63 | OSMO_ASSERT(the_bts.ul_tbf_by_tlli(0x2342) == ul_tbf); |
Holger Hans Peter Freyther | b809866 | 2013-10-30 14:50:17 +0100 | [diff] [blame] | 64 | |
| 65 | |
| 66 | /* |
| 67 | * Now check.. that DL changes and that the timing advance |
| 68 | * has changed. |
| 69 | */ |
| 70 | dl_tbf->update_tlli(0x4232); |
Daniel Willmann | b59d61b | 2014-07-02 17:58:14 +0200 | [diff] [blame] | 71 | OSMO_ASSERT(!the_bts.dl_tbf_by_tlli(0x2342)); |
| 72 | OSMO_ASSERT(!the_bts.ul_tbf_by_tlli(0x2342)); |
Holger Hans Peter Freyther | b809866 | 2013-10-30 14:50:17 +0100 | [diff] [blame] | 73 | |
| 74 | |
Daniel Willmann | b59d61b | 2014-07-02 17:58:14 +0200 | [diff] [blame] | 75 | OSMO_ASSERT(the_bts.dl_tbf_by_tlli(0x4232) == dl_tbf); |
| 76 | OSMO_ASSERT(the_bts.ul_tbf_by_tlli(0x4232) == 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 | |
Daniel Willmann | 510d7d3 | 2014-08-15 18:19:41 +0200 | [diff] [blame] | 81 | static uint8_t llc_data[200]; |
| 82 | |
| 83 | int pcu_sock_send(struct msgb *msg) |
| 84 | { |
| 85 | return 0; |
| 86 | } |
| 87 | |
Jacob Erlbeck | 5e9f40d | 2015-02-23 14:26:59 +0100 | [diff] [blame^] | 88 | enum test_tbf_final_ack_mode { |
| 89 | TEST_MODE_STANDARD, |
| 90 | TEST_MODE_REVERSE_FREE |
| 91 | }; |
| 92 | |
| 93 | static void test_tbf_final_ack(enum test_tbf_final_ack_mode test_mode) |
Daniel Willmann | 510d7d3 | 2014-08-15 18:19:41 +0200 | [diff] [blame] | 94 | { |
| 95 | BTS the_bts; |
| 96 | gprs_rlcmac_bts *bts; |
| 97 | gprs_rlcmac_trx *trx; |
| 98 | gprs_rlcmac_pdch * pdch; |
| 99 | int tfi, i; |
| 100 | uint8_t ts_no, trx_no; |
| 101 | uint8_t ms_class = 45; |
| 102 | uint32_t fn; |
| 103 | |
| 104 | uint8_t rbb[64/8]; |
| 105 | |
| 106 | struct msgb *dl_msg; |
| 107 | gprs_rlcmac_dl_tbf *dl_tbf; |
| 108 | gprs_rlcmac_tbf *new_tbf; |
| 109 | |
| 110 | bts = the_bts.bts_data(); |
| 111 | bts->alloc_algorithm = alloc_algorithm_a; |
| 112 | trx = &bts->trx[0]; |
| 113 | |
| 114 | ts_no = 4; |
| 115 | trx->pdch[ts_no].enable(); |
| 116 | pdch = &trx->pdch[ts_no]; |
| 117 | |
| 118 | tfi = the_bts.tfi_find_free(GPRS_RLCMAC_DL_TBF, &trx_no, -1); |
| 119 | OSMO_ASSERT(tfi >= 0); |
| 120 | dl_tbf = tbf_alloc_dl_tbf(bts, NULL, tfi, trx_no, ms_class, 1); |
| 121 | OSMO_ASSERT(dl_tbf); |
| 122 | |
| 123 | /* "Establish" the DL TBF */ |
| 124 | dl_tbf->dl_ass_state = GPRS_RLCMAC_DL_ASS_SEND_ASS; |
| 125 | dl_tbf->set_state(GPRS_RLCMAC_FLOW); |
| 126 | dl_tbf->m_wait_confirm = 0; |
| 127 | dl_tbf->set_new_tbf(dl_tbf); |
| 128 | |
| 129 | for (i = 0; i < sizeof(llc_data); i++) |
| 130 | llc_data[i] = i%256; |
| 131 | |
| 132 | /* Schedule two blocks */ |
Daniel Willmann | 0f58af6 | 2014-09-19 11:57:21 +0200 | [diff] [blame] | 133 | dl_tbf->append_data(ms_class, 1000, llc_data, sizeof(llc_data)); |
| 134 | dl_tbf->append_data(ms_class, 1000, llc_data, sizeof(llc_data)); |
Daniel Willmann | 510d7d3 | 2014-08-15 18:19:41 +0200 | [diff] [blame] | 135 | |
| 136 | |
| 137 | /* FIXME: Need correct frame number here? */ |
| 138 | fn = 0; |
| 139 | for (; fn < 3; fn++) { |
| 140 | /* Request to send one block */ |
| 141 | gprs_rlcmac_rcv_rts_block(bts, trx_no, ts_no, 0, fn, 0); |
| 142 | } |
| 143 | |
| 144 | /* Queue a final ACK */ |
| 145 | memset(rbb, 0, sizeof(rbb)); |
| 146 | /* Receive a final ACK */ |
| 147 | dl_tbf->rcvd_dl_ack(1, 1, rbb); |
| 148 | |
| 149 | /* Clean up and ensure tbfs are in the correct state */ |
| 150 | OSMO_ASSERT(dl_tbf->state_is(GPRS_RLCMAC_WAIT_RELEASE)); |
| 151 | new_tbf = dl_tbf->new_tbf(); |
| 152 | OSMO_ASSERT(new_tbf != dl_tbf); |
| 153 | OSMO_ASSERT(new_tbf->tfi() == 1); |
| 154 | dl_tbf->dl_ass_state = GPRS_RLCMAC_DL_ASS_NONE; |
Jacob Erlbeck | 5e9f40d | 2015-02-23 14:26:59 +0100 | [diff] [blame^] | 155 | if (test_mode == TEST_MODE_REVERSE_FREE) { |
| 156 | tbf_free(new_tbf); |
| 157 | if (dl_tbf->m_new_tbf == new_tbf) |
| 158 | fprintf(stderr, "dangling m_new_tbf pointer in dl_tbf " |
| 159 | "(known bug)\n"); |
| 160 | /* OSMO_ASSERT(dl_tbf->m_new_tbf != new_tbf); */ |
| 161 | tbf_free(dl_tbf); |
| 162 | } else { |
| 163 | tbf_free(dl_tbf); |
| 164 | OSMO_ASSERT(new_tbf->m_new_tbf != dl_tbf); |
| 165 | tbf_free(new_tbf); |
| 166 | } |
Daniel Willmann | 510d7d3 | 2014-08-15 18:19:41 +0200 | [diff] [blame] | 167 | } |
| 168 | |
Daniel Willmann | 341689d | 2014-06-11 18:33:14 +0200 | [diff] [blame] | 169 | static const struct log_info_cat default_categories[] = { |
| 170 | {"DCSN1", "\033[1;31m", "Concrete Syntax Notation One (CSN1)", LOGL_INFO, 0}, |
| 171 | {"DL1IF", "\033[1;32m", "GPRS PCU L1 interface (L1IF)", LOGL_DEBUG, 1}, |
| 172 | {"DRLCMAC", "\033[0;33m", "GPRS RLC/MAC layer (RLCMAC)", LOGL_DEBUG, 1}, |
| 173 | {"DRLCMACDATA", "\033[0;33m", "GPRS RLC/MAC layer Data (RLCMAC)", LOGL_DEBUG, 1}, |
| 174 | {"DRLCMACDL", "\033[1;33m", "GPRS RLC/MAC layer Downlink (RLCMAC)", LOGL_DEBUG, 1}, |
| 175 | {"DRLCMACUL", "\033[1;36m", "GPRS RLC/MAC layer Uplink (RLCMAC)", LOGL_DEBUG, 1}, |
| 176 | {"DRLCMACSCHED", "\033[0;36m", "GPRS RLC/MAC layer Scheduling (RLCMAC)", LOGL_DEBUG, 1}, |
| 177 | {"DRLCMACMEAS", "\033[1;31m", "GPRS RLC/MAC layer Measurements (RLCMAC)", LOGL_INFO, 1}, |
| 178 | {"DBSSGP","\033[1;34m", "GPRS BSS Gateway Protocol (BSSGP)", LOGL_INFO , 1}, |
| 179 | {"DPCU", "\033[1;35m", "GPRS Packet Control Unit (PCU)", LOGL_NOTICE, 1}, |
| 180 | }; |
| 181 | |
| 182 | static int filter_fn(const struct log_context *ctx, |
| 183 | struct log_target *tar) |
| 184 | { |
| 185 | return 1; |
| 186 | } |
| 187 | |
| 188 | const struct log_info debug_log_info = { |
| 189 | filter_fn, |
| 190 | (struct log_info_cat*)default_categories, |
| 191 | ARRAY_SIZE(default_categories), |
| 192 | }; |
| 193 | |
Holger Hans Peter Freyther | b809866 | 2013-10-30 14:50:17 +0100 | [diff] [blame] | 194 | int main(int argc, char **argv) |
| 195 | { |
| 196 | tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile TbfTest context"); |
| 197 | if (!tall_pcu_ctx) |
| 198 | abort(); |
| 199 | |
| 200 | msgb_set_talloc_ctx(tall_pcu_ctx); |
Daniel Willmann | 341689d | 2014-06-11 18:33:14 +0200 | [diff] [blame] | 201 | osmo_init_logging(&debug_log_info); |
Holger Hans Peter Freyther | b809866 | 2013-10-30 14:50:17 +0100 | [diff] [blame] | 202 | log_set_use_color(osmo_stderr_target, 0); |
| 203 | log_set_print_filename(osmo_stderr_target, 0); |
| 204 | |
| 205 | test_tbf_tlli_update(); |
Jacob Erlbeck | 5e9f40d | 2015-02-23 14:26:59 +0100 | [diff] [blame^] | 206 | test_tbf_final_ack(TEST_MODE_STANDARD); |
| 207 | test_tbf_final_ack(TEST_MODE_REVERSE_FREE); |
Holger Hans Peter Freyther | b809866 | 2013-10-30 14:50:17 +0100 | [diff] [blame] | 208 | return EXIT_SUCCESS; |
| 209 | } |
| 210 | |
| 211 | /* |
| 212 | * stubs that should not be reached |
| 213 | */ |
| 214 | extern "C" { |
| 215 | void l1if_pdch_req() { abort(); } |
| 216 | void l1if_connect_pdch() { abort(); } |
| 217 | void l1if_close_pdch() { abort(); } |
| 218 | void l1if_open_pdch() { abort(); } |
| 219 | } |