blob: f514c434452c2ebc9f27df2efc6d2130583755bb [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;
Harald Welteae026692017-12-09 01:03:01 +0100964 }
Harald Welte60e823a2017-12-10 14:10:59 +0100965 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100966 [] IPA_RSL[i].receive { repeat }
967 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100968 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200969 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100970 }
971 }
972}
973
Harald Welte12055472018-03-17 20:10:08 +0100974function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100975 var IPL4asp_Types.Result res := {
976 errorCode := omit,
977 connId := omit,
978 os_error_code := omit,
979 os_error_text := omit
980 };
981
Harald Welte12055472018-03-17 20:10:08 +0100982 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
983 return;
984 }
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100985
986 /* Alive components don't finish sockets (TCP FIN) when they are
987 * stopped. Hence, we need to manually call close() on them to make sure
988 * the IUT knows about it. */
989 f_ipa_cfg_disconnect(IPA_CFG_PORT, res);
990
Harald Welte12055472018-03-17 20:10:08 +0100991 clnt.vc_IPA.stop;
992 if (isbound(clnt.vc_RSL)) {
993 clnt.vc_RSL.stop;
994 }
995}
996
Harald Welte21b46bd2017-12-17 19:46:32 +0100997/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100998function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
999 timer T := secs_max;
1000 T.start;
1001 while (true) {
1002 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
1003 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +01001004 /* the 'degraded' state exists from OML connection time, and we have to wait
1005 * until all MO's are initialized */
1006 T.start(1.0);
1007 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001008 return;
1009 }
Harald Weltef0d6ac62017-12-17 17:02:21 +01001010 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +01001011 if (not T.running) {
Max99253902018-11-16 17:57:39 +01001012 setverdict(fail, "Timeout waiting for BTS" & int2str(bts_nr) & " oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +02001013 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001014 }
1015 }
1016}
1017
Harald Welte21b46bd2017-12-17 19:46:32 +01001018/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +01001019altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +01001020 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +01001021 [] T_guard.timeout {
1022 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +02001023 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +01001024 }
Harald Welte60e823a2017-12-10 14:10:59 +01001025 /* always respond with RESET ACK to RESET */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001026 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Welte60e823a2017-12-10 14:10:59 +01001027 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001028 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Welte69c1c262017-12-13 21:02:08 +01001029 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +01001030 }
Harald Welte28d943e2017-11-25 15:00:50 +01001031}
1032
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001033altstep no_bssmap_reset() runs on test_CT {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001034 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001035 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +02001036 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001037 }
1038}
1039
Daniel Willmann191e0d92018-01-17 12:44:35 +01001040function f_init_mgcp(charstring id) runs on test_CT {
1041 id := id & "-MGCP";
1042
1043 var MGCPOps ops := {
1044 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
1045 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
1046 };
1047 var MGCP_conn_parameters mgcp_pars := {
1048 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +01001049 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +01001050 mgw_ip := mp_test_ip,
Pau Espin Pedrol1a026a52019-06-18 17:21:52 +02001051 mgw_udp_port := 2427,
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02001052 /* Enable it for SCCPlite, since we have 2 MGCP sockets towards MGW (UDP one +
1053 the on with MGCP over IPA forwarded from MSC one) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001054 multi_conn_mode := (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER)
Daniel Willmann191e0d92018-01-17 12:44:35 +01001055 };
1056
Harald Welte71389132021-12-09 21:58:18 +01001057 vc_MGCP := MGCP_Emulation_CT.create(id) alive;
Daniel Willmann191e0d92018-01-17 12:44:35 +01001058 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
1059}
1060
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001061/* Enable or disable (current default) Osmux. When enabling, BSSMAP Reset
1062 * contains extra IE (OsmuxSupport) and osmo-bsc will handle AssignReq with
1063 * OsmuxCID IE.
1064 */
1065private function f_vty_allow_osmux(boolean allow) runs on test_CT {
1066 f_vty_enter_cfg_msc(BSCVTY, 0);
1067 if (allow) {
1068 f_vty_transceive(BSCVTY, "osmux on");
1069 } else {
1070 f_vty_transceive(BSCVTY, "osmux off");
1071 }
1072 f_vty_transceive(BSCVTY, "exit");
1073 f_vty_transceive(BSCVTY, "exit");
1074 g_osmux_enabled := allow;
1075}
1076
Max2253c0b2018-11-06 19:28:05 +01001077function f_init_vty(charstring id := "foo") runs on test_CT {
Harald Welte94e0c342018-04-07 11:33:23 +02001078 if (BSCVTY.checkstate("Mapped")) {
1079 /* skip initialization if already executed once */
1080 return;
1081 }
Harald Weltebc03c762018-02-12 18:09:38 +01001082 map(self:BSCVTY, system:BSCVTY);
1083 f_vty_set_prompts(BSCVTY);
1084 f_vty_transceive(BSCVTY, "enable");
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01001085 f_cs7_inst_0_cfg(BSCVTY, {"sccp-timer ias " & int2str(g_bsc_sccp_timer_ias),
1086 "sccp-timer iar " & int2str(g_bsc_sccp_timer_iar)});
Harald Weltebc03c762018-02-12 18:09:38 +01001087}
1088
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +02001089friend function f_logp(TELNETasp_PT pt, charstring log_msg)
Neels Hofmeyr4f118412020-06-04 15:25:10 +02001090{
1091 // log on TTCN3 log output
1092 log(log_msg);
1093 // log in stderr log
Neels Hofmeyr8bdafe52021-12-14 17:25:48 +01001094 if (pt.checkstate("Mapped")) {
1095 f_vty_transceive(pt, "logp lglobal notice TTCN3 f_logp(): " & log_msg);
1096 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02001097}
1098
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001099private function f_sysinfo_seen(integer rsl_idx, RSL_Message rsl) runs on test_CT
1100{
1101 if (rsl_idx >= lengthof(g_system_information)) {
1102 g_system_information[rsl_idx] := SystemInformationConfig_omit
1103 }
1104 f_sysinfo_dec_raw(g_system_information[rsl_idx], rsl);
1105}
1106
1107altstep as_catch_RSL_sysinfo(integer rsl_idx) runs on test_CT {
1108 var ASP_RSL_Unitdata rx_rsl_ud;
1109
1110 /* For handler_mode := false, receiving the RSL bootstrap messages directly on IPA_RSL */
1111 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
1112 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1113 repeat;
1114 }
1115 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
1116 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1117 repeat;
1118 }
1119 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> value rx_rsl_ud {
1120 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1121 repeat;
1122 }
1123 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_SACCH_FILL)) -> value rx_rsl_ud {
1124 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1125 repeat;
1126 }
1127
1128 /* For handler_mode := true, receiving the RSL bootstrap messages via RSL_Emulation */
1129 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
1130 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1131 repeat;
1132 }
1133 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
1134 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1135 repeat;
1136 }
1137 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> value rx_rsl_ud {
1138 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1139 repeat;
1140 }
1141 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_SACCH_FILL)) -> value rx_rsl_ud {
1142 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1143 repeat;
1144 }
1145}
1146
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001147/* TODO: use BooleanList from COMMON/src/General_Types.ttcn */
1148private type record of boolean my_BooleanList;
1149
1150private function f_vty_msc_allow_attach(TELNETasp_PT pt, my_BooleanList allow_attach_list)
1151{
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001152 var charstring config := f_vty_transceive_ret(pt, "show running-config");
1153
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001154 for (var integer msc_nr := 0; msc_nr < sizeof(allow_attach_list); msc_nr := msc_nr+1) {
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001155 if (f_strstr(config, "\nmsc " & int2str(msc_nr) & "\n") < 0) {
1156 /* There is no 'msc N' for this msc_nr in the running config, so don't create an empty msc by
1157 * stepping into that config node. */
1158 log("msc ", msc_nr, " is not configured, skipping");
1159 continue;
1160 }
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001161 f_vty_enter_cfg_msc(pt, msc_nr);
1162 if (allow_attach_list[msc_nr]) {
1163 /* strict := false: ignore if osmo-bsc does not support this config option (latest build) */
1164 f_vty_transceive(pt, "allow-attach", strict := false);
1165 } else {
1166 f_vty_transceive(pt, "no allow-attach", strict := false);
1167 }
1168 f_vty_transceive(pt, "exit");
1169 f_vty_transceive(pt, "exit");
1170 }
1171}
1172
Harald Welte21b46bd2017-12-17 19:46:32 +01001173/* global initialization function
1174 * \param nr_bts Number of BTSs we should start/bring up
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001175 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false).
1176 * \param nr_msc Number of virtual MSCs to bring up to connect to osmo-bsc.
1177 */
1178function f_init(integer nr_bts := NUM_BTS, boolean handler_mode := false, boolean allow_osmux := false,
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001179 integer nr_msc := 1, float guard_timeout := 30.0) runs on test_CT {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001180 var integer bssap_idx;
Harald Welte28d943e2017-11-25 15:00:50 +01001181
Harald Welteae026692017-12-09 01:03:01 +01001182 if (g_initialized) {
1183 return;
Harald Welte28d943e2017-11-25 15:00:50 +01001184 }
Harald Welteae026692017-12-09 01:03:01 +01001185 g_initialized := true;
1186
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001187 T_guard.start(guard_timeout);
Daniel Willmanne68f9272018-11-27 15:15:28 +01001188 activate(as_Tguard());
1189
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001190 f_init_vty("VirtMSC");
Pau Espin Pedrol23510fb2021-07-20 17:00:38 +02001191 f_vty_allow_osmux(allow_osmux);
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001192
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001193 var my_BooleanList allow_attach := { false, false, false };
Daniel Willmannebdecc02020-08-12 15:30:17 +02001194 f_init_statsd("VirtMSC", vc_STATSD, mp_test_ip, mp_bsc_statsd_port);
1195
Neels Hofmeyr9db8e0e2021-08-23 20:45:58 +02001196 /* Make sure each MSC's internal state is "DISCONNECTED" at first */
1197 for (bssap_idx := 0; bssap_idx < NUM_MSC; bssap_idx := bssap_idx+1) {
1198 f_vty_transceive(BSCVTY, "msc " & int2str(bssap_idx) & " bssmap reset", strict := false);
1199 }
1200
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001201 for (bssap_idx := 0; bssap_idx < nr_msc; bssap_idx := bssap_idx+1) {
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001202 allow_attach[bssap_idx] := true;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001203 /* Call a function of our 'parent component' RAN_Adapter_CT to start the
1204 * MSC-side BSSAP emulation */
1205 if (handler_mode) {
1206 var RanOps ranops := MSC_RanOps;
1207 ranops.use_osmux := g_osmux_enabled;
1208 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", ranops);
1209 connect(self:SCCPLITE_IPA_CTRL, g_bssap[bssap_idx].vc_RAN:CTRL_CLIENT);
1210 f_ran_adapter_start(g_bssap[bssap_idx]);
1211 } else {
1212 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", omit);
1213 connect(self:BSSAP, g_bssap[bssap_idx].vc_SCCP:SCCP_SP_PORT);
1214 f_ran_adapter_start(g_bssap[bssap_idx]);
1215 f_legacy_bssap_reset();
1216 }
Harald Welte67089ee2018-01-17 22:19:03 +01001217 }
Harald Welted5833a82018-05-27 16:52:56 +02001218
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02001219 if (mp_enable_lcs_tests) {
1220 if (handler_mode) {
1221 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", SMLC_BssapLeOps);
1222 } else {
1223 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", omit);
1224 connect(self:BSSAP_LE, g_bssap_le.vc_SCCP:SCCP_SP_PORT);
1225 }
1226 f_bssap_le_adapter_start(g_bssap_le);
Harald Welte47cd0e32020-08-21 12:39:11 +02001227 }
Harald Welte47cd0e32020-08-21 12:39:11 +02001228
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001229 /* start the test with exactly all enabled MSCs allowed to attach */
1230 f_vty_msc_allow_attach(BSCVTY, allow_attach);
1231
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01001232 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +01001233
Daniel Willmann191e0d92018-01-17 12:44:35 +01001234 f_init_mgcp("VirtMSC");
1235
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001236 for (var integer i := 0; i < nr_bts; i := i+1) {
1237 f_init_bts(i, handler_mode);
Harald Welte696ddb62017-12-08 14:01:43 +01001238 }
Neels Hofmeyr9c0f9c82022-01-23 01:20:28 +01001239
1240 /* Emit a marker to appear in the SUT's own logging output */
1241 f_logp(BSCVTY, testcasename() & "() start");
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001242}
Harald Welte696ddb62017-12-08 14:01:43 +01001243
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001244function f_init_bts(integer bts_idx := 0, boolean handler_mode := false)
1245runs on test_CT {
1246 /* wait until osmo-bts-omldummy has respawned */
1247 f_wait_oml(bts_idx, "degraded", 5.0);
1248
1249 /* start RSL connection */
1250 f_ipa_rsl_start(bts[bts_idx].rsl, mp_bsc_ip, mp_bsc_rsl_port, bts_idx, handler_mode);
1251 /* wait until BSC tells us "connected" */
1252 f_wait_oml(bts_idx, "connected", 5.0);
Harald Welte28d943e2017-11-25 15:00:50 +01001253}
1254
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001255function f_init_bts_and_check_sysinfo(integer bts_idx := 0, boolean handler_mode := false,
1256 template SystemInformationConfig expect_si)
1257runs on test_CT {
1258 var default sysinfo := activate(as_catch_RSL_sysinfo(bts_idx));
1259
1260 f_init_bts(bts_idx, handler_mode);
1261
1262 /* Give some time to (hopefully/most likely) collect all system informations from RSL startup.
1263 * We could stop as soon as all expected SI are received, but then we might miss SI that we don't expect and
1264 * that might be sent afterwards. So rather give a generous timeout and be quite sure to catch all SI.
1265 */
1266 f_sleep(5.0);
1267 log("RSL ", bts_idx, " SYSTEM INFORMATION: ", g_system_information[bts_idx]);
1268
1269 deactivate(sysinfo);
1270
1271 if (match(g_system_information[bts_idx], expect_si)) {
1272 setverdict(pass);
1273 } else {
1274 log("RSL ", bts_idx, ": EXPECTED SI: ", expect_si);
1275 log("RSL ", bts_idx, ": GOT SI: ", g_system_information[bts_idx]);
1276 setverdict(fail, "received SI does not match expectations");
1277 return;
1278 }
1279}
1280
Maxd4e56962018-10-31 19:08:25 +01001281/* expect to receive a RSL message matching a specified template on a given BTS / stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001282function 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 +01001283runs on test_CT return RSL_Message {
1284 var ASP_RSL_Unitdata rx_rsl_ud;
1285 timer T := t_secs;
1286
1287 T.start;
1288 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001289 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
Harald Welteae026692017-12-09 01:03:01 +01001290 T.stop;
1291 }
1292 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +01001293 [] T.timeout {
1294 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +02001295 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +01001296 }
Harald Welteae026692017-12-09 01:03:01 +01001297 }
1298 return rx_rsl_ud.rsl;
1299}
1300
Harald Welte21b46bd2017-12-17 19:46:32 +01001301/* helper function to transmit RSL on a given BTS/stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001302function 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 +01001303runs on test_CT {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001304 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(t_tx, sid));
Harald Welteae026692017-12-09 01:03:01 +01001305}
1306
1307
Harald Welte4003d112017-12-09 22:35:39 +01001308/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +01001309testcase TC_chan_act_noreply() runs on test_CT {
1310 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +01001311 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +01001312
Harald Welte89d42e82017-12-17 16:42:41 +01001313 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +01001314
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001315 IPA_RSL[0].send(ts_ASP_RSL_UD(ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +01001316 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001317 f_shutdown_helper();
Harald Welte28d943e2017-11-25 15:00:50 +01001318}
1319
Neels Hofmeyr734b1a32021-11-29 16:00:17 +01001320const CounterNameVals counternames_bts_chreq := {
1321 { "chreq:total", 0 },
1322 { "chreq:attempted_emerg", 0 },
1323 { "chreq:attempted_call", 0 },
1324 { "chreq:attempted_location_upd", 0 },
1325 { "chreq:attempted_pag", 0 },
1326 { "chreq:attempted_pdch", 0 },
1327 { "chreq:attempted_other", 0 },
1328 { "chreq:attempted_unknown", 0 },
1329 { "chreq:successful", 0 },
1330 { "chreq:successful_emerg", 0 },
1331 { "chreq:successful_call", 0 },
1332 { "chreq:successful_location_upd", 0 },
1333 { "chreq:successful_pag", 0 },
1334 { "chreq:successful_pdch", 0 },
1335 { "chreq:successful_other", 0 },
1336 { "chreq:successful_unknown", 0 },
1337 { "chreq:no_channel", 0 },
1338 { "chreq:max_delay_exceeded", 0 }
1339};
1340
1341/* verify the "chreq:*" counters */
1342private function f_chan_act_counter(OCT1 ra, charstring chreq_ctr_suffix) runs on test_CT
1343{
1344 var GsmFrameNumber fn := 23;
1345
1346 f_logp(BSCVTY, "f_chan_act_counter(" & chreq_ctr_suffix & ")");
1347
1348 var RSL_Message rx_rsl;
1349 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1350 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1351 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1352
1353 f_ctrs_bts_add(0, "chreq:total");
1354 f_ctrs_bts_add(0, "chreq:attempted_" & chreq_ctr_suffix);
1355 f_ctrs_bts_verify();
1356
1357 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
1358 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
1359
1360 f_ctrs_bts_add(0, "chreq:successful");
1361 f_ctrs_bts_add(0, "chreq:successful_" & chreq_ctr_suffix);
1362 f_ctrs_bts_verify();
1363
1364 /* test is done, release RSL Conn Fail Ind to clean up */
1365 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1366 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1367 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
1368 f_sleep(1.0);
1369}
1370
Harald Welte4003d112017-12-09 22:35:39 +01001371testcase TC_chan_act_counter() runs on test_CT {
1372 var BSSAP_N_UNITDATA_ind ud_ind;
1373 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +01001374 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +01001375
Harald Welte89d42e82017-12-17 16:42:41 +01001376 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001377
Neels Hofmeyr734b1a32021-11-29 16:00:17 +01001378 f_vty_allow_emerg_bts(true, 0);
1379
1380 f_ctrs_bts_init(1, counternames_bts_chreq);
1381
1382 /* emergency call: RA & 0xe0 == 0xa0 --> CHREQ_T_EMERG_CALL */
1383 f_chan_act_counter('a3'O, "emerg");
1384
1385 /* voice TCH/H: RA & 0xf0 == 0x40 --> CHREQ_T_VOICE_CALL_TCH_H */
1386 f_chan_act_counter('43'O, "call");
1387
1388 /* LU: RA & 0xf0 == 0x00 --> CHREQ_T_LOCATION_UPD */
1389 f_chan_act_counter('03'O, "location_upd");
1390
1391 /* Paging: RA & 0xf0 == 0x20 --> CHREQ_T_PAG_R_TCH_F */
1392 f_chan_act_counter('23'O, "pag");
1393 /* Paging: RA & 0xf0 == 0x30 --> CHREQ_T_PAG_R_TCH_FH */
1394 f_chan_act_counter('33'O, "pag");
1395
1396 /* LU: RA & 0xfc == 0x78 --> CHREQ_T_PDCH_TWO_PHASE */
1397 /* no PCU, so PDCH not allowed. Skip this test for now. */
1398 /* f_chan_act_counter('7b'O, "pdch"); */
1399
1400 /* LU: RA & 0xf0 == 0x10 --> CHREQ_T_SDCCH */
1401 f_chan_act_counter('13'O, "other");
Harald Welte4003d112017-12-09 22:35:39 +01001402
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001403 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001404}
1405
Harald Welteae026692017-12-09 01:03:01 +01001406/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
Philipp Maier9c60a622020-07-09 15:08:46 +02001407private function f_TC_chan_act_ack_noest(OCT1 ra := '23'O) runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +01001408 var RSL_Message rx_rsl;
1409
Harald Welteae026692017-12-09 01:03:01 +01001410 /* Send CHAN RQD and wait for allocation; acknowledge it */
Philipp Maier9c60a622020-07-09 15:08:46 +02001411 var RslChannelNr chan_nr := f_chreq_act_ack(ra);
Harald Welteae026692017-12-09 01:03:01 +01001412
1413 /* expect BSC to disable the channel again if there's no RLL EST IND */
1414 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1415
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001416 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001417}
1418
Philipp Maier9c60a622020-07-09 15:08:46 +02001419/* Normal variant */
1420testcase TC_chan_act_ack_noest() runs on test_CT {
Philipp Maieraf58db22020-08-12 17:24:40 +02001421 f_init(1);
Philipp Maier9c60a622020-07-09 15:08:46 +02001422 f_TC_chan_act_ack_noest();
1423}
1424
1425/* Emergency call variant */
1426testcase TC_chan_act_ack_noest_emerg() runs on test_CT {
1427 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
Philipp Maieraf58db22020-08-12 17:24:40 +02001428 f_init(1);
1429 f_vty_allow_emerg_bts(true, 0);
Philipp Maier9c60a622020-07-09 15:08:46 +02001430 f_TC_chan_act_ack_noest(ra := 'A5'O);
1431}
1432
Philipp Maier606f07d2020-08-12 17:21:58 +02001433/* Emergency call variant, but emergency calls are not allowed */
1434testcase TC_chan_rqd_emerg_deny() runs on test_CT {
1435 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
1436
1437 var RSL_Message rx_rsl;
1438 var GsmRrMessage rr;
1439
1440 f_init(1);
1441 f_vty_allow_emerg_bts(false, 0);
1442
1443 IPA_RSL[0].clear;
1444 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
1445
1446 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
1447 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
1448 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1449 setverdict(pass);
1450 } else {
1451 setverdict(fail, "immediate assignment not rejected");
1452 }
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01001453
1454 f_shutdown_helper();
Philipp Maier606f07d2020-08-12 17:21:58 +02001455}
1456
Harald Welteae026692017-12-09 01:03:01 +01001457/* Test behavior if MSC never answers to CR */
1458testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +01001459 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
1460 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +01001461 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +01001462 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +01001463
Harald Welte89d42e82017-12-17 16:42:41 +01001464 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001465
1466 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001467 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001468
1469 var octetstring l3 := '00010203040506'O
1470 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1471
1472 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
1473
1474 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +01001475 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001476 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001477 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001478}
1479
1480/* Test behavior if MSC answers with CREF to CR */
1481testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
1482 var BSSAP_N_CONNECT_ind rx_c_ind;
1483 var RSL_Message rx_rsl;
1484
Harald Welte89d42e82017-12-17 16:42:41 +01001485 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001486
1487 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001488 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001489
1490 var octetstring l3 := '00010203040506'O
1491 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1492
1493 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1494 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
1495
1496 /* expect BSC to disable the channel */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001497 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001498 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001499}
1500
Harald Welte618ef642017-12-14 14:58:20 +01001501/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
1502testcase TC_chan_act_nack() runs on test_CT {
1503 var RSL_Message rx_rsl;
1504 var integer chact_nack;
1505
Harald Welte89d42e82017-12-17 16:42:41 +01001506 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +01001507
1508 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
1509
1510 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
1511 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1512 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1513
1514 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
1515
1516 /* wait for some time to hope the NACK arrives before the CTRL GET below */
1517 f_sleep(0.5);
1518
1519 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
1520
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001521 f_shutdown_helper();
Harald Welte618ef642017-12-14 14:58:20 +01001522}
1523
Harald Welte799c97b2017-12-14 17:50:30 +01001524/* Test for channel exhaustion due to RACH overload */
1525testcase TC_chan_exhaustion() runs on test_CT {
1526 var ASP_RSL_Unitdata rsl_ud;
1527 var integer i;
1528 var integer chreq_total, chreq_nochan;
1529
Harald Welte89d42e82017-12-17 16:42:41 +01001530 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +01001531
1532 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
1533 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
1534
Neels Hofmeyr85fa37f2021-10-06 13:50:38 +02001535 /* GSM 44.018 Table 9.1.8.2:
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +01001536 * RA = '33'O -> Establishment cause = 0011xxxx (MS dual rate capable and asks for "TCH/H or TCH/F").
1537 * With current setup, expect 4xSDCCH + 4xTCH/F + 1xTCH/H to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +02001538 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 +01001539 var RslChannelNr chan_nr := f_chreq_act_ack('33'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +01001540 }
1541
1542 IPA_RSL[0].clear;
1543
Harald Weltedd8cbf32018-01-28 12:07:52 +01001544 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001545 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +01001546
1547 /* now expect additional channel activations to fail */
1548 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
1549
1550 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001551 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
Harald Welte799c97b2017-12-14 17:50:30 +01001552 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
1553 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001554 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
Harald Welte799c97b2017-12-14 17:50:30 +01001555 var GsmRrMessage rr;
1556 /* match on IMM ASS REJ */
1557 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
1558 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1559 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001560 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +01001561 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
1562 chreq_nochan+1);
1563 setverdict(pass);
1564 } else {
1565 repeat;
1566 }
1567 }
1568 [] IPA_RSL[0].receive { repeat; }
1569 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001570 f_shutdown_helper();
Harald Welte799c97b2017-12-14 17:50:30 +01001571}
1572
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001573/* Test channel deactivation due to silence from MS */
1574testcase TC_chan_deact_silence() runs on test_CT {
1575 var RslChannelNr chan_nr;
1576
1577 f_init(1);
1578
1579 /* Request for a dedicated channel */
1580 chan_nr := f_chreq_act_ack('23'O);
1581
1582 /* Wait some time until the channel is released */
1583 f_sleep(2.0);
1584
1585 /* Expect CHANnel RELease */
1586 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001587 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001588 log("Received CHANnel RELease");
1589 setverdict(pass);
1590 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001591 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001592 /* See OS#3709, OsmoBSC should not send Immediate
1593 * Assignment Reject since a dedicated channel was
1594 * already allocated, and Immediate Assignment was
1595 * already sent. */
1596 setverdict(fail, "Unexpected Immediate Assignment!");
1597 }
1598 [] IPA_RSL[0].receive {
1599 setverdict(fail, "Unexpected RSL message!");
1600 }
1601 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001602 f_shutdown_helper();
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001603}
1604
Harald Weltecfe2c962017-12-15 12:09:32 +01001605/***********************************************************************
1606 * Assignment Testing
1607 ***********************************************************************/
1608
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001609/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction,
1610 * except for the inter-BSC handover, MT side) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001611testcase TC_outbound_connect(integer bssap_idx := 0) runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +01001612 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +01001613
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001614 BSSAP.send(ts_BSSAP_CONNECT_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
1615 2342, ts_BSSMAP_AssignmentReq));
Harald Weltecfe2c962017-12-15 12:09:32 +01001616 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001617 f_shutdown_helper();
Harald Weltecfe2c962017-12-15 12:09:32 +01001618}
1619
Harald Welte16a4adf2017-12-14 18:54:01 +01001620/* Test behavior if MSC answers with CREF to CR */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001621testcase TC_assignment_cic_only(integer bssap_idx := 0) runs on test_CT {
Harald Welte16a4adf2017-12-14 18:54:01 +01001622 var BSSAP_N_CONNECT_ind rx_c_ind;
1623 var RSL_Message rx_rsl;
1624 var DchanTuple dt;
1625
Harald Welte89d42e82017-12-17 16:42:41 +01001626 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +01001627
1628 dt := f_est_dchan('23'O, 23, '00000000'O);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001629 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte17b27da2018-05-25 20:33:53 +02001630 /* send assignment without AoIP IEs */
1631 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
1632 } else {
1633 /* Send assignmetn without CIC in IPA case */
1634 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
1635 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
1636 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
1637 }
Harald Welte16a4adf2017-12-14 18:54:01 +01001638 alt {
1639 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1640 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
1641 }
Harald Welte235ebf12017-12-15 14:18:16 +01001642 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +01001643 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1644 setverdict(pass);
1645 }
1646 [] BSSAP.receive { repeat; }
1647 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001648 f_perform_clear_test_ct(dt);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001649 f_shutdown_helper();
Harald Welte16a4adf2017-12-14 18:54:01 +01001650}
1651
Harald Welteed848512018-05-24 22:27:58 +02001652/* generate an assignment request for either AoIP or SCCPlite */
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001653function 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 +02001654 var PDU_BSSAP ass_cmd;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001655 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001656 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welteed848512018-05-24 22:27:58 +02001657 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001658 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001659 if (osmux_enabled) {
1660 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla, osmux_cid));
1661 } else {
1662 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
1663 }
Harald Welteed848512018-05-24 22:27:58 +02001664 } else {
1665 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001666 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
Harald Welteed848512018-05-24 22:27:58 +02001667 }
1668 return ass_cmd;
1669}
1670
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02001671function f_gen_handover_req(integer bssap_idx := 0, charstring aoip_tla := "1.2.3.4",
Pau Espin Pedrola8ef3be2022-02-16 16:21:17 +01001672 template (value) BSSMAP_IE_CellIdentifier cell_id_source := ts_CellID_LAC_CI(1, 1),
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001673 template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit,
1674 template (omit) TestHdlrEncrParams enc := omit) return PDU_BSSAP {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001675 var PDU_BSSAP ho_req;
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001676
1677 var BSSMAP_IE_EncryptionInformation encryptionInformation :=
1678 valueof(ts_BSSMAP_IE_EncrInfo('0000000000000000'O,'01'O));
Vadim Yanitskiy35c9a332022-03-16 20:26:35 +03001679 var template (omit) BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm := omit;
1680 var template (omit) BSSMAP_IE_KC128 kc128 := omit;
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001681 if (ispresent(enc)) {
1682 var TestHdlrEncrParams v_enc := valueof(enc);
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01001683 encryptionInformation := valueof(ts_BSSMAP_IE_EncrInfo(v_enc.enc_key, v_enc.enc_alg_permitted));
1684 if (ispresent(v_enc.enc_alg_chosen)) {
1685 chosenEncryptionAlgorithm := valueof(
1686 ts_BSSMAP_IE_ChosenEncryptionAlgorithm(int2oct(enum2int(
1687 f_cipher_mode_bssmap_to_rsl(v_enc.enc_alg_chosen)), 1)));
1688 }
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001689 if (ispresent(v_enc.enc_kc128)) {
1690 kc128 := ts_BSSMAP_IE_Kc128(v_enc.enc_kc128);
1691 }
1692 }
1693
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001694 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001695 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001696 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Pau Espin Pedrola8ef3be2022-02-16 16:21:17 +01001697 ho_req := valueof(ts_BSSMAP_HandoverRequest(omit, tla,
1698 cell_id_source := cell_id_source,
1699 oldToNewBSSIEs := oldToNewBSSIEs,
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001700 encryptionInformation := encryptionInformation,
1701 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
Neels Hofmeyr9fe13202022-03-04 00:05:43 +01001702 kC128 := kc128,
1703 /* on AoIP, allow "all" codecs (until we add more concise
1704 * tests) */
1705 codecList := ts_BSSMAP_IE_CodecList(
1706 {ts_CodecAMR_F, ts_CodecAMR_H,
1707 ts_CodecEFR, ts_CodecFR, ts_CodecHR})));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001708 } else {
1709 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrola8ef3be2022-02-16 16:21:17 +01001710 ho_req := valueof(ts_BSSMAP_HandoverRequest(cic, omit,
1711 cell_id_source := cell_id_source,
1712 oldToNewBSSIEs := oldToNewBSSIEs,
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001713 encryptionInformation := encryptionInformation,
1714 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
1715 kC128 := kc128));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001716 }
1717 return ho_req;
1718}
1719
Harald Welteed848512018-05-24 22:27:58 +02001720/* generate an assignment complete template for either AoIP or SCCPlite */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001721function f_gen_exp_compl(boolean expect_osmux := false, integer bssap_idx := 0) return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +02001722 var template PDU_BSSAP exp_compl;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001723 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001724 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001725 if (expect_osmux) {
1726 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, osmux_cid);
1727 } else {
1728 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, omit);
1729 }
Harald Welteed848512018-05-24 22:27:58 +02001730 } else {
1731 /* CIC is optional "*" as the MSC allocated it */
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001732 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
Harald Welteed848512018-05-24 22:27:58 +02001733 }
1734 return exp_compl;
1735}
1736
Harald Welte235ebf12017-12-15 14:18:16 +01001737/* Run everything required up to sending a caller-specified assignment command and expect response */
1738function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001739runs on test_CT return DchanTuple {
Harald Welte235ebf12017-12-15 14:18:16 +01001740 var BSSAP_N_CONNECT_ind rx_c_ind;
1741 var RSL_Message rx_rsl;
1742 var DchanTuple dt;
1743
Harald Welte89d42e82017-12-17 16:42:41 +01001744 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +01001745
1746 dt := f_est_dchan('23'O, 23, '00000000'O);
1747 /* send assignment without AoIP IEs */
1748 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
1749 alt {
1750 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1751 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
1752 setverdict(pass);
1753 } else {
1754 setverdict(fail, fail_text);
1755 }
1756 }
1757 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1758 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
1759 setverdict(pass);
1760 } else {
1761 setverdict(fail, fail_text);
1762 }
1763 }
1764 [] BSSAP.receive { repeat; }
1765 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001766 return dt;
Harald Welte235ebf12017-12-15 14:18:16 +01001767}
1768testcase TC_assignment_csd() runs on test_CT {
1769 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001770 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001771 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1772 //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 +01001773 var DchanTuple dt := f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
1774 f_perform_clear_test_ct(dt);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001775 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001776}
1777
1778testcase TC_assignment_ctm() runs on test_CT {
1779 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001780 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001781 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
1782 //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 +01001783 var DchanTuple dt := f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
1784 f_perform_clear_test_ct(dt);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001785 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001786}
1787
Harald Welte4003d112017-12-09 22:35:39 +01001788type record DchanTuple {
1789 integer sccp_conn_id,
1790 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +01001791}
1792
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +02001793type record of DchanTuple DchanTuples;
1794
Harald Welted6939652017-12-13 21:02:46 +01001795/* Send CHAN RQD and wait for allocation; acknowledge it */
1796private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
1797runs on test_CT return RslChannelNr {
1798 var RSL_Message rx_rsl;
1799 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1800 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1801 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1802 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
Daniel Willmannf4ac4ce2018-08-02 14:06:30 +02001803 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Harald Welted6939652017-12-13 21:02:46 +01001804 return chan_nr;
1805}
1806
Harald Welte4003d112017-12-09 22:35:39 +01001807/* helper function to establish a dedicated channel via BTS and MSC */
1808function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1809runs on test_CT return DchanTuple {
1810 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +01001811 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001812
Harald Welte4003d112017-12-09 22:35:39 +01001813 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001814 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +01001815
1816 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1817
1818 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1819 dt.sccp_conn_id := rx_c_ind.connectionId;
1820 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1821
1822 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001823}
1824
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02001825/* Like f_est_dchan(), but for the first lchan of a dynamic timeslot: first ACK the deactivation of PDCH. */
1826function f_est_dchan_dyn(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1827runs on test_CT return DchanTuple {
1828 var BSSAP_N_CONNECT_ind rx_c_ind;
1829 var DchanTuple dt;
1830
1831 /* Send CHAN RQD */
1832 var RSL_Message rx_rsl;
1833 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1834
1835 /* The dyn TS first deactivates PDCH */
1836 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1837 dt.rsl_chan_nr := rx_rsl.ies[0].body.chan_nr;
1838 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1839
1840 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1841 dt.rsl_chan_nr := rx_rsl.ies[0].body.chan_nr;
1842
1843 /* Now activates the signalling channel */
1844 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, fn+10));
1845 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
1846
1847 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1848
1849 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1850 dt.sccp_conn_id := rx_c_ind.connectionId;
1851 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1852
1853 return dt;
1854}
1855
Harald Welte641fcbe2018-06-14 10:58:35 +02001856/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
1857private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
1858 var RSL_Message rx_rsl;
1859 /* expect BSC to disable the channel */
1860 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1861 /* respond with CHAN REL ACK */
1862 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1863
1864 /* expect Clear Complete from BSC */
1865 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1866
1867 /* MSC disconnects as instructed. */
1868 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1869}
1870
Harald Welte4003d112017-12-09 22:35:39 +01001871/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
1872testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001873 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001874 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +01001875
Harald Welte89d42e82017-12-17 16:42:41 +01001876 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +01001877
Harald Welte4003d112017-12-09 22:35:39 +01001878 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1879
1880 /* simulate RLL REL IND */
1881 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
1882
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001883 /* expect Clear Request on MSC side */
1884 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1885
1886 /* Instruct BSC to clear channel */
1887 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1888 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1889
Harald Welte4003d112017-12-09 22:35:39 +01001890 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001891 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001892
1893 /* wait for SCCP emulation to do its job */
1894 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +01001895
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001896 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001897}
1898
1899/* Test behavior of channel release after CONN FAIL IND from BTS */
1900testcase TC_chan_rel_conn_fail() runs on test_CT {
1901 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001902 var DchanTuple dt;
1903
Harald Welte89d42e82017-12-17 16:42:41 +01001904 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001905
1906 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1907
1908 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +01001909 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 +01001910 /* TODO: different cause values? */
1911
Harald Welte4003d112017-12-09 22:35:39 +01001912 /* expect Clear Request from BSC */
1913 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1914
1915 /* Instruct BSC to clear channel */
1916 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1917 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1918
Harald Welte6ff76ea2018-01-28 13:08:01 +01001919 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001920 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +01001921
1922 /* wait for SCCP emulation to do its job */
1923 f_sleep(1.0);
1924
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001925 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001926}
1927
Harald Welte99f3ca02018-06-14 13:40:29 +02001928/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
1929/* See also https://www.osmocom.org/issues/3182 */
1930testcase TC_early_conn_fail() runs on test_CT {
1931 var RSL_Message rx_rsl;
1932 var DchanTuple dt;
1933
1934 f_init(1);
1935
1936 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
Harald Weltec46ea3c2020-10-10 18:46:12 +02001937 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_ra_cs(), 23);
Harald Welte99f3ca02018-06-14 13:40:29 +02001938
1939 /* BTS->BSC: simulate CONN FAIL IND */
1940 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1941
1942 /* BTS->BSC: Expect RF channel release from BSC on Abis */
1943 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1944
1945 /* BTS<-BSC: respond with CHAN REL ACK */
1946 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1947
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001948 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001949}
1950
1951/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
1952/* See also https://www.osmocom.org/issues/3182 */
1953testcase TC_late_conn_fail() runs on test_CT {
1954 var RSL_Message rx_rsl;
1955 var DchanTuple dt;
1956
1957 f_init(1);
1958
1959 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1960
1961 /* BSC<-MSC: Instruct BSC to clear connection */
1962 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
1963
1964 /* BTS->BSC: expect BSC to deactivate SACCH */
1965 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
1966
1967 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
1968 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1969
1970 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
1971 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1972 /* BTS->BSC: respond with CHAN REL ACK */
1973 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1974
1975 /* BSC->MSC: expect Clear Complete from BSC */
1976 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1977
1978 /* BSC<-MSC: MSC disconnects as requested. */
1979 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1980
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001981 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001982}
1983
Oliver Smithaf03bef2021-08-24 15:34:51 +02001984private function f_TC_stats_conn_fail(charstring id) runs on MSC_ConnHdlr {
1985 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
1986 var PDU_BSSAP ass_cmd := f_gen_ass_req();
1987
1988 f_statsd_reset();
1989
1990 /* Establish SDCCH */
1991 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1992 f_establish_fully(ass_cmd, exp_fail);
1993
1994 /* Expect stats to be 0 */
1995 var StatsDExpects expect := {
1996 {name := "TTCN3.bts.0.chan.rf_fail", mtype := "c", min := 0, max := 0},
1997 {name := "TTCN3.bts.0.chan.rf_fail_sdcch", mtype := "c", min := 0, max := 0}
1998 };
1999 f_statsd_expect(expect);
2000
2001 /* Simulate CONN FAIL IND on SDCCH */
2002 RSL.send(ts_ASP_RSL_UD(
2003 ts_RSL_CONN_FAIL_IND(g_chan_nr, RSL_ERR_RADIO_LINK_FAIL),
2004 IPAC_PROTO_RSL_TRX0));
2005
Neels Hofmeyr58be48a2021-09-07 18:39:21 +02002006 f_sleep(1.0);
2007
Oliver Smithaf03bef2021-08-24 15:34:51 +02002008 /* Expect stats to be 1 */
2009 expect := {
2010 {name := "TTCN3.bts.0.chan.rf_fail", mtype := "c", min := 1, max := 1},
2011 {name := "TTCN3.bts.0.chan.rf_fail_sdcch", mtype := "c", min := 1, max := 1}
2012 };
2013 f_statsd_expect(expect);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01002014 BSSAP.receive(tr_BSSMAP_ClearRequest);
2015 f_perform_clear();
Oliver Smithaf03bef2021-08-24 15:34:51 +02002016}
2017testcase TC_stats_conn_fail() runs on test_CT {
2018 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2019 var MSC_ConnHdlr vc_conn;
2020
2021 f_init(1, true);
2022 f_sleep(1.0);
2023
2024 vc_conn := f_start_handler(refers(f_TC_stats_conn_fail), pars);
2025 vc_conn.done;
2026
2027 f_shutdown_helper();
2028}
2029
Neels Hofmeyrf44ccd12018-11-05 19:15:23 +01002030function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr,
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002031 boolean expect_deact_sacch := true,
2032 boolean expect_rr_chan_rel := true,
2033 boolean expect_rll_rel_req := true,
Harald Welte99787102019-02-04 10:41:36 +01002034 boolean handle_rll_rel := true,
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002035 template CellSelIndValue expect_cells := omit,
Vadim Yanitskiybc7c35a2022-03-16 19:50:06 +03002036 template (present) RR_Cause expect_rr_cause := ?
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002037 ) runs on test_CT {
Harald Welte91d54a52018-01-28 15:35:07 +01002038
2039 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002040 var boolean got_deact_sacch := false;
2041 var boolean got_rr_chan_rel := false;
2042 var boolean got_rll_rel_req := false;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002043 var ASP_RSL_Unitdata ud;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002044 var RSL_IE_Body l3_ie;
2045 var PDU_ML3_NW_MS l3;
2046 var RR_Cause got_cause;
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002047 log("f_expect_chan_rel() expecting: expect_deact_sacch=", expect_deact_sacch, " expect_rr_chan_rel=", expect_rr_chan_rel,
2048 " expect_rll_rel_req=", expect_rll_rel_req);
Harald Welte91d54a52018-01-28 15:35:07 +01002049 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002050 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002051 got_deact_sacch := true;
Harald Welte91d54a52018-01-28 15:35:07 +01002052 repeat;
2053 }
Vadim Yanitskiya25fe232022-03-16 19:56:19 +03002054 [] 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 +01002055 got_rr_chan_rel := true;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002056
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002057 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
2058 setverdict(fail, "cannot find L3");
2059 mtc.stop;
2060 }
2061 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
2062
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002063 if (not istemplatekind(expect_cells, "omit")) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002064 var CellSelIndValue cells := dec_CellSelIndValue(
2065 l3.msgs.rrm.channelRelease.cellSelectionIndicator.cellSelectionIndicatorValue);
2066
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002067 log("GOT RR CHANNEL RELEASE WITH CELLS: ", cells);
2068 if (match(cells, expect_cells)) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002069 setverdict(pass);
2070 } else {
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002071 log("EXPECTED CELLS: ", expect_cells);
2072 setverdict(fail, "Received cells list on RR Channel Release does not match expectations");
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002073 }
2074 }
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002075
Vadim Yanitskiybc7c35a2022-03-16 19:50:06 +03002076 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
2077 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
2078 if (match(got_cause, expect_rr_cause)) {
2079 setverdict(pass);
2080 } else {
2081 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
2082 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002083 }
Harald Welte99787102019-02-04 10:41:36 +01002084 repeat;
2085 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002086 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002087 got_rll_rel_req := true;
Harald Welte91d54a52018-01-28 15:35:07 +01002088 /* FIXME: Why are we getting this for LinkID SACCH? */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002089 if (handle_rll_rel) {
2090 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
2091 }
Harald Welte91d54a52018-01-28 15:35:07 +01002092 repeat;
2093 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002094 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Harald Welte91d54a52018-01-28 15:35:07 +01002095 /* respond with CHAN REL ACK */
2096 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
2097 }
2098 /* ignore any user data */
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002099 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeR(?))) {
Harald Welte91d54a52018-01-28 15:35:07 +01002100 repeat;
2101 }
2102 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002103
2104 log("f_expect_chan_rel() summary: got_deact_sacch=", got_deact_sacch, " got_rr_chan_rel=", got_rr_chan_rel,
2105 " got_rll_rel_req=", got_rll_rel_req);
2106
2107 if (expect_deact_sacch != got_deact_sacch) {
2108 setverdict(fail, "f_expect_chan_rel(): expect_deact_sacch=", expect_deact_sacch, " got_deact_sacch=", got_deact_sacch);
2109 }
2110 if (expect_rr_chan_rel != got_rr_chan_rel) {
2111 setverdict(fail, "f_expect_chan_rel(): expect_rr_chan_rel=", expect_rr_chan_rel, " got_rr_chan_rel=", got_rr_chan_rel);
2112 }
2113 if (expect_rll_rel_req != got_rll_rel_req) {
2114 setverdict(fail, "f_expect_chan_rel(): expect_rll_rel_req=", expect_rll_rel_req, " got_rll_rel_req=", got_rll_rel_req);
2115 }
Harald Welte91d54a52018-01-28 15:35:07 +01002116}
2117
Harald Welte4003d112017-12-09 22:35:39 +01002118/* Test behavior of channel release after hard Clear Command from MSC */
2119testcase TC_chan_rel_hard_clear() runs on test_CT {
2120 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01002121 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +01002122
Harald Welte89d42e82017-12-17 16:42:41 +01002123 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002124
2125 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2126
2127 /* Instruct BSC to clear channel */
2128 var BssmapCause cause := 0;
2129 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2130
2131 /* expect Clear Complete from BSC on A */
2132 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2133 /* release the SCCP connection */
2134 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2135 }
2136
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002137 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002138 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002139}
2140
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002141function f_TC_chan_rel_last_eutran_plmn_hard_clear(boolean tx_csfb_ind) runs on test_CT {
2142 var BSSAP_N_DATA_ind rx_di;
2143 var DchanTuple dt;
2144
2145 f_init(1);
2146
2147 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2148 /* Send CommonID with some random PLMN (BSC doesn't take it into account
2149 /* yet when generating the EUTRAN neigh list in RR CHannel Release) */
2150 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
2151
2152 /* Instruct BSC to clear channel */
2153 var BssmapCause cause := 0;
2154 if (tx_csfb_ind) {
2155 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2156 } else {
2157 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2158 }
2159
2160 /* expect Clear Complete from BSC on A */
2161 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2162 /* release the SCCP connection */
2163 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2164 }
2165
2166 /* 1 neighbor is added by default in osmo-bts.cfg and
2167 SystemInformationConfig_default, use that: */
2168 var template CellSelIndValue exp_cells := f_tr_rr_chan_rel_earfcns(1);
2169
2170 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, expect_cells := exp_cells);
2171 f_shutdown_helper();
2172}
2173
2174/* Test behavior of RR Channel rRelease after Clear Command without CSFB indicator
2175 from MSC, previously receiving any CommonID containing the "Last Used E-UTRAN
2176 PLMN Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
2177 EUTRAN neighbor list sent later on by BSC in RR Channel, so receiving CSFB
2178 Indicator or not shouldn't matter at all. */
2179testcase TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() runs on test_CT {
2180 f_TC_chan_rel_last_eutran_plmn_hard_clear(false);
2181}
2182
2183/* Test behavior of RR Channel rRelease after Clear Command with CSFB indicator from
2184 MSC, previously receiving any CommonID containing the "Last Used E-UTRAN PLMN
2185 Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
2186 EUTRAN neighbor list sent later on by BSC in RR Channel. */
2187testcase TC_chan_rel_last_eutran_plmn_hard_clear_csfb() runs on test_CT {
2188 f_TC_chan_rel_last_eutran_plmn_hard_clear(true);
2189}
2190
2191/* Test behavior of RR Channel Release after Clear Command with CSFB indicator from
2192 MSC, without receiving any CommonID containing the "Last Used E-UTRAN PLMN
2193 Id". According to spec (TS 48.008 version 16.0.0 Release 16 "3.2.1.21") the
2194 CSFB Indicator should not be used anymore, and hence, there should be no
2195 EUTRAN neighbor list sent by BSC in RR Channel release since no CommonId with
2196 Last Used E-UTRAN PLMN Id" IE was sent for this conn. */
Harald Welte99787102019-02-04 10:41:36 +01002197testcase TC_chan_rel_hard_clear_csfb() runs on test_CT {
2198 var BSSAP_N_DATA_ind rx_di;
2199 var DchanTuple dt;
2200
2201 f_init(1);
2202
2203 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2204
2205 /* Instruct BSC to clear channel */
2206 var BssmapCause cause := 0;
2207 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2208
2209 /* expect Clear Complete from BSC on A */
2210 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2211 /* release the SCCP connection */
2212 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2213 }
2214
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002215 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002216 f_shutdown_helper();
Harald Welte99787102019-02-04 10:41:36 +01002217}
2218
Harald Welted8c36cd2017-12-09 23:05:31 +01002219/* Test behavior of channel release after hard RLSD from MSC */
2220testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +01002221 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +01002222
Harald Welte89d42e82017-12-17 16:42:41 +01002223 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +01002224
2225 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2226
2227 /* release the SCCP connection */
2228 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2229
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002230 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002231 f_shutdown_helper();
Harald Welted8c36cd2017-12-09 23:05:31 +01002232}
2233
Harald Welte550daf92018-06-11 19:22:13 +02002234/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
2235testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
2236 var DchanTuple dt;
2237
2238 f_init(1);
2239
2240 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2241
2242 /* release the SCCP connection */
2243 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2244
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002245 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002246 f_shutdown_helper();
Harald Welte550daf92018-06-11 19:22:13 +02002247}
2248
Harald Welte85804d42017-12-10 14:11:58 +01002249/* Test behavior of channel release after BSSMAP RESET from MSC */
2250testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +01002251 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +01002252
Harald Welte89d42e82017-12-17 16:42:41 +01002253 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +01002254
2255 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2256
2257 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
2258 IPA_RSL[0].clear;
2259
2260 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002261 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 +01002262 interleave {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002263 [] 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 +01002264 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
2265 }
2266
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002267 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002268 f_shutdown_helper();
Harald Welte85804d42017-12-10 14:11:58 +01002269}
2270
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002271/* Verify T(iar) triggers and releases the channel */
2272testcase TC_chan_rel_sccp_tiar_timeout() runs on test_CT {
2273 var DchanTuple dt;
2274
2275 /* Set T(iar) in BSC low enough that it will trigger before other side
2276 has time to keep alive with a T(ias). Keep recommended ratio of
2277 T(iar) >= T(ias)*2 */
2278 g_bsc_sccp_timer_ias := 2;
2279 g_bsc_sccp_timer_iar := 5;
2280
2281 f_init(1);
2282
2283 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2284 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002285 f_shutdown_helper();
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002286}
2287
Vadim Yanitskiybc7c35a2022-03-16 19:50:06 +03002288private function f_tc_chan_rel_rr_cause(myBSSMAP_Cause clear_cmd_cause,
2289 template (present) RR_Cause expect_rr_cause)
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002290runs on test_CT
2291{
2292 var DchanTuple dt;
2293
2294 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2295 var BssmapCause cause := 0;
2296 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(enum2int(clear_cmd_cause))));
2297 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2298 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2299 }
2300
2301 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 +02002302}
2303
2304/* Test that Clear Command cause codes affect the RR Channel Release cause code */
2305testcase TC_chan_rel_rr_cause() runs on test_CT {
2306 f_init(1);
2307
2308 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_CALL_CONTROL, GSM48_RR_CAUSE_NORMAL);
2309 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_HANDOVER_SUCCESSFUL, GSM48_RR_CAUSE_NORMAL);
2310 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_PREEMPTION, GSM48_RR_CAUSE_PREMPTIVE_REL);
2311 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE, GSM48_RR_CAUSE_PROT_ERROR_UNSPC);
2312 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
2313 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_EQUIPMENT_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
Vadim Yanitskiye18aebb2021-01-03 13:10:43 +01002314
2315 f_shutdown_helper();
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002316}
2317
Harald Welte5cd20ed2017-12-13 21:03:20 +01002318/* Test behavior if RSL EST IND for non-active channel */
2319testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
2320 timer T := 2.0;
2321
Harald Welte89d42e82017-12-17 16:42:41 +01002322 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002323
2324 var octetstring l3 := '00010203040506'O;
2325 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2326 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
2327
2328 T.start;
2329 alt {
2330 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2331 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
2332 }
2333 [] BSSAP.receive {}
2334 [] IPA_RSL[0].receive {}
2335 [] T.timeout {}
2336 }
2337
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002338 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002339}
2340
2341/* Test behavior if RSL EST IND for invalid SAPI */
2342testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
2343 var RslChannelNr chan_nr;
2344
Harald Welte89d42e82017-12-17 16:42:41 +01002345 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002346
2347 chan_nr := f_chreq_act_ack()
2348
2349 var octetstring l3 := '00010203040506'O;
2350 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
2351
2352 timer T := 2.0;
2353 T.start;
2354 alt {
2355 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2356 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
2357 }
2358 [] BSSAP.receive { repeat; }
2359 [] IPA_RSL[0].receive { repeat; }
2360 [] T.timeout {}
2361 }
2362
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002363 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002364}
2365
2366/* Test behavior if RSL EST IND for invalid SAPI */
2367testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
2368 timer T := 2.0;
2369
Harald Welte89d42e82017-12-17 16:42:41 +01002370 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002371
2372 var RslChannelNr chan_nr := f_chreq_act_ack();
2373
2374 var octetstring l3 := '00010203040506'O;
2375 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
2376
2377 T.start;
2378 alt {
2379 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2380 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
2381 }
2382 [] BSSAP.receive { repeat; }
2383 [] IPA_RSL[0].receive { repeat; }
2384 [] T.timeout {}
2385 }
2386
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002387 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002388}
2389
2390/* Test behavior if RSL EST IND for invalid SACCH */
2391testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
2392 timer T := 2.0;
2393
Harald Welte89d42e82017-12-17 16:42:41 +01002394 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002395
2396 var RslChannelNr chan_nr := f_chreq_act_ack();
2397
2398 var octetstring l3 := '00010203040506'O;
2399 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
2400
2401 T.start;
2402 alt {
2403 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2404 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
2405 }
2406 [] BSSAP.receive { repeat; }
2407 [] IPA_RSL[0].receive { repeat; }
2408 [] T.timeout {}
2409 }
2410
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002411 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002412}
2413
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002414/* Verify DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
2415private function f_TC_tch_dlci_link_id_sapi(charstring id) runs on MSC_ConnHdlr {
2416 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2417 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2418
2419 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2420 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2421
2422 f_establish_fully(ass_cmd, exp_compl);
2423
2424 /* SAPI0 has already been established by f_establish_fully(), establish SAPI3 */
2425 RSL.send(ts_RSL_EST_IND(g_chan_nr, ts_RslLinkID_SACCH(3), '0904'O));
2426 /* Expect BSSAP/DTAP on SAPI3 (DLCI IE) */
2427 BSSAP.receive(PDU_BSSAP:{
2428 discriminator := '1'B,
2429 spare := '0000000'B,
2430 dlci := 'C3'O,
2431 lengthIndicator := ?,
2432 pdu := { dtap := '0904'O }
2433 });
2434
2435 /* Send messages on DCCH/SAPI0 and ACCH/SAPI3 */
2436 for (var integer i := 0; i < 32; i := i + 1) {
2437 var octetstring l3 := '09'O & f_rnd_octstring(14);
2438 var template (value) RslLinkId link_id;
2439 var template (value) OCT1 dlci;
2440
2441 if (i mod 2 == 0) {
2442 /* SAPI0 on FACCH or SDCCH */
2443 link_id := ts_RslLinkID_DCCH(0);
2444 dlci := '80'O;
2445 } else {
2446 /* SAPI3 on SACCH */
2447 link_id := ts_RslLinkID_SACCH(3);
2448 dlci := 'C3'O;
2449 }
2450
2451 /* Send MO message: RSL -> BSSAP */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002452 f_mo_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002453 /* Send MT message: BSSAP -> RSL */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002454 f_mt_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002455 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01002456 f_perform_clear();
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002457}
2458testcase TC_tch_dlci_link_id_sapi() runs on test_CT {
2459 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2460 var MSC_ConnHdlr vc_conn;
2461
2462 f_init(1, true);
2463 f_sleep(1.0);
2464
2465 vc_conn := f_start_handler(refers(f_TC_tch_dlci_link_id_sapi), pars);
2466 vc_conn.done;
2467
2468 f_shutdown_helper();
2469}
2470
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002471private function f_exp_sapi_n_reject(template (present) GsmSapi sapi := ?,
Vadim Yanitskiy35c9a332022-03-16 20:26:35 +03002472 template (present) myBSSMAP_Cause cause := ?,
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002473 template (present) BIT2 cc := ?,
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002474 float T_val := 2.0)
2475runs on test_CT {
2476 var BSSAP_N_DATA_ind rx_di;
2477 timer T;
2478
Vadim Yanitskiy35c9a332022-03-16 20:26:35 +03002479 var template (present) BSSMAP_IE_Cause tr_cause := tr_BSSMAP_IE_Cause(cause);
2480 var template (present) PDU_BSSAP tr_pdu := tr_BSSMAP_SAPInReject(sapi);
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002481
2482 T.start(T_val);
2483 alt {
2484 [] BSSAP.receive(tr_BSSAP_DATA_ind(?, tr_pdu)) -> value rx_di {
2485 var BSSMAP_IE_Cause rx_cause := rx_di.userData.pdu.bssmap.sAPInReject.cause;
2486 if (not match(rx_cause, tr_cause)) {
2487 setverdict(fail, "Rx unexpected Cause IE: ",
2488 rx_cause, " vs expected ", tr_cause);
2489 }
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002490
2491 /* Who ever on the earth decided to define this field as two separate bits?!? */
2492 var BIT2 rx_cc := rx_di.userData.pdu.bssmap.sAPInReject.dLCI.c2
2493 & rx_di.userData.pdu.bssmap.sAPInReject.dLCI.c1;
2494 if (not match(rx_cc, cc)) {
2495 setverdict(fail, "Rx unexpected Control Channel type: ",
2496 rx_cc, " vs expected ", cc);
2497 }
2498
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002499 setverdict(pass);
2500 }
2501 [] BSSAP.receive(BSSAP_N_DATA_ind:?) -> value rx_di {
2502 setverdict(fail, "Rx unexpected BSSAP PDU: ", rx_di);
2503 }
2504 [] T.timeout {
2505 setverdict(fail, "Timeout waiting for BSSMAP SAPI N Reject");
2506 }
2507 }
2508}
2509
2510/* Check if we get SAPI N Reject on receipt of unexpected RLL RELease INDication */
2511testcase TC_rll_rel_ind_sapi_n_reject() runs on test_CT {
2512 var octetstring rnd_data := f_rnd_octstring(16);
2513 var RSL_Message rx_rsl;
2514 var DchanTuple dt;
2515
2516 f_init(1);
2517
2518 /* MS establishes a SAPI=0 link on DCCH */
2519 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2520
2521 /* MSC sends some data on (not yet established) SAPI=3 link */
2522 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2523 /* BSC attempts to establish a SAPI=3 link on DCCH */
2524 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2525
2526 /* MS sends unexpected RELease INDication on SAPI=3 */
2527 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3)));
2528 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2529 f_exp_sapi_n_reject(3, GSM0808_CAUSE_MS_NOT_EQUIPPED);
2530
2531 /* Clean up the connection */
2532 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2533 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2534
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002535 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002536}
2537
2538/* Check if we get SAPI N Reject on receipt of unexpected RLL ERROR INDication */
2539testcase TC_rll_err_ind_sapi_n_reject() runs on test_CT {
2540 var octetstring rnd_data := f_rnd_octstring(16);
2541 var RSL_Message rx_rsl;
2542 var DchanTuple dt;
2543
2544 f_init(1);
2545
2546 /* MS establishes a SAPI=0 link on DCCH */
2547 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2548
2549 /* MSC sends some data on (not yet established) SAPI=3 link */
2550 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2551 /* BSC attempts to establish a SAPI=3 link on DCCH */
2552 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2553
2554 /* BTS sends unexpected ERROR INDication on SAPI=3 */
2555 f_ipa_tx(0, ts_RSL_ERROR_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3), ''O));
2556 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2557 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED);
2558
2559 /* Clean up the connection */
2560 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2561 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2562
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002563 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002564}
2565
2566/* Check if we get SAPI N Reject due to a SAPI=3 link establishment timeout */
2567testcase TC_rll_timeout_sapi_n_reject() runs on test_CT {
2568 var octetstring rnd_data := f_rnd_octstring(16);
2569 var RSL_Message rx_rsl;
2570 var DchanTuple dt;
2571
2572 f_init(1);
2573
2574 /* MS establishes a SAPI=0 link on DCCH */
2575 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2576
2577 /* MSC sends some data on (not yet established) SAPI=3 link */
2578 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2579 /* BSC attempts to establish a SAPI=3 link on DCCH */
2580 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2581
2582 /* MS does not respond, so the link establishment timeout triggers SAPI N Reject */
2583 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED, T_val := 8.0);
2584
2585 /* Clean up the connection */
2586 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2587 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2588
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002589 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002590}
2591
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002592/* Check DLCI CC (Control Channel type) bits in SAPI N Reject */
2593testcase TC_rll_sapi_n_reject_dlci_cc() runs on test_CT {
2594 var octetstring rnd_data := f_rnd_octstring(16);
2595 var RSL_Message rx_rsl;
2596 var DchanTuple dt;
2597
2598 f_init(1);
2599
2600 /* MS establishes a SAPI=0 link on DCCH */
2601 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2602
2603 /* MSC sends some data on (not yet established) SAPI=3 link */
2604 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2605 /* BSC attempts to establish a SAPI=3 link on DCCH */
2606 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2607
2608 /* MS sends unexpected ERROR INDication on DCCH/ACCH SAPI=3 */
2609 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 +01002610 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED, '10'B);
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002611
2612 /* Clean up the connection */
2613 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2614 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2615
2616 f_shutdown_helper();
2617}
2618
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002619testcase TC_si_default() runs on test_CT {
2620 f_init(0);
2621 f_init_bts_and_check_sysinfo(0, expect_si := SystemInformationConfig_default);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002622 f_shutdown_helper();
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002623}
Harald Welte4003d112017-12-09 22:35:39 +01002624
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002625/* We're testing SI2quater with lists of EARFCNs. Instead of just incrementing EARFCNs, also pick some from the edges of
2626 * the entire value range. This function provides the same EARFCN numbers for the same earfcn_index */
2627private function f_test_si2quater_earfcn_by_idx(integer earfcn_index) return uint16_t
2628{
2629 select (earfcn_index) {
2630 case (0) {
2631 /* E-ARFCN 111 is already added in the osmo-bsc.cfg */
2632 return 111;
2633 }
2634 case (1) {
2635 return 1;
2636 }
2637 case (2) {
2638 return 0;
2639 }
2640 case (3) {
2641 return 65535;
2642 }
2643 case else {
2644 return 23 * (earfcn_index - 3);
2645 }
2646 }
2647}
2648
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002649function f_test_si2quater(integer total_earfcns, template SystemInformationConfig expect_si,
2650 template CellSelIndValue expect_cells := omit) runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002651
2652 f_init(0);
2653
2654 /* E-ARFCN 111 is already added in the osmo-bsc.cfg, so only add more arfcns if total_earfcns > 1 */
2655 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002656 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2657 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002658 }
2659
2660 f_init_bts_and_check_sysinfo(0, expect_si := expect_si);
2661
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002662 if (not istemplatekind(expect_cells, "omit")) {
2663 /* Also check that RR Channel Release contains these EARFCNs.
2664 * (copied code from TC_chan_rel_hard_clear_csfb) */
2665 var BSSAP_N_DATA_ind rx_di;
2666 var DchanTuple dt;
2667
2668 dt := f_est_dchan('23'O, 23, '00010203040506'O);
Pau Espin Pedrold0046312021-04-19 16:35:58 +02002669 /* Send CommonID with some random PLMN (BSC doesn't take it into account
2670 * yet when generating the EUTRAN neigh list in RR CHannel Release) */
2671 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002672
2673 /* Instruct BSC to clear channel */
2674 var BssmapCause cause := 0;
2675 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2676
2677 /* expect Clear Complete from BSC on A */
2678 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2679 /* release the SCCP connection */
2680 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2681 }
2682
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002683 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 +02002684 }
2685
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002686 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002687 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 +02002688 }
2689}
2690
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002691private function f_tr_si2quater_earfcns(integer count) return template SI2quaterRestOctetsList
2692{
2693 var template SI2quaterRestOctetsList si2quater := {};
2694 var integer si2quater_count := (count + 2) / 3;
2695
2696 for (var integer i := 0; i < count; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002697 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002698 var integer index := i / 3;
2699 var integer earfcn_index := i mod 3;
2700 if (index >= lengthof(si2quater)) {
2701 si2quater[index] := tr_SI2quaterRestOctets_EUTRAN(index := index, count := si2quater_count - 1);
2702 }
2703 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);
2704 }
2705
2706 return si2quater;
2707}
2708
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002709private function f_tr_rr_chan_rel_earfcns(integer count) return template CellSelIndValue
2710{
2711 var template CellSelIndValue_EUTRAN_Descrs cells := {};
2712
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002713 /* the lte neighbors must match the config & vty to pass this test */
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002714 for (var integer i := 0; i < count; i := i + 1) {
2715 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002716 cells[i] := tr_CellSelIndValue_EUTRAN_Descr(earfcn, '1'B, 3);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002717 }
2718
2719 return tr_CellSelIndValue_EUTRAN(cells);
2720}
2721
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002722private function f_tc_si2quater_n_earfcns(integer n) runs on test_CT
2723{
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002724 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrol8ab62e42020-12-18 16:19:11 +01002725 sic.si2quater := f_tr_si2quater_earfcns(n);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002726 var template CellSelIndValue cells := f_tr_rr_chan_rel_earfcns(n);
2727 f_test_si2quater(n, sic, cells);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002728}
2729
2730testcase TC_si2quater_2_earfcns() runs on test_CT {
2731 f_tc_si2quater_n_earfcns(2);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002732 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002733}
2734
2735testcase TC_si2quater_3_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002736 f_tc_si2quater_n_earfcns(3);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002737 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002738}
2739
2740testcase TC_si2quater_4_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002741 f_tc_si2quater_n_earfcns(4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002742 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002743}
2744
2745testcase TC_si2quater_5_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002746 f_tc_si2quater_n_earfcns(5);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002747 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002748}
2749
2750testcase TC_si2quater_6_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002751 f_tc_si2quater_n_earfcns(6);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002752 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002753}
2754
2755testcase TC_si2quater_12_earfcns() runs on test_CT {
2756 f_tc_si2quater_n_earfcns(12);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002757 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002758}
2759
2760testcase TC_si2quater_23_earfcns() runs on test_CT {
2761 f_tc_si2quater_n_earfcns(23);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002762 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002763}
2764
2765testcase TC_si2quater_32_earfcns() runs on test_CT {
2766 f_tc_si2quater_n_earfcns(32);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002767 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002768}
2769
2770testcase TC_si2quater_33_earfcns() runs on test_CT {
2771 f_tc_si2quater_n_earfcns(33);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002772 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002773}
2774
2775testcase TC_si2quater_42_earfcns() runs on test_CT {
2776 f_tc_si2quater_n_earfcns(42);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002777 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002778}
2779
2780testcase TC_si2quater_48_earfcns() runs on test_CT {
2781 f_tc_si2quater_n_earfcns(48);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002782 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002783}
2784
2785/* verify the VTY error response when adding too many EARFCNs, and showing that osmo-bsc still sends 16 SI2quater with
2786 * 48 EARFCNs. */
2787testcase TC_si2quater_49_earfcns() runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002788 var template SystemInformationConfig sic := SystemInformationConfig_default;
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002789 sic.si2quater := f_tr_si2quater_earfcns(48); /* 48, not 49! */
2790 f_init(0);
2791
2792 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002793 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2794 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002795 }
2796
2797 /* The 49th EARFCN no longer fits, expect VTY error */
2798 f_vty_enter_cfg_bts(BSCVTY, 0);
2799 var charstring vty_error;
2800 vty_error := f_vty_transceive_ret(BSCVTY,
2801 "si2quater neighbor-list add earfcn 70 thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3")
2802 f_vty_transceive(BSCVTY, "end");
2803
2804 if (f_strstr(vty_error, "Unable to add ARFCN 70") >= 0) {
2805 log("Got expected VTY error: ", vty_error);
2806 setverdict(pass);
2807 } else {
2808 setverdict(fail, "Expected the 49th EUTRAN ARFCN to be rejected by vty config, got: ", vty_error);
2809 }
2810
2811 f_init_bts_and_check_sysinfo(0, expect_si := sic);
2812
2813 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002814 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 +02002815 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002816 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002817}
2818
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002819private function f_acc09_count_allowed(AccessControlClass acc) return uint8_t
2820{
2821 var uint8_t count := 0;
2822 for (var integer i := 5; i < 16; i := i + 1) {
2823 if (acc[i] == '0'B) { /* the list marks barred, we count allowed */
2824 count := count + 1;
2825 }
2826 }
2827 return count;
2828}
2829
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002830private function f_recv_next_si1(integer rsl_idx := 0) runs on test_CT return SystemInformationType1
2831{
2832 var ASP_RSL_Unitdata rx_rsl_ud;
2833 var SystemInformationType1 last_si1;
2834
2835 timer T := 30.0;
2836 T.start;
2837 alt {
2838 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD((tr_RSL_NO_BCCH_INFO,
2839 tr_RSL_BCCH_INFO,
2840 tr_RSL_NO_SACCH_FILL,
2841 tr_RSL_SACCH_FILL))
2842 ) -> value rx_rsl_ud {
2843 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
2844 if (g_system_information[rsl_idx].si1 == omit) {
2845 repeat;
2846 }
2847 last_si1 := g_system_information[rsl_idx].si1;
2848 g_system_information[rsl_idx].si1 := omit;
2849 T.stop;
2850 }
Vadim Yanitskiy79ebd5e2021-01-04 00:12:55 +01002851 [] IPA_RSL[rsl_idx].receive { repeat; }
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002852 [] T.timeout { setverdict(fail, "Timeout receiving next SI1"); }
2853 }
2854 return last_si1;
2855}
2856
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002857/* verify ACC rotate feature */
2858testcase TC_si_acc_rotate() runs on test_CT {
2859 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002860 var SystemInformationType1 last_si1;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002861 var AccessControlClass acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002862 var uint8_t count;
2863 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2864
2865 f_init(0, guard_timeout := 60.0);
2866
2867 f_bts_0_cfg(BSCVTY, {"rach access-control-class 5 barred",
2868 "access-control-class-rotate 3",
2869 "access-control-class-rotate-quantum 1"});
2870
2871 /* Init and get first sysinfo */
2872 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2873
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002874 for (var integer i:= 0; i < 20; i := i + 1) {
2875 last_si1 := f_recv_next_si1(0);
2876 acc := last_si1.rach_control.acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002877 count := f_acc09_count_allowed(acc);
2878 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2879
2880 if (count != 3) {
2881 log("RSL: EXPECTED SI ACC len=3");
2882 setverdict(fail, "received SI does not match expectations");
2883 break;
2884 }
2885
2886 for (var integer j := 0; j < 10; j := j + 1) {
2887 if (acc[16 - 1 - j] == '0'B) { /* the list marks barred, we count allowed */
2888 times_allowed[j] := times_allowed[j] + 1;
2889 }
2890 }
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002891 }
2892
2893 for (var integer j := 0; j < 10; j := j + 1) {
2894 log("ACC", j, " allowed ", times_allowed[j], " times" );
2895 if (j != 5 and times_allowed[j] < 3) {
2896 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " < 1 times");
2897 } else if (j == 5 and times_allowed[j] > 0) {
2898 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " > 0 times");
2899 }
2900 }
2901
2902 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2903 "rach access-control-class 5 allowed"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002904 f_shutdown_helper();
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002905}
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002906
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002907/* verify ACC startup ramp+rotate feature */
2908testcase TC_si_acc_ramp_rotate() runs on test_CT {
2909 var template SystemInformationConfig sic := SystemInformationConfig_default;
2910 var SystemInformationType1 last_si1;
2911 var AccessControlClass acc;
2912 var ASP_RSL_Unitdata rx_rsl_ud;
2913 var uint8_t count;
2914 var uint8_t prev_count;
2915 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2916
2917 f_init(0, guard_timeout := 80.0);
2918
2919 f_bts_0_cfg(BSCVTY, {"rach access-control-class 4 barred",
2920 "access-control-class-rotate 0",
2921 "access-control-class-rotate-quantum 1",
2922 "access-control-class-ramping",
2923 "access-control-class-ramping-step-interval 5",
2924 "access-control-class-ramping-step-size 5"});
2925
2926 /* Init and get first sysinfo */
2927 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2928 last_si1 := g_system_information[0].si1;
2929 acc := last_si1.rach_control.acc;
2930 count := f_acc09_count_allowed(acc);
2931 /* Adm subset size was set to 0 above, so wait until all ACC are barred */
2932 while (count > 0) {
2933 last_si1 := f_recv_next_si1(0);
2934 acc := last_si1.rach_control.acc;
2935 count := f_acc09_count_allowed(acc);
2936 log("RSL: wait len()=0: GOT SI1 ACC len=", count, ": ", acc);
2937 }
2938
2939 /* Increase adm subset size, we should see ramping start up */
2940 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10"});
2941 prev_count := 0;
2942 while (true) {
2943 last_si1 := f_recv_next_si1(0);
2944 acc := last_si1.rach_control.acc;
2945 count := f_acc09_count_allowed(acc);
2946 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2947
2948 if (prev_count > count) {
2949 setverdict(fail, "ACC allowed count dropped while expecting grow: ", prev_count, " -> ", count);
2950 break;
2951 }
2952
2953 if (count == 9) {
2954 break; /* Maximum reached (10 - 1 perm barred), done here */
2955 }
2956
2957 prev_count := count;
2958 }
2959
2960 setverdict(pass);
2961
2962 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2963 "rach access-control-class 4 allowed",
2964 "no access-control-class-ramping"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002965 f_shutdown_helper();
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002966}
2967
Harald Welte4003d112017-12-09 22:35:39 +01002968testcase TC_ctrl_msc_connection_status() runs on test_CT {
2969 var charstring ctrl_resp;
2970
Harald Welte89d42e82017-12-17 16:42:41 +01002971 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002972
2973 /* See https://osmocom.org/issues/2729 */
2974 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002975 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002976}
2977
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002978testcase TC_ctrl_msc0_connection_status() runs on test_CT {
2979 var charstring ctrl_resp;
2980
2981 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002982
2983 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002984 f_shutdown_helper();
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002985}
2986
Neels Hofmeyr0bc470d2021-08-21 13:37:13 +02002987/* Verify correct stats on the number of configured and connected MSCs */
2988private function f_tc_stat_num_msc_connected_msc_connhdlr(integer expect_num_msc_connected) runs on MSC_ConnHdlr {
2989 g_pars := f_gen_test_hdlr_pars();
2990 var StatsDExpects expect := {
2991 { name := "TTCN3.bsc.0.num_msc.connected", mtype := "g", min := expect_num_msc_connected, max := expect_num_msc_connected },
2992 { name := "TTCN3.bsc.0.num_msc.total", mtype := "g", min := NUM_MSC, max := NUM_MSC }
2993 };
2994 f_statsd_expect(expect);
2995}
2996
2997private function f_tc_stat_num_msc_connected_test_ct(void_fn tc_fn, integer nr_msc) runs on test_CT
2998{
2999 var MSC_ConnHdlr vc_conn;
3000
3001 f_init(nr_bts := 1, handler_mode := true, nr_msc := nr_msc);
3002 f_sleep(1.0);
3003 vc_conn := f_start_handler(tc_fn);
3004 vc_conn.done;
3005
3006 /* Also verify stat exposed on CTRL interface */
3007 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_msc:connected", int2str(nr_msc));
3008 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_msc:total", int2str(NUM_MSC));
3009
3010 f_shutdown_helper();
3011}
3012
3013/* Verify that when 1 MSC is active, that num_msc:connected reports 1. */
3014private function f_tc_stat_num_msc_connected_1(charstring id) runs on MSC_ConnHdlr {
3015 f_tc_stat_num_msc_connected_msc_connhdlr(1);
3016}
3017testcase TC_stat_num_msc_connected_1() runs on test_CT {
3018 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_1), 1);
3019}
3020
3021/* Verify that when 2 MSCs are active, that num_msc:connected reports 2. */
3022private function f_tc_stat_num_msc_connected_2(charstring id) runs on MSC_ConnHdlr {
3023 f_tc_stat_num_msc_connected_msc_connhdlr(2);
3024}
3025testcase TC_stat_num_msc_connected_2() runs on test_CT {
3026 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_2), 2);
3027}
3028
3029/* Verify that when 3 MSCs are active, that num_msc:connected reports 3. */
3030private function f_tc_stat_num_msc_connected_3(charstring id) runs on MSC_ConnHdlr {
3031 f_tc_stat_num_msc_connected_msc_connhdlr(3);
3032}
3033testcase TC_stat_num_msc_connected_3() runs on test_CT {
3034 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_3), 3);
3035}
3036
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +02003037/* Verify correct stats on the number of configured and connected MSCs */
3038private function f_tc_stat_num_bts_connected_msc_connhdlr(integer expect_num_bts_connected) runs on MSC_ConnHdlr {
3039 g_pars := f_gen_test_hdlr_pars();
3040 var StatsDExpects expect := {
3041 { name := "TTCN3.bsc.0.num_bts.oml_connected", mtype := "g", min := expect_num_bts_connected, max := NUM_BTS_CFG },
3042 { name := "TTCN3.bsc.0.num_bts.all_trx_rsl_connected", mtype := "g", min := expect_num_bts_connected, max := expect_num_bts_connected },
3043 { name := "TTCN3.bsc.0.num_bts.total", mtype := "g", min := NUM_BTS_CFG, max := NUM_BTS_CFG },
3044 { name := "TTCN3.bsc.0.num_trx.rsl_connected", mtype := "g", min := expect_num_bts_connected, max := expect_num_bts_connected },
3045 { name := "TTCN3.bsc.0.num_trx.total", mtype := "g", min := NUM_BTS_CFG, max := NUM_BTS_CFG }
3046 };
3047 f_statsd_expect(expect);
3048}
3049
3050private function f_tc_stat_num_bts_connected_test_ct(void_fn tc_fn, integer nr_bts) runs on test_CT {
3051 var MSC_ConnHdlr vc_conn;
3052
3053 f_init(nr_bts := nr_bts, handler_mode := true, nr_msc := 1);
3054 f_sleep(1.0);
3055 vc_conn := f_start_handler(tc_fn);
3056 vc_conn.done;
3057
3058 /* Also verify stat exposed on CTRL interface */
3059 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_bts:all_trx_rsl_connected", int2str(nr_bts));
3060 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_bts:total", int2str(NUM_BTS_CFG));
3061 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_trx:rsl_connected", int2str(nr_bts));
3062 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_trx:total", int2str(NUM_BTS_CFG));
3063
Neels Hofmeyra41ae302021-09-06 22:06:02 +02003064 /* Verify rf_states exposed on CTRL interface */
3065 var charstring expect_net_rf_states := "";
3066 for (var integer i := 0; i < NUM_BTS_CFG; i := i + 1) {
3067 var charstring expect_bts_rf_states := int2str(i) & ",0,";
3068 if (i < NUM_BTS) {
3069 /* In these tests, OML for the first NUM_BTS are always connected via osmo-bts-omldummy */
3070 expect_bts_rf_states := expect_bts_rf_states & "operational,unlocked,";
3071 } else {
3072 /* For remaining i < NUM_BTS_CFG, OML is not connected, i.e. inoperational */
3073 expect_bts_rf_states := expect_bts_rf_states & "inoperational,locked,";
3074 }
3075 /* The RF policy is still global in osmo-bsc, i.e. always "on" */
3076 expect_bts_rf_states := expect_bts_rf_states & "on,";
3077 if (i < nr_bts) {
3078 /* For BTS where RSL is connected, the RSL state will be "up" */
3079 expect_bts_rf_states := expect_bts_rf_states & "rsl-up;";
3080 } else {
3081 expect_bts_rf_states := expect_bts_rf_states & "rsl-down;";
3082 }
3083
3084 f_ctrl_get_exp(IPA_CTRL, "bts." & int2str(i) & ".rf_states", expect_bts_rf_states);
3085 expect_net_rf_states := expect_net_rf_states & expect_bts_rf_states;
3086 }
3087 f_ctrl_get_exp(IPA_CTRL, "rf_states", expect_net_rf_states);
3088
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +02003089 f_shutdown_helper();
3090}
3091
3092/* Verify that when 1 BTS is connected, that num_{bts,trx}:*_connected reports 1. */
3093private function f_tc_stat_num_bts_connected_1(charstring id) runs on MSC_ConnHdlr {
3094 f_tc_stat_num_bts_connected_msc_connhdlr(1);
3095}
3096testcase TC_stat_num_bts_connected_1() runs on test_CT {
3097 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_1), 1);
3098}
3099
3100/* Verify that when 2 BTS is connected, that num_{bts,trx}:*_connected reports 2. */
3101private function f_tc_stat_num_bts_connected_2(charstring id) runs on MSC_ConnHdlr {
3102 f_tc_stat_num_bts_connected_msc_connhdlr(2);
3103}
3104testcase TC_stat_num_bts_connected_2() runs on test_CT {
3105 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_2), 2);
3106}
3107
3108/* Verify that when 3 BTS is connected, that num_{bts,trx}:*_connected reports 3. */
3109private function f_tc_stat_num_bts_connected_3(charstring id) runs on MSC_ConnHdlr {
3110 f_tc_stat_num_bts_connected_msc_connhdlr(3);
3111}
3112testcase TC_stat_num_bts_connected_3() runs on test_CT {
3113 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_3), 3);
3114}
3115
Harald Welte4003d112017-12-09 22:35:39 +01003116testcase TC_ctrl() runs on test_CT {
3117 var charstring ctrl_resp;
3118
Harald Welte89d42e82017-12-17 16:42:41 +01003119 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01003120
3121 /* all below values must match the osmo-bsc.cfg config file used */
3122
Harald Welte6a129692018-03-17 17:30:14 +01003123 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
3124 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Oliver Smith75aa0202019-08-19 14:17:50 +02003125 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "4");
Harald Welte4003d112017-12-09 22:35:39 +01003126
3127 var integer bts_nr := 0;
3128 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
3129 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
3130 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
3131 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
3132 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
3133 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
3134 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
3135
3136 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
3137 f_sleep(2.0);
3138 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
3139 setverdict(fail, "oml-uptime not incrementing as expected");
3140 }
3141 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
3142
3143 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
3144
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003145 f_shutdown_helper();
Harald Welte96c94412017-12-09 03:12:45 +01003146}
3147
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02003148/* Verify that Upon receival of SET "location", BSC forwards a TRAP
3149 "location-state" over the SCCPlite IPA conn */
3150testcase TC_ctrl_location() runs on test_CT {
3151 var MSC_ConnHdlr vc_conn;
3152 var integer bts_nr := 0;
3153
3154 f_init(1, true);
3155 f_sleep(1.0);
3156
3157 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234567,fix3d,0.340000,0.560000,0.780000");
3158 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
3159 "1234567,fix3d,0.340000,0.560000,0.780000,operational,unlocked,on,001,01");
3160
3161 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "1");
3162 f_sleep(2.0);
3163
3164 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234888,fix3d,0.350000,0.570000,0.790000");
3165 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
3166 "1234888,fix3d,0.350000,0.570000,0.790000,operational,locked,off,001,01");
3167
3168 /* should match the one from config */
3169 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "0");
3170
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003171 f_shutdown_helper();
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02003172}
3173
Harald Welte6f521d82017-12-11 19:52:02 +01003174
3175/***********************************************************************
3176 * Paging Testing
3177 ***********************************************************************/
3178
3179type record Cell_Identity {
3180 GsmMcc mcc,
3181 GsmMnc mnc,
3182 GsmLac lac,
3183 GsmCellId ci
3184};
Harald Welte24135bd2018-03-17 19:27:53 +01003185private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01003186private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01003187
Harald Welte5d1a2202017-12-13 19:51:29 +01003188type set of integer BtsIdList;
3189
3190private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
3191 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
3192 if (bts_id == bts_ids[j]) {
3193 return true;
3194 }
3195 }
3196 return false;
3197}
Harald Welte6f521d82017-12-11 19:52:02 +01003198
3199/* core paging test helper function; used by most paging test cases */
3200private function f_pageing_helper(hexstring imsi,
3201 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01003202 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01003203 template RSL_ChanNeeded rsl_chneed := omit,
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003204 template (omit) OCT4 tmsi := omit) runs on test_CT
Harald Welte6f521d82017-12-11 19:52:02 +01003205{
3206 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003207 var template MobileIdentityV mi;
Harald Welte6f521d82017-12-11 19:52:02 +01003208 var RSL_Message rx_rsl;
3209 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01003210 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01003211
3212 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01003213
3214 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01003215 for (i := 0; i < NUM_BTS; i := i + 1) {
3216 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01003217 }
Harald Welte6f521d82017-12-11 19:52:02 +01003218
3219 if (isvalue(rsl_chneed)) {
3220 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
3221 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
3222 } else {
3223 bssmap_chneed := omit;
3224 }
3225
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003226 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[0].sccp_addr_peer, g_bssap[0].sccp_addr_own,
3227 ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed)));
Harald Welte6f521d82017-12-11 19:52:02 +01003228
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003229 if (not istemplatekind(tmsi, "omit")) {
3230 mi := t_MI_TMSI(tmsi);
Harald Welte6f521d82017-12-11 19:52:02 +01003231 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003232 mi := tr_MI_IMSI(imsi);
Harald Welte6f521d82017-12-11 19:52:02 +01003233 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003234
Harald Welte5d1a2202017-12-13 19:51:29 +01003235 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003236 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(mi));
Harald Welte5d1a2202017-12-13 19:51:29 +01003237 /* check channel type, paging group */
3238 if (rx_rsl.ies[1].body.paging_group != paging_group) {
3239 setverdict(fail, "Paging for wrong paging group");
3240 }
3241 if (ispresent(rsl_chneed) and
3242 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
3243 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
3244 }
Harald Welte6f521d82017-12-11 19:52:02 +01003245 }
Harald Welte2fccd982018-01-31 15:48:19 +01003246 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01003247 /* do a quick check on all not-included BTSs if they received paging */
3248 for (i := 0; i < NUM_BTS; i := i + 1) {
3249 timer T := 0.1;
3250 if (f_bts_in_list(i, bts_ids)) {
3251 continue;
3252 }
3253 T.start;
3254 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003255 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(mi))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003256 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
3257 }
3258 [] IPA_RSL[i].receive { repeat; }
3259 [] T.timeout { }
3260 }
Harald Welte6f521d82017-12-11 19:52:02 +01003261 }
3262
3263 setverdict(pass);
3264}
3265
Harald Welte5d1a2202017-12-13 19:51:29 +01003266const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01003267const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01003268const BtsIdList c_BtsId_LAC1 := { 0, 1 };
3269const BtsIdList c_BtsId_LAC2 := { 2 };
3270
Harald Welte6f521d82017-12-11 19:52:02 +01003271/* PAGING by IMSI + TMSI */
3272testcase TC_paging_imsi_nochan() runs on test_CT {
3273 var BSSMAP_FIELD_CellIdentificationList cid_list;
3274 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01003275 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003276 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003277}
3278
3279/* PAGING by IMSI + TMSI */
3280testcase TC_paging_tmsi_nochan() runs on test_CT {
3281 var BSSMAP_FIELD_CellIdentificationList cid_list;
3282 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003283 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003284 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003285}
3286
3287/* Paging with different "channel needed' values */
3288testcase TC_paging_tmsi_any() runs on test_CT {
3289 var BSSMAP_FIELD_CellIdentificationList cid_list;
3290 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003291 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003292 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003293}
3294testcase TC_paging_tmsi_sdcch() runs on test_CT {
3295 var BSSMAP_FIELD_CellIdentificationList cid_list;
3296 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003297 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003298 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003299}
3300testcase TC_paging_tmsi_tch_f() runs on test_CT {
3301 var BSSMAP_FIELD_CellIdentificationList cid_list;
3302 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003303 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003304 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003305}
3306testcase TC_paging_tmsi_tch_hf() runs on test_CT {
3307 var BSSMAP_FIELD_CellIdentificationList cid_list;
3308 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003309 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003310 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003311}
3312
3313/* Paging by CGI */
3314testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
3315 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3316 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003317 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003318 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003319}
3320
3321/* Paging by LAC+CI */
3322testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
3323 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3324 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003325 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003326 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003327}
3328
3329/* Paging by CI */
3330testcase TC_paging_imsi_nochan_ci() runs on test_CT {
3331 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3332 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003333 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003334 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003335}
3336
3337/* Paging by LAI */
3338testcase TC_paging_imsi_nochan_lai() runs on test_CT {
3339 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3340 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003341 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003342 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003343}
3344
3345/* Paging by LAC */
3346testcase TC_paging_imsi_nochan_lac() runs on test_CT {
3347 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3348 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003349 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003350 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003351}
3352
3353/* Paging by "all in BSS" */
3354testcase TC_paging_imsi_nochan_all() runs on test_CT {
3355 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3356 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01003357 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003358 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003359}
3360
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003361/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003362testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
3363 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3364 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 +01003365 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003366 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003367}
Harald Welte6f521d82017-12-11 19:52:02 +01003368
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003369/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003370testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
3371 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3372 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003373 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003374 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003375}
3376
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003377/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003378testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
3379 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3380 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003381 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003382 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003383}
3384
Harald Welte6f521d82017-12-11 19:52:02 +01003385/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01003386testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
3387 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3388 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
3389 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003390 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003391}
3392
3393/* Paging on empty list: Verify none of them page */
3394testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
3395 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3396 cid_list := { cIl_LAC := { } };
3397 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003398 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003399}
3400
Stefan Sperling049a86e2018-03-20 15:51:00 +01003401/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
3402testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
3403 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3404 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
3405 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
3406 f_shutdown_helper();
3407}
3408
Harald Welte6f521d82017-12-11 19:52:02 +01003409/* Verify paging retransmission interval + count */
3410/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01003411/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01003412
Harald Weltee65d40e2017-12-13 00:09:06 +01003413/* Verify PCH load */
3414testcase TC_paging_imsi_load() runs on test_CT {
3415 var BSSMAP_FIELD_CellIdentificationList cid_list;
3416 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01003417 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01003418 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003419 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01003420
3421 /* tell BSC there is no paging space anymore */
3422 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01003423 f_sleep(0.2);
3424 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01003425
3426 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
3427 * there would be 8 retransmissions during 4 seconds */
3428 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01003429 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01003430 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003431 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Weltee65d40e2017-12-13 00:09:06 +01003432 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02003433 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01003434 }
Harald Welte2caa1062018-03-17 18:19:05 +01003435 [] T_retrans.timeout {
3436 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
3437 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
3438 T_retrans.start;
3439 repeat;
3440 }
Harald Weltee65d40e2017-12-13 00:09:06 +01003441 [] T.timeout {
3442 setverdict(pass);
3443 }
3444 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003445
3446 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01003447}
3448
Harald Welte235ebf12017-12-15 14:18:16 +01003449/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01003450testcase TC_paging_counter() runs on test_CT {
3451 var BSSMAP_FIELD_CellIdentificationList cid_list;
3452 timer T := 4.0;
3453 var integer i;
3454 var integer paging_attempted_bsc;
3455 var integer paging_attempted_bts[NUM_BTS];
Oliver Smith8b343d32021-11-26 13:01:42 +01003456 var integer paging_expired_bsc;
Harald Welte1ff69992017-12-14 12:31:17 +01003457 var integer paging_expired_bts[NUM_BTS];
3458 cid_list := valueof(ts_BSSMAP_CIL_noCell);
3459
3460 f_init();
3461
3462 /* read counters before paging */
3463 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
Oliver Smith8b343d32021-11-26 13:01:42 +01003464 if (Misc_Helpers.f_osmo_repo_is("nightly")) { /* osmo-bsc > 1.8.0 */
3465 paging_expired_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:expired");
3466 }
Harald Welte1ff69992017-12-14 12:31:17 +01003467 for (i := 0; i < NUM_BTS; i := i+1) {
3468 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
3469 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
3470 }
3471
3472 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
3473
3474 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
3475 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
3476 for (i := 0; i < NUM_BTS; i := i+1) {
3477 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
3478 paging_attempted_bts[i]+1);
3479 }
3480
3481 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
3482 f_sleep(12.0);
Oliver Smith8b343d32021-11-26 13:01:42 +01003483 if (Misc_Helpers.f_osmo_repo_is("nightly")) { /* osmo-bsc > 1.8.0 */
3484 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:expired", paging_expired_bsc+1);
3485 }
Harald Welte1ff69992017-12-14 12:31:17 +01003486 for (i := 0; i < NUM_BTS; i := i+1) {
3487 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
3488 paging_expired_bts[i]+1);
3489 }
Harald Welte1ff69992017-12-14 12:31:17 +01003490
Philipp Maier282ca4b2018-02-27 17:17:00 +01003491 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01003492}
3493
3494
Harald Welte10985002017-12-12 09:29:15 +01003495/* Verify paging stops after A-RESET */
3496testcase TC_paging_imsi_a_reset() runs on test_CT {
3497 var BSSMAP_FIELD_CellIdentificationList cid_list;
3498 timer T := 3.0;
3499 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003500 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01003501
3502 /* Perform a BSSMAP Reset and wait for ACK */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003503 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 +01003504 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003505 [] 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 +01003506 [] BSSAP.receive { repeat; }
3507 }
3508
Daniel Willmanncbef3982018-07-30 09:22:40 +02003509 /* Wait to avoid a possible race condition if a paging message is
3510 * received right before the reset ACK. */
3511 f_sleep(0.2);
3512
Harald Welte10985002017-12-12 09:29:15 +01003513 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01003514 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
3515 IPA_RSL[i].clear;
3516 }
Harald Welte10985002017-12-12 09:29:15 +01003517
3518 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
3519 T.start;
3520 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003521 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte10985002017-12-12 09:29:15 +01003522 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003523 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01003524 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003525 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003526 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003527 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003528 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003529 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003530 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003531 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003532 }
Harald Welte10985002017-12-12 09:29:15 +01003533 [] T.timeout {
3534 setverdict(pass);
3535 }
3536 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003537
3538 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01003539}
Harald Welteae026692017-12-09 01:03:01 +01003540
Philipp Maierf45824a2019-08-14 14:44:10 +02003541/* Verify how we handle unsolicited Paging Response. In case of an unsolicit
3542 * paging response we can not know which MSC is in charge, so we will blindly
3543 * pick the first configured MSC. This behavior is required in order to make
3544 * MT-CSFB calls working because in those cases the BSC can not know that the
3545 * MSC has already paged the subscriver via SGs. So any MT-CSFB call will look
3546 * like an unsolicited Paging Response to the MSC.
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003547 */
3548testcase TC_paging_resp_unsol() runs on test_CT {
3549
3550 f_init(1);
Philipp Maierf45824a2019-08-14 14:44:10 +02003551 timer T := 5.0;
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003552
3553 var BSSAP_N_CONNECT_ind rx_c_ind;
3554 var DchanTuple dt;
3555 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
Philipp Maierf45824a2019-08-14 14:44:10 +02003556 var octetstring rr_pag_resp := enc_PDU_ML3_MS_NW(l3);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003557
3558 /* Send CHAN RQD and wait for allocation; acknowledge it */
3559 dt.rsl_chan_nr := f_chreq_act_ack();
3560
3561 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
3562 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
3563
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003564
Philipp Maierf45824a2019-08-14 14:44:10 +02003565 /* Expevct a CR with a matching Paging response on the A-Interface */
3566 T.start;
3567 alt {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003568 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(rr_pag_resp))) -> value rx_c_ind {
Philipp Maierf45824a2019-08-14 14:44:10 +02003569 setverdict(pass);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003570 dt.sccp_conn_id := rx_c_ind.connectionId;
3571 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
Philipp Maierf45824a2019-08-14 14:44:10 +02003572 }
3573 [] BSSAP.receive {
3574 setverdict(fail, "Received unexpected message on A-Interface!");
3575 }
3576 [] T.timeout {
3577 setverdict(fail, "Received nothing on A-Interface!");
3578 }
3579 }
3580
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003581 f_perform_clear_test_ct(dt);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003582 f_shutdown_helper();
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003583}
3584
Pau Espin Pedrol189bf1b2022-04-27 12:42:13 +02003585/* Verify BSC can schedule N paging requests under one minute if BTS buffer is good enough */
3586function f_TC_paging_Nreq(integer num_subscribers, boolean send_pag_load_ind) runs on test_CT {
Pau Espin Pedrol09b9bad2022-04-21 18:48:08 +02003587 var ASP_RSL_Unitdata rx_rsl_ud;
Pau Espin Pedrol189bf1b2022-04-27 12:42:13 +02003588 var Hexstrings imsis := {};
3589 var Booleans rx_paging_done := {};
Pau Espin Pedrol09b9bad2022-04-21 18:48:08 +02003590 var integer rx_paging_num := 0;
3591 var integer i;
3592 timer T_rx := 60.0;
3593 timer T_load_ind := 1.0;
3594
3595 for (i := 0; i < num_subscribers; i := i + 1) {
Pau Espin Pedrol189bf1b2022-04-27 12:42:13 +02003596 imsis := imsis & {f_gen_imsi(i)};
3597 rx_paging_done := rx_paging_done & { false };
Pau Espin Pedrol09b9bad2022-04-21 18:48:08 +02003598 }
3599
3600 f_init(1, guard_timeout := 100.0);
3601
3602 /* Clear the queue, it might still contain stuff like BCCH FILLING */
3603 IPA_RSL[0].clear;
Pau Espin Pedrol189bf1b2022-04-27 12:42:13 +02003604 if (send_pag_load_ind) {
3605 /* Tell there's plenty of space at the BTS (UINT16_MAX): */
3606 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(65535));
3607 }
Pau Espin Pedrol09b9bad2022-04-21 18:48:08 +02003608
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;
Pau Espin Pedrolef7ef632022-04-25 13:34:57 +02003625 } else {
Pau Espin Pedrol189bf1b2022-04-27 12:42:13 +02003626 setverdict(fail, "Retrans of ", imsi_str, " happened before Rx initial trans for all reqs. rx_paging_num=", rx_paging_num);
Pau Espin Pedrolef7ef632022-04-25 13:34:57 +02003627 mtc.stop;
Pau Espin Pedrol09b9bad2022-04-21 18:48:08 +02003628 }
3629 if (rx_paging_num < num_subscribers) {
3630 repeat;
3631 }
3632 }
3633 [] IPA_RSL[0].receive { repeat; }
3634 [] T_load_ind.timeout {
Pau Espin Pedrol189bf1b2022-04-27 12:42:13 +02003635 log("[CCH Load Ind timer] received paging requests so far: ", rx_paging_num);
3636 if (send_pag_load_ind) {
3637 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(40));
3638 }
Pau Espin Pedrol09b9bad2022-04-21 18:48:08 +02003639 T_load_ind.start;
3640 repeat;
3641 }
3642 [] T_rx.timeout {
3643 setverdict(fail, "Timeout expecting paging requests, so far ", rx_paging_num);
3644 mtc.stop;
3645 }
3646 }
3647
3648 f_shutdown_helper();
3649}
Pau Espin Pedrol189bf1b2022-04-27 12:42:13 +02003650/* Verify BSC can schedule 500 paging requests under one minute if BTS buffer is good enough */
3651testcase TC_paging_500req() runs on test_CT {
3652 f_TC_paging_Nreq(500, true);
3653}
3654/* Same as TC_paging_500req, but without sending CCCH Load Indication, which
3655 * means BTS is always under CCH Load Threshold, aka capable of sending tons of requests.
3656 * Since No CCCH Load Ind, BSC uses a conservative estimation of BTS load, which
3657 * for current config yields ~8req/sec, so 480req/min maximum. */
3658testcase TC_paging_450req_no_paging_load_ind() runs on test_CT {
3659 f_TC_paging_Nreq(450, false);
3660}
Pau Espin Pedrol09b9bad2022-04-21 18:48:08 +02003661
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003662/* Test RSL link drop causes counter increment */
3663testcase TC_rsl_drop_counter() runs on test_CT {
3664 var integer rsl_fail;
3665
Harald Welte89d42e82017-12-17 16:42:41 +01003666 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003667
3668 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
3669
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +01003670 f_ipa_rsl_stop(bts[0].rsl);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003671
3672 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
3673
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003674 f_shutdown_helper();
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003675}
3676
3677/* TODO: Test OML link drop causes counter increment */
3678
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003679/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
3680function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
3681 timer T := 10.0;
3682
3683 bts[0].rsl.id := "IPA-0-RSL";
Harald Welte71389132021-12-09 21:58:18 +01003684 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA") alive;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003685 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
3686 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
Oliver Smith92c2bdb2019-08-20 15:11:24 +02003687 bts[0].rsl.ccm_pars.unit_id := "99/0/0"; /* value which is unknown at BTS */
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003688
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01003689 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003690
3691 f_init_mgcp("VirtMSC");
3692
3693 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
3694 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
3695 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
3696 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
3697
3698 /* wait for IPA OML link to connect and then disconnect */
3699 T.start;
3700 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +07003701 [] IPA_RSL[0].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) {
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003702 T.stop;
3703 return true;
3704 }
3705 [] IPA_RSL[0].receive { repeat }
3706 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02003707 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003708 }
3709 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003710 return false;
3711}
3712
3713/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3714testcase TC_rsl_unknown_unit_id() runs on test_CT {
3715 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
3716 setverdict(pass);
3717 } else {
3718 setverdict(fail, "Timeout RSL waiting for connection to close");
3719 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003720 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003721}
3722
3723
3724/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3725testcase TC_oml_unknown_unit_id() runs on test_CT {
3726 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
3727 setverdict(pass);
3728 } else {
3729 setverdict(fail, "Timeout OML waiting for connection to close");
3730 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003731 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003732}
3733
3734
Harald Weltec1a2fff2017-12-17 11:06:19 +01003735/***********************************************************************
Harald Welte6811d102019-04-14 22:23:14 +02003736 * "New world" test cases using RSL_Emulation + RAN_Emulation
Harald Weltec1a2fff2017-12-17 11:06:19 +01003737 ***********************************************************************/
3738
Harald Welte6811d102019-04-14 22:23:14 +02003739import from RAN_Emulation all;
Harald Welte47cd0e32020-08-21 12:39:11 +02003740import from BSSAP_LE_Emulation all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01003741import from RSL_Emulation all;
3742import from MSC_ConnectionHandler all;
3743
3744type function void_fn(charstring id) runs on MSC_ConnHdlr;
3745
Harald Welte336820c2018-05-31 20:34:52 +02003746/* helper function to create and connect a MSC_ConnHdlr component */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003747private function f_connect_handler(inout MSC_ConnHdlr vc_conn, integer bssap_idx := 0) runs on test_CT {
3748 connect(vc_conn:RAN, g_bssap[bssap_idx].vc_RAN:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01003749 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003750 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01003751 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01003752 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01003753 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
3754 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
3755 }
Neels Hofmeyr91401012019-07-11 00:42:35 +02003756 if (isvalue(bts[2])) {
3757 connect(vc_conn:RSL2, bts[2].rsl.vc_RSL:CLIENT_PT);
3758 connect(vc_conn:RSL2_PROC, bts[2].rsl.vc_RSL:RSL_PROC);
3759 }
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003760 connect(vc_conn:BSSAP, g_bssap[bssap_idx].vc_RAN:CLIENT);
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02003761 if (mp_enable_lcs_tests) {
3762 connect(vc_conn:BSSAP_LE, g_bssap_le.vc_BSSAP_LE:CLIENT);
3763 connect(vc_conn:BSSAP_LE_PROC, g_bssap_le.vc_BSSAP_LE:PROC);
3764 }
Daniel Willmann191e0d92018-01-17 12:44:35 +01003765 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02003766 connect(vc_conn:MGCP_MULTI, vc_MGCP:MGCP_CLIENT_MULTI);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003767 connect(vc_conn:STATSD_PROC, vc_STATSD:STATSD_PROC);
Harald Welte336820c2018-05-31 20:34:52 +02003768}
3769
Neels Hofmeyrda436782021-07-20 22:09:06 +02003770function f_start_handler_create(template (omit) TestHdlrParams pars := omit)
Harald Welte336820c2018-05-31 20:34:52 +02003771runs on test_CT return MSC_ConnHdlr {
3772 var charstring id := testcasename();
3773 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003774 var integer bssap_idx := 0;
3775 if (isvalue(pars)) {
3776 bssap_idx := valueof(pars).mscpool.bssap_idx;
3777 }
Harald Welte336820c2018-05-31 20:34:52 +02003778 vc_conn := MSC_ConnHdlr.create(id);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003779 f_connect_handler(vc_conn, bssap_idx);
Neels Hofmeyrda436782021-07-20 22:09:06 +02003780 return vc_conn;
3781}
3782
3783function f_start_handler_run(MSC_ConnHdlr vc_conn, void_fn fn, template (omit) TestHdlrParams pars := omit)
3784runs on test_CT return MSC_ConnHdlr {
3785 var charstring id := testcasename();
Harald Weltea0630032018-03-20 21:09:55 +01003786 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003787 return vc_conn;
3788}
3789
Neels Hofmeyrda436782021-07-20 22:09:06 +02003790function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
3791runs on test_CT return MSC_ConnHdlr {
3792 return f_start_handler_run(f_start_handler_create(pars), fn, pars);
3793}
3794
Harald Weltea0630032018-03-20 21:09:55 +01003795/* first function inside ConnHdlr component; sets g_pars + starts function */
3796private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
3797runs on MSC_ConnHdlr {
3798 if (isvalue(pars)) {
3799 g_pars := valueof(pars);
3800 }
3801 fn.apply(id);
3802}
3803
Oliver Smith26a3db72021-07-09 13:51:29 +02003804private function f_vty_encryption_a5(charstring options) runs on test_CT {
3805 f_vty_transceive(BSCVTY, "configure terminal");
3806 f_vty_transceive(BSCVTY, "network");
3807 f_vty_transceive(BSCVTY, "encryption a5 " & options);
3808 f_vty_transceive(BSCVTY, "exit");
3809 f_vty_transceive(BSCVTY, "exit");
3810}
3811
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01003812const charstring VTY_A5_DEFAULT := "0 1 3";
3813
Oliver Smith26a3db72021-07-09 13:51:29 +02003814private function f_vty_encryption_a5_reset() runs on test_CT {
3815 /* keep in sync with docker-playground.git ttcn3-bsc-test/osmo-bsc.cfg */
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01003816 f_vty_encryption_a5(VTY_A5_DEFAULT);
Oliver Smith26a3db72021-07-09 13:51:29 +02003817}
3818
Harald Welte3c86ea02018-05-10 22:28:05 +02003819/* Establish signalling channel (non-assignment case) followed by cipher mode */
3820private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003821 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3822 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02003823 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02003824 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
3825 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
3826 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
3827 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02003828
Philipp Maier23000732018-05-18 11:25:37 +02003829 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003830 f_perform_clear();
Harald Welte3c86ea02018-05-10 22:28:05 +02003831}
3832testcase TC_ciph_mode_a5_0() runs on test_CT {
3833 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003834 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003835 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
3836
3837 f_init(1, true);
3838 f_sleep(1.0);
3839 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3840 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003841 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003842}
3843testcase TC_ciph_mode_a5_1() runs on test_CT {
3844 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003845 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003846 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
3847
3848 f_init(1, true);
3849 f_sleep(1.0);
3850 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3851 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003852 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003853}
Oliver Smith50b98122021-07-09 15:00:28 +02003854/* OS#4975: verify that A5/2 is preferred over A5/0 */
3855testcase TC_ciph_mode_a5_2_0() runs on test_CT {
3856 var MSC_ConnHdlr vc_conn;
3857 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3858
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01003859 pars.encr := f_encr_params('05'O, '04'O); /* A5/0 and A5/2 (0x01|0x04)*/
Oliver Smith50b98122021-07-09 15:00:28 +02003860
3861 f_init(1, true);
3862 f_vty_encryption_a5("0 1 2 3");
3863 f_sleep(1.0);
3864 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3865 vc_conn.done;
3866 f_vty_encryption_a5_reset();
3867 f_shutdown_helper();
3868}
Oliver Smith1dff88d2021-07-09 08:45:51 +02003869/* OS#4975: verify that A5/1 is preferred over A5/2 */
3870testcase TC_ciph_mode_a5_2_1() runs on test_CT {
3871 var MSC_ConnHdlr vc_conn;
3872 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3873
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01003874 pars.encr := f_encr_params('06'O, '02'O); /* A5/1 and A5/2 (0x02|0x04)*/
Oliver Smith1dff88d2021-07-09 08:45:51 +02003875
3876 f_init(1, true);
3877 f_vty_encryption_a5("1 2");
3878 f_sleep(1.0);
3879 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3880 vc_conn.done;
3881 f_vty_encryption_a5_reset();
3882 f_shutdown_helper();
3883}
Harald Welte3c86ea02018-05-10 22:28:05 +02003884testcase TC_ciph_mode_a5_3() runs on test_CT {
3885 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003886 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003887 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
3888
3889 f_init(1, true);
3890 f_sleep(1.0);
3891 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3892 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003893 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003894}
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003895/* Establish a Signalling channel with A5/4 encryption. */
3896testcase TC_ciph_mode_a5_4() runs on test_CT {
3897 var MSC_ConnHdlr vc_conn;
3898 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3899 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Harald Welte3c86ea02018-05-10 22:28:05 +02003900
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003901 f_init(1, true);
Oliver Smith26a3db72021-07-09 13:51:29 +02003902 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003903 f_sleep(1.0);
3904 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3905 vc_conn.done;
Oliver Smith26a3db72021-07-09 13:51:29 +02003906 f_vty_encryption_a5_reset();
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003907 f_shutdown_helper();
3908}
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003909/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
3910private function f_tc_assignment_aoip_tla_v6(charstring id) runs on MSC_ConnHdlr {
3911 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3912 var PDU_BSSAP ass_cmd := f_gen_ass_req(aoip_tla := "::3");
3913 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3914 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3915
3916 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003917 f_perform_clear();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003918}
3919testcase TC_assignment_aoip_tla_v6() runs on test_CT {
3920 var MSC_ConnHdlr vc_conn;
3921 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3922
3923 f_init(1, true);
3924 f_sleep(1.0);
3925 vc_conn := f_start_handler(refers(f_tc_assignment_aoip_tla_v6), pars);
3926 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003927 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003928}
3929
Harald Welte3c86ea02018-05-10 22:28:05 +02003930
3931/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02003932private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003933 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3934 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003935
Harald Welte552620d2017-12-16 23:21:36 +01003936 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3937 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01003938
Harald Weltea0630032018-03-20 21:09:55 +01003939 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003940 f_perform_clear();
Harald Welte552620d2017-12-16 23:21:36 +01003941}
Harald Welte552620d2017-12-16 23:21:36 +01003942testcase TC_assignment_fr_a5_0() runs on test_CT {
3943 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003944 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003945 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01003946
Harald Welte89d42e82017-12-17 16:42:41 +01003947 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003948 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003949 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003950 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003951 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003952}
Harald Welte552620d2017-12-16 23:21:36 +01003953testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01003954 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003955 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003956 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003957
Harald Welte89d42e82017-12-17 16:42:41 +01003958 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003959 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003960 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3961 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003962 f_shutdown_helper();
Harald Welte651fcdc2018-05-10 20:23:16 +02003963}
3964testcase TC_assignment_fr_a5_3() runs on test_CT {
3965 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003966 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003967 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003968
Harald Welte651fcdc2018-05-10 20:23:16 +02003969 f_init(1, true);
3970 f_sleep(1.0);
3971 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003972 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003973 f_shutdown_helper();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003974}
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003975/* Establish a Signalling channel and re-assign to TCH/F with A5/4 encryption. */
3976testcase TC_assignment_fr_a5_4() runs on test_CT {
3977 var MSC_ConnHdlr vc_conn;
3978 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3979 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
3980
3981 f_init(1, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02003982 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003983 f_sleep(1.0);
3984 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3985 vc_conn.done;
Oliver Smith7eabd312021-07-12 14:18:56 +02003986 f_vty_encryption_a5_reset();
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003987 f_shutdown_helper();
3988}
Harald Weltec1a2fff2017-12-17 11:06:19 +01003989
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +02003990/* Allow only A5/4, but omit the Kc128 IE from MSC's msg. Expect Cipher Mode Reject. */
3991testcase TC_assignment_fr_a5_4_fail() runs on test_CT {
3992 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3993 var MSC_ConnHdlr vc_conn;
3994
3995 f_init(1, true);
3996 f_sleep(1.0);
3997
3998 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8))); // A5/4 support, but Kc128 missing!
3999 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
4000 vc_conn.done;
4001 f_shutdown_helper();
4002}
4003
Harald Welte552620d2017-12-16 23:21:36 +01004004/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
4005private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02004006 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01004007 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02004008 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01004009
4010 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02004011 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
4012
Harald Weltea0630032018-03-20 21:09:55 +01004013 f_establish_fully(ass_cmd, exp_fail);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004014 f_perform_clear();
Harald Welte552620d2017-12-16 23:21:36 +01004015}
Harald Welte552620d2017-12-16 23:21:36 +01004016testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
4017 var MSC_ConnHdlr vc_conn;
4018
Harald Welte89d42e82017-12-17 16:42:41 +01004019 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01004020 f_sleep(1.0);
4021
Harald Welte8863fa12018-05-10 20:15:27 +02004022 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01004023 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004024 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01004025}
4026
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02004027private function f_TC_assignment_a5_not_sup(charstring id) runs on MSC_ConnHdlr {
4028 var template PDU_BSSAP exp_ass_cpl := f_gen_exp_compl();
4029 var PDU_BSSAP exp_ass_req := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01004030
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02004031 exp_ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4032 exp_ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4033
4034 /* this is like the beginning of f_establish_fully(), but only up to ciphering reject */
4035
4036 var BSSMAP_FIELD_CodecType codecType;
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02004037
4038 codecType := exp_ass_req.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType;
4039 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
4040
4041 f_create_chan_and_exp();
4042 /* we should now have a COMPL_L3 at the MSC */
4043
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02004044 /* Start ciphering, expect Cipher Mode Reject */
Neels Hofmeyr6c388f22021-06-11 02:36:56 +02004045 f_cipher_mode(g_pars.encr, exp_fail := true);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004046 f_perform_clear();
Harald Welte552620d2017-12-16 23:21:36 +01004047}
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02004048testcase TC_assignment_fr_a5_not_sup() runs on test_CT {
4049 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01004050 var MSC_ConnHdlr vc_conn;
4051
Harald Welte89d42e82017-12-17 16:42:41 +01004052 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01004053 f_sleep(1.0);
4054
Neels Hofmeyr0588cad2021-06-11 01:38:18 +02004055 pars.encr := valueof(t_EncrParams('20'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02004056 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
Harald Welte552620d2017-12-16 23:21:36 +01004057 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004058 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01004059}
4060
4061
Harald Welte4532e0a2017-12-23 02:05:44 +01004062private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02004063 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01004064 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02004065 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01004066 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Daniel Willmannebdecc02020-08-12 15:30:17 +02004067
4068 f_statsd_reset();
Harald Weltea0630032018-03-20 21:09:55 +01004069 f_establish_fully(ass_cmd, exp_compl);
Daniel Willmannebdecc02020-08-12 15:30:17 +02004070
4071 var StatsDExpects expect := {
Daniel Willmannc5398f72020-09-21 10:41:35 +02004072 { name := "TTCN3.bts.0.chreq.total", mtype := "c", min := 1, max := 1},
4073 { name := "TTCN3.bts.0.chreq.successful", mtype := "c", min := 1, max := 1},
Daniel Willmannebdecc02020-08-12 15:30:17 +02004074 { name := "TTCN3.bsc.0.assignment.attempted", mtype := "c", min := 1, max := 1},
4075 { name := "TTCN3.bsc.0.assignment.completed", mtype := "c", min := 1, max := 1}
4076 };
4077 f_statsd_expect(expect);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004078 f_perform_clear();
Harald Welte4532e0a2017-12-23 02:05:44 +01004079}
4080
4081testcase TC_assignment_sign() runs on test_CT {
4082 var MSC_ConnHdlr vc_conn;
4083
4084 f_init(1, true);
4085 f_sleep(1.0);
4086
Harald Welte8863fa12018-05-10 20:15:27 +02004087 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01004088 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004089 f_shutdown_helper();
Harald Welte4532e0a2017-12-23 02:05:44 +01004090}
4091
Harald Welte60aa5762018-03-21 19:33:13 +01004092/***********************************************************************
4093 * Codec (list) testing
4094 ***********************************************************************/
4095
4096/* check if the given rsl_mode is compatible with the a_elem */
4097private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
4098return boolean {
4099 select (a_elem.codecType) {
4100 case (GSM_FR) {
4101 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
4102 return true;
4103 }
4104 }
4105 case (GSM_HR) {
4106 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
4107 return true;
4108 }
4109 }
4110 case (GSM_EFR) {
4111 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
4112 return true;
4113 }
4114 }
4115 case (FR_AMR) {
4116 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
4117 return true;
4118 }
4119 }
4120 case (HR_AMR) {
4121 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
4122 return true;
4123 }
4124 }
4125 case else { }
4126 }
4127 return false;
4128}
4129
4130/* check if the given rsl_mode is compatible with the a_list */
4131private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
4132return boolean {
4133 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
4134 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
4135 return true;
4136 }
4137 }
4138 return false;
4139}
4140
4141/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02004142function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01004143return BSSMAP_IE_ChannelType {
4144 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
4145 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
4146 select (a_elem.codecType) {
4147 case (GSM_FR) {
4148 ret.channelRateAndType := ChRate_TCHF;
4149 ret.speechId_DataIndicator := Spdi_TCHF_FR;
4150 }
4151 case (GSM_HR) {
4152 ret.channelRateAndType := ChRate_TCHH;
4153 ret.speechId_DataIndicator := Spdi_TCHH_HR;
4154 }
4155 case (GSM_EFR) {
4156 ret.channelRateAndType := ChRate_TCHF;
4157 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
4158 }
4159 case (FR_AMR) {
4160 ret.channelRateAndType := ChRate_TCHF;
4161 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
4162 }
4163 case (HR_AMR) {
4164 ret.channelRateAndType := ChRate_TCHH;
4165 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
4166 }
4167 case else {
4168 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02004169 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01004170 }
4171 }
4172 return ret;
4173}
4174
Harald Weltea63b9102018-03-22 20:36:16 +01004175private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
4176return template RSL_IE_Body {
4177 var template RSL_IE_Body mode_ie := {
4178 chan_mode := {
4179 len := ?,
4180 reserved := ?,
4181 dtx_d := ?,
4182 dtx_u := ?,
4183 spd_ind := RSL_SPDI_SPEECH,
4184 ch_rate_type := -,
4185 coding_alg_rate := -
4186 }
4187 }
4188
4189 select (a_elem.codecType) {
4190 case (GSM_FR) {
4191 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4192 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
4193 }
4194 case (GSM_HR) {
4195 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
4196 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
4197 }
4198 case (GSM_EFR) {
4199 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4200 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
4201 }
4202 case (FR_AMR) {
4203 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4204 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
4205 }
4206 case (HR_AMR) {
4207 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
4208 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
4209 }
4210 }
4211 return mode_ie;
4212}
4213
Harald Welte60aa5762018-03-21 19:33:13 +01004214type record CodecListTest {
4215 BSSMAP_IE_SpeechCodecList codec_list,
4216 charstring id
4217}
4218type record of CodecListTest CodecListTests
4219
4220private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004221 f_assignment_codec(id);
4222}
4223
4224private function f_assignment_codec(charstring id, boolean do_perform_clear := true) runs on MSC_ConnHdlr {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004225 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
4226 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
Harald Welte60aa5762018-03-21 19:33:13 +01004227
4228 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02004229 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte79f3f542018-05-25 20:02:37 +02004230 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
4231 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
4232 g_pars.ass_codec_list.codecElements[0];
Philipp Maierd0e64b02019-03-13 14:15:23 +01004233 if (isvalue(g_pars.expect_mr_s0_s7)) {
4234 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
4235 g_pars.expect_mr_s0_s7;
4236 }
Harald Welte79f3f542018-05-25 20:02:37 +02004237 }
Harald Welte60aa5762018-03-21 19:33:13 +01004238 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
4239 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01004240 log("expecting ASS COMPL like this: ", exp_compl);
4241
4242 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01004243
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004244 if (not g_pars.expect_channel_mode_modify) {
4245 /* Verify that the RSL-side activation actually matches our expectations */
4246 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
Harald Weltea63b9102018-03-22 20:36:16 +01004247
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004248 var RSL_IE_Body mode_ie;
4249 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
4250 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02004251 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004252 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004253 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
4254 if (not match(mode_ie, t_mode_ie)) {
4255 log("mode_ie ", mode_ie, " != t_mode_ie ", t_mode_ie);
4256 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004257 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004258
4259 var RSL_IE_Body mr_conf;
4260 if (g_pars.expect_mr_conf_ie != omit) {
4261 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
4262 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
4263 mtc.stop;
4264 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004265 log("found RSL MR CONFIG IE: ", mr_conf);
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004266
4267 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
4268 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
4269 g_pars.expect_mr_conf_ie);
4270 }
4271 } else {
4272 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
4273 log("found RSL MR CONFIG IE: ", mr_conf);
4274 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
4275 mtc.stop;
4276 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004277 }
4278 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004279
4280 if (do_perform_clear) {
4281 f_perform_clear();
4282 }
Harald Welte60aa5762018-03-21 19:33:13 +01004283}
4284
Philipp Maierd0e64b02019-03-13 14:15:23 +01004285private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
4286
4287 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4288 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4289
4290 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02004291 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maierd0e64b02019-03-13 14:15:23 +01004292 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
4293 }
4294 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
4295 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
4296 log("expecting ASS FAIL like this: ", exp_fail);
4297
4298 f_establish_fully(ass_cmd, exp_fail);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004299 f_perform_clear();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004300}
4301
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004302const CounterNameVals counternames_bsc_bts_assignment := {
4303 { "assignment:attempted", 0 },
4304 { "assignment:completed", 0 },
4305 { "assignment:stopped", 0 },
4306 { "assignment:no_channel", 0 },
4307 { "assignment:timeout", 0 },
4308 { "assignment:failed", 0 },
4309 { "assignment:error", 0 }
4310};
4311
4312const CounterNameVals counternames_bts_assignment := {
4313 { "assignment:attempted_sign", 0 },
4314 { "assignment:attempted_speech", 0 },
4315 { "assignment:completed_sign", 0 },
4316 { "assignment:completed_speech", 0 },
4317 { "assignment:stopped_sign", 0 },
4318 { "assignment:stopped_speech", 0 },
4319 { "assignment:no_channel_sign", 0 },
4320 { "assignment:no_channel_speech", 0 },
4321 { "assignment:timeout_sign", 0 },
4322 { "assignment:timeout_speech", 0 },
4323 { "assignment:failed_sign", 0 },
4324 { "assignment:failed_speech", 0 },
4325 { "assignment:error_sign", 0 },
4326 { "assignment:error_speech", 0 }
4327};
4328
4329function f_ctrs_bsc_and_bts_assignment_init(integer bts_count := NUM_BTS) runs on test_CT {
4330 var CounterNameVals bts_names := counternames_bsc_bts_assignment & counternames_bts_assignment;
4331 f_ctrs_bts_init(bts_count, bts_names);
4332 f_ctrs_bsc_init(counternames_bsc_bts_assignment);
4333}
4334
Harald Welte60aa5762018-03-21 19:33:13 +01004335testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004336 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004337 var MSC_ConnHdlr vc_conn;
4338
4339 f_init(1, true);
4340 f_sleep(1.0);
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004341 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004342
4343 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004344 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004345 vc_conn.done;
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004346
4347 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4348 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4349 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4350 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4351 f_ctrs_bts_verify();
4352
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004353 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004354}
4355
4356testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004357 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004358 var MSC_ConnHdlr vc_conn;
4359
4360 f_init(1, true);
4361 f_sleep(1.0);
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004362 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004363
4364 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004365 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004366 vc_conn.done;
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004367
4368 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4369 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4370 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4371 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4372 f_ctrs_bts_verify();
4373
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004374 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004375}
4376
4377testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004378 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004379 var MSC_ConnHdlr vc_conn;
4380
4381 f_init(1, true);
4382 f_sleep(1.0);
4383
4384 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004385 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004386 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004387 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004388}
4389
Philipp Maierd0e64b02019-03-13 14:15:23 +01004390/* Allow 5,90k only (current default config) */
4391private function f_allow_amr_rate_5_90k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00004392 f_vty_cfg_msc(BSCVTY, 0, {
4393 "amr-config 12_2k forbidden",
4394 "amr-config 10_2k forbidden",
4395 "amr-config 7_95k forbidden",
4396 "amr-config 7_40k forbidden",
4397 "amr-config 6_70k forbidden",
4398 "amr-config 5_90k allowed",
4399 "amr-config 5_15k forbidden",
4400 "amr-config 4_75k forbidden"
4401 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01004402}
4403
4404/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
4405 * ("Config-NB-Code = 1") */
4406private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00004407 f_vty_cfg_msc(BSCVTY, 0, {
4408 "amr-config 12_2k allowed",
4409 "amr-config 10_2k forbidden",
4410 "amr-config 7_95k forbidden",
4411 "amr-config 7_40k allowed",
4412 "amr-config 6_70k forbidden",
4413 "amr-config 5_90k allowed",
4414 "amr-config 5_15k forbidden",
4415 "amr-config 4_75k allowed"
4416 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01004417}
4418
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004419private function f_vty_amr_start_mode_set(boolean fr, charstring startmode) runs on test_CT {
4420 var charstring tch;
4421 if (fr) {
4422 tch := "tch-f";
4423 } else {
4424 tch := "tch-h";
4425 }
4426 f_vty_cfg_bts(BSCVTY, 0, { "amr " & tch & " start-mode " & startmode });
4427}
4428
4429/* Set the AMR start-mode for this TCH back to the default configuration. */
4430private function f_vty_amr_start_mode_restore(boolean fr) runs on test_CT {
4431 f_vty_amr_start_mode_set(fr, "auto");
4432}
4433
Harald Welte60aa5762018-03-21 19:33:13 +01004434testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004435 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004436 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02004437
4438 /* Note: This setups the codec configuration. The parameter payload in
4439 * mr_conf must be consistant with the parameter codecElements in pars
4440 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004441 var RSL_IE_Body mr_conf := {
4442 other := {
4443 len := 2,
4444 payload := '2804'O
4445 }
4446 };
Harald Welte60aa5762018-03-21 19:33:13 +01004447
Philipp Maier7695a0d2018-09-27 17:52:14 +02004448 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Philipp Maier806f8f12019-03-12 12:13:41 +01004449 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02004450 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
4451 pars.expect_mr_conf_ie := mr_conf;
4452
Harald Welte60aa5762018-03-21 19:33:13 +01004453 f_init(1, true);
4454 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004455 f_vty_amr_start_mode_set(true, "1");
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004456 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004457
Harald Welte8863fa12018-05-10 20:15:27 +02004458 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004459 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004460
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004461 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4462 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4463 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4464 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4465 f_ctrs_bts_verify();
4466
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004467 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004468 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004469}
4470
4471testcase TC_assignment_codec_amr_h() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004472 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004473 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02004474
4475 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004476 var RSL_IE_Body mr_conf := {
4477 other := {
4478 len := 2,
4479 payload := '2804'O
4480 }
4481 };
Harald Welte60aa5762018-03-21 19:33:13 +01004482
Philipp Maier7695a0d2018-09-27 17:52:14 +02004483 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Philipp Maier806f8f12019-03-12 12:13:41 +01004484 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02004485 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4486 pars.expect_mr_conf_ie := mr_conf;
4487
Harald Welte60aa5762018-03-21 19:33:13 +01004488 f_init(1, true);
4489 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004490 f_vty_amr_start_mode_set(false, "1");
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004491 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004492
Harald Welte8863fa12018-05-10 20:15:27 +02004493 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004494 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004495
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004496 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4497 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4498 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4499 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4500 f_ctrs_bts_verify();
4501
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004502 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004503 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004504}
4505
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004506/* Establish signalling on a TCH/F lchan, and then switch to speech mode without a new Assignment. */
4507testcase TC_assignment_codec_fr_by_mode_modify() runs on test_CT {
4508 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4509 var MSC_ConnHdlr vc_conn;
4510
4511 f_init(1, true);
4512 f_sleep(1.0);
4513
4514 /* By disabling all SDCCH, the MS should be given a TCH/F for signalling. Then activating an FR codec should
4515 * merely do a Channel Mode Modify, and not assign to a new lchan. f_establish_fully() already accounts for
4516 * expecting a Channel Mode Modify if the channel type is compatible. */
4517 f_disable_all_sdcch();
4518 f_disable_all_tch_h();
4519
4520 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4521 pars.expect_channel_mode_modify := true;
4522 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4523 vc_conn.done;
4524
4525 f_enable_all_sdcch();
4526 f_enable_all_tch();
4527 f_shutdown_helper();
4528}
4529
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004530/* 'amr start-mode auto' should not keep the (unused) 'smod' bits from previous configuration */
4531testcase TC_assignment_codec_amr_startmode_cruft() runs on test_CT {
4532 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4533 var MSC_ConnHdlr vc_conn;
4534
4535 var RSL_IE_Body mr_conf := {
4536 other := {
4537 len := 2,
4538 payload := '2004'O /* <- expect ICMI=0, smod=00 */
4539 }
4540 };
4541
4542 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4543 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
4544 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
4545 pars.expect_mr_conf_ie := mr_conf;
4546
4547 f_init(1, true);
4548 f_sleep(1.0);
4549
4550 /* First set nonzero start mode bits */
4551 f_vty_amr_start_mode_set(true, "4");
4552 /* Now set to auto, and expect the startmode bits to be zero in the message, i.e. ensure that osmo-bsc does not
4553 * let the startmode bits stick around and has deterministic MultiRate config for 'start-mode auto'; that is
4554 * ensured by above '2004'O, where 'x0xx'O indicates ICMI = 0, spare = 0, smod = 00. */
4555 f_vty_amr_start_mode_set(true, "auto");
4556
4557 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4558 vc_conn.done;
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004559
4560 /* Clear the startmode bits to not affect subsequent tests, in case the bits should indeed stick around. */
4561 f_vty_amr_start_mode_set(true, "1");
4562 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004563 f_shutdown_helper();
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004564}
4565
Neels Hofmeyr21863562020-11-26 00:34:33 +00004566function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0,
4567 charstring start_mode := "1")
Philipp Maierd0e64b02019-03-13 14:15:23 +01004568runs on test_CT {
4569
4570 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4571 var MSC_ConnHdlr vc_conn;
4572
4573 /* See note above */
4574 var RSL_IE_Body mr_conf := {
4575 other := {
4576 len := lengthof(mrconf),
4577 payload := mrconf
4578 }
4579 };
4580
4581 if (fr) {
4582 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4583 } else {
4584 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4585 }
4586 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4587 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4588 pars.expect_mr_conf_ie := mr_conf;
4589 pars.expect_mr_s0_s7 := exp_s8_s0;
4590
4591 f_init(1, true);
4592 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004593 f_vty_amr_start_mode_set(fr, start_mode);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004594 f_sleep(1.0);
4595
4596 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4597 vc_conn.done;
4598 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004599 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004600}
4601
4602function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
4603runs on test_CT {
4604
4605 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4606 var MSC_ConnHdlr vc_conn;
4607
4608 if (fr) {
4609 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4610 } else {
4611 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4612 }
4613 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4614 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4615
4616 f_init(1, true);
4617 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004618 f_vty_amr_start_mode_set(fr, "1");
Philipp Maierd0e64b02019-03-13 14:15:23 +01004619 f_sleep(1.0);
4620
4621 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
4622 vc_conn.done;
4623 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004624 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004625}
4626
4627
4628/* Set S1, we expect an AMR multirate configuration IE with all four rates
4629 * set. */
4630testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004631 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004632 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004633}
4634
4635/* Set S1, we expect an AMR multirate configuration IE with the lower three
4636 * rates set. */
4637testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004638 f_TC_assignment_codec_amr(false, '2815208820'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004639 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004640}
4641
4642/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4643 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4644testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004645 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004646 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004647}
4648
4649/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4650 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4651testcase TC_assignment_codec_amr_h_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004652 f_TC_assignment_codec_amr(false, '2815208820'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004653 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004654}
4655
4656/* The following block of tests selects more and more rates until all four
4657 * possible rates are in the active set (full rate) */
4658testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004659 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004660 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004661}
4662
4663testcase TC_assignment_codec_amr_f_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004664 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004665 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004666}
4667
4668testcase TC_assignment_codec_amr_f_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004669 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004670 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004671}
4672
4673testcase TC_assignment_codec_amr_f_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004674 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004675 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004676}
4677
4678/* The following block of tests selects more and more rates until all three
4679 * possible rates are in the active set (half rate) */
4680testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004681 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004682 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004683}
4684
4685testcase TC_assignment_codec_amr_h_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004686 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004687 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004688}
4689
4690testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004691 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004692 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004693}
4694
4695/* The following block tests what happens when the MSC does offer rate
4696 * configurations that are not supported by the BSC. Normally such situations
4697 * should not happen because the MSC gets informed by the BSC in advance via
4698 * the L3 COMPLETE message which rates are applicable. The MSC should not try
4699 * to offer rates that are not applicable anyway. */
4700
4701testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004702 /* Try to include 12,2k in into the active set even though the channel
4703 * is half rate only. The BSC is expected to remove the 12,0k */
4704 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'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_S01234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004709 /* See what happens when all rates are selected at once. Since then
4710 * Also S1 is selected, this setting will be prefered and we should
4711 * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
4712 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004713 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004714}
4715
4716testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004717 /* Same as above, but with S1 missing, the MSC is then expected to
4718 * select the currently supported rates, which are also 12.2k, 7,40k,
4719 * 5,90k, and 4,75k, into the active set. */
4720 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004721 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004722}
4723
4724testcase TC_assignment_codec_amr_f_zero() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004725 /* Try to select no rates at all */
4726 f_TC_assignment_codec_amr_fail(true, '00000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004727 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004728}
4729
4730testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004731 /* Try to select only unsupported rates */
4732 f_TC_assignment_codec_amr_fail(true, '01101000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004733 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004734}
4735
4736testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004737 /* Try to select 12,2k for half rate */
4738 f_TC_assignment_codec_amr_fail(false, '10000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004739 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004740}
4741
Neels Hofmeyr21863562020-11-26 00:34:33 +00004742testcase TC_assignment_codec_amr_f_start_mode_auto() runs on test_CT {
4743 f_TC_assignment_codec_amr(true, '209520882208'O, '11111111'B, '00000010'B,
4744 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004745 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004746}
4747
4748testcase TC_assignment_codec_amr_h_start_mode_auto() runs on test_CT {
4749 f_TC_assignment_codec_amr(false, '2015208820'O, '10010101'B, '00010101'B,
4750 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004751 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004752}
4753
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004754testcase TC_assignment_codec_amr_f_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004755 /* "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 +00004756 f_TC_assignment_codec_amr(true, '2b9520882208'O, '11111111'B, '00000010'B,
4757 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004758 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004759}
4760
4761testcase TC_assignment_codec_amr_h_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004762 /* "amr tch-h modes 0 2 4" => total 3 modes and start mode 4 => '10'B on the wire */
4763 f_TC_assignment_codec_amr(false, '2a15208820'O, '10010101'B, '00010101'B,
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004764 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004765 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004766}
4767
Philipp Maierac09bfc2019-01-08 13:41:39 +01004768private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004769 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
4770 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
4771 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
4772 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004773}
4774
4775private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004776 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
4777 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004778}
4779
4780private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004781 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
4782 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
4783 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
4784 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
4785 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
4786 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004787}
4788
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004789private function f_disable_all_sdcch() runs on test_CT {
4790 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 borken");
4791 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 borken");
4792 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 borken");
4793 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 borken");
4794}
4795
4796private function f_enable_all_sdcch() runs on test_CT {
4797 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 unused");
4798 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 unused");
4799 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 unused");
4800 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 unused");
4801}
4802
Philipp Maierac09bfc2019-01-08 13:41:39 +01004803/* Allow HR only */
4804private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
4805 g_pars := f_gen_test_hdlr_pars();
4806 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4807 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4808 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4809 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4810 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4811 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4812 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004813 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004814}
4815
4816/* Allow FR only */
4817private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
4818 g_pars := f_gen_test_hdlr_pars();
4819 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4820 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4821 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4822 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4823 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4824 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4825 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004826 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004827}
4828
4829/* Allow HR only (expect assignment failure) */
4830private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
4831 g_pars := f_gen_test_hdlr_pars();
4832 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4833 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4834 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4835 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4836 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4837 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4838 f_establish_fully(ass_cmd, exp_fail);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004839 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004840}
4841
4842/* Allow FR only (expect assignment failure) */
4843private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(charstring id) runs on MSC_ConnHdlr {
4844 g_pars := f_gen_test_hdlr_pars();
4845 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4846 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4847 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4848 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4849 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4850 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4851 f_establish_fully(ass_cmd, exp_fail);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004852 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004853}
4854
4855/* Allow FR and HR, but prefer FR */
4856private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4857 g_pars := f_gen_test_hdlr_pars();
4858 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4859 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4860 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4861 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4862 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4863 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4864 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4865 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004866 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004867}
4868
4869/* Allow FR and HR, but prefer HR */
4870private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4871 g_pars := f_gen_test_hdlr_pars();
4872 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4873 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4874 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4875 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4876 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4877 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4878 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4879 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004880 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004881}
4882
4883/* Allow FR and HR, but prefer FR */
4884private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4885 g_pars := f_gen_test_hdlr_pars();
4886 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4887 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4888 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4889 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4890 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4891 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4892 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4893 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004894 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004895}
4896
4897/* Allow FR and HR, but prefer HR */
4898private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4899 g_pars := f_gen_test_hdlr_pars();
4900 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4901 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4902 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4903 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4904 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4905 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4906 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4907 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004908 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004909}
4910
4911/* Request a HR channel while all FR channels are exhausted, this is expected
4912 * to work without conflicts */
4913testcase TC_assignment_codec_fr_exhausted_req_hr() runs on test_CT {
4914 var MSC_ConnHdlr vc_conn;
4915 f_init(1, true);
4916 f_sleep(1.0);
4917 f_enable_all_tch();
4918 f_disable_all_tch_f();
4919 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr));
4920 vc_conn.done;
4921 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004922 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004923}
4924
4925/* Request a FR channel while all FR channels are exhausted, this is expected
4926 * to fail. */
4927testcase TC_assignment_codec_fr_exhausted_req_fr() runs on test_CT {
4928 var MSC_ConnHdlr vc_conn;
4929 f_init(1, true);
4930 f_sleep(1.0);
4931 f_enable_all_tch();
4932 f_disable_all_tch_f();
4933 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr_fail));
4934 vc_conn.done;
4935 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004936 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004937}
4938
4939/* Request a FR (prefered) or alternatively a HR channel while all FR channels
4940 * are exhausted, this is expected to be resolved by selecting a HR channel. */
4941testcase TC_assignment_codec_fr_exhausted_req_fr_hr() runs on test_CT {
4942 var MSC_ConnHdlr vc_conn;
4943 f_init(1, true);
4944 f_sleep(1.0);
4945 f_enable_all_tch();
4946 f_disable_all_tch_f();
4947 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
4948 vc_conn.done;
4949 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004950 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004951}
4952
4953/* Request a HR (prefered) or alternatively a FR channel while all FR channels
4954 * are exhausted, this is expected to work without conflicts. */
4955testcase TC_assignment_codec_fr_exhausted_req_hr_fr() runs on test_CT {
4956 var MSC_ConnHdlr vc_conn;
4957 f_init(1, true);
4958 f_sleep(1.0);
4959 f_enable_all_tch();
4960 f_disable_all_tch_f();
4961 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_hr_fr));
4962 vc_conn.done;
4963 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004964 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004965}
4966
4967/* Request a FR channel while all HR channels are exhausted, this is expected
4968 * to work without conflicts */
4969testcase TC_assignment_codec_hr_exhausted_req_fr() runs on test_CT {
4970 var MSC_ConnHdlr vc_conn;
4971 f_init(1, true);
4972 f_sleep(1.0);
4973 f_enable_all_tch();
4974 f_disable_all_tch_h();
4975 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr));
4976 vc_conn.done;
4977 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004978 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004979}
4980
4981/* Request a HR channel while all HR channels are exhausted, this is expected
4982 * to fail. */
4983testcase TC_assignment_codec_hr_exhausted_req_hr() runs on test_CT {
4984 var MSC_ConnHdlr vc_conn;
4985 f_init(1, true);
4986 f_sleep(1.0);
4987 f_enable_all_tch();
4988 f_disable_all_tch_h();
4989 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr_fail));
4990 vc_conn.done;
4991 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004992 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004993}
4994
4995/* Request a HR (prefered) or alternatively a FR channel while all HR channels
4996 * are exhausted, this is expected to be resolved by selecting a FR channel. */
4997testcase TC_assignment_codec_hr_exhausted_req_hr_fr() runs on test_CT {
4998 var MSC_ConnHdlr vc_conn;
4999 f_init(1, true);
5000 f_sleep(1.0);
5001 f_enable_all_tch();
5002 f_disable_all_tch_h();
5003 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_hr_fr));
5004 vc_conn.done;
5005 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005006 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01005007}
5008
5009/* Request a FR (prefered) or alternatively a HR channel while all HR channels
5010 * are exhausted, this is expected to work without conflicts. */
5011testcase TC_assignment_codec_hr_exhausted_req_fr_hr() runs on test_CT {
5012 var MSC_ConnHdlr vc_conn;
5013 f_init(1, true);
5014 f_sleep(1.0);
5015 f_enable_all_tch();
5016 f_disable_all_tch_h();
5017 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_fr_hr));
5018 vc_conn.done;
5019 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005020 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01005021}
5022
5023/* Allow FR and HR, but prefer HR */
5024private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
5025 g_pars := f_gen_test_hdlr_pars();
5026 var PDU_BSSAP ass_cmd := f_gen_ass_req();
5027 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5028 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5029 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
5030 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
5031 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
5032 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
5033 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005034 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01005035}
5036
5037/* Allow FR and HR, but prefer FR */
5038private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
5039 g_pars := f_gen_test_hdlr_pars();
5040 var PDU_BSSAP ass_cmd := f_gen_ass_req();
5041 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5042 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5043 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
5044 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
5045 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
5046 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
5047 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005048 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01005049}
5050
5051/* Request a HR (prefered) or alternatively a FR channel, it is expected that
5052 * HR, which is the prefered type, is selected. */
5053testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
5054 var MSC_ConnHdlr vc_conn;
5055 f_init(1, true);
5056 f_sleep(1.0);
5057 f_enable_all_tch();
5058 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
5059 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005060 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01005061}
5062
5063/* Request a FR (prefered) or alternatively a HR channel, it is expected that
5064 * FR, which is the prefered type, is selected. */
5065testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
5066 var MSC_ConnHdlr vc_conn;
5067 f_init(1, true);
5068 f_sleep(1.0);
5069 f_enable_all_tch();
5070 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
5071 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005072 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01005073}
5074
Pau Espin Pedrol14475352021-07-22 15:48:16 +02005075/* request a signalling channel with all SDCCH exhausted, it is expected that a TCH will be selected */
5076private function f_TC_assignment_sdcch_exhausted_req_signalling(charstring id) runs on MSC_ConnHdlr {
5077 g_pars := f_gen_test_hdlr_pars();
5078 g_pars.ra := '02'O; /* RA containing reason=LU */
5079
5080 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
5081 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
5082 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
5083 var template uint3_t tsc := ?;
5084
5085 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
5086 f_create_bssmap_exp(l3_enc);
5087 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
5088 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, tsc);
5089
5090 /* we should now have a COMPL_L3 at the MSC */
5091 timer T := 10.0;
5092 T.start;
5093 alt {
5094 [] BSSAP.receive(tr_BSSMAP_ComplL3);
5095 [] T.timeout {
5096 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
5097 }
5098 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005099
5100 f_perform_clear();
Pau Espin Pedrol14475352021-07-22 15:48:16 +02005101}
5102testcase TC_assignment_sdcch_exhausted_req_signalling() runs on test_CT {
5103 var MSC_ConnHdlr vc_conn;
5104 f_init(1, true);
5105 f_sleep(1.0);
5106 f_disable_all_sdcch();
5107 vc_conn := f_start_handler(refers(f_TC_assignment_sdcch_exhausted_req_signalling));
5108 vc_conn.done;
5109 f_enable_all_sdcch();
5110 f_shutdown_helper();
5111}
5112
5113/* Request a signalling channel with all SDCCH exhausted, it is
5114 expected that no TCH will be selected for signalling and assigment will fail
5115 because it's dictated by VTY config */
5116testcase TC_assignment_sdcch_exhausted_req_signalling_tch_forbidden() runs on test_CT {
5117 var RSL_Message rsl_unused, rsl_msg;
5118 var GsmRrMessage rr;
5119 f_init(1, false);
5120 f_sleep(1.0);
5121 f_vty_allow_tch_for_signalling(false, 0);
5122 f_disable_all_sdcch();
5123
5124 /* RA containing reason=LU */
5125 f_ipa_tx(0, ts_RSL_CHAN_RQD('02'O, 2342));
5126 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
5127 rr := dec_GsmRrMessage(rsl_msg.ies[1].body.full_imm_ass_info.payload);
5128 if (rr.header.message_type != IMMEDIATE_ASSIGNMENT_REJECT) {
5129 setverdict(fail, "Expected reject");
5130 }
5131
5132 f_vty_allow_tch_for_signalling(true, 0);
5133 f_enable_all_sdcch();
5134 f_shutdown_helper();
5135}
5136
5137/* Request a voice channel with all SDCCH exhausted, it is
5138 * expected that TCH channel will be allocated since the VTY option is only
5139 * aimed at signalling requests */
5140private function f_TC_assignment_sdcch_exhausted_req_voice_tch_forbidden(charstring id) runs on MSC_ConnHdlr {
5141 g_pars := f_gen_test_hdlr_pars();
5142 g_pars.ra := '43'O; /* RA containing reason=originating speech call*/
5143
5144 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
5145 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
5146 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
5147 var template uint3_t tsc := ?;
5148
5149 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
5150 f_create_bssmap_exp(l3_enc);
5151 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
5152 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, tsc);
5153
5154 /* we should now have a COMPL_L3 at the MSC */
5155 timer T := 10.0;
5156 T.start;
5157 alt {
5158 [] BSSAP.receive(tr_BSSMAP_ComplL3);
5159 [] T.timeout {
5160 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
5161 }
5162 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005163 f_perform_clear();
Pau Espin Pedrol14475352021-07-22 15:48:16 +02005164}
5165testcase TC_assignment_sdcch_exhausted_req_voice_tch_forbidden() runs on test_CT {
5166 var MSC_ConnHdlr vc_conn;
5167 f_init(1, true);
5168 f_sleep(1.0);
5169 f_vty_allow_tch_for_signalling(false, 0);
5170 f_disable_all_sdcch();
5171
5172 vc_conn := f_start_handler(refers(f_TC_assignment_sdcch_exhausted_req_voice_tch_forbidden));
5173 vc_conn.done;
5174
5175 f_vty_allow_tch_for_signalling(true, 0);
5176 f_enable_all_sdcch();
5177 f_shutdown_helper();
5178}
5179
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005180testcase TC_assignment_osmux() runs on test_CT {
5181 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5182 var MSC_ConnHdlr vc_conn;
5183
5184 /* See note above */
5185 var RSL_IE_Body mr_conf := {
5186 other := {
5187 len := 2,
5188 payload := '2804'O
5189 }
5190 };
5191
5192 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
5193 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
5194 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
5195 pars.expect_mr_conf_ie := mr_conf;
5196 pars.use_osmux := true;
5197
5198 f_init(1, true, true);
5199 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00005200 f_vty_amr_start_mode_set(false, "1");
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005201
5202 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
5203 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00005204
5205 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01005206 f_shutdown_helper();
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005207}
5208
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02005209/* test the procedure of the MSC requesting a Classmark Update:
5210 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
5211 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01005212private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005213 g_pars := f_gen_test_hdlr_pars();
5214
Harald Weltea0630032018-03-20 21:09:55 +01005215 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01005216 /* we should now have a COMPL_L3 at the MSC */
Harald Welte898113b2018-01-31 18:32:21 +01005217
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02005218 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
5219 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
5220
Harald Welte898113b2018-01-31 18:32:21 +01005221 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
5222 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
5223 setverdict(pass);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005224
5225 f_perform_clear();
Harald Welte898113b2018-01-31 18:32:21 +01005226}
5227testcase TC_classmark() runs on test_CT {
5228 var MSC_ConnHdlr vc_conn;
5229 f_init(1, true);
5230 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005231 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01005232 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005233 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01005234}
5235
Harald Welteeddf0e92020-06-21 19:42:15 +02005236/* Send a CommonID from the simulated MSC and verify that the information is used to
5237 * fill BSC-internal data structures (specifically, bsc_subscr associated with subscr_conn) */
5238private function f_tc_common_id(charstring id) runs on MSC_ConnHdlr {
5239 g_pars := f_gen_test_hdlr_pars();
5240 f_MscConnHdlr_init_vty();
5241
5242 f_create_chan_and_exp();
5243 /* we should now have a COMPL_L3 at the MSC */
Harald Welteeddf0e92020-06-21 19:42:15 +02005244
5245 /* Send CommonID */
5246 BSSAP.send(ts_BSSMAP_CommonId(g_pars.imsi));
5247
5248 /* Use VTY to verify that the IMSI of the subscr_conn is set */
5249 var charstring regex := "*(IMSI: " & hex2str(g_pars.imsi) & ")*";
5250 f_vty_transceive_match_regexp_retry(BSCVTY, "show conns", regex, 0, 4, 1.0);
5251
5252 setverdict(pass);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005253
5254 f_perform_clear();
Harald Welteeddf0e92020-06-21 19:42:15 +02005255}
5256testcase TC_common_id() runs on test_CT {
5257 var MSC_ConnHdlr vc_conn;
5258 f_init(1, true);
5259 f_sleep(1.0);
5260 vc_conn := f_start_handler(refers(f_tc_common_id));
5261 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005262 f_shutdown_helper();
Harald Welteeddf0e92020-06-21 19:42:15 +02005263}
5264
Harald Weltee3bd6582018-01-31 22:51:25 +01005265private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005266 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01005267 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01005268 /* we should now have a COMPL_L3 at the MSC */
Harald Welte898113b2018-01-31 18:32:21 +01005269
Harald Weltee3bd6582018-01-31 22:51:25 +01005270 /* send the single message we want to send */
5271 f_rsl_send_l3(l3);
5272}
5273
5274private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
5275 timer T := sec;
5276 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01005277 T.start;
5278 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01005279 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
5280 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02005281 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01005282 }
5283 [] T.timeout {
5284 setverdict(pass);
5285 }
5286 }
5287}
5288
Harald Weltee3bd6582018-01-31 22:51:25 +01005289/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
5290private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
5291 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
5292 f_bssap_expect_nothing();
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005293 f_perform_clear();
Harald Weltee3bd6582018-01-31 22:51:25 +01005294}
Harald Welte898113b2018-01-31 18:32:21 +01005295testcase TC_unsol_ass_fail() 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_fail));
Harald Welte898113b2018-01-31 18:32:21 +01005300 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005301 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01005302}
Harald Welte552620d2017-12-16 23:21:36 +01005303
Harald Welteea99a002018-01-31 20:46:43 +01005304
5305/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
5306private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01005307 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
5308 f_bssap_expect_nothing();
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005309 f_perform_clear();
Harald Welteea99a002018-01-31 20:46:43 +01005310}
5311testcase TC_unsol_ass_compl() 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_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01005316 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005317 f_shutdown_helper();
Harald Welteea99a002018-01-31 20:46:43 +01005318}
5319
5320
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005321/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
5322private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01005323 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
5324 f_bssap_expect_nothing();
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005325 f_perform_clear();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005326}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005327testcase TC_unsol_ho_fail() runs on test_CT {
5328 var MSC_ConnHdlr vc_conn;
5329 f_init(1, true);
5330 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005331 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005332 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005333 f_shutdown_helper();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005334}
5335
5336
Harald Weltee3bd6582018-01-31 22:51:25 +01005337/* short message from MS should be ignored */
5338private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005339 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01005340 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01005341 /* we should now have a COMPL_L3 at the MSC */
Harald Weltee3bd6582018-01-31 22:51:25 +01005342
5343 /* send short message */
5344 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
5345 f_bssap_expect_nothing();
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005346 f_perform_clear();
Harald Weltee3bd6582018-01-31 22:51:25 +01005347}
5348testcase TC_err_82_short_msg() runs on test_CT {
5349 var MSC_ConnHdlr vc_conn;
5350 f_init(1, true);
5351 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005352 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01005353 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005354 f_shutdown_helper();
Harald Weltee3bd6582018-01-31 22:51:25 +01005355}
5356
5357
Harald Weltee9e02e42018-01-31 23:36:25 +01005358/* 24.008 8.4 Unknown message must trigger RR STATUS */
5359private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
5360 f_est_single_l3(ts_RRM_UL_REL('00'O));
5361 timer T := 3.0
5362 alt {
5363 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
5364 setverdict(pass);
5365 }
5366 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01005367 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01005368 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005369 f_perform_clear();
Harald Weltee9e02e42018-01-31 23:36:25 +01005370}
5371testcase TC_err_84_unknown_msg() runs on test_CT {
5372 var MSC_ConnHdlr vc_conn;
5373 f_init(1, true);
5374 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005375 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01005376 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005377 f_shutdown_helper();
Harald Weltee9e02e42018-01-31 23:36:25 +01005378}
5379
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005380/***********************************************************************
5381 * Handover
5382 ***********************************************************************/
5383
Harald Welte94e0c342018-04-07 11:33:23 +02005384/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
5385private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
5386runs on test_CT {
5387 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
5388 " timeslot "&int2str(ts_nr)&" ";
5389 f_vty_transceive(BSCVTY, cmd & suffix);
5390}
5391
Harald Welte261af4b2018-02-12 21:20:39 +01005392/* 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 +07005393private function f_vty_ss_action(TELNETasp_PT pt, charstring suffix,
5394 uint8_t bts_nr, uint8_t trx_nr,
5395 in RslChannelNr chan_nr)
5396{
Harald Welte261af4b2018-02-12 21:20:39 +01005397 /* FIXME: resolve those from component-global state */
5398 var integer ts_nr := chan_nr.tn;
5399 var integer ss_nr;
5400 if (ischosen(chan_nr.u.ch0)) {
5401 ss_nr := 0;
5402 } else if (ischosen(chan_nr.u.lm)) {
5403 ss_nr := chan_nr.u.lm.sub_chan;
5404 } else if (ischosen(chan_nr.u.sdcch4)) {
5405 ss_nr := chan_nr.u.sdcch4.sub_chan;
5406 } else if (ischosen(chan_nr.u.sdcch8)) {
5407 ss_nr := chan_nr.u.sdcch8.sub_chan;
5408 } else {
5409 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02005410 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01005411 }
5412
5413 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
5414 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005415 f_vty_transceive(pt, cmd & suffix);
Harald Welte261af4b2018-02-12 21:20:39 +01005416}
5417
Neels Hofmeyr91401012019-07-11 00:42:35 +02005418/* Even though the VTY command to trigger handover takes a new BTS number as argument, behind the scenes osmo-bsc always
5419 * translates that to a target ARFCN+BSIC first. See bsc_vty.c trigger_ho_or_as(), which puts the selected BTS' neighbor
5420 * ident key (ARFCN + BSIC) in the struct passed on to handover_request(). handover_start() then resolves that to a
5421 * viable actual neighbor cell. So from the internal osmo-bsc perspective, we always request handover to an ARFCN + BSIC
5422 * pair, not really to a specific BTS number. */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005423private function f_vty_handover(TELNETasp_PT pt, uint8_t bts_nr, uint8_t trx_nr,
5424 in RslChannelNr chan_nr, uint8_t new_bts_nr)
5425{
5426 f_vty_ss_action(pt, "handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
Harald Welte261af4b2018-02-12 21:20:39 +01005427}
5428
5429/* intra-BSC hand-over between BTS0 and BTS1 */
5430private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02005431 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5432 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01005433
5434 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5435 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5436
Harald Weltea0630032018-03-20 21:09:55 +01005437 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005438 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Harald Welte261af4b2018-02-12 21:20:39 +01005439
5440 var HandoverState hs := {
5441 rr_ho_cmpl_seen := false,
5442 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02005443 old_chan_nr := -,
5444 expect_target_tsc := BTS_TSC[1]
Harald Welte261af4b2018-02-12 21:20:39 +01005445 };
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005446 /* issue hand-over command on VTY, from BTS 0 to BTS 1 */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005447 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
Harald Welte261af4b2018-02-12 21:20:39 +01005448 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
5449 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005450
5451 /* From the MGW perspective, a handover is is characterized by
5452 * performing one MDCX operation with the MGW. So we expect to see
5453 * one more MDCX during handover. */
5454 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
5455
Harald Welte261af4b2018-02-12 21:20:39 +01005456 alt {
5457 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01005458 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005459
Philipp Maier4dae0652018-11-12 12:03:26 +01005460 /* Since this is an internal handover we expect the BSC to inform the
5461 * MSC about the event */
5462 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
5463
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005464 /* Check the amount of MGCP transactions is still consistant with the
5465 * test expectation */
5466 f_check_mgcp_expectations()
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005467
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005468 var RSL_Message chan_act := f_rslem_get_last_act(RSL1_PROC, 0, g_chan_nr);
5469
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005470 /* Ensure the Channel Activation for the new channel contained the right encryption params. as_handover() set
5471 * 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 +02005472 f_verify_encr_info(chan_act);
5473
5474 f_chan_act_verify_tsc(chan_act, BTS_TSC[1]);
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005475
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005476 f_perform_clear(RSL1, RSL1_PROC);
5477
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01005478 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01005479}
5480
5481testcase TC_ho_int() runs on test_CT {
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02005482 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte261af4b2018-02-12 21:20:39 +01005483 var MSC_ConnHdlr vc_conn;
5484 f_init(2, true);
5485 f_sleep(1.0);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005486
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005487 pars.expect_tsc := BTS_TSC[0];
5488
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005489 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005490
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02005491 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
Harald Welte261af4b2018-02-12 21:20:39 +01005492 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005493
5494 /* from f_establish_fully() */
5495 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5496 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5497 /* from handover */
5498 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5499 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5500 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5501 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005502 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5503 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:completed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005504 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005505 f_shutdown_helper();
Harald Welte261af4b2018-02-12 21:20:39 +01005506}
Harald Weltee9e02e42018-01-31 23:36:25 +01005507
Oliver Smith7eabd312021-07-12 14:18:56 +02005508function 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 +02005509 var MSC_ConnHdlr vc_conn;
5510 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5511 pars.encr := valueof(t_EncrParams(encr_alg, f_rnd_octstring(8), f_rnd_octstring(16)));
5512
5513 f_init(2, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02005514 f_vty_encryption_a5(enc_a5);
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005515 f_sleep(1.0);
5516
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005517 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005518
5519 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
5520 vc_conn.done;
5521
5522 /* from f_establish_fully() */
5523 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5524 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5525 /* from handover */
5526 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5527 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5528 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5529 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005530 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5531 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:completed");
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005532 f_ctrs_bsc_and_bts_verify();
Oliver Smith7eabd312021-07-12 14:18:56 +02005533 f_vty_encryption_a5_reset();
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005534 f_shutdown_helper();
5535}
5536
5537testcase TC_ho_int_a5_0() runs on test_CT {
5538 f_tc_ho_int_a5('01'O);
5539}
5540
5541testcase TC_ho_int_a5_1() runs on test_CT {
5542 f_tc_ho_int_a5('02'O);
5543}
5544
5545testcase TC_ho_int_a5_3() runs on test_CT {
5546 f_tc_ho_int_a5('08'O);
5547}
5548
5549testcase TC_ho_int_a5_4() runs on test_CT {
Oliver Smith7eabd312021-07-12 14:18:56 +02005550 f_tc_ho_int_a5('10'O, "0 1 3 4");
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005551}
5552
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005553/* intra-BSC hand-over with CONNection FAILure and cause Radio Link Failure: check RR release cause */
5554private function f_tc_ho_int_radio_link_failure(charstring id) runs on MSC_ConnHdlr {
5555 g_pars := f_gen_test_hdlr_pars();
5556 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5557 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005558
5559 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5560 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5561
5562 f_establish_fully(ass_cmd, exp_compl);
5563 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
5564
5565 var HandoverState hs := {
5566 rr_ho_cmpl_seen := false,
5567 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02005568 old_chan_nr := -,
5569 expect_target_tsc := BTS_TSC[1]
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005570 };
5571 /* issue hand-over command on VTY */
5572 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
5573 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
5574 f_rslem_suspend(RSL1_PROC);
5575
5576 /* From the MGW perspective, a handover is is characterized by
5577 * performing one MDCX operation with the MGW. So we expect to see
5578 * one more MDCX during handover. */
5579 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
5580
5581 var RSL_Message rsl;
5582 var PDU_ML3_NW_MS l3;
5583 var RslChannelNr new_chan_nr;
5584 var GsmArfcn arfcn;
5585 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
5586 l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
5587 if (not ischosen(l3.msgs.rrm.handoverCommand)) {
5588 setverdict(fail, "Expected handoverCommand");
5589 mtc.stop;
5590 }
5591 }
5592 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
5593 new_chan_nr, arfcn);
5594
5595 f_rslem_register(0, new_chan_nr, RSL1_PROC);
5596
5597 /* resume processing of RSL DChan messages, which was temporarily suspended
5598 * before performing a hand-over */
5599 f_rslem_resume(RSL1_PROC);
5600 RSL1.receive(tr_RSL_IPA_CRCX(new_chan_nr));
5601
5602 f_sleep(1.0);
5603
5604 /* Handover fails because no HANDO DET appears on the new lchan,
5605 * and the old lchan reports a Radio Link Failure. */
5606 RSL.send(ts_RSL_CONN_FAIL_IND(g_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
5607
5608 var PDU_BSSAP rx_clear_request;
5609 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
5610 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5611 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5612
5613 var RR_Cause rr_cause := GSM48_RR_CAUSE_ABNORMAL_UNSPEC;
5614
5615 var MgcpCommand mgcp;
5616 interleave {
5617 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE(int2oct(enum2int(rr_cause), 1)))) {}
5618 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005619 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005620 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005621 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005622 }
5623 [] RSL1.receive(tr_RSL_DEACT_SACCH(new_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005624 [] RSL1.receive(tr_RSL_RF_CHAN_REL(new_chan_nr)) {
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005625 RSL1.send(ts_RSL_RF_CHAN_REL_ACK(new_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005626 f_rslem_unregister(0, g_chan_nr, PT := RSL1_PROC);
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005627 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005628 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
5629 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
5630 }
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005631 }
5632
5633 f_sleep(0.5);
5634 setverdict(pass);
5635}
5636testcase TC_ho_int_radio_link_failure() runs on test_CT {
5637 var MSC_ConnHdlr vc_conn;
5638 f_init(2, true);
5639 f_sleep(1.0);
5640
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005641 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005642
5643 vc_conn := f_start_handler(refers(f_tc_ho_int_radio_link_failure));
5644 vc_conn.done;
5645
5646 /* from f_establish_fully() */
5647 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5648 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5649 /* from handover */
5650 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5651 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
5652 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5653 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:stopped");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005654 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5655 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:stopped");
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005656 f_ctrs_bsc_and_bts_verify();
5657 f_shutdown_helper();
5658}
5659
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005660/* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005661private function f_expect_dlcx_conns() runs on MSC_ConnHdlr {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005662 var MgcpCommand mgcp;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005663 var template MgcpResponse mgcp_resp;
5664 var MGCP_RecvFrom mrf;
5665 var template MgcpMessage msg_resp;
5666 var template MgcpMessage msg_dlcx := {
5667 command := tr_DLCX()
5668 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005669
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005670 if (g_pars.aoip) {
5671 MGCP.receive(tr_DLCX()) -> value mgcp {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005672 log("Got first DLCX: ", mgcp);
5673 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005674 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005675
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005676 MGCP.receive(tr_DLCX()) -> value mgcp {
5677 log("Got second DLCX: ", mgcp);
5678 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
5679 };
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005680 } else {
5681 /* For SCCPLite, BSC doesn't handle the MSC-side */
5682 MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_dlcx)) -> value mrf {
5683 log("Got first DLCX: ", mrf.msg.command);
5684 msg_resp := {
5685 response := ts_DLCX_ACK2(mrf.msg.command.line.trans_id)
5686 }
5687 MGCP_MULTI.send(t_MGCP_SendToMrf(mrf, msg_resp));
5688 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005689 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005690}
5691
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005692private 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 +01005693
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005694 var NcellReports neighbor_rep := {
5695 { rxlev := 20, bcch_freq := 0, bsic := 11 }
5696 };
5697 var octetstring l3_mr := enc_GsmRrL3Message(valueof(ts_MEAS_REP(true, 8, 8, reps := neighbor_rep)));
5698 RSL.send(ts_RSL_MEAS_RES(g_chan_nr, 0, ts_RSL_IE_UplinkMeas, ts_RSL_IE_BS_Power(0), ts_RSL_IE_L1Info,
5699 l3_mr, 0));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005700
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005701 BSSAP.receive(tr_BSSMAP_HandoverRequired(exp_oldToNewBSSIEs));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005702
5703 f_sleep(0.5);
5704 /* The MSC negotiates Handover Request and Handover Request Ack with
5705 * the other BSS and comes back with a BSSMAP Handover Command
5706 * containing an RR Handover Command coming from the target BSS... */
5707
5708 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5709 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5710 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5711 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5712 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5713
5714 /* expect the Handover Command to go out on RR */
5715 var RSL_Message rsl_ho_cmd
5716 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5717 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5718 var RSL_IE_Body rsl_ho_cmd_l3;
5719 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5720 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5721 setverdict(fail);
5722 } else {
5723 log("Found L3 Info: ", rsl_ho_cmd_l3);
5724 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5725 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5726 setverdict(fail);
5727 } else {
5728 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5729 setverdict(pass);
5730 }
5731 }
5732
5733 /* When the other BSS has reported a completed handover, this side is
5734 * torn down. */
5735
5736 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
5737 var BssmapCause cause := enum2int(cause_val);
5738 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5739
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005740 f_expect_dlcx_conns();
Pau Espin Pedrol06199952021-06-15 11:30:00 +02005741
5742 interleave {
5743 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE));
5744 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr));
5745 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr));
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005746 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
5747 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
5748 }
Pau Espin Pedrol06199952021-06-15 11:30:00 +02005749 }
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005750 setverdict(pass);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005751}
5752
5753private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
5754 g_pars := f_gen_test_hdlr_pars();
5755 var PDU_BSSAP ass_req := f_gen_ass_req();
5756 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5757 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5758 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5759 f_establish_fully(ass_req, exp_compl);
5760
5761 f_ho_out_of_this_bsc();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005762}
5763testcase TC_ho_out_of_this_bsc() runs on test_CT {
5764 var MSC_ConnHdlr vc_conn;
5765
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005766 f_init_vty();
5767 f_bts_0_cfg(BSCVTY,
5768 {"neighbor-list mode automatic",
5769 "handover 1",
5770 "handover algorithm 2",
5771 "handover2 window rxlev averaging 1",
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005772 "no neighbors",
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005773 "neighbor lac 99 arfcn 123 bsic any"});
5774 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5775
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005776 f_init(1, true);
5777 f_sleep(1.0);
5778
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005779 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005780
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005781 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
5782 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005783
5784 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5785 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5786 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5787 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5788 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5789 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed");
5790 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005791 f_shutdown_helper();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005792}
5793
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005794private function f_mo_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5795 template (value) RslLinkId link_id := ts_RslLinkID_DCCH(0),
Vadim Yanitskiy2ef6a2f2020-10-08 23:17:32 +07005796 template (present) OCT1 dlci := ?,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005797 octetstring l3 := '0123456789'O)
5798runs on MSC_ConnHdlr {
Neels Hofmeyr43654812020-09-25 01:35:35 +02005799 /* The old lchan and conn should still be active. See that arbitrary L3
5800 * is still going through. */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005801 rsl.send(ts_RSL_DATA_IND(g_chan_nr, link_id, l3));
Neels Hofmeyr43654812020-09-25 01:35:35 +02005802 var template PDU_BSSAP exp_data := {
5803 discriminator := '1'B,
5804 spare := '0000000'B,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005805 dlci := dlci,
5806 lengthIndicator := lengthof(l3),
Neels Hofmeyr43654812020-09-25 01:35:35 +02005807 pdu := {
5808 dtap := l3
5809 }
5810 };
5811 BSSAP.receive(exp_data);
5812 setverdict(pass);
5813}
5814
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005815private function f_mt_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5816 template (present) RslLinkId link_id := tr_RslLinkID_DCCH(0),
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005817 template (value) OCT1 dlci := '00'O,
5818 octetstring l3 := '0123456789'O)
5819runs on MSC_ConnHdlr {
5820 BSSAP.send(PDU_BSSAP:{
5821 discriminator := '1'B,
5822 spare := '0000000'B,
5823 dlci := dlci,
5824 lengthIndicator := lengthof(l3),
5825 pdu := {
5826 dtap := l3
5827 }
5828 });
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005829 rsl.receive(tr_RSL_DATA_REQ(g_chan_nr, link_id, l3));
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005830 setverdict(pass);
5831}
5832
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005833/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
5834 * simply never sends a BSSMAP Handover Command. */
5835private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005836 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005837
5838 var PDU_BSSAP ass_req := f_gen_ass_req();
5839 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5840 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5841 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5842 f_establish_fully(ass_req, exp_compl);
5843
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005844 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005845 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5846
5847 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5848
5849 /* osmo-bsc should time out 10 seconds after the handover started.
5850 * Let's give it a bit extra. */
5851 f_sleep(15.0);
5852
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005853 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005854 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005855 f_perform_clear();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005856}
5857testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
5858 var MSC_ConnHdlr vc_conn;
5859
5860 f_init(1, true);
5861 f_sleep(1.0);
5862
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005863 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005864
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005865 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
5866 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005867
5868 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5869 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5870 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5871 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5872 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5873 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5874 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005875 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005876}
5877
5878/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
5879 * RR Handover Failure. */
5880private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005881 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005882
5883 var PDU_BSSAP ass_req := f_gen_ass_req();
5884 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5885 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5886 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5887 f_establish_fully(ass_req, exp_compl);
5888
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005889 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005890 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5891
5892 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5893
5894 f_sleep(0.5);
5895 /* The MSC negotiates Handover Request and Handover Request Ack with
5896 * the other BSS and comes back with a BSSMAP Handover Command
5897 * containing an RR Handover Command coming from the target BSS... */
5898
5899 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5900 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5901 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5902 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5903 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5904
5905 /* expect the Handover Command to go out on RR */
5906 var RSL_Message rsl_ho_cmd
5907 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5908 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5909 var RSL_IE_Body rsl_ho_cmd_l3;
5910 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5911 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5912 setverdict(fail);
5913 } else {
5914 log("Found L3 Info: ", rsl_ho_cmd_l3);
5915 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5916 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5917 setverdict(fail);
5918 } else {
5919 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5920 setverdict(pass);
5921 }
5922 }
5923
5924 f_sleep(0.2);
5925 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
5926
5927 /* Should tell the MSC about the failure */
5928 BSSAP.receive(tr_BSSMAP_HandoverFailure);
5929
5930 f_sleep(1.0);
5931
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005932 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005933 f_sleep(1.0);
5934
5935 setverdict(pass);
5936 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005937 f_perform_clear();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005938}
5939testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
5940 var MSC_ConnHdlr vc_conn;
5941
5942 f_init(1, true);
5943 f_sleep(1.0);
5944
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005945 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005946
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005947 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
5948 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005949
5950 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5951 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5952 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5953 f_ctrs_bsc_and_bts_add(0, "handover:failed");
5954 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5955 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:failed");
5956 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005957 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005958}
5959
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005960/* BSC asks for inter-BSC-out HO, receives BSSMAP Handover Command, but then no reply is received about HO outcome
5961 * (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 +02005962 * and the lchan is released. */
5963private function f_tc_ho_out_fail_no_result_after_ho_cmd(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005964 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005965
5966 var PDU_BSSAP ass_req := f_gen_ass_req();
5967 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5968 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5969 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5970 f_establish_fully(ass_req, exp_compl);
5971
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005972 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005973 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5974
5975 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5976
5977 f_sleep(0.5);
5978 /* The MSC negotiates Handover Request and Handover Request Ack with
5979 * the other BSS and comes back with a BSSMAP Handover Command
5980 * containing an RR Handover Command coming from the target BSS... */
5981
5982 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5983 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5984 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5985 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5986 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5987
5988 /* expect the Handover Command to go out on RR */
5989 var RSL_Message rsl_ho_cmd
5990 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5991 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5992 var RSL_IE_Body rsl_ho_cmd_l3;
5993 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5994 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5995 setverdict(fail);
5996 } else {
5997 log("Found L3 Info: ", rsl_ho_cmd_l3);
5998 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5999 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
6000 setverdict(fail);
6001 } else {
6002 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
6003 setverdict(pass);
6004 }
6005 }
6006
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02006007 /* We get neither success nor failure report from the remote BSS. Eventually T8 times out and we run into 3GPP
6008 * TS 48.008 3.1.5.3.3 "Abnormal Conditions": Clear Request should go to the MSC, and RR should be released
6009 * after Clear Command */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02006010
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006011 var PDU_BSSAP rx_clear_request;
Neels Hofmeyre1797aa2019-07-09 19:34:04 +02006012 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
6013 log("Got BSSMAP Clear Request");
6014 /* Instruct BSC to clear channel */
6015 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
6016 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6017
6018 var MgcpCommand mgcp;
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02006019 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01006020 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
6021 log("Got Deact SACCH");
6022 }
Harald Welte924b6ea2019-02-04 01:05:34 +01006023 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01006024 log("Got RR Release");
6025 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02006026 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02006027 log("Got RF Chan Rel");
6028 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02006029 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02006030 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02006031 }
6032
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006033 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006034 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006035 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02006036
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02006037 setverdict(pass);
6038 f_sleep(1.0);
6039}
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02006040testcase TC_ho_out_fail_no_result_after_ho_cmd() runs on test_CT {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02006041 var MSC_ConnHdlr vc_conn;
6042
6043 f_init(1, true);
6044 f_sleep(1.0);
6045
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006046 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006047
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02006048 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_result_after_ho_cmd));
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02006049 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006050
6051 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6052 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6053 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6054 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
6055 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
6056 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
6057 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006058 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02006059}
6060
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006061private 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 +01006062 var PDU_BSSAP rx_bssap;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006063 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
6064 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
6065 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
6066 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
6067 * before we get started. */
6068 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6069 f_rslem_register(0, new_chan_nr);
6070 g_chan_nr := new_chan_nr;
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02006071 var uint3_t expect_target_tsc := BTS_TSC[0];
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006072 f_sleep(1.0);
6073
6074 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6075 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
Neels Hofmeyr2677b872022-04-12 01:44:43 +02006076 var default as_media := activate(as_Media());
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006077
Neels Hofmeyra23f3b12022-03-02 19:57:12 +01006078 var PDU_BSSAP ho_req := f_gen_handover_req(aoip_tla := g_pars.host_aoip_tla,
6079 cell_id_source := g_pars.cell_id_source,
6080 oldToNewBSSIEs := oldToNewBSSIEs,
6081 enc := g_pars.encr);
6082 if (g_pars.inter_bsc_ho_in__ho_req_in_initial_sccp_cr) {
6083 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc, ho_req));
6084 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
6085 } else {
6086 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc, omit));
6087 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
6088 BSSAP.send(ho_req);
6089 }
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006090
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006091 alt {
6092 [] BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap {
6093 if (g_pars.expect_ho_fail) {
6094 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6095 "Expected Handover Request to fail, but got Handover Request Ack")
6096 }
6097 }
6098 [] BSSAP.receive(tr_BSSMAP_HandoverFailure) -> value rx_bssap {
6099 if (not g_pars.expect_ho_fail) {
6100 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6101 "Expected Handover Request to succeed, but got Handover Failure")
6102 }
6103 // TODO: evaluate correct cause value. But osmo-bsc doesn't seem to send meaningful causes yet!
6104 // For now just accept any cause.
6105 BSSAP.receive(tr_BSSMAP_ClearRequest);
6106 setverdict(pass);
6107 return;
6108 }
6109 }
6110
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006111 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6112
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02006113 /* we're sure that the channel activation is done now, verify the parameters in it */
6114 var RSL_Message chan_act := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
6115 f_verify_encr_info(chan_act);
6116 f_chan_act_verify_tsc(chan_act, expect_target_tsc);
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006117
Neels Hofmeyr46e16e52022-02-23 17:04:00 +01006118 if (ispresent(rx_bssap.pdu.bssmap.handoverRequestAck.codecList)) {
6119 if (not g_pars.aoip) {
6120 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6121 "handoverRequestAck: Expected no Speech Codec List (BSS Supported), because this is not AoIP");
6122 }
6123 /* TODO: check actual codecs? */
6124 } else {
6125 if (g_pars.aoip) {
6126 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6127 "handoverRequestAck: Expected Speech Codec List (BSS Supported), but none found");
6128 }
6129 }
6130
6131 if (ispresent(rx_bssap.pdu.bssmap.handoverRequestAck.speechCodec)) {
6132 if (not g_pars.aoip) {
6133 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6134 "handoverRequestAck: Expected no Speech Codec (Chosen), because this is not AoIP");
6135 }
6136 /* TODO: check actual codec? */
6137 } else {
6138 if (g_pars.aoip) {
6139 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6140 "handoverRequestAck: Expected Speech Codec (Chosen), but none found");
6141 }
6142 }
6143
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006144 var octetstring ho_command_str;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006145 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6146 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6147 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6148 log("L3 Info in HO Request Ack is ", ho_command);
6149
6150 var GsmArfcn arfcn;
6151 var RslChannelNr actual_new_chan_nr;
6152 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6153 actual_new_chan_nr, arfcn);
6154
6155 if (actual_new_chan_nr != new_chan_nr) {
6156 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6157 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6158 setverdict(fail);
6159 return;
6160 }
6161 log("Handover Command chan_nr is", actual_new_chan_nr);
6162
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02006163 var uint3_t got_tsc := rr_chan_desc_tsc(ho_command.msgs.rrm.handoverCommand.channelDescription2);
6164 if (not match(got_tsc, expect_target_tsc)) {
6165 setverdict(fail, "RR Handover Command: unexpected TSC in Channel Description: expected ",
6166 expect_target_tsc, " got ", got_tsc);
6167 mtc.stop;
6168 } else {
6169 log("handoverCommand: verified TSC = ", got_tsc);
6170 }
6171
Vadim Yanitskiy634f75d2022-03-14 17:04:45 +03006172 /* Check the Cipher Mode Setting IE (shall be present during inter-RAT handover) */
6173 if (ispresent(ho_command.msgs.rrm.handoverCommand.cipherModeSetting)) {
6174 var CipherModeSetting_TV cms := ho_command.msgs.rrm.handoverCommand.cipherModeSetting;
6175 var template (present) CipherModeSetting_TV tr_cms := {
6176 sC := '0'B, /* no ciphering by default */
6177 algorithmIdentifier := '000'B,
6178 elementIdentifier := ?
6179 };
6180 if (ispresent(g_pars.encr) and g_pars.encr.enc_alg_expect != '01'O) { /* A5/N */
6181 tr_cms.algorithmIdentifier := f_cipher_mode_bssmap_to_rr(g_pars.encr.enc_alg_expect);
6182 tr_cms.sC := '1'B;
6183 }
6184 if (not match(cms, tr_cms)) {
6185 setverdict(fail, "RR Handover Command: unexpected Cipher Mode Setting IE: ",
6186 cms, ", expected: ", tr_cms);
6187 }
6188 } else {
6189 setverdict(fail, "RR Handover Command: Cipher Mode Setting IE is not present");
6190 }
6191
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006192 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6193 * tells the MS to handover to the new lchan. Here comes the new MS on
6194 * the new lchan with a Handover RACH: */
6195
6196 /* send handover detect */
6197
6198 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
6199
6200 BSSAP.receive(tr_BSSMAP_HandoverDetect);
6201
6202 /* send handover complete over the new channel */
6203
6204 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
6205 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
6206 enc_PDU_ML3_MS_NW(l3_tx)));
6207
6208 BSSAP.receive(tr_BSSMAP_HandoverComplete);
Neels Hofmeyr2677b872022-04-12 01:44:43 +02006209 deactivate(as_media);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006210 setverdict(pass);
6211}
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006212
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006213private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006214 var template PDU_ML3_NW_MS exp_rr_rel_tmpl;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006215 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit;
6216 if (not istemplatekind(g_pars.last_used_eutran_plmn, "omit")) {
6217 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006218 }
6219 if (g_pars.exp_fast_return) {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006220 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE_CellSelectInd;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006221 } else {
6222 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006223 }
6224 f_ho_into_this_bsc(id, oldToNewBSSIEs);
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006225 if (g_pars.expect_ho_fail) {
6226 f_perform_clear_no_lchan();
6227 } else {
6228 f_perform_clear(exp_rr_rel_tmpl := exp_rr_rel_tmpl);
6229 }
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006230 setverdict(pass);
6231}
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01006232function 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 +01006233 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006234
6235 f_init(1, true);
6236 f_sleep(1.0);
6237
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01006238 f_vty_encryption_a5(vty_a5_cfg);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006239 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006240
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006241 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6242 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006243
6244 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
6245 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006246
6247 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006248 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006249 if (pars.expect_ho_fail) {
6250 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6251 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:failed");
6252 } else {
6253 f_ctrs_bsc_and_bts_add(0, "handover:completed");
6254 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed");
6255 }
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006256 f_ctrs_bsc_and_bts_verify();
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01006257
6258 f_vty_encryption_a5_reset();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006259}
6260
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006261testcase TC_ho_into_this_bsc() runs on test_CT {
6262 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6263 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006264 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006265}
6266
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006267function f_tc_ho_into_this_bsc_a5(TestHdlrEncrParams encr, charstring vty_a5_cfg := VTY_A5_DEFAULT,
6268 boolean expect_fail := false) runs on test_CT {
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006269 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01006270 pars.encr := encr;
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006271 pars.expect_ho_fail := expect_fail;
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01006272 f_tc_ho_into_this_bsc_main(pars, vty_a5_cfg);
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006273 f_shutdown_helper();
6274}
6275
6276testcase TC_ho_into_this_bsc_a5_0() runs on test_CT {
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01006277 f_tc_ho_into_this_bsc_a5(f_encr_params('01'O));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006278}
6279
6280testcase TC_ho_into_this_bsc_a5_1() runs on test_CT {
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01006281 f_tc_ho_into_this_bsc_a5(f_encr_params('02'O));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006282}
6283
6284testcase TC_ho_into_this_bsc_a5_3() runs on test_CT {
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01006285 f_tc_ho_into_this_bsc_a5(f_encr_params('08'O));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006286}
6287
6288testcase TC_ho_into_this_bsc_a5_4() runs on test_CT {
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01006289 f_tc_ho_into_this_bsc_a5(f_encr_params('10'O, kc128 := true), "3 4");
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006290}
6291
Neels Hofmeyr1951be22022-02-16 16:21:07 +01006292/* Report: in inter-BSC incoming handover, when the MSC omits the Chosen Encryption Algorithm IE in the Handover Request
6293 * message, then osmo-bsc starts an unencrypted lchan even if A5/0 is not permitted.
6294 *
6295 * This test verifies that the Encryption Information is present in the Channel Activation when the Chosen Enc Alg is
6296 * omitted.
6297 *
6298 * Related: SYS#5839
6299 */
6300testcase TC_ho_into_this_bsc_a5_1_3_no_chosen_enc_alg() runs on test_CT {
6301 f_tc_ho_into_this_bsc_a5(f_encr_params(alg_permitted := '0a'O, alg_expect := '08'O, alg_chosen := omit));
6302}
6303
6304testcase TC_ho_into_this_bsc_a5_1_3() runs on test_CT {
6305 f_tc_ho_into_this_bsc_a5(f_encr_params(alg_permitted := '0a'O, alg_expect := '08'O));
6306}
6307
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006308/* Send a permitted algo mask that does not intersect with osmo-bsc.cfg */
6309testcase TC_ho_into_this_bsc_a5_mismatch() runs on test_CT {
6310 f_tc_ho_into_this_bsc_a5(f_encr_params(alg_permitted := '18'O, alg_expect := '10'O), "0 1",
6311 expect_fail := true); // 0x18 = A5/3 and A5/4
6312}
6313
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006314testcase TC_ho_into_this_bsc_tla_v6() runs on test_CT {
6315 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6316 pars.host_aoip_tla := "::6";
6317 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006318 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006319}
6320
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006321/* Similar to TC_ho_into_this_bsc, but when in SRVCC, HO Req contains "Old BSS
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006322 to New BSS Information" IE with "Last Used E-UTRAN PLMN Id", which, when the
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006323 channel is later released (RR CHannel Release), should trigger inclusion of
6324 IE "Cell Selection Indicator after Release of all TCH and SDCCH" with E-UTRAN
6325 neighbors. */
6326testcase TC_srvcc_eutran_to_geran() runs on test_CT {
6327 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6328 pars.last_used_eutran_plmn := '323454'O;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006329 pars.exp_fast_return := true;
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006330 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02006331
6332 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted");
6333 f_ctrs_bsc_and_bts_add(0, "srvcc:completed");
6334 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006335 f_shutdown_helper();
6336}
6337
Vadim Yanitskiy634f75d2022-03-14 17:04:45 +03006338/* Same as TC_srvcc_eutran_to_geran, but enables ciphering on the target channel. */
6339testcase TC_srvcc_eutran_to_geran_a5_3() runs on test_CT {
6340 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6341 pars.encr := f_encr_params('08'O); /* only A5/3 */
6342 pars.last_used_eutran_plmn := '323454'O;
6343 pars.exp_fast_return := true;
6344 f_tc_ho_into_this_bsc_main(pars);
6345
6346 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted");
6347 f_ctrs_bsc_and_bts_add(0, "srvcc:completed");
6348 f_ctrs_bsc_and_bts_verify();
6349 f_shutdown_helper();
6350}
6351
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006352/* Same as TC_srvcc_eutran_to_geran, but test explicitly forbiding fast return
6353 on the BTS. As a result, RR Release shouldn't contain the EUTRAN neighbor
6354 list when the channel is released. */
6355testcase TC_srvcc_eutran_to_geran_forbid_fast_return() runs on test_CT {
6356 f_init_vty();
6357 f_vty_allow_srvcc_fast_return(true, 0)
6358
6359 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6360 pars.last_used_eutran_plmn := '323454'O;
6361 pars.exp_fast_return := false;
6362 f_tc_ho_into_this_bsc_main(pars);
6363 f_vty_allow_srvcc_fast_return(false, 0);
6364 f_shutdown_helper();
6365}
6366
Pau Espin Pedrola8ef3be2022-02-16 16:21:17 +01006367/* Same as TC_srvcc_eutran_to_geran, but using SAI as serving Cell Identifier. SYS#5838 */
6368testcase TC_srvcc_eutran_to_geran_src_sai() runs on test_CT {
6369 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6370 pars.last_used_eutran_plmn := '323454'O;
6371 pars.cell_id_source := valueof(ts_CellID_SAI('123456'O, 300, 444));
6372 f_tc_ho_into_this_bsc_main(pars);
6373
6374 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted");
6375 f_ctrs_bsc_and_bts_add(0, "srvcc:completed");
6376 f_ctrs_bsc_and_bts_verify();
6377 f_shutdown_helper();
6378}
6379
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006380private function f_tc_srvcc_eutran_to_geran_ho_out(charstring id) runs on MSC_ConnHdlr {
6381 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs;
6382 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
6383 f_ho_into_this_bsc(id, oldToNewBSSIEs);
6384 f_ho_out_of_this_bsc(oldToNewBSSIEs);
6385 setverdict(pass);
6386}
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006387
6388private function f_tc_srvcc_eutran_to_geran_ho_out_main(boolean disable_fast_return)
6389 runs on test_CT {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006390 var MSC_ConnHdlr vc_conn;
6391 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6392
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01006393 f_init_vty();
6394 f_bts_0_cfg(BSCVTY,
6395 {"neighbor-list mode automatic",
6396 "handover 1",
6397 "handover algorithm 2",
6398 "handover2 window rxlev averaging 1",
6399 "no neighbors",
6400 "neighbor lac 99 arfcn 123 bsic any"});
6401 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6402
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006403 f_init(1, true);
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006404 if (disable_fast_return) {
6405 f_vty_allow_srvcc_fast_return(true, 0);
6406 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006407 f_sleep(1.0);
6408
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006409 f_ctrs_bsc_and_bts_handover_init();
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006410
6411 pars.last_used_eutran_plmn := '323454'O;
6412 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6413 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
6414
6415 vc_conn := f_start_handler(refers(f_tc_srvcc_eutran_to_geran_ho_out), pars);
6416 vc_conn.done;
6417
6418 f_ctrs_bsc_and_bts_add(0, "handover:attempted", 2);
6419 f_ctrs_bsc_and_bts_add(0, "handover:completed", 2);
6420 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted", 1);
6421 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed", 1);
6422 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted", 1);
6423 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed", 1);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02006424
6425 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted", 1);
6426 f_ctrs_bsc_and_bts_add(0, "srvcc:completed", 1);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006427 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006428
6429 if (disable_fast_return) {
6430 f_vty_allow_srvcc_fast_return(false, 0);
6431 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006432 f_shutdown_helper();
6433}
6434
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006435/* First, HO into BSC from EUTRAN (SRVCC): HO Request contains "Old BSS to New
6436 BSS Information" IE with "Last Used E-UTRAN PLMN Id".
6437 Second, HO to another BSC: HO Required contains "Old BSS to New BSS Information"
6438 IE with "Last Used E-UTRAN PLMN Id" from first step. */
6439testcase TC_srvcc_eutran_to_geran_ho_out() runs on test_CT {
6440 f_tc_srvcc_eutran_to_geran_ho_out_main(false);
6441}
6442/* Validate subsequent intra-GSM-HO works the same (with OldBSSToNewBSSInfo IE)
6443 * independently of fast-reture allowed/forbidden in local BTS */
6444testcase TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() runs on test_CT {
6445 f_tc_srvcc_eutran_to_geran_ho_out_main(true);
6446}
6447
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006448private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
6449 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6450 f_rslem_register(0, new_chan_nr);
6451 g_chan_nr := new_chan_nr;
6452 f_sleep(1.0);
6453
6454 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6455 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6456 activate(as_Media());
6457
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006458 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006459 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006460 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006461
6462 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6463
6464 var PDU_BSSAP rx_bssap;
6465 var octetstring ho_command_str;
6466
6467 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6468
6469 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6470 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6471 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6472 log("L3 Info in HO Request Ack is ", ho_command);
6473
6474 var GsmArfcn arfcn;
6475 var RslChannelNr actual_new_chan_nr;
6476 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6477 actual_new_chan_nr, arfcn);
6478
6479 if (actual_new_chan_nr != new_chan_nr) {
6480 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6481 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6482 setverdict(fail);
6483 return;
6484 }
6485 log("Handover Command chan_nr is", actual_new_chan_nr);
6486
Neels Hofmeyr61ca08d2019-05-06 23:52:22 +02006487 /* For deterministic test results, give some time for the MGW endpoint to be configured */
6488 f_sleep(1.0);
6489
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006490 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6491 * tells the MS to handover to the new lchan. In this case, the MS
6492 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
6493 * Handover Failure to the MSC. The procedure according to 3GPP TS
6494 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
6495 * BSSMAP Clear Command: */
6496
6497 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6498 var BssmapCause cause := enum2int(cause_val);
6499 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6500
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006501 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006502 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006503 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006504
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006505 setverdict(pass);
6506 f_sleep(1.0);
6507
6508 setverdict(pass);
6509}
6510testcase TC_ho_in_fail_msc_clears() runs on test_CT {
6511 var MSC_ConnHdlr vc_conn;
6512 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6513
6514 f_init(1, true);
6515 f_sleep(1.0);
6516
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006517 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006518
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006519 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6520 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006521
6522 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
6523 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006524
6525 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6526 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
6527 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6528 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
6529 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006530 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006531}
6532
6533private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
6534 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
6535 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
6536 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
6537 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
6538 * before we get started. */
6539 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6540 f_rslem_register(0, new_chan_nr);
6541 g_chan_nr := new_chan_nr;
6542 f_sleep(1.0);
6543
6544 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6545 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6546 activate(as_Media());
6547
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006548 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006549 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006550 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006551
6552 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6553
6554 var PDU_BSSAP rx_bssap;
6555 var octetstring ho_command_str;
6556
6557 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6558
6559 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6560 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6561 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6562 log("L3 Info in HO Request Ack is ", ho_command);
6563
6564 var GsmArfcn arfcn;
6565 var RslChannelNr actual_new_chan_nr;
6566 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6567 actual_new_chan_nr, arfcn);
6568
6569 if (actual_new_chan_nr != new_chan_nr) {
6570 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6571 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6572 setverdict(fail);
6573 return;
6574 }
6575 log("Handover Command chan_nr is", actual_new_chan_nr);
6576
6577 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6578 * tells the MS to handover to the new lchan. Here comes the new MS on
6579 * the new lchan with a Handover RACH: */
6580
6581 /* send handover detect */
6582
6583 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
6584
6585 BSSAP.receive(tr_BSSMAP_HandoverDetect);
6586
6587 /* The MSC chooses to clear the connection now, maybe we got the
6588 * Handover RACH on the new cell but the MS still signaled Handover
6589 * Failure to the old BSS? */
6590
6591 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6592 var BssmapCause cause := enum2int(cause_val);
6593 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6594
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006595 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006596 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006597 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006598
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006599 f_sleep(1.0);
6600}
6601testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
6602 var MSC_ConnHdlr vc_conn;
6603 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6604
6605 f_init(1, true);
6606 f_sleep(1.0);
6607
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006608 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006609
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006610 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6611 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006612
6613 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
6614 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006615
6616 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6617 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
6618 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6619 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
6620 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006621 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006622}
6623
6624/* The new BSS's lchan times out before the MSC decides that handover failed. */
6625private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
6626 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6627 f_rslem_register(0, new_chan_nr);
6628 g_chan_nr := new_chan_nr;
6629 f_sleep(1.0);
6630
6631 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6632 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
Neels Hofmeyr9b320c12022-04-07 00:19:01 +02006633 activate(as_Media(fail_on_dlcx := false));
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006634
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006635 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006636 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006637 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006638
6639 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6640
6641 var PDU_BSSAP rx_bssap;
6642 var octetstring ho_command_str;
6643
6644 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6645
6646 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6647 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6648 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6649 log("L3 Info in HO Request Ack is ", ho_command);
6650
6651 var GsmArfcn arfcn;
6652 var RslChannelNr actual_new_chan_nr;
6653 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6654 actual_new_chan_nr, arfcn);
6655
6656 if (actual_new_chan_nr != new_chan_nr) {
6657 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6658 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6659 setverdict(fail);
6660 return;
6661 }
6662 log("Handover Command chan_nr is", actual_new_chan_nr);
6663
6664 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6665 * tells the MS to handover to the new lchan. But the MS never shows up
6666 * on the new lchan. */
6667
6668 BSSAP.receive(tr_BSSMAP_HandoverFailure);
6669
6670 /* Did osmo-bsc also send a Clear Request? */
6671 timer T := 0.5;
6672 T.start;
6673 alt {
6674 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
6675 [] T.timeout { }
6676 }
6677
6678 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
6679 * asked for it, this is a Handover Failure after all). */
6680
6681 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6682 var BssmapCause cause := enum2int(cause_val);
6683 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6684
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006685 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006686 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006687 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006688
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006689 f_sleep(1.0);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006690}
6691testcase TC_ho_in_fail_no_detect() runs on test_CT {
6692 var MSC_ConnHdlr vc_conn;
6693 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6694
6695 f_init(1, true);
6696 f_sleep(1.0);
6697
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006698 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006699
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006700 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6701 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006702
6703 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
6704 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006705
6706 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6707 f_ctrs_bsc_and_bts_add(0, "handover:error");
6708 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6709 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
6710 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006711 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006712}
6713
6714/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
6715private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
6716 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6717 f_rslem_register(0, new_chan_nr);
6718 g_chan_nr := new_chan_nr;
6719 f_sleep(1.0);
6720
6721 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6722 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
Neels Hofmeyr9b320c12022-04-07 00:19:01 +02006723 activate(as_Media(fail_on_dlcx := false));
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006724
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006725 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006726 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006727 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006728
6729 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6730
6731 var PDU_BSSAP rx_bssap;
6732 var octetstring ho_command_str;
6733
6734 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6735
6736 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6737 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6738 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6739 log("L3 Info in HO Request Ack is ", ho_command);
6740
6741 var GsmArfcn arfcn;
6742 var RslChannelNr actual_new_chan_nr;
6743 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6744 actual_new_chan_nr, arfcn);
6745
6746 if (actual_new_chan_nr != new_chan_nr) {
6747 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6748 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6749 setverdict(fail);
6750 return;
6751 }
6752 log("Handover Command chan_nr is", actual_new_chan_nr);
6753
6754 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6755 * tells the MS to handover to the new lchan. But the MS never shows up
6756 * on the new lchan. */
6757
6758 BSSAP.receive(tr_BSSMAP_HandoverFailure);
6759
6760 /* MSC plays dumb and sends no Clear Command */
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006761 var PDU_BSSAP rx_clear_request;
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02006762
6763 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006764 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
6765 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6766 };
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006767 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006768 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006769 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006770
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006771 f_sleep(1.0);
6772}
6773testcase TC_ho_in_fail_no_detect2() runs on test_CT {
6774 var MSC_ConnHdlr vc_conn;
6775 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6776
6777 f_init(1, true);
6778 f_sleep(1.0);
6779
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006780 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006781
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006782 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6783 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006784
6785 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
6786 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006787
6788 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6789 f_ctrs_bsc_and_bts_add(0, "handover:error");
6790 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6791 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
6792 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006793 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006794}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006795
Neels Hofmeyra23f3b12022-03-02 19:57:12 +01006796/* An incoming inter-BSC HO can either issue the Handover Request message attached to the initial SCCP N-Connect (as in
6797 * the other tests we have so far), or the first CR can be "empty" with the BSSAP request following later. Test the
6798 * empty N-Connect case. */
6799testcase TC_ho_into_this_bsc_sccp_cr_without_bssap() runs on test_CT {
6800 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6801 pars.inter_bsc_ho_in__ho_req_in_initial_sccp_cr := false;
6802 f_tc_ho_into_this_bsc_main(pars);
6803 f_shutdown_helper();
6804}
6805
Neels Hofmeyr91401012019-07-11 00:42:35 +02006806type record of charstring Commands;
6807
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006808private function f_bts_0_cfg(TELNETasp_PT pt, Commands cmds := {})
Neels Hofmeyr91401012019-07-11 00:42:35 +02006809{
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006810 f_vty_enter_cfg_bts(pt, 0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006811 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006812 f_vty_transceive(pt, cmds[i]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006813 }
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006814 f_vty_transceive(pt, "end");
Neels Hofmeyr91401012019-07-11 00:42:35 +02006815}
6816
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01006817private function f_cs7_inst_0_cfg(TELNETasp_PT pt, Commands cmds := {})
6818{
6819 f_vty_enter_cfg_cs7_inst(pt, 0);
6820 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
6821 f_vty_transceive(pt, cmds[i]);
6822 }
6823 f_vty_transceive(pt, "end");
6824}
6825
Neels Hofmeyr91401012019-07-11 00:42:35 +02006826private function f_probe_for_handover(charstring log_label,
6827 charstring log_descr,
6828 charstring handover_vty_cmd,
6829 boolean expect_handover,
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006830 boolean is_inter_bsc_handover := false,
6831 template uint3_t expect_target_tsc := ?)
Neels Hofmeyr91401012019-07-11 00:42:35 +02006832runs on MSC_ConnHdlr
6833{
Neels Hofmeyrb3fc8982020-05-11 00:16:42 +02006834 /* We're going to thwart any and all handover attempts, just be ready to handle (and ignore) handover target
6835 * lchans to be established on bts 1 or bts 2. */
6836 f_rslem_suspend(RSL1_PROC);
6837 f_rslem_suspend(RSL2_PROC);
6838
Neels Hofmeyr91401012019-07-11 00:42:35 +02006839 var RSL_Message rsl;
6840
6841 var charstring log_msg := " (expecting handover)"
6842 if (not expect_handover) {
6843 log_msg := " (expecting NO handover)";
6844 }
6845 log("f_probe_for_handover starting: " & log_label & ": " & log_descr & log_msg);
6846 f_vty_transceive(BSCVTY, handover_vty_cmd);
6847
Neels Hofmeyr91401012019-07-11 00:42:35 +02006848 timer T := 2.0;
6849 T.start;
6850
6851 alt {
6852 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
6853 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
6854 log("Rx L3 from net: ", l3);
6855 if (ischosen(l3.msgs.rrm.handoverCommand)) {
6856 var RslChannelNr new_chan_nr;
6857 var GsmArfcn arfcn;
6858 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
6859 new_chan_nr, arfcn);
6860 log("Handover to new chan ", new_chan_nr, " on ARFCN ", arfcn);
6861 log(l3.msgs.rrm.handoverCommand);
6862
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006863 /* Verify correct TSC in handoverCommand */
6864 var uint3_t got_tsc := rr_chan_desc_tsc(l3.msgs.rrm.handoverCommand.channelDescription2);
6865 if (not match(got_tsc, expect_target_tsc)) {
6866 setverdict(fail, "RR Handover Command: unexpected TSC in Channel Description: expected ",
6867 expect_target_tsc, " got ", got_tsc);
6868 mtc.stop;
6869 } else {
6870 log("handoverCommand: verified TSC = ", got_tsc, " (matches ",
6871 expect_target_tsc, ")");
6872 }
6873
Neels Hofmeyr91401012019-07-11 00:42:35 +02006874 /* Need to register for new lchan on new BTS -- it's either bts 1 or bts 2. It doesn't really
6875 * matter on which BTS it really is, we're not going to follow through an entire handover
6876 * anyway. */
6877 f_rslem_register(0, new_chan_nr, RSL1_PROC);
6878 f_rslem_resume(RSL1_PROC);
6879 f_rslem_register(0, new_chan_nr, RSL2_PROC);
6880 f_rslem_resume(RSL2_PROC);
6881
6882 if (expect_handover and not is_inter_bsc_handover) {
6883 setverdict(pass);
6884 log("f_probe_for_handover(" & log_label & "): Got RSL Handover Command as expected.");
6885 } else {
6886 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got RSL Handover Command. "
6887 & log_label & ": " & log_descr);
6888 }
6889
6890 log("f_probe_for_handover(" & log_label & "): Ending the test: Handover Failure stops the procedure.");
6891 /* osmo-bsc has triggered Handover. That's all we need to know for this test, reply with
6892 * Handover Failure. */
6893 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
6894
6895 /* target BTS is told to release lchan again; don't care which BTS nor what messages. */
6896 f_sleep(0.5);
6897 RSL1.clear;
6898 RSL2.clear;
6899 log("f_probe_for_handover(" & log_label & "): done (got RSL Handover Command)");
6900 break;
6901 } else {
6902 repeat;
6903 }
6904 }
6905 [] BSSAP.receive(tr_BSSMAP_HandoverRequired) {
6906 if (expect_handover and is_inter_bsc_handover) {
6907 setverdict(pass);
6908 log("f_probe_for_handover(" & log_label & "): Got BSSMAP Handover Required as expected.");
6909 } else {
6910 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got BSSMAP Handover Required. "
6911 & log_label & ": " & log_descr);
6912 }
6913
6914 log("f_probe_for_handover(" & log_label & "): done (got BSSMAP Handover Required)");
6915
6916 /* Note: f_tc_ho_neighbor_config_start() sets T7, the timeout for BSSMAP Handover Required, to
6917 * 1 second. There is no legal way to quickly abort a handover after a BSSMAP Handover Required,
6918 * setting a short timeout and waiting is the only way. */
6919 log("f_probe_for_handover(" & log_label & "): waiting for inter-BSC HO to time out...");
6920 f_sleep(1.5);
6921 log("f_probe_for_handover(" & log_label & "): ...done");
6922
6923 break;
6924 }
6925 [] T.timeout {
6926 if (expect_handover) {
6927 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected Handover, but got none. "
6928 & log_label & ": " & log_descr);
6929 } else {
6930 setverdict(pass);
6931 log("f_probe_for_handover(" & log_label & "): Got no Handover, as expected.");
6932 }
6933 log("f_probe_for_handover(" & log_label & "): done (got no Handover)");
6934 break;
6935 }
6936 }
6937
6938 f_rslem_resume(RSL1_PROC);
6939 f_rslem_resume(RSL2_PROC);
6940 f_sleep(3.0);
6941 RSL.clear;
6942
6943 log("f_probe_for_handover(" & log_label & "): done clearing");
6944}
6945
6946/* Test the effect of various neighbor configuration scenarios:
6947 *
6948 * To avoid complexity, block off any actual handover operation, and always remain on the lchan at bts 0.
6949 * Reconfigure the neighbors for bts 0, trigger a Handover, and probe whether osmo-bsc does or doesn't start HO.
6950 */
6951private function f_tc_ho_neighbor_config_start() runs on MSC_ConnHdlr {
6952 g_pars := f_gen_test_hdlr_pars();
6953 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
6954 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006955
6956 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
6957 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
6958
6959 /* Establish lchan at bts 0 */
6960 f_establish_fully(ass_cmd, exp_compl);
6961
6962 /* Shorten the inter-BSC Handover timeout, to not wait so long for inter-BSC Handovers */
6963 f_vty_enter_cfg_network(BSCVTY);
6964 f_vty_transceive(BSCVTY, "timer T7 1");
6965 f_vty_transceive(BSCVTY, "end");
6966}
6967
6968private function f_tc_ho_neighbor_config_1(charstring id) runs on MSC_ConnHdlr {
6969 f_tc_ho_neighbor_config_start();
6970
6971 /*
6972 * bts 0 ARFCN 871 BSIC 10
6973 * bts 1 ARFCN 871 BSIC 11
6974 * bts 2 ARFCN 871 BSIC 12
6975 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6976 */
6977
6978 log("f_tc_ho_neighbor_config: 1. No 'neighbor' config");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006979 f_bts_0_cfg(BSCVTY, {"no neighbors"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006980 f_probe_for_handover("1.a", "HO to bts 1 works, implicitly listed as neighbor (legacy behavior when none are configured)",
6981 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006982 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006983
6984 f_probe_for_handover("1.b", "HO to unknown cell does not start",
6985 "handover any to arfcn 13 bsic 39",
6986 false);
6987
6988 f_probe_for_handover("1.c", "HO to 871-12 is ambiguous = error",
6989 "handover any to arfcn 871 bsic 12",
6990 false);
6991
6992 f_probe_for_handover("1.d", "HO to 871-11 still works (verify that this test properly cleans up)",
6993 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006994 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006995
6996 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006997}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006998testcase TC_ho_neighbor_config_1() runs on test_CT {
6999 var MSC_ConnHdlr vc_conn;
7000 f_init(3, true, guard_timeout := 60.0);
7001 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007002 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007003 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_1));
7004 vc_conn.done;
7005
7006 /* f_tc_ho_neighbor_config_start() */
7007 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7008 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7009
7010 /* 1.a */
7011 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
7012 * handover quickly by sending a Handover Failure message. */
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 /* 1.b */
7021 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7022 f_ctrs_bsc_and_bts_add(0, "handover:error");
7023
7024 /* 1.c */
7025 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7026 f_ctrs_bsc_and_bts_add(0, "handover:error");
7027
7028 /* 1.d */
7029 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7030 f_ctrs_bsc_and_bts_add(0, "handover:failed");
7031 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
7032 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007033 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
7034 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007035
7036 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007037 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007038}
7039
Neels Hofmeyr91401012019-07-11 00:42:35 +02007040private function f_tc_ho_neighbor_config_2(charstring id) runs on MSC_ConnHdlr {
7041 f_tc_ho_neighbor_config_start();
7042
7043 /*
7044 * bts 0 ARFCN 871 BSIC 10
7045 * bts 1 ARFCN 871 BSIC 11
7046 * bts 2 ARFCN 871 BSIC 12
7047 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7048 */
7049
7050 log("f_tc_ho_neighbor_config: 2. explicit local neighbor: 'neighbor bts 1'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007051 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007052 f_sleep(0.5);
7053
7054 f_probe_for_handover("2.a", "HO to bts 1 works, explicitly listed as neighbor",
7055 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02007056 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02007057
7058 f_probe_for_handover("2.b", "HO to bts 2 doesn't work, not listed as neighbor",
7059 "handover any to arfcn 871 bsic 12",
7060 false);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007061 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007062}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007063testcase TC_ho_neighbor_config_2() runs on test_CT {
7064 var MSC_ConnHdlr vc_conn;
7065 f_init(3, true, guard_timeout := 50.0);
7066 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007067 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007068 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_2));
7069 vc_conn.done;
7070
7071 /* f_tc_ho_neighbor_config_start() */
7072 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7073 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7074
7075 /* 2.a */
7076 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
7077 * handover quickly by sending a Handover Failure message. */
7078 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7079 f_ctrs_bsc_and_bts_add(0, "handover:failed");
7080 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
7081 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007082 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
7083 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007084
7085 /* 2.b */
7086 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7087 f_ctrs_bsc_and_bts_add(0, "handover:error");
7088
7089 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007090 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007091}
7092
Neels Hofmeyr91401012019-07-11 00:42:35 +02007093private function f_tc_ho_neighbor_config_3(charstring id) runs on MSC_ConnHdlr {
7094 f_tc_ho_neighbor_config_start();
7095
7096 /*
7097 * bts 0 ARFCN 871 BSIC 10
7098 * bts 1 ARFCN 871 BSIC 11
7099 * bts 2 ARFCN 871 BSIC 12
7100 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7101 */
7102
7103 log("f_tc_ho_neighbor_config: 3. explicit local neighbor: 'neighbor bts 2'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007104 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007105 f_sleep(0.5);
7106
7107 f_probe_for_handover("3.a", "HO to bts 1 doesn't work, not listed as neighbor",
7108 "handover any to arfcn 871 bsic 11",
7109 false);
7110 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",
7111 "handover any to arfcn 871 bsic 12",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02007112 true, expect_target_tsc := BTS_TSC[2]);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007113 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007114}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007115testcase TC_ho_neighbor_config_3() runs on test_CT {
7116 var MSC_ConnHdlr vc_conn;
7117 f_init(3, true, guard_timeout := 50.0);
7118 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007119 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007120 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_3));
7121 vc_conn.done;
7122
7123 /* f_tc_ho_neighbor_config_start() */
7124 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7125 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7126
7127 /* 3.a */
7128 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7129 f_ctrs_bsc_and_bts_add(0, "handover:error");
7130
7131 /* 3.b */
7132 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
7133 * handover quickly by sending a Handover Failure message. */
7134 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7135 f_ctrs_bsc_and_bts_add(0, "handover:failed");
7136 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
7137 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007138 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:attempted");
7139 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007140
7141 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007142 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007143}
7144
Neels Hofmeyr91401012019-07-11 00:42:35 +02007145private function f_tc_ho_neighbor_config_4(charstring id) runs on MSC_ConnHdlr {
7146 f_tc_ho_neighbor_config_start();
7147
7148 /*
7149 * bts 0 ARFCN 871 BSIC 10
7150 * bts 1 ARFCN 871 BSIC 11
7151 * bts 2 ARFCN 871 BSIC 12
7152 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7153 */
7154
7155 log("f_tc_ho_neighbor_config: 4. explicit remote neighbor: 'neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007156 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007157 f_sleep(0.5);
7158
7159 f_probe_for_handover("4.a", "HO to bts 1 doesn't work, not listed as neighbor",
7160 "handover any to arfcn 871 bsic 11",
7161 false);
7162 f_probe_for_handover("4.b", "HO to bts 2 doesn't work, not listed as neighbor",
7163 "handover any to arfcn 871 bsic 12",
7164 false);
7165 f_probe_for_handover("4.c", "HO to 123-45 triggers inter-BSC HO",
7166 "handover any to arfcn 123 bsic 45",
7167 true, true);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007168 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007169}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007170testcase TC_ho_neighbor_config_4() runs on test_CT {
7171 var MSC_ConnHdlr vc_conn;
7172 f_init(3, true, guard_timeout := 50.0);
7173 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007174 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007175 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_4));
7176 vc_conn.done;
7177
7178 /* f_tc_ho_neighbor_config_start() */
7179 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7180 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7181
7182 /* 4.a */
7183 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7184 f_ctrs_bsc_and_bts_add(0, "handover:error");
7185
7186 /* 4.b */
7187 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7188 f_ctrs_bsc_and_bts_add(0, "handover:error");
7189
7190 /* 4.c */
7191 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7192 * handover quickly by timing out after the Handover Required message */
7193 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7194 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
7195 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
7196 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
7197
7198 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007199 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007200}
7201
Neels Hofmeyr91401012019-07-11 00:42:35 +02007202private function f_tc_ho_neighbor_config_5(charstring id) runs on MSC_ConnHdlr {
7203 f_tc_ho_neighbor_config_start();
7204
7205 /*
7206 * bts 0 ARFCN 871 BSIC 10
7207 * bts 1 ARFCN 871 BSIC 11
7208 * bts 2 ARFCN 871 BSIC 12
7209 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7210 */
7211
7212 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 +02007213 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007214 f_sleep(0.5);
7215
7216 f_probe_for_handover("5.a", "HO to 871-12 triggers inter-BSC HO (ignoring local cells with same ARFCN+BSIC)",
7217 "handover any to arfcn 871 bsic 12",
7218 true, true);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007219 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007220}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007221testcase TC_ho_neighbor_config_5() runs on test_CT {
7222 var MSC_ConnHdlr vc_conn;
7223 f_init(3, true);
7224 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007225 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007226 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_5));
7227 vc_conn.done;
7228
7229 /* f_tc_ho_neighbor_config_start() */
7230 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7231 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7232
7233 /* 5 */
7234 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7235 * handover quickly by timing out after the Handover Required message */
7236 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7237 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
7238 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
7239 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
7240
7241 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007242 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007243}
7244
Neels Hofmeyr91401012019-07-11 00:42:35 +02007245private function f_tc_ho_neighbor_config_6(charstring id) runs on MSC_ConnHdlr {
7246 f_tc_ho_neighbor_config_start();
7247
7248 /*
7249 * bts 0 ARFCN 871 BSIC 10
7250 * bts 1 ARFCN 871 BSIC 11
7251 * bts 2 ARFCN 871 BSIC 12
7252 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7253 */
7254
7255 log("f_tc_ho_neighbor_config: 6. config error: explicit local and remote neighbors with ambiguous ARFCN+BSIC:"
7256 & " 'neighbor bts 2; neighbor lac 99 arfcn 871 bsic 12'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007257 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007258 f_sleep(0.5);
7259
7260 f_probe_for_handover("6.a", "HO to 871-12 is ambiguous = error",
7261 "handover any to arfcn 871 bsic 12",
7262 false);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007263 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007264}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007265testcase TC_ho_neighbor_config_6() runs on test_CT {
7266 var MSC_ConnHdlr vc_conn;
7267 f_init(3, true);
7268 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007269 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007270 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_6));
7271 vc_conn.done;
7272
7273 /* f_tc_ho_neighbor_config_start() */
7274 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7275 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7276
7277 /* 6.a */
7278 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7279 * handover quickly by timing out after the Handover Required message */
7280 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7281 f_ctrs_bsc_and_bts_add(0, "handover:error");
7282
7283 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007284 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007285}
7286
Neels Hofmeyr91401012019-07-11 00:42:35 +02007287private function f_tc_ho_neighbor_config_7(charstring id) runs on MSC_ConnHdlr {
7288 f_tc_ho_neighbor_config_start();
7289
7290 /*
7291 * bts 0 ARFCN 871 BSIC 10
7292 * bts 1 ARFCN 871 BSIC 11
7293 * bts 2 ARFCN 871 BSIC 12
7294 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7295 */
7296
7297 log("f_tc_ho_neighbor_config: 7. explicit local and remote neighbors:"
7298 & " 'neighbor bts 2; neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007299 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007300 f_sleep(0.5);
7301
7302 f_probe_for_handover("7.a", "HO to 871-12 does HO to bts 2",
7303 "handover any to arfcn 871 bsic 12",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02007304 true, expect_target_tsc := BTS_TSC[2]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02007305 f_probe_for_handover("7.b", "HO to 123-45 triggers inter-BSC HO",
7306 "handover any to arfcn 123 bsic 45",
7307 true, true);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007308 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007309}
Neels Hofmeyr91401012019-07-11 00:42:35 +02007310testcase TC_ho_neighbor_config_7() runs on test_CT {
7311 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf2b88032020-06-16 00:35:04 +02007312 f_init(3, true, guard_timeout := 50.0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02007313 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007314 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007315 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_7));
7316 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007317
7318 /* f_tc_ho_neighbor_config_start() */
7319 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7320 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7321
7322 /* 7.a */
7323 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
7324 * handover quickly by sending a Handover Failure message. */
7325 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7326 f_ctrs_bsc_and_bts_add(0, "handover:failed");
7327 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
7328 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007329 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:attempted");
7330 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007331
7332 /* 7.b */
7333 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7334 * handover quickly by timing out after the Handover Required message */
7335 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7336 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
7337 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
7338 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
7339
7340 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007341 f_shutdown_helper();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007342}
7343
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007344/* OS#3041: Open and close N connections in a normal fashion, and expect no
7345 * BSSMAP Reset just because of that. */
7346testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
7347 var default d;
7348 var integer i;
7349 var DchanTuple dt;
7350
7351 f_init();
7352
7353 /* Wait for initial BSSMAP Reset to pass */
7354 f_sleep(4.0);
7355
7356 d := activate(no_bssmap_reset());
7357
7358 /* Setup up a number of connections and RLSD them again from the MSC
7359 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7360 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02007361 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007362 /* Since we're doing a lot of runs, give each one a fresh
7363 * T_guard from the top. */
7364 T_guard.start;
7365
7366 /* Setup a BSSAP connection and clear it right away. This is
7367 * the MSC telling the BSC about a planned release, it's not an
7368 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02007369 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007370
7371 /* MSC disconnects (RLSD). */
7372 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
7373 }
7374
7375 /* In the buggy behavior, a timeout of 2 seconds happens between above
7376 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7377 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7378 f_sleep(4.0);
7379
7380 deactivate(d);
7381 f_shutdown_helper();
7382}
Harald Welte552620d2017-12-16 23:21:36 +01007383
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007384/* OS#3041: Open and close N connections in a normal fashion, and expect no
7385 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
7386 * the MSC. */
7387testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
7388 var default d;
7389 var integer i;
7390 var DchanTuple dt;
7391 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007392 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
7393 var BssmapCause cause := enum2int(cause_val);
7394
7395 f_init();
7396
7397 /* Wait for initial BSSMAP Reset to pass */
7398 f_sleep(4.0);
7399
7400 d := activate(no_bssmap_reset());
7401
7402 /* Setup up a number of connections and RLSD them again from the MSC
7403 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7404 * Let's do it some more times for good measure. */
7405 for (i := 0; i < 8; i := i+1) {
7406 /* Since we're doing a lot of runs, give each one a fresh
7407 * T_guard from the top. */
7408 T_guard.start;
7409
7410 /* Setup a BSSAP connection and clear it right away. This is
7411 * the MSC telling the BSC about a planned release, it's not an
7412 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02007413 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007414
7415 /* Instruct BSC to clear channel */
7416 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7417
7418 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02007419 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007420 }
7421
7422 /* In the buggy behavior, a timeout of 2 seconds happens between above
7423 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7424 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7425 f_sleep(4.0);
7426
7427 deactivate(d);
7428 f_shutdown_helper();
7429}
7430
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007431/* OS#3041: Open and close N connections in a normal fashion, and expect no
7432 * BSSMAP Reset just because of that. Close connections from the MS side with a
7433 * Release Ind on RSL. */
7434testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
7435 var default d;
7436 var integer i;
7437 var DchanTuple dt;
7438 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007439 var integer j;
7440
7441 f_init();
7442
7443 /* Wait for initial BSSMAP Reset to pass */
7444 f_sleep(4.0);
7445
7446 d := activate(no_bssmap_reset());
7447
7448 /* Setup up a number of connections and RLSD them again from the MSC
7449 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7450 * Let's do it some more times for good measure. */
7451 for (i := 0; i < 8; i := i+1) {
7452 /* Since we're doing a lot of runs, give each one a fresh
7453 * T_guard from the top. */
7454 T_guard.start;
7455
7456 /* Setup a BSSAP connection and clear it right away. This is
7457 * the MSC telling the BSC about a planned release, it's not an
7458 * erratic loss of a connection. */
7459 dt := f_est_dchan('23'O, 23, '00010203040506'O);
7460
7461 /* simulate RLL REL IND */
7462 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
7463
7464 /* expect Clear Request on MSC side */
7465 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
7466
7467 /* Instruct BSC to clear channel */
7468 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
7469 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7470
7471 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02007472 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007473 }
7474
7475 /* In the buggy behavior, a timeout of 2 seconds happens between above
7476 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7477 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7478 f_sleep(4.0);
7479
7480 deactivate(d);
7481 f_shutdown_helper();
7482}
7483
Harald Welte94e0c342018-04-07 11:33:23 +02007484/***********************************************************************
7485 * IPA style dynamic PDCH
7486 ***********************************************************************/
7487
7488private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
7489 template (omit) RSL_Cause nack := omit)
7490runs on test_CT {
7491 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
7492 var RSL_Message rsl_unused;
7493 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
7494 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
7495 /* expect the BSC to issue the related RSL command */
7496 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7497 if (istemplatekind(nack, "omit")) {
7498 /* respond with a related acknowledgement */
7499 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7500 } else {
7501 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
7502 }
7503}
7504
7505private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
7506 template (omit) RSL_Cause nack := omit)
7507runs on test_CT {
7508 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
7509 var RSL_Message rsl_unused;
7510 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
7511 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
7512 /* expect the BSC to issue the related RSL command */
7513 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
7514 if (istemplatekind(nack, "omit")) {
7515 /* respond with a related acknowledgement */
7516 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
7517 } else {
7518 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
7519 }
7520}
7521
7522private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
7523runs on test_CT return charstring {
7524 var charstring cmd, resp;
7525 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01007526 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02007527}
7528
7529private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
7530 template charstring exp)
7531runs on test_CT {
7532 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
7533 if (not match(mode, exp)) {
7534 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02007535 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02007536 }
7537}
7538
7539private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
7540runs on test_CT {
7541 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
7542 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
7543 f_vty_transceive(BSCVTY, "end");
7544}
7545
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007546
7547private function f_ts_reset_chcomb(integer bts_nr) runs on test_CT {
7548 var integer i;
7549 for (i := 0; i < 8; i := i + 1) {
7550 f_ts_set_chcomb(bts_nr, 0, i, phys_chan_config[i]);
7551 }
7552}
7553
Harald Welte94e0c342018-04-07 11:33:23 +02007554private const charstring TCHF_MODE := "TCH/F mode";
7555private const charstring TCHH_MODE := "TCH/H mode";
7556private const charstring PDCH_MODE := "PDCH mode";
7557private const charstring NONE_MODE := "NONE mode";
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007558private const charstring SDCCH8_MODE := "SDCCH8 mode";
Harald Welte94e0c342018-04-07 11:33:23 +02007559
7560/* Test IPA PDCH activation / deactivation triggered by VTY */
7561testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
7562 var RSL_Message rsl_unused;
7563
7564 /* change Timeslot 6 before f_init() starts RSL */
7565 f_init_vty();
7566 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
7567 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7568
7569 f_init(1, false);
7570 f_sleep(1.0);
7571
7572 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
7573
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007574 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007575 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7576 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7577 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7578 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7579 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007580 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007581 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7582
7583 /* De-activate it via VTY */
7584 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7585 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007586 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007587 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7588
7589 /* re-activate it via VTY */
7590 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
7591 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007592 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007593 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7594
7595 /* and finally de-activate it again */
7596 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7597 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007598 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007599 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7600
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007601 /* clean up config */
7602 f_ts_set_chcomb(0, 0, 6, "PDCH");
7603
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007604 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007605}
7606
7607/* Test IPA PDCH activation NACK */
7608testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
7609 var RSL_Message rsl_unused;
7610
7611 /* change Timeslot 6 before f_init() starts RSL */
7612 f_init_vty();
7613 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
7614 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7615
7616 f_init(1, false);
7617 f_sleep(1.0);
7618
7619 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
7620
7621 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7622 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7623 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7624 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7625 f_sleep(1.0);
7626 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7627
7628 /* De-activate it via VTY */
7629 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7630 f_sleep(1.0);
7631 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7632
7633 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
7634 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
7635 f_sleep(1.0);
7636 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7637
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007638 /* clean up config */
7639 f_ts_set_chcomb(0, 0, 6, "PDCH");
7640
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007641 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007642}
7643
7644
7645/***********************************************************************
7646 * Osmocom style dynamic PDCH
7647 ***********************************************************************/
7648
7649private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
7650 template (omit) RSL_Cause nack := omit)
7651runs on test_CT {
7652 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
7653 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02007654 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02007655 /* FIXME: no VTY command to activate Osmocom PDCH !! */
7656 /* expect the BSC to issue the related RSL command */
7657 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
7658 if (istemplatekind(nack, "omit")) {
7659 /* respond with a related acknowledgement */
7660 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7661 } else {
7662 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
7663 }
7664}
7665
7666private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
7667 template (omit) RSL_Cause nack := omit)
7668runs on test_CT {
7669 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
7670 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02007671 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02007672 /* FIXME: no VTY command to activate Osmocom PDCH !! */
7673 /* expect the BSC to issue the related RSL command */
7674 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
7675 if (istemplatekind(nack, "omit")) {
7676 /* respond with a related acknowledgement */
7677 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
7678 } else {
7679 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
7680 }
7681}
7682
7683/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
7684testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
7685 var RSL_Message rsl_unused;
7686
7687 /* change Timeslot 6 before f_init() starts RSL */
7688 f_init_vty();
7689 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
7690 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7691
7692 f_init(1, false);
7693 f_sleep(1.0);
7694
7695 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
7696
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007697 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007698 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7699 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007700 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Harald Welte94e0c342018-04-07 11:33:23 +02007701
7702 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7703 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007704 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 +02007705 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7706
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007707 /* clean up config */
7708 f_ts_set_chcomb(0, 0, 6, "PDCH");
7709
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007710 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007711}
7712
7713/* Test Osmocom dyn PDCH activation NACK behavior */
7714testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
7715 var RSL_Message rsl_unused;
7716
7717 /* change Timeslot 6 before f_init() starts RSL */
7718 f_init_vty();
7719 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
7720 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7721
7722 f_init(1, false);
7723 f_sleep(1.0);
7724
7725 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
7726
7727 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7728 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007729 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Harald Welte94e0c342018-04-07 11:33:23 +02007730
7731 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
7732 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
7733 f_sleep(1.0);
7734 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7735
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007736 /* clean up config */
7737 f_ts_set_chcomb(0, 0, 6, "PDCH");
7738
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007739 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007740}
7741
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007742/* Test Osmocom dyn TS SDCCH8 activation / deactivation */
7743testcase TC_dyn_ts_sdcch8_act_deact() runs on test_CT {
7744 var RSL_Message rsl_unused, rsl_msg;
7745 var DchanTuple dt;
7746 var BSSAP_N_CONNECT_ind rx_c_ind;
7747
7748 /* change Timeslot 6 before f_init() starts RSL */
7749 f_init_vty();
7750 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
7751 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7752
7753 f_init(1, false);
7754 f_sleep(1.0);
7755
7756 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7757
7758 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7759 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7760 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007761 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007762
7763 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7764 f_sleep(1.0);
7765 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7766 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7767
7768 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7769 * on CCCH+SDCCH4+CBCH) */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007770 var DchanTuples sdcch_cleanup := {};
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007771 var integer i;
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007772 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007773 dt := f_est_dchan('23'O, i, '00010203040506'O);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007774 sdcch_cleanup := sdcch_cleanup & { dt };
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007775 }
7776
7777 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
7778 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
7779 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7780 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7781
7782 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7783 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7784
7785 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7786 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
7787 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7788 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7789
7790 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
7791 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
7792 dt.sccp_conn_id := rx_c_ind.connectionId;
7793 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
7794
7795 /* Instruct BSC to clear channel */
7796 var BssmapCause cause := 0;
7797 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7798 f_exp_chan_rel_and_clear(dt, 0);
7799
7800 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007801 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007802 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7803 f_sleep(1.0);
7804 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7805
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007806 /* Clean up SDCCH lchans */
7807 for (i := 0; i < lengthof(sdcch_cleanup); i := i + 1) {
7808 f_perform_clear_test_ct(sdcch_cleanup[i]);
7809 }
7810
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007811 /* clean up config */
7812 f_ts_set_chcomb(0, 0, 6, "PDCH");
7813
7814 f_shutdown_helper();
7815}
7816
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007817/* Validate all 8 subslots of a dynamics TS configured as SDCCH8 are used */
7818testcase TC_dyn_ts_sdcch8_all_subslots_used() runs on test_CT {
7819 var ASP_RSL_Unitdata rsl_ud;
7820 var integer i;
7821 var integer chreq_total, chreq_nochan;
7822
7823 f_init_vty();
7824 for (i := 1; i < 8; i := i + 1) {
7825 if (i == 2) {
7826 f_ts_set_chcomb(0, 0, i, "TCH/F_TCH/H_SDCCH8_PDCH");
7827 } else {
7828 f_ts_set_chcomb(0, 0, i, "PDCH");
7829 }
7830 }
7831 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7832
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007833 f_init(1, guard_timeout := 60.0);
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007834
7835 /* The dyn TS want to activate PDCH mode, ACK that. */
7836 var RslChannelNr chan_nr;
7837 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007838 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007839 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7840
7841 f_sleep(1.0);
7842
7843 /* Exhaust all dedicated SDCCH lchans.
7844 /* GSM 44.018 Table 9.1.8.2:
7845 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
7846 */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007847 var DchanTuples chan_cleanup := {};
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007848 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007849 chan_cleanup := chan_cleanup & { f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007850 }
7851
7852 /* Only the dyn TS is still available. Its first lchan gets converted to SDCCH8 */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007853 chan_cleanup := chan_cleanup & { f_est_dchan_dyn('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007854 /* Also occupy the seven other SDCCH of the dyn TS */
7855 for (i := 0; i < 7; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007856 chan_cleanup := chan_cleanup & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
7857 }
7858
7859 /* Clean up SDCCH lchans */
7860 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
7861 f_perform_clear_test_ct(chan_cleanup[i]);
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007862 }
7863
7864 /* clean up config */
7865 f_ts_reset_chcomb(0);
7866
7867 f_shutdown_helper();
7868}
7869
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007870/* Test Osmocom dyn TS SDCCH8 activation / deactivation: If activating dyn TS as
7871 SDCCH8 would end up in having no free TCH, then BSC should decide to activate
7872 it as TCH directly instead. SYS#5309. */
7873testcase TC_dyn_ts_sdcch8_tch_call_act_deact() runs on test_CT {
7874 var RSL_Message rsl_unused, rsl_msg;
7875 var DchanTuple dt;
7876 var BSSAP_N_CONNECT_ind rx_c_ind;
7877 var integer i;
7878
7879 /* change Timeslot 6 before f_init() starts RSL */
7880 f_init_vty();
7881 for (i := 1; i < 8; i := i + 1) {
7882 if (i == 6) {
7883 f_ts_set_chcomb(0, 0, i, "TCH/F_TCH/H_SDCCH8_PDCH");
7884 } else {
7885 f_ts_set_chcomb(0, 0, i, "PDCH");
7886 }
7887 }
7888 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7889
7890 f_init(1, false);
7891 f_sleep(1.0);
7892
7893 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7894
7895 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7896 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7897 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007898 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007899
7900 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7901 f_sleep(1.0);
7902 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7903 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7904
7905 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7906 * on CCCH+SDCCH4+CBCH) */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007907 var DchanTuples chan_cleanup := {};
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007908 var OCT1 ra := '43'O; /* RA containing reason=originating speech call*/
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007909 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007910 dt := f_est_dchan(ra, i, '00010203040506'O);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007911 chan_cleanup := chan_cleanup & { dt };
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007912 }
7913
7914 /* Now the dyn ts is selected. First PDCH is released, then TCH chan is activated */
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007915 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int(ra) + i, 1), 2342));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007916 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7917 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7918
7919 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7920 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7921
7922 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
7923 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
7924 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7925 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
7926
7927 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
7928 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
7929 dt.sccp_conn_id := rx_c_ind.connectionId;
7930 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
7931
7932 /* Instruct BSC to clear channel */
7933 var BssmapCause cause := 0;
7934 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7935 f_exp_chan_rel_and_clear(dt, 0);
7936
7937 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007938 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007939 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7940 f_sleep(1.0);
7941 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7942
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007943 /* Clean up SDCCH lchans */
7944 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
7945 f_perform_clear_test_ct(chan_cleanup[i]);
7946 }
7947
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007948 /* clean up config */
7949 f_ts_reset_chcomb(0);
7950 /* TODO: clean up other channels? */
7951
7952 f_shutdown_helper();
7953}
7954
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007955/* Test Osmocom dyn TS SDCCH8 activation / deactivation when SDCCH fails at BTS */
7956testcase TC_dyn_ts_sdcch8_act_nack() runs on test_CT {
7957 var RSL_Message rsl_unused, rsl_msg;
7958 var DchanTuple dt;
7959 var BSSAP_N_CONNECT_ind rx_c_ind;
7960 var GsmRrMessage rr;
7961
7962 /* change Timeslot 6 before f_init() starts RSL */
7963 f_init_vty();
7964 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
7965 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7966
7967 f_init(1, false);
7968 f_sleep(1.0);
7969
7970 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7971
7972 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7973 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7974 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007975 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007976
7977 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7978 f_sleep(1.0);
7979 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7980 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7981
7982 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7983 * on CCCH+SDCCH4+CBCH) */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007984 var DchanTuples chan_cleanup := {};
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007985 var integer i;
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007986 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007987 dt := f_est_dchan('23'O, i, '00010203040506'O);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007988 chan_cleanup := chan_cleanup & { dt };
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007989 }
7990
7991 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
7992 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
7993 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7994 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7995
7996 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7997 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7998
7999 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
8000 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(dt.rsl_chan_nr, RSL_ERR_EQUIPMENT_FAIL));
8001 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
8002 rr := dec_GsmRrMessage(rsl_msg.ies[1].body.full_imm_ass_info.payload);
8003 if (rr.header.message_type != IMMEDIATE_ASSIGNMENT_REJECT) {
8004 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Expected reject");
8005 }
8006
8007 /* FIXME? Currently the TS stays in state BORKEN: */
8008
8009 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06008010 /* rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02008011 * f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
8012 * f_sleep(1.0);
8013 * f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE)
8014 */
8015
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01008016 /* Clean up SDCCH lchans */
8017 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
8018 f_perform_clear_test_ct(chan_cleanup[i]);
8019 }
8020
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02008021 /* clean up config */
8022 f_ts_set_chcomb(0, 0, 6, "PDCH");
8023
8024 f_shutdown_helper();
8025}
8026
Stefan Sperling0796a822018-10-05 13:01:39 +02008027testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02008028 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02008029 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
8030 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
8031 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008032 f_shutdown_helper();
Stefan Sperling0796a822018-10-05 13:01:39 +02008033}
8034
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008035testcase TC_chopped_ipa_payload() runs on test_CT {
8036 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
8037 /* TODO: mp_bsc_ctrl_port does not work yet */};
8038 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
8039 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
8040 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008041 f_shutdown_helper();
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008042}
8043
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01008044/* Verify the BSC sends the MS Power Parameters IE during CHAN ACT to make sure
8045 the BTS does autonomous MS power control loop */
8046testcase TC_assignment_verify_ms_power_params_ie() runs on test_CT {
8047 var MSC_ConnHdlr vc_conn;
8048 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8049 //pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
8050 pars.exp_ms_power_params := true;
8051
8052 f_init(1, true);
8053 f_sleep(1.0);
8054 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
8055 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008056 f_shutdown_helper();
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01008057}
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02008058
Vadim Yanitskiy4b233042021-06-30 00:58:43 +02008059/* Verify activation and deactivation of the BCCH carrier power reduction mode */
8060testcase TC_c0_power_red_mode() runs on test_CT {
8061 f_init(1);
8062
8063 for (var integer red := 6; red >= 0; red := red - 2) {
8064 /* Configure BCCH carrier power reduction mode via the VTY */
8065 f_vty_transceive(BSCVTY, "bts 0 c0-power-reduction " & int2str(red));
8066
8067 /* Expect Osmocom specific BS Power Control message on the RSL */
Vadim Yanitskiy35c9a332022-03-16 20:26:35 +03008068 var template (present) RSL_Message tr_rsl_pdu := tr_RSL_BS_PWR_CTRL(
Vadim Yanitskiy4b233042021-06-30 00:58:43 +02008069 chan_nr := t_RslChanNr_BCCH(0),
8070 bs_power := tr_RSL_IE_BS_Power(red / 2));
8071 tr_rsl_pdu.msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false);
8072 var RSL_Message unused := f_exp_ipa_rx(0, tr_rsl_pdu);
8073
8074 /* Additionally verify the applied value over the CTRL interface */
8075 var CtrlValue cred := f_ctrl_get_bts(IPA_CTRL, 0, "c0-power-reduction");
8076 if (cred != int2str(red)) {
8077 setverdict(fail, "Unexpected BCCH carrier power reduction value ",
8078 cred, " (expected ", red, ")");
8079 }
8080 }
8081
8082 f_shutdown_helper();
8083}
8084
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008085/***********************************************************************
8086 * MSC Pooling
8087 ***********************************************************************/
8088
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008089template MobileIdentityLV ts_MI_TMSI_NRI_LV(integer nri_v, integer nri_bitlen := 10) :=
Harald Weltebf397612021-01-14 20:39:46 +01008090 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 +02008091
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008092private 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 +02008093runs on MSC_ConnHdlr {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008094 interleave {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008095 [] rsl_pt.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008096 f_logp(BSCVTY, "Got RSL RR Release");
8097 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008098 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008099 f_logp(BSCVTY, "Got RSL Deact SACCH");
8100 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02008101 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008102 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008103 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
8104 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008105 break;
8106 }
8107 }
8108}
8109
Neels Hofmeyr6289af12021-12-16 18:17:49 +01008110private altstep as_mgcp_ack_all_dlcx() runs on MSC_ConnHdlr {
8111 var MgcpCommand mgcp_cmd;
8112 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
8113 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
8114 repeat;
8115 }
8116}
8117
8118private altstep as_rsl_ack_all_rel_req() runs on MSC_ConnHdlr {
8119 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
8120 [] RSL.receive(tr_RSL_REL_REQ(g_chan_nr, ?)) {
8121 RSL.send(ts_RSL_REL_CONF(g_chan_nr, main_dcch));
8122 repeat;
8123 }
8124}
8125
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008126friend function f_perform_clear(RSL_DCHAN_PT rsl_pt := RSL, RSLEM_PROC_PT rsl_proc_pt := RSL_PROC,
8127 template PDU_ML3_NW_MS exp_rr_rel_tmpl := tr_RRM_RR_RELEASE)
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02008128runs on MSC_ConnHdlr {
Neels Hofmeyr6289af12021-12-16 18:17:49 +01008129 var default ack_dlcx := activate(as_mgcp_ack_all_dlcx());
8130 var default ack_rel_req := activate(as_rsl_ack_all_rel_req());
Neels Hofmeyr767548a2020-08-09 20:26:07 +00008131 f_logp(BSCVTY, "MSC instructs BSC to clear channel");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008132 BSSAP.send(ts_BSSMAP_ClearCommand(0));
8133 interleave {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008134 [] rsl_pt.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00008135 f_logp(BSCVTY, "Got RSL RR Release");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008136 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008137 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00008138 f_logp(BSCVTY, "Got RSL Deact SACCH");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008139 }
8140 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00008141 f_logp(BSCVTY, "Got BSSMAP Clear Complete");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008142 /* Also drop the SCCP connection */
8143 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
8144 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02008145 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00008146 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008147 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
8148 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008149 }
8150 }
Neels Hofmeyr6289af12021-12-16 18:17:49 +01008151 deactivate(ack_dlcx);
8152 deactivate(ack_rel_req);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008153}
8154
Neels Hofmeyrc3c6ee62022-01-26 01:22:12 +01008155friend function f_perform_clear_no_rr_rel(RSL_DCHAN_PT rsl_pt := RSL, RSLEM_PROC_PT rsl_proc_pt := RSL_PROC)
8156runs on MSC_ConnHdlr {
8157 var default ack_dlcx := activate(as_mgcp_ack_all_dlcx());
8158 var default ack_rel_req := activate(as_rsl_ack_all_rel_req());
8159 f_logp(BSCVTY, "MSC instructs BSC to clear channel");
8160 BSSAP.send(ts_BSSMAP_ClearCommand(0));
8161 interleave {
8162 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
8163 f_logp(BSCVTY, "Got RSL Deact SACCH");
8164 }
8165 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
8166 f_logp(BSCVTY, "Got BSSMAP Clear Complete");
8167 /* Also drop the SCCP connection */
8168 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
8169 }
8170 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
8171 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
8172 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
8173 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
8174 }
8175 }
8176 deactivate(ack_dlcx);
8177 deactivate(ack_rel_req);
8178}
8179
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01008180friend function f_perform_clear_no_lchan()
8181runs on MSC_ConnHdlr {
8182 f_logp(BSCVTY, "MSC instructs BSC to clear channel");
8183 BSSAP.send(ts_BSSMAP_ClearCommand(0));
8184 BSSAP.receive(tr_BSSMAP_ClearComplete);
8185 f_logp(BSCVTY, "Got BSSMAP Clear Complete");
8186 /* Also drop the SCCP connection */
8187 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
8188}
8189
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01008190private function f_perform_clear_test_ct(DchanTuple dt)
8191 runs on test_CT
8192{
8193 /* Instruct BSC to clear channel */
8194 var BssmapCause cause := 0;
8195 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
8196 f_exp_chan_rel_and_clear(dt, 0);
8197}
8198
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008199private function f_perform_compl_l3(RSL_DCHAN_PT rsl_pt, RSLEM_PROC_PT rsl_proc_pt,
8200 template PDU_ML3_MS_NW l3_info, boolean do_clear := true, boolean expect_bssmap_l3 := true)
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008201runs on MSC_ConnHdlr {
8202 timer T := 10.0;
8203 var octetstring l3_enc := enc_PDU_ML3_MS_NW(valueof(l3_info));
8204
Neels Hofmeyr767548a2020-08-09 20:26:07 +00008205 f_logp(BSCVTY, "establish channel, send Complete Layer 3 Info");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008206 f_create_bssmap_exp(l3_enc);
8207
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008208 /* RSL_Emulation.f_chan_est() on rsl_pt:
8209 * This is basically code dup with s/RSL/rsl_pt from:
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008210 * RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
8211 */
8212 var RSL_Message rx_rsl;
8213 var GsmRrMessage rr;
8214
8215 /* request a channel to be established */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008216 rsl_pt.send(ts_RSLDC_ChanRqd(g_pars.ra, g_pars.fn));
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008217 /* expect immediate assignment.
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008218 * Code dup with s/RSL/rsl_pt from:
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008219 * rx_rsl := f_rx_or_fail(tr_RSL_IMM_ASSIGN);
8220 */
8221 timer Tt := 10.0;
8222
8223 /* request a channel to be established */
8224 Tt.start;
8225 alt {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008226 [] rsl_pt.receive(tr_RSL_IMM_ASSIGN) -> value rx_rsl {
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008227 Tt.stop;
8228 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008229 [] rsl_pt.receive {
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008230 setverdict(fail, "Unexpected RSL message on DCHAN");
8231 mtc.stop;
8232 }
8233 [] Tt.timeout {
8234 setverdict(fail, "Timeout waiting for RSL on DCHAN");
8235 mtc.stop;
8236 }
8237 }
8238 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
8239 g_chan_nr := rr.payload.imm_ass.chan_desc.chan_nr;
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008240 rsl_pt.send(ts_RSL_EST_IND(g_chan_nr, valueof(g_pars.link_id), l3_enc));
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008241
8242
Neels Hofmeyr66e15092020-10-12 18:44:41 +00008243 if (expect_bssmap_l3) {
8244 f_logp(BSCVTY, "expect BSSAP Complete Layer 3 Info at MSC");
8245 var template PDU_BSSAP exp_l3_compl;
8246 exp_l3_compl := tr_BSSMAP_ComplL3()
8247 if (g_pars.aoip == false) {
8248 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := omit;
8249 } else {
8250 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := ?;
8251 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008252
Neels Hofmeyr66e15092020-10-12 18:44:41 +00008253 var PDU_BSSAP bssap;
8254 T.start;
8255 alt {
8256 [] BSSAP.receive(exp_l3_compl) -> value bssap {
8257 f_logp(BSCVTY, "received expected Complete Layer 3 Info at MSC");
8258 log("rx exp_l3_compl = ", bssap);
8259 }
8260 [] BSSAP.receive(tr_BSSMAP_ComplL3) {
8261 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching COMPLETE LAYER 3 INFORMATION");
8262 }
8263 [] T.timeout {
8264 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
8265 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008266 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008267
Neels Hofmeyr66e15092020-10-12 18:44:41 +00008268 /* start ciphering, if requested */
8269 if (ispresent(g_pars.encr)) {
8270 f_logp(BSCVTY, "start ciphering");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008271 f_cipher_mode(g_pars.encr, rsl_pt := rsl_pt, rsl_proc_pt := rsl_proc_pt);
Neels Hofmeyr66e15092020-10-12 18:44:41 +00008272 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008273 }
8274
8275 if (do_clear) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008276 f_perform_clear(rsl_pt, rsl_proc_pt);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008277 }
8278 setverdict(pass);
8279 f_sleep(1.0);
8280}
8281
8282private function f_tc_mscpool_compl_l3(charstring id) runs on MSC_ConnHdlr {
8283 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8284 if (g_pars.mscpool.rsl_idx == 0) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008285 f_perform_compl_l3(RSL, RSL_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008286 } else if (g_pars.mscpool.rsl_idx == 1) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008287 f_perform_compl_l3(RSL1, RSL1_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008288 } else if (g_pars.mscpool.rsl_idx == 2) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008289 f_perform_compl_l3(RSL2, RSL2_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008290 }
8291}
8292
8293/* Various Complete Layer 3 by IMSI all end up with the first MSC, because the other MSCs are not connected. */
8294private function f_tc_mscpool_L3Compl_on_1_msc(charstring id) runs on MSC_ConnHdlr {
8295 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008296 f_perform_compl_l3(RSL, RSL_PROC, ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O) );
8297 f_perform_compl_l3(RSL, RSL_PROC, ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_IMSI_LV('001010000000002'H))) );
8298 f_perform_compl_l3(RSL, RSL_PROC, ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))) );
8299 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 +02008300}
8301testcase TC_mscpool_L3Compl_on_1_msc() runs on test_CT {
8302
8303 f_init(1, true);
8304 f_sleep(1.0);
8305 var MSC_ConnHdlr vc_conn;
8306 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008307
8308 f_ctrs_msc_init();
8309
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008310 vc_conn := f_start_handler(refers(f_tc_mscpool_L3Compl_on_1_msc), pars);
8311 vc_conn.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008312
8313 f_ctrs_msc_expect(0, "mscpool:subscr:new", 4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008314 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008315}
8316
8317/* Three Layer 3 Complete by IMSI are round-robin'ed across two connected MSCs */
8318/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8319 * just as well using only RSL. */
8320testcase TC_mscpool_L3Complete_by_imsi_round_robin() runs on test_CT {
8321
8322 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8323 f_sleep(1.0);
8324
8325 /* Control which MSC gets chosen next by the round-robin, otherwise
8326 * would be randomly affected by which other tests ran before this. */
8327 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8328
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008329 f_ctrs_msc_init();
8330
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008331 var MSC_ConnHdlr vc_conn1;
8332 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8333 pars1.mscpool.rsl_idx := 0;
8334 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
8335 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8336 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008337 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008338
8339 var MSC_ConnHdlr vc_conn2;
8340 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8341 pars2.mscpool.rsl_idx := 1;
8342 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8343 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8344 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008345 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008346
8347 /* Test round-robin wrap to the first MSC */
8348 var MSC_ConnHdlr vc_conn3;
8349 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8350 pars3.mscpool.rsl_idx := 2;
8351 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
8352 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8353 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008354 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008355 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008356}
8357
8358/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 0
8359 * (configured in osmo-bsc.cfg). */
8360/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8361 * just as well using only RSL. */
8362testcase TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() runs on test_CT {
8363
8364 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8365 f_sleep(1.0);
8366
8367 /* Control which MSC gets chosen next by the round-robin, otherwise
8368 * would be randomly affected by which other tests ran before this. */
8369 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8370
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008371 f_ctrs_msc_init();
8372
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008373 var MSC_ConnHdlr vc_conn1;
8374 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8375 pars1.mscpool.rsl_idx := 0;
8376 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
8377 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8378 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008379 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008380
8381 var MSC_ConnHdlr vc_conn2;
8382 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8383 pars2.mscpool.rsl_idx := 1;
8384 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
8385 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8386 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008387 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008388
8389 /* Test round-robin wrap to the first MSC */
8390 var MSC_ConnHdlr vc_conn3;
8391 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8392 pars3.mscpool.rsl_idx := 2;
8393 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
8394 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8395 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008396 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008397 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008398}
8399
8400/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 1
8401 * (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
8402 * NULL-NRI setting is stronger than that. */
8403/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8404 * just as well using only RSL. */
8405testcase TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() runs on test_CT {
8406
8407 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8408 f_sleep(1.0);
8409
8410 /* Control which MSC gets chosen next by the round-robin, otherwise
8411 * would be randomly affected by which other tests ran before this. */
8412 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8413
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008414 f_ctrs_msc_init();
8415
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008416 var MSC_ConnHdlr vc_conn1;
8417 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8418 pars1.mscpool.rsl_idx := 0;
8419 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8420 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8421 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008422 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008423
8424 var MSC_ConnHdlr vc_conn2;
8425 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8426 pars2.mscpool.rsl_idx := 1;
8427 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8428 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8429 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008430 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008431
8432 /* Test round-robin wrap to the first MSC */
8433 var MSC_ConnHdlr vc_conn3;
8434 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8435 pars3.mscpool.rsl_idx := 2;
8436 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8437 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8438 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008439 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008440 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008441}
8442
8443/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI not
8444 * assigned to any MSC (configured in osmo-bsc.cfg). */
8445/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8446 * just as well using only RSL. */
8447testcase TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() runs on test_CT {
8448
8449 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8450 f_sleep(1.0);
8451
8452 /* Control which MSC gets chosen next by the round-robin, otherwise
8453 * would be randomly affected by which other tests ran before this. */
8454 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8455
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008456 f_ctrs_msc_init();
8457
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008458 var MSC_ConnHdlr vc_conn1;
8459 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8460 pars1.mscpool.rsl_idx := 0;
8461 /* An NRI that is not assigned to any MSC */
8462 pars1.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(1023))));
8463 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8464 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008465 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008466
8467 var MSC_ConnHdlr vc_conn2;
8468 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8469 pars2.mscpool.rsl_idx := 1;
8470 /* An NRI that is not assigned to any MSC */
8471 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(768)), '00F110'O));
8472 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8473 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008474 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008475
8476 /* Test round-robin wrap to the first MSC */
8477 var MSC_ConnHdlr vc_conn3;
8478 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8479 pars3.mscpool.rsl_idx := 2;
8480 /* An NRI that is not assigned to any MSC */
8481 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, valueof(ts_MI_TMSI_NRI_LV(819))));
8482 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8483 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008484 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008485 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008486}
8487
8488/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI
8489 * assigned to an MSC that is currently not connected (configured in osmo-bsc.cfg). */
8490/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8491 * just as well using only RSL. */
8492testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() runs on test_CT {
8493
8494 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8495 f_sleep(1.0);
8496
8497 /* Control which MSC gets chosen next by the round-robin, otherwise
8498 * would be randomly affected by which other tests ran before this. */
8499 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8500
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008501 f_ctrs_msc_init();
8502
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008503 var MSC_ConnHdlr vc_conn1;
8504 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8505 pars1.mscpool.rsl_idx := 0;
8506 /* An NRI that is assigned to an unconnected MSC */
8507 pars1.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(512))));
8508 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8509 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008510 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8511 f_ctrs_msc_add(0, "mscpool:subscr:new");
8512 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008513
8514 var MSC_ConnHdlr vc_conn2;
8515 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8516 pars2.mscpool.rsl_idx := 1;
8517 /* An NRI that is assigned to an unconnected MSC */
8518 pars2.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(767))));
8519 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8520 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008521 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8522 f_ctrs_msc_add(1, "mscpool:subscr:new");
8523 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008524
8525 /* Test round-robin wrap to the first MSC */
8526 var MSC_ConnHdlr vc_conn3;
8527 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8528 pars3.mscpool.rsl_idx := 2;
8529 /* An NRI that is assigned to an unconnected MSC */
8530 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(750)), '00F110'O));
8531 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8532 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008533 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8534 f_ctrs_msc_add(0, "mscpool:subscr:new");
8535 f_ctrs_msc_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008536 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008537}
8538
8539/* Three Layer 3 Complete by TMSI with valid NRI for the second MSC are all directed to the second MSC (configured in
8540 * osmo-bsc.cfg). */
8541/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8542 * just as well using only RSL. */
8543testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_1() runs on test_CT {
8544
8545 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8546 f_sleep(1.0);
8547
8548 /* All TMSIs in this test point at the second MSC, set the round robin to point at the first MSC to make sure
8549 * this is not using round-robin. */
8550 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8551
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008552 f_ctrs_msc_init();
8553
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008554 var MSC_ConnHdlr vc_conn1;
8555 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
8556 pars1.mscpool.rsl_idx := 0;
8557 /* An NRI of the second MSC's range (256-511) */
8558 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(256))));
8559 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8560 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008561 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008562
8563 var MSC_ConnHdlr vc_conn2;
8564 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8565 pars2.mscpool.rsl_idx := 1;
8566 /* An NRI of the second MSC's range (256-511) */
8567 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(260))));
8568 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8569 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008570 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008571
8572 var MSC_ConnHdlr vc_conn3;
8573 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
8574 pars3.mscpool.rsl_idx := 2;
8575 /* An NRI of the second MSC's range (256-511) */
8576 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(511)), '00F110'O));
8577 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8578 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008579 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008580 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008581}
8582
8583/* Layer 3 Complete by TMSI with valid NRI for the third MSC are directed to the third MSC (configured in osmo-bsc.cfg),
8584 * while a round-robin remains unaffected by that. */
8585/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8586 * just as well using only RSL. */
8587testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_2() runs on test_CT {
8588
8589 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8590 f_sleep(1.0);
8591
8592 /* All TMSIs in this test point at the third MSC, set the round robin to point at the second MSC to make sure
8593 * this is not using round-robin. */
8594 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
8595
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008596 f_ctrs_msc_init();
8597
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008598 var MSC_ConnHdlr vc_conn1;
8599 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 2);
8600 pars1.mscpool.rsl_idx := 0;
8601 /* An NRI of the third MSC's range (512-767) */
8602 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(512))));
8603 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8604 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008605 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008606
8607 var MSC_ConnHdlr vc_conn2;
8608 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8609 pars2.mscpool.rsl_idx := 1;
8610 /* An NRI of the third MSC's range (512-767) */
8611 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(678))));
8612 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8613 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008614 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008615
8616 /* The above forwardings to third MSC have not affected the round robin, which still points at the second MSC */
8617 var MSC_ConnHdlr vc_conn3;
8618 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
8619 pars3.mscpool.rsl_idx := 2;
8620 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000013'H)), '00F110'O));
8621 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8622 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008623 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008624 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008625}
8626
8627/* LU with a TMSI but indicating a different PLMN in its previous LAI: ignore the NRI. */
8628/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8629 * just as well using only RSL. */
8630testcase TC_mscpool_LU_by_tmsi_from_other_PLMN() runs on test_CT {
8631
8632 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8633 f_sleep(1.0);
8634
8635 /* The TMSIs in this test points at the second MSC, but since it is from a different PLMN, round-robin is used
8636 * instead, and hits msc 0. */
8637 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8638
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008639 f_ctrs_msc_init();
8640
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008641 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-bsc.cfg */
8642 var MSC_ConnHdlr vc_conn1;
8643 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8644 pars1.mscpool.rsl_idx := 0;
8645 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(260)), '99F999'O));
8646 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8647 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008648 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008649
8650 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
8651 var MSC_ConnHdlr vc_conn2;
8652 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8653 pars2.mscpool.rsl_idx := 1;
8654 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(555)), '00F110'O));
8655 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8656 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008657 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008658 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008659}
8660
8661/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by IMSI, which would be
8662 * round-robined to another MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
8663private function f_tc_mscpool_paging_imsi(charstring id) runs on MSC_ConnHdlr {
8664 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
8665 //cid_list := { cIl_allInBSS := ''O };
8666 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
8667 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
8668 var BSSAP_N_UNITDATA_req paging;
8669 var hexstring imsi := '001010000000123'H;
8670
8671 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8672
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008673 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008674 valueof(ts_BSSMAP_Paging(imsi, cid_list, omit, bssmap_chneed))));
8675 BSSAP.send(paging);
8676
8677 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
8678 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
8679 * channel number is picked here. */
8680 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
8681 f_rslem_register(0, new_chan_nr);
8682 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(imsi)));
8683 f_rslem_unregister(0, new_chan_nr);
8684
8685 /* Despite the round robin pointing at the second MSC ('roundrobin next 1'), the earlier Paging for the same IMSI
8686 * causes this Paging Response to go to the first MSC (bssap_idx := 0). */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008687 f_perform_compl_l3(RSL, RSL_PROC, ts_PAG_RESP(valueof(ts_MI_IMSI_LV(imsi))) );
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008688 f_sleep(1.0);
8689}
8690testcase TC_mscpool_paging_and_response_imsi() runs on test_CT {
8691 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
8692 f_sleep(1.0);
8693
8694 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
8695 * second MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
8696 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
8697
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008698 f_ctrs_msc_init();
8699
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008700 var MSC_ConnHdlr vc_conn1;
8701 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8702 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008703 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
8704 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008705 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_imsi), pars1);
8706 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008707 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008708 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008709}
8710
8711/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by TMSI with an NRI value
8712 * that matches a different MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
8713private function f_tc_mscpool_paging_tmsi(charstring id) runs on MSC_ConnHdlr {
8714 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
8715 //cid_list := { cIl_allInBSS := ''O };
8716 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
8717 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
8718 var integer nri_v := 300; /* <-- second MSC's NRI */
Harald Weltebf397612021-01-14 20:39:46 +01008719 var octetstring tmsi := f_gen_tmsi(suffix := 0, nri_v := nri_v);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008720 var BSSAP_N_UNITDATA_req paging;
8721
8722 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8723
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008724 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008725 valueof(ts_BSSMAP_Paging('001010000000011'H, cid_list, tmsi, bssmap_chneed))));
8726 BSSAP.send(paging);
8727
8728 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
8729 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
8730 * channel number is picked here. */
8731 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
8732 f_rslem_register(0, new_chan_nr);
8733 RSL.receive(tr_RSL_PAGING_CMD(t_MI_TMSI(tmsi)));
8734 f_rslem_unregister(0, new_chan_nr);
8735
8736 /* Despite the NRI matching the second MSC (NRI from 'msc 1' in osmo-bsc.cfg) and round robin pointing at the
8737 * third MSC ('roundrobin next 2'), the earlier Paging for the same TMSI causes this Paging Response to go to
8738 * the first MSC (bssap_idx := 0). */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008739 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 +02008740 f_sleep(1.0);
8741}
8742testcase TC_mscpool_paging_and_response_tmsi() runs on test_CT {
8743 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
8744 f_sleep(1.0);
8745
8746 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
8747 * third MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
8748 f_vty_transceive(BSCVTY, "mscpool roundrobin next 2");
8749
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008750 f_ctrs_msc_init();
8751
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008752 var MSC_ConnHdlr vc_conn1;
8753 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8754 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008755 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
8756 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008757 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_tmsi), pars1);
8758 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008759 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008760 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008761}
8762
8763/* For round-robin, skip an MSC that has 'no allow-attach' set. */
8764/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8765 * just as well using only RSL. */
8766testcase TC_mscpool_no_allow_attach_round_robin() runs on test_CT {
8767
8768 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8769 f_sleep(1.0);
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00008770 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
8771 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008772
8773 /* Control which MSC gets chosen next by the round-robin, otherwise
8774 * would be randomly affected by which other tests ran before this. */
8775 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8776
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008777 f_ctrs_msc_init();
8778
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008779 var MSC_ConnHdlr vc_conn1;
8780 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8781 pars1.mscpool.rsl_idx := 0;
8782 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
8783 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8784 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008785 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008786
8787 var MSC_ConnHdlr vc_conn2;
8788 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8789 pars2.mscpool.rsl_idx := 1;
8790 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8791 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8792 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008793 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008794
8795 var MSC_ConnHdlr vc_conn3;
8796 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8797 pars3.mscpool.rsl_idx := 2;
8798 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
8799 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8800 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008801 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008802 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008803}
8804
8805/* An MSC that has 'no allow-attach' set should still serve subscribers that are already attached according to their
8806 * TMSI NRI. */
8807testcase TC_mscpool_no_allow_attach_valid_nri() runs on test_CT {
8808
8809 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8810 f_sleep(1.0);
8811
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00008812 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
8813 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
8814
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008815 /* Control which MSC gets chosen next by the round-robin, otherwise
8816 * would be randomly affected by which other tests ran before this. */
8817 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8818
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008819 f_ctrs_msc_init();
8820
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008821 /* Round robin points at msc 0, but the valid NRI directs to msc 1, even though msc 1 has 'no allow-attach'. */
8822 var MSC_ConnHdlr vc_conn1;
8823 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
8824 pars1.mscpool.rsl_idx := 0;
8825 /* An NRI of the second MSC's range (256-511) */
8826 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_TMSI_NRI_LV(260))));
8827 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8828 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008829 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008830
8831 var MSC_ConnHdlr vc_conn2;
8832 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 0);
8833 pars2.mscpool.rsl_idx := 1;
8834 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8835 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8836 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008837 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008838
8839 var MSC_ConnHdlr vc_conn3;
8840 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 2);
8841 pars3.mscpool.rsl_idx := 2;
8842 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000003'H))));
8843 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8844 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008845 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008846 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008847}
8848
Philipp Maier783681c2020-07-16 16:47:06 +02008849/* Allow/Deny emergency calls globally via VTY */
8850private function f_vty_allow_emerg_msc(boolean allow) runs on test_CT {
8851 f_vty_enter_cfg_msc(BSCVTY, 0);
8852 if (allow) {
8853 f_vty_transceive(BSCVTY, "allow-emergency allow");
8854 } else {
8855 f_vty_transceive(BSCVTY, "allow-emergency deny");
8856 }
8857 f_vty_transceive(BSCVTY, "exit");
8858 f_vty_transceive(BSCVTY, "exit");
8859}
8860
8861/* Allow/Deny emergency calls per BTS via VTY */
8862private function f_vty_allow_emerg_bts(boolean allow, integer bts_nr) runs on test_CT {
8863 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8864 if (allow) {
8865 f_vty_transceive(BSCVTY, "rach emergency call allowed 1");
8866 } else {
8867 f_vty_transceive(BSCVTY, "rach emergency call allowed 0");
8868 }
8869 f_vty_transceive(BSCVTY, "exit");
8870 f_vty_transceive(BSCVTY, "exit");
Neels Hofmeyrb6ed80c2020-10-12 22:52:39 +00008871 f_vty_transceive(BSCVTY, "exit");
Philipp Maier783681c2020-07-16 16:47:06 +02008872}
8873
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02008874/* Allow/Forbid Fast Return after SRVCC on a given BTS via VTY */
8875private function f_vty_allow_srvcc_fast_return(boolean allow, integer bts_nr) runs on test_CT {
8876 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8877 if (allow) {
8878 f_vty_transceive(BSCVTY, "srvcc fast-return allow");
8879 } else {
8880 f_vty_transceive(BSCVTY, "srvcc fast-return forbid");
8881 }
8882 f_vty_transceive(BSCVTY, "exit");
8883 f_vty_transceive(BSCVTY, "exit");
8884 f_vty_transceive(BSCVTY, "exit");
8885}
8886
Pau Espin Pedrol14475352021-07-22 15:48:16 +02008887/* Allow/Forbid TCH for signalling if SDCCH exhausted on a given BTS via VTY */
8888private function f_vty_allow_tch_for_signalling(boolean allow, integer bts_nr) runs on test_CT {
8889 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8890 if (allow) {
8891 f_vty_transceive(BSCVTY, "channel allocator allow-tch-for-signalling 1");
8892 } else {
8893 f_vty_transceive(BSCVTY, "channel allocator allow-tch-for-signalling 0");
8894 }
8895 f_vty_transceive(BSCVTY, "exit");
8896 f_vty_transceive(BSCVTY, "exit");
8897 f_vty_transceive(BSCVTY, "exit");
8898}
8899
Philipp Maier783681c2020-07-16 16:47:06 +02008900/* Begin assignmet procedure and send an EMERGENCY SETUP (RR) */
8901private function f_assignment_emerg_setup() runs on MSC_ConnHdlr {
8902 var PDU_ML3_MS_NW emerg_setup;
8903 var octetstring emerg_setup_enc;
8904 var RSL_Message emerg_setup_data_ind;
8905
8906 f_establish_fully(omit, omit);
8907
8908 emerg_setup := valueof(ts_ML3_MO_CC_EMERG_SETUP(1, valueof(ts_Bcap_voice)));
8909 emerg_setup_enc := enc_PDU_ML3_MS_NW(emerg_setup);
8910 emerg_setup_data_ind := valueof(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), emerg_setup_enc));
8911
8912 RSL.send(emerg_setup_data_ind);
8913}
8914
8915/* Test if the EMERGENCY SETUP gets passed on to the MSC via A when EMERGENCY
8916 * CALLS are permitted by the BSC config. */
8917private function f_TC_assignment_emerg_setup_allow(charstring id) runs on MSC_ConnHdlr {
8918 var PDU_BSSAP emerg_setup_data_ind_bssap;
8919 var PDU_ML3_MS_NW emerg_setup;
8920 timer T := 3.0;
8921
8922 f_assignment_emerg_setup()
8923
8924 T.start;
8925 alt {
8926 [] BSSAP.receive(tr_BSSAP_DTAP) -> value emerg_setup_data_ind_bssap {
8927 emerg_setup := dec_PDU_ML3_MS_NW(emerg_setup_data_ind_bssap.pdu.dtap);
8928 if (not isbound(emerg_setup.msgs.cc.emergencySetup)) {
8929 setverdict(fail, "no emergency setup");
8930 }
8931 }
8932 [] BSSAP.receive {
8933 setverdict(fail, "unexpected BSSAP message!");
8934 }
8935 [] T.timeout {
8936 setverdict(fail, "timout waiting for EMERGENCY SETUP!");
8937 }
8938 }
8939
8940 setverdict(pass);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01008941 f_perform_clear();
Philipp Maier783681c2020-07-16 16:47:06 +02008942}
8943
8944/* Test if the EMERGENCY SETUP gets blocked by the BSC if EMERGENCY CALLS are
8945 * forbidden by the BSC config. */
8946private function f_TC_assignment_emerg_setup_deny(charstring id) runs on MSC_ConnHdlr {
8947 var PDU_BSSAP emerg_setup_data_ind_bssap;
8948 timer T := 3.0;
8949
8950 f_assignment_emerg_setup()
8951
8952 T.start;
8953 alt {
8954 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
8955 setverdict(pass);
8956 }
8957 [] RSL.receive {
8958 setverdict(fail, "unexpected RSL message!");
8959 }
8960 [] T.timeout {
8961 setverdict(fail, "timout waiting for RR CHANNEL RELEASE!");
8962 }
8963 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01008964 BSSAP.receive(tr_BSSMAP_ClearRequest);
Neels Hofmeyrc3c6ee62022-01-26 01:22:12 +01008965 f_perform_clear_no_rr_rel();
Philipp Maier783681c2020-07-16 16:47:06 +02008966}
8967
8968/* EMERGENCY CALL situation #1, allowed globally and by BTS */
8969testcase TC_assignment_emerg_setup_allow() runs on test_CT {
8970 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8971 var MSC_ConnHdlr vc_conn;
8972
8973 f_init(1, true);
8974 f_sleep(1.0);
8975
8976 f_vty_allow_emerg_msc(true);
8977 f_vty_allow_emerg_bts(true, 0);
8978 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_allow), pars);
8979 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008980 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008981}
8982
8983/* EMERGENCY CALL situation #2, forbidden globally but allowed by BTS */
8984testcase TC_assignment_emerg_setup_deny_msc() runs on test_CT {
8985 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8986 var MSC_ConnHdlr vc_conn;
8987
8988 f_init(1, true);
8989 f_sleep(1.0);
8990
8991 f_vty_allow_emerg_msc(false);
8992 f_vty_allow_emerg_bts(true, 0);
8993 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
8994 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008995 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008996}
8997
8998/* EMERGENCY CALL situation #3, allowed globally but forbidden by BTS */
8999testcase TC_assignment_emerg_setup_deny_bts() runs on test_CT {
9000 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9001 var MSC_ConnHdlr vc_conn;
9002
9003 /* Note: This simulates a spec violation by the MS, correct MS
9004 * implementations would not try to establish an emergency call because
9005 * the system information tells in advance that emergency calls are
9006 * not forbidden */
9007
9008 f_init(1, true);
9009 f_sleep(1.0);
9010
9011 f_vty_allow_emerg_msc(true);
9012 f_vty_allow_emerg_bts(false, 0);
9013 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
9014 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02009015 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02009016}
9017
Philipp Maier82812002020-08-13 18:48:27 +02009018/* Test what happens when an emergency call arrives while all TCH channels are
9019 * busy, the BSC is expected to terminate one call in favor of the incoming
9020 * emergency call */
9021testcase TC_emerg_premption() runs on test_CT {
9022 var ASP_RSL_Unitdata rsl_ud;
9023 var integer i;
9024 var integer chreq_total, chreq_nochan;
9025 var RSL_Message rx_rsl;
Philipp Maier82812002020-08-13 18:48:27 +02009026
9027 f_init(1);
9028 f_sleep(1.0);
9029
9030 f_vty_allow_emerg_msc(true);
9031 f_vty_allow_emerg_bts(true, 0);
9032
9033 /* Fill up all channels on the BTS */
9034 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
9035 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
9036 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 +02009037 f_chreq_act_ack('33'O, i);
Philipp Maier82812002020-08-13 18:48:27 +02009038 }
9039 IPA_RSL[0].clear;
9040 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
9041 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
9042
Neels Hofmeyrace698c2022-04-24 00:30:21 +02009043 /* Send EST IND for the first TCH, so we get to test the RR release cause */
9044 var RslChannelNr first_tch := valueof(t_RslChanNr_Bm(1));
9045 var octetstring l3 := '00010203040506'O;
9046 f_ipa_tx(0, ts_RSL_EST_IND(first_tch, valueof(ts_RslLinkID_DCCH(0)), l3));
9047
Neels Hofmeyrde564b12022-04-24 23:11:46 +02009048 /* Accept BSSAP conn, so we get to test the Clear Request cause */
9049 var BSSAP_N_CONNECT_ind rx_c_ind;
9050 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
9051 var integer sccp_conn_id := rx_c_ind.connectionId;
9052 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
9053
Philipp Maier82812002020-08-13 18:48:27 +02009054 /* Send Channel request for emegergency call */
9055 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
9056
9057 /* Expect the BSC to release one (the first) TCH/F on the BTS */
Neels Hofmeyrace698c2022-04-24 00:30:21 +02009058 f_expect_chan_rel(0, first_tch, expect_rr_chan_rel := true, expect_rll_rel_req := false,
9059 expect_rr_cause := GSM48_RR_CAUSE_PREMPTIVE_REL);
Philipp Maier82812002020-08-13 18:48:27 +02009060
Neels Hofmeyrde564b12022-04-24 23:11:46 +02009061 /* Also expect a BSSMAP Clear Request with PREEMPTION */
9062 var BSSAP_N_DATA_ind rx_clear_req;
9063 const myBSSMAP_Cause preemption := GSM0808_CAUSE_PREEMPTION;
9064 BSSAP.receive(tr_BSSAP_DATA_ind(sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_clear_req;
9065 log("XXX ", rx_clear_req);
9066 if (rx_clear_req.userData.pdu.bssmap.clearRequest.cause.causeValue != int2bit(enum2int(preemption), 7)) {
9067 setverdict(fail, "BSSMAP Clear Request: expected cause PREEMPTION");
9068 }
9069
Neels Hofmeyr32ef5912022-04-24 00:29:04 +02009070 /* Expect the BSC to send activate/assign the channel for the emergency call */
Philipp Maier82812002020-08-13 18:48:27 +02009071 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Neels Hofmeyr32ef5912022-04-24 00:29:04 +02009072 if (first_tch != rx_rsl.ies[0].body.chan_nr) {
9073 setverdict(fail, "different TCH lchan activated than expected");
9074 }
9075 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(first_tch, 33));
Philipp Maier82812002020-08-13 18:48:27 +02009076 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Philipp Maier104f4c02020-09-11 18:12:18 +02009077
Neels Hofmeyrde564b12022-04-24 23:11:46 +02009078 /* complete the BSSMAP Clear to satisfy the conn leak check */
9079 BSSAP.send(ts_BSSAP_DATA_req(sccp_conn_id, ts_BSSMAP_ClearCommand(enum2int(preemption))));
9080 BSSAP.receive(tr_BSSAP_DATA_ind(sccp_conn_id, tr_BSSMAP_ClearComplete)) {
9081 BSSAP.send(ts_BSSAP_DISC_req(sccp_conn_id, 0));
9082 }
9083
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02009084 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009085}
9086
9087/* Hopping parameters per a timeslot */
Vadim Yanitskiybc6654a2020-09-13 01:27:40 +07009088private type record length(0..64) of GsmArfcn ArfcnList;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009089private type record FHParamsTs {
9090 boolean enabled,
9091 uint6_t hsn,
9092 uint6_t maio,
9093 ArfcnList ma
9094};
9095
9096/* Hopping parameters per a transceiver */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009097private type record FHParamsTrx {
Philipp Maier798d8952021-10-19 14:43:19 +02009098 GsmBandArfcn arfcn,
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009099 FHParamsTs ts[8]
9100};
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009101
9102/* Randomly generate the hopping parameters for the given timeslot numbers */
9103private function f_TC_fh_params_gen(template integer tr_tn := (1, 3, 5))
9104runs on test_CT return FHParamsTrx {
9105 var FHParamsTrx fhp;
9106
Philipp Maier798d8952021-10-19 14:43:19 +02009107 /* Generate a random ARFCN in the range of 0 - 3. This ARFCN will
9108 * fall in the GSM900 band. */
9109 fhp.arfcn.arfcn := f_rnd_int(3);
9110 fhp.arfcn.pcs := false;
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009111
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009112 for (var integer tn := 0; tn < 8; tn := tn + 1) {
9113 if (not match(tn, tr_tn)) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009114 fhp.ts[tn].enabled := false;
9115 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009116 continue;
9117 }
9118
9119 /* Random HSN / MAIO values: 0..63 */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009120 fhp.ts[tn].hsn := f_rnd_int(64);
9121 fhp.ts[tn].maio := f_rnd_int(64);
9122 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009123
9124 /* Random Mobile Allocation (hopping channels) */
9125 var integer ma_len := 2 + f_rnd_int(9); /* 2..10 channels */
9126 var integer step := 3 + f_rnd_int(4); /* 3..6 stepping */
9127 for (var integer i := 1; i <= ma_len; i := i + 1) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009128 fhp.ts[tn].ma := fhp.ts[tn].ma & { i * step };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009129 }
9130
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009131 fhp.ts[tn].enabled := true;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009132 }
9133
9134 log("f_TC_fh_params_gen(): ", fhp);
9135 return fhp;
9136}
9137
9138/* Make sure that the given Channel Description IE matches the hopping configuration */
9139private function f_TC_fh_params_match_chan_desc(in FHParamsTrx fhp, in ChannelDescription cd)
9140{
9141 var template (present) ChannelDescription tr_cd;
9142 var template (present) MaioHsn tr_maio_hsn;
9143 var uint3_t tn := cd.chan_nr.tn;
9144
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009145 if (fhp.ts[tn].enabled) {
9146 tr_maio_hsn := tr_HsnMaio(fhp.ts[tn].hsn, fhp.ts[tn].maio);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009147 tr_cd := tr_ChanDescH1(cd.chan_nr, tr_maio_hsn);
9148 } else {
Philipp Maier798d8952021-10-19 14:43:19 +02009149 tr_cd := tr_ChanDescH0(cd.chan_nr, fhp.arfcn.arfcn);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009150 }
9151
9152 if (not match(cd, tr_cd)) {
9153 setverdict(fail, "Channel Description IE does not match: ",
9154 cd, " vs expected ", tr_cd);
9155 }
9156}
9157
9158/* Make sure that the given Mobile Allocation IE matches the hopping configuration */
9159private function f_TC_fh_params_match_ma(in FHParamsTrx fhp, uint3_t tn,
9160 in MobileAllocationLV ma)
9161{
9162 var template MobileAllocationLV tr_ma := f_TC_fh_params_gen_tr_ma(fhp, tn, ma);
9163
9164 if (not match(ma, tr_ma)) {
9165 setverdict(fail, "Mobile Allocation IE does not match (tn := ",
9166 tn, "): ", ma, " vs expected: ", tr_ma);
9167 } else {
9168 setverdict(pass);
9169 }
9170}
9171
9172private function f_TC_fh_params_gen_tr_ma(in FHParamsTrx fhp, uint3_t tn,
9173 in MobileAllocationLV ma)
9174return template MobileAllocationLV {
9175 /* Mobile Allocation IE is expected to be empty if hopping is not enabled */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009176 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009177 return { len := 0, ma := ''B };
9178 }
9179
9180 var bitstring full_mask := f_pad_bit(''B, 1024, '0'B);
9181 var bitstring slot_mask := f_pad_bit(''B, 1024, '0'B);
9182 var bitstring ma_mask := ''B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009183
9184 /* Compose the full bit-mask (all channels, up to 1024 entries) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009185 for (var integer i := 0; i < lengthof(fhp.ts); i := i + 1) {
9186 for (var integer j := 0; j < lengthof(fhp.ts[i].ma); j := j + 1) {
9187 if (full_mask[fhp.ts[i].ma[j]] == '1'B)
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009188 { continue; }
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009189 full_mask[fhp.ts[i].ma[j]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009190 }
9191 }
9192
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009193 /* Take ARFCN of the TRX itself into account */
Philipp Maier798d8952021-10-19 14:43:19 +02009194 full_mask[fhp.arfcn.arfcn] := '1'B;
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009195
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009196 /* Compose a bit-mask for the given timeslot number */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009197 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
9198 slot_mask[fhp.ts[tn].ma[i]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009199 }
9200
9201 /* Finally, compose the Mobile Allocation bit-mask */
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07009202 for (var integer i := 1; i < lengthof(full_mask); i := i + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009203 if (full_mask[i] != '1'B)
9204 { continue; }
9205
9206 /* FIXME: ma_mask := ma_mask & slot_mask[i]; // triggers a bug in TITAN */
9207 if (slot_mask[i] == '1'B) {
9208 ma_mask := ma_mask & '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009209 } else {
9210 ma_mask := ma_mask & '0'B;
9211 }
9212 }
9213
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07009214 /* ARFCN 0 (if present) goes to the last position of the bit-mask */
9215 if (full_mask[0] == '1'B) {
9216 /* FIXME: ma_mask := ma_mask & slot_mask[0]; // triggers a bug in TITAN */
9217 if (slot_mask[0] == '1'B) {
9218 ma_mask := ma_mask & '1'B;
9219 } else {
9220 ma_mask := ma_mask & '0'B;
9221 }
9222 }
9223
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009224 /* Ensure that ma_mask is octet-aligned */
Vadim Yanitskiy2aa02522020-09-06 14:05:23 +07009225 var integer ma_mask_len := (lengthof(ma_mask) + 8 - 1) / 8;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009226 ma_mask := f_pad_bit(ma_mask, ma_mask_len * 8, '0'B);
9227
9228 return { len := ma_mask_len, ma := ma_mask };
9229}
9230
Philipp Maier798d8952021-10-19 14:43:19 +02009231/* Configure the appropriate band for a given arfcn, exc */
9232private function f_TC_set_band_by_arfcn(integer bts_nr, GsmBandArfcn arfcn) runs on test_CT
9233{
9234 var charstring band;
9235 var GsmBandArfcn arfcn_ := valueof(ts_GsmBandArfcn(arfcn.arfcn, arfcn.pcs, false));
9236
9237 select (arfcn_) {
9238 case (tr_GsmBandArfcn((259..293), false, ?)) { band := "GSM450"; }
9239 case (tr_GsmBandArfcn((306..340), false, ?)) { band := "GSM480"; }
9240 case (tr_GsmBandArfcn((438..511), false, ?)) { band := "GSM750"; }
9241 case (tr_GsmBandArfcn((128..251), false, ?)) { band := "GSM850"; }
9242 case (tr_GsmBandArfcn((0..124), false, ?)) { band := "GSM900"; }
9243 case (tr_GsmBandArfcn((955..1023), false, ?)) { band := "GSM900"; }
9244 case (tr_GsmBandArfcn((512..885), false, ?)) { band := "DCS1800"; }
9245 case (tr_GsmBandArfcn((512..810), true, ?)) { band := "PCS1900"; }
9246 case else { return; }
9247 }
9248
9249 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
9250 f_vty_transceive(BSCVTY, "band " & band);
9251 f_vty_transceive(BSCVTY, "end");
9252}
9253
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009254/* Configure the hopping parameters in accordance with the given record */
9255private function f_TC_fh_params_set(in FHParamsTrx fhp,
9256 uint8_t bts_nr := 0,
9257 uint8_t trx_nr := 0)
9258runs on test_CT {
Philipp Maier798d8952021-10-19 14:43:19 +02009259
9260 f_TC_set_band_by_arfcn(bts_nr, fhp.arfcn);
9261
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009262 /* Enter the configuration node for the given BTS/TRX numbers */
9263 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
9264
Philipp Maier798d8952021-10-19 14:43:19 +02009265 f_vty_transceive(BSCVTY, "arfcn " & int2str(fhp.arfcn.arfcn));
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009266
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009267 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009268 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
9269
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009270 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009271 f_vty_transceive(BSCVTY, "hopping enabled 0");
9272 f_vty_transceive(BSCVTY, "exit"); /* go back */
9273 continue;
9274 }
9275
9276 /* Configure HSN / MAIO values */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009277 f_vty_transceive(BSCVTY, "hopping sequence-number " & int2str(fhp.ts[tn].hsn));
9278 f_vty_transceive(BSCVTY, "hopping maio " & int2str(fhp.ts[tn].maio));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009279
9280 /* Configure the Mobile Allocation (hopping channels) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009281 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
9282 f_vty_transceive(BSCVTY, "hopping arfcn add " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009283 }
9284
9285 f_vty_transceive(BSCVTY, "hopping enabled 1");
9286 f_vty_transceive(BSCVTY, "exit"); /* go back */
9287 }
9288
9289 f_vty_transceive(BSCVTY, "end");
9290}
9291
9292/* Disable frequency hopping on all timeslots */
9293private function f_TC_fh_params_unset(in FHParamsTrx fhp,
9294 uint8_t bts_nr := 0,
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009295 uint8_t trx_nr := 0,
Philipp Maier798d8952021-10-19 14:43:19 +02009296 GsmBandArfcn arfcn := {pcs := false, arfcn := 871})
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009297runs on test_CT {
Philipp Maier798d8952021-10-19 14:43:19 +02009298
9299 f_TC_set_band_by_arfcn(bts_nr, arfcn);
9300
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009301 /* Enter the configuration node for the given BTS/TRX numbers */
9302 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
9303
Philipp Maier798d8952021-10-19 14:43:19 +02009304 f_vty_transceive(BSCVTY, "arfcn " & int2str(arfcn.arfcn));
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009305
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009306 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009307 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
9308
9309 /* Delete all ARFCNs from the Mobile Allocation (if any) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009310 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
9311 f_vty_transceive(BSCVTY, "hopping arfcn del " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009312 }
9313
9314 f_vty_transceive(BSCVTY, "hopping enabled 0");
9315 f_vty_transceive(BSCVTY, "exit"); /* go back */
9316 }
9317
9318 f_vty_transceive(BSCVTY, "end");
9319 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9320}
9321
9322/* Verify presence and correctness of the hopping parameters (HSN, MAIO)
9323 * in the Channel Identification IE of the RSL CHANnel ACTIVation message. */
9324testcase TC_fh_params_chan_activ() runs on test_CT {
9325 var FHParamsTrx fhp := f_TC_fh_params_gen();
9326 var RSL_Message rsl_msg;
9327 var RSL_IE_Body ie;
9328
9329 f_init_vty();
9330
9331 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9332 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9333
9334 f_init(1);
9335
9336 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
9337 for (var integer i := 0; i < 9; i := i + 1) {
9338 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
9339 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9340
9341 /* Make sure that Channel Identification IE is present */
9342 if (not f_rsl_find_ie(rsl_msg, RSL_IE_CHAN_IDENT, ie)) {
9343 setverdict(fail, "RSL Channel Identification IE is absent");
9344 continue;
9345 }
9346
9347 /* Make sure that hopping parameters (HSN/MAIO) match */
9348 f_TC_fh_params_match_chan_desc(fhp, ie.chan_ident.ch_desc.v);
9349
9350 /* "Mobile Allocation shall be included but empty" - let's check this */
9351 if (ie.chan_ident.ma.v.len != 0) {
9352 setverdict(fail, "Mobile Allocation IE is not empty: ",
9353 ie.chan_ident.ma, ", despite it shall be");
9354 continue;
9355 }
9356 }
9357
9358 /* Disable frequency hopping */
9359 f_TC_fh_params_unset(fhp);
9360
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009361 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009362}
9363
9364/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Immediate Assignment */
9365testcase TC_fh_params_imm_ass() runs on test_CT {
9366 var FHParamsTrx fhp := f_TC_fh_params_gen();
9367 var RSL_Message rsl_msg;
9368 var RSL_IE_Body ie;
9369
9370 f_init_vty();
9371
9372 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9373 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9374
9375 f_init(1);
9376
9377 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
9378 for (var integer i := 0; i < 9; i := i + 1) {
9379 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
9380 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9381
9382 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9383 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
9384
9385 /* Make sure that Full Immediate Assign Info IE is present */
9386 if (not f_rsl_find_ie(rsl_msg, RSL_IE_FULL_IMM_ASS_INFO, ie)) {
9387 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
9388 continue;
9389 }
9390
9391 /* Decode the actual Immediate Assignment message */
9392 var GsmRrMessage rr_msg := dec_GsmRrMessage(ie.full_imm_ass_info.payload);
9393 if (not match(rr_msg.header, t_RrHeader(IMMEDIATE_ASSIGNMENT, ?))) {
9394 setverdict(fail, "Failed to match Immediate Assignment: ", rr_msg);
9395 continue;
9396 }
9397
9398 /* Make sure that hopping parameters (HSN/MAIO) match */
9399 f_TC_fh_params_match_chan_desc(fhp, rr_msg.payload.imm_ass.chan_desc);
9400
9401 /* Make sure that the Mobile Allocation IE matches */
9402 f_TC_fh_params_match_ma(fhp, rr_msg.payload.imm_ass.chan_desc.chan_nr.tn,
9403 rr_msg.payload.imm_ass.mobile_allocation);
9404 }
9405
9406 /* Disable frequency hopping */
9407 f_TC_fh_params_unset(fhp);
Philipp Maier82812002020-08-13 18:48:27 +02009408
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009409 f_shutdown_helper();
Philipp Maier82812002020-08-13 18:48:27 +02009410}
9411
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009412/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Assignment Command */
9413testcase TC_fh_params_assignment_cmd() runs on test_CT {
9414 var FHParamsTrx fhp := f_TC_fh_params_gen();
9415 var RSL_Message rsl_msg;
9416 var RSL_IE_Body ie;
9417
9418 f_init_vty();
9419
9420 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9421 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9422
9423 f_init(1);
9424
9425 /* HACK: work around "Couldn't find Expect for CRCX" */
9426 vc_MGCP.stop;
9427
9428 var template PDU_BSSAP ass_cmd := f_gen_ass_req();
9429 ass_cmd.pdu.bssmap.assignmentRequest.codecList := ts_BSSMAP_IE_CodecList({ts_CodecFR});
9430
9431 /* CS domain (TCH): 4 (TCH/F) + 2 (TCH/H) channels available
9432 * NOTE: only 3 SDCCH/4 channels are available on CCCH+SDCCH4+CBCH */
9433 for (var integer i := 0; i < 3; i := i + 1) {
9434 /* Establish a dedicated channel, so we can trigger (late) TCH assignment */
9435 var DchanTuple dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
9436
9437 /* Send a BSSMAP Assignment Command, expect CHANnel ACTIVation */
9438 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
9439 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9440
9441 /* ACKnowledge CHANnel ACTIVation, expect RSL DATA REQuest */
9442 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9443 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
9444
9445 /* Make sure that L3 Information IE is present */
9446 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
9447 setverdict(fail, "RSL L3 Information IE is absent");
9448 continue;
9449 }
9450
9451 /* Decode the L3 message and make sure it is (RR) Assignment Command */
9452 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
9453 if (not match(l3_msg.header, t_RrL3Header(ASSIGNMENT_COMMAND))) {
9454 setverdict(fail, "Failed to match Assignment Command: ", l3_msg);
9455 continue;
9456 }
9457
9458 /* Make sure that hopping parameters (HSN/MAIO) match */
9459 var ChannelDescription chan_desc := l3_msg.payload.ass_cmd.chan_desc;
9460 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9461
9462 /* Make sure that Cell Channel Description IE is present if FH is enabled */
9463 if (chan_desc.h and not ispresent(l3_msg.payload.ass_cmd.cell_chan_desc)) {
Vadim Yanitskiy38d069d2020-09-02 17:18:57 +07009464 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009465 continue;
9466 }
9467
9468 /* Make sure that the Mobile Allocation IE matches (if present) */
9469 var boolean ma_present := ispresent(l3_msg.payload.ass_cmd.mobile_allocation);
9470 if (chan_desc.h and ma_present) {
9471 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9472 l3_msg.payload.ass_cmd.mobile_allocation.v);
9473 } else if (chan_desc.h and not ma_present) {
9474 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9475 continue;
9476 } else if (not chan_desc.h and ma_present) {
9477 setverdict(fail, "FH disabled, but Mobile Allocation IE is present");
9478 continue;
9479 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01009480
9481 f_perform_clear_test_ct(dt);
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009482 }
9483
9484 /* Give the IUT some time to release all channels */
9485 f_sleep(3.0);
9486
9487 /* Disable frequency hopping */
9488 f_TC_fh_params_unset(fhp);
9489
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009490 f_shutdown_helper();
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009491}
9492
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009493/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Handover Command */
9494private function f_TC_fh_params_handover_cmd(in FHParamsTrx fhp)
9495runs on test_CT {
9496 var RSL_Message rsl_msg;
9497 var RSL_IE_Body ie;
9498 var DchanTuple dt;
9499
9500 /* Establish a dedicated channel, so we can trigger handover */
9501 dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
Vadim Yanitskiyc18ff472021-11-18 20:15:37 +03009502 f_sleep(0.5);
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009503
9504 /* Trigger handover from BTS0 to BTS1 */
9505 f_bts_0_cfg(BSCVTY, { "neighbor bts 1" });
9506 f_vty_handover(BSCVTY, 0, 0, dt.rsl_chan_nr, 1);
9507
9508 /* Expect RSL CHANnel ACTIVation on BTS1/TRX0/TS1 */
9509 rsl_msg := f_exp_ipa_rx(1, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9510
9511 /* ACKnowledge channel activation and expect (RR) Handover Command */
9512 f_ipa_tx(1, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9513 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
9514
9515 /* Make sure that L3 Information IE is present */
9516 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
9517 setverdict(fail, "RSL L3 Information IE is absent");
9518 return;
9519 }
9520
9521 /* Decode the L3 message and make sure it is (RR) Handover Command */
9522 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
9523 if (not match(l3_msg.header, t_RrL3Header(HANDOVER_COMMAND))) {
9524 setverdict(fail, "Failed to match Handover Command: ", l3_msg);
9525 return;
9526 }
9527
9528 /* Make sure that we've got SDCCH/8 on TS1 (expected to be hopping) */
9529 var ChannelDescription chan_desc := l3_msg.payload.ho_cmd.chan_desc;
9530 if (not match(chan_desc.chan_nr, t_RslChanNr_SDCCH8(1, ?))) {
9531 setverdict(fail, "Unexpected channel number: ", chan_desc.chan_nr);
9532 return;
9533 }
9534
9535 /* Make sure that hopping parameters (HSN/MAIO) match */
9536 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9537
9538 /* Make sure that Cell Channel Description IE is present */
9539 if (not ispresent(l3_msg.payload.ho_cmd.cell_chan_desc)) {
9540 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
9541 return;
9542 }
9543
9544 /* Make sure that the Mobile Allocation (after time) IE is present and matches */
9545 var boolean ma_present := ispresent(l3_msg.payload.ho_cmd.mobile_allocation);
9546 if (ma_present) {
9547 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9548 l3_msg.payload.ho_cmd.mobile_allocation.v);
9549 } else {
9550 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9551 return;
9552 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01009553
9554 f_perform_clear_test_ct(dt);
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009555}
9556testcase TC_fh_params_handover_cmd() runs on test_CT {
9557 var FHParamsTrx fhp := f_TC_fh_params_gen();
9558
9559 f_init_vty();
9560
9561 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8 on BTS1/TRX0 */
9562 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
9563
9564 f_vty_transceive(BSCVTY, "timeslot 0");
9565 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
9566 f_vty_transceive(BSCVTY, "exit"); /* go back */
9567
9568 f_vty_transceive(BSCVTY, "timeslot 1");
9569 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8");
9570 f_vty_transceive(BSCVTY, "end"); /* we're done */
9571
9572 f_TC_fh_params_set(fhp, 1); /* Enable frequency hopping on BTS1 */
9573 f_vty_transceive(BSCVTY, "drop bts connection 1 oml");
9574
9575 f_init(2);
9576
9577 f_TC_fh_params_handover_cmd(fhp);
9578
9579 /* Disable frequency hopping on BTS1 */
9580 f_TC_fh_params_unset(fhp, 1);
9581
9582 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
9583 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
9584
9585 f_vty_transceive(BSCVTY, "timeslot 0");
9586 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
9587 f_vty_transceive(BSCVTY, "exit"); /* go back */
9588
9589 f_vty_transceive(BSCVTY, "timeslot 1");
9590 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
9591 f_vty_transceive(BSCVTY, "end"); /* we're done */
9592
9593 f_shutdown_helper();
9594}
9595
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009596/* Verify the hopping parameters in System Information Type 4 */
9597testcase TC_fh_params_si4_cbch() runs on test_CT {
9598 var FHParamsTrx fhp := f_TC_fh_params_gen(tr_tn := 1);
9599 var ASP_RSL_Unitdata rx_rsl_ud;
9600 timer T := 5.0;
9601
9602 f_init_vty();
9603
9604 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8+CBCH */
9605 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
9606
9607 f_vty_transceive(BSCVTY, "timeslot 0");
9608 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
9609 f_vty_transceive(BSCVTY, "exit"); /* go back */
9610
9611 f_vty_transceive(BSCVTY, "timeslot 1");
9612 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8+cbch");
9613 f_vty_transceive(BSCVTY, "end"); /* we're done */
9614
9615 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9616 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9617
9618 f_init(1);
9619
9620 T.start;
9621 alt {
9622 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO(RSL_SYSTEM_INFO_4))) -> value rx_rsl_ud {
9623 var RSL_IE_Body ie := rx_rsl_ud.rsl.ies[2].body; /* FULL BCCH Information IE */
9624 var SystemInformation si := dec_SystemInformation(ie.other.payload);
9625
9626 /* Make sure that what we decoded is System Information Type 4 */
9627 if (si.header.message_type != SYSTEM_INFORMATION_TYPE_4) {
9628 setverdict(fail, "RSL FULL BCCH Information IE contains: ", si);
9629 repeat;
9630 }
9631
9632 /* Make sure that CBCH Channel Description IE is present */
9633 if (not ispresent(si.payload.si4.cbch_chan_desc)) {
9634 setverdict(fail, "CBCH Channel Description IE is absent");
9635 break;
9636 }
9637
9638 /* Finally, check the hopping parameters (HSN, MAIO) */
9639 var ChannelDescription chan_desc := si.payload.si4.cbch_chan_desc.v;
9640 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9641
9642 /* 3GPP TS 44.018, section 9.1.36.2 "CBCH Mobile Allocation":
9643 * The CBCH Mobile Allocation IE *shall* be present if FH is enabled. */
9644 if (chan_desc.h and not ispresent(si.payload.si4.cbch_mobile_alloc)) {
9645 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9646 break;
9647 } else if (chan_desc.h and ispresent(si.payload.si4.cbch_mobile_alloc)) {
9648 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9649 si.payload.si4.cbch_mobile_alloc.v);
9650 }
9651 }
9652 [] IPA_RSL[0].receive { repeat; }
9653 [] T.timeout {
9654 setverdict(fail, "Timeout waiting for RSL BCCH INFOrmation (SI4)");
9655 }
9656 }
9657
9658 /* Disable frequency hopping */
9659 f_TC_fh_params_unset(fhp);
9660
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07009661 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009662 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
9663
9664 f_vty_transceive(BSCVTY, "timeslot 0");
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07009665 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009666 f_vty_transceive(BSCVTY, "exit"); /* go back */
9667
9668 f_vty_transceive(BSCVTY, "timeslot 1");
9669 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
9670 f_vty_transceive(BSCVTY, "end"); /* we're done */
9671
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009672 f_shutdown_helper();
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009673}
9674
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009675template (value) PDU_BSSAP_LE ts_BSSMAP_LE_BSSLAP(template (value) BSSLAP_PDU bsslap)
9676 := ts_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, data := enc_BSSLAP_PDU(valueof(bsslap)));
9677
9678private function f_match_bsslap(PDU_BSSAP_LE got_bsslap_msg,
9679 template (present) BSSLAP_PDU expect_bsslap)
9680{
9681 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(got_bsslap_msg.pdu.bssmap.co_info.bsslap_apdu.data);
9682 if (not match(bsslap, expect_bsslap)) {
9683 log("EXPECTING BSSLAP: ", expect_bsslap);
9684 log("GOT BSSLAP: ", bsslap);
9685 setverdict(fail, "BSSLAP is not as expected");
9686 mtc.stop;
9687 }
9688 setverdict(pass);
9689}
9690
9691/* GAD: this is an Ellipsoid point with uncertainty circle, encoded as in 3GPP TS 23.032 §7.3.2. */
9692const octetstring gad_ell_point_unc_circle := '10b0646d0d5f6627'O;
9693
9694private function f_expect_bsslap(template (present) BSSLAP_PDU expect_rx_bsslap) runs on MSC_ConnHdlr {
9695 var PDU_BSSAP_LE rx_bsslap;
9696 BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap);
9697 f_match_bsslap(rx_bsslap, expect_rx_bsslap);
9698}
9699
9700/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9701 * Request on Lb interface. Either with or without the SMLC doing a BSSLAP TA Request. */
9702private function f_lcs_loc_req_for_active_ms(boolean do_ta_request := false) runs on MSC_ConnHdlr {
9703 f_sleep(1.0);
9704
9705 f_establish_fully(omit, omit);
9706 f_bssap_le_register_imsi(g_pars.imsi, omit);
9707
9708 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9709 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9710
9711 var PDU_BSSAP_LE plr;
9712 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9713
9714 if (not do_ta_request) {
9715 /* verify TA Layer 3 in APDU. First the APDU type (BSSLAP), then the BSSLAP data contents. */
9716 var template BSSMAP_LE_IE_APDU expect_apdu := tr_BSSMAP_LE_APDU(BSSMAP_LE_PROT_BSSLAP, ?);
9717 if (not match(plr.pdu.bssmap.perf_loc_req.bsslap_apdu, expect_apdu)) {
9718 log("EXPECTING BSSMAP-LE APDU IE ", expect_apdu);
9719 log("GOT BSSMAP-LE APDU IE ", plr.pdu.bssmap.perf_loc_req.bsslap_apdu);
9720 setverdict(fail, "BSSMAP-LE APDU IE is not as expected");
9721 mtc.stop;
9722 }
9723 var template BSSLAP_PDU expect_ta_layer3 := tr_BSSLAP_TA_Layer3(tr_BSSLAP_IE_TA(0));
9724 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(plr.pdu.bssmap.perf_loc_req.bsslap_apdu.data);
9725 if (not match(bsslap, expect_ta_layer3)) {
9726 log("EXPECTING BSSLAP TA Layer 3: ", expect_ta_layer3);
9727 log("GOT BSSLAP: ", bsslap);
9728 setverdict(fail, "BSSLAP is not as expected");
9729 mtc.stop;
9730 }
9731 /* OsmoBSC directly sent the TA as BSSLAP APDU in the BSSMAP-LE Perform Location Request to the SMLC. The SMLC
9732 * has no need to request the TA from the BSC and directly responds. */
9733 } else {
9734 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9735 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9736 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9737 }
9738
9739 /* SMLC got the TA from the BSC, now responds with geo information data. */
9740 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9741 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9742 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9743
9744 /* The LCS was using an active A-interface conn. It should still remain active after this. */
9745 f_mo_l3_transceive();
9746
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009747 f_perform_clear();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009748
9749 f_sleep(2.0);
9750 setverdict(pass);
9751}
9752
9753/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9754 * Request on Lb interface. Without the SMLC doing a BSSLAP TA Request. */
9755private function f_tc_lcs_loc_req_for_active_ms(charstring id) runs on MSC_ConnHdlr {
9756 f_lcs_loc_req_for_active_ms(false);
9757}
9758testcase TC_lcs_loc_req_for_active_ms() 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), 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/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9770 * Request on Lb interface. With the SMLC doing a BSSLAP TA Request. */
9771private function f_tc_lcs_loc_req_for_active_ms_ta_req(charstring id) runs on MSC_ConnHdlr {
9772 f_lcs_loc_req_for_active_ms(true);
9773}
9774testcase TC_lcs_loc_req_for_active_ms_ta_req() runs on test_CT {
9775 var MSC_ConnHdlr vc_conn;
9776 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9777
9778 f_init(1, true);
9779 f_sleep(1.0);
9780 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_ta_req), pars);
9781 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009782 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009783}
9784
9785/* Clear the A-interface conn only, without doing anything on Abis. Useful for LCS, for cases where there is only an A
9786 * conn without an active lchan. */
9787private function f_clear_A_conn() runs on MSC_ConnHdlr
9788{
9789 var BssmapCause cause := 0;
9790 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
9791 BSSAP.receive(tr_BSSMAP_ClearComplete);
9792 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
9793
9794 timer no_more_bssap := 5.0;
9795 no_more_bssap.start;
9796 alt {
9797 [] no_more_bssap.timeout { break; }
9798 [] BSSAP.receive(tr_BSSAP_BSSMAP) {
9799 setverdict(fail, "Expected no more BSSAP after Clear Complete");
9800 mtc.stop;
9801 }
9802 }
9803 setverdict(pass);
9804}
9805
9806/* Verify that the A-interface connection is still working, and then clear it, without doing anything on Abis. Useful
9807 * for LCS, for cases where there is only an A conn without an active lchan. */
9808private function f_verify_active_A_conn_and_clear() runs on MSC_ConnHdlr
9809{
9810 f_logp(BSCVTY, "f_verify_active_A_conn_and_clear: test A link, then clear");
9811
9812 /* When an lchan is active, we can send some L3 data from the BTS side and verify that it shows up on the other
9813 * side towards the MSC. When there is no lchan, this is not possible. To probe whether the A-interface
9814 * connection is still up, we need something that echos back on the A-interface. Another LCS request! */
9815 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9816 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9817 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?));
9818
9819 /* Right, the Perform Location Request showed up on Lb, now we can clear the A conn. */
9820 f_clear_A_conn();
9821 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
9822 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9823}
9824
9825/* With *no* active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9826 * Request on Lb interface. BSC will Page for the subscriber as soon as we (virtual SMLC) request the TA via BSSLAP.
9827 */
9828private function f_tc_lcs_loc_req_for_idle_ms(charstring id) runs on MSC_ConnHdlr {
9829 f_sleep(1.0);
9830
9831 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9832 f_bssap_le_register_imsi(g_pars.imsi, omit);
9833
9834 /* Register to receive the Paging Command */
9835 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9836 g_chan_nr := new_chan_nr;
9837 f_rslem_register(0, g_chan_nr);
9838
9839 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9840 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9841 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9842 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9843
9844 var PDU_BSSAP_LE plr;
9845 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9846
9847 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9848 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9849
9850 /* OsmoBSC needs to Page */
9851 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi)));
9852 f_logp(BSCVTY, "got Paging Command");
9853
9854 /* MS requests channel. Since the Paging was for LCS, the Paging Response does not trigger a Complete Layer 3 to
9855 * the MSC, and releases the lchan directly. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009856 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);
9857 f_expect_lchan_rel(RSL, RSL_PROC);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009858
9859 /* From the Paging Response, the TA is now known to the BSC, and it responds to the SMLC. */
9860
9861 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9862
9863 /* SMLC got the TA from the BSC, now responds with geo information data. */
9864 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9865 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9866
9867 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9868
9869 /* The lchan is gone, the A-interface conn was created for the LCS only.
9870 * Still it is clearly the MSC's job to decide whether to tear down the conn or not. */
9871 f_verify_active_A_conn_and_clear();
9872
9873 f_sleep(2.0);
9874 setverdict(pass);
9875}
9876testcase TC_lcs_loc_req_for_idle_ms() runs on test_CT {
9877 var MSC_ConnHdlr vc_conn;
9878 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9879
9880 f_init(1, true);
9881 f_sleep(1.0);
9882
9883 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9884 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9885
9886 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms), pars);
9887 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009888 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009889}
9890
9891/* With no active lchan, start BSSMAP Perform Location Request on A interface, but omit IMSI; expect failure response.
9892 */
9893private function f_tc_lcs_loc_req_no_subscriber(charstring id) runs on MSC_ConnHdlr {
9894 f_sleep(1.0);
9895
9896 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9897 f_bssap_le_register_imsi(g_pars.imsi, omit);
9898
9899 /* provoke an abort by omitting both IMSI and IMEI */
9900 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9901 valueof(ts_BSSMAP_Perform_Location_Request(omit,
9902 ts_CellId_CGI('262'H, '42'H, 23, 42)))));
9903 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9904
9905 /* BSC tells MSC about failure */
9906 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9907 locationEstimate := omit, positioningData := omit,
9908 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_DATA_MISSING_IN_REQ)));
9909
9910 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9911 f_verify_active_A_conn_and_clear();
9912
9913 f_sleep(2.0);
9914 setverdict(pass);
9915}
9916testcase TC_lcs_loc_req_no_subscriber() runs on test_CT {
9917 var MSC_ConnHdlr vc_conn;
9918 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9919
9920 f_init(1, true);
9921 f_sleep(1.0);
9922
9923 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9924 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9925
9926 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_no_subscriber), pars);
9927 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009928 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009929}
9930
9931/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9932 * BSSMAP-LE Perform Location Response (before or after sending a BSSLAP TA Request) */
9933private function f_lcs_loc_req_for_active_ms_le_timeout(boolean do_ta) runs on MSC_ConnHdlr {
9934 f_sleep(1.0);
9935
9936 f_establish_fully(omit, omit);
9937 f_bssap_le_register_imsi(g_pars.imsi, omit);
9938
9939 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9940 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9941
9942 var PDU_BSSAP_LE plr;
9943 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9944
9945 if (do_ta) {
9946 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9947 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9948 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9949 }
9950
9951 /* SMLC fails to respond, BSC runs into timeout */
9952 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_SYSTEM_FAILURE));
9953 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9954
9955 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9956 locationEstimate := omit, positioningData := omit,
9957 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_SYSTEM_FAILURE)));
9958
9959 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9960 f_verify_active_A_conn_and_clear();
9961
9962 f_sleep(2.0);
9963 setverdict(pass);
9964}
9965
9966/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9967 * BSSMAP-LE Perform Location Response, without sending a BSSLAP TA Request. */
9968private function f_tc_lcs_loc_req_for_active_ms_le_timeout(charstring id) runs on MSC_ConnHdlr {
9969 f_lcs_loc_req_for_active_ms_le_timeout(false);
9970}
9971
9972testcase TC_lcs_loc_req_for_active_ms_le_timeout() runs on test_CT {
9973 var MSC_ConnHdlr vc_conn;
9974 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9975
9976 f_init(1, true);
9977 f_sleep(1.0);
9978 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout), pars);
9979 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009980 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009981}
9982
9983/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9984 * BSSMAP-LE Perform Location Response, after sending a BSSLAP TA Request. */
9985private function f_tc_lcs_loc_req_for_active_ms_le_timeout2(charstring id) runs on MSC_ConnHdlr {
9986 f_lcs_loc_req_for_active_ms_le_timeout(true);
9987}
9988
9989testcase TC_lcs_loc_req_for_active_ms_le_timeout2() runs on test_CT {
9990 var MSC_ConnHdlr vc_conn;
9991 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9992
9993 f_init(1, true);
9994 f_sleep(1.0);
9995 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout2), pars);
9996 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009997 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009998}
9999
10000/* With *no* active lchan, start a Perform Location Request, expecting that the MS will be Paged. */
10001private function f_tc_lcs_loc_req_for_idle_ms_no_pag_resp(charstring id) runs on MSC_ConnHdlr {
10002 f_sleep(1.0);
10003
10004 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
10005 f_bssap_le_register_imsi(g_pars.imsi, omit);
10006
10007 /* Register to receive the Paging Command */
10008 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
10009 g_chan_nr := new_chan_nr;
10010 f_rslem_register(0, g_chan_nr);
10011
10012 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
10013 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
10014 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
10015 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
10016
10017 var PDU_BSSAP_LE plr;
10018 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
10019
10020 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
10021 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
10022
10023 /* OsmoBSC needs to Page */
10024 var PDU_BSSAP_LE rx_bsslap;
10025 alt {
10026 [] RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi))) {
10027 f_logp(BSCVTY, "got Paging Command");
10028 repeat;
10029 }
10030 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
10031 /* MS does not respond to Paging, TA Req runs into timeout. */
10032 f_match_bsslap(rx_bsslap, tr_BSSLAP_Abort(?));
10033 }
10034 }
10035
10036 /* SMLC responds with failure */
10037 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(omit, BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
10038 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
10039
10040 /* BSC tells MSC about failure */
10041 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
10042 locationEstimate := omit, positioningData := omit,
10043 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_REQUEST_ABORTED)));
10044
10045 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
10046 f_verify_active_A_conn_and_clear();
10047
10048 f_sleep(2.0);
10049 setverdict(pass);
10050}
10051testcase TC_lcs_loc_req_for_idle_ms_no_pag_resp() runs on test_CT {
10052 var MSC_ConnHdlr vc_conn;
10053 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10054
10055 f_init(1, true);
10056 f_sleep(1.0);
10057
10058 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
10059 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
10060
10061 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms_no_pag_resp), pars);
10062 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +010010063 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020010064}
10065
10066/* During an ongoing Location Request, the MS sends a CM Service Request. Expect the same A-conn to be re-used / taken
10067 * over. */
10068private function f_tc_cm_service_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
10069 f_sleep(1.0);
10070
10071 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
10072 f_bssap_le_register_imsi(g_pars.imsi, omit);
10073
10074 /* Register to receive the Paging Command */
10075 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
10076 g_chan_nr := new_chan_nr;
10077 f_rslem_register(0, g_chan_nr);
10078
10079 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
10080 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
10081 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
10082 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
10083
10084 var PDU_BSSAP_LE plr;
10085 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
10086
10087 /* As the A-interface conn was established for LCS, the MS coincidentally decides to issue a CM Service Request
10088 * and establish Layer 3. It should use the existing A-interface conn. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +020010089 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 +020010090 do_clear := false, expect_bssmap_l3 := true);
10091
10092 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
10093 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
10094
10095 /* OsmoBSC already has an lchan, no need to Page, just returns the TA */
10096 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
10097
10098 /* SMLC got the TA from the BSC, now responds with geo information data. */
10099 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
10100 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
10101 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
10102
10103 /* The lchan should still exist, it was from a CM Service Request. */
10104 f_mo_l3_transceive();
10105
Neels Hofmeyr85bcd272021-07-22 19:14:48 +020010106 f_perform_clear();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020010107
10108 f_sleep(2.0);
10109 setverdict(pass);
10110}
10111testcase TC_cm_service_during_lcs_loc_req() runs on test_CT {
10112 var MSC_ConnHdlr vc_conn;
10113 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10114
10115 f_init(1, true);
10116 f_sleep(1.0);
10117
10118 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
10119 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
10120
10121 vc_conn := f_start_handler(refers(f_tc_cm_service_during_lcs_loc_req), pars);
10122 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +010010123 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020010124}
10125
10126/* During an ongoing Perform Location Request, do a Handover, an expect a BSSLAP Reset message from the BSC to indicate
10127 * the new lchan after handover. */
10128private function f_tc_ho_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
10129 f_sleep(1.0);
10130
10131 f_establish_fully(omit, omit);
10132 f_bssap_le_register_imsi(g_pars.imsi, omit);
10133
10134 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
10135 ts_CellId_CGI('262'H, '42'H, 23, 42))));
10136
10137 var PDU_BSSAP_LE plr;
10138 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
10139
10140 /* SMLC ponders the Location Request, in the meantime the BSC decides to handover */
10141 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
10142
10143 var HandoverState hs := {
10144 rr_ho_cmpl_seen := false,
10145 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +020010146 old_chan_nr := -,
10147 expect_target_tsc := BTS_TSC[1]
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020010148 };
10149 /* issue hand-over command on VTY */
10150 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
10151 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
10152 f_rslem_suspend(RSL1_PROC);
10153
10154 /* From the MGW perspective, a handover is is characterized by
10155 * performing one MDCX operation with the MGW. So we expect to see
10156 * one more MDCX during handover. */
10157 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
10158
10159 alt {
10160 [] as_handover(hs);
10161 }
10162
10163 var PDU_BSSAP_LE rx_bsslap;
10164
10165 interleave {
10166 /* Expect the BSC to inform the MSC about the handover */
10167 [] BSSAP.receive(tr_BSSMAP_HandoverPerformed);
10168
10169 /* Expect the BSC to inform the SMLC about the handover */
10170 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
10171 f_match_bsslap(rx_bsslap, tr_BSSLAP_Reset(BSSLAP_CAUSE_INTRA_BSS_HO));
10172 }
10173 }
10174
10175 /* SMLC now responds with geo information data. */
10176 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
10177 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
10178 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
10179
10180 /* lchan still active */
10181 f_mo_l3_transceive(RSL1);
10182
10183 /* MSC decides it is done now. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +020010184 f_perform_clear(RSL1, RSL1_PROC);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020010185
10186 f_sleep(2.0);
10187 setverdict(pass);
10188}
10189testcase TC_ho_during_lcs_loc_req() runs on test_CT {
10190 var MSC_ConnHdlr vc_conn;
10191 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10192
10193 f_init(2, true);
10194 f_sleep(1.0);
10195 vc_conn := f_start_handler(refers(f_tc_ho_during_lcs_loc_req), pars);
10196 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +010010197 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020010198}
10199
Neels Hofmeyra47a8c62022-04-07 00:31:19 +020010200private function f_tc_emerg_call_and_lcs_loc_req(charstring id) runs on MSC_ConnHdlr
10201{
10202 /* Make sure the CHAN RQD indicates an emergency call (0b101xxxxx). The difference is that osmo-bsc directly
10203 * assigns a TCH lchan and establishing voice for the emergency call will use Mode Modify, not reassignment to
10204 * another lchan. */
10205 g_pars.ra := 'b7'O;
10206 f_assignment_emerg_setup();
10207
10208 var PDU_BSSAP emerg_setup_data_ind_bssap;
10209 timer T := 3.0;
10210 T.start;
10211 alt {
10212 [] BSSAP.receive(tr_BSSAP_DTAP) -> value emerg_setup_data_ind_bssap {
10213 var PDU_ML3_MS_NW verify_emerg_setup;
10214 verify_emerg_setup := dec_PDU_ML3_MS_NW(emerg_setup_data_ind_bssap.pdu.dtap);
10215 if (not isbound(verify_emerg_setup.msgs.cc.emergencySetup)) {
10216 setverdict(fail, "no emergency setup");
10217 }
10218 }
10219 [] BSSAP.receive {
10220 setverdict(fail, "unexpected BSSAP message!");
10221 }
10222 [] T.timeout {
10223 setverdict(fail, "timeout waiting for EMERGENCY SETUP!");
10224 }
10225 }
10226
10227 /* Here would usually be a CC Call Proceeding from the MSC, but what does the BSC care about DTAP. */
10228
10229 /* Do a Location Request in-between the CC call setup */
10230 f_bssap_le_register_imsi(g_pars.imsi, omit);
10231 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
10232 ts_CellId_CGI('262'H, '42'H, 23, 42))));
10233 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?));
10234 /* SMLC got the TA from the BSC, now responds with geo information data. */
10235 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
10236 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
10237 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
10238
10239 /* Go on with voice call assignment */
10240 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
10241 var PDU_BSSAP ass_cmd := f_gen_ass_req();
10242
10243 /* Below speechOrDataIndicator and codecList are copied from an emergency call captured during tests.
10244 * They seem a bit weird (AMR-WB, and the order differ between speechId_DataIndicator and the codecList), but
10245 * seems a good idea to see how osmo-bsc reacts to this. */
10246 ass_cmd.pdu.bssmap.assignmentRequest.channelType := {
10247 elementIdentifier := '0B'O, /* overwritten */
10248 lengthIndicator := 0, /* overwritten */
10249 speechOrDataIndicator := '0001'B, /* speech */
10250 spare1_4 := '0000'B,
10251 channelRateAndType := ChRate_TCHForH_Fpref,
10252 speechId_DataIndicator := 'c2918105'O
10253 };
10254 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({
10255 ts_CodecHR, ts_CodecAMR_WB, ts_CodecEFR, ts_CodecFR}));
10256
10257 f_rslem_dchan_queue_enable();
10258
10259 var ExpectCriteria mgcpcrit := {
10260 connid := omit,
10261 endpoint := omit,
10262 transid := omit
10263 };
10264 f_create_mgcp_expect(mgcpcrit);
10265
10266 BSSAP.send(ass_cmd);
10267
10268 var AssignmentState st := valueof(ts_AssignmentStateInit);
10269 st.voice_call := true;
10270 st.is_assignment := false;
10271 alt {
10272 [] as_modify(st);
10273 [] as_Media();
10274 [st.modify_done] BSSAP.receive(exp_compl) {
10275 setverdict(pass);
10276 }
10277 }
10278
10279 /* Voice call carries on ... */
10280 f_sleep(2.0);
10281
10282 setverdict(pass);
10283 f_perform_clear();
10284}
10285
10286testcase TC_emerg_call_and_lcs_loc_req() runs on test_CT {
10287 var MSC_ConnHdlr vc_conn;
10288 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10289
10290 f_init(1, true);
10291 f_sleep(1.0);
10292 f_vty_allow_emerg_msc(true);
10293 f_vty_allow_emerg_bts(true, 0);
10294 vc_conn := f_start_handler(refers(f_tc_emerg_call_and_lcs_loc_req), pars);
10295 vc_conn.done;
10296 f_shutdown_helper();
10297}
10298
Neels Hofmeyrbf037052020-10-28 22:52:02 +000010299/* Attempt Complete Layer 3 without any MSC available (OS#4832) */
10300private function f_tc_no_msc(charstring id) runs on MSC_ConnHdlr {
10301 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
10302
10303 /* Also disable attach for the single connected MSC */
10304 f_vty_msc_allow_attach(BSCVTY, { false });
10305
10306 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) ));
10307 f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
10308
10309 /* No MSC is found, expecting a proper release on RSL */
10310 interleave {
10311 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
10312 f_logp(BSCVTY, "Got RSL RR Release");
10313 }
10314 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
10315 f_logp(BSCVTY, "Got RSL Deact SACCH");
10316 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +020010317 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyrbf037052020-10-28 22:52:02 +000010318 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
10319 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +020010320 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyrbf037052020-10-28 22:52:02 +000010321 }
10322 }
10323 setverdict(pass);
10324}
10325testcase TC_no_msc() runs on test_CT {
10326
10327 f_init(1, true);
10328 f_sleep(1.0);
10329 var MSC_ConnHdlr vc_conn;
10330 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10331
10332 f_ctrs_bsc_init(counternames_bsc_mscpool);
10333
10334 vc_conn := f_start_handler(refers(f_tc_no_msc), pars);
10335 vc_conn.done;
10336
10337 f_ctrs_bsc_add("mscpool:subscr:no_msc");
10338 f_ctrs_bsc_verify();
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +010010339 f_shutdown_helper();
Neels Hofmeyrbf037052020-10-28 22:52:02 +000010340}
10341
Harald Welte0ea2d5e2018-04-07 21:40:29 +020010342/* Dyn PDCH todo:
10343 * activate OSMO as TCH/F
10344 * activate OSMO as TCH/H
10345 * does the BSC-located PCU socket get the updated INFO?
10346 * what if no PCU is connected at the time?
10347 * is the info correct on delayed PCU (re)connect?
10348 */
Harald Welte94e0c342018-04-07 11:33:23 +020010349
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000010350private function f_TC_refuse_mode_modif_to_vamos(charstring id) runs on MSC_ConnHdlr {
10351 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
10352 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
10353
10354 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
10355 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
10356 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
10357 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
10358 g_pars.ass_codec_list.codecElements[0];
10359 if (isvalue(g_pars.expect_mr_s0_s7)) {
10360 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
10361 g_pars.expect_mr_s0_s7;
10362 }
10363 }
10364 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
10365 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
10366 log("expecting ASS COMPL like this: ", exp_compl);
10367
10368 f_establish_fully(ass_cmd, exp_compl);
10369
Neels Hofmeyr8746b0d2021-06-01 17:25:39 +020010370 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 +000010371
10372 var RSL_Message rsl;
10373
10374 timer T := 5.0;
10375 T.start;
10376 alt {
10377 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
10378 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
10379 log("Rx L3 from net: ", l3);
10380 if (ischosen(l3.msgs.rrm.channelModeModify)) {
10381 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
10382 mtc.stop;
10383 }
10384 }
10385 [] RSL.receive(tr_RSL_MODE_MODIFY_REQ(g_chan_nr, ?)) -> value rsl {
10386 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
10387 mtc.stop;
10388 }
10389 [] T.timeout {
10390 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related Mode Modify should happen. */
10391 setverdict(pass);
10392 }
10393 }
10394 T.stop;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010395
10396 f_perform_clear();
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000010397}
10398
10399/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel Mode Modify to VAMOS mode is refused by
10400 * osmo-bsc. */
10401testcase TC_refuse_mode_modif_to_vamos() runs on test_CT {
10402 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10403 var MSC_ConnHdlr vc_conn;
10404
10405 f_init(1, true);
10406 f_sleep(1.0);
10407
10408 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10409 vc_conn := f_start_handler(refers(f_TC_refuse_mode_modif_to_vamos), pars);
10410 vc_conn.done;
10411 f_shutdown_helper();
10412}
10413
10414/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel activation to VAMOS mode is refused by osmo-bsc.
10415 */
10416testcase TC_refuse_chan_act_to_vamos() runs on test_CT {
10417 f_init_vty();
10418
10419 f_init(1, false);
10420 f_sleep(1.0);
10421
10422 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 activate-vamos fr");
10423
10424 var ASP_RSL_Unitdata rx_rsl_ud;
10425 timer T := 5.0;
10426
10427 T.start;
10428 alt {
10429 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(?, IPAC_PROTO_RSL_TRX0)) -> value rx_rsl_ud {
10430 if (rx_rsl_ud.rsl.msg_type == RSL_MT_CHAN_ACTIV) {
10431 T.stop;
10432 setverdict(fail, "CHANnel ACTivate in VAMOS mode succeeded even though BTS does not support VAMOS");
10433 mtc.stop;
10434 }
10435 repeat;
10436 }
10437 [] T.timeout {
10438 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related CHANnel ACTivate should happen. */
10439 setverdict(pass);
10440 }
10441 }
10442}
10443
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010444private function f_TC_reassignment_codec(charstring id) runs on MSC_ConnHdlr {
10445 /* First fully set up a speech lchan */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010446 f_assignment_codec(id, do_perform_clear := false);
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010447
10448 /* Trigger re-assignment to another lchan */
10449 var AssignmentState assignment_st := valueof(ts_AssignmentStateInit);
10450
10451 /* Re-Assignment should tell the MGW endpoint the new lchan's RTP address and port, so expecting to see exactly
10452 * one MDCX on MGCP. */
10453 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].mdcx_seen_exp + 1;
10454
10455 /* The new lchan will see all-new IPAC_CRCX and IPAC_MDCX messages telling the BTS the same RTP address and port
10456 * as the old lchan used. */
10457 g_media.bts.ipa_crcx_seen := false;
10458 g_media.bts.ipa_mdcx_seen := false;
10459
10460 /* Send different BTS side RTP port number for the new lchan */
10461 g_media.bts.bts.port_nr := 4223;
10462
10463 f_rslem_register(0, valueof(ts_RslChanNr_Bm(2))); /* <-- FIXME: can we somehow infer the timeslot that will be used? */
10464
10465 /* Trigger re-assignment. */
10466 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot " & int2str(g_chan_nr.tn) & " sub-slot 0 assignment");
10467
10468 timer T := 5.0;
10469 T.start;
10470 alt {
10471 [] as_assignment(assignment_st);
10472 [] as_Media();
10473 [] T.timeout {
10474 break;
10475 }
10476 }
10477
10478 if (not assignment_st.assignment_done) {
10479 setverdict(fail, "Assignment did not complete");
10480 mtc.stop;
10481 }
10482
10483 f_check_mgcp_expectations()
10484 setverdict(pass);
10485
10486 f_sleep(2.0);
10487 log("show lchan summary: ", f_vty_transceive_ret(BSCVTY, "show lchan summary"));
10488
10489 /* Instruct BSC to clear channel */
10490 var BssmapCause cause := 0;
10491 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
10492 interleave {
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010493 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {}
10494 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +020010495 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010496 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +020010497 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010498 }
10499 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
10500 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
10501 }
10502 }
Neels Hofmeyr40a45d12021-09-23 22:57:12 +020010503 f_expect_dlcx_conns();
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010504
10505 f_sleep(0.5);
10506}
10507
10508testcase TC_reassignment_fr() runs on test_CT {
10509 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10510 var MSC_ConnHdlr vc_conn;
10511
10512 f_init(1, true);
10513 f_sleep(1.0);
10514
Neels Hofmeyrac432fa2021-11-02 16:45:56 +010010515 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010516
10517 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10518 vc_conn := f_start_handler(refers(f_TC_reassignment_codec), pars);
10519 vc_conn.done;
10520
10521 /* from f_establish_fully() */
10522 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
10523 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
10524 /* from re-assignment */
10525 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
10526 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
10527 f_ctrs_bsc_and_bts_verify();
10528 f_shutdown_helper();
10529}
10530
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010531const charstring REEST_LOST_CONNECTION := "REEST_LOST_CONNECTION";
10532const charstring REEST_CLEAR := "REEST_CLEAR";
10533const charstring REEST_CLEAR_DONE := "REEST_CLEAR_DONE";
10534
10535/* CM Re-Establishment, 3GPP TS 24.008 4.5.1.6.
10536 * The MS <-> BTS loses radio connection, MS shows up on second BTS and asks for CM Re-Establishment.
10537 * BSC should establish a separate A conn for the same MS, the original A conn is then cleared by
10538 * the MSC as the CM Re-Establishment is handled.
10539 *
10540 * MS bts0 bts1 bsc msc test-component
10541 * |<----->|<----------------->|<-0-->| _1 Establish channel on bts 0
10542 * | | _1 wait a bit, to settle down
10543 * |<-x x--| | _1 "lose connection"
10544 * | | REEST_LOST_CONNECTION
10545 * |----------------->|------->|--1-->| _2 new A-conn: Chan Rqd, Imm Ass, Compl L3 with CM Re-Establishment Req
10546 * | | REEST_CLEAR
10547 * | |<-0---| _1 Clear Command on first A-conn
10548 * | |--0-->| _1 Clear Complete
10549 * | |<----------------->| | _1 Release first channel
10550 * | | REEST_CLEAR_DONE
10551 * |<-----------------|<-------|<-1---| _2 Chan Activ, Assignment Command
10552 * |<-----------------|<-------|<-1---| _2 Clear Command, Release
10553 *
10554 */
10555private function f_tc_cm_reestablishment_1(charstring id) runs on MSC_ConnHdlr {
10556 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
10557 var PDU_BSSAP ass_cmd := f_gen_ass_req();
10558
10559 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10560 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10561
10562 f_establish_fully(ass_cmd, exp_compl);
10563
10564 /* The original channel loses connection, MS attemts CM Re-Establishment on another cell, see
10565 * f_tc_cm_reestablishment_2(). This established channel stays active until MSC sends a Clear Command. The time
10566 * when exactly that happens is determined by f_tc_cm_reestablishment_2(). */
10567 f_sleep(2.0);
10568 COORD.send(REEST_LOST_CONNECTION);
10569
10570 alt {
10571 [] COORD.receive(REEST_CLEAR);
10572 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
10573 setverdict(fail, "Unexpected channel release");
10574 mtc.stop;
10575 }
10576 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
10577 setverdict(fail, "Unexpected channel release");
10578 mtc.stop;
10579 }
10580 }
10581 f_perform_clear()
Neels Hofmeyr969abd02021-09-23 22:24:08 +020010582 f_create_mgcp_delete_ep(g_media.mgcp_ep);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010583 COORD.send(REEST_CLEAR_DONE);
10584}
10585
10586private function f_tc_cm_reestablishment_2(charstring id) runs on MSC_ConnHdlr {
10587 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
10588
10589 /* The MS lost the connection on the first channel, now establishes another one */
10590 COORD.receive(REEST_LOST_CONNECTION);
10591
10592 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
10593 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_REESTABL_REQ(mi));
10594 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
10595
10596 f_create_bssmap_exp(l3_enc);
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010597 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 +020010598 BSSAP.receive(tr_BSSMAP_ComplL3(l3_enc));
10599
10600 /* MSC got the CM Re-Establishment request and first off clears the previous conn. */
10601 COORD.send(REEST_CLEAR);
10602 COORD.receive(REEST_CLEAR_DONE);
10603
10604 f_sleep(2.0);
10605
10606 /* Answer the CM Re-Establishment with an Assignment Command. */
10607 var template PDU_BSSAP expect_assignment_compl := f_gen_exp_compl();
10608 var PDU_BSSAP ass_cmd := f_gen_ass_req();
10609 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10610 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10611
10612 var AssignmentState st := valueof(ts_AssignmentStateInit);
10613 st.voice_call := true;
10614 st.is_assignment := true;
10615
10616 var ExpectCriteria mgcpcrit := {
10617 connid := omit,
10618 endpoint := omit,
10619 transid := omit
10620 };
10621 f_create_mgcp_expect(mgcpcrit);
10622
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010623 f_rslem_dchan_queue_enable(RSL1_PROC);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010624
10625 BSSAP.send(ass_cmd);
10626
10627 var PDU_BSSAP bssap;
10628
10629 alt {
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010630 [] as_assignment(st, rsl_pt := RSL1, rsl_proc_pt := RSL1_PROC);
10631 [] as_Media_ipacc(RSL1, RSL2);
10632 [] as_Media_mgw();
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010633 [st.assignment_done] BSSAP.receive(expect_assignment_compl) {
10634 break;
10635 }
10636 }
10637
10638 f_sleep(3.0);
10639
10640 f_logp(BSCVTY, "f_tc_cm_reestablishment_2 clearing");
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010641 f_perform_clear(RSL1, RSL1_PROC);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010642}
10643
10644testcase TC_cm_reestablishment() runs on test_CT {
10645 var TestHdlrParams pars1 := f_gen_test_hdlr_pars();
10646 var MSC_ConnHdlr vc_conn1;
10647
10648 var TestHdlrParams pars2 := f_gen_test_hdlr_pars();
10649 var MSC_ConnHdlr vc_conn2;
10650 pars2.imsi := pars1.imsi;
10651 pars2.media_nr := 2;
Neels Hofmeyrbf720202021-10-02 12:58:24 +020010652 pars2.expect_tsc := BTS_TSC[1];
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010653
10654 f_init(2, true, guard_timeout := 40.0);
10655 f_sleep(1.0);
10656
10657 vc_conn1 := f_start_handler_create(pars1);
10658 vc_conn2 := f_start_handler_create(pars2);
10659 connect(vc_conn1:COORD, vc_conn2:COORD);
10660 f_start_handler_run(vc_conn1, refers(f_tc_cm_reestablishment_1), pars1);
10661 f_start_handler_run(vc_conn2, refers(f_tc_cm_reestablishment_2), pars2);
10662 vc_conn1.done;
10663 vc_conn2.done;
10664
10665 f_shutdown_helper();
10666}
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000010667
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010668function f_exp_ipa_rx_nonfatal(integer bts_nr, template (present) RSL_Message t_rx, float t_secs := 2.0,
10669 IpaStreamId sid := IPAC_PROTO_RSL_TRX0, boolean ignore_other_rx := true)
10670runs on test_CT return template (omit) RSL_Message {
10671 var ASP_RSL_Unitdata rx_rsl_ud;
10672 timer T := t_secs;
10673
10674 T.start;
10675 alt {
10676 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
10677 T.stop;
10678 }
10679 [ignore_other_rx] IPA_RSL[bts_nr].receive { repeat; }
10680 [not ignore_other_rx] IPA_RSL[bts_nr].receive {
10681 log("f_exp_ipa_rx_nonfatal(): Got different message than ", t_rx);
10682 T.stop;
10683 return omit;
10684 }
10685 [] T.timeout {
10686 return omit;
10687 }
10688 }
10689 return rx_rsl_ud.rsl;
10690}
10691
10692private function f_vty_set_imm_ass(TELNETasp_PT pt, BtsNr bts_nr := 0, charstring imm_ass_setting := "post-chan-ack") {
10693 f_vty_enter_cfg_bts(pt, bts_nr);
10694 f_vty_transceive(pt, "immediate-assignment " & imm_ass_setting);
10695 f_vty_transceive(pt, "exit");
10696 f_vty_transceive(pt, "exit");
10697 f_vty_transceive(pt, "exit");
10698}
10699
10700private function f_verify_imm_ass(RSL_Message imm_ass, template uint8_t ra := ?, template GsmFrameNumber fn := ?,
Vadim Yanitskiy35c9a332022-03-16 20:26:35 +030010701 template (present) RslChannelNr chan_nr := ?,
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010702 template (present) uint12_t arfcn := ?,
10703 template (present) uint3_t tsc := ?)
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010704{
10705 var RSL_IE_Body full_imm_ass_info;
10706 if (not f_rsl_find_ie(imm_ass, RSL_IE_FULL_IMM_ASS_INFO, full_imm_ass_info)) {
10707 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
10708 mtc.stop;
10709 }
10710
10711 var GsmRrMessage rr_imm_ass := dec_GsmRrMessage(full_imm_ass_info.full_imm_ass_info.payload);
10712 var template GsmRrMessage expect_imm_ass := tr_IMM_ASS(ra := ra,
10713 fn := fn,
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010714 ch_desc := tr_ChanDescH0(chan_nr, arfcn, tsc),
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010715 page_mode := ?);
10716 if (not match(rr_imm_ass, expect_imm_ass)) {
10717 log("Error: expected ", expect_imm_ass, " got ", rr_imm_ass);
10718 setverdict(fail, "Failed to match Immediate Assignment");
10719 mtc.stop;
10720 }
10721}
10722
10723testcase TC_imm_ass_post_chan_ack() runs on test_CT {
10724 var RSL_Message chan_act;
10725 var RSL_Message imm_ass;
10726
10727 f_init(1, false);
10728 f_sleep(1.0);
10729
10730 /* (should be the default anyway, just to make things clear) */
10731 f_vty_set_imm_ass(BSCVTY, 0, "post-chan-ack");
10732
10733 /* RA containing reason=LU */
10734 var GsmFrameNumber fn := 2342;
10735 var uint8_t ra := 2;
10736 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10737
10738 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10739
10740 /* First send the Chan Act ACK */
10741 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010742 var DchanTuple dt;
10743 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010744 var RSL_IE_Body chan_ident_ie;
10745 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10746 setverdict(fail, "RSL Channel Identification IE is absent");
10747 mtc.stop;
10748 }
10749
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010750 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn + 10));
10751
10752 /* Then expect the Immediate Assignment, after we ACKed the chan act */
10753 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10754
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010755 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10756 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010757
10758 /* Check that the lchan is working */
10759 var octetstring l3 := '00010203040506'O;
10760 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10761
10762 var BSSAP_N_CONNECT_ind rx_c_ind;
10763 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010764 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010765 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10766
10767 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010768 f_perform_clear_test_ct(dt);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010769 f_shutdown_helper();
10770}
10771
10772testcase TC_imm_ass_pre_chan_ack() runs on test_CT {
10773 var RSL_Message chan_act;
10774 var RSL_Message imm_ass;
10775
10776 f_init(1, false);
10777 f_sleep(1.0);
10778
10779 f_vty_set_imm_ass(BSCVTY, 0, "pre-chan-ack");
10780
10781 /* RA containing reason=LU */
10782 var GsmFrameNumber fn := 2342;
10783 var uint8_t ra := 2;
10784 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10785
10786 /* (set bts 0 cfg back to default) */
10787 f_vty_set_imm_ass(BSCVTY);
10788
10789 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10790 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010791 var DchanTuple dt;
10792 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010793 var RSL_IE_Body chan_ident_ie;
10794 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10795 setverdict(fail, "RSL Channel Identification IE is absent");
10796 mtc.stop;
10797 }
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010798
10799 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10800 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010801 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10802 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010803
10804 /* Only now send the Chan Act ACK */
10805 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10806
10807 /* Check that the lchan is working */
10808 var octetstring l3 := '00010203040506'O;
10809 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10810
10811 var BSSAP_N_CONNECT_ind rx_c_ind;
10812 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010813 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010814 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10815
10816 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010817 f_perform_clear_test_ct(dt);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010818 f_shutdown_helper();
10819}
10820
Neels Hofmeyr23158742021-09-07 19:08:07 +020010821testcase TC_imm_ass_pre_ts_ack() runs on test_CT {
10822 var RSL_Message chan_act;
10823 var RSL_Message imm_ass;
10824
10825 f_init(1, false);
10826 f_sleep(1.0);
10827
10828 f_vty_set_imm_ass(BSCVTY, 0, "pre-ts-ack");
10829
10830 /* RA containing reason=LU */
10831 var GsmFrameNumber fn := 2342;
10832 var uint8_t ra := 2;
10833 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10834
10835 /* (set bts 0 cfg back to default) */
10836 f_vty_set_imm_ass(BSCVTY);
10837
10838 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10839 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010840 var DchanTuple dt;
10841 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyr23158742021-09-07 19:08:07 +020010842 var RSL_IE_Body chan_ident_ie;
10843 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10844 setverdict(fail, "RSL Channel Identification IE is absent");
10845 mtc.stop;
10846 }
10847
10848 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10849 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10850 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10851 chan_ident_ie.chan_ident.ch_desc.v.tsc);
10852
10853 /* Only now send the Chan Act ACK */
10854 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10855
10856 /* Check that the lchan is working */
10857 var octetstring l3 := '00010203040506'O;
10858 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10859
10860 var BSSAP_N_CONNECT_ind rx_c_ind;
10861 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010862 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyr23158742021-09-07 19:08:07 +020010863 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10864
10865 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010866 f_perform_clear_test_ct(dt);
Neels Hofmeyr23158742021-09-07 19:08:07 +020010867 f_shutdown_helper();
10868}
10869
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010870testcase TC_imm_ass_pre_chan_ack_dyn_ts() runs on test_CT {
10871 /* change Timeslot 6 before f_init() starts RSL */
10872 f_init_vty();
10873 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
10874 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10875
10876 f_init(1, false);
10877 f_sleep(1.0);
10878
10879 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
10880 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010881 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010882 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2323));
10883
10884 /* clean up timeslot 6 config, will only take effect when the OML drops the next time */
10885 f_ts_set_chcomb(0, 0, 6, "PDCH");
10886
10887 /* block all static timeslots so that the dyn TS will be used */
10888 f_disable_all_tch_f();
10889 f_disable_all_tch_h();
10890 f_disable_all_sdcch();
10891
10892 var RSL_Message chan_act;
10893 var RSL_Message imm_ass;
10894
10895 f_init(1, false);
10896 f_sleep(1.0);
10897
10898 f_vty_set_imm_ass(BSCVTY, 0, "pre-chan-ack");
10899
10900 /* RA containing reason=LU */
10901 var GsmFrameNumber fn := 2342;
10902 var uint8_t ra := 2;
10903 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10904
10905 /* (set bts 0 cfg back to default) */
10906 f_vty_set_imm_ass(BSCVTY);
10907
10908 /* Expect the dyn TS to deactivate PDCH first */
10909 f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
10910 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
10911
10912 /* Now activation as SDCCH8 */
10913 chan_nr := valueof(t_RslChanNr_SDCCH8(tn := 6, sub_slot := 0));
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010914 var DchanTuple dt;
10915 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010916
10917 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010918 var RSL_IE_Body chan_ident_ie;
10919 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10920 setverdict(fail, "RSL Channel Identification IE is absent");
10921 mtc.stop;
10922 }
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010923
10924 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10925 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010926 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10927 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010928
10929 /* Only now send the Chan Act ACK */
10930 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10931
10932 /* Check that the lchan is working */
10933 var octetstring l3 := '00010203040506'O;
10934 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10935
10936 var BSSAP_N_CONNECT_ind rx_c_ind;
10937 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010938 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010939 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10940
10941 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010942 f_perform_clear_test_ct(dt);
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010943 f_shutdown_helper();
10944}
10945
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010946testcase TC_imm_ass_pre_ts_ack_dyn_ts() runs on test_CT {
10947 /* change Timeslot 6 before f_init() starts RSL */
10948 f_init_vty();
10949 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
10950 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10951
10952 f_init(1, false);
10953 f_sleep(1.0);
10954
10955 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
10956 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010957 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010958 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2323));
10959
10960 /* clean up timeslot 6 config, will only take effect when the OML drops the next time */
10961 f_ts_set_chcomb(0, 0, 6, "PDCH");
10962
10963 /* block all static timeslots so that the dyn TS will be used */
10964 f_disable_all_tch_f();
10965 f_disable_all_tch_h();
10966 f_disable_all_sdcch();
10967
10968 var RSL_Message chan_act;
10969 var RSL_Message imm_ass;
10970
10971 f_init(1, false);
10972 f_sleep(1.0);
10973
10974 f_vty_set_imm_ass(BSCVTY, 0, "pre-ts-ack");
10975
10976 /* RA containing reason=LU */
10977 var GsmFrameNumber fn := 2342;
10978 var uint8_t ra := 2;
10979 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10980
10981 /* (set bts 0 cfg back to default) */
10982 f_vty_set_imm_ass(BSCVTY);
10983
10984 /* Expect the dyn TS to deactivate PDCH first */
10985 f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
10986
10987 /* And already the Immediate Assignment even before the PDCH Deact ACK */
10988 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10989
10990 /* continue the Osmo style PDCH Deact (usual chan rel) */
10991 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
10992
10993 /* Now activation as SDCCH8 */
10994 chan_nr := valueof(t_RslChanNr_SDCCH8(tn := 6, sub_slot := 0));
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010995 var DchanTuple dt;
10996 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010997
10998 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010999 var RSL_IE_Body chan_ident_ie;
11000 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
11001 setverdict(fail, "RSL Channel Identification IE is absent");
11002 mtc.stop;
11003 }
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020011004 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
11005
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020011006 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
11007 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020011008
11009 /* Check that the lchan is working */
11010 var octetstring l3 := '00010203040506'O;
11011 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
11012
11013 var BSSAP_N_CONNECT_ind rx_c_ind;
11014 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011015 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020011016 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
11017
11018 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011019 f_perform_clear_test_ct(dt);
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020011020 f_shutdown_helper();
11021}
11022
Neels Hofmeyr5d7d13f2021-09-07 14:44:36 +020011023/* GET and SET the bts.N.trx.M.rf_locked CTRL variable */
11024testcase TC_ctrl_trx_rf_locked() runs on test_CT {
11025 var MSC_ConnHdlr vc_conn;
11026
11027 f_init(nr_bts := 2, handler_mode := true, nr_msc := 1);
11028 f_sleep(1.0);
11029
11030 /* BTS 0, 1, 2 are OML unlocked, only BTS 0, 1 are actually connected to RSL. */
11031 f_ctrl_get_exp(IPA_CTRL, "rf_states",
11032 "0,0,operational,unlocked,on,rsl-up;" &
11033 "1,0,operational,unlocked,on,rsl-up;" &
11034 "2,0,operational,unlocked,on,rsl-down;" &
11035 "3,0,inoperational,locked,on,rsl-down;");
11036
11037 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: lock BTS 1 TRX 0");
11038 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "1");
11039 /* give it a moment to settle the FSM status */
11040 f_sleep(1.0);
11041
11042 /* Now BTS 1 TRX 0 should reflect "locked". Note the RF policy stays "on", because this is still handled
11043 * globally in osmo-bsc. Probably after sending "rf_locked 1" for a TRX, that TRX should reflect an RF policy
11044 * of "off"? But that's for a future patch if at all. */
11045 f_ctrl_get_exp(IPA_CTRL, "rf_states",
11046 "0,0,operational,unlocked,on,rsl-up;" &
11047 "1,0,operational,locked,on,rsl-up;" &
11048 "2,0,operational,unlocked,on,rsl-down;" &
11049 "3,0,inoperational,locked,on,rsl-down;");
11050
11051 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: lock the already locked TRX, nothing should change");
11052 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "1");
11053 f_sleep(1.0);
11054 f_ctrl_get_exp(IPA_CTRL, "rf_states",
11055 "0,0,operational,unlocked,on,rsl-up;" &
11056 "1,0,operational,locked,on,rsl-up;" &
11057 "2,0,operational,unlocked,on,rsl-down;" &
11058 "3,0,inoperational,locked,on,rsl-down;");
11059
11060 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock BTS 1 TRX 0");
11061 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "0");
11062 f_sleep(1.0);
11063 f_ctrl_get_exp(IPA_CTRL, "rf_states",
11064 "0,0,operational,unlocked,on,rsl-up;" &
11065 "1,0,operational,unlocked,on,rsl-up;" &
11066 "2,0,operational,unlocked,on,rsl-down;" &
11067 "3,0,inoperational,locked,on,rsl-down;");
11068
11069 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock an already unlocked TRX, nothing should change");
11070 f_ctrl_set(IPA_CTRL, "bts.0.trx.0.rf_locked", "0");
11071 f_sleep(1.0);
11072 f_ctrl_get_exp(IPA_CTRL, "rf_states",
11073 "0,0,operational,unlocked,on,rsl-up;" &
11074 "1,0,operational,unlocked,on,rsl-up;" &
11075 "2,0,operational,unlocked,on,rsl-down;" &
11076 "3,0,inoperational,locked,on,rsl-down;");
11077
11078 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock an inoperational TRX");
11079 f_ctrl_set(IPA_CTRL, "bts.3.trx.0.rf_locked", "0");
11080 f_sleep(1.0);
11081 f_ctrl_get_exp(IPA_CTRL, "rf_states",
11082 "0,0,operational,unlocked,on,rsl-up;" &
11083 "1,0,operational,unlocked,on,rsl-up;" &
11084 "2,0,operational,unlocked,on,rsl-down;" &
11085 "3,0,inoperational,locked,on,rsl-down;");
11086
11087 f_shutdown_helper();
11088}
11089
Neels Hofmeyrb7581872021-11-07 14:02:49 +010011090const CounterNameVals counternames_cm_serv_rej := {
11091 { "cm_serv_rej", 0 },
11092 { "cm_serv_rej:imsi_unknown_in_hlr", 0 },
11093 { "cm_serv_rej:illegal_ms", 0 },
11094 { "cm_serv_rej:imsi_unknown_in_vlr", 0 },
11095 { "cm_serv_rej:imei_not_accepted", 0 },
11096 { "cm_serv_rej:illegal_me", 0 },
11097 { "cm_serv_rej:plmn_not_allowed", 0 },
11098 { "cm_serv_rej:loc_not_allowed", 0 },
11099 { "cm_serv_rej:roaming_not_allowed", 0 },
11100 { "cm_serv_rej:network_failure", 0 },
11101 { "cm_serv_rej:synch_failure", 0 },
11102 { "cm_serv_rej:congestion", 0 },
11103 { "cm_serv_rej:srv_opt_not_supported", 0 },
11104 { "cm_serv_rej:rqd_srv_opt_not_supported", 0 },
11105 { "cm_serv_rej:srv_opt_tmp_out_of_order", 0 },
11106 { "cm_serv_rej:call_can_not_be_identified", 0 },
11107 { "cm_serv_rej:incorrect_message", 0 },
11108 { "cm_serv_rej:invalid_mandantory_inf", 0 },
11109 { "cm_serv_rej:msg_type_not_implemented", 0 },
11110 { "cm_serv_rej:msg_type_not_compatible", 0 },
11111 { "cm_serv_rej:inf_eleme_not_implemented", 0 },
11112 { "cm_serv_rej:condtional_ie_error", 0 },
11113 { "cm_serv_rej:msg_not_compatible", 0 },
11114 { "cm_serv_rej:protocol_error", 0 },
11115 { "cm_serv_rej:retry_in_new_cell", 0 }
11116};
11117
11118private function f_TC_cm_serv_rej(charstring id) runs on MSC_ConnHdlr
11119{
11120 f_create_chan_and_exp();
Vadim Yanitskiya7fc5a62021-12-04 20:10:08 +030011121 /* we should now have a COMPL_L3 at the MSC */
Neels Hofmeyrb7581872021-11-07 14:02:49 +010011122 BSSAP.send(ts_PDU_DTAP_MT(ts_CM_SERV_REJ('02'O), '00'O));
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011123 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_CM_SERV_REJ));
11124 f_perform_clear();
Neels Hofmeyr87a65612021-11-16 15:56:45 +010011125 f_sleep(1.0);
Neels Hofmeyrb7581872021-11-07 14:02:49 +010011126}
11127testcase TC_cm_serv_rej() runs on test_CT {
11128 var TestHdlrParams pars := f_gen_test_hdlr_pars();
11129 var MSC_ConnHdlr vc_conn;
11130
11131 f_init(1, true);
11132 f_sleep(1.0);
11133
11134 f_ctrs_bts_init(1, counternames_cm_serv_rej);
11135
11136 vc_conn := f_start_handler(refers(f_TC_cm_serv_rej), pars);
11137 vc_conn.done;
11138
11139 f_ctrs_bts_add(0, "cm_serv_rej", 1);
11140 f_ctrs_bts_add(0, "cm_serv_rej:imsi_unknown_in_hlr", 1);
11141 f_ctrs_bts_verify();
11142
Neels Hofmeyr87a65612021-11-16 15:56:45 +010011143 f_sleep(1.0);
Neels Hofmeyrb7581872021-11-07 14:02:49 +010011144 f_shutdown_helper();
11145}
11146
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011147/* Reproduce a segfault happening when the SDCCH (primary) lchan is lost in-between a TCH Channel Activ and its Channel
11148 * Activ Ack (SYS#5627). */
11149private function f_TC_lost_sdcch_during_assignment(charstring id) runs on MSC_ConnHdlr {
11150 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Vadim Yanitskiyf0310e32021-10-26 00:30:59 +030011151
11152 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
11153 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011154
11155 var BSSMAP_FIELD_CodecType codecType;
11156 codecType := valueof(ass_cmd.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType);
11157
11158 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
11159
11160 /* First establish a signalling lchan */
11161 f_create_chan_and_exp();
11162 f_rslem_dchan_queue_enable();
11163
11164 /* we should now have a COMPL_L3 at the MSC */
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011165
11166 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
11167 activate(as_Media_mgw());
11168
11169 var RslChannelNr chan_nr := { u := { ch0 := RSL_CHAN_NR_Bm_ACCH }, tn := 1 };
11170 f_rslem_register(0, chan_nr);
11171
11172 f_rslem_set_auto_chan_act_ack(RSL_PROC, false);
11173 BSSAP.send(ass_cmd);
11174
11175
11176 /* Wait for the Channel Activ for the TCH channel */
11177 var ASP_RSL_Unitdata rx_rsl_ud;
11178 RSL.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV), sid := ?)) -> value rx_rsl_ud;
11179
11180 /* make the original SDCCH disappear */
11181 RSL.send(ts_RSL_REL_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
11182
11183 /* and ACK the TCH channel activation. This caused a segfault up to OsmoBSC 1.7.0 (SYS#5627) */
11184 RSL.send(ts_ASP_RSL_UD(ts_RSL_CHAN_ACT_ACK(chan_nr, 23), rx_rsl_ud.streamId));
11185
11186 interleave {
11187 [] BSSAP.receive(tr_BSSMAP_AssignmentFail);
11188 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
11189 }
11190
11191 BSSAP.send(ts_BSSMAP_ClearCommand(0));
11192 BSSAP.receive(tr_BSSMAP_ClearComplete);
11193 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
11194
11195 var MgcpCommand mgcp;
11196 MGCP.receive(tr_DLCX()) -> value mgcp {
11197 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
11198 };
11199
11200 f_sleep(0.5);
11201}
11202testcase TC_lost_sdcch_during_assignment() runs on test_CT {
11203 var TestHdlrParams pars := f_gen_test_hdlr_pars();
11204 var MSC_ConnHdlr vc_conn;
11205
11206 f_init(1, true);
11207 f_sleep(1.0);
11208
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011209 vc_conn := f_start_handler(refers(f_TC_lost_sdcch_during_assignment), pars);
11210 vc_conn.done;
11211
11212 f_shutdown_helper();
11213}
11214
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011215const CounterNameVals counternames_bsc_bts_all_available_allocated := {
11216 { "all_allocated:sdcch", 0 },
11217 { "all_allocated:static_sdcch", 0 },
11218 { "all_allocated:tch", 0 },
11219 { "all_allocated:static_tch", 0 }
11220}
11221
11222private function f_all_allocated_expect_counter_change(charstring_list expect_changed) runs on test_CT
11223{
11224 /* Make sure counters settle first */
11225 f_sleep(1.0);
11226
11227 /* Take a baseline of counters */
11228 f_ctrs_bsc_and_bts_init(1, counternames_bsc_bts_all_available_allocated);
11229
11230 /* Elapse some time so that we see changes in counters, hopefully where expected */
11231 f_sleep(2.0);
11232
11233 /* Get new counters */
11234 var charstring_list all_changed := {};
11235 all_changed := all_changed & f_counter_name_vals_get_changed_n(IPA_CTRL, "bsc", g_ctr_bsc);
11236 all_changed := all_changed & f_counter_name_vals_get_changed_n(IPA_CTRL, "bts", g_ctr_bts);
11237
11238 /* Compare with expectations */
11239 var charstring_list all_expect_changed := {};
11240 for (var integer i := 0; i < lengthof(expect_changed); i := i + 1) {
11241 all_expect_changed := all_expect_changed & { "bsc.0." & expect_changed[i], "bts.0." & expect_changed[i] };
11242 }
11243 f_counter_name_vals_expect_changed_list(all_changed, all_expect_changed);
11244}
11245
11246testcase TC_ratectr_all_available_allocated() runs on test_CT {
11247 var ASP_RSL_Unitdata rsl_ud;
11248 var integer i;
11249 var integer chreq_total, chreq_nochan;
11250
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011251 f_init(1, guard_timeout := 60.0);
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011252 f_sleep(1.0);
11253
11254 /* Exhaust all dedicated SDCCH lchans.
11255 /* GSM 44.018 Table 9.1.8.2:
11256 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
11257 */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011258 var DchanTuples chan_cleanup := {};
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011259 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011260 chan_cleanup := chan_cleanup & { f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011261 }
11262
11263 /* Since only bts 0 is connected, expecting all_allocated to become true for both bts 0 and the "global" bsc
11264 * level.
11265 * All SDCCH are now occupied. */
11266 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch"});
11267
11268 /* Also fill up all remaining (TCH) channels */
11269 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011270 chan_cleanup := chan_cleanup & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011271 }
11272
11273 /* All TCH are now also occupied */
11274 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch",
11275 "all_allocated:tch", "all_allocated:static_tch"});
11276
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011277 /* Clean up SDCCH lchans */
11278 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
11279 f_perform_clear_test_ct(chan_cleanup[i]);
11280 }
11281
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011282 f_shutdown_helper();
11283}
11284
11285testcase TC_ratectr_all_available_allocated_dyn() runs on test_CT {
11286 var ASP_RSL_Unitdata rsl_ud;
11287 var integer i;
11288 var integer chreq_total, chreq_nochan;
11289
11290 f_init_vty();
11291 f_ts_set_chcomb(0, 0, 2, "TCH/F_TCH/H_PDCH");
11292 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
11293 /* Now we have 3 TCH/F, 1 OSMO_DYN, 1 TCH/H */
11294
11295 f_init(1, guard_timeout := 60.0);
11296 f_sleep(1.0);
11297
11298 /* The dyn TS wants to activate PDCH mode, ACK that. */
11299 var RslChannelNr chan_nr;
11300 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060011301 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011302 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
11303
11304 /* Exhaust all dedicated SDCCH lchans.
11305 /* GSM 44.018 Table 9.1.8.2:
11306 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
11307 */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011308 var DchanTuples chan_cleanup := {};
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011309 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011310 chan_cleanup := chan_cleanup & { f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011311 }
11312
11313 /* The static SDCCH should now be occupied, while still 3x8 dynamic SDCCH potentially remain. So only
11314 * all_allocated:static_sdcch is counted, all_allocated:sdcch remains zero. */
11315 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch"});
11316
11317 /* Request more SDCCH, hence convert the first dyn TS to SDCCH8.
11318 * Will release them later, so remember all the DchanTuples. */
11319 var DchanTuples dyn_sddch := {};
11320 dyn_sddch := dyn_sddch & { f_est_dchan_dyn('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
11321
11322 /* Also occupy the seven other SDCCH of the dyn TS */
11323 for (i := 0; i < 7; i := i+1) {
11324 dyn_sddch := dyn_sddch & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
11325 }
11326
11327 /* Now all dynamic SDCCH are also occupied, so for the first time all_allocated:sdcch will trigger... */
11328 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch"});
11329
11330 /* occupy the remaining TCH, three TCH/F and two TCH/H lchans */
11331 for (i := 0; i < 5; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011332 chan_cleanup := chan_cleanup & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011333 }
11334
11335 /* All TCH lchans are now also occupied, both static and dynamic */
11336 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch",
11337 "all_allocated:tch", "all_allocated:static_tch"});
11338
11339 /* Starting to release the dyn TS: as soon as the first SDCCH gets released, all_allocated:sdcch stops
11340 * incrementing. */
11341 var BssmapCause cause := 0;
11342 var DchanTuple dt := dyn_sddch[0];
11343 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
11344 f_exp_chan_rel_and_clear(dt, 0);
11345
11346 /* one dyn TS SDCCH is free again, so only the static_sdcch should increment. For tch, both static and dynamic
11347 * count as occupied, so those still both increment. */
11348 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch",
11349 "all_allocated:tch", "all_allocated:static_tch"});
11350
11351 /* Release the remaining SDCCH of the dyn TS, so it becomes available as TCH again */
11352 for (i := 1; i < lengthof(dyn_sddch); i := i+1) {
11353 dt := dyn_sddch[i];
11354 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
11355 f_exp_chan_rel_and_clear(dt, 0);
11356 }
11357
11358 /* All SDCCH on the dyn TS are released, the dyn TS wants to activate PDCH again */
11359 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060011360 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011361 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
11362
11363 /* Now all channels are occupied except the dyn TS, so expecting only the static counters to increment */
11364 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch", "all_allocated:static_tch"});
11365
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011366 /* Clean up SDCCH lchans */
11367 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
11368 f_perform_clear_test_ct(chan_cleanup[i]);
11369 }
11370
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011371 /* clean up config */
11372 f_ts_reset_chcomb(0);
11373
11374 f_shutdown_helper();
11375}
11376
Harald Welte28d943e2017-11-25 15:00:50 +010011377control {
Harald Welte898113b2018-01-31 18:32:21 +010011378 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +010011379 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +010011380 execute( TC_ctrl_msc0_connection_status() );
Neels Hofmeyrf65ce872021-09-23 18:40:10 +020011381 /* In SCCPlite tests, only one MSC is configured. These tests assume that three MSCs are configured, so only run
11382 * these in the AoIP test suite. */
11383 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11384 execute( TC_stat_num_msc_connected_1() );
11385 execute( TC_stat_num_msc_connected_2() );
11386 execute( TC_stat_num_msc_connected_3() );
11387 }
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +020011388 execute( TC_stat_num_bts_connected_1() );
11389 execute( TC_stat_num_bts_connected_2() );
11390 execute( TC_stat_num_bts_connected_3() );
Harald Welte96c94412017-12-09 03:12:45 +010011391 execute( TC_ctrl() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +020011392 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER) {
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +020011393 execute( TC_ctrl_location() );
11394 }
Harald Welte898113b2018-01-31 18:32:21 +010011395
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020011396 execute( TC_si_default() );
Neels Hofmeyr66aeba42020-07-06 02:21:21 +020011397 execute( TC_si2quater_2_earfcns() );
11398 execute( TC_si2quater_3_earfcns() );
11399 execute( TC_si2quater_4_earfcns() );
11400 execute( TC_si2quater_5_earfcns() );
11401 execute( TC_si2quater_6_earfcns() );
Neels Hofmeyrad132f22020-07-08 02:20:16 +020011402 execute( TC_si2quater_12_earfcns() );
11403 execute( TC_si2quater_23_earfcns() );
11404 execute( TC_si2quater_32_earfcns() );
11405 execute( TC_si2quater_33_earfcns() );
11406 execute( TC_si2quater_42_earfcns() );
11407 execute( TC_si2quater_48_earfcns() );
11408 execute( TC_si2quater_49_earfcns() );
Pau Espin Pedrol85a84432020-07-20 18:45:03 +020011409 execute( TC_si_acc_rotate() );
Alexander Couzens4ad3a352020-09-10 22:29:12 +020011410 execute( TC_si_acc_ramp_rotate() );
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020011411
Harald Welte898113b2018-01-31 18:32:21 +010011412 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +010011413 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +010011414 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +010011415 execute( TC_chan_act_ack_noest() );
Philipp Maier9c60a622020-07-09 15:08:46 +020011416 execute( TC_chan_act_ack_noest_emerg() );
Philipp Maier606f07d2020-08-12 17:21:58 +020011417 execute( TC_chan_rqd_emerg_deny() );
Harald Welteae026692017-12-09 01:03:01 +010011418 execute( TC_chan_act_ack_est_ind_noreply() );
11419 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +010011420 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +010011421 execute( TC_chan_exhaustion() );
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +070011422 execute( TC_chan_deact_silence() );
Harald Welte4003d112017-12-09 22:35:39 +010011423 execute( TC_chan_rel_rll_rel_ind() );
11424 execute( TC_chan_rel_conn_fail() );
11425 execute( TC_chan_rel_hard_clear() );
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +020011426 execute( TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() );
11427 execute( TC_chan_rel_last_eutran_plmn_hard_clear_csfb() );
Harald Welte99787102019-02-04 10:41:36 +010011428 execute( TC_chan_rel_hard_clear_csfb() );
Harald Welted8c36cd2017-12-09 23:05:31 +010011429 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +020011430 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +010011431 execute( TC_chan_rel_a_reset() );
Pau Espin Pedrolc675b612020-01-09 19:55:40 +010011432 execute( TC_chan_rel_sccp_tiar_timeout() );
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +020011433 execute( TC_chan_rel_rr_cause() );
Harald Welte6f521d82017-12-11 19:52:02 +010011434
Harald Weltecfe2c962017-12-15 12:09:32 +010011435 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +010011436
11437 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +010011438 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +010011439 execute( TC_assignment_csd() );
11440 execute( TC_assignment_ctm() );
11441 execute( TC_assignment_sign() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +020011442 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11443 execute( TC_assignment_aoip_tla_v6() );
11444 }
Harald Welte235ebf12017-12-15 14:18:16 +010011445 execute( TC_assignment_fr_a5_0() );
11446 execute( TC_assignment_fr_a5_1() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +020011447 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte8f67d1d2018-05-25 20:38:42 +020011448 execute( TC_assignment_fr_a5_1_codec_missing() );
11449 }
Harald Welte235ebf12017-12-15 14:18:16 +010011450 execute( TC_assignment_fr_a5_3() );
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +020011451 execute( TC_assignment_fr_a5_4() );
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +020011452 execute( TC_assignment_fr_a5_4_fail() );
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +020011453 execute( TC_assignment_fr_a5_not_sup() );
Harald Welte3c86ea02018-05-10 22:28:05 +020011454 execute( TC_ciph_mode_a5_0() );
11455 execute( TC_ciph_mode_a5_1() );
Oliver Smith50b98122021-07-09 15:00:28 +020011456 execute( TC_ciph_mode_a5_2_0() );
Oliver Smith1dff88d2021-07-09 08:45:51 +020011457 execute( TC_ciph_mode_a5_2_1() );
Harald Welte3c86ea02018-05-10 22:28:05 +020011458 execute( TC_ciph_mode_a5_3() );
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +020011459 execute( TC_ciph_mode_a5_4() );
Harald Welte16a4adf2017-12-14 18:54:01 +010011460
Harald Welte60aa5762018-03-21 19:33:13 +010011461 execute( TC_assignment_codec_fr() );
Neels Hofmeyr559d5d02021-04-16 16:50:49 +020011462 execute( TC_assignment_codec_fr_by_mode_modify() );
Harald Welte60aa5762018-03-21 19:33:13 +010011463 execute( TC_assignment_codec_hr() );
11464 execute( TC_assignment_codec_efr() );
11465 execute( TC_assignment_codec_amr_f() );
11466 execute( TC_assignment_codec_amr_h() );
Philipp Maier8a581d22019-03-26 18:32:48 +010011467
Neels Hofmeyrf246a922020-05-13 02:27:10 +020011468 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier8a581d22019-03-26 18:32:48 +010011469 execute( TC_assignment_codec_amr_f_S1() );
11470 execute( TC_assignment_codec_amr_h_S1() );
11471 execute( TC_assignment_codec_amr_f_S124() );
11472 execute( TC_assignment_codec_amr_h_S124() );
11473 execute( TC_assignment_codec_amr_f_S0() );
11474 execute( TC_assignment_codec_amr_f_S02() );
11475 execute( TC_assignment_codec_amr_f_S024() );
11476 execute( TC_assignment_codec_amr_f_S0247() );
11477 execute( TC_assignment_codec_amr_h_S0() );
11478 execute( TC_assignment_codec_amr_h_S02() );
11479 execute( TC_assignment_codec_amr_h_S024() );
11480 execute( TC_assignment_codec_amr_h_S0247() );
11481 execute( TC_assignment_codec_amr_f_S01234567() );
11482 execute( TC_assignment_codec_amr_f_S0234567() );
11483 execute( TC_assignment_codec_amr_f_zero() );
11484 execute( TC_assignment_codec_amr_f_unsupp() );
11485 execute( TC_assignment_codec_amr_h_S7() );
Neels Hofmeyr21863562020-11-26 00:34:33 +000011486 execute( TC_assignment_codec_amr_f_start_mode_auto() );
11487 execute( TC_assignment_codec_amr_h_start_mode_auto() );
Neels Hofmeyr3eb94562020-11-26 02:40:26 +000011488 execute( TC_assignment_codec_amr_f_start_mode_4() );
11489 execute( TC_assignment_codec_amr_h_start_mode_4() );
Neels Hofmeyr454d7922020-11-26 02:24:57 +000011490 execute( TC_assignment_codec_amr_startmode_cruft() );
Philipp Maier8a581d22019-03-26 18:32:48 +010011491 }
Harald Welte60aa5762018-03-21 19:33:13 +010011492
Philipp Maierac09bfc2019-01-08 13:41:39 +010011493 execute( TC_assignment_codec_fr_exhausted_req_hr() );
11494 execute( TC_assignment_codec_fr_exhausted_req_fr() );
11495 execute( TC_assignment_codec_fr_exhausted_req_fr_hr() );
11496 execute( TC_assignment_codec_fr_exhausted_req_hr_fr() );
11497 execute( TC_assignment_codec_hr_exhausted_req_fr() );
11498 execute( TC_assignment_codec_hr_exhausted_req_hr() );
11499 execute( TC_assignment_codec_hr_exhausted_req_hr_fr() );
11500 execute( TC_assignment_codec_hr_exhausted_req_fr_hr() );
11501 execute( TC_assignment_codec_req_hr_fr() );
11502 execute( TC_assignment_codec_req_fr_hr() );
Pau Espin Pedrol14475352021-07-22 15:48:16 +020011503 execute( TC_assignment_sdcch_exhausted_req_signalling() );
11504 execute( TC_assignment_sdcch_exhausted_req_signalling_tch_forbidden() );
11505 execute( TC_assignment_sdcch_exhausted_req_voice_tch_forbidden() );
Philipp Maierac09bfc2019-01-08 13:41:39 +010011506
Pau Espin Pedrol23510fb2021-07-20 17:00:38 +020011507 execute( TC_assignment_osmux() );
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +020011508
Harald Welte898113b2018-01-31 18:32:21 +010011509 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +010011510 execute( TC_rll_est_ind_inact_lchan() );
11511 execute( TC_rll_est_ind_inval_sapi1() );
11512 execute( TC_rll_est_ind_inval_sapi3() );
11513 execute( TC_rll_est_ind_inval_sacch() );
11514
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +070011515 /* DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
11516 execute( TC_tch_dlci_link_id_sapi() );
11517
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +070011518 /* SAPI N Reject triggered by RLL establishment failures */
11519 execute( TC_rll_rel_ind_sapi_n_reject() );
11520 execute( TC_rll_err_ind_sapi_n_reject() );
11521 execute( TC_rll_timeout_sapi_n_reject() );
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +070011522 execute( TC_rll_sapi_n_reject_dlci_cc() );
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +070011523
Harald Welte898113b2018-01-31 18:32:21 +010011524 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +010011525 execute( TC_paging_imsi_nochan() );
11526 execute( TC_paging_tmsi_nochan() );
11527 execute( TC_paging_tmsi_any() );
11528 execute( TC_paging_tmsi_sdcch() );
11529 execute( TC_paging_tmsi_tch_f() );
11530 execute( TC_paging_tmsi_tch_hf() );
11531 execute( TC_paging_imsi_nochan_cgi() );
11532 execute( TC_paging_imsi_nochan_lac_ci() );
11533 execute( TC_paging_imsi_nochan_ci() );
11534 execute( TC_paging_imsi_nochan_lai() );
11535 execute( TC_paging_imsi_nochan_lac() );
11536 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +010011537 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
11538 execute( TC_paging_imsi_nochan_rnc() );
11539 execute( TC_paging_imsi_nochan_lac_rnc() );
11540 execute( TC_paging_imsi_nochan_lacs() );
11541 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +010011542 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +010011543 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +010011544 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +010011545 execute( TC_paging_counter() );
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +010011546 execute( TC_paging_resp_unsol() );
Pau Espin Pedrol09b9bad2022-04-21 18:48:08 +020011547 execute( TC_paging_500req() );
Pau Espin Pedrol189bf1b2022-04-27 12:42:13 +020011548 execute( TC_paging_450req_no_paging_load_ind() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +010011549
11550 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +010011551 execute( TC_rsl_unknown_unit_id() );
11552
11553 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +010011554
11555 execute( TC_classmark() );
Harald Welteeddf0e92020-06-21 19:42:15 +020011556 execute( TC_common_id() );
Harald Welte898113b2018-01-31 18:32:21 +010011557 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +010011558 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +010011559 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +010011560 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +010011561 execute( TC_err_84_unknown_msg() );
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010011562
Harald Welte261af4b2018-02-12 21:20:39 +010011563 execute( TC_ho_int() );
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +020011564 execute( TC_ho_int_a5_0() );
11565 execute( TC_ho_int_a5_1() );
11566 execute( TC_ho_int_a5_3() );
11567 execute( TC_ho_int_a5_4() );
Neels Hofmeyr5f144212020-11-03 15:41:58 +000011568 execute( TC_ho_int_radio_link_failure() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011569
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +010011570 /* TC_ho_out_of_this_bsc is run last, see comment below */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +020011571 execute( TC_ho_out_fail_no_msc_response() );
11572 execute( TC_ho_out_fail_rr_ho_failure() );
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +020011573 execute( TC_ho_out_fail_no_result_after_ho_cmd() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011574
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010011575 execute( TC_ho_into_this_bsc() );
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +020011576 execute( TC_ho_into_this_bsc_a5_0() );
11577 execute( TC_ho_into_this_bsc_a5_1() );
11578 execute( TC_ho_into_this_bsc_a5_3() );
11579 execute( TC_ho_into_this_bsc_a5_4() );
Neels Hofmeyr93182e02022-02-17 21:59:07 +010011580 execute( TC_ho_into_this_bsc_a5_1_3_no_chosen_enc_alg() );
11581 execute( TC_ho_into_this_bsc_a5_1_3() );
Neels Hofmeyr907b23b2022-02-17 21:58:47 +010011582 execute( TC_ho_into_this_bsc_a5_mismatch() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +020011583 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11584 execute( TC_ho_into_this_bsc_tla_v6() );
11585 }
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +020011586 execute( TC_srvcc_eutran_to_geran() );
Vadim Yanitskiy634f75d2022-03-14 17:04:45 +030011587 execute( TC_srvcc_eutran_to_geran_a5_3() );
Pau Espin Pedrola8ef3be2022-02-16 16:21:17 +010011588 execute( TC_srvcc_eutran_to_geran_src_sai() );
Pau Espin Pedrol35801c32021-04-19 13:03:20 +020011589 execute( TC_srvcc_eutran_to_geran_ho_out() );
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +020011590 execute( TC_srvcc_eutran_to_geran_forbid_fast_return() );
11591 execute( TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011592 execute( TC_ho_in_fail_msc_clears() );
11593 execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
11594 execute( TC_ho_in_fail_no_detect() );
11595 execute( TC_ho_in_fail_no_detect2() );
Neels Hofmeyra23f3b12022-03-02 19:57:12 +010011596 execute( TC_ho_into_this_bsc_sccp_cr_without_bssap() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +010011597
Neels Hofmeyr91401012019-07-11 00:42:35 +020011598 execute( TC_ho_neighbor_config_1() );
11599 execute( TC_ho_neighbor_config_2() );
11600 execute( TC_ho_neighbor_config_3() );
11601 execute( TC_ho_neighbor_config_4() );
11602 execute( TC_ho_neighbor_config_5() );
11603 execute( TC_ho_neighbor_config_6() );
11604 execute( TC_ho_neighbor_config_7() );
11605
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +010011606 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010011607 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +010011608 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +020011609
11610 execute( TC_dyn_pdch_ipa_act_deact() );
11611 execute( TC_dyn_pdch_ipa_act_nack() );
11612 execute( TC_dyn_pdch_osmo_act_deact() );
11613 execute( TC_dyn_pdch_osmo_act_nack() );
Pau Espin Pedrol37a4c152021-11-16 19:02:23 +010011614 execute( TC_dyn_ts_sdcch8_act_deact() );
11615 execute( TC_dyn_ts_sdcch8_all_subslots_used() );
11616 execute( TC_dyn_ts_sdcch8_tch_call_act_deact() );
11617 execute( TC_dyn_ts_sdcch8_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +020011618
Stefan Sperling0796a822018-10-05 13:01:39 +020011619 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +020011620 execute( TC_chopped_ipa_payload() );
Stefan Sperling0796a822018-10-05 13:01:39 +020011621
Pau Espin Pedrol8f773632019-11-05 11:46:53 +010011622 /* Power control related */
11623 execute( TC_assignment_verify_ms_power_params_ie() );
Vadim Yanitskiy4b233042021-06-30 00:58:43 +020011624 execute( TC_c0_power_red_mode() );
Neels Hofmeyr4f118412020-06-04 15:25:10 +020011625
11626 /* MSC pooling */
11627 /* FIXME: in SCCPlite, indicating how many MSCs should be connected does currently not work. Since
11628 * RESET->RESET-ACK is unconditionally negotiated for all configured MSCs, they always all appear as connected
11629 * to osmo-bsc. The MSC pooling tests however require disconnecting selected MSCs, and hence don't work out as
11630 * intended on SCCPlite. So for now, run these only for SCCP/M3UA. */
11631 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11632 execute( TC_mscpool_L3Compl_on_1_msc() );
11633 execute( TC_mscpool_L3Complete_by_imsi_round_robin() );
11634 execute( TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() );
11635 execute( TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() );
11636 execute( TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() );
11637 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() );
11638 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_1() );
11639 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_2() );
11640 execute( TC_mscpool_LU_by_tmsi_from_other_PLMN() );
11641 execute( TC_mscpool_paging_and_response_imsi() );
11642 execute( TC_mscpool_paging_and_response_tmsi() );
11643 execute( TC_mscpool_no_allow_attach_round_robin() );
11644 execute( TC_mscpool_no_allow_attach_valid_nri() );
11645 }
11646
Harald Welte99f3ca02018-06-14 13:40:29 +020011647 execute( TC_early_conn_fail() );
11648 execute( TC_late_conn_fail() );
Oliver Smithaf03bef2021-08-24 15:34:51 +020011649 execute( TC_stats_conn_fail() );
Harald Welte99f3ca02018-06-14 13:40:29 +020011650
Philipp Maier783681c2020-07-16 16:47:06 +020011651 /* Emergency call handling (deny / allow) */
11652 execute( TC_assignment_emerg_setup_allow() );
11653 execute( TC_assignment_emerg_setup_deny_msc() );
11654 execute( TC_assignment_emerg_setup_deny_bts() );
Philipp Maier82812002020-08-13 18:48:27 +020011655 execute( TC_emerg_premption() );
11656
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +070011657 /* Frequency hopping parameters handling */
11658 execute( TC_fh_params_chan_activ() );
11659 execute( TC_fh_params_imm_ass() );
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +070011660 execute( TC_fh_params_assignment_cmd() );
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +070011661 execute( TC_fh_params_handover_cmd() );
Vadim Yanitskiyca974032020-09-01 07:20:39 +070011662 execute( TC_fh_params_si4_cbch() );
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020011663
11664 if (mp_enable_lcs_tests) {
11665 execute( TC_lcs_loc_req_for_active_ms() );
11666 execute( TC_lcs_loc_req_for_active_ms_ta_req() );
11667 execute( TC_lcs_loc_req_for_idle_ms() );
11668 execute( TC_lcs_loc_req_no_subscriber() );
11669 execute( TC_lcs_loc_req_for_active_ms_le_timeout() );
11670 execute( TC_lcs_loc_req_for_active_ms_le_timeout2() );
11671 execute( TC_lcs_loc_req_for_idle_ms_no_pag_resp() );
11672 execute( TC_cm_service_during_lcs_loc_req() );
11673 execute( TC_ho_during_lcs_loc_req() );
Neels Hofmeyra47a8c62022-04-07 00:31:19 +020011674 execute( TC_emerg_call_and_lcs_loc_req() );
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020011675 }
Neels Hofmeyrbf037052020-10-28 22:52:02 +000011676
11677 execute( TC_no_msc() );
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000011678
11679 execute( TC_refuse_chan_act_to_vamos() );
11680 execute( TC_refuse_mode_modif_to_vamos() );
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000011681
11682 execute( TC_reassignment_fr() );
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020011683
11684 execute( TC_cm_reestablishment() );
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020011685
11686 execute( TC_imm_ass_post_chan_ack() );
11687 execute( TC_imm_ass_pre_chan_ack() );
Neels Hofmeyr23158742021-09-07 19:08:07 +020011688 execute( TC_imm_ass_pre_ts_ack() );
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020011689 execute( TC_imm_ass_pre_chan_ack_dyn_ts() );
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020011690 execute( TC_imm_ass_pre_ts_ack_dyn_ts() );
Neels Hofmeyr5d7d13f2021-09-07 14:44:36 +020011691
11692 execute( TC_ctrl_trx_rf_locked() );
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011693
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011694 execute( TC_ratectr_all_available_allocated() );
11695 execute( TC_ratectr_all_available_allocated_dyn() );
11696
Neels Hofmeyrb7581872021-11-07 14:02:49 +010011697 execute( TC_cm_serv_rej() );
11698
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011699 execute( TC_lost_sdcch_during_assignment() );
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +010011700
11701 /* Run TC_ho_out_of_this_bsc last, because it may trigger a segfault before osmo-bsc's patch
11702 * with change-id I5a3345ab0005a73597f5c27207480912a2f5aae6 */
11703 execute( TC_ho_out_of_this_bsc() );
Harald Welte28d943e2017-11-25 15:00:50 +010011704}
11705
11706}