blob: 518f9e1f000d1dd5e3214449ffce24e6094e4113 [file] [log] [blame]
Harald Welte28d943e2017-11-25 15:00:50 +01001module BSC_Tests {
2
Harald Welte21b46bd2017-12-17 19:46:32 +01003/* Integration Tests for OsmoBSC
Harald Weltea0630032018-03-20 21:09:55 +01004 * (C) 2017-2018 by Harald Welte <laforge@gnumonks.org>
Harald Welte21b46bd2017-12-17 19:46:32 +01005 * All rights reserved.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
Harald Welte34b5a952019-05-27 11:54:11 +020010 * SPDX-License-Identifier: GPL-2.0-or-later
11 *
Harald Welte21b46bd2017-12-17 19:46:32 +010012 * This test suite tests OsmoBSC while emulating both multiple BTS + MS as
13 * well as the MSC. See README for more details.
14 *
15 * There are test cases that run in so-called 'handler mode' and test cases
16 * that run directly on top of the BSSAP and RSL CodecPorts. The "handler mode"
17 * tests abstract the multiplexing/demultiplexing of multiple SCCP connections
18 * and/or RSL channels and are hence suitable for higher-level test cases, while
19 * the "raw" tests directly on top of the CodecPorts are more suitable for lower-
20 * level testing.
21 */
22
Harald Welte4003d112017-12-09 22:35:39 +010023import from General_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010024import from Osmocom_Types all;
Harald Welteae026692017-12-09 01:03:01 +010025import from GSM_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010026import from IPL4asp_Types all;
27
Harald Welte6f521d82017-12-11 19:52:02 +010028import from BSSAP_Types all;
Harald Welte6811d102019-04-14 22:23:14 +020029import from RAN_Adapter all;
Harald Welteae026692017-12-09 01:03:01 +010030import from BSSAP_CodecPort all;
31import from BSSMAP_Templates all;
Harald Welte28d943e2017-11-25 15:00:50 +010032import from IPA_Emulation all;
Stefan Sperling830dc9d2018-02-12 21:08:28 +010033import from IPA_CodecPort all;
Harald Welteae026692017-12-09 01:03:01 +010034import from IPA_Types all;
Stefan Sperling0796a822018-10-05 13:01:39 +020035import from IPA_Testing all;
Harald Welteae026692017-12-09 01:03:01 +010036import from RSL_Types all;
Harald Welte624f9632017-12-16 19:26:04 +010037import from RSL_Emulation all;
Daniel Willmann191e0d92018-01-17 12:44:35 +010038import from MGCP_Emulation all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010039import from MGCP_Templates all;
40import from MGCP_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010041
Harald Welte96c94412017-12-09 03:12:45 +010042import from Osmocom_CTRL_Functions all;
Harald Weltea5d2ab22017-12-09 14:21:42 +010043import from Osmocom_CTRL_Types all;
Harald Welteffe55fc2018-01-17 22:39:54 +010044import from Osmocom_CTRL_Adapter all;
Harald Welte96c94412017-12-09 03:12:45 +010045
Harald Weltebc03c762018-02-12 18:09:38 +010046import from Osmocom_VTY_Functions all;
47import from TELNETasp_PortType all;
48
Harald Welte6f521d82017-12-11 19:52:02 +010049import from MobileL3_CommonIE_Types all;
Harald Weltee3bd6582018-01-31 22:51:25 +010050import from MobileL3_Types all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010051import from MobileL3_RRM_Types all;
Harald Welte6f521d82017-12-11 19:52:02 +010052import from L3_Templates all;
53import from GSM_RR_Types all;
54
Stefan Sperlingc307e682018-06-14 15:15:46 +020055import from SCCP_Templates all;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010056import from BSSMAP_Templates all;
57
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010058import from SCCPasp_Types all;
59
Harald Welte5d1a2202017-12-13 19:51:29 +010060const integer NUM_BTS := 3;
Harald Welteae026692017-12-09 01:03:01 +010061const float T3101_MAX := 12.0;
Harald Welte28d943e2017-11-25 15:00:50 +010062
Harald Welte799c97b2017-12-14 17:50:30 +010063/* make sure to sync this with the osmo-bts.cfg you're using */
Philipp Maiercb6cc482018-03-26 13:08:00 +020064const integer NUM_TCHH_PER_BTS := 2;
65const integer NUM_TCHF_PER_BTS := 4;
Harald Weltedd8cbf32018-01-28 12:07:52 +010066const integer NUM_SDCCH_PER_BTS := 4;
Harald Welte799c97b2017-12-14 17:50:30 +010067
Harald Welte4003d112017-12-09 22:35:39 +010068
Harald Welte21b46bd2017-12-17 19:46:32 +010069/* per-BTS state which we keep */
Harald Welte96c94412017-12-09 03:12:45 +010070type record BTS_State {
Harald Welte21b46bd2017-12-17 19:46:32 +010071 /* component reference to the IPA_Client component used for RSL */
Harald Weltea5d2ab22017-12-09 14:21:42 +010072 IPA_Client rsl
Harald Welte96c94412017-12-09 03:12:45 +010073}
74
Harald Weltea4ca4462018-02-09 00:17:14 +010075type component test_CT extends CTRL_Adapter_CT {
Harald Welte21b46bd2017-12-17 19:46:32 +010076 /* Array of per-BTS state */
Harald Welte96c94412017-12-09 03:12:45 +010077 var BTS_State bts[NUM_BTS];
Harald Welte89ab1912018-02-23 18:56:29 +010078 /* RSL common Channel Port (for RSL_Emulation) */
79 port RSL_CCHAN_PT RSL_CCHAN[NUM_BTS];
Harald Welte21b46bd2017-12-17 19:46:32 +010080 /* array of per-BTS RSL test ports */
Harald Welteae026692017-12-09 01:03:01 +010081 port IPA_RSL_PT IPA_RSL[NUM_BTS];
Stefan Sperling830dc9d2018-02-12 21:08:28 +010082 port IPA_CODEC_PT IPA; /* Required for compilation of TC_rsl_unknown_unit_id() */
Harald Weltea5d2ab22017-12-09 14:21:42 +010083
Daniel Willmann191e0d92018-01-17 12:44:35 +010084 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +010085 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +010086
Harald Welte6811d102019-04-14 22:23:14 +020087 var RAN_Adapter g_bssap;
Harald Weltea4ca4462018-02-09 00:17:14 +010088 /* for old legacy-tests only */
89 port BSSAP_CODEC_PT BSSAP;
90
Harald Welte21b46bd2017-12-17 19:46:32 +010091 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +010092 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +010093
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +020094 /* Osmux is enabled through VTY */
95 var boolean g_osmux_enabled := false;
96
Harald Welte21b46bd2017-12-17 19:46:32 +010097 /* global test case guard timer */
Harald Welteae026692017-12-09 01:03:01 +010098 timer T_guard := 30.0;
99
Harald Welte28d943e2017-11-25 15:00:50 +0100100}
101
102modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +0100103 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +0100104 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100105 /* port number to which to establish the IPA OML connections */
106 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +0100107 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +0100108 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +0100109 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +0100110 integer mp_bsc_ctrl_port := 4249;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100111 /* IP address at which the test binds */
112 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100113
Harald Welte6811d102019-04-14 22:23:14 +0200114 RAN_Configuration mp_bssap_cfg := {
Harald Welte7ef51aa2018-04-16 19:16:01 +0200115 transport := BSSAP_TRANSPORT_AoIP,
Harald Weltea4ca4462018-02-09 00:17:14 +0100116 sccp_service_type := "mtp3_itu",
117 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
118 own_pc := 185,
119 own_ssn := 254,
120 peer_pc := 187,
121 peer_ssn := 254,
Philipp Maier38d68942018-03-29 15:38:09 +0200122 sio := '83'O,
123 rctx := 0
Harald Weltea4ca4462018-02-09 00:17:14 +0100124 };
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +0200125
126 /* Whether to enable osmux tests. Can be dropped completely and enable
127 unconditionally once new version of osmo-bsc is released (current
128 version: 1.4.1) */
129 boolean mp_enable_osmux_test := true;
Harald Weltea4ca4462018-02-09 00:17:14 +0100130}
131
Philipp Maier48604732018-10-09 15:00:37 +0200132private function f_gen_test_hdlr_pars() return TestHdlrParams {
133
134 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
135 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
136 pars.aoip := true;
137 } else {
138 pars.aoip := false;
139 }
140
141 return pars;
142}
143
Philipp Maier282ca4b2018-02-27 17:17:00 +0100144private function f_shutdown_helper() runs on test_CT {
Daniel Willmann637ef6c2018-07-25 10:49:09 +0200145 all component.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100146 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200147 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100148}
149
Harald Weltea4ca4462018-02-09 00:17:14 +0100150private function f_legacy_bssap_reset() runs on test_CT {
151 var BSSAP_N_UNITDATA_ind ud_ind;
152 timer T := 5.0;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200153 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, ts_BSSMAP_Reset(0, g_osmux_enabled)));
Harald Weltea4ca4462018-02-09 00:17:14 +0100154 T.start;
155 alt {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200156 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap.sccp_addr_own, g_bssap.sccp_addr_peer, tr_BSSMAP_ResetAck(g_osmux_enabled))) {
Harald Weltea4ca4462018-02-09 00:17:14 +0100157 log("Received RESET-ACK in response to RESET, we're ready to go!");
158 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200159 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Weltea4ca4462018-02-09 00:17:14 +0100160 log("Respoding to inbound RESET with RESET-ACK");
161 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200162 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Weltea4ca4462018-02-09 00:17:14 +0100163 repeat;
164 }
165 [] BSSAP.receive { repeat; }
166 [] T.timeout { setverdict(fail, "Waiting for RESET-ACK after sending RESET"); }
167 }
Harald Welte28d943e2017-11-25 15:00:50 +0100168}
169
Harald Welteae026692017-12-09 01:03:01 +0100170type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100171 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100172 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100173 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100174 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100175 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100176 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100177 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100178 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100179}
180
Harald Welte21b46bd2017-12-17 19:46:32 +0100181/*! Start the IPA/RSL related bits for one IPA_Client.
182 * \param clnt IPA_Client for which to establish
183 * \param bsc_host IP address / hostname of the BSC
184 * \param bsc_port TCP port number of the BSC
185 * \param i number identifying this BTS
186 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100187function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
188 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100189runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100190 timer T := 10.0;
191
Harald Welte96c94412017-12-09 03:12:45 +0100192 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welteae026692017-12-09 01:03:01 +0100193 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA");
194 clnt.ccm_pars := c_IPA_default_ccm_pars;
195 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
196 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100197 if (handler_mode) {
198 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL");
Harald Welte89ab1912018-02-23 18:56:29 +0100199 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100200 }
Harald Welteae026692017-12-09 01:03:01 +0100201
202 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Harald Welte624f9632017-12-16 19:26:04 +0100203 if (handler_mode) {
204 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
205 } else {
206 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
207 }
Harald Welteae026692017-12-09 01:03:01 +0100208
Harald Welte5d1a2202017-12-13 19:51:29 +0100209 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100210 if (handler_mode) {
211 clnt.vc_RSL.start(RSL_Emulation.main());
212 return;
213 }
Harald Welteae026692017-12-09 01:03:01 +0100214
215 /* wait for IPA RSL link to connect and send ID ACK */
216 T.start;
217 alt {
218 [] IPA_RSL[i].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_ID_ACK}) {
219 T.stop;
220 IPA_RSL[i].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_PAGING_LOAD_IND(23)));
221 }
Harald Welte60e823a2017-12-10 14:10:59 +0100222 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100223 [] IPA_RSL[i].receive { repeat }
224 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100225 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200226 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100227 }
228 }
229}
230
Harald Welte12055472018-03-17 20:10:08 +0100231function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
232 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
233 return;
234 }
235 clnt.vc_IPA.stop;
236 if (isbound(clnt.vc_RSL)) {
237 clnt.vc_RSL.stop;
238 }
239}
240
Harald Welte21b46bd2017-12-17 19:46:32 +0100241/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100242function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
243 timer T := secs_max;
244 T.start;
245 while (true) {
246 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
247 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100248 /* the 'degraded' state exists from OML connection time, and we have to wait
249 * until all MO's are initialized */
250 T.start(1.0);
251 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100252 return;
253 }
Harald Weltef0d6ac62017-12-17 17:02:21 +0100254 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100255 if (not T.running) {
Max99253902018-11-16 17:57:39 +0100256 setverdict(fail, "Timeout waiting for BTS" & int2str(bts_nr) & " oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +0200257 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100258 }
259 }
260}
261
Harald Welte21b46bd2017-12-17 19:46:32 +0100262/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +0100263altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +0100264 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100265 [] T_guard.timeout {
266 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +0200267 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100268 }
Harald Welte60e823a2017-12-10 14:10:59 +0100269 /* always respond with RESET ACK to RESET */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200270 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Welte60e823a2017-12-10 14:10:59 +0100271 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200272 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Welte69c1c262017-12-13 21:02:08 +0100273 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +0100274 }
Harald Welte28d943e2017-11-25 15:00:50 +0100275}
276
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100277altstep no_bssmap_reset() runs on test_CT {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200278 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100279 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +0200280 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100281 }
282}
283
Daniel Willmann191e0d92018-01-17 12:44:35 +0100284function f_init_mgcp(charstring id) runs on test_CT {
285 id := id & "-MGCP";
286
287 var MGCPOps ops := {
288 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
289 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
290 };
291 var MGCP_conn_parameters mgcp_pars := {
292 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +0100293 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +0100294 mgw_ip := mp_test_ip,
295 mgw_udp_port := 2427
296 };
297
298 vc_MGCP := MGCP_Emulation_CT.create(id);
299 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
300}
301
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200302/* Enable or disable (current default) Osmux. When enabling, BSSMAP Reset
303 * contains extra IE (OsmuxSupport) and osmo-bsc will handle AssignReq with
304 * OsmuxCID IE.
305 */
306private function f_vty_allow_osmux(boolean allow) runs on test_CT {
307 f_vty_enter_cfg_msc(BSCVTY, 0);
308 if (allow) {
309 f_vty_transceive(BSCVTY, "osmux on");
310 } else {
311 f_vty_transceive(BSCVTY, "osmux off");
312 }
313 f_vty_transceive(BSCVTY, "exit");
314 f_vty_transceive(BSCVTY, "exit");
315 g_osmux_enabled := allow;
316}
317
Max2253c0b2018-11-06 19:28:05 +0100318function f_init_vty(charstring id := "foo") runs on test_CT {
Harald Welte94e0c342018-04-07 11:33:23 +0200319 if (BSCVTY.checkstate("Mapped")) {
320 /* skip initialization if already executed once */
321 return;
322 }
Harald Weltebc03c762018-02-12 18:09:38 +0100323 map(self:BSCVTY, system:BSCVTY);
324 f_vty_set_prompts(BSCVTY);
325 f_vty_transceive(BSCVTY, "enable");
326}
327
Harald Welte21b46bd2017-12-17 19:46:32 +0100328/* global initialization function
329 * \param nr_bts Number of BTSs we should start/bring up
330 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200331function f_init(integer nr_bts := NUM_BTS, boolean handler_mode := false, boolean allow_osmux := false) runs on test_CT {
Harald Welte28d943e2017-11-25 15:00:50 +0100332 var integer i;
Harald Welte28d943e2017-11-25 15:00:50 +0100333
Harald Welteae026692017-12-09 01:03:01 +0100334 if (g_initialized) {
335 return;
Harald Welte28d943e2017-11-25 15:00:50 +0100336 }
Harald Welteae026692017-12-09 01:03:01 +0100337 g_initialized := true;
338
Daniel Willmanne68f9272018-11-27 15:15:28 +0100339 T_guard.start;
340 activate(as_Tguard());
341
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200342 f_init_vty("VirtMSC");
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +0200343 if (mp_enable_osmux_test) {
344 f_vty_allow_osmux(allow_osmux);
345 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200346
Harald Welte6811d102019-04-14 22:23:14 +0200347 /* Call a function of our 'parent component' RAN_Adapter_CT to start the
Harald Welteae026692017-12-09 01:03:01 +0100348 * MSC-side BSSAP emulation */
Harald Welte67089ee2018-01-17 22:19:03 +0100349 if (handler_mode) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200350 var RanOps ranops := MSC_RanOps;
351 ranops.use_osmux := g_osmux_enabled;
352 f_ran_adapter_init(g_bssap, mp_bssap_cfg, "VirtMSC", ranops);
Harald Welte3ca0ce12019-04-23 17:18:48 +0200353 f_ran_adapter_start(g_bssap);
Harald Welte67089ee2018-01-17 22:19:03 +0100354 } else {
Harald Welte3ca0ce12019-04-23 17:18:48 +0200355 f_ran_adapter_init(g_bssap, mp_bssap_cfg, "VirtMSC", omit);
Harald Weltea4ca4462018-02-09 00:17:14 +0100356 connect(self:BSSAP, g_bssap.vc_SCCP:SCCP_SP_PORT);
Harald Welte3ca0ce12019-04-23 17:18:48 +0200357 f_ran_adapter_start(g_bssap);
Harald Weltea4ca4462018-02-09 00:17:14 +0100358 f_legacy_bssap_reset();
Harald Welte67089ee2018-01-17 22:19:03 +0100359 }
Harald Welted5833a82018-05-27 16:52:56 +0200360
Harald Welteffe55fc2018-01-17 22:39:54 +0100361 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +0100362
Daniel Willmann191e0d92018-01-17 12:44:35 +0100363 f_init_mgcp("VirtMSC");
364
Harald Welte89d42e82017-12-17 16:42:41 +0100365 for (i := 0; i < nr_bts; i := i+1) {
Harald Weltea5d2ab22017-12-09 14:21:42 +0100366 /* wait until osmo-bts-omldummy has respawned */
367 f_wait_oml(i, "degraded", 5.0);
368 /* start RSL connection */
Harald Welte624f9632017-12-16 19:26:04 +0100369 f_ipa_rsl_start(bts[i].rsl, mp_bsc_ip, mp_bsc_rsl_port, i, handler_mode);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100370 /* wait until BSC tells us "connected" */
371 f_wait_oml(i, "connected", 5.0);
Harald Welte696ddb62017-12-08 14:01:43 +0100372 }
373
Harald Welte28d943e2017-11-25 15:00:50 +0100374}
375
Maxd4e56962018-10-31 19:08:25 +0100376/* expect to receive a RSL message matching a specified template on a given BTS / stream */
Harald Welteae026692017-12-09 01:03:01 +0100377function f_exp_ipa_rx(integer bts_nr, template RSL_Message t_rx, float t_secs := 2.0, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
378runs on test_CT return RSL_Message {
379 var ASP_RSL_Unitdata rx_rsl_ud;
380 timer T := t_secs;
381
382 T.start;
383 alt {
384 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(sid, t_rx)) -> value rx_rsl_ud {
385 T.stop;
386 }
387 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +0100388 [] T.timeout {
389 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +0200390 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +0100391 }
Harald Welteae026692017-12-09 01:03:01 +0100392 }
393 return rx_rsl_ud.rsl;
394}
395
Harald Welte21b46bd2017-12-17 19:46:32 +0100396/* helper function to transmit RSL on a given BTS/stream */
Harald Welteae026692017-12-09 01:03:01 +0100397function f_ipa_tx(integer bts_nr, template RSL_Message t_tx, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
398runs on test_CT {
399 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(sid, t_tx));
400}
401
402
Harald Welte4003d112017-12-09 22:35:39 +0100403/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +0100404testcase TC_chan_act_noreply() runs on test_CT {
405 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +0100406 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +0100407
Harald Welte89d42e82017-12-17 16:42:41 +0100408 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +0100409
Harald Welteae026692017-12-09 01:03:01 +0100410 IPA_RSL[0].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +0100411 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welteae026692017-12-09 01:03:01 +0100412 setverdict(pass);
Harald Welte28d943e2017-11-25 15:00:50 +0100413}
414
Harald Welte4003d112017-12-09 22:35:39 +0100415/* verify if the "chreq:total" counter increments as expected */
416testcase TC_chan_act_counter() runs on test_CT {
417 var BSSAP_N_UNITDATA_ind ud_ind;
418 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +0100419 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +0100420
Harald Welte89d42e82017-12-17 16:42:41 +0100421 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100422
423 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
424 IPA_RSL[0].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +0100425 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welte4003d112017-12-09 22:35:39 +0100426 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total", chreq_total+1);
427
428 setverdict(pass);
429}
430
Harald Welteae026692017-12-09 01:03:01 +0100431/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
432testcase TC_chan_act_ack_noest() runs on test_CT {
433 var RSL_Message rx_rsl;
434
Harald Welte89d42e82017-12-17 16:42:41 +0100435 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100436
437 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100438 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100439
440 /* expect BSC to disable the channel again if there's no RLL EST IND */
441 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
442
443 setverdict(pass);
444}
445
446/* Test behavior if MSC never answers to CR */
447testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +0100448 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
449 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +0100450 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +0100451 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +0100452
Harald Welte89d42e82017-12-17 16:42:41 +0100453 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100454
455 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100456 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100457
458 var octetstring l3 := '00010203040506'O
459 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
460
461 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
462
463 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +0100464 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100465 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Harald Welteae026692017-12-09 01:03:01 +0100466 setverdict(pass);
467}
468
469/* Test behavior if MSC answers with CREF to CR */
470testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
471 var BSSAP_N_CONNECT_ind rx_c_ind;
472 var RSL_Message rx_rsl;
473
Harald Welte89d42e82017-12-17 16:42:41 +0100474 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100475
476 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100477 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100478
479 var octetstring l3 := '00010203040506'O
480 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
481
482 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
483 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
484
485 /* expect BSC to disable the channel */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100486 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Harald Welteae026692017-12-09 01:03:01 +0100487 setverdict(pass);
488}
489
Harald Welte618ef642017-12-14 14:58:20 +0100490/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
491testcase TC_chan_act_nack() runs on test_CT {
492 var RSL_Message rx_rsl;
493 var integer chact_nack;
494
Harald Welte89d42e82017-12-17 16:42:41 +0100495 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +0100496
497 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
498
499 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
500 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
501 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
502
503 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
504
505 /* wait for some time to hope the NACK arrives before the CTRL GET below */
506 f_sleep(0.5);
507
508 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
509
510 setverdict(pass);
511}
512
Harald Welte799c97b2017-12-14 17:50:30 +0100513/* Test for channel exhaustion due to RACH overload */
514testcase TC_chan_exhaustion() runs on test_CT {
515 var ASP_RSL_Unitdata rsl_ud;
516 var integer i;
517 var integer chreq_total, chreq_nochan;
518
Harald Welte89d42e82017-12-17 16:42:41 +0100519 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +0100520
521 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
522 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
523
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +0100524 /* GSM 04.08 Table 9.9a:
525 * RA = '33'O -> Establishment cause = 0011xxxx (MS dual rate capable and asks for "TCH/H or TCH/F").
526 * With current setup, expect 4xSDCCH + 4xTCH/F + 1xTCH/H to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +0200527 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS; i := i+1) {
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +0100528 var RslChannelNr chan_nr := f_chreq_act_ack('33'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +0100529 }
530
531 IPA_RSL[0].clear;
532
Harald Weltedd8cbf32018-01-28 12:07:52 +0100533 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200534 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +0100535
536 /* now expect additional channel activations to fail */
537 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
538
539 alt {
540 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
541 tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
542 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
543 }
544 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
545 var GsmRrMessage rr;
546 /* match on IMM ASS REJ */
547 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
548 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
549 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200550 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +0100551 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
552 chreq_nochan+1);
553 setverdict(pass);
554 } else {
555 repeat;
556 }
557 }
558 [] IPA_RSL[0].receive { repeat; }
559 }
560}
561
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +0700562/* Test channel deactivation due to silence from MS */
563testcase TC_chan_deact_silence() runs on test_CT {
564 var RslChannelNr chan_nr;
565
566 f_init(1);
567
568 /* Request for a dedicated channel */
569 chan_nr := f_chreq_act_ack('23'O);
570
571 /* Wait some time until the channel is released */
572 f_sleep(2.0);
573
574 /* Expect CHANnel RELease */
575 alt {
576 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
577 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
578 log("Received CHANnel RELease");
579 setverdict(pass);
580 }
581 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
582 tr_RSL_IMM_ASSIGN(?))) {
583 /* See OS#3709, OsmoBSC should not send Immediate
584 * Assignment Reject since a dedicated channel was
585 * already allocated, and Immediate Assignment was
586 * already sent. */
587 setverdict(fail, "Unexpected Immediate Assignment!");
588 }
589 [] IPA_RSL[0].receive {
590 setverdict(fail, "Unexpected RSL message!");
591 }
592 }
593}
594
Harald Weltecfe2c962017-12-15 12:09:32 +0100595/***********************************************************************
596 * Assignment Testing
597 ***********************************************************************/
598
Neels Hofmeyrda4a6952018-06-14 04:02:49 +0200599/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction,
600 * except for the inter-BSC handover, MT side) */
Harald Weltecfe2c962017-12-15 12:09:32 +0100601testcase TC_outbound_connect() runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +0100602 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +0100603
Harald Weltea4ca4462018-02-09 00:17:14 +0100604 BSSAP.send(ts_BSSAP_CONNECT_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, 2342, ts_BSSMAP_AssignmentReq));
Harald Weltecfe2c962017-12-15 12:09:32 +0100605 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
606 setverdict(pass);
607}
608
Harald Welte16a4adf2017-12-14 18:54:01 +0100609/* Test behavior if MSC answers with CREF to CR */
610testcase TC_assignment_cic_only() runs on test_CT {
611 var BSSAP_N_CONNECT_ind rx_c_ind;
612 var RSL_Message rx_rsl;
613 var DchanTuple dt;
614
Harald Welte89d42e82017-12-17 16:42:41 +0100615 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +0100616
617 dt := f_est_dchan('23'O, 23, '00000000'O);
Harald Welte17b27da2018-05-25 20:33:53 +0200618 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
619 /* send assignment without AoIP IEs */
620 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
621 } else {
622 /* Send assignmetn without CIC in IPA case */
623 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
624 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
625 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
626 }
Harald Welte16a4adf2017-12-14 18:54:01 +0100627 alt {
628 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
629 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
630 }
Harald Welte235ebf12017-12-15 14:18:16 +0100631 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +0100632 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
633 setverdict(pass);
634 }
635 [] BSSAP.receive { repeat; }
636 }
637}
638
Harald Welteed848512018-05-24 22:27:58 +0200639/* generate an assignment request for either AoIP or SCCPlite */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200640function f_gen_ass_req(boolean osmux_enabled := false) return PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200641 var PDU_BSSAP ass_cmd;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200642 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Harald Welteed848512018-05-24 22:27:58 +0200643 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
644 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
645 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200646 if (osmux_enabled) {
647 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla, osmux_cid));
648 } else {
649 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
650 }
Harald Welteed848512018-05-24 22:27:58 +0200651 } else {
652 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +0200653 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
Harald Welteed848512018-05-24 22:27:58 +0200654 }
655 return ass_cmd;
656}
657
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +0100658function f_gen_handover_req() return PDU_BSSAP {
659 var PDU_BSSAP ho_req;
660 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
661 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
662 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
663 ho_req := valueof(ts_BSSMAP_HandoverRequest(omit, tla));
664 } else {
665 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
666 ho_req := valueof(ts_BSSMAP_HandoverRequest(cic, omit));
667 }
668 return ho_req;
669}
670
Harald Welteed848512018-05-24 22:27:58 +0200671/* generate an assignment complete template for either AoIP or SCCPlite */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200672function f_gen_exp_compl(boolean expect_osmux := false) return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200673 var template PDU_BSSAP exp_compl;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200674 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Harald Welteed848512018-05-24 22:27:58 +0200675 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200676 if (expect_osmux) {
677 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, osmux_cid);
678 } else {
679 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, omit);
680 }
Harald Welteed848512018-05-24 22:27:58 +0200681 } else {
682 /* CIC is optional "*" as the MSC allocated it */
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +0200683 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
Harald Welteed848512018-05-24 22:27:58 +0200684 }
685 return exp_compl;
686}
687
Harald Welte235ebf12017-12-15 14:18:16 +0100688/* Run everything required up to sending a caller-specified assignment command and expect response */
689function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
690runs on test_CT {
691 var BSSAP_N_CONNECT_ind rx_c_ind;
692 var RSL_Message rx_rsl;
693 var DchanTuple dt;
694
Harald Welte89d42e82017-12-17 16:42:41 +0100695 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +0100696
697 dt := f_est_dchan('23'O, 23, '00000000'O);
698 /* send assignment without AoIP IEs */
699 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
700 alt {
701 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
702 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
703 setverdict(pass);
704 } else {
705 setverdict(fail, fail_text);
706 }
707 }
708 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
709 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
710 setverdict(pass);
711 } else {
712 setverdict(fail, fail_text);
713 }
714 }
715 [] BSSAP.receive { repeat; }
716 }
717}
718testcase TC_assignment_csd() runs on test_CT {
719 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200720 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100721 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
722 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
723 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
724}
725
726testcase TC_assignment_ctm() runs on test_CT {
727 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200728 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100729 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
730 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
731 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
732}
733
Harald Welte4003d112017-12-09 22:35:39 +0100734type record DchanTuple {
735 integer sccp_conn_id,
736 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +0100737}
738
Harald Welted6939652017-12-13 21:02:46 +0100739/* Send CHAN RQD and wait for allocation; acknowledge it */
740private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
741runs on test_CT return RslChannelNr {
742 var RSL_Message rx_rsl;
743 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
744 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
745 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
746 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
Daniel Willmannf4ac4ce2018-08-02 14:06:30 +0200747 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Harald Welted6939652017-12-13 21:02:46 +0100748 return chan_nr;
749}
750
Harald Welte4003d112017-12-09 22:35:39 +0100751/* helper function to establish a dedicated channel via BTS and MSC */
752function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
753runs on test_CT return DchanTuple {
754 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +0100755 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100756
Harald Welte4003d112017-12-09 22:35:39 +0100757 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100758 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +0100759
760 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
761
762 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
763 dt.sccp_conn_id := rx_c_ind.connectionId;
764 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
765
766 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100767}
768
Harald Welte641fcbe2018-06-14 10:58:35 +0200769/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
770private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
771 var RSL_Message rx_rsl;
772 /* expect BSC to disable the channel */
773 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
774 /* respond with CHAN REL ACK */
775 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
776
777 /* expect Clear Complete from BSC */
778 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
779
780 /* MSC disconnects as instructed. */
781 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
782}
783
Harald Welte4003d112017-12-09 22:35:39 +0100784/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
785testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100786 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100787 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +0100788
Harald Welte89d42e82017-12-17 16:42:41 +0100789 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +0100790
Harald Welte4003d112017-12-09 22:35:39 +0100791 dt := f_est_dchan('23'O, 23, '00010203040506'O);
792
793 /* simulate RLL REL IND */
794 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
795
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100796 /* expect Clear Request on MSC side */
797 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
798
799 /* Instruct BSC to clear channel */
800 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
801 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
802
Harald Welte4003d112017-12-09 22:35:39 +0100803 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200804 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100805
806 /* wait for SCCP emulation to do its job */
807 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +0100808
809 setverdict(pass);
810}
811
812/* Test behavior of channel release after CONN FAIL IND from BTS */
813testcase TC_chan_rel_conn_fail() runs on test_CT {
814 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100815 var DchanTuple dt;
816
Harald Welte89d42e82017-12-17 16:42:41 +0100817 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100818
819 dt := f_est_dchan('23'O, 23, '00010203040506'O);
820
821 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +0100822 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 +0100823 /* TODO: different cause values? */
824
Harald Welte4003d112017-12-09 22:35:39 +0100825 /* expect Clear Request from BSC */
826 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
827
828 /* Instruct BSC to clear channel */
829 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
830 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
831
Harald Welte6ff76ea2018-01-28 13:08:01 +0100832 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200833 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +0100834
835 /* wait for SCCP emulation to do its job */
836 f_sleep(1.0);
837
838 setverdict(pass);
839}
840
Harald Welte99f3ca02018-06-14 13:40:29 +0200841/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
842/* See also https://www.osmocom.org/issues/3182 */
843testcase TC_early_conn_fail() runs on test_CT {
844 var RSL_Message rx_rsl;
845 var DchanTuple dt;
846
847 f_init(1);
848
849 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
850 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_octstring(1), 23);
851
852 /* BTS->BSC: simulate CONN FAIL IND */
853 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
854
855 /* BTS->BSC: Expect RF channel release from BSC on Abis */
856 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
857
858 /* BTS<-BSC: respond with CHAN REL ACK */
859 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
860
861 setverdict(pass);
862}
863
864/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
865/* See also https://www.osmocom.org/issues/3182 */
866testcase TC_late_conn_fail() runs on test_CT {
867 var RSL_Message rx_rsl;
868 var DchanTuple dt;
869
870 f_init(1);
871
872 dt := f_est_dchan('23'O, 23, '00010203040506'O);
873
874 /* BSC<-MSC: Instruct BSC to clear connection */
875 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
876
877 /* BTS->BSC: expect BSC to deactivate SACCH */
878 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
879
880 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
881 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
882
883 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
884 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
885 /* BTS->BSC: respond with CHAN REL ACK */
886 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
887
888 /* BSC->MSC: expect Clear Complete from BSC */
889 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
890
891 /* BSC<-MSC: MSC disconnects as requested. */
892 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
893
894 setverdict(pass);
895}
896
Neels Hofmeyrf44ccd12018-11-05 19:15:23 +0100897function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr,
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100898 boolean expect_deact_sacch := true,
899 boolean expect_rr_chan_rel := true,
900 boolean expect_rll_rel_req := true,
Harald Welte99787102019-02-04 10:41:36 +0100901 boolean handle_rll_rel := true,
902 boolean is_csfb := false
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100903 ) runs on test_CT {
Harald Welte91d54a52018-01-28 15:35:07 +0100904
905 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100906 var boolean got_deact_sacch := false;
907 var boolean got_rr_chan_rel := false;
908 var boolean got_rll_rel_req := false;
909 log("f_expect_chan_rel() expecting: expect_deact_sacch=", expect_deact_sacch, " expect_rr_chan_rel=", expect_rr_chan_rel,
910 " expect_rll_rel_req=", expect_rll_rel_req);
Harald Welte91d54a52018-01-28 15:35:07 +0100911 alt {
Harald Welte91d54a52018-01-28 15:35:07 +0100912 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
913 tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100914 got_deact_sacch := true;
Harald Welte91d54a52018-01-28 15:35:07 +0100915 repeat;
916 }
Harald Welte99787102019-02-04 10:41:36 +0100917 [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))) {
918 got_rr_chan_rel := true;
919 repeat;
920 }
921 [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 +0100922 got_rr_chan_rel := true;
Neels Hofmeyr211169d2018-11-07 00:37:29 +0100923 repeat;
924 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100925 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
Harald Welte91d54a52018-01-28 15:35:07 +0100926 tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100927 got_rll_rel_req := true;
Harald Welte91d54a52018-01-28 15:35:07 +0100928 /* FIXME: Why are we getting this for LinkID SACCH? */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100929 if (handle_rll_rel) {
930 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
931 }
Harald Welte91d54a52018-01-28 15:35:07 +0100932 repeat;
933 }
Harald Welte91d54a52018-01-28 15:35:07 +0100934 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
935 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
936 /* respond with CHAN REL ACK */
937 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
938 }
939 /* ignore any user data */
940 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_MsgTypeR(?))) {
941 repeat;
942 }
943 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100944
945 log("f_expect_chan_rel() summary: got_deact_sacch=", got_deact_sacch, " got_rr_chan_rel=", got_rr_chan_rel,
946 " got_rll_rel_req=", got_rll_rel_req);
947
948 if (expect_deact_sacch != got_deact_sacch) {
949 setverdict(fail, "f_expect_chan_rel(): expect_deact_sacch=", expect_deact_sacch, " got_deact_sacch=", got_deact_sacch);
950 }
951 if (expect_rr_chan_rel != got_rr_chan_rel) {
952 setverdict(fail, "f_expect_chan_rel(): expect_rr_chan_rel=", expect_rr_chan_rel, " got_rr_chan_rel=", got_rr_chan_rel);
953 }
954 if (expect_rll_rel_req != got_rll_rel_req) {
955 setverdict(fail, "f_expect_chan_rel(): expect_rll_rel_req=", expect_rll_rel_req, " got_rll_rel_req=", got_rll_rel_req);
956 }
Harald Welte91d54a52018-01-28 15:35:07 +0100957}
958
Harald Welte4003d112017-12-09 22:35:39 +0100959/* Test behavior of channel release after hard Clear Command from MSC */
960testcase TC_chan_rel_hard_clear() runs on test_CT {
961 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100962 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +0100963
Harald Welte89d42e82017-12-17 16:42:41 +0100964 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100965
966 dt := f_est_dchan('23'O, 23, '00010203040506'O);
967
968 /* Instruct BSC to clear channel */
969 var BssmapCause cause := 0;
970 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
971
972 /* expect Clear Complete from BSC on A */
973 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
974 /* release the SCCP connection */
975 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
976 }
977
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100978 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte4003d112017-12-09 22:35:39 +0100979 setverdict(pass);
980}
981
Harald Welte99787102019-02-04 10:41:36 +0100982/* Test behavior of channel release after Clear Command with CSFB indicator from MSC */
983testcase TC_chan_rel_hard_clear_csfb() runs on test_CT {
984 var BSSAP_N_DATA_ind rx_di;
985 var DchanTuple dt;
986
987 f_init(1);
988
989 dt := f_est_dchan('23'O, 23, '00010203040506'O);
990
991 /* Instruct BSC to clear channel */
992 var BssmapCause cause := 0;
993 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
994
995 /* expect Clear Complete from BSC on A */
996 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
997 /* release the SCCP connection */
998 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
999 }
1000
1001 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, is_csfb := true);
1002 setverdict(pass);
1003}
1004
Harald Welted8c36cd2017-12-09 23:05:31 +01001005/* Test behavior of channel release after hard RLSD from MSC */
1006testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +01001007 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +01001008
Harald Welte89d42e82017-12-17 16:42:41 +01001009 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +01001010
1011 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1012
1013 /* release the SCCP connection */
1014 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1015
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001016 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welted8c36cd2017-12-09 23:05:31 +01001017 setverdict(pass);
1018}
1019
Harald Welte550daf92018-06-11 19:22:13 +02001020/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
1021testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
1022 var DchanTuple dt;
1023
1024 f_init(1);
1025
1026 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1027
1028 /* release the SCCP connection */
1029 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1030
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001031 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte550daf92018-06-11 19:22:13 +02001032 setverdict(pass);
1033}
1034
Harald Welte85804d42017-12-10 14:11:58 +01001035/* Test behavior of channel release after BSSMAP RESET from MSC */
1036testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +01001037 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +01001038
Harald Welte89d42e82017-12-17 16:42:41 +01001039 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +01001040
1041 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1042
1043 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
1044 IPA_RSL[0].clear;
1045
1046 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001047 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 +01001048 interleave {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001049 [] 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 +01001050 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
1051 }
1052
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001053 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte85804d42017-12-10 14:11:58 +01001054 setverdict(pass);
1055}
1056
Harald Welte5cd20ed2017-12-13 21:03:20 +01001057/* Test behavior if RSL EST IND for non-active channel */
1058testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
1059 timer T := 2.0;
1060
Harald Welte89d42e82017-12-17 16:42:41 +01001061 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001062
1063 var octetstring l3 := '00010203040506'O;
1064 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
1065 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1066
1067 T.start;
1068 alt {
1069 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1070 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
1071 }
1072 [] BSSAP.receive {}
1073 [] IPA_RSL[0].receive {}
1074 [] T.timeout {}
1075 }
1076
1077 setverdict(pass);
1078}
1079
1080/* Test behavior if RSL EST IND for invalid SAPI */
1081testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
1082 var RslChannelNr chan_nr;
1083
Harald Welte89d42e82017-12-17 16:42:41 +01001084 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001085
1086 chan_nr := f_chreq_act_ack()
1087
1088 var octetstring l3 := '00010203040506'O;
1089 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
1090
1091 timer T := 2.0;
1092 T.start;
1093 alt {
1094 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1095 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
1096 }
1097 [] BSSAP.receive { repeat; }
1098 [] IPA_RSL[0].receive { repeat; }
1099 [] T.timeout {}
1100 }
1101
1102 setverdict(pass);
1103}
1104
1105/* Test behavior if RSL EST IND for invalid SAPI */
1106testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
1107 timer T := 2.0;
1108
Harald Welte89d42e82017-12-17 16:42:41 +01001109 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001110
1111 var RslChannelNr chan_nr := f_chreq_act_ack();
1112
1113 var octetstring l3 := '00010203040506'O;
1114 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
1115
1116 T.start;
1117 alt {
1118 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1119 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
1120 }
1121 [] BSSAP.receive { repeat; }
1122 [] IPA_RSL[0].receive { repeat; }
1123 [] T.timeout {}
1124 }
1125
1126 setverdict(pass);
1127}
1128
1129/* Test behavior if RSL EST IND for invalid SACCH */
1130testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
1131 timer T := 2.0;
1132
Harald Welte89d42e82017-12-17 16:42:41 +01001133 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001134
1135 var RslChannelNr chan_nr := f_chreq_act_ack();
1136
1137 var octetstring l3 := '00010203040506'O;
1138 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
1139
1140 T.start;
1141 alt {
1142 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1143 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
1144 }
1145 [] BSSAP.receive { repeat; }
1146 [] IPA_RSL[0].receive { repeat; }
1147 [] T.timeout {}
1148 }
1149
1150 setverdict(pass);
1151}
1152
1153
1154
Harald Welte4003d112017-12-09 22:35:39 +01001155
1156testcase TC_ctrl_msc_connection_status() runs on test_CT {
1157 var charstring ctrl_resp;
1158
Harald Welte89d42e82017-12-17 16:42:41 +01001159 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001160
1161 /* See https://osmocom.org/issues/2729 */
1162 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
1163 setverdict(pass);
1164}
1165
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001166testcase TC_ctrl_msc0_connection_status() runs on test_CT {
1167 var charstring ctrl_resp;
1168
1169 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001170
1171 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
1172 setverdict(pass);
1173}
1174
Harald Welte4003d112017-12-09 22:35:39 +01001175testcase TC_ctrl() runs on test_CT {
1176 var charstring ctrl_resp;
1177
Harald Welte89d42e82017-12-17 16:42:41 +01001178 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001179
1180 /* all below values must match the osmo-bsc.cfg config file used */
1181
Harald Welte6a129692018-03-17 17:30:14 +01001182 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
1183 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Harald Welte44bdaa52017-12-17 17:01:47 +01001184 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "3");
Harald Welte4003d112017-12-09 22:35:39 +01001185
1186 var integer bts_nr := 0;
1187 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
1188 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
1189 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
1190 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
1191 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
1192 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
1193 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
1194
1195 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
1196 f_sleep(2.0);
1197 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
1198 setverdict(fail, "oml-uptime not incrementing as expected");
1199 }
1200 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
1201
1202 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
1203
1204 setverdict(pass);
Harald Welte96c94412017-12-09 03:12:45 +01001205}
1206
Harald Welte6f521d82017-12-11 19:52:02 +01001207function f_bssap_tx_ud(template PDU_BSSAP bssap) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +01001208 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, bssap));
Harald Welte6f521d82017-12-11 19:52:02 +01001209}
1210
1211
1212/***********************************************************************
1213 * Paging Testing
1214 ***********************************************************************/
1215
1216type record Cell_Identity {
1217 GsmMcc mcc,
1218 GsmMnc mnc,
1219 GsmLac lac,
1220 GsmCellId ci
1221};
Harald Welte24135bd2018-03-17 19:27:53 +01001222private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01001223private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01001224
Harald Welte5d1a2202017-12-13 19:51:29 +01001225type set of integer BtsIdList;
1226
1227private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
1228 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
1229 if (bts_id == bts_ids[j]) {
1230 return true;
1231 }
1232 }
1233 return false;
1234}
Harald Welte6f521d82017-12-11 19:52:02 +01001235
1236/* core paging test helper function; used by most paging test cases */
1237private function f_pageing_helper(hexstring imsi,
1238 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01001239 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01001240 template RSL_ChanNeeded rsl_chneed := omit,
1241 template OCT4 tmsi := omit) runs on test_CT
1242{
1243 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
1244 var MobileIdentity mi;
1245 var template octetstring id_enc; /* FIXME */
1246 var RSL_Message rx_rsl;
1247 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01001248 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01001249
1250 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01001251
1252 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01001253 for (i := 0; i < NUM_BTS; i := i + 1) {
1254 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01001255 }
Harald Welte6f521d82017-12-11 19:52:02 +01001256
1257 if (isvalue(rsl_chneed)) {
1258 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
1259 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
1260 } else {
1261 bssmap_chneed := omit;
1262 }
1263
1264 f_bssap_tx_ud(ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed));
1265
1266/* FIXME: Disabled due to bugs in both GSM_RR_Types and MobileL3_CommonIE_Types IMSI encoder
1267 if (isvalue(tmsi)) {
1268 mi := valueof(t_Osmo_MI_TMSI(oct2int(valueof(tmsi))));
1269 } else {
1270 mi := valueof(ts_Osmo_MI_IMSI(imsi));
1271 }
1272 id_enc := enc_MobileIdentity(mi);
1273*/
1274 id_enc := ?;
Harald Welte5d1a2202017-12-13 19:51:29 +01001275 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
1276 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(id_enc));
1277 /* check channel type, paging group */
1278 if (rx_rsl.ies[1].body.paging_group != paging_group) {
1279 setverdict(fail, "Paging for wrong paging group");
1280 }
1281 if (ispresent(rsl_chneed) and
1282 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
1283 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
1284 }
Harald Welte6f521d82017-12-11 19:52:02 +01001285 }
Harald Welte2fccd982018-01-31 15:48:19 +01001286 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01001287 /* do a quick check on all not-included BTSs if they received paging */
1288 for (i := 0; i < NUM_BTS; i := i + 1) {
1289 timer T := 0.1;
1290 if (f_bts_in_list(i, bts_ids)) {
1291 continue;
1292 }
1293 T.start;
1294 alt {
1295 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(id_enc))) {
1296 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
1297 }
1298 [] IPA_RSL[i].receive { repeat; }
1299 [] T.timeout { }
1300 }
Harald Welte6f521d82017-12-11 19:52:02 +01001301 }
1302
1303 setverdict(pass);
1304}
1305
Harald Welte5d1a2202017-12-13 19:51:29 +01001306const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01001307const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01001308const BtsIdList c_BtsId_LAC1 := { 0, 1 };
1309const BtsIdList c_BtsId_LAC2 := { 2 };
1310
Harald Welte6f521d82017-12-11 19:52:02 +01001311/* PAGING by IMSI + TMSI */
1312testcase TC_paging_imsi_nochan() runs on test_CT {
1313 var BSSMAP_FIELD_CellIdentificationList cid_list;
1314 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01001315 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001316 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001317}
1318
1319/* PAGING by IMSI + TMSI */
1320testcase TC_paging_tmsi_nochan() runs on test_CT {
1321 var BSSMAP_FIELD_CellIdentificationList cid_list;
1322 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001323 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001324 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001325}
1326
1327/* Paging with different "channel needed' values */
1328testcase TC_paging_tmsi_any() runs on test_CT {
1329 var BSSMAP_FIELD_CellIdentificationList cid_list;
1330 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001331 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001332 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001333}
1334testcase TC_paging_tmsi_sdcch() runs on test_CT {
1335 var BSSMAP_FIELD_CellIdentificationList cid_list;
1336 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001337 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001338 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001339}
1340testcase TC_paging_tmsi_tch_f() runs on test_CT {
1341 var BSSMAP_FIELD_CellIdentificationList cid_list;
1342 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001343 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001344 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001345}
1346testcase TC_paging_tmsi_tch_hf() runs on test_CT {
1347 var BSSMAP_FIELD_CellIdentificationList cid_list;
1348 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001349 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001350 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001351}
1352
1353/* Paging by CGI */
1354testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
1355 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1356 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001357 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001358 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001359}
1360
1361/* Paging by LAC+CI */
1362testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
1363 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1364 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001365 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001366 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001367}
1368
1369/* Paging by CI */
1370testcase TC_paging_imsi_nochan_ci() runs on test_CT {
1371 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1372 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001373 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001374 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001375}
1376
1377/* Paging by LAI */
1378testcase TC_paging_imsi_nochan_lai() runs on test_CT {
1379 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1380 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001381 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001382 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001383}
1384
1385/* Paging by LAC */
1386testcase TC_paging_imsi_nochan_lac() runs on test_CT {
1387 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1388 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001389 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001390 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001391}
1392
1393/* Paging by "all in BSS" */
1394testcase TC_paging_imsi_nochan_all() runs on test_CT {
1395 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1396 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01001397 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001398 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001399}
1400
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001401/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001402testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
1403 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1404 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 +01001405 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001406 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001407}
Harald Welte6f521d82017-12-11 19:52:02 +01001408
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001409/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001410testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
1411 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1412 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001413 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001414 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001415}
1416
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001417/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001418testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
1419 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1420 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001421 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001422 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001423}
1424
Harald Welte6f521d82017-12-11 19:52:02 +01001425/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01001426testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
1427 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1428 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
1429 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001430 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001431}
1432
1433/* Paging on empty list: Verify none of them page */
1434testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
1435 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1436 cid_list := { cIl_LAC := { } };
1437 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001438 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001439}
1440
Stefan Sperling049a86e2018-03-20 15:51:00 +01001441/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
1442testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
1443 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1444 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
1445 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
1446 f_shutdown_helper();
1447}
1448
Harald Welte6f521d82017-12-11 19:52:02 +01001449/* Verify paging retransmission interval + count */
1450/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01001451/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01001452
Harald Weltee65d40e2017-12-13 00:09:06 +01001453/* Verify PCH load */
1454testcase TC_paging_imsi_load() runs on test_CT {
1455 var BSSMAP_FIELD_CellIdentificationList cid_list;
1456 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01001457 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01001458 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001459 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01001460
1461 /* tell BSC there is no paging space anymore */
1462 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01001463 f_sleep(0.2);
1464 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01001465
1466 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
1467 * there would be 8 retransmissions during 4 seconds */
1468 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01001469 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01001470 alt {
1471 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1472 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02001473 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01001474 }
Harald Welte2caa1062018-03-17 18:19:05 +01001475 [] T_retrans.timeout {
1476 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
1477 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
1478 T_retrans.start;
1479 repeat;
1480 }
Harald Weltee65d40e2017-12-13 00:09:06 +01001481 [] T.timeout {
1482 setverdict(pass);
1483 }
1484 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001485
1486 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01001487}
1488
Harald Welte235ebf12017-12-15 14:18:16 +01001489/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01001490testcase TC_paging_counter() runs on test_CT {
1491 var BSSMAP_FIELD_CellIdentificationList cid_list;
1492 timer T := 4.0;
1493 var integer i;
1494 var integer paging_attempted_bsc;
1495 var integer paging_attempted_bts[NUM_BTS];
1496 var integer paging_expired_bts[NUM_BTS];
1497 cid_list := valueof(ts_BSSMAP_CIL_noCell);
1498
1499 f_init();
1500
1501 /* read counters before paging */
1502 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
1503 for (i := 0; i < NUM_BTS; i := i+1) {
1504 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
1505 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
1506 }
1507
1508 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
1509
1510 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
1511 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
1512 for (i := 0; i < NUM_BTS; i := i+1) {
1513 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
1514 paging_attempted_bts[i]+1);
1515 }
1516
1517 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
1518 f_sleep(12.0);
1519 for (i := 0; i < NUM_BTS; i := i+1) {
1520 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
1521 paging_expired_bts[i]+1);
1522 }
Harald Welte1ff69992017-12-14 12:31:17 +01001523
Philipp Maier282ca4b2018-02-27 17:17:00 +01001524 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01001525}
1526
1527
Harald Welte10985002017-12-12 09:29:15 +01001528/* Verify paging stops after A-RESET */
1529testcase TC_paging_imsi_a_reset() runs on test_CT {
1530 var BSSMAP_FIELD_CellIdentificationList cid_list;
1531 timer T := 3.0;
1532 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001533 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01001534
1535 /* Perform a BSSMAP Reset and wait for ACK */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001536 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 +01001537 alt {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001538 [] 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 +01001539 [] BSSAP.receive { repeat; }
1540 }
1541
Daniel Willmanncbef3982018-07-30 09:22:40 +02001542 /* Wait to avoid a possible race condition if a paging message is
1543 * received right before the reset ACK. */
1544 f_sleep(0.2);
1545
Harald Welte10985002017-12-12 09:29:15 +01001546 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01001547 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
1548 IPA_RSL[i].clear;
1549 }
Harald Welte10985002017-12-12 09:29:15 +01001550
1551 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
1552 T.start;
1553 alt {
1554 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1555 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001556 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01001557 }
Harald Welte5d1a2202017-12-13 19:51:29 +01001558 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1559 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001560 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001561 }
1562 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1563 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001564 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001565 }
Harald Welte10985002017-12-12 09:29:15 +01001566 [] T.timeout {
1567 setverdict(pass);
1568 }
1569 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001570
1571 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01001572}
Harald Welteae026692017-12-09 01:03:01 +01001573
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001574/* Verify how we handle unsolicited Paging Response, for instance because we
1575 * receive a Paging Response after T3113 expired (and subscriber information was
1576 * dropped). See OS#3680.
1577 */
1578testcase TC_paging_resp_unsol() runs on test_CT {
1579
1580 f_init(1);
1581
1582 var BSSAP_N_CONNECT_ind rx_c_ind;
1583 var DchanTuple dt;
1584 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
1585
1586 /* Send CHAN RQD and wait for allocation; acknowledge it */
1587 dt.rsl_chan_nr := f_chreq_act_ack();
1588
1589 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
1590 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
1591
1592 /* expect BSC to disable the channel */
Pau Espin Pedrol5ee6f6c2018-12-07 12:07:43 +01001593 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001594 setverdict(pass);
1595
1596}
1597
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001598/* Test RSL link drop causes counter increment */
1599testcase TC_rsl_drop_counter() runs on test_CT {
1600 var integer rsl_fail;
1601
Harald Welte89d42e82017-12-17 16:42:41 +01001602 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001603
1604 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
1605
1606 bts[0].rsl.vc_IPA.stop;
1607
1608 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
1609
1610 setverdict(pass);
1611}
1612
1613/* TODO: Test OML link drop causes counter increment */
1614
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001615/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
1616function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
1617 timer T := 10.0;
1618
1619 bts[0].rsl.id := "IPA-0-RSL";
1620 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
1621 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
1622 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
1623 bts[0].rsl.ccm_pars.unit_id := "0/0/0"; /* value which is unknown at BTS */
1624
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001625 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
1626
1627 f_init_mgcp("VirtMSC");
1628
1629 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
1630 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
1631 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
1632 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
1633
1634 /* wait for IPA OML link to connect and then disconnect */
1635 T.start;
1636 alt {
1637 [] IPA_RSL[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) {
1638 T.stop;
1639 return true;
1640 }
1641 [] IPA_RSL[0].receive { repeat }
1642 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02001643 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001644 }
1645 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001646 return false;
1647}
1648
1649/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1650testcase TC_rsl_unknown_unit_id() runs on test_CT {
1651 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
1652 setverdict(pass);
1653 } else {
1654 setverdict(fail, "Timeout RSL waiting for connection to close");
1655 }
1656}
1657
1658
1659/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1660testcase TC_oml_unknown_unit_id() runs on test_CT {
1661 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
1662 setverdict(pass);
1663 } else {
1664 setverdict(fail, "Timeout OML waiting for connection to close");
1665 }
1666}
1667
1668
Harald Weltec1a2fff2017-12-17 11:06:19 +01001669/***********************************************************************
Harald Welte6811d102019-04-14 22:23:14 +02001670 * "New world" test cases using RSL_Emulation + RAN_Emulation
Harald Weltec1a2fff2017-12-17 11:06:19 +01001671 ***********************************************************************/
1672
Harald Welte6811d102019-04-14 22:23:14 +02001673import from RAN_Emulation all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01001674import from RSL_Emulation all;
1675import from MSC_ConnectionHandler all;
1676
1677type function void_fn(charstring id) runs on MSC_ConnHdlr;
1678
Harald Welte336820c2018-05-31 20:34:52 +02001679/* helper function to create and connect a MSC_ConnHdlr component */
Harald Welteff579f92018-05-31 22:19:39 +02001680private function f_connect_handler(inout MSC_ConnHdlr vc_conn) runs on test_CT {
Harald Welte6811d102019-04-14 22:23:14 +02001681 connect(vc_conn:RAN, g_bssap.vc_RAN:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001682 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001683 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01001684 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01001685 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01001686 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
1687 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
1688 }
Harald Welte6811d102019-04-14 22:23:14 +02001689 connect(vc_conn:BSSAP, g_bssap.vc_RAN:CLIENT);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001690 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Harald Welte336820c2018-05-31 20:34:52 +02001691}
1692
1693function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
1694runs on test_CT return MSC_ConnHdlr {
1695 var charstring id := testcasename();
1696 var MSC_ConnHdlr vc_conn;
1697 vc_conn := MSC_ConnHdlr.create(id);
1698 f_connect_handler(vc_conn);
Harald Weltea0630032018-03-20 21:09:55 +01001699 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001700 return vc_conn;
1701}
1702
Harald Weltea0630032018-03-20 21:09:55 +01001703/* first function inside ConnHdlr component; sets g_pars + starts function */
1704private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
1705runs on MSC_ConnHdlr {
1706 if (isvalue(pars)) {
1707 g_pars := valueof(pars);
1708 }
1709 fn.apply(id);
1710}
1711
Harald Welte3c86ea02018-05-10 22:28:05 +02001712/* Establish signalling channel (non-assignment case) followed by cipher mode */
1713private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001714 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1715 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02001716 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02001717 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
1718 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
1719 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
1720 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02001721
Philipp Maier23000732018-05-18 11:25:37 +02001722 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02001723}
1724testcase TC_ciph_mode_a5_0() runs on test_CT {
1725 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001726 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001727 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
1728
1729 f_init(1, true);
1730 f_sleep(1.0);
1731 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1732 vc_conn.done;
1733}
1734testcase TC_ciph_mode_a5_1() runs on test_CT {
1735 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001736 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001737 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
1738
1739 f_init(1, true);
1740 f_sleep(1.0);
1741 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1742 vc_conn.done;
1743}
1744testcase TC_ciph_mode_a5_3() runs on test_CT {
1745 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001746 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001747 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
1748
1749 f_init(1, true);
1750 f_sleep(1.0);
1751 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1752 vc_conn.done;
1753}
1754
1755
1756/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02001757private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001758 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1759 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01001760
Harald Welte552620d2017-12-16 23:21:36 +01001761 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1762 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01001763
Harald Weltea0630032018-03-20 21:09:55 +01001764 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01001765}
Harald Welte552620d2017-12-16 23:21:36 +01001766testcase TC_assignment_fr_a5_0() runs on test_CT {
1767 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001768 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001769 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01001770
Harald Welte89d42e82017-12-17 16:42:41 +01001771 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001772 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001773 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01001774 vc_conn.done;
1775}
Harald Welte552620d2017-12-16 23:21:36 +01001776testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01001777 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001778 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001779 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001780
Harald Welte89d42e82017-12-17 16:42:41 +01001781 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001782 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001783 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
1784 vc_conn.done;
1785}
1786testcase TC_assignment_fr_a5_3() runs on test_CT {
1787 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001788 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001789 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001790
Harald Welte651fcdc2018-05-10 20:23:16 +02001791 f_init(1, true);
1792 f_sleep(1.0);
1793 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001794 vc_conn.done;
1795}
1796
Harald Welte552620d2017-12-16 23:21:36 +01001797/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
1798private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001799 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01001800 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001801 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001802 const OCT8 kc := '0001020304050607'O;
1803
1804 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001805 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
1806
Harald Weltea0630032018-03-20 21:09:55 +01001807 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01001808}
Harald Welte552620d2017-12-16 23:21:36 +01001809testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
1810 var MSC_ConnHdlr vc_conn;
1811
Harald Welte89d42e82017-12-17 16:42:41 +01001812 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001813 f_sleep(1.0);
1814
Harald Welte8863fa12018-05-10 20:15:27 +02001815 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01001816 vc_conn.done;
1817}
1818
Harald Welte552620d2017-12-16 23:21:36 +01001819private function f_tc_assignment_fr_a5_4(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001820 g_pars := f_gen_test_hdlr_pars();
Harald Welteed848512018-05-24 22:27:58 +02001821 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1822 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001823 const OCT8 kc := '0001020304050607'O;
1824 const OCT16 kc128 := kc & kc;
1825
1826 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1827 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Weltea0630032018-03-20 21:09:55 +01001828 f_establish_fully(ass_cmd, exp_compl);
Harald Welte38b2a102017-12-23 02:42:58 +01001829 f_cipher_mode('10'O, kc, kc128, true);
Harald Welte552620d2017-12-16 23:21:36 +01001830 /* TODO: expect GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED cause value */
Harald Welte552620d2017-12-16 23:21:36 +01001831}
Harald Welte552620d2017-12-16 23:21:36 +01001832testcase TC_assignment_fr_a5_4() runs on test_CT {
1833 var MSC_ConnHdlr vc_conn;
1834
Harald Welte89d42e82017-12-17 16:42:41 +01001835 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001836 f_sleep(1.0);
1837
Harald Welte8863fa12018-05-10 20:15:27 +02001838 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_4));
Harald Welte552620d2017-12-16 23:21:36 +01001839 vc_conn.done;
1840}
1841
1842
Harald Welte4532e0a2017-12-23 02:05:44 +01001843private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001844 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01001845 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02001846 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01001847 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Harald Weltea0630032018-03-20 21:09:55 +01001848 f_establish_fully(ass_cmd, exp_compl);
Harald Welte4532e0a2017-12-23 02:05:44 +01001849}
1850
1851testcase TC_assignment_sign() runs on test_CT {
1852 var MSC_ConnHdlr vc_conn;
1853
1854 f_init(1, true);
1855 f_sleep(1.0);
1856
Harald Welte8863fa12018-05-10 20:15:27 +02001857 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01001858 vc_conn.done;
1859}
1860
Harald Welte60aa5762018-03-21 19:33:13 +01001861/***********************************************************************
1862 * Codec (list) testing
1863 ***********************************************************************/
1864
1865/* check if the given rsl_mode is compatible with the a_elem */
1866private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
1867return boolean {
1868 select (a_elem.codecType) {
1869 case (GSM_FR) {
1870 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
1871 return true;
1872 }
1873 }
1874 case (GSM_HR) {
1875 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
1876 return true;
1877 }
1878 }
1879 case (GSM_EFR) {
1880 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
1881 return true;
1882 }
1883 }
1884 case (FR_AMR) {
1885 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
1886 return true;
1887 }
1888 }
1889 case (HR_AMR) {
1890 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
1891 return true;
1892 }
1893 }
1894 case else { }
1895 }
1896 return false;
1897}
1898
1899/* check if the given rsl_mode is compatible with the a_list */
1900private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
1901return boolean {
1902 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
1903 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
1904 return true;
1905 }
1906 }
1907 return false;
1908}
1909
1910/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02001911function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01001912return BSSMAP_IE_ChannelType {
1913 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
1914 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
1915 select (a_elem.codecType) {
1916 case (GSM_FR) {
1917 ret.channelRateAndType := ChRate_TCHF;
1918 ret.speechId_DataIndicator := Spdi_TCHF_FR;
1919 }
1920 case (GSM_HR) {
1921 ret.channelRateAndType := ChRate_TCHH;
1922 ret.speechId_DataIndicator := Spdi_TCHH_HR;
1923 }
1924 case (GSM_EFR) {
1925 ret.channelRateAndType := ChRate_TCHF;
1926 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
1927 }
1928 case (FR_AMR) {
1929 ret.channelRateAndType := ChRate_TCHF;
1930 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
1931 }
1932 case (HR_AMR) {
1933 ret.channelRateAndType := ChRate_TCHH;
1934 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
1935 }
1936 case else {
1937 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02001938 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01001939 }
1940 }
1941 return ret;
1942}
1943
Harald Weltea63b9102018-03-22 20:36:16 +01001944private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
1945return template RSL_IE_Body {
1946 var template RSL_IE_Body mode_ie := {
1947 chan_mode := {
1948 len := ?,
1949 reserved := ?,
1950 dtx_d := ?,
1951 dtx_u := ?,
1952 spd_ind := RSL_SPDI_SPEECH,
1953 ch_rate_type := -,
1954 coding_alg_rate := -
1955 }
1956 }
1957
1958 select (a_elem.codecType) {
1959 case (GSM_FR) {
1960 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1961 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1962 }
1963 case (GSM_HR) {
1964 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1965 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1966 }
1967 case (GSM_EFR) {
1968 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1969 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
1970 }
1971 case (FR_AMR) {
1972 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1973 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1974 }
1975 case (HR_AMR) {
1976 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1977 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1978 }
1979 }
1980 return mode_ie;
1981}
1982
Harald Welte60aa5762018-03-21 19:33:13 +01001983type record CodecListTest {
1984 BSSMAP_IE_SpeechCodecList codec_list,
1985 charstring id
1986}
1987type record of CodecListTest CodecListTests
1988
1989private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001990 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
1991 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
Harald Welte60aa5762018-03-21 19:33:13 +01001992
1993 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Harald Welte79f3f542018-05-25 20:02:37 +02001994 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
1995 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
1996 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
1997 g_pars.ass_codec_list.codecElements[0];
Philipp Maierd0e64b02019-03-13 14:15:23 +01001998 if (isvalue(g_pars.expect_mr_s0_s7)) {
1999 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
2000 g_pars.expect_mr_s0_s7;
2001 }
Harald Welte79f3f542018-05-25 20:02:37 +02002002 }
Harald Welte60aa5762018-03-21 19:33:13 +01002003 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
2004 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01002005 log("expecting ASS COMPL like this: ", exp_compl);
2006
2007 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01002008
2009 /* Verify that the RSL-side activation actually matches our expectations */
2010 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
2011
2012 var RSL_IE_Body mode_ie;
2013 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
2014 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02002015 mtc.stop;
Harald Weltea63b9102018-03-22 20:36:16 +01002016 }
2017 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
2018 if (not match(mode_ie, t_mode_ie)) {
2019 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
2020 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002021
2022 var RSL_IE_Body mr_conf;
2023 if (g_pars.expect_mr_conf_ie != omit) {
2024 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
2025 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
Daniel Willmannafce8662018-07-06 23:11:32 +02002026 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002027 }
2028 log("found RSL MR CONFIG IE: ", mr_conf);
2029
2030 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
2031 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
2032 g_pars.expect_mr_conf_ie);
2033 }
2034 } else {
2035 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
2036 log("found RSL MR CONFIG IE: ", mr_conf);
2037 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
Daniel Willmannafce8662018-07-06 23:11:32 +02002038 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002039 }
2040 }
Harald Welte60aa5762018-03-21 19:33:13 +01002041}
2042
Philipp Maierd0e64b02019-03-13 14:15:23 +01002043private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
2044
2045 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2046 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2047
2048 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
2049 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
2050 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
2051 }
2052 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
2053 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
2054 log("expecting ASS FAIL like this: ", exp_fail);
2055
2056 f_establish_fully(ass_cmd, exp_fail);
2057}
2058
Harald Welte60aa5762018-03-21 19:33:13 +01002059testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002060 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002061 var MSC_ConnHdlr vc_conn;
2062
2063 f_init(1, true);
2064 f_sleep(1.0);
2065
2066 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002067 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002068 vc_conn.done;
2069}
2070
2071testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002072 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002073 var MSC_ConnHdlr vc_conn;
2074
2075 f_init(1, true);
2076 f_sleep(1.0);
2077
2078 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002079 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002080 vc_conn.done;
2081}
2082
2083testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002084 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002085 var MSC_ConnHdlr vc_conn;
2086
2087 f_init(1, true);
2088 f_sleep(1.0);
2089
2090 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002091 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002092 vc_conn.done;
2093}
2094
Philipp Maierd0e64b02019-03-13 14:15:23 +01002095/* Allow 5,90k only (current default config) */
2096private function f_allow_amr_rate_5_90k() runs on test_CT {
2097 f_vty_enter_cfg_msc(BSCVTY, 0);
2098 f_vty_transceive(BSCVTY, "amr-config 12_2k forbidden");
2099 f_vty_transceive(BSCVTY, "amr-config 10_2k forbidden");
2100 f_vty_transceive(BSCVTY, "amr-config 7_95k forbidden");
2101 f_vty_transceive(BSCVTY, "amr-config 7_40k forbidden");
2102 f_vty_transceive(BSCVTY, "amr-config 6_70k forbidden");
2103 f_vty_transceive(BSCVTY, "amr-config 5_90k allowed");
2104 f_vty_transceive(BSCVTY, "amr-config 5_15k forbidden");
2105 f_vty_transceive(BSCVTY, "amr-config 4_75k forbidden");
2106 f_vty_transceive(BSCVTY, "exit");
2107 f_vty_transceive(BSCVTY, "exit");
2108}
2109
2110/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
2111 * ("Config-NB-Code = 1") */
2112private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
2113 f_vty_enter_cfg_msc(BSCVTY, 0);
2114 f_vty_transceive(BSCVTY, "amr-config 12_2k allowed");
2115 f_vty_transceive(BSCVTY, "amr-config 10_2k forbidden");
2116 f_vty_transceive(BSCVTY, "amr-config 7_95k forbidden");
2117 f_vty_transceive(BSCVTY, "amr-config 7_40k allowed");
2118 f_vty_transceive(BSCVTY, "amr-config 6_70k forbidden");
2119 f_vty_transceive(BSCVTY, "amr-config 5_90k allowed");
2120 f_vty_transceive(BSCVTY, "amr-config 5_15k forbidden");
2121 f_vty_transceive(BSCVTY, "amr-config 4_75k allowed");
2122 f_vty_transceive(BSCVTY, "exit");
2123 f_vty_transceive(BSCVTY, "exit");
2124}
2125
Harald Welte60aa5762018-03-21 19:33:13 +01002126testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002127 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002128 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02002129
2130 /* Note: This setups the codec configuration. The parameter payload in
2131 * mr_conf must be consistant with the parameter codecElements in pars
2132 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002133 var RSL_IE_Body mr_conf := {
2134 other := {
2135 len := 2,
2136 payload := '2804'O
2137 }
2138 };
Harald Welte60aa5762018-03-21 19:33:13 +01002139
Philipp Maier7695a0d2018-09-27 17:52:14 +02002140 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Philipp Maier806f8f12019-03-12 12:13:41 +01002141 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02002142 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
2143 pars.expect_mr_conf_ie := mr_conf;
2144
Harald Welte60aa5762018-03-21 19:33:13 +01002145 f_init(1, true);
2146 f_sleep(1.0);
2147
Harald Welte8863fa12018-05-10 20:15:27 +02002148 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002149 vc_conn.done;
2150}
2151
2152testcase TC_assignment_codec_amr_h() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002153 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002154 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02002155
2156 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002157 var RSL_IE_Body mr_conf := {
2158 other := {
2159 len := 2,
2160 payload := '2804'O
2161 }
2162 };
Harald Welte60aa5762018-03-21 19:33:13 +01002163
Philipp Maier7695a0d2018-09-27 17:52:14 +02002164 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Philipp Maier806f8f12019-03-12 12:13:41 +01002165 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02002166 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2167 pars.expect_mr_conf_ie := mr_conf;
2168
Harald Welte60aa5762018-03-21 19:33:13 +01002169 f_init(1, true);
2170 f_sleep(1.0);
2171
Harald Welte8863fa12018-05-10 20:15:27 +02002172 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002173 vc_conn.done;
2174}
2175
Philipp Maierd0e64b02019-03-13 14:15:23 +01002176function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0)
2177runs on test_CT {
2178
2179 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2180 var MSC_ConnHdlr vc_conn;
2181
2182 /* See note above */
2183 var RSL_IE_Body mr_conf := {
2184 other := {
2185 len := lengthof(mrconf),
2186 payload := mrconf
2187 }
2188 };
2189
2190 if (fr) {
2191 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
2192 } else {
2193 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2194 }
2195 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
2196 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2197 pars.expect_mr_conf_ie := mr_conf;
2198 pars.expect_mr_s0_s7 := exp_s8_s0;
2199
2200 f_init(1, true);
2201 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
2202 f_sleep(1.0);
2203
2204 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
2205 vc_conn.done;
2206 f_allow_amr_rate_5_90k();
2207}
2208
2209function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
2210runs on test_CT {
2211
2212 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2213 var MSC_ConnHdlr vc_conn;
2214
2215 if (fr) {
2216 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
2217 } else {
2218 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2219 }
2220 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
2221 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2222
2223 f_init(1, true);
2224 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
2225 f_sleep(1.0);
2226
2227 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
2228 vc_conn.done;
2229 f_allow_amr_rate_5_90k();
2230}
2231
2232
2233/* Set S1, we expect an AMR multirate configuration IE with all four rates
2234 * set. */
2235testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
2236 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
2237}
2238
2239/* Set S1, we expect an AMR multirate configuration IE with the lower three
2240 * rates set. */
2241testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
2242 f_TC_assignment_codec_amr(false, '2815208820'O, '00000010'B, '00000010'B);
2243}
2244
2245/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
2246 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
2247testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
2248 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'B, '00000010'B);
2249}
2250
2251/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
2252 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
2253testcase TC_assignment_codec_amr_h_S124() runs on test_CT {
2254 f_TC_assignment_codec_amr(false, '2815208820'O, '00010110'B, '00000010'B);
2255}
2256
2257/* The following block of tests selects more and more rates until all four
2258 * possible rates are in the active set (full rate) */
2259testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
2260 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'B);
2261}
2262
2263testcase TC_assignment_codec_amr_f_S02() runs on test_CT {
2264 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'B);
2265}
2266
2267testcase TC_assignment_codec_amr_f_S024() runs on test_CT {
2268 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'B);
2269}
2270
2271testcase TC_assignment_codec_amr_f_S0247() runs on test_CT {
2272 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
2273}
2274
2275/* The following block of tests selects more and more rates until all three
2276 * possible rates are in the active set (half rate) */
2277testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
2278 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'B);
2279}
2280
2281testcase TC_assignment_codec_amr_h_S02() runs on test_CT {
2282 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
2283}
2284
2285testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
2286 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
2287}
2288
2289/* The following block tests what happens when the MSC does offer rate
2290 * configurations that are not supported by the BSC. Normally such situations
2291 * should not happen because the MSC gets informed by the BSC in advance via
2292 * the L3 COMPLETE message which rates are applicable. The MSC should not try
2293 * to offer rates that are not applicable anyway. */
2294
2295testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
2296 /* Try to include 12,2k in into the active set even though the channel
2297 * is half rate only. The BSC is expected to remove the 12,0k */
2298 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'B);
2299}
2300
2301testcase TC_assignment_codec_amr_f_S01234567() runs on test_CT {
2302 /* See what happens when all rates are selected at once. Since then
2303 * Also S1 is selected, this setting will be prefered and we should
2304 * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
2305 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
2306}
2307
2308testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
2309 /* Same as above, but with S1 missing, the MSC is then expected to
2310 * select the currently supported rates, which are also 12.2k, 7,40k,
2311 * 5,90k, and 4,75k, into the active set. */
2312 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'B);
2313}
2314
2315testcase TC_assignment_codec_amr_f_zero() runs on test_CT {
2316 /* Try to select no rates at all */
2317 f_TC_assignment_codec_amr_fail(true, '00000000'B);
2318}
2319
2320testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
2321 /* Try to select only unsupported rates */
2322 f_TC_assignment_codec_amr_fail(true, '01101000'B);
2323}
2324
2325testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
2326 /* Try to select 12,2k for half rate */
2327 f_TC_assignment_codec_amr_fail(false, '10000000'B);
2328}
2329
Philipp Maierac09bfc2019-01-08 13:41:39 +01002330private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002331 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
2332 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
2333 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
2334 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002335}
2336
2337private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002338 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
2339 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002340}
2341
2342private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002343 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
2344 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
2345 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
2346 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
2347 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
2348 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002349}
2350
2351/* Allow HR only */
2352private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
2353 g_pars := f_gen_test_hdlr_pars();
2354 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2355 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2356 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2357 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
2358 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
2359 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
2360 f_establish_fully(ass_cmd, exp_compl);
2361}
2362
2363/* Allow FR only */
2364private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
2365 g_pars := f_gen_test_hdlr_pars();
2366 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2367 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2368 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2369 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
2370 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
2371 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2372 f_establish_fully(ass_cmd, exp_compl);
2373}
2374
2375/* Allow HR only (expect assignment failure) */
2376private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
2377 g_pars := f_gen_test_hdlr_pars();
2378 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2379 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2380 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2381 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
2382 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
2383 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
2384 f_establish_fully(ass_cmd, exp_fail);
2385}
2386
2387/* Allow FR only (expect assignment failure) */
2388private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(charstring id) runs on MSC_ConnHdlr {
2389 g_pars := f_gen_test_hdlr_pars();
2390 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2391 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2392 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2393 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
2394 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
2395 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2396 f_establish_fully(ass_cmd, exp_fail);
2397}
2398
2399/* Allow FR and HR, but prefer FR */
2400private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2401 g_pars := f_gen_test_hdlr_pars();
2402 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2403 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2404 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2405 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2406 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2407 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2408 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2409 f_establish_fully(ass_cmd, exp_compl);
2410}
2411
2412/* Allow FR and HR, but prefer HR */
2413private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2414 g_pars := f_gen_test_hdlr_pars();
2415 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2416 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2417 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2418 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2419 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2420 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2421 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2422 f_establish_fully(ass_cmd, exp_compl);
2423}
2424
2425/* Allow FR and HR, but prefer FR */
2426private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2427 g_pars := f_gen_test_hdlr_pars();
2428 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2429 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2430 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2431 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2432 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2433 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2434 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2435 f_establish_fully(ass_cmd, exp_compl);
2436}
2437
2438/* Allow FR and HR, but prefer HR */
2439private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2440 g_pars := f_gen_test_hdlr_pars();
2441 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2442 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2443 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2444 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2445 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2446 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2447 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2448 f_establish_fully(ass_cmd, exp_compl);
2449}
2450
2451/* Request a HR channel while all FR channels are exhausted, this is expected
2452 * to work without conflicts */
2453testcase TC_assignment_codec_fr_exhausted_req_hr() runs on test_CT {
2454 var MSC_ConnHdlr vc_conn;
2455 f_init(1, true);
2456 f_sleep(1.0);
2457 f_enable_all_tch();
2458 f_disable_all_tch_f();
2459 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr));
2460 vc_conn.done;
2461 f_enable_all_tch();
2462 setverdict(pass);
2463}
2464
2465/* Request a FR channel while all FR channels are exhausted, this is expected
2466 * to fail. */
2467testcase TC_assignment_codec_fr_exhausted_req_fr() runs on test_CT {
2468 var MSC_ConnHdlr vc_conn;
2469 f_init(1, true);
2470 f_sleep(1.0);
2471 f_enable_all_tch();
2472 f_disable_all_tch_f();
2473 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr_fail));
2474 vc_conn.done;
2475 f_enable_all_tch();
2476 setverdict(pass);
2477}
2478
2479/* Request a FR (prefered) or alternatively a HR channel while all FR channels
2480 * are exhausted, this is expected to be resolved by selecting a HR channel. */
2481testcase TC_assignment_codec_fr_exhausted_req_fr_hr() runs on test_CT {
2482 var MSC_ConnHdlr vc_conn;
2483 f_init(1, true);
2484 f_sleep(1.0);
2485 f_enable_all_tch();
2486 f_disable_all_tch_f();
2487 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
2488 vc_conn.done;
2489 f_enable_all_tch();
2490 setverdict(pass);
2491}
2492
2493/* Request a HR (prefered) or alternatively a FR channel while all FR channels
2494 * are exhausted, this is expected to work without conflicts. */
2495testcase TC_assignment_codec_fr_exhausted_req_hr_fr() runs on test_CT {
2496 var MSC_ConnHdlr vc_conn;
2497 f_init(1, true);
2498 f_sleep(1.0);
2499 f_enable_all_tch();
2500 f_disable_all_tch_f();
2501 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_hr_fr));
2502 vc_conn.done;
2503 f_enable_all_tch();
2504 setverdict(pass);
2505}
2506
2507/* Request a FR channel while all HR channels are exhausted, this is expected
2508 * to work without conflicts */
2509testcase TC_assignment_codec_hr_exhausted_req_fr() runs on test_CT {
2510 var MSC_ConnHdlr vc_conn;
2511 f_init(1, true);
2512 f_sleep(1.0);
2513 f_enable_all_tch();
2514 f_disable_all_tch_h();
2515 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr));
2516 vc_conn.done;
2517 f_enable_all_tch();
2518 setverdict(pass);
2519}
2520
2521/* Request a HR channel while all HR channels are exhausted, this is expected
2522 * to fail. */
2523testcase TC_assignment_codec_hr_exhausted_req_hr() runs on test_CT {
2524 var MSC_ConnHdlr vc_conn;
2525 f_init(1, true);
2526 f_sleep(1.0);
2527 f_enable_all_tch();
2528 f_disable_all_tch_h();
2529 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr_fail));
2530 vc_conn.done;
2531 f_enable_all_tch();
2532 setverdict(pass);
2533}
2534
2535/* Request a HR (prefered) or alternatively a FR channel while all HR channels
2536 * are exhausted, this is expected to be resolved by selecting a FR channel. */
2537testcase TC_assignment_codec_hr_exhausted_req_hr_fr() runs on test_CT {
2538 var MSC_ConnHdlr vc_conn;
2539 f_init(1, true);
2540 f_sleep(1.0);
2541 f_enable_all_tch();
2542 f_disable_all_tch_h();
2543 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_hr_fr));
2544 vc_conn.done;
2545 f_enable_all_tch();
2546 setverdict(pass);
2547}
2548
2549/* Request a FR (prefered) or alternatively a HR channel while all HR channels
2550 * are exhausted, this is expected to work without conflicts. */
2551testcase TC_assignment_codec_hr_exhausted_req_fr_hr() runs on test_CT {
2552 var MSC_ConnHdlr vc_conn;
2553 f_init(1, true);
2554 f_sleep(1.0);
2555 f_enable_all_tch();
2556 f_disable_all_tch_h();
2557 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_fr_hr));
2558 vc_conn.done;
2559 f_enable_all_tch();
2560 setverdict(pass);
2561}
2562
2563/* Allow FR and HR, but prefer HR */
2564private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2565 g_pars := f_gen_test_hdlr_pars();
2566 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2567 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2568 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2569 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2570 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2571 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2572 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2573 f_establish_fully(ass_cmd, exp_compl);
2574}
2575
2576/* Allow FR and HR, but prefer FR */
2577private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2578 g_pars := f_gen_test_hdlr_pars();
2579 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2580 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2581 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2582 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2583 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2584 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2585 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2586 f_establish_fully(ass_cmd, exp_compl);
2587}
2588
2589/* Request a HR (prefered) or alternatively a FR channel, it is expected that
2590 * HR, which is the prefered type, is selected. */
2591testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
2592 var MSC_ConnHdlr vc_conn;
2593 f_init(1, true);
2594 f_sleep(1.0);
2595 f_enable_all_tch();
2596 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
2597 vc_conn.done;
2598 setverdict(pass);
2599}
2600
2601/* Request a FR (prefered) or alternatively a HR channel, it is expected that
2602 * FR, which is the prefered type, is selected. */
2603testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
2604 var MSC_ConnHdlr vc_conn;
2605 f_init(1, true);
2606 f_sleep(1.0);
2607 f_enable_all_tch();
2608 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
2609 vc_conn.done;
2610 setverdict(pass);
2611}
2612
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02002613testcase TC_assignment_osmux() runs on test_CT {
2614 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2615 var MSC_ConnHdlr vc_conn;
2616
2617 /* See note above */
2618 var RSL_IE_Body mr_conf := {
2619 other := {
2620 len := 2,
2621 payload := '2804'O
2622 }
2623 };
2624
2625 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2626 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
2627 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2628 pars.expect_mr_conf_ie := mr_conf;
2629 pars.use_osmux := true;
2630
2631 f_init(1, true, true);
2632 f_sleep(1.0);
2633
2634 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
2635 vc_conn.done;
2636}
2637
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02002638/* test the procedure of the MSC requesting a Classmark Update:
2639 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
2640 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01002641private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002642 g_pars := f_gen_test_hdlr_pars();
2643
Harald Weltea0630032018-03-20 21:09:55 +01002644 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01002645 /* we should now have a COMPL_L3 at the MSC */
2646 BSSAP.receive(tr_BSSMAP_ComplL3);
2647
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02002648 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
2649 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
2650
Harald Welte898113b2018-01-31 18:32:21 +01002651 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
2652 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
2653 setverdict(pass);
2654}
2655testcase TC_classmark() runs on test_CT {
2656 var MSC_ConnHdlr vc_conn;
2657 f_init(1, true);
2658 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002659 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01002660 vc_conn.done;
2661}
2662
Harald Weltee3bd6582018-01-31 22:51:25 +01002663private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002664 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01002665 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01002666 /* we should now have a COMPL_L3 at the MSC */
2667 BSSAP.receive(tr_BSSMAP_ComplL3);
2668
Harald Weltee3bd6582018-01-31 22:51:25 +01002669 /* send the single message we want to send */
2670 f_rsl_send_l3(l3);
2671}
2672
2673private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
2674 timer T := sec;
2675 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01002676 T.start;
2677 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01002678 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
2679 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02002680 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01002681 }
2682 [] T.timeout {
2683 setverdict(pass);
2684 }
2685 }
2686}
2687
Harald Weltee3bd6582018-01-31 22:51:25 +01002688/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2689private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
2690 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
2691 f_bssap_expect_nothing();
2692}
Harald Welte898113b2018-01-31 18:32:21 +01002693testcase TC_unsol_ass_fail() runs on test_CT {
2694 var MSC_ConnHdlr vc_conn;
2695 f_init(1, true);
2696 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002697 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01002698 vc_conn.done;
2699}
Harald Welte552620d2017-12-16 23:21:36 +01002700
Harald Welteea99a002018-01-31 20:46:43 +01002701
2702/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
2703private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002704 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
2705 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01002706}
2707testcase TC_unsol_ass_compl() runs on test_CT {
2708 var MSC_ConnHdlr vc_conn;
2709 f_init(1, true);
2710 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002711 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01002712 vc_conn.done;
2713}
2714
2715
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002716/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2717private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002718 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
2719 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002720}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002721testcase TC_unsol_ho_fail() runs on test_CT {
2722 var MSC_ConnHdlr vc_conn;
2723 f_init(1, true);
2724 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002725 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002726 vc_conn.done;
2727}
2728
2729
Harald Weltee3bd6582018-01-31 22:51:25 +01002730/* short message from MS should be ignored */
2731private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002732 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01002733 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01002734 /* we should now have a COMPL_L3 at the MSC */
2735 BSSAP.receive(tr_BSSMAP_ComplL3);
2736
2737 /* send short message */
2738 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
2739 f_bssap_expect_nothing();
2740}
2741testcase TC_err_82_short_msg() runs on test_CT {
2742 var MSC_ConnHdlr vc_conn;
2743 f_init(1, true);
2744 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002745 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01002746 vc_conn.done;
2747}
2748
2749
Harald Weltee9e02e42018-01-31 23:36:25 +01002750/* 24.008 8.4 Unknown message must trigger RR STATUS */
2751private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
2752 f_est_single_l3(ts_RRM_UL_REL('00'O));
2753 timer T := 3.0
2754 alt {
2755 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
2756 setverdict(pass);
2757 }
2758 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01002759 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01002760 }
2761}
2762testcase TC_err_84_unknown_msg() runs on test_CT {
2763 var MSC_ConnHdlr vc_conn;
2764 f_init(1, true);
2765 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002766 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01002767 vc_conn.done;
2768}
2769
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002770/***********************************************************************
2771 * Handover
2772 ***********************************************************************/
2773
Harald Welte94e0c342018-04-07 11:33:23 +02002774/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
2775private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
2776runs on test_CT {
2777 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2778 " timeslot "&int2str(ts_nr)&" ";
2779 f_vty_transceive(BSCVTY, cmd & suffix);
2780}
2781
Harald Welte261af4b2018-02-12 21:20:39 +01002782/* execute a "bts <0-255> trx <0-255> timeslot <0-7> sub-slot <0-7>" command on given Dchan */
2783private function f_vty_ss_action(charstring suffix, integer bts_nr, integer trx_nr, RslChannelNr chan_nr)
2784runs on MSC_ConnHdlr {
2785 /* FIXME: resolve those from component-global state */
2786 var integer ts_nr := chan_nr.tn;
2787 var integer ss_nr;
2788 if (ischosen(chan_nr.u.ch0)) {
2789 ss_nr := 0;
2790 } else if (ischosen(chan_nr.u.lm)) {
2791 ss_nr := chan_nr.u.lm.sub_chan;
2792 } else if (ischosen(chan_nr.u.sdcch4)) {
2793 ss_nr := chan_nr.u.sdcch4.sub_chan;
2794 } else if (ischosen(chan_nr.u.sdcch8)) {
2795 ss_nr := chan_nr.u.sdcch8.sub_chan;
2796 } else {
2797 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02002798 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01002799 }
2800
2801 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2802 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
2803 f_vty_transceive(BSCVTY, cmd & suffix);
2804}
2805
2806private function f_vty_handover(integer bts_nr, integer trx_nr, RslChannelNr chan_nr,
2807 integer new_bts_nr)
2808runs on MSC_ConnHdlr {
2809 f_vty_ss_action("handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
2810}
2811
2812/* intra-BSC hand-over between BTS0 and BTS1 */
2813private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002814 g_pars := f_gen_test_hdlr_pars();
Harald Welteed848512018-05-24 22:27:58 +02002815 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2816 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01002817 const OCT8 kc := '0001020304050607'O;
2818
2819 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2820 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2821
Harald Weltea0630032018-03-20 21:09:55 +01002822 f_establish_fully(ass_cmd, exp_compl);
Harald Welte261af4b2018-02-12 21:20:39 +01002823
2824 var HandoverState hs := {
2825 rr_ho_cmpl_seen := false,
2826 handover_done := false,
2827 old_chan_nr := -
2828 };
2829 /* issue hand-over command on VTY */
2830 f_vty_handover(0, 0, g_chan_nr, 1);
2831 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
2832 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002833
2834 /* From the MGW perspective, a handover is is characterized by
2835 * performing one MDCX operation with the MGW. So we expect to see
2836 * one more MDCX during handover. */
2837 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
2838
Harald Welte261af4b2018-02-12 21:20:39 +01002839 alt {
2840 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01002841 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002842
Philipp Maier4dae0652018-11-12 12:03:26 +01002843 /* Since this is an internal handover we expect the BSC to inform the
2844 * MSC about the event */
2845 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
2846
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002847 /* Check the amount of MGCP transactions is still consistant with the
2848 * test expectation */
2849 f_check_mgcp_expectations()
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01002850 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01002851}
2852
2853testcase TC_ho_int() runs on test_CT {
2854 var MSC_ConnHdlr vc_conn;
2855 f_init(2, true);
2856 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002857 vc_conn := f_start_handler(refers(f_tc_ho_int));
Harald Welte261af4b2018-02-12 21:20:39 +01002858 vc_conn.done;
2859}
Harald Weltee9e02e42018-01-31 23:36:25 +01002860
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002861private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002862 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002863
2864 var PDU_BSSAP ass_req := f_gen_ass_req();
2865 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2866 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2867 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2868 f_establish_fully(ass_req, exp_compl);
2869
2870 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2871
2872 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2873
2874 f_sleep(0.5);
2875 /* The MSC negotiates Handover Request and Handover Request Ack with
2876 * the other BSS and comes back with a BSSMAP Handover Command
2877 * containing an RR Handover Command coming from the target BSS... */
2878
2879 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
2880 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
2881 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
2882 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
2883 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
2884
2885 /* expect the Handover Command to go out on RR */
2886 var RSL_Message rsl_ho_cmd
2887 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
2888 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
2889 var RSL_IE_Body rsl_ho_cmd_l3;
2890 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
2891 log("RSL message contains no L3 Info IE, expected RR Handover Command");
2892 setverdict(fail);
2893 } else {
2894 log("Found L3 Info: ", rsl_ho_cmd_l3);
2895 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
2896 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
2897 setverdict(fail);
2898 } else {
2899 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
2900 setverdict(pass);
2901 }
2902 }
2903
2904 /* When the other BSS has reported a completed handover, this side is
2905 * torn down. */
2906
2907 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
2908 var BssmapCause cause := enum2int(cause_val);
2909 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
2910
2911 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
2912 var MgcpCommand mgcp;
2913 interleave {
2914 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
2915 [] MGCP.receive(tr_DLCX()) -> value mgcp {
2916 log("Got first DLCX: ", mgcp);
2917 }
2918 [] MGCP.receive(tr_DLCX()) -> value mgcp {
2919 log("Got second DLCX: ", mgcp);
2920 }
2921 }
2922 setverdict(pass);
2923 f_sleep(1.0);
2924}
2925testcase TC_ho_out_of_this_bsc() runs on test_CT {
2926 var MSC_ConnHdlr vc_conn;
2927
2928 f_init(1, true);
2929 f_sleep(1.0);
2930
2931 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
2932 vc_conn.done;
2933}
2934
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002935/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
2936 * simply never sends a BSSMAP Handover Command. */
2937private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01002938 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002939
2940 var PDU_BSSAP ass_req := f_gen_ass_req();
2941 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2942 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2943 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2944 f_establish_fully(ass_req, exp_compl);
2945
2946 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2947
2948 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2949
2950 /* osmo-bsc should time out 10 seconds after the handover started.
2951 * Let's give it a bit extra. */
2952 f_sleep(15.0);
2953
2954 /* The old lchan and conn should still be active. See that arbitrary L3
2955 * is still going through. */
2956 var octetstring l3 := '0123456789'O;
2957 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
2958 var template PDU_BSSAP exp_data := {
2959 discriminator := '1'B,
2960 spare := '0000000'B,
2961 dlci := '00'O,
2962 lengthIndicator := 5,
2963 pdu := {
2964 dtap := l3
2965 }
2966 };
2967 BSSAP.receive(exp_data);
2968 setverdict(pass);
2969 f_sleep(1.0);
2970}
2971testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
2972 var MSC_ConnHdlr vc_conn;
2973
2974 f_init(1, true);
2975 f_sleep(1.0);
2976
2977 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
2978 vc_conn.done;
2979}
2980
2981/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
2982 * RR Handover Failure. */
2983private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01002984 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002985
2986 var PDU_BSSAP ass_req := f_gen_ass_req();
2987 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2988 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2989 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2990 f_establish_fully(ass_req, exp_compl);
2991
2992 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2993
2994 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2995
2996 f_sleep(0.5);
2997 /* The MSC negotiates Handover Request and Handover Request Ack with
2998 * the other BSS and comes back with a BSSMAP Handover Command
2999 * containing an RR Handover Command coming from the target BSS... */
3000
3001 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
3002 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
3003 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
3004 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
3005 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
3006
3007 /* expect the Handover Command to go out on RR */
3008 var RSL_Message rsl_ho_cmd
3009 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
3010 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
3011 var RSL_IE_Body rsl_ho_cmd_l3;
3012 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
3013 log("RSL message contains no L3 Info IE, expected RR Handover Command");
3014 setverdict(fail);
3015 } else {
3016 log("Found L3 Info: ", rsl_ho_cmd_l3);
3017 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
3018 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
3019 setverdict(fail);
3020 } else {
3021 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
3022 setverdict(pass);
3023 }
3024 }
3025
3026 f_sleep(0.2);
3027 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
3028
3029 /* Should tell the MSC about the failure */
3030 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3031
3032 f_sleep(1.0);
3033
3034 /* The old lchan and conn should still be active. See that arbitrary L3
3035 * is still going through. */
3036 var octetstring l3 := '0123456789'O;
3037 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
3038 var template PDU_BSSAP exp_data := {
3039 discriminator := '1'B,
3040 spare := '0000000'B,
3041 dlci := '00'O,
3042 lengthIndicator := 5,
3043 pdu := {
3044 dtap := l3
3045 }
3046 };
3047 BSSAP.receive(exp_data);
3048 setverdict(pass);
3049 f_sleep(1.0);
3050
3051 setverdict(pass);
3052 f_sleep(1.0);
3053}
3054testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
3055 var MSC_ConnHdlr vc_conn;
3056
3057 f_init(1, true);
3058 f_sleep(1.0);
3059
3060 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
3061 vc_conn.done;
3062}
3063
3064/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
3065 * RR Handover Failure. */
3066private function f_tc_ho_out_fail_no_ho_detect(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01003067 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003068
3069 var PDU_BSSAP ass_req := f_gen_ass_req();
3070 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3071 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3072 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3073 f_establish_fully(ass_req, exp_compl);
3074
3075 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
3076
3077 BSSAP.receive(tr_BSSMAP_HandoverRequired);
3078
3079 f_sleep(0.5);
3080 /* The MSC negotiates Handover Request and Handover Request Ack with
3081 * the other BSS and comes back with a BSSMAP Handover Command
3082 * containing an RR Handover Command coming from the target BSS... */
3083
3084 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
3085 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
3086 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
3087 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
3088 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
3089
3090 /* expect the Handover Command to go out on RR */
3091 var RSL_Message rsl_ho_cmd
3092 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
3093 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
3094 var RSL_IE_Body rsl_ho_cmd_l3;
3095 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
3096 log("RSL message contains no L3 Info IE, expected RR Handover Command");
3097 setverdict(fail);
3098 } else {
3099 log("Found L3 Info: ", rsl_ho_cmd_l3);
3100 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
3101 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
3102 setverdict(fail);
3103 } else {
3104 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
3105 setverdict(pass);
3106 }
3107 }
3108
3109 /* The MS never shows up on the remote BSS. Eventually the BSC times
3110 * out and we run into 3GPP TS 48.008 3.1.5.3.3 "Abnormal Conditions":
3111 * RR should be released and Clear Request should go to the MSC. */
3112
3113 var MgcpCommand mgcp;
3114 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01003115 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
3116 log("Got Deact SACCH");
3117 }
Harald Welte924b6ea2019-02-04 01:05:34 +01003118 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01003119 log("Got RR Release");
3120 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003121 [] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
3122 log("Got RF Chan Rel");
3123 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
3124 }
3125 [] BSSAP.receive(tr_BSSMAP_ClearRequest) {
3126 log("Got BSSMAP Clear Request");
3127 }
3128 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3129 log("Got first DLCX: ", mgcp);
3130 }
3131 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3132 log("Got second DLCX: ", mgcp);
3133 }
3134 }
3135
3136 setverdict(pass);
3137 f_sleep(1.0);
3138}
3139testcase TC_ho_out_fail_no_ho_detect() runs on test_CT {
3140 var MSC_ConnHdlr vc_conn;
3141
3142 f_init(1, true);
3143 f_sleep(1.0);
3144
3145 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_ho_detect));
3146 vc_conn.done;
3147}
3148
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003149private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
3150 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
3151 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
3152 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
3153 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
3154 * before we get started. */
3155 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3156 f_rslem_register(0, new_chan_nr);
3157 g_chan_nr := new_chan_nr;
3158 f_sleep(1.0);
3159
3160 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3161 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3162 activate(as_Media());
3163
3164 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3165 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003166 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003167
3168 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3169
3170 var PDU_BSSAP rx_bssap;
3171 var octetstring ho_command_str;
3172
3173 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3174
3175 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3176 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3177 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3178 log("L3 Info in HO Request Ack is ", ho_command);
3179
3180 var GsmArfcn arfcn;
3181 var RslChannelNr actual_new_chan_nr;
3182 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3183 actual_new_chan_nr, arfcn);
3184
3185 if (actual_new_chan_nr != new_chan_nr) {
3186 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3187 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3188 setverdict(fail);
3189 return;
3190 }
3191 log("Handover Command chan_nr is", actual_new_chan_nr);
3192
3193 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3194 * tells the MS to handover to the new lchan. Here comes the new MS on
3195 * the new lchan with a Handover RACH: */
3196
3197 /* send handover detect */
3198
3199 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
3200
3201 BSSAP.receive(tr_BSSMAP_HandoverDetect);
3202
3203 /* send handover complete over the new channel */
3204
3205 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
3206 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
3207 enc_PDU_ML3_MS_NW(l3_tx)));
3208
3209 BSSAP.receive(tr_BSSMAP_HandoverComplete);
3210 setverdict(pass);
3211}
3212testcase TC_ho_into_this_bsc() runs on test_CT {
3213 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003214 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003215
3216 f_init(1, true);
3217 f_sleep(1.0);
3218
3219 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3220 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3221
3222 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
3223 vc_conn.done;
3224}
3225
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003226private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
3227 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3228 f_rslem_register(0, new_chan_nr);
3229 g_chan_nr := new_chan_nr;
3230 f_sleep(1.0);
3231
3232 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3233 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3234 activate(as_Media());
3235
3236 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3237 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003238 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003239
3240 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3241
3242 var PDU_BSSAP rx_bssap;
3243 var octetstring ho_command_str;
3244
3245 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3246
3247 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3248 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3249 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3250 log("L3 Info in HO Request Ack is ", ho_command);
3251
3252 var GsmArfcn arfcn;
3253 var RslChannelNr actual_new_chan_nr;
3254 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3255 actual_new_chan_nr, arfcn);
3256
3257 if (actual_new_chan_nr != new_chan_nr) {
3258 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3259 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3260 setverdict(fail);
3261 return;
3262 }
3263 log("Handover Command chan_nr is", actual_new_chan_nr);
3264
Neels Hofmeyr61ca08d2019-05-06 23:52:22 +02003265 /* For deterministic test results, give some time for the MGW endpoint to be configured */
3266 f_sleep(1.0);
3267
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003268 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3269 * tells the MS to handover to the new lchan. In this case, the MS
3270 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
3271 * Handover Failure to the MSC. The procedure according to 3GPP TS
3272 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
3273 * BSSMAP Clear Command: */
3274
3275 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3276 var BssmapCause cause := enum2int(cause_val);
3277 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3278
3279 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3280 var MgcpCommand mgcp;
3281 interleave {
3282 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3283 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3284 log("Got first DLCX: ", mgcp);
3285 }
3286 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3287 log("Got second DLCX: ", mgcp);
3288 }
3289 }
3290 setverdict(pass);
3291 f_sleep(1.0);
3292
3293 setverdict(pass);
3294}
3295testcase TC_ho_in_fail_msc_clears() runs on test_CT {
3296 var MSC_ConnHdlr vc_conn;
3297 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3298
3299 f_init(1, true);
3300 f_sleep(1.0);
3301
3302 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3303 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3304
3305 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
3306 vc_conn.done;
3307}
3308
3309private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
3310 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
3311 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
3312 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
3313 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
3314 * before we get started. */
3315 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3316 f_rslem_register(0, new_chan_nr);
3317 g_chan_nr := new_chan_nr;
3318 f_sleep(1.0);
3319
3320 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3321 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3322 activate(as_Media());
3323
3324 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3325 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003326 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003327
3328 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3329
3330 var PDU_BSSAP rx_bssap;
3331 var octetstring ho_command_str;
3332
3333 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3334
3335 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3336 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3337 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3338 log("L3 Info in HO Request Ack is ", ho_command);
3339
3340 var GsmArfcn arfcn;
3341 var RslChannelNr actual_new_chan_nr;
3342 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3343 actual_new_chan_nr, arfcn);
3344
3345 if (actual_new_chan_nr != new_chan_nr) {
3346 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3347 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3348 setverdict(fail);
3349 return;
3350 }
3351 log("Handover Command chan_nr is", actual_new_chan_nr);
3352
3353 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3354 * tells the MS to handover to the new lchan. Here comes the new MS on
3355 * the new lchan with a Handover RACH: */
3356
3357 /* send handover detect */
3358
3359 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
3360
3361 BSSAP.receive(tr_BSSMAP_HandoverDetect);
3362
3363 /* The MSC chooses to clear the connection now, maybe we got the
3364 * Handover RACH on the new cell but the MS still signaled Handover
3365 * Failure to the old BSS? */
3366
3367 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3368 var BssmapCause cause := enum2int(cause_val);
3369 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3370
3371 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3372 var MgcpCommand mgcp;
3373 interleave {
3374 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3375 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3376 log("Got first DLCX: ", mgcp);
3377 }
3378 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3379 log("Got second DLCX: ", mgcp);
3380 }
3381 }
3382 setverdict(pass);
3383 f_sleep(1.0);
3384}
3385testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
3386 var MSC_ConnHdlr vc_conn;
3387 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3388
3389 f_init(1, true);
3390 f_sleep(1.0);
3391
3392 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3393 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3394
3395 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
3396 vc_conn.done;
3397}
3398
3399/* The new BSS's lchan times out before the MSC decides that handover failed. */
3400private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
3401 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3402 f_rslem_register(0, new_chan_nr);
3403 g_chan_nr := new_chan_nr;
3404 f_sleep(1.0);
3405
3406 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3407 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3408 activate(as_Media());
3409
3410 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3411 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003412 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003413
3414 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3415
3416 var PDU_BSSAP rx_bssap;
3417 var octetstring ho_command_str;
3418
3419 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3420
3421 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3422 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3423 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3424 log("L3 Info in HO Request Ack is ", ho_command);
3425
3426 var GsmArfcn arfcn;
3427 var RslChannelNr actual_new_chan_nr;
3428 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3429 actual_new_chan_nr, arfcn);
3430
3431 if (actual_new_chan_nr != new_chan_nr) {
3432 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3433 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3434 setverdict(fail);
3435 return;
3436 }
3437 log("Handover Command chan_nr is", actual_new_chan_nr);
3438
3439 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3440 * tells the MS to handover to the new lchan. But the MS never shows up
3441 * on the new lchan. */
3442
3443 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3444
3445 /* Did osmo-bsc also send a Clear Request? */
3446 timer T := 0.5;
3447 T.start;
3448 alt {
3449 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
3450 [] T.timeout { }
3451 }
3452
3453 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
3454 * asked for it, this is a Handover Failure after all). */
3455
3456 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3457 var BssmapCause cause := enum2int(cause_val);
3458 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3459
3460 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3461 var MgcpCommand mgcp;
3462 interleave {
3463 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3464 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3465 log("Got first DLCX: ", mgcp);
3466 }
3467 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3468 log("Got second DLCX: ", mgcp);
3469 }
3470 }
3471 setverdict(pass);
3472 f_sleep(1.0);
3473
3474 setverdict(pass);
3475}
3476testcase TC_ho_in_fail_no_detect() runs on test_CT {
3477 var MSC_ConnHdlr vc_conn;
3478 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3479
3480 f_init(1, true);
3481 f_sleep(1.0);
3482
3483 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3484 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3485
3486 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
3487 vc_conn.done;
3488}
3489
3490/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
3491private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
3492 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3493 f_rslem_register(0, new_chan_nr);
3494 g_chan_nr := new_chan_nr;
3495 f_sleep(1.0);
3496
3497 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3498 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3499 activate(as_Media());
3500
3501 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3502 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003503 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003504
3505 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3506
3507 var PDU_BSSAP rx_bssap;
3508 var octetstring ho_command_str;
3509
3510 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3511
3512 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3513 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3514 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3515 log("L3 Info in HO Request Ack is ", ho_command);
3516
3517 var GsmArfcn arfcn;
3518 var RslChannelNr actual_new_chan_nr;
3519 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3520 actual_new_chan_nr, arfcn);
3521
3522 if (actual_new_chan_nr != new_chan_nr) {
3523 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3524 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3525 setverdict(fail);
3526 return;
3527 }
3528 log("Handover Command chan_nr is", actual_new_chan_nr);
3529
3530 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3531 * tells the MS to handover to the new lchan. But the MS never shows up
3532 * on the new lchan. */
3533
3534 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3535
3536 /* MSC plays dumb and sends no Clear Command */
3537
3538 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3539 var PDU_BSSAP rx_clear_request;
3540 var MgcpCommand mgcp;
3541 interleave {
3542 [] BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
3543 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
3544 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3545 };
3546 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3547
3548 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3549 log("Got first DLCX: ", mgcp);
3550 }
3551 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3552 log("Got second DLCX: ", mgcp);
3553 }
3554 }
3555 setverdict(pass);
3556 f_sleep(1.0);
3557}
3558testcase TC_ho_in_fail_no_detect2() runs on test_CT {
3559 var MSC_ConnHdlr vc_conn;
3560 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3561
3562 f_init(1, true);
3563 f_sleep(1.0);
3564
3565 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3566 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3567
3568 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
3569 vc_conn.done;
3570}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003571
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003572/* OS#3041: Open and close N connections in a normal fashion, and expect no
3573 * BSSMAP Reset just because of that. */
3574testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
3575 var default d;
3576 var integer i;
3577 var DchanTuple dt;
3578
3579 f_init();
3580
3581 /* Wait for initial BSSMAP Reset to pass */
3582 f_sleep(4.0);
3583
3584 d := activate(no_bssmap_reset());
3585
3586 /* Setup up a number of connections and RLSD them again from the MSC
3587 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3588 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02003589 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003590 /* Since we're doing a lot of runs, give each one a fresh
3591 * T_guard from the top. */
3592 T_guard.start;
3593
3594 /* Setup a BSSAP connection and clear it right away. This is
3595 * the MSC telling the BSC about a planned release, it's not an
3596 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02003597 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003598
3599 /* MSC disconnects (RLSD). */
3600 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
3601 }
3602
3603 /* In the buggy behavior, a timeout of 2 seconds happens between above
3604 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3605 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3606 f_sleep(4.0);
3607
3608 deactivate(d);
3609 f_shutdown_helper();
3610}
Harald Welte552620d2017-12-16 23:21:36 +01003611
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003612/* OS#3041: Open and close N connections in a normal fashion, and expect no
3613 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
3614 * the MSC. */
3615testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
3616 var default d;
3617 var integer i;
3618 var DchanTuple dt;
3619 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003620 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
3621 var BssmapCause cause := enum2int(cause_val);
3622
3623 f_init();
3624
3625 /* Wait for initial BSSMAP Reset to pass */
3626 f_sleep(4.0);
3627
3628 d := activate(no_bssmap_reset());
3629
3630 /* Setup up a number of connections and RLSD them again from the MSC
3631 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3632 * Let's do it some more times for good measure. */
3633 for (i := 0; i < 8; i := i+1) {
3634 /* Since we're doing a lot of runs, give each one a fresh
3635 * T_guard from the top. */
3636 T_guard.start;
3637
3638 /* Setup a BSSAP connection and clear it right away. This is
3639 * the MSC telling the BSC about a planned release, it's not an
3640 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02003641 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003642
3643 /* Instruct BSC to clear channel */
3644 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
3645
3646 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02003647 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003648 }
3649
3650 /* In the buggy behavior, a timeout of 2 seconds happens between above
3651 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3652 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3653 f_sleep(4.0);
3654
3655 deactivate(d);
3656 f_shutdown_helper();
3657}
3658
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003659/* OS#3041: Open and close N connections in a normal fashion, and expect no
3660 * BSSMAP Reset just because of that. Close connections from the MS side with a
3661 * Release Ind on RSL. */
3662testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
3663 var default d;
3664 var integer i;
3665 var DchanTuple dt;
3666 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003667 var integer j;
3668
3669 f_init();
3670
3671 /* Wait for initial BSSMAP Reset to pass */
3672 f_sleep(4.0);
3673
3674 d := activate(no_bssmap_reset());
3675
3676 /* Setup up a number of connections and RLSD them again from the MSC
3677 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3678 * Let's do it some more times for good measure. */
3679 for (i := 0; i < 8; i := i+1) {
3680 /* Since we're doing a lot of runs, give each one a fresh
3681 * T_guard from the top. */
3682 T_guard.start;
3683
3684 /* Setup a BSSAP connection and clear it right away. This is
3685 * the MSC telling the BSC about a planned release, it's not an
3686 * erratic loss of a connection. */
3687 dt := f_est_dchan('23'O, 23, '00010203040506'O);
3688
3689 /* simulate RLL REL IND */
3690 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
3691
3692 /* expect Clear Request on MSC side */
3693 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
3694
3695 /* Instruct BSC to clear channel */
3696 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
3697 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
3698
3699 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02003700 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003701 }
3702
3703 /* In the buggy behavior, a timeout of 2 seconds happens between above
3704 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3705 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3706 f_sleep(4.0);
3707
3708 deactivate(d);
3709 f_shutdown_helper();
3710}
3711
Harald Welte94e0c342018-04-07 11:33:23 +02003712/***********************************************************************
3713 * IPA style dynamic PDCH
3714 ***********************************************************************/
3715
3716private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
3717 template (omit) RSL_Cause nack := omit)
3718runs on test_CT {
3719 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
3720 var RSL_Message rsl_unused;
3721 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3722 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
3723 /* expect the BSC to issue the related RSL command */
3724 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3725 if (istemplatekind(nack, "omit")) {
3726 /* respond with a related acknowledgement */
3727 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3728 } else {
3729 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
3730 }
3731}
3732
3733private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
3734 template (omit) RSL_Cause nack := omit)
3735runs on test_CT {
3736 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
3737 var RSL_Message rsl_unused;
3738 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3739 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
3740 /* expect the BSC to issue the related RSL command */
3741 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
3742 if (istemplatekind(nack, "omit")) {
3743 /* respond with a related acknowledgement */
3744 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
3745 } else {
3746 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
3747 }
3748}
3749
3750private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
3751runs on test_CT return charstring {
3752 var charstring cmd, resp;
3753 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01003754 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02003755}
3756
3757private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
3758 template charstring exp)
3759runs on test_CT {
3760 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
3761 if (not match(mode, exp)) {
3762 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02003763 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02003764 }
3765}
3766
3767private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
3768runs on test_CT {
3769 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
3770 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
3771 f_vty_transceive(BSCVTY, "end");
3772}
3773
3774private const charstring TCHF_MODE := "TCH/F mode";
3775private const charstring TCHH_MODE := "TCH/H mode";
3776private const charstring PDCH_MODE := "PDCH mode";
3777private const charstring NONE_MODE := "NONE mode";
3778
3779/* Test IPA PDCH activation / deactivation triggered by VTY */
3780testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
3781 var RSL_Message rsl_unused;
3782
3783 /* change Timeslot 6 before f_init() starts RSL */
3784 f_init_vty();
3785 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
3786 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3787
3788 f_init(1, false);
3789 f_sleep(1.0);
3790
3791 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
3792
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003793 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003794 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3795 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3796 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3797 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3798 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003799 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003800 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3801
3802 /* De-activate it via VTY */
3803 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3804 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003805 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003806 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3807
3808 /* re-activate it via VTY */
3809 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
3810 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003811 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003812 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3813
3814 /* and finally de-activate it again */
3815 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3816 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003817 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003818 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3819
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003820 /* clean up config */
3821 f_ts_set_chcomb(0, 0, 6, "PDCH");
3822
Harald Welte94e0c342018-04-07 11:33:23 +02003823 setverdict(pass);
3824}
3825
3826/* Test IPA PDCH activation NACK */
3827testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
3828 var RSL_Message rsl_unused;
3829
3830 /* change Timeslot 6 before f_init() starts RSL */
3831 f_init_vty();
3832 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
3833 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3834
3835 f_init(1, false);
3836 f_sleep(1.0);
3837
3838 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
3839
3840 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3841 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3842 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3843 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3844 f_sleep(1.0);
3845 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3846
3847 /* De-activate it via VTY */
3848 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3849 f_sleep(1.0);
3850 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3851
3852 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
3853 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
3854 f_sleep(1.0);
3855 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3856
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003857 /* clean up config */
3858 f_ts_set_chcomb(0, 0, 6, "PDCH");
3859
Harald Welte94e0c342018-04-07 11:33:23 +02003860 setverdict(pass);
3861}
3862
3863
3864/***********************************************************************
3865 * Osmocom style dynamic PDCH
3866 ***********************************************************************/
3867
3868private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
3869 template (omit) RSL_Cause nack := omit)
3870runs on test_CT {
3871 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
3872 var RSL_Message rsl_unused;
3873 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3874 /* FIXME: no VTY command to activate Osmocom PDCH !! */
3875 /* expect the BSC to issue the related RSL command */
3876 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
3877 if (istemplatekind(nack, "omit")) {
3878 /* respond with a related acknowledgement */
3879 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
3880 } else {
3881 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
3882 }
3883}
3884
3885private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
3886 template (omit) RSL_Cause nack := omit)
3887runs on test_CT {
3888 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
3889 var RSL_Message rsl_unused;
3890 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3891 /* FIXME: no VTY command to activate Osmocom PDCH !! */
3892 /* expect the BSC to issue the related RSL command */
3893 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
3894 if (istemplatekind(nack, "omit")) {
3895 /* respond with a related acknowledgement */
3896 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
3897 } else {
3898 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
3899 }
3900}
3901
3902/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
3903testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
3904 var RSL_Message rsl_unused;
3905
3906 /* change Timeslot 6 before f_init() starts RSL */
3907 f_init_vty();
3908 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
3909 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3910
3911 f_init(1, false);
3912 f_sleep(1.0);
3913
3914 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
3915
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003916 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003917 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
3918 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3919 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
3920
3921 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
3922 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003923 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 +02003924 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3925
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003926 /* clean up config */
3927 f_ts_set_chcomb(0, 0, 6, "PDCH");
3928
Harald Welte94e0c342018-04-07 11:33:23 +02003929 setverdict(pass);
3930}
3931
3932/* Test Osmocom dyn PDCH activation NACK behavior */
3933testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
3934 var RSL_Message rsl_unused;
3935
3936 /* change Timeslot 6 before f_init() starts RSL */
3937 f_init_vty();
3938 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
3939 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3940
3941 f_init(1, false);
3942 f_sleep(1.0);
3943
3944 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
3945
3946 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 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
3951 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
3952 f_sleep(1.0);
3953 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_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
Stefan Sperling0796a822018-10-05 13:01:39 +02003961testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02003962 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02003963 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
3964 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
3965 }
3966}
3967
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02003968testcase TC_chopped_ipa_payload() runs on test_CT {
3969 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
3970 /* TODO: mp_bsc_ctrl_port does not work yet */};
3971 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
3972 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
3973 }
3974}
3975
3976
Harald Welte0ea2d5e2018-04-07 21:40:29 +02003977/* Dyn PDCH todo:
3978 * activate OSMO as TCH/F
3979 * activate OSMO as TCH/H
3980 * does the BSC-located PCU socket get the updated INFO?
3981 * what if no PCU is connected at the time?
3982 * is the info correct on delayed PCU (re)connect?
3983 */
Harald Welte94e0c342018-04-07 11:33:23 +02003984
Harald Welte28d943e2017-11-25 15:00:50 +01003985control {
Harald Welte898113b2018-01-31 18:32:21 +01003986 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +01003987 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01003988 execute( TC_ctrl_msc0_connection_status() );
Harald Welte96c94412017-12-09 03:12:45 +01003989 execute( TC_ctrl() );
Harald Welte898113b2018-01-31 18:32:21 +01003990
3991 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +01003992 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +01003993 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +01003994 execute( TC_chan_act_ack_noest() );
3995 execute( TC_chan_act_ack_est_ind_noreply() );
3996 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +01003997 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +01003998 execute( TC_chan_exhaustion() );
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07003999 execute( TC_chan_deact_silence() );
Harald Welte4003d112017-12-09 22:35:39 +01004000 execute( TC_chan_rel_rll_rel_ind() );
4001 execute( TC_chan_rel_conn_fail() );
4002 execute( TC_chan_rel_hard_clear() );
Harald Welte99787102019-02-04 10:41:36 +01004003 execute( TC_chan_rel_hard_clear_csfb() );
Harald Welted8c36cd2017-12-09 23:05:31 +01004004 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +02004005 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +01004006 execute( TC_chan_rel_a_reset() );
Harald Welte6f521d82017-12-11 19:52:02 +01004007
Harald Weltecfe2c962017-12-15 12:09:32 +01004008 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +01004009
4010 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +01004011 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +01004012 execute( TC_assignment_csd() );
4013 execute( TC_assignment_ctm() );
4014 execute( TC_assignment_sign() );
4015 execute( TC_assignment_fr_a5_0() );
4016 execute( TC_assignment_fr_a5_1() );
Harald Welte8f67d1d2018-05-25 20:38:42 +02004017 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
4018 execute( TC_assignment_fr_a5_1_codec_missing() );
4019 }
Harald Welte235ebf12017-12-15 14:18:16 +01004020 execute( TC_assignment_fr_a5_3() );
4021 execute( TC_assignment_fr_a5_4() );
Harald Welte3c86ea02018-05-10 22:28:05 +02004022 execute( TC_ciph_mode_a5_0() );
4023 execute( TC_ciph_mode_a5_1() );
4024 execute( TC_ciph_mode_a5_3() );
Harald Welte16a4adf2017-12-14 18:54:01 +01004025
Harald Welte60aa5762018-03-21 19:33:13 +01004026 execute( TC_assignment_codec_fr() );
4027 execute( TC_assignment_codec_hr() );
4028 execute( TC_assignment_codec_efr() );
4029 execute( TC_assignment_codec_amr_f() );
4030 execute( TC_assignment_codec_amr_h() );
Philipp Maier8a581d22019-03-26 18:32:48 +01004031
4032 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
4033 execute( TC_assignment_codec_amr_f_S1() );
4034 execute( TC_assignment_codec_amr_h_S1() );
4035 execute( TC_assignment_codec_amr_f_S124() );
4036 execute( TC_assignment_codec_amr_h_S124() );
4037 execute( TC_assignment_codec_amr_f_S0() );
4038 execute( TC_assignment_codec_amr_f_S02() );
4039 execute( TC_assignment_codec_amr_f_S024() );
4040 execute( TC_assignment_codec_amr_f_S0247() );
4041 execute( TC_assignment_codec_amr_h_S0() );
4042 execute( TC_assignment_codec_amr_h_S02() );
4043 execute( TC_assignment_codec_amr_h_S024() );
4044 execute( TC_assignment_codec_amr_h_S0247() );
4045 execute( TC_assignment_codec_amr_f_S01234567() );
4046 execute( TC_assignment_codec_amr_f_S0234567() );
4047 execute( TC_assignment_codec_amr_f_zero() );
4048 execute( TC_assignment_codec_amr_f_unsupp() );
4049 execute( TC_assignment_codec_amr_h_S7() );
4050 }
Harald Welte60aa5762018-03-21 19:33:13 +01004051
Philipp Maierac09bfc2019-01-08 13:41:39 +01004052 execute( TC_assignment_codec_fr_exhausted_req_hr() );
4053 execute( TC_assignment_codec_fr_exhausted_req_fr() );
4054 execute( TC_assignment_codec_fr_exhausted_req_fr_hr() );
4055 execute( TC_assignment_codec_fr_exhausted_req_hr_fr() );
4056 execute( TC_assignment_codec_hr_exhausted_req_fr() );
4057 execute( TC_assignment_codec_hr_exhausted_req_hr() );
4058 execute( TC_assignment_codec_hr_exhausted_req_hr_fr() );
4059 execute( TC_assignment_codec_hr_exhausted_req_fr_hr() );
4060 execute( TC_assignment_codec_req_hr_fr() );
4061 execute( TC_assignment_codec_req_fr_hr() );
4062
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +02004063 if (mp_enable_osmux_test) {
4064 execute( TC_assignment_osmux() );
4065 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004066
Harald Welte898113b2018-01-31 18:32:21 +01004067 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +01004068 execute( TC_rll_est_ind_inact_lchan() );
4069 execute( TC_rll_est_ind_inval_sapi1() );
4070 execute( TC_rll_est_ind_inval_sapi3() );
4071 execute( TC_rll_est_ind_inval_sacch() );
4072
Harald Welte898113b2018-01-31 18:32:21 +01004073 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +01004074 execute( TC_paging_imsi_nochan() );
4075 execute( TC_paging_tmsi_nochan() );
4076 execute( TC_paging_tmsi_any() );
4077 execute( TC_paging_tmsi_sdcch() );
4078 execute( TC_paging_tmsi_tch_f() );
4079 execute( TC_paging_tmsi_tch_hf() );
4080 execute( TC_paging_imsi_nochan_cgi() );
4081 execute( TC_paging_imsi_nochan_lac_ci() );
4082 execute( TC_paging_imsi_nochan_ci() );
4083 execute( TC_paging_imsi_nochan_lai() );
4084 execute( TC_paging_imsi_nochan_lac() );
4085 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +01004086 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
4087 execute( TC_paging_imsi_nochan_rnc() );
4088 execute( TC_paging_imsi_nochan_lac_rnc() );
4089 execute( TC_paging_imsi_nochan_lacs() );
4090 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +01004091 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +01004092 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +01004093 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +01004094 execute( TC_paging_counter() );
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01004095 execute( TC_paging_resp_unsol() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +01004096
4097 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +01004098 execute( TC_rsl_unknown_unit_id() );
4099
4100 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +01004101
4102 execute( TC_classmark() );
4103 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +01004104 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004105 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +01004106 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +01004107 execute( TC_err_84_unknown_msg() );
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004108
Harald Welte261af4b2018-02-12 21:20:39 +01004109 execute( TC_ho_int() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004110
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004111 execute( TC_ho_out_of_this_bsc() );
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004112 execute( TC_ho_out_fail_no_msc_response() );
4113 execute( TC_ho_out_fail_rr_ho_failure() );
4114 execute( TC_ho_out_fail_no_ho_detect() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004115
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004116 execute( TC_ho_into_this_bsc() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004117 execute( TC_ho_in_fail_msc_clears() );
4118 execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
4119 execute( TC_ho_in_fail_no_detect() );
4120 execute( TC_ho_in_fail_no_detect2() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01004121
4122 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01004123 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01004124 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +02004125
4126 execute( TC_dyn_pdch_ipa_act_deact() );
4127 execute( TC_dyn_pdch_ipa_act_nack() );
4128 execute( TC_dyn_pdch_osmo_act_deact() );
4129 execute( TC_dyn_pdch_osmo_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +02004130
Stefan Sperling0796a822018-10-05 13:01:39 +02004131 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02004132 execute( TC_chopped_ipa_payload() );
Stefan Sperling0796a822018-10-05 13:01:39 +02004133
Harald Welte99f3ca02018-06-14 13:40:29 +02004134 /* at bottom as they might crash OsmoBSC before OS#3182 is fixed */
4135 execute( TC_early_conn_fail() );
4136 execute( TC_late_conn_fail() );
4137
Harald Welte28d943e2017-11-25 15:00:50 +01004138}
4139
4140}