blob: 4c86e51f9349e74725fa34cdb64e46d9173e51d5 [file] [log] [blame]
Harald Welte28d943e2017-11-25 15:00:50 +01001module BSC_Tests {
2
Harald Welte21b46bd2017-12-17 19:46:32 +01003/* Integration Tests for OsmoBSC
Harald Weltea0630032018-03-20 21:09:55 +01004 * (C) 2017-2018 by Harald Welte <laforge@gnumonks.org>
Harald Welte21b46bd2017-12-17 19:46:32 +01005 * All rights reserved.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
Harald Welte34b5a952019-05-27 11:54:11 +020010 * SPDX-License-Identifier: GPL-2.0-or-later
11 *
Harald Welte21b46bd2017-12-17 19:46:32 +010012 * This test suite tests OsmoBSC while emulating both multiple BTS + MS as
13 * well as the MSC. See README for more details.
14 *
15 * There are test cases that run in so-called 'handler mode' and test cases
16 * that run directly on top of the BSSAP and RSL CodecPorts. The "handler mode"
17 * tests abstract the multiplexing/demultiplexing of multiple SCCP connections
18 * and/or RSL channels and are hence suitable for higher-level test cases, while
19 * the "raw" tests directly on top of the CodecPorts are more suitable for lower-
20 * level testing.
21 */
22
Harald Welte4003d112017-12-09 22:35:39 +010023import from General_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010024import from Osmocom_Types all;
Harald Welteae026692017-12-09 01:03:01 +010025import from GSM_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010026import from IPL4asp_Types all;
27
Harald Welte6f521d82017-12-11 19:52:02 +010028import from BSSAP_Types all;
Harald Welte6811d102019-04-14 22:23:14 +020029import from RAN_Adapter all;
Harald Welteae026692017-12-09 01:03:01 +010030import from BSSAP_CodecPort all;
31import from BSSMAP_Templates all;
Harald Welte28d943e2017-11-25 15:00:50 +010032import from IPA_Emulation all;
Stefan Sperling830dc9d2018-02-12 21:08:28 +010033import from IPA_CodecPort all;
Harald Welteae026692017-12-09 01:03:01 +010034import from IPA_Types all;
Stefan Sperling0796a822018-10-05 13:01:39 +020035import from IPA_Testing all;
Harald Welteae026692017-12-09 01:03:01 +010036import from RSL_Types all;
Harald Welte624f9632017-12-16 19:26:04 +010037import from RSL_Emulation all;
Daniel Willmann191e0d92018-01-17 12:44:35 +010038import from MGCP_Emulation all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010039import from MGCP_Templates all;
40import from MGCP_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010041
Harald Welte96c94412017-12-09 03:12:45 +010042import from Osmocom_CTRL_Functions all;
Harald Weltea5d2ab22017-12-09 14:21:42 +010043import from Osmocom_CTRL_Types all;
Harald Welteffe55fc2018-01-17 22:39:54 +010044import from Osmocom_CTRL_Adapter all;
Harald Welte96c94412017-12-09 03:12:45 +010045
Harald Weltebc03c762018-02-12 18:09:38 +010046import from Osmocom_VTY_Functions all;
47import from TELNETasp_PortType all;
48
Harald Welte6f521d82017-12-11 19:52:02 +010049import from MobileL3_CommonIE_Types all;
Harald Weltee3bd6582018-01-31 22:51:25 +010050import from MobileL3_Types all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010051import from MobileL3_RRM_Types all;
Harald Welte6f521d82017-12-11 19:52:02 +010052import from L3_Templates all;
53import from GSM_RR_Types all;
54
Stefan Sperlingc307e682018-06-14 15:15:46 +020055import from SCCP_Templates all;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010056import from BSSMAP_Templates all;
57
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010058import from SCCPasp_Types all;
59
Harald Welte5d1a2202017-12-13 19:51:29 +010060const integer NUM_BTS := 3;
Harald Welteae026692017-12-09 01:03:01 +010061const float T3101_MAX := 12.0;
Harald Welte28d943e2017-11-25 15:00:50 +010062
Harald Welte799c97b2017-12-14 17:50:30 +010063/* make sure to sync this with the osmo-bts.cfg you're using */
Philipp Maiercb6cc482018-03-26 13:08:00 +020064const integer NUM_TCHH_PER_BTS := 2;
65const integer NUM_TCHF_PER_BTS := 4;
Harald Weltedd8cbf32018-01-28 12:07:52 +010066const integer NUM_SDCCH_PER_BTS := 4;
Harald Welte799c97b2017-12-14 17:50:30 +010067
Harald Welte4003d112017-12-09 22:35:39 +010068
Harald Welte21b46bd2017-12-17 19:46:32 +010069/* per-BTS state which we keep */
Harald Welte96c94412017-12-09 03:12:45 +010070type record BTS_State {
Harald Welte21b46bd2017-12-17 19:46:32 +010071 /* component reference to the IPA_Client component used for RSL */
Harald Weltea5d2ab22017-12-09 14:21:42 +010072 IPA_Client rsl
Harald Welte96c94412017-12-09 03:12:45 +010073}
74
Harald Weltea4ca4462018-02-09 00:17:14 +010075type component test_CT extends CTRL_Adapter_CT {
Harald Welte21b46bd2017-12-17 19:46:32 +010076 /* Array of per-BTS state */
Harald Welte96c94412017-12-09 03:12:45 +010077 var BTS_State bts[NUM_BTS];
Harald Welte89ab1912018-02-23 18:56:29 +010078 /* RSL common Channel Port (for RSL_Emulation) */
79 port RSL_CCHAN_PT RSL_CCHAN[NUM_BTS];
Harald Welte21b46bd2017-12-17 19:46:32 +010080 /* array of per-BTS RSL test ports */
Harald Welteae026692017-12-09 01:03:01 +010081 port IPA_RSL_PT IPA_RSL[NUM_BTS];
Stefan Sperling830dc9d2018-02-12 21:08:28 +010082 port IPA_CODEC_PT IPA; /* Required for compilation of TC_rsl_unknown_unit_id() */
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +020083 /* CTRL muxed over IPA in SCCPlite conn BSC<->MSC (or BSC-NAT) */
84 port IPA_CTRL_PT SCCPLITE_IPA_CTRL;
Harald Weltea5d2ab22017-12-09 14:21:42 +010085
Daniel Willmann191e0d92018-01-17 12:44:35 +010086 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +010087 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +010088
Harald Welte6811d102019-04-14 22:23:14 +020089 var RAN_Adapter g_bssap;
Harald Weltea4ca4462018-02-09 00:17:14 +010090 /* for old legacy-tests only */
91 port BSSAP_CODEC_PT BSSAP;
92
Harald Welte21b46bd2017-12-17 19:46:32 +010093 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +010094 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +010095
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +020096 /* Osmux is enabled through VTY */
97 var boolean g_osmux_enabled := false;
98
Harald Welte21b46bd2017-12-17 19:46:32 +010099 /* global test case guard timer */
Harald Welteae026692017-12-09 01:03:01 +0100100 timer T_guard := 30.0;
101
Harald Welte28d943e2017-11-25 15:00:50 +0100102}
103
104modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +0100105 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +0100106 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100107 /* port number to which to establish the IPA OML connections */
108 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +0100109 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +0100110 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +0100111 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +0100112 integer mp_bsc_ctrl_port := 4249;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100113 /* IP address at which the test binds */
114 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100115
Harald Welte6811d102019-04-14 22:23:14 +0200116 RAN_Configuration mp_bssap_cfg := {
Harald Welte7ef51aa2018-04-16 19:16:01 +0200117 transport := BSSAP_TRANSPORT_AoIP,
Harald Weltea4ca4462018-02-09 00:17:14 +0100118 sccp_service_type := "mtp3_itu",
119 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
120 own_pc := 185,
121 own_ssn := 254,
122 peer_pc := 187,
123 peer_ssn := 254,
Philipp Maier38d68942018-03-29 15:38:09 +0200124 sio := '83'O,
125 rctx := 0
Harald Weltea4ca4462018-02-09 00:17:14 +0100126 };
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +0200127
128 /* Whether to enable osmux tests. Can be dropped completely and enable
129 unconditionally once new version of osmo-bsc is released (current
130 version: 1.4.1) */
131 boolean mp_enable_osmux_test := true;
Harald Weltea4ca4462018-02-09 00:17:14 +0100132}
133
Philipp Maier48604732018-10-09 15:00:37 +0200134private function f_gen_test_hdlr_pars() return TestHdlrParams {
135
136 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
137 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
138 pars.aoip := true;
139 } else {
140 pars.aoip := false;
141 }
142
143 return pars;
144}
145
Philipp Maier282ca4b2018-02-27 17:17:00 +0100146private function f_shutdown_helper() runs on test_CT {
Daniel Willmann637ef6c2018-07-25 10:49:09 +0200147 all component.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100148 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200149 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100150}
151
Harald Weltea4ca4462018-02-09 00:17:14 +0100152private function f_legacy_bssap_reset() runs on test_CT {
153 var BSSAP_N_UNITDATA_ind ud_ind;
154 timer T := 5.0;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200155 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, ts_BSSMAP_Reset(0, g_osmux_enabled)));
Harald Weltea4ca4462018-02-09 00:17:14 +0100156 T.start;
157 alt {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200158 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap.sccp_addr_own, g_bssap.sccp_addr_peer, tr_BSSMAP_ResetAck(g_osmux_enabled))) {
Harald Weltea4ca4462018-02-09 00:17:14 +0100159 log("Received RESET-ACK in response to RESET, we're ready to go!");
160 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200161 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Weltea4ca4462018-02-09 00:17:14 +0100162 log("Respoding to inbound RESET with RESET-ACK");
163 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200164 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Weltea4ca4462018-02-09 00:17:14 +0100165 repeat;
166 }
167 [] BSSAP.receive { repeat; }
168 [] T.timeout { setverdict(fail, "Waiting for RESET-ACK after sending RESET"); }
169 }
Harald Welte28d943e2017-11-25 15:00:50 +0100170}
171
Harald Welteae026692017-12-09 01:03:01 +0100172type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100173 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100174 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100175 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100176 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100177 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100178 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100179 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100180 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100181}
182
Harald Welte21b46bd2017-12-17 19:46:32 +0100183/*! Start the IPA/RSL related bits for one IPA_Client.
184 * \param clnt IPA_Client for which to establish
185 * \param bsc_host IP address / hostname of the BSC
186 * \param bsc_port TCP port number of the BSC
187 * \param i number identifying this BTS
188 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100189function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
190 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100191runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100192 timer T := 10.0;
193
Harald Welte96c94412017-12-09 03:12:45 +0100194 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welteae026692017-12-09 01:03:01 +0100195 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA");
196 clnt.ccm_pars := c_IPA_default_ccm_pars;
197 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
198 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100199 if (handler_mode) {
200 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL");
Harald Welte89ab1912018-02-23 18:56:29 +0100201 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100202 }
Harald Welteae026692017-12-09 01:03:01 +0100203
204 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Harald Welte624f9632017-12-16 19:26:04 +0100205 if (handler_mode) {
206 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
207 } else {
208 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
209 }
Harald Welteae026692017-12-09 01:03:01 +0100210
Harald Welte5d1a2202017-12-13 19:51:29 +0100211 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100212 if (handler_mode) {
213 clnt.vc_RSL.start(RSL_Emulation.main());
214 return;
215 }
Harald Welteae026692017-12-09 01:03:01 +0100216
217 /* wait for IPA RSL link to connect and send ID ACK */
218 T.start;
219 alt {
220 [] IPA_RSL[i].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_ID_ACK}) {
221 T.stop;
222 IPA_RSL[i].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_PAGING_LOAD_IND(23)));
223 }
Harald Welte60e823a2017-12-10 14:10:59 +0100224 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100225 [] IPA_RSL[i].receive { repeat }
226 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100227 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200228 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100229 }
230 }
231}
232
Harald Welte12055472018-03-17 20:10:08 +0100233function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
234 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
235 return;
236 }
237 clnt.vc_IPA.stop;
238 if (isbound(clnt.vc_RSL)) {
239 clnt.vc_RSL.stop;
240 }
241}
242
Harald Welte21b46bd2017-12-17 19:46:32 +0100243/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100244function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
245 timer T := secs_max;
246 T.start;
247 while (true) {
248 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
249 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100250 /* the 'degraded' state exists from OML connection time, and we have to wait
251 * until all MO's are initialized */
252 T.start(1.0);
253 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100254 return;
255 }
Harald Weltef0d6ac62017-12-17 17:02:21 +0100256 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100257 if (not T.running) {
Max99253902018-11-16 17:57:39 +0100258 setverdict(fail, "Timeout waiting for BTS" & int2str(bts_nr) & " oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +0200259 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100260 }
261 }
262}
263
Harald Welte21b46bd2017-12-17 19:46:32 +0100264/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +0100265altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +0100266 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100267 [] T_guard.timeout {
268 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +0200269 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100270 }
Harald Welte60e823a2017-12-10 14:10:59 +0100271 /* always respond with RESET ACK to RESET */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200272 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Welte60e823a2017-12-10 14:10:59 +0100273 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200274 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Welte69c1c262017-12-13 21:02:08 +0100275 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +0100276 }
Harald Welte28d943e2017-11-25 15:00:50 +0100277}
278
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100279altstep no_bssmap_reset() runs on test_CT {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200280 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100281 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +0200282 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100283 }
284}
285
Daniel Willmann191e0d92018-01-17 12:44:35 +0100286function f_init_mgcp(charstring id) runs on test_CT {
287 id := id & "-MGCP";
288
289 var MGCPOps ops := {
290 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
291 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
292 };
293 var MGCP_conn_parameters mgcp_pars := {
294 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +0100295 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +0100296 mgw_ip := mp_test_ip,
Pau Espin Pedrol1a026a52019-06-18 17:21:52 +0200297 mgw_udp_port := 2427,
298 multi_conn_mode := false
Daniel Willmann191e0d92018-01-17 12:44:35 +0100299 };
300
301 vc_MGCP := MGCP_Emulation_CT.create(id);
302 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
303}
304
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200305/* Enable or disable (current default) Osmux. When enabling, BSSMAP Reset
306 * contains extra IE (OsmuxSupport) and osmo-bsc will handle AssignReq with
307 * OsmuxCID IE.
308 */
309private function f_vty_allow_osmux(boolean allow) runs on test_CT {
310 f_vty_enter_cfg_msc(BSCVTY, 0);
311 if (allow) {
312 f_vty_transceive(BSCVTY, "osmux on");
313 } else {
314 f_vty_transceive(BSCVTY, "osmux off");
315 }
316 f_vty_transceive(BSCVTY, "exit");
317 f_vty_transceive(BSCVTY, "exit");
318 g_osmux_enabled := allow;
319}
320
Max2253c0b2018-11-06 19:28:05 +0100321function f_init_vty(charstring id := "foo") runs on test_CT {
Harald Welte94e0c342018-04-07 11:33:23 +0200322 if (BSCVTY.checkstate("Mapped")) {
323 /* skip initialization if already executed once */
324 return;
325 }
Harald Weltebc03c762018-02-12 18:09:38 +0100326 map(self:BSCVTY, system:BSCVTY);
327 f_vty_set_prompts(BSCVTY);
328 f_vty_transceive(BSCVTY, "enable");
329}
330
Harald Welte21b46bd2017-12-17 19:46:32 +0100331/* global initialization function
332 * \param nr_bts Number of BTSs we should start/bring up
333 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200334function 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 +0100335 var integer i;
Harald Welte28d943e2017-11-25 15:00:50 +0100336
Harald Welteae026692017-12-09 01:03:01 +0100337 if (g_initialized) {
338 return;
Harald Welte28d943e2017-11-25 15:00:50 +0100339 }
Harald Welteae026692017-12-09 01:03:01 +0100340 g_initialized := true;
341
Daniel Willmanne68f9272018-11-27 15:15:28 +0100342 T_guard.start;
343 activate(as_Tguard());
344
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200345 f_init_vty("VirtMSC");
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +0200346 if (mp_enable_osmux_test) {
347 f_vty_allow_osmux(allow_osmux);
348 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200349
Harald Welte6811d102019-04-14 22:23:14 +0200350 /* Call a function of our 'parent component' RAN_Adapter_CT to start the
Harald Welteae026692017-12-09 01:03:01 +0100351 * MSC-side BSSAP emulation */
Harald Welte67089ee2018-01-17 22:19:03 +0100352 if (handler_mode) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200353 var RanOps ranops := MSC_RanOps;
354 ranops.use_osmux := g_osmux_enabled;
355 f_ran_adapter_init(g_bssap, mp_bssap_cfg, "VirtMSC", ranops);
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +0200356 connect(self:SCCPLITE_IPA_CTRL, g_bssap.vc_RAN:CTRL_CLIENT);
Harald Welte3ca0ce12019-04-23 17:18:48 +0200357 f_ran_adapter_start(g_bssap);
Harald Welte67089ee2018-01-17 22:19:03 +0100358 } else {
Harald Welte3ca0ce12019-04-23 17:18:48 +0200359 f_ran_adapter_init(g_bssap, mp_bssap_cfg, "VirtMSC", omit);
Harald Weltea4ca4462018-02-09 00:17:14 +0100360 connect(self:BSSAP, g_bssap.vc_SCCP:SCCP_SP_PORT);
Harald Welte3ca0ce12019-04-23 17:18:48 +0200361 f_ran_adapter_start(g_bssap);
Harald Weltea4ca4462018-02-09 00:17:14 +0100362 f_legacy_bssap_reset();
Harald Welte67089ee2018-01-17 22:19:03 +0100363 }
Harald Welted5833a82018-05-27 16:52:56 +0200364
Harald Welteffe55fc2018-01-17 22:39:54 +0100365 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +0100366
Daniel Willmann191e0d92018-01-17 12:44:35 +0100367 f_init_mgcp("VirtMSC");
368
Harald Welte89d42e82017-12-17 16:42:41 +0100369 for (i := 0; i < nr_bts; i := i+1) {
Harald Weltea5d2ab22017-12-09 14:21:42 +0100370 /* wait until osmo-bts-omldummy has respawned */
371 f_wait_oml(i, "degraded", 5.0);
372 /* start RSL connection */
Harald Welte624f9632017-12-16 19:26:04 +0100373 f_ipa_rsl_start(bts[i].rsl, mp_bsc_ip, mp_bsc_rsl_port, i, handler_mode);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100374 /* wait until BSC tells us "connected" */
375 f_wait_oml(i, "connected", 5.0);
Harald Welte696ddb62017-12-08 14:01:43 +0100376 }
377
Harald Welte28d943e2017-11-25 15:00:50 +0100378}
379
Maxd4e56962018-10-31 19:08:25 +0100380/* expect to receive a RSL message matching a specified template on a given BTS / stream */
Harald Welteae026692017-12-09 01:03:01 +0100381function f_exp_ipa_rx(integer bts_nr, template RSL_Message t_rx, float t_secs := 2.0, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
382runs on test_CT return RSL_Message {
383 var ASP_RSL_Unitdata rx_rsl_ud;
384 timer T := t_secs;
385
386 T.start;
387 alt {
388 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(sid, t_rx)) -> value rx_rsl_ud {
389 T.stop;
390 }
391 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +0100392 [] T.timeout {
393 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +0200394 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +0100395 }
Harald Welteae026692017-12-09 01:03:01 +0100396 }
397 return rx_rsl_ud.rsl;
398}
399
Harald Welte21b46bd2017-12-17 19:46:32 +0100400/* helper function to transmit RSL on a given BTS/stream */
Harald Welteae026692017-12-09 01:03:01 +0100401function f_ipa_tx(integer bts_nr, template RSL_Message t_tx, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
402runs on test_CT {
403 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(sid, t_tx));
404}
405
406
Harald Welte4003d112017-12-09 22:35:39 +0100407/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +0100408testcase TC_chan_act_noreply() runs on test_CT {
409 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +0100410 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +0100411
Harald Welte89d42e82017-12-17 16:42:41 +0100412 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +0100413
Harald Welteae026692017-12-09 01:03:01 +0100414 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 +0100415 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welteae026692017-12-09 01:03:01 +0100416 setverdict(pass);
Harald Welte28d943e2017-11-25 15:00:50 +0100417}
418
Harald Welte4003d112017-12-09 22:35:39 +0100419/* verify if the "chreq:total" counter increments as expected */
420testcase TC_chan_act_counter() runs on test_CT {
421 var BSSAP_N_UNITDATA_ind ud_ind;
422 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +0100423 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +0100424
Harald Welte89d42e82017-12-17 16:42:41 +0100425 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100426
427 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
428 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 +0100429 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welte4003d112017-12-09 22:35:39 +0100430 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total", chreq_total+1);
431
432 setverdict(pass);
433}
434
Harald Welteae026692017-12-09 01:03:01 +0100435/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
436testcase TC_chan_act_ack_noest() runs on test_CT {
437 var RSL_Message rx_rsl;
438
Harald Welte89d42e82017-12-17 16:42:41 +0100439 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100440
441 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100442 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100443
444 /* expect BSC to disable the channel again if there's no RLL EST IND */
445 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
446
447 setverdict(pass);
448}
449
450/* Test behavior if MSC never answers to CR */
451testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +0100452 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
453 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +0100454 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +0100455 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +0100456
Harald Welte89d42e82017-12-17 16:42:41 +0100457 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100458
459 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100460 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100461
462 var octetstring l3 := '00010203040506'O
463 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
464
465 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
466
467 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +0100468 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100469 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Harald Welteae026692017-12-09 01:03:01 +0100470 setverdict(pass);
471}
472
473/* Test behavior if MSC answers with CREF to CR */
474testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
475 var BSSAP_N_CONNECT_ind rx_c_ind;
476 var RSL_Message rx_rsl;
477
Harald Welte89d42e82017-12-17 16:42:41 +0100478 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100479
480 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100481 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100482
483 var octetstring l3 := '00010203040506'O
484 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
485
486 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
487 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
488
489 /* expect BSC to disable the channel */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100490 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Harald Welteae026692017-12-09 01:03:01 +0100491 setverdict(pass);
492}
493
Harald Welte618ef642017-12-14 14:58:20 +0100494/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
495testcase TC_chan_act_nack() runs on test_CT {
496 var RSL_Message rx_rsl;
497 var integer chact_nack;
498
Harald Welte89d42e82017-12-17 16:42:41 +0100499 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +0100500
501 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
502
503 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
504 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
505 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
506
507 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
508
509 /* wait for some time to hope the NACK arrives before the CTRL GET below */
510 f_sleep(0.5);
511
512 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
513
514 setverdict(pass);
515}
516
Harald Welte799c97b2017-12-14 17:50:30 +0100517/* Test for channel exhaustion due to RACH overload */
518testcase TC_chan_exhaustion() runs on test_CT {
519 var ASP_RSL_Unitdata rsl_ud;
520 var integer i;
521 var integer chreq_total, chreq_nochan;
522
Harald Welte89d42e82017-12-17 16:42:41 +0100523 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +0100524
525 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
526 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
527
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +0100528 /* GSM 04.08 Table 9.9a:
529 * RA = '33'O -> Establishment cause = 0011xxxx (MS dual rate capable and asks for "TCH/H or TCH/F").
530 * With current setup, expect 4xSDCCH + 4xTCH/F + 1xTCH/H to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +0200531 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 +0100532 var RslChannelNr chan_nr := f_chreq_act_ack('33'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +0100533 }
534
535 IPA_RSL[0].clear;
536
Harald Weltedd8cbf32018-01-28 12:07:52 +0100537 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200538 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +0100539
540 /* now expect additional channel activations to fail */
541 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
542
543 alt {
544 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
545 tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
546 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
547 }
548 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
549 var GsmRrMessage rr;
550 /* match on IMM ASS REJ */
551 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
552 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
553 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200554 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +0100555 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
556 chreq_nochan+1);
557 setverdict(pass);
558 } else {
559 repeat;
560 }
561 }
562 [] IPA_RSL[0].receive { repeat; }
563 }
564}
565
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +0700566/* Test channel deactivation due to silence from MS */
567testcase TC_chan_deact_silence() runs on test_CT {
568 var RslChannelNr chan_nr;
569
570 f_init(1);
571
572 /* Request for a dedicated channel */
573 chan_nr := f_chreq_act_ack('23'O);
574
575 /* Wait some time until the channel is released */
576 f_sleep(2.0);
577
578 /* Expect CHANnel RELease */
579 alt {
580 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
581 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
582 log("Received CHANnel RELease");
583 setverdict(pass);
584 }
585 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
586 tr_RSL_IMM_ASSIGN(?))) {
587 /* See OS#3709, OsmoBSC should not send Immediate
588 * Assignment Reject since a dedicated channel was
589 * already allocated, and Immediate Assignment was
590 * already sent. */
591 setverdict(fail, "Unexpected Immediate Assignment!");
592 }
593 [] IPA_RSL[0].receive {
594 setverdict(fail, "Unexpected RSL message!");
595 }
596 }
597}
598
Harald Weltecfe2c962017-12-15 12:09:32 +0100599/***********************************************************************
600 * Assignment Testing
601 ***********************************************************************/
602
Neels Hofmeyrda4a6952018-06-14 04:02:49 +0200603/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction,
604 * except for the inter-BSC handover, MT side) */
Harald Weltecfe2c962017-12-15 12:09:32 +0100605testcase TC_outbound_connect() runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +0100606 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +0100607
Harald Weltea4ca4462018-02-09 00:17:14 +0100608 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 +0100609 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
610 setverdict(pass);
611}
612
Harald Welte16a4adf2017-12-14 18:54:01 +0100613/* Test behavior if MSC answers with CREF to CR */
614testcase TC_assignment_cic_only() runs on test_CT {
615 var BSSAP_N_CONNECT_ind rx_c_ind;
616 var RSL_Message rx_rsl;
617 var DchanTuple dt;
618
Harald Welte89d42e82017-12-17 16:42:41 +0100619 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +0100620
621 dt := f_est_dchan('23'O, 23, '00000000'O);
Harald Welte17b27da2018-05-25 20:33:53 +0200622 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
623 /* send assignment without AoIP IEs */
624 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
625 } else {
626 /* Send assignmetn without CIC in IPA case */
627 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
628 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
629 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
630 }
Harald Welte16a4adf2017-12-14 18:54:01 +0100631 alt {
632 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
633 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
634 }
Harald Welte235ebf12017-12-15 14:18:16 +0100635 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +0100636 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
637 setverdict(pass);
638 }
639 [] BSSAP.receive { repeat; }
640 }
641}
642
Harald Welteed848512018-05-24 22:27:58 +0200643/* generate an assignment request for either AoIP or SCCPlite */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200644function f_gen_ass_req(boolean osmux_enabled := false) return PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200645 var PDU_BSSAP ass_cmd;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200646 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Harald Welteed848512018-05-24 22:27:58 +0200647 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
648 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
649 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200650 if (osmux_enabled) {
651 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla, osmux_cid));
652 } else {
653 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
654 }
Harald Welteed848512018-05-24 22:27:58 +0200655 } else {
656 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +0200657 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
Harald Welteed848512018-05-24 22:27:58 +0200658 }
659 return ass_cmd;
660}
661
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +0100662function f_gen_handover_req() return PDU_BSSAP {
663 var PDU_BSSAP ho_req;
664 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
665 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
666 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
667 ho_req := valueof(ts_BSSMAP_HandoverRequest(omit, tla));
668 } else {
669 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
670 ho_req := valueof(ts_BSSMAP_HandoverRequest(cic, omit));
671 }
672 return ho_req;
673}
674
Harald Welteed848512018-05-24 22:27:58 +0200675/* generate an assignment complete template for either AoIP or SCCPlite */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200676function f_gen_exp_compl(boolean expect_osmux := false) return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200677 var template PDU_BSSAP exp_compl;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200678 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Harald Welteed848512018-05-24 22:27:58 +0200679 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200680 if (expect_osmux) {
681 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, osmux_cid);
682 } else {
683 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, omit);
684 }
Harald Welteed848512018-05-24 22:27:58 +0200685 } else {
686 /* CIC is optional "*" as the MSC allocated it */
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +0200687 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
Harald Welteed848512018-05-24 22:27:58 +0200688 }
689 return exp_compl;
690}
691
Harald Welte235ebf12017-12-15 14:18:16 +0100692/* Run everything required up to sending a caller-specified assignment command and expect response */
693function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
694runs on test_CT {
695 var BSSAP_N_CONNECT_ind rx_c_ind;
696 var RSL_Message rx_rsl;
697 var DchanTuple dt;
698
Harald Welte89d42e82017-12-17 16:42:41 +0100699 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +0100700
701 dt := f_est_dchan('23'O, 23, '00000000'O);
702 /* send assignment without AoIP IEs */
703 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
704 alt {
705 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
706 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
707 setverdict(pass);
708 } else {
709 setverdict(fail, fail_text);
710 }
711 }
712 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
713 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
714 setverdict(pass);
715 } else {
716 setverdict(fail, fail_text);
717 }
718 }
719 [] BSSAP.receive { repeat; }
720 }
721}
722testcase TC_assignment_csd() runs on test_CT {
723 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200724 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100725 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
726 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
727 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
728}
729
730testcase TC_assignment_ctm() runs on test_CT {
731 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200732 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100733 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
734 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
735 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
736}
737
Harald Welte4003d112017-12-09 22:35:39 +0100738type record DchanTuple {
739 integer sccp_conn_id,
740 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +0100741}
742
Harald Welted6939652017-12-13 21:02:46 +0100743/* Send CHAN RQD and wait for allocation; acknowledge it */
744private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
745runs on test_CT return RslChannelNr {
746 var RSL_Message rx_rsl;
747 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
748 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
749 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
750 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
Daniel Willmannf4ac4ce2018-08-02 14:06:30 +0200751 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Harald Welted6939652017-12-13 21:02:46 +0100752 return chan_nr;
753}
754
Harald Welte4003d112017-12-09 22:35:39 +0100755/* helper function to establish a dedicated channel via BTS and MSC */
756function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
757runs on test_CT return DchanTuple {
758 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +0100759 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100760
Harald Welte4003d112017-12-09 22:35:39 +0100761 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100762 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +0100763
764 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
765
766 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
767 dt.sccp_conn_id := rx_c_ind.connectionId;
768 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
769
770 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100771}
772
Harald Welte641fcbe2018-06-14 10:58:35 +0200773/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
774private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
775 var RSL_Message rx_rsl;
776 /* expect BSC to disable the channel */
777 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
778 /* respond with CHAN REL ACK */
779 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
780
781 /* expect Clear Complete from BSC */
782 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
783
784 /* MSC disconnects as instructed. */
785 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
786}
787
Harald Welte4003d112017-12-09 22:35:39 +0100788/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
789testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100790 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100791 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +0100792
Harald Welte89d42e82017-12-17 16:42:41 +0100793 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +0100794
Harald Welte4003d112017-12-09 22:35:39 +0100795 dt := f_est_dchan('23'O, 23, '00010203040506'O);
796
797 /* simulate RLL REL IND */
798 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
799
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100800 /* expect Clear Request on MSC side */
801 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
802
803 /* Instruct BSC to clear channel */
804 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
805 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
806
Harald Welte4003d112017-12-09 22:35:39 +0100807 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200808 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100809
810 /* wait for SCCP emulation to do its job */
811 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +0100812
813 setverdict(pass);
814}
815
816/* Test behavior of channel release after CONN FAIL IND from BTS */
817testcase TC_chan_rel_conn_fail() runs on test_CT {
818 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100819 var DchanTuple dt;
820
Harald Welte89d42e82017-12-17 16:42:41 +0100821 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100822
823 dt := f_est_dchan('23'O, 23, '00010203040506'O);
824
825 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +0100826 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 +0100827 /* TODO: different cause values? */
828
Harald Welte4003d112017-12-09 22:35:39 +0100829 /* expect Clear Request from BSC */
830 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
831
832 /* Instruct BSC to clear channel */
833 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
834 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
835
Harald Welte6ff76ea2018-01-28 13:08:01 +0100836 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200837 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +0100838
839 /* wait for SCCP emulation to do its job */
840 f_sleep(1.0);
841
842 setverdict(pass);
843}
844
Harald Welte99f3ca02018-06-14 13:40:29 +0200845/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
846/* See also https://www.osmocom.org/issues/3182 */
847testcase TC_early_conn_fail() runs on test_CT {
848 var RSL_Message rx_rsl;
849 var DchanTuple dt;
850
851 f_init(1);
852
853 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
854 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_octstring(1), 23);
855
856 /* BTS->BSC: simulate CONN FAIL IND */
857 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
858
859 /* BTS->BSC: Expect RF channel release from BSC on Abis */
860 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
861
862 /* BTS<-BSC: respond with CHAN REL ACK */
863 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
864
865 setverdict(pass);
866}
867
868/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
869/* See also https://www.osmocom.org/issues/3182 */
870testcase TC_late_conn_fail() runs on test_CT {
871 var RSL_Message rx_rsl;
872 var DchanTuple dt;
873
874 f_init(1);
875
876 dt := f_est_dchan('23'O, 23, '00010203040506'O);
877
878 /* BSC<-MSC: Instruct BSC to clear connection */
879 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
880
881 /* BTS->BSC: expect BSC to deactivate SACCH */
882 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
883
884 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
885 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
886
887 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
888 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
889 /* BTS->BSC: respond with CHAN REL ACK */
890 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
891
892 /* BSC->MSC: expect Clear Complete from BSC */
893 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
894
895 /* BSC<-MSC: MSC disconnects as requested. */
896 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
897
898 setverdict(pass);
899}
900
Neels Hofmeyrf44ccd12018-11-05 19:15:23 +0100901function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr,
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100902 boolean expect_deact_sacch := true,
903 boolean expect_rr_chan_rel := true,
904 boolean expect_rll_rel_req := true,
Harald Welte99787102019-02-04 10:41:36 +0100905 boolean handle_rll_rel := true,
906 boolean is_csfb := false
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100907 ) runs on test_CT {
Harald Welte91d54a52018-01-28 15:35:07 +0100908
909 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100910 var boolean got_deact_sacch := false;
911 var boolean got_rr_chan_rel := false;
912 var boolean got_rll_rel_req := false;
913 log("f_expect_chan_rel() expecting: expect_deact_sacch=", expect_deact_sacch, " expect_rr_chan_rel=", expect_rr_chan_rel,
914 " expect_rll_rel_req=", expect_rll_rel_req);
Harald Welte91d54a52018-01-28 15:35:07 +0100915 alt {
Harald Welte91d54a52018-01-28 15:35:07 +0100916 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
917 tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100918 got_deact_sacch := true;
Harald Welte91d54a52018-01-28 15:35:07 +0100919 repeat;
920 }
Harald Welte99787102019-02-04 10:41:36 +0100921 [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))) {
922 got_rr_chan_rel := true;
923 repeat;
924 }
925 [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 +0100926 got_rr_chan_rel := true;
Neels Hofmeyr211169d2018-11-07 00:37:29 +0100927 repeat;
928 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100929 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
Harald Welte91d54a52018-01-28 15:35:07 +0100930 tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100931 got_rll_rel_req := true;
Harald Welte91d54a52018-01-28 15:35:07 +0100932 /* FIXME: Why are we getting this for LinkID SACCH? */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100933 if (handle_rll_rel) {
934 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
935 }
Harald Welte91d54a52018-01-28 15:35:07 +0100936 repeat;
937 }
Harald Welte91d54a52018-01-28 15:35:07 +0100938 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
939 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
940 /* respond with CHAN REL ACK */
941 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
942 }
943 /* ignore any user data */
944 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_MsgTypeR(?))) {
945 repeat;
946 }
947 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100948
949 log("f_expect_chan_rel() summary: got_deact_sacch=", got_deact_sacch, " got_rr_chan_rel=", got_rr_chan_rel,
950 " got_rll_rel_req=", got_rll_rel_req);
951
952 if (expect_deact_sacch != got_deact_sacch) {
953 setverdict(fail, "f_expect_chan_rel(): expect_deact_sacch=", expect_deact_sacch, " got_deact_sacch=", got_deact_sacch);
954 }
955 if (expect_rr_chan_rel != got_rr_chan_rel) {
956 setverdict(fail, "f_expect_chan_rel(): expect_rr_chan_rel=", expect_rr_chan_rel, " got_rr_chan_rel=", got_rr_chan_rel);
957 }
958 if (expect_rll_rel_req != got_rll_rel_req) {
959 setverdict(fail, "f_expect_chan_rel(): expect_rll_rel_req=", expect_rll_rel_req, " got_rll_rel_req=", got_rll_rel_req);
960 }
Harald Welte91d54a52018-01-28 15:35:07 +0100961}
962
Harald Welte4003d112017-12-09 22:35:39 +0100963/* Test behavior of channel release after hard Clear Command from MSC */
964testcase TC_chan_rel_hard_clear() runs on test_CT {
965 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100966 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +0100967
Harald Welte89d42e82017-12-17 16:42:41 +0100968 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100969
970 dt := f_est_dchan('23'O, 23, '00010203040506'O);
971
972 /* Instruct BSC to clear channel */
973 var BssmapCause cause := 0;
974 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
975
976 /* expect Clear Complete from BSC on A */
977 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
978 /* release the SCCP connection */
979 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
980 }
981
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100982 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte4003d112017-12-09 22:35:39 +0100983 setverdict(pass);
984}
985
Harald Welte99787102019-02-04 10:41:36 +0100986/* Test behavior of channel release after Clear Command with CSFB indicator from MSC */
987testcase TC_chan_rel_hard_clear_csfb() runs on test_CT {
988 var BSSAP_N_DATA_ind rx_di;
989 var DchanTuple dt;
990
991 f_init(1);
992
993 dt := f_est_dchan('23'O, 23, '00010203040506'O);
994
995 /* Instruct BSC to clear channel */
996 var BssmapCause cause := 0;
997 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
998
999 /* expect Clear Complete from BSC on A */
1000 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
1001 /* release the SCCP connection */
1002 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1003 }
1004
1005 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, is_csfb := true);
1006 setverdict(pass);
1007}
1008
Harald Welted8c36cd2017-12-09 23:05:31 +01001009/* Test behavior of channel release after hard RLSD from MSC */
1010testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +01001011 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +01001012
Harald Welte89d42e82017-12-17 16:42:41 +01001013 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +01001014
1015 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1016
1017 /* release the SCCP connection */
1018 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1019
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001020 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welted8c36cd2017-12-09 23:05:31 +01001021 setverdict(pass);
1022}
1023
Harald Welte550daf92018-06-11 19:22:13 +02001024/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
1025testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
1026 var DchanTuple dt;
1027
1028 f_init(1);
1029
1030 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1031
1032 /* release the SCCP connection */
1033 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1034
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001035 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte550daf92018-06-11 19:22:13 +02001036 setverdict(pass);
1037}
1038
Harald Welte85804d42017-12-10 14:11:58 +01001039/* Test behavior of channel release after BSSMAP RESET from MSC */
1040testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +01001041 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +01001042
Harald Welte89d42e82017-12-17 16:42:41 +01001043 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +01001044
1045 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1046
1047 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
1048 IPA_RSL[0].clear;
1049
1050 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001051 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 +01001052 interleave {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001053 [] 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 +01001054 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
1055 }
1056
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001057 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte85804d42017-12-10 14:11:58 +01001058 setverdict(pass);
1059}
1060
Harald Welte5cd20ed2017-12-13 21:03:20 +01001061/* Test behavior if RSL EST IND for non-active channel */
1062testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
1063 timer T := 2.0;
1064
Harald Welte89d42e82017-12-17 16:42:41 +01001065 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001066
1067 var octetstring l3 := '00010203040506'O;
1068 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
1069 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1070
1071 T.start;
1072 alt {
1073 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1074 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
1075 }
1076 [] BSSAP.receive {}
1077 [] IPA_RSL[0].receive {}
1078 [] T.timeout {}
1079 }
1080
1081 setverdict(pass);
1082}
1083
1084/* Test behavior if RSL EST IND for invalid SAPI */
1085testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
1086 var RslChannelNr chan_nr;
1087
Harald Welte89d42e82017-12-17 16:42:41 +01001088 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001089
1090 chan_nr := f_chreq_act_ack()
1091
1092 var octetstring l3 := '00010203040506'O;
1093 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
1094
1095 timer T := 2.0;
1096 T.start;
1097 alt {
1098 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1099 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
1100 }
1101 [] BSSAP.receive { repeat; }
1102 [] IPA_RSL[0].receive { repeat; }
1103 [] T.timeout {}
1104 }
1105
1106 setverdict(pass);
1107}
1108
1109/* Test behavior if RSL EST IND for invalid SAPI */
1110testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
1111 timer T := 2.0;
1112
Harald Welte89d42e82017-12-17 16:42:41 +01001113 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001114
1115 var RslChannelNr chan_nr := f_chreq_act_ack();
1116
1117 var octetstring l3 := '00010203040506'O;
1118 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
1119
1120 T.start;
1121 alt {
1122 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1123 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
1124 }
1125 [] BSSAP.receive { repeat; }
1126 [] IPA_RSL[0].receive { repeat; }
1127 [] T.timeout {}
1128 }
1129
1130 setverdict(pass);
1131}
1132
1133/* Test behavior if RSL EST IND for invalid SACCH */
1134testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
1135 timer T := 2.0;
1136
Harald Welte89d42e82017-12-17 16:42:41 +01001137 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001138
1139 var RslChannelNr chan_nr := f_chreq_act_ack();
1140
1141 var octetstring l3 := '00010203040506'O;
1142 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
1143
1144 T.start;
1145 alt {
1146 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1147 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
1148 }
1149 [] BSSAP.receive { repeat; }
1150 [] IPA_RSL[0].receive { repeat; }
1151 [] T.timeout {}
1152 }
1153
1154 setverdict(pass);
1155}
1156
1157
1158
Harald Welte4003d112017-12-09 22:35:39 +01001159
1160testcase TC_ctrl_msc_connection_status() runs on test_CT {
1161 var charstring ctrl_resp;
1162
Harald Welte89d42e82017-12-17 16:42:41 +01001163 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001164
1165 /* See https://osmocom.org/issues/2729 */
1166 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
1167 setverdict(pass);
1168}
1169
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001170testcase TC_ctrl_msc0_connection_status() runs on test_CT {
1171 var charstring ctrl_resp;
1172
1173 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001174
1175 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
1176 setverdict(pass);
1177}
1178
Harald Welte4003d112017-12-09 22:35:39 +01001179testcase TC_ctrl() runs on test_CT {
1180 var charstring ctrl_resp;
1181
Harald Welte89d42e82017-12-17 16:42:41 +01001182 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001183
1184 /* all below values must match the osmo-bsc.cfg config file used */
1185
Harald Welte6a129692018-03-17 17:30:14 +01001186 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
1187 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Harald Welte44bdaa52017-12-17 17:01:47 +01001188 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "3");
Harald Welte4003d112017-12-09 22:35:39 +01001189
1190 var integer bts_nr := 0;
1191 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
1192 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
1193 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
1194 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
1195 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
1196 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
1197 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
1198
1199 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
1200 f_sleep(2.0);
1201 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
1202 setverdict(fail, "oml-uptime not incrementing as expected");
1203 }
1204 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
1205
1206 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
1207
1208 setverdict(pass);
Harald Welte96c94412017-12-09 03:12:45 +01001209}
1210
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02001211/* Verify that Upon receival of SET "location", BSC forwards a TRAP
1212 "location-state" over the SCCPlite IPA conn */
1213testcase TC_ctrl_location() runs on test_CT {
1214 var MSC_ConnHdlr vc_conn;
1215 var integer bts_nr := 0;
1216
1217 f_init(1, true);
1218 f_sleep(1.0);
1219
1220 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234567,fix3d,0.340000,0.560000,0.780000");
1221 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
1222 "1234567,fix3d,0.340000,0.560000,0.780000,operational,unlocked,on,001,01");
1223
1224 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "1");
1225 f_sleep(2.0);
1226
1227 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234888,fix3d,0.350000,0.570000,0.790000");
1228 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
1229 "1234888,fix3d,0.350000,0.570000,0.790000,operational,locked,off,001,01");
1230
1231 /* should match the one from config */
1232 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "0");
1233
1234 setverdict(pass);
1235}
1236
Harald Welte6f521d82017-12-11 19:52:02 +01001237function f_bssap_tx_ud(template PDU_BSSAP bssap) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +01001238 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, bssap));
Harald Welte6f521d82017-12-11 19:52:02 +01001239}
1240
1241
1242/***********************************************************************
1243 * Paging Testing
1244 ***********************************************************************/
1245
1246type record Cell_Identity {
1247 GsmMcc mcc,
1248 GsmMnc mnc,
1249 GsmLac lac,
1250 GsmCellId ci
1251};
Harald Welte24135bd2018-03-17 19:27:53 +01001252private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01001253private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01001254
Harald Welte5d1a2202017-12-13 19:51:29 +01001255type set of integer BtsIdList;
1256
1257private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
1258 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
1259 if (bts_id == bts_ids[j]) {
1260 return true;
1261 }
1262 }
1263 return false;
1264}
Harald Welte6f521d82017-12-11 19:52:02 +01001265
1266/* core paging test helper function; used by most paging test cases */
1267private function f_pageing_helper(hexstring imsi,
1268 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01001269 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01001270 template RSL_ChanNeeded rsl_chneed := omit,
1271 template OCT4 tmsi := omit) runs on test_CT
1272{
1273 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
1274 var MobileIdentity mi;
1275 var template octetstring id_enc; /* FIXME */
1276 var RSL_Message rx_rsl;
1277 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01001278 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01001279
1280 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01001281
1282 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01001283 for (i := 0; i < NUM_BTS; i := i + 1) {
1284 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01001285 }
Harald Welte6f521d82017-12-11 19:52:02 +01001286
1287 if (isvalue(rsl_chneed)) {
1288 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
1289 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
1290 } else {
1291 bssmap_chneed := omit;
1292 }
1293
1294 f_bssap_tx_ud(ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed));
1295
Pau Espin Pedrol76ba5412019-06-10 11:00:33 +02001296/* FIXME: Disabled due to bugs in both GSM_RR_Types and MobileL3_CommonIE_Types IMSI encoder
Harald Welte6f521d82017-12-11 19:52:02 +01001297 if (isvalue(tmsi)) {
1298 mi := valueof(t_Osmo_MI_TMSI(oct2int(valueof(tmsi))));
1299 } else {
1300 mi := valueof(ts_Osmo_MI_IMSI(imsi));
1301 }
1302 id_enc := enc_MobileIdentity(mi);
1303*/
1304 id_enc := ?;
Harald Welte5d1a2202017-12-13 19:51:29 +01001305 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
1306 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(id_enc));
1307 /* check channel type, paging group */
1308 if (rx_rsl.ies[1].body.paging_group != paging_group) {
1309 setverdict(fail, "Paging for wrong paging group");
1310 }
1311 if (ispresent(rsl_chneed) and
1312 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
1313 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
1314 }
Harald Welte6f521d82017-12-11 19:52:02 +01001315 }
Harald Welte2fccd982018-01-31 15:48:19 +01001316 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01001317 /* do a quick check on all not-included BTSs if they received paging */
1318 for (i := 0; i < NUM_BTS; i := i + 1) {
1319 timer T := 0.1;
1320 if (f_bts_in_list(i, bts_ids)) {
1321 continue;
1322 }
1323 T.start;
1324 alt {
1325 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(id_enc))) {
1326 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
1327 }
1328 [] IPA_RSL[i].receive { repeat; }
1329 [] T.timeout { }
1330 }
Harald Welte6f521d82017-12-11 19:52:02 +01001331 }
1332
1333 setverdict(pass);
1334}
1335
Harald Welte5d1a2202017-12-13 19:51:29 +01001336const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01001337const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01001338const BtsIdList c_BtsId_LAC1 := { 0, 1 };
1339const BtsIdList c_BtsId_LAC2 := { 2 };
1340
Harald Welte6f521d82017-12-11 19:52:02 +01001341/* PAGING by IMSI + TMSI */
1342testcase TC_paging_imsi_nochan() runs on test_CT {
1343 var BSSMAP_FIELD_CellIdentificationList cid_list;
1344 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01001345 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001346 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001347}
1348
1349/* PAGING by IMSI + TMSI */
1350testcase TC_paging_tmsi_nochan() runs on test_CT {
1351 var BSSMAP_FIELD_CellIdentificationList cid_list;
1352 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001353 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001354 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001355}
1356
1357/* Paging with different "channel needed' values */
1358testcase TC_paging_tmsi_any() runs on test_CT {
1359 var BSSMAP_FIELD_CellIdentificationList cid_list;
1360 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001361 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001362 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001363}
1364testcase TC_paging_tmsi_sdcch() runs on test_CT {
1365 var BSSMAP_FIELD_CellIdentificationList cid_list;
1366 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001367 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001368 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001369}
1370testcase TC_paging_tmsi_tch_f() runs on test_CT {
1371 var BSSMAP_FIELD_CellIdentificationList cid_list;
1372 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001373 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001374 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001375}
1376testcase TC_paging_tmsi_tch_hf() runs on test_CT {
1377 var BSSMAP_FIELD_CellIdentificationList cid_list;
1378 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001379 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001380 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001381}
1382
1383/* Paging by CGI */
1384testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
1385 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1386 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001387 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001388 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001389}
1390
1391/* Paging by LAC+CI */
1392testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
1393 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1394 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001395 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001396 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001397}
1398
1399/* Paging by CI */
1400testcase TC_paging_imsi_nochan_ci() runs on test_CT {
1401 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1402 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001403 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001404 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001405}
1406
1407/* Paging by LAI */
1408testcase TC_paging_imsi_nochan_lai() runs on test_CT {
1409 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1410 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001411 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001412 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001413}
1414
1415/* Paging by LAC */
1416testcase TC_paging_imsi_nochan_lac() runs on test_CT {
1417 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1418 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001419 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001420 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001421}
1422
1423/* Paging by "all in BSS" */
1424testcase TC_paging_imsi_nochan_all() runs on test_CT {
1425 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1426 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01001427 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001428 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001429}
1430
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001431/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001432testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
1433 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1434 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 +01001435 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001436 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001437}
Harald Welte6f521d82017-12-11 19:52:02 +01001438
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001439/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001440testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
1441 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1442 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001443 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001444 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001445}
1446
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001447/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001448testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
1449 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1450 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001451 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001452 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001453}
1454
Harald Welte6f521d82017-12-11 19:52:02 +01001455/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01001456testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
1457 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1458 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
1459 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001460 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001461}
1462
1463/* Paging on empty list: Verify none of them page */
1464testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
1465 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1466 cid_list := { cIl_LAC := { } };
1467 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001468 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001469}
1470
Stefan Sperling049a86e2018-03-20 15:51:00 +01001471/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
1472testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
1473 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1474 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
1475 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
1476 f_shutdown_helper();
1477}
1478
Harald Welte6f521d82017-12-11 19:52:02 +01001479/* Verify paging retransmission interval + count */
1480/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01001481/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01001482
Harald Weltee65d40e2017-12-13 00:09:06 +01001483/* Verify PCH load */
1484testcase TC_paging_imsi_load() runs on test_CT {
1485 var BSSMAP_FIELD_CellIdentificationList cid_list;
1486 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01001487 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01001488 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001489 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01001490
1491 /* tell BSC there is no paging space anymore */
1492 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01001493 f_sleep(0.2);
1494 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01001495
1496 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
1497 * there would be 8 retransmissions during 4 seconds */
1498 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01001499 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01001500 alt {
1501 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1502 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02001503 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01001504 }
Harald Welte2caa1062018-03-17 18:19:05 +01001505 [] T_retrans.timeout {
1506 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
1507 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
1508 T_retrans.start;
1509 repeat;
1510 }
Harald Weltee65d40e2017-12-13 00:09:06 +01001511 [] T.timeout {
1512 setverdict(pass);
1513 }
1514 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001515
1516 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01001517}
1518
Harald Welte235ebf12017-12-15 14:18:16 +01001519/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01001520testcase TC_paging_counter() runs on test_CT {
1521 var BSSMAP_FIELD_CellIdentificationList cid_list;
1522 timer T := 4.0;
1523 var integer i;
1524 var integer paging_attempted_bsc;
1525 var integer paging_attempted_bts[NUM_BTS];
1526 var integer paging_expired_bts[NUM_BTS];
1527 cid_list := valueof(ts_BSSMAP_CIL_noCell);
1528
1529 f_init();
1530
1531 /* read counters before paging */
1532 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
1533 for (i := 0; i < NUM_BTS; i := i+1) {
1534 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
1535 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
1536 }
1537
1538 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
1539
1540 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
1541 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
1542 for (i := 0; i < NUM_BTS; i := i+1) {
1543 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
1544 paging_attempted_bts[i]+1);
1545 }
1546
1547 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
1548 f_sleep(12.0);
1549 for (i := 0; i < NUM_BTS; i := i+1) {
1550 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
1551 paging_expired_bts[i]+1);
1552 }
Harald Welte1ff69992017-12-14 12:31:17 +01001553
Philipp Maier282ca4b2018-02-27 17:17:00 +01001554 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01001555}
1556
1557
Harald Welte10985002017-12-12 09:29:15 +01001558/* Verify paging stops after A-RESET */
1559testcase TC_paging_imsi_a_reset() runs on test_CT {
1560 var BSSMAP_FIELD_CellIdentificationList cid_list;
1561 timer T := 3.0;
1562 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001563 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01001564
1565 /* Perform a BSSMAP Reset and wait for ACK */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001566 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 +01001567 alt {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001568 [] 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 +01001569 [] BSSAP.receive { repeat; }
1570 }
1571
Daniel Willmanncbef3982018-07-30 09:22:40 +02001572 /* Wait to avoid a possible race condition if a paging message is
1573 * received right before the reset ACK. */
1574 f_sleep(0.2);
1575
Harald Welte10985002017-12-12 09:29:15 +01001576 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01001577 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
1578 IPA_RSL[i].clear;
1579 }
Harald Welte10985002017-12-12 09:29:15 +01001580
1581 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
1582 T.start;
1583 alt {
1584 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1585 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001586 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01001587 }
Harald Welte5d1a2202017-12-13 19:51:29 +01001588 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1589 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001590 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001591 }
1592 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1593 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001594 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001595 }
Harald Welte10985002017-12-12 09:29:15 +01001596 [] T.timeout {
1597 setverdict(pass);
1598 }
1599 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001600
1601 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01001602}
Harald Welteae026692017-12-09 01:03:01 +01001603
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001604/* Verify how we handle unsolicited Paging Response, for instance because we
1605 * receive a Paging Response after T3113 expired (and subscriber information was
1606 * dropped). See OS#3680.
1607 */
1608testcase TC_paging_resp_unsol() runs on test_CT {
1609
1610 f_init(1);
1611
1612 var BSSAP_N_CONNECT_ind rx_c_ind;
1613 var DchanTuple dt;
1614 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
1615
1616 /* Send CHAN RQD and wait for allocation; acknowledge it */
1617 dt.rsl_chan_nr := f_chreq_act_ack();
1618
1619 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
1620 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
1621
1622 /* expect BSC to disable the channel */
Pau Espin Pedrol5ee6f6c2018-12-07 12:07:43 +01001623 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001624 setverdict(pass);
1625
1626}
1627
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001628/* Test RSL link drop causes counter increment */
1629testcase TC_rsl_drop_counter() runs on test_CT {
1630 var integer rsl_fail;
1631
Harald Welte89d42e82017-12-17 16:42:41 +01001632 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001633
1634 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
1635
1636 bts[0].rsl.vc_IPA.stop;
1637
1638 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
1639
1640 setverdict(pass);
1641}
1642
1643/* TODO: Test OML link drop causes counter increment */
1644
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001645/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
1646function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
1647 timer T := 10.0;
1648
1649 bts[0].rsl.id := "IPA-0-RSL";
1650 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
1651 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
1652 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
1653 bts[0].rsl.ccm_pars.unit_id := "0/0/0"; /* value which is unknown at BTS */
1654
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001655 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
1656
1657 f_init_mgcp("VirtMSC");
1658
1659 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
1660 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
1661 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
1662 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
1663
1664 /* wait for IPA OML link to connect and then disconnect */
1665 T.start;
1666 alt {
1667 [] IPA_RSL[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) {
1668 T.stop;
1669 return true;
1670 }
1671 [] IPA_RSL[0].receive { repeat }
1672 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02001673 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001674 }
1675 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001676 return false;
1677}
1678
1679/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1680testcase TC_rsl_unknown_unit_id() runs on test_CT {
1681 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
1682 setverdict(pass);
1683 } else {
1684 setverdict(fail, "Timeout RSL waiting for connection to close");
1685 }
1686}
1687
1688
1689/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1690testcase TC_oml_unknown_unit_id() runs on test_CT {
1691 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
1692 setverdict(pass);
1693 } else {
1694 setverdict(fail, "Timeout OML waiting for connection to close");
1695 }
1696}
1697
1698
Harald Weltec1a2fff2017-12-17 11:06:19 +01001699/***********************************************************************
Harald Welte6811d102019-04-14 22:23:14 +02001700 * "New world" test cases using RSL_Emulation + RAN_Emulation
Harald Weltec1a2fff2017-12-17 11:06:19 +01001701 ***********************************************************************/
1702
Harald Welte6811d102019-04-14 22:23:14 +02001703import from RAN_Emulation all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01001704import from RSL_Emulation all;
1705import from MSC_ConnectionHandler all;
1706
1707type function void_fn(charstring id) runs on MSC_ConnHdlr;
1708
Harald Welte336820c2018-05-31 20:34:52 +02001709/* helper function to create and connect a MSC_ConnHdlr component */
Harald Welteff579f92018-05-31 22:19:39 +02001710private function f_connect_handler(inout MSC_ConnHdlr vc_conn) runs on test_CT {
Harald Welte6811d102019-04-14 22:23:14 +02001711 connect(vc_conn:RAN, g_bssap.vc_RAN:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001712 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001713 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01001714 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01001715 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01001716 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
1717 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
1718 }
Harald Welte6811d102019-04-14 22:23:14 +02001719 connect(vc_conn:BSSAP, g_bssap.vc_RAN:CLIENT);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001720 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Harald Welte336820c2018-05-31 20:34:52 +02001721}
1722
1723function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
1724runs on test_CT return MSC_ConnHdlr {
1725 var charstring id := testcasename();
1726 var MSC_ConnHdlr vc_conn;
1727 vc_conn := MSC_ConnHdlr.create(id);
1728 f_connect_handler(vc_conn);
Harald Weltea0630032018-03-20 21:09:55 +01001729 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001730 return vc_conn;
1731}
1732
Harald Weltea0630032018-03-20 21:09:55 +01001733/* first function inside ConnHdlr component; sets g_pars + starts function */
1734private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
1735runs on MSC_ConnHdlr {
1736 if (isvalue(pars)) {
1737 g_pars := valueof(pars);
1738 }
1739 fn.apply(id);
1740}
1741
Harald Welte3c86ea02018-05-10 22:28:05 +02001742/* Establish signalling channel (non-assignment case) followed by cipher mode */
1743private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001744 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1745 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02001746 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02001747 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
1748 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
1749 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
1750 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02001751
Philipp Maier23000732018-05-18 11:25:37 +02001752 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02001753}
1754testcase TC_ciph_mode_a5_0() runs on test_CT {
1755 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001756 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001757 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
1758
1759 f_init(1, true);
1760 f_sleep(1.0);
1761 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1762 vc_conn.done;
1763}
1764testcase TC_ciph_mode_a5_1() runs on test_CT {
1765 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001766 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001767 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
1768
1769 f_init(1, true);
1770 f_sleep(1.0);
1771 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1772 vc_conn.done;
1773}
1774testcase TC_ciph_mode_a5_3() runs on test_CT {
1775 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001776 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001777 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
1778
1779 f_init(1, true);
1780 f_sleep(1.0);
1781 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1782 vc_conn.done;
1783}
1784
1785
1786/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02001787private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001788 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1789 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01001790
Harald Welte552620d2017-12-16 23:21:36 +01001791 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1792 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01001793
Harald Weltea0630032018-03-20 21:09:55 +01001794 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01001795}
Harald Welte552620d2017-12-16 23:21:36 +01001796testcase TC_assignment_fr_a5_0() runs on test_CT {
1797 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001798 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001799 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01001800
Harald Welte89d42e82017-12-17 16:42:41 +01001801 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001802 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001803 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01001804 vc_conn.done;
1805}
Harald Welte552620d2017-12-16 23:21:36 +01001806testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01001807 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001808 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001809 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001810
Harald Welte89d42e82017-12-17 16:42:41 +01001811 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001812 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001813 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
1814 vc_conn.done;
1815}
1816testcase TC_assignment_fr_a5_3() runs on test_CT {
1817 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001818 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001819 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001820
Harald Welte651fcdc2018-05-10 20:23:16 +02001821 f_init(1, true);
1822 f_sleep(1.0);
1823 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001824 vc_conn.done;
1825}
1826
Harald Welte552620d2017-12-16 23:21:36 +01001827/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
1828private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001829 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01001830 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001831 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001832 const OCT8 kc := '0001020304050607'O;
1833
1834 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001835 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
1836
Harald Weltea0630032018-03-20 21:09:55 +01001837 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01001838}
Harald Welte552620d2017-12-16 23:21:36 +01001839testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
1840 var MSC_ConnHdlr vc_conn;
1841
Harald Welte89d42e82017-12-17 16:42:41 +01001842 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001843 f_sleep(1.0);
1844
Harald Welte8863fa12018-05-10 20:15:27 +02001845 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01001846 vc_conn.done;
1847}
1848
Harald Welte552620d2017-12-16 23:21:36 +01001849private function f_tc_assignment_fr_a5_4(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001850 g_pars := f_gen_test_hdlr_pars();
Harald Welteed848512018-05-24 22:27:58 +02001851 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1852 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001853 const OCT8 kc := '0001020304050607'O;
1854 const OCT16 kc128 := kc & kc;
1855
1856 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1857 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Weltea0630032018-03-20 21:09:55 +01001858 f_establish_fully(ass_cmd, exp_compl);
Harald Welte38b2a102017-12-23 02:42:58 +01001859 f_cipher_mode('10'O, kc, kc128, true);
Harald Welte552620d2017-12-16 23:21:36 +01001860 /* TODO: expect GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED cause value */
Harald Welte552620d2017-12-16 23:21:36 +01001861}
Harald Welte552620d2017-12-16 23:21:36 +01001862testcase TC_assignment_fr_a5_4() runs on test_CT {
1863 var MSC_ConnHdlr vc_conn;
1864
Harald Welte89d42e82017-12-17 16:42:41 +01001865 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001866 f_sleep(1.0);
1867
Harald Welte8863fa12018-05-10 20:15:27 +02001868 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_4));
Harald Welte552620d2017-12-16 23:21:36 +01001869 vc_conn.done;
1870}
1871
1872
Harald Welte4532e0a2017-12-23 02:05:44 +01001873private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001874 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01001875 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02001876 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01001877 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Harald Weltea0630032018-03-20 21:09:55 +01001878 f_establish_fully(ass_cmd, exp_compl);
Harald Welte4532e0a2017-12-23 02:05:44 +01001879}
1880
1881testcase TC_assignment_sign() runs on test_CT {
1882 var MSC_ConnHdlr vc_conn;
1883
1884 f_init(1, true);
1885 f_sleep(1.0);
1886
Harald Welte8863fa12018-05-10 20:15:27 +02001887 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01001888 vc_conn.done;
1889}
1890
Harald Welte60aa5762018-03-21 19:33:13 +01001891/***********************************************************************
1892 * Codec (list) testing
1893 ***********************************************************************/
1894
1895/* check if the given rsl_mode is compatible with the a_elem */
1896private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
1897return boolean {
1898 select (a_elem.codecType) {
1899 case (GSM_FR) {
1900 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
1901 return true;
1902 }
1903 }
1904 case (GSM_HR) {
1905 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
1906 return true;
1907 }
1908 }
1909 case (GSM_EFR) {
1910 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
1911 return true;
1912 }
1913 }
1914 case (FR_AMR) {
1915 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
1916 return true;
1917 }
1918 }
1919 case (HR_AMR) {
1920 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
1921 return true;
1922 }
1923 }
1924 case else { }
1925 }
1926 return false;
1927}
1928
1929/* check if the given rsl_mode is compatible with the a_list */
1930private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
1931return boolean {
1932 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
1933 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
1934 return true;
1935 }
1936 }
1937 return false;
1938}
1939
1940/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02001941function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01001942return BSSMAP_IE_ChannelType {
1943 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
1944 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
1945 select (a_elem.codecType) {
1946 case (GSM_FR) {
1947 ret.channelRateAndType := ChRate_TCHF;
1948 ret.speechId_DataIndicator := Spdi_TCHF_FR;
1949 }
1950 case (GSM_HR) {
1951 ret.channelRateAndType := ChRate_TCHH;
1952 ret.speechId_DataIndicator := Spdi_TCHH_HR;
1953 }
1954 case (GSM_EFR) {
1955 ret.channelRateAndType := ChRate_TCHF;
1956 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
1957 }
1958 case (FR_AMR) {
1959 ret.channelRateAndType := ChRate_TCHF;
1960 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
1961 }
1962 case (HR_AMR) {
1963 ret.channelRateAndType := ChRate_TCHH;
1964 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
1965 }
1966 case else {
1967 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02001968 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01001969 }
1970 }
1971 return ret;
1972}
1973
Harald Weltea63b9102018-03-22 20:36:16 +01001974private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
1975return template RSL_IE_Body {
1976 var template RSL_IE_Body mode_ie := {
1977 chan_mode := {
1978 len := ?,
1979 reserved := ?,
1980 dtx_d := ?,
1981 dtx_u := ?,
1982 spd_ind := RSL_SPDI_SPEECH,
1983 ch_rate_type := -,
1984 coding_alg_rate := -
1985 }
1986 }
1987
1988 select (a_elem.codecType) {
1989 case (GSM_FR) {
1990 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1991 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1992 }
1993 case (GSM_HR) {
1994 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1995 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1996 }
1997 case (GSM_EFR) {
1998 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1999 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
2000 }
2001 case (FR_AMR) {
2002 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
2003 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
2004 }
2005 case (HR_AMR) {
2006 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
2007 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
2008 }
2009 }
2010 return mode_ie;
2011}
2012
Harald Welte60aa5762018-03-21 19:33:13 +01002013type record CodecListTest {
2014 BSSMAP_IE_SpeechCodecList codec_list,
2015 charstring id
2016}
2017type record of CodecListTest CodecListTests
2018
2019private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02002020 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
2021 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
Harald Welte60aa5762018-03-21 19:33:13 +01002022
2023 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Harald Welte79f3f542018-05-25 20:02:37 +02002024 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
2025 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
2026 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
2027 g_pars.ass_codec_list.codecElements[0];
Philipp Maierd0e64b02019-03-13 14:15:23 +01002028 if (isvalue(g_pars.expect_mr_s0_s7)) {
2029 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
2030 g_pars.expect_mr_s0_s7;
2031 }
Harald Welte79f3f542018-05-25 20:02:37 +02002032 }
Harald Welte60aa5762018-03-21 19:33:13 +01002033 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
2034 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01002035 log("expecting ASS COMPL like this: ", exp_compl);
2036
2037 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01002038
2039 /* Verify that the RSL-side activation actually matches our expectations */
2040 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
2041
2042 var RSL_IE_Body mode_ie;
2043 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
2044 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02002045 mtc.stop;
Harald Weltea63b9102018-03-22 20:36:16 +01002046 }
2047 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
2048 if (not match(mode_ie, t_mode_ie)) {
2049 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
2050 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002051
2052 var RSL_IE_Body mr_conf;
2053 if (g_pars.expect_mr_conf_ie != omit) {
2054 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
2055 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
Daniel Willmannafce8662018-07-06 23:11:32 +02002056 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002057 }
2058 log("found RSL MR CONFIG IE: ", mr_conf);
2059
2060 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
2061 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
2062 g_pars.expect_mr_conf_ie);
2063 }
2064 } else {
2065 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
2066 log("found RSL MR CONFIG IE: ", mr_conf);
2067 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
Daniel Willmannafce8662018-07-06 23:11:32 +02002068 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002069 }
2070 }
Harald Welte60aa5762018-03-21 19:33:13 +01002071}
2072
Philipp Maierd0e64b02019-03-13 14:15:23 +01002073private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
2074
2075 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2076 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2077
2078 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
2079 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
2080 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
2081 }
2082 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
2083 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
2084 log("expecting ASS FAIL like this: ", exp_fail);
2085
2086 f_establish_fully(ass_cmd, exp_fail);
2087}
2088
Harald Welte60aa5762018-03-21 19:33:13 +01002089testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002090 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002091 var MSC_ConnHdlr vc_conn;
2092
2093 f_init(1, true);
2094 f_sleep(1.0);
2095
2096 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002097 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002098 vc_conn.done;
2099}
2100
2101testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002102 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002103 var MSC_ConnHdlr vc_conn;
2104
2105 f_init(1, true);
2106 f_sleep(1.0);
2107
2108 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002109 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002110 vc_conn.done;
2111}
2112
2113testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002114 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002115 var MSC_ConnHdlr vc_conn;
2116
2117 f_init(1, true);
2118 f_sleep(1.0);
2119
2120 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002121 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002122 vc_conn.done;
2123}
2124
Philipp Maierd0e64b02019-03-13 14:15:23 +01002125/* Allow 5,90k only (current default config) */
2126private function f_allow_amr_rate_5_90k() runs on test_CT {
2127 f_vty_enter_cfg_msc(BSCVTY, 0);
2128 f_vty_transceive(BSCVTY, "amr-config 12_2k forbidden");
2129 f_vty_transceive(BSCVTY, "amr-config 10_2k forbidden");
2130 f_vty_transceive(BSCVTY, "amr-config 7_95k forbidden");
2131 f_vty_transceive(BSCVTY, "amr-config 7_40k forbidden");
2132 f_vty_transceive(BSCVTY, "amr-config 6_70k forbidden");
2133 f_vty_transceive(BSCVTY, "amr-config 5_90k allowed");
2134 f_vty_transceive(BSCVTY, "amr-config 5_15k forbidden");
2135 f_vty_transceive(BSCVTY, "amr-config 4_75k forbidden");
2136 f_vty_transceive(BSCVTY, "exit");
2137 f_vty_transceive(BSCVTY, "exit");
2138}
2139
2140/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
2141 * ("Config-NB-Code = 1") */
2142private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
2143 f_vty_enter_cfg_msc(BSCVTY, 0);
2144 f_vty_transceive(BSCVTY, "amr-config 12_2k allowed");
2145 f_vty_transceive(BSCVTY, "amr-config 10_2k forbidden");
2146 f_vty_transceive(BSCVTY, "amr-config 7_95k forbidden");
2147 f_vty_transceive(BSCVTY, "amr-config 7_40k allowed");
2148 f_vty_transceive(BSCVTY, "amr-config 6_70k forbidden");
2149 f_vty_transceive(BSCVTY, "amr-config 5_90k allowed");
2150 f_vty_transceive(BSCVTY, "amr-config 5_15k forbidden");
2151 f_vty_transceive(BSCVTY, "amr-config 4_75k allowed");
2152 f_vty_transceive(BSCVTY, "exit");
2153 f_vty_transceive(BSCVTY, "exit");
2154}
2155
Harald Welte60aa5762018-03-21 19:33:13 +01002156testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002157 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002158 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02002159
2160 /* Note: This setups the codec configuration. The parameter payload in
2161 * mr_conf must be consistant with the parameter codecElements in pars
2162 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002163 var RSL_IE_Body mr_conf := {
2164 other := {
2165 len := 2,
2166 payload := '2804'O
2167 }
2168 };
Harald Welte60aa5762018-03-21 19:33:13 +01002169
Philipp Maier7695a0d2018-09-27 17:52:14 +02002170 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Philipp Maier806f8f12019-03-12 12:13:41 +01002171 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02002172 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
2173 pars.expect_mr_conf_ie := mr_conf;
2174
Harald Welte60aa5762018-03-21 19:33:13 +01002175 f_init(1, true);
2176 f_sleep(1.0);
2177
Harald Welte8863fa12018-05-10 20:15:27 +02002178 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002179 vc_conn.done;
2180}
2181
2182testcase TC_assignment_codec_amr_h() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002183 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002184 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02002185
2186 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002187 var RSL_IE_Body mr_conf := {
2188 other := {
2189 len := 2,
2190 payload := '2804'O
2191 }
2192 };
Harald Welte60aa5762018-03-21 19:33:13 +01002193
Philipp Maier7695a0d2018-09-27 17:52:14 +02002194 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Philipp Maier806f8f12019-03-12 12:13:41 +01002195 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02002196 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2197 pars.expect_mr_conf_ie := mr_conf;
2198
Harald Welte60aa5762018-03-21 19:33:13 +01002199 f_init(1, true);
2200 f_sleep(1.0);
2201
Harald Welte8863fa12018-05-10 20:15:27 +02002202 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002203 vc_conn.done;
2204}
2205
Philipp Maierd0e64b02019-03-13 14:15:23 +01002206function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0)
2207runs on test_CT {
2208
2209 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2210 var MSC_ConnHdlr vc_conn;
2211
2212 /* See note above */
2213 var RSL_IE_Body mr_conf := {
2214 other := {
2215 len := lengthof(mrconf),
2216 payload := mrconf
2217 }
2218 };
2219
2220 if (fr) {
2221 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
2222 } else {
2223 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2224 }
2225 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
2226 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2227 pars.expect_mr_conf_ie := mr_conf;
2228 pars.expect_mr_s0_s7 := exp_s8_s0;
2229
2230 f_init(1, true);
2231 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
2232 f_sleep(1.0);
2233
2234 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
2235 vc_conn.done;
2236 f_allow_amr_rate_5_90k();
2237}
2238
2239function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
2240runs on test_CT {
2241
2242 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2243 var MSC_ConnHdlr vc_conn;
2244
2245 if (fr) {
2246 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
2247 } else {
2248 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2249 }
2250 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
2251 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2252
2253 f_init(1, true);
2254 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
2255 f_sleep(1.0);
2256
2257 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
2258 vc_conn.done;
2259 f_allow_amr_rate_5_90k();
2260}
2261
2262
2263/* Set S1, we expect an AMR multirate configuration IE with all four rates
2264 * set. */
2265testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
2266 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
2267}
2268
2269/* Set S1, we expect an AMR multirate configuration IE with the lower three
2270 * rates set. */
2271testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
2272 f_TC_assignment_codec_amr(false, '2815208820'O, '00000010'B, '00000010'B);
2273}
2274
2275/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
2276 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
2277testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
2278 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'B, '00000010'B);
2279}
2280
2281/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
2282 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
2283testcase TC_assignment_codec_amr_h_S124() runs on test_CT {
2284 f_TC_assignment_codec_amr(false, '2815208820'O, '00010110'B, '00000010'B);
2285}
2286
2287/* The following block of tests selects more and more rates until all four
2288 * possible rates are in the active set (full rate) */
2289testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
2290 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'B);
2291}
2292
2293testcase TC_assignment_codec_amr_f_S02() runs on test_CT {
2294 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'B);
2295}
2296
2297testcase TC_assignment_codec_amr_f_S024() runs on test_CT {
2298 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'B);
2299}
2300
2301testcase TC_assignment_codec_amr_f_S0247() runs on test_CT {
2302 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
2303}
2304
2305/* The following block of tests selects more and more rates until all three
2306 * possible rates are in the active set (half rate) */
2307testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
2308 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'B);
2309}
2310
2311testcase TC_assignment_codec_amr_h_S02() runs on test_CT {
2312 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
2313}
2314
2315testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
2316 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
2317}
2318
2319/* The following block tests what happens when the MSC does offer rate
2320 * configurations that are not supported by the BSC. Normally such situations
2321 * should not happen because the MSC gets informed by the BSC in advance via
2322 * the L3 COMPLETE message which rates are applicable. The MSC should not try
2323 * to offer rates that are not applicable anyway. */
2324
2325testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
2326 /* Try to include 12,2k in into the active set even though the channel
2327 * is half rate only. The BSC is expected to remove the 12,0k */
2328 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'B);
2329}
2330
2331testcase TC_assignment_codec_amr_f_S01234567() runs on test_CT {
2332 /* See what happens when all rates are selected at once. Since then
2333 * Also S1 is selected, this setting will be prefered and we should
2334 * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
2335 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
2336}
2337
2338testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
2339 /* Same as above, but with S1 missing, the MSC is then expected to
2340 * select the currently supported rates, which are also 12.2k, 7,40k,
2341 * 5,90k, and 4,75k, into the active set. */
2342 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'B);
2343}
2344
2345testcase TC_assignment_codec_amr_f_zero() runs on test_CT {
2346 /* Try to select no rates at all */
2347 f_TC_assignment_codec_amr_fail(true, '00000000'B);
2348}
2349
2350testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
2351 /* Try to select only unsupported rates */
2352 f_TC_assignment_codec_amr_fail(true, '01101000'B);
2353}
2354
2355testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
2356 /* Try to select 12,2k for half rate */
2357 f_TC_assignment_codec_amr_fail(false, '10000000'B);
2358}
2359
Philipp Maierac09bfc2019-01-08 13:41:39 +01002360private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002361 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
2362 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
2363 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
2364 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002365}
2366
2367private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002368 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
2369 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002370}
2371
2372private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002373 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
2374 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
2375 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
2376 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
2377 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
2378 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002379}
2380
2381/* Allow HR only */
2382private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
2383 g_pars := f_gen_test_hdlr_pars();
2384 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2385 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2386 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2387 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
2388 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
2389 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
2390 f_establish_fully(ass_cmd, exp_compl);
2391}
2392
2393/* Allow FR only */
2394private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
2395 g_pars := f_gen_test_hdlr_pars();
2396 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2397 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2398 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2399 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
2400 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
2401 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2402 f_establish_fully(ass_cmd, exp_compl);
2403}
2404
2405/* Allow HR only (expect assignment failure) */
2406private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
2407 g_pars := f_gen_test_hdlr_pars();
2408 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2409 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2410 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2411 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
2412 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
2413 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
2414 f_establish_fully(ass_cmd, exp_fail);
2415}
2416
2417/* Allow FR only (expect assignment failure) */
2418private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(charstring id) runs on MSC_ConnHdlr {
2419 g_pars := f_gen_test_hdlr_pars();
2420 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2421 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2422 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2423 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
2424 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
2425 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2426 f_establish_fully(ass_cmd, exp_fail);
2427}
2428
2429/* Allow FR and HR, but prefer FR */
2430private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2431 g_pars := f_gen_test_hdlr_pars();
2432 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2433 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2434 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2435 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2436 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2437 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2438 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2439 f_establish_fully(ass_cmd, exp_compl);
2440}
2441
2442/* Allow FR and HR, but prefer HR */
2443private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2444 g_pars := f_gen_test_hdlr_pars();
2445 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2446 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2447 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2448 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2449 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2450 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2451 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2452 f_establish_fully(ass_cmd, exp_compl);
2453}
2454
2455/* Allow FR and HR, but prefer FR */
2456private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2457 g_pars := f_gen_test_hdlr_pars();
2458 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2459 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2460 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2461 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2462 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2463 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2464 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2465 f_establish_fully(ass_cmd, exp_compl);
2466}
2467
2468/* Allow FR and HR, but prefer HR */
2469private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2470 g_pars := f_gen_test_hdlr_pars();
2471 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2472 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2473 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2474 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2475 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2476 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2477 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2478 f_establish_fully(ass_cmd, exp_compl);
2479}
2480
2481/* Request a HR channel while all FR channels are exhausted, this is expected
2482 * to work without conflicts */
2483testcase TC_assignment_codec_fr_exhausted_req_hr() runs on test_CT {
2484 var MSC_ConnHdlr vc_conn;
2485 f_init(1, true);
2486 f_sleep(1.0);
2487 f_enable_all_tch();
2488 f_disable_all_tch_f();
2489 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr));
2490 vc_conn.done;
2491 f_enable_all_tch();
2492 setverdict(pass);
2493}
2494
2495/* Request a FR channel while all FR channels are exhausted, this is expected
2496 * to fail. */
2497testcase TC_assignment_codec_fr_exhausted_req_fr() runs on test_CT {
2498 var MSC_ConnHdlr vc_conn;
2499 f_init(1, true);
2500 f_sleep(1.0);
2501 f_enable_all_tch();
2502 f_disable_all_tch_f();
2503 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr_fail));
2504 vc_conn.done;
2505 f_enable_all_tch();
2506 setverdict(pass);
2507}
2508
2509/* Request a FR (prefered) or alternatively a HR channel while all FR channels
2510 * are exhausted, this is expected to be resolved by selecting a HR channel. */
2511testcase TC_assignment_codec_fr_exhausted_req_fr_hr() runs on test_CT {
2512 var MSC_ConnHdlr vc_conn;
2513 f_init(1, true);
2514 f_sleep(1.0);
2515 f_enable_all_tch();
2516 f_disable_all_tch_f();
2517 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
2518 vc_conn.done;
2519 f_enable_all_tch();
2520 setverdict(pass);
2521}
2522
2523/* Request a HR (prefered) or alternatively a FR channel while all FR channels
2524 * are exhausted, this is expected to work without conflicts. */
2525testcase TC_assignment_codec_fr_exhausted_req_hr_fr() runs on test_CT {
2526 var MSC_ConnHdlr vc_conn;
2527 f_init(1, true);
2528 f_sleep(1.0);
2529 f_enable_all_tch();
2530 f_disable_all_tch_f();
2531 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_hr_fr));
2532 vc_conn.done;
2533 f_enable_all_tch();
2534 setverdict(pass);
2535}
2536
2537/* Request a FR channel while all HR channels are exhausted, this is expected
2538 * to work without conflicts */
2539testcase TC_assignment_codec_hr_exhausted_req_fr() runs on test_CT {
2540 var MSC_ConnHdlr vc_conn;
2541 f_init(1, true);
2542 f_sleep(1.0);
2543 f_enable_all_tch();
2544 f_disable_all_tch_h();
2545 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr));
2546 vc_conn.done;
2547 f_enable_all_tch();
2548 setverdict(pass);
2549}
2550
2551/* Request a HR channel while all HR channels are exhausted, this is expected
2552 * to fail. */
2553testcase TC_assignment_codec_hr_exhausted_req_hr() runs on test_CT {
2554 var MSC_ConnHdlr vc_conn;
2555 f_init(1, true);
2556 f_sleep(1.0);
2557 f_enable_all_tch();
2558 f_disable_all_tch_h();
2559 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr_fail));
2560 vc_conn.done;
2561 f_enable_all_tch();
2562 setverdict(pass);
2563}
2564
2565/* Request a HR (prefered) or alternatively a FR channel while all HR channels
2566 * are exhausted, this is expected to be resolved by selecting a FR channel. */
2567testcase TC_assignment_codec_hr_exhausted_req_hr_fr() runs on test_CT {
2568 var MSC_ConnHdlr vc_conn;
2569 f_init(1, true);
2570 f_sleep(1.0);
2571 f_enable_all_tch();
2572 f_disable_all_tch_h();
2573 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_hr_fr));
2574 vc_conn.done;
2575 f_enable_all_tch();
2576 setverdict(pass);
2577}
2578
2579/* Request a FR (prefered) or alternatively a HR channel while all HR channels
2580 * are exhausted, this is expected to work without conflicts. */
2581testcase TC_assignment_codec_hr_exhausted_req_fr_hr() runs on test_CT {
2582 var MSC_ConnHdlr vc_conn;
2583 f_init(1, true);
2584 f_sleep(1.0);
2585 f_enable_all_tch();
2586 f_disable_all_tch_h();
2587 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_fr_hr));
2588 vc_conn.done;
2589 f_enable_all_tch();
2590 setverdict(pass);
2591}
2592
2593/* Allow FR and HR, but prefer HR */
2594private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2595 g_pars := f_gen_test_hdlr_pars();
2596 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2597 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2598 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2599 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2600 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2601 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2602 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2603 f_establish_fully(ass_cmd, exp_compl);
2604}
2605
2606/* Allow FR and HR, but prefer FR */
2607private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2608 g_pars := f_gen_test_hdlr_pars();
2609 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2610 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2611 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2612 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2613 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2614 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2615 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2616 f_establish_fully(ass_cmd, exp_compl);
2617}
2618
2619/* Request a HR (prefered) or alternatively a FR channel, it is expected that
2620 * HR, which is the prefered type, is selected. */
2621testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
2622 var MSC_ConnHdlr vc_conn;
2623 f_init(1, true);
2624 f_sleep(1.0);
2625 f_enable_all_tch();
2626 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
2627 vc_conn.done;
2628 setverdict(pass);
2629}
2630
2631/* Request a FR (prefered) or alternatively a HR channel, it is expected that
2632 * FR, which is the prefered type, is selected. */
2633testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
2634 var MSC_ConnHdlr vc_conn;
2635 f_init(1, true);
2636 f_sleep(1.0);
2637 f_enable_all_tch();
2638 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
2639 vc_conn.done;
2640 setverdict(pass);
2641}
2642
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02002643testcase TC_assignment_osmux() runs on test_CT {
2644 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2645 var MSC_ConnHdlr vc_conn;
2646
2647 /* See note above */
2648 var RSL_IE_Body mr_conf := {
2649 other := {
2650 len := 2,
2651 payload := '2804'O
2652 }
2653 };
2654
2655 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2656 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
2657 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2658 pars.expect_mr_conf_ie := mr_conf;
2659 pars.use_osmux := true;
2660
2661 f_init(1, true, true);
2662 f_sleep(1.0);
2663
2664 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
2665 vc_conn.done;
2666}
2667
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02002668/* test the procedure of the MSC requesting a Classmark Update:
2669 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
2670 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01002671private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002672 g_pars := f_gen_test_hdlr_pars();
2673
Harald Weltea0630032018-03-20 21:09:55 +01002674 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01002675 /* we should now have a COMPL_L3 at the MSC */
2676 BSSAP.receive(tr_BSSMAP_ComplL3);
2677
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02002678 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
2679 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
2680
Harald Welte898113b2018-01-31 18:32:21 +01002681 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
2682 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
2683 setverdict(pass);
2684}
2685testcase TC_classmark() runs on test_CT {
2686 var MSC_ConnHdlr vc_conn;
2687 f_init(1, true);
2688 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002689 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01002690 vc_conn.done;
2691}
2692
Harald Weltee3bd6582018-01-31 22:51:25 +01002693private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002694 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01002695 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01002696 /* we should now have a COMPL_L3 at the MSC */
2697 BSSAP.receive(tr_BSSMAP_ComplL3);
2698
Harald Weltee3bd6582018-01-31 22:51:25 +01002699 /* send the single message we want to send */
2700 f_rsl_send_l3(l3);
2701}
2702
2703private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
2704 timer T := sec;
2705 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01002706 T.start;
2707 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01002708 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
2709 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02002710 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01002711 }
2712 [] T.timeout {
2713 setverdict(pass);
2714 }
2715 }
2716}
2717
Harald Weltee3bd6582018-01-31 22:51:25 +01002718/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2719private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
2720 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
2721 f_bssap_expect_nothing();
2722}
Harald Welte898113b2018-01-31 18:32:21 +01002723testcase TC_unsol_ass_fail() runs on test_CT {
2724 var MSC_ConnHdlr vc_conn;
2725 f_init(1, true);
2726 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002727 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01002728 vc_conn.done;
2729}
Harald Welte552620d2017-12-16 23:21:36 +01002730
Harald Welteea99a002018-01-31 20:46:43 +01002731
2732/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
2733private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002734 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
2735 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01002736}
2737testcase TC_unsol_ass_compl() runs on test_CT {
2738 var MSC_ConnHdlr vc_conn;
2739 f_init(1, true);
2740 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002741 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01002742 vc_conn.done;
2743}
2744
2745
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002746/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2747private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002748 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
2749 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002750}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002751testcase TC_unsol_ho_fail() runs on test_CT {
2752 var MSC_ConnHdlr vc_conn;
2753 f_init(1, true);
2754 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002755 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002756 vc_conn.done;
2757}
2758
2759
Harald Weltee3bd6582018-01-31 22:51:25 +01002760/* short message from MS should be ignored */
2761private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002762 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01002763 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01002764 /* we should now have a COMPL_L3 at the MSC */
2765 BSSAP.receive(tr_BSSMAP_ComplL3);
2766
2767 /* send short message */
2768 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
2769 f_bssap_expect_nothing();
2770}
2771testcase TC_err_82_short_msg() runs on test_CT {
2772 var MSC_ConnHdlr vc_conn;
2773 f_init(1, true);
2774 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002775 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01002776 vc_conn.done;
2777}
2778
2779
Harald Weltee9e02e42018-01-31 23:36:25 +01002780/* 24.008 8.4 Unknown message must trigger RR STATUS */
2781private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
2782 f_est_single_l3(ts_RRM_UL_REL('00'O));
2783 timer T := 3.0
2784 alt {
2785 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
2786 setverdict(pass);
2787 }
2788 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01002789 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01002790 }
2791}
2792testcase TC_err_84_unknown_msg() runs on test_CT {
2793 var MSC_ConnHdlr vc_conn;
2794 f_init(1, true);
2795 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002796 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01002797 vc_conn.done;
2798}
2799
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002800/***********************************************************************
2801 * Handover
2802 ***********************************************************************/
2803
Harald Welte94e0c342018-04-07 11:33:23 +02002804/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
2805private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
2806runs on test_CT {
2807 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2808 " timeslot "&int2str(ts_nr)&" ";
2809 f_vty_transceive(BSCVTY, cmd & suffix);
2810}
2811
Harald Welte261af4b2018-02-12 21:20:39 +01002812/* execute a "bts <0-255> trx <0-255> timeslot <0-7> sub-slot <0-7>" command on given Dchan */
2813private function f_vty_ss_action(charstring suffix, integer bts_nr, integer trx_nr, RslChannelNr chan_nr)
2814runs on MSC_ConnHdlr {
2815 /* FIXME: resolve those from component-global state */
2816 var integer ts_nr := chan_nr.tn;
2817 var integer ss_nr;
2818 if (ischosen(chan_nr.u.ch0)) {
2819 ss_nr := 0;
2820 } else if (ischosen(chan_nr.u.lm)) {
2821 ss_nr := chan_nr.u.lm.sub_chan;
2822 } else if (ischosen(chan_nr.u.sdcch4)) {
2823 ss_nr := chan_nr.u.sdcch4.sub_chan;
2824 } else if (ischosen(chan_nr.u.sdcch8)) {
2825 ss_nr := chan_nr.u.sdcch8.sub_chan;
2826 } else {
2827 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02002828 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01002829 }
2830
2831 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2832 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
2833 f_vty_transceive(BSCVTY, cmd & suffix);
2834}
2835
2836private function f_vty_handover(integer bts_nr, integer trx_nr, RslChannelNr chan_nr,
2837 integer new_bts_nr)
2838runs on MSC_ConnHdlr {
2839 f_vty_ss_action("handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
2840}
2841
2842/* intra-BSC hand-over between BTS0 and BTS1 */
2843private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002844 g_pars := f_gen_test_hdlr_pars();
Harald Welteed848512018-05-24 22:27:58 +02002845 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2846 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01002847 const OCT8 kc := '0001020304050607'O;
2848
2849 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2850 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2851
Harald Weltea0630032018-03-20 21:09:55 +01002852 f_establish_fully(ass_cmd, exp_compl);
Harald Welte261af4b2018-02-12 21:20:39 +01002853
2854 var HandoverState hs := {
2855 rr_ho_cmpl_seen := false,
2856 handover_done := false,
2857 old_chan_nr := -
2858 };
2859 /* issue hand-over command on VTY */
2860 f_vty_handover(0, 0, g_chan_nr, 1);
2861 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
2862 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002863
2864 /* From the MGW perspective, a handover is is characterized by
2865 * performing one MDCX operation with the MGW. So we expect to see
2866 * one more MDCX during handover. */
2867 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
2868
Harald Welte261af4b2018-02-12 21:20:39 +01002869 alt {
2870 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01002871 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002872
Philipp Maier4dae0652018-11-12 12:03:26 +01002873 /* Since this is an internal handover we expect the BSC to inform the
2874 * MSC about the event */
2875 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
2876
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002877 /* Check the amount of MGCP transactions is still consistant with the
2878 * test expectation */
2879 f_check_mgcp_expectations()
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01002880 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01002881}
2882
2883testcase TC_ho_int() runs on test_CT {
2884 var MSC_ConnHdlr vc_conn;
2885 f_init(2, true);
2886 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002887 vc_conn := f_start_handler(refers(f_tc_ho_int));
Harald Welte261af4b2018-02-12 21:20:39 +01002888 vc_conn.done;
2889}
Harald Weltee9e02e42018-01-31 23:36:25 +01002890
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02002891/* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
2892private function f_expect_dlcx_conns(boolean exp_clear_cmpl := true) runs on MSC_ConnHdlr {
2893 var MgcpCommand mgcp;
2894
2895 MGCP.receive(tr_DLCX()) -> value mgcp {
2896 log("Got first DLCX: ", mgcp);
2897 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
2898 };
2899
2900 /* For SCCPLite, BSC doesn't handle the MSC-side */
2901 if (g_pars.aoip) {
2902 MGCP.receive(tr_DLCX()) -> value mgcp {
2903 log("Got second DLCX: ", mgcp);
2904 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
2905 };
2906 }
2907
2908 if (exp_clear_cmpl) {
2909 BSSAP.receive(tr_BSSMAP_ClearComplete);
2910 }
2911}
2912
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002913private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002914 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002915
2916 var PDU_BSSAP ass_req := f_gen_ass_req();
2917 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2918 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2919 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2920 f_establish_fully(ass_req, exp_compl);
2921
2922 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2923
2924 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2925
2926 f_sleep(0.5);
2927 /* The MSC negotiates Handover Request and Handover Request Ack with
2928 * the other BSS and comes back with a BSSMAP Handover Command
2929 * containing an RR Handover Command coming from the target BSS... */
2930
2931 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
2932 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
2933 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
2934 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
2935 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
2936
2937 /* expect the Handover Command to go out on RR */
2938 var RSL_Message rsl_ho_cmd
2939 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
2940 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
2941 var RSL_IE_Body rsl_ho_cmd_l3;
2942 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
2943 log("RSL message contains no L3 Info IE, expected RR Handover Command");
2944 setverdict(fail);
2945 } else {
2946 log("Found L3 Info: ", rsl_ho_cmd_l3);
2947 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
2948 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
2949 setverdict(fail);
2950 } else {
2951 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
2952 setverdict(pass);
2953 }
2954 }
2955
2956 /* When the other BSS has reported a completed handover, this side is
2957 * torn down. */
2958
2959 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
2960 var BssmapCause cause := enum2int(cause_val);
2961 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
2962
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02002963 f_expect_dlcx_conns(true);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002964 setverdict(pass);
2965 f_sleep(1.0);
2966}
2967testcase TC_ho_out_of_this_bsc() runs on test_CT {
2968 var MSC_ConnHdlr vc_conn;
2969
2970 f_init(1, true);
2971 f_sleep(1.0);
2972
2973 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
2974 vc_conn.done;
2975}
2976
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002977/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
2978 * simply never sends a BSSMAP Handover Command. */
2979private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01002980 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002981
2982 var PDU_BSSAP ass_req := f_gen_ass_req();
2983 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2984 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2985 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2986 f_establish_fully(ass_req, exp_compl);
2987
2988 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2989
2990 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2991
2992 /* osmo-bsc should time out 10 seconds after the handover started.
2993 * Let's give it a bit extra. */
2994 f_sleep(15.0);
2995
2996 /* The old lchan and conn should still be active. See that arbitrary L3
2997 * is still going through. */
2998 var octetstring l3 := '0123456789'O;
2999 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
3000 var template PDU_BSSAP exp_data := {
3001 discriminator := '1'B,
3002 spare := '0000000'B,
3003 dlci := '00'O,
3004 lengthIndicator := 5,
3005 pdu := {
3006 dtap := l3
3007 }
3008 };
3009 BSSAP.receive(exp_data);
3010 setverdict(pass);
3011 f_sleep(1.0);
3012}
3013testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
3014 var MSC_ConnHdlr vc_conn;
3015
3016 f_init(1, true);
3017 f_sleep(1.0);
3018
3019 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
3020 vc_conn.done;
3021}
3022
3023/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
3024 * RR Handover Failure. */
3025private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01003026 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003027
3028 var PDU_BSSAP ass_req := f_gen_ass_req();
3029 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3030 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3031 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3032 f_establish_fully(ass_req, exp_compl);
3033
3034 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
3035
3036 BSSAP.receive(tr_BSSMAP_HandoverRequired);
3037
3038 f_sleep(0.5);
3039 /* The MSC negotiates Handover Request and Handover Request Ack with
3040 * the other BSS and comes back with a BSSMAP Handover Command
3041 * containing an RR Handover Command coming from the target BSS... */
3042
3043 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
3044 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
3045 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
3046 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
3047 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
3048
3049 /* expect the Handover Command to go out on RR */
3050 var RSL_Message rsl_ho_cmd
3051 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
3052 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
3053 var RSL_IE_Body rsl_ho_cmd_l3;
3054 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
3055 log("RSL message contains no L3 Info IE, expected RR Handover Command");
3056 setverdict(fail);
3057 } else {
3058 log("Found L3 Info: ", rsl_ho_cmd_l3);
3059 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
3060 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
3061 setverdict(fail);
3062 } else {
3063 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
3064 setverdict(pass);
3065 }
3066 }
3067
3068 f_sleep(0.2);
3069 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
3070
3071 /* Should tell the MSC about the failure */
3072 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3073
3074 f_sleep(1.0);
3075
3076 /* The old lchan and conn should still be active. See that arbitrary L3
3077 * is still going through. */
3078 var octetstring l3 := '0123456789'O;
3079 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
3080 var template PDU_BSSAP exp_data := {
3081 discriminator := '1'B,
3082 spare := '0000000'B,
3083 dlci := '00'O,
3084 lengthIndicator := 5,
3085 pdu := {
3086 dtap := l3
3087 }
3088 };
3089 BSSAP.receive(exp_data);
3090 setverdict(pass);
3091 f_sleep(1.0);
3092
3093 setverdict(pass);
3094 f_sleep(1.0);
3095}
3096testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
3097 var MSC_ConnHdlr vc_conn;
3098
3099 f_init(1, true);
3100 f_sleep(1.0);
3101
3102 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
3103 vc_conn.done;
3104}
3105
3106/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
3107 * RR Handover Failure. */
3108private function f_tc_ho_out_fail_no_ho_detect(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01003109 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003110
3111 var PDU_BSSAP ass_req := f_gen_ass_req();
3112 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3113 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3114 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3115 f_establish_fully(ass_req, exp_compl);
3116
3117 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
3118
3119 BSSAP.receive(tr_BSSMAP_HandoverRequired);
3120
3121 f_sleep(0.5);
3122 /* The MSC negotiates Handover Request and Handover Request Ack with
3123 * the other BSS and comes back with a BSSMAP Handover Command
3124 * containing an RR Handover Command coming from the target BSS... */
3125
3126 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
3127 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
3128 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
3129 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
3130 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
3131
3132 /* expect the Handover Command to go out on RR */
3133 var RSL_Message rsl_ho_cmd
3134 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
3135 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
3136 var RSL_IE_Body rsl_ho_cmd_l3;
3137 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
3138 log("RSL message contains no L3 Info IE, expected RR Handover Command");
3139 setverdict(fail);
3140 } else {
3141 log("Found L3 Info: ", rsl_ho_cmd_l3);
3142 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
3143 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
3144 setverdict(fail);
3145 } else {
3146 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
3147 setverdict(pass);
3148 }
3149 }
3150
3151 /* The MS never shows up on the remote BSS. Eventually the BSC times
3152 * out and we run into 3GPP TS 48.008 3.1.5.3.3 "Abnormal Conditions":
3153 * RR should be released and Clear Request should go to the MSC. */
3154
3155 var MgcpCommand mgcp;
3156 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01003157 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
3158 log("Got Deact SACCH");
3159 }
Harald Welte924b6ea2019-02-04 01:05:34 +01003160 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01003161 log("Got RR Release");
3162 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003163 [] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
3164 log("Got RF Chan Rel");
3165 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
3166 }
3167 [] BSSAP.receive(tr_BSSMAP_ClearRequest) {
3168 log("Got BSSMAP Clear Request");
3169 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003170 }
3171
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02003172 f_expect_dlcx_conns(false);
3173
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003174 setverdict(pass);
3175 f_sleep(1.0);
3176}
3177testcase TC_ho_out_fail_no_ho_detect() runs on test_CT {
3178 var MSC_ConnHdlr vc_conn;
3179
3180 f_init(1, true);
3181 f_sleep(1.0);
3182
3183 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_ho_detect));
3184 vc_conn.done;
3185}
3186
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003187private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
3188 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
3189 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
3190 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
3191 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
3192 * before we get started. */
3193 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3194 f_rslem_register(0, new_chan_nr);
3195 g_chan_nr := new_chan_nr;
3196 f_sleep(1.0);
3197
3198 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3199 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3200 activate(as_Media());
3201
3202 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3203 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003204 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003205
3206 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3207
3208 var PDU_BSSAP rx_bssap;
3209 var octetstring ho_command_str;
3210
3211 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
Pau Espin Pedrol76ba5412019-06-10 11:00:33 +02003212
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003213 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3214 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3215 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3216 log("L3 Info in HO Request Ack is ", ho_command);
3217
3218 var GsmArfcn arfcn;
3219 var RslChannelNr actual_new_chan_nr;
3220 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3221 actual_new_chan_nr, arfcn);
3222
3223 if (actual_new_chan_nr != new_chan_nr) {
3224 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3225 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3226 setverdict(fail);
3227 return;
3228 }
3229 log("Handover Command chan_nr is", actual_new_chan_nr);
3230
3231 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3232 * tells the MS to handover to the new lchan. Here comes the new MS on
3233 * the new lchan with a Handover RACH: */
3234
3235 /* send handover detect */
3236
3237 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
3238
3239 BSSAP.receive(tr_BSSMAP_HandoverDetect);
3240
3241 /* send handover complete over the new channel */
3242
3243 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
3244 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
3245 enc_PDU_ML3_MS_NW(l3_tx)));
3246
3247 BSSAP.receive(tr_BSSMAP_HandoverComplete);
3248 setverdict(pass);
3249}
3250testcase TC_ho_into_this_bsc() runs on test_CT {
3251 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003252 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003253
3254 f_init(1, true);
3255 f_sleep(1.0);
3256
3257 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3258 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3259
3260 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
3261 vc_conn.done;
3262}
3263
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003264private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
3265 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3266 f_rslem_register(0, new_chan_nr);
3267 g_chan_nr := new_chan_nr;
3268 f_sleep(1.0);
3269
3270 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3271 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3272 activate(as_Media());
3273
3274 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3275 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003276 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003277
3278 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3279
3280 var PDU_BSSAP rx_bssap;
3281 var octetstring ho_command_str;
3282
3283 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3284
3285 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3286 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3287 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3288 log("L3 Info in HO Request Ack is ", ho_command);
3289
3290 var GsmArfcn arfcn;
3291 var RslChannelNr actual_new_chan_nr;
3292 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3293 actual_new_chan_nr, arfcn);
3294
3295 if (actual_new_chan_nr != new_chan_nr) {
3296 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3297 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3298 setverdict(fail);
3299 return;
3300 }
3301 log("Handover Command chan_nr is", actual_new_chan_nr);
3302
Neels Hofmeyr61ca08d2019-05-06 23:52:22 +02003303 /* For deterministic test results, give some time for the MGW endpoint to be configured */
3304 f_sleep(1.0);
3305
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003306 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3307 * tells the MS to handover to the new lchan. In this case, the MS
3308 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
3309 * Handover Failure to the MSC. The procedure according to 3GPP TS
3310 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
3311 * BSSMAP Clear Command: */
3312
3313 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3314 var BssmapCause cause := enum2int(cause_val);
3315 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3316
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02003317 f_expect_dlcx_conns(true);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003318 setverdict(pass);
3319 f_sleep(1.0);
3320
3321 setverdict(pass);
3322}
3323testcase TC_ho_in_fail_msc_clears() runs on test_CT {
3324 var MSC_ConnHdlr vc_conn;
3325 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3326
3327 f_init(1, true);
3328 f_sleep(1.0);
3329
3330 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3331 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3332
3333 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
3334 vc_conn.done;
3335}
3336
3337private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
3338 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
3339 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
3340 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
3341 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
3342 * before we get started. */
3343 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3344 f_rslem_register(0, new_chan_nr);
3345 g_chan_nr := new_chan_nr;
3346 f_sleep(1.0);
3347
3348 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3349 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3350 activate(as_Media());
3351
3352 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3353 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003354 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003355
3356 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3357
3358 var PDU_BSSAP rx_bssap;
3359 var octetstring ho_command_str;
3360
3361 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3362
3363 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3364 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3365 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3366 log("L3 Info in HO Request Ack is ", ho_command);
3367
3368 var GsmArfcn arfcn;
3369 var RslChannelNr actual_new_chan_nr;
3370 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3371 actual_new_chan_nr, arfcn);
3372
3373 if (actual_new_chan_nr != new_chan_nr) {
3374 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3375 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3376 setverdict(fail);
3377 return;
3378 }
3379 log("Handover Command chan_nr is", actual_new_chan_nr);
3380
3381 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3382 * tells the MS to handover to the new lchan. Here comes the new MS on
3383 * the new lchan with a Handover RACH: */
3384
3385 /* send handover detect */
3386
3387 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
3388
3389 BSSAP.receive(tr_BSSMAP_HandoverDetect);
3390
3391 /* The MSC chooses to clear the connection now, maybe we got the
3392 * Handover RACH on the new cell but the MS still signaled Handover
3393 * Failure to the old BSS? */
3394
3395 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3396 var BssmapCause cause := enum2int(cause_val);
3397 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3398
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02003399 f_expect_dlcx_conns(true);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003400 setverdict(pass);
3401 f_sleep(1.0);
3402}
3403testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
3404 var MSC_ConnHdlr vc_conn;
3405 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3406
3407 f_init(1, true);
3408 f_sleep(1.0);
3409
3410 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3411 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3412
3413 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
3414 vc_conn.done;
3415}
3416
3417/* The new BSS's lchan times out before the MSC decides that handover failed. */
3418private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
3419 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3420 f_rslem_register(0, new_chan_nr);
3421 g_chan_nr := new_chan_nr;
3422 f_sleep(1.0);
3423
3424 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3425 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3426 activate(as_Media());
3427
3428 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3429 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003430 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003431
3432 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3433
3434 var PDU_BSSAP rx_bssap;
3435 var octetstring ho_command_str;
3436
3437 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3438
3439 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3440 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3441 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3442 log("L3 Info in HO Request Ack is ", ho_command);
3443
3444 var GsmArfcn arfcn;
3445 var RslChannelNr actual_new_chan_nr;
3446 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3447 actual_new_chan_nr, arfcn);
3448
3449 if (actual_new_chan_nr != new_chan_nr) {
3450 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3451 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3452 setverdict(fail);
3453 return;
3454 }
3455 log("Handover Command chan_nr is", actual_new_chan_nr);
3456
3457 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3458 * tells the MS to handover to the new lchan. But the MS never shows up
3459 * on the new lchan. */
3460
3461 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3462
3463 /* Did osmo-bsc also send a Clear Request? */
3464 timer T := 0.5;
3465 T.start;
3466 alt {
3467 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
3468 [] T.timeout { }
3469 }
3470
3471 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
3472 * asked for it, this is a Handover Failure after all). */
3473
3474 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3475 var BssmapCause cause := enum2int(cause_val);
3476 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3477
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02003478 f_expect_dlcx_conns(true);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003479 setverdict(pass);
3480 f_sleep(1.0);
3481
3482 setverdict(pass);
3483}
3484testcase TC_ho_in_fail_no_detect() runs on test_CT {
3485 var MSC_ConnHdlr vc_conn;
3486 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3487
3488 f_init(1, true);
3489 f_sleep(1.0);
3490
3491 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3492 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3493
3494 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
3495 vc_conn.done;
3496}
3497
3498/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
3499private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
3500 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3501 f_rslem_register(0, new_chan_nr);
3502 g_chan_nr := new_chan_nr;
3503 f_sleep(1.0);
3504
3505 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3506 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3507 activate(as_Media());
3508
3509 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3510 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003511 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003512
3513 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3514
3515 var PDU_BSSAP rx_bssap;
3516 var octetstring ho_command_str;
3517
3518 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3519
3520 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3521 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3522 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3523 log("L3 Info in HO Request Ack is ", ho_command);
3524
3525 var GsmArfcn arfcn;
3526 var RslChannelNr actual_new_chan_nr;
3527 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3528 actual_new_chan_nr, arfcn);
3529
3530 if (actual_new_chan_nr != new_chan_nr) {
3531 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3532 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3533 setverdict(fail);
3534 return;
3535 }
3536 log("Handover Command chan_nr is", actual_new_chan_nr);
3537
3538 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3539 * tells the MS to handover to the new lchan. But the MS never shows up
3540 * on the new lchan. */
3541
3542 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3543
3544 /* MSC plays dumb and sends no Clear Command */
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003545 var PDU_BSSAP rx_clear_request;
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02003546
3547 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003548 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
3549 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3550 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02003551 f_expect_dlcx_conns(true);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003552 setverdict(pass);
3553 f_sleep(1.0);
3554}
3555testcase TC_ho_in_fail_no_detect2() runs on test_CT {
3556 var MSC_ConnHdlr vc_conn;
3557 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3558
3559 f_init(1, true);
3560 f_sleep(1.0);
3561
3562 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3563 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3564
3565 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
3566 vc_conn.done;
3567}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003568
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003569/* OS#3041: Open and close N connections in a normal fashion, and expect no
3570 * BSSMAP Reset just because of that. */
3571testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
3572 var default d;
3573 var integer i;
3574 var DchanTuple dt;
3575
3576 f_init();
3577
3578 /* Wait for initial BSSMAP Reset to pass */
3579 f_sleep(4.0);
3580
3581 d := activate(no_bssmap_reset());
3582
3583 /* Setup up a number of connections and RLSD them again from the MSC
3584 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3585 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02003586 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003587 /* Since we're doing a lot of runs, give each one a fresh
3588 * T_guard from the top. */
3589 T_guard.start;
3590
3591 /* Setup a BSSAP connection and clear it right away. This is
3592 * the MSC telling the BSC about a planned release, it's not an
3593 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02003594 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003595
3596 /* MSC disconnects (RLSD). */
3597 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
3598 }
3599
3600 /* In the buggy behavior, a timeout of 2 seconds happens between above
3601 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3602 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3603 f_sleep(4.0);
3604
3605 deactivate(d);
3606 f_shutdown_helper();
3607}
Harald Welte552620d2017-12-16 23:21:36 +01003608
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003609/* OS#3041: Open and close N connections in a normal fashion, and expect no
3610 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
3611 * the MSC. */
3612testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
3613 var default d;
3614 var integer i;
3615 var DchanTuple dt;
3616 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003617 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
3618 var BssmapCause cause := enum2int(cause_val);
3619
3620 f_init();
3621
3622 /* Wait for initial BSSMAP Reset to pass */
3623 f_sleep(4.0);
3624
3625 d := activate(no_bssmap_reset());
3626
3627 /* Setup up a number of connections and RLSD them again from the MSC
3628 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3629 * Let's do it some more times for good measure. */
3630 for (i := 0; i < 8; i := i+1) {
3631 /* Since we're doing a lot of runs, give each one a fresh
3632 * T_guard from the top. */
3633 T_guard.start;
3634
3635 /* Setup a BSSAP connection and clear it right away. This is
3636 * the MSC telling the BSC about a planned release, it's not an
3637 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02003638 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003639
3640 /* Instruct BSC to clear channel */
3641 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
3642
3643 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02003644 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003645 }
3646
3647 /* In the buggy behavior, a timeout of 2 seconds happens between above
3648 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3649 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3650 f_sleep(4.0);
3651
3652 deactivate(d);
3653 f_shutdown_helper();
3654}
3655
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003656/* OS#3041: Open and close N connections in a normal fashion, and expect no
3657 * BSSMAP Reset just because of that. Close connections from the MS side with a
3658 * Release Ind on RSL. */
3659testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
3660 var default d;
3661 var integer i;
3662 var DchanTuple dt;
3663 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003664 var integer j;
3665
3666 f_init();
3667
3668 /* Wait for initial BSSMAP Reset to pass */
3669 f_sleep(4.0);
3670
3671 d := activate(no_bssmap_reset());
3672
3673 /* Setup up a number of connections and RLSD them again from the MSC
3674 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3675 * Let's do it some more times for good measure. */
3676 for (i := 0; i < 8; i := i+1) {
3677 /* Since we're doing a lot of runs, give each one a fresh
3678 * T_guard from the top. */
3679 T_guard.start;
3680
3681 /* Setup a BSSAP connection and clear it right away. This is
3682 * the MSC telling the BSC about a planned release, it's not an
3683 * erratic loss of a connection. */
3684 dt := f_est_dchan('23'O, 23, '00010203040506'O);
3685
3686 /* simulate RLL REL IND */
3687 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
3688
3689 /* expect Clear Request on MSC side */
3690 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
3691
3692 /* Instruct BSC to clear channel */
3693 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
3694 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
3695
3696 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02003697 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003698 }
3699
3700 /* In the buggy behavior, a timeout of 2 seconds happens between above
3701 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3702 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3703 f_sleep(4.0);
3704
3705 deactivate(d);
3706 f_shutdown_helper();
3707}
3708
Harald Welte94e0c342018-04-07 11:33:23 +02003709/***********************************************************************
3710 * IPA style dynamic PDCH
3711 ***********************************************************************/
3712
3713private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
3714 template (omit) RSL_Cause nack := omit)
3715runs on test_CT {
3716 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
3717 var RSL_Message rsl_unused;
3718 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3719 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
3720 /* expect the BSC to issue the related RSL command */
3721 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3722 if (istemplatekind(nack, "omit")) {
3723 /* respond with a related acknowledgement */
3724 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3725 } else {
3726 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
3727 }
3728}
3729
3730private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
3731 template (omit) RSL_Cause nack := omit)
3732runs on test_CT {
3733 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
3734 var RSL_Message rsl_unused;
3735 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3736 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
3737 /* expect the BSC to issue the related RSL command */
3738 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
3739 if (istemplatekind(nack, "omit")) {
3740 /* respond with a related acknowledgement */
3741 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
3742 } else {
3743 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
3744 }
3745}
3746
3747private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
3748runs on test_CT return charstring {
3749 var charstring cmd, resp;
3750 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01003751 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02003752}
3753
3754private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
3755 template charstring exp)
3756runs on test_CT {
3757 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
3758 if (not match(mode, exp)) {
3759 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02003760 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02003761 }
3762}
3763
3764private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
3765runs on test_CT {
3766 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
3767 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
3768 f_vty_transceive(BSCVTY, "end");
3769}
3770
3771private const charstring TCHF_MODE := "TCH/F mode";
3772private const charstring TCHH_MODE := "TCH/H mode";
3773private const charstring PDCH_MODE := "PDCH mode";
3774private const charstring NONE_MODE := "NONE mode";
3775
3776/* Test IPA PDCH activation / deactivation triggered by VTY */
3777testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
3778 var RSL_Message rsl_unused;
3779
3780 /* change Timeslot 6 before f_init() starts RSL */
3781 f_init_vty();
3782 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
3783 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3784
3785 f_init(1, false);
3786 f_sleep(1.0);
3787
3788 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
3789
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003790 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003791 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3792 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3793 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3794 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3795 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003796 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003797 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3798
3799 /* De-activate it via VTY */
3800 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3801 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003802 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003803 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3804
3805 /* re-activate it via VTY */
3806 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
3807 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003808 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003809 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3810
3811 /* and finally de-activate it again */
3812 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3813 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003814 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003815 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3816
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003817 /* clean up config */
3818 f_ts_set_chcomb(0, 0, 6, "PDCH");
3819
Harald Welte94e0c342018-04-07 11:33:23 +02003820 setverdict(pass);
3821}
3822
3823/* Test IPA PDCH activation NACK */
3824testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
3825 var RSL_Message rsl_unused;
3826
3827 /* change Timeslot 6 before f_init() starts RSL */
3828 f_init_vty();
3829 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
3830 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3831
3832 f_init(1, false);
3833 f_sleep(1.0);
3834
3835 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
3836
3837 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3838 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3839 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3840 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3841 f_sleep(1.0);
3842 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3843
3844 /* De-activate it via VTY */
3845 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3846 f_sleep(1.0);
3847 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3848
3849 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
3850 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
3851 f_sleep(1.0);
3852 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3853
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003854 /* clean up config */
3855 f_ts_set_chcomb(0, 0, 6, "PDCH");
3856
Harald Welte94e0c342018-04-07 11:33:23 +02003857 setverdict(pass);
3858}
3859
3860
3861/***********************************************************************
3862 * Osmocom style dynamic PDCH
3863 ***********************************************************************/
3864
3865private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
3866 template (omit) RSL_Cause nack := omit)
3867runs on test_CT {
3868 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
3869 var RSL_Message rsl_unused;
3870 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3871 /* FIXME: no VTY command to activate Osmocom PDCH !! */
3872 /* expect the BSC to issue the related RSL command */
3873 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
3874 if (istemplatekind(nack, "omit")) {
3875 /* respond with a related acknowledgement */
3876 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
3877 } else {
3878 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
3879 }
3880}
3881
3882private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
3883 template (omit) RSL_Cause nack := omit)
3884runs on test_CT {
3885 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
3886 var RSL_Message rsl_unused;
3887 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3888 /* FIXME: no VTY command to activate Osmocom PDCH !! */
3889 /* expect the BSC to issue the related RSL command */
3890 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
3891 if (istemplatekind(nack, "omit")) {
3892 /* respond with a related acknowledgement */
3893 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
3894 } else {
3895 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
3896 }
3897}
3898
3899/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
3900testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
3901 var RSL_Message rsl_unused;
3902
3903 /* change Timeslot 6 before f_init() starts RSL */
3904 f_init_vty();
3905 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
3906 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3907
3908 f_init(1, false);
3909 f_sleep(1.0);
3910
3911 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
3912
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003913 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003914 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
3915 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3916 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
3917
3918 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
3919 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003920 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 +02003921 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3922
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003923 /* clean up config */
3924 f_ts_set_chcomb(0, 0, 6, "PDCH");
3925
Harald Welte94e0c342018-04-07 11:33:23 +02003926 setverdict(pass);
3927}
3928
3929/* Test Osmocom dyn PDCH activation NACK behavior */
3930testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
3931 var RSL_Message rsl_unused;
3932
3933 /* change Timeslot 6 before f_init() starts RSL */
3934 f_init_vty();
3935 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
3936 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3937
3938 f_init(1, false);
3939 f_sleep(1.0);
3940
3941 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
3942
3943 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
3944 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3945 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
3946
3947 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
3948 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
3949 f_sleep(1.0);
3950 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
3951
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003952 /* clean up config */
3953 f_ts_set_chcomb(0, 0, 6, "PDCH");
3954
Harald Welte94e0c342018-04-07 11:33:23 +02003955 setverdict(pass);
3956}
3957
Stefan Sperling0796a822018-10-05 13:01:39 +02003958testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02003959 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02003960 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
3961 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
3962 }
3963}
3964
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02003965testcase TC_chopped_ipa_payload() runs on test_CT {
3966 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
3967 /* TODO: mp_bsc_ctrl_port does not work yet */};
3968 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
3969 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
3970 }
3971}
3972
3973
Harald Welte0ea2d5e2018-04-07 21:40:29 +02003974/* Dyn PDCH todo:
3975 * activate OSMO as TCH/F
3976 * activate OSMO as TCH/H
3977 * does the BSC-located PCU socket get the updated INFO?
3978 * what if no PCU is connected at the time?
3979 * is the info correct on delayed PCU (re)connect?
3980 */
Harald Welte94e0c342018-04-07 11:33:23 +02003981
Harald Welte28d943e2017-11-25 15:00:50 +01003982control {
Harald Welte898113b2018-01-31 18:32:21 +01003983 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +01003984 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01003985 execute( TC_ctrl_msc0_connection_status() );
Harald Welte96c94412017-12-09 03:12:45 +01003986 execute( TC_ctrl() );
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02003987 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_SCCPlite_SERVER) {
3988 execute( TC_ctrl_location() );
3989 }
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}