Change in osmo-bts[master]: bts: Allocate TRX for BTS dynamically, deprecate -t

Harald Welte gerrit-no-reply at lists.osmocom.org
Sun Nov 18 20:29:40 UTC 2018


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/11735 )

Change subject: bts: Allocate TRX for BTS dynamically, deprecate -t
......................................................................

bts: Allocate TRX for BTS dynamically, deprecate -t

No need to pass -t num_trx anymore to specify number of TRX to use. It
is calculated based on dynamic allocation from VTY config.
Using parameter -t is flagged as deprecated and is transformed into a
NOOP por backward compatibility.

As a result, TRX now are allocated after the BTS is allocated and
initial config (pre-VTY) is applied.
A new function bts_trx_init() is added, to set default config on each
TRX during allocation and before setting VTY config on it.
A new per BTS model function bts_model_trx_init() is added, to allow
per model specific default configuration of each TRX.

Change-Id: Iab1a754ab12a626759f9f90aa66f87bdce65ac9c
---
M include/osmo-bts/bts.h
M include/osmo-bts/bts_model.h
M src/common/bts.c
M src/common/main.c
M src/common/vty.c
M src/osmo-bts-litecell15/main.c
M src/osmo-bts-oc2g/main.c
M src/osmo-bts-octphy/l1_if.c
M src/osmo-bts-omldummy/bts_model.c
M src/osmo-bts-sysmo/main.c
M src/osmo-bts-trx/main.c
M src/osmo-bts-virtual/main.c
M tests/handover/handover_test.c
M tests/meas/meas_test.c
M tests/stubs.c
M tests/sysmobts/sysmobts_test.c
16 files changed, 119 insertions(+), 61 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Vadim Yanitskiy: Looks good to me, but someone else must approve
  Jenkins Builder: Verified



diff --git a/include/osmo-bts/bts.h b/include/osmo-bts/bts.h
index 34ba956..d7c4bbf 100644
--- a/include/osmo-bts/bts.h
+++ b/include/osmo-bts/bts.h
@@ -27,6 +27,7 @@
 extern void *tall_bts_ctx;
 
 int bts_init(struct gsm_bts *bts);
+int bts_trx_init(struct gsm_bts_trx *trx);
 void bts_shutdown(struct gsm_bts *bts, const char *reason);
 
 struct gsm_bts *create_bts(uint8_t num_trx, char *id);
diff --git a/include/osmo-bts/bts_model.h b/include/osmo-bts/bts_model.h
index 7a87d78..f1f6830 100644
--- a/include/osmo-bts/bts_model.h
+++ b/include/osmo-bts/bts_model.h
@@ -14,6 +14,7 @@
 /* BTS model specific functions needed by the common code */
 
 int bts_model_init(struct gsm_bts *bts);
+int bts_model_trx_init(struct gsm_bts_trx *trx);
 
 int bts_model_check_oml(struct gsm_bts *bts, uint8_t msg_type,
 			struct tlv_parsed *old_attr, struct tlv_parsed *new_attr,
diff --git a/src/common/bts.c b/src/common/bts.c
index c251fdd..68cb167 100644
--- a/src/common/bts.c
+++ b/src/common/bts.c
@@ -105,11 +105,10 @@
 	bts_ctr_desc
 };
 
