blob: 9412251022ac3442c8986bb9913d14f53255756c [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
Stefan Sperlingc307e682018-06-14 15:15:46 +020049import from SCCP_Templates all;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010050import from BSSMAP_Templates all;
51
Harald Welte5d1a2202017-12-13 19:51:29 +010052const integer NUM_BTS := 3;
Harald Welteae026692017-12-09 01:03:01 +010053const float T3101_MAX := 12.0;
Harald Welte28d943e2017-11-25 15:00:50 +010054
Harald Welte799c97b2017-12-14 17:50:30 +010055/* make sure to sync this with the osmo-bts.cfg you're using */
Philipp Maiercb6cc482018-03-26 13:08:00 +020056const integer NUM_TCHH_PER_BTS := 2;
57const integer NUM_TCHF_PER_BTS := 4;
Harald Weltedd8cbf32018-01-28 12:07:52 +010058const integer NUM_SDCCH_PER_BTS := 4;
Harald Welte799c97b2017-12-14 17:50:30 +010059
Harald Welte4003d112017-12-09 22:35:39 +010060
Harald Welte21b46bd2017-12-17 19:46:32 +010061/* per-BTS state which we keep */
Harald Welte96c94412017-12-09 03:12:45 +010062type record BTS_State {
Harald Welte21b46bd2017-12-17 19:46:32 +010063 /* component reference to the IPA_Client component used for RSL */
Harald Weltea5d2ab22017-12-09 14:21:42 +010064 IPA_Client rsl
Harald Welte96c94412017-12-09 03:12:45 +010065}
66
Harald Weltea4ca4462018-02-09 00:17:14 +010067type component test_CT extends CTRL_Adapter_CT {
Harald Welte21b46bd2017-12-17 19:46:32 +010068 /* Array of per-BTS state */
Harald Welte96c94412017-12-09 03:12:45 +010069 var BTS_State bts[NUM_BTS];
Harald Welte89ab1912018-02-23 18:56:29 +010070 /* RSL common Channel Port (for RSL_Emulation) */
71 port RSL_CCHAN_PT RSL_CCHAN[NUM_BTS];
Harald Welte21b46bd2017-12-17 19:46:32 +010072 /* array of per-BTS RSL test ports */
Harald Welteae026692017-12-09 01:03:01 +010073 port IPA_RSL_PT IPA_RSL[NUM_BTS];
Stefan Sperling830dc9d2018-02-12 21:08:28 +010074 port IPA_CODEC_PT IPA; /* Required for compilation of TC_rsl_unknown_unit_id() */
Harald Weltea5d2ab22017-12-09 14:21:42 +010075
Daniel Willmann191e0d92018-01-17 12:44:35 +010076 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +010077 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +010078
Harald Weltea4ca4462018-02-09 00:17:14 +010079 var BSSAP_Adapter g_bssap;
80 /* for old legacy-tests only */
81 port BSSAP_CODEC_PT BSSAP;
82
Harald Welte21b46bd2017-12-17 19:46:32 +010083 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +010084 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +010085
86 /* global test case guard timer */
Harald Welteae026692017-12-09 01:03:01 +010087 timer T_guard := 30.0;
88
Harald Welte28d943e2017-11-25 15:00:50 +010089}
90
91modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +010092 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +010093 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +010094 /* port number to which to establish the IPA OML connections */
95 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +010096 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +010097 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +010098 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +010099 integer mp_bsc_ctrl_port := 4249;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100100 /* IP address at which the test binds */
101 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100102
103 BSSAP_Configuration mp_bssap_cfg := {
Harald Welte7ef51aa2018-04-16 19:16:01 +0200104 transport := BSSAP_TRANSPORT_AoIP,
Harald Weltea4ca4462018-02-09 00:17:14 +0100105 sccp_service_type := "mtp3_itu",
106 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
107 own_pc := 185,
108 own_ssn := 254,
109 peer_pc := 187,
110 peer_ssn := 254,
Philipp Maier38d68942018-03-29 15:38:09 +0200111 sio := '83'O,
112 rctx := 0
Harald Weltea4ca4462018-02-09 00:17:14 +0100113 };
114}
115
Philipp Maier282ca4b2018-02-27 17:17:00 +0100116private function f_shutdown_helper() runs on test_CT {
Philipp Maier282ca4b2018-02-27 17:17:00 +0100117 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200118 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100119}
120
Harald Weltea4ca4462018-02-09 00:17:14 +0100121private function f_legacy_bssap_reset() runs on test_CT {
122 var BSSAP_N_UNITDATA_ind ud_ind;
123 timer T := 5.0;
124 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, ts_BSSMAP_Reset(0)));
125 T.start;
126 alt {
127 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap.sccp_addr_own, g_bssap.sccp_addr_peer, tr_BSSMAP_ResetAck)) {
128 log("Received RESET-ACK in response to RESET, we're ready to go!");
129 }
130 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) -> value ud_ind {
131 log("Respoding to inbound RESET with RESET-ACK");
132 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
133 ts_BSSMAP_ResetAck));
134 repeat;
135 }
136 [] BSSAP.receive { repeat; }
137 [] T.timeout { setverdict(fail, "Waiting for RESET-ACK after sending RESET"); }
138 }
Harald Welte28d943e2017-11-25 15:00:50 +0100139}
140
Harald Welteae026692017-12-09 01:03:01 +0100141type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100142 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100143 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100144 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100145 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100146 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100147 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100148 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100149 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100150}
151
Harald Welte21b46bd2017-12-17 19:46:32 +0100152/*! Start the IPA/RSL related bits for one IPA_Client.
153 * \param clnt IPA_Client for which to establish
154 * \param bsc_host IP address / hostname of the BSC
155 * \param bsc_port TCP port number of the BSC
156 * \param i number identifying this BTS
157 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100158function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
159 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100160runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100161 timer T := 10.0;
162
Harald Welte96c94412017-12-09 03:12:45 +0100163 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welteae026692017-12-09 01:03:01 +0100164 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA");
165 clnt.ccm_pars := c_IPA_default_ccm_pars;
166 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
167 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100168 if (handler_mode) {
169 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL");
Harald Welte89ab1912018-02-23 18:56:29 +0100170 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100171 }
Harald Welteae026692017-12-09 01:03:01 +0100172
173 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Harald Welte624f9632017-12-16 19:26:04 +0100174 if (handler_mode) {
175 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
176 } else {
177 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
178 }
Harald Welteae026692017-12-09 01:03:01 +0100179
Harald Welte5d1a2202017-12-13 19:51:29 +0100180 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100181 if (handler_mode) {
182 clnt.vc_RSL.start(RSL_Emulation.main());
183 return;
184 }
Harald Welteae026692017-12-09 01:03:01 +0100185
186 /* wait for IPA RSL link to connect and send ID ACK */
187 T.start;
188 alt {
189 [] IPA_RSL[i].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_ID_ACK}) {
190 T.stop;
191 IPA_RSL[i].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_PAGING_LOAD_IND(23)));
192 }
Harald Welte60e823a2017-12-10 14:10:59 +0100193 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100194 [] IPA_RSL[i].receive { repeat }
195 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100196 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200197 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100198 }
199 }
200}
201
Harald Welte12055472018-03-17 20:10:08 +0100202function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
203 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
204 return;
205 }
206 clnt.vc_IPA.stop;
207 if (isbound(clnt.vc_RSL)) {
208 clnt.vc_RSL.stop;
209 }
210}
211
Harald Welte21b46bd2017-12-17 19:46:32 +0100212/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100213function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
214 timer T := secs_max;
215 T.start;
216 while (true) {
217 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
218 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100219 /* the 'degraded' state exists from OML connection time, and we have to wait
220 * until all MO's are initialized */
221 T.start(1.0);
222 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100223 return;
224 }
Harald Weltef0d6ac62017-12-17 17:02:21 +0100225 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100226 if (not T.running) {
227 setverdict(fail, "Timeout waiting for oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +0200228 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100229 }
230 }
231}
232
Harald Welte21b46bd2017-12-17 19:46:32 +0100233/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +0100234altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +0100235 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100236 [] T_guard.timeout {
237 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +0200238 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100239 }
Harald Welte60e823a2017-12-10 14:10:59 +0100240 /* always respond with RESET ACK to RESET */
241 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) -> value ud_ind {
242 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
243 ts_BSSMAP_ResetAck));
Harald Welte69c1c262017-12-13 21:02:08 +0100244 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +0100245 }
Harald Welte28d943e2017-11-25 15:00:50 +0100246}
247
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100248altstep no_bssmap_reset() runs on test_CT {
249 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) {
250 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +0200251 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100252 }
253}
254
Daniel Willmann191e0d92018-01-17 12:44:35 +0100255function f_init_mgcp(charstring id) runs on test_CT {
256 id := id & "-MGCP";
257
258 var MGCPOps ops := {
259 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
260 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
261 };
262 var MGCP_conn_parameters mgcp_pars := {
263 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +0100264 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +0100265 mgw_ip := mp_test_ip,
266 mgw_udp_port := 2427
267 };
268
269 vc_MGCP := MGCP_Emulation_CT.create(id);
270 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
271}
272
Harald Welte94e0c342018-04-07 11:33:23 +0200273private function f_init_vty(charstring id := "foo") runs on test_CT {
274 if (BSCVTY.checkstate("Mapped")) {
275 /* skip initialization if already executed once */
276 return;
277 }
Harald Weltebc03c762018-02-12 18:09:38 +0100278 map(self:BSCVTY, system:BSCVTY);
279 f_vty_set_prompts(BSCVTY);
280 f_vty_transceive(BSCVTY, "enable");
281}
282
Harald Welte21b46bd2017-12-17 19:46:32 +0100283/* global initialization function
284 * \param nr_bts Number of BTSs we should start/bring up
285 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte89d42e82017-12-17 16:42:41 +0100286function f_init(integer nr_bts := NUM_BTS, boolean handler_mode := false) runs on test_CT {
Harald Welte28d943e2017-11-25 15:00:50 +0100287 var integer i;
Harald Welte28d943e2017-11-25 15:00:50 +0100288
Harald Welteae026692017-12-09 01:03:01 +0100289 if (g_initialized) {
290 return;
Harald Welte28d943e2017-11-25 15:00:50 +0100291 }
Harald Welteae026692017-12-09 01:03:01 +0100292 g_initialized := true;
293
294 /* Call a function of our 'parent component' BSSAP_Adapter_CT to start the
295 * MSC-side BSSAP emulation */
Harald Welte67089ee2018-01-17 22:19:03 +0100296 if (handler_mode) {
Harald Weltea4ca4462018-02-09 00:17:14 +0100297 f_bssap_init(g_bssap, mp_bssap_cfg, "VirtMSC", MSC_BssmapOps);
Harald Welte4bcbd172018-05-27 19:47:44 +0200298 f_bssap_start(g_bssap);
Harald Welte67089ee2018-01-17 22:19:03 +0100299 } else {
Harald Weltea4ca4462018-02-09 00:17:14 +0100300 f_bssap_init(g_bssap, mp_bssap_cfg, "VirtMSC", omit);
301 connect(self:BSSAP, g_bssap.vc_SCCP:SCCP_SP_PORT);
Harald Welte4bcbd172018-05-27 19:47:44 +0200302 f_bssap_start(g_bssap);
Harald Weltea4ca4462018-02-09 00:17:14 +0100303 f_legacy_bssap_reset();
Harald Welte67089ee2018-01-17 22:19:03 +0100304 }
Harald Welted5833a82018-05-27 16:52:56 +0200305
Harald Welteffe55fc2018-01-17 22:39:54 +0100306 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +0100307
Daniel Willmann191e0d92018-01-17 12:44:35 +0100308 f_init_mgcp("VirtMSC");
Harald Weltebc03c762018-02-12 18:09:38 +0100309 f_init_vty("VirtMSC");
Daniel Willmann191e0d92018-01-17 12:44:35 +0100310
Harald Welte89d42e82017-12-17 16:42:41 +0100311 for (i := 0; i < nr_bts; i := i+1) {
Harald Weltea5d2ab22017-12-09 14:21:42 +0100312 /* wait until osmo-bts-omldummy has respawned */
313 f_wait_oml(i, "degraded", 5.0);
314 /* start RSL connection */
Harald Welte624f9632017-12-16 19:26:04 +0100315 f_ipa_rsl_start(bts[i].rsl, mp_bsc_ip, mp_bsc_rsl_port, i, handler_mode);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100316 /* wait until BSC tells us "connected" */
317 f_wait_oml(i, "connected", 5.0);
Harald Welte696ddb62017-12-08 14:01:43 +0100318 }
319
Harald Welteae026692017-12-09 01:03:01 +0100320 T_guard.start;
321 activate(as_Tguard());
Harald Welte28d943e2017-11-25 15:00:50 +0100322}
323
Harald Welte21b46bd2017-12-17 19:46:32 +0100324/* expect to receive a RSL message matching a specified templaten on a given BTS / stream */
Harald Welteae026692017-12-09 01:03:01 +0100325function f_exp_ipa_rx(integer bts_nr, template RSL_Message t_rx, float t_secs := 2.0, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
326runs on test_CT return RSL_Message {
327 var ASP_RSL_Unitdata rx_rsl_ud;
328 timer T := t_secs;
329
330 T.start;
331 alt {
332 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(sid, t_rx)) -> value rx_rsl_ud {
333 T.stop;
334 }
335 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +0100336 [] T.timeout {
337 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +0200338 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +0100339 }
Harald Welteae026692017-12-09 01:03:01 +0100340 }
341 return rx_rsl_ud.rsl;
342}
343
Harald Welte21b46bd2017-12-17 19:46:32 +0100344/* helper function to transmit RSL on a given BTS/stream */
Harald Welteae026692017-12-09 01:03:01 +0100345function f_ipa_tx(integer bts_nr, template RSL_Message t_tx, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
346runs on test_CT {
347 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(sid, t_tx));
348}
349
350
Harald Welte4003d112017-12-09 22:35:39 +0100351/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +0100352testcase TC_chan_act_noreply() runs on test_CT {
353 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +0100354 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +0100355
Harald Welte89d42e82017-12-17 16:42:41 +0100356 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +0100357
Harald Welteae026692017-12-09 01:03:01 +0100358 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 +0100359 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welteae026692017-12-09 01:03:01 +0100360 setverdict(pass);
Harald Welte28d943e2017-11-25 15:00:50 +0100361}
362
Harald Welte4003d112017-12-09 22:35:39 +0100363/* verify if the "chreq:total" counter increments as expected */
364testcase TC_chan_act_counter() runs on test_CT {
365 var BSSAP_N_UNITDATA_ind ud_ind;
366 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +0100367 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +0100368
Harald Welte89d42e82017-12-17 16:42:41 +0100369 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100370
371 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
372 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 +0100373 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welte4003d112017-12-09 22:35:39 +0100374 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total", chreq_total+1);
375
376 setverdict(pass);
377}
378
Harald Welteae026692017-12-09 01:03:01 +0100379/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
380testcase TC_chan_act_ack_noest() runs on test_CT {
381 var RSL_Message rx_rsl;
382
Harald Welte89d42e82017-12-17 16:42:41 +0100383 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100384
385 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100386 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100387
388 /* expect BSC to disable the channel again if there's no RLL EST IND */
389 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
390
391 setverdict(pass);
392}
393
394/* Test behavior if MSC never answers to CR */
395testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +0100396 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
397 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +0100398 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +0100399 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +0100400
Harald Welte89d42e82017-12-17 16:42:41 +0100401 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100402
403 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100404 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100405
406 var octetstring l3 := '00010203040506'O
407 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
408
409 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
410
411 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +0100412 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
413 IPA_RSL[0].clear;
414 alt {
415 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(sid, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) -> value rx_rsl_ud { }
416 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(sid, tr_RSL_REL_REQ(chan_nr, ?))) -> value rx_rsl_ud {
417 f_ipa_tx(0, ts_RSL_REL_CONF(chan_nr, main_dcch));
418 repeat;
419 }
420 }
Harald Welteae026692017-12-09 01:03:01 +0100421
422 setverdict(pass);
423}
424
425/* Test behavior if MSC answers with CREF to CR */
426testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
427 var BSSAP_N_CONNECT_ind rx_c_ind;
428 var RSL_Message rx_rsl;
429
Harald Welte89d42e82017-12-17 16:42:41 +0100430 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100431
432 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100433 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100434
435 var octetstring l3 := '00010203040506'O
436 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
437
438 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
439 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
440
441 /* expect BSC to disable the channel */
Harald Welte725844b2018-01-28 16:18:32 +0100442 f_expect_chan_rel(0, chan_nr);
Harald Welteae026692017-12-09 01:03:01 +0100443 setverdict(pass);
444}
445
Harald Welte618ef642017-12-14 14:58:20 +0100446/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
447testcase TC_chan_act_nack() runs on test_CT {
448 var RSL_Message rx_rsl;
449 var integer chact_nack;
450
Harald Welte89d42e82017-12-17 16:42:41 +0100451 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +0100452
453 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
454
455 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
456 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
457 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
458
459 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
460
461 /* wait for some time to hope the NACK arrives before the CTRL GET below */
462 f_sleep(0.5);
463
464 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
465
466 setverdict(pass);
467}
468
Harald Welte799c97b2017-12-14 17:50:30 +0100469/* Test for channel exhaustion due to RACH overload */
470testcase TC_chan_exhaustion() runs on test_CT {
471 var ASP_RSL_Unitdata rsl_ud;
472 var integer i;
473 var integer chreq_total, chreq_nochan;
474
Harald Welte89d42e82017-12-17 16:42:41 +0100475 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +0100476
477 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
478 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
479
480 /* expect 5xTCH/F to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +0200481 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 +0100482 var RslChannelNr chan_nr := f_chreq_act_ack('23'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +0100483 }
484
485 IPA_RSL[0].clear;
486
Harald Weltedd8cbf32018-01-28 12:07:52 +0100487 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200488 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +0100489
490 /* now expect additional channel activations to fail */
491 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
492
493 alt {
494 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
495 tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
496 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
497 }
498 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
499 var GsmRrMessage rr;
500 /* match on IMM ASS REJ */
501 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
502 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
503 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200504 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +0100505 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
506 chreq_nochan+1);
507 setverdict(pass);
508 } else {
509 repeat;
510 }
511 }
512 [] IPA_RSL[0].receive { repeat; }
513 }
514}
515
Harald Weltecfe2c962017-12-15 12:09:32 +0100516/***********************************************************************
517 * Assignment Testing
518 ***********************************************************************/
519
520/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction) */
521testcase TC_outbound_connect() runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +0100522 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +0100523
Harald Weltea4ca4462018-02-09 00:17:14 +0100524 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 +0100525 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
526 setverdict(pass);
527}
528
Harald Welte16a4adf2017-12-14 18:54:01 +0100529/* Test behavior if MSC answers with CREF to CR */
530testcase TC_assignment_cic_only() runs on test_CT {
531 var BSSAP_N_CONNECT_ind rx_c_ind;
532 var RSL_Message rx_rsl;
533 var DchanTuple dt;
534
Harald Welte89d42e82017-12-17 16:42:41 +0100535 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +0100536
537 dt := f_est_dchan('23'O, 23, '00000000'O);
Harald Welte17b27da2018-05-25 20:33:53 +0200538 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
539 /* send assignment without AoIP IEs */
540 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
541 } else {
542 /* Send assignmetn without CIC in IPA case */
543 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
544 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
545 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
546 }
Harald Welte16a4adf2017-12-14 18:54:01 +0100547 alt {
548 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
549 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
550 }
Harald Welte235ebf12017-12-15 14:18:16 +0100551 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +0100552 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
553 setverdict(pass);
554 }
555 [] BSSAP.receive { repeat; }
556 }
557}
558
Harald Welteed848512018-05-24 22:27:58 +0200559/* generate an assignment request for either AoIP or SCCPlite */
Harald Weltee102eae2018-05-31 21:03:47 +0200560function f_gen_ass_req() return PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200561 var PDU_BSSAP ass_cmd;
562 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
563 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
564 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
565 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
566 } else {
567 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
568 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
569 }
570 return ass_cmd;
571}
572
573/* generate an assignment complete template for either AoIP or SCCPlite */
Harald Weltee102eae2018-05-31 21:03:47 +0200574function f_gen_exp_compl() return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200575 var template PDU_BSSAP exp_compl;
576 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
577 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?);
578 } else {
579 /* CIC is optional "*" as the MSC allocated it */
580 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
581 }
582 return exp_compl;
583}
584
Harald Welte235ebf12017-12-15 14:18:16 +0100585/* Run everything required up to sending a caller-specified assignment command and expect response */
586function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
587runs on test_CT {
588 var BSSAP_N_CONNECT_ind rx_c_ind;
589 var RSL_Message rx_rsl;
590 var DchanTuple dt;
591
Harald Welte89d42e82017-12-17 16:42:41 +0100592 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +0100593
594 dt := f_est_dchan('23'O, 23, '00000000'O);
595 /* send assignment without AoIP IEs */
596 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
597 alt {
598 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
599 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
600 setverdict(pass);
601 } else {
602 setverdict(fail, fail_text);
603 }
604 }
605 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
606 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
607 setverdict(pass);
608 } else {
609 setverdict(fail, fail_text);
610 }
611 }
612 [] BSSAP.receive { repeat; }
613 }
614}
615testcase TC_assignment_csd() runs on test_CT {
616 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200617 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100618 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
619 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
620 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
621}
622
623testcase TC_assignment_ctm() runs on test_CT {
624 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200625 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100626 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
627 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
628 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
629}
630
Harald Welte4003d112017-12-09 22:35:39 +0100631type record DchanTuple {
632 integer sccp_conn_id,
633 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +0100634}
635
Harald Welted6939652017-12-13 21:02:46 +0100636/* Send CHAN RQD and wait for allocation; acknowledge it */
637private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
638runs on test_CT return RslChannelNr {
639 var RSL_Message rx_rsl;
640 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
641 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
642 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
643 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
644 return chan_nr;
645}
646
Harald Welte4003d112017-12-09 22:35:39 +0100647/* helper function to establish a dedicated channel via BTS and MSC */
648function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
649runs on test_CT return DchanTuple {
650 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +0100651 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100652
Harald Welte4003d112017-12-09 22:35:39 +0100653 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100654 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +0100655
656 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
657
658 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
659 dt.sccp_conn_id := rx_c_ind.connectionId;
660 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
661
662 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100663}
664
Harald Welte641fcbe2018-06-14 10:58:35 +0200665/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
666private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
667 var RSL_Message rx_rsl;
668 /* expect BSC to disable the channel */
669 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
670 /* respond with CHAN REL ACK */
671 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
672
673 /* expect Clear Complete from BSC */
674 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
675
676 /* MSC disconnects as instructed. */
677 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
678}
679
Harald Welte4003d112017-12-09 22:35:39 +0100680/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
681testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100682 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100683 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +0100684
Harald Welte89d42e82017-12-17 16:42:41 +0100685 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +0100686
Harald Welte4003d112017-12-09 22:35:39 +0100687 dt := f_est_dchan('23'O, 23, '00010203040506'O);
688
689 /* simulate RLL REL IND */
690 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
691
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100692 /* expect Clear Request on MSC side */
693 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
694
695 /* Instruct BSC to clear channel */
696 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
697 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
698
Harald Welte4003d112017-12-09 22:35:39 +0100699 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200700 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100701
702 /* wait for SCCP emulation to do its job */
703 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +0100704
705 setverdict(pass);
706}
707
708/* Test behavior of channel release after CONN FAIL IND from BTS */
709testcase TC_chan_rel_conn_fail() runs on test_CT {
710 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100711 var DchanTuple dt;
712
Harald Welte89d42e82017-12-17 16:42:41 +0100713 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100714
715 dt := f_est_dchan('23'O, 23, '00010203040506'O);
716
717 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +0100718 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 +0100719 /* TODO: different cause values? */
720
Harald Welte4003d112017-12-09 22:35:39 +0100721 /* expect Clear Request from BSC */
722 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
723
724 /* Instruct BSC to clear channel */
725 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
726 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
727
Harald Welte6ff76ea2018-01-28 13:08:01 +0100728 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200729 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +0100730
731 /* wait for SCCP emulation to do its job */
732 f_sleep(1.0);
733
734 setverdict(pass);
735}
736
Harald Welte99f3ca02018-06-14 13:40:29 +0200737/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
738/* See also https://www.osmocom.org/issues/3182 */
739testcase TC_early_conn_fail() runs on test_CT {
740 var RSL_Message rx_rsl;
741 var DchanTuple dt;
742
743 f_init(1);
744
745 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
746 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_octstring(1), 23);
747
748 /* BTS->BSC: simulate CONN FAIL IND */
749 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
750
751 /* BTS->BSC: Expect RF channel release from BSC on Abis */
752 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
753
754 /* BTS<-BSC: respond with CHAN REL ACK */
755 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
756
757 setverdict(pass);
758}
759
760/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
761/* See also https://www.osmocom.org/issues/3182 */
762testcase TC_late_conn_fail() runs on test_CT {
763 var RSL_Message rx_rsl;
764 var DchanTuple dt;
765
766 f_init(1);
767
768 dt := f_est_dchan('23'O, 23, '00010203040506'O);
769
770 /* BSC<-MSC: Instruct BSC to clear connection */
771 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
772
773 /* BTS->BSC: expect BSC to deactivate SACCH */
774 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
775
776 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
777 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
778
779 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
780 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
781 /* BTS->BSC: respond with CHAN REL ACK */
782 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
783
784 /* BSC->MSC: expect Clear Complete from BSC */
785 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
786
787 /* BSC<-MSC: MSC disconnects as requested. */
788 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
789
790 setverdict(pass);
791}
792
Harald Welte91d54a52018-01-28 15:35:07 +0100793function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr, boolean flush := true,
794 boolean handle_rll_rel := true) runs on test_CT {
795
796 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
797 if (flush) {
798 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
799 IPA_RSL[bts_nr].clear;
800 }
801 alt {
802 /* ignore DEACTIVATE SACCH (if any) */
803 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
804 tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
805 repeat;
806 }
807 /* acknowledge RLL release (if any)*/
808 [handle_rll_rel] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
809 tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
810 /* FIXME: Why are we getting this for LinkID SACCH? */
811 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
812 repeat;
813 }
Neels Hofmeyr92d48422018-06-14 04:05:07 +0200814 [not handle_rll_rel] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
815 tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
816 /* Do not reply, just continue */
817 repeat;
818 }
Harald Welte91d54a52018-01-28 15:35:07 +0100819 /* Expect RF channel release from BSC on Abis */
820 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
821 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
822 /* respond with CHAN REL ACK */
823 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
824 }
825 /* ignore any user data */
826 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_MsgTypeR(?))) {
827 repeat;
828 }
829 }
830}
831
Harald Welte4003d112017-12-09 22:35:39 +0100832/* Test behavior of channel release after hard Clear Command from MSC */
833testcase TC_chan_rel_hard_clear() runs on test_CT {
834 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100835 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +0100836
Harald Welte89d42e82017-12-17 16:42:41 +0100837 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100838
839 dt := f_est_dchan('23'O, 23, '00010203040506'O);
840
841 /* Instruct BSC to clear channel */
842 var BssmapCause cause := 0;
843 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
844
845 /* expect Clear Complete from BSC on A */
846 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
847 /* release the SCCP connection */
848 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
849 }
850
Harald Welte91d54a52018-01-28 15:35:07 +0100851 f_expect_chan_rel(0, dt.rsl_chan_nr);
Harald Welte4003d112017-12-09 22:35:39 +0100852 setverdict(pass);
853}
854
Harald Welted8c36cd2017-12-09 23:05:31 +0100855/* Test behavior of channel release after hard RLSD from MSC */
856testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +0100857 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +0100858
Harald Welte89d42e82017-12-17 16:42:41 +0100859 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +0100860
861 dt := f_est_dchan('23'O, 23, '00010203040506'O);
862
863 /* release the SCCP connection */
864 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
865
Harald Welte91d54a52018-01-28 15:35:07 +0100866 f_expect_chan_rel(0, dt.rsl_chan_nr);
Harald Welted8c36cd2017-12-09 23:05:31 +0100867 setverdict(pass);
868}
869
Harald Welte550daf92018-06-11 19:22:13 +0200870/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
871testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
872 var DchanTuple dt;
873
874 f_init(1);
875
876 dt := f_est_dchan('23'O, 23, '00010203040506'O);
877
878 /* release the SCCP connection */
879 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
880
881 f_expect_chan_rel(0, dt.rsl_chan_nr, true, false);
882 setverdict(pass);
883}
884
Harald Welte85804d42017-12-10 14:11:58 +0100885/* Test behavior of channel release after BSSMAP RESET from MSC */
886testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +0100887 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +0100888
Harald Welte89d42e82017-12-17 16:42:41 +0100889 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +0100890
891 dt := f_est_dchan('23'O, 23, '00010203040506'O);
892
893 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
894 IPA_RSL[0].clear;
895
896 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Harald Weltea4ca4462018-02-09 00:17:14 +0100897 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 +0100898 interleave {
Harald Weltea4ca4462018-02-09 00:17:14 +0100899 [] 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 +0100900 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
901 }
902
Philipp Maiere8f38ed2018-02-09 10:30:31 +0100903 f_expect_chan_rel(0, dt.rsl_chan_nr, false);
Harald Welte85804d42017-12-10 14:11:58 +0100904 setverdict(pass);
905}
906
Harald Welte5cd20ed2017-12-13 21:03:20 +0100907/* Test behavior if RSL EST IND for non-active channel */
908testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
909 timer T := 2.0;
910
Harald Welte89d42e82017-12-17 16:42:41 +0100911 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100912
913 var octetstring l3 := '00010203040506'O;
914 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
915 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
916
917 T.start;
918 alt {
919 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
920 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
921 }
922 [] BSSAP.receive {}
923 [] IPA_RSL[0].receive {}
924 [] T.timeout {}
925 }
926
927 setverdict(pass);
928}
929
930/* Test behavior if RSL EST IND for invalid SAPI */
931testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
932 var RslChannelNr chan_nr;
933
Harald Welte89d42e82017-12-17 16:42:41 +0100934 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100935
936 chan_nr := f_chreq_act_ack()
937
938 var octetstring l3 := '00010203040506'O;
939 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
940
941 timer T := 2.0;
942 T.start;
943 alt {
944 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
945 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
946 }
947 [] BSSAP.receive { repeat; }
948 [] IPA_RSL[0].receive { repeat; }
949 [] T.timeout {}
950 }
951
952 setverdict(pass);
953}
954
955/* Test behavior if RSL EST IND for invalid SAPI */
956testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
957 timer T := 2.0;
958
Harald Welte89d42e82017-12-17 16:42:41 +0100959 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100960
961 var RslChannelNr chan_nr := f_chreq_act_ack();
962
963 var octetstring l3 := '00010203040506'O;
964 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
965
966 T.start;
967 alt {
968 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
969 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
970 }
971 [] BSSAP.receive { repeat; }
972 [] IPA_RSL[0].receive { repeat; }
973 [] T.timeout {}
974 }
975
976 setverdict(pass);
977}
978
979/* Test behavior if RSL EST IND for invalid SACCH */
980testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
981 timer T := 2.0;
982
Harald Welte89d42e82017-12-17 16:42:41 +0100983 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +0100984
985 var RslChannelNr chan_nr := f_chreq_act_ack();
986
987 var octetstring l3 := '00010203040506'O;
988 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
989
990 T.start;
991 alt {
992 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
993 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
994 }
995 [] BSSAP.receive { repeat; }
996 [] IPA_RSL[0].receive { repeat; }
997 [] T.timeout {}
998 }
999
1000 setverdict(pass);
1001}
1002
1003
1004
Harald Welte4003d112017-12-09 22:35:39 +01001005
1006testcase TC_ctrl_msc_connection_status() runs on test_CT {
1007 var charstring ctrl_resp;
1008
Harald Welte89d42e82017-12-17 16:42:41 +01001009 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001010
1011 /* See https://osmocom.org/issues/2729 */
1012 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
1013 setverdict(pass);
1014}
1015
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001016testcase TC_ctrl_msc0_connection_status() runs on test_CT {
1017 var charstring ctrl_resp;
1018
1019 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001020
1021 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
1022 setverdict(pass);
1023}
1024
Harald Welte4003d112017-12-09 22:35:39 +01001025testcase TC_ctrl() runs on test_CT {
1026 var charstring ctrl_resp;
1027
Harald Welte89d42e82017-12-17 16:42:41 +01001028 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001029
1030 /* all below values must match the osmo-bsc.cfg config file used */
1031
Harald Welte6a129692018-03-17 17:30:14 +01001032 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
1033 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Harald Welte44bdaa52017-12-17 17:01:47 +01001034 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "3");
Harald Welte4003d112017-12-09 22:35:39 +01001035
1036 var integer bts_nr := 0;
1037 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
1038 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
1039 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
1040 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
1041 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
1042 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
1043 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
1044
1045 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
1046 f_sleep(2.0);
1047 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
1048 setverdict(fail, "oml-uptime not incrementing as expected");
1049 }
1050 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
1051
1052 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
1053
1054 setverdict(pass);
Harald Welte96c94412017-12-09 03:12:45 +01001055}
1056
Harald Welte6f521d82017-12-11 19:52:02 +01001057function f_bssap_tx_ud(template PDU_BSSAP bssap) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +01001058 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, bssap));
Harald Welte6f521d82017-12-11 19:52:02 +01001059}
1060
1061
1062/***********************************************************************
1063 * Paging Testing
1064 ***********************************************************************/
1065
1066type record Cell_Identity {
1067 GsmMcc mcc,
1068 GsmMnc mnc,
1069 GsmLac lac,
1070 GsmCellId ci
1071};
Harald Welte24135bd2018-03-17 19:27:53 +01001072private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01001073private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01001074
Harald Welte5d1a2202017-12-13 19:51:29 +01001075type set of integer BtsIdList;
1076
1077private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
1078 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
1079 if (bts_id == bts_ids[j]) {
1080 return true;
1081 }
1082 }
1083 return false;
1084}
Harald Welte6f521d82017-12-11 19:52:02 +01001085
1086/* core paging test helper function; used by most paging test cases */
1087private function f_pageing_helper(hexstring imsi,
1088 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01001089 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01001090 template RSL_ChanNeeded rsl_chneed := omit,
1091 template OCT4 tmsi := omit) runs on test_CT
1092{
1093 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
1094 var MobileIdentity mi;
1095 var template octetstring id_enc; /* FIXME */
1096 var RSL_Message rx_rsl;
1097 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01001098 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01001099
1100 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01001101
1102 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01001103 for (i := 0; i < NUM_BTS; i := i + 1) {
1104 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01001105 }
Harald Welte6f521d82017-12-11 19:52:02 +01001106
1107 if (isvalue(rsl_chneed)) {
1108 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
1109 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
1110 } else {
1111 bssmap_chneed := omit;
1112 }
1113
1114 f_bssap_tx_ud(ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed));
1115
1116/* FIXME: Disabled due to bugs in both GSM_RR_Types and MobileL3_CommonIE_Types IMSI encoder
1117 if (isvalue(tmsi)) {
1118 mi := valueof(t_Osmo_MI_TMSI(oct2int(valueof(tmsi))));
1119 } else {
1120 mi := valueof(ts_Osmo_MI_IMSI(imsi));
1121 }
1122 id_enc := enc_MobileIdentity(mi);
1123*/
1124 id_enc := ?;
Harald Welte5d1a2202017-12-13 19:51:29 +01001125 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
1126 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(id_enc));
1127 /* check channel type, paging group */
1128 if (rx_rsl.ies[1].body.paging_group != paging_group) {
1129 setverdict(fail, "Paging for wrong paging group");
1130 }
1131 if (ispresent(rsl_chneed) and
1132 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
1133 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
1134 }
Harald Welte6f521d82017-12-11 19:52:02 +01001135 }
Harald Welte2fccd982018-01-31 15:48:19 +01001136 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01001137 /* do a quick check on all not-included BTSs if they received paging */
1138 for (i := 0; i < NUM_BTS; i := i + 1) {
1139 timer T := 0.1;
1140 if (f_bts_in_list(i, bts_ids)) {
1141 continue;
1142 }
1143 T.start;
1144 alt {
1145 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(id_enc))) {
1146 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
1147 }
1148 [] IPA_RSL[i].receive { repeat; }
1149 [] T.timeout { }
1150 }
Harald Welte6f521d82017-12-11 19:52:02 +01001151 }
1152
1153 setverdict(pass);
1154}
1155
Harald Welte5d1a2202017-12-13 19:51:29 +01001156const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01001157const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01001158const BtsIdList c_BtsId_LAC1 := { 0, 1 };
1159const BtsIdList c_BtsId_LAC2 := { 2 };
1160
Harald Welte6f521d82017-12-11 19:52:02 +01001161/* PAGING by IMSI + TMSI */
1162testcase TC_paging_imsi_nochan() runs on test_CT {
1163 var BSSMAP_FIELD_CellIdentificationList cid_list;
1164 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01001165 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001166 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001167}
1168
1169/* PAGING by IMSI + TMSI */
1170testcase TC_paging_tmsi_nochan() runs on test_CT {
1171 var BSSMAP_FIELD_CellIdentificationList cid_list;
1172 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001173 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001174 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001175}
1176
1177/* Paging with different "channel needed' values */
1178testcase TC_paging_tmsi_any() runs on test_CT {
1179 var BSSMAP_FIELD_CellIdentificationList cid_list;
1180 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001181 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001182 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001183}
1184testcase TC_paging_tmsi_sdcch() runs on test_CT {
1185 var BSSMAP_FIELD_CellIdentificationList cid_list;
1186 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001187 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001188 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001189}
1190testcase TC_paging_tmsi_tch_f() runs on test_CT {
1191 var BSSMAP_FIELD_CellIdentificationList cid_list;
1192 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001193 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001194 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001195}
1196testcase TC_paging_tmsi_tch_hf() runs on test_CT {
1197 var BSSMAP_FIELD_CellIdentificationList cid_list;
1198 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001199 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001200 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001201}
1202
1203/* Paging by CGI */
1204testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
1205 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1206 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001207 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001208 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001209}
1210
1211/* Paging by LAC+CI */
1212testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
1213 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1214 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001215 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001216 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001217}
1218
1219/* Paging by CI */
1220testcase TC_paging_imsi_nochan_ci() runs on test_CT {
1221 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1222 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001223 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001224 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001225}
1226
1227/* Paging by LAI */
1228testcase TC_paging_imsi_nochan_lai() runs on test_CT {
1229 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1230 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001231 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001232 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001233}
1234
1235/* Paging by LAC */
1236testcase TC_paging_imsi_nochan_lac() runs on test_CT {
1237 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1238 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001239 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001240 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001241}
1242
1243/* Paging by "all in BSS" */
1244testcase TC_paging_imsi_nochan_all() runs on test_CT {
1245 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1246 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01001247 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001248 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001249}
1250
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001251/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001252testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
1253 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1254 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 +01001255 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001256 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001257}
Harald Welte6f521d82017-12-11 19:52:02 +01001258
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001259/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001260testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
1261 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1262 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001263 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001264 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001265}
1266
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001267/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001268testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
1269 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1270 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001271 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001272 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001273}
1274
Harald Welte6f521d82017-12-11 19:52:02 +01001275/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01001276testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
1277 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1278 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
1279 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001280 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001281}
1282
1283/* Paging on empty list: Verify none of them page */
1284testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
1285 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1286 cid_list := { cIl_LAC := { } };
1287 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001288 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001289}
1290
Stefan Sperling049a86e2018-03-20 15:51:00 +01001291/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
1292testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
1293 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1294 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
1295 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
1296 f_shutdown_helper();
1297}
1298
Harald Welte6f521d82017-12-11 19:52:02 +01001299/* Verify paging retransmission interval + count */
1300/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01001301/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01001302
Harald Weltee65d40e2017-12-13 00:09:06 +01001303/* Verify PCH load */
1304testcase TC_paging_imsi_load() runs on test_CT {
1305 var BSSMAP_FIELD_CellIdentificationList cid_list;
1306 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01001307 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01001308 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001309 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01001310
1311 /* tell BSC there is no paging space anymore */
1312 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01001313 f_sleep(0.2);
1314 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01001315
1316 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
1317 * there would be 8 retransmissions during 4 seconds */
1318 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01001319 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01001320 alt {
1321 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1322 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02001323 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01001324 }
Harald Welte2caa1062018-03-17 18:19:05 +01001325 [] T_retrans.timeout {
1326 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
1327 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
1328 T_retrans.start;
1329 repeat;
1330 }
Harald Weltee65d40e2017-12-13 00:09:06 +01001331 [] T.timeout {
1332 setverdict(pass);
1333 }
1334 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001335
1336 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01001337}
1338
Harald Welte235ebf12017-12-15 14:18:16 +01001339/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01001340testcase TC_paging_counter() runs on test_CT {
1341 var BSSMAP_FIELD_CellIdentificationList cid_list;
1342 timer T := 4.0;
1343 var integer i;
1344 var integer paging_attempted_bsc;
1345 var integer paging_attempted_bts[NUM_BTS];
1346 var integer paging_expired_bts[NUM_BTS];
1347 cid_list := valueof(ts_BSSMAP_CIL_noCell);
1348
1349 f_init();
1350
1351 /* read counters before paging */
1352 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
1353 for (i := 0; i < NUM_BTS; i := i+1) {
1354 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
1355 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
1356 }
1357
1358 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
1359
1360 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
1361 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
1362 for (i := 0; i < NUM_BTS; i := i+1) {
1363 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
1364 paging_attempted_bts[i]+1);
1365 }
1366
1367 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
1368 f_sleep(12.0);
1369 for (i := 0; i < NUM_BTS; i := i+1) {
1370 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
1371 paging_expired_bts[i]+1);
1372 }
Harald Welte1ff69992017-12-14 12:31:17 +01001373
Philipp Maier282ca4b2018-02-27 17:17:00 +01001374 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01001375}
1376
1377
Harald Welte10985002017-12-12 09:29:15 +01001378/* Verify paging stops after A-RESET */
1379testcase TC_paging_imsi_a_reset() runs on test_CT {
1380 var BSSMAP_FIELD_CellIdentificationList cid_list;
1381 timer T := 3.0;
1382 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001383 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01001384
1385 /* Perform a BSSMAP Reset and wait for ACK */
Harald Weltea4ca4462018-02-09 00:17:14 +01001386 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 +01001387 alt {
Harald Weltea4ca4462018-02-09 00:17:14 +01001388 [] 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 +01001389 [] BSSAP.receive { repeat; }
1390 }
1391
1392 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01001393 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
1394 IPA_RSL[i].clear;
1395 }
Harald Welte10985002017-12-12 09:29:15 +01001396
1397 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
1398 T.start;
1399 alt {
1400 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1401 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001402 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01001403 }
Harald Welte5d1a2202017-12-13 19:51:29 +01001404 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1405 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001406 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001407 }
1408 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1409 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001410 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001411 }
Harald Welte10985002017-12-12 09:29:15 +01001412 [] T.timeout {
1413 setverdict(pass);
1414 }
1415 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001416
1417 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01001418}
Harald Welteae026692017-12-09 01:03:01 +01001419
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001420/* Test RSL link drop causes counter increment */
1421testcase TC_rsl_drop_counter() runs on test_CT {
1422 var integer rsl_fail;
1423
Harald Welte89d42e82017-12-17 16:42:41 +01001424 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001425
1426 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
1427
1428 bts[0].rsl.vc_IPA.stop;
1429
1430 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
1431
1432 setverdict(pass);
1433}
1434
1435/* TODO: Test OML link drop causes counter increment */
1436
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001437/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
1438function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
1439 timer T := 10.0;
1440
1441 bts[0].rsl.id := "IPA-0-RSL";
1442 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
1443 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
1444 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
1445 bts[0].rsl.ccm_pars.unit_id := "0/0/0"; /* value which is unknown at BTS */
1446
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001447 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
1448
1449 f_init_mgcp("VirtMSC");
1450
1451 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
1452 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
1453 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
1454 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
1455
1456 /* wait for IPA OML link to connect and then disconnect */
1457 T.start;
1458 alt {
1459 [] IPA_RSL[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) {
1460 T.stop;
1461 return true;
1462 }
1463 [] IPA_RSL[0].receive { repeat }
1464 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02001465 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001466 }
1467 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001468 return false;
1469}
1470
1471/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1472testcase TC_rsl_unknown_unit_id() runs on test_CT {
1473 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
1474 setverdict(pass);
1475 } else {
1476 setverdict(fail, "Timeout RSL waiting for connection to close");
1477 }
1478}
1479
1480
1481/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1482testcase TC_oml_unknown_unit_id() runs on test_CT {
1483 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
1484 setverdict(pass);
1485 } else {
1486 setverdict(fail, "Timeout OML waiting for connection to close");
1487 }
1488}
1489
1490
Harald Weltec1a2fff2017-12-17 11:06:19 +01001491/***********************************************************************
1492 * "New world" test cases using RSL_Emulation + BSSMAP_Emulation
1493 ***********************************************************************/
1494
1495import from BSSMAP_Emulation all;
1496import from RSL_Emulation all;
1497import from MSC_ConnectionHandler all;
1498
1499type function void_fn(charstring id) runs on MSC_ConnHdlr;
1500
Harald Welte336820c2018-05-31 20:34:52 +02001501/* helper function to create and connect a MSC_ConnHdlr component */
Harald Welteff579f92018-05-31 22:19:39 +02001502private function f_connect_handler(inout MSC_ConnHdlr vc_conn) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +01001503 connect(vc_conn:BSSMAPEM, g_bssap.vc_BSSMAP:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001504 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001505 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01001506 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01001507 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01001508 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
1509 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
1510 }
Harald Weltea4ca4462018-02-09 00:17:14 +01001511 connect(vc_conn:BSSAP, g_bssap.vc_BSSMAP:CLIENT);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001512 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Harald Welte336820c2018-05-31 20:34:52 +02001513}
1514
1515function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
1516runs on test_CT return MSC_ConnHdlr {
1517 var charstring id := testcasename();
1518 var MSC_ConnHdlr vc_conn;
1519 vc_conn := MSC_ConnHdlr.create(id);
1520 f_connect_handler(vc_conn);
Harald Weltea0630032018-03-20 21:09:55 +01001521 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001522 return vc_conn;
1523}
1524
Harald Weltea0630032018-03-20 21:09:55 +01001525/* first function inside ConnHdlr component; sets g_pars + starts function */
1526private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
1527runs on MSC_ConnHdlr {
1528 if (isvalue(pars)) {
1529 g_pars := valueof(pars);
1530 }
1531 fn.apply(id);
1532}
1533
Harald Welte3c86ea02018-05-10 22:28:05 +02001534/* Establish signalling channel (non-assignment case) followed by cipher mode */
1535private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001536 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1537 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02001538 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02001539 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
1540 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
1541 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
1542 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02001543
Philipp Maier23000732018-05-18 11:25:37 +02001544 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02001545}
1546testcase TC_ciph_mode_a5_0() runs on test_CT {
1547 var MSC_ConnHdlr vc_conn;
1548 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1549 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
1550
1551 f_init(1, true);
1552 f_sleep(1.0);
1553 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1554 vc_conn.done;
1555}
1556testcase TC_ciph_mode_a5_1() runs on test_CT {
1557 var MSC_ConnHdlr vc_conn;
1558 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1559 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
1560
1561 f_init(1, true);
1562 f_sleep(1.0);
1563 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1564 vc_conn.done;
1565}
1566testcase TC_ciph_mode_a5_3() runs on test_CT {
1567 var MSC_ConnHdlr vc_conn;
1568 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1569 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
1570
1571 f_init(1, true);
1572 f_sleep(1.0);
1573 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1574 vc_conn.done;
1575}
1576
1577
1578/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02001579private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001580 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1581 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01001582
Harald Welte552620d2017-12-16 23:21:36 +01001583 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1584 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01001585
Harald Weltea0630032018-03-20 21:09:55 +01001586 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01001587}
Harald Welte552620d2017-12-16 23:21:36 +01001588testcase TC_assignment_fr_a5_0() runs on test_CT {
1589 var MSC_ConnHdlr vc_conn;
Harald Welte651fcdc2018-05-10 20:23:16 +02001590 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1591 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01001592
Harald Welte89d42e82017-12-17 16:42:41 +01001593 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001594 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001595 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01001596 vc_conn.done;
1597}
Harald Welte552620d2017-12-16 23:21:36 +01001598testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01001599 var MSC_ConnHdlr vc_conn;
Harald Welte651fcdc2018-05-10 20:23:16 +02001600 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1601 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001602
Harald Welte89d42e82017-12-17 16:42:41 +01001603 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001604 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001605 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
1606 vc_conn.done;
1607}
1608testcase TC_assignment_fr_a5_3() runs on test_CT {
1609 var MSC_ConnHdlr vc_conn;
1610 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1611 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001612
Harald Welte651fcdc2018-05-10 20:23:16 +02001613 f_init(1, true);
1614 f_sleep(1.0);
1615 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001616 vc_conn.done;
1617}
1618
Harald Welte552620d2017-12-16 23:21:36 +01001619/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
1620private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001621 g_pars := valueof(t_def_TestHdlrPars);
Harald Welte552620d2017-12-16 23:21:36 +01001622 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001623 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001624 const OCT8 kc := '0001020304050607'O;
1625
1626 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Harald Weltea0630032018-03-20 21:09:55 +01001627 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01001628}
Harald Welte552620d2017-12-16 23:21:36 +01001629testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
1630 var MSC_ConnHdlr vc_conn;
1631
Harald Welte89d42e82017-12-17 16:42:41 +01001632 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001633 f_sleep(1.0);
1634
Harald Welte8863fa12018-05-10 20:15:27 +02001635 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01001636 vc_conn.done;
1637}
1638
Harald Welte552620d2017-12-16 23:21:36 +01001639private function f_tc_assignment_fr_a5_4(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001640 g_pars := valueof(t_def_TestHdlrPars);
Harald Welteed848512018-05-24 22:27:58 +02001641 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1642 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001643 const OCT8 kc := '0001020304050607'O;
1644 const OCT16 kc128 := kc & kc;
1645
1646 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1647 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Weltea0630032018-03-20 21:09:55 +01001648 f_establish_fully(ass_cmd, exp_compl);
Harald Welte38b2a102017-12-23 02:42:58 +01001649 f_cipher_mode('10'O, kc, kc128, true);
Harald Welte552620d2017-12-16 23:21:36 +01001650 /* TODO: expect GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED cause value */
Harald Welte552620d2017-12-16 23:21:36 +01001651}
Harald Welte552620d2017-12-16 23:21:36 +01001652testcase TC_assignment_fr_a5_4() runs on test_CT {
1653 var MSC_ConnHdlr vc_conn;
1654
Harald Welte89d42e82017-12-17 16:42:41 +01001655 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001656 f_sleep(1.0);
1657
Harald Welte8863fa12018-05-10 20:15:27 +02001658 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_4));
Harald Welte552620d2017-12-16 23:21:36 +01001659 vc_conn.done;
1660}
1661
1662
Harald Welte4532e0a2017-12-23 02:05:44 +01001663private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier6a50c7c2018-04-16 16:15:59 +02001664 g_pars := valueof(t_def_TestHdlrPars);
Harald Welte4532e0a2017-12-23 02:05:44 +01001665 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
1666 var PDU_BSSAP ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, omit));
1667
1668 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Harald Weltea0630032018-03-20 21:09:55 +01001669 f_establish_fully(ass_cmd, exp_compl);
Harald Welte4532e0a2017-12-23 02:05:44 +01001670}
1671
1672testcase TC_assignment_sign() runs on test_CT {
1673 var MSC_ConnHdlr vc_conn;
1674
1675 f_init(1, true);
1676 f_sleep(1.0);
1677
Harald Welte8863fa12018-05-10 20:15:27 +02001678 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01001679 vc_conn.done;
1680}
1681
Harald Welte60aa5762018-03-21 19:33:13 +01001682/***********************************************************************
1683 * Codec (list) testing
1684 ***********************************************************************/
1685
1686/* check if the given rsl_mode is compatible with the a_elem */
1687private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
1688return boolean {
1689 select (a_elem.codecType) {
1690 case (GSM_FR) {
1691 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
1692 return true;
1693 }
1694 }
1695 case (GSM_HR) {
1696 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
1697 return true;
1698 }
1699 }
1700 case (GSM_EFR) {
1701 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
1702 return true;
1703 }
1704 }
1705 case (FR_AMR) {
1706 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
1707 return true;
1708 }
1709 }
1710 case (HR_AMR) {
1711 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
1712 return true;
1713 }
1714 }
1715 case else { }
1716 }
1717 return false;
1718}
1719
1720/* check if the given rsl_mode is compatible with the a_list */
1721private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
1722return boolean {
1723 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
1724 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
1725 return true;
1726 }
1727 }
1728 return false;
1729}
1730
1731/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02001732function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01001733return BSSMAP_IE_ChannelType {
1734 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
1735 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
1736 select (a_elem.codecType) {
1737 case (GSM_FR) {
1738 ret.channelRateAndType := ChRate_TCHF;
1739 ret.speechId_DataIndicator := Spdi_TCHF_FR;
1740 }
1741 case (GSM_HR) {
1742 ret.channelRateAndType := ChRate_TCHH;
1743 ret.speechId_DataIndicator := Spdi_TCHH_HR;
1744 }
1745 case (GSM_EFR) {
1746 ret.channelRateAndType := ChRate_TCHF;
1747 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
1748 }
1749 case (FR_AMR) {
1750 ret.channelRateAndType := ChRate_TCHF;
1751 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
1752 }
1753 case (HR_AMR) {
1754 ret.channelRateAndType := ChRate_TCHH;
1755 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
1756 }
1757 case else {
1758 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02001759 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01001760 }
1761 }
1762 return ret;
1763}
1764
Harald Weltea63b9102018-03-22 20:36:16 +01001765private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
1766return template RSL_IE_Body {
1767 var template RSL_IE_Body mode_ie := {
1768 chan_mode := {
1769 len := ?,
1770 reserved := ?,
1771 dtx_d := ?,
1772 dtx_u := ?,
1773 spd_ind := RSL_SPDI_SPEECH,
1774 ch_rate_type := -,
1775 coding_alg_rate := -
1776 }
1777 }
1778
1779 select (a_elem.codecType) {
1780 case (GSM_FR) {
1781 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1782 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1783 }
1784 case (GSM_HR) {
1785 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1786 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1787 }
1788 case (GSM_EFR) {
1789 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1790 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
1791 }
1792 case (FR_AMR) {
1793 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1794 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1795 }
1796 case (HR_AMR) {
1797 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1798 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1799 }
1800 }
1801 return mode_ie;
1802}
1803
Harald Welte60aa5762018-03-21 19:33:13 +01001804type record CodecListTest {
1805 BSSMAP_IE_SpeechCodecList codec_list,
1806 charstring id
1807}
1808type record of CodecListTest CodecListTests
1809
1810private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001811 var PDU_BSSAP ass_cmd := f_gen_ass_req();
1812 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
Harald Welte60aa5762018-03-21 19:33:13 +01001813
1814 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Harald Welte79f3f542018-05-25 20:02:37 +02001815 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
1816 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
1817 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
1818 g_pars.ass_codec_list.codecElements[0];
1819 }
Harald Welte60aa5762018-03-21 19:33:13 +01001820 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
1821 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01001822 log("expecting ASS COMPL like this: ", exp_compl);
1823
1824 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01001825
1826 /* Verify that the RSL-side activation actually matches our expectations */
1827 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
1828
1829 var RSL_IE_Body mode_ie;
1830 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
1831 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02001832 mtc.stop;
Harald Weltea63b9102018-03-22 20:36:16 +01001833 }
1834 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
1835 if (not match(mode_ie, t_mode_ie)) {
1836 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
1837 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001838
1839 var RSL_IE_Body mr_conf;
1840 if (g_pars.expect_mr_conf_ie != omit) {
1841 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
1842 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
Daniel Willmannafce8662018-07-06 23:11:32 +02001843 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001844 }
1845 log("found RSL MR CONFIG IE: ", mr_conf);
1846
1847 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
1848 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
1849 g_pars.expect_mr_conf_ie);
1850 }
1851 } else {
1852 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
1853 log("found RSL MR CONFIG IE: ", mr_conf);
1854 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
Daniel Willmannafce8662018-07-06 23:11:32 +02001855 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001856 }
1857 }
Harald Welte60aa5762018-03-21 19:33:13 +01001858}
1859
1860testcase TC_assignment_codec_fr() runs on test_CT {
1861 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1862 var MSC_ConnHdlr vc_conn;
1863
1864 f_init(1, true);
1865 f_sleep(1.0);
1866
1867 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02001868 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001869 vc_conn.done;
1870}
1871
1872testcase TC_assignment_codec_hr() runs on test_CT {
1873 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1874 var MSC_ConnHdlr vc_conn;
1875
1876 f_init(1, true);
1877 f_sleep(1.0);
1878
1879 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02001880 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001881 vc_conn.done;
1882}
1883
1884testcase TC_assignment_codec_efr() runs on test_CT {
1885 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1886 var MSC_ConnHdlr vc_conn;
1887
1888 f_init(1, true);
1889 f_sleep(1.0);
1890
1891 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02001892 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001893 vc_conn.done;
1894}
1895
1896testcase TC_assignment_codec_amr_f() runs on test_CT {
1897 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1898 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001899 var RSL_IE_Body mr_conf := {
1900 other := {
1901 len := 2,
1902 payload := '2804'O
1903 }
1904 };
Harald Welte60aa5762018-03-21 19:33:13 +01001905
1906 f_init(1, true);
1907 f_sleep(1.0);
1908
1909 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001910 pars.expect_mr_conf_ie := mr_conf;
Harald Welte8863fa12018-05-10 20:15:27 +02001911 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001912 vc_conn.done;
1913}
1914
1915testcase TC_assignment_codec_amr_h() runs on test_CT {
1916 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
1917 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001918 var RSL_IE_Body mr_conf := {
1919 other := {
1920 len := 2,
1921 payload := '2804'O
1922 }
1923 };
Harald Welte60aa5762018-03-21 19:33:13 +01001924
1925 f_init(1, true);
1926 f_sleep(1.0);
1927
1928 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02001929 pars.expect_mr_conf_ie := mr_conf;
Harald Welte8863fa12018-05-10 20:15:27 +02001930 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01001931 vc_conn.done;
1932}
1933
Harald Welte898113b2018-01-31 18:32:21 +01001934/* test if L3 RR CLASSMARK CHANGE is translated to BSSMAP CLASSMARK UPDATE */
1935private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001936 g_pars := valueof(t_def_TestHdlrPars);
1937 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01001938 /* we should now have a COMPL_L3 at the MSC */
1939 BSSAP.receive(tr_BSSMAP_ComplL3);
1940
1941 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
1942 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
1943 setverdict(pass);
1944}
1945testcase TC_classmark() runs on test_CT {
1946 var MSC_ConnHdlr vc_conn;
1947 f_init(1, true);
1948 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02001949 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01001950 vc_conn.done;
1951}
1952
Harald Weltee3bd6582018-01-31 22:51:25 +01001953private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01001954 g_pars := valueof(t_def_TestHdlrPars);
1955 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01001956 /* we should now have a COMPL_L3 at the MSC */
1957 BSSAP.receive(tr_BSSMAP_ComplL3);
1958
Harald Weltee3bd6582018-01-31 22:51:25 +01001959 /* send the single message we want to send */
1960 f_rsl_send_l3(l3);
1961}
1962
1963private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
1964 timer T := sec;
1965 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01001966 T.start;
1967 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01001968 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
1969 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02001970 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01001971 }
1972 [] T.timeout {
1973 setverdict(pass);
1974 }
1975 }
1976}
1977
Harald Weltee3bd6582018-01-31 22:51:25 +01001978/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
1979private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
1980 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
1981 f_bssap_expect_nothing();
1982}
Harald Welte898113b2018-01-31 18:32:21 +01001983testcase TC_unsol_ass_fail() runs on test_CT {
1984 var MSC_ConnHdlr vc_conn;
1985 f_init(1, true);
1986 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02001987 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01001988 vc_conn.done;
1989}
Harald Welte552620d2017-12-16 23:21:36 +01001990
Harald Welteea99a002018-01-31 20:46:43 +01001991
1992/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
1993private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01001994 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
1995 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01001996}
1997testcase TC_unsol_ass_compl() runs on test_CT {
1998 var MSC_ConnHdlr vc_conn;
1999 f_init(1, true);
2000 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002001 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01002002 vc_conn.done;
2003}
2004
2005
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002006/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2007private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002008 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
2009 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002010}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002011testcase TC_unsol_ho_fail() runs on test_CT {
2012 var MSC_ConnHdlr vc_conn;
2013 f_init(1, true);
2014 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002015 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002016 vc_conn.done;
2017}
2018
2019
Harald Weltee3bd6582018-01-31 22:51:25 +01002020/* short message from MS should be ignored */
2021private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01002022 g_pars := valueof(t_def_TestHdlrPars);
2023 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01002024 /* we should now have a COMPL_L3 at the MSC */
2025 BSSAP.receive(tr_BSSMAP_ComplL3);
2026
2027 /* send short message */
2028 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
2029 f_bssap_expect_nothing();
2030}
2031testcase TC_err_82_short_msg() runs on test_CT {
2032 var MSC_ConnHdlr vc_conn;
2033 f_init(1, true);
2034 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002035 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01002036 vc_conn.done;
2037}
2038
2039
Harald Weltee9e02e42018-01-31 23:36:25 +01002040/* 24.008 8.4 Unknown message must trigger RR STATUS */
2041private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
2042 f_est_single_l3(ts_RRM_UL_REL('00'O));
2043 timer T := 3.0
2044 alt {
2045 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
2046 setverdict(pass);
2047 }
2048 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01002049 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01002050 }
2051}
2052testcase TC_err_84_unknown_msg() runs on test_CT {
2053 var MSC_ConnHdlr vc_conn;
2054 f_init(1, true);
2055 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002056 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01002057 vc_conn.done;
2058}
2059
Harald Welte94e0c342018-04-07 11:33:23 +02002060/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
2061private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
2062runs on test_CT {
2063 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2064 " timeslot "&int2str(ts_nr)&" ";
2065 f_vty_transceive(BSCVTY, cmd & suffix);
2066}
2067
Harald Welte261af4b2018-02-12 21:20:39 +01002068/* execute a "bts <0-255> trx <0-255> timeslot <0-7> sub-slot <0-7>" command on given Dchan */
2069private function f_vty_ss_action(charstring suffix, integer bts_nr, integer trx_nr, RslChannelNr chan_nr)
2070runs on MSC_ConnHdlr {
2071 /* FIXME: resolve those from component-global state */
2072 var integer ts_nr := chan_nr.tn;
2073 var integer ss_nr;
2074 if (ischosen(chan_nr.u.ch0)) {
2075 ss_nr := 0;
2076 } else if (ischosen(chan_nr.u.lm)) {
2077 ss_nr := chan_nr.u.lm.sub_chan;
2078 } else if (ischosen(chan_nr.u.sdcch4)) {
2079 ss_nr := chan_nr.u.sdcch4.sub_chan;
2080 } else if (ischosen(chan_nr.u.sdcch8)) {
2081 ss_nr := chan_nr.u.sdcch8.sub_chan;
2082 } else {
2083 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02002084 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01002085 }
2086
2087 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2088 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
2089 f_vty_transceive(BSCVTY, cmd & suffix);
2090}
2091
2092private function f_vty_handover(integer bts_nr, integer trx_nr, RslChannelNr chan_nr,
2093 integer new_bts_nr)
2094runs on MSC_ConnHdlr {
2095 f_vty_ss_action("handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
2096}
2097
2098/* intra-BSC hand-over between BTS0 and BTS1 */
2099private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +01002100 g_pars := valueof(t_def_TestHdlrPars);
Harald Welteed848512018-05-24 22:27:58 +02002101 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2102 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01002103 const OCT8 kc := '0001020304050607'O;
2104
2105 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2106 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2107
Harald Weltea0630032018-03-20 21:09:55 +01002108 f_establish_fully(ass_cmd, exp_compl);
Harald Welte261af4b2018-02-12 21:20:39 +01002109
2110 var HandoverState hs := {
2111 rr_ho_cmpl_seen := false,
2112 handover_done := false,
2113 old_chan_nr := -
2114 };
2115 /* issue hand-over command on VTY */
2116 f_vty_handover(0, 0, g_chan_nr, 1);
2117 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
2118 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002119
2120 /* From the MGW perspective, a handover is is characterized by
2121 * performing one MDCX operation with the MGW. So we expect to see
2122 * one more MDCX during handover. */
2123 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
2124
Harald Welte261af4b2018-02-12 21:20:39 +01002125 alt {
2126 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01002127 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002128
2129 /* Check the amount of MGCP transactions is still consistant with the
2130 * test expectation */
2131 f_check_mgcp_expectations()
Harald Welte261af4b2018-02-12 21:20:39 +01002132}
2133
2134testcase TC_ho_int() runs on test_CT {
2135 var MSC_ConnHdlr vc_conn;
2136 f_init(2, true);
2137 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002138 vc_conn := f_start_handler(refers(f_tc_ho_int));
Harald Welte261af4b2018-02-12 21:20:39 +01002139 vc_conn.done;
2140}
Harald Weltee9e02e42018-01-31 23:36:25 +01002141
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002142/* OS#3041: Open and close N connections in a normal fashion, and expect no
2143 * BSSMAP Reset just because of that. */
2144testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
2145 var default d;
2146 var integer i;
2147 var DchanTuple dt;
2148
2149 f_init();
2150
2151 /* Wait for initial BSSMAP Reset to pass */
2152 f_sleep(4.0);
2153
2154 d := activate(no_bssmap_reset());
2155
2156 /* Setup up a number of connections and RLSD them again from the MSC
2157 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
2158 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02002159 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002160 /* Since we're doing a lot of runs, give each one a fresh
2161 * T_guard from the top. */
2162 T_guard.start;
2163
2164 /* Setup a BSSAP connection and clear it right away. This is
2165 * the MSC telling the BSC about a planned release, it's not an
2166 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02002167 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002168
2169 /* MSC disconnects (RLSD). */
2170 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2171 }
2172
2173 /* In the buggy behavior, a timeout of 2 seconds happens between above
2174 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
2175 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
2176 f_sleep(4.0);
2177
2178 deactivate(d);
2179 f_shutdown_helper();
2180}
Harald Welte552620d2017-12-16 23:21:36 +01002181
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002182/* OS#3041: Open and close N connections in a normal fashion, and expect no
2183 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
2184 * the MSC. */
2185testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
2186 var default d;
2187 var integer i;
2188 var DchanTuple dt;
2189 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002190 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
2191 var BssmapCause cause := enum2int(cause_val);
2192
2193 f_init();
2194
2195 /* Wait for initial BSSMAP Reset to pass */
2196 f_sleep(4.0);
2197
2198 d := activate(no_bssmap_reset());
2199
2200 /* Setup up a number of connections and RLSD them again from the MSC
2201 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
2202 * Let's do it some more times for good measure. */
2203 for (i := 0; i < 8; i := i+1) {
2204 /* Since we're doing a lot of runs, give each one a fresh
2205 * T_guard from the top. */
2206 T_guard.start;
2207
2208 /* Setup a BSSAP connection and clear it right away. This is
2209 * the MSC telling the BSC about a planned release, it's not an
2210 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02002211 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002212
2213 /* Instruct BSC to clear channel */
2214 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2215
2216 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02002217 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002218 }
2219
2220 /* In the buggy behavior, a timeout of 2 seconds happens between above
2221 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
2222 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
2223 f_sleep(4.0);
2224
2225 deactivate(d);
2226 f_shutdown_helper();
2227}
2228
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002229/* OS#3041: Open and close N connections in a normal fashion, and expect no
2230 * BSSMAP Reset just because of that. Close connections from the MS side with a
2231 * Release Ind on RSL. */
2232testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
2233 var default d;
2234 var integer i;
2235 var DchanTuple dt;
2236 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002237 var integer j;
2238
2239 f_init();
2240
2241 /* Wait for initial BSSMAP Reset to pass */
2242 f_sleep(4.0);
2243
2244 d := activate(no_bssmap_reset());
2245
2246 /* Setup up a number of connections and RLSD them again from the MSC
2247 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
2248 * Let's do it some more times for good measure. */
2249 for (i := 0; i < 8; i := i+1) {
2250 /* Since we're doing a lot of runs, give each one a fresh
2251 * T_guard from the top. */
2252 T_guard.start;
2253
2254 /* Setup a BSSAP connection and clear it right away. This is
2255 * the MSC telling the BSC about a planned release, it's not an
2256 * erratic loss of a connection. */
2257 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2258
2259 /* simulate RLL REL IND */
2260 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
2261
2262 /* expect Clear Request on MSC side */
2263 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
2264
2265 /* Instruct BSC to clear channel */
2266 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
2267 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2268
2269 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02002270 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002271 }
2272
2273 /* In the buggy behavior, a timeout of 2 seconds happens between above
2274 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
2275 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
2276 f_sleep(4.0);
2277
2278 deactivate(d);
2279 f_shutdown_helper();
2280}
2281
Harald Welte94e0c342018-04-07 11:33:23 +02002282/***********************************************************************
2283 * IPA style dynamic PDCH
2284 ***********************************************************************/
2285
2286private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
2287 template (omit) RSL_Cause nack := omit)
2288runs on test_CT {
2289 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
2290 var RSL_Message rsl_unused;
2291 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2292 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
2293 /* expect the BSC to issue the related RSL command */
2294 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
2295 if (istemplatekind(nack, "omit")) {
2296 /* respond with a related acknowledgement */
2297 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
2298 } else {
2299 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
2300 }
2301}
2302
2303private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
2304 template (omit) RSL_Cause nack := omit)
2305runs on test_CT {
2306 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
2307 var RSL_Message rsl_unused;
2308 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2309 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
2310 /* expect the BSC to issue the related RSL command */
2311 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
2312 if (istemplatekind(nack, "omit")) {
2313 /* respond with a related acknowledgement */
2314 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
2315 } else {
2316 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
2317 }
2318}
2319
2320private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
2321runs on test_CT return charstring {
2322 var charstring cmd, resp;
2323 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
2324 resp := f_vty_transceive_ret(BSCVTY, cmd);
2325 return regexp(resp, "*\((*)\)*", 0);
2326}
2327
2328private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
2329 template charstring exp)
2330runs on test_CT {
2331 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
2332 if (not match(mode, exp)) {
2333 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02002334 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02002335 }
2336}
2337
2338private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
2339runs on test_CT {
2340 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
2341 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
2342 f_vty_transceive(BSCVTY, "end");
2343}
2344
2345private const charstring TCHF_MODE := "TCH/F mode";
2346private const charstring TCHH_MODE := "TCH/H mode";
2347private const charstring PDCH_MODE := "PDCH mode";
2348private const charstring NONE_MODE := "NONE mode";
2349
2350/* Test IPA PDCH activation / deactivation triggered by VTY */
2351testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
2352 var RSL_Message rsl_unused;
2353
2354 /* change Timeslot 6 before f_init() starts RSL */
2355 f_init_vty();
2356 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
2357 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2358
2359 f_init(1, false);
2360 f_sleep(1.0);
2361
2362 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2363
2364 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2365 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2366 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
2367 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
2368 f_sleep(1.0);
2369 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2370
2371 /* De-activate it via VTY */
2372 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
2373 f_sleep(1.0);
2374 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2375
2376 /* re-activate it via VTY */
2377 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
2378 f_sleep(1.0);
2379 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2380
2381 /* and finally de-activate it again */
2382 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
2383 f_sleep(1.0);
2384 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2385
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02002386 /* clean up config */
2387 f_ts_set_chcomb(0, 0, 6, "PDCH");
2388
Harald Welte94e0c342018-04-07 11:33:23 +02002389 setverdict(pass);
2390}
2391
2392/* Test IPA PDCH activation NACK */
2393testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
2394 var RSL_Message rsl_unused;
2395
2396 /* change Timeslot 6 before f_init() starts RSL */
2397 f_init_vty();
2398 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
2399 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2400
2401 f_init(1, false);
2402 f_sleep(1.0);
2403
2404 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2405
2406 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2407 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2408 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
2409 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
2410 f_sleep(1.0);
2411 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2412
2413 /* De-activate it via VTY */
2414 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
2415 f_sleep(1.0);
2416 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2417
2418 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
2419 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
2420 f_sleep(1.0);
2421 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
2422
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02002423 /* clean up config */
2424 f_ts_set_chcomb(0, 0, 6, "PDCH");
2425
Harald Welte94e0c342018-04-07 11:33:23 +02002426 setverdict(pass);
2427}
2428
2429
2430/***********************************************************************
2431 * Osmocom style dynamic PDCH
2432 ***********************************************************************/
2433
2434private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
2435 template (omit) RSL_Cause nack := omit)
2436runs on test_CT {
2437 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
2438 var RSL_Message rsl_unused;
2439 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2440 /* FIXME: no VTY command to activate Osmocom PDCH !! */
2441 /* expect the BSC to issue the related RSL command */
2442 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
2443 if (istemplatekind(nack, "omit")) {
2444 /* respond with a related acknowledgement */
2445 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
2446 } else {
2447 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
2448 }
2449}
2450
2451private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
2452 template (omit) RSL_Cause nack := omit)
2453runs on test_CT {
2454 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
2455 var RSL_Message rsl_unused;
2456 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
2457 /* FIXME: no VTY command to activate Osmocom PDCH !! */
2458 /* expect the BSC to issue the related RSL command */
2459 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
2460 if (istemplatekind(nack, "omit")) {
2461 /* respond with a related acknowledgement */
2462 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
2463 } else {
2464 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
2465 }
2466}
2467
2468/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
2469testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
2470 var RSL_Message rsl_unused;
2471
2472 /* change Timeslot 6 before f_init() starts RSL */
2473 f_init_vty();
2474 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
2475 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2476
2477 f_init(1, false);
2478 f_sleep(1.0);
2479
2480 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
2481
2482 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
2483 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2484 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
2485
2486 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
2487 f_sleep(1.0);
2488 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
2489
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02002490 /* clean up config */
2491 f_ts_set_chcomb(0, 0, 6, "PDCH");
2492
Harald Welte94e0c342018-04-07 11:33:23 +02002493 setverdict(pass);
2494}
2495
2496/* Test Osmocom dyn PDCH activation NACK behavior */
2497testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
2498 var RSL_Message rsl_unused;
2499
2500 /* change Timeslot 6 before f_init() starts RSL */
2501 f_init_vty();
2502 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
2503 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
2504
2505 f_init(1, false);
2506 f_sleep(1.0);
2507
2508 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
2509
2510 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
2511 /* The BSC will activate the dynamic PDCH by default, so confirm that */
2512 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
2513
2514 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
2515 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
2516 f_sleep(1.0);
2517 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
2518
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02002519 /* clean up config */
2520 f_ts_set_chcomb(0, 0, 6, "PDCH");
2521
Harald Welte94e0c342018-04-07 11:33:23 +02002522 setverdict(pass);
2523}
2524
Harald Welte0ea2d5e2018-04-07 21:40:29 +02002525/* Dyn PDCH todo:
2526 * activate OSMO as TCH/F
2527 * activate OSMO as TCH/H
2528 * does the BSC-located PCU socket get the updated INFO?
2529 * what if no PCU is connected at the time?
2530 * is the info correct on delayed PCU (re)connect?
2531 */
Harald Welte94e0c342018-04-07 11:33:23 +02002532
Harald Welte28d943e2017-11-25 15:00:50 +01002533control {
Harald Welte898113b2018-01-31 18:32:21 +01002534 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +01002535 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002536 execute( TC_ctrl_msc0_connection_status() );
Harald Welte96c94412017-12-09 03:12:45 +01002537 execute( TC_ctrl() );
Harald Welte898113b2018-01-31 18:32:21 +01002538
2539 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +01002540 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +01002541 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +01002542 execute( TC_chan_act_ack_noest() );
2543 execute( TC_chan_act_ack_est_ind_noreply() );
2544 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +01002545 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +01002546 execute( TC_chan_exhaustion() );
Harald Welte4003d112017-12-09 22:35:39 +01002547 execute( TC_chan_rel_rll_rel_ind() );
2548 execute( TC_chan_rel_conn_fail() );
2549 execute( TC_chan_rel_hard_clear() );
Harald Welted8c36cd2017-12-09 23:05:31 +01002550 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +02002551 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +01002552 execute( TC_chan_rel_a_reset() );
Harald Welte6f521d82017-12-11 19:52:02 +01002553
Harald Weltecfe2c962017-12-15 12:09:32 +01002554 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +01002555
2556 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +01002557 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +01002558 execute( TC_assignment_csd() );
2559 execute( TC_assignment_ctm() );
2560 execute( TC_assignment_sign() );
2561 execute( TC_assignment_fr_a5_0() );
2562 execute( TC_assignment_fr_a5_1() );
Harald Welte8f67d1d2018-05-25 20:38:42 +02002563 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
2564 execute( TC_assignment_fr_a5_1_codec_missing() );
2565 }
Harald Welte235ebf12017-12-15 14:18:16 +01002566 execute( TC_assignment_fr_a5_3() );
2567 execute( TC_assignment_fr_a5_4() );
Harald Welte3c86ea02018-05-10 22:28:05 +02002568 execute( TC_ciph_mode_a5_0() );
2569 execute( TC_ciph_mode_a5_1() );
2570 execute( TC_ciph_mode_a5_3() );
Harald Welte16a4adf2017-12-14 18:54:01 +01002571
Harald Welte60aa5762018-03-21 19:33:13 +01002572 execute( TC_assignment_codec_fr() );
2573 execute( TC_assignment_codec_hr() );
2574 execute( TC_assignment_codec_efr() );
2575 execute( TC_assignment_codec_amr_f() );
2576 execute( TC_assignment_codec_amr_h() );
2577
Harald Welte898113b2018-01-31 18:32:21 +01002578 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +01002579 execute( TC_rll_est_ind_inact_lchan() );
2580 execute( TC_rll_est_ind_inval_sapi1() );
2581 execute( TC_rll_est_ind_inval_sapi3() );
2582 execute( TC_rll_est_ind_inval_sacch() );
2583
Harald Welte898113b2018-01-31 18:32:21 +01002584 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +01002585 execute( TC_paging_imsi_nochan() );
2586 execute( TC_paging_tmsi_nochan() );
2587 execute( TC_paging_tmsi_any() );
2588 execute( TC_paging_tmsi_sdcch() );
2589 execute( TC_paging_tmsi_tch_f() );
2590 execute( TC_paging_tmsi_tch_hf() );
2591 execute( TC_paging_imsi_nochan_cgi() );
2592 execute( TC_paging_imsi_nochan_lac_ci() );
2593 execute( TC_paging_imsi_nochan_ci() );
2594 execute( TC_paging_imsi_nochan_lai() );
2595 execute( TC_paging_imsi_nochan_lac() );
2596 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +01002597 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
2598 execute( TC_paging_imsi_nochan_rnc() );
2599 execute( TC_paging_imsi_nochan_lac_rnc() );
2600 execute( TC_paging_imsi_nochan_lacs() );
2601 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +01002602 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +01002603 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +01002604 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +01002605 execute( TC_paging_counter() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +01002606
2607 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +01002608 execute( TC_rsl_unknown_unit_id() );
2609
2610 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +01002611
2612 execute( TC_classmark() );
2613 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +01002614 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002615 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +01002616 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +01002617 execute( TC_err_84_unknown_msg() );
Harald Welte261af4b2018-02-12 21:20:39 +01002618 execute( TC_ho_int() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01002619
2620 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01002621 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01002622 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +02002623
2624 execute( TC_dyn_pdch_ipa_act_deact() );
2625 execute( TC_dyn_pdch_ipa_act_nack() );
2626 execute( TC_dyn_pdch_osmo_act_deact() );
2627 execute( TC_dyn_pdch_osmo_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +02002628
2629 /* at bottom as they might crash OsmoBSC before OS#3182 is fixed */
2630 execute( TC_early_conn_fail() );
2631 execute( TC_late_conn_fail() );
2632
Harald Welte28d943e2017-11-25 15:00:50 +01002633}
2634
2635}