summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Stuge <peter@stuge.se>2012-12-27 18:26:22 +0100
committerHolger Hans Peter Freyther <zecke@selfish.org>2012-12-30 18:36:36 +0100
commit2a3876295fdacd75db20b7571e7d3b438b12f895 (patch)
treedf47b9aee24cfd86109b0ff736b93301109d307f
parentd831fdcd95db8b5dc49ee5aa84565856ef18f612 (diff)
introduce control interface command to return the number of currently active subscriberszecke/29c3
-rwxr-xr-xopenbsc/contrib/bsc_control.py2
-rw-r--r--openbsc/include/openbsc/db.h1
-rw-r--r--openbsc/src/libctrl/control_if.c30
-rw-r--r--openbsc/src/libmsc/db.c22
4 files changed, 55 insertions, 0 deletions
diff --git a/openbsc/contrib/bsc_control.py b/openbsc/contrib/bsc_control.py
index 9dc01e3..beec4c4 100755
--- a/openbsc/contrib/bsc_control.py
+++ b/openbsc/contrib/bsc_control.py
@@ -34,6 +34,7 @@ def send(sck, data):
if verbose:
print "Sending \"%s\"" %(data)
data = prefix_ipa_ctrl_header(data)
+ print data.encode("hex")
sck.send(data)
def do_set(var, value, id, sck):
@@ -83,6 +84,7 @@ if options.cmd_set:
if options.cmd_get:
if len(args) != 1:
parser.error("Get requires the var argument")
+ print options.id
do_get(args[0], options.id, sock)
data = sock.recv(1024)
diff --git a/openbsc/include/openbsc/db.h b/openbsc/include/openbsc/db.h
index 25c2aea..1d026df 100644
--- a/openbsc/include/openbsc/db.h
+++ b/openbsc/include/openbsc/db.h
@@ -48,6 +48,7 @@ int db_subscriber_alloc_token(struct gsm_subscriber *subscriber, uint32_t* token
int db_subscriber_assoc_imei(struct gsm_subscriber *subscriber, char *imei);
int db_sync_equipment(struct gsm_equipment *equip);
int db_subscriber_update(struct gsm_subscriber *subscriber);
+int db_get_active_subscribers(void);
/* auth info */
int db_get_authinfo_for_subscr(struct gsm_auth_info *ainfo,
diff --git a/openbsc/src/libctrl/control_if.c b/openbsc/src/libctrl/control_if.c
index beb5b43..45d7eb5 100644
--- a/openbsc/src/libctrl/control_if.c
+++ b/openbsc/src/libctrl/control_if.c
@@ -43,6 +43,8 @@
#include <openbsc/debug.h>
#include <openbsc/gsm_data.h>
#include <openbsc/ipaccess.h>
+#include <openbsc/db.h>
+
#include <openbsc/socket.h>
#include <osmocom/abis/subchan_demux.h>
@@ -608,6 +610,31 @@ static int verify_rate_ctr(struct ctrl_cmd *cmd, const char *value, void *data)
return 0;
}
+/* active subscribers */
+CTRL_CMD_DEFINE(active_subscribers, "active_subscribers");
+static int get_active_subscribers(struct ctrl_cmd *cmd, void *data)
+{
+ cmd->reply = talloc_asprintf(cmd, "%d", db_get_active_subscribers());
+ if (!cmd->reply) {
+ cmd->reply = "OOM";
+ goto err;
+ }
+
+ return CTRL_CMD_REPLY;
+err:
+ return CTRL_CMD_ERROR;
+}
+
+static int verify_active_subscribers(struct ctrl_cmd *cmd, const char *value, void *data)
+{
+ return 0;
+}
+
+static int set_active_subscribers(struct ctrl_cmd *cmd, void *data)
+{
+ return 0;
+}
+
/* counter */
CTRL_CMD_DEFINE(counter, "counter *");
static int get_counter(struct ctrl_cmd *cmd, void *data)
@@ -695,6 +722,9 @@ struct ctrl_handle *controlif_setup(struct gsm_network *gsmnet, uint16_t port)
ret = ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_counter);
if (ret)
goto err_vec;
+ ret = ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_active_subscribers);
+ if (ret)
+ goto err_vec;
return ctrl;
err_vec:
diff --git a/openbsc/src/libmsc/db.c b/openbsc/src/libmsc/db.c
index 4e20e23..3ec5ccd 100644
--- a/openbsc/src/libmsc/db.c
+++ b/openbsc/src/libmsc/db.c
@@ -315,6 +315,28 @@ int db_fini(void)
return 0;
}
+int db_get_active_subscribers(void) {
+ dbi_result result;
+ const char *res;
+ unsigned subscriber = 0;
+ result = dbi_conn_queryf(conn,
+ "SELECT COUNT(ID) AS C FROM Subscriber WHERE LAC != 0 AND AUTHORIZED=1");
+
+ if (!result) {
+ LOGP(DDB, LOGL_ERROR, "failed to get active subscribers\n");
+ return subscriber;
+ }
+ if (!dbi_result_next_row(result)) {
+ dbi_result_free(result);
+ LOGP(DDB, LOGL_ERROR, "dbi_result_next_row() returned NULL\n");
+ return subscriber;
+ }
+ res = dbi_result_get_string(result, "C");
+ subscriber = atoi(res);
+
+ return subscriber;
+}
+
struct gsm_subscriber *db_create_subscriber(struct gsm_network *net, char *imsi)
{
dbi_result result;