-/* Initialize the BTS (and TRX) data structures, called before config
+/* Initialize the BTS data structures, called before config
  * file reading */
 int bts_init(struct gsm_bts *bts)
 {
-	struct gsm_bts_trx *trx;
 	int rc, i;
 	static int initialized = 0;
 	void *tall_rtp_ctx;
@@ -167,26 +166,6 @@
 	oml_mo_state_init(&bts->gprs.nsvc[0].mo, -1, NM_AVSTATE_DEPENDENCY);
 	oml_mo_state_init(&bts->gprs.nsvc[1].mo, NM_OPSTATE_DISABLED, NM_AVSTATE_OFF_LINE);
 
-	/* initialize bts data structure */
-	llist_for_each_entry(trx, &bts->trx_list, list) {
-		struct trx_power_params *tpp = &trx->power_params;
-		int i;
-
-		for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
-			struct gsm_bts_trx_ts *ts = &trx->ts[i];
-			int k;
-
-			for (k = 0; k < ARRAY_SIZE(ts->lchan); k++) {
-				struct gsm_lchan *lchan = &ts->lchan[k];
-				INIT_LLIST_HEAD(&lchan->dl_tch_queue);
-			}
-		}
-		/* Default values for the power adjustments */
-		tpp->ramp.max_initial_pout_mdBm = to_mdB(0);
-		tpp->ramp.step_size_mdB = to_mdB(2);
-		tpp->ramp.step_interval_sec = 1;
-	}
-
 	/* allocate a talloc pool for ORTP to ensure it doesn't have to go back
 	 * to the libc malloc all the time */
 	tall_rtp_ctx = talloc_pool(tall_bts_ctx, 262144);
@@ -215,6 +194,36 @@
 	return rc;
 }
 
+/* Initialize the TRX data structures, called before config
+ * file reading */
+int bts_trx_init(struct gsm_bts_trx *trx)
+{
+	/* initialize bts data structure */
+	struct trx_power_params *tpp = &trx->power_params;
+	int rc, i;
+
+	for (i = 0; i < ARRAY_SIZE(trx->ts); i++) {
+		struct gsm_bts_trx_ts *ts = &trx->ts[i];
+		int k;
+
+		for (k = 0; k < ARRAY_SIZE(ts->lchan); k++) {
+			struct gsm_lchan *lchan = &ts->lchan[k];
+			INIT_LLIST_HEAD(&lchan->dl_tch_queue);
+		}
+	}
+	/* Default values for the power adjustments */
+	tpp->ramp.max_initial_pout_mdBm = to_mdB(0);
+	tpp->ramp.step_size_mdB = to_mdB(2);
+	tpp->ramp.step_interval_sec = 1;
+
+	rc = bts_model_trx_init(trx);
+	if (rc < 0) {
+		llist_del(&trx->list);
+		return rc;
+	}
+	return 0;
+}
+
 static void shutdown_timer_cb(void *data)
 {
 	fprintf(stderr, "Shutdown timer expired\n");
diff --git a/src/common/main.c b/src/common/main.c
index 9121a2a..f90a4d4 100644
--- a/src/common/main.c
+++ b/src/common/main.c
@@ -59,7 +59,6 @@
 static const char *config_file = "osmo-bts.cfg";
 static int daemonize = 0;
 static int rt_prio = -1;
-static int trx_num = 1;
 static char *gsmtap_ip = 0;
 extern int g_vty_port_num;
 
@@ -76,8 +75,6 @@
 		"  -e 	--log-level	Set a global log-level\n"
 		"  -r	--realtime PRIO	Use SCHED_RR with the specified priority\n"
 		"  -i	--gsmtap-ip	The destination IP used for GSMTAP.\n"
-		"  -t	--trx-num	Set number of TRX (default=%d)\n",
-		trx_num
 		);
 	bts_model_print_help();
 }
@@ -152,9 +149,8 @@
 			gsmtap_ip = optarg;
 			break;
 		case 't':
-			trx_num = atoi(optarg);
-			if (trx_num < 1)
-				trx_num = 1;
+			fprintf(stderr, "Parameter -t is deprecated and does nothing, "
+					"TRX num is calculated from VTY\n");
 			break;
 		case '?':
 		case 1:
@@ -228,7 +224,7 @@
 {
 	struct gsm_bts_trx *trx;
 	struct e1inp_line *line;
-	int rc, i;
+	int rc;
 
 	printf("((*))\n  |\n / \\ OsmoBTS\n");
 
@@ -251,13 +247,7 @@
 		fprintf(stderr, "Failed to create BTS structure\n");
 		exit(1);
 	}
