blob: 5996846c3a65c329896bce8818d3b3b56dfeb412 [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 Pedrol392eaf32020-01-21 12:21:05 +0100114private function f_exp_sccp(template PDU_SCCP sccp)
115runs on SCCP_Test_RAW_CT return SCCP_MTP3_TRANSFERind {
116
Harald Welte9adf57b2020-01-10 12:33:44 +0100117 var SCCP_MTP3_TRANSFERind rx;
118 var template SCCP_MTP3_TRANSFERind exp := {
119 sio := g_param.sio,
120 opc := g_param.dpc,
121 dpc := g_param.opc,
122 sls := g_param.sls,
123 data := sccp
124 };
125 timer T := 10.0;
126 T.start;
127 alt {
128 [] MTP3.receive(exp) -> value rx {
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100129 return rx;
Harald Welte9adf57b2020-01-10 12:33:44 +0100130 }
131 [] MTP3.receive {
132 setverdict(fail, "Unexpected MTP/SCCP received");
Pau Espin Pedrol94b7a682020-01-20 19:30:07 +0100133 self.stop
Harald Welte9adf57b2020-01-10 12:33:44 +0100134 }
135 [] T.timeout {
136 setverdict(fail, "Timeout waiting for ", exp);
Pau Espin Pedrol94b7a682020-01-20 19:30:07 +0100137 self.stop
Harald Welte9adf57b2020-01-10 12:33:44 +0100138 }
139 }
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100140 return rx;
Harald Welte9adf57b2020-01-10 12:33:44 +0100141}
142
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100143private function f_establish_conn(SCCP_PAR_Address calling, SCCP_PAR_Address called)
144runs on SCCP_Test_RAW_CT return OCT3 {
145 var SCCP_MTP3_TRANSFERind mtp3_rx;
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100146
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100147 f_send_sccp(ts_SCCP_CR(g_own_lref, calling, called));
148 mtp3_rx := f_exp_sccp(tr_SCCP_CC(?, g_own_lref));
149
150 return mtp3_rx.data.connconfirm.sourceLocRef;
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100151}
152
153private function f_tx_udt_exp(SCCP_PAR_Address calling, SCCP_PAR_Address called, octetstring data) runs on SCCP_Test_RAW_CT {
154
155 f_send_sccp(ts_SCCP_UDT(calling, called, data));
156 f_exp_sccp(tr_SCCP_UDT(called, calling, data));
157}
158
Harald Welte9adf57b2020-01-10 12:33:44 +0100159/* Verify sccp_demo_user answers a CR with a CC for PC and SSN set up to echo back */
160testcase TC_cr_cc() runs on SCCP_Test_RAW_CT {
161 var SCCP_PAR_Address calling, called;
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100162
163 f_init_raw(mp_sccp_cfg[0]);
164 f_sleep(1.0);
165
Pau Espin Pedrole1870912020-01-17 17:30:19 +0100166 called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, mp_sccp_cfg[0].peer_ssn,
167 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
168 calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, mp_sccp_cfg[0].own_ssn,
169 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100170 f_establish_conn(calling, called);
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100171 setverdict(pass);
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100172}
173
Pau Espin Pedrolf7ba2342020-01-20 20:19:47 +0100174/* Verify sccp_demo_user answers a CR with a CC for PC and SSN set up to echo back */
175testcase TC_udt_without_cr_cc() runs on SCCP_Test_RAW_CT {
176 var SCCP_PAR_Address calling, called;
177 var octetstring data := f_rnd_octstring(f_rnd_int(100));
178
179 f_init_raw(mp_sccp_cfg[0]);
180 f_sleep(1.0);
181
182 called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, mp_sccp_cfg[0].peer_ssn,
183 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
184 calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, mp_sccp_cfg[0].own_ssn,
185 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
186
187 f_tx_udt_exp(calling, called, data);
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100188 setverdict(pass);
Pau Espin Pedrolf7ba2342020-01-20 20:19:47 +0100189}
190
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100191/* Verify T(iar) triggers and releases the channel */
192testcase TC_tiar_timeout() runs on SCCP_Test_RAW_CT {
193 var SCCP_PAR_Address calling, called;
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100194 var OCT3 remote_lref;
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100195 var octetstring data := f_rnd_octstring(f_rnd_int(100));
196
197 /* Set T(iar) in sccp_demo_user low enough that it will trigger before other side
198 has time to keep alive with a T(ias). Keep recommended ratio of
199 T(iar) >= T(ias)*2 */
200 g_demo_sccp_timer_ias := 2;
201 g_demo_sccp_timer_iar := 5;
Pau Espin Pedrole1870912020-01-17 17:30:19 +0100202 f_init_raw(mp_sccp_cfg[0]);
Harald Welte9adf57b2020-01-10 12:33:44 +0100203 f_sleep(1.0);
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100204
205 called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, mp_sccp_cfg[0].peer_ssn,
206 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
207 calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, mp_sccp_cfg[0].own_ssn,
208 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100209 remote_lref := f_establish_conn(calling, called);
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100210 f_tx_udt_exp(calling, called, data);
211
212 log("Waiting for first IT");
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100213 f_exp_sccp(tr_SCCP_IT(remote_lref, g_own_lref));
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100214 log("Waiting for second IT");
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100215 f_exp_sccp(tr_SCCP_IT(remote_lref, g_own_lref));
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100216
217 log("Waiting for RLSD");
Pau Espin Pedrol392eaf32020-01-21 12:21:05 +0100218 f_exp_sccp(tr_SCCP_RLSD(remote_lref, g_own_lref, hex2int('0D'H))); /* Cause: Expiration of Rx Inactivity Timer */
219 f_send_sccp(ts_SCCP_RLC(g_own_lref, remote_lref));
220 setverdict(pass);
Harald Welte9adf57b2020-01-10 12:33:44 +0100221}
222
223control {
224 execute( TC_cr_cc() );
Pau Espin Pedrolf7ba2342020-01-20 20:19:47 +0100225 execute( TC_udt_without_cr_cc() );
Pau Espin Pedrola2473da2020-01-20 13:20:58 +0100226 execute( TC_tiar_timeout() );
Harald Welte9adf57b2020-01-10 12:33:44 +0100227}
228
229
230}