blob: 00995bfb12e8e7491238999a5214f20baba2deda [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() */
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +020083 /* CTRL muxed over IPA in SCCPlite conn BSC<->MSC (or BSC-NAT) */
84 port IPA_CTRL_PT SCCPLITE_IPA_CTRL;
Harald Weltea5d2ab22017-12-09 14:21:42 +010085
Daniel Willmann191e0d92018-01-17 12:44:35 +010086 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +010087 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +010088
Harald Welte6811d102019-04-14 22:23:14 +020089 var RAN_Adapter g_bssap;
Harald Weltea4ca4462018-02-09 00:17:14 +010090 /* for old legacy-tests only */
91 port BSSAP_CODEC_PT BSSAP;
92
Harald Welte21b46bd2017-12-17 19:46:32 +010093 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +010094 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +010095
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +020096 /* Osmux is enabled through VTY */
97 var boolean g_osmux_enabled := false;
98
Harald Welte21b46bd2017-12-17 19:46:32 +010099 /* global test case guard timer */
Harald Welteae026692017-12-09 01:03:01 +0100100 timer T_guard := 30.0;
101
Harald Welte28d943e2017-11-25 15:00:50 +0100102}
103
104modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +0100105 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +0100106 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100107 /* port number to which to establish the IPA OML connections */
108 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +0100109 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +0100110 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +0100111 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +0100112 integer mp_bsc_ctrl_port := 4249;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100113 /* IP address at which the test binds */
114 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100115
Harald Welte6811d102019-04-14 22:23:14 +0200116 RAN_Configuration mp_bssap_cfg := {
Harald Welte7ef51aa2018-04-16 19:16:01 +0200117 transport := BSSAP_TRANSPORT_AoIP,
Harald Weltea4ca4462018-02-09 00:17:14 +0100118 sccp_service_type := "mtp3_itu",
119 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
120 own_pc := 185,
121 own_ssn := 254,
122 peer_pc := 187,
123 peer_ssn := 254,
Philipp Maier38d68942018-03-29 15:38:09 +0200124 sio := '83'O,
125 rctx := 0
Harald Weltea4ca4462018-02-09 00:17:14 +0100126 };
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +0200127
128 /* Whether to enable osmux tests. Can be dropped completely and enable
129 unconditionally once new version of osmo-bsc is released (current
130 version: 1.4.1) */
131 boolean mp_enable_osmux_test := true;
Harald Weltea4ca4462018-02-09 00:17:14 +0100132}
133
Philipp Maier48604732018-10-09 15:00:37 +0200134private function f_gen_test_hdlr_pars() return TestHdlrParams {
135
136 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
137 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
138 pars.aoip := true;
139 } else {
140 pars.aoip := false;
141 }
142
143 return pars;
144}
145
Philipp Maier282ca4b2018-02-27 17:17:00 +0100146private function f_shutdown_helper() runs on test_CT {
Daniel Willmann637ef6c2018-07-25 10:49:09 +0200147 all component.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100148 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200149 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100150}
151
Harald Weltea4ca4462018-02-09 00:17:14 +0100152private function f_legacy_bssap_reset() runs on test_CT {
153 var BSSAP_N_UNITDATA_ind ud_ind;
154 timer T := 5.0;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200155 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 +0100156 T.start;
157 alt {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200158 [] 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 +0100159 log("Received RESET-ACK in response to RESET, we're ready to go!");
160 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200161 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Weltea4ca4462018-02-09 00:17:14 +0100162 log("Respoding to inbound RESET with RESET-ACK");
163 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200164 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Weltea4ca4462018-02-09 00:17:14 +0100165 repeat;
166 }
167 [] BSSAP.receive { repeat; }
168 [] T.timeout { setverdict(fail, "Waiting for RESET-ACK after sending RESET"); }
169 }
Harald Welte28d943e2017-11-25 15:00:50 +0100170}
171
Harald Welteae026692017-12-09 01:03:01 +0100172type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100173 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100174 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100175 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100176 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100177 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100178 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100179 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100180 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100181}
182
Harald Welte21b46bd2017-12-17 19:46:32 +0100183/*! Start the IPA/RSL related bits for one IPA_Client.
184 * \param clnt IPA_Client for which to establish
185 * \param bsc_host IP address / hostname of the BSC
186 * \param bsc_port TCP port number of the BSC
187 * \param i number identifying this BTS
188 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100189function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
190 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100191runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100192 timer T := 10.0;
193
Harald Welte96c94412017-12-09 03:12:45 +0100194 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welteae026692017-12-09 01:03:01 +0100195 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA");
196 clnt.ccm_pars := c_IPA_default_ccm_pars;
197 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
198 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100199 if (handler_mode) {
200 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL");
Harald Welte89ab1912018-02-23 18:56:29 +0100201 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100202 }
Harald Welteae026692017-12-09 01:03:01 +0100203
204 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Harald Welte624f9632017-12-16 19:26:04 +0100205 if (handler_mode) {
206 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
207 } else {
208 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
209 }
Harald Welteae026692017-12-09 01:03:01 +0100210
Harald Welte5d1a2202017-12-13 19:51:29 +0100211 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100212 if (handler_mode) {
213 clnt.vc_RSL.start(RSL_Emulation.main());
214 return;
215 }
Harald Welteae026692017-12-09 01:03:01 +0100216
217 /* wait for IPA RSL link to connect and send ID ACK */
218 T.start;
219 alt {
220 [] IPA_RSL[i].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_ID_ACK}) {
221 T.stop;
222 IPA_RSL[i].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_PAGING_LOAD_IND(23)));
223 }
Harald Welte60e823a2017-12-10 14:10:59 +0100224 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100225 [] IPA_RSL[i].receive { repeat }
226 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100227 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200228 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100229 }
230 }
231}
232
Harald Welte12055472018-03-17 20:10:08 +0100233function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
234 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
235 return;
236 }
237 clnt.vc_IPA.stop;
238 if (isbound(clnt.vc_RSL)) {
239 clnt.vc_RSL.stop;
240 }
241}
242
Harald Welte21b46bd2017-12-17 19:46:32 +0100243/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100244function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
245 timer T := secs_max;
246 T.start;
247 while (true) {
248 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
249 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100250 /* the 'degraded' state exists from OML connection time, and we have to wait
251 * until all MO's are initialized */
252 T.start(1.0);
253 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100254 return;
255 }
Harald Weltef0d6ac62017-12-17 17:02:21 +0100256 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100257 if (not T.running) {
Max99253902018-11-16 17:57:39 +0100258 setverdict(fail, "Timeout waiting for BTS" & int2str(bts_nr) & " oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +0200259 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100260 }
261 }
262}
263
Harald Welte21b46bd2017-12-17 19:46:32 +0100264/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +0100265altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +0100266 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100267 [] T_guard.timeout {
268 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +0200269 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100270 }
Harald Welte60e823a2017-12-10 14:10:59 +0100271 /* always respond with RESET ACK to RESET */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200272 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Welte60e823a2017-12-10 14:10:59 +0100273 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200274 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Welte69c1c262017-12-13 21:02:08 +0100275 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +0100276 }
Harald Welte28d943e2017-11-25 15:00:50 +0100277}
278
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100279altstep no_bssmap_reset() runs on test_CT {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200280 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100281 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +0200282 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100283 }
284}
285
Daniel Willmann191e0d92018-01-17 12:44:35 +0100286function f_init_mgcp(charstring id) runs on test_CT {
287 id := id & "-MGCP";
288
289 var MGCPOps ops := {
290 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
291 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
292 };
293 var MGCP_conn_parameters mgcp_pars := {
294 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +0100295 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +0100296 mgw_ip := mp_test_ip,
297 mgw_udp_port := 2427
298 };
299
300 vc_MGCP := MGCP_Emulation_CT.create(id);
301 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
302}
303
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200304/* Enable or disable (current default) Osmux. When enabling, BSSMAP Reset
305 * contains extra IE (OsmuxSupport) and osmo-bsc will handle AssignReq with
306 * OsmuxCID IE.
307 */
308private function f_vty_allow_osmux(boolean allow) runs on test_CT {
309 f_vty_enter_cfg_msc(BSCVTY, 0);
310 if (allow) {
311 f_vty_transceive(BSCVTY, "osmux on");
312 } else {
313 f_vty_transceive(BSCVTY, "osmux off");
314 }
315 f_vty_transceive(BSCVTY, "exit");
316 f_vty_transceive(BSCVTY, "exit");
317 g_osmux_enabled := allow;
318}
319
Max2253c0b2018-11-06 19:28:05 +0100320function f_init_vty(charstring id := "foo") runs on test_CT {
Harald Welte94e0c342018-04-07 11:33:23 +0200321 if (BSCVTY.checkstate("Mapped")) {
322 /* skip initialization if already executed once */
323 return;
324 }
Harald Weltebc03c762018-02-12 18:09:38 +0100325 map(self:BSCVTY, system:BSCVTY);
326 f_vty_set_prompts(BSCVTY);
327 f_vty_transceive(BSCVTY, "enable");
328}
329
Harald Welte21b46bd2017-12-17 19:46:32 +0100330/* global initialization function
331 * \param nr_bts Number of BTSs we should start/bring up
332 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200333function 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 +0100334 var integer i;
Harald Welte28d943e2017-11-25 15:00:50 +0100335
Harald Welteae026692017-12-09 01:03:01 +0100336 if (g_initialized) {
337 return;
Harald Welte28d943e2017-11-25 15:00:50 +0100338 }
Harald Welteae026692017-12-09 01:03:01 +0100339 g_initialized := true;
340
Daniel Willmanne68f9272018-11-27 15:15:28 +0100341 T_guard.start;
342 activate(as_Tguard());
343
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200344 f_init_vty("VirtMSC");
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +0200345 if (mp_enable_osmux_test) {
346 f_vty_allow_osmux(allow_osmux);
347 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200348
Harald Welte6811d102019-04-14 22:23:14 +0200349 /* Call a function of our 'parent component' RAN_Adapter_CT to start the
Harald Welteae026692017-12-09 01:03:01 +0100350 * MSC-side BSSAP emulation */
Harald Welte67089ee2018-01-17 22:19:03 +0100351 if (handler_mode) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200352 var RanOps ranops := MSC_RanOps;
353 ranops.use_osmux := g_osmux_enabled;
354 f_ran_adapter_init(g_bssap, mp_bssap_cfg, "VirtMSC", ranops);
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +0200355 connect(self:SCCPLITE_IPA_CTRL, g_bssap.vc_RAN:CTRL_CLIENT);
Harald Welte3ca0ce12019-04-23 17:18:48 +0200356 f_ran_adapter_start(g_bssap);
Harald Welte67089ee2018-01-17 22:19:03 +0100357 } else {
Harald Welte3ca0ce12019-04-23 17:18:48 +0200358 f_ran_adapter_init(g_bssap, mp_bssap_cfg, "VirtMSC", omit);
Harald Weltea4ca4462018-02-09 00:17:14 +0100359 connect(self:BSSAP, g_bssap.vc_SCCP:SCCP_SP_PORT);
Harald Welte3ca0ce12019-04-23 17:18:48 +0200360 f_ran_adapter_start(g_bssap);
Harald Weltea4ca4462018-02-09 00:17:14 +0100361 f_legacy_bssap_reset();
Harald Welte67089ee2018-01-17 22:19:03 +0100362 }
Harald Welted5833a82018-05-27 16:52:56 +0200363
Harald Welteffe55fc2018-01-17 22:39:54 +0100364 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +0100365
Daniel Willmann191e0d92018-01-17 12:44:35 +0100366 f_init_mgcp("VirtMSC");
367
Harald Welte89d42e82017-12-17 16:42:41 +0100368 for (i := 0; i < nr_bts; i := i+1) {
Harald Weltea5d2ab22017-12-09 14:21:42 +0100369 /* wait until osmo-bts-omldummy has respawned */
370 f_wait_oml(i, "degraded", 5.0);
371 /* start RSL connection */
Harald Welte624f9632017-12-16 19:26:04 +0100372 f_ipa_rsl_start(bts[i].rsl, mp_bsc_ip, mp_bsc_rsl_port, i, handler_mode);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100373 /* wait until BSC tells us "connected" */
374 f_wait_oml(i, "connected", 5.0);
Harald Welte696ddb62017-12-08 14:01:43 +0100375 }
376
Harald Welte28d943e2017-11-25 15:00:50 +0100377}
378
Maxd4e56962018-10-31 19:08:25 +0100379/* expect to receive a RSL message matching a specified template on a given BTS / stream */
Harald Welteae026692017-12-09 01:03:01 +0100380function f_exp_ipa_rx(integer bts_nr, template RSL_Message t_rx, float t_secs := 2.0, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
381runs on test_CT return RSL_Message {
382 var ASP_RSL_Unitdata rx_rsl_ud;
383 timer T := t_secs;
384
385 T.start;
386 alt {
387 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(sid, t_rx)) -> value rx_rsl_ud {
388 T.stop;
389 }
390 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +0100391 [] T.timeout {
392 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +0200393 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +0100394 }
Harald Welteae026692017-12-09 01:03:01 +0100395 }
396 return rx_rsl_ud.rsl;
397}
398
Harald Welte21b46bd2017-12-17 19:46:32 +0100399/* helper function to transmit RSL on a given BTS/stream */
Harald Welteae026692017-12-09 01:03:01 +0100400function f_ipa_tx(integer bts_nr, template RSL_Message t_tx, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
401runs on test_CT {
402 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(sid, t_tx));
403}
404
405
Harald Welte4003d112017-12-09 22:35:39 +0100406/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +0100407testcase TC_chan_act_noreply() runs on test_CT {
408 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +0100409 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +0100410
Harald Welte89d42e82017-12-17 16:42:41 +0100411 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +0100412
Harald Welteae026692017-12-09 01:03:01 +0100413 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 +0100414 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welteae026692017-12-09 01:03:01 +0100415 setverdict(pass);
Harald Welte28d943e2017-11-25 15:00:50 +0100416}
417
Harald Welte4003d112017-12-09 22:35:39 +0100418/* verify if the "chreq:total" counter increments as expected */
419testcase TC_chan_act_counter() runs on test_CT {
420 var BSSAP_N_UNITDATA_ind ud_ind;
421 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +0100422 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +0100423
Harald Welte89d42e82017-12-17 16:42:41 +0100424 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100425
426 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
427 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 +0100428 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welte4003d112017-12-09 22:35:39 +0100429 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total", chreq_total+1);
430
431 setverdict(pass);
432}
433
Harald Welteae026692017-12-09 01:03:01 +0100434/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
435testcase TC_chan_act_ack_noest() runs on test_CT {
436 var RSL_Message rx_rsl;
437
Harald Welte89d42e82017-12-17 16:42:41 +0100438 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100439
440 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100441 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100442
443 /* expect BSC to disable the channel again if there's no RLL EST IND */
444 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
445
446 setverdict(pass);
447}
448
449/* Test behavior if MSC never answers to CR */
450testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +0100451 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
452 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +0100453 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +0100454 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +0100455
Harald Welte89d42e82017-12-17 16:42:41 +0100456 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100457
458 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100459 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100460
461 var octetstring l3 := '00010203040506'O
462 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
463
464 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
465
466 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +0100467 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100468 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Harald Welteae026692017-12-09 01:03:01 +0100469 setverdict(pass);
470}
471
472/* Test behavior if MSC answers with CREF to CR */
473testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
474 var BSSAP_N_CONNECT_ind rx_c_ind;
475 var RSL_Message rx_rsl;
476
Harald Welte89d42e82017-12-17 16:42:41 +0100477 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100478
479 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100480 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100481
482 var octetstring l3 := '00010203040506'O
483 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
484
485 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
486 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
487
488 /* expect BSC to disable the channel */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100489 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Harald Welteae026692017-12-09 01:03:01 +0100490 setverdict(pass);
491}
492
Harald Welte618ef642017-12-14 14:58:20 +0100493/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
494testcase TC_chan_act_nack() runs on test_CT {
495 var RSL_Message rx_rsl;
496 var integer chact_nack;
497
Harald Welte89d42e82017-12-17 16:42:41 +0100498 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +0100499
500 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
501
502 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
503 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
504 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
505
506 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
507
508 /* wait for some time to hope the NACK arrives before the CTRL GET below */
509 f_sleep(0.5);
510
511 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
512
513 setverdict(pass);
514}
515
Harald Welte799c97b2017-12-14 17:50:30 +0100516/* Test for channel exhaustion due to RACH overload */
517testcase TC_chan_exhaustion() runs on test_CT {
518 var ASP_RSL_Unitdata rsl_ud;
519 var integer i;
520 var integer chreq_total, chreq_nochan;
521
Harald Welte89d42e82017-12-17 16:42:41 +0100522 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +0100523
524 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
525 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
526
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +0100527 /* GSM 04.08 Table 9.9a:
528 * RA = '33'O -> Establishment cause = 0011xxxx (MS dual rate capable and asks for "TCH/H or TCH/F").
529 * With current setup, expect 4xSDCCH + 4xTCH/F + 1xTCH/H to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +0200530 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 +0100531 var RslChannelNr chan_nr := f_chreq_act_ack('33'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +0100532 }
533
534 IPA_RSL[0].clear;
535
Harald Weltedd8cbf32018-01-28 12:07:52 +0100536 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200537 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +0100538
539 /* now expect additional channel activations to fail */
540 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
541
542 alt {
543 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
544 tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
545 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
546 }
547 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
548 var GsmRrMessage rr;
549 /* match on IMM ASS REJ */
550 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
551 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
552 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200553 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +0100554 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
555 chreq_nochan+1);
556 setverdict(pass);
557 } else {
558 repeat;
559 }
560 }
561 [] IPA_RSL[0].receive { repeat; }
562 }
563}
564
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +0700565/* Test channel deactivation due to silence from MS */
566testcase TC_chan_deact_silence() runs on test_CT {
567 var RslChannelNr chan_nr;
568
569 f_init(1);
570
571 /* Request for a dedicated channel */
572 chan_nr := f_chreq_act_ack('23'O);
573
574 /* Wait some time until the channel is released */
575 f_sleep(2.0);
576
577 /* Expect CHANnel RELease */
578 alt {
579 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
580 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
581 log("Received CHANnel RELease");
582 setverdict(pass);
583 }
584 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
585 tr_RSL_IMM_ASSIGN(?))) {
586 /* See OS#3709, OsmoBSC should not send Immediate
587 * Assignment Reject since a dedicated channel was
588 * already allocated, and Immediate Assignment was
589 * already sent. */
590 setverdict(fail, "Unexpected Immediate Assignment!");
591 }
592 [] IPA_RSL[0].receive {
593 setverdict(fail, "Unexpected RSL message!");
594 }
595 }
596}
597
Harald Weltecfe2c962017-12-15 12:09:32 +0100598/***********************************************************************
599 * Assignment Testing
600 ***********************************************************************/
601
Neels Hofmeyrda4a6952018-06-14 04:02:49 +0200602/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction,
603 * except for the inter-BSC handover, MT side) */
Harald Weltecfe2c962017-12-15 12:09:32 +0100604testcase TC_outbound_connect() runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +0100605 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +0100606
Harald Weltea4ca4462018-02-09 00:17:14 +0100607 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 +0100608 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
609 setverdict(pass);
610}
611
Harald Welte16a4adf2017-12-14 18:54:01 +0100612/* Test behavior if MSC answers with CREF to CR */
613testcase TC_assignment_cic_only() runs on test_CT {
614 var BSSAP_N_CONNECT_ind rx_c_ind;
615 var RSL_Message rx_rsl;
616 var DchanTuple dt;
617
Harald Welte89d42e82017-12-17 16:42:41 +0100618 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +0100619
620 dt := f_est_dchan('23'O, 23, '00000000'O);
Harald Welte17b27da2018-05-25 20:33:53 +0200621 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
622 /* send assignment without AoIP IEs */
623 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
624 } else {
625 /* Send assignmetn without CIC in IPA case */
626 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
627 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
628 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
629 }
Harald Welte16a4adf2017-12-14 18:54:01 +0100630 alt {
631 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
632 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
633 }
Harald Welte235ebf12017-12-15 14:18:16 +0100634 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +0100635 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
636 setverdict(pass);
637 }
638 [] BSSAP.receive { repeat; }
639 }
640}
641
Harald Welteed848512018-05-24 22:27:58 +0200642/* generate an assignment request for either AoIP or SCCPlite */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200643function f_gen_ass_req(boolean osmux_enabled := false) return PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200644 var PDU_BSSAP ass_cmd;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200645 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Harald Welteed848512018-05-24 22:27:58 +0200646 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
647 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
648 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200649 if (osmux_enabled) {
650 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla, osmux_cid));
651 } else {
652 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
653 }
Harald Welteed848512018-05-24 22:27:58 +0200654 } else {
655 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +0200656 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
Harald Welteed848512018-05-24 22:27:58 +0200657 }
658 return ass_cmd;
659}
660
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +0100661function f_gen_handover_req() return PDU_BSSAP {
662 var PDU_BSSAP ho_req;
663 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
664 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
665 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
666 ho_req := valueof(ts_BSSMAP_HandoverRequest(omit, tla));
667 } else {
668 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
669 ho_req := valueof(ts_BSSMAP_HandoverRequest(cic, omit));
670 }
671 return ho_req;
672}
673
Harald Welteed848512018-05-24 22:27:58 +0200674/* generate an assignment complete template for either AoIP or SCCPlite */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200675function f_gen_exp_compl(boolean expect_osmux := false) return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200676 var template PDU_BSSAP exp_compl;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200677 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Harald Welteed848512018-05-24 22:27:58 +0200678 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200679 if (expect_osmux) {
680 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, osmux_cid);
681 } else {
682 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, omit);
683 }
Harald Welteed848512018-05-24 22:27:58 +0200684 } else {
685 /* CIC is optional "*" as the MSC allocated it */
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +0200686 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
Harald Welteed848512018-05-24 22:27:58 +0200687 }
688 return exp_compl;
689}
690
Harald Welte235ebf12017-12-15 14:18:16 +0100691/* Run everything required up to sending a caller-specified assignment command and expect response */
692function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
693runs on test_CT {
694 var BSSAP_N_CONNECT_ind rx_c_ind;
695 var RSL_Message rx_rsl;
696 var DchanTuple dt;
697
Harald Welte89d42e82017-12-17 16:42:41 +0100698 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +0100699
700 dt := f_est_dchan('23'O, 23, '00000000'O);
701 /* send assignment without AoIP IEs */
702 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
703 alt {
704 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
705 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
706 setverdict(pass);
707 } else {
708 setverdict(fail, fail_text);
709 }
710 }
711 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
712 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
713 setverdict(pass);
714 } else {
715 setverdict(fail, fail_text);
716 }
717 }
718 [] BSSAP.receive { repeat; }
719 }
720}
721testcase TC_assignment_csd() runs on test_CT {
722 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200723 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100724 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
725 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
726 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
727}
728
729testcase TC_assignment_ctm() runs on test_CT {
730 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200731 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100732 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
733 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
734 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
735}
736
Harald Welte4003d112017-12-09 22:35:39 +0100737type record DchanTuple {
738 integer sccp_conn_id,
739 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +0100740}
741
Harald Welted6939652017-12-13 21:02:46 +0100742/* Send CHAN RQD and wait for allocation; acknowledge it */
743private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
744runs on test_CT return RslChannelNr {
745 var RSL_Message rx_rsl;
746 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
747 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
748 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
749 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
Daniel Willmannf4ac4ce2018-08-02 14:06:30 +0200750 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Harald Welted6939652017-12-13 21:02:46 +0100751 return chan_nr;
752}
753
Harald Welte4003d112017-12-09 22:35:39 +0100754/* helper function to establish a dedicated channel via BTS and MSC */
755function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
756runs on test_CT return DchanTuple {
757 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +0100758 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100759
Harald Welte4003d112017-12-09 22:35:39 +0100760 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100761 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +0100762
763 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
764
765 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
766 dt.sccp_conn_id := rx_c_ind.connectionId;
767 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
768
769 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100770}
771
Harald Welte641fcbe2018-06-14 10:58:35 +0200772/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
773private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
774 var RSL_Message rx_rsl;
775 /* expect BSC to disable the channel */
776 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
777 /* respond with CHAN REL ACK */
778 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
779
780 /* expect Clear Complete from BSC */
781 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
782
783 /* MSC disconnects as instructed. */
784 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
785}
786
Harald Welte4003d112017-12-09 22:35:39 +0100787/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
788testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100789 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100790 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +0100791
Harald Welte89d42e82017-12-17 16:42:41 +0100792 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +0100793
Harald Welte4003d112017-12-09 22:35:39 +0100794 dt := f_est_dchan('23'O, 23, '00010203040506'O);
795
796 /* simulate RLL REL IND */
797 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
798
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100799 /* expect Clear Request on MSC side */
800 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
801
802 /* Instruct BSC to clear channel */
803 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
804 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
805
Harald Welte4003d112017-12-09 22:35:39 +0100806 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200807 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100808
809 /* wait for SCCP emulation to do its job */
810 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +0100811
812 setverdict(pass);
813}
814
815/* Test behavior of channel release after CONN FAIL IND from BTS */
816testcase TC_chan_rel_conn_fail() runs on test_CT {
817 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100818 var DchanTuple dt;
819
Harald Welte89d42e82017-12-17 16:42:41 +0100820 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100821
822 dt := f_est_dchan('23'O, 23, '00010203040506'O);
823
824 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +0100825 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 +0100826 /* TODO: different cause values? */
827
Harald Welte4003d112017-12-09 22:35:39 +0100828 /* expect Clear Request from BSC */
829 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
830
831 /* Instruct BSC to clear channel */
832 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
833 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
834
Harald Welte6ff76ea2018-01-28 13:08:01 +0100835 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200836 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +0100837
838 /* wait for SCCP emulation to do its job */
839 f_sleep(1.0);
840
841 setverdict(pass);
842}
843
Harald Welte99f3ca02018-06-14 13:40:29 +0200844/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
845/* See also https://www.osmocom.org/issues/3182 */
846testcase TC_early_conn_fail() runs on test_CT {
847 var RSL_Message rx_rsl;
848 var DchanTuple dt;
849
850 f_init(1);
851
852 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
853 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_octstring(1), 23);
854
855 /* BTS->BSC: simulate CONN FAIL IND */
856 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
857
858 /* BTS->BSC: Expect RF channel release from BSC on Abis */
859 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
860
861 /* BTS<-BSC: respond with CHAN REL ACK */
862 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
863
864 setverdict(pass);
865}
866
867/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
868/* See also https://www.osmocom.org/issues/3182 */
869testcase TC_late_conn_fail() runs on test_CT {
870 var RSL_Message rx_rsl;
871 var DchanTuple dt;
872
873 f_init(1);
874
875 dt := f_est_dchan('23'O, 23, '00010203040506'O);
876
877 /* BSC<-MSC: Instruct BSC to clear connection */
878 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
879
880 /* BTS->BSC: expect BSC to deactivate SACCH */
881 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
882
883 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
884 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
885
886 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
887 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
888 /* BTS->BSC: respond with CHAN REL ACK */
889 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
890
891 /* BSC->MSC: expect Clear Complete from BSC */
892 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
893
894 /* BSC<-MSC: MSC disconnects as requested. */
895 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
896
897 setverdict(pass);
898}
899
Neels Hofmeyrf44ccd12018-11-05 19:15:23 +0100900function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr,
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100901 boolean expect_deact_sacch := true,
902 boolean expect_rr_chan_rel := true,
903 boolean expect_rll_rel_req := true,
Harald Welte99787102019-02-04 10:41:36 +0100904 boolean handle_rll_rel := true,
905 boolean is_csfb := false
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100906 ) runs on test_CT {
Harald Welte91d54a52018-01-28 15:35:07 +0100907
908 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100909 var boolean got_deact_sacch := false;
910 var boolean got_rr_chan_rel := false;
911 var boolean got_rll_rel_req := false;
912 log("f_expect_chan_rel() expecting: expect_deact_sacch=", expect_deact_sacch, " expect_rr_chan_rel=", expect_rr_chan_rel,
913 " expect_rll_rel_req=", expect_rll_rel_req);
Harald Welte91d54a52018-01-28 15:35:07 +0100914 alt {
Harald Welte91d54a52018-01-28 15:35:07 +0100915 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
916 tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100917 got_deact_sacch := true;
Harald Welte91d54a52018-01-28 15:35:07 +0100918 repeat;
919 }
Harald Welte99787102019-02-04 10:41:36 +0100920 [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))) {
921 got_rr_chan_rel := true;
922 repeat;
923 }
924 [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 +0100925 got_rr_chan_rel := true;
Neels Hofmeyr211169d2018-11-07 00:37:29 +0100926 repeat;
927 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100928 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
Harald Welte91d54a52018-01-28 15:35:07 +0100929 tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100930 got_rll_rel_req := true;
Harald Welte91d54a52018-01-28 15:35:07 +0100931 /* FIXME: Why are we getting this for LinkID SACCH? */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100932 if (handle_rll_rel) {
933 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
934 }
Harald Welte91d54a52018-01-28 15:35:07 +0100935 repeat;
936 }
Harald Welte91d54a52018-01-28 15:35:07 +0100937 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
938 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
939 /* respond with CHAN REL ACK */
940 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
941 }
942 /* ignore any user data */
943 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_MsgTypeR(?))) {
944 repeat;
945 }
946 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100947
948 log("f_expect_chan_rel() summary: got_deact_sacch=", got_deact_sacch, " got_rr_chan_rel=", got_rr_chan_rel,
949 " got_rll_rel_req=", got_rll_rel_req);
950
951 if (expect_deact_sacch != got_deact_sacch) {
952 setverdict(fail, "f_expect_chan_rel(): expect_deact_sacch=", expect_deact_sacch, " got_deact_sacch=", got_deact_sacch);
953 }
954 if (expect_rr_chan_rel != got_rr_chan_rel) {
955 setverdict(fail, "f_expect_chan_rel(): expect_rr_chan_rel=", expect_rr_chan_rel, " got_rr_chan_rel=", got_rr_chan_rel);
956 }
957 if (expect_rll_rel_req != got_rll_rel_req) {
958 setverdict(fail, "f_expect_chan_rel(): expect_rll_rel_req=", expect_rll_rel_req, " got_rll_rel_req=", got_rll_rel_req);
959 }
Harald Welte91d54a52018-01-28 15:35:07 +0100960}
961
Harald Welte4003d112017-12-09 22:35:39 +0100962/* Test behavior of channel release after hard Clear Command from MSC */
963testcase TC_chan_rel_hard_clear() runs on test_CT {
964 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100965 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +0100966
Harald Welte89d42e82017-12-17 16:42:41 +0100967 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100968
969 dt := f_est_dchan('23'O, 23, '00010203040506'O);
970
971 /* Instruct BSC to clear channel */
972 var BssmapCause cause := 0;
973 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
974
975 /* expect Clear Complete from BSC on A */
976 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
977 /* release the SCCP connection */
978 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
979 }
980
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100981 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte4003d112017-12-09 22:35:39 +0100982 setverdict(pass);
983}
984
Harald Welte99787102019-02-04 10:41:36 +0100985/* Test behavior of channel release after Clear Command with CSFB indicator from MSC */
986testcase TC_chan_rel_hard_clear_csfb() runs on test_CT {
987 var BSSAP_N_DATA_ind rx_di;
988 var DchanTuple dt;
989
990 f_init(1);
991
992 dt := f_est_dchan('23'O, 23, '00010203040506'O);
993
994 /* Instruct BSC to clear channel */
995 var BssmapCause cause := 0;
996 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
997
998 /* expect Clear Complete from BSC on A */
999 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
1000 /* release the SCCP connection */
1001 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1002 }
1003
1004 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, is_csfb := true);
1005 setverdict(pass);
1006}
1007
Harald Welted8c36cd2017-12-09 23:05:31 +01001008/* Test behavior of channel release after hard RLSD from MSC */
1009testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +01001010 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +01001011
Harald Welte89d42e82017-12-17 16:42:41 +01001012 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +01001013
1014 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1015
1016 /* release the SCCP connection */
1017 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1018
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001019 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welted8c36cd2017-12-09 23:05:31 +01001020 setverdict(pass);
1021}
1022
Harald Welte550daf92018-06-11 19:22:13 +02001023/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
1024testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
1025 var DchanTuple dt;
1026
1027 f_init(1);
1028
1029 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1030
1031 /* release the SCCP connection */
1032 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1033
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001034 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte550daf92018-06-11 19:22:13 +02001035 setverdict(pass);
1036}
1037
Harald Welte85804d42017-12-10 14:11:58 +01001038/* Test behavior of channel release after BSSMAP RESET from MSC */
1039testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +01001040 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +01001041
Harald Welte89d42e82017-12-17 16:42:41 +01001042 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +01001043
1044 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1045
1046 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
1047 IPA_RSL[0].clear;
1048
1049 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001050 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 +01001051 interleave {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001052 [] 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 +01001053 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
1054 }
1055
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001056 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte85804d42017-12-10 14:11:58 +01001057 setverdict(pass);
1058}
1059
Harald Welte5cd20ed2017-12-13 21:03:20 +01001060/* Test behavior if RSL EST IND for non-active channel */
1061testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
1062 timer T := 2.0;
1063
Harald Welte89d42e82017-12-17 16:42:41 +01001064 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001065
1066 var octetstring l3 := '00010203040506'O;
1067 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
1068 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1069
1070 T.start;
1071 alt {
1072 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1073 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
1074 }
1075 [] BSSAP.receive {}
1076 [] IPA_RSL[0].receive {}
1077 [] T.timeout {}
1078 }
1079
1080 setverdict(pass);
1081}
1082
1083/* Test behavior if RSL EST IND for invalid SAPI */
1084testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
1085 var RslChannelNr chan_nr;
1086
Harald Welte89d42e82017-12-17 16:42:41 +01001087 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001088
1089 chan_nr := f_chreq_act_ack()
1090
1091 var octetstring l3 := '00010203040506'O;
1092 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
1093
1094 timer T := 2.0;
1095 T.start;
1096 alt {
1097 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1098 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
1099 }
1100 [] BSSAP.receive { repeat; }
1101 [] IPA_RSL[0].receive { repeat; }
1102 [] T.timeout {}
1103 }
1104
1105 setverdict(pass);
1106}
1107
1108/* Test behavior if RSL EST IND for invalid SAPI */
1109testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
1110 timer T := 2.0;
1111
Harald Welte89d42e82017-12-17 16:42:41 +01001112 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001113
1114 var RslChannelNr chan_nr := f_chreq_act_ack();
1115
1116 var octetstring l3 := '00010203040506'O;
1117 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
1118
1119 T.start;
1120 alt {
1121 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1122 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
1123 }
1124 [] BSSAP.receive { repeat; }
1125 [] IPA_RSL[0].receive { repeat; }
1126 [] T.timeout {}
1127 }
1128
1129 setverdict(pass);
1130}
1131
1132/* Test behavior if RSL EST IND for invalid SACCH */
1133testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
1134 timer T := 2.0;
1135
Harald Welte89d42e82017-12-17 16:42:41 +01001136 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001137
1138 var RslChannelNr chan_nr := f_chreq_act_ack();
1139
1140 var octetstring l3 := '00010203040506'O;
1141 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
1142
1143 T.start;
1144 alt {
1145 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1146 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
1147 }
1148 [] BSSAP.receive { repeat; }
1149 [] IPA_RSL[0].receive { repeat; }
1150 [] T.timeout {}
1151 }
1152
1153 setverdict(pass);
1154}
1155
1156
1157
Harald Welte4003d112017-12-09 22:35:39 +01001158
1159testcase TC_ctrl_msc_connection_status() runs on test_CT {
1160 var charstring ctrl_resp;
1161
Harald Welte89d42e82017-12-17 16:42:41 +01001162 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001163
1164 /* See https://osmocom.org/issues/2729 */
1165 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
1166 setverdict(pass);
1167}
1168
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001169testcase TC_ctrl_msc0_connection_status() runs on test_CT {
1170 var charstring ctrl_resp;
1171
1172 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001173
1174 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
1175 setverdict(pass);
1176}
1177
Harald Welte4003d112017-12-09 22:35:39 +01001178testcase TC_ctrl() runs on test_CT {
1179 var charstring ctrl_resp;
1180
Harald Welte89d42e82017-12-17 16:42:41 +01001181 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001182
1183 /* all below values must match the osmo-bsc.cfg config file used */
1184
Harald Welte6a129692018-03-17 17:30:14 +01001185 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
1186 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Harald Welte44bdaa52017-12-17 17:01:47 +01001187 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "3");
Harald Welte4003d112017-12-09 22:35:39 +01001188
1189 var integer bts_nr := 0;
1190 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
1191 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
1192 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
1193 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
1194 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
1195 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
1196 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
1197
1198 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
1199 f_sleep(2.0);
1200 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
1201 setverdict(fail, "oml-uptime not incrementing as expected");
1202 }
1203 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
1204
1205 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
1206
1207 setverdict(pass);
Harald Welte96c94412017-12-09 03:12:45 +01001208}
1209
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02001210/* Verify that Upon receival of SET "location", BSC forwards a TRAP
1211 "location-state" over the SCCPlite IPA conn */
1212testcase TC_ctrl_location() runs on test_CT {
1213 var MSC_ConnHdlr vc_conn;
1214 var integer bts_nr := 0;
1215
1216 f_init(1, true);
1217 f_sleep(1.0);
1218
1219 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234567,fix3d,0.340000,0.560000,0.780000");
1220 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
1221 "1234567,fix3d,0.340000,0.560000,0.780000,operational,unlocked,on,001,01");
1222
1223 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "1");
1224 f_sleep(2.0);
1225
1226 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234888,fix3d,0.350000,0.570000,0.790000");
1227 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
1228 "1234888,fix3d,0.350000,0.570000,0.790000,operational,locked,off,001,01");
1229
1230 /* should match the one from config */
1231 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "0");
1232
1233 setverdict(pass);
1234}
1235
Harald Welte6f521d82017-12-11 19:52:02 +01001236function f_bssap_tx_ud(template PDU_BSSAP bssap) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +01001237 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, bssap));
Harald Welte6f521d82017-12-11 19:52:02 +01001238}
1239
1240
1241/***********************************************************************
1242 * Paging Testing
1243 ***********************************************************************/
1244
1245type record Cell_Identity {
1246 GsmMcc mcc,
1247 GsmMnc mnc,
1248 GsmLac lac,
1249 GsmCellId ci
1250};
Harald Welte24135bd2018-03-17 19:27:53 +01001251private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01001252private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01001253
Harald Welte5d1a2202017-12-13 19:51:29 +01001254type set of integer BtsIdList;
1255
1256private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
1257 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
1258 if (bts_id == bts_ids[j]) {
1259 return true;
1260 }
1261 }
1262 return false;
1263}
Harald Welte6f521d82017-12-11 19:52:02 +01001264
1265/* core paging test helper function; used by most paging test cases */
1266private function f_pageing_helper(hexstring imsi,
1267 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01001268 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01001269 template RSL_ChanNeeded rsl_chneed := omit,
1270 template OCT4 tmsi := omit) runs on test_CT
1271{
1272 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
1273 var MobileIdentity mi;
1274 var template octetstring id_enc; /* FIXME */
1275 var RSL_Message rx_rsl;
1276 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01001277 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01001278
1279 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01001280
1281 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01001282 for (i := 0; i < NUM_BTS; i := i + 1) {
1283 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01001284 }
Harald Welte6f521d82017-12-11 19:52:02 +01001285
1286 if (isvalue(rsl_chneed)) {
1287 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
1288 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
1289 } else {
1290 bssmap_chneed := omit;
1291 }
1292
1293 f_bssap_tx_ud(ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed));
1294
Pau Espin Pedrol76ba5412019-06-10 11:00:33 +02001295/* FIXME: Disabled due to bugs in both GSM_RR_Types and MobileL3_CommonIE_Types IMSI encoder
Harald Welte6f521d82017-12-11 19:52:02 +01001296 if (isvalue(tmsi)) {
1297 mi := valueof(t_Osmo_MI_TMSI(oct2int(valueof(tmsi))));
1298 } else {
1299 mi := valueof(ts_Osmo_MI_IMSI(imsi));
1300 }
1301 id_enc := enc_MobileIdentity(mi);
1302*/
1303 id_enc := ?;
Harald Welte5d1a2202017-12-13 19:51:29 +01001304 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
1305 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(id_enc));
1306 /* check channel type, paging group */
1307 if (rx_rsl.ies[1].body.paging_group != paging_group) {
1308 setverdict(fail, "Paging for wrong paging group");
1309 }
1310 if (ispresent(rsl_chneed) and
1311 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
1312 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
1313 }
Harald Welte6f521d82017-12-11 19:52:02 +01001314 }
Harald Welte2fccd982018-01-31 15:48:19 +01001315 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01001316 /* do a quick check on all not-included BTSs if they received paging */
1317 for (i := 0; i < NUM_BTS; i := i + 1) {
1318 timer T := 0.1;
1319 if (f_bts_in_list(i, bts_ids)) {
1320 continue;
1321 }
1322 T.start;
1323 alt {
1324 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(id_enc))) {
1325 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
1326 }
1327 [] IPA_RSL[i].receive { repeat; }
1328 [] T.timeout { }
1329 }
Harald Welte6f521d82017-12-11 19:52:02 +01001330 }
1331
1332 setverdict(pass);
1333}
1334
Harald Welte5d1a2202017-12-13 19:51:29 +01001335const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01001336const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01001337const BtsIdList c_BtsId_LAC1 := { 0, 1 };
1338const BtsIdList c_BtsId_LAC2 := { 2 };
1339
Harald Welte6f521d82017-12-11 19:52:02 +01001340/* PAGING by IMSI + TMSI */
1341testcase TC_paging_imsi_nochan() runs on test_CT {
1342 var BSSMAP_FIELD_CellIdentificationList cid_list;
1343 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01001344 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001345 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001346}
1347
1348/* PAGING by IMSI + TMSI */
1349testcase TC_paging_tmsi_nochan() runs on test_CT {
1350 var BSSMAP_FIELD_CellIdentificationList cid_list;
1351 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001352 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001353 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001354}
1355
1356/* Paging with different "channel needed' values */
1357testcase TC_paging_tmsi_any() runs on test_CT {
1358 var BSSMAP_FIELD_CellIdentificationList cid_list;
1359 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001360 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001361 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001362}
1363testcase TC_paging_tmsi_sdcch() runs on test_CT {
1364 var BSSMAP_FIELD_CellIdentificationList cid_list;
1365 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001366 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001367 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001368}
1369testcase TC_paging_tmsi_tch_f() runs on test_CT {
1370 var BSSMAP_FIELD_CellIdentificationList cid_list;
1371 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001372 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001373 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001374}
1375testcase TC_paging_tmsi_tch_hf() runs on test_CT {
1376 var BSSMAP_FIELD_CellIdentificationList cid_list;
1377 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001378 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001379 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001380}
1381
1382/* Paging by CGI */
1383testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
1384 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1385 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001386 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001387 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001388}
1389
1390/* Paging by LAC+CI */
1391testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
1392 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1393 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001394 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001395 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001396}
1397
1398/* Paging by CI */
1399testcase TC_paging_imsi_nochan_ci() runs on test_CT {
1400 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1401 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001402 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001403 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001404}
1405
1406/* Paging by LAI */
1407testcase TC_paging_imsi_nochan_lai() runs on test_CT {
1408 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1409 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001410 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001411 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001412}
1413
1414/* Paging by LAC */
1415testcase TC_paging_imsi_nochan_lac() runs on test_CT {
1416 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1417 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001418 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001419 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001420}
1421
1422/* Paging by "all in BSS" */
1423testcase TC_paging_imsi_nochan_all() runs on test_CT {
1424 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1425 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01001426 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001427 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001428}
1429
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001430/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001431testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
1432 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1433 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 +01001434 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001435 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001436}
Harald Welte6f521d82017-12-11 19:52:02 +01001437
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001438/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001439testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
1440 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1441 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001442 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001443 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001444}
1445
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001446/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001447testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
1448 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1449 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001450 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001451 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001452}
1453
Harald Welte6f521d82017-12-11 19:52:02 +01001454/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01001455testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
1456 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1457 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
1458 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001459 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001460}
1461
1462/* Paging on empty list: Verify none of them page */
1463testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
1464 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1465 cid_list := { cIl_LAC := { } };
1466 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001467 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001468}
1469
Stefan Sperling049a86e2018-03-20 15:51:00 +01001470/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
1471testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
1472 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1473 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
1474 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
1475 f_shutdown_helper();
1476}
1477
Harald Welte6f521d82017-12-11 19:52:02 +01001478/* Verify paging retransmission interval + count */
1479/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01001480/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01001481
Harald Weltee65d40e2017-12-13 00:09:06 +01001482/* Verify PCH load */
1483testcase TC_paging_imsi_load() runs on test_CT {
1484 var BSSMAP_FIELD_CellIdentificationList cid_list;
1485 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01001486 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01001487 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001488 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01001489
1490 /* tell BSC there is no paging space anymore */
1491 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01001492 f_sleep(0.2);
1493 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01001494
1495 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
1496 * there would be 8 retransmissions during 4 seconds */
1497 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01001498 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01001499 alt {
1500 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1501 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02001502 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01001503 }
Harald Welte2caa1062018-03-17 18:19:05 +01001504 [] T_retrans.timeout {
1505 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
1506 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
1507 T_retrans.start;
1508 repeat;
1509 }
Harald Weltee65d40e2017-12-13 00:09:06 +01001510 [] T.timeout {
1511 setverdict(pass);
1512 }
1513 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001514
1515 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01001516}
1517
Harald Welte235ebf12017-12-15 14:18:16 +01001518/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01001519testcase TC_paging_counter() runs on test_CT {
1520 var BSSMAP_FIELD_CellIdentificationList cid_list;
1521 timer T := 4.0;
1522 var integer i;
1523 var integer paging_attempted_bsc;
1524 var integer paging_attempted_bts[NUM_BTS];
1525 var integer paging_expired_bts[NUM_BTS];
1526 cid_list := valueof(ts_BSSMAP_CIL_noCell);
1527
1528 f_init();
1529
1530 /* read counters before paging */
1531 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
1532 for (i := 0; i < NUM_BTS; i := i+1) {
1533 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
1534 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
1535 }
1536
1537 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
1538
1539 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
1540 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
1541 for (i := 0; i < NUM_BTS; i := i+1) {
1542 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
1543 paging_attempted_bts[i]+1);
1544 }
1545
1546 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
1547 f_sleep(12.0);
1548 for (i := 0; i < NUM_BTS; i := i+1) {
1549 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
1550 paging_expired_bts[i]+1);
1551 }
Harald Welte1ff69992017-12-14 12:31:17 +01001552
Philipp Maier282ca4b2018-02-27 17:17:00 +01001553 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01001554}
1555
1556
Harald Welte10985002017-12-12 09:29:15 +01001557/* Verify paging stops after A-RESET */
1558testcase TC_paging_imsi_a_reset() runs on test_CT {
1559 var BSSMAP_FIELD_CellIdentificationList cid_list;
1560 timer T := 3.0;
1561 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001562 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01001563
1564 /* Perform a BSSMAP Reset and wait for ACK */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001565 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 +01001566 alt {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001567 [] 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 +01001568 [] BSSAP.receive { repeat; }
1569 }
1570
Daniel Willmanncbef3982018-07-30 09:22:40 +02001571 /* Wait to avoid a possible race condition if a paging message is
1572 * received right before the reset ACK. */
1573 f_sleep(0.2);
1574
Harald Welte10985002017-12-12 09:29:15 +01001575 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01001576 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
1577 IPA_RSL[i].clear;
1578 }
Harald Welte10985002017-12-12 09:29:15 +01001579
1580 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
1581 T.start;
1582 alt {
1583 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1584 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001585 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01001586 }
Harald Welte5d1a2202017-12-13 19:51:29 +01001587 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1588 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001589 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001590 }
1591 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1592 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001593 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001594 }
Harald Welte10985002017-12-12 09:29:15 +01001595 [] T.timeout {
1596 setverdict(pass);
1597 }
1598 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001599
1600 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01001601}
Harald Welteae026692017-12-09 01:03:01 +01001602
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001603/* Verify how we handle unsolicited Paging Response, for instance because we
1604 * receive a Paging Response after T3113 expired (and subscriber information was
1605 * dropped). See OS#3680.
1606 */
1607testcase TC_paging_resp_unsol() runs on test_CT {
1608
1609 f_init(1);
1610
1611 var BSSAP_N_CONNECT_ind rx_c_ind;
1612 var DchanTuple dt;
1613 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
1614
1615 /* Send CHAN RQD and wait for allocation; acknowledge it */
1616 dt.rsl_chan_nr := f_chreq_act_ack();
1617
1618 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
1619 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
1620
1621 /* expect BSC to disable the channel */
Pau Espin Pedrol5ee6f6c2018-12-07 12:07:43 +01001622 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001623 setverdict(pass);
1624
1625}
1626
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001627/* Test RSL link drop causes counter increment */
1628testcase TC_rsl_drop_counter() runs on test_CT {
1629 var integer rsl_fail;
1630
Harald Welte89d42e82017-12-17 16:42:41 +01001631 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001632
1633 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
1634
1635 bts[0].rsl.vc_IPA.stop;
1636
1637 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
1638
1639 setverdict(pass);
1640}
1641
1642/* TODO: Test OML link drop causes counter increment */
1643
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001644/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
1645function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
1646 timer T := 10.0;
1647
1648 bts[0].rsl.id := "IPA-0-RSL";
1649 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
1650 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
1651 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
1652 bts[0].rsl.ccm_pars.unit_id := "0/0/0"; /* value which is unknown at BTS */
1653
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001654 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
1655
1656 f_init_mgcp("VirtMSC");
1657
1658 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
1659 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
1660 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
1661 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
1662
1663 /* wait for IPA OML link to connect and then disconnect */
1664 T.start;
1665 alt {
1666 [] IPA_RSL[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) {
1667 T.stop;
1668 return true;
1669 }
1670 [] IPA_RSL[0].receive { repeat }
1671 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02001672 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001673 }
1674 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001675 return false;
1676}
1677
1678/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1679testcase TC_rsl_unknown_unit_id() runs on test_CT {
1680 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
1681 setverdict(pass);
1682 } else {
1683 setverdict(fail, "Timeout RSL waiting for connection to close");
1684 }
1685}
1686
1687
1688/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1689testcase TC_oml_unknown_unit_id() runs on test_CT {
1690 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
1691 setverdict(pass);
1692 } else {
1693 setverdict(fail, "Timeout OML waiting for connection to close");
1694 }
1695}
1696
1697
Harald Weltec1a2fff2017-12-17 11:06:19 +01001698/***********************************************************************
Harald Welte6811d102019-04-14 22:23:14 +02001699 * "New world" test cases using RSL_Emulation + RAN_Emulation
Harald Weltec1a2fff2017-12-17 11:06:19 +01001700 ***********************************************************************/
1701
Harald Welte6811d102019-04-14 22:23:14 +02001702import from RAN_Emulation all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01001703import from RSL_Emulation all;
1704import from MSC_ConnectionHandler all;
1705
1706type function void_fn(charstring id) runs on MSC_ConnHdlr;
1707
Harald Welte336820c2018-05-31 20:34:52 +02001708/* helper function to create and connect a MSC_ConnHdlr component */
Harald Welteff579f92018-05-31 22:19:39 +02001709private function f_connect_handler(inout MSC_ConnHdlr vc_conn) runs on test_CT {
Harald Welte6811d102019-04-14 22:23:14 +02001710 connect(vc_conn:RAN, g_bssap.vc_RAN:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001711 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001712 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01001713 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01001714 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01001715 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
1716 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
1717 }
Harald Welte6811d102019-04-14 22:23:14 +02001718 connect(vc_conn:BSSAP, g_bssap.vc_RAN:CLIENT);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001719 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Harald Welte336820c2018-05-31 20:34:52 +02001720}
1721
1722function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
1723runs on test_CT return MSC_ConnHdlr {
1724 var charstring id := testcasename();
1725 var MSC_ConnHdlr vc_conn;
1726 vc_conn := MSC_ConnHdlr.create(id);
1727 f_connect_handler(vc_conn);
Harald Weltea0630032018-03-20 21:09:55 +01001728 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001729 return vc_conn;
1730}
1731
Harald Weltea0630032018-03-20 21:09:55 +01001732/* first function inside ConnHdlr component; sets g_pars + starts function */
1733private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
1734runs on MSC_ConnHdlr {
1735 if (isvalue(pars)) {
1736 g_pars := valueof(pars);
1737 }
1738 fn.apply(id);
1739}
1740
Harald Welte3c86ea02018-05-10 22:28:05 +02001741/* Establish signalling channel (non-assignment case) followed by cipher mode */
1742private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001743 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1744 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02001745 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02001746 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
1747 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
1748 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
1749 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02001750
Philipp Maier23000732018-05-18 11:25:37 +02001751 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02001752}
1753testcase TC_ciph_mode_a5_0() runs on test_CT {
1754 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001755 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001756 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
1757
1758 f_init(1, true);
1759 f_sleep(1.0);
1760 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1761 vc_conn.done;
1762}
1763testcase TC_ciph_mode_a5_1() runs on test_CT {
1764 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001765 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001766 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
1767
1768 f_init(1, true);
1769 f_sleep(1.0);
1770 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1771 vc_conn.done;
1772}
1773testcase TC_ciph_mode_a5_3() runs on test_CT {
1774 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001775 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001776 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
1777
1778 f_init(1, true);
1779 f_sleep(1.0);
1780 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1781 vc_conn.done;
1782}
1783
1784
1785/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02001786private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001787 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1788 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01001789
Harald Welte552620d2017-12-16 23:21:36 +01001790 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1791 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01001792
Harald Weltea0630032018-03-20 21:09:55 +01001793 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01001794}
Harald Welte552620d2017-12-16 23:21:36 +01001795testcase TC_assignment_fr_a5_0() runs on test_CT {
1796 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001797 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001798 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01001799
Harald Welte89d42e82017-12-17 16:42:41 +01001800 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001801 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001802 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01001803 vc_conn.done;
1804}
Harald Welte552620d2017-12-16 23:21:36 +01001805testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01001806 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001807 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001808 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001809
Harald Welte89d42e82017-12-17 16:42:41 +01001810 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001811 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001812 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
1813 vc_conn.done;
1814}
1815testcase TC_assignment_fr_a5_3() runs on test_CT {
1816 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001817 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001818 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001819
Harald Welte651fcdc2018-05-10 20:23:16 +02001820 f_init(1, true);
1821 f_sleep(1.0);
1822 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001823 vc_conn.done;
1824}
1825
Harald Welte552620d2017-12-16 23:21:36 +01001826/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
1827private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001828 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01001829 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001830 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001831 const OCT8 kc := '0001020304050607'O;
1832
1833 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001834 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
1835
Harald Weltea0630032018-03-20 21:09:55 +01001836 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01001837}
Harald Welte552620d2017-12-16 23:21:36 +01001838testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
1839 var MSC_ConnHdlr vc_conn;
1840
Harald Welte89d42e82017-12-17 16:42:41 +01001841 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001842 f_sleep(1.0);
1843
Harald Welte8863fa12018-05-10 20:15:27 +02001844 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01001845 vc_conn.done;
1846}
1847
Harald Welte552620d2017-12-16 23:21:36 +01001848private function f_tc_assignment_fr_a5_4(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001849 g_pars := f_gen_test_hdlr_pars();
Harald Welteed848512018-05-24 22:27:58 +02001850 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1851 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001852 const OCT8 kc := '0001020304050607'O;
1853 const OCT16 kc128 := kc & kc;
1854
1855 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1856 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Weltea0630032018-03-20 21:09:55 +01001857 f_establish_fully(ass_cmd, exp_compl);
Harald Welte38b2a102017-12-23 02:42:58 +01001858 f_cipher_mode('10'O, kc, kc128, true);
Harald Welte552620d2017-12-16 23:21:36 +01001859 /* TODO: expect GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED cause value */
Harald Welte552620d2017-12-16 23:21:36 +01001860}
Harald Welte552620d2017-12-16 23:21:36 +01001861testcase TC_assignment_fr_a5_4() runs on test_CT {
1862 var MSC_ConnHdlr vc_conn;
1863
Harald Welte89d42e82017-12-17 16:42:41 +01001864 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001865 f_sleep(1.0);
1866
Harald Welte8863fa12018-05-10 20:15:27 +02001867 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_4));
Harald Welte552620d2017-12-16 23:21:36 +01001868 vc_conn.done;
1869}
1870
1871
Harald Welte4532e0a2017-12-23 02:05:44 +01001872private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001873 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01001874 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02001875 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01001876 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Harald Weltea0630032018-03-20 21:09:55 +01001877 f_establish_fully(ass_cmd, exp_compl);
Harald Welte4532e0a2017-12-23 02:05:44 +01001878}
1879
1880testcase TC_assignment_sign() runs on test_CT {
1881 var MSC_ConnHdlr vc_conn;
1882
1883 f_init(1, true);
1884 f_sleep(1.0);
1885
Harald Welte8863fa12018-05-10 20:15:27 +02001886 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01001887 vc_conn.done;
1888}
1889
Harald Welte60aa5762018-03-21 19:33:13 +01001890/***********************************************************************
1891 * Codec (list) testing
1892 ***********************************************************************/
1893
1894/* check if the given rsl_mode is compatible with the a_elem */
1895private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
1896return boolean {
1897 select (a_elem.codecType) {
1898 case (GSM_FR) {
1899 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
1900 return true;
1901 }
1902 }
1903 case (GSM_HR) {
1904 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
1905 return true;
1906 }
1907 }
1908 case (GSM_EFR) {
1909 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
1910 return true;
1911 }
1912 }
1913 case (FR_AMR) {
1914 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
1915 return true;
1916 }
1917 }
1918 case (HR_AMR) {
1919 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
1920 return true;
1921 }
1922 }
1923 case else { }
1924 }
1925 return false;
1926}
1927
1928/* check if the given rsl_mode is compatible with the a_list */
1929private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
1930return boolean {
1931 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
1932 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
1933 return true;
1934 }
1935 }
1936 return false;
1937}
1938
1939/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02001940function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01001941return BSSMAP_IE_ChannelType {
1942 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
1943 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
1944 select (a_elem.codecType) {
1945 case (GSM_FR) {
1946 ret.channelRateAndType := ChRate_TCHF;
1947 ret.speechId_DataIndicator := Spdi_TCHF_FR;
1948 }
1949 case (GSM_HR) {
1950 ret.channelRateAndType := ChRate_TCHH;
1951 ret.speechId_DataIndicator := Spdi_TCHH_HR;
1952 }
1953 case (GSM_EFR) {
1954 ret.channelRateAndType := ChRate_TCHF;
1955 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
1956 }
1957 case (FR_AMR) {
1958 ret.channelRateAndType := ChRate_TCHF;
1959 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
1960 }
1961 case (HR_AMR) {
1962 ret.channelRateAndType := ChRate_TCHH;
1963 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
1964 }
1965 case else {
1966 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02001967 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01001968 }
1969 }
1970 return ret;
1971}
1972
Harald Weltea63b9102018-03-22 20:36:16 +01001973private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
1974return template RSL_IE_Body {
1975 var template RSL_IE_Body mode_ie := {
1976 chan_mode := {
1977 len := ?,
1978 reserved := ?,
1979 dtx_d := ?,
1980 dtx_u := ?,
1981 spd_ind := RSL_SPDI_SPEECH,
1982 ch_rate_type := -,
1983 coding_alg_rate := -
1984 }
1985 }
1986
1987 select (a_elem.codecType) {
1988 case (GSM_FR) {
1989 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1990 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1991 }
1992 case (GSM_HR) {
1993 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1994 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1995 }
1996 case (GSM_EFR) {
1997 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1998 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
1999 }
2000 case (FR_AMR) {
2001 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
2002 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
2003 }
2004 case (HR_AMR) {
2005 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
2006 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
2007 }
2008 }
2009 return mode_ie;
2010}
2011
Harald Welte60aa5762018-03-21 19:33:13 +01002012type record CodecListTest {
2013 BSSMAP_IE_SpeechCodecList codec_list,
2014 charstring id
2015}
2016type record of CodecListTest CodecListTests
2017
2018private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02002019 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
2020 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
Harald Welte60aa5762018-03-21 19:33:13 +01002021
2022 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Harald Welte79f3f542018-05-25 20:02:37 +02002023 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
2024 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
2025 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
2026 g_pars.ass_codec_list.codecElements[0];
Philipp Maierd0e64b02019-03-13 14:15:23 +01002027 if (isvalue(g_pars.expect_mr_s0_s7)) {
2028 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
2029 g_pars.expect_mr_s0_s7;
2030 }
Harald Welte79f3f542018-05-25 20:02:37 +02002031 }
Harald Welte60aa5762018-03-21 19:33:13 +01002032 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
2033 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01002034 log("expecting ASS COMPL like this: ", exp_compl);
2035
2036 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01002037
2038 /* Verify that the RSL-side activation actually matches our expectations */
2039 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
2040
2041 var RSL_IE_Body mode_ie;
2042 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
2043 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02002044 mtc.stop;
Harald Weltea63b9102018-03-22 20:36:16 +01002045 }
2046 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
2047 if (not match(mode_ie, t_mode_ie)) {
2048 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
2049 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002050
2051 var RSL_IE_Body mr_conf;
2052 if (g_pars.expect_mr_conf_ie != omit) {
2053 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
2054 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
Daniel Willmannafce8662018-07-06 23:11:32 +02002055 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002056 }
2057 log("found RSL MR CONFIG IE: ", mr_conf);
2058
2059 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
2060 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
2061 g_pars.expect_mr_conf_ie);
2062 }
2063 } else {
2064 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
2065 log("found RSL MR CONFIG IE: ", mr_conf);
2066 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
Daniel Willmannafce8662018-07-06 23:11:32 +02002067 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002068 }
2069 }
Harald Welte60aa5762018-03-21 19:33:13 +01002070}
2071
Philipp Maierd0e64b02019-03-13 14:15:23 +01002072private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
2073
2074 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2075 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2076
2077 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
2078 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
2079 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
2080 }
2081 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
2082 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
2083 log("expecting ASS FAIL like this: ", exp_fail);
2084
2085 f_establish_fully(ass_cmd, exp_fail);
2086}
2087
Harald Welte60aa5762018-03-21 19:33:13 +01002088testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002089 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002090 var MSC_ConnHdlr vc_conn;
2091
2092 f_init(1, true);
2093 f_sleep(1.0);
2094
2095 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002096 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002097 vc_conn.done;
2098}
2099
2100testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002101 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002102 var MSC_ConnHdlr vc_conn;
2103
2104 f_init(1, true);
2105 f_sleep(1.0);
2106
2107 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002108 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002109 vc_conn.done;
2110}
2111
2112testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002113 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002114 var MSC_ConnHdlr vc_conn;
2115
2116 f_init(1, true);
2117 f_sleep(1.0);
2118
2119 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002120 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002121 vc_conn.done;
2122}
2123
Philipp Maierd0e64b02019-03-13 14:15:23 +01002124/* Allow 5,90k only (current default config) */
2125private function f_allow_amr_rate_5_90k() runs on test_CT {
2126 f_vty_enter_cfg_msc(BSCVTY, 0);
2127 f_vty_transceive(BSCVTY, "amr-config 12_2k forbidden");
2128 f_vty_transceive(BSCVTY, "amr-config 10_2k forbidden");
2129 f_vty_transceive(BSCVTY, "amr-config 7_95k forbidden");
2130 f_vty_transceive(BSCVTY, "amr-config 7_40k forbidden");
2131 f_vty_transceive(BSCVTY, "amr-config 6_70k forbidden");
2132 f_vty_transceive(BSCVTY, "amr-config 5_90k allowed");
2133 f_vty_transceive(BSCVTY, "amr-config 5_15k forbidden");
2134 f_vty_transceive(BSCVTY, "amr-config 4_75k forbidden");
2135 f_vty_transceive(BSCVTY, "exit");
2136 f_vty_transceive(BSCVTY, "exit");
2137}
2138
2139/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
2140 * ("Config-NB-Code = 1") */
2141private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
2142 f_vty_enter_cfg_msc(BSCVTY, 0);
2143 f_vty_transceive(BSCVTY, "amr-config 12_2k allowed");
2144 f_vty_transceive(BSCVTY, "amr-config 10_2k forbidden");
2145 f_vty_transceive(BSCVTY, "amr-config 7_95k forbidden");
2146 f_vty_transceive(BSCVTY, "amr-config 7_40k allowed");
2147 f_vty_transceive(BSCVTY, "amr-config 6_70k forbidden");
2148 f_vty_transceive(BSCVTY, "amr-config 5_90k allowed");
2149 f_vty_transceive(BSCVTY, "amr-config 5_15k forbidden");
2150 f_vty_transceive(BSCVTY, "amr-config 4_75k allowed");
2151 f_vty_transceive(BSCVTY, "exit");
2152 f_vty_transceive(BSCVTY, "exit");
2153}
2154
Harald Welte60aa5762018-03-21 19:33:13 +01002155testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002156 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002157 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02002158
2159 /* Note: This setups the codec configuration. The parameter payload in
2160 * mr_conf must be consistant with the parameter codecElements in pars
2161 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002162 var RSL_IE_Body mr_conf := {
2163 other := {
2164 len := 2,
2165 payload := '2804'O
2166 }
2167 };
Harald Welte60aa5762018-03-21 19:33:13 +01002168
Philipp Maier7695a0d2018-09-27 17:52:14 +02002169 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Philipp Maier806f8f12019-03-12 12:13:41 +01002170 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02002171 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
2172 pars.expect_mr_conf_ie := mr_conf;
2173
Harald Welte60aa5762018-03-21 19:33:13 +01002174 f_init(1, true);
2175 f_sleep(1.0);
2176
Harald Welte8863fa12018-05-10 20:15:27 +02002177 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002178 vc_conn.done;
2179}
2180
2181testcase TC_assignment_codec_amr_h() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002182 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002183 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02002184
2185 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002186 var RSL_IE_Body mr_conf := {
2187 other := {
2188 len := 2,
2189 payload := '2804'O
2190 }
2191 };
Harald Welte60aa5762018-03-21 19:33:13 +01002192
Philipp Maier7695a0d2018-09-27 17:52:14 +02002193 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Philipp Maier806f8f12019-03-12 12:13:41 +01002194 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02002195 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2196 pars.expect_mr_conf_ie := mr_conf;
2197
Harald Welte60aa5762018-03-21 19:33:13 +01002198 f_init(1, true);
2199 f_sleep(1.0);
2200
Harald Welte8863fa12018-05-10 20:15:27 +02002201 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002202 vc_conn.done;
2203}
2204
Philipp Maierd0e64b02019-03-13 14:15:23 +01002205function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0)
2206runs on test_CT {
2207
2208 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2209 var MSC_ConnHdlr vc_conn;
2210
2211 /* See note above */
2212 var RSL_IE_Body mr_conf := {
2213 other := {
2214 len := lengthof(mrconf),
2215 payload := mrconf
2216 }
2217 };
2218
2219 if (fr) {
2220 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
2221 } else {
2222 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2223 }
2224 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
2225 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2226 pars.expect_mr_conf_ie := mr_conf;
2227 pars.expect_mr_s0_s7 := exp_s8_s0;
2228
2229 f_init(1, true);
2230 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
2231 f_sleep(1.0);
2232
2233 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
2234 vc_conn.done;
2235 f_allow_amr_rate_5_90k();
2236}
2237
2238function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
2239runs on test_CT {
2240
2241 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2242 var MSC_ConnHdlr vc_conn;
2243
2244 if (fr) {
2245 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
2246 } else {
2247 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2248 }
2249 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
2250 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2251
2252 f_init(1, true);
2253 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
2254 f_sleep(1.0);
2255
2256 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
2257 vc_conn.done;
2258 f_allow_amr_rate_5_90k();
2259}
2260
2261
2262/* Set S1, we expect an AMR multirate configuration IE with all four rates
2263 * set. */
2264testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
2265 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
2266}
2267
2268/* Set S1, we expect an AMR multirate configuration IE with the lower three
2269 * rates set. */
2270testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
2271 f_TC_assignment_codec_amr(false, '2815208820'O, '00000010'B, '00000010'B);
2272}
2273
2274/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
2275 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
2276testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
2277 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'B, '00000010'B);
2278}
2279
2280/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
2281 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
2282testcase TC_assignment_codec_amr_h_S124() runs on test_CT {
2283 f_TC_assignment_codec_amr(false, '2815208820'O, '00010110'B, '00000010'B);
2284}
2285
2286/* The following block of tests selects more and more rates until all four
2287 * possible rates are in the active set (full rate) */
2288testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
2289 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'B);
2290}
2291
2292testcase TC_assignment_codec_amr_f_S02() runs on test_CT {
2293 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'B);
2294}
2295
2296testcase TC_assignment_codec_amr_f_S024() runs on test_CT {
2297 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'B);
2298}
2299
2300testcase TC_assignment_codec_amr_f_S0247() runs on test_CT {
2301 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
2302}
2303
2304/* The following block of tests selects more and more rates until all three
2305 * possible rates are in the active set (half rate) */
2306testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
2307 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'B);
2308}
2309
2310testcase TC_assignment_codec_amr_h_S02() runs on test_CT {
2311 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
2312}
2313
2314testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
2315 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
2316}
2317
2318/* The following block tests what happens when the MSC does offer rate
2319 * configurations that are not supported by the BSC. Normally such situations
2320 * should not happen because the MSC gets informed by the BSC in advance via
2321 * the L3 COMPLETE message which rates are applicable. The MSC should not try
2322 * to offer rates that are not applicable anyway. */
2323
2324testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
2325 /* Try to include 12,2k in into the active set even though the channel
2326 * is half rate only. The BSC is expected to remove the 12,0k */
2327 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'B);
2328}
2329
2330testcase TC_assignment_codec_amr_f_S01234567() runs on test_CT {
2331 /* See what happens when all rates are selected at once. Since then
2332 * Also S1 is selected, this setting will be prefered and we should
2333 * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
2334 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
2335}
2336
2337testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
2338 /* Same as above, but with S1 missing, the MSC is then expected to
2339 * select the currently supported rates, which are also 12.2k, 7,40k,
2340 * 5,90k, and 4,75k, into the active set. */
2341 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'B);
2342}
2343
2344testcase TC_assignment_codec_amr_f_zero() runs on test_CT {
2345 /* Try to select no rates at all */
2346 f_TC_assignment_codec_amr_fail(true, '00000000'B);
2347}
2348
2349testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
2350 /* Try to select only unsupported rates */
2351 f_TC_assignment_codec_amr_fail(true, '01101000'B);
2352}
2353
2354testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
2355 /* Try to select 12,2k for half rate */
2356 f_TC_assignment_codec_amr_fail(false, '10000000'B);
2357}
2358
Philipp Maierac09bfc2019-01-08 13:41:39 +01002359private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002360 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
2361 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
2362 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
2363 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002364}
2365
2366private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002367 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
2368 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002369}
2370
2371private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002372 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
2373 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
2374 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
2375 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
2376 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
2377 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002378}
2379
2380/* Allow HR only */
2381private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
2382 g_pars := f_gen_test_hdlr_pars();
2383 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2384 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2385 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2386 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
2387 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
2388 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
2389 f_establish_fully(ass_cmd, exp_compl);
2390}
2391
2392/* Allow FR only */
2393private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
2394 g_pars := f_gen_test_hdlr_pars();
2395 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2396 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2397 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2398 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
2399 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
2400 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2401 f_establish_fully(ass_cmd, exp_compl);
2402}
2403
2404/* Allow HR only (expect assignment failure) */
2405private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
2406 g_pars := f_gen_test_hdlr_pars();
2407 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2408 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2409 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2410 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
2411 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
2412 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
2413 f_establish_fully(ass_cmd, exp_fail);
2414}
2415
2416/* Allow FR only (expect assignment failure) */
2417private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(charstring id) runs on MSC_ConnHdlr {
2418 g_pars := f_gen_test_hdlr_pars();
2419 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2420 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2421 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2422 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
2423 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
2424 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2425 f_establish_fully(ass_cmd, exp_fail);
2426}
2427
2428/* Allow FR and HR, but prefer FR */
2429private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2430 g_pars := f_gen_test_hdlr_pars();
2431 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2432 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2433 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2434 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2435 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2436 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2437 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2438 f_establish_fully(ass_cmd, exp_compl);
2439}
2440
2441/* Allow FR and HR, but prefer HR */
2442private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2443 g_pars := f_gen_test_hdlr_pars();
2444 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2445 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2446 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2447 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2448 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2449 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2450 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2451 f_establish_fully(ass_cmd, exp_compl);
2452}
2453
2454/* Allow FR and HR, but prefer FR */
2455private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2456 g_pars := f_gen_test_hdlr_pars();
2457 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2458 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2459 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2460 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2461 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2462 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2463 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2464 f_establish_fully(ass_cmd, exp_compl);
2465}
2466
2467/* Allow FR and HR, but prefer HR */
2468private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2469 g_pars := f_gen_test_hdlr_pars();
2470 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2471 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2472 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2473 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2474 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2475 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2476 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2477 f_establish_fully(ass_cmd, exp_compl);
2478}
2479
2480/* Request a HR channel while all FR channels are exhausted, this is expected
2481 * to work without conflicts */
2482testcase TC_assignment_codec_fr_exhausted_req_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_xr_exhausted_req_hr));
2489 vc_conn.done;
2490 f_enable_all_tch();
2491 setverdict(pass);
2492}
2493
2494/* Request a FR channel while all FR channels are exhausted, this is expected
2495 * to fail. */
2496testcase TC_assignment_codec_fr_exhausted_req_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_xr_exhausted_req_fr_fail));
2503 vc_conn.done;
2504 f_enable_all_tch();
2505 setverdict(pass);
2506}
2507
2508/* Request a FR (prefered) or alternatively a HR channel while all FR channels
2509 * are exhausted, this is expected to be resolved by selecting a HR channel. */
2510testcase TC_assignment_codec_fr_exhausted_req_fr_hr() 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_f();
2516 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
2517 vc_conn.done;
2518 f_enable_all_tch();
2519 setverdict(pass);
2520}
2521
2522/* Request a HR (prefered) or alternatively a FR channel while all FR channels
2523 * are exhausted, this is expected to work without conflicts. */
2524testcase TC_assignment_codec_fr_exhausted_req_hr_fr() 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_f();
2530 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_hr_fr));
2531 vc_conn.done;
2532 f_enable_all_tch();
2533 setverdict(pass);
2534}
2535
2536/* Request a FR channel while all HR channels are exhausted, this is expected
2537 * to work without conflicts */
2538testcase TC_assignment_codec_hr_exhausted_req_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_xr_exhausted_req_fr));
2545 vc_conn.done;
2546 f_enable_all_tch();
2547 setverdict(pass);
2548}
2549
2550/* Request a HR channel while all HR channels are exhausted, this is expected
2551 * to fail. */
2552testcase TC_assignment_codec_hr_exhausted_req_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_xr_exhausted_req_hr_fail));
2559 vc_conn.done;
2560 f_enable_all_tch();
2561 setverdict(pass);
2562}
2563
2564/* Request a HR (prefered) or alternatively a FR channel while all HR channels
2565 * are exhausted, this is expected to be resolved by selecting a FR channel. */
2566testcase TC_assignment_codec_hr_exhausted_req_hr_fr() runs on test_CT {
2567 var MSC_ConnHdlr vc_conn;
2568 f_init(1, true);
2569 f_sleep(1.0);
2570 f_enable_all_tch();
2571 f_disable_all_tch_h();
2572 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_hr_fr));
2573 vc_conn.done;
2574 f_enable_all_tch();
2575 setverdict(pass);
2576}
2577
2578/* Request a FR (prefered) or alternatively a HR channel while all HR channels
2579 * are exhausted, this is expected to work without conflicts. */
2580testcase TC_assignment_codec_hr_exhausted_req_fr_hr() runs on test_CT {
2581 var MSC_ConnHdlr vc_conn;
2582 f_init(1, true);
2583 f_sleep(1.0);
2584 f_enable_all_tch();
2585 f_disable_all_tch_h();
2586 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_fr_hr));
2587 vc_conn.done;
2588 f_enable_all_tch();
2589 setverdict(pass);
2590}
2591
2592/* Allow FR and HR, but prefer HR */
2593private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2594 g_pars := f_gen_test_hdlr_pars();
2595 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2596 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2597 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2598 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2599 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2600 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2601 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2602 f_establish_fully(ass_cmd, exp_compl);
2603}
2604
2605/* Allow FR and HR, but prefer FR */
2606private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2607 g_pars := f_gen_test_hdlr_pars();
2608 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2609 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2610 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2611 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2612 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2613 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2614 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2615 f_establish_fully(ass_cmd, exp_compl);
2616}
2617
2618/* Request a HR (prefered) or alternatively a FR channel, it is expected that
2619 * HR, which is the prefered type, is selected. */
2620testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
2621 var MSC_ConnHdlr vc_conn;
2622 f_init(1, true);
2623 f_sleep(1.0);
2624 f_enable_all_tch();
2625 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
2626 vc_conn.done;
2627 setverdict(pass);
2628}
2629
2630/* Request a FR (prefered) or alternatively a HR channel, it is expected that
2631 * FR, which is the prefered type, is selected. */
2632testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
2633 var MSC_ConnHdlr vc_conn;
2634 f_init(1, true);
2635 f_sleep(1.0);
2636 f_enable_all_tch();
2637 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
2638 vc_conn.done;
2639 setverdict(pass);
2640}
2641
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02002642testcase TC_assignment_osmux() runs on test_CT {
2643 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2644 var MSC_ConnHdlr vc_conn;
2645
2646 /* See note above */
2647 var RSL_IE_Body mr_conf := {
2648 other := {
2649 len := 2,
2650 payload := '2804'O
2651 }
2652 };
2653
2654 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2655 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
2656 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2657 pars.expect_mr_conf_ie := mr_conf;
2658 pars.use_osmux := true;
2659
2660 f_init(1, true, true);
2661 f_sleep(1.0);
2662
2663 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
2664 vc_conn.done;
2665}
2666
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02002667/* test the procedure of the MSC requesting a Classmark Update:
2668 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
2669 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01002670private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002671 g_pars := f_gen_test_hdlr_pars();
2672
Harald Weltea0630032018-03-20 21:09:55 +01002673 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01002674 /* we should now have a COMPL_L3 at the MSC */
2675 BSSAP.receive(tr_BSSMAP_ComplL3);
2676
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02002677 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
2678 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
2679
Harald Welte898113b2018-01-31 18:32:21 +01002680 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
2681 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
2682 setverdict(pass);
2683}
2684testcase TC_classmark() runs on test_CT {
2685 var MSC_ConnHdlr vc_conn;
2686 f_init(1, true);
2687 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002688 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01002689 vc_conn.done;
2690}
2691
Harald Weltee3bd6582018-01-31 22:51:25 +01002692private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002693 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01002694 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01002695 /* we should now have a COMPL_L3 at the MSC */
2696 BSSAP.receive(tr_BSSMAP_ComplL3);
2697
Harald Weltee3bd6582018-01-31 22:51:25 +01002698 /* send the single message we want to send */
2699 f_rsl_send_l3(l3);
2700}
2701
2702private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
2703 timer T := sec;
2704 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01002705 T.start;
2706 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01002707 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
2708 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02002709 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01002710 }
2711 [] T.timeout {
2712 setverdict(pass);
2713 }
2714 }
2715}
2716
Harald Weltee3bd6582018-01-31 22:51:25 +01002717/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2718private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
2719 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
2720 f_bssap_expect_nothing();
2721}
Harald Welte898113b2018-01-31 18:32:21 +01002722testcase TC_unsol_ass_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_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01002727 vc_conn.done;
2728}
Harald Welte552620d2017-12-16 23:21:36 +01002729
Harald Welteea99a002018-01-31 20:46:43 +01002730
2731/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
2732private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002733 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
2734 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01002735}
2736testcase TC_unsol_ass_compl() runs on test_CT {
2737 var MSC_ConnHdlr vc_conn;
2738 f_init(1, true);
2739 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002740 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01002741 vc_conn.done;
2742}
2743
2744
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002745/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2746private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002747 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
2748 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002749}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002750testcase TC_unsol_ho_fail() runs on test_CT {
2751 var MSC_ConnHdlr vc_conn;
2752 f_init(1, true);
2753 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002754 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002755 vc_conn.done;
2756}
2757
2758
Harald Weltee3bd6582018-01-31 22:51:25 +01002759/* short message from MS should be ignored */
2760private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002761 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01002762 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01002763 /* we should now have a COMPL_L3 at the MSC */
2764 BSSAP.receive(tr_BSSMAP_ComplL3);
2765
2766 /* send short message */
2767 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
2768 f_bssap_expect_nothing();
2769}
2770testcase TC_err_82_short_msg() runs on test_CT {
2771 var MSC_ConnHdlr vc_conn;
2772 f_init(1, true);
2773 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002774 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01002775 vc_conn.done;
2776}
2777
2778
Harald Weltee9e02e42018-01-31 23:36:25 +01002779/* 24.008 8.4 Unknown message must trigger RR STATUS */
2780private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
2781 f_est_single_l3(ts_RRM_UL_REL('00'O));
2782 timer T := 3.0
2783 alt {
2784 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
2785 setverdict(pass);
2786 }
2787 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01002788 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01002789 }
2790}
2791testcase TC_err_84_unknown_msg() runs on test_CT {
2792 var MSC_ConnHdlr vc_conn;
2793 f_init(1, true);
2794 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002795 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01002796 vc_conn.done;
2797}
2798
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002799/***********************************************************************
2800 * Handover
2801 ***********************************************************************/
2802
Harald Welte94e0c342018-04-07 11:33:23 +02002803/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
2804private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
2805runs on test_CT {
2806 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2807 " timeslot "&int2str(ts_nr)&" ";
2808 f_vty_transceive(BSCVTY, cmd & suffix);
2809}
2810
Harald Welte261af4b2018-02-12 21:20:39 +01002811/* execute a "bts <0-255> trx <0-255> timeslot <0-7> sub-slot <0-7>" command on given Dchan */
2812private function f_vty_ss_action(charstring suffix, integer bts_nr, integer trx_nr, RslChannelNr chan_nr)
2813runs on MSC_ConnHdlr {
2814 /* FIXME: resolve those from component-global state */
2815 var integer ts_nr := chan_nr.tn;
2816 var integer ss_nr;
2817 if (ischosen(chan_nr.u.ch0)) {
2818 ss_nr := 0;
2819 } else if (ischosen(chan_nr.u.lm)) {
2820 ss_nr := chan_nr.u.lm.sub_chan;
2821 } else if (ischosen(chan_nr.u.sdcch4)) {
2822 ss_nr := chan_nr.u.sdcch4.sub_chan;
2823 } else if (ischosen(chan_nr.u.sdcch8)) {
2824 ss_nr := chan_nr.u.sdcch8.sub_chan;
2825 } else {
2826 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02002827 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01002828 }
2829
2830 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2831 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
2832 f_vty_transceive(BSCVTY, cmd & suffix);
2833}
2834
2835private function f_vty_handover(integer bts_nr, integer trx_nr, RslChannelNr chan_nr,
2836 integer new_bts_nr)
2837runs on MSC_ConnHdlr {
2838 f_vty_ss_action("handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
2839}
2840
2841/* intra-BSC hand-over between BTS0 and BTS1 */
2842private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002843 g_pars := f_gen_test_hdlr_pars();
Harald Welteed848512018-05-24 22:27:58 +02002844 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2845 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01002846 const OCT8 kc := '0001020304050607'O;
2847
2848 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2849 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2850
Harald Weltea0630032018-03-20 21:09:55 +01002851 f_establish_fully(ass_cmd, exp_compl);
Harald Welte261af4b2018-02-12 21:20:39 +01002852
2853 var HandoverState hs := {
2854 rr_ho_cmpl_seen := false,
2855 handover_done := false,
2856 old_chan_nr := -
2857 };
2858 /* issue hand-over command on VTY */
2859 f_vty_handover(0, 0, g_chan_nr, 1);
2860 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
2861 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002862
2863 /* From the MGW perspective, a handover is is characterized by
2864 * performing one MDCX operation with the MGW. So we expect to see
2865 * one more MDCX during handover. */
2866 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
2867
Harald Welte261af4b2018-02-12 21:20:39 +01002868 alt {
2869 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01002870 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002871
Philipp Maier4dae0652018-11-12 12:03:26 +01002872 /* Since this is an internal handover we expect the BSC to inform the
2873 * MSC about the event */
2874 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
2875
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002876 /* Check the amount of MGCP transactions is still consistant with the
2877 * test expectation */
2878 f_check_mgcp_expectations()
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01002879 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01002880}
2881
2882testcase TC_ho_int() runs on test_CT {
2883 var MSC_ConnHdlr vc_conn;
2884 f_init(2, true);
2885 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002886 vc_conn := f_start_handler(refers(f_tc_ho_int));
Harald Welte261af4b2018-02-12 21:20:39 +01002887 vc_conn.done;
2888}
Harald Weltee9e02e42018-01-31 23:36:25 +01002889
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002890private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002891 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002892
2893 var PDU_BSSAP ass_req := f_gen_ass_req();
2894 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2895 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2896 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2897 f_establish_fully(ass_req, exp_compl);
2898
2899 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2900
2901 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2902
2903 f_sleep(0.5);
2904 /* The MSC negotiates Handover Request and Handover Request Ack with
2905 * the other BSS and comes back with a BSSMAP Handover Command
2906 * containing an RR Handover Command coming from the target BSS... */
2907
2908 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
2909 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
2910 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
2911 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
2912 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
2913
2914 /* expect the Handover Command to go out on RR */
2915 var RSL_Message rsl_ho_cmd
2916 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
2917 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
2918 var RSL_IE_Body rsl_ho_cmd_l3;
2919 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
2920 log("RSL message contains no L3 Info IE, expected RR Handover Command");
2921 setverdict(fail);
2922 } else {
2923 log("Found L3 Info: ", rsl_ho_cmd_l3);
2924 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
2925 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
2926 setverdict(fail);
2927 } else {
2928 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
2929 setverdict(pass);
2930 }
2931 }
2932
2933 /* When the other BSS has reported a completed handover, this side is
2934 * torn down. */
2935
2936 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
2937 var BssmapCause cause := enum2int(cause_val);
2938 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
2939
2940 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
2941 var MgcpCommand mgcp;
2942 interleave {
2943 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
2944 [] MGCP.receive(tr_DLCX()) -> value mgcp {
2945 log("Got first DLCX: ", mgcp);
2946 }
2947 [] MGCP.receive(tr_DLCX()) -> value mgcp {
2948 log("Got second DLCX: ", mgcp);
2949 }
2950 }
2951 setverdict(pass);
2952 f_sleep(1.0);
2953}
2954testcase TC_ho_out_of_this_bsc() runs on test_CT {
2955 var MSC_ConnHdlr vc_conn;
2956
2957 f_init(1, true);
2958 f_sleep(1.0);
2959
2960 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
2961 vc_conn.done;
2962}
2963
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002964/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
2965 * simply never sends a BSSMAP Handover Command. */
2966private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01002967 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002968
2969 var PDU_BSSAP ass_req := f_gen_ass_req();
2970 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2971 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2972 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2973 f_establish_fully(ass_req, exp_compl);
2974
2975 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2976
2977 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2978
2979 /* osmo-bsc should time out 10 seconds after the handover started.
2980 * Let's give it a bit extra. */
2981 f_sleep(15.0);
2982
2983 /* The old lchan and conn should still be active. See that arbitrary L3
2984 * is still going through. */
2985 var octetstring l3 := '0123456789'O;
2986 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
2987 var template PDU_BSSAP exp_data := {
2988 discriminator := '1'B,
2989 spare := '0000000'B,
2990 dlci := '00'O,
2991 lengthIndicator := 5,
2992 pdu := {
2993 dtap := l3
2994 }
2995 };
2996 BSSAP.receive(exp_data);
2997 setverdict(pass);
2998 f_sleep(1.0);
2999}
3000testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
3001 var MSC_ConnHdlr vc_conn;
3002
3003 f_init(1, true);
3004 f_sleep(1.0);
3005
3006 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
3007 vc_conn.done;
3008}
3009
3010/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
3011 * RR Handover Failure. */
3012private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01003013 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003014
3015 var PDU_BSSAP ass_req := f_gen_ass_req();
3016 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3017 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3018 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3019 f_establish_fully(ass_req, exp_compl);
3020
3021 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
3022
3023 BSSAP.receive(tr_BSSMAP_HandoverRequired);
3024
3025 f_sleep(0.5);
3026 /* The MSC negotiates Handover Request and Handover Request Ack with
3027 * the other BSS and comes back with a BSSMAP Handover Command
3028 * containing an RR Handover Command coming from the target BSS... */
3029
3030 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
3031 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
3032 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
3033 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
3034 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
3035
3036 /* expect the Handover Command to go out on RR */
3037 var RSL_Message rsl_ho_cmd
3038 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
3039 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
3040 var RSL_IE_Body rsl_ho_cmd_l3;
3041 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
3042 log("RSL message contains no L3 Info IE, expected RR Handover Command");
3043 setverdict(fail);
3044 } else {
3045 log("Found L3 Info: ", rsl_ho_cmd_l3);
3046 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
3047 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
3048 setverdict(fail);
3049 } else {
3050 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
3051 setverdict(pass);
3052 }
3053 }
3054
3055 f_sleep(0.2);
3056 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
3057
3058 /* Should tell the MSC about the failure */
3059 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3060
3061 f_sleep(1.0);
3062
3063 /* The old lchan and conn should still be active. See that arbitrary L3
3064 * is still going through. */
3065 var octetstring l3 := '0123456789'O;
3066 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
3067 var template PDU_BSSAP exp_data := {
3068 discriminator := '1'B,
3069 spare := '0000000'B,
3070 dlci := '00'O,
3071 lengthIndicator := 5,
3072 pdu := {
3073 dtap := l3
3074 }
3075 };
3076 BSSAP.receive(exp_data);
3077 setverdict(pass);
3078 f_sleep(1.0);
3079
3080 setverdict(pass);
3081 f_sleep(1.0);
3082}
3083testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
3084 var MSC_ConnHdlr vc_conn;
3085
3086 f_init(1, true);
3087 f_sleep(1.0);
3088
3089 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
3090 vc_conn.done;
3091}
3092
3093/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
3094 * RR Handover Failure. */
3095private function f_tc_ho_out_fail_no_ho_detect(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01003096 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003097
3098 var PDU_BSSAP ass_req := f_gen_ass_req();
3099 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3100 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3101 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3102 f_establish_fully(ass_req, exp_compl);
3103
3104 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
3105
3106 BSSAP.receive(tr_BSSMAP_HandoverRequired);
3107
3108 f_sleep(0.5);
3109 /* The MSC negotiates Handover Request and Handover Request Ack with
3110 * the other BSS and comes back with a BSSMAP Handover Command
3111 * containing an RR Handover Command coming from the target BSS... */
3112
3113 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
3114 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
3115 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
3116 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
3117 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
3118
3119 /* expect the Handover Command to go out on RR */
3120 var RSL_Message rsl_ho_cmd
3121 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
3122 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
3123 var RSL_IE_Body rsl_ho_cmd_l3;
3124 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
3125 log("RSL message contains no L3 Info IE, expected RR Handover Command");
3126 setverdict(fail);
3127 } else {
3128 log("Found L3 Info: ", rsl_ho_cmd_l3);
3129 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
3130 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
3131 setverdict(fail);
3132 } else {
3133 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
3134 setverdict(pass);
3135 }
3136 }
3137
3138 /* The MS never shows up on the remote BSS. Eventually the BSC times
3139 * out and we run into 3GPP TS 48.008 3.1.5.3.3 "Abnormal Conditions":
3140 * RR should be released and Clear Request should go to the MSC. */
3141
3142 var MgcpCommand mgcp;
3143 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01003144 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
3145 log("Got Deact SACCH");
3146 }
Harald Welte924b6ea2019-02-04 01:05:34 +01003147 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01003148 log("Got RR Release");
3149 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003150 [] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
3151 log("Got RF Chan Rel");
3152 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
3153 }
3154 [] BSSAP.receive(tr_BSSMAP_ClearRequest) {
3155 log("Got BSSMAP Clear Request");
3156 }
3157 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3158 log("Got first DLCX: ", mgcp);
3159 }
3160 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3161 log("Got second DLCX: ", mgcp);
3162 }
3163 }
3164
3165 setverdict(pass);
3166 f_sleep(1.0);
3167}
3168testcase TC_ho_out_fail_no_ho_detect() runs on test_CT {
3169 var MSC_ConnHdlr vc_conn;
3170
3171 f_init(1, true);
3172 f_sleep(1.0);
3173
3174 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_ho_detect));
3175 vc_conn.done;
3176}
3177
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003178private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
3179 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
3180 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
3181 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
3182 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
3183 * before we get started. */
3184 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3185 f_rslem_register(0, new_chan_nr);
3186 g_chan_nr := new_chan_nr;
3187 f_sleep(1.0);
3188
3189 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3190 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3191 activate(as_Media());
3192
3193 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3194 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003195 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003196
3197 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3198
3199 var PDU_BSSAP rx_bssap;
3200 var octetstring ho_command_str;
3201
3202 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
Pau Espin Pedrol76ba5412019-06-10 11:00:33 +02003203
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003204 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3205 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3206 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3207 log("L3 Info in HO Request Ack is ", ho_command);
3208
3209 var GsmArfcn arfcn;
3210 var RslChannelNr actual_new_chan_nr;
3211 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3212 actual_new_chan_nr, arfcn);
3213
3214 if (actual_new_chan_nr != new_chan_nr) {
3215 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3216 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3217 setverdict(fail);
3218 return;
3219 }
3220 log("Handover Command chan_nr is", actual_new_chan_nr);
3221
3222 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3223 * tells the MS to handover to the new lchan. Here comes the new MS on
3224 * the new lchan with a Handover RACH: */
3225
3226 /* send handover detect */
3227
3228 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
3229
3230 BSSAP.receive(tr_BSSMAP_HandoverDetect);
3231
3232 /* send handover complete over the new channel */
3233
3234 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
3235 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
3236 enc_PDU_ML3_MS_NW(l3_tx)));
3237
3238 BSSAP.receive(tr_BSSMAP_HandoverComplete);
3239 setverdict(pass);
3240}
3241testcase TC_ho_into_this_bsc() runs on test_CT {
3242 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003243 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003244
3245 f_init(1, true);
3246 f_sleep(1.0);
3247
3248 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3249 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3250
3251 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
3252 vc_conn.done;
3253}
3254
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003255private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
3256 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3257 f_rslem_register(0, new_chan_nr);
3258 g_chan_nr := new_chan_nr;
3259 f_sleep(1.0);
3260
3261 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3262 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3263 activate(as_Media());
3264
3265 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3266 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003267 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003268
3269 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3270
3271 var PDU_BSSAP rx_bssap;
3272 var octetstring ho_command_str;
3273
3274 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3275
3276 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3277 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3278 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3279 log("L3 Info in HO Request Ack is ", ho_command);
3280
3281 var GsmArfcn arfcn;
3282 var RslChannelNr actual_new_chan_nr;
3283 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3284 actual_new_chan_nr, arfcn);
3285
3286 if (actual_new_chan_nr != new_chan_nr) {
3287 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3288 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3289 setverdict(fail);
3290 return;
3291 }
3292 log("Handover Command chan_nr is", actual_new_chan_nr);
3293
Neels Hofmeyr61ca08d2019-05-06 23:52:22 +02003294 /* For deterministic test results, give some time for the MGW endpoint to be configured */
3295 f_sleep(1.0);
3296
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003297 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3298 * tells the MS to handover to the new lchan. In this case, the MS
3299 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
3300 * Handover Failure to the MSC. The procedure according to 3GPP TS
3301 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
3302 * BSSMAP Clear Command: */
3303
3304 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3305 var BssmapCause cause := enum2int(cause_val);
3306 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3307
3308 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3309 var MgcpCommand mgcp;
3310 interleave {
3311 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3312 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3313 log("Got first DLCX: ", mgcp);
3314 }
3315 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3316 log("Got second DLCX: ", mgcp);
3317 }
3318 }
3319 setverdict(pass);
3320 f_sleep(1.0);
3321
3322 setverdict(pass);
3323}
3324testcase TC_ho_in_fail_msc_clears() runs on test_CT {
3325 var MSC_ConnHdlr vc_conn;
3326 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3327
3328 f_init(1, true);
3329 f_sleep(1.0);
3330
3331 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3332 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3333
3334 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
3335 vc_conn.done;
3336}
3337
3338private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
3339 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
3340 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
3341 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
3342 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
3343 * before we get started. */
3344 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3345 f_rslem_register(0, new_chan_nr);
3346 g_chan_nr := new_chan_nr;
3347 f_sleep(1.0);
3348
3349 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3350 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3351 activate(as_Media());
3352
3353 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3354 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003355 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003356
3357 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3358
3359 var PDU_BSSAP rx_bssap;
3360 var octetstring ho_command_str;
3361
3362 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3363
3364 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3365 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3366 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3367 log("L3 Info in HO Request Ack is ", ho_command);
3368
3369 var GsmArfcn arfcn;
3370 var RslChannelNr actual_new_chan_nr;
3371 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3372 actual_new_chan_nr, arfcn);
3373
3374 if (actual_new_chan_nr != new_chan_nr) {
3375 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3376 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3377 setverdict(fail);
3378 return;
3379 }
3380 log("Handover Command chan_nr is", actual_new_chan_nr);
3381
3382 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3383 * tells the MS to handover to the new lchan. Here comes the new MS on
3384 * the new lchan with a Handover RACH: */
3385
3386 /* send handover detect */
3387
3388 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
3389
3390 BSSAP.receive(tr_BSSMAP_HandoverDetect);
3391
3392 /* The MSC chooses to clear the connection now, maybe we got the
3393 * Handover RACH on the new cell but the MS still signaled Handover
3394 * Failure to the old BSS? */
3395
3396 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3397 var BssmapCause cause := enum2int(cause_val);
3398 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3399
3400 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3401 var MgcpCommand mgcp;
3402 interleave {
3403 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3404 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3405 log("Got first DLCX: ", mgcp);
3406 }
3407 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3408 log("Got second DLCX: ", mgcp);
3409 }
3410 }
3411 setverdict(pass);
3412 f_sleep(1.0);
3413}
3414testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
3415 var MSC_ConnHdlr vc_conn;
3416 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3417
3418 f_init(1, true);
3419 f_sleep(1.0);
3420
3421 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3422 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3423
3424 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
3425 vc_conn.done;
3426}
3427
3428/* The new BSS's lchan times out before the MSC decides that handover failed. */
3429private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
3430 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3431 f_rslem_register(0, new_chan_nr);
3432 g_chan_nr := new_chan_nr;
3433 f_sleep(1.0);
3434
3435 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3436 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3437 activate(as_Media());
3438
3439 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3440 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003441 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003442
3443 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3444
3445 var PDU_BSSAP rx_bssap;
3446 var octetstring ho_command_str;
3447
3448 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3449
3450 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3451 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3452 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3453 log("L3 Info in HO Request Ack is ", ho_command);
3454
3455 var GsmArfcn arfcn;
3456 var RslChannelNr actual_new_chan_nr;
3457 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3458 actual_new_chan_nr, arfcn);
3459
3460 if (actual_new_chan_nr != new_chan_nr) {
3461 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3462 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3463 setverdict(fail);
3464 return;
3465 }
3466 log("Handover Command chan_nr is", actual_new_chan_nr);
3467
3468 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3469 * tells the MS to handover to the new lchan. But the MS never shows up
3470 * on the new lchan. */
3471
3472 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3473
3474 /* Did osmo-bsc also send a Clear Request? */
3475 timer T := 0.5;
3476 T.start;
3477 alt {
3478 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
3479 [] T.timeout { }
3480 }
3481
3482 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
3483 * asked for it, this is a Handover Failure after all). */
3484
3485 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3486 var BssmapCause cause := enum2int(cause_val);
3487 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3488
3489 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3490 var MgcpCommand mgcp;
3491 interleave {
3492 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3493 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3494 log("Got first DLCX: ", mgcp);
3495 }
3496 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3497 log("Got second DLCX: ", mgcp);
3498 }
3499 }
3500 setverdict(pass);
3501 f_sleep(1.0);
3502
3503 setverdict(pass);
3504}
3505testcase TC_ho_in_fail_no_detect() runs on test_CT {
3506 var MSC_ConnHdlr vc_conn;
3507 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3508
3509 f_init(1, true);
3510 f_sleep(1.0);
3511
3512 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3513 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3514
3515 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
3516 vc_conn.done;
3517}
3518
3519/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
3520private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
3521 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3522 f_rslem_register(0, new_chan_nr);
3523 g_chan_nr := new_chan_nr;
3524 f_sleep(1.0);
3525
3526 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3527 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3528 activate(as_Media());
3529
3530 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3531 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003532 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003533
3534 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3535
3536 var PDU_BSSAP rx_bssap;
3537 var octetstring ho_command_str;
3538
3539 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3540
3541 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3542 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3543 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3544 log("L3 Info in HO Request Ack is ", ho_command);
3545
3546 var GsmArfcn arfcn;
3547 var RslChannelNr actual_new_chan_nr;
3548 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3549 actual_new_chan_nr, arfcn);
3550
3551 if (actual_new_chan_nr != new_chan_nr) {
3552 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3553 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3554 setverdict(fail);
3555 return;
3556 }
3557 log("Handover Command chan_nr is", actual_new_chan_nr);
3558
3559 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3560 * tells the MS to handover to the new lchan. But the MS never shows up
3561 * on the new lchan. */
3562
3563 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3564
3565 /* MSC plays dumb and sends no Clear Command */
3566
3567 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3568 var PDU_BSSAP rx_clear_request;
3569 var MgcpCommand mgcp;
3570 interleave {
3571 [] BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
3572 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
3573 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3574 };
3575 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3576
3577 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3578 log("Got first DLCX: ", mgcp);
3579 }
3580 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3581 log("Got second DLCX: ", mgcp);
3582 }
3583 }
3584 setverdict(pass);
3585 f_sleep(1.0);
3586}
3587testcase TC_ho_in_fail_no_detect2() runs on test_CT {
3588 var MSC_ConnHdlr vc_conn;
3589 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3590
3591 f_init(1, true);
3592 f_sleep(1.0);
3593
3594 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3595 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3596
3597 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
3598 vc_conn.done;
3599}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003600
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003601/* OS#3041: Open and close N connections in a normal fashion, and expect no
3602 * BSSMAP Reset just because of that. */
3603testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
3604 var default d;
3605 var integer i;
3606 var DchanTuple dt;
3607
3608 f_init();
3609
3610 /* Wait for initial BSSMAP Reset to pass */
3611 f_sleep(4.0);
3612
3613 d := activate(no_bssmap_reset());
3614
3615 /* Setup up a number of connections and RLSD them again from the MSC
3616 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3617 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02003618 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003619 /* Since we're doing a lot of runs, give each one a fresh
3620 * T_guard from the top. */
3621 T_guard.start;
3622
3623 /* Setup a BSSAP connection and clear it right away. This is
3624 * the MSC telling the BSC about a planned release, it's not an
3625 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02003626 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003627
3628 /* MSC disconnects (RLSD). */
3629 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
3630 }
3631
3632 /* In the buggy behavior, a timeout of 2 seconds happens between above
3633 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3634 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3635 f_sleep(4.0);
3636
3637 deactivate(d);
3638 f_shutdown_helper();
3639}
Harald Welte552620d2017-12-16 23:21:36 +01003640
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003641/* OS#3041: Open and close N connections in a normal fashion, and expect no
3642 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
3643 * the MSC. */
3644testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
3645 var default d;
3646 var integer i;
3647 var DchanTuple dt;
3648 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003649 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
3650 var BssmapCause cause := enum2int(cause_val);
3651
3652 f_init();
3653
3654 /* Wait for initial BSSMAP Reset to pass */
3655 f_sleep(4.0);
3656
3657 d := activate(no_bssmap_reset());
3658
3659 /* Setup up a number of connections and RLSD them again from the MSC
3660 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3661 * Let's do it some more times for good measure. */
3662 for (i := 0; i < 8; i := i+1) {
3663 /* Since we're doing a lot of runs, give each one a fresh
3664 * T_guard from the top. */
3665 T_guard.start;
3666
3667 /* Setup a BSSAP connection and clear it right away. This is
3668 * the MSC telling the BSC about a planned release, it's not an
3669 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02003670 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003671
3672 /* Instruct BSC to clear channel */
3673 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
3674
3675 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02003676 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003677 }
3678
3679 /* In the buggy behavior, a timeout of 2 seconds happens between above
3680 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3681 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3682 f_sleep(4.0);
3683
3684 deactivate(d);
3685 f_shutdown_helper();
3686}
3687
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003688/* OS#3041: Open and close N connections in a normal fashion, and expect no
3689 * BSSMAP Reset just because of that. Close connections from the MS side with a
3690 * Release Ind on RSL. */
3691testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
3692 var default d;
3693 var integer i;
3694 var DchanTuple dt;
3695 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003696 var integer j;
3697
3698 f_init();
3699
3700 /* Wait for initial BSSMAP Reset to pass */
3701 f_sleep(4.0);
3702
3703 d := activate(no_bssmap_reset());
3704
3705 /* Setup up a number of connections and RLSD them again from the MSC
3706 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3707 * Let's do it some more times for good measure. */
3708 for (i := 0; i < 8; i := i+1) {
3709 /* Since we're doing a lot of runs, give each one a fresh
3710 * T_guard from the top. */
3711 T_guard.start;
3712
3713 /* Setup a BSSAP connection and clear it right away. This is
3714 * the MSC telling the BSC about a planned release, it's not an
3715 * erratic loss of a connection. */
3716 dt := f_est_dchan('23'O, 23, '00010203040506'O);
3717
3718 /* simulate RLL REL IND */
3719 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
3720
3721 /* expect Clear Request on MSC side */
3722 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
3723
3724 /* Instruct BSC to clear channel */
3725 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
3726 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
3727
3728 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02003729 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003730 }
3731
3732 /* In the buggy behavior, a timeout of 2 seconds happens between above
3733 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3734 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3735 f_sleep(4.0);
3736
3737 deactivate(d);
3738 f_shutdown_helper();
3739}
3740
Harald Welte94e0c342018-04-07 11:33:23 +02003741/***********************************************************************
3742 * IPA style dynamic PDCH
3743 ***********************************************************************/
3744
3745private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
3746 template (omit) RSL_Cause nack := omit)
3747runs on test_CT {
3748 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
3749 var RSL_Message rsl_unused;
3750 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3751 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
3752 /* expect the BSC to issue the related RSL command */
3753 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3754 if (istemplatekind(nack, "omit")) {
3755 /* respond with a related acknowledgement */
3756 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3757 } else {
3758 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
3759 }
3760}
3761
3762private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
3763 template (omit) RSL_Cause nack := omit)
3764runs on test_CT {
3765 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
3766 var RSL_Message rsl_unused;
3767 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3768 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
3769 /* expect the BSC to issue the related RSL command */
3770 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
3771 if (istemplatekind(nack, "omit")) {
3772 /* respond with a related acknowledgement */
3773 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
3774 } else {
3775 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
3776 }
3777}
3778
3779private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
3780runs on test_CT return charstring {
3781 var charstring cmd, resp;
3782 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01003783 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02003784}
3785
3786private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
3787 template charstring exp)
3788runs on test_CT {
3789 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
3790 if (not match(mode, exp)) {
3791 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02003792 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02003793 }
3794}
3795
3796private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
3797runs on test_CT {
3798 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
3799 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
3800 f_vty_transceive(BSCVTY, "end");
3801}
3802
3803private const charstring TCHF_MODE := "TCH/F mode";
3804private const charstring TCHH_MODE := "TCH/H mode";
3805private const charstring PDCH_MODE := "PDCH mode";
3806private const charstring NONE_MODE := "NONE mode";
3807
3808/* Test IPA PDCH activation / deactivation triggered by VTY */
3809testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
3810 var RSL_Message rsl_unused;
3811
3812 /* change Timeslot 6 before f_init() starts RSL */
3813 f_init_vty();
3814 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
3815 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3816
3817 f_init(1, false);
3818 f_sleep(1.0);
3819
3820 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
3821
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003822 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003823 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3824 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3825 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3826 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3827 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003828 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003829 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3830
3831 /* De-activate it via VTY */
3832 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3833 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003834 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003835 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3836
3837 /* re-activate it via VTY */
3838 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
3839 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003840 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003841 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3842
3843 /* and finally de-activate it again */
3844 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3845 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003846 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003847 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3848
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003849 /* clean up config */
3850 f_ts_set_chcomb(0, 0, 6, "PDCH");
3851
Harald Welte94e0c342018-04-07 11:33:23 +02003852 setverdict(pass);
3853}
3854
3855/* Test IPA PDCH activation NACK */
3856testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
3857 var RSL_Message rsl_unused;
3858
3859 /* change Timeslot 6 before f_init() starts RSL */
3860 f_init_vty();
3861 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
3862 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3863
3864 f_init(1, false);
3865 f_sleep(1.0);
3866
3867 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
3868
3869 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3870 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3871 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3872 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3873 f_sleep(1.0);
3874 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3875
3876 /* De-activate it via VTY */
3877 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3878 f_sleep(1.0);
3879 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3880
3881 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
3882 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
3883 f_sleep(1.0);
3884 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3885
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003886 /* clean up config */
3887 f_ts_set_chcomb(0, 0, 6, "PDCH");
3888
Harald Welte94e0c342018-04-07 11:33:23 +02003889 setverdict(pass);
3890}
3891
3892
3893/***********************************************************************
3894 * Osmocom style dynamic PDCH
3895 ***********************************************************************/
3896
3897private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
3898 template (omit) RSL_Cause nack := omit)
3899runs on test_CT {
3900 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
3901 var RSL_Message rsl_unused;
3902 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3903 /* FIXME: no VTY command to activate Osmocom PDCH !! */
3904 /* expect the BSC to issue the related RSL command */
3905 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
3906 if (istemplatekind(nack, "omit")) {
3907 /* respond with a related acknowledgement */
3908 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
3909 } else {
3910 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
3911 }
3912}
3913
3914private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
3915 template (omit) RSL_Cause nack := omit)
3916runs on test_CT {
3917 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
3918 var RSL_Message rsl_unused;
3919 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3920 /* FIXME: no VTY command to activate Osmocom PDCH !! */
3921 /* expect the BSC to issue the related RSL command */
3922 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
3923 if (istemplatekind(nack, "omit")) {
3924 /* respond with a related acknowledgement */
3925 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
3926 } else {
3927 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
3928 }
3929}
3930
3931/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
3932testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
3933 var RSL_Message rsl_unused;
3934
3935 /* change Timeslot 6 before f_init() starts RSL */
3936 f_init_vty();
3937 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
3938 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3939
3940 f_init(1, false);
3941 f_sleep(1.0);
3942
3943 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
3944
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003945 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003946 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
3947 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3948 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
3949
3950 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
3951 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003952 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 +02003953 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3954
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003955 /* clean up config */
3956 f_ts_set_chcomb(0, 0, 6, "PDCH");
3957
Harald Welte94e0c342018-04-07 11:33:23 +02003958 setverdict(pass);
3959}
3960
3961/* Test Osmocom dyn PDCH activation NACK behavior */
3962testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
3963 var RSL_Message rsl_unused;
3964
3965 /* change Timeslot 6 before f_init() starts RSL */
3966 f_init_vty();
3967 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
3968 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3969
3970 f_init(1, false);
3971 f_sleep(1.0);
3972
3973 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
3974
3975 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
3976 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3977 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
3978
3979 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
3980 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
3981 f_sleep(1.0);
3982 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
3983
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003984 /* clean up config */
3985 f_ts_set_chcomb(0, 0, 6, "PDCH");
3986
Harald Welte94e0c342018-04-07 11:33:23 +02003987 setverdict(pass);
3988}
3989
Stefan Sperling0796a822018-10-05 13:01:39 +02003990testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02003991 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02003992 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
3993 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
3994 }
3995}
3996
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02003997testcase TC_chopped_ipa_payload() runs on test_CT {
3998 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
3999 /* TODO: mp_bsc_ctrl_port does not work yet */};
4000 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
4001 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
4002 }
4003}
4004
4005
Harald Welte0ea2d5e2018-04-07 21:40:29 +02004006/* Dyn PDCH todo:
4007 * activate OSMO as TCH/F
4008 * activate OSMO as TCH/H
4009 * does the BSC-located PCU socket get the updated INFO?
4010 * what if no PCU is connected at the time?
4011 * is the info correct on delayed PCU (re)connect?
4012 */
Harald Welte94e0c342018-04-07 11:33:23 +02004013
Harald Welte28d943e2017-11-25 15:00:50 +01004014control {
Harald Welte898113b2018-01-31 18:32:21 +01004015 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +01004016 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01004017 execute( TC_ctrl_msc0_connection_status() );
Harald Welte96c94412017-12-09 03:12:45 +01004018 execute( TC_ctrl() );
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02004019 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_SCCPlite_SERVER) {
4020 execute( TC_ctrl_location() );
4021 }
Harald Welte898113b2018-01-31 18:32:21 +01004022
4023 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +01004024 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +01004025 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +01004026 execute( TC_chan_act_ack_noest() );
4027 execute( TC_chan_act_ack_est_ind_noreply() );
4028 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +01004029 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +01004030 execute( TC_chan_exhaustion() );
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07004031 execute( TC_chan_deact_silence() );
Harald Welte4003d112017-12-09 22:35:39 +01004032 execute( TC_chan_rel_rll_rel_ind() );
4033 execute( TC_chan_rel_conn_fail() );
4034 execute( TC_chan_rel_hard_clear() );
Harald Welte99787102019-02-04 10:41:36 +01004035 execute( TC_chan_rel_hard_clear_csfb() );
Harald Welted8c36cd2017-12-09 23:05:31 +01004036 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +02004037 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +01004038 execute( TC_chan_rel_a_reset() );
Harald Welte6f521d82017-12-11 19:52:02 +01004039
Harald Weltecfe2c962017-12-15 12:09:32 +01004040 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +01004041
4042 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +01004043 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +01004044 execute( TC_assignment_csd() );
4045 execute( TC_assignment_ctm() );
4046 execute( TC_assignment_sign() );
4047 execute( TC_assignment_fr_a5_0() );
4048 execute( TC_assignment_fr_a5_1() );
Harald Welte8f67d1d2018-05-25 20:38:42 +02004049 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
4050 execute( TC_assignment_fr_a5_1_codec_missing() );
4051 }
Harald Welte235ebf12017-12-15 14:18:16 +01004052 execute( TC_assignment_fr_a5_3() );
4053 execute( TC_assignment_fr_a5_4() );
Harald Welte3c86ea02018-05-10 22:28:05 +02004054 execute( TC_ciph_mode_a5_0() );
4055 execute( TC_ciph_mode_a5_1() );
4056 execute( TC_ciph_mode_a5_3() );
Harald Welte16a4adf2017-12-14 18:54:01 +01004057
Harald Welte60aa5762018-03-21 19:33:13 +01004058 execute( TC_assignment_codec_fr() );
4059 execute( TC_assignment_codec_hr() );
4060 execute( TC_assignment_codec_efr() );
4061 execute( TC_assignment_codec_amr_f() );
4062 execute( TC_assignment_codec_amr_h() );
Philipp Maier8a581d22019-03-26 18:32:48 +01004063
4064 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
4065 execute( TC_assignment_codec_amr_f_S1() );
4066 execute( TC_assignment_codec_amr_h_S1() );
4067 execute( TC_assignment_codec_amr_f_S124() );
4068 execute( TC_assignment_codec_amr_h_S124() );
4069 execute( TC_assignment_codec_amr_f_S0() );
4070 execute( TC_assignment_codec_amr_f_S02() );
4071 execute( TC_assignment_codec_amr_f_S024() );
4072 execute( TC_assignment_codec_amr_f_S0247() );
4073 execute( TC_assignment_codec_amr_h_S0() );
4074 execute( TC_assignment_codec_amr_h_S02() );
4075 execute( TC_assignment_codec_amr_h_S024() );
4076 execute( TC_assignment_codec_amr_h_S0247() );
4077 execute( TC_assignment_codec_amr_f_S01234567() );
4078 execute( TC_assignment_codec_amr_f_S0234567() );
4079 execute( TC_assignment_codec_amr_f_zero() );
4080 execute( TC_assignment_codec_amr_f_unsupp() );
4081 execute( TC_assignment_codec_amr_h_S7() );
4082 }
Harald Welte60aa5762018-03-21 19:33:13 +01004083
Philipp Maierac09bfc2019-01-08 13:41:39 +01004084 execute( TC_assignment_codec_fr_exhausted_req_hr() );
4085 execute( TC_assignment_codec_fr_exhausted_req_fr() );
4086 execute( TC_assignment_codec_fr_exhausted_req_fr_hr() );
4087 execute( TC_assignment_codec_fr_exhausted_req_hr_fr() );
4088 execute( TC_assignment_codec_hr_exhausted_req_fr() );
4089 execute( TC_assignment_codec_hr_exhausted_req_hr() );
4090 execute( TC_assignment_codec_hr_exhausted_req_hr_fr() );
4091 execute( TC_assignment_codec_hr_exhausted_req_fr_hr() );
4092 execute( TC_assignment_codec_req_hr_fr() );
4093 execute( TC_assignment_codec_req_fr_hr() );
4094
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +02004095 if (mp_enable_osmux_test) {
4096 execute( TC_assignment_osmux() );
4097 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004098
Harald Welte898113b2018-01-31 18:32:21 +01004099 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +01004100 execute( TC_rll_est_ind_inact_lchan() );
4101 execute( TC_rll_est_ind_inval_sapi1() );
4102 execute( TC_rll_est_ind_inval_sapi3() );
4103 execute( TC_rll_est_ind_inval_sacch() );
4104
Harald Welte898113b2018-01-31 18:32:21 +01004105 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +01004106 execute( TC_paging_imsi_nochan() );
4107 execute( TC_paging_tmsi_nochan() );
4108 execute( TC_paging_tmsi_any() );
4109 execute( TC_paging_tmsi_sdcch() );
4110 execute( TC_paging_tmsi_tch_f() );
4111 execute( TC_paging_tmsi_tch_hf() );
4112 execute( TC_paging_imsi_nochan_cgi() );
4113 execute( TC_paging_imsi_nochan_lac_ci() );
4114 execute( TC_paging_imsi_nochan_ci() );
4115 execute( TC_paging_imsi_nochan_lai() );
4116 execute( TC_paging_imsi_nochan_lac() );
4117 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +01004118 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
4119 execute( TC_paging_imsi_nochan_rnc() );
4120 execute( TC_paging_imsi_nochan_lac_rnc() );
4121 execute( TC_paging_imsi_nochan_lacs() );
4122 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +01004123 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +01004124 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +01004125 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +01004126 execute( TC_paging_counter() );
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01004127 execute( TC_paging_resp_unsol() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +01004128
4129 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +01004130 execute( TC_rsl_unknown_unit_id() );
4131
4132 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +01004133
4134 execute( TC_classmark() );
4135 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +01004136 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004137 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +01004138 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +01004139 execute( TC_err_84_unknown_msg() );
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004140
Harald Welte261af4b2018-02-12 21:20:39 +01004141 execute( TC_ho_int() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004142
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004143 execute( TC_ho_out_of_this_bsc() );
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004144 execute( TC_ho_out_fail_no_msc_response() );
4145 execute( TC_ho_out_fail_rr_ho_failure() );
4146 execute( TC_ho_out_fail_no_ho_detect() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004147
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004148 execute( TC_ho_into_this_bsc() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004149 execute( TC_ho_in_fail_msc_clears() );
4150 execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
4151 execute( TC_ho_in_fail_no_detect() );
4152 execute( TC_ho_in_fail_no_detect2() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01004153
4154 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01004155 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01004156 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +02004157
4158 execute( TC_dyn_pdch_ipa_act_deact() );
4159 execute( TC_dyn_pdch_ipa_act_nack() );
4160 execute( TC_dyn_pdch_osmo_act_deact() );
4161 execute( TC_dyn_pdch_osmo_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +02004162
Stefan Sperling0796a822018-10-05 13:01:39 +02004163 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02004164 execute( TC_chopped_ipa_payload() );
Stefan Sperling0796a822018-10-05 13:01:39 +02004165
Harald Welte99f3ca02018-06-14 13:40:29 +02004166 /* at bottom as they might crash OsmoBSC before OS#3182 is fixed */
4167 execute( TC_early_conn_fail() );
4168 execute( TC_late_conn_fail() );
4169
Harald Welte28d943e2017-11-25 15:00:50 +01004170}
4171
4172}