agch/test: Add test for AGCH queue handling

The first test checks the AGCH may queue length computation.

The second test fills the queue by calling bts_agch_enqueue() with a
mix of IMM.ASS and IMM.ASS.REJ. Then it drains the queue by calling
bts_ccch_copy_msg(). After each of both steps, statistics are printed
out.

Sponsored-by: On-Waves ehf
This commit is contained in:
Jacob Erlbeck 2014-02-21 16:12:46 +01:00 committed by Holger Hans Peter Freyther
parent 35a8144e41
commit 2d725e77f7
6 changed files with 283 additions and 1 deletions

View File

@ -59,6 +59,7 @@ AC_OUTPUT(
include/osmo-bts/Makefile
tests/Makefile
tests/paging/Makefile
tests/agch/Makefile
tests/cipher/Makefile
tests/sysmobts/Makefile
Makefile)

View File

@ -1,4 +1,4 @@
SUBDIRS = paging cipher sysmobts
SUBDIRS = paging cipher sysmobts agch
# The `:;' works around a Bash 3.2 bug when the output is not writeable.
$(srcdir)/package.m4: $(top_srcdir)/configure.ac

8
tests/agch/Makefile.am Normal file
View File

@ -0,0 +1,8 @@
AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -I$(OPENBSC_INCDIR)
AM_CFLAGS = -Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) $(LIBOSMOVTY_CFLAGS) $(LIBOSMOTRAU_CFLAGS)
LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOVTY_LIBS) $(LIBOSMOTRAU_LIBS) $(LIBOSMOABIS_LIBS) -lortp
noinst_PROGRAMS = agch_test
EXTRA_DIST = agch_test.ok
agch_test_SOURCES = agch_test.c $(srcdir)/../stubs.c
agch_test_LDADD = $(top_builddir)/src/common/libbts.a $(LDADD)

244
tests/agch/agch_test.c Normal file
View File