-	for (i = 1; i < trx_num; i++) {
-		trx = gsm_bts_trx_alloc(bts);
-		if (!trx) {
-			fprintf(stderr, "Failed to create TRX structure\n");
-			exit(1);
-		}
-	}
+
 	e1inp_vty_init();
 	bts_vty_init(bts, &bts_log_info);
 
diff --git a/src/common/vty.c b/src/common/vty.c
index f918f57..f305413 100644
--- a/src/common/vty.c
+++ b/src/common/vty.c
@@ -227,12 +227,22 @@
 	struct gsm_bts *bts = vty->index;
 	struct gsm_bts_trx *trx;
 
-	trx = gsm_bts_trx_num(bts, trx_nr);
+
+	if (trx_nr > bts->num_trx) {
+		vty_out(vty, "%% The next unused TRX number is %u%s",
+			bts->num_trx, VTY_NEWLINE);
+		return CMD_WARNING;
+	} else if (trx_nr == bts->num_trx) {
+		/* allocate a new one */
+		trx = gsm_bts_trx_alloc(bts);
+		if (trx)
+			bts_trx_init(trx);
+	} else
+		trx = gsm_bts_trx_num(bts, trx_nr);
+
 	if (!trx) {
-		vty_out(vty, "Unknown TRX %u. Available TRX are: 0..%u%s",
-			trx_nr, bts->num_trx - 1, VTY_NEWLINE);
-		vty_out(vty, "Hint: Check if commandline option -t matches the"
-			"number of available transceivers!%s", VTY_NEWLINE);
+		vty_out(vty, "%% Unable to allocate TRX %u%s",
+			trx_nr, VTY_NEWLINE);
 		return CMD_WARNING;
 	}
 
diff --git a/src/osmo-bts-litecell15/main.c b/src/osmo-bts-litecell15/main.c
index de175e3..e4f9a56 100644
--- a/src/osmo-bts-litecell15/main.c
+++ b/src/osmo-bts-litecell15/main.c
@@ -79,11 +79,6 @@
 		exit(1);
 	}
 
-	llist_for_each_entry(trx, &bts->trx_list, list) {
-		trx->nominal_power = 40;
-		trx->power_params.trx_p_max_out_mdBm = to_mdB(bts->c0->nominal_power);
-	}
-
 	if (stat(LC15BTS_RF_LOCK_PATH, &st) == 0) {
 		LOGP(DL1C, LOGL_NOTICE, "Not starting BTS due to RF_LOCK file present\n");
 		exit(23);
@@ -104,6 +99,13 @@
 	return 0;
 }
 
+int bts_model_trx_init(struct gsm_bts_trx *trx)
+{
+	trx->nominal_power = 40;
+	trx->power_params.trx_p_max_out_mdBm = to_mdB(trx->bts->c0->nominal_power);
+	return 0;
+}
+
 void bts_model_phy_link_set_defaults(struct phy_link *plink)
 {
 }
diff --git a/src/osmo-bts-oc2g/main.c b/src/osmo-bts-oc2g/main.c
index 9777c09..574bc72 100644
--- a/src/osmo-bts-oc2g/main.c
+++ b/src/osmo-bts-oc2g/main.c
@@ -105,11 +105,6 @@
 		exit(1);
 	}
 
-	llist_for_each_entry(trx, &bts->trx_list, list) {
-		trx->nominal_power = 40;
-		trx->power_params.trx_p_max_out_mdBm = to_mdB(bts->c0->nominal_power);
-	}
-
 	if (stat(OC2GBTS_RF_LOCK_PATH, &st) == 0) {
 		LOGP(DL1C, LOGL_NOTICE, "Not starting BTS due to RF_LOCK file present\n");
 		exit(23);
@@ -130,6 +125,13 @@
 	return 0;
 }
 
