aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax <msuraev@sysmocom.de>2017-01-19 13:02:36 +0100
committerMax <msuraev@sysmocom.de>2017-02-24 15:03:37 +0100
commit4acc98e68a6ee0f3ab39ac4d7bcf090b55969825 (patch)
tree9a9b1485e4ea930bc0dbc8c995f6a08141504fc4
parent758522947f2937a1d17b6c3988b03abc80bd0051 (diff)
Use oml-alert CTRL command for temp report
Send temperature reports via OML alert facility exposed by CTRL protocol. Change-Id: If29fbd0ab01fefc76e87b90cf1fbc81b2089ba76 Related: OS#1615
-rw-r--r--src/osmo-bts-sysmo/Makefile.am2
-rw-r--r--src/osmo-bts-sysmo/misc/sysmobts_mgr.c29
-rw-r--r--src/osmo-bts-sysmo/misc/sysmobts_mgr.h5
-rw-r--r--src/osmo-bts-sysmo/misc/sysmobts_mgr_temp.c42
4 files changed, 65 insertions, 13 deletions
diff --git a/src/osmo-bts-sysmo/Makefile.am b/src/osmo-bts-sysmo/Makefile.am
index 8e39a3a2..7b27e704 100644
--- a/src/osmo-bts-sysmo/Makefile.am
+++ b/src/osmo-bts-sysmo/Makefile.am
@@ -29,7 +29,7 @@ sysmobts_mgr_SOURCES = \
misc/sysmobts_mgr_temp.c \
misc/sysmobts_mgr_calib.c \
eeprom.c
-sysmobts_mgr_LDADD = $(LIBGPS_LIBS) $(LIBOSMOCORE_LIBS) $(LIBOSMOVTY_LIBS) $(LIBOSMOABIS_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOCTRL_LIBS) $(top_builddir)/src/common/libbts.a $(COMMON_LDADD)
+sysmobts_mgr_LDADD = $(LIBGPS_LIBS) $(top_builddir)/src/common/libbts.a $(COMMON_LDADD)
sysmobts_util_SOURCES = misc/sysmobts_util.c misc/sysmobts_par.c eeprom.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 f126db2d..e9c59bca 100644
--- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.c
+++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.c
@@ -21,6 +21,8 @@
*/
#include <stdint.h>
+#include <stdlib.h>
+#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
@@ -28,14 +30,19 @@
#include <limits.h>
#include <sys/signal.h>
#include <sys/stat.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/application.h>
#include <osmocom/core/timer.h>
+#include <osmocom/core/socket.h>
#include <osmocom/core/msgb.h>
#include <osmocom/vty/telnet_interface.h>
#include <osmocom/vty/logging.h>
#include <osmocom/vty/ports.h>
+#include <osmocom/ctrl/control_if.h>
+#include <osmocom/ctrl/ports.h>
#include "misc/sysmobts_misc.h"
#include "misc/sysmobts_mgr.h"
@@ -246,11 +253,13 @@ static int mgr_log_init(void)
int main(int argc, char **argv)
{
int rc;
-
+ struct ctrl_connection *ccon;
tall_mgr_ctx = talloc_named_const(NULL, 1, "bts manager");
msgb_talloc_ctx_init(tall_mgr_ctx, 0);
+ srand(time(NULL));
+
mgr_log_init();
if (classify_bts() != 0)
exit(2);
@@ -294,7 +303,23 @@ int main(int argc, char **argv)
exit(3);
/* Initialize the temperature control */
- sysmobts_mgr_temp_init(&manager);
+ ccon = osmo_ctrl_conn_alloc(tall_mgr_ctx, NULL);
+ rc = -1;
+ if (ccon) {
+ ccon->write_queue.bfd.data = ccon;
+ rc = osmo_sock_init_ofd(&ccon->write_queue.bfd, AF_INET,
+ SOCK_STREAM, IPPROTO_TCP,
+ "localhost", OSMO_CTRL_PORT_BTS,
+ OSMO_SOCK_F_CONNECT);
+ }
+ if (rc < 0)
+ LOGP(DLCTRL, LOGL_ERROR, "Can't connect to CTRL @ localhost:%u\n",
+ OSMO_CTRL_PORT_BTS);
+ else
+ LOGP(DLCTRL, LOGL_NOTICE, "CTRL connected to locahost:%u\n",
+ OSMO_CTRL_PORT_BTS);
+
+ sysmobts_mgr_temp_init(&manager, ccon);
if (sysmobts_mgr_calib_init(&manager) != 0)
exit(3);
diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr.h b/src/osmo-bts-sysmo/misc/sysmobts_mgr.h
index b393c389..88f4e245 100644
--- a/src/osmo-bts-sysmo/misc/sysmobts_mgr.h
+++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr.h
@@ -3,7 +3,7 @@
#include <osmocom/vty/vty.h>
#include <osmocom/vty/command.h>
-
+#include <osmocom/ctrl/control_if.h>
#include <osmocom/core/select.h>
#include <osmocom/core/timer.h>
@@ -108,7 +108,8 @@ struct sysmobts_mgr_instance {
int sysmobts_mgr_vty_init(void);
int sysmobts_mgr_parse_config(struct sysmobts_mgr_instance *mgr);
int sysmobts_mgr_nl_init(void);
-int sysmobts_mgr_temp_init(struct sysmobts_mgr_instance *mgr);
+int sysmobts_mgr_temp_init(struct sysmobts_mgr_instance *mgr,
+ struct ctrl_connection *ctrl);
const char *sysmobts_mgr_temp_get_state(enum sysmobts_temp_state state);
diff --git a/src/osmo-bts-sysmo/misc/sysmobts_mgr_temp.c b/src/osmo-bts-sysmo/misc/sysmobts_mgr_temp.c
index 34af2abc..2a15d2ec 100644
--- a/src/osmo-bts-sysmo/misc/sysmobts_mgr_temp.c
+++ b/src/osmo-bts-sysmo/misc/sysmobts_mgr_temp.c
@@ -28,6 +28,8 @@
#include <osmocom/core/timer.h>
#include <osmocom/core/utils.h>
+#include <stdlib.h>
+
static struct sysmobts_mgr_instance *s_mgr;
static struct osmo_timer_list temp_ctrl_timer;
@@ -185,14 +187,25 @@ static void execute_critical_act(struct sysmobts_mgr_instance *manager)
}
static void sysmobts_mgr_temp_handle(struct sysmobts_mgr_instance *manager,
- int critical, int warning)
+ struct ctrl_connection *ctrl, int critical,
+ int warning)
{
- int new_state = next_state(manager->state, critical, warning);
+ int new_state = next_state(manager->state, critical, warning), rc;
+ struct ctrl_cmd *rep;
+ bool send = false;
/* Nothing changed */
if (new_state < 0)
return;
+ rep = ctrl_cmd_create(tall_mgr_ctx, CTRL_TYPE_SET);
+ if (!rep) {
+ LOGP(DTEMP, LOGL_ERROR, "OML alert creation failed.\n");
+ } else {
+ rep->id = talloc_asprintf(rep, "%d", rand());
+ rep->variable = "oml-alert";
+ }
+
LOGP(DTEMP, LOGL_NOTICE, "Moving from state %s to %s.\n",
get_value_string(state_names, manager->state),
get_value_string(state_names, new_state));
@@ -206,14 +219,24 @@ static void sysmobts_mgr_temp_handle(struct sysmobts_mgr_instance *manager,
break;
case STATE_WARNING:
execute_warning_act(manager);
+ rep->value = "Temperature Warning";
+ send = true;
break;
case STATE_CRITICAL:
execute_critical_act(manager);
+ rep->value = "Temperature Critical";
+ send = true;
break;
};
+
+ if (send) {
+ rc = ctrl_cmd_send(&ctrl->write_queue, rep);
+ LOGP(DTEMP, LOGL_ERROR, "OML alert sent: %d\n", rc);
+ }
+ talloc_free(rep);
}
-static void temp_ctrl_check()
+static void temp_ctrl_check(struct ctrl_connection *ctrl)
{
int rc;
int warn_thresh_passed = 0;
@@ -275,20 +298,23 @@ static void temp_ctrl_check()
}
}
- sysmobts_mgr_temp_handle(s_mgr, crit_thresh_passed, warn_thresh_passed);
+ sysmobts_mgr_temp_handle(s_mgr, ctrl, crit_thresh_passed,
+ warn_thresh_passed);
}
-static void temp_ctrl_check_cb(void *unused)
+static void temp_ctrl_check_cb(void *ctrl)
{
- temp_ctrl_check();
+ temp_ctrl_check(ctrl);
/* Check every two minutes? XXX make it configurable! */
osmo_timer_schedule(&temp_ctrl_timer, 2 * 60, 0);
}
-int sysmobts_mgr_temp_init(struct sysmobts_mgr_instance *mgr)
+int sysmobts_mgr_temp_init(struct sysmobts_mgr_instance *mgr,
+ struct ctrl_connection *ctrl)
{
s_mgr = mgr;
temp_ctrl_timer.cb = temp_ctrl_check_cb;
- temp_ctrl_check_cb(NULL);
+ temp_ctrl_timer.data = ctrl;
+ temp_ctrl_check_cb(ctrl);
return 0;
}