blob: 2bc1c62adda0cd983207ca3e37d78ccbe9f18e19 [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;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +020041import from MGCP_CodecPort all;
Harald Welte28d943e2017-11-25 15:00:50 +010042
Harald Welte96c94412017-12-09 03:12:45 +010043import from Osmocom_CTRL_Functions all;
Harald Weltea5d2ab22017-12-09 14:21:42 +010044import from Osmocom_CTRL_Types all;
Harald Welteffe55fc2018-01-17 22:39:54 +010045import from Osmocom_CTRL_Adapter all;
Harald Welte96c94412017-12-09 03:12:45 +010046
Harald Weltebc03c762018-02-12 18:09:38 +010047import from Osmocom_VTY_Functions all;
48import from TELNETasp_PortType all;
49
Harald Welte6f521d82017-12-11 19:52:02 +010050import from MobileL3_CommonIE_Types all;
Harald Weltee3bd6582018-01-31 22:51:25 +010051import from MobileL3_Types all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010052import from MobileL3_RRM_Types all;
Harald Welte6f521d82017-12-11 19:52:02 +010053import from L3_Templates all;
54import from GSM_RR_Types all;
55
Stefan Sperlingc307e682018-06-14 15:15:46 +020056import from SCCP_Templates all;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010057import from BSSMAP_Templates all;
58
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010059import from SCCPasp_Types all;
60
Harald Welte5d1a2202017-12-13 19:51:29 +010061const integer NUM_BTS := 3;
Harald Welteae026692017-12-09 01:03:01 +010062const float T3101_MAX := 12.0;
Harald Welte28d943e2017-11-25 15:00:50 +010063
Harald Welte799c97b2017-12-14 17:50:30 +010064/* make sure to sync this with the osmo-bts.cfg you're using */
Philipp Maiercb6cc482018-03-26 13:08:00 +020065const integer NUM_TCHH_PER_BTS := 2;
66const integer NUM_TCHF_PER_BTS := 4;
Harald Weltedd8cbf32018-01-28 12:07:52 +010067const integer NUM_SDCCH_PER_BTS := 4;
Harald Welte799c97b2017-12-14 17:50:30 +010068
Harald Welte4003d112017-12-09 22:35:39 +010069
Harald Welte21b46bd2017-12-17 19:46:32 +010070/* per-BTS state which we keep */
Harald Welte96c94412017-12-09 03:12:45 +010071type record BTS_State {
Harald Welte21b46bd2017-12-17 19:46:32 +010072 /* component reference to the IPA_Client component used for RSL */
Harald Weltea5d2ab22017-12-09 14:21:42 +010073 IPA_Client rsl
Harald Welte96c94412017-12-09 03:12:45 +010074}
75
Harald Weltea4ca4462018-02-09 00:17:14 +010076type component test_CT extends CTRL_Adapter_CT {
Harald Welte21b46bd2017-12-17 19:46:32 +010077 /* Array of per-BTS state */
Harald Welte96c94412017-12-09 03:12:45 +010078 var BTS_State bts[NUM_BTS];
Harald Welte89ab1912018-02-23 18:56:29 +010079 /* RSL common Channel Port (for RSL_Emulation) */
80 port RSL_CCHAN_PT RSL_CCHAN[NUM_BTS];
Harald Welte21b46bd2017-12-17 19:46:32 +010081 /* array of per-BTS RSL test ports */
Harald Welteae026692017-12-09 01:03:01 +010082 port IPA_RSL_PT IPA_RSL[NUM_BTS];
Stefan Sperling830dc9d2018-02-12 21:08:28 +010083 port IPA_CODEC_PT IPA; /* Required for compilation of TC_rsl_unknown_unit_id() */
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +020084 /* CTRL muxed over IPA in SCCPlite conn BSC<->MSC (or BSC-NAT) */
85 port IPA_CTRL_PT SCCPLITE_IPA_CTRL;
Harald Weltea5d2ab22017-12-09 14:21:42 +010086
Daniel Willmann191e0d92018-01-17 12:44:35 +010087 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +010088 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +010089
Harald Welte6811d102019-04-14 22:23:14 +020090 var RAN_Adapter g_bssap;
Harald Weltea4ca4462018-02-09 00:17:14 +010091 /* for old legacy-tests only */
92 port BSSAP_CODEC_PT BSSAP;
93
Harald Welte21b46bd2017-12-17 19:46:32 +010094 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +010095 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +010096
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +020097 /* Osmux is enabled through VTY */
98 var boolean g_osmux_enabled := false;
99
Harald Welte21b46bd2017-12-17 19:46:32 +0100100 /* global test case guard timer */
Harald Welteae026692017-12-09 01:03:01 +0100101 timer T_guard := 30.0;
102
Harald Welte28d943e2017-11-25 15:00:50 +0100103}
104
105modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +0100106 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +0100107 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100108 /* port number to which to establish the IPA OML connections */
109 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +0100110 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +0100111 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +0100112 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +0100113 integer mp_bsc_ctrl_port := 4249;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100114 /* IP address at which the test binds */
115 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100116
Harald Welte6811d102019-04-14 22:23:14 +0200117 RAN_Configuration mp_bssap_cfg := {
Harald Welte7ef51aa2018-04-16 19:16:01 +0200118 transport := BSSAP_TRANSPORT_AoIP,
Harald Weltea4ca4462018-02-09 00:17:14 +0100119 sccp_service_type := "mtp3_itu",
120 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
121 own_pc := 185,
122 own_ssn := 254,
123 peer_pc := 187,
124 peer_ssn := 254,
Philipp Maier38d68942018-03-29 15:38:09 +0200125 sio := '83'O,
126 rctx := 0
Harald Weltea4ca4462018-02-09 00:17:14 +0100127 };
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +0200128
129 /* Whether to enable osmux tests. Can be dropped completely and enable
130 unconditionally once new version of osmo-bsc is released (current
131 version: 1.4.1) */
132 boolean mp_enable_osmux_test := true;
Harald Weltea4ca4462018-02-09 00:17:14 +0100133}
134
Philipp Maier48604732018-10-09 15:00:37 +0200135private function f_gen_test_hdlr_pars() return TestHdlrParams {
136
137 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
138 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
139 pars.aoip := true;
140 } else {
141 pars.aoip := false;
142 }
143
144 return pars;
145}
146
Philipp Maier282ca4b2018-02-27 17:17:00 +0100147private function f_shutdown_helper() runs on test_CT {
Daniel Willmann637ef6c2018-07-25 10:49:09 +0200148 all component.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100149 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200150 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100151}
152
Harald Weltea4ca4462018-02-09 00:17:14 +0100153private function f_legacy_bssap_reset() runs on test_CT {
154 var BSSAP_N_UNITDATA_ind ud_ind;
155 timer T := 5.0;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200156 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 +0100157 T.start;
158 alt {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200159 [] 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 +0100160 log("Received RESET-ACK in response to RESET, we're ready to go!");
161 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200162 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Weltea4ca4462018-02-09 00:17:14 +0100163 log("Respoding to inbound RESET with RESET-ACK");
164 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200165 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Weltea4ca4462018-02-09 00:17:14 +0100166 repeat;
167 }
168 [] BSSAP.receive { repeat; }
169 [] T.timeout { setverdict(fail, "Waiting for RESET-ACK after sending RESET"); }
170 }
Harald Welte28d943e2017-11-25 15:00:50 +0100171}
172
Harald Welteae026692017-12-09 01:03:01 +0100173type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100174 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100175 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100176 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100177 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100178 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100179 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100180 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100181 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100182}
183
Harald Welte21b46bd2017-12-17 19:46:32 +0100184/*! Start the IPA/RSL related bits for one IPA_Client.
185 * \param clnt IPA_Client for which to establish
186 * \param bsc_host IP address / hostname of the BSC
187 * \param bsc_port TCP port number of the BSC
188 * \param i number identifying this BTS
189 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100190function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
191 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100192runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100193 timer T := 10.0;
194
Harald Welte96c94412017-12-09 03:12:45 +0100195 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welteae026692017-12-09 01:03:01 +0100196 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA");
197 clnt.ccm_pars := c_IPA_default_ccm_pars;
198 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
199 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100200 if (handler_mode) {
201 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL");
Harald Welte89ab1912018-02-23 18:56:29 +0100202 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100203 }
Harald Welteae026692017-12-09 01:03:01 +0100204
205 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Harald Welte624f9632017-12-16 19:26:04 +0100206 if (handler_mode) {
207 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
208 } else {
209 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
210 }
Harald Welteae026692017-12-09 01:03:01 +0100211
Harald Welte5d1a2202017-12-13 19:51:29 +0100212 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100213 if (handler_mode) {
214 clnt.vc_RSL.start(RSL_Emulation.main());
215 return;
216 }
Harald Welteae026692017-12-09 01:03:01 +0100217
218 /* wait for IPA RSL link to connect and send ID ACK */
219 T.start;
220 alt {
221 [] IPA_RSL[i].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_ID_ACK}) {
222 T.stop;
223 IPA_RSL[i].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_PAGING_LOAD_IND(23)));
224 }
Harald Welte60e823a2017-12-10 14:10:59 +0100225 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100226 [] IPA_RSL[i].receive { repeat }
227 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100228 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200229 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100230 }
231 }
232}
233
Harald Welte12055472018-03-17 20:10:08 +0100234function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
235 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
236 return;
237 }
238 clnt.vc_IPA.stop;
239 if (isbound(clnt.vc_RSL)) {
240 clnt.vc_RSL.stop;
241 }
242}
243
Harald Welte21b46bd2017-12-17 19:46:32 +0100244/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100245function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
246 timer T := secs_max;
247 T.start;
248 while (true) {
249 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
250 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100251 /* the 'degraded' state exists from OML connection time, and we have to wait
252 * until all MO's are initialized */
253 T.start(1.0);
254 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100255 return;
256 }
Harald Weltef0d6ac62017-12-17 17:02:21 +0100257 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100258 if (not T.running) {
Max99253902018-11-16 17:57:39 +0100259 setverdict(fail, "Timeout waiting for BTS" & int2str(bts_nr) & " oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +0200260 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100261 }
262 }
263}
264
Harald Welte21b46bd2017-12-17 19:46:32 +0100265/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +0100266altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +0100267 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100268 [] T_guard.timeout {
269 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +0200270 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100271 }
Harald Welte60e823a2017-12-10 14:10:59 +0100272 /* always respond with RESET ACK to RESET */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200273 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Welte60e823a2017-12-10 14:10:59 +0100274 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200275 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Welte69c1c262017-12-13 21:02:08 +0100276 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +0100277 }
Harald Welte28d943e2017-11-25 15:00:50 +0100278}
279
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100280altstep no_bssmap_reset() runs on test_CT {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200281 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100282 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +0200283 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100284 }
285}
286
Daniel Willmann191e0d92018-01-17 12:44:35 +0100287function f_init_mgcp(charstring id) runs on test_CT {
288 id := id & "-MGCP";
289
290 var MGCPOps ops := {
291 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
292 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
293 };
294 var MGCP_conn_parameters mgcp_pars := {
295 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +0100296 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +0100297 mgw_ip := mp_test_ip,
Pau Espin Pedrol1a026a52019-06-18 17:21:52 +0200298 mgw_udp_port := 2427,
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200299 /* Enable it for SCCPlite, since we have 2 MGCP sockets towards MGW (UDP one +
300 the on with MGCP over IPA forwarded from MSC one) */
301 multi_conn_mode := (mp_bssap_cfg.transport == BSSAP_TRANSPORT_SCCPlite_SERVER)
Daniel Willmann191e0d92018-01-17 12:44:35 +0100302 };
303
304 vc_MGCP := MGCP_Emulation_CT.create(id);
305 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
306}
307
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200308/* Enable or disable (current default) Osmux. When enabling, BSSMAP Reset
309 * contains extra IE (OsmuxSupport) and osmo-bsc will handle AssignReq with
310 * OsmuxCID IE.
311 */
312private function f_vty_allow_osmux(boolean allow) runs on test_CT {
313 f_vty_enter_cfg_msc(BSCVTY, 0);
314 if (allow) {
315 f_vty_transceive(BSCVTY, "osmux on");
316 } else {
317 f_vty_transceive(BSCVTY, "osmux off");
318 }
319 f_vty_transceive(BSCVTY, "exit");
320 f_vty_transceive(BSCVTY, "exit");
321 g_osmux_enabled := allow;
322}
323
Max2253c0b2018-11-06 19:28:05 +0100324function f_init_vty(charstring id := "foo") runs on test_CT {
Harald Welte94e0c342018-04-07 11:33:23 +0200325 if (BSCVTY.checkstate("Mapped")) {
326 /* skip initialization if already executed once */
327 return;
328 }
Harald Weltebc03c762018-02-12 18:09:38 +0100329 map(self:BSCVTY, system:BSCVTY);
330 f_vty_set_prompts(BSCVTY);
331 f_vty_transceive(BSCVTY, "enable");
332}
333
Harald Welte21b46bd2017-12-17 19:46:32 +0100334/* global initialization function
335 * \param nr_bts Number of BTSs we should start/bring up
336 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200337function 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 +0100338 var integer i;
Harald Welte28d943e2017-11-25 15:00:50 +0100339
Harald Welteae026692017-12-09 01:03:01 +0100340 if (g_initialized) {
341 return;
Harald Welte28d943e2017-11-25 15:00:50 +0100342 }
Harald Welteae026692017-12-09 01:03:01 +0100343 g_initialized := true;
344
Daniel Willmanne68f9272018-11-27 15:15:28 +0100345 T_guard.start;
346 activate(as_Tguard());
347
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200348 f_init_vty("VirtMSC");
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +0200349 if (mp_enable_osmux_test) {
350 f_vty_allow_osmux(allow_osmux);
351 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200352
Harald Welte6811d102019-04-14 22:23:14 +0200353 /* Call a function of our 'parent component' RAN_Adapter_CT to start the
Harald Welteae026692017-12-09 01:03:01 +0100354 * MSC-side BSSAP emulation */
Harald Welte67089ee2018-01-17 22:19:03 +0100355 if (handler_mode) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200356 var RanOps ranops := MSC_RanOps;
357 ranops.use_osmux := g_osmux_enabled;
358 f_ran_adapter_init(g_bssap, mp_bssap_cfg, "VirtMSC", ranops);
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +0200359 connect(self:SCCPLITE_IPA_CTRL, g_bssap.vc_RAN:CTRL_CLIENT);
Harald Welte3ca0ce12019-04-23 17:18:48 +0200360 f_ran_adapter_start(g_bssap);
Harald Welte67089ee2018-01-17 22:19:03 +0100361 } else {
Harald Welte3ca0ce12019-04-23 17:18:48 +0200362 f_ran_adapter_init(g_bssap, mp_bssap_cfg, "VirtMSC", omit);
Harald Weltea4ca4462018-02-09 00:17:14 +0100363 connect(self:BSSAP, g_bssap.vc_SCCP:SCCP_SP_PORT);
Harald Welte3ca0ce12019-04-23 17:18:48 +0200364 f_ran_adapter_start(g_bssap);
Harald Weltea4ca4462018-02-09 00:17:14 +0100365 f_legacy_bssap_reset();
Harald Welte67089ee2018-01-17 22:19:03 +0100366 }
Harald Welted5833a82018-05-27 16:52:56 +0200367
Harald Welteffe55fc2018-01-17 22:39:54 +0100368 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +0100369
Daniel Willmann191e0d92018-01-17 12:44:35 +0100370 f_init_mgcp("VirtMSC");
371
Harald Welte89d42e82017-12-17 16:42:41 +0100372 for (i := 0; i < nr_bts; i := i+1) {
Harald Weltea5d2ab22017-12-09 14:21:42 +0100373 /* wait until osmo-bts-omldummy has respawned */
374 f_wait_oml(i, "degraded", 5.0);
375 /* start RSL connection */
Harald Welte624f9632017-12-16 19:26:04 +0100376 f_ipa_rsl_start(bts[i].rsl, mp_bsc_ip, mp_bsc_rsl_port, i, handler_mode);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100377 /* wait until BSC tells us "connected" */
378 f_wait_oml(i, "connected", 5.0);
Harald Welte696ddb62017-12-08 14:01:43 +0100379 }
380
Harald Welte28d943e2017-11-25 15:00:50 +0100381}
382
Maxd4e56962018-10-31 19:08:25 +0100383/* expect to receive a RSL message matching a specified template on a given BTS / stream */
Harald Welteae026692017-12-09 01:03:01 +0100384function f_exp_ipa_rx(integer bts_nr, template RSL_Message t_rx, float t_secs := 2.0, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
385runs on test_CT return RSL_Message {
386 var ASP_RSL_Unitdata rx_rsl_ud;
387 timer T := t_secs;
388
389 T.start;
390 alt {
391 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(sid, t_rx)) -> value rx_rsl_ud {
392 T.stop;
393 }
394 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +0100395 [] T.timeout {
396 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +0200397 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +0100398 }
Harald Welteae026692017-12-09 01:03:01 +0100399 }
400 return rx_rsl_ud.rsl;
401}
402
Harald Welte21b46bd2017-12-17 19:46:32 +0100403/* helper function to transmit RSL on a given BTS/stream */
Harald Welteae026692017-12-09 01:03:01 +0100404function f_ipa_tx(integer bts_nr, template RSL_Message t_tx, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
405runs on test_CT {
406 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(sid, t_tx));
407}
408
409
Harald Welte4003d112017-12-09 22:35:39 +0100410/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +0100411testcase TC_chan_act_noreply() runs on test_CT {
412 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +0100413 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +0100414
Harald Welte89d42e82017-12-17 16:42:41 +0100415 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +0100416
Harald Welteae026692017-12-09 01:03:01 +0100417 IPA_RSL[0].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +0100418 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welteae026692017-12-09 01:03:01 +0100419 setverdict(pass);
Harald Welte28d943e2017-11-25 15:00:50 +0100420}
421
Harald Welte4003d112017-12-09 22:35:39 +0100422/* verify if the "chreq:total" counter increments as expected */
423testcase TC_chan_act_counter() runs on test_CT {
424 var BSSAP_N_UNITDATA_ind ud_ind;
425 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +0100426 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +0100427
Harald Welte89d42e82017-12-17 16:42:41 +0100428 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100429
430 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
431 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 +0100432 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welte4003d112017-12-09 22:35:39 +0100433 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total", chreq_total+1);
434
435 setverdict(pass);
436}
437
Harald Welteae026692017-12-09 01:03:01 +0100438/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
439testcase TC_chan_act_ack_noest() runs on test_CT {
440 var RSL_Message rx_rsl;
441
Harald Welte89d42e82017-12-17 16:42:41 +0100442 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100443
444 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100445 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100446
447 /* expect BSC to disable the channel again if there's no RLL EST IND */
448 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
449
450 setverdict(pass);
451}
452
453/* Test behavior if MSC never answers to CR */
454testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +0100455 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
456 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +0100457 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +0100458 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +0100459
Harald Welte89d42e82017-12-17 16:42:41 +0100460 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100461
462 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100463 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100464
465 var octetstring l3 := '00010203040506'O
466 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
467
468 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
469
470 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +0100471 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100472 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Harald Welteae026692017-12-09 01:03:01 +0100473 setverdict(pass);
474}
475
476/* Test behavior if MSC answers with CREF to CR */
477testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
478 var BSSAP_N_CONNECT_ind rx_c_ind;
479 var RSL_Message rx_rsl;
480
Harald Welte89d42e82017-12-17 16:42:41 +0100481 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100482
483 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100484 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100485
486 var octetstring l3 := '00010203040506'O
487 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
488
489 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
490 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
491
492 /* expect BSC to disable the channel */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100493 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Harald Welteae026692017-12-09 01:03:01 +0100494 setverdict(pass);
495}
496
Harald Welte618ef642017-12-14 14:58:20 +0100497/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
498testcase TC_chan_act_nack() runs on test_CT {
499 var RSL_Message rx_rsl;
500 var integer chact_nack;
501
Harald Welte89d42e82017-12-17 16:42:41 +0100502 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +0100503
504 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
505
506 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
507 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
508 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
509
510 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
511
512 /* wait for some time to hope the NACK arrives before the CTRL GET below */
513 f_sleep(0.5);
514
515 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
516
517 setverdict(pass);
518}
519
Harald Welte799c97b2017-12-14 17:50:30 +0100520/* Test for channel exhaustion due to RACH overload */
521testcase TC_chan_exhaustion() runs on test_CT {
522 var ASP_RSL_Unitdata rsl_ud;
523 var integer i;
524 var integer chreq_total, chreq_nochan;
525
Harald Welte89d42e82017-12-17 16:42:41 +0100526 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +0100527
528 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
529 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
530
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +0100531 /* GSM 04.08 Table 9.9a:
532 * RA = '33'O -> Establishment cause = 0011xxxx (MS dual rate capable and asks for "TCH/H or TCH/F").
533 * With current setup, expect 4xSDCCH + 4xTCH/F + 1xTCH/H to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +0200534 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 +0100535 var RslChannelNr chan_nr := f_chreq_act_ack('33'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +0100536 }
537
538 IPA_RSL[0].clear;
539
Harald Weltedd8cbf32018-01-28 12:07:52 +0100540 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200541 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +0100542
543 /* now expect additional channel activations to fail */
544 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
545
546 alt {
547 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
548 tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
549 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
550 }
551 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
552 var GsmRrMessage rr;
553 /* match on IMM ASS REJ */
554 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
555 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
556 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200557 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +0100558 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
559 chreq_nochan+1);
560 setverdict(pass);
561 } else {
562 repeat;
563 }
564 }
565 [] IPA_RSL[0].receive { repeat; }
566 }
567}
568
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +0700569/* Test channel deactivation due to silence from MS */
570testcase TC_chan_deact_silence() runs on test_CT {
571 var RslChannelNr chan_nr;
572
573 f_init(1);
574
575 /* Request for a dedicated channel */
576 chan_nr := f_chreq_act_ack('23'O);
577
578 /* Wait some time until the channel is released */
579 f_sleep(2.0);
580
581 /* Expect CHANnel RELease */
582 alt {
583 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
584 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
585 log("Received CHANnel RELease");
586 setverdict(pass);
587 }
588 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
589 tr_RSL_IMM_ASSIGN(?))) {
590 /* See OS#3709, OsmoBSC should not send Immediate
591 * Assignment Reject since a dedicated channel was
592 * already allocated, and Immediate Assignment was
593 * already sent. */
594 setverdict(fail, "Unexpected Immediate Assignment!");
595 }
596 [] IPA_RSL[0].receive {
597 setverdict(fail, "Unexpected RSL message!");
598 }
599 }
600}
601
Harald Weltecfe2c962017-12-15 12:09:32 +0100602/***********************************************************************
603 * Assignment Testing
604 ***********************************************************************/
605
Neels Hofmeyrda4a6952018-06-14 04:02:49 +0200606/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction,
607 * except for the inter-BSC handover, MT side) */
Harald Weltecfe2c962017-12-15 12:09:32 +0100608testcase TC_outbound_connect() runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +0100609 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +0100610
Harald Weltea4ca4462018-02-09 00:17:14 +0100611 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 +0100612 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
613 setverdict(pass);
614}
615
Harald Welte16a4adf2017-12-14 18:54:01 +0100616/* Test behavior if MSC answers with CREF to CR */
617testcase TC_assignment_cic_only() runs on test_CT {
618 var BSSAP_N_CONNECT_ind rx_c_ind;
619 var RSL_Message rx_rsl;
620 var DchanTuple dt;
621
Harald Welte89d42e82017-12-17 16:42:41 +0100622 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +0100623
624 dt := f_est_dchan('23'O, 23, '00000000'O);
Harald Welte17b27da2018-05-25 20:33:53 +0200625 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
626 /* send assignment without AoIP IEs */
627 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
628 } else {
629 /* Send assignmetn without CIC in IPA case */
630 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
631 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
632 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
633 }
Harald Welte16a4adf2017-12-14 18:54:01 +0100634 alt {
635 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
636 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
637 }
Harald Welte235ebf12017-12-15 14:18:16 +0100638 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +0100639 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
640 setverdict(pass);
641 }
642 [] BSSAP.receive { repeat; }
643 }
644}
645
Harald Welteed848512018-05-24 22:27:58 +0200646/* generate an assignment request for either AoIP or SCCPlite */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200647function f_gen_ass_req(boolean osmux_enabled := false) return PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200648 var PDU_BSSAP ass_cmd;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200649 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Harald Welteed848512018-05-24 22:27:58 +0200650 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
651 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
652 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200653 if (osmux_enabled) {
654 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla, osmux_cid));
655 } else {
656 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
657 }
Harald Welteed848512018-05-24 22:27:58 +0200658 } else {
659 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +0200660 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
Harald Welteed848512018-05-24 22:27:58 +0200661 }
662 return ass_cmd;
663}
664
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +0100665function f_gen_handover_req() return PDU_BSSAP {
666 var PDU_BSSAP ho_req;
667 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
668 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
669 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
670 ho_req := valueof(ts_BSSMAP_HandoverRequest(omit, tla));
671 } else {
672 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
673 ho_req := valueof(ts_BSSMAP_HandoverRequest(cic, omit));
674 }
675 return ho_req;
676}
677
Harald Welteed848512018-05-24 22:27:58 +0200678/* generate an assignment complete template for either AoIP or SCCPlite */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200679function f_gen_exp_compl(boolean expect_osmux := false) return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200680 var template PDU_BSSAP exp_compl;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200681 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Harald Welteed848512018-05-24 22:27:58 +0200682 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200683 if (expect_osmux) {
684 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, osmux_cid);
685 } else {
686 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, omit);
687 }
Harald Welteed848512018-05-24 22:27:58 +0200688 } else {
689 /* CIC is optional "*" as the MSC allocated it */
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +0200690 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
Harald Welteed848512018-05-24 22:27:58 +0200691 }
692 return exp_compl;
693}
694
Harald Welte235ebf12017-12-15 14:18:16 +0100695/* Run everything required up to sending a caller-specified assignment command and expect response */
696function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
697runs on test_CT {
698 var BSSAP_N_CONNECT_ind rx_c_ind;
699 var RSL_Message rx_rsl;
700 var DchanTuple dt;
701
Harald Welte89d42e82017-12-17 16:42:41 +0100702 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +0100703
704 dt := f_est_dchan('23'O, 23, '00000000'O);
705 /* send assignment without AoIP IEs */
706 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
707 alt {
708 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
709 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
710 setverdict(pass);
711 } else {
712 setverdict(fail, fail_text);
713 }
714 }
715 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
716 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
717 setverdict(pass);
718 } else {
719 setverdict(fail, fail_text);
720 }
721 }
722 [] BSSAP.receive { repeat; }
723 }
724}
725testcase TC_assignment_csd() runs on test_CT {
726 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200727 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100728 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
729 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
730 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
731}
732
733testcase TC_assignment_ctm() runs on test_CT {
734 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200735 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100736 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
737 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
738 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
739}
740
Harald Welte4003d112017-12-09 22:35:39 +0100741type record DchanTuple {
742 integer sccp_conn_id,
743 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +0100744}
745
Harald Welted6939652017-12-13 21:02:46 +0100746/* Send CHAN RQD and wait for allocation; acknowledge it */
747private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
748runs on test_CT return RslChannelNr {
749 var RSL_Message rx_rsl;
750 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
751 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
752 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
753 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
Daniel Willmannf4ac4ce2018-08-02 14:06:30 +0200754 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Harald Welted6939652017-12-13 21:02:46 +0100755 return chan_nr;
756}
757
Harald Welte4003d112017-12-09 22:35:39 +0100758/* helper function to establish a dedicated channel via BTS and MSC */
759function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
760runs on test_CT return DchanTuple {
761 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +0100762 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100763
Harald Welte4003d112017-12-09 22:35:39 +0100764 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100765 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +0100766
767 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
768
769 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
770 dt.sccp_conn_id := rx_c_ind.connectionId;
771 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
772
773 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100774}
775
Harald Welte641fcbe2018-06-14 10:58:35 +0200776/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
777private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
778 var RSL_Message rx_rsl;
779 /* expect BSC to disable the channel */
780 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
781 /* respond with CHAN REL ACK */
782 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
783
784 /* expect Clear Complete from BSC */
785 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
786
787 /* MSC disconnects as instructed. */
788 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
789}
790
Harald Welte4003d112017-12-09 22:35:39 +0100791/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
792testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100793 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100794 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +0100795
Harald Welte89d42e82017-12-17 16:42:41 +0100796 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +0100797
Harald Welte4003d112017-12-09 22:35:39 +0100798 dt := f_est_dchan('23'O, 23, '00010203040506'O);
799
800 /* simulate RLL REL IND */
801 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
802
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100803 /* expect Clear Request on MSC side */
804 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
805
806 /* Instruct BSC to clear channel */
807 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
808 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
809
Harald Welte4003d112017-12-09 22:35:39 +0100810 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200811 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100812
813 /* wait for SCCP emulation to do its job */
814 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +0100815
816 setverdict(pass);
817}
818
819/* Test behavior of channel release after CONN FAIL IND from BTS */
820testcase TC_chan_rel_conn_fail() runs on test_CT {
821 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100822 var DchanTuple dt;
823
Harald Welte89d42e82017-12-17 16:42:41 +0100824 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100825
826 dt := f_est_dchan('23'O, 23, '00010203040506'O);
827
828 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +0100829 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 +0100830 /* TODO: different cause values? */
831
Harald Welte4003d112017-12-09 22:35:39 +0100832 /* expect Clear Request from BSC */
833 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
834
835 /* Instruct BSC to clear channel */
836 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
837 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
838
Harald Welte6ff76ea2018-01-28 13:08:01 +0100839 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200840 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +0100841
842 /* wait for SCCP emulation to do its job */
843 f_sleep(1.0);
844
845 setverdict(pass);
846}
847
Harald Welte99f3ca02018-06-14 13:40:29 +0200848/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
849/* See also https://www.osmocom.org/issues/3182 */
850testcase TC_early_conn_fail() runs on test_CT {
851 var RSL_Message rx_rsl;
852 var DchanTuple dt;
853
854 f_init(1);
855
856 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
857 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_octstring(1), 23);
858
859 /* BTS->BSC: simulate CONN FAIL IND */
860 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
861
862 /* BTS->BSC: Expect RF channel release from BSC on Abis */
863 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
864
865 /* BTS<-BSC: respond with CHAN REL ACK */
866 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
867
868 setverdict(pass);
869}
870
871/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
872/* See also https://www.osmocom.org/issues/3182 */
873testcase TC_late_conn_fail() runs on test_CT {
874 var RSL_Message rx_rsl;
875 var DchanTuple dt;
876
877 f_init(1);
878
879 dt := f_est_dchan('23'O, 23, '00010203040506'O);
880
881 /* BSC<-MSC: Instruct BSC to clear connection */
882 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
883
884 /* BTS->BSC: expect BSC to deactivate SACCH */
885 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
886
887 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
888 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
889
890 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
891 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
892 /* BTS->BSC: respond with CHAN REL ACK */
893 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
894
895 /* BSC->MSC: expect Clear Complete from BSC */
896 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
897
898 /* BSC<-MSC: MSC disconnects as requested. */
899 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
900
901 setverdict(pass);
902}
903
Neels Hofmeyrf44ccd12018-11-05 19:15:23 +0100904function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr,
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100905 boolean expect_deact_sacch := true,
906 boolean expect_rr_chan_rel := true,
907 boolean expect_rll_rel_req := true,
Harald Welte99787102019-02-04 10:41:36 +0100908 boolean handle_rll_rel := true,
909 boolean is_csfb := false
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100910 ) runs on test_CT {
Harald Welte91d54a52018-01-28 15:35:07 +0100911
912 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100913 var boolean got_deact_sacch := false;
914 var boolean got_rr_chan_rel := false;
915 var boolean got_rll_rel_req := false;
916 log("f_expect_chan_rel() expecting: expect_deact_sacch=", expect_deact_sacch, " expect_rr_chan_rel=", expect_rr_chan_rel,
917 " expect_rll_rel_req=", expect_rll_rel_req);
Harald Welte91d54a52018-01-28 15:35:07 +0100918 alt {
Harald Welte91d54a52018-01-28 15:35:07 +0100919 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
920 tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100921 got_deact_sacch := true;
Harald Welte91d54a52018-01-28 15:35:07 +0100922 repeat;
923 }
Harald Welte99787102019-02-04 10:41:36 +0100924 [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))) {
925 got_rr_chan_rel := true;
926 repeat;
927 }
928 [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 +0100929 got_rr_chan_rel := true;
Neels Hofmeyr211169d2018-11-07 00:37:29 +0100930 repeat;
931 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100932 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
Harald Welte91d54a52018-01-28 15:35:07 +0100933 tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100934 got_rll_rel_req := true;
Harald Welte91d54a52018-01-28 15:35:07 +0100935 /* FIXME: Why are we getting this for LinkID SACCH? */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100936 if (handle_rll_rel) {
937 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
938 }
Harald Welte91d54a52018-01-28 15:35:07 +0100939 repeat;
940 }
Harald Welte91d54a52018-01-28 15:35:07 +0100941 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
942 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
943 /* respond with CHAN REL ACK */
944 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
945 }
946 /* ignore any user data */
947 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_MsgTypeR(?))) {
948 repeat;
949 }
950 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100951
952 log("f_expect_chan_rel() summary: got_deact_sacch=", got_deact_sacch, " got_rr_chan_rel=", got_rr_chan_rel,
953 " got_rll_rel_req=", got_rll_rel_req);
954
955 if (expect_deact_sacch != got_deact_sacch) {
956 setverdict(fail, "f_expect_chan_rel(): expect_deact_sacch=", expect_deact_sacch, " got_deact_sacch=", got_deact_sacch);
957 }
958 if (expect_rr_chan_rel != got_rr_chan_rel) {
959 setverdict(fail, "f_expect_chan_rel(): expect_rr_chan_rel=", expect_rr_chan_rel, " got_rr_chan_rel=", got_rr_chan_rel);
960 }
961 if (expect_rll_rel_req != got_rll_rel_req) {
962 setverdict(fail, "f_expect_chan_rel(): expect_rll_rel_req=", expect_rll_rel_req, " got_rll_rel_req=", got_rll_rel_req);
963 }
Harald Welte91d54a52018-01-28 15:35:07 +0100964}
965
Harald Welte4003d112017-12-09 22:35:39 +0100966/* Test behavior of channel release after hard Clear Command from MSC */
967testcase TC_chan_rel_hard_clear() runs on test_CT {
968 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100969 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +0100970
Harald Welte89d42e82017-12-17 16:42:41 +0100971 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100972
973 dt := f_est_dchan('23'O, 23, '00010203040506'O);
974
975 /* Instruct BSC to clear channel */
976 var BssmapCause cause := 0;
977 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
978
979 /* expect Clear Complete from BSC on A */
980 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
981 /* release the SCCP connection */
982 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
983 }
984
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100985 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte4003d112017-12-09 22:35:39 +0100986 setverdict(pass);
987}
988
Harald Welte99787102019-02-04 10:41:36 +0100989/* Test behavior of channel release after Clear Command with CSFB indicator from MSC */
990testcase TC_chan_rel_hard_clear_csfb() runs on test_CT {
991 var BSSAP_N_DATA_ind rx_di;
992 var DchanTuple dt;
993
994 f_init(1);
995
996 dt := f_est_dchan('23'O, 23, '00010203040506'O);
997
998 /* Instruct BSC to clear channel */
999 var BssmapCause cause := 0;
1000 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
1001
1002 /* expect Clear Complete from BSC on A */
1003 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
1004 /* release the SCCP connection */
1005 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1006 }
1007
1008 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, is_csfb := true);
1009 setverdict(pass);
1010}
1011
Harald Welted8c36cd2017-12-09 23:05:31 +01001012/* Test behavior of channel release after hard RLSD from MSC */
1013testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +01001014 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +01001015
Harald Welte89d42e82017-12-17 16:42:41 +01001016 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +01001017
1018 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1019
1020 /* release the SCCP connection */
1021 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1022
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001023 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welted8c36cd2017-12-09 23:05:31 +01001024 setverdict(pass);
1025}
1026
Harald Welte550daf92018-06-11 19:22:13 +02001027/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
1028testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
1029 var DchanTuple dt;
1030
1031 f_init(1);
1032
1033 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1034
1035 /* release the SCCP connection */
1036 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1037
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001038 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte550daf92018-06-11 19:22:13 +02001039 setverdict(pass);
1040}
1041
Harald Welte85804d42017-12-10 14:11:58 +01001042/* Test behavior of channel release after BSSMAP RESET from MSC */
1043testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +01001044 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +01001045
Harald Welte89d42e82017-12-17 16:42:41 +01001046 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +01001047
1048 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1049
1050 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
1051 IPA_RSL[0].clear;
1052
1053 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001054 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 +01001055 interleave {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001056 [] 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 +01001057 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
1058 }
1059
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001060 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte85804d42017-12-10 14:11:58 +01001061 setverdict(pass);
1062}
1063
Harald Welte5cd20ed2017-12-13 21:03:20 +01001064/* Test behavior if RSL EST IND for non-active channel */
1065testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
1066 timer T := 2.0;
1067
Harald Welte89d42e82017-12-17 16:42:41 +01001068 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001069
1070 var octetstring l3 := '00010203040506'O;
1071 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
1072 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1073
1074 T.start;
1075 alt {
1076 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1077 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
1078 }
1079 [] BSSAP.receive {}
1080 [] IPA_RSL[0].receive {}
1081 [] T.timeout {}
1082 }
1083
1084 setverdict(pass);
1085}
1086
1087/* Test behavior if RSL EST IND for invalid SAPI */
1088testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
1089 var RslChannelNr chan_nr;
1090
Harald Welte89d42e82017-12-17 16:42:41 +01001091 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001092
1093 chan_nr := f_chreq_act_ack()
1094
1095 var octetstring l3 := '00010203040506'O;
1096 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
1097
1098 timer T := 2.0;
1099 T.start;
1100 alt {
1101 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1102 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
1103 }
1104 [] BSSAP.receive { repeat; }
1105 [] IPA_RSL[0].receive { repeat; }
1106 [] T.timeout {}
1107 }
1108
1109 setverdict(pass);
1110}
1111
1112/* Test behavior if RSL EST IND for invalid SAPI */
1113testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
1114 timer T := 2.0;
1115
Harald Welte89d42e82017-12-17 16:42:41 +01001116 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001117
1118 var RslChannelNr chan_nr := f_chreq_act_ack();
1119
1120 var octetstring l3 := '00010203040506'O;
1121 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
1122
1123 T.start;
1124 alt {
1125 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1126 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
1127 }
1128 [] BSSAP.receive { repeat; }
1129 [] IPA_RSL[0].receive { repeat; }
1130 [] T.timeout {}
1131 }
1132
1133 setverdict(pass);
1134}
1135
1136/* Test behavior if RSL EST IND for invalid SACCH */
1137testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
1138 timer T := 2.0;
1139
Harald Welte89d42e82017-12-17 16:42:41 +01001140 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001141
1142 var RslChannelNr chan_nr := f_chreq_act_ack();
1143
1144 var octetstring l3 := '00010203040506'O;
1145 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
1146
1147 T.start;
1148 alt {
1149 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1150 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
1151 }
1152 [] BSSAP.receive { repeat; }
1153 [] IPA_RSL[0].receive { repeat; }
1154 [] T.timeout {}
1155 }
1156
1157 setverdict(pass);
1158}
1159
1160
1161
Harald Welte4003d112017-12-09 22:35:39 +01001162
1163testcase TC_ctrl_msc_connection_status() runs on test_CT {
1164 var charstring ctrl_resp;
1165
Harald Welte89d42e82017-12-17 16:42:41 +01001166 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001167
1168 /* See https://osmocom.org/issues/2729 */
1169 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
1170 setverdict(pass);
1171}
1172
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001173testcase TC_ctrl_msc0_connection_status() runs on test_CT {
1174 var charstring ctrl_resp;
1175
1176 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001177
1178 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
1179 setverdict(pass);
1180}
1181
Harald Welte4003d112017-12-09 22:35:39 +01001182testcase TC_ctrl() runs on test_CT {
1183 var charstring ctrl_resp;
1184
Harald Welte89d42e82017-12-17 16:42:41 +01001185 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001186
1187 /* all below values must match the osmo-bsc.cfg config file used */
1188
Harald Welte6a129692018-03-17 17:30:14 +01001189 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
1190 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Oliver Smith75aa0202019-08-19 14:17:50 +02001191 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "4");
Harald Welte4003d112017-12-09 22:35:39 +01001192
1193 var integer bts_nr := 0;
1194 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
1195 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
1196 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
1197 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
1198 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
1199 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
1200 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
1201
1202 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
1203 f_sleep(2.0);
1204 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
1205 setverdict(fail, "oml-uptime not incrementing as expected");
1206 }
1207 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
1208
1209 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
1210
1211 setverdict(pass);
Harald Welte96c94412017-12-09 03:12:45 +01001212}
1213
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02001214/* Verify that Upon receival of SET "location", BSC forwards a TRAP
1215 "location-state" over the SCCPlite IPA conn */
1216testcase TC_ctrl_location() runs on test_CT {
1217 var MSC_ConnHdlr vc_conn;
1218 var integer bts_nr := 0;
1219
1220 f_init(1, true);
1221 f_sleep(1.0);
1222
1223 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234567,fix3d,0.340000,0.560000,0.780000");
1224 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
1225 "1234567,fix3d,0.340000,0.560000,0.780000,operational,unlocked,on,001,01");
1226
1227 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "1");
1228 f_sleep(2.0);
1229
1230 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234888,fix3d,0.350000,0.570000,0.790000");
1231 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
1232 "1234888,fix3d,0.350000,0.570000,0.790000,operational,locked,off,001,01");
1233
1234 /* should match the one from config */
1235 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "0");
1236
1237 setverdict(pass);
1238}
1239
Harald Welte6f521d82017-12-11 19:52:02 +01001240function f_bssap_tx_ud(template PDU_BSSAP bssap) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +01001241 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, bssap));
Harald Welte6f521d82017-12-11 19:52:02 +01001242}
1243
1244
1245/***********************************************************************
1246 * Paging Testing
1247 ***********************************************************************/
1248
1249type record Cell_Identity {
1250 GsmMcc mcc,
1251 GsmMnc mnc,
1252 GsmLac lac,
1253 GsmCellId ci
1254};
Harald Welte24135bd2018-03-17 19:27:53 +01001255private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01001256private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01001257
Harald Welte5d1a2202017-12-13 19:51:29 +01001258type set of integer BtsIdList;
1259
1260private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
1261 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
1262 if (bts_id == bts_ids[j]) {
1263 return true;
1264 }
1265 }
1266 return false;
1267}
Harald Welte6f521d82017-12-11 19:52:02 +01001268
1269/* core paging test helper function; used by most paging test cases */
1270private function f_pageing_helper(hexstring imsi,
1271 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01001272 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01001273 template RSL_ChanNeeded rsl_chneed := omit,
1274 template OCT4 tmsi := omit) runs on test_CT
1275{
1276 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
1277 var MobileIdentity mi;
1278 var template octetstring id_enc; /* FIXME */
1279 var RSL_Message rx_rsl;
1280 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01001281 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01001282
1283 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01001284
1285 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01001286 for (i := 0; i < NUM_BTS; i := i + 1) {
1287 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01001288 }
Harald Welte6f521d82017-12-11 19:52:02 +01001289
1290 if (isvalue(rsl_chneed)) {
1291 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
1292 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
1293 } else {
1294 bssmap_chneed := omit;
1295 }
1296
1297 f_bssap_tx_ud(ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed));
1298
Pau Espin Pedrol76ba5412019-06-10 11:00:33 +02001299/* FIXME: Disabled due to bugs in both GSM_RR_Types and MobileL3_CommonIE_Types IMSI encoder
Harald Welte6f521d82017-12-11 19:52:02 +01001300 if (isvalue(tmsi)) {
1301 mi := valueof(t_Osmo_MI_TMSI(oct2int(valueof(tmsi))));
1302 } else {
1303 mi := valueof(ts_Osmo_MI_IMSI(imsi));
1304 }
1305 id_enc := enc_MobileIdentity(mi);
1306*/
1307 id_enc := ?;
Harald Welte5d1a2202017-12-13 19:51:29 +01001308 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
1309 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(id_enc));
1310 /* check channel type, paging group */
1311 if (rx_rsl.ies[1].body.paging_group != paging_group) {
1312 setverdict(fail, "Paging for wrong paging group");
1313 }
1314 if (ispresent(rsl_chneed) and
1315 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
1316 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
1317 }
Harald Welte6f521d82017-12-11 19:52:02 +01001318 }
Harald Welte2fccd982018-01-31 15:48:19 +01001319 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01001320 /* do a quick check on all not-included BTSs if they received paging */
1321 for (i := 0; i < NUM_BTS; i := i + 1) {
1322 timer T := 0.1;
1323 if (f_bts_in_list(i, bts_ids)) {
1324 continue;
1325 }
1326 T.start;
1327 alt {
1328 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(id_enc))) {
1329 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
1330 }
1331 [] IPA_RSL[i].receive { repeat; }
1332 [] T.timeout { }
1333 }
Harald Welte6f521d82017-12-11 19:52:02 +01001334 }
1335
1336 setverdict(pass);
1337}
1338
Harald Welte5d1a2202017-12-13 19:51:29 +01001339const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01001340const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01001341const BtsIdList c_BtsId_LAC1 := { 0, 1 };
1342const BtsIdList c_BtsId_LAC2 := { 2 };
1343
Harald Welte6f521d82017-12-11 19:52:02 +01001344/* PAGING by IMSI + TMSI */
1345testcase TC_paging_imsi_nochan() runs on test_CT {
1346 var BSSMAP_FIELD_CellIdentificationList cid_list;
1347 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01001348 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001349 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001350}
1351
1352/* PAGING by IMSI + TMSI */
1353testcase TC_paging_tmsi_nochan() runs on test_CT {
1354 var BSSMAP_FIELD_CellIdentificationList cid_list;
1355 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001356 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001357 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001358}
1359
1360/* Paging with different "channel needed' values */
1361testcase TC_paging_tmsi_any() runs on test_CT {
1362 var BSSMAP_FIELD_CellIdentificationList cid_list;
1363 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001364 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001365 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001366}
1367testcase TC_paging_tmsi_sdcch() runs on test_CT {
1368 var BSSMAP_FIELD_CellIdentificationList cid_list;
1369 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001370 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001371 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001372}
1373testcase TC_paging_tmsi_tch_f() runs on test_CT {
1374 var BSSMAP_FIELD_CellIdentificationList cid_list;
1375 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001376 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001377 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001378}
1379testcase TC_paging_tmsi_tch_hf() runs on test_CT {
1380 var BSSMAP_FIELD_CellIdentificationList cid_list;
1381 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001382 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001383 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001384}
1385
1386/* Paging by CGI */
1387testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
1388 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1389 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001390 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001391 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001392}
1393
1394/* Paging by LAC+CI */
1395testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
1396 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1397 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001398 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001399 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001400}
1401
1402/* Paging by CI */
1403testcase TC_paging_imsi_nochan_ci() runs on test_CT {
1404 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1405 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001406 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001407 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001408}
1409
1410/* Paging by LAI */
1411testcase TC_paging_imsi_nochan_lai() runs on test_CT {
1412 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1413 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001414 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001415 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001416}
1417
1418/* Paging by LAC */
1419testcase TC_paging_imsi_nochan_lac() runs on test_CT {
1420 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1421 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001422 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001423 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001424}
1425
1426/* Paging by "all in BSS" */
1427testcase TC_paging_imsi_nochan_all() runs on test_CT {
1428 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1429 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01001430 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001431 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001432}
1433
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001434/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001435testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
1436 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1437 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 +01001438 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001439 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001440}
Harald Welte6f521d82017-12-11 19:52:02 +01001441
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001442/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001443testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
1444 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1445 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001446 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001447 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001448}
1449
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001450/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001451testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
1452 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1453 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001454 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001455 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001456}
1457
Harald Welte6f521d82017-12-11 19:52:02 +01001458/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01001459testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
1460 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1461 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
1462 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001463 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001464}
1465
1466/* Paging on empty list: Verify none of them page */
1467testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
1468 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1469 cid_list := { cIl_LAC := { } };
1470 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001471 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001472}
1473
Stefan Sperling049a86e2018-03-20 15:51:00 +01001474/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
1475testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
1476 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1477 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
1478 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
1479 f_shutdown_helper();
1480}
1481
Harald Welte6f521d82017-12-11 19:52:02 +01001482/* Verify paging retransmission interval + count */
1483/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01001484/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01001485
Harald Weltee65d40e2017-12-13 00:09:06 +01001486/* Verify PCH load */
1487testcase TC_paging_imsi_load() runs on test_CT {
1488 var BSSMAP_FIELD_CellIdentificationList cid_list;
1489 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01001490 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01001491 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001492 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01001493
1494 /* tell BSC there is no paging space anymore */
1495 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01001496 f_sleep(0.2);
1497 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01001498
1499 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
1500 * there would be 8 retransmissions during 4 seconds */
1501 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01001502 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01001503 alt {
1504 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1505 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02001506 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01001507 }
Harald Welte2caa1062018-03-17 18:19:05 +01001508 [] T_retrans.timeout {
1509 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
1510 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
1511 T_retrans.start;
1512 repeat;
1513 }
Harald Weltee65d40e2017-12-13 00:09:06 +01001514 [] T.timeout {
1515 setverdict(pass);
1516 }
1517 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001518
1519 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01001520}
1521
Harald Welte235ebf12017-12-15 14:18:16 +01001522/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01001523testcase TC_paging_counter() runs on test_CT {
1524 var BSSMAP_FIELD_CellIdentificationList cid_list;
1525 timer T := 4.0;
1526 var integer i;
1527 var integer paging_attempted_bsc;
1528 var integer paging_attempted_bts[NUM_BTS];
1529 var integer paging_expired_bts[NUM_BTS];
1530 cid_list := valueof(ts_BSSMAP_CIL_noCell);
1531
1532 f_init();
1533
1534 /* read counters before paging */
1535 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
1536 for (i := 0; i < NUM_BTS; i := i+1) {
1537 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
1538 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
1539 }
1540
1541 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
1542
1543 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
1544 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
1545 for (i := 0; i < NUM_BTS; i := i+1) {
1546 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
1547 paging_attempted_bts[i]+1);
1548 }
1549
1550 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
1551 f_sleep(12.0);
1552 for (i := 0; i < NUM_BTS; i := i+1) {
1553 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
1554 paging_expired_bts[i]+1);
1555 }
Harald Welte1ff69992017-12-14 12:31:17 +01001556
Philipp Maier282ca4b2018-02-27 17:17:00 +01001557 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01001558}
1559
1560
Harald Welte10985002017-12-12 09:29:15 +01001561/* Verify paging stops after A-RESET */
1562testcase TC_paging_imsi_a_reset() runs on test_CT {
1563 var BSSMAP_FIELD_CellIdentificationList cid_list;
1564 timer T := 3.0;
1565 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001566 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01001567
1568 /* Perform a BSSMAP Reset and wait for ACK */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001569 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 +01001570 alt {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001571 [] 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 +01001572 [] BSSAP.receive { repeat; }
1573 }
1574
Daniel Willmanncbef3982018-07-30 09:22:40 +02001575 /* Wait to avoid a possible race condition if a paging message is
1576 * received right before the reset ACK. */
1577 f_sleep(0.2);
1578
Harald Welte10985002017-12-12 09:29:15 +01001579 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01001580 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
1581 IPA_RSL[i].clear;
1582 }
Harald Welte10985002017-12-12 09:29:15 +01001583
1584 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
1585 T.start;
1586 alt {
1587 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1588 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001589 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01001590 }
Harald Welte5d1a2202017-12-13 19:51:29 +01001591 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1592 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001593 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001594 }
1595 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1596 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001597 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001598 }
Harald Welte10985002017-12-12 09:29:15 +01001599 [] T.timeout {
1600 setverdict(pass);
1601 }
1602 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001603
1604 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01001605}
Harald Welteae026692017-12-09 01:03:01 +01001606
Philipp Maierf45824a2019-08-14 14:44:10 +02001607/* Verify how we handle unsolicited Paging Response. In case of an unsolicit
1608 * paging response we can not know which MSC is in charge, so we will blindly
1609 * pick the first configured MSC. This behavior is required in order to make
1610 * MT-CSFB calls working because in those cases the BSC can not know that the
1611 * MSC has already paged the subscriver via SGs. So any MT-CSFB call will look
1612 * like an unsolicited Paging Response to the MSC.
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001613 */
1614testcase TC_paging_resp_unsol() runs on test_CT {
1615
1616 f_init(1);
Philipp Maierf45824a2019-08-14 14:44:10 +02001617 timer T := 5.0;
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001618
1619 var BSSAP_N_CONNECT_ind rx_c_ind;
1620 var DchanTuple dt;
1621 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
Philipp Maierf45824a2019-08-14 14:44:10 +02001622 var octetstring rr_pag_resp := enc_PDU_ML3_MS_NW(l3);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001623
1624 /* Send CHAN RQD and wait for allocation; acknowledge it */
1625 dt.rsl_chan_nr := f_chreq_act_ack();
1626
1627 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
1628 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
1629
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001630
Philipp Maierf45824a2019-08-14 14:44:10 +02001631 /* Expevct a CR with a matching Paging response on the A-Interface */
1632 T.start;
1633 alt {
1634 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(rr_pag_resp))) {
1635 setverdict(pass);
1636 }
1637 [] BSSAP.receive {
1638 setverdict(fail, "Received unexpected message on A-Interface!");
1639 }
1640 [] T.timeout {
1641 setverdict(fail, "Received nothing on A-Interface!");
1642 }
1643 }
1644
1645 setverdict(pass);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001646}
1647
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001648/* Test RSL link drop causes counter increment */
1649testcase TC_rsl_drop_counter() runs on test_CT {
1650 var integer rsl_fail;
1651
Harald Welte89d42e82017-12-17 16:42:41 +01001652 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001653
1654 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
1655
1656 bts[0].rsl.vc_IPA.stop;
1657
1658 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
1659
1660 setverdict(pass);
1661}
1662
1663/* TODO: Test OML link drop causes counter increment */
1664
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001665/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
1666function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
1667 timer T := 10.0;
1668
1669 bts[0].rsl.id := "IPA-0-RSL";
1670 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
1671 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
1672 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
1673 bts[0].rsl.ccm_pars.unit_id := "0/0/0"; /* value which is unknown at BTS */
1674
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001675 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
1676
1677 f_init_mgcp("VirtMSC");
1678
1679 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
1680 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
1681 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
1682 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
1683
1684 /* wait for IPA OML link to connect and then disconnect */
1685 T.start;
1686 alt {
1687 [] IPA_RSL[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) {
1688 T.stop;
1689 return true;
1690 }
1691 [] IPA_RSL[0].receive { repeat }
1692 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02001693 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001694 }
1695 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001696 return false;
1697}
1698
1699/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1700testcase TC_rsl_unknown_unit_id() runs on test_CT {
1701 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
1702 setverdict(pass);
1703 } else {
1704 setverdict(fail, "Timeout RSL waiting for connection to close");
1705 }
1706}
1707
1708
1709/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1710testcase TC_oml_unknown_unit_id() runs on test_CT {
1711 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
1712 setverdict(pass);
1713 } else {
1714 setverdict(fail, "Timeout OML waiting for connection to close");
1715 }
1716}
1717
1718
Harald Weltec1a2fff2017-12-17 11:06:19 +01001719/***********************************************************************
Harald Welte6811d102019-04-14 22:23:14 +02001720 * "New world" test cases using RSL_Emulation + RAN_Emulation
Harald Weltec1a2fff2017-12-17 11:06:19 +01001721 ***********************************************************************/
1722
Harald Welte6811d102019-04-14 22:23:14 +02001723import from RAN_Emulation all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01001724import from RSL_Emulation all;
1725import from MSC_ConnectionHandler all;
1726
1727type function void_fn(charstring id) runs on MSC_ConnHdlr;
1728
Harald Welte336820c2018-05-31 20:34:52 +02001729/* helper function to create and connect a MSC_ConnHdlr component */
Harald Welteff579f92018-05-31 22:19:39 +02001730private function f_connect_handler(inout MSC_ConnHdlr vc_conn) runs on test_CT {
Harald Welte6811d102019-04-14 22:23:14 +02001731 connect(vc_conn:RAN, g_bssap.vc_RAN:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001732 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001733 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01001734 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01001735 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01001736 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
1737 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
1738 }
Neels Hofmeyr91401012019-07-11 00:42:35 +02001739 if (isvalue(bts[2])) {
1740 connect(vc_conn:RSL2, bts[2].rsl.vc_RSL:CLIENT_PT);
1741 connect(vc_conn:RSL2_PROC, bts[2].rsl.vc_RSL:RSL_PROC);
1742 }
Harald Welte6811d102019-04-14 22:23:14 +02001743 connect(vc_conn:BSSAP, g_bssap.vc_RAN:CLIENT);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001744 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02001745 connect(vc_conn:MGCP_MULTI, vc_MGCP:MGCP_CLIENT_MULTI);
Harald Welte336820c2018-05-31 20:34:52 +02001746}
1747
1748function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
1749runs on test_CT return MSC_ConnHdlr {
1750 var charstring id := testcasename();
1751 var MSC_ConnHdlr vc_conn;
1752 vc_conn := MSC_ConnHdlr.create(id);
1753 f_connect_handler(vc_conn);
Harald Weltea0630032018-03-20 21:09:55 +01001754 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001755 return vc_conn;
1756}
1757
Harald Weltea0630032018-03-20 21:09:55 +01001758/* first function inside ConnHdlr component; sets g_pars + starts function */
1759private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
1760runs on MSC_ConnHdlr {
1761 if (isvalue(pars)) {
1762 g_pars := valueof(pars);
1763 }
1764 fn.apply(id);
1765}
1766
Harald Welte3c86ea02018-05-10 22:28:05 +02001767/* Establish signalling channel (non-assignment case) followed by cipher mode */
1768private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001769 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1770 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02001771 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02001772 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
1773 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
1774 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
1775 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02001776
Philipp Maier23000732018-05-18 11:25:37 +02001777 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02001778}
1779testcase TC_ciph_mode_a5_0() runs on test_CT {
1780 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001781 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001782 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
1783
1784 f_init(1, true);
1785 f_sleep(1.0);
1786 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1787 vc_conn.done;
1788}
1789testcase TC_ciph_mode_a5_1() runs on test_CT {
1790 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001791 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001792 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
1793
1794 f_init(1, true);
1795 f_sleep(1.0);
1796 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1797 vc_conn.done;
1798}
1799testcase TC_ciph_mode_a5_3() runs on test_CT {
1800 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001801 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001802 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
1803
1804 f_init(1, true);
1805 f_sleep(1.0);
1806 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1807 vc_conn.done;
1808}
1809
1810
1811/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02001812private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001813 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1814 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01001815
Harald Welte552620d2017-12-16 23:21:36 +01001816 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1817 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01001818
Harald Weltea0630032018-03-20 21:09:55 +01001819 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01001820}
Harald Welte552620d2017-12-16 23:21:36 +01001821testcase TC_assignment_fr_a5_0() runs on test_CT {
1822 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001823 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001824 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01001825
Harald Welte89d42e82017-12-17 16:42:41 +01001826 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001827 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001828 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01001829 vc_conn.done;
1830}
Harald Welte552620d2017-12-16 23:21:36 +01001831testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01001832 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001833 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001834 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001835
Harald Welte89d42e82017-12-17 16:42:41 +01001836 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001837 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001838 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
1839 vc_conn.done;
1840}
1841testcase TC_assignment_fr_a5_3() runs on test_CT {
1842 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001843 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001844 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001845
Harald Welte651fcdc2018-05-10 20:23:16 +02001846 f_init(1, true);
1847 f_sleep(1.0);
1848 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001849 vc_conn.done;
1850}
1851
Harald Welte552620d2017-12-16 23:21:36 +01001852/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
1853private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001854 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01001855 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001856 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001857 const OCT8 kc := '0001020304050607'O;
1858
1859 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001860 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
1861
Harald Weltea0630032018-03-20 21:09:55 +01001862 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01001863}
Harald Welte552620d2017-12-16 23:21:36 +01001864testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
1865 var MSC_ConnHdlr vc_conn;
1866
Harald Welte89d42e82017-12-17 16:42:41 +01001867 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001868 f_sleep(1.0);
1869
Harald Welte8863fa12018-05-10 20:15:27 +02001870 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01001871 vc_conn.done;
1872}
1873
Harald Welte552620d2017-12-16 23:21:36 +01001874private function f_tc_assignment_fr_a5_4(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001875 g_pars := f_gen_test_hdlr_pars();
Harald Welteed848512018-05-24 22:27:58 +02001876 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1877 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001878 const OCT8 kc := '0001020304050607'O;
1879 const OCT16 kc128 := kc & kc;
1880
1881 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1882 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Weltea0630032018-03-20 21:09:55 +01001883 f_establish_fully(ass_cmd, exp_compl);
Harald Welte38b2a102017-12-23 02:42:58 +01001884 f_cipher_mode('10'O, kc, kc128, true);
Harald Welte552620d2017-12-16 23:21:36 +01001885 /* TODO: expect GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED cause value */
Harald Welte552620d2017-12-16 23:21:36 +01001886}
Harald Welte552620d2017-12-16 23:21:36 +01001887testcase TC_assignment_fr_a5_4() runs on test_CT {
1888 var MSC_ConnHdlr vc_conn;
1889
Harald Welte89d42e82017-12-17 16:42:41 +01001890 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001891 f_sleep(1.0);
1892
Harald Welte8863fa12018-05-10 20:15:27 +02001893 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_4));
Harald Welte552620d2017-12-16 23:21:36 +01001894 vc_conn.done;
1895}
1896
1897
Harald Welte4532e0a2017-12-23 02:05:44 +01001898private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001899 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01001900 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02001901 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01001902 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Harald Weltea0630032018-03-20 21:09:55 +01001903 f_establish_fully(ass_cmd, exp_compl);
Harald Welte4532e0a2017-12-23 02:05:44 +01001904}
1905
1906testcase TC_assignment_sign() runs on test_CT {
1907 var MSC_ConnHdlr vc_conn;
1908
1909 f_init(1, true);
1910 f_sleep(1.0);
1911
Harald Welte8863fa12018-05-10 20:15:27 +02001912 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01001913 vc_conn.done;
1914}
1915
Harald Welte60aa5762018-03-21 19:33:13 +01001916/***********************************************************************
1917 * Codec (list) testing
1918 ***********************************************************************/
1919
1920/* check if the given rsl_mode is compatible with the a_elem */
1921private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
1922return boolean {
1923 select (a_elem.codecType) {
1924 case (GSM_FR) {
1925 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
1926 return true;
1927 }
1928 }
1929 case (GSM_HR) {
1930 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
1931 return true;
1932 }
1933 }
1934 case (GSM_EFR) {
1935 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
1936 return true;
1937 }
1938 }
1939 case (FR_AMR) {
1940 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
1941 return true;
1942 }
1943 }
1944 case (HR_AMR) {
1945 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
1946 return true;
1947 }
1948 }
1949 case else { }
1950 }
1951 return false;
1952}
1953
1954/* check if the given rsl_mode is compatible with the a_list */
1955private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
1956return boolean {
1957 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
1958 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
1959 return true;
1960 }
1961 }
1962 return false;
1963}
1964
1965/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02001966function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01001967return BSSMAP_IE_ChannelType {
1968 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
1969 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
1970 select (a_elem.codecType) {
1971 case (GSM_FR) {
1972 ret.channelRateAndType := ChRate_TCHF;
1973 ret.speechId_DataIndicator := Spdi_TCHF_FR;
1974 }
1975 case (GSM_HR) {
1976 ret.channelRateAndType := ChRate_TCHH;
1977 ret.speechId_DataIndicator := Spdi_TCHH_HR;
1978 }
1979 case (GSM_EFR) {
1980 ret.channelRateAndType := ChRate_TCHF;
1981 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
1982 }
1983 case (FR_AMR) {
1984 ret.channelRateAndType := ChRate_TCHF;
1985 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
1986 }
1987 case (HR_AMR) {
1988 ret.channelRateAndType := ChRate_TCHH;
1989 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
1990 }
1991 case else {
1992 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02001993 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01001994 }
1995 }
1996 return ret;
1997}
1998
Harald Weltea63b9102018-03-22 20:36:16 +01001999private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
2000return template RSL_IE_Body {
2001 var template RSL_IE_Body mode_ie := {
2002 chan_mode := {
2003 len := ?,
2004 reserved := ?,
2005 dtx_d := ?,
2006 dtx_u := ?,
2007 spd_ind := RSL_SPDI_SPEECH,
2008 ch_rate_type := -,
2009 coding_alg_rate := -
2010 }
2011 }
2012
2013 select (a_elem.codecType) {
2014 case (GSM_FR) {
2015 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
2016 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
2017 }
2018 case (GSM_HR) {
2019 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
2020 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
2021 }
2022 case (GSM_EFR) {
2023 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
2024 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
2025 }
2026 case (FR_AMR) {
2027 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
2028 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
2029 }
2030 case (HR_AMR) {
2031 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
2032 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
2033 }
2034 }
2035 return mode_ie;
2036}
2037
Harald Welte60aa5762018-03-21 19:33:13 +01002038type record CodecListTest {
2039 BSSMAP_IE_SpeechCodecList codec_list,
2040 charstring id
2041}
2042type record of CodecListTest CodecListTests
2043
2044private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02002045 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
2046 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
Harald Welte60aa5762018-03-21 19:33:13 +01002047
2048 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Harald Welte79f3f542018-05-25 20:02:37 +02002049 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
2050 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
2051 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
2052 g_pars.ass_codec_list.codecElements[0];
Philipp Maierd0e64b02019-03-13 14:15:23 +01002053 if (isvalue(g_pars.expect_mr_s0_s7)) {
2054 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
2055 g_pars.expect_mr_s0_s7;
2056 }
Harald Welte79f3f542018-05-25 20:02:37 +02002057 }
Harald Welte60aa5762018-03-21 19:33:13 +01002058 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
2059 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01002060 log("expecting ASS COMPL like this: ", exp_compl);
2061
2062 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01002063
2064 /* Verify that the RSL-side activation actually matches our expectations */
2065 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
2066
2067 var RSL_IE_Body mode_ie;
2068 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
2069 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02002070 mtc.stop;
Harald Weltea63b9102018-03-22 20:36:16 +01002071 }
2072 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
2073 if (not match(mode_ie, t_mode_ie)) {
2074 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
2075 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002076
2077 var RSL_IE_Body mr_conf;
2078 if (g_pars.expect_mr_conf_ie != omit) {
2079 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
2080 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
Daniel Willmannafce8662018-07-06 23:11:32 +02002081 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002082 }
2083 log("found RSL MR CONFIG IE: ", mr_conf);
2084
2085 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
2086 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
2087 g_pars.expect_mr_conf_ie);
2088 }
2089 } else {
2090 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
2091 log("found RSL MR CONFIG IE: ", mr_conf);
2092 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
Daniel Willmannafce8662018-07-06 23:11:32 +02002093 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002094 }
2095 }
Harald Welte60aa5762018-03-21 19:33:13 +01002096}
2097
Philipp Maierd0e64b02019-03-13 14:15:23 +01002098private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
2099
2100 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2101 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2102
2103 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
2104 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
2105 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
2106 }
2107 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
2108 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
2109 log("expecting ASS FAIL like this: ", exp_fail);
2110
2111 f_establish_fully(ass_cmd, exp_fail);
2112}
2113
Harald Welte60aa5762018-03-21 19:33:13 +01002114testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002115 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002116 var MSC_ConnHdlr vc_conn;
2117
2118 f_init(1, true);
2119 f_sleep(1.0);
2120
2121 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002122 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002123 vc_conn.done;
2124}
2125
2126testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002127 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002128 var MSC_ConnHdlr vc_conn;
2129
2130 f_init(1, true);
2131 f_sleep(1.0);
2132
2133 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002134 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002135 vc_conn.done;
2136}
2137
2138testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002139 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002140 var MSC_ConnHdlr vc_conn;
2141
2142 f_init(1, true);
2143 f_sleep(1.0);
2144
2145 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002146 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002147 vc_conn.done;
2148}
2149
Philipp Maierd0e64b02019-03-13 14:15:23 +01002150/* Allow 5,90k only (current default config) */
2151private function f_allow_amr_rate_5_90k() runs on test_CT {
2152 f_vty_enter_cfg_msc(BSCVTY, 0);
2153 f_vty_transceive(BSCVTY, "amr-config 12_2k forbidden");
2154 f_vty_transceive(BSCVTY, "amr-config 10_2k forbidden");
2155 f_vty_transceive(BSCVTY, "amr-config 7_95k forbidden");
2156 f_vty_transceive(BSCVTY, "amr-config 7_40k forbidden");
2157 f_vty_transceive(BSCVTY, "amr-config 6_70k forbidden");
2158 f_vty_transceive(BSCVTY, "amr-config 5_90k allowed");
2159 f_vty_transceive(BSCVTY, "amr-config 5_15k forbidden");
2160 f_vty_transceive(BSCVTY, "amr-config 4_75k forbidden");
2161 f_vty_transceive(BSCVTY, "exit");
2162 f_vty_transceive(BSCVTY, "exit");
2163}
2164
2165/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
2166 * ("Config-NB-Code = 1") */
2167private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
2168 f_vty_enter_cfg_msc(BSCVTY, 0);
2169 f_vty_transceive(BSCVTY, "amr-config 12_2k allowed");
2170 f_vty_transceive(BSCVTY, "amr-config 10_2k forbidden");
2171 f_vty_transceive(BSCVTY, "amr-config 7_95k forbidden");
2172 f_vty_transceive(BSCVTY, "amr-config 7_40k allowed");
2173 f_vty_transceive(BSCVTY, "amr-config 6_70k forbidden");
2174 f_vty_transceive(BSCVTY, "amr-config 5_90k allowed");
2175 f_vty_transceive(BSCVTY, "amr-config 5_15k forbidden");
2176 f_vty_transceive(BSCVTY, "amr-config 4_75k allowed");
2177 f_vty_transceive(BSCVTY, "exit");
2178 f_vty_transceive(BSCVTY, "exit");
2179}
2180
Harald Welte60aa5762018-03-21 19:33:13 +01002181testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002182 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002183 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02002184
2185 /* Note: This setups the codec configuration. The parameter payload in
2186 * mr_conf must be consistant with the parameter codecElements in pars
2187 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002188 var RSL_IE_Body mr_conf := {
2189 other := {
2190 len := 2,
2191 payload := '2804'O
2192 }
2193 };
Harald Welte60aa5762018-03-21 19:33:13 +01002194
Philipp Maier7695a0d2018-09-27 17:52:14 +02002195 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Philipp Maier806f8f12019-03-12 12:13:41 +01002196 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02002197 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
2198 pars.expect_mr_conf_ie := mr_conf;
2199
Harald Welte60aa5762018-03-21 19:33:13 +01002200 f_init(1, true);
2201 f_sleep(1.0);
2202
Harald Welte8863fa12018-05-10 20:15:27 +02002203 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002204 vc_conn.done;
2205}
2206
2207testcase TC_assignment_codec_amr_h() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002208 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002209 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02002210
2211 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002212 var RSL_IE_Body mr_conf := {
2213 other := {
2214 len := 2,
2215 payload := '2804'O
2216 }
2217 };
Harald Welte60aa5762018-03-21 19:33:13 +01002218
Philipp Maier7695a0d2018-09-27 17:52:14 +02002219 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Philipp Maier806f8f12019-03-12 12:13:41 +01002220 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02002221 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2222 pars.expect_mr_conf_ie := mr_conf;
2223
Harald Welte60aa5762018-03-21 19:33:13 +01002224 f_init(1, true);
2225 f_sleep(1.0);
2226
Harald Welte8863fa12018-05-10 20:15:27 +02002227 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002228 vc_conn.done;
2229}
2230
Philipp Maierd0e64b02019-03-13 14:15:23 +01002231function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0)
2232runs on test_CT {
2233
2234 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2235 var MSC_ConnHdlr vc_conn;
2236
2237 /* See note above */
2238 var RSL_IE_Body mr_conf := {
2239 other := {
2240 len := lengthof(mrconf),
2241 payload := mrconf
2242 }
2243 };
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 pars.expect_mr_conf_ie := mr_conf;
2253 pars.expect_mr_s0_s7 := exp_s8_s0;
2254
2255 f_init(1, true);
2256 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
2257 f_sleep(1.0);
2258
2259 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
2260 vc_conn.done;
2261 f_allow_amr_rate_5_90k();
2262}
2263
2264function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
2265runs on test_CT {
2266
2267 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2268 var MSC_ConnHdlr vc_conn;
2269
2270 if (fr) {
2271 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
2272 } else {
2273 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2274 }
2275 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
2276 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2277
2278 f_init(1, true);
2279 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
2280 f_sleep(1.0);
2281
2282 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
2283 vc_conn.done;
2284 f_allow_amr_rate_5_90k();
2285}
2286
2287
2288/* Set S1, we expect an AMR multirate configuration IE with all four rates
2289 * set. */
2290testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
2291 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
2292}
2293
2294/* Set S1, we expect an AMR multirate configuration IE with the lower three
2295 * rates set. */
2296testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
2297 f_TC_assignment_codec_amr(false, '2815208820'O, '00000010'B, '00000010'B);
2298}
2299
2300/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
2301 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
2302testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
2303 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'B, '00000010'B);
2304}
2305
2306/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
2307 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
2308testcase TC_assignment_codec_amr_h_S124() runs on test_CT {
2309 f_TC_assignment_codec_amr(false, '2815208820'O, '00010110'B, '00000010'B);
2310}
2311
2312/* The following block of tests selects more and more rates until all four
2313 * possible rates are in the active set (full rate) */
2314testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
2315 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'B);
2316}
2317
2318testcase TC_assignment_codec_amr_f_S02() runs on test_CT {
2319 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'B);
2320}
2321
2322testcase TC_assignment_codec_amr_f_S024() runs on test_CT {
2323 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'B);
2324}
2325
2326testcase TC_assignment_codec_amr_f_S0247() runs on test_CT {
2327 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
2328}
2329
2330/* The following block of tests selects more and more rates until all three
2331 * possible rates are in the active set (half rate) */
2332testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
2333 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'B);
2334}
2335
2336testcase TC_assignment_codec_amr_h_S02() runs on test_CT {
2337 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
2338}
2339
2340testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
2341 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
2342}
2343
2344/* The following block tests what happens when the MSC does offer rate
2345 * configurations that are not supported by the BSC. Normally such situations
2346 * should not happen because the MSC gets informed by the BSC in advance via
2347 * the L3 COMPLETE message which rates are applicable. The MSC should not try
2348 * to offer rates that are not applicable anyway. */
2349
2350testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
2351 /* Try to include 12,2k in into the active set even though the channel
2352 * is half rate only. The BSC is expected to remove the 12,0k */
2353 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'B);
2354}
2355
2356testcase TC_assignment_codec_amr_f_S01234567() runs on test_CT {
2357 /* See what happens when all rates are selected at once. Since then
2358 * Also S1 is selected, this setting will be prefered and we should
2359 * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
2360 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
2361}
2362
2363testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
2364 /* Same as above, but with S1 missing, the MSC is then expected to
2365 * select the currently supported rates, which are also 12.2k, 7,40k,
2366 * 5,90k, and 4,75k, into the active set. */
2367 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'B);
2368}
2369
2370testcase TC_assignment_codec_amr_f_zero() runs on test_CT {
2371 /* Try to select no rates at all */
2372 f_TC_assignment_codec_amr_fail(true, '00000000'B);
2373}
2374
2375testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
2376 /* Try to select only unsupported rates */
2377 f_TC_assignment_codec_amr_fail(true, '01101000'B);
2378}
2379
2380testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
2381 /* Try to select 12,2k for half rate */
2382 f_TC_assignment_codec_amr_fail(false, '10000000'B);
2383}
2384
Philipp Maierac09bfc2019-01-08 13:41:39 +01002385private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002386 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
2387 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
2388 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
2389 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002390}
2391
2392private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002393 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
2394 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002395}
2396
2397private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002398 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
2399 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
2400 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
2401 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
2402 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
2403 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002404}
2405
2406/* Allow HR only */
2407private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
2408 g_pars := f_gen_test_hdlr_pars();
2409 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2410 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2411 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2412 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
2413 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
2414 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
2415 f_establish_fully(ass_cmd, exp_compl);
2416}
2417
2418/* Allow FR only */
2419private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
2420 g_pars := f_gen_test_hdlr_pars();
2421 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2422 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2423 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2424 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
2425 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
2426 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2427 f_establish_fully(ass_cmd, exp_compl);
2428}
2429
2430/* Allow HR only (expect assignment failure) */
2431private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
2432 g_pars := f_gen_test_hdlr_pars();
2433 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2434 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2435 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2436 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
2437 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
2438 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
2439 f_establish_fully(ass_cmd, exp_fail);
2440}
2441
2442/* Allow FR only (expect assignment failure) */
2443private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(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_fail := tr_BSSMAP_AssignmentFail;
2447 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2448 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
2449 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
2450 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2451 f_establish_fully(ass_cmd, exp_fail);
2452}
2453
2454/* Allow FR and HR, but prefer FR */
2455private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2456 g_pars := f_gen_test_hdlr_pars();
2457 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2458 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2459 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2460 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2461 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2462 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2463 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2464 f_establish_fully(ass_cmd, exp_compl);
2465}
2466
2467/* Allow FR and HR, but prefer HR */
2468private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2469 g_pars := f_gen_test_hdlr_pars();
2470 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2471 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2472 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2473 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2474 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2475 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2476 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2477 f_establish_fully(ass_cmd, exp_compl);
2478}
2479
2480/* Allow FR and HR, but prefer FR */
2481private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2482 g_pars := f_gen_test_hdlr_pars();
2483 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2484 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2485 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2486 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2487 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2488 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2489 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2490 f_establish_fully(ass_cmd, exp_compl);
2491}
2492
2493/* Allow FR and HR, but prefer HR */
2494private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2495 g_pars := f_gen_test_hdlr_pars();
2496 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2497 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2498 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2499 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2500 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2501 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2502 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2503 f_establish_fully(ass_cmd, exp_compl);
2504}
2505
2506/* Request a HR channel while all FR channels are exhausted, this is expected
2507 * to work without conflicts */
2508testcase TC_assignment_codec_fr_exhausted_req_hr() runs on test_CT {
2509 var MSC_ConnHdlr vc_conn;
2510 f_init(1, true);
2511 f_sleep(1.0);
2512 f_enable_all_tch();
2513 f_disable_all_tch_f();
2514 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr));
2515 vc_conn.done;
2516 f_enable_all_tch();
2517 setverdict(pass);
2518}
2519
2520/* Request a FR channel while all FR channels are exhausted, this is expected
2521 * to fail. */
2522testcase TC_assignment_codec_fr_exhausted_req_fr() runs on test_CT {
2523 var MSC_ConnHdlr vc_conn;
2524 f_init(1, true);
2525 f_sleep(1.0);
2526 f_enable_all_tch();
2527 f_disable_all_tch_f();
2528 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr_fail));
2529 vc_conn.done;
2530 f_enable_all_tch();
2531 setverdict(pass);
2532}
2533
2534/* Request a FR (prefered) or alternatively a HR channel while all FR channels
2535 * are exhausted, this is expected to be resolved by selecting a HR channel. */
2536testcase TC_assignment_codec_fr_exhausted_req_fr_hr() runs on test_CT {
2537 var MSC_ConnHdlr vc_conn;
2538 f_init(1, true);
2539 f_sleep(1.0);
2540 f_enable_all_tch();
2541 f_disable_all_tch_f();
2542 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
2543 vc_conn.done;
2544 f_enable_all_tch();
2545 setverdict(pass);
2546}
2547
2548/* Request a HR (prefered) or alternatively a FR channel while all FR channels
2549 * are exhausted, this is expected to work without conflicts. */
2550testcase TC_assignment_codec_fr_exhausted_req_hr_fr() runs on test_CT {
2551 var MSC_ConnHdlr vc_conn;
2552 f_init(1, true);
2553 f_sleep(1.0);
2554 f_enable_all_tch();
2555 f_disable_all_tch_f();
2556 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_hr_fr));
2557 vc_conn.done;
2558 f_enable_all_tch();
2559 setverdict(pass);
2560}
2561
2562/* Request a FR channel while all HR channels are exhausted, this is expected
2563 * to work without conflicts */
2564testcase TC_assignment_codec_hr_exhausted_req_fr() runs on test_CT {
2565 var MSC_ConnHdlr vc_conn;
2566 f_init(1, true);
2567 f_sleep(1.0);
2568 f_enable_all_tch();
2569 f_disable_all_tch_h();
2570 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr));
2571 vc_conn.done;
2572 f_enable_all_tch();
2573 setverdict(pass);
2574}
2575
2576/* Request a HR channel while all HR channels are exhausted, this is expected
2577 * to fail. */
2578testcase TC_assignment_codec_hr_exhausted_req_hr() runs on test_CT {
2579 var MSC_ConnHdlr vc_conn;
2580 f_init(1, true);
2581 f_sleep(1.0);
2582 f_enable_all_tch();
2583 f_disable_all_tch_h();
2584 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr_fail));
2585 vc_conn.done;
2586 f_enable_all_tch();
2587 setverdict(pass);
2588}
2589
2590/* Request a HR (prefered) or alternatively a FR channel while all HR channels
2591 * are exhausted, this is expected to be resolved by selecting a FR channel. */
2592testcase TC_assignment_codec_hr_exhausted_req_hr_fr() runs on test_CT {
2593 var MSC_ConnHdlr vc_conn;
2594 f_init(1, true);
2595 f_sleep(1.0);
2596 f_enable_all_tch();
2597 f_disable_all_tch_h();
2598 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_hr_fr));
2599 vc_conn.done;
2600 f_enable_all_tch();
2601 setverdict(pass);
2602}
2603
2604/* Request a FR (prefered) or alternatively a HR channel while all HR channels
2605 * are exhausted, this is expected to work without conflicts. */
2606testcase TC_assignment_codec_hr_exhausted_req_fr_hr() runs on test_CT {
2607 var MSC_ConnHdlr vc_conn;
2608 f_init(1, true);
2609 f_sleep(1.0);
2610 f_enable_all_tch();
2611 f_disable_all_tch_h();
2612 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_fr_hr));
2613 vc_conn.done;
2614 f_enable_all_tch();
2615 setverdict(pass);
2616}
2617
2618/* Allow FR and HR, but prefer HR */
2619private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2620 g_pars := f_gen_test_hdlr_pars();
2621 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2622 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2623 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2624 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2625 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2626 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2627 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2628 f_establish_fully(ass_cmd, exp_compl);
2629}
2630
2631/* Allow FR and HR, but prefer FR */
2632private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2633 g_pars := f_gen_test_hdlr_pars();
2634 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2635 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2636 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2637 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2638 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2639 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2640 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2641 f_establish_fully(ass_cmd, exp_compl);
2642}
2643
2644/* Request a HR (prefered) or alternatively a FR channel, it is expected that
2645 * HR, which is the prefered type, is selected. */
2646testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
2647 var MSC_ConnHdlr vc_conn;
2648 f_init(1, true);
2649 f_sleep(1.0);
2650 f_enable_all_tch();
2651 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
2652 vc_conn.done;
2653 setverdict(pass);
2654}
2655
2656/* Request a FR (prefered) or alternatively a HR channel, it is expected that
2657 * FR, which is the prefered type, is selected. */
2658testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
2659 var MSC_ConnHdlr vc_conn;
2660 f_init(1, true);
2661 f_sleep(1.0);
2662 f_enable_all_tch();
2663 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
2664 vc_conn.done;
2665 setverdict(pass);
2666}
2667
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02002668testcase TC_assignment_osmux() runs on test_CT {
2669 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2670 var MSC_ConnHdlr vc_conn;
2671
2672 /* See note above */
2673 var RSL_IE_Body mr_conf := {
2674 other := {
2675 len := 2,
2676 payload := '2804'O
2677 }
2678 };
2679
2680 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2681 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
2682 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2683 pars.expect_mr_conf_ie := mr_conf;
2684 pars.use_osmux := true;
2685
2686 f_init(1, true, true);
2687 f_sleep(1.0);
2688
2689 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
2690 vc_conn.done;
2691}
2692
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02002693/* test the procedure of the MSC requesting a Classmark Update:
2694 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
2695 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01002696private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002697 g_pars := f_gen_test_hdlr_pars();
2698
Harald Weltea0630032018-03-20 21:09:55 +01002699 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01002700 /* we should now have a COMPL_L3 at the MSC */
2701 BSSAP.receive(tr_BSSMAP_ComplL3);
2702
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02002703 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
2704 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
2705
Harald Welte898113b2018-01-31 18:32:21 +01002706 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
2707 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
2708 setverdict(pass);
2709}
2710testcase TC_classmark() runs on test_CT {
2711 var MSC_ConnHdlr vc_conn;
2712 f_init(1, true);
2713 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002714 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01002715 vc_conn.done;
2716}
2717
Harald Weltee3bd6582018-01-31 22:51:25 +01002718private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002719 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01002720 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01002721 /* we should now have a COMPL_L3 at the MSC */
2722 BSSAP.receive(tr_BSSMAP_ComplL3);
2723
Harald Weltee3bd6582018-01-31 22:51:25 +01002724 /* send the single message we want to send */
2725 f_rsl_send_l3(l3);
2726}
2727
2728private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
2729 timer T := sec;
2730 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01002731 T.start;
2732 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01002733 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
2734 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02002735 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01002736 }
2737 [] T.timeout {
2738 setverdict(pass);
2739 }
2740 }
2741}
2742
Harald Weltee3bd6582018-01-31 22:51:25 +01002743/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2744private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
2745 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
2746 f_bssap_expect_nothing();
2747}
Harald Welte898113b2018-01-31 18:32:21 +01002748testcase TC_unsol_ass_fail() runs on test_CT {
2749 var MSC_ConnHdlr vc_conn;
2750 f_init(1, true);
2751 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002752 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01002753 vc_conn.done;
2754}
Harald Welte552620d2017-12-16 23:21:36 +01002755
Harald Welteea99a002018-01-31 20:46:43 +01002756
2757/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
2758private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002759 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
2760 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01002761}
2762testcase TC_unsol_ass_compl() runs on test_CT {
2763 var MSC_ConnHdlr vc_conn;
2764 f_init(1, true);
2765 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002766 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01002767 vc_conn.done;
2768}
2769
2770
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002771/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2772private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002773 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
2774 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002775}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002776testcase TC_unsol_ho_fail() runs on test_CT {
2777 var MSC_ConnHdlr vc_conn;
2778 f_init(1, true);
2779 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002780 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002781 vc_conn.done;
2782}
2783
2784
Harald Weltee3bd6582018-01-31 22:51:25 +01002785/* short message from MS should be ignored */
2786private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002787 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01002788 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01002789 /* we should now have a COMPL_L3 at the MSC */
2790 BSSAP.receive(tr_BSSMAP_ComplL3);
2791
2792 /* send short message */
2793 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
2794 f_bssap_expect_nothing();
2795}
2796testcase TC_err_82_short_msg() runs on test_CT {
2797 var MSC_ConnHdlr vc_conn;
2798 f_init(1, true);
2799 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002800 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01002801 vc_conn.done;
2802}
2803
2804
Harald Weltee9e02e42018-01-31 23:36:25 +01002805/* 24.008 8.4 Unknown message must trigger RR STATUS */
2806private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
2807 f_est_single_l3(ts_RRM_UL_REL('00'O));
2808 timer T := 3.0
2809 alt {
2810 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
2811 setverdict(pass);
2812 }
2813 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01002814 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01002815 }
2816}
2817testcase TC_err_84_unknown_msg() runs on test_CT {
2818 var MSC_ConnHdlr vc_conn;
2819 f_init(1, true);
2820 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002821 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01002822 vc_conn.done;
2823}
2824
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002825/***********************************************************************
2826 * Handover
2827 ***********************************************************************/
2828
Harald Welte94e0c342018-04-07 11:33:23 +02002829/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
2830private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
2831runs on test_CT {
2832 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2833 " timeslot "&int2str(ts_nr)&" ";
2834 f_vty_transceive(BSCVTY, cmd & suffix);
2835}
2836
Harald Welte261af4b2018-02-12 21:20:39 +01002837/* execute a "bts <0-255> trx <0-255> timeslot <0-7> sub-slot <0-7>" command on given Dchan */
2838private function f_vty_ss_action(charstring suffix, integer bts_nr, integer trx_nr, RslChannelNr chan_nr)
2839runs on MSC_ConnHdlr {
2840 /* FIXME: resolve those from component-global state */
2841 var integer ts_nr := chan_nr.tn;
2842 var integer ss_nr;
2843 if (ischosen(chan_nr.u.ch0)) {
2844 ss_nr := 0;
2845 } else if (ischosen(chan_nr.u.lm)) {
2846 ss_nr := chan_nr.u.lm.sub_chan;
2847 } else if (ischosen(chan_nr.u.sdcch4)) {
2848 ss_nr := chan_nr.u.sdcch4.sub_chan;
2849 } else if (ischosen(chan_nr.u.sdcch8)) {
2850 ss_nr := chan_nr.u.sdcch8.sub_chan;
2851 } else {
2852 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02002853 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01002854 }
2855
2856 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2857 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
2858 f_vty_transceive(BSCVTY, cmd & suffix);
2859}
2860
Neels Hofmeyr91401012019-07-11 00:42:35 +02002861/* Even though the VTY command to trigger handover takes a new BTS number as argument, behind the scenes osmo-bsc always
2862 * translates that to a target ARFCN+BSIC first. See bsc_vty.c trigger_ho_or_as(), which puts the selected BTS' neighbor
2863 * ident key (ARFCN + BSIC) in the struct passed on to handover_request(). handover_start() then resolves that to a
2864 * viable actual neighbor cell. So from the internal osmo-bsc perspective, we always request handover to an ARFCN + BSIC
2865 * pair, not really to a specific BTS number. */
Harald Welte261af4b2018-02-12 21:20:39 +01002866private function f_vty_handover(integer bts_nr, integer trx_nr, RslChannelNr chan_nr,
2867 integer new_bts_nr)
2868runs on MSC_ConnHdlr {
2869 f_vty_ss_action("handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
2870}
2871
2872/* intra-BSC hand-over between BTS0 and BTS1 */
2873private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002874 g_pars := f_gen_test_hdlr_pars();
Harald Welteed848512018-05-24 22:27:58 +02002875 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2876 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01002877 const OCT8 kc := '0001020304050607'O;
2878
2879 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2880 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2881
Harald Weltea0630032018-03-20 21:09:55 +01002882 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr7e2769f2019-08-14 19:17:53 +02002883 f_bts_0_cfg({"neighbor bts 1"});
Harald Welte261af4b2018-02-12 21:20:39 +01002884
2885 var HandoverState hs := {
2886 rr_ho_cmpl_seen := false,
2887 handover_done := false,
2888 old_chan_nr := -
2889 };
2890 /* issue hand-over command on VTY */
2891 f_vty_handover(0, 0, g_chan_nr, 1);
2892 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
2893 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002894
2895 /* From the MGW perspective, a handover is is characterized by
2896 * performing one MDCX operation with the MGW. So we expect to see
2897 * one more MDCX during handover. */
2898 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
2899
Harald Welte261af4b2018-02-12 21:20:39 +01002900 alt {
2901 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01002902 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002903
Philipp Maier4dae0652018-11-12 12:03:26 +01002904 /* Since this is an internal handover we expect the BSC to inform the
2905 * MSC about the event */
2906 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
2907
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002908 /* Check the amount of MGCP transactions is still consistant with the
2909 * test expectation */
2910 f_check_mgcp_expectations()
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01002911 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01002912}
2913
2914testcase TC_ho_int() runs on test_CT {
2915 var MSC_ConnHdlr vc_conn;
2916 f_init(2, true);
2917 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002918 vc_conn := f_start_handler(refers(f_tc_ho_int));
Harald Welte261af4b2018-02-12 21:20:39 +01002919 vc_conn.done;
2920}
Harald Weltee9e02e42018-01-31 23:36:25 +01002921
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02002922/* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02002923private function f_expect_dlcx_conns() runs on MSC_ConnHdlr {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02002924 var MgcpCommand mgcp;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02002925 var template MgcpResponse mgcp_resp;
2926 var MGCP_RecvFrom mrf;
2927 var template MgcpMessage msg_resp;
2928 var template MgcpMessage msg_dlcx := {
2929 command := tr_DLCX()
2930 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02002931
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02002932 if (g_pars.aoip) {
2933 MGCP.receive(tr_DLCX()) -> value mgcp {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02002934 log("Got first DLCX: ", mgcp);
2935 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02002936 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02002937
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02002938 MGCP.receive(tr_DLCX()) -> value mgcp {
2939 log("Got second DLCX: ", mgcp);
2940 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
2941 };
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02002942 } else {
2943 /* For SCCPLite, BSC doesn't handle the MSC-side */
2944 MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_dlcx)) -> value mrf {
2945 log("Got first DLCX: ", mrf.msg.command);
2946 msg_resp := {
2947 response := ts_DLCX_ACK2(mrf.msg.command.line.trans_id)
2948 }
2949 MGCP_MULTI.send(t_MGCP_SendToMrf(mrf, msg_resp));
2950 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02002951 }
2952
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02002953 BSSAP.receive(tr_BSSMAP_ClearComplete);
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02002954}
2955
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002956private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002957 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002958
2959 var PDU_BSSAP ass_req := f_gen_ass_req();
2960 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2961 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2962 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2963 f_establish_fully(ass_req, exp_compl);
2964
Neels Hofmeyr7e2769f2019-08-14 19:17:53 +02002965 f_bts_0_cfg({"neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002966 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2967
2968 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2969
2970 f_sleep(0.5);
2971 /* The MSC negotiates Handover Request and Handover Request Ack with
2972 * the other BSS and comes back with a BSSMAP Handover Command
2973 * containing an RR Handover Command coming from the target BSS... */
2974
2975 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
2976 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
2977 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
2978 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
2979 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
2980
2981 /* expect the Handover Command to go out on RR */
2982 var RSL_Message rsl_ho_cmd
2983 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
2984 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
2985 var RSL_IE_Body rsl_ho_cmd_l3;
2986 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
2987 log("RSL message contains no L3 Info IE, expected RR Handover Command");
2988 setverdict(fail);
2989 } else {
2990 log("Found L3 Info: ", rsl_ho_cmd_l3);
2991 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
2992 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
2993 setverdict(fail);
2994 } else {
2995 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
2996 setverdict(pass);
2997 }
2998 }
2999
3000 /* When the other BSS has reported a completed handover, this side is
3001 * torn down. */
3002
3003 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
3004 var BssmapCause cause := enum2int(cause_val);
3005 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3006
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02003007 f_expect_dlcx_conns();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003008 setverdict(pass);
3009 f_sleep(1.0);
3010}
3011testcase TC_ho_out_of_this_bsc() runs on test_CT {
3012 var MSC_ConnHdlr vc_conn;
3013
3014 f_init(1, true);
3015 f_sleep(1.0);
3016
3017 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
3018 vc_conn.done;
3019}
3020
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003021/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
3022 * simply never sends a BSSMAP Handover Command. */
3023private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01003024 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003025
3026 var PDU_BSSAP ass_req := f_gen_ass_req();
3027 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3028 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3029 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3030 f_establish_fully(ass_req, exp_compl);
3031
Neels Hofmeyr7e2769f2019-08-14 19:17:53 +02003032 f_bts_0_cfg({"neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003033 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
3034
3035 BSSAP.receive(tr_BSSMAP_HandoverRequired);
3036
3037 /* osmo-bsc should time out 10 seconds after the handover started.
3038 * Let's give it a bit extra. */
3039 f_sleep(15.0);
3040
3041 /* The old lchan and conn should still be active. See that arbitrary L3
3042 * is still going through. */
3043 var octetstring l3 := '0123456789'O;
3044 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
3045 var template PDU_BSSAP exp_data := {
3046 discriminator := '1'B,
3047 spare := '0000000'B,
3048 dlci := '00'O,
3049 lengthIndicator := 5,
3050 pdu := {
3051 dtap := l3
3052 }
3053 };
3054 BSSAP.receive(exp_data);
3055 setverdict(pass);
3056 f_sleep(1.0);
3057}
3058testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
3059 var MSC_ConnHdlr vc_conn;
3060
3061 f_init(1, true);
3062 f_sleep(1.0);
3063
3064 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
3065 vc_conn.done;
3066}
3067
3068/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
3069 * RR Handover Failure. */
3070private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01003071 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003072
3073 var PDU_BSSAP ass_req := f_gen_ass_req();
3074 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3075 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3076 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3077 f_establish_fully(ass_req, exp_compl);
3078
Neels Hofmeyr7e2769f2019-08-14 19:17:53 +02003079 f_bts_0_cfg({"neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003080 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
3081
3082 BSSAP.receive(tr_BSSMAP_HandoverRequired);
3083
3084 f_sleep(0.5);
3085 /* The MSC negotiates Handover Request and Handover Request Ack with
3086 * the other BSS and comes back with a BSSMAP Handover Command
3087 * containing an RR Handover Command coming from the target BSS... */
3088
3089 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
3090 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
3091 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
3092 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
3093 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
3094
3095 /* expect the Handover Command to go out on RR */
3096 var RSL_Message rsl_ho_cmd
3097 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
3098 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
3099 var RSL_IE_Body rsl_ho_cmd_l3;
3100 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
3101 log("RSL message contains no L3 Info IE, expected RR Handover Command");
3102 setverdict(fail);
3103 } else {
3104 log("Found L3 Info: ", rsl_ho_cmd_l3);
3105 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
3106 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
3107 setverdict(fail);
3108 } else {
3109 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
3110 setverdict(pass);
3111 }
3112 }
3113
3114 f_sleep(0.2);
3115 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
3116
3117 /* Should tell the MSC about the failure */
3118 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3119
3120 f_sleep(1.0);
3121
3122 /* The old lchan and conn should still be active. See that arbitrary L3
3123 * is still going through. */
3124 var octetstring l3 := '0123456789'O;
3125 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
3126 var template PDU_BSSAP exp_data := {
3127 discriminator := '1'B,
3128 spare := '0000000'B,
3129 dlci := '00'O,
3130 lengthIndicator := 5,
3131 pdu := {
3132 dtap := l3
3133 }
3134 };
3135 BSSAP.receive(exp_data);
3136 setverdict(pass);
3137 f_sleep(1.0);
3138
3139 setverdict(pass);
3140 f_sleep(1.0);
3141}
3142testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
3143 var MSC_ConnHdlr vc_conn;
3144
3145 f_init(1, true);
3146 f_sleep(1.0);
3147
3148 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
3149 vc_conn.done;
3150}
3151
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02003152/* BSC asks for inter-BSC-out HO, receives BSSMAP Handover Command, but then no reply is received about HO outcome
3153 * (neither BSSMAP Clear Command for success nor RR Handover Failure). 48.008 3.1.5.3.3 "Abnormal Conditions" applies
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02003154 * and the lchan is released. */
3155private function f_tc_ho_out_fail_no_result_after_ho_cmd(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01003156 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003157
3158 var PDU_BSSAP ass_req := f_gen_ass_req();
3159 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3160 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3161 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3162 f_establish_fully(ass_req, exp_compl);
3163
Neels Hofmeyr7e2769f2019-08-14 19:17:53 +02003164 f_bts_0_cfg({"neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003165 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
3166
3167 BSSAP.receive(tr_BSSMAP_HandoverRequired);
3168
3169 f_sleep(0.5);
3170 /* The MSC negotiates Handover Request and Handover Request Ack with
3171 * the other BSS and comes back with a BSSMAP Handover Command
3172 * containing an RR Handover Command coming from the target BSS... */
3173
3174 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
3175 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
3176 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
3177 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
3178 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
3179
3180 /* expect the Handover Command to go out on RR */
3181 var RSL_Message rsl_ho_cmd
3182 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
3183 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
3184 var RSL_IE_Body rsl_ho_cmd_l3;
3185 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
3186 log("RSL message contains no L3 Info IE, expected RR Handover Command");
3187 setverdict(fail);
3188 } else {
3189 log("Found L3 Info: ", rsl_ho_cmd_l3);
3190 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
3191 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
3192 setverdict(fail);
3193 } else {
3194 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
3195 setverdict(pass);
3196 }
3197 }
3198
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02003199 /* We get neither success nor failure report from the remote BSS. Eventually T8 times out and we run into 3GPP
3200 * TS 48.008 3.1.5.3.3 "Abnormal Conditions": Clear Request should go to the MSC, and RR should be released
3201 * after Clear Command */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003202
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02003203 var PDU_BSSAP rx_clear_request;
Neels Hofmeyre1797aa2019-07-09 19:34:04 +02003204 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
3205 log("Got BSSMAP Clear Request");
3206 /* Instruct BSC to clear channel */
3207 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
3208 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3209
3210 var MgcpCommand mgcp;
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003211 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01003212 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
3213 log("Got Deact SACCH");
3214 }
Harald Welte924b6ea2019-02-04 01:05:34 +01003215 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01003216 log("Got RR Release");
3217 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003218 [] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
3219 log("Got RF Chan Rel");
3220 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
3221 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003222 }
3223
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02003224 f_expect_dlcx_conns();
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02003225
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003226 setverdict(pass);
3227 f_sleep(1.0);
3228}
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02003229testcase TC_ho_out_fail_no_result_after_ho_cmd() runs on test_CT {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003230 var MSC_ConnHdlr vc_conn;
3231
3232 f_init(1, true);
3233 f_sleep(1.0);
3234
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02003235 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_result_after_ho_cmd));
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003236 vc_conn.done;
3237}
3238
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003239private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
3240 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
3241 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
3242 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
3243 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
3244 * before we get started. */
3245 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3246 f_rslem_register(0, new_chan_nr);
3247 g_chan_nr := new_chan_nr;
3248 f_sleep(1.0);
3249
3250 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3251 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3252 activate(as_Media());
3253
3254 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3255 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003256 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003257
3258 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3259
3260 var PDU_BSSAP rx_bssap;
3261 var octetstring ho_command_str;
3262
3263 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
Pau Espin Pedrol76ba5412019-06-10 11:00:33 +02003264
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003265 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3266 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3267 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3268 log("L3 Info in HO Request Ack is ", ho_command);
3269
3270 var GsmArfcn arfcn;
3271 var RslChannelNr actual_new_chan_nr;
3272 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3273 actual_new_chan_nr, arfcn);
3274
3275 if (actual_new_chan_nr != new_chan_nr) {
3276 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3277 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3278 setverdict(fail);
3279 return;
3280 }
3281 log("Handover Command chan_nr is", actual_new_chan_nr);
3282
3283 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3284 * tells the MS to handover to the new lchan. Here comes the new MS on
3285 * the new lchan with a Handover RACH: */
3286
3287 /* send handover detect */
3288
3289 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
3290
3291 BSSAP.receive(tr_BSSMAP_HandoverDetect);
3292
3293 /* send handover complete over the new channel */
3294
3295 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
3296 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
3297 enc_PDU_ML3_MS_NW(l3_tx)));
3298
3299 BSSAP.receive(tr_BSSMAP_HandoverComplete);
3300 setverdict(pass);
3301}
3302testcase TC_ho_into_this_bsc() runs on test_CT {
3303 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003304 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003305
3306 f_init(1, true);
3307 f_sleep(1.0);
3308
3309 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3310 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3311
3312 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
3313 vc_conn.done;
3314}
3315
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003316private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
3317 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3318 f_rslem_register(0, new_chan_nr);
3319 g_chan_nr := new_chan_nr;
3320 f_sleep(1.0);
3321
3322 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3323 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3324 activate(as_Media());
3325
3326 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3327 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003328 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003329
3330 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3331
3332 var PDU_BSSAP rx_bssap;
3333 var octetstring ho_command_str;
3334
3335 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3336
3337 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3338 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3339 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3340 log("L3 Info in HO Request Ack is ", ho_command);
3341
3342 var GsmArfcn arfcn;
3343 var RslChannelNr actual_new_chan_nr;
3344 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3345 actual_new_chan_nr, arfcn);
3346
3347 if (actual_new_chan_nr != new_chan_nr) {
3348 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3349 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3350 setverdict(fail);
3351 return;
3352 }
3353 log("Handover Command chan_nr is", actual_new_chan_nr);
3354
Neels Hofmeyr61ca08d2019-05-06 23:52:22 +02003355 /* For deterministic test results, give some time for the MGW endpoint to be configured */
3356 f_sleep(1.0);
3357
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003358 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3359 * tells the MS to handover to the new lchan. In this case, the MS
3360 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
3361 * Handover Failure to the MSC. The procedure according to 3GPP TS
3362 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
3363 * BSSMAP Clear Command: */
3364
3365 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3366 var BssmapCause cause := enum2int(cause_val);
3367 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3368
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02003369 f_expect_dlcx_conns();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003370 setverdict(pass);
3371 f_sleep(1.0);
3372
3373 setverdict(pass);
3374}
3375testcase TC_ho_in_fail_msc_clears() runs on test_CT {
3376 var MSC_ConnHdlr vc_conn;
3377 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3378
3379 f_init(1, true);
3380 f_sleep(1.0);
3381
3382 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3383 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3384
3385 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
3386 vc_conn.done;
3387}
3388
3389private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
3390 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
3391 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
3392 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
3393 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
3394 * before we get started. */
3395 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3396 f_rslem_register(0, new_chan_nr);
3397 g_chan_nr := new_chan_nr;
3398 f_sleep(1.0);
3399
3400 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3401 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3402 activate(as_Media());
3403
3404 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3405 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003406 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003407
3408 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3409
3410 var PDU_BSSAP rx_bssap;
3411 var octetstring ho_command_str;
3412
3413 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3414
3415 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3416 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3417 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3418 log("L3 Info in HO Request Ack is ", ho_command);
3419
3420 var GsmArfcn arfcn;
3421 var RslChannelNr actual_new_chan_nr;
3422 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3423 actual_new_chan_nr, arfcn);
3424
3425 if (actual_new_chan_nr != new_chan_nr) {
3426 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3427 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3428 setverdict(fail);
3429 return;
3430 }
3431 log("Handover Command chan_nr is", actual_new_chan_nr);
3432
3433 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3434 * tells the MS to handover to the new lchan. Here comes the new MS on
3435 * the new lchan with a Handover RACH: */
3436
3437 /* send handover detect */
3438
3439 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
3440
3441 BSSAP.receive(tr_BSSMAP_HandoverDetect);
3442
3443 /* The MSC chooses to clear the connection now, maybe we got the
3444 * Handover RACH on the new cell but the MS still signaled Handover
3445 * Failure to the old BSS? */
3446
3447 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3448 var BssmapCause cause := enum2int(cause_val);
3449 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3450
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02003451 f_expect_dlcx_conns();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003452 setverdict(pass);
3453 f_sleep(1.0);
3454}
3455testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
3456 var MSC_ConnHdlr vc_conn;
3457 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3458
3459 f_init(1, true);
3460 f_sleep(1.0);
3461
3462 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3463 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3464
3465 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
3466 vc_conn.done;
3467}
3468
3469/* The new BSS's lchan times out before the MSC decides that handover failed. */
3470private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
3471 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3472 f_rslem_register(0, new_chan_nr);
3473 g_chan_nr := new_chan_nr;
3474 f_sleep(1.0);
3475
3476 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3477 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3478 activate(as_Media());
3479
3480 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3481 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003482 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003483
3484 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3485
3486 var PDU_BSSAP rx_bssap;
3487 var octetstring ho_command_str;
3488
3489 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3490
3491 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3492 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3493 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3494 log("L3 Info in HO Request Ack is ", ho_command);
3495
3496 var GsmArfcn arfcn;
3497 var RslChannelNr actual_new_chan_nr;
3498 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3499 actual_new_chan_nr, arfcn);
3500
3501 if (actual_new_chan_nr != new_chan_nr) {
3502 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3503 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3504 setverdict(fail);
3505 return;
3506 }
3507 log("Handover Command chan_nr is", actual_new_chan_nr);
3508
3509 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3510 * tells the MS to handover to the new lchan. But the MS never shows up
3511 * on the new lchan. */
3512
3513 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3514
3515 /* Did osmo-bsc also send a Clear Request? */
3516 timer T := 0.5;
3517 T.start;
3518 alt {
3519 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
3520 [] T.timeout { }
3521 }
3522
3523 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
3524 * asked for it, this is a Handover Failure after all). */
3525
3526 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3527 var BssmapCause cause := enum2int(cause_val);
3528 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3529
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02003530 f_expect_dlcx_conns();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003531 setverdict(pass);
3532 f_sleep(1.0);
3533
3534 setverdict(pass);
3535}
3536testcase TC_ho_in_fail_no_detect() runs on test_CT {
3537 var MSC_ConnHdlr vc_conn;
3538 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3539
3540 f_init(1, true);
3541 f_sleep(1.0);
3542
3543 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3544 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3545
3546 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
3547 vc_conn.done;
3548}
3549
3550/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
3551private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
3552 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3553 f_rslem_register(0, new_chan_nr);
3554 g_chan_nr := new_chan_nr;
3555 f_sleep(1.0);
3556
3557 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3558 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3559 activate(as_Media());
3560
3561 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3562 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003563 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003564
3565 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3566
3567 var PDU_BSSAP rx_bssap;
3568 var octetstring ho_command_str;
3569
3570 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3571
3572 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3573 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3574 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3575 log("L3 Info in HO Request Ack is ", ho_command);
3576
3577 var GsmArfcn arfcn;
3578 var RslChannelNr actual_new_chan_nr;
3579 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3580 actual_new_chan_nr, arfcn);
3581
3582 if (actual_new_chan_nr != new_chan_nr) {
3583 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3584 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3585 setverdict(fail);
3586 return;
3587 }
3588 log("Handover Command chan_nr is", actual_new_chan_nr);
3589
3590 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3591 * tells the MS to handover to the new lchan. But the MS never shows up
3592 * on the new lchan. */
3593
3594 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3595
3596 /* MSC plays dumb and sends no Clear Command */
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003597 var PDU_BSSAP rx_clear_request;
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02003598
3599 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003600 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
3601 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3602 };
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02003603 f_expect_dlcx_conns();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003604 setverdict(pass);
3605 f_sleep(1.0);
3606}
3607testcase TC_ho_in_fail_no_detect2() runs on test_CT {
3608 var MSC_ConnHdlr vc_conn;
3609 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3610
3611 f_init(1, true);
3612 f_sleep(1.0);
3613
3614 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3615 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3616
3617 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
3618 vc_conn.done;
3619}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003620
Neels Hofmeyr91401012019-07-11 00:42:35 +02003621type record of charstring Commands;
3622
3623private function f_bts_0_cfg(Commands cmds := {}) runs on MSC_ConnHdlr
3624{
3625 f_vty_enter_cfg_bts(BSCVTY, 0);
3626 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
3627 f_vty_transceive(BSCVTY, cmds[i]);
3628 }
3629 f_vty_transceive(BSCVTY, "end");
3630}
3631
3632private function f_probe_for_handover(charstring log_label,
3633 charstring log_descr,
3634 charstring handover_vty_cmd,
3635 boolean expect_handover,
3636 boolean is_inter_bsc_handover := false)
3637runs on MSC_ConnHdlr
3638{
3639 var RSL_Message rsl;
3640
3641 var charstring log_msg := " (expecting handover)"
3642 if (not expect_handover) {
3643 log_msg := " (expecting NO handover)";
3644 }
3645 log("f_probe_for_handover starting: " & log_label & ": " & log_descr & log_msg);
3646 f_vty_transceive(BSCVTY, handover_vty_cmd);
3647
3648 /* We're going to thwart any and all handover attempts, just be ready to handle (and ignore) handover target
3649 * lchans to be established on bts 1 or bts 2. */
3650 f_rslem_suspend(RSL1_PROC);
3651 f_rslem_suspend(RSL2_PROC);
3652
3653 timer T := 2.0;
3654 T.start;
3655
3656 alt {
3657 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
3658 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
3659 log("Rx L3 from net: ", l3);
3660 if (ischosen(l3.msgs.rrm.handoverCommand)) {
3661 var RslChannelNr new_chan_nr;
3662 var GsmArfcn arfcn;
3663 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
3664 new_chan_nr, arfcn);
3665 log("Handover to new chan ", new_chan_nr, " on ARFCN ", arfcn);
3666 log(l3.msgs.rrm.handoverCommand);
3667
3668 /* Need to register for new lchan on new BTS -- it's either bts 1 or bts 2. It doesn't really
3669 * matter on which BTS it really is, we're not going to follow through an entire handover
3670 * anyway. */
3671 f_rslem_register(0, new_chan_nr, RSL1_PROC);
3672 f_rslem_resume(RSL1_PROC);
3673 f_rslem_register(0, new_chan_nr, RSL2_PROC);
3674 f_rslem_resume(RSL2_PROC);
3675
3676 if (expect_handover and not is_inter_bsc_handover) {
3677 setverdict(pass);
3678 log("f_probe_for_handover(" & log_label & "): Got RSL Handover Command as expected.");
3679 } else {
3680 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got RSL Handover Command. "
3681 & log_label & ": " & log_descr);
3682 }
3683
3684 log("f_probe_for_handover(" & log_label & "): Ending the test: Handover Failure stops the procedure.");
3685 /* osmo-bsc has triggered Handover. That's all we need to know for this test, reply with
3686 * Handover Failure. */
3687 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
3688
3689 /* target BTS is told to release lchan again; don't care which BTS nor what messages. */
3690 f_sleep(0.5);
3691 RSL1.clear;
3692 RSL2.clear;
3693 log("f_probe_for_handover(" & log_label & "): done (got RSL Handover Command)");
3694 break;
3695 } else {
3696 repeat;
3697 }
3698 }
3699 [] BSSAP.receive(tr_BSSMAP_HandoverRequired) {
3700 if (expect_handover and is_inter_bsc_handover) {
3701 setverdict(pass);
3702 log("f_probe_for_handover(" & log_label & "): Got BSSMAP Handover Required as expected.");
3703 } else {
3704 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got BSSMAP Handover Required. "
3705 & log_label & ": " & log_descr);
3706 }
3707
3708 log("f_probe_for_handover(" & log_label & "): done (got BSSMAP Handover Required)");
3709
3710 /* Note: f_tc_ho_neighbor_config_start() sets T7, the timeout for BSSMAP Handover Required, to
3711 * 1 second. There is no legal way to quickly abort a handover after a BSSMAP Handover Required,
3712 * setting a short timeout and waiting is the only way. */
3713 log("f_probe_for_handover(" & log_label & "): waiting for inter-BSC HO to time out...");
3714 f_sleep(1.5);
3715 log("f_probe_for_handover(" & log_label & "): ...done");
3716
3717 break;
3718 }
3719 [] T.timeout {
3720 if (expect_handover) {
3721 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected Handover, but got none. "
3722 & log_label & ": " & log_descr);
3723 } else {
3724 setverdict(pass);
3725 log("f_probe_for_handover(" & log_label & "): Got no Handover, as expected.");
3726 }
3727 log("f_probe_for_handover(" & log_label & "): done (got no Handover)");
3728 break;
3729 }
3730 }
3731
3732 f_rslem_resume(RSL1_PROC);
3733 f_rslem_resume(RSL2_PROC);
3734 f_sleep(3.0);
3735 RSL.clear;
3736
3737 log("f_probe_for_handover(" & log_label & "): done clearing");
3738}
3739
3740/* Test the effect of various neighbor configuration scenarios:
3741 *
3742 * To avoid complexity, block off any actual handover operation, and always remain on the lchan at bts 0.
3743 * Reconfigure the neighbors for bts 0, trigger a Handover, and probe whether osmo-bsc does or doesn't start HO.
3744 */
3745private function f_tc_ho_neighbor_config_start() runs on MSC_ConnHdlr {
3746 g_pars := f_gen_test_hdlr_pars();
3747 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3748 var PDU_BSSAP ass_cmd := f_gen_ass_req();
3749 const OCT8 kc := '0001020304050607'O;
3750
3751 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3752 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3753
3754 /* Establish lchan at bts 0 */
3755 f_establish_fully(ass_cmd, exp_compl);
3756
3757 /* Shorten the inter-BSC Handover timeout, to not wait so long for inter-BSC Handovers */
3758 f_vty_enter_cfg_network(BSCVTY);
3759 f_vty_transceive(BSCVTY, "timer T7 1");
3760 f_vty_transceive(BSCVTY, "end");
3761}
3762
3763private function f_tc_ho_neighbor_config_1(charstring id) runs on MSC_ConnHdlr {
3764 f_tc_ho_neighbor_config_start();
3765
3766 /*
3767 * bts 0 ARFCN 871 BSIC 10
3768 * bts 1 ARFCN 871 BSIC 11
3769 * bts 2 ARFCN 871 BSIC 12
3770 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
3771 */
3772
3773 log("f_tc_ho_neighbor_config: 1. No 'neighbor' config");
3774 f_bts_0_cfg({"no neighbors"});
3775 f_probe_for_handover("1.a", "HO to bts 1 works, implicitly listed as neighbor (legacy behavior when none are configured)",
3776 "handover any to arfcn 871 bsic 11",
3777 true);
3778
3779 f_probe_for_handover("1.b", "HO to unknown cell does not start",
3780 "handover any to arfcn 13 bsic 39",
3781 false);
3782
3783 f_probe_for_handover("1.c", "HO to 871-12 is ambiguous = error",
3784 "handover any to arfcn 871 bsic 12",
3785 false);
3786
3787 f_probe_for_handover("1.d", "HO to 871-11 still works (verify that this test properly cleans up)",
3788 "handover any to arfcn 871 bsic 11",
3789 true);
3790}
3791private function f_tc_ho_neighbor_config_2(charstring id) runs on MSC_ConnHdlr {
3792 f_tc_ho_neighbor_config_start();
3793
3794 /*
3795 * bts 0 ARFCN 871 BSIC 10
3796 * bts 1 ARFCN 871 BSIC 11
3797 * bts 2 ARFCN 871 BSIC 12
3798 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
3799 */
3800
3801 log("f_tc_ho_neighbor_config: 2. explicit local neighbor: 'neighbor bts 1'");
3802 f_bts_0_cfg({"neighbor bts 1"});
3803 f_sleep(0.5);
3804
3805 f_probe_for_handover("2.a", "HO to bts 1 works, explicitly listed as neighbor",
3806 "handover any to arfcn 871 bsic 11",
3807 true);
3808
3809 f_probe_for_handover("2.b", "HO to bts 2 doesn't work, not listed as neighbor",
3810 "handover any to arfcn 871 bsic 12",
3811 false);
3812}
3813private function f_tc_ho_neighbor_config_3(charstring id) runs on MSC_ConnHdlr {
3814 f_tc_ho_neighbor_config_start();
3815
3816 /*
3817 * bts 0 ARFCN 871 BSIC 10
3818 * bts 1 ARFCN 871 BSIC 11
3819 * bts 2 ARFCN 871 BSIC 12
3820 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
3821 */
3822
3823 log("f_tc_ho_neighbor_config: 3. explicit local neighbor: 'neighbor bts 2'");
3824 f_bts_0_cfg({"no neighbors", "neighbor bts 2"});
3825 f_sleep(0.5);
3826
3827 f_probe_for_handover("3.a", "HO to bts 1 doesn't work, not listed as neighbor",
3828 "handover any to arfcn 871 bsic 11",
3829 false);
3830 f_probe_for_handover("3.b", "HO to bts 2 works, explicitly listed as neighbor; no ambiguity because bts 3 is not listed as neighbor",
3831 "handover any to arfcn 871 bsic 12",
3832 true);
3833}
3834private function f_tc_ho_neighbor_config_4(charstring id) runs on MSC_ConnHdlr {
3835 f_tc_ho_neighbor_config_start();
3836
3837 /*
3838 * bts 0 ARFCN 871 BSIC 10
3839 * bts 1 ARFCN 871 BSIC 11
3840 * bts 2 ARFCN 871 BSIC 12
3841 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
3842 */
3843
3844 log("f_tc_ho_neighbor_config: 4. explicit remote neighbor: 'neighbor lac 99 arfcn 123 bsic 45'");
3845 f_bts_0_cfg({"no neighbors", "neighbor lac 99 arfcn 123 bsic 45"});
3846 f_sleep(0.5);
3847
3848 f_probe_for_handover("4.a", "HO to bts 1 doesn't work, not listed as neighbor",
3849 "handover any to arfcn 871 bsic 11",
3850 false);
3851 f_probe_for_handover("4.b", "HO to bts 2 doesn't work, not listed as neighbor",
3852 "handover any to arfcn 871 bsic 12",
3853 false);
3854 f_probe_for_handover("4.c", "HO to 123-45 triggers inter-BSC HO",
3855 "handover any to arfcn 123 bsic 45",
3856 true, true);
3857}
3858private function f_tc_ho_neighbor_config_5(charstring id) runs on MSC_ConnHdlr {
3859 f_tc_ho_neighbor_config_start();
3860
3861 /*
3862 * bts 0 ARFCN 871 BSIC 10
3863 * bts 1 ARFCN 871 BSIC 11
3864 * bts 2 ARFCN 871 BSIC 12
3865 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
3866 */
3867
3868 log("f_tc_ho_neighbor_config: 5. explicit remote neighbor re-using ARFCN+BSIC: 'neighbor lac 99 arfcn 871 bsic 12'");
3869 f_bts_0_cfg({"no neighbors", "neighbor lac 99 arfcn 871 bsic 12"});
3870 f_sleep(0.5);
3871
3872 f_probe_for_handover("5.a", "HO to 871-12 triggers inter-BSC HO (ignoring local cells with same ARFCN+BSIC)",
3873 "handover any to arfcn 871 bsic 12",
3874 true, true);
3875}
3876private function f_tc_ho_neighbor_config_6(charstring id) runs on MSC_ConnHdlr {
3877 f_tc_ho_neighbor_config_start();
3878
3879 /*
3880 * bts 0 ARFCN 871 BSIC 10
3881 * bts 1 ARFCN 871 BSIC 11
3882 * bts 2 ARFCN 871 BSIC 12
3883 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
3884 */
3885
3886 log("f_tc_ho_neighbor_config: 6. config error: explicit local and remote neighbors with ambiguous ARFCN+BSIC:"
3887 & " 'neighbor bts 2; neighbor lac 99 arfcn 871 bsic 12'");
3888 f_bts_0_cfg({"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 871 bsic 12"});
3889 f_sleep(0.5);
3890
3891 f_probe_for_handover("6.a", "HO to 871-12 is ambiguous = error",
3892 "handover any to arfcn 871 bsic 12",
3893 false);
3894}
3895private function f_tc_ho_neighbor_config_7(charstring id) runs on MSC_ConnHdlr {
3896 f_tc_ho_neighbor_config_start();
3897
3898 /*
3899 * bts 0 ARFCN 871 BSIC 10
3900 * bts 1 ARFCN 871 BSIC 11
3901 * bts 2 ARFCN 871 BSIC 12
3902 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
3903 */
3904
3905 log("f_tc_ho_neighbor_config: 7. explicit local and remote neighbors:"
3906 & " 'neighbor bts 2; neighbor lac 99 arfcn 123 bsic 45'");
3907 f_bts_0_cfg({"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 123 bsic 45"});
3908 f_sleep(0.5);
3909
3910 f_probe_for_handover("7.a", "HO to 871-12 does HO to bts 2",
3911 "handover any to arfcn 871 bsic 12",
3912 true);
3913 f_probe_for_handover("7.b", "HO to 123-45 triggers inter-BSC HO",
3914 "handover any to arfcn 123 bsic 45",
3915 true, true);
3916}
3917
3918testcase TC_ho_neighbor_config_1() runs on test_CT {
3919 var MSC_ConnHdlr vc_conn;
3920 f_init(3, true);
3921 f_sleep(1.0);
3922 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_1));
3923 vc_conn.done;
3924}
3925testcase TC_ho_neighbor_config_2() runs on test_CT {
3926 var MSC_ConnHdlr vc_conn;
3927 f_init(3, true);
3928 f_sleep(1.0);
3929 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_2));
3930 vc_conn.done;
3931}
3932testcase TC_ho_neighbor_config_3() runs on test_CT {
3933 var MSC_ConnHdlr vc_conn;
3934 f_init(3, true);
3935 f_sleep(1.0);
3936 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_3));
3937 vc_conn.done;
3938}
3939testcase TC_ho_neighbor_config_4() runs on test_CT {
3940 var MSC_ConnHdlr vc_conn;
3941 f_init(3, true);
3942 f_sleep(1.0);
3943 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_4));
3944 vc_conn.done;
3945}
3946testcase TC_ho_neighbor_config_5() runs on test_CT {
3947 var MSC_ConnHdlr vc_conn;
3948 f_init(3, true);
3949 f_sleep(1.0);
3950 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_5));
3951 vc_conn.done;
3952}
3953testcase TC_ho_neighbor_config_6() runs on test_CT {
3954 var MSC_ConnHdlr vc_conn;
3955 f_init(3, true);
3956 f_sleep(1.0);
3957 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_6));
3958 vc_conn.done;
3959}
3960testcase TC_ho_neighbor_config_7() runs on test_CT {
3961 var MSC_ConnHdlr vc_conn;
3962 f_init(3, true);
3963 f_sleep(1.0);
3964 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_7));
3965 vc_conn.done;
3966}
3967
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003968/* OS#3041: Open and close N connections in a normal fashion, and expect no
3969 * BSSMAP Reset just because of that. */
3970testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
3971 var default d;
3972 var integer i;
3973 var DchanTuple dt;
3974
3975 f_init();
3976
3977 /* Wait for initial BSSMAP Reset to pass */
3978 f_sleep(4.0);
3979
3980 d := activate(no_bssmap_reset());
3981
3982 /* Setup up a number of connections and RLSD them again from the MSC
3983 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3984 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02003985 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003986 /* Since we're doing a lot of runs, give each one a fresh
3987 * T_guard from the top. */
3988 T_guard.start;
3989
3990 /* Setup a BSSAP connection and clear it right away. This is
3991 * the MSC telling the BSC about a planned release, it's not an
3992 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02003993 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003994
3995 /* MSC disconnects (RLSD). */
3996 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
3997 }
3998
3999 /* In the buggy behavior, a timeout of 2 seconds happens between above
4000 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
4001 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
4002 f_sleep(4.0);
4003
4004 deactivate(d);
4005 f_shutdown_helper();
4006}
Harald Welte552620d2017-12-16 23:21:36 +01004007
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01004008/* OS#3041: Open and close N connections in a normal fashion, and expect no
4009 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
4010 * the MSC. */
4011testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
4012 var default d;
4013 var integer i;
4014 var DchanTuple dt;
4015 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01004016 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
4017 var BssmapCause cause := enum2int(cause_val);
4018
4019 f_init();
4020
4021 /* Wait for initial BSSMAP Reset to pass */
4022 f_sleep(4.0);
4023
4024 d := activate(no_bssmap_reset());
4025
4026 /* Setup up a number of connections and RLSD them again from the MSC
4027 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
4028 * Let's do it some more times for good measure. */
4029 for (i := 0; i < 8; i := i+1) {
4030 /* Since we're doing a lot of runs, give each one a fresh
4031 * T_guard from the top. */
4032 T_guard.start;
4033
4034 /* Setup a BSSAP connection and clear it right away. This is
4035 * the MSC telling the BSC about a planned release, it's not an
4036 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02004037 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01004038
4039 /* Instruct BSC to clear channel */
4040 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
4041
4042 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02004043 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01004044 }
4045
4046 /* In the buggy behavior, a timeout of 2 seconds happens between above
4047 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
4048 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
4049 f_sleep(4.0);
4050
4051 deactivate(d);
4052 f_shutdown_helper();
4053}
4054
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01004055/* OS#3041: Open and close N connections in a normal fashion, and expect no
4056 * BSSMAP Reset just because of that. Close connections from the MS side with a
4057 * Release Ind on RSL. */
4058testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
4059 var default d;
4060 var integer i;
4061 var DchanTuple dt;
4062 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01004063 var integer j;
4064
4065 f_init();
4066
4067 /* Wait for initial BSSMAP Reset to pass */
4068 f_sleep(4.0);
4069
4070 d := activate(no_bssmap_reset());
4071
4072 /* Setup up a number of connections and RLSD them again from the MSC
4073 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
4074 * Let's do it some more times for good measure. */
4075 for (i := 0; i < 8; i := i+1) {
4076 /* Since we're doing a lot of runs, give each one a fresh
4077 * T_guard from the top. */
4078 T_guard.start;
4079
4080 /* Setup a BSSAP connection and clear it right away. This is
4081 * the MSC telling the BSC about a planned release, it's not an
4082 * erratic loss of a connection. */
4083 dt := f_est_dchan('23'O, 23, '00010203040506'O);
4084
4085 /* simulate RLL REL IND */
4086 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
4087
4088 /* expect Clear Request on MSC side */
4089 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
4090
4091 /* Instruct BSC to clear channel */
4092 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
4093 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
4094
4095 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02004096 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01004097 }
4098
4099 /* In the buggy behavior, a timeout of 2 seconds happens between above
4100 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
4101 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
4102 f_sleep(4.0);
4103
4104 deactivate(d);
4105 f_shutdown_helper();
4106}
4107
Harald Welte94e0c342018-04-07 11:33:23 +02004108/***********************************************************************
4109 * IPA style dynamic PDCH
4110 ***********************************************************************/
4111
4112private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
4113 template (omit) RSL_Cause nack := omit)
4114runs on test_CT {
4115 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
4116 var RSL_Message rsl_unused;
4117 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
4118 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
4119 /* expect the BSC to issue the related RSL command */
4120 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
4121 if (istemplatekind(nack, "omit")) {
4122 /* respond with a related acknowledgement */
4123 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
4124 } else {
4125 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
4126 }
4127}
4128
4129private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
4130 template (omit) RSL_Cause nack := omit)
4131runs on test_CT {
4132 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
4133 var RSL_Message rsl_unused;
4134 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
4135 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
4136 /* expect the BSC to issue the related RSL command */
4137 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
4138 if (istemplatekind(nack, "omit")) {
4139 /* respond with a related acknowledgement */
4140 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
4141 } else {
4142 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
4143 }
4144}
4145
4146private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
4147runs on test_CT return charstring {
4148 var charstring cmd, resp;
4149 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01004150 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02004151}
4152
4153private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
4154 template charstring exp)
4155runs on test_CT {
4156 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
4157 if (not match(mode, exp)) {
4158 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02004159 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02004160 }
4161}
4162
4163private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
4164runs on test_CT {
4165 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
4166 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
4167 f_vty_transceive(BSCVTY, "end");
4168}
4169
4170private const charstring TCHF_MODE := "TCH/F mode";
4171private const charstring TCHH_MODE := "TCH/H mode";
4172private const charstring PDCH_MODE := "PDCH mode";
4173private const charstring NONE_MODE := "NONE mode";
4174
4175/* Test IPA PDCH activation / deactivation triggered by VTY */
4176testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
4177 var RSL_Message rsl_unused;
4178
4179 /* change Timeslot 6 before f_init() starts RSL */
4180 f_init_vty();
4181 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
4182 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
4183
4184 f_init(1, false);
4185 f_sleep(1.0);
4186
4187 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
4188
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02004189 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02004190 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
4191 /* The BSC will activate the dynamic PDCH by default, so confirm that */
4192 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
4193 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
4194 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02004195 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02004196 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
4197
4198 /* De-activate it via VTY */
4199 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
4200 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02004201 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02004202 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
4203
4204 /* re-activate it via VTY */
4205 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
4206 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02004207 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02004208 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
4209
4210 /* and finally de-activate it again */
4211 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
4212 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02004213 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02004214 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
4215
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02004216 /* clean up config */
4217 f_ts_set_chcomb(0, 0, 6, "PDCH");
4218
Harald Welte94e0c342018-04-07 11:33:23 +02004219 setverdict(pass);
4220}
4221
4222/* Test IPA PDCH activation NACK */
4223testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
4224 var RSL_Message rsl_unused;
4225
4226 /* change Timeslot 6 before f_init() starts RSL */
4227 f_init_vty();
4228 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
4229 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
4230
4231 f_init(1, false);
4232 f_sleep(1.0);
4233
4234 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
4235
4236 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
4237 /* The BSC will activate the dynamic PDCH by default, so confirm that */
4238 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
4239 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
4240 f_sleep(1.0);
4241 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
4242
4243 /* De-activate it via VTY */
4244 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
4245 f_sleep(1.0);
4246 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
4247
4248 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
4249 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
4250 f_sleep(1.0);
4251 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
4252
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02004253 /* clean up config */
4254 f_ts_set_chcomb(0, 0, 6, "PDCH");
4255
Harald Welte94e0c342018-04-07 11:33:23 +02004256 setverdict(pass);
4257}
4258
4259
4260/***********************************************************************
4261 * Osmocom style dynamic PDCH
4262 ***********************************************************************/
4263
4264private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
4265 template (omit) RSL_Cause nack := omit)
4266runs on test_CT {
4267 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
4268 var RSL_Message rsl_unused;
4269 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
4270 /* FIXME: no VTY command to activate Osmocom PDCH !! */
4271 /* expect the BSC to issue the related RSL command */
4272 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
4273 if (istemplatekind(nack, "omit")) {
4274 /* respond with a related acknowledgement */
4275 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
4276 } else {
4277 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
4278 }
4279}
4280
4281private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
4282 template (omit) RSL_Cause nack := omit)
4283runs on test_CT {
4284 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
4285 var RSL_Message rsl_unused;
4286 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
4287 /* FIXME: no VTY command to activate Osmocom PDCH !! */
4288 /* expect the BSC to issue the related RSL command */
4289 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
4290 if (istemplatekind(nack, "omit")) {
4291 /* respond with a related acknowledgement */
4292 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
4293 } else {
4294 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
4295 }
4296}
4297
4298/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
4299testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
4300 var RSL_Message rsl_unused;
4301
4302 /* change Timeslot 6 before f_init() starts RSL */
4303 f_init_vty();
4304 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
4305 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
4306
4307 f_init(1, false);
4308 f_sleep(1.0);
4309
4310 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
4311
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02004312 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02004313 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
4314 /* The BSC will activate the dynamic PDCH by default, so confirm that */
4315 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
4316
4317 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
4318 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02004319 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 +02004320 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
4321
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02004322 /* clean up config */
4323 f_ts_set_chcomb(0, 0, 6, "PDCH");
4324
Harald Welte94e0c342018-04-07 11:33:23 +02004325 setverdict(pass);
4326}
4327
4328/* Test Osmocom dyn PDCH activation NACK behavior */
4329testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
4330 var RSL_Message rsl_unused;
4331
4332 /* change Timeslot 6 before f_init() starts RSL */
4333 f_init_vty();
4334 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
4335 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
4336
4337 f_init(1, false);
4338 f_sleep(1.0);
4339
4340 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
4341
4342 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
4343 /* The BSC will activate the dynamic PDCH by default, so confirm that */
4344 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
4345
4346 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
4347 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
4348 f_sleep(1.0);
4349 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
4350
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02004351 /* clean up config */
4352 f_ts_set_chcomb(0, 0, 6, "PDCH");
4353
Harald Welte94e0c342018-04-07 11:33:23 +02004354 setverdict(pass);
4355}
4356
Stefan Sperling0796a822018-10-05 13:01:39 +02004357testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02004358 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02004359 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
4360 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
4361 }
4362}
4363
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02004364testcase TC_chopped_ipa_payload() runs on test_CT {
4365 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
4366 /* TODO: mp_bsc_ctrl_port does not work yet */};
4367 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
4368 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
4369 }
4370}
4371
4372
Harald Welte0ea2d5e2018-04-07 21:40:29 +02004373/* Dyn PDCH todo:
4374 * activate OSMO as TCH/F
4375 * activate OSMO as TCH/H
4376 * does the BSC-located PCU socket get the updated INFO?
4377 * what if no PCU is connected at the time?
4378 * is the info correct on delayed PCU (re)connect?
4379 */
Harald Welte94e0c342018-04-07 11:33:23 +02004380
Harald Welte28d943e2017-11-25 15:00:50 +01004381control {
Harald Welte898113b2018-01-31 18:32:21 +01004382 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +01004383 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01004384 execute( TC_ctrl_msc0_connection_status() );
Harald Welte96c94412017-12-09 03:12:45 +01004385 execute( TC_ctrl() );
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02004386 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_SCCPlite_SERVER) {
4387 execute( TC_ctrl_location() );
4388 }
Harald Welte898113b2018-01-31 18:32:21 +01004389
4390 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +01004391 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +01004392 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +01004393 execute( TC_chan_act_ack_noest() );
4394 execute( TC_chan_act_ack_est_ind_noreply() );
4395 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +01004396 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +01004397 execute( TC_chan_exhaustion() );
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07004398 execute( TC_chan_deact_silence() );
Harald Welte4003d112017-12-09 22:35:39 +01004399 execute( TC_chan_rel_rll_rel_ind() );
4400 execute( TC_chan_rel_conn_fail() );
4401 execute( TC_chan_rel_hard_clear() );
Harald Welte99787102019-02-04 10:41:36 +01004402 execute( TC_chan_rel_hard_clear_csfb() );
Harald Welted8c36cd2017-12-09 23:05:31 +01004403 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +02004404 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +01004405 execute( TC_chan_rel_a_reset() );
Harald Welte6f521d82017-12-11 19:52:02 +01004406
Harald Weltecfe2c962017-12-15 12:09:32 +01004407 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +01004408
4409 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +01004410 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +01004411 execute( TC_assignment_csd() );
4412 execute( TC_assignment_ctm() );
4413 execute( TC_assignment_sign() );
4414 execute( TC_assignment_fr_a5_0() );
4415 execute( TC_assignment_fr_a5_1() );
Harald Welte8f67d1d2018-05-25 20:38:42 +02004416 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
4417 execute( TC_assignment_fr_a5_1_codec_missing() );
4418 }
Harald Welte235ebf12017-12-15 14:18:16 +01004419 execute( TC_assignment_fr_a5_3() );
4420 execute( TC_assignment_fr_a5_4() );
Harald Welte3c86ea02018-05-10 22:28:05 +02004421 execute( TC_ciph_mode_a5_0() );
4422 execute( TC_ciph_mode_a5_1() );
4423 execute( TC_ciph_mode_a5_3() );
Harald Welte16a4adf2017-12-14 18:54:01 +01004424
Harald Welte60aa5762018-03-21 19:33:13 +01004425 execute( TC_assignment_codec_fr() );
4426 execute( TC_assignment_codec_hr() );
4427 execute( TC_assignment_codec_efr() );
4428 execute( TC_assignment_codec_amr_f() );
4429 execute( TC_assignment_codec_amr_h() );
Philipp Maier8a581d22019-03-26 18:32:48 +01004430
4431 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
4432 execute( TC_assignment_codec_amr_f_S1() );
4433 execute( TC_assignment_codec_amr_h_S1() );
4434 execute( TC_assignment_codec_amr_f_S124() );
4435 execute( TC_assignment_codec_amr_h_S124() );
4436 execute( TC_assignment_codec_amr_f_S0() );
4437 execute( TC_assignment_codec_amr_f_S02() );
4438 execute( TC_assignment_codec_amr_f_S024() );
4439 execute( TC_assignment_codec_amr_f_S0247() );
4440 execute( TC_assignment_codec_amr_h_S0() );
4441 execute( TC_assignment_codec_amr_h_S02() );
4442 execute( TC_assignment_codec_amr_h_S024() );
4443 execute( TC_assignment_codec_amr_h_S0247() );
4444 execute( TC_assignment_codec_amr_f_S01234567() );
4445 execute( TC_assignment_codec_amr_f_S0234567() );
4446 execute( TC_assignment_codec_amr_f_zero() );
4447 execute( TC_assignment_codec_amr_f_unsupp() );
4448 execute( TC_assignment_codec_amr_h_S7() );
4449 }
Harald Welte60aa5762018-03-21 19:33:13 +01004450
Philipp Maierac09bfc2019-01-08 13:41:39 +01004451 execute( TC_assignment_codec_fr_exhausted_req_hr() );
4452 execute( TC_assignment_codec_fr_exhausted_req_fr() );
4453 execute( TC_assignment_codec_fr_exhausted_req_fr_hr() );
4454 execute( TC_assignment_codec_fr_exhausted_req_hr_fr() );
4455 execute( TC_assignment_codec_hr_exhausted_req_fr() );
4456 execute( TC_assignment_codec_hr_exhausted_req_hr() );
4457 execute( TC_assignment_codec_hr_exhausted_req_hr_fr() );
4458 execute( TC_assignment_codec_hr_exhausted_req_fr_hr() );
4459 execute( TC_assignment_codec_req_hr_fr() );
4460 execute( TC_assignment_codec_req_fr_hr() );
4461
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +02004462 if (mp_enable_osmux_test) {
4463 execute( TC_assignment_osmux() );
4464 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004465
Harald Welte898113b2018-01-31 18:32:21 +01004466 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +01004467 execute( TC_rll_est_ind_inact_lchan() );
4468 execute( TC_rll_est_ind_inval_sapi1() );
4469 execute( TC_rll_est_ind_inval_sapi3() );
4470 execute( TC_rll_est_ind_inval_sacch() );
4471
Harald Welte898113b2018-01-31 18:32:21 +01004472 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +01004473 execute( TC_paging_imsi_nochan() );
4474 execute( TC_paging_tmsi_nochan() );
4475 execute( TC_paging_tmsi_any() );
4476 execute( TC_paging_tmsi_sdcch() );
4477 execute( TC_paging_tmsi_tch_f() );
4478 execute( TC_paging_tmsi_tch_hf() );
4479 execute( TC_paging_imsi_nochan_cgi() );
4480 execute( TC_paging_imsi_nochan_lac_ci() );
4481 execute( TC_paging_imsi_nochan_ci() );
4482 execute( TC_paging_imsi_nochan_lai() );
4483 execute( TC_paging_imsi_nochan_lac() );
4484 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +01004485 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
4486 execute( TC_paging_imsi_nochan_rnc() );
4487 execute( TC_paging_imsi_nochan_lac_rnc() );
4488 execute( TC_paging_imsi_nochan_lacs() );
4489 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +01004490 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +01004491 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +01004492 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +01004493 execute( TC_paging_counter() );
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01004494 execute( TC_paging_resp_unsol() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +01004495
4496 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +01004497 execute( TC_rsl_unknown_unit_id() );
4498
4499 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +01004500
4501 execute( TC_classmark() );
4502 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +01004503 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004504 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +01004505 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +01004506 execute( TC_err_84_unknown_msg() );
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004507
Harald Welte261af4b2018-02-12 21:20:39 +01004508 execute( TC_ho_int() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004509
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004510 execute( TC_ho_out_of_this_bsc() );
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004511 execute( TC_ho_out_fail_no_msc_response() );
4512 execute( TC_ho_out_fail_rr_ho_failure() );
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02004513 execute( TC_ho_out_fail_no_result_after_ho_cmd() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004514
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004515 execute( TC_ho_into_this_bsc() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004516 execute( TC_ho_in_fail_msc_clears() );
4517 execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
4518 execute( TC_ho_in_fail_no_detect() );
4519 execute( TC_ho_in_fail_no_detect2() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01004520
Neels Hofmeyr91401012019-07-11 00:42:35 +02004521 execute( TC_ho_neighbor_config_1() );
4522 execute( TC_ho_neighbor_config_2() );
4523 execute( TC_ho_neighbor_config_3() );
4524 execute( TC_ho_neighbor_config_4() );
4525 execute( TC_ho_neighbor_config_5() );
4526 execute( TC_ho_neighbor_config_6() );
4527 execute( TC_ho_neighbor_config_7() );
4528
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01004529 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01004530 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01004531 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +02004532
4533 execute( TC_dyn_pdch_ipa_act_deact() );
4534 execute( TC_dyn_pdch_ipa_act_nack() );
4535 execute( TC_dyn_pdch_osmo_act_deact() );
4536 execute( TC_dyn_pdch_osmo_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +02004537
Stefan Sperling0796a822018-10-05 13:01:39 +02004538 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02004539 execute( TC_chopped_ipa_payload() );
Stefan Sperling0796a822018-10-05 13:01:39 +02004540
Harald Welte99f3ca02018-06-14 13:40:29 +02004541 /* at bottom as they might crash OsmoBSC before OS#3182 is fixed */
4542 execute( TC_early_conn_fail() );
4543 execute( TC_late_conn_fail() );
4544
Harald Welte28d943e2017-11-25 15:00:50 +01004545}
4546
4547}