@ -0,0 +1,244 @@
/* testing the agch code */
/* (C) 2011 by Holger Hans Peter Freyther
* (C) 2014 by sysmocom s.f.m.c. GmbH
*
* All Rights Reserved
*
* 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 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 <osmocom/core/talloc.h>
#include <osmo-bts/bts.h>
#include <osmo-bts/logging.h>
#include <osmo-bts/gsm_data.h>
#include <unistd.h>
static struct gsm_bts *bts;
static struct gsm_bts_role_bts *btsb;
int pcu_direct = 0;
static const uint8_t static_ilv[] = {
0x08, 0x59, 0x51, 0x30, 0x99, 0x00, 0x00, 0x00, 0x19
};
static int count_imm_ass_rej_refs(struct gsm48_imm_ass_rej *rej)
{
int count = 0;
count++;
if (memcmp(&rej->req_ref1, &rej->req_ref2, sizeof(rej->req_ref2))) {
count++;
}
if (memcmp(&rej->req_ref1, &rej->req_ref3, sizeof(rej->req_ref3))
&& memcmp(&rej->req_ref2, &rej->req_ref3, sizeof(rej->req_ref3))) {
count++;
}
if (memcmp(&rej->req_ref1, &rej->req_ref4, sizeof(rej->req_ref4))
&& memcmp(&rej->req_ref2, &rej->req_ref4, sizeof(rej->req_ref4))
&& memcmp(&rej->req_ref3, &rej->req_ref4, sizeof(rej->req_ref4))) {
count++;
}
return count;
}
static void put_imm_ass_rej(struct msgb *msg, int idx, uint8_t wait_ind)
{
/* GSM CCCH - Immediate Assignment Reject */
static const unsigned char gsm_a_ccch_data[23] = {
0x4d, 0x06, 0x3a, 0x03, 0x25, 0x00, 0x00, 0x0a,
0x25, 0x00, 0x00, 0x0a, 0x25, 0x00, 0x00, 0x0a,
0x25, 0x00, 0x00, 0x0a, 0x2b, 0x2b, 0x2b
};
struct gsm48_imm_ass_rej *rej;
msg->l3h = msgb_put(msg, sizeof(gsm_a_ccch_data));
rej = (struct gsm48_imm_ass_rej *)msg->l3h;
memmove(msg->l3h, gsm_a_ccch_data, sizeof(gsm_a_ccch_data));
rej->req_ref1.t1 = idx;
rej->wait_ind1 = wait_ind;
rej->req_ref2.t1 = idx;
rej->req_ref3.t1 = idx;
rej->req_ref4.t1 = idx;
}
static void put_imm_ass(struct msgb *msg, int idx)
{
/* GSM CCCH - Immediate Assignment */
static const unsigned char gsm_a_ccch_data[23] = {
0x2d, 0x06, 0x3f, 0x03, 0x0c, 0xe3, 0x69, 0x25,
0x00, 0x00, 0x00, 0x00, 0x2b, 0x2b, 0x2b, 0x2b,
0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b
};
struct gsm48_imm_ass *ima;
msg->l3h = msgb_put(msg, sizeof(gsm_a_ccch_data));
ima = (struct gsm48_imm_ass *)msg->l3h;
memmove(msg->l3h, gsm_a_ccch_data, sizeof(gsm_a_ccch_data));
ima->req_ref.t1 = idx;
}
static void test_agch_queue(void)
{
int rc;
uint8_t out_buf[GSM_MACBLOCK_LEN];
struct gsm_time g_time;
const int num_rounds = 40;
const int num_ima_per_round = 2;
const int num_rej_per_round = 16;
int round, idx;
int count = 0;
struct msgb *msg = NULL;
int multiframes = 0;
int imm_ass_count = 0;
int imm_ass_rej_count = 0;
int imm_ass_rej_ref_count = 0;
g_time.fn = 0;
g_time.t1 = 0;
g_time.t2 = 0;
g_time.t3 = 6;
printf("Testing AGCH messages queue handling.\n");
btsb->agch_max_queue_length = 32;
for (round = 1; round <= num_rounds; round++) {
for (idx = 0; idx < num_ima_per_round; idx++) {
msg = msgb_alloc(GSM_MACBLOCK_LEN, __FUNCTION__);
put_imm_ass(msg, ++count);
bts_agch_enqueue(bts, msg);
imm_ass_count++;
}
for (idx = 0; idx < num_rej_per_round; idx++) {
msg = msgb_alloc(GSM_MACBLOCK_LEN, __FUNCTION__);
put_imm_ass_rej(msg, ++count, 10);
bts_agch_enqueue(bts, msg);
imm_ass_rej_count++;
imm_ass_rej_ref_count++;
}
}
printf("AGCH filled: count %u, imm.ass %d, imm.ass.rej %d (refs %d), "
"queue limit %u, occupied %d, "
"dropped %llu, merged %llu, rejected %llu, "
"ag-res %llu, non-res %llu\n",
count, imm_ass_count, imm_ass_rej_count, imm_ass_rej_ref_count,
btsb->agch_max_queue_length, btsb->agch_queue_length,
btsb->agch_queue_dropped_msgs, btsb->agch_queue_merged_msgs,
btsb->agch_queue_rejected_msgs, btsb->agch_queue_agch_msgs,
btsb->agch_queue_pch_msgs);
imm_ass_count = 0;
imm_ass_rej_count = 0;
imm_ass_rej_ref_count = 0;
for (idx = 0; 1; idx++) {
struct gsm48_imm_ass *ima;
int is_agch = (idx % 3) == 0; /* 1 AG reserved, 2 PCH */
if (is_agch)
multiframes++;
rc = bts_ccch_copy_msg(bts, out_buf, &g_time, is_agch);
ima = (struct gsm48_imm_ass *)out_buf;
switch (ima->msg_type) {
case GSM48_MT_RR_IMM_ASS:
imm_ass_count++;
break;
case GSM48_MT_RR_IMM_ASS_REJ:
imm_ass_rej_count++;
imm_ass_rej_ref_count +=
count_imm_ass_rej_refs((struct gsm48_imm_ass_rej *)ima);
break;
default:
break;
}
if (is_agch && rc <= 0)
break;
}
printf("AGCH drained: multiframes %u, imm.ass %d, imm.ass.rej %d (refs %d), "
"queue limit %u, occupied %d, "
"dropped %llu, merged %llu, rejected %llu, "
"ag-res %llu, non-res %llu\n",
multiframes, imm_ass_count, imm_ass_rej_count, imm_ass_rej_ref_count,
btsb->agch_max_queue_length, btsb->agch_queue_length,
btsb->agch_queue_dropped_msgs, btsb->agch_queue_merged_msgs,
btsb->agch_queue_rejected_msgs, btsb->agch_queue_agch_msgs,
btsb->agch_queue_pch_msgs);
}
static void test_agch_queue_length_computation(void)
{
static const int ccch_configs[] = {
RSL_BCCH_CCCH_CONF_1_NC,
RSL_BCCH_CCCH_CONF_1_C,
RSL_BCCH_CCCH_CONF_2_NC,
RSL_BCCH_CCCH_CONF_3_NC,
RSL_BCCH_CCCH_CONF_4_NC,
};
static const uint8_t tx_integer[] = {
3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 20, 25, 32, 50,
};
int T_idx, c_idx, max_len;
printf("Testing AGCH queue length computation.\n");
printf("T\t\tBCCH slots\n");
printf("\t1(NC)\t1(C)\t2(NC)\t3(NC)\t4(NC)\n");
for (T_idx = 0; T_idx < ARRAY_SIZE(tx_integer); T_idx++) {
printf("%d", tx_integer[T_idx]);
for (c_idx = 0; c_idx < ARRAY_SIZE(ccch_configs); c_idx++) {
max_len = bts_agch_max_queue_length(tx_integer[T_idx],
ccch_configs[c_idx]);
printf("\t%d", max_len);
}
printf("\n");
}
}
int main(int argc, char **argv)
{
void *tall_msgb_ctx;
tall_bts_ctx = talloc_named_const(NULL, 1, "OsmoBTS context");
tall_msgb_ctx = talloc_named_const(tall_bts_ctx, 1, "msgb");
msgb_set_talloc_ctx(tall_msgb_ctx);
bts_log_init(NULL);
bts = gsm_bts_alloc(tall_bts_ctx);
if (bts_init(bts) < 0) {
fprintf(stderr, "unable to open bts\n");
exit(1);
}
btsb = bts_role_bts(bts);
test_agch_queue_length_computation();
test_agch_queue();
printf("Success\n");
return 0;
}

