2019-09-05 15:13:33 +00:00
|
|
|
/* Copyright (C) 2019 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
#include <assert.h>
|
|
|
|
#include "gprs_rlcmac.h"
|
|
|
|
#include "bts.h"
|
2021-01-14 15:48:38 +00:00
|
|
|
#include "tbf_dl.h"
|
2019-09-05 15:13:33 +00:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <osmocom/vty/telnet_interface.h>
|
|
|
|
#include <osmocom/vty/logging.h>
|
|
|
|
#include <osmocom/core/utils.h>
|
|
|
|
#include <osmocom/core/msgb.h>
|
|
|
|
#include <osmocom/core/application.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
gprs_rlcmac_dl_tbf *tbf1, *tbf2;
|
|
|
|
GprsMs *ms1, *ms2;
|
|
|
|
struct msgb *sched_app_info(struct gprs_rlcmac_tbf *tbf);
|
|
|
|
|
|
|
|
/* globals used by the code */
|
|
|
|
void *tall_pcu_ctx;
|
|
|
|
int16_t spoof_mnc = 0, spoof_mcc = 0;
|
|
|
|
bool spoof_mnc_3_digits = false;
|
|
|
|
|
|
|
|
void test_enc_zero_len() {
|
|
|
|
struct gsm_pcu_if_app_info_req req = {0, 0, {0}};
|
|
|
|
|
|
|
|
fprintf(stderr, "--- %s ---\n", __func__);
|
|
|
|
assert(gprs_rlcmac_app_info_msg(&req) == NULL);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
2019-09-18 11:47:25 +00:00
|
|
|
void test_enc(const struct gsm_pcu_if_app_info_req *req)
|
|
|
|
{
|
2019-09-05 15:13:33 +00:00
|
|
|
const char *exp = "03 fc 03 fc 00 00 00 00 00 00 00 00 00 00 00 00 "; /* shifted by two bits to the right */
|
|
|
|
struct msgb *msg;
|
|
|
|
char *msg_dump;
|
|
|
|
|
|
|
|
fprintf(stderr, "--- %s ---\n", __func__);
|
2019-09-18 11:47:25 +00:00
|
|
|
msg = gprs_rlcmac_app_info_msg(req);
|
2019-09-05 15:13:33 +00:00
|
|
|
msg_dump = msgb_hexdump_c(tall_pcu_ctx, msg);
|
|
|
|
|
|
|
|
fprintf(stderr, "exp: %s\n", exp);
|
|
|
|
fprintf(stderr, "msg: %s\n", msg_dump);
|
|
|
|
assert(strcmp(msg_dump, exp) == 0);
|
|
|
|
|
|
|
|
msgb_free(msg);
|
|
|
|
talloc_free(msg_dump);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_pcu_rx_no_subscr_with_active_tbf()
|
|
|
|
{
|
|
|
|
struct gsm_pcu_if pcu_prim = {PCU_IF_MSG_APP_INFO_REQ, };
|
|
|
|
|
|
|
|
fprintf(stderr, "--- %s ---\n", __func__);
|
|
|
|
pcu_rx(PCU_IF_MSG_APP_INFO_REQ, &pcu_prim);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void prepare_bts_with_two_dl_tbf_subscr()
|
|
|
|
{
|
2021-01-18 16:14:14 +00:00
|
|
|
struct gprs_rlcmac_bts *bts = gprs_pcu_get_bts_by_nr(the_pcu, 0);
|
2019-09-05 15:13:33 +00:00
|
|
|
struct gprs_rlcmac_trx *trx;
|
|
|
|
|
|
|
|
fprintf(stderr, "--- %s ---\n", __func__);
|
|
|
|
|
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->alloc_algorithm = alloc_algorithm_b;
|
2019-09-05 15:13:33 +00:00
|
|
|
|
2021-01-14 15:48:38 +00:00
|
|
|
trx = bts->trx;
|
2019-09-05 15:13:33 +00:00
|
|
|
trx->pdch[4].enable();
|
|
|
|
trx->pdch[5].enable();
|
|
|
|
trx->pdch[6].enable();
|
|
|
|
trx->pdch[7].enable();
|
|
|
|
|
2021-01-14 15:48:38 +00:00
|
|
|
ms1 = bts_alloc_ms(bts, 10, 11);
|
|
|
|
tbf1 = tbf_alloc_dl_tbf(bts, ms1, 0, false);
|
|
|
|
ms2 = bts_alloc_ms(bts, 12, 13);
|
|
|
|
tbf2 = tbf_alloc_dl_tbf(bts, ms2, 0, false);
|
2019-09-05 15:13:33 +00:00
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
2019-09-18 11:47:25 +00:00
|
|
|
void test_sched_app_info_ok(const struct gsm_pcu_if_app_info_req *req)
|
2019-09-05 15:13:33 +00:00
|
|
|
{
|
|
|
|
struct gsm_pcu_if pcu_prim = {PCU_IF_MSG_APP_INFO_REQ, };
|
|
|
|
struct msgb *msg;
|
|
|
|
|
|
|
|
fprintf(stderr, "--- %s ---\n", __func__);
|
2019-09-18 11:47:25 +00:00
|
|
|
pcu_prim.u.app_info_req = *req;
|
2019-09-05 15:13:33 +00:00
|
|
|
pcu_rx(PCU_IF_MSG_APP_INFO_REQ, &pcu_prim);
|
|
|
|
|
|
|
|
msg = sched_app_info(tbf1);
|
|
|
|
assert(msg);
|
|
|
|
msgb_free(msg);
|
|
|
|
|
|
|
|
msg = sched_app_info(tbf2);
|
|
|
|
assert(msg);
|
|
|
|
msgb_free(msg);
|
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
2019-09-18 11:47:25 +00:00
|
|
|
void test_sched_app_info_missing_app_info_in_bts(const struct gsm_pcu_if_app_info_req *req)
|
2019-09-05 15:13:33 +00:00
|
|
|
{
|
2021-01-18 16:14:14 +00:00
|
|
|
struct gprs_rlcmac_bts *bts = gprs_pcu_get_bts_by_nr(the_pcu, 0);
|
2019-09-05 15:13:33 +00:00
|
|
|
struct gsm_pcu_if pcu_prim = {PCU_IF_MSG_APP_INFO_REQ, };
|
|
|
|
|
|
|
|
fprintf(stderr, "--- %s ---\n", __func__);
|
2019-09-18 11:47:25 +00:00
|
|
|
pcu_prim.u.app_info_req = *req;
|
2019-09-05 15:13:33 +00:00
|
|
|
pcu_rx(PCU_IF_MSG_APP_INFO_REQ, &pcu_prim);
|
|
|
|
|
2021-01-14 15:48:38 +00:00
|
|
|
msgb_free(bts->app_info);
|
|
|
|
bts->app_info = NULL;
|
2019-09-05 15:13:33 +00:00
|
|
|
|
|
|
|
assert(sched_app_info(tbf1) == NULL);
|
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
2019-09-18 11:47:25 +00:00
|
|
|
void test_pcu_rx_overwrite_app_info(const struct gsm_pcu_if_app_info_req *req)
|
2019-09-05 15:13:33 +00:00
|
|
|
{
|
|
|
|
struct gsm_pcu_if pcu_prim = {PCU_IF_MSG_APP_INFO_REQ, };
|
|
|
|
|
|
|
|
fprintf(stderr, "--- %s ---\n", __func__);
|
2019-09-18 11:47:25 +00:00
|
|
|
pcu_prim.u.app_info_req = *req;
|
2019-09-05 15:13:33 +00:00
|
|
|
pcu_rx(PCU_IF_MSG_APP_INFO_REQ, &pcu_prim);
|
|
|
|
pcu_rx(PCU_IF_MSG_APP_INFO_REQ, &pcu_prim);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
2021-01-18 16:14:14 +00:00
|
|
|
extern "C" void cleanup()
|
2019-09-05 15:13:33 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "--- %s ---\n", __func__);
|
|
|
|
|
2021-01-18 16:14:14 +00:00
|
|
|
struct gprs_rlcmac_bts *bts;
|
|
|
|
|
Convert GprsMS and helpers classes to C
As we integrate osmo-pcu more and more with libosmocore features, it
becomes really hard to use them since libosmocore relies heavily on C
specific compilation features, which are not available in old C++
compilers (such as designated initializers for complex types in FSMs).
GprsMs is right now a quite simple object since initial design of
osmo-pcu made it optional and most of the logic was placed and stored
duplicated in TBF objects. However, that's changing as we introduce more
features, with the GprsMS class getting more weight. Hence, let's move
it now to be a C struct in order to be able to easily use libosmocore
features there, such as FSMs.
Some helper classes which GprsMs uses are also mostly move to C since
they are mostly structs with methods, so there's no point in having
duplicated APIs for C++ and C for such simple cases.
For some more complex classes, like (ul_,dl_)tbf, C API bindings are
added where needed so that GprsMs can use functionalitites from that
class. Most of those APIs can be kept afterwards and drop the C++ ones
since they provide no benefit in general.
Change-Id: I0b50e3367aaad9dcada76da97b438e452c8b230c
2020-12-16 14:59:45 +00:00
|
|
|
tbf_free(tbf1);
|
|
|
|
tbf_free(tbf2);
|
2021-01-18 16:14:14 +00:00
|
|
|
|
|
|
|
bts = gprs_pcu_get_bts_by_nr(the_pcu, 0);
|
|
|
|
talloc_free(bts);
|
|
|
|
|
2021-01-14 15:48:38 +00:00
|
|
|
/* FIXME: talloc report disabled, because bts_alloc_ms(bts, ) in prepare_bts_with_two_dl_tbf_subscr() causes leak */
|
2019-09-05 15:13:33 +00:00
|
|
|
/* talloc_report_full(tall_pcu_ctx, stderr); */
|
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);
|
2019-09-05 15:13:33 +00:00
|
|
|
talloc_free(tall_pcu_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2019-09-18 11:47:25 +00:00
|
|
|
struct gsm_pcu_if_app_info_req req = {0, 15, {0}};
|
|
|
|
const uint8_t req_data[] = {0xff, 0x00, 0xff};
|
|
|
|
memcpy(req.data, req_data, 3);
|
|
|
|
|
2019-09-05 15:13:33 +00:00
|
|
|
tall_pcu_ctx = talloc_named_const(NULL, 1, "AppInfoTest");
|
|
|
|
osmo_init_logging2(tall_pcu_ctx, &gprs_log_info);
|
|
|
|
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);
|
2021-02-19 13:00:48 +00:00
|
|
|
log_set_print_category(osmo_stderr_target, 0);
|
|
|
|
log_set_print_category_hex(osmo_stderr_target, 0);
|
2019-09-05 15:13:33 +00:00
|
|
|
log_parse_category_mask(osmo_stderr_target, "DL1IF,1:DRLCMAC,3:DRLCMACSCHED,1");
|
|
|
|
|
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);
|
2021-01-18 16:14:14 +00:00
|
|
|
bts_alloc(the_pcu, 0);
|
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
|
|
|
|
2019-09-05 15:13:33 +00:00
|
|
|
test_enc_zero_len();
|
2019-09-18 11:47:25 +00:00
|
|
|
test_enc(&req);
|
2019-09-05 15:13:33 +00:00
|
|
|
test_pcu_rx_no_subscr_with_active_tbf();
|
|
|
|
|
|
|
|
prepare_bts_with_two_dl_tbf_subscr();
|
2019-09-18 11:47:25 +00:00
|
|
|
test_sched_app_info_ok(&req);
|
|
|
|
test_sched_app_info_missing_app_info_in_bts(&req);
|
|
|
|
test_pcu_rx_overwrite_app_info(&req);
|
2019-09-05 15:13:33 +00:00
|
|
|
|
|
|
|
cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* stubs that should not be reached
|
|
|
|
*/
|
|
|
|
extern "C" {
|
|
|
|
void l1if_pdch_req() { abort(); }
|
|
|
|
void l1if_connect_pdch() { abort(); }
|
|
|
|
void l1if_close_pdch() { abort(); }
|
|
|
|
void l1if_open_pdch() { abort(); }
|
|
|
|
}
|