aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo-bts-sysmo/misc
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-07-31 18:48:35 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-08-21 15:49:06 +0200
commit013df51ca8693d39ee01252f71d1e61f7cff84b4 (patch)
tree140a7db0842dcb8ddbb5dbf398df1e1b118e2ce3 /src/osmo-bts-sysmo/misc
parent07198750b29fa891dd6c1d6266964691aa9e9095 (diff)
sysmobts: Add VTY support to the sysmobts-mgr
Add VTY support to the manager. This way we can interactively inspect the state of the system and trigger events.
Diffstat (limited to 'src/osmo-bts-sysmo/misc')
-rw-r--r--src/osmo-bts-sysmo/misc/sysmobts_mgr.c21
-rw-r--r--src/osmo-bts-sysmo/misc/sysmobts_mgr.h13
-rw-r--r--src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c133
3 files changed, 166 insertions, 1 deletions
diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c
index 41ee8143..ba3aa2ef 100644
--- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c
+++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c
@@ -47,6 +47,7 @@
static int no_eeprom_write = 0;
static int daemonize = 0;
+static const char *cfgfile = "sysmobts-mgr.cfg";
void *tall_mgr_ctx;
/* every 6 hours means 365*4 = 1460 EEprom writes per year (max) */
@@ -130,13 +131,14 @@ static void print_help(void)
printf(" -s Disable color\n");
printf(" -d CAT enable debugging\n");
printf(" -D daemonize\n");
+ printf(" -c Specify the filename of the config file\n");
}
static int parse_options(int argc, char **argv)
{
int opt;
- while ((opt = getopt(argc, argv, "nhsd:")) != -1) {
+ while ((opt = getopt(argc, argv, "nhsd:c:")) != -1) {
switch (opt) {
case 'n':
no_eeprom_write = 1;
@@ -153,6 +155,9 @@ static int parse_options(int argc, char **argv)
case 'D':
daemonize = 1;
break;
+ case 'c':
+ cfgfile = optarg;
+ break;
default:
return -1;
}
@@ -386,6 +391,20 @@ int main(int argc, char **argv)
if (rc < 0)
exit(2);
+ sysmobts_mgr_vty_init();
+ logging_vty_add_cmds(&mgr_log_info);
+ rc = sysmobts_mgr_parse_config(cfgfile);
+ if (rc < 0) {
+ LOGP(DFIND, LOGL_FATAL, "Cannot parse config file\n");
+ exit(1);
+ }
+
+ rc = telnet_init(tall_msgb_ctx, NULL, 4252);
+ if (rc < 0) {
+ fprintf(stderr, "Error initializing telnet\n");
+ exit(1);
+ }
+
/* start temperature check timer */
temp_timer.cb = check_temp_timer_cb;
check_temp_timer_cb(NULL);
diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr.h b/src/osmo-bts-sysmo/misc/sysmobts_mgr.h
index ddb6774a..aaa43736 100644
--- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.h
+++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.h
@@ -1,10 +1,23 @@
#ifndef _SYSMOBTS_MGR_H
#define _SYSMOBTS_MGR_H
+#include <osmocom/vty/vty.h>
+#include <osmocom/vty/command.h>
+
enum {
DTEMP,
DFW,
DFIND,
};
+enum mgr_vty_node {
+ MGR_NODE = _LAST_OSMOVTY_NODE + 1,
+};
+
+int sysmobts_mgr_vty_init(void);
+int sysmobts_mgr_parse_config(const char *config_file);
+
+struct sysmobts_mgr_instance {
+ const char *config_file;
+};
#endif
diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c
new file mode 100644
index 00000000..50d8e152
--- /dev/null
+++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c
@@ -0,0 +1,133 @@
+/* (C) 2014 by sysmocom - s.f.m.c. GmbH
+ *
+ * All Rights Reserved
+ *
+ * Author: Alvaro Neira Ayuso <anayuso@sysmocom.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdint.h>
+#include <ctype.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <osmocom/vty/vty.h>
+#include <osmocom/vty/command.h>
+#include <osmocom/vty/misc.h>
+
+#include <osmo-bts/logging.h>
+
+#include "sysmobts_misc.h"
+#include "sysmobts_mgr.h"
+#include "btsconfig.h"
+
+static const char copyright[] =
+ "(C) 2012 by Harald Welte <laforge@gnumonks.org>\r\n"
+ "(C) 2014 by Holger Hans Peter Freyther\r\n"
+ "License AGPLv3+: GNU AGPL version 2 or later <http://gnu.org/licenses/agpl-3.0.html>\r\n"
+ "This is free software: you are free to change and redistribute it.\r\n"
+ "There is NO WARRANTY, to the extent permitted by law.\r\n";
+
+static enum node_type go_to_parent(struct vty *vty)
+{
+ switch (vty->node) {
+ case MGR_NODE:
+ vty->node = CONFIG_NODE;
+ break;
+ default:
+ vty->node = CONFIG_NODE;
+ }
+ return vty->node;
+}
+
+static int is_config_node(struct vty *vty, int node)
+{
+ switch (node) {
+ case MGR_NODE:
+ return 1;
+ default:
+ return 0;
+ }
+}
+
+static struct vty_app_info vty_info = {
+ .name = "sysmobts-mgr",
+ .version = PACKAGE_VERSION,
+ .go_parent_cb = go_to_parent,
+ .is_config_node = is_config_node,
+ .copyright = copyright,
+};
+
+
+#define MGR_STR "Configure sysmobts-mgr\n"
+
+static struct cmd_node mgr_node = {
+ MGR_NODE,
+ "%s(sysmobts-mgr)# ",
+ 1,
+};
+
+DEFUN(cfg_mgr, cfg_mgr_cmd,
+ "sysmobts-mgr",
+ MGR_STR)
+{
+ vty->node = MGR_NODE;
+ return CMD_SUCCESS;
+}
+
+DEFUN(show_mgr, show_mgr_cmd, "show manager",
+ SHOW_STR "Display information about the manager")
+{
+ return CMD_SUCCESS;
+}
+
+static int config_write_mgr(struct vty *vty)
+{
+ vty_out(vty, "sysmobts-mgr%s", VTY_NEWLINE);
+ return CMD_SUCCESS;
+}
+
+int sysmobts_mgr_vty_init(void)
+{
+ vty_init(&vty_info);
+
+ install_element_ve(&show_mgr_cmd);
+
+ install_node(&mgr_node, config_write_mgr);
+ install_element(CONFIG_NODE, &cfg_mgr_cmd);
+ vty_install_default(MGR_NODE);
+
+ return 0;
+}
+
+int sysmobts_mgr_parse_config(const char *config_file)
+{
+ int rc;
+
+ rc = vty_read_config_file(config_file, NULL);
+ if (rc < 0) {
+ fprintf(stderr, "Failed to parse the config file: '%s'\n",
+ config_file);
+ return rc;
+ }
+
+ return 0;
+}