From: Álvaro Neira Ayuso anayuso@sysmocom.de
Added the vty support for configuring the parameter for using the OML report in manager when we have anomalous temperature.
Signed-off-by: Alvaro Neira Ayuso anayuso@sysmocom.de --- doc/examples/osmobts-mgr.cfg | 30 ++++ src/osmo-bts-sysmo/Makefile.am | 5 +- src/osmo-bts-sysmo/misc/sysmobts_mgr.c | 43 ++++- src/osmo-bts-sysmo/misc/sysmobts_mgr.h | 16 ++ src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c | 250 ++++++++++++++++++++++++++++ 5 files changed, 341 insertions(+), 3 deletions(-) create mode 100644 doc/examples/osmobts-mgr.cfg create mode 100644 src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c
diff --git a/doc/examples/osmobts-mgr.cfg b/doc/examples/osmobts-mgr.cfg new file mode 100644 index 0000000..3d99495 --- /dev/null +++ b/doc/examples/osmobts-mgr.cfg @@ -0,0 +1,30 @@ +! +! SysmoMgr (0.3.0.137-7576) configuration saved from vty +!! +! +log stderr + logging filter all 1 + logging color 1 + logging timestamp 0 + logging level all everything + logging level temp info + logging level fw info + logging level find info + logging level lglobal notice + logging level llapd notice + logging level linp notice + logging level lmux notice + logging level lmi notice + logging level lmib notice + logging level lsms notice +! +line vty + no login +! +config-mgr + temp-warn-board -30 50 + temp-sever-board -50 80 + temp-warn-pa -30 50 + temp-sever-pa -50 80 + pwr-action 1 1 0 + pwr-pa-transmiter 0 diff --git a/src/osmo-bts-sysmo/Makefile.am b/src/osmo-bts-sysmo/Makefile.am index 1c08af3..b4b7de7 100644 --- a/src/osmo-bts-sysmo/Makefile.am +++ b/src/osmo-bts-sysmo/Makefile.am @@ -22,8 +22,9 @@ l1fwd_proxy_LDADD = $(top_builddir)/src/common/libbts.a $(COMMON_LDADD)
sysmobts_mgr_SOURCES = \ misc/sysmobts_mgr.c misc/sysmobts_misc.c \ - misc/sysmobts_par.c misc/sysmobts_nl.c -sysmobts_mgr_LDADD = $(LIBOSMOCORE_LIBS) + misc/sysmobts_par.c misc/sysmobts_nl.c \ + misc/sysmobts_mgr_vty.c +sysmobts_mgr_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOVTY_LIBS)
sysmobts_util_SOURCES = misc/sysmobts_util.c misc/sysmobts_par.c sysmobts_util_LDADD = $(LIBOSMOCORE_LIBS) diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c index 525e526..4a879a3 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c @@ -54,6 +54,24 @@ static int state_connection = 0; void *tall_mgr_ctx; static struct sbts2050_config_info confinfo;
+static struct sysmobts_mgr_instance sysmobts_mgr_inst = { + .config_file = "osmobts-mgr.cfg", +}; + +const char *sysmomgr_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 struct vty_app_info vty_info = { + .name = "SysmoMgr", + .version = PACKAGE_VERSION, + .go_parent_cb = mgr_vty_go_parent, + .is_config_node = mgr_vty_is_config_node, +}; + /* every 6 hours means 365*4 = 1460 EEprom writes per year (max) */ #define TEMP_TIMER_SECS (6 * 3600)
@@ -202,13 +220,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; @@ -225,6 +244,9 @@ static int parse_options(int argc, char **argv) case 'D': daemonize = 1; break; + case 'c': + sysmobts_mgr_inst.config_file = optarg; + break; default: return -1; } @@ -428,6 +450,25 @@ int main(int argc, char **argv) if (rc < 0) exit(2);
+ vty_info.copyright = sysmomgr_copyright; + vty_init(&vty_info); + logging_vty_add_cmds(&mgr_log_info); + + sysmobts_mgr_vty_init(); + + rc = sysmobts_mgr_parse_config(sysmobts_mgr_inst.config_file, + &confinfo); + if (rc < 0) { + LOGP(DFIND, LOGL_FATAL, "Cannot parse config file\n"); + exit(2); + } + + rc = telnet_init(tall_msgb_ctx, NULL, 4247); + 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 ddb6774..4048854 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.h +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.h @@ -1,10 +1,26 @@ #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, +}; + +enum node_type mgr_vty_go_parent(struct vty *vty); +int mgr_vty_is_config_node(struct vty *vty, int node); +int sysmobts_mgr_vty_init(); +int sysmobts_mgr_parse_config(const char *config_file, + struct sbts2050_config_info *cfg); + +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 0000000..b462181 --- /dev/null +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c @@ -0,0 +1,250 @@ +/* (C) 2014 by Sysmocom + * + * 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 <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" + +static struct sbts2050_config_info *mgr_cfg = NULL; + +enum node_type mgr_vty_go_parent(struct vty *vty) +{ + switch (vty->node) { + case MGR_NODE: + vty->node = CONFIG_NODE; + break; + default: + vty->node = CONFIG_NODE; + } + return vty->node; +} + +int mgr_vty_is_config_node(struct vty *vty, int node) +{ + switch (node) { + case MGR_NODE: + return 1; + default: + return 0; + } +} + +#define MGR_STR "Configure the sysmobts-mgr\n" + +static struct cmd_node mgr_node = { + MGR_NODE, + "%s(config-mgr)# ", + 1, +}; + +DEFUN(cfg_mgr, cfg_mgr_cmd, + "config-mgr", + MGR_STR) +{ + vty->node = MGR_NODE; + return CMD_SUCCESS; +} + +DEFUN(show_mgr, show_mgr_cmd, "show mgr", + SHOW_STR "Display information about the mgr") +{ + vty_out(vty, " temp-warn-board Min:%d Max:%d%s", + mgr_cfg->temp_min_board_warn_limit, + mgr_cfg->temp_max_board_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-sever-board Min:%d Max:%d%s", + mgr_cfg->temp_min_board_sever_limit, + mgr_cfg->temp_max_board_sever_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-warn-pa Min:%d Max:%d%s", + mgr_cfg->temp_min_pa_warn_limit, + mgr_cfg->temp_max_pa_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-sever-pa Min:%d Max:%d%s", + mgr_cfg->temp_min_pa_sever_limit, + mgr_cfg->temp_max_pa_sever_limit, + VTY_NEWLINE); + + vty_out(vty, " pwr_action Master:%d Slave:%d PA:%d%s", + mgr_cfg->master_power_act, + mgr_cfg->slave_power_act, + mgr_cfg->pa_power_act, + VTY_NEWLINE); + + vty_out(vty, " pwr-pa-transmiter %d%s", + mgr_cfg->pa_power, + VTY_NEWLINE); + return CMD_SUCCESS; +} + +static int config_write_mgr(struct vty *vty) +{ + vty_out(vty, "config-mgr%s", VTY_NEWLINE); + + vty_out(vty, " temp-warn-board %d %d%s", + mgr_cfg->temp_min_board_warn_limit, + mgr_cfg->temp_max_board_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-sever-board %d %d%s", + mgr_cfg->temp_min_board_sever_limit, + mgr_cfg->temp_max_board_sever_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-warn-pa %d %d%s", + mgr_cfg->temp_min_pa_warn_limit, + mgr_cfg->temp_max_pa_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-sever-pa %d %d%s", + mgr_cfg->temp_min_pa_sever_limit, + mgr_cfg->temp_max_pa_sever_limit, + VTY_NEWLINE); + + vty_out(vty, " pwr-action %d %d %d%s", + mgr_cfg->master_power_act, + mgr_cfg->slave_power_act, + mgr_cfg->pa_power_act, + VTY_NEWLINE); + + vty_out(vty, " pwr-pa-transmiter %d%s", + mgr_cfg->pa_power, + VTY_NEWLINE); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_board_temp_warn, cfg_mgr_board_temp_warn_cmd, + "temp-warn-board <-255-255> <-255-255>", + MGR_STR "Temperature Range Value of the warning limit (Min and Max)" + "in the Board\n") +{ + mgr_cfg->temp_min_board_warn_limit = atoi(argv[0]); + mgr_cfg->temp_max_board_warn_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_board_temp_sever, cfg_mgr_board_temp_sever_cmd, + "temp-sever-board <-255-255> <-255-255>", + MGR_STR "Temperature Range Value of the several limit (Min and Max)" + "in the Board\n") +{ + mgr_cfg->temp_min_board_sever_limit = atoi(argv[0]); + mgr_cfg->temp_max_board_sever_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_temp_warn, cfg_mgr_pa_temp_warn_cmd, + "temp-warn-pa <-255-255> <-255-255>", + MGR_STR "Temperature Range Value of the warning limit (Min and Max)" + "in the PA\n") +{ + mgr_cfg->temp_min_pa_warn_limit = atoi(argv[0]); + mgr_cfg->temp_max_pa_warn_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_temp_sever, cfg_mgr_pa_temp_sever_cmd, + "temp-sever-pa <-255-255> <-255-255>", + MGR_STR "Temperature Range Value of the several limit (Min and Max)" + "in the PA\n") +{ + mgr_cfg->temp_min_pa_sever_limit = atoi(argv[0]); + mgr_cfg->temp_max_pa_sever_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pwr_action, cfg_mgr_pwr_action_cmd, + "pwr-action (0|1) (0|1) (0|1)", + MGR_STR "Action for switching on (1) | off (0)" + "the Master, Slave and PA\n") +{ + mgr_cfg->master_power_act = atoi(argv[0]); + mgr_cfg->slave_power_act = atoi(argv[1]); + mgr_cfg->pa_power_act = atoi(argv[2]); + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_baud_action, cfg_mgr_pa_baud_action_cmd, + "pwr-pa-transmiter <0-255>", + MGR_STR "Power baud transmition in the PA\n") +{ + mgr_cfg->pa_power = atoi(argv[0]);; + + return CMD_SUCCESS; +} + +int sysmobts_mgr_vty_init() + +{ + install_element_ve(&show_mgr_cmd); + + install_node(&mgr_node, config_write_mgr); + install_element(CONFIG_NODE, &cfg_mgr_cmd); + install_default(MGR_NODE); + + install_element(MGR_NODE, &cfg_mgr_board_temp_warn_cmd); + install_element(MGR_NODE, &cfg_mgr_board_temp_sever_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_temp_warn_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_temp_sever_cmd); + install_element(MGR_NODE, &cfg_mgr_pwr_action_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_baud_action_cmd); + + return 0; +} + +int sysmobts_mgr_parse_config(const char *config_file, + struct sbts2050_config_info *cfg) +{ + int rc; + + mgr_cfg = cfg; + + 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; +}
From: Álvaro Neira Ayuso anayuso@sysmocom.de
Added the vty support for configuring the parameter for using the OML report in manager when we have anomalous temperature.
Signed-off-by: Alvaro Neira Ayuso anayuso@sysmocom.de --- v2: Changed the functions for init the max_power_red value that we want to use in case of failure.
doc/examples/osmobts-mgr.cfg | 30 ++++ src/osmo-bts-sysmo/Makefile.am | 5 +- src/osmo-bts-sysmo/misc/sysmobts_mgr.c | 43 ++++- src/osmo-bts-sysmo/misc/sysmobts_mgr.h | 16 ++ src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c | 250 ++++++++++++++++++++++++++++ 5 files changed, 341 insertions(+), 3 deletions(-) create mode 100644 doc/examples/osmobts-mgr.cfg create mode 100644 src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c
diff --git a/doc/examples/osmobts-mgr.cfg b/doc/examples/osmobts-mgr.cfg new file mode 100644 index 0000000..f1c4e8e --- /dev/null +++ b/doc/examples/osmobts-mgr.cfg @@ -0,0 +1,30 @@ +! +! SysmoMgr (0.3.0.137-7576) configuration saved from vty +!! +! +log stderr + logging filter all 1 + logging color 1 + logging timestamp 0 + logging level all everything + logging level temp info + logging level fw info + logging level find info + logging level lglobal notice + logging level llapd notice + logging level linp notice + logging level lmux notice + logging level lmi notice + logging level lmib notice + logging level lsms notice +! +line vty + no login +! +config-mgr + temp-warn-board -30 50 + temp-sever-board -50 80 + temp-warn-pa -30 50 + temp-sever-pa -50 80 + pwr-action 1 1 0 + pwr-max-transmiter 32 diff --git a/src/osmo-bts-sysmo/Makefile.am b/src/osmo-bts-sysmo/Makefile.am index 1c08af3..b4b7de7 100644 --- a/src/osmo-bts-sysmo/Makefile.am +++ b/src/osmo-bts-sysmo/Makefile.am @@ -22,8 +22,9 @@ l1fwd_proxy_LDADD = $(top_builddir)/src/common/libbts.a $(COMMON_LDADD)
sysmobts_mgr_SOURCES = \ misc/sysmobts_mgr.c misc/sysmobts_misc.c \ - misc/sysmobts_par.c misc/sysmobts_nl.c -sysmobts_mgr_LDADD = $(LIBOSMOCORE_LIBS) + misc/sysmobts_par.c misc/sysmobts_nl.c \ + misc/sysmobts_mgr_vty.c +sysmobts_mgr_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOVTY_LIBS)
sysmobts_util_SOURCES = misc/sysmobts_util.c misc/sysmobts_par.c sysmobts_util_LDADD = $(LIBOSMOCORE_LIBS) diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c index b8813f0..0fb1221 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c @@ -57,6 +57,24 @@ static int fd_unix = -1; void *tall_mgr_ctx; static struct sbts2050_config_info confinfo;
+static struct sysmobts_mgr_instance sysmobts_mgr_inst = { + .config_file = "osmobts-mgr.cfg", +}; + +const char *sysmomgr_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 struct vty_app_info vty_info = { + .name = "SysmoMgr", + .version = PACKAGE_VERSION, + .go_parent_cb = mgr_vty_go_parent, + .is_config_node = mgr_vty_is_config_node, +}; + /* every 6 hours means 365*4 = 1460 EEprom writes per year (max) */ #define TEMP_TIMER_SECS (6 * 3600)
@@ -219,13 +237,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; @@ -242,6 +261,9 @@ static int parse_options(int argc, char **argv) case 'D': daemonize = 1; break; + case 'c': + sysmobts_mgr_inst.config_file = optarg; + break; default: return -1; } @@ -445,6 +467,25 @@ int main(int argc, char **argv) if (rc < 0) exit(2);
+ vty_info.copyright = sysmomgr_copyright; + vty_init(&vty_info); + logging_vty_add_cmds(&mgr_log_info); + + sysmobts_mgr_vty_init(); + + rc = sysmobts_mgr_parse_config(sysmobts_mgr_inst.config_file, + &confinfo); + if (rc < 0) { + LOGP(DFIND, LOGL_FATAL, "Cannot parse config file\n"); + exit(2); + } + + rc = telnet_init(tall_msgb_ctx, NULL, 4247); + 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 ddb6774..d89c46f 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.h +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.h @@ -1,10 +1,26 @@ #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, +}; + +enum node_type mgr_vty_go_parent(struct vty *vty); +int mgr_vty_is_config_node(struct vty *vty, int node); +int sysmobts_mgr_vty_init(void); +int sysmobts_mgr_parse_config(const char *config_file, + struct sbts2050_config_info *cfg); + +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 0000000..412c2bc --- /dev/null +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c @@ -0,0 +1,250 @@ +/* (C) 2014 by Sysmocom + * + * 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 <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" + +static struct sbts2050_config_info *mgr_cfg = NULL; + +enum node_type mgr_vty_go_parent(struct vty *vty) +{ + switch (vty->node) { + case MGR_NODE: + vty->node = CONFIG_NODE; + break; + default: + vty->node = CONFIG_NODE; + } + return vty->node; +} + +int mgr_vty_is_config_node(struct vty *vty, int node) +{ + switch (node) { + case MGR_NODE: + return 1; + default: + return 0; + } +} + +#define MGR_STR "Configure the sysmobts-mgr\n" + +static struct cmd_node mgr_node = { + MGR_NODE, + "%s(config-mgr)# ", + 1, +}; + +DEFUN(cfg_mgr, cfg_mgr_cmd, + "config-mgr", + MGR_STR) +{ + vty->node = MGR_NODE; + return CMD_SUCCESS; +} + +DEFUN(show_mgr, show_mgr_cmd, "show mgr", + SHOW_STR "Display information about the mgr") +{ + vty_out(vty, " temp-warn-board Min:%d Max:%d%s", + mgr_cfg->temp_min_board_warn_limit, + mgr_cfg->temp_max_board_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-sever-board Min:%d Max:%d%s", + mgr_cfg->temp_min_board_sever_limit, + mgr_cfg->temp_max_board_sever_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-warn-pa Min:%d Max:%d%s", + mgr_cfg->temp_min_pa_warn_limit, + mgr_cfg->temp_max_pa_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-sever-pa Min:%d Max:%d%s", + mgr_cfg->temp_min_pa_sever_limit, + mgr_cfg->temp_max_pa_sever_limit, + VTY_NEWLINE); + + vty_out(vty, " pwr_action Master:%d Slave:%d PA:%d%s", + mgr_cfg->master_power_act, + mgr_cfg->slave_power_act, + mgr_cfg->pa_power_act, + VTY_NEWLINE); + + vty_out(vty, " pwr-max-transmiter %d%s", + mgr_cfg->max_power_red, + VTY_NEWLINE); + return CMD_SUCCESS; +} + +static int config_write_mgr(struct vty *vty) +{ + vty_out(vty, "config-mgr%s", VTY_NEWLINE); + + vty_out(vty, " temp-warn-board %d %d%s", + mgr_cfg->temp_min_board_warn_limit, + mgr_cfg->temp_max_board_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-sever-board %d %d%s", + mgr_cfg->temp_min_board_sever_limit, + mgr_cfg->temp_max_board_sever_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-warn-pa %d %d%s", + mgr_cfg->temp_min_pa_warn_limit, + mgr_cfg->temp_max_pa_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-sever-pa %d %d%s", + mgr_cfg->temp_min_pa_sever_limit, + mgr_cfg->temp_max_pa_sever_limit, + VTY_NEWLINE); + + vty_out(vty, " pwr-action %d %d %d%s", + mgr_cfg->master_power_act, + mgr_cfg->slave_power_act, + mgr_cfg->pa_power_act, + VTY_NEWLINE); + + vty_out(vty, " pwr-max-transmiter %d%s", + mgr_cfg->max_power_red, + VTY_NEWLINE); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_board_temp_warn, cfg_mgr_board_temp_warn_cmd, + "temp-warn-board <-255-255> <-255-255>", + MGR_STR "Temperature Range Value of the warning limit (Min and Max)" + "in the Board\n") +{ + mgr_cfg->temp_min_board_warn_limit = atoi(argv[0]); + mgr_cfg->temp_max_board_warn_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_board_temp_sever, cfg_mgr_board_temp_sever_cmd, + "temp-sever-board <-255-255> <-255-255>", + MGR_STR "Temperature Range Value of the several limit (Min and Max)" + "in the Board\n") +{ + mgr_cfg->temp_min_board_sever_limit = atoi(argv[0]); + mgr_cfg->temp_max_board_sever_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_temp_warn, cfg_mgr_pa_temp_warn_cmd, + "temp-warn-pa <-255-255> <-255-255>", + MGR_STR "Temperature Range Value of the warning limit (Min and Max)" + "in the PA\n") +{ + mgr_cfg->temp_min_pa_warn_limit = atoi(argv[0]); + mgr_cfg->temp_max_pa_warn_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_temp_sever, cfg_mgr_pa_temp_sever_cmd, + "temp-sever-pa <-255-255> <-255-255>", + MGR_STR "Temperature Range Value of the several limit (Min and Max)" + "in the PA\n") +{ + mgr_cfg->temp_min_pa_sever_limit = atoi(argv[0]); + mgr_cfg->temp_max_pa_sever_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pwr_action, cfg_mgr_pwr_action_cmd, + "pwr-action (0|1) (0|1) (0|1)", + MGR_STR "Action for switching on (1) | off (0)" + "the Master, Slave and PA\n") +{ + mgr_cfg->master_power_act = atoi(argv[0]); + mgr_cfg->slave_power_act = atoi(argv[1]); + mgr_cfg->pa_power_act = atoi(argv[2]); + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_baud_action, cfg_mgr_pa_baud_action_cmd, + "pwr-max-transmiter <0-255>", + MGR_STR "Power baud transmition in the PA\n") +{ + mgr_cfg->max_power_red = atoi(argv[0]); + + return CMD_SUCCESS; +} + +int sysmobts_mgr_vty_init(void) + +{ + install_element_ve(&show_mgr_cmd); + + install_node(&mgr_node, config_write_mgr); + install_element(CONFIG_NODE, &cfg_mgr_cmd); + install_default(MGR_NODE); + + install_element(MGR_NODE, &cfg_mgr_board_temp_warn_cmd); + install_element(MGR_NODE, &cfg_mgr_board_temp_sever_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_temp_warn_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_temp_sever_cmd); + install_element(MGR_NODE, &cfg_mgr_pwr_action_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_baud_action_cmd); + + return 0; +} + +int sysmobts_mgr_parse_config(const char *config_file, + struct sbts2050_config_info *cfg) +{ + int rc; + + mgr_cfg = cfg; + + 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; +}
On Tue, Apr 08, 2014 at 02:35:26PM +0200, Alvaro Neira Ayuso wrote:
From: Álvaro Neira Ayuso anayuso@sysmocom.de
Added the vty support for configuring the parameter for using the OML report in manager when we have anomalous temperature.
Signed-off-by: Alvaro Neira Ayuso anayuso@sysmocom.de
v2: Changed the functions for init the max_power_red value that we want to use in case of failure.
doc/examples/osmobts-mgr.cfg | 30 ++++ src/osmo-bts-sysmo/Makefile.am | 5 +- src/osmo-bts-sysmo/misc/sysmobts_mgr.c | 43 ++++- src/osmo-bts-sysmo/misc/sysmobts_mgr.h | 16 ++ src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c | 250 ++++++++++++++++++++++++++++ 5 files changed, 341 insertions(+), 3 deletions(-) create mode 100644 doc/examples/osmobts-mgr.cfg create mode 100644 src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c
diff --git a/doc/examples/osmobts-mgr.cfg b/doc/examples/osmobts-mgr.cfg new file mode 100644 index 0000000..f1c4e8e --- /dev/null +++ b/doc/examples/osmobts-mgr.cfg @@ -0,0 +1,30 @@ +! +! SysmoMgr (0.3.0.137-7576) configuration saved from vty +!! +! +log stderr
- logging filter all 1
- logging color 1
- logging timestamp 0
- logging level all everything
- logging level temp info
- logging level fw info
- logging level find info
- logging level lglobal notice
- logging level llapd notice
- logging level linp notice
- logging level lmux notice
- logging level lmi notice
- logging level lmib notice
- logging level lsms notice
+! +line vty
- no login
+! +config-mgr
- temp-warn-board -30 50
- temp-sever-board -50 80
- temp-warn-pa -30 50
- temp-sever-pa -50 80
- pwr-action 1 1 0
- pwr-max-transmiter 32
diff --git a/src/osmo-bts-sysmo/Makefile.am b/src/osmo-bts-sysmo/Makefile.am index 1c08af3..b4b7de7 100644 --- a/src/osmo-bts-sysmo/Makefile.am +++ b/src/osmo-bts-sysmo/Makefile.am @@ -22,8 +22,9 @@ l1fwd_proxy_LDADD = $(top_builddir)/src/common/libbts.a $(COMMON_LDADD)
sysmobts_mgr_SOURCES = \ misc/sysmobts_mgr.c misc/sysmobts_misc.c \
misc/sysmobts_par.c misc/sysmobts_nl.c-sysmobts_mgr_LDADD = $(LIBOSMOCORE_LIBS)
misc/sysmobts_par.c misc/sysmobts_nl.c \misc/sysmobts_mgr_vty.c+sysmobts_mgr_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOVTY_LIBS)
sysmobts_util_SOURCES = misc/sysmobts_util.c misc/sysmobts_par.c sysmobts_util_LDADD = $(LIBOSMOCORE_LIBS) diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c index b8813f0..0fb1221 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c @@ -57,6 +57,24 @@ static int fd_unix = -1; void *tall_mgr_ctx; static struct sbts2050_config_info confinfo;
+static struct sysmobts_mgr_instance sysmobts_mgr_inst = {
- .config_file = "osmobts-mgr.cfg",
+};
+const char *sysmomgr_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 struct vty_app_info vty_info = {
- .name = "SysmoMgr",
- .version = PACKAGE_VERSION,
- .go_parent_cb = mgr_vty_go_parent,
- .is_config_node = mgr_vty_is_config_node,
+};
/* every 6 hours means 365*4 = 1460 EEprom writes per year (max) */ #define TEMP_TIMER_SECS (6 * 3600)
@@ -219,13 +237,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;
@@ -242,6 +261,9 @@ static int parse_options(int argc, char **argv) case 'D': daemonize = 1; break;
case 'c':sysmobts_mgr_inst.config_file = optarg; default: return -1; }break;@@ -445,6 +467,25 @@ int main(int argc, char **argv) if (rc < 0) exit(2);
- vty_info.copyright = sysmomgr_copyright;
- vty_init(&vty_info);
- logging_vty_add_cmds(&mgr_log_info);
- sysmobts_mgr_vty_init();
- rc = sysmobts_mgr_parse_config(sysmobts_mgr_inst.config_file,
&confinfo);- if (rc < 0) {
LOGP(DFIND, LOGL_FATAL, "Cannot parse config file\n");exit(2);- }
- rc = telnet_init(tall_msgb_ctx, NULL, 4247);
- 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 ddb6774..d89c46f 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.h +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.h @@ -1,10 +1,26 @@ #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,
+};
+enum node_type mgr_vty_go_parent(struct vty *vty); +int mgr_vty_is_config_node(struct vty *vty, int node); +int sysmobts_mgr_vty_init(void); +int sysmobts_mgr_parse_config(const char *config_file,
struct sbts2050_config_info *cfg);+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 0000000..412c2bc --- /dev/null +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c @@ -0,0 +1,250 @@ +/* (C) 2014 by Sysmocom
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 <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"
+static struct sbts2050_config_info *mgr_cfg = NULL;
+enum node_type mgr_vty_go_parent(struct vty *vty) +{
- switch (vty->node) {
- case MGR_NODE:
vty->node = CONFIG_NODE;break;- default:
vty->node = CONFIG_NODE;- }
- return vty->node;
+}
+int mgr_vty_is_config_node(struct vty *vty, int node) +{
- switch (node) {
- case MGR_NODE:
return 1;- default:
return 0;- }
+}
+#define MGR_STR "Configure the sysmobts-mgr\n"
+static struct cmd_node mgr_node = {
- MGR_NODE,
- "%s(config-mgr)# ",
- 1,
+};
+DEFUN(cfg_mgr, cfg_mgr_cmd,
- "config-mgr",
- MGR_STR)
+{
- vty->node = MGR_NODE;
- return CMD_SUCCESS;
+}
+DEFUN(show_mgr, show_mgr_cmd, "show mgr",
SHOW_STR "Display information about the mgr")+{
- vty_out(vty, " temp-warn-board Min:%d Max:%d%s",
mgr_cfg->temp_min_board_warn_limit,mgr_cfg->temp_max_board_warn_limit,VTY_NEWLINE);
Coding style nitpick:
vty_out(vty, ... mgr_cfg->temp_min_board_warn_limit,
Apart from those nitpicks, this looks good to me.
On Wed, Apr 09, 2014 at 10:37:10AM +0200, Pablo Neira Ayuso wrote:
- rc = telnet_init(tall_msgb_ctx, NULL, 4247);
This port number is already used by osmocomBB. Please have a look at: http://openbsc.osmocom.org/trac/wiki/PortNumbers and then claim a number from it.
From: Álvaro Neira Ayuso anayuso@sysmocom.de
Added the vty support for configuring the parameter for using the OML report in manager when we have anomalous temperature.
Signed-off-by: Alvaro Neira Ayuso anayuso@sysmocom.de --- [changes in v3] * Fixed some coding style errors * Changed the port of the sysmo-mgr vty because the previous was already being used
doc/examples/osmobts-mgr.cfg | 30 ++++ src/osmo-bts-sysmo/Makefile.am | 5 +- src/osmo-bts-sysmo/misc/sysmobts_mgr.c | 43 ++++- src/osmo-bts-sysmo/misc/sysmobts_mgr.h | 16 ++ src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c | 250 ++++++++++++++++++++++++++++ 5 files changed, 341 insertions(+), 3 deletions(-) create mode 100644 doc/examples/osmobts-mgr.cfg create mode 100644 src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c
diff --git a/doc/examples/osmobts-mgr.cfg b/doc/examples/osmobts-mgr.cfg new file mode 100644 index 0000000..f1c4e8e --- /dev/null +++ b/doc/examples/osmobts-mgr.cfg @@ -0,0 +1,30 @@ +! +! SysmoMgr (0.3.0.137-7576) configuration saved from vty +!! +! +log stderr + logging filter all 1 + logging color 1 + logging timestamp 0 + logging level all everything + logging level temp info + logging level fw info + logging level find info + logging level lglobal notice + logging level llapd notice + logging level linp notice + logging level lmux notice + logging level lmi notice + logging level lmib notice + logging level lsms notice +! +line vty + no login +! +config-mgr + temp-warn-board -30 50 + temp-sever-board -50 80 + temp-warn-pa -30 50 + temp-sever-pa -50 80 + pwr-action 1 1 0 + pwr-max-transmiter 32 diff --git a/src/osmo-bts-sysmo/Makefile.am b/src/osmo-bts-sysmo/Makefile.am index 1c08af3..b4b7de7 100644 --- a/src/osmo-bts-sysmo/Makefile.am +++ b/src/osmo-bts-sysmo/Makefile.am @@ -22,8 +22,9 @@ l1fwd_proxy_LDADD = $(top_builddir)/src/common/libbts.a $(COMMON_LDADD)
sysmobts_mgr_SOURCES = \ misc/sysmobts_mgr.c misc/sysmobts_misc.c \ - misc/sysmobts_par.c misc/sysmobts_nl.c -sysmobts_mgr_LDADD = $(LIBOSMOCORE_LIBS) + misc/sysmobts_par.c misc/sysmobts_nl.c \ + misc/sysmobts_mgr_vty.c +sysmobts_mgr_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOVTY_LIBS)
sysmobts_util_SOURCES = misc/sysmobts_util.c misc/sysmobts_par.c sysmobts_util_LDADD = $(LIBOSMOCORE_LIBS) diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c index 7a50bdc..2635c5f 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c @@ -57,6 +57,24 @@ static int fd_unix = -1; void *tall_mgr_ctx; static struct sbts2050_config_info confinfo;
+static struct sysmobts_mgr_instance sysmobts_mgr_inst = { + .config_file = "osmobts-mgr.cfg", +}; + +const char *sysmomgr_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 struct vty_app_info vty_info = { + .name = "SysmoMgr", + .version = PACKAGE_VERSION, + .go_parent_cb = mgr_vty_go_parent, + .is_config_node = mgr_vty_is_config_node, +}; + /* every 6 hours means 365*4 = 1460 EEprom writes per year (max) */ #define TEMP_TIMER_SECS (6 * 3600)
@@ -217,13 +235,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; @@ -240,6 +259,9 @@ static int parse_options(int argc, char **argv) case 'D': daemonize = 1; break; + case 'c': + sysmobts_mgr_inst.config_file = optarg; + break; default: return -1; } @@ -443,6 +465,25 @@ int main(int argc, char **argv) if (rc < 0) exit(2);
+ vty_info.copyright = sysmomgr_copyright; + vty_init(&vty_info); + logging_vty_add_cmds(&mgr_log_info); + + sysmobts_mgr_vty_init(); + + rc = sysmobts_mgr_parse_config(sysmobts_mgr_inst.config_file, + &confinfo); + if (rc < 0) { + LOGP(DFIND, LOGL_FATAL, "Cannot parse config file\n"); + exit(2); + } + + 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 ddb6774..d89c46f 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.h +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.h @@ -1,10 +1,26 @@ #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, +}; + +enum node_type mgr_vty_go_parent(struct vty *vty); +int mgr_vty_is_config_node(struct vty *vty, int node); +int sysmobts_mgr_vty_init(void); +int sysmobts_mgr_parse_config(const char *config_file, + struct sbts2050_config_info *cfg); + +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 0000000..33c3fe6 --- /dev/null +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c @@ -0,0 +1,250 @@ +/* (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 <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" + +static struct sbts2050_config_info *mgr_cfg = NULL; + +enum node_type mgr_vty_go_parent(struct vty *vty) +{ + switch (vty->node) { + case MGR_NODE: + vty->node = CONFIG_NODE; + break; + default: + vty->node = CONFIG_NODE; + } + return vty->node; +} + +int mgr_vty_is_config_node(struct vty *vty, int node) +{ + switch (node) { + case MGR_NODE: + return 1; + default: + return 0; + } +} + +#define MGR_STR "Configure the sysmobts-mgr\n" + +static struct cmd_node mgr_node = { + MGR_NODE, + "%s(config-mgr)# ", + 1, +}; + +DEFUN(cfg_mgr, cfg_mgr_cmd, + "config-mgr", + MGR_STR) +{ + vty->node = MGR_NODE; + return CMD_SUCCESS; +} + +DEFUN(show_mgr, show_mgr_cmd, "show mgr", + SHOW_STR "Display information about the mgr") +{ + vty_out(vty, " temp-warn-board Min:%d Max:%d%s", + mgr_cfg->temp_min_board_warn_limit, + mgr_cfg->temp_max_board_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-sever-board Min:%d Max:%d%s", + mgr_cfg->temp_min_board_sever_limit, + mgr_cfg->temp_max_board_sever_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-warn-pa Min:%d Max:%d%s", + mgr_cfg->temp_min_pa_warn_limit, + mgr_cfg->temp_max_pa_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-sever-pa Min:%d Max:%d%s", + mgr_cfg->temp_min_pa_sever_limit, + mgr_cfg->temp_max_pa_sever_limit, + VTY_NEWLINE); + + vty_out(vty, " pwr_action Master:%d Slave:%d PA:%d%s", + mgr_cfg->master_power_act, + mgr_cfg->slave_power_act, + mgr_cfg->pa_power_act, + VTY_NEWLINE); + + vty_out(vty, " pwr-max-transmiter %d%s", + mgr_cfg->max_power_red, + VTY_NEWLINE); + return CMD_SUCCESS; +} + +static int config_write_mgr(struct vty *vty) +{ + vty_out(vty, "config-mgr%s", VTY_NEWLINE); + + vty_out(vty, " temp-warn-board %d %d%s", + mgr_cfg->temp_min_board_warn_limit, + mgr_cfg->temp_max_board_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-sever-board %d %d%s", + mgr_cfg->temp_min_board_sever_limit, + mgr_cfg->temp_max_board_sever_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-warn-pa %d %d%s", + mgr_cfg->temp_min_pa_warn_limit, + mgr_cfg->temp_max_pa_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-sever-pa %d %d%s", + mgr_cfg->temp_min_pa_sever_limit, + mgr_cfg->temp_max_pa_sever_limit, + VTY_NEWLINE); + + vty_out(vty, " pwr-action %d %d %d%s", + mgr_cfg->master_power_act, + mgr_cfg->slave_power_act, + mgr_cfg->pa_power_act, + VTY_NEWLINE); + + vty_out(vty, " pwr-max-transmiter %d%s", + mgr_cfg->max_power_red, + VTY_NEWLINE); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_board_temp_warn, cfg_mgr_board_temp_warn_cmd, + "temp-warn-board <-255-255> <-255-255>", + MGR_STR "Temperature Range Value of the warning limit (Min and Max)" + "in the Board\n") +{ + mgr_cfg->temp_min_board_warn_limit = atoi(argv[0]); + mgr_cfg->temp_max_board_warn_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_board_temp_sever, cfg_mgr_board_temp_sever_cmd, + "temp-sever-board <-255-255> <-255-255>", + MGR_STR "Temperature Range Value of the several limit (Min and Max)" + "in the Board\n") +{ + mgr_cfg->temp_min_board_sever_limit = atoi(argv[0]); + mgr_cfg->temp_max_board_sever_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_temp_warn, cfg_mgr_pa_temp_warn_cmd, + "temp-warn-pa <-255-255> <-255-255>", + MGR_STR "Temperature Range Value of the warning limit (Min and Max)" + "in the PA\n") +{ + mgr_cfg->temp_min_pa_warn_limit = atoi(argv[0]); + mgr_cfg->temp_max_pa_warn_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_temp_sever, cfg_mgr_pa_temp_sever_cmd, + "temp-sever-pa <-255-255> <-255-255>", + MGR_STR "Temperature Range Value of the several limit (Min and Max)" + "in the PA\n") +{ + mgr_cfg->temp_min_pa_sever_limit = atoi(argv[0]); + mgr_cfg->temp_max_pa_sever_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pwr_action, cfg_mgr_pwr_action_cmd, + "pwr-action (0|1) (0|1) (0|1)", + MGR_STR "Action for switching on (1) | off (0)" + "the Master, Slave and PA\n") +{ + mgr_cfg->master_power_act = atoi(argv[0]); + mgr_cfg->slave_power_act = atoi(argv[1]); + mgr_cfg->pa_power_act = atoi(argv[2]); + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_baud_action, cfg_mgr_pa_baud_action_cmd, + "pwr-max-transmiter <0-255>", + MGR_STR "Power baud transmition in the PA\n") +{ + mgr_cfg->max_power_red = atoi(argv[0]); + + return CMD_SUCCESS; +} + +int sysmobts_mgr_vty_init(void) + +{ + install_element_ve(&show_mgr_cmd); + + install_node(&mgr_node, config_write_mgr); + install_element(CONFIG_NODE, &cfg_mgr_cmd); + install_default(MGR_NODE); + + install_element(MGR_NODE, &cfg_mgr_board_temp_warn_cmd); + install_element(MGR_NODE, &cfg_mgr_board_temp_sever_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_temp_warn_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_temp_sever_cmd); + install_element(MGR_NODE, &cfg_mgr_pwr_action_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_baud_action_cmd); + + return 0; +} + +int sysmobts_mgr_parse_config(const char *config_file, + struct sbts2050_config_info *cfg) +{ + int rc; + + mgr_cfg = cfg; + + 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; +}
On Thu, Apr 10, 2014 at 12:25:37PM +0200, Alvaro Neira Ayuso wrote:
From: Álvaro Neira Ayuso anayuso@sysmocom.de
Added the vty support for configuring the parameter for using the OML report in manager when we have anomalous temperature.
Signed-off-by: Alvaro Neira Ayuso anayuso@sysmocom.de
[changes in v3]
- Fixed some coding style errors
- Changed the port of the sysmo-mgr vty because the previous was already being used
doc/examples/osmobts-mgr.cfg | 30 ++++ src/osmo-bts-sysmo/Makefile.am | 5 +- src/osmo-bts-sysmo/misc/sysmobts_mgr.c | 43 ++++- src/osmo-bts-sysmo/misc/sysmobts_mgr.h | 16 ++ src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c | 250 ++++++++++++++++++++++++++++ 5 files changed, 341 insertions(+), 3 deletions(-) create mode 100644 doc/examples/osmobts-mgr.cfg create mode 100644 src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c
diff --git a/doc/examples/osmobts-mgr.cfg b/doc/examples/osmobts-mgr.cfg new file mode 100644 index 0000000..f1c4e8e --- /dev/null +++ b/doc/examples/osmobts-mgr.cfg @@ -0,0 +1,30 @@ +! +! SysmoMgr (0.3.0.137-7576) configuration saved from vty +!! +! +log stderr
- logging filter all 1
- logging color 1
- logging timestamp 0
- logging level all everything
- logging level temp info
- logging level fw info
- logging level find info
- logging level lglobal notice
- logging level llapd notice
- logging level linp notice
- logging level lmux notice
- logging level lmi notice
- logging level lmib notice
- logging level lsms notice
+! +line vty
- no login
+! +config-mgr
- temp-warn-board -30 50
- temp-sever-board -50 80
- temp-warn-pa -30 50
- temp-sever-pa -50 80
- pwr-action 1 1 0
- pwr-max-transmiter 32
diff --git a/src/osmo-bts-sysmo/Makefile.am b/src/osmo-bts-sysmo/Makefile.am index 1c08af3..b4b7de7 100644 --- a/src/osmo-bts-sysmo/Makefile.am +++ b/src/osmo-bts-sysmo/Makefile.am @@ -22,8 +22,9 @@ l1fwd_proxy_LDADD = $(top_builddir)/src/common/libbts.a $(COMMON_LDADD)
sysmobts_mgr_SOURCES = \ misc/sysmobts_mgr.c misc/sysmobts_misc.c \
misc/sysmobts_par.c misc/sysmobts_nl.c-sysmobts_mgr_LDADD = $(LIBOSMOCORE_LIBS)
misc/sysmobts_par.c misc/sysmobts_nl.c \misc/sysmobts_mgr_vty.c+sysmobts_mgr_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOVTY_LIBS)
sysmobts_util_SOURCES = misc/sysmobts_util.c misc/sysmobts_par.c sysmobts_util_LDADD = $(LIBOSMOCORE_LIBS) diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c index 7a50bdc..2635c5f 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c @@ -57,6 +57,24 @@ static int fd_unix = -1; void *tall_mgr_ctx; static struct sbts2050_config_info confinfo;
+static struct sysmobts_mgr_instance sysmobts_mgr_inst = {
- .config_file = "osmobts-mgr.cfg",
+};
+const char *sysmomgr_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 struct vty_app_info vty_info = {
- .name = "SysmoMgr",
- .version = PACKAGE_VERSION,
- .go_parent_cb = mgr_vty_go_parent,
- .is_config_node = mgr_vty_is_config_node,
+};
/* every 6 hours means 365*4 = 1460 EEprom writes per year (max) */ #define TEMP_TIMER_SECS (6 * 3600)
@@ -217,13 +235,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;
@@ -240,6 +259,9 @@ static int parse_options(int argc, char **argv) case 'D': daemonize = 1; break;
case 'c':sysmobts_mgr_inst.config_file = optarg; default: return -1; }break;@@ -443,6 +465,25 @@ int main(int argc, char **argv) if (rc < 0) exit(2);
- vty_info.copyright = sysmomgr_copyright;
- vty_init(&vty_info);
- logging_vty_add_cmds(&mgr_log_info);
- sysmobts_mgr_vty_init();
- rc = sysmobts_mgr_parse_config(sysmobts_mgr_inst.config_file,
&confinfo);- if (rc < 0) {
LOGP(DFIND, LOGL_FATAL, "Cannot parse config file\n");exit(2);
IIRC these error values indicate from which point we have failed. So this should be exit(3).
From: Álvaro Neira Ayuso anayuso@sysmocom.de
Added the vty support for configuring the parameter for using the OML report in manager when we have anomalous temperature.
Signed-off-by: Alvaro Neira Ayuso anayuso@sysmocom.de --- [changes in v4] * Changed the exit value for having consistency with the exit values that we have used in the same failure cases but in other programs.
doc/examples/osmobts-mgr.cfg | 30 ++++ src/osmo-bts-sysmo/Makefile.am | 5 +- src/osmo-bts-sysmo/misc/sysmobts_mgr.c | 43 ++++- src/osmo-bts-sysmo/misc/sysmobts_mgr.h | 16 ++ src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c | 250 ++++++++++++++++++++++++++++ 5 files changed, 341 insertions(+), 3 deletions(-) create mode 100644 doc/examples/osmobts-mgr.cfg create mode 100644 src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c
diff --git a/doc/examples/osmobts-mgr.cfg b/doc/examples/osmobts-mgr.cfg new file mode 100644 index 0000000..f1c4e8e --- /dev/null +++ b/doc/examples/osmobts-mgr.cfg @@ -0,0 +1,30 @@ +! +! SysmoMgr (0.3.0.137-7576) configuration saved from vty +!! +! +log stderr + logging filter all 1 + logging color 1 + logging timestamp 0 + logging level all everything + logging level temp info + logging level fw info + logging level find info + logging level lglobal notice + logging level llapd notice + logging level linp notice + logging level lmux notice + logging level lmi notice + logging level lmib notice + logging level lsms notice +! +line vty + no login +! +config-mgr + temp-warn-board -30 50 + temp-sever-board -50 80 + temp-warn-pa -30 50 + temp-sever-pa -50 80 + pwr-action 1 1 0 + pwr-max-transmiter 32 diff --git a/src/osmo-bts-sysmo/Makefile.am b/src/osmo-bts-sysmo/Makefile.am index 1c08af3..b4b7de7 100644 --- a/src/osmo-bts-sysmo/Makefile.am +++ b/src/osmo-bts-sysmo/Makefile.am @@ -22,8 +22,9 @@ l1fwd_proxy_LDADD = $(top_builddir)/src/common/libbts.a $(COMMON_LDADD)
sysmobts_mgr_SOURCES = \ misc/sysmobts_mgr.c misc/sysmobts_misc.c \ - misc/sysmobts_par.c misc/sysmobts_nl.c -sysmobts_mgr_LDADD = $(LIBOSMOCORE_LIBS) + misc/sysmobts_par.c misc/sysmobts_nl.c \ + misc/sysmobts_mgr_vty.c +sysmobts_mgr_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOVTY_LIBS)
sysmobts_util_SOURCES = misc/sysmobts_util.c misc/sysmobts_par.c sysmobts_util_LDADD = $(LIBOSMOCORE_LIBS) diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c index 51fa539..2f169e0 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c @@ -52,6 +52,24 @@ static int fd_unix = -1; void *tall_mgr_ctx; static struct sbts2050_config_info confinfo;
+static struct sysmobts_mgr_instance sysmobts_mgr_inst = { + .config_file = "osmobts-mgr.cfg", +}; + +const char *sysmomgr_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 struct vty_app_info vty_info = { + .name = "SysmoMgr", + .version = PACKAGE_VERSION, + .go_parent_cb = mgr_vty_go_parent, + .is_config_node = mgr_vty_is_config_node, +}; + /* every 6 hours means 365*4 = 1460 EEprom writes per year (max) */ #define TEMP_TIMER_SECS (6 * 3600)
@@ -211,13 +229,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; @@ -234,6 +253,9 @@ static int parse_options(int argc, char **argv) case 'D': daemonize = 1; break; + case 'c': + sysmobts_mgr_inst.config_file = optarg; + break; default: return -1; } @@ -437,6 +459,25 @@ int main(int argc, char **argv) if (rc < 0) exit(2);
+ vty_info.copyright = sysmomgr_copyright; + vty_init(&vty_info); + logging_vty_add_cmds(&mgr_log_info); + + sysmobts_mgr_vty_init(); + + rc = sysmobts_mgr_parse_config(sysmobts_mgr_inst.config_file, + &confinfo); + 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 87668e0..f9e5c09 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.h +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.h @@ -1,6 +1,9 @@ #ifndef _SYSMOBTS_MGR_H #define _SYSMOBTS_MGR_H
+#include <osmocom/vty/vty.h> +#include <osmocom/vty/command.h> + enum { DTEMP, DFW, @@ -12,4 +15,17 @@ enum { SYSMO_MGR_CONNECTED, };
+enum mgr_vty_node { + MGR_NODE = _LAST_OSMOVTY_NODE + 1, +}; + +enum node_type mgr_vty_go_parent(struct vty *vty); +int mgr_vty_is_config_node(struct vty *vty, int node); +int sysmobts_mgr_vty_init(void); +int sysmobts_mgr_parse_config(const char *config_file, + struct sbts2050_config_info *cfg); + +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 0000000..33c3fe6 --- /dev/null +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c @@ -0,0 +1,250 @@ +/* (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 <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" + +static struct sbts2050_config_info *mgr_cfg = NULL; + +enum node_type mgr_vty_go_parent(struct vty *vty) +{ + switch (vty->node) { + case MGR_NODE: + vty->node = CONFIG_NODE; + break; + default: + vty->node = CONFIG_NODE; + } + return vty->node; +} + +int mgr_vty_is_config_node(struct vty *vty, int node) +{ + switch (node) { + case MGR_NODE: + return 1; + default: + return 0; + } +} + +#define MGR_STR "Configure the sysmobts-mgr\n" + +static struct cmd_node mgr_node = { + MGR_NODE, + "%s(config-mgr)# ", + 1, +}; + +DEFUN(cfg_mgr, cfg_mgr_cmd, + "config-mgr", + MGR_STR) +{ + vty->node = MGR_NODE; + return CMD_SUCCESS; +} + +DEFUN(show_mgr, show_mgr_cmd, "show mgr", + SHOW_STR "Display information about the mgr") +{ + vty_out(vty, " temp-warn-board Min:%d Max:%d%s", + mgr_cfg->temp_min_board_warn_limit, + mgr_cfg->temp_max_board_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-sever-board Min:%d Max:%d%s", + mgr_cfg->temp_min_board_sever_limit, + mgr_cfg->temp_max_board_sever_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-warn-pa Min:%d Max:%d%s", + mgr_cfg->temp_min_pa_warn_limit, + mgr_cfg->temp_max_pa_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-sever-pa Min:%d Max:%d%s", + mgr_cfg->temp_min_pa_sever_limit, + mgr_cfg->temp_max_pa_sever_limit, + VTY_NEWLINE); + + vty_out(vty, " pwr_action Master:%d Slave:%d PA:%d%s", + mgr_cfg->master_power_act, + mgr_cfg->slave_power_act, + mgr_cfg->pa_power_act, + VTY_NEWLINE); + + vty_out(vty, " pwr-max-transmiter %d%s", + mgr_cfg->max_power_red, + VTY_NEWLINE); + return CMD_SUCCESS; +} + +static int config_write_mgr(struct vty *vty) +{ + vty_out(vty, "config-mgr%s", VTY_NEWLINE); + + vty_out(vty, " temp-warn-board %d %d%s", + mgr_cfg->temp_min_board_warn_limit, + mgr_cfg->temp_max_board_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-sever-board %d %d%s", + mgr_cfg->temp_min_board_sever_limit, + mgr_cfg->temp_max_board_sever_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-warn-pa %d %d%s", + mgr_cfg->temp_min_pa_warn_limit, + mgr_cfg->temp_max_pa_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-sever-pa %d %d%s", + mgr_cfg->temp_min_pa_sever_limit, + mgr_cfg->temp_max_pa_sever_limit, + VTY_NEWLINE); + + vty_out(vty, " pwr-action %d %d %d%s", + mgr_cfg->master_power_act, + mgr_cfg->slave_power_act, + mgr_cfg->pa_power_act, + VTY_NEWLINE); + + vty_out(vty, " pwr-max-transmiter %d%s", + mgr_cfg->max_power_red, + VTY_NEWLINE); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_board_temp_warn, cfg_mgr_board_temp_warn_cmd, + "temp-warn-board <-255-255> <-255-255>", + MGR_STR "Temperature Range Value of the warning limit (Min and Max)" + "in the Board\n") +{ + mgr_cfg->temp_min_board_warn_limit = atoi(argv[0]); + mgr_cfg->temp_max_board_warn_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_board_temp_sever, cfg_mgr_board_temp_sever_cmd, + "temp-sever-board <-255-255> <-255-255>", + MGR_STR "Temperature Range Value of the several limit (Min and Max)" + "in the Board\n") +{ + mgr_cfg->temp_min_board_sever_limit = atoi(argv[0]); + mgr_cfg->temp_max_board_sever_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_temp_warn, cfg_mgr_pa_temp_warn_cmd, + "temp-warn-pa <-255-255> <-255-255>", + MGR_STR "Temperature Range Value of the warning limit (Min and Max)" + "in the PA\n") +{ + mgr_cfg->temp_min_pa_warn_limit = atoi(argv[0]); + mgr_cfg->temp_max_pa_warn_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_temp_sever, cfg_mgr_pa_temp_sever_cmd, + "temp-sever-pa <-255-255> <-255-255>", + MGR_STR "Temperature Range Value of the several limit (Min and Max)" + "in the PA\n") +{ + mgr_cfg->temp_min_pa_sever_limit = atoi(argv[0]); + mgr_cfg->temp_max_pa_sever_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pwr_action, cfg_mgr_pwr_action_cmd, + "pwr-action (0|1) (0|1) (0|1)", + MGR_STR "Action for switching on (1) | off (0)" + "the Master, Slave and PA\n") +{ + mgr_cfg->master_power_act = atoi(argv[0]); + mgr_cfg->slave_power_act = atoi(argv[1]); + mgr_cfg->pa_power_act = atoi(argv[2]); + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_baud_action, cfg_mgr_pa_baud_action_cmd, + "pwr-max-transmiter <0-255>", + MGR_STR "Power baud transmition in the PA\n") +{ + mgr_cfg->max_power_red = atoi(argv[0]); + + return CMD_SUCCESS; +} + +int sysmobts_mgr_vty_init(void) + +{ + install_element_ve(&show_mgr_cmd); + + install_node(&mgr_node, config_write_mgr); + install_element(CONFIG_NODE, &cfg_mgr_cmd); + install_default(MGR_NODE); + + install_element(MGR_NODE, &cfg_mgr_board_temp_warn_cmd); + install_element(MGR_NODE, &cfg_mgr_board_temp_sever_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_temp_warn_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_temp_sever_cmd); + install_element(MGR_NODE, &cfg_mgr_pwr_action_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_baud_action_cmd); + + return 0; +} + +int sysmobts_mgr_parse_config(const char *config_file, + struct sbts2050_config_info *cfg) +{ + int rc; + + mgr_cfg = cfg; + + 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; +}
On Thu, Apr 10, 2014 at 03:42:33PM +0200, Alvaro Neira Ayuso wrote:
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 0000000..33c3fe6 --- /dev/null +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c @@ -0,0 +1,250 @@ +/* (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 <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"
+static struct sbts2050_config_info *mgr_cfg = NULL;
You don't need to initialize this variable, it's stored in the BSS so it's already set to zero.
From: Álvaro Neira Ayuso anayuso@sysmocom.de
Added the vty support for configuring the parameter for using the OML report in manager when we have anomalous temperature.
Signed-off-by: Alvaro Neira Ayuso anayuso@sysmocom.de --- [changes in v5] * Removed a NULL initialize of a static variable
doc/examples/osmobts-mgr.cfg | 30 ++++ src/osmo-bts-sysmo/Makefile.am | 5 +- src/osmo-bts-sysmo/misc/sysmobts_mgr.c | 43 ++++- src/osmo-bts-sysmo/misc/sysmobts_mgr.h | 16 ++ src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c | 250 ++++++++++++++++++++++++++++ 5 files changed, 341 insertions(+), 3 deletions(-) create mode 100644 doc/examples/osmobts-mgr.cfg create mode 100644 src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c
diff --git a/doc/examples/osmobts-mgr.cfg b/doc/examples/osmobts-mgr.cfg new file mode 100644 index 0000000..f1c4e8e --- /dev/null +++ b/doc/examples/osmobts-mgr.cfg @@ -0,0 +1,30 @@ +! +! SysmoMgr (0.3.0.137-7576) configuration saved from vty +!! +! +log stderr + logging filter all 1 + logging color 1 + logging timestamp 0 + logging level all everything + logging level temp info + logging level fw info + logging level find info + logging level lglobal notice + logging level llapd notice + logging level linp notice + logging level lmux notice + logging level lmi notice + logging level lmib notice + logging level lsms notice +! +line vty + no login +! +config-mgr + temp-warn-board -30 50 + temp-sever-board -50 80 + temp-warn-pa -30 50 + temp-sever-pa -50 80 + pwr-action 1 1 0 + pwr-max-transmiter 32 diff --git a/src/osmo-bts-sysmo/Makefile.am b/src/osmo-bts-sysmo/Makefile.am index 1c08af3..b4b7de7 100644 --- a/src/osmo-bts-sysmo/Makefile.am +++ b/src/osmo-bts-sysmo/Makefile.am @@ -22,8 +22,9 @@ l1fwd_proxy_LDADD = $(top_builddir)/src/common/libbts.a $(COMMON_LDADD)
sysmobts_mgr_SOURCES = \ misc/sysmobts_mgr.c misc/sysmobts_misc.c \ - misc/sysmobts_par.c misc/sysmobts_nl.c -sysmobts_mgr_LDADD = $(LIBOSMOCORE_LIBS) + misc/sysmobts_par.c misc/sysmobts_nl.c \ + misc/sysmobts_mgr_vty.c +sysmobts_mgr_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOVTY_LIBS)
sysmobts_util_SOURCES = misc/sysmobts_util.c misc/sysmobts_par.c sysmobts_util_LDADD = $(LIBOSMOCORE_LIBS) diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c index 51fa539..2f169e0 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c @@ -52,6 +52,24 @@ static int fd_unix = -1; void *tall_mgr_ctx; static struct sbts2050_config_info confinfo;
+static struct sysmobts_mgr_instance sysmobts_mgr_inst = { + .config_file = "osmobts-mgr.cfg", +}; + +const char *sysmomgr_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 struct vty_app_info vty_info = { + .name = "SysmoMgr", + .version = PACKAGE_VERSION, + .go_parent_cb = mgr_vty_go_parent, + .is_config_node = mgr_vty_is_config_node, +}; + /* every 6 hours means 365*4 = 1460 EEprom writes per year (max) */ #define TEMP_TIMER_SECS (6 * 3600)
@@ -211,13 +229,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; @@ -234,6 +253,9 @@ static int parse_options(int argc, char **argv) case 'D': daemonize = 1; break; + case 'c': + sysmobts_mgr_inst.config_file = optarg; + break; default: return -1; } @@ -437,6 +459,25 @@ int main(int argc, char **argv) if (rc < 0) exit(2);
+ vty_info.copyright = sysmomgr_copyright; + vty_init(&vty_info); + logging_vty_add_cmds(&mgr_log_info); + + sysmobts_mgr_vty_init(); + + rc = sysmobts_mgr_parse_config(sysmobts_mgr_inst.config_file, + &confinfo); + 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 87668e0..f9e5c09 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.h +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.h @@ -1,6 +1,9 @@ #ifndef _SYSMOBTS_MGR_H #define _SYSMOBTS_MGR_H
+#include <osmocom/vty/vty.h> +#include <osmocom/vty/command.h> + enum { DTEMP, DFW, @@ -12,4 +15,17 @@ enum { SYSMO_MGR_CONNECTED, };
+enum mgr_vty_node { + MGR_NODE = _LAST_OSMOVTY_NODE + 1, +}; + +enum node_type mgr_vty_go_parent(struct vty *vty); +int mgr_vty_is_config_node(struct vty *vty, int node); +int sysmobts_mgr_vty_init(void); +int sysmobts_mgr_parse_config(const char *config_file, + struct sbts2050_config_info *cfg); + +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 0000000..1f7a3fd --- /dev/null +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c @@ -0,0 +1,250 @@ +/* (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 <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" + +static struct sbts2050_config_info *mgr_cfg; + +enum node_type mgr_vty_go_parent(struct vty *vty) +{ + switch (vty->node) { + case MGR_NODE: + vty->node = CONFIG_NODE; + break; + default: + vty->node = CONFIG_NODE; + } + return vty->node; +} + +int mgr_vty_is_config_node(struct vty *vty, int node) +{ + switch (node) { + case MGR_NODE: + return 1; + default: + return 0; + } +} + +#define MGR_STR "Configure the sysmobts-mgr\n" + +static struct cmd_node mgr_node = { + MGR_NODE, + "%s(config-mgr)# ", + 1, +}; + +DEFUN(cfg_mgr, cfg_mgr_cmd, + "config-mgr", + MGR_STR) +{ + vty->node = MGR_NODE; + return CMD_SUCCESS; +} + +DEFUN(show_mgr, show_mgr_cmd, "show mgr", + SHOW_STR "Display information about the mgr") +{ + vty_out(vty, " temp-warn-board Min:%d Max:%d%s", + mgr_cfg->temp_min_board_warn_limit, + mgr_cfg->temp_max_board_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-sever-board Min:%d Max:%d%s", + mgr_cfg->temp_min_board_sever_limit, + mgr_cfg->temp_max_board_sever_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-warn-pa Min:%d Max:%d%s", + mgr_cfg->temp_min_pa_warn_limit, + mgr_cfg->temp_max_pa_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-sever-pa Min:%d Max:%d%s", + mgr_cfg->temp_min_pa_sever_limit, + mgr_cfg->temp_max_pa_sever_limit, + VTY_NEWLINE); + + vty_out(vty, " pwr_action Master:%d Slave:%d PA:%d%s", + mgr_cfg->master_power_act, + mgr_cfg->slave_power_act, + mgr_cfg->pa_power_act, + VTY_NEWLINE); + + vty_out(vty, " pwr-max-transmiter %d%s", + mgr_cfg->max_power_red, + VTY_NEWLINE); + return CMD_SUCCESS; +} + +static int config_write_mgr(struct vty *vty) +{ + vty_out(vty, "config-mgr%s", VTY_NEWLINE); + + vty_out(vty, " temp-warn-board %d %d%s", + mgr_cfg->temp_min_board_warn_limit, + mgr_cfg->temp_max_board_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-sever-board %d %d%s", + mgr_cfg->temp_min_board_sever_limit, + mgr_cfg->temp_max_board_sever_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-warn-pa %d %d%s", + mgr_cfg->temp_min_pa_warn_limit, + mgr_cfg->temp_max_pa_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temp-sever-pa %d %d%s", + mgr_cfg->temp_min_pa_sever_limit, + mgr_cfg->temp_max_pa_sever_limit, + VTY_NEWLINE); + + vty_out(vty, " pwr-action %d %d %d%s", + mgr_cfg->master_power_act, + mgr_cfg->slave_power_act, + mgr_cfg->pa_power_act, + VTY_NEWLINE); + + vty_out(vty, " pwr-max-transmiter %d%s", + mgr_cfg->max_power_red, + VTY_NEWLINE); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_board_temp_warn, cfg_mgr_board_temp_warn_cmd, + "temp-warn-board <-255-255> <-255-255>", + MGR_STR "Temperature Range Value of the warning limit (Min and Max)" + "in the Board\n") +{ + mgr_cfg->temp_min_board_warn_limit = atoi(argv[0]); + mgr_cfg->temp_max_board_warn_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_board_temp_sever, cfg_mgr_board_temp_sever_cmd, + "temp-sever-board <-255-255> <-255-255>", + MGR_STR "Temperature Range Value of the several limit (Min and Max)" + "in the Board\n") +{ + mgr_cfg->temp_min_board_sever_limit = atoi(argv[0]); + mgr_cfg->temp_max_board_sever_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_temp_warn, cfg_mgr_pa_temp_warn_cmd, + "temp-warn-pa <-255-255> <-255-255>", + MGR_STR "Temperature Range Value of the warning limit (Min and Max)" + "in the PA\n") +{ + mgr_cfg->temp_min_pa_warn_limit = atoi(argv[0]); + mgr_cfg->temp_max_pa_warn_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_temp_sever, cfg_mgr_pa_temp_sever_cmd, + "temp-sever-pa <-255-255> <-255-255>", + MGR_STR "Temperature Range Value of the several limit (Min and Max)" + "in the PA\n") +{ + mgr_cfg->temp_min_pa_sever_limit = atoi(argv[0]); + mgr_cfg->temp_max_pa_sever_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pwr_action, cfg_mgr_pwr_action_cmd, + "pwr-action (0|1) (0|1) (0|1)", + MGR_STR "Action for switching on (1) | off (0)" + "the Master, Slave and PA\n") +{ + mgr_cfg->master_power_act = atoi(argv[0]); + mgr_cfg->slave_power_act = atoi(argv[1]); + mgr_cfg->pa_power_act = atoi(argv[2]); + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_baud_action, cfg_mgr_pa_baud_action_cmd, + "pwr-max-transmiter <0-255>", + MGR_STR "Power baud transmition in the PA\n") +{ + mgr_cfg->max_power_red = atoi(argv[0]); + + return CMD_SUCCESS; +} + +int sysmobts_mgr_vty_init(void) + +{ + install_element_ve(&show_mgr_cmd); + + install_node(&mgr_node, config_write_mgr); + install_element(CONFIG_NODE, &cfg_mgr_cmd); + install_default(MGR_NODE); + + install_element(MGR_NODE, &cfg_mgr_board_temp_warn_cmd); + install_element(MGR_NODE, &cfg_mgr_board_temp_sever_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_temp_warn_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_temp_sever_cmd); + install_element(MGR_NODE, &cfg_mgr_pwr_action_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_baud_action_cmd); + + return 0; +} + +int sysmobts_mgr_parse_config(const char *config_file, + struct sbts2050_config_info *cfg) +{ + int rc; + + mgr_cfg = cfg; + + 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; +}
On Sun, Apr 13, 2014 at 03:22:45PM +0200, Alvaro Neira Ayuso wrote:
From: Álvaro Neira Ayuso anayuso@sysmocom.de
Added the vty support for configuring the parameter for using the OML report in manager when we have anomalous temperature.
Acked-by: Pablo Neira Ayuso pablo@gnumonks.org
From: Álvaro Neira Ayuso anayuso@sysmocom.de
Added the vty support for configuring the parameter for using the OML report in manager when we have anomalous temperature.
Signed-off-by: Alvaro Neira Ayuso anayuso@sysmocom.de --- [changes in v6] * Fixed the all the help information in the manager vty * Changed the name functions for using name more correct and with more intuitive * Changed the power-actions parameters for using ON and OFF
doc/examples/osmobts-mgr.cfg | 30 +++ src/osmo-bts-sysmo/Makefile.am | 5 +- src/osmo-bts-sysmo/misc/sysmobts_mgr.c | 43 ++++- src/osmo-bts-sysmo/misc/sysmobts_mgr.h | 18 ++ src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c | 279 ++++++++++++++++++++++++++++ 5 files changed, 372 insertions(+), 3 deletions(-) create mode 100644 doc/examples/osmobts-mgr.cfg create mode 100644 src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c
diff --git a/doc/examples/osmobts-mgr.cfg b/doc/examples/osmobts-mgr.cfg new file mode 100644 index 0000000..a1a1394 --- /dev/null +++ b/doc/examples/osmobts-mgr.cfg @@ -0,0 +1,30 @@ +! +! SysmoMgr (0.3.0.141-33e5) configuration saved from vty +!! +! +log stderr + logging filter all 1 + logging color 1 + logging timestamp 0 + logging level all everything + logging level temp info + logging level fw info + logging level find info + logging level lglobal notice + logging level llapd notice + logging level linp notice + logging level lmux notice + logging level lmi notice + logging level lmib notice + logging level lsms notice +! +line vty + no login +! +config-mgr + temperature-warning board -30 50 + temperature-severe board -50 80 + temperature-warning pa -30 50 + temperature-severe pa -50 80 + power-action ON ON OFF + power-max-transmiter 4 diff --git a/src/osmo-bts-sysmo/Makefile.am b/src/osmo-bts-sysmo/Makefile.am index 1c08af3..b4b7de7 100644 --- a/src/osmo-bts-sysmo/Makefile.am +++ b/src/osmo-bts-sysmo/Makefile.am @@ -22,8 +22,9 @@ l1fwd_proxy_LDADD = $(top_builddir)/src/common/libbts.a $(COMMON_LDADD)
sysmobts_mgr_SOURCES = \ misc/sysmobts_mgr.c misc/sysmobts_misc.c \ - misc/sysmobts_par.c misc/sysmobts_nl.c -sysmobts_mgr_LDADD = $(LIBOSMOCORE_LIBS) + misc/sysmobts_par.c misc/sysmobts_nl.c \ + misc/sysmobts_mgr_vty.c +sysmobts_mgr_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOVTY_LIBS)
sysmobts_util_SOURCES = misc/sysmobts_util.c misc/sysmobts_par.c sysmobts_util_LDADD = $(LIBOSMOCORE_LIBS) diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c index b686c79..efce674 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c @@ -52,6 +52,24 @@ static int fd_unix = -1; void *tall_mgr_ctx; static struct sbts2050_config_info confinfo;
+static struct sysmobts_mgr_instance sysmobts_mgr_inst = { + .config_file = "osmobts-mgr.cfg", +}; + +const char *sysmomgr_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 struct vty_app_info vty_info = { + .name = "SysmoMgr", + .version = PACKAGE_VERSION, + .go_parent_cb = mgr_vty_go_parent, + .is_config_node = mgr_vty_is_config_node, +}; + /* every 6 hours means 365*4 = 1460 EEprom writes per year (max) */ #define TEMP_TIMER_SECS (6 * 3600)
@@ -213,13 +231,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; @@ -236,6 +255,9 @@ static int parse_options(int argc, char **argv) case 'D': daemonize = 1; break; + case 'c': + sysmobts_mgr_inst.config_file = optarg; + break; default: return -1; } @@ -439,6 +461,25 @@ int main(int argc, char **argv) if (rc < 0) exit(2);
+ vty_info.copyright = sysmomgr_copyright; + vty_init(&vty_info); + logging_vty_add_cmds(&mgr_log_info); + + sysmobts_mgr_vty_init(); + + rc = sysmobts_mgr_parse_config(sysmobts_mgr_inst.config_file, + &confinfo); + 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 21f30a4..5e0d4a7 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.h +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.h @@ -1,6 +1,9 @@ #ifndef _SYSMOBTS_MGR_H #define _SYSMOBTS_MGR_H
+#include <osmocom/vty/vty.h> +#include <osmocom/vty/command.h> + enum { DTEMP, DFW, @@ -14,4 +17,19 @@ enum {
#define SOCKET_PATH "/var/run/bts_oml"
+struct sbts2050_config_info; + +enum mgr_vty_node { + MGR_NODE = _LAST_OSMOVTY_NODE + 1, +}; + +enum node_type mgr_vty_go_parent(struct vty *vty); +int mgr_vty_is_config_node(struct vty *vty, int node); +int sysmobts_mgr_vty_init(void); +int sysmobts_mgr_parse_config(const char *config_file, + struct sbts2050_config_info *cfg); + +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 0000000..c5e1a69 --- /dev/null +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c @@ -0,0 +1,279 @@ +/* (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" + +static struct sbts2050_config_info *mgr_cfg; + +enum node_type mgr_vty_go_parent(struct vty *vty) +{ + switch (vty->node) { + case MGR_NODE: + vty->node = CONFIG_NODE; + break; + default: + vty->node = CONFIG_NODE; + } + return vty->node; +} + +int mgr_vty_is_config_node(struct vty *vty, int node) +{ + switch (node) { + case MGR_NODE: + return 1; + default: + return 0; + } +} + +#define MGR_STR "Configure sysmobts-mgr\n" +#define MGR_TEMP_WARN_STR "Configure the temperature warning limits\n" +#define MGR_TEMP_SEVERE_STR "Configure the temperature severe limits\n" + +static struct cmd_node mgr_node = { + MGR_NODE, + "%s(config-mgr)# ", + 1, +}; + +DEFUN(cfg_mgr, cfg_mgr_cmd, + "config-mgr", + MGR_STR) +{ + vty->node = MGR_NODE; + return CMD_SUCCESS; +} + +DEFUN(show_mgr, show_mgr_cmd, "show mgr", + SHOW_STR "Display information about the mgr") +{ + vty_out(vty, " temperature-warning board Min:%d Max:%d%s", + mgr_cfg->temp_min_board_warn_limit, + mgr_cfg->temp_max_board_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-severe board Min:%d Max:%d%s", + mgr_cfg->temp_min_board_severe_limit, + mgr_cfg->temp_max_board_severe_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-warning pa Min:%d Max:%d%s", + mgr_cfg->temp_min_pa_warn_limit, + mgr_cfg->temp_max_pa_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-severe pa Min:%d Max:%d%s", + mgr_cfg->temp_min_pa_severe_limit, + mgr_cfg->temp_max_pa_severe_limit, + VTY_NEWLINE); + + vty_out(vty, " power-action Master:%s Slave:%s PA:%s%s", + mgr_cfg->master_power_act ? "ON" : "OFF", + mgr_cfg->slave_power_act ? "ON" : "OFF", + mgr_cfg->pa_power_act ? "ON" : "OFF", + VTY_NEWLINE); + + vty_out(vty, " power-max-transmitter %d%s", + mgr_cfg->reduce_max_power, + VTY_NEWLINE); + return CMD_SUCCESS; +} + +static int config_write_mgr(struct vty *vty) +{ + vty_out(vty, "config-mgr%s", VTY_NEWLINE); + + vty_out(vty, " temperature-warning board %d %d%s", + mgr_cfg->temp_min_board_warn_limit, + mgr_cfg->temp_max_board_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-severe board %d %d%s", + mgr_cfg->temp_min_board_severe_limit, + mgr_cfg->temp_max_board_severe_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-warning pa %d %d%s", + mgr_cfg->temp_min_pa_warn_limit, + mgr_cfg->temp_max_pa_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-severe pa %d %d%s", + mgr_cfg->temp_min_pa_severe_limit, + mgr_cfg->temp_max_pa_severe_limit, + VTY_NEWLINE); + + vty_out(vty, " power-action %s %s %s%s", + mgr_cfg->master_power_act ? "ON" : "OFF", + mgr_cfg->slave_power_act ? "ON" : "OFF", + mgr_cfg->pa_power_act ? "ON" : "OFF", + VTY_NEWLINE); + + vty_out(vty, " power-max-transmitter %d%s", + mgr_cfg->reduce_max_power, + VTY_NEWLINE); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_board_temp_warn, cfg_mgr_board_temp_warn_cmd, + "temperature-warning board <-255-255> <-255-255>", + MGR_TEMP_WARN_STR + "Set warning temperature limits on the Board\n" + "Warning temperature low limit on the Board\n" + "Warning temperature high limit on the Board\n") +{ + mgr_cfg->temp_min_board_warn_limit = atoi(argv[0]); + mgr_cfg->temp_max_board_warn_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_board_temp_sever, cfg_mgr_board_temp_sever_cmd, + "temperature-severe board <-255-255> <-255-255>", + MGR_TEMP_SEVERE_STR + "Set severe temperature limits on the Board\n" + "Severe temperature low limit on the Board\n" + "Severe Temperature high limit on the Board\n") +{ + mgr_cfg->temp_min_board_severe_limit = atoi(argv[0]); + mgr_cfg->temp_max_board_severe_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_temp_warn, cfg_mgr_pa_temp_warn_cmd, + "temperature-warning pa <-255-255> <-255-255>", + MGR_TEMP_WARN_STR + "Set warning temperature limits on the PA\n" + "Warning temperature low limit on the PA\n" + "Warning temperature high limit on the PA\n") +{ + mgr_cfg->temp_min_pa_warn_limit = atoi(argv[0]); + mgr_cfg->temp_max_pa_warn_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_temp_sever, cfg_mgr_pa_temp_sever_cmd, + "temperature-severe pa <-255-255> <-255-255>", + MGR_TEMP_SEVERE_STR + "Set severe temperature limits on the Board\n" + "Severe temperature low limit on the PA\n" + "Severe temperature high limit on the PA\n") +{ + mgr_cfg->temp_min_pa_severe_limit = atoi(argv[0]); + mgr_cfg->temp_max_pa_severe_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pwr_action, cfg_mgr_pwr_action_cmd, + "power-action (ON|OFF) (ON|OFF) (ON|OFF)", + "Configure which devices we want to turn on/off in several situation\n" + "the Master\n" + "the Master\n" + "the Slave\n" + "the Slave\n" + "the PA\n" + "the PA\n") +{ + if (strcmp(argv[0], "ON") == 0) + mgr_cfg->master_power_act = 1; + else if (strcmp(argv[0], "OFF") == 0) + mgr_cfg->master_power_act = 0; + + if (strcmp(argv[1], "ON") == 0) + mgr_cfg->slave_power_act = 1; + else if (strcmp(argv[1], "OFF") == 0) + mgr_cfg->slave_power_act = 0; + + if (strcmp(argv[2], "ON") == 0) + mgr_cfg->pa_power_act = 1; + else if (strcmp(argv[2], "OFF") == 0) + mgr_cfg->pa_power_act = 0; + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_baud_action, cfg_mgr_pa_baud_action_cmd, + "power-max-transmitter <0-255>", + "Configure the power that we want to reduce in warning situation\n" + "Power baud transmition that we want to reduce in the PA\n") +{ + mgr_cfg->reduce_max_power = atoi(argv[0]); + + return CMD_SUCCESS; +} + +int sysmobts_mgr_vty_init(void) + +{ + 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); + + install_element(MGR_NODE, &cfg_mgr_board_temp_warn_cmd); + install_element(MGR_NODE, &cfg_mgr_board_temp_sever_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_temp_warn_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_temp_sever_cmd); + install_element(MGR_NODE, &cfg_mgr_pwr_action_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_baud_action_cmd); + + return 0; +} + +int sysmobts_mgr_parse_config(const char *config_file, + struct sbts2050_config_info *cfg) +{ + int rc; + + mgr_cfg = cfg; + + 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; +}
From: Álvaro Neira Ayuso anayuso@sysmocom.de
Added the vty support for configuring the parameter for using the OML report in manager when we have anomalous temperature.
Signed-off-by: Alvaro Neira Ayuso anayuso@sysmocom.de --- [changes in v7] * Change the function power_max_transmitter for power_reduce_transmitter
doc/examples/osmobts-mgr.cfg | 30 +++ src/osmo-bts-sysmo/Makefile.am | 5 +- src/osmo-bts-sysmo/misc/sysmobts_mgr.c | 43 ++++- src/osmo-bts-sysmo/misc/sysmobts_mgr.h | 18 ++ src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c | 279 ++++++++++++++++++++++++++++ 5 files changed, 372 insertions(+), 3 deletions(-) create mode 100644 doc/examples/osmobts-mgr.cfg create mode 100644 src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c
diff --git a/doc/examples/osmobts-mgr.cfg b/doc/examples/osmobts-mgr.cfg new file mode 100644 index 0000000..c1b5465 --- /dev/null +++ b/doc/examples/osmobts-mgr.cfg @@ -0,0 +1,30 @@ +! +! SysmoMgr (0.3.0.141-33e5) configuration saved from vty +!! +! +log stderr + logging filter all 1 + logging color 1 + logging timestamp 0 + logging level all everything + logging level temp info + logging level fw info + logging level find info + logging level lglobal notice + logging level llapd notice + logging level linp notice + logging level lmux notice + logging level lmi notice + logging level lmib notice + logging level lsms notice +! +line vty + no login +! +config-mgr + temperature-warning board -30 50 + temperature-severe board -50 80 + temperature-warning pa -30 50 + temperature-severe pa -50 80 + power-action ON ON OFF + power-reduce-transmiter 4 diff --git a/src/osmo-bts-sysmo/Makefile.am b/src/osmo-bts-sysmo/Makefile.am index 1c08af3..b4b7de7 100644 --- a/src/osmo-bts-sysmo/Makefile.am +++ b/src/osmo-bts-sysmo/Makefile.am @@ -22,8 +22,9 @@ l1fwd_proxy_LDADD = $(top_builddir)/src/common/libbts.a $(COMMON_LDADD)
sysmobts_mgr_SOURCES = \ misc/sysmobts_mgr.c misc/sysmobts_misc.c \ - misc/sysmobts_par.c misc/sysmobts_nl.c -sysmobts_mgr_LDADD = $(LIBOSMOCORE_LIBS) + misc/sysmobts_par.c misc/sysmobts_nl.c \ + misc/sysmobts_mgr_vty.c +sysmobts_mgr_LDADD = $(LIBOSMOCORE_LIBS) $(LIBOSMOVTY_LIBS)
sysmobts_util_SOURCES = misc/sysmobts_util.c misc/sysmobts_par.c sysmobts_util_LDADD = $(LIBOSMOCORE_LIBS) diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c index 8dd97ec..15199f9 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c @@ -52,6 +52,24 @@ static int fd_unix = -1; void *tall_mgr_ctx; static struct sbts2050_config_info confinfo;
+static struct sysmobts_mgr_instance sysmobts_mgr_inst = { + .config_file = "osmobts-mgr.cfg", +}; + +const char *sysmomgr_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 struct vty_app_info vty_info = { + .name = "SysmoMgr", + .version = PACKAGE_VERSION, + .go_parent_cb = mgr_vty_go_parent, + .is_config_node = mgr_vty_is_config_node, +}; + /* every 6 hours means 365*4 = 1460 EEprom writes per year (max) */ #define TEMP_TIMER_SECS (6 * 3600)
@@ -206,13 +224,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; @@ -229,6 +248,9 @@ static int parse_options(int argc, char **argv) case 'D': daemonize = 1; break; + case 'c': + sysmobts_mgr_inst.config_file = optarg; + break; default: return -1; } @@ -432,6 +454,25 @@ int main(int argc, char **argv) if (rc < 0) exit(2);
+ vty_info.copyright = sysmomgr_copyright; + vty_init(&vty_info); + logging_vty_add_cmds(&mgr_log_info); + + sysmobts_mgr_vty_init(); + + rc = sysmobts_mgr_parse_config(sysmobts_mgr_inst.config_file, + &confinfo); + 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 21f30a4..5e0d4a7 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.h +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.h @@ -1,6 +1,9 @@ #ifndef _SYSMOBTS_MGR_H #define _SYSMOBTS_MGR_H
+#include <osmocom/vty/vty.h> +#include <osmocom/vty/command.h> + enum { DTEMP, DFW, @@ -14,4 +17,19 @@ enum {
#define SOCKET_PATH "/var/run/bts_oml"
+struct sbts2050_config_info; + +enum mgr_vty_node { + MGR_NODE = _LAST_OSMOVTY_NODE + 1, +}; + +enum node_type mgr_vty_go_parent(struct vty *vty); +int mgr_vty_is_config_node(struct vty *vty, int node); +int sysmobts_mgr_vty_init(void); +int sysmobts_mgr_parse_config(const char *config_file, + struct sbts2050_config_info *cfg); + +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 0000000..fc50054 --- /dev/null +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c @@ -0,0 +1,279 @@ +/* (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" + +static struct sbts2050_config_info *mgr_cfg; + +enum node_type mgr_vty_go_parent(struct vty *vty) +{ + switch (vty->node) { + case MGR_NODE: + vty->node = CONFIG_NODE; + break; + default: + vty->node = CONFIG_NODE; + } + return vty->node; +} + +int mgr_vty_is_config_node(struct vty *vty, int node) +{ + switch (node) { + case MGR_NODE: + return 1; + default: + return 0; + } +} + +#define MGR_STR "Configure sysmobts-mgr\n" +#define MGR_TEMP_WARN_STR "Configure the temperature warning limits\n" +#define MGR_TEMP_SEVERE_STR "Configure the temperature severe limits\n" + +static struct cmd_node mgr_node = { + MGR_NODE, + "%s(config-mgr)# ", + 1, +}; + +DEFUN(cfg_mgr, cfg_mgr_cmd, + "config-mgr", + MGR_STR) +{ + vty->node = MGR_NODE; + return CMD_SUCCESS; +} + +DEFUN(show_mgr, show_mgr_cmd, "show mgr", + SHOW_STR "Display information about the mgr") +{ + vty_out(vty, " temperature-warning board Min:%d Max:%d%s", + mgr_cfg->temp_min_board_warn_limit, + mgr_cfg->temp_max_board_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-severe board Min:%d Max:%d%s", + mgr_cfg->temp_min_board_severe_limit, + mgr_cfg->temp_max_board_severe_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-warning pa Min:%d Max:%d%s", + mgr_cfg->temp_min_pa_warn_limit, + mgr_cfg->temp_max_pa_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-severe pa Min:%d Max:%d%s", + mgr_cfg->temp_min_pa_severe_limit, + mgr_cfg->temp_max_pa_severe_limit, + VTY_NEWLINE); + + vty_out(vty, " power-action Master:%s Slave:%s PA:%s%s", + mgr_cfg->master_power_act ? "ON" : "OFF", + mgr_cfg->slave_power_act ? "ON" : "OFF", + mgr_cfg->pa_power_act ? "ON" : "OFF", + VTY_NEWLINE); + + vty_out(vty, " power-reduce-transmitter %d%s", + mgr_cfg->reduce_max_power, + VTY_NEWLINE); + return CMD_SUCCESS; +} + +static int config_write_mgr(struct vty *vty) +{ + vty_out(vty, "config-mgr%s", VTY_NEWLINE); + + vty_out(vty, " temperature-warning board %d %d%s", + mgr_cfg->temp_min_board_warn_limit, + mgr_cfg->temp_max_board_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-severe board %d %d%s", + mgr_cfg->temp_min_board_severe_limit, + mgr_cfg->temp_max_board_severe_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-warning pa %d %d%s", + mgr_cfg->temp_min_pa_warn_limit, + mgr_cfg->temp_max_pa_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-severe pa %d %d%s", + mgr_cfg->temp_min_pa_severe_limit, + mgr_cfg->temp_max_pa_severe_limit, + VTY_NEWLINE); + + vty_out(vty, " power-action %s %s %s%s", + mgr_cfg->master_power_act ? "ON" : "OFF", + mgr_cfg->slave_power_act ? "ON" : "OFF", + mgr_cfg->pa_power_act ? "ON" : "OFF", + VTY_NEWLINE); + + vty_out(vty, " power-reduce-transmitter %d%s", + mgr_cfg->reduce_max_power, + VTY_NEWLINE); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_board_temp_warn, cfg_mgr_board_temp_warn_cmd, + "temperature-warning board <-255-255> <-255-255>", + MGR_TEMP_WARN_STR + "Set warning temperature limits on the Board\n" + "Warning temperature low limit on the Board\n" + "Warning temperature high limit on the Board\n") +{ + mgr_cfg->temp_min_board_warn_limit = atoi(argv[0]); + mgr_cfg->temp_max_board_warn_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_board_temp_sever, cfg_mgr_board_temp_sever_cmd, + "temperature-severe board <-255-255> <-255-255>", + MGR_TEMP_SEVERE_STR + "Set severe temperature limits on the Board\n" + "Severe temperature low limit on the Board\n" + "Severe Temperature high limit on the Board\n") +{ + mgr_cfg->temp_min_board_severe_limit = atoi(argv[0]); + mgr_cfg->temp_max_board_severe_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_temp_warn, cfg_mgr_pa_temp_warn_cmd, + "temperature-warning pa <-255-255> <-255-255>", + MGR_TEMP_WARN_STR + "Set warning temperature limits on the PA\n" + "Warning temperature low limit on the PA\n" + "Warning temperature high limit on the PA\n") +{ + mgr_cfg->temp_min_pa_warn_limit = atoi(argv[0]); + mgr_cfg->temp_max_pa_warn_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_temp_sever, cfg_mgr_pa_temp_sever_cmd, + "temperature-severe pa <-255-255> <-255-255>", + MGR_TEMP_SEVERE_STR + "Set severe temperature limits on the Board\n" + "Severe temperature low limit on the PA\n" + "Severe temperature high limit on the PA\n") +{ + mgr_cfg->temp_min_pa_severe_limit = atoi(argv[0]); + mgr_cfg->temp_max_pa_severe_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pwr_action, cfg_mgr_pwr_action_cmd, + "power-action (ON|OFF) (ON|OFF) (ON|OFF)", + "Configure which devices we want to turn on/off in several situation\n" + "the Master\n" + "the Master\n" + "the Slave\n" + "the Slave\n" + "the PA\n" + "the PA\n") +{ + if (strcmp(argv[0], "ON") == 0) + mgr_cfg->master_power_act = 1; + else if (strcmp(argv[0], "OFF") == 0) + mgr_cfg->master_power_act = 0; + + if (strcmp(argv[1], "ON") == 0) + mgr_cfg->slave_power_act = 1; + else if (strcmp(argv[1], "OFF") == 0) + mgr_cfg->slave_power_act = 0; + + if (strcmp(argv[2], "ON") == 0) + mgr_cfg->pa_power_act = 1; + else if (strcmp(argv[2], "OFF") == 0) + mgr_cfg->pa_power_act = 0; + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_baud_action, cfg_mgr_pa_baud_action_cmd, + "power-reduce-transmitter <0-255>", + "Configure the power that we want to reduce in warning situation\n" + "Power baud transmition that we want to reduce in the PA\n") +{ + mgr_cfg->reduce_max_power = atoi(argv[0]); + + return CMD_SUCCESS; +} + +int sysmobts_mgr_vty_init(void) + +{ + 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); + + install_element(MGR_NODE, &cfg_mgr_board_temp_warn_cmd); + install_element(MGR_NODE, &cfg_mgr_board_temp_sever_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_temp_warn_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_temp_sever_cmd); + install_element(MGR_NODE, &cfg_mgr_pwr_action_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_baud_action_cmd); + + return 0; +} + +int sysmobts_mgr_parse_config(const char *config_file, + struct sbts2050_config_info *cfg) +{ + int rc; + + mgr_cfg = cfg; + + 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; +}
On Wed, Apr 16, 2014 at 02:07:34PM +0200, Alvaro Neira Ayuso wrote:
+DEFUN(cfg_mgr_pwr_action, cfg_mgr_pwr_action_cmd,
- "power-action (ON|OFF) (ON|OFF) (ON|OFF)",
Why do you want to use capital letters here? No need to scream at the manager? right?
- "Configure which devices we want to turn on/off in several situation\n"
- "the Master\n"
- "the Master\n"
Use different descriptions for On and Off.
From: Álvaro Neira Ayuso anayuso@sysmocom.de
Added the vty support for configuring the parameter for using the OML report in manager when we have anomalous temperature.
Signed-off-by: Alvaro Neira Ayuso anayuso@sysmocom.de --- [changes in v8] * Changed the capital parameter in the function power-action * Fixed a forgot value when we print our manager configuration * Added best description in the help information of the power-action parameters
doc/examples/osmobts-mgr.cfg | 30 +++ src/osmo-bts-sysmo/Makefile.am | 3 +- src/osmo-bts-sysmo/misc/sysmobts_mgr.c | 43 ++++- src/osmo-bts-sysmo/misc/sysmobts_mgr.h | 18 ++ src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c | 279 ++++++++++++++++++++++++++++ 5 files changed, 371 insertions(+), 2 deletions(-) create mode 100644 doc/examples/osmobts-mgr.cfg create mode 100644 src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c
diff --git a/doc/examples/osmobts-mgr.cfg b/doc/examples/osmobts-mgr.cfg new file mode 100644 index 0000000..3592202 --- /dev/null +++ b/doc/examples/osmobts-mgr.cfg @@ -0,0 +1,30 @@ +! +! SysmoMgr (0.3.0.141-33e5) configuration saved from vty +!! +! +log stderr + logging filter all 1 + logging color 1 + logging timestamp 0 + logging level all everything + logging level temp info + logging level fw info + logging level find info + logging level lglobal notice + logging level llapd notice + logging level linp notice + logging level lmux notice + logging level lmi notice + logging level lmib notice + logging level lsms notice +! +line vty + no login +! +config-mgr + temperature-warning board -30 50 + temperature-severe board -50 80 + temperature-warning pa -30 50 + temperature-severe pa -50 80 + power-action on on off + power-reduce-transmitter 4 diff --git a/src/osmo-bts-sysmo/Makefile.am b/src/osmo-bts-sysmo/Makefile.am index e9ba949..de70761 100644 --- a/src/osmo-bts-sysmo/Makefile.am +++ b/src/osmo-bts-sysmo/Makefile.am @@ -22,7 +22,8 @@ l1fwd_proxy_LDADD = $(top_builddir)/src/common/libbts.a $(COMMON_LDADD)
sysmobts_mgr_SOURCES = \ misc/sysmobts_mgr.c misc/sysmobts_misc.c \ - misc/sysmobts_par.c misc/sysmobts_nl.c utils.c + misc/sysmobts_par.c misc/sysmobts_nl.c utils.c \ + misc/sysmobts_mgr_vty.c sysmobts_mgr_LDADD = $(COMMON_LDADD)
sysmobts_util_SOURCES = misc/sysmobts_util.c misc/sysmobts_par.c diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c index 51fdd83..99e95d5 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c @@ -52,6 +52,24 @@ static int fd_unix = -1; void *tall_mgr_ctx; static struct sbts2050_config_info confinfo;
+static struct sysmobts_mgr_instance sysmobts_mgr_inst = { + .config_file = "osmobts-mgr.cfg", +}; + +const char *sysmomgr_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 struct vty_app_info vty_info = { + .name = "SysmoMgr", + .version = PACKAGE_VERSION, + .go_parent_cb = mgr_vty_go_parent, + .is_config_node = mgr_vty_is_config_node, +}; + /* every 6 hours means 365*4 = 1460 EEprom writes per year (max) */ #define TEMP_TIMER_SECS (6 * 3600)
@@ -221,13 +239,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; @@ -244,6 +263,9 @@ static int parse_options(int argc, char **argv) case 'D': daemonize = 1; break; + case 'c': + sysmobts_mgr_inst.config_file = optarg; + break; default: return -1; } @@ -447,6 +469,25 @@ int main(int argc, char **argv) if (rc < 0) exit(2);
+ vty_info.copyright = sysmomgr_copyright; + vty_init(&vty_info); + logging_vty_add_cmds(&mgr_log_info); + + sysmobts_mgr_vty_init(); + + rc = sysmobts_mgr_parse_config(sysmobts_mgr_inst.config_file, + &confinfo); + 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 21f30a4..5e0d4a7 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.h +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.h @@ -1,6 +1,9 @@ #ifndef _SYSMOBTS_MGR_H #define _SYSMOBTS_MGR_H
+#include <osmocom/vty/vty.h> +#include <osmocom/vty/command.h> + enum { DTEMP, DFW, @@ -14,4 +17,19 @@ enum {
#define SOCKET_PATH "/var/run/bts_oml"
+struct sbts2050_config_info; + +enum mgr_vty_node { + MGR_NODE = _LAST_OSMOVTY_NODE + 1, +}; + +enum node_type mgr_vty_go_parent(struct vty *vty); +int mgr_vty_is_config_node(struct vty *vty, int node); +int sysmobts_mgr_vty_init(void); +int sysmobts_mgr_parse_config(const char *config_file, + struct sbts2050_config_info *cfg); + +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 0000000..9a77a95 --- /dev/null +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c @@ -0,0 +1,279 @@ +/* (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" + +static struct sbts2050_config_info *mgr_cfg; + +enum node_type mgr_vty_go_parent(struct vty *vty) +{ + switch (vty->node) { + case MGR_NODE: + vty->node = CONFIG_NODE; + break; + default: + vty->node = CONFIG_NODE; + } + return vty->node; +} + +int mgr_vty_is_config_node(struct vty *vty, int node) +{ + switch (node) { + case MGR_NODE: + return 1; + default: + return 0; + } +} + +#define MGR_STR "Configure sysmobts-mgr\n" +#define MGR_TEMP_WARN_STR "Configure the temperature warning limits\n" +#define MGR_TEMP_SEVERE_STR "Configure the temperature severe limits\n" + +static struct cmd_node mgr_node = { + MGR_NODE, + "%s(config-mgr)# ", + 1, +}; + +DEFUN(cfg_mgr, cfg_mgr_cmd, + "config-mgr", + MGR_STR) +{ + vty->node = MGR_NODE; + return CMD_SUCCESS; +} + +DEFUN(show_mgr, show_mgr_cmd, "show mgr", + SHOW_STR "Display information about the mgr") +{ + vty_out(vty, " temperature-warning board Min:%d Max:%d%s", + mgr_cfg->temp_min_board_warn_limit, + mgr_cfg->temp_max_board_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-severe board Min:%d Max:%d%s", + mgr_cfg->temp_min_board_severe_limit, + mgr_cfg->temp_max_board_severe_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-warning pa Min:%d Max:%d%s", + mgr_cfg->temp_min_pa_warn_limit, + mgr_cfg->temp_max_pa_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-severe pa Min:%d Max:%d%s", + mgr_cfg->temp_min_pa_severe_limit, + mgr_cfg->temp_max_pa_severe_limit, + VTY_NEWLINE); + + vty_out(vty, " power-action Master:%s Slave:%s PA:%s%s", + mgr_cfg->master_power_act ? "on" : "off", + mgr_cfg->slave_power_act ? "on" : "off", + mgr_cfg->pa_power_act ? "on" : "off", + VTY_NEWLINE); + + vty_out(vty, " power-reduce-transmitter %d%s", + mgr_cfg->reduce_max_power, + VTY_NEWLINE); + return CMD_SUCCESS; +} + +static int config_write_mgr(struct vty *vty) +{ + vty_out(vty, "config-mgr%s", VTY_NEWLINE); + + vty_out(vty, " temperature-warning board %d %d%s", + mgr_cfg->temp_min_board_warn_limit, + mgr_cfg->temp_max_board_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-severe board %d %d%s", + mgr_cfg->temp_min_board_severe_limit, + mgr_cfg->temp_max_board_severe_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-warning pa %d %d%s", + mgr_cfg->temp_min_pa_warn_limit, + mgr_cfg->temp_max_pa_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-severe pa %d %d%s", + mgr_cfg->temp_min_pa_severe_limit, + mgr_cfg->temp_max_pa_severe_limit, + VTY_NEWLINE); + + vty_out(vty, " power-action %s %s %s%s", + mgr_cfg->master_power_act ? "on" : "off", + mgr_cfg->slave_power_act ? "on" : "off", + mgr_cfg->pa_power_act ? "on" : "off", + VTY_NEWLINE); + + vty_out(vty, " power-reduce-transmitter %d%s", + mgr_cfg->reduce_max_power, + VTY_NEWLINE); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_board_temp_warn, cfg_mgr_board_temp_warn_cmd, + "temperature-warning board <-255-255> <-255-255>", + MGR_TEMP_WARN_STR + "Set warning temperature limits on the Board\n" + "Warning temperature low limit on the Board\n" + "Warning temperature high limit on the Board\n") +{ + mgr_cfg->temp_min_board_warn_limit = atoi(argv[0]); + mgr_cfg->temp_max_board_warn_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_board_temp_sever, cfg_mgr_board_temp_sever_cmd, + "temperature-severe board <-255-255> <-255-255>", + MGR_TEMP_SEVERE_STR + "Set severe temperature limits on the Board\n" + "Severe temperature low limit on the Board\n" + "Severe Temperature high limit on the Board\n") +{ + mgr_cfg->temp_min_board_severe_limit = atoi(argv[0]); + mgr_cfg->temp_max_board_severe_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_temp_warn, cfg_mgr_pa_temp_warn_cmd, + "temperature-warning pa <-255-255> <-255-255>", + MGR_TEMP_WARN_STR + "Set warning temperature limits on the PA\n" + "Warning temperature low limit on the PA\n" + "Warning temperature high limit on the PA\n") +{ + mgr_cfg->temp_min_pa_warn_limit = atoi(argv[0]); + mgr_cfg->temp_max_pa_warn_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_temp_sever, cfg_mgr_pa_temp_sever_cmd, + "temperature-severe pa <-255-255> <-255-255>", + MGR_TEMP_SEVERE_STR + "Set severe temperature limits on the Board\n" + "Severe temperature low limit on the PA\n" + "Severe temperature high limit on the PA\n") +{ + mgr_cfg->temp_min_pa_severe_limit = atoi(argv[0]); + mgr_cfg->temp_max_pa_severe_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pwr_action, cfg_mgr_pwr_action_cmd, + "power-action (on|off) (on|off) (on|off)", + "Configure which devices we want to turn on/off in several situation\n" + "Turn on the Master\n" + "Turn off the Master\n" + "Turn on the Slave\n" + "Turn off the Slave\n" + "Turn on the PA\n" + "Turn off the PA\n") +{ + if (strcmp(argv[0], "on") == 0) + mgr_cfg->master_power_act = 1; + else if (strcmp(argv[0], "off") == 0) + mgr_cfg->master_power_act = 0; + + if (strcmp(argv[1], "on") == 0) + mgr_cfg->slave_power_act = 1; + else if (strcmp(argv[1], "off") == 0) + mgr_cfg->slave_power_act = 0; + + if (strcmp(argv[2], "on") == 0) + mgr_cfg->pa_power_act = 1; + else if (strcmp(argv[2], "off") == 0) + mgr_cfg->pa_power_act = 0; + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_baud_action, cfg_mgr_pa_baud_action_cmd, + "power-reduce-transmitter <0-255>", + "Configure the power that we want to reduce in warning situation\n" + "Power baud transmition that we want to reduce in the PA\n") +{ + mgr_cfg->reduce_max_power = atoi(argv[0]); + + return CMD_SUCCESS; +} + +int sysmobts_mgr_vty_init(void) + +{ + 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); + + install_element(MGR_NODE, &cfg_mgr_board_temp_warn_cmd); + install_element(MGR_NODE, &cfg_mgr_board_temp_sever_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_temp_warn_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_temp_sever_cmd); + install_element(MGR_NODE, &cfg_mgr_pwr_action_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_baud_action_cmd); + + return 0; +} + +int sysmobts_mgr_parse_config(const char *config_file, + struct sbts2050_config_info *cfg) +{ + int rc; + + mgr_cfg = cfg; + + 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; +}
Added the vty support for configuring the parameter for using the OML report in manager when we have anomalous temperature.
Signed-off-by: Alvaro Neira Ayuso anayuso@sysmocom.de --- doc/examples/osmobts-mgr.cfg | 30 +++ src/osmo-bts-sysmo/Makefile.am | 3 +- src/osmo-bts-sysmo/misc/sysmobts_mgr.c | 43 ++++- src/osmo-bts-sysmo/misc/sysmobts_mgr.h | 18 ++ src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c | 279 ++++++++++++++++++++++++++++ 5 files changed, 371 insertions(+), 2 deletions(-) create mode 100644 doc/examples/osmobts-mgr.cfg create mode 100644 src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c
diff --git a/doc/examples/osmobts-mgr.cfg b/doc/examples/osmobts-mgr.cfg new file mode 100644 index 0000000..3592202 --- /dev/null +++ b/doc/examples/osmobts-mgr.cfg @@ -0,0 +1,30 @@ +! +! SysmoMgr (0.3.0.141-33e5) configuration saved from vty +!! +! +log stderr + logging filter all 1 + logging color 1 + logging timestamp 0 + logging level all everything + logging level temp info + logging level fw info + logging level find info + logging level lglobal notice + logging level llapd notice + logging level linp notice + logging level lmux notice + logging level lmi notice + logging level lmib notice + logging level lsms notice +! +line vty + no login +! +config-mgr + temperature-warning board -30 50 + temperature-severe board -50 80 + temperature-warning pa -30 50 + temperature-severe pa -50 80 + power-action on on off + power-reduce-transmitter 4 diff --git a/src/osmo-bts-sysmo/Makefile.am b/src/osmo-bts-sysmo/Makefile.am index e9ba949..de70761 100644 --- a/src/osmo-bts-sysmo/Makefile.am +++ b/src/osmo-bts-sysmo/Makefile.am @@ -22,7 +22,8 @@ l1fwd_proxy_LDADD = $(top_builddir)/src/common/libbts.a $(COMMON_LDADD)
sysmobts_mgr_SOURCES = \ misc/sysmobts_mgr.c misc/sysmobts_misc.c \ - misc/sysmobts_par.c misc/sysmobts_nl.c utils.c + misc/sysmobts_par.c misc/sysmobts_nl.c utils.c \ + misc/sysmobts_mgr_vty.c sysmobts_mgr_LDADD = $(COMMON_LDADD)
sysmobts_util_SOURCES = misc/sysmobts_util.c misc/sysmobts_par.c diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c index 51fdd83..99e95d5 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c @@ -52,6 +52,24 @@ static int fd_unix = -1; void *tall_mgr_ctx; static struct sbts2050_config_info confinfo;
+static struct sysmobts_mgr_instance sysmobts_mgr_inst = { + .config_file = "osmobts-mgr.cfg", +}; + +const char *sysmomgr_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 struct vty_app_info vty_info = { + .name = "SysmoMgr", + .version = PACKAGE_VERSION, + .go_parent_cb = mgr_vty_go_parent, + .is_config_node = mgr_vty_is_config_node, +}; + /* every 6 hours means 365*4 = 1460 EEprom writes per year (max) */ #define TEMP_TIMER_SECS (6 * 3600)
@@ -221,13 +239,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; @@ -244,6 +263,9 @@ static int parse_options(int argc, char **argv) case 'D': daemonize = 1; break; + case 'c': + sysmobts_mgr_inst.config_file = optarg; + break; default: return -1; } @@ -447,6 +469,25 @@ int main(int argc, char **argv) if (rc < 0) exit(2);
+ vty_info.copyright = sysmomgr_copyright; + vty_init(&vty_info); + logging_vty_add_cmds(&mgr_log_info); + + sysmobts_mgr_vty_init(); + + rc = sysmobts_mgr_parse_config(sysmobts_mgr_inst.config_file, + &confinfo); + 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 21f30a4..5e0d4a7 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.h +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.h @@ -1,6 +1,9 @@ #ifndef _SYSMOBTS_MGR_H #define _SYSMOBTS_MGR_H
+#include <osmocom/vty/vty.h> +#include <osmocom/vty/command.h> + enum { DTEMP, DFW, @@ -14,4 +17,19 @@ enum {
#define SOCKET_PATH "/var/run/bts_oml"
+struct sbts2050_config_info; + +enum mgr_vty_node { + MGR_NODE = _LAST_OSMOVTY_NODE + 1, +}; + +enum node_type mgr_vty_go_parent(struct vty *vty); +int mgr_vty_is_config_node(struct vty *vty, int node); +int sysmobts_mgr_vty_init(void); +int sysmobts_mgr_parse_config(const char *config_file, + struct sbts2050_config_info *cfg); + +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 0000000..9a77a95 --- /dev/null +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c @@ -0,0 +1,279 @@ +/* (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" + +static struct sbts2050_config_info *mgr_cfg; + +enum node_type mgr_vty_go_parent(struct vty *vty) +{ + switch (vty->node) { + case MGR_NODE: + vty->node = CONFIG_NODE; + break; + default: + vty->node = CONFIG_NODE; + } + return vty->node; +} + +int mgr_vty_is_config_node(struct vty *vty, int node) +{ + switch (node) { + case MGR_NODE: + return 1; + default: + return 0; + } +} + +#define MGR_STR "Configure sysmobts-mgr\n" +#define MGR_TEMP_WARN_STR "Configure the temperature warning limits\n" +#define MGR_TEMP_SEVERE_STR "Configure the temperature severe limits\n" + +static struct cmd_node mgr_node = { + MGR_NODE, + "%s(config-mgr)# ", + 1, +}; + +DEFUN(cfg_mgr, cfg_mgr_cmd, + "config-mgr", + MGR_STR) +{ + vty->node = MGR_NODE; + return CMD_SUCCESS; +} + +DEFUN(show_mgr, show_mgr_cmd, "show mgr", + SHOW_STR "Display information about the mgr") +{ + vty_out(vty, " temperature-warning board Min:%d Max:%d%s", + mgr_cfg->temp_min_board_warn_limit, + mgr_cfg->temp_max_board_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-severe board Min:%d Max:%d%s", + mgr_cfg->temp_min_board_severe_limit, + mgr_cfg->temp_max_board_severe_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-warning pa Min:%d Max:%d%s", + mgr_cfg->temp_min_pa_warn_limit, + mgr_cfg->temp_max_pa_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-severe pa Min:%d Max:%d%s", + mgr_cfg->temp_min_pa_severe_limit, + mgr_cfg->temp_max_pa_severe_limit, + VTY_NEWLINE); + + vty_out(vty, " power-action Master:%s Slave:%s PA:%s%s", + mgr_cfg->master_power_act ? "on" : "off", + mgr_cfg->slave_power_act ? "on" : "off", + mgr_cfg->pa_power_act ? "on" : "off", + VTY_NEWLINE); + + vty_out(vty, " power-reduce-transmitter %d%s", + mgr_cfg->reduce_max_power, + VTY_NEWLINE); + return CMD_SUCCESS; +} + +static int config_write_mgr(struct vty *vty) +{ + vty_out(vty, "config-mgr%s", VTY_NEWLINE); + + vty_out(vty, " temperature-warning board %d %d%s", + mgr_cfg->temp_min_board_warn_limit, + mgr_cfg->temp_max_board_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-severe board %d %d%s", + mgr_cfg->temp_min_board_severe_limit, + mgr_cfg->temp_max_board_severe_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-warning pa %d %d%s", + mgr_cfg->temp_min_pa_warn_limit, + mgr_cfg->temp_max_pa_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-severe pa %d %d%s", + mgr_cfg->temp_min_pa_severe_limit, + mgr_cfg->temp_max_pa_severe_limit, + VTY_NEWLINE); + + vty_out(vty, " power-action %s %s %s%s", + mgr_cfg->master_power_act ? "on" : "off", + mgr_cfg->slave_power_act ? "on" : "off", + mgr_cfg->pa_power_act ? "on" : "off", + VTY_NEWLINE); + + vty_out(vty, " power-reduce-transmitter %d%s", + mgr_cfg->reduce_max_power, + VTY_NEWLINE); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_board_temp_warn, cfg_mgr_board_temp_warn_cmd, + "temperature-warning board <-255-255> <-255-255>", + MGR_TEMP_WARN_STR + "Set warning temperature limits on the Board\n" + "Warning temperature low limit on the Board\n" + "Warning temperature high limit on the Board\n") +{ + mgr_cfg->temp_min_board_warn_limit = atoi(argv[0]); + mgr_cfg->temp_max_board_warn_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_board_temp_sever, cfg_mgr_board_temp_sever_cmd, + "temperature-severe board <-255-255> <-255-255>", + MGR_TEMP_SEVERE_STR + "Set severe temperature limits on the Board\n" + "Severe temperature low limit on the Board\n" + "Severe Temperature high limit on the Board\n") +{ + mgr_cfg->temp_min_board_severe_limit = atoi(argv[0]); + mgr_cfg->temp_max_board_severe_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_temp_warn, cfg_mgr_pa_temp_warn_cmd, + "temperature-warning pa <-255-255> <-255-255>", + MGR_TEMP_WARN_STR + "Set warning temperature limits on the PA\n" + "Warning temperature low limit on the PA\n" + "Warning temperature high limit on the PA\n") +{ + mgr_cfg->temp_min_pa_warn_limit = atoi(argv[0]); + mgr_cfg->temp_max_pa_warn_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_temp_sever, cfg_mgr_pa_temp_sever_cmd, + "temperature-severe pa <-255-255> <-255-255>", + MGR_TEMP_SEVERE_STR + "Set severe temperature limits on the Board\n" + "Severe temperature low limit on the PA\n" + "Severe temperature high limit on the PA\n") +{ + mgr_cfg->temp_min_pa_severe_limit = atoi(argv[0]); + mgr_cfg->temp_max_pa_severe_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pwr_action, cfg_mgr_pwr_action_cmd, + "power-action (on|off) (on|off) (on|off)", + "Configure which devices we want to turn on/off in several situation\n" + "Turn on the Master\n" + "Turn off the Master\n" + "Turn on the Slave\n" + "Turn off the Slave\n" + "Turn on the PA\n" + "Turn off the PA\n") +{ + if (strcmp(argv[0], "on") == 0) + mgr_cfg->master_power_act = 1; + else if (strcmp(argv[0], "off") == 0) + mgr_cfg->master_power_act = 0; + + if (strcmp(argv[1], "on") == 0) + mgr_cfg->slave_power_act = 1; + else if (strcmp(argv[1], "off") == 0) + mgr_cfg->slave_power_act = 0; + + if (strcmp(argv[2], "on") == 0) + mgr_cfg->pa_power_act = 1; + else if (strcmp(argv[2], "off") == 0) + mgr_cfg->pa_power_act = 0; + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_baud_action, cfg_mgr_pa_baud_action_cmd, + "power-reduce-transmitter <0-255>", + "Configure the power that we want to reduce in warning situation\n" + "Power baud transmition that we want to reduce in the PA\n") +{ + mgr_cfg->reduce_max_power = atoi(argv[0]); + + return CMD_SUCCESS; +} + +int sysmobts_mgr_vty_init(void) + +{ + 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); + + install_element(MGR_NODE, &cfg_mgr_board_temp_warn_cmd); + install_element(MGR_NODE, &cfg_mgr_board_temp_sever_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_temp_warn_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_temp_sever_cmd); + install_element(MGR_NODE, &cfg_mgr_pwr_action_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_baud_action_cmd); + + return 0; +} + +int sysmobts_mgr_parse_config(const char *config_file, + struct sbts2050_config_info *cfg) +{ + int rc; + + mgr_cfg = cfg; + + 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; +}
On Mon, May 05, 2014 at 04:14:54PM +0200, Alvaro Neira Ayuso wrote:
Added the vty support for configuring the parameter for using the OML report in manager when we have anomalous temperature.
Please try to have a more accurate and descriptive commit message here.
- rc = telnet_init(tall_msgb_ctx, NULL, 4252);
I just added this to PortNumber wiki pagein OpenBSC
From: Álvaro Neira Ayuso anayuso@sysmocom.de
This patch allows to configure the warning temperature threshold, the severe temperature threshold of the board and the PA and the actions like the relative value power that we want to reduce to the transmit power and the part that we want to switch off or not
Signed-off-by: Alvaro Neira Ayuso anayuso@sysmocom.de --- [changes in v9] * Changed the subject and the patch explanation.
doc/examples/osmobts-mgr.cfg | 30 +++ src/osmo-bts-sysmo/Makefile.am | 3 +- src/osmo-bts-sysmo/misc/sysmobts_mgr.c | 43 ++++- src/osmo-bts-sysmo/misc/sysmobts_mgr.h | 18 ++ src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c | 279 ++++++++++++++++++++++++++++ 5 files changed, 371 insertions(+), 2 deletions(-) create mode 100644 doc/examples/osmobts-mgr.cfg create mode 100644 src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c
diff --git a/doc/examples/osmobts-mgr.cfg b/doc/examples/osmobts-mgr.cfg new file mode 100644 index 0000000..3592202 --- /dev/null +++ b/doc/examples/osmobts-mgr.cfg @@ -0,0 +1,30 @@ +! +! SysmoMgr (0.3.0.141-33e5) configuration saved from vty +!! +! +log stderr + logging filter all 1 + logging color 1 + logging timestamp 0 + logging level all everything + logging level temp info + logging level fw info + logging level find info + logging level lglobal notice + logging level llapd notice + logging level linp notice + logging level lmux notice + logging level lmi notice + logging level lmib notice + logging level lsms notice +! +line vty + no login +! +config-mgr + temperature-warning board -30 50 + temperature-severe board -50 80 + temperature-warning pa -30 50 + temperature-severe pa -50 80 + power-action on on off + power-reduce-transmitter 4 diff --git a/src/osmo-bts-sysmo/Makefile.am b/src/osmo-bts-sysmo/Makefile.am index e9ba949..de70761 100644 --- a/src/osmo-bts-sysmo/Makefile.am +++ b/src/osmo-bts-sysmo/Makefile.am @@ -22,7 +22,8 @@ l1fwd_proxy_LDADD = $(top_builddir)/src/common/libbts.a $(COMMON_LDADD)
sysmobts_mgr_SOURCES = \ misc/sysmobts_mgr.c misc/sysmobts_misc.c \ - misc/sysmobts_par.c misc/sysmobts_nl.c utils.c + misc/sysmobts_par.c misc/sysmobts_nl.c utils.c \ + misc/sysmobts_mgr_vty.c sysmobts_mgr_LDADD = $(COMMON_LDADD)
sysmobts_util_SOURCES = misc/sysmobts_util.c misc/sysmobts_par.c diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c index 3148c7d..e45d41f 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c @@ -51,6 +51,24 @@ static int daemonize = 0; void *tall_mgr_ctx; static struct sbts2050_config_info confinfo;
+static struct sysmobts_mgr_instance sysmobts_mgr_inst = { + .config_file = "osmobts-mgr.cfg", +}; + +const char *sysmomgr_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 struct vty_app_info vty_info = { + .name = "SysmoMgr", + .version = PACKAGE_VERSION, + .go_parent_cb = mgr_vty_go_parent, + .is_config_node = mgr_vty_is_config_node, +}; + /* every 6 hours means 365*4 = 1460 EEprom writes per year (max) */ #define TEMP_TIMER_SECS (6 * 3600)
@@ -222,13 +240,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; @@ -245,6 +264,9 @@ static int parse_options(int argc, char **argv) case 'D': daemonize = 1; break; + case 'c': + sysmobts_mgr_inst.config_file = optarg; + break; default: return -1; } @@ -447,6 +469,25 @@ int main(int argc, char **argv) if (rc < 0) exit(2);
+ vty_info.copyright = sysmomgr_copyright; + vty_init(&vty_info); + logging_vty_add_cmds(&mgr_log_info); + + sysmobts_mgr_vty_init(); + + rc = sysmobts_mgr_parse_config(sysmobts_mgr_inst.config_file, + &confinfo); + 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 21f30a4..5e0d4a7 100644 --- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.h +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.h @@ -1,6 +1,9 @@ #ifndef _SYSMOBTS_MGR_H #define _SYSMOBTS_MGR_H
+#include <osmocom/vty/vty.h> +#include <osmocom/vty/command.h> + enum { DTEMP, DFW, @@ -14,4 +17,19 @@ enum {
#define SOCKET_PATH "/var/run/bts_oml"
+struct sbts2050_config_info; + +enum mgr_vty_node { + MGR_NODE = _LAST_OSMOVTY_NODE + 1, +}; + +enum node_type mgr_vty_go_parent(struct vty *vty); +int mgr_vty_is_config_node(struct vty *vty, int node); +int sysmobts_mgr_vty_init(void); +int sysmobts_mgr_parse_config(const char *config_file, + struct sbts2050_config_info *cfg); + +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 0000000..9a77a95 --- /dev/null +++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr_vty.c @@ -0,0 +1,279 @@ +/* (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" + +static struct sbts2050_config_info *mgr_cfg; + +enum node_type mgr_vty_go_parent(struct vty *vty) +{ + switch (vty->node) { + case MGR_NODE: + vty->node = CONFIG_NODE; + break; + default: + vty->node = CONFIG_NODE; + } + return vty->node; +} + +int mgr_vty_is_config_node(struct vty *vty, int node) +{ + switch (node) { + case MGR_NODE: + return 1; + default: + return 0; + } +} + +#define MGR_STR "Configure sysmobts-mgr\n" +#define MGR_TEMP_WARN_STR "Configure the temperature warning limits\n" +#define MGR_TEMP_SEVERE_STR "Configure the temperature severe limits\n" + +static struct cmd_node mgr_node = { + MGR_NODE, + "%s(config-mgr)# ", + 1, +}; + +DEFUN(cfg_mgr, cfg_mgr_cmd, + "config-mgr", + MGR_STR) +{ + vty->node = MGR_NODE; + return CMD_SUCCESS; +} + +DEFUN(show_mgr, show_mgr_cmd, "show mgr", + SHOW_STR "Display information about the mgr") +{ + vty_out(vty, " temperature-warning board Min:%d Max:%d%s", + mgr_cfg->temp_min_board_warn_limit, + mgr_cfg->temp_max_board_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-severe board Min:%d Max:%d%s", + mgr_cfg->temp_min_board_severe_limit, + mgr_cfg->temp_max_board_severe_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-warning pa Min:%d Max:%d%s", + mgr_cfg->temp_min_pa_warn_limit, + mgr_cfg->temp_max_pa_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-severe pa Min:%d Max:%d%s", + mgr_cfg->temp_min_pa_severe_limit, + mgr_cfg->temp_max_pa_severe_limit, + VTY_NEWLINE); + + vty_out(vty, " power-action Master:%s Slave:%s PA:%s%s", + mgr_cfg->master_power_act ? "on" : "off", + mgr_cfg->slave_power_act ? "on" : "off", + mgr_cfg->pa_power_act ? "on" : "off", + VTY_NEWLINE); + + vty_out(vty, " power-reduce-transmitter %d%s", + mgr_cfg->reduce_max_power, + VTY_NEWLINE); + return CMD_SUCCESS; +} + +static int config_write_mgr(struct vty *vty) +{ + vty_out(vty, "config-mgr%s", VTY_NEWLINE); + + vty_out(vty, " temperature-warning board %d %d%s", + mgr_cfg->temp_min_board_warn_limit, + mgr_cfg->temp_max_board_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-severe board %d %d%s", + mgr_cfg->temp_min_board_severe_limit, + mgr_cfg->temp_max_board_severe_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-warning pa %d %d%s", + mgr_cfg->temp_min_pa_warn_limit, + mgr_cfg->temp_max_pa_warn_limit, + VTY_NEWLINE); + + vty_out(vty, " temperature-severe pa %d %d%s", + mgr_cfg->temp_min_pa_severe_limit, + mgr_cfg->temp_max_pa_severe_limit, + VTY_NEWLINE); + + vty_out(vty, " power-action %s %s %s%s", + mgr_cfg->master_power_act ? "on" : "off", + mgr_cfg->slave_power_act ? "on" : "off", + mgr_cfg->pa_power_act ? "on" : "off", + VTY_NEWLINE); + + vty_out(vty, " power-reduce-transmitter %d%s", + mgr_cfg->reduce_max_power, + VTY_NEWLINE); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_board_temp_warn, cfg_mgr_board_temp_warn_cmd, + "temperature-warning board <-255-255> <-255-255>", + MGR_TEMP_WARN_STR + "Set warning temperature limits on the Board\n" + "Warning temperature low limit on the Board\n" + "Warning temperature high limit on the Board\n") +{ + mgr_cfg->temp_min_board_warn_limit = atoi(argv[0]); + mgr_cfg->temp_max_board_warn_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_board_temp_sever, cfg_mgr_board_temp_sever_cmd, + "temperature-severe board <-255-255> <-255-255>", + MGR_TEMP_SEVERE_STR + "Set severe temperature limits on the Board\n" + "Severe temperature low limit on the Board\n" + "Severe Temperature high limit on the Board\n") +{ + mgr_cfg->temp_min_board_severe_limit = atoi(argv[0]); + mgr_cfg->temp_max_board_severe_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_temp_warn, cfg_mgr_pa_temp_warn_cmd, + "temperature-warning pa <-255-255> <-255-255>", + MGR_TEMP_WARN_STR + "Set warning temperature limits on the PA\n" + "Warning temperature low limit on the PA\n" + "Warning temperature high limit on the PA\n") +{ + mgr_cfg->temp_min_pa_warn_limit = atoi(argv[0]); + mgr_cfg->temp_max_pa_warn_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_temp_sever, cfg_mgr_pa_temp_sever_cmd, + "temperature-severe pa <-255-255> <-255-255>", + MGR_TEMP_SEVERE_STR + "Set severe temperature limits on the Board\n" + "Severe temperature low limit on the PA\n" + "Severe temperature high limit on the PA\n") +{ + mgr_cfg->temp_min_pa_severe_limit = atoi(argv[0]); + mgr_cfg->temp_max_pa_severe_limit = atoi(argv[1]); + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pwr_action, cfg_mgr_pwr_action_cmd, + "power-action (on|off) (on|off) (on|off)", + "Configure which devices we want to turn on/off in several situation\n" + "Turn on the Master\n" + "Turn off the Master\n" + "Turn on the Slave\n" + "Turn off the Slave\n" + "Turn on the PA\n" + "Turn off the PA\n") +{ + if (strcmp(argv[0], "on") == 0) + mgr_cfg->master_power_act = 1; + else if (strcmp(argv[0], "off") == 0) + mgr_cfg->master_power_act = 0; + + if (strcmp(argv[1], "on") == 0) + mgr_cfg->slave_power_act = 1; + else if (strcmp(argv[1], "off") == 0) + mgr_cfg->slave_power_act = 0; + + if (strcmp(argv[2], "on") == 0) + mgr_cfg->pa_power_act = 1; + else if (strcmp(argv[2], "off") == 0) + mgr_cfg->pa_power_act = 0; + + return CMD_SUCCESS; +} + +DEFUN(cfg_mgr_pa_baud_action, cfg_mgr_pa_baud_action_cmd, + "power-reduce-transmitter <0-255>", + "Configure the power that we want to reduce in warning situation\n" + "Power baud transmition that we want to reduce in the PA\n") +{ + mgr_cfg->reduce_max_power = atoi(argv[0]); + + return CMD_SUCCESS; +} + +int sysmobts_mgr_vty_init(void) + +{ + 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); + + install_element(MGR_NODE, &cfg_mgr_board_temp_warn_cmd); + install_element(MGR_NODE, &cfg_mgr_board_temp_sever_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_temp_warn_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_temp_sever_cmd); + install_element(MGR_NODE, &cfg_mgr_pwr_action_cmd); + install_element(MGR_NODE, &cfg_mgr_pa_baud_action_cmd); + + return 0; +} + +int sysmobts_mgr_parse_config(const char *config_file, + struct sbts2050_config_info *cfg) +{ + int rc; + + mgr_cfg = cfg; + + 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; +}