blob: 577999055acf179a9ae0c690e8b8337df7060208 [file] [log] [blame]
Harald Welte28d943e2017-11-25 15:00:50 +01001module BSC_Tests {
2
Harald Welte21b46bd2017-12-17 19:46:32 +01003/* Integration Tests for OsmoBSC
Harald Weltea0630032018-03-20 21:09:55 +01004 * (C) 2017-2018 by Harald Welte <laforge@gnumonks.org>
Harald Welte21b46bd2017-12-17 19:46:32 +01005 * All rights reserved.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
Harald Welte34b5a952019-05-27 11:54:11 +020010 * SPDX-License-Identifier: GPL-2.0-or-later
11 *
Harald Welte21b46bd2017-12-17 19:46:32 +010012 * This test suite tests OsmoBSC while emulating both multiple BTS + MS as
13 * well as the MSC. See README for more details.
14 *
15 * There are test cases that run in so-called 'handler mode' and test cases
16 * that run directly on top of the BSSAP and RSL CodecPorts. The "handler mode"
17 * tests abstract the multiplexing/demultiplexing of multiple SCCP connections
18 * and/or RSL channels and are hence suitable for higher-level test cases, while
19 * the "raw" tests directly on top of the CodecPorts are more suitable for lower-
20 * level testing.
21 */
22
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +020023friend module BSC_Tests_VAMOS;
24
Neels Hofmeyr4f118412020-06-04 15:25:10 +020025import from Misc_Helpers all;
Harald Welte4003d112017-12-09 22:35:39 +010026import from General_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010027import from Osmocom_Types all;
Harald Welteae026692017-12-09 01:03:01 +010028import from GSM_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010029import from IPL4asp_Types all;
30
Harald Welte6f521d82017-12-11 19:52:02 +010031import from BSSAP_Types all;
Harald Welte6811d102019-04-14 22:23:14 +020032import from RAN_Adapter all;
Harald Welte47cd0e32020-08-21 12:39:11 +020033import from BSSAP_LE_Adapter all;
34import from BSSAP_LE_CodecPort all;
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020035import from BSSAP_LE_Types all;
36import from BSSLAP_Types all;
Harald Welteae026692017-12-09 01:03:01 +010037import from BSSAP_CodecPort all;
38import from BSSMAP_Templates all;
Harald Welte28d943e2017-11-25 15:00:50 +010039import from IPA_Emulation all;
Stefan Sperling830dc9d2018-02-12 21:08:28 +010040import from IPA_CodecPort all;
Harald Welteae026692017-12-09 01:03:01 +010041import from IPA_Types all;
Stefan Sperling0796a822018-10-05 13:01:39 +020042import from IPA_Testing all;
Harald Welteae026692017-12-09 01:03:01 +010043import from RSL_Types all;
Harald Welte624f9632017-12-16 19:26:04 +010044import from RSL_Emulation all;
Daniel Willmann191e0d92018-01-17 12:44:35 +010045import from MGCP_Emulation all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010046import from MGCP_Templates all;
47import from MGCP_Types all;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +020048import from MGCP_CodecPort all;
Harald Welte28d943e2017-11-25 15:00:50 +010049
Harald Welte96c94412017-12-09 03:12:45 +010050import from Osmocom_CTRL_Functions all;
Harald Weltea5d2ab22017-12-09 14:21:42 +010051import from Osmocom_CTRL_Types all;
Harald Welteffe55fc2018-01-17 22:39:54 +010052import from Osmocom_CTRL_Adapter all;
Harald Welte96c94412017-12-09 03:12:45 +010053
Daniel Willmannebdecc02020-08-12 15:30:17 +020054import from StatsD_Types all;
55import from StatsD_CodecPort all;
56import from StatsD_CodecPort_CtrlFunct all;
57import from StatsD_Checker all;
58
Harald Weltebc03c762018-02-12 18:09:38 +010059import from Osmocom_VTY_Functions all;
60import from TELNETasp_PortType all;
61
Harald Welte6f521d82017-12-11 19:52:02 +010062import from MobileL3_CommonIE_Types all;
Harald Weltee3bd6582018-01-31 22:51:25 +010063import from MobileL3_Types all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010064import from MobileL3_RRM_Types all;
Harald Welte6f521d82017-12-11 19:52:02 +010065import from L3_Templates all;
66import from GSM_RR_Types all;
67
Stefan Sperlingc307e682018-06-14 15:15:46 +020068import from SCCP_Templates all;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010069import from BSSMAP_Templates all;
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020070import from BSSMAP_LE_Templates all;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010071
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010072import from SCCPasp_Types all;
73
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020074import from GSM_SystemInformation all;
75import from GSM_RestOctets all;
Neels Hofmeyrad132f22020-07-08 02:20:16 +020076import from TCCConversion_Functions all;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020077
Neels Hofmeyrbf720202021-10-02 12:58:24 +020078type record of integer integer_list;
79
Harald Welte5d1a2202017-12-13 19:51:29 +010080const integer NUM_BTS := 3;
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +020081const integer NUM_BTS_CFG := 4; /* we have 4 BTS in the osmo-bsc.cfg (for inter-BSC HO tests) but use only 3 */
Neels Hofmeyrf246a922020-05-13 02:27:10 +020082const integer NUM_MSC := 3;
Harald Welteae026692017-12-09 01:03:01 +010083const float T3101_MAX := 12.0;
Harald Welte28d943e2017-11-25 15:00:50 +010084
Harald Welte799c97b2017-12-14 17:50:30 +010085/* make sure to sync this with the osmo-bts.cfg you're using */
Philipp Maiercb6cc482018-03-26 13:08:00 +020086const integer NUM_TCHH_PER_BTS := 2;
87const integer NUM_TCHF_PER_BTS := 4;
Neels Hofmeyr74083c22020-07-29 00:43:01 +020088const integer NUM_SDCCH_PER_BTS := 3;
Harald Welte799c97b2017-12-14 17:50:30 +010089
Neels Hofmeyrbf720202021-10-02 12:58:24 +020090/* Default Training Sequence Code expected for bts[i]:
91 * BTS 0 has BSIC 10 (and no explicit timeslot training_sequence_code config), so expecting TSC = (BSIC & 7) = 2.
92 * BTS 1 has BSIC 11, TSC = (BSIC & 7) = 3.
93 * BTS 2 has BSIC 12, TSC = (BSIC & 7) = 4.
94 * BTS 2 has BSIC 12, TSC = (BSIC & 7) = 4.
95 */
96const integer_list BTS_TSC := {
97 2,
98 3,
99 4,
100 4
101}
Harald Welte4003d112017-12-09 22:35:39 +0100102
Harald Welte21b46bd2017-12-17 19:46:32 +0100103/* per-BTS state which we keep */
Harald Welte96c94412017-12-09 03:12:45 +0100104type record BTS_State {
Harald Welte21b46bd2017-12-17 19:46:32 +0100105 /* component reference to the IPA_Client component used for RSL */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100106 IPA_Client rsl
Harald Welte96c94412017-12-09 03:12:45 +0100107}
108
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200109/* Default list of counters for an 'msc' entity. */
110const CounterNameVals counternames_msc_mscpool := {
111 { "mscpool:subscr:new", 0 },
112 { "mscpool:subscr:known", 0 },
113 { "mscpool:subscr:reattach", 0 },
114 { "mscpool:subscr:attach_lost", 0 },
115 { "mscpool:subscr:paged", 0 }
116};
117
Neels Hofmeyrbf037052020-10-28 22:52:02 +0000118/* List of global mscpool counters, not related to a specific 'msc' entity. */
119const CounterNameVals counternames_bsc_mscpool := {
120 { "mscpool:subscr:no_msc", 0 }
121};
122
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000123/* Default list of counters for 'bsc' and 'bts' entities. */
124const CounterNameVals counternames_bsc_bts_handover := {
125 { "assignment:attempted", 0 },
126 { "assignment:completed", 0 },
127 { "assignment:stopped", 0 },
128 { "assignment:no_channel", 0 },
129 { "assignment:timeout", 0 },
130 { "assignment:failed", 0 },
131 { "assignment:error", 0 },
132
133 { "handover:attempted", 0 },
134 { "handover:completed", 0 },
135 { "handover:stopped", 0 },
136 { "handover:no_channel", 0 },
137 { "handover:timeout", 0 },
138 { "handover:failed", 0 },
139 { "handover:error", 0 },
140
141 { "intra_cell_ho:attempted", 0 },
142 { "intra_cell_ho:completed", 0 },
143 { "intra_cell_ho:stopped", 0 },
144 { "intra_cell_ho:no_channel", 0 },
145 { "intra_cell_ho:timeout", 0 },
146 { "intra_cell_ho:failed", 0 },
147 { "intra_cell_ho:error", 0 },
148
149 { "intra_bsc_ho:attempted", 0 },
150 { "intra_bsc_ho:completed", 0 },
151 { "intra_bsc_ho:stopped", 0 },
152 { "intra_bsc_ho:no_channel", 0 },
153 { "intra_bsc_ho:timeout", 0 },
154 { "intra_bsc_ho:failed", 0 },
155 { "intra_bsc_ho:error", 0 },
156
157 { "interbsc_ho_out:attempted", 0 },
158 { "interbsc_ho_out:completed", 0 },
159 { "interbsc_ho_out:stopped", 0 },
160 { "interbsc_ho_out:timeout", 0 },
161 { "interbsc_ho_out:failed", 0 },
162 { "interbsc_ho_out:error", 0 },
163
164 { "interbsc_ho_in:attempted", 0 },
165 { "interbsc_ho_in:completed", 0 },
166 { "interbsc_ho_in:stopped", 0 },
167 { "interbsc_ho_in:no_channel", 0 },
168 { "interbsc_ho_in:timeout", 0 },
169 { "interbsc_ho_in:failed", 0 },
170 { "interbsc_ho_in:error", 0 }
171};
172
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100173const CounterNameVals counternames_bts_handover := {
174 { "incoming_intra_bsc_ho:attempted", 0 },
175 { "incoming_intra_bsc_ho:completed", 0 },
176 { "incoming_intra_bsc_ho:stopped", 0 },
177 { "incoming_intra_bsc_ho:no_channel", 0 },
178 { "incoming_intra_bsc_ho:timeout", 0 },
179 { "incoming_intra_bsc_ho:failed", 0 },
180 { "incoming_intra_bsc_ho:error", 0 }
181};
182
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200183/* Set of all System Information received during one RSL port's startup.
184 * Note that some System Information may be sent on RSL, but lacking actual SI data, to indicate that the BTS should not
185 * broadcast that SI type. That will be reflected as 'omit' here.
186 */
187type record SystemInformationConfig {
188 SystemInformationType1 si1 optional,
189 SystemInformationType2 si2 optional,
190 SystemInformationType2bis si2bis optional,
191 SystemInformationType2ter si2ter optional,
Neels Hofmeyrad132f22020-07-08 02:20:16 +0200192 SI2quaterRestOctetsList si2quater optional,
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200193 SystemInformationType3 si3 optional,
194 SystemInformationType4 si4 optional,
Pau Espin Pedrol28652d82021-02-09 20:20:17 +0100195 SystemInformationType13 si13 optional,
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200196 SystemInformationType5 si5 optional,
197 SystemInformationType5bis si5bis optional,
198 SystemInformationType5ter si5ter optional,
199 SystemInformationType6 si6 optional
200};
201
202const SystemInformationConfig SystemInformationConfig_omit := {
203 si1 := omit,
204 si2 := omit,
205 si2bis := omit,
206 si2ter := omit,
207 si2quater := omit,
208 si3 := omit,
209 si4 := omit,
210 si13 := omit,
211 si5 := omit,
212 si5bis := omit,
213 si5ter := omit,
214 si6 := omit
215};
216
217/* tr_EUTRAN_CellDesc with defaults used in BSC_Tests.ttcn */
218template EUTRAN_CellDesc tr_EUTRAN_CellDesc_default(template (present) uint16_t e_arfcn := ?,
219 template uint3_t meas_bw := 3)
220:= tr_EUTRAN_CellDesc(e_arfcn := e_arfcn,
221 meas_bw_presence := '1'B,
222 meas_bw := meas_bw);
223
224/* tr_EUTRAN_NeighbourCells with defaults used in BSC_Tests.ttcn */
Harald Welte65e419a2020-08-21 12:38:33 +0200225template EUTRAN_NeighbourCells tr_EUTRAN_NeighbourCells_default(template (present) EUTRAN_CellDescs cell_desc_list := { tr_EUTRAN_CellDesc_default },
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200226 template uint3_t prio := 3,
227 template (present) uint5_t thresh_high := 20,
228 template uint5_t thresh_low := 10,
229 template uint5_t qrxlevmin := 22)
230:= tr_EUTRAN_NeighbourCells(
231 cell_desc_list := cell_desc_list,
232 prio_presence := '1'B,
233 prio := prio,
234 thresh_high := thresh_high,
235 thresh_low_presence := '1'B,
236 thresh_low := thresh_low,
237 qrxlevmin_presence := '1'B,
238 qrxlevmin := qrxlevmin);
239
240template SystemInformationConfig SystemInformationConfig_default := {
241 si1 := {
242 cell_chan_desc := '8FB38000000000000000000000000000'O,
243 rach_control := {
244 max_retrans := RACH_MAX_RETRANS_7,
245 tx_integer := '1001'B,
246 cell_barr_access := false,
247 re_not_allowed := true,
248 acc := '0000010000000000'B
249 },
250 rest_octets := ?
251 },
252 si2 := {
253 bcch_freq_list := '00000000000000000000000000000000'O,
254 ncc_permitted := '11111111'B,
255 rach_control := {
256 max_retrans := RACH_MAX_RETRANS_7,
257 tx_integer := '1001'B,
258 cell_barr_access := false,
259 re_not_allowed := true,
260 acc := '0000010000000000'B
261 }
262 },
263 si2bis := omit,
264 si2ter := {
265 extd_bcch_freq_list := '8E320000000000000000000000000800'O,
266 rest_octets := ?
267 },
268 si2quater := {
269 tr_SI2quaterRestOctets_EUTRAN( repeated_neigh_cells := { tr_EUTRAN_NeighbourCells_default } )
270 },
271 si3 := {
272 cell_id := 0,
273 lai := {
274 mcc_mnc := '001F01'H,
275 lac := 1
276 },
277 ctrl_chan_desc := {
278 msc_r99 := true,
279 att := true,
280 bs_ag_blks_res := 1,
281 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
282 si22ind := false,
283 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
284 spare := '00'B,
285 bs_pa_mfrms := 3,
286 t3212 := 30
287 },
288 cell_options := {
289 dn_ind := false,
290 pwrc := false,
291 dtx := MS_SHALL_USE_UL_DTX,
292 radio_link_tout_div4 := 7
293 },
294 cell_sel_par := {
295 cell_resel_hyst_2dB := 2,
296 ms_txpwr_max_cch := 7,
297 acs := '0'B,
298 neci := true,
299 rxlev_access_min := 0
300 },
301 rach_control := {
302 max_retrans := RACH_MAX_RETRANS_7,
303 tx_integer := '1001'B,
304 cell_barr_access := false,
305 re_not_allowed := true,
306 acc := '0000010000000000'B
307 },
308 rest_octets := {
309 sel_params := {
310 presence := '0'B,
311 params := omit
312 },
313 pwr_offset := {
314 presence := '0'B,
315 offset := omit
316 },
317 si_2ter_ind := '1'B,
318 early_cm_ind := '0'B,
319 sched_where := {
320 presence := '0'B,
321 where := omit
322 },
323 gprs_ind := {
324 presence := '1'B,
325 ind := {
326 ra_colour := 0,
327 si13_pos := '0'B
328 }
329 },
330 umts_early_cm_ind := '1'B,
331 si2_quater_ind := {
332 presence := '1'B,
333 ind := '0'B
334 },
335 iu_mode_ind := omit,
336 si21_ind := {
337 presence := '0'B,
338 pos := omit
339 }
340 }
341 },
342 si4 := {
343 lai := {
344 mcc_mnc := '001F01'H,
345 lac := 1
346 },
347 cell_sel_par := {
348 cell_resel_hyst_2dB := 2,
349 ms_txpwr_max_cch := 7,
350 acs := '0'B,
351 neci := true,
352 rxlev_access_min := 0
353 },
354 rach_control := {
355 max_retrans := RACH_MAX_RETRANS_7,
356 tx_integer := '1001'B,
357 cell_barr_access := false,
358 re_not_allowed := true,
359 acc := '0000010000000000'B
360 },
Neels Hofmeyr74083c22020-07-29 00:43:01 +0200361 cbch_chan_desc := {
362 iei := '64'O,
363 v := {
364 chan_nr := {
365 u := {
366 sdcch4 := {
367 tag := '001'B,
368 sub_chan := 2
369 }
370 },
371 tn := 0
372 },
373 tsc := 2,
374 h := false,
375 arfcn := 871,
376 maio_hsn := omit
377 }
378 },
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200379 cbch_mobile_alloc := omit,
380 rest_octets := {
381 sel_params := {
382 presence := '0'B,
383 params := omit
384 },
385 pwr_offset := {
386 presence := '0'B,
387 offset := omit
388 },
389 gprs_ind := {
390 presence := '1'B,
391 ind := {
392 ra_colour := 0,
393 si13_pos := '0'B
394 }
395 },
396 s_presence := '0'B,
397 s := omit
398 }
399 },
Pau Espin Pedrol28652d82021-02-09 20:20:17 +0100400 si13 := {
401 rest_octets := {
402 presence := '1'B,
403 bcch_change_mark := ?,
404 si_change_field := '0000'B,
405 presence2 := '0'B,
406 si13_change_mark := omit,
407 gprs_ma := omit,
408 zero := '0'B, /* PBCCH not present in cell */
409 rac := 0,
410 spgc_ccch_sup := '0'B,
411 priority_access_thr := '110'B,
412 network_control_order := '00'B,
413 gprs_cell_opts := {
414 nmo := '01'B,
415 t3168 := '011'B,
416 t3192 := '010'B,
417 drx_timer_max := '011'B,
418 access_burst_type := '0'B,
419 control_ack_type := '1'B,
420 bs_cv_max := 15,
421 pan_presence := '1'B,
422 pan_dec := 1,
423 pan_inc := 1,
424 pan_max := '111'B,
425 ext_info_presence := ?,
426 ext_info_length := *,
427 ext_info := *
428 },
429 gprs_pwr_ctrl_params := {
430 alpha := 0,
431 t_avg_w := '10000'B,
432 t_avg_t := '10000'B,
433 pc_meas_chan := '0'B,
434 n_avg_i := '1000'B
435 }
436 }
437 },
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200438 si5 := {
439 bcch_freq_list := '10000000000000000000000000000000'O
440 },
441 si5bis := omit,
442 si5ter := {
443 extd_bcch_freq_list := '9E050020000000000000000000000000'O
444 },
445 si6 := {
446 cell_id := 0,
447 lai := {
448 mcc_mnc := '001F01'H,
449 lac := 1
450 },
451 cell_options := {
452 dtx_ext := '1'B,
453 pwrc := false,
454 dtx := '01'B,
455 radio_link_timeout := '0111'B
456 },
457 ncc_permitted := '11111111'B,
Vadim Yanitskiy348b07c2022-03-10 17:11:22 +0300458 rest_octets := {
459 pch_nch_info := ?,
460 vbs_vgcs_options := ?,
461 dtm_support := '0'B,
462 rac := omit,
463 max_lapdm := omit,
464 band_ind := '0'B /* C0 ARFCN indicates 1800 band */
465 }
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200466 }
467 };
468
469
470/* List of all the System Information received on all RSL ports */
471type record of SystemInformationConfig SystemInformationConfig_list;
472
473function f_sysinfo_dec_raw(inout SystemInformationConfig si, RSL_Message rsl)
474{
475 var RSL_IE_Body sysinfo_type_ie;
476 var RSL_IE_SysinfoType si_type;
477 var octetstring data;
478
479 if (f_rsl_find_ie(rsl, RSL_IE_SYSINFO_TYPE, sysinfo_type_ie) == false) {
480 setverdict(fail, "Cannot find RSL_IE_SYSINFO_TYPE");
481 mtc.stop;
482 }
483 si_type := sysinfo_type_ie.sysinfo_type;
484
485 if (rsl.msg_type == RSL_MT_BCCH_INFO) {
486 var RSL_IE_Body bcch_ie;
487 if (f_rsl_find_ie(rsl, RSL_IE_FULL_BCCH_INFO, bcch_ie)) {
488 data := bcch_ie.other.payload;
489 }
490 } else if (rsl.msg_type == RSL_MT_SACCH_FILL) {
491 var RSL_IE_Body l3_ie;
492 if (f_rsl_find_ie(rsl, RSL_IE_L3_INFO, l3_ie)) {
493 data := l3_ie.l3_info.payload;
494 }
495 } else {
496 setverdict(fail, "Don't understand this System Information message");
497 mtc.stop;
498 }
499
500 var boolean handled := false;
501
502 if (rsl.msg_type == RSL_MT_BCCH_INFO) {
503 handled := true;
504
505 if (si_type == RSL_SYSTEM_INFO_1) {
506 if (not isbound(data)) {
507 si.si1 := omit;
508 } else {
509 si.si1 := dec_SystemInformation(data).payload.si1;
510 }
511 } else if (si_type == RSL_SYSTEM_INFO_2) {
512 if (not isbound(data)) {
513 si.si2 := omit;
514 } else {
515 si.si2 := dec_SystemInformation(data).payload.si2;
516 }
517 } else if (si_type == RSL_SYSTEM_INFO_2bis) {
518 if (not isbound(data)) {
519 si.si2bis := omit;
520 } else {
521 si.si2bis := dec_SystemInformation(data).payload.si2bis;
522 }
523 } else if (si_type == RSL_SYSTEM_INFO_2ter) {
524 if (not isbound(data)) {
525 si.si2ter := omit;
526 } else {
527 si.si2ter := dec_SystemInformation(data).payload.si2ter;
528 }
529 } else if (si_type == RSL_SYSTEM_INFO_2quater) {
530 if (not isbound(data)) {
531 si.si2quater := {};
532 } else {
533 var SystemInformationType2quater decoded := dec_SystemInformation(data).payload.si2quater;
534 /* this is a *record* of SI2quaterRestOctets! (multiplexed) */
535 si.si2quater[decoded.rest_octets.si2quater_index] := decoded.rest_octets;
536 }
537 } else if (si_type == RSL_SYSTEM_INFO_3) {
538 if (not isbound(data)) {
539 si.si3 := omit;
540 } else {
541 si.si3 := dec_SystemInformation(data).payload.si3;
542 }
543 } else if (si_type == RSL_SYSTEM_INFO_4) {
544 if (not isbound(data)) {
545 si.si4 := omit;
546 } else {
547 si.si4 := dec_SystemInformation(data).payload.si4;
548 }
549 } else if (si_type == RSL_SYSTEM_INFO_13) {
550 if (not isbound(data)) {
551 si.si13 := omit;
552 } else {
Pau Espin Pedrol28652d82021-02-09 20:20:17 +0100553 si.si13 := dec_SystemInformation(data).payload.si13;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200554 }
555 } else {
556 handled := false;
557 }
558 } else if (rsl.msg_type == RSL_MT_SACCH_FILL) {
559 handled := true;
560
561 if (si_type == RSL_SYSTEM_INFO_5) {
562 if (not isbound(data)) {
563 si.si5 := omit;
564 } else {
565 si.si5 := dec_SystemInformation(data).payload.si5;
566 }
567 } else if (si_type == RSL_SYSTEM_INFO_5bis) {
568 if (not isbound(data)) {
569 si.si5bis := omit;
570 } else {
571 si.si5bis := dec_SystemInformation(data).payload.si5bis;
572 }
573 } else if (si_type == RSL_SYSTEM_INFO_5ter) {
574 if (not isbound(data)) {
575 si.si5ter := omit;
576 } else {
577 si.si5ter := dec_SystemInformation(data).payload.si5ter;
578 }
579 } else if (si_type == RSL_SYSTEM_INFO_6) {
580 if (not isbound(data)) {
581 si.si6 := omit;
582 } else {
583 si.si6 := dec_SystemInformation(data).payload.si6;
584 }
585 } else {
586 handled := false;
587 }
588 }
589
590 if (not handled) {
591 setverdict(fail, "Unexpected SI type in ", rsl.msg_type, " message: ", si_type);
592 }
593}
594
Harald Weltea4ca4462018-02-09 00:17:14 +0100595type component test_CT extends CTRL_Adapter_CT {
Harald Welte21b46bd2017-12-17 19:46:32 +0100596 /* Array of per-BTS state */
Harald Welte96c94412017-12-09 03:12:45 +0100597 var BTS_State bts[NUM_BTS];
Harald Welte89ab1912018-02-23 18:56:29 +0100598 /* RSL common Channel Port (for RSL_Emulation) */
599 port RSL_CCHAN_PT RSL_CCHAN[NUM_BTS];
Harald Welte21b46bd2017-12-17 19:46:32 +0100600 /* array of per-BTS RSL test ports */
Harald Welteae026692017-12-09 01:03:01 +0100601 port IPA_RSL_PT IPA_RSL[NUM_BTS];
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100602 port IPA_CODEC_PT IPA; /* Required for compilation of TC_rsl_unknown_unit_id() */
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +0200603 /* CTRL muxed over IPA in SCCPlite conn BSC<->MSC (or BSC-NAT) */
604 port IPA_CTRL_PT SCCPLITE_IPA_CTRL;
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100605 /* Configure/manage IPA_Emulation: */
606 port IPA_CFG_PT IPA_CFG_PORT;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100607
Daniel Willmann191e0d92018-01-17 12:44:35 +0100608 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +0100609 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100610
Daniel Willmannebdecc02020-08-12 15:30:17 +0200611 /* StatsD */
612 var StatsD_Checker_CT vc_STATSD;
613
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200614 var RAN_Adapter g_bssap[NUM_MSC];
Harald Welte47cd0e32020-08-21 12:39:11 +0200615 var BSSAP_LE_Adapter g_bssap_le;
Harald Weltea4ca4462018-02-09 00:17:14 +0100616 /* for old legacy-tests only */
617 port BSSAP_CODEC_PT BSSAP;
Harald Welte47cd0e32020-08-21 12:39:11 +0200618 port BSSAP_LE_CODEC_PT BSSAP_LE;
Harald Weltea4ca4462018-02-09 00:17:14 +0100619
Harald Welte21b46bd2017-12-17 19:46:32 +0100620 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +0100621 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +0100622
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200623 /* Osmux is enabled through VTY */
624 var boolean g_osmux_enabled := false;
625
Pau Espin Pedrolc675b612020-01-09 19:55:40 +0100626 /*Configure T(tias) over VTY, seconds */
627 var integer g_bsc_sccp_timer_ias := 7 * 60;
628 /*Configure T(tiar) over VTY, seconds */
629 var integer g_bsc_sccp_timer_iar := 15 * 60;
630
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +0200631 /* global test case guard timer (actual timeout value is set in f_init()) */
Harald Welteae026692017-12-09 01:03:01 +0100632 timer T_guard := 30.0;
633
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200634 var CounterNameValsList g_ctr_msc;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000635 var CounterNameValsList g_ctr_bsc;
636 var CounterNameValsList g_ctr_bts;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200637
638 /* System Information bytes as received during RSL startup, for each RSL[idx]. */
639 var SystemInformationConfig_list g_system_information := {};
Harald Welte28d943e2017-11-25 15:00:50 +0100640}
641
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200642type record of charstring phys_chan_configs;
Harald Welte28d943e2017-11-25 15:00:50 +0100643modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +0100644 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +0100645 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100646 /* port number to which to establish the IPA OML connections */
647 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +0100648 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +0100649 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +0100650 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +0100651 integer mp_bsc_ctrl_port := 4249;
Daniel Willmannebdecc02020-08-12 15:30:17 +0200652 /* port number to which to listen for STATSD metrics */
653 integer mp_bsc_statsd_port := 8125;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100654 /* IP address at which the test binds */
655 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100656
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200657 RAN_Configurations mp_bssap_cfg := {
658 {
659 transport := BSSAP_TRANSPORT_AoIP,
660 sccp_service_type := "mtp3_itu",
661 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
662 own_pc := 185, /* 0.23.1 first MSC emulation */
663 own_ssn := 254,
664 peer_pc := 187, /* 0.23.3 osmo-bsc */
665 peer_ssn := 254,
666 sio := '83'O,
Harald Weltecb0cc432020-06-21 19:42:31 +0200667 rctx := 1
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200668 },
669 {
670 transport := BSSAP_TRANSPORT_AoIP,
671 sccp_service_type := "mtp3_itu",
672 sctp_addr := { 23906, "127.0.0.1", 2905, "127.0.0.1" },
673 own_pc := 2, /* 0.0.2 second MSC emulation */
674 own_ssn := 254,
675 peer_pc := 187, /* 0.23.3 osmo-bsc */
676 peer_ssn := 254,
677 sio := '83'O,
678 rctx := 2
679 },
680 {
681 transport := BSSAP_TRANSPORT_AoIP,
682 sccp_service_type := "mtp3_itu",
683 sctp_addr := { 23907, "127.0.0.1", 2905, "127.0.0.1" },
684 own_pc := 3, /* 0.0.3 third MSC emulation */
685 own_ssn := 254,
686 peer_pc := 187, /* 0.23.3 osmo-bsc */
687 peer_ssn := 254,
688 sio := '83'O,
689 rctx := 3
690 }
Harald Weltea4ca4462018-02-09 00:17:14 +0100691 };
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +0200692
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200693 /* Must match per BTS config in osmo-bsc.cfg */
694 phys_chan_configs phys_chan_config := {
695 "CCCH+SDCCH4+CBCH",
696 "TCH/F",
697 "TCH/F",
698 "TCH/F",
699 "TCH/F",
Vadim Yanitskiy343c9eb2021-07-16 18:36:01 +0600700 "TCH/H",
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200701 "PDCH",
702 "PDCH"
703 };
704
Harald Welte47cd0e32020-08-21 12:39:11 +0200705 BSSAP_LE_Configuration mp_bssap_le_cfg := {
706 sccp_service_type := "mtp3_itu",
707 sctp_addr := { 23908, "127.0.0.1", 2905, "127.0.0.1" },
Neels Hofmeyrac086c12020-09-18 23:46:42 +0200708 own_pc := 190, /* 0.23.6 SMLC emulation */
Harald Welte47cd0e32020-08-21 12:39:11 +0200709 own_ssn := 252, /* SMLC side SSN */
710 peer_pc := 187, /* 0.23.3 osmo-bsc */
711 peer_ssn := 250, /* BSC side SSN */
712 sio := '83'O,
713 rctx := 6
714 };
Neels Hofmeyrcfe44062020-10-15 02:28:08 +0200715 boolean mp_enable_lcs_tests := true;
Harald Welte47cd0e32020-08-21 12:39:11 +0200716
Pau Espin Pedrol8f30ccd2019-11-01 17:30:57 +0100717 /* Value set in osmo-bsc.cfg "ms max power" */
718 uint8_t mp_exp_ms_power_level := 7;
Vadim Yanitskiy6e068012022-02-05 21:35:43 +0600719
720 /* Whether to check for memory leaks */
721 boolean mp_verify_talloc_count := true;
Harald Weltea4ca4462018-02-09 00:17:14 +0100722}
723
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +0200724friend function f_gen_test_hdlr_pars(integer bssap_idx := 0) return TestHdlrParams {
Philipp Maier48604732018-10-09 15:00:37 +0200725
726 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200727 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier48604732018-10-09 15:00:37 +0200728 pars.aoip := true;
729 } else {
730 pars.aoip := false;
731 }
Pau Espin Pedrol8f30ccd2019-11-01 17:30:57 +0100732 pars.exp_ms_power_level := mp_exp_ms_power_level;
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200733 pars.mscpool.bssap_idx := bssap_idx;
Neels Hofmeyrbf720202021-10-02 12:58:24 +0200734 pars.expect_tsc := BTS_TSC[0];
Vadim Yanitskiy96bb9cb2021-12-10 21:14:15 +0300735 pars.imsi := f_rnd_imsi('00101'H);
736
737 log(testcasename(), ": using IMSI ", pars.imsi);
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200738
Philipp Maier48604732018-10-09 15:00:37 +0200739 return pars;
740}
741
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200742/* Convenience functions for rate counters using g_ctr_msc. */
743
744private function f_ctrs_msc_init(integer mscs_count := NUM_MSC, CounterNameVals counternames := counternames_msc_mscpool) runs on test_CT {
745 g_ctr_msc := f_counter_name_vals_get_n(IPA_CTRL, "msc", mscs_count, counternames);
746 log("initial msc rate counters: ", g_ctr_msc);
747}
748
749private function f_ctrs_msc_add(integer msc_nr, charstring countername, integer val := 1) runs on test_CT {
Neels Hofmeyr9656e922020-06-30 01:27:01 +0200750 f_counter_name_vals_list_add(g_ctr_msc, msc_nr, countername, val);
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200751}
752
753/* f_ctrs_msc_init();
754 * f_do_thing(on_msc := 0);
755 * f_do_thing(on_msc := 0);
756 * f_do_other(on_msc := 1);
757 * f_ctrs_msc_add(0, "thing", 2);
758 * f_ctrs_msc_add(1, "other");
759 * f_ctrs_msc_verify();
760 */
761private function f_ctrs_msc_verify() runs on test_CT {
762 log("verifying msc rate counters: ", g_ctr_msc);
763 f_counter_name_vals_expect_n(IPA_CTRL, "msc", g_ctr_msc);
764}
765
766/* convenience: f_ctrs_msc_add() and f_ctrs_msc_verify() in one call.
767 * f_ctrs_msc_init();
768 * f_do_thing(on_msc := 0);
769 * f_do_thing(on_msc := 0);
770 * f_do_thing(on_msc := 0);
771 * f_ctrs_msc_expect(0, "thing", 3);
772 */
773private function f_ctrs_msc_expect(integer msc_nr, charstring countername, integer val := 1) runs on test_CT {
774 f_ctrs_msc_add(msc_nr, countername, val);
775 f_ctrs_msc_verify();
776}
777
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000778/* Convenience functions for rate counters using g_ctr_bts, always also including g_ctr_bsc. */
779
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100780private function f_ctrs_bts_init(integer bts_count := NUM_BTS, CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000781 g_ctr_bts := f_counter_name_vals_get_n(IPA_CTRL, "bts", bts_count, counternames);
Neels Hofmeyr4dec8cc2021-11-29 15:59:44 +0100782 log("initial bts rate counters: ", g_ctr_bts);
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100783}
784
785function f_ctrs_bsc_and_bts_init(integer bts_count := NUM_BTS, CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
786 f_ctrs_bts_init(bts_count, counternames);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000787 f_ctrs_bsc_init(counternames);
788}
789
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100790private function f_ctrs_bsc_and_bts_handover_init(integer bts_count := NUM_BTS) runs on test_CT {
791 var CounterNameVals bts_names := counternames_bsc_bts_handover & counternames_bts_handover;
Neels Hofmeyr4dec8cc2021-11-29 15:59:44 +0100792 f_ctrs_bts_init(bts_count, bts_names);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100793 f_ctrs_bsc_init(counternames_bsc_bts_handover);
794}
795
796private function f_ctrs_bts_add(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000797 f_counter_name_vals_list_add(g_ctr_bts, bts_nr, countername, val);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100798}
799
800private function f_ctrs_bsc_and_bts_add(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
801 f_ctrs_bts_add(bts_nr, countername, val);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000802 f_ctrs_bsc_add(countername, val);
803}
804
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100805function f_ctrs_bts_verify() runs on test_CT {
806 f_counter_name_vals_expect_n(IPA_CTRL, "bts", g_ctr_bts);
807}
808
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000809/* f_ctrs_bsc_and_bts_init();
810 * f_do_thing(on_bts := 0);
811 * f_do_thing(on_bts := 0);
812 * f_do_other(on_bts := 1);
813 * f_ctrs_bsc_and_bts_add(0, "thing", 2);
814 * f_ctrs_bsc_and_bts_add(1, "other");
815 * f_ctrs_bsc_and_bts_verify();
816 */
817private function f_ctrs_bsc_and_bts_verify() runs on test_CT {
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100818 f_ctrs_bts_verify();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000819 f_ctrs_bsc_verify();
820}
821
822/* convenience: f_ctrs_bsc_and_bts_add() and f_ctrs_bsc_and_bts_verify() in one call.
823 * f_ctrs_bsc_and_bts_init();
824 * f_do_thing(on_bts := 0);
825 * f_do_thing(on_bts := 0);
826 * f_do_thing(on_bts := 0);
827 * f_ctrs_bsc_and_bts_expect(0, "thing", 3);
828 */
829private function f_ctrs_bsc_and_bts_expect(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
830 f_ctrs_bsc_and_bts_add(bts_nr, countername, val);
831 f_ctrs_bsc_and_bts_verify();
832}
833
834
835/* Convenience functions for rate counters using g_ctr_bsc. */
836
837private function f_ctrs_bsc_init(CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
838 g_ctr_bsc := f_counter_name_vals_get_n(IPA_CTRL, "bsc", 1, counternames);
839 log("initial bsc rate counters: ", g_ctr_bsc);
840}
841
842private function f_ctrs_bsc_add(charstring countername, integer val := 1) runs on test_CT {
843 f_counter_name_vals_list_add(g_ctr_bsc, 0, countername, val);
844}
845
846/* f_ctrs_bsc_init();
847 * f_do_thing();
848 * f_do_thing();
849 * f_do_other();
850 * f_ctrs_bsc_add("thing", 2);
851 * f_ctrs_bsc_add("other");
852 * f_ctrs_bsc_verify();
853 */
854private function f_ctrs_bsc_verify() runs on test_CT {
855 f_counter_name_vals_expect_n(IPA_CTRL, "bsc", g_ctr_bsc);
856}
857
858/* convenience: f_ctrs_bsc_add() and f_ctrs_bsc_verify() in one call.
859 * f_ctrs_bsc_init();
860 * f_do_thing();
861 * f_ctrs_bsc_expect("thing", 1);
862 */
863private function f_ctrs_bsc_expect(charstring countername, integer val := 1) runs on test_CT {
864 f_ctrs_bsc_add(countername, val);
865 f_ctrs_bsc_verify();
866}
867
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200868
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +0200869friend function f_shutdown_helper() runs on test_CT {
Neels Hofmeyr18997492021-12-13 17:30:35 +0100870 /* Run the subscr and conn leak test only when the VTY is initialized */
Vadim Yanitskiy6e068012022-02-05 21:35:43 +0600871 if (BSCVTY.checkstate("Mapped") and mp_verify_talloc_count) {
Neels Hofmeyr18997492021-12-13 17:30:35 +0100872 f_verify_talloc_count(BSCVTY, {"struct bsc_subscr", "struct gsm_subscriber_connection"});
873 }
874
Daniel Willmann637ef6c2018-07-25 10:49:09 +0200875 all component.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100876 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200877 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100878}
879
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200880private function f_legacy_bssap_reset(integer bssap_idx := 0) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +0100881 var BSSAP_N_UNITDATA_ind ud_ind;
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200882 var boolean reset_received := false;
Harald Weltea4ca4462018-02-09 00:17:14 +0100883 timer T := 5.0;
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200884 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
885 ts_BSSMAP_Reset(0, g_osmux_enabled)));
Harald Weltea4ca4462018-02-09 00:17:14 +0100886 T.start;
887 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200888 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap[bssap_idx].sccp_addr_own, g_bssap[bssap_idx].sccp_addr_peer,
889 tr_BSSMAP_ResetAck(g_osmux_enabled))) {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200890 log("BSSMAP: Received RESET-ACK in response to RESET, we're ready to go!");
Harald Weltea4ca4462018-02-09 00:17:14 +0100891 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200892 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200893 log("BSSMAP: Respoding to inbound RESET with RESET-ACK");
Harald Weltea4ca4462018-02-09 00:17:14 +0100894 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200895 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200896 reset_received := true;
Harald Weltea4ca4462018-02-09 00:17:14 +0100897 repeat;
898 }
899 [] BSSAP.receive { repeat; }
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200900 [] T.timeout {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200901 log("BSSMAP: Timeout waiting for RESET-ACK after sending RESET");
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200902 /* If we received a RESET after ours was sent, it
903 may be a race condition where the other peer beacame
904 available after we sent it, but we are in a desired
905 state anyway, so go forward. */
906 if (not reset_received) {
907 setverdict(fail);
908 }
909 }
Harald Weltea4ca4462018-02-09 00:17:14 +0100910 }
Harald Welte28d943e2017-11-25 15:00:50 +0100911}
912
Harald Welteae026692017-12-09 01:03:01 +0100913type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100914 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100915 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100916 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100917 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100918 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100919 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100920 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100921 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100922}
923
Harald Welte21b46bd2017-12-17 19:46:32 +0100924/*! Start the IPA/RSL related bits for one IPA_Client.
925 * \param clnt IPA_Client for which to establish
926 * \param bsc_host IP address / hostname of the BSC
927 * \param bsc_port TCP port number of the BSC
928 * \param i number identifying this BTS
929 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100930function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
931 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100932runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100933 timer T := 10.0;
934
Harald Welte96c94412017-12-09 03:12:45 +0100935 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welte71389132021-12-09 21:58:18 +0100936 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA") alive;
Harald Welteae026692017-12-09 01:03:01 +0100937 clnt.ccm_pars := c_IPA_default_ccm_pars;
938 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
939 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100940 if (handler_mode) {
Harald Welte71389132021-12-09 21:58:18 +0100941 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL") alive;
Harald Welte89ab1912018-02-23 18:56:29 +0100942 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100943 }
Harald Welteae026692017-12-09 01:03:01 +0100944
945 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100946 connect(clnt.vc_IPA:CFG_PORT, self:IPA_CFG_PORT);
Harald Welte624f9632017-12-16 19:26:04 +0100947 if (handler_mode) {
948 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
949 } else {
950 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
951 }
Harald Welteae026692017-12-09 01:03:01 +0100952
Harald Welte5d1a2202017-12-13 19:51:29 +0100953 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100954 if (handler_mode) {
955 clnt.vc_RSL.start(RSL_Emulation.main());
956 return;
957 }
Harald Welteae026692017-12-09 01:03:01 +0100958
959 /* wait for IPA RSL link to connect and send ID ACK */
960 T.start;
961 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700962 [] IPA_RSL[i].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) {
Harald Welteae026692017-12-09 01:03:01 +0100963 T.stop;
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +0700964 IPA_RSL[i].send(ts_ASP_RSL_UD(ts_RSL_PAGING_LOAD_IND(23)));
Harald Welteae026692017-12-09 01:03:01 +0100965 }
Harald Welte60e823a2017-12-10 14:10:59 +0100966 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100967 [] IPA_RSL[i].receive { repeat }
968 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100969 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200970 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100971 }
972 }
973}
974
Harald Welte12055472018-03-17 20:10:08 +0100975function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100976 var IPL4asp_Types.Result res := {
977 errorCode := omit,
978 connId := omit,
979 os_error_code := omit,
980 os_error_text := omit
981 };
982
Harald Welte12055472018-03-17 20:10:08 +0100983 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
984 return;
985 }
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100986
987 /* Alive components don't finish sockets (TCP FIN) when they are
988 * stopped. Hence, we need to manually call close() on them to make sure
989 * the IUT knows about it. */
990 f_ipa_cfg_disconnect(IPA_CFG_PORT, res);
991
Harald Welte12055472018-03-17 20:10:08 +0100992 clnt.vc_IPA.stop;
993 if (isbound(clnt.vc_RSL)) {
994 clnt.vc_RSL.stop;
995 }
996}
997
Harald Welte21b46bd2017-12-17 19:46:32 +0100998/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100999function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
1000 timer T := secs_max;
1001 T.start;
1002 while (true) {
1003 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
1004 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +01001005 /* the 'degraded' state exists from OML connection time, and we have to wait
1006 * until all MO's are initialized */
1007 T.start(1.0);
1008 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001009 return;
1010 }
Harald Weltef0d6ac62017-12-17 17:02:21 +01001011 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +01001012 if (not T.running) {
Max99253902018-11-16 17:57:39 +01001013 setverdict(fail, "Timeout waiting for BTS" & int2str(bts_nr) & " oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +02001014 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001015 }
1016 }
1017}
1018
Harald Welte21b46bd2017-12-17 19:46:32 +01001019/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +01001020altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +01001021 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +01001022 [] T_guard.timeout {
1023 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +02001024 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +01001025 }
Harald Welte60e823a2017-12-10 14:10:59 +01001026 /* always respond with RESET ACK to RESET */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001027 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Welte60e823a2017-12-10 14:10:59 +01001028 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001029 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Welte69c1c262017-12-13 21:02:08 +01001030 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +01001031 }
Harald Welte28d943e2017-11-25 15:00:50 +01001032}
1033
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001034altstep no_bssmap_reset() runs on test_CT {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001035 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001036 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +02001037 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001038 }
1039}
1040
Daniel Willmann191e0d92018-01-17 12:44:35 +01001041function f_init_mgcp(charstring id) runs on test_CT {
1042 id := id & "-MGCP";
1043
1044 var MGCPOps ops := {
1045 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
1046 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
1047 };
1048 var MGCP_conn_parameters mgcp_pars := {
1049 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +01001050 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +01001051 mgw_ip := mp_test_ip,
Pau Espin Pedrol1a026a52019-06-18 17:21:52 +02001052 mgw_udp_port := 2427,
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02001053 /* Enable it for SCCPlite, since we have 2 MGCP sockets towards MGW (UDP one +
1054 the on with MGCP over IPA forwarded from MSC one) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001055 multi_conn_mode := (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER)
Daniel Willmann191e0d92018-01-17 12:44:35 +01001056 };
1057
Harald Welte71389132021-12-09 21:58:18 +01001058 vc_MGCP := MGCP_Emulation_CT.create(id) alive;
Daniel Willmann191e0d92018-01-17 12:44:35 +01001059 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
1060}
1061
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001062/* Enable or disable (current default) Osmux. When enabling, BSSMAP Reset
1063 * contains extra IE (OsmuxSupport) and osmo-bsc will handle AssignReq with
1064 * OsmuxCID IE.
1065 */
1066private function f_vty_allow_osmux(boolean allow) runs on test_CT {
1067 f_vty_enter_cfg_msc(BSCVTY, 0);
1068 if (allow) {
1069 f_vty_transceive(BSCVTY, "osmux on");
1070 } else {
1071 f_vty_transceive(BSCVTY, "osmux off");
1072 }
1073 f_vty_transceive(BSCVTY, "exit");
1074 f_vty_transceive(BSCVTY, "exit");
1075 g_osmux_enabled := allow;
1076}
1077
Max2253c0b2018-11-06 19:28:05 +01001078function f_init_vty(charstring id := "foo") runs on test_CT {
Harald Welte94e0c342018-04-07 11:33:23 +02001079 if (BSCVTY.checkstate("Mapped")) {
1080 /* skip initialization if already executed once */
1081 return;
1082 }
Harald Weltebc03c762018-02-12 18:09:38 +01001083 map(self:BSCVTY, system:BSCVTY);
1084 f_vty_set_prompts(BSCVTY);
1085 f_vty_transceive(BSCVTY, "enable");
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01001086 f_cs7_inst_0_cfg(BSCVTY, {"sccp-timer ias " & int2str(g_bsc_sccp_timer_ias),
1087 "sccp-timer iar " & int2str(g_bsc_sccp_timer_iar)});
Harald Weltebc03c762018-02-12 18:09:38 +01001088}
1089
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +02001090friend function f_logp(TELNETasp_PT pt, charstring log_msg)
Neels Hofmeyr4f118412020-06-04 15:25:10 +02001091{
1092 // log on TTCN3 log output
1093 log(log_msg);
1094 // log in stderr log
Neels Hofmeyr8bdafe52021-12-14 17:25:48 +01001095 if (pt.checkstate("Mapped")) {
1096 f_vty_transceive(pt, "logp lglobal notice TTCN3 f_logp(): " & log_msg);
1097 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02001098}
1099
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001100private function f_sysinfo_seen(integer rsl_idx, RSL_Message rsl) runs on test_CT
1101{
1102 if (rsl_idx >= lengthof(g_system_information)) {
1103 g_system_information[rsl_idx] := SystemInformationConfig_omit
1104 }
1105 f_sysinfo_dec_raw(g_system_information[rsl_idx], rsl);
1106}
1107
1108altstep as_catch_RSL_sysinfo(integer rsl_idx) runs on test_CT {
1109 var ASP_RSL_Unitdata rx_rsl_ud;
1110
1111 /* For handler_mode := false, receiving the RSL bootstrap messages directly on IPA_RSL */
1112 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
1113 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1114 repeat;
1115 }
1116 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
1117 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1118 repeat;
1119 }
1120 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> value rx_rsl_ud {
1121 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1122 repeat;
1123 }
1124 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_SACCH_FILL)) -> value rx_rsl_ud {
1125 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1126 repeat;
1127 }
1128
1129 /* For handler_mode := true, receiving the RSL bootstrap messages via RSL_Emulation */
1130 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
1131 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1132 repeat;
1133 }
1134 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
1135 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1136 repeat;
1137 }
1138 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> value rx_rsl_ud {
1139 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1140 repeat;
1141 }
1142 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_SACCH_FILL)) -> value rx_rsl_ud {
1143 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1144 repeat;
1145 }
1146}
1147
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001148/* TODO: use BooleanList from COMMON/src/General_Types.ttcn */
1149private type record of boolean my_BooleanList;
1150
1151private function f_vty_msc_allow_attach(TELNETasp_PT pt, my_BooleanList allow_attach_list)
1152{
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001153 var charstring config := f_vty_transceive_ret(pt, "show running-config");
1154
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001155 for (var integer msc_nr := 0; msc_nr < sizeof(allow_attach_list); msc_nr := msc_nr+1) {
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001156 if (f_strstr(config, "\nmsc " & int2str(msc_nr) & "\n") < 0) {
1157 /* There is no 'msc N' for this msc_nr in the running config, so don't create an empty msc by
1158 * stepping into that config node. */
1159 log("msc ", msc_nr, " is not configured, skipping");
1160 continue;
1161 }
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001162 f_vty_enter_cfg_msc(pt, msc_nr);
1163 if (allow_attach_list[msc_nr]) {
1164 /* strict := false: ignore if osmo-bsc does not support this config option (latest build) */
1165 f_vty_transceive(pt, "allow-attach", strict := false);
1166 } else {
1167 f_vty_transceive(pt, "no allow-attach", strict := false);
1168 }
1169 f_vty_transceive(pt, "exit");
1170 f_vty_transceive(pt, "exit");
1171 }
1172}
1173
Harald Welte21b46bd2017-12-17 19:46:32 +01001174/* global initialization function
1175 * \param nr_bts Number of BTSs we should start/bring up
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001176 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false).
1177 * \param nr_msc Number of virtual MSCs to bring up to connect to osmo-bsc.
1178 */
1179function f_init(integer nr_bts := NUM_BTS, boolean handler_mode := false, boolean allow_osmux := false,
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001180 integer nr_msc := 1, float guard_timeout := 30.0) runs on test_CT {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001181 var integer bssap_idx;
Harald Welte28d943e2017-11-25 15:00:50 +01001182
Harald Welteae026692017-12-09 01:03:01 +01001183 if (g_initialized) {
1184 return;
Harald Welte28d943e2017-11-25 15:00:50 +01001185 }
Harald Welteae026692017-12-09 01:03:01 +01001186 g_initialized := true;
1187
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001188 T_guard.start(guard_timeout);
Daniel Willmanne68f9272018-11-27 15:15:28 +01001189 activate(as_Tguard());
1190
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001191 f_init_vty("VirtMSC");
Pau Espin Pedrol23510fb2021-07-20 17:00:38 +02001192 f_vty_allow_osmux(allow_osmux);
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001193
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001194 var my_BooleanList allow_attach := { false, false, false };
Daniel Willmannebdecc02020-08-12 15:30:17 +02001195 f_init_statsd("VirtMSC", vc_STATSD, mp_test_ip, mp_bsc_statsd_port);
1196
Neels Hofmeyr9db8e0e2021-08-23 20:45:58 +02001197 /* Make sure each MSC's internal state is "DISCONNECTED" at first */
1198 for (bssap_idx := 0; bssap_idx < NUM_MSC; bssap_idx := bssap_idx+1) {
1199 f_vty_transceive(BSCVTY, "msc " & int2str(bssap_idx) & " bssmap reset", strict := false);
1200 }
1201
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001202 for (bssap_idx := 0; bssap_idx < nr_msc; bssap_idx := bssap_idx+1) {
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001203 allow_attach[bssap_idx] := true;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001204 /* Call a function of our 'parent component' RAN_Adapter_CT to start the
1205 * MSC-side BSSAP emulation */
1206 if (handler_mode) {
1207 var RanOps ranops := MSC_RanOps;
1208 ranops.use_osmux := g_osmux_enabled;
1209 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", ranops);
1210 connect(self:SCCPLITE_IPA_CTRL, g_bssap[bssap_idx].vc_RAN:CTRL_CLIENT);
1211 f_ran_adapter_start(g_bssap[bssap_idx]);
1212 } else {
1213 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", omit);
1214 connect(self:BSSAP, g_bssap[bssap_idx].vc_SCCP:SCCP_SP_PORT);
1215 f_ran_adapter_start(g_bssap[bssap_idx]);
1216 f_legacy_bssap_reset();
1217 }
Harald Welte67089ee2018-01-17 22:19:03 +01001218 }
Harald Welted5833a82018-05-27 16:52:56 +02001219
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02001220 if (mp_enable_lcs_tests) {
1221 if (handler_mode) {
1222 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", SMLC_BssapLeOps);
1223 } else {
1224 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", omit);
1225 connect(self:BSSAP_LE, g_bssap_le.vc_SCCP:SCCP_SP_PORT);
1226 }
1227 f_bssap_le_adapter_start(g_bssap_le);
Harald Welte47cd0e32020-08-21 12:39:11 +02001228 }
Harald Welte47cd0e32020-08-21 12:39:11 +02001229
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001230 /* start the test with exactly all enabled MSCs allowed to attach */
1231 f_vty_msc_allow_attach(BSCVTY, allow_attach);
1232
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01001233 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +01001234
Daniel Willmann191e0d92018-01-17 12:44:35 +01001235 f_init_mgcp("VirtMSC");
1236
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001237 for (var integer i := 0; i < nr_bts; i := i+1) {
1238 f_init_bts(i, handler_mode);
Harald Welte696ddb62017-12-08 14:01:43 +01001239 }
Neels Hofmeyr9c0f9c82022-01-23 01:20:28 +01001240
1241 /* Emit a marker to appear in the SUT's own logging output */
1242 f_logp(BSCVTY, testcasename() & "() start");
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001243}
Harald Welte696ddb62017-12-08 14:01:43 +01001244
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001245function f_init_bts(integer bts_idx := 0, boolean handler_mode := false)
1246runs on test_CT {
1247 /* wait until osmo-bts-omldummy has respawned */
1248 f_wait_oml(bts_idx, "degraded", 5.0);
1249
1250 /* start RSL connection */
1251 f_ipa_rsl_start(bts[bts_idx].rsl, mp_bsc_ip, mp_bsc_rsl_port, bts_idx, handler_mode);
1252 /* wait until BSC tells us "connected" */
1253 f_wait_oml(bts_idx, "connected", 5.0);
Harald Welte28d943e2017-11-25 15:00:50 +01001254}
1255
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001256function f_init_bts_and_check_sysinfo(integer bts_idx := 0, boolean handler_mode := false,
1257 template SystemInformationConfig expect_si)
1258runs on test_CT {
1259 var default sysinfo := activate(as_catch_RSL_sysinfo(bts_idx));
1260
1261 f_init_bts(bts_idx, handler_mode);
1262
1263 /* Give some time to (hopefully/most likely) collect all system informations from RSL startup.
1264 * We could stop as soon as all expected SI are received, but then we might miss SI that we don't expect and
1265 * that might be sent afterwards. So rather give a generous timeout and be quite sure to catch all SI.
1266 */
1267 f_sleep(5.0);
1268 log("RSL ", bts_idx, " SYSTEM INFORMATION: ", g_system_information[bts_idx]);
1269
1270 deactivate(sysinfo);
1271
1272 if (match(g_system_information[bts_idx], expect_si)) {
1273 setverdict(pass);
1274 } else {
1275 log("RSL ", bts_idx, ": EXPECTED SI: ", expect_si);
1276 log("RSL ", bts_idx, ": GOT SI: ", g_system_information[bts_idx]);
1277 setverdict(fail, "received SI does not match expectations");
1278 return;
1279 }
1280}
1281
Maxd4e56962018-10-31 19:08:25 +01001282/* expect to receive a RSL message matching a specified template on a given BTS / stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001283function f_exp_ipa_rx(integer bts_nr, template (present) RSL_Message t_rx, float t_secs := 2.0, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
Harald Welteae026692017-12-09 01:03:01 +01001284runs on test_CT return RSL_Message {
1285 var ASP_RSL_Unitdata rx_rsl_ud;
1286 timer T := t_secs;
1287
1288 T.start;
1289 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001290 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
Harald Welteae026692017-12-09 01:03:01 +01001291 T.stop;
1292 }
1293 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +01001294 [] T.timeout {
1295 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +02001296 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +01001297 }
Harald Welteae026692017-12-09 01:03:01 +01001298 }
1299 return rx_rsl_ud.rsl;
1300}
1301
Harald Welte21b46bd2017-12-17 19:46:32 +01001302/* helper function to transmit RSL on a given BTS/stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001303function f_ipa_tx(integer bts_nr, template (value) RSL_Message t_tx, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
Harald Welteae026692017-12-09 01:03:01 +01001304runs on test_CT {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001305 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(t_tx, sid));
Harald Welteae026692017-12-09 01:03:01 +01001306}
1307
1308
Harald Welte4003d112017-12-09 22:35:39 +01001309/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +01001310testcase TC_chan_act_noreply() runs on test_CT {
1311 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +01001312 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +01001313
Harald Welte89d42e82017-12-17 16:42:41 +01001314 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +01001315
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001316 IPA_RSL[0].send(ts_ASP_RSL_UD(ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +01001317 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001318 f_shutdown_helper();
Harald Welte28d943e2017-11-25 15:00:50 +01001319}
1320
Neels Hofmeyr734b1a32021-11-29 16:00:17 +01001321const CounterNameVals counternames_bts_chreq := {
1322 { "chreq:total", 0 },
1323 { "chreq:attempted_emerg", 0 },
1324 { "chreq:attempted_call", 0 },
1325 { "chreq:attempted_location_upd", 0 },
1326 { "chreq:attempted_pag", 0 },
1327 { "chreq:attempted_pdch", 0 },
1328 { "chreq:attempted_other", 0 },
1329 { "chreq:attempted_unknown", 0 },
1330 { "chreq:successful", 0 },
1331 { "chreq:successful_emerg", 0 },
1332 { "chreq:successful_call", 0 },
1333 { "chreq:successful_location_upd", 0 },
1334 { "chreq:successful_pag", 0 },
1335 { "chreq:successful_pdch", 0 },
1336 { "chreq:successful_other", 0 },
1337 { "chreq:successful_unknown", 0 },
1338 { "chreq:no_channel", 0 },
1339 { "chreq:max_delay_exceeded", 0 }
1340};
1341
1342/* verify the "chreq:*" counters */
1343private function f_chan_act_counter(OCT1 ra, charstring chreq_ctr_suffix) runs on test_CT
1344{
1345 var GsmFrameNumber fn := 23;
1346
1347 f_logp(BSCVTY, "f_chan_act_counter(" & chreq_ctr_suffix & ")");
1348
1349 var RSL_Message rx_rsl;
1350 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1351 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1352 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1353
1354 f_ctrs_bts_add(0, "chreq:total");
1355 f_ctrs_bts_add(0, "chreq:attempted_" & chreq_ctr_suffix);
1356 f_ctrs_bts_verify();
1357
1358 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
1359 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
1360
1361 f_ctrs_bts_add(0, "chreq:successful");
1362 f_ctrs_bts_add(0, "chreq:successful_" & chreq_ctr_suffix);
1363 f_ctrs_bts_verify();
1364
1365 /* test is done, release RSL Conn Fail Ind to clean up */
1366 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1367 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1368 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
1369 f_sleep(1.0);
1370}
1371
Harald Welte4003d112017-12-09 22:35:39 +01001372testcase TC_chan_act_counter() runs on test_CT {
1373 var BSSAP_N_UNITDATA_ind ud_ind;
1374 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +01001375 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +01001376
Harald Welte89d42e82017-12-17 16:42:41 +01001377 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001378
Neels Hofmeyr734b1a32021-11-29 16:00:17 +01001379 f_vty_allow_emerg_bts(true, 0);
1380
1381 f_ctrs_bts_init(1, counternames_bts_chreq);
1382
1383 /* emergency call: RA & 0xe0 == 0xa0 --> CHREQ_T_EMERG_CALL */
1384 f_chan_act_counter('a3'O, "emerg");
1385
1386 /* voice TCH/H: RA & 0xf0 == 0x40 --> CHREQ_T_VOICE_CALL_TCH_H */
1387 f_chan_act_counter('43'O, "call");
1388
1389 /* LU: RA & 0xf0 == 0x00 --> CHREQ_T_LOCATION_UPD */
1390 f_chan_act_counter('03'O, "location_upd");
1391
1392 /* Paging: RA & 0xf0 == 0x20 --> CHREQ_T_PAG_R_TCH_F */
1393 f_chan_act_counter('23'O, "pag");
1394 /* Paging: RA & 0xf0 == 0x30 --> CHREQ_T_PAG_R_TCH_FH */
1395 f_chan_act_counter('33'O, "pag");
1396
1397 /* LU: RA & 0xfc == 0x78 --> CHREQ_T_PDCH_TWO_PHASE */
1398 /* no PCU, so PDCH not allowed. Skip this test for now. */
1399 /* f_chan_act_counter('7b'O, "pdch"); */
1400
1401 /* LU: RA & 0xf0 == 0x10 --> CHREQ_T_SDCCH */
1402 f_chan_act_counter('13'O, "other");
Harald Welte4003d112017-12-09 22:35:39 +01001403
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001404 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001405}
1406
Harald Welteae026692017-12-09 01:03:01 +01001407/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
Philipp Maier9c60a622020-07-09 15:08:46 +02001408private function f_TC_chan_act_ack_noest(OCT1 ra := '23'O) runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +01001409 var RSL_Message rx_rsl;
1410
Harald Welteae026692017-12-09 01:03:01 +01001411 /* Send CHAN RQD and wait for allocation; acknowledge it */
Philipp Maier9c60a622020-07-09 15:08:46 +02001412 var RslChannelNr chan_nr := f_chreq_act_ack(ra);
Harald Welteae026692017-12-09 01:03:01 +01001413
1414 /* expect BSC to disable the channel again if there's no RLL EST IND */
1415 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1416
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001417 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001418}
1419
Philipp Maier9c60a622020-07-09 15:08:46 +02001420/* Normal variant */
1421testcase TC_chan_act_ack_noest() runs on test_CT {
Philipp Maieraf58db22020-08-12 17:24:40 +02001422 f_init(1);
Philipp Maier9c60a622020-07-09 15:08:46 +02001423 f_TC_chan_act_ack_noest();
1424}
1425
1426/* Emergency call variant */
1427testcase TC_chan_act_ack_noest_emerg() runs on test_CT {
1428 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
Philipp Maieraf58db22020-08-12 17:24:40 +02001429 f_init(1);
1430 f_vty_allow_emerg_bts(true, 0);
Philipp Maier9c60a622020-07-09 15:08:46 +02001431 f_TC_chan_act_ack_noest(ra := 'A5'O);
1432}
1433
Philipp Maier606f07d2020-08-12 17:21:58 +02001434/* Emergency call variant, but emergency calls are not allowed */
1435testcase TC_chan_rqd_emerg_deny() runs on test_CT {
1436 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
1437
1438 var RSL_Message rx_rsl;
1439 var GsmRrMessage rr;
1440
1441 f_init(1);
1442 f_vty_allow_emerg_bts(false, 0);
1443
1444 IPA_RSL[0].clear;
1445 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
1446
1447 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
1448 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
1449 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1450 setverdict(pass);
1451 } else {
1452 setverdict(fail, "immediate assignment not rejected");
1453 }
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01001454
1455 f_shutdown_helper();
Philipp Maier606f07d2020-08-12 17:21:58 +02001456}
1457
Harald Welteae026692017-12-09 01:03:01 +01001458/* Test behavior if MSC never answers to CR */
1459testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +01001460 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
1461 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +01001462 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +01001463 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +01001464
Harald Welte89d42e82017-12-17 16:42:41 +01001465 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001466
1467 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001468 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001469
1470 var octetstring l3 := '00010203040506'O
1471 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1472
1473 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
1474
1475 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +01001476 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001477 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001478 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001479}
1480
1481/* Test behavior if MSC answers with CREF to CR */
1482testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
1483 var BSSAP_N_CONNECT_ind rx_c_ind;
1484 var RSL_Message rx_rsl;
1485
Harald Welte89d42e82017-12-17 16:42:41 +01001486 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001487
1488 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001489 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001490
1491 var octetstring l3 := '00010203040506'O
1492 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1493
1494 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1495 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
1496
1497 /* expect BSC to disable the channel */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001498 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001499 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001500}
1501
Harald Welte618ef642017-12-14 14:58:20 +01001502/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
1503testcase TC_chan_act_nack() runs on test_CT {
1504 var RSL_Message rx_rsl;
1505 var integer chact_nack;
1506
Harald Welte89d42e82017-12-17 16:42:41 +01001507 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +01001508
1509 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
1510
1511 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
1512 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1513 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1514
1515 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
1516
1517 /* wait for some time to hope the NACK arrives before the CTRL GET below */
1518 f_sleep(0.5);
1519
1520 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
1521
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001522 f_shutdown_helper();
Harald Welte618ef642017-12-14 14:58:20 +01001523}
1524
Harald Welte799c97b2017-12-14 17:50:30 +01001525/* Test for channel exhaustion due to RACH overload */
1526testcase TC_chan_exhaustion() runs on test_CT {
1527 var ASP_RSL_Unitdata rsl_ud;
1528 var integer i;
1529 var integer chreq_total, chreq_nochan;
1530
Harald Welte89d42e82017-12-17 16:42:41 +01001531 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +01001532
1533 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
1534 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
1535
Neels Hofmeyr85fa37f2021-10-06 13:50:38 +02001536 /* GSM 44.018 Table 9.1.8.2:
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +01001537 * RA = '33'O -> Establishment cause = 0011xxxx (MS dual rate capable and asks for "TCH/H or TCH/F").
1538 * With current setup, expect 4xSDCCH + 4xTCH/F + 1xTCH/H to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +02001539 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 +01001540 var RslChannelNr chan_nr := f_chreq_act_ack('33'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +01001541 }
1542
1543 IPA_RSL[0].clear;
1544
Harald Weltedd8cbf32018-01-28 12:07:52 +01001545 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001546 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +01001547
1548 /* now expect additional channel activations to fail */
1549 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
1550
1551 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001552 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
Harald Welte799c97b2017-12-14 17:50:30 +01001553 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
1554 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001555 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
Harald Welte799c97b2017-12-14 17:50:30 +01001556 var GsmRrMessage rr;
1557 /* match on IMM ASS REJ */
1558 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
1559 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1560 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001561 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +01001562 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
1563 chreq_nochan+1);
1564 setverdict(pass);
1565 } else {
1566 repeat;
1567 }
1568 }
1569 [] IPA_RSL[0].receive { repeat; }
1570 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001571 f_shutdown_helper();
Harald Welte799c97b2017-12-14 17:50:30 +01001572}
1573
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001574/* Test channel deactivation due to silence from MS */
1575testcase TC_chan_deact_silence() runs on test_CT {
1576 var RslChannelNr chan_nr;
1577
1578 f_init(1);
1579
1580 /* Request for a dedicated channel */
1581 chan_nr := f_chreq_act_ack('23'O);
1582
1583 /* Wait some time until the channel is released */
1584 f_sleep(2.0);
1585
1586 /* Expect CHANnel RELease */
1587 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001588 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001589 log("Received CHANnel RELease");
1590 setverdict(pass);
1591 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001592 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001593 /* See OS#3709, OsmoBSC should not send Immediate
1594 * Assignment Reject since a dedicated channel was
1595 * already allocated, and Immediate Assignment was
1596 * already sent. */
1597 setverdict(fail, "Unexpected Immediate Assignment!");
1598 }
1599 [] IPA_RSL[0].receive {
1600 setverdict(fail, "Unexpected RSL message!");
1601 }
1602 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001603 f_shutdown_helper();
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001604}
1605
Harald Weltecfe2c962017-12-15 12:09:32 +01001606/***********************************************************************
1607 * Assignment Testing
1608 ***********************************************************************/
1609
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001610/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction,
1611 * except for the inter-BSC handover, MT side) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001612testcase TC_outbound_connect(integer bssap_idx := 0) runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +01001613 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +01001614
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001615 BSSAP.send(ts_BSSAP_CONNECT_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
1616 2342, ts_BSSMAP_AssignmentReq));
Harald Weltecfe2c962017-12-15 12:09:32 +01001617 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001618 f_shutdown_helper();
Harald Weltecfe2c962017-12-15 12:09:32 +01001619}
1620
Harald Welte16a4adf2017-12-14 18:54:01 +01001621/* Test behavior if MSC answers with CREF to CR */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001622testcase TC_assignment_cic_only(integer bssap_idx := 0) runs on test_CT {
Harald Welte16a4adf2017-12-14 18:54:01 +01001623 var BSSAP_N_CONNECT_ind rx_c_ind;
1624 var RSL_Message rx_rsl;
1625 var DchanTuple dt;
1626
Harald Welte89d42e82017-12-17 16:42:41 +01001627 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +01001628
1629 dt := f_est_dchan('23'O, 23, '00000000'O);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001630 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte17b27da2018-05-25 20:33:53 +02001631 /* send assignment without AoIP IEs */
1632 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
1633 } else {
1634 /* Send assignmetn without CIC in IPA case */
1635 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
1636 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
1637 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
1638 }
Harald Welte16a4adf2017-12-14 18:54:01 +01001639 alt {
1640 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1641 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
1642 }
Harald Welte235ebf12017-12-15 14:18:16 +01001643 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +01001644 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1645 setverdict(pass);
1646 }
1647 [] BSSAP.receive { repeat; }
1648 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001649 f_perform_clear_test_ct(dt);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001650 f_shutdown_helper();
Harald Welte16a4adf2017-12-14 18:54:01 +01001651}
1652
Harald Welteed848512018-05-24 22:27:58 +02001653/* generate an assignment request for either AoIP or SCCPlite */
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001654function f_gen_ass_req(boolean osmux_enabled := false, integer bssap_idx := 0, charstring aoip_tla := "1.2.3.4") return PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +02001655 var PDU_BSSAP ass_cmd;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001656 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001657 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welteed848512018-05-24 22:27:58 +02001658 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001659 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001660 if (osmux_enabled) {
1661 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla, osmux_cid));
1662 } else {
1663 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
1664 }
Harald Welteed848512018-05-24 22:27:58 +02001665 } else {
1666 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001667 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
Harald Welteed848512018-05-24 22:27:58 +02001668 }
1669 return ass_cmd;
1670}
1671
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02001672function f_gen_handover_req(integer bssap_idx := 0, charstring aoip_tla := "1.2.3.4",
Pau Espin Pedrola8ef3be2022-02-16 16:21:17 +01001673 template (value) BSSMAP_IE_CellIdentifier cell_id_source := ts_CellID_LAC_CI(1, 1),
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001674 template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit,
1675 template (omit) TestHdlrEncrParams enc := omit) return PDU_BSSAP {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001676 var PDU_BSSAP ho_req;
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001677
1678 var BSSMAP_IE_EncryptionInformation encryptionInformation :=
1679 valueof(ts_BSSMAP_IE_EncrInfo('0000000000000000'O,'01'O));
Vadim Yanitskiy35c9a332022-03-16 20:26:35 +03001680 var template (omit) BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm := omit;
1681 var template (omit) BSSMAP_IE_KC128 kc128 := omit;
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001682 if (ispresent(enc)) {
1683 var TestHdlrEncrParams v_enc := valueof(enc);
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01001684 encryptionInformation := valueof(ts_BSSMAP_IE_EncrInfo(v_enc.enc_key, v_enc.enc_alg_permitted));
1685 if (ispresent(v_enc.enc_alg_chosen)) {
1686 chosenEncryptionAlgorithm := valueof(
1687 ts_BSSMAP_IE_ChosenEncryptionAlgorithm(int2oct(enum2int(
1688 f_cipher_mode_bssmap_to_rsl(v_enc.enc_alg_chosen)), 1)));
1689 }
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001690 if (ispresent(v_enc.enc_kc128)) {
1691 kc128 := ts_BSSMAP_IE_Kc128(v_enc.enc_kc128);
1692 }
1693 }
1694
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001695 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001696 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001697 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Pau Espin Pedrola8ef3be2022-02-16 16:21:17 +01001698 ho_req := valueof(ts_BSSMAP_HandoverRequest(omit, tla,
1699 cell_id_source := cell_id_source,
1700 oldToNewBSSIEs := oldToNewBSSIEs,
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001701 encryptionInformation := encryptionInformation,
1702 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
Neels Hofmeyr9fe13202022-03-04 00:05:43 +01001703 kC128 := kc128,
1704 /* on AoIP, allow "all" codecs (until we add more concise
1705 * tests) */
1706 codecList := ts_BSSMAP_IE_CodecList(
1707 {ts_CodecAMR_F, ts_CodecAMR_H,
1708 ts_CodecEFR, ts_CodecFR, ts_CodecHR})));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001709 } else {
1710 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrola8ef3be2022-02-16 16:21:17 +01001711 ho_req := valueof(ts_BSSMAP_HandoverRequest(cic, omit,
1712 cell_id_source := cell_id_source,
1713 oldToNewBSSIEs := oldToNewBSSIEs,
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001714 encryptionInformation := encryptionInformation,
1715 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
1716 kC128 := kc128));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001717 }
1718 return ho_req;
1719}
1720
Harald Welteed848512018-05-24 22:27:58 +02001721/* generate an assignment complete template for either AoIP or SCCPlite */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001722function f_gen_exp_compl(boolean expect_osmux := false, integer bssap_idx := 0) return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +02001723 var template PDU_BSSAP exp_compl;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001724 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001725 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001726 if (expect_osmux) {
1727 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, osmux_cid);
1728 } else {
1729 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, omit);
1730 }
Harald Welteed848512018-05-24 22:27:58 +02001731 } else {
1732 /* CIC is optional "*" as the MSC allocated it */
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001733 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
Harald Welteed848512018-05-24 22:27:58 +02001734 }
1735 return exp_compl;
1736}
1737
Harald Welte235ebf12017-12-15 14:18:16 +01001738/* Run everything required up to sending a caller-specified assignment command and expect response */
1739function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001740runs on test_CT return DchanTuple {
Harald Welte235ebf12017-12-15 14:18:16 +01001741 var BSSAP_N_CONNECT_ind rx_c_ind;
1742 var RSL_Message rx_rsl;
1743 var DchanTuple dt;
1744
Harald Welte89d42e82017-12-17 16:42:41 +01001745 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +01001746
1747 dt := f_est_dchan('23'O, 23, '00000000'O);
1748 /* send assignment without AoIP IEs */
1749 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
1750 alt {
1751 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1752 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
1753 setverdict(pass);
1754 } else {
1755 setverdict(fail, fail_text);
1756 }
1757 }
1758 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1759 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
1760 setverdict(pass);
1761 } else {
1762 setverdict(fail, fail_text);
1763 }
1764 }
1765 [] BSSAP.receive { repeat; }
1766 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001767 return dt;
Harald Welte235ebf12017-12-15 14:18:16 +01001768}
1769testcase TC_assignment_csd() runs on test_CT {
1770 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001771 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001772 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1773 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001774 var DchanTuple dt := f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
1775 f_perform_clear_test_ct(dt);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001776 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001777}
1778
1779testcase TC_assignment_ctm() runs on test_CT {
1780 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001781 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001782 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
1783 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001784 var DchanTuple dt := f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
1785 f_perform_clear_test_ct(dt);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001786 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001787}
1788
Harald Welte4003d112017-12-09 22:35:39 +01001789type record DchanTuple {
1790 integer sccp_conn_id,
1791 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +01001792}
1793
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +02001794type record of DchanTuple DchanTuples;
1795
Harald Welted6939652017-12-13 21:02:46 +01001796/* Send CHAN RQD and wait for allocation; acknowledge it */
1797private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
1798runs on test_CT return RslChannelNr {
1799 var RSL_Message rx_rsl;
1800 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1801 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1802 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1803 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
Daniel Willmannf4ac4ce2018-08-02 14:06:30 +02001804 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Harald Welted6939652017-12-13 21:02:46 +01001805 return chan_nr;
1806}
1807
Harald Welte4003d112017-12-09 22:35:39 +01001808/* helper function to establish a dedicated channel via BTS and MSC */
1809function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1810runs on test_CT return DchanTuple {
1811 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +01001812 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001813
Harald Welte4003d112017-12-09 22:35:39 +01001814 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001815 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +01001816
1817 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1818
1819 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1820 dt.sccp_conn_id := rx_c_ind.connectionId;
1821 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1822
1823 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001824}
1825
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02001826/* Like f_est_dchan(), but for the first lchan of a dynamic timeslot: first ACK the deactivation of PDCH. */
1827function f_est_dchan_dyn(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1828runs on test_CT return DchanTuple {
1829 var BSSAP_N_CONNECT_ind rx_c_ind;
1830 var DchanTuple dt;
1831
1832 /* Send CHAN RQD */
1833 var RSL_Message rx_rsl;
1834 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1835
1836 /* The dyn TS first deactivates PDCH */
1837 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1838 dt.rsl_chan_nr := rx_rsl.ies[0].body.chan_nr;
1839 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1840
1841 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1842 dt.rsl_chan_nr := rx_rsl.ies[0].body.chan_nr;
1843
1844 /* Now activates the signalling channel */
1845 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, fn+10));
1846 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
1847
1848 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1849
1850 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1851 dt.sccp_conn_id := rx_c_ind.connectionId;
1852 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1853
1854 return dt;
1855}
1856
Harald Welte641fcbe2018-06-14 10:58:35 +02001857/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
1858private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
1859 var RSL_Message rx_rsl;
1860 /* expect BSC to disable the channel */
1861 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1862 /* respond with CHAN REL ACK */
1863 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1864
1865 /* expect Clear Complete from BSC */
1866 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1867
1868 /* MSC disconnects as instructed. */
1869 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1870}
1871
Harald Welte4003d112017-12-09 22:35:39 +01001872/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
1873testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001874 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001875 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +01001876
Harald Welte89d42e82017-12-17 16:42:41 +01001877 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +01001878
Harald Welte4003d112017-12-09 22:35:39 +01001879 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1880
1881 /* simulate RLL REL IND */
1882 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
1883
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001884 /* expect Clear Request on MSC side */
1885 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1886
1887 /* Instruct BSC to clear channel */
1888 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1889 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1890
Harald Welte4003d112017-12-09 22:35:39 +01001891 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001892 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001893
1894 /* wait for SCCP emulation to do its job */
1895 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +01001896
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001897 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001898}
1899
1900/* Test behavior of channel release after CONN FAIL IND from BTS */
1901testcase TC_chan_rel_conn_fail() runs on test_CT {
1902 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001903 var DchanTuple dt;
1904
Harald Welte89d42e82017-12-17 16:42:41 +01001905 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001906
1907 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1908
1909 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +01001910 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 +01001911 /* TODO: different cause values? */
1912
Harald Welte4003d112017-12-09 22:35:39 +01001913 /* expect Clear Request from BSC */
1914 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1915
1916 /* Instruct BSC to clear channel */
1917 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1918 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1919
Harald Welte6ff76ea2018-01-28 13:08:01 +01001920 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001921 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +01001922
1923 /* wait for SCCP emulation to do its job */
1924 f_sleep(1.0);
1925
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001926 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001927}
1928
Harald Welte99f3ca02018-06-14 13:40:29 +02001929/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
1930/* See also https://www.osmocom.org/issues/3182 */
1931testcase TC_early_conn_fail() runs on test_CT {
1932 var RSL_Message rx_rsl;
1933 var DchanTuple dt;
1934
1935 f_init(1);
1936
1937 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
Harald Weltec46ea3c2020-10-10 18:46:12 +02001938 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_ra_cs(), 23);
Harald Welte99f3ca02018-06-14 13:40:29 +02001939
1940 /* BTS->BSC: simulate CONN FAIL IND */
1941 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1942
1943 /* BTS->BSC: Expect RF channel release from BSC on Abis */
1944 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1945
1946 /* BTS<-BSC: respond with CHAN REL ACK */
1947 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1948
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001949 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001950}
1951
1952/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
1953/* See also https://www.osmocom.org/issues/3182 */
1954testcase TC_late_conn_fail() runs on test_CT {
1955 var RSL_Message rx_rsl;
1956 var DchanTuple dt;
1957
1958 f_init(1);
1959
1960 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1961
1962 /* BSC<-MSC: Instruct BSC to clear connection */
1963 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
1964
1965 /* BTS->BSC: expect BSC to deactivate SACCH */
1966 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
1967
1968 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
1969 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1970
1971 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
1972 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1973 /* BTS->BSC: respond with CHAN REL ACK */
1974 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1975
1976 /* BSC->MSC: expect Clear Complete from BSC */
1977 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1978
1979 /* BSC<-MSC: MSC disconnects as requested. */
1980 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1981
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001982 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001983}
1984
Oliver Smithaf03bef2021-08-24 15:34:51 +02001985private function f_TC_stats_conn_fail(charstring id) runs on MSC_ConnHdlr {
1986 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
1987 var PDU_BSSAP ass_cmd := f_gen_ass_req();
1988
1989 f_statsd_reset();
1990
1991 /* Establish SDCCH */
1992 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1993 f_establish_fully(ass_cmd, exp_fail);
1994
1995 /* Expect stats to be 0 */
1996 var StatsDExpects expect := {
1997 {name := "TTCN3.bts.0.chan.rf_fail", mtype := "c", min := 0, max := 0},
1998 {name := "TTCN3.bts.0.chan.rf_fail_sdcch", mtype := "c", min := 0, max := 0}
1999 };
2000 f_statsd_expect(expect);
2001
2002 /* Simulate CONN FAIL IND on SDCCH */
2003 RSL.send(ts_ASP_RSL_UD(
2004 ts_RSL_CONN_FAIL_IND(g_chan_nr, RSL_ERR_RADIO_LINK_FAIL),
2005 IPAC_PROTO_RSL_TRX0));
2006
Neels Hofmeyr58be48a2021-09-07 18:39:21 +02002007 f_sleep(1.0);
2008
Oliver Smithaf03bef2021-08-24 15:34:51 +02002009 /* Expect stats to be 1 */
2010 expect := {
2011 {name := "TTCN3.bts.0.chan.rf_fail", mtype := "c", min := 1, max := 1},
2012 {name := "TTCN3.bts.0.chan.rf_fail_sdcch", mtype := "c", min := 1, max := 1}
2013 };
2014 f_statsd_expect(expect);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01002015 BSSAP.receive(tr_BSSMAP_ClearRequest);
2016 f_perform_clear();
Oliver Smithaf03bef2021-08-24 15:34:51 +02002017}
2018testcase TC_stats_conn_fail() runs on test_CT {
2019 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2020 var MSC_ConnHdlr vc_conn;
2021
2022 f_init(1, true);
2023 f_sleep(1.0);
2024
2025 vc_conn := f_start_handler(refers(f_TC_stats_conn_fail), pars);
2026 vc_conn.done;
2027
2028 f_shutdown_helper();
2029}
2030
Neels Hofmeyrf44ccd12018-11-05 19:15:23 +01002031function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr,
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002032 boolean expect_deact_sacch := true,
2033 boolean expect_rr_chan_rel := true,
2034 boolean expect_rll_rel_req := true,
Harald Welte99787102019-02-04 10:41:36 +01002035 boolean handle_rll_rel := true,
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002036 template CellSelIndValue expect_cells := omit,
Vadim Yanitskiybc7c35a2022-03-16 19:50:06 +03002037 template (present) RR_Cause expect_rr_cause := ?
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002038 ) runs on test_CT {
Harald Welte91d54a52018-01-28 15:35:07 +01002039
2040 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002041 var boolean got_deact_sacch := false;
2042 var boolean got_rr_chan_rel := false;
2043 var boolean got_rll_rel_req := false;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002044 var ASP_RSL_Unitdata ud;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002045 var RSL_IE_Body l3_ie;
2046 var PDU_ML3_NW_MS l3;
2047 var RR_Cause got_cause;
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002048 log("f_expect_chan_rel() expecting: expect_deact_sacch=", expect_deact_sacch, " expect_rr_chan_rel=", expect_rr_chan_rel,
2049 " expect_rll_rel_req=", expect_rll_rel_req);
Harald Welte91d54a52018-01-28 15:35:07 +01002050 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002051 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002052 got_deact_sacch := true;
Harald Welte91d54a52018-01-28 15:35:07 +01002053 repeat;
2054 }
Vadim Yanitskiya25fe232022-03-16 19:56:19 +03002055 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_DATA_REQ(rsl_chan_nr, ?, decmatch tr_RRM_RR_RELEASE))) -> value ud {
Harald Welte99787102019-02-04 10:41:36 +01002056 got_rr_chan_rel := true;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002057
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002058 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
2059 setverdict(fail, "cannot find L3");
2060 mtc.stop;
2061 }
2062 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
2063
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002064 if (not istemplatekind(expect_cells, "omit")) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002065 var CellSelIndValue cells := dec_CellSelIndValue(
2066 l3.msgs.rrm.channelRelease.cellSelectionIndicator.cellSelectionIndicatorValue);
2067
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002068 log("GOT RR CHANNEL RELEASE WITH CELLS: ", cells);
2069 if (match(cells, expect_cells)) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002070 setverdict(pass);
2071 } else {
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002072 log("EXPECTED CELLS: ", expect_cells);
2073 setverdict(fail, "Received cells list on RR Channel Release does not match expectations");
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002074 }
2075 }
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002076
Vadim Yanitskiybc7c35a2022-03-16 19:50:06 +03002077 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
2078 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
2079 if (match(got_cause, expect_rr_cause)) {
2080 setverdict(pass);
2081 } else {
2082 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
2083 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002084 }
Harald Welte99787102019-02-04 10:41:36 +01002085 repeat;
2086 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002087 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002088 got_rll_rel_req := true;
Harald Welte91d54a52018-01-28 15:35:07 +01002089 /* FIXME: Why are we getting this for LinkID SACCH? */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002090 if (handle_rll_rel) {
2091 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
2092 }
Harald Welte91d54a52018-01-28 15:35:07 +01002093 repeat;
2094 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002095 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Harald Welte91d54a52018-01-28 15:35:07 +01002096 /* respond with CHAN REL ACK */
2097 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
2098 }
2099 /* ignore any user data */
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002100 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeR(?))) {
Harald Welte91d54a52018-01-28 15:35:07 +01002101 repeat;
2102 }
2103 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002104
2105 log("f_expect_chan_rel() summary: got_deact_sacch=", got_deact_sacch, " got_rr_chan_rel=", got_rr_chan_rel,
2106 " got_rll_rel_req=", got_rll_rel_req);
2107
2108 if (expect_deact_sacch != got_deact_sacch) {
2109 setverdict(fail, "f_expect_chan_rel(): expect_deact_sacch=", expect_deact_sacch, " got_deact_sacch=", got_deact_sacch);
2110 }
2111 if (expect_rr_chan_rel != got_rr_chan_rel) {
2112 setverdict(fail, "f_expect_chan_rel(): expect_rr_chan_rel=", expect_rr_chan_rel, " got_rr_chan_rel=", got_rr_chan_rel);
2113 }
2114 if (expect_rll_rel_req != got_rll_rel_req) {
2115 setverdict(fail, "f_expect_chan_rel(): expect_rll_rel_req=", expect_rll_rel_req, " got_rll_rel_req=", got_rll_rel_req);
2116 }
Harald Welte91d54a52018-01-28 15:35:07 +01002117}
2118
Harald Welte4003d112017-12-09 22:35:39 +01002119/* Test behavior of channel release after hard Clear Command from MSC */
2120testcase TC_chan_rel_hard_clear() runs on test_CT {
2121 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01002122 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +01002123
Harald Welte89d42e82017-12-17 16:42:41 +01002124 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002125
2126 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2127
2128 /* Instruct BSC to clear channel */
2129 var BssmapCause cause := 0;
2130 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2131
2132 /* expect Clear Complete from BSC on A */
2133 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2134 /* release the SCCP connection */
2135 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2136 }
2137
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002138 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002139 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002140}
2141
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002142function f_TC_chan_rel_last_eutran_plmn_hard_clear(boolean tx_csfb_ind) runs on test_CT {
2143 var BSSAP_N_DATA_ind rx_di;
2144 var DchanTuple dt;
2145
2146 f_init(1);
2147
2148 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2149 /* Send CommonID with some random PLMN (BSC doesn't take it into account
2150 /* yet when generating the EUTRAN neigh list in RR CHannel Release) */
2151 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
2152
2153 /* Instruct BSC to clear channel */
2154 var BssmapCause cause := 0;
2155 if (tx_csfb_ind) {
2156 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2157 } else {
2158 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2159 }
2160
2161 /* expect Clear Complete from BSC on A */
2162 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2163 /* release the SCCP connection */
2164 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2165 }
2166
2167 /* 1 neighbor is added by default in osmo-bts.cfg and
2168 SystemInformationConfig_default, use that: */
2169 var template CellSelIndValue exp_cells := f_tr_rr_chan_rel_earfcns(1);
2170
2171 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, expect_cells := exp_cells);
2172 f_shutdown_helper();
2173}
2174
2175/* Test behavior of RR Channel rRelease after Clear Command without CSFB indicator
2176 from MSC, previously receiving any CommonID containing the "Last Used E-UTRAN
2177 PLMN Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
2178 EUTRAN neighbor list sent later on by BSC in RR Channel, so receiving CSFB
2179 Indicator or not shouldn't matter at all. */
2180testcase TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() runs on test_CT {
2181 f_TC_chan_rel_last_eutran_plmn_hard_clear(false);
2182}
2183
2184/* Test behavior of RR Channel rRelease after Clear Command with CSFB indicator from
2185 MSC, previously receiving any CommonID containing the "Last Used E-UTRAN PLMN
2186 Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
2187 EUTRAN neighbor list sent later on by BSC in RR Channel. */
2188testcase TC_chan_rel_last_eutran_plmn_hard_clear_csfb() runs on test_CT {
2189 f_TC_chan_rel_last_eutran_plmn_hard_clear(true);
2190}
2191
2192/* Test behavior of RR Channel Release after Clear Command with CSFB indicator from
2193 MSC, without receiving any CommonID containing the "Last Used E-UTRAN PLMN
2194 Id". According to spec (TS 48.008 version 16.0.0 Release 16 "3.2.1.21") the
2195 CSFB Indicator should not be used anymore, and hence, there should be no
2196 EUTRAN neighbor list sent by BSC in RR Channel release since no CommonId with
2197 Last Used E-UTRAN PLMN Id" IE was sent for this conn. */
Harald Welte99787102019-02-04 10:41:36 +01002198testcase TC_chan_rel_hard_clear_csfb() runs on test_CT {
2199 var BSSAP_N_DATA_ind rx_di;
2200 var DchanTuple dt;
2201
2202 f_init(1);
2203
2204 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2205
2206 /* Instruct BSC to clear channel */
2207 var BssmapCause cause := 0;
2208 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2209
2210 /* expect Clear Complete from BSC on A */
2211 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2212 /* release the SCCP connection */
2213 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2214 }
2215
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002216 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002217 f_shutdown_helper();
Harald Welte99787102019-02-04 10:41:36 +01002218}
2219
Harald Welted8c36cd2017-12-09 23:05:31 +01002220/* Test behavior of channel release after hard RLSD from MSC */
2221testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +01002222 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +01002223
Harald Welte89d42e82017-12-17 16:42:41 +01002224 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +01002225
2226 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2227
2228 /* release the SCCP connection */
2229 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2230
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002231 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002232 f_shutdown_helper();
Harald Welted8c36cd2017-12-09 23:05:31 +01002233}
2234
Harald Welte550daf92018-06-11 19:22:13 +02002235/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
2236testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
2237 var DchanTuple dt;
2238
2239 f_init(1);
2240
2241 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2242
2243 /* release the SCCP connection */
2244 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2245
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002246 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002247 f_shutdown_helper();
Harald Welte550daf92018-06-11 19:22:13 +02002248}
2249
Harald Welte85804d42017-12-10 14:11:58 +01002250/* Test behavior of channel release after BSSMAP RESET from MSC */
2251testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +01002252 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +01002253
Harald Welte89d42e82017-12-17 16:42:41 +01002254 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +01002255
2256 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2257
2258 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
2259 IPA_RSL[0].clear;
2260
2261 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002262 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[0].sccp_addr_peer, g_bssap[0].sccp_addr_own, ts_BSSMAP_Reset(0, g_osmux_enabled)));
Harald Welte85804d42017-12-10 14:11:58 +01002263 interleave {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002264 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap[0].sccp_addr_own, g_bssap[0].sccp_addr_peer, tr_BSSMAP_ResetAck(g_osmux_enabled))) { }
Harald Welte85804d42017-12-10 14:11:58 +01002265 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
2266 }
2267
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002268 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002269 f_shutdown_helper();
Harald Welte85804d42017-12-10 14:11:58 +01002270}
2271
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002272/* Verify T(iar) triggers and releases the channel */
2273testcase TC_chan_rel_sccp_tiar_timeout() runs on test_CT {
2274 var DchanTuple dt;
2275
2276 /* Set T(iar) in BSC low enough that it will trigger before other side
2277 has time to keep alive with a T(ias). Keep recommended ratio of
2278 T(iar) >= T(ias)*2 */
2279 g_bsc_sccp_timer_ias := 2;
2280 g_bsc_sccp_timer_iar := 5;
2281
2282 f_init(1);
2283
2284 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2285 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002286 f_shutdown_helper();
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002287}
2288
Vadim Yanitskiybc7c35a2022-03-16 19:50:06 +03002289private function f_tc_chan_rel_rr_cause(myBSSMAP_Cause clear_cmd_cause,
2290 template (present) RR_Cause expect_rr_cause)
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002291runs on test_CT
2292{
2293 var DchanTuple dt;
2294
2295 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2296 var BssmapCause cause := 0;
2297 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(enum2int(clear_cmd_cause))));
2298 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2299 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2300 }
2301
2302 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, expect_rr_cause := expect_rr_cause);
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002303}
2304
2305/* Test that Clear Command cause codes affect the RR Channel Release cause code */
2306testcase TC_chan_rel_rr_cause() runs on test_CT {
2307 f_init(1);
2308
2309 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_CALL_CONTROL, GSM48_RR_CAUSE_NORMAL);
2310 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_HANDOVER_SUCCESSFUL, GSM48_RR_CAUSE_NORMAL);
2311 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_PREEMPTION, GSM48_RR_CAUSE_PREMPTIVE_REL);
2312 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE, GSM48_RR_CAUSE_PROT_ERROR_UNSPC);
2313 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
2314 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_EQUIPMENT_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
Vadim Yanitskiye18aebb2021-01-03 13:10:43 +01002315
2316 f_shutdown_helper();
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002317}
2318
Harald Welte5cd20ed2017-12-13 21:03:20 +01002319/* Test behavior if RSL EST IND for non-active channel */
2320testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
2321 timer T := 2.0;
2322
Harald Welte89d42e82017-12-17 16:42:41 +01002323 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002324
2325 var octetstring l3 := '00010203040506'O;
2326 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2327 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
2328
2329 T.start;
2330 alt {
2331 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2332 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
2333 }
2334 [] BSSAP.receive {}
2335 [] IPA_RSL[0].receive {}
2336 [] T.timeout {}
2337 }
2338
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002339 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002340}
2341
2342/* Test behavior if RSL EST IND for invalid SAPI */
2343testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
2344 var RslChannelNr chan_nr;
2345
Harald Welte89d42e82017-12-17 16:42:41 +01002346 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002347
2348 chan_nr := f_chreq_act_ack()
2349
2350 var octetstring l3 := '00010203040506'O;
2351 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
2352
2353 timer T := 2.0;
2354 T.start;
2355 alt {
2356 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2357 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
2358 }
2359 [] BSSAP.receive { repeat; }
2360 [] IPA_RSL[0].receive { repeat; }
2361 [] T.timeout {}
2362 }
2363
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002364 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002365}
2366
2367/* Test behavior if RSL EST IND for invalid SAPI */
2368testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
2369 timer T := 2.0;
2370
Harald Welte89d42e82017-12-17 16:42:41 +01002371 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002372
2373 var RslChannelNr chan_nr := f_chreq_act_ack();
2374
2375 var octetstring l3 := '00010203040506'O;
2376 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
2377
2378 T.start;
2379 alt {
2380 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2381 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
2382 }
2383 [] BSSAP.receive { repeat; }
2384 [] IPA_RSL[0].receive { repeat; }
2385 [] T.timeout {}
2386 }
2387
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002388 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002389}
2390
2391/* Test behavior if RSL EST IND for invalid SACCH */
2392testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
2393 timer T := 2.0;
2394
Harald Welte89d42e82017-12-17 16:42:41 +01002395 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002396
2397 var RslChannelNr chan_nr := f_chreq_act_ack();
2398
2399 var octetstring l3 := '00010203040506'O;
2400 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
2401
2402 T.start;
2403 alt {
2404 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2405 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
2406 }
2407 [] BSSAP.receive { repeat; }
2408 [] IPA_RSL[0].receive { repeat; }
2409 [] T.timeout {}
2410 }
2411
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002412 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002413}
2414
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002415/* Verify DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
2416private function f_TC_tch_dlci_link_id_sapi(charstring id) runs on MSC_ConnHdlr {
2417 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2418 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2419
2420 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2421 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2422
2423 f_establish_fully(ass_cmd, exp_compl);
2424
2425 /* SAPI0 has already been established by f_establish_fully(), establish SAPI3 */
2426 RSL.send(ts_RSL_EST_IND(g_chan_nr, ts_RslLinkID_SACCH(3), '0904'O));
2427 /* Expect BSSAP/DTAP on SAPI3 (DLCI IE) */
2428 BSSAP.receive(PDU_BSSAP:{
2429 discriminator := '1'B,
2430 spare := '0000000'B,
2431 dlci := 'C3'O,
2432 lengthIndicator := ?,
2433 pdu := { dtap := '0904'O }
2434 });
2435
2436 /* Send messages on DCCH/SAPI0 and ACCH/SAPI3 */
2437 for (var integer i := 0; i < 32; i := i + 1) {
2438 var octetstring l3 := '09'O & f_rnd_octstring(14);
2439 var template (value) RslLinkId link_id;
2440 var template (value) OCT1 dlci;
2441
2442 if (i mod 2 == 0) {
2443 /* SAPI0 on FACCH or SDCCH */
2444 link_id := ts_RslLinkID_DCCH(0);
2445 dlci := '80'O;
2446 } else {
2447 /* SAPI3 on SACCH */
2448 link_id := ts_RslLinkID_SACCH(3);
2449 dlci := 'C3'O;
2450 }
2451
2452 /* Send MO message: RSL -> BSSAP */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002453 f_mo_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002454 /* Send MT message: BSSAP -> RSL */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002455 f_mt_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002456 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01002457 f_perform_clear();
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002458}
2459testcase TC_tch_dlci_link_id_sapi() runs on test_CT {
2460 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2461 var MSC_ConnHdlr vc_conn;
2462
2463 f_init(1, true);
2464 f_sleep(1.0);
2465
2466 vc_conn := f_start_handler(refers(f_TC_tch_dlci_link_id_sapi), pars);
2467 vc_conn.done;
2468
2469 f_shutdown_helper();
2470}
2471
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002472private function f_exp_sapi_n_reject(template (present) GsmSapi sapi := ?,
Vadim Yanitskiy35c9a332022-03-16 20:26:35 +03002473 template (present) myBSSMAP_Cause cause := ?,
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002474 template (present) BIT2 cc := ?,
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002475 float T_val := 2.0)
2476runs on test_CT {
2477 var BSSAP_N_DATA_ind rx_di;
2478 timer T;
2479
Vadim Yanitskiy35c9a332022-03-16 20:26:35 +03002480 var template (present) BSSMAP_IE_Cause tr_cause := tr_BSSMAP_IE_Cause(cause);
2481 var template (present) PDU_BSSAP tr_pdu := tr_BSSMAP_SAPInReject(sapi);
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002482
2483 T.start(T_val);
2484 alt {
2485 [] BSSAP.receive(tr_BSSAP_DATA_ind(?, tr_pdu)) -> value rx_di {
2486 var BSSMAP_IE_Cause rx_cause := rx_di.userData.pdu.bssmap.sAPInReject.cause;
2487 if (not match(rx_cause, tr_cause)) {
2488 setverdict(fail, "Rx unexpected Cause IE: ",
2489 rx_cause, " vs expected ", tr_cause);
2490 }
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002491
2492 /* Who ever on the earth decided to define this field as two separate bits?!? */
2493 var BIT2 rx_cc := rx_di.userData.pdu.bssmap.sAPInReject.dLCI.c2
2494 & rx_di.userData.pdu.bssmap.sAPInReject.dLCI.c1;
2495 if (not match(rx_cc, cc)) {
2496 setverdict(fail, "Rx unexpected Control Channel type: ",
2497 rx_cc, " vs expected ", cc);
2498 }
2499
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002500 setverdict(pass);
2501 }
2502 [] BSSAP.receive(BSSAP_N_DATA_ind:?) -> value rx_di {
2503 setverdict(fail, "Rx unexpected BSSAP PDU: ", rx_di);
2504 }
2505 [] T.timeout {
2506 setverdict(fail, "Timeout waiting for BSSMAP SAPI N Reject");
2507 }
2508 }
2509}
2510
2511/* Check if we get SAPI N Reject on receipt of unexpected RLL RELease INDication */
2512testcase TC_rll_rel_ind_sapi_n_reject() runs on test_CT {
2513 var octetstring rnd_data := f_rnd_octstring(16);
2514 var RSL_Message rx_rsl;
2515 var DchanTuple dt;
2516
2517 f_init(1);
2518
2519 /* MS establishes a SAPI=0 link on DCCH */
2520 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2521
2522 /* MSC sends some data on (not yet established) SAPI=3 link */
2523 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2524 /* BSC attempts to establish a SAPI=3 link on DCCH */
2525 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2526
2527 /* MS sends unexpected RELease INDication on SAPI=3 */
2528 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3)));
2529 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2530 f_exp_sapi_n_reject(3, GSM0808_CAUSE_MS_NOT_EQUIPPED);
2531
2532 /* Clean up the connection */
2533 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2534 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2535
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002536 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002537}
2538
2539/* Check if we get SAPI N Reject on receipt of unexpected RLL ERROR INDication */
2540testcase TC_rll_err_ind_sapi_n_reject() runs on test_CT {
2541 var octetstring rnd_data := f_rnd_octstring(16);
2542 var RSL_Message rx_rsl;
2543 var DchanTuple dt;
2544
2545 f_init(1);
2546
2547 /* MS establishes a SAPI=0 link on DCCH */
2548 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2549
2550 /* MSC sends some data on (not yet established) SAPI=3 link */
2551 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2552 /* BSC attempts to establish a SAPI=3 link on DCCH */
2553 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2554
2555 /* BTS sends unexpected ERROR INDication on SAPI=3 */
2556 f_ipa_tx(0, ts_RSL_ERROR_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3), ''O));
2557 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2558 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED);
2559
2560 /* Clean up the connection */
2561 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2562 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2563
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002564 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002565}
2566
2567/* Check if we get SAPI N Reject due to a SAPI=3 link establishment timeout */
2568testcase TC_rll_timeout_sapi_n_reject() runs on test_CT {
2569 var octetstring rnd_data := f_rnd_octstring(16);
2570 var RSL_Message rx_rsl;
2571 var DchanTuple dt;
2572
2573 f_init(1);
2574
2575 /* MS establishes a SAPI=0 link on DCCH */
2576 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2577
2578 /* MSC sends some data on (not yet established) SAPI=3 link */
2579 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2580 /* BSC attempts to establish a SAPI=3 link on DCCH */
2581 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2582
2583 /* MS does not respond, so the link establishment timeout triggers SAPI N Reject */
2584 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED, T_val := 8.0);
2585
2586 /* Clean up the connection */
2587 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2588 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2589
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002590 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002591}
2592
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002593/* Check DLCI CC (Control Channel type) bits in SAPI N Reject */
2594testcase TC_rll_sapi_n_reject_dlci_cc() runs on test_CT {
2595 var octetstring rnd_data := f_rnd_octstring(16);
2596 var RSL_Message rx_rsl;
2597 var DchanTuple dt;
2598
2599 f_init(1);
2600
2601 /* MS establishes a SAPI=0 link on DCCH */
2602 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2603
2604 /* MSC sends some data on (not yet established) SAPI=3 link */
2605 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2606 /* BSC attempts to establish a SAPI=3 link on DCCH */
2607 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2608
2609 /* MS sends unexpected ERROR INDication on DCCH/ACCH SAPI=3 */
2610 f_ipa_tx(0, ts_RSL_ERROR_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3), ''O));
Pau Espin Pedrol121f27f2022-01-12 12:02:10 +01002611 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED, '10'B);
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002612
2613 /* Clean up the connection */
2614 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2615 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2616
2617 f_shutdown_helper();
2618}
2619
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002620testcase TC_si_default() runs on test_CT {
2621 f_init(0);
2622 f_init_bts_and_check_sysinfo(0, expect_si := SystemInformationConfig_default);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002623 f_shutdown_helper();
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002624}
Harald Welte4003d112017-12-09 22:35:39 +01002625
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002626/* We're testing SI2quater with lists of EARFCNs. Instead of just incrementing EARFCNs, also pick some from the edges of
2627 * the entire value range. This function provides the same EARFCN numbers for the same earfcn_index */
2628private function f_test_si2quater_earfcn_by_idx(integer earfcn_index) return uint16_t
2629{
2630 select (earfcn_index) {
2631 case (0) {
2632 /* E-ARFCN 111 is already added in the osmo-bsc.cfg */
2633 return 111;
2634 }
2635 case (1) {
2636 return 1;
2637 }
2638 case (2) {
2639 return 0;
2640 }
2641 case (3) {
2642 return 65535;
2643 }
2644 case else {
2645 return 23 * (earfcn_index - 3);
2646 }
2647 }
2648}
2649
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002650function f_test_si2quater(integer total_earfcns, template SystemInformationConfig expect_si,
2651 template CellSelIndValue expect_cells := omit) runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002652
2653 f_init(0);
2654
2655 /* E-ARFCN 111 is already added in the osmo-bsc.cfg, so only add more arfcns if total_earfcns > 1 */
2656 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002657 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2658 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002659 }
2660
2661 f_init_bts_and_check_sysinfo(0, expect_si := expect_si);
2662
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002663 if (not istemplatekind(expect_cells, "omit")) {
2664 /* Also check that RR Channel Release contains these EARFCNs.
2665 * (copied code from TC_chan_rel_hard_clear_csfb) */
2666 var BSSAP_N_DATA_ind rx_di;
2667 var DchanTuple dt;
2668
2669 dt := f_est_dchan('23'O, 23, '00010203040506'O);
Pau Espin Pedrold0046312021-04-19 16:35:58 +02002670 /* Send CommonID with some random PLMN (BSC doesn't take it into account
2671 * yet when generating the EUTRAN neigh list in RR CHannel Release) */
2672 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002673
2674 /* Instruct BSC to clear channel */
2675 var BssmapCause cause := 0;
2676 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2677
2678 /* expect Clear Complete from BSC on A */
2679 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2680 /* release the SCCP connection */
2681 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2682 }
2683
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002684 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, expect_cells := expect_cells);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002685 }
2686
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002687 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002688 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list del earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))});
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002689 }
2690}
2691
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002692private function f_tr_si2quater_earfcns(integer count) return template SI2quaterRestOctetsList
2693{
2694 var template SI2quaterRestOctetsList si2quater := {};
2695 var integer si2quater_count := (count + 2) / 3;
2696
2697 for (var integer i := 0; i < count; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002698 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002699 var integer index := i / 3;
2700 var integer earfcn_index := i mod 3;
2701 if (index >= lengthof(si2quater)) {
2702 si2quater[index] := tr_SI2quaterRestOctets_EUTRAN(index := index, count := si2quater_count - 1);
2703 }
2704 si2quater[index].rel_additions.rel5.rel6.rel7.rel8.prio_eutran_params_desc.desc.eutran_params_desc.desc.repeated_neigh_cells[0].cell_desc_list[earfcn_index] := tr_EUTRAN_CellDesc_default(e_arfcn := earfcn);
2705 }
2706
2707 return si2quater;
2708}
2709
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002710private function f_tr_rr_chan_rel_earfcns(integer count) return template CellSelIndValue
2711{
2712 var template CellSelIndValue_EUTRAN_Descrs cells := {};
2713
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002714 /* the lte neighbors must match the config & vty to pass this test */
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002715 for (var integer i := 0; i < count; i := i + 1) {
2716 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002717 cells[i] := tr_CellSelIndValue_EUTRAN_Descr(earfcn, '1'B, 3);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002718 }
2719
2720 return tr_CellSelIndValue_EUTRAN(cells);
2721}
2722
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002723private function f_tc_si2quater_n_earfcns(integer n) runs on test_CT
2724{
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002725 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrol8ab62e42020-12-18 16:19:11 +01002726 sic.si2quater := f_tr_si2quater_earfcns(n);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002727 var template CellSelIndValue cells := f_tr_rr_chan_rel_earfcns(n);
2728 f_test_si2quater(n, sic, cells);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002729}
2730
2731testcase TC_si2quater_2_earfcns() runs on test_CT {
2732 f_tc_si2quater_n_earfcns(2);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002733 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002734}
2735
2736testcase TC_si2quater_3_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002737 f_tc_si2quater_n_earfcns(3);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002738 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002739}
2740
2741testcase TC_si2quater_4_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002742 f_tc_si2quater_n_earfcns(4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002743 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002744}
2745
2746testcase TC_si2quater_5_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002747 f_tc_si2quater_n_earfcns(5);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002748 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002749}
2750
2751testcase TC_si2quater_6_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002752 f_tc_si2quater_n_earfcns(6);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002753 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002754}
2755
2756testcase TC_si2quater_12_earfcns() runs on test_CT {
2757 f_tc_si2quater_n_earfcns(12);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002758 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002759}
2760
2761testcase TC_si2quater_23_earfcns() runs on test_CT {
2762 f_tc_si2quater_n_earfcns(23);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002763 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002764}
2765
2766testcase TC_si2quater_32_earfcns() runs on test_CT {
2767 f_tc_si2quater_n_earfcns(32);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002768 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002769}
2770
2771testcase TC_si2quater_33_earfcns() runs on test_CT {
2772 f_tc_si2quater_n_earfcns(33);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002773 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002774}
2775
2776testcase TC_si2quater_42_earfcns() runs on test_CT {
2777 f_tc_si2quater_n_earfcns(42);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002778 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002779}
2780
2781testcase TC_si2quater_48_earfcns() runs on test_CT {
2782 f_tc_si2quater_n_earfcns(48);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002783 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002784}
2785
2786/* verify the VTY error response when adding too many EARFCNs, and showing that osmo-bsc still sends 16 SI2quater with
2787 * 48 EARFCNs. */
2788testcase TC_si2quater_49_earfcns() runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002789 var template SystemInformationConfig sic := SystemInformationConfig_default;
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002790 sic.si2quater := f_tr_si2quater_earfcns(48); /* 48, not 49! */
2791 f_init(0);
2792
2793 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002794 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2795 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002796 }
2797
2798 /* The 49th EARFCN no longer fits, expect VTY error */
2799 f_vty_enter_cfg_bts(BSCVTY, 0);
2800 var charstring vty_error;
2801 vty_error := f_vty_transceive_ret(BSCVTY,
2802 "si2quater neighbor-list add earfcn 70 thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3")
2803 f_vty_transceive(BSCVTY, "end");
2804
2805 if (f_strstr(vty_error, "Unable to add ARFCN 70") >= 0) {
2806 log("Got expected VTY error: ", vty_error);
2807 setverdict(pass);
2808 } else {
2809 setverdict(fail, "Expected the 49th EUTRAN ARFCN to be rejected by vty config, got: ", vty_error);
2810 }
2811
2812 f_init_bts_and_check_sysinfo(0, expect_si := sic);
2813
2814 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002815 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list del earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))});
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002816 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002817 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002818}
2819
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002820private function f_acc09_count_allowed(AccessControlClass acc) return uint8_t
2821{
2822 var uint8_t count := 0;
2823 for (var integer i := 5; i < 16; i := i + 1) {
2824 if (acc[i] == '0'B) { /* the list marks barred, we count allowed */
2825 count := count + 1;
2826 }
2827 }
2828 return count;
2829}
2830
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002831private function f_recv_next_si1(integer rsl_idx := 0) runs on test_CT return SystemInformationType1
2832{
2833 var ASP_RSL_Unitdata rx_rsl_ud;
2834 var SystemInformationType1 last_si1;
2835
2836 timer T := 30.0;
2837 T.start;
2838 alt {
2839 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD((tr_RSL_NO_BCCH_INFO,
2840 tr_RSL_BCCH_INFO,
2841 tr_RSL_NO_SACCH_FILL,
2842 tr_RSL_SACCH_FILL))
2843 ) -> value rx_rsl_ud {
2844 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
2845 if (g_system_information[rsl_idx].si1 == omit) {
2846 repeat;
2847 }
2848 last_si1 := g_system_information[rsl_idx].si1;
2849 g_system_information[rsl_idx].si1 := omit;
2850 T.stop;
2851 }
Vadim Yanitskiy79ebd5e2021-01-04 00:12:55 +01002852 [] IPA_RSL[rsl_idx].receive { repeat; }
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002853 [] T.timeout { setverdict(fail, "Timeout receiving next SI1"); }
2854 }
2855 return last_si1;
2856}
2857
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002858/* verify ACC rotate feature */
2859testcase TC_si_acc_rotate() runs on test_CT {
2860 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002861 var SystemInformationType1 last_si1;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002862 var AccessControlClass acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002863 var uint8_t count;
2864 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2865
2866 f_init(0, guard_timeout := 60.0);
2867
2868 f_bts_0_cfg(BSCVTY, {"rach access-control-class 5 barred",
2869 "access-control-class-rotate 3",
2870 "access-control-class-rotate-quantum 1"});
2871
2872 /* Init and get first sysinfo */
2873 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2874
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002875 for (var integer i:= 0; i < 20; i := i + 1) {
2876 last_si1 := f_recv_next_si1(0);
2877 acc := last_si1.rach_control.acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002878 count := f_acc09_count_allowed(acc);
2879 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2880
2881 if (count != 3) {
2882 log("RSL: EXPECTED SI ACC len=3");
2883 setverdict(fail, "received SI does not match expectations");
2884 break;
2885 }
2886
2887 for (var integer j := 0; j < 10; j := j + 1) {
2888 if (acc[16 - 1 - j] == '0'B) { /* the list marks barred, we count allowed */
2889 times_allowed[j] := times_allowed[j] + 1;
2890 }
2891 }
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002892 }
2893
2894 for (var integer j := 0; j < 10; j := j + 1) {
2895 log("ACC", j, " allowed ", times_allowed[j], " times" );
2896 if (j != 5 and times_allowed[j] < 3) {
2897 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " < 1 times");
2898 } else if (j == 5 and times_allowed[j] > 0) {
2899 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " > 0 times");
2900 }
2901 }
2902
2903 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2904 "rach access-control-class 5 allowed"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002905 f_shutdown_helper();
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002906}
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002907
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002908/* verify ACC startup ramp+rotate feature */
2909testcase TC_si_acc_ramp_rotate() runs on test_CT {
2910 var template SystemInformationConfig sic := SystemInformationConfig_default;
2911 var SystemInformationType1 last_si1;
2912 var AccessControlClass acc;
2913 var ASP_RSL_Unitdata rx_rsl_ud;
2914 var uint8_t count;
2915 var uint8_t prev_count;
2916 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2917
2918 f_init(0, guard_timeout := 80.0);
2919
2920 f_bts_0_cfg(BSCVTY, {"rach access-control-class 4 barred",
2921 "access-control-class-rotate 0",
2922 "access-control-class-rotate-quantum 1",
2923 "access-control-class-ramping",
2924 "access-control-class-ramping-step-interval 5",
2925 "access-control-class-ramping-step-size 5"});
2926
2927 /* Init and get first sysinfo */
2928 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2929 last_si1 := g_system_information[0].si1;
2930 acc := last_si1.rach_control.acc;
2931 count := f_acc09_count_allowed(acc);
2932 /* Adm subset size was set to 0 above, so wait until all ACC are barred */
2933 while (count > 0) {
2934 last_si1 := f_recv_next_si1(0);
2935 acc := last_si1.rach_control.acc;
2936 count := f_acc09_count_allowed(acc);
2937 log("RSL: wait len()=0: GOT SI1 ACC len=", count, ": ", acc);
2938 }
2939
2940 /* Increase adm subset size, we should see ramping start up */
2941 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10"});
2942 prev_count := 0;
2943 while (true) {
2944 last_si1 := f_recv_next_si1(0);
2945 acc := last_si1.rach_control.acc;
2946 count := f_acc09_count_allowed(acc);
2947 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2948
2949 if (prev_count > count) {
2950 setverdict(fail, "ACC allowed count dropped while expecting grow: ", prev_count, " -> ", count);
2951 break;
2952 }
2953
2954 if (count == 9) {
2955 break; /* Maximum reached (10 - 1 perm barred), done here */
2956 }
2957
2958 prev_count := count;
2959 }
2960
2961 setverdict(pass);
2962
2963 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2964 "rach access-control-class 4 allowed",
2965 "no access-control-class-ramping"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002966 f_shutdown_helper();
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002967}
2968
Harald Welte4003d112017-12-09 22:35:39 +01002969testcase TC_ctrl_msc_connection_status() runs on test_CT {
2970 var charstring ctrl_resp;
2971
Harald Welte89d42e82017-12-17 16:42:41 +01002972 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002973
2974 /* See https://osmocom.org/issues/2729 */
2975 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002976 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002977}
2978
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002979testcase TC_ctrl_msc0_connection_status() runs on test_CT {
2980 var charstring ctrl_resp;
2981
2982 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002983
2984 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002985 f_shutdown_helper();
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002986}
2987
Neels Hofmeyr0bc470d2021-08-21 13:37:13 +02002988/* Verify correct stats on the number of configured and connected MSCs */
2989private function f_tc_stat_num_msc_connected_msc_connhdlr(integer expect_num_msc_connected) runs on MSC_ConnHdlr {
2990 g_pars := f_gen_test_hdlr_pars();
2991 var StatsDExpects expect := {
2992 { name := "TTCN3.bsc.0.num_msc.connected", mtype := "g", min := expect_num_msc_connected, max := expect_num_msc_connected },
2993 { name := "TTCN3.bsc.0.num_msc.total", mtype := "g", min := NUM_MSC, max := NUM_MSC }
2994 };
2995 f_statsd_expect(expect);
2996}
2997
2998private function f_tc_stat_num_msc_connected_test_ct(void_fn tc_fn, integer nr_msc) runs on test_CT
2999{
3000 var MSC_ConnHdlr vc_conn;
3001
3002 f_init(nr_bts := 1, handler_mode := true, nr_msc := nr_msc);
3003 f_sleep(1.0);
3004 vc_conn := f_start_handler(tc_fn);
3005 vc_conn.done;
3006
3007 /* Also verify stat exposed on CTRL interface */
3008 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_msc:connected", int2str(nr_msc));
3009 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_msc:total", int2str(NUM_MSC));
3010
3011 f_shutdown_helper();
3012}
3013
3014/* Verify that when 1 MSC is active, that num_msc:connected reports 1. */
3015private function f_tc_stat_num_msc_connected_1(charstring id) runs on MSC_ConnHdlr {
3016 f_tc_stat_num_msc_connected_msc_connhdlr(1);
3017}
3018testcase TC_stat_num_msc_connected_1() runs on test_CT {
3019 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_1), 1);
3020}
3021
3022/* Verify that when 2 MSCs are active, that num_msc:connected reports 2. */
3023private function f_tc_stat_num_msc_connected_2(charstring id) runs on MSC_ConnHdlr {
3024 f_tc_stat_num_msc_connected_msc_connhdlr(2);
3025}
3026testcase TC_stat_num_msc_connected_2() runs on test_CT {
3027 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_2), 2);
3028}
3029
3030/* Verify that when 3 MSCs are active, that num_msc:connected reports 3. */
3031private function f_tc_stat_num_msc_connected_3(charstring id) runs on MSC_ConnHdlr {
3032 f_tc_stat_num_msc_connected_msc_connhdlr(3);
3033}
3034testcase TC_stat_num_msc_connected_3() runs on test_CT {
3035 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_3), 3);
3036}
3037
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +02003038/* Verify correct stats on the number of configured and connected MSCs */
3039private function f_tc_stat_num_bts_connected_msc_connhdlr(integer expect_num_bts_connected) runs on MSC_ConnHdlr {
3040 g_pars := f_gen_test_hdlr_pars();
3041 var StatsDExpects expect := {
3042 { name := "TTCN3.bsc.0.num_bts.oml_connected", mtype := "g", min := expect_num_bts_connected, max := NUM_BTS_CFG },
3043 { name := "TTCN3.bsc.0.num_bts.all_trx_rsl_connected", mtype := "g", min := expect_num_bts_connected, max := expect_num_bts_connected },
3044 { name := "TTCN3.bsc.0.num_bts.total", mtype := "g", min := NUM_BTS_CFG, max := NUM_BTS_CFG },
3045 { name := "TTCN3.bsc.0.num_trx.rsl_connected", mtype := "g", min := expect_num_bts_connected, max := expect_num_bts_connected },
3046 { name := "TTCN3.bsc.0.num_trx.total", mtype := "g", min := NUM_BTS_CFG, max := NUM_BTS_CFG }
3047 };
3048 f_statsd_expect(expect);
3049}
3050
3051private function f_tc_stat_num_bts_connected_test_ct(void_fn tc_fn, integer nr_bts) runs on test_CT {
3052 var MSC_ConnHdlr vc_conn;
3053
3054 f_init(nr_bts := nr_bts, handler_mode := true, nr_msc := 1);
3055 f_sleep(1.0);
3056 vc_conn := f_start_handler(tc_fn);
3057 vc_conn.done;
3058
3059 /* Also verify stat exposed on CTRL interface */
3060 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_bts:all_trx_rsl_connected", int2str(nr_bts));
3061 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_bts:total", int2str(NUM_BTS_CFG));
3062 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_trx:rsl_connected", int2str(nr_bts));
3063 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_trx:total", int2str(NUM_BTS_CFG));
3064
Neels Hofmeyra41ae302021-09-06 22:06:02 +02003065 /* Verify rf_states exposed on CTRL interface */
3066 var charstring expect_net_rf_states := "";
3067 for (var integer i := 0; i < NUM_BTS_CFG; i := i + 1) {
3068 var charstring expect_bts_rf_states := int2str(i) & ",0,";
3069 if (i < NUM_BTS) {
3070 /* In these tests, OML for the first NUM_BTS are always connected via osmo-bts-omldummy */
3071 expect_bts_rf_states := expect_bts_rf_states & "operational,unlocked,";
3072 } else {
3073 /* For remaining i < NUM_BTS_CFG, OML is not connected, i.e. inoperational */
3074 expect_bts_rf_states := expect_bts_rf_states & "inoperational,locked,";
3075 }
3076 /* The RF policy is still global in osmo-bsc, i.e. always "on" */
3077 expect_bts_rf_states := expect_bts_rf_states & "on,";
3078 if (i < nr_bts) {
3079 /* For BTS where RSL is connected, the RSL state will be "up" */
3080 expect_bts_rf_states := expect_bts_rf_states & "rsl-up;";
3081 } else {
3082 expect_bts_rf_states := expect_bts_rf_states & "rsl-down;";
3083 }
3084
3085 f_ctrl_get_exp(IPA_CTRL, "bts." & int2str(i) & ".rf_states", expect_bts_rf_states);
3086 expect_net_rf_states := expect_net_rf_states & expect_bts_rf_states;
3087 }
3088 f_ctrl_get_exp(IPA_CTRL, "rf_states", expect_net_rf_states);
3089
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +02003090 f_shutdown_helper();
3091}
3092
3093/* Verify that when 1 BTS is connected, that num_{bts,trx}:*_connected reports 1. */
3094private function f_tc_stat_num_bts_connected_1(charstring id) runs on MSC_ConnHdlr {
3095 f_tc_stat_num_bts_connected_msc_connhdlr(1);
3096}
3097testcase TC_stat_num_bts_connected_1() runs on test_CT {
3098 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_1), 1);
3099}
3100
3101/* Verify that when 2 BTS is connected, that num_{bts,trx}:*_connected reports 2. */
3102private function f_tc_stat_num_bts_connected_2(charstring id) runs on MSC_ConnHdlr {
3103 f_tc_stat_num_bts_connected_msc_connhdlr(2);
3104}
3105testcase TC_stat_num_bts_connected_2() runs on test_CT {
3106 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_2), 2);
3107}
3108
3109/* Verify that when 3 BTS is connected, that num_{bts,trx}:*_connected reports 3. */
3110private function f_tc_stat_num_bts_connected_3(charstring id) runs on MSC_ConnHdlr {
3111 f_tc_stat_num_bts_connected_msc_connhdlr(3);
3112}
3113testcase TC_stat_num_bts_connected_3() runs on test_CT {
3114 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_3), 3);
3115}
3116
Harald Welte4003d112017-12-09 22:35:39 +01003117testcase TC_ctrl() runs on test_CT {
3118 var charstring ctrl_resp;
3119
Harald Welte89d42e82017-12-17 16:42:41 +01003120 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01003121
3122 /* all below values must match the osmo-bsc.cfg config file used */
3123
Harald Welte6a129692018-03-17 17:30:14 +01003124 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
3125 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Oliver Smith75aa0202019-08-19 14:17:50 +02003126 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "4");
Harald Welte4003d112017-12-09 22:35:39 +01003127
3128 var integer bts_nr := 0;
3129 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
3130 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
3131 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
3132 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
3133 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
3134 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
3135 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
3136
3137 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
3138 f_sleep(2.0);
3139 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
3140 setverdict(fail, "oml-uptime not incrementing as expected");
3141 }
3142 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
3143
3144 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
3145
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003146 f_shutdown_helper();
Harald Welte96c94412017-12-09 03:12:45 +01003147}
3148
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02003149/* Verify that Upon receival of SET "location", BSC forwards a TRAP
3150 "location-state" over the SCCPlite IPA conn */
3151testcase TC_ctrl_location() runs on test_CT {
3152 var MSC_ConnHdlr vc_conn;
3153 var integer bts_nr := 0;
3154
3155 f_init(1, true);
3156 f_sleep(1.0);
3157
3158 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234567,fix3d,0.340000,0.560000,0.780000");
3159 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
3160 "1234567,fix3d,0.340000,0.560000,0.780000,operational,unlocked,on,001,01");
3161
3162 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "1");
3163 f_sleep(2.0);
3164
3165 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234888,fix3d,0.350000,0.570000,0.790000");
3166 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
3167 "1234888,fix3d,0.350000,0.570000,0.790000,operational,locked,off,001,01");
3168
3169 /* should match the one from config */
3170 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "0");
3171
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003172 f_shutdown_helper();
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02003173}
3174
Harald Welte6f521d82017-12-11 19:52:02 +01003175
3176/***********************************************************************
3177 * Paging Testing
3178 ***********************************************************************/
3179
3180type record Cell_Identity {
3181 GsmMcc mcc,
3182 GsmMnc mnc,
3183 GsmLac lac,
3184 GsmCellId ci
3185};
Harald Welte24135bd2018-03-17 19:27:53 +01003186private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01003187private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01003188
Harald Welte5d1a2202017-12-13 19:51:29 +01003189type set of integer BtsIdList;
3190
3191private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
3192 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
3193 if (bts_id == bts_ids[j]) {
3194 return true;
3195 }
3196 }
3197 return false;
3198}
Harald Welte6f521d82017-12-11 19:52:02 +01003199
3200/* core paging test helper function; used by most paging test cases */
3201private function f_pageing_helper(hexstring imsi,
3202 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01003203 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01003204 template RSL_ChanNeeded rsl_chneed := omit,
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003205 template (omit) OCT4 tmsi := omit) runs on test_CT
Harald Welte6f521d82017-12-11 19:52:02 +01003206{
3207 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003208 var template MobileIdentityV mi;
Harald Welte6f521d82017-12-11 19:52:02 +01003209 var RSL_Message rx_rsl;
3210 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01003211 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01003212
3213 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01003214
3215 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01003216 for (i := 0; i < NUM_BTS; i := i + 1) {
3217 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01003218 }
Harald Welte6f521d82017-12-11 19:52:02 +01003219
3220 if (isvalue(rsl_chneed)) {
3221 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
3222 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
3223 } else {
3224 bssmap_chneed := omit;
3225 }
3226
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003227 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[0].sccp_addr_peer, g_bssap[0].sccp_addr_own,
3228 ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed)));
Harald Welte6f521d82017-12-11 19:52:02 +01003229
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003230 if (not istemplatekind(tmsi, "omit")) {
3231 mi := t_MI_TMSI(tmsi);
Harald Welte6f521d82017-12-11 19:52:02 +01003232 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003233 mi := tr_MI_IMSI(imsi);
Harald Welte6f521d82017-12-11 19:52:02 +01003234 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003235
Harald Welte5d1a2202017-12-13 19:51:29 +01003236 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003237 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(mi));
Harald Welte5d1a2202017-12-13 19:51:29 +01003238 /* check channel type, paging group */
3239 if (rx_rsl.ies[1].body.paging_group != paging_group) {
3240 setverdict(fail, "Paging for wrong paging group");
3241 }
3242 if (ispresent(rsl_chneed) and
3243 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
3244 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
3245 }
Harald Welte6f521d82017-12-11 19:52:02 +01003246 }
Harald Welte2fccd982018-01-31 15:48:19 +01003247 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01003248 /* do a quick check on all not-included BTSs if they received paging */
3249 for (i := 0; i < NUM_BTS; i := i + 1) {
3250 timer T := 0.1;
3251 if (f_bts_in_list(i, bts_ids)) {
3252 continue;
3253 }
3254 T.start;
3255 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003256 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(mi))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003257 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
3258 }
3259 [] IPA_RSL[i].receive { repeat; }
3260 [] T.timeout { }
3261 }
Harald Welte6f521d82017-12-11 19:52:02 +01003262 }
3263
3264 setverdict(pass);
3265}
3266
Harald Welte5d1a2202017-12-13 19:51:29 +01003267const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01003268const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01003269const BtsIdList c_BtsId_LAC1 := { 0, 1 };
3270const BtsIdList c_BtsId_LAC2 := { 2 };
3271
Harald Welte6f521d82017-12-11 19:52:02 +01003272/* PAGING by IMSI + TMSI */
3273testcase TC_paging_imsi_nochan() runs on test_CT {
3274 var BSSMAP_FIELD_CellIdentificationList cid_list;
3275 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01003276 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003277 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003278}
3279
3280/* PAGING by IMSI + TMSI */
3281testcase TC_paging_tmsi_nochan() runs on test_CT {
3282 var BSSMAP_FIELD_CellIdentificationList cid_list;
3283 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003284 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003285 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003286}
3287
3288/* Paging with different "channel needed' values */
3289testcase TC_paging_tmsi_any() runs on test_CT {
3290 var BSSMAP_FIELD_CellIdentificationList cid_list;
3291 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003292 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003293 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003294}
3295testcase TC_paging_tmsi_sdcch() runs on test_CT {
3296 var BSSMAP_FIELD_CellIdentificationList cid_list;
3297 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003298 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003299 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003300}
3301testcase TC_paging_tmsi_tch_f() runs on test_CT {
3302 var BSSMAP_FIELD_CellIdentificationList cid_list;
3303 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003304 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003305 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003306}
3307testcase TC_paging_tmsi_tch_hf() runs on test_CT {
3308 var BSSMAP_FIELD_CellIdentificationList cid_list;
3309 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003310 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003311 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003312}
3313
3314/* Paging by CGI */
3315testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
3316 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3317 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003318 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003319 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003320}
3321
3322/* Paging by LAC+CI */
3323testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
3324 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3325 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003326 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003327 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003328}
3329
3330/* Paging by CI */
3331testcase TC_paging_imsi_nochan_ci() runs on test_CT {
3332 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3333 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003334 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003335 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003336}
3337
3338/* Paging by LAI */
3339testcase TC_paging_imsi_nochan_lai() runs on test_CT {
3340 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3341 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003342 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003343 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003344}
3345
3346/* Paging by LAC */
3347testcase TC_paging_imsi_nochan_lac() runs on test_CT {
3348 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3349 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003350 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003351 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003352}
3353
3354/* Paging by "all in BSS" */
3355testcase TC_paging_imsi_nochan_all() runs on test_CT {
3356 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3357 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01003358 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003359 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003360}
3361
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003362/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003363testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
3364 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3365 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 +01003366 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003367 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003368}
Harald Welte6f521d82017-12-11 19:52:02 +01003369
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003370/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003371testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
3372 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3373 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003374 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003375 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003376}
3377
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003378/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003379testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
3380 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3381 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003382 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003383 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003384}
3385
Harald Welte6f521d82017-12-11 19:52:02 +01003386/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01003387testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
3388 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3389 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
3390 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003391 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003392}
3393
3394/* Paging on empty list: Verify none of them page */
3395testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
3396 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3397 cid_list := { cIl_LAC := { } };
3398 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003399 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003400}
3401
Stefan Sperling049a86e2018-03-20 15:51:00 +01003402/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
3403testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
3404 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3405 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
3406 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
3407 f_shutdown_helper();
3408}
3409
Harald Welte6f521d82017-12-11 19:52:02 +01003410/* Verify paging retransmission interval + count */
3411/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01003412/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01003413
Harald Weltee65d40e2017-12-13 00:09:06 +01003414/* Verify PCH load */
3415testcase TC_paging_imsi_load() runs on test_CT {
3416 var BSSMAP_FIELD_CellIdentificationList cid_list;
3417 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01003418 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01003419 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003420 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01003421
3422 /* tell BSC there is no paging space anymore */
3423 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01003424 f_sleep(0.2);
3425 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01003426
3427 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
3428 * there would be 8 retransmissions during 4 seconds */
3429 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01003430 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01003431 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003432 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Weltee65d40e2017-12-13 00:09:06 +01003433 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02003434 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01003435 }
Harald Welte2caa1062018-03-17 18:19:05 +01003436 [] T_retrans.timeout {
3437 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
3438 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
3439 T_retrans.start;
3440 repeat;
3441 }
Harald Weltee65d40e2017-12-13 00:09:06 +01003442 [] T.timeout {
3443 setverdict(pass);
3444 }
3445 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003446
3447 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01003448}
3449
Harald Welte235ebf12017-12-15 14:18:16 +01003450/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01003451testcase TC_paging_counter() runs on test_CT {
3452 var BSSMAP_FIELD_CellIdentificationList cid_list;
3453 timer T := 4.0;
3454 var integer i;
3455 var integer paging_attempted_bsc;
3456 var integer paging_attempted_bts[NUM_BTS];
Oliver Smith8b343d32021-11-26 13:01:42 +01003457 var integer paging_expired_bsc;
Harald Welte1ff69992017-12-14 12:31:17 +01003458 var integer paging_expired_bts[NUM_BTS];
3459 cid_list := valueof(ts_BSSMAP_CIL_noCell);
3460
3461 f_init();
3462
3463 /* read counters before paging */
3464 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
Oliver Smith8b343d32021-11-26 13:01:42 +01003465 if (Misc_Helpers.f_osmo_repo_is("nightly")) { /* osmo-bsc > 1.8.0 */
3466 paging_expired_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:expired");
3467 }
Harald Welte1ff69992017-12-14 12:31:17 +01003468 for (i := 0; i < NUM_BTS; i := i+1) {
3469 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
3470 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
3471 }
3472
3473 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
3474
3475 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
3476 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
3477 for (i := 0; i < NUM_BTS; i := i+1) {
3478 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
3479 paging_attempted_bts[i]+1);
3480 }
3481
3482 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
3483 f_sleep(12.0);
Oliver Smith8b343d32021-11-26 13:01:42 +01003484 if (Misc_Helpers.f_osmo_repo_is("nightly")) { /* osmo-bsc > 1.8.0 */
3485 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:expired", paging_expired_bsc+1);
3486 }
Harald Welte1ff69992017-12-14 12:31:17 +01003487 for (i := 0; i < NUM_BTS; i := i+1) {
3488 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
3489 paging_expired_bts[i]+1);
3490 }
Harald Welte1ff69992017-12-14 12:31:17 +01003491
Philipp Maier282ca4b2018-02-27 17:17:00 +01003492 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01003493}
3494
3495
Harald Welte10985002017-12-12 09:29:15 +01003496/* Verify paging stops after A-RESET */
3497testcase TC_paging_imsi_a_reset() runs on test_CT {
3498 var BSSMAP_FIELD_CellIdentificationList cid_list;
3499 timer T := 3.0;
3500 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003501 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01003502
3503 /* Perform a BSSMAP Reset and wait for ACK */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003504 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[0].sccp_addr_peer, g_bssap[0].sccp_addr_own, ts_BSSMAP_Reset(0, g_osmux_enabled)));
Harald Welte10985002017-12-12 09:29:15 +01003505 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003506 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap[0].sccp_addr_own, g_bssap[0].sccp_addr_peer, tr_BSSMAP_ResetAck(g_osmux_enabled))) { }
Harald Welte10985002017-12-12 09:29:15 +01003507 [] BSSAP.receive { repeat; }
3508 }
3509
Daniel Willmanncbef3982018-07-30 09:22:40 +02003510 /* Wait to avoid a possible race condition if a paging message is
3511 * received right before the reset ACK. */
3512 f_sleep(0.2);
3513
Harald Welte10985002017-12-12 09:29:15 +01003514 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01003515 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
3516 IPA_RSL[i].clear;
3517 }
Harald Welte10985002017-12-12 09:29:15 +01003518
3519 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
3520 T.start;
3521 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003522 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte10985002017-12-12 09:29:15 +01003523 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003524 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01003525 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003526 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003527 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003528 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003529 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003530 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003531 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003532 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003533 }
Harald Welte10985002017-12-12 09:29:15 +01003534 [] T.timeout {
3535 setverdict(pass);
3536 }
3537 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003538
3539 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01003540}
Harald Welteae026692017-12-09 01:03:01 +01003541
Philipp Maierf45824a2019-08-14 14:44:10 +02003542/* Verify how we handle unsolicited Paging Response. In case of an unsolicit
3543 * paging response we can not know which MSC is in charge, so we will blindly
3544 * pick the first configured MSC. This behavior is required in order to make
3545 * MT-CSFB calls working because in those cases the BSC can not know that the
3546 * MSC has already paged the subscriver via SGs. So any MT-CSFB call will look
3547 * like an unsolicited Paging Response to the MSC.
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003548 */
3549testcase TC_paging_resp_unsol() runs on test_CT {
3550
3551 f_init(1);
Philipp Maierf45824a2019-08-14 14:44:10 +02003552 timer T := 5.0;
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003553
3554 var BSSAP_N_CONNECT_ind rx_c_ind;
3555 var DchanTuple dt;
3556 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
Philipp Maierf45824a2019-08-14 14:44:10 +02003557 var octetstring rr_pag_resp := enc_PDU_ML3_MS_NW(l3);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003558
3559 /* Send CHAN RQD and wait for allocation; acknowledge it */
3560 dt.rsl_chan_nr := f_chreq_act_ack();
3561
3562 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
3563 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
3564
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003565
Philipp Maierf45824a2019-08-14 14:44:10 +02003566 /* Expevct a CR with a matching Paging response on the A-Interface */
3567 T.start;
3568 alt {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003569 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(rr_pag_resp))) -> value rx_c_ind {
Philipp Maierf45824a2019-08-14 14:44:10 +02003570 setverdict(pass);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003571 dt.sccp_conn_id := rx_c_ind.connectionId;
3572 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
Philipp Maierf45824a2019-08-14 14:44:10 +02003573 }
3574 [] BSSAP.receive {
3575 setverdict(fail, "Received unexpected message on A-Interface!");
3576 }
3577 [] T.timeout {
3578 setverdict(fail, "Received nothing on A-Interface!");
3579 }
3580 }
3581
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003582 f_perform_clear_test_ct(dt);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003583 f_shutdown_helper();
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003584}
3585
Pau Espin Pedrol09b9bad2022-04-21 18:48:08 +02003586/* Verify BSC can schedule 500 paging requests under one minute if BTS buffer is good enough */
3587testcase TC_paging_500req() runs on test_CT {
3588 var ASP_RSL_Unitdata rx_rsl_ud;
3589 const integer num_subscribers := 500;
3590 var hexstring imsis[num_subscribers];
3591 var boolean rx_paging_done[num_subscribers];
3592 var integer rx_paging_num := 0;
3593 var integer i;
3594 timer T_rx := 60.0;
3595 timer T_load_ind := 1.0;
3596
3597 for (i := 0; i < num_subscribers; i := i + 1) {
3598 imsis[i] := f_gen_imsi(i);
3599 rx_paging_done[i] := false;
3600 }
3601
3602 f_init(1, guard_timeout := 100.0);
3603
3604 /* Clear the queue, it might still contain stuff like BCCH FILLING */
3605 IPA_RSL[0].clear;
3606 /* Tell there's plenty of space at the BTS (UINT16_MAX): */
3607 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(65535));
3608
3609 for (i := 0; i < num_subscribers; i := i + 1) {
3610 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[0].sccp_addr_peer, g_bssap[0].sccp_addr_own,
3611 ts_BSSMAP_Paging(imsis[i], valueof(ts_BSSMAP_CIL_noCell), omit, omit)));
3612 }
3613
3614 T_rx.start;
3615 T_load_ind.start;
3616 alt {
3617 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?), IPAC_PROTO_RSL_TRX0)) -> value rx_rsl_ud {
3618 var hexstring imsi := rx_rsl_ud.rsl.ies[2].body.ms_identity.mobileIdentityV.oddEvenInd_identity.imsi.digits;
3619 var hexstring imsi_suffix := substr(imsi, lengthof(imsi)-6, 6);
3620 var charstring imsi_str := hex2str(imsi_suffix);
3621 var integer imsi_idx := str2int(imsi_str);
3622 if (rx_paging_done[imsi_idx] == false) {
3623 rx_paging_done[imsi_idx] := true;
3624 rx_paging_num := rx_paging_num + 1;
3625 }
3626 if (rx_paging_num < num_subscribers) {
3627 repeat;
3628 }
3629 }
3630 [] IPA_RSL[0].receive { repeat; }
3631 [] T_load_ind.timeout {
3632 log("Tx CCH Load Ind, received paging requests so far: ", rx_paging_num);
3633 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(40));
3634 T_load_ind.start;
3635 repeat;
3636 }
3637 [] T_rx.timeout {
3638 setverdict(fail, "Timeout expecting paging requests, so far ", rx_paging_num);
3639 mtc.stop;
3640 }
3641 }
3642
3643 f_shutdown_helper();
3644}
3645
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003646/* Test RSL link drop causes counter increment */
3647testcase TC_rsl_drop_counter() runs on test_CT {
3648 var integer rsl_fail;
3649
Harald Welte89d42e82017-12-17 16:42:41 +01003650 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003651
3652 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
3653
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +01003654 f_ipa_rsl_stop(bts[0].rsl);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003655
3656 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
3657
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003658 f_shutdown_helper();
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003659}
3660
3661/* TODO: Test OML link drop causes counter increment */
3662
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003663/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
3664function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
3665 timer T := 10.0;
3666
3667 bts[0].rsl.id := "IPA-0-RSL";
Harald Welte71389132021-12-09 21:58:18 +01003668 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA") alive;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003669 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
3670 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
Oliver Smith92c2bdb2019-08-20 15:11:24 +02003671 bts[0].rsl.ccm_pars.unit_id := "99/0/0"; /* value which is unknown at BTS */
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003672
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01003673 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003674
3675 f_init_mgcp("VirtMSC");
3676
3677 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
3678 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
3679 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
3680 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
3681
3682 /* wait for IPA OML link to connect and then disconnect */
3683 T.start;
3684 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +07003685 [] IPA_RSL[0].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) {
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003686 T.stop;
3687 return true;
3688 }
3689 [] IPA_RSL[0].receive { repeat }
3690 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02003691 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003692 }
3693 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003694 return false;
3695}
3696
3697/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3698testcase TC_rsl_unknown_unit_id() runs on test_CT {
3699 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
3700 setverdict(pass);
3701 } else {
3702 setverdict(fail, "Timeout RSL waiting for connection to close");
3703 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003704 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003705}
3706
3707
3708/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3709testcase TC_oml_unknown_unit_id() runs on test_CT {
3710 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
3711 setverdict(pass);
3712 } else {
3713 setverdict(fail, "Timeout OML waiting for connection to close");
3714 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003715 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003716}
3717
3718
Harald Weltec1a2fff2017-12-17 11:06:19 +01003719/***********************************************************************
Harald Welte6811d102019-04-14 22:23:14 +02003720 * "New world" test cases using RSL_Emulation + RAN_Emulation
Harald Weltec1a2fff2017-12-17 11:06:19 +01003721 ***********************************************************************/
3722
Harald Welte6811d102019-04-14 22:23:14 +02003723import from RAN_Emulation all;
Harald Welte47cd0e32020-08-21 12:39:11 +02003724import from BSSAP_LE_Emulation all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01003725import from RSL_Emulation all;
3726import from MSC_ConnectionHandler all;
3727
3728type function void_fn(charstring id) runs on MSC_ConnHdlr;
3729
Harald Welte336820c2018-05-31 20:34:52 +02003730/* helper function to create and connect a MSC_ConnHdlr component */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003731private function f_connect_handler(inout MSC_ConnHdlr vc_conn, integer bssap_idx := 0) runs on test_CT {
3732 connect(vc_conn:RAN, g_bssap[bssap_idx].vc_RAN:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01003733 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003734 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01003735 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01003736 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01003737 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
3738 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
3739 }
Neels Hofmeyr91401012019-07-11 00:42:35 +02003740 if (isvalue(bts[2])) {
3741 connect(vc_conn:RSL2, bts[2].rsl.vc_RSL:CLIENT_PT);
3742 connect(vc_conn:RSL2_PROC, bts[2].rsl.vc_RSL:RSL_PROC);
3743 }
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003744 connect(vc_conn:BSSAP, g_bssap[bssap_idx].vc_RAN:CLIENT);
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02003745 if (mp_enable_lcs_tests) {
3746 connect(vc_conn:BSSAP_LE, g_bssap_le.vc_BSSAP_LE:CLIENT);
3747 connect(vc_conn:BSSAP_LE_PROC, g_bssap_le.vc_BSSAP_LE:PROC);
3748 }
Daniel Willmann191e0d92018-01-17 12:44:35 +01003749 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02003750 connect(vc_conn:MGCP_MULTI, vc_MGCP:MGCP_CLIENT_MULTI);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003751 connect(vc_conn:STATSD_PROC, vc_STATSD:STATSD_PROC);
Harald Welte336820c2018-05-31 20:34:52 +02003752}
3753
Neels Hofmeyrda436782021-07-20 22:09:06 +02003754function f_start_handler_create(template (omit) TestHdlrParams pars := omit)
Harald Welte336820c2018-05-31 20:34:52 +02003755runs on test_CT return MSC_ConnHdlr {
3756 var charstring id := testcasename();
3757 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003758 var integer bssap_idx := 0;
3759 if (isvalue(pars)) {
3760 bssap_idx := valueof(pars).mscpool.bssap_idx;
3761 }
Harald Welte336820c2018-05-31 20:34:52 +02003762 vc_conn := MSC_ConnHdlr.create(id);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003763 f_connect_handler(vc_conn, bssap_idx);
Neels Hofmeyrda436782021-07-20 22:09:06 +02003764 return vc_conn;
3765}
3766
3767function f_start_handler_run(MSC_ConnHdlr vc_conn, void_fn fn, template (omit) TestHdlrParams pars := omit)
3768runs on test_CT return MSC_ConnHdlr {
3769 var charstring id := testcasename();
Harald Weltea0630032018-03-20 21:09:55 +01003770 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003771 return vc_conn;
3772}
3773
Neels Hofmeyrda436782021-07-20 22:09:06 +02003774function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
3775runs on test_CT return MSC_ConnHdlr {
3776 return f_start_handler_run(f_start_handler_create(pars), fn, pars);
3777}
3778
Harald Weltea0630032018-03-20 21:09:55 +01003779/* first function inside ConnHdlr component; sets g_pars + starts function */
3780private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
3781runs on MSC_ConnHdlr {
3782 if (isvalue(pars)) {
3783 g_pars := valueof(pars);
3784 }
3785 fn.apply(id);
3786}
3787
Oliver Smith26a3db72021-07-09 13:51:29 +02003788private function f_vty_encryption_a5(charstring options) runs on test_CT {
3789 f_vty_transceive(BSCVTY, "configure terminal");
3790 f_vty_transceive(BSCVTY, "network");
3791 f_vty_transceive(BSCVTY, "encryption a5 " & options);
3792 f_vty_transceive(BSCVTY, "exit");
3793 f_vty_transceive(BSCVTY, "exit");
3794}
3795
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01003796const charstring VTY_A5_DEFAULT := "0 1 3";
3797
Oliver Smith26a3db72021-07-09 13:51:29 +02003798private function f_vty_encryption_a5_reset() runs on test_CT {
3799 /* keep in sync with docker-playground.git ttcn3-bsc-test/osmo-bsc.cfg */
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01003800 f_vty_encryption_a5(VTY_A5_DEFAULT);
Oliver Smith26a3db72021-07-09 13:51:29 +02003801}
3802
Harald Welte3c86ea02018-05-10 22:28:05 +02003803/* Establish signalling channel (non-assignment case) followed by cipher mode */
3804private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003805 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3806 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02003807 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02003808 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
3809 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
3810 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
3811 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02003812
Philipp Maier23000732018-05-18 11:25:37 +02003813 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003814 f_perform_clear();
Harald Welte3c86ea02018-05-10 22:28:05 +02003815}
3816testcase TC_ciph_mode_a5_0() runs on test_CT {
3817 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003818 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003819 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
3820
3821 f_init(1, true);
3822 f_sleep(1.0);
3823 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3824 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003825 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003826}
3827testcase TC_ciph_mode_a5_1() runs on test_CT {
3828 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003829 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003830 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
3831
3832 f_init(1, true);
3833 f_sleep(1.0);
3834 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3835 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003836 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003837}
Oliver Smith50b98122021-07-09 15:00:28 +02003838/* OS#4975: verify that A5/2 is preferred over A5/0 */
3839testcase TC_ciph_mode_a5_2_0() runs on test_CT {
3840 var MSC_ConnHdlr vc_conn;
3841 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3842
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01003843 pars.encr := f_encr_params('05'O, '04'O); /* A5/0 and A5/2 (0x01|0x04)*/
Oliver Smith50b98122021-07-09 15:00:28 +02003844
3845 f_init(1, true);
3846 f_vty_encryption_a5("0 1 2 3");
3847 f_sleep(1.0);
3848 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3849 vc_conn.done;
3850 f_vty_encryption_a5_reset();
3851 f_shutdown_helper();
3852}
Oliver Smith1dff88d2021-07-09 08:45:51 +02003853/* OS#4975: verify that A5/1 is preferred over A5/2 */
3854testcase TC_ciph_mode_a5_2_1() runs on test_CT {
3855 var MSC_ConnHdlr vc_conn;
3856 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3857
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01003858 pars.encr := f_encr_params('06'O, '02'O); /* A5/1 and A5/2 (0x02|0x04)*/
Oliver Smith1dff88d2021-07-09 08:45:51 +02003859
3860 f_init(1, true);
3861 f_vty_encryption_a5("1 2");
3862 f_sleep(1.0);
3863 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3864 vc_conn.done;
3865 f_vty_encryption_a5_reset();
3866 f_shutdown_helper();
3867}
Harald Welte3c86ea02018-05-10 22:28:05 +02003868testcase TC_ciph_mode_a5_3() runs on test_CT {
3869 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003870 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003871 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
3872
3873 f_init(1, true);
3874 f_sleep(1.0);
3875 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3876 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003877 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003878}
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003879/* Establish a Signalling channel with A5/4 encryption. */
3880testcase TC_ciph_mode_a5_4() runs on test_CT {
3881 var MSC_ConnHdlr vc_conn;
3882 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3883 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Harald Welte3c86ea02018-05-10 22:28:05 +02003884
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003885 f_init(1, true);
Oliver Smith26a3db72021-07-09 13:51:29 +02003886 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003887 f_sleep(1.0);
3888 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3889 vc_conn.done;
Oliver Smith26a3db72021-07-09 13:51:29 +02003890 f_vty_encryption_a5_reset();
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003891 f_shutdown_helper();
3892}
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003893/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
3894private function f_tc_assignment_aoip_tla_v6(charstring id) runs on MSC_ConnHdlr {
3895 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3896 var PDU_BSSAP ass_cmd := f_gen_ass_req(aoip_tla := "::3");
3897 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3898 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3899
3900 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003901 f_perform_clear();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003902}
3903testcase TC_assignment_aoip_tla_v6() runs on test_CT {
3904 var MSC_ConnHdlr vc_conn;
3905 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3906
3907 f_init(1, true);
3908 f_sleep(1.0);
3909 vc_conn := f_start_handler(refers(f_tc_assignment_aoip_tla_v6), pars);
3910 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003911 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003912}
3913
Harald Welte3c86ea02018-05-10 22:28:05 +02003914
3915/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02003916private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003917 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3918 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003919
Harald Welte552620d2017-12-16 23:21:36 +01003920 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3921 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01003922
Harald Weltea0630032018-03-20 21:09:55 +01003923 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003924 f_perform_clear();
Harald Welte552620d2017-12-16 23:21:36 +01003925}
Harald Welte552620d2017-12-16 23:21:36 +01003926testcase TC_assignment_fr_a5_0() runs on test_CT {
3927 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003928 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003929 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01003930
Harald Welte89d42e82017-12-17 16:42:41 +01003931 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003932 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003933 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003934 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003935 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003936}
Harald Welte552620d2017-12-16 23:21:36 +01003937testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01003938 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003939 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003940 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003941
Harald Welte89d42e82017-12-17 16:42:41 +01003942 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003943 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003944 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3945 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003946 f_shutdown_helper();
Harald Welte651fcdc2018-05-10 20:23:16 +02003947}
3948testcase TC_assignment_fr_a5_3() runs on test_CT {
3949 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003950 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003951 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003952
Harald Welte651fcdc2018-05-10 20:23:16 +02003953 f_init(1, true);
3954 f_sleep(1.0);
3955 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003956 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003957 f_shutdown_helper();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003958}
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003959/* Establish a Signalling channel and re-assign to TCH/F with A5/4 encryption. */
3960testcase TC_assignment_fr_a5_4() runs on test_CT {
3961 var MSC_ConnHdlr vc_conn;
3962 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3963 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
3964
3965 f_init(1, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02003966 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003967 f_sleep(1.0);
3968 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3969 vc_conn.done;
Oliver Smith7eabd312021-07-12 14:18:56 +02003970 f_vty_encryption_a5_reset();
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003971 f_shutdown_helper();
3972}
Harald Weltec1a2fff2017-12-17 11:06:19 +01003973
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +02003974/* Allow only A5/4, but omit the Kc128 IE from MSC's msg. Expect Cipher Mode Reject. */
3975testcase TC_assignment_fr_a5_4_fail() runs on test_CT {
3976 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3977 var MSC_ConnHdlr vc_conn;
3978
3979 f_init(1, true);
3980 f_sleep(1.0);
3981
3982 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8))); // A5/4 support, but Kc128 missing!
3983 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
3984 vc_conn.done;
3985 f_shutdown_helper();
3986}
3987
Harald Welte552620d2017-12-16 23:21:36 +01003988/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
3989private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003990 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01003991 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02003992 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003993
3994 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003995 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
3996
Harald Weltea0630032018-03-20 21:09:55 +01003997 f_establish_fully(ass_cmd, exp_fail);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003998 f_perform_clear();
Harald Welte552620d2017-12-16 23:21:36 +01003999}
Harald Welte552620d2017-12-16 23:21:36 +01004000testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
4001 var MSC_ConnHdlr vc_conn;
4002
Harald Welte89d42e82017-12-17 16:42:41 +01004003 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01004004 f_sleep(1.0);
4005
Harald Welte8863fa12018-05-10 20:15:27 +02004006 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01004007 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004008 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01004009}
4010
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02004011private function f_TC_assignment_a5_not_sup(charstring id) runs on MSC_ConnHdlr {
4012 var template PDU_BSSAP exp_ass_cpl := f_gen_exp_compl();
4013 var PDU_BSSAP exp_ass_req := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01004014
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02004015 exp_ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4016 exp_ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4017
4018 /* this is like the beginning of f_establish_fully(), but only up to ciphering reject */
4019
4020 var BSSMAP_FIELD_CodecType codecType;
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02004021
4022 codecType := exp_ass_req.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType;
4023 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
4024
4025 f_create_chan_and_exp();
4026 /* we should now have a COMPL_L3 at the MSC */
4027
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02004028 /* Start ciphering, expect Cipher Mode Reject */
Neels Hofmeyr6c388f22021-06-11 02:36:56 +02004029 f_cipher_mode(g_pars.encr, exp_fail := true);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004030 f_perform_clear();
Harald Welte552620d2017-12-16 23:21:36 +01004031}
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02004032testcase TC_assignment_fr_a5_not_sup() runs on test_CT {
4033 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01004034 var MSC_ConnHdlr vc_conn;
4035
Harald Welte89d42e82017-12-17 16:42:41 +01004036 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01004037 f_sleep(1.0);
4038
Neels Hofmeyr0588cad2021-06-11 01:38:18 +02004039 pars.encr := valueof(t_EncrParams('20'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02004040 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
Harald Welte552620d2017-12-16 23:21:36 +01004041 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004042 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01004043}
4044
4045
Harald Welte4532e0a2017-12-23 02:05:44 +01004046private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02004047 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01004048 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02004049 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01004050 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Daniel Willmannebdecc02020-08-12 15:30:17 +02004051
4052 f_statsd_reset();
Harald Weltea0630032018-03-20 21:09:55 +01004053 f_establish_fully(ass_cmd, exp_compl);
Daniel Willmannebdecc02020-08-12 15:30:17 +02004054
4055 var StatsDExpects expect := {
Daniel Willmannc5398f72020-09-21 10:41:35 +02004056 { name := "TTCN3.bts.0.chreq.total", mtype := "c", min := 1, max := 1},
4057 { name := "TTCN3.bts.0.chreq.successful", mtype := "c", min := 1, max := 1},
Daniel Willmannebdecc02020-08-12 15:30:17 +02004058 { name := "TTCN3.bsc.0.assignment.attempted", mtype := "c", min := 1, max := 1},
4059 { name := "TTCN3.bsc.0.assignment.completed", mtype := "c", min := 1, max := 1}
4060 };
4061 f_statsd_expect(expect);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004062 f_perform_clear();
Harald Welte4532e0a2017-12-23 02:05:44 +01004063}
4064
4065testcase TC_assignment_sign() runs on test_CT {
4066 var MSC_ConnHdlr vc_conn;
4067
4068 f_init(1, true);
4069 f_sleep(1.0);
4070
Harald Welte8863fa12018-05-10 20:15:27 +02004071 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01004072 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004073 f_shutdown_helper();
Harald Welte4532e0a2017-12-23 02:05:44 +01004074}
4075
Harald Welte60aa5762018-03-21 19:33:13 +01004076/***********************************************************************
4077 * Codec (list) testing
4078 ***********************************************************************/
4079
4080/* check if the given rsl_mode is compatible with the a_elem */
4081private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
4082return boolean {
4083 select (a_elem.codecType) {
4084 case (GSM_FR) {
4085 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
4086 return true;
4087 }
4088 }
4089 case (GSM_HR) {
4090 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
4091 return true;
4092 }
4093 }
4094 case (GSM_EFR) {
4095 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
4096 return true;
4097 }
4098 }
4099 case (FR_AMR) {
4100 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
4101 return true;
4102 }
4103 }
4104 case (HR_AMR) {
4105 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
4106 return true;
4107 }
4108 }
4109 case else { }
4110 }
4111 return false;
4112}
4113
4114/* check if the given rsl_mode is compatible with the a_list */
4115private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
4116return boolean {
4117 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
4118 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
4119 return true;
4120 }
4121 }
4122 return false;
4123}
4124
4125/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02004126function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01004127return BSSMAP_IE_ChannelType {
4128 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
4129 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
4130 select (a_elem.codecType) {
4131 case (GSM_FR) {
4132 ret.channelRateAndType := ChRate_TCHF;
4133 ret.speechId_DataIndicator := Spdi_TCHF_FR;
4134 }
4135 case (GSM_HR) {
4136 ret.channelRateAndType := ChRate_TCHH;
4137 ret.speechId_DataIndicator := Spdi_TCHH_HR;
4138 }
4139 case (GSM_EFR) {
4140 ret.channelRateAndType := ChRate_TCHF;
4141 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
4142 }
4143 case (FR_AMR) {
4144 ret.channelRateAndType := ChRate_TCHF;
4145 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
4146 }
4147 case (HR_AMR) {
4148 ret.channelRateAndType := ChRate_TCHH;
4149 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
4150 }
4151 case else {
4152 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02004153 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01004154 }
4155 }
4156 return ret;
4157}
4158
Harald Weltea63b9102018-03-22 20:36:16 +01004159private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
4160return template RSL_IE_Body {
4161 var template RSL_IE_Body mode_ie := {
4162 chan_mode := {
4163 len := ?,
4164 reserved := ?,
4165 dtx_d := ?,
4166 dtx_u := ?,
4167 spd_ind := RSL_SPDI_SPEECH,
4168 ch_rate_type := -,
4169 coding_alg_rate := -
4170 }
4171 }
4172
4173 select (a_elem.codecType) {
4174 case (GSM_FR) {
4175 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4176 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
4177 }
4178 case (GSM_HR) {
4179 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
4180 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
4181 }
4182 case (GSM_EFR) {
4183 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4184 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
4185 }
4186 case (FR_AMR) {
4187 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4188 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
4189 }
4190 case (HR_AMR) {
4191 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
4192 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
4193 }
4194 }
4195 return mode_ie;
4196}
4197
Harald Welte60aa5762018-03-21 19:33:13 +01004198type record CodecListTest {
4199 BSSMAP_IE_SpeechCodecList codec_list,
4200 charstring id
4201}
4202type record of CodecListTest CodecListTests
4203
4204private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004205 f_assignment_codec(id);
4206}
4207
4208private function f_assignment_codec(charstring id, boolean do_perform_clear := true) runs on MSC_ConnHdlr {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004209 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
4210 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
Harald Welte60aa5762018-03-21 19:33:13 +01004211
4212 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02004213 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte79f3f542018-05-25 20:02:37 +02004214 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
4215 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
4216 g_pars.ass_codec_list.codecElements[0];
Philipp Maierd0e64b02019-03-13 14:15:23 +01004217 if (isvalue(g_pars.expect_mr_s0_s7)) {
4218 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
4219 g_pars.expect_mr_s0_s7;
4220 }
Harald Welte79f3f542018-05-25 20:02:37 +02004221 }
Harald Welte60aa5762018-03-21 19:33:13 +01004222 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
4223 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01004224 log("expecting ASS COMPL like this: ", exp_compl);
4225
4226 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01004227
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004228 if (not g_pars.expect_channel_mode_modify) {
4229 /* Verify that the RSL-side activation actually matches our expectations */
4230 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
Harald Weltea63b9102018-03-22 20:36:16 +01004231
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004232 var RSL_IE_Body mode_ie;
4233 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
4234 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02004235 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004236 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004237 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
4238 if (not match(mode_ie, t_mode_ie)) {
4239 log("mode_ie ", mode_ie, " != t_mode_ie ", t_mode_ie);
4240 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004241 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004242
4243 var RSL_IE_Body mr_conf;
4244 if (g_pars.expect_mr_conf_ie != omit) {
4245 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
4246 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
4247 mtc.stop;
4248 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004249 log("found RSL MR CONFIG IE: ", mr_conf);
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004250
4251 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
4252 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
4253 g_pars.expect_mr_conf_ie);
4254 }
4255 } else {
4256 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
4257 log("found RSL MR CONFIG IE: ", mr_conf);
4258 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
4259 mtc.stop;
4260 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004261 }
4262 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004263
4264 if (do_perform_clear) {
4265 f_perform_clear();
4266 }
Harald Welte60aa5762018-03-21 19:33:13 +01004267}
4268
Philipp Maierd0e64b02019-03-13 14:15:23 +01004269private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
4270
4271 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4272 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4273
4274 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02004275 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maierd0e64b02019-03-13 14:15:23 +01004276 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
4277 }
4278 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
4279 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
4280 log("expecting ASS FAIL like this: ", exp_fail);
4281
4282 f_establish_fully(ass_cmd, exp_fail);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004283 f_perform_clear();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004284}
4285
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004286const CounterNameVals counternames_bsc_bts_assignment := {
4287 { "assignment:attempted", 0 },
4288 { "assignment:completed", 0 },
4289 { "assignment:stopped", 0 },
4290 { "assignment:no_channel", 0 },
4291 { "assignment:timeout", 0 },
4292 { "assignment:failed", 0 },
4293 { "assignment:error", 0 }
4294};
4295
4296const CounterNameVals counternames_bts_assignment := {
4297 { "assignment:attempted_sign", 0 },
4298 { "assignment:attempted_speech", 0 },
4299 { "assignment:completed_sign", 0 },
4300 { "assignment:completed_speech", 0 },
4301 { "assignment:stopped_sign", 0 },
4302 { "assignment:stopped_speech", 0 },
4303 { "assignment:no_channel_sign", 0 },
4304 { "assignment:no_channel_speech", 0 },
4305 { "assignment:timeout_sign", 0 },
4306 { "assignment:timeout_speech", 0 },
4307 { "assignment:failed_sign", 0 },
4308 { "assignment:failed_speech", 0 },
4309 { "assignment:error_sign", 0 },
4310 { "assignment:error_speech", 0 }
4311};
4312
4313function f_ctrs_bsc_and_bts_assignment_init(integer bts_count := NUM_BTS) runs on test_CT {
4314 var CounterNameVals bts_names := counternames_bsc_bts_assignment & counternames_bts_assignment;
4315 f_ctrs_bts_init(bts_count, bts_names);
4316 f_ctrs_bsc_init(counternames_bsc_bts_assignment);
4317}
4318
Harald Welte60aa5762018-03-21 19:33:13 +01004319testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004320 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004321 var MSC_ConnHdlr vc_conn;
4322
4323 f_init(1, true);
4324 f_sleep(1.0);
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004325 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004326
4327 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004328 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004329 vc_conn.done;
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004330
4331 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4332 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4333 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4334 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4335 f_ctrs_bts_verify();
4336
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004337 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004338}
4339
4340testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004341 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004342 var MSC_ConnHdlr vc_conn;
4343
4344 f_init(1, true);
4345 f_sleep(1.0);
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004346 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004347
4348 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004349 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004350 vc_conn.done;
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004351
4352 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4353 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4354 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4355 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4356 f_ctrs_bts_verify();
4357
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004358 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004359}
4360
4361testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004362 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004363 var MSC_ConnHdlr vc_conn;
4364
4365 f_init(1, true);
4366 f_sleep(1.0);
4367
4368 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004369 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004370 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004371 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004372}
4373
Philipp Maierd0e64b02019-03-13 14:15:23 +01004374/* Allow 5,90k only (current default config) */
4375private function f_allow_amr_rate_5_90k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00004376 f_vty_cfg_msc(BSCVTY, 0, {
4377 "amr-config 12_2k forbidden",
4378 "amr-config 10_2k forbidden",
4379 "amr-config 7_95k forbidden",
4380 "amr-config 7_40k forbidden",
4381 "amr-config 6_70k forbidden",
4382 "amr-config 5_90k allowed",
4383 "amr-config 5_15k forbidden",
4384 "amr-config 4_75k forbidden"
4385 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01004386}
4387
4388/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
4389 * ("Config-NB-Code = 1") */
4390private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00004391 f_vty_cfg_msc(BSCVTY, 0, {
4392 "amr-config 12_2k allowed",
4393 "amr-config 10_2k forbidden",
4394 "amr-config 7_95k forbidden",
4395 "amr-config 7_40k allowed",
4396 "amr-config 6_70k forbidden",
4397 "amr-config 5_90k allowed",
4398 "amr-config 5_15k forbidden",
4399 "amr-config 4_75k allowed"
4400 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01004401}
4402
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004403private function f_vty_amr_start_mode_set(boolean fr, charstring startmode) runs on test_CT {
4404 var charstring tch;
4405 if (fr) {
4406 tch := "tch-f";
4407 } else {
4408 tch := "tch-h";
4409 }
4410 f_vty_cfg_bts(BSCVTY, 0, { "amr " & tch & " start-mode " & startmode });
4411}
4412
4413/* Set the AMR start-mode for this TCH back to the default configuration. */
4414private function f_vty_amr_start_mode_restore(boolean fr) runs on test_CT {
4415 f_vty_amr_start_mode_set(fr, "auto");
4416}
4417
Harald Welte60aa5762018-03-21 19:33:13 +01004418testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004419 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004420 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02004421
4422 /* Note: This setups the codec configuration. The parameter payload in
4423 * mr_conf must be consistant with the parameter codecElements in pars
4424 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004425 var RSL_IE_Body mr_conf := {
4426 other := {
4427 len := 2,
4428 payload := '2804'O
4429 }
4430 };
Harald Welte60aa5762018-03-21 19:33:13 +01004431
Philipp Maier7695a0d2018-09-27 17:52:14 +02004432 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Philipp Maier806f8f12019-03-12 12:13:41 +01004433 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02004434 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
4435 pars.expect_mr_conf_ie := mr_conf;
4436
Harald Welte60aa5762018-03-21 19:33:13 +01004437 f_init(1, true);
4438 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004439 f_vty_amr_start_mode_set(true, "1");
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004440 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004441
Harald Welte8863fa12018-05-10 20:15:27 +02004442 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004443 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004444
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004445 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4446 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4447 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4448 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4449 f_ctrs_bts_verify();
4450
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004451 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004452 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004453}
4454
4455testcase TC_assignment_codec_amr_h() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004456 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004457 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02004458
4459 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004460 var RSL_IE_Body mr_conf := {
4461 other := {
4462 len := 2,
4463 payload := '2804'O
4464 }
4465 };
Harald Welte60aa5762018-03-21 19:33:13 +01004466
Philipp Maier7695a0d2018-09-27 17:52:14 +02004467 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Philipp Maier806f8f12019-03-12 12:13:41 +01004468 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02004469 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4470 pars.expect_mr_conf_ie := mr_conf;
4471
Harald Welte60aa5762018-03-21 19:33:13 +01004472 f_init(1, true);
4473 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004474 f_vty_amr_start_mode_set(false, "1");
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004475 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004476
Harald Welte8863fa12018-05-10 20:15:27 +02004477 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004478 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004479
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004480 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4481 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4482 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4483 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4484 f_ctrs_bts_verify();
4485
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004486 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004487 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004488}
4489
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004490/* Establish signalling on a TCH/F lchan, and then switch to speech mode without a new Assignment. */
4491testcase TC_assignment_codec_fr_by_mode_modify() runs on test_CT {
4492 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4493 var MSC_ConnHdlr vc_conn;
4494
4495 f_init(1, true);
4496 f_sleep(1.0);
4497
4498 /* By disabling all SDCCH, the MS should be given a TCH/F for signalling. Then activating an FR codec should
4499 * merely do a Channel Mode Modify, and not assign to a new lchan. f_establish_fully() already accounts for
4500 * expecting a Channel Mode Modify if the channel type is compatible. */
4501 f_disable_all_sdcch();
4502 f_disable_all_tch_h();
4503
4504 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4505 pars.expect_channel_mode_modify := true;
4506 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4507 vc_conn.done;
4508
4509 f_enable_all_sdcch();
4510 f_enable_all_tch();
4511 f_shutdown_helper();
4512}
4513
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004514/* 'amr start-mode auto' should not keep the (unused) 'smod' bits from previous configuration */
4515testcase TC_assignment_codec_amr_startmode_cruft() runs on test_CT {
4516 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4517 var MSC_ConnHdlr vc_conn;
4518
4519 var RSL_IE_Body mr_conf := {
4520 other := {
4521 len := 2,
4522 payload := '2004'O /* <- expect ICMI=0, smod=00 */
4523 }
4524 };
4525
4526 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4527 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
4528 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
4529 pars.expect_mr_conf_ie := mr_conf;
4530
4531 f_init(1, true);
4532 f_sleep(1.0);
4533
4534 /* First set nonzero start mode bits */
4535 f_vty_amr_start_mode_set(true, "4");
4536 /* Now set to auto, and expect the startmode bits to be zero in the message, i.e. ensure that osmo-bsc does not
4537 * let the startmode bits stick around and has deterministic MultiRate config for 'start-mode auto'; that is
4538 * ensured by above '2004'O, where 'x0xx'O indicates ICMI = 0, spare = 0, smod = 00. */
4539 f_vty_amr_start_mode_set(true, "auto");
4540
4541 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4542 vc_conn.done;
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004543
4544 /* Clear the startmode bits to not affect subsequent tests, in case the bits should indeed stick around. */
4545 f_vty_amr_start_mode_set(true, "1");
4546 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004547 f_shutdown_helper();
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004548}
4549
Neels Hofmeyr21863562020-11-26 00:34:33 +00004550function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0,
4551 charstring start_mode := "1")
Philipp Maierd0e64b02019-03-13 14:15:23 +01004552runs on test_CT {
4553
4554 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4555 var MSC_ConnHdlr vc_conn;
4556
4557 /* See note above */
4558 var RSL_IE_Body mr_conf := {
4559 other := {
4560 len := lengthof(mrconf),
4561 payload := mrconf
4562 }
4563 };
4564
4565 if (fr) {
4566 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4567 } else {
4568 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4569 }
4570 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4571 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4572 pars.expect_mr_conf_ie := mr_conf;
4573 pars.expect_mr_s0_s7 := exp_s8_s0;
4574
4575 f_init(1, true);
4576 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004577 f_vty_amr_start_mode_set(fr, start_mode);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004578 f_sleep(1.0);
4579
4580 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4581 vc_conn.done;
4582 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004583 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004584}
4585
4586function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
4587runs on test_CT {
4588
4589 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4590 var MSC_ConnHdlr vc_conn;
4591
4592 if (fr) {
4593 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4594 } else {
4595 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4596 }
4597 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4598 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4599
4600 f_init(1, true);
4601 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004602 f_vty_amr_start_mode_set(fr, "1");
Philipp Maierd0e64b02019-03-13 14:15:23 +01004603 f_sleep(1.0);
4604
4605 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
4606 vc_conn.done;
4607 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004608 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004609}
4610
4611
4612/* Set S1, we expect an AMR multirate configuration IE with all four rates
4613 * set. */
4614testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004615 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004616 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004617}
4618
4619/* Set S1, we expect an AMR multirate configuration IE with the lower three
4620 * rates set. */
4621testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004622 f_TC_assignment_codec_amr(false, '2815208820'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004623 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004624}
4625
4626/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4627 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4628testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004629 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004630 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004631}
4632
4633/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4634 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4635testcase TC_assignment_codec_amr_h_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004636 f_TC_assignment_codec_amr(false, '2815208820'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004637 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004638}
4639
4640/* The following block of tests selects more and more rates until all four
4641 * possible rates are in the active set (full rate) */
4642testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004643 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004644 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004645}
4646
4647testcase TC_assignment_codec_amr_f_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004648 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004649 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004650}
4651
4652testcase TC_assignment_codec_amr_f_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004653 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004654 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004655}
4656
4657testcase TC_assignment_codec_amr_f_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004658 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004659 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004660}
4661
4662/* The following block of tests selects more and more rates until all three
4663 * possible rates are in the active set (half rate) */
4664testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004665 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004666 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004667}
4668
4669testcase TC_assignment_codec_amr_h_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004670 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004671 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004672}
4673
4674testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004675 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004676 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004677}
4678
4679/* The following block tests what happens when the MSC does offer rate
4680 * configurations that are not supported by the BSC. Normally such situations
4681 * should not happen because the MSC gets informed by the BSC in advance via
4682 * the L3 COMPLETE message which rates are applicable. The MSC should not try
4683 * to offer rates that are not applicable anyway. */
4684
4685testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004686 /* Try to include 12,2k in into the active set even though the channel
4687 * is half rate only. The BSC is expected to remove the 12,0k */
4688 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004689 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004690}
4691
4692testcase TC_assignment_codec_amr_f_S01234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004693 /* See what happens when all rates are selected at once. Since then
4694 * Also S1 is selected, this setting will be prefered and we should
4695 * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
4696 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004697 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004698}
4699
4700testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004701 /* Same as above, but with S1 missing, the MSC is then expected to
4702 * select the currently supported rates, which are also 12.2k, 7,40k,
4703 * 5,90k, and 4,75k, into the active set. */
4704 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004705 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004706}
4707
4708testcase TC_assignment_codec_amr_f_zero() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004709 /* Try to select no rates at all */
4710 f_TC_assignment_codec_amr_fail(true, '00000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004711 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004712}
4713
4714testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004715 /* Try to select only unsupported rates */
4716 f_TC_assignment_codec_amr_fail(true, '01101000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004717 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004718}
4719
4720testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004721 /* Try to select 12,2k for half rate */
4722 f_TC_assignment_codec_amr_fail(false, '10000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004723 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004724}
4725
Neels Hofmeyr21863562020-11-26 00:34:33 +00004726testcase TC_assignment_codec_amr_f_start_mode_auto() runs on test_CT {
4727 f_TC_assignment_codec_amr(true, '209520882208'O, '11111111'B, '00000010'B,
4728 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004729 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004730}
4731
4732testcase TC_assignment_codec_amr_h_start_mode_auto() runs on test_CT {
4733 f_TC_assignment_codec_amr(false, '2015208820'O, '10010101'B, '00010101'B,
4734 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004735 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004736}
4737
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004738testcase TC_assignment_codec_amr_f_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004739 /* "amr tch-f modes 0 2 4 7" => total 4 modes and start mode 4 => '11'B on the wire */
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004740 f_TC_assignment_codec_amr(true, '2b9520882208'O, '11111111'B, '00000010'B,
4741 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004742 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004743}
4744
4745testcase TC_assignment_codec_amr_h_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004746 /* "amr tch-h modes 0 2 4" => total 3 modes and start mode 4 => '10'B on the wire */
4747 f_TC_assignment_codec_amr(false, '2a15208820'O, '10010101'B, '00010101'B,
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004748 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004749 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004750}
4751
Philipp Maierac09bfc2019-01-08 13:41:39 +01004752private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004753 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
4754 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
4755 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
4756 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004757}
4758
4759private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004760 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
4761 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004762}
4763
4764private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004765 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
4766 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
4767 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
4768 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
4769 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
4770 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004771}
4772
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004773private function f_disable_all_sdcch() runs on test_CT {
4774 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 borken");
4775 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 borken");
4776 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 borken");
4777 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 borken");
4778}
4779
4780private function f_enable_all_sdcch() runs on test_CT {
4781 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 unused");
4782 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 unused");
4783 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 unused");
4784 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 unused");
4785}
4786
Philipp Maierac09bfc2019-01-08 13:41:39 +01004787/* Allow HR only */
4788private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
4789 g_pars := f_gen_test_hdlr_pars();
4790 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4791 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4792 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4793 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4794 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4795 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4796 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004797 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004798}
4799
4800/* Allow FR only */
4801private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
4802 g_pars := f_gen_test_hdlr_pars();
4803 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4804 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4805 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4806 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4807 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4808 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4809 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004810 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004811}
4812
4813/* Allow HR only (expect assignment failure) */
4814private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
4815 g_pars := f_gen_test_hdlr_pars();
4816 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4817 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4818 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4819 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4820 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4821 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4822 f_establish_fully(ass_cmd, exp_fail);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004823 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004824}
4825
4826/* Allow FR only (expect assignment failure) */
4827private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(charstring id) runs on MSC_ConnHdlr {
4828 g_pars := f_gen_test_hdlr_pars();
4829 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4830 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4831 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4832 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4833 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4834 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4835 f_establish_fully(ass_cmd, exp_fail);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004836 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004837}
4838
4839/* Allow FR and HR, but prefer FR */
4840private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4841 g_pars := f_gen_test_hdlr_pars();
4842 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4843 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4844 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4845 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4846 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4847 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4848 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4849 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004850 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004851}
4852
4853/* Allow FR and HR, but prefer HR */
4854private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4855 g_pars := f_gen_test_hdlr_pars();
4856 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4857 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4858 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4859 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4860 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4861 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4862 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4863 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004864 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004865}
4866
4867/* Allow FR and HR, but prefer FR */
4868private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4869 g_pars := f_gen_test_hdlr_pars();
4870 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4871 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4872 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4873 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4874 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4875 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4876 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4877 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004878 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004879}
4880
4881/* Allow FR and HR, but prefer HR */
4882private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4883 g_pars := f_gen_test_hdlr_pars();
4884 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4885 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4886 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4887 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4888 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4889 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4890 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4891 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004892 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004893}
4894
4895/* Request a HR channel while all FR channels are exhausted, this is expected
4896 * to work without conflicts */
4897testcase TC_assignment_codec_fr_exhausted_req_hr() runs on test_CT {
4898 var MSC_ConnHdlr vc_conn;
4899 f_init(1, true);
4900 f_sleep(1.0);
4901 f_enable_all_tch();
4902 f_disable_all_tch_f();
4903 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr));
4904 vc_conn.done;
4905 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004906 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004907}
4908
4909/* Request a FR channel while all FR channels are exhausted, this is expected
4910 * to fail. */
4911testcase TC_assignment_codec_fr_exhausted_req_fr() runs on test_CT {
4912 var MSC_ConnHdlr vc_conn;
4913 f_init(1, true);
4914 f_sleep(1.0);
4915 f_enable_all_tch();
4916 f_disable_all_tch_f();
4917 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr_fail));
4918 vc_conn.done;
4919 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004920 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004921}
4922
4923/* Request a FR (prefered) or alternatively a HR channel while all FR channels
4924 * are exhausted, this is expected to be resolved by selecting a HR channel. */
4925testcase TC_assignment_codec_fr_exhausted_req_fr_hr() runs on test_CT {
4926 var MSC_ConnHdlr vc_conn;
4927 f_init(1, true);
4928 f_sleep(1.0);
4929 f_enable_all_tch();
4930 f_disable_all_tch_f();
4931 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
4932 vc_conn.done;
4933 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004934 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004935}
4936
4937/* Request a HR (prefered) or alternatively a FR channel while all FR channels
4938 * are exhausted, this is expected to work without conflicts. */
4939testcase TC_assignment_codec_fr_exhausted_req_hr_fr() runs on test_CT {
4940 var MSC_ConnHdlr vc_conn;
4941 f_init(1, true);
4942 f_sleep(1.0);
4943 f_enable_all_tch();
4944 f_disable_all_tch_f();
4945 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_hr_fr));
4946 vc_conn.done;
4947 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004948 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004949}
4950
4951/* Request a FR channel while all HR channels are exhausted, this is expected
4952 * to work without conflicts */
4953testcase TC_assignment_codec_hr_exhausted_req_fr() runs on test_CT {
4954 var MSC_ConnHdlr vc_conn;
4955 f_init(1, true);
4956 f_sleep(1.0);
4957 f_enable_all_tch();
4958 f_disable_all_tch_h();
4959 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr));
4960 vc_conn.done;
4961 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004962 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004963}
4964
4965/* Request a HR channel while all HR channels are exhausted, this is expected
4966 * to fail. */
4967testcase TC_assignment_codec_hr_exhausted_req_hr() runs on test_CT {
4968 var MSC_ConnHdlr vc_conn;
4969 f_init(1, true);
4970 f_sleep(1.0);
4971 f_enable_all_tch();
4972 f_disable_all_tch_h();
4973 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr_fail));
4974 vc_conn.done;
4975 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004976 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004977}
4978
4979/* Request a HR (prefered) or alternatively a FR channel while all HR channels
4980 * are exhausted, this is expected to be resolved by selecting a FR channel. */
4981testcase TC_assignment_codec_hr_exhausted_req_hr_fr() runs on test_CT {
4982 var MSC_ConnHdlr vc_conn;
4983 f_init(1, true);
4984 f_sleep(1.0);
4985 f_enable_all_tch();
4986 f_disable_all_tch_h();
4987 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_hr_fr));
4988 vc_conn.done;
4989 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004990 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004991}
4992
4993/* Request a FR (prefered) or alternatively a HR channel while all HR channels
4994 * are exhausted, this is expected to work without conflicts. */
4995testcase TC_assignment_codec_hr_exhausted_req_fr_hr() runs on test_CT {
4996 var MSC_ConnHdlr vc_conn;
4997 f_init(1, true);
4998 f_sleep(1.0);
4999 f_enable_all_tch();
5000 f_disable_all_tch_h();
5001 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_fr_hr));
5002 vc_conn.done;
5003 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005004 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01005005}
5006
5007/* Allow FR and HR, but prefer HR */
5008private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
5009 g_pars := f_gen_test_hdlr_pars();
5010 var PDU_BSSAP ass_cmd := f_gen_ass_req();
5011 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5012 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5013 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
5014 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
5015 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
5016 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
5017 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005018 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01005019}
5020
5021/* Allow FR and HR, but prefer FR */
5022private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
5023 g_pars := f_gen_test_hdlr_pars();
5024 var PDU_BSSAP ass_cmd := f_gen_ass_req();
5025 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5026 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5027 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
5028 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
5029 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
5030 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
5031 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005032 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01005033}
5034
5035/* Request a HR (prefered) or alternatively a FR channel, it is expected that
5036 * HR, which is the prefered type, is selected. */
5037testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
5038 var MSC_ConnHdlr vc_conn;
5039 f_init(1, true);
5040 f_sleep(1.0);
5041 f_enable_all_tch();
5042 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
5043 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005044 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01005045}
5046
5047/* Request a FR (prefered) or alternatively a HR channel, it is expected that
5048 * FR, which is the prefered type, is selected. */
5049testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
5050 var MSC_ConnHdlr vc_conn;
5051 f_init(1, true);
5052 f_sleep(1.0);
5053 f_enable_all_tch();
5054 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
5055 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005056 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01005057}
5058
Pau Espin Pedrol14475352021-07-22 15:48:16 +02005059/* request a signalling channel with all SDCCH exhausted, it is expected that a TCH will be selected */
5060private function f_TC_assignment_sdcch_exhausted_req_signalling(charstring id) runs on MSC_ConnHdlr {
5061 g_pars := f_gen_test_hdlr_pars();
5062 g_pars.ra := '02'O; /* RA containing reason=LU */
5063
5064 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
5065 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
5066 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
5067 var template uint3_t tsc := ?;
5068
5069 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
5070 f_create_bssmap_exp(l3_enc);
5071 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
5072 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, tsc);
5073
5074 /* we should now have a COMPL_L3 at the MSC */
5075 timer T := 10.0;
5076 T.start;
5077 alt {
5078 [] BSSAP.receive(tr_BSSMAP_ComplL3);
5079 [] T.timeout {
5080 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
5081 }
5082 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005083
5084 f_perform_clear();
Pau Espin Pedrol14475352021-07-22 15:48:16 +02005085}
5086testcase TC_assignment_sdcch_exhausted_req_signalling() runs on test_CT {
5087 var MSC_ConnHdlr vc_conn;
5088 f_init(1, true);
5089 f_sleep(1.0);
5090 f_disable_all_sdcch();
5091 vc_conn := f_start_handler(refers(f_TC_assignment_sdcch_exhausted_req_signalling));
5092 vc_conn.done;
5093 f_enable_all_sdcch();
5094 f_shutdown_helper();
5095}
5096
5097/* Request a signalling channel with all SDCCH exhausted, it is
5098 expected that no TCH will be selected for signalling and assigment will fail
5099 because it's dictated by VTY config */
5100testcase TC_assignment_sdcch_exhausted_req_signalling_tch_forbidden() runs on test_CT {
5101 var RSL_Message rsl_unused, rsl_msg;
5102 var GsmRrMessage rr;
5103 f_init(1, false);
5104 f_sleep(1.0);
5105 f_vty_allow_tch_for_signalling(false, 0);
5106 f_disable_all_sdcch();
5107
5108 /* RA containing reason=LU */
5109 f_ipa_tx(0, ts_RSL_CHAN_RQD('02'O, 2342));
5110 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
5111 rr := dec_GsmRrMessage(rsl_msg.ies[1].body.full_imm_ass_info.payload);
5112 if (rr.header.message_type != IMMEDIATE_ASSIGNMENT_REJECT) {
5113 setverdict(fail, "Expected reject");
5114 }
5115
5116 f_vty_allow_tch_for_signalling(true, 0);
5117 f_enable_all_sdcch();
5118 f_shutdown_helper();
5119}
5120
5121/* Request a voice channel with all SDCCH exhausted, it is
5122 * expected that TCH channel will be allocated since the VTY option is only
5123 * aimed at signalling requests */
5124private function f_TC_assignment_sdcch_exhausted_req_voice_tch_forbidden(charstring id) runs on MSC_ConnHdlr {
5125 g_pars := f_gen_test_hdlr_pars();
5126 g_pars.ra := '43'O; /* RA containing reason=originating speech call*/
5127
5128 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
5129 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
5130 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
5131 var template uint3_t tsc := ?;
5132
5133 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
5134 f_create_bssmap_exp(l3_enc);
5135 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
5136 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, tsc);
5137
5138 /* we should now have a COMPL_L3 at the MSC */
5139 timer T := 10.0;
5140 T.start;
5141 alt {
5142 [] BSSAP.receive(tr_BSSMAP_ComplL3);
5143 [] T.timeout {
5144 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
5145 }
5146 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005147 f_perform_clear();
Pau Espin Pedrol14475352021-07-22 15:48:16 +02005148}
5149testcase TC_assignment_sdcch_exhausted_req_voice_tch_forbidden() runs on test_CT {
5150 var MSC_ConnHdlr vc_conn;
5151 f_init(1, true);
5152 f_sleep(1.0);
5153 f_vty_allow_tch_for_signalling(false, 0);
5154 f_disable_all_sdcch();
5155
5156 vc_conn := f_start_handler(refers(f_TC_assignment_sdcch_exhausted_req_voice_tch_forbidden));
5157 vc_conn.done;
5158
5159 f_vty_allow_tch_for_signalling(true, 0);
5160 f_enable_all_sdcch();
5161 f_shutdown_helper();
5162}
5163
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005164testcase TC_assignment_osmux() runs on test_CT {
5165 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5166 var MSC_ConnHdlr vc_conn;
5167
5168 /* See note above */
5169 var RSL_IE_Body mr_conf := {
5170 other := {
5171 len := 2,
5172 payload := '2804'O
5173 }
5174 };
5175
5176 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
5177 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
5178 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
5179 pars.expect_mr_conf_ie := mr_conf;
5180 pars.use_osmux := true;
5181
5182 f_init(1, true, true);
5183 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00005184 f_vty_amr_start_mode_set(false, "1");
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005185
5186 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
5187 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00005188
5189 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01005190 f_shutdown_helper();
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005191}
5192
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02005193/* test the procedure of the MSC requesting a Classmark Update:
5194 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
5195 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01005196private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005197 g_pars := f_gen_test_hdlr_pars();
5198
Harald Weltea0630032018-03-20 21:09:55 +01005199 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01005200 /* we should now have a COMPL_L3 at the MSC */
Harald Welte898113b2018-01-31 18:32:21 +01005201
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02005202 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
5203 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
5204
Harald Welte898113b2018-01-31 18:32:21 +01005205 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
5206 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
5207 setverdict(pass);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005208
5209 f_perform_clear();
Harald Welte898113b2018-01-31 18:32:21 +01005210}
5211testcase TC_classmark() runs on test_CT {
5212 var MSC_ConnHdlr vc_conn;
5213 f_init(1, true);
5214 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005215 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01005216 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005217 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01005218}
5219
Harald Welteeddf0e92020-06-21 19:42:15 +02005220/* Send a CommonID from the simulated MSC and verify that the information is used to
5221 * fill BSC-internal data structures (specifically, bsc_subscr associated with subscr_conn) */
5222private function f_tc_common_id(charstring id) runs on MSC_ConnHdlr {
5223 g_pars := f_gen_test_hdlr_pars();
5224 f_MscConnHdlr_init_vty();
5225
5226 f_create_chan_and_exp();
5227 /* we should now have a COMPL_L3 at the MSC */
Harald Welteeddf0e92020-06-21 19:42:15 +02005228
5229 /* Send CommonID */
5230 BSSAP.send(ts_BSSMAP_CommonId(g_pars.imsi));
5231
5232 /* Use VTY to verify that the IMSI of the subscr_conn is set */
5233 var charstring regex := "*(IMSI: " & hex2str(g_pars.imsi) & ")*";
5234 f_vty_transceive_match_regexp_retry(BSCVTY, "show conns", regex, 0, 4, 1.0);
5235
5236 setverdict(pass);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005237
5238 f_perform_clear();
Harald Welteeddf0e92020-06-21 19:42:15 +02005239}
5240testcase TC_common_id() runs on test_CT {
5241 var MSC_ConnHdlr vc_conn;
5242 f_init(1, true);
5243 f_sleep(1.0);
5244 vc_conn := f_start_handler(refers(f_tc_common_id));
5245 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005246 f_shutdown_helper();
Harald Welteeddf0e92020-06-21 19:42:15 +02005247}
5248
Harald Weltee3bd6582018-01-31 22:51:25 +01005249private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005250 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01005251 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01005252 /* we should now have a COMPL_L3 at the MSC */
Harald Welte898113b2018-01-31 18:32:21 +01005253
Harald Weltee3bd6582018-01-31 22:51:25 +01005254 /* send the single message we want to send */
5255 f_rsl_send_l3(l3);
5256}
5257
5258private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
5259 timer T := sec;
5260 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01005261 T.start;
5262 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01005263 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
5264 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02005265 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01005266 }
5267 [] T.timeout {
5268 setverdict(pass);
5269 }
5270 }
5271}
5272
Harald Weltee3bd6582018-01-31 22:51:25 +01005273/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
5274private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
5275 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
5276 f_bssap_expect_nothing();
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005277 f_perform_clear();
Harald Weltee3bd6582018-01-31 22:51:25 +01005278}
Harald Welte898113b2018-01-31 18:32:21 +01005279testcase TC_unsol_ass_fail() runs on test_CT {
5280 var MSC_ConnHdlr vc_conn;
5281 f_init(1, true);
5282 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005283 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01005284 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005285 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01005286}
Harald Welte552620d2017-12-16 23:21:36 +01005287
Harald Welteea99a002018-01-31 20:46:43 +01005288
5289/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
5290private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01005291 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
5292 f_bssap_expect_nothing();
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005293 f_perform_clear();
Harald Welteea99a002018-01-31 20:46:43 +01005294}
5295testcase TC_unsol_ass_compl() runs on test_CT {
5296 var MSC_ConnHdlr vc_conn;
5297 f_init(1, true);
5298 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005299 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01005300 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005301 f_shutdown_helper();
Harald Welteea99a002018-01-31 20:46:43 +01005302}
5303
5304
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005305/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
5306private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01005307 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
5308 f_bssap_expect_nothing();
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005309 f_perform_clear();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005310}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005311testcase TC_unsol_ho_fail() runs on test_CT {
5312 var MSC_ConnHdlr vc_conn;
5313 f_init(1, true);
5314 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005315 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005316 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005317 f_shutdown_helper();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005318}
5319
5320
Harald Weltee3bd6582018-01-31 22:51:25 +01005321/* short message from MS should be ignored */
5322private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005323 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01005324 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01005325 /* we should now have a COMPL_L3 at the MSC */
Harald Weltee3bd6582018-01-31 22:51:25 +01005326
5327 /* send short message */
5328 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
5329 f_bssap_expect_nothing();
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005330 f_perform_clear();
Harald Weltee3bd6582018-01-31 22:51:25 +01005331}
5332testcase TC_err_82_short_msg() runs on test_CT {
5333 var MSC_ConnHdlr vc_conn;
5334 f_init(1, true);
5335 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005336 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01005337 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005338 f_shutdown_helper();
Harald Weltee3bd6582018-01-31 22:51:25 +01005339}
5340
5341
Harald Weltee9e02e42018-01-31 23:36:25 +01005342/* 24.008 8.4 Unknown message must trigger RR STATUS */
5343private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
5344 f_est_single_l3(ts_RRM_UL_REL('00'O));
5345 timer T := 3.0
5346 alt {
5347 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
5348 setverdict(pass);
5349 }
5350 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01005351 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01005352 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005353 f_perform_clear();
Harald Weltee9e02e42018-01-31 23:36:25 +01005354}
5355testcase TC_err_84_unknown_msg() runs on test_CT {
5356 var MSC_ConnHdlr vc_conn;
5357 f_init(1, true);
5358 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005359 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01005360 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005361 f_shutdown_helper();
Harald Weltee9e02e42018-01-31 23:36:25 +01005362}
5363
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005364/***********************************************************************
5365 * Handover
5366 ***********************************************************************/
5367
Harald Welte94e0c342018-04-07 11:33:23 +02005368/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
5369private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
5370runs on test_CT {
5371 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
5372 " timeslot "&int2str(ts_nr)&" ";
5373 f_vty_transceive(BSCVTY, cmd & suffix);
5374}
5375
Harald Welte261af4b2018-02-12 21:20:39 +01005376/* execute a "bts <0-255> trx <0-255> timeslot <0-7> sub-slot <0-7>" command on given Dchan */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005377private function f_vty_ss_action(TELNETasp_PT pt, charstring suffix,
5378 uint8_t bts_nr, uint8_t trx_nr,
5379 in RslChannelNr chan_nr)
5380{
Harald Welte261af4b2018-02-12 21:20:39 +01005381 /* FIXME: resolve those from component-global state */
5382 var integer ts_nr := chan_nr.tn;
5383 var integer ss_nr;
5384 if (ischosen(chan_nr.u.ch0)) {
5385 ss_nr := 0;
5386 } else if (ischosen(chan_nr.u.lm)) {
5387 ss_nr := chan_nr.u.lm.sub_chan;
5388 } else if (ischosen(chan_nr.u.sdcch4)) {
5389 ss_nr := chan_nr.u.sdcch4.sub_chan;
5390 } else if (ischosen(chan_nr.u.sdcch8)) {
5391 ss_nr := chan_nr.u.sdcch8.sub_chan;
5392 } else {
5393 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02005394 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01005395 }
5396
5397 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
5398 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005399 f_vty_transceive(pt, cmd & suffix);
Harald Welte261af4b2018-02-12 21:20:39 +01005400}
5401
Neels Hofmeyr91401012019-07-11 00:42:35 +02005402/* Even though the VTY command to trigger handover takes a new BTS number as argument, behind the scenes osmo-bsc always
5403 * translates that to a target ARFCN+BSIC first. See bsc_vty.c trigger_ho_or_as(), which puts the selected BTS' neighbor
5404 * ident key (ARFCN + BSIC) in the struct passed on to handover_request(). handover_start() then resolves that to a
5405 * viable actual neighbor cell. So from the internal osmo-bsc perspective, we always request handover to an ARFCN + BSIC
5406 * pair, not really to a specific BTS number. */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005407private function f_vty_handover(TELNETasp_PT pt, uint8_t bts_nr, uint8_t trx_nr,
5408 in RslChannelNr chan_nr, uint8_t new_bts_nr)
5409{
5410 f_vty_ss_action(pt, "handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
Harald Welte261af4b2018-02-12 21:20:39 +01005411}
5412
5413/* intra-BSC hand-over between BTS0 and BTS1 */
5414private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02005415 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5416 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01005417
5418 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5419 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5420
Harald Weltea0630032018-03-20 21:09:55 +01005421 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005422 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Harald Welte261af4b2018-02-12 21:20:39 +01005423
5424 var HandoverState hs := {
5425 rr_ho_cmpl_seen := false,
5426 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02005427 old_chan_nr := -,
5428 expect_target_tsc := BTS_TSC[1]
Harald Welte261af4b2018-02-12 21:20:39 +01005429 };
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005430 /* issue hand-over command on VTY, from BTS 0 to BTS 1 */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005431 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
Harald Welte261af4b2018-02-12 21:20:39 +01005432 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
5433 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005434
5435 /* From the MGW perspective, a handover is is characterized by
5436 * performing one MDCX operation with the MGW. So we expect to see
5437 * one more MDCX during handover. */
5438 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
5439
Harald Welte261af4b2018-02-12 21:20:39 +01005440 alt {
5441 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01005442 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005443
Philipp Maier4dae0652018-11-12 12:03:26 +01005444 /* Since this is an internal handover we expect the BSC to inform the
5445 * MSC about the event */
5446 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
5447
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005448 /* Check the amount of MGCP transactions is still consistant with the
5449 * test expectation */
5450 f_check_mgcp_expectations()
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005451
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005452 var RSL_Message chan_act := f_rslem_get_last_act(RSL1_PROC, 0, g_chan_nr);
5453
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005454 /* Ensure the Channel Activation for the new channel contained the right encryption params. as_handover() set
5455 * g_chan_nr to the new lchan that was handed over to. It lives in bts 1, so look it up at RSL1_PROC. */
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005456 f_verify_encr_info(chan_act);
5457
5458 f_chan_act_verify_tsc(chan_act, BTS_TSC[1]);
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005459
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005460 f_perform_clear(RSL1, RSL1_PROC);
5461
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01005462 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01005463}
5464
5465testcase TC_ho_int() runs on test_CT {
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02005466 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte261af4b2018-02-12 21:20:39 +01005467 var MSC_ConnHdlr vc_conn;
5468 f_init(2, true);
5469 f_sleep(1.0);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005470
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005471 pars.expect_tsc := BTS_TSC[0];
5472
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005473 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005474
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02005475 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
Harald Welte261af4b2018-02-12 21:20:39 +01005476 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005477
5478 /* from f_establish_fully() */
5479 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5480 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5481 /* from handover */
5482 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5483 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5484 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5485 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005486 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5487 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:completed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005488 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005489 f_shutdown_helper();
Harald Welte261af4b2018-02-12 21:20:39 +01005490}
Harald Weltee9e02e42018-01-31 23:36:25 +01005491
Oliver Smith7eabd312021-07-12 14:18:56 +02005492function f_tc_ho_int_a5(OCT1 encr_alg, charstring enc_a5 := "0 1 3") runs on test_CT {
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005493 var MSC_ConnHdlr vc_conn;
5494 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5495 pars.encr := valueof(t_EncrParams(encr_alg, f_rnd_octstring(8), f_rnd_octstring(16)));
5496
5497 f_init(2, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02005498 f_vty_encryption_a5(enc_a5);
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005499 f_sleep(1.0);
5500
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005501 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005502
5503 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
5504 vc_conn.done;
5505
5506 /* from f_establish_fully() */
5507 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5508 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5509 /* from handover */
5510 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5511 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5512 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5513 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005514 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5515 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:completed");
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005516 f_ctrs_bsc_and_bts_verify();
Oliver Smith7eabd312021-07-12 14:18:56 +02005517 f_vty_encryption_a5_reset();
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005518 f_shutdown_helper();
5519}
5520
5521testcase TC_ho_int_a5_0() runs on test_CT {
5522 f_tc_ho_int_a5('01'O);
5523}
5524
5525testcase TC_ho_int_a5_1() runs on test_CT {
5526 f_tc_ho_int_a5('02'O);
5527}
5528
5529testcase TC_ho_int_a5_3() runs on test_CT {
5530 f_tc_ho_int_a5('08'O);
5531}
5532
5533testcase TC_ho_int_a5_4() runs on test_CT {
Oliver Smith7eabd312021-07-12 14:18:56 +02005534 f_tc_ho_int_a5('10'O, "0 1 3 4");
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005535}
5536
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005537/* intra-BSC hand-over with CONNection FAILure and cause Radio Link Failure: check RR release cause */
5538private function f_tc_ho_int_radio_link_failure(charstring id) runs on MSC_ConnHdlr {
5539 g_pars := f_gen_test_hdlr_pars();
5540 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5541 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005542
5543 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5544 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5545
5546 f_establish_fully(ass_cmd, exp_compl);
5547 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
5548
5549 var HandoverState hs := {
5550 rr_ho_cmpl_seen := false,
5551 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02005552 old_chan_nr := -,
5553 expect_target_tsc := BTS_TSC[1]
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005554 };
5555 /* issue hand-over command on VTY */
5556 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
5557 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
5558 f_rslem_suspend(RSL1_PROC);
5559
5560 /* From the MGW perspective, a handover is is characterized by
5561 * performing one MDCX operation with the MGW. So we expect to see
5562 * one more MDCX during handover. */
5563 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
5564
5565 var RSL_Message rsl;
5566 var PDU_ML3_NW_MS l3;
5567 var RslChannelNr new_chan_nr;
5568 var GsmArfcn arfcn;
5569 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
5570 l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
5571 if (not ischosen(l3.msgs.rrm.handoverCommand)) {
5572 setverdict(fail, "Expected handoverCommand");
5573 mtc.stop;
5574 }
5575 }
5576 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
5577 new_chan_nr, arfcn);
5578
5579 f_rslem_register(0, new_chan_nr, RSL1_PROC);
5580
5581 /* resume processing of RSL DChan messages, which was temporarily suspended
5582 * before performing a hand-over */
5583 f_rslem_resume(RSL1_PROC);
5584 RSL1.receive(tr_RSL_IPA_CRCX(new_chan_nr));
5585
5586 f_sleep(1.0);
5587
5588 /* Handover fails because no HANDO DET appears on the new lchan,
5589 * and the old lchan reports a Radio Link Failure. */
5590 RSL.send(ts_RSL_CONN_FAIL_IND(g_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
5591
5592 var PDU_BSSAP rx_clear_request;
5593 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
5594 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5595 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5596
5597 var RR_Cause rr_cause := GSM48_RR_CAUSE_ABNORMAL_UNSPEC;
5598
5599 var MgcpCommand mgcp;
5600 interleave {
5601 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE(int2oct(enum2int(rr_cause), 1)))) {}
5602 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005603 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005604 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005605 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005606 }
5607 [] RSL1.receive(tr_RSL_DEACT_SACCH(new_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005608 [] RSL1.receive(tr_RSL_RF_CHAN_REL(new_chan_nr)) {
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005609 RSL1.send(ts_RSL_RF_CHAN_REL_ACK(new_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005610 f_rslem_unregister(0, g_chan_nr, PT := RSL1_PROC);
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005611 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005612 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
5613 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
5614 }
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005615 }
5616
5617 f_sleep(0.5);
5618 setverdict(pass);
5619}
5620testcase TC_ho_int_radio_link_failure() runs on test_CT {
5621 var MSC_ConnHdlr vc_conn;
5622 f_init(2, true);
5623 f_sleep(1.0);
5624
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005625 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005626
5627 vc_conn := f_start_handler(refers(f_tc_ho_int_radio_link_failure));
5628 vc_conn.done;
5629
5630 /* from f_establish_fully() */
5631 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5632 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5633 /* from handover */
5634 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5635 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
5636 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5637 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:stopped");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005638 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5639 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:stopped");
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005640 f_ctrs_bsc_and_bts_verify();
5641 f_shutdown_helper();
5642}
5643
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005644/* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005645private function f_expect_dlcx_conns() runs on MSC_ConnHdlr {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005646 var MgcpCommand mgcp;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005647 var template MgcpResponse mgcp_resp;
5648 var MGCP_RecvFrom mrf;
5649 var template MgcpMessage msg_resp;
5650 var template MgcpMessage msg_dlcx := {
5651 command := tr_DLCX()
5652 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005653
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005654 if (g_pars.aoip) {
5655 MGCP.receive(tr_DLCX()) -> value mgcp {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005656 log("Got first DLCX: ", mgcp);
5657 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005658 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005659
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005660 MGCP.receive(tr_DLCX()) -> value mgcp {
5661 log("Got second DLCX: ", mgcp);
5662 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
5663 };
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005664 } else {
5665 /* For SCCPLite, BSC doesn't handle the MSC-side */
5666 MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_dlcx)) -> value mrf {
5667 log("Got first DLCX: ", mrf.msg.command);
5668 msg_resp := {
5669 response := ts_DLCX_ACK2(mrf.msg.command.line.trans_id)
5670 }
5671 MGCP_MULTI.send(t_MGCP_SendToMrf(mrf, msg_resp));
5672 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005673 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005674}
5675
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005676private function f_ho_out_of_this_bsc(template (omit) BSSMAP_oldToNewBSSIEs exp_oldToNewBSSIEs := omit) runs on MSC_ConnHdlr {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005677
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005678 var NcellReports neighbor_rep := {
5679 { rxlev := 20, bcch_freq := 0, bsic := 11 }
5680 };
5681 var octetstring l3_mr := enc_GsmRrL3Message(valueof(ts_MEAS_REP(true, 8, 8, reps := neighbor_rep)));
5682 RSL.send(ts_RSL_MEAS_RES(g_chan_nr, 0, ts_RSL_IE_UplinkMeas, ts_RSL_IE_BS_Power(0), ts_RSL_IE_L1Info,
5683 l3_mr, 0));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005684
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005685 BSSAP.receive(tr_BSSMAP_HandoverRequired(exp_oldToNewBSSIEs));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005686
5687 f_sleep(0.5);
5688 /* The MSC negotiates Handover Request and Handover Request Ack with
5689 * the other BSS and comes back with a BSSMAP Handover Command
5690 * containing an RR Handover Command coming from the target BSS... */
5691
5692 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5693 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5694 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5695 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5696 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5697
5698 /* expect the Handover Command to go out on RR */
5699 var RSL_Message rsl_ho_cmd
5700 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5701 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5702 var RSL_IE_Body rsl_ho_cmd_l3;
5703 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5704 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5705 setverdict(fail);
5706 } else {
5707 log("Found L3 Info: ", rsl_ho_cmd_l3);
5708 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5709 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5710 setverdict(fail);
5711 } else {
5712 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5713 setverdict(pass);
5714 }
5715 }
5716
5717 /* When the other BSS has reported a completed handover, this side is
5718 * torn down. */
5719
5720 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
5721 var BssmapCause cause := enum2int(cause_val);
5722 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5723
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005724 f_expect_dlcx_conns();
Pau Espin Pedrol06199952021-06-15 11:30:00 +02005725
5726 interleave {
5727 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE));
5728 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr));
5729 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr));
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005730 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
5731 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
5732 }
Pau Espin Pedrol06199952021-06-15 11:30:00 +02005733 }
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005734 setverdict(pass);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005735}
5736
5737private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
5738 g_pars := f_gen_test_hdlr_pars();
5739 var PDU_BSSAP ass_req := f_gen_ass_req();
5740 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5741 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5742 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5743 f_establish_fully(ass_req, exp_compl);
5744
5745 f_ho_out_of_this_bsc();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005746}
5747testcase TC_ho_out_of_this_bsc() runs on test_CT {
5748 var MSC_ConnHdlr vc_conn;
5749
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005750 f_init_vty();
5751 f_bts_0_cfg(BSCVTY,
5752 {"neighbor-list mode automatic",
5753 "handover 1",
5754 "handover algorithm 2",
5755 "handover2 window rxlev averaging 1",
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005756 "no neighbors",
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005757 "neighbor lac 99 arfcn 123 bsic any"});
5758 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5759
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005760 f_init(1, true);
5761 f_sleep(1.0);
5762
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005763 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005764
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005765 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
5766 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005767
5768 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5769 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5770 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5771 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5772 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5773 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed");
5774 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005775 f_shutdown_helper();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005776}
5777
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005778private function f_mo_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5779 template (value) RslLinkId link_id := ts_RslLinkID_DCCH(0),
Vadim Yanitskiy2ef6a2f2020-10-08 23:17:32 +07005780 template (present) OCT1 dlci := ?,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005781 octetstring l3 := '0123456789'O)
5782runs on MSC_ConnHdlr {
Neels Hofmeyr43654812020-09-25 01:35:35 +02005783 /* The old lchan and conn should still be active. See that arbitrary L3
5784 * is still going through. */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005785 rsl.send(ts_RSL_DATA_IND(g_chan_nr, link_id, l3));
Neels Hofmeyr43654812020-09-25 01:35:35 +02005786 var template PDU_BSSAP exp_data := {
5787 discriminator := '1'B,
5788 spare := '0000000'B,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005789 dlci := dlci,
5790 lengthIndicator := lengthof(l3),
Neels Hofmeyr43654812020-09-25 01:35:35 +02005791 pdu := {
5792 dtap := l3
5793 }
5794 };
5795 BSSAP.receive(exp_data);
5796 setverdict(pass);
5797}
5798
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005799private function f_mt_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5800 template (present) RslLinkId link_id := tr_RslLinkID_DCCH(0),
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005801 template (value) OCT1 dlci := '00'O,
5802 octetstring l3 := '0123456789'O)
5803runs on MSC_ConnHdlr {
5804 BSSAP.send(PDU_BSSAP:{
5805 discriminator := '1'B,
5806 spare := '0000000'B,
5807 dlci := dlci,
5808 lengthIndicator := lengthof(l3),
5809 pdu := {
5810 dtap := l3
5811 }
5812 });
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005813 rsl.receive(tr_RSL_DATA_REQ(g_chan_nr, link_id, l3));
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005814 setverdict(pass);
5815}
5816
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005817/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
5818 * simply never sends a BSSMAP Handover Command. */
5819private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005820 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005821
5822 var PDU_BSSAP ass_req := f_gen_ass_req();
5823 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5824 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5825 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5826 f_establish_fully(ass_req, exp_compl);
5827
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005828 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005829 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5830
5831 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5832
5833 /* osmo-bsc should time out 10 seconds after the handover started.
5834 * Let's give it a bit extra. */
5835 f_sleep(15.0);
5836
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005837 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005838 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005839 f_perform_clear();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005840}
5841testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
5842 var MSC_ConnHdlr vc_conn;
5843
5844 f_init(1, true);
5845 f_sleep(1.0);
5846
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005847 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005848
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005849 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
5850 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005851
5852 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5853 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5854 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5855 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5856 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5857 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5858 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005859 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005860}
5861
5862/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
5863 * RR Handover Failure. */
5864private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005865 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005866
5867 var PDU_BSSAP ass_req := f_gen_ass_req();
5868 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5869 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5870 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5871 f_establish_fully(ass_req, exp_compl);
5872
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005873 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005874 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5875
5876 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5877
5878 f_sleep(0.5);
5879 /* The MSC negotiates Handover Request and Handover Request Ack with
5880 * the other BSS and comes back with a BSSMAP Handover Command
5881 * containing an RR Handover Command coming from the target BSS... */
5882
5883 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5884 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5885 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5886 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5887 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5888
5889 /* expect the Handover Command to go out on RR */
5890 var RSL_Message rsl_ho_cmd
5891 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5892 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5893 var RSL_IE_Body rsl_ho_cmd_l3;
5894 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5895 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5896 setverdict(fail);
5897 } else {
5898 log("Found L3 Info: ", rsl_ho_cmd_l3);
5899 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5900 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5901 setverdict(fail);
5902 } else {
5903 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5904 setverdict(pass);
5905 }
5906 }
5907
5908 f_sleep(0.2);
5909 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
5910
5911 /* Should tell the MSC about the failure */
5912 BSSAP.receive(tr_BSSMAP_HandoverFailure);
5913
5914 f_sleep(1.0);
5915
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005916 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005917 f_sleep(1.0);
5918
5919 setverdict(pass);
5920 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005921 f_perform_clear();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005922}
5923testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
5924 var MSC_ConnHdlr vc_conn;
5925
5926 f_init(1, true);
5927 f_sleep(1.0);
5928
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005929 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005930
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005931 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
5932 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005933
5934 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5935 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5936 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5937 f_ctrs_bsc_and_bts_add(0, "handover:failed");
5938 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5939 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:failed");
5940 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005941 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005942}
5943
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005944/* BSC asks for inter-BSC-out HO, receives BSSMAP Handover Command, but then no reply is received about HO outcome
5945 * (neither BSSMAP Clear Command for success nor RR Handover Failure). 48.008 3.1.5.3.3 "Abnormal Conditions" applies
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02005946 * and the lchan is released. */
5947private function f_tc_ho_out_fail_no_result_after_ho_cmd(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005948 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005949
5950 var PDU_BSSAP ass_req := f_gen_ass_req();
5951 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5952 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5953 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5954 f_establish_fully(ass_req, exp_compl);
5955
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005956 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005957 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5958
5959 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5960
5961 f_sleep(0.5);
5962 /* The MSC negotiates Handover Request and Handover Request Ack with
5963 * the other BSS and comes back with a BSSMAP Handover Command
5964 * containing an RR Handover Command coming from the target BSS... */
5965
5966 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5967 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5968 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5969 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5970 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5971
5972 /* expect the Handover Command to go out on RR */
5973 var RSL_Message rsl_ho_cmd
5974 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5975 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5976 var RSL_IE_Body rsl_ho_cmd_l3;
5977 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5978 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5979 setverdict(fail);
5980 } else {
5981 log("Found L3 Info: ", rsl_ho_cmd_l3);
5982 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5983 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5984 setverdict(fail);
5985 } else {
5986 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5987 setverdict(pass);
5988 }
5989 }
5990
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005991 /* We get neither success nor failure report from the remote BSS. Eventually T8 times out and we run into 3GPP
5992 * TS 48.008 3.1.5.3.3 "Abnormal Conditions": Clear Request should go to the MSC, and RR should be released
5993 * after Clear Command */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005994
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005995 var PDU_BSSAP rx_clear_request;
Neels Hofmeyre1797aa2019-07-09 19:34:04 +02005996 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
5997 log("Got BSSMAP Clear Request");
5998 /* Instruct BSC to clear channel */
5999 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
6000 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6001
6002 var MgcpCommand mgcp;
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02006003 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01006004 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
6005 log("Got Deact SACCH");
6006 }
Harald Welte924b6ea2019-02-04 01:05:34 +01006007 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01006008 log("Got RR Release");
6009 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02006010 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02006011 log("Got RF Chan Rel");
6012 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02006013 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02006014 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02006015 }
6016
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006017 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006018 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006019 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02006020
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02006021 setverdict(pass);
6022 f_sleep(1.0);
6023}
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02006024testcase TC_ho_out_fail_no_result_after_ho_cmd() runs on test_CT {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02006025 var MSC_ConnHdlr vc_conn;
6026
6027 f_init(1, true);
6028 f_sleep(1.0);
6029
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006030 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006031
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02006032 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_result_after_ho_cmd));
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02006033 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006034
6035 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6036 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6037 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6038 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
6039 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
6040 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
6041 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006042 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02006043}
6044
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006045private function f_ho_into_this_bsc(charstring id, template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit) runs on MSC_ConnHdlr {
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006046 var PDU_BSSAP rx_bssap;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006047 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
6048 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
6049 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
6050 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
6051 * before we get started. */
6052 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6053 f_rslem_register(0, new_chan_nr);
6054 g_chan_nr := new_chan_nr;
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02006055 var uint3_t expect_target_tsc := BTS_TSC[0];
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006056 f_sleep(1.0);
6057
6058 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6059 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
Neels Hofmeyr2677b872022-04-12 01:44:43 +02006060 var default as_media := activate(as_Media());
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006061
Neels Hofmeyra23f3b12022-03-02 19:57:12 +01006062 var PDU_BSSAP ho_req := f_gen_handover_req(aoip_tla := g_pars.host_aoip_tla,
6063 cell_id_source := g_pars.cell_id_source,
6064 oldToNewBSSIEs := oldToNewBSSIEs,
6065 enc := g_pars.encr);
6066 if (g_pars.inter_bsc_ho_in__ho_req_in_initial_sccp_cr) {
6067 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc, ho_req));
6068 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
6069 } else {
6070 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc, omit));
6071 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
6072 BSSAP.send(ho_req);
6073 }
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006074
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006075 alt {
6076 [] BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap {
6077 if (g_pars.expect_ho_fail) {
6078 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6079 "Expected Handover Request to fail, but got Handover Request Ack")
6080 }
6081 }
6082 [] BSSAP.receive(tr_BSSMAP_HandoverFailure) -> value rx_bssap {
6083 if (not g_pars.expect_ho_fail) {
6084 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6085 "Expected Handover Request to succeed, but got Handover Failure")
6086 }
6087 // TODO: evaluate correct cause value. But osmo-bsc doesn't seem to send meaningful causes yet!
6088 // For now just accept any cause.
6089 BSSAP.receive(tr_BSSMAP_ClearRequest);
6090 setverdict(pass);
6091 return;
6092 }
6093 }
6094
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006095 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6096
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02006097 /* we're sure that the channel activation is done now, verify the parameters in it */
6098 var RSL_Message chan_act := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
6099 f_verify_encr_info(chan_act);
6100 f_chan_act_verify_tsc(chan_act, expect_target_tsc);
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006101
Neels Hofmeyr46e16e52022-02-23 17:04:00 +01006102 if (ispresent(rx_bssap.pdu.bssmap.handoverRequestAck.codecList)) {
6103 if (not g_pars.aoip) {
6104 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6105 "handoverRequestAck: Expected no Speech Codec List (BSS Supported), because this is not AoIP");
6106 }
6107 /* TODO: check actual codecs? */
6108 } else {
6109 if (g_pars.aoip) {
6110 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6111 "handoverRequestAck: Expected Speech Codec List (BSS Supported), but none found");
6112 }
6113 }
6114
6115 if (ispresent(rx_bssap.pdu.bssmap.handoverRequestAck.speechCodec)) {
6116 if (not g_pars.aoip) {
6117 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6118 "handoverRequestAck: Expected no Speech Codec (Chosen), because this is not AoIP");
6119 }
6120 /* TODO: check actual codec? */
6121 } else {
6122 if (g_pars.aoip) {
6123 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6124 "handoverRequestAck: Expected Speech Codec (Chosen), but none found");
6125 }
6126 }
6127
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006128 var octetstring ho_command_str;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006129 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6130 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6131 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6132 log("L3 Info in HO Request Ack is ", ho_command);
6133
6134 var GsmArfcn arfcn;
6135 var RslChannelNr actual_new_chan_nr;
6136 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6137 actual_new_chan_nr, arfcn);
6138
6139 if (actual_new_chan_nr != new_chan_nr) {
6140 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6141 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6142 setverdict(fail);
6143 return;
6144 }
6145 log("Handover Command chan_nr is", actual_new_chan_nr);
6146
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02006147 var uint3_t got_tsc := rr_chan_desc_tsc(ho_command.msgs.rrm.handoverCommand.channelDescription2);
6148 if (not match(got_tsc, expect_target_tsc)) {
6149 setverdict(fail, "RR Handover Command: unexpected TSC in Channel Description: expected ",
6150 expect_target_tsc, " got ", got_tsc);
6151 mtc.stop;
6152 } else {
6153 log("handoverCommand: verified TSC = ", got_tsc);
6154 }
6155
Vadim Yanitskiy634f75d2022-03-14 17:04:45 +03006156 /* Check the Cipher Mode Setting IE (shall be present during inter-RAT handover) */
6157 if (ispresent(ho_command.msgs.rrm.handoverCommand.cipherModeSetting)) {
6158 var CipherModeSetting_TV cms := ho_command.msgs.rrm.handoverCommand.cipherModeSetting;
6159 var template (present) CipherModeSetting_TV tr_cms := {
6160 sC := '0'B, /* no ciphering by default */
6161 algorithmIdentifier := '000'B,
6162 elementIdentifier := ?
6163 };
6164 if (ispresent(g_pars.encr) and g_pars.encr.enc_alg_expect != '01'O) { /* A5/N */
6165 tr_cms.algorithmIdentifier := f_cipher_mode_bssmap_to_rr(g_pars.encr.enc_alg_expect);
6166 tr_cms.sC := '1'B;
6167 }
6168 if (not match(cms, tr_cms)) {
6169 setverdict(fail, "RR Handover Command: unexpected Cipher Mode Setting IE: ",
6170 cms, ", expected: ", tr_cms);
6171 }
6172 } else {
6173 setverdict(fail, "RR Handover Command: Cipher Mode Setting IE is not present");
6174 }
6175
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006176 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6177 * tells the MS to handover to the new lchan. Here comes the new MS on
6178 * the new lchan with a Handover RACH: */
6179
6180 /* send handover detect */
6181
6182 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
6183
6184 BSSAP.receive(tr_BSSMAP_HandoverDetect);
6185
6186 /* send handover complete over the new channel */
6187
6188 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
6189 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
6190 enc_PDU_ML3_MS_NW(l3_tx)));
6191
6192 BSSAP.receive(tr_BSSMAP_HandoverComplete);
Neels Hofmeyr2677b872022-04-12 01:44:43 +02006193 deactivate(as_media);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006194 setverdict(pass);
6195}
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006196
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006197private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006198 var template PDU_ML3_NW_MS exp_rr_rel_tmpl;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006199 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit;
6200 if (not istemplatekind(g_pars.last_used_eutran_plmn, "omit")) {
6201 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006202 }
6203 if (g_pars.exp_fast_return) {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006204 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE_CellSelectInd;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006205 } else {
6206 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006207 }
6208 f_ho_into_this_bsc(id, oldToNewBSSIEs);
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006209 if (g_pars.expect_ho_fail) {
6210 f_perform_clear_no_lchan();
6211 } else {
6212 f_perform_clear(exp_rr_rel_tmpl := exp_rr_rel_tmpl);
6213 }
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006214 setverdict(pass);
6215}
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01006216function f_tc_ho_into_this_bsc_main(TestHdlrParams pars, charstring vty_a5_cfg := VTY_A5_DEFAULT) runs on test_CT {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006217 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006218
6219 f_init(1, true);
6220 f_sleep(1.0);
6221
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01006222 f_vty_encryption_a5(vty_a5_cfg);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006223 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006224
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006225 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6226 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006227
6228 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
6229 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006230
6231 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006232 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006233 if (pars.expect_ho_fail) {
6234 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6235 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:failed");
6236 } else {
6237 f_ctrs_bsc_and_bts_add(0, "handover:completed");
6238 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed");
6239 }
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006240 f_ctrs_bsc_and_bts_verify();
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01006241
6242 f_vty_encryption_a5_reset();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006243}
6244
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006245testcase TC_ho_into_this_bsc() runs on test_CT {
6246 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6247 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006248 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006249}
6250
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006251function f_tc_ho_into_this_bsc_a5(TestHdlrEncrParams encr, charstring vty_a5_cfg := VTY_A5_DEFAULT,
6252 boolean expect_fail := false) runs on test_CT {
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006253 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01006254 pars.encr := encr;
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006255 pars.expect_ho_fail := expect_fail;
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01006256 f_tc_ho_into_this_bsc_main(pars, vty_a5_cfg);
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006257 f_shutdown_helper();
6258}
6259
6260testcase TC_ho_into_this_bsc_a5_0() runs on test_CT {
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01006261 f_tc_ho_into_this_bsc_a5(f_encr_params('01'O));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006262}
6263
6264testcase TC_ho_into_this_bsc_a5_1() runs on test_CT {
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01006265 f_tc_ho_into_this_bsc_a5(f_encr_params('02'O));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006266}
6267
6268testcase TC_ho_into_this_bsc_a5_3() runs on test_CT {
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01006269 f_tc_ho_into_this_bsc_a5(f_encr_params('08'O));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006270}
6271
6272testcase TC_ho_into_this_bsc_a5_4() runs on test_CT {
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01006273 f_tc_ho_into_this_bsc_a5(f_encr_params('10'O, kc128 := true), "3 4");
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006274}
6275
Neels Hofmeyr1951be22022-02-16 16:21:07 +01006276/* Report: in inter-BSC incoming handover, when the MSC omits the Chosen Encryption Algorithm IE in the Handover Request
6277 * message, then osmo-bsc starts an unencrypted lchan even if A5/0 is not permitted.
6278 *
6279 * This test verifies that the Encryption Information is present in the Channel Activation when the Chosen Enc Alg is
6280 * omitted.
6281 *
6282 * Related: SYS#5839
6283 */
6284testcase TC_ho_into_this_bsc_a5_1_3_no_chosen_enc_alg() runs on test_CT {
6285 f_tc_ho_into_this_bsc_a5(f_encr_params(alg_permitted := '0a'O, alg_expect := '08'O, alg_chosen := omit));
6286}
6287
6288testcase TC_ho_into_this_bsc_a5_1_3() runs on test_CT {
6289 f_tc_ho_into_this_bsc_a5(f_encr_params(alg_permitted := '0a'O, alg_expect := '08'O));
6290}
6291
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006292/* Send a permitted algo mask that does not intersect with osmo-bsc.cfg */
6293testcase TC_ho_into_this_bsc_a5_mismatch() runs on test_CT {
6294 f_tc_ho_into_this_bsc_a5(f_encr_params(alg_permitted := '18'O, alg_expect := '10'O), "0 1",
6295 expect_fail := true); // 0x18 = A5/3 and A5/4
6296}
6297
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006298testcase TC_ho_into_this_bsc_tla_v6() runs on test_CT {
6299 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6300 pars.host_aoip_tla := "::6";
6301 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006302 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006303}
6304
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006305/* Similar to TC_ho_into_this_bsc, but when in SRVCC, HO Req contains "Old BSS
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006306 to New BSS Information" IE with "Last Used E-UTRAN PLMN Id", which, when the
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006307 channel is later released (RR CHannel Release), should trigger inclusion of
6308 IE "Cell Selection Indicator after Release of all TCH and SDCCH" with E-UTRAN
6309 neighbors. */
6310testcase TC_srvcc_eutran_to_geran() runs on test_CT {
6311 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6312 pars.last_used_eutran_plmn := '323454'O;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006313 pars.exp_fast_return := true;
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006314 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02006315
6316 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted");
6317 f_ctrs_bsc_and_bts_add(0, "srvcc:completed");
6318 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006319 f_shutdown_helper();
6320}
6321
Vadim Yanitskiy634f75d2022-03-14 17:04:45 +03006322/* Same as TC_srvcc_eutran_to_geran, but enables ciphering on the target channel. */
6323testcase TC_srvcc_eutran_to_geran_a5_3() runs on test_CT {
6324 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6325 pars.encr := f_encr_params('08'O); /* only A5/3 */
6326 pars.last_used_eutran_plmn := '323454'O;
6327 pars.exp_fast_return := true;
6328 f_tc_ho_into_this_bsc_main(pars);
6329
6330 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted");
6331 f_ctrs_bsc_and_bts_add(0, "srvcc:completed");
6332 f_ctrs_bsc_and_bts_verify();
6333 f_shutdown_helper();
6334}
6335
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006336/* Same as TC_srvcc_eutran_to_geran, but test explicitly forbiding fast return
6337 on the BTS. As a result, RR Release shouldn't contain the EUTRAN neighbor
6338 list when the channel is released. */
6339testcase TC_srvcc_eutran_to_geran_forbid_fast_return() runs on test_CT {
6340 f_init_vty();
6341 f_vty_allow_srvcc_fast_return(true, 0)
6342
6343 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6344 pars.last_used_eutran_plmn := '323454'O;
6345 pars.exp_fast_return := false;
6346 f_tc_ho_into_this_bsc_main(pars);
6347 f_vty_allow_srvcc_fast_return(false, 0);
6348 f_shutdown_helper();
6349}
6350
Pau Espin Pedrola8ef3be2022-02-16 16:21:17 +01006351/* Same as TC_srvcc_eutran_to_geran, but using SAI as serving Cell Identifier. SYS#5838 */
6352testcase TC_srvcc_eutran_to_geran_src_sai() runs on test_CT {
6353 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6354 pars.last_used_eutran_plmn := '323454'O;
6355 pars.cell_id_source := valueof(ts_CellID_SAI('123456'O, 300, 444));
6356 f_tc_ho_into_this_bsc_main(pars);
6357
6358 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted");
6359 f_ctrs_bsc_and_bts_add(0, "srvcc:completed");
6360 f_ctrs_bsc_and_bts_verify();
6361 f_shutdown_helper();
6362}
6363
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006364private function f_tc_srvcc_eutran_to_geran_ho_out(charstring id) runs on MSC_ConnHdlr {
6365 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs;
6366 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
6367 f_ho_into_this_bsc(id, oldToNewBSSIEs);
6368 f_ho_out_of_this_bsc(oldToNewBSSIEs);
6369 setverdict(pass);
6370}
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006371
6372private function f_tc_srvcc_eutran_to_geran_ho_out_main(boolean disable_fast_return)
6373 runs on test_CT {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006374 var MSC_ConnHdlr vc_conn;
6375 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6376
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01006377 f_init_vty();
6378 f_bts_0_cfg(BSCVTY,
6379 {"neighbor-list mode automatic",
6380 "handover 1",
6381 "handover algorithm 2",
6382 "handover2 window rxlev averaging 1",
6383 "no neighbors",
6384 "neighbor lac 99 arfcn 123 bsic any"});
6385 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6386
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006387 f_init(1, true);
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006388 if (disable_fast_return) {
6389 f_vty_allow_srvcc_fast_return(true, 0);
6390 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006391 f_sleep(1.0);
6392
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006393 f_ctrs_bsc_and_bts_handover_init();
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006394
6395 pars.last_used_eutran_plmn := '323454'O;
6396 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6397 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
6398
6399 vc_conn := f_start_handler(refers(f_tc_srvcc_eutran_to_geran_ho_out), pars);
6400 vc_conn.done;
6401
6402 f_ctrs_bsc_and_bts_add(0, "handover:attempted", 2);
6403 f_ctrs_bsc_and_bts_add(0, "handover:completed", 2);
6404 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted", 1);
6405 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed", 1);
6406 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted", 1);
6407 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed", 1);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02006408
6409 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted", 1);
6410 f_ctrs_bsc_and_bts_add(0, "srvcc:completed", 1);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006411 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006412
6413 if (disable_fast_return) {
6414 f_vty_allow_srvcc_fast_return(false, 0);
6415 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006416 f_shutdown_helper();
6417}
6418
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006419/* First, HO into BSC from EUTRAN (SRVCC): HO Request contains "Old BSS to New
6420 BSS Information" IE with "Last Used E-UTRAN PLMN Id".
6421 Second, HO to another BSC: HO Required contains "Old BSS to New BSS Information"
6422 IE with "Last Used E-UTRAN PLMN Id" from first step. */
6423testcase TC_srvcc_eutran_to_geran_ho_out() runs on test_CT {
6424 f_tc_srvcc_eutran_to_geran_ho_out_main(false);
6425}
6426/* Validate subsequent intra-GSM-HO works the same (with OldBSSToNewBSSInfo IE)
6427 * independently of fast-reture allowed/forbidden in local BTS */
6428testcase TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() runs on test_CT {
6429 f_tc_srvcc_eutran_to_geran_ho_out_main(true);
6430}
6431
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006432private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
6433 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6434 f_rslem_register(0, new_chan_nr);
6435 g_chan_nr := new_chan_nr;
6436 f_sleep(1.0);
6437
6438 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6439 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6440 activate(as_Media());
6441
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006442 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006443 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006444 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006445
6446 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6447
6448 var PDU_BSSAP rx_bssap;
6449 var octetstring ho_command_str;
6450
6451 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6452
6453 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6454 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6455 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6456 log("L3 Info in HO Request Ack is ", ho_command);
6457
6458 var GsmArfcn arfcn;
6459 var RslChannelNr actual_new_chan_nr;
6460 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6461 actual_new_chan_nr, arfcn);
6462
6463 if (actual_new_chan_nr != new_chan_nr) {
6464 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6465 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6466 setverdict(fail);
6467 return;
6468 }
6469 log("Handover Command chan_nr is", actual_new_chan_nr);
6470
Neels Hofmeyr61ca08d2019-05-06 23:52:22 +02006471 /* For deterministic test results, give some time for the MGW endpoint to be configured */
6472 f_sleep(1.0);
6473
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006474 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6475 * tells the MS to handover to the new lchan. In this case, the MS
6476 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
6477 * Handover Failure to the MSC. The procedure according to 3GPP TS
6478 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
6479 * BSSMAP Clear Command: */
6480
6481 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6482 var BssmapCause cause := enum2int(cause_val);
6483 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6484
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006485 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006486 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006487 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006488
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006489 setverdict(pass);
6490 f_sleep(1.0);
6491
6492 setverdict(pass);
6493}
6494testcase TC_ho_in_fail_msc_clears() runs on test_CT {
6495 var MSC_ConnHdlr vc_conn;
6496 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6497
6498 f_init(1, true);
6499 f_sleep(1.0);
6500
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006501 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006502
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006503 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6504 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006505
6506 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
6507 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006508
6509 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6510 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
6511 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6512 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
6513 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006514 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006515}
6516
6517private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
6518 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
6519 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
6520 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
6521 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
6522 * before we get started. */
6523 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6524 f_rslem_register(0, new_chan_nr);
6525 g_chan_nr := new_chan_nr;
6526 f_sleep(1.0);
6527
6528 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6529 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6530 activate(as_Media());
6531
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006532 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006533 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006534 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006535
6536 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6537
6538 var PDU_BSSAP rx_bssap;
6539 var octetstring ho_command_str;
6540
6541 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6542
6543 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6544 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6545 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6546 log("L3 Info in HO Request Ack is ", ho_command);
6547
6548 var GsmArfcn arfcn;
6549 var RslChannelNr actual_new_chan_nr;
6550 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6551 actual_new_chan_nr, arfcn);
6552
6553 if (actual_new_chan_nr != new_chan_nr) {
6554 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6555 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6556 setverdict(fail);
6557 return;
6558 }
6559 log("Handover Command chan_nr is", actual_new_chan_nr);
6560
6561 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6562 * tells the MS to handover to the new lchan. Here comes the new MS on
6563 * the new lchan with a Handover RACH: */
6564
6565 /* send handover detect */
6566
6567 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
6568
6569 BSSAP.receive(tr_BSSMAP_HandoverDetect);
6570
6571 /* The MSC chooses to clear the connection now, maybe we got the
6572 * Handover RACH on the new cell but the MS still signaled Handover
6573 * Failure to the old BSS? */
6574
6575 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6576 var BssmapCause cause := enum2int(cause_val);
6577 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6578
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006579 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006580 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006581 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006582
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006583 f_sleep(1.0);
6584}
6585testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
6586 var MSC_ConnHdlr vc_conn;
6587 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6588
6589 f_init(1, true);
6590 f_sleep(1.0);
6591
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006592 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006593
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006594 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6595 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006596
6597 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
6598 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006599
6600 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6601 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
6602 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6603 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
6604 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006605 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006606}
6607
6608/* The new BSS's lchan times out before the MSC decides that handover failed. */
6609private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
6610 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6611 f_rslem_register(0, new_chan_nr);
6612 g_chan_nr := new_chan_nr;
6613 f_sleep(1.0);
6614
6615 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6616 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
Neels Hofmeyr9b320c12022-04-07 00:19:01 +02006617 activate(as_Media(fail_on_dlcx := false));
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006618
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006619 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006620 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006621 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006622
6623 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6624
6625 var PDU_BSSAP rx_bssap;
6626 var octetstring ho_command_str;
6627
6628 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6629
6630 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6631 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6632 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6633 log("L3 Info in HO Request Ack is ", ho_command);
6634
6635 var GsmArfcn arfcn;
6636 var RslChannelNr actual_new_chan_nr;
6637 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6638 actual_new_chan_nr, arfcn);
6639
6640 if (actual_new_chan_nr != new_chan_nr) {
6641 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6642 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6643 setverdict(fail);
6644 return;
6645 }
6646 log("Handover Command chan_nr is", actual_new_chan_nr);
6647
6648 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6649 * tells the MS to handover to the new lchan. But the MS never shows up
6650 * on the new lchan. */
6651
6652 BSSAP.receive(tr_BSSMAP_HandoverFailure);
6653
6654 /* Did osmo-bsc also send a Clear Request? */
6655 timer T := 0.5;
6656 T.start;
6657 alt {
6658 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
6659 [] T.timeout { }
6660 }
6661
6662 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
6663 * asked for it, this is a Handover Failure after all). */
6664
6665 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6666 var BssmapCause cause := enum2int(cause_val);
6667 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6668
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006669 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006670 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006671 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006672
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006673 f_sleep(1.0);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006674}
6675testcase TC_ho_in_fail_no_detect() runs on test_CT {
6676 var MSC_ConnHdlr vc_conn;
6677 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6678
6679 f_init(1, true);
6680 f_sleep(1.0);
6681
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006682 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006683
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006684 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6685 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006686
6687 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
6688 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006689
6690 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6691 f_ctrs_bsc_and_bts_add(0, "handover:error");
6692 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6693 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
6694 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006695 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006696}
6697
6698/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
6699private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
6700 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6701 f_rslem_register(0, new_chan_nr);
6702 g_chan_nr := new_chan_nr;
6703 f_sleep(1.0);
6704
6705 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6706 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
Neels Hofmeyr9b320c12022-04-07 00:19:01 +02006707 activate(as_Media(fail_on_dlcx := false));
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006708
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006709 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006710 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006711 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006712
6713 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6714
6715 var PDU_BSSAP rx_bssap;
6716 var octetstring ho_command_str;
6717
6718 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6719
6720 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6721 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6722 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6723 log("L3 Info in HO Request Ack is ", ho_command);
6724
6725 var GsmArfcn arfcn;
6726 var RslChannelNr actual_new_chan_nr;
6727 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6728 actual_new_chan_nr, arfcn);
6729
6730 if (actual_new_chan_nr != new_chan_nr) {
6731 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6732 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6733 setverdict(fail);
6734 return;
6735 }
6736 log("Handover Command chan_nr is", actual_new_chan_nr);
6737
6738 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6739 * tells the MS to handover to the new lchan. But the MS never shows up
6740 * on the new lchan. */
6741
6742 BSSAP.receive(tr_BSSMAP_HandoverFailure);
6743
6744 /* MSC plays dumb and sends no Clear Command */
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006745 var PDU_BSSAP rx_clear_request;
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02006746
6747 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006748 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
6749 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6750 };
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006751 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006752 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006753 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006754
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006755 f_sleep(1.0);
6756}
6757testcase TC_ho_in_fail_no_detect2() runs on test_CT {
6758 var MSC_ConnHdlr vc_conn;
6759 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6760
6761 f_init(1, true);
6762 f_sleep(1.0);
6763
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006764 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006765
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006766 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6767 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006768
6769 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
6770 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006771
6772 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6773 f_ctrs_bsc_and_bts_add(0, "handover:error");
6774 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6775 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
6776 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006777 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006778}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006779
Neels Hofmeyra23f3b12022-03-02 19:57:12 +01006780/* An incoming inter-BSC HO can either issue the Handover Request message attached to the initial SCCP N-Connect (as in
6781 * the other tests we have so far), or the first CR can be "empty" with the BSSAP request following later. Test the
6782 * empty N-Connect case. */
6783testcase TC_ho_into_this_bsc_sccp_cr_without_bssap() runs on test_CT {
6784 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6785 pars.inter_bsc_ho_in__ho_req_in_initial_sccp_cr := false;
6786 f_tc_ho_into_this_bsc_main(pars);
6787 f_shutdown_helper();
6788}
6789
Neels Hofmeyr91401012019-07-11 00:42:35 +02006790type record of charstring Commands;
6791
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006792private function f_bts_0_cfg(TELNETasp_PT pt, Commands cmds := {})
Neels Hofmeyr91401012019-07-11 00:42:35 +02006793{
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006794 f_vty_enter_cfg_bts(pt, 0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006795 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006796 f_vty_transceive(pt, cmds[i]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006797 }
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006798 f_vty_transceive(pt, "end");
Neels Hofmeyr91401012019-07-11 00:42:35 +02006799}
6800
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01006801private function f_cs7_inst_0_cfg(TELNETasp_PT pt, Commands cmds := {})
6802{
6803 f_vty_enter_cfg_cs7_inst(pt, 0);
6804 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
6805 f_vty_transceive(pt, cmds[i]);
6806 }
6807 f_vty_transceive(pt, "end");
6808}
6809
Neels Hofmeyr91401012019-07-11 00:42:35 +02006810private function f_probe_for_handover(charstring log_label,
6811 charstring log_descr,
6812 charstring handover_vty_cmd,
6813 boolean expect_handover,
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006814 boolean is_inter_bsc_handover := false,
6815 template uint3_t expect_target_tsc := ?)
Neels Hofmeyr91401012019-07-11 00:42:35 +02006816runs on MSC_ConnHdlr
6817{
Neels Hofmeyrb3fc8982020-05-11 00:16:42 +02006818 /* We're going to thwart any and all handover attempts, just be ready to handle (and ignore) handover target
6819 * lchans to be established on bts 1 or bts 2. */
6820 f_rslem_suspend(RSL1_PROC);
6821 f_rslem_suspend(RSL2_PROC);
6822
Neels Hofmeyr91401012019-07-11 00:42:35 +02006823 var RSL_Message rsl;
6824
6825 var charstring log_msg := " (expecting handover)"
6826 if (not expect_handover) {
6827 log_msg := " (expecting NO handover)";
6828 }
6829 log("f_probe_for_handover starting: " & log_label & ": " & log_descr & log_msg);
6830 f_vty_transceive(BSCVTY, handover_vty_cmd);
6831
Neels Hofmeyr91401012019-07-11 00:42:35 +02006832 timer T := 2.0;
6833 T.start;
6834
6835 alt {
6836 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
6837 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
6838 log("Rx L3 from net: ", l3);
6839 if (ischosen(l3.msgs.rrm.handoverCommand)) {
6840 var RslChannelNr new_chan_nr;
6841 var GsmArfcn arfcn;
6842 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
6843 new_chan_nr, arfcn);
6844 log("Handover to new chan ", new_chan_nr, " on ARFCN ", arfcn);
6845 log(l3.msgs.rrm.handoverCommand);
6846
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006847 /* Verify correct TSC in handoverCommand */
6848 var uint3_t got_tsc := rr_chan_desc_tsc(l3.msgs.rrm.handoverCommand.channelDescription2);
6849 if (not match(got_tsc, expect_target_tsc)) {
6850 setverdict(fail, "RR Handover Command: unexpected TSC in Channel Description: expected ",
6851 expect_target_tsc, " got ", got_tsc);
6852 mtc.stop;
6853 } else {
6854 log("handoverCommand: verified TSC = ", got_tsc, " (matches ",
6855 expect_target_tsc, ")");
6856 }
6857
Neels Hofmeyr91401012019-07-11 00:42:35 +02006858 /* Need to register for new lchan on new BTS -- it's either bts 1 or bts 2. It doesn't really
6859 * matter on which BTS it really is, we're not going to follow through an entire handover
6860 * anyway. */
6861 f_rslem_register(0, new_chan_nr, RSL1_PROC);
6862 f_rslem_resume(RSL1_PROC);
6863 f_rslem_register(0, new_chan_nr, RSL2_PROC);
6864 f_rslem_resume(RSL2_PROC);
6865
6866 if (expect_handover and not is_inter_bsc_handover) {
6867 setverdict(pass);
6868 log("f_probe_for_handover(" & log_label & "): Got RSL Handover Command as expected.");
6869 } else {
6870 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got RSL Handover Command. "
6871 & log_label & ": " & log_descr);
6872 }
6873
6874 log("f_probe_for_handover(" & log_label & "): Ending the test: Handover Failure stops the procedure.");
6875 /* osmo-bsc has triggered Handover. That's all we need to know for this test, reply with
6876 * Handover Failure. */
6877 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
6878
6879 /* target BTS is told to release lchan again; don't care which BTS nor what messages. */
6880 f_sleep(0.5);
6881 RSL1.clear;
6882 RSL2.clear;
6883 log("f_probe_for_handover(" & log_label & "): done (got RSL Handover Command)");
6884 break;
6885 } else {
6886 repeat;
6887 }
6888 }
6889 [] BSSAP.receive(tr_BSSMAP_HandoverRequired) {
6890 if (expect_handover and is_inter_bsc_handover) {
6891 setverdict(pass);
6892 log("f_probe_for_handover(" & log_label & "): Got BSSMAP Handover Required as expected.");
6893 } else {
6894 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got BSSMAP Handover Required. "
6895 & log_label & ": " & log_descr);
6896 }
6897
6898 log("f_probe_for_handover(" & log_label & "): done (got BSSMAP Handover Required)");
6899
6900 /* Note: f_tc_ho_neighbor_config_start() sets T7, the timeout for BSSMAP Handover Required, to
6901 * 1 second. There is no legal way to quickly abort a handover after a BSSMAP Handover Required,
6902 * setting a short timeout and waiting is the only way. */
6903 log("f_probe_for_handover(" & log_label & "): waiting for inter-BSC HO to time out...");
6904 f_sleep(1.5);
6905 log("f_probe_for_handover(" & log_label & "): ...done");
6906
6907 break;
6908 }
6909 [] T.timeout {
6910 if (expect_handover) {
6911 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected Handover, but got none. "
6912 & log_label & ": " & log_descr);
6913 } else {
6914 setverdict(pass);
6915 log("f_probe_for_handover(" & log_label & "): Got no Handover, as expected.");
6916 }
6917 log("f_probe_for_handover(" & log_label & "): done (got no Handover)");
6918 break;
6919 }
6920 }
6921
6922 f_rslem_resume(RSL1_PROC);
6923 f_rslem_resume(RSL2_PROC);
6924 f_sleep(3.0);
6925 RSL.clear;
6926
6927 log("f_probe_for_handover(" & log_label & "): done clearing");
6928}
6929
6930/* Test the effect of various neighbor configuration scenarios:
6931 *
6932 * To avoid complexity, block off any actual handover operation, and always remain on the lchan at bts 0.
6933 * Reconfigure the neighbors for bts 0, trigger a Handover, and probe whether osmo-bsc does or doesn't start HO.
6934 */
6935private function f_tc_ho_neighbor_config_start() runs on MSC_ConnHdlr {
6936 g_pars := f_gen_test_hdlr_pars();
6937 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
6938 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006939
6940 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
6941 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
6942
6943 /* Establish lchan at bts 0 */
6944 f_establish_fully(ass_cmd, exp_compl);
6945
6946 /* Shorten the inter-BSC Handover timeout, to not wait so long for inter-BSC Handovers */
6947 f_vty_enter_cfg_network(BSCVTY);
6948 f_vty_transceive(BSCVTY, "timer T7 1");
6949 f_vty_transceive(BSCVTY, "end");
6950}
6951
6952private function f_tc_ho_neighbor_config_1(charstring id) runs on MSC_ConnHdlr {
6953 f_tc_ho_neighbor_config_start();
6954
6955 /*
6956 * bts 0 ARFCN 871 BSIC 10
6957 * bts 1 ARFCN 871 BSIC 11
6958 * bts 2 ARFCN 871 BSIC 12
6959 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6960 */
6961
6962 log("f_tc_ho_neighbor_config: 1. No 'neighbor' config");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006963 f_bts_0_cfg(BSCVTY, {"no neighbors"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006964 f_probe_for_handover("1.a", "HO to bts 1 works, implicitly listed as neighbor (legacy behavior when none are configured)",
6965 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006966 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006967
6968 f_probe_for_handover("1.b", "HO to unknown cell does not start",
6969 "handover any to arfcn 13 bsic 39",
6970 false);
6971
6972 f_probe_for_handover("1.c", "HO to 871-12 is ambiguous = error",
6973 "handover any to arfcn 871 bsic 12",
6974 false);
6975
6976 f_probe_for_handover("1.d", "HO to 871-11 still works (verify that this test properly cleans up)",
6977 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006978 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006979
6980 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006981}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006982testcase TC_ho_neighbor_config_1() runs on test_CT {
6983 var MSC_ConnHdlr vc_conn;
6984 f_init(3, true, guard_timeout := 60.0);
6985 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006986 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006987 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_1));
6988 vc_conn.done;
6989
6990 /* f_tc_ho_neighbor_config_start() */
6991 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6992 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6993
6994 /* 1.a */
6995 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6996 * handover quickly by sending a Handover Failure message. */
6997 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6998 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6999 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
7000 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007001 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
7002 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007003
7004 /* 1.b */
7005 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7006 f_ctrs_bsc_and_bts_add(0, "handover:error");
7007
7008 /* 1.c */
7009 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7010 f_ctrs_bsc_and_bts_add(0, "handover:error");
7011
7012 /* 1.d */
7013 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7014 f_ctrs_bsc_and_bts_add(0, "handover:failed");
7015 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
7016 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007017 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
7018 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007019
7020 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007021 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007022}
7023
Neels Hofmeyr91401012019-07-11 00:42:35 +02007024private function f_tc_ho_neighbor_config_2(charstring id) runs on MSC_ConnHdlr {
7025 f_tc_ho_neighbor_config_start();
7026
7027 /*
7028 * bts 0 ARFCN 871 BSIC 10
7029 * bts 1 ARFCN 871 BSIC 11
7030 * bts 2 ARFCN 871 BSIC 12
7031 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7032 */
7033
7034 log("f_tc_ho_neighbor_config: 2. explicit local neighbor: 'neighbor bts 1'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007035 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007036 f_sleep(0.5);
7037
7038 f_probe_for_handover("2.a", "HO to bts 1 works, explicitly listed as neighbor",
7039 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02007040 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02007041
7042 f_probe_for_handover("2.b", "HO to bts 2 doesn't work, not listed as neighbor",
7043 "handover any to arfcn 871 bsic 12",
7044 false);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007045 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007046}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007047testcase TC_ho_neighbor_config_2() runs on test_CT {
7048 var MSC_ConnHdlr vc_conn;
7049 f_init(3, true, guard_timeout := 50.0);
7050 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007051 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007052 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_2));
7053 vc_conn.done;
7054
7055 /* f_tc_ho_neighbor_config_start() */
7056 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7057 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7058
7059 /* 2.a */
7060 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
7061 * handover quickly by sending a Handover Failure message. */
7062 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7063 f_ctrs_bsc_and_bts_add(0, "handover:failed");
7064 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
7065 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007066 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
7067 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007068
7069 /* 2.b */
7070 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7071 f_ctrs_bsc_and_bts_add(0, "handover:error");
7072
7073 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007074 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007075}
7076
Neels Hofmeyr91401012019-07-11 00:42:35 +02007077private function f_tc_ho_neighbor_config_3(charstring id) runs on MSC_ConnHdlr {
7078 f_tc_ho_neighbor_config_start();
7079
7080 /*
7081 * bts 0 ARFCN 871 BSIC 10
7082 * bts 1 ARFCN 871 BSIC 11
7083 * bts 2 ARFCN 871 BSIC 12
7084 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7085 */
7086
7087 log("f_tc_ho_neighbor_config: 3. explicit local neighbor: 'neighbor bts 2'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007088 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007089 f_sleep(0.5);
7090
7091 f_probe_for_handover("3.a", "HO to bts 1 doesn't work, not listed as neighbor",
7092 "handover any to arfcn 871 bsic 11",
7093 false);
7094 f_probe_for_handover("3.b", "HO to bts 2 works, explicitly listed as neighbor; no ambiguity because bts 3 is not listed as neighbor",
7095 "handover any to arfcn 871 bsic 12",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02007096 true, expect_target_tsc := BTS_TSC[2]);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007097 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007098}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007099testcase TC_ho_neighbor_config_3() runs on test_CT {
7100 var MSC_ConnHdlr vc_conn;
7101 f_init(3, true, guard_timeout := 50.0);
7102 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007103 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007104 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_3));
7105 vc_conn.done;
7106
7107 /* f_tc_ho_neighbor_config_start() */
7108 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7109 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7110
7111 /* 3.a */
7112 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7113 f_ctrs_bsc_and_bts_add(0, "handover:error");
7114
7115 /* 3.b */
7116 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
7117 * handover quickly by sending a Handover Failure message. */
7118 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7119 f_ctrs_bsc_and_bts_add(0, "handover:failed");
7120 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
7121 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007122 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:attempted");
7123 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007124
7125 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007126 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007127}
7128
Neels Hofmeyr91401012019-07-11 00:42:35 +02007129private function f_tc_ho_neighbor_config_4(charstring id) runs on MSC_ConnHdlr {
7130 f_tc_ho_neighbor_config_start();
7131
7132 /*
7133 * bts 0 ARFCN 871 BSIC 10
7134 * bts 1 ARFCN 871 BSIC 11
7135 * bts 2 ARFCN 871 BSIC 12
7136 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7137 */
7138
7139 log("f_tc_ho_neighbor_config: 4. explicit remote neighbor: 'neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007140 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007141 f_sleep(0.5);
7142
7143 f_probe_for_handover("4.a", "HO to bts 1 doesn't work, not listed as neighbor",
7144 "handover any to arfcn 871 bsic 11",
7145 false);
7146 f_probe_for_handover("4.b", "HO to bts 2 doesn't work, not listed as neighbor",
7147 "handover any to arfcn 871 bsic 12",
7148 false);
7149 f_probe_for_handover("4.c", "HO to 123-45 triggers inter-BSC HO",
7150 "handover any to arfcn 123 bsic 45",
7151 true, true);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007152 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007153}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007154testcase TC_ho_neighbor_config_4() runs on test_CT {
7155 var MSC_ConnHdlr vc_conn;
7156 f_init(3, true, guard_timeout := 50.0);
7157 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007158 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007159 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_4));
7160 vc_conn.done;
7161
7162 /* f_tc_ho_neighbor_config_start() */
7163 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7164 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7165
7166 /* 4.a */
7167 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7168 f_ctrs_bsc_and_bts_add(0, "handover:error");
7169
7170 /* 4.b */
7171 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7172 f_ctrs_bsc_and_bts_add(0, "handover:error");
7173
7174 /* 4.c */
7175 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7176 * handover quickly by timing out after the Handover Required message */
7177 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7178 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
7179 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
7180 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
7181
7182 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007183 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007184}
7185
Neels Hofmeyr91401012019-07-11 00:42:35 +02007186private function f_tc_ho_neighbor_config_5(charstring id) runs on MSC_ConnHdlr {
7187 f_tc_ho_neighbor_config_start();
7188
7189 /*
7190 * bts 0 ARFCN 871 BSIC 10
7191 * bts 1 ARFCN 871 BSIC 11
7192 * bts 2 ARFCN 871 BSIC 12
7193 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7194 */
7195
7196 log("f_tc_ho_neighbor_config: 5. explicit remote neighbor re-using ARFCN+BSIC: 'neighbor lac 99 arfcn 871 bsic 12'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007197 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007198 f_sleep(0.5);
7199
7200 f_probe_for_handover("5.a", "HO to 871-12 triggers inter-BSC HO (ignoring local cells with same ARFCN+BSIC)",
7201 "handover any to arfcn 871 bsic 12",
7202 true, true);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007203 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007204}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007205testcase TC_ho_neighbor_config_5() runs on test_CT {
7206 var MSC_ConnHdlr vc_conn;
7207 f_init(3, true);
7208 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007209 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007210 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_5));
7211 vc_conn.done;
7212
7213 /* f_tc_ho_neighbor_config_start() */
7214 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7215 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7216
7217 /* 5 */
7218 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7219 * handover quickly by timing out after the Handover Required message */
7220 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7221 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
7222 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
7223 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
7224
7225 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007226 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007227}
7228
Neels Hofmeyr91401012019-07-11 00:42:35 +02007229private function f_tc_ho_neighbor_config_6(charstring id) runs on MSC_ConnHdlr {
7230 f_tc_ho_neighbor_config_start();
7231
7232 /*
7233 * bts 0 ARFCN 871 BSIC 10
7234 * bts 1 ARFCN 871 BSIC 11
7235 * bts 2 ARFCN 871 BSIC 12
7236 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7237 */
7238
7239 log("f_tc_ho_neighbor_config: 6. config error: explicit local and remote neighbors with ambiguous ARFCN+BSIC:"
7240 & " 'neighbor bts 2; neighbor lac 99 arfcn 871 bsic 12'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007241 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007242 f_sleep(0.5);
7243
7244 f_probe_for_handover("6.a", "HO to 871-12 is ambiguous = error",
7245 "handover any to arfcn 871 bsic 12",
7246 false);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007247 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007248}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007249testcase TC_ho_neighbor_config_6() runs on test_CT {
7250 var MSC_ConnHdlr vc_conn;
7251 f_init(3, true);
7252 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007253 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007254 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_6));
7255 vc_conn.done;
7256
7257 /* f_tc_ho_neighbor_config_start() */
7258 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7259 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7260
7261 /* 6.a */
7262 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7263 * handover quickly by timing out after the Handover Required message */
7264 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7265 f_ctrs_bsc_and_bts_add(0, "handover:error");
7266
7267 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007268 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007269}
7270
Neels Hofmeyr91401012019-07-11 00:42:35 +02007271private function f_tc_ho_neighbor_config_7(charstring id) runs on MSC_ConnHdlr {
7272 f_tc_ho_neighbor_config_start();
7273
7274 /*
7275 * bts 0 ARFCN 871 BSIC 10
7276 * bts 1 ARFCN 871 BSIC 11
7277 * bts 2 ARFCN 871 BSIC 12
7278 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7279 */
7280
7281 log("f_tc_ho_neighbor_config: 7. explicit local and remote neighbors:"
7282 & " 'neighbor bts 2; neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007283 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007284 f_sleep(0.5);
7285
7286 f_probe_for_handover("7.a", "HO to 871-12 does HO to bts 2",
7287 "handover any to arfcn 871 bsic 12",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02007288 true, expect_target_tsc := BTS_TSC[2]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02007289 f_probe_for_handover("7.b", "HO to 123-45 triggers inter-BSC HO",
7290 "handover any to arfcn 123 bsic 45",
7291 true, true);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007292 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007293}
Neels Hofmeyr91401012019-07-11 00:42:35 +02007294testcase TC_ho_neighbor_config_7() runs on test_CT {
7295 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf2b88032020-06-16 00:35:04 +02007296 f_init(3, true, guard_timeout := 50.0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02007297 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007298 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007299 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_7));
7300 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007301
7302 /* f_tc_ho_neighbor_config_start() */
7303 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7304 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7305
7306 /* 7.a */
7307 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
7308 * handover quickly by sending a Handover Failure message. */
7309 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7310 f_ctrs_bsc_and_bts_add(0, "handover:failed");
7311 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
7312 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007313 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:attempted");
7314 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007315
7316 /* 7.b */
7317 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7318 * handover quickly by timing out after the Handover Required message */
7319 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7320 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
7321 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
7322 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
7323
7324 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007325 f_shutdown_helper();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007326}
7327
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007328/* OS#3041: Open and close N connections in a normal fashion, and expect no
7329 * BSSMAP Reset just because of that. */
7330testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
7331 var default d;
7332 var integer i;
7333 var DchanTuple dt;
7334
7335 f_init();
7336
7337 /* Wait for initial BSSMAP Reset to pass */
7338 f_sleep(4.0);
7339
7340 d := activate(no_bssmap_reset());
7341
7342 /* Setup up a number of connections and RLSD them again from the MSC
7343 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7344 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02007345 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007346 /* Since we're doing a lot of runs, give each one a fresh
7347 * T_guard from the top. */
7348 T_guard.start;
7349
7350 /* Setup a BSSAP connection and clear it right away. This is
7351 * the MSC telling the BSC about a planned release, it's not an
7352 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02007353 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007354
7355 /* MSC disconnects (RLSD). */
7356 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
7357 }
7358
7359 /* In the buggy behavior, a timeout of 2 seconds happens between above
7360 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7361 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7362 f_sleep(4.0);
7363
7364 deactivate(d);
7365 f_shutdown_helper();
7366}
Harald Welte552620d2017-12-16 23:21:36 +01007367
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007368/* OS#3041: Open and close N connections in a normal fashion, and expect no
7369 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
7370 * the MSC. */
7371testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
7372 var default d;
7373 var integer i;
7374 var DchanTuple dt;
7375 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007376 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
7377 var BssmapCause cause := enum2int(cause_val);
7378
7379 f_init();
7380
7381 /* Wait for initial BSSMAP Reset to pass */
7382 f_sleep(4.0);
7383
7384 d := activate(no_bssmap_reset());
7385
7386 /* Setup up a number of connections and RLSD them again from the MSC
7387 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7388 * Let's do it some more times for good measure. */
7389 for (i := 0; i < 8; i := i+1) {
7390 /* Since we're doing a lot of runs, give each one a fresh
7391 * T_guard from the top. */
7392 T_guard.start;
7393
7394 /* Setup a BSSAP connection and clear it right away. This is
7395 * the MSC telling the BSC about a planned release, it's not an
7396 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02007397 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007398
7399 /* Instruct BSC to clear channel */
7400 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7401
7402 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02007403 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007404 }
7405
7406 /* In the buggy behavior, a timeout of 2 seconds happens between above
7407 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7408 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7409 f_sleep(4.0);
7410
7411 deactivate(d);
7412 f_shutdown_helper();
7413}
7414
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007415/* OS#3041: Open and close N connections in a normal fashion, and expect no
7416 * BSSMAP Reset just because of that. Close connections from the MS side with a
7417 * Release Ind on RSL. */
7418testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
7419 var default d;
7420 var integer i;
7421 var DchanTuple dt;
7422 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007423 var integer j;
7424
7425 f_init();
7426
7427 /* Wait for initial BSSMAP Reset to pass */
7428 f_sleep(4.0);
7429
7430 d := activate(no_bssmap_reset());
7431
7432 /* Setup up a number of connections and RLSD them again from the MSC
7433 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7434 * Let's do it some more times for good measure. */
7435 for (i := 0; i < 8; i := i+1) {
7436 /* Since we're doing a lot of runs, give each one a fresh
7437 * T_guard from the top. */
7438 T_guard.start;
7439
7440 /* Setup a BSSAP connection and clear it right away. This is
7441 * the MSC telling the BSC about a planned release, it's not an
7442 * erratic loss of a connection. */
7443 dt := f_est_dchan('23'O, 23, '00010203040506'O);
7444
7445 /* simulate RLL REL IND */
7446 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
7447
7448 /* expect Clear Request on MSC side */
7449 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
7450
7451 /* Instruct BSC to clear channel */
7452 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
7453 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7454
7455 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02007456 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007457 }
7458
7459 /* In the buggy behavior, a timeout of 2 seconds happens between above
7460 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7461 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7462 f_sleep(4.0);
7463
7464 deactivate(d);
7465 f_shutdown_helper();
7466}
7467
Harald Welte94e0c342018-04-07 11:33:23 +02007468/***********************************************************************
7469 * IPA style dynamic PDCH
7470 ***********************************************************************/
7471
7472private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
7473 template (omit) RSL_Cause nack := omit)
7474runs on test_CT {
7475 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
7476 var RSL_Message rsl_unused;
7477 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
7478 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
7479 /* expect the BSC to issue the related RSL command */
7480 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7481 if (istemplatekind(nack, "omit")) {
7482 /* respond with a related acknowledgement */
7483 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7484 } else {
7485 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
7486 }
7487}
7488
7489private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
7490 template (omit) RSL_Cause nack := omit)
7491runs on test_CT {
7492 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
7493 var RSL_Message rsl_unused;
7494 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
7495 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
7496 /* expect the BSC to issue the related RSL command */
7497 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
7498 if (istemplatekind(nack, "omit")) {
7499 /* respond with a related acknowledgement */
7500 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
7501 } else {
7502 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
7503 }
7504}
7505
7506private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
7507runs on test_CT return charstring {
7508 var charstring cmd, resp;
7509 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01007510 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02007511}
7512
7513private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
7514 template charstring exp)
7515runs on test_CT {
7516 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
7517 if (not match(mode, exp)) {
7518 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02007519 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02007520 }
7521}
7522
7523private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
7524runs on test_CT {
7525 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
7526 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
7527 f_vty_transceive(BSCVTY, "end");
7528}
7529
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007530
7531private function f_ts_reset_chcomb(integer bts_nr) runs on test_CT {
7532 var integer i;
7533 for (i := 0; i < 8; i := i + 1) {
7534 f_ts_set_chcomb(bts_nr, 0, i, phys_chan_config[i]);
7535 }
7536}
7537
Harald Welte94e0c342018-04-07 11:33:23 +02007538private const charstring TCHF_MODE := "TCH/F mode";
7539private const charstring TCHH_MODE := "TCH/H mode";
7540private const charstring PDCH_MODE := "PDCH mode";
7541private const charstring NONE_MODE := "NONE mode";
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007542private const charstring SDCCH8_MODE := "SDCCH8 mode";
Harald Welte94e0c342018-04-07 11:33:23 +02007543
7544/* Test IPA PDCH activation / deactivation triggered by VTY */
7545testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
7546 var RSL_Message rsl_unused;
7547
7548 /* change Timeslot 6 before f_init() starts RSL */
7549 f_init_vty();
7550 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
7551 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7552
7553 f_init(1, false);
7554 f_sleep(1.0);
7555
7556 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
7557
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007558 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007559 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7560 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7561 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7562 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7563 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007564 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007565 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7566
7567 /* De-activate it via VTY */
7568 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7569 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007570 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007571 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7572
7573 /* re-activate it via VTY */
7574 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
7575 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007576 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007577 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7578
7579 /* and finally de-activate it again */
7580 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7581 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007582 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007583 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7584
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007585 /* clean up config */
7586 f_ts_set_chcomb(0, 0, 6, "PDCH");
7587
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007588 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007589}
7590
7591/* Test IPA PDCH activation NACK */
7592testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
7593 var RSL_Message rsl_unused;
7594
7595 /* change Timeslot 6 before f_init() starts RSL */
7596 f_init_vty();
7597 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
7598 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7599
7600 f_init(1, false);
7601 f_sleep(1.0);
7602
7603 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
7604
7605 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7606 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7607 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7608 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7609 f_sleep(1.0);
7610 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7611
7612 /* De-activate it via VTY */
7613 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7614 f_sleep(1.0);
7615 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7616
7617 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
7618 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
7619 f_sleep(1.0);
7620 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7621
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007622 /* clean up config */
7623 f_ts_set_chcomb(0, 0, 6, "PDCH");
7624
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007625 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007626}
7627
7628
7629/***********************************************************************
7630 * Osmocom style dynamic PDCH
7631 ***********************************************************************/
7632
7633private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
7634 template (omit) RSL_Cause nack := omit)
7635runs on test_CT {
7636 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
7637 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02007638 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02007639 /* FIXME: no VTY command to activate Osmocom PDCH !! */
7640 /* expect the BSC to issue the related RSL command */
7641 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
7642 if (istemplatekind(nack, "omit")) {
7643 /* respond with a related acknowledgement */
7644 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7645 } else {
7646 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
7647 }
7648}
7649
7650private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
7651 template (omit) RSL_Cause nack := omit)
7652runs on test_CT {
7653 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
7654 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02007655 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02007656 /* FIXME: no VTY command to activate Osmocom PDCH !! */
7657 /* expect the BSC to issue the related RSL command */
7658 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
7659 if (istemplatekind(nack, "omit")) {
7660 /* respond with a related acknowledgement */
7661 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
7662 } else {
7663 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
7664 }
7665}
7666
7667/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
7668testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
7669 var RSL_Message rsl_unused;
7670
7671 /* change Timeslot 6 before f_init() starts RSL */
7672 f_init_vty();
7673 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
7674 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7675
7676 f_init(1, false);
7677 f_sleep(1.0);
7678
7679 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
7680
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007681 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007682 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7683 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007684 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Harald Welte94e0c342018-04-07 11:33:23 +02007685
7686 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7687 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007688 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 +02007689 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7690
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007691 /* clean up config */
7692 f_ts_set_chcomb(0, 0, 6, "PDCH");
7693
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007694 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007695}
7696
7697/* Test Osmocom dyn PDCH activation NACK behavior */
7698testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
7699 var RSL_Message rsl_unused;
7700
7701 /* change Timeslot 6 before f_init() starts RSL */
7702 f_init_vty();
7703 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
7704 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7705
7706 f_init(1, false);
7707 f_sleep(1.0);
7708
7709 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
7710
7711 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7712 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007713 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Harald Welte94e0c342018-04-07 11:33:23 +02007714
7715 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
7716 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
7717 f_sleep(1.0);
7718 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7719
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007720 /* clean up config */
7721 f_ts_set_chcomb(0, 0, 6, "PDCH");
7722
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007723 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007724}
7725
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007726/* Test Osmocom dyn TS SDCCH8 activation / deactivation */
7727testcase TC_dyn_ts_sdcch8_act_deact() runs on test_CT {
7728 var RSL_Message rsl_unused, rsl_msg;
7729 var DchanTuple dt;
7730 var BSSAP_N_CONNECT_ind rx_c_ind;
7731
7732 /* change Timeslot 6 before f_init() starts RSL */
7733 f_init_vty();
7734 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
7735 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7736
7737 f_init(1, false);
7738 f_sleep(1.0);
7739
7740 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7741
7742 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7743 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7744 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007745 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007746
7747 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7748 f_sleep(1.0);
7749 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7750 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7751
7752 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7753 * on CCCH+SDCCH4+CBCH) */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007754 var DchanTuples sdcch_cleanup := {};
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007755 var integer i;
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007756 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007757 dt := f_est_dchan('23'O, i, '00010203040506'O);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007758 sdcch_cleanup := sdcch_cleanup & { dt };
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007759 }
7760
7761 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
7762 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
7763 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7764 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7765
7766 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7767 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7768
7769 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7770 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
7771 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7772 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7773
7774 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
7775 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
7776 dt.sccp_conn_id := rx_c_ind.connectionId;
7777 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
7778
7779 /* Instruct BSC to clear channel */
7780 var BssmapCause cause := 0;
7781 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7782 f_exp_chan_rel_and_clear(dt, 0);
7783
7784 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007785 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007786 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7787 f_sleep(1.0);
7788 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7789
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007790 /* Clean up SDCCH lchans */
7791 for (i := 0; i < lengthof(sdcch_cleanup); i := i + 1) {
7792 f_perform_clear_test_ct(sdcch_cleanup[i]);
7793 }
7794
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007795 /* clean up config */
7796 f_ts_set_chcomb(0, 0, 6, "PDCH");
7797
7798 f_shutdown_helper();
7799}
7800
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007801/* Validate all 8 subslots of a dynamics TS configured as SDCCH8 are used */
7802testcase TC_dyn_ts_sdcch8_all_subslots_used() runs on test_CT {
7803 var ASP_RSL_Unitdata rsl_ud;
7804 var integer i;
7805 var integer chreq_total, chreq_nochan;
7806
7807 f_init_vty();
7808 for (i := 1; i < 8; i := i + 1) {
7809 if (i == 2) {
7810 f_ts_set_chcomb(0, 0, i, "TCH/F_TCH/H_SDCCH8_PDCH");
7811 } else {
7812 f_ts_set_chcomb(0, 0, i, "PDCH");
7813 }
7814 }
7815 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7816
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007817 f_init(1, guard_timeout := 60.0);
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007818
7819 /* The dyn TS want to activate PDCH mode, ACK that. */
7820 var RslChannelNr chan_nr;
7821 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007822 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007823 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7824
7825 f_sleep(1.0);
7826
7827 /* Exhaust all dedicated SDCCH lchans.
7828 /* GSM 44.018 Table 9.1.8.2:
7829 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
7830 */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007831 var DchanTuples chan_cleanup := {};
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007832 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007833 chan_cleanup := chan_cleanup & { f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007834 }
7835
7836 /* Only the dyn TS is still available. Its first lchan gets converted to SDCCH8 */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007837 chan_cleanup := chan_cleanup & { f_est_dchan_dyn('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007838 /* Also occupy the seven other SDCCH of the dyn TS */
7839 for (i := 0; i < 7; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007840 chan_cleanup := chan_cleanup & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
7841 }
7842
7843 /* Clean up SDCCH lchans */
7844 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
7845 f_perform_clear_test_ct(chan_cleanup[i]);
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007846 }
7847
7848 /* clean up config */
7849 f_ts_reset_chcomb(0);
7850
7851 f_shutdown_helper();
7852}
7853
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007854/* Test Osmocom dyn TS SDCCH8 activation / deactivation: If activating dyn TS as
7855 SDCCH8 would end up in having no free TCH, then BSC should decide to activate
7856 it as TCH directly instead. SYS#5309. */
7857testcase TC_dyn_ts_sdcch8_tch_call_act_deact() runs on test_CT {
7858 var RSL_Message rsl_unused, rsl_msg;
7859 var DchanTuple dt;
7860 var BSSAP_N_CONNECT_ind rx_c_ind;
7861 var integer i;
7862
7863 /* change Timeslot 6 before f_init() starts RSL */
7864 f_init_vty();
7865 for (i := 1; i < 8; i := i + 1) {
7866 if (i == 6) {
7867 f_ts_set_chcomb(0, 0, i, "TCH/F_TCH/H_SDCCH8_PDCH");
7868 } else {
7869 f_ts_set_chcomb(0, 0, i, "PDCH");
7870 }
7871 }
7872 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7873
7874 f_init(1, false);
7875 f_sleep(1.0);
7876
7877 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7878
7879 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7880 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7881 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007882 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007883
7884 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7885 f_sleep(1.0);
7886 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7887 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7888
7889 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7890 * on CCCH+SDCCH4+CBCH) */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007891 var DchanTuples chan_cleanup := {};
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007892 var OCT1 ra := '43'O; /* RA containing reason=originating speech call*/
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007893 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007894 dt := f_est_dchan(ra, i, '00010203040506'O);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007895 chan_cleanup := chan_cleanup & { dt };
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007896 }
7897
7898 /* Now the dyn ts is selected. First PDCH is released, then TCH chan is activated */
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007899 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int(ra) + i, 1), 2342));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007900 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7901 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7902
7903 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7904 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7905
7906 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
7907 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
7908 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7909 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
7910
7911 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
7912 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
7913 dt.sccp_conn_id := rx_c_ind.connectionId;
7914 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
7915
7916 /* Instruct BSC to clear channel */
7917 var BssmapCause cause := 0;
7918 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7919 f_exp_chan_rel_and_clear(dt, 0);
7920
7921 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007922 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007923 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7924 f_sleep(1.0);
7925 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7926
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007927 /* Clean up SDCCH lchans */
7928 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
7929 f_perform_clear_test_ct(chan_cleanup[i]);
7930 }
7931
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007932 /* clean up config */
7933 f_ts_reset_chcomb(0);
7934 /* TODO: clean up other channels? */
7935
7936 f_shutdown_helper();
7937}
7938
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007939/* Test Osmocom dyn TS SDCCH8 activation / deactivation when SDCCH fails at BTS */
7940testcase TC_dyn_ts_sdcch8_act_nack() runs on test_CT {
7941 var RSL_Message rsl_unused, rsl_msg;
7942 var DchanTuple dt;
7943 var BSSAP_N_CONNECT_ind rx_c_ind;
7944 var GsmRrMessage rr;
7945
7946 /* change Timeslot 6 before f_init() starts RSL */
7947 f_init_vty();
7948 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
7949 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7950
7951 f_init(1, false);
7952 f_sleep(1.0);
7953
7954 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7955
7956 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7957 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7958 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007959 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007960
7961 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7962 f_sleep(1.0);
7963 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7964 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7965
7966 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7967 * on CCCH+SDCCH4+CBCH) */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007968 var DchanTuples chan_cleanup := {};
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007969 var integer i;
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007970 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007971 dt := f_est_dchan('23'O, i, '00010203040506'O);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007972 chan_cleanup := chan_cleanup & { dt };
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007973 }
7974
7975 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
7976 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
7977 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7978 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7979
7980 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7981 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7982
7983 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7984 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(dt.rsl_chan_nr, RSL_ERR_EQUIPMENT_FAIL));
7985 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7986 rr := dec_GsmRrMessage(rsl_msg.ies[1].body.full_imm_ass_info.payload);
7987 if (rr.header.message_type != IMMEDIATE_ASSIGNMENT_REJECT) {
7988 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Expected reject");
7989 }
7990
7991 /* FIXME? Currently the TS stays in state BORKEN: */
7992
7993 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007994 /* rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007995 * f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7996 * f_sleep(1.0);
7997 * f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE)
7998 */
7999
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01008000 /* Clean up SDCCH lchans */
8001 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
8002 f_perform_clear_test_ct(chan_cleanup[i]);
8003 }
8004
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02008005 /* clean up config */
8006 f_ts_set_chcomb(0, 0, 6, "PDCH");
8007
8008 f_shutdown_helper();
8009}
8010
Stefan Sperling0796a822018-10-05 13:01:39 +02008011testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02008012 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02008013 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
8014 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
8015 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008016 f_shutdown_helper();
Stefan Sperling0796a822018-10-05 13:01:39 +02008017}
8018
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008019testcase TC_chopped_ipa_payload() runs on test_CT {
8020 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
8021 /* TODO: mp_bsc_ctrl_port does not work yet */};
8022 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
8023 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
8024 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008025 f_shutdown_helper();
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008026}
8027
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01008028/* Verify the BSC sends the MS Power Parameters IE during CHAN ACT to make sure
8029 the BTS does autonomous MS power control loop */
8030testcase TC_assignment_verify_ms_power_params_ie() runs on test_CT {
8031 var MSC_ConnHdlr vc_conn;
8032 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8033 //pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
8034 pars.exp_ms_power_params := true;
8035
8036 f_init(1, true);
8037 f_sleep(1.0);
8038 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
8039 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008040 f_shutdown_helper();
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01008041}
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008042
Vadim Yanitskiy4b233042021-06-30 00:58:43 +02008043/* Verify activation and deactivation of the BCCH carrier power reduction mode */
8044testcase TC_c0_power_red_mode() runs on test_CT {
8045 f_init(1);
8046
8047 for (var integer red := 6; red >= 0; red := red - 2) {
8048 /* Configure BCCH carrier power reduction mode via the VTY */
8049 f_vty_transceive(BSCVTY, "bts 0 c0-power-reduction " & int2str(red));
8050
8051 /* Expect Osmocom specific BS Power Control message on the RSL */
Vadim Yanitskiy35c9a332022-03-16 20:26:35 +03008052 var template (present) RSL_Message tr_rsl_pdu := tr_RSL_BS_PWR_CTRL(
Vadim Yanitskiy4b233042021-06-30 00:58:43 +02008053 chan_nr := t_RslChanNr_BCCH(0),
8054 bs_power := tr_RSL_IE_BS_Power(red / 2));
8055 tr_rsl_pdu.msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false);
8056 var RSL_Message unused := f_exp_ipa_rx(0, tr_rsl_pdu);
8057
8058 /* Additionally verify the applied value over the CTRL interface */
8059 var CtrlValue cred := f_ctrl_get_bts(IPA_CTRL, 0, "c0-power-reduction");
8060 if (cred != int2str(red)) {
8061 setverdict(fail, "Unexpected BCCH carrier power reduction value ",
8062 cred, " (expected ", red, ")");
8063 }
8064 }
8065
8066 f_shutdown_helper();
8067}
8068
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008069/***********************************************************************
8070 * MSC Pooling
8071 ***********************************************************************/
8072
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008073template MobileIdentityLV ts_MI_TMSI_NRI_LV(integer nri_v, integer nri_bitlen := 10) :=
Harald Weltebf397612021-01-14 20:39:46 +01008074 ts_MI_TMSI_LV(tmsi := f_gen_tmsi(suffix := 0, nri_v := nri_v, nri_bitlen := nri_bitlen));
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008075
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008076private function f_expect_lchan_rel(RSL_DCHAN_PT rsl_pt, RSLEM_PROC_PT rsl_proc_pt, template PDU_ML3_NW_MS exp_rr_rel_tmpl := tr_RRM_RR_RELEASE)
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02008077runs on MSC_ConnHdlr {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008078 interleave {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008079 [] rsl_pt.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008080 f_logp(BSCVTY, "Got RSL RR Release");
8081 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008082 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008083 f_logp(BSCVTY, "Got RSL Deact SACCH");
8084 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02008085 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008086 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008087 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
8088 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008089 break;
8090 }
8091 }
8092}
8093
Neels Hofmeyr6289af12021-12-16 18:17:49 +01008094private altstep as_mgcp_ack_all_dlcx() runs on MSC_ConnHdlr {
8095 var MgcpCommand mgcp_cmd;
8096 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
8097 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
8098 repeat;
8099 }
8100}
8101
8102private altstep as_rsl_ack_all_rel_req() runs on MSC_ConnHdlr {
8103 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
8104 [] RSL.receive(tr_RSL_REL_REQ(g_chan_nr, ?)) {
8105 RSL.send(ts_RSL_REL_CONF(g_chan_nr, main_dcch));
8106 repeat;
8107 }
8108}
8109
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008110friend function f_perform_clear(RSL_DCHAN_PT rsl_pt := RSL, RSLEM_PROC_PT rsl_proc_pt := RSL_PROC,
8111 template PDU_ML3_NW_MS exp_rr_rel_tmpl := tr_RRM_RR_RELEASE)
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02008112runs on MSC_ConnHdlr {
Neels Hofmeyr6289af12021-12-16 18:17:49 +01008113 var default ack_dlcx := activate(as_mgcp_ack_all_dlcx());
8114 var default ack_rel_req := activate(as_rsl_ack_all_rel_req());
Neels Hofmeyr767548a2020-08-09 20:26:07 +00008115 f_logp(BSCVTY, "MSC instructs BSC to clear channel");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008116 BSSAP.send(ts_BSSMAP_ClearCommand(0));
8117 interleave {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008118 [] rsl_pt.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00008119 f_logp(BSCVTY, "Got RSL RR Release");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008120 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008121 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00008122 f_logp(BSCVTY, "Got RSL Deact SACCH");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008123 }
8124 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00008125 f_logp(BSCVTY, "Got BSSMAP Clear Complete");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008126 /* Also drop the SCCP connection */
8127 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
8128 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02008129 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00008130 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008131 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
8132 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008133 }
8134 }
Neels Hofmeyr6289af12021-12-16 18:17:49 +01008135 deactivate(ack_dlcx);
8136 deactivate(ack_rel_req);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008137}
8138
Neels Hofmeyrc3c6ee62022-01-26 01:22:12 +01008139friend function f_perform_clear_no_rr_rel(RSL_DCHAN_PT rsl_pt := RSL, RSLEM_PROC_PT rsl_proc_pt := RSL_PROC)
8140runs on MSC_ConnHdlr {
8141 var default ack_dlcx := activate(as_mgcp_ack_all_dlcx());
8142 var default ack_rel_req := activate(as_rsl_ack_all_rel_req());
8143 f_logp(BSCVTY, "MSC instructs BSC to clear channel");
8144 BSSAP.send(ts_BSSMAP_ClearCommand(0));
8145 interleave {
8146 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
8147 f_logp(BSCVTY, "Got RSL Deact SACCH");
8148 }
8149 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
8150 f_logp(BSCVTY, "Got BSSMAP Clear Complete");
8151 /* Also drop the SCCP connection */
8152 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
8153 }
8154 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
8155 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
8156 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
8157 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
8158 }
8159 }
8160 deactivate(ack_dlcx);
8161 deactivate(ack_rel_req);
8162}
8163
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01008164friend function f_perform_clear_no_lchan()
8165runs on MSC_ConnHdlr {
8166 f_logp(BSCVTY, "MSC instructs BSC to clear channel");
8167 BSSAP.send(ts_BSSMAP_ClearCommand(0));
8168 BSSAP.receive(tr_BSSMAP_ClearComplete);
8169 f_logp(BSCVTY, "Got BSSMAP Clear Complete");
8170 /* Also drop the SCCP connection */
8171 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
8172}
8173
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01008174private function f_perform_clear_test_ct(DchanTuple dt)
8175 runs on test_CT
8176{
8177 /* Instruct BSC to clear channel */
8178 var BssmapCause cause := 0;
8179 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
8180 f_exp_chan_rel_and_clear(dt, 0);
8181}
8182
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008183private function f_perform_compl_l3(RSL_DCHAN_PT rsl_pt, RSLEM_PROC_PT rsl_proc_pt,
8184 template PDU_ML3_MS_NW l3_info, boolean do_clear := true, boolean expect_bssmap_l3 := true)
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008185runs on MSC_ConnHdlr {
8186 timer T := 10.0;
8187 var octetstring l3_enc := enc_PDU_ML3_MS_NW(valueof(l3_info));
8188
Neels Hofmeyr767548a2020-08-09 20:26:07 +00008189 f_logp(BSCVTY, "establish channel, send Complete Layer 3 Info");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008190 f_create_bssmap_exp(l3_enc);
8191
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008192 /* RSL_Emulation.f_chan_est() on rsl_pt:
8193 * This is basically code dup with s/RSL/rsl_pt from:
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008194 * RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
8195 */
8196 var RSL_Message rx_rsl;
8197 var GsmRrMessage rr;
8198
8199 /* request a channel to be established */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008200 rsl_pt.send(ts_RSLDC_ChanRqd(g_pars.ra, g_pars.fn));
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008201 /* expect immediate assignment.
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008202 * Code dup with s/RSL/rsl_pt from:
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008203 * rx_rsl := f_rx_or_fail(tr_RSL_IMM_ASSIGN);
8204 */
8205 timer Tt := 10.0;
8206
8207 /* request a channel to be established */
8208 Tt.start;
8209 alt {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008210 [] rsl_pt.receive(tr_RSL_IMM_ASSIGN) -> value rx_rsl {
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008211 Tt.stop;
8212 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008213 [] rsl_pt.receive {
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008214 setverdict(fail, "Unexpected RSL message on DCHAN");
8215 mtc.stop;
8216 }
8217 [] Tt.timeout {
8218 setverdict(fail, "Timeout waiting for RSL on DCHAN");
8219 mtc.stop;
8220 }
8221 }
8222 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
8223 g_chan_nr := rr.payload.imm_ass.chan_desc.chan_nr;
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008224 rsl_pt.send(ts_RSL_EST_IND(g_chan_nr, valueof(g_pars.link_id), l3_enc));
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008225
8226
Neels Hofmeyr66e15092020-10-12 18:44:41 +00008227 if (expect_bssmap_l3) {
8228 f_logp(BSCVTY, "expect BSSAP Complete Layer 3 Info at MSC");
8229 var template PDU_BSSAP exp_l3_compl;
8230 exp_l3_compl := tr_BSSMAP_ComplL3()
8231 if (g_pars.aoip == false) {
8232 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := omit;
8233 } else {
8234 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := ?;
8235 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008236
Neels Hofmeyr66e15092020-10-12 18:44:41 +00008237 var PDU_BSSAP bssap;
8238 T.start;
8239 alt {
8240 [] BSSAP.receive(exp_l3_compl) -> value bssap {
8241 f_logp(BSCVTY, "received expected Complete Layer 3 Info at MSC");
8242 log("rx exp_l3_compl = ", bssap);
8243 }
8244 [] BSSAP.receive(tr_BSSMAP_ComplL3) {
8245 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching COMPLETE LAYER 3 INFORMATION");
8246 }
8247 [] T.timeout {
8248 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
8249 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008250 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008251
Neels Hofmeyr66e15092020-10-12 18:44:41 +00008252 /* start ciphering, if requested */
8253 if (ispresent(g_pars.encr)) {
8254 f_logp(BSCVTY, "start ciphering");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008255 f_cipher_mode(g_pars.encr, rsl_pt := rsl_pt, rsl_proc_pt := rsl_proc_pt);
Neels Hofmeyr66e15092020-10-12 18:44:41 +00008256 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008257 }
8258
8259 if (do_clear) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008260 f_perform_clear(rsl_pt, rsl_proc_pt);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008261 }
8262 setverdict(pass);
8263 f_sleep(1.0);
8264}
8265
8266private function f_tc_mscpool_compl_l3(charstring id) runs on MSC_ConnHdlr {
8267 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8268 if (g_pars.mscpool.rsl_idx == 0) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008269 f_perform_compl_l3(RSL, RSL_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008270 } else if (g_pars.mscpool.rsl_idx == 1) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008271 f_perform_compl_l3(RSL1, RSL1_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008272 } else if (g_pars.mscpool.rsl_idx == 2) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008273 f_perform_compl_l3(RSL2, RSL2_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008274 }
8275}
8276
8277/* Various Complete Layer 3 by IMSI all end up with the first MSC, because the other MSCs are not connected. */
8278private function f_tc_mscpool_L3Compl_on_1_msc(charstring id) runs on MSC_ConnHdlr {
8279 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008280 f_perform_compl_l3(RSL, RSL_PROC, ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O) );
8281 f_perform_compl_l3(RSL, RSL_PROC, ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_IMSI_LV('001010000000002'H))) );
8282 f_perform_compl_l3(RSL, RSL_PROC, ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))) );
8283 f_perform_compl_l3(RSL, RSL_PROC, ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_IMSI_LV('001010000000004'H))) );
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008284}
8285testcase TC_mscpool_L3Compl_on_1_msc() runs on test_CT {
8286
8287 f_init(1, true);
8288 f_sleep(1.0);
8289 var MSC_ConnHdlr vc_conn;
8290 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008291
8292 f_ctrs_msc_init();
8293
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008294 vc_conn := f_start_handler(refers(f_tc_mscpool_L3Compl_on_1_msc), pars);
8295 vc_conn.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008296
8297 f_ctrs_msc_expect(0, "mscpool:subscr:new", 4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008298 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008299}
8300
8301/* Three Layer 3 Complete by IMSI are round-robin'ed across two connected MSCs */
8302/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8303 * just as well using only RSL. */
8304testcase TC_mscpool_L3Complete_by_imsi_round_robin() runs on test_CT {
8305
8306 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8307 f_sleep(1.0);
8308
8309 /* Control which MSC gets chosen next by the round-robin, otherwise
8310 * would be randomly affected by which other tests ran before this. */
8311 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8312
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008313 f_ctrs_msc_init();
8314
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008315 var MSC_ConnHdlr vc_conn1;
8316 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8317 pars1.mscpool.rsl_idx := 0;
8318 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
8319 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8320 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008321 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008322
8323 var MSC_ConnHdlr vc_conn2;
8324 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8325 pars2.mscpool.rsl_idx := 1;
8326 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8327 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8328 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008329 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008330
8331 /* Test round-robin wrap to the first MSC */
8332 var MSC_ConnHdlr vc_conn3;
8333 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8334 pars3.mscpool.rsl_idx := 2;
8335 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
8336 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8337 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008338 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008339 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008340}
8341
8342/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 0
8343 * (configured in osmo-bsc.cfg). */
8344/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8345 * just as well using only RSL. */
8346testcase TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() runs on test_CT {
8347
8348 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8349 f_sleep(1.0);
8350
8351 /* Control which MSC gets chosen next by the round-robin, otherwise
8352 * would be randomly affected by which other tests ran before this. */
8353 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8354
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008355 f_ctrs_msc_init();
8356
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008357 var MSC_ConnHdlr vc_conn1;
8358 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8359 pars1.mscpool.rsl_idx := 0;
8360 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
8361 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8362 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008363 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008364
8365 var MSC_ConnHdlr vc_conn2;
8366 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8367 pars2.mscpool.rsl_idx := 1;
8368 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
8369 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8370 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008371 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008372
8373 /* Test round-robin wrap to the first MSC */
8374 var MSC_ConnHdlr vc_conn3;
8375 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8376 pars3.mscpool.rsl_idx := 2;
8377 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
8378 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8379 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008380 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008381 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008382}
8383
8384/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 1
8385 * (configured in osmo-bsc.cfg). In this case, one of the MSC also has the NULL-NRI as part of its owned NRIs, but the
8386 * NULL-NRI setting is stronger than that. */
8387/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8388 * just as well using only RSL. */
8389testcase TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() runs on test_CT {
8390
8391 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8392 f_sleep(1.0);
8393
8394 /* Control which MSC gets chosen next by the round-robin, otherwise
8395 * would be randomly affected by which other tests ran before this. */
8396 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8397
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008398 f_ctrs_msc_init();
8399
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008400 var MSC_ConnHdlr vc_conn1;
8401 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8402 pars1.mscpool.rsl_idx := 0;
8403 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8404 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8405 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008406 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008407
8408 var MSC_ConnHdlr vc_conn2;
8409 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8410 pars2.mscpool.rsl_idx := 1;
8411 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8412 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8413 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008414 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008415
8416 /* Test round-robin wrap to the first MSC */
8417 var MSC_ConnHdlr vc_conn3;
8418 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8419 pars3.mscpool.rsl_idx := 2;
8420 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8421 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8422 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008423 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008424 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008425}
8426
8427/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI not
8428 * assigned to any MSC (configured in osmo-bsc.cfg). */
8429/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8430 * just as well using only RSL. */
8431testcase TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() runs on test_CT {
8432
8433 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8434 f_sleep(1.0);
8435
8436 /* Control which MSC gets chosen next by the round-robin, otherwise
8437 * would be randomly affected by which other tests ran before this. */
8438 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8439
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008440 f_ctrs_msc_init();
8441
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008442 var MSC_ConnHdlr vc_conn1;
8443 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8444 pars1.mscpool.rsl_idx := 0;
8445 /* An NRI that is not assigned to any MSC */
8446 pars1.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(1023))));
8447 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8448 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008449 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008450
8451 var MSC_ConnHdlr vc_conn2;
8452 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8453 pars2.mscpool.rsl_idx := 1;
8454 /* An NRI that is not assigned to any MSC */
8455 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(768)), '00F110'O));
8456 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8457 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008458 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008459
8460 /* Test round-robin wrap to the first MSC */
8461 var MSC_ConnHdlr vc_conn3;
8462 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8463 pars3.mscpool.rsl_idx := 2;
8464 /* An NRI that is not assigned to any MSC */
8465 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, valueof(ts_MI_TMSI_NRI_LV(819))));
8466 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8467 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008468 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008469 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008470}
8471
8472/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI
8473 * assigned to an MSC that is currently not connected (configured in osmo-bsc.cfg). */
8474/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8475 * just as well using only RSL. */
8476testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() runs on test_CT {
8477
8478 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8479 f_sleep(1.0);
8480
8481 /* Control which MSC gets chosen next by the round-robin, otherwise
8482 * would be randomly affected by which other tests ran before this. */
8483 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8484
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008485 f_ctrs_msc_init();
8486
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008487 var MSC_ConnHdlr vc_conn1;
8488 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8489 pars1.mscpool.rsl_idx := 0;
8490 /* An NRI that is assigned to an unconnected MSC */
8491 pars1.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(512))));
8492 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8493 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008494 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8495 f_ctrs_msc_add(0, "mscpool:subscr:new");
8496 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008497
8498 var MSC_ConnHdlr vc_conn2;
8499 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8500 pars2.mscpool.rsl_idx := 1;
8501 /* An NRI that is assigned to an unconnected MSC */
8502 pars2.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(767))));
8503 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8504 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008505 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8506 f_ctrs_msc_add(1, "mscpool:subscr:new");
8507 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008508
8509 /* Test round-robin wrap to the first MSC */
8510 var MSC_ConnHdlr vc_conn3;
8511 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8512 pars3.mscpool.rsl_idx := 2;
8513 /* An NRI that is assigned to an unconnected MSC */
8514 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(750)), '00F110'O));
8515 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8516 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008517 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8518 f_ctrs_msc_add(0, "mscpool:subscr:new");
8519 f_ctrs_msc_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008520 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008521}
8522
8523/* Three Layer 3 Complete by TMSI with valid NRI for the second MSC are all directed to the second MSC (configured in
8524 * osmo-bsc.cfg). */
8525/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8526 * just as well using only RSL. */
8527testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_1() runs on test_CT {
8528
8529 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8530 f_sleep(1.0);
8531
8532 /* All TMSIs in this test point at the second MSC, set the round robin to point at the first MSC to make sure
8533 * this is not using round-robin. */
8534 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8535
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008536 f_ctrs_msc_init();
8537
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008538 var MSC_ConnHdlr vc_conn1;
8539 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
8540 pars1.mscpool.rsl_idx := 0;
8541 /* An NRI of the second MSC's range (256-511) */
8542 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(256))));
8543 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8544 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008545 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008546
8547 var MSC_ConnHdlr vc_conn2;
8548 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8549 pars2.mscpool.rsl_idx := 1;
8550 /* An NRI of the second MSC's range (256-511) */
8551 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(260))));
8552 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8553 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008554 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008555
8556 var MSC_ConnHdlr vc_conn3;
8557 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
8558 pars3.mscpool.rsl_idx := 2;
8559 /* An NRI of the second MSC's range (256-511) */
8560 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(511)), '00F110'O));
8561 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8562 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008563 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008564 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008565}
8566
8567/* Layer 3 Complete by TMSI with valid NRI for the third MSC are directed to the third MSC (configured in osmo-bsc.cfg),
8568 * while a round-robin remains unaffected by that. */
8569/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8570 * just as well using only RSL. */
8571testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_2() runs on test_CT {
8572
8573 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8574 f_sleep(1.0);
8575
8576 /* All TMSIs in this test point at the third MSC, set the round robin to point at the second MSC to make sure
8577 * this is not using round-robin. */
8578 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
8579
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008580 f_ctrs_msc_init();
8581
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008582 var MSC_ConnHdlr vc_conn1;
8583 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 2);
8584 pars1.mscpool.rsl_idx := 0;
8585 /* An NRI of the third MSC's range (512-767) */
8586 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(512))));
8587 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8588 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008589 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008590
8591 var MSC_ConnHdlr vc_conn2;
8592 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8593 pars2.mscpool.rsl_idx := 1;
8594 /* An NRI of the third MSC's range (512-767) */
8595 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(678))));
8596 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8597 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008598 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008599
8600 /* The above forwardings to third MSC have not affected the round robin, which still points at the second MSC */
8601 var MSC_ConnHdlr vc_conn3;
8602 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
8603 pars3.mscpool.rsl_idx := 2;
8604 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000013'H)), '00F110'O));
8605 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8606 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008607 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008608 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008609}
8610
8611/* LU with a TMSI but indicating a different PLMN in its previous LAI: ignore the NRI. */
8612/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8613 * just as well using only RSL. */
8614testcase TC_mscpool_LU_by_tmsi_from_other_PLMN() runs on test_CT {
8615
8616 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8617 f_sleep(1.0);
8618
8619 /* The TMSIs in this test points at the second MSC, but since it is from a different PLMN, round-robin is used
8620 * instead, and hits msc 0. */
8621 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8622
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008623 f_ctrs_msc_init();
8624
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008625 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-bsc.cfg */
8626 var MSC_ConnHdlr vc_conn1;
8627 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8628 pars1.mscpool.rsl_idx := 0;
8629 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(260)), '99F999'O));
8630 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8631 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008632 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008633
8634 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
8635 var MSC_ConnHdlr vc_conn2;
8636 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8637 pars2.mscpool.rsl_idx := 1;
8638 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(555)), '00F110'O));
8639 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8640 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008641 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008642 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008643}
8644
8645/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by IMSI, which would be
8646 * round-robined to another MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
8647private function f_tc_mscpool_paging_imsi(charstring id) runs on MSC_ConnHdlr {
8648 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
8649 //cid_list := { cIl_allInBSS := ''O };
8650 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
8651 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
8652 var BSSAP_N_UNITDATA_req paging;
8653 var hexstring imsi := '001010000000123'H;
8654
8655 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8656
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008657 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008658 valueof(ts_BSSMAP_Paging(imsi, cid_list, omit, bssmap_chneed))));
8659 BSSAP.send(paging);
8660
8661 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
8662 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
8663 * channel number is picked here. */
8664 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
8665 f_rslem_register(0, new_chan_nr);
8666 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(imsi)));
8667 f_rslem_unregister(0, new_chan_nr);
8668
8669 /* Despite the round robin pointing at the second MSC ('roundrobin next 1'), the earlier Paging for the same IMSI
8670 * causes this Paging Response to go to the first MSC (bssap_idx := 0). */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008671 f_perform_compl_l3(RSL, RSL_PROC, ts_PAG_RESP(valueof(ts_MI_IMSI_LV(imsi))) );
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008672 f_sleep(1.0);
8673}
8674testcase TC_mscpool_paging_and_response_imsi() runs on test_CT {
8675 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
8676 f_sleep(1.0);
8677
8678 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
8679 * second MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
8680 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
8681
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008682 f_ctrs_msc_init();
8683
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008684 var MSC_ConnHdlr vc_conn1;
8685 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8686 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008687 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
8688 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008689 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_imsi), pars1);
8690 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008691 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008692 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008693}
8694
8695/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by TMSI with an NRI value
8696 * that matches a different MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
8697private function f_tc_mscpool_paging_tmsi(charstring id) runs on MSC_ConnHdlr {
8698 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
8699 //cid_list := { cIl_allInBSS := ''O };
8700 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
8701 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
8702 var integer nri_v := 300; /* <-- second MSC's NRI */
Harald Weltebf397612021-01-14 20:39:46 +01008703 var octetstring tmsi := f_gen_tmsi(suffix := 0, nri_v := nri_v);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008704 var BSSAP_N_UNITDATA_req paging;
8705
8706 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8707
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008708 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008709 valueof(ts_BSSMAP_Paging('001010000000011'H, cid_list, tmsi, bssmap_chneed))));
8710 BSSAP.send(paging);
8711
8712 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
8713 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
8714 * channel number is picked here. */
8715 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
8716 f_rslem_register(0, new_chan_nr);
8717 RSL.receive(tr_RSL_PAGING_CMD(t_MI_TMSI(tmsi)));
8718 f_rslem_unregister(0, new_chan_nr);
8719
8720 /* Despite the NRI matching the second MSC (NRI from 'msc 1' in osmo-bsc.cfg) and round robin pointing at the
8721 * third MSC ('roundrobin next 2'), the earlier Paging for the same TMSI causes this Paging Response to go to
8722 * the first MSC (bssap_idx := 0). */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008723 f_perform_compl_l3(RSL, RSL_PROC, ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(nri_v))) );
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008724 f_sleep(1.0);
8725}
8726testcase TC_mscpool_paging_and_response_tmsi() runs on test_CT {
8727 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
8728 f_sleep(1.0);
8729
8730 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
8731 * third MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
8732 f_vty_transceive(BSCVTY, "mscpool roundrobin next 2");
8733
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008734 f_ctrs_msc_init();
8735
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008736 var MSC_ConnHdlr vc_conn1;
8737 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8738 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008739 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
8740 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008741 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_tmsi), pars1);
8742 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008743 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008744 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008745}
8746
8747/* For round-robin, skip an MSC that has 'no allow-attach' set. */
8748/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8749 * just as well using only RSL. */
8750testcase TC_mscpool_no_allow_attach_round_robin() runs on test_CT {
8751
8752 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8753 f_sleep(1.0);
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00008754 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
8755 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008756
8757 /* Control which MSC gets chosen next by the round-robin, otherwise
8758 * would be randomly affected by which other tests ran before this. */
8759 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8760
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008761 f_ctrs_msc_init();
8762
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008763 var MSC_ConnHdlr vc_conn1;
8764 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8765 pars1.mscpool.rsl_idx := 0;
8766 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
8767 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8768 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008769 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008770
8771 var MSC_ConnHdlr vc_conn2;
8772 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8773 pars2.mscpool.rsl_idx := 1;
8774 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8775 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8776 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008777 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008778
8779 var MSC_ConnHdlr vc_conn3;
8780 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8781 pars3.mscpool.rsl_idx := 2;
8782 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
8783 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8784 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008785 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008786 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008787}
8788
8789/* An MSC that has 'no allow-attach' set should still serve subscribers that are already attached according to their
8790 * TMSI NRI. */
8791testcase TC_mscpool_no_allow_attach_valid_nri() runs on test_CT {
8792
8793 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8794 f_sleep(1.0);
8795
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00008796 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
8797 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
8798
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008799 /* Control which MSC gets chosen next by the round-robin, otherwise
8800 * would be randomly affected by which other tests ran before this. */
8801 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8802
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008803 f_ctrs_msc_init();
8804
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008805 /* Round robin points at msc 0, but the valid NRI directs to msc 1, even though msc 1 has 'no allow-attach'. */
8806 var MSC_ConnHdlr vc_conn1;
8807 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
8808 pars1.mscpool.rsl_idx := 0;
8809 /* An NRI of the second MSC's range (256-511) */
8810 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_TMSI_NRI_LV(260))));
8811 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8812 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008813 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008814
8815 var MSC_ConnHdlr vc_conn2;
8816 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 0);
8817 pars2.mscpool.rsl_idx := 1;
8818 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8819 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8820 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008821 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008822
8823 var MSC_ConnHdlr vc_conn3;
8824 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 2);
8825 pars3.mscpool.rsl_idx := 2;
8826 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000003'H))));
8827 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8828 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008829 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008830 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008831}
8832
Philipp Maier783681c2020-07-16 16:47:06 +02008833/* Allow/Deny emergency calls globally via VTY */
8834private function f_vty_allow_emerg_msc(boolean allow) runs on test_CT {
8835 f_vty_enter_cfg_msc(BSCVTY, 0);
8836 if (allow) {
8837 f_vty_transceive(BSCVTY, "allow-emergency allow");
8838 } else {
8839 f_vty_transceive(BSCVTY, "allow-emergency deny");
8840 }
8841 f_vty_transceive(BSCVTY, "exit");
8842 f_vty_transceive(BSCVTY, "exit");
8843}
8844
8845/* Allow/Deny emergency calls per BTS via VTY */
8846private function f_vty_allow_emerg_bts(boolean allow, integer bts_nr) runs on test_CT {
8847 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8848 if (allow) {
8849 f_vty_transceive(BSCVTY, "rach emergency call allowed 1");
8850 } else {
8851 f_vty_transceive(BSCVTY, "rach emergency call allowed 0");
8852 }
8853 f_vty_transceive(BSCVTY, "exit");
8854 f_vty_transceive(BSCVTY, "exit");
Neels Hofmeyrb6ed80c2020-10-12 22:52:39 +00008855 f_vty_transceive(BSCVTY, "exit");
Philipp Maier783681c2020-07-16 16:47:06 +02008856}
8857
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02008858/* Allow/Forbid Fast Return after SRVCC on a given BTS via VTY */
8859private function f_vty_allow_srvcc_fast_return(boolean allow, integer bts_nr) runs on test_CT {
8860 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8861 if (allow) {
8862 f_vty_transceive(BSCVTY, "srvcc fast-return allow");
8863 } else {
8864 f_vty_transceive(BSCVTY, "srvcc fast-return forbid");
8865 }
8866 f_vty_transceive(BSCVTY, "exit");
8867 f_vty_transceive(BSCVTY, "exit");
8868 f_vty_transceive(BSCVTY, "exit");
8869}
8870
Pau Espin Pedrol14475352021-07-22 15:48:16 +02008871/* Allow/Forbid TCH for signalling if SDCCH exhausted on a given BTS via VTY */
8872private function f_vty_allow_tch_for_signalling(boolean allow, integer bts_nr) runs on test_CT {
8873 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8874 if (allow) {
8875 f_vty_transceive(BSCVTY, "channel allocator allow-tch-for-signalling 1");
8876 } else {
8877 f_vty_transceive(BSCVTY, "channel allocator allow-tch-for-signalling 0");
8878 }
8879 f_vty_transceive(BSCVTY, "exit");
8880 f_vty_transceive(BSCVTY, "exit");
8881 f_vty_transceive(BSCVTY, "exit");
8882}
8883
Philipp Maier783681c2020-07-16 16:47:06 +02008884/* Begin assignmet procedure and send an EMERGENCY SETUP (RR) */
8885private function f_assignment_emerg_setup() runs on MSC_ConnHdlr {
8886 var PDU_ML3_MS_NW emerg_setup;
8887 var octetstring emerg_setup_enc;
8888 var RSL_Message emerg_setup_data_ind;
8889
8890 f_establish_fully(omit, omit);
8891
8892 emerg_setup := valueof(ts_ML3_MO_CC_EMERG_SETUP(1, valueof(ts_Bcap_voice)));
8893 emerg_setup_enc := enc_PDU_ML3_MS_NW(emerg_setup);
8894 emerg_setup_data_ind := valueof(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), emerg_setup_enc));
8895
8896 RSL.send(emerg_setup_data_ind);
8897}
8898
8899/* Test if the EMERGENCY SETUP gets passed on to the MSC via A when EMERGENCY
8900 * CALLS are permitted by the BSC config. */
8901private function f_TC_assignment_emerg_setup_allow(charstring id) runs on MSC_ConnHdlr {
8902 var PDU_BSSAP emerg_setup_data_ind_bssap;
8903 var PDU_ML3_MS_NW emerg_setup;
8904 timer T := 3.0;
8905
8906 f_assignment_emerg_setup()
8907
8908 T.start;
8909 alt {
8910 [] BSSAP.receive(tr_BSSAP_DTAP) -> value emerg_setup_data_ind_bssap {
8911 emerg_setup := dec_PDU_ML3_MS_NW(emerg_setup_data_ind_bssap.pdu.dtap);
8912 if (not isbound(emerg_setup.msgs.cc.emergencySetup)) {
8913 setverdict(fail, "no emergency setup");
8914 }
8915 }
8916 [] BSSAP.receive {
8917 setverdict(fail, "unexpected BSSAP message!");
8918 }
8919 [] T.timeout {
8920 setverdict(fail, "timout waiting for EMERGENCY SETUP!");
8921 }
8922 }
8923
8924 setverdict(pass);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01008925 f_perform_clear();
Philipp Maier783681c2020-07-16 16:47:06 +02008926}
8927
8928/* Test if the EMERGENCY SETUP gets blocked by the BSC if EMERGENCY CALLS are
8929 * forbidden by the BSC config. */
8930private function f_TC_assignment_emerg_setup_deny(charstring id) runs on MSC_ConnHdlr {
8931 var PDU_BSSAP emerg_setup_data_ind_bssap;
8932 timer T := 3.0;
8933
8934 f_assignment_emerg_setup()
8935
8936 T.start;
8937 alt {
8938 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
8939 setverdict(pass);
8940 }
8941 [] RSL.receive {
8942 setverdict(fail, "unexpected RSL message!");
8943 }
8944 [] T.timeout {
8945 setverdict(fail, "timout waiting for RR CHANNEL RELEASE!");
8946 }
8947 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01008948 BSSAP.receive(tr_BSSMAP_ClearRequest);
Neels Hofmeyrc3c6ee62022-01-26 01:22:12 +01008949 f_perform_clear_no_rr_rel();
Philipp Maier783681c2020-07-16 16:47:06 +02008950}
8951
8952/* EMERGENCY CALL situation #1, allowed globally and by BTS */
8953testcase TC_assignment_emerg_setup_allow() runs on test_CT {
8954 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8955 var MSC_ConnHdlr vc_conn;
8956
8957 f_init(1, true);
8958 f_sleep(1.0);
8959
8960 f_vty_allow_emerg_msc(true);
8961 f_vty_allow_emerg_bts(true, 0);
8962 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_allow), pars);
8963 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008964 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008965}
8966
8967/* EMERGENCY CALL situation #2, forbidden globally but allowed by BTS */
8968testcase TC_assignment_emerg_setup_deny_msc() runs on test_CT {
8969 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8970 var MSC_ConnHdlr vc_conn;
8971
8972 f_init(1, true);
8973 f_sleep(1.0);
8974
8975 f_vty_allow_emerg_msc(false);
8976 f_vty_allow_emerg_bts(true, 0);
8977 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
8978 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008979 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008980}
8981
8982/* EMERGENCY CALL situation #3, allowed globally but forbidden by BTS */
8983testcase TC_assignment_emerg_setup_deny_bts() runs on test_CT {
8984 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8985 var MSC_ConnHdlr vc_conn;
8986
8987 /* Note: This simulates a spec violation by the MS, correct MS
8988 * implementations would not try to establish an emergency call because
8989 * the system information tells in advance that emergency calls are
8990 * not forbidden */
8991
8992 f_init(1, true);
8993 f_sleep(1.0);
8994
8995 f_vty_allow_emerg_msc(true);
8996 f_vty_allow_emerg_bts(false, 0);
8997 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
8998 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008999 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02009000}
9001
Philipp Maier82812002020-08-13 18:48:27 +02009002/* Test what happens when an emergency call arrives while all TCH channels are
9003 * busy, the BSC is expected to terminate one call in favor of the incoming
9004 * emergency call */
9005testcase TC_emerg_premption() runs on test_CT {
9006 var ASP_RSL_Unitdata rsl_ud;
9007 var integer i;
9008 var integer chreq_total, chreq_nochan;
9009 var RSL_Message rx_rsl;
Philipp Maier82812002020-08-13 18:48:27 +02009010
9011 f_init(1);
9012 f_sleep(1.0);
9013
9014 f_vty_allow_emerg_msc(true);
9015 f_vty_allow_emerg_bts(true, 0);
9016
9017 /* Fill up all channels on the BTS */
9018 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
9019 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
9020 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS; i := i+1) {
Neels Hofmeyr32ef5912022-04-24 00:29:04 +02009021 f_chreq_act_ack('33'O, i);
Philipp Maier82812002020-08-13 18:48:27 +02009022 }
9023 IPA_RSL[0].clear;
9024 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
9025 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
9026
Neels Hofmeyrace698c2022-04-24 00:30:21 +02009027 /* Send EST IND for the first TCH, so we get to test the RR release cause */
9028 var RslChannelNr first_tch := valueof(t_RslChanNr_Bm(1));
9029 var octetstring l3 := '00010203040506'O;
9030 f_ipa_tx(0, ts_RSL_EST_IND(first_tch, valueof(ts_RslLinkID_DCCH(0)), l3));
9031
Neels Hofmeyrde564b12022-04-24 23:11:46 +02009032 /* Accept BSSAP conn, so we get to test the Clear Request cause */
9033 var BSSAP_N_CONNECT_ind rx_c_ind;
9034 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
9035 var integer sccp_conn_id := rx_c_ind.connectionId;
9036 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
9037
Philipp Maier82812002020-08-13 18:48:27 +02009038 /* Send Channel request for emegergency call */
9039 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
9040
9041 /* Expect the BSC to release one (the first) TCH/F on the BTS */
Neels Hofmeyrace698c2022-04-24 00:30:21 +02009042 f_expect_chan_rel(0, first_tch, expect_rr_chan_rel := true, expect_rll_rel_req := false,
9043 expect_rr_cause := GSM48_RR_CAUSE_PREMPTIVE_REL);
Philipp Maier82812002020-08-13 18:48:27 +02009044
Neels Hofmeyrde564b12022-04-24 23:11:46 +02009045 /* Also expect a BSSMAP Clear Request with PREEMPTION */
9046 var BSSAP_N_DATA_ind rx_clear_req;
9047 const myBSSMAP_Cause preemption := GSM0808_CAUSE_PREEMPTION;
9048 BSSAP.receive(tr_BSSAP_DATA_ind(sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_clear_req;
9049 log("XXX ", rx_clear_req);
9050 if (rx_clear_req.userData.pdu.bssmap.clearRequest.cause.causeValue != int2bit(enum2int(preemption), 7)) {
9051 setverdict(fail, "BSSMAP Clear Request: expected cause PREEMPTION");
9052 }
9053
Neels Hofmeyr32ef5912022-04-24 00:29:04 +02009054 /* Expect the BSC to send activate/assign the channel for the emergency call */
Philipp Maier82812002020-08-13 18:48:27 +02009055 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Neels Hofmeyr32ef5912022-04-24 00:29:04 +02009056 if (first_tch != rx_rsl.ies[0].body.chan_nr) {
9057 setverdict(fail, "different TCH lchan activated than expected");
9058 }
9059 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(first_tch, 33));
Philipp Maier82812002020-08-13 18:48:27 +02009060 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Philipp Maier104f4c02020-09-11 18:12:18 +02009061
Neels Hofmeyrde564b12022-04-24 23:11:46 +02009062 /* complete the BSSMAP Clear to satisfy the conn leak check */
9063 BSSAP.send(ts_BSSAP_DATA_req(sccp_conn_id, ts_BSSMAP_ClearCommand(enum2int(preemption))));
9064 BSSAP.receive(tr_BSSAP_DATA_ind(sccp_conn_id, tr_BSSMAP_ClearComplete)) {
9065 BSSAP.send(ts_BSSAP_DISC_req(sccp_conn_id, 0));
9066 }
9067
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02009068 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009069}
9070
9071/* Hopping parameters per a timeslot */
Vadim Yanitskiybc6654a2020-09-13 01:27:40 +07009072private type record length(0..64) of GsmArfcn ArfcnList;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009073private type record FHParamsTs {
9074 boolean enabled,
9075 uint6_t hsn,
9076 uint6_t maio,
9077 ArfcnList ma
9078};
9079
9080/* Hopping parameters per a transceiver */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009081private type record FHParamsTrx {
Philipp Maier798d8952021-10-19 14:43:19 +02009082 GsmBandArfcn arfcn,
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009083 FHParamsTs ts[8]
9084};
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009085
9086/* Randomly generate the hopping parameters for the given timeslot numbers */
9087private function f_TC_fh_params_gen(template integer tr_tn := (1, 3, 5))
9088runs on test_CT return FHParamsTrx {
9089 var FHParamsTrx fhp;
9090
Philipp Maier798d8952021-10-19 14:43:19 +02009091 /* Generate a random ARFCN in the range of 0 - 3. This ARFCN will
9092 * fall in the GSM900 band. */
9093 fhp.arfcn.arfcn := f_rnd_int(3);
9094 fhp.arfcn.pcs := false;
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009095
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009096 for (var integer tn := 0; tn < 8; tn := tn + 1) {
9097 if (not match(tn, tr_tn)) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009098 fhp.ts[tn].enabled := false;
9099 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009100 continue;
9101 }
9102
9103 /* Random HSN / MAIO values: 0..63 */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009104 fhp.ts[tn].hsn := f_rnd_int(64);
9105 fhp.ts[tn].maio := f_rnd_int(64);
9106 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009107
9108 /* Random Mobile Allocation (hopping channels) */
9109 var integer ma_len := 2 + f_rnd_int(9); /* 2..10 channels */
9110 var integer step := 3 + f_rnd_int(4); /* 3..6 stepping */
9111 for (var integer i := 1; i <= ma_len; i := i + 1) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009112 fhp.ts[tn].ma := fhp.ts[tn].ma & { i * step };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009113 }
9114
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009115 fhp.ts[tn].enabled := true;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009116 }
9117
9118 log("f_TC_fh_params_gen(): ", fhp);
9119 return fhp;
9120}
9121
9122/* Make sure that the given Channel Description IE matches the hopping configuration */
9123private function f_TC_fh_params_match_chan_desc(in FHParamsTrx fhp, in ChannelDescription cd)
9124{
9125 var template (present) ChannelDescription tr_cd;
9126 var template (present) MaioHsn tr_maio_hsn;
9127 var uint3_t tn := cd.chan_nr.tn;
9128
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009129 if (fhp.ts[tn].enabled) {
9130 tr_maio_hsn := tr_HsnMaio(fhp.ts[tn].hsn, fhp.ts[tn].maio);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009131 tr_cd := tr_ChanDescH1(cd.chan_nr, tr_maio_hsn);
9132 } else {
Philipp Maier798d8952021-10-19 14:43:19 +02009133 tr_cd := tr_ChanDescH0(cd.chan_nr, fhp.arfcn.arfcn);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009134 }
9135
9136 if (not match(cd, tr_cd)) {
9137 setverdict(fail, "Channel Description IE does not match: ",
9138 cd, " vs expected ", tr_cd);
9139 }
9140}
9141
9142/* Make sure that the given Mobile Allocation IE matches the hopping configuration */
9143private function f_TC_fh_params_match_ma(in FHParamsTrx fhp, uint3_t tn,
9144 in MobileAllocationLV ma)
9145{
9146 var template MobileAllocationLV tr_ma := f_TC_fh_params_gen_tr_ma(fhp, tn, ma);
9147
9148 if (not match(ma, tr_ma)) {
9149 setverdict(fail, "Mobile Allocation IE does not match (tn := ",
9150 tn, "): ", ma, " vs expected: ", tr_ma);
9151 } else {
9152 setverdict(pass);
9153 }
9154}
9155
9156private function f_TC_fh_params_gen_tr_ma(in FHParamsTrx fhp, uint3_t tn,
9157 in MobileAllocationLV ma)
9158return template MobileAllocationLV {
9159 /* Mobile Allocation IE is expected to be empty if hopping is not enabled */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009160 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009161 return { len := 0, ma := ''B };
9162 }
9163
9164 var bitstring full_mask := f_pad_bit(''B, 1024, '0'B);
9165 var bitstring slot_mask := f_pad_bit(''B, 1024, '0'B);
9166 var bitstring ma_mask := ''B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009167
9168 /* Compose the full bit-mask (all channels, up to 1024 entries) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009169 for (var integer i := 0; i < lengthof(fhp.ts); i := i + 1) {
9170 for (var integer j := 0; j < lengthof(fhp.ts[i].ma); j := j + 1) {
9171 if (full_mask[fhp.ts[i].ma[j]] == '1'B)
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009172 { continue; }
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009173 full_mask[fhp.ts[i].ma[j]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009174 }
9175 }
9176
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009177 /* Take ARFCN of the TRX itself into account */
Philipp Maier798d8952021-10-19 14:43:19 +02009178 full_mask[fhp.arfcn.arfcn] := '1'B;
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009179
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009180 /* Compose a bit-mask for the given timeslot number */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009181 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
9182 slot_mask[fhp.ts[tn].ma[i]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009183 }
9184
9185 /* Finally, compose the Mobile Allocation bit-mask */
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07009186 for (var integer i := 1; i < lengthof(full_mask); i := i + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009187 if (full_mask[i] != '1'B)
9188 { continue; }
9189
9190 /* FIXME: ma_mask := ma_mask & slot_mask[i]; // triggers a bug in TITAN */
9191 if (slot_mask[i] == '1'B) {
9192 ma_mask := ma_mask & '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009193 } else {
9194 ma_mask := ma_mask & '0'B;
9195 }
9196 }
9197
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07009198 /* ARFCN 0 (if present) goes to the last position of the bit-mask */
9199 if (full_mask[0] == '1'B) {
9200 /* FIXME: ma_mask := ma_mask & slot_mask[0]; // triggers a bug in TITAN */
9201 if (slot_mask[0] == '1'B) {
9202 ma_mask := ma_mask & '1'B;
9203 } else {
9204 ma_mask := ma_mask & '0'B;
9205 }
9206 }
9207
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009208 /* Ensure that ma_mask is octet-aligned */
Vadim Yanitskiy2aa02522020-09-06 14:05:23 +07009209 var integer ma_mask_len := (lengthof(ma_mask) + 8 - 1) / 8;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009210 ma_mask := f_pad_bit(ma_mask, ma_mask_len * 8, '0'B);
9211
9212 return { len := ma_mask_len, ma := ma_mask };
9213}
9214
Philipp Maier798d8952021-10-19 14:43:19 +02009215/* Configure the appropriate band for a given arfcn, exc */
9216private function f_TC_set_band_by_arfcn(integer bts_nr, GsmBandArfcn arfcn) runs on test_CT
9217{
9218 var charstring band;
9219 var GsmBandArfcn arfcn_ := valueof(ts_GsmBandArfcn(arfcn.arfcn, arfcn.pcs, false));
9220
9221 select (arfcn_) {
9222 case (tr_GsmBandArfcn((259..293), false, ?)) { band := "GSM450"; }
9223 case (tr_GsmBandArfcn((306..340), false, ?)) { band := "GSM480"; }
9224 case (tr_GsmBandArfcn((438..511), false, ?)) { band := "GSM750"; }
9225 case (tr_GsmBandArfcn((128..251), false, ?)) { band := "GSM850"; }
9226 case (tr_GsmBandArfcn((0..124), false, ?)) { band := "GSM900"; }
9227 case (tr_GsmBandArfcn((955..1023), false, ?)) { band := "GSM900"; }
9228 case (tr_GsmBandArfcn((512..885), false, ?)) { band := "DCS1800"; }
9229 case (tr_GsmBandArfcn((512..810), true, ?)) { band := "PCS1900"; }
9230 case else { return; }
9231 }
9232
9233 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
9234 f_vty_transceive(BSCVTY, "band " & band);
9235 f_vty_transceive(BSCVTY, "end");
9236}
9237
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009238/* Configure the hopping parameters in accordance with the given record */
9239private function f_TC_fh_params_set(in FHParamsTrx fhp,
9240 uint8_t bts_nr := 0,
9241 uint8_t trx_nr := 0)
9242runs on test_CT {
Philipp Maier798d8952021-10-19 14:43:19 +02009243
9244 f_TC_set_band_by_arfcn(bts_nr, fhp.arfcn);
9245
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009246 /* Enter the configuration node for the given BTS/TRX numbers */
9247 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
9248
Philipp Maier798d8952021-10-19 14:43:19 +02009249 f_vty_transceive(BSCVTY, "arfcn " & int2str(fhp.arfcn.arfcn));
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009250
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009251 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009252 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
9253
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009254 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009255 f_vty_transceive(BSCVTY, "hopping enabled 0");
9256 f_vty_transceive(BSCVTY, "exit"); /* go back */
9257 continue;
9258 }
9259
9260 /* Configure HSN / MAIO values */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009261 f_vty_transceive(BSCVTY, "hopping sequence-number " & int2str(fhp.ts[tn].hsn));
9262 f_vty_transceive(BSCVTY, "hopping maio " & int2str(fhp.ts[tn].maio));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009263
9264 /* Configure the Mobile Allocation (hopping channels) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009265 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
9266 f_vty_transceive(BSCVTY, "hopping arfcn add " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009267 }
9268
9269 f_vty_transceive(BSCVTY, "hopping enabled 1");
9270 f_vty_transceive(BSCVTY, "exit"); /* go back */
9271 }
9272
9273 f_vty_transceive(BSCVTY, "end");
9274}
9275
9276/* Disable frequency hopping on all timeslots */
9277private function f_TC_fh_params_unset(in FHParamsTrx fhp,
9278 uint8_t bts_nr := 0,
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009279 uint8_t trx_nr := 0,
Philipp Maier798d8952021-10-19 14:43:19 +02009280 GsmBandArfcn arfcn := {pcs := false, arfcn := 871})
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009281runs on test_CT {
Philipp Maier798d8952021-10-19 14:43:19 +02009282
9283 f_TC_set_band_by_arfcn(bts_nr, arfcn);
9284
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009285 /* Enter the configuration node for the given BTS/TRX numbers */
9286 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
9287
Philipp Maier798d8952021-10-19 14:43:19 +02009288 f_vty_transceive(BSCVTY, "arfcn " & int2str(arfcn.arfcn));
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009289
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009290 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009291 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
9292
9293 /* Delete all ARFCNs from the Mobile Allocation (if any) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009294 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
9295 f_vty_transceive(BSCVTY, "hopping arfcn del " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009296 }
9297
9298 f_vty_transceive(BSCVTY, "hopping enabled 0");
9299 f_vty_transceive(BSCVTY, "exit"); /* go back */
9300 }
9301
9302 f_vty_transceive(BSCVTY, "end");
9303 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9304}
9305
9306/* Verify presence and correctness of the hopping parameters (HSN, MAIO)
9307 * in the Channel Identification IE of the RSL CHANnel ACTIVation message. */
9308testcase TC_fh_params_chan_activ() runs on test_CT {
9309 var FHParamsTrx fhp := f_TC_fh_params_gen();
9310 var RSL_Message rsl_msg;
9311 var RSL_IE_Body ie;
9312
9313 f_init_vty();
9314
9315 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9316 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9317
9318 f_init(1);
9319
9320 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
9321 for (var integer i := 0; i < 9; i := i + 1) {
9322 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
9323 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9324
9325 /* Make sure that Channel Identification IE is present */
9326 if (not f_rsl_find_ie(rsl_msg, RSL_IE_CHAN_IDENT, ie)) {
9327 setverdict(fail, "RSL Channel Identification IE is absent");
9328 continue;
9329 }
9330
9331 /* Make sure that hopping parameters (HSN/MAIO) match */
9332 f_TC_fh_params_match_chan_desc(fhp, ie.chan_ident.ch_desc.v);
9333
9334 /* "Mobile Allocation shall be included but empty" - let's check this */
9335 if (ie.chan_ident.ma.v.len != 0) {
9336 setverdict(fail, "Mobile Allocation IE is not empty: ",
9337 ie.chan_ident.ma, ", despite it shall be");
9338 continue;
9339 }
9340 }
9341
9342 /* Disable frequency hopping */
9343 f_TC_fh_params_unset(fhp);
9344
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009345 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009346}
9347
9348/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Immediate Assignment */
9349testcase TC_fh_params_imm_ass() runs on test_CT {
9350 var FHParamsTrx fhp := f_TC_fh_params_gen();
9351 var RSL_Message rsl_msg;
9352 var RSL_IE_Body ie;
9353
9354 f_init_vty();
9355
9356 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9357 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9358
9359 f_init(1);
9360
9361 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
9362 for (var integer i := 0; i < 9; i := i + 1) {
9363 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
9364 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9365
9366 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9367 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
9368
9369 /* Make sure that Full Immediate Assign Info IE is present */
9370 if (not f_rsl_find_ie(rsl_msg, RSL_IE_FULL_IMM_ASS_INFO, ie)) {
9371 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
9372 continue;
9373 }
9374
9375 /* Decode the actual Immediate Assignment message */
9376 var GsmRrMessage rr_msg := dec_GsmRrMessage(ie.full_imm_ass_info.payload);
9377 if (not match(rr_msg.header, t_RrHeader(IMMEDIATE_ASSIGNMENT, ?))) {
9378 setverdict(fail, "Failed to match Immediate Assignment: ", rr_msg);
9379 continue;
9380 }
9381
9382 /* Make sure that hopping parameters (HSN/MAIO) match */
9383 f_TC_fh_params_match_chan_desc(fhp, rr_msg.payload.imm_ass.chan_desc);
9384
9385 /* Make sure that the Mobile Allocation IE matches */
9386 f_TC_fh_params_match_ma(fhp, rr_msg.payload.imm_ass.chan_desc.chan_nr.tn,
9387 rr_msg.payload.imm_ass.mobile_allocation);
9388 }
9389
9390 /* Disable frequency hopping */
9391 f_TC_fh_params_unset(fhp);
Philipp Maier82812002020-08-13 18:48:27 +02009392
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009393 f_shutdown_helper();
Philipp Maier82812002020-08-13 18:48:27 +02009394}
9395
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009396/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Assignment Command */
9397testcase TC_fh_params_assignment_cmd() runs on test_CT {
9398 var FHParamsTrx fhp := f_TC_fh_params_gen();
9399 var RSL_Message rsl_msg;
9400 var RSL_IE_Body ie;
9401
9402 f_init_vty();
9403
9404 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9405 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9406
9407 f_init(1);
9408
9409 /* HACK: work around "Couldn't find Expect for CRCX" */
9410 vc_MGCP.stop;
9411
9412 var template PDU_BSSAP ass_cmd := f_gen_ass_req();
9413 ass_cmd.pdu.bssmap.assignmentRequest.codecList := ts_BSSMAP_IE_CodecList({ts_CodecFR});
9414
9415 /* CS domain (TCH): 4 (TCH/F) + 2 (TCH/H) channels available
9416 * NOTE: only 3 SDCCH/4 channels are available on CCCH+SDCCH4+CBCH */
9417 for (var integer i := 0; i < 3; i := i + 1) {
9418 /* Establish a dedicated channel, so we can trigger (late) TCH assignment */
9419 var DchanTuple dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
9420
9421 /* Send a BSSMAP Assignment Command, expect CHANnel ACTIVation */
9422 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
9423 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9424
9425 /* ACKnowledge CHANnel ACTIVation, expect RSL DATA REQuest */
9426 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9427 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
9428
9429 /* Make sure that L3 Information IE is present */
9430 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
9431 setverdict(fail, "RSL L3 Information IE is absent");
9432 continue;
9433 }
9434
9435 /* Decode the L3 message and make sure it is (RR) Assignment Command */
9436 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
9437 if (not match(l3_msg.header, t_RrL3Header(ASSIGNMENT_COMMAND))) {
9438 setverdict(fail, "Failed to match Assignment Command: ", l3_msg);
9439 continue;
9440 }
9441
9442 /* Make sure that hopping parameters (HSN/MAIO) match */
9443 var ChannelDescription chan_desc := l3_msg.payload.ass_cmd.chan_desc;
9444 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9445
9446 /* Make sure that Cell Channel Description IE is present if FH is enabled */
9447 if (chan_desc.h and not ispresent(l3_msg.payload.ass_cmd.cell_chan_desc)) {
Vadim Yanitskiy38d069d2020-09-02 17:18:57 +07009448 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009449 continue;
9450 }
9451
9452 /* Make sure that the Mobile Allocation IE matches (if present) */
9453 var boolean ma_present := ispresent(l3_msg.payload.ass_cmd.mobile_allocation);
9454 if (chan_desc.h and ma_present) {
9455 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9456 l3_msg.payload.ass_cmd.mobile_allocation.v);
9457 } else if (chan_desc.h and not ma_present) {
9458 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9459 continue;
9460 } else if (not chan_desc.h and ma_present) {
9461 setverdict(fail, "FH disabled, but Mobile Allocation IE is present");
9462 continue;
9463 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01009464
9465 f_perform_clear_test_ct(dt);
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009466 }
9467
9468 /* Give the IUT some time to release all channels */
9469 f_sleep(3.0);
9470
9471 /* Disable frequency hopping */
9472 f_TC_fh_params_unset(fhp);
9473
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009474 f_shutdown_helper();
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009475}
9476
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009477/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Handover Command */
9478private function f_TC_fh_params_handover_cmd(in FHParamsTrx fhp)
9479runs on test_CT {
9480 var RSL_Message rsl_msg;
9481 var RSL_IE_Body ie;
9482 var DchanTuple dt;
9483
9484 /* Establish a dedicated channel, so we can trigger handover */
9485 dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
Vadim Yanitskiyc18ff472021-11-18 20:15:37 +03009486 f_sleep(0.5);
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009487
9488 /* Trigger handover from BTS0 to BTS1 */
9489 f_bts_0_cfg(BSCVTY, { "neighbor bts 1" });
9490 f_vty_handover(BSCVTY, 0, 0, dt.rsl_chan_nr, 1);
9491
9492 /* Expect RSL CHANnel ACTIVation on BTS1/TRX0/TS1 */
9493 rsl_msg := f_exp_ipa_rx(1, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9494
9495 /* ACKnowledge channel activation and expect (RR) Handover Command */
9496 f_ipa_tx(1, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9497 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
9498
9499 /* Make sure that L3 Information IE is present */
9500 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
9501 setverdict(fail, "RSL L3 Information IE is absent");
9502 return;
9503 }
9504
9505 /* Decode the L3 message and make sure it is (RR) Handover Command */
9506 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
9507 if (not match(l3_msg.header, t_RrL3Header(HANDOVER_COMMAND))) {
9508 setverdict(fail, "Failed to match Handover Command: ", l3_msg);
9509 return;
9510 }
9511
9512 /* Make sure that we've got SDCCH/8 on TS1 (expected to be hopping) */
9513 var ChannelDescription chan_desc := l3_msg.payload.ho_cmd.chan_desc;
9514 if (not match(chan_desc.chan_nr, t_RslChanNr_SDCCH8(1, ?))) {
9515 setverdict(fail, "Unexpected channel number: ", chan_desc.chan_nr);
9516 return;
9517 }
9518
9519 /* Make sure that hopping parameters (HSN/MAIO) match */
9520 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9521
9522 /* Make sure that Cell Channel Description IE is present */
9523 if (not ispresent(l3_msg.payload.ho_cmd.cell_chan_desc)) {
9524 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
9525 return;
9526 }
9527
9528 /* Make sure that the Mobile Allocation (after time) IE is present and matches */
9529 var boolean ma_present := ispresent(l3_msg.payload.ho_cmd.mobile_allocation);
9530 if (ma_present) {
9531 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9532 l3_msg.payload.ho_cmd.mobile_allocation.v);
9533 } else {
9534 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9535 return;
9536 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01009537
9538 f_perform_clear_test_ct(dt);
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009539}
9540testcase TC_fh_params_handover_cmd() runs on test_CT {
9541 var FHParamsTrx fhp := f_TC_fh_params_gen();
9542
9543 f_init_vty();
9544
9545 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8 on BTS1/TRX0 */
9546 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
9547
9548 f_vty_transceive(BSCVTY, "timeslot 0");
9549 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
9550 f_vty_transceive(BSCVTY, "exit"); /* go back */
9551
9552 f_vty_transceive(BSCVTY, "timeslot 1");
9553 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8");
9554 f_vty_transceive(BSCVTY, "end"); /* we're done */
9555
9556 f_TC_fh_params_set(fhp, 1); /* Enable frequency hopping on BTS1 */
9557 f_vty_transceive(BSCVTY, "drop bts connection 1 oml");
9558
9559 f_init(2);
9560
9561 f_TC_fh_params_handover_cmd(fhp);
9562
9563 /* Disable frequency hopping on BTS1 */
9564 f_TC_fh_params_unset(fhp, 1);
9565
9566 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
9567 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
9568
9569 f_vty_transceive(BSCVTY, "timeslot 0");
9570 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
9571 f_vty_transceive(BSCVTY, "exit"); /* go back */
9572
9573 f_vty_transceive(BSCVTY, "timeslot 1");
9574 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
9575 f_vty_transceive(BSCVTY, "end"); /* we're done */
9576
9577 f_shutdown_helper();
9578}
9579
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009580/* Verify the hopping parameters in System Information Type 4 */
9581testcase TC_fh_params_si4_cbch() runs on test_CT {
9582 var FHParamsTrx fhp := f_TC_fh_params_gen(tr_tn := 1);
9583 var ASP_RSL_Unitdata rx_rsl_ud;
9584 timer T := 5.0;
9585
9586 f_init_vty();
9587
9588 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8+CBCH */
9589 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
9590
9591 f_vty_transceive(BSCVTY, "timeslot 0");
9592 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
9593 f_vty_transceive(BSCVTY, "exit"); /* go back */
9594
9595 f_vty_transceive(BSCVTY, "timeslot 1");
9596 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8+cbch");
9597 f_vty_transceive(BSCVTY, "end"); /* we're done */
9598
9599 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9600 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9601
9602 f_init(1);
9603
9604 T.start;
9605 alt {
9606 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO(RSL_SYSTEM_INFO_4))) -> value rx_rsl_ud {
9607 var RSL_IE_Body ie := rx_rsl_ud.rsl.ies[2].body; /* FULL BCCH Information IE */
9608 var SystemInformation si := dec_SystemInformation(ie.other.payload);
9609
9610 /* Make sure that what we decoded is System Information Type 4 */
9611 if (si.header.message_type != SYSTEM_INFORMATION_TYPE_4) {
9612 setverdict(fail, "RSL FULL BCCH Information IE contains: ", si);
9613 repeat;
9614 }
9615
9616 /* Make sure that CBCH Channel Description IE is present */
9617 if (not ispresent(si.payload.si4.cbch_chan_desc)) {
9618 setverdict(fail, "CBCH Channel Description IE is absent");
9619 break;
9620 }
9621
9622 /* Finally, check the hopping parameters (HSN, MAIO) */
9623 var ChannelDescription chan_desc := si.payload.si4.cbch_chan_desc.v;
9624 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9625
9626 /* 3GPP TS 44.018, section 9.1.36.2 "CBCH Mobile Allocation":
9627 * The CBCH Mobile Allocation IE *shall* be present if FH is enabled. */
9628 if (chan_desc.h and not ispresent(si.payload.si4.cbch_mobile_alloc)) {
9629 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9630 break;
9631 } else if (chan_desc.h and ispresent(si.payload.si4.cbch_mobile_alloc)) {
9632 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9633 si.payload.si4.cbch_mobile_alloc.v);
9634 }
9635 }
9636 [] IPA_RSL[0].receive { repeat; }
9637 [] T.timeout {
9638 setverdict(fail, "Timeout waiting for RSL BCCH INFOrmation (SI4)");
9639 }
9640 }
9641
9642 /* Disable frequency hopping */
9643 f_TC_fh_params_unset(fhp);
9644
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07009645 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009646 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
9647
9648 f_vty_transceive(BSCVTY, "timeslot 0");
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07009649 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009650 f_vty_transceive(BSCVTY, "exit"); /* go back */
9651
9652 f_vty_transceive(BSCVTY, "timeslot 1");
9653 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
9654 f_vty_transceive(BSCVTY, "end"); /* we're done */
9655
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009656 f_shutdown_helper();
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009657}
9658
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009659template (value) PDU_BSSAP_LE ts_BSSMAP_LE_BSSLAP(template (value) BSSLAP_PDU bsslap)
9660 := ts_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, data := enc_BSSLAP_PDU(valueof(bsslap)));
9661
9662private function f_match_bsslap(PDU_BSSAP_LE got_bsslap_msg,
9663 template (present) BSSLAP_PDU expect_bsslap)
9664{
9665 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(got_bsslap_msg.pdu.bssmap.co_info.bsslap_apdu.data);
9666 if (not match(bsslap, expect_bsslap)) {
9667 log("EXPECTING BSSLAP: ", expect_bsslap);
9668 log("GOT BSSLAP: ", bsslap);
9669 setverdict(fail, "BSSLAP is not as expected");
9670 mtc.stop;
9671 }
9672 setverdict(pass);
9673}
9674
9675/* GAD: this is an Ellipsoid point with uncertainty circle, encoded as in 3GPP TS 23.032 §7.3.2. */
9676const octetstring gad_ell_point_unc_circle := '10b0646d0d5f6627'O;
9677
9678private function f_expect_bsslap(template (present) BSSLAP_PDU expect_rx_bsslap) runs on MSC_ConnHdlr {
9679 var PDU_BSSAP_LE rx_bsslap;
9680 BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap);
9681 f_match_bsslap(rx_bsslap, expect_rx_bsslap);
9682}
9683
9684/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9685 * Request on Lb interface. Either with or without the SMLC doing a BSSLAP TA Request. */
9686private function f_lcs_loc_req_for_active_ms(boolean do_ta_request := false) runs on MSC_ConnHdlr {
9687 f_sleep(1.0);
9688
9689 f_establish_fully(omit, omit);
9690 f_bssap_le_register_imsi(g_pars.imsi, omit);
9691
9692 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9693 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9694
9695 var PDU_BSSAP_LE plr;
9696 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9697
9698 if (not do_ta_request) {
9699 /* verify TA Layer 3 in APDU. First the APDU type (BSSLAP), then the BSSLAP data contents. */
9700 var template BSSMAP_LE_IE_APDU expect_apdu := tr_BSSMAP_LE_APDU(BSSMAP_LE_PROT_BSSLAP, ?);
9701 if (not match(plr.pdu.bssmap.perf_loc_req.bsslap_apdu, expect_apdu)) {
9702 log("EXPECTING BSSMAP-LE APDU IE ", expect_apdu);
9703 log("GOT BSSMAP-LE APDU IE ", plr.pdu.bssmap.perf_loc_req.bsslap_apdu);
9704 setverdict(fail, "BSSMAP-LE APDU IE is not as expected");
9705 mtc.stop;
9706 }
9707 var template BSSLAP_PDU expect_ta_layer3 := tr_BSSLAP_TA_Layer3(tr_BSSLAP_IE_TA(0));
9708 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(plr.pdu.bssmap.perf_loc_req.bsslap_apdu.data);
9709 if (not match(bsslap, expect_ta_layer3)) {
9710 log("EXPECTING BSSLAP TA Layer 3: ", expect_ta_layer3);
9711 log("GOT BSSLAP: ", bsslap);
9712 setverdict(fail, "BSSLAP is not as expected");
9713 mtc.stop;
9714 }
9715 /* OsmoBSC directly sent the TA as BSSLAP APDU in the BSSMAP-LE Perform Location Request to the SMLC. The SMLC
9716 * has no need to request the TA from the BSC and directly responds. */
9717 } else {
9718 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9719 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9720 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9721 }
9722
9723 /* SMLC got the TA from the BSC, now responds with geo information data. */
9724 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9725 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9726 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9727
9728 /* The LCS was using an active A-interface conn. It should still remain active after this. */
9729 f_mo_l3_transceive();
9730
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009731 f_perform_clear();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009732
9733 f_sleep(2.0);
9734 setverdict(pass);
9735}
9736
9737/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9738 * Request on Lb interface. Without the SMLC doing a BSSLAP TA Request. */
9739private function f_tc_lcs_loc_req_for_active_ms(charstring id) runs on MSC_ConnHdlr {
9740 f_lcs_loc_req_for_active_ms(false);
9741}
9742testcase TC_lcs_loc_req_for_active_ms() runs on test_CT {
9743 var MSC_ConnHdlr vc_conn;
9744 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9745
9746 f_init(1, true);
9747 f_sleep(1.0);
9748 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms), pars);
9749 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009750 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009751}
9752
9753/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9754 * Request on Lb interface. With the SMLC doing a BSSLAP TA Request. */
9755private function f_tc_lcs_loc_req_for_active_ms_ta_req(charstring id) runs on MSC_ConnHdlr {
9756 f_lcs_loc_req_for_active_ms(true);
9757}
9758testcase TC_lcs_loc_req_for_active_ms_ta_req() runs on test_CT {
9759 var MSC_ConnHdlr vc_conn;
9760 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9761
9762 f_init(1, true);
9763 f_sleep(1.0);
9764 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_ta_req), pars);
9765 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009766 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009767}
9768
9769/* Clear the A-interface conn only, without doing anything on Abis. Useful for LCS, for cases where there is only an A
9770 * conn without an active lchan. */
9771private function f_clear_A_conn() runs on MSC_ConnHdlr
9772{
9773 var BssmapCause cause := 0;
9774 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
9775 BSSAP.receive(tr_BSSMAP_ClearComplete);
9776 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
9777
9778 timer no_more_bssap := 5.0;
9779 no_more_bssap.start;
9780 alt {
9781 [] no_more_bssap.timeout { break; }
9782 [] BSSAP.receive(tr_BSSAP_BSSMAP) {
9783 setverdict(fail, "Expected no more BSSAP after Clear Complete");
9784 mtc.stop;
9785 }
9786 }
9787 setverdict(pass);
9788}
9789
9790/* Verify that the A-interface connection is still working, and then clear it, without doing anything on Abis. Useful
9791 * for LCS, for cases where there is only an A conn without an active lchan. */
9792private function f_verify_active_A_conn_and_clear() runs on MSC_ConnHdlr
9793{
9794 f_logp(BSCVTY, "f_verify_active_A_conn_and_clear: test A link, then clear");
9795
9796 /* When an lchan is active, we can send some L3 data from the BTS side and verify that it shows up on the other
9797 * side towards the MSC. When there is no lchan, this is not possible. To probe whether the A-interface
9798 * connection is still up, we need something that echos back on the A-interface. Another LCS request! */
9799 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9800 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9801 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?));
9802
9803 /* Right, the Perform Location Request showed up on Lb, now we can clear the A conn. */
9804 f_clear_A_conn();
9805 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
9806 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9807}
9808
9809/* With *no* active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9810 * Request on Lb interface. BSC will Page for the subscriber as soon as we (virtual SMLC) request the TA via BSSLAP.
9811 */
9812private function f_tc_lcs_loc_req_for_idle_ms(charstring id) runs on MSC_ConnHdlr {
9813 f_sleep(1.0);
9814
9815 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9816 f_bssap_le_register_imsi(g_pars.imsi, omit);
9817
9818 /* Register to receive the Paging Command */
9819 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9820 g_chan_nr := new_chan_nr;
9821 f_rslem_register(0, g_chan_nr);
9822
9823 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9824 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9825 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9826 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9827
9828 var PDU_BSSAP_LE plr;
9829 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9830
9831 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9832 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9833
9834 /* OsmoBSC needs to Page */
9835 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi)));
9836 f_logp(BSCVTY, "got Paging Command");
9837
9838 /* MS requests channel. Since the Paging was for LCS, the Paging Response does not trigger a Complete Layer 3 to
9839 * the MSC, and releases the lchan directly. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009840 f_perform_compl_l3(RSL, RSL_PROC, ts_PAG_RESP(valueof(ts_MI_IMSI_LV(g_pars.imsi))), do_clear := false, expect_bssmap_l3 := false);
9841 f_expect_lchan_rel(RSL, RSL_PROC);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009842
9843 /* From the Paging Response, the TA is now known to the BSC, and it responds to the SMLC. */
9844
9845 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9846
9847 /* SMLC got the TA from the BSC, now responds with geo information data. */
9848 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9849 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9850
9851 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9852
9853 /* The lchan is gone, the A-interface conn was created for the LCS only.
9854 * Still it is clearly the MSC's job to decide whether to tear down the conn or not. */
9855 f_verify_active_A_conn_and_clear();
9856
9857 f_sleep(2.0);
9858 setverdict(pass);
9859}
9860testcase TC_lcs_loc_req_for_idle_ms() runs on test_CT {
9861 var MSC_ConnHdlr vc_conn;
9862 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9863
9864 f_init(1, true);
9865 f_sleep(1.0);
9866
9867 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9868 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9869
9870 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms), pars);
9871 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009872 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009873}
9874
9875/* With no active lchan, start BSSMAP Perform Location Request on A interface, but omit IMSI; expect failure response.
9876 */
9877private function f_tc_lcs_loc_req_no_subscriber(charstring id) runs on MSC_ConnHdlr {
9878 f_sleep(1.0);
9879
9880 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9881 f_bssap_le_register_imsi(g_pars.imsi, omit);
9882
9883 /* provoke an abort by omitting both IMSI and IMEI */
9884 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9885 valueof(ts_BSSMAP_Perform_Location_Request(omit,
9886 ts_CellId_CGI('262'H, '42'H, 23, 42)))));
9887 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9888
9889 /* BSC tells MSC about failure */
9890 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9891 locationEstimate := omit, positioningData := omit,
9892 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_DATA_MISSING_IN_REQ)));
9893
9894 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9895 f_verify_active_A_conn_and_clear();
9896
9897 f_sleep(2.0);
9898 setverdict(pass);
9899}
9900testcase TC_lcs_loc_req_no_subscriber() runs on test_CT {
9901 var MSC_ConnHdlr vc_conn;
9902 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9903
9904 f_init(1, true);
9905 f_sleep(1.0);
9906
9907 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9908 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9909
9910 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_no_subscriber), pars);
9911 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009912 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009913}
9914
9915/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9916 * BSSMAP-LE Perform Location Response (before or after sending a BSSLAP TA Request) */
9917private function f_lcs_loc_req_for_active_ms_le_timeout(boolean do_ta) runs on MSC_ConnHdlr {
9918 f_sleep(1.0);
9919
9920 f_establish_fully(omit, omit);
9921 f_bssap_le_register_imsi(g_pars.imsi, omit);
9922
9923 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9924 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9925
9926 var PDU_BSSAP_LE plr;
9927 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9928
9929 if (do_ta) {
9930 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9931 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9932 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9933 }
9934
9935 /* SMLC fails to respond, BSC runs into timeout */
9936 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_SYSTEM_FAILURE));
9937 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9938
9939 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9940 locationEstimate := omit, positioningData := omit,
9941 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_SYSTEM_FAILURE)));
9942
9943 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9944 f_verify_active_A_conn_and_clear();
9945
9946 f_sleep(2.0);
9947 setverdict(pass);
9948}
9949
9950/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9951 * BSSMAP-LE Perform Location Response, without sending a BSSLAP TA Request. */
9952private function f_tc_lcs_loc_req_for_active_ms_le_timeout(charstring id) runs on MSC_ConnHdlr {
9953 f_lcs_loc_req_for_active_ms_le_timeout(false);
9954}
9955
9956testcase TC_lcs_loc_req_for_active_ms_le_timeout() runs on test_CT {
9957 var MSC_ConnHdlr vc_conn;
9958 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9959
9960 f_init(1, true);
9961 f_sleep(1.0);
9962 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout), pars);
9963 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009964 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009965}
9966
9967/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9968 * BSSMAP-LE Perform Location Response, after sending a BSSLAP TA Request. */
9969private function f_tc_lcs_loc_req_for_active_ms_le_timeout2(charstring id) runs on MSC_ConnHdlr {
9970 f_lcs_loc_req_for_active_ms_le_timeout(true);
9971}
9972
9973testcase TC_lcs_loc_req_for_active_ms_le_timeout2() runs on test_CT {
9974 var MSC_ConnHdlr vc_conn;
9975 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9976
9977 f_init(1, true);
9978 f_sleep(1.0);
9979 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout2), pars);
9980 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009981 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009982}
9983
9984/* With *no* active lchan, start a Perform Location Request, expecting that the MS will be Paged. */
9985private function f_tc_lcs_loc_req_for_idle_ms_no_pag_resp(charstring id) runs on MSC_ConnHdlr {
9986 f_sleep(1.0);
9987
9988 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9989 f_bssap_le_register_imsi(g_pars.imsi, omit);
9990
9991 /* Register to receive the Paging Command */
9992 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9993 g_chan_nr := new_chan_nr;
9994 f_rslem_register(0, g_chan_nr);
9995
9996 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9997 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9998 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9999 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
10000
10001 var PDU_BSSAP_LE plr;
10002 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
10003
10004 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
10005 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
10006
10007 /* OsmoBSC needs to Page */
10008 var PDU_BSSAP_LE rx_bsslap;
10009 alt {
10010 [] RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi))) {
10011 f_logp(BSCVTY, "got Paging Command");
10012 repeat;
10013 }
10014 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
10015 /* MS does not respond to Paging, TA Req runs into timeout. */
10016 f_match_bsslap(rx_bsslap, tr_BSSLAP_Abort(?));
10017 }
10018 }
10019
10020 /* SMLC responds with failure */
10021 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(omit, BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
10022 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
10023
10024 /* BSC tells MSC about failure */
10025 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
10026 locationEstimate := omit, positioningData := omit,
10027 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_REQUEST_ABORTED)));
10028
10029 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
10030 f_verify_active_A_conn_and_clear();
10031
10032 f_sleep(2.0);
10033 setverdict(pass);
10034}
10035testcase TC_lcs_loc_req_for_idle_ms_no_pag_resp() runs on test_CT {
10036 var MSC_ConnHdlr vc_conn;
10037 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10038
10039 f_init(1, true);
10040 f_sleep(1.0);
10041
10042 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
10043 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
10044
10045 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms_no_pag_resp), pars);
10046 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +010010047 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020010048}
10049
10050/* During an ongoing Location Request, the MS sends a CM Service Request. Expect the same A-conn to be re-used / taken
10051 * over. */
10052private function f_tc_cm_service_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
10053 f_sleep(1.0);
10054
10055 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
10056 f_bssap_le_register_imsi(g_pars.imsi, omit);
10057
10058 /* Register to receive the Paging Command */
10059 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
10060 g_chan_nr := new_chan_nr;
10061 f_rslem_register(0, g_chan_nr);
10062
10063 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
10064 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
10065 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
10066 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
10067
10068 var PDU_BSSAP_LE plr;
10069 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
10070
10071 /* As the A-interface conn was established for LCS, the MS coincidentally decides to issue a CM Service Request
10072 * and establish Layer 3. It should use the existing A-interface conn. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +020010073 f_perform_compl_l3(RSL, RSL_PROC, valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV(g_pars.imsi)))),
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020010074 do_clear := false, expect_bssmap_l3 := true);
10075
10076 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
10077 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
10078
10079 /* OsmoBSC already has an lchan, no need to Page, just returns the TA */
10080 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
10081
10082 /* SMLC got the TA from the BSC, now responds with geo information data. */
10083 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
10084 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
10085 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
10086
10087 /* The lchan should still exist, it was from a CM Service Request. */
10088 f_mo_l3_transceive();
10089
Neels Hofmeyr85bcd272021-07-22 19:14:48 +020010090 f_perform_clear();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020010091
10092 f_sleep(2.0);
10093 setverdict(pass);
10094}
10095testcase TC_cm_service_during_lcs_loc_req() runs on test_CT {
10096 var MSC_ConnHdlr vc_conn;
10097 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10098
10099 f_init(1, true);
10100 f_sleep(1.0);
10101
10102 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
10103 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
10104
10105 vc_conn := f_start_handler(refers(f_tc_cm_service_during_lcs_loc_req), pars);
10106 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +010010107 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020010108}
10109
10110/* During an ongoing Perform Location Request, do a Handover, an expect a BSSLAP Reset message from the BSC to indicate
10111 * the new lchan after handover. */
10112private function f_tc_ho_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
10113 f_sleep(1.0);
10114
10115 f_establish_fully(omit, omit);
10116 f_bssap_le_register_imsi(g_pars.imsi, omit);
10117
10118 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
10119 ts_CellId_CGI('262'H, '42'H, 23, 42))));
10120
10121 var PDU_BSSAP_LE plr;
10122 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
10123
10124 /* SMLC ponders the Location Request, in the meantime the BSC decides to handover */
10125 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
10126
10127 var HandoverState hs := {
10128 rr_ho_cmpl_seen := false,
10129 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +020010130 old_chan_nr := -,
10131 expect_target_tsc := BTS_TSC[1]
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020010132 };
10133 /* issue hand-over command on VTY */
10134 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
10135 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
10136 f_rslem_suspend(RSL1_PROC);
10137
10138 /* From the MGW perspective, a handover is is characterized by
10139 * performing one MDCX operation with the MGW. So we expect to see
10140 * one more MDCX during handover. */
10141 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
10142
10143 alt {
10144 [] as_handover(hs);
10145 }
10146
10147 var PDU_BSSAP_LE rx_bsslap;
10148
10149 interleave {
10150 /* Expect the BSC to inform the MSC about the handover */
10151 [] BSSAP.receive(tr_BSSMAP_HandoverPerformed);
10152
10153 /* Expect the BSC to inform the SMLC about the handover */
10154 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
10155 f_match_bsslap(rx_bsslap, tr_BSSLAP_Reset(BSSLAP_CAUSE_INTRA_BSS_HO));
10156 }
10157 }
10158
10159 /* SMLC now responds with geo information data. */
10160 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
10161 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
10162 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
10163
10164 /* lchan still active */
10165 f_mo_l3_transceive(RSL1);
10166
10167 /* MSC decides it is done now. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +020010168 f_perform_clear(RSL1, RSL1_PROC);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020010169
10170 f_sleep(2.0);
10171 setverdict(pass);
10172}
10173testcase TC_ho_during_lcs_loc_req() runs on test_CT {
10174 var MSC_ConnHdlr vc_conn;
10175 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10176
10177 f_init(2, true);
10178 f_sleep(1.0);
10179 vc_conn := f_start_handler(refers(f_tc_ho_during_lcs_loc_req), pars);
10180 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +010010181 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020010182}
10183
Neels Hofmeyra47a8c62022-04-07 00:31:19 +020010184private function f_tc_emerg_call_and_lcs_loc_req(charstring id) runs on MSC_ConnHdlr
10185{
10186 /* Make sure the CHAN RQD indicates an emergency call (0b101xxxxx). The difference is that osmo-bsc directly
10187 * assigns a TCH lchan and establishing voice for the emergency call will use Mode Modify, not reassignment to
10188 * another lchan. */
10189 g_pars.ra := 'b7'O;
10190 f_assignment_emerg_setup();
10191
10192 var PDU_BSSAP emerg_setup_data_ind_bssap;
10193 timer T := 3.0;
10194 T.start;
10195 alt {
10196 [] BSSAP.receive(tr_BSSAP_DTAP) -> value emerg_setup_data_ind_bssap {
10197 var PDU_ML3_MS_NW verify_emerg_setup;
10198 verify_emerg_setup := dec_PDU_ML3_MS_NW(emerg_setup_data_ind_bssap.pdu.dtap);
10199 if (not isbound(verify_emerg_setup.msgs.cc.emergencySetup)) {
10200 setverdict(fail, "no emergency setup");
10201 }
10202 }
10203 [] BSSAP.receive {
10204 setverdict(fail, "unexpected BSSAP message!");
10205 }
10206 [] T.timeout {
10207 setverdict(fail, "timeout waiting for EMERGENCY SETUP!");
10208 }
10209 }
10210
10211 /* Here would usually be a CC Call Proceeding from the MSC, but what does the BSC care about DTAP. */
10212
10213 /* Do a Location Request in-between the CC call setup */
10214 f_bssap_le_register_imsi(g_pars.imsi, omit);
10215 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
10216 ts_CellId_CGI('262'H, '42'H, 23, 42))));
10217 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?));
10218 /* SMLC got the TA from the BSC, now responds with geo information data. */
10219 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
10220 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
10221 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
10222
10223 /* Go on with voice call assignment */
10224 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
10225 var PDU_BSSAP ass_cmd := f_gen_ass_req();
10226
10227 /* Below speechOrDataIndicator and codecList are copied from an emergency call captured during tests.
10228 * They seem a bit weird (AMR-WB, and the order differ between speechId_DataIndicator and the codecList), but
10229 * seems a good idea to see how osmo-bsc reacts to this. */
10230 ass_cmd.pdu.bssmap.assignmentRequest.channelType := {
10231 elementIdentifier := '0B'O, /* overwritten */
10232 lengthIndicator := 0, /* overwritten */
10233 speechOrDataIndicator := '0001'B, /* speech */
10234 spare1_4 := '0000'B,
10235 channelRateAndType := ChRate_TCHForH_Fpref,
10236 speechId_DataIndicator := 'c2918105'O
10237 };
10238 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({
10239 ts_CodecHR, ts_CodecAMR_WB, ts_CodecEFR, ts_CodecFR}));
10240
10241 f_rslem_dchan_queue_enable();
10242
10243 var ExpectCriteria mgcpcrit := {
10244 connid := omit,
10245 endpoint := omit,
10246 transid := omit
10247 };
10248 f_create_mgcp_expect(mgcpcrit);
10249
10250 BSSAP.send(ass_cmd);
10251
10252 var AssignmentState st := valueof(ts_AssignmentStateInit);
10253 st.voice_call := true;
10254 st.is_assignment := false;
10255 alt {
10256 [] as_modify(st);
10257 [] as_Media();
10258 [st.modify_done] BSSAP.receive(exp_compl) {
10259 setverdict(pass);
10260 }
10261 }
10262
10263 /* Voice call carries on ... */
10264 f_sleep(2.0);
10265
10266 setverdict(pass);
10267 f_perform_clear();
10268}
10269
10270testcase TC_emerg_call_and_lcs_loc_req() runs on test_CT {
10271 var MSC_ConnHdlr vc_conn;
10272 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10273
10274 f_init(1, true);
10275 f_sleep(1.0);
10276 f_vty_allow_emerg_msc(true);
10277 f_vty_allow_emerg_bts(true, 0);
10278 vc_conn := f_start_handler(refers(f_tc_emerg_call_and_lcs_loc_req), pars);
10279 vc_conn.done;
10280 f_shutdown_helper();
10281}
10282
Neels Hofmeyrbf037052020-10-28 22:52:02 +000010283/* Attempt Complete Layer 3 without any MSC available (OS#4832) */
10284private function f_tc_no_msc(charstring id) runs on MSC_ConnHdlr {
10285 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
10286
10287 /* Also disable attach for the single connected MSC */
10288 f_vty_msc_allow_attach(BSCVTY, { false });
10289
10290 var octetstring l3_enc := enc_PDU_ML3_MS_NW(valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000100001'H)), '00F110'O) ));
10291 f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
10292
10293 /* No MSC is found, expecting a proper release on RSL */
10294 interleave {
10295 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
10296 f_logp(BSCVTY, "Got RSL RR Release");
10297 }
10298 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
10299 f_logp(BSCVTY, "Got RSL Deact SACCH");
10300 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +020010301 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyrbf037052020-10-28 22:52:02 +000010302 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
10303 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +020010304 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyrbf037052020-10-28 22:52:02 +000010305 }
10306 }
10307 setverdict(pass);
10308}
10309testcase TC_no_msc() runs on test_CT {
10310
10311 f_init(1, true);
10312 f_sleep(1.0);
10313 var MSC_ConnHdlr vc_conn;
10314 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10315
10316 f_ctrs_bsc_init(counternames_bsc_mscpool);
10317
10318 vc_conn := f_start_handler(refers(f_tc_no_msc), pars);
10319 vc_conn.done;
10320
10321 f_ctrs_bsc_add("mscpool:subscr:no_msc");
10322 f_ctrs_bsc_verify();
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +010010323 f_shutdown_helper();
Neels Hofmeyrbf037052020-10-28 22:52:02 +000010324}
10325
Harald Welte0ea2d5e2018-04-07 21:40:29 +020010326/* Dyn PDCH todo:
10327 * activate OSMO as TCH/F
10328 * activate OSMO as TCH/H
10329 * does the BSC-located PCU socket get the updated INFO?
10330 * what if no PCU is connected at the time?
10331 * is the info correct on delayed PCU (re)connect?
10332 */
Harald Welte94e0c342018-04-07 11:33:23 +020010333
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000010334private function f_TC_refuse_mode_modif_to_vamos(charstring id) runs on MSC_ConnHdlr {
10335 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
10336 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
10337
10338 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
10339 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
10340 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
10341 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
10342 g_pars.ass_codec_list.codecElements[0];
10343 if (isvalue(g_pars.expect_mr_s0_s7)) {
10344 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
10345 g_pars.expect_mr_s0_s7;
10346 }
10347 }
10348 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
10349 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
10350 log("expecting ASS COMPL like this: ", exp_compl);
10351
10352 f_establish_fully(ass_cmd, exp_compl);
10353
Neels Hofmeyr8746b0d2021-06-01 17:25:39 +020010354 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 modify vamos tsc 2 3");
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000010355
10356 var RSL_Message rsl;
10357
10358 timer T := 5.0;
10359 T.start;
10360 alt {
10361 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
10362 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
10363 log("Rx L3 from net: ", l3);
10364 if (ischosen(l3.msgs.rrm.channelModeModify)) {
10365 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
10366 mtc.stop;
10367 }
10368 }
10369 [] RSL.receive(tr_RSL_MODE_MODIFY_REQ(g_chan_nr, ?)) -> value rsl {
10370 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
10371 mtc.stop;
10372 }
10373 [] T.timeout {
10374 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related Mode Modify should happen. */
10375 setverdict(pass);
10376 }
10377 }
10378 T.stop;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010379
10380 f_perform_clear();
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000010381}
10382
10383/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel Mode Modify to VAMOS mode is refused by
10384 * osmo-bsc. */
10385testcase TC_refuse_mode_modif_to_vamos() runs on test_CT {
10386 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10387 var MSC_ConnHdlr vc_conn;
10388
10389 f_init(1, true);
10390 f_sleep(1.0);
10391
10392 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10393 vc_conn := f_start_handler(refers(f_TC_refuse_mode_modif_to_vamos), pars);
10394 vc_conn.done;
10395 f_shutdown_helper();
10396}
10397
10398/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel activation to VAMOS mode is refused by osmo-bsc.
10399 */
10400testcase TC_refuse_chan_act_to_vamos() runs on test_CT {
10401 f_init_vty();
10402
10403 f_init(1, false);
10404 f_sleep(1.0);
10405
10406 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 activate-vamos fr");
10407
10408 var ASP_RSL_Unitdata rx_rsl_ud;
10409 timer T := 5.0;
10410
10411 T.start;
10412 alt {
10413 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(?, IPAC_PROTO_RSL_TRX0)) -> value rx_rsl_ud {
10414 if (rx_rsl_ud.rsl.msg_type == RSL_MT_CHAN_ACTIV) {
10415 T.stop;
10416 setverdict(fail, "CHANnel ACTivate in VAMOS mode succeeded even though BTS does not support VAMOS");
10417 mtc.stop;
10418 }
10419 repeat;
10420 }
10421 [] T.timeout {
10422 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related CHANnel ACTivate should happen. */
10423 setverdict(pass);
10424 }
10425 }
10426}
10427
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010428private function f_TC_reassignment_codec(charstring id) runs on MSC_ConnHdlr {
10429 /* First fully set up a speech lchan */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010430 f_assignment_codec(id, do_perform_clear := false);
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010431
10432 /* Trigger re-assignment to another lchan */
10433 var AssignmentState assignment_st := valueof(ts_AssignmentStateInit);
10434
10435 /* Re-Assignment should tell the MGW endpoint the new lchan's RTP address and port, so expecting to see exactly
10436 * one MDCX on MGCP. */
10437 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].mdcx_seen_exp + 1;
10438
10439 /* The new lchan will see all-new IPAC_CRCX and IPAC_MDCX messages telling the BTS the same RTP address and port
10440 * as the old lchan used. */
10441 g_media.bts.ipa_crcx_seen := false;
10442 g_media.bts.ipa_mdcx_seen := false;
10443
10444 /* Send different BTS side RTP port number for the new lchan */
10445 g_media.bts.bts.port_nr := 4223;
10446
10447 f_rslem_register(0, valueof(ts_RslChanNr_Bm(2))); /* <-- FIXME: can we somehow infer the timeslot that will be used? */
10448
10449 /* Trigger re-assignment. */
10450 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot " & int2str(g_chan_nr.tn) & " sub-slot 0 assignment");
10451
10452 timer T := 5.0;
10453 T.start;
10454 alt {
10455 [] as_assignment(assignment_st);
10456 [] as_Media();
10457 [] T.timeout {
10458 break;
10459 }
10460 }
10461
10462 if (not assignment_st.assignment_done) {
10463 setverdict(fail, "Assignment did not complete");
10464 mtc.stop;
10465 }
10466
10467 f_check_mgcp_expectations()
10468 setverdict(pass);
10469
10470 f_sleep(2.0);
10471 log("show lchan summary: ", f_vty_transceive_ret(BSCVTY, "show lchan summary"));
10472
10473 /* Instruct BSC to clear channel */
10474 var BssmapCause cause := 0;
10475 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
10476 interleave {
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010477 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {}
10478 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +020010479 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010480 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +020010481 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010482 }
10483 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
10484 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
10485 }
10486 }
Neels Hofmeyr40a45d12021-09-23 22:57:12 +020010487 f_expect_dlcx_conns();
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010488
10489 f_sleep(0.5);
10490}
10491
10492testcase TC_reassignment_fr() runs on test_CT {
10493 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10494 var MSC_ConnHdlr vc_conn;
10495
10496 f_init(1, true);
10497 f_sleep(1.0);
10498
Neels Hofmeyrac432fa2021-11-02 16:45:56 +010010499 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010500
10501 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10502 vc_conn := f_start_handler(refers(f_TC_reassignment_codec), pars);
10503 vc_conn.done;
10504
10505 /* from f_establish_fully() */
10506 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
10507 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
10508 /* from re-assignment */
10509 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
10510 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
10511 f_ctrs_bsc_and_bts_verify();
10512 f_shutdown_helper();
10513}
10514
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010515const charstring REEST_LOST_CONNECTION := "REEST_LOST_CONNECTION";
10516const charstring REEST_CLEAR := "REEST_CLEAR";
10517const charstring REEST_CLEAR_DONE := "REEST_CLEAR_DONE";
10518
10519/* CM Re-Establishment, 3GPP TS 24.008 4.5.1.6.
10520 * The MS <-> BTS loses radio connection, MS shows up on second BTS and asks for CM Re-Establishment.
10521 * BSC should establish a separate A conn for the same MS, the original A conn is then cleared by
10522 * the MSC as the CM Re-Establishment is handled.
10523 *
10524 * MS bts0 bts1 bsc msc test-component
10525 * |<----->|<----------------->|<-0-->| _1 Establish channel on bts 0
10526 * | | _1 wait a bit, to settle down
10527 * |<-x x--| | _1 "lose connection"
10528 * | | REEST_LOST_CONNECTION
10529 * |----------------->|------->|--1-->| _2 new A-conn: Chan Rqd, Imm Ass, Compl L3 with CM Re-Establishment Req
10530 * | | REEST_CLEAR
10531 * | |<-0---| _1 Clear Command on first A-conn
10532 * | |--0-->| _1 Clear Complete
10533 * | |<----------------->| | _1 Release first channel
10534 * | | REEST_CLEAR_DONE
10535 * |<-----------------|<-------|<-1---| _2 Chan Activ, Assignment Command
10536 * |<-----------------|<-------|<-1---| _2 Clear Command, Release
10537 *
10538 */
10539private function f_tc_cm_reestablishment_1(charstring id) runs on MSC_ConnHdlr {
10540 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
10541 var PDU_BSSAP ass_cmd := f_gen_ass_req();
10542
10543 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10544 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10545
10546 f_establish_fully(ass_cmd, exp_compl);
10547
10548 /* The original channel loses connection, MS attemts CM Re-Establishment on another cell, see
10549 * f_tc_cm_reestablishment_2(). This established channel stays active until MSC sends a Clear Command. The time
10550 * when exactly that happens is determined by f_tc_cm_reestablishment_2(). */
10551 f_sleep(2.0);
10552 COORD.send(REEST_LOST_CONNECTION);
10553
10554 alt {
10555 [] COORD.receive(REEST_CLEAR);
10556 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
10557 setverdict(fail, "Unexpected channel release");
10558 mtc.stop;
10559 }
10560 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
10561 setverdict(fail, "Unexpected channel release");
10562 mtc.stop;
10563 }
10564 }
10565 f_perform_clear()
Neels Hofmeyr969abd02021-09-23 22:24:08 +020010566 f_create_mgcp_delete_ep(g_media.mgcp_ep);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010567 COORD.send(REEST_CLEAR_DONE);
10568}
10569
10570private function f_tc_cm_reestablishment_2(charstring id) runs on MSC_ConnHdlr {
10571 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
10572
10573 /* The MS lost the connection on the first channel, now establishes another one */
10574 COORD.receive(REEST_LOST_CONNECTION);
10575
10576 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
10577 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_REESTABL_REQ(mi));
10578 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
10579
10580 f_create_bssmap_exp(l3_enc);
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010581 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, rsl_pt := RSL1, rsl_proc_pt := RSL1_PROC);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010582 BSSAP.receive(tr_BSSMAP_ComplL3(l3_enc));
10583
10584 /* MSC got the CM Re-Establishment request and first off clears the previous conn. */
10585 COORD.send(REEST_CLEAR);
10586 COORD.receive(REEST_CLEAR_DONE);
10587
10588 f_sleep(2.0);
10589
10590 /* Answer the CM Re-Establishment with an Assignment Command. */
10591 var template PDU_BSSAP expect_assignment_compl := f_gen_exp_compl();
10592 var PDU_BSSAP ass_cmd := f_gen_ass_req();
10593 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10594 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10595
10596 var AssignmentState st := valueof(ts_AssignmentStateInit);
10597 st.voice_call := true;
10598 st.is_assignment := true;
10599
10600 var ExpectCriteria mgcpcrit := {
10601 connid := omit,
10602 endpoint := omit,
10603 transid := omit
10604 };
10605 f_create_mgcp_expect(mgcpcrit);
10606
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010607 f_rslem_dchan_queue_enable(RSL1_PROC);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010608
10609 BSSAP.send(ass_cmd);
10610
10611 var PDU_BSSAP bssap;
10612
10613 alt {
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010614 [] as_assignment(st, rsl_pt := RSL1, rsl_proc_pt := RSL1_PROC);
10615 [] as_Media_ipacc(RSL1, RSL2);
10616 [] as_Media_mgw();
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010617 [st.assignment_done] BSSAP.receive(expect_assignment_compl) {
10618 break;
10619 }
10620 }
10621
10622 f_sleep(3.0);
10623
10624 f_logp(BSCVTY, "f_tc_cm_reestablishment_2 clearing");
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010625 f_perform_clear(RSL1, RSL1_PROC);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010626}
10627
10628testcase TC_cm_reestablishment() runs on test_CT {
10629 var TestHdlrParams pars1 := f_gen_test_hdlr_pars();
10630 var MSC_ConnHdlr vc_conn1;
10631
10632 var TestHdlrParams pars2 := f_gen_test_hdlr_pars();
10633 var MSC_ConnHdlr vc_conn2;
10634 pars2.imsi := pars1.imsi;
10635 pars2.media_nr := 2;
Neels Hofmeyrbf720202021-10-02 12:58:24 +020010636 pars2.expect_tsc := BTS_TSC[1];
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010637
10638 f_init(2, true, guard_timeout := 40.0);
10639 f_sleep(1.0);
10640
10641 vc_conn1 := f_start_handler_create(pars1);
10642 vc_conn2 := f_start_handler_create(pars2);
10643 connect(vc_conn1:COORD, vc_conn2:COORD);
10644 f_start_handler_run(vc_conn1, refers(f_tc_cm_reestablishment_1), pars1);
10645 f_start_handler_run(vc_conn2, refers(f_tc_cm_reestablishment_2), pars2);
10646 vc_conn1.done;
10647 vc_conn2.done;
10648
10649 f_shutdown_helper();
10650}
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000010651
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010652function f_exp_ipa_rx_nonfatal(integer bts_nr, template (present) RSL_Message t_rx, float t_secs := 2.0,
10653 IpaStreamId sid := IPAC_PROTO_RSL_TRX0, boolean ignore_other_rx := true)
10654runs on test_CT return template (omit) RSL_Message {
10655 var ASP_RSL_Unitdata rx_rsl_ud;
10656 timer T := t_secs;
10657
10658 T.start;
10659 alt {
10660 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
10661 T.stop;
10662 }
10663 [ignore_other_rx] IPA_RSL[bts_nr].receive { repeat; }
10664 [not ignore_other_rx] IPA_RSL[bts_nr].receive {
10665 log("f_exp_ipa_rx_nonfatal(): Got different message than ", t_rx);
10666 T.stop;
10667 return omit;
10668 }
10669 [] T.timeout {
10670 return omit;
10671 }
10672 }
10673 return rx_rsl_ud.rsl;
10674}
10675
10676private function f_vty_set_imm_ass(TELNETasp_PT pt, BtsNr bts_nr := 0, charstring imm_ass_setting := "post-chan-ack") {
10677 f_vty_enter_cfg_bts(pt, bts_nr);
10678 f_vty_transceive(pt, "immediate-assignment " & imm_ass_setting);
10679 f_vty_transceive(pt, "exit");
10680 f_vty_transceive(pt, "exit");
10681 f_vty_transceive(pt, "exit");
10682}
10683
10684private function f_verify_imm_ass(RSL_Message imm_ass, template uint8_t ra := ?, template GsmFrameNumber fn := ?,
Vadim Yanitskiy35c9a332022-03-16 20:26:35 +030010685 template (present) RslChannelNr chan_nr := ?,
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010686 template (present) uint12_t arfcn := ?,
10687 template (present) uint3_t tsc := ?)
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010688{
10689 var RSL_IE_Body full_imm_ass_info;
10690 if (not f_rsl_find_ie(imm_ass, RSL_IE_FULL_IMM_ASS_INFO, full_imm_ass_info)) {
10691 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
10692 mtc.stop;
10693 }
10694
10695 var GsmRrMessage rr_imm_ass := dec_GsmRrMessage(full_imm_ass_info.full_imm_ass_info.payload);
10696 var template GsmRrMessage expect_imm_ass := tr_IMM_ASS(ra := ra,
10697 fn := fn,
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010698 ch_desc := tr_ChanDescH0(chan_nr, arfcn, tsc),
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010699 page_mode := ?);
10700 if (not match(rr_imm_ass, expect_imm_ass)) {
10701 log("Error: expected ", expect_imm_ass, " got ", rr_imm_ass);
10702 setverdict(fail, "Failed to match Immediate Assignment");
10703 mtc.stop;
10704 }
10705}
10706
10707testcase TC_imm_ass_post_chan_ack() runs on test_CT {
10708 var RSL_Message chan_act;
10709 var RSL_Message imm_ass;
10710
10711 f_init(1, false);
10712 f_sleep(1.0);
10713
10714 /* (should be the default anyway, just to make things clear) */
10715 f_vty_set_imm_ass(BSCVTY, 0, "post-chan-ack");
10716
10717 /* RA containing reason=LU */
10718 var GsmFrameNumber fn := 2342;
10719 var uint8_t ra := 2;
10720 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10721
10722 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10723
10724 /* First send the Chan Act ACK */
10725 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010726 var DchanTuple dt;
10727 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010728 var RSL_IE_Body chan_ident_ie;
10729 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10730 setverdict(fail, "RSL Channel Identification IE is absent");
10731 mtc.stop;
10732 }
10733
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010734 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn + 10));
10735
10736 /* Then expect the Immediate Assignment, after we ACKed the chan act */
10737 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10738
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010739 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10740 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010741
10742 /* Check that the lchan is working */
10743 var octetstring l3 := '00010203040506'O;
10744 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10745
10746 var BSSAP_N_CONNECT_ind rx_c_ind;
10747 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010748 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010749 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10750
10751 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010752 f_perform_clear_test_ct(dt);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010753 f_shutdown_helper();
10754}
10755
10756testcase TC_imm_ass_pre_chan_ack() runs on test_CT {
10757 var RSL_Message chan_act;
10758 var RSL_Message imm_ass;
10759
10760 f_init(1, false);
10761 f_sleep(1.0);
10762
10763 f_vty_set_imm_ass(BSCVTY, 0, "pre-chan-ack");
10764
10765 /* RA containing reason=LU */
10766 var GsmFrameNumber fn := 2342;
10767 var uint8_t ra := 2;
10768 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10769
10770 /* (set bts 0 cfg back to default) */
10771 f_vty_set_imm_ass(BSCVTY);
10772
10773 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10774 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010775 var DchanTuple dt;
10776 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010777 var RSL_IE_Body chan_ident_ie;
10778 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10779 setverdict(fail, "RSL Channel Identification IE is absent");
10780 mtc.stop;
10781 }
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010782
10783 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10784 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010785 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10786 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010787
10788 /* Only now send the Chan Act ACK */
10789 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10790
10791 /* Check that the lchan is working */
10792 var octetstring l3 := '00010203040506'O;
10793 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10794
10795 var BSSAP_N_CONNECT_ind rx_c_ind;
10796 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010797 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010798 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10799
10800 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010801 f_perform_clear_test_ct(dt);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010802 f_shutdown_helper();
10803}
10804
Neels Hofmeyr23158742021-09-07 19:08:07 +020010805testcase TC_imm_ass_pre_ts_ack() runs on test_CT {
10806 var RSL_Message chan_act;
10807 var RSL_Message imm_ass;
10808
10809 f_init(1, false);
10810 f_sleep(1.0);
10811
10812 f_vty_set_imm_ass(BSCVTY, 0, "pre-ts-ack");
10813
10814 /* RA containing reason=LU */
10815 var GsmFrameNumber fn := 2342;
10816 var uint8_t ra := 2;
10817 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10818
10819 /* (set bts 0 cfg back to default) */
10820 f_vty_set_imm_ass(BSCVTY);
10821
10822 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10823 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010824 var DchanTuple dt;
10825 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyr23158742021-09-07 19:08:07 +020010826 var RSL_IE_Body chan_ident_ie;
10827 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10828 setverdict(fail, "RSL Channel Identification IE is absent");
10829 mtc.stop;
10830 }
10831
10832 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10833 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10834 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10835 chan_ident_ie.chan_ident.ch_desc.v.tsc);
10836
10837 /* Only now send the Chan Act ACK */
10838 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10839
10840 /* Check that the lchan is working */
10841 var octetstring l3 := '00010203040506'O;
10842 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10843
10844 var BSSAP_N_CONNECT_ind rx_c_ind;
10845 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010846 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyr23158742021-09-07 19:08:07 +020010847 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10848
10849 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010850 f_perform_clear_test_ct(dt);
Neels Hofmeyr23158742021-09-07 19:08:07 +020010851 f_shutdown_helper();
10852}
10853
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010854testcase TC_imm_ass_pre_chan_ack_dyn_ts() runs on test_CT {
10855 /* change Timeslot 6 before f_init() starts RSL */
10856 f_init_vty();
10857 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
10858 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10859
10860 f_init(1, false);
10861 f_sleep(1.0);
10862
10863 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
10864 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010865 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010866 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2323));
10867
10868 /* clean up timeslot 6 config, will only take effect when the OML drops the next time */
10869 f_ts_set_chcomb(0, 0, 6, "PDCH");
10870
10871 /* block all static timeslots so that the dyn TS will be used */
10872 f_disable_all_tch_f();
10873 f_disable_all_tch_h();
10874 f_disable_all_sdcch();
10875
10876 var RSL_Message chan_act;
10877 var RSL_Message imm_ass;
10878
10879 f_init(1, false);
10880 f_sleep(1.0);
10881
10882 f_vty_set_imm_ass(BSCVTY, 0, "pre-chan-ack");
10883
10884 /* RA containing reason=LU */
10885 var GsmFrameNumber fn := 2342;
10886 var uint8_t ra := 2;
10887 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10888
10889 /* (set bts 0 cfg back to default) */
10890 f_vty_set_imm_ass(BSCVTY);
10891
10892 /* Expect the dyn TS to deactivate PDCH first */
10893 f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
10894 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
10895
10896 /* Now activation as SDCCH8 */
10897 chan_nr := valueof(t_RslChanNr_SDCCH8(tn := 6, sub_slot := 0));
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010898 var DchanTuple dt;
10899 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010900
10901 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010902 var RSL_IE_Body chan_ident_ie;
10903 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10904 setverdict(fail, "RSL Channel Identification IE is absent");
10905 mtc.stop;
10906 }
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010907
10908 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10909 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010910 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10911 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010912
10913 /* Only now send the Chan Act ACK */
10914 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10915
10916 /* Check that the lchan is working */
10917 var octetstring l3 := '00010203040506'O;
10918 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10919
10920 var BSSAP_N_CONNECT_ind rx_c_ind;
10921 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010922 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010923 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10924
10925 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010926 f_perform_clear_test_ct(dt);
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010927 f_shutdown_helper();
10928}
10929
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010930testcase TC_imm_ass_pre_ts_ack_dyn_ts() runs on test_CT {
10931 /* change Timeslot 6 before f_init() starts RSL */
10932 f_init_vty();
10933 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
10934 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10935
10936 f_init(1, false);
10937 f_sleep(1.0);
10938
10939 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
10940 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010941 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010942 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2323));
10943
10944 /* clean up timeslot 6 config, will only take effect when the OML drops the next time */
10945 f_ts_set_chcomb(0, 0, 6, "PDCH");
10946
10947 /* block all static timeslots so that the dyn TS will be used */
10948 f_disable_all_tch_f();
10949 f_disable_all_tch_h();
10950 f_disable_all_sdcch();
10951
10952 var RSL_Message chan_act;
10953 var RSL_Message imm_ass;
10954
10955 f_init(1, false);
10956 f_sleep(1.0);
10957
10958 f_vty_set_imm_ass(BSCVTY, 0, "pre-ts-ack");
10959
10960 /* RA containing reason=LU */
10961 var GsmFrameNumber fn := 2342;
10962 var uint8_t ra := 2;
10963 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10964
10965 /* (set bts 0 cfg back to default) */
10966 f_vty_set_imm_ass(BSCVTY);
10967
10968 /* Expect the dyn TS to deactivate PDCH first */
10969 f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
10970
10971 /* And already the Immediate Assignment even before the PDCH Deact ACK */
10972 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10973
10974 /* continue the Osmo style PDCH Deact (usual chan rel) */
10975 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
10976
10977 /* Now activation as SDCCH8 */
10978 chan_nr := valueof(t_RslChanNr_SDCCH8(tn := 6, sub_slot := 0));
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010979 var DchanTuple dt;
10980 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010981
10982 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010983 var RSL_IE_Body chan_ident_ie;
10984 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10985 setverdict(fail, "RSL Channel Identification IE is absent");
10986 mtc.stop;
10987 }
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010988 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10989
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010990 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10991 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010992
10993 /* Check that the lchan is working */
10994 var octetstring l3 := '00010203040506'O;
10995 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10996
10997 var BSSAP_N_CONNECT_ind rx_c_ind;
10998 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010999 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020011000 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
11001
11002 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011003 f_perform_clear_test_ct(dt);
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020011004 f_shutdown_helper();
11005}
11006
Neels Hofmeyr5d7d13f2021-09-07 14:44:36 +020011007/* GET and SET the bts.N.trx.M.rf_locked CTRL variable */
11008testcase TC_ctrl_trx_rf_locked() runs on test_CT {
11009 var MSC_ConnHdlr vc_conn;
11010
11011 f_init(nr_bts := 2, handler_mode := true, nr_msc := 1);
11012 f_sleep(1.0);
11013
11014 /* BTS 0, 1, 2 are OML unlocked, only BTS 0, 1 are actually connected to RSL. */
11015 f_ctrl_get_exp(IPA_CTRL, "rf_states",
11016 "0,0,operational,unlocked,on,rsl-up;" &
11017 "1,0,operational,unlocked,on,rsl-up;" &
11018 "2,0,operational,unlocked,on,rsl-down;" &
11019 "3,0,inoperational,locked,on,rsl-down;");
11020
11021 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: lock BTS 1 TRX 0");
11022 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "1");
11023 /* give it a moment to settle the FSM status */
11024 f_sleep(1.0);
11025
11026 /* Now BTS 1 TRX 0 should reflect "locked". Note the RF policy stays "on", because this is still handled
11027 * globally in osmo-bsc. Probably after sending "rf_locked 1" for a TRX, that TRX should reflect an RF policy
11028 * of "off"? But that's for a future patch if at all. */
11029 f_ctrl_get_exp(IPA_CTRL, "rf_states",
11030 "0,0,operational,unlocked,on,rsl-up;" &
11031 "1,0,operational,locked,on,rsl-up;" &
11032 "2,0,operational,unlocked,on,rsl-down;" &
11033 "3,0,inoperational,locked,on,rsl-down;");
11034
11035 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: lock the already locked TRX, nothing should change");
11036 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "1");
11037 f_sleep(1.0);
11038 f_ctrl_get_exp(IPA_CTRL, "rf_states",
11039 "0,0,operational,unlocked,on,rsl-up;" &
11040 "1,0,operational,locked,on,rsl-up;" &
11041 "2,0,operational,unlocked,on,rsl-down;" &
11042 "3,0,inoperational,locked,on,rsl-down;");
11043
11044 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock BTS 1 TRX 0");
11045 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "0");
11046 f_sleep(1.0);
11047 f_ctrl_get_exp(IPA_CTRL, "rf_states",
11048 "0,0,operational,unlocked,on,rsl-up;" &
11049 "1,0,operational,unlocked,on,rsl-up;" &
11050 "2,0,operational,unlocked,on,rsl-down;" &
11051 "3,0,inoperational,locked,on,rsl-down;");
11052
11053 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock an already unlocked TRX, nothing should change");
11054 f_ctrl_set(IPA_CTRL, "bts.0.trx.0.rf_locked", "0");
11055 f_sleep(1.0);
11056 f_ctrl_get_exp(IPA_CTRL, "rf_states",
11057 "0,0,operational,unlocked,on,rsl-up;" &
11058 "1,0,operational,unlocked,on,rsl-up;" &
11059 "2,0,operational,unlocked,on,rsl-down;" &
11060 "3,0,inoperational,locked,on,rsl-down;");
11061
11062 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock an inoperational TRX");
11063 f_ctrl_set(IPA_CTRL, "bts.3.trx.0.rf_locked", "0");
11064 f_sleep(1.0);
11065 f_ctrl_get_exp(IPA_CTRL, "rf_states",
11066 "0,0,operational,unlocked,on,rsl-up;" &
11067 "1,0,operational,unlocked,on,rsl-up;" &
11068 "2,0,operational,unlocked,on,rsl-down;" &
11069 "3,0,inoperational,locked,on,rsl-down;");
11070
11071 f_shutdown_helper();
11072}
11073
Neels Hofmeyrb7581872021-11-07 14:02:49 +010011074const CounterNameVals counternames_cm_serv_rej := {
11075 { "cm_serv_rej", 0 },
11076 { "cm_serv_rej:imsi_unknown_in_hlr", 0 },
11077 { "cm_serv_rej:illegal_ms", 0 },
11078 { "cm_serv_rej:imsi_unknown_in_vlr", 0 },
11079 { "cm_serv_rej:imei_not_accepted", 0 },
11080 { "cm_serv_rej:illegal_me", 0 },
11081 { "cm_serv_rej:plmn_not_allowed", 0 },
11082 { "cm_serv_rej:loc_not_allowed", 0 },
11083 { "cm_serv_rej:roaming_not_allowed", 0 },
11084 { "cm_serv_rej:network_failure", 0 },
11085 { "cm_serv_rej:synch_failure", 0 },
11086 { "cm_serv_rej:congestion", 0 },
11087 { "cm_serv_rej:srv_opt_not_supported", 0 },
11088 { "cm_serv_rej:rqd_srv_opt_not_supported", 0 },
11089 { "cm_serv_rej:srv_opt_tmp_out_of_order", 0 },
11090 { "cm_serv_rej:call_can_not_be_identified", 0 },
11091 { "cm_serv_rej:incorrect_message", 0 },
11092 { "cm_serv_rej:invalid_mandantory_inf", 0 },
11093 { "cm_serv_rej:msg_type_not_implemented", 0 },
11094 { "cm_serv_rej:msg_type_not_compatible", 0 },
11095 { "cm_serv_rej:inf_eleme_not_implemented", 0 },
11096 { "cm_serv_rej:condtional_ie_error", 0 },
11097 { "cm_serv_rej:msg_not_compatible", 0 },
11098 { "cm_serv_rej:protocol_error", 0 },
11099 { "cm_serv_rej:retry_in_new_cell", 0 }
11100};
11101
11102private function f_TC_cm_serv_rej(charstring id) runs on MSC_ConnHdlr
11103{
11104 f_create_chan_and_exp();
Vadim Yanitskiya7fc5a62021-12-04 20:10:08 +030011105 /* we should now have a COMPL_L3 at the MSC */
Neels Hofmeyrb7581872021-11-07 14:02:49 +010011106 BSSAP.send(ts_PDU_DTAP_MT(ts_CM_SERV_REJ('02'O), '00'O));
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011107 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_CM_SERV_REJ));
11108 f_perform_clear();
Neels Hofmeyr87a65612021-11-16 15:56:45 +010011109 f_sleep(1.0);
Neels Hofmeyrb7581872021-11-07 14:02:49 +010011110}
11111testcase TC_cm_serv_rej() runs on test_CT {
11112 var TestHdlrParams pars := f_gen_test_hdlr_pars();
11113 var MSC_ConnHdlr vc_conn;
11114
11115 f_init(1, true);
11116 f_sleep(1.0);
11117
11118 f_ctrs_bts_init(1, counternames_cm_serv_rej);
11119
11120 vc_conn := f_start_handler(refers(f_TC_cm_serv_rej), pars);
11121 vc_conn.done;
11122
11123 f_ctrs_bts_add(0, "cm_serv_rej", 1);
11124 f_ctrs_bts_add(0, "cm_serv_rej:imsi_unknown_in_hlr", 1);
11125 f_ctrs_bts_verify();
11126
Neels Hofmeyr87a65612021-11-16 15:56:45 +010011127 f_sleep(1.0);
Neels Hofmeyrb7581872021-11-07 14:02:49 +010011128 f_shutdown_helper();
11129}
11130
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011131/* Reproduce a segfault happening when the SDCCH (primary) lchan is lost in-between a TCH Channel Activ and its Channel
11132 * Activ Ack (SYS#5627). */
11133private function f_TC_lost_sdcch_during_assignment(charstring id) runs on MSC_ConnHdlr {
11134 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Vadim Yanitskiyf0310e32021-10-26 00:30:59 +030011135
11136 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
11137 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011138
11139 var BSSMAP_FIELD_CodecType codecType;
11140 codecType := valueof(ass_cmd.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType);
11141
11142 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
11143
11144 /* First establish a signalling lchan */
11145 f_create_chan_and_exp();
11146 f_rslem_dchan_queue_enable();
11147
11148 /* we should now have a COMPL_L3 at the MSC */
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011149
11150 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
11151 activate(as_Media_mgw());
11152
11153 var RslChannelNr chan_nr := { u := { ch0 := RSL_CHAN_NR_Bm_ACCH }, tn := 1 };
11154 f_rslem_register(0, chan_nr);
11155
11156 f_rslem_set_auto_chan_act_ack(RSL_PROC, false);
11157 BSSAP.send(ass_cmd);
11158
11159
11160 /* Wait for the Channel Activ for the TCH channel */
11161 var ASP_RSL_Unitdata rx_rsl_ud;
11162 RSL.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV), sid := ?)) -> value rx_rsl_ud;
11163
11164 /* make the original SDCCH disappear */
11165 RSL.send(ts_RSL_REL_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
11166
11167 /* and ACK the TCH channel activation. This caused a segfault up to OsmoBSC 1.7.0 (SYS#5627) */
11168 RSL.send(ts_ASP_RSL_UD(ts_RSL_CHAN_ACT_ACK(chan_nr, 23), rx_rsl_ud.streamId));
11169
11170 interleave {
11171 [] BSSAP.receive(tr_BSSMAP_AssignmentFail);
11172 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
11173 }
11174
11175 BSSAP.send(ts_BSSMAP_ClearCommand(0));
11176 BSSAP.receive(tr_BSSMAP_ClearComplete);
11177 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
11178
11179 var MgcpCommand mgcp;
11180 MGCP.receive(tr_DLCX()) -> value mgcp {
11181 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
11182 };
11183
11184 f_sleep(0.5);
11185}
11186testcase TC_lost_sdcch_during_assignment() runs on test_CT {
11187 var TestHdlrParams pars := f_gen_test_hdlr_pars();
11188 var MSC_ConnHdlr vc_conn;
11189
11190 f_init(1, true);
11191 f_sleep(1.0);
11192
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011193 vc_conn := f_start_handler(refers(f_TC_lost_sdcch_during_assignment), pars);
11194 vc_conn.done;
11195
11196 f_shutdown_helper();
11197}
11198
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011199const CounterNameVals counternames_bsc_bts_all_available_allocated := {
11200 { "all_allocated:sdcch", 0 },
11201 { "all_allocated:static_sdcch", 0 },
11202 { "all_allocated:tch", 0 },
11203 { "all_allocated:static_tch", 0 }
11204}
11205
11206private function f_all_allocated_expect_counter_change(charstring_list expect_changed) runs on test_CT
11207{
11208 /* Make sure counters settle first */
11209 f_sleep(1.0);
11210
11211 /* Take a baseline of counters */
11212 f_ctrs_bsc_and_bts_init(1, counternames_bsc_bts_all_available_allocated);
11213
11214 /* Elapse some time so that we see changes in counters, hopefully where expected */
11215 f_sleep(2.0);
11216
11217 /* Get new counters */
11218 var charstring_list all_changed := {};
11219 all_changed := all_changed & f_counter_name_vals_get_changed_n(IPA_CTRL, "bsc", g_ctr_bsc);
11220 all_changed := all_changed & f_counter_name_vals_get_changed_n(IPA_CTRL, "bts", g_ctr_bts);
11221
11222 /* Compare with expectations */
11223 var charstring_list all_expect_changed := {};
11224 for (var integer i := 0; i < lengthof(expect_changed); i := i + 1) {
11225 all_expect_changed := all_expect_changed & { "bsc.0." & expect_changed[i], "bts.0." & expect_changed[i] };
11226 }
11227 f_counter_name_vals_expect_changed_list(all_changed, all_expect_changed);
11228}
11229
11230testcase TC_ratectr_all_available_allocated() runs on test_CT {
11231 var ASP_RSL_Unitdata rsl_ud;
11232 var integer i;
11233 var integer chreq_total, chreq_nochan;
11234
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011235 f_init(1, guard_timeout := 60.0);
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011236 f_sleep(1.0);
11237
11238 /* Exhaust all dedicated SDCCH lchans.
11239 /* GSM 44.018 Table 9.1.8.2:
11240 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
11241 */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011242 var DchanTuples chan_cleanup := {};
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011243 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011244 chan_cleanup := chan_cleanup & { f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011245 }
11246
11247 /* Since only bts 0 is connected, expecting all_allocated to become true for both bts 0 and the "global" bsc
11248 * level.
11249 * All SDCCH are now occupied. */
11250 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch"});
11251
11252 /* Also fill up all remaining (TCH) channels */
11253 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011254 chan_cleanup := chan_cleanup & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011255 }
11256
11257 /* All TCH are now also occupied */
11258 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch",
11259 "all_allocated:tch", "all_allocated:static_tch"});
11260
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011261 /* Clean up SDCCH lchans */
11262 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
11263 f_perform_clear_test_ct(chan_cleanup[i]);
11264 }
11265
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011266 f_shutdown_helper();
11267}
11268
11269testcase TC_ratectr_all_available_allocated_dyn() runs on test_CT {
11270 var ASP_RSL_Unitdata rsl_ud;
11271 var integer i;
11272 var integer chreq_total, chreq_nochan;
11273
11274 f_init_vty();
11275 f_ts_set_chcomb(0, 0, 2, "TCH/F_TCH/H_PDCH");
11276 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
11277 /* Now we have 3 TCH/F, 1 OSMO_DYN, 1 TCH/H */
11278
11279 f_init(1, guard_timeout := 60.0);
11280 f_sleep(1.0);
11281
11282 /* The dyn TS wants to activate PDCH mode, ACK that. */
11283 var RslChannelNr chan_nr;
11284 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060011285 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011286 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
11287
11288 /* Exhaust all dedicated SDCCH lchans.
11289 /* GSM 44.018 Table 9.1.8.2:
11290 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
11291 */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011292 var DchanTuples chan_cleanup := {};
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011293 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011294 chan_cleanup := chan_cleanup & { f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011295 }
11296
11297 /* The static SDCCH should now be occupied, while still 3x8 dynamic SDCCH potentially remain. So only
11298 * all_allocated:static_sdcch is counted, all_allocated:sdcch remains zero. */
11299 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch"});
11300
11301 /* Request more SDCCH, hence convert the first dyn TS to SDCCH8.
11302 * Will release them later, so remember all the DchanTuples. */
11303 var DchanTuples dyn_sddch := {};
11304 dyn_sddch := dyn_sddch & { f_est_dchan_dyn('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
11305
11306 /* Also occupy the seven other SDCCH of the dyn TS */
11307 for (i := 0; i < 7; i := i+1) {
11308 dyn_sddch := dyn_sddch & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
11309 }
11310
11311 /* Now all dynamic SDCCH are also occupied, so for the first time all_allocated:sdcch will trigger... */
11312 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch"});
11313
11314 /* occupy the remaining TCH, three TCH/F and two TCH/H lchans */
11315 for (i := 0; i < 5; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011316 chan_cleanup := chan_cleanup & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011317 }
11318
11319 /* All TCH lchans are now also occupied, both static and dynamic */
11320 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch",
11321 "all_allocated:tch", "all_allocated:static_tch"});
11322
11323 /* Starting to release the dyn TS: as soon as the first SDCCH gets released, all_allocated:sdcch stops
11324 * incrementing. */
11325 var BssmapCause cause := 0;
11326 var DchanTuple dt := dyn_sddch[0];
11327 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
11328 f_exp_chan_rel_and_clear(dt, 0);
11329
11330 /* one dyn TS SDCCH is free again, so only the static_sdcch should increment. For tch, both static and dynamic
11331 * count as occupied, so those still both increment. */
11332 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch",
11333 "all_allocated:tch", "all_allocated:static_tch"});
11334
11335 /* Release the remaining SDCCH of the dyn TS, so it becomes available as TCH again */
11336 for (i := 1; i < lengthof(dyn_sddch); i := i+1) {
11337 dt := dyn_sddch[i];
11338 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
11339 f_exp_chan_rel_and_clear(dt, 0);
11340 }
11341
11342 /* All SDCCH on the dyn TS are released, the dyn TS wants to activate PDCH again */
11343 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060011344 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011345 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
11346
11347 /* Now all channels are occupied except the dyn TS, so expecting only the static counters to increment */
11348 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch", "all_allocated:static_tch"});
11349
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011350 /* Clean up SDCCH lchans */
11351 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
11352 f_perform_clear_test_ct(chan_cleanup[i]);
11353 }
11354
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011355 /* clean up config */
11356 f_ts_reset_chcomb(0);
11357
11358 f_shutdown_helper();
11359}
11360
Harald Welte28d943e2017-11-25 15:00:50 +010011361control {
Harald Welte898113b2018-01-31 18:32:21 +010011362 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +010011363 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +010011364 execute( TC_ctrl_msc0_connection_status() );
Neels Hofmeyrf65ce872021-09-23 18:40:10 +020011365 /* In SCCPlite tests, only one MSC is configured. These tests assume that three MSCs are configured, so only run
11366 * these in the AoIP test suite. */
11367 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11368 execute( TC_stat_num_msc_connected_1() );
11369 execute( TC_stat_num_msc_connected_2() );
11370 execute( TC_stat_num_msc_connected_3() );
11371 }
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +020011372 execute( TC_stat_num_bts_connected_1() );
11373 execute( TC_stat_num_bts_connected_2() );
11374 execute( TC_stat_num_bts_connected_3() );
Harald Welte96c94412017-12-09 03:12:45 +010011375 execute( TC_ctrl() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +020011376 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER) {
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +020011377 execute( TC_ctrl_location() );
11378 }
Harald Welte898113b2018-01-31 18:32:21 +010011379
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020011380 execute( TC_si_default() );
Neels Hofmeyr66aeba42020-07-06 02:21:21 +020011381 execute( TC_si2quater_2_earfcns() );
11382 execute( TC_si2quater_3_earfcns() );
11383 execute( TC_si2quater_4_earfcns() );
11384 execute( TC_si2quater_5_earfcns() );
11385 execute( TC_si2quater_6_earfcns() );
Neels Hofmeyrad132f22020-07-08 02:20:16 +020011386 execute( TC_si2quater_12_earfcns() );
11387 execute( TC_si2quater_23_earfcns() );
11388 execute( TC_si2quater_32_earfcns() );
11389 execute( TC_si2quater_33_earfcns() );
11390 execute( TC_si2quater_42_earfcns() );
11391 execute( TC_si2quater_48_earfcns() );
11392 execute( TC_si2quater_49_earfcns() );
Pau Espin Pedrol85a84432020-07-20 18:45:03 +020011393 execute( TC_si_acc_rotate() );
Alexander Couzens4ad3a352020-09-10 22:29:12 +020011394 execute( TC_si_acc_ramp_rotate() );
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020011395
Harald Welte898113b2018-01-31 18:32:21 +010011396 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +010011397 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +010011398 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +010011399 execute( TC_chan_act_ack_noest() );
Philipp Maier9c60a622020-07-09 15:08:46 +020011400 execute( TC_chan_act_ack_noest_emerg() );
Philipp Maier606f07d2020-08-12 17:21:58 +020011401 execute( TC_chan_rqd_emerg_deny() );
Harald Welteae026692017-12-09 01:03:01 +010011402 execute( TC_chan_act_ack_est_ind_noreply() );
11403 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +010011404 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +010011405 execute( TC_chan_exhaustion() );
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +070011406 execute( TC_chan_deact_silence() );
Harald Welte4003d112017-12-09 22:35:39 +010011407 execute( TC_chan_rel_rll_rel_ind() );
11408 execute( TC_chan_rel_conn_fail() );
11409 execute( TC_chan_rel_hard_clear() );
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +020011410 execute( TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() );
11411 execute( TC_chan_rel_last_eutran_plmn_hard_clear_csfb() );
Harald Welte99787102019-02-04 10:41:36 +010011412 execute( TC_chan_rel_hard_clear_csfb() );
Harald Welted8c36cd2017-12-09 23:05:31 +010011413 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +020011414 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +010011415 execute( TC_chan_rel_a_reset() );
Pau Espin Pedrolc675b612020-01-09 19:55:40 +010011416 execute( TC_chan_rel_sccp_tiar_timeout() );
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +020011417 execute( TC_chan_rel_rr_cause() );
Harald Welte6f521d82017-12-11 19:52:02 +010011418
Harald Weltecfe2c962017-12-15 12:09:32 +010011419 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +010011420
11421 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +010011422 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +010011423 execute( TC_assignment_csd() );
11424 execute( TC_assignment_ctm() );
11425 execute( TC_assignment_sign() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +020011426 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11427 execute( TC_assignment_aoip_tla_v6() );
11428 }
Harald Welte235ebf12017-12-15 14:18:16 +010011429 execute( TC_assignment_fr_a5_0() );
11430 execute( TC_assignment_fr_a5_1() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +020011431 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte8f67d1d2018-05-25 20:38:42 +020011432 execute( TC_assignment_fr_a5_1_codec_missing() );
11433 }
Harald Welte235ebf12017-12-15 14:18:16 +010011434 execute( TC_assignment_fr_a5_3() );
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +020011435 execute( TC_assignment_fr_a5_4() );
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +020011436 execute( TC_assignment_fr_a5_4_fail() );
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +020011437 execute( TC_assignment_fr_a5_not_sup() );
Harald Welte3c86ea02018-05-10 22:28:05 +020011438 execute( TC_ciph_mode_a5_0() );
11439 execute( TC_ciph_mode_a5_1() );
Oliver Smith50b98122021-07-09 15:00:28 +020011440 execute( TC_ciph_mode_a5_2_0() );
Oliver Smith1dff88d2021-07-09 08:45:51 +020011441 execute( TC_ciph_mode_a5_2_1() );
Harald Welte3c86ea02018-05-10 22:28:05 +020011442 execute( TC_ciph_mode_a5_3() );
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +020011443 execute( TC_ciph_mode_a5_4() );
Harald Welte16a4adf2017-12-14 18:54:01 +010011444
Harald Welte60aa5762018-03-21 19:33:13 +010011445 execute( TC_assignment_codec_fr() );
Neels Hofmeyr559d5d02021-04-16 16:50:49 +020011446 execute( TC_assignment_codec_fr_by_mode_modify() );
Harald Welte60aa5762018-03-21 19:33:13 +010011447 execute( TC_assignment_codec_hr() );
11448 execute( TC_assignment_codec_efr() );
11449 execute( TC_assignment_codec_amr_f() );
11450 execute( TC_assignment_codec_amr_h() );
Philipp Maier8a581d22019-03-26 18:32:48 +010011451
Neels Hofmeyrf246a922020-05-13 02:27:10 +020011452 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier8a581d22019-03-26 18:32:48 +010011453 execute( TC_assignment_codec_amr_f_S1() );
11454 execute( TC_assignment_codec_amr_h_S1() );
11455 execute( TC_assignment_codec_amr_f_S124() );
11456 execute( TC_assignment_codec_amr_h_S124() );
11457 execute( TC_assignment_codec_amr_f_S0() );
11458 execute( TC_assignment_codec_amr_f_S02() );
11459 execute( TC_assignment_codec_amr_f_S024() );
11460 execute( TC_assignment_codec_amr_f_S0247() );
11461 execute( TC_assignment_codec_amr_h_S0() );
11462 execute( TC_assignment_codec_amr_h_S02() );
11463 execute( TC_assignment_codec_amr_h_S024() );
11464 execute( TC_assignment_codec_amr_h_S0247() );
11465 execute( TC_assignment_codec_amr_f_S01234567() );
11466 execute( TC_assignment_codec_amr_f_S0234567() );
11467 execute( TC_assignment_codec_amr_f_zero() );
11468 execute( TC_assignment_codec_amr_f_unsupp() );
11469 execute( TC_assignment_codec_amr_h_S7() );
Neels Hofmeyr21863562020-11-26 00:34:33 +000011470 execute( TC_assignment_codec_amr_f_start_mode_auto() );
11471 execute( TC_assignment_codec_amr_h_start_mode_auto() );
Neels Hofmeyr3eb94562020-11-26 02:40:26 +000011472 execute( TC_assignment_codec_amr_f_start_mode_4() );
11473 execute( TC_assignment_codec_amr_h_start_mode_4() );
Neels Hofmeyr454d7922020-11-26 02:24:57 +000011474 execute( TC_assignment_codec_amr_startmode_cruft() );
Philipp Maier8a581d22019-03-26 18:32:48 +010011475 }
Harald Welte60aa5762018-03-21 19:33:13 +010011476
Philipp Maierac09bfc2019-01-08 13:41:39 +010011477 execute( TC_assignment_codec_fr_exhausted_req_hr() );
11478 execute( TC_assignment_codec_fr_exhausted_req_fr() );
11479 execute( TC_assignment_codec_fr_exhausted_req_fr_hr() );
11480 execute( TC_assignment_codec_fr_exhausted_req_hr_fr() );
11481 execute( TC_assignment_codec_hr_exhausted_req_fr() );
11482 execute( TC_assignment_codec_hr_exhausted_req_hr() );
11483 execute( TC_assignment_codec_hr_exhausted_req_hr_fr() );
11484 execute( TC_assignment_codec_hr_exhausted_req_fr_hr() );
11485 execute( TC_assignment_codec_req_hr_fr() );
11486 execute( TC_assignment_codec_req_fr_hr() );
Pau Espin Pedrol14475352021-07-22 15:48:16 +020011487 execute( TC_assignment_sdcch_exhausted_req_signalling() );
11488 execute( TC_assignment_sdcch_exhausted_req_signalling_tch_forbidden() );
11489 execute( TC_assignment_sdcch_exhausted_req_voice_tch_forbidden() );
Philipp Maierac09bfc2019-01-08 13:41:39 +010011490
Pau Espin Pedrol23510fb2021-07-20 17:00:38 +020011491 execute( TC_assignment_osmux() );
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +020011492
Harald Welte898113b2018-01-31 18:32:21 +010011493 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +010011494 execute( TC_rll_est_ind_inact_lchan() );
11495 execute( TC_rll_est_ind_inval_sapi1() );
11496 execute( TC_rll_est_ind_inval_sapi3() );
11497 execute( TC_rll_est_ind_inval_sacch() );
11498
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +070011499 /* DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
11500 execute( TC_tch_dlci_link_id_sapi() );
11501
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +070011502 /* SAPI N Reject triggered by RLL establishment failures */
11503 execute( TC_rll_rel_ind_sapi_n_reject() );
11504 execute( TC_rll_err_ind_sapi_n_reject() );
11505 execute( TC_rll_timeout_sapi_n_reject() );
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +070011506 execute( TC_rll_sapi_n_reject_dlci_cc() );
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +070011507
Harald Welte898113b2018-01-31 18:32:21 +010011508 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +010011509 execute( TC_paging_imsi_nochan() );
11510 execute( TC_paging_tmsi_nochan() );
11511 execute( TC_paging_tmsi_any() );
11512 execute( TC_paging_tmsi_sdcch() );
11513 execute( TC_paging_tmsi_tch_f() );
11514 execute( TC_paging_tmsi_tch_hf() );
11515 execute( TC_paging_imsi_nochan_cgi() );
11516 execute( TC_paging_imsi_nochan_lac_ci() );
11517 execute( TC_paging_imsi_nochan_ci() );
11518 execute( TC_paging_imsi_nochan_lai() );
11519 execute( TC_paging_imsi_nochan_lac() );
11520 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +010011521 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
11522 execute( TC_paging_imsi_nochan_rnc() );
11523 execute( TC_paging_imsi_nochan_lac_rnc() );
11524 execute( TC_paging_imsi_nochan_lacs() );
11525 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +010011526 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +010011527 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +010011528 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +010011529 execute( TC_paging_counter() );
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +010011530 execute( TC_paging_resp_unsol() );
Pau Espin Pedrol09b9bad2022-04-21 18:48:08 +020011531 execute( TC_paging_500req() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +010011532
11533 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +010011534 execute( TC_rsl_unknown_unit_id() );
11535
11536 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +010011537
11538 execute( TC_classmark() );
Harald Welteeddf0e92020-06-21 19:42:15 +020011539 execute( TC_common_id() );
Harald Welte898113b2018-01-31 18:32:21 +010011540 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +010011541 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +010011542 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +010011543 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +010011544 execute( TC_err_84_unknown_msg() );
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010011545
Harald Welte261af4b2018-02-12 21:20:39 +010011546 execute( TC_ho_int() );
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +020011547 execute( TC_ho_int_a5_0() );
11548 execute( TC_ho_int_a5_1() );
11549 execute( TC_ho_int_a5_3() );
11550 execute( TC_ho_int_a5_4() );
Neels Hofmeyr5f144212020-11-03 15:41:58 +000011551 execute( TC_ho_int_radio_link_failure() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011552
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +010011553 /* TC_ho_out_of_this_bsc is run last, see comment below */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +020011554 execute( TC_ho_out_fail_no_msc_response() );
11555 execute( TC_ho_out_fail_rr_ho_failure() );
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +020011556 execute( TC_ho_out_fail_no_result_after_ho_cmd() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011557
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010011558 execute( TC_ho_into_this_bsc() );
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +020011559 execute( TC_ho_into_this_bsc_a5_0() );
11560 execute( TC_ho_into_this_bsc_a5_1() );
11561 execute( TC_ho_into_this_bsc_a5_3() );
11562 execute( TC_ho_into_this_bsc_a5_4() );
Neels Hofmeyr93182e02022-02-17 21:59:07 +010011563 execute( TC_ho_into_this_bsc_a5_1_3_no_chosen_enc_alg() );
11564 execute( TC_ho_into_this_bsc_a5_1_3() );
Neels Hofmeyr907b23b2022-02-17 21:58:47 +010011565 execute( TC_ho_into_this_bsc_a5_mismatch() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +020011566 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11567 execute( TC_ho_into_this_bsc_tla_v6() );
11568 }
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +020011569 execute( TC_srvcc_eutran_to_geran() );
Vadim Yanitskiy634f75d2022-03-14 17:04:45 +030011570 execute( TC_srvcc_eutran_to_geran_a5_3() );
Pau Espin Pedrola8ef3be2022-02-16 16:21:17 +010011571 execute( TC_srvcc_eutran_to_geran_src_sai() );
Pau Espin Pedrol35801c32021-04-19 13:03:20 +020011572 execute( TC_srvcc_eutran_to_geran_ho_out() );
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +020011573 execute( TC_srvcc_eutran_to_geran_forbid_fast_return() );
11574 execute( TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011575 execute( TC_ho_in_fail_msc_clears() );
11576 execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
11577 execute( TC_ho_in_fail_no_detect() );
11578 execute( TC_ho_in_fail_no_detect2() );
Neels Hofmeyra23f3b12022-03-02 19:57:12 +010011579 execute( TC_ho_into_this_bsc_sccp_cr_without_bssap() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +010011580
Neels Hofmeyr91401012019-07-11 00:42:35 +020011581 execute( TC_ho_neighbor_config_1() );
11582 execute( TC_ho_neighbor_config_2() );
11583 execute( TC_ho_neighbor_config_3() );
11584 execute( TC_ho_neighbor_config_4() );
11585 execute( TC_ho_neighbor_config_5() );
11586 execute( TC_ho_neighbor_config_6() );
11587 execute( TC_ho_neighbor_config_7() );
11588
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +010011589 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010011590 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +010011591 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +020011592
11593 execute( TC_dyn_pdch_ipa_act_deact() );
11594 execute( TC_dyn_pdch_ipa_act_nack() );
11595 execute( TC_dyn_pdch_osmo_act_deact() );
11596 execute( TC_dyn_pdch_osmo_act_nack() );
Pau Espin Pedrol37a4c152021-11-16 19:02:23 +010011597 execute( TC_dyn_ts_sdcch8_act_deact() );
11598 execute( TC_dyn_ts_sdcch8_all_subslots_used() );
11599 execute( TC_dyn_ts_sdcch8_tch_call_act_deact() );
11600 execute( TC_dyn_ts_sdcch8_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +020011601
Stefan Sperling0796a822018-10-05 13:01:39 +020011602 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +020011603 execute( TC_chopped_ipa_payload() );
Stefan Sperling0796a822018-10-05 13:01:39 +020011604
Pau Espin Pedrol8f773632019-11-05 11:46:53 +010011605 /* Power control related */
11606 execute( TC_assignment_verify_ms_power_params_ie() );
Vadim Yanitskiy4b233042021-06-30 00:58:43 +020011607 execute( TC_c0_power_red_mode() );
Neels Hofmeyr4f118412020-06-04 15:25:10 +020011608
11609 /* MSC pooling */
11610 /* FIXME: in SCCPlite, indicating how many MSCs should be connected does currently not work. Since
11611 * RESET->RESET-ACK is unconditionally negotiated for all configured MSCs, they always all appear as connected
11612 * to osmo-bsc. The MSC pooling tests however require disconnecting selected MSCs, and hence don't work out as
11613 * intended on SCCPlite. So for now, run these only for SCCP/M3UA. */
11614 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11615 execute( TC_mscpool_L3Compl_on_1_msc() );
11616 execute( TC_mscpool_L3Complete_by_imsi_round_robin() );
11617 execute( TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() );
11618 execute( TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() );
11619 execute( TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() );
11620 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() );
11621 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_1() );
11622 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_2() );
11623 execute( TC_mscpool_LU_by_tmsi_from_other_PLMN() );
11624 execute( TC_mscpool_paging_and_response_imsi() );
11625 execute( TC_mscpool_paging_and_response_tmsi() );
11626 execute( TC_mscpool_no_allow_attach_round_robin() );
11627 execute( TC_mscpool_no_allow_attach_valid_nri() );
11628 }
11629
Harald Welte99f3ca02018-06-14 13:40:29 +020011630 execute( TC_early_conn_fail() );
11631 execute( TC_late_conn_fail() );
Oliver Smithaf03bef2021-08-24 15:34:51 +020011632 execute( TC_stats_conn_fail() );
Harald Welte99f3ca02018-06-14 13:40:29 +020011633
Philipp Maier783681c2020-07-16 16:47:06 +020011634 /* Emergency call handling (deny / allow) */
11635 execute( TC_assignment_emerg_setup_allow() );
11636 execute( TC_assignment_emerg_setup_deny_msc() );
11637 execute( TC_assignment_emerg_setup_deny_bts() );
Philipp Maier82812002020-08-13 18:48:27 +020011638 execute( TC_emerg_premption() );
11639
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +070011640 /* Frequency hopping parameters handling */
11641 execute( TC_fh_params_chan_activ() );
11642 execute( TC_fh_params_imm_ass() );
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +070011643 execute( TC_fh_params_assignment_cmd() );
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +070011644 execute( TC_fh_params_handover_cmd() );
Vadim Yanitskiyca974032020-09-01 07:20:39 +070011645 execute( TC_fh_params_si4_cbch() );
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020011646
11647 if (mp_enable_lcs_tests) {
11648 execute( TC_lcs_loc_req_for_active_ms() );
11649 execute( TC_lcs_loc_req_for_active_ms_ta_req() );
11650 execute( TC_lcs_loc_req_for_idle_ms() );
11651 execute( TC_lcs_loc_req_no_subscriber() );
11652 execute( TC_lcs_loc_req_for_active_ms_le_timeout() );
11653 execute( TC_lcs_loc_req_for_active_ms_le_timeout2() );
11654 execute( TC_lcs_loc_req_for_idle_ms_no_pag_resp() );
11655 execute( TC_cm_service_during_lcs_loc_req() );
11656 execute( TC_ho_during_lcs_loc_req() );
Neels Hofmeyra47a8c62022-04-07 00:31:19 +020011657 execute( TC_emerg_call_and_lcs_loc_req() );
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020011658 }
Neels Hofmeyrbf037052020-10-28 22:52:02 +000011659
11660 execute( TC_no_msc() );
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000011661
11662 execute( TC_refuse_chan_act_to_vamos() );
11663 execute( TC_refuse_mode_modif_to_vamos() );
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000011664
11665 execute( TC_reassignment_fr() );
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020011666
11667 execute( TC_cm_reestablishment() );
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020011668
11669 execute( TC_imm_ass_post_chan_ack() );
11670 execute( TC_imm_ass_pre_chan_ack() );
Neels Hofmeyr23158742021-09-07 19:08:07 +020011671 execute( TC_imm_ass_pre_ts_ack() );
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020011672 execute( TC_imm_ass_pre_chan_ack_dyn_ts() );
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020011673 execute( TC_imm_ass_pre_ts_ack_dyn_ts() );
Neels Hofmeyr5d7d13f2021-09-07 14:44:36 +020011674
11675 execute( TC_ctrl_trx_rf_locked() );
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011676
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011677 execute( TC_ratectr_all_available_allocated() );
11678 execute( TC_ratectr_all_available_allocated_dyn() );
11679
Neels Hofmeyrb7581872021-11-07 14:02:49 +010011680 execute( TC_cm_serv_rej() );
11681
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011682 execute( TC_lost_sdcch_during_assignment() );
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +010011683
11684 /* Run TC_ho_out_of_this_bsc last, because it may trigger a segfault before osmo-bsc's patch
11685 * with change-id I5a3345ab0005a73597f5c27207480912a2f5aae6 */
11686 execute( TC_ho_out_of_this_bsc() );
Harald Welte28d943e2017-11-25 15:00:50 +010011687}
11688
11689}