blob: 03ef4af436b4997c642a8a2089ddbd75508c57da [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
42 /*Configure T(tias) over VTY, seconds */
43 var integer g_demo_sccp_timer_ias := 7 * 60;
44 /*Configure T(tiar) over VTY, seconds */
45 var integer g_demo_sccp_timer_iar := 15 * 60;
46}
47
48type record of charstring Commands;
49private function f_cs7_inst_0_cfg(TELNETasp_PT pt, Commands cmds := {})
50{
51 f_vty_enter_cfg_cs7_inst(pt, 0);
52 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
53 f_vty_transceive(pt, cmds[i]);
54 }
55 f_vty_transceive(pt, "end");
56}
57
58function f_init_vty() runs on SCCP_Test_RAW_CT {
59 if (SCCP_DEMO_USER_VTY.checkstate("Mapped")) {
60 /* skip initialization if already executed once */
61 return;
62 }
63 map(self:SCCP_DEMO_USER_VTY, system:SCCP_DEMO_USER_VTY);
64 f_vty_set_prompts(SCCP_DEMO_USER_VTY);
65 f_vty_transceive(SCCP_DEMO_USER_VTY, "enable");
66 f_cs7_inst_0_cfg(SCCP_DEMO_USER_VTY, {"sccp-timer ias " & int2str(g_demo_sccp_timer_ias),
67 "sccp-timer iar " & int2str(g_demo_sccp_timer_iar)});
Harald Welte9adf57b2020-01-10 12:33:44 +010068}
69
70private function f_init_raw(SCCP_Configuration cfg) runs on SCCP_Test_RAW_CT {
71 g_param := {
72 sio := {
73 ni := substr(oct2bit(cfg.sio),0,2),
74 prio := substr(oct2bit(cfg.sio),2,2),
75 si := substr(oct2bit(cfg.sio),4,4)
76 },
77 opc := cfg.own_pc,
78 dpc := cfg.peer_pc,
79 sls := 0,
80 sccp_serviceType := cfg.sccp_service_type,
81 ssn := cfg.own_ssn
82 };
83
Pau Espin Pedrola2473da2020-01-20 13:20:58 +010084 f_init_vty();
Harald Welte9adf57b2020-01-10 12:33:44 +010085
86 /* Create and connect test components */
87 vc_M3UA := M3UA_CT.create;
88 connect(self:MTP3, vc_M3UA:MTP3_SP_PORT);
89 map(vc_M3UA:SCTP_PORT, system:sctp);
90
91 vc_M3UA.start(f_M3UA_Emulation(cfg.sctp_addr));
92}
93
94private function f_cleanup() runs on SCCP_Test_RAW_CT {
95 all component.stop;
96 unmap(vc_M3UA:SCTP_PORT, system:sctp);
97 disconnect(vc_M3UA:MTP3_SP_PORT, self:MTP3);
98 self.stop
99}
100
Harald Welte9adf57b2020-01-10 12:33:44 +0100101private function f_send_sccp(template PDU_SCCP sccp) runs on SCCP_Test_RAW_CT {
102 var SCCP_MTP3_TRANSFERreq tx := {
103 sio := g_param.sio,
104 opc := g_param.opc,
105 dpc := g_param.dpc,
106 sls := g_param.sls,
107 data := valueof(sccp)
108 };
109 MTP3.send(tx);
110}
111
112private function f_exp_sccp(template PDU_SCCP sccp) runs on SCCP_Test_RAW_CT {
113 var SCCP_MTP3_TRANSFERind rx;
114 var template SCCP_MTP3_TRANSFERind exp := {
115 sio := g_param.sio,
116 opc := g_param.dpc,
117 dpc := g_param.opc,
118 sls := g_param.sls,
119 data := sccp
120 };
121 timer T := 10.0;
122 T.start;
123 alt {
124 [] MTP3.receive(exp) -> value rx {
125 setverdict(pass);
126 }
127 [] MTP3.receive {
128 setverdict(fail, "Unexpected MTP/SCCP received");
Pau Espin Pedrol94b7a682020-01-20 19:30:07 +0100129 self.stop
Harald Welte9adf57b2020-01-10 12:33:44 +0100130 }
131 [] T.timeout {
132 setverdict(fail, "Timeout waiting for ", exp);
Pau Espin Pedrol94b7a682020-01-20 19:30:07 +0100133 self.stop
Harald Welte9adf57b2020-01-10 12:33:44 +0100134 }
135 }
136}
137
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100138private function f_establish_conn(SCCP_PAR_Address calling, SCCP_PAR_Address called) runs on SCCP_Test_RAW_CT {
139
140 f_send_sccp(ts_SCCP_CR('000001'O, calling, called));
141 f_exp_sccp(tr_SCCP_CC('000000'O, '000001'O));
142}
143
144private function f_tx_udt_exp(SCCP_PAR_Address calling, SCCP_PAR_Address called, octetstring data) runs on SCCP_Test_RAW_CT {
145
146 f_send_sccp(ts_SCCP_UDT(calling, called, data));
147 f_exp_sccp(tr_SCCP_UDT(called, calling, data));
148}
149
Harald Welte9adf57b2020-01-10 12:33:44 +0100150/* Verify sccp_demo_user answers a CR with a CC for PC and SSN set up to echo back */
151testcase TC_cr_cc() runs on SCCP_Test_RAW_CT {
152 var SCCP_PAR_Address calling, called;
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100153
154 f_init_raw(mp_sccp_cfg[0]);
155 f_sleep(1.0);
156
Pau Espin Pedrole1870912020-01-17 17:30:19 +0100157 called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, mp_sccp_cfg[0].peer_ssn,
158 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
159 calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, mp_sccp_cfg[0].own_ssn,
160 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100161 f_establish_conn(calling, called);
162}
163
164/* Verify T(iar) triggers and releases the channel */
165testcase TC_tiar_timeout() runs on SCCP_Test_RAW_CT {
166 var SCCP_PAR_Address calling, called;
167 var octetstring data := f_rnd_octstring(f_rnd_int(100));
168
169 /* Set T(iar) in sccp_demo_user low enough that it will trigger before other side
170 has time to keep alive with a T(ias). Keep recommended ratio of
171 T(iar) >= T(ias)*2 */
172 g_demo_sccp_timer_ias := 2;
173 g_demo_sccp_timer_iar := 5;
Pau Espin Pedrole1870912020-01-17 17:30:19 +0100174 f_init_raw(mp_sccp_cfg[0]);
Harald Welte9adf57b2020-01-10 12:33:44 +0100175 f_sleep(1.0);
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100176
177 called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, mp_sccp_cfg[0].peer_ssn,
178 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
179 calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, mp_sccp_cfg[0].own_ssn,
180 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
181 f_establish_conn(calling, called);
182 f_tx_udt_exp(calling, called, data);
183
184 log("Waiting for first IT");
185 f_exp_sccp(tr_SCCP_IT(?, ?));
186 log("Waiting for second IT");
187 f_exp_sccp(tr_SCCP_IT(?, ?));
188
189 log("Waiting for RLSD");
190 f_exp_sccp(tr_SCCP_RLSD(?, ?, hex2int('0D'H))); /* Cause: Expiration of Rx Inactivity Timer */
191 f_send_sccp(ts_SCCP_RLC('000001'O, '000000'O));
Harald Welte9adf57b2020-01-10 12:33:44 +0100192}
193
194control {
195 execute( TC_cr_cc() );
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100196 execute( TC_tiar_timeout() );
Harald Welte9adf57b2020-01-10 12:33:44 +0100197}
198
199
200}