add tests/vty: VTY UI transcript testing
Add ss7_asp_vty_test, a shim test program with the sole purpose of exposing the cs7 VTY nodes. Add ss7_asp_test.vty, transcript for verifying VTY nodes using above program. Add --enable-external-tests to configure. Run jenkins.sh with --enable-external-tests. Change-Id: I6a28684fa24d6e7de568623444297028eba2ab8c
This commit is contained in:
parent
66f6ed06e1
commit
4a3e8f5b19
16
configure.ac
16
configure.ac
|
@ -113,6 +113,21 @@ AS_IF([test "x$with_systemdsystemunitdir" != "xno"],
|
|||
[AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])])
|
||||
AM_CONDITIONAL([HAVE_SYSTEMD], [test "x$with_systemdsystemunitdir" != "xno"])
|
||||
|
||||
AC_ARG_ENABLE([external_tests],
|
||||
AC_HELP_STRING([--enable-external-tests],
|
||||
[Include the VTY/CTRL tests in make check [default=no]]),
|
||||
[enable_ext_tests="$enableval"],[enable_ext_tests="no"])
|
||||
if test "x$enable_ext_tests" = "xyes" ; then
|
||||
AM_PATH_PYTHON
|
||||
AC_CHECK_PROG(OSMOTESTEXT_CHECK,osmo_verify_transcript_vty.py,yes)
|
||||
if test "x$OSMOTESTEXT_CHECK" != "xyes" ; then
|
||||
AC_MSG_ERROR([Please install git://osmocom.org/python/osmo-python-tests to run the VTY/CTRL tests.])
|
||||
fi
|
||||
fi
|
||||
AC_MSG_CHECKING([whether to enable VTY/CTRL tests])
|
||||
AC_MSG_RESULT([$enable_ext_tests])
|
||||
AM_CONDITIONAL(ENABLE_EXT_TESTS, test "x$enable_ext_tests" = "xyes")
|
||||
|
||||
AC_MSG_RESULT([CFLAGS="$CFLAGS"])
|
||||
AC_MSG_RESULT([CPPFLAGS="$CPPFLAGS"])
|
||||
|
||||
|
@ -133,6 +148,7 @@ AC_OUTPUT(
|
|||
tests/m2ua/Makefile
|
||||
tests/xua/Makefile
|
||||
tests/ss7/Makefile
|
||||
tests/vty/Makefile
|
||||
examples/Makefile
|
||||
stp/Makefile
|
||||
doc/Makefile
|
||||
|
|
|
@ -36,9 +36,10 @@ echo
|
|||
set -x
|
||||
|
||||
autoreconf --install --force
|
||||
./configure --enable-sanitize --enable-werror
|
||||
./configure --enable-sanitize --enable-werror --enable-external-tests
|
||||
$MAKE $PARALLEL_MAKE
|
||||
$MAKE distcheck \
|
||||
DISTCHECK_CONFIGURE_FLAGS="--enable-external-tests" \
|
||||
$MAKE distcheck \
|
||||
|| cat-testlogs.sh
|
||||
|
||||
osmo-clean-workspace.sh
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
SUBDIRS = xua sccp mtp m2ua ss7
|
||||
SUBDIRS = xua sccp mtp m2ua ss7 vty
|
||||
|
||||
# The `:;' works around a Bash 3.2 bug when the output is not writeable.
|
||||
$(srcdir)/package.m4: $(top_srcdir)/configure.ac
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
AM_CPPFLAGS = $(all_includes) -I$(top_srcdir)/include -Wall
|
||||
AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOVTY_CFLAGS)
|
||||
|
||||
AM_LDFLAGS = -static
|
||||
LDADD = $(top_builddir)/src/libosmo-sigtran.la \
|
||||
$(LIBOSMOCORE_LIBS) $(LIBOSMOVTY_LIBS) $(LIBOSMONETIF_LIBS) $(LIBSCTP_LIBS)
|
||||
|
||||
EXTRA_DIST = ss7_asp_test.vty
|
||||
|
||||
noinst_PROGRAMS = ss7_asp_vty_test
|
||||
|
||||
ss7_asp_vty_test_SOURCES = ss7_asp_vty_test.c
|
||||
|
||||
if ENABLE_EXT_TESTS
|
||||
ext-tests:
|
||||
$(MAKE) vty-test
|
||||
else
|
||||
ext-tests:
|
||||
echo "Not running python-based external tests (determined at configure-time)"
|
||||
endif
|
||||
|
||||
# To update the VTY script from current application behavior,
|
||||
# pass -u to osmo_verify_transcript_vty.py by doing:
|
||||
# make vty-test U=-u
|
||||
vty-test: ss7_asp_vty_test
|
||||
osmo_verify_transcript_vty.py -v \
|
||||
-p 42043 \
|
||||
-r "$(builddir)/ss7_asp_vty_test" \
|
||||
$(U) $(srcdir)/ss7_asp_*.vty
|
||||
|
||||
check-local:
|
||||
$(MAKE) $(AM_MAKEFLAGS) ext-tests
|
|
@ -0,0 +1,350 @@
|
|||
ss7_asp_vty_test> list
|
||||
... !show cs7
|
||||
show cs7 instance <0-15> users
|
||||
show cs7 (sua|m3ua|ipa) [<0-65534>]
|
||||
show cs7 instance <0-15> asp
|
||||
show cs7 instance <0-15> as (active|all|m3ua|sua)
|
||||
show cs7 instance <0-15> sccp users
|
||||
show cs7 instance <0-15> sccp ssn <0-65535>
|
||||
show cs7 instance <0-15> sccp connections
|
||||
... !show cs7
|
||||
|
||||
ss7_asp_vty_test> enable
|
||||
ss7_asp_vty_test# list
|
||||
... !show cs7
|
||||
show cs7 instance <0-15> users
|
||||
show cs7 (sua|m3ua|ipa) [<0-65534>]
|
||||
show cs7 instance <0-15> asp
|
||||
show cs7 instance <0-15> as (active|all|m3ua|sua)
|
||||
show cs7 instance <0-15> sccp users
|
||||
show cs7 instance <0-15> sccp ssn <0-65535>
|
||||
show cs7 instance <0-15> sccp connections
|
||||
... !show cs7
|
||||
|
||||
ss7_asp_vty_test# show ?
|
||||
...
|
||||
cs7 ITU-T Signaling System 7
|
||||
...
|
||||
|
||||
ss7_asp_vty_test# show cs7 ?
|
||||
instance An instance of the SS7 stack
|
||||
sua SCCP User Adaptation
|
||||
m3ua MTP3 User Adaptation
|
||||
ipa IPA Multiplex (SCCP Lite)
|
||||
|
||||
ss7_asp_vty_test# show cs7 m3ua ?
|
||||
[<0-65534>] Port Number
|
||||
|
||||
ss7_asp_vty_test# show cs7 instance ?
|
||||
<0-15> An instance of the SS7 stack
|
||||
|
||||
ss7_asp_vty_test# show cs7 instance 0 ?
|
||||
users User Table
|
||||
asp Application Server Process (ASP)
|
||||
as Application Server (AS)
|
||||
sccp Signaling Connection Control Part
|
||||
|
||||
ss7_asp_vty_test# show cs7 instance 0 as ?
|
||||
active Display all active ASs
|
||||
all Display all ASs (default)
|
||||
m3ua Display all m3ua ASs
|
||||
sua Display all SUA ASs
|
||||
|
||||
ss7_asp_vty_test# show cs7 instance 0 sccp ?
|
||||
users Show List of SCCP Users registered
|
||||
ssn Show List of SCCP Users registered
|
||||
connections Show List of SCCP Users registered
|
||||
|
||||
ss7_asp_vty_test# show cs7 instance 0 sccp ssn ?
|
||||
<0-65535>
|
||||
|
||||
ss7_asp_vty_test# configure terminal
|
||||
ss7_asp_vty_test(config)# cs7 instance 0
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# list
|
||||
...
|
||||
description .TEXT
|
||||
network-indicator (international | national | reserved | spare)
|
||||
point-code POINT_CODE
|
||||
point-code format <1-24> [<1-23>] [<1-22>]
|
||||
point-code format default
|
||||
point-code delimiter (default|dash)
|
||||
xua rkm routing-key-allocation (static-only|dynamic-permitted)
|
||||
asp NAME <0-65535> <0-65535> (sua|m3ua|ipa)
|
||||
no asp NAME
|
||||
as NAME (sua|m3ua|ipa)
|
||||
no as NAME
|
||||
show cs7 instance <0-15> sccp-addressbook
|
||||
sccp-address NAME
|
||||
no sccp-address NAME
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# ?
|
||||
...
|
||||
description Save human-readable description of the object
|
||||
network-indicator Configure the Network Indicator
|
||||
point-code Configure the local Point Code
|
||||
xua SIGTRAN xxxUA related
|
||||
asp Configure Application Server Process
|
||||
no Negate a command or set its defaults
|
||||
as Configure an Application Server
|
||||
sccp-address Create/Modify an SCCP addressbook entry
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# description ?
|
||||
TEXT Text until the end of the line
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# network-indicator ?
|
||||
international International Network
|
||||
national National Network
|
||||
reserved Reserved Network
|
||||
spare Spare Network
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# point-code ?
|
||||
POINT_CODE Point Code
|
||||
format Configure Point Code Format
|
||||
delimiter Configure Point Code Delimiter
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# point-code format ?
|
||||
<1-24> Length of first PC component
|
||||
default Default Point Code Format (3.8.3)
|
||||
ss7_asp_vty_test(config-cs7)# point-code format 1 ?
|
||||
[<1-23>] Length of second PC component
|
||||
ss7_asp_vty_test(config-cs7)# point-code format 1 1 ?
|
||||
[<1-22>] Length of third PC component
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# point-code delimiter ?
|
||||
default Use dot as delimiter
|
||||
dash User dash as delimiter
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# xua ?
|
||||
rkm Routing Key Management
|
||||
ss7_asp_vty_test(config-cs7)# xua rkm ?
|
||||
routing-key-allocation Routing Key Management Allocation Policy
|
||||
ss7_asp_vty_test(config-cs7)# xua rkm routing-key-allocation ?
|
||||
static-only Only static (pre-confgured) Routing Keys permitted
|
||||
dynamic-permitted Dynamically allocate Routing Keys for what ASPs request
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# asp ?
|
||||
NAME Name of ASP
|
||||
ss7_asp_vty_test(config-cs7)# asp foo ?
|
||||
<0-65535> Remote SCTP port number
|
||||
ss7_asp_vty_test(config-cs7)# asp foo 0 ?
|
||||
<0-65535> Local SCTP port number
|
||||
ss7_asp_vty_test(config-cs7)# asp foo 0 0 ?
|
||||
sua SCCP User Adaptation
|
||||
m3ua MTP3 User Adaptation
|
||||
ipa IPA Multiplex (SCCP Lite)
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# as ?
|
||||
NAME Name of the Application Server
|
||||
ss7_asp_vty_test(config-cs7)# as foo ?
|
||||
sua SCCP User Adaptation
|
||||
m3ua MTP3 User Adaptation
|
||||
ipa IPA Multiplex (SCCP Lite)
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# sccp-address ?
|
||||
NAME Name of the SCCP Address
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# no ?
|
||||
asp Disable Application Server Process
|
||||
as Disable Application Server
|
||||
sccp-address Delete an SCCP addressbook entry
|
||||
ss7_asp_vty_test(config-cs7)# no asp ?
|
||||
NAME Name of ASP
|
||||
ss7_asp_vty_test(config-cs7)# no as ?
|
||||
NAME Name of AS
|
||||
ss7_asp_vty_test(config-cs7)# no sccp-address ?
|
||||
NAME Name of the SCCP Address
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# sccp-address foo
|
||||
ss7_asp_vty_test(config-cs7-sccpaddr)# list
|
||||
...
|
||||
no point-code
|
||||
no subsystem-number
|
||||
no global-title
|
||||
routing-indicator (GT|PC|IP)
|
||||
point-code POINT_CODE
|
||||
subsystem-number <0-4294967295>
|
||||
global-title
|
||||
ss7_asp_vty_test(config-cs7-sccpaddr)# ?
|
||||
...
|
||||
no Negate a command or set its defaults
|
||||
routing-indicator Add Routing Indicator
|
||||
point-code Add point-code Number
|
||||
subsystem-number Add Subsystem Number
|
||||
global-title Add/Modify Global Title
|
||||
|
||||
ss7_asp_vty_test(config-cs7-sccpaddr)# point-code 1.2.3
|
||||
|
||||
ss7_asp_vty_test(config-cs7-sccpaddr)# do show cs7 instance 0 sccp addressbook
|
||||
% Unknown command.
|
||||
ss7_asp_vty_test(config-cs7-sccpaddr)# exit
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# sccp-address foobarfoobarfoobarfoobarfoobarfoobar
|
||||
Error: SCCP address name to long: 'foobarfoobarfoobarfoobarfoobarfoobar'
|
||||
% Command incomplete.
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# exit
|
||||
ss7_asp_vty_test(config)# cs7 instance 1
|
||||
ss7_asp_vty_test(config-cs7)# sccp-address foo
|
||||
Error: SCCP address name already used in ss7 instance 0: 'foo'
|
||||
% Command incomplete.
|
||||
ss7_asp_vty_test(config-cs7)# sccp-address bar
|
||||
ss7_asp_vty_test(config-cs7-sccpaddr)# point-code 1.2.3
|
||||
ss7_asp_vty_test(config-cs7-sccpaddr)# exit
|
||||
ss7_asp_vty_test(config-cs7)# exit
|
||||
ss7_asp_vty_test(config)# no cs7 instance 1
|
||||
% Unknown command.
|
||||
|
||||
ss7_asp_vty_test(config)# cs7 instance 0
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# asp my-asp 12345 54321 m3ua
|
||||
ss7_asp_vty_test(config-cs7-asp)# list
|
||||
...
|
||||
description .TEXT
|
||||
remote-ip A.B.C.D
|
||||
local-ip A.B.C.D
|
||||
qos-class <0-255>
|
||||
block
|
||||
shutdown
|
||||
|
||||
ss7_asp_vty_test(config-cs7-asp)# ?
|
||||
...
|
||||
description Save human-readable description of the object
|
||||
remote-ip Specify Remote IP Address of ASP
|
||||
local-ip Specify Local IP Address from which to contact ASP
|
||||
qos-class Specify QoS Class of ASP
|
||||
block Allows a SCTP Association with ASP, but doesn't let it become active
|
||||
shutdown Terminates SCTP association; New associations will be rejected
|
||||
|
||||
ss7_asp_vty_test(config-cs7-asp)# remote-ip 127.0.0.200
|
||||
ss7_asp_vty_test(config-cs7-asp)# local-ip 127.0.0.100
|
||||
ss7_asp_vty_test(config-cs7-asp)# do show cs7 instance 0 asp
|
||||
Effect Primary
|
||||
ASP Name AS Name State Type Rmt Port Remote IP Addr SCTP
|
||||
------------ ------------ ------------- ---- -------- --------------- ----------
|
||||
my-asp ? uninitialized m3ua 12345 127.0.0.200
|
||||
ss7_asp_vty_test(config-cs7-asp)# exit
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# as my-ass m3ua
|
||||
ss7_asp_vty_test(config-cs7-as)# list
|
||||
...
|
||||
description .TEXT
|
||||
asp NAME
|
||||
no asp NAME
|
||||
traffic-mode (broadcast | loadshare | roundrobin | override)
|
||||
recovery-timeout <1-2000>
|
||||
qos-class <0-255>
|
||||
routing-key RCONTEXT DPC
|
||||
routing-key RCONTEXT DPC si (aal2|bicc|b-isup|h248|isup|sat-isup|sccp|tup)
|
||||
routing-key RCONTEXT DPC ssn SSN
|
||||
routing-key RCONTEXT DPC si (aal2|bicc|b-isup|h248|isup|sat-isup|sccp|tup) ssn SSN
|
||||
point-code override dpc PC
|
||||
|
||||
ss7_asp_vty_test(config-cs7-as)# ?
|
||||
...
|
||||
description Save human-readable description of the object
|
||||
asp Specify that a given ASP is part of this AS
|
||||
no Negate a command or set its defaults
|
||||
traffic-mode Specifies traffic mode of operation of the ASP within the AS
|
||||
recovery-timeout Specifies the recovery timeout value in milliseconds
|
||||
qos-class Specity QoS Class of AS
|
||||
routing-key Define a routing key
|
||||
point-code Point Code Specific Features
|
||||
|
||||
ss7_asp_vty_test(config-cs7-as)# no ?
|
||||
asp Specify ASP to be removed from this AS
|
||||
|
||||
ss7_asp_vty_test(config-cs7-as)# do show cs7 instance 0 as all
|
||||
Routing Routing Key Cic Cic
|
||||
AS Name State Context Dpc Si Opc Ssn Min Max
|
||||
------------ ------------ ---------- ------------- ---- ------------- --- ----- -----
|
||||
my-ass AS_DOWN 0 0.0.0
|
||||
|
||||
ss7_asp_vty_test(config-cs7-as)# do show cs7 instance 0 as active
|
||||
Routing Routing Key Cic Cic
|
||||
AS Name State Context Dpc Si Opc Ssn Min Max
|
||||
------------ ------------ ---------- ------------- ---- ------------- --- ----- -----
|
||||
my-ass AS_DOWN 0 0.0.0
|
||||
|
||||
ss7_asp_vty_test(config-cs7-as)# do show cs7 instance 0 as sua
|
||||
Routing Routing Key Cic Cic
|
||||
AS Name State Context Dpc Si Opc Ssn Min Max
|
||||
------------ ------------ ---------- ------------- ---- ------------- --- ----- -----
|
||||
|
||||
ss7_asp_vty_test(config-cs7-as)# do show cs7 instance 0 as m3ua
|
||||
Routing Routing Key Cic Cic
|
||||
AS Name State Context Dpc Si Opc Ssn Min Max
|
||||
------------ ------------ ---------- ------------- ---- ------------- --- ----- -----
|
||||
my-ass AS_DOWN 0 0.0.0
|
||||
|
||||
ss7_asp_vty_test(config-cs7-as)# asp my-asp
|
||||
ss7_asp_vty_test(config-cs7-as)# routing-key 0 3.2.1
|
||||
|
||||
ss7_asp_vty_test(config-cs7-as)# do show cs7 instance 0 asp
|
||||
Effect Primary
|
||||
ASP Name AS Name State Type Rmt Port Remote IP Addr SCTP
|
||||
------------ ------------ ------------- ---- -------- --------------- ----------
|
||||
my-asp ? ASP_DOWN m3ua 12345 127.0.0.200
|
||||
|
||||
ss7_asp_vty_test(config-cs7-as)# exit
|
||||
ss7_asp_vty_test(config-cs7)# do show cs7 instance 0 asp
|
||||
Effect Primary
|
||||
ASP Name AS Name State Type Rmt Port Remote IP Addr SCTP
|
||||
------------ ------------ ------------- ---- -------- --------------- ----------
|
||||
my-asp ? ASP_DOWN m3ua 12345 127.0.0.200
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# exit
|
||||
|
||||
|
||||
ss7_asp_vty_test(config)# do show cs7 instance 0 asp
|
||||
Effect Primary
|
||||
ASP Name AS Name State Type Rmt Port Remote IP Addr SCTP
|
||||
------------ ------------ ------------- ---- -------- --------------- ----------
|
||||
my-asp ? ASP_DOWN m3ua 12345 127.0.0.200
|
||||
|
||||
ss7_asp_vty_test(config)# do show cs7 instance 0 as all
|
||||
Routing Routing Key Cic Cic
|
||||
AS Name State Context Dpc Si Opc Ssn Min Max
|
||||
------------ ------------ ---------- ------------- ---- ------------- --- ----- -----
|
||||
my-ass AS_DOWN 0 3.2.1
|
||||
|
||||
|
||||
|
||||
ss7_asp_vty_test(config)# show running-config
|
||||
...
|
||||
cs7 instance 1
|
||||
sccp-address bar
|
||||
routing-indicator PC
|
||||
point-code 1.2.3
|
||||
cs7 instance 0
|
||||
asp my-asp 12345 54321 m3ua
|
||||
local-ip 127.0.0.100
|
||||
remote-ip 127.0.0.200
|
||||
as my-ass m3ua
|
||||
asp my-asp
|
||||
routing-key 0 3.2.1
|
||||
sccp-address foo
|
||||
routing-indicator PC
|
||||
point-code 1.2.3
|
||||
end
|
||||
|
||||
ss7_asp_vty_test(config)# do show cs7 instance 0 users
|
||||
|
||||
ss7_asp_vty_test(config)# do show cs7 m3ua
|
||||
|
||||
ss7_asp_vty_test(config)# cs7 instance 0
|
||||
ss7_asp_vty_test(config-cs7)# no asp unknown-asp
|
||||
No ASP named 'unknown-asp' found
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# no asp my-asp
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# do show cs7 instance 0 asp
|
||||
Effect Primary
|
||||
ASP Name AS Name State Type Rmt Port Remote IP Addr SCTP
|
||||
------------ ------------ ------------- ---- -------- --------------- ----------
|
||||
|
||||
ss7_asp_vty_test(config-cs7)# do show cs7 instance 0 as all
|
||||
Routing Routing Key Cic Cic
|
||||
AS Name State Context Dpc Si Opc Ssn Min Max
|
||||
------------ ------------ ---------- ------------- ---- ------------- --- ----- -----
|
||||
my-ass AS_DOWN 0 3.2.1
|
|
@ -0,0 +1,219 @@
|
|||
/* test program with a vty interface to test VTY node behavior */
|
||||
/*
|
||||
* (C) 2018 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* Author: Neels Hofmeyr <neels@hofmeyr.de>
|
||||
*
|
||||
* 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, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <getopt.h>
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
#include <osmocom/core/logging.h>
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/core/application.h>
|
||||
|
||||
#include <osmocom/vty/command.h>
|
||||
#include <osmocom/vty/logging.h>
|
||||
#include <osmocom/vty/misc.h>
|
||||
#include <osmocom/vty/telnet_interface.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <osmocom/sigtran/osmo_ss7.h>
|
||||
#include <osmocom/sigtran/sccp_sap.h>
|
||||
|
||||
void *root_ctx = NULL;
|
||||
|
||||
const struct log_info log_info = {
|
||||
};
|
||||
|
||||
static void print_help()
|
||||
{
|
||||
printf( "options:\n"
|
||||
" -h --help this text\n"
|
||||
" -d --debug MASK Enable debugging (e.g. -d DRSL:DOML:DLAPDM)\n"
|
||||
" -D --daemonize For the process into a background daemon\n"
|
||||
" -c --config-file Specify the filename of the config file\n"
|
||||
" -s --disable-color Don't use colors in stderr log output\n"
|
||||
" -T --timestamp Prefix every log line with a timestamp\n"
|
||||
" -V --version Print version information and exit\n"
|
||||
" -e --log-level Set a global log-level\n"
|
||||
);
|
||||
}
|
||||
|
||||
static struct {
|
||||
const char *config_file;
|
||||
int daemonize;
|
||||
} cmdline_config = {};
|
||||
|
||||
static void handle_options(int argc, char **argv)
|
||||
{
|
||||
while (1) {
|
||||
int option_idx = 0, c;
|
||||
static const struct option long_options[] = {
|
||||
{ "help", 0, 0, 'h' },
|
||||
{ "debug", 1, 0, 'd' },
|
||||
{ "daemonize", 0, 0, 'D' },
|
||||
{ "config-file", 1, 0, 'c' },
|
||||
{ "disable-color", 0, 0, 's' },
|
||||
{ "timestamp", 0, 0, 'T' },
|
||||
{ "version", 0, 0, 'V' },
|
||||
{ "log-level", 1, 0, 'e' },
|
||||
{}
|
||||
};
|
||||
|
||||
c = getopt_long(argc, argv, "hc:d:Dc:sTVe:",
|
||||
long_options, &option_idx);
|
||||
if (c == -1)
|
||||
break;
|
||||
|
||||
switch (c) {
|
||||
case 'h':
|
||||
print_help();
|
||||
exit(0);
|
||||
case 's':
|
||||
log_set_use_color(osmo_stderr_target, 0);
|
||||
break;
|
||||
case 'd':
|
||||
log_parse_category_mask(osmo_stderr_target, optarg);
|
||||
break;
|
||||
case 'D':
|
||||
cmdline_config.daemonize = 1;
|
||||
break;
|
||||
case 'c':
|
||||
cmdline_config.config_file = optarg;
|
||||
break;
|
||||
case 'T':
|
||||
log_set_print_timestamp(osmo_stderr_target, 1);
|
||||
break;
|
||||
case 'e':
|
||||
log_set_log_level(osmo_stderr_target, atoi(optarg));
|
||||
break;
|
||||
case 'V':
|
||||
print_version(1);
|
||||
exit(0);
|
||||
break;
|
||||
default:
|
||||
/* catch unknown options *as well as* missing arguments. */
|
||||
fprintf(stderr, "Error in command line options. Exiting.\n");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int quit = 0;
|
||||
|
||||
static void signal_handler(int signal)
|
||||
{
|
||||
fprintf(stdout, "signal %u received\n", signal);
|
||||
|
||||
switch (signal) {
|
||||
case SIGINT:
|
||||
case SIGTERM:
|
||||
quit++;
|
||||
break;
|
||||
case SIGABRT:
|
||||
osmo_generate_backtrace();
|
||||
/* in case of abort, we want to obtain a talloc report
|
||||
* and then return to the caller, who will abort the process */
|
||||
case SIGUSR1:
|
||||
talloc_report(tall_vty_ctx, stderr);
|
||||
talloc_report_full(root_ctx, stderr);
|
||||
break;
|
||||
case SIGUSR2:
|
||||
talloc_report_full(tall_vty_ctx, stderr);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static struct vty_app_info vty_info = {
|
||||
.name = "ss7_asp_vty_test",
|
||||
.version = PACKAGE_VERSION,
|
||||
.go_parent_cb = osmo_ss7_vty_go_parent,
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int rc;
|
||||
|
||||
root_ctx = talloc_named_const(NULL, 0, "ss7_asp_vty_test");
|
||||
|
||||
vty_info.tall_ctx = root_ctx;
|
||||
vty_init(&vty_info);
|
||||
|
||||
osmo_init_logging2(root_ctx, &log_info);
|
||||
logging_vty_add_cmds(&log_info);
|
||||
|
||||
osmo_ss7_init();
|
||||
osmo_ss7_vty_init_asp(root_ctx);
|
||||
osmo_sccp_vty_init();
|
||||
|
||||
handle_options(argc, argv);
|
||||
|
||||
osmo_talloc_vty_add_cmds();
|
||||
|
||||
log_set_print_category(osmo_stderr_target, 1);
|
||||
log_set_print_category_hex(osmo_stderr_target, 0);
|
||||
log_set_print_level(osmo_stderr_target, 1);
|
||||
log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
|
||||
|
||||
if (cmdline_config.config_file) {
|
||||
rc = vty_read_config_file(cmdline_config.config_file, NULL);
|
||||
if (rc < 0) {
|
||||
LOGP(DLGLOBAL, LOGL_FATAL, "Failed to parse the config file: '%s'\n",
|
||||
cmdline_config.config_file);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
rc = telnet_init_dynif(root_ctx, NULL, vty_get_bind_addr(), 42043);
|
||||
if (rc < 0)
|
||||
return 2;
|
||||
|
||||
signal(SIGINT, &signal_handler);
|
||||
signal(SIGTERM, &signal_handler);
|
||||
signal(SIGABRT, &signal_handler);
|
||||
signal(SIGUSR1, &signal_handler);
|
||||
signal(SIGUSR2, &signal_handler);
|
||||
osmo_init_ignore_signals();
|
||||
|
||||
if (cmdline_config.daemonize) {
|
||||
rc = osmo_daemonize();
|
||||
if (rc < 0) {
|
||||
perror("Error during daemonize");
|
||||
return 6;
|
||||
}
|
||||
}
|
||||
|
||||
while (!quit) {
|
||||
log_reset_context();
|
||||
osmo_select_main(0);
|
||||
}
|
||||
|
||||
log_fini();
|
||||
|
||||
talloc_free(root_ctx);
|
||||
talloc_free(tall_vty_ctx);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue