2017-02-21 18:35:23 +00:00
|
|
|
/* Frame number calculation test */
|
|
|
|
|
|
|
|
/* (C) 2016 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* Author: Philipp Maier
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bts.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <osmocom/core/application.h>
|
|
|
|
#include <osmocom/gsm/gsm_utils.h>
|
|
|
|
#include <osmocom/core/talloc.h>
|
|
|
|
#include <osmocom/core/utils.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
#define RFN_MODULUS 42432
|
|
|
|
|
|
|
|
/* globals used by the code */ void *tall_pcu_ctx;
|
|
|
|
int16_t spoof_mnc = 0, spoof_mcc = 0;
|
2018-02-20 23:39:07 +00:00
|
|
|
bool spoof_mnc_3_digits = false;
|
2017-02-21 18:35:23 +00:00
|
|
|
|
2021-01-14 15:48:38 +00:00
|
|
|
static uint32_t calc_fn(struct gprs_rlcmac_bts * bts, uint32_t rfn)
|
2017-02-21 18:35:23 +00:00
|
|
|
{
|
|
|
|
uint32_t fn;
|
2021-01-14 15:48:38 +00:00
|
|
|
fn = bts_rfn_to_fn(bts, rfn);
|
2017-02-21 18:35:23 +00:00
|
|
|
printf("rfn=%i ==> fn=%i\n", rfn, fn);
|
|
|
|
return fn;
|
|
|
|
}
|
|
|
|
|
2021-01-14 15:48:38 +00:00
|
|
|
static void set_fn(struct gprs_rlcmac_bts * bts, uint32_t fn)
|
2017-02-21 18:35:23 +00:00
|
|
|
{
|
|
|
|
printf("\n");
|
2021-01-14 15:48:38 +00:00
|
|
|
bts_set_current_frame_number(bts, fn);
|
2017-02-21 18:35:23 +00:00
|
|
|
printf("bts: fn=%i\n", fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void run_test()
|
|
|
|
{
|
2021-01-18 16:14:14 +00:00
|
|
|
struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
|
2017-02-21 18:35:23 +00:00
|
|
|
uint32_t fn;
|
|
|
|
|
|
|
|
printf("RFN_MODULUS=%i\n",RFN_MODULUS);
|
|
|
|
printf("GSM_MAX_FN=%i\n",GSM_MAX_FN);
|
|
|
|
|
|
|
|
|
|
|
|
/* Test with a collection of real world examples,
|
|
|
|
* all all of them are not critical and do not
|
|
|
|
* assume the occurence of any race contions */
|
2021-01-14 15:48:38 +00:00
|
|
|
set_fn(bts, 1320462);
|
|
|
|
fn = calc_fn(bts, 5066);
|
2017-02-21 18:35:23 +00:00
|
|
|
OSMO_ASSERT(fn == 1320458);
|
|
|
|
|
2021-01-14 15:48:38 +00:00
|
|
|
set_fn(bts, 8246);
|
|
|
|
fn = calc_fn(bts, 8244);
|
2017-02-21 18:35:23 +00:00
|
|
|
OSMO_ASSERT(fn == 8244);
|
|
|
|
|
2021-01-14 15:48:38 +00:00
|
|
|
set_fn(bts, 10270);
|
|
|
|
fn = calc_fn(bts, 10269);
|
2017-02-21 18:35:23 +00:00
|
|
|
OSMO_ASSERT(fn == 10269);
|
|
|
|
|
2021-01-14 15:48:38 +00:00
|
|
|
set_fn(bts, 311276);
|
|
|
|
fn = calc_fn(bts, 14250);
|
2017-02-21 18:35:23 +00:00
|
|
|
OSMO_ASSERT(fn == 311274);
|
|
|
|
|
|
|
|
|
|
|
|
/* Now lets assume a case where the frame number
|
|
|
|
* just wrapped over a little bit above the
|
|
|
|
* modulo 42432 raster, but the rach request
|
|
|
|
* occurred before the wrapping */
|
2021-01-14 15:48:38 +00:00
|
|
|
set_fn(bts, RFN_MODULUS + 30);
|
|
|
|
fn = calc_fn(bts, RFN_MODULUS - 10);
|
2017-02-21 18:35:23 +00:00
|
|
|
OSMO_ASSERT(fn == 42422);
|
|
|
|
|
2021-01-14 15:48:38 +00:00
|
|
|
set_fn(bts, RFN_MODULUS + 1);
|
|
|
|
fn = calc_fn(bts, RFN_MODULUS - 1);
|
2017-02-21 18:35:23 +00:00
|
|
|
OSMO_ASSERT(fn == 42431);
|
|
|
|
|
2023-01-05 10:55:17 +00:00
|
|
|
set_fn(bts, RFN_MODULUS * 12 + 16);
|
2021-01-14 15:48:38 +00:00
|
|
|
fn = calc_fn(bts, RFN_MODULUS - 4);
|
2023-01-05 10:55:17 +00:00
|
|
|
OSMO_ASSERT(fn == 509180);
|
2017-02-21 18:35:23 +00:00
|
|
|
|
2023-01-05 10:55:17 +00:00
|
|
|
set_fn(bts, RFN_MODULUS * 12 + 451);
|
2021-01-14 15:48:38 +00:00
|
|
|
fn = calc_fn(bts, RFN_MODULUS - 175);
|
2023-01-05 10:55:17 +00:00
|
|
|
OSMO_ASSERT(fn == 509009);
|
2017-02-21 18:35:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Lets check a special cornercase. We assume that
|
|
|
|
* the BTS just wrapped its internal frame number
|
|
|
|
* but we still get rach requests with high relative
|
|
|
|
* frame numbers. */
|
2021-01-14 15:48:38 +00:00
|
|
|
set_fn(bts, 0);
|
|
|
|
fn = calc_fn(bts, RFN_MODULUS - 13);
|
2017-02-21 18:35:23 +00:00
|
|
|
OSMO_ASSERT(fn == 2715635);
|
|
|
|
|
2021-01-14 15:48:38 +00:00
|
|
|
set_fn(bts, 453);
|
|
|
|
fn = calc_fn(bts, RFN_MODULUS - 102);
|
2017-02-21 18:35:23 +00:00
|
|
|
OSMO_ASSERT(fn == 2715546);
|
|
|
|
|
2021-01-14 15:48:38 +00:00
|
|
|
set_fn(bts, 10);
|
|
|
|
fn = calc_fn(bts, RFN_MODULUS - 10);
|
2017-02-21 18:35:23 +00:00
|
|
|
OSMO_ASSERT(fn == 2715638);
|
|
|
|
|
2021-01-14 15:48:38 +00:00
|
|
|
set_fn(bts, 23);
|
|
|
|
fn = calc_fn(bts, RFN_MODULUS - 42);
|
2017-02-21 18:35:23 +00:00
|
|
|
OSMO_ASSERT(fn == 2715606);
|
|
|
|
|
|
|
|
|
|
|
|
/* Also check with some corner case
|
|
|
|
* values where Fn and RFn reach its
|
|
|
|
* maximum/minimum valid range */
|
2023-01-05 10:55:17 +00:00
|
|
|
set_fn(bts, GSM_MAX_FN-1);
|
2021-01-14 15:48:38 +00:00
|
|
|
fn = calc_fn(bts, RFN_MODULUS-1);
|
2017-02-21 18:35:23 +00:00
|
|
|
OSMO_ASSERT(fn == GSM_MAX_FN-1);
|
|
|
|
|
2021-01-14 15:48:38 +00:00
|
|
|
set_fn(bts, 0);
|
|
|
|
fn = calc_fn(bts, RFN_MODULUS-1);
|
2017-02-21 18:35:23 +00:00
|
|
|
OSMO_ASSERT(fn == GSM_MAX_FN-1);
|
|
|
|
|
2023-01-05 10:55:17 +00:00
|
|
|
set_fn(bts, GSM_MAX_FN-1);
|
2021-01-14 15:48:38 +00:00
|
|
|
fn = calc_fn(bts, 0);
|
2023-01-05 10:55:17 +00:00
|
|
|
OSMO_ASSERT(fn == GSM_MAX_FN-RFN_MODULUS*2);
|
2017-02-21 18:35:23 +00:00
|
|
|
|
2021-01-14 15:48:38 +00:00
|
|
|
set_fn(bts, 0);
|
|
|
|
fn = calc_fn(bts, 0);
|
2017-02-21 18:35:23 +00:00
|
|
|
OSMO_ASSERT(fn == 0);
|
2021-01-14 15:48:38 +00:00
|
|
|
talloc_free(bts);
|
2017-02-21 18:35:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
tall_pcu_ctx = talloc_named_const(NULL, 1, "fn test context");
|
|
|
|
if (!tall_pcu_ctx)
|
|
|
|
abort();
|
|
|
|
|
|
|
|
msgb_talloc_ctx_init(tall_pcu_ctx, 0);
|
2018-04-01 14:54:40 +00:00
|
|
|
osmo_init_logging2(tall_pcu_ctx, &gprs_log_info);
|
2017-02-21 18:35:23 +00:00
|
|
|
log_set_use_color(osmo_stderr_target, 0);
|
2021-02-19 13:01:52 +00:00
|
|
|
log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
|
2017-02-21 18:35:23 +00:00
|
|
|
log_set_log_level(osmo_stderr_target, LOGL_DEBUG);
|
|
|
|
|
Split PCU global PCU object from BTS object
Currently the BTS object (and gprs_rlcmac_bts struct) are used to hold
both PCU global fields and BTS specific fields, all mangled together.
The BTS is even accessed in lots of places by means of a singleton.
This patch introduces a new struct gprs_pcu object aimed at holding all
global state, and several fields are already moved from BTS to it. The
new object can be accessed as global variable "the_pcu", reusing and
including an already exisitng "the_pcu" global variable only used for
bssgp related purposes so far.
This is only a first step towards having a complete split global pcu and
BTS, some fields are still kept in BTS and will be moved over follow-up
smaller patches in the future (since this patch is already quite big).
So far, the code still only supports one BTS, which can be accessed
using the_pcu->bts. In the future that field will be replaced with a
list, and the BTS singletons will be removed.
The cur_fn output changes in TbfTest are actually a side effect fix,
since the singleton main_bts() now points internally to the_pcu->bts,
hence the same we allocate and assign in the test. Beforehand, "the_bts"
was allocated in the stack while main_bts() still returned an unrelated
singleton BTS object instance.
Related: OS#4935
Change-Id: I88e3c6471b80245ce3798223f1a61190f14aa840
2021-01-13 17:54:38 +00:00
|
|
|
the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
|
|
|
|
|
2017-02-21 18:35:23 +00:00
|
|
|
run_test();
|
Split PCU global PCU object from BTS object
Currently the BTS object (and gprs_rlcmac_bts struct) are used to hold
both PCU global fields and BTS specific fields, all mangled together.
The BTS is even accessed in lots of places by means of a singleton.
This patch introduces a new struct gprs_pcu object aimed at holding all
global state, and several fields are already moved from BTS to it. The
new object can be accessed as global variable "the_pcu", reusing and
including an already exisitng "the_pcu" global variable only used for
bssgp related purposes so far.
This is only a first step towards having a complete split global pcu and
BTS, some fields are still kept in BTS and will be moved over follow-up
smaller patches in the future (since this patch is already quite big).
So far, the code still only supports one BTS, which can be accessed
using the_pcu->bts. In the future that field will be replaced with a
list, and the BTS singletons will be removed.
The cur_fn output changes in TbfTest are actually a side effect fix,
since the singleton main_bts() now points internally to the_pcu->bts,
hence the same we allocate and assign in the test. Beforehand, "the_bts"
was allocated in the stack while main_bts() still returned an unrelated
singleton BTS object instance.
Related: OS#4935
Change-Id: I88e3c6471b80245ce3798223f1a61190f14aa840
2021-01-13 17:54:38 +00:00
|
|
|
|
|
|
|
talloc_free(the_pcu);
|
2017-02-21 18:35:23 +00:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stubs that should not be reached
|
|
|
|
*/
|
|
|
|
extern "C" {
|
|
|
|
void l1if_pdch_req() {
|
|
|
|
abort();
|
|
|
|
} void l1if_connect_pdch() {
|
|
|
|
abort();
|
2023-02-27 14:32:00 +00:00
|
|
|
} void l1if_disconnect_pdch() {
|
|
|
|
abort();
|
2017-02-21 18:35:23 +00:00
|
|
|
}
|
2023-04-25 07:41:17 +00:00
|
|
|
void l1if_close_trx() {
|
2017-02-21 18:35:23 +00:00
|
|
|
abort();
|
|
|
|
}
|
2023-04-25 07:41:17 +00:00
|
|
|
void l1if_open_trx() {
|
2017-02-21 18:35:23 +00:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|