+int bts_model_trx_init(struct gsm_bts_trx *trx)
+{
+	trx->nominal_power = 40;
+	trx->power_params.trx_p_max_out_mdBm = to_mdB(trx->bts->c0->nominal_power);
+	return 0;
+}
+
 void bts_model_phy_link_set_defaults(struct phy_link *plink)
 {
 }
diff --git a/src/osmo-bts-octphy/l1_if.c b/src/osmo-bts-octphy/l1_if.c
index 40d5300..f149c04 100644
--- a/src/osmo-bts-octphy/l1_if.c
+++ b/src/osmo-bts-octphy/l1_if.c
@@ -792,6 +792,11 @@
 	return 0;
 }
 
+int bts_model_trx_init(struct gsm_bts_trx *trx)
+{
+	return 0;
+}
+
 /***********************************************************************
  * handling of messages coming up from PHY
  ***********************************************************************/
diff --git a/src/osmo-bts-omldummy/bts_model.c b/src/osmo-bts-omldummy/bts_model.c
index 9ade2c6..fa1aaf4 100644
--- a/src/osmo-bts-omldummy/bts_model.c
+++ b/src/osmo-bts-omldummy/bts_model.c
@@ -179,6 +179,11 @@
 	return 0;
 }
 
+int bts_model_trx_init(struct gsm_bts_trx *trx)
+{
+	return 0;
+}
+
 void bts_model_print_help()
 {
 }
diff --git a/src/osmo-bts-sysmo/main.c b/src/osmo-bts-sysmo/main.c
index b63d07e..221e8e8 100644
--- a/src/osmo-bts-sysmo/main.c
+++ b/src/osmo-bts-sysmo/main.c
@@ -91,6 +91,11 @@
 	return 0;
 }
 
+int bts_model_trx_init(struct gsm_bts_trx *trx)
+{
+	return 0;
+}
+
 int bts_model_oml_estab(struct gsm_bts *bts)
 {
 	return 0;
diff --git a/src/osmo-bts-trx/main.c b/src/osmo-bts-trx/main.c
index 61610f7..98f460e 100644
--- a/src/osmo-bts-trx/main.c
+++ b/src/osmo-bts-trx/main.c
@@ -118,6 +118,11 @@
 	return 0;
 }
 
+int bts_model_trx_init(struct gsm_bts_trx *trx)
+{
+	return 0;
+}
+
 void bts_model_phy_link_set_defaults(struct phy_link *plink)
 {
 	plink->u.osmotrx.local_ip = talloc_strdup(plink, "127.0.0.1");
diff --git a/src/osmo-bts-virtual/main.c b/src/osmo-bts-virtual/main.c
index b66a3ff..88041fd 100644
--- a/src/osmo-bts-virtual/main.c
+++ b/src/osmo-bts-virtual/main.c
@@ -72,6 +72,11 @@
 	return 0;
 }
 
+int bts_model_trx_init(struct gsm_bts_trx *trx)
+{
+	return 0;
+}
+
 void bts_model_print_help()
 {
 	LOGP(DSUM, LOGL_NOTICE, "Unimplemented %s\n", __func__);
diff --git a/tests/handover/handover_test.c b/tests/handover/handover_test.c
index c7bd8f8..407ed95 100644
--- a/tests/handover/handover_test.c
+++ b/tests/handover/handover_test.c
@@ -75,14 +75,18 @@
 		fprintf(stderr, "Failed to create BTS structure\n");
 		exit(1);
 	}
