[PATCH] osmo-trx[master]: Add initial support for logging, vty, ctrl

Pau Espin Pedrol gerrit-no-reply at lists.osmocom.org
Tue Feb 20 19:37:12 UTC 2018


Hello Jenkins Builder,

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

    https://gerrit.osmocom.org/6619

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

Add initial support for logging, vty, ctrl

Up to this point, the logging system, vty and ctrl are initialized and
can be used fine, though they don't have a lot of use yet.

Depends on libosmocore Change-Id Ib79cdb62d45d8c78445c7b064e58eb7e9faeccf9

Change-Id: I08982c37b4f873966304b3cfb38a10ee86eb3dad
---
M CommonLibs/Makefile.am
A CommonLibs/debug.c
A CommonLibs/debug.h
A CommonLibs/trx_vty.c
A CommonLibs/trx_vty.h
M Transceiver52M/Makefile.am
M Transceiver52M/osmo-trx.cpp
M configure.ac
M contrib/jenkins.sh
A doc/examples/osmo-trx-limesdr.cfg
10 files changed, 295 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-trx refs/changes/19/6619/3

diff --git a/CommonLibs/Makefile.am b/CommonLibs/Makefile.am
index fa0b285..843bc38 100644
--- a/CommonLibs/Makefile.am
+++ b/CommonLibs/Makefile.am
@@ -23,6 +23,7 @@
 
 AM_CPPFLAGS = $(STD_DEFINES_AND_INCLUDES)
 AM_CXXFLAGS = -Wall -O3 -g -lpthread
+AM_CFLAGS = $(LIBOSMOCORE_CFLAGS) $(LIBOSMOCTRL_CFLAGS) $(LIBOSMOVTY_CFLAGS)
 
 EXTRA_DIST = \
 	example.config \
@@ -36,7 +37,9 @@
 	Sockets.cpp \
 	Threads.cpp \
 	Timeval.cpp \
-	Logger.cpp
+	Logger.cpp \
+	trx_vty.c \
+	debug.c
 
 noinst_HEADERS = \
 	BitVector.h \
@@ -47,4 +50,6 @@
 	Threads.h \
 	Timeval.h \
 	Vector.h \
