Allow multiple bts objects in PCU

This patch doesn't really tests whether osmo-pcu can work on a multi-bts
environment, but it prepares the data structures to be able to do so at
any later point in time.

Change-Id: I6b10913f46c19d438c4e250a436a7446694b725a
diff --git a/tests/alloc/AllocTest.cpp b/tests/alloc/AllocTest.cpp
index 20f5286..ecc3e80 100644
--- a/tests/alloc/AllocTest.cpp
+++ b/tests/alloc/AllocTest.cpp
@@ -114,7 +114,7 @@
 	int tfi;
 	int i;
 	uint8_t used_trx, tmp_trx;
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	GprsMs *ms;
 	struct gprs_rlcmac_tbf *tbfs[32*8+1] = { 0, };
 
@@ -206,7 +206,7 @@
 static inline bool test_alloc_b_ul_dl(bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7,
 				      uint8_t ms_class, bool verbose)
 {
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	GprsMs *ms;
 	gprs_rlcmac_ul_tbf *ul_tbf;
 	gprs_rlcmac_dl_tbf *dl_tbf;
@@ -250,7 +250,7 @@
 static inline bool test_alloc_b_dl_ul(bool ts0, bool ts1, bool ts2, bool ts3, bool ts4, bool ts5, bool ts6, bool ts7,
 				      uint8_t ms_class, bool verbose)
 {
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	GprsMs *ms;
 	gprs_rlcmac_ul_tbf *ul_tbf;
 	gprs_rlcmac_dl_tbf *dl_tbf;
@@ -301,7 +301,7 @@
 
 static inline bool test_alloc_b_jolly(uint8_t ms_class)
 {
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	GprsMs *ms;
 	int tfi;
 	uint8_t trx_no;
@@ -644,7 +644,7 @@
 	unsigned max_class, enum test_mode mode,
 	unsigned expect_num, const char *text)
 {
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	struct gprs_rlcmac_trx *trx;
 	unsigned counter;
 
@@ -677,7 +677,7 @@
 static void test_many_connections(algo_t algo, unsigned expect_num,
 	const char *text)
 {
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	struct gprs_rlcmac_trx *trx;
 	int counter1, counter2 = -1;
 	unsigned i;
@@ -754,7 +754,7 @@
 
 static void test_2_consecutive_dl_tbfs()
 {
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	GprsMs *ms;
 	struct gprs_rlcmac_trx *trx;
 	uint8_t ms_class = 11;
diff --git a/tests/alloc/MslotTest.cpp b/tests/alloc/MslotTest.cpp
index b32a828..96b82a5 100644
--- a/tests/alloc/MslotTest.cpp
+++ b/tests/alloc/MslotTest.cpp
@@ -62,7 +62,7 @@
 
 static inline void test_multislot_total_ascending(bool seq)
 {
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	struct gprs_rlcmac_trx *trx;
 	int i;
 
@@ -81,7 +81,7 @@
 
 static inline void test_multislot_total_descending(bool seq)
 {
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	struct gprs_rlcmac_trx *trx;
 	int i;
 
@@ -100,7 +100,7 @@
 
 static inline void test_multislot_middle(bool seq)
 {
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	struct gprs_rlcmac_trx *trx;
 
 	printf("%s(): %s\n", __func__, seq ? "sequential" : "accumulative");
@@ -117,7 +117,7 @@
 
 static inline void test_multislot_ends(bool seq)
 {
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	struct gprs_rlcmac_trx *trx;
 
 	printf("%s(): %s\n", __func__, seq ? "sequential" : "accumulative");
diff --git a/tests/app_info/AppInfoTest.cpp b/tests/app_info/AppInfoTest.cpp
index e0b2853..f145fa5 100644
--- a/tests/app_info/AppInfoTest.cpp
+++ b/tests/app_info/AppInfoTest.cpp
@@ -78,7 +78,7 @@
 
 void prepare_bts_with_two_dl_tbf_subscr()
 {
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = gprs_pcu_get_bts_by_nr(the_pcu, 0);
 	struct gprs_rlcmac_trx *trx;
 
 	fprintf(stderr, "--- %s ---\n",  __func__);
@@ -121,7 +121,7 @@
 
 void test_sched_app_info_missing_app_info_in_bts(const struct gsm_pcu_if_app_info_req *req)
 {
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = gprs_pcu_get_bts_by_nr(the_pcu, 0);
 	struct gsm_pcu_if pcu_prim = {PCU_IF_MSG_APP_INFO_REQ, };
 
 	fprintf(stderr, "--- %s ---\n",  __func__);
@@ -147,13 +147,18 @@
 	fprintf(stderr, "\n");
 }
 
-void cleanup()
+extern "C" void cleanup()
 {
 	fprintf(stderr, "--- %s ---\n",  __func__);
 
+	struct gprs_rlcmac_bts *bts;
+
 	tbf_free(tbf1);
 	tbf_free(tbf2);
-	TALLOC_FREE(the_pcu->bts);
+
+	bts = gprs_pcu_get_bts_by_nr(the_pcu, 0);
+	talloc_free(bts);
+
 	/* FIXME: talloc report disabled, because bts_alloc_ms(bts, ) in prepare_bts_with_two_dl_tbf_subscr() causes leak */
 	/* talloc_report_full(tall_pcu_ctx, stderr); */
 	talloc_free(the_pcu);
@@ -173,7 +178,7 @@
 	log_parse_category_mask(osmo_stderr_target, "DL1IF,1:DRLCMAC,3:DRLCMACSCHED,1");
 
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
+	bts_alloc(the_pcu, 0);
 
 	test_enc_zero_len();
 	test_enc(&req);
diff --git a/tests/edge/EdgeTest.cpp b/tests/edge/EdgeTest.cpp
index d67646e..6161e0e 100644
--- a/tests/edge/EdgeTest.cpp
+++ b/tests/edge/EdgeTest.cpp
@@ -1252,7 +1252,7 @@
 
 static void uplink_header_type2_test(void)
 {
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	int ts_no = 7;
 	uint32_t fn = 2654218;
 	uint16_t qta = 31;
@@ -1370,7 +1370,7 @@
 
 void uplink_header_type1_test(void)
 {
-	struct gprs_rlcmac_bts  *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts  *bts = bts_alloc(the_pcu, 0);
 	int ts_no = 7;
 	uint32_t fn = 2654218;
 	uint16_t qta = 31;
diff --git a/tests/emu/pcu_emu.cpp b/tests/emu/pcu_emu.cpp
index d7b11ca..ef573a7 100644
--- a/tests/emu/pcu_emu.cpp
+++ b/tests/emu/pcu_emu.cpp
@@ -63,9 +63,8 @@
 			test_pdp_activation_data),
 };
 
-static void init_main_bts()
+static void init_main_bts(struct gprs_rlcmac_bts *bts)
 {
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
 	bts->initial_cs_dl = bts->initial_cs_ul = 1;
 	bts->cs_mask = 1 << 0; /* CS-1 always enabled by default */
 	bts->n3101 = 10;
@@ -119,7 +118,7 @@
 {
 	struct gprs_pcu *pcu = gprs_pcu_alloc(tall_pcu_ctx);
 	the_pcu = pcu; /* globally avaialable object */
-	pcu->bts = bts_alloc(pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(pcu, 0);
 
 	tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile Emu-PCU context");
 	if (!tall_pcu_ctx)
@@ -140,9 +139,9 @@
 	current_test = 0;
 
 	init_pcu(pcu);
-	init_main_bts();
+	init_main_bts(bts);
 	bssgp_set_bssgp_callback(gprs_gp_send_cb, pcu->nsi);
-	create_and_connect_bssgp(pcu->bts, INADDR_LOOPBACK, 23000);
+	create_and_connect_bssgp(bts, INADDR_LOOPBACK, 23000);
 
 	for (;;)
 		osmo_select_main(0);
diff --git a/tests/fn/FnTest.cpp b/tests/fn/FnTest.cpp
index dd30b34..4281fc3 100644
--- a/tests/fn/FnTest.cpp
+++ b/tests/fn/FnTest.cpp
@@ -53,7 +53,7 @@
 
 static void run_test()
 {
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	uint32_t fn;
 
 	printf("RFN_MODULUS=%i\n",RFN_MODULUS);
diff --git a/tests/ms/MsTest.cpp b/tests/ms/MsTest.cpp
index 58579f8..f459e99 100644
--- a/tests/ms/MsTest.cpp
+++ b/tests/ms/MsTest.cpp
@@ -51,7 +51,7 @@
 	uint32_t tlli = 0xffeeddbb;
 	gprs_rlcmac_dl_tbf *dl_tbf;
 	gprs_rlcmac_ul_tbf *ul_tbf;
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	GprsMs *ms;
 
 	printf("=== start %s ===\n", __func__);
@@ -114,7 +114,7 @@
 	uint32_t tlli = 0xffeeddbb;
 	gprs_rlcmac_dl_tbf *dl_tbf;
 	gprs_rlcmac_ul_tbf *ul_tbf;
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	GprsMs *ms;
 	last_cb = CB_UNKNOWN;
 
@@ -188,7 +188,7 @@
 	uint32_t tlli = 0xffeeddbb;
 	gprs_rlcmac_dl_tbf *dl_tbf[2];
 	gprs_rlcmac_ul_tbf *ul_tbf;
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	GprsMs *ms;
 
 	printf("=== start %s ===\n", __func__);
@@ -262,7 +262,7 @@
 	uint32_t start_tlli = 0xaa000000;
 	uint32_t new_ms_tlli = 0xff001111;
 	uint32_t other_sgsn_tlli = 0xff00eeee;
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	GprsMs *ms;
 
 	printf("=== start %s ===\n", __func__);
@@ -374,7 +374,7 @@
 	const char *imsi2 = "001001987654322";
 
 	gprs_rlcmac_ul_tbf *ul_tbf;
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	GprsMs *ms, *ms_tmp;
 	GprsMsStorage store(bts);
 
@@ -446,7 +446,7 @@
 	uint32_t tlli = 0xffeeddbb;
 	gprs_rlcmac_dl_tbf *dl_tbf;
 	gprs_rlcmac_ul_tbf *ul_tbf;
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	GprsMs *ms;
 	last_cb = CB_UNKNOWN;
 
@@ -499,7 +499,7 @@
 
 static void test_ms_cs_selection()
 {
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	uint32_t tlli = 0xffeeddbb;
 
 	gprs_rlcmac_dl_tbf *dl_tbf;
@@ -544,7 +544,7 @@
 
 static void test_ms_mcs_mode()
 {
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	uint32_t tlli = 0xdeadbeef;
 
 	gprs_rlcmac_dl_tbf *dl_tbf;
diff --git a/tests/tbf/TbfTest.cpp b/tests/tbf/TbfTest.cpp
index 798dc3c..24fd109 100644
--- a/tests/tbf/TbfTest.cpp
+++ b/tests/tbf/TbfTest.cpp
@@ -95,8 +95,7 @@
 static void test_tbf_tlli_update()
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	GprsMs *ms, *ms_new;
 
 	fprintf(stderr, "=== start %s ===\n", __func__);
@@ -254,8 +253,7 @@
 static void test_tbf_final_ack(enum test_tbf_final_ack_mode test_mode)
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	uint8_t ts_no = 4;
 	unsigned i;
 	uint8_t ms_class = 45;
@@ -340,8 +338,7 @@
 static void test_tbf_delayed_release()
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	uint8_t ts_no = 4;
 	unsigned i;
 	uint8_t ms_class = 45;
@@ -411,8 +408,7 @@
 static void test_tbf_imsi()
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	uint8_t ts_no = 4;
 	uint8_t ms_class = 45;
 	uint8_t trx_no;
@@ -473,8 +469,7 @@
 static void test_tbf_exhaustion()
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	unsigned i;
 	uint8_t ts_no = 4;
 	uint8_t ms_class = 45;
@@ -517,8 +512,7 @@
 static void test_tbf_dl_llc_loss()
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	uint8_t ts_no = 4;
 	uint8_t ms_class = 45;
 	int rc = 0;
@@ -1699,8 +1693,7 @@
 static void test_tbf_single_phase()
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	int ts_no = 7;
 	uint32_t fn = DUMMY_FN; /* 17,25,9 */
 	uint32_t tlli = 0xf1223344;
@@ -1724,8 +1717,7 @@
 static void test_tbf_egprs_two_phase_puan(void)
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	int ts_no = 7;
 	uint32_t fn = 2654218;
 	uint16_t qta = 31;
@@ -1780,8 +1772,7 @@
 static void test_immediate_assign_rej_single_block()
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	uint32_t fn = 2654218;
 	uint16_t qta = 31;
 	int ts_no = 7;
@@ -1814,8 +1805,7 @@
 static void test_immediate_assign_rej_multi_block()
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	uint32_t fn = 2654218;
 	uint16_t qta = 31;
 	int ts_no = 7;
@@ -1856,8 +1846,7 @@
 static void test_tbf_two_phase()
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	int ts_no = 7;
 	uint32_t fn = 2654218;
 	uint16_t qta = 31;
@@ -1889,8 +1878,7 @@
 static void test_tbf_ra_update_rach()
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	int ts_no = 7;
 	uint32_t fn = 2654218;
 	uint16_t qta = 31;
@@ -1956,8 +1944,7 @@
 static void test_tbf_dl_flow_and_rach_two_phase()
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	int ts_no = 7;
 	uint32_t fn = 2654218;
 	uint16_t qta = 31;
@@ -2018,8 +2005,7 @@
 static void test_tbf_dl_flow_and_rach_single_phase()
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	int ts_no = 7;
 	uint32_t fn = 2654218;
 	uint16_t qta = 31;
@@ -2079,8 +2065,7 @@
 static void test_tbf_dl_reuse()
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	int ts_no = 7;
 	uint32_t fn = 2654218;
 	uint16_t qta = 31;
@@ -2180,8 +2165,7 @@
 static void test_tbf_gprs_egprs()
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	uint8_t ts_no = 4;
 	uint8_t ms_class = 45;
 	int rc = 0;
@@ -2248,8 +2232,7 @@
 static void test_tbf_ws()
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	GprsMs *ms;
 	uint8_t ts_no = 4;
 	uint8_t ms_class = 12;
@@ -2294,8 +2277,7 @@
 static void test_tbf_update_ws(void)
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	GprsMs *ms;
 	uint8_t ts_no = 4;
 	uint8_t ms_class = 11;
@@ -2339,8 +2321,7 @@
 static void test_tbf_puan_urbb_len(void)
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	int ts_no = 7;
 	uint32_t fn = 2654218;
 	uint16_t qta = 31;
@@ -2479,8 +2460,7 @@
 static void test_tbf_li_decoding(void)
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	int ts_no = 7;
 	uint32_t fn = 2654218;
 	uint16_t qta = 31;
@@ -2516,8 +2496,7 @@
 static void test_tbf_epdan_out_of_rx_window(void)
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	uint8_t ms_class = 11;
 	uint8_t egprs_ms_class = 11;
 	uint8_t trx_no;
@@ -2608,8 +2587,7 @@
 static void test_tbf_egprs_two_phase_spb(void)
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	int ts_no = 7;
 	uint32_t fn = 2654218;
 	uint16_t qta = 31;
@@ -2640,8 +2618,7 @@
 static void test_tbf_egprs_two_phase()
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	int ts_no = 7;
 	uint32_t fn = 2654218;
 	uint16_t qta = 31;
@@ -3064,8 +3041,7 @@
 static void test_tbf_egprs_retx_dl(void)
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	uint8_t ts_no = 4;
 
 	fprintf(stderr, "=== start %s ===\n", __func__);
@@ -3093,8 +3069,7 @@
 static void test_tbf_egprs_spb_dl(void)
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	uint8_t ts_no = 4;
 
 	fprintf(stderr, "=== start %s ===\n", __func__);
@@ -3124,8 +3099,7 @@
 static void test_tbf_egprs_dl()
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	uint8_t ts_no = 4;
 	int i;
 
@@ -3148,8 +3122,7 @@
 static void test_packet_access_rej_prr_no_other_tbfs()
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	uint32_t fn = 2654218;
 	int ts_no = 7;
 	uint8_t trx_no = 0;
@@ -3184,8 +3157,7 @@
 static void test_packet_access_rej_prr()
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	uint32_t fn = 2654218;
 	uint16_t qta = 31;
 	int ts_no = 7;
@@ -3255,8 +3227,7 @@
 void test_packet_access_rej_epdan()
 {
 	the_pcu = gprs_pcu_alloc(tall_pcu_ctx);
-	the_pcu->bts = bts_alloc(the_pcu);
-	struct gprs_rlcmac_bts *bts = the_pcu->bts;
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	uint32_t tlli = 0xffeeddcc;
 	static uint8_t exp[] = { 0x40, 0x84, 0x7f, 0xf7, 0x6e, 0xe6, 0x41, 0x4b,
 				 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b, 0x2b,
diff --git a/tests/types/TypesTest.cpp b/tests/types/TypesTest.cpp
index 2da6a64..038d737 100644
--- a/tests/types/TypesTest.cpp
+++ b/tests/types/TypesTest.cpp
@@ -353,7 +353,7 @@
 		uint16_t lost = 0, recv = 0;
 		char show_rbb[65];
 		uint8_t bits_data[8];
-		struct gprs_rlcmac_bts *dummy_bts = bts_alloc(the_pcu);
+		struct gprs_rlcmac_bts *dummy_bts = bts_alloc(the_pcu, 0);
 		gprs_rlc_dl_window dl_win;
 		bitvec bits;
 		int bsn_begin, bsn_end, num_blocks;
@@ -671,7 +671,7 @@
 
 	fprintf(stderr, "############## test_egprs_ul_ack_nack\n");
 
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	the_pcu->alloc_algorithm = alloc_algorithm_a;
 	bts->trx[0].pdch[4].enable();
 
@@ -762,7 +762,7 @@
 
 void test_immediate_assign_dl()
 {
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	the_pcu->alloc_algorithm = alloc_algorithm_a;
 	bts->trx[0].pdch[2].enable();
 	bts->trx[0].pdch[3].enable();
@@ -787,7 +787,7 @@
 
 void test_immediate_assign_ul0m()
 {
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	the_pcu->alloc_algorithm = alloc_algorithm_a;
 	bts->trx[0].pdch[4].enable();
 	bts->trx[0].pdch[5].enable();
@@ -829,7 +829,7 @@
 
 void test_immediate_assign_ul1s()
 {
-	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu);
+	struct gprs_rlcmac_bts *bts = bts_alloc(the_pcu, 0);
 	the_pcu->alloc_algorithm = alloc_algorithm_a;
 	bts->trx[0].pdch[1].enable();
 	bts->trx[0].pdch[2].enable();