blob: a84277f04997371bbd2ccaaa6d0d5f442a44b6c0 [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 *
Harald Welte34b5a952019-05-27 11:54:11 +020010 * SPDX-License-Identifier: GPL-2.0-or-later
11 *
Harald Welte21b46bd2017-12-17 19:46:32 +010012 * This test suite tests OsmoBSC while emulating both multiple BTS + MS as
13 * well as the MSC. See README for more details.
14 *
15 * There are test cases that run in so-called 'handler mode' and test cases
16 * that run directly on top of the BSSAP and RSL CodecPorts. The "handler mode"
17 * tests abstract the multiplexing/demultiplexing of multiple SCCP connections
18 * and/or RSL channels and are hence suitable for higher-level test cases, while
19 * the "raw" tests directly on top of the CodecPorts are more suitable for lower-
20 * level testing.
21 */
22
Harald Welte4003d112017-12-09 22:35:39 +010023import from General_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010024import from Osmocom_Types all;
Harald Welteae026692017-12-09 01:03:01 +010025import from GSM_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010026import from IPL4asp_Types all;
27
Harald Welte6f521d82017-12-11 19:52:02 +010028import from BSSAP_Types all;
Harald Welte6811d102019-04-14 22:23:14 +020029import from RAN_Adapter all;
Harald Welteae026692017-12-09 01:03:01 +010030import from BSSAP_CodecPort all;
31import from BSSMAP_Templates all;
Harald Welte28d943e2017-11-25 15:00:50 +010032import from IPA_Emulation all;
Stefan Sperling830dc9d2018-02-12 21:08:28 +010033import from IPA_CodecPort all;
Harald Welteae026692017-12-09 01:03:01 +010034import from IPA_Types all;
Stefan Sperling0796a822018-10-05 13:01:39 +020035import from IPA_Testing all;
Harald Welteae026692017-12-09 01:03:01 +010036import from RSL_Types all;
Harald Welte624f9632017-12-16 19:26:04 +010037import from RSL_Emulation all;
Daniel Willmann191e0d92018-01-17 12:44:35 +010038import from MGCP_Emulation all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010039import from MGCP_Templates all;
40import from MGCP_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010041
Harald Welte96c94412017-12-09 03:12:45 +010042import from Osmocom_CTRL_Functions all;
Harald Weltea5d2ab22017-12-09 14:21:42 +010043import from Osmocom_CTRL_Types all;
Harald Welteffe55fc2018-01-17 22:39:54 +010044import from Osmocom_CTRL_Adapter all;
Harald Welte96c94412017-12-09 03:12:45 +010045
Harald Weltebc03c762018-02-12 18:09:38 +010046import from Osmocom_VTY_Functions all;
47import from TELNETasp_PortType all;
48
Harald Welte6f521d82017-12-11 19:52:02 +010049import from MobileL3_CommonIE_Types all;
Harald Weltee3bd6582018-01-31 22:51:25 +010050import from MobileL3_Types all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010051import from MobileL3_RRM_Types all;
Harald Welte6f521d82017-12-11 19:52:02 +010052import from L3_Templates all;
53import from GSM_RR_Types all;
54
Stefan Sperlingc307e682018-06-14 15:15:46 +020055import from SCCP_Templates all;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010056import from BSSMAP_Templates all;
57
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010058import from SCCPasp_Types all;
59
Harald Welte5d1a2202017-12-13 19:51:29 +010060const integer NUM_BTS := 3;
Harald Welteae026692017-12-09 01:03:01 +010061const float T3101_MAX := 12.0;
Harald Welte28d943e2017-11-25 15:00:50 +010062
Harald Welte799c97b2017-12-14 17:50:30 +010063/* make sure to sync this with the osmo-bts.cfg you're using */
Philipp Maiercb6cc482018-03-26 13:08:00 +020064const integer NUM_TCHH_PER_BTS := 2;
65const integer NUM_TCHF_PER_BTS := 4;
Harald Weltedd8cbf32018-01-28 12:07:52 +010066const integer NUM_SDCCH_PER_BTS := 4;
Harald Welte799c97b2017-12-14 17:50:30 +010067
Harald Welte4003d112017-12-09 22:35:39 +010068
Harald Welte21b46bd2017-12-17 19:46:32 +010069/* per-BTS state which we keep */
Harald Welte96c94412017-12-09 03:12:45 +010070type record BTS_State {
Harald Welte21b46bd2017-12-17 19:46:32 +010071 /* component reference to the IPA_Client component used for RSL */
Harald Weltea5d2ab22017-12-09 14:21:42 +010072 IPA_Client rsl
Harald Welte96c94412017-12-09 03:12:45 +010073}
74
Harald Weltea4ca4462018-02-09 00:17:14 +010075type component test_CT extends CTRL_Adapter_CT {
Harald Welte21b46bd2017-12-17 19:46:32 +010076 /* Array of per-BTS state */
Harald Welte96c94412017-12-09 03:12:45 +010077 var BTS_State bts[NUM_BTS];
Harald Welte89ab1912018-02-23 18:56:29 +010078 /* RSL common Channel Port (for RSL_Emulation) */
79 port RSL_CCHAN_PT RSL_CCHAN[NUM_BTS];
Harald Welte21b46bd2017-12-17 19:46:32 +010080 /* array of per-BTS RSL test ports */
Harald Welteae026692017-12-09 01:03:01 +010081 port IPA_RSL_PT IPA_RSL[NUM_BTS];
Stefan Sperling830dc9d2018-02-12 21:08:28 +010082 port IPA_CODEC_PT IPA; /* Required for compilation of TC_rsl_unknown_unit_id() */
Harald Weltea5d2ab22017-12-09 14:21:42 +010083
Daniel Willmann191e0d92018-01-17 12:44:35 +010084 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +010085 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +010086
Harald Welte6811d102019-04-14 22:23:14 +020087 var RAN_Adapter g_bssap;
Harald Weltea4ca4462018-02-09 00:17:14 +010088 /* for old legacy-tests only */
89 port BSSAP_CODEC_PT BSSAP;
90
Harald Welte21b46bd2017-12-17 19:46:32 +010091 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +010092 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +010093
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +020094 /* Osmux is enabled through VTY */
95 var boolean g_osmux_enabled := false;
96
Harald Welte21b46bd2017-12-17 19:46:32 +010097 /* global test case guard timer */
Harald Welteae026692017-12-09 01:03:01 +010098 timer T_guard := 30.0;
99
Harald Welte28d943e2017-11-25 15:00:50 +0100100}
101
102modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +0100103 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +0100104 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100105 /* port number to which to establish the IPA OML connections */
106 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +0100107 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +0100108 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +0100109 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +0100110 integer mp_bsc_ctrl_port := 4249;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100111 /* IP address at which the test binds */
112 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100113
Harald Welte6811d102019-04-14 22:23:14 +0200114 RAN_Configuration mp_bssap_cfg := {
Harald Welte7ef51aa2018-04-16 19:16:01 +0200115 transport := BSSAP_TRANSPORT_AoIP,
Harald Weltea4ca4462018-02-09 00:17:14 +0100116 sccp_service_type := "mtp3_itu",
117 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
118 own_pc := 185,
119 own_ssn := 254,
120 peer_pc := 187,
121 peer_ssn := 254,
Philipp Maier38d68942018-03-29 15:38:09 +0200122 sio := '83'O,
123 rctx := 0
Harald Weltea4ca4462018-02-09 00:17:14 +0100124 };
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +0200125
126 /* Whether to enable osmux tests. Can be dropped completely and enable
127 unconditionally once new version of osmo-bsc is released (current
128 version: 1.4.1) */
129 boolean mp_enable_osmux_test := true;
Harald Weltea4ca4462018-02-09 00:17:14 +0100130}
131
Philipp Maier48604732018-10-09 15:00:37 +0200132private function f_gen_test_hdlr_pars() return TestHdlrParams {
133
134 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
135 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
136 pars.aoip := true;
137 } else {
138 pars.aoip := false;
139 }
140
141 return pars;
142}
143
Philipp Maier282ca4b2018-02-27 17:17:00 +0100144private function f_shutdown_helper() runs on test_CT {
Daniel Willmann637ef6c2018-07-25 10:49:09 +0200145 all component.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100146 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200147 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100148}
149
Harald Weltea4ca4462018-02-09 00:17:14 +0100150private function f_legacy_bssap_reset() runs on test_CT {
151 var BSSAP_N_UNITDATA_ind ud_ind;
152 timer T := 5.0;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200153 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, ts_BSSMAP_Reset(0, g_osmux_enabled)));
Harald Weltea4ca4462018-02-09 00:17:14 +0100154 T.start;
155 alt {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200156 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap.sccp_addr_own, g_bssap.sccp_addr_peer, tr_BSSMAP_ResetAck(g_osmux_enabled))) {
Harald Weltea4ca4462018-02-09 00:17:14 +0100157 log("Received RESET-ACK in response to RESET, we're ready to go!");
158 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200159 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Weltea4ca4462018-02-09 00:17:14 +0100160 log("Respoding to inbound RESET with RESET-ACK");
161 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200162 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Weltea4ca4462018-02-09 00:17:14 +0100163 repeat;
164 }
165 [] BSSAP.receive { repeat; }
166 [] T.timeout { setverdict(fail, "Waiting for RESET-ACK after sending RESET"); }
167 }
Harald Welte28d943e2017-11-25 15:00:50 +0100168}
169
Harald Welteae026692017-12-09 01:03:01 +0100170type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100171 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100172 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100173 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100174 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100175 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100176 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100177 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100178 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100179}
180
Harald Welte21b46bd2017-12-17 19:46:32 +0100181/*! Start the IPA/RSL related bits for one IPA_Client.
182 * \param clnt IPA_Client for which to establish
183 * \param bsc_host IP address / hostname of the BSC
184 * \param bsc_port TCP port number of the BSC
185 * \param i number identifying this BTS
186 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100187function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
188 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100189runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100190 timer T := 10.0;
191
Harald Welte96c94412017-12-09 03:12:45 +0100192 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welteae026692017-12-09 01:03:01 +0100193 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA");
194 clnt.ccm_pars := c_IPA_default_ccm_pars;
195 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
196 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100197 if (handler_mode) {
198 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL");
Harald Welte89ab1912018-02-23 18:56:29 +0100199 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100200 }
Harald Welteae026692017-12-09 01:03:01 +0100201
202 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Harald Welte624f9632017-12-16 19:26:04 +0100203 if (handler_mode) {
204 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
205 } else {
206 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
207 }
Harald Welteae026692017-12-09 01:03:01 +0100208
Harald Welte5d1a2202017-12-13 19:51:29 +0100209 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100210 if (handler_mode) {
211 clnt.vc_RSL.start(RSL_Emulation.main());
212 return;
213 }
Harald Welteae026692017-12-09 01:03:01 +0100214
215 /* wait for IPA RSL link to connect and send ID ACK */
216 T.start;
217 alt {
218 [] IPA_RSL[i].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_ID_ACK}) {
219 T.stop;
220 IPA_RSL[i].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_PAGING_LOAD_IND(23)));
221 }
Harald Welte60e823a2017-12-10 14:10:59 +0100222 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100223 [] IPA_RSL[i].receive { repeat }
224 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100225 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200226 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100227 }
228 }
229}
230
Harald Welte12055472018-03-17 20:10:08 +0100231function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
232 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
233 return;
234 }
235 clnt.vc_IPA.stop;
236 if (isbound(clnt.vc_RSL)) {
237 clnt.vc_RSL.stop;
238 }
239}
240
Harald Welte21b46bd2017-12-17 19:46:32 +0100241/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100242function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
243 timer T := secs_max;
244 T.start;
245 while (true) {
246 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
247 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100248 /* the 'degraded' state exists from OML connection time, and we have to wait
249 * until all MO's are initialized */
250 T.start(1.0);
251 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100252 return;
253 }
Harald Weltef0d6ac62017-12-17 17:02:21 +0100254 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100255 if (not T.running) {
Max99253902018-11-16 17:57:39 +0100256 setverdict(fail, "Timeout waiting for BTS" & int2str(bts_nr) & " oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +0200257 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100258 }
259 }
260}
261
Harald Welte21b46bd2017-12-17 19:46:32 +0100262/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +0100263altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +0100264 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100265 [] T_guard.timeout {
266 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +0200267 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100268 }
Harald Welte60e823a2017-12-10 14:10:59 +0100269 /* always respond with RESET ACK to RESET */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200270 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Welte60e823a2017-12-10 14:10:59 +0100271 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200272 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Welte69c1c262017-12-13 21:02:08 +0100273 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +0100274 }
Harald Welte28d943e2017-11-25 15:00:50 +0100275}
276
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100277altstep no_bssmap_reset() runs on test_CT {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200278 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100279 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +0200280 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100281 }
282}
283
Daniel Willmann191e0d92018-01-17 12:44:35 +0100284function f_init_mgcp(charstring id) runs on test_CT {
285 id := id & "-MGCP";
286
287 var MGCPOps ops := {
288 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
289 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
290 };
291 var MGCP_conn_parameters mgcp_pars := {
292 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +0100293 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +0100294 mgw_ip := mp_test_ip,
295 mgw_udp_port := 2427
296 };
297
298 vc_MGCP := MGCP_Emulation_CT.create(id);
299 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
300}
301
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200302/* Enable or disable (current default) Osmux. When enabling, BSSMAP Reset
303 * contains extra IE (OsmuxSupport) and osmo-bsc will handle AssignReq with
304 * OsmuxCID IE.
305 */
306private function f_vty_allow_osmux(boolean allow) runs on test_CT {
307 f_vty_enter_cfg_msc(BSCVTY, 0);
308 if (allow) {
309 f_vty_transceive(BSCVTY, "osmux on");
310 } else {
311 f_vty_transceive(BSCVTY, "osmux off");
312 }
313 f_vty_transceive(BSCVTY, "exit");
314 f_vty_transceive(BSCVTY, "exit");
315 g_osmux_enabled := allow;
316}
317
Max2253c0b2018-11-06 19:28:05 +0100318function f_init_vty(charstring id := "foo") runs on test_CT {
Harald Welte94e0c342018-04-07 11:33:23 +0200319 if (BSCVTY.checkstate("Mapped")) {
320 /* skip initialization if already executed once */
321 return;
322 }
Harald Weltebc03c762018-02-12 18:09:38 +0100323 map(self:BSCVTY, system:BSCVTY);
324 f_vty_set_prompts(BSCVTY);
325 f_vty_transceive(BSCVTY, "enable");
326}
327
Harald Welte21b46bd2017-12-17 19:46:32 +0100328/* global initialization function
329 * \param nr_bts Number of BTSs we should start/bring up
330 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200331function f_init(integer nr_bts := NUM_BTS, boolean handler_mode := false, boolean allow_osmux := false) runs on test_CT {
Harald Welte28d943e2017-11-25 15:00:50 +0100332 var integer i;
Harald Welte28d943e2017-11-25 15:00:50 +0100333
Harald Welteae026692017-12-09 01:03:01 +0100334 if (g_initialized) {
335 return;
Harald Welte28d943e2017-11-25 15:00:50 +0100336 }
Harald Welteae026692017-12-09 01:03:01 +0100337 g_initialized := true;
338
Daniel Willmanne68f9272018-11-27 15:15:28 +0100339 T_guard.start;
340 activate(as_Tguard());
341
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200342 f_init_vty("VirtMSC");
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +0200343 if (mp_enable_osmux_test) {
344 f_vty_allow_osmux(allow_osmux);
345 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200346
Harald Welte6811d102019-04-14 22:23:14 +0200347 /* Call a function of our 'parent component' RAN_Adapter_CT to start the
Harald Welteae026692017-12-09 01:03:01 +0100348 * MSC-side BSSAP emulation */
Harald Welte67089ee2018-01-17 22:19:03 +0100349 if (handler_mode) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200350 var RanOps ranops := MSC_RanOps;
351 ranops.use_osmux := g_osmux_enabled;
352 f_ran_adapter_init(g_bssap, mp_bssap_cfg, "VirtMSC", ranops);
Harald Welte3ca0ce12019-04-23 17:18:48 +0200353 f_ran_adapter_start(g_bssap);
Harald Welte67089ee2018-01-17 22:19:03 +0100354 } else {
Harald Welte3ca0ce12019-04-23 17:18:48 +0200355 f_ran_adapter_init(g_bssap, mp_bssap_cfg, "VirtMSC", omit);
Harald Weltea4ca4462018-02-09 00:17:14 +0100356 connect(self:BSSAP, g_bssap.vc_SCCP:SCCP_SP_PORT);
Harald Welte3ca0ce12019-04-23 17:18:48 +0200357 f_ran_adapter_start(g_bssap);
Harald Weltea4ca4462018-02-09 00:17:14 +0100358 f_legacy_bssap_reset();
Harald Welte67089ee2018-01-17 22:19:03 +0100359 }
Harald Welted5833a82018-05-27 16:52:56 +0200360
Harald Welteffe55fc2018-01-17 22:39:54 +0100361 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +0100362
Daniel Willmann191e0d92018-01-17 12:44:35 +0100363 f_init_mgcp("VirtMSC");
364
Harald Welte89d42e82017-12-17 16:42:41 +0100365 for (i := 0; i < nr_bts; i := i+1) {
Harald Weltea5d2ab22017-12-09 14:21:42 +0100366 /* wait until osmo-bts-omldummy has respawned */
367 f_wait_oml(i, "degraded", 5.0);
368 /* start RSL connection */
Harald Welte624f9632017-12-16 19:26:04 +0100369 f_ipa_rsl_start(bts[i].rsl, mp_bsc_ip, mp_bsc_rsl_port, i, handler_mode);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100370 /* wait until BSC tells us "connected" */
371 f_wait_oml(i, "connected", 5.0);
Harald Welte696ddb62017-12-08 14:01:43 +0100372 }
373
Harald Welte28d943e2017-11-25 15:00:50 +0100374}
375
Maxd4e56962018-10-31 19:08:25 +0100376/* expect to receive a RSL message matching a specified template on a given BTS / stream */
Harald Welteae026692017-12-09 01:03:01 +0100377function f_exp_ipa_rx(integer bts_nr, template RSL_Message t_rx, float t_secs := 2.0, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
378runs on test_CT return RSL_Message {
379 var ASP_RSL_Unitdata rx_rsl_ud;
380 timer T := t_secs;
381
382 T.start;
383 alt {
384 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(sid, t_rx)) -> value rx_rsl_ud {
385 T.stop;
386 }
387 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +0100388 [] T.timeout {
389 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +0200390 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +0100391 }
Harald Welteae026692017-12-09 01:03:01 +0100392 }
393 return rx_rsl_ud.rsl;
394}
395
Harald Welte21b46bd2017-12-17 19:46:32 +0100396/* helper function to transmit RSL on a given BTS/stream */
Harald Welteae026692017-12-09 01:03:01 +0100397function f_ipa_tx(integer bts_nr, template RSL_Message t_tx, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
398runs on test_CT {
399 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(sid, t_tx));
400}
401
402
Harald Welte4003d112017-12-09 22:35:39 +0100403/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +0100404testcase TC_chan_act_noreply() runs on test_CT {
405 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +0100406 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +0100407
Harald Welte89d42e82017-12-17 16:42:41 +0100408 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +0100409
Harald Welteae026692017-12-09 01:03:01 +0100410 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 +0100411 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welteae026692017-12-09 01:03:01 +0100412 setverdict(pass);
Harald Welte28d943e2017-11-25 15:00:50 +0100413}
414
Harald Welte4003d112017-12-09 22:35:39 +0100415/* verify if the "chreq:total" counter increments as expected */
416testcase TC_chan_act_counter() runs on test_CT {
417 var BSSAP_N_UNITDATA_ind ud_ind;
418 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +0100419 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +0100420
Harald Welte89d42e82017-12-17 16:42:41 +0100421 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100422
423 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
424 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 +0100425 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welte4003d112017-12-09 22:35:39 +0100426 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total", chreq_total+1);
427
428 setverdict(pass);
429}
430
Harald Welteae026692017-12-09 01:03:01 +0100431/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
432testcase TC_chan_act_ack_noest() runs on test_CT {
433 var RSL_Message rx_rsl;
434
Harald Welte89d42e82017-12-17 16:42:41 +0100435 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100436
437 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100438 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100439
440 /* expect BSC to disable the channel again if there's no RLL EST IND */
441 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
442
443 setverdict(pass);
444}
445
446/* Test behavior if MSC never answers to CR */
447testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +0100448 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
449 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +0100450 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +0100451 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +0100452
Harald Welte89d42e82017-12-17 16:42:41 +0100453 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100454
455 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100456 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100457
458 var octetstring l3 := '00010203040506'O
459 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
460
461 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
462
463 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +0100464 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100465 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Harald Welteae026692017-12-09 01:03:01 +0100466 setverdict(pass);
467}
468
469/* Test behavior if MSC answers with CREF to CR */
470testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
471 var BSSAP_N_CONNECT_ind rx_c_ind;
472 var RSL_Message rx_rsl;
473
Harald Welte89d42e82017-12-17 16:42:41 +0100474 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100475
476 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100477 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100478
479 var octetstring l3 := '00010203040506'O
480 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
481
482 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
483 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
484
485 /* expect BSC to disable the channel */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100486 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Harald Welteae026692017-12-09 01:03:01 +0100487 setverdict(pass);
488}
489
Harald Welte618ef642017-12-14 14:58:20 +0100490/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
491testcase TC_chan_act_nack() runs on test_CT {
492 var RSL_Message rx_rsl;
493 var integer chact_nack;
494
Harald Welte89d42e82017-12-17 16:42:41 +0100495 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +0100496
497 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
498
499 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
500 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
501 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
502
503 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
504
505 /* wait for some time to hope the NACK arrives before the CTRL GET below */
506 f_sleep(0.5);
507
508 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
509
510 setverdict(pass);
511}
512
Harald Welte799c97b2017-12-14 17:50:30 +0100513/* Test for channel exhaustion due to RACH overload */
514testcase TC_chan_exhaustion() runs on test_CT {
515 var ASP_RSL_Unitdata rsl_ud;
516 var integer i;
517 var integer chreq_total, chreq_nochan;
518
Harald Welte89d42e82017-12-17 16:42:41 +0100519 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +0100520
521 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
522 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
523
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +0100524 /* GSM 04.08 Table 9.9a:
525 * RA = '33'O -> Establishment cause = 0011xxxx (MS dual rate capable and asks for "TCH/H or TCH/F").
526 * With current setup, expect 4xSDCCH + 4xTCH/F + 1xTCH/H to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +0200527 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS; i := i+1) {
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +0100528 var RslChannelNr chan_nr := f_chreq_act_ack('33'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +0100529 }
530
531 IPA_RSL[0].clear;
532
Harald Weltedd8cbf32018-01-28 12:07:52 +0100533 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200534 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +0100535
536 /* now expect additional channel activations to fail */
537 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
538
539 alt {
540 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
541 tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
542 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
543 }
544 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
545 var GsmRrMessage rr;
546 /* match on IMM ASS REJ */
547 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
548 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
549 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200550 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +0100551 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
552 chreq_nochan+1);
553 setverdict(pass);
554 } else {
555 repeat;
556 }
557 }
558 [] IPA_RSL[0].receive { repeat; }
559 }
560}
561
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +0700562/* Test channel deactivation due to silence from MS */
563testcase TC_chan_deact_silence() runs on test_CT {
564 var RslChannelNr chan_nr;
565
566 f_init(1);
567
568 /* Request for a dedicated channel */
569 chan_nr := f_chreq_act_ack('23'O);
570
571 /* Wait some time until the channel is released */
572 f_sleep(2.0);
573
574 /* Expect CHANnel RELease */
575 alt {
576 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
577 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
578 log("Received CHANnel RELease");
579 setverdict(pass);
580 }
581 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
582 tr_RSL_IMM_ASSIGN(?))) {
583 /* See OS#3709, OsmoBSC should not send Immediate
584 * Assignment Reject since a dedicated channel was
585 * already allocated, and Immediate Assignment was
586 * already sent. */
587 setverdict(fail, "Unexpected Immediate Assignment!");
588 }
589 [] IPA_RSL[0].receive {
590 setverdict(fail, "Unexpected RSL message!");
591 }
592 }
593}
594
Harald Weltecfe2c962017-12-15 12:09:32 +0100595/***********************************************************************
596 * Assignment Testing
597 ***********************************************************************/
598
Neels Hofmeyrda4a6952018-06-14 04:02:49 +0200599/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction,
600 * except for the inter-BSC handover, MT side) */
Harald Weltecfe2c962017-12-15 12:09:32 +0100601testcase TC_outbound_connect() runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +0100602 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +0100603
Harald Weltea4ca4462018-02-09 00:17:14 +0100604 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 +0100605 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
606 setverdict(pass);
607}
608
Harald Welte16a4adf2017-12-14 18:54:01 +0100609/* Test behavior if MSC answers with CREF to CR */
610testcase TC_assignment_cic_only() runs on test_CT {
611 var BSSAP_N_CONNECT_ind rx_c_ind;
612 var RSL_Message rx_rsl;
613 var DchanTuple dt;
614
Harald Welte89d42e82017-12-17 16:42:41 +0100615 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +0100616
617 dt := f_est_dchan('23'O, 23, '00000000'O);
Harald Welte17b27da2018-05-25 20:33:53 +0200618 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
619 /* send assignment without AoIP IEs */
620 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
621 } else {
622 /* Send assignmetn without CIC in IPA case */
623 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
624 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
625 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
626 }
Harald Welte16a4adf2017-12-14 18:54:01 +0100627 alt {
628 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
629 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
630 }
Harald Welte235ebf12017-12-15 14:18:16 +0100631 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +0100632 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
633 setverdict(pass);
634 }
635 [] BSSAP.receive { repeat; }
636 }
637}
638
Harald Welteed848512018-05-24 22:27:58 +0200639/* generate an assignment request for either AoIP or SCCPlite */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200640function f_gen_ass_req(boolean osmux_enabled := false) return PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200641 var PDU_BSSAP ass_cmd;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200642 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Harald Welteed848512018-05-24 22:27:58 +0200643 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
644 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
645 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200646 if (osmux_enabled) {
647 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla, osmux_cid));
648 } else {
649 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
650 }
Harald Welteed848512018-05-24 22:27:58 +0200651 } else {
652 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200653 if (osmux_enabled) {
654 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit, osmux_cid));
655 } else {
656 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
657 }
Harald Welteed848512018-05-24 22:27:58 +0200658 }
659 return ass_cmd;
660}
661
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +0100662function f_gen_handover_req() return PDU_BSSAP {
663 var PDU_BSSAP ho_req;
664 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
665 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
666 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
667 ho_req := valueof(ts_BSSMAP_HandoverRequest(omit, tla));
668 } else {
669 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
670 ho_req := valueof(ts_BSSMAP_HandoverRequest(cic, omit));
671 }
672 return ho_req;
673}
674
Harald Welteed848512018-05-24 22:27:58 +0200675/* generate an assignment complete template for either AoIP or SCCPlite */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200676function f_gen_exp_compl(boolean expect_osmux := false) return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200677 var template PDU_BSSAP exp_compl;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200678 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Harald Welteed848512018-05-24 22:27:58 +0200679 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200680 if (expect_osmux) {
681 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, osmux_cid);
682 } else {
683 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, omit);
684 }
Harald Welteed848512018-05-24 22:27:58 +0200685 } else {
686 /* CIC is optional "*" as the MSC allocated it */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200687 if (expect_osmux) {
688 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit, osmux_cid);
689 } else {
690 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
691 }
Harald Welteed848512018-05-24 22:27:58 +0200692 }
693 return exp_compl;
694}
695
Harald Welte235ebf12017-12-15 14:18:16 +0100696/* Run everything required up to sending a caller-specified assignment command and expect response */
697function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
698runs on test_CT {
699 var BSSAP_N_CONNECT_ind rx_c_ind;
700 var RSL_Message rx_rsl;
701 var DchanTuple dt;
702
Harald Welte89d42e82017-12-17 16:42:41 +0100703 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +0100704
705 dt := f_est_dchan('23'O, 23, '00000000'O);
706 /* send assignment without AoIP IEs */
707 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
708 alt {
709 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
710 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
711 setverdict(pass);
712 } else {
713 setverdict(fail, fail_text);
714 }
715 }
716 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
717 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
718 setverdict(pass);
719 } else {
720 setverdict(fail, fail_text);
721 }
722 }
723 [] BSSAP.receive { repeat; }
724 }
725}
726testcase TC_assignment_csd() runs on test_CT {
727 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200728 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100729 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
730 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
731 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
732}
733
734testcase TC_assignment_ctm() runs on test_CT {
735 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200736 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100737 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
738 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
739 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
740}
741
Harald Welte4003d112017-12-09 22:35:39 +0100742type record DchanTuple {
743 integer sccp_conn_id,
744 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +0100745}
746
Harald Welted6939652017-12-13 21:02:46 +0100747/* Send CHAN RQD and wait for allocation; acknowledge it */
748private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
749runs on test_CT return RslChannelNr {
750 var RSL_Message rx_rsl;
751 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
752 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
753 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
754 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
Daniel Willmannf4ac4ce2018-08-02 14:06:30 +0200755 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Harald Welted6939652017-12-13 21:02:46 +0100756 return chan_nr;
757}
758
Harald Welte4003d112017-12-09 22:35:39 +0100759/* helper function to establish a dedicated channel via BTS and MSC */
760function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
761runs on test_CT return DchanTuple {
762 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +0100763 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100764
Harald Welte4003d112017-12-09 22:35:39 +0100765 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100766 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +0100767
768 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
769
770 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
771 dt.sccp_conn_id := rx_c_ind.connectionId;
772 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
773
774 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100775}
776
Harald Welte641fcbe2018-06-14 10:58:35 +0200777/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
778private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
779 var RSL_Message rx_rsl;
780 /* expect BSC to disable the channel */
781 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
782 /* respond with CHAN REL ACK */
783 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
784
785 /* expect Clear Complete from BSC */
786 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
787
788 /* MSC disconnects as instructed. */
789 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
790}
791
Harald Welte4003d112017-12-09 22:35:39 +0100792/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
793testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100794 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100795 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +0100796
Harald Welte89d42e82017-12-17 16:42:41 +0100797 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +0100798
Harald Welte4003d112017-12-09 22:35:39 +0100799 dt := f_est_dchan('23'O, 23, '00010203040506'O);
800
801 /* simulate RLL REL IND */
802 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
803
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100804 /* expect Clear Request on MSC side */
805 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
806
807 /* Instruct BSC to clear channel */
808 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
809 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
810
Harald Welte4003d112017-12-09 22:35:39 +0100811 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200812 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100813
814 /* wait for SCCP emulation to do its job */
815 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +0100816
817 setverdict(pass);
818}
819
820/* Test behavior of channel release after CONN FAIL IND from BTS */
821testcase TC_chan_rel_conn_fail() runs on test_CT {
822 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100823 var DchanTuple dt;
824
Harald Welte89d42e82017-12-17 16:42:41 +0100825 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100826
827 dt := f_est_dchan('23'O, 23, '00010203040506'O);
828
829 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +0100830 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 +0100831 /* TODO: different cause values? */
832
Harald Welte4003d112017-12-09 22:35:39 +0100833 /* expect Clear Request from BSC */
834 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
835
836 /* Instruct BSC to clear channel */
837 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
838 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
839
Harald Welte6ff76ea2018-01-28 13:08:01 +0100840 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200841 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +0100842
843 /* wait for SCCP emulation to do its job */
844 f_sleep(1.0);
845
846 setverdict(pass);
847}
848
Harald Welte99f3ca02018-06-14 13:40:29 +0200849/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
850/* See also https://www.osmocom.org/issues/3182 */
851testcase TC_early_conn_fail() runs on test_CT {
852 var RSL_Message rx_rsl;
853 var DchanTuple dt;
854
855 f_init(1);
856
857 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
858 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_octstring(1), 23);
859
860 /* BTS->BSC: simulate CONN FAIL IND */
861 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
862
863 /* BTS->BSC: Expect RF channel release from BSC on Abis */
864 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
865
866 /* BTS<-BSC: respond with CHAN REL ACK */
867 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
868
869 setverdict(pass);
870}
871
872/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
873/* See also https://www.osmocom.org/issues/3182 */
874testcase TC_late_conn_fail() runs on test_CT {
875 var RSL_Message rx_rsl;
876 var DchanTuple dt;
877
878 f_init(1);
879
880 dt := f_est_dchan('23'O, 23, '00010203040506'O);
881
882 /* BSC<-MSC: Instruct BSC to clear connection */
883 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
884
885 /* BTS->BSC: expect BSC to deactivate SACCH */
886 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
887
888 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
889 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
890
891 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
892 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
893 /* BTS->BSC: respond with CHAN REL ACK */
894 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
895
896 /* BSC->MSC: expect Clear Complete from BSC */
897 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
898
899 /* BSC<-MSC: MSC disconnects as requested. */
900 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
901
902 setverdict(pass);
903}
904
Neels Hofmeyrf44ccd12018-11-05 19:15:23 +0100905function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr,
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100906 boolean expect_deact_sacch := true,
907 boolean expect_rr_chan_rel := true,
908 boolean expect_rll_rel_req := true,
Harald Welte99787102019-02-04 10:41:36 +0100909 boolean handle_rll_rel := true,
910 boolean is_csfb := false
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100911 ) runs on test_CT {
Harald Welte91d54a52018-01-28 15:35:07 +0100912
913 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100914 var boolean got_deact_sacch := false;
915 var boolean got_rr_chan_rel := false;
916 var boolean got_rll_rel_req := false;
917 log("f_expect_chan_rel() expecting: expect_deact_sacch=", expect_deact_sacch, " expect_rr_chan_rel=", expect_rr_chan_rel,
918 " expect_rll_rel_req=", expect_rll_rel_req);
Harald Welte91d54a52018-01-28 15:35:07 +0100919 alt {
Harald Welte91d54a52018-01-28 15:35:07 +0100920 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
921 tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100922 got_deact_sacch := true;
Harald Welte91d54a52018-01-28 15:35:07 +0100923 repeat;
924 }
Harald Welte99787102019-02-04 10:41:36 +0100925 [is_csfb] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_DATA_REQ(rsl_chan_nr, ?, decmatch tr_RRM_RR_RELEASE_CSFB))) {
926 got_rr_chan_rel := true;
927 repeat;
928 }
929 [not is_csfb] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_DATA_REQ(rsl_chan_nr, ?, decmatch tr_RRM_RR_RELEASE))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100930 got_rr_chan_rel := true;
Neels Hofmeyr211169d2018-11-07 00:37:29 +0100931 repeat;
932 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100933 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
Harald Welte91d54a52018-01-28 15:35:07 +0100934 tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100935 got_rll_rel_req := true;
Harald Welte91d54a52018-01-28 15:35:07 +0100936 /* FIXME: Why are we getting this for LinkID SACCH? */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100937 if (handle_rll_rel) {
938 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
939 }
Harald Welte91d54a52018-01-28 15:35:07 +0100940 repeat;
941 }
Harald Welte91d54a52018-01-28 15:35:07 +0100942 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
943 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
944 /* respond with CHAN REL ACK */
945 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
946 }
947 /* ignore any user data */
948 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_MsgTypeR(?))) {
949 repeat;
950 }
951 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100952
953 log("f_expect_chan_rel() summary: got_deact_sacch=", got_deact_sacch, " got_rr_chan_rel=", got_rr_chan_rel,
954 " got_rll_rel_req=", got_rll_rel_req);
955
956 if (expect_deact_sacch != got_deact_sacch) {
957 setverdict(fail, "f_expect_chan_rel(): expect_deact_sacch=", expect_deact_sacch, " got_deact_sacch=", got_deact_sacch);
958 }
959 if (expect_rr_chan_rel != got_rr_chan_rel) {
960 setverdict(fail, "f_expect_chan_rel(): expect_rr_chan_rel=", expect_rr_chan_rel, " got_rr_chan_rel=", got_rr_chan_rel);
961 }
962 if (expect_rll_rel_req != got_rll_rel_req) {
963 setverdict(fail, "f_expect_chan_rel(): expect_rll_rel_req=", expect_rll_rel_req, " got_rll_rel_req=", got_rll_rel_req);
964 }
Harald Welte91d54a52018-01-28 15:35:07 +0100965}
966
Harald Welte4003d112017-12-09 22:35:39 +0100967/* Test behavior of channel release after hard Clear Command from MSC */
968testcase TC_chan_rel_hard_clear() runs on test_CT {
969 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100970 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +0100971
Harald Welte89d42e82017-12-17 16:42:41 +0100972 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100973
974 dt := f_est_dchan('23'O, 23, '00010203040506'O);
975
976 /* Instruct BSC to clear channel */
977 var BssmapCause cause := 0;
978 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
979
980 /* expect Clear Complete from BSC on A */
981 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
982 /* release the SCCP connection */
983 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
984 }
985
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100986 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte4003d112017-12-09 22:35:39 +0100987 setverdict(pass);
988}
989
Harald Welte99787102019-02-04 10:41:36 +0100990/* Test behavior of channel release after Clear Command with CSFB indicator from MSC */
991testcase TC_chan_rel_hard_clear_csfb() runs on test_CT {
992 var BSSAP_N_DATA_ind rx_di;
993 var DchanTuple dt;
994
995 f_init(1);
996
997 dt := f_est_dchan('23'O, 23, '00010203040506'O);
998
999 /* Instruct BSC to clear channel */
1000 var BssmapCause cause := 0;
1001 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
1002
1003 /* expect Clear Complete from BSC on A */
1004 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
1005 /* release the SCCP connection */
1006 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1007 }
1008
1009 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, is_csfb := true);
1010 setverdict(pass);
1011}
1012
Harald Welted8c36cd2017-12-09 23:05:31 +01001013/* Test behavior of channel release after hard RLSD from MSC */
1014testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +01001015 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +01001016
Harald Welte89d42e82017-12-17 16:42:41 +01001017 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +01001018
1019 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1020
1021 /* release the SCCP connection */
1022 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1023
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001024 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welted8c36cd2017-12-09 23:05:31 +01001025 setverdict(pass);
1026}
1027
Harald Welte550daf92018-06-11 19:22:13 +02001028/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
1029testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
1030 var DchanTuple dt;
1031
1032 f_init(1);
1033
1034 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1035
1036 /* release the SCCP connection */
1037 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1038
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001039 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte550daf92018-06-11 19:22:13 +02001040 setverdict(pass);
1041}
1042
Harald Welte85804d42017-12-10 14:11:58 +01001043/* Test behavior of channel release after BSSMAP RESET from MSC */
1044testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +01001045 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +01001046
Harald Welte89d42e82017-12-17 16:42:41 +01001047 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +01001048
1049 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1050
1051 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
1052 IPA_RSL[0].clear;
1053
1054 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001055 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, ts_BSSMAP_Reset(0, g_osmux_enabled)));
Harald Welte85804d42017-12-10 14:11:58 +01001056 interleave {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001057 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap.sccp_addr_own, g_bssap.sccp_addr_peer, tr_BSSMAP_ResetAck(g_osmux_enabled))) { }
Harald Welte85804d42017-12-10 14:11:58 +01001058 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
1059 }
1060
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001061 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte85804d42017-12-10 14:11:58 +01001062 setverdict(pass);
1063}
1064
Harald Welte5cd20ed2017-12-13 21:03:20 +01001065/* Test behavior if RSL EST IND for non-active channel */
1066testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
1067 timer T := 2.0;
1068
Harald Welte89d42e82017-12-17 16:42:41 +01001069 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001070
1071 var octetstring l3 := '00010203040506'O;
1072 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
1073 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1074
1075 T.start;
1076 alt {
1077 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1078 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
1079 }
1080 [] BSSAP.receive {}
1081 [] IPA_RSL[0].receive {}
1082 [] T.timeout {}
1083 }
1084
1085 setverdict(pass);
1086}
1087
1088/* Test behavior if RSL EST IND for invalid SAPI */
1089testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
1090 var RslChannelNr chan_nr;
1091
Harald Welte89d42e82017-12-17 16:42:41 +01001092 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001093
1094 chan_nr := f_chreq_act_ack()
1095
1096 var octetstring l3 := '00010203040506'O;
1097 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
1098
1099 timer T := 2.0;
1100 T.start;
1101 alt {
1102 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1103 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
1104 }
1105 [] BSSAP.receive { repeat; }
1106 [] IPA_RSL[0].receive { repeat; }
1107 [] T.timeout {}
1108 }
1109
1110 setverdict(pass);
1111}
1112
1113/* Test behavior if RSL EST IND for invalid SAPI */
1114testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
1115 timer T := 2.0;
1116
Harald Welte89d42e82017-12-17 16:42:41 +01001117 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001118
1119 var RslChannelNr chan_nr := f_chreq_act_ack();
1120
1121 var octetstring l3 := '00010203040506'O;
1122 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
1123
1124 T.start;
1125 alt {
1126 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1127 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
1128 }
1129 [] BSSAP.receive { repeat; }
1130 [] IPA_RSL[0].receive { repeat; }
1131 [] T.timeout {}
1132 }
1133
1134 setverdict(pass);
1135}
1136
1137/* Test behavior if RSL EST IND for invalid SACCH */
1138testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
1139 timer T := 2.0;
1140
Harald Welte89d42e82017-12-17 16:42:41 +01001141 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001142
1143 var RslChannelNr chan_nr := f_chreq_act_ack();
1144
1145 var octetstring l3 := '00010203040506'O;
1146 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
1147
1148 T.start;
1149 alt {
1150 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1151 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
1152 }
1153 [] BSSAP.receive { repeat; }
1154 [] IPA_RSL[0].receive { repeat; }
1155 [] T.timeout {}
1156 }
1157
1158 setverdict(pass);
1159}
1160
1161
1162
Harald Welte4003d112017-12-09 22:35:39 +01001163
1164testcase TC_ctrl_msc_connection_status() runs on test_CT {
1165 var charstring ctrl_resp;
1166
Harald Welte89d42e82017-12-17 16:42:41 +01001167 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001168
1169 /* See https://osmocom.org/issues/2729 */
1170 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
1171 setverdict(pass);
1172}
1173
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001174testcase TC_ctrl_msc0_connection_status() runs on test_CT {
1175 var charstring ctrl_resp;
1176
1177 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001178
1179 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
1180 setverdict(pass);
1181}
1182
Harald Welte4003d112017-12-09 22:35:39 +01001183testcase TC_ctrl() runs on test_CT {
1184 var charstring ctrl_resp;
1185
Harald Welte89d42e82017-12-17 16:42:41 +01001186 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001187
1188 /* all below values must match the osmo-bsc.cfg config file used */
1189
Harald Welte6a129692018-03-17 17:30:14 +01001190 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
1191 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Harald Welte44bdaa52017-12-17 17:01:47 +01001192 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "3");
Harald Welte4003d112017-12-09 22:35:39 +01001193
1194 var integer bts_nr := 0;
1195 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
1196 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
1197 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
1198 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
1199 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
1200 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
1201 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
1202
1203 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
1204 f_sleep(2.0);
1205 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
1206 setverdict(fail, "oml-uptime not incrementing as expected");
1207 }
1208 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
1209
1210 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
1211
1212 setverdict(pass);
Harald Welte96c94412017-12-09 03:12:45 +01001213}
1214
Harald Welte6f521d82017-12-11 19:52:02 +01001215function f_bssap_tx_ud(template PDU_BSSAP bssap) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +01001216 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, bssap));
Harald Welte6f521d82017-12-11 19:52:02 +01001217}
1218
1219
1220/***********************************************************************
1221 * Paging Testing
1222 ***********************************************************************/
1223
1224type record Cell_Identity {
1225 GsmMcc mcc,
1226 GsmMnc mnc,
1227 GsmLac lac,
1228 GsmCellId ci
1229};
Harald Welte24135bd2018-03-17 19:27:53 +01001230private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01001231private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01001232
Harald Welte5d1a2202017-12-13 19:51:29 +01001233type set of integer BtsIdList;
1234
1235private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
1236 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
1237 if (bts_id == bts_ids[j]) {
1238 return true;
1239 }
1240 }
1241 return false;
1242}
Harald Welte6f521d82017-12-11 19:52:02 +01001243
1244/* core paging test helper function; used by most paging test cases */
1245private function f_pageing_helper(hexstring imsi,
1246 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01001247 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01001248 template RSL_ChanNeeded rsl_chneed := omit,
1249 template OCT4 tmsi := omit) runs on test_CT
1250{
1251 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
1252 var MobileIdentity mi;
1253 var template octetstring id_enc; /* FIXME */
1254 var RSL_Message rx_rsl;
1255 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01001256 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01001257
1258 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01001259
1260 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01001261 for (i := 0; i < NUM_BTS; i := i + 1) {
1262 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01001263 }
Harald Welte6f521d82017-12-11 19:52:02 +01001264
1265 if (isvalue(rsl_chneed)) {
1266 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
1267 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
1268 } else {
1269 bssmap_chneed := omit;
1270 }
1271
1272 f_bssap_tx_ud(ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed));
1273
1274/* FIXME: Disabled due to bugs in both GSM_RR_Types and MobileL3_CommonIE_Types IMSI encoder
1275 if (isvalue(tmsi)) {
1276 mi := valueof(t_Osmo_MI_TMSI(oct2int(valueof(tmsi))));
1277 } else {
1278 mi := valueof(ts_Osmo_MI_IMSI(imsi));
1279 }
1280 id_enc := enc_MobileIdentity(mi);
1281*/
1282 id_enc := ?;
Harald Welte5d1a2202017-12-13 19:51:29 +01001283 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
1284 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(id_enc));
1285 /* check channel type, paging group */
1286 if (rx_rsl.ies[1].body.paging_group != paging_group) {
1287 setverdict(fail, "Paging for wrong paging group");
1288 }
1289 if (ispresent(rsl_chneed) and
1290 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
1291 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
1292 }
Harald Welte6f521d82017-12-11 19:52:02 +01001293 }
Harald Welte2fccd982018-01-31 15:48:19 +01001294 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01001295 /* do a quick check on all not-included BTSs if they received paging */
1296 for (i := 0; i < NUM_BTS; i := i + 1) {
1297 timer T := 0.1;
1298 if (f_bts_in_list(i, bts_ids)) {
1299 continue;
1300 }
1301 T.start;
1302 alt {
1303 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(id_enc))) {
1304 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
1305 }
1306 [] IPA_RSL[i].receive { repeat; }
1307 [] T.timeout { }
1308 }
Harald Welte6f521d82017-12-11 19:52:02 +01001309 }
1310
1311 setverdict(pass);
1312}
1313
Harald Welte5d1a2202017-12-13 19:51:29 +01001314const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01001315const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01001316const BtsIdList c_BtsId_LAC1 := { 0, 1 };
1317const BtsIdList c_BtsId_LAC2 := { 2 };
1318
Harald Welte6f521d82017-12-11 19:52:02 +01001319/* PAGING by IMSI + TMSI */
1320testcase TC_paging_imsi_nochan() runs on test_CT {
1321 var BSSMAP_FIELD_CellIdentificationList cid_list;
1322 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01001323 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001324 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001325}
1326
1327/* PAGING by IMSI + TMSI */
1328testcase TC_paging_tmsi_nochan() runs on test_CT {
1329 var BSSMAP_FIELD_CellIdentificationList cid_list;
1330 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001331 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001332 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001333}
1334
1335/* Paging with different "channel needed' values */
1336testcase TC_paging_tmsi_any() runs on test_CT {
1337 var BSSMAP_FIELD_CellIdentificationList cid_list;
1338 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001339 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001340 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001341}
1342testcase TC_paging_tmsi_sdcch() runs on test_CT {
1343 var BSSMAP_FIELD_CellIdentificationList cid_list;
1344 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001345 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001346 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001347}
1348testcase TC_paging_tmsi_tch_f() runs on test_CT {
1349 var BSSMAP_FIELD_CellIdentificationList cid_list;
1350 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001351 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001352 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001353}
1354testcase TC_paging_tmsi_tch_hf() runs on test_CT {
1355 var BSSMAP_FIELD_CellIdentificationList cid_list;
1356 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001357 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001358 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001359}
1360
1361/* Paging by CGI */
1362testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
1363 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1364 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001365 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001366 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001367}
1368
1369/* Paging by LAC+CI */
1370testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
1371 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1372 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001373 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001374 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001375}
1376
1377/* Paging by CI */
1378testcase TC_paging_imsi_nochan_ci() runs on test_CT {
1379 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1380 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001381 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001382 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001383}
1384
1385/* Paging by LAI */
1386testcase TC_paging_imsi_nochan_lai() runs on test_CT {
1387 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1388 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001389 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001390 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001391}
1392
1393/* Paging by LAC */
1394testcase TC_paging_imsi_nochan_lac() runs on test_CT {
1395 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1396 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001397 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001398 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001399}
1400
1401/* Paging by "all in BSS" */
1402testcase TC_paging_imsi_nochan_all() runs on test_CT {
1403 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1404 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01001405 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001406 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001407}
1408
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001409/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001410testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
1411 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1412 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 +01001413 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001414 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001415}
Harald Welte6f521d82017-12-11 19:52:02 +01001416
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001417/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001418testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
1419 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1420 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001421 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001422 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001423}
1424
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001425/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001426testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
1427 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1428 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001429 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001430 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001431}
1432
Harald Welte6f521d82017-12-11 19:52:02 +01001433/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01001434testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
1435 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1436 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
1437 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001438 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001439}
1440
1441/* Paging on empty list: Verify none of them page */
1442testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
1443 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1444 cid_list := { cIl_LAC := { } };
1445 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001446 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001447}
1448
Stefan Sperling049a86e2018-03-20 15:51:00 +01001449/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
1450testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
1451 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1452 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
1453 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
1454 f_shutdown_helper();
1455}
1456
Harald Welte6f521d82017-12-11 19:52:02 +01001457/* Verify paging retransmission interval + count */
1458/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01001459/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01001460
Harald Weltee65d40e2017-12-13 00:09:06 +01001461/* Verify PCH load */
1462testcase TC_paging_imsi_load() runs on test_CT {
1463 var BSSMAP_FIELD_CellIdentificationList cid_list;
1464 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01001465 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01001466 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001467 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01001468
1469 /* tell BSC there is no paging space anymore */
1470 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01001471 f_sleep(0.2);
1472 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01001473
1474 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
1475 * there would be 8 retransmissions during 4 seconds */
1476 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01001477 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01001478 alt {
1479 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1480 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02001481 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01001482 }
Harald Welte2caa1062018-03-17 18:19:05 +01001483 [] T_retrans.timeout {
1484 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
1485 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
1486 T_retrans.start;
1487 repeat;
1488 }
Harald Weltee65d40e2017-12-13 00:09:06 +01001489 [] T.timeout {
1490 setverdict(pass);
1491 }
1492 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001493
1494 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01001495}
1496
Harald Welte235ebf12017-12-15 14:18:16 +01001497/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01001498testcase TC_paging_counter() runs on test_CT {
1499 var BSSMAP_FIELD_CellIdentificationList cid_list;
1500 timer T := 4.0;
1501 var integer i;
1502 var integer paging_attempted_bsc;
1503 var integer paging_attempted_bts[NUM_BTS];
1504 var integer paging_expired_bts[NUM_BTS];
1505 cid_list := valueof(ts_BSSMAP_CIL_noCell);
1506
1507 f_init();
1508
1509 /* read counters before paging */
1510 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
1511 for (i := 0; i < NUM_BTS; i := i+1) {
1512 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
1513 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
1514 }
1515
1516 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
1517
1518 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
1519 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
1520 for (i := 0; i < NUM_BTS; i := i+1) {
1521 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
1522 paging_attempted_bts[i]+1);
1523 }
1524
1525 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
1526 f_sleep(12.0);
1527 for (i := 0; i < NUM_BTS; i := i+1) {
1528 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
1529 paging_expired_bts[i]+1);
1530 }
Harald Welte1ff69992017-12-14 12:31:17 +01001531
Philipp Maier282ca4b2018-02-27 17:17:00 +01001532 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01001533}
1534
1535
Harald Welte10985002017-12-12 09:29:15 +01001536/* Verify paging stops after A-RESET */
1537testcase TC_paging_imsi_a_reset() runs on test_CT {
1538 var BSSMAP_FIELD_CellIdentificationList cid_list;
1539 timer T := 3.0;
1540 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001541 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01001542
1543 /* Perform a BSSMAP Reset and wait for ACK */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001544 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, ts_BSSMAP_Reset(0, g_osmux_enabled)));
Harald Welte10985002017-12-12 09:29:15 +01001545 alt {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001546 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap.sccp_addr_own, g_bssap.sccp_addr_peer, tr_BSSMAP_ResetAck(g_osmux_enabled))) { }
Harald Welte10985002017-12-12 09:29:15 +01001547 [] BSSAP.receive { repeat; }
1548 }
1549
Daniel Willmanncbef3982018-07-30 09:22:40 +02001550 /* Wait to avoid a possible race condition if a paging message is
1551 * received right before the reset ACK. */
1552 f_sleep(0.2);
1553
Harald Welte10985002017-12-12 09:29:15 +01001554 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01001555 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
1556 IPA_RSL[i].clear;
1557 }
Harald Welte10985002017-12-12 09:29:15 +01001558
1559 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
1560 T.start;
1561 alt {
1562 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1563 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001564 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01001565 }
Harald Welte5d1a2202017-12-13 19:51:29 +01001566 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1567 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001568 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001569 }
1570 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1571 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001572 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001573 }
Harald Welte10985002017-12-12 09:29:15 +01001574 [] T.timeout {
1575 setverdict(pass);
1576 }
1577 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001578
1579 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01001580}
Harald Welteae026692017-12-09 01:03:01 +01001581
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001582/* Verify how we handle unsolicited Paging Response, for instance because we
1583 * receive a Paging Response after T3113 expired (and subscriber information was
1584 * dropped). See OS#3680.
1585 */
1586testcase TC_paging_resp_unsol() runs on test_CT {
1587
1588 f_init(1);
1589
1590 var BSSAP_N_CONNECT_ind rx_c_ind;
1591 var DchanTuple dt;
1592 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
1593
1594 /* Send CHAN RQD and wait for allocation; acknowledge it */
1595 dt.rsl_chan_nr := f_chreq_act_ack();
1596
1597 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
1598 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
1599
1600 /* expect BSC to disable the channel */
Pau Espin Pedrol5ee6f6c2018-12-07 12:07:43 +01001601 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001602 setverdict(pass);
1603
1604}
1605
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001606/* Test RSL link drop causes counter increment */
1607testcase TC_rsl_drop_counter() runs on test_CT {
1608 var integer rsl_fail;
1609
Harald Welte89d42e82017-12-17 16:42:41 +01001610 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001611
1612 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
1613
1614 bts[0].rsl.vc_IPA.stop;
1615
1616 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
1617
1618 setverdict(pass);
1619}
1620
1621/* TODO: Test OML link drop causes counter increment */
1622
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001623/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
1624function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
1625 timer T := 10.0;
1626
1627 bts[0].rsl.id := "IPA-0-RSL";
1628 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
1629 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
1630 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
1631 bts[0].rsl.ccm_pars.unit_id := "0/0/0"; /* value which is unknown at BTS */
1632
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001633 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
1634
1635 f_init_mgcp("VirtMSC");
1636
1637 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
1638 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
1639 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
1640 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
1641
1642 /* wait for IPA OML link to connect and then disconnect */
1643 T.start;
1644 alt {
1645 [] IPA_RSL[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) {
1646 T.stop;
1647 return true;
1648 }
1649 [] IPA_RSL[0].receive { repeat }
1650 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02001651 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001652 }
1653 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001654 return false;
1655}
1656
1657/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1658testcase TC_rsl_unknown_unit_id() runs on test_CT {
1659 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
1660 setverdict(pass);
1661 } else {
1662 setverdict(fail, "Timeout RSL waiting for connection to close");
1663 }
1664}
1665
1666
1667/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1668testcase TC_oml_unknown_unit_id() runs on test_CT {
1669 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
1670 setverdict(pass);
1671 } else {
1672 setverdict(fail, "Timeout OML waiting for connection to close");
1673 }
1674}
1675
1676
Harald Weltec1a2fff2017-12-17 11:06:19 +01001677/***********************************************************************
Harald Welte6811d102019-04-14 22:23:14 +02001678 * "New world" test cases using RSL_Emulation + RAN_Emulation
Harald Weltec1a2fff2017-12-17 11:06:19 +01001679 ***********************************************************************/
1680
Harald Welte6811d102019-04-14 22:23:14 +02001681import from RAN_Emulation all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01001682import from RSL_Emulation all;
1683import from MSC_ConnectionHandler all;
1684
1685type function void_fn(charstring id) runs on MSC_ConnHdlr;
1686
Harald Welte336820c2018-05-31 20:34:52 +02001687/* helper function to create and connect a MSC_ConnHdlr component */
Harald Welteff579f92018-05-31 22:19:39 +02001688private function f_connect_handler(inout MSC_ConnHdlr vc_conn) runs on test_CT {
Harald Welte6811d102019-04-14 22:23:14 +02001689 connect(vc_conn:RAN, g_bssap.vc_RAN:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001690 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001691 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01001692 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01001693 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01001694 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
1695 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
1696 }
Harald Welte6811d102019-04-14 22:23:14 +02001697 connect(vc_conn:BSSAP, g_bssap.vc_RAN:CLIENT);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001698 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Harald Welte336820c2018-05-31 20:34:52 +02001699}
1700
1701function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
1702runs on test_CT return MSC_ConnHdlr {
1703 var charstring id := testcasename();
1704 var MSC_ConnHdlr vc_conn;
1705 vc_conn := MSC_ConnHdlr.create(id);
1706 f_connect_handler(vc_conn);
Harald Weltea0630032018-03-20 21:09:55 +01001707 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001708 return vc_conn;
1709}
1710
Harald Weltea0630032018-03-20 21:09:55 +01001711/* first function inside ConnHdlr component; sets g_pars + starts function */
1712private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
1713runs on MSC_ConnHdlr {
1714 if (isvalue(pars)) {
1715 g_pars := valueof(pars);
1716 }
1717 fn.apply(id);
1718}
1719
Harald Welte3c86ea02018-05-10 22:28:05 +02001720/* Establish signalling channel (non-assignment case) followed by cipher mode */
1721private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001722 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1723 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02001724 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02001725 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
1726 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
1727 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
1728 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02001729
Philipp Maier23000732018-05-18 11:25:37 +02001730 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02001731}
1732testcase TC_ciph_mode_a5_0() runs on test_CT {
1733 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001734 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001735 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
1736
1737 f_init(1, true);
1738 f_sleep(1.0);
1739 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1740 vc_conn.done;
1741}
1742testcase TC_ciph_mode_a5_1() runs on test_CT {
1743 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001744 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001745 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
1746
1747 f_init(1, true);
1748 f_sleep(1.0);
1749 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1750 vc_conn.done;
1751}
1752testcase TC_ciph_mode_a5_3() runs on test_CT {
1753 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001754 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001755 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
1756
1757 f_init(1, true);
1758 f_sleep(1.0);
1759 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1760 vc_conn.done;
1761}
1762
1763
1764/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02001765private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001766 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1767 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01001768
Harald Welte552620d2017-12-16 23:21:36 +01001769 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1770 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01001771
Harald Weltea0630032018-03-20 21:09:55 +01001772 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01001773}
Harald Welte552620d2017-12-16 23:21:36 +01001774testcase TC_assignment_fr_a5_0() runs on test_CT {
1775 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001776 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001777 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01001778
Harald Welte89d42e82017-12-17 16:42:41 +01001779 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001780 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001781 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01001782 vc_conn.done;
1783}
Harald Welte552620d2017-12-16 23:21:36 +01001784testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01001785 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001786 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001787 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001788
Harald Welte89d42e82017-12-17 16:42:41 +01001789 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001790 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001791 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
1792 vc_conn.done;
1793}
1794testcase TC_assignment_fr_a5_3() runs on test_CT {
1795 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001796 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001797 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001798
Harald Welte651fcdc2018-05-10 20:23:16 +02001799 f_init(1, true);
1800 f_sleep(1.0);
1801 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001802 vc_conn.done;
1803}
1804
Harald Welte552620d2017-12-16 23:21:36 +01001805/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
1806private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001807 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01001808 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001809 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001810 const OCT8 kc := '0001020304050607'O;
1811
1812 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001813 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
1814
Harald Weltea0630032018-03-20 21:09:55 +01001815 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01001816}
Harald Welte552620d2017-12-16 23:21:36 +01001817testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
1818 var MSC_ConnHdlr vc_conn;
1819
Harald Welte89d42e82017-12-17 16:42:41 +01001820 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001821 f_sleep(1.0);
1822
Harald Welte8863fa12018-05-10 20:15:27 +02001823 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01001824 vc_conn.done;
1825}
1826
Harald Welte552620d2017-12-16 23:21:36 +01001827private function f_tc_assignment_fr_a5_4(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001828 g_pars := f_gen_test_hdlr_pars();
Harald Welteed848512018-05-24 22:27:58 +02001829 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1830 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001831 const OCT8 kc := '0001020304050607'O;
1832 const OCT16 kc128 := kc & kc;
1833
1834 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1835 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Weltea0630032018-03-20 21:09:55 +01001836 f_establish_fully(ass_cmd, exp_compl);
Harald Welte38b2a102017-12-23 02:42:58 +01001837 f_cipher_mode('10'O, kc, kc128, true);
Harald Welte552620d2017-12-16 23:21:36 +01001838 /* TODO: expect GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED cause value */
Harald Welte552620d2017-12-16 23:21:36 +01001839}
Harald Welte552620d2017-12-16 23:21:36 +01001840testcase TC_assignment_fr_a5_4() runs on test_CT {
1841 var MSC_ConnHdlr vc_conn;
1842
Harald Welte89d42e82017-12-17 16:42:41 +01001843 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001844 f_sleep(1.0);
1845
Harald Welte8863fa12018-05-10 20:15:27 +02001846 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_4));
Harald Welte552620d2017-12-16 23:21:36 +01001847 vc_conn.done;
1848}
1849
1850
Harald Welte4532e0a2017-12-23 02:05:44 +01001851private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001852 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01001853 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02001854 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01001855 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Harald Weltea0630032018-03-20 21:09:55 +01001856 f_establish_fully(ass_cmd, exp_compl);
Harald Welte4532e0a2017-12-23 02:05:44 +01001857}
1858
1859testcase TC_assignment_sign() runs on test_CT {
1860 var MSC_ConnHdlr vc_conn;
1861
1862 f_init(1, true);
1863 f_sleep(1.0);
1864
Harald Welte8863fa12018-05-10 20:15:27 +02001865 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01001866 vc_conn.done;
1867}
1868
Harald Welte60aa5762018-03-21 19:33:13 +01001869/***********************************************************************
1870 * Codec (list) testing
1871 ***********************************************************************/
1872
1873/* check if the given rsl_mode is compatible with the a_elem */
1874private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
1875return boolean {
1876 select (a_elem.codecType) {
1877 case (GSM_FR) {
1878 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
1879 return true;
1880 }
1881 }
1882 case (GSM_HR) {
1883 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
1884 return true;
1885 }
1886 }
1887 case (GSM_EFR) {
1888 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
1889 return true;
1890 }
1891 }
1892 case (FR_AMR) {
1893 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
1894 return true;
1895 }
1896 }
1897 case (HR_AMR) {
1898 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
1899 return true;
1900 }
1901 }
1902 case else { }
1903 }
1904 return false;
1905}
1906
1907/* check if the given rsl_mode is compatible with the a_list */
1908private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
1909return boolean {
1910 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
1911 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
1912 return true;
1913 }
1914 }
1915 return false;
1916}
1917
1918/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02001919function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01001920return BSSMAP_IE_ChannelType {
1921 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
1922 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
1923 select (a_elem.codecType) {
1924 case (GSM_FR) {
1925 ret.channelRateAndType := ChRate_TCHF;
1926 ret.speechId_DataIndicator := Spdi_TCHF_FR;
1927 }
1928 case (GSM_HR) {
1929 ret.channelRateAndType := ChRate_TCHH;
1930 ret.speechId_DataIndicator := Spdi_TCHH_HR;
1931 }
1932 case (GSM_EFR) {
1933 ret.channelRateAndType := ChRate_TCHF;
1934 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
1935 }
1936 case (FR_AMR) {
1937 ret.channelRateAndType := ChRate_TCHF;
1938 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
1939 }
1940 case (HR_AMR) {
1941 ret.channelRateAndType := ChRate_TCHH;
1942 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
1943 }
1944 case else {
1945 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02001946 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01001947 }
1948 }
1949 return ret;
1950}
1951
Harald Weltea63b9102018-03-22 20:36:16 +01001952private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
1953return template RSL_IE_Body {
1954 var template RSL_IE_Body mode_ie := {
1955 chan_mode := {
1956 len := ?,
1957 reserved := ?,
1958 dtx_d := ?,
1959 dtx_u := ?,
1960 spd_ind := RSL_SPDI_SPEECH,
1961 ch_rate_type := -,
1962 coding_alg_rate := -
1963 }
1964 }
1965
1966 select (a_elem.codecType) {
1967 case (GSM_FR) {
1968 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1969 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1970 }
1971 case (GSM_HR) {
1972 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1973 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1974 }
1975 case (GSM_EFR) {
1976 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1977 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
1978 }
1979 case (FR_AMR) {
1980 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1981 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1982 }
1983 case (HR_AMR) {
1984 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1985 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1986 }
1987 }
1988 return mode_ie;
1989}
1990
Harald Welte60aa5762018-03-21 19:33:13 +01001991type record CodecListTest {
1992 BSSMAP_IE_SpeechCodecList codec_list,
1993 charstring id
1994}
1995type record of CodecListTest CodecListTests
1996
1997private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001998 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
1999 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
Harald Welte60aa5762018-03-21 19:33:13 +01002000
2001 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Harald Welte79f3f542018-05-25 20:02:37 +02002002 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
2003 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
2004 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
2005 g_pars.ass_codec_list.codecElements[0];
Philipp Maierd0e64b02019-03-13 14:15:23 +01002006 if (isvalue(g_pars.expect_mr_s0_s7)) {
2007 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
2008 g_pars.expect_mr_s0_s7;
2009 }
Harald Welte79f3f542018-05-25 20:02:37 +02002010 }
Harald Welte60aa5762018-03-21 19:33:13 +01002011 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
2012 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01002013 log("expecting ASS COMPL like this: ", exp_compl);
2014
2015 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01002016
2017 /* Verify that the RSL-side activation actually matches our expectations */
2018 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
2019
2020 var RSL_IE_Body mode_ie;
2021 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
2022 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02002023 mtc.stop;
Harald Weltea63b9102018-03-22 20:36:16 +01002024 }
2025 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
2026 if (not match(mode_ie, t_mode_ie)) {
2027 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
2028 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002029
2030 var RSL_IE_Body mr_conf;
2031 if (g_pars.expect_mr_conf_ie != omit) {
2032 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
2033 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
Daniel Willmannafce8662018-07-06 23:11:32 +02002034 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002035 }
2036 log("found RSL MR CONFIG IE: ", mr_conf);
2037
2038 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
2039 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
2040 g_pars.expect_mr_conf_ie);
2041 }
2042 } else {
2043 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
2044 log("found RSL MR CONFIG IE: ", mr_conf);
2045 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
Daniel Willmannafce8662018-07-06 23:11:32 +02002046 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002047 }
2048 }
Harald Welte60aa5762018-03-21 19:33:13 +01002049}
2050
Philipp Maierd0e64b02019-03-13 14:15:23 +01002051private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
2052
2053 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2054 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2055
2056 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
2057 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
2058 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
2059 }
2060 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
2061 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
2062 log("expecting ASS FAIL like this: ", exp_fail);
2063
2064 f_establish_fully(ass_cmd, exp_fail);
2065}
2066
Harald Welte60aa5762018-03-21 19:33:13 +01002067testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002068 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002069 var MSC_ConnHdlr vc_conn;
2070
2071 f_init(1, true);
2072 f_sleep(1.0);
2073
2074 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002075 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002076 vc_conn.done;
2077}
2078
2079testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002080 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002081 var MSC_ConnHdlr vc_conn;
2082
2083 f_init(1, true);
2084 f_sleep(1.0);
2085
2086 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002087 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002088 vc_conn.done;
2089}
2090
2091testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002092 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002093 var MSC_ConnHdlr vc_conn;
2094
2095 f_init(1, true);
2096 f_sleep(1.0);
2097
2098 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002099 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002100 vc_conn.done;
2101}
2102
Philipp Maierd0e64b02019-03-13 14:15:23 +01002103/* Allow 5,90k only (current default config) */
2104private function f_allow_amr_rate_5_90k() runs on test_CT {
2105 f_vty_enter_cfg_msc(BSCVTY, 0);
2106 f_vty_transceive(BSCVTY, "amr-config 12_2k forbidden");
2107 f_vty_transceive(BSCVTY, "amr-config 10_2k forbidden");
2108 f_vty_transceive(BSCVTY, "amr-config 7_95k forbidden");
2109 f_vty_transceive(BSCVTY, "amr-config 7_40k forbidden");
2110 f_vty_transceive(BSCVTY, "amr-config 6_70k forbidden");
2111 f_vty_transceive(BSCVTY, "amr-config 5_90k allowed");
2112 f_vty_transceive(BSCVTY, "amr-config 5_15k forbidden");
2113 f_vty_transceive(BSCVTY, "amr-config 4_75k forbidden");
2114 f_vty_transceive(BSCVTY, "exit");
2115 f_vty_transceive(BSCVTY, "exit");
2116}
2117
2118/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
2119 * ("Config-NB-Code = 1") */
2120private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
2121 f_vty_enter_cfg_msc(BSCVTY, 0);
2122 f_vty_transceive(BSCVTY, "amr-config 12_2k allowed");
2123 f_vty_transceive(BSCVTY, "amr-config 10_2k forbidden");
2124 f_vty_transceive(BSCVTY, "amr-config 7_95k forbidden");
2125 f_vty_transceive(BSCVTY, "amr-config 7_40k allowed");
2126 f_vty_transceive(BSCVTY, "amr-config 6_70k forbidden");
2127 f_vty_transceive(BSCVTY, "amr-config 5_90k allowed");
2128 f_vty_transceive(BSCVTY, "amr-config 5_15k forbidden");
2129 f_vty_transceive(BSCVTY, "amr-config 4_75k allowed");
2130 f_vty_transceive(BSCVTY, "exit");
2131 f_vty_transceive(BSCVTY, "exit");
2132}
2133
Harald Welte60aa5762018-03-21 19:33:13 +01002134testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002135 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002136 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02002137
2138 /* Note: This setups the codec configuration. The parameter payload in
2139 * mr_conf must be consistant with the parameter codecElements in pars
2140 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002141 var RSL_IE_Body mr_conf := {
2142 other := {
2143 len := 2,
2144 payload := '2804'O
2145 }
2146 };
Harald Welte60aa5762018-03-21 19:33:13 +01002147
Philipp Maier7695a0d2018-09-27 17:52:14 +02002148 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Philipp Maier806f8f12019-03-12 12:13:41 +01002149 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02002150 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
2151 pars.expect_mr_conf_ie := mr_conf;
2152
Harald Welte60aa5762018-03-21 19:33:13 +01002153 f_init(1, true);
2154 f_sleep(1.0);
2155
Harald Welte8863fa12018-05-10 20:15:27 +02002156 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002157 vc_conn.done;
2158}
2159
2160testcase TC_assignment_codec_amr_h() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002161 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002162 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02002163
2164 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002165 var RSL_IE_Body mr_conf := {
2166 other := {
2167 len := 2,
2168 payload := '2804'O
2169 }
2170 };
Harald Welte60aa5762018-03-21 19:33:13 +01002171
Philipp Maier7695a0d2018-09-27 17:52:14 +02002172 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Philipp Maier806f8f12019-03-12 12:13:41 +01002173 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02002174 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2175 pars.expect_mr_conf_ie := mr_conf;
2176
Harald Welte60aa5762018-03-21 19:33:13 +01002177 f_init(1, true);
2178 f_sleep(1.0);
2179
Harald Welte8863fa12018-05-10 20:15:27 +02002180 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002181 vc_conn.done;
2182}
2183
Philipp Maierd0e64b02019-03-13 14:15:23 +01002184function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0)
2185runs on test_CT {
2186
2187 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2188 var MSC_ConnHdlr vc_conn;
2189
2190 /* See note above */
2191 var RSL_IE_Body mr_conf := {
2192 other := {
2193 len := lengthof(mrconf),
2194 payload := mrconf
2195 }
2196 };
2197
2198 if (fr) {
2199 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
2200 } else {
2201 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2202 }
2203 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
2204 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2205 pars.expect_mr_conf_ie := mr_conf;
2206 pars.expect_mr_s0_s7 := exp_s8_s0;
2207
2208 f_init(1, true);
2209 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
2210 f_sleep(1.0);
2211
2212 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
2213 vc_conn.done;
2214 f_allow_amr_rate_5_90k();
2215}
2216
2217function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
2218runs on test_CT {
2219
2220 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2221 var MSC_ConnHdlr vc_conn;
2222
2223 if (fr) {
2224 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
2225 } else {
2226 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2227 }
2228 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
2229 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2230
2231 f_init(1, true);
2232 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
2233 f_sleep(1.0);
2234
2235 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
2236 vc_conn.done;
2237 f_allow_amr_rate_5_90k();
2238}
2239
2240
2241/* Set S1, we expect an AMR multirate configuration IE with all four rates
2242 * set. */
2243testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
2244 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
2245}
2246
2247/* Set S1, we expect an AMR multirate configuration IE with the lower three
2248 * rates set. */
2249testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
2250 f_TC_assignment_codec_amr(false, '2815208820'O, '00000010'B, '00000010'B);
2251}
2252
2253/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
2254 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
2255testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
2256 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'B, '00000010'B);
2257}
2258
2259/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
2260 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
2261testcase TC_assignment_codec_amr_h_S124() runs on test_CT {
2262 f_TC_assignment_codec_amr(false, '2815208820'O, '00010110'B, '00000010'B);
2263}
2264
2265/* The following block of tests selects more and more rates until all four
2266 * possible rates are in the active set (full rate) */
2267testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
2268 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'B);
2269}
2270
2271testcase TC_assignment_codec_amr_f_S02() runs on test_CT {
2272 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'B);
2273}
2274
2275testcase TC_assignment_codec_amr_f_S024() runs on test_CT {
2276 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'B);
2277}
2278
2279testcase TC_assignment_codec_amr_f_S0247() runs on test_CT {
2280 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
2281}
2282
2283/* The following block of tests selects more and more rates until all three
2284 * possible rates are in the active set (half rate) */
2285testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
2286 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'B);
2287}
2288
2289testcase TC_assignment_codec_amr_h_S02() runs on test_CT {
2290 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
2291}
2292
2293testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
2294 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
2295}
2296
2297/* The following block tests what happens when the MSC does offer rate
2298 * configurations that are not supported by the BSC. Normally such situations
2299 * should not happen because the MSC gets informed by the BSC in advance via
2300 * the L3 COMPLETE message which rates are applicable. The MSC should not try
2301 * to offer rates that are not applicable anyway. */
2302
2303testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
2304 /* Try to include 12,2k in into the active set even though the channel
2305 * is half rate only. The BSC is expected to remove the 12,0k */
2306 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'B);
2307}
2308
2309testcase TC_assignment_codec_amr_f_S01234567() runs on test_CT {
2310 /* See what happens when all rates are selected at once. Since then
2311 * Also S1 is selected, this setting will be prefered and we should
2312 * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
2313 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
2314}
2315
2316testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
2317 /* Same as above, but with S1 missing, the MSC is then expected to
2318 * select the currently supported rates, which are also 12.2k, 7,40k,
2319 * 5,90k, and 4,75k, into the active set. */
2320 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'B);
2321}
2322
2323testcase TC_assignment_codec_amr_f_zero() runs on test_CT {
2324 /* Try to select no rates at all */
2325 f_TC_assignment_codec_amr_fail(true, '00000000'B);
2326}
2327
2328testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
2329 /* Try to select only unsupported rates */
2330 f_TC_assignment_codec_amr_fail(true, '01101000'B);
2331}
2332
2333testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
2334 /* Try to select 12,2k for half rate */
2335 f_TC_assignment_codec_amr_fail(false, '10000000'B);
2336}
2337
Philipp Maierac09bfc2019-01-08 13:41:39 +01002338private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002339 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
2340 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
2341 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
2342 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002343}
2344
2345private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002346 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
2347 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002348}
2349
2350private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002351 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
2352 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
2353 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
2354 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
2355 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
2356 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002357}
2358
2359/* Allow HR only */
2360private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
2361 g_pars := f_gen_test_hdlr_pars();
2362 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2363 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2364 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2365 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
2366 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
2367 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
2368 f_establish_fully(ass_cmd, exp_compl);
2369}
2370
2371/* Allow FR only */
2372private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
2373 g_pars := f_gen_test_hdlr_pars();
2374 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2375 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2376 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2377 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
2378 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
2379 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2380 f_establish_fully(ass_cmd, exp_compl);
2381}
2382
2383/* Allow HR only (expect assignment failure) */
2384private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
2385 g_pars := f_gen_test_hdlr_pars();
2386 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2387 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2388 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2389 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
2390 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
2391 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
2392 f_establish_fully(ass_cmd, exp_fail);
2393}
2394
2395/* Allow FR only (expect assignment failure) */
2396private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(charstring id) runs on MSC_ConnHdlr {
2397 g_pars := f_gen_test_hdlr_pars();
2398 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2399 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2400 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2401 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
2402 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
2403 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2404 f_establish_fully(ass_cmd, exp_fail);
2405}
2406
2407/* Allow FR and HR, but prefer FR */
2408private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2409 g_pars := f_gen_test_hdlr_pars();
2410 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2411 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2412 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2413 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2414 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2415 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2416 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2417 f_establish_fully(ass_cmd, exp_compl);
2418}
2419
2420/* Allow FR and HR, but prefer HR */
2421private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2422 g_pars := f_gen_test_hdlr_pars();
2423 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2424 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2425 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2426 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2427 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2428 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2429 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2430 f_establish_fully(ass_cmd, exp_compl);
2431}
2432
2433/* Allow FR and HR, but prefer FR */
2434private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2435 g_pars := f_gen_test_hdlr_pars();
2436 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2437 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2438 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2439 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2440 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2441 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2442 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2443 f_establish_fully(ass_cmd, exp_compl);
2444}
2445
2446/* Allow FR and HR, but prefer HR */
2447private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2448 g_pars := f_gen_test_hdlr_pars();
2449 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2450 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2451 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2452 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2453 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2454 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2455 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2456 f_establish_fully(ass_cmd, exp_compl);
2457}
2458
2459/* Request a HR channel while all FR channels are exhausted, this is expected
2460 * to work without conflicts */
2461testcase TC_assignment_codec_fr_exhausted_req_hr() runs on test_CT {
2462 var MSC_ConnHdlr vc_conn;
2463 f_init(1, true);
2464 f_sleep(1.0);
2465 f_enable_all_tch();
2466 f_disable_all_tch_f();
2467 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr));
2468 vc_conn.done;
2469 f_enable_all_tch();
2470 setverdict(pass);
2471}
2472
2473/* Request a FR channel while all FR channels are exhausted, this is expected
2474 * to fail. */
2475testcase TC_assignment_codec_fr_exhausted_req_fr() runs on test_CT {
2476 var MSC_ConnHdlr vc_conn;
2477 f_init(1, true);
2478 f_sleep(1.0);
2479 f_enable_all_tch();
2480 f_disable_all_tch_f();
2481 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr_fail));
2482 vc_conn.done;
2483 f_enable_all_tch();
2484 setverdict(pass);
2485}
2486
2487/* Request a FR (prefered) or alternatively a HR channel while all FR channels
2488 * are exhausted, this is expected to be resolved by selecting a HR channel. */
2489testcase TC_assignment_codec_fr_exhausted_req_fr_hr() runs on test_CT {
2490 var MSC_ConnHdlr vc_conn;
2491 f_init(1, true);
2492 f_sleep(1.0);
2493 f_enable_all_tch();
2494 f_disable_all_tch_f();
2495 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
2496 vc_conn.done;
2497 f_enable_all_tch();
2498 setverdict(pass);
2499}
2500
2501/* Request a HR (prefered) or alternatively a FR channel while all FR channels
2502 * are exhausted, this is expected to work without conflicts. */
2503testcase TC_assignment_codec_fr_exhausted_req_hr_fr() runs on test_CT {
2504 var MSC_ConnHdlr vc_conn;
2505 f_init(1, true);
2506 f_sleep(1.0);
2507 f_enable_all_tch();
2508 f_disable_all_tch_f();
2509 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_hr_fr));
2510 vc_conn.done;
2511 f_enable_all_tch();
2512 setverdict(pass);
2513}
2514
2515/* Request a FR channel while all HR channels are exhausted, this is expected
2516 * to work without conflicts */
2517testcase TC_assignment_codec_hr_exhausted_req_fr() runs on test_CT {
2518 var MSC_ConnHdlr vc_conn;
2519 f_init(1, true);
2520 f_sleep(1.0);
2521 f_enable_all_tch();
2522 f_disable_all_tch_h();
2523 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr));
2524 vc_conn.done;
2525 f_enable_all_tch();
2526 setverdict(pass);
2527}
2528
2529/* Request a HR channel while all HR channels are exhausted, this is expected
2530 * to fail. */
2531testcase TC_assignment_codec_hr_exhausted_req_hr() runs on test_CT {
2532 var MSC_ConnHdlr vc_conn;
2533 f_init(1, true);
2534 f_sleep(1.0);
2535 f_enable_all_tch();
2536 f_disable_all_tch_h();
2537 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr_fail));
2538 vc_conn.done;
2539 f_enable_all_tch();
2540 setverdict(pass);
2541}
2542
2543/* Request a HR (prefered) or alternatively a FR channel while all HR channels
2544 * are exhausted, this is expected to be resolved by selecting a FR channel. */
2545testcase TC_assignment_codec_hr_exhausted_req_hr_fr() runs on test_CT {
2546 var MSC_ConnHdlr vc_conn;
2547 f_init(1, true);
2548 f_sleep(1.0);
2549 f_enable_all_tch();
2550 f_disable_all_tch_h();
2551 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_hr_fr));
2552 vc_conn.done;
2553 f_enable_all_tch();
2554 setverdict(pass);
2555}
2556
2557/* Request a FR (prefered) or alternatively a HR channel while all HR channels
2558 * are exhausted, this is expected to work without conflicts. */
2559testcase TC_assignment_codec_hr_exhausted_req_fr_hr() runs on test_CT {
2560 var MSC_ConnHdlr vc_conn;
2561 f_init(1, true);
2562 f_sleep(1.0);
2563 f_enable_all_tch();
2564 f_disable_all_tch_h();
2565 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_fr_hr));
2566 vc_conn.done;
2567 f_enable_all_tch();
2568 setverdict(pass);
2569}
2570
2571/* Allow FR and HR, but prefer HR */
2572private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2573 g_pars := f_gen_test_hdlr_pars();
2574 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2575 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2576 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2577 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2578 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2579 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2580 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2581 f_establish_fully(ass_cmd, exp_compl);
2582}
2583
2584/* Allow FR and HR, but prefer FR */
2585private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2586 g_pars := f_gen_test_hdlr_pars();
2587 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2588 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2589 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2590 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2591 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2592 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2593 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2594 f_establish_fully(ass_cmd, exp_compl);
2595}
2596
2597/* Request a HR (prefered) or alternatively a FR channel, it is expected that
2598 * HR, which is the prefered type, is selected. */
2599testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
2600 var MSC_ConnHdlr vc_conn;
2601 f_init(1, true);
2602 f_sleep(1.0);
2603 f_enable_all_tch();
2604 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
2605 vc_conn.done;
2606 setverdict(pass);
2607}
2608
2609/* Request a FR (prefered) or alternatively a HR channel, it is expected that
2610 * FR, which is the prefered type, is selected. */
2611testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
2612 var MSC_ConnHdlr vc_conn;
2613 f_init(1, true);
2614 f_sleep(1.0);
2615 f_enable_all_tch();
2616 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
2617 vc_conn.done;
2618 setverdict(pass);
2619}
2620
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02002621testcase TC_assignment_osmux() runs on test_CT {
2622 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2623 var MSC_ConnHdlr vc_conn;
2624
2625 /* See note above */
2626 var RSL_IE_Body mr_conf := {
2627 other := {
2628 len := 2,
2629 payload := '2804'O
2630 }
2631 };
2632
2633 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2634 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
2635 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2636 pars.expect_mr_conf_ie := mr_conf;
2637 pars.use_osmux := true;
2638
2639 f_init(1, true, true);
2640 f_sleep(1.0);
2641
2642 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
2643 vc_conn.done;
2644}
2645
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02002646/* test the procedure of the MSC requesting a Classmark Update:
2647 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
2648 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01002649private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002650 g_pars := f_gen_test_hdlr_pars();
2651
Harald Weltea0630032018-03-20 21:09:55 +01002652 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01002653 /* we should now have a COMPL_L3 at the MSC */
2654 BSSAP.receive(tr_BSSMAP_ComplL3);
2655
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02002656 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
2657 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
2658
Harald Welte898113b2018-01-31 18:32:21 +01002659 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
2660 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
2661 setverdict(pass);
2662}
2663testcase TC_classmark() runs on test_CT {
2664 var MSC_ConnHdlr vc_conn;
2665 f_init(1, true);
2666 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002667 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01002668 vc_conn.done;
2669}
2670
Harald Weltee3bd6582018-01-31 22:51:25 +01002671private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002672 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01002673 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01002674 /* we should now have a COMPL_L3 at the MSC */
2675 BSSAP.receive(tr_BSSMAP_ComplL3);
2676
Harald Weltee3bd6582018-01-31 22:51:25 +01002677 /* send the single message we want to send */
2678 f_rsl_send_l3(l3);
2679}
2680
2681private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
2682 timer T := sec;
2683 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01002684 T.start;
2685 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01002686 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
2687 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02002688 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01002689 }
2690 [] T.timeout {
2691 setverdict(pass);
2692 }
2693 }
2694}
2695
Harald Weltee3bd6582018-01-31 22:51:25 +01002696/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2697private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
2698 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
2699 f_bssap_expect_nothing();
2700}
Harald Welte898113b2018-01-31 18:32:21 +01002701testcase TC_unsol_ass_fail() runs on test_CT {
2702 var MSC_ConnHdlr vc_conn;
2703 f_init(1, true);
2704 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002705 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01002706 vc_conn.done;
2707}
Harald Welte552620d2017-12-16 23:21:36 +01002708
Harald Welteea99a002018-01-31 20:46:43 +01002709
2710/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
2711private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002712 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
2713 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01002714}
2715testcase TC_unsol_ass_compl() runs on test_CT {
2716 var MSC_ConnHdlr vc_conn;
2717 f_init(1, true);
2718 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002719 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01002720 vc_conn.done;
2721}
2722
2723
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002724/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2725private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002726 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
2727 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002728}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002729testcase TC_unsol_ho_fail() runs on test_CT {
2730 var MSC_ConnHdlr vc_conn;
2731 f_init(1, true);
2732 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002733 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002734 vc_conn.done;
2735}
2736
2737
Harald Weltee3bd6582018-01-31 22:51:25 +01002738/* short message from MS should be ignored */
2739private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002740 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01002741 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01002742 /* we should now have a COMPL_L3 at the MSC */
2743 BSSAP.receive(tr_BSSMAP_ComplL3);
2744
2745 /* send short message */
2746 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
2747 f_bssap_expect_nothing();
2748}
2749testcase TC_err_82_short_msg() runs on test_CT {
2750 var MSC_ConnHdlr vc_conn;
2751 f_init(1, true);
2752 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002753 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01002754 vc_conn.done;
2755}
2756
2757
Harald Weltee9e02e42018-01-31 23:36:25 +01002758/* 24.008 8.4 Unknown message must trigger RR STATUS */
2759private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
2760 f_est_single_l3(ts_RRM_UL_REL('00'O));
2761 timer T := 3.0
2762 alt {
2763 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
2764 setverdict(pass);
2765 }
2766 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01002767 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01002768 }
2769}
2770testcase TC_err_84_unknown_msg() runs on test_CT {
2771 var MSC_ConnHdlr vc_conn;
2772 f_init(1, true);
2773 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002774 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01002775 vc_conn.done;
2776}
2777
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002778/***********************************************************************
2779 * Handover
2780 ***********************************************************************/
2781
Harald Welte94e0c342018-04-07 11:33:23 +02002782/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
2783private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
2784runs on test_CT {
2785 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2786 " timeslot "&int2str(ts_nr)&" ";
2787 f_vty_transceive(BSCVTY, cmd & suffix);
2788}
2789
Harald Welte261af4b2018-02-12 21:20:39 +01002790/* execute a "bts <0-255> trx <0-255> timeslot <0-7> sub-slot <0-7>" command on given Dchan */
2791private function f_vty_ss_action(charstring suffix, integer bts_nr, integer trx_nr, RslChannelNr chan_nr)
2792runs on MSC_ConnHdlr {
2793 /* FIXME: resolve those from component-global state */
2794 var integer ts_nr := chan_nr.tn;
2795 var integer ss_nr;
2796 if (ischosen(chan_nr.u.ch0)) {
2797 ss_nr := 0;
2798 } else if (ischosen(chan_nr.u.lm)) {
2799 ss_nr := chan_nr.u.lm.sub_chan;
2800 } else if (ischosen(chan_nr.u.sdcch4)) {
2801 ss_nr := chan_nr.u.sdcch4.sub_chan;
2802 } else if (ischosen(chan_nr.u.sdcch8)) {
2803 ss_nr := chan_nr.u.sdcch8.sub_chan;
2804 } else {
2805 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02002806 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01002807 }
2808
2809 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2810 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
2811 f_vty_transceive(BSCVTY, cmd & suffix);
2812}
2813
2814private function f_vty_handover(integer bts_nr, integer trx_nr, RslChannelNr chan_nr,
2815 integer new_bts_nr)
2816runs on MSC_ConnHdlr {
2817 f_vty_ss_action("handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
2818}
2819
2820/* intra-BSC hand-over between BTS0 and BTS1 */
2821private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002822 g_pars := f_gen_test_hdlr_pars();
Harald Welteed848512018-05-24 22:27:58 +02002823 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2824 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01002825 const OCT8 kc := '0001020304050607'O;
2826
2827 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2828 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2829
Harald Weltea0630032018-03-20 21:09:55 +01002830 f_establish_fully(ass_cmd, exp_compl);
Harald Welte261af4b2018-02-12 21:20:39 +01002831
2832 var HandoverState hs := {
2833 rr_ho_cmpl_seen := false,
2834 handover_done := false,
2835 old_chan_nr := -
2836 };
2837 /* issue hand-over command on VTY */
2838 f_vty_handover(0, 0, g_chan_nr, 1);
2839 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
2840 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002841
2842 /* From the MGW perspective, a handover is is characterized by
2843 * performing one MDCX operation with the MGW. So we expect to see
2844 * one more MDCX during handover. */
2845 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
2846
Harald Welte261af4b2018-02-12 21:20:39 +01002847 alt {
2848 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01002849 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002850
Philipp Maier4dae0652018-11-12 12:03:26 +01002851 /* Since this is an internal handover we expect the BSC to inform the
2852 * MSC about the event */
2853 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
2854
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002855 /* Check the amount of MGCP transactions is still consistant with the
2856 * test expectation */
2857 f_check_mgcp_expectations()
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01002858 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01002859}
2860
2861testcase TC_ho_int() runs on test_CT {
2862 var MSC_ConnHdlr vc_conn;
2863 f_init(2, true);
2864 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002865 vc_conn := f_start_handler(refers(f_tc_ho_int));
Harald Welte261af4b2018-02-12 21:20:39 +01002866 vc_conn.done;
2867}
Harald Weltee9e02e42018-01-31 23:36:25 +01002868
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002869private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002870 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002871
2872 var PDU_BSSAP ass_req := f_gen_ass_req();
2873 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2874 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2875 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2876 f_establish_fully(ass_req, exp_compl);
2877
2878 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2879
2880 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2881
2882 f_sleep(0.5);
2883 /* The MSC negotiates Handover Request and Handover Request Ack with
2884 * the other BSS and comes back with a BSSMAP Handover Command
2885 * containing an RR Handover Command coming from the target BSS... */
2886
2887 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
2888 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
2889 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
2890 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
2891 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
2892
2893 /* expect the Handover Command to go out on RR */
2894 var RSL_Message rsl_ho_cmd
2895 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
2896 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
2897 var RSL_IE_Body rsl_ho_cmd_l3;
2898 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
2899 log("RSL message contains no L3 Info IE, expected RR Handover Command");
2900 setverdict(fail);
2901 } else {
2902 log("Found L3 Info: ", rsl_ho_cmd_l3);
2903 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
2904 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
2905 setverdict(fail);
2906 } else {
2907 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
2908 setverdict(pass);
2909 }
2910 }
2911
2912 /* When the other BSS has reported a completed handover, this side is
2913 * torn down. */
2914
2915 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
2916 var BssmapCause cause := enum2int(cause_val);
2917 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
2918
2919 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
2920 var MgcpCommand mgcp;
2921 interleave {
2922 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
2923 [] MGCP.receive(tr_DLCX()) -> value mgcp {
2924 log("Got first DLCX: ", mgcp);
2925 }
2926 [] MGCP.receive(tr_DLCX()) -> value mgcp {
2927 log("Got second DLCX: ", mgcp);
2928 }
2929 }
2930 setverdict(pass);
2931 f_sleep(1.0);
2932}
2933testcase TC_ho_out_of_this_bsc() runs on test_CT {
2934 var MSC_ConnHdlr vc_conn;
2935
2936 f_init(1, true);
2937 f_sleep(1.0);
2938
2939 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
2940 vc_conn.done;
2941}
2942
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002943/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
2944 * simply never sends a BSSMAP Handover Command. */
2945private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01002946 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002947
2948 var PDU_BSSAP ass_req := f_gen_ass_req();
2949 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2950 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2951 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2952 f_establish_fully(ass_req, exp_compl);
2953
2954 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2955
2956 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2957
2958 /* osmo-bsc should time out 10 seconds after the handover started.
2959 * Let's give it a bit extra. */
2960 f_sleep(15.0);
2961
2962 /* The old lchan and conn should still be active. See that arbitrary L3
2963 * is still going through. */
2964 var octetstring l3 := '0123456789'O;
2965 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
2966 var template PDU_BSSAP exp_data := {
2967 discriminator := '1'B,
2968 spare := '0000000'B,
2969 dlci := '00'O,
2970 lengthIndicator := 5,
2971 pdu := {
2972 dtap := l3
2973 }
2974 };
2975 BSSAP.receive(exp_data);
2976 setverdict(pass);
2977 f_sleep(1.0);
2978}
2979testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
2980 var MSC_ConnHdlr vc_conn;
2981
2982 f_init(1, true);
2983 f_sleep(1.0);
2984
2985 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
2986 vc_conn.done;
2987}
2988
2989/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
2990 * RR Handover Failure. */
2991private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01002992 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002993
2994 var PDU_BSSAP ass_req := f_gen_ass_req();
2995 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2996 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2997 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2998 f_establish_fully(ass_req, exp_compl);
2999
3000 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
3001
3002 BSSAP.receive(tr_BSSMAP_HandoverRequired);
3003
3004 f_sleep(0.5);
3005 /* The MSC negotiates Handover Request and Handover Request Ack with
3006 * the other BSS and comes back with a BSSMAP Handover Command
3007 * containing an RR Handover Command coming from the target BSS... */
3008
3009 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
3010 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
3011 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
3012 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
3013 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
3014
3015 /* expect the Handover Command to go out on RR */
3016 var RSL_Message rsl_ho_cmd
3017 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
3018 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
3019 var RSL_IE_Body rsl_ho_cmd_l3;
3020 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
3021 log("RSL message contains no L3 Info IE, expected RR Handover Command");
3022 setverdict(fail);
3023 } else {
3024 log("Found L3 Info: ", rsl_ho_cmd_l3);
3025 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
3026 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
3027 setverdict(fail);
3028 } else {
3029 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
3030 setverdict(pass);
3031 }
3032 }
3033
3034 f_sleep(0.2);
3035 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
3036
3037 /* Should tell the MSC about the failure */
3038 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3039
3040 f_sleep(1.0);
3041
3042 /* The old lchan and conn should still be active. See that arbitrary L3
3043 * is still going through. */
3044 var octetstring l3 := '0123456789'O;
3045 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
3046 var template PDU_BSSAP exp_data := {
3047 discriminator := '1'B,
3048 spare := '0000000'B,
3049 dlci := '00'O,
3050 lengthIndicator := 5,
3051 pdu := {
3052 dtap := l3
3053 }
3054 };
3055 BSSAP.receive(exp_data);
3056 setverdict(pass);
3057 f_sleep(1.0);
3058
3059 setverdict(pass);
3060 f_sleep(1.0);
3061}
3062testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
3063 var MSC_ConnHdlr vc_conn;
3064
3065 f_init(1, true);
3066 f_sleep(1.0);
3067
3068 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
3069 vc_conn.done;
3070}
3071
3072/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
3073 * RR Handover Failure. */
3074private function f_tc_ho_out_fail_no_ho_detect(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01003075 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003076
3077 var PDU_BSSAP ass_req := f_gen_ass_req();
3078 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3079 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3080 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3081 f_establish_fully(ass_req, exp_compl);
3082
3083 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
3084
3085 BSSAP.receive(tr_BSSMAP_HandoverRequired);
3086
3087 f_sleep(0.5);
3088 /* The MSC negotiates Handover Request and Handover Request Ack with
3089 * the other BSS and comes back with a BSSMAP Handover Command
3090 * containing an RR Handover Command coming from the target BSS... */
3091
3092 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
3093 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
3094 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
3095 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
3096 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
3097
3098 /* expect the Handover Command to go out on RR */
3099 var RSL_Message rsl_ho_cmd
3100 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
3101 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
3102 var RSL_IE_Body rsl_ho_cmd_l3;
3103 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
3104 log("RSL message contains no L3 Info IE, expected RR Handover Command");
3105 setverdict(fail);
3106 } else {
3107 log("Found L3 Info: ", rsl_ho_cmd_l3);
3108 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
3109 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
3110 setverdict(fail);
3111 } else {
3112 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
3113 setverdict(pass);
3114 }
3115 }
3116
3117 /* The MS never shows up on the remote BSS. Eventually the BSC times
3118 * out and we run into 3GPP TS 48.008 3.1.5.3.3 "Abnormal Conditions":
3119 * RR should be released and Clear Request should go to the MSC. */
3120
3121 var MgcpCommand mgcp;
3122 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01003123 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
3124 log("Got Deact SACCH");
3125 }
Harald Welte924b6ea2019-02-04 01:05:34 +01003126 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01003127 log("Got RR Release");
3128 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003129 [] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
3130 log("Got RF Chan Rel");
3131 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
3132 }
3133 [] BSSAP.receive(tr_BSSMAP_ClearRequest) {
3134 log("Got BSSMAP Clear Request");
3135 }
3136 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3137 log("Got first DLCX: ", mgcp);
3138 }
3139 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3140 log("Got second DLCX: ", mgcp);
3141 }
3142 }
3143
3144 setverdict(pass);
3145 f_sleep(1.0);
3146}
3147testcase TC_ho_out_fail_no_ho_detect() runs on test_CT {
3148 var MSC_ConnHdlr vc_conn;
3149
3150 f_init(1, true);
3151 f_sleep(1.0);
3152
3153 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_ho_detect));
3154 vc_conn.done;
3155}
3156
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003157private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
3158 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
3159 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
3160 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
3161 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
3162 * before we get started. */
3163 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3164 f_rslem_register(0, new_chan_nr);
3165 g_chan_nr := new_chan_nr;
3166 f_sleep(1.0);
3167
3168 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3169 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3170 activate(as_Media());
3171
3172 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3173 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003174 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003175
3176 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3177
3178 var PDU_BSSAP rx_bssap;
3179 var octetstring ho_command_str;
3180
3181 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3182
3183 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3184 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3185 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3186 log("L3 Info in HO Request Ack is ", ho_command);
3187
3188 var GsmArfcn arfcn;
3189 var RslChannelNr actual_new_chan_nr;
3190 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3191 actual_new_chan_nr, arfcn);
3192
3193 if (actual_new_chan_nr != new_chan_nr) {
3194 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3195 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3196 setverdict(fail);
3197 return;
3198 }
3199 log("Handover Command chan_nr is", actual_new_chan_nr);
3200
3201 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3202 * tells the MS to handover to the new lchan. Here comes the new MS on
3203 * the new lchan with a Handover RACH: */
3204
3205 /* send handover detect */
3206
3207 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
3208
3209 BSSAP.receive(tr_BSSMAP_HandoverDetect);
3210
3211 /* send handover complete over the new channel */
3212
3213 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
3214 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
3215 enc_PDU_ML3_MS_NW(l3_tx)));
3216
3217 BSSAP.receive(tr_BSSMAP_HandoverComplete);
3218 setverdict(pass);
3219}
3220testcase TC_ho_into_this_bsc() runs on test_CT {
3221 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003222 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003223
3224 f_init(1, true);
3225 f_sleep(1.0);
3226
3227 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3228 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3229
3230 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
3231 vc_conn.done;
3232}
3233
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003234private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
3235 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3236 f_rslem_register(0, new_chan_nr);
3237 g_chan_nr := new_chan_nr;
3238 f_sleep(1.0);
3239
3240 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3241 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3242 activate(as_Media());
3243
3244 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3245 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003246 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003247
3248 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3249
3250 var PDU_BSSAP rx_bssap;
3251 var octetstring ho_command_str;
3252
3253 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3254
3255 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3256 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3257 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3258 log("L3 Info in HO Request Ack is ", ho_command);
3259
3260 var GsmArfcn arfcn;
3261 var RslChannelNr actual_new_chan_nr;
3262 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3263 actual_new_chan_nr, arfcn);
3264
3265 if (actual_new_chan_nr != new_chan_nr) {
3266 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3267 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3268 setverdict(fail);
3269 return;
3270 }
3271 log("Handover Command chan_nr is", actual_new_chan_nr);
3272
Neels Hofmeyr61ca08d2019-05-06 23:52:22 +02003273 /* For deterministic test results, give some time for the MGW endpoint to be configured */
3274 f_sleep(1.0);
3275
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003276 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3277 * tells the MS to handover to the new lchan. In this case, the MS
3278 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
3279 * Handover Failure to the MSC. The procedure according to 3GPP TS
3280 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
3281 * BSSMAP Clear Command: */
3282
3283 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3284 var BssmapCause cause := enum2int(cause_val);
3285 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3286
3287 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3288 var MgcpCommand mgcp;
3289 interleave {
3290 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3291 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3292 log("Got first DLCX: ", mgcp);
3293 }
3294 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3295 log("Got second DLCX: ", mgcp);
3296 }
3297 }
3298 setverdict(pass);
3299 f_sleep(1.0);
3300
3301 setverdict(pass);
3302}
3303testcase TC_ho_in_fail_msc_clears() runs on test_CT {
3304 var MSC_ConnHdlr vc_conn;
3305 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3306
3307 f_init(1, true);
3308 f_sleep(1.0);
3309
3310 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3311 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3312
3313 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
3314 vc_conn.done;
3315}
3316
3317private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
3318 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
3319 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
3320 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
3321 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
3322 * before we get started. */
3323 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3324 f_rslem_register(0, new_chan_nr);
3325 g_chan_nr := new_chan_nr;
3326 f_sleep(1.0);
3327
3328 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3329 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3330 activate(as_Media());
3331
3332 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3333 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003334 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003335
3336 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3337
3338 var PDU_BSSAP rx_bssap;
3339 var octetstring ho_command_str;
3340
3341 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3342
3343 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3344 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3345 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3346 log("L3 Info in HO Request Ack is ", ho_command);
3347
3348 var GsmArfcn arfcn;
3349 var RslChannelNr actual_new_chan_nr;
3350 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3351 actual_new_chan_nr, arfcn);
3352
3353 if (actual_new_chan_nr != new_chan_nr) {
3354 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3355 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3356 setverdict(fail);
3357 return;
3358 }
3359 log("Handover Command chan_nr is", actual_new_chan_nr);
3360
3361 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3362 * tells the MS to handover to the new lchan. Here comes the new MS on
3363 * the new lchan with a Handover RACH: */
3364
3365 /* send handover detect */
3366
3367 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
3368
3369 BSSAP.receive(tr_BSSMAP_HandoverDetect);
3370
3371 /* The MSC chooses to clear the connection now, maybe we got the
3372 * Handover RACH on the new cell but the MS still signaled Handover
3373 * Failure to the old BSS? */
3374
3375 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3376 var BssmapCause cause := enum2int(cause_val);
3377 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3378
3379 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3380 var MgcpCommand mgcp;
3381 interleave {
3382 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3383 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3384 log("Got first DLCX: ", mgcp);
3385 }
3386 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3387 log("Got second DLCX: ", mgcp);
3388 }
3389 }
3390 setverdict(pass);
3391 f_sleep(1.0);
3392}
3393testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
3394 var MSC_ConnHdlr vc_conn;
3395 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3396
3397 f_init(1, true);
3398 f_sleep(1.0);
3399
3400 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3401 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3402
3403 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
3404 vc_conn.done;
3405}
3406
3407/* The new BSS's lchan times out before the MSC decides that handover failed. */
3408private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
3409 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3410 f_rslem_register(0, new_chan_nr);
3411 g_chan_nr := new_chan_nr;
3412 f_sleep(1.0);
3413
3414 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3415 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3416 activate(as_Media());
3417
3418 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3419 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003420 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003421
3422 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3423
3424 var PDU_BSSAP rx_bssap;
3425 var octetstring ho_command_str;
3426
3427 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3428
3429 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3430 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3431 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3432 log("L3 Info in HO Request Ack is ", ho_command);
3433
3434 var GsmArfcn arfcn;
3435 var RslChannelNr actual_new_chan_nr;
3436 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3437 actual_new_chan_nr, arfcn);
3438
3439 if (actual_new_chan_nr != new_chan_nr) {
3440 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3441 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3442 setverdict(fail);
3443 return;
3444 }
3445 log("Handover Command chan_nr is", actual_new_chan_nr);
3446
3447 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3448 * tells the MS to handover to the new lchan. But the MS never shows up
3449 * on the new lchan. */
3450
3451 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3452
3453 /* Did osmo-bsc also send a Clear Request? */
3454 timer T := 0.5;
3455 T.start;
3456 alt {
3457 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
3458 [] T.timeout { }
3459 }
3460
3461 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
3462 * asked for it, this is a Handover Failure after all). */
3463
3464 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3465 var BssmapCause cause := enum2int(cause_val);
3466 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3467
3468 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3469 var MgcpCommand mgcp;
3470 interleave {
3471 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3472 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3473 log("Got first DLCX: ", mgcp);
3474 }
3475 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3476 log("Got second DLCX: ", mgcp);
3477 }
3478 }
3479 setverdict(pass);
3480 f_sleep(1.0);
3481
3482 setverdict(pass);
3483}
3484testcase TC_ho_in_fail_no_detect() runs on test_CT {
3485 var MSC_ConnHdlr vc_conn;
3486 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3487
3488 f_init(1, true);
3489 f_sleep(1.0);
3490
3491 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3492 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3493
3494 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
3495 vc_conn.done;
3496}
3497
3498/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
3499private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
3500 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3501 f_rslem_register(0, new_chan_nr);
3502 g_chan_nr := new_chan_nr;
3503 f_sleep(1.0);
3504
3505 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3506 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3507 activate(as_Media());
3508
3509 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3510 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003511 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003512
3513 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3514
3515 var PDU_BSSAP rx_bssap;
3516 var octetstring ho_command_str;
3517
3518 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3519
3520 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3521 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3522 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3523 log("L3 Info in HO Request Ack is ", ho_command);
3524
3525 var GsmArfcn arfcn;
3526 var RslChannelNr actual_new_chan_nr;
3527 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3528 actual_new_chan_nr, arfcn);
3529
3530 if (actual_new_chan_nr != new_chan_nr) {
3531 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3532 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3533 setverdict(fail);
3534 return;
3535 }
3536 log("Handover Command chan_nr is", actual_new_chan_nr);
3537
3538 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3539 * tells the MS to handover to the new lchan. But the MS never shows up
3540 * on the new lchan. */
3541
3542 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3543
3544 /* MSC plays dumb and sends no Clear Command */
3545
3546 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3547 var PDU_BSSAP rx_clear_request;
3548 var MgcpCommand mgcp;
3549 interleave {
3550 [] BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
3551 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
3552 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3553 };
3554 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3555
3556 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3557 log("Got first DLCX: ", mgcp);
3558 }
3559 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3560 log("Got second DLCX: ", mgcp);
3561 }
3562 }
3563 setverdict(pass);
3564 f_sleep(1.0);
3565}
3566testcase TC_ho_in_fail_no_detect2() runs on test_CT {
3567 var MSC_ConnHdlr vc_conn;
3568 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3569
3570 f_init(1, true);
3571 f_sleep(1.0);
3572
3573 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3574 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3575
3576 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
3577 vc_conn.done;
3578}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003579
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003580/* OS#3041: Open and close N connections in a normal fashion, and expect no
3581 * BSSMAP Reset just because of that. */
3582testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
3583 var default d;
3584 var integer i;
3585 var DchanTuple dt;
3586
3587 f_init();
3588
3589 /* Wait for initial BSSMAP Reset to pass */
3590 f_sleep(4.0);
3591
3592 d := activate(no_bssmap_reset());
3593
3594 /* Setup up a number of connections and RLSD them again from the MSC
3595 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3596 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02003597 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003598 /* Since we're doing a lot of runs, give each one a fresh
3599 * T_guard from the top. */
3600 T_guard.start;
3601
3602 /* Setup a BSSAP connection and clear it right away. This is
3603 * the MSC telling the BSC about a planned release, it's not an
3604 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02003605 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003606
3607 /* MSC disconnects (RLSD). */
3608 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
3609 }
3610
3611 /* In the buggy behavior, a timeout of 2 seconds happens between above
3612 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3613 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3614 f_sleep(4.0);
3615
3616 deactivate(d);
3617 f_shutdown_helper();
3618}
Harald Welte552620d2017-12-16 23:21:36 +01003619
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003620/* OS#3041: Open and close N connections in a normal fashion, and expect no
3621 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
3622 * the MSC. */
3623testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
3624 var default d;
3625 var integer i;
3626 var DchanTuple dt;
3627 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003628 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
3629 var BssmapCause cause := enum2int(cause_val);
3630
3631 f_init();
3632
3633 /* Wait for initial BSSMAP Reset to pass */
3634 f_sleep(4.0);
3635
3636 d := activate(no_bssmap_reset());
3637
3638 /* Setup up a number of connections and RLSD them again from the MSC
3639 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3640 * Let's do it some more times for good measure. */
3641 for (i := 0; i < 8; i := i+1) {
3642 /* Since we're doing a lot of runs, give each one a fresh
3643 * T_guard from the top. */
3644 T_guard.start;
3645
3646 /* Setup a BSSAP connection and clear it right away. This is
3647 * the MSC telling the BSC about a planned release, it's not an
3648 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02003649 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003650
3651 /* Instruct BSC to clear channel */
3652 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
3653
3654 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02003655 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003656 }
3657
3658 /* In the buggy behavior, a timeout of 2 seconds happens between above
3659 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3660 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3661 f_sleep(4.0);
3662
3663 deactivate(d);
3664 f_shutdown_helper();
3665}
3666
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003667/* OS#3041: Open and close N connections in a normal fashion, and expect no
3668 * BSSMAP Reset just because of that. Close connections from the MS side with a
3669 * Release Ind on RSL. */
3670testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
3671 var default d;
3672 var integer i;
3673 var DchanTuple dt;
3674 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003675 var integer j;
3676
3677 f_init();
3678
3679 /* Wait for initial BSSMAP Reset to pass */
3680 f_sleep(4.0);
3681
3682 d := activate(no_bssmap_reset());
3683
3684 /* Setup up a number of connections and RLSD them again from the MSC
3685 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3686 * Let's do it some more times for good measure. */
3687 for (i := 0; i < 8; i := i+1) {
3688 /* Since we're doing a lot of runs, give each one a fresh
3689 * T_guard from the top. */
3690 T_guard.start;
3691
3692 /* Setup a BSSAP connection and clear it right away. This is
3693 * the MSC telling the BSC about a planned release, it's not an
3694 * erratic loss of a connection. */
3695 dt := f_est_dchan('23'O, 23, '00010203040506'O);
3696
3697 /* simulate RLL REL IND */
3698 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
3699
3700 /* expect Clear Request on MSC side */
3701 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
3702
3703 /* Instruct BSC to clear channel */
3704 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
3705 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
3706
3707 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02003708 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003709 }
3710
3711 /* In the buggy behavior, a timeout of 2 seconds happens between above
3712 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3713 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3714 f_sleep(4.0);
3715
3716 deactivate(d);
3717 f_shutdown_helper();
3718}
3719
Harald Welte94e0c342018-04-07 11:33:23 +02003720/***********************************************************************
3721 * IPA style dynamic PDCH
3722 ***********************************************************************/
3723
3724private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
3725 template (omit) RSL_Cause nack := omit)
3726runs on test_CT {
3727 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
3728 var RSL_Message rsl_unused;
3729 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3730 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
3731 /* expect the BSC to issue the related RSL command */
3732 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3733 if (istemplatekind(nack, "omit")) {
3734 /* respond with a related acknowledgement */
3735 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3736 } else {
3737 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
3738 }
3739}
3740
3741private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
3742 template (omit) RSL_Cause nack := omit)
3743runs on test_CT {
3744 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
3745 var RSL_Message rsl_unused;
3746 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3747 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
3748 /* expect the BSC to issue the related RSL command */
3749 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
3750 if (istemplatekind(nack, "omit")) {
3751 /* respond with a related acknowledgement */
3752 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
3753 } else {
3754 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
3755 }
3756}
3757
3758private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
3759runs on test_CT return charstring {
3760 var charstring cmd, resp;
3761 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01003762 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02003763}
3764
3765private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
3766 template charstring exp)
3767runs on test_CT {
3768 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
3769 if (not match(mode, exp)) {
3770 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02003771 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02003772 }
3773}
3774
3775private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
3776runs on test_CT {
3777 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
3778 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
3779 f_vty_transceive(BSCVTY, "end");
3780}
3781
3782private const charstring TCHF_MODE := "TCH/F mode";
3783private const charstring TCHH_MODE := "TCH/H mode";
3784private const charstring PDCH_MODE := "PDCH mode";
3785private const charstring NONE_MODE := "NONE mode";
3786
3787/* Test IPA PDCH activation / deactivation triggered by VTY */
3788testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
3789 var RSL_Message rsl_unused;
3790
3791 /* change Timeslot 6 before f_init() starts RSL */
3792 f_init_vty();
3793 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
3794 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3795
3796 f_init(1, false);
3797 f_sleep(1.0);
3798
3799 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
3800
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003801 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003802 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3803 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3804 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3805 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3806 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003807 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003808 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3809
3810 /* De-activate it via VTY */
3811 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3812 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003813 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003814 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3815
3816 /* re-activate it via VTY */
3817 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
3818 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003819 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003820 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3821
3822 /* and finally de-activate it again */
3823 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3824 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003825 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003826 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3827
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003828 /* clean up config */
3829 f_ts_set_chcomb(0, 0, 6, "PDCH");
3830
Harald Welte94e0c342018-04-07 11:33:23 +02003831 setverdict(pass);
3832}
3833
3834/* Test IPA PDCH activation NACK */
3835testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
3836 var RSL_Message rsl_unused;
3837
3838 /* change Timeslot 6 before f_init() starts RSL */
3839 f_init_vty();
3840 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
3841 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3842
3843 f_init(1, false);
3844 f_sleep(1.0);
3845
3846 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
3847
3848 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3849 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3850 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3851 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3852 f_sleep(1.0);
3853 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3854
3855 /* De-activate it via VTY */
3856 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3857 f_sleep(1.0);
3858 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3859
3860 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
3861 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
3862 f_sleep(1.0);
3863 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3864
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003865 /* clean up config */
3866 f_ts_set_chcomb(0, 0, 6, "PDCH");
3867
Harald Welte94e0c342018-04-07 11:33:23 +02003868 setverdict(pass);
3869}
3870
3871
3872/***********************************************************************
3873 * Osmocom style dynamic PDCH
3874 ***********************************************************************/
3875
3876private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
3877 template (omit) RSL_Cause nack := omit)
3878runs on test_CT {
3879 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
3880 var RSL_Message rsl_unused;
3881 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3882 /* FIXME: no VTY command to activate Osmocom PDCH !! */
3883 /* expect the BSC to issue the related RSL command */
3884 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
3885 if (istemplatekind(nack, "omit")) {
3886 /* respond with a related acknowledgement */
3887 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
3888 } else {
3889 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
3890 }
3891}
3892
3893private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
3894 template (omit) RSL_Cause nack := omit)
3895runs on test_CT {
3896 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
3897 var RSL_Message rsl_unused;
3898 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3899 /* FIXME: no VTY command to activate Osmocom PDCH !! */
3900 /* expect the BSC to issue the related RSL command */
3901 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
3902 if (istemplatekind(nack, "omit")) {
3903 /* respond with a related acknowledgement */
3904 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
3905 } else {
3906 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
3907 }
3908}
3909
3910/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
3911testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
3912 var RSL_Message rsl_unused;
3913
3914 /* change Timeslot 6 before f_init() starts RSL */
3915 f_init_vty();
3916 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
3917 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3918
3919 f_init(1, false);
3920 f_sleep(1.0);
3921
3922 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
3923
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003924 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003925 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
3926 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3927 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
3928
3929 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
3930 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003931 log("TCH/F_TCH/H_PDCH requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
Harald Welte94e0c342018-04-07 11:33:23 +02003932 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3933
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003934 /* clean up config */
3935 f_ts_set_chcomb(0, 0, 6, "PDCH");
3936
Harald Welte94e0c342018-04-07 11:33:23 +02003937 setverdict(pass);
3938}
3939
3940/* Test Osmocom dyn PDCH activation NACK behavior */
3941testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
3942 var RSL_Message rsl_unused;
3943
3944 /* change Timeslot 6 before f_init() starts RSL */
3945 f_init_vty();
3946 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
3947 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3948
3949 f_init(1, false);
3950 f_sleep(1.0);
3951
3952 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
3953
3954 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
3955 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3956 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
3957
3958 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
3959 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
3960 f_sleep(1.0);
3961 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
3962
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003963 /* clean up config */
3964 f_ts_set_chcomb(0, 0, 6, "PDCH");
3965
Harald Welte94e0c342018-04-07 11:33:23 +02003966 setverdict(pass);
3967}
3968
Stefan Sperling0796a822018-10-05 13:01:39 +02003969testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02003970 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02003971 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
3972 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
3973 }
3974}
3975
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02003976testcase TC_chopped_ipa_payload() runs on test_CT {
3977 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
3978 /* TODO: mp_bsc_ctrl_port does not work yet */};
3979 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
3980 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
3981 }
3982}
3983
3984
Harald Welte0ea2d5e2018-04-07 21:40:29 +02003985/* Dyn PDCH todo:
3986 * activate OSMO as TCH/F
3987 * activate OSMO as TCH/H
3988 * does the BSC-located PCU socket get the updated INFO?
3989 * what if no PCU is connected at the time?
3990 * is the info correct on delayed PCU (re)connect?
3991 */
Harald Welte94e0c342018-04-07 11:33:23 +02003992
Harald Welte28d943e2017-11-25 15:00:50 +01003993control {
Harald Welte898113b2018-01-31 18:32:21 +01003994 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +01003995 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01003996 execute( TC_ctrl_msc0_connection_status() );
Harald Welte96c94412017-12-09 03:12:45 +01003997 execute( TC_ctrl() );
Harald Welte898113b2018-01-31 18:32:21 +01003998
3999 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +01004000 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +01004001 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +01004002 execute( TC_chan_act_ack_noest() );
4003 execute( TC_chan_act_ack_est_ind_noreply() );
4004 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +01004005 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +01004006 execute( TC_chan_exhaustion() );
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07004007 execute( TC_chan_deact_silence() );
Harald Welte4003d112017-12-09 22:35:39 +01004008 execute( TC_chan_rel_rll_rel_ind() );
4009 execute( TC_chan_rel_conn_fail() );
4010 execute( TC_chan_rel_hard_clear() );
Harald Welte99787102019-02-04 10:41:36 +01004011 execute( TC_chan_rel_hard_clear_csfb() );
Harald Welted8c36cd2017-12-09 23:05:31 +01004012 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +02004013 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +01004014 execute( TC_chan_rel_a_reset() );
Harald Welte6f521d82017-12-11 19:52:02 +01004015
Harald Weltecfe2c962017-12-15 12:09:32 +01004016 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +01004017
4018 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +01004019 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +01004020 execute( TC_assignment_csd() );
4021 execute( TC_assignment_ctm() );
4022 execute( TC_assignment_sign() );
4023 execute( TC_assignment_fr_a5_0() );
4024 execute( TC_assignment_fr_a5_1() );
Harald Welte8f67d1d2018-05-25 20:38:42 +02004025 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
4026 execute( TC_assignment_fr_a5_1_codec_missing() );
4027 }
Harald Welte235ebf12017-12-15 14:18:16 +01004028 execute( TC_assignment_fr_a5_3() );
4029 execute( TC_assignment_fr_a5_4() );
Harald Welte3c86ea02018-05-10 22:28:05 +02004030 execute( TC_ciph_mode_a5_0() );
4031 execute( TC_ciph_mode_a5_1() );
4032 execute( TC_ciph_mode_a5_3() );
Harald Welte16a4adf2017-12-14 18:54:01 +01004033
Harald Welte60aa5762018-03-21 19:33:13 +01004034 execute( TC_assignment_codec_fr() );
4035 execute( TC_assignment_codec_hr() );
4036 execute( TC_assignment_codec_efr() );
4037 execute( TC_assignment_codec_amr_f() );
4038 execute( TC_assignment_codec_amr_h() );
Philipp Maier8a581d22019-03-26 18:32:48 +01004039
4040 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
4041 execute( TC_assignment_codec_amr_f_S1() );
4042 execute( TC_assignment_codec_amr_h_S1() );
4043 execute( TC_assignment_codec_amr_f_S124() );
4044 execute( TC_assignment_codec_amr_h_S124() );
4045 execute( TC_assignment_codec_amr_f_S0() );
4046 execute( TC_assignment_codec_amr_f_S02() );
4047 execute( TC_assignment_codec_amr_f_S024() );
4048 execute( TC_assignment_codec_amr_f_S0247() );
4049 execute( TC_assignment_codec_amr_h_S0() );
4050 execute( TC_assignment_codec_amr_h_S02() );
4051 execute( TC_assignment_codec_amr_h_S024() );
4052 execute( TC_assignment_codec_amr_h_S0247() );
4053 execute( TC_assignment_codec_amr_f_S01234567() );
4054 execute( TC_assignment_codec_amr_f_S0234567() );
4055 execute( TC_assignment_codec_amr_f_zero() );
4056 execute( TC_assignment_codec_amr_f_unsupp() );
4057 execute( TC_assignment_codec_amr_h_S7() );
4058 }
Harald Welte60aa5762018-03-21 19:33:13 +01004059
Philipp Maierac09bfc2019-01-08 13:41:39 +01004060 execute( TC_assignment_codec_fr_exhausted_req_hr() );
4061 execute( TC_assignment_codec_fr_exhausted_req_fr() );
4062 execute( TC_assignment_codec_fr_exhausted_req_fr_hr() );
4063 execute( TC_assignment_codec_fr_exhausted_req_hr_fr() );
4064 execute( TC_assignment_codec_hr_exhausted_req_fr() );
4065 execute( TC_assignment_codec_hr_exhausted_req_hr() );
4066 execute( TC_assignment_codec_hr_exhausted_req_hr_fr() );
4067 execute( TC_assignment_codec_hr_exhausted_req_fr_hr() );
4068 execute( TC_assignment_codec_req_hr_fr() );
4069 execute( TC_assignment_codec_req_fr_hr() );
4070
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +02004071 if (mp_enable_osmux_test) {
4072 execute( TC_assignment_osmux() );
4073 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004074
Harald Welte898113b2018-01-31 18:32:21 +01004075 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +01004076 execute( TC_rll_est_ind_inact_lchan() );
4077 execute( TC_rll_est_ind_inval_sapi1() );
4078 execute( TC_rll_est_ind_inval_sapi3() );
4079 execute( TC_rll_est_ind_inval_sacch() );
4080
Harald Welte898113b2018-01-31 18:32:21 +01004081 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +01004082 execute( TC_paging_imsi_nochan() );
4083 execute( TC_paging_tmsi_nochan() );
4084 execute( TC_paging_tmsi_any() );
4085 execute( TC_paging_tmsi_sdcch() );
4086 execute( TC_paging_tmsi_tch_f() );
4087 execute( TC_paging_tmsi_tch_hf() );
4088 execute( TC_paging_imsi_nochan_cgi() );
4089 execute( TC_paging_imsi_nochan_lac_ci() );
4090 execute( TC_paging_imsi_nochan_ci() );
4091 execute( TC_paging_imsi_nochan_lai() );
4092 execute( TC_paging_imsi_nochan_lac() );
4093 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +01004094 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
4095 execute( TC_paging_imsi_nochan_rnc() );
4096 execute( TC_paging_imsi_nochan_lac_rnc() );
4097 execute( TC_paging_imsi_nochan_lacs() );
4098 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +01004099 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +01004100 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +01004101 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +01004102 execute( TC_paging_counter() );
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01004103 execute( TC_paging_resp_unsol() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +01004104
4105 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +01004106 execute( TC_rsl_unknown_unit_id() );
4107
4108 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +01004109
4110 execute( TC_classmark() );
4111 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +01004112 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004113 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +01004114 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +01004115 execute( TC_err_84_unknown_msg() );
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004116
Harald Welte261af4b2018-02-12 21:20:39 +01004117 execute( TC_ho_int() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004118
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004119 execute( TC_ho_out_of_this_bsc() );
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004120 execute( TC_ho_out_fail_no_msc_response() );
4121 execute( TC_ho_out_fail_rr_ho_failure() );
4122 execute( TC_ho_out_fail_no_ho_detect() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004123
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004124 execute( TC_ho_into_this_bsc() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004125 execute( TC_ho_in_fail_msc_clears() );
4126 execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
4127 execute( TC_ho_in_fail_no_detect() );
4128 execute( TC_ho_in_fail_no_detect2() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01004129
4130 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01004131 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01004132 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +02004133
4134 execute( TC_dyn_pdch_ipa_act_deact() );
4135 execute( TC_dyn_pdch_ipa_act_nack() );
4136 execute( TC_dyn_pdch_osmo_act_deact() );
4137 execute( TC_dyn_pdch_osmo_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +02004138
Stefan Sperling0796a822018-10-05 13:01:39 +02004139 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02004140 execute( TC_chopped_ipa_payload() );
Stefan Sperling0796a822018-10-05 13:01:39 +02004141
Harald Welte99f3ca02018-06-14 13:40:29 +02004142 /* at bottom as they might crash OsmoBSC before OS#3182 is fixed */
4143 execute( TC_early_conn_fail() );
4144 execute( TC_late_conn_fail() );
4145
Harald Welte28d943e2017-11-25 15:00:50 +01004146}
4147
4148}