blob: c731b7c37cee9ffc598c66a49d59285f54684893 [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 *
10 * This test suite tests OsmoBSC while emulating both multiple BTS + MS as
11 * well as the MSC. See README for more details.
12 *
13 * There are test cases that run in so-called 'handler mode' and test cases
14 * that run directly on top of the BSSAP and RSL CodecPorts. The "handler mode"
15 * tests abstract the multiplexing/demultiplexing of multiple SCCP connections
16 * and/or RSL channels and are hence suitable for higher-level test cases, while
17 * the "raw" tests directly on top of the CodecPorts are more suitable for lower-
18 * level testing.
19 */
20
Harald Welte4003d112017-12-09 22:35:39 +010021import from General_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010022import from Osmocom_Types all;
Harald Welteae026692017-12-09 01:03:01 +010023import from GSM_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010024import from IPL4asp_Types all;
25
Harald Welte6f521d82017-12-11 19:52:02 +010026import from BSSAP_Types all;
Harald Welte6811d102019-04-14 22:23:14 +020027import from RAN_Adapter all;
Harald Welteae026692017-12-09 01:03:01 +010028import from BSSAP_CodecPort all;
29import from BSSMAP_Templates all;
Harald Welte28d943e2017-11-25 15:00:50 +010030import from IPA_Emulation all;
Stefan Sperling830dc9d2018-02-12 21:08:28 +010031import from IPA_CodecPort all;
Harald Welteae026692017-12-09 01:03:01 +010032import from IPA_Types all;
Stefan Sperling0796a822018-10-05 13:01:39 +020033import from IPA_Testing all;
Harald Welteae026692017-12-09 01:03:01 +010034import from RSL_Types all;
Harald Welte624f9632017-12-16 19:26:04 +010035import from RSL_Emulation all;
Daniel Willmann191e0d92018-01-17 12:44:35 +010036import from MGCP_Emulation all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010037import from MGCP_Templates all;
38import from MGCP_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010039
Harald Welte96c94412017-12-09 03:12:45 +010040import from Osmocom_CTRL_Functions all;
Harald Weltea5d2ab22017-12-09 14:21:42 +010041import from Osmocom_CTRL_Types all;
Harald Welteffe55fc2018-01-17 22:39:54 +010042import from Osmocom_CTRL_Adapter all;
Harald Welte96c94412017-12-09 03:12:45 +010043
Harald Weltebc03c762018-02-12 18:09:38 +010044import from Osmocom_VTY_Functions all;
45import from TELNETasp_PortType all;
46
Harald Welte6f521d82017-12-11 19:52:02 +010047import from MobileL3_CommonIE_Types all;
Harald Weltee3bd6582018-01-31 22:51:25 +010048import from MobileL3_Types all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010049import from MobileL3_RRM_Types all;
Harald Welte6f521d82017-12-11 19:52:02 +010050import from L3_Templates all;
51import from GSM_RR_Types all;
52
Stefan Sperlingc307e682018-06-14 15:15:46 +020053import from SCCP_Templates all;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010054import from BSSMAP_Templates all;
55
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010056import from SCCPasp_Types all;
57
Harald Welte5d1a2202017-12-13 19:51:29 +010058const integer NUM_BTS := 3;
Harald Welteae026692017-12-09 01:03:01 +010059const float T3101_MAX := 12.0;
Harald Welte28d943e2017-11-25 15:00:50 +010060
Harald Welte799c97b2017-12-14 17:50:30 +010061/* make sure to sync this with the osmo-bts.cfg you're using */
Philipp Maiercb6cc482018-03-26 13:08:00 +020062const integer NUM_TCHH_PER_BTS := 2;
63const integer NUM_TCHF_PER_BTS := 4;
Harald Weltedd8cbf32018-01-28 12:07:52 +010064const integer NUM_SDCCH_PER_BTS := 4;
Harald Welte799c97b2017-12-14 17:50:30 +010065
Harald Welte4003d112017-12-09 22:35:39 +010066
Harald Welte21b46bd2017-12-17 19:46:32 +010067/* per-BTS state which we keep */
Harald Welte96c94412017-12-09 03:12:45 +010068type record BTS_State {
Harald Welte21b46bd2017-12-17 19:46:32 +010069 /* component reference to the IPA_Client component used for RSL */
Harald Weltea5d2ab22017-12-09 14:21:42 +010070 IPA_Client rsl
Harald Welte96c94412017-12-09 03:12:45 +010071}
72
Harald Weltea4ca4462018-02-09 00:17:14 +010073type component test_CT extends CTRL_Adapter_CT {
Harald Welte21b46bd2017-12-17 19:46:32 +010074 /* Array of per-BTS state */
Harald Welte96c94412017-12-09 03:12:45 +010075 var BTS_State bts[NUM_BTS];
Harald Welte89ab1912018-02-23 18:56:29 +010076 /* RSL common Channel Port (for RSL_Emulation) */
77 port RSL_CCHAN_PT RSL_CCHAN[NUM_BTS];
Harald Welte21b46bd2017-12-17 19:46:32 +010078 /* array of per-BTS RSL test ports */
Harald Welteae026692017-12-09 01:03:01 +010079 port IPA_RSL_PT IPA_RSL[NUM_BTS];
Stefan Sperling830dc9d2018-02-12 21:08:28 +010080 port IPA_CODEC_PT IPA; /* Required for compilation of TC_rsl_unknown_unit_id() */
Harald Weltea5d2ab22017-12-09 14:21:42 +010081
Daniel Willmann191e0d92018-01-17 12:44:35 +010082 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +010083 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +010084
Harald Welte6811d102019-04-14 22:23:14 +020085 var RAN_Adapter g_bssap;
Harald Weltea4ca4462018-02-09 00:17:14 +010086 /* for old legacy-tests only */
87 port BSSAP_CODEC_PT BSSAP;
88
Harald Welte21b46bd2017-12-17 19:46:32 +010089 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +010090 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +010091
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +020092 /* Osmux is enabled through VTY */
93 var boolean g_osmux_enabled := false;
94
Harald Welte21b46bd2017-12-17 19:46:32 +010095 /* global test case guard timer */
Harald Welteae026692017-12-09 01:03:01 +010096 timer T_guard := 30.0;
97
Harald Welte28d943e2017-11-25 15:00:50 +010098}
99
100modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +0100101 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +0100102 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100103 /* port number to which to establish the IPA OML connections */
104 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +0100105 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +0100106 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +0100107 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +0100108 integer mp_bsc_ctrl_port := 4249;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100109 /* IP address at which the test binds */
110 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100111
Harald Welte6811d102019-04-14 22:23:14 +0200112 RAN_Configuration mp_bssap_cfg := {
Harald Welte7ef51aa2018-04-16 19:16:01 +0200113 transport := BSSAP_TRANSPORT_AoIP,
Harald Weltea4ca4462018-02-09 00:17:14 +0100114 sccp_service_type := "mtp3_itu",
115 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
116 own_pc := 185,
117 own_ssn := 254,
118 peer_pc := 187,
119 peer_ssn := 254,
Philipp Maier38d68942018-03-29 15:38:09 +0200120 sio := '83'O,
121 rctx := 0
Harald Weltea4ca4462018-02-09 00:17:14 +0100122 };
123}
124
Philipp Maier48604732018-10-09 15:00:37 +0200125private function f_gen_test_hdlr_pars() return TestHdlrParams {
126
127 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
128 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
129 pars.aoip := true;
130 } else {
131 pars.aoip := false;
132 }
133
134 return pars;
135}
136
Philipp Maier282ca4b2018-02-27 17:17:00 +0100137private function f_shutdown_helper() runs on test_CT {
Daniel Willmann637ef6c2018-07-25 10:49:09 +0200138 all component.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100139 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200140 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100141}
142
Harald Weltea4ca4462018-02-09 00:17:14 +0100143private function f_legacy_bssap_reset() runs on test_CT {
144 var BSSAP_N_UNITDATA_ind ud_ind;
145 timer T := 5.0;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200146 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 +0100147 T.start;
148 alt {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200149 [] 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 +0100150 log("Received RESET-ACK in response to RESET, we're ready to go!");
151 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200152 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Weltea4ca4462018-02-09 00:17:14 +0100153 log("Respoding to inbound RESET with RESET-ACK");
154 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200155 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Weltea4ca4462018-02-09 00:17:14 +0100156 repeat;
157 }
158 [] BSSAP.receive { repeat; }
159 [] T.timeout { setverdict(fail, "Waiting for RESET-ACK after sending RESET"); }
160 }
Harald Welte28d943e2017-11-25 15:00:50 +0100161}
162
Harald Welteae026692017-12-09 01:03:01 +0100163type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100164 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100165 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100166 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100167 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100168 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100169 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100170 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100171 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100172}
173
Harald Welte21b46bd2017-12-17 19:46:32 +0100174/*! Start the IPA/RSL related bits for one IPA_Client.
175 * \param clnt IPA_Client for which to establish
176 * \param bsc_host IP address / hostname of the BSC
177 * \param bsc_port TCP port number of the BSC
178 * \param i number identifying this BTS
179 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100180function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
181 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100182runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100183 timer T := 10.0;
184
Harald Welte96c94412017-12-09 03:12:45 +0100185 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welteae026692017-12-09 01:03:01 +0100186 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA");
187 clnt.ccm_pars := c_IPA_default_ccm_pars;
188 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
189 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100190 if (handler_mode) {
191 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL");
Harald Welte89ab1912018-02-23 18:56:29 +0100192 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100193 }
Harald Welteae026692017-12-09 01:03:01 +0100194
195 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Harald Welte624f9632017-12-16 19:26:04 +0100196 if (handler_mode) {
197 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
198 } else {
199 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
200 }
Harald Welteae026692017-12-09 01:03:01 +0100201
Harald Welte5d1a2202017-12-13 19:51:29 +0100202 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100203 if (handler_mode) {
204 clnt.vc_RSL.start(RSL_Emulation.main());
205 return;
206 }
Harald Welteae026692017-12-09 01:03:01 +0100207
208 /* wait for IPA RSL link to connect and send ID ACK */
209 T.start;
210 alt {
211 [] IPA_RSL[i].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_ID_ACK}) {
212 T.stop;
213 IPA_RSL[i].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_PAGING_LOAD_IND(23)));
214 }
Harald Welte60e823a2017-12-10 14:10:59 +0100215 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100216 [] IPA_RSL[i].receive { repeat }
217 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100218 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200219 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100220 }
221 }
222}
223
Harald Welte12055472018-03-17 20:10:08 +0100224function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
225 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
226 return;
227 }
228 clnt.vc_IPA.stop;
229 if (isbound(clnt.vc_RSL)) {
230 clnt.vc_RSL.stop;
231 }
232}
233
Harald Welte21b46bd2017-12-17 19:46:32 +0100234/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100235function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
236 timer T := secs_max;
237 T.start;
238 while (true) {
239 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
240 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100241 /* the 'degraded' state exists from OML connection time, and we have to wait
242 * until all MO's are initialized */
243 T.start(1.0);
244 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100245 return;
246 }
Harald Weltef0d6ac62017-12-17 17:02:21 +0100247 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100248 if (not T.running) {
Max99253902018-11-16 17:57:39 +0100249 setverdict(fail, "Timeout waiting for BTS" & int2str(bts_nr) & " oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +0200250 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100251 }
252 }
253}
254
Harald Welte21b46bd2017-12-17 19:46:32 +0100255/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +0100256altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +0100257 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100258 [] T_guard.timeout {
259 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +0200260 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100261 }
Harald Welte60e823a2017-12-10 14:10:59 +0100262 /* always respond with RESET ACK to RESET */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200263 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Welte60e823a2017-12-10 14:10:59 +0100264 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200265 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Welte69c1c262017-12-13 21:02:08 +0100266 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +0100267 }
Harald Welte28d943e2017-11-25 15:00:50 +0100268}
269
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100270altstep no_bssmap_reset() runs on test_CT {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200271 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100272 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +0200273 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100274 }
275}
276
Daniel Willmann191e0d92018-01-17 12:44:35 +0100277function f_init_mgcp(charstring id) runs on test_CT {
278 id := id & "-MGCP";
279
280 var MGCPOps ops := {
281 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
282 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
283 };
284 var MGCP_conn_parameters mgcp_pars := {
285 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +0100286 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +0100287 mgw_ip := mp_test_ip,
288 mgw_udp_port := 2427
289 };
290
291 vc_MGCP := MGCP_Emulation_CT.create(id);
292 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
293}
294
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200295/* Enable or disable (current default) Osmux. When enabling, BSSMAP Reset
296 * contains extra IE (OsmuxSupport) and osmo-bsc will handle AssignReq with
297 * OsmuxCID IE.
298 */
299private function f_vty_allow_osmux(boolean allow) runs on test_CT {
300 f_vty_enter_cfg_msc(BSCVTY, 0);
301 if (allow) {
302 f_vty_transceive(BSCVTY, "osmux on");
303 } else {
304 f_vty_transceive(BSCVTY, "osmux off");
305 }
306 f_vty_transceive(BSCVTY, "exit");
307 f_vty_transceive(BSCVTY, "exit");
308 g_osmux_enabled := allow;
309}
310
Max2253c0b2018-11-06 19:28:05 +0100311function f_init_vty(charstring id := "foo") runs on test_CT {
Harald Welte94e0c342018-04-07 11:33:23 +0200312 if (BSCVTY.checkstate("Mapped")) {
313 /* skip initialization if already executed once */
314 return;
315 }
Harald Weltebc03c762018-02-12 18:09:38 +0100316 map(self:BSCVTY, system:BSCVTY);
317 f_vty_set_prompts(BSCVTY);
318 f_vty_transceive(BSCVTY, "enable");
319}
320
Harald Welte21b46bd2017-12-17 19:46:32 +0100321/* global initialization function
322 * \param nr_bts Number of BTSs we should start/bring up
323 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200324function 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 +0100325 var integer i;
Harald Welte28d943e2017-11-25 15:00:50 +0100326
Harald Welteae026692017-12-09 01:03:01 +0100327 if (g_initialized) {
328 return;
Harald Welte28d943e2017-11-25 15:00:50 +0100329 }
Harald Welteae026692017-12-09 01:03:01 +0100330 g_initialized := true;
331
Daniel Willmanne68f9272018-11-27 15:15:28 +0100332 T_guard.start;
333 activate(as_Tguard());
334
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200335 f_init_vty("VirtMSC");
336 f_vty_allow_osmux(allow_osmux);
337
Harald Welte6811d102019-04-14 22:23:14 +0200338 /* Call a function of our 'parent component' RAN_Adapter_CT to start the
Harald Welteae026692017-12-09 01:03:01 +0100339 * MSC-side BSSAP emulation */
Harald Welte67089ee2018-01-17 22:19:03 +0100340 if (handler_mode) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200341 var RanOps ranops := MSC_RanOps;
342 ranops.use_osmux := g_osmux_enabled;
343 f_ran_adapter_init(g_bssap, mp_bssap_cfg, "VirtMSC", ranops);
Harald Welte3ca0ce12019-04-23 17:18:48 +0200344 f_ran_adapter_start(g_bssap);
Harald Welte67089ee2018-01-17 22:19:03 +0100345 } else {
Harald Welte3ca0ce12019-04-23 17:18:48 +0200346 f_ran_adapter_init(g_bssap, mp_bssap_cfg, "VirtMSC", omit);
Harald Weltea4ca4462018-02-09 00:17:14 +0100347 connect(self:BSSAP, g_bssap.vc_SCCP:SCCP_SP_PORT);
Harald Welte3ca0ce12019-04-23 17:18:48 +0200348 f_ran_adapter_start(g_bssap);
Harald Weltea4ca4462018-02-09 00:17:14 +0100349 f_legacy_bssap_reset();
Harald Welte67089ee2018-01-17 22:19:03 +0100350 }
Harald Welted5833a82018-05-27 16:52:56 +0200351
Harald Welteffe55fc2018-01-17 22:39:54 +0100352 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +0100353
Daniel Willmann191e0d92018-01-17 12:44:35 +0100354 f_init_mgcp("VirtMSC");
355
Harald Welte89d42e82017-12-17 16:42:41 +0100356 for (i := 0; i < nr_bts; i := i+1) {
Harald Weltea5d2ab22017-12-09 14:21:42 +0100357 /* wait until osmo-bts-omldummy has respawned */
358 f_wait_oml(i, "degraded", 5.0);
359 /* start RSL connection */
Harald Welte624f9632017-12-16 19:26:04 +0100360 f_ipa_rsl_start(bts[i].rsl, mp_bsc_ip, mp_bsc_rsl_port, i, handler_mode);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100361 /* wait until BSC tells us "connected" */
362 f_wait_oml(i, "connected", 5.0);
Harald Welte696ddb62017-12-08 14:01:43 +0100363 }
364
Harald Welte28d943e2017-11-25 15:00:50 +0100365}
366
Maxd4e56962018-10-31 19:08:25 +0100367/* expect to receive a RSL message matching a specified template on a given BTS / stream */
Harald Welteae026692017-12-09 01:03:01 +0100368function f_exp_ipa_rx(integer bts_nr, template RSL_Message t_rx, float t_secs := 2.0, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
369runs on test_CT return RSL_Message {
370 var ASP_RSL_Unitdata rx_rsl_ud;
371 timer T := t_secs;
372
373 T.start;
374 alt {
375 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(sid, t_rx)) -> value rx_rsl_ud {
376 T.stop;
377 }
378 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +0100379 [] T.timeout {
380 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +0200381 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +0100382 }
Harald Welteae026692017-12-09 01:03:01 +0100383 }
384 return rx_rsl_ud.rsl;
385}
386
Harald Welte21b46bd2017-12-17 19:46:32 +0100387/* helper function to transmit RSL on a given BTS/stream */
Harald Welteae026692017-12-09 01:03:01 +0100388function f_ipa_tx(integer bts_nr, template RSL_Message t_tx, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
389runs on test_CT {
390 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(sid, t_tx));
391}
392
393
Harald Welte4003d112017-12-09 22:35:39 +0100394/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +0100395testcase TC_chan_act_noreply() runs on test_CT {
396 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +0100397 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +0100398
Harald Welte89d42e82017-12-17 16:42:41 +0100399 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +0100400
Harald Welteae026692017-12-09 01:03:01 +0100401 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 +0100402 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welteae026692017-12-09 01:03:01 +0100403 setverdict(pass);
Harald Welte28d943e2017-11-25 15:00:50 +0100404}
405
Harald Welte4003d112017-12-09 22:35:39 +0100406/* verify if the "chreq:total" counter increments as expected */
407testcase TC_chan_act_counter() runs on test_CT {
408 var BSSAP_N_UNITDATA_ind ud_ind;
409 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +0100410 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +0100411
Harald Welte89d42e82017-12-17 16:42:41 +0100412 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100413
414 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
415 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 +0100416 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welte4003d112017-12-09 22:35:39 +0100417 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total", chreq_total+1);
418
419 setverdict(pass);
420}
421
Harald Welteae026692017-12-09 01:03:01 +0100422/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
423testcase TC_chan_act_ack_noest() runs on test_CT {
424 var RSL_Message rx_rsl;
425
Harald Welte89d42e82017-12-17 16:42:41 +0100426 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100427
428 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100429 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100430
431 /* expect BSC to disable the channel again if there's no RLL EST IND */
432 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
433
434 setverdict(pass);
435}
436
437/* Test behavior if MSC never answers to CR */
438testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +0100439 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
440 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +0100441 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +0100442 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +0100443
Harald Welte89d42e82017-12-17 16:42:41 +0100444 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100445
446 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100447 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100448
449 var octetstring l3 := '00010203040506'O
450 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
451
452 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
453
454 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +0100455 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100456 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Harald Welteae026692017-12-09 01:03:01 +0100457 setverdict(pass);
458}
459
460/* Test behavior if MSC answers with CREF to CR */
461testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
462 var BSSAP_N_CONNECT_ind rx_c_ind;
463 var RSL_Message rx_rsl;
464
Harald Welte89d42e82017-12-17 16:42:41 +0100465 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +0100466
467 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100468 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +0100469
470 var octetstring l3 := '00010203040506'O
471 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
472
473 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
474 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
475
476 /* expect BSC to disable the channel */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100477 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Harald Welteae026692017-12-09 01:03:01 +0100478 setverdict(pass);
479}
480
Harald Welte618ef642017-12-14 14:58:20 +0100481/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
482testcase TC_chan_act_nack() runs on test_CT {
483 var RSL_Message rx_rsl;
484 var integer chact_nack;
485
Harald Welte89d42e82017-12-17 16:42:41 +0100486 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +0100487
488 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
489
490 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
491 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
492 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
493
494 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
495
496 /* wait for some time to hope the NACK arrives before the CTRL GET below */
497 f_sleep(0.5);
498
499 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
500
501 setverdict(pass);
502}
503
Harald Welte799c97b2017-12-14 17:50:30 +0100504/* Test for channel exhaustion due to RACH overload */
505testcase TC_chan_exhaustion() runs on test_CT {
506 var ASP_RSL_Unitdata rsl_ud;
507 var integer i;
508 var integer chreq_total, chreq_nochan;
509
Harald Welte89d42e82017-12-17 16:42:41 +0100510 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +0100511
512 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
513 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
514
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +0100515 /* GSM 04.08 Table 9.9a:
516 * RA = '33'O -> Establishment cause = 0011xxxx (MS dual rate capable and asks for "TCH/H or TCH/F").
517 * With current setup, expect 4xSDCCH + 4xTCH/F + 1xTCH/H to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +0200518 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 +0100519 var RslChannelNr chan_nr := f_chreq_act_ack('33'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +0100520 }
521
522 IPA_RSL[0].clear;
523
Harald Weltedd8cbf32018-01-28 12:07:52 +0100524 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +0200525 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +0100526
527 /* now expect additional channel activations to fail */
528 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
529
530 alt {
531 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
532 tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
533 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
534 }
535 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
536 var GsmRrMessage rr;
537 /* match on IMM ASS REJ */
538 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
539 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
540 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+1);
Harald Welte799c97b2017-12-14 17:50:30 +0100542 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
543 chreq_nochan+1);
544 setverdict(pass);
545 } else {
546 repeat;
547 }
548 }
549 [] IPA_RSL[0].receive { repeat; }
550 }
551}
552
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +0700553/* Test channel deactivation due to silence from MS */
554testcase TC_chan_deact_silence() runs on test_CT {
555 var RslChannelNr chan_nr;
556
557 f_init(1);
558
559 /* Request for a dedicated channel */
560 chan_nr := f_chreq_act_ack('23'O);
561
562 /* Wait some time until the channel is released */
563 f_sleep(2.0);
564
565 /* Expect CHANnel RELease */
566 alt {
567 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
568 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
569 log("Received CHANnel RELease");
570 setverdict(pass);
571 }
572 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
573 tr_RSL_IMM_ASSIGN(?))) {
574 /* See OS#3709, OsmoBSC should not send Immediate
575 * Assignment Reject since a dedicated channel was
576 * already allocated, and Immediate Assignment was
577 * already sent. */
578 setverdict(fail, "Unexpected Immediate Assignment!");
579 }
580 [] IPA_RSL[0].receive {
581 setverdict(fail, "Unexpected RSL message!");
582 }
583 }
584}
585
Harald Weltecfe2c962017-12-15 12:09:32 +0100586/***********************************************************************
587 * Assignment Testing
588 ***********************************************************************/
589
Neels Hofmeyrda4a6952018-06-14 04:02:49 +0200590/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction,
591 * except for the inter-BSC handover, MT side) */
Harald Weltecfe2c962017-12-15 12:09:32 +0100592testcase TC_outbound_connect() runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +0100593 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +0100594
Harald Weltea4ca4462018-02-09 00:17:14 +0100595 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 +0100596 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
597 setverdict(pass);
598}
599
Harald Welte16a4adf2017-12-14 18:54:01 +0100600/* Test behavior if MSC answers with CREF to CR */
601testcase TC_assignment_cic_only() runs on test_CT {
602 var BSSAP_N_CONNECT_ind rx_c_ind;
603 var RSL_Message rx_rsl;
604 var DchanTuple dt;
605
Harald Welte89d42e82017-12-17 16:42:41 +0100606 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +0100607
608 dt := f_est_dchan('23'O, 23, '00000000'O);
Harald Welte17b27da2018-05-25 20:33:53 +0200609 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
610 /* send assignment without AoIP IEs */
611 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
612 } else {
613 /* Send assignmetn without CIC in IPA case */
614 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
615 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
616 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
617 }
Harald Welte16a4adf2017-12-14 18:54:01 +0100618 alt {
619 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
620 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
621 }
Harald Welte235ebf12017-12-15 14:18:16 +0100622 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +0100623 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
624 setverdict(pass);
625 }
626 [] BSSAP.receive { repeat; }
627 }
628}
629
Harald Welteed848512018-05-24 22:27:58 +0200630/* generate an assignment request for either AoIP or SCCPlite */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200631function f_gen_ass_req(boolean osmux_enabled := false) return PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200632 var PDU_BSSAP ass_cmd;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200633 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Harald Welteed848512018-05-24 22:27:58 +0200634 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
635 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
636 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200637 if (osmux_enabled) {
638 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla, osmux_cid));
639 } else {
640 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
641 }
Harald Welteed848512018-05-24 22:27:58 +0200642 } else {
643 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200644 if (osmux_enabled) {
645 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit, osmux_cid));
646 } else {
647 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
648 }
Harald Welteed848512018-05-24 22:27:58 +0200649 }
650 return ass_cmd;
651}
652
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +0100653function f_gen_handover_req() return PDU_BSSAP {
654 var PDU_BSSAP ho_req;
655 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
656 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
657 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
658 ho_req := valueof(ts_BSSMAP_HandoverRequest(omit, tla));
659 } else {
660 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
661 ho_req := valueof(ts_BSSMAP_HandoverRequest(cic, omit));
662 }
663 return ho_req;
664}
665
Harald Welteed848512018-05-24 22:27:58 +0200666/* generate an assignment complete template for either AoIP or SCCPlite */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200667function f_gen_exp_compl(boolean expect_osmux := false) return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +0200668 var template PDU_BSSAP exp_compl;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200669 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Harald Welteed848512018-05-24 22:27:58 +0200670 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200671 if (expect_osmux) {
672 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, osmux_cid);
673 } else {
674 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, omit);
675 }
Harald Welteed848512018-05-24 22:27:58 +0200676 } else {
677 /* CIC is optional "*" as the MSC allocated it */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200678 if (expect_osmux) {
679 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit, osmux_cid);
680 } else {
681 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
682 }
Harald Welteed848512018-05-24 22:27:58 +0200683 }
684 return exp_compl;
685}
686
Harald Welte235ebf12017-12-15 14:18:16 +0100687/* Run everything required up to sending a caller-specified assignment command and expect response */
688function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
689runs on test_CT {
690 var BSSAP_N_CONNECT_ind rx_c_ind;
691 var RSL_Message rx_rsl;
692 var DchanTuple dt;
693
Harald Welte89d42e82017-12-17 16:42:41 +0100694 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +0100695
696 dt := f_est_dchan('23'O, 23, '00000000'O);
697 /* send assignment without AoIP IEs */
698 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
699 alt {
700 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
701 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
702 setverdict(pass);
703 } else {
704 setverdict(fail, fail_text);
705 }
706 }
707 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
708 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
709 setverdict(pass);
710 } else {
711 setverdict(fail, fail_text);
712 }
713 }
714 [] BSSAP.receive { repeat; }
715 }
716}
717testcase TC_assignment_csd() runs on test_CT {
718 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +0200719 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +0100720 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
721 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
722 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
723}
724
725testcase TC_assignment_ctm() 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_ChannelTypeCTM);
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 Speech+CTM");
731}
732
Harald Welte4003d112017-12-09 22:35:39 +0100733type record DchanTuple {
734 integer sccp_conn_id,
735 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +0100736}
737
Harald Welted6939652017-12-13 21:02:46 +0100738/* Send CHAN RQD and wait for allocation; acknowledge it */
739private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
740runs on test_CT return RslChannelNr {
741 var RSL_Message rx_rsl;
742 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
743 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
744 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
745 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
Daniel Willmannf4ac4ce2018-08-02 14:06:30 +0200746 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Harald Welted6939652017-12-13 21:02:46 +0100747 return chan_nr;
748}
749
Harald Welte4003d112017-12-09 22:35:39 +0100750/* helper function to establish a dedicated channel via BTS and MSC */
751function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
752runs on test_CT return DchanTuple {
753 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +0100754 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100755
Harald Welte4003d112017-12-09 22:35:39 +0100756 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +0100757 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +0100758
759 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
760
761 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
762 dt.sccp_conn_id := rx_c_ind.connectionId;
763 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
764
765 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100766}
767
Harald Welte641fcbe2018-06-14 10:58:35 +0200768/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
769private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
770 var RSL_Message rx_rsl;
771 /* expect BSC to disable the channel */
772 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
773 /* respond with CHAN REL ACK */
774 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
775
776 /* expect Clear Complete from BSC */
777 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
778
779 /* MSC disconnects as instructed. */
780 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
781}
782
Harald Welte4003d112017-12-09 22:35:39 +0100783/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
784testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100785 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100786 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +0100787
Harald Welte89d42e82017-12-17 16:42:41 +0100788 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +0100789
Harald Welte4003d112017-12-09 22:35:39 +0100790 dt := f_est_dchan('23'O, 23, '00010203040506'O);
791
792 /* simulate RLL REL IND */
793 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
794
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100795 /* expect Clear Request on MSC side */
796 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
797
798 /* Instruct BSC to clear channel */
799 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
800 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
801
Harald Welte4003d112017-12-09 22:35:39 +0100802 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200803 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +0100804
805 /* wait for SCCP emulation to do its job */
806 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +0100807
808 setverdict(pass);
809}
810
811/* Test behavior of channel release after CONN FAIL IND from BTS */
812testcase TC_chan_rel_conn_fail() runs on test_CT {
813 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100814 var DchanTuple dt;
815
Harald Welte89d42e82017-12-17 16:42:41 +0100816 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100817
818 dt := f_est_dchan('23'O, 23, '00010203040506'O);
819
820 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +0100821 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 +0100822 /* TODO: different cause values? */
823
Harald Welte4003d112017-12-09 22:35:39 +0100824 /* expect Clear Request from BSC */
825 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
826
827 /* Instruct BSC to clear channel */
828 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
829 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
830
Harald Welte6ff76ea2018-01-28 13:08:01 +0100831 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +0200832 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +0100833
834 /* wait for SCCP emulation to do its job */
835 f_sleep(1.0);
836
837 setverdict(pass);
838}
839
Harald Welte99f3ca02018-06-14 13:40:29 +0200840/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
841/* See also https://www.osmocom.org/issues/3182 */
842testcase TC_early_conn_fail() runs on test_CT {
843 var RSL_Message rx_rsl;
844 var DchanTuple dt;
845
846 f_init(1);
847
848 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
849 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_octstring(1), 23);
850
851 /* BTS->BSC: simulate CONN FAIL IND */
852 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
853
854 /* BTS->BSC: Expect RF channel release from BSC on Abis */
855 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
856
857 /* BTS<-BSC: respond with CHAN REL ACK */
858 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
859
860 setverdict(pass);
861}
862
863/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
864/* See also https://www.osmocom.org/issues/3182 */
865testcase TC_late_conn_fail() runs on test_CT {
866 var RSL_Message rx_rsl;
867 var DchanTuple dt;
868
869 f_init(1);
870
871 dt := f_est_dchan('23'O, 23, '00010203040506'O);
872
873 /* BSC<-MSC: Instruct BSC to clear connection */
874 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
875
876 /* BTS->BSC: expect BSC to deactivate SACCH */
877 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
878
879 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
880 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
881
882 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
883 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
884 /* BTS->BSC: respond with CHAN REL ACK */
885 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
886
887 /* BSC->MSC: expect Clear Complete from BSC */
888 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
889
890 /* BSC<-MSC: MSC disconnects as requested. */
891 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
892
893 setverdict(pass);
894}
895
Neels Hofmeyrf44ccd12018-11-05 19:15:23 +0100896function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr,
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100897 boolean expect_deact_sacch := true,
898 boolean expect_rr_chan_rel := true,
899 boolean expect_rll_rel_req := true,
Harald Welte99787102019-02-04 10:41:36 +0100900 boolean handle_rll_rel := true,
901 boolean is_csfb := false
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100902 ) runs on test_CT {
Harald Welte91d54a52018-01-28 15:35:07 +0100903
904 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100905 var boolean got_deact_sacch := false;
906 var boolean got_rr_chan_rel := false;
907 var boolean got_rll_rel_req := false;
908 log("f_expect_chan_rel() expecting: expect_deact_sacch=", expect_deact_sacch, " expect_rr_chan_rel=", expect_rr_chan_rel,
909 " expect_rll_rel_req=", expect_rll_rel_req);
Harald Welte91d54a52018-01-28 15:35:07 +0100910 alt {
Harald Welte91d54a52018-01-28 15:35:07 +0100911 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
912 tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100913 got_deact_sacch := true;
Harald Welte91d54a52018-01-28 15:35:07 +0100914 repeat;
915 }
Harald Welte99787102019-02-04 10:41:36 +0100916 [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))) {
917 got_rr_chan_rel := true;
918 repeat;
919 }
920 [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 +0100921 got_rr_chan_rel := true;
Neels Hofmeyr211169d2018-11-07 00:37:29 +0100922 repeat;
923 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100924 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
Harald Welte91d54a52018-01-28 15:35:07 +0100925 tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100926 got_rll_rel_req := true;
Harald Welte91d54a52018-01-28 15:35:07 +0100927 /* FIXME: Why are we getting this for LinkID SACCH? */
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100928 if (handle_rll_rel) {
929 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
930 }
Harald Welte91d54a52018-01-28 15:35:07 +0100931 repeat;
932 }
Harald Welte91d54a52018-01-28 15:35:07 +0100933 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
934 tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
935 /* respond with CHAN REL ACK */
936 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
937 }
938 /* ignore any user data */
939 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_MsgTypeR(?))) {
940 repeat;
941 }
942 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100943
944 log("f_expect_chan_rel() summary: got_deact_sacch=", got_deact_sacch, " got_rr_chan_rel=", got_rr_chan_rel,
945 " got_rll_rel_req=", got_rll_rel_req);
946
947 if (expect_deact_sacch != got_deact_sacch) {
948 setverdict(fail, "f_expect_chan_rel(): expect_deact_sacch=", expect_deact_sacch, " got_deact_sacch=", got_deact_sacch);
949 }
950 if (expect_rr_chan_rel != got_rr_chan_rel) {
951 setverdict(fail, "f_expect_chan_rel(): expect_rr_chan_rel=", expect_rr_chan_rel, " got_rr_chan_rel=", got_rr_chan_rel);
952 }
953 if (expect_rll_rel_req != got_rll_rel_req) {
954 setverdict(fail, "f_expect_chan_rel(): expect_rll_rel_req=", expect_rll_rel_req, " got_rll_rel_req=", got_rll_rel_req);
955 }
Harald Welte91d54a52018-01-28 15:35:07 +0100956}
957
Harald Welte4003d112017-12-09 22:35:39 +0100958/* Test behavior of channel release after hard Clear Command from MSC */
959testcase TC_chan_rel_hard_clear() runs on test_CT {
960 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +0100961 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +0100962
Harald Welte89d42e82017-12-17 16:42:41 +0100963 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +0100964
965 dt := f_est_dchan('23'O, 23, '00010203040506'O);
966
967 /* Instruct BSC to clear channel */
968 var BssmapCause cause := 0;
969 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
970
971 /* expect Clear Complete from BSC on A */
972 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
973 /* release the SCCP connection */
974 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
975 }
976
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100977 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte4003d112017-12-09 22:35:39 +0100978 setverdict(pass);
979}
980
Harald Welte99787102019-02-04 10:41:36 +0100981/* Test behavior of channel release after Clear Command with CSFB indicator from MSC */
982testcase TC_chan_rel_hard_clear_csfb() runs on test_CT {
983 var BSSAP_N_DATA_ind rx_di;
984 var DchanTuple dt;
985
986 f_init(1);
987
988 dt := f_est_dchan('23'O, 23, '00010203040506'O);
989
990 /* Instruct BSC to clear channel */
991 var BssmapCause cause := 0;
992 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
993
994 /* expect Clear Complete from BSC on A */
995 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
996 /* release the SCCP connection */
997 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
998 }
999
1000 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, is_csfb := true);
1001 setverdict(pass);
1002}
1003
Harald Welted8c36cd2017-12-09 23:05:31 +01001004/* Test behavior of channel release after hard RLSD from MSC */
1005testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +01001006 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +01001007
Harald Welte89d42e82017-12-17 16:42:41 +01001008 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +01001009
1010 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1011
1012 /* release the SCCP connection */
1013 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1014
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001015 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welted8c36cd2017-12-09 23:05:31 +01001016 setverdict(pass);
1017}
1018
Harald Welte550daf92018-06-11 19:22:13 +02001019/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
1020testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
1021 var DchanTuple dt;
1022
1023 f_init(1);
1024
1025 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1026
1027 /* release the SCCP connection */
1028 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1029
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001030 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte550daf92018-06-11 19:22:13 +02001031 setverdict(pass);
1032}
1033
Harald Welte85804d42017-12-10 14:11:58 +01001034/* Test behavior of channel release after BSSMAP RESET from MSC */
1035testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +01001036 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +01001037
Harald Welte89d42e82017-12-17 16:42:41 +01001038 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +01001039
1040 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1041
1042 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
1043 IPA_RSL[0].clear;
1044
1045 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001046 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 +01001047 interleave {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001048 [] 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 +01001049 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
1050 }
1051
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001052 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Harald Welte85804d42017-12-10 14:11:58 +01001053 setverdict(pass);
1054}
1055
Harald Welte5cd20ed2017-12-13 21:03:20 +01001056/* Test behavior if RSL EST IND for non-active channel */
1057testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
1058 timer T := 2.0;
1059
Harald Welte89d42e82017-12-17 16:42:41 +01001060 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001061
1062 var octetstring l3 := '00010203040506'O;
1063 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
1064 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1065
1066 T.start;
1067 alt {
1068 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1069 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
1070 }
1071 [] BSSAP.receive {}
1072 [] IPA_RSL[0].receive {}
1073 [] T.timeout {}
1074 }
1075
1076 setverdict(pass);
1077}
1078
1079/* Test behavior if RSL EST IND for invalid SAPI */
1080testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
1081 var RslChannelNr chan_nr;
1082
Harald Welte89d42e82017-12-17 16:42:41 +01001083 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001084
1085 chan_nr := f_chreq_act_ack()
1086
1087 var octetstring l3 := '00010203040506'O;
1088 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
1089
1090 timer T := 2.0;
1091 T.start;
1092 alt {
1093 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1094 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
1095 }
1096 [] BSSAP.receive { repeat; }
1097 [] IPA_RSL[0].receive { repeat; }
1098 [] T.timeout {}
1099 }
1100
1101 setverdict(pass);
1102}
1103
1104/* Test behavior if RSL EST IND for invalid SAPI */
1105testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
1106 timer T := 2.0;
1107
Harald Welte89d42e82017-12-17 16:42:41 +01001108 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001109
1110 var RslChannelNr chan_nr := f_chreq_act_ack();
1111
1112 var octetstring l3 := '00010203040506'O;
1113 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
1114
1115 T.start;
1116 alt {
1117 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1118 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
1119 }
1120 [] BSSAP.receive { repeat; }
1121 [] IPA_RSL[0].receive { repeat; }
1122 [] T.timeout {}
1123 }
1124
1125 setverdict(pass);
1126}
1127
1128/* Test behavior if RSL EST IND for invalid SACCH */
1129testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
1130 timer T := 2.0;
1131
Harald Welte89d42e82017-12-17 16:42:41 +01001132 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001133
1134 var RslChannelNr chan_nr := f_chreq_act_ack();
1135
1136 var octetstring l3 := '00010203040506'O;
1137 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
1138
1139 T.start;
1140 alt {
1141 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1142 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
1143 }
1144 [] BSSAP.receive { repeat; }
1145 [] IPA_RSL[0].receive { repeat; }
1146 [] T.timeout {}
1147 }
1148
1149 setverdict(pass);
1150}
1151
1152
1153
Harald Welte4003d112017-12-09 22:35:39 +01001154
1155testcase TC_ctrl_msc_connection_status() runs on test_CT {
1156 var charstring ctrl_resp;
1157
Harald Welte89d42e82017-12-17 16:42:41 +01001158 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001159
1160 /* See https://osmocom.org/issues/2729 */
1161 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
1162 setverdict(pass);
1163}
1164
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001165testcase TC_ctrl_msc0_connection_status() runs on test_CT {
1166 var charstring ctrl_resp;
1167
1168 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01001169
1170 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
1171 setverdict(pass);
1172}
1173
Harald Welte4003d112017-12-09 22:35:39 +01001174testcase TC_ctrl() runs on test_CT {
1175 var charstring ctrl_resp;
1176
Harald Welte89d42e82017-12-17 16:42:41 +01001177 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001178
1179 /* all below values must match the osmo-bsc.cfg config file used */
1180
Harald Welte6a129692018-03-17 17:30:14 +01001181 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
1182 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Harald Welte44bdaa52017-12-17 17:01:47 +01001183 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "3");
Harald Welte4003d112017-12-09 22:35:39 +01001184
1185 var integer bts_nr := 0;
1186 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
1187 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
1188 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
1189 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
1190 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
1191 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
1192 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
1193
1194 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
1195 f_sleep(2.0);
1196 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
1197 setverdict(fail, "oml-uptime not incrementing as expected");
1198 }
1199 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
1200
1201 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
1202
1203 setverdict(pass);
Harald Welte96c94412017-12-09 03:12:45 +01001204}
1205
Harald Welte6f521d82017-12-11 19:52:02 +01001206function f_bssap_tx_ud(template PDU_BSSAP bssap) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +01001207 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap.sccp_addr_peer, g_bssap.sccp_addr_own, bssap));
Harald Welte6f521d82017-12-11 19:52:02 +01001208}
1209
1210
1211/***********************************************************************
1212 * Paging Testing
1213 ***********************************************************************/
1214
1215type record Cell_Identity {
1216 GsmMcc mcc,
1217 GsmMnc mnc,
1218 GsmLac lac,
1219 GsmCellId ci
1220};
Harald Welte24135bd2018-03-17 19:27:53 +01001221private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01001222private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01001223
Harald Welte5d1a2202017-12-13 19:51:29 +01001224type set of integer BtsIdList;
1225
1226private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
1227 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
1228 if (bts_id == bts_ids[j]) {
1229 return true;
1230 }
1231 }
1232 return false;
1233}
Harald Welte6f521d82017-12-11 19:52:02 +01001234
1235/* core paging test helper function; used by most paging test cases */
1236private function f_pageing_helper(hexstring imsi,
1237 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01001238 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01001239 template RSL_ChanNeeded rsl_chneed := omit,
1240 template OCT4 tmsi := omit) runs on test_CT
1241{
1242 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
1243 var MobileIdentity mi;
1244 var template octetstring id_enc; /* FIXME */
1245 var RSL_Message rx_rsl;
1246 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01001247 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01001248
1249 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01001250
1251 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01001252 for (i := 0; i < NUM_BTS; i := i + 1) {
1253 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01001254 }
Harald Welte6f521d82017-12-11 19:52:02 +01001255
1256 if (isvalue(rsl_chneed)) {
1257 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
1258 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
1259 } else {
1260 bssmap_chneed := omit;
1261 }
1262
1263 f_bssap_tx_ud(ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed));
1264
1265/* FIXME: Disabled due to bugs in both GSM_RR_Types and MobileL3_CommonIE_Types IMSI encoder
1266 if (isvalue(tmsi)) {
1267 mi := valueof(t_Osmo_MI_TMSI(oct2int(valueof(tmsi))));
1268 } else {
1269 mi := valueof(ts_Osmo_MI_IMSI(imsi));
1270 }
1271 id_enc := enc_MobileIdentity(mi);
1272*/
1273 id_enc := ?;
Harald Welte5d1a2202017-12-13 19:51:29 +01001274 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
1275 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(id_enc));
1276 /* check channel type, paging group */
1277 if (rx_rsl.ies[1].body.paging_group != paging_group) {
1278 setverdict(fail, "Paging for wrong paging group");
1279 }
1280 if (ispresent(rsl_chneed) and
1281 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
1282 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
1283 }
Harald Welte6f521d82017-12-11 19:52:02 +01001284 }
Harald Welte2fccd982018-01-31 15:48:19 +01001285 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01001286 /* do a quick check on all not-included BTSs if they received paging */
1287 for (i := 0; i < NUM_BTS; i := i + 1) {
1288 timer T := 0.1;
1289 if (f_bts_in_list(i, bts_ids)) {
1290 continue;
1291 }
1292 T.start;
1293 alt {
1294 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(id_enc))) {
1295 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
1296 }
1297 [] IPA_RSL[i].receive { repeat; }
1298 [] T.timeout { }
1299 }
Harald Welte6f521d82017-12-11 19:52:02 +01001300 }
1301
1302 setverdict(pass);
1303}
1304
Harald Welte5d1a2202017-12-13 19:51:29 +01001305const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01001306const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01001307const BtsIdList c_BtsId_LAC1 := { 0, 1 };
1308const BtsIdList c_BtsId_LAC2 := { 2 };
1309
Harald Welte6f521d82017-12-11 19:52:02 +01001310/* PAGING by IMSI + TMSI */
1311testcase TC_paging_imsi_nochan() runs on test_CT {
1312 var BSSMAP_FIELD_CellIdentificationList cid_list;
1313 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01001314 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001315 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001316}
1317
1318/* PAGING by IMSI + TMSI */
1319testcase TC_paging_tmsi_nochan() runs on test_CT {
1320 var BSSMAP_FIELD_CellIdentificationList cid_list;
1321 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001322 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001323 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001324}
1325
1326/* Paging with different "channel needed' values */
1327testcase TC_paging_tmsi_any() runs on test_CT {
1328 var BSSMAP_FIELD_CellIdentificationList cid_list;
1329 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001330 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001331 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001332}
1333testcase TC_paging_tmsi_sdcch() runs on test_CT {
1334 var BSSMAP_FIELD_CellIdentificationList cid_list;
1335 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001336 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001337 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001338}
1339testcase TC_paging_tmsi_tch_f() runs on test_CT {
1340 var BSSMAP_FIELD_CellIdentificationList cid_list;
1341 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001342 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001343 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001344}
1345testcase TC_paging_tmsi_tch_hf() runs on test_CT {
1346 var BSSMAP_FIELD_CellIdentificationList cid_list;
1347 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001348 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001349 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001350}
1351
1352/* Paging by CGI */
1353testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
1354 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1355 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001356 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001357 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001358}
1359
1360/* Paging by LAC+CI */
1361testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
1362 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1363 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001364 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001365 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001366}
1367
1368/* Paging by CI */
1369testcase TC_paging_imsi_nochan_ci() runs on test_CT {
1370 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1371 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001372 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01001373 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001374}
1375
1376/* Paging by LAI */
1377testcase TC_paging_imsi_nochan_lai() runs on test_CT {
1378 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1379 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001380 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001381 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001382}
1383
1384/* Paging by LAC */
1385testcase TC_paging_imsi_nochan_lac() runs on test_CT {
1386 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1387 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01001388 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001389 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001390}
1391
1392/* Paging by "all in BSS" */
1393testcase TC_paging_imsi_nochan_all() runs on test_CT {
1394 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1395 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01001396 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001397 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01001398}
1399
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001400/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001401testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
1402 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1403 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 +01001404 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001405 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001406}
Harald Welte6f521d82017-12-11 19:52:02 +01001407
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001408/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001409testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
1410 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1411 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001412 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001413 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001414}
1415
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001416/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01001417testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
1418 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1419 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01001420 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001421 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001422}
1423
Harald Welte6f521d82017-12-11 19:52:02 +01001424/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01001425testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
1426 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1427 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
1428 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001429 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001430}
1431
1432/* Paging on empty list: Verify none of them page */
1433testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
1434 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1435 cid_list := { cIl_LAC := { } };
1436 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01001437 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01001438}
1439
Stefan Sperling049a86e2018-03-20 15:51:00 +01001440/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
1441testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
1442 var template BSSMAP_FIELD_CellIdentificationList cid_list;
1443 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
1444 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
1445 f_shutdown_helper();
1446}
1447
Harald Welte6f521d82017-12-11 19:52:02 +01001448/* Verify paging retransmission interval + count */
1449/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01001450/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01001451
Harald Weltee65d40e2017-12-13 00:09:06 +01001452/* Verify PCH load */
1453testcase TC_paging_imsi_load() runs on test_CT {
1454 var BSSMAP_FIELD_CellIdentificationList cid_list;
1455 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01001456 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01001457 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001458 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01001459
1460 /* tell BSC there is no paging space anymore */
1461 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01001462 f_sleep(0.2);
1463 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01001464
1465 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
1466 * there would be 8 retransmissions during 4 seconds */
1467 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01001468 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01001469 alt {
1470 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1471 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02001472 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01001473 }
Harald Welte2caa1062018-03-17 18:19:05 +01001474 [] T_retrans.timeout {
1475 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
1476 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
1477 T_retrans.start;
1478 repeat;
1479 }
Harald Weltee65d40e2017-12-13 00:09:06 +01001480 [] T.timeout {
1481 setverdict(pass);
1482 }
1483 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001484
1485 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01001486}
1487
Harald Welte235ebf12017-12-15 14:18:16 +01001488/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01001489testcase TC_paging_counter() runs on test_CT {
1490 var BSSMAP_FIELD_CellIdentificationList cid_list;
1491 timer T := 4.0;
1492 var integer i;
1493 var integer paging_attempted_bsc;
1494 var integer paging_attempted_bts[NUM_BTS];
1495 var integer paging_expired_bts[NUM_BTS];
1496 cid_list := valueof(ts_BSSMAP_CIL_noCell);
1497
1498 f_init();
1499
1500 /* read counters before paging */
1501 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
1502 for (i := 0; i < NUM_BTS; i := i+1) {
1503 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
1504 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
1505 }
1506
1507 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
1508
1509 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
1510 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
1511 for (i := 0; i < NUM_BTS; i := i+1) {
1512 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
1513 paging_attempted_bts[i]+1);
1514 }
1515
1516 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
1517 f_sleep(12.0);
1518 for (i := 0; i < NUM_BTS; i := i+1) {
1519 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
1520 paging_expired_bts[i]+1);
1521 }
Harald Welte1ff69992017-12-14 12:31:17 +01001522
Philipp Maier282ca4b2018-02-27 17:17:00 +01001523 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01001524}
1525
1526
Harald Welte10985002017-12-12 09:29:15 +01001527/* Verify paging stops after A-RESET */
1528testcase TC_paging_imsi_a_reset() runs on test_CT {
1529 var BSSMAP_FIELD_CellIdentificationList cid_list;
1530 timer T := 3.0;
1531 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01001532 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01001533
1534 /* Perform a BSSMAP Reset and wait for ACK */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001535 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 +01001536 alt {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001537 [] 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 +01001538 [] BSSAP.receive { repeat; }
1539 }
1540
Daniel Willmanncbef3982018-07-30 09:22:40 +02001541 /* Wait to avoid a possible race condition if a paging message is
1542 * received right before the reset ACK. */
1543 f_sleep(0.2);
1544
Harald Welte10985002017-12-12 09:29:15 +01001545 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01001546 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
1547 IPA_RSL[i].clear;
1548 }
Harald Welte10985002017-12-12 09:29:15 +01001549
1550 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
1551 T.start;
1552 alt {
1553 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1554 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001555 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01001556 }
Harald Welte5d1a2202017-12-13 19:51:29 +01001557 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1558 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001559 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001560 }
1561 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, tr_RSL_PAGING_CMD(?))) {
1562 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02001563 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01001564 }
Harald Welte10985002017-12-12 09:29:15 +01001565 [] T.timeout {
1566 setverdict(pass);
1567 }
1568 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01001569
1570 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01001571}
Harald Welteae026692017-12-09 01:03:01 +01001572
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001573/* Verify how we handle unsolicited Paging Response, for instance because we
1574 * receive a Paging Response after T3113 expired (and subscriber information was
1575 * dropped). See OS#3680.
1576 */
1577testcase TC_paging_resp_unsol() runs on test_CT {
1578
1579 f_init(1);
1580
1581 var BSSAP_N_CONNECT_ind rx_c_ind;
1582 var DchanTuple dt;
1583 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
1584
1585 /* Send CHAN RQD and wait for allocation; acknowledge it */
1586 dt.rsl_chan_nr := f_chreq_act_ack();
1587
1588 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
1589 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
1590
1591 /* expect BSC to disable the channel */
Pau Espin Pedrol5ee6f6c2018-12-07 12:07:43 +01001592 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01001593 setverdict(pass);
1594
1595}
1596
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001597/* Test RSL link drop causes counter increment */
1598testcase TC_rsl_drop_counter() runs on test_CT {
1599 var integer rsl_fail;
1600
Harald Welte89d42e82017-12-17 16:42:41 +01001601 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01001602
1603 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
1604
1605 bts[0].rsl.vc_IPA.stop;
1606
1607 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
1608
1609 setverdict(pass);
1610}
1611
1612/* TODO: Test OML link drop causes counter increment */
1613
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001614/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
1615function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
1616 timer T := 10.0;
1617
1618 bts[0].rsl.id := "IPA-0-RSL";
1619 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
1620 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
1621 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
1622 bts[0].rsl.ccm_pars.unit_id := "0/0/0"; /* value which is unknown at BTS */
1623
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001624 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
1625
1626 f_init_mgcp("VirtMSC");
1627
1628 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
1629 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
1630 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
1631 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
1632
1633 /* wait for IPA OML link to connect and then disconnect */
1634 T.start;
1635 alt {
1636 [] IPA_RSL[0].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) {
1637 T.stop;
1638 return true;
1639 }
1640 [] IPA_RSL[0].receive { repeat }
1641 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02001642 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001643 }
1644 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01001645 return false;
1646}
1647
1648/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1649testcase TC_rsl_unknown_unit_id() runs on test_CT {
1650 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
1651 setverdict(pass);
1652 } else {
1653 setverdict(fail, "Timeout RSL waiting for connection to close");
1654 }
1655}
1656
1657
1658/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
1659testcase TC_oml_unknown_unit_id() runs on test_CT {
1660 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
1661 setverdict(pass);
1662 } else {
1663 setverdict(fail, "Timeout OML waiting for connection to close");
1664 }
1665}
1666
1667
Harald Weltec1a2fff2017-12-17 11:06:19 +01001668/***********************************************************************
Harald Welte6811d102019-04-14 22:23:14 +02001669 * "New world" test cases using RSL_Emulation + RAN_Emulation
Harald Weltec1a2fff2017-12-17 11:06:19 +01001670 ***********************************************************************/
1671
Harald Welte6811d102019-04-14 22:23:14 +02001672import from RAN_Emulation all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01001673import from RSL_Emulation all;
1674import from MSC_ConnectionHandler all;
1675
1676type function void_fn(charstring id) runs on MSC_ConnHdlr;
1677
Harald Welte336820c2018-05-31 20:34:52 +02001678/* helper function to create and connect a MSC_ConnHdlr component */
Harald Welteff579f92018-05-31 22:19:39 +02001679private function f_connect_handler(inout MSC_ConnHdlr vc_conn) runs on test_CT {
Harald Welte6811d102019-04-14 22:23:14 +02001680 connect(vc_conn:RAN, g_bssap.vc_RAN:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001681 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001682 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01001683 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01001684 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01001685 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
1686 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
1687 }
Harald Welte6811d102019-04-14 22:23:14 +02001688 connect(vc_conn:BSSAP, g_bssap.vc_RAN:CLIENT);
Daniel Willmann191e0d92018-01-17 12:44:35 +01001689 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Harald Welte336820c2018-05-31 20:34:52 +02001690}
1691
1692function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
1693runs on test_CT return MSC_ConnHdlr {
1694 var charstring id := testcasename();
1695 var MSC_ConnHdlr vc_conn;
1696 vc_conn := MSC_ConnHdlr.create(id);
1697 f_connect_handler(vc_conn);
Harald Weltea0630032018-03-20 21:09:55 +01001698 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001699 return vc_conn;
1700}
1701
Harald Weltea0630032018-03-20 21:09:55 +01001702/* first function inside ConnHdlr component; sets g_pars + starts function */
1703private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
1704runs on MSC_ConnHdlr {
1705 if (isvalue(pars)) {
1706 g_pars := valueof(pars);
1707 }
1708 fn.apply(id);
1709}
1710
Harald Welte3c86ea02018-05-10 22:28:05 +02001711/* Establish signalling channel (non-assignment case) followed by cipher mode */
1712private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001713 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1714 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02001715 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02001716 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
1717 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
1718 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
1719 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02001720
Philipp Maier23000732018-05-18 11:25:37 +02001721 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02001722}
1723testcase TC_ciph_mode_a5_0() runs on test_CT {
1724 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001725 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001726 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
1727
1728 f_init(1, true);
1729 f_sleep(1.0);
1730 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1731 vc_conn.done;
1732}
1733testcase TC_ciph_mode_a5_1() runs on test_CT {
1734 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001735 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001736 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
1737
1738 f_init(1, true);
1739 f_sleep(1.0);
1740 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1741 vc_conn.done;
1742}
1743testcase TC_ciph_mode_a5_3() runs on test_CT {
1744 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001745 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02001746 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
1747
1748 f_init(1, true);
1749 f_sleep(1.0);
1750 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
1751 vc_conn.done;
1752}
1753
1754
1755/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02001756private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02001757 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1758 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01001759
Harald Welte552620d2017-12-16 23:21:36 +01001760 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1761 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01001762
Harald Weltea0630032018-03-20 21:09:55 +01001763 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01001764}
Harald Welte552620d2017-12-16 23:21:36 +01001765testcase TC_assignment_fr_a5_0() runs on test_CT {
1766 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001767 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001768 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01001769
Harald Welte89d42e82017-12-17 16:42:41 +01001770 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001771 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001772 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01001773 vc_conn.done;
1774}
Harald Welte552620d2017-12-16 23:21:36 +01001775testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01001776 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001777 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001778 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001779
Harald Welte89d42e82017-12-17 16:42:41 +01001780 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001781 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02001782 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
1783 vc_conn.done;
1784}
1785testcase TC_assignment_fr_a5_3() runs on test_CT {
1786 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02001787 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02001788 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001789
Harald Welte651fcdc2018-05-10 20:23:16 +02001790 f_init(1, true);
1791 f_sleep(1.0);
1792 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01001793 vc_conn.done;
1794}
1795
Harald Welte552620d2017-12-16 23:21:36 +01001796/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
1797private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001798 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01001799 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001800 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001801 const OCT8 kc := '0001020304050607'O;
1802
1803 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001804 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
1805
Harald Weltea0630032018-03-20 21:09:55 +01001806 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01001807}
Harald Welte552620d2017-12-16 23:21:36 +01001808testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
1809 var MSC_ConnHdlr vc_conn;
1810
Harald Welte89d42e82017-12-17 16:42:41 +01001811 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001812 f_sleep(1.0);
1813
Harald Welte8863fa12018-05-10 20:15:27 +02001814 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01001815 vc_conn.done;
1816}
1817
Harald Welte552620d2017-12-16 23:21:36 +01001818private function f_tc_assignment_fr_a5_4(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001819 g_pars := f_gen_test_hdlr_pars();
Harald Welteed848512018-05-24 22:27:58 +02001820 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
1821 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01001822 const OCT8 kc := '0001020304050607'O;
1823 const OCT16 kc128 := kc & kc;
1824
1825 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
1826 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Weltea0630032018-03-20 21:09:55 +01001827 f_establish_fully(ass_cmd, exp_compl);
Harald Welte38b2a102017-12-23 02:42:58 +01001828 f_cipher_mode('10'O, kc, kc128, true);
Harald Welte552620d2017-12-16 23:21:36 +01001829 /* TODO: expect GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED cause value */
Harald Welte552620d2017-12-16 23:21:36 +01001830}
Harald Welte552620d2017-12-16 23:21:36 +01001831testcase TC_assignment_fr_a5_4() runs on test_CT {
1832 var MSC_ConnHdlr vc_conn;
1833
Harald Welte89d42e82017-12-17 16:42:41 +01001834 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01001835 f_sleep(1.0);
1836
Harald Welte8863fa12018-05-10 20:15:27 +02001837 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_4));
Harald Welte552620d2017-12-16 23:21:36 +01001838 vc_conn.done;
1839}
1840
1841
Harald Welte4532e0a2017-12-23 02:05:44 +01001842private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02001843 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01001844 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02001845 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01001846 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Harald Weltea0630032018-03-20 21:09:55 +01001847 f_establish_fully(ass_cmd, exp_compl);
Harald Welte4532e0a2017-12-23 02:05:44 +01001848}
1849
1850testcase TC_assignment_sign() runs on test_CT {
1851 var MSC_ConnHdlr vc_conn;
1852
1853 f_init(1, true);
1854 f_sleep(1.0);
1855
Harald Welte8863fa12018-05-10 20:15:27 +02001856 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01001857 vc_conn.done;
1858}
1859
Harald Welte60aa5762018-03-21 19:33:13 +01001860/***********************************************************************
1861 * Codec (list) testing
1862 ***********************************************************************/
1863
1864/* check if the given rsl_mode is compatible with the a_elem */
1865private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
1866return boolean {
1867 select (a_elem.codecType) {
1868 case (GSM_FR) {
1869 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
1870 return true;
1871 }
1872 }
1873 case (GSM_HR) {
1874 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
1875 return true;
1876 }
1877 }
1878 case (GSM_EFR) {
1879 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
1880 return true;
1881 }
1882 }
1883 case (FR_AMR) {
1884 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
1885 return true;
1886 }
1887 }
1888 case (HR_AMR) {
1889 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
1890 return true;
1891 }
1892 }
1893 case else { }
1894 }
1895 return false;
1896}
1897
1898/* check if the given rsl_mode is compatible with the a_list */
1899private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
1900return boolean {
1901 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
1902 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
1903 return true;
1904 }
1905 }
1906 return false;
1907}
1908
1909/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02001910function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01001911return BSSMAP_IE_ChannelType {
1912 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
1913 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
1914 select (a_elem.codecType) {
1915 case (GSM_FR) {
1916 ret.channelRateAndType := ChRate_TCHF;
1917 ret.speechId_DataIndicator := Spdi_TCHF_FR;
1918 }
1919 case (GSM_HR) {
1920 ret.channelRateAndType := ChRate_TCHH;
1921 ret.speechId_DataIndicator := Spdi_TCHH_HR;
1922 }
1923 case (GSM_EFR) {
1924 ret.channelRateAndType := ChRate_TCHF;
1925 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
1926 }
1927 case (FR_AMR) {
1928 ret.channelRateAndType := ChRate_TCHF;
1929 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
1930 }
1931 case (HR_AMR) {
1932 ret.channelRateAndType := ChRate_TCHH;
1933 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
1934 }
1935 case else {
1936 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02001937 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01001938 }
1939 }
1940 return ret;
1941}
1942
Harald Weltea63b9102018-03-22 20:36:16 +01001943private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
1944return template RSL_IE_Body {
1945 var template RSL_IE_Body mode_ie := {
1946 chan_mode := {
1947 len := ?,
1948 reserved := ?,
1949 dtx_d := ?,
1950 dtx_u := ?,
1951 spd_ind := RSL_SPDI_SPEECH,
1952 ch_rate_type := -,
1953 coding_alg_rate := -
1954 }
1955 }
1956
1957 select (a_elem.codecType) {
1958 case (GSM_FR) {
1959 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1960 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1961 }
1962 case (GSM_HR) {
1963 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1964 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
1965 }
1966 case (GSM_EFR) {
1967 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1968 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
1969 }
1970 case (FR_AMR) {
1971 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
1972 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1973 }
1974 case (HR_AMR) {
1975 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
1976 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
1977 }
1978 }
1979 return mode_ie;
1980}
1981
Harald Welte60aa5762018-03-21 19:33:13 +01001982type record CodecListTest {
1983 BSSMAP_IE_SpeechCodecList codec_list,
1984 charstring id
1985}
1986type record of CodecListTest CodecListTests
1987
1988private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001989 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
1990 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
Harald Welte60aa5762018-03-21 19:33:13 +01001991
1992 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Harald Welte79f3f542018-05-25 20:02:37 +02001993 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
1994 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
1995 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
1996 g_pars.ass_codec_list.codecElements[0];
Philipp Maierd0e64b02019-03-13 14:15:23 +01001997 if (isvalue(g_pars.expect_mr_s0_s7)) {
1998 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
1999 g_pars.expect_mr_s0_s7;
2000 }
Harald Welte79f3f542018-05-25 20:02:37 +02002001 }
Harald Welte60aa5762018-03-21 19:33:13 +01002002 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
2003 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01002004 log("expecting ASS COMPL like this: ", exp_compl);
2005
2006 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01002007
2008 /* Verify that the RSL-side activation actually matches our expectations */
2009 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
2010
2011 var RSL_IE_Body mode_ie;
2012 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
2013 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02002014 mtc.stop;
Harald Weltea63b9102018-03-22 20:36:16 +01002015 }
2016 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
2017 if (not match(mode_ie, t_mode_ie)) {
2018 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
2019 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002020
2021 var RSL_IE_Body mr_conf;
2022 if (g_pars.expect_mr_conf_ie != omit) {
2023 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
2024 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
Daniel Willmannafce8662018-07-06 23:11:32 +02002025 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002026 }
2027 log("found RSL MR CONFIG IE: ", mr_conf);
2028
2029 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
2030 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
2031 g_pars.expect_mr_conf_ie);
2032 }
2033 } else {
2034 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
2035 log("found RSL MR CONFIG IE: ", mr_conf);
2036 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
Daniel Willmannafce8662018-07-06 23:11:32 +02002037 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002038 }
2039 }
Harald Welte60aa5762018-03-21 19:33:13 +01002040}
2041
Philipp Maierd0e64b02019-03-13 14:15:23 +01002042private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
2043
2044 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2045 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2046
2047 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
2048 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
2049 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
2050 }
2051 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
2052 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
2053 log("expecting ASS FAIL like this: ", exp_fail);
2054
2055 f_establish_fully(ass_cmd, exp_fail);
2056}
2057
Harald Welte60aa5762018-03-21 19:33:13 +01002058testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002059 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002060 var MSC_ConnHdlr vc_conn;
2061
2062 f_init(1, true);
2063 f_sleep(1.0);
2064
2065 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002066 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002067 vc_conn.done;
2068}
2069
2070testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002071 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002072 var MSC_ConnHdlr vc_conn;
2073
2074 f_init(1, true);
2075 f_sleep(1.0);
2076
2077 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002078 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002079 vc_conn.done;
2080}
2081
2082testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002083 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002084 var MSC_ConnHdlr vc_conn;
2085
2086 f_init(1, true);
2087 f_sleep(1.0);
2088
2089 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02002090 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002091 vc_conn.done;
2092}
2093
Philipp Maierd0e64b02019-03-13 14:15:23 +01002094/* Allow 5,90k only (current default config) */
2095private function f_allow_amr_rate_5_90k() runs on test_CT {
2096 f_vty_enter_cfg_msc(BSCVTY, 0);
2097 f_vty_transceive(BSCVTY, "amr-config 12_2k forbidden");
2098 f_vty_transceive(BSCVTY, "amr-config 10_2k forbidden");
2099 f_vty_transceive(BSCVTY, "amr-config 7_95k forbidden");
2100 f_vty_transceive(BSCVTY, "amr-config 7_40k forbidden");
2101 f_vty_transceive(BSCVTY, "amr-config 6_70k forbidden");
2102 f_vty_transceive(BSCVTY, "amr-config 5_90k allowed");
2103 f_vty_transceive(BSCVTY, "amr-config 5_15k forbidden");
2104 f_vty_transceive(BSCVTY, "amr-config 4_75k forbidden");
2105 f_vty_transceive(BSCVTY, "exit");
2106 f_vty_transceive(BSCVTY, "exit");
2107}
2108
2109/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
2110 * ("Config-NB-Code = 1") */
2111private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
2112 f_vty_enter_cfg_msc(BSCVTY, 0);
2113 f_vty_transceive(BSCVTY, "amr-config 12_2k allowed");
2114 f_vty_transceive(BSCVTY, "amr-config 10_2k forbidden");
2115 f_vty_transceive(BSCVTY, "amr-config 7_95k forbidden");
2116 f_vty_transceive(BSCVTY, "amr-config 7_40k allowed");
2117 f_vty_transceive(BSCVTY, "amr-config 6_70k forbidden");
2118 f_vty_transceive(BSCVTY, "amr-config 5_90k allowed");
2119 f_vty_transceive(BSCVTY, "amr-config 5_15k forbidden");
2120 f_vty_transceive(BSCVTY, "amr-config 4_75k allowed");
2121 f_vty_transceive(BSCVTY, "exit");
2122 f_vty_transceive(BSCVTY, "exit");
2123}
2124
Harald Welte60aa5762018-03-21 19:33:13 +01002125testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002126 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002127 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02002128
2129 /* Note: This setups the codec configuration. The parameter payload in
2130 * mr_conf must be consistant with the parameter codecElements in pars
2131 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002132 var RSL_IE_Body mr_conf := {
2133 other := {
2134 len := 2,
2135 payload := '2804'O
2136 }
2137 };
Harald Welte60aa5762018-03-21 19:33:13 +01002138
Philipp Maier7695a0d2018-09-27 17:52:14 +02002139 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Philipp Maier806f8f12019-03-12 12:13:41 +01002140 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02002141 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
2142 pars.expect_mr_conf_ie := mr_conf;
2143
Harald Welte60aa5762018-03-21 19:33:13 +01002144 f_init(1, true);
2145 f_sleep(1.0);
2146
Harald Welte8863fa12018-05-10 20:15:27 +02002147 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002148 vc_conn.done;
2149}
2150
2151testcase TC_assignment_codec_amr_h() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02002152 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01002153 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02002154
2155 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02002156 var RSL_IE_Body mr_conf := {
2157 other := {
2158 len := 2,
2159 payload := '2804'O
2160 }
2161 };
Harald Welte60aa5762018-03-21 19:33:13 +01002162
Philipp Maier7695a0d2018-09-27 17:52:14 +02002163 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Philipp Maier806f8f12019-03-12 12:13:41 +01002164 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02002165 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2166 pars.expect_mr_conf_ie := mr_conf;
2167
Harald Welte60aa5762018-03-21 19:33:13 +01002168 f_init(1, true);
2169 f_sleep(1.0);
2170
Harald Welte8863fa12018-05-10 20:15:27 +02002171 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01002172 vc_conn.done;
2173}
2174
Philipp Maierd0e64b02019-03-13 14:15:23 +01002175function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0)
2176runs on test_CT {
2177
2178 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2179 var MSC_ConnHdlr vc_conn;
2180
2181 /* See note above */
2182 var RSL_IE_Body mr_conf := {
2183 other := {
2184 len := lengthof(mrconf),
2185 payload := mrconf
2186 }
2187 };
2188
2189 if (fr) {
2190 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
2191 } else {
2192 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2193 }
2194 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
2195 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2196 pars.expect_mr_conf_ie := mr_conf;
2197 pars.expect_mr_s0_s7 := exp_s8_s0;
2198
2199 f_init(1, true);
2200 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
2201 f_sleep(1.0);
2202
2203 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
2204 vc_conn.done;
2205 f_allow_amr_rate_5_90k();
2206}
2207
2208function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
2209runs on test_CT {
2210
2211 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2212 var MSC_ConnHdlr vc_conn;
2213
2214 if (fr) {
2215 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
2216 } else {
2217 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2218 }
2219 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
2220 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2221
2222 f_init(1, true);
2223 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
2224 f_sleep(1.0);
2225
2226 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
2227 vc_conn.done;
2228 f_allow_amr_rate_5_90k();
2229}
2230
2231
2232/* Set S1, we expect an AMR multirate configuration IE with all four rates
2233 * set. */
2234testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
2235 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
2236}
2237
2238/* Set S1, we expect an AMR multirate configuration IE with the lower three
2239 * rates set. */
2240testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
2241 f_TC_assignment_codec_amr(false, '2815208820'O, '00000010'B, '00000010'B);
2242}
2243
2244/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
2245 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
2246testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
2247 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'B, '00000010'B);
2248}
2249
2250/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
2251 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
2252testcase TC_assignment_codec_amr_h_S124() runs on test_CT {
2253 f_TC_assignment_codec_amr(false, '2815208820'O, '00010110'B, '00000010'B);
2254}
2255
2256/* The following block of tests selects more and more rates until all four
2257 * possible rates are in the active set (full rate) */
2258testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
2259 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'B);
2260}
2261
2262testcase TC_assignment_codec_amr_f_S02() runs on test_CT {
2263 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'B);
2264}
2265
2266testcase TC_assignment_codec_amr_f_S024() runs on test_CT {
2267 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'B);
2268}
2269
2270testcase TC_assignment_codec_amr_f_S0247() runs on test_CT {
2271 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
2272}
2273
2274/* The following block of tests selects more and more rates until all three
2275 * possible rates are in the active set (half rate) */
2276testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
2277 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'B);
2278}
2279
2280testcase TC_assignment_codec_amr_h_S02() runs on test_CT {
2281 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
2282}
2283
2284testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
2285 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
2286}
2287
2288/* The following block tests what happens when the MSC does offer rate
2289 * configurations that are not supported by the BSC. Normally such situations
2290 * should not happen because the MSC gets informed by the BSC in advance via
2291 * the L3 COMPLETE message which rates are applicable. The MSC should not try
2292 * to offer rates that are not applicable anyway. */
2293
2294testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
2295 /* Try to include 12,2k in into the active set even though the channel
2296 * is half rate only. The BSC is expected to remove the 12,0k */
2297 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'B);
2298}
2299
2300testcase TC_assignment_codec_amr_f_S01234567() runs on test_CT {
2301 /* See what happens when all rates are selected at once. Since then
2302 * Also S1 is selected, this setting will be prefered and we should
2303 * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
2304 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
2305}
2306
2307testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
2308 /* Same as above, but with S1 missing, the MSC is then expected to
2309 * select the currently supported rates, which are also 12.2k, 7,40k,
2310 * 5,90k, and 4,75k, into the active set. */
2311 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'B);
2312}
2313
2314testcase TC_assignment_codec_amr_f_zero() runs on test_CT {
2315 /* Try to select no rates at all */
2316 f_TC_assignment_codec_amr_fail(true, '00000000'B);
2317}
2318
2319testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
2320 /* Try to select only unsupported rates */
2321 f_TC_assignment_codec_amr_fail(true, '01101000'B);
2322}
2323
2324testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
2325 /* Try to select 12,2k for half rate */
2326 f_TC_assignment_codec_amr_fail(false, '10000000'B);
2327}
2328
Philipp Maierac09bfc2019-01-08 13:41:39 +01002329private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002330 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
2331 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
2332 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
2333 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002334}
2335
2336private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002337 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
2338 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002339}
2340
2341private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01002342 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
2343 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
2344 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
2345 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
2346 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
2347 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01002348}
2349
2350/* Allow HR only */
2351private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
2352 g_pars := f_gen_test_hdlr_pars();
2353 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2354 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2355 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2356 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
2357 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
2358 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
2359 f_establish_fully(ass_cmd, exp_compl);
2360}
2361
2362/* Allow FR only */
2363private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
2364 g_pars := f_gen_test_hdlr_pars();
2365 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2366 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2367 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2368 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
2369 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
2370 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2371 f_establish_fully(ass_cmd, exp_compl);
2372}
2373
2374/* Allow HR only (expect assignment failure) */
2375private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
2376 g_pars := f_gen_test_hdlr_pars();
2377 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2378 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2379 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2380 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
2381 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
2382 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
2383 f_establish_fully(ass_cmd, exp_fail);
2384}
2385
2386/* Allow FR only (expect assignment failure) */
2387private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(charstring id) runs on MSC_ConnHdlr {
2388 g_pars := f_gen_test_hdlr_pars();
2389 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2390 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
2391 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2392 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
2393 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
2394 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2395 f_establish_fully(ass_cmd, exp_fail);
2396}
2397
2398/* Allow FR and HR, but prefer FR */
2399private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2400 g_pars := f_gen_test_hdlr_pars();
2401 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2402 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2403 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2404 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2405 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2406 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2407 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2408 f_establish_fully(ass_cmd, exp_compl);
2409}
2410
2411/* Allow FR and HR, but prefer HR */
2412private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2413 g_pars := f_gen_test_hdlr_pars();
2414 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2415 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2416 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2417 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2418 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2419 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2420 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2421 f_establish_fully(ass_cmd, exp_compl);
2422}
2423
2424/* Allow FR and HR, but prefer FR */
2425private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2426 g_pars := f_gen_test_hdlr_pars();
2427 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2428 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2429 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2430 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2431 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2432 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2433 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2434 f_establish_fully(ass_cmd, exp_compl);
2435}
2436
2437/* Allow FR and HR, but prefer HR */
2438private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(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 := '0B'O; /* Prefer HR */
2444 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2445 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2446 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2447 f_establish_fully(ass_cmd, exp_compl);
2448}
2449
2450/* Request a HR channel while all FR channels are exhausted, this is expected
2451 * to work without conflicts */
2452testcase TC_assignment_codec_fr_exhausted_req_hr() runs on test_CT {
2453 var MSC_ConnHdlr vc_conn;
2454 f_init(1, true);
2455 f_sleep(1.0);
2456 f_enable_all_tch();
2457 f_disable_all_tch_f();
2458 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr));
2459 vc_conn.done;
2460 f_enable_all_tch();
2461 setverdict(pass);
2462}
2463
2464/* Request a FR channel while all FR channels are exhausted, this is expected
2465 * to fail. */
2466testcase TC_assignment_codec_fr_exhausted_req_fr() runs on test_CT {
2467 var MSC_ConnHdlr vc_conn;
2468 f_init(1, true);
2469 f_sleep(1.0);
2470 f_enable_all_tch();
2471 f_disable_all_tch_f();
2472 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr_fail));
2473 vc_conn.done;
2474 f_enable_all_tch();
2475 setverdict(pass);
2476}
2477
2478/* Request a FR (prefered) or alternatively a HR channel while all FR channels
2479 * are exhausted, this is expected to be resolved by selecting a HR channel. */
2480testcase TC_assignment_codec_fr_exhausted_req_fr_hr() runs on test_CT {
2481 var MSC_ConnHdlr vc_conn;
2482 f_init(1, true);
2483 f_sleep(1.0);
2484 f_enable_all_tch();
2485 f_disable_all_tch_f();
2486 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
2487 vc_conn.done;
2488 f_enable_all_tch();
2489 setverdict(pass);
2490}
2491
2492/* Request a HR (prefered) or alternatively a FR channel while all FR channels
2493 * are exhausted, this is expected to work without conflicts. */
2494testcase TC_assignment_codec_fr_exhausted_req_hr_fr() runs on test_CT {
2495 var MSC_ConnHdlr vc_conn;
2496 f_init(1, true);
2497 f_sleep(1.0);
2498 f_enable_all_tch();
2499 f_disable_all_tch_f();
2500 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_hr_fr));
2501 vc_conn.done;
2502 f_enable_all_tch();
2503 setverdict(pass);
2504}
2505
2506/* Request a FR channel while all HR channels are exhausted, this is expected
2507 * to work without conflicts */
2508testcase TC_assignment_codec_hr_exhausted_req_fr() runs on test_CT {
2509 var MSC_ConnHdlr vc_conn;
2510 f_init(1, true);
2511 f_sleep(1.0);
2512 f_enable_all_tch();
2513 f_disable_all_tch_h();
2514 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr));
2515 vc_conn.done;
2516 f_enable_all_tch();
2517 setverdict(pass);
2518}
2519
2520/* Request a HR channel while all HR channels are exhausted, this is expected
2521 * to fail. */
2522testcase TC_assignment_codec_hr_exhausted_req_hr() runs on test_CT {
2523 var MSC_ConnHdlr vc_conn;
2524 f_init(1, true);
2525 f_sleep(1.0);
2526 f_enable_all_tch();
2527 f_disable_all_tch_h();
2528 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr_fail));
2529 vc_conn.done;
2530 f_enable_all_tch();
2531 setverdict(pass);
2532}
2533
2534/* Request a HR (prefered) or alternatively a FR channel while all HR channels
2535 * are exhausted, this is expected to be resolved by selecting a FR channel. */
2536testcase TC_assignment_codec_hr_exhausted_req_hr_fr() runs on test_CT {
2537 var MSC_ConnHdlr vc_conn;
2538 f_init(1, true);
2539 f_sleep(1.0);
2540 f_enable_all_tch();
2541 f_disable_all_tch_h();
2542 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_hr_fr));
2543 vc_conn.done;
2544 f_enable_all_tch();
2545 setverdict(pass);
2546}
2547
2548/* Request a FR (prefered) or alternatively a HR channel while all HR channels
2549 * are exhausted, this is expected to work without conflicts. */
2550testcase TC_assignment_codec_hr_exhausted_req_fr_hr() runs on test_CT {
2551 var MSC_ConnHdlr vc_conn;
2552 f_init(1, true);
2553 f_sleep(1.0);
2554 f_enable_all_tch();
2555 f_disable_all_tch_h();
2556 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_fr_hr));
2557 vc_conn.done;
2558 f_enable_all_tch();
2559 setverdict(pass);
2560}
2561
2562/* Allow FR and HR, but prefer HR */
2563private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
2564 g_pars := f_gen_test_hdlr_pars();
2565 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2566 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2567 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2568 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
2569 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
2570 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
2571 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
2572 f_establish_fully(ass_cmd, exp_compl);
2573}
2574
2575/* Allow FR and HR, but prefer FR */
2576private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
2577 g_pars := f_gen_test_hdlr_pars();
2578 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2579 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2580 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2581 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
2582 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
2583 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
2584 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
2585 f_establish_fully(ass_cmd, exp_compl);
2586}
2587
2588/* Request a HR (prefered) or alternatively a FR channel, it is expected that
2589 * HR, which is the prefered type, is selected. */
2590testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
2591 var MSC_ConnHdlr vc_conn;
2592 f_init(1, true);
2593 f_sleep(1.0);
2594 f_enable_all_tch();
2595 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
2596 vc_conn.done;
2597 setverdict(pass);
2598}
2599
2600/* Request a FR (prefered) or alternatively a HR channel, it is expected that
2601 * FR, which is the prefered type, is selected. */
2602testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
2603 var MSC_ConnHdlr vc_conn;
2604 f_init(1, true);
2605 f_sleep(1.0);
2606 f_enable_all_tch();
2607 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
2608 vc_conn.done;
2609 setverdict(pass);
2610}
2611
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02002612testcase TC_assignment_osmux() runs on test_CT {
2613 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2614 var MSC_ConnHdlr vc_conn;
2615
2616 /* See note above */
2617 var RSL_IE_Body mr_conf := {
2618 other := {
2619 len := 2,
2620 payload := '2804'O
2621 }
2622 };
2623
2624 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
2625 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
2626 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
2627 pars.expect_mr_conf_ie := mr_conf;
2628 pars.use_osmux := true;
2629
2630 f_init(1, true, true);
2631 f_sleep(1.0);
2632
2633 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
2634 vc_conn.done;
2635}
2636
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02002637/* test the procedure of the MSC requesting a Classmark Update:
2638 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
2639 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01002640private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002641 g_pars := f_gen_test_hdlr_pars();
2642
Harald Weltea0630032018-03-20 21:09:55 +01002643 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01002644 /* we should now have a COMPL_L3 at the MSC */
2645 BSSAP.receive(tr_BSSMAP_ComplL3);
2646
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02002647 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
2648 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
2649
Harald Welte898113b2018-01-31 18:32:21 +01002650 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
2651 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
2652 setverdict(pass);
2653}
2654testcase TC_classmark() runs on test_CT {
2655 var MSC_ConnHdlr vc_conn;
2656 f_init(1, true);
2657 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002658 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01002659 vc_conn.done;
2660}
2661
Harald Weltee3bd6582018-01-31 22:51:25 +01002662private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002663 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01002664 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01002665 /* we should now have a COMPL_L3 at the MSC */
2666 BSSAP.receive(tr_BSSMAP_ComplL3);
2667
Harald Weltee3bd6582018-01-31 22:51:25 +01002668 /* send the single message we want to send */
2669 f_rsl_send_l3(l3);
2670}
2671
2672private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
2673 timer T := sec;
2674 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01002675 T.start;
2676 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01002677 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
2678 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02002679 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01002680 }
2681 [] T.timeout {
2682 setverdict(pass);
2683 }
2684 }
2685}
2686
Harald Weltee3bd6582018-01-31 22:51:25 +01002687/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2688private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
2689 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
2690 f_bssap_expect_nothing();
2691}
Harald Welte898113b2018-01-31 18:32:21 +01002692testcase TC_unsol_ass_fail() runs on test_CT {
2693 var MSC_ConnHdlr vc_conn;
2694 f_init(1, true);
2695 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002696 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01002697 vc_conn.done;
2698}
Harald Welte552620d2017-12-16 23:21:36 +01002699
Harald Welteea99a002018-01-31 20:46:43 +01002700
2701/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
2702private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002703 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
2704 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01002705}
2706testcase TC_unsol_ass_compl() runs on test_CT {
2707 var MSC_ConnHdlr vc_conn;
2708 f_init(1, true);
2709 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002710 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01002711 vc_conn.done;
2712}
2713
2714
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002715/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
2716private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01002717 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
2718 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002719}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002720testcase TC_unsol_ho_fail() runs on test_CT {
2721 var MSC_ConnHdlr vc_conn;
2722 f_init(1, true);
2723 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002724 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01002725 vc_conn.done;
2726}
2727
2728
Harald Weltee3bd6582018-01-31 22:51:25 +01002729/* short message from MS should be ignored */
2730private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002731 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01002732 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01002733 /* we should now have a COMPL_L3 at the MSC */
2734 BSSAP.receive(tr_BSSMAP_ComplL3);
2735
2736 /* send short message */
2737 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
2738 f_bssap_expect_nothing();
2739}
2740testcase TC_err_82_short_msg() runs on test_CT {
2741 var MSC_ConnHdlr vc_conn;
2742 f_init(1, true);
2743 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002744 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01002745 vc_conn.done;
2746}
2747
2748
Harald Weltee9e02e42018-01-31 23:36:25 +01002749/* 24.008 8.4 Unknown message must trigger RR STATUS */
2750private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
2751 f_est_single_l3(ts_RRM_UL_REL('00'O));
2752 timer T := 3.0
2753 alt {
2754 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
2755 setverdict(pass);
2756 }
2757 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01002758 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01002759 }
2760}
2761testcase TC_err_84_unknown_msg() runs on test_CT {
2762 var MSC_ConnHdlr vc_conn;
2763 f_init(1, true);
2764 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002765 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01002766 vc_conn.done;
2767}
2768
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002769/***********************************************************************
2770 * Handover
2771 ***********************************************************************/
2772
Harald Welte94e0c342018-04-07 11:33:23 +02002773/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
2774private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
2775runs on test_CT {
2776 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2777 " timeslot "&int2str(ts_nr)&" ";
2778 f_vty_transceive(BSCVTY, cmd & suffix);
2779}
2780
Harald Welte261af4b2018-02-12 21:20:39 +01002781/* execute a "bts <0-255> trx <0-255> timeslot <0-7> sub-slot <0-7>" command on given Dchan */
2782private function f_vty_ss_action(charstring suffix, integer bts_nr, integer trx_nr, RslChannelNr chan_nr)
2783runs on MSC_ConnHdlr {
2784 /* FIXME: resolve those from component-global state */
2785 var integer ts_nr := chan_nr.tn;
2786 var integer ss_nr;
2787 if (ischosen(chan_nr.u.ch0)) {
2788 ss_nr := 0;
2789 } else if (ischosen(chan_nr.u.lm)) {
2790 ss_nr := chan_nr.u.lm.sub_chan;
2791 } else if (ischosen(chan_nr.u.sdcch4)) {
2792 ss_nr := chan_nr.u.sdcch4.sub_chan;
2793 } else if (ischosen(chan_nr.u.sdcch8)) {
2794 ss_nr := chan_nr.u.sdcch8.sub_chan;
2795 } else {
2796 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02002797 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01002798 }
2799
2800 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
2801 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
2802 f_vty_transceive(BSCVTY, cmd & suffix);
2803}
2804
2805private function f_vty_handover(integer bts_nr, integer trx_nr, RslChannelNr chan_nr,
2806 integer new_bts_nr)
2807runs on MSC_ConnHdlr {
2808 f_vty_ss_action("handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
2809}
2810
2811/* intra-BSC hand-over between BTS0 and BTS1 */
2812private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002813 g_pars := f_gen_test_hdlr_pars();
Harald Welteed848512018-05-24 22:27:58 +02002814 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2815 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01002816 const OCT8 kc := '0001020304050607'O;
2817
2818 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2819 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2820
Harald Weltea0630032018-03-20 21:09:55 +01002821 f_establish_fully(ass_cmd, exp_compl);
Harald Welte261af4b2018-02-12 21:20:39 +01002822
2823 var HandoverState hs := {
2824 rr_ho_cmpl_seen := false,
2825 handover_done := false,
2826 old_chan_nr := -
2827 };
2828 /* issue hand-over command on VTY */
2829 f_vty_handover(0, 0, g_chan_nr, 1);
2830 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
2831 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002832
2833 /* From the MGW perspective, a handover is is characterized by
2834 * performing one MDCX operation with the MGW. So we expect to see
2835 * one more MDCX during handover. */
2836 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
2837
Harald Welte261af4b2018-02-12 21:20:39 +01002838 alt {
2839 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01002840 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002841
Philipp Maier4dae0652018-11-12 12:03:26 +01002842 /* Since this is an internal handover we expect the BSC to inform the
2843 * MSC about the event */
2844 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
2845
Philipp Maier3e2af5d2018-07-11 17:01:05 +02002846 /* Check the amount of MGCP transactions is still consistant with the
2847 * test expectation */
2848 f_check_mgcp_expectations()
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01002849 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01002850}
2851
2852testcase TC_ho_int() runs on test_CT {
2853 var MSC_ConnHdlr vc_conn;
2854 f_init(2, true);
2855 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02002856 vc_conn := f_start_handler(refers(f_tc_ho_int));
Harald Welte261af4b2018-02-12 21:20:39 +01002857 vc_conn.done;
2858}
Harald Weltee9e02e42018-01-31 23:36:25 +01002859
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002860private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02002861 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01002862
2863 var PDU_BSSAP ass_req := f_gen_ass_req();
2864 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2865 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2866 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2867 f_establish_fully(ass_req, exp_compl);
2868
2869 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2870
2871 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2872
2873 f_sleep(0.5);
2874 /* The MSC negotiates Handover Request and Handover Request Ack with
2875 * the other BSS and comes back with a BSSMAP Handover Command
2876 * containing an RR Handover Command coming from the target BSS... */
2877
2878 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
2879 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
2880 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
2881 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
2882 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
2883
2884 /* expect the Handover Command to go out on RR */
2885 var RSL_Message rsl_ho_cmd
2886 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
2887 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
2888 var RSL_IE_Body rsl_ho_cmd_l3;
2889 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
2890 log("RSL message contains no L3 Info IE, expected RR Handover Command");
2891 setverdict(fail);
2892 } else {
2893 log("Found L3 Info: ", rsl_ho_cmd_l3);
2894 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
2895 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
2896 setverdict(fail);
2897 } else {
2898 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
2899 setverdict(pass);
2900 }
2901 }
2902
2903 /* When the other BSS has reported a completed handover, this side is
2904 * torn down. */
2905
2906 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
2907 var BssmapCause cause := enum2int(cause_val);
2908 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
2909
2910 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
2911 var MgcpCommand mgcp;
2912 interleave {
2913 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
2914 [] MGCP.receive(tr_DLCX()) -> value mgcp {
2915 log("Got first DLCX: ", mgcp);
2916 }
2917 [] MGCP.receive(tr_DLCX()) -> value mgcp {
2918 log("Got second DLCX: ", mgcp);
2919 }
2920 }
2921 setverdict(pass);
2922 f_sleep(1.0);
2923}
2924testcase TC_ho_out_of_this_bsc() runs on test_CT {
2925 var MSC_ConnHdlr vc_conn;
2926
2927 f_init(1, true);
2928 f_sleep(1.0);
2929
2930 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
2931 vc_conn.done;
2932}
2933
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002934/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
2935 * simply never sends a BSSMAP Handover Command. */
2936private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01002937 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002938
2939 var PDU_BSSAP ass_req := f_gen_ass_req();
2940 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2941 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2942 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2943 f_establish_fully(ass_req, exp_compl);
2944
2945 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2946
2947 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2948
2949 /* osmo-bsc should time out 10 seconds after the handover started.
2950 * Let's give it a bit extra. */
2951 f_sleep(15.0);
2952
2953 /* The old lchan and conn should still be active. See that arbitrary L3
2954 * is still going through. */
2955 var octetstring l3 := '0123456789'O;
2956 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
2957 var template PDU_BSSAP exp_data := {
2958 discriminator := '1'B,
2959 spare := '0000000'B,
2960 dlci := '00'O,
2961 lengthIndicator := 5,
2962 pdu := {
2963 dtap := l3
2964 }
2965 };
2966 BSSAP.receive(exp_data);
2967 setverdict(pass);
2968 f_sleep(1.0);
2969}
2970testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
2971 var MSC_ConnHdlr vc_conn;
2972
2973 f_init(1, true);
2974 f_sleep(1.0);
2975
2976 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
2977 vc_conn.done;
2978}
2979
2980/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
2981 * RR Handover Failure. */
2982private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01002983 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02002984
2985 var PDU_BSSAP ass_req := f_gen_ass_req();
2986 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2987 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2988 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2989 f_establish_fully(ass_req, exp_compl);
2990
2991 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
2992
2993 BSSAP.receive(tr_BSSMAP_HandoverRequired);
2994
2995 f_sleep(0.5);
2996 /* The MSC negotiates Handover Request and Handover Request Ack with
2997 * the other BSS and comes back with a BSSMAP Handover Command
2998 * containing an RR Handover Command coming from the target BSS... */
2999
3000 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
3001 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
3002 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
3003 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
3004 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
3005
3006 /* expect the Handover Command to go out on RR */
3007 var RSL_Message rsl_ho_cmd
3008 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
3009 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
3010 var RSL_IE_Body rsl_ho_cmd_l3;
3011 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
3012 log("RSL message contains no L3 Info IE, expected RR Handover Command");
3013 setverdict(fail);
3014 } else {
3015 log("Found L3 Info: ", rsl_ho_cmd_l3);
3016 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
3017 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
3018 setverdict(fail);
3019 } else {
3020 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
3021 setverdict(pass);
3022 }
3023 }
3024
3025 f_sleep(0.2);
3026 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
3027
3028 /* Should tell the MSC about the failure */
3029 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3030
3031 f_sleep(1.0);
3032
3033 /* The old lchan and conn should still be active. See that arbitrary L3
3034 * is still going through. */
3035 var octetstring l3 := '0123456789'O;
3036 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
3037 var template PDU_BSSAP exp_data := {
3038 discriminator := '1'B,
3039 spare := '0000000'B,
3040 dlci := '00'O,
3041 lengthIndicator := 5,
3042 pdu := {
3043 dtap := l3
3044 }
3045 };
3046 BSSAP.receive(exp_data);
3047 setverdict(pass);
3048 f_sleep(1.0);
3049
3050 setverdict(pass);
3051 f_sleep(1.0);
3052}
3053testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
3054 var MSC_ConnHdlr vc_conn;
3055
3056 f_init(1, true);
3057 f_sleep(1.0);
3058
3059 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
3060 vc_conn.done;
3061}
3062
3063/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
3064 * RR Handover Failure. */
3065private function f_tc_ho_out_fail_no_ho_detect(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01003066 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003067
3068 var PDU_BSSAP ass_req := f_gen_ass_req();
3069 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3070 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3071 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3072 f_establish_fully(ass_req, exp_compl);
3073
3074 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
3075
3076 BSSAP.receive(tr_BSSMAP_HandoverRequired);
3077
3078 f_sleep(0.5);
3079 /* The MSC negotiates Handover Request and Handover Request Ack with
3080 * the other BSS and comes back with a BSSMAP Handover Command
3081 * containing an RR Handover Command coming from the target BSS... */
3082
3083 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
3084 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
3085 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
3086 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
3087 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
3088
3089 /* expect the Handover Command to go out on RR */
3090 var RSL_Message rsl_ho_cmd
3091 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
3092 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
3093 var RSL_IE_Body rsl_ho_cmd_l3;
3094 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
3095 log("RSL message contains no L3 Info IE, expected RR Handover Command");
3096 setverdict(fail);
3097 } else {
3098 log("Found L3 Info: ", rsl_ho_cmd_l3);
3099 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
3100 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
3101 setverdict(fail);
3102 } else {
3103 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
3104 setverdict(pass);
3105 }
3106 }
3107
3108 /* The MS never shows up on the remote BSS. Eventually the BSC times
3109 * out and we run into 3GPP TS 48.008 3.1.5.3.3 "Abnormal Conditions":
3110 * RR should be released and Clear Request should go to the MSC. */
3111
3112 var MgcpCommand mgcp;
3113 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01003114 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
3115 log("Got Deact SACCH");
3116 }
Harald Welte924b6ea2019-02-04 01:05:34 +01003117 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01003118 log("Got RR Release");
3119 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02003120 [] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
3121 log("Got RF Chan Rel");
3122 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
3123 }
3124 [] BSSAP.receive(tr_BSSMAP_ClearRequest) {
3125 log("Got BSSMAP Clear Request");
3126 }
3127 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3128 log("Got first DLCX: ", mgcp);
3129 }
3130 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3131 log("Got second DLCX: ", mgcp);
3132 }
3133 }
3134
3135 setverdict(pass);
3136 f_sleep(1.0);
3137}
3138testcase TC_ho_out_fail_no_ho_detect() runs on test_CT {
3139 var MSC_ConnHdlr vc_conn;
3140
3141 f_init(1, true);
3142 f_sleep(1.0);
3143
3144 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_ho_detect));
3145 vc_conn.done;
3146}
3147
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003148private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
3149 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
3150 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
3151 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
3152 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
3153 * before we get started. */
3154 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3155 f_rslem_register(0, new_chan_nr);
3156 g_chan_nr := new_chan_nr;
3157 f_sleep(1.0);
3158
3159 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3160 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3161 activate(as_Media());
3162
3163 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3164 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003165 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003166
3167 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3168
3169 var PDU_BSSAP rx_bssap;
3170 var octetstring ho_command_str;
3171
3172 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3173
3174 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3175 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3176 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3177 log("L3 Info in HO Request Ack is ", ho_command);
3178
3179 var GsmArfcn arfcn;
3180 var RslChannelNr actual_new_chan_nr;
3181 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3182 actual_new_chan_nr, arfcn);
3183
3184 if (actual_new_chan_nr != new_chan_nr) {
3185 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3186 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3187 setverdict(fail);
3188 return;
3189 }
3190 log("Handover Command chan_nr is", actual_new_chan_nr);
3191
3192 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3193 * tells the MS to handover to the new lchan. Here comes the new MS on
3194 * the new lchan with a Handover RACH: */
3195
3196 /* send handover detect */
3197
3198 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
3199
3200 BSSAP.receive(tr_BSSMAP_HandoverDetect);
3201
3202 /* send handover complete over the new channel */
3203
3204 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
3205 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
3206 enc_PDU_ML3_MS_NW(l3_tx)));
3207
3208 BSSAP.receive(tr_BSSMAP_HandoverComplete);
3209 setverdict(pass);
3210}
3211testcase TC_ho_into_this_bsc() runs on test_CT {
3212 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003213 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003214
3215 f_init(1, true);
3216 f_sleep(1.0);
3217
3218 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3219 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3220
3221 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
3222 vc_conn.done;
3223}
3224
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003225private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
3226 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3227 f_rslem_register(0, new_chan_nr);
3228 g_chan_nr := new_chan_nr;
3229 f_sleep(1.0);
3230
3231 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3232 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3233 activate(as_Media());
3234
3235 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3236 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003237 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003238
3239 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3240
3241 var PDU_BSSAP rx_bssap;
3242 var octetstring ho_command_str;
3243
3244 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3245
3246 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3247 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3248 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3249 log("L3 Info in HO Request Ack is ", ho_command);
3250
3251 var GsmArfcn arfcn;
3252 var RslChannelNr actual_new_chan_nr;
3253 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3254 actual_new_chan_nr, arfcn);
3255
3256 if (actual_new_chan_nr != new_chan_nr) {
3257 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3258 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3259 setverdict(fail);
3260 return;
3261 }
3262 log("Handover Command chan_nr is", actual_new_chan_nr);
3263
Neels Hofmeyr61ca08d2019-05-06 23:52:22 +02003264 /* For deterministic test results, give some time for the MGW endpoint to be configured */
3265 f_sleep(1.0);
3266
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003267 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3268 * tells the MS to handover to the new lchan. In this case, the MS
3269 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
3270 * Handover Failure to the MSC. The procedure according to 3GPP TS
3271 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
3272 * BSSMAP Clear Command: */
3273
3274 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3275 var BssmapCause cause := enum2int(cause_val);
3276 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3277
3278 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3279 var MgcpCommand mgcp;
3280 interleave {
3281 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3282 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3283 log("Got first DLCX: ", mgcp);
3284 }
3285 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3286 log("Got second DLCX: ", mgcp);
3287 }
3288 }
3289 setverdict(pass);
3290 f_sleep(1.0);
3291
3292 setverdict(pass);
3293}
3294testcase TC_ho_in_fail_msc_clears() runs on test_CT {
3295 var MSC_ConnHdlr vc_conn;
3296 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3297
3298 f_init(1, true);
3299 f_sleep(1.0);
3300
3301 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3302 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3303
3304 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
3305 vc_conn.done;
3306}
3307
3308private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
3309 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
3310 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
3311 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
3312 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
3313 * before we get started. */
3314 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3315 f_rslem_register(0, new_chan_nr);
3316 g_chan_nr := new_chan_nr;
3317 f_sleep(1.0);
3318
3319 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3320 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3321 activate(as_Media());
3322
3323 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3324 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003325 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003326
3327 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3328
3329 var PDU_BSSAP rx_bssap;
3330 var octetstring ho_command_str;
3331
3332 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3333
3334 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3335 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3336 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3337 log("L3 Info in HO Request Ack is ", ho_command);
3338
3339 var GsmArfcn arfcn;
3340 var RslChannelNr actual_new_chan_nr;
3341 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3342 actual_new_chan_nr, arfcn);
3343
3344 if (actual_new_chan_nr != new_chan_nr) {
3345 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3346 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3347 setverdict(fail);
3348 return;
3349 }
3350 log("Handover Command chan_nr is", actual_new_chan_nr);
3351
3352 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3353 * tells the MS to handover to the new lchan. Here comes the new MS on
3354 * the new lchan with a Handover RACH: */
3355
3356 /* send handover detect */
3357
3358 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
3359
3360 BSSAP.receive(tr_BSSMAP_HandoverDetect);
3361
3362 /* The MSC chooses to clear the connection now, maybe we got the
3363 * Handover RACH on the new cell but the MS still signaled Handover
3364 * Failure to the old BSS? */
3365
3366 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3367 var BssmapCause cause := enum2int(cause_val);
3368 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3369
3370 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3371 var MgcpCommand mgcp;
3372 interleave {
3373 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3374 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3375 log("Got first DLCX: ", mgcp);
3376 }
3377 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3378 log("Got second DLCX: ", mgcp);
3379 }
3380 }
3381 setverdict(pass);
3382 f_sleep(1.0);
3383}
3384testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
3385 var MSC_ConnHdlr vc_conn;
3386 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3387
3388 f_init(1, true);
3389 f_sleep(1.0);
3390
3391 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3392 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3393
3394 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
3395 vc_conn.done;
3396}
3397
3398/* The new BSS's lchan times out before the MSC decides that handover failed. */
3399private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
3400 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3401 f_rslem_register(0, new_chan_nr);
3402 g_chan_nr := new_chan_nr;
3403 f_sleep(1.0);
3404
3405 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3406 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3407 activate(as_Media());
3408
3409 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3410 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003411 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003412
3413 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3414
3415 var PDU_BSSAP rx_bssap;
3416 var octetstring ho_command_str;
3417
3418 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3419
3420 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3421 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3422 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3423 log("L3 Info in HO Request Ack is ", ho_command);
3424
3425 var GsmArfcn arfcn;
3426 var RslChannelNr actual_new_chan_nr;
3427 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3428 actual_new_chan_nr, arfcn);
3429
3430 if (actual_new_chan_nr != new_chan_nr) {
3431 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3432 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3433 setverdict(fail);
3434 return;
3435 }
3436 log("Handover Command chan_nr is", actual_new_chan_nr);
3437
3438 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3439 * tells the MS to handover to the new lchan. But the MS never shows up
3440 * on the new lchan. */
3441
3442 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3443
3444 /* Did osmo-bsc also send a Clear Request? */
3445 timer T := 0.5;
3446 T.start;
3447 alt {
3448 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
3449 [] T.timeout { }
3450 }
3451
3452 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
3453 * asked for it, this is a Handover Failure after all). */
3454
3455 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
3456 var BssmapCause cause := enum2int(cause_val);
3457 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3458
3459 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3460 var MgcpCommand mgcp;
3461 interleave {
3462 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3463 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3464 log("Got first DLCX: ", mgcp);
3465 }
3466 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3467 log("Got second DLCX: ", mgcp);
3468 }
3469 }
3470 setverdict(pass);
3471 f_sleep(1.0);
3472
3473 setverdict(pass);
3474}
3475testcase TC_ho_in_fail_no_detect() runs on test_CT {
3476 var MSC_ConnHdlr vc_conn;
3477 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3478
3479 f_init(1, true);
3480 f_sleep(1.0);
3481
3482 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3483 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3484
3485 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
3486 vc_conn.done;
3487}
3488
3489/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
3490private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
3491 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
3492 f_rslem_register(0, new_chan_nr);
3493 g_chan_nr := new_chan_nr;
3494 f_sleep(1.0);
3495
3496 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
3497 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
3498 activate(as_Media());
3499
3500 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.handover.sccp_addr_bsc, g_pars.handover.sccp_addr_msc,
3501 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02003502 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01003503
3504 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
3505
3506 var PDU_BSSAP rx_bssap;
3507 var octetstring ho_command_str;
3508
3509 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
3510
3511 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
3512 log("Received L3 Info in HO Request Ack: ", ho_command_str);
3513 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
3514 log("L3 Info in HO Request Ack is ", ho_command);
3515
3516 var GsmArfcn arfcn;
3517 var RslChannelNr actual_new_chan_nr;
3518 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
3519 actual_new_chan_nr, arfcn);
3520
3521 if (actual_new_chan_nr != new_chan_nr) {
3522 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
3523 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
3524 setverdict(fail);
3525 return;
3526 }
3527 log("Handover Command chan_nr is", actual_new_chan_nr);
3528
3529 /* Now the MSC forwards the RR Handover Command to the other BSC, which
3530 * tells the MS to handover to the new lchan. But the MS never shows up
3531 * on the new lchan. */
3532
3533 BSSAP.receive(tr_BSSMAP_HandoverFailure);
3534
3535 /* MSC plays dumb and sends no Clear Command */
3536
3537 /* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
3538 var PDU_BSSAP rx_clear_request;
3539 var MgcpCommand mgcp;
3540 interleave {
3541 [] BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
3542 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
3543 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
3544 };
3545 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
3546
3547 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3548 log("Got first DLCX: ", mgcp);
3549 }
3550 [] MGCP.receive(tr_DLCX()) -> value mgcp {
3551 log("Got second DLCX: ", mgcp);
3552 }
3553 }
3554 setverdict(pass);
3555 f_sleep(1.0);
3556}
3557testcase TC_ho_in_fail_no_detect2() runs on test_CT {
3558 var MSC_ConnHdlr vc_conn;
3559 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3560
3561 f_init(1, true);
3562 f_sleep(1.0);
3563
3564 pars.handover.sccp_addr_msc := g_bssap.sccp_addr_own;
3565 pars.handover.sccp_addr_bsc := g_bssap.sccp_addr_peer;
3566
3567 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
3568 vc_conn.done;
3569}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01003570
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003571/* OS#3041: Open and close N connections in a normal fashion, and expect no
3572 * BSSMAP Reset just because of that. */
3573testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
3574 var default d;
3575 var integer i;
3576 var DchanTuple dt;
3577
3578 f_init();
3579
3580 /* Wait for initial BSSMAP Reset to pass */
3581 f_sleep(4.0);
3582
3583 d := activate(no_bssmap_reset());
3584
3585 /* Setup up a number of connections and RLSD them again from the MSC
3586 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3587 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02003588 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003589 /* Since we're doing a lot of runs, give each one a fresh
3590 * T_guard from the top. */
3591 T_guard.start;
3592
3593 /* Setup a BSSAP connection and clear it right away. This is
3594 * the MSC telling the BSC about a planned release, it's not an
3595 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02003596 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01003597
3598 /* MSC disconnects (RLSD). */
3599 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
3600 }
3601
3602 /* In the buggy behavior, a timeout of 2 seconds happens between above
3603 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3604 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3605 f_sleep(4.0);
3606
3607 deactivate(d);
3608 f_shutdown_helper();
3609}
Harald Welte552620d2017-12-16 23:21:36 +01003610
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003611/* OS#3041: Open and close N connections in a normal fashion, and expect no
3612 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
3613 * the MSC. */
3614testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
3615 var default d;
3616 var integer i;
3617 var DchanTuple dt;
3618 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003619 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
3620 var BssmapCause cause := enum2int(cause_val);
3621
3622 f_init();
3623
3624 /* Wait for initial BSSMAP Reset to pass */
3625 f_sleep(4.0);
3626
3627 d := activate(no_bssmap_reset());
3628
3629 /* Setup up a number of connections and RLSD them again from the MSC
3630 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3631 * Let's do it some more times for good measure. */
3632 for (i := 0; i < 8; i := i+1) {
3633 /* Since we're doing a lot of runs, give each one a fresh
3634 * T_guard from the top. */
3635 T_guard.start;
3636
3637 /* Setup a BSSAP connection and clear it right away. This is
3638 * the MSC telling the BSC about a planned release, it's not an
3639 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02003640 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003641
3642 /* Instruct BSC to clear channel */
3643 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
3644
3645 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02003646 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01003647 }
3648
3649 /* In the buggy behavior, a timeout of 2 seconds happens between above
3650 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3651 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3652 f_sleep(4.0);
3653
3654 deactivate(d);
3655 f_shutdown_helper();
3656}
3657
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003658/* OS#3041: Open and close N connections in a normal fashion, and expect no
3659 * BSSMAP Reset just because of that. Close connections from the MS side with a
3660 * Release Ind on RSL. */
3661testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
3662 var default d;
3663 var integer i;
3664 var DchanTuple dt;
3665 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003666 var integer j;
3667
3668 f_init();
3669
3670 /* Wait for initial BSSMAP Reset to pass */
3671 f_sleep(4.0);
3672
3673 d := activate(no_bssmap_reset());
3674
3675 /* Setup up a number of connections and RLSD them again from the MSC
3676 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
3677 * Let's do it some more times for good measure. */
3678 for (i := 0; i < 8; i := i+1) {
3679 /* Since we're doing a lot of runs, give each one a fresh
3680 * T_guard from the top. */
3681 T_guard.start;
3682
3683 /* Setup a BSSAP connection and clear it right away. This is
3684 * the MSC telling the BSC about a planned release, it's not an
3685 * erratic loss of a connection. */
3686 dt := f_est_dchan('23'O, 23, '00010203040506'O);
3687
3688 /* simulate RLL REL IND */
3689 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
3690
3691 /* expect Clear Request on MSC side */
3692 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
3693
3694 /* Instruct BSC to clear channel */
3695 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
3696 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
3697
3698 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02003699 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01003700 }
3701
3702 /* In the buggy behavior, a timeout of 2 seconds happens between above
3703 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
3704 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
3705 f_sleep(4.0);
3706
3707 deactivate(d);
3708 f_shutdown_helper();
3709}
3710
Harald Welte94e0c342018-04-07 11:33:23 +02003711/***********************************************************************
3712 * IPA style dynamic PDCH
3713 ***********************************************************************/
3714
3715private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
3716 template (omit) RSL_Cause nack := omit)
3717runs on test_CT {
3718 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
3719 var RSL_Message rsl_unused;
3720 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3721 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
3722 /* expect the BSC to issue the related RSL command */
3723 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3724 if (istemplatekind(nack, "omit")) {
3725 /* respond with a related acknowledgement */
3726 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3727 } else {
3728 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
3729 }
3730}
3731
3732private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
3733 template (omit) RSL_Cause nack := omit)
3734runs on test_CT {
3735 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
3736 var RSL_Message rsl_unused;
3737 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3738 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
3739 /* expect the BSC to issue the related RSL command */
3740 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
3741 if (istemplatekind(nack, "omit")) {
3742 /* respond with a related acknowledgement */
3743 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
3744 } else {
3745 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
3746 }
3747}
3748
3749private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
3750runs on test_CT return charstring {
3751 var charstring cmd, resp;
3752 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01003753 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02003754}
3755
3756private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
3757 template charstring exp)
3758runs on test_CT {
3759 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
3760 if (not match(mode, exp)) {
3761 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02003762 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02003763 }
3764}
3765
3766private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
3767runs on test_CT {
3768 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
3769 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
3770 f_vty_transceive(BSCVTY, "end");
3771}
3772
3773private const charstring TCHF_MODE := "TCH/F mode";
3774private const charstring TCHH_MODE := "TCH/H mode";
3775private const charstring PDCH_MODE := "PDCH mode";
3776private const charstring NONE_MODE := "NONE mode";
3777
3778/* Test IPA PDCH activation / deactivation triggered by VTY */
3779testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
3780 var RSL_Message rsl_unused;
3781
3782 /* change Timeslot 6 before f_init() starts RSL */
3783 f_init_vty();
3784 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
3785 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3786
3787 f_init(1, false);
3788 f_sleep(1.0);
3789
3790 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
3791
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003792 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003793 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3794 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3795 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3796 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3797 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003798 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003799 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3800
3801 /* De-activate it via VTY */
3802 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3803 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003804 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003805 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3806
3807 /* re-activate it via VTY */
3808 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
3809 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003810 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003811 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3812
3813 /* and finally de-activate it again */
3814 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3815 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003816 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003817 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3818
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003819 /* clean up config */
3820 f_ts_set_chcomb(0, 0, 6, "PDCH");
3821
Harald Welte94e0c342018-04-07 11:33:23 +02003822 setverdict(pass);
3823}
3824
3825/* Test IPA PDCH activation NACK */
3826testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
3827 var RSL_Message rsl_unused;
3828
3829 /* change Timeslot 6 before f_init() starts RSL */
3830 f_init_vty();
3831 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
3832 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3833
3834 f_init(1, false);
3835 f_sleep(1.0);
3836
3837 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
3838
3839 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3840 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3841 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
3842 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
3843 f_sleep(1.0);
3844 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3845
3846 /* De-activate it via VTY */
3847 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
3848 f_sleep(1.0);
3849 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3850
3851 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
3852 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
3853 f_sleep(1.0);
3854 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
3855
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003856 /* clean up config */
3857 f_ts_set_chcomb(0, 0, 6, "PDCH");
3858
Harald Welte94e0c342018-04-07 11:33:23 +02003859 setverdict(pass);
3860}
3861
3862
3863/***********************************************************************
3864 * Osmocom style dynamic PDCH
3865 ***********************************************************************/
3866
3867private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
3868 template (omit) RSL_Cause nack := omit)
3869runs on test_CT {
3870 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
3871 var RSL_Message rsl_unused;
3872 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3873 /* FIXME: no VTY command to activate Osmocom PDCH !! */
3874 /* expect the BSC to issue the related RSL command */
3875 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
3876 if (istemplatekind(nack, "omit")) {
3877 /* respond with a related acknowledgement */
3878 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
3879 } else {
3880 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
3881 }
3882}
3883
3884private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
3885 template (omit) RSL_Cause nack := omit)
3886runs on test_CT {
3887 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
3888 var RSL_Message rsl_unused;
3889 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
3890 /* FIXME: no VTY command to activate Osmocom PDCH !! */
3891 /* expect the BSC to issue the related RSL command */
3892 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
3893 if (istemplatekind(nack, "omit")) {
3894 /* respond with a related acknowledgement */
3895 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
3896 } else {
3897 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
3898 }
3899}
3900
3901/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
3902testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
3903 var RSL_Message rsl_unused;
3904
3905 /* change Timeslot 6 before f_init() starts RSL */
3906 f_init_vty();
3907 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
3908 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3909
3910 f_init(1, false);
3911 f_sleep(1.0);
3912
3913 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
3914
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003915 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02003916 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
3917 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3918 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
3919
3920 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
3921 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003922 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 +02003923 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
3924
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003925 /* clean up config */
3926 f_ts_set_chcomb(0, 0, 6, "PDCH");
3927
Harald Welte94e0c342018-04-07 11:33:23 +02003928 setverdict(pass);
3929}
3930
3931/* Test Osmocom dyn PDCH activation NACK behavior */
3932testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
3933 var RSL_Message rsl_unused;
3934
3935 /* change Timeslot 6 before f_init() starts RSL */
3936 f_init_vty();
3937 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
3938 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
3939
3940 f_init(1, false);
3941 f_sleep(1.0);
3942
3943 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
3944
3945 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
3946 /* The BSC will activate the dynamic PDCH by default, so confirm that */
3947 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
3948
3949 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
3950 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
3951 f_sleep(1.0);
3952 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
3953
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02003954 /* clean up config */
3955 f_ts_set_chcomb(0, 0, 6, "PDCH");
3956
Harald Welte94e0c342018-04-07 11:33:23 +02003957 setverdict(pass);
3958}
3959
Stefan Sperling0796a822018-10-05 13:01:39 +02003960testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02003961 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02003962 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
3963 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
3964 }
3965}
3966
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02003967testcase TC_chopped_ipa_payload() runs on test_CT {
3968 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
3969 /* TODO: mp_bsc_ctrl_port does not work yet */};
3970 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
3971 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
3972 }
3973}
3974
3975
Harald Welte0ea2d5e2018-04-07 21:40:29 +02003976/* Dyn PDCH todo:
3977 * activate OSMO as TCH/F
3978 * activate OSMO as TCH/H
3979 * does the BSC-located PCU socket get the updated INFO?
3980 * what if no PCU is connected at the time?
3981 * is the info correct on delayed PCU (re)connect?
3982 */
Harald Welte94e0c342018-04-07 11:33:23 +02003983
Harald Welte28d943e2017-11-25 15:00:50 +01003984control {
Harald Welte898113b2018-01-31 18:32:21 +01003985 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +01003986 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01003987 execute( TC_ctrl_msc0_connection_status() );
Harald Welte96c94412017-12-09 03:12:45 +01003988 execute( TC_ctrl() );
Harald Welte898113b2018-01-31 18:32:21 +01003989
3990 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +01003991 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +01003992 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +01003993 execute( TC_chan_act_ack_noest() );
3994 execute( TC_chan_act_ack_est_ind_noreply() );
3995 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +01003996 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +01003997 execute( TC_chan_exhaustion() );
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07003998 execute( TC_chan_deact_silence() );
Harald Welte4003d112017-12-09 22:35:39 +01003999 execute( TC_chan_rel_rll_rel_ind() );
4000 execute( TC_chan_rel_conn_fail() );
4001 execute( TC_chan_rel_hard_clear() );
Harald Welte99787102019-02-04 10:41:36 +01004002 execute( TC_chan_rel_hard_clear_csfb() );
Harald Welted8c36cd2017-12-09 23:05:31 +01004003 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +02004004 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +01004005 execute( TC_chan_rel_a_reset() );
Harald Welte6f521d82017-12-11 19:52:02 +01004006
Harald Weltecfe2c962017-12-15 12:09:32 +01004007 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +01004008
4009 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +01004010 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +01004011 execute( TC_assignment_csd() );
4012 execute( TC_assignment_ctm() );
4013 execute( TC_assignment_sign() );
4014 execute( TC_assignment_fr_a5_0() );
4015 execute( TC_assignment_fr_a5_1() );
Harald Welte8f67d1d2018-05-25 20:38:42 +02004016 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
4017 execute( TC_assignment_fr_a5_1_codec_missing() );
4018 }
Harald Welte235ebf12017-12-15 14:18:16 +01004019 execute( TC_assignment_fr_a5_3() );
4020 execute( TC_assignment_fr_a5_4() );
Harald Welte3c86ea02018-05-10 22:28:05 +02004021 execute( TC_ciph_mode_a5_0() );
4022 execute( TC_ciph_mode_a5_1() );
4023 execute( TC_ciph_mode_a5_3() );
Harald Welte16a4adf2017-12-14 18:54:01 +01004024
Harald Welte60aa5762018-03-21 19:33:13 +01004025 execute( TC_assignment_codec_fr() );
4026 execute( TC_assignment_codec_hr() );
4027 execute( TC_assignment_codec_efr() );
4028 execute( TC_assignment_codec_amr_f() );
4029 execute( TC_assignment_codec_amr_h() );
Philipp Maier8a581d22019-03-26 18:32:48 +01004030
4031 if (mp_bssap_cfg.transport == BSSAP_TRANSPORT_AoIP) {
4032 execute( TC_assignment_codec_amr_f_S1() );
4033 execute( TC_assignment_codec_amr_h_S1() );
4034 execute( TC_assignment_codec_amr_f_S124() );
4035 execute( TC_assignment_codec_amr_h_S124() );
4036 execute( TC_assignment_codec_amr_f_S0() );
4037 execute( TC_assignment_codec_amr_f_S02() );
4038 execute( TC_assignment_codec_amr_f_S024() );
4039 execute( TC_assignment_codec_amr_f_S0247() );
4040 execute( TC_assignment_codec_amr_h_S0() );
4041 execute( TC_assignment_codec_amr_h_S02() );
4042 execute( TC_assignment_codec_amr_h_S024() );
4043 execute( TC_assignment_codec_amr_h_S0247() );
4044 execute( TC_assignment_codec_amr_f_S01234567() );
4045 execute( TC_assignment_codec_amr_f_S0234567() );
4046 execute( TC_assignment_codec_amr_f_zero() );
4047 execute( TC_assignment_codec_amr_f_unsupp() );
4048 execute( TC_assignment_codec_amr_h_S7() );
4049 }
Harald Welte60aa5762018-03-21 19:33:13 +01004050
Philipp Maierac09bfc2019-01-08 13:41:39 +01004051 execute( TC_assignment_codec_fr_exhausted_req_hr() );
4052 execute( TC_assignment_codec_fr_exhausted_req_fr() );
4053 execute( TC_assignment_codec_fr_exhausted_req_fr_hr() );
4054 execute( TC_assignment_codec_fr_exhausted_req_hr_fr() );
4055 execute( TC_assignment_codec_hr_exhausted_req_fr() );
4056 execute( TC_assignment_codec_hr_exhausted_req_hr() );
4057 execute( TC_assignment_codec_hr_exhausted_req_hr_fr() );
4058 execute( TC_assignment_codec_hr_exhausted_req_fr_hr() );
4059 execute( TC_assignment_codec_req_hr_fr() );
4060 execute( TC_assignment_codec_req_fr_hr() );
4061
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004062 execute( TC_assignment_osmux() );
4063
Harald Welte898113b2018-01-31 18:32:21 +01004064 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +01004065 execute( TC_rll_est_ind_inact_lchan() );
4066 execute( TC_rll_est_ind_inval_sapi1() );
4067 execute( TC_rll_est_ind_inval_sapi3() );
4068 execute( TC_rll_est_ind_inval_sacch() );
4069
Harald Welte898113b2018-01-31 18:32:21 +01004070 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +01004071 execute( TC_paging_imsi_nochan() );
4072 execute( TC_paging_tmsi_nochan() );
4073 execute( TC_paging_tmsi_any() );
4074 execute( TC_paging_tmsi_sdcch() );
4075 execute( TC_paging_tmsi_tch_f() );
4076 execute( TC_paging_tmsi_tch_hf() );
4077 execute( TC_paging_imsi_nochan_cgi() );
4078 execute( TC_paging_imsi_nochan_lac_ci() );
4079 execute( TC_paging_imsi_nochan_ci() );
4080 execute( TC_paging_imsi_nochan_lai() );
4081 execute( TC_paging_imsi_nochan_lac() );
4082 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +01004083 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
4084 execute( TC_paging_imsi_nochan_rnc() );
4085 execute( TC_paging_imsi_nochan_lac_rnc() );
4086 execute( TC_paging_imsi_nochan_lacs() );
4087 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +01004088 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +01004089 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +01004090 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +01004091 execute( TC_paging_counter() );
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01004092 execute( TC_paging_resp_unsol() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +01004093
4094 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +01004095 execute( TC_rsl_unknown_unit_id() );
4096
4097 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +01004098
4099 execute( TC_classmark() );
4100 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +01004101 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004102 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +01004103 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +01004104 execute( TC_err_84_unknown_msg() );
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004105
Harald Welte261af4b2018-02-12 21:20:39 +01004106 execute( TC_ho_int() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004107
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004108 execute( TC_ho_out_of_this_bsc() );
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004109 execute( TC_ho_out_fail_no_msc_response() );
4110 execute( TC_ho_out_fail_rr_ho_failure() );
4111 execute( TC_ho_out_fail_no_ho_detect() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004112
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004113 execute( TC_ho_into_this_bsc() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004114 execute( TC_ho_in_fail_msc_clears() );
4115 execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
4116 execute( TC_ho_in_fail_no_detect() );
4117 execute( TC_ho_in_fail_no_detect2() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01004118
4119 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01004120 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01004121 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +02004122
4123 execute( TC_dyn_pdch_ipa_act_deact() );
4124 execute( TC_dyn_pdch_ipa_act_nack() );
4125 execute( TC_dyn_pdch_osmo_act_deact() );
4126 execute( TC_dyn_pdch_osmo_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +02004127
Stefan Sperling0796a822018-10-05 13:01:39 +02004128 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02004129 execute( TC_chopped_ipa_payload() );
Stefan Sperling0796a822018-10-05 13:01:39 +02004130
Harald Welte99f3ca02018-06-14 13:40:29 +02004131 /* at bottom as they might crash OsmoBSC before OS#3182 is fixed */
4132 execute( TC_early_conn_fail() );
4133 execute( TC_late_conn_fail() );
4134
Harald Welte28d943e2017-11-25 15:00:50 +01004135}
4136
4137}