diff options
author | Max <msuraev@sysmocom.de> | 2022-11-23 16:01:07 +0300 |
---|---|---|
committer | msuraev <msuraev@sysmocom.de> | 2022-11-30 18:47:32 +0000 |
commit | a9ddb834e6db51cfc68b8b2c08ae522303b9579c (patch) | |
tree | 080ab8f27296c03d3ef9f5c730dfcabcb31c7cd8 /utils | |
parent | f4854f39c6e1a7e130b4a33a15da1044801e0d1c (diff) |
osmo-ns-dummy: add ctrl interface
It's handy for rate_ctr tests with follow-up patches.
Related: OS#5671
Change-Id: If6e06d9433e438b92f1ed1ef0f892308e031779b
Diffstat (limited to 'utils')
-rw-r--r-- | utils/Makefile.am | 1 | ||||
-rw-r--r-- | utils/osmo-ns-dummy.c | 27 |
2 files changed, 25 insertions, 3 deletions
diff --git a/utils/Makefile.am b/utils/Makefile.am index 47c5a78c..712f01a2 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -35,6 +35,7 @@ osmo_ns_dummy_SOURCES = osmo-ns-dummy.c osmo-ns-dummy-vty.c osmo_ns_dummy_LDADD = $(LDADD) $(TALLOC_LIBS) \ $(top_builddir)/src/gb/libosmogb.la \ $(top_builddir)/src/vty/libosmovty.la \ + $(top_builddir)/src/ctrl/libosmoctrl.la \ $(top_builddir)/src/gsm/libosmogsm.la osmo_ns_dummy_CFLAGS = $(TALLOC_CFLAGS) endif diff --git a/utils/osmo-ns-dummy.c b/utils/osmo-ns-dummy.c index eabe0085..a85775ee 100644 --- a/utils/osmo-ns-dummy.c +++ b/utils/osmo-ns-dummy.c @@ -8,7 +8,8 @@ #include <osmocom/core/select.h> #include <osmocom/core/application.h> #include <osmocom/core/stats.h> - +#include <osmocom/ctrl/control_if.h> +#include <osmocom/ctrl/control_vty.h> #include <osmocom/gprs/gprs_ns2.h> #include <osmocom/vty/vty.h> #include <osmocom/vty/telnet_interface.h> @@ -27,6 +28,7 @@ static bool quit = false; static bool config_given = false; static bool daemonize = false; static int vty_port = 0; +static int ctrl_port = 0; static char *config_file = NULL; struct gprs_ns2_inst *g_nsi; @@ -51,6 +53,7 @@ static void print_help(void) " -V --version Print version\n" " -D --daemonize Fork the process into a background daemon\n" " -p --vty-port PORT Set the vty port to listen on.\n" + " -r --ctrl-port PORT Set the ctrl port to listen on.\n" "\nVTY reference generation:\n" " --vty-ref-mode MODE VTY reference generation mode (e.g. 'expert').\n" " --vty-ref-xml Generate the VTY reference XML output and exit.\n" @@ -93,12 +96,13 @@ static void handle_options(int argc, char **argv) { "version", 0, 0, 'V' }, { "daemonize", 0, 0, 'D' }, { "vty-port", 1, 0, 'p' }, + { "ctrl-port", 1, 0, 'r' }, { "vty-ref-mode", 1, &long_option, 1 }, { "vty-ref-xml", 0, &long_option, 2 }, { 0, 0, 0, 0 } }; - c = getopt_long(argc, argv, "hc:p:VD", + c = getopt_long(argc, argv, "hc:p:r:VD", long_options, &option_idx); if (c == -1) break; @@ -120,7 +124,14 @@ static void handle_options(int argc, char **argv) case 'p': vty_port = atoi(optarg); if (vty_port < 0 || vty_port > 65535) { - fprintf(stderr, "Invalid port %d given!\n", vty_port); + fprintf(stderr, "Invalid VTY port %d given!\n", vty_port); + exit(1); + } + break; + case 'r': + ctrl_port = atoi(optarg); + if (ctrl_port < 0 || ctrl_port > 65535) { + fprintf(stderr, "Invalid CTRL port %d given!\n", ctrl_port); exit(1); } break; @@ -223,6 +234,7 @@ extern int nsdummy_vty_init(void); int main (int argc, char *argv[]) { void *ctx = tall_nsdummy_ctx = talloc_named_const(NULL, 0, "osmo-ns-dummy"); + struct ctrl_handle *ctrl; int rc = 0; osmo_init_logging2(ctx, &log_info); @@ -235,6 +247,7 @@ int main (int argc, char *argv[]) vty_info.tall_ctx = ctx; vty_init(&vty_info); + ctrl_vty_init(ctx); logging_vty_add_cmds(); osmo_stats_vty_add_cmds(); osmo_talloc_vty_add_cmds(); @@ -266,6 +279,14 @@ int main (int argc, char *argv[]) exit(1); } + if (ctrl_port > 0) { + ctrl = ctrl_interface_setup_dynip(NULL, ctrl_vty_get_bind_addr(), ctrl_port, NULL); + if (!ctrl) { + fprintf(stderr, "Failed to initialize control interface. Exiting.\n"); + exit(1); + } + } + signal(SIGINT, sighandler); signal(SIGTERM, sighandler); signal(SIGPIPE, sighandler); |