On 04/05/11 11:02, Harald Welte wrote:
> On Tue, May 03, 2011 at 11:29:16PM +0200, Holger Hans Peter Freyther wrote:
>> On 05/03/2011 10:44 PM, [email protected] wrote:
>>> From: Pablo Neira Ayuso <[email protected]>
>>>
>>> The daemon set up nanoBTS and HSL femto sockets by default,
>>> ie. the three sockets to support these two drivers are open even
>>> if we have no BTS of that kind. This patch enables them if they
>>> are present in any configuration file.
>>
>> good goal, but maybe trigger this from within the VTY code? E.g. what
>> if I want to add a HSL BTS to a running system? or start with no
>> config file at all? Anyway our story of doing such config changes at
>> runtime is not very good.
> 
> yes, but I agree we should do this from the VTY code.  At least all new
> features we're adding should be more runtime vty based then thinking of
> a config file that we parse once and then forget about it.
> 
> So when we get a 'bts type ...' command (or when we leave the BTS_NODE)
> we should check if the respective sockets are needed.

You can find a patch attached to support what you describe, I tried to
make as generic as possible. Please, have a look at the description.

The new start(...) function for e1inp_driver objects could be use to
replace the e1inp_init() call. The idea that I propose is to register
the dahdi and misdn input drivers if we receive an "e1_input" command
(via VTY or config file), then invoke start(...).

BTW, e1inp_init() is only used by osmo-nitb, any reason for that?

I also added a new attribute to the BTS model object, this field is
useless for bs11. I found no way to relate e1inp_driver and bts objects
in the case of hsl and ipaccess. This is usually done by means of the
"e1_input" command in bs11, but its use does not make sense for hsl and
ipaccess.

> But yes, another big long pending TODO is to think about how we can
> make most or even all runtime config changes work.

Adding support for config file reload in runtime seems interesting to
me, I would prefer changing things in the config file and reloading than
typing all those VTY commands to add a new BTS, IMO.
bsc: on-demand setup of nanoBTS and HSL femto sockets

From: Pablo Neira Ayuso <[email protected]>

The daemon set up nanoBTS and HSL femto sockets by default, ie. the
three sockets to support these two drivers are open even if we have
no BTS of that kind.

This patch adds two new attributes to the e1inp_driver object,
they are:

* the start() function for A-bis input drivers, which is used to
create the sockets.
* refcnt, which is used to know how many BTS are using this driver.
We use it to know if this is the first BTS that uses the driver, in
that case, we trigger the socket initialization. This would be useful
in the near future if we decide to support disabling BTS in runtime.
---
 openbsc/include/openbsc/e1_input.h        |    5 +++++
 openbsc/include/openbsc/gsm_data.h        |    6 ++++++
 openbsc/src/libabis/input/hsl.c           |    6 +++++-
 openbsc/src/libabis/input/ipaccess.c      |    6 +++++-
 openbsc/src/libbsc/bsc_init.c             |    6 +-----
 openbsc/src/libbsc/bsc_vty.c              |    6 ++++++
 openbsc/src/libbsc/bts_hsl_femtocell.c    |    1 +
 openbsc/src/libbsc/bts_ipaccess_nanobts.c |    2 ++
 openbsc/src/libcommon/gsm_data.c          |   18 ++++++++++++++++++
 9 files changed, 49 insertions(+), 7 deletions(-)

