blob: 62c62c669bdc28461476a75084e17c02181ea274 [file] [log] [blame]
Stefan Sperlingc307e682018-06-14 15:15:46 +02001/* (C) 2018 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
2 * Author: Stefan Sperling <ssperling@sysmocom.de>
3 * All Rights Reserved
4 *
Pau Espin Pedrolc64d7262020-01-16 17:00:14 +01005 * The idea is that these tests are executed against sccp_demo_user from
6 * libosmo-sccp.git in server mode.
7 *
Stefan Sperlingc307e682018-06-14 15:15:46 +02008 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
Harald Welte34b5a952019-05-27 11:54:11 +020010 *
11 * SPDX-License-Identifier: GPL-2.0-or-later
Stefan Sperlingc307e682018-06-14 15:15:46 +020012 */
13
14module SCCP_Tests {
15
16import from M3UA_Emulation all;
17
18import from SCCPasp_Types all;
19import from SCCP_Types all;
20import from SCCP_Emulation all;
21import from SCCP_Templates all;
22
23import from SCTPasp_PortType all;
24
25import from Osmocom_CTRL_Adapter all;
26
27import from TELNETasp_PortType all;
28import from Osmocom_VTY_Functions all;
29
30type component system_CT {
31 port SCTPasp_PT sctp;
32};
33
34type component MTC_CT extends CTRL_Adapter_CT {
35 /* VTY to sccp_demo_user (not used yet) */
36 port TELNETasp_PT SCCP_DEMO_USER_VTY;
37
38 /* SCCP protocol runs on top of M3UA Emulation.
39 * "System Under Test" is libosmo-sccp's sccp_demo_user example program. */
40 var SCCP_CT vc_SCCP_A;
41 var M3UA_CT vc_M3UA;
42 port SCCPasp_PT A_PORT;
43}
44
45type record SCCP_Configuration {
46 charstring sccp_service_type,
47 SCTP_Association_Address sctp_addr,
48 integer own_pc,
49 integer own_ssn,
50 integer peer_pc,
51 integer peer_ssn,
52 octetstring sio,
53 integer rctx
54};
55
56type record of SCCP_Configuration SCCP_Configurations;
57modulepar {
Pau Espin Pedrole1870912020-01-17 17:30:19 +010058 SCCP_Configurations mp_sccp_cfg;
Stefan Sperlingc307e682018-06-14 15:15:46 +020059}
60
61function f_init(SCCP_Configuration cfg) runs on MTC_CT {
62 var MSC_SCCP_MTP3_parameters v_param := {
63 sio := {
64 ni := substr(oct2bit(cfg.sio),0,2),
65 prio := substr(oct2bit(cfg.sio),2,2),
66 si := substr(oct2bit(cfg.sio),4,4)
67 },
68 opc := cfg.own_pc,
69 dpc := cfg.peer_pc,
70 sls := 0,
71 sccp_serviceType := cfg.sccp_service_type,
72 ssn := cfg.own_ssn
73 };
74
75 map(self:SCCP_DEMO_USER_VTY, system:SCCP_DEMO_USER_VTY);
76 f_vty_set_prompts(SCCP_DEMO_USER_VTY);
77 f_vty_transceive(SCCP_DEMO_USER_VTY, "enable");
78
79 /* Create and connect test components for an SCCP connection with M3UA beneath. */
80 vc_SCCP_A := SCCP_CT.create;
81 vc_M3UA := M3UA_CT.create;
82 connect(self:A_PORT, vc_SCCP_A:SCCP_SP_PORT);
83 connect(vc_M3UA:MTP3_SP_PORT, vc_SCCP_A:MTP3_SCCP_PORT);
84 map(vc_M3UA:SCTP_PORT, system:sctp);
85
86 vc_M3UA.start(f_M3UA_Emulation(cfg.sctp_addr));
87 vc_SCCP_A.start(SCCPStart(v_param));
88}
89
90function f_cleanup() runs on MTC_CT {
91 all component.stop;
92 unmap(vc_M3UA:SCTP_PORT, system:sctp);
93 disconnect(vc_M3UA:MTP3_SP_PORT, vc_SCCP_A:MTP3_SCCP_PORT);
94 disconnect(self:A_PORT, vc_SCCP_A:SCCP_SP_PORT);
95 self.stop
96}
97
98/*
99 * libosmo-sccp does not support Global Title address as a routing indicator.
100 * But sccp_demo_user should not crash if such a message is received (see OS#2666).
101 */
102testcase TC_routing_global_title_crash() runs on MTC_CT system system_CT {
103 timer TL_timer:= 10.0; /* twice the sccp_demo_user connection attempt interval */
104 var SCCP_PAR_Address v_CallingAddress;
105 var SCCP_PAR_Address v_CalledAddress;
106 var octetstring vl_userdata :='12345678901234567890'O;
107 var ASP_SCCP_N_UNITDATA_ind vl_N_UNITDATA_ind;
108
Pau Espin Pedrole1870912020-01-17 17:30:19 +0100109 f_init(mp_sccp_cfg[0]);
Stefan Sperlingc307e682018-06-14 15:15:46 +0200110
111 /* Called address with routing indicator set to Global Title Address. This used to trigger the crash. */
112 v_CalledAddress := valueof(ts_SccpAddr_GT('012345'H));
113
Pau Espin Pedrole1870912020-01-17 17:30:19 +0100114 v_CallingAddress := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, mp_sccp_cfg[0].own_ssn,
115 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
Stefan Sperlingc307e682018-06-14 15:15:46 +0200116 A_PORT.send(t_ASP_N_UNITDATA_req(v_CalledAddress, v_CallingAddress, '00000001'B /* sequence control */,
117 '00000001'B /* return option */, vl_userdata, omit));
118
119 /*
120 * Start a timeout within which our DATA packet will be sent out.
121 * The M3UA Emulation layer has buffered the packet and is going
122 * to send it when the sccp_demo_user SCCP client connects.
123 *
124 * libosmo-sccp will echo the packet back at us in an SCCP UDTS packet.
125 * However, the current M3UA Emulation implementation will discard this
126 * response because it arrives on a separate SCTP association and the
127 * emulation only supports one association at a time.
128 *
129 * As a workaround, we wait for a fixed amount of time and then issue
130 * another command to the VTY of sccp_demo_user. If sccp_demo_user
131 * has crashed, this will result in a test failure.
132 */
133 TL_timer.start;
134 alt {
135 [] A_PORT.receive(tr_ASP_N_UNITDATA_ind) -> value vl_N_UNITDATA_ind {
136 log("Received data from SCCP client.");
137 repeat;
138 }
139
140 [] TL_timer.timeout {
141 log("Timeout....");
142 }
143 }
144 TL_timer.stop;
145
146 /* Check that the VTY is still active (implying that the process hasn't crashed). */
147 f_vty_transceive_ret(SCCP_DEMO_USER_VTY, "?");
148 setverdict(pass);
149
150 f_cleanup();
151}
152
153control {
154 execute( TC_routing_global_title_crash() );
155}
156
157
158}