blob: 58f2704833476bcd8ebe9d5cc7dc442335954354 [file] [log] [blame]
Harald Welte28d943e2017-11-25 15:00:50 +01001module BSC_Tests {
2
Harald Welte21b46bd2017-12-17 19:46:32 +01003/* Integration Tests for OsmoBSC
Harald Weltea0630032018-03-20 21:09:55 +01004 * (C) 2017-2018 by Harald Welte <laforge@gnumonks.org>
Harald Welte21b46bd2017-12-17 19:46:32 +01005 * All rights reserved.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
10 * This test suite tests OsmoBSC while emulating both multiple BTS + MS as
11 * well as the MSC. See README for more details.
12 *
13 * There are test cases that run in so-called 'handler mode' and test cases
14 * that run directly on top of the BSSAP and RSL CodecPorts. The "handler mode"
15 * tests abstract the multiplexing/demultiplexing of multiple SCCP connections
16 * and/or RSL channels and are hence suitable for higher-level test cases, while
17 * the "raw" tests directly on top of the CodecPorts are more suitable for lower-
18 * level testing.
19 */
20
Harald Welte4003d112017-12-09 22:35:39 +010021import from General_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010022import from Osmocom_Types all;
Harald Welteae026692017-12-09 01:03:01 +010023import from GSM_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010024import from IPL4asp_Types all;
25
Harald Welte6f521d82017-12-11 19:52:02 +010026import from BSSAP_Types all;
Harald Welteae026692017-12-09 01:03:01 +010027import from BSSAP_Adapter all;
28import from BSSAP_CodecPort all;
29import from BSSMAP_Templates all;
Harald Welte28d943e2017-11-25 15:00:50 +010030import from IPA_Emulation all;
Stefan Sperling830dc9d2018-02-12 21:08:28 +010031import from IPA_CodecPort all;
Harald Welteae026692017-12-09 01:03:01 +010032import from IPA_Types all;
33import from RSL_Types all;
Harald Welte624f9632017-12-16 19:26:04 +010034import from RSL_Emulation all;
Daniel Willmann191e0d92018-01-17 12:44:35 +010035import from MGCP_Emulation all;
Harald Welte28d943e2017-11-25 15:00:50 +010036
Harald Welte96c94412017-12-09 03:12:45 +010037import from Osmocom_CTRL_Functions all;
Harald Weltea5d2ab22017-12-09 14:21:42 +010038import from Osmocom_CTRL_Types all;
Harald Welteffe55fc2018-01-17 22:39:54 +010039import from Osmocom_CTRL_Adapter all;
Harald Welte96c94412017-12-09 03:12:45 +010040
Harald Weltebc03c762018-02-12 18:09:38 +010041import from Osmocom_VTY_Functions all;
42import from TELNETasp_PortType all;
43
Harald Welte6f521d82017-12-11 19:52:02 +010044import from MobileL3_CommonIE_Types all;
Harald Weltee3bd6582018-01-31 22:51:25 +010045import from MobileL3_Types all;
Harald Welte6f521d82017-12-11 19:52:02 +010046import from L3_Templates all;
47import from GSM_RR_Types all;
48
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010049import from BSSMAP_Templates all;
50
Harald Welte5d1a2202017-12-13 19:51:29 +010051const integer NUM_BTS := 3;
Harald Welteae026692017-12-09 01:03:01 +010052const float T3101_MAX := 12.0;
Harald Welte28d943e2017-11-25 15:00:50 +010053
Harald Welte799c97b2017-12-14 17:50:30 +010054/* make sure to sync this with the osmo-bts.cfg you're using */
Philipp Maiercb6cc482018-03-26 13:08:00 +020055const integer NUM_TCHH_PER_BTS := 2;
56const integer NUM_TCHF_PER_BTS := 4;
Harald Weltedd8cbf32018-01-28 12:07:52 +010057const integer NUM_SDCCH_PER_BTS := 4;
Harald Welte799c97b2017-12-14 17:50:30 +010058
Harald Welte4003d112017-12-09 22:35:39 +010059
Harald Welte21b46bd2017-12-17 19:46:32 +010060/* per-BTS state which we keep */
Harald Welte96c94412017-12-09 03:12:45 +010061type record BTS_State {
Harald Welte21b46bd2017-12-17 19:46:32 +010062 /* component reference to the IPA_Client component used for RSL */
Harald Weltea5d2ab22017-12-09 14:21:42 +010063 IPA_Client rsl
Harald Welte96c94412017-12-09 03:12:45 +010064}
65
Harald Weltea4ca4462018-02-09 00:17:14 +010066type component test_CT extends CTRL_Adapter_CT {
Harald Welte21b46bd2017-12-17 19:46:32 +010067 /* Array of per-BTS state */
Harald Welte96c94412017-12-09 03:12:45 +010068 var BTS_State bts[NUM_BTS];
Harald Welte89ab1912018-02-23 18:56:29 +010069 /* RSL common Channel Port (for RSL_Emulation) */
70 port RSL_CCHAN_PT RSL_CCHAN[NUM_BTS];
Harald Welte21b46bd2017-12-17 19:46:32 +010071 /* array of per-BTS RSL test ports */
Harald Welteae026692017-12-09 01:03:01 +010072 port IPA_RSL_PT IPA_RSL[NUM_BTS];
Stefan Sperling830dc9d2018-02-12 21:08:28 +010073 port IPA_CODEC_PT IPA; /* Required for compilation of TC_rsl_unknown_unit_id() */
Harald Weltea5d2ab22017-12-09 14:21:42 +010074
Daniel Willmann191e0d92018-01-17 12:44:35 +010075 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +010076 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +010077
Harald Weltea4ca4462018-02-09 00:17:14 +010078 var BSSAP_Adapter g_bssap;
79 /* for old legacy-tests only */
80 port BSSAP_CODEC_PT BSSAP;
81
Harald Welte21b46bd2017-12-17 19:46:32 +010082 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +010083 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +010084
85 /* global test case guard timer */
Harald Welteae026692017-12-09 01:03:01 +010086 timer T_guard := 30.0;
87
Harald Welte28d943e2017-11-25 15:00:50 +010088}
89
90modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +010091 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +010092 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +010093 /* port number to which to establish the IPA OML connections */
94 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +010095 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +010096 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +010097 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +010098 integer mp_bsc_ctrl_port := 4249;
Daniel Willmann191e0d92018-01-17 12:44:35 +010099 /* IP address at which the test binds */
100 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100101
102 BSSAP_Configuration mp_bssap_cfg := {
Harald Welte7ef51aa2018-04-16 19:16:01 +0200103 transport := BSSAP_TRANSPORT_AoIP,
Harald Weltea4ca4462018-02-09 00:17:14 +0100104 sccp_service_type := "mtp3_itu",
105 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
106 own_pc := 185,
107 own_ssn := 254,
108 peer_pc := 187,
109 peer_ssn := 254,
Philipp Maier38d68942018-03-29 15:38:09 +0200110 sio := '83'O,
111 rctx := 0
Harald Weltea4ca4462018-02-09 00:17:14 +0100112 };
113}
114
Philipp Maier282ca4b2018-02-27 17:17:00 +0100115private function f_shutdown_helper() runs on test_CT {
Harald Welte12055472018-03-17 20:10:08 +0100116 for (var integer i := 0; i < NUM_BTS; i := i+1) {
117 if (isbound(bts[i]) and isbound(bts[i].rsl)) {
118 f_ipa_rsl_stop(bts[i].rsl);
119 }
120 }
121 f_ipa_ctrl_stop();
Philipp Maier282ca4b2018-02-27 17:17:00 +0100122 all port.stop;
123 setverdict(pass);
124}
125
Harald Weltea4ca4462018-02-09 00:17:14 +0100126private function f_legacy_bssap_reset() runs on test_CT {
127 var BSSAP_N_UNITDATA_ind ud_ind;
128 timer T := 5.0;
129 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, ts_BSSMAP_Reset(0)));
130 T.start;
131 alt {
132 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap.sccp_addr_own, g_bssap.sccp_addr_peer, tr_BSSMAP_ResetAck)) {
133 log("Received RESET-ACK in response to RESET, we're ready to go!");
134 }
135 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) -> value ud_ind {
136 log("Respoding to inbound RESET with RESET-ACK");
137 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
138 ts_BSSMAP_ResetAck));
139 repeat;
140 }
141 [] BSSAP.receive { repeat; }
142 [] T.timeout { setverdict(fail, "Waiting for RESET-ACK after sending RESET"); }
143 }
Harald Welte28d943e2017-11-25 15:00:50 +0100144}
145
Harald Welteae026692017-12-09 01:03:01 +0100146type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100147 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100148 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100149 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100150 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100151 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100152 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100153 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100154 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100155}
156
Harald Welte21b46bd2017-12-17 19:46:32 +0100157/*! Start the IPA/RSL related bits for one IPA_Client.
158 * \param clnt IPA_Client for which to establish
159 * \param bsc_host IP address / hostname of the BSC
160 * \param bsc_port TCP port number of the BSC
161 * \param i number identifying this BTS
162 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100163function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
164 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100165runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100166 timer T := 10.0;
167
Harald Welte96c94412017-12-09 03:12:45 +0100168 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welteae026692017-12-09 01:03:01 +0100169 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA");
170 clnt.ccm_pars := c_IPA_default_ccm_pars;
171 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
172 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100173 if (handler_mode) {
174 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL");
Harald Welte89ab1912018-02-23 18:56:29 +0100175 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100176 }
Harald Welteae026692017-12-09 01:03:01 +0100177
178 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Harald Welte624f9632017-12-16 19:26:04 +0100179 if (handler_mode) {
180 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
181 } else {
182 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
183 }
Harald Welteae026692017-12-09 01:03:01 +0100184
Harald Welte5d1a2202017-12-13 19:51:29 +0100185 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100186 if (handler_mode) {
187 clnt.vc_RSL.start(RSL_Emulation.main());
188 return;
189 }
Harald Welteae026692017-12-09 01:03:01 +0100190
191 /* wait for IPA RSL link to connect and send ID ACK */
192 T.start;
193 alt {
194 [] IPA_RSL[i].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_ID_ACK}) {
195 T.stop;
196 IPA_RSL[i].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_PAGING_LOAD_IND(23)));
197 }
Harald Welte60e823a2017-12-10 14:10:59 +0100198 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100199 [] IPA_RSL[i].receive { repeat }
200 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100201 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Harald Welteae026692017-12-09 01:03:01 +0100202 self.stop;
203 }
204 }
205}
206
Harald Welte12055472018-03-17 20:10:08 +0100207function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
208 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
209 return;
210 }
211 clnt.vc_IPA.stop;
212 if (isbound(clnt.vc_RSL)) {
213 clnt.vc_RSL.stop;
214 }
215}
216
Harald Welte21b46bd2017-12-17 19:46:32 +0100217/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100218function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
219 timer T := secs_max;
220 T.start;
221 while (true) {
222 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
223 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100224 /* the 'degraded' state exists from OML connection time, and we have to wait
225 * until all MO's are initialized */
226 T.start(1.0);
227 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100228 return;
229 }
Harald Weltef0d6ac62017-12-17 17:02:21 +0100230 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100231 if (not T.running) {
232 setverdict(fail, "Timeout waiting for oml-connection-state ", status);
233 self.stop;
234 }
235 }
236}
237
Harald Welte21b46bd2017-12-17 19:46:32 +0100238/* sleep for given number of (fractional) seconds */
Harald Welteae026692017-12-09 01:03:01 +0100239function f_sleep(float seconds) {
240 timer T := seconds;
241 T.start;
242 T.timeout;
243}
244
Harald Welte21b46bd2017-12-17 19:46:32 +0100245/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +0100246altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +0100247 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100248 [] T_guard.timeout {
249 setverdict(fail, "Timeout of T_guard");
250 self.stop;
251 }
Harald Welte60e823a2017-12-10 14:10:59 +0100252 /* always respond with RESET ACK to RESET */
253 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) -> value ud_ind {
254 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
255 ts_BSSMAP_ResetAck));
Harald Welte69c1c262017-12-13 21:02:08 +0100256 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +0100257 }
Harald Welte28d943e2017-11-25 15:00:50 +0100258}
259
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100260altstep no_bssmap_reset() runs on test_CT {
261 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) {
262 setverdict(fail, "unexpected BSSMAP Reset");
263 self.stop;
264 }
265}
266
Daniel Willmann191e0d92018-01-17 12:44:35 +0100267function f_init_mgcp(charstring id) runs on test_CT {
268 id := id & "-MGCP";
269
270 var MGCPOps ops := {
271 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
272 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
273 };
274 var MGCP_conn_parameters mgcp_pars := {
275 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +0100276 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +0100277 mgw_ip := mp_test_ip,
278 mgw_udp_port := 2427
279 };
280
281 vc_MGCP := MGCP_Emulation_CT.create(id);
282 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
283}
284
Harald Welte94e0c342018-04-07 11:33:23 +0200285private function f_init_vty(charstring id := "foo") runs on test_CT {
286 if (BSCVTY.checkstate("Mapped")) {
287 /* skip initialization if already executed once */
288 return;
289 }
Harald Weltebc03c762018-02-12 18:09:38 +0100290 map(self:BSCVTY, system:BSCVTY);
291 f_vty_set_prompts(BSCVTY);
292 f_vty_transceive(BSCVTY, "enable");
293}
294
Harald Welte21b46bd2017-12-17 19:46:32 +0100295/* global initialization function
296 * \param nr_bts Number of BTSs we should start/bring up
297 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte89d42e82017-12-17 16:42:41 +0100298function f_init(integer nr_bts := NUM_BTS, boolean handler_mode := false) runs on test_CT {
Harald Welte28d943e2017-11-25 15:00:50 +0100299 var integer i;
Harald Welte28d943e2017-11-25 15:00:50 +0100300
Harald Welteae026692017-12-09 01:03:01 +0100301 if (g_initialized) {
302 return;
Harald Welte28d943e2017-11-25 15:00:50 +0100303 }
Harald Welteae026692017-12-09 01:03:01 +0100304 g_initialized := true;
305
306 /* Call a function of our 'parent component' BSSAP_Adapter_CT to start the
307 * MSC-side BSSAP emulation */
Harald Welte67089ee2018-01-17 22:19:03 +0100308 if (handler_mode) {
Harald Weltea4ca4462018-02-09 00:17:14 +0100309 f_bssap_init(g_bssap, mp_bssap_cfg, "VirtMSC", MSC_BssmapOps);
Harald Welte4bcbd172018-05-27 19:47:44 +0200310 f_bssap_start(g_bssap);
Harald Welte67089ee2018-01-17 22:19:03 +0100311 } else {
Harald Weltea4ca4462018-02-09 00:17:14 +0100312 f_bssap_init(g_bssap, mp_bssap_cfg, "VirtMSC", omit);
313 connect(self:BSSAP, g_bssap.vc_SCCP:SCCP_SP_PORT);
Harald Welte4bcbd172018-05-27 19:47:44 +0200314 f_bssap_start(g_bssap);
Harald Weltea4ca4462018-02-09 00:17:14 +0100315 f_legacy_bssap_reset();
Harald Welte67089ee2018-01-17 22:19:03 +0100316 }
Harald Welted5833a82018-05-27 16:52:56 +0200317
Harald Welteffe55fc2018-01-17 22:39:54 +0100318 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +0100319
Daniel Willmann191e0d92018-01-17 12:44:35 +0100320 f_init_mgcp("VirtMSC");
Harald Weltebc03c762018-02-12 18:09:38 +0100321 f_init_vty("VirtMSC");
Daniel Willmann191e0d92018-01-17 12:44:35 +0100322
Harald Welte89d42e82017-12-17 16:42:41 +0100323 for (i := 0; i < nr_bts; i := i+1) {
Harald Weltea5d2ab22017-12-09 14:21:42 +0100324 /* wait until osmo-bts-omldummy has respawned */
325 f_wait_oml(i, "degraded", 5.0);
326 /* start RSL connection */
Harald Welte624f9632017-12-16 19:26:04 +0100327 f_ipa_rsl_start(bts[i].rsl, mp_bsc_ip, mp_bsc_rsl_port, i, handler_mode);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100328 /* wait until BSC tells us "connected" */
329 f_wait_oml(i, "connected", 5.0);
Harald Welte696ddb62017-12-08 14:01:43 +0100330 }
331
Harald Welteae026692017-12-09 01:03:01 +0100332 T_guard.start;
333 activate(as_Tguard());
Harald Welte28d943e2017-11-25 15:00:50 +0100334}
335
Harald Welte21b46bd2017-12-17 19:46:32 +0100336/* expect to receive a RSL message matching a specified templaten on a given BTS / stream */
Harald Welteae026692017-12-09 01:03:01 +0100337function f_exp_ipa_rx(integer bts_nr, template RSL_Message t_rx, float t_secs := 2.0, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
338runs on test_CT return RSL_Message {
339 var ASP_RSL_Unitdata rx_rsl_ud;
340 timer T := t_secs;
341
342 T.start;
343 alt {
344 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(sid, t_rx)) -> value rx_rsl_ud {
345 T.stop;
346 }
347 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +0100348 [] T.timeout {
349 setverdict(fail, "Timeout expecting ", t_rx);
350 self.stop;
351 }
Harald Welteae026692017-12-09 01:03:01 +0100352 }
353 return rx_rsl_ud.rsl;
354}
355
Harald Welte21b46bd2017-12-17 19:46:32 +0100356/* helper function to transmit RSL on a given BTS/stream */
Harald Welteae026692017-12-09 01:03:01 +0100357function f_ipa_tx(integer bts_nr, template RSL_Message t_tx, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
358runs on test_CT {
359 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(sid, t_tx));
360}
361
362
Harald Welte4003d112017-12-09 22:35:39 +0100363/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +0100364testcase TC_chan_act_noreply() runs on test_CT {
365 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +0100366 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +0100367
Harald Welte89d42e82017-12-17 16:42:41 +0100368 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +0100369
Harald Welteae026692017-12-09 01:03:01 +0100370 IPA_RSL[0].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +0100371 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welteae026692017-12-09 01:03:01 +0100372 setverdict(pass);
Harald Welte28d943e2017-11-25 15:00:50 +0100373}
374
Harald Welte4003d112017-12-09 22:35:39 +0100375/* verify if the "chreq:total" counter increments as expected */
376testcase TC_chan_act_counter() runs on test_CT {
377 var BSSAP_N_UNITDATA_ind ud_ind;
378 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +0100379 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +0100380
Harald Welte89d42e82017-12-17 16:42:41 +0100381 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100382
383 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
384 IPA_RSL[0].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +0100385 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welte4003d112017-12-09 22:35:39 +0100386 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total", chreq_total+1);
387
388 setverdict(pass);
389}
390
Harald Welteae026692017-12-09 01:03:01 +0100391/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
392testcase TC_chan_act_ack_noest() runs on test_CT {
393 var RSL_Message rx_rsl;
394
Harald Welte89d42e82017-12-17 16:42:41 +0100395 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100396
397 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100398 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100399
400 /* expect BSC to disable the channel again if there's no RLL EST IND */
401 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
402
403 setverdict(pass);
404}
405
406/* Test behavior if MSC never answers to CR */
407testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +0100408 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
409 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +0100410 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +0100411 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +0100412
Harald Welte89d42e82017-12-17 16:42:41 +0100413 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100414
415 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100416 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100417
418 var octetstring l3 := '00010203040506'O
419 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
420
421 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
422
423 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +0100424 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
425 IPA_RSL[0].clear;
426 alt {
427 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(sid, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) -> value rx_rsl_ud { }
428 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(sid, tr_RSL_REL_REQ(chan_nr, ?))) -> value rx_rsl_ud {
429 f_ipa_tx(0, ts_RSL_REL_CONF(chan_nr, main_dcch));
430 repeat;
431 }
432 }
Harald Welteae026692017-12-09 01:03:01 +0100433
434 setverdict(pass);
435}
436
437/* Test behavior if MSC answers with CREF to CR */
438testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
439 var BSSAP_N_CONNECT_ind rx_c_ind;
440 var RSL_Message rx_rsl;
441
Harald Welte89d42e82017-12-17 16:42:41 +0100442 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100443
444 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100445 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100446
447 var octetstring l3 := '00010203040506'O
448 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
449
450 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
451 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
452
453 /* expect BSC to disable the channel */
Harald Welte725844b2018-01-28 16:18:32 +0100454 f_expect_chan_rel(0, chan_nr);
Harald Welteae026692017-12-09 01:03:01 +0100455 setverdict(pass);
456}
457
Harald Welte618ef642017-12-14 14:58:20 +0100458/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
459testcase TC_chan_act_nack() runs on test_CT {
460 var RSL_Message rx_rsl;
461 var integer chact_nack;
462
Harald Welte89d42e82017-12-17 16:42:41 +0100463 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +0100464
465 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
466
467 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
468 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
469 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
470
471 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
472
473 /* wait for some time to hope the NACK arrives before the CTRL GET below */
474 f_sleep(0.5);
475
476 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
477
478 setverdict(pass);
479}
480
Harald Welte799c97b2017-12-14 17:50:30 +0100481/* Test for channel exhaustion due to RACH overload */
482testcase TC_chan_exhaustion() runs on test_CT {
483 var ASP_RSL_Unitdata rsl_ud;
484 var integer i;
485 var integer chreq_total, chreq_nochan;
486
Harald Welte89d42e82017-12-17 16:42:41 +0100487 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +0100488
489 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
490 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
491
492 /* expect 5xTCH/F to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +0200493 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS; i := i+1) {
Harald Welte930d0a72018-03-22 22:08:40 +0100494 var RslChannelNr chan_nr := f_chreq_act_ack('23'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +0100495 }
496
497 IPA_RSL[0].clear;
498
Harald Weltedd8cbf32018-01-28 12:07:52 +0100499 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200500 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +0100501
502 /* now expect additional channel activations to fail */
503 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
504
505 alt {
506 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
507 tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
508 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
509 }
510 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
511 var GsmRrMessage rr;
512 /* match on IMM ASS REJ */
513 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
514 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
515 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200516 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +0100517 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
518 chreq_nochan+1);
519 setverdict(pass);
520 } else {
521 repeat;
522 }
523 }
524 [] IPA_RSL[0].receive { repeat; }
525 }
526}
527
Harald Weltecfe2c962017-12-15 12:09:32 +0100528/***********************************************************************
529 * Assignment Testing
530 ***********************************************************************/
531
532/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction) */
533testcase TC_outbound_connect() runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +0100534 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +0100535
Harald Weltea4ca4462018-02-09 00:17:14 +0100536 BSSAP.send(ts_BSSAP_CONNECT_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, 2342, ts_BSSMAP_AssignmentReq));
Harald Weltecfe2c962017-12-15 12:09:32 +0100537 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
538 setverdict(pass);
539}
540
Harald Welte16a4adf2017-12-14 18:54:01 +0100541/* Test behavior if MSC answers with CREF to CR */
542testcase TC_assignment_cic_only() runs on test_CT {
543 var BSSAP_N_CONNECT_ind rx_c_ind;
544 var RSL_Message rx_rsl;
545 var DchanTuple dt;
546
Harald Welte89d42e82017-12-17 16:42:41 +0100547 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +0100548
549 dt := f_est_dchan('23'O, 23, '00000000'O);
Harald Welte17b27da2018-05-25 20:33:53 +0200550 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
551 /* send assignment without AoIP IEs */
552 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
553 } else {
554 /* Send assignmetn without CIC in IPA case */
555 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
556 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
557 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
558 }
Harald Welte16a4adf2017-12-14 18:54:01 +0100559 alt {
560 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
561 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
562 }
Harald Welte235ebf12017-12-15 14:18:16 +0100563 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +0100564 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
565 setverdict(pass);
566 }
567 [] BSSAP.receive { repeat; }
568 }
569}
570
Harald Welteed848512018-05-24 22:27:58 +0200571/* generate an assignment request for either AoIP or SCCPlite */
572private function f_gen_ass_req() return PDU_BSSAP {
573 var PDU_BSSAP ass_cmd;
574 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
575 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
576 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
577 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
578 } else {
579 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
580 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
581 }
582 return ass_cmd;
583}
584
585/* generate an assignment complete template for either AoIP or SCCPlite */
586private function f_gen_exp_compl() return template PDU_BSSAP {
587 var template PDU_BSSAP exp_compl;
588 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
589 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?);
590 } else {
591 /* CIC is optional "*" as the MSC allocated it */
592 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
593 }
594 return exp_compl;
595}
596
Harald Welte235ebf12017-12-15 14:18:16 +0100597/* Run everything required up to sending a caller-specified assignment command and expect response */
598function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
599runs on test_CT {
600 var BSSAP_N_CONNECT_ind rx_c_ind;
601 var RSL_Message rx_rsl;
602 var DchanTuple dt;
603
Harald Welte89d42e82017-12-17 16:42:41 +0100604 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +0100605
606 dt := f_est_dchan('23'O, 23, '00000000'O);
607 /* send assignment without AoIP IEs */
608 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
609 alt {
610 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
611 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
612 setverdict(pass);
613 } else {
614 setverdict(fail, fail_text);
615 }
616 }
617 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
618 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
619 setverdict(pass);
620 } else {
621 setverdict(fail, fail_text);
622 }
623 }
624 [] BSSAP.receive { repeat; }
625 }
626}
627testcase TC_assignment_csd() runs on test_CT {
628 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200629 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100630 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
631 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
632 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
633}
634
635testcase TC_assignment_ctm() runs on test_CT {
636 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200637 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100638 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
639 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
640 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
641}
642
Harald Welte4003d112017-12-09 22:35:39 +0100643type record DchanTuple {
644 integer sccp_conn_id,
645 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +0100646}
647
Harald Welted6939652017-12-13 21:02:46 +0100648/* Send CHAN RQD and wait for allocation; acknowledge it */
649private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
650runs on test_CT return RslChannelNr {
651 var RSL_Message rx_rsl;
652 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
653 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
654 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
655 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
656 return chan_nr;
657}
658
Harald Welte4003d112017-12-09 22:35:39 +0100659/* helper function to establish a dedicated channel via BTS and MSC */
660function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
661runs on test_CT return DchanTuple {
662 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +0100663 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100664
Harald Welte4003d112017-12-09 22:35:39 +0100665 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100666 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +0100667
668 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
669
670 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
671 dt.sccp_conn_id := rx_c_ind.connectionId;
672 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
673
674 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100675}
676
Harald Welte4003d112017-12-09 22:35:39 +0100677/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
678testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
679 var RSL_Message rx_rsl;
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100680 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100681 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +0100682
Harald Welte89d42e82017-12-17 16:42:41 +0100683 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +0100684
Harald Welte4003d112017-12-09 22:35:39 +0100685 dt := f_est_dchan('23'O, 23, '00010203040506'O);
686
687 /* simulate RLL REL IND */
688 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
689
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100690 /* expect Clear Request on MSC side */
691 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
692
693 /* Instruct BSC to clear channel */
694 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
695 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
696
Harald Welte4003d112017-12-09 22:35:39 +0100697 /* expect BSC to disable the channel */
698 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
699 /* respond with CHAN REL ACK */
700 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
701
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100702 /* expect Clear Complete from BSC */
703 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
704
705 /* release the SCCP connection */
706 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
707
708 /* wait for SCCP emulation to do its job */
709 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +0100710
711 setverdict(pass);
712}
713
714/* Test behavior of channel release after CONN FAIL IND from BTS */
715testcase TC_chan_rel_conn_fail() runs on test_CT {
716 var BSSAP_N_DATA_ind rx_di;
717 var RSL_Message rx_rsl;
718 var DchanTuple dt;
719
Harald Welte89d42e82017-12-17 16:42:41 +0100720 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100721
722 dt := f_est_dchan('23'O, 23, '00010203040506'O);
723
724 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +0100725 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
Harald Welte4003d112017-12-09 22:35:39 +0100726 /* TODO: different cause values? */
727
Harald Welte4003d112017-12-09 22:35:39 +0100728 /* expect Clear Request from BSC */
729 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
730
731 /* Instruct BSC to clear channel */
732 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
733 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
734
Harald Welte6ff76ea2018-01-28 13:08:01 +0100735 /* expect BSC to disable the channel */
736 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
737 /* respond with CHAN REL ACK */
738 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
739
Harald Welte4003d112017-12-09 22:35:39 +0100740 /* expect Clear Complete from BSC */
741 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
742
743 /* release the SCCP connection */
744 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
745
746 /* wait for SCCP emulation to do its job */
747 f_sleep(1.0);
748
749 setverdict(pass);
750}
751
Harald Welte91d54a52018-01-28 15:35:07 +0100752function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr, boolean flush := true,
753 boolean handle_rll_rel := true) runs on test_CT {
754
755 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
756 if (flush) {
757 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
758 IPA_RSL[bts_nr].clear;
759 }
760 alt {
761 /* ignore DEACTIVATE SACCH (if any) */
762 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
763 tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
764 repeat;
765 }
766 /* acknowledge RLL release (if any)*/
767 [handle_rll_rel] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
768 tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
769 /* FIXME: Why are we getting this for LinkID SACCH? */
770 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
771 repeat;
772 }
773 /* Expect RF channel release from BSC on Abis */
774 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
775 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
776 /* respond with CHAN REL ACK */
777 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
778 }
779 /* ignore any user data */
780 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_MsgTypeR(?))) {
781 repeat;
782 }
783 }
784}
785
Harald Welte4003d112017-12-09 22:35:39 +0100786/* Test behavior of channel release after hard Clear Command from MSC */
787testcase TC_chan_rel_hard_clear() runs on test_CT {
788 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100789 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +0100790
Harald Welte89d42e82017-12-17 16:42:41 +0100791 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100792
793 dt := f_est_dchan('23'O, 23, '00010203040506'O);
794
795 /* Instruct BSC to clear channel */
796 var BssmapCause cause := 0;
797 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
798
799 /* expect Clear Complete from BSC on A */
800 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
801 /* release the SCCP connection */
802 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
803 }
804
Harald Welte91d54a52018-01-28 15:35:07 +0100805 f_expect_chan_rel(0, dt.rsl_chan_nr);
Harald Welte4003d112017-12-09 22:35:39 +0100806 setverdict(pass);
807}
808
Harald Welted8c36cd2017-12-09 23:05:31 +0100809/* Test behavior of channel release after hard RLSD from MSC */
810testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +0100811 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +0100812
Harald Welte89d42e82017-12-17 16:42:41 +0100813 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +0100814
815 dt := f_est_dchan('23'O, 23, '00010203040506'O);
816
817 /* release the SCCP connection */
818 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
819
Harald Welte91d54a52018-01-28 15:35:07 +0100820 f_expect_chan_rel(0, dt.rsl_chan_nr);
Harald Welted8c36cd2017-12-09 23:05:31 +0100821 setverdict(pass);
822}
823
Harald Welte85804d42017-12-10 14:11:58 +0100824/* Test behavior of channel release after BSSMAP RESET from MSC */
825testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +0100826 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +0100827
Harald Welte89d42e82017-12-17 16:42:41 +0100828 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +0100829
830 dt := f_est_dchan('23'O, 23, '00010203040506'O);
831
832 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
833 IPA_RSL[0].clear;
834
835 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Harald Weltea4ca4462018-02-09 00:17:14 +0100836 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, ts_BSSMAP_Reset(0)));
Harald Welte85804d42017-12-10 14:11:58 +0100837 interleave {
Harald Weltea4ca4462018-02-09 00:17:14 +0100838 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap.sccp_addr_own, g_bssap.sccp_addr_peer, tr_BSSMAP_ResetAck)) { }
Harald Welte85804d42017-12-10 14:11:58 +0100839 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
840 }
841
Philipp Maiere8f38ed2018-02-09 10:30:31 +0100842 f_expect_chan_rel(0, dt.rsl_chan_nr, false);
Harald Welte85804d42017-12-10 14:11:58 +0100843 setverdict(pass);
844}
845
Harald Welte5cd20ed2017-12-13 21:03:20 +0100846/* Test behavior if RSL EST IND for non-active channel */
847testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
848 timer T := 2.0;
849
Harald Welte89d42e82017-12-17 16:42:41 +0100850 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100851
852 var octetstring l3 := '00010203040506'O;
853 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
854 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
855
856 T.start;
857 alt {
858 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
859 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
860 }
861 [] BSSAP.receive {}
862 [] IPA_RSL[0].receive {}
863 [] T.timeout {}
864 }
865
866 setverdict(pass);
867}
868
869/* Test behavior if RSL EST IND for invalid SAPI */
870testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
871 var RslChannelNr chan_nr;
872
Harald Welte89d42e82017-12-17 16:42:41 +0100873 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100874
875 chan_nr := f_chreq_act_ack()
876
877 var octetstring l3 := '00010203040506'O;
878 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
879
880 timer T := 2.0;
881 T.start;
882 alt {
883 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
884 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
885 }
886 [] BSSAP.receive { repeat; }
887 [] IPA_RSL[0].receive { repeat; }
888 [] T.timeout {}
889 }
890
891 setverdict(pass);
892}
893
894/* Test behavior if RSL EST IND for invalid SAPI */
895testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
896 timer T := 2.0;
897
Harald Welte89d42e82017-12-17 16:42:41 +0100898 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100899
900 var RslChannelNr chan_nr := f_chreq_act_ack();
901
902 var octetstring l3 := '00010203040506'O;
903 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
904
905 T.start;
906 alt {
907 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
908 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
909 }
910 [] BSSAP.receive { repeat; }
911 [] IPA_RSL[0].receive { repeat; }
912 [] T.timeout {}
913 }
914
915 setverdict(pass);
916}
917
918/* Test behavior if RSL EST IND for invalid SACCH */
919testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
920 timer T := 2.0;
921
Harald Welte89d42e82017-12-17 16:42:41 +0100922 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100923
924 var RslChannelNr chan_nr := f_chreq_act_ack();
925
926 var octetstring l3 := '00010203040506'O;
927 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
928
929 T.start;
930 alt {
931 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
932 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
933 }
934 [] BSSAP.receive { repeat; }
935 [] IPA_RSL[0].receive { repeat; }
936 [] T.timeout {}
937 }
938
939 setverdict(pass);
940}
941
942
943
Harald Welte4003d112017-12-09 22:35:39 +0100944
945testcase TC_ctrl_msc_connection_status() runs on test_CT {
946 var charstring ctrl_resp;
947
Harald Welte89d42e82017-12-17 16:42:41 +0100948 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100949
950 /* See https://osmocom.org/issues/2729 */
951 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
952 setverdict(pass);
953}
954
Stefan Sperlingb041b3d2018-01-03 17:14:55 +0100955testcase TC_ctrl_msc0_connection_status() runs on test_CT {
956 var charstring ctrl_resp;
957
958 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +0100959
960 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
961 setverdict(pass);
962}
963
Harald Welte4003d112017-12-09 22:35:39 +0100964testcase TC_ctrl() runs on test_CT {
965 var charstring ctrl_resp;
966
Harald Welte89d42e82017-12-17 16:42:41 +0100967 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100968
969 /* all below values must match the osmo-bsc.cfg config file used */
970
Harald Welte6a129692018-03-17 17:30:14 +0100971 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
972 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Harald Welte44bdaa52017-12-17 17:01:47 +0100973 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "3");
Harald Welte4003d112017-12-09 22:35:39 +0100974
975 var integer bts_nr := 0;
976 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
977 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
978 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
979 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
980 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
981 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
982 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
983
984 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
985 f_sleep(2.0);
986 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
987 setverdict(fail, "oml-uptime not incrementing as expected");
988 }
989 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
990
991 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
992
993 setverdict(pass);
Harald Welte96c94412017-12-09 03:12:45 +0100994}
995
Harald Welte6f521d82017-12-11 19:52:02 +0100996function f_bssap_tx_ud(template PDU_BSSAP bssap) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +0100997 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, bssap));
Harald Welte6f521d82017-12-11 19:52:02 +0100998}
999
1000
1001/***********************************************************************
1002 * Paging Testing
1003 ***********************************************************************/
1004
1005type record Cell_Identity {
1006 GsmMcc mcc,
1007 GsmMnc mnc,
1008 GsmLac lac,
1009 GsmCellId ci
1010};
Harald Welte24135bd2018-03-17 19:27:53 +01001011private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01001012private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01001013
Harald Welte5d1a2202017-12-13 19:51:29 +01001014type set of integer BtsIdList;
1015
1016private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
1017 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
1018 if (bts_id == bts_ids[j]) {
1019 return true;
1020 }
1021 }
1022 return false;
1023}
Harald Welte6f521d82017-12-11 19:52:02 +01001024
1025/* core paging test helper function; used by most paging test cases */
1026private function f_pageing_helper(hexstring imsi,
1027 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01001028 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01001029 template RSL_ChanNeeded rsl_chneed := omit,
1030 template OCT4 tmsi := omit) runs on test_CT
1031{
1032 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
1033 var MobileIdentity mi;
1034 var template octetstring id_enc; /* FIXME */
1035 var RSL_Message rx_rsl;
1036 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01001037 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01001038
1039 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01001040
1041 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01001042 for (i := 0; i < NUM_BTS; i := i + 1) {
1043 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01001044 }
Harald Welte6f521d82017-12-11 19:52:02 +01001045
1046 if (isvalue(rsl_chneed)) {
1047 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
1048 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
1049 } else {
1050 bssmap_chneed := omit;
1051 }
1052
1053 f_bssap_tx_ud(ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed));
1054
1055/* FIXME: Disabled due to bugs in both GSM_RR_Types and MobileL3_CommonIE_Types IMSI encoder
1056 if (isvalue(tmsi)) {
1057 mi := valueof(t_Osmo_MI_TMSI(oct2int(valueof(tmsi))));
1058 } else {
1059 mi := valueof(ts_Osmo_MI_IMSI(imsi));
1060 }
1061 id_enc := enc_MobileIdentity(mi);
1062*/
1063 id_enc := ?;
Harald Welte5d1a2202017-12-13 19:51:29 +01001064 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
1065 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(id_enc));
1066 /* check channel type, paging group */
1067 if (rx_rsl.ies[1].body.paging_group != paging_group) {
1068 setverdict(fail, "Paging for wrong paging group");
1069 }
1070 if (ispresent(rsl_chneed) and
1071 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
1072 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
1073 }
Harald Welte6f521d82017-12-11 19:52:02 +01001074 }
Harald Welte2fccd982018-01-31 15:48:19 +01001075 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01001076 /* do a quick check on all not-included BTSs if they received paging */
1077 for (i := 0; i < NUM_BTS; i := i + 1) {
1078 timer T := 0.1;
1079 if (f_bts_in_list(i, bts_ids)) {
1080 continue;
1081 }
1082 T.start;
1083 alt {
1084 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(id_enc))) {
1085 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
1086 }
1087 [] IPA_RSL[i].receive { repeat; }
1088 [] T.timeout { }
1089 }
Harald Welte6f521d82017-12-11 19:52:02 +01001090 }
1091
1092 setverdict(pass);
1093}
1094
Harald Welte5d1a2202017-12-13 19:51:29 +01001095const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01001096const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01001097const BtsIdList c_BtsId_LAC1 := { 0, 1 };
1098const BtsIdList c_BtsId_LAC2 := { 2 };
1099
Harald Welte6f521d82017-12-11 19:52:02 +01001100/* PAGING by IMSI + TMSI */
1101testcase TC_paging_imsi_nochan() runs on test_CT {
1102 var BSSMAP_FIELD_CellIdentificationList cid_list;
1103 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01001104 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001105 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001106}
1107
1108/* PAGING by IMSI + TMSI */
1109testcase TC_paging_tmsi_nochan() runs on test_CT {
1110 var BSSMAP_FIELD_CellIdentificationList cid_list;
1111 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001112 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001113 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001114}
1115
1116/* Paging with different "channel needed' values */
1117testcase TC_paging_tmsi_any() runs on test_CT {
1118 var BSSMAP_FIELD_CellIdentificationList cid_list;
1119 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001120 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001121 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001122}
1123testcase TC_paging_tmsi_sdcch() runs on test_CT {
1124 var BSSMAP_FIELD_CellIdentificationList cid_list;
1125 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001126 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001127 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001128}
1129testcase TC_paging_tmsi_tch_f() runs on test_CT {
1130 var BSSMAP_FIELD_CellIdentificationList cid_list;
1131 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001132 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001133 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001134}
1135testcase TC_paging_tmsi_tch_hf() runs on test_CT {
1136 var BSSMAP_FIELD_CellIdentificationList cid_list;
1137 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001138 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001139 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001140}
1141
1142/* Paging by CGI */
1143testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
1144 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1145 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001146 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001147 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001148}
1149
1150/* Paging by LAC+CI */
1151testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
1152 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1153 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001154 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001155 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001156}
1157
1158/* Paging by CI */
1159testcase TC_paging_imsi_nochan_ci() runs on test_CT {
1160 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1161 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001162 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001163 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001164}
1165
1166/* Paging by LAI */
1167testcase TC_paging_imsi_nochan_lai() runs on test_CT {
1168 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1169 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001170 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001171 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001172}
1173
1174/* Paging by LAC */
1175testcase TC_paging_imsi_nochan_lac() runs on test_CT {
1176 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1177 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001178 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001179 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001180}
1181
1182/* Paging by "all in BSS" */
1183testcase TC_paging_imsi_nochan_all() runs on test_CT {
1184 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1185 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01001186 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001187 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001188}
1189
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001190/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001191testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
1192 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1193 cid_list := { cIl_PLMN_LAC_RNC := { ts_BSSMAP_CI_PLMN_LAC_RNC(cid.mcc, cid.mnc, cid.lac, 12) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001194 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001195 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001196}
Harald Welte6f521d82017-12-11 19:52:02 +01001197
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001198/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001199testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
1200 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1201 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001202 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001203 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001204}
1205
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001206/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001207testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
1208 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1209 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001210 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001211 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001212}
1213
Harald Welte6f521d82017-12-11 19:52:02 +01001214/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01001215testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
1216 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1217 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
1218 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001219 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001220}
1221
1222/* Paging on empty list: Verify none of them page */
1223testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
1224 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1225 cid_list := { cIl_LAC := { } };
1226 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001227 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001228}
1229
Stefan Sperling049a86e2018-03-20 15:51:00 +01001230/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
1231testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
1232 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1233 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
1234 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
1235 f_shutdown_helper();
1236}
1237
Harald Welte6f521d82017-12-11 19:52:02 +01001238/* Verify paging retransmission interval + count */
1239/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01001240/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01001241
Harald Weltee65d40e2017-12-13 00:09:06 +01001242/* Verify PCH load */
1243testcase TC_paging_imsi_load() runs on test_CT {
1244 var BSSMAP_FIELD_CellIdentificationList cid_list;
1245 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01001246 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01001247 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001248 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01001249
1250 /* tell BSC there is no paging space anymore */
1251 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01001252 f_sleep(0.2);
1253 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01001254
1255 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
1256 * there would be 8 retransmissions during 4 seconds */
1257 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01001258 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01001259 alt {
1260 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1261 setverdict(fail, "Received PAGING after LOAD_IND(0)");
1262 self.stop;
1263 }
Harald Welte2caa1062018-03-17 18:19:05 +01001264 [] T_retrans.timeout {
1265 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
1266 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
1267 T_retrans.start;
1268 repeat;
1269 }
Harald Weltee65d40e2017-12-13 00:09:06 +01001270 [] T.timeout {
1271 setverdict(pass);
1272 }
1273 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001274
1275 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01001276}
1277
Harald Welte235ebf12017-12-15 14:18:16 +01001278/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01001279testcase TC_paging_counter() runs on test_CT {
1280 var BSSMAP_FIELD_CellIdentificationList cid_list;
1281 timer T := 4.0;
1282 var integer i;
1283 var integer paging_attempted_bsc;
1284 var integer paging_attempted_bts[NUM_BTS];
1285 var integer paging_expired_bts[NUM_BTS];
1286 cid_list := valueof(ts_BSSMAP_CIL_noCell);
1287
1288 f_init();
1289
1290 /* read counters before paging */
1291 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
1292 for (i := 0; i < NUM_BTS; i := i+1) {
1293 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
1294 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
1295 }
1296
1297 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
1298
1299 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
1300 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
1301 for (i := 0; i < NUM_BTS; i := i+1) {
1302 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
1303 paging_attempted_bts[i]+1);
1304 }
1305
1306 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
1307 f_sleep(12.0);
1308 for (i := 0; i < NUM_BTS; i := i+1) {
1309 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
1310 paging_expired_bts[i]+1);
1311 }
Harald Welte1ff69992017-12-14 12:31:17 +01001312
Philipp Maier282ca4b2018-02-27 17:17:00 +01001313 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01001314}
1315
1316
Harald Welte10985002017-12-12 09:29:15 +01001317/* Verify paging stops after A-RESET */
1318testcase TC_paging_imsi_a_reset() runs on test_CT {
1319 var BSSMAP_FIELD_CellIdentificationList cid_list;
1320 timer T := 3.0;
1321 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001322 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01001323
1324 /* Perform a BSSMAP Reset and wait for ACK */
Harald Weltea4ca4462018-02-09 00:17:14 +01001325 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, ts_BSSMAP_Reset(0)));
Harald Welte10985002017-12-12 09:29:15 +01001326 alt {
Harald Weltea4ca4462018-02-09 00:17:14 +01001327 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap.sccp_addr_own, g_bssap.sccp_addr_peer, tr_BSSMAP_ResetAck)) { }
Harald Welte10985002017-12-12 09:29:15 +01001328 [] BSSAP.receive { repeat; }
1329 }
1330
1331 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01001332 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
1333 IPA_RSL[i].clear;
1334 }
Harald Welte10985002017-12-12 09:29:15 +01001335
1336 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
1337 T.start;
1338 alt {
1339 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1340 setverdict(fail, "Received PAGING after A-RESET");
1341 self.stop;
1342 }
Harald Welte5d1a2202017-12-13 19:51:29 +01001343 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1344 setverdict(fail, "Received PAGING after A-RESET");
1345 self.stop;
1346 }
1347 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1348 setverdict(fail, "Received PAGING after A-RESET");
1349 self.stop;
1350 }
Harald Welte10985002017-12-12 09:29:15 +01001351 [] T.timeout {
1352 setverdict(pass);
1353 }
1354 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001355
1356 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01001357}
Harald Welteae026692017-12-09 01:03:01 +01001358
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001359/* Test RSL link drop causes counter increment */
1360testcase TC_rsl_drop_counter() runs on test_CT {
1361 var integer rsl_fail;
1362
Harald Welte89d42e82017-12-17 16:42:41 +01001363 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001364
1365 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
1366
1367 bts[0].rsl.vc_IPA.stop;
1368
1369 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
1370
1371 setverdict(pass);
1372}
1373
1374/* TODO: Test OML link drop causes counter increment */
1375
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001376/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
1377function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
1378 timer T := 10.0;
1379
1380 bts[0].rsl.id := "IPA-0-RSL";
1381 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
1382 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
1383 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
1384 bts[0].rsl.ccm_pars.unit_id := "0/0/0"; /* value which is unknown at BTS */
1385
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001386 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
1387
1388 f_init_mgcp("VirtMSC");
1389
1390 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
1391 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
1392 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
1393 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
1394
1395 /* wait for IPA OML link to connect and then disconnect */
1396 T.start;
1397 alt {
1398 [] IPA_RSL[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) {
1399 T.stop;
1400 return true;
1401 }
1402 [] IPA_RSL[0].receive { repeat }
1403 [] T.timeout {
1404 self.stop;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001405 }
1406 }
1407
1408 return false;
1409}
1410
1411/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1412testcase TC_rsl_unknown_unit_id() runs on test_CT {
1413 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
1414 setverdict(pass);
1415 } else {
1416 setverdict(fail, "Timeout RSL waiting for connection to close");
1417 }
1418}
1419
1420
1421/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1422testcase TC_oml_unknown_unit_id() runs on test_CT {
1423 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
1424 setverdict(pass);
1425 } else {
1426 setverdict(fail, "Timeout OML waiting for connection to close");
1427 }
1428}
1429
1430
Harald Weltec1a2fff2017-12-17 11:06:19 +01001431/***********************************************************************
1432 * "New world" test cases using RSL_Emulation + BSSMAP_Emulation
1433 ***********************************************************************/
1434
1435import from BSSMAP_Emulation all;
1436import from RSL_Emulation all;
1437import from MSC_ConnectionHandler all;
1438
1439type function void_fn(charstring id) runs on MSC_ConnHdlr;
1440
1441/* helper function to create, connect and start a MSC_ConnHdlr component */
Harald Welte8863fa12018-05-10 20:15:27 +02001442function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
Harald Weltea0630032018-03-20 21:09:55 +01001443runs on test_CT return MSC_ConnHdlr {
Harald Welte8863fa12018-05-10 20:15:27 +02001444 var charstring id := testcasename();
Harald Weltec1a2fff2017-12-17 11:06:19 +01001445 var MSC_ConnHdlr vc_conn;
1446
1447 vc_conn := MSC_ConnHdlr.create(id);
Harald Weltea4ca4462018-02-09 00:17:14 +01001448 connect(vc_conn:BSSMAPEM, g_bssap.vc_BSSMAP:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001449 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001450 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01001451 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01001452 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01001453 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
1454 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
1455 }
Harald Weltea4ca4462018-02-09 00:17:14 +01001456 connect(vc_conn:BSSAP, g_bssap.vc_BSSMAP:CLIENT);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001457 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Harald Weltea0630032018-03-20 21:09:55 +01001458 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001459 return vc_conn;
1460}
1461
Harald Weltea0630032018-03-20 21:09:55 +01001462/* first function inside ConnHdlr component; sets g_pars + starts function */
1463private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
1464runs on MSC_ConnHdlr {
1465 if (isvalue(pars)) {
1466 g_pars := valueof(pars);
1467 }
1468 fn.apply(id);
1469}
1470
Harald Welte3c86ea02018-05-10 22:28:05 +02001471/* Establish signalling channel (non-assignment case) followed by cipher mode */
1472private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001473 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1474 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02001475 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
1476
1477 // Disable generation of ASSIGNMENT CMD, as OsmoBSC currently performs MODE MODFIY sign->sign (OS#2936)
1478 //f_establish_fully(ass_cmd, exp_compl);
1479 f_establish_fully(omit, exp_compl);
1480}
1481testcase TC_ciph_mode_a5_0() runs on test_CT {
1482 var MSC_ConnHdlr vc_conn;
1483 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1484 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
1485
1486 f_init(1, true);
1487 f_sleep(1.0);
1488 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1489 vc_conn.done;
1490}
1491testcase TC_ciph_mode_a5_1() runs on test_CT {
1492 var MSC_ConnHdlr vc_conn;
1493 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1494 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
1495
1496 f_init(1, true);
1497 f_sleep(1.0);
1498 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1499 vc_conn.done;
1500}
1501testcase TC_ciph_mode_a5_3() runs on test_CT {
1502 var MSC_ConnHdlr vc_conn;
1503 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1504 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
1505
1506 f_init(1, true);
1507 f_sleep(1.0);
1508 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1509 vc_conn.done;
1510}
1511
1512
1513/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02001514private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001515 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1516 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01001517
Harald Welte552620d2017-12-16 23:21:36 +01001518 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1519 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01001520
Harald Weltea0630032018-03-20 21:09:55 +01001521 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01001522}
Harald Welte552620d2017-12-16 23:21:36 +01001523testcase TC_assignment_fr_a5_0() runs on test_CT {
1524 var MSC_ConnHdlr vc_conn;
Harald Welte651fcdc2018-05-10 20:23:16 +02001525 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1526 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01001527
Harald Welte89d42e82017-12-17 16:42:41 +01001528 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001529 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001530 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01001531 vc_conn.done;
1532}
Harald Welte552620d2017-12-16 23:21:36 +01001533testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01001534 var MSC_ConnHdlr vc_conn;
Harald Welte651fcdc2018-05-10 20:23:16 +02001535 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1536 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001537
Harald Welte89d42e82017-12-17 16:42:41 +01001538 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001539 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001540 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
1541 vc_conn.done;
1542}
1543testcase TC_assignment_fr_a5_3() runs on test_CT {
1544 var MSC_ConnHdlr vc_conn;
1545 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1546 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001547
Harald Welte651fcdc2018-05-10 20:23:16 +02001548 f_init(1, true);
1549 f_sleep(1.0);
1550 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001551 vc_conn.done;
1552}
1553
Harald Welte552620d2017-12-16 23:21:36 +01001554/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
1555private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001556 g_pars := valueof(t_def_TestHdlrPars);
Harald Welte552620d2017-12-16 23:21:36 +01001557 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001558 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001559 const OCT8 kc := '0001020304050607'O;
1560
1561 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Harald Weltea0630032018-03-20 21:09:55 +01001562 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01001563}
Harald Welte552620d2017-12-16 23:21:36 +01001564testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
1565 var MSC_ConnHdlr vc_conn;
1566
Harald Welte89d42e82017-12-17 16:42:41 +01001567 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001568 f_sleep(1.0);
1569
Harald Welte8863fa12018-05-10 20:15:27 +02001570 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01001571 vc_conn.done;
1572}
1573
Harald Welte552620d2017-12-16 23:21:36 +01001574private function f_tc_assignment_fr_a5_4(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001575 g_pars := valueof(t_def_TestHdlrPars);
Harald Welteed848512018-05-24 22:27:58 +02001576 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1577 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001578 const OCT8 kc := '0001020304050607'O;
1579 const OCT16 kc128 := kc & kc;
1580
1581 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1582 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Weltea0630032018-03-20 21:09:55 +01001583 f_establish_fully(ass_cmd, exp_compl);
Harald Welte38b2a102017-12-23 02:42:58 +01001584 f_cipher_mode('10'O, kc, kc128, true);
Harald Welte552620d2017-12-16 23:21:36 +01001585 /* TODO: expect GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED cause value */
Harald Welte552620d2017-12-16 23:21:36 +01001586}
Harald Welte552620d2017-12-16 23:21:36 +01001587testcase TC_assignment_fr_a5_4() runs on test_CT {
1588 var MSC_ConnHdlr vc_conn;
1589
Harald Welte89d42e82017-12-17 16:42:41 +01001590 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001591 f_sleep(1.0);
1592
Harald Welte8863fa12018-05-10 20:15:27 +02001593 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_4));
Harald Welte552620d2017-12-16 23:21:36 +01001594 vc_conn.done;
1595}
1596
1597
Harald Welte4532e0a2017-12-23 02:05:44 +01001598private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier6a50c7c2018-04-16 16:15:59 +02001599 g_pars := valueof(t_def_TestHdlrPars);
Harald Welte4532e0a2017-12-23 02:05:44 +01001600 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
1601 var PDU_BSSAP ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, omit));
1602
1603 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Harald Weltea0630032018-03-20 21:09:55 +01001604 f_establish_fully(ass_cmd, exp_compl);
Harald Welte4532e0a2017-12-23 02:05:44 +01001605}
1606
1607testcase TC_assignment_sign() runs on test_CT {
1608 var MSC_ConnHdlr vc_conn;
1609
1610 f_init(1, true);
1611 f_sleep(1.0);
1612
Harald Welte8863fa12018-05-10 20:15:27 +02001613 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01001614 vc_conn.done;
1615}
1616
Harald Welte60aa5762018-03-21 19:33:13 +01001617/***********************************************************************
1618 * Codec (list) testing
1619 ***********************************************************************/
1620
1621/* check if the given rsl_mode is compatible with the a_elem */
1622private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
1623return boolean {
1624 select (a_elem.codecType) {
1625 case (GSM_FR) {
1626 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
1627 return true;
1628 }
1629 }
1630 case (GSM_HR) {
1631 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
1632 return true;
1633 }
1634 }
1635 case (GSM_EFR) {
1636 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
1637 return true;
1638 }
1639 }
1640 case (FR_AMR) {
1641 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
1642 return true;
1643 }
1644 }
1645 case (HR_AMR) {
1646 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
1647 return true;
1648 }
1649 }
1650 case else { }
1651 }
1652 return false;
1653}
1654
1655/* check if the given rsl_mode is compatible with the a_list */
1656private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
1657return boolean {
1658 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
1659 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
1660 return true;
1661 }
1662 }
1663 return false;
1664}
1665
1666/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
1667private function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
1668return BSSMAP_IE_ChannelType {
1669 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
1670 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
1671 select (a_elem.codecType) {
1672 case (GSM_FR) {
1673 ret.channelRateAndType := ChRate_TCHF;
1674 ret.speechId_DataIndicator := Spdi_TCHF_FR;
1675 }
1676 case (GSM_HR) {
1677 ret.channelRateAndType := ChRate_TCHH;
1678 ret.speechId_DataIndicator := Spdi_TCHH_HR;
1679 }
1680 case (GSM_EFR) {
1681 ret.channelRateAndType := ChRate_TCHF;
1682 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
1683 }
1684 case (FR_AMR) {
1685 ret.channelRateAndType := ChRate_TCHF;
1686 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
1687 }
1688 case (HR_AMR) {
1689 ret.channelRateAndType := ChRate_TCHH;
1690 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
1691 }
1692 case else {
1693 setverdict(fail, "Unsupported codec ", a_elem);
1694 self.stop;
1695 }
1696 }
1697 return ret;
1698}
1699
Harald Weltea63b9102018-03-22 20:36:16 +01001700private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
1701return template RSL_IE_Body {
1702 var template RSL_IE_Body mode_ie := {
1703 chan_mode := {
1704 len := ?,
1705 reserved := ?,
1706 dtx_d := ?,
1707 dtx_u := ?,
1708 spd_ind := RSL_SPDI_SPEECH,
1709 ch_rate_type := -,
1710 coding_alg_rate := -
1711 }
1712 }
1713
1714 select (a_elem.codecType) {
1715 case (GSM_FR) {
1716 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1717 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1718 }
1719 case (GSM_HR) {
1720 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1721 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1722 }
1723 case (GSM_EFR) {
1724 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1725 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
1726 }
1727 case (FR_AMR) {
1728 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1729 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1730 }
1731 case (HR_AMR) {
1732 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1733 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1734 }
1735 }
1736 return mode_ie;
1737}
1738
Harald Welte60aa5762018-03-21 19:33:13 +01001739type record CodecListTest {
1740 BSSMAP_IE_SpeechCodecList codec_list,
1741 charstring id
1742}
1743type record of CodecListTest CodecListTests
1744
1745private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001746 var PDU_BSSAP ass_cmd := f_gen_ass_req();
1747 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
Harald Welte60aa5762018-03-21 19:33:13 +01001748
1749 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Harald Welte79f3f542018-05-25 20:02:37 +02001750 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
1751 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
1752 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
1753 g_pars.ass_codec_list.codecElements[0];
1754 }
Harald Welte60aa5762018-03-21 19:33:13 +01001755 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
1756 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01001757 log("expecting ASS COMPL like this: ", exp_compl);
1758
1759 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01001760
1761 /* Verify that the RSL-side activation actually matches our expectations */
1762 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
1763
1764 var RSL_IE_Body mode_ie;
1765 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
1766 setverdict(fail, "Couldn't find CHAN_MODE IE");
1767 self.stop;
1768 }
1769 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
1770 if (not match(mode_ie, t_mode_ie)) {
1771 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
1772 }
Harald Welte60aa5762018-03-21 19:33:13 +01001773}
1774
1775testcase TC_assignment_codec_fr() runs on test_CT {
1776 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1777 var MSC_ConnHdlr vc_conn;
1778
1779 f_init(1, true);
1780 f_sleep(1.0);
1781
1782 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02001783 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001784 vc_conn.done;
1785}
1786
1787testcase TC_assignment_codec_hr() runs on test_CT {
1788 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1789 var MSC_ConnHdlr vc_conn;
1790
1791 f_init(1, true);
1792 f_sleep(1.0);
1793
1794 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02001795 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001796 vc_conn.done;
1797}
1798
1799testcase TC_assignment_codec_efr() runs on test_CT {
1800 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1801 var MSC_ConnHdlr vc_conn;
1802
1803 f_init(1, true);
1804 f_sleep(1.0);
1805
1806 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02001807 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001808 vc_conn.done;
1809}
1810
1811testcase TC_assignment_codec_amr_f() runs on test_CT {
1812 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1813 var MSC_ConnHdlr vc_conn;
1814
1815 f_init(1, true);
1816 f_sleep(1.0);
1817
1818 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Harald Welte8863fa12018-05-10 20:15:27 +02001819 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001820 vc_conn.done;
1821}
1822
1823testcase TC_assignment_codec_amr_h() runs on test_CT {
1824 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1825 var MSC_ConnHdlr vc_conn;
1826
1827 f_init(1, true);
1828 f_sleep(1.0);
1829
1830 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Harald Welte8863fa12018-05-10 20:15:27 +02001831 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001832 vc_conn.done;
1833}
1834
1835
1836
Harald Welte898113b2018-01-31 18:32:21 +01001837/* test if L3 RR CLASSMARK CHANGE is translated to BSSMAP CLASSMARK UPDATE */
1838private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001839 g_pars := valueof(t_def_TestHdlrPars);
1840 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01001841 /* we should now have a COMPL_L3 at the MSC */
1842 BSSAP.receive(tr_BSSMAP_ComplL3);
1843
1844 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
1845 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
1846 setverdict(pass);
1847}
1848testcase TC_classmark() runs on test_CT {
1849 var MSC_ConnHdlr vc_conn;
1850 f_init(1, true);
1851 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02001852 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01001853 vc_conn.done;
1854}
1855
Harald Weltee3bd6582018-01-31 22:51:25 +01001856private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001857 g_pars := valueof(t_def_TestHdlrPars);
1858 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01001859 /* we should now have a COMPL_L3 at the MSC */
1860 BSSAP.receive(tr_BSSMAP_ComplL3);
1861
Harald Weltee3bd6582018-01-31 22:51:25 +01001862 /* send the single message we want to send */
1863 f_rsl_send_l3(l3);
1864}
1865
1866private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
1867 timer T := sec;
1868 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01001869 T.start;
1870 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01001871 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
1872 setverdict(fail, "Unexpected BSSMAP ", bssap);
1873 self.stop;
Harald Welte898113b2018-01-31 18:32:21 +01001874 }
1875 [] T.timeout {
1876 setverdict(pass);
1877 }
1878 }
1879}
1880
Harald Weltee3bd6582018-01-31 22:51:25 +01001881/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
1882private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
1883 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
1884 f_bssap_expect_nothing();
1885}
Harald Welte898113b2018-01-31 18:32:21 +01001886testcase TC_unsol_ass_fail() runs on test_CT {
1887 var MSC_ConnHdlr vc_conn;
1888 f_init(1, true);
1889 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02001890 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01001891 vc_conn.done;
1892}
Harald Welte552620d2017-12-16 23:21:36 +01001893
Harald Welteea99a002018-01-31 20:46:43 +01001894
1895/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
1896private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01001897 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
1898 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01001899}
1900testcase TC_unsol_ass_compl() runs on test_CT {
1901 var MSC_ConnHdlr vc_conn;
1902 f_init(1, true);
1903 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02001904 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01001905 vc_conn.done;
1906}
1907
1908
Harald Weltefbf9b5e2018-01-31 20:41:23 +01001909/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
1910private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01001911 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
1912 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01001913}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01001914testcase TC_unsol_ho_fail() runs on test_CT {
1915 var MSC_ConnHdlr vc_conn;
1916 f_init(1, true);
1917 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02001918 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01001919 vc_conn.done;
1920}
1921
1922
Harald Weltee3bd6582018-01-31 22:51:25 +01001923/* short message from MS should be ignored */
1924private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001925 g_pars := valueof(t_def_TestHdlrPars);
1926 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01001927 /* we should now have a COMPL_L3 at the MSC */
1928 BSSAP.receive(tr_BSSMAP_ComplL3);
1929
1930 /* send short message */
1931 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
1932 f_bssap_expect_nothing();
1933}
1934testcase TC_err_82_short_msg() runs on test_CT {
1935 var MSC_ConnHdlr vc_conn;
1936 f_init(1, true);
1937 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02001938 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01001939 vc_conn.done;
1940}
1941
1942
Harald Weltee9e02e42018-01-31 23:36:25 +01001943/* 24.008 8.4 Unknown message must trigger RR STATUS */
1944private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
1945 f_est_single_l3(ts_RRM_UL_REL('00'O));
1946 timer T := 3.0
1947 alt {
1948 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
1949 setverdict(pass);
1950 }
1951 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01001952 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01001953 }
1954}
1955testcase TC_err_84_unknown_msg() runs on test_CT {
1956 var MSC_ConnHdlr vc_conn;
1957 f_init(1, true);
1958 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02001959 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01001960 vc_conn.done;
1961}
1962
Harald Welte94e0c342018-04-07 11:33:23 +02001963/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
1964private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
1965runs on test_CT {
1966 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
1967 " timeslot "&int2str(ts_nr)&" ";
1968 f_vty_transceive(BSCVTY, cmd & suffix);
1969}
1970
Harald Welte261af4b2018-02-12 21:20:39 +01001971/* execute a "bts <0-255> trx <0-255> timeslot <0-7> sub-slot <0-7>" command on given Dchan */
1972private function f_vty_ss_action(charstring suffix, integer bts_nr, integer trx_nr, RslChannelNr chan_nr)
1973runs on MSC_ConnHdlr {
1974 /* FIXME: resolve those from component-global state */
1975 var integer ts_nr := chan_nr.tn;
1976 var integer ss_nr;
1977 if (ischosen(chan_nr.u.ch0)) {
1978 ss_nr := 0;
1979 } else if (ischosen(chan_nr.u.lm)) {
1980 ss_nr := chan_nr.u.lm.sub_chan;
1981 } else if (ischosen(chan_nr.u.sdcch4)) {
1982 ss_nr := chan_nr.u.sdcch4.sub_chan;
1983 } else if (ischosen(chan_nr.u.sdcch8)) {
1984 ss_nr := chan_nr.u.sdcch8.sub_chan;
1985 } else {
1986 setverdict(fail, "Invalid ChanNr ", chan_nr);
1987 self.stop;
1988 }
1989
1990 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
1991 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
1992 f_vty_transceive(BSCVTY, cmd & suffix);
1993}
1994
1995private function f_vty_handover(integer bts_nr, integer trx_nr, RslChannelNr chan_nr,
1996 integer new_bts_nr)
1997runs on MSC_ConnHdlr {
1998 f_vty_ss_action("handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
1999}
2000
2001/* intra-BSC hand-over between BTS0 and BTS1 */
2002private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01002003 g_pars := valueof(t_def_TestHdlrPars);
Harald Welteed848512018-05-24 22:27:58 +02002004 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2005 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01002006 const OCT8 kc := '0001020304050607'O;
2007
2008 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2009 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2010
Harald Weltea0630032018-03-20 21:09:55 +01002011 f_establish_fully(ass_cmd, exp_compl);
Harald Welte261af4b2018-02-12 21:20:39 +01002012
2013 var HandoverState hs := {
2014 rr_ho_cmpl_seen := false,
2015 handover_done := false,
2016 old_chan_nr := -
2017 };
2018 /* issue hand-over command on VTY */
2019 f_vty_handover(0, 0, g_chan_nr, 1);
2020 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
2021 f_rslem_suspend(RSL1_PROC);
2022 alt {
2023 [] as_handover(hs);
2024 /* FIXME: somehow determine that the hand-over has completed, by MGCP MDCX? */
2025 }
2026}
2027
2028testcase TC_ho_int() runs on test_CT {
2029 var MSC_ConnHdlr vc_conn;
2030 f_init(2, true);
2031 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002032 vc_conn := f_start_handler(refers(f_tc_ho_int));
Harald Welte261af4b2018-02-12 21:20:39 +01002033 vc_conn.done;
2034}
Harald Weltee9e02e42018-01-31 23:36:25 +01002035
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002036/* OS#3041: Open and close N connections in a normal fashion, and expect no
2037 * BSSMAP Reset just because of that. */
2038testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
2039 var default d;
2040 var integer i;
2041 var DchanTuple dt;
2042
2043 f_init();
2044
2045 /* Wait for initial BSSMAP Reset to pass */
2046 f_sleep(4.0);
2047
2048 d := activate(no_bssmap_reset());
2049
2050 /* Setup up a number of connections and RLSD them again from the MSC
2051 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
2052 * Let's do it some more times for good measure. */
2053 for (i := 0; i < 8; i := i+1) {
2054 /* Since we're doing a lot of runs, give each one a fresh
2055 * T_guard from the top. */
2056 T_guard.start;
2057
2058 /* Setup a BSSAP connection and clear it right away. This is
2059 * the MSC telling the BSC about a planned release, it's not an
2060 * erratic loss of a connection. */
2061 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2062
2063 /* MSC disconnects (RLSD). */
2064 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2065 }
2066
2067 /* In the buggy behavior, a timeout of 2 seconds happens between above
2068 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
2069 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
2070 f_sleep(4.0);
2071
2072 deactivate(d);
2073 f_shutdown_helper();
2074}
Harald Welte552620d2017-12-16 23:21:36 +01002075
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002076/* OS#3041: Open and close N connections in a normal fashion, and expect no
2077 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
2078 * the MSC. */
2079testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
2080 var default d;
2081 var integer i;
2082 var DchanTuple dt;
2083 var BSSAP_N_DATA_ind rx_di;
2084 var RSL_Message rx_rsl;
2085 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
2086 var BssmapCause cause := enum2int(cause_val);
2087
2088 f_init();
2089
2090 /* Wait for initial BSSMAP Reset to pass */
2091 f_sleep(4.0);
2092
2093 d := activate(no_bssmap_reset());
2094
2095 /* Setup up a number of connections and RLSD them again from the MSC
2096 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
2097 * Let's do it some more times for good measure. */
2098 for (i := 0; i < 8; i := i+1) {
2099 /* Since we're doing a lot of runs, give each one a fresh
2100 * T_guard from the top. */
2101 T_guard.start;
2102
2103 /* Setup a BSSAP connection and clear it right away. This is
2104 * the MSC telling the BSC about a planned release, it's not an
2105 * erratic loss of a connection. */
2106 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2107
2108 /* Instruct BSC to clear channel */
2109 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2110
2111 /* expect BSC to disable the channel */
2112 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
2113 /* respond with CHAN REL ACK */
2114 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
2115
2116 /* expect Clear Complete from BSC */
2117 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
2118
2119 /* MSC disconnects as instructed. */
2120 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2121
2122
2123 /* MSC disconnects (RLSD). */
2124 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2125 }
2126
2127 /* In the buggy behavior, a timeout of 2 seconds happens between above
2128 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
2129 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
2130 f_sleep(4.0);
2131
2132 deactivate(d);
2133 f_shutdown_helper();
2134}
2135
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002136/* OS#3041: Open and close N connections in a normal fashion, and expect no
2137 * BSSMAP Reset just because of that. Close connections from the MS side with a
2138 * Release Ind on RSL. */
2139testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
2140 var default d;
2141 var integer i;
2142 var DchanTuple dt;
2143 var BSSAP_N_DATA_ind rx_di;
2144 var RSL_Message rx_rsl;
2145 var integer j;
2146
2147 f_init();
2148
2149 /* Wait for initial BSSMAP Reset to pass */
2150 f_sleep(4.0);
2151
2152 d := activate(no_bssmap_reset());
2153
2154 /* Setup up a number of connections and RLSD them again from the MSC
2155 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
2156 * Let's do it some more times for good measure. */
2157 for (i := 0; i < 8; i := i+1) {
2158 /* Since we're doing a lot of runs, give each one a fresh
2159 * T_guard from the top. */
2160 T_guard.start;
2161
2162 /* Setup a BSSAP connection and clear it right away. This is
2163 * the MSC telling the BSC about a planned release, it's not an
2164 * erratic loss of a connection. */
2165 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2166
2167 /* simulate RLL REL IND */
2168 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
2169
2170 /* expect Clear Request on MSC side */
2171 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
2172
2173 /* Instruct BSC to clear channel */
2174 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
2175 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2176
2177 /* expect BSC to disable the channel */
2178 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
2179 /* respond with CHAN REL ACK */
2180 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
2181
2182 /* expect Clear Complete from BSC */
2183 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
2184
2185 /* MSC disconnects as instructed. */
2186 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2187 }
2188
2189 /* In the buggy behavior, a timeout of 2 seconds happens between above
2190 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
2191 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
2192 f_sleep(4.0);
2193
2194 deactivate(d);
2195 f_shutdown_helper();
2196}
2197
Harald Welte94e0c342018-04-07 11:33:23 +02002198/***********************************************************************
2199 * IPA style dynamic PDCH
2200 ***********************************************************************/
2201
2202private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
2203 template (omit) RSL_Cause nack := omit)
2204runs on test_CT {
2205 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
2206 var RSL_Message rsl_unused;
2207 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2208 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
2209 /* expect the BSC to issue the related RSL command */
2210 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
2211 if (istemplatekind(nack, "omit")) {
2212 /* respond with a related acknowledgement */
2213 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
2214 } else {
2215 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
2216 }
2217}
2218
2219private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
2220 template (omit) RSL_Cause nack := omit)
2221runs on test_CT {
2222 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
2223 var RSL_Message rsl_unused;
2224 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2225 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
2226 /* expect the BSC to issue the related RSL command */
2227 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
2228 if (istemplatekind(nack, "omit")) {
2229 /* respond with a related acknowledgement */
2230 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
2231 } else {
2232 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
2233 }
2234}
2235
2236private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
2237runs on test_CT return charstring {
2238 var charstring cmd, resp;
2239 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
2240 resp := f_vty_transceive_ret(BSCVTY, cmd);
2241 return regexp(resp, "*\((*)\)*", 0);
2242}
2243
2244private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
2245 template charstring exp)
2246runs on test_CT {
2247 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
2248 if (not match(mode, exp)) {
2249 setverdict(fail, "Unexpected TS Mode: ", mode);
2250 self.stop;
2251 }
2252}
2253
2254private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
2255runs on test_CT {
2256 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
2257 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
2258 f_vty_transceive(BSCVTY, "end");
2259}
2260
2261private const charstring TCHF_MODE := "TCH/F mode";
2262private const charstring TCHH_MODE := "TCH/H mode";
2263private const charstring PDCH_MODE := "PDCH mode";
2264private const charstring NONE_MODE := "NONE mode";
2265
2266/* Test IPA PDCH activation / deactivation triggered by VTY */
2267testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
2268 var RSL_Message rsl_unused;
2269
2270 /* change Timeslot 6 before f_init() starts RSL */
2271 f_init_vty();
2272 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
2273 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2274
2275 f_init(1, false);
2276 f_sleep(1.0);
2277
2278 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2279
2280 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2281 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2282 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
2283 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
2284 f_sleep(1.0);
2285 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2286
2287 /* De-activate it via VTY */
2288 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
2289 f_sleep(1.0);
2290 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2291
2292 /* re-activate it via VTY */
2293 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
2294 f_sleep(1.0);
2295 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2296
2297 /* and finally de-activate it again */
2298 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
2299 f_sleep(1.0);
2300 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2301
2302 setverdict(pass);
2303}
2304
2305/* Test IPA PDCH activation NACK */
2306testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
2307 var RSL_Message rsl_unused;
2308
2309 /* change Timeslot 6 before f_init() starts RSL */
2310 f_init_vty();
2311 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
2312 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2313
2314 f_init(1, false);
2315 f_sleep(1.0);
2316
2317 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2318
2319 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2320 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2321 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
2322 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
2323 f_sleep(1.0);
2324 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2325
2326 /* De-activate it via VTY */
2327 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
2328 f_sleep(1.0);
2329 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2330
2331 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
2332 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
2333 f_sleep(1.0);
2334 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2335
2336 setverdict(pass);
2337}
2338
2339
2340/***********************************************************************
2341 * Osmocom style dynamic PDCH
2342 ***********************************************************************/
2343
2344private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
2345 template (omit) RSL_Cause nack := omit)
2346runs on test_CT {
2347 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
2348 var RSL_Message rsl_unused;
2349 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2350 /* FIXME: no VTY command to activate Osmocom PDCH !! */
2351 /* expect the BSC to issue the related RSL command */
2352 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
2353 if (istemplatekind(nack, "omit")) {
2354 /* respond with a related acknowledgement */
2355 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
2356 } else {
2357 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
2358 }
2359}
2360
2361private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
2362 template (omit) RSL_Cause nack := omit)
2363runs on test_CT {
2364 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
2365 var RSL_Message rsl_unused;
2366 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2367 /* FIXME: no VTY command to activate Osmocom PDCH !! */
2368 /* expect the BSC to issue the related RSL command */
2369 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
2370 if (istemplatekind(nack, "omit")) {
2371 /* respond with a related acknowledgement */
2372 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
2373 } else {
2374 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
2375 }
2376}
2377
2378/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
2379testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
2380 var RSL_Message rsl_unused;
2381
2382 /* change Timeslot 6 before f_init() starts RSL */
2383 f_init_vty();
2384 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
2385 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2386
2387 f_init(1, false);
2388 f_sleep(1.0);
2389
2390 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
2391
2392 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
2393 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2394 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
2395
2396 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
2397 f_sleep(1.0);
2398 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2399
2400 setverdict(pass);
2401}
2402
2403/* Test Osmocom dyn PDCH activation NACK behavior */
2404testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
2405 var RSL_Message rsl_unused;
2406
2407 /* change Timeslot 6 before f_init() starts RSL */
2408 f_init_vty();
2409 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
2410 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2411
2412 f_init(1, false);
2413 f_sleep(1.0);
2414
2415 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
2416
2417 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
2418 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2419 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
2420
2421 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
2422 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
2423 f_sleep(1.0);
2424 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
2425
2426 setverdict(pass);
2427}
2428
Harald Welte0ea2d5e2018-04-07 21:40:29 +02002429/* Dyn PDCH todo:
2430 * activate OSMO as TCH/F
2431 * activate OSMO as TCH/H
2432 * does the BSC-located PCU socket get the updated INFO?
2433 * what if no PCU is connected at the time?
2434 * is the info correct on delayed PCU (re)connect?
2435 */
Harald Welte94e0c342018-04-07 11:33:23 +02002436
Harald Welte28d943e2017-11-25 15:00:50 +01002437control {
Harald Welte898113b2018-01-31 18:32:21 +01002438 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +01002439 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002440 execute( TC_ctrl_msc0_connection_status() );
Harald Welte96c94412017-12-09 03:12:45 +01002441 execute( TC_ctrl() );
Harald Welte898113b2018-01-31 18:32:21 +01002442
2443 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +01002444 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +01002445 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +01002446 execute( TC_chan_act_ack_noest() );
2447 execute( TC_chan_act_ack_est_ind_noreply() );
2448 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +01002449 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +01002450 execute( TC_chan_exhaustion() );
Harald Welte4003d112017-12-09 22:35:39 +01002451 execute( TC_chan_rel_rll_rel_ind() );
2452 execute( TC_chan_rel_conn_fail() );
2453 execute( TC_chan_rel_hard_clear() );
Harald Welted8c36cd2017-12-09 23:05:31 +01002454 execute( TC_chan_rel_hard_rlsd() );
Harald Welte85804d42017-12-10 14:11:58 +01002455 execute( TC_chan_rel_a_reset() );
Harald Welte6f521d82017-12-11 19:52:02 +01002456
Harald Weltecfe2c962017-12-15 12:09:32 +01002457 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +01002458
2459 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +01002460 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +01002461 execute( TC_assignment_csd() );
2462 execute( TC_assignment_ctm() );
2463 execute( TC_assignment_sign() );
2464 execute( TC_assignment_fr_a5_0() );
2465 execute( TC_assignment_fr_a5_1() );
Harald Welte8f67d1d2018-05-25 20:38:42 +02002466 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
2467 execute( TC_assignment_fr_a5_1_codec_missing() );
2468 }
Harald Welte235ebf12017-12-15 14:18:16 +01002469 execute( TC_assignment_fr_a5_3() );
2470 execute( TC_assignment_fr_a5_4() );
Harald Welte3c86ea02018-05-10 22:28:05 +02002471 execute( TC_ciph_mode_a5_0() );
2472 execute( TC_ciph_mode_a5_1() );
2473 execute( TC_ciph_mode_a5_3() );
Harald Welte16a4adf2017-12-14 18:54:01 +01002474
Harald Welte60aa5762018-03-21 19:33:13 +01002475 execute( TC_assignment_codec_fr() );
2476 execute( TC_assignment_codec_hr() );
2477 execute( TC_assignment_codec_efr() );
2478 execute( TC_assignment_codec_amr_f() );
2479 execute( TC_assignment_codec_amr_h() );
2480
Harald Welte898113b2018-01-31 18:32:21 +01002481 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +01002482 execute( TC_rll_est_ind_inact_lchan() );
2483 execute( TC_rll_est_ind_inval_sapi1() );
2484 execute( TC_rll_est_ind_inval_sapi3() );
2485 execute( TC_rll_est_ind_inval_sacch() );
2486
Harald Welte898113b2018-01-31 18:32:21 +01002487 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +01002488 execute( TC_paging_imsi_nochan() );
2489 execute( TC_paging_tmsi_nochan() );
2490 execute( TC_paging_tmsi_any() );
2491 execute( TC_paging_tmsi_sdcch() );
2492 execute( TC_paging_tmsi_tch_f() );
2493 execute( TC_paging_tmsi_tch_hf() );
2494 execute( TC_paging_imsi_nochan_cgi() );
2495 execute( TC_paging_imsi_nochan_lac_ci() );
2496 execute( TC_paging_imsi_nochan_ci() );
2497 execute( TC_paging_imsi_nochan_lai() );
2498 execute( TC_paging_imsi_nochan_lac() );
2499 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +01002500 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
2501 execute( TC_paging_imsi_nochan_rnc() );
2502 execute( TC_paging_imsi_nochan_lac_rnc() );
2503 execute( TC_paging_imsi_nochan_lacs() );
2504 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +01002505 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +01002506 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +01002507 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +01002508 execute( TC_paging_counter() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +01002509
2510 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +01002511 execute( TC_rsl_unknown_unit_id() );
2512
2513 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +01002514
2515 execute( TC_classmark() );
2516 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +01002517 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002518 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +01002519 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +01002520 execute( TC_err_84_unknown_msg() );
Harald Welte261af4b2018-02-12 21:20:39 +01002521 execute( TC_ho_int() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002522
2523 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002524 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002525 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +02002526
2527 execute( TC_dyn_pdch_ipa_act_deact() );
2528 execute( TC_dyn_pdch_ipa_act_nack() );
2529 execute( TC_dyn_pdch_osmo_act_deact() );
2530 execute( TC_dyn_pdch_osmo_act_nack() );
Harald Welte28d943e2017-11-25 15:00:50 +01002531}
2532
2533}