From 97db03a68246b7821de144b0ef41ad6ad7486610 Mon Sep 17 00:00:00 2001 From: Stefan Sperling Date: Thu, 14 Jun 2018 11:03:52 +0200 Subject: rename m3ua_example to sccp_demo_user The new name allows for more natural naming of variables in TTCN3 code when this program is used as a TTCN3 test component. Consider e.g. "SCCP_DEMO_USER_VTY" vs. "M3UA_EXAMPLE_VTY". Change-Id: I92b5e16e765a1ac36371a16933389903628f8dfe Related: OS#2666 --- examples/Makefile.am | 6 +- examples/m3ua_example.c | 237 ---------------------------------------------- examples/sccp_demo_user.c | 237 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 240 insertions(+), 240 deletions(-) delete mode 100644 examples/m3ua_example.c create mode 100644 examples/sccp_demo_user.c (limited to 'examples') diff --git a/examples/Makefile.am b/examples/Makefile.am index 6418aca..1993a01 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -4,8 +4,8 @@ AM_LDFLAGS=$(COVERAGE_LDFLAGS) noinst_HEADERS = internal.h -noinst_PROGRAMS = m3ua_example +noinst_PROGRAMS = sccp_demo_user -m3ua_example_SOURCES = m3ua_example.c sccp_test_server.c sccp_test_vty.c -m3ua_example_LDADD = $(top_builddir)/src/libosmo-sigtran.la \ +sccp_demo_user_SOURCES = sccp_demo_user.c sccp_test_server.c sccp_test_vty.c +sccp_demo_user_LDADD = $(top_builddir)/src/libosmo-sigtran.la \ $(LIBOSMOCORE_LIBS) $(LIBOSMOVTY_LIBS) diff --git a/examples/m3ua_example.c b/examples/m3ua_example.c deleted file mode 100644 index 2a99450..0000000 --- a/examples/m3ua_example.c +++ /dev/null @@ -1,237 +0,0 @@ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "internal.h" - -static struct osmo_sccp_instance *g_sccp; - -static struct osmo_sccp_instance *sua_server_helper(int local_port, const char *local_address, int local_pc, - int remote_port, const char *remote_address, int remote_pc) -{ - struct osmo_sccp_instance *sccp; - - sccp = osmo_sccp_simple_server(NULL, local_pc, OSMO_SS7_ASP_PROT_M3UA, local_port, local_address); - if (sccp == NULL) - return NULL; - - osmo_sccp_simple_server_add_clnt(sccp, OSMO_SS7_ASP_PROT_M3UA, "client", remote_pc, local_port, - remote_port, remote_address); - - return sccp; -} - -/*********************************************************************** - * Initialization - ***********************************************************************/ - -static void signal_handler(int signal) -{ - fprintf(stdout, "signal %d received\n", signal); - - switch (signal) { - case SIGUSR1: - talloc_report_full(osmo_sccp_get_ss7(g_sccp), stderr); - break; - case SIGUSR2: - talloc_report_full(NULL, stderr); - break; - } -} - -static const struct log_info_cat log_info_cat[] = { -}; - -static const struct log_info log_info = { - .cat = log_info_cat, - .num_cat = ARRAY_SIZE(log_info_cat), -}; - -static void init_logging(void) -{ - const int log_cats[] = { DLSS7, DLSUA, DLM3UA, DLSCCP, DLINP }; - unsigned int i; - void *tall_ctx = talloc_named_const(NULL, 1, "example"); - msgb_talloc_ctx_init(tall_ctx, 0); - osmo_init_logging2(tall_ctx, &log_info); - - for (i = 0; i < ARRAY_SIZE(log_cats); i++) - log_set_category_filter(osmo_stderr_target, log_cats[i], 1, LOGL_DEBUG); -} - -static struct vty_app_info vty_info = { - .name = "sccp-test", - .version = 0, -}; - -#define DEFAULT_LOCAL_PC -1 -#define DEFAULT_LOCAL_ADDRESS "127.0.0.2" -#define DEFAULT_LOCAL_PORT M3UA_PORT -#define DEFAULT_REMOTE_PC 23 -#define DEFAULT_REMOTE_ADDRESS "127.0.0.1" -#define DEFAULT_REMOTE_PORT M3UA_PORT - -static void usage(void) { - fprintf(stderr, "m3ua_example [-c] [-l LOCAL_ADDRESS[:LOCAL_PORT]]\n" - " [-r REMOTE_ADDRESS[:REMOTE_PORT]]\n" - " [-L LOCAL_POINT_CODE] [-R REMOTE_POINT_CODE]\n" - "Options:\n" - " -c: Run in client mode (default is server mode)\n" - " -l: local IP address and SCTP port (default is %s:%d)\n" - " -r: remote IP address and SCTP port (default is %s:%d)\n" - " -L: local point code (default is %d)\n" - " -R: remote point code (default is %d)\n", - DEFAULT_LOCAL_ADDRESS, DEFAULT_LOCAL_PORT, - DEFAULT_REMOTE_ADDRESS, DEFAULT_REMOTE_PORT, - DEFAULT_LOCAL_PC, DEFAULT_REMOTE_PC); - exit(1); -} - -static int is_decimal_string(const char *s) -{ - const char *p = s; - - if (*p == '\0') - return 0; - - while (*p) { - if (!isdigit(*p++)) - return 0; - } - return 1; -} - -static int parse_address_port(char **address, int *port, const char *arg) -{ - char *s, *colon; - - s = strdup(arg); - OSMO_ASSERT(s); - - colon = strrchr(s, ':'); - if (colon) { - char *portstr = colon + 1; - *colon = '\0'; - if (*portstr == '\0') { - fprintf(stderr, "missing port number after : in '%s'\n", arg); - free(s); - return 1; - } - if (!is_decimal_string(portstr)) { - fprintf(stderr, "invalid port number: '%s'\n", portstr); - free(s); - return 1; - } - *port = atoi(portstr); - } - - *address = s; - return 0; -} - -int main(int argc, char **argv) -{ - bool client = false; - int rc, ch; - char *local_address = DEFAULT_LOCAL_ADDRESS; - int local_port = DEFAULT_LOCAL_PORT; - int local_pc = DEFAULT_LOCAL_PC; - char *remote_address = DEFAULT_REMOTE_ADDRESS; - int remote_port = DEFAULT_LOCAL_PORT; - int remote_pc = DEFAULT_REMOTE_PC; - - while ((ch = getopt(argc, argv, "cl:r:p:L:R:")) != -1) { - switch (ch) { - case 'c': - client = true; - break; - case 'l': - if (parse_address_port(&local_address, &local_port, optarg)) - exit(1); - break; - case 'r': - if (parse_address_port(&remote_address, &remote_port, optarg)) - exit(1); - break; - case 'L': - if (!is_decimal_string(optarg)) { - fprintf(stderr, "invalid decimal point code: '%s'\n", optarg); - exit(1); - } - local_pc = atoi(optarg); - break; - case 'R': - if (!is_decimal_string(optarg)) { - fprintf(stderr, "invalid decimal point code: '%s'\n", optarg); - exit(1); - } - remote_pc = atoi(optarg); - break; - default: - usage(); - } - } - argc -= optind; - argv += optind; - - if (argc != 0) - usage(); - - talloc_enable_leak_report_full(); - - signal(SIGUSR1, &signal_handler); - signal(SIGUSR2, &signal_handler); - - init_logging(); - osmo_ss7_init(); - osmo_fsm_log_addr(false); - vty_init(&vty_info); - osmo_ss7_vty_init_asp(NULL); - osmo_sccp_vty_init(); - - rc = telnet_init_dynif(NULL, NULL, vty_get_bind_addr(), 2324+client); - if (rc < 0) { - perror("Error binding VTY port"); - exit(1); - } - - if (client) { - g_sccp = osmo_sccp_simple_client(NULL, "client", local_pc, OSMO_SS7_ASP_PROT_M3UA, - local_port, local_address, remote_port, remote_address); - if (g_sccp == NULL) { - perror("Could not create SCCP client"); - exit (1); - } - sccp_test_user_vty_install(g_sccp, OSMO_SCCP_SSN_BSSAP); - } else { - g_sccp = sua_server_helper(local_port, local_address, local_pc, - remote_port, remote_address, remote_pc); - if (g_sccp == NULL) { - perror("Could not create SCCP server"); - exit(1); - } - sccp_test_server_init(g_sccp); - } - - while (1) { - osmo_select_main(0); - } -} diff --git a/examples/sccp_demo_user.c b/examples/sccp_demo_user.c new file mode 100644 index 0000000..f0b1a3e --- /dev/null +++ b/examples/sccp_demo_user.c @@ -0,0 +1,237 @@ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "internal.h" + +static struct osmo_sccp_instance *g_sccp; + +static struct osmo_sccp_instance *sua_server_helper(int local_port, const char *local_address, int local_pc, + int remote_port, const char *remote_address, int remote_pc) +{ + struct osmo_sccp_instance *sccp; + + sccp = osmo_sccp_simple_server(NULL, local_pc, OSMO_SS7_ASP_PROT_M3UA, local_port, local_address); + if (sccp == NULL) + return NULL; + + osmo_sccp_simple_server_add_clnt(sccp, OSMO_SS7_ASP_PROT_M3UA, "client", remote_pc, local_port, + remote_port, remote_address); + + return sccp; +} + +/*********************************************************************** + * Initialization + ***********************************************************************/ + +static void signal_handler(int signal) +{ + fprintf(stdout, "signal %d received\n", signal); + + switch (signal) { + case SIGUSR1: + talloc_report_full(osmo_sccp_get_ss7(g_sccp), stderr); + break; + case SIGUSR2: + talloc_report_full(NULL, stderr); + break; + } +} + +static const struct log_info_cat log_info_cat[] = { +}; + +static const struct log_info log_info = { + .cat = log_info_cat, + .num_cat = ARRAY_SIZE(log_info_cat), +}; + +static void init_logging(void) +{ + const int log_cats[] = { DLSS7, DLSUA, DLM3UA, DLSCCP, DLINP }; + unsigned int i; + void *tall_ctx = talloc_named_const(NULL, 1, "example"); + msgb_talloc_ctx_init(tall_ctx, 0); + osmo_init_logging2(tall_ctx, &log_info); + + for (i = 0; i < ARRAY_SIZE(log_cats); i++) + log_set_category_filter(osmo_stderr_target, log_cats[i], 1, LOGL_DEBUG); +} + +static struct vty_app_info vty_info = { + .name = "sccp-demo-user", + .version = 0, +}; + +#define DEFAULT_LOCAL_PC -1 +#define DEFAULT_LOCAL_ADDRESS "127.0.0.2" +#define DEFAULT_LOCAL_PORT M3UA_PORT +#define DEFAULT_REMOTE_PC 23 +#define DEFAULT_REMOTE_ADDRESS "127.0.0.1" +#define DEFAULT_REMOTE_PORT M3UA_PORT + +static void usage(void) { + fprintf(stderr, "sccp_demo_user [-c] [-l LOCAL_ADDRESS[:LOCAL_PORT]]\n" + " [-r REMOTE_ADDRESS[:REMOTE_PORT]]\n" + " [-L LOCAL_POINT_CODE] [-R REMOTE_POINT_CODE]\n" + "Options:\n" + " -c: Run in client mode (default is server mode)\n" + " -l: local IP address and SCTP port (default is %s:%d)\n" + " -r: remote IP address and SCTP port (default is %s:%d)\n" + " -L: local point code (default is %d)\n" + " -R: remote point code (default is %d)\n", + DEFAULT_LOCAL_ADDRESS, DEFAULT_LOCAL_PORT, + DEFAULT_REMOTE_ADDRESS, DEFAULT_REMOTE_PORT, + DEFAULT_LOCAL_PC, DEFAULT_REMOTE_PC); + exit(1); +} + +static int is_decimal_string(const char *s) +{ + const char *p = s; + + if (*p == '\0') + return 0; + + while (*p) { + if (!isdigit(*p++)) + return 0; + } + return 1; +} + +static int parse_address_port(char **address, int *port, const char *arg) +{ + char *s, *colon; + + s = strdup(arg); + OSMO_ASSERT(s); + + colon = strrchr(s, ':'); + if (colon) { + char *portstr = colon + 1; + *colon = '\0'; + if (*portstr == '\0') { + fprintf(stderr, "missing port number after : in '%s'\n", arg); + free(s); + return 1; + } + if (!is_decimal_string(portstr)) { + fprintf(stderr, "invalid port number: '%s'\n", portstr); + free(s); + return 1; + } + *port = atoi(portstr); + } + + *address = s; + return 0; +} + +int main(int argc, char **argv) +{ + bool client = false; + int rc, ch; + char *local_address = DEFAULT_LOCAL_ADDRESS; + int local_port = DEFAULT_LOCAL_PORT; + int local_pc = DEFAULT_LOCAL_PC; + char *remote_address = DEFAULT_REMOTE_ADDRESS; + int remote_port = DEFAULT_LOCAL_PORT; + int remote_pc = DEFAULT_REMOTE_PC; + + while ((ch = getopt(argc, argv, "cl:r:p:L:R:")) != -1) { + switch (ch) { + case 'c': + client = true; + break; + case 'l': + if (parse_address_port(&local_address, &local_port, optarg)) + exit(1); + break; + case 'r': + if (parse_address_port(&remote_address, &remote_port, optarg)) + exit(1); + break; + case 'L': + if (!is_decimal_string(optarg)) { + fprintf(stderr, "invalid decimal point code: '%s'\n", optarg); + exit(1); + } + local_pc = atoi(optarg); + break; + case 'R': + if (!is_decimal_string(optarg)) { + fprintf(stderr, "invalid decimal point code: '%s'\n", optarg); + exit(1); + } + remote_pc = atoi(optarg); + break; + default: + usage(); + } + } + argc -= optind; + argv += optind; + + if (argc != 0) + usage(); + + talloc_enable_leak_report_full(); + + signal(SIGUSR1, &signal_handler); + signal(SIGUSR2, &signal_handler); + + init_logging(); + osmo_ss7_init(); + osmo_fsm_log_addr(false); + vty_init(&vty_info); + osmo_ss7_vty_init_asp(NULL); + osmo_sccp_vty_init(); + + rc = telnet_init_dynif(NULL, NULL, vty_get_bind_addr(), 2324+client); + if (rc < 0) { + perror("Error binding VTY port"); + exit(1); + } + + if (client) { + g_sccp = osmo_sccp_simple_client(NULL, "client", local_pc, OSMO_SS7_ASP_PROT_M3UA, + local_port, local_address, remote_port, remote_address); + if (g_sccp == NULL) { + perror("Could not create SCCP client"); + exit (1); + } + sccp_test_user_vty_install(g_sccp, OSMO_SCCP_SSN_BSSAP); + } else { + g_sccp = sua_server_helper(local_port, local_address, local_pc, + remote_port, remote_address, remote_pc); + if (g_sccp == NULL) { + perror("Could not create SCCP server"); + exit(1); + } + sccp_test_server_init(g_sccp); + } + + while (1) { + osmo_select_main(0); + } +} -- cgit v1.2.3