23
tests/agch/agch_test.ok Normal file
View File

@ -0,0 +1,23 @@
Testing AGCH queue length computation.
T BCCH slots
1(NC) 1(C) 2(NC) 3(NC) 4(NC)
3 20 9 20 20 20
4 28 11 28 28 28
5 40 13 40 40 40
6 59 19 59 59 59
7 79 25 79 79 79
8 21 9 21 21 21
9 28 12 28 28 28
10 40 13 40 40 40
11 60 20 60 60 60
12 80 26 80 80 80
14 22 10 22 22 22
16 30 13 30 30 30
20 42 14 42 42 42
25 63 21 63 63 63
32 83 28 83 83 83
50 28 14 28 28 28
Testing AGCH messages queue handling.
AGCH filled: count 720, imm.ass 80, imm.ass.rej 640 (refs 640), queue limit 32, occupied 720, dropped 0, merged 0, rejected 0, ag-res 0, non-res 0
AGCH drained: multiframes 721, imm.ass 80, imm.ass.rej 640 (refs 640), queue limit 32, occupied 0, dropped 0, merged 0, rejected 0, ag-res 720, non-res 0
Success

View File

@ -7,6 +7,12 @@ cat $abs_srcdir/paging/paging_test.ok > expout
AT_CHECK([$OSMO_QEMU $abs_top_builddir/tests/paging/paging_test], [], [expout], [ignore])
AT_CLEANUP
AT_SETUP([agch])
AT_KEYWORDS([agch])
cat $abs_srcdir/agch/agch_test.ok > expout
AT_CHECK([$OSMO_QEMU $abs_top_builddir/tests/agch/agch_test], [], [expout], [ignore])
AT_CLEANUP
AT_SETUP([cipher])
AT_KEYWORDS([cipher])
cat $abs_srcdir/cipher/cipher_test.ok > expout