From c0315368084d91d0fbec4d6a6e29c72ac94e255b Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 14 Apr 2017 20:16:10 +0200 Subject: SCCP: Add VTY interface for SCCP Change-Id: I100daaa947dbab6a4528c4e9fbd0d30790288f63 --- include/osmocom/sigtran/sccp_sap.h | 2 + src/Makefile.am | 2 +- src/osmo_ss7_vty.c | 4 +- src/sccp_internal.h | 2 + src/sccp_scoc.c | 39 ++++++++++ src/sccp_vty.c | 149 +++++++++++++++++++++++++++++++++++++ src/xua_internal.h | 4 + tests/ss7/Makefile.am | 4 +- tests/xua/Makefile.am | 4 +- 9 files changed, 202 insertions(+), 8 deletions(-) create mode 100644 src/sccp_vty.c diff --git a/include/osmocom/sigtran/sccp_sap.h b/include/osmocom/sigtran/sccp_sap.h index fd25752..f378e5c 100644 --- a/include/osmocom/sigtran/sccp_sap.h +++ b/include/osmocom/sigtran/sccp_sap.h @@ -227,6 +227,8 @@ struct osmo_ss7_instance; struct osmo_sccp_instance; struct osmo_sccp_user; +void osmo_sccp_vty_init(void); + struct osmo_sccp_instance * osmo_sccp_instance_create(struct osmo_ss7_instance *ss7, void *priv); void osmo_sccp_instance_destroy(struct osmo_sccp_instance *inst); diff --git a/src/Makefile.am b/src/Makefile.am index 8e52792..217f2f7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -30,6 +30,6 @@ libosmo_sigtran_la_SOURCES = sccp_sap.c sua.c m3ua.c xua_msg.c sccp_helpers.c \ sccp2sua.c sccp_scrc.c sccp_sclc.c sccp_scoc.c \ sccp_user.c xua_rkm.c xua_default_lm_fsm.c \ osmo_ss7.c osmo_ss7_hmrt.c xua_asp_fsm.c xua_as_fsm.c \ - osmo_ss7_vty.c + osmo_ss7_vty.c sccp_vty.c libosmo_sigtran_la_LDFLAGS = -version-info $(LIBVERSION) -no-undefined -export-symbols-regex '^osmo_' libosmo_sigtran_la_LIBADD = $(LIBOSMOCORE_LIBS) $(LIBOSMONETIF_LIBS) $(LIBSCTP_LIBS) diff --git a/src/osmo_ss7_vty.c b/src/osmo_ss7_vty.c index b08a456..c2ad25c 100644 --- a/src/osmo_ss7_vty.c +++ b/src/osmo_ss7_vty.c @@ -35,9 +35,7 @@ #include #include -#define CS7_STR "ITU-T Signaling System 7\n" -#define PC_STR "Point Code\n" -#define INST_STR "An instance of the SS7 stack\n" +#include "xua_internal.h" /*********************************************************************** * Core CS7 Configuration diff --git a/src/sccp_internal.h b/src/sccp_internal.h index c35ef4b..17dda13 100644 --- a/src/sccp_internal.h +++ b/src/sccp_internal.h @@ -87,3 +87,5 @@ int sccp_sclc_user_sap_down(struct osmo_sccp_user *scu, struct osmo_prim_hdr *op struct msgb *sccp_msgb_alloc(const char *name); struct osmo_fsm sccp_scoc_fsm; + +void sccp_scoc_show_connections(struct vty *vty, struct osmo_sccp_instance *inst); diff --git a/src/sccp_scoc.c b/src/sccp_scoc.c index 8621e6d..6d9916b 100644 --- a/src/sccp_scoc.c +++ b/src/sccp_scoc.c @@ -1649,3 +1649,42 @@ void sccp_scoc_flush_connections(struct osmo_sccp_instance *inst) llist_for_each_entry_safe(conn, conn2, &inst->connections, list) conn_destroy(conn); } + +#include + +static void vty_show_connection(struct vty *vty, struct sccp_connection *conn) +{ + struct osmo_ss7_instance *s7i = conn->inst->ss7; + struct osmo_sccp_addr *remote_addr; + uint32_t local_pc; + + if (conn->user->pc_valid) + local_pc = conn->user->pc; + else + local_pc = s7i->cfg.primary_pc; + + if (conn->incoming) + remote_addr = &conn->calling_addr; + else + remote_addr = &conn->called_addr; + + vty_out(vty, "%c %06x %3u %7s ", conn->incoming ? 'I' : 'O', + conn->conn_id, conn->user->ssn, + osmo_ss7_pointcode_print(s7i, local_pc)); + vty_out(vty, "%16s %06x %3u %7s%s", + osmo_fsm_inst_state_name(conn->fi), conn->remote_ref, remote_addr->ssn, + osmo_ss7_pointcode_print(s7i, conn->remote_pc), + VTY_NEWLINE); +} + +void sccp_scoc_show_connections(struct vty *vty, struct osmo_sccp_instance *inst) +{ + struct sccp_connection *conn; + + vty_out(vty, "I Local Conn. Remote %s", VTY_NEWLINE); + vty_out(vty, "O Ref SSN PC State Ref SSN PC %s", VTY_NEWLINE); + vty_out(vty, "- ------ --- ------- ---------------- ------ --- -------%s", VTY_NEWLINE); + + llist_for_each_entry(conn, &inst->connections, list) + vty_show_connection(vty, conn); +} diff --git a/src/sccp_vty.c b/src/sccp_vty.c new file mode 100644 index 0000000..626fefb --- /dev/null +++ b/src/sccp_vty.c @@ -0,0 +1,149 @@ +/* Core SS7 Instance/Linkset/Link/AS/ASP VTY Interface */ + +/* (C) 2015-2017 by Harald Welte + * 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 . + * + */ + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include "xua_internal.h" +#include "sccp_internal.h" + +static void show_user(struct vty *vty, struct osmo_sccp_user *user) +{ + struct osmo_sccp_instance *sccp = user->inst; + + if (user->pc_valid) + vty_out(vty, "SSN %3u %7s : %s%s", user->ssn, + osmo_ss7_pointcode_print(sccp->ss7, user->pc), + user->name, VTY_NEWLINE); + else + vty_out(vty, "SSN %3u ANY : %s%s", user->ssn, user->name, VTY_NEWLINE); +} + +DEFUN(show_sccp_users, show_sccp_users_cmd, + "show cs7 instance <0-15> sccp users", + SHOW_STR CS7_STR INST_STR INST_STR + "Signaling Connection Control Part\n" + "Show List of SCCP Users registered\n") +{ + int id = atoi(argv[0]); + struct osmo_ss7_instance *inst; + struct osmo_sccp_instance *sccp; + struct osmo_sccp_user *scu; + + inst = osmo_ss7_instance_find(id); + if (!inst) { + vty_out(vty, "No SS7 instance %d found%s", id, VTY_NEWLINE); + return CMD_WARNING; + } + + sccp = inst->sccp; + if (!sccp) { + vty_out(vty, "SS7 instance %d has no SCCP%s", id, VTY_NEWLINE); + return CMD_WARNING; + }; + + llist_for_each_entry(scu, &sccp->users, list) + show_user(vty, scu); + + return CMD_SUCCESS; +} + +DEFUN(show_sccp_user_ssn, show_sccp_user_ssn_cmd, + "show cs7 instance <0-15> sccp ssn <0-65535>", + SHOW_STR CS7_STR INST_STR INST_STR + "Signaling Connection Control Part\n" + "Show List of SCCP Users registered\n") +{ + int id = atoi(argv[0]); + int ssn = atoi(argv[1]); + struct osmo_ss7_instance *inst; + struct osmo_sccp_instance *sccp; + struct osmo_sccp_user *scu; + + inst = osmo_ss7_instance_find(id); + if (!inst) { + vty_out(vty, "No SS7 instance %d found%s", id, VTY_NEWLINE); + return CMD_WARNING; + } + + sccp = inst->sccp; + if (!sccp) { + vty_out(vty, "SS7 instance %d has no SCCP%s", id, VTY_NEWLINE); + return CMD_WARNING; + }; + + scu = sccp_user_find(sccp, ssn, 0); + if (!scu) { + vty_out(vty, "Can't find SCCP User in instance %d%s", id, VTY_NEWLINE); + return CMD_WARNING; + } + + show_user(vty, scu); + + return CMD_SUCCESS; +} + +DEFUN(show_sccp_connections, show_sccp_connections_cmd, + "show cs7 instance <0-15> sccp connections", + SHOW_STR CS7_STR INST_STR INST_STR + "Signaling Connection Control Part\n" + "Show List of SCCP Users registered\n") +{ + int id = atoi(argv[0]); + struct osmo_ss7_instance *inst; + struct osmo_sccp_instance *sccp; + + inst = osmo_ss7_instance_find(id); + if (!inst) { + vty_out(vty, "No SS7 instance %d found%s", id, VTY_NEWLINE); + return CMD_WARNING; + } + + sccp = inst->sccp; + if (!sccp) { + vty_out(vty, "SS7 instance %d has no SCCP%s", id, VTY_NEWLINE); + return CMD_WARNING; + }; + + sccp_scoc_show_connections(vty, sccp); + + return CMD_SUCCESS; +} + +void osmo_sccp_vty_init(void) +{ + install_element_ve(&show_sccp_users_cmd); + install_element_ve(&show_sccp_user_ssn_cmd); + install_element_ve(&show_sccp_connections_cmd); +} diff --git a/src/xua_internal.h b/src/xua_internal.h index b291703..31c941e 100644 --- a/src/xua_internal.h +++ b/src/xua_internal.h @@ -60,3 +60,7 @@ void xua_asp_send_xlm_prim_simple(struct osmo_ss7_asp *asp, extern struct osmo_fsm xua_default_lm_fsm; extern const struct value_string m3ua_rkm_reg_status_vals[]; extern const struct value_string m3ua_rkm_dereg_status_vals[]; + +#define CS7_STR "ITU-T Signaling System 7\n" +#define PC_STR "Point Code\n" +#define INST_STR "An instance of the SS7 stack\n" diff --git a/tests/ss7/Makefile.am b/tests/ss7/Makefile.am index bc81915..3b6cb2c 100644 --- a/tests/ss7/Makefile.am +++ b/tests/ss7/Makefile.am @@ -1,9 +1,9 @@ AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -Wall -AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS) +AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOVTY_CFLAGS) AM_LDFLAGS = -static LDADD = $(top_builddir)/src/libosmo-sigtran.la \ - $(LIBOSMOCORE_LIBS) $(LIBOSMONETIF_LIBS) $(LIBSCTP_LIBS) + $(LIBOSMOCORE_LIBS) $(LIBOSMOVTY_LIBS) $(LIBOSMONETIF_LIBS) $(LIBSCTP_LIBS) EXTRA_DIST = ss7_test.ok ss7_test.err diff --git a/tests/xua/Makefile.am b/tests/xua/Makefile.am index 8a75e6c..c6a9955 100644 --- a/tests/xua/Makefile.am +++ b/tests/xua/Makefile.am @@ -1,9 +1,9 @@ AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -Wall -AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS) +AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOVTY_CFLAGS) AM_LDFLAGS = -static LDADD = $(top_builddir)/src/libosmo-sigtran.la \ - $(LIBOSMOCORE_LIBS) $(LIBOSMONETIF_LIBS) $(LIBSCTP_LIBS) + $(LIBOSMOCORE_LIBS) $(LIBOSMOVTY_LIBS) $(LIBOSMONETIF_LIBS) $(LIBSCTP_LIBS) EXTRA_DIST = xua_test.ok -- cgit v1.2.3