-	Logger.h
+	Logger.h \
+	trx_vty.h \
+	debug.h
diff --git a/CommonLibs/debug.c b/CommonLibs/debug.c
new file mode 100644
index 0000000..3c5f6ba
--- /dev/null
+++ b/CommonLibs/debug.c
@@ -0,0 +1,18 @@
+#include <osmocom/core/logging.h>
+#include <osmocom/core/utils.h>
+#include "debug.h"
+
+/* default categories */
+static const struct log_info_cat default_categories[] = {
+	[DTRX] = {
+		.name = "DTRX",
+		.description = "Transciever",
+		.color = NULL,
+		.enabled = 1, .loglevel = LOGL_NOTICE,
+	},
+};
+
+const struct log_info log_info = {
+	.cat = default_categories,
+	.num_cat = ARRAY_SIZE(default_categories),
+};
diff --git a/CommonLibs/debug.h b/CommonLibs/debug.h
new file mode 100644
index 0000000..408efc9
--- /dev/null
+++ b/CommonLibs/debug.h
@@ -0,0 +1,8 @@
+#pragma once
+
+extern const struct log_info log_info;
+
+/* Debug Areas of the code */
+enum {
+	DTRX,
+};
diff --git a/CommonLibs/trx_vty.c b/CommonLibs/trx_vty.c
new file mode 100644
index 0000000..6193635
--- /dev/null
+++ b/CommonLibs/trx_vty.c
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2012-2017 sysmocom - s.f.m.c. GmbH
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <string.h>
+#include <stdint.h>
+#include <inttypes.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <osmocom/core/talloc.h>
+#include <osmocom/core/utils.h>
+#include <osmocom/core/rate_ctr.h>
+
+#include <osmocom/vty/command.h>
+#include <osmocom/vty/vty.h>
+#include <osmocom/vty/misc.h>
+
+#include "trx_vty.h"
+#include "../config.h"
+
+static struct trx_ctx* g_trx_ctx;
+
+struct trx_ctx *trx_from_vty(struct vty *v)
+{
+        /* It can't hurt to force callers to continue to pass the vty instance
+         * to this function, in case we'd like to retrieve the global
+         * trx instance from the vty at some point in the future. But
+         * until then, just return the global pointer, which should have been
+         * initialized by trx_vty_init().
+         */
+        OSMO_ASSERT(g_trx_ctx);
+        return g_trx_ctx;
+}
+
+enum trx_vty_node {
+	TRX_NODE = _LAST_OSMOVTY_NODE + 1,
+	APN_NODE,
+};
+/* TRX Node */
+
+static struct cmd_node trx_node = {
+	TRX_NODE,
+	"%s(config-trx)# ",
+	1,
+};
+
+DEFUN(cfg_trx, cfg_trx_cmd,
+	"trx",
+	"Configure the TRX\n")
+{
+	struct trx_ctx *trx = trx_from_vty(vty);
+
+	if (!trx)
+		return CMD_WARNING;
+
+	vty->node = TRX_NODE;
+
+	return CMD_SUCCESS;
+}
+
+DEFUN(cfg_bind_ip, cfg_bind_ip_cmd,
+	"bind-ip A.B.C.D",
+	"Set the IP address for the local GTP bind\n"
+	"IPv4 Address\n")
+{
+	struct trx_ctx *trx = trx_from_vty(vty);
+
+	trx->cfg.bind_addr = talloc_strdup(trx, argv[0]);
+
+	return CMD_SUCCESS;
+}
+
+static int config_write_trx(struct vty *vty)
+{
+	struct trx_ctx *trx = trx_from_vty(vty);
+
+	vty_out(vty, "trx%s", VTY_NEWLINE);
+	if (trx->cfg.bind_addr)
+		vty_out(vty, " bind-ip %s%s", trx->cfg.bind_addr, VTY_NEWLINE);
+
+	return CMD_SUCCESS;
+}
+
+DEFUN(show_trx, show_trx_cmd,
+	"show trx",
+	SHOW_STR "Display information on the TRX\n")
+{
+	struct trx_ctx *trx = trx_from_vty(vty);
+
+	vty_out(vty, "TRX: Bound to %s%s", trx->cfg.bind_addr, VTY_NEWLINE);
+
+	return CMD_SUCCESS;
+}
+
+static int trx_vty_is_config_node(struct vty *vty, int node)
+{
+	switch (node) {
+	case TRX_NODE:
+		return 1;
+	default:
+		return 0;
+	}
+}
+
+static int trx_vty_go_parent(struct vty *vty)
+{
+	switch (vty->node) {
+	case TRX_NODE:
+		vty->node = CONFIG_NODE;
+		vty->index = NULL;
+		vty->index_sub = NULL;
+		break;
+	default:
+		OSMO_ASSERT(0);
+	}
+
+	return vty->node;
+}
+
+static const char trx_copyright[] =
+	"Copyright (C) 2017-2018 by sysmocom s.f.m.c. GmbH <info at sysmocom.de>\r\n"
+	"Copyright (C) 2013 Thomas Tsou <tom at tsou.cc>\r\n"
+	"License AGPLv3+: GNU AGPL version 3 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";
+
+struct vty_app_info g_vty_info = {
+	.name		= "OsmoTRX",
+	.version	= PACKAGE_VERSION,
+	.copyright	= trx_copyright,
+	.go_parent_cb	= trx_vty_go_parent,
+	.is_config_node	= trx_vty_is_config_node,
+};
+
+int trx_vty_init(struct trx_ctx* trx)
+{
+	g_trx_ctx = trx;
+	install_element_ve(&show_trx_cmd);
+
+	install_element(CONFIG_NODE, &cfg_trx_cmd);
+
+	install_node(&trx_node, config_write_trx);
+	install_element(TRX_NODE, &cfg_bind_ip_cmd);
+
+	return 0;
+}
diff --git a/CommonLibs/trx_vty.h b/CommonLibs/trx_vty.h
new file mode 100644
index 0000000..56135cc
--- /dev/null
+++ b/CommonLibs/trx_vty.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#include <osmocom/vty/command.h>
+
+extern struct vty_app_info g_vty_info;
+
+struct trx_ctx {
+	struct {
+		char* bind_addr;
+	} cfg;
+};
+
+int trx_vty_init(struct trx_ctx* trx);
diff --git a/Transceiver52M/Makefile.am b/Transceiver52M/Makefile.am
index 21104dc..3c1b86c 100644
--- a/Transceiver52M/Makefile.am
+++ b/Transceiver52M/Makefile.am
@@ -22,7 +22,7 @@
 include $(top_srcdir)/Makefile.common
 
 AM_CPPFLAGS = -Wall $(STD_DEFINES_AND_INCLUDES) -I${srcdir}/common
