blob: 634e6295a4aaf1bb628e876a39ac0ff5eeb24166 [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,
458 rest_octets := ?
459 }
460 };
461
462
463/* List of all the System Information received on all RSL ports */
464type record of SystemInformationConfig SystemInformationConfig_list;
465
466function f_sysinfo_dec_raw(inout SystemInformationConfig si, RSL_Message rsl)
467{
468 var RSL_IE_Body sysinfo_type_ie;
469 var RSL_IE_SysinfoType si_type;
470 var octetstring data;
471
472 if (f_rsl_find_ie(rsl, RSL_IE_SYSINFO_TYPE, sysinfo_type_ie) == false) {
473 setverdict(fail, "Cannot find RSL_IE_SYSINFO_TYPE");
474 mtc.stop;
475 }
476 si_type := sysinfo_type_ie.sysinfo_type;
477
478 if (rsl.msg_type == RSL_MT_BCCH_INFO) {
479 var RSL_IE_Body bcch_ie;
480 if (f_rsl_find_ie(rsl, RSL_IE_FULL_BCCH_INFO, bcch_ie)) {
481 data := bcch_ie.other.payload;
482 }
483 } else if (rsl.msg_type == RSL_MT_SACCH_FILL) {
484 var RSL_IE_Body l3_ie;
485 if (f_rsl_find_ie(rsl, RSL_IE_L3_INFO, l3_ie)) {
486 data := l3_ie.l3_info.payload;
487 }
488 } else {
489 setverdict(fail, "Don't understand this System Information message");
490 mtc.stop;
491 }
492
493 var boolean handled := false;
494
495 if (rsl.msg_type == RSL_MT_BCCH_INFO) {
496 handled := true;
497
498 if (si_type == RSL_SYSTEM_INFO_1) {
499 if (not isbound(data)) {
500 si.si1 := omit;
501 } else {
502 si.si1 := dec_SystemInformation(data).payload.si1;
503 }
504 } else if (si_type == RSL_SYSTEM_INFO_2) {
505 if (not isbound(data)) {
506 si.si2 := omit;
507 } else {
508 si.si2 := dec_SystemInformation(data).payload.si2;
509 }
510 } else if (si_type == RSL_SYSTEM_INFO_2bis) {
511 if (not isbound(data)) {
512 si.si2bis := omit;
513 } else {
514 si.si2bis := dec_SystemInformation(data).payload.si2bis;
515 }
516 } else if (si_type == RSL_SYSTEM_INFO_2ter) {
517 if (not isbound(data)) {
518 si.si2ter := omit;
519 } else {
520 si.si2ter := dec_SystemInformation(data).payload.si2ter;
521 }
522 } else if (si_type == RSL_SYSTEM_INFO_2quater) {
523 if (not isbound(data)) {
524 si.si2quater := {};
525 } else {
526 var SystemInformationType2quater decoded := dec_SystemInformation(data).payload.si2quater;
527 /* this is a *record* of SI2quaterRestOctets! (multiplexed) */
528 si.si2quater[decoded.rest_octets.si2quater_index] := decoded.rest_octets;
529 }
530 } else if (si_type == RSL_SYSTEM_INFO_3) {
531 if (not isbound(data)) {
532 si.si3 := omit;
533 } else {
534 si.si3 := dec_SystemInformation(data).payload.si3;
535 }
536 } else if (si_type == RSL_SYSTEM_INFO_4) {
537 if (not isbound(data)) {
538 si.si4 := omit;
539 } else {
540 si.si4 := dec_SystemInformation(data).payload.si4;
541 }
542 } else if (si_type == RSL_SYSTEM_INFO_13) {
543 if (not isbound(data)) {
544 si.si13 := omit;
545 } else {
Pau Espin Pedrol28652d82021-02-09 20:20:17 +0100546 si.si13 := dec_SystemInformation(data).payload.si13;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200547 }
548 } else {
549 handled := false;
550 }
551 } else if (rsl.msg_type == RSL_MT_SACCH_FILL) {
552 handled := true;
553
554 if (si_type == RSL_SYSTEM_INFO_5) {
555 if (not isbound(data)) {
556 si.si5 := omit;
557 } else {
558 si.si5 := dec_SystemInformation(data).payload.si5;
559 }
560 } else if (si_type == RSL_SYSTEM_INFO_5bis) {
561 if (not isbound(data)) {
562 si.si5bis := omit;
563 } else {
564 si.si5bis := dec_SystemInformation(data).payload.si5bis;
565 }
566 } else if (si_type == RSL_SYSTEM_INFO_5ter) {
567 if (not isbound(data)) {
568 si.si5ter := omit;
569 } else {
570 si.si5ter := dec_SystemInformation(data).payload.si5ter;
571 }
572 } else if (si_type == RSL_SYSTEM_INFO_6) {
573 if (not isbound(data)) {
574 si.si6 := omit;
575 } else {
576 si.si6 := dec_SystemInformation(data).payload.si6;
577 }
578 } else {
579 handled := false;
580 }
581 }
582
583 if (not handled) {
584 setverdict(fail, "Unexpected SI type in ", rsl.msg_type, " message: ", si_type);
585 }
586}
587
Harald Weltea4ca4462018-02-09 00:17:14 +0100588type component test_CT extends CTRL_Adapter_CT {
Harald Welte21b46bd2017-12-17 19:46:32 +0100589 /* Array of per-BTS state */
Harald Welte96c94412017-12-09 03:12:45 +0100590 var BTS_State bts[NUM_BTS];
Harald Welte89ab1912018-02-23 18:56:29 +0100591 /* RSL common Channel Port (for RSL_Emulation) */
592 port RSL_CCHAN_PT RSL_CCHAN[NUM_BTS];
Harald Welte21b46bd2017-12-17 19:46:32 +0100593 /* array of per-BTS RSL test ports */
Harald Welteae026692017-12-09 01:03:01 +0100594 port IPA_RSL_PT IPA_RSL[NUM_BTS];
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100595 port IPA_CODEC_PT IPA; /* Required for compilation of TC_rsl_unknown_unit_id() */
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +0200596 /* CTRL muxed over IPA in SCCPlite conn BSC<->MSC (or BSC-NAT) */
597 port IPA_CTRL_PT SCCPLITE_IPA_CTRL;
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100598 /* Configure/manage IPA_Emulation: */
599 port IPA_CFG_PT IPA_CFG_PORT;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100600
Daniel Willmann191e0d92018-01-17 12:44:35 +0100601 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +0100602 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100603
Daniel Willmannebdecc02020-08-12 15:30:17 +0200604 /* StatsD */
605 var StatsD_Checker_CT vc_STATSD;
606
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200607 var RAN_Adapter g_bssap[NUM_MSC];
Harald Welte47cd0e32020-08-21 12:39:11 +0200608 var BSSAP_LE_Adapter g_bssap_le;
Harald Weltea4ca4462018-02-09 00:17:14 +0100609 /* for old legacy-tests only */
610 port BSSAP_CODEC_PT BSSAP;
Harald Welte47cd0e32020-08-21 12:39:11 +0200611 port BSSAP_LE_CODEC_PT BSSAP_LE;
Harald Weltea4ca4462018-02-09 00:17:14 +0100612
Harald Welte21b46bd2017-12-17 19:46:32 +0100613 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +0100614 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +0100615
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200616 /* Osmux is enabled through VTY */
617 var boolean g_osmux_enabled := false;
618
Pau Espin Pedrolc675b612020-01-09 19:55:40 +0100619 /*Configure T(tias) over VTY, seconds */
620 var integer g_bsc_sccp_timer_ias := 7 * 60;
621 /*Configure T(tiar) over VTY, seconds */
622 var integer g_bsc_sccp_timer_iar := 15 * 60;
623
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +0200624 /* global test case guard timer (actual timeout value is set in f_init()) */
Harald Welteae026692017-12-09 01:03:01 +0100625 timer T_guard := 30.0;
626
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200627 var CounterNameValsList g_ctr_msc;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000628 var CounterNameValsList g_ctr_bsc;
629 var CounterNameValsList g_ctr_bts;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200630
631 /* System Information bytes as received during RSL startup, for each RSL[idx]. */
632 var SystemInformationConfig_list g_system_information := {};
Harald Welte28d943e2017-11-25 15:00:50 +0100633}
634
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200635type record of charstring phys_chan_configs;
Harald Welte28d943e2017-11-25 15:00:50 +0100636modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +0100637 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +0100638 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100639 /* port number to which to establish the IPA OML connections */
640 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +0100641 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +0100642 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +0100643 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +0100644 integer mp_bsc_ctrl_port := 4249;
Daniel Willmannebdecc02020-08-12 15:30:17 +0200645 /* port number to which to listen for STATSD metrics */
646 integer mp_bsc_statsd_port := 8125;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100647 /* IP address at which the test binds */
648 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100649
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200650 RAN_Configurations mp_bssap_cfg := {
651 {
652 transport := BSSAP_TRANSPORT_AoIP,
653 sccp_service_type := "mtp3_itu",
654 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
655 own_pc := 185, /* 0.23.1 first MSC emulation */
656 own_ssn := 254,
657 peer_pc := 187, /* 0.23.3 osmo-bsc */
658 peer_ssn := 254,
659 sio := '83'O,
Harald Weltecb0cc432020-06-21 19:42:31 +0200660 rctx := 1
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200661 },
662 {
663 transport := BSSAP_TRANSPORT_AoIP,
664 sccp_service_type := "mtp3_itu",
665 sctp_addr := { 23906, "127.0.0.1", 2905, "127.0.0.1" },
666 own_pc := 2, /* 0.0.2 second MSC emulation */
667 own_ssn := 254,
668 peer_pc := 187, /* 0.23.3 osmo-bsc */
669 peer_ssn := 254,
670 sio := '83'O,
671 rctx := 2
672 },
673 {
674 transport := BSSAP_TRANSPORT_AoIP,
675 sccp_service_type := "mtp3_itu",
676 sctp_addr := { 23907, "127.0.0.1", 2905, "127.0.0.1" },
677 own_pc := 3, /* 0.0.3 third MSC emulation */
678 own_ssn := 254,
679 peer_pc := 187, /* 0.23.3 osmo-bsc */
680 peer_ssn := 254,
681 sio := '83'O,
682 rctx := 3
683 }
Harald Weltea4ca4462018-02-09 00:17:14 +0100684 };
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +0200685
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200686 /* Must match per BTS config in osmo-bsc.cfg */
687 phys_chan_configs phys_chan_config := {
688 "CCCH+SDCCH4+CBCH",
689 "TCH/F",
690 "TCH/F",
691 "TCH/F",
692 "TCH/F",
Vadim Yanitskiy343c9eb2021-07-16 18:36:01 +0600693 "TCH/H",
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200694 "PDCH",
695 "PDCH"
696 };
697
Harald Welte47cd0e32020-08-21 12:39:11 +0200698 BSSAP_LE_Configuration mp_bssap_le_cfg := {
699 sccp_service_type := "mtp3_itu",
700 sctp_addr := { 23908, "127.0.0.1", 2905, "127.0.0.1" },
Neels Hofmeyrac086c12020-09-18 23:46:42 +0200701 own_pc := 190, /* 0.23.6 SMLC emulation */
Harald Welte47cd0e32020-08-21 12:39:11 +0200702 own_ssn := 252, /* SMLC side SSN */
703 peer_pc := 187, /* 0.23.3 osmo-bsc */
704 peer_ssn := 250, /* BSC side SSN */
705 sio := '83'O,
706 rctx := 6
707 };
Neels Hofmeyrcfe44062020-10-15 02:28:08 +0200708 boolean mp_enable_lcs_tests := true;
Harald Welte47cd0e32020-08-21 12:39:11 +0200709
Pau Espin Pedrol8f30ccd2019-11-01 17:30:57 +0100710 /* Value set in osmo-bsc.cfg "ms max power" */
711 uint8_t mp_exp_ms_power_level := 7;
Harald Weltea4ca4462018-02-09 00:17:14 +0100712}
713
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +0200714friend function f_gen_test_hdlr_pars(integer bssap_idx := 0) return TestHdlrParams {
Philipp Maier48604732018-10-09 15:00:37 +0200715
716 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200717 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier48604732018-10-09 15:00:37 +0200718 pars.aoip := true;
719 } else {
720 pars.aoip := false;
721 }
Pau Espin Pedrol8f30ccd2019-11-01 17:30:57 +0100722 pars.exp_ms_power_level := mp_exp_ms_power_level;
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200723 pars.mscpool.bssap_idx := bssap_idx;
Neels Hofmeyrbf720202021-10-02 12:58:24 +0200724 pars.expect_tsc := BTS_TSC[0];
Vadim Yanitskiy96bb9cb2021-12-10 21:14:15 +0300725 pars.imsi := f_rnd_imsi('00101'H);
726
727 log(testcasename(), ": using IMSI ", pars.imsi);
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200728
Philipp Maier48604732018-10-09 15:00:37 +0200729 return pars;
730}
731
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200732/* Convenience functions for rate counters using g_ctr_msc. */
733
734private function f_ctrs_msc_init(integer mscs_count := NUM_MSC, CounterNameVals counternames := counternames_msc_mscpool) runs on test_CT {
735 g_ctr_msc := f_counter_name_vals_get_n(IPA_CTRL, "msc", mscs_count, counternames);
736 log("initial msc rate counters: ", g_ctr_msc);
737}
738
739private function f_ctrs_msc_add(integer msc_nr, charstring countername, integer val := 1) runs on test_CT {
Neels Hofmeyr9656e922020-06-30 01:27:01 +0200740 f_counter_name_vals_list_add(g_ctr_msc, msc_nr, countername, val);
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200741}
742
743/* f_ctrs_msc_init();
744 * f_do_thing(on_msc := 0);
745 * f_do_thing(on_msc := 0);
746 * f_do_other(on_msc := 1);
747 * f_ctrs_msc_add(0, "thing", 2);
748 * f_ctrs_msc_add(1, "other");
749 * f_ctrs_msc_verify();
750 */
751private function f_ctrs_msc_verify() runs on test_CT {
752 log("verifying msc rate counters: ", g_ctr_msc);
753 f_counter_name_vals_expect_n(IPA_CTRL, "msc", g_ctr_msc);
754}
755
756/* convenience: f_ctrs_msc_add() and f_ctrs_msc_verify() in one call.
757 * f_ctrs_msc_init();
758 * f_do_thing(on_msc := 0);
759 * f_do_thing(on_msc := 0);
760 * f_do_thing(on_msc := 0);
761 * f_ctrs_msc_expect(0, "thing", 3);
762 */
763private function f_ctrs_msc_expect(integer msc_nr, charstring countername, integer val := 1) runs on test_CT {
764 f_ctrs_msc_add(msc_nr, countername, val);
765 f_ctrs_msc_verify();
766}
767
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000768/* Convenience functions for rate counters using g_ctr_bts, always also including g_ctr_bsc. */
769
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100770private 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 +0000771 g_ctr_bts := f_counter_name_vals_get_n(IPA_CTRL, "bts", bts_count, counternames);
Neels Hofmeyr4dec8cc2021-11-29 15:59:44 +0100772 log("initial bts rate counters: ", g_ctr_bts);
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100773}
774
775function f_ctrs_bsc_and_bts_init(integer bts_count := NUM_BTS, CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
776 f_ctrs_bts_init(bts_count, counternames);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000777 f_ctrs_bsc_init(counternames);
778}
779
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100780private function f_ctrs_bsc_and_bts_handover_init(integer bts_count := NUM_BTS) runs on test_CT {
781 var CounterNameVals bts_names := counternames_bsc_bts_handover & counternames_bts_handover;
Neels Hofmeyr4dec8cc2021-11-29 15:59:44 +0100782 f_ctrs_bts_init(bts_count, bts_names);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100783 f_ctrs_bsc_init(counternames_bsc_bts_handover);
784}
785
786private function f_ctrs_bts_add(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000787 f_counter_name_vals_list_add(g_ctr_bts, bts_nr, countername, val);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100788}
789
790private function f_ctrs_bsc_and_bts_add(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
791 f_ctrs_bts_add(bts_nr, countername, val);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000792 f_ctrs_bsc_add(countername, val);
793}
794
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100795function f_ctrs_bts_verify() runs on test_CT {
796 f_counter_name_vals_expect_n(IPA_CTRL, "bts", g_ctr_bts);
797}
798
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000799/* f_ctrs_bsc_and_bts_init();
800 * f_do_thing(on_bts := 0);
801 * f_do_thing(on_bts := 0);
802 * f_do_other(on_bts := 1);
803 * f_ctrs_bsc_and_bts_add(0, "thing", 2);
804 * f_ctrs_bsc_and_bts_add(1, "other");
805 * f_ctrs_bsc_and_bts_verify();
806 */
807private function f_ctrs_bsc_and_bts_verify() runs on test_CT {
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100808 f_ctrs_bts_verify();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000809 f_ctrs_bsc_verify();
810}
811
812/* convenience: f_ctrs_bsc_and_bts_add() and f_ctrs_bsc_and_bts_verify() in one call.
813 * f_ctrs_bsc_and_bts_init();
814 * f_do_thing(on_bts := 0);
815 * f_do_thing(on_bts := 0);
816 * f_do_thing(on_bts := 0);
817 * f_ctrs_bsc_and_bts_expect(0, "thing", 3);
818 */
819private function f_ctrs_bsc_and_bts_expect(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
820 f_ctrs_bsc_and_bts_add(bts_nr, countername, val);
821 f_ctrs_bsc_and_bts_verify();
822}
823
824
825/* Convenience functions for rate counters using g_ctr_bsc. */
826
827private function f_ctrs_bsc_init(CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
828 g_ctr_bsc := f_counter_name_vals_get_n(IPA_CTRL, "bsc", 1, counternames);
829 log("initial bsc rate counters: ", g_ctr_bsc);
830}
831
832private function f_ctrs_bsc_add(charstring countername, integer val := 1) runs on test_CT {
833 f_counter_name_vals_list_add(g_ctr_bsc, 0, countername, val);
834}
835
836/* f_ctrs_bsc_init();
837 * f_do_thing();
838 * f_do_thing();
839 * f_do_other();
840 * f_ctrs_bsc_add("thing", 2);
841 * f_ctrs_bsc_add("other");
842 * f_ctrs_bsc_verify();
843 */
844private function f_ctrs_bsc_verify() runs on test_CT {
845 f_counter_name_vals_expect_n(IPA_CTRL, "bsc", g_ctr_bsc);
846}
847
848/* convenience: f_ctrs_bsc_add() and f_ctrs_bsc_verify() in one call.
849 * f_ctrs_bsc_init();
850 * f_do_thing();
851 * f_ctrs_bsc_expect("thing", 1);
852 */
853private function f_ctrs_bsc_expect(charstring countername, integer val := 1) runs on test_CT {
854 f_ctrs_bsc_add(countername, val);
855 f_ctrs_bsc_verify();
856}
857
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200858
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +0200859friend function f_shutdown_helper() runs on test_CT {
Neels Hofmeyr18997492021-12-13 17:30:35 +0100860 /* Run the subscr and conn leak test only when the VTY is initialized */
861 if (BSCVTY.checkstate("Mapped")) {
862 f_verify_talloc_count(BSCVTY, {"struct bsc_subscr", "struct gsm_subscriber_connection"});
863 }
864
Daniel Willmann637ef6c2018-07-25 10:49:09 +0200865 all component.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100866 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200867 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100868}
869
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200870private function f_legacy_bssap_reset(integer bssap_idx := 0) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +0100871 var BSSAP_N_UNITDATA_ind ud_ind;
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200872 var boolean reset_received := false;
Harald Weltea4ca4462018-02-09 00:17:14 +0100873 timer T := 5.0;
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200874 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
875 ts_BSSMAP_Reset(0, g_osmux_enabled)));
Harald Weltea4ca4462018-02-09 00:17:14 +0100876 T.start;
877 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200878 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap[bssap_idx].sccp_addr_own, g_bssap[bssap_idx].sccp_addr_peer,
879 tr_BSSMAP_ResetAck(g_osmux_enabled))) {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200880 log("BSSMAP: Received RESET-ACK in response to RESET, we're ready to go!");
Harald Weltea4ca4462018-02-09 00:17:14 +0100881 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200882 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200883 log("BSSMAP: Respoding to inbound RESET with RESET-ACK");
Harald Weltea4ca4462018-02-09 00:17:14 +0100884 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200885 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200886 reset_received := true;
Harald Weltea4ca4462018-02-09 00:17:14 +0100887 repeat;
888 }
889 [] BSSAP.receive { repeat; }
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200890 [] T.timeout {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200891 log("BSSMAP: Timeout waiting for RESET-ACK after sending RESET");
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200892 /* If we received a RESET after ours was sent, it
893 may be a race condition where the other peer beacame
894 available after we sent it, but we are in a desired
895 state anyway, so go forward. */
896 if (not reset_received) {
897 setverdict(fail);
898 }
899 }
Harald Weltea4ca4462018-02-09 00:17:14 +0100900 }
Harald Welte28d943e2017-11-25 15:00:50 +0100901}
902
Harald Welteae026692017-12-09 01:03:01 +0100903type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100904 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100905 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100906 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100907 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100908 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100909 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100910 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100911 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100912}
913
Harald Welte21b46bd2017-12-17 19:46:32 +0100914/*! Start the IPA/RSL related bits for one IPA_Client.
915 * \param clnt IPA_Client for which to establish
916 * \param bsc_host IP address / hostname of the BSC
917 * \param bsc_port TCP port number of the BSC
918 * \param i number identifying this BTS
919 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100920function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
921 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100922runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100923 timer T := 10.0;
924
Harald Welte96c94412017-12-09 03:12:45 +0100925 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welte71389132021-12-09 21:58:18 +0100926 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA") alive;
Harald Welteae026692017-12-09 01:03:01 +0100927 clnt.ccm_pars := c_IPA_default_ccm_pars;
928 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
929 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100930 if (handler_mode) {
Harald Welte71389132021-12-09 21:58:18 +0100931 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL") alive;
Harald Welte89ab1912018-02-23 18:56:29 +0100932 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100933 }
Harald Welteae026692017-12-09 01:03:01 +0100934
935 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100936 connect(clnt.vc_IPA:CFG_PORT, self:IPA_CFG_PORT);
Harald Welte624f9632017-12-16 19:26:04 +0100937 if (handler_mode) {
938 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
939 } else {
940 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
941 }
Harald Welteae026692017-12-09 01:03:01 +0100942
Harald Welte5d1a2202017-12-13 19:51:29 +0100943 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100944 if (handler_mode) {
945 clnt.vc_RSL.start(RSL_Emulation.main());
946 return;
947 }
Harald Welteae026692017-12-09 01:03:01 +0100948
949 /* wait for IPA RSL link to connect and send ID ACK */
950 T.start;
951 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700952 [] IPA_RSL[i].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) {
Harald Welteae026692017-12-09 01:03:01 +0100953 T.stop;
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +0700954 IPA_RSL[i].send(ts_ASP_RSL_UD(ts_RSL_PAGING_LOAD_IND(23)));
Harald Welteae026692017-12-09 01:03:01 +0100955 }
Harald Welte60e823a2017-12-10 14:10:59 +0100956 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100957 [] IPA_RSL[i].receive { repeat }
958 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100959 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200960 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100961 }
962 }
963}
964
Harald Welte12055472018-03-17 20:10:08 +0100965function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100966 var IPL4asp_Types.Result res := {
967 errorCode := omit,
968 connId := omit,
969 os_error_code := omit,
970 os_error_text := omit
971 };
972
Harald Welte12055472018-03-17 20:10:08 +0100973 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
974 return;
975 }
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100976
977 /* Alive components don't finish sockets (TCP FIN) when they are
978 * stopped. Hence, we need to manually call close() on them to make sure
979 * the IUT knows about it. */
980 f_ipa_cfg_disconnect(IPA_CFG_PORT, res);
981
Harald Welte12055472018-03-17 20:10:08 +0100982 clnt.vc_IPA.stop;
983 if (isbound(clnt.vc_RSL)) {
984 clnt.vc_RSL.stop;
985 }
986}
987
Harald Welte21b46bd2017-12-17 19:46:32 +0100988/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100989function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
990 timer T := secs_max;
991 T.start;
992 while (true) {
993 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
994 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100995 /* the 'degraded' state exists from OML connection time, and we have to wait
996 * until all MO's are initialized */
997 T.start(1.0);
998 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100999 return;
1000 }
Harald Weltef0d6ac62017-12-17 17:02:21 +01001001 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +01001002 if (not T.running) {
Max99253902018-11-16 17:57:39 +01001003 setverdict(fail, "Timeout waiting for BTS" & int2str(bts_nr) & " oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +02001004 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001005 }
1006 }
1007}
1008
Harald Welte21b46bd2017-12-17 19:46:32 +01001009/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +01001010altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +01001011 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +01001012 [] T_guard.timeout {
1013 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +02001014 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +01001015 }
Harald Welte60e823a2017-12-10 14:10:59 +01001016 /* always respond with RESET ACK to RESET */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001017 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Welte60e823a2017-12-10 14:10:59 +01001018 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001019 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Welte69c1c262017-12-13 21:02:08 +01001020 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +01001021 }
Harald Welte28d943e2017-11-25 15:00:50 +01001022}
1023
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001024altstep no_bssmap_reset() runs on test_CT {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001025 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001026 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +02001027 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001028 }
1029}
1030
Daniel Willmann191e0d92018-01-17 12:44:35 +01001031function f_init_mgcp(charstring id) runs on test_CT {
1032 id := id & "-MGCP";
1033
1034 var MGCPOps ops := {
1035 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
1036 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
1037 };
1038 var MGCP_conn_parameters mgcp_pars := {
1039 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +01001040 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +01001041 mgw_ip := mp_test_ip,
Pau Espin Pedrol1a026a52019-06-18 17:21:52 +02001042 mgw_udp_port := 2427,
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02001043 /* Enable it for SCCPlite, since we have 2 MGCP sockets towards MGW (UDP one +
1044 the on with MGCP over IPA forwarded from MSC one) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001045 multi_conn_mode := (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER)
Daniel Willmann191e0d92018-01-17 12:44:35 +01001046 };
1047
Harald Welte71389132021-12-09 21:58:18 +01001048 vc_MGCP := MGCP_Emulation_CT.create(id) alive;
Daniel Willmann191e0d92018-01-17 12:44:35 +01001049 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
1050}
1051
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001052/* Enable or disable (current default) Osmux. When enabling, BSSMAP Reset
1053 * contains extra IE (OsmuxSupport) and osmo-bsc will handle AssignReq with
1054 * OsmuxCID IE.
1055 */
1056private function f_vty_allow_osmux(boolean allow) runs on test_CT {
1057 f_vty_enter_cfg_msc(BSCVTY, 0);
1058 if (allow) {
1059 f_vty_transceive(BSCVTY, "osmux on");
1060 } else {
1061 f_vty_transceive(BSCVTY, "osmux off");
1062 }
1063 f_vty_transceive(BSCVTY, "exit");
1064 f_vty_transceive(BSCVTY, "exit");
1065 g_osmux_enabled := allow;
1066}
1067
Max2253c0b2018-11-06 19:28:05 +01001068function f_init_vty(charstring id := "foo") runs on test_CT {
Harald Welte94e0c342018-04-07 11:33:23 +02001069 if (BSCVTY.checkstate("Mapped")) {
1070 /* skip initialization if already executed once */
1071 return;
1072 }
Harald Weltebc03c762018-02-12 18:09:38 +01001073 map(self:BSCVTY, system:BSCVTY);
1074 f_vty_set_prompts(BSCVTY);
1075 f_vty_transceive(BSCVTY, "enable");
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01001076 f_cs7_inst_0_cfg(BSCVTY, {"sccp-timer ias " & int2str(g_bsc_sccp_timer_ias),
1077 "sccp-timer iar " & int2str(g_bsc_sccp_timer_iar)});
Harald Weltebc03c762018-02-12 18:09:38 +01001078}
1079
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +02001080friend function f_logp(TELNETasp_PT pt, charstring log_msg)
Neels Hofmeyr4f118412020-06-04 15:25:10 +02001081{
1082 // log on TTCN3 log output
1083 log(log_msg);
1084 // log in stderr log
Neels Hofmeyr8bdafe52021-12-14 17:25:48 +01001085 if (pt.checkstate("Mapped")) {
1086 f_vty_transceive(pt, "logp lglobal notice TTCN3 f_logp(): " & log_msg);
1087 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02001088}
1089
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001090private function f_sysinfo_seen(integer rsl_idx, RSL_Message rsl) runs on test_CT
1091{
1092 if (rsl_idx >= lengthof(g_system_information)) {
1093 g_system_information[rsl_idx] := SystemInformationConfig_omit
1094 }
1095 f_sysinfo_dec_raw(g_system_information[rsl_idx], rsl);
1096}
1097
1098altstep as_catch_RSL_sysinfo(integer rsl_idx) runs on test_CT {
1099 var ASP_RSL_Unitdata rx_rsl_ud;
1100
1101 /* For handler_mode := false, receiving the RSL bootstrap messages directly on IPA_RSL */
1102 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
1103 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1104 repeat;
1105 }
1106 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
1107 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1108 repeat;
1109 }
1110 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> value rx_rsl_ud {
1111 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1112 repeat;
1113 }
1114 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_SACCH_FILL)) -> value rx_rsl_ud {
1115 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1116 repeat;
1117 }
1118
1119 /* For handler_mode := true, receiving the RSL bootstrap messages via RSL_Emulation */
1120 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
1121 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1122 repeat;
1123 }
1124 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
1125 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1126 repeat;
1127 }
1128 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> value rx_rsl_ud {
1129 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1130 repeat;
1131 }
1132 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_SACCH_FILL)) -> value rx_rsl_ud {
1133 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1134 repeat;
1135 }
1136}
1137
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001138/* TODO: use BooleanList from COMMON/src/General_Types.ttcn */
1139private type record of boolean my_BooleanList;
1140
1141private function f_vty_msc_allow_attach(TELNETasp_PT pt, my_BooleanList allow_attach_list)
1142{
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001143 var charstring config := f_vty_transceive_ret(pt, "show running-config");
1144
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001145 for (var integer msc_nr := 0; msc_nr < sizeof(allow_attach_list); msc_nr := msc_nr+1) {
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001146 if (f_strstr(config, "\nmsc " & int2str(msc_nr) & "\n") < 0) {
1147 /* There is no 'msc N' for this msc_nr in the running config, so don't create an empty msc by
1148 * stepping into that config node. */
1149 log("msc ", msc_nr, " is not configured, skipping");
1150 continue;
1151 }
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001152 f_vty_enter_cfg_msc(pt, msc_nr);
1153 if (allow_attach_list[msc_nr]) {
1154 /* strict := false: ignore if osmo-bsc does not support this config option (latest build) */
1155 f_vty_transceive(pt, "allow-attach", strict := false);
1156 } else {
1157 f_vty_transceive(pt, "no allow-attach", strict := false);
1158 }
1159 f_vty_transceive(pt, "exit");
1160 f_vty_transceive(pt, "exit");
1161 }
1162}
1163
Harald Welte21b46bd2017-12-17 19:46:32 +01001164/* global initialization function
1165 * \param nr_bts Number of BTSs we should start/bring up
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001166 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false).
1167 * \param nr_msc Number of virtual MSCs to bring up to connect to osmo-bsc.
1168 */
1169function f_init(integer nr_bts := NUM_BTS, boolean handler_mode := false, boolean allow_osmux := false,
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001170 integer nr_msc := 1, float guard_timeout := 30.0) runs on test_CT {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001171 var integer bssap_idx;
Harald Welte28d943e2017-11-25 15:00:50 +01001172
Harald Welteae026692017-12-09 01:03:01 +01001173 if (g_initialized) {
1174 return;
Harald Welte28d943e2017-11-25 15:00:50 +01001175 }
Harald Welteae026692017-12-09 01:03:01 +01001176 g_initialized := true;
1177
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001178 T_guard.start(guard_timeout);
Daniel Willmanne68f9272018-11-27 15:15:28 +01001179 activate(as_Tguard());
1180
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001181 f_init_vty("VirtMSC");
Pau Espin Pedrol23510fb2021-07-20 17:00:38 +02001182 f_vty_allow_osmux(allow_osmux);
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001183
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001184 var my_BooleanList allow_attach := { false, false, false };
Daniel Willmannebdecc02020-08-12 15:30:17 +02001185 f_init_statsd("VirtMSC", vc_STATSD, mp_test_ip, mp_bsc_statsd_port);
1186
Neels Hofmeyr9db8e0e2021-08-23 20:45:58 +02001187 /* Make sure each MSC's internal state is "DISCONNECTED" at first */
1188 for (bssap_idx := 0; bssap_idx < NUM_MSC; bssap_idx := bssap_idx+1) {
1189 f_vty_transceive(BSCVTY, "msc " & int2str(bssap_idx) & " bssmap reset", strict := false);
1190 }
1191
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001192 for (bssap_idx := 0; bssap_idx < nr_msc; bssap_idx := bssap_idx+1) {
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001193 allow_attach[bssap_idx] := true;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001194 /* Call a function of our 'parent component' RAN_Adapter_CT to start the
1195 * MSC-side BSSAP emulation */
1196 if (handler_mode) {
1197 var RanOps ranops := MSC_RanOps;
1198 ranops.use_osmux := g_osmux_enabled;
1199 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", ranops);
1200 connect(self:SCCPLITE_IPA_CTRL, g_bssap[bssap_idx].vc_RAN:CTRL_CLIENT);
1201 f_ran_adapter_start(g_bssap[bssap_idx]);
1202 } else {
1203 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", omit);
1204 connect(self:BSSAP, g_bssap[bssap_idx].vc_SCCP:SCCP_SP_PORT);
1205 f_ran_adapter_start(g_bssap[bssap_idx]);
1206 f_legacy_bssap_reset();
1207 }
Harald Welte67089ee2018-01-17 22:19:03 +01001208 }
Harald Welted5833a82018-05-27 16:52:56 +02001209
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02001210 if (mp_enable_lcs_tests) {
1211 if (handler_mode) {
1212 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", SMLC_BssapLeOps);
1213 } else {
1214 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", omit);
1215 connect(self:BSSAP_LE, g_bssap_le.vc_SCCP:SCCP_SP_PORT);
1216 }
1217 f_bssap_le_adapter_start(g_bssap_le);
Harald Welte47cd0e32020-08-21 12:39:11 +02001218 }
Harald Welte47cd0e32020-08-21 12:39:11 +02001219
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001220 /* start the test with exactly all enabled MSCs allowed to attach */
1221 f_vty_msc_allow_attach(BSCVTY, allow_attach);
1222
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01001223 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +01001224
Daniel Willmann191e0d92018-01-17 12:44:35 +01001225 f_init_mgcp("VirtMSC");
1226
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001227 for (var integer i := 0; i < nr_bts; i := i+1) {
1228 f_init_bts(i, handler_mode);
Harald Welte696ddb62017-12-08 14:01:43 +01001229 }
Neels Hofmeyr9c0f9c82022-01-23 01:20:28 +01001230
1231 /* Emit a marker to appear in the SUT's own logging output */
1232 f_logp(BSCVTY, testcasename() & "() start");
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001233}
Harald Welte696ddb62017-12-08 14:01:43 +01001234
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001235function f_init_bts(integer bts_idx := 0, boolean handler_mode := false)
1236runs on test_CT {
1237 /* wait until osmo-bts-omldummy has respawned */
1238 f_wait_oml(bts_idx, "degraded", 5.0);
1239
1240 /* start RSL connection */
1241 f_ipa_rsl_start(bts[bts_idx].rsl, mp_bsc_ip, mp_bsc_rsl_port, bts_idx, handler_mode);
1242 /* wait until BSC tells us "connected" */
1243 f_wait_oml(bts_idx, "connected", 5.0);
Harald Welte28d943e2017-11-25 15:00:50 +01001244}
1245
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001246function f_init_bts_and_check_sysinfo(integer bts_idx := 0, boolean handler_mode := false,
1247 template SystemInformationConfig expect_si)
1248runs on test_CT {
1249 var default sysinfo := activate(as_catch_RSL_sysinfo(bts_idx));
1250
1251 f_init_bts(bts_idx, handler_mode);
1252
1253 /* Give some time to (hopefully/most likely) collect all system informations from RSL startup.
1254 * We could stop as soon as all expected SI are received, but then we might miss SI that we don't expect and
1255 * that might be sent afterwards. So rather give a generous timeout and be quite sure to catch all SI.
1256 */
1257 f_sleep(5.0);
1258 log("RSL ", bts_idx, " SYSTEM INFORMATION: ", g_system_information[bts_idx]);
1259
1260 deactivate(sysinfo);
1261
1262 if (match(g_system_information[bts_idx], expect_si)) {
1263 setverdict(pass);
1264 } else {
1265 log("RSL ", bts_idx, ": EXPECTED SI: ", expect_si);
1266 log("RSL ", bts_idx, ": GOT SI: ", g_system_information[bts_idx]);
1267 setverdict(fail, "received SI does not match expectations");
1268 return;
1269 }
1270}
1271
Maxd4e56962018-10-31 19:08:25 +01001272/* expect to receive a RSL message matching a specified template on a given BTS / stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001273function 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 +01001274runs on test_CT return RSL_Message {
1275 var ASP_RSL_Unitdata rx_rsl_ud;
1276 timer T := t_secs;
1277
1278 T.start;
1279 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001280 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
Harald Welteae026692017-12-09 01:03:01 +01001281 T.stop;
1282 }
1283 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +01001284 [] T.timeout {
1285 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +02001286 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +01001287 }
Harald Welteae026692017-12-09 01:03:01 +01001288 }
1289 return rx_rsl_ud.rsl;
1290}
1291
Harald Welte21b46bd2017-12-17 19:46:32 +01001292/* helper function to transmit RSL on a given BTS/stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001293function 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 +01001294runs on test_CT {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001295 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(t_tx, sid));
Harald Welteae026692017-12-09 01:03:01 +01001296}
1297
1298
Harald Welte4003d112017-12-09 22:35:39 +01001299/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +01001300testcase TC_chan_act_noreply() runs on test_CT {
1301 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +01001302 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +01001303
Harald Welte89d42e82017-12-17 16:42:41 +01001304 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +01001305
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001306 IPA_RSL[0].send(ts_ASP_RSL_UD(ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +01001307 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001308 f_shutdown_helper();
Harald Welte28d943e2017-11-25 15:00:50 +01001309}
1310
Neels Hofmeyr734b1a32021-11-29 16:00:17 +01001311const CounterNameVals counternames_bts_chreq := {
1312 { "chreq:total", 0 },
1313 { "chreq:attempted_emerg", 0 },
1314 { "chreq:attempted_call", 0 },
1315 { "chreq:attempted_location_upd", 0 },
1316 { "chreq:attempted_pag", 0 },
1317 { "chreq:attempted_pdch", 0 },
1318 { "chreq:attempted_other", 0 },
1319 { "chreq:attempted_unknown", 0 },
1320 { "chreq:successful", 0 },
1321 { "chreq:successful_emerg", 0 },
1322 { "chreq:successful_call", 0 },
1323 { "chreq:successful_location_upd", 0 },
1324 { "chreq:successful_pag", 0 },
1325 { "chreq:successful_pdch", 0 },
1326 { "chreq:successful_other", 0 },
1327 { "chreq:successful_unknown", 0 },
1328 { "chreq:no_channel", 0 },
1329 { "chreq:max_delay_exceeded", 0 }
1330};
1331
1332/* verify the "chreq:*" counters */
1333private function f_chan_act_counter(OCT1 ra, charstring chreq_ctr_suffix) runs on test_CT
1334{
1335 var GsmFrameNumber fn := 23;
1336
1337 f_logp(BSCVTY, "f_chan_act_counter(" & chreq_ctr_suffix & ")");
1338
1339 var RSL_Message rx_rsl;
1340 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1341 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1342 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1343
1344 f_ctrs_bts_add(0, "chreq:total");
1345 f_ctrs_bts_add(0, "chreq:attempted_" & chreq_ctr_suffix);
1346 f_ctrs_bts_verify();
1347
1348 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
1349 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
1350
1351 f_ctrs_bts_add(0, "chreq:successful");
1352 f_ctrs_bts_add(0, "chreq:successful_" & chreq_ctr_suffix);
1353 f_ctrs_bts_verify();
1354
1355 /* test is done, release RSL Conn Fail Ind to clean up */
1356 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1357 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1358 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
1359 f_sleep(1.0);
1360}
1361
Harald Welte4003d112017-12-09 22:35:39 +01001362testcase TC_chan_act_counter() runs on test_CT {
1363 var BSSAP_N_UNITDATA_ind ud_ind;
1364 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +01001365 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +01001366
Harald Welte89d42e82017-12-17 16:42:41 +01001367 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001368
Neels Hofmeyr734b1a32021-11-29 16:00:17 +01001369 f_vty_allow_emerg_bts(true, 0);
1370
1371 f_ctrs_bts_init(1, counternames_bts_chreq);
1372
1373 /* emergency call: RA & 0xe0 == 0xa0 --> CHREQ_T_EMERG_CALL */
1374 f_chan_act_counter('a3'O, "emerg");
1375
1376 /* voice TCH/H: RA & 0xf0 == 0x40 --> CHREQ_T_VOICE_CALL_TCH_H */
1377 f_chan_act_counter('43'O, "call");
1378
1379 /* LU: RA & 0xf0 == 0x00 --> CHREQ_T_LOCATION_UPD */
1380 f_chan_act_counter('03'O, "location_upd");
1381
1382 /* Paging: RA & 0xf0 == 0x20 --> CHREQ_T_PAG_R_TCH_F */
1383 f_chan_act_counter('23'O, "pag");
1384 /* Paging: RA & 0xf0 == 0x30 --> CHREQ_T_PAG_R_TCH_FH */
1385 f_chan_act_counter('33'O, "pag");
1386
1387 /* LU: RA & 0xfc == 0x78 --> CHREQ_T_PDCH_TWO_PHASE */
1388 /* no PCU, so PDCH not allowed. Skip this test for now. */
1389 /* f_chan_act_counter('7b'O, "pdch"); */
1390
1391 /* LU: RA & 0xf0 == 0x10 --> CHREQ_T_SDCCH */
1392 f_chan_act_counter('13'O, "other");
Harald Welte4003d112017-12-09 22:35:39 +01001393
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001394 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001395}
1396
Harald Welteae026692017-12-09 01:03:01 +01001397/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
Philipp Maier9c60a622020-07-09 15:08:46 +02001398private function f_TC_chan_act_ack_noest(OCT1 ra := '23'O) runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +01001399 var RSL_Message rx_rsl;
1400
Harald Welteae026692017-12-09 01:03:01 +01001401 /* Send CHAN RQD and wait for allocation; acknowledge it */
Philipp Maier9c60a622020-07-09 15:08:46 +02001402 var RslChannelNr chan_nr := f_chreq_act_ack(ra);
Harald Welteae026692017-12-09 01:03:01 +01001403
1404 /* expect BSC to disable the channel again if there's no RLL EST IND */
1405 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1406
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001407 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001408}
1409
Philipp Maier9c60a622020-07-09 15:08:46 +02001410/* Normal variant */
1411testcase TC_chan_act_ack_noest() runs on test_CT {
Philipp Maieraf58db22020-08-12 17:24:40 +02001412 f_init(1);
Philipp Maier9c60a622020-07-09 15:08:46 +02001413 f_TC_chan_act_ack_noest();
1414}
1415
1416/* Emergency call variant */
1417testcase TC_chan_act_ack_noest_emerg() runs on test_CT {
1418 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
Philipp Maieraf58db22020-08-12 17:24:40 +02001419 f_init(1);
1420 f_vty_allow_emerg_bts(true, 0);
Philipp Maier9c60a622020-07-09 15:08:46 +02001421 f_TC_chan_act_ack_noest(ra := 'A5'O);
1422}
1423
Philipp Maier606f07d2020-08-12 17:21:58 +02001424/* Emergency call variant, but emergency calls are not allowed */
1425testcase TC_chan_rqd_emerg_deny() runs on test_CT {
1426 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
1427
1428 var RSL_Message rx_rsl;
1429 var GsmRrMessage rr;
1430
1431 f_init(1);
1432 f_vty_allow_emerg_bts(false, 0);
1433
1434 IPA_RSL[0].clear;
1435 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
1436
1437 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
1438 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
1439 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1440 setverdict(pass);
1441 } else {
1442 setverdict(fail, "immediate assignment not rejected");
1443 }
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01001444
1445 f_shutdown_helper();
Philipp Maier606f07d2020-08-12 17:21:58 +02001446}
1447
Harald Welteae026692017-12-09 01:03:01 +01001448/* Test behavior if MSC never answers to CR */
1449testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +01001450 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
1451 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +01001452 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +01001453 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +01001454
Harald Welte89d42e82017-12-17 16:42:41 +01001455 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001456
1457 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001458 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001459
1460 var octetstring l3 := '00010203040506'O
1461 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1462
1463 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
1464
1465 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +01001466 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001467 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001468 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001469}
1470
1471/* Test behavior if MSC answers with CREF to CR */
1472testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
1473 var BSSAP_N_CONNECT_ind rx_c_ind;
1474 var RSL_Message rx_rsl;
1475
Harald Welte89d42e82017-12-17 16:42:41 +01001476 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001477
1478 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001479 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001480
1481 var octetstring l3 := '00010203040506'O
1482 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1483
1484 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1485 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
1486
1487 /* expect BSC to disable the channel */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001488 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001489 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001490}
1491
Harald Welte618ef642017-12-14 14:58:20 +01001492/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
1493testcase TC_chan_act_nack() runs on test_CT {
1494 var RSL_Message rx_rsl;
1495 var integer chact_nack;
1496
Harald Welte89d42e82017-12-17 16:42:41 +01001497 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +01001498
1499 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
1500
1501 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
1502 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1503 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1504
1505 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
1506
1507 /* wait for some time to hope the NACK arrives before the CTRL GET below */
1508 f_sleep(0.5);
1509
1510 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
1511
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001512 f_shutdown_helper();
Harald Welte618ef642017-12-14 14:58:20 +01001513}
1514
Harald Welte799c97b2017-12-14 17:50:30 +01001515/* Test for channel exhaustion due to RACH overload */
1516testcase TC_chan_exhaustion() runs on test_CT {
1517 var ASP_RSL_Unitdata rsl_ud;
1518 var integer i;
1519 var integer chreq_total, chreq_nochan;
1520
Harald Welte89d42e82017-12-17 16:42:41 +01001521 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +01001522
1523 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
1524 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
1525
Neels Hofmeyr85fa37f2021-10-06 13:50:38 +02001526 /* GSM 44.018 Table 9.1.8.2:
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +01001527 * RA = '33'O -> Establishment cause = 0011xxxx (MS dual rate capable and asks for "TCH/H or TCH/F").
1528 * With current setup, expect 4xSDCCH + 4xTCH/F + 1xTCH/H to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +02001529 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 +01001530 var RslChannelNr chan_nr := f_chreq_act_ack('33'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +01001531 }
1532
1533 IPA_RSL[0].clear;
1534
Harald Weltedd8cbf32018-01-28 12:07:52 +01001535 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001536 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +01001537
1538 /* now expect additional channel activations to fail */
1539 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
1540
1541 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001542 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
Harald Welte799c97b2017-12-14 17:50:30 +01001543 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
1544 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001545 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
Harald Welte799c97b2017-12-14 17:50:30 +01001546 var GsmRrMessage rr;
1547 /* match on IMM ASS REJ */
1548 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
1549 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1550 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001551 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +01001552 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
1553 chreq_nochan+1);
1554 setverdict(pass);
1555 } else {
1556 repeat;
1557 }
1558 }
1559 [] IPA_RSL[0].receive { repeat; }
1560 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001561 f_shutdown_helper();
Harald Welte799c97b2017-12-14 17:50:30 +01001562}
1563
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001564/* Test channel deactivation due to silence from MS */
1565testcase TC_chan_deact_silence() runs on test_CT {
1566 var RslChannelNr chan_nr;
1567
1568 f_init(1);
1569
1570 /* Request for a dedicated channel */
1571 chan_nr := f_chreq_act_ack('23'O);
1572
1573 /* Wait some time until the channel is released */
1574 f_sleep(2.0);
1575
1576 /* Expect CHANnel RELease */
1577 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001578 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001579 log("Received CHANnel RELease");
1580 setverdict(pass);
1581 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001582 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001583 /* See OS#3709, OsmoBSC should not send Immediate
1584 * Assignment Reject since a dedicated channel was
1585 * already allocated, and Immediate Assignment was
1586 * already sent. */
1587 setverdict(fail, "Unexpected Immediate Assignment!");
1588 }
1589 [] IPA_RSL[0].receive {
1590 setverdict(fail, "Unexpected RSL message!");
1591 }
1592 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001593 f_shutdown_helper();
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001594}
1595
Harald Weltecfe2c962017-12-15 12:09:32 +01001596/***********************************************************************
1597 * Assignment Testing
1598 ***********************************************************************/
1599
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001600/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction,
1601 * except for the inter-BSC handover, MT side) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001602testcase TC_outbound_connect(integer bssap_idx := 0) runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +01001603 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +01001604
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001605 BSSAP.send(ts_BSSAP_CONNECT_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
1606 2342, ts_BSSMAP_AssignmentReq));
Harald Weltecfe2c962017-12-15 12:09:32 +01001607 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001608 f_shutdown_helper();
Harald Weltecfe2c962017-12-15 12:09:32 +01001609}
1610
Harald Welte16a4adf2017-12-14 18:54:01 +01001611/* Test behavior if MSC answers with CREF to CR */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001612testcase TC_assignment_cic_only(integer bssap_idx := 0) runs on test_CT {
Harald Welte16a4adf2017-12-14 18:54:01 +01001613 var BSSAP_N_CONNECT_ind rx_c_ind;
1614 var RSL_Message rx_rsl;
1615 var DchanTuple dt;
1616
Harald Welte89d42e82017-12-17 16:42:41 +01001617 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +01001618
1619 dt := f_est_dchan('23'O, 23, '00000000'O);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001620 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte17b27da2018-05-25 20:33:53 +02001621 /* send assignment without AoIP IEs */
1622 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
1623 } else {
1624 /* Send assignmetn without CIC in IPA case */
1625 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
1626 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
1627 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
1628 }
Harald Welte16a4adf2017-12-14 18:54:01 +01001629 alt {
1630 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1631 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
1632 }
Harald Welte235ebf12017-12-15 14:18:16 +01001633 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +01001634 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1635 setverdict(pass);
1636 }
1637 [] BSSAP.receive { repeat; }
1638 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001639 f_perform_clear_test_ct(dt);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001640 f_shutdown_helper();
Harald Welte16a4adf2017-12-14 18:54:01 +01001641}
1642
Harald Welteed848512018-05-24 22:27:58 +02001643/* generate an assignment request for either AoIP or SCCPlite */
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001644function 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 +02001645 var PDU_BSSAP ass_cmd;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001646 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001647 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welteed848512018-05-24 22:27:58 +02001648 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001649 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001650 if (osmux_enabled) {
1651 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla, osmux_cid));
1652 } else {
1653 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
1654 }
Harald Welteed848512018-05-24 22:27:58 +02001655 } else {
1656 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001657 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
Harald Welteed848512018-05-24 22:27:58 +02001658 }
1659 return ass_cmd;
1660}
1661
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02001662function f_gen_handover_req(integer bssap_idx := 0, charstring aoip_tla := "1.2.3.4",
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001663 template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit,
1664 template (omit) TestHdlrEncrParams enc := omit) return PDU_BSSAP {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001665 var PDU_BSSAP ho_req;
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001666
1667 var BSSMAP_IE_EncryptionInformation encryptionInformation :=
1668 valueof(ts_BSSMAP_IE_EncrInfo('0000000000000000'O,'01'O));
1669 var template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm := omit;
1670 var template BSSMAP_IE_KC128 kc128 := omit;
1671 if (ispresent(enc)) {
1672 var TestHdlrEncrParams v_enc := valueof(enc);
1673 encryptionInformation := valueof(ts_BSSMAP_IE_EncrInfo(v_enc.enc_key, v_enc.enc_alg));
1674 chosenEncryptionAlgorithm := valueof(
1675 ts_BSSMAP_IE_ChosenEncryptionAlgorithm(int2oct(enum2int(
Oliver Smith598e1ed2021-07-09 10:28:40 +02001676 f_cipher_mode_bssmap_to_rsl(v_enc.enc_alg)), 1)));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001677 if (ispresent(v_enc.enc_kc128)) {
1678 kc128 := ts_BSSMAP_IE_Kc128(v_enc.enc_kc128);
1679 }
1680 }
1681
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001682 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001683 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001684 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001685 ho_req := valueof(ts_BSSMAP_HandoverRequest(omit, tla, oldToNewBSSIEs := oldToNewBSSIEs,
1686 encryptionInformation := encryptionInformation,
1687 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
1688 kC128 := kc128));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001689 } else {
1690 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001691 ho_req := valueof(ts_BSSMAP_HandoverRequest(cic, omit, oldToNewBSSIEs := oldToNewBSSIEs,
1692 encryptionInformation := encryptionInformation,
1693 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
1694 kC128 := kc128));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001695 }
1696 return ho_req;
1697}
1698
Harald Welteed848512018-05-24 22:27:58 +02001699/* generate an assignment complete template for either AoIP or SCCPlite */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001700function f_gen_exp_compl(boolean expect_osmux := false, integer bssap_idx := 0) return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +02001701 var template PDU_BSSAP exp_compl;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001702 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001703 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001704 if (expect_osmux) {
1705 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, osmux_cid);
1706 } else {
1707 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, omit);
1708 }
Harald Welteed848512018-05-24 22:27:58 +02001709 } else {
1710 /* CIC is optional "*" as the MSC allocated it */
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001711 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
Harald Welteed848512018-05-24 22:27:58 +02001712 }
1713 return exp_compl;
1714}
1715
Harald Welte235ebf12017-12-15 14:18:16 +01001716/* Run everything required up to sending a caller-specified assignment command and expect response */
1717function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001718runs on test_CT return DchanTuple {
Harald Welte235ebf12017-12-15 14:18:16 +01001719 var BSSAP_N_CONNECT_ind rx_c_ind;
1720 var RSL_Message rx_rsl;
1721 var DchanTuple dt;
1722
Harald Welte89d42e82017-12-17 16:42:41 +01001723 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +01001724
1725 dt := f_est_dchan('23'O, 23, '00000000'O);
1726 /* send assignment without AoIP IEs */
1727 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
1728 alt {
1729 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1730 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
1731 setverdict(pass);
1732 } else {
1733 setverdict(fail, fail_text);
1734 }
1735 }
1736 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1737 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
1738 setverdict(pass);
1739 } else {
1740 setverdict(fail, fail_text);
1741 }
1742 }
1743 [] BSSAP.receive { repeat; }
1744 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001745 return dt;
Harald Welte235ebf12017-12-15 14:18:16 +01001746}
1747testcase TC_assignment_csd() runs on test_CT {
1748 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001749 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001750 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1751 //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 +01001752 var DchanTuple dt := f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
1753 f_perform_clear_test_ct(dt);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001754 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001755}
1756
1757testcase TC_assignment_ctm() runs on test_CT {
1758 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001759 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001760 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
1761 //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 +01001762 var DchanTuple dt := f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
1763 f_perform_clear_test_ct(dt);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001764 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001765}
1766
Harald Welte4003d112017-12-09 22:35:39 +01001767type record DchanTuple {
1768 integer sccp_conn_id,
1769 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +01001770}
1771
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +02001772type record of DchanTuple DchanTuples;
1773
Harald Welted6939652017-12-13 21:02:46 +01001774/* Send CHAN RQD and wait for allocation; acknowledge it */
1775private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
1776runs on test_CT return RslChannelNr {
1777 var RSL_Message rx_rsl;
1778 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1779 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1780 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1781 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
Daniel Willmannf4ac4ce2018-08-02 14:06:30 +02001782 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Harald Welted6939652017-12-13 21:02:46 +01001783 return chan_nr;
1784}
1785
Harald Welte4003d112017-12-09 22:35:39 +01001786/* helper function to establish a dedicated channel via BTS and MSC */
1787function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1788runs on test_CT return DchanTuple {
1789 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +01001790 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001791
Harald Welte4003d112017-12-09 22:35:39 +01001792 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001793 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +01001794
1795 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1796
1797 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1798 dt.sccp_conn_id := rx_c_ind.connectionId;
1799 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1800
1801 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001802}
1803
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02001804/* Like f_est_dchan(), but for the first lchan of a dynamic timeslot: first ACK the deactivation of PDCH. */
1805function f_est_dchan_dyn(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1806runs on test_CT return DchanTuple {
1807 var BSSAP_N_CONNECT_ind rx_c_ind;
1808 var DchanTuple dt;
1809
1810 /* Send CHAN RQD */
1811 var RSL_Message rx_rsl;
1812 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1813
1814 /* The dyn TS first deactivates PDCH */
1815 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1816 dt.rsl_chan_nr := rx_rsl.ies[0].body.chan_nr;
1817 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1818
1819 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1820 dt.rsl_chan_nr := rx_rsl.ies[0].body.chan_nr;
1821
1822 /* Now activates the signalling channel */
1823 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, fn+10));
1824 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
1825
1826 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1827
1828 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1829 dt.sccp_conn_id := rx_c_ind.connectionId;
1830 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1831
1832 return dt;
1833}
1834
Harald Welte641fcbe2018-06-14 10:58:35 +02001835/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
1836private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
1837 var RSL_Message rx_rsl;
1838 /* expect BSC to disable the channel */
1839 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1840 /* respond with CHAN REL ACK */
1841 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1842
1843 /* expect Clear Complete from BSC */
1844 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1845
1846 /* MSC disconnects as instructed. */
1847 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1848}
1849
Harald Welte4003d112017-12-09 22:35:39 +01001850/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
1851testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001852 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001853 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +01001854
Harald Welte89d42e82017-12-17 16:42:41 +01001855 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +01001856
Harald Welte4003d112017-12-09 22:35:39 +01001857 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1858
1859 /* simulate RLL REL IND */
1860 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
1861
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001862 /* expect Clear Request on MSC side */
1863 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1864
1865 /* Instruct BSC to clear channel */
1866 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1867 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1868
Harald Welte4003d112017-12-09 22:35:39 +01001869 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001870 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001871
1872 /* wait for SCCP emulation to do its job */
1873 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +01001874
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001875 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001876}
1877
1878/* Test behavior of channel release after CONN FAIL IND from BTS */
1879testcase TC_chan_rel_conn_fail() runs on test_CT {
1880 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001881 var DchanTuple dt;
1882
Harald Welte89d42e82017-12-17 16:42:41 +01001883 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001884
1885 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1886
1887 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +01001888 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 +01001889 /* TODO: different cause values? */
1890
Harald Welte4003d112017-12-09 22:35:39 +01001891 /* expect Clear Request from BSC */
1892 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1893
1894 /* Instruct BSC to clear channel */
1895 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1896 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1897
Harald Welte6ff76ea2018-01-28 13:08:01 +01001898 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001899 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +01001900
1901 /* wait for SCCP emulation to do its job */
1902 f_sleep(1.0);
1903
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001904 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001905}
1906
Harald Welte99f3ca02018-06-14 13:40:29 +02001907/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
1908/* See also https://www.osmocom.org/issues/3182 */
1909testcase TC_early_conn_fail() runs on test_CT {
1910 var RSL_Message rx_rsl;
1911 var DchanTuple dt;
1912
1913 f_init(1);
1914
1915 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
Harald Weltec46ea3c2020-10-10 18:46:12 +02001916 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_ra_cs(), 23);
Harald Welte99f3ca02018-06-14 13:40:29 +02001917
1918 /* BTS->BSC: simulate CONN FAIL IND */
1919 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1920
1921 /* BTS->BSC: Expect RF channel release from BSC on Abis */
1922 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1923
1924 /* BTS<-BSC: respond with CHAN REL ACK */
1925 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1926
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001927 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001928}
1929
1930/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
1931/* See also https://www.osmocom.org/issues/3182 */
1932testcase TC_late_conn_fail() runs on test_CT {
1933 var RSL_Message rx_rsl;
1934 var DchanTuple dt;
1935
1936 f_init(1);
1937
1938 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1939
1940 /* BSC<-MSC: Instruct BSC to clear connection */
1941 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
1942
1943 /* BTS->BSC: expect BSC to deactivate SACCH */
1944 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
1945
1946 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
1947 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1948
1949 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
1950 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1951 /* BTS->BSC: respond with CHAN REL ACK */
1952 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1953
1954 /* BSC->MSC: expect Clear Complete from BSC */
1955 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1956
1957 /* BSC<-MSC: MSC disconnects as requested. */
1958 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1959
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001960 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001961}
1962
Oliver Smithaf03bef2021-08-24 15:34:51 +02001963private function f_TC_stats_conn_fail(charstring id) runs on MSC_ConnHdlr {
1964 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
1965 var PDU_BSSAP ass_cmd := f_gen_ass_req();
1966
1967 f_statsd_reset();
1968
1969 /* Establish SDCCH */
1970 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1971 f_establish_fully(ass_cmd, exp_fail);
1972
1973 /* Expect stats to be 0 */
1974 var StatsDExpects expect := {
1975 {name := "TTCN3.bts.0.chan.rf_fail", mtype := "c", min := 0, max := 0},
1976 {name := "TTCN3.bts.0.chan.rf_fail_sdcch", mtype := "c", min := 0, max := 0}
1977 };
1978 f_statsd_expect(expect);
1979
1980 /* Simulate CONN FAIL IND on SDCCH */
1981 RSL.send(ts_ASP_RSL_UD(
1982 ts_RSL_CONN_FAIL_IND(g_chan_nr, RSL_ERR_RADIO_LINK_FAIL),
1983 IPAC_PROTO_RSL_TRX0));
1984
Neels Hofmeyr58be48a2021-09-07 18:39:21 +02001985 f_sleep(1.0);
1986
Oliver Smithaf03bef2021-08-24 15:34:51 +02001987 /* Expect stats to be 1 */
1988 expect := {
1989 {name := "TTCN3.bts.0.chan.rf_fail", mtype := "c", min := 1, max := 1},
1990 {name := "TTCN3.bts.0.chan.rf_fail_sdcch", mtype := "c", min := 1, max := 1}
1991 };
1992 f_statsd_expect(expect);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001993 BSSAP.receive(tr_BSSMAP_ClearRequest);
1994 f_perform_clear();
Oliver Smithaf03bef2021-08-24 15:34:51 +02001995}
1996testcase TC_stats_conn_fail() runs on test_CT {
1997 var TestHdlrParams pars := f_gen_test_hdlr_pars();
1998 var MSC_ConnHdlr vc_conn;
1999
2000 f_init(1, true);
2001 f_sleep(1.0);
2002
2003 vc_conn := f_start_handler(refers(f_TC_stats_conn_fail), pars);
2004 vc_conn.done;
2005
2006 f_shutdown_helper();
2007}
2008
Neels Hofmeyrf44ccd12018-11-05 19:15:23 +01002009function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr,
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002010 boolean expect_deact_sacch := true,
2011 boolean expect_rr_chan_rel := true,
2012 boolean expect_rll_rel_req := true,
Harald Welte99787102019-02-04 10:41:36 +01002013 boolean handle_rll_rel := true,
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002014 template CellSelIndValue expect_cells := omit,
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002015 template RR_Cause expect_rr_cause := ?
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002016 ) runs on test_CT {
Harald Welte91d54a52018-01-28 15:35:07 +01002017
2018 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002019 var boolean got_deact_sacch := false;
2020 var boolean got_rr_chan_rel := false;
2021 var boolean got_rll_rel_req := false;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002022 var ASP_RSL_Unitdata ud;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002023 var RSL_IE_Body l3_ie;
2024 var PDU_ML3_NW_MS l3;
2025 var RR_Cause got_cause;
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002026 log("f_expect_chan_rel() expecting: expect_deact_sacch=", expect_deact_sacch, " expect_rr_chan_rel=", expect_rr_chan_rel,
2027 " expect_rll_rel_req=", expect_rll_rel_req);
Harald Welte91d54a52018-01-28 15:35:07 +01002028 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002029 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002030 got_deact_sacch := true;
Harald Welte91d54a52018-01-28 15:35:07 +01002031 repeat;
2032 }
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002033 [not istemplatekind(expect_cells, "omit")] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_DATA_REQ(rsl_chan_nr, ?, decmatch tr_RRM_RR_RELEASE_CellSelectInd))) -> value ud {
Harald Welte99787102019-02-04 10:41:36 +01002034 got_rr_chan_rel := true;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002035
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002036 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
2037 setverdict(fail, "cannot find L3");
2038 mtc.stop;
2039 }
2040 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
2041
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002042 if (not istemplatekind(expect_cells, "omit")) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002043 var CellSelIndValue cells := dec_CellSelIndValue(
2044 l3.msgs.rrm.channelRelease.cellSelectionIndicator.cellSelectionIndicatorValue);
2045
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002046 log("GOT RR CHANNEL RELEASE WITH CELLS: ", cells);
2047 if (match(cells, expect_cells)) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002048 setverdict(pass);
2049 } else {
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002050 log("EXPECTED CELLS: ", expect_cells);
2051 setverdict(fail, "Received cells list on RR Channel Release does not match expectations");
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002052 }
2053 }
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002054
2055 if (not istemplatekind(expect_rr_cause, "omit")) {
2056 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
2057 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
2058 if (match(got_cause, expect_rr_cause)) {
2059 setverdict(pass);
2060 } else {
2061 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
2062 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
2063 }
2064 }
Harald Welte99787102019-02-04 10:41:36 +01002065 repeat;
2066 }
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002067 [istemplatekind(expect_cells, "omit")] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_DATA_REQ(rsl_chan_nr, ?, decmatch tr_RRM_RR_RELEASE))) -> value ud {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002068 got_rr_chan_rel := true;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002069
2070 if (not istemplatekind(expect_rr_cause, "omit")) {
2071 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
2072 setverdict(fail, "cannot find L3");
2073 mtc.stop;
2074 }
2075 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
2076
2077 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
2078 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
2079 if (match(got_cause, expect_rr_cause)) {
2080 setverdict(pass);
2081 } else {
2082 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
2083 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
2084 }
2085 }
Neels Hofmeyr211169d2018-11-07 00:37:29 +01002086 repeat;
2087 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002088 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002089 got_rll_rel_req := true;
Harald Welte91d54a52018-01-28 15:35:07 +01002090 /* FIXME: Why are we getting this for LinkID SACCH? */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002091 if (handle_rll_rel) {
2092 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
2093 }
Harald Welte91d54a52018-01-28 15:35:07 +01002094 repeat;
2095 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002096 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Harald Welte91d54a52018-01-28 15:35:07 +01002097 /* respond with CHAN REL ACK */
2098 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
2099 }
2100 /* ignore any user data */
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002101 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeR(?))) {
Harald Welte91d54a52018-01-28 15:35:07 +01002102 repeat;
2103 }
2104 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002105
2106 log("f_expect_chan_rel() summary: got_deact_sacch=", got_deact_sacch, " got_rr_chan_rel=", got_rr_chan_rel,
2107 " got_rll_rel_req=", got_rll_rel_req);
2108
2109 if (expect_deact_sacch != got_deact_sacch) {
2110 setverdict(fail, "f_expect_chan_rel(): expect_deact_sacch=", expect_deact_sacch, " got_deact_sacch=", got_deact_sacch);
2111 }
2112 if (expect_rr_chan_rel != got_rr_chan_rel) {
2113 setverdict(fail, "f_expect_chan_rel(): expect_rr_chan_rel=", expect_rr_chan_rel, " got_rr_chan_rel=", got_rr_chan_rel);
2114 }
2115 if (expect_rll_rel_req != got_rll_rel_req) {
2116 setverdict(fail, "f_expect_chan_rel(): expect_rll_rel_req=", expect_rll_rel_req, " got_rll_rel_req=", got_rll_rel_req);
2117 }
Harald Welte91d54a52018-01-28 15:35:07 +01002118}
2119
Harald Welte4003d112017-12-09 22:35:39 +01002120/* Test behavior of channel release after hard Clear Command from MSC */
2121testcase TC_chan_rel_hard_clear() runs on test_CT {
2122 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01002123 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +01002124
Harald Welte89d42e82017-12-17 16:42:41 +01002125 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002126
2127 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2128
2129 /* Instruct BSC to clear channel */
2130 var BssmapCause cause := 0;
2131 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2132
2133 /* expect Clear Complete from BSC on A */
2134 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2135 /* release the SCCP connection */
2136 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2137 }
2138
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002139 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002140 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002141}
2142
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002143function f_TC_chan_rel_last_eutran_plmn_hard_clear(boolean tx_csfb_ind) runs on test_CT {
2144 var BSSAP_N_DATA_ind rx_di;
2145 var DchanTuple dt;
2146
2147 f_init(1);
2148
2149 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2150 /* Send CommonID with some random PLMN (BSC doesn't take it into account
2151 /* yet when generating the EUTRAN neigh list in RR CHannel Release) */
2152 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
2153
2154 /* Instruct BSC to clear channel */
2155 var BssmapCause cause := 0;
2156 if (tx_csfb_ind) {
2157 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2158 } else {
2159 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2160 }
2161
2162 /* expect Clear Complete from BSC on A */
2163 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2164 /* release the SCCP connection */
2165 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2166 }
2167
2168 /* 1 neighbor is added by default in osmo-bts.cfg and
2169 SystemInformationConfig_default, use that: */
2170 var template CellSelIndValue exp_cells := f_tr_rr_chan_rel_earfcns(1);
2171
2172 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, expect_cells := exp_cells);
2173 f_shutdown_helper();
2174}
2175
2176/* Test behavior of RR Channel rRelease after Clear Command without CSFB indicator
2177 from MSC, previously receiving any CommonID containing the "Last Used E-UTRAN
2178 PLMN Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
2179 EUTRAN neighbor list sent later on by BSC in RR Channel, so receiving CSFB
2180 Indicator or not shouldn't matter at all. */
2181testcase TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() runs on test_CT {
2182 f_TC_chan_rel_last_eutran_plmn_hard_clear(false);
2183}
2184
2185/* Test behavior of RR Channel rRelease after Clear Command with CSFB indicator from
2186 MSC, previously receiving any CommonID containing the "Last Used E-UTRAN PLMN
2187 Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
2188 EUTRAN neighbor list sent later on by BSC in RR Channel. */
2189testcase TC_chan_rel_last_eutran_plmn_hard_clear_csfb() runs on test_CT {
2190 f_TC_chan_rel_last_eutran_plmn_hard_clear(true);
2191}
2192
2193/* Test behavior of RR Channel Release after Clear Command with CSFB indicator from
2194 MSC, without receiving any CommonID containing the "Last Used E-UTRAN PLMN
2195 Id". According to spec (TS 48.008 version 16.0.0 Release 16 "3.2.1.21") the
2196 CSFB Indicator should not be used anymore, and hence, there should be no
2197 EUTRAN neighbor list sent by BSC in RR Channel release since no CommonId with
2198 Last Used E-UTRAN PLMN Id" IE was sent for this conn. */
Harald Welte99787102019-02-04 10:41:36 +01002199testcase TC_chan_rel_hard_clear_csfb() runs on test_CT {
2200 var BSSAP_N_DATA_ind rx_di;
2201 var DchanTuple dt;
2202
2203 f_init(1);
2204
2205 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2206
2207 /* Instruct BSC to clear channel */
2208 var BssmapCause cause := 0;
2209 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2210
2211 /* expect Clear Complete from BSC on A */
2212 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2213 /* release the SCCP connection */
2214 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2215 }
2216
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002217 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002218 f_shutdown_helper();
Harald Welte99787102019-02-04 10:41:36 +01002219}
2220
Harald Welted8c36cd2017-12-09 23:05:31 +01002221/* Test behavior of channel release after hard RLSD from MSC */
2222testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +01002223 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +01002224
Harald Welte89d42e82017-12-17 16:42:41 +01002225 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +01002226
2227 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2228
2229 /* release the SCCP connection */
2230 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2231
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002232 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002233 f_shutdown_helper();
Harald Welted8c36cd2017-12-09 23:05:31 +01002234}
2235
Harald Welte550daf92018-06-11 19:22:13 +02002236/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
2237testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
2238 var DchanTuple dt;
2239
2240 f_init(1);
2241
2242 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2243
2244 /* release the SCCP connection */
2245 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2246
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002247 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002248 f_shutdown_helper();
Harald Welte550daf92018-06-11 19:22:13 +02002249}
2250
Harald Welte85804d42017-12-10 14:11:58 +01002251/* Test behavior of channel release after BSSMAP RESET from MSC */
2252testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +01002253 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +01002254
Harald Welte89d42e82017-12-17 16:42:41 +01002255 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +01002256
2257 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2258
2259 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
2260 IPA_RSL[0].clear;
2261
2262 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002263 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 +01002264 interleave {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002265 [] 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 +01002266 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
2267 }
2268
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002269 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002270 f_shutdown_helper();
Harald Welte85804d42017-12-10 14:11:58 +01002271}
2272
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002273/* Verify T(iar) triggers and releases the channel */
2274testcase TC_chan_rel_sccp_tiar_timeout() runs on test_CT {
2275 var DchanTuple dt;
2276
2277 /* Set T(iar) in BSC low enough that it will trigger before other side
2278 has time to keep alive with a T(ias). Keep recommended ratio of
2279 T(iar) >= T(ias)*2 */
2280 g_bsc_sccp_timer_ias := 2;
2281 g_bsc_sccp_timer_iar := 5;
2282
2283 f_init(1);
2284
2285 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2286 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002287 f_shutdown_helper();
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002288}
2289
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002290private function f_tc_chan_rel_rr_cause(myBSSMAP_Cause clear_cmd_cause, template RR_Cause expect_rr_cause)
2291runs on test_CT
2292{
2293 var DchanTuple dt;
2294
2295 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2296 var BssmapCause cause := 0;
2297 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(enum2int(clear_cmd_cause))));
2298 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2299 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2300 }
2301
2302 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, expect_rr_cause := expect_rr_cause);
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002303}
2304
2305/* Test that Clear Command cause codes affect the RR Channel Release cause code */
2306testcase TC_chan_rel_rr_cause() runs on test_CT {
2307 f_init(1);
2308
2309 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_CALL_CONTROL, GSM48_RR_CAUSE_NORMAL);
2310 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_HANDOVER_SUCCESSFUL, GSM48_RR_CAUSE_NORMAL);
2311 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_PREEMPTION, GSM48_RR_CAUSE_PREMPTIVE_REL);
2312 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE, GSM48_RR_CAUSE_PROT_ERROR_UNSPC);
2313 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
2314 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_EQUIPMENT_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
Vadim Yanitskiye18aebb2021-01-03 13:10:43 +01002315
2316 f_shutdown_helper();
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002317}
2318
Harald Welte5cd20ed2017-12-13 21:03:20 +01002319/* Test behavior if RSL EST IND for non-active channel */
2320testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
2321 timer T := 2.0;
2322
Harald Welte89d42e82017-12-17 16:42:41 +01002323 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002324
2325 var octetstring l3 := '00010203040506'O;
2326 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2327 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
2328
2329 T.start;
2330 alt {
2331 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2332 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
2333 }
2334 [] BSSAP.receive {}
2335 [] IPA_RSL[0].receive {}
2336 [] T.timeout {}
2337 }
2338
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002339 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002340}
2341
2342/* Test behavior if RSL EST IND for invalid SAPI */
2343testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
2344 var RslChannelNr chan_nr;
2345
Harald Welte89d42e82017-12-17 16:42:41 +01002346 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002347
2348 chan_nr := f_chreq_act_ack()
2349
2350 var octetstring l3 := '00010203040506'O;
2351 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
2352
2353 timer T := 2.0;
2354 T.start;
2355 alt {
2356 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2357 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
2358 }
2359 [] BSSAP.receive { repeat; }
2360 [] IPA_RSL[0].receive { repeat; }
2361 [] T.timeout {}
2362 }
2363
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002364 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002365}
2366
2367/* Test behavior if RSL EST IND for invalid SAPI */
2368testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
2369 timer T := 2.0;
2370
Harald Welte89d42e82017-12-17 16:42:41 +01002371 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002372
2373 var RslChannelNr chan_nr := f_chreq_act_ack();
2374
2375 var octetstring l3 := '00010203040506'O;
2376 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
2377
2378 T.start;
2379 alt {
2380 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2381 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
2382 }
2383 [] BSSAP.receive { repeat; }
2384 [] IPA_RSL[0].receive { repeat; }
2385 [] T.timeout {}
2386 }
2387
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002388 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002389}
2390
2391/* Test behavior if RSL EST IND for invalid SACCH */
2392testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
2393 timer T := 2.0;
2394
Harald Welte89d42e82017-12-17 16:42:41 +01002395 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002396
2397 var RslChannelNr chan_nr := f_chreq_act_ack();
2398
2399 var octetstring l3 := '00010203040506'O;
2400 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
2401
2402 T.start;
2403 alt {
2404 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2405 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
2406 }
2407 [] BSSAP.receive { repeat; }
2408 [] IPA_RSL[0].receive { repeat; }
2409 [] T.timeout {}
2410 }
2411
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002412 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002413}
2414
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002415/* Verify DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
2416private function f_TC_tch_dlci_link_id_sapi(charstring id) runs on MSC_ConnHdlr {
2417 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2418 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2419
2420 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2421 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2422
2423 f_establish_fully(ass_cmd, exp_compl);
2424
2425 /* SAPI0 has already been established by f_establish_fully(), establish SAPI3 */
2426 RSL.send(ts_RSL_EST_IND(g_chan_nr, ts_RslLinkID_SACCH(3), '0904'O));
2427 /* Expect BSSAP/DTAP on SAPI3 (DLCI IE) */
2428 BSSAP.receive(PDU_BSSAP:{
2429 discriminator := '1'B,
2430 spare := '0000000'B,
2431 dlci := 'C3'O,
2432 lengthIndicator := ?,
2433 pdu := { dtap := '0904'O }
2434 });
2435
2436 /* Send messages on DCCH/SAPI0 and ACCH/SAPI3 */
2437 for (var integer i := 0; i < 32; i := i + 1) {
2438 var octetstring l3 := '09'O & f_rnd_octstring(14);
2439 var template (value) RslLinkId link_id;
2440 var template (value) OCT1 dlci;
2441
2442 if (i mod 2 == 0) {
2443 /* SAPI0 on FACCH or SDCCH */
2444 link_id := ts_RslLinkID_DCCH(0);
2445 dlci := '80'O;
2446 } else {
2447 /* SAPI3 on SACCH */
2448 link_id := ts_RslLinkID_SACCH(3);
2449 dlci := 'C3'O;
2450 }
2451
2452 /* Send MO message: RSL -> BSSAP */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002453 f_mo_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002454 /* Send MT message: BSSAP -> RSL */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002455 f_mt_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002456 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01002457 f_perform_clear();
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002458}
2459testcase TC_tch_dlci_link_id_sapi() runs on test_CT {
2460 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2461 var MSC_ConnHdlr vc_conn;
2462
2463 f_init(1, true);
2464 f_sleep(1.0);
2465
2466 vc_conn := f_start_handler(refers(f_TC_tch_dlci_link_id_sapi), pars);
2467 vc_conn.done;
2468
2469 f_shutdown_helper();
2470}
2471
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002472private function f_exp_sapi_n_reject(template (present) GsmSapi sapi := ?,
2473 template myBSSMAP_Cause cause := ?,
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002474 template (present) BIT2 cc := ?,
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002475 float T_val := 2.0)
2476runs on test_CT {
2477 var BSSAP_N_DATA_ind rx_di;
2478 timer T;
2479
2480 var template BSSMAP_IE_Cause tr_cause := tr_BSSMAP_IE_Cause(cause);
2481 var template PDU_BSSAP tr_pdu := tr_BSSMAP_SAPInReject(sapi);
2482
2483 T.start(T_val);
2484 alt {
2485 [] BSSAP.receive(tr_BSSAP_DATA_ind(?, tr_pdu)) -> value rx_di {
2486 var BSSMAP_IE_Cause rx_cause := rx_di.userData.pdu.bssmap.sAPInReject.cause;
2487 if (not match(rx_cause, tr_cause)) {
2488 setverdict(fail, "Rx unexpected Cause IE: ",
2489 rx_cause, " vs expected ", tr_cause);
2490 }
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002491
2492 /* Who ever on the earth decided to define this field as two separate bits?!? */
2493 var BIT2 rx_cc := rx_di.userData.pdu.bssmap.sAPInReject.dLCI.c2
2494 & rx_di.userData.pdu.bssmap.sAPInReject.dLCI.c1;
2495 if (not match(rx_cc, cc)) {
2496 setverdict(fail, "Rx unexpected Control Channel type: ",
2497 rx_cc, " vs expected ", cc);
2498 }
2499
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002500 setverdict(pass);
2501 }
2502 [] BSSAP.receive(BSSAP_N_DATA_ind:?) -> value rx_di {
2503 setverdict(fail, "Rx unexpected BSSAP PDU: ", rx_di);
2504 }
2505 [] T.timeout {
2506 setverdict(fail, "Timeout waiting for BSSMAP SAPI N Reject");
2507 }
2508 }
2509}
2510
2511/* Check if we get SAPI N Reject on receipt of unexpected RLL RELease INDication */
2512testcase TC_rll_rel_ind_sapi_n_reject() runs on test_CT {
2513 var octetstring rnd_data := f_rnd_octstring(16);
2514 var RSL_Message rx_rsl;
2515 var DchanTuple dt;
2516
2517 f_init(1);
2518
2519 /* MS establishes a SAPI=0 link on DCCH */
2520 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2521
2522 /* MSC sends some data on (not yet established) SAPI=3 link */
2523 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2524 /* BSC attempts to establish a SAPI=3 link on DCCH */
2525 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2526
2527 /* MS sends unexpected RELease INDication on SAPI=3 */
2528 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3)));
2529 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2530 f_exp_sapi_n_reject(3, GSM0808_CAUSE_MS_NOT_EQUIPPED);
2531
2532 /* Clean up the connection */
2533 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2534 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2535
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002536 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002537}
2538
2539/* Check if we get SAPI N Reject on receipt of unexpected RLL ERROR INDication */
2540testcase TC_rll_err_ind_sapi_n_reject() runs on test_CT {
2541 var octetstring rnd_data := f_rnd_octstring(16);
2542 var RSL_Message rx_rsl;
2543 var DchanTuple dt;
2544
2545 f_init(1);
2546
2547 /* MS establishes a SAPI=0 link on DCCH */
2548 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2549
2550 /* MSC sends some data on (not yet established) SAPI=3 link */
2551 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2552 /* BSC attempts to establish a SAPI=3 link on DCCH */
2553 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2554
2555 /* BTS sends unexpected ERROR INDication on SAPI=3 */
2556 f_ipa_tx(0, ts_RSL_ERROR_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3), ''O));
2557 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2558 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED);
2559
2560 /* Clean up the connection */
2561 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2562 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2563
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002564 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002565}
2566
2567/* Check if we get SAPI N Reject due to a SAPI=3 link establishment timeout */
2568testcase TC_rll_timeout_sapi_n_reject() runs on test_CT {
2569 var octetstring rnd_data := f_rnd_octstring(16);
2570 var RSL_Message rx_rsl;
2571 var DchanTuple dt;
2572
2573 f_init(1);
2574
2575 /* MS establishes a SAPI=0 link on DCCH */
2576 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2577
2578 /* MSC sends some data on (not yet established) SAPI=3 link */
2579 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2580 /* BSC attempts to establish a SAPI=3 link on DCCH */
2581 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2582
2583 /* MS does not respond, so the link establishment timeout triggers SAPI N Reject */
2584 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED, T_val := 8.0);
2585
2586 /* Clean up the connection */
2587 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2588 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2589
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002590 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002591}
2592
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002593/* Check DLCI CC (Control Channel type) bits in SAPI N Reject */
2594testcase TC_rll_sapi_n_reject_dlci_cc() runs on test_CT {
2595 var octetstring rnd_data := f_rnd_octstring(16);
2596 var RSL_Message rx_rsl;
2597 var DchanTuple dt;
2598
2599 f_init(1);
2600
2601 /* MS establishes a SAPI=0 link on DCCH */
2602 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2603
2604 /* MSC sends some data on (not yet established) SAPI=3 link */
2605 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2606 /* BSC attempts to establish a SAPI=3 link on DCCH */
2607 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2608
2609 /* MS sends unexpected ERROR INDication on DCCH/ACCH SAPI=3 */
2610 f_ipa_tx(0, ts_RSL_ERROR_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3), ''O));
Pau Espin Pedrol121f27f2022-01-12 12:02:10 +01002611 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED, '10'B);
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002612
2613 /* Clean up the connection */
2614 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2615 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2616
2617 f_shutdown_helper();
2618}
2619
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002620testcase TC_si_default() runs on test_CT {
2621 f_init(0);
2622 f_init_bts_and_check_sysinfo(0, expect_si := SystemInformationConfig_default);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002623 f_shutdown_helper();
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002624}
Harald Welte4003d112017-12-09 22:35:39 +01002625
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002626/* We're testing SI2quater with lists of EARFCNs. Instead of just incrementing EARFCNs, also pick some from the edges of
2627 * the entire value range. This function provides the same EARFCN numbers for the same earfcn_index */
2628private function f_test_si2quater_earfcn_by_idx(integer earfcn_index) return uint16_t
2629{
2630 select (earfcn_index) {
2631 case (0) {
2632 /* E-ARFCN 111 is already added in the osmo-bsc.cfg */
2633 return 111;
2634 }
2635 case (1) {
2636 return 1;
2637 }
2638 case (2) {
2639 return 0;
2640 }
2641 case (3) {
2642 return 65535;
2643 }
2644 case else {
2645 return 23 * (earfcn_index - 3);
2646 }
2647 }
2648}
2649
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002650function f_test_si2quater(integer total_earfcns, template SystemInformationConfig expect_si,
2651 template CellSelIndValue expect_cells := omit) runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002652
2653 f_init(0);
2654
2655 /* E-ARFCN 111 is already added in the osmo-bsc.cfg, so only add more arfcns if total_earfcns > 1 */
2656 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002657 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2658 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002659 }
2660
2661 f_init_bts_and_check_sysinfo(0, expect_si := expect_si);
2662
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002663 if (not istemplatekind(expect_cells, "omit")) {
2664 /* Also check that RR Channel Release contains these EARFCNs.
2665 * (copied code from TC_chan_rel_hard_clear_csfb) */
2666 var BSSAP_N_DATA_ind rx_di;
2667 var DchanTuple dt;
2668
2669 dt := f_est_dchan('23'O, 23, '00010203040506'O);
Pau Espin Pedrold0046312021-04-19 16:35:58 +02002670 /* Send CommonID with some random PLMN (BSC doesn't take it into account
2671 * yet when generating the EUTRAN neigh list in RR CHannel Release) */
2672 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002673
2674 /* Instruct BSC to clear channel */
2675 var BssmapCause cause := 0;
2676 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2677
2678 /* expect Clear Complete from BSC on A */
2679 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2680 /* release the SCCP connection */
2681 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2682 }
2683
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002684 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, expect_cells := expect_cells);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002685 }
2686
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002687 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002688 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list del earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))});
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002689 }
2690}
2691
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002692private function f_tr_si2quater_earfcns(integer count) return template SI2quaterRestOctetsList
2693{
2694 var template SI2quaterRestOctetsList si2quater := {};
2695 var integer si2quater_count := (count + 2) / 3;
2696
2697 for (var integer i := 0; i < count; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002698 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002699 var integer index := i / 3;
2700 var integer earfcn_index := i mod 3;
2701 if (index >= lengthof(si2quater)) {
2702 si2quater[index] := tr_SI2quaterRestOctets_EUTRAN(index := index, count := si2quater_count - 1);
2703 }
2704 si2quater[index].rel_additions.rel5.rel6.rel7.rel8.prio_eutran_params_desc.desc.eutran_params_desc.desc.repeated_neigh_cells[0].cell_desc_list[earfcn_index] := tr_EUTRAN_CellDesc_default(e_arfcn := earfcn);
2705 }
2706
2707 return si2quater;
2708}
2709
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002710private function f_tr_rr_chan_rel_earfcns(integer count) return template CellSelIndValue
2711{
2712 var template CellSelIndValue_EUTRAN_Descrs cells := {};
2713
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002714 /* the lte neighbors must match the config & vty to pass this test */
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002715 for (var integer i := 0; i < count; i := i + 1) {
2716 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002717 cells[i] := tr_CellSelIndValue_EUTRAN_Descr(earfcn, '1'B, 3);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002718 }
2719
2720 return tr_CellSelIndValue_EUTRAN(cells);
2721}
2722
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002723private function f_tc_si2quater_n_earfcns(integer n) runs on test_CT
2724{
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002725 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrol8ab62e42020-12-18 16:19:11 +01002726 sic.si2quater := f_tr_si2quater_earfcns(n);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002727 var template CellSelIndValue cells := f_tr_rr_chan_rel_earfcns(n);
2728 f_test_si2quater(n, sic, cells);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002729}
2730
2731testcase TC_si2quater_2_earfcns() runs on test_CT {
2732 f_tc_si2quater_n_earfcns(2);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002733 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002734}
2735
2736testcase TC_si2quater_3_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002737 f_tc_si2quater_n_earfcns(3);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002738 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002739}
2740
2741testcase TC_si2quater_4_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002742 f_tc_si2quater_n_earfcns(4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002743 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002744}
2745
2746testcase TC_si2quater_5_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002747 f_tc_si2quater_n_earfcns(5);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002748 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002749}
2750
2751testcase TC_si2quater_6_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002752 f_tc_si2quater_n_earfcns(6);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002753 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002754}
2755
2756testcase TC_si2quater_12_earfcns() runs on test_CT {
2757 f_tc_si2quater_n_earfcns(12);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002758 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002759}
2760
2761testcase TC_si2quater_23_earfcns() runs on test_CT {
2762 f_tc_si2quater_n_earfcns(23);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002763 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002764}
2765
2766testcase TC_si2quater_32_earfcns() runs on test_CT {
2767 f_tc_si2quater_n_earfcns(32);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002768 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002769}
2770
2771testcase TC_si2quater_33_earfcns() runs on test_CT {
2772 f_tc_si2quater_n_earfcns(33);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002773 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002774}
2775
2776testcase TC_si2quater_42_earfcns() runs on test_CT {
2777 f_tc_si2quater_n_earfcns(42);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002778 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002779}
2780
2781testcase TC_si2quater_48_earfcns() runs on test_CT {
2782 f_tc_si2quater_n_earfcns(48);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002783 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002784}
2785
2786/* verify the VTY error response when adding too many EARFCNs, and showing that osmo-bsc still sends 16 SI2quater with
2787 * 48 EARFCNs. */
2788testcase TC_si2quater_49_earfcns() runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002789 var template SystemInformationConfig sic := SystemInformationConfig_default;
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002790 sic.si2quater := f_tr_si2quater_earfcns(48); /* 48, not 49! */
2791 f_init(0);
2792
2793 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002794 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2795 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002796 }
2797
2798 /* The 49th EARFCN no longer fits, expect VTY error */
2799 f_vty_enter_cfg_bts(BSCVTY, 0);
2800 var charstring vty_error;
2801 vty_error := f_vty_transceive_ret(BSCVTY,
2802 "si2quater neighbor-list add earfcn 70 thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3")
2803 f_vty_transceive(BSCVTY, "end");
2804
2805 if (f_strstr(vty_error, "Unable to add ARFCN 70") >= 0) {
2806 log("Got expected VTY error: ", vty_error);
2807 setverdict(pass);
2808 } else {
2809 setverdict(fail, "Expected the 49th EUTRAN ARFCN to be rejected by vty config, got: ", vty_error);
2810 }
2811
2812 f_init_bts_and_check_sysinfo(0, expect_si := sic);
2813
2814 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002815 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list del earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))});
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002816 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002817 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002818}
2819
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002820private function f_acc09_count_allowed(AccessControlClass acc) return uint8_t
2821{
2822 var uint8_t count := 0;
2823 for (var integer i := 5; i < 16; i := i + 1) {
2824 if (acc[i] == '0'B) { /* the list marks barred, we count allowed */
2825 count := count + 1;
2826 }
2827 }
2828 return count;
2829}
2830
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002831private function f_recv_next_si1(integer rsl_idx := 0) runs on test_CT return SystemInformationType1
2832{
2833 var ASP_RSL_Unitdata rx_rsl_ud;
2834 var SystemInformationType1 last_si1;
2835
2836 timer T := 30.0;
2837 T.start;
2838 alt {
2839 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD((tr_RSL_NO_BCCH_INFO,
2840 tr_RSL_BCCH_INFO,
2841 tr_RSL_NO_SACCH_FILL,
2842 tr_RSL_SACCH_FILL))
2843 ) -> value rx_rsl_ud {
2844 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
2845 if (g_system_information[rsl_idx].si1 == omit) {
2846 repeat;
2847 }
2848 last_si1 := g_system_information[rsl_idx].si1;
2849 g_system_information[rsl_idx].si1 := omit;
2850 T.stop;
2851 }
Vadim Yanitskiy79ebd5e2021-01-04 00:12:55 +01002852 [] IPA_RSL[rsl_idx].receive { repeat; }
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002853 [] T.timeout { setverdict(fail, "Timeout receiving next SI1"); }
2854 }
2855 return last_si1;
2856}
2857
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002858/* verify ACC rotate feature */
2859testcase TC_si_acc_rotate() runs on test_CT {
2860 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002861 var SystemInformationType1 last_si1;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002862 var AccessControlClass acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002863 var uint8_t count;
2864 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2865
2866 f_init(0, guard_timeout := 60.0);
2867
2868 f_bts_0_cfg(BSCVTY, {"rach access-control-class 5 barred",
2869 "access-control-class-rotate 3",
2870 "access-control-class-rotate-quantum 1"});
2871
2872 /* Init and get first sysinfo */
2873 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2874
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002875 for (var integer i:= 0; i < 20; i := i + 1) {
2876 last_si1 := f_recv_next_si1(0);
2877 acc := last_si1.rach_control.acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002878 count := f_acc09_count_allowed(acc);
2879 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2880
2881 if (count != 3) {
2882 log("RSL: EXPECTED SI ACC len=3");
2883 setverdict(fail, "received SI does not match expectations");
2884 break;
2885 }
2886
2887 for (var integer j := 0; j < 10; j := j + 1) {
2888 if (acc[16 - 1 - j] == '0'B) { /* the list marks barred, we count allowed */
2889 times_allowed[j] := times_allowed[j] + 1;
2890 }
2891 }
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002892 }
2893
2894 for (var integer j := 0; j < 10; j := j + 1) {
2895 log("ACC", j, " allowed ", times_allowed[j], " times" );
2896 if (j != 5 and times_allowed[j] < 3) {
2897 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " < 1 times");
2898 } else if (j == 5 and times_allowed[j] > 0) {
2899 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " > 0 times");
2900 }
2901 }
2902
2903 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2904 "rach access-control-class 5 allowed"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002905 f_shutdown_helper();
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002906}
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002907
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002908/* verify ACC startup ramp+rotate feature */
2909testcase TC_si_acc_ramp_rotate() runs on test_CT {
2910 var template SystemInformationConfig sic := SystemInformationConfig_default;
2911 var SystemInformationType1 last_si1;
2912 var AccessControlClass acc;
2913 var ASP_RSL_Unitdata rx_rsl_ud;
2914 var uint8_t count;
2915 var uint8_t prev_count;
2916 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2917
2918 f_init(0, guard_timeout := 80.0);
2919
2920 f_bts_0_cfg(BSCVTY, {"rach access-control-class 4 barred",
2921 "access-control-class-rotate 0",
2922 "access-control-class-rotate-quantum 1",
2923 "access-control-class-ramping",
2924 "access-control-class-ramping-step-interval 5",
2925 "access-control-class-ramping-step-size 5"});
2926
2927 /* Init and get first sysinfo */
2928 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2929 last_si1 := g_system_information[0].si1;
2930 acc := last_si1.rach_control.acc;
2931 count := f_acc09_count_allowed(acc);
2932 /* Adm subset size was set to 0 above, so wait until all ACC are barred */
2933 while (count > 0) {
2934 last_si1 := f_recv_next_si1(0);
2935 acc := last_si1.rach_control.acc;
2936 count := f_acc09_count_allowed(acc);
2937 log("RSL: wait len()=0: GOT SI1 ACC len=", count, ": ", acc);
2938 }
2939
2940 /* Increase adm subset size, we should see ramping start up */
2941 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10"});
2942 prev_count := 0;
2943 while (true) {
2944 last_si1 := f_recv_next_si1(0);
2945 acc := last_si1.rach_control.acc;
2946 count := f_acc09_count_allowed(acc);
2947 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2948
2949 if (prev_count > count) {
2950 setverdict(fail, "ACC allowed count dropped while expecting grow: ", prev_count, " -> ", count);
2951 break;
2952 }
2953
2954 if (count == 9) {
2955 break; /* Maximum reached (10 - 1 perm barred), done here */
2956 }
2957
2958 prev_count := count;
2959 }
2960
2961 setverdict(pass);
2962
2963 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2964 "rach access-control-class 4 allowed",
2965 "no access-control-class-ramping"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002966 f_shutdown_helper();
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002967}
2968
Harald Welte4003d112017-12-09 22:35:39 +01002969testcase TC_ctrl_msc_connection_status() runs on test_CT {
2970 var charstring ctrl_resp;
2971
Harald Welte89d42e82017-12-17 16:42:41 +01002972 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002973
2974 /* See https://osmocom.org/issues/2729 */
2975 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002976 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002977}
2978
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002979testcase TC_ctrl_msc0_connection_status() runs on test_CT {
2980 var charstring ctrl_resp;
2981
2982 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002983
2984 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002985 f_shutdown_helper();
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002986}
2987
Neels Hofmeyr0bc470d2021-08-21 13:37:13 +02002988/* Verify correct stats on the number of configured and connected MSCs */
2989private function f_tc_stat_num_msc_connected_msc_connhdlr(integer expect_num_msc_connected) runs on MSC_ConnHdlr {
2990 g_pars := f_gen_test_hdlr_pars();
2991 var StatsDExpects expect := {
2992 { name := "TTCN3.bsc.0.num_msc.connected", mtype := "g", min := expect_num_msc_connected, max := expect_num_msc_connected },
2993 { name := "TTCN3.bsc.0.num_msc.total", mtype := "g", min := NUM_MSC, max := NUM_MSC }
2994 };
2995 f_statsd_expect(expect);
2996}
2997
2998private function f_tc_stat_num_msc_connected_test_ct(void_fn tc_fn, integer nr_msc) runs on test_CT
2999{
3000 var MSC_ConnHdlr vc_conn;
3001
3002 f_init(nr_bts := 1, handler_mode := true, nr_msc := nr_msc);
3003 f_sleep(1.0);
3004 vc_conn := f_start_handler(tc_fn);
3005 vc_conn.done;
3006
3007 /* Also verify stat exposed on CTRL interface */
3008 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_msc:connected", int2str(nr_msc));
3009 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_msc:total", int2str(NUM_MSC));
3010
3011 f_shutdown_helper();
3012}
3013
3014/* Verify that when 1 MSC is active, that num_msc:connected reports 1. */
3015private function f_tc_stat_num_msc_connected_1(charstring id) runs on MSC_ConnHdlr {
3016 f_tc_stat_num_msc_connected_msc_connhdlr(1);
3017}
3018testcase TC_stat_num_msc_connected_1() runs on test_CT {
3019 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_1), 1);
3020}
3021
3022/* Verify that when 2 MSCs are active, that num_msc:connected reports 2. */
3023private function f_tc_stat_num_msc_connected_2(charstring id) runs on MSC_ConnHdlr {
3024 f_tc_stat_num_msc_connected_msc_connhdlr(2);
3025}
3026testcase TC_stat_num_msc_connected_2() runs on test_CT {
3027 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_2), 2);
3028}
3029
3030/* Verify that when 3 MSCs are active, that num_msc:connected reports 3. */
3031private function f_tc_stat_num_msc_connected_3(charstring id) runs on MSC_ConnHdlr {
3032 f_tc_stat_num_msc_connected_msc_connhdlr(3);
3033}
3034testcase TC_stat_num_msc_connected_3() runs on test_CT {
3035 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_3), 3);
3036}
3037
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +02003038/* Verify correct stats on the number of configured and connected MSCs */
3039private function f_tc_stat_num_bts_connected_msc_connhdlr(integer expect_num_bts_connected) runs on MSC_ConnHdlr {
3040 g_pars := f_gen_test_hdlr_pars();
3041 var StatsDExpects expect := {
3042 { name := "TTCN3.bsc.0.num_bts.oml_connected", mtype := "g", min := expect_num_bts_connected, max := NUM_BTS_CFG },
3043 { name := "TTCN3.bsc.0.num_bts.all_trx_rsl_connected", mtype := "g", min := expect_num_bts_connected, max := expect_num_bts_connected },
3044 { name := "TTCN3.bsc.0.num_bts.total", mtype := "g", min := NUM_BTS_CFG, max := NUM_BTS_CFG },
3045 { name := "TTCN3.bsc.0.num_trx.rsl_connected", mtype := "g", min := expect_num_bts_connected, max := expect_num_bts_connected },
3046 { name := "TTCN3.bsc.0.num_trx.total", mtype := "g", min := NUM_BTS_CFG, max := NUM_BTS_CFG }
3047 };
3048 f_statsd_expect(expect);
3049}
3050
3051private function f_tc_stat_num_bts_connected_test_ct(void_fn tc_fn, integer nr_bts) runs on test_CT {
3052 var MSC_ConnHdlr vc_conn;
3053
3054 f_init(nr_bts := nr_bts, handler_mode := true, nr_msc := 1);
3055 f_sleep(1.0);
3056 vc_conn := f_start_handler(tc_fn);
3057 vc_conn.done;
3058
3059 /* Also verify stat exposed on CTRL interface */
3060 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_bts:all_trx_rsl_connected", int2str(nr_bts));
3061 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_bts:total", int2str(NUM_BTS_CFG));
3062 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_trx:rsl_connected", int2str(nr_bts));
3063 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_trx:total", int2str(NUM_BTS_CFG));
3064
Neels Hofmeyra41ae302021-09-06 22:06:02 +02003065 /* Verify rf_states exposed on CTRL interface */
3066 var charstring expect_net_rf_states := "";
3067 for (var integer i := 0; i < NUM_BTS_CFG; i := i + 1) {
3068 var charstring expect_bts_rf_states := int2str(i) & ",0,";
3069 if (i < NUM_BTS) {
3070 /* In these tests, OML for the first NUM_BTS are always connected via osmo-bts-omldummy */
3071 expect_bts_rf_states := expect_bts_rf_states & "operational,unlocked,";
3072 } else {
3073 /* For remaining i < NUM_BTS_CFG, OML is not connected, i.e. inoperational */
3074 expect_bts_rf_states := expect_bts_rf_states & "inoperational,locked,";
3075 }
3076 /* The RF policy is still global in osmo-bsc, i.e. always "on" */
3077 expect_bts_rf_states := expect_bts_rf_states & "on,";
3078 if (i < nr_bts) {
3079 /* For BTS where RSL is connected, the RSL state will be "up" */
3080 expect_bts_rf_states := expect_bts_rf_states & "rsl-up;";
3081 } else {
3082 expect_bts_rf_states := expect_bts_rf_states & "rsl-down;";
3083 }
3084
3085 f_ctrl_get_exp(IPA_CTRL, "bts." & int2str(i) & ".rf_states", expect_bts_rf_states);
3086 expect_net_rf_states := expect_net_rf_states & expect_bts_rf_states;
3087 }
3088 f_ctrl_get_exp(IPA_CTRL, "rf_states", expect_net_rf_states);
3089
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +02003090 f_shutdown_helper();
3091}
3092
3093/* Verify that when 1 BTS is connected, that num_{bts,trx}:*_connected reports 1. */
3094private function f_tc_stat_num_bts_connected_1(charstring id) runs on MSC_ConnHdlr {
3095 f_tc_stat_num_bts_connected_msc_connhdlr(1);
3096}
3097testcase TC_stat_num_bts_connected_1() runs on test_CT {
3098 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_1), 1);
3099}
3100
3101/* Verify that when 2 BTS is connected, that num_{bts,trx}:*_connected reports 2. */
3102private function f_tc_stat_num_bts_connected_2(charstring id) runs on MSC_ConnHdlr {
3103 f_tc_stat_num_bts_connected_msc_connhdlr(2);
3104}
3105testcase TC_stat_num_bts_connected_2() runs on test_CT {
3106 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_2), 2);
3107}
3108
3109/* Verify that when 3 BTS is connected, that num_{bts,trx}:*_connected reports 3. */
3110private function f_tc_stat_num_bts_connected_3(charstring id) runs on MSC_ConnHdlr {
3111 f_tc_stat_num_bts_connected_msc_connhdlr(3);
3112}
3113testcase TC_stat_num_bts_connected_3() runs on test_CT {
3114 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_3), 3);
3115}
3116
Harald Welte4003d112017-12-09 22:35:39 +01003117testcase TC_ctrl() runs on test_CT {
3118 var charstring ctrl_resp;
3119
Harald Welte89d42e82017-12-17 16:42:41 +01003120 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01003121
3122 /* all below values must match the osmo-bsc.cfg config file used */
3123
Harald Welte6a129692018-03-17 17:30:14 +01003124 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
3125 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Oliver Smith75aa0202019-08-19 14:17:50 +02003126 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "4");
Harald Welte4003d112017-12-09 22:35:39 +01003127
3128 var integer bts_nr := 0;
3129 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
3130 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
3131 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
3132 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
3133 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
3134 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
3135 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
3136
3137 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
3138 f_sleep(2.0);
3139 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
3140 setverdict(fail, "oml-uptime not incrementing as expected");
3141 }
3142 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
3143
3144 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
3145
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003146 f_shutdown_helper();
Harald Welte96c94412017-12-09 03:12:45 +01003147}
3148
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02003149/* Verify that Upon receival of SET "location", BSC forwards a TRAP
3150 "location-state" over the SCCPlite IPA conn */
3151testcase TC_ctrl_location() runs on test_CT {
3152 var MSC_ConnHdlr vc_conn;
3153 var integer bts_nr := 0;
3154
3155 f_init(1, true);
3156 f_sleep(1.0);
3157
3158 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234567,fix3d,0.340000,0.560000,0.780000");
3159 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
3160 "1234567,fix3d,0.340000,0.560000,0.780000,operational,unlocked,on,001,01");
3161
3162 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "1");
3163 f_sleep(2.0);
3164
3165 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234888,fix3d,0.350000,0.570000,0.790000");
3166 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
3167 "1234888,fix3d,0.350000,0.570000,0.790000,operational,locked,off,001,01");
3168
3169 /* should match the one from config */
3170 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "0");
3171
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003172 f_shutdown_helper();
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02003173}
3174
Harald Welte6f521d82017-12-11 19:52:02 +01003175
3176/***********************************************************************
3177 * Paging Testing
3178 ***********************************************************************/
3179
3180type record Cell_Identity {
3181 GsmMcc mcc,
3182 GsmMnc mnc,
3183 GsmLac lac,
3184 GsmCellId ci
3185};
Harald Welte24135bd2018-03-17 19:27:53 +01003186private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01003187private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01003188
Harald Welte5d1a2202017-12-13 19:51:29 +01003189type set of integer BtsIdList;
3190
3191private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
3192 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
3193 if (bts_id == bts_ids[j]) {
3194 return true;
3195 }
3196 }
3197 return false;
3198}
Harald Welte6f521d82017-12-11 19:52:02 +01003199
3200/* core paging test helper function; used by most paging test cases */
3201private function f_pageing_helper(hexstring imsi,
3202 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01003203 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01003204 template RSL_ChanNeeded rsl_chneed := omit,
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003205 template (omit) OCT4 tmsi := omit) runs on test_CT
Harald Welte6f521d82017-12-11 19:52:02 +01003206{
3207 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003208 var template MobileIdentityV mi;
Harald Welte6f521d82017-12-11 19:52:02 +01003209 var RSL_Message rx_rsl;
3210 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01003211 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01003212
3213 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01003214
3215 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01003216 for (i := 0; i < NUM_BTS; i := i + 1) {
3217 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01003218 }
Harald Welte6f521d82017-12-11 19:52:02 +01003219
3220 if (isvalue(rsl_chneed)) {
3221 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
3222 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
3223 } else {
3224 bssmap_chneed := omit;
3225 }
3226
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003227 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[0].sccp_addr_peer, g_bssap[0].sccp_addr_own,
3228 ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed)));
Harald Welte6f521d82017-12-11 19:52:02 +01003229
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003230 if (not istemplatekind(tmsi, "omit")) {
3231 mi := t_MI_TMSI(tmsi);
Harald Welte6f521d82017-12-11 19:52:02 +01003232 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003233 mi := tr_MI_IMSI(imsi);
Harald Welte6f521d82017-12-11 19:52:02 +01003234 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003235
Harald Welte5d1a2202017-12-13 19:51:29 +01003236 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003237 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(mi));
Harald Welte5d1a2202017-12-13 19:51:29 +01003238 /* check channel type, paging group */
3239 if (rx_rsl.ies[1].body.paging_group != paging_group) {
3240 setverdict(fail, "Paging for wrong paging group");
3241 }
3242 if (ispresent(rsl_chneed) and
3243 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
3244 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
3245 }
Harald Welte6f521d82017-12-11 19:52:02 +01003246 }
Harald Welte2fccd982018-01-31 15:48:19 +01003247 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01003248 /* do a quick check on all not-included BTSs if they received paging */
3249 for (i := 0; i < NUM_BTS; i := i + 1) {
3250 timer T := 0.1;
3251 if (f_bts_in_list(i, bts_ids)) {
3252 continue;
3253 }
3254 T.start;
3255 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003256 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(mi))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003257 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
3258 }
3259 [] IPA_RSL[i].receive { repeat; }
3260 [] T.timeout { }
3261 }
Harald Welte6f521d82017-12-11 19:52:02 +01003262 }
3263
3264 setverdict(pass);
3265}
3266
Harald Welte5d1a2202017-12-13 19:51:29 +01003267const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01003268const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01003269const BtsIdList c_BtsId_LAC1 := { 0, 1 };
3270const BtsIdList c_BtsId_LAC2 := { 2 };
3271
Harald Welte6f521d82017-12-11 19:52:02 +01003272/* PAGING by IMSI + TMSI */
3273testcase TC_paging_imsi_nochan() runs on test_CT {
3274 var BSSMAP_FIELD_CellIdentificationList cid_list;
3275 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01003276 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003277 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003278}
3279
3280/* PAGING by IMSI + TMSI */
3281testcase TC_paging_tmsi_nochan() runs on test_CT {
3282 var BSSMAP_FIELD_CellIdentificationList cid_list;
3283 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003284 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003285 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003286}
3287
3288/* Paging with different "channel needed' values */
3289testcase TC_paging_tmsi_any() runs on test_CT {
3290 var BSSMAP_FIELD_CellIdentificationList cid_list;
3291 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003292 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003293 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003294}
3295testcase TC_paging_tmsi_sdcch() runs on test_CT {
3296 var BSSMAP_FIELD_CellIdentificationList cid_list;
3297 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003298 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003299 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003300}
3301testcase TC_paging_tmsi_tch_f() runs on test_CT {
3302 var BSSMAP_FIELD_CellIdentificationList cid_list;
3303 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003304 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003305 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003306}
3307testcase TC_paging_tmsi_tch_hf() runs on test_CT {
3308 var BSSMAP_FIELD_CellIdentificationList cid_list;
3309 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003310 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003311 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003312}
3313
3314/* Paging by CGI */
3315testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
3316 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3317 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003318 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003319 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003320}
3321
3322/* Paging by LAC+CI */
3323testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
3324 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3325 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003326 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003327 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003328}
3329
3330/* Paging by CI */
3331testcase TC_paging_imsi_nochan_ci() runs on test_CT {
3332 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3333 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003334 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003335 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003336}
3337
3338/* Paging by LAI */
3339testcase TC_paging_imsi_nochan_lai() runs on test_CT {
3340 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3341 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003342 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003343 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003344}
3345
3346/* Paging by LAC */
3347testcase TC_paging_imsi_nochan_lac() runs on test_CT {
3348 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3349 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003350 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003351 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003352}
3353
3354/* Paging by "all in BSS" */
3355testcase TC_paging_imsi_nochan_all() runs on test_CT {
3356 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3357 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01003358 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003359 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003360}
3361
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003362/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003363testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
3364 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3365 cid_list := { cIl_PLMN_LAC_RNC := { ts_BSSMAP_CI_PLMN_LAC_RNC(cid.mcc, cid.mnc, cid.lac, 12) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003366 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003367 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003368}
Harald Welte6f521d82017-12-11 19:52:02 +01003369
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003370/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003371testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
3372 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3373 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003374 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003375 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003376}
3377
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003378/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003379testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
3380 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3381 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003382 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003383 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003384}
3385
Harald Welte6f521d82017-12-11 19:52:02 +01003386/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01003387testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
3388 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3389 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
3390 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003391 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003392}
3393
3394/* Paging on empty list: Verify none of them page */
3395testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
3396 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3397 cid_list := { cIl_LAC := { } };
3398 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003399 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003400}
3401
Stefan Sperling049a86e2018-03-20 15:51:00 +01003402/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
3403testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
3404 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3405 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
3406 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
3407 f_shutdown_helper();
3408}
3409
Harald Welte6f521d82017-12-11 19:52:02 +01003410/* Verify paging retransmission interval + count */
3411/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01003412/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01003413
Harald Weltee65d40e2017-12-13 00:09:06 +01003414/* Verify PCH load */
3415testcase TC_paging_imsi_load() runs on test_CT {
3416 var BSSMAP_FIELD_CellIdentificationList cid_list;
3417 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01003418 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01003419 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003420 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01003421
3422 /* tell BSC there is no paging space anymore */
3423 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01003424 f_sleep(0.2);
3425 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01003426
3427 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
3428 * there would be 8 retransmissions during 4 seconds */
3429 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01003430 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01003431 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003432 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Weltee65d40e2017-12-13 00:09:06 +01003433 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02003434 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01003435 }
Harald Welte2caa1062018-03-17 18:19:05 +01003436 [] T_retrans.timeout {
3437 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
3438 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
3439 T_retrans.start;
3440 repeat;
3441 }
Harald Weltee65d40e2017-12-13 00:09:06 +01003442 [] T.timeout {
3443 setverdict(pass);
3444 }
3445 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003446
3447 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01003448}
3449
Harald Welte235ebf12017-12-15 14:18:16 +01003450/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01003451testcase TC_paging_counter() runs on test_CT {
3452 var BSSMAP_FIELD_CellIdentificationList cid_list;
3453 timer T := 4.0;
3454 var integer i;
3455 var integer paging_attempted_bsc;
3456 var integer paging_attempted_bts[NUM_BTS];
Oliver Smith8b343d32021-11-26 13:01:42 +01003457 var integer paging_expired_bsc;
Harald Welte1ff69992017-12-14 12:31:17 +01003458 var integer paging_expired_bts[NUM_BTS];
3459 cid_list := valueof(ts_BSSMAP_CIL_noCell);
3460
3461 f_init();
3462
3463 /* read counters before paging */
3464 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
Oliver Smith8b343d32021-11-26 13:01:42 +01003465 if (Misc_Helpers.f_osmo_repo_is("nightly")) { /* osmo-bsc > 1.8.0 */
3466 paging_expired_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:expired");
3467 }
Harald Welte1ff69992017-12-14 12:31:17 +01003468 for (i := 0; i < NUM_BTS; i := i+1) {
3469 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
3470 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
3471 }
3472
3473 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
3474
3475 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
3476 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
3477 for (i := 0; i < NUM_BTS; i := i+1) {
3478 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
3479 paging_attempted_bts[i]+1);
3480 }
3481
3482 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
3483 f_sleep(12.0);
Oliver Smith8b343d32021-11-26 13:01:42 +01003484 if (Misc_Helpers.f_osmo_repo_is("nightly")) { /* osmo-bsc > 1.8.0 */
3485 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:expired", paging_expired_bsc+1);
3486 }
Harald Welte1ff69992017-12-14 12:31:17 +01003487 for (i := 0; i < NUM_BTS; i := i+1) {
3488 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
3489 paging_expired_bts[i]+1);
3490 }
Harald Welte1ff69992017-12-14 12:31:17 +01003491
Philipp Maier282ca4b2018-02-27 17:17:00 +01003492 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01003493}
3494
3495
Harald Welte10985002017-12-12 09:29:15 +01003496/* Verify paging stops after A-RESET */
3497testcase TC_paging_imsi_a_reset() runs on test_CT {
3498 var BSSMAP_FIELD_CellIdentificationList cid_list;
3499 timer T := 3.0;
3500 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003501 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01003502
3503 /* Perform a BSSMAP Reset and wait for ACK */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003504 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[0].sccp_addr_peer, g_bssap[0].sccp_addr_own, ts_BSSMAP_Reset(0, g_osmux_enabled)));
Harald Welte10985002017-12-12 09:29:15 +01003505 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003506 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap[0].sccp_addr_own, g_bssap[0].sccp_addr_peer, tr_BSSMAP_ResetAck(g_osmux_enabled))) { }
Harald Welte10985002017-12-12 09:29:15 +01003507 [] BSSAP.receive { repeat; }
3508 }
3509
Daniel Willmanncbef3982018-07-30 09:22:40 +02003510 /* Wait to avoid a possible race condition if a paging message is
3511 * received right before the reset ACK. */
3512 f_sleep(0.2);
3513
Harald Welte10985002017-12-12 09:29:15 +01003514 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01003515 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
3516 IPA_RSL[i].clear;
3517 }
Harald Welte10985002017-12-12 09:29:15 +01003518
3519 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
3520 T.start;
3521 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003522 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte10985002017-12-12 09:29:15 +01003523 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003524 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01003525 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003526 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003527 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003528 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003529 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003530 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003531 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003532 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003533 }
Harald Welte10985002017-12-12 09:29:15 +01003534 [] T.timeout {
3535 setverdict(pass);
3536 }
3537 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003538
3539 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01003540}
Harald Welteae026692017-12-09 01:03:01 +01003541
Philipp Maierf45824a2019-08-14 14:44:10 +02003542/* Verify how we handle unsolicited Paging Response. In case of an unsolicit
3543 * paging response we can not know which MSC is in charge, so we will blindly
3544 * pick the first configured MSC. This behavior is required in order to make
3545 * MT-CSFB calls working because in those cases the BSC can not know that the
3546 * MSC has already paged the subscriver via SGs. So any MT-CSFB call will look
3547 * like an unsolicited Paging Response to the MSC.
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003548 */
3549testcase TC_paging_resp_unsol() runs on test_CT {
3550
3551 f_init(1);
Philipp Maierf45824a2019-08-14 14:44:10 +02003552 timer T := 5.0;
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003553
3554 var BSSAP_N_CONNECT_ind rx_c_ind;
3555 var DchanTuple dt;
3556 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
Philipp Maierf45824a2019-08-14 14:44:10 +02003557 var octetstring rr_pag_resp := enc_PDU_ML3_MS_NW(l3);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003558
3559 /* Send CHAN RQD and wait for allocation; acknowledge it */
3560 dt.rsl_chan_nr := f_chreq_act_ack();
3561
3562 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
3563 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
3564
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003565
Philipp Maierf45824a2019-08-14 14:44:10 +02003566 /* Expevct a CR with a matching Paging response on the A-Interface */
3567 T.start;
3568 alt {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003569 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(rr_pag_resp))) -> value rx_c_ind {
Philipp Maierf45824a2019-08-14 14:44:10 +02003570 setverdict(pass);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003571 dt.sccp_conn_id := rx_c_ind.connectionId;
3572 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
Philipp Maierf45824a2019-08-14 14:44:10 +02003573 }
3574 [] BSSAP.receive {
3575 setverdict(fail, "Received unexpected message on A-Interface!");
3576 }
3577 [] T.timeout {
3578 setverdict(fail, "Received nothing on A-Interface!");
3579 }
3580 }
3581
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003582 f_perform_clear_test_ct(dt);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003583 f_shutdown_helper();
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003584}
3585
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003586/* Test RSL link drop causes counter increment */
3587testcase TC_rsl_drop_counter() runs on test_CT {
3588 var integer rsl_fail;
3589
Harald Welte89d42e82017-12-17 16:42:41 +01003590 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003591
3592 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
3593
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +01003594 f_ipa_rsl_stop(bts[0].rsl);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003595
3596 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
3597
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003598 f_shutdown_helper();
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003599}
3600
3601/* TODO: Test OML link drop causes counter increment */
3602
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003603/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
3604function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
3605 timer T := 10.0;
3606
3607 bts[0].rsl.id := "IPA-0-RSL";
Harald Welte71389132021-12-09 21:58:18 +01003608 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA") alive;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003609 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
3610 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
Oliver Smith92c2bdb2019-08-20 15:11:24 +02003611 bts[0].rsl.ccm_pars.unit_id := "99/0/0"; /* value which is unknown at BTS */
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003612
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01003613 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003614
3615 f_init_mgcp("VirtMSC");
3616
3617 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
3618 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
3619 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
3620 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
3621
3622 /* wait for IPA OML link to connect and then disconnect */
3623 T.start;
3624 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +07003625 [] IPA_RSL[0].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) {
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003626 T.stop;
3627 return true;
3628 }
3629 [] IPA_RSL[0].receive { repeat }
3630 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02003631 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003632 }
3633 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003634 return false;
3635}
3636
3637/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3638testcase TC_rsl_unknown_unit_id() runs on test_CT {
3639 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
3640 setverdict(pass);
3641 } else {
3642 setverdict(fail, "Timeout RSL waiting for connection to close");
3643 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003644 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003645}
3646
3647
3648/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3649testcase TC_oml_unknown_unit_id() runs on test_CT {
3650 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
3651 setverdict(pass);
3652 } else {
3653 setverdict(fail, "Timeout OML waiting for connection to close");
3654 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003655 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003656}
3657
3658
Harald Weltec1a2fff2017-12-17 11:06:19 +01003659/***********************************************************************
Harald Welte6811d102019-04-14 22:23:14 +02003660 * "New world" test cases using RSL_Emulation + RAN_Emulation
Harald Weltec1a2fff2017-12-17 11:06:19 +01003661 ***********************************************************************/
3662
Harald Welte6811d102019-04-14 22:23:14 +02003663import from RAN_Emulation all;
Harald Welte47cd0e32020-08-21 12:39:11 +02003664import from BSSAP_LE_Emulation all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01003665import from RSL_Emulation all;
3666import from MSC_ConnectionHandler all;
3667
3668type function void_fn(charstring id) runs on MSC_ConnHdlr;
3669
Harald Welte336820c2018-05-31 20:34:52 +02003670/* helper function to create and connect a MSC_ConnHdlr component */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003671private function f_connect_handler(inout MSC_ConnHdlr vc_conn, integer bssap_idx := 0) runs on test_CT {
3672 connect(vc_conn:RAN, g_bssap[bssap_idx].vc_RAN:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01003673 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003674 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01003675 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01003676 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01003677 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
3678 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
3679 }
Neels Hofmeyr91401012019-07-11 00:42:35 +02003680 if (isvalue(bts[2])) {
3681 connect(vc_conn:RSL2, bts[2].rsl.vc_RSL:CLIENT_PT);
3682 connect(vc_conn:RSL2_PROC, bts[2].rsl.vc_RSL:RSL_PROC);
3683 }
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003684 connect(vc_conn:BSSAP, g_bssap[bssap_idx].vc_RAN:CLIENT);
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02003685 if (mp_enable_lcs_tests) {
3686 connect(vc_conn:BSSAP_LE, g_bssap_le.vc_BSSAP_LE:CLIENT);
3687 connect(vc_conn:BSSAP_LE_PROC, g_bssap_le.vc_BSSAP_LE:PROC);
3688 }
Daniel Willmann191e0d92018-01-17 12:44:35 +01003689 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02003690 connect(vc_conn:MGCP_MULTI, vc_MGCP:MGCP_CLIENT_MULTI);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003691 connect(vc_conn:STATSD_PROC, vc_STATSD:STATSD_PROC);
Harald Welte336820c2018-05-31 20:34:52 +02003692}
3693
Neels Hofmeyrda436782021-07-20 22:09:06 +02003694function f_start_handler_create(template (omit) TestHdlrParams pars := omit)
Harald Welte336820c2018-05-31 20:34:52 +02003695runs on test_CT return MSC_ConnHdlr {
3696 var charstring id := testcasename();
3697 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003698 var integer bssap_idx := 0;
3699 if (isvalue(pars)) {
3700 bssap_idx := valueof(pars).mscpool.bssap_idx;
3701 }
Harald Welte336820c2018-05-31 20:34:52 +02003702 vc_conn := MSC_ConnHdlr.create(id);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003703 f_connect_handler(vc_conn, bssap_idx);
Neels Hofmeyrda436782021-07-20 22:09:06 +02003704 return vc_conn;
3705}
3706
3707function f_start_handler_run(MSC_ConnHdlr vc_conn, void_fn fn, template (omit) TestHdlrParams pars := omit)
3708runs on test_CT return MSC_ConnHdlr {
3709 var charstring id := testcasename();
Harald Weltea0630032018-03-20 21:09:55 +01003710 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003711 return vc_conn;
3712}
3713
Neels Hofmeyrda436782021-07-20 22:09:06 +02003714function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
3715runs on test_CT return MSC_ConnHdlr {
3716 return f_start_handler_run(f_start_handler_create(pars), fn, pars);
3717}
3718
Harald Weltea0630032018-03-20 21:09:55 +01003719/* first function inside ConnHdlr component; sets g_pars + starts function */
3720private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
3721runs on MSC_ConnHdlr {
3722 if (isvalue(pars)) {
3723 g_pars := valueof(pars);
3724 }
3725 fn.apply(id);
3726}
3727
Oliver Smith26a3db72021-07-09 13:51:29 +02003728private function f_vty_encryption_a5(charstring options) runs on test_CT {
3729 f_vty_transceive(BSCVTY, "configure terminal");
3730 f_vty_transceive(BSCVTY, "network");
3731 f_vty_transceive(BSCVTY, "encryption a5 " & options);
3732 f_vty_transceive(BSCVTY, "exit");
3733 f_vty_transceive(BSCVTY, "exit");
3734}
3735
3736private function f_vty_encryption_a5_reset() runs on test_CT {
3737 /* keep in sync with docker-playground.git ttcn3-bsc-test/osmo-bsc.cfg */
3738 f_vty_encryption_a5("0 1 3");
3739}
3740
Harald Welte3c86ea02018-05-10 22:28:05 +02003741/* Establish signalling channel (non-assignment case) followed by cipher mode */
3742private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003743 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3744 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02003745 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02003746 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
3747 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
3748 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
3749 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02003750
Philipp Maier23000732018-05-18 11:25:37 +02003751 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003752 f_perform_clear();
Harald Welte3c86ea02018-05-10 22:28:05 +02003753}
3754testcase TC_ciph_mode_a5_0() runs on test_CT {
3755 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003756 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003757 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
3758
3759 f_init(1, true);
3760 f_sleep(1.0);
3761 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3762 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003763 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003764}
3765testcase TC_ciph_mode_a5_1() runs on test_CT {
3766 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003767 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003768 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
3769
3770 f_init(1, true);
3771 f_sleep(1.0);
3772 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3773 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003774 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003775}
Oliver Smith50b98122021-07-09 15:00:28 +02003776/* OS#4975: verify that A5/2 is preferred over A5/0 */
3777testcase TC_ciph_mode_a5_2_0() runs on test_CT {
3778 var MSC_ConnHdlr vc_conn;
3779 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3780
3781 pars.encr := valueof(t_EncrParams('05'O, f_rnd_octstring(8))); /* A5/0 and A5/2 (0x01|0x04)*/
3782 pars.encr_exp_enc_alg := '04'O; /* A5/2 */
3783
3784 f_init(1, true);
3785 f_vty_encryption_a5("0 1 2 3");
3786 f_sleep(1.0);
3787 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3788 vc_conn.done;
3789 f_vty_encryption_a5_reset();
3790 f_shutdown_helper();
3791}
Oliver Smith1dff88d2021-07-09 08:45:51 +02003792/* OS#4975: verify that A5/1 is preferred over A5/2 */
3793testcase TC_ciph_mode_a5_2_1() runs on test_CT {
3794 var MSC_ConnHdlr vc_conn;
3795 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3796
3797 pars.encr := valueof(t_EncrParams('06'O, f_rnd_octstring(8))); /* A5/1 and A5/2 (0x02|0x04)*/
3798 pars.encr_exp_enc_alg := '02'O; /* A5/1 */
3799
3800 f_init(1, true);
3801 f_vty_encryption_a5("1 2");
3802 f_sleep(1.0);
3803 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3804 vc_conn.done;
3805 f_vty_encryption_a5_reset();
3806 f_shutdown_helper();
3807}
Harald Welte3c86ea02018-05-10 22:28:05 +02003808testcase TC_ciph_mode_a5_3() runs on test_CT {
3809 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003810 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003811 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
3812
3813 f_init(1, true);
3814 f_sleep(1.0);
3815 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3816 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003817 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003818}
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003819/* Establish a Signalling channel with A5/4 encryption. */
3820testcase TC_ciph_mode_a5_4() runs on test_CT {
3821 var MSC_ConnHdlr vc_conn;
3822 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3823 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Harald Welte3c86ea02018-05-10 22:28:05 +02003824
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003825 f_init(1, true);
Oliver Smith26a3db72021-07-09 13:51:29 +02003826 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003827 f_sleep(1.0);
3828 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3829 vc_conn.done;
Oliver Smith26a3db72021-07-09 13:51:29 +02003830 f_vty_encryption_a5_reset();
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003831 f_shutdown_helper();
3832}
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003833/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
3834private function f_tc_assignment_aoip_tla_v6(charstring id) runs on MSC_ConnHdlr {
3835 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3836 var PDU_BSSAP ass_cmd := f_gen_ass_req(aoip_tla := "::3");
3837 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3838 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3839
3840 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003841 f_perform_clear();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003842}
3843testcase TC_assignment_aoip_tla_v6() runs on test_CT {
3844 var MSC_ConnHdlr vc_conn;
3845 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3846
3847 f_init(1, true);
3848 f_sleep(1.0);
3849 vc_conn := f_start_handler(refers(f_tc_assignment_aoip_tla_v6), pars);
3850 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003851 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003852}
3853
Harald Welte3c86ea02018-05-10 22:28:05 +02003854
3855/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02003856private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003857 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3858 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003859
Harald Welte552620d2017-12-16 23:21:36 +01003860 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3861 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01003862
Harald Weltea0630032018-03-20 21:09:55 +01003863 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003864 f_perform_clear();
Harald Welte552620d2017-12-16 23:21:36 +01003865}
Harald Welte552620d2017-12-16 23:21:36 +01003866testcase TC_assignment_fr_a5_0() runs on test_CT {
3867 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003868 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003869 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01003870
Harald Welte89d42e82017-12-17 16:42:41 +01003871 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003872 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003873 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003874 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003875 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003876}
Harald Welte552620d2017-12-16 23:21:36 +01003877testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01003878 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003879 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003880 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003881
Harald Welte89d42e82017-12-17 16:42:41 +01003882 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003883 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003884 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3885 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003886 f_shutdown_helper();
Harald Welte651fcdc2018-05-10 20:23:16 +02003887}
3888testcase TC_assignment_fr_a5_3() runs on test_CT {
3889 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003890 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003891 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003892
Harald Welte651fcdc2018-05-10 20:23:16 +02003893 f_init(1, true);
3894 f_sleep(1.0);
3895 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003896 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003897 f_shutdown_helper();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003898}
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003899/* Establish a Signalling channel and re-assign to TCH/F with A5/4 encryption. */
3900testcase TC_assignment_fr_a5_4() runs on test_CT {
3901 var MSC_ConnHdlr vc_conn;
3902 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3903 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
3904
3905 f_init(1, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02003906 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003907 f_sleep(1.0);
3908 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3909 vc_conn.done;
Oliver Smith7eabd312021-07-12 14:18:56 +02003910 f_vty_encryption_a5_reset();
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003911 f_shutdown_helper();
3912}
Harald Weltec1a2fff2017-12-17 11:06:19 +01003913
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +02003914/* Allow only A5/4, but omit the Kc128 IE from MSC's msg. Expect Cipher Mode Reject. */
3915testcase TC_assignment_fr_a5_4_fail() runs on test_CT {
3916 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3917 var MSC_ConnHdlr vc_conn;
3918
3919 f_init(1, true);
3920 f_sleep(1.0);
3921
3922 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8))); // A5/4 support, but Kc128 missing!
3923 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
3924 vc_conn.done;
3925 f_shutdown_helper();
3926}
3927
Harald Welte552620d2017-12-16 23:21:36 +01003928/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
3929private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003930 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01003931 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02003932 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003933
3934 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003935 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
3936
Harald Weltea0630032018-03-20 21:09:55 +01003937 f_establish_fully(ass_cmd, exp_fail);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003938 f_perform_clear();
Harald Welte552620d2017-12-16 23:21:36 +01003939}
Harald Welte552620d2017-12-16 23:21:36 +01003940testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
3941 var MSC_ConnHdlr vc_conn;
3942
Harald Welte89d42e82017-12-17 16:42:41 +01003943 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003944 f_sleep(1.0);
3945
Harald Welte8863fa12018-05-10 20:15:27 +02003946 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01003947 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003948 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003949}
3950
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003951private function f_TC_assignment_a5_not_sup(charstring id) runs on MSC_ConnHdlr {
3952 var template PDU_BSSAP exp_ass_cpl := f_gen_exp_compl();
3953 var PDU_BSSAP exp_ass_req := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003954
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003955 exp_ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3956 exp_ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3957
3958 /* this is like the beginning of f_establish_fully(), but only up to ciphering reject */
3959
3960 var BSSMAP_FIELD_CodecType codecType;
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003961
3962 codecType := exp_ass_req.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType;
3963 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
3964
3965 f_create_chan_and_exp();
3966 /* we should now have a COMPL_L3 at the MSC */
3967
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003968 /* Start ciphering, expect Cipher Mode Reject */
Neels Hofmeyr6c388f22021-06-11 02:36:56 +02003969 f_cipher_mode(g_pars.encr, exp_fail := true);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003970 f_perform_clear();
Harald Welte552620d2017-12-16 23:21:36 +01003971}
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003972testcase TC_assignment_fr_a5_not_sup() runs on test_CT {
3973 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01003974 var MSC_ConnHdlr vc_conn;
3975
Harald Welte89d42e82017-12-17 16:42:41 +01003976 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003977 f_sleep(1.0);
3978
Neels Hofmeyr0588cad2021-06-11 01:38:18 +02003979 pars.encr := valueof(t_EncrParams('20'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003980 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003981 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003982 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003983}
3984
3985
Harald Welte4532e0a2017-12-23 02:05:44 +01003986private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003987 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01003988 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02003989 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01003990 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003991
3992 f_statsd_reset();
Harald Weltea0630032018-03-20 21:09:55 +01003993 f_establish_fully(ass_cmd, exp_compl);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003994
3995 var StatsDExpects expect := {
Daniel Willmannc5398f72020-09-21 10:41:35 +02003996 { name := "TTCN3.bts.0.chreq.total", mtype := "c", min := 1, max := 1},
3997 { name := "TTCN3.bts.0.chreq.successful", mtype := "c", min := 1, max := 1},
Daniel Willmannebdecc02020-08-12 15:30:17 +02003998 { name := "TTCN3.bsc.0.assignment.attempted", mtype := "c", min := 1, max := 1},
3999 { name := "TTCN3.bsc.0.assignment.completed", mtype := "c", min := 1, max := 1}
4000 };
4001 f_statsd_expect(expect);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004002 f_perform_clear();
Harald Welte4532e0a2017-12-23 02:05:44 +01004003}
4004
4005testcase TC_assignment_sign() runs on test_CT {
4006 var MSC_ConnHdlr vc_conn;
4007
4008 f_init(1, true);
4009 f_sleep(1.0);
4010
Harald Welte8863fa12018-05-10 20:15:27 +02004011 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01004012 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004013 f_shutdown_helper();
Harald Welte4532e0a2017-12-23 02:05:44 +01004014}
4015
Harald Welte60aa5762018-03-21 19:33:13 +01004016/***********************************************************************
4017 * Codec (list) testing
4018 ***********************************************************************/
4019
4020/* check if the given rsl_mode is compatible with the a_elem */
4021private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
4022return boolean {
4023 select (a_elem.codecType) {
4024 case (GSM_FR) {
4025 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
4026 return true;
4027 }
4028 }
4029 case (GSM_HR) {
4030 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
4031 return true;
4032 }
4033 }
4034 case (GSM_EFR) {
4035 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
4036 return true;
4037 }
4038 }
4039 case (FR_AMR) {
4040 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
4041 return true;
4042 }
4043 }
4044 case (HR_AMR) {
4045 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
4046 return true;
4047 }
4048 }
4049 case else { }
4050 }
4051 return false;
4052}
4053
4054/* check if the given rsl_mode is compatible with the a_list */
4055private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
4056return boolean {
4057 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
4058 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
4059 return true;
4060 }
4061 }
4062 return false;
4063}
4064
4065/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02004066function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01004067return BSSMAP_IE_ChannelType {
4068 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
4069 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
4070 select (a_elem.codecType) {
4071 case (GSM_FR) {
4072 ret.channelRateAndType := ChRate_TCHF;
4073 ret.speechId_DataIndicator := Spdi_TCHF_FR;
4074 }
4075 case (GSM_HR) {
4076 ret.channelRateAndType := ChRate_TCHH;
4077 ret.speechId_DataIndicator := Spdi_TCHH_HR;
4078 }
4079 case (GSM_EFR) {
4080 ret.channelRateAndType := ChRate_TCHF;
4081 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
4082 }
4083 case (FR_AMR) {
4084 ret.channelRateAndType := ChRate_TCHF;
4085 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
4086 }
4087 case (HR_AMR) {
4088 ret.channelRateAndType := ChRate_TCHH;
4089 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
4090 }
4091 case else {
4092 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02004093 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01004094 }
4095 }
4096 return ret;
4097}
4098
Harald Weltea63b9102018-03-22 20:36:16 +01004099private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
4100return template RSL_IE_Body {
4101 var template RSL_IE_Body mode_ie := {
4102 chan_mode := {
4103 len := ?,
4104 reserved := ?,
4105 dtx_d := ?,
4106 dtx_u := ?,
4107 spd_ind := RSL_SPDI_SPEECH,
4108 ch_rate_type := -,
4109 coding_alg_rate := -
4110 }
4111 }
4112
4113 select (a_elem.codecType) {
4114 case (GSM_FR) {
4115 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4116 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
4117 }
4118 case (GSM_HR) {
4119 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
4120 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
4121 }
4122 case (GSM_EFR) {
4123 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4124 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
4125 }
4126 case (FR_AMR) {
4127 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4128 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
4129 }
4130 case (HR_AMR) {
4131 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
4132 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
4133 }
4134 }
4135 return mode_ie;
4136}
4137
Harald Welte60aa5762018-03-21 19:33:13 +01004138type record CodecListTest {
4139 BSSMAP_IE_SpeechCodecList codec_list,
4140 charstring id
4141}
4142type record of CodecListTest CodecListTests
4143
4144private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004145 f_assignment_codec(id);
4146}
4147
4148private function f_assignment_codec(charstring id, boolean do_perform_clear := true) runs on MSC_ConnHdlr {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004149 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
4150 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
Harald Welte60aa5762018-03-21 19:33:13 +01004151
4152 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02004153 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte79f3f542018-05-25 20:02:37 +02004154 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
4155 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
4156 g_pars.ass_codec_list.codecElements[0];
Philipp Maierd0e64b02019-03-13 14:15:23 +01004157 if (isvalue(g_pars.expect_mr_s0_s7)) {
4158 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
4159 g_pars.expect_mr_s0_s7;
4160 }
Harald Welte79f3f542018-05-25 20:02:37 +02004161 }
Harald Welte60aa5762018-03-21 19:33:13 +01004162 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
4163 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01004164 log("expecting ASS COMPL like this: ", exp_compl);
4165
4166 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01004167
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004168 if (not g_pars.expect_channel_mode_modify) {
4169 /* Verify that the RSL-side activation actually matches our expectations */
4170 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
Harald Weltea63b9102018-03-22 20:36:16 +01004171
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004172 var RSL_IE_Body mode_ie;
4173 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
4174 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02004175 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004176 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004177 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
4178 if (not match(mode_ie, t_mode_ie)) {
4179 log("mode_ie ", mode_ie, " != t_mode_ie ", t_mode_ie);
4180 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004181 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004182
4183 var RSL_IE_Body mr_conf;
4184 if (g_pars.expect_mr_conf_ie != omit) {
4185 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
4186 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
4187 mtc.stop;
4188 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004189 log("found RSL MR CONFIG IE: ", mr_conf);
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004190
4191 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
4192 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
4193 g_pars.expect_mr_conf_ie);
4194 }
4195 } else {
4196 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
4197 log("found RSL MR CONFIG IE: ", mr_conf);
4198 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
4199 mtc.stop;
4200 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004201 }
4202 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004203
4204 if (do_perform_clear) {
4205 f_perform_clear();
4206 }
Harald Welte60aa5762018-03-21 19:33:13 +01004207}
4208
Philipp Maierd0e64b02019-03-13 14:15:23 +01004209private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
4210
4211 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4212 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4213
4214 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02004215 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maierd0e64b02019-03-13 14:15:23 +01004216 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
4217 }
4218 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
4219 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
4220 log("expecting ASS FAIL like this: ", exp_fail);
4221
4222 f_establish_fully(ass_cmd, exp_fail);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004223 f_perform_clear();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004224}
4225
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004226const CounterNameVals counternames_bsc_bts_assignment := {
4227 { "assignment:attempted", 0 },
4228 { "assignment:completed", 0 },
4229 { "assignment:stopped", 0 },
4230 { "assignment:no_channel", 0 },
4231 { "assignment:timeout", 0 },
4232 { "assignment:failed", 0 },
4233 { "assignment:error", 0 }
4234};
4235
4236const CounterNameVals counternames_bts_assignment := {
4237 { "assignment:attempted_sign", 0 },
4238 { "assignment:attempted_speech", 0 },
4239 { "assignment:completed_sign", 0 },
4240 { "assignment:completed_speech", 0 },
4241 { "assignment:stopped_sign", 0 },
4242 { "assignment:stopped_speech", 0 },
4243 { "assignment:no_channel_sign", 0 },
4244 { "assignment:no_channel_speech", 0 },
4245 { "assignment:timeout_sign", 0 },
4246 { "assignment:timeout_speech", 0 },
4247 { "assignment:failed_sign", 0 },
4248 { "assignment:failed_speech", 0 },
4249 { "assignment:error_sign", 0 },
4250 { "assignment:error_speech", 0 }
4251};
4252
4253function f_ctrs_bsc_and_bts_assignment_init(integer bts_count := NUM_BTS) runs on test_CT {
4254 var CounterNameVals bts_names := counternames_bsc_bts_assignment & counternames_bts_assignment;
4255 f_ctrs_bts_init(bts_count, bts_names);
4256 f_ctrs_bsc_init(counternames_bsc_bts_assignment);
4257}
4258
Harald Welte60aa5762018-03-21 19:33:13 +01004259testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004260 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004261 var MSC_ConnHdlr vc_conn;
4262
4263 f_init(1, true);
4264 f_sleep(1.0);
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004265 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004266
4267 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004268 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004269 vc_conn.done;
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004270
4271 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4272 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4273 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4274 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4275 f_ctrs_bts_verify();
4276
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004277 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004278}
4279
4280testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004281 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004282 var MSC_ConnHdlr vc_conn;
4283
4284 f_init(1, true);
4285 f_sleep(1.0);
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004286 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004287
4288 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004289 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004290 vc_conn.done;
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004291
4292 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4293 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4294 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4295 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4296 f_ctrs_bts_verify();
4297
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004298 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004299}
4300
4301testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004302 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004303 var MSC_ConnHdlr vc_conn;
4304
4305 f_init(1, true);
4306 f_sleep(1.0);
4307
4308 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004309 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004310 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004311 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004312}
4313
Philipp Maierd0e64b02019-03-13 14:15:23 +01004314/* Allow 5,90k only (current default config) */
4315private function f_allow_amr_rate_5_90k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00004316 f_vty_cfg_msc(BSCVTY, 0, {
4317 "amr-config 12_2k forbidden",
4318 "amr-config 10_2k forbidden",
4319 "amr-config 7_95k forbidden",
4320 "amr-config 7_40k forbidden",
4321 "amr-config 6_70k forbidden",
4322 "amr-config 5_90k allowed",
4323 "amr-config 5_15k forbidden",
4324 "amr-config 4_75k forbidden"
4325 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01004326}
4327
4328/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
4329 * ("Config-NB-Code = 1") */
4330private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00004331 f_vty_cfg_msc(BSCVTY, 0, {
4332 "amr-config 12_2k allowed",
4333 "amr-config 10_2k forbidden",
4334 "amr-config 7_95k forbidden",
4335 "amr-config 7_40k allowed",
4336 "amr-config 6_70k forbidden",
4337 "amr-config 5_90k allowed",
4338 "amr-config 5_15k forbidden",
4339 "amr-config 4_75k allowed"
4340 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01004341}
4342
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004343private function f_vty_amr_start_mode_set(boolean fr, charstring startmode) runs on test_CT {
4344 var charstring tch;
4345 if (fr) {
4346 tch := "tch-f";
4347 } else {
4348 tch := "tch-h";
4349 }
4350 f_vty_cfg_bts(BSCVTY, 0, { "amr " & tch & " start-mode " & startmode });
4351}
4352
4353/* Set the AMR start-mode for this TCH back to the default configuration. */
4354private function f_vty_amr_start_mode_restore(boolean fr) runs on test_CT {
4355 f_vty_amr_start_mode_set(fr, "auto");
4356}
4357
Harald Welte60aa5762018-03-21 19:33:13 +01004358testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004359 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004360 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02004361
4362 /* Note: This setups the codec configuration. The parameter payload in
4363 * mr_conf must be consistant with the parameter codecElements in pars
4364 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004365 var RSL_IE_Body mr_conf := {
4366 other := {
4367 len := 2,
4368 payload := '2804'O
4369 }
4370 };
Harald Welte60aa5762018-03-21 19:33:13 +01004371
Philipp Maier7695a0d2018-09-27 17:52:14 +02004372 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Philipp Maier806f8f12019-03-12 12:13:41 +01004373 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02004374 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
4375 pars.expect_mr_conf_ie := mr_conf;
4376
Harald Welte60aa5762018-03-21 19:33:13 +01004377 f_init(1, true);
4378 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004379 f_vty_amr_start_mode_set(true, "1");
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004380 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004381
Harald Welte8863fa12018-05-10 20:15:27 +02004382 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004383 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004384
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004385 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4386 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4387 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4388 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4389 f_ctrs_bts_verify();
4390
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004391 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004392 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004393}
4394
4395testcase TC_assignment_codec_amr_h() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004396 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004397 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02004398
4399 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004400 var RSL_IE_Body mr_conf := {
4401 other := {
4402 len := 2,
4403 payload := '2804'O
4404 }
4405 };
Harald Welte60aa5762018-03-21 19:33:13 +01004406
Philipp Maier7695a0d2018-09-27 17:52:14 +02004407 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Philipp Maier806f8f12019-03-12 12:13:41 +01004408 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02004409 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4410 pars.expect_mr_conf_ie := mr_conf;
4411
Harald Welte60aa5762018-03-21 19:33:13 +01004412 f_init(1, true);
4413 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004414 f_vty_amr_start_mode_set(false, "1");
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004415 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004416
Harald Welte8863fa12018-05-10 20:15:27 +02004417 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004418 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004419
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004420 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4421 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4422 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4423 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4424 f_ctrs_bts_verify();
4425
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004426 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004427 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004428}
4429
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004430/* Establish signalling on a TCH/F lchan, and then switch to speech mode without a new Assignment. */
4431testcase TC_assignment_codec_fr_by_mode_modify() runs on test_CT {
4432 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4433 var MSC_ConnHdlr vc_conn;
4434
4435 f_init(1, true);
4436 f_sleep(1.0);
4437
4438 /* By disabling all SDCCH, the MS should be given a TCH/F for signalling. Then activating an FR codec should
4439 * merely do a Channel Mode Modify, and not assign to a new lchan. f_establish_fully() already accounts for
4440 * expecting a Channel Mode Modify if the channel type is compatible. */
4441 f_disable_all_sdcch();
4442 f_disable_all_tch_h();
4443
4444 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4445 pars.expect_channel_mode_modify := true;
4446 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4447 vc_conn.done;
4448
4449 f_enable_all_sdcch();
4450 f_enable_all_tch();
4451 f_shutdown_helper();
4452}
4453
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004454/* 'amr start-mode auto' should not keep the (unused) 'smod' bits from previous configuration */
4455testcase TC_assignment_codec_amr_startmode_cruft() runs on test_CT {
4456 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4457 var MSC_ConnHdlr vc_conn;
4458
4459 var RSL_IE_Body mr_conf := {
4460 other := {
4461 len := 2,
4462 payload := '2004'O /* <- expect ICMI=0, smod=00 */
4463 }
4464 };
4465
4466 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4467 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
4468 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
4469 pars.expect_mr_conf_ie := mr_conf;
4470
4471 f_init(1, true);
4472 f_sleep(1.0);
4473
4474 /* First set nonzero start mode bits */
4475 f_vty_amr_start_mode_set(true, "4");
4476 /* Now set to auto, and expect the startmode bits to be zero in the message, i.e. ensure that osmo-bsc does not
4477 * let the startmode bits stick around and has deterministic MultiRate config for 'start-mode auto'; that is
4478 * ensured by above '2004'O, where 'x0xx'O indicates ICMI = 0, spare = 0, smod = 00. */
4479 f_vty_amr_start_mode_set(true, "auto");
4480
4481 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4482 vc_conn.done;
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004483
4484 /* Clear the startmode bits to not affect subsequent tests, in case the bits should indeed stick around. */
4485 f_vty_amr_start_mode_set(true, "1");
4486 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004487 f_shutdown_helper();
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004488}
4489
Neels Hofmeyr21863562020-11-26 00:34:33 +00004490function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0,
4491 charstring start_mode := "1")
Philipp Maierd0e64b02019-03-13 14:15:23 +01004492runs on test_CT {
4493
4494 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4495 var MSC_ConnHdlr vc_conn;
4496
4497 /* See note above */
4498 var RSL_IE_Body mr_conf := {
4499 other := {
4500 len := lengthof(mrconf),
4501 payload := mrconf
4502 }
4503 };
4504
4505 if (fr) {
4506 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4507 } else {
4508 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4509 }
4510 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4511 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4512 pars.expect_mr_conf_ie := mr_conf;
4513 pars.expect_mr_s0_s7 := exp_s8_s0;
4514
4515 f_init(1, true);
4516 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004517 f_vty_amr_start_mode_set(fr, start_mode);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004518 f_sleep(1.0);
4519
4520 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4521 vc_conn.done;
4522 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004523 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004524}
4525
4526function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
4527runs on test_CT {
4528
4529 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4530 var MSC_ConnHdlr vc_conn;
4531
4532 if (fr) {
4533 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4534 } else {
4535 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4536 }
4537 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4538 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4539
4540 f_init(1, true);
4541 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004542 f_vty_amr_start_mode_set(fr, "1");
Philipp Maierd0e64b02019-03-13 14:15:23 +01004543 f_sleep(1.0);
4544
4545 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
4546 vc_conn.done;
4547 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004548 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004549}
4550
4551
4552/* Set S1, we expect an AMR multirate configuration IE with all four rates
4553 * set. */
4554testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004555 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004556 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004557}
4558
4559/* Set S1, we expect an AMR multirate configuration IE with the lower three
4560 * rates set. */
4561testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004562 f_TC_assignment_codec_amr(false, '2815208820'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004563 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004564}
4565
4566/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4567 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4568testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004569 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004570 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004571}
4572
4573/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4574 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4575testcase TC_assignment_codec_amr_h_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004576 f_TC_assignment_codec_amr(false, '2815208820'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004577 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004578}
4579
4580/* The following block of tests selects more and more rates until all four
4581 * possible rates are in the active set (full rate) */
4582testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004583 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004584 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004585}
4586
4587testcase TC_assignment_codec_amr_f_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004588 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004589 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004590}
4591
4592testcase TC_assignment_codec_amr_f_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004593 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004594 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004595}
4596
4597testcase TC_assignment_codec_amr_f_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004598 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004599 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004600}
4601
4602/* The following block of tests selects more and more rates until all three
4603 * possible rates are in the active set (half rate) */
4604testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004605 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004606 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004607}
4608
4609testcase TC_assignment_codec_amr_h_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004610 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004611 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004612}
4613
4614testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004615 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004616 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004617}
4618
4619/* The following block tests what happens when the MSC does offer rate
4620 * configurations that are not supported by the BSC. Normally such situations
4621 * should not happen because the MSC gets informed by the BSC in advance via
4622 * the L3 COMPLETE message which rates are applicable. The MSC should not try
4623 * to offer rates that are not applicable anyway. */
4624
4625testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004626 /* Try to include 12,2k in into the active set even though the channel
4627 * is half rate only. The BSC is expected to remove the 12,0k */
4628 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004629 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004630}
4631
4632testcase TC_assignment_codec_amr_f_S01234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004633 /* See what happens when all rates are selected at once. Since then
4634 * Also S1 is selected, this setting will be prefered and we should
4635 * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
4636 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004637 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004638}
4639
4640testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004641 /* Same as above, but with S1 missing, the MSC is then expected to
4642 * select the currently supported rates, which are also 12.2k, 7,40k,
4643 * 5,90k, and 4,75k, into the active set. */
4644 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004645 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004646}
4647
4648testcase TC_assignment_codec_amr_f_zero() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004649 /* Try to select no rates at all */
4650 f_TC_assignment_codec_amr_fail(true, '00000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004651 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004652}
4653
4654testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004655 /* Try to select only unsupported rates */
4656 f_TC_assignment_codec_amr_fail(true, '01101000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004657 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004658}
4659
4660testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004661 /* Try to select 12,2k for half rate */
4662 f_TC_assignment_codec_amr_fail(false, '10000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004663 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004664}
4665
Neels Hofmeyr21863562020-11-26 00:34:33 +00004666testcase TC_assignment_codec_amr_f_start_mode_auto() runs on test_CT {
4667 f_TC_assignment_codec_amr(true, '209520882208'O, '11111111'B, '00000010'B,
4668 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004669 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004670}
4671
4672testcase TC_assignment_codec_amr_h_start_mode_auto() runs on test_CT {
4673 f_TC_assignment_codec_amr(false, '2015208820'O, '10010101'B, '00010101'B,
4674 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004675 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004676}
4677
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004678testcase TC_assignment_codec_amr_f_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004679 /* "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 +00004680 f_TC_assignment_codec_amr(true, '2b9520882208'O, '11111111'B, '00000010'B,
4681 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004682 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004683}
4684
4685testcase TC_assignment_codec_amr_h_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004686 /* "amr tch-h modes 0 2 4" => total 3 modes and start mode 4 => '10'B on the wire */
4687 f_TC_assignment_codec_amr(false, '2a15208820'O, '10010101'B, '00010101'B,
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004688 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004689 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004690}
4691
Philipp Maierac09bfc2019-01-08 13:41:39 +01004692private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004693 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
4694 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
4695 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
4696 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004697}
4698
4699private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004700 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
4701 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004702}
4703
4704private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004705 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
4706 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
4707 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
4708 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
4709 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
4710 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004711}
4712
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004713private function f_disable_all_sdcch() runs on test_CT {
4714 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 borken");
4715 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 borken");
4716 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 borken");
4717 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 borken");
4718}
4719
4720private function f_enable_all_sdcch() runs on test_CT {
4721 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 unused");
4722 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 unused");
4723 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 unused");
4724 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 unused");
4725}
4726
Philipp Maierac09bfc2019-01-08 13:41:39 +01004727/* Allow HR only */
4728private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
4729 g_pars := f_gen_test_hdlr_pars();
4730 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4731 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4732 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4733 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4734 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4735 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4736 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004737 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004738}
4739
4740/* Allow FR only */
4741private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
4742 g_pars := f_gen_test_hdlr_pars();
4743 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4744 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4745 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4746 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4747 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4748 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4749 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004750 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004751}
4752
4753/* Allow HR only (expect assignment failure) */
4754private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
4755 g_pars := f_gen_test_hdlr_pars();
4756 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4757 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4758 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4759 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4760 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4761 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4762 f_establish_fully(ass_cmd, exp_fail);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004763 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004764}
4765
4766/* Allow FR only (expect assignment failure) */
4767private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(charstring id) runs on MSC_ConnHdlr {
4768 g_pars := f_gen_test_hdlr_pars();
4769 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4770 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4771 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4772 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4773 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4774 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4775 f_establish_fully(ass_cmd, exp_fail);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004776 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004777}
4778
4779/* Allow FR and HR, but prefer FR */
4780private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4781 g_pars := f_gen_test_hdlr_pars();
4782 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4783 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4784 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4785 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4786 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4787 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4788 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4789 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004790 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004791}
4792
4793/* Allow FR and HR, but prefer HR */
4794private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4795 g_pars := f_gen_test_hdlr_pars();
4796 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4797 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4798 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4799 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4800 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4801 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4802 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4803 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004804 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004805}
4806
4807/* Allow FR and HR, but prefer FR */
4808private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4809 g_pars := f_gen_test_hdlr_pars();
4810 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4811 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4812 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4813 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4814 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4815 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4816 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4817 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004818 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004819}
4820
4821/* Allow FR and HR, but prefer HR */
4822private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4823 g_pars := f_gen_test_hdlr_pars();
4824 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4825 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4826 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4827 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4828 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4829 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4830 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4831 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004832 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004833}
4834
4835/* Request a HR channel while all FR channels are exhausted, this is expected
4836 * to work without conflicts */
4837testcase TC_assignment_codec_fr_exhausted_req_hr() runs on test_CT {
4838 var MSC_ConnHdlr vc_conn;
4839 f_init(1, true);
4840 f_sleep(1.0);
4841 f_enable_all_tch();
4842 f_disable_all_tch_f();
4843 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr));
4844 vc_conn.done;
4845 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004846 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004847}
4848
4849/* Request a FR channel while all FR channels are exhausted, this is expected
4850 * to fail. */
4851testcase TC_assignment_codec_fr_exhausted_req_fr() runs on test_CT {
4852 var MSC_ConnHdlr vc_conn;
4853 f_init(1, true);
4854 f_sleep(1.0);
4855 f_enable_all_tch();
4856 f_disable_all_tch_f();
4857 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr_fail));
4858 vc_conn.done;
4859 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004860 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004861}
4862
4863/* Request a FR (prefered) or alternatively a HR channel while all FR channels
4864 * are exhausted, this is expected to be resolved by selecting a HR channel. */
4865testcase TC_assignment_codec_fr_exhausted_req_fr_hr() runs on test_CT {
4866 var MSC_ConnHdlr vc_conn;
4867 f_init(1, true);
4868 f_sleep(1.0);
4869 f_enable_all_tch();
4870 f_disable_all_tch_f();
4871 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
4872 vc_conn.done;
4873 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004874 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004875}
4876
4877/* Request a HR (prefered) or alternatively a FR channel while all FR channels
4878 * are exhausted, this is expected to work without conflicts. */
4879testcase TC_assignment_codec_fr_exhausted_req_hr_fr() runs on test_CT {
4880 var MSC_ConnHdlr vc_conn;
4881 f_init(1, true);
4882 f_sleep(1.0);
4883 f_enable_all_tch();
4884 f_disable_all_tch_f();
4885 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_hr_fr));
4886 vc_conn.done;
4887 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004888 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004889}
4890
4891/* Request a FR channel while all HR channels are exhausted, this is expected
4892 * to work without conflicts */
4893testcase TC_assignment_codec_hr_exhausted_req_fr() runs on test_CT {
4894 var MSC_ConnHdlr vc_conn;
4895 f_init(1, true);
4896 f_sleep(1.0);
4897 f_enable_all_tch();
4898 f_disable_all_tch_h();
4899 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr));
4900 vc_conn.done;
4901 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004902 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004903}
4904
4905/* Request a HR channel while all HR channels are exhausted, this is expected
4906 * to fail. */
4907testcase TC_assignment_codec_hr_exhausted_req_hr() runs on test_CT {
4908 var MSC_ConnHdlr vc_conn;
4909 f_init(1, true);
4910 f_sleep(1.0);
4911 f_enable_all_tch();
4912 f_disable_all_tch_h();
4913 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr_fail));
4914 vc_conn.done;
4915 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004916 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004917}
4918
4919/* Request a HR (prefered) or alternatively a FR channel while all HR channels
4920 * are exhausted, this is expected to be resolved by selecting a FR channel. */
4921testcase TC_assignment_codec_hr_exhausted_req_hr_fr() runs on test_CT {
4922 var MSC_ConnHdlr vc_conn;
4923 f_init(1, true);
4924 f_sleep(1.0);
4925 f_enable_all_tch();
4926 f_disable_all_tch_h();
4927 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_hr_fr));
4928 vc_conn.done;
4929 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004930 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004931}
4932
4933/* Request a FR (prefered) or alternatively a HR channel while all HR channels
4934 * are exhausted, this is expected to work without conflicts. */
4935testcase TC_assignment_codec_hr_exhausted_req_fr_hr() runs on test_CT {
4936 var MSC_ConnHdlr vc_conn;
4937 f_init(1, true);
4938 f_sleep(1.0);
4939 f_enable_all_tch();
4940 f_disable_all_tch_h();
4941 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_fr_hr));
4942 vc_conn.done;
4943 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004944 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004945}
4946
4947/* Allow FR and HR, but prefer HR */
4948private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4949 g_pars := f_gen_test_hdlr_pars();
4950 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4951 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4952 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4953 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4954 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4955 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4956 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4957 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004958 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004959}
4960
4961/* Allow FR and HR, but prefer FR */
4962private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4963 g_pars := f_gen_test_hdlr_pars();
4964 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4965 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4966 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4967 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4968 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4969 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4970 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4971 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004972 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004973}
4974
4975/* Request a HR (prefered) or alternatively a FR channel, it is expected that
4976 * HR, which is the prefered type, is selected. */
4977testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
4978 var MSC_ConnHdlr vc_conn;
4979 f_init(1, true);
4980 f_sleep(1.0);
4981 f_enable_all_tch();
4982 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
4983 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004984 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004985}
4986
4987/* Request a FR (prefered) or alternatively a HR channel, it is expected that
4988 * FR, which is the prefered type, is selected. */
4989testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
4990 var MSC_ConnHdlr vc_conn;
4991 f_init(1, true);
4992 f_sleep(1.0);
4993 f_enable_all_tch();
4994 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
4995 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004996 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004997}
4998
Pau Espin Pedrol14475352021-07-22 15:48:16 +02004999/* request a signalling channel with all SDCCH exhausted, it is expected that a TCH will be selected */
5000private function f_TC_assignment_sdcch_exhausted_req_signalling(charstring id) runs on MSC_ConnHdlr {
5001 g_pars := f_gen_test_hdlr_pars();
5002 g_pars.ra := '02'O; /* RA containing reason=LU */
5003
5004 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
5005 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
5006 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
5007 var template uint3_t tsc := ?;
5008
5009 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
5010 f_create_bssmap_exp(l3_enc);
5011 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
5012 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, tsc);
5013
5014 /* we should now have a COMPL_L3 at the MSC */
5015 timer T := 10.0;
5016 T.start;
5017 alt {
5018 [] BSSAP.receive(tr_BSSMAP_ComplL3);
5019 [] T.timeout {
5020 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
5021 }
5022 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005023
5024 f_perform_clear();
Pau Espin Pedrol14475352021-07-22 15:48:16 +02005025}
5026testcase TC_assignment_sdcch_exhausted_req_signalling() runs on test_CT {
5027 var MSC_ConnHdlr vc_conn;
5028 f_init(1, true);
5029 f_sleep(1.0);
5030 f_disable_all_sdcch();
5031 vc_conn := f_start_handler(refers(f_TC_assignment_sdcch_exhausted_req_signalling));
5032 vc_conn.done;
5033 f_enable_all_sdcch();
5034 f_shutdown_helper();
5035}
5036
5037/* Request a signalling channel with all SDCCH exhausted, it is
5038 expected that no TCH will be selected for signalling and assigment will fail
5039 because it's dictated by VTY config */
5040testcase TC_assignment_sdcch_exhausted_req_signalling_tch_forbidden() runs on test_CT {
5041 var RSL_Message rsl_unused, rsl_msg;
5042 var GsmRrMessage rr;
5043 f_init(1, false);
5044 f_sleep(1.0);
5045 f_vty_allow_tch_for_signalling(false, 0);
5046 f_disable_all_sdcch();
5047
5048 /* RA containing reason=LU */
5049 f_ipa_tx(0, ts_RSL_CHAN_RQD('02'O, 2342));
5050 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
5051 rr := dec_GsmRrMessage(rsl_msg.ies[1].body.full_imm_ass_info.payload);
5052 if (rr.header.message_type != IMMEDIATE_ASSIGNMENT_REJECT) {
5053 setverdict(fail, "Expected reject");
5054 }
5055
5056 f_vty_allow_tch_for_signalling(true, 0);
5057 f_enable_all_sdcch();
5058 f_shutdown_helper();
5059}
5060
5061/* Request a voice channel with all SDCCH exhausted, it is
5062 * expected that TCH channel will be allocated since the VTY option is only
5063 * aimed at signalling requests */
5064private function f_TC_assignment_sdcch_exhausted_req_voice_tch_forbidden(charstring id) runs on MSC_ConnHdlr {
5065 g_pars := f_gen_test_hdlr_pars();
5066 g_pars.ra := '43'O; /* RA containing reason=originating speech call*/
5067
5068 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
5069 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
5070 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
5071 var template uint3_t tsc := ?;
5072
5073 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
5074 f_create_bssmap_exp(l3_enc);
5075 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
5076 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, tsc);
5077
5078 /* we should now have a COMPL_L3 at the MSC */
5079 timer T := 10.0;
5080 T.start;
5081 alt {
5082 [] BSSAP.receive(tr_BSSMAP_ComplL3);
5083 [] T.timeout {
5084 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
5085 }
5086 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005087 f_perform_clear();
Pau Espin Pedrol14475352021-07-22 15:48:16 +02005088}
5089testcase TC_assignment_sdcch_exhausted_req_voice_tch_forbidden() runs on test_CT {
5090 var MSC_ConnHdlr vc_conn;
5091 f_init(1, true);
5092 f_sleep(1.0);
5093 f_vty_allow_tch_for_signalling(false, 0);
5094 f_disable_all_sdcch();
5095
5096 vc_conn := f_start_handler(refers(f_TC_assignment_sdcch_exhausted_req_voice_tch_forbidden));
5097 vc_conn.done;
5098
5099 f_vty_allow_tch_for_signalling(true, 0);
5100 f_enable_all_sdcch();
5101 f_shutdown_helper();
5102}
5103
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005104testcase TC_assignment_osmux() runs on test_CT {
5105 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5106 var MSC_ConnHdlr vc_conn;
5107
5108 /* See note above */
5109 var RSL_IE_Body mr_conf := {
5110 other := {
5111 len := 2,
5112 payload := '2804'O
5113 }
5114 };
5115
5116 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
5117 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
5118 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
5119 pars.expect_mr_conf_ie := mr_conf;
5120 pars.use_osmux := true;
5121
5122 f_init(1, true, true);
5123 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00005124 f_vty_amr_start_mode_set(false, "1");
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005125
5126 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
5127 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00005128
5129 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01005130 f_shutdown_helper();
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005131}
5132
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02005133/* test the procedure of the MSC requesting a Classmark Update:
5134 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
5135 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01005136private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005137 g_pars := f_gen_test_hdlr_pars();
5138
Harald Weltea0630032018-03-20 21:09:55 +01005139 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01005140 /* we should now have a COMPL_L3 at the MSC */
Harald Welte898113b2018-01-31 18:32:21 +01005141
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02005142 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
5143 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
5144
Harald Welte898113b2018-01-31 18:32:21 +01005145 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
5146 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
5147 setverdict(pass);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005148
5149 f_perform_clear();
Harald Welte898113b2018-01-31 18:32:21 +01005150}
5151testcase TC_classmark() runs on test_CT {
5152 var MSC_ConnHdlr vc_conn;
5153 f_init(1, true);
5154 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005155 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01005156 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005157 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01005158}
5159
Harald Welteeddf0e92020-06-21 19:42:15 +02005160/* Send a CommonID from the simulated MSC and verify that the information is used to
5161 * fill BSC-internal data structures (specifically, bsc_subscr associated with subscr_conn) */
5162private function f_tc_common_id(charstring id) runs on MSC_ConnHdlr {
5163 g_pars := f_gen_test_hdlr_pars();
5164 f_MscConnHdlr_init_vty();
5165
5166 f_create_chan_and_exp();
5167 /* we should now have a COMPL_L3 at the MSC */
Harald Welteeddf0e92020-06-21 19:42:15 +02005168
5169 /* Send CommonID */
5170 BSSAP.send(ts_BSSMAP_CommonId(g_pars.imsi));
5171
5172 /* Use VTY to verify that the IMSI of the subscr_conn is set */
5173 var charstring regex := "*(IMSI: " & hex2str(g_pars.imsi) & ")*";
5174 f_vty_transceive_match_regexp_retry(BSCVTY, "show conns", regex, 0, 4, 1.0);
5175
5176 setverdict(pass);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005177
5178 f_perform_clear();
Harald Welteeddf0e92020-06-21 19:42:15 +02005179}
5180testcase TC_common_id() runs on test_CT {
5181 var MSC_ConnHdlr vc_conn;
5182 f_init(1, true);
5183 f_sleep(1.0);
5184 vc_conn := f_start_handler(refers(f_tc_common_id));
5185 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005186 f_shutdown_helper();
Harald Welteeddf0e92020-06-21 19:42:15 +02005187}
5188
Harald Weltee3bd6582018-01-31 22:51:25 +01005189private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005190 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01005191 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01005192 /* we should now have a COMPL_L3 at the MSC */
Harald Welte898113b2018-01-31 18:32:21 +01005193
Harald Weltee3bd6582018-01-31 22:51:25 +01005194 /* send the single message we want to send */
5195 f_rsl_send_l3(l3);
5196}
5197
5198private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
5199 timer T := sec;
5200 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01005201 T.start;
5202 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01005203 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
5204 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02005205 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01005206 }
5207 [] T.timeout {
5208 setverdict(pass);
5209 }
5210 }
5211}
5212
Harald Weltee3bd6582018-01-31 22:51:25 +01005213/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
5214private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
5215 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
5216 f_bssap_expect_nothing();
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005217 f_perform_clear();
Harald Weltee3bd6582018-01-31 22:51:25 +01005218}
Harald Welte898113b2018-01-31 18:32:21 +01005219testcase TC_unsol_ass_fail() runs on test_CT {
5220 var MSC_ConnHdlr vc_conn;
5221 f_init(1, true);
5222 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005223 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01005224 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005225 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01005226}
Harald Welte552620d2017-12-16 23:21:36 +01005227
Harald Welteea99a002018-01-31 20:46:43 +01005228
5229/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
5230private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01005231 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
5232 f_bssap_expect_nothing();
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005233 f_perform_clear();
Harald Welteea99a002018-01-31 20:46:43 +01005234}
5235testcase TC_unsol_ass_compl() runs on test_CT {
5236 var MSC_ConnHdlr vc_conn;
5237 f_init(1, true);
5238 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005239 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01005240 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005241 f_shutdown_helper();
Harald Welteea99a002018-01-31 20:46:43 +01005242}
5243
5244
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005245/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
5246private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01005247 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
5248 f_bssap_expect_nothing();
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005249 f_perform_clear();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005250}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005251testcase TC_unsol_ho_fail() runs on test_CT {
5252 var MSC_ConnHdlr vc_conn;
5253 f_init(1, true);
5254 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005255 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005256 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005257 f_shutdown_helper();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005258}
5259
5260
Harald Weltee3bd6582018-01-31 22:51:25 +01005261/* short message from MS should be ignored */
5262private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005263 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01005264 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01005265 /* we should now have a COMPL_L3 at the MSC */
Harald Weltee3bd6582018-01-31 22:51:25 +01005266
5267 /* send short message */
5268 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
5269 f_bssap_expect_nothing();
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005270 f_perform_clear();
Harald Weltee3bd6582018-01-31 22:51:25 +01005271}
5272testcase TC_err_82_short_msg() runs on test_CT {
5273 var MSC_ConnHdlr vc_conn;
5274 f_init(1, true);
5275 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005276 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01005277 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005278 f_shutdown_helper();
Harald Weltee3bd6582018-01-31 22:51:25 +01005279}
5280
5281
Harald Weltee9e02e42018-01-31 23:36:25 +01005282/* 24.008 8.4 Unknown message must trigger RR STATUS */
5283private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
5284 f_est_single_l3(ts_RRM_UL_REL('00'O));
5285 timer T := 3.0
5286 alt {
5287 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
5288 setverdict(pass);
5289 }
5290 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01005291 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01005292 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005293 f_perform_clear();
Harald Weltee9e02e42018-01-31 23:36:25 +01005294}
5295testcase TC_err_84_unknown_msg() 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_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01005300 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005301 f_shutdown_helper();
Harald Weltee9e02e42018-01-31 23:36:25 +01005302}
5303
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005304/***********************************************************************
5305 * Handover
5306 ***********************************************************************/
5307
Harald Welte94e0c342018-04-07 11:33:23 +02005308/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
5309private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
5310runs on test_CT {
5311 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
5312 " timeslot "&int2str(ts_nr)&" ";
5313 f_vty_transceive(BSCVTY, cmd & suffix);
5314}
5315
Harald Welte261af4b2018-02-12 21:20:39 +01005316/* 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 +07005317private function f_vty_ss_action(TELNETasp_PT pt, charstring suffix,
5318 uint8_t bts_nr, uint8_t trx_nr,
5319 in RslChannelNr chan_nr)
5320{
Harald Welte261af4b2018-02-12 21:20:39 +01005321 /* FIXME: resolve those from component-global state */
5322 var integer ts_nr := chan_nr.tn;
5323 var integer ss_nr;
5324 if (ischosen(chan_nr.u.ch0)) {
5325 ss_nr := 0;
5326 } else if (ischosen(chan_nr.u.lm)) {
5327 ss_nr := chan_nr.u.lm.sub_chan;
5328 } else if (ischosen(chan_nr.u.sdcch4)) {
5329 ss_nr := chan_nr.u.sdcch4.sub_chan;
5330 } else if (ischosen(chan_nr.u.sdcch8)) {
5331 ss_nr := chan_nr.u.sdcch8.sub_chan;
5332 } else {
5333 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02005334 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01005335 }
5336
5337 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
5338 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005339 f_vty_transceive(pt, cmd & suffix);
Harald Welte261af4b2018-02-12 21:20:39 +01005340}
5341
Neels Hofmeyr91401012019-07-11 00:42:35 +02005342/* Even though the VTY command to trigger handover takes a new BTS number as argument, behind the scenes osmo-bsc always
5343 * translates that to a target ARFCN+BSIC first. See bsc_vty.c trigger_ho_or_as(), which puts the selected BTS' neighbor
5344 * ident key (ARFCN + BSIC) in the struct passed on to handover_request(). handover_start() then resolves that to a
5345 * viable actual neighbor cell. So from the internal osmo-bsc perspective, we always request handover to an ARFCN + BSIC
5346 * pair, not really to a specific BTS number. */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005347private function f_vty_handover(TELNETasp_PT pt, uint8_t bts_nr, uint8_t trx_nr,
5348 in RslChannelNr chan_nr, uint8_t new_bts_nr)
5349{
5350 f_vty_ss_action(pt, "handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
Harald Welte261af4b2018-02-12 21:20:39 +01005351}
5352
5353/* intra-BSC hand-over between BTS0 and BTS1 */
5354private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02005355 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5356 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01005357
5358 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5359 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5360
Harald Weltea0630032018-03-20 21:09:55 +01005361 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005362 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Harald Welte261af4b2018-02-12 21:20:39 +01005363
5364 var HandoverState hs := {
5365 rr_ho_cmpl_seen := false,
5366 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02005367 old_chan_nr := -,
5368 expect_target_tsc := BTS_TSC[1]
Harald Welte261af4b2018-02-12 21:20:39 +01005369 };
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005370 /* issue hand-over command on VTY, from BTS 0 to BTS 1 */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005371 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
Harald Welte261af4b2018-02-12 21:20:39 +01005372 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
5373 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005374
5375 /* From the MGW perspective, a handover is is characterized by
5376 * performing one MDCX operation with the MGW. So we expect to see
5377 * one more MDCX during handover. */
5378 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
5379
Harald Welte261af4b2018-02-12 21:20:39 +01005380 alt {
5381 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01005382 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005383
Philipp Maier4dae0652018-11-12 12:03:26 +01005384 /* Since this is an internal handover we expect the BSC to inform the
5385 * MSC about the event */
5386 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
5387
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005388 /* Check the amount of MGCP transactions is still consistant with the
5389 * test expectation */
5390 f_check_mgcp_expectations()
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005391
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005392 var RSL_Message chan_act := f_rslem_get_last_act(RSL1_PROC, 0, g_chan_nr);
5393
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005394 /* Ensure the Channel Activation for the new channel contained the right encryption params. as_handover() set
5395 * 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 +02005396 f_verify_encr_info(chan_act);
5397
5398 f_chan_act_verify_tsc(chan_act, BTS_TSC[1]);
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005399
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005400 f_perform_clear(RSL1, RSL1_PROC);
5401
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01005402 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01005403}
5404
5405testcase TC_ho_int() runs on test_CT {
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02005406 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte261af4b2018-02-12 21:20:39 +01005407 var MSC_ConnHdlr vc_conn;
5408 f_init(2, true);
5409 f_sleep(1.0);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005410
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005411 pars.expect_tsc := BTS_TSC[0];
5412
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005413 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005414
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02005415 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
Harald Welte261af4b2018-02-12 21:20:39 +01005416 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005417
5418 /* from f_establish_fully() */
5419 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5420 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5421 /* from handover */
5422 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5423 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5424 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5425 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005426 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5427 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:completed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005428 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005429 f_shutdown_helper();
Harald Welte261af4b2018-02-12 21:20:39 +01005430}
Harald Weltee9e02e42018-01-31 23:36:25 +01005431
Oliver Smith7eabd312021-07-12 14:18:56 +02005432function 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 +02005433 var MSC_ConnHdlr vc_conn;
5434 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5435 pars.encr := valueof(t_EncrParams(encr_alg, f_rnd_octstring(8), f_rnd_octstring(16)));
5436
5437 f_init(2, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02005438 f_vty_encryption_a5(enc_a5);
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005439 f_sleep(1.0);
5440
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005441 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005442
5443 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
5444 vc_conn.done;
5445
5446 /* from f_establish_fully() */
5447 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5448 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5449 /* from handover */
5450 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5451 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5452 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5453 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005454 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5455 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:completed");
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005456 f_ctrs_bsc_and_bts_verify();
Oliver Smith7eabd312021-07-12 14:18:56 +02005457 f_vty_encryption_a5_reset();
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005458 f_shutdown_helper();
5459}
5460
5461testcase TC_ho_int_a5_0() runs on test_CT {
5462 f_tc_ho_int_a5('01'O);
5463}
5464
5465testcase TC_ho_int_a5_1() runs on test_CT {
5466 f_tc_ho_int_a5('02'O);
5467}
5468
5469testcase TC_ho_int_a5_3() runs on test_CT {
5470 f_tc_ho_int_a5('08'O);
5471}
5472
5473testcase TC_ho_int_a5_4() runs on test_CT {
Oliver Smith7eabd312021-07-12 14:18:56 +02005474 f_tc_ho_int_a5('10'O, "0 1 3 4");
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005475}
5476
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005477/* intra-BSC hand-over with CONNection FAILure and cause Radio Link Failure: check RR release cause */
5478private function f_tc_ho_int_radio_link_failure(charstring id) runs on MSC_ConnHdlr {
5479 g_pars := f_gen_test_hdlr_pars();
5480 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5481 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005482
5483 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5484 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5485
5486 f_establish_fully(ass_cmd, exp_compl);
5487 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
5488
5489 var HandoverState hs := {
5490 rr_ho_cmpl_seen := false,
5491 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02005492 old_chan_nr := -,
5493 expect_target_tsc := BTS_TSC[1]
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005494 };
5495 /* issue hand-over command on VTY */
5496 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
5497 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
5498 f_rslem_suspend(RSL1_PROC);
5499
5500 /* From the MGW perspective, a handover is is characterized by
5501 * performing one MDCX operation with the MGW. So we expect to see
5502 * one more MDCX during handover. */
5503 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
5504
5505 var RSL_Message rsl;
5506 var PDU_ML3_NW_MS l3;
5507 var RslChannelNr new_chan_nr;
5508 var GsmArfcn arfcn;
5509 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
5510 l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
5511 if (not ischosen(l3.msgs.rrm.handoverCommand)) {
5512 setverdict(fail, "Expected handoverCommand");
5513 mtc.stop;
5514 }
5515 }
5516 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
5517 new_chan_nr, arfcn);
5518
5519 f_rslem_register(0, new_chan_nr, RSL1_PROC);
5520
5521 /* resume processing of RSL DChan messages, which was temporarily suspended
5522 * before performing a hand-over */
5523 f_rslem_resume(RSL1_PROC);
5524 RSL1.receive(tr_RSL_IPA_CRCX(new_chan_nr));
5525
5526 f_sleep(1.0);
5527
5528 /* Handover fails because no HANDO DET appears on the new lchan,
5529 * and the old lchan reports a Radio Link Failure. */
5530 RSL.send(ts_RSL_CONN_FAIL_IND(g_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
5531
5532 var PDU_BSSAP rx_clear_request;
5533 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
5534 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5535 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5536
5537 var RR_Cause rr_cause := GSM48_RR_CAUSE_ABNORMAL_UNSPEC;
5538
5539 var MgcpCommand mgcp;
5540 interleave {
5541 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE(int2oct(enum2int(rr_cause), 1)))) {}
5542 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005543 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005544 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005545 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005546 }
5547 [] RSL1.receive(tr_RSL_DEACT_SACCH(new_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005548 [] RSL1.receive(tr_RSL_RF_CHAN_REL(new_chan_nr)) {
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005549 RSL1.send(ts_RSL_RF_CHAN_REL_ACK(new_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005550 f_rslem_unregister(0, g_chan_nr, PT := RSL1_PROC);
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005551 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005552 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
5553 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
5554 }
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005555 }
5556
5557 f_sleep(0.5);
5558 setverdict(pass);
5559}
5560testcase TC_ho_int_radio_link_failure() runs on test_CT {
5561 var MSC_ConnHdlr vc_conn;
5562 f_init(2, true);
5563 f_sleep(1.0);
5564
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005565 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005566
5567 vc_conn := f_start_handler(refers(f_tc_ho_int_radio_link_failure));
5568 vc_conn.done;
5569
5570 /* from f_establish_fully() */
5571 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5572 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5573 /* from handover */
5574 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5575 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
5576 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5577 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:stopped");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005578 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5579 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:stopped");
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005580 f_ctrs_bsc_and_bts_verify();
5581 f_shutdown_helper();
5582}
5583
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005584/* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005585private function f_expect_dlcx_conns() runs on MSC_ConnHdlr {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005586 var MgcpCommand mgcp;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005587 var template MgcpResponse mgcp_resp;
5588 var MGCP_RecvFrom mrf;
5589 var template MgcpMessage msg_resp;
5590 var template MgcpMessage msg_dlcx := {
5591 command := tr_DLCX()
5592 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005593
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005594 if (g_pars.aoip) {
5595 MGCP.receive(tr_DLCX()) -> value mgcp {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005596 log("Got first DLCX: ", mgcp);
5597 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005598 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005599
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005600 MGCP.receive(tr_DLCX()) -> value mgcp {
5601 log("Got second DLCX: ", mgcp);
5602 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
5603 };
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005604 } else {
5605 /* For SCCPLite, BSC doesn't handle the MSC-side */
5606 MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_dlcx)) -> value mrf {
5607 log("Got first DLCX: ", mrf.msg.command);
5608 msg_resp := {
5609 response := ts_DLCX_ACK2(mrf.msg.command.line.trans_id)
5610 }
5611 MGCP_MULTI.send(t_MGCP_SendToMrf(mrf, msg_resp));
5612 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005613 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005614}
5615
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005616private 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 +01005617
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005618 var NcellReports neighbor_rep := {
5619 { rxlev := 20, bcch_freq := 0, bsic := 11 }
5620 };
5621 var octetstring l3_mr := enc_GsmRrL3Message(valueof(ts_MEAS_REP(true, 8, 8, reps := neighbor_rep)));
5622 RSL.send(ts_RSL_MEAS_RES(g_chan_nr, 0, ts_RSL_IE_UplinkMeas, ts_RSL_IE_BS_Power(0), ts_RSL_IE_L1Info,
5623 l3_mr, 0));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005624
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005625 BSSAP.receive(tr_BSSMAP_HandoverRequired(exp_oldToNewBSSIEs));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005626
5627 f_sleep(0.5);
5628 /* The MSC negotiates Handover Request and Handover Request Ack with
5629 * the other BSS and comes back with a BSSMAP Handover Command
5630 * containing an RR Handover Command coming from the target BSS... */
5631
5632 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5633 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5634 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5635 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5636 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5637
5638 /* expect the Handover Command to go out on RR */
5639 var RSL_Message rsl_ho_cmd
5640 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5641 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5642 var RSL_IE_Body rsl_ho_cmd_l3;
5643 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5644 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5645 setverdict(fail);
5646 } else {
5647 log("Found L3 Info: ", rsl_ho_cmd_l3);
5648 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5649 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5650 setverdict(fail);
5651 } else {
5652 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5653 setverdict(pass);
5654 }
5655 }
5656
5657 /* When the other BSS has reported a completed handover, this side is
5658 * torn down. */
5659
5660 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
5661 var BssmapCause cause := enum2int(cause_val);
5662 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5663
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005664 f_expect_dlcx_conns();
Pau Espin Pedrol06199952021-06-15 11:30:00 +02005665
5666 interleave {
5667 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE));
5668 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr));
5669 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr));
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005670 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
5671 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
5672 }
Pau Espin Pedrol06199952021-06-15 11:30:00 +02005673 }
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005674 setverdict(pass);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005675}
5676
5677private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
5678 g_pars := f_gen_test_hdlr_pars();
5679 var PDU_BSSAP ass_req := f_gen_ass_req();
5680 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5681 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5682 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5683 f_establish_fully(ass_req, exp_compl);
5684
5685 f_ho_out_of_this_bsc();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005686}
5687testcase TC_ho_out_of_this_bsc() runs on test_CT {
5688 var MSC_ConnHdlr vc_conn;
5689
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005690 f_init_vty();
5691 f_bts_0_cfg(BSCVTY,
5692 {"neighbor-list mode automatic",
5693 "handover 1",
5694 "handover algorithm 2",
5695 "handover2 window rxlev averaging 1",
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005696 "no neighbors",
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005697 "neighbor lac 99 arfcn 123 bsic any"});
5698 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5699
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005700 f_init(1, true);
5701 f_sleep(1.0);
5702
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005703 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005704
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005705 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
5706 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005707
5708 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5709 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5710 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5711 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5712 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5713 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed");
5714 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005715 f_shutdown_helper();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005716}
5717
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005718private function f_mo_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5719 template (value) RslLinkId link_id := ts_RslLinkID_DCCH(0),
Vadim Yanitskiy2ef6a2f2020-10-08 23:17:32 +07005720 template (present) OCT1 dlci := ?,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005721 octetstring l3 := '0123456789'O)
5722runs on MSC_ConnHdlr {
Neels Hofmeyr43654812020-09-25 01:35:35 +02005723 /* The old lchan and conn should still be active. See that arbitrary L3
5724 * is still going through. */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005725 rsl.send(ts_RSL_DATA_IND(g_chan_nr, link_id, l3));
Neels Hofmeyr43654812020-09-25 01:35:35 +02005726 var template PDU_BSSAP exp_data := {
5727 discriminator := '1'B,
5728 spare := '0000000'B,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005729 dlci := dlci,
5730 lengthIndicator := lengthof(l3),
Neels Hofmeyr43654812020-09-25 01:35:35 +02005731 pdu := {
5732 dtap := l3
5733 }
5734 };
5735 BSSAP.receive(exp_data);
5736 setverdict(pass);
5737}
5738
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005739private function f_mt_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5740 template (present) RslLinkId link_id := tr_RslLinkID_DCCH(0),
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005741 template (value) OCT1 dlci := '00'O,
5742 octetstring l3 := '0123456789'O)
5743runs on MSC_ConnHdlr {
5744 BSSAP.send(PDU_BSSAP:{
5745 discriminator := '1'B,
5746 spare := '0000000'B,
5747 dlci := dlci,
5748 lengthIndicator := lengthof(l3),
5749 pdu := {
5750 dtap := l3
5751 }
5752 });
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005753 rsl.receive(tr_RSL_DATA_REQ(g_chan_nr, link_id, l3));
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005754 setverdict(pass);
5755}
5756
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005757/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
5758 * simply never sends a BSSMAP Handover Command. */
5759private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005760 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005761
5762 var PDU_BSSAP ass_req := f_gen_ass_req();
5763 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5764 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5765 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5766 f_establish_fully(ass_req, exp_compl);
5767
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005768 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005769 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5770
5771 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5772
5773 /* osmo-bsc should time out 10 seconds after the handover started.
5774 * Let's give it a bit extra. */
5775 f_sleep(15.0);
5776
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005777 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005778 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005779 f_perform_clear();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005780}
5781testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
5782 var MSC_ConnHdlr vc_conn;
5783
5784 f_init(1, true);
5785 f_sleep(1.0);
5786
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005787 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005788
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005789 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
5790 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005791
5792 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5793 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5794 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5795 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5796 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5797 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5798 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005799 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005800}
5801
5802/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
5803 * RR Handover Failure. */
5804private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005805 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005806
5807 var PDU_BSSAP ass_req := f_gen_ass_req();
5808 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5809 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5810 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5811 f_establish_fully(ass_req, exp_compl);
5812
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005813 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005814 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5815
5816 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5817
5818 f_sleep(0.5);
5819 /* The MSC negotiates Handover Request and Handover Request Ack with
5820 * the other BSS and comes back with a BSSMAP Handover Command
5821 * containing an RR Handover Command coming from the target BSS... */
5822
5823 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5824 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5825 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5826 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5827 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5828
5829 /* expect the Handover Command to go out on RR */
5830 var RSL_Message rsl_ho_cmd
5831 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5832 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5833 var RSL_IE_Body rsl_ho_cmd_l3;
5834 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5835 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5836 setverdict(fail);
5837 } else {
5838 log("Found L3 Info: ", rsl_ho_cmd_l3);
5839 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5840 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5841 setverdict(fail);
5842 } else {
5843 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5844 setverdict(pass);
5845 }
5846 }
5847
5848 f_sleep(0.2);
5849 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
5850
5851 /* Should tell the MSC about the failure */
5852 BSSAP.receive(tr_BSSMAP_HandoverFailure);
5853
5854 f_sleep(1.0);
5855
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005856 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005857 f_sleep(1.0);
5858
5859 setverdict(pass);
5860 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005861 f_perform_clear();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005862}
5863testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
5864 var MSC_ConnHdlr vc_conn;
5865
5866 f_init(1, true);
5867 f_sleep(1.0);
5868
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005869 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005870
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005871 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
5872 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005873
5874 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5875 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5876 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5877 f_ctrs_bsc_and_bts_add(0, "handover:failed");
5878 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5879 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:failed");
5880 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005881 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005882}
5883
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005884/* BSC asks for inter-BSC-out HO, receives BSSMAP Handover Command, but then no reply is received about HO outcome
5885 * (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 +02005886 * and the lchan is released. */
5887private function f_tc_ho_out_fail_no_result_after_ho_cmd(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005888 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005889
5890 var PDU_BSSAP ass_req := f_gen_ass_req();
5891 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5892 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5893 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5894 f_establish_fully(ass_req, exp_compl);
5895
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005896 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005897 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5898
5899 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5900
5901 f_sleep(0.5);
5902 /* The MSC negotiates Handover Request and Handover Request Ack with
5903 * the other BSS and comes back with a BSSMAP Handover Command
5904 * containing an RR Handover Command coming from the target BSS... */
5905
5906 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5907 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5908 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5909 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5910 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5911
5912 /* expect the Handover Command to go out on RR */
5913 var RSL_Message rsl_ho_cmd
5914 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5915 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5916 var RSL_IE_Body rsl_ho_cmd_l3;
5917 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5918 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5919 setverdict(fail);
5920 } else {
5921 log("Found L3 Info: ", rsl_ho_cmd_l3);
5922 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5923 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5924 setverdict(fail);
5925 } else {
5926 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5927 setverdict(pass);
5928 }
5929 }
5930
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005931 /* We get neither success nor failure report from the remote BSS. Eventually T8 times out and we run into 3GPP
5932 * TS 48.008 3.1.5.3.3 "Abnormal Conditions": Clear Request should go to the MSC, and RR should be released
5933 * after Clear Command */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005934
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005935 var PDU_BSSAP rx_clear_request;
Neels Hofmeyre1797aa2019-07-09 19:34:04 +02005936 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
5937 log("Got BSSMAP Clear Request");
5938 /* Instruct BSC to clear channel */
5939 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5940 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5941
5942 var MgcpCommand mgcp;
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005943 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01005944 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
5945 log("Got Deact SACCH");
5946 }
Harald Welte924b6ea2019-02-04 01:05:34 +01005947 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01005948 log("Got RR Release");
5949 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005950 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005951 log("Got RF Chan Rel");
5952 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005953 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005954 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005955 }
5956
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005957 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02005958 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005959 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005960
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005961 setverdict(pass);
5962 f_sleep(1.0);
5963}
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02005964testcase TC_ho_out_fail_no_result_after_ho_cmd() runs on test_CT {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005965 var MSC_ConnHdlr vc_conn;
5966
5967 f_init(1, true);
5968 f_sleep(1.0);
5969
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005970 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005971
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02005972 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_result_after_ho_cmd));
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005973 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005974
5975 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5976 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5977 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5978 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5979 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5980 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5981 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005982 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005983}
5984
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005985private function f_ho_into_this_bsc(charstring id, template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit) runs on MSC_ConnHdlr {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005986 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
5987 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
5988 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
5989 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
5990 * before we get started. */
5991 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
5992 f_rslem_register(0, new_chan_nr);
5993 g_chan_nr := new_chan_nr;
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02005994 var uint3_t expect_target_tsc := BTS_TSC[0];
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005995 f_sleep(1.0);
5996
5997 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
5998 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
5999 activate(as_Media());
6000
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006001 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006002 f_gen_handover_req(aoip_tla := g_pars.host_aoip_tla,
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006003 oldToNewBSSIEs := oldToNewBSSIEs,
6004 enc := g_pars.encr)));
Harald Welte6811d102019-04-14 22:23:14 +02006005 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006006
6007 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6008
6009 var PDU_BSSAP rx_bssap;
6010 var octetstring ho_command_str;
6011
6012 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
Pau Espin Pedrol76ba5412019-06-10 11:00:33 +02006013
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02006014 /* we're sure that the channel activation is done now, verify the parameters in it */
6015 var RSL_Message chan_act := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
6016 f_verify_encr_info(chan_act);
6017 f_chan_act_verify_tsc(chan_act, expect_target_tsc);
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006018
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006019 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6020 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6021 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6022 log("L3 Info in HO Request Ack is ", ho_command);
6023
6024 var GsmArfcn arfcn;
6025 var RslChannelNr actual_new_chan_nr;
6026 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6027 actual_new_chan_nr, arfcn);
6028
6029 if (actual_new_chan_nr != new_chan_nr) {
6030 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6031 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6032 setverdict(fail);
6033 return;
6034 }
6035 log("Handover Command chan_nr is", actual_new_chan_nr);
6036
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02006037 var uint3_t got_tsc := rr_chan_desc_tsc(ho_command.msgs.rrm.handoverCommand.channelDescription2);
6038 if (not match(got_tsc, expect_target_tsc)) {
6039 setverdict(fail, "RR Handover Command: unexpected TSC in Channel Description: expected ",
6040 expect_target_tsc, " got ", got_tsc);
6041 mtc.stop;
6042 } else {
6043 log("handoverCommand: verified TSC = ", got_tsc);
6044 }
6045
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006046 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6047 * tells the MS to handover to the new lchan. Here comes the new MS on
6048 * the new lchan with a Handover RACH: */
6049
6050 /* send handover detect */
6051
6052 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
6053
6054 BSSAP.receive(tr_BSSMAP_HandoverDetect);
6055
6056 /* send handover complete over the new channel */
6057
6058 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
6059 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
6060 enc_PDU_ML3_MS_NW(l3_tx)));
6061
6062 BSSAP.receive(tr_BSSMAP_HandoverComplete);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006063 setverdict(pass);
6064}
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006065
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006066private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006067 var template PDU_ML3_NW_MS exp_rr_rel_tmpl;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006068 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit;
6069 if (not istemplatekind(g_pars.last_used_eutran_plmn, "omit")) {
6070 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006071 }
6072 if (g_pars.exp_fast_return) {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006073 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE_CellSelectInd;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006074 } else {
6075 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006076 }
6077 f_ho_into_this_bsc(id, oldToNewBSSIEs);
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02006078 f_perform_clear(exp_rr_rel_tmpl := exp_rr_rel_tmpl);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006079 setverdict(pass);
6080}
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006081function f_tc_ho_into_this_bsc_main(TestHdlrParams pars) runs on test_CT {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006082 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006083
6084 f_init(1, true);
6085 f_sleep(1.0);
6086
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006087 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006088
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006089 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6090 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006091
6092 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
6093 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006094
6095 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6096 f_ctrs_bsc_and_bts_add(0, "handover:completed");
6097 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6098 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed");
6099 f_ctrs_bsc_and_bts_verify();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006100}
6101
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006102testcase TC_ho_into_this_bsc() runs on test_CT {
6103 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6104 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006105 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006106}
6107
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006108function f_tc_ho_into_this_bsc_a5(OCT1 encr_alg) runs on test_CT {
6109 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6110 pars.encr := valueof(t_EncrParams(encr_alg, f_rnd_octstring(8), f_rnd_octstring(16)));
6111 f_tc_ho_into_this_bsc_main(pars);
6112 f_shutdown_helper();
6113}
6114
6115testcase TC_ho_into_this_bsc_a5_0() runs on test_CT {
6116 f_tc_ho_into_this_bsc_a5('01'O);
6117}
6118
6119testcase TC_ho_into_this_bsc_a5_1() runs on test_CT {
6120 f_tc_ho_into_this_bsc_a5('02'O);
6121}
6122
6123testcase TC_ho_into_this_bsc_a5_3() runs on test_CT {
6124 f_tc_ho_into_this_bsc_a5('08'O);
6125}
6126
6127testcase TC_ho_into_this_bsc_a5_4() runs on test_CT {
6128 f_tc_ho_into_this_bsc_a5('10'O);
6129}
6130
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006131testcase TC_ho_into_this_bsc_tla_v6() runs on test_CT {
6132 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6133 pars.host_aoip_tla := "::6";
6134 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006135 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006136}
6137
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006138/* Similar to TC_ho_into_this_bsc, but when in SRVCC, HO Req contains "Old BSS
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006139 to New BSS Information" IE with "Last Used E-UTRAN PLMN Id", which, when the
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006140 channel is later released (RR CHannel Release), should trigger inclusion of
6141 IE "Cell Selection Indicator after Release of all TCH and SDCCH" with E-UTRAN
6142 neighbors. */
6143testcase TC_srvcc_eutran_to_geran() runs on test_CT {
6144 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6145 pars.last_used_eutran_plmn := '323454'O;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006146 pars.exp_fast_return := true;
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006147 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02006148
6149 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted");
6150 f_ctrs_bsc_and_bts_add(0, "srvcc:completed");
6151 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006152 f_shutdown_helper();
6153}
6154
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006155/* Same as TC_srvcc_eutran_to_geran, but test explicitly forbiding fast return
6156 on the BTS. As a result, RR Release shouldn't contain the EUTRAN neighbor
6157 list when the channel is released. */
6158testcase TC_srvcc_eutran_to_geran_forbid_fast_return() runs on test_CT {
6159 f_init_vty();
6160 f_vty_allow_srvcc_fast_return(true, 0)
6161
6162 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6163 pars.last_used_eutran_plmn := '323454'O;
6164 pars.exp_fast_return := false;
6165 f_tc_ho_into_this_bsc_main(pars);
6166 f_vty_allow_srvcc_fast_return(false, 0);
6167 f_shutdown_helper();
6168}
6169
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006170private function f_tc_srvcc_eutran_to_geran_ho_out(charstring id) runs on MSC_ConnHdlr {
6171 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs;
6172 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
6173 f_ho_into_this_bsc(id, oldToNewBSSIEs);
6174 f_ho_out_of_this_bsc(oldToNewBSSIEs);
6175 setverdict(pass);
6176}
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006177
6178private function f_tc_srvcc_eutran_to_geran_ho_out_main(boolean disable_fast_return)
6179 runs on test_CT {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006180 var MSC_ConnHdlr vc_conn;
6181 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6182
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01006183 f_init_vty();
6184 f_bts_0_cfg(BSCVTY,
6185 {"neighbor-list mode automatic",
6186 "handover 1",
6187 "handover algorithm 2",
6188 "handover2 window rxlev averaging 1",
6189 "no neighbors",
6190 "neighbor lac 99 arfcn 123 bsic any"});
6191 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6192
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006193 f_init(1, true);
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006194 if (disable_fast_return) {
6195 f_vty_allow_srvcc_fast_return(true, 0);
6196 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006197 f_sleep(1.0);
6198
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006199 f_ctrs_bsc_and_bts_handover_init();
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006200
6201 pars.last_used_eutran_plmn := '323454'O;
6202 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6203 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
6204
6205 vc_conn := f_start_handler(refers(f_tc_srvcc_eutran_to_geran_ho_out), pars);
6206 vc_conn.done;
6207
6208 f_ctrs_bsc_and_bts_add(0, "handover:attempted", 2);
6209 f_ctrs_bsc_and_bts_add(0, "handover:completed", 2);
6210 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted", 1);
6211 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed", 1);
6212 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted", 1);
6213 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed", 1);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02006214
6215 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted", 1);
6216 f_ctrs_bsc_and_bts_add(0, "srvcc:completed", 1);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006217 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006218
6219 if (disable_fast_return) {
6220 f_vty_allow_srvcc_fast_return(false, 0);
6221 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006222 f_shutdown_helper();
6223}
6224
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006225/* First, HO into BSC from EUTRAN (SRVCC): HO Request contains "Old BSS to New
6226 BSS Information" IE with "Last Used E-UTRAN PLMN Id".
6227 Second, HO to another BSC: HO Required contains "Old BSS to New BSS Information"
6228 IE with "Last Used E-UTRAN PLMN Id" from first step. */
6229testcase TC_srvcc_eutran_to_geran_ho_out() runs on test_CT {
6230 f_tc_srvcc_eutran_to_geran_ho_out_main(false);
6231}
6232/* Validate subsequent intra-GSM-HO works the same (with OldBSSToNewBSSInfo IE)
6233 * independently of fast-reture allowed/forbidden in local BTS */
6234testcase TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() runs on test_CT {
6235 f_tc_srvcc_eutran_to_geran_ho_out_main(true);
6236}
6237
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006238private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
6239 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6240 f_rslem_register(0, new_chan_nr);
6241 g_chan_nr := new_chan_nr;
6242 f_sleep(1.0);
6243
6244 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6245 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6246 activate(as_Media());
6247
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006248 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006249 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006250 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006251
6252 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6253
6254 var PDU_BSSAP rx_bssap;
6255 var octetstring ho_command_str;
6256
6257 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6258
6259 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6260 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6261 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6262 log("L3 Info in HO Request Ack is ", ho_command);
6263
6264 var GsmArfcn arfcn;
6265 var RslChannelNr actual_new_chan_nr;
6266 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6267 actual_new_chan_nr, arfcn);
6268
6269 if (actual_new_chan_nr != new_chan_nr) {
6270 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6271 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6272 setverdict(fail);
6273 return;
6274 }
6275 log("Handover Command chan_nr is", actual_new_chan_nr);
6276
Neels Hofmeyr61ca08d2019-05-06 23:52:22 +02006277 /* For deterministic test results, give some time for the MGW endpoint to be configured */
6278 f_sleep(1.0);
6279
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006280 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6281 * tells the MS to handover to the new lchan. In this case, the MS
6282 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
6283 * Handover Failure to the MSC. The procedure according to 3GPP TS
6284 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
6285 * BSSMAP Clear Command: */
6286
6287 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6288 var BssmapCause cause := enum2int(cause_val);
6289 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6290
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006291 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006292 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006293 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006294
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006295 setverdict(pass);
6296 f_sleep(1.0);
6297
6298 setverdict(pass);
6299}
6300testcase TC_ho_in_fail_msc_clears() runs on test_CT {
6301 var MSC_ConnHdlr vc_conn;
6302 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6303
6304 f_init(1, true);
6305 f_sleep(1.0);
6306
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006307 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006308
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006309 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6310 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006311
6312 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
6313 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006314
6315 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6316 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
6317 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6318 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
6319 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006320 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006321}
6322
6323private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
6324 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
6325 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
6326 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
6327 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
6328 * before we get started. */
6329 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6330 f_rslem_register(0, new_chan_nr);
6331 g_chan_nr := new_chan_nr;
6332 f_sleep(1.0);
6333
6334 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6335 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6336 activate(as_Media());
6337
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006338 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006339 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006340 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006341
6342 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6343
6344 var PDU_BSSAP rx_bssap;
6345 var octetstring ho_command_str;
6346
6347 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6348
6349 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6350 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6351 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6352 log("L3 Info in HO Request Ack is ", ho_command);
6353
6354 var GsmArfcn arfcn;
6355 var RslChannelNr actual_new_chan_nr;
6356 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6357 actual_new_chan_nr, arfcn);
6358
6359 if (actual_new_chan_nr != new_chan_nr) {
6360 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6361 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6362 setverdict(fail);
6363 return;
6364 }
6365 log("Handover Command chan_nr is", actual_new_chan_nr);
6366
6367 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6368 * tells the MS to handover to the new lchan. Here comes the new MS on
6369 * the new lchan with a Handover RACH: */
6370
6371 /* send handover detect */
6372
6373 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
6374
6375 BSSAP.receive(tr_BSSMAP_HandoverDetect);
6376
6377 /* The MSC chooses to clear the connection now, maybe we got the
6378 * Handover RACH on the new cell but the MS still signaled Handover
6379 * Failure to the old BSS? */
6380
6381 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6382 var BssmapCause cause := enum2int(cause_val);
6383 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6384
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006385 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006386 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006387 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006388
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006389 f_sleep(1.0);
6390}
6391testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
6392 var MSC_ConnHdlr vc_conn;
6393 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6394
6395 f_init(1, true);
6396 f_sleep(1.0);
6397
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006398 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006399
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006400 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6401 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006402
6403 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
6404 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006405
6406 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6407 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
6408 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6409 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
6410 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006411 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006412}
6413
6414/* The new BSS's lchan times out before the MSC decides that handover failed. */
6415private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
6416 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6417 f_rslem_register(0, new_chan_nr);
6418 g_chan_nr := new_chan_nr;
6419 f_sleep(1.0);
6420
6421 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6422 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6423 activate(as_Media());
6424
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006425 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006426 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006427 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006428
6429 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6430
6431 var PDU_BSSAP rx_bssap;
6432 var octetstring ho_command_str;
6433
6434 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6435
6436 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6437 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6438 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6439 log("L3 Info in HO Request Ack is ", ho_command);
6440
6441 var GsmArfcn arfcn;
6442 var RslChannelNr actual_new_chan_nr;
6443 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6444 actual_new_chan_nr, arfcn);
6445
6446 if (actual_new_chan_nr != new_chan_nr) {
6447 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6448 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6449 setverdict(fail);
6450 return;
6451 }
6452 log("Handover Command chan_nr is", actual_new_chan_nr);
6453
6454 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6455 * tells the MS to handover to the new lchan. But the MS never shows up
6456 * on the new lchan. */
6457
6458 BSSAP.receive(tr_BSSMAP_HandoverFailure);
6459
6460 /* Did osmo-bsc also send a Clear Request? */
6461 timer T := 0.5;
6462 T.start;
6463 alt {
6464 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
6465 [] T.timeout { }
6466 }
6467
6468 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
6469 * asked for it, this is a Handover Failure after all). */
6470
6471 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6472 var BssmapCause cause := enum2int(cause_val);
6473 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6474
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006475 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006476 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006477 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006478
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006479 f_sleep(1.0);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006480}
6481testcase TC_ho_in_fail_no_detect() runs on test_CT {
6482 var MSC_ConnHdlr vc_conn;
6483 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6484
6485 f_init(1, true);
6486 f_sleep(1.0);
6487
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006488 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006489
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006490 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6491 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006492
6493 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
6494 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006495
6496 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6497 f_ctrs_bsc_and_bts_add(0, "handover:error");
6498 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6499 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
6500 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006501 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006502}
6503
6504/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
6505private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
6506 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6507 f_rslem_register(0, new_chan_nr);
6508 g_chan_nr := new_chan_nr;
6509 f_sleep(1.0);
6510
6511 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6512 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6513 activate(as_Media());
6514
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006515 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006516 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006517 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006518
6519 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6520
6521 var PDU_BSSAP rx_bssap;
6522 var octetstring ho_command_str;
6523
6524 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6525
6526 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6527 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6528 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6529 log("L3 Info in HO Request Ack is ", ho_command);
6530
6531 var GsmArfcn arfcn;
6532 var RslChannelNr actual_new_chan_nr;
6533 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6534 actual_new_chan_nr, arfcn);
6535
6536 if (actual_new_chan_nr != new_chan_nr) {
6537 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6538 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6539 setverdict(fail);
6540 return;
6541 }
6542 log("Handover Command chan_nr is", actual_new_chan_nr);
6543
6544 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6545 * tells the MS to handover to the new lchan. But the MS never shows up
6546 * on the new lchan. */
6547
6548 BSSAP.receive(tr_BSSMAP_HandoverFailure);
6549
6550 /* MSC plays dumb and sends no Clear Command */
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006551 var PDU_BSSAP rx_clear_request;
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02006552
6553 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006554 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
6555 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6556 };
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006557 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006558 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006559 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006560
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006561 f_sleep(1.0);
6562}
6563testcase TC_ho_in_fail_no_detect2() runs on test_CT {
6564 var MSC_ConnHdlr vc_conn;
6565 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6566
6567 f_init(1, true);
6568 f_sleep(1.0);
6569
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006570 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006571
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006572 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6573 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006574
6575 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
6576 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006577
6578 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6579 f_ctrs_bsc_and_bts_add(0, "handover:error");
6580 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6581 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
6582 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006583 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006584}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006585
Neels Hofmeyr91401012019-07-11 00:42:35 +02006586type record of charstring Commands;
6587
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006588private function f_bts_0_cfg(TELNETasp_PT pt, Commands cmds := {})
Neels Hofmeyr91401012019-07-11 00:42:35 +02006589{
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006590 f_vty_enter_cfg_bts(pt, 0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006591 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006592 f_vty_transceive(pt, cmds[i]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006593 }
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006594 f_vty_transceive(pt, "end");
Neels Hofmeyr91401012019-07-11 00:42:35 +02006595}
6596
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01006597private function f_cs7_inst_0_cfg(TELNETasp_PT pt, Commands cmds := {})
6598{
6599 f_vty_enter_cfg_cs7_inst(pt, 0);
6600 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
6601 f_vty_transceive(pt, cmds[i]);
6602 }
6603 f_vty_transceive(pt, "end");
6604}
6605
Neels Hofmeyr91401012019-07-11 00:42:35 +02006606private function f_probe_for_handover(charstring log_label,
6607 charstring log_descr,
6608 charstring handover_vty_cmd,
6609 boolean expect_handover,
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006610 boolean is_inter_bsc_handover := false,
6611 template uint3_t expect_target_tsc := ?)
Neels Hofmeyr91401012019-07-11 00:42:35 +02006612runs on MSC_ConnHdlr
6613{
Neels Hofmeyrb3fc8982020-05-11 00:16:42 +02006614 /* We're going to thwart any and all handover attempts, just be ready to handle (and ignore) handover target
6615 * lchans to be established on bts 1 or bts 2. */
6616 f_rslem_suspend(RSL1_PROC);
6617 f_rslem_suspend(RSL2_PROC);
6618
Neels Hofmeyr91401012019-07-11 00:42:35 +02006619 var RSL_Message rsl;
6620
6621 var charstring log_msg := " (expecting handover)"
6622 if (not expect_handover) {
6623 log_msg := " (expecting NO handover)";
6624 }
6625 log("f_probe_for_handover starting: " & log_label & ": " & log_descr & log_msg);
6626 f_vty_transceive(BSCVTY, handover_vty_cmd);
6627
Neels Hofmeyr91401012019-07-11 00:42:35 +02006628 timer T := 2.0;
6629 T.start;
6630
6631 alt {
6632 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
6633 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
6634 log("Rx L3 from net: ", l3);
6635 if (ischosen(l3.msgs.rrm.handoverCommand)) {
6636 var RslChannelNr new_chan_nr;
6637 var GsmArfcn arfcn;
6638 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
6639 new_chan_nr, arfcn);
6640 log("Handover to new chan ", new_chan_nr, " on ARFCN ", arfcn);
6641 log(l3.msgs.rrm.handoverCommand);
6642
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006643 /* Verify correct TSC in handoverCommand */
6644 var uint3_t got_tsc := rr_chan_desc_tsc(l3.msgs.rrm.handoverCommand.channelDescription2);
6645 if (not match(got_tsc, expect_target_tsc)) {
6646 setverdict(fail, "RR Handover Command: unexpected TSC in Channel Description: expected ",
6647 expect_target_tsc, " got ", got_tsc);
6648 mtc.stop;
6649 } else {
6650 log("handoverCommand: verified TSC = ", got_tsc, " (matches ",
6651 expect_target_tsc, ")");
6652 }
6653
Neels Hofmeyr91401012019-07-11 00:42:35 +02006654 /* Need to register for new lchan on new BTS -- it's either bts 1 or bts 2. It doesn't really
6655 * matter on which BTS it really is, we're not going to follow through an entire handover
6656 * anyway. */
6657 f_rslem_register(0, new_chan_nr, RSL1_PROC);
6658 f_rslem_resume(RSL1_PROC);
6659 f_rslem_register(0, new_chan_nr, RSL2_PROC);
6660 f_rslem_resume(RSL2_PROC);
6661
6662 if (expect_handover and not is_inter_bsc_handover) {
6663 setverdict(pass);
6664 log("f_probe_for_handover(" & log_label & "): Got RSL Handover Command as expected.");
6665 } else {
6666 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got RSL Handover Command. "
6667 & log_label & ": " & log_descr);
6668 }
6669
6670 log("f_probe_for_handover(" & log_label & "): Ending the test: Handover Failure stops the procedure.");
6671 /* osmo-bsc has triggered Handover. That's all we need to know for this test, reply with
6672 * Handover Failure. */
6673 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
6674
6675 /* target BTS is told to release lchan again; don't care which BTS nor what messages. */
6676 f_sleep(0.5);
6677 RSL1.clear;
6678 RSL2.clear;
6679 log("f_probe_for_handover(" & log_label & "): done (got RSL Handover Command)");
6680 break;
6681 } else {
6682 repeat;
6683 }
6684 }
6685 [] BSSAP.receive(tr_BSSMAP_HandoverRequired) {
6686 if (expect_handover and is_inter_bsc_handover) {
6687 setverdict(pass);
6688 log("f_probe_for_handover(" & log_label & "): Got BSSMAP Handover Required as expected.");
6689 } else {
6690 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got BSSMAP Handover Required. "
6691 & log_label & ": " & log_descr);
6692 }
6693
6694 log("f_probe_for_handover(" & log_label & "): done (got BSSMAP Handover Required)");
6695
6696 /* Note: f_tc_ho_neighbor_config_start() sets T7, the timeout for BSSMAP Handover Required, to
6697 * 1 second. There is no legal way to quickly abort a handover after a BSSMAP Handover Required,
6698 * setting a short timeout and waiting is the only way. */
6699 log("f_probe_for_handover(" & log_label & "): waiting for inter-BSC HO to time out...");
6700 f_sleep(1.5);
6701 log("f_probe_for_handover(" & log_label & "): ...done");
6702
6703 break;
6704 }
6705 [] T.timeout {
6706 if (expect_handover) {
6707 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected Handover, but got none. "
6708 & log_label & ": " & log_descr);
6709 } else {
6710 setverdict(pass);
6711 log("f_probe_for_handover(" & log_label & "): Got no Handover, as expected.");
6712 }
6713 log("f_probe_for_handover(" & log_label & "): done (got no Handover)");
6714 break;
6715 }
6716 }
6717
6718 f_rslem_resume(RSL1_PROC);
6719 f_rslem_resume(RSL2_PROC);
6720 f_sleep(3.0);
6721 RSL.clear;
6722
6723 log("f_probe_for_handover(" & log_label & "): done clearing");
6724}
6725
6726/* Test the effect of various neighbor configuration scenarios:
6727 *
6728 * To avoid complexity, block off any actual handover operation, and always remain on the lchan at bts 0.
6729 * Reconfigure the neighbors for bts 0, trigger a Handover, and probe whether osmo-bsc does or doesn't start HO.
6730 */
6731private function f_tc_ho_neighbor_config_start() runs on MSC_ConnHdlr {
6732 g_pars := f_gen_test_hdlr_pars();
6733 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
6734 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006735
6736 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
6737 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
6738
6739 /* Establish lchan at bts 0 */
6740 f_establish_fully(ass_cmd, exp_compl);
6741
6742 /* Shorten the inter-BSC Handover timeout, to not wait so long for inter-BSC Handovers */
6743 f_vty_enter_cfg_network(BSCVTY);
6744 f_vty_transceive(BSCVTY, "timer T7 1");
6745 f_vty_transceive(BSCVTY, "end");
6746}
6747
6748private function f_tc_ho_neighbor_config_1(charstring id) runs on MSC_ConnHdlr {
6749 f_tc_ho_neighbor_config_start();
6750
6751 /*
6752 * bts 0 ARFCN 871 BSIC 10
6753 * bts 1 ARFCN 871 BSIC 11
6754 * bts 2 ARFCN 871 BSIC 12
6755 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6756 */
6757
6758 log("f_tc_ho_neighbor_config: 1. No 'neighbor' config");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006759 f_bts_0_cfg(BSCVTY, {"no neighbors"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006760 f_probe_for_handover("1.a", "HO to bts 1 works, implicitly listed as neighbor (legacy behavior when none are configured)",
6761 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006762 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006763
6764 f_probe_for_handover("1.b", "HO to unknown cell does not start",
6765 "handover any to arfcn 13 bsic 39",
6766 false);
6767
6768 f_probe_for_handover("1.c", "HO to 871-12 is ambiguous = error",
6769 "handover any to arfcn 871 bsic 12",
6770 false);
6771
6772 f_probe_for_handover("1.d", "HO to 871-11 still works (verify that this test properly cleans up)",
6773 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006774 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006775
6776 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006777}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006778testcase TC_ho_neighbor_config_1() runs on test_CT {
6779 var MSC_ConnHdlr vc_conn;
6780 f_init(3, true, guard_timeout := 60.0);
6781 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006782 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006783 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_1));
6784 vc_conn.done;
6785
6786 /* f_tc_ho_neighbor_config_start() */
6787 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6788 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6789
6790 /* 1.a */
6791 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6792 * handover quickly by sending a Handover Failure message. */
6793 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6794 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6795 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6796 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006797 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6798 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006799
6800 /* 1.b */
6801 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6802 f_ctrs_bsc_and_bts_add(0, "handover:error");
6803
6804 /* 1.c */
6805 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6806 f_ctrs_bsc_and_bts_add(0, "handover:error");
6807
6808 /* 1.d */
6809 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6810 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6811 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6812 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006813 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6814 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006815
6816 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006817 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006818}
6819
Neels Hofmeyr91401012019-07-11 00:42:35 +02006820private function f_tc_ho_neighbor_config_2(charstring id) runs on MSC_ConnHdlr {
6821 f_tc_ho_neighbor_config_start();
6822
6823 /*
6824 * bts 0 ARFCN 871 BSIC 10
6825 * bts 1 ARFCN 871 BSIC 11
6826 * bts 2 ARFCN 871 BSIC 12
6827 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6828 */
6829
6830 log("f_tc_ho_neighbor_config: 2. explicit local neighbor: 'neighbor bts 1'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006831 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006832 f_sleep(0.5);
6833
6834 f_probe_for_handover("2.a", "HO to bts 1 works, explicitly listed as neighbor",
6835 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006836 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006837
6838 f_probe_for_handover("2.b", "HO to bts 2 doesn't work, not listed as neighbor",
6839 "handover any to arfcn 871 bsic 12",
6840 false);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006841 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006842}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006843testcase TC_ho_neighbor_config_2() runs on test_CT {
6844 var MSC_ConnHdlr vc_conn;
6845 f_init(3, true, guard_timeout := 50.0);
6846 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006847 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006848 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_2));
6849 vc_conn.done;
6850
6851 /* f_tc_ho_neighbor_config_start() */
6852 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6853 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6854
6855 /* 2.a */
6856 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6857 * handover quickly by sending a Handover Failure message. */
6858 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6859 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6860 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6861 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006862 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6863 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006864
6865 /* 2.b */
6866 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6867 f_ctrs_bsc_and_bts_add(0, "handover:error");
6868
6869 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006870 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006871}
6872
Neels Hofmeyr91401012019-07-11 00:42:35 +02006873private function f_tc_ho_neighbor_config_3(charstring id) runs on MSC_ConnHdlr {
6874 f_tc_ho_neighbor_config_start();
6875
6876 /*
6877 * bts 0 ARFCN 871 BSIC 10
6878 * bts 1 ARFCN 871 BSIC 11
6879 * bts 2 ARFCN 871 BSIC 12
6880 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6881 */
6882
6883 log("f_tc_ho_neighbor_config: 3. explicit local neighbor: 'neighbor bts 2'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006884 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006885 f_sleep(0.5);
6886
6887 f_probe_for_handover("3.a", "HO to bts 1 doesn't work, not listed as neighbor",
6888 "handover any to arfcn 871 bsic 11",
6889 false);
6890 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",
6891 "handover any to arfcn 871 bsic 12",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006892 true, expect_target_tsc := BTS_TSC[2]);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006893 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006894}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006895testcase TC_ho_neighbor_config_3() runs on test_CT {
6896 var MSC_ConnHdlr vc_conn;
6897 f_init(3, true, guard_timeout := 50.0);
6898 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006899 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006900 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_3));
6901 vc_conn.done;
6902
6903 /* f_tc_ho_neighbor_config_start() */
6904 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6905 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6906
6907 /* 3.a */
6908 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6909 f_ctrs_bsc_and_bts_add(0, "handover:error");
6910
6911 /* 3.b */
6912 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6913 * handover quickly by sending a Handover Failure message. */
6914 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6915 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6916 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6917 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006918 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:attempted");
6919 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006920
6921 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006922 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006923}
6924
Neels Hofmeyr91401012019-07-11 00:42:35 +02006925private function f_tc_ho_neighbor_config_4(charstring id) runs on MSC_ConnHdlr {
6926 f_tc_ho_neighbor_config_start();
6927
6928 /*
6929 * bts 0 ARFCN 871 BSIC 10
6930 * bts 1 ARFCN 871 BSIC 11
6931 * bts 2 ARFCN 871 BSIC 12
6932 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6933 */
6934
6935 log("f_tc_ho_neighbor_config: 4. explicit remote neighbor: 'neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006936 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006937 f_sleep(0.5);
6938
6939 f_probe_for_handover("4.a", "HO to bts 1 doesn't work, not listed as neighbor",
6940 "handover any to arfcn 871 bsic 11",
6941 false);
6942 f_probe_for_handover("4.b", "HO to bts 2 doesn't work, not listed as neighbor",
6943 "handover any to arfcn 871 bsic 12",
6944 false);
6945 f_probe_for_handover("4.c", "HO to 123-45 triggers inter-BSC HO",
6946 "handover any to arfcn 123 bsic 45",
6947 true, true);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006948 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006949}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006950testcase TC_ho_neighbor_config_4() runs on test_CT {
6951 var MSC_ConnHdlr vc_conn;
6952 f_init(3, true, guard_timeout := 50.0);
6953 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006954 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006955 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_4));
6956 vc_conn.done;
6957
6958 /* f_tc_ho_neighbor_config_start() */
6959 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6960 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6961
6962 /* 4.a */
6963 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6964 f_ctrs_bsc_and_bts_add(0, "handover:error");
6965
6966 /* 4.b */
6967 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6968 f_ctrs_bsc_and_bts_add(0, "handover:error");
6969
6970 /* 4.c */
6971 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6972 * handover quickly by timing out after the Handover Required message */
6973 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6974 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
6975 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
6976 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
6977
6978 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006979 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006980}
6981
Neels Hofmeyr91401012019-07-11 00:42:35 +02006982private function f_tc_ho_neighbor_config_5(charstring id) runs on MSC_ConnHdlr {
6983 f_tc_ho_neighbor_config_start();
6984
6985 /*
6986 * bts 0 ARFCN 871 BSIC 10
6987 * bts 1 ARFCN 871 BSIC 11
6988 * bts 2 ARFCN 871 BSIC 12
6989 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6990 */
6991
6992 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 +02006993 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006994 f_sleep(0.5);
6995
6996 f_probe_for_handover("5.a", "HO to 871-12 triggers inter-BSC HO (ignoring local cells with same ARFCN+BSIC)",
6997 "handover any to arfcn 871 bsic 12",
6998 true, true);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006999 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007000}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007001testcase TC_ho_neighbor_config_5() runs on test_CT {
7002 var MSC_ConnHdlr vc_conn;
7003 f_init(3, true);
7004 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007005 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007006 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_5));
7007 vc_conn.done;
7008
7009 /* f_tc_ho_neighbor_config_start() */
7010 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7011 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7012
7013 /* 5 */
7014 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7015 * handover quickly by timing out after the Handover Required message */
7016 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7017 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
7018 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
7019 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
7020
7021 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007022 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007023}
7024
Neels Hofmeyr91401012019-07-11 00:42:35 +02007025private function f_tc_ho_neighbor_config_6(charstring id) runs on MSC_ConnHdlr {
7026 f_tc_ho_neighbor_config_start();
7027
7028 /*
7029 * bts 0 ARFCN 871 BSIC 10
7030 * bts 1 ARFCN 871 BSIC 11
7031 * bts 2 ARFCN 871 BSIC 12
7032 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7033 */
7034
7035 log("f_tc_ho_neighbor_config: 6. config error: explicit local and remote neighbors with ambiguous ARFCN+BSIC:"
7036 & " 'neighbor bts 2; neighbor lac 99 arfcn 871 bsic 12'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007037 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007038 f_sleep(0.5);
7039
7040 f_probe_for_handover("6.a", "HO to 871-12 is ambiguous = error",
7041 "handover any to arfcn 871 bsic 12",
7042 false);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007043 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007044}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007045testcase TC_ho_neighbor_config_6() runs on test_CT {
7046 var MSC_ConnHdlr vc_conn;
7047 f_init(3, true);
7048 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007049 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007050 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_6));
7051 vc_conn.done;
7052
7053 /* f_tc_ho_neighbor_config_start() */
7054 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7055 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7056
7057 /* 6.a */
7058 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7059 * handover quickly by timing out after the Handover Required message */
7060 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7061 f_ctrs_bsc_and_bts_add(0, "handover:error");
7062
7063 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007064 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007065}
7066
Neels Hofmeyr91401012019-07-11 00:42:35 +02007067private function f_tc_ho_neighbor_config_7(charstring id) runs on MSC_ConnHdlr {
7068 f_tc_ho_neighbor_config_start();
7069
7070 /*
7071 * bts 0 ARFCN 871 BSIC 10
7072 * bts 1 ARFCN 871 BSIC 11
7073 * bts 2 ARFCN 871 BSIC 12
7074 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7075 */
7076
7077 log("f_tc_ho_neighbor_config: 7. explicit local and remote neighbors:"
7078 & " 'neighbor bts 2; neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007079 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007080 f_sleep(0.5);
7081
7082 f_probe_for_handover("7.a", "HO to 871-12 does HO to bts 2",
7083 "handover any to arfcn 871 bsic 12",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02007084 true, expect_target_tsc := BTS_TSC[2]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02007085 f_probe_for_handover("7.b", "HO to 123-45 triggers inter-BSC HO",
7086 "handover any to arfcn 123 bsic 45",
7087 true, true);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007088 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007089}
Neels Hofmeyr91401012019-07-11 00:42:35 +02007090testcase TC_ho_neighbor_config_7() runs on test_CT {
7091 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf2b88032020-06-16 00:35:04 +02007092 f_init(3, true, guard_timeout := 50.0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02007093 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007094 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007095 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_7));
7096 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007097
7098 /* f_tc_ho_neighbor_config_start() */
7099 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7100 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7101
7102 /* 7.a */
7103 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
7104 * handover quickly by sending a Handover Failure message. */
7105 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7106 f_ctrs_bsc_and_bts_add(0, "handover:failed");
7107 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
7108 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007109 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:attempted");
7110 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007111
7112 /* 7.b */
7113 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7114 * handover quickly by timing out after the Handover Required message */
7115 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7116 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
7117 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
7118 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
7119
7120 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007121 f_shutdown_helper();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007122}
7123
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007124/* OS#3041: Open and close N connections in a normal fashion, and expect no
7125 * BSSMAP Reset just because of that. */
7126testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
7127 var default d;
7128 var integer i;
7129 var DchanTuple dt;
7130
7131 f_init();
7132
7133 /* Wait for initial BSSMAP Reset to pass */
7134 f_sleep(4.0);
7135
7136 d := activate(no_bssmap_reset());
7137
7138 /* Setup up a number of connections and RLSD them again from the MSC
7139 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7140 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02007141 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007142 /* Since we're doing a lot of runs, give each one a fresh
7143 * T_guard from the top. */
7144 T_guard.start;
7145
7146 /* Setup a BSSAP connection and clear it right away. This is
7147 * the MSC telling the BSC about a planned release, it's not an
7148 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02007149 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007150
7151 /* MSC disconnects (RLSD). */
7152 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
7153 }
7154
7155 /* In the buggy behavior, a timeout of 2 seconds happens between above
7156 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7157 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7158 f_sleep(4.0);
7159
7160 deactivate(d);
7161 f_shutdown_helper();
7162}
Harald Welte552620d2017-12-16 23:21:36 +01007163
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007164/* OS#3041: Open and close N connections in a normal fashion, and expect no
7165 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
7166 * the MSC. */
7167testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
7168 var default d;
7169 var integer i;
7170 var DchanTuple dt;
7171 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007172 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
7173 var BssmapCause cause := enum2int(cause_val);
7174
7175 f_init();
7176
7177 /* Wait for initial BSSMAP Reset to pass */
7178 f_sleep(4.0);
7179
7180 d := activate(no_bssmap_reset());
7181
7182 /* Setup up a number of connections and RLSD them again from the MSC
7183 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7184 * Let's do it some more times for good measure. */
7185 for (i := 0; i < 8; i := i+1) {
7186 /* Since we're doing a lot of runs, give each one a fresh
7187 * T_guard from the top. */
7188 T_guard.start;
7189
7190 /* Setup a BSSAP connection and clear it right away. This is
7191 * the MSC telling the BSC about a planned release, it's not an
7192 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02007193 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007194
7195 /* Instruct BSC to clear channel */
7196 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7197
7198 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02007199 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007200 }
7201
7202 /* In the buggy behavior, a timeout of 2 seconds happens between above
7203 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7204 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7205 f_sleep(4.0);
7206
7207 deactivate(d);
7208 f_shutdown_helper();
7209}
7210
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007211/* OS#3041: Open and close N connections in a normal fashion, and expect no
7212 * BSSMAP Reset just because of that. Close connections from the MS side with a
7213 * Release Ind on RSL. */
7214testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
7215 var default d;
7216 var integer i;
7217 var DchanTuple dt;
7218 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007219 var integer j;
7220
7221 f_init();
7222
7223 /* Wait for initial BSSMAP Reset to pass */
7224 f_sleep(4.0);
7225
7226 d := activate(no_bssmap_reset());
7227
7228 /* Setup up a number of connections and RLSD them again from the MSC
7229 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7230 * Let's do it some more times for good measure. */
7231 for (i := 0; i < 8; i := i+1) {
7232 /* Since we're doing a lot of runs, give each one a fresh
7233 * T_guard from the top. */
7234 T_guard.start;
7235
7236 /* Setup a BSSAP connection and clear it right away. This is
7237 * the MSC telling the BSC about a planned release, it's not an
7238 * erratic loss of a connection. */
7239 dt := f_est_dchan('23'O, 23, '00010203040506'O);
7240
7241 /* simulate RLL REL IND */
7242 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
7243
7244 /* expect Clear Request on MSC side */
7245 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
7246
7247 /* Instruct BSC to clear channel */
7248 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
7249 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7250
7251 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02007252 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007253 }
7254
7255 /* In the buggy behavior, a timeout of 2 seconds happens between above
7256 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7257 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7258 f_sleep(4.0);
7259
7260 deactivate(d);
7261 f_shutdown_helper();
7262}
7263
Harald Welte94e0c342018-04-07 11:33:23 +02007264/***********************************************************************
7265 * IPA style dynamic PDCH
7266 ***********************************************************************/
7267
7268private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
7269 template (omit) RSL_Cause nack := omit)
7270runs on test_CT {
7271 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
7272 var RSL_Message rsl_unused;
7273 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
7274 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
7275 /* expect the BSC to issue the related RSL command */
7276 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7277 if (istemplatekind(nack, "omit")) {
7278 /* respond with a related acknowledgement */
7279 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7280 } else {
7281 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
7282 }
7283}
7284
7285private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
7286 template (omit) RSL_Cause nack := omit)
7287runs on test_CT {
7288 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
7289 var RSL_Message rsl_unused;
7290 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
7291 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
7292 /* expect the BSC to issue the related RSL command */
7293 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
7294 if (istemplatekind(nack, "omit")) {
7295 /* respond with a related acknowledgement */
7296 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
7297 } else {
7298 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
7299 }
7300}
7301
7302private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
7303runs on test_CT return charstring {
7304 var charstring cmd, resp;
7305 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01007306 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02007307}
7308
7309private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
7310 template charstring exp)
7311runs on test_CT {
7312 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
7313 if (not match(mode, exp)) {
7314 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02007315 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02007316 }
7317}
7318
7319private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
7320runs on test_CT {
7321 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
7322 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
7323 f_vty_transceive(BSCVTY, "end");
7324}
7325
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007326
7327private function f_ts_reset_chcomb(integer bts_nr) runs on test_CT {
7328 var integer i;
7329 for (i := 0; i < 8; i := i + 1) {
7330 f_ts_set_chcomb(bts_nr, 0, i, phys_chan_config[i]);
7331 }
7332}
7333
Harald Welte94e0c342018-04-07 11:33:23 +02007334private const charstring TCHF_MODE := "TCH/F mode";
7335private const charstring TCHH_MODE := "TCH/H mode";
7336private const charstring PDCH_MODE := "PDCH mode";
7337private const charstring NONE_MODE := "NONE mode";
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007338private const charstring SDCCH8_MODE := "SDCCH8 mode";
Harald Welte94e0c342018-04-07 11:33:23 +02007339
7340/* Test IPA PDCH activation / deactivation triggered by VTY */
7341testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
7342 var RSL_Message rsl_unused;
7343
7344 /* change Timeslot 6 before f_init() starts RSL */
7345 f_init_vty();
7346 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
7347 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7348
7349 f_init(1, false);
7350 f_sleep(1.0);
7351
7352 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
7353
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007354 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007355 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7356 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7357 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7358 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7359 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007360 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007361 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7362
7363 /* De-activate it via VTY */
7364 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7365 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007366 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007367 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7368
7369 /* re-activate it via VTY */
7370 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
7371 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007372 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007373 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7374
7375 /* and finally de-activate it again */
7376 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7377 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007378 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007379 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7380
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007381 /* clean up config */
7382 f_ts_set_chcomb(0, 0, 6, "PDCH");
7383
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007384 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007385}
7386
7387/* Test IPA PDCH activation NACK */
7388testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
7389 var RSL_Message rsl_unused;
7390
7391 /* change Timeslot 6 before f_init() starts RSL */
7392 f_init_vty();
7393 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
7394 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7395
7396 f_init(1, false);
7397 f_sleep(1.0);
7398
7399 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
7400
7401 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7402 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7403 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7404 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7405 f_sleep(1.0);
7406 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7407
7408 /* De-activate it via VTY */
7409 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7410 f_sleep(1.0);
7411 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7412
7413 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
7414 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
7415 f_sleep(1.0);
7416 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7417
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007418 /* clean up config */
7419 f_ts_set_chcomb(0, 0, 6, "PDCH");
7420
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007421 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007422}
7423
7424
7425/***********************************************************************
7426 * Osmocom style dynamic PDCH
7427 ***********************************************************************/
7428
7429private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
7430 template (omit) RSL_Cause nack := omit)
7431runs on test_CT {
7432 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
7433 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02007434 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02007435 /* FIXME: no VTY command to activate Osmocom PDCH !! */
7436 /* expect the BSC to issue the related RSL command */
7437 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
7438 if (istemplatekind(nack, "omit")) {
7439 /* respond with a related acknowledgement */
7440 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7441 } else {
7442 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
7443 }
7444}
7445
7446private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
7447 template (omit) RSL_Cause nack := omit)
7448runs on test_CT {
7449 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
7450 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02007451 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02007452 /* FIXME: no VTY command to activate Osmocom PDCH !! */
7453 /* expect the BSC to issue the related RSL command */
7454 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
7455 if (istemplatekind(nack, "omit")) {
7456 /* respond with a related acknowledgement */
7457 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
7458 } else {
7459 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
7460 }
7461}
7462
7463/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
7464testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
7465 var RSL_Message rsl_unused;
7466
7467 /* change Timeslot 6 before f_init() starts RSL */
7468 f_init_vty();
7469 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
7470 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7471
7472 f_init(1, false);
7473 f_sleep(1.0);
7474
7475 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
7476
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007477 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007478 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7479 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007480 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Harald Welte94e0c342018-04-07 11:33:23 +02007481
7482 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7483 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007484 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 +02007485 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7486
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007487 /* clean up config */
7488 f_ts_set_chcomb(0, 0, 6, "PDCH");
7489
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007490 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007491}
7492
7493/* Test Osmocom dyn PDCH activation NACK behavior */
7494testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
7495 var RSL_Message rsl_unused;
7496
7497 /* change Timeslot 6 before f_init() starts RSL */
7498 f_init_vty();
7499 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
7500 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7501
7502 f_init(1, false);
7503 f_sleep(1.0);
7504
7505 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
7506
7507 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7508 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007509 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Harald Welte94e0c342018-04-07 11:33:23 +02007510
7511 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
7512 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
7513 f_sleep(1.0);
7514 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7515
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007516 /* clean up config */
7517 f_ts_set_chcomb(0, 0, 6, "PDCH");
7518
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007519 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007520}
7521
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007522/* Test Osmocom dyn TS SDCCH8 activation / deactivation */
7523testcase TC_dyn_ts_sdcch8_act_deact() runs on test_CT {
7524 var RSL_Message rsl_unused, rsl_msg;
7525 var DchanTuple dt;
7526 var BSSAP_N_CONNECT_ind rx_c_ind;
7527
7528 /* change Timeslot 6 before f_init() starts RSL */
7529 f_init_vty();
7530 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
7531 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7532
7533 f_init(1, false);
7534 f_sleep(1.0);
7535
7536 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7537
7538 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7539 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7540 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007541 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007542
7543 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7544 f_sleep(1.0);
7545 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7546 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7547
7548 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7549 * on CCCH+SDCCH4+CBCH) */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007550 var DchanTuples sdcch_cleanup := {};
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007551 var integer i;
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007552 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007553 dt := f_est_dchan('23'O, i, '00010203040506'O);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007554 sdcch_cleanup := sdcch_cleanup & { dt };
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007555 }
7556
7557 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
7558 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
7559 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7560 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7561
7562 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7563 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7564
7565 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7566 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
7567 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7568 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7569
7570 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
7571 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
7572 dt.sccp_conn_id := rx_c_ind.connectionId;
7573 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
7574
7575 /* Instruct BSC to clear channel */
7576 var BssmapCause cause := 0;
7577 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7578 f_exp_chan_rel_and_clear(dt, 0);
7579
7580 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007581 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007582 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7583 f_sleep(1.0);
7584 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7585
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007586 /* Clean up SDCCH lchans */
7587 for (i := 0; i < lengthof(sdcch_cleanup); i := i + 1) {
7588 f_perform_clear_test_ct(sdcch_cleanup[i]);
7589 }
7590
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007591 /* clean up config */
7592 f_ts_set_chcomb(0, 0, 6, "PDCH");
7593
7594 f_shutdown_helper();
7595}
7596
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007597/* Validate all 8 subslots of a dynamics TS configured as SDCCH8 are used */
7598testcase TC_dyn_ts_sdcch8_all_subslots_used() runs on test_CT {
7599 var ASP_RSL_Unitdata rsl_ud;
7600 var integer i;
7601 var integer chreq_total, chreq_nochan;
7602
7603 f_init_vty();
7604 for (i := 1; i < 8; i := i + 1) {
7605 if (i == 2) {
7606 f_ts_set_chcomb(0, 0, i, "TCH/F_TCH/H_SDCCH8_PDCH");
7607 } else {
7608 f_ts_set_chcomb(0, 0, i, "PDCH");
7609 }
7610 }
7611 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7612
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007613 f_init(1, guard_timeout := 60.0);
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007614
7615 /* The dyn TS want to activate PDCH mode, ACK that. */
7616 var RslChannelNr chan_nr;
7617 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007618 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007619 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7620
7621 f_sleep(1.0);
7622
7623 /* Exhaust all dedicated SDCCH lchans.
7624 /* GSM 44.018 Table 9.1.8.2:
7625 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
7626 */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007627 var DchanTuples chan_cleanup := {};
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007628 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007629 chan_cleanup := chan_cleanup & { f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007630 }
7631
7632 /* Only the dyn TS is still available. Its first lchan gets converted to SDCCH8 */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007633 chan_cleanup := chan_cleanup & { f_est_dchan_dyn('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007634 /* Also occupy the seven other SDCCH of the dyn TS */
7635 for (i := 0; i < 7; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007636 chan_cleanup := chan_cleanup & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
7637 }
7638
7639 /* Clean up SDCCH lchans */
7640 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
7641 f_perform_clear_test_ct(chan_cleanup[i]);
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007642 }
7643
7644 /* clean up config */
7645 f_ts_reset_chcomb(0);
7646
7647 f_shutdown_helper();
7648}
7649
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007650/* Test Osmocom dyn TS SDCCH8 activation / deactivation: If activating dyn TS as
7651 SDCCH8 would end up in having no free TCH, then BSC should decide to activate
7652 it as TCH directly instead. SYS#5309. */
7653testcase TC_dyn_ts_sdcch8_tch_call_act_deact() runs on test_CT {
7654 var RSL_Message rsl_unused, rsl_msg;
7655 var DchanTuple dt;
7656 var BSSAP_N_CONNECT_ind rx_c_ind;
7657 var integer i;
7658
7659 /* change Timeslot 6 before f_init() starts RSL */
7660 f_init_vty();
7661 for (i := 1; i < 8; i := i + 1) {
7662 if (i == 6) {
7663 f_ts_set_chcomb(0, 0, i, "TCH/F_TCH/H_SDCCH8_PDCH");
7664 } else {
7665 f_ts_set_chcomb(0, 0, i, "PDCH");
7666 }
7667 }
7668 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7669
7670 f_init(1, false);
7671 f_sleep(1.0);
7672
7673 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7674
7675 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7676 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7677 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007678 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007679
7680 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7681 f_sleep(1.0);
7682 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7683 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7684
7685 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7686 * on CCCH+SDCCH4+CBCH) */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007687 var DchanTuples chan_cleanup := {};
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007688 var OCT1 ra := '43'O; /* RA containing reason=originating speech call*/
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007689 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007690 dt := f_est_dchan(ra, i, '00010203040506'O);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007691 chan_cleanup := chan_cleanup & { dt };
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007692 }
7693
7694 /* Now the dyn ts is selected. First PDCH is released, then TCH chan is activated */
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007695 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int(ra) + i, 1), 2342));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007696 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7697 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7698
7699 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7700 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7701
7702 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
7703 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
7704 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7705 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
7706
7707 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
7708 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
7709 dt.sccp_conn_id := rx_c_ind.connectionId;
7710 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
7711
7712 /* Instruct BSC to clear channel */
7713 var BssmapCause cause := 0;
7714 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7715 f_exp_chan_rel_and_clear(dt, 0);
7716
7717 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007718 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007719 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7720 f_sleep(1.0);
7721 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7722
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007723 /* Clean up SDCCH lchans */
7724 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
7725 f_perform_clear_test_ct(chan_cleanup[i]);
7726 }
7727
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007728 /* clean up config */
7729 f_ts_reset_chcomb(0);
7730 /* TODO: clean up other channels? */
7731
7732 f_shutdown_helper();
7733}
7734
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007735/* Test Osmocom dyn TS SDCCH8 activation / deactivation when SDCCH fails at BTS */
7736testcase TC_dyn_ts_sdcch8_act_nack() runs on test_CT {
7737 var RSL_Message rsl_unused, rsl_msg;
7738 var DchanTuple dt;
7739 var BSSAP_N_CONNECT_ind rx_c_ind;
7740 var GsmRrMessage rr;
7741
7742 /* change Timeslot 6 before f_init() starts RSL */
7743 f_init_vty();
7744 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
7745 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7746
7747 f_init(1, false);
7748 f_sleep(1.0);
7749
7750 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7751
7752 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7753 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7754 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007755 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007756
7757 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7758 f_sleep(1.0);
7759 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7760 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7761
7762 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7763 * on CCCH+SDCCH4+CBCH) */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007764 var DchanTuples chan_cleanup := {};
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007765 var integer i;
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007766 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007767 dt := f_est_dchan('23'O, i, '00010203040506'O);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007768 chan_cleanup := chan_cleanup & { dt };
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007769 }
7770
7771 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
7772 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
7773 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7774 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7775
7776 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7777 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7778
7779 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7780 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(dt.rsl_chan_nr, RSL_ERR_EQUIPMENT_FAIL));
7781 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7782 rr := dec_GsmRrMessage(rsl_msg.ies[1].body.full_imm_ass_info.payload);
7783 if (rr.header.message_type != IMMEDIATE_ASSIGNMENT_REJECT) {
7784 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Expected reject");
7785 }
7786
7787 /* FIXME? Currently the TS stays in state BORKEN: */
7788
7789 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007790 /* rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007791 * f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7792 * f_sleep(1.0);
7793 * f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE)
7794 */
7795
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007796 /* Clean up SDCCH lchans */
7797 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
7798 f_perform_clear_test_ct(chan_cleanup[i]);
7799 }
7800
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007801 /* clean up config */
7802 f_ts_set_chcomb(0, 0, 6, "PDCH");
7803
7804 f_shutdown_helper();
7805}
7806
Stefan Sperling0796a822018-10-05 13:01:39 +02007807testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02007808 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02007809 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
7810 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
7811 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007812 f_shutdown_helper();
Stefan Sperling0796a822018-10-05 13:01:39 +02007813}
7814
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007815testcase TC_chopped_ipa_payload() runs on test_CT {
7816 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
7817 /* TODO: mp_bsc_ctrl_port does not work yet */};
7818 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
7819 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
7820 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007821 f_shutdown_helper();
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007822}
7823
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01007824/* Verify the BSC sends the MS Power Parameters IE during CHAN ACT to make sure
7825 the BTS does autonomous MS power control loop */
7826testcase TC_assignment_verify_ms_power_params_ie() runs on test_CT {
7827 var MSC_ConnHdlr vc_conn;
7828 var TestHdlrParams pars := f_gen_test_hdlr_pars();
7829 //pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
7830 pars.exp_ms_power_params := true;
7831
7832 f_init(1, true);
7833 f_sleep(1.0);
7834 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
7835 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007836 f_shutdown_helper();
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01007837}
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007838
Vadim Yanitskiy4b233042021-06-30 00:58:43 +02007839/* Verify activation and deactivation of the BCCH carrier power reduction mode */
7840testcase TC_c0_power_red_mode() runs on test_CT {
7841 f_init(1);
7842
7843 for (var integer red := 6; red >= 0; red := red - 2) {
7844 /* Configure BCCH carrier power reduction mode via the VTY */
7845 f_vty_transceive(BSCVTY, "bts 0 c0-power-reduction " & int2str(red));
7846
7847 /* Expect Osmocom specific BS Power Control message on the RSL */
7848 var template RSL_Message tr_rsl_pdu := tr_RSL_BS_PWR_CTRL(
7849 chan_nr := t_RslChanNr_BCCH(0),
7850 bs_power := tr_RSL_IE_BS_Power(red / 2));
7851 tr_rsl_pdu.msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false);
7852 var RSL_Message unused := f_exp_ipa_rx(0, tr_rsl_pdu);
7853
7854 /* Additionally verify the applied value over the CTRL interface */
7855 var CtrlValue cred := f_ctrl_get_bts(IPA_CTRL, 0, "c0-power-reduction");
7856 if (cred != int2str(red)) {
7857 setverdict(fail, "Unexpected BCCH carrier power reduction value ",
7858 cred, " (expected ", red, ")");
7859 }
7860 }
7861
7862 f_shutdown_helper();
7863}
7864
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007865/***********************************************************************
7866 * MSC Pooling
7867 ***********************************************************************/
7868
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007869template MobileIdentityLV ts_MI_TMSI_NRI_LV(integer nri_v, integer nri_bitlen := 10) :=
Harald Weltebf397612021-01-14 20:39:46 +01007870 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 +02007871
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007872private 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 +02007873runs on MSC_ConnHdlr {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007874 interleave {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007875 [] rsl_pt.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007876 f_logp(BSCVTY, "Got RSL RR Release");
7877 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007878 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007879 f_logp(BSCVTY, "Got RSL Deact SACCH");
7880 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02007881 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007882 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007883 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
7884 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007885 break;
7886 }
7887 }
7888}
7889
Neels Hofmeyr6289af12021-12-16 18:17:49 +01007890private altstep as_mgcp_ack_all_dlcx() runs on MSC_ConnHdlr {
7891 var MgcpCommand mgcp_cmd;
7892 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
7893 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
7894 repeat;
7895 }
7896}
7897
7898private altstep as_rsl_ack_all_rel_req() runs on MSC_ConnHdlr {
7899 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
7900 [] RSL.receive(tr_RSL_REL_REQ(g_chan_nr, ?)) {
7901 RSL.send(ts_RSL_REL_CONF(g_chan_nr, main_dcch));
7902 repeat;
7903 }
7904}
7905
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007906friend function f_perform_clear(RSL_DCHAN_PT rsl_pt := RSL, RSLEM_PROC_PT rsl_proc_pt := RSL_PROC,
7907 template PDU_ML3_NW_MS exp_rr_rel_tmpl := tr_RRM_RR_RELEASE)
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02007908runs on MSC_ConnHdlr {
Neels Hofmeyr6289af12021-12-16 18:17:49 +01007909 var default ack_dlcx := activate(as_mgcp_ack_all_dlcx());
7910 var default ack_rel_req := activate(as_rsl_ack_all_rel_req());
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007911 f_logp(BSCVTY, "MSC instructs BSC to clear channel");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007912 BSSAP.send(ts_BSSMAP_ClearCommand(0));
7913 interleave {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007914 [] rsl_pt.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007915 f_logp(BSCVTY, "Got RSL RR Release");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007916 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007917 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007918 f_logp(BSCVTY, "Got RSL Deact SACCH");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007919 }
7920 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007921 f_logp(BSCVTY, "Got BSSMAP Clear Complete");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007922 /* Also drop the SCCP connection */
7923 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
7924 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02007925 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007926 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007927 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
7928 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007929 }
7930 }
Neels Hofmeyr6289af12021-12-16 18:17:49 +01007931 deactivate(ack_dlcx);
7932 deactivate(ack_rel_req);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007933}
7934
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007935private function f_perform_clear_test_ct(DchanTuple dt)
7936 runs on test_CT
7937{
7938 /* Instruct BSC to clear channel */
7939 var BssmapCause cause := 0;
7940 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7941 f_exp_chan_rel_and_clear(dt, 0);
7942}
7943
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007944private function f_perform_compl_l3(RSL_DCHAN_PT rsl_pt, RSLEM_PROC_PT rsl_proc_pt,
7945 template PDU_ML3_MS_NW l3_info, boolean do_clear := true, boolean expect_bssmap_l3 := true)
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007946runs on MSC_ConnHdlr {
7947 timer T := 10.0;
7948 var octetstring l3_enc := enc_PDU_ML3_MS_NW(valueof(l3_info));
7949
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007950 f_logp(BSCVTY, "establish channel, send Complete Layer 3 Info");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007951 f_create_bssmap_exp(l3_enc);
7952
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007953 /* RSL_Emulation.f_chan_est() on rsl_pt:
7954 * This is basically code dup with s/RSL/rsl_pt from:
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007955 * RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
7956 */
7957 var RSL_Message rx_rsl;
7958 var GsmRrMessage rr;
7959
7960 /* request a channel to be established */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007961 rsl_pt.send(ts_RSLDC_ChanRqd(g_pars.ra, g_pars.fn));
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007962 /* expect immediate assignment.
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007963 * Code dup with s/RSL/rsl_pt from:
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007964 * rx_rsl := f_rx_or_fail(tr_RSL_IMM_ASSIGN);
7965 */
7966 timer Tt := 10.0;
7967
7968 /* request a channel to be established */
7969 Tt.start;
7970 alt {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007971 [] rsl_pt.receive(tr_RSL_IMM_ASSIGN) -> value rx_rsl {
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007972 Tt.stop;
7973 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007974 [] rsl_pt.receive {
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007975 setverdict(fail, "Unexpected RSL message on DCHAN");
7976 mtc.stop;
7977 }
7978 [] Tt.timeout {
7979 setverdict(fail, "Timeout waiting for RSL on DCHAN");
7980 mtc.stop;
7981 }
7982 }
7983 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
7984 g_chan_nr := rr.payload.imm_ass.chan_desc.chan_nr;
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007985 rsl_pt.send(ts_RSL_EST_IND(g_chan_nr, valueof(g_pars.link_id), l3_enc));
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007986
7987
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007988 if (expect_bssmap_l3) {
7989 f_logp(BSCVTY, "expect BSSAP Complete Layer 3 Info at MSC");
7990 var template PDU_BSSAP exp_l3_compl;
7991 exp_l3_compl := tr_BSSMAP_ComplL3()
7992 if (g_pars.aoip == false) {
7993 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := omit;
7994 } else {
7995 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := ?;
7996 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007997
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007998 var PDU_BSSAP bssap;
7999 T.start;
8000 alt {
8001 [] BSSAP.receive(exp_l3_compl) -> value bssap {
8002 f_logp(BSCVTY, "received expected Complete Layer 3 Info at MSC");
8003 log("rx exp_l3_compl = ", bssap);
8004 }
8005 [] BSSAP.receive(tr_BSSMAP_ComplL3) {
8006 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching COMPLETE LAYER 3 INFORMATION");
8007 }
8008 [] T.timeout {
8009 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
8010 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008011 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008012
Neels Hofmeyr66e15092020-10-12 18:44:41 +00008013 /* start ciphering, if requested */
8014 if (ispresent(g_pars.encr)) {
8015 f_logp(BSCVTY, "start ciphering");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008016 f_cipher_mode(g_pars.encr, rsl_pt := rsl_pt, rsl_proc_pt := rsl_proc_pt);
Neels Hofmeyr66e15092020-10-12 18:44:41 +00008017 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008018 }
8019
8020 if (do_clear) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008021 f_perform_clear(rsl_pt, rsl_proc_pt);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008022 }
8023 setverdict(pass);
8024 f_sleep(1.0);
8025}
8026
8027private function f_tc_mscpool_compl_l3(charstring id) runs on MSC_ConnHdlr {
8028 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8029 if (g_pars.mscpool.rsl_idx == 0) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008030 f_perform_compl_l3(RSL, RSL_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008031 } else if (g_pars.mscpool.rsl_idx == 1) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008032 f_perform_compl_l3(RSL1, RSL1_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008033 } else if (g_pars.mscpool.rsl_idx == 2) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008034 f_perform_compl_l3(RSL2, RSL2_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008035 }
8036}
8037
8038/* Various Complete Layer 3 by IMSI all end up with the first MSC, because the other MSCs are not connected. */
8039private function f_tc_mscpool_L3Compl_on_1_msc(charstring id) runs on MSC_ConnHdlr {
8040 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008041 f_perform_compl_l3(RSL, RSL_PROC, ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O) );
8042 f_perform_compl_l3(RSL, RSL_PROC, ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_IMSI_LV('001010000000002'H))) );
8043 f_perform_compl_l3(RSL, RSL_PROC, ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))) );
8044 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 +02008045}
8046testcase TC_mscpool_L3Compl_on_1_msc() runs on test_CT {
8047
8048 f_init(1, true);
8049 f_sleep(1.0);
8050 var MSC_ConnHdlr vc_conn;
8051 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008052
8053 f_ctrs_msc_init();
8054
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008055 vc_conn := f_start_handler(refers(f_tc_mscpool_L3Compl_on_1_msc), pars);
8056 vc_conn.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008057
8058 f_ctrs_msc_expect(0, "mscpool:subscr:new", 4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008059 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008060}
8061
8062/* Three Layer 3 Complete by IMSI are round-robin'ed across two connected MSCs */
8063/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8064 * just as well using only RSL. */
8065testcase TC_mscpool_L3Complete_by_imsi_round_robin() runs on test_CT {
8066
8067 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8068 f_sleep(1.0);
8069
8070 /* Control which MSC gets chosen next by the round-robin, otherwise
8071 * would be randomly affected by which other tests ran before this. */
8072 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8073
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008074 f_ctrs_msc_init();
8075
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008076 var MSC_ConnHdlr vc_conn1;
8077 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8078 pars1.mscpool.rsl_idx := 0;
8079 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
8080 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8081 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008082 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008083
8084 var MSC_ConnHdlr vc_conn2;
8085 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8086 pars2.mscpool.rsl_idx := 1;
8087 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8088 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8089 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008090 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008091
8092 /* Test round-robin wrap to the first MSC */
8093 var MSC_ConnHdlr vc_conn3;
8094 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8095 pars3.mscpool.rsl_idx := 2;
8096 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
8097 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8098 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008099 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008100 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008101}
8102
8103/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 0
8104 * (configured in osmo-bsc.cfg). */
8105/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8106 * just as well using only RSL. */
8107testcase TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() runs on test_CT {
8108
8109 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8110 f_sleep(1.0);
8111
8112 /* Control which MSC gets chosen next by the round-robin, otherwise
8113 * would be randomly affected by which other tests ran before this. */
8114 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8115
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008116 f_ctrs_msc_init();
8117
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008118 var MSC_ConnHdlr vc_conn1;
8119 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8120 pars1.mscpool.rsl_idx := 0;
8121 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
8122 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8123 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008124 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008125
8126 var MSC_ConnHdlr vc_conn2;
8127 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8128 pars2.mscpool.rsl_idx := 1;
8129 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
8130 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8131 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008132 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008133
8134 /* Test round-robin wrap to the first MSC */
8135 var MSC_ConnHdlr vc_conn3;
8136 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8137 pars3.mscpool.rsl_idx := 2;
8138 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
8139 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8140 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008141 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008142 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008143}
8144
8145/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 1
8146 * (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
8147 * NULL-NRI setting is stronger than that. */
8148/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8149 * just as well using only RSL. */
8150testcase TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() runs on test_CT {
8151
8152 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8153 f_sleep(1.0);
8154
8155 /* Control which MSC gets chosen next by the round-robin, otherwise
8156 * would be randomly affected by which other tests ran before this. */
8157 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8158
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008159 f_ctrs_msc_init();
8160
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008161 var MSC_ConnHdlr vc_conn1;
8162 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8163 pars1.mscpool.rsl_idx := 0;
8164 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8165 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8166 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008167 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008168
8169 var MSC_ConnHdlr vc_conn2;
8170 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8171 pars2.mscpool.rsl_idx := 1;
8172 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8173 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8174 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008175 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008176
8177 /* Test round-robin wrap to the first MSC */
8178 var MSC_ConnHdlr vc_conn3;
8179 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8180 pars3.mscpool.rsl_idx := 2;
8181 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8182 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8183 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008184 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008185 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008186}
8187
8188/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI not
8189 * assigned to any MSC (configured in osmo-bsc.cfg). */
8190/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8191 * just as well using only RSL. */
8192testcase TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() runs on test_CT {
8193
8194 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8195 f_sleep(1.0);
8196
8197 /* Control which MSC gets chosen next by the round-robin, otherwise
8198 * would be randomly affected by which other tests ran before this. */
8199 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8200
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008201 f_ctrs_msc_init();
8202
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008203 var MSC_ConnHdlr vc_conn1;
8204 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8205 pars1.mscpool.rsl_idx := 0;
8206 /* An NRI that is not assigned to any MSC */
8207 pars1.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(1023))));
8208 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8209 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008210 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008211
8212 var MSC_ConnHdlr vc_conn2;
8213 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8214 pars2.mscpool.rsl_idx := 1;
8215 /* An NRI that is not assigned to any MSC */
8216 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(768)), '00F110'O));
8217 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8218 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008219 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008220
8221 /* Test round-robin wrap to the first MSC */
8222 var MSC_ConnHdlr vc_conn3;
8223 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8224 pars3.mscpool.rsl_idx := 2;
8225 /* An NRI that is not assigned to any MSC */
8226 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, valueof(ts_MI_TMSI_NRI_LV(819))));
8227 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8228 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008229 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008230 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008231}
8232
8233/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI
8234 * assigned to an MSC that is currently not connected (configured in osmo-bsc.cfg). */
8235/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8236 * just as well using only RSL. */
8237testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() runs on test_CT {
8238
8239 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8240 f_sleep(1.0);
8241
8242 /* Control which MSC gets chosen next by the round-robin, otherwise
8243 * would be randomly affected by which other tests ran before this. */
8244 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8245
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008246 f_ctrs_msc_init();
8247
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008248 var MSC_ConnHdlr vc_conn1;
8249 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8250 pars1.mscpool.rsl_idx := 0;
8251 /* An NRI that is assigned to an unconnected MSC */
8252 pars1.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(512))));
8253 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8254 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008255 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8256 f_ctrs_msc_add(0, "mscpool:subscr:new");
8257 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008258
8259 var MSC_ConnHdlr vc_conn2;
8260 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8261 pars2.mscpool.rsl_idx := 1;
8262 /* An NRI that is assigned to an unconnected MSC */
8263 pars2.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(767))));
8264 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8265 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008266 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8267 f_ctrs_msc_add(1, "mscpool:subscr:new");
8268 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008269
8270 /* Test round-robin wrap to the first MSC */
8271 var MSC_ConnHdlr vc_conn3;
8272 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8273 pars3.mscpool.rsl_idx := 2;
8274 /* An NRI that is assigned to an unconnected MSC */
8275 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(750)), '00F110'O));
8276 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8277 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008278 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8279 f_ctrs_msc_add(0, "mscpool:subscr:new");
8280 f_ctrs_msc_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008281 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008282}
8283
8284/* Three Layer 3 Complete by TMSI with valid NRI for the second MSC are all directed to the second MSC (configured in
8285 * osmo-bsc.cfg). */
8286/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8287 * just as well using only RSL. */
8288testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_1() runs on test_CT {
8289
8290 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8291 f_sleep(1.0);
8292
8293 /* All TMSIs in this test point at the second MSC, set the round robin to point at the first MSC to make sure
8294 * this is not using round-robin. */
8295 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8296
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008297 f_ctrs_msc_init();
8298
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008299 var MSC_ConnHdlr vc_conn1;
8300 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
8301 pars1.mscpool.rsl_idx := 0;
8302 /* An NRI of the second MSC's range (256-511) */
8303 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(256))));
8304 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8305 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008306 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008307
8308 var MSC_ConnHdlr vc_conn2;
8309 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8310 pars2.mscpool.rsl_idx := 1;
8311 /* An NRI of the second MSC's range (256-511) */
8312 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(260))));
8313 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8314 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008315 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008316
8317 var MSC_ConnHdlr vc_conn3;
8318 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
8319 pars3.mscpool.rsl_idx := 2;
8320 /* An NRI of the second MSC's range (256-511) */
8321 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(511)), '00F110'O));
8322 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8323 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008324 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008325 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008326}
8327
8328/* Layer 3 Complete by TMSI with valid NRI for the third MSC are directed to the third MSC (configured in osmo-bsc.cfg),
8329 * while a round-robin remains unaffected by that. */
8330/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8331 * just as well using only RSL. */
8332testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_2() runs on test_CT {
8333
8334 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8335 f_sleep(1.0);
8336
8337 /* All TMSIs in this test point at the third MSC, set the round robin to point at the second MSC to make sure
8338 * this is not using round-robin. */
8339 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
8340
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008341 f_ctrs_msc_init();
8342
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008343 var MSC_ConnHdlr vc_conn1;
8344 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 2);
8345 pars1.mscpool.rsl_idx := 0;
8346 /* An NRI of the third MSC's range (512-767) */
8347 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(512))));
8348 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8349 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008350 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008351
8352 var MSC_ConnHdlr vc_conn2;
8353 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8354 pars2.mscpool.rsl_idx := 1;
8355 /* An NRI of the third MSC's range (512-767) */
8356 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(678))));
8357 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8358 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008359 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008360
8361 /* The above forwardings to third MSC have not affected the round robin, which still points at the second MSC */
8362 var MSC_ConnHdlr vc_conn3;
8363 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
8364 pars3.mscpool.rsl_idx := 2;
8365 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000013'H)), '00F110'O));
8366 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8367 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008368 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008369 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008370}
8371
8372/* LU with a TMSI but indicating a different PLMN in its previous LAI: ignore the NRI. */
8373/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8374 * just as well using only RSL. */
8375testcase TC_mscpool_LU_by_tmsi_from_other_PLMN() runs on test_CT {
8376
8377 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8378 f_sleep(1.0);
8379
8380 /* The TMSIs in this test points at the second MSC, but since it is from a different PLMN, round-robin is used
8381 * instead, and hits msc 0. */
8382 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8383
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008384 f_ctrs_msc_init();
8385
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008386 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-bsc.cfg */
8387 var MSC_ConnHdlr vc_conn1;
8388 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8389 pars1.mscpool.rsl_idx := 0;
8390 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(260)), '99F999'O));
8391 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8392 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008393 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008394
8395 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
8396 var MSC_ConnHdlr vc_conn2;
8397 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8398 pars2.mscpool.rsl_idx := 1;
8399 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(555)), '00F110'O));
8400 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8401 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008402 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008403 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008404}
8405
8406/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by IMSI, which would be
8407 * round-robined to another MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
8408private function f_tc_mscpool_paging_imsi(charstring id) runs on MSC_ConnHdlr {
8409 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
8410 //cid_list := { cIl_allInBSS := ''O };
8411 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
8412 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
8413 var BSSAP_N_UNITDATA_req paging;
8414 var hexstring imsi := '001010000000123'H;
8415
8416 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8417
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008418 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008419 valueof(ts_BSSMAP_Paging(imsi, cid_list, omit, bssmap_chneed))));
8420 BSSAP.send(paging);
8421
8422 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
8423 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
8424 * channel number is picked here. */
8425 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
8426 f_rslem_register(0, new_chan_nr);
8427 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(imsi)));
8428 f_rslem_unregister(0, new_chan_nr);
8429
8430 /* Despite the round robin pointing at the second MSC ('roundrobin next 1'), the earlier Paging for the same IMSI
8431 * causes this Paging Response to go to the first MSC (bssap_idx := 0). */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008432 f_perform_compl_l3(RSL, RSL_PROC, ts_PAG_RESP(valueof(ts_MI_IMSI_LV(imsi))) );
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008433 f_sleep(1.0);
8434}
8435testcase TC_mscpool_paging_and_response_imsi() runs on test_CT {
8436 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
8437 f_sleep(1.0);
8438
8439 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
8440 * second MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
8441 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
8442
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008443 f_ctrs_msc_init();
8444
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008445 var MSC_ConnHdlr vc_conn1;
8446 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8447 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008448 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
8449 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008450 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_imsi), pars1);
8451 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008452 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008453 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008454}
8455
8456/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by TMSI with an NRI value
8457 * that matches a different MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
8458private function f_tc_mscpool_paging_tmsi(charstring id) runs on MSC_ConnHdlr {
8459 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
8460 //cid_list := { cIl_allInBSS := ''O };
8461 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
8462 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
8463 var integer nri_v := 300; /* <-- second MSC's NRI */
Harald Weltebf397612021-01-14 20:39:46 +01008464 var octetstring tmsi := f_gen_tmsi(suffix := 0, nri_v := nri_v);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008465 var BSSAP_N_UNITDATA_req paging;
8466
8467 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8468
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008469 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008470 valueof(ts_BSSMAP_Paging('001010000000011'H, cid_list, tmsi, bssmap_chneed))));
8471 BSSAP.send(paging);
8472
8473 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
8474 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
8475 * channel number is picked here. */
8476 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
8477 f_rslem_register(0, new_chan_nr);
8478 RSL.receive(tr_RSL_PAGING_CMD(t_MI_TMSI(tmsi)));
8479 f_rslem_unregister(0, new_chan_nr);
8480
8481 /* Despite the NRI matching the second MSC (NRI from 'msc 1' in osmo-bsc.cfg) and round robin pointing at the
8482 * third MSC ('roundrobin next 2'), the earlier Paging for the same TMSI causes this Paging Response to go to
8483 * the first MSC (bssap_idx := 0). */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008484 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 +02008485 f_sleep(1.0);
8486}
8487testcase TC_mscpool_paging_and_response_tmsi() runs on test_CT {
8488 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
8489 f_sleep(1.0);
8490
8491 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
8492 * third MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
8493 f_vty_transceive(BSCVTY, "mscpool roundrobin next 2");
8494
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008495 f_ctrs_msc_init();
8496
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008497 var MSC_ConnHdlr vc_conn1;
8498 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8499 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008500 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
8501 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008502 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_tmsi), pars1);
8503 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008504 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008505 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008506}
8507
8508/* For round-robin, skip an MSC that has 'no allow-attach' set. */
8509/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8510 * just as well using only RSL. */
8511testcase TC_mscpool_no_allow_attach_round_robin() runs on test_CT {
8512
8513 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8514 f_sleep(1.0);
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00008515 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
8516 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008517
8518 /* Control which MSC gets chosen next by the round-robin, otherwise
8519 * would be randomly affected by which other tests ran before this. */
8520 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8521
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008522 f_ctrs_msc_init();
8523
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008524 var MSC_ConnHdlr vc_conn1;
8525 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8526 pars1.mscpool.rsl_idx := 0;
8527 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
8528 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8529 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008530 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008531
8532 var MSC_ConnHdlr vc_conn2;
8533 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8534 pars2.mscpool.rsl_idx := 1;
8535 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8536 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8537 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008538 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008539
8540 var MSC_ConnHdlr vc_conn3;
8541 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8542 pars3.mscpool.rsl_idx := 2;
8543 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
8544 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8545 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008546 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008547 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008548}
8549
8550/* An MSC that has 'no allow-attach' set should still serve subscribers that are already attached according to their
8551 * TMSI NRI. */
8552testcase TC_mscpool_no_allow_attach_valid_nri() runs on test_CT {
8553
8554 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8555 f_sleep(1.0);
8556
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00008557 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
8558 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
8559
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008560 /* Control which MSC gets chosen next by the round-robin, otherwise
8561 * would be randomly affected by which other tests ran before this. */
8562 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8563
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008564 f_ctrs_msc_init();
8565
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008566 /* Round robin points at msc 0, but the valid NRI directs to msc 1, even though msc 1 has 'no allow-attach'. */
8567 var MSC_ConnHdlr vc_conn1;
8568 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
8569 pars1.mscpool.rsl_idx := 0;
8570 /* An NRI of the second MSC's range (256-511) */
8571 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_TMSI_NRI_LV(260))));
8572 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8573 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008574 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008575
8576 var MSC_ConnHdlr vc_conn2;
8577 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 0);
8578 pars2.mscpool.rsl_idx := 1;
8579 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8580 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8581 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008582 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008583
8584 var MSC_ConnHdlr vc_conn3;
8585 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 2);
8586 pars3.mscpool.rsl_idx := 2;
8587 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000003'H))));
8588 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8589 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008590 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008591 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008592}
8593
Philipp Maier783681c2020-07-16 16:47:06 +02008594/* Allow/Deny emergency calls globally via VTY */
8595private function f_vty_allow_emerg_msc(boolean allow) runs on test_CT {
8596 f_vty_enter_cfg_msc(BSCVTY, 0);
8597 if (allow) {
8598 f_vty_transceive(BSCVTY, "allow-emergency allow");
8599 } else {
8600 f_vty_transceive(BSCVTY, "allow-emergency deny");
8601 }
8602 f_vty_transceive(BSCVTY, "exit");
8603 f_vty_transceive(BSCVTY, "exit");
8604}
8605
8606/* Allow/Deny emergency calls per BTS via VTY */
8607private function f_vty_allow_emerg_bts(boolean allow, integer bts_nr) runs on test_CT {
8608 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8609 if (allow) {
8610 f_vty_transceive(BSCVTY, "rach emergency call allowed 1");
8611 } else {
8612 f_vty_transceive(BSCVTY, "rach emergency call allowed 0");
8613 }
8614 f_vty_transceive(BSCVTY, "exit");
8615 f_vty_transceive(BSCVTY, "exit");
Neels Hofmeyrb6ed80c2020-10-12 22:52:39 +00008616 f_vty_transceive(BSCVTY, "exit");
Philipp Maier783681c2020-07-16 16:47:06 +02008617}
8618
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02008619/* Allow/Forbid Fast Return after SRVCC on a given BTS via VTY */
8620private function f_vty_allow_srvcc_fast_return(boolean allow, integer bts_nr) runs on test_CT {
8621 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8622 if (allow) {
8623 f_vty_transceive(BSCVTY, "srvcc fast-return allow");
8624 } else {
8625 f_vty_transceive(BSCVTY, "srvcc fast-return forbid");
8626 }
8627 f_vty_transceive(BSCVTY, "exit");
8628 f_vty_transceive(BSCVTY, "exit");
8629 f_vty_transceive(BSCVTY, "exit");
8630}
8631
Pau Espin Pedrol14475352021-07-22 15:48:16 +02008632/* Allow/Forbid TCH for signalling if SDCCH exhausted on a given BTS via VTY */
8633private function f_vty_allow_tch_for_signalling(boolean allow, integer bts_nr) runs on test_CT {
8634 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8635 if (allow) {
8636 f_vty_transceive(BSCVTY, "channel allocator allow-tch-for-signalling 1");
8637 } else {
8638 f_vty_transceive(BSCVTY, "channel allocator allow-tch-for-signalling 0");
8639 }
8640 f_vty_transceive(BSCVTY, "exit");
8641 f_vty_transceive(BSCVTY, "exit");
8642 f_vty_transceive(BSCVTY, "exit");
8643}
8644
Philipp Maier783681c2020-07-16 16:47:06 +02008645/* Begin assignmet procedure and send an EMERGENCY SETUP (RR) */
8646private function f_assignment_emerg_setup() runs on MSC_ConnHdlr {
8647 var PDU_ML3_MS_NW emerg_setup;
8648 var octetstring emerg_setup_enc;
8649 var RSL_Message emerg_setup_data_ind;
8650
8651 f_establish_fully(omit, omit);
8652
8653 emerg_setup := valueof(ts_ML3_MO_CC_EMERG_SETUP(1, valueof(ts_Bcap_voice)));
8654 emerg_setup_enc := enc_PDU_ML3_MS_NW(emerg_setup);
8655 emerg_setup_data_ind := valueof(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), emerg_setup_enc));
8656
8657 RSL.send(emerg_setup_data_ind);
8658}
8659
8660/* Test if the EMERGENCY SETUP gets passed on to the MSC via A when EMERGENCY
8661 * CALLS are permitted by the BSC config. */
8662private function f_TC_assignment_emerg_setup_allow(charstring id) runs on MSC_ConnHdlr {
8663 var PDU_BSSAP emerg_setup_data_ind_bssap;
8664 var PDU_ML3_MS_NW emerg_setup;
8665 timer T := 3.0;
8666
8667 f_assignment_emerg_setup()
8668
8669 T.start;
8670 alt {
8671 [] BSSAP.receive(tr_BSSAP_DTAP) -> value emerg_setup_data_ind_bssap {
8672 emerg_setup := dec_PDU_ML3_MS_NW(emerg_setup_data_ind_bssap.pdu.dtap);
8673 if (not isbound(emerg_setup.msgs.cc.emergencySetup)) {
8674 setverdict(fail, "no emergency setup");
8675 }
8676 }
8677 [] BSSAP.receive {
8678 setverdict(fail, "unexpected BSSAP message!");
8679 }
8680 [] T.timeout {
8681 setverdict(fail, "timout waiting for EMERGENCY SETUP!");
8682 }
8683 }
8684
8685 setverdict(pass);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01008686 f_perform_clear();
Philipp Maier783681c2020-07-16 16:47:06 +02008687}
8688
8689/* Test if the EMERGENCY SETUP gets blocked by the BSC if EMERGENCY CALLS are
8690 * forbidden by the BSC config. */
8691private function f_TC_assignment_emerg_setup_deny(charstring id) runs on MSC_ConnHdlr {
8692 var PDU_BSSAP emerg_setup_data_ind_bssap;
8693 timer T := 3.0;
8694
8695 f_assignment_emerg_setup()
8696
8697 T.start;
8698 alt {
8699 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
8700 setverdict(pass);
8701 }
8702 [] RSL.receive {
8703 setverdict(fail, "unexpected RSL message!");
8704 }
8705 [] T.timeout {
8706 setverdict(fail, "timout waiting for RR CHANNEL RELEASE!");
8707 }
8708 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01008709 BSSAP.receive(tr_BSSMAP_ClearRequest);
8710 f_perform_clear();
Philipp Maier783681c2020-07-16 16:47:06 +02008711}
8712
8713/* EMERGENCY CALL situation #1, allowed globally and by BTS */
8714testcase TC_assignment_emerg_setup_allow() runs on test_CT {
8715 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8716 var MSC_ConnHdlr vc_conn;
8717
8718 f_init(1, true);
8719 f_sleep(1.0);
8720
8721 f_vty_allow_emerg_msc(true);
8722 f_vty_allow_emerg_bts(true, 0);
8723 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_allow), pars);
8724 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008725 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008726}
8727
8728/* EMERGENCY CALL situation #2, forbidden globally but allowed by BTS */
8729testcase TC_assignment_emerg_setup_deny_msc() runs on test_CT {
8730 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8731 var MSC_ConnHdlr vc_conn;
8732
8733 f_init(1, true);
8734 f_sleep(1.0);
8735
8736 f_vty_allow_emerg_msc(false);
8737 f_vty_allow_emerg_bts(true, 0);
8738 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
8739 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008740 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008741}
8742
8743/* EMERGENCY CALL situation #3, allowed globally but forbidden by BTS */
8744testcase TC_assignment_emerg_setup_deny_bts() runs on test_CT {
8745 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8746 var MSC_ConnHdlr vc_conn;
8747
8748 /* Note: This simulates a spec violation by the MS, correct MS
8749 * implementations would not try to establish an emergency call because
8750 * the system information tells in advance that emergency calls are
8751 * not forbidden */
8752
8753 f_init(1, true);
8754 f_sleep(1.0);
8755
8756 f_vty_allow_emerg_msc(true);
8757 f_vty_allow_emerg_bts(false, 0);
8758 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
8759 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008760 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008761}
8762
Philipp Maier82812002020-08-13 18:48:27 +02008763/* Test what happens when an emergency call arrives while all TCH channels are
8764 * busy, the BSC is expected to terminate one call in favor of the incoming
8765 * emergency call */
8766testcase TC_emerg_premption() runs on test_CT {
8767 var ASP_RSL_Unitdata rsl_ud;
8768 var integer i;
8769 var integer chreq_total, chreq_nochan;
8770 var RSL_Message rx_rsl;
8771 var RslChannelNr chan_nr;
8772
8773 f_init(1);
8774 f_sleep(1.0);
8775
8776 f_vty_allow_emerg_msc(true);
8777 f_vty_allow_emerg_bts(true, 0);
8778
8779 /* Fill up all channels on the BTS */
8780 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
8781 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
8782 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS; i := i+1) {
8783 chan_nr := f_chreq_act_ack('33'O, i);
8784 }
8785 IPA_RSL[0].clear;
8786 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
8787 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
8788
8789 /* Send Channel request for emegergency call */
8790 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
8791
8792 /* Expect the BSC to release one (the first) TCH/F on the BTS */
8793 chan_nr := valueof(t_RslChanNr_Bm(1));
8794 f_expect_chan_rel(0, chan_nr, expect_rr_chan_rel := false, expect_rll_rel_req := false);
8795
8796 /* Expect the BSC to send activate/assign the a channel for the emergency call */
8797 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8798 chan_nr := rx_rsl.ies[0].body.chan_nr;
8799 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 33));
8800 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Philipp Maier104f4c02020-09-11 18:12:18 +02008801
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008802 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008803}
8804
8805/* Hopping parameters per a timeslot */
Vadim Yanitskiybc6654a2020-09-13 01:27:40 +07008806private type record length(0..64) of GsmArfcn ArfcnList;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008807private type record FHParamsTs {
8808 boolean enabled,
8809 uint6_t hsn,
8810 uint6_t maio,
8811 ArfcnList ma
8812};
8813
8814/* Hopping parameters per a transceiver */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008815private type record FHParamsTrx {
Philipp Maier798d8952021-10-19 14:43:19 +02008816 GsmBandArfcn arfcn,
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008817 FHParamsTs ts[8]
8818};
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008819
8820/* Randomly generate the hopping parameters for the given timeslot numbers */
8821private function f_TC_fh_params_gen(template integer tr_tn := (1, 3, 5))
8822runs on test_CT return FHParamsTrx {
8823 var FHParamsTrx fhp;
8824
Philipp Maier798d8952021-10-19 14:43:19 +02008825 /* Generate a random ARFCN in the range of 0 - 3. This ARFCN will
8826 * fall in the GSM900 band. */
8827 fhp.arfcn.arfcn := f_rnd_int(3);
8828 fhp.arfcn.pcs := false;
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008829
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008830 for (var integer tn := 0; tn < 8; tn := tn + 1) {
8831 if (not match(tn, tr_tn)) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008832 fhp.ts[tn].enabled := false;
8833 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008834 continue;
8835 }
8836
8837 /* Random HSN / MAIO values: 0..63 */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008838 fhp.ts[tn].hsn := f_rnd_int(64);
8839 fhp.ts[tn].maio := f_rnd_int(64);
8840 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008841
8842 /* Random Mobile Allocation (hopping channels) */
8843 var integer ma_len := 2 + f_rnd_int(9); /* 2..10 channels */
8844 var integer step := 3 + f_rnd_int(4); /* 3..6 stepping */
8845 for (var integer i := 1; i <= ma_len; i := i + 1) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008846 fhp.ts[tn].ma := fhp.ts[tn].ma & { i * step };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008847 }
8848
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008849 fhp.ts[tn].enabled := true;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008850 }
8851
8852 log("f_TC_fh_params_gen(): ", fhp);
8853 return fhp;
8854}
8855
8856/* Make sure that the given Channel Description IE matches the hopping configuration */
8857private function f_TC_fh_params_match_chan_desc(in FHParamsTrx fhp, in ChannelDescription cd)
8858{
8859 var template (present) ChannelDescription tr_cd;
8860 var template (present) MaioHsn tr_maio_hsn;
8861 var uint3_t tn := cd.chan_nr.tn;
8862
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008863 if (fhp.ts[tn].enabled) {
8864 tr_maio_hsn := tr_HsnMaio(fhp.ts[tn].hsn, fhp.ts[tn].maio);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008865 tr_cd := tr_ChanDescH1(cd.chan_nr, tr_maio_hsn);
8866 } else {
Philipp Maier798d8952021-10-19 14:43:19 +02008867 tr_cd := tr_ChanDescH0(cd.chan_nr, fhp.arfcn.arfcn);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008868 }
8869
8870 if (not match(cd, tr_cd)) {
8871 setverdict(fail, "Channel Description IE does not match: ",
8872 cd, " vs expected ", tr_cd);
8873 }
8874}
8875
8876/* Make sure that the given Mobile Allocation IE matches the hopping configuration */
8877private function f_TC_fh_params_match_ma(in FHParamsTrx fhp, uint3_t tn,
8878 in MobileAllocationLV ma)
8879{
8880 var template MobileAllocationLV tr_ma := f_TC_fh_params_gen_tr_ma(fhp, tn, ma);
8881
8882 if (not match(ma, tr_ma)) {
8883 setverdict(fail, "Mobile Allocation IE does not match (tn := ",
8884 tn, "): ", ma, " vs expected: ", tr_ma);
8885 } else {
8886 setverdict(pass);
8887 }
8888}
8889
8890private function f_TC_fh_params_gen_tr_ma(in FHParamsTrx fhp, uint3_t tn,
8891 in MobileAllocationLV ma)
8892return template MobileAllocationLV {
8893 /* Mobile Allocation IE is expected to be empty if hopping is not enabled */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008894 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008895 return { len := 0, ma := ''B };
8896 }
8897
8898 var bitstring full_mask := f_pad_bit(''B, 1024, '0'B);
8899 var bitstring slot_mask := f_pad_bit(''B, 1024, '0'B);
8900 var bitstring ma_mask := ''B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008901
8902 /* Compose the full bit-mask (all channels, up to 1024 entries) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008903 for (var integer i := 0; i < lengthof(fhp.ts); i := i + 1) {
8904 for (var integer j := 0; j < lengthof(fhp.ts[i].ma); j := j + 1) {
8905 if (full_mask[fhp.ts[i].ma[j]] == '1'B)
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008906 { continue; }
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008907 full_mask[fhp.ts[i].ma[j]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008908 }
8909 }
8910
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008911 /* Take ARFCN of the TRX itself into account */
Philipp Maier798d8952021-10-19 14:43:19 +02008912 full_mask[fhp.arfcn.arfcn] := '1'B;
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008913
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008914 /* Compose a bit-mask for the given timeslot number */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008915 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
8916 slot_mask[fhp.ts[tn].ma[i]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008917 }
8918
8919 /* Finally, compose the Mobile Allocation bit-mask */
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07008920 for (var integer i := 1; i < lengthof(full_mask); i := i + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008921 if (full_mask[i] != '1'B)
8922 { continue; }
8923
8924 /* FIXME: ma_mask := ma_mask & slot_mask[i]; // triggers a bug in TITAN */
8925 if (slot_mask[i] == '1'B) {
8926 ma_mask := ma_mask & '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008927 } else {
8928 ma_mask := ma_mask & '0'B;
8929 }
8930 }
8931
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07008932 /* ARFCN 0 (if present) goes to the last position of the bit-mask */
8933 if (full_mask[0] == '1'B) {
8934 /* FIXME: ma_mask := ma_mask & slot_mask[0]; // triggers a bug in TITAN */
8935 if (slot_mask[0] == '1'B) {
8936 ma_mask := ma_mask & '1'B;
8937 } else {
8938 ma_mask := ma_mask & '0'B;
8939 }
8940 }
8941
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008942 /* Ensure that ma_mask is octet-aligned */
Vadim Yanitskiy2aa02522020-09-06 14:05:23 +07008943 var integer ma_mask_len := (lengthof(ma_mask) + 8 - 1) / 8;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008944 ma_mask := f_pad_bit(ma_mask, ma_mask_len * 8, '0'B);
8945
8946 return { len := ma_mask_len, ma := ma_mask };
8947}
8948
Philipp Maier798d8952021-10-19 14:43:19 +02008949/* Configure the appropriate band for a given arfcn, exc */
8950private function f_TC_set_band_by_arfcn(integer bts_nr, GsmBandArfcn arfcn) runs on test_CT
8951{
8952 var charstring band;
8953 var GsmBandArfcn arfcn_ := valueof(ts_GsmBandArfcn(arfcn.arfcn, arfcn.pcs, false));
8954
8955 select (arfcn_) {
8956 case (tr_GsmBandArfcn((259..293), false, ?)) { band := "GSM450"; }
8957 case (tr_GsmBandArfcn((306..340), false, ?)) { band := "GSM480"; }
8958 case (tr_GsmBandArfcn((438..511), false, ?)) { band := "GSM750"; }
8959 case (tr_GsmBandArfcn((128..251), false, ?)) { band := "GSM850"; }
8960 case (tr_GsmBandArfcn((0..124), false, ?)) { band := "GSM900"; }
8961 case (tr_GsmBandArfcn((955..1023), false, ?)) { band := "GSM900"; }
8962 case (tr_GsmBandArfcn((512..885), false, ?)) { band := "DCS1800"; }
8963 case (tr_GsmBandArfcn((512..810), true, ?)) { band := "PCS1900"; }
8964 case else { return; }
8965 }
8966
8967 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8968 f_vty_transceive(BSCVTY, "band " & band);
8969 f_vty_transceive(BSCVTY, "end");
8970}
8971
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008972/* Configure the hopping parameters in accordance with the given record */
8973private function f_TC_fh_params_set(in FHParamsTrx fhp,
8974 uint8_t bts_nr := 0,
8975 uint8_t trx_nr := 0)
8976runs on test_CT {
Philipp Maier798d8952021-10-19 14:43:19 +02008977
8978 f_TC_set_band_by_arfcn(bts_nr, fhp.arfcn);
8979
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008980 /* Enter the configuration node for the given BTS/TRX numbers */
8981 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
8982
Philipp Maier798d8952021-10-19 14:43:19 +02008983 f_vty_transceive(BSCVTY, "arfcn " & int2str(fhp.arfcn.arfcn));
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008984
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008985 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008986 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
8987
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008988 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008989 f_vty_transceive(BSCVTY, "hopping enabled 0");
8990 f_vty_transceive(BSCVTY, "exit"); /* go back */
8991 continue;
8992 }
8993
8994 /* Configure HSN / MAIO values */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008995 f_vty_transceive(BSCVTY, "hopping sequence-number " & int2str(fhp.ts[tn].hsn));
8996 f_vty_transceive(BSCVTY, "hopping maio " & int2str(fhp.ts[tn].maio));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008997
8998 /* Configure the Mobile Allocation (hopping channels) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008999 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
9000 f_vty_transceive(BSCVTY, "hopping arfcn add " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009001 }
9002
9003 f_vty_transceive(BSCVTY, "hopping enabled 1");
9004 f_vty_transceive(BSCVTY, "exit"); /* go back */
9005 }
9006
9007 f_vty_transceive(BSCVTY, "end");
9008}
9009
9010/* Disable frequency hopping on all timeslots */
9011private function f_TC_fh_params_unset(in FHParamsTrx fhp,
9012 uint8_t bts_nr := 0,
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009013 uint8_t trx_nr := 0,
Philipp Maier798d8952021-10-19 14:43:19 +02009014 GsmBandArfcn arfcn := {pcs := false, arfcn := 871})
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009015runs on test_CT {
Philipp Maier798d8952021-10-19 14:43:19 +02009016
9017 f_TC_set_band_by_arfcn(bts_nr, arfcn);
9018
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009019 /* Enter the configuration node for the given BTS/TRX numbers */
9020 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
9021
Philipp Maier798d8952021-10-19 14:43:19 +02009022 f_vty_transceive(BSCVTY, "arfcn " & int2str(arfcn.arfcn));
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009023
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009024 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009025 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
9026
9027 /* Delete all ARFCNs from the Mobile Allocation (if any) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009028 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
9029 f_vty_transceive(BSCVTY, "hopping arfcn del " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009030 }
9031
9032 f_vty_transceive(BSCVTY, "hopping enabled 0");
9033 f_vty_transceive(BSCVTY, "exit"); /* go back */
9034 }
9035
9036 f_vty_transceive(BSCVTY, "end");
9037 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9038}
9039
9040/* Verify presence and correctness of the hopping parameters (HSN, MAIO)
9041 * in the Channel Identification IE of the RSL CHANnel ACTIVation message. */
9042testcase TC_fh_params_chan_activ() runs on test_CT {
9043 var FHParamsTrx fhp := f_TC_fh_params_gen();
9044 var RSL_Message rsl_msg;
9045 var RSL_IE_Body ie;
9046
9047 f_init_vty();
9048
9049 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9050 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9051
9052 f_init(1);
9053
9054 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
9055 for (var integer i := 0; i < 9; i := i + 1) {
9056 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
9057 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9058
9059 /* Make sure that Channel Identification IE is present */
9060 if (not f_rsl_find_ie(rsl_msg, RSL_IE_CHAN_IDENT, ie)) {
9061 setverdict(fail, "RSL Channel Identification IE is absent");
9062 continue;
9063 }
9064
9065 /* Make sure that hopping parameters (HSN/MAIO) match */
9066 f_TC_fh_params_match_chan_desc(fhp, ie.chan_ident.ch_desc.v);
9067
9068 /* "Mobile Allocation shall be included but empty" - let's check this */
9069 if (ie.chan_ident.ma.v.len != 0) {
9070 setverdict(fail, "Mobile Allocation IE is not empty: ",
9071 ie.chan_ident.ma, ", despite it shall be");
9072 continue;
9073 }
9074 }
9075
9076 /* Disable frequency hopping */
9077 f_TC_fh_params_unset(fhp);
9078
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009079 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009080}
9081
9082/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Immediate Assignment */
9083testcase TC_fh_params_imm_ass() runs on test_CT {
9084 var FHParamsTrx fhp := f_TC_fh_params_gen();
9085 var RSL_Message rsl_msg;
9086 var RSL_IE_Body ie;
9087
9088 f_init_vty();
9089
9090 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9091 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9092
9093 f_init(1);
9094
9095 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
9096 for (var integer i := 0; i < 9; i := i + 1) {
9097 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
9098 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9099
9100 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9101 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
9102
9103 /* Make sure that Full Immediate Assign Info IE is present */
9104 if (not f_rsl_find_ie(rsl_msg, RSL_IE_FULL_IMM_ASS_INFO, ie)) {
9105 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
9106 continue;
9107 }
9108
9109 /* Decode the actual Immediate Assignment message */
9110 var GsmRrMessage rr_msg := dec_GsmRrMessage(ie.full_imm_ass_info.payload);
9111 if (not match(rr_msg.header, t_RrHeader(IMMEDIATE_ASSIGNMENT, ?))) {
9112 setverdict(fail, "Failed to match Immediate Assignment: ", rr_msg);
9113 continue;
9114 }
9115
9116 /* Make sure that hopping parameters (HSN/MAIO) match */
9117 f_TC_fh_params_match_chan_desc(fhp, rr_msg.payload.imm_ass.chan_desc);
9118
9119 /* Make sure that the Mobile Allocation IE matches */
9120 f_TC_fh_params_match_ma(fhp, rr_msg.payload.imm_ass.chan_desc.chan_nr.tn,
9121 rr_msg.payload.imm_ass.mobile_allocation);
9122 }
9123
9124 /* Disable frequency hopping */
9125 f_TC_fh_params_unset(fhp);
Philipp Maier82812002020-08-13 18:48:27 +02009126
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009127 f_shutdown_helper();
Philipp Maier82812002020-08-13 18:48:27 +02009128}
9129
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009130/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Assignment Command */
9131testcase TC_fh_params_assignment_cmd() runs on test_CT {
9132 var FHParamsTrx fhp := f_TC_fh_params_gen();
9133 var RSL_Message rsl_msg;
9134 var RSL_IE_Body ie;
9135
9136 f_init_vty();
9137
9138 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9139 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9140
9141 f_init(1);
9142
9143 /* HACK: work around "Couldn't find Expect for CRCX" */
9144 vc_MGCP.stop;
9145
9146 var template PDU_BSSAP ass_cmd := f_gen_ass_req();
9147 ass_cmd.pdu.bssmap.assignmentRequest.codecList := ts_BSSMAP_IE_CodecList({ts_CodecFR});
9148
9149 /* CS domain (TCH): 4 (TCH/F) + 2 (TCH/H) channels available
9150 * NOTE: only 3 SDCCH/4 channels are available on CCCH+SDCCH4+CBCH */
9151 for (var integer i := 0; i < 3; i := i + 1) {
9152 /* Establish a dedicated channel, so we can trigger (late) TCH assignment */
9153 var DchanTuple dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
9154
9155 /* Send a BSSMAP Assignment Command, expect CHANnel ACTIVation */
9156 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
9157 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9158
9159 /* ACKnowledge CHANnel ACTIVation, expect RSL DATA REQuest */
9160 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9161 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
9162
9163 /* Make sure that L3 Information IE is present */
9164 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
9165 setverdict(fail, "RSL L3 Information IE is absent");
9166 continue;
9167 }
9168
9169 /* Decode the L3 message and make sure it is (RR) Assignment Command */
9170 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
9171 if (not match(l3_msg.header, t_RrL3Header(ASSIGNMENT_COMMAND))) {
9172 setverdict(fail, "Failed to match Assignment Command: ", l3_msg);
9173 continue;
9174 }
9175
9176 /* Make sure that hopping parameters (HSN/MAIO) match */
9177 var ChannelDescription chan_desc := l3_msg.payload.ass_cmd.chan_desc;
9178 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9179
9180 /* Make sure that Cell Channel Description IE is present if FH is enabled */
9181 if (chan_desc.h and not ispresent(l3_msg.payload.ass_cmd.cell_chan_desc)) {
Vadim Yanitskiy38d069d2020-09-02 17:18:57 +07009182 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009183 continue;
9184 }
9185
9186 /* Make sure that the Mobile Allocation IE matches (if present) */
9187 var boolean ma_present := ispresent(l3_msg.payload.ass_cmd.mobile_allocation);
9188 if (chan_desc.h and ma_present) {
9189 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9190 l3_msg.payload.ass_cmd.mobile_allocation.v);
9191 } else if (chan_desc.h and not ma_present) {
9192 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9193 continue;
9194 } else if (not chan_desc.h and ma_present) {
9195 setverdict(fail, "FH disabled, but Mobile Allocation IE is present");
9196 continue;
9197 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01009198
9199 f_perform_clear_test_ct(dt);
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009200 }
9201
9202 /* Give the IUT some time to release all channels */
9203 f_sleep(3.0);
9204
9205 /* Disable frequency hopping */
9206 f_TC_fh_params_unset(fhp);
9207
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009208 f_shutdown_helper();
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009209}
9210
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009211/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Handover Command */
9212private function f_TC_fh_params_handover_cmd(in FHParamsTrx fhp)
9213runs on test_CT {
9214 var RSL_Message rsl_msg;
9215 var RSL_IE_Body ie;
9216 var DchanTuple dt;
9217
9218 /* Establish a dedicated channel, so we can trigger handover */
9219 dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
Vadim Yanitskiyc18ff472021-11-18 20:15:37 +03009220 f_sleep(0.5);
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009221
9222 /* Trigger handover from BTS0 to BTS1 */
9223 f_bts_0_cfg(BSCVTY, { "neighbor bts 1" });
9224 f_vty_handover(BSCVTY, 0, 0, dt.rsl_chan_nr, 1);
9225
9226 /* Expect RSL CHANnel ACTIVation on BTS1/TRX0/TS1 */
9227 rsl_msg := f_exp_ipa_rx(1, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9228
9229 /* ACKnowledge channel activation and expect (RR) Handover Command */
9230 f_ipa_tx(1, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9231 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
9232
9233 /* Make sure that L3 Information IE is present */
9234 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
9235 setverdict(fail, "RSL L3 Information IE is absent");
9236 return;
9237 }
9238
9239 /* Decode the L3 message and make sure it is (RR) Handover Command */
9240 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
9241 if (not match(l3_msg.header, t_RrL3Header(HANDOVER_COMMAND))) {
9242 setverdict(fail, "Failed to match Handover Command: ", l3_msg);
9243 return;
9244 }
9245
9246 /* Make sure that we've got SDCCH/8 on TS1 (expected to be hopping) */
9247 var ChannelDescription chan_desc := l3_msg.payload.ho_cmd.chan_desc;
9248 if (not match(chan_desc.chan_nr, t_RslChanNr_SDCCH8(1, ?))) {
9249 setverdict(fail, "Unexpected channel number: ", chan_desc.chan_nr);
9250 return;
9251 }
9252
9253 /* Make sure that hopping parameters (HSN/MAIO) match */
9254 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9255
9256 /* Make sure that Cell Channel Description IE is present */
9257 if (not ispresent(l3_msg.payload.ho_cmd.cell_chan_desc)) {
9258 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
9259 return;
9260 }
9261
9262 /* Make sure that the Mobile Allocation (after time) IE is present and matches */
9263 var boolean ma_present := ispresent(l3_msg.payload.ho_cmd.mobile_allocation);
9264 if (ma_present) {
9265 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9266 l3_msg.payload.ho_cmd.mobile_allocation.v);
9267 } else {
9268 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9269 return;
9270 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01009271
9272 f_perform_clear_test_ct(dt);
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009273}
9274testcase TC_fh_params_handover_cmd() runs on test_CT {
9275 var FHParamsTrx fhp := f_TC_fh_params_gen();
9276
9277 f_init_vty();
9278
9279 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8 on BTS1/TRX0 */
9280 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
9281
9282 f_vty_transceive(BSCVTY, "timeslot 0");
9283 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
9284 f_vty_transceive(BSCVTY, "exit"); /* go back */
9285
9286 f_vty_transceive(BSCVTY, "timeslot 1");
9287 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8");
9288 f_vty_transceive(BSCVTY, "end"); /* we're done */
9289
9290 f_TC_fh_params_set(fhp, 1); /* Enable frequency hopping on BTS1 */
9291 f_vty_transceive(BSCVTY, "drop bts connection 1 oml");
9292
9293 f_init(2);
9294
9295 f_TC_fh_params_handover_cmd(fhp);
9296
9297 /* Disable frequency hopping on BTS1 */
9298 f_TC_fh_params_unset(fhp, 1);
9299
9300 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
9301 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
9302
9303 f_vty_transceive(BSCVTY, "timeslot 0");
9304 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
9305 f_vty_transceive(BSCVTY, "exit"); /* go back */
9306
9307 f_vty_transceive(BSCVTY, "timeslot 1");
9308 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
9309 f_vty_transceive(BSCVTY, "end"); /* we're done */
9310
9311 f_shutdown_helper();
9312}
9313
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009314/* Verify the hopping parameters in System Information Type 4 */
9315testcase TC_fh_params_si4_cbch() runs on test_CT {
9316 var FHParamsTrx fhp := f_TC_fh_params_gen(tr_tn := 1);
9317 var ASP_RSL_Unitdata rx_rsl_ud;
9318 timer T := 5.0;
9319
9320 f_init_vty();
9321
9322 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8+CBCH */
9323 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
9324
9325 f_vty_transceive(BSCVTY, "timeslot 0");
9326 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
9327 f_vty_transceive(BSCVTY, "exit"); /* go back */
9328
9329 f_vty_transceive(BSCVTY, "timeslot 1");
9330 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8+cbch");
9331 f_vty_transceive(BSCVTY, "end"); /* we're done */
9332
9333 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9334 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9335
9336 f_init(1);
9337
9338 T.start;
9339 alt {
9340 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO(RSL_SYSTEM_INFO_4))) -> value rx_rsl_ud {
9341 var RSL_IE_Body ie := rx_rsl_ud.rsl.ies[2].body; /* FULL BCCH Information IE */
9342 var SystemInformation si := dec_SystemInformation(ie.other.payload);
9343
9344 /* Make sure that what we decoded is System Information Type 4 */
9345 if (si.header.message_type != SYSTEM_INFORMATION_TYPE_4) {
9346 setverdict(fail, "RSL FULL BCCH Information IE contains: ", si);
9347 repeat;
9348 }
9349
9350 /* Make sure that CBCH Channel Description IE is present */
9351 if (not ispresent(si.payload.si4.cbch_chan_desc)) {
9352 setverdict(fail, "CBCH Channel Description IE is absent");
9353 break;
9354 }
9355
9356 /* Finally, check the hopping parameters (HSN, MAIO) */
9357 var ChannelDescription chan_desc := si.payload.si4.cbch_chan_desc.v;
9358 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9359
9360 /* 3GPP TS 44.018, section 9.1.36.2 "CBCH Mobile Allocation":
9361 * The CBCH Mobile Allocation IE *shall* be present if FH is enabled. */
9362 if (chan_desc.h and not ispresent(si.payload.si4.cbch_mobile_alloc)) {
9363 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9364 break;
9365 } else if (chan_desc.h and ispresent(si.payload.si4.cbch_mobile_alloc)) {
9366 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9367 si.payload.si4.cbch_mobile_alloc.v);
9368 }
9369 }
9370 [] IPA_RSL[0].receive { repeat; }
9371 [] T.timeout {
9372 setverdict(fail, "Timeout waiting for RSL BCCH INFOrmation (SI4)");
9373 }
9374 }
9375
9376 /* Disable frequency hopping */
9377 f_TC_fh_params_unset(fhp);
9378
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07009379 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009380 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
9381
9382 f_vty_transceive(BSCVTY, "timeslot 0");
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07009383 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009384 f_vty_transceive(BSCVTY, "exit"); /* go back */
9385
9386 f_vty_transceive(BSCVTY, "timeslot 1");
9387 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
9388 f_vty_transceive(BSCVTY, "end"); /* we're done */
9389
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009390 f_shutdown_helper();
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009391}
9392
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009393template (value) PDU_BSSAP_LE ts_BSSMAP_LE_BSSLAP(template (value) BSSLAP_PDU bsslap)
9394 := ts_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, data := enc_BSSLAP_PDU(valueof(bsslap)));
9395
9396private function f_match_bsslap(PDU_BSSAP_LE got_bsslap_msg,
9397 template (present) BSSLAP_PDU expect_bsslap)
9398{
9399 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(got_bsslap_msg.pdu.bssmap.co_info.bsslap_apdu.data);
9400 if (not match(bsslap, expect_bsslap)) {
9401 log("EXPECTING BSSLAP: ", expect_bsslap);
9402 log("GOT BSSLAP: ", bsslap);
9403 setverdict(fail, "BSSLAP is not as expected");
9404 mtc.stop;
9405 }
9406 setverdict(pass);
9407}
9408
9409/* GAD: this is an Ellipsoid point with uncertainty circle, encoded as in 3GPP TS 23.032 §7.3.2. */
9410const octetstring gad_ell_point_unc_circle := '10b0646d0d5f6627'O;
9411
9412private function f_expect_bsslap(template (present) BSSLAP_PDU expect_rx_bsslap) runs on MSC_ConnHdlr {
9413 var PDU_BSSAP_LE rx_bsslap;
9414 BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap);
9415 f_match_bsslap(rx_bsslap, expect_rx_bsslap);
9416}
9417
9418/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9419 * Request on Lb interface. Either with or without the SMLC doing a BSSLAP TA Request. */
9420private function f_lcs_loc_req_for_active_ms(boolean do_ta_request := false) runs on MSC_ConnHdlr {
9421 f_sleep(1.0);
9422
9423 f_establish_fully(omit, omit);
9424 f_bssap_le_register_imsi(g_pars.imsi, omit);
9425
9426 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9427 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9428
9429 var PDU_BSSAP_LE plr;
9430 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9431
9432 if (not do_ta_request) {
9433 /* verify TA Layer 3 in APDU. First the APDU type (BSSLAP), then the BSSLAP data contents. */
9434 var template BSSMAP_LE_IE_APDU expect_apdu := tr_BSSMAP_LE_APDU(BSSMAP_LE_PROT_BSSLAP, ?);
9435 if (not match(plr.pdu.bssmap.perf_loc_req.bsslap_apdu, expect_apdu)) {
9436 log("EXPECTING BSSMAP-LE APDU IE ", expect_apdu);
9437 log("GOT BSSMAP-LE APDU IE ", plr.pdu.bssmap.perf_loc_req.bsslap_apdu);
9438 setverdict(fail, "BSSMAP-LE APDU IE is not as expected");
9439 mtc.stop;
9440 }
9441 var template BSSLAP_PDU expect_ta_layer3 := tr_BSSLAP_TA_Layer3(tr_BSSLAP_IE_TA(0));
9442 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(plr.pdu.bssmap.perf_loc_req.bsslap_apdu.data);
9443 if (not match(bsslap, expect_ta_layer3)) {
9444 log("EXPECTING BSSLAP TA Layer 3: ", expect_ta_layer3);
9445 log("GOT BSSLAP: ", bsslap);
9446 setverdict(fail, "BSSLAP is not as expected");
9447 mtc.stop;
9448 }
9449 /* OsmoBSC directly sent the TA as BSSLAP APDU in the BSSMAP-LE Perform Location Request to the SMLC. The SMLC
9450 * has no need to request the TA from the BSC and directly responds. */
9451 } else {
9452 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9453 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9454 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9455 }
9456
9457 /* SMLC got the TA from the BSC, now responds with geo information data. */
9458 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9459 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9460 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9461
9462 /* The LCS was using an active A-interface conn. It should still remain active after this. */
9463 f_mo_l3_transceive();
9464
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009465 f_perform_clear();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009466
9467 f_sleep(2.0);
9468 setverdict(pass);
9469}
9470
9471/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9472 * Request on Lb interface. Without the SMLC doing a BSSLAP TA Request. */
9473private function f_tc_lcs_loc_req_for_active_ms(charstring id) runs on MSC_ConnHdlr {
9474 f_lcs_loc_req_for_active_ms(false);
9475}
9476testcase TC_lcs_loc_req_for_active_ms() runs on test_CT {
9477 var MSC_ConnHdlr vc_conn;
9478 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9479
9480 f_init(1, true);
9481 f_sleep(1.0);
9482 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms), pars);
9483 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009484 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009485}
9486
9487/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9488 * Request on Lb interface. With the SMLC doing a BSSLAP TA Request. */
9489private function f_tc_lcs_loc_req_for_active_ms_ta_req(charstring id) runs on MSC_ConnHdlr {
9490 f_lcs_loc_req_for_active_ms(true);
9491}
9492testcase TC_lcs_loc_req_for_active_ms_ta_req() runs on test_CT {
9493 var MSC_ConnHdlr vc_conn;
9494 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9495
9496 f_init(1, true);
9497 f_sleep(1.0);
9498 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_ta_req), pars);
9499 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009500 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009501}
9502
9503/* Clear the A-interface conn only, without doing anything on Abis. Useful for LCS, for cases where there is only an A
9504 * conn without an active lchan. */
9505private function f_clear_A_conn() runs on MSC_ConnHdlr
9506{
9507 var BssmapCause cause := 0;
9508 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
9509 BSSAP.receive(tr_BSSMAP_ClearComplete);
9510 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
9511
9512 timer no_more_bssap := 5.0;
9513 no_more_bssap.start;
9514 alt {
9515 [] no_more_bssap.timeout { break; }
9516 [] BSSAP.receive(tr_BSSAP_BSSMAP) {
9517 setverdict(fail, "Expected no more BSSAP after Clear Complete");
9518 mtc.stop;
9519 }
9520 }
9521 setverdict(pass);
9522}
9523
9524/* Verify that the A-interface connection is still working, and then clear it, without doing anything on Abis. Useful
9525 * for LCS, for cases where there is only an A conn without an active lchan. */
9526private function f_verify_active_A_conn_and_clear() runs on MSC_ConnHdlr
9527{
9528 f_logp(BSCVTY, "f_verify_active_A_conn_and_clear: test A link, then clear");
9529
9530 /* When an lchan is active, we can send some L3 data from the BTS side and verify that it shows up on the other
9531 * side towards the MSC. When there is no lchan, this is not possible. To probe whether the A-interface
9532 * connection is still up, we need something that echos back on the A-interface. Another LCS request! */
9533 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9534 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9535 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?));
9536
9537 /* Right, the Perform Location Request showed up on Lb, now we can clear the A conn. */
9538 f_clear_A_conn();
9539 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
9540 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9541}
9542
9543/* With *no* active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9544 * Request on Lb interface. BSC will Page for the subscriber as soon as we (virtual SMLC) request the TA via BSSLAP.
9545 */
9546private function f_tc_lcs_loc_req_for_idle_ms(charstring id) runs on MSC_ConnHdlr {
9547 f_sleep(1.0);
9548
9549 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9550 f_bssap_le_register_imsi(g_pars.imsi, omit);
9551
9552 /* Register to receive the Paging Command */
9553 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9554 g_chan_nr := new_chan_nr;
9555 f_rslem_register(0, g_chan_nr);
9556
9557 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9558 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9559 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9560 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9561
9562 var PDU_BSSAP_LE plr;
9563 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9564
9565 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9566 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9567
9568 /* OsmoBSC needs to Page */
9569 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi)));
9570 f_logp(BSCVTY, "got Paging Command");
9571
9572 /* MS requests channel. Since the Paging was for LCS, the Paging Response does not trigger a Complete Layer 3 to
9573 * the MSC, and releases the lchan directly. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009574 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);
9575 f_expect_lchan_rel(RSL, RSL_PROC);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009576
9577 /* From the Paging Response, the TA is now known to the BSC, and it responds to the SMLC. */
9578
9579 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9580
9581 /* SMLC got the TA from the BSC, now responds with geo information data. */
9582 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9583 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9584
9585 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9586
9587 /* The lchan is gone, the A-interface conn was created for the LCS only.
9588 * Still it is clearly the MSC's job to decide whether to tear down the conn or not. */
9589 f_verify_active_A_conn_and_clear();
9590
9591 f_sleep(2.0);
9592 setverdict(pass);
9593}
9594testcase TC_lcs_loc_req_for_idle_ms() runs on test_CT {
9595 var MSC_ConnHdlr vc_conn;
9596 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9597
9598 f_init(1, true);
9599 f_sleep(1.0);
9600
9601 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9602 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9603
9604 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms), pars);
9605 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009606 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009607}
9608
9609/* With no active lchan, start BSSMAP Perform Location Request on A interface, but omit IMSI; expect failure response.
9610 */
9611private function f_tc_lcs_loc_req_no_subscriber(charstring id) runs on MSC_ConnHdlr {
9612 f_sleep(1.0);
9613
9614 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9615 f_bssap_le_register_imsi(g_pars.imsi, omit);
9616
9617 /* provoke an abort by omitting both IMSI and IMEI */
9618 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9619 valueof(ts_BSSMAP_Perform_Location_Request(omit,
9620 ts_CellId_CGI('262'H, '42'H, 23, 42)))));
9621 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9622
9623 /* BSC tells MSC about failure */
9624 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9625 locationEstimate := omit, positioningData := omit,
9626 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_DATA_MISSING_IN_REQ)));
9627
9628 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9629 f_verify_active_A_conn_and_clear();
9630
9631 f_sleep(2.0);
9632 setverdict(pass);
9633}
9634testcase TC_lcs_loc_req_no_subscriber() runs on test_CT {
9635 var MSC_ConnHdlr vc_conn;
9636 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9637
9638 f_init(1, true);
9639 f_sleep(1.0);
9640
9641 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9642 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9643
9644 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_no_subscriber), pars);
9645 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009646 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009647}
9648
9649/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9650 * BSSMAP-LE Perform Location Response (before or after sending a BSSLAP TA Request) */
9651private function f_lcs_loc_req_for_active_ms_le_timeout(boolean do_ta) runs on MSC_ConnHdlr {
9652 f_sleep(1.0);
9653
9654 f_establish_fully(omit, omit);
9655 f_bssap_le_register_imsi(g_pars.imsi, omit);
9656
9657 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9658 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9659
9660 var PDU_BSSAP_LE plr;
9661 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9662
9663 if (do_ta) {
9664 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9665 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9666 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9667 }
9668
9669 /* SMLC fails to respond, BSC runs into timeout */
9670 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_SYSTEM_FAILURE));
9671 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9672
9673 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9674 locationEstimate := omit, positioningData := omit,
9675 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_SYSTEM_FAILURE)));
9676
9677 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9678 f_verify_active_A_conn_and_clear();
9679
9680 f_sleep(2.0);
9681 setverdict(pass);
9682}
9683
9684/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9685 * BSSMAP-LE Perform Location Response, without sending a BSSLAP TA Request. */
9686private function f_tc_lcs_loc_req_for_active_ms_le_timeout(charstring id) runs on MSC_ConnHdlr {
9687 f_lcs_loc_req_for_active_ms_le_timeout(false);
9688}
9689
9690testcase TC_lcs_loc_req_for_active_ms_le_timeout() runs on test_CT {
9691 var MSC_ConnHdlr vc_conn;
9692 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9693
9694 f_init(1, true);
9695 f_sleep(1.0);
9696 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout), pars);
9697 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009698 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009699}
9700
9701/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9702 * BSSMAP-LE Perform Location Response, after sending a BSSLAP TA Request. */
9703private function f_tc_lcs_loc_req_for_active_ms_le_timeout2(charstring id) runs on MSC_ConnHdlr {
9704 f_lcs_loc_req_for_active_ms_le_timeout(true);
9705}
9706
9707testcase TC_lcs_loc_req_for_active_ms_le_timeout2() runs on test_CT {
9708 var MSC_ConnHdlr vc_conn;
9709 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9710
9711 f_init(1, true);
9712 f_sleep(1.0);
9713 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout2), pars);
9714 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009715 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009716}
9717
9718/* With *no* active lchan, start a Perform Location Request, expecting that the MS will be Paged. */
9719private function f_tc_lcs_loc_req_for_idle_ms_no_pag_resp(charstring id) runs on MSC_ConnHdlr {
9720 f_sleep(1.0);
9721
9722 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9723 f_bssap_le_register_imsi(g_pars.imsi, omit);
9724
9725 /* Register to receive the Paging Command */
9726 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9727 g_chan_nr := new_chan_nr;
9728 f_rslem_register(0, g_chan_nr);
9729
9730 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9731 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9732 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9733 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9734
9735 var PDU_BSSAP_LE plr;
9736 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9737
9738 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9739 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9740
9741 /* OsmoBSC needs to Page */
9742 var PDU_BSSAP_LE rx_bsslap;
9743 alt {
9744 [] RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi))) {
9745 f_logp(BSCVTY, "got Paging Command");
9746 repeat;
9747 }
9748 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
9749 /* MS does not respond to Paging, TA Req runs into timeout. */
9750 f_match_bsslap(rx_bsslap, tr_BSSLAP_Abort(?));
9751 }
9752 }
9753
9754 /* SMLC responds with failure */
9755 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(omit, BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
9756 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9757
9758 /* BSC tells MSC about failure */
9759 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9760 locationEstimate := omit, positioningData := omit,
9761 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_REQUEST_ABORTED)));
9762
9763 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9764 f_verify_active_A_conn_and_clear();
9765
9766 f_sleep(2.0);
9767 setverdict(pass);
9768}
9769testcase TC_lcs_loc_req_for_idle_ms_no_pag_resp() runs on test_CT {
9770 var MSC_ConnHdlr vc_conn;
9771 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9772
9773 f_init(1, true);
9774 f_sleep(1.0);
9775
9776 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9777 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9778
9779 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms_no_pag_resp), pars);
9780 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009781 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009782}
9783
9784/* During an ongoing Location Request, the MS sends a CM Service Request. Expect the same A-conn to be re-used / taken
9785 * over. */
9786private function f_tc_cm_service_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
9787 f_sleep(1.0);
9788
9789 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9790 f_bssap_le_register_imsi(g_pars.imsi, omit);
9791
9792 /* Register to receive the Paging Command */
9793 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9794 g_chan_nr := new_chan_nr;
9795 f_rslem_register(0, g_chan_nr);
9796
9797 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9798 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9799 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9800 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9801
9802 var PDU_BSSAP_LE plr;
9803 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9804
9805 /* As the A-interface conn was established for LCS, the MS coincidentally decides to issue a CM Service Request
9806 * and establish Layer 3. It should use the existing A-interface conn. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009807 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 +02009808 do_clear := false, expect_bssmap_l3 := true);
9809
9810 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9811 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9812
9813 /* OsmoBSC already has an lchan, no need to Page, just returns the TA */
9814 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9815
9816 /* SMLC got the TA from the BSC, now responds with geo information data. */
9817 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9818 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9819 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9820
9821 /* The lchan should still exist, it was from a CM Service Request. */
9822 f_mo_l3_transceive();
9823
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009824 f_perform_clear();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009825
9826 f_sleep(2.0);
9827 setverdict(pass);
9828}
9829testcase TC_cm_service_during_lcs_loc_req() runs on test_CT {
9830 var MSC_ConnHdlr vc_conn;
9831 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9832
9833 f_init(1, true);
9834 f_sleep(1.0);
9835
9836 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9837 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9838
9839 vc_conn := f_start_handler(refers(f_tc_cm_service_during_lcs_loc_req), pars);
9840 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009841 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009842}
9843
9844/* During an ongoing Perform Location Request, do a Handover, an expect a BSSLAP Reset message from the BSC to indicate
9845 * the new lchan after handover. */
9846private function f_tc_ho_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
9847 f_sleep(1.0);
9848
9849 f_establish_fully(omit, omit);
9850 f_bssap_le_register_imsi(g_pars.imsi, omit);
9851
9852 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9853 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9854
9855 var PDU_BSSAP_LE plr;
9856 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9857
9858 /* SMLC ponders the Location Request, in the meantime the BSC decides to handover */
9859 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
9860
9861 var HandoverState hs := {
9862 rr_ho_cmpl_seen := false,
9863 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02009864 old_chan_nr := -,
9865 expect_target_tsc := BTS_TSC[1]
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009866 };
9867 /* issue hand-over command on VTY */
9868 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
9869 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
9870 f_rslem_suspend(RSL1_PROC);
9871
9872 /* From the MGW perspective, a handover is is characterized by
9873 * performing one MDCX operation with the MGW. So we expect to see
9874 * one more MDCX during handover. */
9875 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
9876
9877 alt {
9878 [] as_handover(hs);
9879 }
9880
9881 var PDU_BSSAP_LE rx_bsslap;
9882
9883 interleave {
9884 /* Expect the BSC to inform the MSC about the handover */
9885 [] BSSAP.receive(tr_BSSMAP_HandoverPerformed);
9886
9887 /* Expect the BSC to inform the SMLC about the handover */
9888 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
9889 f_match_bsslap(rx_bsslap, tr_BSSLAP_Reset(BSSLAP_CAUSE_INTRA_BSS_HO));
9890 }
9891 }
9892
9893 /* SMLC now responds with geo information data. */
9894 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9895 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9896 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9897
9898 /* lchan still active */
9899 f_mo_l3_transceive(RSL1);
9900
9901 /* MSC decides it is done now. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009902 f_perform_clear(RSL1, RSL1_PROC);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009903
9904 f_sleep(2.0);
9905 setverdict(pass);
9906}
9907testcase TC_ho_during_lcs_loc_req() runs on test_CT {
9908 var MSC_ConnHdlr vc_conn;
9909 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9910
9911 f_init(2, true);
9912 f_sleep(1.0);
9913 vc_conn := f_start_handler(refers(f_tc_ho_during_lcs_loc_req), pars);
9914 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009915 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009916}
9917
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009918/* Attempt Complete Layer 3 without any MSC available (OS#4832) */
9919private function f_tc_no_msc(charstring id) runs on MSC_ConnHdlr {
9920 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9921
9922 /* Also disable attach for the single connected MSC */
9923 f_vty_msc_allow_attach(BSCVTY, { false });
9924
9925 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) ));
9926 f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
9927
9928 /* No MSC is found, expecting a proper release on RSL */
9929 interleave {
9930 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
9931 f_logp(BSCVTY, "Got RSL RR Release");
9932 }
9933 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
9934 f_logp(BSCVTY, "Got RSL Deact SACCH");
9935 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02009936 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009937 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
9938 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02009939 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009940 }
9941 }
9942 setverdict(pass);
9943}
9944testcase TC_no_msc() runs on test_CT {
9945
9946 f_init(1, true);
9947 f_sleep(1.0);
9948 var MSC_ConnHdlr vc_conn;
9949 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9950
9951 f_ctrs_bsc_init(counternames_bsc_mscpool);
9952
9953 vc_conn := f_start_handler(refers(f_tc_no_msc), pars);
9954 vc_conn.done;
9955
9956 f_ctrs_bsc_add("mscpool:subscr:no_msc");
9957 f_ctrs_bsc_verify();
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009958 f_shutdown_helper();
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009959}
9960
Harald Welte0ea2d5e2018-04-07 21:40:29 +02009961/* Dyn PDCH todo:
9962 * activate OSMO as TCH/F
9963 * activate OSMO as TCH/H
9964 * does the BSC-located PCU socket get the updated INFO?
9965 * what if no PCU is connected at the time?
9966 * is the info correct on delayed PCU (re)connect?
9967 */
Harald Welte94e0c342018-04-07 11:33:23 +02009968
Neels Hofmeyr87857ec2021-04-25 16:17:47 +00009969private function f_TC_refuse_mode_modif_to_vamos(charstring id) runs on MSC_ConnHdlr {
9970 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
9971 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
9972
9973 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
9974 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
9975 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
9976 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
9977 g_pars.ass_codec_list.codecElements[0];
9978 if (isvalue(g_pars.expect_mr_s0_s7)) {
9979 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
9980 g_pars.expect_mr_s0_s7;
9981 }
9982 }
9983 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
9984 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
9985 log("expecting ASS COMPL like this: ", exp_compl);
9986
9987 f_establish_fully(ass_cmd, exp_compl);
9988
Neels Hofmeyr8746b0d2021-06-01 17:25:39 +02009989 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 +00009990
9991 var RSL_Message rsl;
9992
9993 timer T := 5.0;
9994 T.start;
9995 alt {
9996 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
9997 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
9998 log("Rx L3 from net: ", l3);
9999 if (ischosen(l3.msgs.rrm.channelModeModify)) {
10000 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
10001 mtc.stop;
10002 }
10003 }
10004 [] RSL.receive(tr_RSL_MODE_MODIFY_REQ(g_chan_nr, ?)) -> value rsl {
10005 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
10006 mtc.stop;
10007 }
10008 [] T.timeout {
10009 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related Mode Modify should happen. */
10010 setverdict(pass);
10011 }
10012 }
10013 T.stop;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010014
10015 f_perform_clear();
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000010016}
10017
10018/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel Mode Modify to VAMOS mode is refused by
10019 * osmo-bsc. */
10020testcase TC_refuse_mode_modif_to_vamos() runs on test_CT {
10021 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10022 var MSC_ConnHdlr vc_conn;
10023
10024 f_init(1, true);
10025 f_sleep(1.0);
10026
10027 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10028 vc_conn := f_start_handler(refers(f_TC_refuse_mode_modif_to_vamos), pars);
10029 vc_conn.done;
10030 f_shutdown_helper();
10031}
10032
10033/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel activation to VAMOS mode is refused by osmo-bsc.
10034 */
10035testcase TC_refuse_chan_act_to_vamos() runs on test_CT {
10036 f_init_vty();
10037
10038 f_init(1, false);
10039 f_sleep(1.0);
10040
10041 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 activate-vamos fr");
10042
10043 var ASP_RSL_Unitdata rx_rsl_ud;
10044 timer T := 5.0;
10045
10046 T.start;
10047 alt {
10048 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(?, IPAC_PROTO_RSL_TRX0)) -> value rx_rsl_ud {
10049 if (rx_rsl_ud.rsl.msg_type == RSL_MT_CHAN_ACTIV) {
10050 T.stop;
10051 setverdict(fail, "CHANnel ACTivate in VAMOS mode succeeded even though BTS does not support VAMOS");
10052 mtc.stop;
10053 }
10054 repeat;
10055 }
10056 [] T.timeout {
10057 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related CHANnel ACTivate should happen. */
10058 setverdict(pass);
10059 }
10060 }
10061}
10062
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010063private function f_TC_reassignment_codec(charstring id) runs on MSC_ConnHdlr {
10064 /* First fully set up a speech lchan */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010065 f_assignment_codec(id, do_perform_clear := false);
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010066
10067 /* Trigger re-assignment to another lchan */
10068 var AssignmentState assignment_st := valueof(ts_AssignmentStateInit);
10069
10070 /* Re-Assignment should tell the MGW endpoint the new lchan's RTP address and port, so expecting to see exactly
10071 * one MDCX on MGCP. */
10072 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].mdcx_seen_exp + 1;
10073
10074 /* The new lchan will see all-new IPAC_CRCX and IPAC_MDCX messages telling the BTS the same RTP address and port
10075 * as the old lchan used. */
10076 g_media.bts.ipa_crcx_seen := false;
10077 g_media.bts.ipa_mdcx_seen := false;
10078
10079 /* Send different BTS side RTP port number for the new lchan */
10080 g_media.bts.bts.port_nr := 4223;
10081
10082 f_rslem_register(0, valueof(ts_RslChanNr_Bm(2))); /* <-- FIXME: can we somehow infer the timeslot that will be used? */
10083
10084 /* Trigger re-assignment. */
10085 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot " & int2str(g_chan_nr.tn) & " sub-slot 0 assignment");
10086
10087 timer T := 5.0;
10088 T.start;
10089 alt {
10090 [] as_assignment(assignment_st);
10091 [] as_Media();
10092 [] T.timeout {
10093 break;
10094 }
10095 }
10096
10097 if (not assignment_st.assignment_done) {
10098 setverdict(fail, "Assignment did not complete");
10099 mtc.stop;
10100 }
10101
10102 f_check_mgcp_expectations()
10103 setverdict(pass);
10104
10105 f_sleep(2.0);
10106 log("show lchan summary: ", f_vty_transceive_ret(BSCVTY, "show lchan summary"));
10107
10108 /* Instruct BSC to clear channel */
10109 var BssmapCause cause := 0;
10110 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
10111 interleave {
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010112 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {}
10113 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +020010114 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010115 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +020010116 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010117 }
10118 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
10119 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
10120 }
10121 }
Neels Hofmeyr40a45d12021-09-23 22:57:12 +020010122 f_expect_dlcx_conns();
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010123
10124 f_sleep(0.5);
10125}
10126
10127testcase TC_reassignment_fr() runs on test_CT {
10128 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10129 var MSC_ConnHdlr vc_conn;
10130
10131 f_init(1, true);
10132 f_sleep(1.0);
10133
Neels Hofmeyrac432fa2021-11-02 16:45:56 +010010134 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010135
10136 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10137 vc_conn := f_start_handler(refers(f_TC_reassignment_codec), pars);
10138 vc_conn.done;
10139
10140 /* from f_establish_fully() */
10141 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
10142 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
10143 /* from re-assignment */
10144 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
10145 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
10146 f_ctrs_bsc_and_bts_verify();
10147 f_shutdown_helper();
10148}
10149
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010150const charstring REEST_LOST_CONNECTION := "REEST_LOST_CONNECTION";
10151const charstring REEST_CLEAR := "REEST_CLEAR";
10152const charstring REEST_CLEAR_DONE := "REEST_CLEAR_DONE";
10153
10154/* CM Re-Establishment, 3GPP TS 24.008 4.5.1.6.
10155 * The MS <-> BTS loses radio connection, MS shows up on second BTS and asks for CM Re-Establishment.
10156 * BSC should establish a separate A conn for the same MS, the original A conn is then cleared by
10157 * the MSC as the CM Re-Establishment is handled.
10158 *
10159 * MS bts0 bts1 bsc msc test-component
10160 * |<----->|<----------------->|<-0-->| _1 Establish channel on bts 0
10161 * | | _1 wait a bit, to settle down
10162 * |<-x x--| | _1 "lose connection"
10163 * | | REEST_LOST_CONNECTION
10164 * |----------------->|------->|--1-->| _2 new A-conn: Chan Rqd, Imm Ass, Compl L3 with CM Re-Establishment Req
10165 * | | REEST_CLEAR
10166 * | |<-0---| _1 Clear Command on first A-conn
10167 * | |--0-->| _1 Clear Complete
10168 * | |<----------------->| | _1 Release first channel
10169 * | | REEST_CLEAR_DONE
10170 * |<-----------------|<-------|<-1---| _2 Chan Activ, Assignment Command
10171 * |<-----------------|<-------|<-1---| _2 Clear Command, Release
10172 *
10173 */
10174private function f_tc_cm_reestablishment_1(charstring id) runs on MSC_ConnHdlr {
10175 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
10176 var PDU_BSSAP ass_cmd := f_gen_ass_req();
10177
10178 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10179 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10180
10181 f_establish_fully(ass_cmd, exp_compl);
10182
10183 /* The original channel loses connection, MS attemts CM Re-Establishment on another cell, see
10184 * f_tc_cm_reestablishment_2(). This established channel stays active until MSC sends a Clear Command. The time
10185 * when exactly that happens is determined by f_tc_cm_reestablishment_2(). */
10186 f_sleep(2.0);
10187 COORD.send(REEST_LOST_CONNECTION);
10188
10189 alt {
10190 [] COORD.receive(REEST_CLEAR);
10191 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
10192 setverdict(fail, "Unexpected channel release");
10193 mtc.stop;
10194 }
10195 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
10196 setverdict(fail, "Unexpected channel release");
10197 mtc.stop;
10198 }
10199 }
10200 f_perform_clear()
10201 f_expect_dlcx_conns();
Neels Hofmeyr969abd02021-09-23 22:24:08 +020010202 f_create_mgcp_delete_ep(g_media.mgcp_ep);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010203 COORD.send(REEST_CLEAR_DONE);
10204}
10205
10206private function f_tc_cm_reestablishment_2(charstring id) runs on MSC_ConnHdlr {
10207 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
10208
10209 /* The MS lost the connection on the first channel, now establishes another one */
10210 COORD.receive(REEST_LOST_CONNECTION);
10211
10212 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
10213 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_REESTABL_REQ(mi));
10214 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
10215
10216 f_create_bssmap_exp(l3_enc);
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010217 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 +020010218 BSSAP.receive(tr_BSSMAP_ComplL3(l3_enc));
10219
10220 /* MSC got the CM Re-Establishment request and first off clears the previous conn. */
10221 COORD.send(REEST_CLEAR);
10222 COORD.receive(REEST_CLEAR_DONE);
10223
10224 f_sleep(2.0);
10225
10226 /* Answer the CM Re-Establishment with an Assignment Command. */
10227 var template PDU_BSSAP expect_assignment_compl := f_gen_exp_compl();
10228 var PDU_BSSAP ass_cmd := f_gen_ass_req();
10229 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10230 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10231
10232 var AssignmentState st := valueof(ts_AssignmentStateInit);
10233 st.voice_call := true;
10234 st.is_assignment := true;
10235
10236 var ExpectCriteria mgcpcrit := {
10237 connid := omit,
10238 endpoint := omit,
10239 transid := omit
10240 };
10241 f_create_mgcp_expect(mgcpcrit);
10242
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010243 f_rslem_dchan_queue_enable(RSL1_PROC);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010244
10245 BSSAP.send(ass_cmd);
10246
10247 var PDU_BSSAP bssap;
10248
10249 alt {
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010250 [] as_assignment(st, rsl_pt := RSL1, rsl_proc_pt := RSL1_PROC);
10251 [] as_Media_ipacc(RSL1, RSL2);
10252 [] as_Media_mgw();
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010253 [st.assignment_done] BSSAP.receive(expect_assignment_compl) {
10254 break;
10255 }
10256 }
10257
10258 f_sleep(3.0);
10259
10260 f_logp(BSCVTY, "f_tc_cm_reestablishment_2 clearing");
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010261 f_perform_clear(RSL1, RSL1_PROC);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010262 f_expect_dlcx_conns();
10263}
10264
10265testcase TC_cm_reestablishment() runs on test_CT {
10266 var TestHdlrParams pars1 := f_gen_test_hdlr_pars();
10267 var MSC_ConnHdlr vc_conn1;
10268
10269 var TestHdlrParams pars2 := f_gen_test_hdlr_pars();
10270 var MSC_ConnHdlr vc_conn2;
10271 pars2.imsi := pars1.imsi;
10272 pars2.media_nr := 2;
Neels Hofmeyrbf720202021-10-02 12:58:24 +020010273 pars2.expect_tsc := BTS_TSC[1];
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010274
10275 f_init(2, true, guard_timeout := 40.0);
10276 f_sleep(1.0);
10277
10278 vc_conn1 := f_start_handler_create(pars1);
10279 vc_conn2 := f_start_handler_create(pars2);
10280 connect(vc_conn1:COORD, vc_conn2:COORD);
10281 f_start_handler_run(vc_conn1, refers(f_tc_cm_reestablishment_1), pars1);
10282 f_start_handler_run(vc_conn2, refers(f_tc_cm_reestablishment_2), pars2);
10283 vc_conn1.done;
10284 vc_conn2.done;
10285
10286 f_shutdown_helper();
10287}
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000010288
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010289function f_exp_ipa_rx_nonfatal(integer bts_nr, template (present) RSL_Message t_rx, float t_secs := 2.0,
10290 IpaStreamId sid := IPAC_PROTO_RSL_TRX0, boolean ignore_other_rx := true)
10291runs on test_CT return template (omit) RSL_Message {
10292 var ASP_RSL_Unitdata rx_rsl_ud;
10293 timer T := t_secs;
10294
10295 T.start;
10296 alt {
10297 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
10298 T.stop;
10299 }
10300 [ignore_other_rx] IPA_RSL[bts_nr].receive { repeat; }
10301 [not ignore_other_rx] IPA_RSL[bts_nr].receive {
10302 log("f_exp_ipa_rx_nonfatal(): Got different message than ", t_rx);
10303 T.stop;
10304 return omit;
10305 }
10306 [] T.timeout {
10307 return omit;
10308 }
10309 }
10310 return rx_rsl_ud.rsl;
10311}
10312
10313private function f_vty_set_imm_ass(TELNETasp_PT pt, BtsNr bts_nr := 0, charstring imm_ass_setting := "post-chan-ack") {
10314 f_vty_enter_cfg_bts(pt, bts_nr);
10315 f_vty_transceive(pt, "immediate-assignment " & imm_ass_setting);
10316 f_vty_transceive(pt, "exit");
10317 f_vty_transceive(pt, "exit");
10318 f_vty_transceive(pt, "exit");
10319}
10320
10321private function f_verify_imm_ass(RSL_Message imm_ass, template uint8_t ra := ?, template GsmFrameNumber fn := ?,
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010322 template RslChannelNr chan_nr := ?,
10323 template (present) uint12_t arfcn := ?,
10324 template (present) uint3_t tsc := ?)
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010325{
10326 var RSL_IE_Body full_imm_ass_info;
10327 if (not f_rsl_find_ie(imm_ass, RSL_IE_FULL_IMM_ASS_INFO, full_imm_ass_info)) {
10328 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
10329 mtc.stop;
10330 }
10331
10332 var GsmRrMessage rr_imm_ass := dec_GsmRrMessage(full_imm_ass_info.full_imm_ass_info.payload);
10333 var template GsmRrMessage expect_imm_ass := tr_IMM_ASS(ra := ra,
10334 fn := fn,
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010335 ch_desc := tr_ChanDescH0(chan_nr, arfcn, tsc),
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010336 page_mode := ?);
10337 if (not match(rr_imm_ass, expect_imm_ass)) {
10338 log("Error: expected ", expect_imm_ass, " got ", rr_imm_ass);
10339 setverdict(fail, "Failed to match Immediate Assignment");
10340 mtc.stop;
10341 }
10342}
10343
10344testcase TC_imm_ass_post_chan_ack() runs on test_CT {
10345 var RSL_Message chan_act;
10346 var RSL_Message imm_ass;
10347
10348 f_init(1, false);
10349 f_sleep(1.0);
10350
10351 /* (should be the default anyway, just to make things clear) */
10352 f_vty_set_imm_ass(BSCVTY, 0, "post-chan-ack");
10353
10354 /* RA containing reason=LU */
10355 var GsmFrameNumber fn := 2342;
10356 var uint8_t ra := 2;
10357 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10358
10359 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10360
10361 /* First send the Chan Act ACK */
10362 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010363 var DchanTuple dt;
10364 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010365 var RSL_IE_Body chan_ident_ie;
10366 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10367 setverdict(fail, "RSL Channel Identification IE is absent");
10368 mtc.stop;
10369 }
10370
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010371 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn + 10));
10372
10373 /* Then expect the Immediate Assignment, after we ACKed the chan act */
10374 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10375
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010376 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10377 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010378
10379 /* Check that the lchan is working */
10380 var octetstring l3 := '00010203040506'O;
10381 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10382
10383 var BSSAP_N_CONNECT_ind rx_c_ind;
10384 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010385 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010386 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10387
10388 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010389 f_perform_clear_test_ct(dt);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010390 f_shutdown_helper();
10391}
10392
10393testcase TC_imm_ass_pre_chan_ack() runs on test_CT {
10394 var RSL_Message chan_act;
10395 var RSL_Message imm_ass;
10396
10397 f_init(1, false);
10398 f_sleep(1.0);
10399
10400 f_vty_set_imm_ass(BSCVTY, 0, "pre-chan-ack");
10401
10402 /* RA containing reason=LU */
10403 var GsmFrameNumber fn := 2342;
10404 var uint8_t ra := 2;
10405 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10406
10407 /* (set bts 0 cfg back to default) */
10408 f_vty_set_imm_ass(BSCVTY);
10409
10410 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10411 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010412 var DchanTuple dt;
10413 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010414 var RSL_IE_Body chan_ident_ie;
10415 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10416 setverdict(fail, "RSL Channel Identification IE is absent");
10417 mtc.stop;
10418 }
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010419
10420 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10421 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010422 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10423 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010424
10425 /* Only now send the Chan Act ACK */
10426 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10427
10428 /* Check that the lchan is working */
10429 var octetstring l3 := '00010203040506'O;
10430 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10431
10432 var BSSAP_N_CONNECT_ind rx_c_ind;
10433 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010434 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010435 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10436
10437 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010438 f_perform_clear_test_ct(dt);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010439 f_shutdown_helper();
10440}
10441
Neels Hofmeyr23158742021-09-07 19:08:07 +020010442testcase TC_imm_ass_pre_ts_ack() runs on test_CT {
10443 var RSL_Message chan_act;
10444 var RSL_Message imm_ass;
10445
10446 f_init(1, false);
10447 f_sleep(1.0);
10448
10449 f_vty_set_imm_ass(BSCVTY, 0, "pre-ts-ack");
10450
10451 /* RA containing reason=LU */
10452 var GsmFrameNumber fn := 2342;
10453 var uint8_t ra := 2;
10454 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10455
10456 /* (set bts 0 cfg back to default) */
10457 f_vty_set_imm_ass(BSCVTY);
10458
10459 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10460 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010461 var DchanTuple dt;
10462 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyr23158742021-09-07 19:08:07 +020010463 var RSL_IE_Body chan_ident_ie;
10464 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10465 setverdict(fail, "RSL Channel Identification IE is absent");
10466 mtc.stop;
10467 }
10468
10469 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10470 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10471 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10472 chan_ident_ie.chan_ident.ch_desc.v.tsc);
10473
10474 /* Only now send the Chan Act ACK */
10475 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10476
10477 /* Check that the lchan is working */
10478 var octetstring l3 := '00010203040506'O;
10479 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10480
10481 var BSSAP_N_CONNECT_ind rx_c_ind;
10482 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010483 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyr23158742021-09-07 19:08:07 +020010484 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10485
10486 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010487 f_perform_clear_test_ct(dt);
Neels Hofmeyr23158742021-09-07 19:08:07 +020010488 f_shutdown_helper();
10489}
10490
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010491testcase TC_imm_ass_pre_chan_ack_dyn_ts() runs on test_CT {
10492 /* change Timeslot 6 before f_init() starts RSL */
10493 f_init_vty();
10494 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
10495 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10496
10497 f_init(1, false);
10498 f_sleep(1.0);
10499
10500 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
10501 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010502 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010503 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2323));
10504
10505 /* clean up timeslot 6 config, will only take effect when the OML drops the next time */
10506 f_ts_set_chcomb(0, 0, 6, "PDCH");
10507
10508 /* block all static timeslots so that the dyn TS will be used */
10509 f_disable_all_tch_f();
10510 f_disable_all_tch_h();
10511 f_disable_all_sdcch();
10512
10513 var RSL_Message chan_act;
10514 var RSL_Message imm_ass;
10515
10516 f_init(1, false);
10517 f_sleep(1.0);
10518
10519 f_vty_set_imm_ass(BSCVTY, 0, "pre-chan-ack");
10520
10521 /* RA containing reason=LU */
10522 var GsmFrameNumber fn := 2342;
10523 var uint8_t ra := 2;
10524 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10525
10526 /* (set bts 0 cfg back to default) */
10527 f_vty_set_imm_ass(BSCVTY);
10528
10529 /* Expect the dyn TS to deactivate PDCH first */
10530 f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
10531 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
10532
10533 /* Now activation as SDCCH8 */
10534 chan_nr := valueof(t_RslChanNr_SDCCH8(tn := 6, sub_slot := 0));
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010535 var DchanTuple dt;
10536 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010537
10538 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010539 var RSL_IE_Body chan_ident_ie;
10540 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10541 setverdict(fail, "RSL Channel Identification IE is absent");
10542 mtc.stop;
10543 }
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010544
10545 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10546 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010547 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10548 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010549
10550 /* Only now send the Chan Act ACK */
10551 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10552
10553 /* Check that the lchan is working */
10554 var octetstring l3 := '00010203040506'O;
10555 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10556
10557 var BSSAP_N_CONNECT_ind rx_c_ind;
10558 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010559 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010560 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10561
10562 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010563 f_perform_clear_test_ct(dt);
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010564 f_shutdown_helper();
10565}
10566
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010567testcase TC_imm_ass_pre_ts_ack_dyn_ts() runs on test_CT {
10568 /* change Timeslot 6 before f_init() starts RSL */
10569 f_init_vty();
10570 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
10571 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10572
10573 f_init(1, false);
10574 f_sleep(1.0);
10575
10576 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
10577 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010578 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010579 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2323));
10580
10581 /* clean up timeslot 6 config, will only take effect when the OML drops the next time */
10582 f_ts_set_chcomb(0, 0, 6, "PDCH");
10583
10584 /* block all static timeslots so that the dyn TS will be used */
10585 f_disable_all_tch_f();
10586 f_disable_all_tch_h();
10587 f_disable_all_sdcch();
10588
10589 var RSL_Message chan_act;
10590 var RSL_Message imm_ass;
10591
10592 f_init(1, false);
10593 f_sleep(1.0);
10594
10595 f_vty_set_imm_ass(BSCVTY, 0, "pre-ts-ack");
10596
10597 /* RA containing reason=LU */
10598 var GsmFrameNumber fn := 2342;
10599 var uint8_t ra := 2;
10600 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10601
10602 /* (set bts 0 cfg back to default) */
10603 f_vty_set_imm_ass(BSCVTY);
10604
10605 /* Expect the dyn TS to deactivate PDCH first */
10606 f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
10607
10608 /* And already the Immediate Assignment even before the PDCH Deact ACK */
10609 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10610
10611 /* continue the Osmo style PDCH Deact (usual chan rel) */
10612 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
10613
10614 /* Now activation as SDCCH8 */
10615 chan_nr := valueof(t_RslChanNr_SDCCH8(tn := 6, sub_slot := 0));
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010616 var DchanTuple dt;
10617 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010618
10619 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010620 var RSL_IE_Body chan_ident_ie;
10621 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10622 setverdict(fail, "RSL Channel Identification IE is absent");
10623 mtc.stop;
10624 }
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010625 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10626
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010627 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10628 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010629
10630 /* Check that the lchan is working */
10631 var octetstring l3 := '00010203040506'O;
10632 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10633
10634 var BSSAP_N_CONNECT_ind rx_c_ind;
10635 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010636 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010637 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10638
10639 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010640 f_perform_clear_test_ct(dt);
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010641 f_shutdown_helper();
10642}
10643
Neels Hofmeyr5d7d13f2021-09-07 14:44:36 +020010644/* GET and SET the bts.N.trx.M.rf_locked CTRL variable */
10645testcase TC_ctrl_trx_rf_locked() runs on test_CT {
10646 var MSC_ConnHdlr vc_conn;
10647
10648 f_init(nr_bts := 2, handler_mode := true, nr_msc := 1);
10649 f_sleep(1.0);
10650
10651 /* BTS 0, 1, 2 are OML unlocked, only BTS 0, 1 are actually connected to RSL. */
10652 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10653 "0,0,operational,unlocked,on,rsl-up;" &
10654 "1,0,operational,unlocked,on,rsl-up;" &
10655 "2,0,operational,unlocked,on,rsl-down;" &
10656 "3,0,inoperational,locked,on,rsl-down;");
10657
10658 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: lock BTS 1 TRX 0");
10659 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "1");
10660 /* give it a moment to settle the FSM status */
10661 f_sleep(1.0);
10662
10663 /* Now BTS 1 TRX 0 should reflect "locked". Note the RF policy stays "on", because this is still handled
10664 * globally in osmo-bsc. Probably after sending "rf_locked 1" for a TRX, that TRX should reflect an RF policy
10665 * of "off"? But that's for a future patch if at all. */
10666 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10667 "0,0,operational,unlocked,on,rsl-up;" &
10668 "1,0,operational,locked,on,rsl-up;" &
10669 "2,0,operational,unlocked,on,rsl-down;" &
10670 "3,0,inoperational,locked,on,rsl-down;");
10671
10672 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: lock the already locked TRX, nothing should change");
10673 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "1");
10674 f_sleep(1.0);
10675 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10676 "0,0,operational,unlocked,on,rsl-up;" &
10677 "1,0,operational,locked,on,rsl-up;" &
10678 "2,0,operational,unlocked,on,rsl-down;" &
10679 "3,0,inoperational,locked,on,rsl-down;");
10680
10681 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock BTS 1 TRX 0");
10682 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "0");
10683 f_sleep(1.0);
10684 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10685 "0,0,operational,unlocked,on,rsl-up;" &
10686 "1,0,operational,unlocked,on,rsl-up;" &
10687 "2,0,operational,unlocked,on,rsl-down;" &
10688 "3,0,inoperational,locked,on,rsl-down;");
10689
10690 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock an already unlocked TRX, nothing should change");
10691 f_ctrl_set(IPA_CTRL, "bts.0.trx.0.rf_locked", "0");
10692 f_sleep(1.0);
10693 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10694 "0,0,operational,unlocked,on,rsl-up;" &
10695 "1,0,operational,unlocked,on,rsl-up;" &
10696 "2,0,operational,unlocked,on,rsl-down;" &
10697 "3,0,inoperational,locked,on,rsl-down;");
10698
10699 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock an inoperational TRX");
10700 f_ctrl_set(IPA_CTRL, "bts.3.trx.0.rf_locked", "0");
10701 f_sleep(1.0);
10702 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10703 "0,0,operational,unlocked,on,rsl-up;" &
10704 "1,0,operational,unlocked,on,rsl-up;" &
10705 "2,0,operational,unlocked,on,rsl-down;" &
10706 "3,0,inoperational,locked,on,rsl-down;");
10707
10708 f_shutdown_helper();
10709}
10710
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010711const CounterNameVals counternames_cm_serv_rej := {
10712 { "cm_serv_rej", 0 },
10713 { "cm_serv_rej:imsi_unknown_in_hlr", 0 },
10714 { "cm_serv_rej:illegal_ms", 0 },
10715 { "cm_serv_rej:imsi_unknown_in_vlr", 0 },
10716 { "cm_serv_rej:imei_not_accepted", 0 },
10717 { "cm_serv_rej:illegal_me", 0 },
10718 { "cm_serv_rej:plmn_not_allowed", 0 },
10719 { "cm_serv_rej:loc_not_allowed", 0 },
10720 { "cm_serv_rej:roaming_not_allowed", 0 },
10721 { "cm_serv_rej:network_failure", 0 },
10722 { "cm_serv_rej:synch_failure", 0 },
10723 { "cm_serv_rej:congestion", 0 },
10724 { "cm_serv_rej:srv_opt_not_supported", 0 },
10725 { "cm_serv_rej:rqd_srv_opt_not_supported", 0 },
10726 { "cm_serv_rej:srv_opt_tmp_out_of_order", 0 },
10727 { "cm_serv_rej:call_can_not_be_identified", 0 },
10728 { "cm_serv_rej:incorrect_message", 0 },
10729 { "cm_serv_rej:invalid_mandantory_inf", 0 },
10730 { "cm_serv_rej:msg_type_not_implemented", 0 },
10731 { "cm_serv_rej:msg_type_not_compatible", 0 },
10732 { "cm_serv_rej:inf_eleme_not_implemented", 0 },
10733 { "cm_serv_rej:condtional_ie_error", 0 },
10734 { "cm_serv_rej:msg_not_compatible", 0 },
10735 { "cm_serv_rej:protocol_error", 0 },
10736 { "cm_serv_rej:retry_in_new_cell", 0 }
10737};
10738
10739private function f_TC_cm_serv_rej(charstring id) runs on MSC_ConnHdlr
10740{
10741 f_create_chan_and_exp();
Vadim Yanitskiya7fc5a62021-12-04 20:10:08 +030010742 /* we should now have a COMPL_L3 at the MSC */
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010743 BSSAP.send(ts_PDU_DTAP_MT(ts_CM_SERV_REJ('02'O), '00'O));
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010744 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_CM_SERV_REJ));
10745 f_perform_clear();
Neels Hofmeyr87a65612021-11-16 15:56:45 +010010746 f_sleep(1.0);
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010747}
10748testcase TC_cm_serv_rej() runs on test_CT {
10749 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10750 var MSC_ConnHdlr vc_conn;
10751
10752 f_init(1, true);
10753 f_sleep(1.0);
10754
10755 f_ctrs_bts_init(1, counternames_cm_serv_rej);
10756
10757 vc_conn := f_start_handler(refers(f_TC_cm_serv_rej), pars);
10758 vc_conn.done;
10759
10760 f_ctrs_bts_add(0, "cm_serv_rej", 1);
10761 f_ctrs_bts_add(0, "cm_serv_rej:imsi_unknown_in_hlr", 1);
10762 f_ctrs_bts_verify();
10763
Neels Hofmeyr87a65612021-11-16 15:56:45 +010010764 f_sleep(1.0);
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010765 f_shutdown_helper();
10766}
10767
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010768/* Reproduce a segfault happening when the SDCCH (primary) lchan is lost in-between a TCH Channel Activ and its Channel
10769 * Activ Ack (SYS#5627). */
10770private function f_TC_lost_sdcch_during_assignment(charstring id) runs on MSC_ConnHdlr {
10771 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Vadim Yanitskiyf0310e32021-10-26 00:30:59 +030010772
10773 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10774 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010775
10776 var BSSMAP_FIELD_CodecType codecType;
10777 codecType := valueof(ass_cmd.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType);
10778
10779 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
10780
10781 /* First establish a signalling lchan */
10782 f_create_chan_and_exp();
10783 f_rslem_dchan_queue_enable();
10784
10785 /* we should now have a COMPL_L3 at the MSC */
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010786
10787 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
10788 activate(as_Media_mgw());
10789
10790 var RslChannelNr chan_nr := { u := { ch0 := RSL_CHAN_NR_Bm_ACCH }, tn := 1 };
10791 f_rslem_register(0, chan_nr);
10792
10793 f_rslem_set_auto_chan_act_ack(RSL_PROC, false);
10794 BSSAP.send(ass_cmd);
10795
10796
10797 /* Wait for the Channel Activ for the TCH channel */
10798 var ASP_RSL_Unitdata rx_rsl_ud;
10799 RSL.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV), sid := ?)) -> value rx_rsl_ud;
10800
10801 /* make the original SDCCH disappear */
10802 RSL.send(ts_RSL_REL_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
10803
10804 /* and ACK the TCH channel activation. This caused a segfault up to OsmoBSC 1.7.0 (SYS#5627) */
10805 RSL.send(ts_ASP_RSL_UD(ts_RSL_CHAN_ACT_ACK(chan_nr, 23), rx_rsl_ud.streamId));
10806
10807 interleave {
10808 [] BSSAP.receive(tr_BSSMAP_AssignmentFail);
10809 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
10810 }
10811
10812 BSSAP.send(ts_BSSMAP_ClearCommand(0));
10813 BSSAP.receive(tr_BSSMAP_ClearComplete);
10814 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
10815
10816 var MgcpCommand mgcp;
10817 MGCP.receive(tr_DLCX()) -> value mgcp {
10818 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
10819 };
10820
10821 f_sleep(0.5);
10822}
10823testcase TC_lost_sdcch_during_assignment() runs on test_CT {
10824 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10825 var MSC_ConnHdlr vc_conn;
10826
10827 f_init(1, true);
10828 f_sleep(1.0);
10829
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010830 vc_conn := f_start_handler(refers(f_TC_lost_sdcch_during_assignment), pars);
10831 vc_conn.done;
10832
10833 f_shutdown_helper();
10834}
10835
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010836const CounterNameVals counternames_bsc_bts_all_available_allocated := {
10837 { "all_allocated:sdcch", 0 },
10838 { "all_allocated:static_sdcch", 0 },
10839 { "all_allocated:tch", 0 },
10840 { "all_allocated:static_tch", 0 }
10841}
10842
10843private function f_all_allocated_expect_counter_change(charstring_list expect_changed) runs on test_CT
10844{
10845 /* Make sure counters settle first */
10846 f_sleep(1.0);
10847
10848 /* Take a baseline of counters */
10849 f_ctrs_bsc_and_bts_init(1, counternames_bsc_bts_all_available_allocated);
10850
10851 /* Elapse some time so that we see changes in counters, hopefully where expected */
10852 f_sleep(2.0);
10853
10854 /* Get new counters */
10855 var charstring_list all_changed := {};
10856 all_changed := all_changed & f_counter_name_vals_get_changed_n(IPA_CTRL, "bsc", g_ctr_bsc);
10857 all_changed := all_changed & f_counter_name_vals_get_changed_n(IPA_CTRL, "bts", g_ctr_bts);
10858
10859 /* Compare with expectations */
10860 var charstring_list all_expect_changed := {};
10861 for (var integer i := 0; i < lengthof(expect_changed); i := i + 1) {
10862 all_expect_changed := all_expect_changed & { "bsc.0." & expect_changed[i], "bts.0." & expect_changed[i] };
10863 }
10864 f_counter_name_vals_expect_changed_list(all_changed, all_expect_changed);
10865}
10866
10867testcase TC_ratectr_all_available_allocated() runs on test_CT {
10868 var ASP_RSL_Unitdata rsl_ud;
10869 var integer i;
10870 var integer chreq_total, chreq_nochan;
10871
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010872 f_init(1, guard_timeout := 60.0);
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010873 f_sleep(1.0);
10874
10875 /* Exhaust all dedicated SDCCH lchans.
10876 /* GSM 44.018 Table 9.1.8.2:
10877 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
10878 */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010879 var DchanTuples chan_cleanup := {};
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010880 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010881 chan_cleanup := chan_cleanup & { f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010882 }
10883
10884 /* Since only bts 0 is connected, expecting all_allocated to become true for both bts 0 and the "global" bsc
10885 * level.
10886 * All SDCCH are now occupied. */
10887 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch"});
10888
10889 /* Also fill up all remaining (TCH) channels */
10890 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010891 chan_cleanup := chan_cleanup & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010892 }
10893
10894 /* All TCH are now also occupied */
10895 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch",
10896 "all_allocated:tch", "all_allocated:static_tch"});
10897
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010898 /* Clean up SDCCH lchans */
10899 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
10900 f_perform_clear_test_ct(chan_cleanup[i]);
10901 }
10902
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010903 f_shutdown_helper();
10904}
10905
10906testcase TC_ratectr_all_available_allocated_dyn() runs on test_CT {
10907 var ASP_RSL_Unitdata rsl_ud;
10908 var integer i;
10909 var integer chreq_total, chreq_nochan;
10910
10911 f_init_vty();
10912 f_ts_set_chcomb(0, 0, 2, "TCH/F_TCH/H_PDCH");
10913 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10914 /* Now we have 3 TCH/F, 1 OSMO_DYN, 1 TCH/H */
10915
10916 f_init(1, guard_timeout := 60.0);
10917 f_sleep(1.0);
10918
10919 /* The dyn TS wants to activate PDCH mode, ACK that. */
10920 var RslChannelNr chan_nr;
10921 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010922 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010923 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
10924
10925 /* Exhaust all dedicated SDCCH lchans.
10926 /* GSM 44.018 Table 9.1.8.2:
10927 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
10928 */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010929 var DchanTuples chan_cleanup := {};
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010930 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010931 chan_cleanup := chan_cleanup & { f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010932 }
10933
10934 /* The static SDCCH should now be occupied, while still 3x8 dynamic SDCCH potentially remain. So only
10935 * all_allocated:static_sdcch is counted, all_allocated:sdcch remains zero. */
10936 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch"});
10937
10938 /* Request more SDCCH, hence convert the first dyn TS to SDCCH8.
10939 * Will release them later, so remember all the DchanTuples. */
10940 var DchanTuples dyn_sddch := {};
10941 dyn_sddch := dyn_sddch & { f_est_dchan_dyn('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
10942
10943 /* Also occupy the seven other SDCCH of the dyn TS */
10944 for (i := 0; i < 7; i := i+1) {
10945 dyn_sddch := dyn_sddch & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
10946 }
10947
10948 /* Now all dynamic SDCCH are also occupied, so for the first time all_allocated:sdcch will trigger... */
10949 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch"});
10950
10951 /* occupy the remaining TCH, three TCH/F and two TCH/H lchans */
10952 for (i := 0; i < 5; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010953 chan_cleanup := chan_cleanup & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010954 }
10955
10956 /* All TCH lchans are now also occupied, both static and dynamic */
10957 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch",
10958 "all_allocated:tch", "all_allocated:static_tch"});
10959
10960 /* Starting to release the dyn TS: as soon as the first SDCCH gets released, all_allocated:sdcch stops
10961 * incrementing. */
10962 var BssmapCause cause := 0;
10963 var DchanTuple dt := dyn_sddch[0];
10964 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
10965 f_exp_chan_rel_and_clear(dt, 0);
10966
10967 /* one dyn TS SDCCH is free again, so only the static_sdcch should increment. For tch, both static and dynamic
10968 * count as occupied, so those still both increment. */
10969 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch",
10970 "all_allocated:tch", "all_allocated:static_tch"});
10971
10972 /* Release the remaining SDCCH of the dyn TS, so it becomes available as TCH again */
10973 for (i := 1; i < lengthof(dyn_sddch); i := i+1) {
10974 dt := dyn_sddch[i];
10975 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
10976 f_exp_chan_rel_and_clear(dt, 0);
10977 }
10978
10979 /* All SDCCH on the dyn TS are released, the dyn TS wants to activate PDCH again */
10980 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010981 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010982 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
10983
10984 /* Now all channels are occupied except the dyn TS, so expecting only the static counters to increment */
10985 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch", "all_allocated:static_tch"});
10986
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010987 /* Clean up SDCCH lchans */
10988 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
10989 f_perform_clear_test_ct(chan_cleanup[i]);
10990 }
10991
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010992 /* clean up config */
10993 f_ts_reset_chcomb(0);
10994
10995 f_shutdown_helper();
10996}
10997
Harald Welte28d943e2017-11-25 15:00:50 +010010998control {
Harald Welte898113b2018-01-31 18:32:21 +010010999 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +010011000 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +010011001 execute( TC_ctrl_msc0_connection_status() );
Neels Hofmeyrf65ce872021-09-23 18:40:10 +020011002 /* In SCCPlite tests, only one MSC is configured. These tests assume that three MSCs are configured, so only run
11003 * these in the AoIP test suite. */
11004 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11005 execute( TC_stat_num_msc_connected_1() );
11006 execute( TC_stat_num_msc_connected_2() );
11007 execute( TC_stat_num_msc_connected_3() );
11008 }
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +020011009 execute( TC_stat_num_bts_connected_1() );
11010 execute( TC_stat_num_bts_connected_2() );
11011 execute( TC_stat_num_bts_connected_3() );
Harald Welte96c94412017-12-09 03:12:45 +010011012 execute( TC_ctrl() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +020011013 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER) {
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +020011014 execute( TC_ctrl_location() );
11015 }
Harald Welte898113b2018-01-31 18:32:21 +010011016
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020011017 execute( TC_si_default() );
Neels Hofmeyr66aeba42020-07-06 02:21:21 +020011018 execute( TC_si2quater_2_earfcns() );
11019 execute( TC_si2quater_3_earfcns() );
11020 execute( TC_si2quater_4_earfcns() );
11021 execute( TC_si2quater_5_earfcns() );
11022 execute( TC_si2quater_6_earfcns() );
Neels Hofmeyrad132f22020-07-08 02:20:16 +020011023 execute( TC_si2quater_12_earfcns() );
11024 execute( TC_si2quater_23_earfcns() );
11025 execute( TC_si2quater_32_earfcns() );
11026 execute( TC_si2quater_33_earfcns() );
11027 execute( TC_si2quater_42_earfcns() );
11028 execute( TC_si2quater_48_earfcns() );
11029 execute( TC_si2quater_49_earfcns() );
Pau Espin Pedrol85a84432020-07-20 18:45:03 +020011030 execute( TC_si_acc_rotate() );
Alexander Couzens4ad3a352020-09-10 22:29:12 +020011031 execute( TC_si_acc_ramp_rotate() );
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020011032
Harald Welte898113b2018-01-31 18:32:21 +010011033 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +010011034 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +010011035 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +010011036 execute( TC_chan_act_ack_noest() );
Philipp Maier9c60a622020-07-09 15:08:46 +020011037 execute( TC_chan_act_ack_noest_emerg() );
Philipp Maier606f07d2020-08-12 17:21:58 +020011038 execute( TC_chan_rqd_emerg_deny() );
Harald Welteae026692017-12-09 01:03:01 +010011039 execute( TC_chan_act_ack_est_ind_noreply() );
11040 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +010011041 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +010011042 execute( TC_chan_exhaustion() );
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +070011043 execute( TC_chan_deact_silence() );
Harald Welte4003d112017-12-09 22:35:39 +010011044 execute( TC_chan_rel_rll_rel_ind() );
11045 execute( TC_chan_rel_conn_fail() );
11046 execute( TC_chan_rel_hard_clear() );
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +020011047 execute( TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() );
11048 execute( TC_chan_rel_last_eutran_plmn_hard_clear_csfb() );
Harald Welte99787102019-02-04 10:41:36 +010011049 execute( TC_chan_rel_hard_clear_csfb() );
Harald Welted8c36cd2017-12-09 23:05:31 +010011050 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +020011051 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +010011052 execute( TC_chan_rel_a_reset() );
Pau Espin Pedrolc675b612020-01-09 19:55:40 +010011053 execute( TC_chan_rel_sccp_tiar_timeout() );
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +020011054 execute( TC_chan_rel_rr_cause() );
Harald Welte6f521d82017-12-11 19:52:02 +010011055
Harald Weltecfe2c962017-12-15 12:09:32 +010011056 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +010011057
11058 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +010011059 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +010011060 execute( TC_assignment_csd() );
11061 execute( TC_assignment_ctm() );
11062 execute( TC_assignment_sign() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +020011063 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11064 execute( TC_assignment_aoip_tla_v6() );
11065 }
Harald Welte235ebf12017-12-15 14:18:16 +010011066 execute( TC_assignment_fr_a5_0() );
11067 execute( TC_assignment_fr_a5_1() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +020011068 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte8f67d1d2018-05-25 20:38:42 +020011069 execute( TC_assignment_fr_a5_1_codec_missing() );
11070 }
Harald Welte235ebf12017-12-15 14:18:16 +010011071 execute( TC_assignment_fr_a5_3() );
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +020011072 execute( TC_assignment_fr_a5_4() );
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +020011073 execute( TC_assignment_fr_a5_4_fail() );
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +020011074 execute( TC_assignment_fr_a5_not_sup() );
Harald Welte3c86ea02018-05-10 22:28:05 +020011075 execute( TC_ciph_mode_a5_0() );
11076 execute( TC_ciph_mode_a5_1() );
Oliver Smith50b98122021-07-09 15:00:28 +020011077 execute( TC_ciph_mode_a5_2_0() );
Oliver Smith1dff88d2021-07-09 08:45:51 +020011078 execute( TC_ciph_mode_a5_2_1() );
Harald Welte3c86ea02018-05-10 22:28:05 +020011079 execute( TC_ciph_mode_a5_3() );
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +020011080 execute( TC_ciph_mode_a5_4() );
Harald Welte16a4adf2017-12-14 18:54:01 +010011081
Harald Welte60aa5762018-03-21 19:33:13 +010011082 execute( TC_assignment_codec_fr() );
Neels Hofmeyr559d5d02021-04-16 16:50:49 +020011083 execute( TC_assignment_codec_fr_by_mode_modify() );
Harald Welte60aa5762018-03-21 19:33:13 +010011084 execute( TC_assignment_codec_hr() );
11085 execute( TC_assignment_codec_efr() );
11086 execute( TC_assignment_codec_amr_f() );
11087 execute( TC_assignment_codec_amr_h() );
Philipp Maier8a581d22019-03-26 18:32:48 +010011088
Neels Hofmeyrf246a922020-05-13 02:27:10 +020011089 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier8a581d22019-03-26 18:32:48 +010011090 execute( TC_assignment_codec_amr_f_S1() );
11091 execute( TC_assignment_codec_amr_h_S1() );
11092 execute( TC_assignment_codec_amr_f_S124() );
11093 execute( TC_assignment_codec_amr_h_S124() );
11094 execute( TC_assignment_codec_amr_f_S0() );
11095 execute( TC_assignment_codec_amr_f_S02() );
11096 execute( TC_assignment_codec_amr_f_S024() );
11097 execute( TC_assignment_codec_amr_f_S0247() );
11098 execute( TC_assignment_codec_amr_h_S0() );
11099 execute( TC_assignment_codec_amr_h_S02() );
11100 execute( TC_assignment_codec_amr_h_S024() );
11101 execute( TC_assignment_codec_amr_h_S0247() );
11102 execute( TC_assignment_codec_amr_f_S01234567() );
11103 execute( TC_assignment_codec_amr_f_S0234567() );
11104 execute( TC_assignment_codec_amr_f_zero() );
11105 execute( TC_assignment_codec_amr_f_unsupp() );
11106 execute( TC_assignment_codec_amr_h_S7() );
Neels Hofmeyr21863562020-11-26 00:34:33 +000011107 execute( TC_assignment_codec_amr_f_start_mode_auto() );
11108 execute( TC_assignment_codec_amr_h_start_mode_auto() );
Neels Hofmeyr3eb94562020-11-26 02:40:26 +000011109 execute( TC_assignment_codec_amr_f_start_mode_4() );
11110 execute( TC_assignment_codec_amr_h_start_mode_4() );
Neels Hofmeyr454d7922020-11-26 02:24:57 +000011111 execute( TC_assignment_codec_amr_startmode_cruft() );
Philipp Maier8a581d22019-03-26 18:32:48 +010011112 }
Harald Welte60aa5762018-03-21 19:33:13 +010011113
Philipp Maierac09bfc2019-01-08 13:41:39 +010011114 execute( TC_assignment_codec_fr_exhausted_req_hr() );
11115 execute( TC_assignment_codec_fr_exhausted_req_fr() );
11116 execute( TC_assignment_codec_fr_exhausted_req_fr_hr() );
11117 execute( TC_assignment_codec_fr_exhausted_req_hr_fr() );
11118 execute( TC_assignment_codec_hr_exhausted_req_fr() );
11119 execute( TC_assignment_codec_hr_exhausted_req_hr() );
11120 execute( TC_assignment_codec_hr_exhausted_req_hr_fr() );
11121 execute( TC_assignment_codec_hr_exhausted_req_fr_hr() );
11122 execute( TC_assignment_codec_req_hr_fr() );
11123 execute( TC_assignment_codec_req_fr_hr() );
Pau Espin Pedrol14475352021-07-22 15:48:16 +020011124 execute( TC_assignment_sdcch_exhausted_req_signalling() );
11125 execute( TC_assignment_sdcch_exhausted_req_signalling_tch_forbidden() );
11126 execute( TC_assignment_sdcch_exhausted_req_voice_tch_forbidden() );
Philipp Maierac09bfc2019-01-08 13:41:39 +010011127
Pau Espin Pedrol23510fb2021-07-20 17:00:38 +020011128 execute( TC_assignment_osmux() );
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +020011129
Harald Welte898113b2018-01-31 18:32:21 +010011130 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +010011131 execute( TC_rll_est_ind_inact_lchan() );
11132 execute( TC_rll_est_ind_inval_sapi1() );
11133 execute( TC_rll_est_ind_inval_sapi3() );
11134 execute( TC_rll_est_ind_inval_sacch() );
11135
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +070011136 /* DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
11137 execute( TC_tch_dlci_link_id_sapi() );
11138
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +070011139 /* SAPI N Reject triggered by RLL establishment failures */
11140 execute( TC_rll_rel_ind_sapi_n_reject() );
11141 execute( TC_rll_err_ind_sapi_n_reject() );
11142 execute( TC_rll_timeout_sapi_n_reject() );
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +070011143 execute( TC_rll_sapi_n_reject_dlci_cc() );
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +070011144
Harald Welte898113b2018-01-31 18:32:21 +010011145 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +010011146 execute( TC_paging_imsi_nochan() );
11147 execute( TC_paging_tmsi_nochan() );
11148 execute( TC_paging_tmsi_any() );
11149 execute( TC_paging_tmsi_sdcch() );
11150 execute( TC_paging_tmsi_tch_f() );
11151 execute( TC_paging_tmsi_tch_hf() );
11152 execute( TC_paging_imsi_nochan_cgi() );
11153 execute( TC_paging_imsi_nochan_lac_ci() );
11154 execute( TC_paging_imsi_nochan_ci() );
11155 execute( TC_paging_imsi_nochan_lai() );
11156 execute( TC_paging_imsi_nochan_lac() );
11157 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +010011158 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
11159 execute( TC_paging_imsi_nochan_rnc() );
11160 execute( TC_paging_imsi_nochan_lac_rnc() );
11161 execute( TC_paging_imsi_nochan_lacs() );
11162 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +010011163 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +010011164 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +010011165 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +010011166 execute( TC_paging_counter() );
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +010011167 execute( TC_paging_resp_unsol() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +010011168
11169 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +010011170 execute( TC_rsl_unknown_unit_id() );
11171
11172 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +010011173
11174 execute( TC_classmark() );
Harald Welteeddf0e92020-06-21 19:42:15 +020011175 execute( TC_common_id() );
Harald Welte898113b2018-01-31 18:32:21 +010011176 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +010011177 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +010011178 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +010011179 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +010011180 execute( TC_err_84_unknown_msg() );
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010011181
Harald Welte261af4b2018-02-12 21:20:39 +010011182 execute( TC_ho_int() );
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +020011183 execute( TC_ho_int_a5_0() );
11184 execute( TC_ho_int_a5_1() );
11185 execute( TC_ho_int_a5_3() );
11186 execute( TC_ho_int_a5_4() );
Neels Hofmeyr5f144212020-11-03 15:41:58 +000011187 execute( TC_ho_int_radio_link_failure() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011188
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +010011189 /* TC_ho_out_of_this_bsc is run last, see comment below */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +020011190 execute( TC_ho_out_fail_no_msc_response() );
11191 execute( TC_ho_out_fail_rr_ho_failure() );
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +020011192 execute( TC_ho_out_fail_no_result_after_ho_cmd() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011193
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010011194 execute( TC_ho_into_this_bsc() );
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +020011195 execute( TC_ho_into_this_bsc_a5_0() );
11196 execute( TC_ho_into_this_bsc_a5_1() );
11197 execute( TC_ho_into_this_bsc_a5_3() );
11198 execute( TC_ho_into_this_bsc_a5_4() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +020011199 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11200 execute( TC_ho_into_this_bsc_tla_v6() );
11201 }
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +020011202 execute( TC_srvcc_eutran_to_geran() );
Pau Espin Pedrol35801c32021-04-19 13:03:20 +020011203 execute( TC_srvcc_eutran_to_geran_ho_out() );
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +020011204 execute( TC_srvcc_eutran_to_geran_forbid_fast_return() );
11205 execute( TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011206 execute( TC_ho_in_fail_msc_clears() );
11207 execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
11208 execute( TC_ho_in_fail_no_detect() );
11209 execute( TC_ho_in_fail_no_detect2() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +010011210
Neels Hofmeyr91401012019-07-11 00:42:35 +020011211 execute( TC_ho_neighbor_config_1() );
11212 execute( TC_ho_neighbor_config_2() );
11213 execute( TC_ho_neighbor_config_3() );
11214 execute( TC_ho_neighbor_config_4() );
11215 execute( TC_ho_neighbor_config_5() );
11216 execute( TC_ho_neighbor_config_6() );
11217 execute( TC_ho_neighbor_config_7() );
11218
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +010011219 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010011220 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +010011221 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +020011222
11223 execute( TC_dyn_pdch_ipa_act_deact() );
11224 execute( TC_dyn_pdch_ipa_act_nack() );
11225 execute( TC_dyn_pdch_osmo_act_deact() );
11226 execute( TC_dyn_pdch_osmo_act_nack() );
Pau Espin Pedrol37a4c152021-11-16 19:02:23 +010011227 execute( TC_dyn_ts_sdcch8_act_deact() );
11228 execute( TC_dyn_ts_sdcch8_all_subslots_used() );
11229 execute( TC_dyn_ts_sdcch8_tch_call_act_deact() );
11230 execute( TC_dyn_ts_sdcch8_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +020011231
Stefan Sperling0796a822018-10-05 13:01:39 +020011232 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +020011233 execute( TC_chopped_ipa_payload() );
Stefan Sperling0796a822018-10-05 13:01:39 +020011234
Pau Espin Pedrol8f773632019-11-05 11:46:53 +010011235 /* Power control related */
11236 execute( TC_assignment_verify_ms_power_params_ie() );
Vadim Yanitskiy4b233042021-06-30 00:58:43 +020011237 execute( TC_c0_power_red_mode() );
Neels Hofmeyr4f118412020-06-04 15:25:10 +020011238
11239 /* MSC pooling */
11240 /* FIXME: in SCCPlite, indicating how many MSCs should be connected does currently not work. Since
11241 * RESET->RESET-ACK is unconditionally negotiated for all configured MSCs, they always all appear as connected
11242 * to osmo-bsc. The MSC pooling tests however require disconnecting selected MSCs, and hence don't work out as
11243 * intended on SCCPlite. So for now, run these only for SCCP/M3UA. */
11244 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11245 execute( TC_mscpool_L3Compl_on_1_msc() );
11246 execute( TC_mscpool_L3Complete_by_imsi_round_robin() );
11247 execute( TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() );
11248 execute( TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() );
11249 execute( TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() );
11250 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() );
11251 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_1() );
11252 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_2() );
11253 execute( TC_mscpool_LU_by_tmsi_from_other_PLMN() );
11254 execute( TC_mscpool_paging_and_response_imsi() );
11255 execute( TC_mscpool_paging_and_response_tmsi() );
11256 execute( TC_mscpool_no_allow_attach_round_robin() );
11257 execute( TC_mscpool_no_allow_attach_valid_nri() );
11258 }
11259
Harald Welte99f3ca02018-06-14 13:40:29 +020011260 execute( TC_early_conn_fail() );
11261 execute( TC_late_conn_fail() );
Oliver Smithaf03bef2021-08-24 15:34:51 +020011262 execute( TC_stats_conn_fail() );
Harald Welte99f3ca02018-06-14 13:40:29 +020011263
Philipp Maier783681c2020-07-16 16:47:06 +020011264 /* Emergency call handling (deny / allow) */
11265 execute( TC_assignment_emerg_setup_allow() );
11266 execute( TC_assignment_emerg_setup_deny_msc() );
11267 execute( TC_assignment_emerg_setup_deny_bts() );
Philipp Maier82812002020-08-13 18:48:27 +020011268 execute( TC_emerg_premption() );
11269
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +070011270 /* Frequency hopping parameters handling */
11271 execute( TC_fh_params_chan_activ() );
11272 execute( TC_fh_params_imm_ass() );
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +070011273 execute( TC_fh_params_assignment_cmd() );
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +070011274 execute( TC_fh_params_handover_cmd() );
Vadim Yanitskiyca974032020-09-01 07:20:39 +070011275 execute( TC_fh_params_si4_cbch() );
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020011276
11277 if (mp_enable_lcs_tests) {
11278 execute( TC_lcs_loc_req_for_active_ms() );
11279 execute( TC_lcs_loc_req_for_active_ms_ta_req() );
11280 execute( TC_lcs_loc_req_for_idle_ms() );
11281 execute( TC_lcs_loc_req_no_subscriber() );
11282 execute( TC_lcs_loc_req_for_active_ms_le_timeout() );
11283 execute( TC_lcs_loc_req_for_active_ms_le_timeout2() );
11284 execute( TC_lcs_loc_req_for_idle_ms_no_pag_resp() );
11285 execute( TC_cm_service_during_lcs_loc_req() );
11286 execute( TC_ho_during_lcs_loc_req() );
11287 }
Neels Hofmeyrbf037052020-10-28 22:52:02 +000011288
11289 execute( TC_no_msc() );
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000011290
11291 execute( TC_refuse_chan_act_to_vamos() );
11292 execute( TC_refuse_mode_modif_to_vamos() );
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000011293
11294 execute( TC_reassignment_fr() );
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020011295
11296 execute( TC_cm_reestablishment() );
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020011297
11298 execute( TC_imm_ass_post_chan_ack() );
11299 execute( TC_imm_ass_pre_chan_ack() );
Neels Hofmeyr23158742021-09-07 19:08:07 +020011300 execute( TC_imm_ass_pre_ts_ack() );
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020011301 execute( TC_imm_ass_pre_chan_ack_dyn_ts() );
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020011302 execute( TC_imm_ass_pre_ts_ack_dyn_ts() );
Neels Hofmeyr5d7d13f2021-09-07 14:44:36 +020011303
11304 execute( TC_ctrl_trx_rf_locked() );
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011305
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011306 execute( TC_ratectr_all_available_allocated() );
11307 execute( TC_ratectr_all_available_allocated_dyn() );
11308
Neels Hofmeyrb7581872021-11-07 14:02:49 +010011309 execute( TC_cm_serv_rej() );
11310
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011311 execute( TC_lost_sdcch_during_assignment() );
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +010011312
11313 /* Run TC_ho_out_of_this_bsc last, because it may trigger a segfault before osmo-bsc's patch
11314 * with change-id I5a3345ab0005a73597f5c27207480912a2f5aae6 */
11315 execute( TC_ho_out_of_this_bsc() );
Harald Welte28d943e2017-11-25 15:00:50 +010011316}
11317
11318}