diff --git a/openbsc/include/openbsc/e1_input.h b/openbsc/include/openbsc/e1_input.h
index 8a966ad..036a52f 100644
--- a/openbsc/include/openbsc/e1_input.h
+++ b/openbsc/include/openbsc/e1_input.h
@@ -98,9 +98,11 @@ struct e1inp_ts {
 struct e1inp_driver {
 	struct llist_head list;
 	const char *name;
+	int (*start)(void *data);
 	int (*want_write)(struct e1inp_ts *ts);
 	int (*line_update)(struct e1inp_line *line);
 	int default_delay;
+	int refcnt;
 };	
 
 struct e1inp_line {
@@ -184,4 +186,7 @@ void e1inp_init(void);
 
 int _abis_nm_sendmsg(struct msgb *msg, int to_trx_oml);
 
+extern struct e1inp_driver ipaccess_driver;
+extern struct e1inp_driver hsl_driver;
+
 #endif /* _E1_INPUT_H */
diff --git a/openbsc/include/openbsc/gsm_data.h b/openbsc/include/openbsc/gsm_data.h
index 31044ec..e61a673 100644
--- a/openbsc/include/openbsc/gsm_data.h
+++ b/openbsc/include/openbsc/gsm_data.h
@@ -434,6 +434,9 @@ struct gsm_bts_model {
 	enum gsm_bts_type type;
 	const char *name;
 
+	/* This BTS model requires one specific A-bis input driver */
+	struct e1inp_driver *abis_driver;
+
 	int (*oml_rcvmsg)(struct msgb *msg);
 
 	void (*config_write_bts)(struct vty *vty, struct gsm_bts *bts);
@@ -809,6 +812,9 @@ struct gsm_bts *gsm_bts_alloc(struct gsm_network *net, enum gsm_bts_type type,
 struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts);
 int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
 
+/* Start A-bis driver for one existing BTS */
+int gsm_bts_abis_driver_start(struct gsm_bts *bts);
+
 struct gsm_bts *gsm_bts_num(struct gsm_network *net, int num);
 
 /* Get reference to a neighbor cell on a given BCCH ARFCN */
diff --git a/openbsc/src/libabis/input/hsl.c b/openbsc/src/libabis/input/hsl.c
index 44528dd..659c56e 100644
--- a/openbsc/src/libabis/input/hsl.c
+++ b/openbsc/src/libabis/input/hsl.c
@@ -370,8 +370,11 @@ static int hsl_fd_cb(struct bsc_fd *bfd, unsigned int what)
 	return rc;
 }
 
+static int hsl_start(void *data);
+
 struct e1inp_driver hsl_driver = {
 	.name = "HSL",
+	.start = hsl_start,
 	.want_write = ts_want_write,
 	.default_delay = 0,
 };
@@ -433,9 +436,10 @@ static int listen_fd_cb(struct bsc_fd *listen_bfd, unsigned int what)
 	//return e1inp_line_register(line);
 }
 
-int hsl_setup(struct gsm_network *gsmnet)
+static int hsl_start(void *data)
 {
 	int ret;
+	struct gsm_network *gsmnet = data;
 
 	/* register the driver with the core */
 	/* FIXME: do this in the plugin initializer function */
diff --git a/openbsc/src/libabis/input/ipaccess.c b/openbsc/src/libabis/input/ipaccess.c
index d2572fb..5fdc442 100644
--- a/openbsc/src/libabis/input/ipaccess.c
+++ b/openbsc/src/libabis/input/ipaccess.c
@@ -663,8 +663,11 @@ static int ipaccess_fd_cb(struct bsc_fd *bfd, unsigned int what)
 	return rc;
 }
 
+static int ipaccess_start(void *data);
+
 struct e1inp_driver ipaccess_driver = {
 	.name = "ip.access",
+	.start = ipaccess_start,
 	.want_write = ts_want_write,
 	.default_delay = 0,
 };
@@ -808,9 +811,10 @@ int ipaccess_connect(struct e1inp_line *line, struct sockaddr_in *sa)
 	//return e1inp_line_register(line);
 }
 
