blob: 4497a2ee74e1e1782f29b140387a460ba870fe81 [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");
Harald Welte44bdaa52017-12-17 17:01:47 +01001191 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "3");
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
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001607/* Verify how we handle unsolicited Paging Response, for instance because we
1608 * receive a Paging Response after T3113 expired (and subscriber information was
1609 * dropped). See OS#3680.
1610 */
1611testcase TC_paging_resp_unsol() runs on test_CT {
1612
1613 f_init(1);
1614
1615 var BSSAP_N_CONNECT_ind rx_c_ind;
1616 var DchanTuple dt;
1617 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
1618
1619 /* Send CHAN RQD and wait for allocation; acknowledge it */
1620 dt.rsl_chan_nr := f_chreq_act_ack();
1621
1622 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
1623 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
1624
1625 /* expect BSC to disable the channel */
Pau Espin Pedrol5ee6f6c2018-12-07 12:07:43 +01001626 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001627 setverdict(pass);
1628
1629}
1630
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001631/* Test RSL link drop causes counter increment */
1632testcase TC_rsl_drop_counter() runs on test_CT {
1633 var integer rsl_fail;
1634
Harald Welte89d42e82017-12-17 16:42:41 +01001635 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001636
1637 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
1638
1639 bts[0].rsl.vc_IPA.stop;
1640
1641 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
1642
1643 setverdict(pass);
1644}
1645
1646/* TODO: Test OML link drop causes counter increment */
1647
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001648/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
1649function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
1650 timer T := 10.0;
1651
1652 bts[0].rsl.id := "IPA-0-RSL";
1653 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
1654 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
1655 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
1656 bts[0].rsl.ccm_pars.unit_id := "0/0/0"; /* value which is unknown at BTS */
1657
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001658 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
1659
1660 f_init_mgcp("VirtMSC");
1661
1662 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
1663 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
1664 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
1665 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
1666
1667 /* wait for IPA OML link to connect and then disconnect */
1668 T.start;
1669 alt {
1670 [] IPA_RSL[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) {
1671 T.stop;
1672 return true;
1673 }
1674 [] IPA_RSL[0].receive { repeat }
1675 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02001676 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001677 }
1678 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001679 return false;
1680}
1681
1682/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1683testcase TC_rsl_unknown_unit_id() runs on test_CT {
1684 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
1685 setverdict(pass);
1686 } else {
1687 setverdict(fail, "Timeout RSL waiting for connection to close");
1688 }
1689}
1690
1691
1692/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1693testcase TC_oml_unknown_unit_id() runs on test_CT {
1694 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
1695 setverdict(pass);
1696 } else {
1697 setverdict(fail, "Timeout OML waiting for connection to close");
1698 }
1699}
1700
1701
Harald Weltec1a2fff2017-12-17 11:06:19 +01001702/***********************************************************************
Harald Welte6811d102019-04-14 22:23:14 +02001703 * "New world" test cases using RSL_Emulation + RAN_Emulation
Harald Weltec1a2fff2017-12-17 11:06:19 +01001704 ***********************************************************************/
1705
Harald Welte6811d102019-04-14 22:23:14 +02001706import from RAN_Emulation all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01001707import from RSL_Emulation all;
1708import from MSC_ConnectionHandler all;
1709
1710type function void_fn(charstring id) runs on MSC_ConnHdlr;
1711
Harald Welte336820c2018-05-31 20:34:52 +02001712/* helper function to create and connect a MSC_ConnHdlr component */
Harald Welteff579f92018-05-31 22:19:39 +02001713private function f_connect_handler(inout MSC_ConnHdlr vc_conn) runs on test_CT {
Harald Welte6811d102019-04-14 22:23:14 +02001714 connect(vc_conn:RAN, g_bssap.vc_RAN:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001715 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001716 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01001717 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01001718 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01001719 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
1720 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
1721 }
Neels Hofmeyr91401012019-07-11 00:42:35 +02001722 if (isvalue(bts[2])) {
1723 connect(vc_conn:RSL2, bts[2].rsl.vc_RSL:CLIENT_PT);
1724 connect(vc_conn:RSL2_PROC, bts[2].rsl.vc_RSL:RSL_PROC);
1725 }
Harald Welte6811d102019-04-14 22:23:14 +02001726 connect(vc_conn:BSSAP, g_bssap.vc_RAN:CLIENT);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001727 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02001728 connect(vc_conn:MGCP_MULTI, vc_MGCP:MGCP_CLIENT_MULTI);
Harald Welte336820c2018-05-31 20:34:52 +02001729}
1730
1731function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
1732runs on test_CT return MSC_ConnHdlr {
1733 var charstring id := testcasename();
1734 var MSC_ConnHdlr vc_conn;
1735 vc_conn := MSC_ConnHdlr.create(id);
1736 f_connect_handler(vc_conn);
Harald Weltea0630032018-03-20 21:09:55 +01001737 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001738 return vc_conn;
1739}
1740
Harald Weltea0630032018-03-20 21:09:55 +01001741/* first function inside ConnHdlr component; sets g_pars + starts function */
1742private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
1743runs on MSC_ConnHdlr {
1744 if (isvalue(pars)) {
1745 g_pars := valueof(pars);
1746 }
1747 fn.apply(id);
1748}
1749
Harald Welte3c86ea02018-05-10 22:28:05 +02001750/* Establish signalling channel (non-assignment case) followed by cipher mode */
1751private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001752 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1753 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02001754 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02001755 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
1756 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
1757 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
1758 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02001759
Philipp Maier23000732018-05-18 11:25:37 +02001760 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02001761}
1762testcase TC_ciph_mode_a5_0() runs on test_CT {
1763 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001764 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001765 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
1766
1767 f_init(1, true);
1768 f_sleep(1.0);
1769 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1770 vc_conn.done;
1771}
1772testcase TC_ciph_mode_a5_1() runs on test_CT {
1773 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001774 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001775 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
1776
1777 f_init(1, true);
1778 f_sleep(1.0);
1779 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1780 vc_conn.done;
1781}
1782testcase TC_ciph_mode_a5_3() runs on test_CT {
1783 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001784 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001785 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
1786
1787 f_init(1, true);
1788 f_sleep(1.0);
1789 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1790 vc_conn.done;
1791}
1792
1793
1794/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02001795private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001796 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1797 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01001798
Harald Welte552620d2017-12-16 23:21:36 +01001799 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1800 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01001801
Harald Weltea0630032018-03-20 21:09:55 +01001802 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01001803}
Harald Welte552620d2017-12-16 23:21:36 +01001804testcase TC_assignment_fr_a5_0() runs on test_CT {
1805 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001806 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001807 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01001808
Harald Welte89d42e82017-12-17 16:42:41 +01001809 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001810 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001811 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01001812 vc_conn.done;
1813}
Harald Welte552620d2017-12-16 23:21:36 +01001814testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01001815 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001816 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001817 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001818
Harald Welte89d42e82017-12-17 16:42:41 +01001819 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001820 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001821 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
1822 vc_conn.done;
1823}
1824testcase TC_assignment_fr_a5_3() runs on test_CT {
1825 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001826 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001827 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001828
Harald Welte651fcdc2018-05-10 20:23:16 +02001829 f_init(1, true);
1830 f_sleep(1.0);
1831 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001832 vc_conn.done;
1833}
1834
Harald Welte552620d2017-12-16 23:21:36 +01001835/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
1836private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001837 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01001838 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001839 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001840 const OCT8 kc := '0001020304050607'O;
1841
1842 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001843 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
1844
Harald Weltea0630032018-03-20 21:09:55 +01001845 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01001846}
Harald Welte552620d2017-12-16 23:21:36 +01001847testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
1848 var MSC_ConnHdlr vc_conn;
1849
Harald Welte89d42e82017-12-17 16:42:41 +01001850 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001851 f_sleep(1.0);
1852
Harald Welte8863fa12018-05-10 20:15:27 +02001853 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01001854 vc_conn.done;
1855}
1856
Harald Welte552620d2017-12-16 23:21:36 +01001857private function f_tc_assignment_fr_a5_4(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001858 g_pars := f_gen_test_hdlr_pars();
Harald Welteed848512018-05-24 22:27:58 +02001859 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1860 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001861 const OCT8 kc := '0001020304050607'O;
1862 const OCT16 kc128 := kc & kc;
1863
1864 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1865 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Weltea0630032018-03-20 21:09:55 +01001866 f_establish_fully(ass_cmd, exp_compl);
Harald Welte38b2a102017-12-23 02:42:58 +01001867 f_cipher_mode('10'O, kc, kc128, true);
Harald Welte552620d2017-12-16 23:21:36 +01001868 /* TODO: expect GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED cause value */
Harald Welte552620d2017-12-16 23:21:36 +01001869}
Harald Welte552620d2017-12-16 23:21:36 +01001870testcase TC_assignment_fr_a5_4() runs on test_CT {
1871 var MSC_ConnHdlr vc_conn;
1872
Harald Welte89d42e82017-12-17 16:42:41 +01001873 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001874 f_sleep(1.0);
1875
Harald Welte8863fa12018-05-10 20:15:27 +02001876 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_4));
Harald Welte552620d2017-12-16 23:21:36 +01001877 vc_conn.done;
1878}
1879
1880
Harald Welte4532e0a2017-12-23 02:05:44 +01001881private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001882 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01001883 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02001884 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01001885 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Harald Weltea0630032018-03-20 21:09:55 +01001886 f_establish_fully(ass_cmd, exp_compl);
Harald Welte4532e0a2017-12-23 02:05:44 +01001887}
1888
1889testcase TC_assignment_sign() runs on test_CT {
1890 var MSC_ConnHdlr vc_conn;
1891
1892 f_init(1, true);
1893 f_sleep(1.0);
1894
Harald Welte8863fa12018-05-10 20:15:27 +02001895 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01001896 vc_conn.done;
1897}
1898
Harald Welte60aa5762018-03-21 19:33:13 +01001899/***********************************************************************
1900 * Codec (list) testing
1901 ***********************************************************************/
1902
1903/* check if the given rsl_mode is compatible with the a_elem */
1904private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
1905return boolean {
1906 select (a_elem.codecType) {
1907 case (GSM_FR) {
1908 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
1909 return true;
1910 }
1911 }
1912 case (GSM_HR) {
1913 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
1914 return true;
1915 }
1916 }
1917 case (GSM_EFR) {
1918 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
1919 return true;
1920 }
1921 }
1922 case (FR_AMR) {
1923 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
1924 return true;
1925 }
1926 }
1927 case (HR_AMR) {
1928 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
1929 return true;
1930 }
1931 }
1932 case else { }
1933 }
1934 return false;
1935}
1936
1937/* check if the given rsl_mode is compatible with the a_list */
1938private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
1939return boolean {
1940 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
1941 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
1942 return true;
1943 }
1944 }
1945 return false;
1946}
1947
1948/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02001949function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01001950return BSSMAP_IE_ChannelType {
1951 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
1952 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
1953 select (a_elem.codecType) {
1954 case (GSM_FR) {
1955 ret.channelRateAndType := ChRate_TCHF;
1956 ret.speechId_DataIndicator := Spdi_TCHF_FR;
1957 }
1958 case (GSM_HR) {
1959 ret.channelRateAndType := ChRate_TCHH;
1960 ret.speechId_DataIndicator := Spdi_TCHH_HR;
1961 }
1962 case (GSM_EFR) {
1963 ret.channelRateAndType := ChRate_TCHF;
1964 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
1965 }
1966 case (FR_AMR) {
1967 ret.channelRateAndType := ChRate_TCHF;
1968 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
1969 }
1970 case (HR_AMR) {
1971 ret.channelRateAndType := ChRate_TCHH;
1972 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
1973 }
1974 case else {
1975 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02001976 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01001977 }
1978 }
1979 return ret;
1980}
1981
Harald Weltea63b9102018-03-22 20:36:16 +01001982private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
1983return template RSL_IE_Body {
1984 var template RSL_IE_Body mode_ie := {
1985 chan_mode := {
1986 len := ?,
1987 reserved := ?,
1988 dtx_d := ?,
1989 dtx_u := ?,
1990 spd_ind := RSL_SPDI_SPEECH,
1991 ch_rate_type := -,
1992 coding_alg_rate := -
1993 }
1994 }
1995
1996 select (a_elem.codecType) {
1997 case (GSM_FR) {
1998 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1999 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
2000 }
2001 case (GSM_HR) {
2002 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
2003 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
2004 }
2005 case (GSM_EFR) {
2006 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
2007 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
2008 }
2009 case (FR_AMR) {
2010 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
2011 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
2012 }
2013 case (HR_AMR) {
2014 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
2015 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
2016 }
2017 }
2018 return mode_ie;
2019}
2020
Harald Welte60aa5762018-03-21 19:33:13 +01002021type record CodecListTest {
2022 BSSMAP_IE_SpeechCodecList codec_list,
2023 charstring id
2024}
2025type record of CodecListTest CodecListTests
2026
2027private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02002028 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
2029 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
Harald Welte60aa5762018-03-21 19:33:13 +01002030
2031 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Harald Welte79f3f542018-05-25 20:02:37 +02002032 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
2033 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
2034 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
2035 g_pars.ass_codec_list.codecElements[0];
Philipp Maierd0e64b02019-03-13 14:15:23 +01002036 if (isvalue(g_pars.expect_mr_s0_s7)) {
2037 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
2038 g_pars.expect_mr_s0_s7;
2039 }
Harald Welte79f3f542018-05-25 20:02:37 +02002040 }
Harald Welte60aa5762018-03-21 19:33:13 +01002041 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
2042 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01002043 log("expecting ASS COMPL like this: ", exp_compl);
2044
2045 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01002046
2047 /* Verify that the RSL-side activation actually matches our expectations */
2048 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
2049
2050 var RSL_IE_Body mode_ie;
2051 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
2052 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02002053 mtc.stop;
Harald Weltea63b9102018-03-22 20:36:16 +01002054 }
2055 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
2056 if (not match(mode_ie, t_mode_ie)) {
2057 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
2058 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002059
2060 var RSL_IE_Body mr_conf;
2061 if (g_pars.expect_mr_conf_ie != omit) {
2062 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
2063 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
Daniel Willmannafce8662018-07-06 23:11:32 +02002064 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002065 }
2066 log("found RSL MR CONFIG IE: ", mr_conf);
2067
2068 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
2069 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
2070 g_pars.expect_mr_conf_ie);
2071 }
2072 } else {
2073 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
2074 log("found RSL MR CONFIG IE: ", mr_conf);
2075 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
Daniel Willmannafce8662018-07-06 23:11:32 +02002076 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002077 }
2078 }
Harald Welte60aa5762018-03-21 19:33:13 +01002079}
2080
Philipp Maierd0e64b02019-03-13 14:15:23 +01002081private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
2082
2083 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2084 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2085
2086 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
2087 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
2088 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
2089 }
2090 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
2091 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
2092 log("expecting ASS FAIL like this: ", exp_fail);
2093
2094 f_establish_fully(ass_cmd, exp_fail);
2095}
2096
Harald Welte60aa5762018-03-21 19:33:13 +01002097testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002098 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002099 var MSC_ConnHdlr vc_conn;
2100
2101 f_init(1, true);
2102 f_sleep(1.0);
2103
2104 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002105 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002106 vc_conn.done;
2107}
2108
2109testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002110 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002111 var MSC_ConnHdlr vc_conn;
2112
2113 f_init(1, true);
2114 f_sleep(1.0);
2115
2116 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002117 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002118 vc_conn.done;
2119}
2120
2121testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002122 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002123 var MSC_ConnHdlr vc_conn;
2124
2125 f_init(1, true);
2126 f_sleep(1.0);
2127
2128 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002129 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002130 vc_conn.done;
2131}
2132
Philipp Maierd0e64b02019-03-13 14:15:23 +01002133/* Allow 5,90k only (current default config) */
2134private function f_allow_amr_rate_5_90k() runs on test_CT {
2135 f_vty_enter_cfg_msc(BSCVTY, 0);
2136 f_vty_transceive(BSCVTY, "amr-config 12_2k forbidden");
2137 f_vty_transceive(BSCVTY, "amr-config 10_2k forbidden");
2138 f_vty_transceive(BSCVTY, "amr-config 7_95k forbidden");
2139 f_vty_transceive(BSCVTY, "amr-config 7_40k forbidden");
2140 f_vty_transceive(BSCVTY, "amr-config 6_70k forbidden");
2141 f_vty_transceive(BSCVTY, "amr-config 5_90k allowed");
2142 f_vty_transceive(BSCVTY, "amr-config 5_15k forbidden");
2143 f_vty_transceive(BSCVTY, "amr-config 4_75k forbidden");
2144 f_vty_transceive(BSCVTY, "exit");
2145 f_vty_transceive(BSCVTY, "exit");
2146}
2147
2148/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
2149 * ("Config-NB-Code = 1") */
2150private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
2151 f_vty_enter_cfg_msc(BSCVTY, 0);
2152 f_vty_transceive(BSCVTY, "amr-config 12_2k allowed");
2153 f_vty_transceive(BSCVTY, "amr-config 10_2k forbidden");
2154 f_vty_transceive(BSCVTY, "amr-config 7_95k forbidden");
2155 f_vty_transceive(BSCVTY, "amr-config 7_40k allowed");
2156 f_vty_transceive(BSCVTY, "amr-config 6_70k forbidden");
2157 f_vty_transceive(BSCVTY, "amr-config 5_90k allowed");
2158 f_vty_transceive(BSCVTY, "amr-config 5_15k forbidden");
2159 f_vty_transceive(BSCVTY, "amr-config 4_75k allowed");
2160 f_vty_transceive(BSCVTY, "exit");
2161 f_vty_transceive(BSCVTY, "exit");
2162}
2163
Harald Welte60aa5762018-03-21 19:33:13 +01002164testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002165 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002166 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02002167
2168 /* Note: This setups the codec configuration. The parameter payload in
2169 * mr_conf must be consistant with the parameter codecElements in pars
2170 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002171 var RSL_IE_Body mr_conf := {
2172 other := {
2173 len := 2,
2174 payload := '2804'O
2175 }
2176 };
Harald Welte60aa5762018-03-21 19:33:13 +01002177
Philipp Maier7695a0d2018-09-27 17:52:14 +02002178 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Philipp Maier806f8f12019-03-12 12:13:41 +01002179 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02002180 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
2181 pars.expect_mr_conf_ie := mr_conf;
2182
Harald Welte60aa5762018-03-21 19:33:13 +01002183 f_init(1, true);
2184 f_sleep(1.0);
2185
Harald Welte8863fa12018-05-10 20:15:27 +02002186 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002187 vc_conn.done;
2188}
2189
2190testcase TC_assignment_codec_amr_h() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002191 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002192 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02002193
2194 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002195 var RSL_IE_Body mr_conf := {
2196 other := {
2197 len := 2,
2198 payload := '2804'O
2199 }
2200 };
Harald Welte60aa5762018-03-21 19:33:13 +01002201
Philipp Maier7695a0d2018-09-27 17:52:14 +02002202 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Philipp Maier806f8f12019-03-12 12:13:41 +01002203 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02002204 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2205 pars.expect_mr_conf_ie := mr_conf;
2206
Harald Welte60aa5762018-03-21 19:33:13 +01002207 f_init(1, true);
2208 f_sleep(1.0);
2209
Harald Welte8863fa12018-05-10 20:15:27 +02002210 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002211 vc_conn.done;
2212}
2213
Philipp Maierd0e64b02019-03-13 14:15:23 +01002214function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0)
2215runs on test_CT {
2216
2217 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2218 var MSC_ConnHdlr vc_conn;
2219
2220 /* See note above */
2221 var RSL_IE_Body mr_conf := {
2222 other := {
2223 len := lengthof(mrconf),
2224 payload := mrconf
2225 }
2226 };
2227
2228 if (fr) {
2229 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
2230 } else {
2231 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2232 }
2233 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
2234 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2235 pars.expect_mr_conf_ie := mr_conf;
2236 pars.expect_mr_s0_s7 := exp_s8_s0;
2237
2238 f_init(1, true);
2239 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
2240 f_sleep(1.0);
2241
2242 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
2243 vc_conn.done;
2244 f_allow_amr_rate_5_90k();
2245}
2246
2247function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
2248runs on test_CT {
2249
2250 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2251 var MSC_ConnHdlr vc_conn;
2252
2253 if (fr) {
2254 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
2255 } else {
2256 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2257 }
2258 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
2259 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2260
2261 f_init(1, true);
2262 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
2263 f_sleep(1.0);
2264
2265 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
2266 vc_conn.done;
2267 f_allow_amr_rate_5_90k();
2268}
2269
2270
2271/* Set S1, we expect an AMR multirate configuration IE with all four rates
2272 * set. */
2273testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
2274 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
2275}
2276
2277/* Set S1, we expect an AMR multirate configuration IE with the lower three
2278 * rates set. */
2279testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
2280 f_TC_assignment_codec_amr(false, '2815208820'O, '00000010'B, '00000010'B);
2281}
2282
2283/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
2284 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
2285testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
2286 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'B, '00000010'B);
2287}
2288
2289/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
2290 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
2291testcase TC_assignment_codec_amr_h_S124() runs on test_CT {
2292 f_TC_assignment_codec_amr(false, '2815208820'O, '00010110'B, '00000010'B);
2293}
2294
2295/* The following block of tests selects more and more rates until all four
2296 * possible rates are in the active set (full rate) */
2297testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
2298 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'B);
2299}
2300
2301testcase TC_assignment_codec_amr_f_S02() runs on test_CT {
2302 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'B);
2303}
2304
2305testcase TC_assignment_codec_amr_f_S024() runs on test_CT {
2306 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'B);
2307}
2308
2309testcase TC_assignment_codec_amr_f_S0247() runs on test_CT {
2310 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
2311}
2312
2313/* The following block of tests selects more and more rates until all three
2314 * possible rates are in the active set (half rate) */
2315testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
2316 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'B);
2317}
2318
2319testcase TC_assignment_codec_amr_h_S02() runs on test_CT {
2320 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
2321}
2322
2323testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
2324 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
2325}
2326
2327/* The following block tests what happens when the MSC does offer rate
2328 * configurations that are not supported by the BSC. Normally such situations
2329 * should not happen because the MSC gets informed by the BSC in advance via
2330 * the L3 COMPLETE message which rates are applicable. The MSC should not try
2331 * to offer rates that are not applicable anyway. */
2332
2333testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
2334 /* Try to include 12,2k in into the active set even though the channel
2335 * is half rate only. The BSC is expected to remove the 12,0k */
2336 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'B);
2337}
2338
2339testcase TC_assignment_codec_amr_f_S01234567() runs on test_CT {
2340 /* See what happens when all rates are selected at once. Since then
2341 * Also S1 is selected, this setting will be prefered and we should
2342 * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
2343 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
2344}
2345
2346testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
2347 /* Same as above, but with S1 missing, the MSC is then expected to
2348 * select the currently supported rates, which are also 12.2k, 7,40k,
2349 * 5,90k, and 4,75k, into the active set. */
2350 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'B);
2351}
2352
2353testcase TC_assignment_codec_amr_f_zero() runs on test_CT {
2354 /* Try to select no rates at all */
2355 f_TC_assignment_codec_amr_fail(true, '00000000'B);
2356}
2357
2358testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
2359 /* Try to select only unsupported rates */
2360 f_TC_assignment_codec_amr_fail(true, '01101000'B);
2361}
2362
2363testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
2364 /* Try to select 12,2k for half rate */
2365 f_TC_assignment_codec_amr_fail(false, '10000000'B);
2366}
2367
Philipp Maierac09bfc2019-01-08 13:41:39 +01002368private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002369 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
2370 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
2371 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
2372 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002373}
2374
2375private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002376 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
2377 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002378}
2379
2380private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002381 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
2382 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
2383 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
2384 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
2385 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
2386 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002387}
2388
2389/* Allow HR only */
2390private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
2391 g_pars := f_gen_test_hdlr_pars();
2392 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2393 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2394 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2395 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
2396 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
2397 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
2398 f_establish_fully(ass_cmd, exp_compl);
2399}
2400
2401/* Allow FR only */
2402private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
2403 g_pars := f_gen_test_hdlr_pars();
2404 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2405 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2406 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2407 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
2408 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
2409 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2410 f_establish_fully(ass_cmd, exp_compl);
2411}
2412
2413/* Allow HR only (expect assignment failure) */
2414private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
2415 g_pars := f_gen_test_hdlr_pars();
2416 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2417 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2418 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2419 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
2420 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
2421 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
2422 f_establish_fully(ass_cmd, exp_fail);
2423}
2424
2425/* Allow FR only (expect assignment failure) */
2426private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(charstring id) runs on MSC_ConnHdlr {
2427 g_pars := f_gen_test_hdlr_pars();
2428 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2429 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2430 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2431 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
2432 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
2433 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2434 f_establish_fully(ass_cmd, exp_fail);
2435}
2436
2437/* Allow FR and HR, but prefer FR */
2438private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2439 g_pars := f_gen_test_hdlr_pars();
2440 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2441 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2442 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2443 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2444 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2445 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2446 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2447 f_establish_fully(ass_cmd, exp_compl);
2448}
2449
2450/* Allow FR and HR, but prefer HR */
2451private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2452 g_pars := f_gen_test_hdlr_pars();
2453 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2454 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2455 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2456 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2457 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2458 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2459 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2460 f_establish_fully(ass_cmd, exp_compl);
2461}
2462
2463/* Allow FR and HR, but prefer FR */
2464private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2465 g_pars := f_gen_test_hdlr_pars();
2466 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2467 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2468 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2469 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2470 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2471 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2472 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2473 f_establish_fully(ass_cmd, exp_compl);
2474}
2475
2476/* Allow FR and HR, but prefer HR */
2477private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2478 g_pars := f_gen_test_hdlr_pars();
2479 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2480 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2481 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2482 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2483 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2484 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2485 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2486 f_establish_fully(ass_cmd, exp_compl);
2487}
2488
2489/* Request a HR channel while all FR channels are exhausted, this is expected
2490 * to work without conflicts */
2491testcase TC_assignment_codec_fr_exhausted_req_hr() runs on test_CT {
2492 var MSC_ConnHdlr vc_conn;
2493 f_init(1, true);
2494 f_sleep(1.0);
2495 f_enable_all_tch();
2496 f_disable_all_tch_f();
2497 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr));
2498 vc_conn.done;
2499 f_enable_all_tch();
2500 setverdict(pass);
2501}
2502
2503/* Request a FR channel while all FR channels are exhausted, this is expected
2504 * to fail. */
2505testcase TC_assignment_codec_fr_exhausted_req_fr() runs on test_CT {
2506 var MSC_ConnHdlr vc_conn;
2507 f_init(1, true);
2508 f_sleep(1.0);
2509 f_enable_all_tch();
2510 f_disable_all_tch_f();
2511 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr_fail));
2512 vc_conn.done;
2513 f_enable_all_tch();
2514 setverdict(pass);
2515}
2516
2517/* Request a FR (prefered) or alternatively a HR channel while all FR channels
2518 * are exhausted, this is expected to be resolved by selecting a HR channel. */
2519testcase TC_assignment_codec_fr_exhausted_req_fr_hr() runs on test_CT {
2520 var MSC_ConnHdlr vc_conn;
2521 f_init(1, true);
2522 f_sleep(1.0);
2523 f_enable_all_tch();
2524 f_disable_all_tch_f();
2525 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
2526 vc_conn.done;
2527 f_enable_all_tch();
2528 setverdict(pass);
2529}
2530
2531/* Request a HR (prefered) or alternatively a FR channel while all FR channels
2532 * are exhausted, this is expected to work without conflicts. */
2533testcase TC_assignment_codec_fr_exhausted_req_hr_fr() runs on test_CT {
2534 var MSC_ConnHdlr vc_conn;
2535 f_init(1, true);
2536 f_sleep(1.0);
2537 f_enable_all_tch();
2538 f_disable_all_tch_f();
2539 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_hr_fr));
2540 vc_conn.done;
2541 f_enable_all_tch();
2542 setverdict(pass);
2543}
2544
2545/* Request a FR channel while all HR channels are exhausted, this is expected
2546 * to work without conflicts */
2547testcase TC_assignment_codec_hr_exhausted_req_fr() runs on test_CT {
2548 var MSC_ConnHdlr vc_conn;
2549 f_init(1, true);
2550 f_sleep(1.0);
2551 f_enable_all_tch();
2552 f_disable_all_tch_h();
2553 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr));
2554 vc_conn.done;
2555 f_enable_all_tch();
2556 setverdict(pass);
2557}
2558
2559/* Request a HR channel while all HR channels are exhausted, this is expected
2560 * to fail. */
2561testcase TC_assignment_codec_hr_exhausted_req_hr() runs on test_CT {
2562 var MSC_ConnHdlr vc_conn;
2563 f_init(1, true);
2564 f_sleep(1.0);
2565 f_enable_all_tch();
2566 f_disable_all_tch_h();
2567 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr_fail));
2568 vc_conn.done;
2569 f_enable_all_tch();
2570 setverdict(pass);
2571}
2572
2573/* Request a HR (prefered) or alternatively a FR channel while all HR channels
2574 * are exhausted, this is expected to be resolved by selecting a FR channel. */
2575testcase TC_assignment_codec_hr_exhausted_req_hr_fr() runs on test_CT {
2576 var MSC_ConnHdlr vc_conn;
2577 f_init(1, true);
2578 f_sleep(1.0);
2579 f_enable_all_tch();
2580 f_disable_all_tch_h();
2581 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_hr_fr));
2582 vc_conn.done;
2583 f_enable_all_tch();
2584 setverdict(pass);
2585}
2586
2587/* Request a FR (prefered) or alternatively a HR channel while all HR channels
2588 * are exhausted, this is expected to work without conflicts. */
2589testcase TC_assignment_codec_hr_exhausted_req_fr_hr() runs on test_CT {
2590 var MSC_ConnHdlr vc_conn;
2591 f_init(1, true);
2592 f_sleep(1.0);
2593 f_enable_all_tch();
2594 f_disable_all_tch_h();
2595 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_fr_hr));
2596 vc_conn.done;
2597 f_enable_all_tch();
2598 setverdict(pass);
2599}
2600
2601/* Allow FR and HR, but prefer HR */
2602private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2603 g_pars := f_gen_test_hdlr_pars();
2604 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2605 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2606 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2607 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2608 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2609 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2610 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2611 f_establish_fully(ass_cmd, exp_compl);
2612}
2613
2614/* Allow FR and HR, but prefer FR */
2615private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2616 g_pars := f_gen_test_hdlr_pars();
2617 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2618 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2619 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2620 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2621 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2622 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2623 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2624 f_establish_fully(ass_cmd, exp_compl);
2625}
2626
2627/* Request a HR (prefered) or alternatively a FR channel, it is expected that
2628 * HR, which is the prefered type, is selected. */
2629testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
2630 var MSC_ConnHdlr vc_conn;
2631 f_init(1, true);
2632 f_sleep(1.0);
2633 f_enable_all_tch();
2634 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
2635 vc_conn.done;
2636 setverdict(pass);
2637}
2638
2639/* Request a FR (prefered) or alternatively a HR channel, it is expected that
2640 * FR, which is the prefered type, is selected. */
2641testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
2642 var MSC_ConnHdlr vc_conn;
2643 f_init(1, true);
2644 f_sleep(1.0);
2645 f_enable_all_tch();
2646 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
2647 vc_conn.done;
2648 setverdict(pass);
2649}
2650
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02002651testcase TC_assignment_osmux() runs on test_CT {
2652 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2653 var MSC_ConnHdlr vc_conn;
2654
2655 /* See note above */
2656 var RSL_IE_Body mr_conf := {
2657 other := {
2658 len := 2,
2659 payload := '2804'O
2660 }
2661 };
2662
2663 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2664 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
2665 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2666 pars.expect_mr_conf_ie := mr_conf;
2667 pars.use_osmux := true;
2668
2669 f_init(1, true, true);
2670 f_sleep(1.0);
2671
2672 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
2673 vc_conn.done;
2674}
2675
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02002676/* test the procedure of the MSC requesting a Classmark Update:
2677 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
2678 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01002679private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002680 g_pars := f_gen_test_hdlr_pars();
2681
Harald Weltea0630032018-03-20 21:09:55 +01002682 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01002683 /* we should now have a COMPL_L3 at the MSC */
2684 BSSAP.receive(tr_BSSMAP_ComplL3);
2685
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02002686 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
2687 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
2688
Harald Welte898113b2018-01-31 18:32:21 +01002689 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
2690 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
2691 setverdict(pass);
2692}
2693testcase TC_classmark() runs on test_CT {
2694 var MSC_ConnHdlr vc_conn;
2695 f_init(1, true);
2696 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002697 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01002698 vc_conn.done;
2699}
2700
Harald Weltee3bd6582018-01-31 22:51:25 +01002701private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002702 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01002703 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01002704 /* we should now have a COMPL_L3 at the MSC */
2705 BSSAP.receive(tr_BSSMAP_ComplL3);
2706
Harald Weltee3bd6582018-01-31 22:51:25 +01002707 /* send the single message we want to send */
2708 f_rsl_send_l3(l3);
2709}
2710
2711private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
2712 timer T := sec;
2713 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01002714 T.start;
2715 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01002716 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
2717 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02002718 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01002719 }
2720 [] T.timeout {
2721 setverdict(pass);
2722 }
2723 }
2724}
2725
Harald Weltee3bd6582018-01-31 22:51:25 +01002726/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2727private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
2728 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
2729 f_bssap_expect_nothing();
2730}
Harald Welte898113b2018-01-31 18:32:21 +01002731testcase TC_unsol_ass_fail() runs on test_CT {
2732 var MSC_ConnHdlr vc_conn;
2733 f_init(1, true);
2734 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002735 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01002736 vc_conn.done;
2737}
Harald Welte552620d2017-12-16 23:21:36 +01002738
Harald Welteea99a002018-01-31 20:46:43 +01002739
2740/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
2741private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002742 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
2743 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01002744}
2745testcase TC_unsol_ass_compl() runs on test_CT {
2746 var MSC_ConnHdlr vc_conn;
2747 f_init(1, true);
2748 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002749 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01002750 vc_conn.done;
2751}
2752
2753
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002754/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2755private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002756 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
2757 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002758}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002759testcase TC_unsol_ho_fail() runs on test_CT {
2760 var MSC_ConnHdlr vc_conn;
2761 f_init(1, true);
2762 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002763 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002764 vc_conn.done;
2765}
2766
2767
Harald Weltee3bd6582018-01-31 22:51:25 +01002768/* short message from MS should be ignored */
2769private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002770 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01002771 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01002772 /* we should now have a COMPL_L3 at the MSC */
2773 BSSAP.receive(tr_BSSMAP_ComplL3);
2774
2775 /* send short message */
2776 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
2777 f_bssap_expect_nothing();
2778}
2779testcase TC_err_82_short_msg() runs on test_CT {
2780 var MSC_ConnHdlr vc_conn;
2781 f_init(1, true);
2782 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002783 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01002784 vc_conn.done;
2785}
2786
2787
Harald Weltee9e02e42018-01-31 23:36:25 +01002788/* 24.008 8.4 Unknown message must trigger RR STATUS */
2789private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
2790 f_est_single_l3(ts_RRM_UL_REL('00'O));
2791 timer T := 3.0
2792 alt {
2793 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
2794 setverdict(pass);
2795 }
2796 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01002797 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01002798 }
2799}
2800testcase TC_err_84_unknown_msg() runs on test_CT {
2801 var MSC_ConnHdlr vc_conn;
2802 f_init(1, true);
2803 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002804 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01002805 vc_conn.done;
2806}
2807
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002808/***********************************************************************
2809 * Handover
2810 ***********************************************************************/
2811
Harald Welte94e0c342018-04-07 11:33:23 +02002812/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
2813private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
2814runs on test_CT {
2815 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2816 " timeslot "&int2str(ts_nr)&" ";
2817 f_vty_transceive(BSCVTY, cmd & suffix);
2818}
2819
Harald Welte261af4b2018-02-12 21:20:39 +01002820/* execute a "bts <0-255> trx <0-255> timeslot <0-7> sub-slot <0-7>" command on given Dchan */
2821private function f_vty_ss_action(charstring suffix, integer bts_nr, integer trx_nr, RslChannelNr chan_nr)
2822runs on MSC_ConnHdlr {
2823 /* FIXME: resolve those from component-global state */
2824 var integer ts_nr := chan_nr.tn;
2825 var integer ss_nr;
2826 if (ischosen(chan_nr.u.ch0)) {
2827 ss_nr := 0;
2828 } else if (ischosen(chan_nr.u.lm)) {
2829 ss_nr := chan_nr.u.lm.sub_chan;
2830 } else if (ischosen(chan_nr.u.sdcch4)) {
2831 ss_nr := chan_nr.u.sdcch4.sub_chan;
2832 } else if (ischosen(chan_nr.u.sdcch8)) {
2833 ss_nr := chan_nr.u.sdcch8.sub_chan;
2834 } else {
2835 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02002836 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01002837 }
2838
2839 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2840 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
2841 f_vty_transceive(BSCVTY, cmd & suffix);
2842}
2843
Neels Hofmeyr91401012019-07-11 00:42:35 +02002844/* Even though the VTY command to trigger handover takes a new BTS number as argument, behind the scenes osmo-bsc always
2845 * translates that to a target ARFCN+BSIC first. See bsc_vty.c trigger_ho_or_as(), which puts the selected BTS' neighbor
2846 * ident key (ARFCN + BSIC) in the struct passed on to handover_request(). handover_start() then resolves that to a
2847 * viable actual neighbor cell. So from the internal osmo-bsc perspective, we always request handover to an ARFCN + BSIC
2848 * pair, not really to a specific BTS number. */
Harald Welte261af4b2018-02-12 21:20:39 +01002849private function f_vty_handover(integer bts_nr, integer trx_nr, RslChannelNr chan_nr,
2850 integer new_bts_nr)
2851runs on MSC_ConnHdlr {
2852 f_vty_ss_action("handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
2853}
2854
2855/* intra-BSC hand-over between BTS0 and BTS1 */
2856private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002857 g_pars := f_gen_test_hdlr_pars();
Harald Welteed848512018-05-24 22:27:58 +02002858 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2859 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01002860 const OCT8 kc := '0001020304050607'O;
2861
2862 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2863 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2864
Harald Weltea0630032018-03-20 21:09:55 +01002865 f_establish_fully(ass_cmd, exp_compl);
Harald Welte261af4b2018-02-12 21:20:39 +01002866
2867 var HandoverState hs := {
2868 rr_ho_cmpl_seen := false,
2869 handover_done := false,
2870 old_chan_nr := -
2871 };
2872 /* issue hand-over command on VTY */
2873 f_vty_handover(0, 0, g_chan_nr, 1);
2874 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
2875 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002876
2877 /* From the MGW perspective, a handover is is characterized by
2878 * performing one MDCX operation with the MGW. So we expect to see
2879 * one more MDCX during handover. */
2880 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
2881
Harald Welte261af4b2018-02-12 21:20:39 +01002882 alt {
2883 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01002884 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002885
Philipp Maier4dae0652018-11-12 12:03:26 +01002886 /* Since this is an internal handover we expect the BSC to inform the
2887 * MSC about the event */
2888 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
2889
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002890 /* Check the amount of MGCP transactions is still consistant with the
2891 * test expectation */
2892 f_check_mgcp_expectations()
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01002893 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01002894}
2895
2896testcase TC_ho_int() runs on test_CT {
2897 var MSC_ConnHdlr vc_conn;
2898 f_init(2, true);
2899 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002900 vc_conn := f_start_handler(refers(f_tc_ho_int));
Harald Welte261af4b2018-02-12 21:20:39 +01002901 vc_conn.done;
2902}
Harald Weltee9e02e42018-01-31 23:36:25 +01002903
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02002904/* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02002905private function f_expect_dlcx_conns() runs on MSC_ConnHdlr {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02002906 var MgcpCommand mgcp;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02002907 var template MgcpResponse mgcp_resp;
2908 var MGCP_RecvFrom mrf;
2909 var template MgcpMessage msg_resp;
2910 var template MgcpMessage msg_dlcx := {
2911 command := tr_DLCX()
2912 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02002913
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02002914 if (g_pars.aoip) {
2915 MGCP.receive(tr_DLCX()) -> value mgcp {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02002916 log("Got first DLCX: ", mgcp);
2917 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02002918 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02002919
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02002920 MGCP.receive(tr_DLCX()) -> value mgcp {
2921 log("Got second DLCX: ", mgcp);
2922 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
2923 };
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02002924 } else {
2925 /* For SCCPLite, BSC doesn't handle the MSC-side */
2926 MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_dlcx)) -> value mrf {
2927 log("Got first DLCX: ", mrf.msg.command);
2928 msg_resp := {
2929 response := ts_DLCX_ACK2(mrf.msg.command.line.trans_id)
2930 }
2931 MGCP_MULTI.send(t_MGCP_SendToMrf(mrf, msg_resp));
2932 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02002933 }
2934
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02002935 BSSAP.receive(tr_BSSMAP_ClearComplete);
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02002936}
2937
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002938private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002939 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002940
2941 var PDU_BSSAP ass_req := f_gen_ass_req();
2942 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2943 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2944 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2945 f_establish_fully(ass_req, exp_compl);
2946
2947 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2948
2949 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2950
2951 f_sleep(0.5);
2952 /* The MSC negotiates Handover Request and Handover Request Ack with
2953 * the other BSS and comes back with a BSSMAP Handover Command
2954 * containing an RR Handover Command coming from the target BSS... */
2955
2956 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
2957 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
2958 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
2959 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
2960 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
2961
2962 /* expect the Handover Command to go out on RR */
2963 var RSL_Message rsl_ho_cmd
2964 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
2965 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
2966 var RSL_IE_Body rsl_ho_cmd_l3;
2967 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
2968 log("RSL message contains no L3 Info IE, expected RR Handover Command");
2969 setverdict(fail);
2970 } else {
2971 log("Found L3 Info: ", rsl_ho_cmd_l3);
2972 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
2973 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
2974 setverdict(fail);
2975 } else {
2976 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
2977 setverdict(pass);
2978 }
2979 }
2980
2981 /* When the other BSS has reported a completed handover, this side is
2982 * torn down. */
2983
2984 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
2985 var BssmapCause cause := enum2int(cause_val);
2986 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
2987
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02002988 f_expect_dlcx_conns();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002989 setverdict(pass);
2990 f_sleep(1.0);
2991}
2992testcase TC_ho_out_of_this_bsc() runs on test_CT {
2993 var MSC_ConnHdlr vc_conn;
2994
2995 f_init(1, true);
2996 f_sleep(1.0);
2997
2998 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
2999 vc_conn.done;
3000}
3001
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003002/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
3003 * simply never sends a BSSMAP Handover Command. */
3004private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01003005 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003006
3007 var PDU_BSSAP ass_req := f_gen_ass_req();
3008 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3009 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3010 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3011 f_establish_fully(ass_req, exp_compl);
3012
3013 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
3014
3015 BSSAP.receive(tr_BSSMAP_HandoverRequired);
3016
3017 /* osmo-bsc should time out 10 seconds after the handover started.
3018 * Let's give it a bit extra. */
3019 f_sleep(15.0);
3020
3021 /* The old lchan and conn should still be active. See that arbitrary L3
3022 * is still going through. */
3023 var octetstring l3 := '0123456789'O;
3024 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
3025 var template PDU_BSSAP exp_data := {
3026 discriminator := '1'B,
3027 spare := '0000000'B,
3028 dlci := '00'O,
3029 lengthIndicator := 5,
3030 pdu := {
3031 dtap := l3
3032 }
3033 };
3034 BSSAP.receive(exp_data);
3035 setverdict(pass);
3036 f_sleep(1.0);
3037}
3038testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
3039 var MSC_ConnHdlr vc_conn;
3040
3041 f_init(1, true);
3042 f_sleep(1.0);
3043
3044 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
3045 vc_conn.done;
3046}
3047
3048/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
3049 * RR Handover Failure. */
3050private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01003051 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003052
3053 var PDU_BSSAP ass_req := f_gen_ass_req();
3054 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3055 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3056 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3057 f_establish_fully(ass_req, exp_compl);
3058
3059 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
3060
3061 BSSAP.receive(tr_BSSMAP_HandoverRequired);
3062
3063 f_sleep(0.5);
3064 /* The MSC negotiates Handover Request and Handover Request Ack with
3065 * the other BSS and comes back with a BSSMAP Handover Command
3066 * containing an RR Handover Command coming from the target BSS... */
3067
3068 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
3069 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
3070 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
3071 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
3072 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
3073
3074 /* expect the Handover Command to go out on RR */
3075 var RSL_Message rsl_ho_cmd
3076 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
3077 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
3078 var RSL_IE_Body rsl_ho_cmd_l3;
3079 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
3080 log("RSL message contains no L3 Info IE, expected RR Handover Command");
3081 setverdict(fail);
3082 } else {
3083 log("Found L3 Info: ", rsl_ho_cmd_l3);
3084 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
3085 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
3086 setverdict(fail);
3087 } else {
3088 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
3089 setverdict(pass);
3090 }
3091 }
3092
3093 f_sleep(0.2);
3094 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
3095
3096 /* Should tell the MSC about the failure */
3097 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3098
3099 f_sleep(1.0);
3100
3101 /* The old lchan and conn should still be active. See that arbitrary L3
3102 * is still going through. */
3103 var octetstring l3 := '0123456789'O;
3104 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
3105 var template PDU_BSSAP exp_data := {
3106 discriminator := '1'B,
3107 spare := '0000000'B,
3108 dlci := '00'O,
3109 lengthIndicator := 5,
3110 pdu := {
3111 dtap := l3
3112 }
3113 };
3114 BSSAP.receive(exp_data);
3115 setverdict(pass);
3116 f_sleep(1.0);
3117
3118 setverdict(pass);
3119 f_sleep(1.0);
3120}
3121testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
3122 var MSC_ConnHdlr vc_conn;
3123
3124 f_init(1, true);
3125 f_sleep(1.0);
3126
3127 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
3128 vc_conn.done;
3129}
3130
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02003131/* BSC asks for inter-BSC-out HO, receives BSSMAP Handover Command, but then no reply is received about HO outcome
3132 * (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 +02003133 * and the lchan is released. */
3134private function f_tc_ho_out_fail_no_result_after_ho_cmd(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01003135 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003136
3137 var PDU_BSSAP ass_req := f_gen_ass_req();
3138 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3139 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3140 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3141 f_establish_fully(ass_req, exp_compl);
3142
3143 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
3144
3145 BSSAP.receive(tr_BSSMAP_HandoverRequired);
3146
3147 f_sleep(0.5);
3148 /* The MSC negotiates Handover Request and Handover Request Ack with
3149 * the other BSS and comes back with a BSSMAP Handover Command
3150 * containing an RR Handover Command coming from the target BSS... */
3151
3152 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
3153 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
3154 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
3155 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
3156 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
3157
3158 /* expect the Handover Command to go out on RR */
3159 var RSL_Message rsl_ho_cmd
3160 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
3161 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
3162 var RSL_IE_Body rsl_ho_cmd_l3;
3163 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
3164 log("RSL message contains no L3 Info IE, expected RR Handover Command");
3165 setverdict(fail);
3166 } else {
3167 log("Found L3 Info: ", rsl_ho_cmd_l3);
3168 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
3169 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
3170 setverdict(fail);
3171 } else {
3172 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
3173 setverdict(pass);
3174 }
3175 }
3176
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02003177 /* We get neither success nor failure report from the remote BSS. Eventually T8 times out and we run into 3GPP
3178 * TS 48.008 3.1.5.3.3 "Abnormal Conditions": Clear Request should go to the MSC, and RR should be released
3179 * after Clear Command */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003180
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02003181 var PDU_BSSAP rx_clear_request;
Neels Hofmeyre1797aa2019-07-09 19:34:04 +02003182 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
3183 log("Got BSSMAP Clear Request");
3184 /* Instruct BSC to clear channel */
3185 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
3186 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3187
3188 var MgcpCommand mgcp;
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003189 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01003190 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
3191 log("Got Deact SACCH");
3192 }
Harald Welte924b6ea2019-02-04 01:05:34 +01003193 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01003194 log("Got RR Release");
3195 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003196 [] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
3197 log("Got RF Chan Rel");
3198 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
3199 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003200 }
3201
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02003202 f_expect_dlcx_conns();
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02003203
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003204 setverdict(pass);
3205 f_sleep(1.0);
3206}
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02003207testcase TC_ho_out_fail_no_result_after_ho_cmd() runs on test_CT {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003208 var MSC_ConnHdlr vc_conn;
3209
3210 f_init(1, true);
3211 f_sleep(1.0);
3212
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02003213 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_result_after_ho_cmd));
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003214 vc_conn.done;
3215}
3216
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003217private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
3218 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
3219 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
3220 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
3221 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
3222 * before we get started. */
3223 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3224 f_rslem_register(0, new_chan_nr);
3225 g_chan_nr := new_chan_nr;
3226 f_sleep(1.0);
3227
3228 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3229 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3230 activate(as_Media());
3231
3232 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3233 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003234 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003235
3236 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3237
3238 var PDU_BSSAP rx_bssap;
3239 var octetstring ho_command_str;
3240
3241 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
Pau Espin Pedrol76ba5412019-06-10 11:00:33 +02003242
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003243 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3244 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3245 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3246 log("L3 Info in HO Request Ack is ", ho_command);
3247
3248 var GsmArfcn arfcn;
3249 var RslChannelNr actual_new_chan_nr;
3250 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3251 actual_new_chan_nr, arfcn);
3252
3253 if (actual_new_chan_nr != new_chan_nr) {
3254 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3255 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3256 setverdict(fail);
3257 return;
3258 }
3259 log("Handover Command chan_nr is", actual_new_chan_nr);
3260
3261 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3262 * tells the MS to handover to the new lchan. Here comes the new MS on
3263 * the new lchan with a Handover RACH: */
3264
3265 /* send handover detect */
3266
3267 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
3268
3269 BSSAP.receive(tr_BSSMAP_HandoverDetect);
3270
3271 /* send handover complete over the new channel */
3272
3273 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
3274 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
3275 enc_PDU_ML3_MS_NW(l3_tx)));
3276
3277 BSSAP.receive(tr_BSSMAP_HandoverComplete);
3278 setverdict(pass);
3279}
3280testcase TC_ho_into_this_bsc() runs on test_CT {
3281 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003282 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003283
3284 f_init(1, true);
3285 f_sleep(1.0);
3286
3287 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3288 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3289
3290 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
3291 vc_conn.done;
3292}
3293
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003294private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
3295 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3296 f_rslem_register(0, new_chan_nr);
3297 g_chan_nr := new_chan_nr;
3298 f_sleep(1.0);
3299
3300 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3301 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3302 activate(as_Media());
3303
3304 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3305 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003306 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003307
3308 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3309
3310 var PDU_BSSAP rx_bssap;
3311 var octetstring ho_command_str;
3312
3313 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3314
3315 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3316 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3317 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3318 log("L3 Info in HO Request Ack is ", ho_command);
3319
3320 var GsmArfcn arfcn;
3321 var RslChannelNr actual_new_chan_nr;
3322 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3323 actual_new_chan_nr, arfcn);
3324
3325 if (actual_new_chan_nr != new_chan_nr) {
3326 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3327 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3328 setverdict(fail);
3329 return;
3330 }
3331 log("Handover Command chan_nr is", actual_new_chan_nr);
3332
Neels Hofmeyr61ca08d2019-05-06 23:52:22 +02003333 /* For deterministic test results, give some time for the MGW endpoint to be configured */
3334 f_sleep(1.0);
3335
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003336 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3337 * tells the MS to handover to the new lchan. In this case, the MS
3338 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
3339 * Handover Failure to the MSC. The procedure according to 3GPP TS
3340 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
3341 * BSSMAP Clear Command: */
3342
3343 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3344 var BssmapCause cause := enum2int(cause_val);
3345 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3346
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02003347 f_expect_dlcx_conns();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003348 setverdict(pass);
3349 f_sleep(1.0);
3350
3351 setverdict(pass);
3352}
3353testcase TC_ho_in_fail_msc_clears() runs on test_CT {
3354 var MSC_ConnHdlr vc_conn;
3355 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3356
3357 f_init(1, true);
3358 f_sleep(1.0);
3359
3360 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3361 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3362
3363 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
3364 vc_conn.done;
3365}
3366
3367private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
3368 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
3369 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
3370 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
3371 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
3372 * before we get started. */
3373 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3374 f_rslem_register(0, new_chan_nr);
3375 g_chan_nr := new_chan_nr;
3376 f_sleep(1.0);
3377
3378 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3379 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3380 activate(as_Media());
3381
3382 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3383 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003384 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003385
3386 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3387
3388 var PDU_BSSAP rx_bssap;
3389 var octetstring ho_command_str;
3390
3391 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3392
3393 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3394 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3395 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3396 log("L3 Info in HO Request Ack is ", ho_command);
3397
3398 var GsmArfcn arfcn;
3399 var RslChannelNr actual_new_chan_nr;
3400 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3401 actual_new_chan_nr, arfcn);
3402
3403 if (actual_new_chan_nr != new_chan_nr) {
3404 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3405 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3406 setverdict(fail);
3407 return;
3408 }
3409 log("Handover Command chan_nr is", actual_new_chan_nr);
3410
3411 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3412 * tells the MS to handover to the new lchan. Here comes the new MS on
3413 * the new lchan with a Handover RACH: */
3414
3415 /* send handover detect */
3416
3417 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
3418
3419 BSSAP.receive(tr_BSSMAP_HandoverDetect);
3420
3421 /* The MSC chooses to clear the connection now, maybe we got the
3422 * Handover RACH on the new cell but the MS still signaled Handover
3423 * Failure to the old BSS? */
3424
3425 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3426 var BssmapCause cause := enum2int(cause_val);
3427 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3428
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02003429 f_expect_dlcx_conns();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003430 setverdict(pass);
3431 f_sleep(1.0);
3432}
3433testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
3434 var MSC_ConnHdlr vc_conn;
3435 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3436
3437 f_init(1, true);
3438 f_sleep(1.0);
3439
3440 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3441 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3442
3443 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
3444 vc_conn.done;
3445}
3446
3447/* The new BSS's lchan times out before the MSC decides that handover failed. */
3448private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
3449 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3450 f_rslem_register(0, new_chan_nr);
3451 g_chan_nr := new_chan_nr;
3452 f_sleep(1.0);
3453
3454 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3455 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3456 activate(as_Media());
3457
3458 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3459 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003460 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003461
3462 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3463
3464 var PDU_BSSAP rx_bssap;
3465 var octetstring ho_command_str;
3466
3467 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3468
3469 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3470 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3471 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3472 log("L3 Info in HO Request Ack is ", ho_command);
3473
3474 var GsmArfcn arfcn;
3475 var RslChannelNr actual_new_chan_nr;
3476 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3477 actual_new_chan_nr, arfcn);
3478
3479 if (actual_new_chan_nr != new_chan_nr) {
3480 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3481 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3482 setverdict(fail);
3483 return;
3484 }
3485 log("Handover Command chan_nr is", actual_new_chan_nr);
3486
3487 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3488 * tells the MS to handover to the new lchan. But the MS never shows up
3489 * on the new lchan. */
3490
3491 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3492
3493 /* Did osmo-bsc also send a Clear Request? */
3494 timer T := 0.5;
3495 T.start;
3496 alt {
3497 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
3498 [] T.timeout { }
3499 }
3500
3501 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
3502 * asked for it, this is a Handover Failure after all). */
3503
3504 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3505 var BssmapCause cause := enum2int(cause_val);
3506 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3507
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02003508 f_expect_dlcx_conns();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003509 setverdict(pass);
3510 f_sleep(1.0);
3511
3512 setverdict(pass);
3513}
3514testcase TC_ho_in_fail_no_detect() runs on test_CT {
3515 var MSC_ConnHdlr vc_conn;
3516 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3517
3518 f_init(1, true);
3519 f_sleep(1.0);
3520
3521 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3522 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3523
3524 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
3525 vc_conn.done;
3526}
3527
3528/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
3529private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
3530 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3531 f_rslem_register(0, new_chan_nr);
3532 g_chan_nr := new_chan_nr;
3533 f_sleep(1.0);
3534
3535 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3536 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3537 activate(as_Media());
3538
3539 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3540 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003541 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003542
3543 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3544
3545 var PDU_BSSAP rx_bssap;
3546 var octetstring ho_command_str;
3547
3548 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3549
3550 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3551 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3552 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3553 log("L3 Info in HO Request Ack is ", ho_command);
3554
3555 var GsmArfcn arfcn;
3556 var RslChannelNr actual_new_chan_nr;
3557 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3558 actual_new_chan_nr, arfcn);
3559
3560 if (actual_new_chan_nr != new_chan_nr) {
3561 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3562 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3563 setverdict(fail);
3564 return;
3565 }
3566 log("Handover Command chan_nr is", actual_new_chan_nr);
3567
3568 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3569 * tells the MS to handover to the new lchan. But the MS never shows up
3570 * on the new lchan. */
3571
3572 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3573
3574 /* MSC plays dumb and sends no Clear Command */
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003575 var PDU_BSSAP rx_clear_request;
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02003576
3577 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003578 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
3579 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3580 };
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02003581 f_expect_dlcx_conns();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003582 setverdict(pass);
3583 f_sleep(1.0);
3584}
3585testcase TC_ho_in_fail_no_detect2() runs on test_CT {
3586 var MSC_ConnHdlr vc_conn;
3587 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3588
3589 f_init(1, true);
3590 f_sleep(1.0);
3591
3592 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3593 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3594
3595 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
3596 vc_conn.done;
3597}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003598
Neels Hofmeyr91401012019-07-11 00:42:35 +02003599type record of charstring Commands;
3600
3601private function f_bts_0_cfg(Commands cmds := {}) runs on MSC_ConnHdlr
3602{
3603 f_vty_enter_cfg_bts(BSCVTY, 0);
3604 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
3605 f_vty_transceive(BSCVTY, cmds[i]);
3606 }
3607 f_vty_transceive(BSCVTY, "end");
3608}
3609
3610private function f_probe_for_handover(charstring log_label,
3611 charstring log_descr,
3612 charstring handover_vty_cmd,
3613 boolean expect_handover,
3614 boolean is_inter_bsc_handover := false)
3615runs on MSC_ConnHdlr
3616{
3617 var RSL_Message rsl;
3618
3619 var charstring log_msg := " (expecting handover)"
3620 if (not expect_handover) {
3621 log_msg := " (expecting NO handover)";
3622 }
3623 log("f_probe_for_handover starting: " & log_label & ": " & log_descr & log_msg);
3624 f_vty_transceive(BSCVTY, handover_vty_cmd);
3625
3626 /* We're going to thwart any and all handover attempts, just be ready to handle (and ignore) handover target
3627 * lchans to be established on bts 1 or bts 2. */
3628 f_rslem_suspend(RSL1_PROC);
3629 f_rslem_suspend(RSL2_PROC);
3630
3631 timer T := 2.0;
3632 T.start;
3633
3634 alt {
3635 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
3636 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
3637 log("Rx L3 from net: ", l3);
3638 if (ischosen(l3.msgs.rrm.handoverCommand)) {
3639 var RslChannelNr new_chan_nr;
3640 var GsmArfcn arfcn;
3641 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
3642 new_chan_nr, arfcn);
3643 log("Handover to new chan ", new_chan_nr, " on ARFCN ", arfcn);
3644 log(l3.msgs.rrm.handoverCommand);
3645
3646 /* Need to register for new lchan on new BTS -- it's either bts 1 or bts 2. It doesn't really
3647 * matter on which BTS it really is, we're not going to follow through an entire handover
3648 * anyway. */
3649 f_rslem_register(0, new_chan_nr, RSL1_PROC);
3650 f_rslem_resume(RSL1_PROC);
3651 f_rslem_register(0, new_chan_nr, RSL2_PROC);
3652 f_rslem_resume(RSL2_PROC);
3653
3654 if (expect_handover and not is_inter_bsc_handover) {
3655 setverdict(pass);
3656 log("f_probe_for_handover(" & log_label & "): Got RSL Handover Command as expected.");
3657 } else {
3658 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got RSL Handover Command. "
3659 & log_label & ": " & log_descr);
3660 }
3661
3662 log("f_probe_for_handover(" & log_label & "): Ending the test: Handover Failure stops the procedure.");
3663 /* osmo-bsc has triggered Handover. That's all we need to know for this test, reply with
3664 * Handover Failure. */
3665 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
3666
3667 /* target BTS is told to release lchan again; don't care which BTS nor what messages. */
3668 f_sleep(0.5);
3669 RSL1.clear;
3670 RSL2.clear;
3671 log("f_probe_for_handover(" & log_label & "): done (got RSL Handover Command)");
3672 break;
3673 } else {
3674 repeat;
3675 }
3676 }
3677 [] BSSAP.receive(tr_BSSMAP_HandoverRequired) {
3678 if (expect_handover and is_inter_bsc_handover) {
3679 setverdict(pass);
3680 log("f_probe_for_handover(" & log_label & "): Got BSSMAP Handover Required as expected.");
3681 } else {
3682 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got BSSMAP Handover Required. "
3683 & log_label & ": " & log_descr);
3684 }
3685
3686 log("f_probe_for_handover(" & log_label & "): done (got BSSMAP Handover Required)");
3687
3688 /* Note: f_tc_ho_neighbor_config_start() sets T7, the timeout for BSSMAP Handover Required, to
3689 * 1 second. There is no legal way to quickly abort a handover after a BSSMAP Handover Required,
3690 * setting a short timeout and waiting is the only way. */
3691 log("f_probe_for_handover(" & log_label & "): waiting for inter-BSC HO to time out...");
3692 f_sleep(1.5);
3693 log("f_probe_for_handover(" & log_label & "): ...done");
3694
3695 break;
3696 }
3697 [] T.timeout {
3698 if (expect_handover) {
3699 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected Handover, but got none. "
3700 & log_label & ": " & log_descr);
3701 } else {
3702 setverdict(pass);
3703 log("f_probe_for_handover(" & log_label & "): Got no Handover, as expected.");
3704 }
3705 log("f_probe_for_handover(" & log_label & "): done (got no Handover)");
3706 break;
3707 }
3708 }
3709
3710 f_rslem_resume(RSL1_PROC);
3711 f_rslem_resume(RSL2_PROC);
3712 f_sleep(3.0);
3713 RSL.clear;
3714
3715 log("f_probe_for_handover(" & log_label & "): done clearing");
3716}
3717
3718/* Test the effect of various neighbor configuration scenarios:
3719 *
3720 * To avoid complexity, block off any actual handover operation, and always remain on the lchan at bts 0.
3721 * Reconfigure the neighbors for bts 0, trigger a Handover, and probe whether osmo-bsc does or doesn't start HO.
3722 */
3723private function f_tc_ho_neighbor_config_start() runs on MSC_ConnHdlr {
3724 g_pars := f_gen_test_hdlr_pars();
3725 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3726 var PDU_BSSAP ass_cmd := f_gen_ass_req();
3727 const OCT8 kc := '0001020304050607'O;
3728
3729 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3730 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3731
3732 /* Establish lchan at bts 0 */
3733 f_establish_fully(ass_cmd, exp_compl);
3734
3735 /* Shorten the inter-BSC Handover timeout, to not wait so long for inter-BSC Handovers */
3736 f_vty_enter_cfg_network(BSCVTY);
3737 f_vty_transceive(BSCVTY, "timer T7 1");
3738 f_vty_transceive(BSCVTY, "end");
3739}
3740
3741private function f_tc_ho_neighbor_config_1(charstring id) runs on MSC_ConnHdlr {
3742 f_tc_ho_neighbor_config_start();
3743
3744 /*
3745 * bts 0 ARFCN 871 BSIC 10
3746 * bts 1 ARFCN 871 BSIC 11
3747 * bts 2 ARFCN 871 BSIC 12
3748 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
3749 */
3750
3751 log("f_tc_ho_neighbor_config: 1. No 'neighbor' config");
3752 f_bts_0_cfg({"no neighbors"});
3753 f_probe_for_handover("1.a", "HO to bts 1 works, implicitly listed as neighbor (legacy behavior when none are configured)",
3754 "handover any to arfcn 871 bsic 11",
3755 true);
3756
3757 f_probe_for_handover("1.b", "HO to unknown cell does not start",
3758 "handover any to arfcn 13 bsic 39",
3759 false);
3760
3761 f_probe_for_handover("1.c", "HO to 871-12 is ambiguous = error",
3762 "handover any to arfcn 871 bsic 12",
3763 false);
3764
3765 f_probe_for_handover("1.d", "HO to 871-11 still works (verify that this test properly cleans up)",
3766 "handover any to arfcn 871 bsic 11",
3767 true);
3768}
3769private function f_tc_ho_neighbor_config_2(charstring id) runs on MSC_ConnHdlr {
3770 f_tc_ho_neighbor_config_start();
3771
3772 /*
3773 * bts 0 ARFCN 871 BSIC 10
3774 * bts 1 ARFCN 871 BSIC 11
3775 * bts 2 ARFCN 871 BSIC 12
3776 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
3777 */
3778
3779 log("f_tc_ho_neighbor_config: 2. explicit local neighbor: 'neighbor bts 1'");
3780 f_bts_0_cfg({"neighbor bts 1"});
3781 f_sleep(0.5);
3782
3783 f_probe_for_handover("2.a", "HO to bts 1 works, explicitly listed as neighbor",
3784 "handover any to arfcn 871 bsic 11",
3785 true);
3786
3787 f_probe_for_handover("2.b", "HO to bts 2 doesn't work, not listed as neighbor",
3788 "handover any to arfcn 871 bsic 12",
3789 false);
3790}
3791private function f_tc_ho_neighbor_config_3(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: 3. explicit local neighbor: 'neighbor bts 2'");
3802 f_bts_0_cfg({"no neighbors", "neighbor bts 2"});
3803 f_sleep(0.5);
3804
3805 f_probe_for_handover("3.a", "HO to bts 1 doesn't work, not listed as neighbor",
3806 "handover any to arfcn 871 bsic 11",
3807 false);
3808 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",
3809 "handover any to arfcn 871 bsic 12",
3810 true);
3811}
3812private function f_tc_ho_neighbor_config_4(charstring id) runs on MSC_ConnHdlr {
3813 f_tc_ho_neighbor_config_start();
3814
3815 /*
3816 * bts 0 ARFCN 871 BSIC 10
3817 * bts 1 ARFCN 871 BSIC 11
3818 * bts 2 ARFCN 871 BSIC 12
3819 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
3820 */
3821
3822 log("f_tc_ho_neighbor_config: 4. explicit remote neighbor: 'neighbor lac 99 arfcn 123 bsic 45'");
3823 f_bts_0_cfg({"no neighbors", "neighbor lac 99 arfcn 123 bsic 45"});
3824 f_sleep(0.5);
3825
3826 f_probe_for_handover("4.a", "HO to bts 1 doesn't work, not listed as neighbor",
3827 "handover any to arfcn 871 bsic 11",
3828 false);
3829 f_probe_for_handover("4.b", "HO to bts 2 doesn't work, not listed as neighbor",
3830 "handover any to arfcn 871 bsic 12",
3831 false);
3832 f_probe_for_handover("4.c", "HO to 123-45 triggers inter-BSC HO",
3833 "handover any to arfcn 123 bsic 45",
3834 true, true);
3835}
3836private function f_tc_ho_neighbor_config_5(charstring id) runs on MSC_ConnHdlr {
3837 f_tc_ho_neighbor_config_start();
3838
3839 /*
3840 * bts 0 ARFCN 871 BSIC 10
3841 * bts 1 ARFCN 871 BSIC 11
3842 * bts 2 ARFCN 871 BSIC 12
3843 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
3844 */
3845
3846 log("f_tc_ho_neighbor_config: 5. explicit remote neighbor re-using ARFCN+BSIC: 'neighbor lac 99 arfcn 871 bsic 12'");
3847 f_bts_0_cfg({"no neighbors", "neighbor lac 99 arfcn 871 bsic 12"});
3848 f_sleep(0.5);
3849
3850 f_probe_for_handover("5.a", "HO to 871-12 triggers inter-BSC HO (ignoring local cells with same ARFCN+BSIC)",
3851 "handover any to arfcn 871 bsic 12",
3852 true, true);
3853}
3854private function f_tc_ho_neighbor_config_6(charstring id) runs on MSC_ConnHdlr {
3855 f_tc_ho_neighbor_config_start();
3856
3857 /*
3858 * bts 0 ARFCN 871 BSIC 10
3859 * bts 1 ARFCN 871 BSIC 11
3860 * bts 2 ARFCN 871 BSIC 12
3861 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
3862 */
3863
3864 log("f_tc_ho_neighbor_config: 6. config error: explicit local and remote neighbors with ambiguous ARFCN+BSIC:"
3865 & " 'neighbor bts 2; neighbor lac 99 arfcn 871 bsic 12'");
3866 f_bts_0_cfg({"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 871 bsic 12"});
3867 f_sleep(0.5);
3868
3869 f_probe_for_handover("6.a", "HO to 871-12 is ambiguous = error",
3870 "handover any to arfcn 871 bsic 12",
3871 false);
3872}
3873private function f_tc_ho_neighbor_config_7(charstring id) runs on MSC_ConnHdlr {
3874 f_tc_ho_neighbor_config_start();
3875
3876 /*
3877 * bts 0 ARFCN 871 BSIC 10
3878 * bts 1 ARFCN 871 BSIC 11
3879 * bts 2 ARFCN 871 BSIC 12
3880 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
3881 */
3882
3883 log("f_tc_ho_neighbor_config: 7. explicit local and remote neighbors:"
3884 & " 'neighbor bts 2; neighbor lac 99 arfcn 123 bsic 45'");
3885 f_bts_0_cfg({"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 123 bsic 45"});
3886 f_sleep(0.5);
3887
3888 f_probe_for_handover("7.a", "HO to 871-12 does HO to bts 2",
3889 "handover any to arfcn 871 bsic 12",
3890 true);
3891 f_probe_for_handover("7.b", "HO to 123-45 triggers inter-BSC HO",
3892 "handover any to arfcn 123 bsic 45",
3893 true, true);
3894}
3895
3896testcase TC_ho_neighbor_config_1() runs on test_CT {
3897 var MSC_ConnHdlr vc_conn;
3898 f_init(3, true);
3899 f_sleep(1.0);
3900 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_1));
3901 vc_conn.done;
3902}
3903testcase TC_ho_neighbor_config_2() runs on test_CT {
3904 var MSC_ConnHdlr vc_conn;
3905 f_init(3, true);
3906 f_sleep(1.0);
3907 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_2));
3908 vc_conn.done;
3909}
3910testcase TC_ho_neighbor_config_3() runs on test_CT {
3911 var MSC_ConnHdlr vc_conn;
3912 f_init(3, true);
3913 f_sleep(1.0);
3914 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_3));
3915 vc_conn.done;
3916}
3917testcase TC_ho_neighbor_config_4() runs on test_CT {
3918 var MSC_ConnHdlr vc_conn;
3919 f_init(3, true);
3920 f_sleep(1.0);
3921 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_4));
3922 vc_conn.done;
3923}
3924testcase TC_ho_neighbor_config_5() runs on test_CT {
3925 var MSC_ConnHdlr vc_conn;
3926 f_init(3, true);
3927 f_sleep(1.0);
3928 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_5));
3929 vc_conn.done;
3930}
3931testcase TC_ho_neighbor_config_6() runs on test_CT {
3932 var MSC_ConnHdlr vc_conn;
3933 f_init(3, true);
3934 f_sleep(1.0);
3935 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_6));
3936 vc_conn.done;
3937}
3938testcase TC_ho_neighbor_config_7() runs on test_CT {
3939 var MSC_ConnHdlr vc_conn;
3940 f_init(3, true);
3941 f_sleep(1.0);
3942 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_7));
3943 vc_conn.done;
3944}
3945
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003946/* OS#3041: Open and close N connections in a normal fashion, and expect no
3947 * BSSMAP Reset just because of that. */
3948testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
3949 var default d;
3950 var integer i;
3951 var DchanTuple dt;
3952
3953 f_init();
3954
3955 /* Wait for initial BSSMAP Reset to pass */
3956 f_sleep(4.0);
3957
3958 d := activate(no_bssmap_reset());
3959
3960 /* Setup up a number of connections and RLSD them again from the MSC
3961 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3962 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02003963 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003964 /* Since we're doing a lot of runs, give each one a fresh
3965 * T_guard from the top. */
3966 T_guard.start;
3967
3968 /* Setup a BSSAP connection and clear it right away. This is
3969 * the MSC telling the BSC about a planned release, it's not an
3970 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02003971 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003972
3973 /* MSC disconnects (RLSD). */
3974 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
3975 }
3976
3977 /* In the buggy behavior, a timeout of 2 seconds happens between above
3978 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3979 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3980 f_sleep(4.0);
3981
3982 deactivate(d);
3983 f_shutdown_helper();
3984}
Harald Welte552620d2017-12-16 23:21:36 +01003985
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003986/* OS#3041: Open and close N connections in a normal fashion, and expect no
3987 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
3988 * the MSC. */
3989testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
3990 var default d;
3991 var integer i;
3992 var DchanTuple dt;
3993 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003994 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
3995 var BssmapCause cause := enum2int(cause_val);
3996
3997 f_init();
3998
3999 /* Wait for initial BSSMAP Reset to pass */
4000 f_sleep(4.0);
4001
4002 d := activate(no_bssmap_reset());
4003
4004 /* Setup up a number of connections and RLSD them again from the MSC
4005 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
4006 * Let's do it some more times for good measure. */
4007 for (i := 0; i < 8; i := i+1) {
4008 /* Since we're doing a lot of runs, give each one a fresh
4009 * T_guard from the top. */
4010 T_guard.start;
4011
4012 /* Setup a BSSAP connection and clear it right away. This is
4013 * the MSC telling the BSC about a planned release, it's not an
4014 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02004015 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01004016
4017 /* Instruct BSC to clear channel */
4018 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
4019
4020 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02004021 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01004022 }
4023
4024 /* In the buggy behavior, a timeout of 2 seconds happens between above
4025 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
4026 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
4027 f_sleep(4.0);
4028
4029 deactivate(d);
4030 f_shutdown_helper();
4031}
4032
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01004033/* OS#3041: Open and close N connections in a normal fashion, and expect no
4034 * BSSMAP Reset just because of that. Close connections from the MS side with a
4035 * Release Ind on RSL. */
4036testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
4037 var default d;
4038 var integer i;
4039 var DchanTuple dt;
4040 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01004041 var integer j;
4042
4043 f_init();
4044
4045 /* Wait for initial BSSMAP Reset to pass */
4046 f_sleep(4.0);
4047
4048 d := activate(no_bssmap_reset());
4049
4050 /* Setup up a number of connections and RLSD them again from the MSC
4051 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
4052 * Let's do it some more times for good measure. */
4053 for (i := 0; i < 8; i := i+1) {
4054 /* Since we're doing a lot of runs, give each one a fresh
4055 * T_guard from the top. */
4056 T_guard.start;
4057
4058 /* Setup a BSSAP connection and clear it right away. This is
4059 * the MSC telling the BSC about a planned release, it's not an
4060 * erratic loss of a connection. */
4061 dt := f_est_dchan('23'O, 23, '00010203040506'O);
4062
4063 /* simulate RLL REL IND */
4064 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
4065
4066 /* expect Clear Request on MSC side */
4067 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
4068
4069 /* Instruct BSC to clear channel */
4070 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
4071 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
4072
4073 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02004074 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01004075 }
4076
4077 /* In the buggy behavior, a timeout of 2 seconds happens between above
4078 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
4079 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
4080 f_sleep(4.0);
4081
4082 deactivate(d);
4083 f_shutdown_helper();
4084}
4085
Harald Welte94e0c342018-04-07 11:33:23 +02004086/***********************************************************************
4087 * IPA style dynamic PDCH
4088 ***********************************************************************/
4089
4090private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
4091 template (omit) RSL_Cause nack := omit)
4092runs on test_CT {
4093 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
4094 var RSL_Message rsl_unused;
4095 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
4096 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
4097 /* expect the BSC to issue the related RSL command */
4098 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
4099 if (istemplatekind(nack, "omit")) {
4100 /* respond with a related acknowledgement */
4101 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
4102 } else {
4103 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
4104 }
4105}
4106
4107private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
4108 template (omit) RSL_Cause nack := omit)
4109runs on test_CT {
4110 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
4111 var RSL_Message rsl_unused;
4112 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
4113 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
4114 /* expect the BSC to issue the related RSL command */
4115 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
4116 if (istemplatekind(nack, "omit")) {
4117 /* respond with a related acknowledgement */
4118 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
4119 } else {
4120 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
4121 }
4122}
4123
4124private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
4125runs on test_CT return charstring {
4126 var charstring cmd, resp;
4127 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01004128 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02004129}
4130
4131private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
4132 template charstring exp)
4133runs on test_CT {
4134 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
4135 if (not match(mode, exp)) {
4136 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02004137 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02004138 }
4139}
4140
4141private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
4142runs on test_CT {
4143 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
4144 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
4145 f_vty_transceive(BSCVTY, "end");
4146}
4147
4148private const charstring TCHF_MODE := "TCH/F mode";
4149private const charstring TCHH_MODE := "TCH/H mode";
4150private const charstring PDCH_MODE := "PDCH mode";
4151private const charstring NONE_MODE := "NONE mode";
4152
4153/* Test IPA PDCH activation / deactivation triggered by VTY */
4154testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
4155 var RSL_Message rsl_unused;
4156
4157 /* change Timeslot 6 before f_init() starts RSL */
4158 f_init_vty();
4159 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
4160 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
4161
4162 f_init(1, false);
4163 f_sleep(1.0);
4164
4165 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
4166
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02004167 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02004168 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
4169 /* The BSC will activate the dynamic PDCH by default, so confirm that */
4170 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
4171 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
4172 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02004173 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02004174 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
4175
4176 /* De-activate it via VTY */
4177 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
4178 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02004179 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02004180 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
4181
4182 /* re-activate it via VTY */
4183 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
4184 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02004185 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02004186 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
4187
4188 /* and finally de-activate it again */
4189 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
4190 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02004191 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02004192 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
4193
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02004194 /* clean up config */
4195 f_ts_set_chcomb(0, 0, 6, "PDCH");
4196
Harald Welte94e0c342018-04-07 11:33:23 +02004197 setverdict(pass);
4198}
4199
4200/* Test IPA PDCH activation NACK */
4201testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
4202 var RSL_Message rsl_unused;
4203
4204 /* change Timeslot 6 before f_init() starts RSL */
4205 f_init_vty();
4206 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
4207 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
4208
4209 f_init(1, false);
4210 f_sleep(1.0);
4211
4212 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
4213
4214 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
4215 /* The BSC will activate the dynamic PDCH by default, so confirm that */
4216 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
4217 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
4218 f_sleep(1.0);
4219 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
4220
4221 /* De-activate it via VTY */
4222 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
4223 f_sleep(1.0);
4224 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
4225
4226 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
4227 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
4228 f_sleep(1.0);
4229 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
4230
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02004231 /* clean up config */
4232 f_ts_set_chcomb(0, 0, 6, "PDCH");
4233
Harald Welte94e0c342018-04-07 11:33:23 +02004234 setverdict(pass);
4235}
4236
4237
4238/***********************************************************************
4239 * Osmocom style dynamic PDCH
4240 ***********************************************************************/
4241
4242private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
4243 template (omit) RSL_Cause nack := omit)
4244runs on test_CT {
4245 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
4246 var RSL_Message rsl_unused;
4247 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
4248 /* FIXME: no VTY command to activate Osmocom PDCH !! */
4249 /* expect the BSC to issue the related RSL command */
4250 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
4251 if (istemplatekind(nack, "omit")) {
4252 /* respond with a related acknowledgement */
4253 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
4254 } else {
4255 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
4256 }
4257}
4258
4259private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
4260 template (omit) RSL_Cause nack := omit)
4261runs on test_CT {
4262 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
4263 var RSL_Message rsl_unused;
4264 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
4265 /* FIXME: no VTY command to activate Osmocom PDCH !! */
4266 /* expect the BSC to issue the related RSL command */
4267 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
4268 if (istemplatekind(nack, "omit")) {
4269 /* respond with a related acknowledgement */
4270 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
4271 } else {
4272 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
4273 }
4274}
4275
4276/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
4277testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
4278 var RSL_Message rsl_unused;
4279
4280 /* change Timeslot 6 before f_init() starts RSL */
4281 f_init_vty();
4282 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
4283 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
4284
4285 f_init(1, false);
4286 f_sleep(1.0);
4287
4288 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
4289
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02004290 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02004291 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
4292 /* The BSC will activate the dynamic PDCH by default, so confirm that */
4293 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
4294
4295 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
4296 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02004297 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 +02004298 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
4299
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02004300 /* clean up config */
4301 f_ts_set_chcomb(0, 0, 6, "PDCH");
4302
Harald Welte94e0c342018-04-07 11:33:23 +02004303 setverdict(pass);
4304}
4305
4306/* Test Osmocom dyn PDCH activation NACK behavior */
4307testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
4308 var RSL_Message rsl_unused;
4309
4310 /* change Timeslot 6 before f_init() starts RSL */
4311 f_init_vty();
4312 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
4313 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
4314
4315 f_init(1, false);
4316 f_sleep(1.0);
4317
4318 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
4319
4320 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
4321 /* The BSC will activate the dynamic PDCH by default, so confirm that */
4322 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
4323
4324 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
4325 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
4326 f_sleep(1.0);
4327 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
4328
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02004329 /* clean up config */
4330 f_ts_set_chcomb(0, 0, 6, "PDCH");
4331
Harald Welte94e0c342018-04-07 11:33:23 +02004332 setverdict(pass);
4333}
4334
Stefan Sperling0796a822018-10-05 13:01:39 +02004335testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02004336 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02004337 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
4338 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
4339 }
4340}
4341
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02004342testcase TC_chopped_ipa_payload() runs on test_CT {
4343 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
4344 /* TODO: mp_bsc_ctrl_port does not work yet */};
4345 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
4346 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
4347 }
4348}
4349
4350
Harald Welte0ea2d5e2018-04-07 21:40:29 +02004351/* Dyn PDCH todo:
4352 * activate OSMO as TCH/F
4353 * activate OSMO as TCH/H
4354 * does the BSC-located PCU socket get the updated INFO?
4355 * what if no PCU is connected at the time?
4356 * is the info correct on delayed PCU (re)connect?
4357 */
Harald Welte94e0c342018-04-07 11:33:23 +02004358
Harald Welte28d943e2017-11-25 15:00:50 +01004359control {
Harald Welte898113b2018-01-31 18:32:21 +01004360 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +01004361 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01004362 execute( TC_ctrl_msc0_connection_status() );
Harald Welte96c94412017-12-09 03:12:45 +01004363 execute( TC_ctrl() );
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02004364 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_SCCPlite_SERVER) {
4365 execute( TC_ctrl_location() );
4366 }
Harald Welte898113b2018-01-31 18:32:21 +01004367
4368 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +01004369 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +01004370 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +01004371 execute( TC_chan_act_ack_noest() );
4372 execute( TC_chan_act_ack_est_ind_noreply() );
4373 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +01004374 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +01004375 execute( TC_chan_exhaustion() );
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07004376 execute( TC_chan_deact_silence() );
Harald Welte4003d112017-12-09 22:35:39 +01004377 execute( TC_chan_rel_rll_rel_ind() );
4378 execute( TC_chan_rel_conn_fail() );
4379 execute( TC_chan_rel_hard_clear() );
Harald Welte99787102019-02-04 10:41:36 +01004380 execute( TC_chan_rel_hard_clear_csfb() );
Harald Welted8c36cd2017-12-09 23:05:31 +01004381 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +02004382 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +01004383 execute( TC_chan_rel_a_reset() );
Harald Welte6f521d82017-12-11 19:52:02 +01004384
Harald Weltecfe2c962017-12-15 12:09:32 +01004385 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +01004386
4387 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +01004388 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +01004389 execute( TC_assignment_csd() );
4390 execute( TC_assignment_ctm() );
4391 execute( TC_assignment_sign() );
4392 execute( TC_assignment_fr_a5_0() );
4393 execute( TC_assignment_fr_a5_1() );
Harald Welte8f67d1d2018-05-25 20:38:42 +02004394 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
4395 execute( TC_assignment_fr_a5_1_codec_missing() );
4396 }
Harald Welte235ebf12017-12-15 14:18:16 +01004397 execute( TC_assignment_fr_a5_3() );
4398 execute( TC_assignment_fr_a5_4() );
Harald Welte3c86ea02018-05-10 22:28:05 +02004399 execute( TC_ciph_mode_a5_0() );
4400 execute( TC_ciph_mode_a5_1() );
4401 execute( TC_ciph_mode_a5_3() );
Harald Welte16a4adf2017-12-14 18:54:01 +01004402
Harald Welte60aa5762018-03-21 19:33:13 +01004403 execute( TC_assignment_codec_fr() );
4404 execute( TC_assignment_codec_hr() );
4405 execute( TC_assignment_codec_efr() );
4406 execute( TC_assignment_codec_amr_f() );
4407 execute( TC_assignment_codec_amr_h() );
Philipp Maier8a581d22019-03-26 18:32:48 +01004408
4409 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
4410 execute( TC_assignment_codec_amr_f_S1() );
4411 execute( TC_assignment_codec_amr_h_S1() );
4412 execute( TC_assignment_codec_amr_f_S124() );
4413 execute( TC_assignment_codec_amr_h_S124() );
4414 execute( TC_assignment_codec_amr_f_S0() );
4415 execute( TC_assignment_codec_amr_f_S02() );
4416 execute( TC_assignment_codec_amr_f_S024() );
4417 execute( TC_assignment_codec_amr_f_S0247() );
4418 execute( TC_assignment_codec_amr_h_S0() );
4419 execute( TC_assignment_codec_amr_h_S02() );
4420 execute( TC_assignment_codec_amr_h_S024() );
4421 execute( TC_assignment_codec_amr_h_S0247() );
4422 execute( TC_assignment_codec_amr_f_S01234567() );
4423 execute( TC_assignment_codec_amr_f_S0234567() );
4424 execute( TC_assignment_codec_amr_f_zero() );
4425 execute( TC_assignment_codec_amr_f_unsupp() );
4426 execute( TC_assignment_codec_amr_h_S7() );
4427 }
Harald Welte60aa5762018-03-21 19:33:13 +01004428
Philipp Maierac09bfc2019-01-08 13:41:39 +01004429 execute( TC_assignment_codec_fr_exhausted_req_hr() );
4430 execute( TC_assignment_codec_fr_exhausted_req_fr() );
4431 execute( TC_assignment_codec_fr_exhausted_req_fr_hr() );
4432 execute( TC_assignment_codec_fr_exhausted_req_hr_fr() );
4433 execute( TC_assignment_codec_hr_exhausted_req_fr() );
4434 execute( TC_assignment_codec_hr_exhausted_req_hr() );
4435 execute( TC_assignment_codec_hr_exhausted_req_hr_fr() );
4436 execute( TC_assignment_codec_hr_exhausted_req_fr_hr() );
4437 execute( TC_assignment_codec_req_hr_fr() );
4438 execute( TC_assignment_codec_req_fr_hr() );
4439
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +02004440 if (mp_enable_osmux_test) {
4441 execute( TC_assignment_osmux() );
4442 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004443
Harald Welte898113b2018-01-31 18:32:21 +01004444 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +01004445 execute( TC_rll_est_ind_inact_lchan() );
4446 execute( TC_rll_est_ind_inval_sapi1() );
4447 execute( TC_rll_est_ind_inval_sapi3() );
4448 execute( TC_rll_est_ind_inval_sacch() );
4449
Harald Welte898113b2018-01-31 18:32:21 +01004450 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +01004451 execute( TC_paging_imsi_nochan() );
4452 execute( TC_paging_tmsi_nochan() );
4453 execute( TC_paging_tmsi_any() );
4454 execute( TC_paging_tmsi_sdcch() );
4455 execute( TC_paging_tmsi_tch_f() );
4456 execute( TC_paging_tmsi_tch_hf() );
4457 execute( TC_paging_imsi_nochan_cgi() );
4458 execute( TC_paging_imsi_nochan_lac_ci() );
4459 execute( TC_paging_imsi_nochan_ci() );
4460 execute( TC_paging_imsi_nochan_lai() );
4461 execute( TC_paging_imsi_nochan_lac() );
4462 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +01004463 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
4464 execute( TC_paging_imsi_nochan_rnc() );
4465 execute( TC_paging_imsi_nochan_lac_rnc() );
4466 execute( TC_paging_imsi_nochan_lacs() );
4467 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +01004468 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +01004469 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +01004470 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +01004471 execute( TC_paging_counter() );
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01004472 execute( TC_paging_resp_unsol() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +01004473
4474 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +01004475 execute( TC_rsl_unknown_unit_id() );
4476
4477 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +01004478
4479 execute( TC_classmark() );
4480 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +01004481 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004482 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +01004483 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +01004484 execute( TC_err_84_unknown_msg() );
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004485
Harald Welte261af4b2018-02-12 21:20:39 +01004486 execute( TC_ho_int() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004487
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004488 execute( TC_ho_out_of_this_bsc() );
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004489 execute( TC_ho_out_fail_no_msc_response() );
4490 execute( TC_ho_out_fail_rr_ho_failure() );
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02004491 execute( TC_ho_out_fail_no_result_after_ho_cmd() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004492
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004493 execute( TC_ho_into_this_bsc() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004494 execute( TC_ho_in_fail_msc_clears() );
4495 execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
4496 execute( TC_ho_in_fail_no_detect() );
4497 execute( TC_ho_in_fail_no_detect2() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01004498
Neels Hofmeyr91401012019-07-11 00:42:35 +02004499 execute( TC_ho_neighbor_config_1() );
4500 execute( TC_ho_neighbor_config_2() );
4501 execute( TC_ho_neighbor_config_3() );
4502 execute( TC_ho_neighbor_config_4() );
4503 execute( TC_ho_neighbor_config_5() );
4504 execute( TC_ho_neighbor_config_6() );
4505 execute( TC_ho_neighbor_config_7() );
4506
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01004507 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01004508 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01004509 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +02004510
4511 execute( TC_dyn_pdch_ipa_act_deact() );
4512 execute( TC_dyn_pdch_ipa_act_nack() );
4513 execute( TC_dyn_pdch_osmo_act_deact() );
4514 execute( TC_dyn_pdch_osmo_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +02004515
Stefan Sperling0796a822018-10-05 13:01:39 +02004516 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02004517 execute( TC_chopped_ipa_payload() );
Stefan Sperling0796a822018-10-05 13:01:39 +02004518
Harald Welte99f3ca02018-06-14 13:40:29 +02004519 /* at bottom as they might crash OsmoBSC before OS#3182 is fixed */
4520 execute( TC_early_conn_fail() );
4521 execute( TC_late_conn_fail() );
4522
Harald Welte28d943e2017-11-25 15:00:50 +01004523}
4524
4525}