blob: 356fbb21f240411411f57b86cb041a1591be87ac [file] [log] [blame]
Harald Welte9adf57b2020-01-10 12:33:44 +01001/* (C) 2019 by Harald Welte <laforge@gnumonks.org>
2 * All Rights Reserved
3 *
4 * The idea is that these tests are executed against sccp_demo_user from
5 * libosmo-sccp.git in server mode.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 */
12
13module SCCP_Tests_RAW {
14
15import from General_Types all;
16import from Osmocom_Types all;
17
18import from M3UA_Emulation all;
19
20import from SCCP_Types all;
21import from SCCPasp_Types all;
22import from SCCP_Templates all;
23import from SCCP_Emulation all;
24import from SCCP_CodecPort all;
25
26import from TELNETasp_PortType all;
27import from Osmocom_VTY_Functions all;
28
29import from SCCP_Tests all;
30
31type component SCCP_Test_RAW_CT {
32 /* VTY to sccp_demo_user (not used yet) */
33 port TELNETasp_PT SCCP_DEMO_USER_VTY;
34
35 /* SCCP raw port runs on top of M3UA Emulation.
36 * "System Under Test" is libosmo-sccp's sccp_demo_user example program. */
37 var M3UA_CT vc_M3UA;
38 port SCCP_CODEC_PT MTP3;
39
40 var MSC_SCCP_MTP3_parameters g_param;
Pau Espin Pedrola2473da2020-01-20 13:20:58 +010041
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +010042 var OCT3 g_own_lref := '000001'O
43
Pau Espin Pedrola2473da2020-01-20 13:20:58 +010044 /*Configure T(tias) over VTY, seconds */
45 var integer g_demo_sccp_timer_ias := 7 * 60;
46 /*Configure T(tiar) over VTY, seconds */
47 var integer g_demo_sccp_timer_iar := 15 * 60;
48}
49
50type record of charstring Commands;
51private function f_cs7_inst_0_cfg(TELNETasp_PT pt, Commands cmds := {})
52{
53 f_vty_enter_cfg_cs7_inst(pt, 0);
54 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
55 f_vty_transceive(pt, cmds[i]);
56 }
57 f_vty_transceive(pt, "end");
58}
59
60function f_init_vty() runs on SCCP_Test_RAW_CT {
61 if (SCCP_DEMO_USER_VTY.checkstate("Mapped")) {
62 /* skip initialization if already executed once */
63 return;
64 }
65 map(self:SCCP_DEMO_USER_VTY, system:SCCP_DEMO_USER_VTY);
66 f_vty_set_prompts(SCCP_DEMO_USER_VTY);
67 f_vty_transceive(SCCP_DEMO_USER_VTY, "enable");
68 f_cs7_inst_0_cfg(SCCP_DEMO_USER_VTY, {"sccp-timer ias " & int2str(g_demo_sccp_timer_ias),
69 "sccp-timer iar " & int2str(g_demo_sccp_timer_iar)});
Harald Welte9adf57b2020-01-10 12:33:44 +010070}
71
72private function f_init_raw(SCCP_Configuration cfg) runs on SCCP_Test_RAW_CT {
73 g_param := {
74 sio := {
75 ni := substr(oct2bit(cfg.sio),0,2),
76 prio := substr(oct2bit(cfg.sio),2,2),
77 si := substr(oct2bit(cfg.sio),4,4)
78 },
79 opc := cfg.own_pc,
80 dpc := cfg.peer_pc,
81 sls := 0,
82 sccp_serviceType := cfg.sccp_service_type,
83 ssn := cfg.own_ssn
84 };
85
Pau Espin Pedrola2473da2020-01-20 13:20:58 +010086 f_init_vty();
Harald Welte9adf57b2020-01-10 12:33:44 +010087
88 /* Create and connect test components */
89 vc_M3UA := M3UA_CT.create;
90 connect(self:MTP3, vc_M3UA:MTP3_SP_PORT);
91 map(vc_M3UA:SCTP_PORT, system:sctp);
92
93 vc_M3UA.start(f_M3UA_Emulation(cfg.sctp_addr));
94}
95
96private function f_cleanup() runs on SCCP_Test_RAW_CT {
97 all component.stop;
98 unmap(vc_M3UA:SCTP_PORT, system:sctp);
99 disconnect(vc_M3UA:MTP3_SP_PORT, self:MTP3);
100 self.stop
101}
102
Harald Welte9adf57b2020-01-10 12:33:44 +0100103private function f_send_sccp(template PDU_SCCP sccp) runs on SCCP_Test_RAW_CT {
104 var SCCP_MTP3_TRANSFERreq tx := {
105 sio := g_param.sio,
106 opc := g_param.opc,
107 dpc := g_param.dpc,
108 sls := g_param.sls,
109 data := valueof(sccp)
110 };
111 MTP3.send(tx);
112}
113
Pau Espin Pedrole30d5432020-01-21 13:47:32 +0100114private function tr_SCCP_MTP3_TRANSFERind(template PDU_SCCP sccp)
115runs on SCCP_Test_RAW_CT return template SCCP_MTP3_TRANSFERind {
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100116
Harald Welte9adf57b2020-01-10 12:33:44 +0100117 var template SCCP_MTP3_TRANSFERind exp := {
118 sio := g_param.sio,
119 opc := g_param.dpc,
120 dpc := g_param.opc,
121 sls := g_param.sls,
122 data := sccp
123 };
Pau Espin Pedrole30d5432020-01-21 13:47:32 +0100124 return exp;
125}
126
127private function f_exp_sccp(template PDU_SCCP sccp)
128runs on SCCP_Test_RAW_CT return SCCP_MTP3_TRANSFERind {
129 var template SCCP_MTP3_TRANSFERind exp := tr_SCCP_MTP3_TRANSFERind(sccp);
130 var SCCP_MTP3_TRANSFERind rx;
Harald Welte9adf57b2020-01-10 12:33:44 +0100131 timer T := 10.0;
132 T.start;
133 alt {
134 [] MTP3.receive(exp) -> value rx {
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100135 return rx;
Harald Welte9adf57b2020-01-10 12:33:44 +0100136 }
137 [] MTP3.receive {
138 setverdict(fail, "Unexpected MTP/SCCP received");
Pau Espin Pedrol94b7a682020-01-20 19:30:07 +0100139 self.stop
Harald Welte9adf57b2020-01-10 12:33:44 +0100140 }
141 [] T.timeout {
142 setverdict(fail, "Timeout waiting for ", exp);
Pau Espin Pedrol94b7a682020-01-20 19:30:07 +0100143 self.stop
Harald Welte9adf57b2020-01-10 12:33:44 +0100144 }
145 }
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100146 return rx;
Harald Welte9adf57b2020-01-10 12:33:44 +0100147}
148
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100149private function f_establish_conn(SCCP_PAR_Address calling, SCCP_PAR_Address called)
150runs on SCCP_Test_RAW_CT return OCT3 {
151 var SCCP_MTP3_TRANSFERind mtp3_rx;
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100152
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100153 f_send_sccp(ts_SCCP_CR(g_own_lref, calling, called));
154 mtp3_rx := f_exp_sccp(tr_SCCP_CC(?, g_own_lref));
155
156 return mtp3_rx.data.connconfirm.sourceLocRef;
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100157}
158
159private function f_tx_udt_exp(SCCP_PAR_Address calling, SCCP_PAR_Address called, octetstring data) runs on SCCP_Test_RAW_CT {
160
161 f_send_sccp(ts_SCCP_UDT(calling, called, data));
162 f_exp_sccp(tr_SCCP_UDT(called, calling, data));
163}
164
Harald Welte9adf57b2020-01-10 12:33:44 +0100165/* Verify sccp_demo_user answers a CR with a CC for PC and SSN set up to echo back */
166testcase TC_cr_cc() runs on SCCP_Test_RAW_CT {
167 var SCCP_PAR_Address calling, called;
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100168
169 f_init_raw(mp_sccp_cfg[0]);
170 f_sleep(1.0);
171
Pau Espin Pedrole1870912020-01-17 17:30:19 +0100172 called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, mp_sccp_cfg[0].peer_ssn,
173 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
174 calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, mp_sccp_cfg[0].own_ssn,
175 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100176 f_establish_conn(calling, called);
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100177 setverdict(pass);
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100178}
179
Pau Espin Pedrol1269b1b2020-01-21 12:58:48 +0100180/* Verify sccp_demo_user inactivty timers are not armed upon dealing with
181/* connectionless data-unit messages. Since no connection exists. */
Pau Espin Pedrolf7ba2342020-01-20 20:19:47 +0100182testcase TC_udt_without_cr_cc() runs on SCCP_Test_RAW_CT {
183 var SCCP_PAR_Address calling, called;
Pau Espin Pedrol1269b1b2020-01-21 12:58:48 +0100184 var SCCP_MTP3_TRANSFERind rx;
Pau Espin Pedrolf7ba2342020-01-20 20:19:47 +0100185 var octetstring data := f_rnd_octstring(f_rnd_int(100));
186
Pau Espin Pedrol1269b1b2020-01-21 12:58:48 +0100187 /* Keep recommended ratio of T(iar) >= T(ias)*2, but anyway no IT
188 should be received in this case. */
189 g_demo_sccp_timer_ias := 1;
190 g_demo_sccp_timer_iar := 3;
Pau Espin Pedrolf7ba2342020-01-20 20:19:47 +0100191 f_init_raw(mp_sccp_cfg[0]);
192 f_sleep(1.0);
193
194 called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, mp_sccp_cfg[0].peer_ssn,
195 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
196 calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, mp_sccp_cfg[0].own_ssn,
197 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
198
199 f_tx_udt_exp(calling, called, data);
Pau Espin Pedrol1269b1b2020-01-21 12:58:48 +0100200
201 /* Make sure no SCCP message is received at all, since no connection is active. */
202 timer T := int2float(g_demo_sccp_timer_iar + 1);
203 T.start;
204 alt {
205 [] MTP3.receive {
206 setverdict(fail, "Unexpected MTP/SCCP received");
207 self.stop;
208 }
209 [] T.timeout {}
210 }
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100211 setverdict(pass);
Pau Espin Pedrolf7ba2342020-01-20 20:19:47 +0100212}
213
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100214/* Verify T(iar) triggers and releases the channel */
215testcase TC_tiar_timeout() runs on SCCP_Test_RAW_CT {
216 var SCCP_PAR_Address calling, called;
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100217 var OCT3 remote_lref;
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100218 var octetstring data := f_rnd_octstring(f_rnd_int(100));
219
220 /* Set T(iar) in sccp_demo_user low enough that it will trigger before other side
221 has time to keep alive with a T(ias). Keep recommended ratio of
222 T(iar) >= T(ias)*2 */
223 g_demo_sccp_timer_ias := 2;
224 g_demo_sccp_timer_iar := 5;
Pau Espin Pedrole1870912020-01-17 17:30:19 +0100225 f_init_raw(mp_sccp_cfg[0]);
Harald Welte9adf57b2020-01-10 12:33:44 +0100226 f_sleep(1.0);
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100227
228 called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, mp_sccp_cfg[0].peer_ssn,
229 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
230 calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, mp_sccp_cfg[0].own_ssn,
231 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100232 remote_lref := f_establish_conn(calling, called);
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100233 f_tx_udt_exp(calling, called, data);
234
235 log("Waiting for first IT");
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100236 f_exp_sccp(tr_SCCP_IT(remote_lref, g_own_lref));
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100237 log("Waiting for second IT");
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100238 f_exp_sccp(tr_SCCP_IT(remote_lref, g_own_lref));
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100239
240 log("Waiting for RLSD");
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100241 f_exp_sccp(tr_SCCP_RLSD(remote_lref, g_own_lref, hex2int('0D'H))); /* Cause: Expiration of Rx Inactivity Timer */
242 f_send_sccp(ts_SCCP_RLC(g_own_lref, remote_lref));
243 setverdict(pass);
Harald Welte9adf57b2020-01-10 12:33:44 +0100244}
245
Pau Espin Pedrole30d5432020-01-21 13:47:32 +0100246/* Verify T(iar) triggers and releases the channel */
247testcase TC_it_avoids_tiar() runs on SCCP_Test_RAW_CT {
248 var SCCP_PAR_Address calling, called;
249 var OCT3 remote_lref;
250 var boolean it_received := false;
251
252 g_demo_sccp_timer_ias := 1;
253 g_demo_sccp_timer_iar := 3;
254 f_init_raw(mp_sccp_cfg[0]);
255 f_sleep(1.0);
256
257 called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, mp_sccp_cfg[0].peer_ssn,
258 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
259 calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, mp_sccp_cfg[0].own_ssn,
260 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
261 remote_lref := f_establish_conn(calling, called);
262
263 timer T_total := 7.0; /* Higher than g_demo_sccp_timer_iar */
264 timer T_tias := 1.0; /* Lower than g_demo_sccp_timer_iar */
265 T_total.start;
266 T_tias.start;
267 alt {
268 [] MTP3.receive(tr_SCCP_MTP3_TRANSFERind(tr_SCCP_IT(remote_lref, g_own_lref))) {
269 it_received := true;
270 repeat;
271 }
272 [] MTP3.receive(tr_SCCP_MTP3_TRANSFERind(tr_SCCP_RLSD(remote_lref, g_own_lref, hex2int('0D'H)))) {
273 setverdict(fail, "Unexpected SCCP RLSD received");
274 self.stop;
275 }
276 [] MTP3.receive {
277 setverdict(fail, "Unexpected MTP/SCCP received");
278 self.stop;
279 }
280 [] T_tias.timeout {
281 f_send_sccp(ts_SCCP_IT(g_own_lref, remote_lref));
282 T_tias.start;
283 repeat;
284 }
285 [] T_total.timeout {
286 /* We kept the connection alive only with IT messages for a while, cool! */
287 T_tias.stop;
288 setverdict(pass);
289 }
290 }
291
292 if (not it_received) {
293 setverdict(fail, "Didn't receive any IT (Tias) from peer");
294 }
295
296 /* After we stop sending IT, we should be receiving an RLSD triggered from T(iar) */
297 log("Waiting for RLSD");
298 alt {
299 [] MTP3.receive(tr_SCCP_MTP3_TRANSFERind(tr_SCCP_IT(remote_lref, g_own_lref))) {
300 repeat;
301 }
302 [] MTP3.receive(tr_SCCP_MTP3_TRANSFERind(tr_SCCP_RLSD(remote_lref, g_own_lref, hex2int('0D'H)))) {
303 f_send_sccp(ts_SCCP_RLC(g_own_lref, remote_lref));
304 setverdict(pass);
305 }
306 [] MTP3.receive {
307 setverdict(fail, "Unexpected MTP/SCCP received");
308 self.stop;
309 }
310 }
311}
312
Harald Welte24f921b2021-02-10 19:37:45 +0100313function f_scmg_xceive(SCCP_PAR_Address calling, SCCP_PAR_Address called,
314 template (value) PDU_SCMG_message tx,
315 template (omit) PDU_SCMG_message rx_exp) runs on SCCP_Test_RAW_CT
316{
317 var boolean exp_something := true;
318 timer T := 5.0;
319
320 if (istemplatekind(rx_exp, "omit")) {
321 exp_something := false;
322 }
323
324 MTP3.clear;
325 f_send_sccp(ts_SCCP_UDT(calling, called, enc_PDU_SCMG_message(valueof(tx))));
326 T.start;
327 alt {
328 [exp_something] MTP3.receive(tr_SCCP_MTP3_TRANSFERind(tr_SCCP_UDT(called, calling, decmatch rx_exp))) {
329 setverdict(pass);
330 }
331 [] MTP3.receive(tr_SCCP_MTP3_TRANSFERind(tr_SCCP_UDT(called, calling, ?))) {
332 setverdict(fail, "Received unexpected SCCP waiting for ", rx_exp);
333 }
334 [] MTP3.receive {
335 setverdict(fail, "Received unexpected waiting for ", rx_exp);
336 }
337 [exp_something] T.timeout {
338 setverdict(fail, "Timeout waiting for ", rx_exp);
339 }
340 [not exp_something] T.timeout {
341 setverdict(pass);
342 }
343 }
344
345}
346
347/* Test is SST(SSN=1) returns SSA */
348testcase TC_scmg_sst_ssn1() runs on SCCP_Test_RAW_CT {
349 var SCCP_PAR_Address calling, called;
350 var template (value) PDU_SCMG_message tx;
351 var template (present) PDU_SCMG_message rx_exp;
352
353 f_init_raw(mp_sccp_cfg[0]);
354 f_sleep(1.0);
355
356 called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, 1,
357 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
358 calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, 1,
359 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
360
361 tx := ts_SCMG_SST(1, mp_sccp_cfg[0].peer_pc);
362 rx_exp := ts_SCMG_SSA(1, mp_sccp_cfg[0].peer_pc);
363 f_scmg_xceive(calling, called, tx, rx_exp);
364}
365
366/* Test is SST(SSN=valid) returns SSA */
367testcase TC_scmg_sst_ssn_valid() runs on SCCP_Test_RAW_CT {
368 var SCCP_PAR_Address calling, called;
369 var template (value) PDU_SCMG_message tx;
370 var template (present) PDU_SCMG_message rx_exp;
371
372 f_init_raw(mp_sccp_cfg[0]);
373 f_sleep(1.0);
374
375 called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, 1,
376 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
377 calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, 1,
378 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
379
380 tx := ts_SCMG_SST(mp_sccp_cfg[0].peer_ssn, mp_sccp_cfg[0].peer_pc);
381 rx_exp := ts_SCMG_SSA(mp_sccp_cfg[0].peer_ssn, mp_sccp_cfg[0].peer_pc);
382 f_scmg_xceive(calling, called, tx, rx_exp);
383}
384
385
386/* Test is SST(SSN=invalid) returns nothing */
387testcase TC_scmg_sst_ssn_invalid() runs on SCCP_Test_RAW_CT {
388 var SCCP_PAR_Address calling, called;
389 var template (value) PDU_SCMG_message tx;
390 var template (omit) PDU_SCMG_message rx_exp;
391
392 f_init_raw(mp_sccp_cfg[0]);
393 f_sleep(1.0);
394
395 called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, 1,
396 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
397 calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, 1,
398 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
399
400 tx := ts_SCMG_SST(123, mp_sccp_cfg[0].peer_pc);
401 rx_exp := omit;
402 f_scmg_xceive(calling, called, tx, rx_exp);
403}
404
405
406
Harald Welte9adf57b2020-01-10 12:33:44 +0100407control {
408 execute( TC_cr_cc() );
Pau Espin Pedrolf7ba2342020-01-20 20:19:47 +0100409 execute( TC_udt_without_cr_cc() );
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100410 execute( TC_tiar_timeout() );
Pau Espin Pedrole30d5432020-01-21 13:47:32 +0100411 execute( TC_it_avoids_tiar() );
Harald Welte24f921b2021-02-10 19:37:45 +0100412
413 execute( TC_scmg_sst_ssn1() );
414 execute( TC_scmg_sst_ssn_valid() );
415 execute( TC_scmg_sst_ssn_invalid() );
Harald Welte9adf57b2020-01-10 12:33:44 +0100416}
417
418
419}