[PATCH] osmo-bts[master]: Use oml-alert CTRL command for temp report

Max gerrit-no-reply at lists.osmocom.org
Thu Feb 23 16:24:45 UTC 2017


Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/1630

to look at the new patch set (#5).

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
---
M src/osmo-bts-sysmo/Makefile.am
M src/osmo-bts-sysmo/misc/sysmobts_mgr.c
M src/osmo-bts-sysmo/misc/sysmobts_mgr.h
M src/osmo-bts-sysmo/misc/sysmobts_mgr_temp.c
4 files changed, 65 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/30/1630/5

diff --git a/src/osmo-bts-sysmo/Makefile.am b/src/osmo-bts-sysmo/Makefile.am
index 8e39a3a..7b27e70 100644
--- a/src/osmo-bts-sysmo/Makefile.am
+++ b/src/osmo-bts-sysmo/Makefile.am
@@ -29,7 +29,7 @@
 		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 f126db2..1136b8f 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,10 +253,12 @@
 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)
@@ -294,7 +303,23 @@
 		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_ifd(&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 b393c38..88f4e24 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 @@
 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 34af2ab..2a15d2e 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,13 +187,24 @@
 }
 
 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),
@@ -206,14 +219,24 @@
 		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 @@
 		}
 	}
 
-	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;
 }

-- 
To view, visit https://gerrit.osmocom.org/1630
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: If29fbd0ab01fefc76e87b90cf1fbc81b2089ba76
Gerrit-PatchSet: 5
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: Max <msuraev at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at sysmocom.de>


More information about the gerrit-log mailing list