blob: 3d1670692c5acf234f36c2653491b50eee946f6d [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;
41}
42
43private function f_init_raw(SCCP_Configuration cfg) runs on SCCP_Test_RAW_CT {
44 g_param := {
45 sio := {
46 ni := substr(oct2bit(cfg.sio),0,2),
47 prio := substr(oct2bit(cfg.sio),2,2),
48 si := substr(oct2bit(cfg.sio),4,4)
49 },
50 opc := cfg.own_pc,
51 dpc := cfg.peer_pc,
52 sls := 0,
53 sccp_serviceType := cfg.sccp_service_type,
54 ssn := cfg.own_ssn
55 };
56
57 map(self:SCCP_DEMO_USER_VTY, system:SCCP_DEMO_USER_VTY);
58 f_vty_set_prompts(SCCP_DEMO_USER_VTY);
59 f_vty_transceive(SCCP_DEMO_USER_VTY, "enable");
60
61 /* Create and connect test components */
62 vc_M3UA := M3UA_CT.create;
63 connect(self:MTP3, vc_M3UA:MTP3_SP_PORT);
64 map(vc_M3UA:SCTP_PORT, system:sctp);
65
66 vc_M3UA.start(f_M3UA_Emulation(cfg.sctp_addr));
67}
68
69private function f_cleanup() runs on SCCP_Test_RAW_CT {
70 all component.stop;
71 unmap(vc_M3UA:SCTP_PORT, system:sctp);
72 disconnect(vc_M3UA:MTP3_SP_PORT, self:MTP3);
73 self.stop
74}
75
76/* connection oriented SCCP */
77const SCCP_param_ProtocolClass c_class2 := { class:='0010'B, messageHandling:='0000'B };//class 2
78
79function ts_SCCP_CR(OCT3 source_lref, SCCP_PAR_Address calling, SCCP_PAR_Address called)
80return template (value) PDU_SCCP {
81 var SCCP_param_CPartyAddressEnc calling_enc := ConvertASPAddressToEncodedAddress_itu(calling);
82
83 var template (value) PDU_SCCP ret := {
84 connrequest := {
85 messageType := cr,
86 sourceLocRef := source_lref,
87 protClass := c_class2,
88 pointer1 := 2,
89 pointer2 := 0, /* overwritten */
90 calledPAddress := ConvertASPAddressToEncodedAddress_itu(called),
91 optionalPart := {
92 credit := omit,
93 callingPAddress := {
94 paramName := con_SCCP_cgPA,
95 paramLength := calling_enc.paramLength, /* overwritten */
96 addr := calling_enc.addr
97 },
98 data := omit,
99 hopCounter := omit,
100 importance := omit
101 },
102 eop := { paramName:= con_SCCP_eop }
103 }
104 }
105 return ret;
106}
107
108template (present) PDU_SCCP tr_SCCP_CC(template (present) OCT3 dest_lref,
109 template (present) OCT3 source_lref) := {
110 connconfirm := {
111 messageType := cc,
112 destLocRef := dest_lref,
113 sourceLocRef := source_lref,
114 protClass := c_class2,
115 pointer1 := ?,
116 optionalPart := *,
117 eop := *
118 }
119}
120
121private function f_send_sccp(template PDU_SCCP sccp) runs on SCCP_Test_RAW_CT {
122 var SCCP_MTP3_TRANSFERreq tx := {
123 sio := g_param.sio,
124 opc := g_param.opc,
125 dpc := g_param.dpc,
126 sls := g_param.sls,
127 data := valueof(sccp)
128 };
129 MTP3.send(tx);
130}
131
132private function f_exp_sccp(template PDU_SCCP sccp) runs on SCCP_Test_RAW_CT {
133 var SCCP_MTP3_TRANSFERind rx;
134 var template SCCP_MTP3_TRANSFERind exp := {
135 sio := g_param.sio,
136 opc := g_param.dpc,
137 dpc := g_param.opc,
138 sls := g_param.sls,
139 data := sccp
140 };
141 timer T := 10.0;
142 T.start;
143 alt {
144 [] MTP3.receive(exp) -> value rx {
145 setverdict(pass);
146 }
147 [] MTP3.receive {
148 setverdict(fail, "Unexpected MTP/SCCP received");
Pau Espin Pedrol94b7a682020-01-20 19:30:07 +0100149 self.stop
Harald Welte9adf57b2020-01-10 12:33:44 +0100150 }
151 [] T.timeout {
152 setverdict(fail, "Timeout waiting for ", exp);
Pau Espin Pedrol94b7a682020-01-20 19:30:07 +0100153 self.stop
Harald Welte9adf57b2020-01-10 12:33:44 +0100154 }
155 }
156}
157
158/* Verify sccp_demo_user answers a CR with a CC for PC and SSN set up to echo back */
159testcase TC_cr_cc() runs on SCCP_Test_RAW_CT {
160 var SCCP_PAR_Address calling, called;
Pau Espin Pedrole1870912020-01-17 17:30:19 +0100161 called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, mp_sccp_cfg[0].peer_ssn,
162 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
163 calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, mp_sccp_cfg[0].own_ssn,
164 mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type));
165 f_init_raw(mp_sccp_cfg[0]);
Harald Welte9adf57b2020-01-10 12:33:44 +0100166 f_sleep(1.0);
167 f_send_sccp(ts_SCCP_CR('000001'O, calling, called));
168 f_exp_sccp(tr_SCCP_CC('000001'O, ?));
169}
170
171control {
172 execute( TC_cr_cc() );
173}
174
175
176}