blob: 85260bc72165884bff94b9a7225d852a6eba5d68 [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 };
125}
126
Philipp Maier48604732018-10-09 15:00:37 +0200127private function f_gen_test_hdlr_pars() return TestHdlrParams {
128
129 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
130 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
131 pars.aoip := true;
132 } else {
133 pars.aoip := false;
134 }
135
136 return pars;
137}
138
Philipp Maier282ca4b2018-02-27 17:17:00 +0100139private function f_shutdown_helper() runs on test_CT {
Daniel Willmann637ef6c2018-07-25 10:49:09 +0200140 all component.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100141 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200142 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100143}
144
Harald Weltea4ca4462018-02-09 00:17:14 +0100145private function f_legacy_bssap_reset() runs on test_CT {
146 var BSSAP_N_UNITDATA_ind ud_ind;
147 timer T := 5.0;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200148 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 +0100149 T.start;
150 alt {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200151 [] 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 +0100152 log("Received RESET-ACK in response to RESET, we're ready to go!");
153 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200154 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Weltea4ca4462018-02-09 00:17:14 +0100155 log("Respoding to inbound RESET with RESET-ACK");
156 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200157 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Weltea4ca4462018-02-09 00:17:14 +0100158 repeat;
159 }
160 [] BSSAP.receive { repeat; }
161 [] T.timeout { setverdict(fail, "Waiting for RESET-ACK after sending RESET"); }
162 }
Harald Welte28d943e2017-11-25 15:00:50 +0100163}
164
Harald Welteae026692017-12-09 01:03:01 +0100165type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100166 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100167 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100168 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100169 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100170 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100171 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100172 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100173 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100174}
175
Harald Welte21b46bd2017-12-17 19:46:32 +0100176/*! Start the IPA/RSL related bits for one IPA_Client.
177 * \param clnt IPA_Client for which to establish
178 * \param bsc_host IP address / hostname of the BSC
179 * \param bsc_port TCP port number of the BSC
180 * \param i number identifying this BTS
181 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100182function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
183 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100184runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100185 timer T := 10.0;
186
Harald Welte96c94412017-12-09 03:12:45 +0100187 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welteae026692017-12-09 01:03:01 +0100188 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA");
189 clnt.ccm_pars := c_IPA_default_ccm_pars;
190 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
191 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100192 if (handler_mode) {
193 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL");
Harald Welte89ab1912018-02-23 18:56:29 +0100194 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100195 }
Harald Welteae026692017-12-09 01:03:01 +0100196
197 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Harald Welte624f9632017-12-16 19:26:04 +0100198 if (handler_mode) {
199 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
200 } else {
201 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
202 }
Harald Welteae026692017-12-09 01:03:01 +0100203
Harald Welte5d1a2202017-12-13 19:51:29 +0100204 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100205 if (handler_mode) {
206 clnt.vc_RSL.start(RSL_Emulation.main());
207 return;
208 }
Harald Welteae026692017-12-09 01:03:01 +0100209
210 /* wait for IPA RSL link to connect and send ID ACK */
211 T.start;
212 alt {
213 [] IPA_RSL[i].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_ID_ACK}) {
214 T.stop;
215 IPA_RSL[i].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_PAGING_LOAD_IND(23)));
216 }
Harald Welte60e823a2017-12-10 14:10:59 +0100217 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100218 [] IPA_RSL[i].receive { repeat }
219 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100220 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200221 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100222 }
223 }
224}
225
Harald Welte12055472018-03-17 20:10:08 +0100226function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
227 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
228 return;
229 }
230 clnt.vc_IPA.stop;
231 if (isbound(clnt.vc_RSL)) {
232 clnt.vc_RSL.stop;
233 }
234}
235
Harald Welte21b46bd2017-12-17 19:46:32 +0100236/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100237function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
238 timer T := secs_max;
239 T.start;
240 while (true) {
241 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
242 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100243 /* the 'degraded' state exists from OML connection time, and we have to wait
244 * until all MO's are initialized */
245 T.start(1.0);
246 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100247 return;
248 }
Harald Weltef0d6ac62017-12-17 17:02:21 +0100249 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100250 if (not T.running) {
Max99253902018-11-16 17:57:39 +0100251 setverdict(fail, "Timeout waiting for BTS" & int2str(bts_nr) & " oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +0200252 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100253 }
254 }
255}
256
Harald Welte21b46bd2017-12-17 19:46:32 +0100257/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +0100258altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +0100259 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100260 [] T_guard.timeout {
261 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +0200262 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100263 }
Harald Welte60e823a2017-12-10 14:10:59 +0100264 /* always respond with RESET ACK to RESET */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200265 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Welte60e823a2017-12-10 14:10:59 +0100266 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200267 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Welte69c1c262017-12-13 21:02:08 +0100268 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +0100269 }
Harald Welte28d943e2017-11-25 15:00:50 +0100270}
271
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100272altstep no_bssmap_reset() runs on test_CT {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200273 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100274 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +0200275 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100276 }
277}
278
Daniel Willmann191e0d92018-01-17 12:44:35 +0100279function f_init_mgcp(charstring id) runs on test_CT {
280 id := id & "-MGCP";
281
282 var MGCPOps ops := {
283 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
284 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
285 };
286 var MGCP_conn_parameters mgcp_pars := {
287 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +0100288 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +0100289 mgw_ip := mp_test_ip,
290 mgw_udp_port := 2427
291 };
292
293 vc_MGCP := MGCP_Emulation_CT.create(id);
294 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
295}
296
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200297/* Enable or disable (current default) Osmux. When enabling, BSSMAP Reset
298 * contains extra IE (OsmuxSupport) and osmo-bsc will handle AssignReq with
299 * OsmuxCID IE.
300 */
301private function f_vty_allow_osmux(boolean allow) runs on test_CT {
302 f_vty_enter_cfg_msc(BSCVTY, 0);
303 if (allow) {
304 f_vty_transceive(BSCVTY, "osmux on");
305 } else {
306 f_vty_transceive(BSCVTY, "osmux off");
307 }
308 f_vty_transceive(BSCVTY, "exit");
309 f_vty_transceive(BSCVTY, "exit");
310 g_osmux_enabled := allow;
311}
312
Max2253c0b2018-11-06 19:28:05 +0100313function f_init_vty(charstring id := "foo") runs on test_CT {
Harald Welte94e0c342018-04-07 11:33:23 +0200314 if (BSCVTY.checkstate("Mapped")) {
315 /* skip initialization if already executed once */
316 return;
317 }
Harald Weltebc03c762018-02-12 18:09:38 +0100318 map(self:BSCVTY, system:BSCVTY);
319 f_vty_set_prompts(BSCVTY);
320 f_vty_transceive(BSCVTY, "enable");
321}
322
Harald Welte21b46bd2017-12-17 19:46:32 +0100323/* global initialization function
324 * \param nr_bts Number of BTSs we should start/bring up
325 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200326function 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 +0100327 var integer i;
Harald Welte28d943e2017-11-25 15:00:50 +0100328
Harald Welteae026692017-12-09 01:03:01 +0100329 if (g_initialized) {
330 return;
Harald Welte28d943e2017-11-25 15:00:50 +0100331 }
Harald Welteae026692017-12-09 01:03:01 +0100332 g_initialized := true;
333
Daniel Willmanne68f9272018-11-27 15:15:28 +0100334 T_guard.start;
335 activate(as_Tguard());
336
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200337 f_init_vty("VirtMSC");
338 f_vty_allow_osmux(allow_osmux);
339
Harald Welte6811d102019-04-14 22:23:14 +0200340 /* Call a function of our 'parent component' RAN_Adapter_CT to start the
Harald Welteae026692017-12-09 01:03:01 +0100341 * MSC-side BSSAP emulation */
Harald Welte67089ee2018-01-17 22:19:03 +0100342 if (handler_mode) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200343 var RanOps ranops := MSC_RanOps;
344 ranops.use_osmux := g_osmux_enabled;
345 f_ran_adapter_init(g_bssap, mp_bssap_cfg, "VirtMSC", ranops);
Harald Welte3ca0ce12019-04-23 17:18:48 +0200346 f_ran_adapter_start(g_bssap);
Harald Welte67089ee2018-01-17 22:19:03 +0100347 } else {
Harald Welte3ca0ce12019-04-23 17:18:48 +0200348 f_ran_adapter_init(g_bssap, mp_bssap_cfg, "VirtMSC", omit);
Harald Weltea4ca4462018-02-09 00:17:14 +0100349 connect(self:BSSAP, g_bssap.vc_SCCP:SCCP_SP_PORT);
Harald Welte3ca0ce12019-04-23 17:18:48 +0200350 f_ran_adapter_start(g_bssap);
Harald Weltea4ca4462018-02-09 00:17:14 +0100351 f_legacy_bssap_reset();
Harald Welte67089ee2018-01-17 22:19:03 +0100352 }
Harald Welted5833a82018-05-27 16:52:56 +0200353
Harald Welteffe55fc2018-01-17 22:39:54 +0100354 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +0100355
Daniel Willmann191e0d92018-01-17 12:44:35 +0100356 f_init_mgcp("VirtMSC");
357
Harald Welte89d42e82017-12-17 16:42:41 +0100358 for (i := 0; i < nr_bts; i := i+1) {
Harald Weltea5d2ab22017-12-09 14:21:42 +0100359 /* wait until osmo-bts-omldummy has respawned */
360 f_wait_oml(i, "degraded", 5.0);
361 /* start RSL connection */
Harald Welte624f9632017-12-16 19:26:04 +0100362 f_ipa_rsl_start(bts[i].rsl, mp_bsc_ip, mp_bsc_rsl_port, i, handler_mode);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100363 /* wait until BSC tells us "connected" */
364 f_wait_oml(i, "connected", 5.0);
Harald Welte696ddb62017-12-08 14:01:43 +0100365 }
366
Harald Welte28d943e2017-11-25 15:00:50 +0100367}
368
Maxd4e56962018-10-31 19:08:25 +0100369/* expect to receive a RSL message matching a specified template on a given BTS / stream */
Harald Welteae026692017-12-09 01:03:01 +0100370function f_exp_ipa_rx(integer bts_nr, template RSL_Message t_rx, float t_secs := 2.0, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
371runs on test_CT return RSL_Message {
372 var ASP_RSL_Unitdata rx_rsl_ud;
373 timer T := t_secs;
374
375 T.start;
376 alt {
377 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(sid, t_rx)) -> value rx_rsl_ud {
378 T.stop;
379 }
380 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +0100381 [] T.timeout {
382 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +0200383 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +0100384 }
Harald Welteae026692017-12-09 01:03:01 +0100385 }
386 return rx_rsl_ud.rsl;
387}
388
Harald Welte21b46bd2017-12-17 19:46:32 +0100389/* helper function to transmit RSL on a given BTS/stream */
Harald Welteae026692017-12-09 01:03:01 +0100390function f_ipa_tx(integer bts_nr, template RSL_Message t_tx, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
391runs on test_CT {
392 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(sid, t_tx));
393}
394
395
Harald Welte4003d112017-12-09 22:35:39 +0100396/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +0100397testcase TC_chan_act_noreply() runs on test_CT {
398 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +0100399 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +0100400
Harald Welte89d42e82017-12-17 16:42:41 +0100401 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +0100402
Harald Welteae026692017-12-09 01:03:01 +0100403 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 +0100404 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welteae026692017-12-09 01:03:01 +0100405 setverdict(pass);
Harald Welte28d943e2017-11-25 15:00:50 +0100406}
407
Harald Welte4003d112017-12-09 22:35:39 +0100408/* verify if the "chreq:total" counter increments as expected */
409testcase TC_chan_act_counter() runs on test_CT {
410 var BSSAP_N_UNITDATA_ind ud_ind;
411 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +0100412 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +0100413
Harald Welte89d42e82017-12-17 16:42:41 +0100414 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100415
416 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
417 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 +0100418 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welte4003d112017-12-09 22:35:39 +0100419 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total", chreq_total+1);
420
421 setverdict(pass);
422}
423
Harald Welteae026692017-12-09 01:03:01 +0100424/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
425testcase TC_chan_act_ack_noest() runs on test_CT {
426 var RSL_Message rx_rsl;
427
Harald Welte89d42e82017-12-17 16:42:41 +0100428 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100429
430 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100431 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100432
433 /* expect BSC to disable the channel again if there's no RLL EST IND */
434 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
435
436 setverdict(pass);
437}
438
439/* Test behavior if MSC never answers to CR */
440testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +0100441 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
442 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +0100443 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +0100444 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +0100445
Harald Welte89d42e82017-12-17 16:42:41 +0100446 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100447
448 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100449 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100450
451 var octetstring l3 := '00010203040506'O
452 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
453
454 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
455
456 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +0100457 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100458 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Harald Welteae026692017-12-09 01:03:01 +0100459 setverdict(pass);
460}
461
462/* Test behavior if MSC answers with CREF to CR */
463testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
464 var BSSAP_N_CONNECT_ind rx_c_ind;
465 var RSL_Message rx_rsl;
466
Harald Welte89d42e82017-12-17 16:42:41 +0100467 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100468
469 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100470 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100471
472 var octetstring l3 := '00010203040506'O
473 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
474
475 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
476 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
477
478 /* expect BSC to disable the channel */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100479 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Harald Welteae026692017-12-09 01:03:01 +0100480 setverdict(pass);
481}
482
Harald Welte618ef642017-12-14 14:58:20 +0100483/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
484testcase TC_chan_act_nack() runs on test_CT {
485 var RSL_Message rx_rsl;
486 var integer chact_nack;
487
Harald Welte89d42e82017-12-17 16:42:41 +0100488 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +0100489
490 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
491
492 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
493 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
494 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
495
496 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
497
498 /* wait for some time to hope the NACK arrives before the CTRL GET below */
499 f_sleep(0.5);
500
501 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
502
503 setverdict(pass);
504}
505
Harald Welte799c97b2017-12-14 17:50:30 +0100506/* Test for channel exhaustion due to RACH overload */
507testcase TC_chan_exhaustion() runs on test_CT {
508 var ASP_RSL_Unitdata rsl_ud;
509 var integer i;
510 var integer chreq_total, chreq_nochan;
511
Harald Welte89d42e82017-12-17 16:42:41 +0100512 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +0100513
514 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
515 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
516
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +0100517 /* GSM 04.08 Table 9.9a:
518 * RA = '33'O -> Establishment cause = 0011xxxx (MS dual rate capable and asks for "TCH/H or TCH/F").
519 * With current setup, expect 4xSDCCH + 4xTCH/F + 1xTCH/H to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +0200520 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 +0100521 var RslChannelNr chan_nr := f_chreq_act_ack('33'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +0100522 }
523
524 IPA_RSL[0].clear;
525
Harald Weltedd8cbf32018-01-28 12:07:52 +0100526 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200527 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +0100528
529 /* now expect additional channel activations to fail */
530 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
531
532 alt {
533 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
534 tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
535 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
536 }
537 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
538 var GsmRrMessage rr;
539 /* match on IMM ASS REJ */
540 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
541 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
542 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200543 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +0100544 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
545 chreq_nochan+1);
546 setverdict(pass);
547 } else {
548 repeat;
549 }
550 }
551 [] IPA_RSL[0].receive { repeat; }
552 }
553}
554
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +0700555/* Test channel deactivation due to silence from MS */
556testcase TC_chan_deact_silence() runs on test_CT {
557 var RslChannelNr chan_nr;
558
559 f_init(1);
560
561 /* Request for a dedicated channel */
562 chan_nr := f_chreq_act_ack('23'O);
563
564 /* Wait some time until the channel is released */
565 f_sleep(2.0);
566
567 /* Expect CHANnel RELease */
568 alt {
569 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
570 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
571 log("Received CHANnel RELease");
572 setverdict(pass);
573 }
574 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
575 tr_RSL_IMM_ASSIGN(?))) {
576 /* See OS#3709, OsmoBSC should not send Immediate
577 * Assignment Reject since a dedicated channel was
578 * already allocated, and Immediate Assignment was
579 * already sent. */
580 setverdict(fail, "Unexpected Immediate Assignment!");
581 }
582 [] IPA_RSL[0].receive {
583 setverdict(fail, "Unexpected RSL message!");
584 }
585 }
586}
587
Harald Weltecfe2c962017-12-15 12:09:32 +0100588/***********************************************************************
589 * Assignment Testing
590 ***********************************************************************/
591
Neels Hofmeyrda4a6952018-06-14 04:02:49 +0200592/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction,
593 * except for the inter-BSC handover, MT side) */
Harald Weltecfe2c962017-12-15 12:09:32 +0100594testcase TC_outbound_connect() runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +0100595 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +0100596
Harald Weltea4ca4462018-02-09 00:17:14 +0100597 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 +0100598 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
599 setverdict(pass);
600}
601
Harald Welte16a4adf2017-12-14 18:54:01 +0100602/* Test behavior if MSC answers with CREF to CR */
603testcase TC_assignment_cic_only() runs on test_CT {
604 var BSSAP_N_CONNECT_ind rx_c_ind;
605 var RSL_Message rx_rsl;
606 var DchanTuple dt;
607
Harald Welte89d42e82017-12-17 16:42:41 +0100608 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +0100609
610 dt := f_est_dchan('23'O, 23, '00000000'O);
Harald Welte17b27da2018-05-25 20:33:53 +0200611 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
612 /* send assignment without AoIP IEs */
613 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
614 } else {
615 /* Send assignmetn without CIC in IPA case */
616 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
617 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
618 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
619 }
Harald Welte16a4adf2017-12-14 18:54:01 +0100620 alt {
621 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
622 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
623 }
Harald Welte235ebf12017-12-15 14:18:16 +0100624 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +0100625 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
626 setverdict(pass);
627 }
628 [] BSSAP.receive { repeat; }
629 }
630}
631
Harald Welteed848512018-05-24 22:27:58 +0200632/* generate an assignment request for either AoIP or SCCPlite */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200633function f_gen_ass_req(boolean osmux_enabled := false) return PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200634 var PDU_BSSAP ass_cmd;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200635 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Harald Welteed848512018-05-24 22:27:58 +0200636 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
637 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
638 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200639 if (osmux_enabled) {
640 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla, osmux_cid));
641 } else {
642 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
643 }
Harald Welteed848512018-05-24 22:27:58 +0200644 } else {
645 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200646 if (osmux_enabled) {
647 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit, osmux_cid));
648 } else {
649 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
650 }
Harald Welteed848512018-05-24 22:27:58 +0200651 }
652 return ass_cmd;
653}
654
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +0100655function f_gen_handover_req() return PDU_BSSAP {
656 var PDU_BSSAP ho_req;
657 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
658 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
659 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
660 ho_req := valueof(ts_BSSMAP_HandoverRequest(omit, tla));
661 } else {
662 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
663 ho_req := valueof(ts_BSSMAP_HandoverRequest(cic, omit));
664 }
665 return ho_req;
666}
667
Harald Welteed848512018-05-24 22:27:58 +0200668/* generate an assignment complete template for either AoIP or SCCPlite */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200669function f_gen_exp_compl(boolean expect_osmux := false) return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200670 var template PDU_BSSAP exp_compl;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200671 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Harald Welteed848512018-05-24 22:27:58 +0200672 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200673 if (expect_osmux) {
674 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, osmux_cid);
675 } else {
676 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, omit);
677 }
Harald Welteed848512018-05-24 22:27:58 +0200678 } else {
679 /* CIC is optional "*" as the MSC allocated it */
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);
684 }
Harald Welteed848512018-05-24 22:27:58 +0200685 }
686 return exp_compl;
687}
688
Harald Welte235ebf12017-12-15 14:18:16 +0100689/* Run everything required up to sending a caller-specified assignment command and expect response */
690function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
691runs on test_CT {
692 var BSSAP_N_CONNECT_ind rx_c_ind;
693 var RSL_Message rx_rsl;
694 var DchanTuple dt;
695
Harald Welte89d42e82017-12-17 16:42:41 +0100696 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +0100697
698 dt := f_est_dchan('23'O, 23, '00000000'O);
699 /* send assignment without AoIP IEs */
700 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
701 alt {
702 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
703 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
704 setverdict(pass);
705 } else {
706 setverdict(fail, fail_text);
707 }
708 }
709 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
710 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
711 setverdict(pass);
712 } else {
713 setverdict(fail, fail_text);
714 }
715 }
716 [] BSSAP.receive { repeat; }
717 }
718}
719testcase TC_assignment_csd() runs on test_CT {
720 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200721 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100722 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
723 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
724 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
725}
726
727testcase TC_assignment_ctm() runs on test_CT {
728 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200729 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100730 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
731 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
732 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
733}
734
Harald Welte4003d112017-12-09 22:35:39 +0100735type record DchanTuple {
736 integer sccp_conn_id,
737 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +0100738}
739
Harald Welted6939652017-12-13 21:02:46 +0100740/* Send CHAN RQD and wait for allocation; acknowledge it */
741private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
742runs on test_CT return RslChannelNr {
743 var RSL_Message rx_rsl;
744 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
745 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
746 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
747 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
Daniel Willmannf4ac4ce2018-08-02 14:06:30 +0200748 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Harald Welted6939652017-12-13 21:02:46 +0100749 return chan_nr;
750}
751
Harald Welte4003d112017-12-09 22:35:39 +0100752/* helper function to establish a dedicated channel via BTS and MSC */
753function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
754runs on test_CT return DchanTuple {
755 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +0100756 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100757
Harald Welte4003d112017-12-09 22:35:39 +0100758 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100759 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +0100760
761 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
762
763 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
764 dt.sccp_conn_id := rx_c_ind.connectionId;
765 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
766
767 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100768}
769
Harald Welte641fcbe2018-06-14 10:58:35 +0200770/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
771private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
772 var RSL_Message rx_rsl;
773 /* expect BSC to disable the channel */
774 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
775 /* respond with CHAN REL ACK */
776 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
777
778 /* expect Clear Complete from BSC */
779 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
780
781 /* MSC disconnects as instructed. */
782 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
783}
784
Harald Welte4003d112017-12-09 22:35:39 +0100785/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
786testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100787 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100788 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +0100789
Harald Welte89d42e82017-12-17 16:42:41 +0100790 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +0100791
Harald Welte4003d112017-12-09 22:35:39 +0100792 dt := f_est_dchan('23'O, 23, '00010203040506'O);
793
794 /* simulate RLL REL IND */
795 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
796
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100797 /* expect Clear Request on MSC side */
798 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
799
800 /* Instruct BSC to clear channel */
801 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
802 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
803
Harald Welte4003d112017-12-09 22:35:39 +0100804 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200805 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100806
807 /* wait for SCCP emulation to do its job */
808 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +0100809
810 setverdict(pass);
811}
812
813/* Test behavior of channel release after CONN FAIL IND from BTS */
814testcase TC_chan_rel_conn_fail() runs on test_CT {
815 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100816 var DchanTuple dt;
817
Harald Welte89d42e82017-12-17 16:42:41 +0100818 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100819
820 dt := f_est_dchan('23'O, 23, '00010203040506'O);
821
822 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +0100823 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 +0100824 /* TODO: different cause values? */
825
Harald Welte4003d112017-12-09 22:35:39 +0100826 /* expect Clear Request from BSC */
827 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
828
829 /* Instruct BSC to clear channel */
830 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
831 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
832
Harald Welte6ff76ea2018-01-28 13:08:01 +0100833 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200834 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +0100835
836 /* wait for SCCP emulation to do its job */
837 f_sleep(1.0);
838
839 setverdict(pass);
840}
841
Harald Welte99f3ca02018-06-14 13:40:29 +0200842/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
843/* See also https://www.osmocom.org/issues/3182 */
844testcase TC_early_conn_fail() runs on test_CT {
845 var RSL_Message rx_rsl;
846 var DchanTuple dt;
847
848 f_init(1);
849
850 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
851 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_octstring(1), 23);
852
853 /* BTS->BSC: simulate CONN FAIL IND */
854 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
855
856 /* BTS->BSC: Expect RF channel release from BSC on Abis */
857 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
858
859 /* BTS<-BSC: respond with CHAN REL ACK */
860 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
861
862 setverdict(pass);
863}
864
865/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
866/* See also https://www.osmocom.org/issues/3182 */
867testcase TC_late_conn_fail() runs on test_CT {
868 var RSL_Message rx_rsl;
869 var DchanTuple dt;
870
871 f_init(1);
872
873 dt := f_est_dchan('23'O, 23, '00010203040506'O);
874
875 /* BSC<-MSC: Instruct BSC to clear connection */
876 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
877
878 /* BTS->BSC: expect BSC to deactivate SACCH */
879 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
880
881 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
882 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
883
884 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
885 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
886 /* BTS->BSC: respond with CHAN REL ACK */
887 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
888
889 /* BSC->MSC: expect Clear Complete from BSC */
890 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
891
892 /* BSC<-MSC: MSC disconnects as requested. */
893 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
894
895 setverdict(pass);
896}
897
Neels Hofmeyrf44ccd12018-11-05 19:15:23 +0100898function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr,
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100899 boolean expect_deact_sacch := true,
900 boolean expect_rr_chan_rel := true,
901 boolean expect_rll_rel_req := true,
Harald Welte99787102019-02-04 10:41:36 +0100902 boolean handle_rll_rel := true,
903 boolean is_csfb := false
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100904 ) runs on test_CT {
Harald Welte91d54a52018-01-28 15:35:07 +0100905
906 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100907 var boolean got_deact_sacch := false;
908 var boolean got_rr_chan_rel := false;
909 var boolean got_rll_rel_req := false;
910 log("f_expect_chan_rel() expecting: expect_deact_sacch=", expect_deact_sacch, " expect_rr_chan_rel=", expect_rr_chan_rel,
911 " expect_rll_rel_req=", expect_rll_rel_req);
Harald Welte91d54a52018-01-28 15:35:07 +0100912 alt {
Harald Welte91d54a52018-01-28 15:35:07 +0100913 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
914 tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100915 got_deact_sacch := true;
Harald Welte91d54a52018-01-28 15:35:07 +0100916 repeat;
917 }
Harald Welte99787102019-02-04 10:41:36 +0100918 [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))) {
919 got_rr_chan_rel := true;
920 repeat;
921 }
922 [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 +0100923 got_rr_chan_rel := true;
Neels Hofmeyr211169d2018-11-07 00:37:29 +0100924 repeat;
925 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100926 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
Harald Welte91d54a52018-01-28 15:35:07 +0100927 tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100928 got_rll_rel_req := true;
Harald Welte91d54a52018-01-28 15:35:07 +0100929 /* FIXME: Why are we getting this for LinkID SACCH? */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100930 if (handle_rll_rel) {
931 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
932 }
Harald Welte91d54a52018-01-28 15:35:07 +0100933 repeat;
934 }
Harald Welte91d54a52018-01-28 15:35:07 +0100935 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
936 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
937 /* respond with CHAN REL ACK */
938 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
939 }
940 /* ignore any user data */
941 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_MsgTypeR(?))) {
942 repeat;
943 }
944 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100945
946 log("f_expect_chan_rel() summary: got_deact_sacch=", got_deact_sacch, " got_rr_chan_rel=", got_rr_chan_rel,
947 " got_rll_rel_req=", got_rll_rel_req);
948
949 if (expect_deact_sacch != got_deact_sacch) {
950 setverdict(fail, "f_expect_chan_rel(): expect_deact_sacch=", expect_deact_sacch, " got_deact_sacch=", got_deact_sacch);
951 }
952 if (expect_rr_chan_rel != got_rr_chan_rel) {
953 setverdict(fail, "f_expect_chan_rel(): expect_rr_chan_rel=", expect_rr_chan_rel, " got_rr_chan_rel=", got_rr_chan_rel);
954 }
955 if (expect_rll_rel_req != got_rll_rel_req) {
956 setverdict(fail, "f_expect_chan_rel(): expect_rll_rel_req=", expect_rll_rel_req, " got_rll_rel_req=", got_rll_rel_req);
957 }
Harald Welte91d54a52018-01-28 15:35:07 +0100958}
959
Harald Welte4003d112017-12-09 22:35:39 +0100960/* Test behavior of channel release after hard Clear Command from MSC */
961testcase TC_chan_rel_hard_clear() runs on test_CT {
962 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100963 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +0100964
Harald Welte89d42e82017-12-17 16:42:41 +0100965 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100966
967 dt := f_est_dchan('23'O, 23, '00010203040506'O);
968
969 /* Instruct BSC to clear channel */
970 var BssmapCause cause := 0;
971 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
972
973 /* expect Clear Complete from BSC on A */
974 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
975 /* release the SCCP connection */
976 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
977 }
978
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100979 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte4003d112017-12-09 22:35:39 +0100980 setverdict(pass);
981}
982
Harald Welte99787102019-02-04 10:41:36 +0100983/* Test behavior of channel release after Clear Command with CSFB indicator from MSC */
984testcase TC_chan_rel_hard_clear_csfb() runs on test_CT {
985 var BSSAP_N_DATA_ind rx_di;
986 var DchanTuple dt;
987
988 f_init(1);
989
990 dt := f_est_dchan('23'O, 23, '00010203040506'O);
991
992 /* Instruct BSC to clear channel */
993 var BssmapCause cause := 0;
994 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
995
996 /* expect Clear Complete from BSC on A */
997 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
998 /* release the SCCP connection */
999 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1000 }
1001
1002 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, is_csfb := true);
1003 setverdict(pass);
1004}
1005
Harald Welted8c36cd2017-12-09 23:05:31 +01001006/* Test behavior of channel release after hard RLSD from MSC */
1007testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +01001008 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +01001009
Harald Welte89d42e82017-12-17 16:42:41 +01001010 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +01001011
1012 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1013
1014 /* release the SCCP connection */
1015 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1016
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001017 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welted8c36cd2017-12-09 23:05:31 +01001018 setverdict(pass);
1019}
1020
Harald Welte550daf92018-06-11 19:22:13 +02001021/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
1022testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
1023 var DchanTuple dt;
1024
1025 f_init(1);
1026
1027 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1028
1029 /* release the SCCP connection */
1030 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1031
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001032 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte550daf92018-06-11 19:22:13 +02001033 setverdict(pass);
1034}
1035
Harald Welte85804d42017-12-10 14:11:58 +01001036/* Test behavior of channel release after BSSMAP RESET from MSC */
1037testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +01001038 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +01001039
Harald Welte89d42e82017-12-17 16:42:41 +01001040 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +01001041
1042 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1043
1044 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
1045 IPA_RSL[0].clear;
1046
1047 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001048 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 +01001049 interleave {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001050 [] 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 +01001051 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
1052 }
1053
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001054 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte85804d42017-12-10 14:11:58 +01001055 setverdict(pass);
1056}
1057
Harald Welte5cd20ed2017-12-13 21:03:20 +01001058/* Test behavior if RSL EST IND for non-active channel */
1059testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
1060 timer T := 2.0;
1061
Harald Welte89d42e82017-12-17 16:42:41 +01001062 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001063
1064 var octetstring l3 := '00010203040506'O;
1065 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
1066 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1067
1068 T.start;
1069 alt {
1070 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1071 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
1072 }
1073 [] BSSAP.receive {}
1074 [] IPA_RSL[0].receive {}
1075 [] T.timeout {}
1076 }
1077
1078 setverdict(pass);
1079}
1080
1081/* Test behavior if RSL EST IND for invalid SAPI */
1082testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
1083 var RslChannelNr chan_nr;
1084
Harald Welte89d42e82017-12-17 16:42:41 +01001085 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001086
1087 chan_nr := f_chreq_act_ack()
1088
1089 var octetstring l3 := '00010203040506'O;
1090 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
1091
1092 timer T := 2.0;
1093 T.start;
1094 alt {
1095 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1096 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
1097 }
1098 [] BSSAP.receive { repeat; }
1099 [] IPA_RSL[0].receive { repeat; }
1100 [] T.timeout {}
1101 }
1102
1103 setverdict(pass);
1104}
1105
1106/* Test behavior if RSL EST IND for invalid SAPI */
1107testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
1108 timer T := 2.0;
1109
Harald Welte89d42e82017-12-17 16:42:41 +01001110 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001111
1112 var RslChannelNr chan_nr := f_chreq_act_ack();
1113
1114 var octetstring l3 := '00010203040506'O;
1115 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
1116
1117 T.start;
1118 alt {
1119 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1120 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
1121 }
1122 [] BSSAP.receive { repeat; }
1123 [] IPA_RSL[0].receive { repeat; }
1124 [] T.timeout {}
1125 }
1126
1127 setverdict(pass);
1128}
1129
1130/* Test behavior if RSL EST IND for invalid SACCH */
1131testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
1132 timer T := 2.0;
1133
Harald Welte89d42e82017-12-17 16:42:41 +01001134 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001135
1136 var RslChannelNr chan_nr := f_chreq_act_ack();
1137
1138 var octetstring l3 := '00010203040506'O;
1139 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
1140
1141 T.start;
1142 alt {
1143 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1144 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
1145 }
1146 [] BSSAP.receive { repeat; }
1147 [] IPA_RSL[0].receive { repeat; }
1148 [] T.timeout {}
1149 }
1150
1151 setverdict(pass);
1152}
1153
1154
1155
Harald Welte4003d112017-12-09 22:35:39 +01001156
1157testcase TC_ctrl_msc_connection_status() runs on test_CT {
1158 var charstring ctrl_resp;
1159
Harald Welte89d42e82017-12-17 16:42:41 +01001160 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001161
1162 /* See https://osmocom.org/issues/2729 */
1163 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
1164 setverdict(pass);
1165}
1166
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001167testcase TC_ctrl_msc0_connection_status() runs on test_CT {
1168 var charstring ctrl_resp;
1169
1170 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001171
1172 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
1173 setverdict(pass);
1174}
1175
Harald Welte4003d112017-12-09 22:35:39 +01001176testcase TC_ctrl() runs on test_CT {
1177 var charstring ctrl_resp;
1178
Harald Welte89d42e82017-12-17 16:42:41 +01001179 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001180
1181 /* all below values must match the osmo-bsc.cfg config file used */
1182
Harald Welte6a129692018-03-17 17:30:14 +01001183 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
1184 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Harald Welte44bdaa52017-12-17 17:01:47 +01001185 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "3");
Harald Welte4003d112017-12-09 22:35:39 +01001186
1187 var integer bts_nr := 0;
1188 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
1189 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
1190 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
1191 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
1192 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
1193 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
1194 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
1195
1196 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
1197 f_sleep(2.0);
1198 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
1199 setverdict(fail, "oml-uptime not incrementing as expected");
1200 }
1201 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
1202
1203 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
1204
1205 setverdict(pass);
Harald Welte96c94412017-12-09 03:12:45 +01001206}
1207
Harald Welte6f521d82017-12-11 19:52:02 +01001208function f_bssap_tx_ud(template PDU_BSSAP bssap) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +01001209 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, bssap));
Harald Welte6f521d82017-12-11 19:52:02 +01001210}
1211
1212
1213/***********************************************************************
1214 * Paging Testing
1215 ***********************************************************************/
1216
1217type record Cell_Identity {
1218 GsmMcc mcc,
1219 GsmMnc mnc,
1220 GsmLac lac,
1221 GsmCellId ci
1222};
Harald Welte24135bd2018-03-17 19:27:53 +01001223private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01001224private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01001225
Harald Welte5d1a2202017-12-13 19:51:29 +01001226type set of integer BtsIdList;
1227
1228private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
1229 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
1230 if (bts_id == bts_ids[j]) {
1231 return true;
1232 }
1233 }
1234 return false;
1235}
Harald Welte6f521d82017-12-11 19:52:02 +01001236
1237/* core paging test helper function; used by most paging test cases */
1238private function f_pageing_helper(hexstring imsi,
1239 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01001240 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01001241 template RSL_ChanNeeded rsl_chneed := omit,
1242 template OCT4 tmsi := omit) runs on test_CT
1243{
1244 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
1245 var MobileIdentity mi;
1246 var template octetstring id_enc; /* FIXME */
1247 var RSL_Message rx_rsl;
1248 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01001249 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01001250
1251 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01001252
1253 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01001254 for (i := 0; i < NUM_BTS; i := i + 1) {
1255 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01001256 }
Harald Welte6f521d82017-12-11 19:52:02 +01001257
1258 if (isvalue(rsl_chneed)) {
1259 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
1260 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
1261 } else {
1262 bssmap_chneed := omit;
1263 }
1264
1265 f_bssap_tx_ud(ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed));
1266
1267/* FIXME: Disabled due to bugs in both GSM_RR_Types and MobileL3_CommonIE_Types IMSI encoder
1268 if (isvalue(tmsi)) {
1269 mi := valueof(t_Osmo_MI_TMSI(oct2int(valueof(tmsi))));
1270 } else {
1271 mi := valueof(ts_Osmo_MI_IMSI(imsi));
1272 }
1273 id_enc := enc_MobileIdentity(mi);
1274*/
1275 id_enc := ?;
Harald Welte5d1a2202017-12-13 19:51:29 +01001276 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
1277 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(id_enc));
1278 /* check channel type, paging group */
1279 if (rx_rsl.ies[1].body.paging_group != paging_group) {
1280 setverdict(fail, "Paging for wrong paging group");
1281 }
1282 if (ispresent(rsl_chneed) and
1283 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
1284 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
1285 }
Harald Welte6f521d82017-12-11 19:52:02 +01001286 }
Harald Welte2fccd982018-01-31 15:48:19 +01001287 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01001288 /* do a quick check on all not-included BTSs if they received paging */
1289 for (i := 0; i < NUM_BTS; i := i + 1) {
1290 timer T := 0.1;
1291 if (f_bts_in_list(i, bts_ids)) {
1292 continue;
1293 }
1294 T.start;
1295 alt {
1296 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(id_enc))) {
1297 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
1298 }
1299 [] IPA_RSL[i].receive { repeat; }
1300 [] T.timeout { }
1301 }
Harald Welte6f521d82017-12-11 19:52:02 +01001302 }
1303
1304 setverdict(pass);
1305}
1306
Harald Welte5d1a2202017-12-13 19:51:29 +01001307const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01001308const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01001309const BtsIdList c_BtsId_LAC1 := { 0, 1 };
1310const BtsIdList c_BtsId_LAC2 := { 2 };
1311
Harald Welte6f521d82017-12-11 19:52:02 +01001312/* PAGING by IMSI + TMSI */
1313testcase TC_paging_imsi_nochan() runs on test_CT {
1314 var BSSMAP_FIELD_CellIdentificationList cid_list;
1315 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01001316 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001317 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001318}
1319
1320/* PAGING by IMSI + TMSI */
1321testcase TC_paging_tmsi_nochan() runs on test_CT {
1322 var BSSMAP_FIELD_CellIdentificationList cid_list;
1323 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001324 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001325 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001326}
1327
1328/* Paging with different "channel needed' values */
1329testcase TC_paging_tmsi_any() runs on test_CT {
1330 var BSSMAP_FIELD_CellIdentificationList cid_list;
1331 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001332 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001333 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001334}
1335testcase TC_paging_tmsi_sdcch() runs on test_CT {
1336 var BSSMAP_FIELD_CellIdentificationList cid_list;
1337 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001338 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001339 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001340}
1341testcase TC_paging_tmsi_tch_f() runs on test_CT {
1342 var BSSMAP_FIELD_CellIdentificationList cid_list;
1343 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001344 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001345 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001346}
1347testcase TC_paging_tmsi_tch_hf() runs on test_CT {
1348 var BSSMAP_FIELD_CellIdentificationList cid_list;
1349 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001350 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001351 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001352}
1353
1354/* Paging by CGI */
1355testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
1356 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1357 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001358 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001359 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001360}
1361
1362/* Paging by LAC+CI */
1363testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
1364 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1365 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001366 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001367 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001368}
1369
1370/* Paging by CI */
1371testcase TC_paging_imsi_nochan_ci() runs on test_CT {
1372 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1373 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001374 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001375 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001376}
1377
1378/* Paging by LAI */
1379testcase TC_paging_imsi_nochan_lai() runs on test_CT {
1380 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1381 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001382 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001383 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001384}
1385
1386/* Paging by LAC */
1387testcase TC_paging_imsi_nochan_lac() runs on test_CT {
1388 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1389 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001390 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001391 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001392}
1393
1394/* Paging by "all in BSS" */
1395testcase TC_paging_imsi_nochan_all() runs on test_CT {
1396 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1397 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01001398 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001399 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001400}
1401
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001402/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001403testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
1404 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1405 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 +01001406 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001407 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001408}
Harald Welte6f521d82017-12-11 19:52:02 +01001409
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001410/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001411testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
1412 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1413 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001414 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001415 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001416}
1417
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001418/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001419testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
1420 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1421 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001422 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001423 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001424}
1425
Harald Welte6f521d82017-12-11 19:52:02 +01001426/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01001427testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
1428 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1429 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
1430 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001431 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001432}
1433
1434/* Paging on empty list: Verify none of them page */
1435testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
1436 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1437 cid_list := { cIl_LAC := { } };
1438 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001439 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001440}
1441
Stefan Sperling049a86e2018-03-20 15:51:00 +01001442/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
1443testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
1444 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1445 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
1446 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
1447 f_shutdown_helper();
1448}
1449
Harald Welte6f521d82017-12-11 19:52:02 +01001450/* Verify paging retransmission interval + count */
1451/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01001452/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01001453
Harald Weltee65d40e2017-12-13 00:09:06 +01001454/* Verify PCH load */
1455testcase TC_paging_imsi_load() runs on test_CT {
1456 var BSSMAP_FIELD_CellIdentificationList cid_list;
1457 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01001458 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01001459 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001460 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01001461
1462 /* tell BSC there is no paging space anymore */
1463 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01001464 f_sleep(0.2);
1465 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01001466
1467 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
1468 * there would be 8 retransmissions during 4 seconds */
1469 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01001470 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01001471 alt {
1472 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1473 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02001474 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01001475 }
Harald Welte2caa1062018-03-17 18:19:05 +01001476 [] T_retrans.timeout {
1477 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
1478 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
1479 T_retrans.start;
1480 repeat;
1481 }
Harald Weltee65d40e2017-12-13 00:09:06 +01001482 [] T.timeout {
1483 setverdict(pass);
1484 }
1485 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001486
1487 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01001488}
1489
Harald Welte235ebf12017-12-15 14:18:16 +01001490/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01001491testcase TC_paging_counter() runs on test_CT {
1492 var BSSMAP_FIELD_CellIdentificationList cid_list;
1493 timer T := 4.0;
1494 var integer i;
1495 var integer paging_attempted_bsc;
1496 var integer paging_attempted_bts[NUM_BTS];
1497 var integer paging_expired_bts[NUM_BTS];
1498 cid_list := valueof(ts_BSSMAP_CIL_noCell);
1499
1500 f_init();
1501
1502 /* read counters before paging */
1503 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
1504 for (i := 0; i < NUM_BTS; i := i+1) {
1505 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
1506 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
1507 }
1508
1509 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
1510
1511 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
1512 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
1513 for (i := 0; i < NUM_BTS; i := i+1) {
1514 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
1515 paging_attempted_bts[i]+1);
1516 }
1517
1518 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
1519 f_sleep(12.0);
1520 for (i := 0; i < NUM_BTS; i := i+1) {
1521 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
1522 paging_expired_bts[i]+1);
1523 }
Harald Welte1ff69992017-12-14 12:31:17 +01001524
Philipp Maier282ca4b2018-02-27 17:17:00 +01001525 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01001526}
1527
1528
Harald Welte10985002017-12-12 09:29:15 +01001529/* Verify paging stops after A-RESET */
1530testcase TC_paging_imsi_a_reset() runs on test_CT {
1531 var BSSMAP_FIELD_CellIdentificationList cid_list;
1532 timer T := 3.0;
1533 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001534 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01001535
1536 /* Perform a BSSMAP Reset and wait for ACK */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001537 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 +01001538 alt {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001539 [] 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 +01001540 [] BSSAP.receive { repeat; }
1541 }
1542
Daniel Willmanncbef3982018-07-30 09:22:40 +02001543 /* Wait to avoid a possible race condition if a paging message is
1544 * received right before the reset ACK. */
1545 f_sleep(0.2);
1546
Harald Welte10985002017-12-12 09:29:15 +01001547 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01001548 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
1549 IPA_RSL[i].clear;
1550 }
Harald Welte10985002017-12-12 09:29:15 +01001551
1552 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
1553 T.start;
1554 alt {
1555 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1556 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001557 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01001558 }
Harald Welte5d1a2202017-12-13 19:51:29 +01001559 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1560 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001561 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001562 }
1563 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1564 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001565 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001566 }
Harald Welte10985002017-12-12 09:29:15 +01001567 [] T.timeout {
1568 setverdict(pass);
1569 }
1570 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001571
1572 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01001573}
Harald Welteae026692017-12-09 01:03:01 +01001574
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001575/* Verify how we handle unsolicited Paging Response, for instance because we
1576 * receive a Paging Response after T3113 expired (and subscriber information was
1577 * dropped). See OS#3680.
1578 */
1579testcase TC_paging_resp_unsol() runs on test_CT {
1580
1581 f_init(1);
1582
1583 var BSSAP_N_CONNECT_ind rx_c_ind;
1584 var DchanTuple dt;
1585 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
1586
1587 /* Send CHAN RQD and wait for allocation; acknowledge it */
1588 dt.rsl_chan_nr := f_chreq_act_ack();
1589
1590 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
1591 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
1592
1593 /* expect BSC to disable the channel */
Pau Espin Pedrol5ee6f6c2018-12-07 12:07:43 +01001594 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001595 setverdict(pass);
1596
1597}
1598
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001599/* Test RSL link drop causes counter increment */
1600testcase TC_rsl_drop_counter() runs on test_CT {
1601 var integer rsl_fail;
1602
Harald Welte89d42e82017-12-17 16:42:41 +01001603 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001604
1605 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
1606
1607 bts[0].rsl.vc_IPA.stop;
1608
1609 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
1610
1611 setverdict(pass);
1612}
1613
1614/* TODO: Test OML link drop causes counter increment */
1615
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001616/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
1617function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
1618 timer T := 10.0;
1619
1620 bts[0].rsl.id := "IPA-0-RSL";
1621 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
1622 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
1623 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
1624 bts[0].rsl.ccm_pars.unit_id := "0/0/0"; /* value which is unknown at BTS */
1625
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001626 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
1627
1628 f_init_mgcp("VirtMSC");
1629
1630 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
1631 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
1632 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
1633 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
1634
1635 /* wait for IPA OML link to connect and then disconnect */
1636 T.start;
1637 alt {
1638 [] IPA_RSL[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) {
1639 T.stop;
1640 return true;
1641 }
1642 [] IPA_RSL[0].receive { repeat }
1643 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02001644 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001645 }
1646 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001647 return false;
1648}
1649
1650/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1651testcase TC_rsl_unknown_unit_id() runs on test_CT {
1652 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
1653 setverdict(pass);
1654 } else {
1655 setverdict(fail, "Timeout RSL waiting for connection to close");
1656 }
1657}
1658
1659
1660/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1661testcase TC_oml_unknown_unit_id() runs on test_CT {
1662 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
1663 setverdict(pass);
1664 } else {
1665 setverdict(fail, "Timeout OML waiting for connection to close");
1666 }
1667}
1668
1669
Harald Weltec1a2fff2017-12-17 11:06:19 +01001670/***********************************************************************
Harald Welte6811d102019-04-14 22:23:14 +02001671 * "New world" test cases using RSL_Emulation + RAN_Emulation
Harald Weltec1a2fff2017-12-17 11:06:19 +01001672 ***********************************************************************/
1673
Harald Welte6811d102019-04-14 22:23:14 +02001674import from RAN_Emulation all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01001675import from RSL_Emulation all;
1676import from MSC_ConnectionHandler all;
1677
1678type function void_fn(charstring id) runs on MSC_ConnHdlr;
1679
Harald Welte336820c2018-05-31 20:34:52 +02001680/* helper function to create and connect a MSC_ConnHdlr component */
Harald Welteff579f92018-05-31 22:19:39 +02001681private function f_connect_handler(inout MSC_ConnHdlr vc_conn) runs on test_CT {
Harald Welte6811d102019-04-14 22:23:14 +02001682 connect(vc_conn:RAN, g_bssap.vc_RAN:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001683 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001684 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01001685 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01001686 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01001687 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
1688 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
1689 }
Harald Welte6811d102019-04-14 22:23:14 +02001690 connect(vc_conn:BSSAP, g_bssap.vc_RAN:CLIENT);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001691 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Harald Welte336820c2018-05-31 20:34:52 +02001692}
1693
1694function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
1695runs on test_CT return MSC_ConnHdlr {
1696 var charstring id := testcasename();
1697 var MSC_ConnHdlr vc_conn;
1698 vc_conn := MSC_ConnHdlr.create(id);
1699 f_connect_handler(vc_conn);
Harald Weltea0630032018-03-20 21:09:55 +01001700 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001701 return vc_conn;
1702}
1703
Harald Weltea0630032018-03-20 21:09:55 +01001704/* first function inside ConnHdlr component; sets g_pars + starts function */
1705private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
1706runs on MSC_ConnHdlr {
1707 if (isvalue(pars)) {
1708 g_pars := valueof(pars);
1709 }
1710 fn.apply(id);
1711}
1712
Harald Welte3c86ea02018-05-10 22:28:05 +02001713/* Establish signalling channel (non-assignment case) followed by cipher mode */
1714private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001715 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1716 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02001717 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02001718 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
1719 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
1720 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
1721 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02001722
Philipp Maier23000732018-05-18 11:25:37 +02001723 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02001724}
1725testcase TC_ciph_mode_a5_0() runs on test_CT {
1726 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001727 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001728 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
1729
1730 f_init(1, true);
1731 f_sleep(1.0);
1732 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1733 vc_conn.done;
1734}
1735testcase TC_ciph_mode_a5_1() runs on test_CT {
1736 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001737 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001738 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
1739
1740 f_init(1, true);
1741 f_sleep(1.0);
1742 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1743 vc_conn.done;
1744}
1745testcase TC_ciph_mode_a5_3() runs on test_CT {
1746 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001747 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001748 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
1749
1750 f_init(1, true);
1751 f_sleep(1.0);
1752 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1753 vc_conn.done;
1754}
1755
1756
1757/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02001758private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001759 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1760 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01001761
Harald Welte552620d2017-12-16 23:21:36 +01001762 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1763 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01001764
Harald Weltea0630032018-03-20 21:09:55 +01001765 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01001766}
Harald Welte552620d2017-12-16 23:21:36 +01001767testcase TC_assignment_fr_a5_0() runs on test_CT {
1768 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001769 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001770 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01001771
Harald Welte89d42e82017-12-17 16:42:41 +01001772 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001773 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001774 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01001775 vc_conn.done;
1776}
Harald Welte552620d2017-12-16 23:21:36 +01001777testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01001778 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001779 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001780 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001781
Harald Welte89d42e82017-12-17 16:42:41 +01001782 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001783 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001784 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
1785 vc_conn.done;
1786}
1787testcase TC_assignment_fr_a5_3() runs on test_CT {
1788 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001789 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001790 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001791
Harald Welte651fcdc2018-05-10 20:23:16 +02001792 f_init(1, true);
1793 f_sleep(1.0);
1794 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001795 vc_conn.done;
1796}
1797
Harald Welte552620d2017-12-16 23:21:36 +01001798/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
1799private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001800 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01001801 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001802 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001803 const OCT8 kc := '0001020304050607'O;
1804
1805 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001806 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
1807
Harald Weltea0630032018-03-20 21:09:55 +01001808 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01001809}
Harald Welte552620d2017-12-16 23:21:36 +01001810testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
1811 var MSC_ConnHdlr vc_conn;
1812
Harald Welte89d42e82017-12-17 16:42:41 +01001813 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001814 f_sleep(1.0);
1815
Harald Welte8863fa12018-05-10 20:15:27 +02001816 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01001817 vc_conn.done;
1818}
1819
Harald Welte552620d2017-12-16 23:21:36 +01001820private function f_tc_assignment_fr_a5_4(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001821 g_pars := f_gen_test_hdlr_pars();
Harald Welteed848512018-05-24 22:27:58 +02001822 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1823 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001824 const OCT8 kc := '0001020304050607'O;
1825 const OCT16 kc128 := kc & kc;
1826
1827 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1828 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Weltea0630032018-03-20 21:09:55 +01001829 f_establish_fully(ass_cmd, exp_compl);
Harald Welte38b2a102017-12-23 02:42:58 +01001830 f_cipher_mode('10'O, kc, kc128, true);
Harald Welte552620d2017-12-16 23:21:36 +01001831 /* TODO: expect GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED cause value */
Harald Welte552620d2017-12-16 23:21:36 +01001832}
Harald Welte552620d2017-12-16 23:21:36 +01001833testcase TC_assignment_fr_a5_4() runs on test_CT {
1834 var MSC_ConnHdlr vc_conn;
1835
Harald Welte89d42e82017-12-17 16:42:41 +01001836 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001837 f_sleep(1.0);
1838
Harald Welte8863fa12018-05-10 20:15:27 +02001839 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_4));
Harald Welte552620d2017-12-16 23:21:36 +01001840 vc_conn.done;
1841}
1842
1843
Harald Welte4532e0a2017-12-23 02:05:44 +01001844private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001845 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01001846 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02001847 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01001848 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Harald Weltea0630032018-03-20 21:09:55 +01001849 f_establish_fully(ass_cmd, exp_compl);
Harald Welte4532e0a2017-12-23 02:05:44 +01001850}
1851
1852testcase TC_assignment_sign() runs on test_CT {
1853 var MSC_ConnHdlr vc_conn;
1854
1855 f_init(1, true);
1856 f_sleep(1.0);
1857
Harald Welte8863fa12018-05-10 20:15:27 +02001858 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01001859 vc_conn.done;
1860}
1861
Harald Welte60aa5762018-03-21 19:33:13 +01001862/***********************************************************************
1863 * Codec (list) testing
1864 ***********************************************************************/
1865
1866/* check if the given rsl_mode is compatible with the a_elem */
1867private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
1868return boolean {
1869 select (a_elem.codecType) {
1870 case (GSM_FR) {
1871 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
1872 return true;
1873 }
1874 }
1875 case (GSM_HR) {
1876 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
1877 return true;
1878 }
1879 }
1880 case (GSM_EFR) {
1881 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
1882 return true;
1883 }
1884 }
1885 case (FR_AMR) {
1886 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
1887 return true;
1888 }
1889 }
1890 case (HR_AMR) {
1891 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
1892 return true;
1893 }
1894 }
1895 case else { }
1896 }
1897 return false;
1898}
1899
1900/* check if the given rsl_mode is compatible with the a_list */
1901private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
1902return boolean {
1903 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
1904 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
1905 return true;
1906 }
1907 }
1908 return false;
1909}
1910
1911/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02001912function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01001913return BSSMAP_IE_ChannelType {
1914 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
1915 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
1916 select (a_elem.codecType) {
1917 case (GSM_FR) {
1918 ret.channelRateAndType := ChRate_TCHF;
1919 ret.speechId_DataIndicator := Spdi_TCHF_FR;
1920 }
1921 case (GSM_HR) {
1922 ret.channelRateAndType := ChRate_TCHH;
1923 ret.speechId_DataIndicator := Spdi_TCHH_HR;
1924 }
1925 case (GSM_EFR) {
1926 ret.channelRateAndType := ChRate_TCHF;
1927 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
1928 }
1929 case (FR_AMR) {
1930 ret.channelRateAndType := ChRate_TCHF;
1931 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
1932 }
1933 case (HR_AMR) {
1934 ret.channelRateAndType := ChRate_TCHH;
1935 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
1936 }
1937 case else {
1938 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02001939 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01001940 }
1941 }
1942 return ret;
1943}
1944
Harald Weltea63b9102018-03-22 20:36:16 +01001945private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
1946return template RSL_IE_Body {
1947 var template RSL_IE_Body mode_ie := {
1948 chan_mode := {
1949 len := ?,
1950 reserved := ?,
1951 dtx_d := ?,
1952 dtx_u := ?,
1953 spd_ind := RSL_SPDI_SPEECH,
1954 ch_rate_type := -,
1955 coding_alg_rate := -
1956 }
1957 }
1958
1959 select (a_elem.codecType) {
1960 case (GSM_FR) {
1961 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1962 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1963 }
1964 case (GSM_HR) {
1965 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1966 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1967 }
1968 case (GSM_EFR) {
1969 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1970 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
1971 }
1972 case (FR_AMR) {
1973 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1974 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1975 }
1976 case (HR_AMR) {
1977 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1978 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1979 }
1980 }
1981 return mode_ie;
1982}
1983
Harald Welte60aa5762018-03-21 19:33:13 +01001984type record CodecListTest {
1985 BSSMAP_IE_SpeechCodecList codec_list,
1986 charstring id
1987}
1988type record of CodecListTest CodecListTests
1989
1990private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001991 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
1992 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
Harald Welte60aa5762018-03-21 19:33:13 +01001993
1994 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Harald Welte79f3f542018-05-25 20:02:37 +02001995 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
1996 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
1997 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
1998 g_pars.ass_codec_list.codecElements[0];
Philipp Maierd0e64b02019-03-13 14:15:23 +01001999 if (isvalue(g_pars.expect_mr_s0_s7)) {
2000 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
2001 g_pars.expect_mr_s0_s7;
2002 }
Harald Welte79f3f542018-05-25 20:02:37 +02002003 }
Harald Welte60aa5762018-03-21 19:33:13 +01002004 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
2005 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01002006 log("expecting ASS COMPL like this: ", exp_compl);
2007
2008 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01002009
2010 /* Verify that the RSL-side activation actually matches our expectations */
2011 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
2012
2013 var RSL_IE_Body mode_ie;
2014 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
2015 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02002016 mtc.stop;
Harald Weltea63b9102018-03-22 20:36:16 +01002017 }
2018 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
2019 if (not match(mode_ie, t_mode_ie)) {
2020 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
2021 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002022
2023 var RSL_IE_Body mr_conf;
2024 if (g_pars.expect_mr_conf_ie != omit) {
2025 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
2026 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
Daniel Willmannafce8662018-07-06 23:11:32 +02002027 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002028 }
2029 log("found RSL MR CONFIG IE: ", mr_conf);
2030
2031 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
2032 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
2033 g_pars.expect_mr_conf_ie);
2034 }
2035 } else {
2036 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
2037 log("found RSL MR CONFIG IE: ", mr_conf);
2038 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
Daniel Willmannafce8662018-07-06 23:11:32 +02002039 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002040 }
2041 }
Harald Welte60aa5762018-03-21 19:33:13 +01002042}
2043
Philipp Maierd0e64b02019-03-13 14:15:23 +01002044private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
2045
2046 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2047 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2048
2049 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
2050 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
2051 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
2052 }
2053 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
2054 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
2055 log("expecting ASS FAIL like this: ", exp_fail);
2056
2057 f_establish_fully(ass_cmd, exp_fail);
2058}
2059
Harald Welte60aa5762018-03-21 19:33:13 +01002060testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002061 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002062 var MSC_ConnHdlr vc_conn;
2063
2064 f_init(1, true);
2065 f_sleep(1.0);
2066
2067 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002068 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002069 vc_conn.done;
2070}
2071
2072testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002073 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002074 var MSC_ConnHdlr vc_conn;
2075
2076 f_init(1, true);
2077 f_sleep(1.0);
2078
2079 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002080 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002081 vc_conn.done;
2082}
2083
2084testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002085 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002086 var MSC_ConnHdlr vc_conn;
2087
2088 f_init(1, true);
2089 f_sleep(1.0);
2090
2091 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002092 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002093 vc_conn.done;
2094}
2095
Philipp Maierd0e64b02019-03-13 14:15:23 +01002096/* Allow 5,90k only (current default config) */
2097private function f_allow_amr_rate_5_90k() runs on test_CT {
2098 f_vty_enter_cfg_msc(BSCVTY, 0);
2099 f_vty_transceive(BSCVTY, "amr-config 12_2k forbidden");
2100 f_vty_transceive(BSCVTY, "amr-config 10_2k forbidden");
2101 f_vty_transceive(BSCVTY, "amr-config 7_95k forbidden");
2102 f_vty_transceive(BSCVTY, "amr-config 7_40k forbidden");
2103 f_vty_transceive(BSCVTY, "amr-config 6_70k forbidden");
2104 f_vty_transceive(BSCVTY, "amr-config 5_90k allowed");
2105 f_vty_transceive(BSCVTY, "amr-config 5_15k forbidden");
2106 f_vty_transceive(BSCVTY, "amr-config 4_75k forbidden");
2107 f_vty_transceive(BSCVTY, "exit");
2108 f_vty_transceive(BSCVTY, "exit");
2109}
2110
2111/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
2112 * ("Config-NB-Code = 1") */
2113private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
2114 f_vty_enter_cfg_msc(BSCVTY, 0);
2115 f_vty_transceive(BSCVTY, "amr-config 12_2k allowed");
2116 f_vty_transceive(BSCVTY, "amr-config 10_2k forbidden");
2117 f_vty_transceive(BSCVTY, "amr-config 7_95k forbidden");
2118 f_vty_transceive(BSCVTY, "amr-config 7_40k allowed");
2119 f_vty_transceive(BSCVTY, "amr-config 6_70k forbidden");
2120 f_vty_transceive(BSCVTY, "amr-config 5_90k allowed");
2121 f_vty_transceive(BSCVTY, "amr-config 5_15k forbidden");
2122 f_vty_transceive(BSCVTY, "amr-config 4_75k allowed");
2123 f_vty_transceive(BSCVTY, "exit");
2124 f_vty_transceive(BSCVTY, "exit");
2125}
2126
Harald Welte60aa5762018-03-21 19:33:13 +01002127testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002128 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002129 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02002130
2131 /* Note: This setups the codec configuration. The parameter payload in
2132 * mr_conf must be consistant with the parameter codecElements in pars
2133 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002134 var RSL_IE_Body mr_conf := {
2135 other := {
2136 len := 2,
2137 payload := '2804'O
2138 }
2139 };
Harald Welte60aa5762018-03-21 19:33:13 +01002140
Philipp Maier7695a0d2018-09-27 17:52:14 +02002141 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Philipp Maier806f8f12019-03-12 12:13:41 +01002142 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02002143 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
2144 pars.expect_mr_conf_ie := mr_conf;
2145
Harald Welte60aa5762018-03-21 19:33:13 +01002146 f_init(1, true);
2147 f_sleep(1.0);
2148
Harald Welte8863fa12018-05-10 20:15:27 +02002149 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002150 vc_conn.done;
2151}
2152
2153testcase TC_assignment_codec_amr_h() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002154 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002155 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02002156
2157 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002158 var RSL_IE_Body mr_conf := {
2159 other := {
2160 len := 2,
2161 payload := '2804'O
2162 }
2163 };
Harald Welte60aa5762018-03-21 19:33:13 +01002164
Philipp Maier7695a0d2018-09-27 17:52:14 +02002165 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Philipp Maier806f8f12019-03-12 12:13:41 +01002166 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02002167 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2168 pars.expect_mr_conf_ie := mr_conf;
2169
Harald Welte60aa5762018-03-21 19:33:13 +01002170 f_init(1, true);
2171 f_sleep(1.0);
2172
Harald Welte8863fa12018-05-10 20:15:27 +02002173 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002174 vc_conn.done;
2175}
2176
Philipp Maierd0e64b02019-03-13 14:15:23 +01002177function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0)
2178runs on test_CT {
2179
2180 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2181 var MSC_ConnHdlr vc_conn;
2182
2183 /* See note above */
2184 var RSL_IE_Body mr_conf := {
2185 other := {
2186 len := lengthof(mrconf),
2187 payload := mrconf
2188 }
2189 };
2190
2191 if (fr) {
2192 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
2193 } else {
2194 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2195 }
2196 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
2197 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2198 pars.expect_mr_conf_ie := mr_conf;
2199 pars.expect_mr_s0_s7 := exp_s8_s0;
2200
2201 f_init(1, true);
2202 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
2203 f_sleep(1.0);
2204
2205 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
2206 vc_conn.done;
2207 f_allow_amr_rate_5_90k();
2208}
2209
2210function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
2211runs on test_CT {
2212
2213 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2214 var MSC_ConnHdlr vc_conn;
2215
2216 if (fr) {
2217 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
2218 } else {
2219 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2220 }
2221 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
2222 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2223
2224 f_init(1, true);
2225 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
2226 f_sleep(1.0);
2227
2228 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
2229 vc_conn.done;
2230 f_allow_amr_rate_5_90k();
2231}
2232
2233
2234/* Set S1, we expect an AMR multirate configuration IE with all four rates
2235 * set. */
2236testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
2237 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
2238}
2239
2240/* Set S1, we expect an AMR multirate configuration IE with the lower three
2241 * rates set. */
2242testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
2243 f_TC_assignment_codec_amr(false, '2815208820'O, '00000010'B, '00000010'B);
2244}
2245
2246/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
2247 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
2248testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
2249 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'B, '00000010'B);
2250}
2251
2252/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
2253 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
2254testcase TC_assignment_codec_amr_h_S124() runs on test_CT {
2255 f_TC_assignment_codec_amr(false, '2815208820'O, '00010110'B, '00000010'B);
2256}
2257
2258/* The following block of tests selects more and more rates until all four
2259 * possible rates are in the active set (full rate) */
2260testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
2261 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'B);
2262}
2263
2264testcase TC_assignment_codec_amr_f_S02() runs on test_CT {
2265 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'B);
2266}
2267
2268testcase TC_assignment_codec_amr_f_S024() runs on test_CT {
2269 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'B);
2270}
2271
2272testcase TC_assignment_codec_amr_f_S0247() runs on test_CT {
2273 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
2274}
2275
2276/* The following block of tests selects more and more rates until all three
2277 * possible rates are in the active set (half rate) */
2278testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
2279 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'B);
2280}
2281
2282testcase TC_assignment_codec_amr_h_S02() runs on test_CT {
2283 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
2284}
2285
2286testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
2287 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
2288}
2289
2290/* The following block tests what happens when the MSC does offer rate
2291 * configurations that are not supported by the BSC. Normally such situations
2292 * should not happen because the MSC gets informed by the BSC in advance via
2293 * the L3 COMPLETE message which rates are applicable. The MSC should not try
2294 * to offer rates that are not applicable anyway. */
2295
2296testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
2297 /* Try to include 12,2k in into the active set even though the channel
2298 * is half rate only. The BSC is expected to remove the 12,0k */
2299 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'B);
2300}
2301
2302testcase TC_assignment_codec_amr_f_S01234567() runs on test_CT {
2303 /* See what happens when all rates are selected at once. Since then
2304 * Also S1 is selected, this setting will be prefered and we should
2305 * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
2306 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
2307}
2308
2309testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
2310 /* Same as above, but with S1 missing, the MSC is then expected to
2311 * select the currently supported rates, which are also 12.2k, 7,40k,
2312 * 5,90k, and 4,75k, into the active set. */
2313 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'B);
2314}
2315
2316testcase TC_assignment_codec_amr_f_zero() runs on test_CT {
2317 /* Try to select no rates at all */
2318 f_TC_assignment_codec_amr_fail(true, '00000000'B);
2319}
2320
2321testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
2322 /* Try to select only unsupported rates */
2323 f_TC_assignment_codec_amr_fail(true, '01101000'B);
2324}
2325
2326testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
2327 /* Try to select 12,2k for half rate */
2328 f_TC_assignment_codec_amr_fail(false, '10000000'B);
2329}
2330
Philipp Maierac09bfc2019-01-08 13:41:39 +01002331private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002332 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
2333 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
2334 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
2335 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002336}
2337
2338private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002339 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
2340 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002341}
2342
2343private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002344 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
2345 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
2346 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
2347 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
2348 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
2349 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002350}
2351
2352/* Allow HR only */
2353private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
2354 g_pars := f_gen_test_hdlr_pars();
2355 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2356 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2357 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2358 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
2359 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
2360 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
2361 f_establish_fully(ass_cmd, exp_compl);
2362}
2363
2364/* Allow FR only */
2365private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
2366 g_pars := f_gen_test_hdlr_pars();
2367 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2368 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2369 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2370 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
2371 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
2372 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2373 f_establish_fully(ass_cmd, exp_compl);
2374}
2375
2376/* Allow HR only (expect assignment failure) */
2377private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
2378 g_pars := f_gen_test_hdlr_pars();
2379 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2380 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2381 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2382 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
2383 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
2384 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
2385 f_establish_fully(ass_cmd, exp_fail);
2386}
2387
2388/* Allow FR only (expect assignment failure) */
2389private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(charstring id) runs on MSC_ConnHdlr {
2390 g_pars := f_gen_test_hdlr_pars();
2391 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2392 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2393 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2394 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
2395 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
2396 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2397 f_establish_fully(ass_cmd, exp_fail);
2398}
2399
2400/* Allow FR and HR, but prefer FR */
2401private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2402 g_pars := f_gen_test_hdlr_pars();
2403 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2404 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2405 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2406 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2407 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2408 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2409 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2410 f_establish_fully(ass_cmd, exp_compl);
2411}
2412
2413/* Allow FR and HR, but prefer HR */
2414private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2415 g_pars := f_gen_test_hdlr_pars();
2416 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2417 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2418 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2419 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2420 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2421 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2422 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2423 f_establish_fully(ass_cmd, exp_compl);
2424}
2425
2426/* Allow FR and HR, but prefer FR */
2427private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2428 g_pars := f_gen_test_hdlr_pars();
2429 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2430 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2431 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2432 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2433 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2434 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2435 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2436 f_establish_fully(ass_cmd, exp_compl);
2437}
2438
2439/* Allow FR and HR, but prefer HR */
2440private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2441 g_pars := f_gen_test_hdlr_pars();
2442 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2443 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2444 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2445 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2446 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2447 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2448 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2449 f_establish_fully(ass_cmd, exp_compl);
2450}
2451
2452/* Request a HR channel while all FR channels are exhausted, this is expected
2453 * to work without conflicts */
2454testcase TC_assignment_codec_fr_exhausted_req_hr() runs on test_CT {
2455 var MSC_ConnHdlr vc_conn;
2456 f_init(1, true);
2457 f_sleep(1.0);
2458 f_enable_all_tch();
2459 f_disable_all_tch_f();
2460 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr));
2461 vc_conn.done;
2462 f_enable_all_tch();
2463 setverdict(pass);
2464}
2465
2466/* Request a FR channel while all FR channels are exhausted, this is expected
2467 * to fail. */
2468testcase TC_assignment_codec_fr_exhausted_req_fr() runs on test_CT {
2469 var MSC_ConnHdlr vc_conn;
2470 f_init(1, true);
2471 f_sleep(1.0);
2472 f_enable_all_tch();
2473 f_disable_all_tch_f();
2474 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr_fail));
2475 vc_conn.done;
2476 f_enable_all_tch();
2477 setverdict(pass);
2478}
2479
2480/* Request a FR (prefered) or alternatively a HR channel while all FR channels
2481 * are exhausted, this is expected to be resolved by selecting a HR channel. */
2482testcase TC_assignment_codec_fr_exhausted_req_fr_hr() runs on test_CT {
2483 var MSC_ConnHdlr vc_conn;
2484 f_init(1, true);
2485 f_sleep(1.0);
2486 f_enable_all_tch();
2487 f_disable_all_tch_f();
2488 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
2489 vc_conn.done;
2490 f_enable_all_tch();
2491 setverdict(pass);
2492}
2493
2494/* Request a HR (prefered) or alternatively a FR channel while all FR channels
2495 * are exhausted, this is expected to work without conflicts. */
2496testcase TC_assignment_codec_fr_exhausted_req_hr_fr() runs on test_CT {
2497 var MSC_ConnHdlr vc_conn;
2498 f_init(1, true);
2499 f_sleep(1.0);
2500 f_enable_all_tch();
2501 f_disable_all_tch_f();
2502 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_hr_fr));
2503 vc_conn.done;
2504 f_enable_all_tch();
2505 setverdict(pass);
2506}
2507
2508/* Request a FR channel while all HR channels are exhausted, this is expected
2509 * to work without conflicts */
2510testcase TC_assignment_codec_hr_exhausted_req_fr() runs on test_CT {
2511 var MSC_ConnHdlr vc_conn;
2512 f_init(1, true);
2513 f_sleep(1.0);
2514 f_enable_all_tch();
2515 f_disable_all_tch_h();
2516 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr));
2517 vc_conn.done;
2518 f_enable_all_tch();
2519 setverdict(pass);
2520}
2521
2522/* Request a HR channel while all HR channels are exhausted, this is expected
2523 * to fail. */
2524testcase TC_assignment_codec_hr_exhausted_req_hr() runs on test_CT {
2525 var MSC_ConnHdlr vc_conn;
2526 f_init(1, true);
2527 f_sleep(1.0);
2528 f_enable_all_tch();
2529 f_disable_all_tch_h();
2530 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr_fail));
2531 vc_conn.done;
2532 f_enable_all_tch();
2533 setverdict(pass);
2534}
2535
2536/* Request a HR (prefered) or alternatively a FR channel while all HR channels
2537 * are exhausted, this is expected to be resolved by selecting a FR channel. */
2538testcase TC_assignment_codec_hr_exhausted_req_hr_fr() runs on test_CT {
2539 var MSC_ConnHdlr vc_conn;
2540 f_init(1, true);
2541 f_sleep(1.0);
2542 f_enable_all_tch();
2543 f_disable_all_tch_h();
2544 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_hr_fr));
2545 vc_conn.done;
2546 f_enable_all_tch();
2547 setverdict(pass);
2548}
2549
2550/* Request a FR (prefered) or alternatively a HR channel while all HR channels
2551 * are exhausted, this is expected to work without conflicts. */
2552testcase TC_assignment_codec_hr_exhausted_req_fr_hr() runs on test_CT {
2553 var MSC_ConnHdlr vc_conn;
2554 f_init(1, true);
2555 f_sleep(1.0);
2556 f_enable_all_tch();
2557 f_disable_all_tch_h();
2558 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_fr_hr));
2559 vc_conn.done;
2560 f_enable_all_tch();
2561 setverdict(pass);
2562}
2563
2564/* Allow FR and HR, but prefer HR */
2565private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2566 g_pars := f_gen_test_hdlr_pars();
2567 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2568 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2569 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2570 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2571 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2572 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2573 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2574 f_establish_fully(ass_cmd, exp_compl);
2575}
2576
2577/* Allow FR and HR, but prefer FR */
2578private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2579 g_pars := f_gen_test_hdlr_pars();
2580 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2581 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2582 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2583 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2584 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2585 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2586 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2587 f_establish_fully(ass_cmd, exp_compl);
2588}
2589
2590/* Request a HR (prefered) or alternatively a FR channel, it is expected that
2591 * HR, which is the prefered type, is selected. */
2592testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
2593 var MSC_ConnHdlr vc_conn;
2594 f_init(1, true);
2595 f_sleep(1.0);
2596 f_enable_all_tch();
2597 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
2598 vc_conn.done;
2599 setverdict(pass);
2600}
2601
2602/* Request a FR (prefered) or alternatively a HR channel, it is expected that
2603 * FR, which is the prefered type, is selected. */
2604testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
2605 var MSC_ConnHdlr vc_conn;
2606 f_init(1, true);
2607 f_sleep(1.0);
2608 f_enable_all_tch();
2609 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
2610 vc_conn.done;
2611 setverdict(pass);
2612}
2613
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02002614testcase TC_assignment_osmux() runs on test_CT {
2615 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2616 var MSC_ConnHdlr vc_conn;
2617
2618 /* See note above */
2619 var RSL_IE_Body mr_conf := {
2620 other := {
2621 len := 2,
2622 payload := '2804'O
2623 }
2624 };
2625
2626 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2627 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
2628 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2629 pars.expect_mr_conf_ie := mr_conf;
2630 pars.use_osmux := true;
2631
2632 f_init(1, true, true);
2633 f_sleep(1.0);
2634
2635 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
2636 vc_conn.done;
2637}
2638
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02002639/* test the procedure of the MSC requesting a Classmark Update:
2640 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
2641 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01002642private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002643 g_pars := f_gen_test_hdlr_pars();
2644
Harald Weltea0630032018-03-20 21:09:55 +01002645 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01002646 /* we should now have a COMPL_L3 at the MSC */
2647 BSSAP.receive(tr_BSSMAP_ComplL3);
2648
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02002649 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
2650 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
2651
Harald Welte898113b2018-01-31 18:32:21 +01002652 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
2653 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
2654 setverdict(pass);
2655}
2656testcase TC_classmark() runs on test_CT {
2657 var MSC_ConnHdlr vc_conn;
2658 f_init(1, true);
2659 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002660 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01002661 vc_conn.done;
2662}
2663
Harald Weltee3bd6582018-01-31 22:51:25 +01002664private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002665 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01002666 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01002667 /* we should now have a COMPL_L3 at the MSC */
2668 BSSAP.receive(tr_BSSMAP_ComplL3);
2669
Harald Weltee3bd6582018-01-31 22:51:25 +01002670 /* send the single message we want to send */
2671 f_rsl_send_l3(l3);
2672}
2673
2674private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
2675 timer T := sec;
2676 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01002677 T.start;
2678 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01002679 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
2680 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02002681 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01002682 }
2683 [] T.timeout {
2684 setverdict(pass);
2685 }
2686 }
2687}
2688
Harald Weltee3bd6582018-01-31 22:51:25 +01002689/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2690private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
2691 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
2692 f_bssap_expect_nothing();
2693}
Harald Welte898113b2018-01-31 18:32:21 +01002694testcase TC_unsol_ass_fail() runs on test_CT {
2695 var MSC_ConnHdlr vc_conn;
2696 f_init(1, true);
2697 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002698 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01002699 vc_conn.done;
2700}
Harald Welte552620d2017-12-16 23:21:36 +01002701
Harald Welteea99a002018-01-31 20:46:43 +01002702
2703/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
2704private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002705 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
2706 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01002707}
2708testcase TC_unsol_ass_compl() runs on test_CT {
2709 var MSC_ConnHdlr vc_conn;
2710 f_init(1, true);
2711 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002712 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01002713 vc_conn.done;
2714}
2715
2716
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002717/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2718private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002719 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
2720 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002721}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002722testcase TC_unsol_ho_fail() runs on test_CT {
2723 var MSC_ConnHdlr vc_conn;
2724 f_init(1, true);
2725 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002726 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002727 vc_conn.done;
2728}
2729
2730
Harald Weltee3bd6582018-01-31 22:51:25 +01002731/* short message from MS should be ignored */
2732private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002733 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01002734 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01002735 /* we should now have a COMPL_L3 at the MSC */
2736 BSSAP.receive(tr_BSSMAP_ComplL3);
2737
2738 /* send short message */
2739 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
2740 f_bssap_expect_nothing();
2741}
2742testcase TC_err_82_short_msg() runs on test_CT {
2743 var MSC_ConnHdlr vc_conn;
2744 f_init(1, true);
2745 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002746 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01002747 vc_conn.done;
2748}
2749
2750
Harald Weltee9e02e42018-01-31 23:36:25 +01002751/* 24.008 8.4 Unknown message must trigger RR STATUS */
2752private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
2753 f_est_single_l3(ts_RRM_UL_REL('00'O));
2754 timer T := 3.0
2755 alt {
2756 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
2757 setverdict(pass);
2758 }
2759 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01002760 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01002761 }
2762}
2763testcase TC_err_84_unknown_msg() runs on test_CT {
2764 var MSC_ConnHdlr vc_conn;
2765 f_init(1, true);
2766 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002767 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01002768 vc_conn.done;
2769}
2770
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002771/***********************************************************************
2772 * Handover
2773 ***********************************************************************/
2774
Harald Welte94e0c342018-04-07 11:33:23 +02002775/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
2776private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
2777runs on test_CT {
2778 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2779 " timeslot "&int2str(ts_nr)&" ";
2780 f_vty_transceive(BSCVTY, cmd & suffix);
2781}
2782
Harald Welte261af4b2018-02-12 21:20:39 +01002783/* execute a "bts <0-255> trx <0-255> timeslot <0-7> sub-slot <0-7>" command on given Dchan */
2784private function f_vty_ss_action(charstring suffix, integer bts_nr, integer trx_nr, RslChannelNr chan_nr)
2785runs on MSC_ConnHdlr {
2786 /* FIXME: resolve those from component-global state */
2787 var integer ts_nr := chan_nr.tn;
2788 var integer ss_nr;
2789 if (ischosen(chan_nr.u.ch0)) {
2790 ss_nr := 0;
2791 } else if (ischosen(chan_nr.u.lm)) {
2792 ss_nr := chan_nr.u.lm.sub_chan;
2793 } else if (ischosen(chan_nr.u.sdcch4)) {
2794 ss_nr := chan_nr.u.sdcch4.sub_chan;
2795 } else if (ischosen(chan_nr.u.sdcch8)) {
2796 ss_nr := chan_nr.u.sdcch8.sub_chan;
2797 } else {
2798 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02002799 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01002800 }
2801
2802 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2803 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
2804 f_vty_transceive(BSCVTY, cmd & suffix);
2805}
2806
2807private function f_vty_handover(integer bts_nr, integer trx_nr, RslChannelNr chan_nr,
2808 integer new_bts_nr)
2809runs on MSC_ConnHdlr {
2810 f_vty_ss_action("handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
2811}
2812
2813/* intra-BSC hand-over between BTS0 and BTS1 */
2814private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002815 g_pars := f_gen_test_hdlr_pars();
Harald Welteed848512018-05-24 22:27:58 +02002816 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2817 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01002818 const OCT8 kc := '0001020304050607'O;
2819
2820 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2821 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2822
Harald Weltea0630032018-03-20 21:09:55 +01002823 f_establish_fully(ass_cmd, exp_compl);
Harald Welte261af4b2018-02-12 21:20:39 +01002824
2825 var HandoverState hs := {
2826 rr_ho_cmpl_seen := false,
2827 handover_done := false,
2828 old_chan_nr := -
2829 };
2830 /* issue hand-over command on VTY */
2831 f_vty_handover(0, 0, g_chan_nr, 1);
2832 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
2833 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002834
2835 /* From the MGW perspective, a handover is is characterized by
2836 * performing one MDCX operation with the MGW. So we expect to see
2837 * one more MDCX during handover. */
2838 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
2839
Harald Welte261af4b2018-02-12 21:20:39 +01002840 alt {
2841 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01002842 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002843
Philipp Maier4dae0652018-11-12 12:03:26 +01002844 /* Since this is an internal handover we expect the BSC to inform the
2845 * MSC about the event */
2846 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
2847
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002848 /* Check the amount of MGCP transactions is still consistant with the
2849 * test expectation */
2850 f_check_mgcp_expectations()
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01002851 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01002852}
2853
2854testcase TC_ho_int() runs on test_CT {
2855 var MSC_ConnHdlr vc_conn;
2856 f_init(2, true);
2857 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002858 vc_conn := f_start_handler(refers(f_tc_ho_int));
Harald Welte261af4b2018-02-12 21:20:39 +01002859 vc_conn.done;
2860}
Harald Weltee9e02e42018-01-31 23:36:25 +01002861
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002862private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002863 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002864
2865 var PDU_BSSAP ass_req := f_gen_ass_req();
2866 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2867 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2868 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2869 f_establish_fully(ass_req, exp_compl);
2870
2871 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2872
2873 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2874
2875 f_sleep(0.5);
2876 /* The MSC negotiates Handover Request and Handover Request Ack with
2877 * the other BSS and comes back with a BSSMAP Handover Command
2878 * containing an RR Handover Command coming from the target BSS... */
2879
2880 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
2881 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
2882 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
2883 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
2884 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
2885
2886 /* expect the Handover Command to go out on RR */
2887 var RSL_Message rsl_ho_cmd
2888 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
2889 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
2890 var RSL_IE_Body rsl_ho_cmd_l3;
2891 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
2892 log("RSL message contains no L3 Info IE, expected RR Handover Command");
2893 setverdict(fail);
2894 } else {
2895 log("Found L3 Info: ", rsl_ho_cmd_l3);
2896 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
2897 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
2898 setverdict(fail);
2899 } else {
2900 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
2901 setverdict(pass);
2902 }
2903 }
2904
2905 /* When the other BSS has reported a completed handover, this side is
2906 * torn down. */
2907
2908 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
2909 var BssmapCause cause := enum2int(cause_val);
2910 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
2911
2912 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
2913 var MgcpCommand mgcp;
2914 interleave {
2915 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
2916 [] MGCP.receive(tr_DLCX()) -> value mgcp {
2917 log("Got first DLCX: ", mgcp);
2918 }
2919 [] MGCP.receive(tr_DLCX()) -> value mgcp {
2920 log("Got second DLCX: ", mgcp);
2921 }
2922 }
2923 setverdict(pass);
2924 f_sleep(1.0);
2925}
2926testcase TC_ho_out_of_this_bsc() runs on test_CT {
2927 var MSC_ConnHdlr vc_conn;
2928
2929 f_init(1, true);
2930 f_sleep(1.0);
2931
2932 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
2933 vc_conn.done;
2934}
2935
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002936/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
2937 * simply never sends a BSSMAP Handover Command. */
2938private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01002939 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002940
2941 var PDU_BSSAP ass_req := f_gen_ass_req();
2942 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2943 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2944 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2945 f_establish_fully(ass_req, exp_compl);
2946
2947 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2948
2949 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2950
2951 /* osmo-bsc should time out 10 seconds after the handover started.
2952 * Let's give it a bit extra. */
2953 f_sleep(15.0);
2954
2955 /* The old lchan and conn should still be active. See that arbitrary L3
2956 * is still going through. */
2957 var octetstring l3 := '0123456789'O;
2958 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
2959 var template PDU_BSSAP exp_data := {
2960 discriminator := '1'B,
2961 spare := '0000000'B,
2962 dlci := '00'O,
2963 lengthIndicator := 5,
2964 pdu := {
2965 dtap := l3
2966 }
2967 };
2968 BSSAP.receive(exp_data);
2969 setverdict(pass);
2970 f_sleep(1.0);
2971}
2972testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
2973 var MSC_ConnHdlr vc_conn;
2974
2975 f_init(1, true);
2976 f_sleep(1.0);
2977
2978 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
2979 vc_conn.done;
2980}
2981
2982/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
2983 * RR Handover Failure. */
2984private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01002985 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002986
2987 var PDU_BSSAP ass_req := f_gen_ass_req();
2988 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2989 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2990 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2991 f_establish_fully(ass_req, exp_compl);
2992
2993 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2994
2995 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2996
2997 f_sleep(0.5);
2998 /* The MSC negotiates Handover Request and Handover Request Ack with
2999 * the other BSS and comes back with a BSSMAP Handover Command
3000 * containing an RR Handover Command coming from the target BSS... */
3001
3002 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
3003 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
3004 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
3005 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
3006 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
3007
3008 /* expect the Handover Command to go out on RR */
3009 var RSL_Message rsl_ho_cmd
3010 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
3011 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
3012 var RSL_IE_Body rsl_ho_cmd_l3;
3013 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
3014 log("RSL message contains no L3 Info IE, expected RR Handover Command");
3015 setverdict(fail);
3016 } else {
3017 log("Found L3 Info: ", rsl_ho_cmd_l3);
3018 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
3019 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
3020 setverdict(fail);
3021 } else {
3022 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
3023 setverdict(pass);
3024 }
3025 }
3026
3027 f_sleep(0.2);
3028 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
3029
3030 /* Should tell the MSC about the failure */
3031 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3032
3033 f_sleep(1.0);
3034
3035 /* The old lchan and conn should still be active. See that arbitrary L3
3036 * is still going through. */
3037 var octetstring l3 := '0123456789'O;
3038 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
3039 var template PDU_BSSAP exp_data := {
3040 discriminator := '1'B,
3041 spare := '0000000'B,
3042 dlci := '00'O,
3043 lengthIndicator := 5,
3044 pdu := {
3045 dtap := l3
3046 }
3047 };
3048 BSSAP.receive(exp_data);
3049 setverdict(pass);
3050 f_sleep(1.0);
3051
3052 setverdict(pass);
3053 f_sleep(1.0);
3054}
3055testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
3056 var MSC_ConnHdlr vc_conn;
3057
3058 f_init(1, true);
3059 f_sleep(1.0);
3060
3061 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
3062 vc_conn.done;
3063}
3064
3065/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
3066 * RR Handover Failure. */
3067private function f_tc_ho_out_fail_no_ho_detect(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01003068 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003069
3070 var PDU_BSSAP ass_req := f_gen_ass_req();
3071 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3072 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3073 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3074 f_establish_fully(ass_req, exp_compl);
3075
3076 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
3077
3078 BSSAP.receive(tr_BSSMAP_HandoverRequired);
3079
3080 f_sleep(0.5);
3081 /* The MSC negotiates Handover Request and Handover Request Ack with
3082 * the other BSS and comes back with a BSSMAP Handover Command
3083 * containing an RR Handover Command coming from the target BSS... */
3084
3085 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
3086 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
3087 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
3088 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
3089 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
3090
3091 /* expect the Handover Command to go out on RR */
3092 var RSL_Message rsl_ho_cmd
3093 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
3094 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
3095 var RSL_IE_Body rsl_ho_cmd_l3;
3096 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
3097 log("RSL message contains no L3 Info IE, expected RR Handover Command");
3098 setverdict(fail);
3099 } else {
3100 log("Found L3 Info: ", rsl_ho_cmd_l3);
3101 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
3102 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
3103 setverdict(fail);
3104 } else {
3105 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
3106 setverdict(pass);
3107 }
3108 }
3109
3110 /* The MS never shows up on the remote BSS. Eventually the BSC times
3111 * out and we run into 3GPP TS 48.008 3.1.5.3.3 "Abnormal Conditions":
3112 * RR should be released and Clear Request should go to the MSC. */
3113
3114 var MgcpCommand mgcp;
3115 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01003116 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
3117 log("Got Deact SACCH");
3118 }
Harald Welte924b6ea2019-02-04 01:05:34 +01003119 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01003120 log("Got RR Release");
3121 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003122 [] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
3123 log("Got RF Chan Rel");
3124 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
3125 }
3126 [] BSSAP.receive(tr_BSSMAP_ClearRequest) {
3127 log("Got BSSMAP Clear Request");
3128 }
3129 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3130 log("Got first DLCX: ", mgcp);
3131 }
3132 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3133 log("Got second DLCX: ", mgcp);
3134 }
3135 }
3136
3137 setverdict(pass);
3138 f_sleep(1.0);
3139}
3140testcase TC_ho_out_fail_no_ho_detect() runs on test_CT {
3141 var MSC_ConnHdlr vc_conn;
3142
3143 f_init(1, true);
3144 f_sleep(1.0);
3145
3146 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_ho_detect));
3147 vc_conn.done;
3148}
3149
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003150private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
3151 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
3152 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
3153 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
3154 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
3155 * before we get started. */
3156 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3157 f_rslem_register(0, new_chan_nr);
3158 g_chan_nr := new_chan_nr;
3159 f_sleep(1.0);
3160
3161 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3162 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3163 activate(as_Media());
3164
3165 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3166 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003167 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003168
3169 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3170
3171 var PDU_BSSAP rx_bssap;
3172 var octetstring ho_command_str;
3173
3174 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3175
3176 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3177 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3178 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3179 log("L3 Info in HO Request Ack is ", ho_command);
3180
3181 var GsmArfcn arfcn;
3182 var RslChannelNr actual_new_chan_nr;
3183 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3184 actual_new_chan_nr, arfcn);
3185
3186 if (actual_new_chan_nr != new_chan_nr) {
3187 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3188 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3189 setverdict(fail);
3190 return;
3191 }
3192 log("Handover Command chan_nr is", actual_new_chan_nr);
3193
3194 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3195 * tells the MS to handover to the new lchan. Here comes the new MS on
3196 * the new lchan with a Handover RACH: */
3197
3198 /* send handover detect */
3199
3200 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
3201
3202 BSSAP.receive(tr_BSSMAP_HandoverDetect);
3203
3204 /* send handover complete over the new channel */
3205
3206 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
3207 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
3208 enc_PDU_ML3_MS_NW(l3_tx)));
3209
3210 BSSAP.receive(tr_BSSMAP_HandoverComplete);
3211 setverdict(pass);
3212}
3213testcase TC_ho_into_this_bsc() runs on test_CT {
3214 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003215 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003216
3217 f_init(1, true);
3218 f_sleep(1.0);
3219
3220 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3221 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3222
3223 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
3224 vc_conn.done;
3225}
3226
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003227private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
3228 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3229 f_rslem_register(0, new_chan_nr);
3230 g_chan_nr := new_chan_nr;
3231 f_sleep(1.0);
3232
3233 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3234 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3235 activate(as_Media());
3236
3237 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3238 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003239 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003240
3241 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3242
3243 var PDU_BSSAP rx_bssap;
3244 var octetstring ho_command_str;
3245
3246 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3247
3248 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3249 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3250 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3251 log("L3 Info in HO Request Ack is ", ho_command);
3252
3253 var GsmArfcn arfcn;
3254 var RslChannelNr actual_new_chan_nr;
3255 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3256 actual_new_chan_nr, arfcn);
3257
3258 if (actual_new_chan_nr != new_chan_nr) {
3259 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3260 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3261 setverdict(fail);
3262 return;
3263 }
3264 log("Handover Command chan_nr is", actual_new_chan_nr);
3265
Neels Hofmeyr61ca08d2019-05-06 23:52:22 +02003266 /* For deterministic test results, give some time for the MGW endpoint to be configured */
3267 f_sleep(1.0);
3268
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003269 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3270 * tells the MS to handover to the new lchan. In this case, the MS
3271 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
3272 * Handover Failure to the MSC. The procedure according to 3GPP TS
3273 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
3274 * BSSMAP Clear Command: */
3275
3276 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3277 var BssmapCause cause := enum2int(cause_val);
3278 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3279
3280 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3281 var MgcpCommand mgcp;
3282 interleave {
3283 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3284 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3285 log("Got first DLCX: ", mgcp);
3286 }
3287 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3288 log("Got second DLCX: ", mgcp);
3289 }
3290 }
3291 setverdict(pass);
3292 f_sleep(1.0);
3293
3294 setverdict(pass);
3295}
3296testcase TC_ho_in_fail_msc_clears() runs on test_CT {
3297 var MSC_ConnHdlr vc_conn;
3298 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3299
3300 f_init(1, true);
3301 f_sleep(1.0);
3302
3303 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3304 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3305
3306 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
3307 vc_conn.done;
3308}
3309
3310private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
3311 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
3312 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
3313 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
3314 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
3315 * before we get started. */
3316 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3317 f_rslem_register(0, new_chan_nr);
3318 g_chan_nr := new_chan_nr;
3319 f_sleep(1.0);
3320
3321 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3322 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3323 activate(as_Media());
3324
3325 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3326 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003327 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003328
3329 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3330
3331 var PDU_BSSAP rx_bssap;
3332 var octetstring ho_command_str;
3333
3334 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3335
3336 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3337 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3338 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3339 log("L3 Info in HO Request Ack is ", ho_command);
3340
3341 var GsmArfcn arfcn;
3342 var RslChannelNr actual_new_chan_nr;
3343 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3344 actual_new_chan_nr, arfcn);
3345
3346 if (actual_new_chan_nr != new_chan_nr) {
3347 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3348 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3349 setverdict(fail);
3350 return;
3351 }
3352 log("Handover Command chan_nr is", actual_new_chan_nr);
3353
3354 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3355 * tells the MS to handover to the new lchan. Here comes the new MS on
3356 * the new lchan with a Handover RACH: */
3357
3358 /* send handover detect */
3359
3360 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
3361
3362 BSSAP.receive(tr_BSSMAP_HandoverDetect);
3363
3364 /* The MSC chooses to clear the connection now, maybe we got the
3365 * Handover RACH on the new cell but the MS still signaled Handover
3366 * Failure to the old BSS? */
3367
3368 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3369 var BssmapCause cause := enum2int(cause_val);
3370 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3371
3372 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3373 var MgcpCommand mgcp;
3374 interleave {
3375 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3376 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3377 log("Got first DLCX: ", mgcp);
3378 }
3379 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3380 log("Got second DLCX: ", mgcp);
3381 }
3382 }
3383 setverdict(pass);
3384 f_sleep(1.0);
3385}
3386testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
3387 var MSC_ConnHdlr vc_conn;
3388 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3389
3390 f_init(1, true);
3391 f_sleep(1.0);
3392
3393 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3394 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3395
3396 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
3397 vc_conn.done;
3398}
3399
3400/* The new BSS's lchan times out before the MSC decides that handover failed. */
3401private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
3402 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3403 f_rslem_register(0, new_chan_nr);
3404 g_chan_nr := new_chan_nr;
3405 f_sleep(1.0);
3406
3407 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3408 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3409 activate(as_Media());
3410
3411 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3412 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003413 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003414
3415 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3416
3417 var PDU_BSSAP rx_bssap;
3418 var octetstring ho_command_str;
3419
3420 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3421
3422 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3423 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3424 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3425 log("L3 Info in HO Request Ack is ", ho_command);
3426
3427 var GsmArfcn arfcn;
3428 var RslChannelNr actual_new_chan_nr;
3429 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3430 actual_new_chan_nr, arfcn);
3431
3432 if (actual_new_chan_nr != new_chan_nr) {
3433 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3434 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3435 setverdict(fail);
3436 return;
3437 }
3438 log("Handover Command chan_nr is", actual_new_chan_nr);
3439
3440 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3441 * tells the MS to handover to the new lchan. But the MS never shows up
3442 * on the new lchan. */
3443
3444 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3445
3446 /* Did osmo-bsc also send a Clear Request? */
3447 timer T := 0.5;
3448 T.start;
3449 alt {
3450 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
3451 [] T.timeout { }
3452 }
3453
3454 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
3455 * asked for it, this is a Handover Failure after all). */
3456
3457 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3458 var BssmapCause cause := enum2int(cause_val);
3459 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3460
3461 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3462 var MgcpCommand mgcp;
3463 interleave {
3464 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3465 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3466 log("Got first DLCX: ", mgcp);
3467 }
3468 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3469 log("Got second DLCX: ", mgcp);
3470 }
3471 }
3472 setverdict(pass);
3473 f_sleep(1.0);
3474
3475 setverdict(pass);
3476}
3477testcase TC_ho_in_fail_no_detect() runs on test_CT {
3478 var MSC_ConnHdlr vc_conn;
3479 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3480
3481 f_init(1, true);
3482 f_sleep(1.0);
3483
3484 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3485 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3486
3487 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
3488 vc_conn.done;
3489}
3490
3491/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
3492private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
3493 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3494 f_rslem_register(0, new_chan_nr);
3495 g_chan_nr := new_chan_nr;
3496 f_sleep(1.0);
3497
3498 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3499 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3500 activate(as_Media());
3501
3502 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3503 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003504 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003505
3506 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3507
3508 var PDU_BSSAP rx_bssap;
3509 var octetstring ho_command_str;
3510
3511 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3512
3513 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3514 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3515 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3516 log("L3 Info in HO Request Ack is ", ho_command);
3517
3518 var GsmArfcn arfcn;
3519 var RslChannelNr actual_new_chan_nr;
3520 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3521 actual_new_chan_nr, arfcn);
3522
3523 if (actual_new_chan_nr != new_chan_nr) {
3524 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3525 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3526 setverdict(fail);
3527 return;
3528 }
3529 log("Handover Command chan_nr is", actual_new_chan_nr);
3530
3531 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3532 * tells the MS to handover to the new lchan. But the MS never shows up
3533 * on the new lchan. */
3534
3535 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3536
3537 /* MSC plays dumb and sends no Clear Command */
3538
3539 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3540 var PDU_BSSAP rx_clear_request;
3541 var MgcpCommand mgcp;
3542 interleave {
3543 [] BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
3544 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
3545 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3546 };
3547 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3548
3549 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3550 log("Got first DLCX: ", mgcp);
3551 }
3552 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3553 log("Got second DLCX: ", mgcp);
3554 }
3555 }
3556 setverdict(pass);
3557 f_sleep(1.0);
3558}
3559testcase TC_ho_in_fail_no_detect2() runs on test_CT {
3560 var MSC_ConnHdlr vc_conn;
3561 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3562
3563 f_init(1, true);
3564 f_sleep(1.0);
3565
3566 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3567 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3568
3569 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
3570 vc_conn.done;
3571}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003572
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003573/* OS#3041: Open and close N connections in a normal fashion, and expect no
3574 * BSSMAP Reset just because of that. */
3575testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
3576 var default d;
3577 var integer i;
3578 var DchanTuple dt;
3579
3580 f_init();
3581
3582 /* Wait for initial BSSMAP Reset to pass */
3583 f_sleep(4.0);
3584
3585 d := activate(no_bssmap_reset());
3586
3587 /* Setup up a number of connections and RLSD them again from the MSC
3588 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3589 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02003590 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003591 /* Since we're doing a lot of runs, give each one a fresh
3592 * T_guard from the top. */
3593 T_guard.start;
3594
3595 /* Setup a BSSAP connection and clear it right away. This is
3596 * the MSC telling the BSC about a planned release, it's not an
3597 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02003598 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003599
3600 /* MSC disconnects (RLSD). */
3601 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
3602 }
3603
3604 /* In the buggy behavior, a timeout of 2 seconds happens between above
3605 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3606 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3607 f_sleep(4.0);
3608
3609 deactivate(d);
3610 f_shutdown_helper();
3611}
Harald Welte552620d2017-12-16 23:21:36 +01003612
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003613/* OS#3041: Open and close N connections in a normal fashion, and expect no
3614 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
3615 * the MSC. */
3616testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
3617 var default d;
3618 var integer i;
3619 var DchanTuple dt;
3620 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003621 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
3622 var BssmapCause cause := enum2int(cause_val);
3623
3624 f_init();
3625
3626 /* Wait for initial BSSMAP Reset to pass */
3627 f_sleep(4.0);
3628
3629 d := activate(no_bssmap_reset());
3630
3631 /* Setup up a number of connections and RLSD them again from the MSC
3632 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3633 * Let's do it some more times for good measure. */
3634 for (i := 0; i < 8; i := i+1) {
3635 /* Since we're doing a lot of runs, give each one a fresh
3636 * T_guard from the top. */
3637 T_guard.start;
3638
3639 /* Setup a BSSAP connection and clear it right away. This is
3640 * the MSC telling the BSC about a planned release, it's not an
3641 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02003642 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003643
3644 /* Instruct BSC to clear channel */
3645 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
3646
3647 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02003648 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003649 }
3650
3651 /* In the buggy behavior, a timeout of 2 seconds happens between above
3652 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3653 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3654 f_sleep(4.0);
3655
3656 deactivate(d);
3657 f_shutdown_helper();
3658}
3659
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003660/* OS#3041: Open and close N connections in a normal fashion, and expect no
3661 * BSSMAP Reset just because of that. Close connections from the MS side with a
3662 * Release Ind on RSL. */
3663testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
3664 var default d;
3665 var integer i;
3666 var DchanTuple dt;
3667 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003668 var integer j;
3669
3670 f_init();
3671
3672 /* Wait for initial BSSMAP Reset to pass */
3673 f_sleep(4.0);
3674
3675 d := activate(no_bssmap_reset());
3676
3677 /* Setup up a number of connections and RLSD them again from the MSC
3678 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3679 * Let's do it some more times for good measure. */
3680 for (i := 0; i < 8; i := i+1) {
3681 /* Since we're doing a lot of runs, give each one a fresh
3682 * T_guard from the top. */
3683 T_guard.start;
3684
3685 /* Setup a BSSAP connection and clear it right away. This is
3686 * the MSC telling the BSC about a planned release, it's not an
3687 * erratic loss of a connection. */
3688 dt := f_est_dchan('23'O, 23, '00010203040506'O);
3689
3690 /* simulate RLL REL IND */
3691 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
3692
3693 /* expect Clear Request on MSC side */
3694 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
3695
3696 /* Instruct BSC to clear channel */
3697 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
3698 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
3699
3700 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02003701 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003702 }
3703
3704 /* In the buggy behavior, a timeout of 2 seconds happens between above
3705 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3706 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3707 f_sleep(4.0);
3708
3709 deactivate(d);
3710 f_shutdown_helper();
3711}
3712
Harald Welte94e0c342018-04-07 11:33:23 +02003713/***********************************************************************
3714 * IPA style dynamic PDCH
3715 ***********************************************************************/
3716
3717private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
3718 template (omit) RSL_Cause nack := omit)
3719runs on test_CT {
3720 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
3721 var RSL_Message rsl_unused;
3722 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3723 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
3724 /* expect the BSC to issue the related RSL command */
3725 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3726 if (istemplatekind(nack, "omit")) {
3727 /* respond with a related acknowledgement */
3728 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3729 } else {
3730 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
3731 }
3732}
3733
3734private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
3735 template (omit) RSL_Cause nack := omit)
3736runs on test_CT {
3737 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
3738 var RSL_Message rsl_unused;
3739 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3740 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
3741 /* expect the BSC to issue the related RSL command */
3742 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
3743 if (istemplatekind(nack, "omit")) {
3744 /* respond with a related acknowledgement */
3745 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
3746 } else {
3747 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
3748 }
3749}
3750
3751private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
3752runs on test_CT return charstring {
3753 var charstring cmd, resp;
3754 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01003755 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02003756}
3757
3758private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
3759 template charstring exp)
3760runs on test_CT {
3761 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
3762 if (not match(mode, exp)) {
3763 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02003764 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02003765 }
3766}
3767
3768private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
3769runs on test_CT {
3770 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
3771 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
3772 f_vty_transceive(BSCVTY, "end");
3773}
3774
3775private const charstring TCHF_MODE := "TCH/F mode";
3776private const charstring TCHH_MODE := "TCH/H mode";
3777private const charstring PDCH_MODE := "PDCH mode";
3778private const charstring NONE_MODE := "NONE mode";
3779
3780/* Test IPA PDCH activation / deactivation triggered by VTY */
3781testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
3782 var RSL_Message rsl_unused;
3783
3784 /* change Timeslot 6 before f_init() starts RSL */
3785 f_init_vty();
3786 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
3787 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3788
3789 f_init(1, false);
3790 f_sleep(1.0);
3791
3792 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
3793
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003794 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003795 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3796 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3797 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3798 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3799 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003800 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003801 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3802
3803 /* De-activate it via VTY */
3804 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3805 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003806 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003807 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3808
3809 /* re-activate it via VTY */
3810 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
3811 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003812 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003813 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3814
3815 /* and finally de-activate it again */
3816 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3817 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003818 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003819 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3820
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003821 /* clean up config */
3822 f_ts_set_chcomb(0, 0, 6, "PDCH");
3823
Harald Welte94e0c342018-04-07 11:33:23 +02003824 setverdict(pass);
3825}
3826
3827/* Test IPA PDCH activation NACK */
3828testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
3829 var RSL_Message rsl_unused;
3830
3831 /* change Timeslot 6 before f_init() starts RSL */
3832 f_init_vty();
3833 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
3834 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3835
3836 f_init(1, false);
3837 f_sleep(1.0);
3838
3839 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
3840
3841 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3842 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3843 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3844 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3845 f_sleep(1.0);
3846 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3847
3848 /* De-activate it via VTY */
3849 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3850 f_sleep(1.0);
3851 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3852
3853 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
3854 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
3855 f_sleep(1.0);
3856 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3857
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003858 /* clean up config */
3859 f_ts_set_chcomb(0, 0, 6, "PDCH");
3860
Harald Welte94e0c342018-04-07 11:33:23 +02003861 setverdict(pass);
3862}
3863
3864
3865/***********************************************************************
3866 * Osmocom style dynamic PDCH
3867 ***********************************************************************/
3868
3869private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
3870 template (omit) RSL_Cause nack := omit)
3871runs on test_CT {
3872 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
3873 var RSL_Message rsl_unused;
3874 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3875 /* FIXME: no VTY command to activate Osmocom PDCH !! */
3876 /* expect the BSC to issue the related RSL command */
3877 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
3878 if (istemplatekind(nack, "omit")) {
3879 /* respond with a related acknowledgement */
3880 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
3881 } else {
3882 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
3883 }
3884}
3885
3886private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
3887 template (omit) RSL_Cause nack := omit)
3888runs on test_CT {
3889 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
3890 var RSL_Message rsl_unused;
3891 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3892 /* FIXME: no VTY command to activate Osmocom PDCH !! */
3893 /* expect the BSC to issue the related RSL command */
3894 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
3895 if (istemplatekind(nack, "omit")) {
3896 /* respond with a related acknowledgement */
3897 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
3898 } else {
3899 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
3900 }
3901}
3902
3903/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
3904testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
3905 var RSL_Message rsl_unused;
3906
3907 /* change Timeslot 6 before f_init() starts RSL */
3908 f_init_vty();
3909 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
3910 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3911
3912 f_init(1, false);
3913 f_sleep(1.0);
3914
3915 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
3916
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003917 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003918 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
3919 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3920 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
3921
3922 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
3923 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003924 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 +02003925 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3926
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003927 /* clean up config */
3928 f_ts_set_chcomb(0, 0, 6, "PDCH");
3929
Harald Welte94e0c342018-04-07 11:33:23 +02003930 setverdict(pass);
3931}
3932
3933/* Test Osmocom dyn PDCH activation NACK behavior */
3934testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
3935 var RSL_Message rsl_unused;
3936
3937 /* change Timeslot 6 before f_init() starts RSL */
3938 f_init_vty();
3939 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
3940 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3941
3942 f_init(1, false);
3943 f_sleep(1.0);
3944
3945 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
3946
3947 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
3948 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3949 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
3950
3951 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
3952 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
3953 f_sleep(1.0);
3954 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
3955
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003956 /* clean up config */
3957 f_ts_set_chcomb(0, 0, 6, "PDCH");
3958
Harald Welte94e0c342018-04-07 11:33:23 +02003959 setverdict(pass);
3960}
3961
Stefan Sperling0796a822018-10-05 13:01:39 +02003962testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02003963 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02003964 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
3965 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
3966 }
3967}
3968
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02003969testcase TC_chopped_ipa_payload() runs on test_CT {
3970 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
3971 /* TODO: mp_bsc_ctrl_port does not work yet */};
3972 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
3973 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
3974 }
3975}
3976
3977
Harald Welte0ea2d5e2018-04-07 21:40:29 +02003978/* Dyn PDCH todo:
3979 * activate OSMO as TCH/F
3980 * activate OSMO as TCH/H
3981 * does the BSC-located PCU socket get the updated INFO?
3982 * what if no PCU is connected at the time?
3983 * is the info correct on delayed PCU (re)connect?
3984 */
Harald Welte94e0c342018-04-07 11:33:23 +02003985
Harald Welte28d943e2017-11-25 15:00:50 +01003986control {
Harald Welte898113b2018-01-31 18:32:21 +01003987 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +01003988 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01003989 execute( TC_ctrl_msc0_connection_status() );
Harald Welte96c94412017-12-09 03:12:45 +01003990 execute( TC_ctrl() );
Harald Welte898113b2018-01-31 18:32:21 +01003991
3992 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +01003993 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +01003994 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +01003995 execute( TC_chan_act_ack_noest() );
3996 execute( TC_chan_act_ack_est_ind_noreply() );
3997 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +01003998 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +01003999 execute( TC_chan_exhaustion() );
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07004000 execute( TC_chan_deact_silence() );
Harald Welte4003d112017-12-09 22:35:39 +01004001 execute( TC_chan_rel_rll_rel_ind() );
4002 execute( TC_chan_rel_conn_fail() );
4003 execute( TC_chan_rel_hard_clear() );
Harald Welte99787102019-02-04 10:41:36 +01004004 execute( TC_chan_rel_hard_clear_csfb() );
Harald Welted8c36cd2017-12-09 23:05:31 +01004005 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +02004006 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +01004007 execute( TC_chan_rel_a_reset() );
Harald Welte6f521d82017-12-11 19:52:02 +01004008
Harald Weltecfe2c962017-12-15 12:09:32 +01004009 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +01004010
4011 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +01004012 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +01004013 execute( TC_assignment_csd() );
4014 execute( TC_assignment_ctm() );
4015 execute( TC_assignment_sign() );
4016 execute( TC_assignment_fr_a5_0() );
4017 execute( TC_assignment_fr_a5_1() );
Harald Welte8f67d1d2018-05-25 20:38:42 +02004018 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
4019 execute( TC_assignment_fr_a5_1_codec_missing() );
4020 }
Harald Welte235ebf12017-12-15 14:18:16 +01004021 execute( TC_assignment_fr_a5_3() );
4022 execute( TC_assignment_fr_a5_4() );
Harald Welte3c86ea02018-05-10 22:28:05 +02004023 execute( TC_ciph_mode_a5_0() );
4024 execute( TC_ciph_mode_a5_1() );
4025 execute( TC_ciph_mode_a5_3() );
Harald Welte16a4adf2017-12-14 18:54:01 +01004026
Harald Welte60aa5762018-03-21 19:33:13 +01004027 execute( TC_assignment_codec_fr() );
4028 execute( TC_assignment_codec_hr() );
4029 execute( TC_assignment_codec_efr() );
4030 execute( TC_assignment_codec_amr_f() );
4031 execute( TC_assignment_codec_amr_h() );
Philipp Maier8a581d22019-03-26 18:32:48 +01004032
4033 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
4034 execute( TC_assignment_codec_amr_f_S1() );
4035 execute( TC_assignment_codec_amr_h_S1() );
4036 execute( TC_assignment_codec_amr_f_S124() );
4037 execute( TC_assignment_codec_amr_h_S124() );
4038 execute( TC_assignment_codec_amr_f_S0() );
4039 execute( TC_assignment_codec_amr_f_S02() );
4040 execute( TC_assignment_codec_amr_f_S024() );
4041 execute( TC_assignment_codec_amr_f_S0247() );
4042 execute( TC_assignment_codec_amr_h_S0() );
4043 execute( TC_assignment_codec_amr_h_S02() );
4044 execute( TC_assignment_codec_amr_h_S024() );
4045 execute( TC_assignment_codec_amr_h_S0247() );
4046 execute( TC_assignment_codec_amr_f_S01234567() );
4047 execute( TC_assignment_codec_amr_f_S0234567() );
4048 execute( TC_assignment_codec_amr_f_zero() );
4049 execute( TC_assignment_codec_amr_f_unsupp() );
4050 execute( TC_assignment_codec_amr_h_S7() );
4051 }
Harald Welte60aa5762018-03-21 19:33:13 +01004052
Philipp Maierac09bfc2019-01-08 13:41:39 +01004053 execute( TC_assignment_codec_fr_exhausted_req_hr() );
4054 execute( TC_assignment_codec_fr_exhausted_req_fr() );
4055 execute( TC_assignment_codec_fr_exhausted_req_fr_hr() );
4056 execute( TC_assignment_codec_fr_exhausted_req_hr_fr() );
4057 execute( TC_assignment_codec_hr_exhausted_req_fr() );
4058 execute( TC_assignment_codec_hr_exhausted_req_hr() );
4059 execute( TC_assignment_codec_hr_exhausted_req_hr_fr() );
4060 execute( TC_assignment_codec_hr_exhausted_req_fr_hr() );
4061 execute( TC_assignment_codec_req_hr_fr() );
4062 execute( TC_assignment_codec_req_fr_hr() );
4063
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004064 execute( TC_assignment_osmux() );
4065
Harald Welte898113b2018-01-31 18:32:21 +01004066 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +01004067 execute( TC_rll_est_ind_inact_lchan() );
4068 execute( TC_rll_est_ind_inval_sapi1() );
4069 execute( TC_rll_est_ind_inval_sapi3() );
4070 execute( TC_rll_est_ind_inval_sacch() );
4071
Harald Welte898113b2018-01-31 18:32:21 +01004072 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +01004073 execute( TC_paging_imsi_nochan() );
4074 execute( TC_paging_tmsi_nochan() );
4075 execute( TC_paging_tmsi_any() );
4076 execute( TC_paging_tmsi_sdcch() );
4077 execute( TC_paging_tmsi_tch_f() );
4078 execute( TC_paging_tmsi_tch_hf() );
4079 execute( TC_paging_imsi_nochan_cgi() );
4080 execute( TC_paging_imsi_nochan_lac_ci() );
4081 execute( TC_paging_imsi_nochan_ci() );
4082 execute( TC_paging_imsi_nochan_lai() );
4083 execute( TC_paging_imsi_nochan_lac() );
4084 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +01004085 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
4086 execute( TC_paging_imsi_nochan_rnc() );
4087 execute( TC_paging_imsi_nochan_lac_rnc() );
4088 execute( TC_paging_imsi_nochan_lacs() );
4089 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +01004090 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +01004091 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +01004092 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +01004093 execute( TC_paging_counter() );
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01004094 execute( TC_paging_resp_unsol() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +01004095
4096 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +01004097 execute( TC_rsl_unknown_unit_id() );
4098
4099 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +01004100
4101 execute( TC_classmark() );
4102 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +01004103 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004104 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +01004105 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +01004106 execute( TC_err_84_unknown_msg() );
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004107
Harald Welte261af4b2018-02-12 21:20:39 +01004108 execute( TC_ho_int() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004109
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004110 execute( TC_ho_out_of_this_bsc() );
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004111 execute( TC_ho_out_fail_no_msc_response() );
4112 execute( TC_ho_out_fail_rr_ho_failure() );
4113 execute( TC_ho_out_fail_no_ho_detect() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004114
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004115 execute( TC_ho_into_this_bsc() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004116 execute( TC_ho_in_fail_msc_clears() );
4117 execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
4118 execute( TC_ho_in_fail_no_detect() );
4119 execute( TC_ho_in_fail_no_detect2() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01004120
4121 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01004122 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01004123 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +02004124
4125 execute( TC_dyn_pdch_ipa_act_deact() );
4126 execute( TC_dyn_pdch_ipa_act_nack() );
4127 execute( TC_dyn_pdch_osmo_act_deact() );
4128 execute( TC_dyn_pdch_osmo_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +02004129
Stefan Sperling0796a822018-10-05 13:01:39 +02004130 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02004131 execute( TC_chopped_ipa_payload() );
Stefan Sperling0796a822018-10-05 13:01:39 +02004132
Harald Welte99f3ca02018-06-14 13:40:29 +02004133 /* at bottom as they might crash OsmoBSC before OS#3182 is fixed */
4134 execute( TC_early_conn_fail() );
4135 execute( TC_late_conn_fail() );
4136
Harald Welte28d943e2017-11-25 15:00:50 +01004137}
4138
4139}