-	trx = gsm_bts_trx_alloc(bts);
-	if (!trx) {
-		fprintf(stderr, "Failed to TRX structure\n");
+	if (bts_init(bts) < 0) {
+		fprintf(stderr, "unable to init BTS\n");
 		exit(1);
 	}
 
-	if (bts_init(bts) < 0) {
-		fprintf(stderr, "unable to to open bts\n");
+	trx = gsm_bts_trx_alloc(bts);
+	if (!trx) {
+		fprintf(stderr, "Failed to alloc TRX structure\n");
+		exit(1);
+	}
+	if (bts_trx_init(trx) < 0) {
+		fprintf(stderr, "unable to init TRX\n");
 		exit(1);
 	}
 
@@ -268,6 +272,7 @@
 int bts_model_opstart(struct gsm_bts *bts, struct gsm_abis_mo *mo, void *obj) { return 0; }
 int bts_model_chg_adm_state(struct gsm_bts *bts, struct gsm_abis_mo *mo, void *obj, uint8_t adm_state) { return 0; }
 int bts_model_init(struct gsm_bts *bts) { return 0; }
+int bts_model_trx_init(struct gsm_bts_trx *trx) { return 0; }
 int bts_model_trx_deact_rf(struct gsm_bts_trx *trx) { return 0; }
 int bts_model_trx_close(struct gsm_bts_trx *trx) { return 0; }
 void trx_get_hlayer1(void) {}
diff --git a/tests/meas/meas_test.c b/tests/meas/meas_test.c
index d4f3fe6..f580374 100644
--- a/tests/meas/meas_test.c
+++ b/tests/meas/meas_test.c
@@ -519,14 +519,18 @@
 		fprintf(stderr, "Failed to create BTS structure\n");
 		exit(1);
 	}
-	trx = gsm_bts_trx_alloc(bts);
-	if (!trx) {
-		fprintf(stderr, "Failed to TRX structure\n");
+	if (bts_init(bts) < 0) {
+		fprintf(stderr, "unable to init BTS\n");
 		exit(1);
 	}
 
-	if (bts_init(bts) < 0) {
-		fprintf(stderr, "unable to to open bts\n");
+	trx = gsm_bts_trx_alloc(bts);
+	if (!trx) {
+		fprintf(stderr, "Failed to alloc TRX structure\n");
+		exit(1);
+	}
+	if (bts_trx_init(trx) < 0) {
+		fprintf(stderr, "unable to init TRX\n");
 		exit(1);
 	}
 
@@ -626,6 +630,11 @@
 	return 0;
 }
 
+int bts_model_trx_init(struct gsm_bts_trx *trx)
+{
+	return 0;
+}
+
 int bts_model_trx_deact_rf(struct gsm_bts_trx *trx)
 {
 	return 0;
diff --git a/tests/stubs.c b/tests/stubs.c
index f969cb3..d6f4d3d 100644
--- a/tests/stubs.c
+++ b/tests/stubs.c
@@ -13,6 +13,8 @@
 { return 0; }
 int bts_model_init(struct gsm_bts *bts)
 { return 0; }
+int bts_model_trx_init(struct gsm_bts_trx *trx)
+{ return 0; }
 int bts_model_apply_oml(struct gsm_bts *bts, struct msgb *msg,
 			struct tlv_parsed *new_attr, int kind, void *obj)
 { return 0; }
diff --git a/tests/sysmobts/sysmobts_test.c b/tests/sysmobts/sysmobts_test.c
index 02490be..4b01ed7 100644
--- a/tests/sysmobts/sysmobts_test.c
+++ b/tests/sysmobts/sysmobts_test.c
@@ -198,6 +198,8 @@
 
 int bts_model_init(struct gsm_bts *bts)
 { return 0; }
+int bts_model_trx_init(struct gsm_bts_trx *trx)
+{ return 0; }
 int bts_model_oml_estab(struct gsm_bts *bts)
 { return 0; }
 void bts_model_abis_close(struct gsm_bts *bts)

-- 
To view, visit https://gerrit.osmocom.org/11735
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Iab1a754ab12a626759f9f90aa66f87bdce65ac9c
Gerrit-Change-Number: 11735
Gerrit-PatchSet: 4
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: Vadim Yanitskiy <axilirator at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181118/fb6f16d4/attachment.html>


More information about the gerrit-log mailing list