Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 1 | /* |
| 2 | * MsTest.cpp |
| 3 | * |
| 4 | * Copyright (C) 2015 by Sysmocom s.f.m.c. GmbH |
| 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 "tbf.h" |
| 24 | #include "gprs_debug.h" |
| 25 | #include "gprs_ms.h" |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 26 | #include "gprs_ms_storage.h" |
Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 27 | |
| 28 | extern "C" { |
| 29 | #include "pcu_vty.h" |
| 30 | |
| 31 | #include <osmocom/core/application.h> |
| 32 | #include <osmocom/core/msgb.h> |
| 33 | #include <osmocom/core/talloc.h> |
| 34 | #include <osmocom/core/utils.h> |
| 35 | #include <osmocom/vty/vty.h> |
| 36 | } |
| 37 | |
| 38 | #include <errno.h> |
Jacob Erlbeck | d9e1024 | 2015-05-28 15:43:53 +0200 | [diff] [blame] | 39 | #include <unistd.h> |
Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 40 | |
| 41 | void *tall_pcu_ctx; |
| 42 | int16_t spoof_mnc = 0, spoof_mcc = 0; |
| 43 | |
| 44 | static void test_ms_state() |
| 45 | { |
| 46 | uint32_t tlli = 0xffeeddbb; |
| 47 | gprs_rlcmac_dl_tbf *dl_tbf; |
| 48 | gprs_rlcmac_ul_tbf *ul_tbf; |
| 49 | GprsMs *ms; |
| 50 | |
| 51 | printf("=== start %s ===\n", __func__); |
| 52 | |
Jacob Erlbeck | 17214bb | 2015-06-02 14:06:12 +0200 | [diff] [blame] | 53 | ms = new GprsMs(NULL, tlli); |
Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 54 | OSMO_ASSERT(ms->is_idle()); |
| 55 | |
| 56 | dl_tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_dl_tbf); |
| 57 | dl_tbf->direction = GPRS_RLCMAC_DL_TBF; |
| 58 | ul_tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf); |
| 59 | ul_tbf->direction = GPRS_RLCMAC_UL_TBF; |
| 60 | |
| 61 | ms->attach_tbf(ul_tbf); |
| 62 | OSMO_ASSERT(!ms->is_idle()); |
| 63 | OSMO_ASSERT(ms->ul_tbf() == ul_tbf); |
| 64 | OSMO_ASSERT(ms->dl_tbf() == NULL); |
| 65 | |
| 66 | ms->attach_tbf(dl_tbf); |
| 67 | OSMO_ASSERT(!ms->is_idle()); |
| 68 | OSMO_ASSERT(ms->ul_tbf() == ul_tbf); |
| 69 | OSMO_ASSERT(ms->dl_tbf() == dl_tbf); |
| 70 | |
| 71 | ms->detach_tbf(ul_tbf); |
| 72 | OSMO_ASSERT(!ms->is_idle()); |
| 73 | OSMO_ASSERT(ms->ul_tbf() == NULL); |
| 74 | OSMO_ASSERT(ms->dl_tbf() == dl_tbf); |
| 75 | |
| 76 | ms->detach_tbf(dl_tbf); |
| 77 | /* The ms object is freed now */ |
| 78 | ms = NULL; |
| 79 | |
| 80 | talloc_free(dl_tbf); |
| 81 | talloc_free(ul_tbf); |
| 82 | |
| 83 | printf("=== end %s ===\n", __func__); |
| 84 | } |
| 85 | |
| 86 | static void test_ms_callback() |
| 87 | { |
| 88 | uint32_t tlli = 0xffeeddbb; |
| 89 | gprs_rlcmac_dl_tbf *dl_tbf; |
| 90 | gprs_rlcmac_ul_tbf *ul_tbf; |
| 91 | GprsMs *ms; |
| 92 | static enum {UNKNOWN, IS_IDLE, IS_ACTIVE} last_cb = UNKNOWN; |
| 93 | |
| 94 | struct MyCallback: public GprsMs::Callback { |
| 95 | virtual void ms_idle(class GprsMs *ms) { |
| 96 | OSMO_ASSERT(ms->is_idle()); |
| 97 | printf(" ms_idle() was called\n"); |
| 98 | last_cb = IS_IDLE; |
| 99 | } |
| 100 | virtual void ms_active(class GprsMs *ms) { |
| 101 | OSMO_ASSERT(!ms->is_idle()); |
| 102 | printf(" ms_active() was called\n"); |
| 103 | last_cb = IS_ACTIVE; |
| 104 | } |
| 105 | } cb; |
| 106 | |
| 107 | printf("=== start %s ===\n", __func__); |
| 108 | |
Jacob Erlbeck | 17214bb | 2015-06-02 14:06:12 +0200 | [diff] [blame] | 109 | ms = new GprsMs(NULL, tlli); |
Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 110 | ms->set_callback(&cb); |
| 111 | |
| 112 | OSMO_ASSERT(ms->is_idle()); |
| 113 | |
| 114 | dl_tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_dl_tbf); |
| 115 | dl_tbf->direction = GPRS_RLCMAC_DL_TBF; |
| 116 | ul_tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf); |
| 117 | ul_tbf->direction = GPRS_RLCMAC_UL_TBF; |
| 118 | |
| 119 | OSMO_ASSERT(last_cb == UNKNOWN); |
| 120 | |
| 121 | ms->attach_tbf(ul_tbf); |
| 122 | OSMO_ASSERT(!ms->is_idle()); |
| 123 | OSMO_ASSERT(ms->ul_tbf() == ul_tbf); |
| 124 | OSMO_ASSERT(ms->dl_tbf() == NULL); |
| 125 | OSMO_ASSERT(last_cb == IS_ACTIVE); |
| 126 | |
| 127 | last_cb = UNKNOWN; |
| 128 | |
| 129 | ms->attach_tbf(dl_tbf); |
| 130 | OSMO_ASSERT(!ms->is_idle()); |
| 131 | OSMO_ASSERT(ms->ul_tbf() == ul_tbf); |
| 132 | OSMO_ASSERT(ms->dl_tbf() == dl_tbf); |
| 133 | OSMO_ASSERT(last_cb == UNKNOWN); |
| 134 | |
| 135 | ms->detach_tbf(ul_tbf); |
| 136 | OSMO_ASSERT(!ms->is_idle()); |
| 137 | OSMO_ASSERT(ms->ul_tbf() == NULL); |
| 138 | OSMO_ASSERT(ms->dl_tbf() == dl_tbf); |
| 139 | OSMO_ASSERT(last_cb == UNKNOWN); |
| 140 | |
| 141 | ms->detach_tbf(dl_tbf); |
| 142 | OSMO_ASSERT(ms->is_idle()); |
| 143 | OSMO_ASSERT(ms->ul_tbf() == NULL); |
| 144 | OSMO_ASSERT(ms->dl_tbf() == NULL); |
| 145 | OSMO_ASSERT(last_cb == IS_IDLE); |
| 146 | |
| 147 | last_cb = UNKNOWN; |
| 148 | delete ms; |
| 149 | |
| 150 | talloc_free(dl_tbf); |
| 151 | talloc_free(ul_tbf); |
| 152 | |
| 153 | printf("=== end %s ===\n", __func__); |
| 154 | } |
| 155 | |
| 156 | static void test_ms_replace_tbf() |
| 157 | { |
| 158 | uint32_t tlli = 0xffeeddbb; |
| 159 | gprs_rlcmac_dl_tbf *dl_tbf[2]; |
| 160 | gprs_rlcmac_ul_tbf *ul_tbf; |
| 161 | GprsMs *ms; |
| 162 | static bool was_idle; |
| 163 | |
| 164 | struct MyCallback: public GprsMs::Callback { |
| 165 | virtual void ms_idle(class GprsMs *ms) { |
| 166 | OSMO_ASSERT(ms->is_idle()); |
| 167 | printf(" ms_idle() was called\n"); |
| 168 | was_idle = true; |
| 169 | } |
| 170 | virtual void ms_active(class GprsMs *ms) { |
| 171 | OSMO_ASSERT(!ms->is_idle()); |
| 172 | printf(" ms_active() was called\n"); |
| 173 | } |
| 174 | } cb; |
| 175 | |
| 176 | printf("=== start %s ===\n", __func__); |
| 177 | |
Jacob Erlbeck | 17214bb | 2015-06-02 14:06:12 +0200 | [diff] [blame] | 178 | ms = new GprsMs(NULL, tlli); |
Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 179 | ms->set_callback(&cb); |
| 180 | |
| 181 | OSMO_ASSERT(ms->is_idle()); |
| 182 | was_idle = false; |
| 183 | |
| 184 | dl_tbf[0] = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_dl_tbf); |
| 185 | dl_tbf[0]->direction = GPRS_RLCMAC_DL_TBF; |
| 186 | dl_tbf[1] = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_dl_tbf); |
| 187 | dl_tbf[1]->direction = GPRS_RLCMAC_DL_TBF; |
| 188 | ul_tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf); |
| 189 | ul_tbf->direction = GPRS_RLCMAC_UL_TBF; |
| 190 | |
| 191 | ms->attach_tbf(dl_tbf[0]); |
| 192 | OSMO_ASSERT(!ms->is_idle()); |
| 193 | OSMO_ASSERT(ms->ul_tbf() == NULL); |
| 194 | OSMO_ASSERT(ms->dl_tbf() == dl_tbf[0]); |
| 195 | OSMO_ASSERT(!was_idle); |
| 196 | |
| 197 | ms->attach_tbf(dl_tbf[1]); |
| 198 | OSMO_ASSERT(!ms->is_idle()); |
| 199 | OSMO_ASSERT(ms->ul_tbf() == NULL); |
| 200 | OSMO_ASSERT(ms->dl_tbf() == dl_tbf[1]); |
| 201 | OSMO_ASSERT(!was_idle); |
| 202 | |
| 203 | ms->attach_tbf(ul_tbf); |
| 204 | OSMO_ASSERT(!ms->is_idle()); |
| 205 | OSMO_ASSERT(ms->ul_tbf() == ul_tbf); |
| 206 | OSMO_ASSERT(ms->dl_tbf() == dl_tbf[1]); |
| 207 | OSMO_ASSERT(!was_idle); |
| 208 | |
| 209 | ms->detach_tbf(ul_tbf); |
| 210 | OSMO_ASSERT(!ms->is_idle()); |
| 211 | OSMO_ASSERT(ms->ul_tbf() == NULL); |
| 212 | OSMO_ASSERT(ms->dl_tbf() == dl_tbf[1]); |
| 213 | OSMO_ASSERT(!was_idle); |
| 214 | |
| 215 | ms->detach_tbf(dl_tbf[0]); |
| 216 | OSMO_ASSERT(!ms->is_idle()); |
| 217 | OSMO_ASSERT(ms->ul_tbf() == NULL); |
| 218 | OSMO_ASSERT(ms->dl_tbf() == dl_tbf[1]); |
| 219 | OSMO_ASSERT(!was_idle); |
| 220 | |
| 221 | ms->detach_tbf(dl_tbf[1]); |
| 222 | OSMO_ASSERT(ms->is_idle()); |
| 223 | OSMO_ASSERT(ms->ul_tbf() == NULL); |
| 224 | OSMO_ASSERT(ms->dl_tbf() == NULL); |
| 225 | OSMO_ASSERT(was_idle); |
| 226 | |
| 227 | delete ms; |
| 228 | |
| 229 | talloc_free(dl_tbf[0]); |
| 230 | talloc_free(dl_tbf[1]); |
| 231 | talloc_free(ul_tbf); |
| 232 | |
| 233 | printf("=== end %s ===\n", __func__); |
| 234 | } |
| 235 | |
Jacob Erlbeck | 9399046 | 2015-05-15 15:50:43 +0200 | [diff] [blame] | 236 | static void test_ms_change_tlli() |
| 237 | { |
| 238 | uint32_t start_tlli = 0xaa000000; |
| 239 | uint32_t new_ms_tlli = 0xff001111; |
| 240 | uint32_t other_sgsn_tlli = 0xff00eeee; |
| 241 | GprsMs *ms; |
| 242 | |
| 243 | printf("=== start %s ===\n", __func__); |
| 244 | |
Jacob Erlbeck | 17214bb | 2015-06-02 14:06:12 +0200 | [diff] [blame] | 245 | ms = new GprsMs(NULL, start_tlli); |
Jacob Erlbeck | 9399046 | 2015-05-15 15:50:43 +0200 | [diff] [blame] | 246 | |
| 247 | OSMO_ASSERT(ms->is_idle()); |
| 248 | |
| 249 | /* MS announces TLLI, SGSN uses it immediately */ |
| 250 | ms->set_tlli(new_ms_tlli); |
| 251 | OSMO_ASSERT(ms->tlli() == new_ms_tlli); |
| 252 | OSMO_ASSERT(ms->check_tlli(new_ms_tlli)); |
| 253 | OSMO_ASSERT(ms->check_tlli(start_tlli)); |
| 254 | |
| 255 | ms->confirm_tlli(new_ms_tlli); |
| 256 | OSMO_ASSERT(ms->tlli() == new_ms_tlli); |
| 257 | OSMO_ASSERT(ms->check_tlli(new_ms_tlli)); |
| 258 | OSMO_ASSERT(!ms->check_tlli(start_tlli)); |
| 259 | |
| 260 | /* MS announces TLLI, SGSN uses it later */ |
| 261 | ms->set_tlli(start_tlli); |
| 262 | ms->confirm_tlli(start_tlli); |
| 263 | |
| 264 | ms->set_tlli(new_ms_tlli); |
| 265 | OSMO_ASSERT(ms->tlli() == new_ms_tlli); |
| 266 | OSMO_ASSERT(ms->check_tlli(new_ms_tlli)); |
| 267 | OSMO_ASSERT(ms->check_tlli(start_tlli)); |
| 268 | |
| 269 | ms->confirm_tlli(start_tlli); |
| 270 | OSMO_ASSERT(ms->tlli() == new_ms_tlli); |
| 271 | OSMO_ASSERT(ms->check_tlli(new_ms_tlli)); |
| 272 | OSMO_ASSERT(ms->check_tlli(start_tlli)); |
| 273 | |
| 274 | ms->set_tlli(new_ms_tlli); |
| 275 | OSMO_ASSERT(ms->tlli() == new_ms_tlli); |
| 276 | OSMO_ASSERT(ms->check_tlli(new_ms_tlli)); |
| 277 | OSMO_ASSERT(ms->check_tlli(start_tlli)); |
| 278 | |
| 279 | ms->confirm_tlli(new_ms_tlli); |
| 280 | OSMO_ASSERT(ms->tlli() == new_ms_tlli); |
| 281 | OSMO_ASSERT(ms->check_tlli(new_ms_tlli)); |
| 282 | OSMO_ASSERT(!ms->check_tlli(start_tlli)); |
| 283 | |
| 284 | /* MS announces TLLI, SGSN uses it later after another new TLLI */ |
| 285 | ms->set_tlli(start_tlli); |
| 286 | ms->confirm_tlli(start_tlli); |
| 287 | |
| 288 | ms->set_tlli(new_ms_tlli); |
| 289 | OSMO_ASSERT(ms->tlli() == new_ms_tlli); |
| 290 | OSMO_ASSERT(ms->check_tlli(new_ms_tlli)); |
| 291 | OSMO_ASSERT(ms->check_tlli(start_tlli)); |
| 292 | |
| 293 | ms->confirm_tlli(other_sgsn_tlli); |
| 294 | OSMO_ASSERT(ms->tlli() == new_ms_tlli); |
| 295 | OSMO_ASSERT(ms->check_tlli(new_ms_tlli)); |
| 296 | OSMO_ASSERT(ms->check_tlli(other_sgsn_tlli)); |
| 297 | |
| 298 | ms->set_tlli(new_ms_tlli); |
| 299 | OSMO_ASSERT(ms->tlli() == new_ms_tlli); |
| 300 | OSMO_ASSERT(ms->check_tlli(new_ms_tlli)); |
| 301 | OSMO_ASSERT(ms->check_tlli(other_sgsn_tlli)); |
| 302 | |
| 303 | ms->confirm_tlli(new_ms_tlli); |
| 304 | OSMO_ASSERT(ms->tlli() == new_ms_tlli); |
| 305 | OSMO_ASSERT(ms->check_tlli(new_ms_tlli)); |
| 306 | OSMO_ASSERT(!ms->check_tlli(start_tlli)); |
| 307 | OSMO_ASSERT(!ms->check_tlli(other_sgsn_tlli)); |
| 308 | |
| 309 | /* SGSN uses the new TLLI before it is announced by the MS (shouldn't |
| 310 | * happen in normal use) */ |
| 311 | ms->set_tlli(start_tlli); |
| 312 | ms->confirm_tlli(start_tlli); |
| 313 | |
| 314 | ms->confirm_tlli(new_ms_tlli); |
| 315 | OSMO_ASSERT(ms->tlli() == start_tlli); |
| 316 | OSMO_ASSERT(ms->check_tlli(new_ms_tlli)); |
| 317 | OSMO_ASSERT(ms->check_tlli(start_tlli)); |
| 318 | |
| 319 | ms->set_tlli(new_ms_tlli); |
| 320 | OSMO_ASSERT(ms->tlli() == new_ms_tlli); |
| 321 | OSMO_ASSERT(ms->check_tlli(new_ms_tlli)); |
| 322 | OSMO_ASSERT(!ms->check_tlli(start_tlli)); |
| 323 | |
| 324 | delete ms; |
| 325 | |
| 326 | printf("=== end %s ===\n", __func__); |
| 327 | } |
| 328 | |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 329 | static void test_ms_storage() |
| 330 | { |
| 331 | uint32_t tlli = 0xffeeddbb; |
Jacob Erlbeck | 7b9f825 | 2015-05-21 11:07:53 +0200 | [diff] [blame] | 332 | const char *imsi1 = "001001987654321"; |
| 333 | const char *imsi2 = "001001987654322"; |
| 334 | |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 335 | gprs_rlcmac_ul_tbf *ul_tbf; |
Jacob Erlbeck | 0e50ce6 | 2015-05-21 16:58:22 +0200 | [diff] [blame] | 336 | GprsMs *ms, *ms_tmp; |
Jacob Erlbeck | 17214bb | 2015-06-02 14:06:12 +0200 | [diff] [blame] | 337 | GprsMsStorage store(NULL); |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 338 | |
| 339 | printf("=== start %s ===\n", __func__); |
| 340 | |
| 341 | ul_tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf); |
| 342 | ul_tbf->direction = GPRS_RLCMAC_UL_TBF; |
| 343 | |
| 344 | ms = store.get_ms(tlli + 0); |
| 345 | OSMO_ASSERT(ms == NULL); |
| 346 | |
Jacob Erlbeck | 0e50ce6 | 2015-05-21 16:58:22 +0200 | [diff] [blame] | 347 | ms = store.create_ms(tlli + 0, GPRS_RLCMAC_UL_TBF); |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 348 | OSMO_ASSERT(ms != NULL); |
| 349 | OSMO_ASSERT(ms->tlli() == tlli + 0); |
Jacob Erlbeck | 7b9f825 | 2015-05-21 11:07:53 +0200 | [diff] [blame] | 350 | ms->set_imsi(imsi1); |
| 351 | OSMO_ASSERT(strcmp(ms->imsi(), imsi1) == 0); |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 352 | |
Jacob Erlbeck | 0e50ce6 | 2015-05-21 16:58:22 +0200 | [diff] [blame] | 353 | ms_tmp = store.get_ms(tlli + 0); |
| 354 | OSMO_ASSERT(ms == ms_tmp); |
| 355 | OSMO_ASSERT(ms->tlli() == tlli + 0); |
| 356 | |
Jacob Erlbeck | 7b9f825 | 2015-05-21 11:07:53 +0200 | [diff] [blame] | 357 | ms_tmp = store.get_ms(0, 0, imsi1); |
| 358 | OSMO_ASSERT(ms == ms_tmp); |
| 359 | OSMO_ASSERT(strcmp(ms->imsi(), imsi1) == 0); |
| 360 | ms_tmp = store.get_ms(0, 0, imsi2); |
| 361 | OSMO_ASSERT(ms_tmp == NULL); |
| 362 | |
Jacob Erlbeck | 0e50ce6 | 2015-05-21 16:58:22 +0200 | [diff] [blame] | 363 | ms = store.create_ms(tlli + 1, GPRS_RLCMAC_UL_TBF); |
| 364 | OSMO_ASSERT(ms != NULL); |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 365 | OSMO_ASSERT(ms->tlli() == tlli + 1); |
Jacob Erlbeck | 7b9f825 | 2015-05-21 11:07:53 +0200 | [diff] [blame] | 366 | ms->set_imsi(imsi2); |
| 367 | OSMO_ASSERT(strcmp(ms->imsi(), imsi2) == 0); |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 368 | |
Jacob Erlbeck | 0e50ce6 | 2015-05-21 16:58:22 +0200 | [diff] [blame] | 369 | ms_tmp = store.get_ms(tlli + 1); |
| 370 | OSMO_ASSERT(ms == ms_tmp); |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 371 | OSMO_ASSERT(ms->tlli() == tlli + 1); |
| 372 | |
Jacob Erlbeck | 7b9f825 | 2015-05-21 11:07:53 +0200 | [diff] [blame] | 373 | ms_tmp = store.get_ms(0, 0, imsi1); |
| 374 | OSMO_ASSERT(ms_tmp != NULL); |
| 375 | OSMO_ASSERT(ms_tmp != ms); |
| 376 | ms_tmp = store.get_ms(0, 0, imsi2); |
| 377 | OSMO_ASSERT(ms == ms_tmp); |
| 378 | OSMO_ASSERT(strcmp(ms->imsi(), imsi2) == 0); |
| 379 | |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 380 | /* delete ms */ |
| 381 | ms = store.get_ms(tlli + 0); |
| 382 | OSMO_ASSERT(ms != NULL); |
| 383 | ms->attach_tbf(ul_tbf); |
| 384 | ms->detach_tbf(ul_tbf); |
| 385 | ms = store.get_ms(tlli + 0); |
| 386 | OSMO_ASSERT(ms == NULL); |
| 387 | ms = store.get_ms(tlli + 1); |
| 388 | OSMO_ASSERT(ms != NULL); |
| 389 | |
| 390 | /* delete ms */ |
| 391 | ms = store.get_ms(tlli + 1); |
| 392 | OSMO_ASSERT(ms != NULL); |
| 393 | ms->attach_tbf(ul_tbf); |
| 394 | ms->detach_tbf(ul_tbf); |
| 395 | ms = store.get_ms(tlli + 1); |
| 396 | OSMO_ASSERT(ms == NULL); |
| 397 | |
| 398 | talloc_free(ul_tbf); |
| 399 | |
| 400 | printf("=== end %s ===\n", __func__); |
| 401 | } |
| 402 | |
Jacob Erlbeck | d9e1024 | 2015-05-28 15:43:53 +0200 | [diff] [blame] | 403 | static void test_ms_timeout() |
| 404 | { |
| 405 | uint32_t tlli = 0xffeeddbb; |
| 406 | gprs_rlcmac_dl_tbf *dl_tbf; |
| 407 | gprs_rlcmac_ul_tbf *ul_tbf; |
| 408 | GprsMs *ms; |
| 409 | static enum {UNKNOWN, IS_IDLE, IS_ACTIVE} last_cb = UNKNOWN; |
| 410 | |
| 411 | struct MyCallback: public GprsMs::Callback { |
| 412 | virtual void ms_idle(class GprsMs *ms) { |
| 413 | OSMO_ASSERT(ms->is_idle()); |
| 414 | printf(" ms_idle() was called\n"); |
| 415 | last_cb = IS_IDLE; |
| 416 | } |
| 417 | virtual void ms_active(class GprsMs *ms) { |
| 418 | OSMO_ASSERT(!ms->is_idle()); |
| 419 | printf(" ms_active() was called\n"); |
| 420 | last_cb = IS_ACTIVE; |
| 421 | } |
| 422 | } cb; |
| 423 | |
| 424 | printf("=== start %s ===\n", __func__); |
| 425 | |
Jacob Erlbeck | 17214bb | 2015-06-02 14:06:12 +0200 | [diff] [blame] | 426 | ms = new GprsMs(NULL, tlli); |
Jacob Erlbeck | d9e1024 | 2015-05-28 15:43:53 +0200 | [diff] [blame] | 427 | ms->set_callback(&cb); |
| 428 | ms->set_timeout(1); |
| 429 | |
| 430 | OSMO_ASSERT(ms->is_idle()); |
| 431 | |
| 432 | dl_tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_dl_tbf); |
| 433 | dl_tbf->direction = GPRS_RLCMAC_DL_TBF; |
| 434 | ul_tbf = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf); |
| 435 | ul_tbf->direction = GPRS_RLCMAC_UL_TBF; |
| 436 | |
| 437 | OSMO_ASSERT(last_cb == UNKNOWN); |
| 438 | |
| 439 | ms->attach_tbf(ul_tbf); |
| 440 | OSMO_ASSERT(!ms->is_idle()); |
| 441 | OSMO_ASSERT(last_cb == IS_ACTIVE); |
| 442 | |
| 443 | last_cb = UNKNOWN; |
| 444 | |
| 445 | ms->attach_tbf(dl_tbf); |
| 446 | OSMO_ASSERT(!ms->is_idle()); |
| 447 | OSMO_ASSERT(last_cb == UNKNOWN); |
| 448 | |
| 449 | ms->detach_tbf(ul_tbf); |
| 450 | OSMO_ASSERT(!ms->is_idle()); |
| 451 | OSMO_ASSERT(last_cb == UNKNOWN); |
| 452 | |
| 453 | ms->detach_tbf(dl_tbf); |
| 454 | OSMO_ASSERT(!ms->is_idle()); |
| 455 | OSMO_ASSERT(last_cb == UNKNOWN); |
| 456 | |
| 457 | usleep(1100000); |
| 458 | osmo_timers_update(); |
| 459 | |
| 460 | OSMO_ASSERT(ms->is_idle()); |
| 461 | OSMO_ASSERT(last_cb == IS_IDLE); |
| 462 | |
| 463 | last_cb = UNKNOWN; |
| 464 | delete ms; |
| 465 | talloc_free(dl_tbf); |
| 466 | talloc_free(ul_tbf); |
| 467 | |
| 468 | printf("=== end %s ===\n", __func__); |
| 469 | } |
| 470 | |
Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 471 | static const struct log_info_cat default_categories[] = { |
| 472 | {"DPCU", "", "GPRS Packet Control Unit (PCU)", LOGL_INFO, 1}, |
| 473 | }; |
| 474 | |
| 475 | static int filter_fn(const struct log_context *ctx, |
| 476 | struct log_target *tar) |
| 477 | { |
| 478 | return 1; |
| 479 | } |
| 480 | |
| 481 | const struct log_info debug_log_info = { |
| 482 | filter_fn, |
| 483 | (struct log_info_cat*)default_categories, |
| 484 | ARRAY_SIZE(default_categories), |
| 485 | }; |
| 486 | |
| 487 | int main(int argc, char **argv) |
| 488 | { |
| 489 | struct vty_app_info pcu_vty_info = {0}; |
| 490 | |
| 491 | tall_pcu_ctx = talloc_named_const(NULL, 1, "MsTest context"); |
| 492 | if (!tall_pcu_ctx) |
| 493 | abort(); |
| 494 | |
| 495 | msgb_set_talloc_ctx(tall_pcu_ctx); |
| 496 | osmo_init_logging(&debug_log_info); |
| 497 | log_set_use_color(osmo_stderr_target, 0); |
| 498 | log_set_print_filename(osmo_stderr_target, 0); |
| 499 | log_set_log_level(osmo_stderr_target, LOGL_INFO); |
| 500 | |
| 501 | vty_init(&pcu_vty_info); |
| 502 | pcu_vty_init(&debug_log_info); |
| 503 | |
| 504 | test_ms_state(); |
| 505 | test_ms_callback(); |
| 506 | test_ms_replace_tbf(); |
Jacob Erlbeck | 9399046 | 2015-05-15 15:50:43 +0200 | [diff] [blame] | 507 | test_ms_change_tlli(); |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 508 | test_ms_storage(); |
Jacob Erlbeck | d9e1024 | 2015-05-28 15:43:53 +0200 | [diff] [blame] | 509 | test_ms_timeout(); |
Jacob Erlbeck | e04e0b0 | 2015-05-06 18:30:48 +0200 | [diff] [blame] | 510 | |
| 511 | if (getenv("TALLOC_REPORT_FULL")) |
| 512 | talloc_report_full(tall_pcu_ctx, stderr); |
| 513 | |
| 514 | return EXIT_SUCCESS; |
| 515 | } |
| 516 | |
| 517 | extern "C" { |
| 518 | void l1if_pdch_req() { abort(); } |
| 519 | void l1if_connect_pdch() { abort(); } |
| 520 | void l1if_close_pdch() { abort(); } |
| 521 | void l1if_open_pdch() { abort(); } |
| 522 | } |