-AM_CXXFLAGS = -lpthread $(LIBOSMOCORE_CFLAGS)
+AM_CXXFLAGS = -lpthread $(LIBOSMOCORE_CFLAGS) $(LIBOSMOCTRL_CFLAGS) $(LIBOSMOVTY_CFLAGS)
 
 SUBDIRS = arm x86
 
@@ -93,7 +93,9 @@
 	$(GSM_LA) \
 	$(COMMON_LA) \
 	$(FFTWF_LIBS) \
-	$(LIBOSMOCORE_LIBS)
+	$(LIBOSMOCORE_LIBS) \
+	$(LIBOSMOCTRL_LIBS) \
+	$(LIBOSMOVTY_LIBS)
 
 if USRP1
 libtransceiver_la_SOURCES += USRPDevice.cpp
diff --git a/Transceiver52M/osmo-trx.cpp b/Transceiver52M/osmo-trx.cpp
index 40269e1..4fff8ad 100644
--- a/Transceiver52M/osmo-trx.cpp
+++ b/Transceiver52M/osmo-trx.cpp
@@ -40,8 +40,19 @@
 #include <osmocom/core/talloc.h>
 #include <osmocom/core/application.h>
 #include <osmocom/core/msgb.h>
+#include <osmocom/core/stats.h>
+#include <osmocom/vty/logging.h>
+#include <osmocom/vty/ports.h>
+#include <osmocom/vty/misc.h>
+#include <osmocom/vty/telnet_interface.h>
+#include <osmocom/ctrl/control_vty.h>
+#include <osmocom/ctrl/ports.h>
+#include <osmocom/ctrl/control_if.h>
+#include <osmocom/vty/stats.h>
 #include "convolve.h"
 #include "convert.h"
