summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Kluchnikov <kluchnikovi@gmail.com>2014-04-14 13:30:25 +0400
committerIvan Kluchnikov <kluchnikovi@gmail.com>2014-05-06 15:40:30 +0400
commitb5c84f628d2bdd8793048ec9bd31e0991be7329a (patch)
tree8d6a41859f22be49e2ef07110247b863a9ab2b95
parentf76ec6c87b9b088662003df07398075e7bfeef94 (diff)
nitb: Add ctrl command to get network channels load
-rw-r--r--openbsc/include/openbsc/control_cmd.h11
-rw-r--r--openbsc/src/libbsc/bsc_ctrl_commands.c43
2 files changed, 54 insertions, 0 deletions
diff --git a/openbsc/include/openbsc/control_cmd.h b/openbsc/include/openbsc/control_cmd.h
index 8aede15df..64a27f841 100644
--- a/openbsc/include/openbsc/control_cmd.h
+++ b/openbsc/include/openbsc/control_cmd.h
@@ -88,6 +88,17 @@ struct ctrl_cmd *ctrl_cmd_cpy(void *ctx, struct ctrl_cmd *cmd);
struct ctrl_cmd *ctrl_cmd_create(void *ctx, enum ctrl_type);
struct ctrl_cmd *ctrl_cmd_trap(struct ctrl_cmd *cmd);
+#define CTRL_HELPER_SET_STATUS(cmdname) \
+static int set_##cmdname(struct ctrl_cmd *cmd, void *_data) \
+{ \
+ cmd->reply = "Read only attribute"; \
+ return CTRL_CMD_ERROR; \
+}
+#define CTRL_HELPER_VERIFY_STATUS(cmdname) \
+static int verify_##cmdname(struct ctrl_cmd *cmd, const char *value, void *_data) \
+{ \
+ return 0;\
+}
#define CTRL_HELPER_GET_INT(cmdname, dtype, element) \
static int get_##cmdname(struct ctrl_cmd *cmd, void *_data) \
diff --git a/openbsc/src/libbsc/bsc_ctrl_commands.c b/openbsc/src/libbsc/bsc_ctrl_commands.c
index d1edf2903..8c75bd58d 100644
--- a/openbsc/src/libbsc/bsc_ctrl_commands.c
+++ b/openbsc/src/libbsc/bsc_ctrl_commands.c
@@ -23,6 +23,7 @@
#include <openbsc/ipaccess.h>
#include <openbsc/gsm_data.h>
#include <openbsc/abis_nm.h>
+#include <openbsc/chan_alloc.h>
#include <openbsc/debug.h>
#define CTRL_CMD_VTY_STRING(cmdname, cmdstr, dtype, element) \
@@ -183,6 +184,47 @@ oom:
}
CTRL_CMD_DEFINE(net_mcc_mnc_apply, "mcc-mnc-apply");
+CTRL_HELPER_VERIFY_STATUS(net_channels_load);
+CTRL_HELPER_SET_STATUS(net_channels_load);
+
+static int get_net_channels_load(struct ctrl_cmd *cmd, void *data)
+{
+ struct gsm_network *net = cmd->node;
+ struct pchan_load pl;
+ network_chan_load(&pl, net);
+ struct pchan_load* pl_ptr = &pl;
+
+ int i;
+
+ if (!strcmp(cmd->variable,"channels-load"))
+ cmd->reply = talloc_strdup(cmd, "\n");
+
+ for (i = 0; i < ARRAY_SIZE(pl_ptr->pchan); i++) {
+ const struct load_counter *lc = &pl_ptr->pchan[i];
+ unsigned int percent;
+
+ if (lc->total == 0)
+ continue;
+
+ percent = (lc->used * 100) / lc->total;
+ cmd->reply = talloc_asprintf_append(cmd->reply,
+ "channel_load.percent.%s,%u\n", gsm_pchan_name(i), percent);
+ cmd->reply = talloc_asprintf_append(cmd->reply,
+ "channel_load.lc_used.%s,%u\n", gsm_pchan_name(i), lc->used);
+ cmd->reply = talloc_asprintf_append(cmd->reply,
+ "channel_load.lc_total.%s,%u\n", gsm_pchan_name(i), lc->total);
+ }
+
+ if (!cmd->reply) {
+ cmd->reply = "OOM";
+ return CTRL_CMD_ERROR;
+ }
+
+ return CTRL_CMD_REPLY;
+}
+
+CTRL_CMD_DEFINE(net_channels_load, "channels-load");
+
/* BTS related commands below here */
static int verify_bts_band(struct ctrl_cmd *cmd, const char *value, void *data)
{
@@ -265,6 +307,7 @@ int bsc_base_ctrl_cmds_install(void)
rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_auth_policy);
rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_apply_config);
rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_mcc_mnc_apply);
+ rc |= ctrl_cmd_install(CTRL_NODE_ROOT, &cmd_net_channels_load);
rc |= ctrl_cmd_install(CTRL_NODE_BTS, &cmd_bts_band);