-int ipaccess_setup(struct gsm_network *gsmnet)
+static int ipaccess_start(void *data)
 {
 	int ret;
+	struct gsm_network *gsmnet = data;
 
 	/* register the driver with the core */
 	/* FIXME: do this in the plugin initializer function */
diff --git a/openbsc/src/libbsc/bsc_init.c b/openbsc/src/libbsc/bsc_init.c
index 1d14df1..42cc03f 100644
--- a/openbsc/src/libbsc/bsc_init.c
+++ b/openbsc/src/libbsc/bsc_init.c
@@ -443,6 +443,7 @@ int bsc_bootstrap_network(int (*mncc_recv)(struct gsm_network *, struct msgb *),
 		switch (bts->type) {
 		case GSM_BTS_TYPE_NANOBTS:
 		case GSM_BTS_TYPE_HSL_FEMTO:
+			rc = gsm_bts_abis_driver_start(bts);
 			break;
 		default:
 			rc = e1_reconfig_bts(bts);
@@ -454,10 +455,5 @@ int bsc_bootstrap_network(int (*mncc_recv)(struct gsm_network *, struct msgb *),
 			exit (1);
 		}
 	}
-
-	/* initialize nanoBTS support omce */
-	rc = ipaccess_setup(bsc_gsmnet);
-	rc = hsl_setup(bsc_gsmnet);
-
 	return 0;
 }
diff --git a/openbsc/src/libbsc/bsc_vty.c b/openbsc/src/libbsc/bsc_vty.c
index 5a4bd6e..b12d977 100644
--- a/openbsc/src/libbsc/bsc_vty.c
+++ b/openbsc/src/libbsc/bsc_vty.c
@@ -1469,6 +1469,12 @@ DEFUN(cfg_bts_type,
 	if (rc < 0)
 		return CMD_WARNING;
 
+	rc = gsm_bts_abis_driver_start(bts);
+	if (rc < 0) {
+		vty_out(vty, "%% Unable to start A-bis driver for this BTS%s",
+			VTY_NEWLINE);
+		return CMD_WARNING;
+	}
 	return CMD_SUCCESS;
 }
 
diff --git a/openbsc/src/libbsc/bts_hsl_femtocell.c b/openbsc/src/libbsc/bts_hsl_femtocell.c
index 9bbf6d2..723693d 100644
--- a/openbsc/src/libbsc/bts_hsl_femtocell.c
+++ b/openbsc/src/libbsc/bts_hsl_femtocell.c
@@ -32,6 +32,7 @@
 
 static struct gsm_bts_model model_hslfemto = {
 	.type = GSM_BTS_TYPE_HSL_FEMTO,
+	.abis_driver = &hsl_driver,
 	.nm_att_tlvdef = {
 		.def = {
 			/* no HSL specific OML attributes that we know of */
diff --git a/openbsc/src/libbsc/bts_ipaccess_nanobts.c b/openbsc/src/libbsc/bts_ipaccess_nanobts.c
index 097a889..325a916 100644
--- a/openbsc/src/libbsc/bts_ipaccess_nanobts.c
+++ b/openbsc/src/libbsc/bts_ipaccess_nanobts.c
@@ -26,10 +26,12 @@
 #include <openbsc/gsm_data.h>
 #include <openbsc/signal.h>
 #include <openbsc/abis_nm.h>
+#include <openbsc/e1_input.h>
 
 static struct gsm_bts_model model_nanobts = {
 	.type = GSM_BTS_TYPE_NANOBTS,
 	.name = "nanobts",
+	.abis_driver = &ipaccess_driver,
 	.oml_rcvmsg = &abis_nm_rcvmsg,
 	.nm_att_tlvdef = {
 		.def = {
diff --git a/openbsc/src/libcommon/gsm_data.c b/openbsc/src/libcommon/gsm_data.c
index 5437548..0310476 100644
--- a/openbsc/src/libcommon/gsm_data.c
+++ b/openbsc/src/libcommon/gsm_data.c
@@ -34,6 +34,7 @@
 #include <openbsc/gsm_data.h>
 #include <openbsc/osmo_msc_data.h>
 #include <openbsc/abis_nm.h>
+#include <openbsc/e1_input.h>
 
 void *tall_bsc_ctx;
 
@@ -592,3 +593,20 @@ int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type)
 
 	return 0;
 }
+
+int gsm_bts_abis_driver_start(struct gsm_bts *bts)
+{
+	int rc = 0;
+
+	/* This BTS requires one A-bis over IP interface, initialize it. */
+	if (bts->model->abis_driver) {
+		/* Create sockets once only. */
+		if (bts->model->abis_driver->refcnt == 0) {
+			rc = bts->model->abis_driver->start(bts->network);
+			if (rc < 0)
+				return rc;
+		}
+		bts->model->abis_driver->refcnt++;
+	}
+	return rc;
+}

Reply via email to