introduce a TTCN3 test suite for SCCP
This test suite acts as an SCCP server on top of M3UA.
SCCP tests are run against the sccp_demo_user program which
can be found in libosmo-sccp/examples. This program must be
started in client mode: sccp_demo_user -c
The SCCP test suite should then work out of the box with
the provided SCCP_Tests.cfg file and this additional change
to sccp_demo_user default point codes:
https://gerrit.osmocom.org/#/c/libosmo-sccp/+/9652/
There is currently only one test, for the libosmo-sccp crash
reported as issue OS#2666. The implementation of this test
is currently using an ugly workaround due to shortcomings of
the M3UA Emulation layer (see source code comments). Whether
a better solution is feasible is still to be determined.
The test requires a patch to the SCCP Protocol Emulation which
has been submitted upstream: https://git.eclipse.org/r/#/c/124552/
Change-Id: I03f5e8b282a7396b45417495c88d8fb81b26cda8
Related: OS#2666
diff --git a/sccp/SCCP_Tests.cfg b/sccp/SCCP_Tests.cfg
new file mode 100644
index 0000000..4b7e742
--- /dev/null
+++ b/sccp/SCCP_Tests.cfg
@@ -0,0 +1,19 @@
+[ORDERED_INCLUDE]
+# Common configuration, shared between test suites
+"../Common.cfg"
+# testsuite specific configuration, not expected to change
+"./SCCP_Tests.default"
+
+# Local configuration below
+
+[LOGGING]
+
+[TESTPORT_PARAMETERS]
+
+[MODULE_PARAMETERS]
+
+[MAIN_CONTROLLER]
+
+[EXECUTE]
+SCCP_Tests.control
+#SCCP_Tests.TC_routing_global_title_crash
diff --git a/sccp/SCCP_Tests.default b/sccp/SCCP_Tests.default
new file mode 100644
index 0000000..7d16e5b
--- /dev/null
+++ b/sccp/SCCP_Tests.default
@@ -0,0 +1,41 @@
+[LOGGING]
+FileMask := LOG_ALL | TTCN_MATCHING | DEBUG_ENCDEC;
+
+BSSAP.FileMask := LOG_NOTHING;
+"SCCP_Test_M3UA".FileMask := ERROR | WARNING;
+"SCCP_Test_SCCP".FileMask := ERROR | WARNING;
+"IPA-CTRL-IPA".FileMask := ERROR | WARNING;
+mtc.FileMask := ERROR | WARNING;
+
+[TESTPORT_PARAMETERS]
+*.SCCP_DEMO_USER_VTY.CTRL_MODE := "client"
+*.SCCP_DEMO_USER_VTY.CTRL_HOSTNAME := "127.0.0.1"
+*.SCCP_DEMO_USER_VTY.CTRL_PORTNUM := "2325"
+*.SCCP_DEMO_USER_VTY.CTRL_LOGIN_SKIPPED := "yes"
+*.SCCP_DEMO_USER_VTY.CTRL_DETECT_SERVER_DISCONNECTED := "yes"
+*.SCCP_DEMO_USER_VTY.CTRL_READMODE := "buffered"
+*.SCCP_DEMO_USER_VTY.CTRL_CLIENT_CLEANUP_LINEFEED := "yes"
+*.SCCP_DEMO_USER_VTY.PROMPT1 := "sccp-demo-user> "
+
+[MODULE_PARAMETERS]
+M3UA_Emulation.tsp_logVerbose := true;
+M3UA_Emulation.tsp_SCTP_Server_Mode := true;
+M3UA_Emulation.tsp_M3UA_Server_Mode := true;
+SCCP_Tests.sccp_cfg := {
+ {
+ sccp_service_type := "mtp3_itu",
+ sctp_addr := { 2905, "127.0.0.1", 2905, "127.0.0.2" },
+ own_pc := 185,
+ own_ssn := 254,
+ peer_pc := 23,
+ peer_ssn := 254,
+ sio := '83'O,
+ rctx := 0
+ }
+};
+
+Osmocom_VTY_Functions.mp_prompt_prefix := "sccp-demo-user";
+
+[MAIN_CONTROLLER]
+
+[EXECUTE]
diff --git a/sccp/SCCP_Tests.ttcn b/sccp/SCCP_Tests.ttcn
new file mode 100644
index 0000000..ea2522a
--- /dev/null
+++ b/sccp/SCCP_Tests.ttcn
@@ -0,0 +1,153 @@
+/* (C) 2018 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
+ * Author: Stefan Sperling <ssperling@sysmocom.de>
+ * All Rights Reserved
+ *
+ * Released under the terms of GNU General Public License, Version 2 or
+ * (at your option) any later version.
+ */
+
+module SCCP_Tests {
+
+import from M3UA_Emulation all;
+
+import from SCCPasp_Types all;
+import from SCCP_Types all;
+import from SCCP_Emulation all;
+import from SCCP_Templates all;
+
+import from SCTPasp_PortType all;
+
+import from Osmocom_CTRL_Adapter all;
+
+import from TELNETasp_PortType all;
+import from Osmocom_VTY_Functions all;
+
+type component system_CT {
+ port SCTPasp_PT sctp;
+};
+
+type component MTC_CT extends CTRL_Adapter_CT {
+ /* VTY to sccp_demo_user (not used yet) */
+ port TELNETasp_PT SCCP_DEMO_USER_VTY;
+
+ /* SCCP protocol runs on top of M3UA Emulation.
+ * "System Under Test" is libosmo-sccp's sccp_demo_user example program. */
+ var SCCP_CT vc_SCCP_A;
+ var M3UA_CT vc_M3UA;
+ port SCCPasp_PT A_PORT;
+}
+
+type record SCCP_Configuration {
+ charstring sccp_service_type,
+ SCTP_Association_Address sctp_addr,
+ integer own_pc,
+ integer own_ssn,
+ integer peer_pc,
+ integer peer_ssn,
+ octetstring sio,
+ integer rctx
+};
+
+type record of SCCP_Configuration SCCP_Configurations;
+modulepar {
+ SCCP_Configurations sccp_cfg;
+}
+
+function f_init(SCCP_Configuration cfg) runs on MTC_CT {
+ var MSC_SCCP_MTP3_parameters v_param := {
+ sio := {
+ ni := substr(oct2bit(cfg.sio),0,2),
+ prio := substr(oct2bit(cfg.sio),2,2),
+ si := substr(oct2bit(cfg.sio),4,4)
+ },
+ opc := cfg.own_pc,
+ dpc := cfg.peer_pc,
+ sls := 0,
+ sccp_serviceType := cfg.sccp_service_type,
+ ssn := cfg.own_ssn
+ };
+
+ map(self:SCCP_DEMO_USER_VTY, system:SCCP_DEMO_USER_VTY);
+ f_vty_set_prompts(SCCP_DEMO_USER_VTY);
+ f_vty_transceive(SCCP_DEMO_USER_VTY, "enable");
+
+ /* Create and connect test components for an SCCP connection with M3UA beneath. */
+ vc_SCCP_A := SCCP_CT.create;
+ vc_M3UA := M3UA_CT.create;
+ connect(self:A_PORT, vc_SCCP_A:SCCP_SP_PORT);
+ connect(vc_M3UA:MTP3_SP_PORT, vc_SCCP_A:MTP3_SCCP_PORT);
+ map(vc_M3UA:SCTP_PORT, system:sctp);
+
+ vc_M3UA.start(f_M3UA_Emulation(cfg.sctp_addr));
+ vc_SCCP_A.start(SCCPStart(v_param));
+}
+
+function f_cleanup() runs on MTC_CT {
+ all component.stop;
+ unmap(vc_M3UA:SCTP_PORT, system:sctp);
+ disconnect(vc_M3UA:MTP3_SP_PORT, vc_SCCP_A:MTP3_SCCP_PORT);
+ disconnect(self:A_PORT, vc_SCCP_A:SCCP_SP_PORT);
+ self.stop
+}
+
+/*
+ * libosmo-sccp does not support Global Title address as a routing indicator.
+ * But sccp_demo_user should not crash if such a message is received (see OS#2666).
+ */
+testcase TC_routing_global_title_crash() runs on MTC_CT system system_CT {
+ timer TL_timer:= 10.0; /* twice the sccp_demo_user connection attempt interval */
+ var SCCP_PAR_Address v_CallingAddress;
+ var SCCP_PAR_Address v_CalledAddress;
+ var octetstring vl_userdata :='12345678901234567890'O;
+ var ASP_SCCP_N_UNITDATA_ind vl_N_UNITDATA_ind;
+
+ f_init(sccp_cfg[0]);
+
+ /* Called address with routing indicator set to Global Title Address. This used to trigger the crash. */
+ v_CalledAddress := valueof(ts_SccpAddr_GT('012345'H));
+
+ v_CallingAddress := valueof(ts_SccpAddr_PC_SSN(sccp_cfg[0].own_pc, sccp_cfg[0].own_ssn,
+ sccp_cfg[0].sio, sccp_cfg[0].sccp_service_type));
+ A_PORT.send(t_ASP_N_UNITDATA_req(v_CalledAddress, v_CallingAddress, '00000001'B /* sequence control */,
+ '00000001'B /* return option */, vl_userdata, omit));
+
+ /*
+ * Start a timeout within which our DATA packet will be sent out.
+ * The M3UA Emulation layer has buffered the packet and is going
+ * to send it when the sccp_demo_user SCCP client connects.
+ *
+ * libosmo-sccp will echo the packet back at us in an SCCP UDTS packet.
+ * However, the current M3UA Emulation implementation will discard this
+ * response because it arrives on a separate SCTP association and the
+ * emulation only supports one association at a time.
+ *
+ * As a workaround, we wait for a fixed amount of time and then issue
+ * another command to the VTY of sccp_demo_user. If sccp_demo_user
+ * has crashed, this will result in a test failure.
+ */
+ TL_timer.start;
+ alt {
+ [] A_PORT.receive(tr_ASP_N_UNITDATA_ind) -> value vl_N_UNITDATA_ind {
+ log("Received data from SCCP client.");
+ repeat;
+ }
+
+ [] TL_timer.timeout {
+ log("Timeout....");
+ }
+ }
+ TL_timer.stop;
+
+ /* Check that the VTY is still active (implying that the process hasn't crashed). */
+ f_vty_transceive_ret(SCCP_DEMO_USER_VTY, "?");
+ setverdict(pass);
+
+ f_cleanup();
+}
+
+control {
+ execute( TC_routing_global_title_crash() );
+}
+
+
+}
diff --git a/sccp/gen_links.sh b/sccp/gen_links.sh
new file mode 100755
index 0000000..faf347c
--- /dev/null
+++ b/sccp/gen_links.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+
+BASEDIR=../deps
+
+. ../gen_links.sh.inc
+
+DIR=$BASEDIR/titan.TestPorts.UNIX_DOMAIN_SOCKETasp/src
+FILES="UD_PT.cc UD_PT.hh UD_PortType.ttcn UD_Types.ttcn"
+gen_links $DIR $FILES
+
+DIR=$BASEDIR/titan.Libraries.TCCUsefulFunctions/src
+FILES="TCCInterface_Functions.ttcn TCCConversion_Functions.ttcn TCCConversion.cc TCCInterface.cc TCCInterface_ip.h"
+FILES+=" TCCEncoding_Functions.ttcn TCCEncoding.cc " # GSM 7-bit coding
+gen_links $DIR $FILES
+
+DIR=$BASEDIR/titan.TestPorts.Common_Components.Socket-API/src
+FILES="Socket_API_Definitions.ttcn"
+gen_links $DIR $FILES
+
+# Required by MGCP and IPA
+DIR=$BASEDIR/titan.TestPorts.IPL4asp/src
+FILES="IPL4asp_Functions.ttcn IPL4asp_PT.cc IPL4asp_PT.hh IPL4asp_PortType.ttcn IPL4asp_Types.ttcn IPL4asp_discovery.cc IPL4asp_protocol_L234.hh"
+gen_links $DIR $FILES
+
+# required by M3UA_Emulation
+DIR=$BASEDIR/titan.ProtocolModules.M3UA/src
+FILES="M3UA_Types.ttcn"
+gen_links $DIR $FILES
+
+# required by M3UA_Emulation
+DIR=$BASEDIR/titan.TestPorts.SCTPasp/src
+FILES="SCTPasp_PT.cc SCTPasp_PT.hh SCTPasp_PortType.ttcn SCTPasp_Types.ttcn"
+gen_links $DIR $FILES
+
+# required by M3UA Emulation
+DIR=$BASEDIR/titan.TestPorts.MTP3asp/src
+FILES="MTP3asp_PortType.ttcn MTP3asp_Types.ttcn"
+gen_links $DIR $FILES
+
+# required by SCCP Emulation
+DIR=$BASEDIR/titan.ProtocolEmulations.M3UA/src
+FILES="M3UA_Emulation.ttcn"
+gen_links $DIR $FILES
+
+DIR=$BASEDIR/titan.ProtocolEmulations.SCCP/src
+FILES="SCCP_Emulation.ttcn SCCP_EncDec.cc SCCP_Mapping.ttcnpp SCCP_Types.ttcn SCCPasp_Types.ttcn"
+gen_links $DIR $FILES
+
+DIR=$BASEDIR/titan.TestPorts.TELNETasp/src
+FILES="TELNETasp_PT.cc TELNETasp_PT.hh TELNETasp_PortType.ttcn"
+gen_links $DIR $FILES
+
+
+DIR=../library
+FILES="General_Types.ttcn GSM_Types.ttcn Osmocom_Types.ttcn "
+FILES+="Osmocom_VTY_Functions.ttcn Native_Functions.ttcn Native_FunctionDefs.cc "
+FILES+="IPA_Types.ttcn IPA_Emulation.ttcnpp IPA_CodecPort.ttcn IPA_CodecPort_CtrlFunct.ttcn IPA_CodecPort_CtrlFunctDef.cc "
+FILES+="Osmocom_CTRL_Types.ttcn Osmocom_CTRL_Functions.ttcn Osmocom_CTRL_Adapter.ttcn "
+FILES+="SCCP_Templates.ttcn "
+gen_links $DIR $FILES
+
+ignore_pp_results
diff --git a/sccp/regen_makefile.sh b/sccp/regen_makefile.sh
new file mode 100755
index 0000000..fc9e6d2
--- /dev/null
+++ b/sccp/regen_makefile.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+FILES="*.ttcn *.ttcnpp SCCP_EncDec.cc SCTPasp_PT.cc TCCConversion.cc TCCInterface.cc UD_PT.cc IPL4asp_PT.cc IPL4asp_discovery.cc IPA_CodecPort_CtrlFunctDef.cc TELNETasp_PT.cc Native_FunctionDefs.cc TCCEncoding.cc "
+
+export CPPFLAGS_TTCN3="-DIPA_EMULATION_SCCP -DUSE_MTP3_DISTRIBUTOR"
+
+../regen-makefile.sh SCCP_Tests.ttcn $FILES