+#include "trx_vty.h"
+#include "debug.h"
 }
 
 /* Samples-per-symbol for downlink path
@@ -65,12 +76,14 @@
 #define DEFAULT_TRX_PORT	5700
 #define DEFAULT_TRX_IP		"127.0.0.1"
 #define DEFAULT_CHANS		1
+#define DEFAULT_CONFIG_FILE	"/etc/osmocom/osmo-trx.cfg"
 
 struct trx_config {
 	std::string log_level;
 	std::string local_addr;
 	std::string remote_addr;
 	std::string dev_args;
+	char* config_file;
 	unsigned port;
 	unsigned tx_sps;
 	unsigned rx_sps;
@@ -93,6 +106,8 @@
 volatile bool gshutdown = false;
 
 static void *tall_trx_ctx;
+static struct trx_ctx *g_trx_ctx;
+static struct ctrl_handle *g_ctrlh;
 
 /* Setup configuration values
  *     Don't query the existence of the Log.Level because it's a
@@ -327,6 +342,7 @@
 	config->log_level = "NOTICE";
 	config->local_addr = DEFAULT_TRX_IP;
 	config->remote_addr = DEFAULT_TRX_IP;
+	config->config_file = DEFAULT_CONFIG_FILE;
 	config->port = DEFAULT_TRX_PORT;
 	config->tx_sps = DEFAULT_TX_SPS;
 	config->rx_sps = DEFAULT_RX_SPS;
@@ -345,7 +361,7 @@
 	config->tx_paths = std::vector<std::string>(DEFAULT_CHANS, "");
 	config->rx_paths = std::vector<std::string>(DEFAULT_CHANS, "");
 
-	while ((option = getopt(argc, argv, "ha:l:i:j:p:c:dmxgfo:s:b:r:A:R:Set:y:z:")) != -1) {
+	while ((option = getopt(argc, argv, "ha:l:i:j:p:c:dmxgfo:s:b:r:A:R:Set:y:z:C:")) != -1) {
 		switch (option) {
 		case 'h':
 			print_help();
@@ -417,6 +433,9 @@
 		case 'z':
 			config->rx_paths = comma_delimited_to_vector(optarg);
 			rx_path_set = true;
+			break;
+		case 'C':
+			config->config_file = optarg;
 			break;
 		default:
 			print_help();
@@ -497,10 +516,15 @@
 	Transceiver *trx = NULL;
 	RadioDevice::InterfaceType iface = RadioDevice::NORMAL;
 	struct trx_config config;
+	int rc;
 
 	tall_trx_ctx = talloc_named_const(NULL, 0, "OsmoTRX");
 	msgb_talloc_ctx_init(tall_trx_ctx, 0);
+	g_vty_info.tall_ctx = tall_trx_ctx;
+
 	setup_signal_handlers();
+
+	g_trx_ctx = talloc_zero(tall_trx_ctx, struct trx_ctx);
 
 #ifdef HAVE_SSE3
 	printf("Info: SSE3 support compiled in");
@@ -529,7 +553,35 @@
 	convolve_init();
 	convert_init();
 
+	osmo_init_logging(&log_info);
+	osmo_stats_init(tall_trx_ctx);
+	vty_init(&g_vty_info);
+	ctrl_vty_init(tall_trx_ctx);
+	trx_vty_init(g_trx_ctx);
+
+	logging_vty_add_cmds();
+	osmo_talloc_vty_add_cmds();
+	osmo_stats_vty_add_cmds();
+
 	handle_options(argc, argv, &config);
+
+	rate_ctr_init(tall_trx_ctx);
+
+	rc = vty_read_config_file(config.config_file, NULL);
+	if (rc < 0) {
+		fprintf(stderr, "Failed to open config file: '%s'\n", config.config_file);
+		exit(2);
+	}
+
+	rc = telnet_init_dynif(tall_trx_ctx, NULL, vty_get_bind_addr(), OSMO_VTY_PORT_TRX);
+	if (rc < 0)
+		exit(1);
+
+	g_ctrlh = ctrl_interface_setup(NULL, OSMO_CTRL_PORT_TRX, NULL);
+	if (!g_ctrlh) {
+		fprintf(stderr, "Failed to create CTRL interface.\n");
+		exit(1);
+	}
 
 	if (config.sched_rr != -1) {
 		if (set_sched_rr(config.sched_rr) < 0)
@@ -580,7 +632,7 @@
 		  << chans << " channel(s)" << std::endl;
 
 	while (!gshutdown)
-		sleep(1);
+		osmo_select_main(0);
 
 shutdown:
 	std::cout << "Shutting down transceiver..." << std::endl;
diff --git a/configure.ac b/configure.ac
index cba4a0c..916cf18 100644
--- a/configure.ac
+++ b/configure.ac
@@ -42,6 +42,7 @@
 AC_SUBST([RELMAKE])
 
 AM_PROG_AS
+AC_PROG_CC
 AC_PROG_CXX
 AX_CXX_COMPILE_STDCXX_11
 AC_PROG_LN_S
@@ -74,6 +75,8 @@
 AC_C_BIGENDIAN
 
 PKG_CHECK_MODULES(LIBOSMOCORE, libosmocore >= 0.10.0)
+PKG_CHECK_MODULES(LIBOSMOVTY, libosmovty >= 0.3.0)
+PKG_CHECK_MODULES(LIBOSMOCTRL, libosmoctrl >= 0.10.0)
 
 AC_ARG_WITH(usrp1, [
     AS_HELP_STRING([--with-usrp1],
diff --git a/contrib/jenkins.sh b/contrib/jenkins.sh
index 123ab10..5f1eed9 100755
--- a/contrib/jenkins.sh
+++ b/contrib/jenkins.sh
@@ -58,6 +58,11 @@
 
 osmo-build-dep.sh libosmocore "" --disable-doxygen
 
+verify_value_string_arrays_are_terminated.py $(find . -name "*.[hc]")
+
+export PKG_CONFIG_PATH="$inst/lib/pkgconfig:$PKG_CONFIG_PATH"
+export LD_LIBRARY_PATH="$inst/lib"
+
 set +x
 echo
 echo
diff --git a/doc/examples/osmo-trx-limesdr.cfg b/doc/examples/osmo-trx-limesdr.cfg
new file mode 100644
index 0000000..e27eaa6
--- /dev/null
+++ b/doc/examples/osmo-trx-limesdr.cfg
@@ -0,0 +1,21 @@
+log stderr
+  logging filter all 1
+  logging color 1
+  logging print category 1
+  logging timestamp 1
+  logging level all debug
+!
+line vty
+ no login
+!
+trx
+ bind-ip 127.0.0.1
+! remote-ip 127.0.0.1
+! base-port 5700
+! gprs mode gprs
+! rt-prio -1
+! tx-samples-per-symbol 4
+! rx-samples-per-symbol 1
+! channel 0
+!  tx-path ""
+!  rx-path ""

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

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I08982c37b4f873966304b3cfb38a10ee86eb3dad
Gerrit-PatchSet: 3
Gerrit-Project: osmo-trx
Gerrit-Branch: master
Gerrit-Owner: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>


More information about the gerrit-log mailing list