blob: 69e187c7f5efe156bba3cc9a704a084998d76a4f [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;
Vadim Yanitskiy6e068012022-02-05 21:35:43 +0600712
713 /* Whether to check for memory leaks */
714 boolean mp_verify_talloc_count := true;
Harald Weltea4ca4462018-02-09 00:17:14 +0100715}
716
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +0200717friend function f_gen_test_hdlr_pars(integer bssap_idx := 0) return TestHdlrParams {
Philipp Maier48604732018-10-09 15:00:37 +0200718
719 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200720 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier48604732018-10-09 15:00:37 +0200721 pars.aoip := true;
722 } else {
723 pars.aoip := false;
724 }
Pau Espin Pedrol8f30ccd2019-11-01 17:30:57 +0100725 pars.exp_ms_power_level := mp_exp_ms_power_level;
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200726 pars.mscpool.bssap_idx := bssap_idx;
Neels Hofmeyrbf720202021-10-02 12:58:24 +0200727 pars.expect_tsc := BTS_TSC[0];
Vadim Yanitskiy96bb9cb2021-12-10 21:14:15 +0300728 pars.imsi := f_rnd_imsi('00101'H);
729
730 log(testcasename(), ": using IMSI ", pars.imsi);
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200731
Philipp Maier48604732018-10-09 15:00:37 +0200732 return pars;
733}
734
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200735/* Convenience functions for rate counters using g_ctr_msc. */
736
737private function f_ctrs_msc_init(integer mscs_count := NUM_MSC, CounterNameVals counternames := counternames_msc_mscpool) runs on test_CT {
738 g_ctr_msc := f_counter_name_vals_get_n(IPA_CTRL, "msc", mscs_count, counternames);
739 log("initial msc rate counters: ", g_ctr_msc);
740}
741
742private function f_ctrs_msc_add(integer msc_nr, charstring countername, integer val := 1) runs on test_CT {
Neels Hofmeyr9656e922020-06-30 01:27:01 +0200743 f_counter_name_vals_list_add(g_ctr_msc, msc_nr, countername, val);
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200744}
745
746/* f_ctrs_msc_init();
747 * f_do_thing(on_msc := 0);
748 * f_do_thing(on_msc := 0);
749 * f_do_other(on_msc := 1);
750 * f_ctrs_msc_add(0, "thing", 2);
751 * f_ctrs_msc_add(1, "other");
752 * f_ctrs_msc_verify();
753 */
754private function f_ctrs_msc_verify() runs on test_CT {
755 log("verifying msc rate counters: ", g_ctr_msc);
756 f_counter_name_vals_expect_n(IPA_CTRL, "msc", g_ctr_msc);
757}
758
759/* convenience: f_ctrs_msc_add() and f_ctrs_msc_verify() in one call.
760 * f_ctrs_msc_init();
761 * f_do_thing(on_msc := 0);
762 * f_do_thing(on_msc := 0);
763 * f_do_thing(on_msc := 0);
764 * f_ctrs_msc_expect(0, "thing", 3);
765 */
766private function f_ctrs_msc_expect(integer msc_nr, charstring countername, integer val := 1) runs on test_CT {
767 f_ctrs_msc_add(msc_nr, countername, val);
768 f_ctrs_msc_verify();
769}
770
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000771/* Convenience functions for rate counters using g_ctr_bts, always also including g_ctr_bsc. */
772
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100773private 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 +0000774 g_ctr_bts := f_counter_name_vals_get_n(IPA_CTRL, "bts", bts_count, counternames);
Neels Hofmeyr4dec8cc2021-11-29 15:59:44 +0100775 log("initial bts rate counters: ", g_ctr_bts);
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100776}
777
778function f_ctrs_bsc_and_bts_init(integer bts_count := NUM_BTS, CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
779 f_ctrs_bts_init(bts_count, counternames);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000780 f_ctrs_bsc_init(counternames);
781}
782
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100783private function f_ctrs_bsc_and_bts_handover_init(integer bts_count := NUM_BTS) runs on test_CT {
784 var CounterNameVals bts_names := counternames_bsc_bts_handover & counternames_bts_handover;
Neels Hofmeyr4dec8cc2021-11-29 15:59:44 +0100785 f_ctrs_bts_init(bts_count, bts_names);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100786 f_ctrs_bsc_init(counternames_bsc_bts_handover);
787}
788
789private function f_ctrs_bts_add(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000790 f_counter_name_vals_list_add(g_ctr_bts, bts_nr, countername, val);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100791}
792
793private function f_ctrs_bsc_and_bts_add(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
794 f_ctrs_bts_add(bts_nr, countername, val);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000795 f_ctrs_bsc_add(countername, val);
796}
797
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100798function f_ctrs_bts_verify() runs on test_CT {
799 f_counter_name_vals_expect_n(IPA_CTRL, "bts", g_ctr_bts);
800}
801
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000802/* f_ctrs_bsc_and_bts_init();
803 * f_do_thing(on_bts := 0);
804 * f_do_thing(on_bts := 0);
805 * f_do_other(on_bts := 1);
806 * f_ctrs_bsc_and_bts_add(0, "thing", 2);
807 * f_ctrs_bsc_and_bts_add(1, "other");
808 * f_ctrs_bsc_and_bts_verify();
809 */
810private function f_ctrs_bsc_and_bts_verify() runs on test_CT {
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100811 f_ctrs_bts_verify();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000812 f_ctrs_bsc_verify();
813}
814
815/* convenience: f_ctrs_bsc_and_bts_add() and f_ctrs_bsc_and_bts_verify() in one call.
816 * f_ctrs_bsc_and_bts_init();
817 * f_do_thing(on_bts := 0);
818 * f_do_thing(on_bts := 0);
819 * f_do_thing(on_bts := 0);
820 * f_ctrs_bsc_and_bts_expect(0, "thing", 3);
821 */
822private function f_ctrs_bsc_and_bts_expect(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
823 f_ctrs_bsc_and_bts_add(bts_nr, countername, val);
824 f_ctrs_bsc_and_bts_verify();
825}
826
827
828/* Convenience functions for rate counters using g_ctr_bsc. */
829
830private function f_ctrs_bsc_init(CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
831 g_ctr_bsc := f_counter_name_vals_get_n(IPA_CTRL, "bsc", 1, counternames);
832 log("initial bsc rate counters: ", g_ctr_bsc);
833}
834
835private function f_ctrs_bsc_add(charstring countername, integer val := 1) runs on test_CT {
836 f_counter_name_vals_list_add(g_ctr_bsc, 0, countername, val);
837}
838
839/* f_ctrs_bsc_init();
840 * f_do_thing();
841 * f_do_thing();
842 * f_do_other();
843 * f_ctrs_bsc_add("thing", 2);
844 * f_ctrs_bsc_add("other");
845 * f_ctrs_bsc_verify();
846 */
847private function f_ctrs_bsc_verify() runs on test_CT {
848 f_counter_name_vals_expect_n(IPA_CTRL, "bsc", g_ctr_bsc);
849}
850
851/* convenience: f_ctrs_bsc_add() and f_ctrs_bsc_verify() in one call.
852 * f_ctrs_bsc_init();
853 * f_do_thing();
854 * f_ctrs_bsc_expect("thing", 1);
855 */
856private function f_ctrs_bsc_expect(charstring countername, integer val := 1) runs on test_CT {
857 f_ctrs_bsc_add(countername, val);
858 f_ctrs_bsc_verify();
859}
860
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200861
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +0200862friend function f_shutdown_helper() runs on test_CT {
Neels Hofmeyr18997492021-12-13 17:30:35 +0100863 /* Run the subscr and conn leak test only when the VTY is initialized */
Vadim Yanitskiy6e068012022-02-05 21:35:43 +0600864 if (BSCVTY.checkstate("Mapped") and mp_verify_talloc_count) {
Neels Hofmeyr18997492021-12-13 17:30:35 +0100865 f_verify_talloc_count(BSCVTY, {"struct bsc_subscr", "struct gsm_subscriber_connection"});
866 }
867
Daniel Willmann637ef6c2018-07-25 10:49:09 +0200868 all component.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100869 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200870 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100871}
872
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200873private function f_legacy_bssap_reset(integer bssap_idx := 0) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +0100874 var BSSAP_N_UNITDATA_ind ud_ind;
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200875 var boolean reset_received := false;
Harald Weltea4ca4462018-02-09 00:17:14 +0100876 timer T := 5.0;
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200877 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
878 ts_BSSMAP_Reset(0, g_osmux_enabled)));
Harald Weltea4ca4462018-02-09 00:17:14 +0100879 T.start;
880 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200881 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap[bssap_idx].sccp_addr_own, g_bssap[bssap_idx].sccp_addr_peer,
882 tr_BSSMAP_ResetAck(g_osmux_enabled))) {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200883 log("BSSMAP: Received RESET-ACK in response to RESET, we're ready to go!");
Harald Weltea4ca4462018-02-09 00:17:14 +0100884 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200885 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200886 log("BSSMAP: Respoding to inbound RESET with RESET-ACK");
Harald Weltea4ca4462018-02-09 00:17:14 +0100887 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200888 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200889 reset_received := true;
Harald Weltea4ca4462018-02-09 00:17:14 +0100890 repeat;
891 }
892 [] BSSAP.receive { repeat; }
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200893 [] T.timeout {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200894 log("BSSMAP: Timeout waiting for RESET-ACK after sending RESET");
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200895 /* If we received a RESET after ours was sent, it
896 may be a race condition where the other peer beacame
897 available after we sent it, but we are in a desired
898 state anyway, so go forward. */
899 if (not reset_received) {
900 setverdict(fail);
901 }
902 }
Harald Weltea4ca4462018-02-09 00:17:14 +0100903 }
Harald Welte28d943e2017-11-25 15:00:50 +0100904}
905
Harald Welteae026692017-12-09 01:03:01 +0100906type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100907 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100908 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100909 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100910 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100911 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100912 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100913 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100914 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100915}
916
Harald Welte21b46bd2017-12-17 19:46:32 +0100917/*! Start the IPA/RSL related bits for one IPA_Client.
918 * \param clnt IPA_Client for which to establish
919 * \param bsc_host IP address / hostname of the BSC
920 * \param bsc_port TCP port number of the BSC
921 * \param i number identifying this BTS
922 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100923function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
924 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100925runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100926 timer T := 10.0;
927
Harald Welte96c94412017-12-09 03:12:45 +0100928 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welte71389132021-12-09 21:58:18 +0100929 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA") alive;
Harald Welteae026692017-12-09 01:03:01 +0100930 clnt.ccm_pars := c_IPA_default_ccm_pars;
931 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
932 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100933 if (handler_mode) {
Harald Welte71389132021-12-09 21:58:18 +0100934 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL") alive;
Harald Welte89ab1912018-02-23 18:56:29 +0100935 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100936 }
Harald Welteae026692017-12-09 01:03:01 +0100937
938 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100939 connect(clnt.vc_IPA:CFG_PORT, self:IPA_CFG_PORT);
Harald Welte624f9632017-12-16 19:26:04 +0100940 if (handler_mode) {
941 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
942 } else {
943 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
944 }
Harald Welteae026692017-12-09 01:03:01 +0100945
Harald Welte5d1a2202017-12-13 19:51:29 +0100946 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100947 if (handler_mode) {
948 clnt.vc_RSL.start(RSL_Emulation.main());
949 return;
950 }
Harald Welteae026692017-12-09 01:03:01 +0100951
952 /* wait for IPA RSL link to connect and send ID ACK */
953 T.start;
954 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700955 [] IPA_RSL[i].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) {
Harald Welteae026692017-12-09 01:03:01 +0100956 T.stop;
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +0700957 IPA_RSL[i].send(ts_ASP_RSL_UD(ts_RSL_PAGING_LOAD_IND(23)));
Harald Welteae026692017-12-09 01:03:01 +0100958 }
Harald Welte60e823a2017-12-10 14:10:59 +0100959 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100960 [] IPA_RSL[i].receive { repeat }
961 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100962 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200963 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100964 }
965 }
966}
967
Harald Welte12055472018-03-17 20:10:08 +0100968function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100969 var IPL4asp_Types.Result res := {
970 errorCode := omit,
971 connId := omit,
972 os_error_code := omit,
973 os_error_text := omit
974 };
975
Harald Welte12055472018-03-17 20:10:08 +0100976 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
977 return;
978 }
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100979
980 /* Alive components don't finish sockets (TCP FIN) when they are
981 * stopped. Hence, we need to manually call close() on them to make sure
982 * the IUT knows about it. */
983 f_ipa_cfg_disconnect(IPA_CFG_PORT, res);
984
Harald Welte12055472018-03-17 20:10:08 +0100985 clnt.vc_IPA.stop;
986 if (isbound(clnt.vc_RSL)) {
987 clnt.vc_RSL.stop;
988 }
989}
990
Harald Welte21b46bd2017-12-17 19:46:32 +0100991/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100992function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
993 timer T := secs_max;
994 T.start;
995 while (true) {
996 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
997 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100998 /* the 'degraded' state exists from OML connection time, and we have to wait
999 * until all MO's are initialized */
1000 T.start(1.0);
1001 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001002 return;
1003 }
Harald Weltef0d6ac62017-12-17 17:02:21 +01001004 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +01001005 if (not T.running) {
Max99253902018-11-16 17:57:39 +01001006 setverdict(fail, "Timeout waiting for BTS" & int2str(bts_nr) & " oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +02001007 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001008 }
1009 }
1010}
1011
Harald Welte21b46bd2017-12-17 19:46:32 +01001012/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +01001013altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +01001014 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +01001015 [] T_guard.timeout {
1016 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +02001017 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +01001018 }
Harald Welte60e823a2017-12-10 14:10:59 +01001019 /* always respond with RESET ACK to RESET */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001020 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Welte60e823a2017-12-10 14:10:59 +01001021 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001022 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Welte69c1c262017-12-13 21:02:08 +01001023 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +01001024 }
Harald Welte28d943e2017-11-25 15:00:50 +01001025}
1026
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001027altstep no_bssmap_reset() runs on test_CT {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001028 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001029 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +02001030 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001031 }
1032}
1033
Daniel Willmann191e0d92018-01-17 12:44:35 +01001034function f_init_mgcp(charstring id) runs on test_CT {
1035 id := id & "-MGCP";
1036
1037 var MGCPOps ops := {
1038 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
1039 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
1040 };
1041 var MGCP_conn_parameters mgcp_pars := {
1042 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +01001043 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +01001044 mgw_ip := mp_test_ip,
Pau Espin Pedrol1a026a52019-06-18 17:21:52 +02001045 mgw_udp_port := 2427,
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02001046 /* Enable it for SCCPlite, since we have 2 MGCP sockets towards MGW (UDP one +
1047 the on with MGCP over IPA forwarded from MSC one) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001048 multi_conn_mode := (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER)
Daniel Willmann191e0d92018-01-17 12:44:35 +01001049 };
1050
Harald Welte71389132021-12-09 21:58:18 +01001051 vc_MGCP := MGCP_Emulation_CT.create(id) alive;
Daniel Willmann191e0d92018-01-17 12:44:35 +01001052 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
1053}
1054
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001055/* Enable or disable (current default) Osmux. When enabling, BSSMAP Reset
1056 * contains extra IE (OsmuxSupport) and osmo-bsc will handle AssignReq with
1057 * OsmuxCID IE.
1058 */
1059private function f_vty_allow_osmux(boolean allow) runs on test_CT {
1060 f_vty_enter_cfg_msc(BSCVTY, 0);
1061 if (allow) {
1062 f_vty_transceive(BSCVTY, "osmux on");
1063 } else {
1064 f_vty_transceive(BSCVTY, "osmux off");
1065 }
1066 f_vty_transceive(BSCVTY, "exit");
1067 f_vty_transceive(BSCVTY, "exit");
1068 g_osmux_enabled := allow;
1069}
1070
Max2253c0b2018-11-06 19:28:05 +01001071function f_init_vty(charstring id := "foo") runs on test_CT {
Harald Welte94e0c342018-04-07 11:33:23 +02001072 if (BSCVTY.checkstate("Mapped")) {
1073 /* skip initialization if already executed once */
1074 return;
1075 }
Harald Weltebc03c762018-02-12 18:09:38 +01001076 map(self:BSCVTY, system:BSCVTY);
1077 f_vty_set_prompts(BSCVTY);
1078 f_vty_transceive(BSCVTY, "enable");
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01001079 f_cs7_inst_0_cfg(BSCVTY, {"sccp-timer ias " & int2str(g_bsc_sccp_timer_ias),
1080 "sccp-timer iar " & int2str(g_bsc_sccp_timer_iar)});
Harald Weltebc03c762018-02-12 18:09:38 +01001081}
1082
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +02001083friend function f_logp(TELNETasp_PT pt, charstring log_msg)
Neels Hofmeyr4f118412020-06-04 15:25:10 +02001084{
1085 // log on TTCN3 log output
1086 log(log_msg);
1087 // log in stderr log
Neels Hofmeyr8bdafe52021-12-14 17:25:48 +01001088 if (pt.checkstate("Mapped")) {
1089 f_vty_transceive(pt, "logp lglobal notice TTCN3 f_logp(): " & log_msg);
1090 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02001091}
1092
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001093private function f_sysinfo_seen(integer rsl_idx, RSL_Message rsl) runs on test_CT
1094{
1095 if (rsl_idx >= lengthof(g_system_information)) {
1096 g_system_information[rsl_idx] := SystemInformationConfig_omit
1097 }
1098 f_sysinfo_dec_raw(g_system_information[rsl_idx], rsl);
1099}
1100
1101altstep as_catch_RSL_sysinfo(integer rsl_idx) runs on test_CT {
1102 var ASP_RSL_Unitdata rx_rsl_ud;
1103
1104 /* For handler_mode := false, receiving the RSL bootstrap messages directly on IPA_RSL */
1105 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
1106 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1107 repeat;
1108 }
1109 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
1110 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1111 repeat;
1112 }
1113 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> value rx_rsl_ud {
1114 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1115 repeat;
1116 }
1117 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_SACCH_FILL)) -> value rx_rsl_ud {
1118 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1119 repeat;
1120 }
1121
1122 /* For handler_mode := true, receiving the RSL bootstrap messages via RSL_Emulation */
1123 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
1124 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1125 repeat;
1126 }
1127 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
1128 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1129 repeat;
1130 }
1131 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> value rx_rsl_ud {
1132 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1133 repeat;
1134 }
1135 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_SACCH_FILL)) -> value rx_rsl_ud {
1136 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1137 repeat;
1138 }
1139}
1140
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001141/* TODO: use BooleanList from COMMON/src/General_Types.ttcn */
1142private type record of boolean my_BooleanList;
1143
1144private function f_vty_msc_allow_attach(TELNETasp_PT pt, my_BooleanList allow_attach_list)
1145{
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001146 var charstring config := f_vty_transceive_ret(pt, "show running-config");
1147
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001148 for (var integer msc_nr := 0; msc_nr < sizeof(allow_attach_list); msc_nr := msc_nr+1) {
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001149 if (f_strstr(config, "\nmsc " & int2str(msc_nr) & "\n") < 0) {
1150 /* There is no 'msc N' for this msc_nr in the running config, so don't create an empty msc by
1151 * stepping into that config node. */
1152 log("msc ", msc_nr, " is not configured, skipping");
1153 continue;
1154 }
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001155 f_vty_enter_cfg_msc(pt, msc_nr);
1156 if (allow_attach_list[msc_nr]) {
1157 /* strict := false: ignore if osmo-bsc does not support this config option (latest build) */
1158 f_vty_transceive(pt, "allow-attach", strict := false);
1159 } else {
1160 f_vty_transceive(pt, "no allow-attach", strict := false);
1161 }
1162 f_vty_transceive(pt, "exit");
1163 f_vty_transceive(pt, "exit");
1164 }
1165}
1166
Harald Welte21b46bd2017-12-17 19:46:32 +01001167/* global initialization function
1168 * \param nr_bts Number of BTSs we should start/bring up
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001169 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false).
1170 * \param nr_msc Number of virtual MSCs to bring up to connect to osmo-bsc.
1171 */
1172function f_init(integer nr_bts := NUM_BTS, boolean handler_mode := false, boolean allow_osmux := false,
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001173 integer nr_msc := 1, float guard_timeout := 30.0) runs on test_CT {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001174 var integer bssap_idx;
Harald Welte28d943e2017-11-25 15:00:50 +01001175
Harald Welteae026692017-12-09 01:03:01 +01001176 if (g_initialized) {
1177 return;
Harald Welte28d943e2017-11-25 15:00:50 +01001178 }
Harald Welteae026692017-12-09 01:03:01 +01001179 g_initialized := true;
1180
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001181 T_guard.start(guard_timeout);
Daniel Willmanne68f9272018-11-27 15:15:28 +01001182 activate(as_Tguard());
1183
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001184 f_init_vty("VirtMSC");
Pau Espin Pedrol23510fb2021-07-20 17:00:38 +02001185 f_vty_allow_osmux(allow_osmux);
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001186
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001187 var my_BooleanList allow_attach := { false, false, false };
Daniel Willmannebdecc02020-08-12 15:30:17 +02001188 f_init_statsd("VirtMSC", vc_STATSD, mp_test_ip, mp_bsc_statsd_port);
1189
Neels Hofmeyr9db8e0e2021-08-23 20:45:58 +02001190 /* Make sure each MSC's internal state is "DISCONNECTED" at first */
1191 for (bssap_idx := 0; bssap_idx < NUM_MSC; bssap_idx := bssap_idx+1) {
1192 f_vty_transceive(BSCVTY, "msc " & int2str(bssap_idx) & " bssmap reset", strict := false);
1193 }
1194
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001195 for (bssap_idx := 0; bssap_idx < nr_msc; bssap_idx := bssap_idx+1) {
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001196 allow_attach[bssap_idx] := true;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001197 /* Call a function of our 'parent component' RAN_Adapter_CT to start the
1198 * MSC-side BSSAP emulation */
1199 if (handler_mode) {
1200 var RanOps ranops := MSC_RanOps;
1201 ranops.use_osmux := g_osmux_enabled;
1202 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", ranops);
1203 connect(self:SCCPLITE_IPA_CTRL, g_bssap[bssap_idx].vc_RAN:CTRL_CLIENT);
1204 f_ran_adapter_start(g_bssap[bssap_idx]);
1205 } else {
1206 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", omit);
1207 connect(self:BSSAP, g_bssap[bssap_idx].vc_SCCP:SCCP_SP_PORT);
1208 f_ran_adapter_start(g_bssap[bssap_idx]);
1209 f_legacy_bssap_reset();
1210 }
Harald Welte67089ee2018-01-17 22:19:03 +01001211 }
Harald Welted5833a82018-05-27 16:52:56 +02001212
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02001213 if (mp_enable_lcs_tests) {
1214 if (handler_mode) {
1215 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", SMLC_BssapLeOps);
1216 } else {
1217 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", omit);
1218 connect(self:BSSAP_LE, g_bssap_le.vc_SCCP:SCCP_SP_PORT);
1219 }
1220 f_bssap_le_adapter_start(g_bssap_le);
Harald Welte47cd0e32020-08-21 12:39:11 +02001221 }
Harald Welte47cd0e32020-08-21 12:39:11 +02001222
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001223 /* start the test with exactly all enabled MSCs allowed to attach */
1224 f_vty_msc_allow_attach(BSCVTY, allow_attach);
1225
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01001226 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +01001227
Daniel Willmann191e0d92018-01-17 12:44:35 +01001228 f_init_mgcp("VirtMSC");
1229
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001230 for (var integer i := 0; i < nr_bts; i := i+1) {
1231 f_init_bts(i, handler_mode);
Harald Welte696ddb62017-12-08 14:01:43 +01001232 }
Neels Hofmeyr9c0f9c82022-01-23 01:20:28 +01001233
1234 /* Emit a marker to appear in the SUT's own logging output */
1235 f_logp(BSCVTY, testcasename() & "() start");
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001236}
Harald Welte696ddb62017-12-08 14:01:43 +01001237
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001238function f_init_bts(integer bts_idx := 0, boolean handler_mode := false)
1239runs on test_CT {
1240 /* wait until osmo-bts-omldummy has respawned */
1241 f_wait_oml(bts_idx, "degraded", 5.0);
1242
1243 /* start RSL connection */
1244 f_ipa_rsl_start(bts[bts_idx].rsl, mp_bsc_ip, mp_bsc_rsl_port, bts_idx, handler_mode);
1245 /* wait until BSC tells us "connected" */
1246 f_wait_oml(bts_idx, "connected", 5.0);
Harald Welte28d943e2017-11-25 15:00:50 +01001247}
1248
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001249function f_init_bts_and_check_sysinfo(integer bts_idx := 0, boolean handler_mode := false,
1250 template SystemInformationConfig expect_si)
1251runs on test_CT {
1252 var default sysinfo := activate(as_catch_RSL_sysinfo(bts_idx));
1253
1254 f_init_bts(bts_idx, handler_mode);
1255
1256 /* Give some time to (hopefully/most likely) collect all system informations from RSL startup.
1257 * We could stop as soon as all expected SI are received, but then we might miss SI that we don't expect and
1258 * that might be sent afterwards. So rather give a generous timeout and be quite sure to catch all SI.
1259 */
1260 f_sleep(5.0);
1261 log("RSL ", bts_idx, " SYSTEM INFORMATION: ", g_system_information[bts_idx]);
1262
1263 deactivate(sysinfo);
1264
1265 if (match(g_system_information[bts_idx], expect_si)) {
1266 setverdict(pass);
1267 } else {
1268 log("RSL ", bts_idx, ": EXPECTED SI: ", expect_si);
1269 log("RSL ", bts_idx, ": GOT SI: ", g_system_information[bts_idx]);
1270 setverdict(fail, "received SI does not match expectations");
1271 return;
1272 }
1273}
1274
Maxd4e56962018-10-31 19:08:25 +01001275/* expect to receive a RSL message matching a specified template on a given BTS / stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001276function 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 +01001277runs on test_CT return RSL_Message {
1278 var ASP_RSL_Unitdata rx_rsl_ud;
1279 timer T := t_secs;
1280
1281 T.start;
1282 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001283 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
Harald Welteae026692017-12-09 01:03:01 +01001284 T.stop;
1285 }
1286 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +01001287 [] T.timeout {
1288 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +02001289 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +01001290 }
Harald Welteae026692017-12-09 01:03:01 +01001291 }
1292 return rx_rsl_ud.rsl;
1293}
1294
Harald Welte21b46bd2017-12-17 19:46:32 +01001295/* helper function to transmit RSL on a given BTS/stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001296function 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 +01001297runs on test_CT {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001298 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(t_tx, sid));
Harald Welteae026692017-12-09 01:03:01 +01001299}
1300
1301
Harald Welte4003d112017-12-09 22:35:39 +01001302/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +01001303testcase TC_chan_act_noreply() runs on test_CT {
1304 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +01001305 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +01001306
Harald Welte89d42e82017-12-17 16:42:41 +01001307 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +01001308
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001309 IPA_RSL[0].send(ts_ASP_RSL_UD(ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +01001310 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001311 f_shutdown_helper();
Harald Welte28d943e2017-11-25 15:00:50 +01001312}
1313
Neels Hofmeyr734b1a32021-11-29 16:00:17 +01001314const CounterNameVals counternames_bts_chreq := {
1315 { "chreq:total", 0 },
1316 { "chreq:attempted_emerg", 0 },
1317 { "chreq:attempted_call", 0 },
1318 { "chreq:attempted_location_upd", 0 },
1319 { "chreq:attempted_pag", 0 },
1320 { "chreq:attempted_pdch", 0 },
1321 { "chreq:attempted_other", 0 },
1322 { "chreq:attempted_unknown", 0 },
1323 { "chreq:successful", 0 },
1324 { "chreq:successful_emerg", 0 },
1325 { "chreq:successful_call", 0 },
1326 { "chreq:successful_location_upd", 0 },
1327 { "chreq:successful_pag", 0 },
1328 { "chreq:successful_pdch", 0 },
1329 { "chreq:successful_other", 0 },
1330 { "chreq:successful_unknown", 0 },
1331 { "chreq:no_channel", 0 },
1332 { "chreq:max_delay_exceeded", 0 }
1333};
1334
1335/* verify the "chreq:*" counters */
1336private function f_chan_act_counter(OCT1 ra, charstring chreq_ctr_suffix) runs on test_CT
1337{
1338 var GsmFrameNumber fn := 23;
1339
1340 f_logp(BSCVTY, "f_chan_act_counter(" & chreq_ctr_suffix & ")");
1341
1342 var RSL_Message rx_rsl;
1343 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1344 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1345 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1346
1347 f_ctrs_bts_add(0, "chreq:total");
1348 f_ctrs_bts_add(0, "chreq:attempted_" & chreq_ctr_suffix);
1349 f_ctrs_bts_verify();
1350
1351 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
1352 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
1353
1354 f_ctrs_bts_add(0, "chreq:successful");
1355 f_ctrs_bts_add(0, "chreq:successful_" & chreq_ctr_suffix);
1356 f_ctrs_bts_verify();
1357
1358 /* test is done, release RSL Conn Fail Ind to clean up */
1359 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1360 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1361 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
1362 f_sleep(1.0);
1363}
1364
Harald Welte4003d112017-12-09 22:35:39 +01001365testcase TC_chan_act_counter() runs on test_CT {
1366 var BSSAP_N_UNITDATA_ind ud_ind;
1367 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +01001368 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +01001369
Harald Welte89d42e82017-12-17 16:42:41 +01001370 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001371
Neels Hofmeyr734b1a32021-11-29 16:00:17 +01001372 f_vty_allow_emerg_bts(true, 0);
1373
1374 f_ctrs_bts_init(1, counternames_bts_chreq);
1375
1376 /* emergency call: RA & 0xe0 == 0xa0 --> CHREQ_T_EMERG_CALL */
1377 f_chan_act_counter('a3'O, "emerg");
1378
1379 /* voice TCH/H: RA & 0xf0 == 0x40 --> CHREQ_T_VOICE_CALL_TCH_H */
1380 f_chan_act_counter('43'O, "call");
1381
1382 /* LU: RA & 0xf0 == 0x00 --> CHREQ_T_LOCATION_UPD */
1383 f_chan_act_counter('03'O, "location_upd");
1384
1385 /* Paging: RA & 0xf0 == 0x20 --> CHREQ_T_PAG_R_TCH_F */
1386 f_chan_act_counter('23'O, "pag");
1387 /* Paging: RA & 0xf0 == 0x30 --> CHREQ_T_PAG_R_TCH_FH */
1388 f_chan_act_counter('33'O, "pag");
1389
1390 /* LU: RA & 0xfc == 0x78 --> CHREQ_T_PDCH_TWO_PHASE */
1391 /* no PCU, so PDCH not allowed. Skip this test for now. */
1392 /* f_chan_act_counter('7b'O, "pdch"); */
1393
1394 /* LU: RA & 0xf0 == 0x10 --> CHREQ_T_SDCCH */
1395 f_chan_act_counter('13'O, "other");
Harald Welte4003d112017-12-09 22:35:39 +01001396
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001397 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001398}
1399
Harald Welteae026692017-12-09 01:03:01 +01001400/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
Philipp Maier9c60a622020-07-09 15:08:46 +02001401private function f_TC_chan_act_ack_noest(OCT1 ra := '23'O) runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +01001402 var RSL_Message rx_rsl;
1403
Harald Welteae026692017-12-09 01:03:01 +01001404 /* Send CHAN RQD and wait for allocation; acknowledge it */
Philipp Maier9c60a622020-07-09 15:08:46 +02001405 var RslChannelNr chan_nr := f_chreq_act_ack(ra);
Harald Welteae026692017-12-09 01:03:01 +01001406
1407 /* expect BSC to disable the channel again if there's no RLL EST IND */
1408 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1409
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001410 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001411}
1412
Philipp Maier9c60a622020-07-09 15:08:46 +02001413/* Normal variant */
1414testcase TC_chan_act_ack_noest() runs on test_CT {
Philipp Maieraf58db22020-08-12 17:24:40 +02001415 f_init(1);
Philipp Maier9c60a622020-07-09 15:08:46 +02001416 f_TC_chan_act_ack_noest();
1417}
1418
1419/* Emergency call variant */
1420testcase TC_chan_act_ack_noest_emerg() runs on test_CT {
1421 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
Philipp Maieraf58db22020-08-12 17:24:40 +02001422 f_init(1);
1423 f_vty_allow_emerg_bts(true, 0);
Philipp Maier9c60a622020-07-09 15:08:46 +02001424 f_TC_chan_act_ack_noest(ra := 'A5'O);
1425}
1426
Philipp Maier606f07d2020-08-12 17:21:58 +02001427/* Emergency call variant, but emergency calls are not allowed */
1428testcase TC_chan_rqd_emerg_deny() runs on test_CT {
1429 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
1430
1431 var RSL_Message rx_rsl;
1432 var GsmRrMessage rr;
1433
1434 f_init(1);
1435 f_vty_allow_emerg_bts(false, 0);
1436
1437 IPA_RSL[0].clear;
1438 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
1439
1440 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
1441 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
1442 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1443 setverdict(pass);
1444 } else {
1445 setverdict(fail, "immediate assignment not rejected");
1446 }
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01001447
1448 f_shutdown_helper();
Philipp Maier606f07d2020-08-12 17:21:58 +02001449}
1450
Harald Welteae026692017-12-09 01:03:01 +01001451/* Test behavior if MSC never answers to CR */
1452testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +01001453 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
1454 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +01001455 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +01001456 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +01001457
Harald Welte89d42e82017-12-17 16:42:41 +01001458 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001459
1460 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001461 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001462
1463 var octetstring l3 := '00010203040506'O
1464 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1465
1466 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
1467
1468 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +01001469 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001470 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001471 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001472}
1473
1474/* Test behavior if MSC answers with CREF to CR */
1475testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
1476 var BSSAP_N_CONNECT_ind rx_c_ind;
1477 var RSL_Message rx_rsl;
1478
Harald Welte89d42e82017-12-17 16:42:41 +01001479 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001480
1481 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001482 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001483
1484 var octetstring l3 := '00010203040506'O
1485 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1486
1487 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1488 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
1489
1490 /* expect BSC to disable the channel */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001491 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001492 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001493}
1494
Harald Welte618ef642017-12-14 14:58:20 +01001495/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
1496testcase TC_chan_act_nack() runs on test_CT {
1497 var RSL_Message rx_rsl;
1498 var integer chact_nack;
1499
Harald Welte89d42e82017-12-17 16:42:41 +01001500 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +01001501
1502 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
1503
1504 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
1505 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1506 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1507
1508 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
1509
1510 /* wait for some time to hope the NACK arrives before the CTRL GET below */
1511 f_sleep(0.5);
1512
1513 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
1514
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001515 f_shutdown_helper();
Harald Welte618ef642017-12-14 14:58:20 +01001516}
1517
Harald Welte799c97b2017-12-14 17:50:30 +01001518/* Test for channel exhaustion due to RACH overload */
1519testcase TC_chan_exhaustion() runs on test_CT {
1520 var ASP_RSL_Unitdata rsl_ud;
1521 var integer i;
1522 var integer chreq_total, chreq_nochan;
1523
Harald Welte89d42e82017-12-17 16:42:41 +01001524 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +01001525
1526 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
1527 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
1528
Neels Hofmeyr85fa37f2021-10-06 13:50:38 +02001529 /* GSM 44.018 Table 9.1.8.2:
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +01001530 * RA = '33'O -> Establishment cause = 0011xxxx (MS dual rate capable and asks for "TCH/H or TCH/F").
1531 * With current setup, expect 4xSDCCH + 4xTCH/F + 1xTCH/H to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +02001532 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 +01001533 var RslChannelNr chan_nr := f_chreq_act_ack('33'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +01001534 }
1535
1536 IPA_RSL[0].clear;
1537
Harald Weltedd8cbf32018-01-28 12:07:52 +01001538 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001539 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +01001540
1541 /* now expect additional channel activations to fail */
1542 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
1543
1544 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001545 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
Harald Welte799c97b2017-12-14 17:50:30 +01001546 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
1547 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001548 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
Harald Welte799c97b2017-12-14 17:50:30 +01001549 var GsmRrMessage rr;
1550 /* match on IMM ASS REJ */
1551 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
1552 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1553 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001554 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +01001555 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
1556 chreq_nochan+1);
1557 setverdict(pass);
1558 } else {
1559 repeat;
1560 }
1561 }
1562 [] IPA_RSL[0].receive { repeat; }
1563 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001564 f_shutdown_helper();
Harald Welte799c97b2017-12-14 17:50:30 +01001565}
1566
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001567/* Test channel deactivation due to silence from MS */
1568testcase TC_chan_deact_silence() runs on test_CT {
1569 var RslChannelNr chan_nr;
1570
1571 f_init(1);
1572
1573 /* Request for a dedicated channel */
1574 chan_nr := f_chreq_act_ack('23'O);
1575
1576 /* Wait some time until the channel is released */
1577 f_sleep(2.0);
1578
1579 /* Expect CHANnel RELease */
1580 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001581 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001582 log("Received CHANnel RELease");
1583 setverdict(pass);
1584 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001585 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001586 /* See OS#3709, OsmoBSC should not send Immediate
1587 * Assignment Reject since a dedicated channel was
1588 * already allocated, and Immediate Assignment was
1589 * already sent. */
1590 setverdict(fail, "Unexpected Immediate Assignment!");
1591 }
1592 [] IPA_RSL[0].receive {
1593 setverdict(fail, "Unexpected RSL message!");
1594 }
1595 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001596 f_shutdown_helper();
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001597}
1598
Harald Weltecfe2c962017-12-15 12:09:32 +01001599/***********************************************************************
1600 * Assignment Testing
1601 ***********************************************************************/
1602
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001603/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction,
1604 * except for the inter-BSC handover, MT side) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001605testcase TC_outbound_connect(integer bssap_idx := 0) runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +01001606 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +01001607
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001608 BSSAP.send(ts_BSSAP_CONNECT_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
1609 2342, ts_BSSMAP_AssignmentReq));
Harald Weltecfe2c962017-12-15 12:09:32 +01001610 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001611 f_shutdown_helper();
Harald Weltecfe2c962017-12-15 12:09:32 +01001612}
1613
Harald Welte16a4adf2017-12-14 18:54:01 +01001614/* Test behavior if MSC answers with CREF to CR */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001615testcase TC_assignment_cic_only(integer bssap_idx := 0) runs on test_CT {
Harald Welte16a4adf2017-12-14 18:54:01 +01001616 var BSSAP_N_CONNECT_ind rx_c_ind;
1617 var RSL_Message rx_rsl;
1618 var DchanTuple dt;
1619
Harald Welte89d42e82017-12-17 16:42:41 +01001620 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +01001621
1622 dt := f_est_dchan('23'O, 23, '00000000'O);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001623 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte17b27da2018-05-25 20:33:53 +02001624 /* send assignment without AoIP IEs */
1625 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
1626 } else {
1627 /* Send assignmetn without CIC in IPA case */
1628 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
1629 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
1630 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
1631 }
Harald Welte16a4adf2017-12-14 18:54:01 +01001632 alt {
1633 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1634 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
1635 }
Harald Welte235ebf12017-12-15 14:18:16 +01001636 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +01001637 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1638 setverdict(pass);
1639 }
1640 [] BSSAP.receive { repeat; }
1641 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001642 f_perform_clear_test_ct(dt);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001643 f_shutdown_helper();
Harald Welte16a4adf2017-12-14 18:54:01 +01001644}
1645
Harald Welteed848512018-05-24 22:27:58 +02001646/* generate an assignment request for either AoIP or SCCPlite */
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001647function 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 +02001648 var PDU_BSSAP ass_cmd;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001649 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001650 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welteed848512018-05-24 22:27:58 +02001651 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001652 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001653 if (osmux_enabled) {
1654 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla, osmux_cid));
1655 } else {
1656 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
1657 }
Harald Welteed848512018-05-24 22:27:58 +02001658 } else {
1659 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001660 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
Harald Welteed848512018-05-24 22:27:58 +02001661 }
1662 return ass_cmd;
1663}
1664
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02001665function f_gen_handover_req(integer bssap_idx := 0, charstring aoip_tla := "1.2.3.4",
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001666 template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit,
1667 template (omit) TestHdlrEncrParams enc := omit) return PDU_BSSAP {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001668 var PDU_BSSAP ho_req;
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001669
1670 var BSSMAP_IE_EncryptionInformation encryptionInformation :=
1671 valueof(ts_BSSMAP_IE_EncrInfo('0000000000000000'O,'01'O));
1672 var template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm := omit;
1673 var template BSSMAP_IE_KC128 kc128 := omit;
1674 if (ispresent(enc)) {
1675 var TestHdlrEncrParams v_enc := valueof(enc);
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01001676 encryptionInformation := valueof(ts_BSSMAP_IE_EncrInfo(v_enc.enc_key, v_enc.enc_alg_permitted));
1677 if (ispresent(v_enc.enc_alg_chosen)) {
1678 chosenEncryptionAlgorithm := valueof(
1679 ts_BSSMAP_IE_ChosenEncryptionAlgorithm(int2oct(enum2int(
1680 f_cipher_mode_bssmap_to_rsl(v_enc.enc_alg_chosen)), 1)));
1681 }
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001682 if (ispresent(v_enc.enc_kc128)) {
1683 kc128 := ts_BSSMAP_IE_Kc128(v_enc.enc_kc128);
1684 }
1685 }
1686
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001687 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001688 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001689 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001690 ho_req := valueof(ts_BSSMAP_HandoverRequest(omit, tla, oldToNewBSSIEs := oldToNewBSSIEs,
1691 encryptionInformation := encryptionInformation,
1692 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
1693 kC128 := kc128));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001694 } else {
1695 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001696 ho_req := valueof(ts_BSSMAP_HandoverRequest(cic, omit, oldToNewBSSIEs := oldToNewBSSIEs,
1697 encryptionInformation := encryptionInformation,
1698 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
1699 kC128 := kc128));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001700 }
1701 return ho_req;
1702}
1703
Harald Welteed848512018-05-24 22:27:58 +02001704/* generate an assignment complete template for either AoIP or SCCPlite */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001705function f_gen_exp_compl(boolean expect_osmux := false, integer bssap_idx := 0) return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +02001706 var template PDU_BSSAP exp_compl;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001707 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001708 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001709 if (expect_osmux) {
1710 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, osmux_cid);
1711 } else {
1712 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, omit);
1713 }
Harald Welteed848512018-05-24 22:27:58 +02001714 } else {
1715 /* CIC is optional "*" as the MSC allocated it */
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001716 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
Harald Welteed848512018-05-24 22:27:58 +02001717 }
1718 return exp_compl;
1719}
1720
Harald Welte235ebf12017-12-15 14:18:16 +01001721/* Run everything required up to sending a caller-specified assignment command and expect response */
1722function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001723runs on test_CT return DchanTuple {
Harald Welte235ebf12017-12-15 14:18:16 +01001724 var BSSAP_N_CONNECT_ind rx_c_ind;
1725 var RSL_Message rx_rsl;
1726 var DchanTuple dt;
1727
Harald Welte89d42e82017-12-17 16:42:41 +01001728 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +01001729
1730 dt := f_est_dchan('23'O, 23, '00000000'O);
1731 /* send assignment without AoIP IEs */
1732 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
1733 alt {
1734 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1735 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
1736 setverdict(pass);
1737 } else {
1738 setverdict(fail, fail_text);
1739 }
1740 }
1741 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1742 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
1743 setverdict(pass);
1744 } else {
1745 setverdict(fail, fail_text);
1746 }
1747 }
1748 [] BSSAP.receive { repeat; }
1749 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001750 return dt;
Harald Welte235ebf12017-12-15 14:18:16 +01001751}
1752testcase TC_assignment_csd() runs on test_CT {
1753 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001754 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001755 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1756 //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 +01001757 var DchanTuple dt := f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
1758 f_perform_clear_test_ct(dt);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001759 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001760}
1761
1762testcase TC_assignment_ctm() runs on test_CT {
1763 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001764 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001765 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
1766 //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 +01001767 var DchanTuple dt := f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
1768 f_perform_clear_test_ct(dt);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001769 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001770}
1771
Harald Welte4003d112017-12-09 22:35:39 +01001772type record DchanTuple {
1773 integer sccp_conn_id,
1774 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +01001775}
1776
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +02001777type record of DchanTuple DchanTuples;
1778
Harald Welted6939652017-12-13 21:02:46 +01001779/* Send CHAN RQD and wait for allocation; acknowledge it */
1780private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
1781runs on test_CT return RslChannelNr {
1782 var RSL_Message rx_rsl;
1783 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1784 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1785 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1786 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
Daniel Willmannf4ac4ce2018-08-02 14:06:30 +02001787 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Harald Welted6939652017-12-13 21:02:46 +01001788 return chan_nr;
1789}
1790
Harald Welte4003d112017-12-09 22:35:39 +01001791/* helper function to establish a dedicated channel via BTS and MSC */
1792function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1793runs on test_CT return DchanTuple {
1794 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +01001795 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001796
Harald Welte4003d112017-12-09 22:35:39 +01001797 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001798 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +01001799
1800 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1801
1802 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1803 dt.sccp_conn_id := rx_c_ind.connectionId;
1804 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1805
1806 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001807}
1808
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02001809/* Like f_est_dchan(), but for the first lchan of a dynamic timeslot: first ACK the deactivation of PDCH. */
1810function f_est_dchan_dyn(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1811runs on test_CT return DchanTuple {
1812 var BSSAP_N_CONNECT_ind rx_c_ind;
1813 var DchanTuple dt;
1814
1815 /* Send CHAN RQD */
1816 var RSL_Message rx_rsl;
1817 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1818
1819 /* The dyn TS first deactivates PDCH */
1820 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1821 dt.rsl_chan_nr := rx_rsl.ies[0].body.chan_nr;
1822 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1823
1824 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1825 dt.rsl_chan_nr := rx_rsl.ies[0].body.chan_nr;
1826
1827 /* Now activates the signalling channel */
1828 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, fn+10));
1829 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
1830
1831 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1832
1833 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1834 dt.sccp_conn_id := rx_c_ind.connectionId;
1835 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1836
1837 return dt;
1838}
1839
Harald Welte641fcbe2018-06-14 10:58:35 +02001840/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
1841private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
1842 var RSL_Message rx_rsl;
1843 /* expect BSC to disable the channel */
1844 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1845 /* respond with CHAN REL ACK */
1846 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1847
1848 /* expect Clear Complete from BSC */
1849 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1850
1851 /* MSC disconnects as instructed. */
1852 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1853}
1854
Harald Welte4003d112017-12-09 22:35:39 +01001855/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
1856testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001857 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001858 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +01001859
Harald Welte89d42e82017-12-17 16:42:41 +01001860 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +01001861
Harald Welte4003d112017-12-09 22:35:39 +01001862 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1863
1864 /* simulate RLL REL IND */
1865 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
1866
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001867 /* expect Clear Request on MSC side */
1868 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1869
1870 /* Instruct BSC to clear channel */
1871 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1872 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1873
Harald Welte4003d112017-12-09 22:35:39 +01001874 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001875 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001876
1877 /* wait for SCCP emulation to do its job */
1878 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +01001879
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001880 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001881}
1882
1883/* Test behavior of channel release after CONN FAIL IND from BTS */
1884testcase TC_chan_rel_conn_fail() runs on test_CT {
1885 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001886 var DchanTuple dt;
1887
Harald Welte89d42e82017-12-17 16:42:41 +01001888 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001889
1890 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1891
1892 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +01001893 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 +01001894 /* TODO: different cause values? */
1895
Harald Welte4003d112017-12-09 22:35:39 +01001896 /* expect Clear Request from BSC */
1897 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1898
1899 /* Instruct BSC to clear channel */
1900 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1901 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1902
Harald Welte6ff76ea2018-01-28 13:08:01 +01001903 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001904 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +01001905
1906 /* wait for SCCP emulation to do its job */
1907 f_sleep(1.0);
1908
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001909 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001910}
1911
Harald Welte99f3ca02018-06-14 13:40:29 +02001912/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
1913/* See also https://www.osmocom.org/issues/3182 */
1914testcase TC_early_conn_fail() runs on test_CT {
1915 var RSL_Message rx_rsl;
1916 var DchanTuple dt;
1917
1918 f_init(1);
1919
1920 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
Harald Weltec46ea3c2020-10-10 18:46:12 +02001921 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_ra_cs(), 23);
Harald Welte99f3ca02018-06-14 13:40:29 +02001922
1923 /* BTS->BSC: simulate CONN FAIL IND */
1924 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1925
1926 /* BTS->BSC: Expect RF channel release from BSC on Abis */
1927 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1928
1929 /* BTS<-BSC: respond with CHAN REL ACK */
1930 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1931
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001932 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001933}
1934
1935/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
1936/* See also https://www.osmocom.org/issues/3182 */
1937testcase TC_late_conn_fail() runs on test_CT {
1938 var RSL_Message rx_rsl;
1939 var DchanTuple dt;
1940
1941 f_init(1);
1942
1943 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1944
1945 /* BSC<-MSC: Instruct BSC to clear connection */
1946 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
1947
1948 /* BTS->BSC: expect BSC to deactivate SACCH */
1949 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
1950
1951 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
1952 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1953
1954 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
1955 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1956 /* BTS->BSC: respond with CHAN REL ACK */
1957 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1958
1959 /* BSC->MSC: expect Clear Complete from BSC */
1960 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1961
1962 /* BSC<-MSC: MSC disconnects as requested. */
1963 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1964
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001965 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001966}
1967
Oliver Smithaf03bef2021-08-24 15:34:51 +02001968private function f_TC_stats_conn_fail(charstring id) runs on MSC_ConnHdlr {
1969 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
1970 var PDU_BSSAP ass_cmd := f_gen_ass_req();
1971
1972 f_statsd_reset();
1973
1974 /* Establish SDCCH */
1975 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1976 f_establish_fully(ass_cmd, exp_fail);
1977
1978 /* Expect stats to be 0 */
1979 var StatsDExpects expect := {
1980 {name := "TTCN3.bts.0.chan.rf_fail", mtype := "c", min := 0, max := 0},
1981 {name := "TTCN3.bts.0.chan.rf_fail_sdcch", mtype := "c", min := 0, max := 0}
1982 };
1983 f_statsd_expect(expect);
1984
1985 /* Simulate CONN FAIL IND on SDCCH */
1986 RSL.send(ts_ASP_RSL_UD(
1987 ts_RSL_CONN_FAIL_IND(g_chan_nr, RSL_ERR_RADIO_LINK_FAIL),
1988 IPAC_PROTO_RSL_TRX0));
1989
Neels Hofmeyr58be48a2021-09-07 18:39:21 +02001990 f_sleep(1.0);
1991
Oliver Smithaf03bef2021-08-24 15:34:51 +02001992 /* Expect stats to be 1 */
1993 expect := {
1994 {name := "TTCN3.bts.0.chan.rf_fail", mtype := "c", min := 1, max := 1},
1995 {name := "TTCN3.bts.0.chan.rf_fail_sdcch", mtype := "c", min := 1, max := 1}
1996 };
1997 f_statsd_expect(expect);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001998 BSSAP.receive(tr_BSSMAP_ClearRequest);
1999 f_perform_clear();
Oliver Smithaf03bef2021-08-24 15:34:51 +02002000}
2001testcase TC_stats_conn_fail() runs on test_CT {
2002 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2003 var MSC_ConnHdlr vc_conn;
2004
2005 f_init(1, true);
2006 f_sleep(1.0);
2007
2008 vc_conn := f_start_handler(refers(f_TC_stats_conn_fail), pars);
2009 vc_conn.done;
2010
2011 f_shutdown_helper();
2012}
2013
Neels Hofmeyrf44ccd12018-11-05 19:15:23 +01002014function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr,
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002015 boolean expect_deact_sacch := true,
2016 boolean expect_rr_chan_rel := true,
2017 boolean expect_rll_rel_req := true,
Harald Welte99787102019-02-04 10:41:36 +01002018 boolean handle_rll_rel := true,
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002019 template CellSelIndValue expect_cells := omit,
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002020 template RR_Cause expect_rr_cause := ?
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002021 ) runs on test_CT {
Harald Welte91d54a52018-01-28 15:35:07 +01002022
2023 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002024 var boolean got_deact_sacch := false;
2025 var boolean got_rr_chan_rel := false;
2026 var boolean got_rll_rel_req := false;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002027 var ASP_RSL_Unitdata ud;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002028 var RSL_IE_Body l3_ie;
2029 var PDU_ML3_NW_MS l3;
2030 var RR_Cause got_cause;
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002031 log("f_expect_chan_rel() expecting: expect_deact_sacch=", expect_deact_sacch, " expect_rr_chan_rel=", expect_rr_chan_rel,
2032 " expect_rll_rel_req=", expect_rll_rel_req);
Harald Welte91d54a52018-01-28 15:35:07 +01002033 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002034 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002035 got_deact_sacch := true;
Harald Welte91d54a52018-01-28 15:35:07 +01002036 repeat;
2037 }
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002038 [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 +01002039 got_rr_chan_rel := true;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002040
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002041 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
2042 setverdict(fail, "cannot find L3");
2043 mtc.stop;
2044 }
2045 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
2046
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002047 if (not istemplatekind(expect_cells, "omit")) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002048 var CellSelIndValue cells := dec_CellSelIndValue(
2049 l3.msgs.rrm.channelRelease.cellSelectionIndicator.cellSelectionIndicatorValue);
2050
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002051 log("GOT RR CHANNEL RELEASE WITH CELLS: ", cells);
2052 if (match(cells, expect_cells)) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002053 setverdict(pass);
2054 } else {
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002055 log("EXPECTED CELLS: ", expect_cells);
2056 setverdict(fail, "Received cells list on RR Channel Release does not match expectations");
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002057 }
2058 }
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002059
2060 if (not istemplatekind(expect_rr_cause, "omit")) {
2061 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
2062 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
2063 if (match(got_cause, expect_rr_cause)) {
2064 setverdict(pass);
2065 } else {
2066 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
2067 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
2068 }
2069 }
Harald Welte99787102019-02-04 10:41:36 +01002070 repeat;
2071 }
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002072 [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 +01002073 got_rr_chan_rel := true;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002074
2075 if (not istemplatekind(expect_rr_cause, "omit")) {
2076 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
2077 setverdict(fail, "cannot find L3");
2078 mtc.stop;
2079 }
2080 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
2081
2082 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
2083 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
2084 if (match(got_cause, expect_rr_cause)) {
2085 setverdict(pass);
2086 } else {
2087 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
2088 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
2089 }
2090 }
Neels Hofmeyr211169d2018-11-07 00:37:29 +01002091 repeat;
2092 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002093 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002094 got_rll_rel_req := true;
Harald Welte91d54a52018-01-28 15:35:07 +01002095 /* FIXME: Why are we getting this for LinkID SACCH? */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002096 if (handle_rll_rel) {
2097 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
2098 }
Harald Welte91d54a52018-01-28 15:35:07 +01002099 repeat;
2100 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002101 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Harald Welte91d54a52018-01-28 15:35:07 +01002102 /* respond with CHAN REL ACK */
2103 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
2104 }
2105 /* ignore any user data */
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002106 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeR(?))) {
Harald Welte91d54a52018-01-28 15:35:07 +01002107 repeat;
2108 }
2109 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002110
2111 log("f_expect_chan_rel() summary: got_deact_sacch=", got_deact_sacch, " got_rr_chan_rel=", got_rr_chan_rel,
2112 " got_rll_rel_req=", got_rll_rel_req);
2113
2114 if (expect_deact_sacch != got_deact_sacch) {
2115 setverdict(fail, "f_expect_chan_rel(): expect_deact_sacch=", expect_deact_sacch, " got_deact_sacch=", got_deact_sacch);
2116 }
2117 if (expect_rr_chan_rel != got_rr_chan_rel) {
2118 setverdict(fail, "f_expect_chan_rel(): expect_rr_chan_rel=", expect_rr_chan_rel, " got_rr_chan_rel=", got_rr_chan_rel);
2119 }
2120 if (expect_rll_rel_req != got_rll_rel_req) {
2121 setverdict(fail, "f_expect_chan_rel(): expect_rll_rel_req=", expect_rll_rel_req, " got_rll_rel_req=", got_rll_rel_req);
2122 }
Harald Welte91d54a52018-01-28 15:35:07 +01002123}
2124
Harald Welte4003d112017-12-09 22:35:39 +01002125/* Test behavior of channel release after hard Clear Command from MSC */
2126testcase TC_chan_rel_hard_clear() runs on test_CT {
2127 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01002128 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +01002129
Harald Welte89d42e82017-12-17 16:42:41 +01002130 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002131
2132 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2133
2134 /* Instruct BSC to clear channel */
2135 var BssmapCause cause := 0;
2136 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2137
2138 /* expect Clear Complete from BSC on A */
2139 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2140 /* release the SCCP connection */
2141 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2142 }
2143
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002144 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002145 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002146}
2147
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002148function f_TC_chan_rel_last_eutran_plmn_hard_clear(boolean tx_csfb_ind) runs on test_CT {
2149 var BSSAP_N_DATA_ind rx_di;
2150 var DchanTuple dt;
2151
2152 f_init(1);
2153
2154 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2155 /* Send CommonID with some random PLMN (BSC doesn't take it into account
2156 /* yet when generating the EUTRAN neigh list in RR CHannel Release) */
2157 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
2158
2159 /* Instruct BSC to clear channel */
2160 var BssmapCause cause := 0;
2161 if (tx_csfb_ind) {
2162 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2163 } else {
2164 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2165 }
2166
2167 /* expect Clear Complete from BSC on A */
2168 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2169 /* release the SCCP connection */
2170 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2171 }
2172
2173 /* 1 neighbor is added by default in osmo-bts.cfg and
2174 SystemInformationConfig_default, use that: */
2175 var template CellSelIndValue exp_cells := f_tr_rr_chan_rel_earfcns(1);
2176
2177 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, expect_cells := exp_cells);
2178 f_shutdown_helper();
2179}
2180
2181/* Test behavior of RR Channel rRelease after Clear Command without CSFB indicator
2182 from MSC, previously receiving any CommonID containing the "Last Used E-UTRAN
2183 PLMN Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
2184 EUTRAN neighbor list sent later on by BSC in RR Channel, so receiving CSFB
2185 Indicator or not shouldn't matter at all. */
2186testcase TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() runs on test_CT {
2187 f_TC_chan_rel_last_eutran_plmn_hard_clear(false);
2188}
2189
2190/* Test behavior of RR Channel rRelease after Clear Command with CSFB indicator from
2191 MSC, previously receiving any CommonID containing the "Last Used E-UTRAN PLMN
2192 Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
2193 EUTRAN neighbor list sent later on by BSC in RR Channel. */
2194testcase TC_chan_rel_last_eutran_plmn_hard_clear_csfb() runs on test_CT {
2195 f_TC_chan_rel_last_eutran_plmn_hard_clear(true);
2196}
2197
2198/* Test behavior of RR Channel Release after Clear Command with CSFB indicator from
2199 MSC, without receiving any CommonID containing the "Last Used E-UTRAN PLMN
2200 Id". According to spec (TS 48.008 version 16.0.0 Release 16 "3.2.1.21") the
2201 CSFB Indicator should not be used anymore, and hence, there should be no
2202 EUTRAN neighbor list sent by BSC in RR Channel release since no CommonId with
2203 Last Used E-UTRAN PLMN Id" IE was sent for this conn. */
Harald Welte99787102019-02-04 10:41:36 +01002204testcase TC_chan_rel_hard_clear_csfb() runs on test_CT {
2205 var BSSAP_N_DATA_ind rx_di;
2206 var DchanTuple dt;
2207
2208 f_init(1);
2209
2210 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2211
2212 /* Instruct BSC to clear channel */
2213 var BssmapCause cause := 0;
2214 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2215
2216 /* expect Clear Complete from BSC on A */
2217 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2218 /* release the SCCP connection */
2219 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2220 }
2221
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002222 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002223 f_shutdown_helper();
Harald Welte99787102019-02-04 10:41:36 +01002224}
2225
Harald Welted8c36cd2017-12-09 23:05:31 +01002226/* Test behavior of channel release after hard RLSD from MSC */
2227testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +01002228 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +01002229
Harald Welte89d42e82017-12-17 16:42:41 +01002230 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +01002231
2232 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2233
2234 /* release the SCCP connection */
2235 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2236
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002237 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002238 f_shutdown_helper();
Harald Welted8c36cd2017-12-09 23:05:31 +01002239}
2240
Harald Welte550daf92018-06-11 19:22:13 +02002241/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
2242testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
2243 var DchanTuple dt;
2244
2245 f_init(1);
2246
2247 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2248
2249 /* release the SCCP connection */
2250 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2251
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002252 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002253 f_shutdown_helper();
Harald Welte550daf92018-06-11 19:22:13 +02002254}
2255
Harald Welte85804d42017-12-10 14:11:58 +01002256/* Test behavior of channel release after BSSMAP RESET from MSC */
2257testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +01002258 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +01002259
Harald Welte89d42e82017-12-17 16:42:41 +01002260 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +01002261
2262 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2263
2264 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
2265 IPA_RSL[0].clear;
2266
2267 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002268 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 +01002269 interleave {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002270 [] 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 +01002271 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
2272 }
2273
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002274 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002275 f_shutdown_helper();
Harald Welte85804d42017-12-10 14:11:58 +01002276}
2277
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002278/* Verify T(iar) triggers and releases the channel */
2279testcase TC_chan_rel_sccp_tiar_timeout() runs on test_CT {
2280 var DchanTuple dt;
2281
2282 /* Set T(iar) in BSC low enough that it will trigger before other side
2283 has time to keep alive with a T(ias). Keep recommended ratio of
2284 T(iar) >= T(ias)*2 */
2285 g_bsc_sccp_timer_ias := 2;
2286 g_bsc_sccp_timer_iar := 5;
2287
2288 f_init(1);
2289
2290 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2291 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002292 f_shutdown_helper();
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002293}
2294
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002295private function f_tc_chan_rel_rr_cause(myBSSMAP_Cause clear_cmd_cause, template RR_Cause expect_rr_cause)
2296runs on test_CT
2297{
2298 var DchanTuple dt;
2299
2300 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2301 var BssmapCause cause := 0;
2302 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(enum2int(clear_cmd_cause))));
2303 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2304 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2305 }
2306
2307 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 +02002308}
2309
2310/* Test that Clear Command cause codes affect the RR Channel Release cause code */
2311testcase TC_chan_rel_rr_cause() runs on test_CT {
2312 f_init(1);
2313
2314 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_CALL_CONTROL, GSM48_RR_CAUSE_NORMAL);
2315 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_HANDOVER_SUCCESSFUL, GSM48_RR_CAUSE_NORMAL);
2316 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_PREEMPTION, GSM48_RR_CAUSE_PREMPTIVE_REL);
2317 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE, GSM48_RR_CAUSE_PROT_ERROR_UNSPC);
2318 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
2319 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_EQUIPMENT_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
Vadim Yanitskiye18aebb2021-01-03 13:10:43 +01002320
2321 f_shutdown_helper();
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002322}
2323
Harald Welte5cd20ed2017-12-13 21:03:20 +01002324/* Test behavior if RSL EST IND for non-active channel */
2325testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
2326 timer T := 2.0;
2327
Harald Welte89d42e82017-12-17 16:42:41 +01002328 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002329
2330 var octetstring l3 := '00010203040506'O;
2331 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2332 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
2333
2334 T.start;
2335 alt {
2336 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2337 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
2338 }
2339 [] BSSAP.receive {}
2340 [] IPA_RSL[0].receive {}
2341 [] T.timeout {}
2342 }
2343
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002344 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002345}
2346
2347/* Test behavior if RSL EST IND for invalid SAPI */
2348testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
2349 var RslChannelNr chan_nr;
2350
Harald Welte89d42e82017-12-17 16:42:41 +01002351 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002352
2353 chan_nr := f_chreq_act_ack()
2354
2355 var octetstring l3 := '00010203040506'O;
2356 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
2357
2358 timer T := 2.0;
2359 T.start;
2360 alt {
2361 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2362 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
2363 }
2364 [] BSSAP.receive { repeat; }
2365 [] IPA_RSL[0].receive { repeat; }
2366 [] T.timeout {}
2367 }
2368
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002369 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002370}
2371
2372/* Test behavior if RSL EST IND for invalid SAPI */
2373testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
2374 timer T := 2.0;
2375
Harald Welte89d42e82017-12-17 16:42:41 +01002376 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002377
2378 var RslChannelNr chan_nr := f_chreq_act_ack();
2379
2380 var octetstring l3 := '00010203040506'O;
2381 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
2382
2383 T.start;
2384 alt {
2385 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2386 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
2387 }
2388 [] BSSAP.receive { repeat; }
2389 [] IPA_RSL[0].receive { repeat; }
2390 [] T.timeout {}
2391 }
2392
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002393 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002394}
2395
2396/* Test behavior if RSL EST IND for invalid SACCH */
2397testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
2398 timer T := 2.0;
2399
Harald Welte89d42e82017-12-17 16:42:41 +01002400 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002401
2402 var RslChannelNr chan_nr := f_chreq_act_ack();
2403
2404 var octetstring l3 := '00010203040506'O;
2405 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
2406
2407 T.start;
2408 alt {
2409 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2410 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
2411 }
2412 [] BSSAP.receive { repeat; }
2413 [] IPA_RSL[0].receive { repeat; }
2414 [] T.timeout {}
2415 }
2416
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002417 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002418}
2419
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002420/* Verify DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
2421private function f_TC_tch_dlci_link_id_sapi(charstring id) runs on MSC_ConnHdlr {
2422 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2423 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2424
2425 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2426 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2427
2428 f_establish_fully(ass_cmd, exp_compl);
2429
2430 /* SAPI0 has already been established by f_establish_fully(), establish SAPI3 */
2431 RSL.send(ts_RSL_EST_IND(g_chan_nr, ts_RslLinkID_SACCH(3), '0904'O));
2432 /* Expect BSSAP/DTAP on SAPI3 (DLCI IE) */
2433 BSSAP.receive(PDU_BSSAP:{
2434 discriminator := '1'B,
2435 spare := '0000000'B,
2436 dlci := 'C3'O,
2437 lengthIndicator := ?,
2438 pdu := { dtap := '0904'O }
2439 });
2440
2441 /* Send messages on DCCH/SAPI0 and ACCH/SAPI3 */
2442 for (var integer i := 0; i < 32; i := i + 1) {
2443 var octetstring l3 := '09'O & f_rnd_octstring(14);
2444 var template (value) RslLinkId link_id;
2445 var template (value) OCT1 dlci;
2446
2447 if (i mod 2 == 0) {
2448 /* SAPI0 on FACCH or SDCCH */
2449 link_id := ts_RslLinkID_DCCH(0);
2450 dlci := '80'O;
2451 } else {
2452 /* SAPI3 on SACCH */
2453 link_id := ts_RslLinkID_SACCH(3);
2454 dlci := 'C3'O;
2455 }
2456
2457 /* Send MO message: RSL -> BSSAP */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002458 f_mo_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002459 /* Send MT message: BSSAP -> RSL */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002460 f_mt_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002461 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01002462 f_perform_clear();
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002463}
2464testcase TC_tch_dlci_link_id_sapi() runs on test_CT {
2465 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2466 var MSC_ConnHdlr vc_conn;
2467
2468 f_init(1, true);
2469 f_sleep(1.0);
2470
2471 vc_conn := f_start_handler(refers(f_TC_tch_dlci_link_id_sapi), pars);
2472 vc_conn.done;
2473
2474 f_shutdown_helper();
2475}
2476
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002477private function f_exp_sapi_n_reject(template (present) GsmSapi sapi := ?,
2478 template myBSSMAP_Cause cause := ?,
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002479 template (present) BIT2 cc := ?,
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002480 float T_val := 2.0)
2481runs on test_CT {
2482 var BSSAP_N_DATA_ind rx_di;
2483 timer T;
2484
2485 var template BSSMAP_IE_Cause tr_cause := tr_BSSMAP_IE_Cause(cause);
2486 var template PDU_BSSAP tr_pdu := tr_BSSMAP_SAPInReject(sapi);
2487
2488 T.start(T_val);
2489 alt {
2490 [] BSSAP.receive(tr_BSSAP_DATA_ind(?, tr_pdu)) -> value rx_di {
2491 var BSSMAP_IE_Cause rx_cause := rx_di.userData.pdu.bssmap.sAPInReject.cause;
2492 if (not match(rx_cause, tr_cause)) {
2493 setverdict(fail, "Rx unexpected Cause IE: ",
2494 rx_cause, " vs expected ", tr_cause);
2495 }
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002496
2497 /* Who ever on the earth decided to define this field as two separate bits?!? */
2498 var BIT2 rx_cc := rx_di.userData.pdu.bssmap.sAPInReject.dLCI.c2
2499 & rx_di.userData.pdu.bssmap.sAPInReject.dLCI.c1;
2500 if (not match(rx_cc, cc)) {
2501 setverdict(fail, "Rx unexpected Control Channel type: ",
2502 rx_cc, " vs expected ", cc);
2503 }
2504
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002505 setverdict(pass);
2506 }
2507 [] BSSAP.receive(BSSAP_N_DATA_ind:?) -> value rx_di {
2508 setverdict(fail, "Rx unexpected BSSAP PDU: ", rx_di);
2509 }
2510 [] T.timeout {
2511 setverdict(fail, "Timeout waiting for BSSMAP SAPI N Reject");
2512 }
2513 }
2514}
2515
2516/* Check if we get SAPI N Reject on receipt of unexpected RLL RELease INDication */
2517testcase TC_rll_rel_ind_sapi_n_reject() runs on test_CT {
2518 var octetstring rnd_data := f_rnd_octstring(16);
2519 var RSL_Message rx_rsl;
2520 var DchanTuple dt;
2521
2522 f_init(1);
2523
2524 /* MS establishes a SAPI=0 link on DCCH */
2525 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2526
2527 /* MSC sends some data on (not yet established) SAPI=3 link */
2528 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2529 /* BSC attempts to establish a SAPI=3 link on DCCH */
2530 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2531
2532 /* MS sends unexpected RELease INDication on SAPI=3 */
2533 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3)));
2534 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2535 f_exp_sapi_n_reject(3, GSM0808_CAUSE_MS_NOT_EQUIPPED);
2536
2537 /* Clean up the connection */
2538 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2539 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2540
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002541 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002542}
2543
2544/* Check if we get SAPI N Reject on receipt of unexpected RLL ERROR INDication */
2545testcase TC_rll_err_ind_sapi_n_reject() runs on test_CT {
2546 var octetstring rnd_data := f_rnd_octstring(16);
2547 var RSL_Message rx_rsl;
2548 var DchanTuple dt;
2549
2550 f_init(1);
2551
2552 /* MS establishes a SAPI=0 link on DCCH */
2553 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2554
2555 /* MSC sends some data on (not yet established) SAPI=3 link */
2556 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2557 /* BSC attempts to establish a SAPI=3 link on DCCH */
2558 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2559
2560 /* BTS sends unexpected ERROR INDication on SAPI=3 */
2561 f_ipa_tx(0, ts_RSL_ERROR_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3), ''O));
2562 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2563 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED);
2564
2565 /* Clean up the connection */
2566 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2567 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2568
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002569 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002570}
2571
2572/* Check if we get SAPI N Reject due to a SAPI=3 link establishment timeout */
2573testcase TC_rll_timeout_sapi_n_reject() runs on test_CT {
2574 var octetstring rnd_data := f_rnd_octstring(16);
2575 var RSL_Message rx_rsl;
2576 var DchanTuple dt;
2577
2578 f_init(1);
2579
2580 /* MS establishes a SAPI=0 link on DCCH */
2581 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2582
2583 /* MSC sends some data on (not yet established) SAPI=3 link */
2584 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2585 /* BSC attempts to establish a SAPI=3 link on DCCH */
2586 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2587
2588 /* MS does not respond, so the link establishment timeout triggers SAPI N Reject */
2589 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED, T_val := 8.0);
2590
2591 /* Clean up the connection */
2592 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2593 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2594
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002595 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002596}
2597
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002598/* Check DLCI CC (Control Channel type) bits in SAPI N Reject */
2599testcase TC_rll_sapi_n_reject_dlci_cc() runs on test_CT {
2600 var octetstring rnd_data := f_rnd_octstring(16);
2601 var RSL_Message rx_rsl;
2602 var DchanTuple dt;
2603
2604 f_init(1);
2605
2606 /* MS establishes a SAPI=0 link on DCCH */
2607 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2608
2609 /* MSC sends some data on (not yet established) SAPI=3 link */
2610 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2611 /* BSC attempts to establish a SAPI=3 link on DCCH */
2612 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2613
2614 /* MS sends unexpected ERROR INDication on DCCH/ACCH SAPI=3 */
2615 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 +01002616 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED, '10'B);
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002617
2618 /* Clean up the connection */
2619 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2620 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2621
2622 f_shutdown_helper();
2623}
2624
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002625testcase TC_si_default() runs on test_CT {
2626 f_init(0);
2627 f_init_bts_and_check_sysinfo(0, expect_si := SystemInformationConfig_default);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002628 f_shutdown_helper();
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002629}
Harald Welte4003d112017-12-09 22:35:39 +01002630
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002631/* We're testing SI2quater with lists of EARFCNs. Instead of just incrementing EARFCNs, also pick some from the edges of
2632 * the entire value range. This function provides the same EARFCN numbers for the same earfcn_index */
2633private function f_test_si2quater_earfcn_by_idx(integer earfcn_index) return uint16_t
2634{
2635 select (earfcn_index) {
2636 case (0) {
2637 /* E-ARFCN 111 is already added in the osmo-bsc.cfg */
2638 return 111;
2639 }
2640 case (1) {
2641 return 1;
2642 }
2643 case (2) {
2644 return 0;
2645 }
2646 case (3) {
2647 return 65535;
2648 }
2649 case else {
2650 return 23 * (earfcn_index - 3);
2651 }
2652 }
2653}
2654
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002655function f_test_si2quater(integer total_earfcns, template SystemInformationConfig expect_si,
2656 template CellSelIndValue expect_cells := omit) runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002657
2658 f_init(0);
2659
2660 /* E-ARFCN 111 is already added in the osmo-bsc.cfg, so only add more arfcns if total_earfcns > 1 */
2661 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002662 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2663 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002664 }
2665
2666 f_init_bts_and_check_sysinfo(0, expect_si := expect_si);
2667
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002668 if (not istemplatekind(expect_cells, "omit")) {
2669 /* Also check that RR Channel Release contains these EARFCNs.
2670 * (copied code from TC_chan_rel_hard_clear_csfb) */
2671 var BSSAP_N_DATA_ind rx_di;
2672 var DchanTuple dt;
2673
2674 dt := f_est_dchan('23'O, 23, '00010203040506'O);
Pau Espin Pedrold0046312021-04-19 16:35:58 +02002675 /* Send CommonID with some random PLMN (BSC doesn't take it into account
2676 * yet when generating the EUTRAN neigh list in RR CHannel Release) */
2677 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002678
2679 /* Instruct BSC to clear channel */
2680 var BssmapCause cause := 0;
2681 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2682
2683 /* expect Clear Complete from BSC on A */
2684 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2685 /* release the SCCP connection */
2686 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2687 }
2688
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002689 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 +02002690 }
2691
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002692 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002693 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 +02002694 }
2695}
2696
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002697private function f_tr_si2quater_earfcns(integer count) return template SI2quaterRestOctetsList
2698{
2699 var template SI2quaterRestOctetsList si2quater := {};
2700 var integer si2quater_count := (count + 2) / 3;
2701
2702 for (var integer i := 0; i < count; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002703 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002704 var integer index := i / 3;
2705 var integer earfcn_index := i mod 3;
2706 if (index >= lengthof(si2quater)) {
2707 si2quater[index] := tr_SI2quaterRestOctets_EUTRAN(index := index, count := si2quater_count - 1);
2708 }
2709 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);
2710 }
2711
2712 return si2quater;
2713}
2714
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002715private function f_tr_rr_chan_rel_earfcns(integer count) return template CellSelIndValue
2716{
2717 var template CellSelIndValue_EUTRAN_Descrs cells := {};
2718
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002719 /* the lte neighbors must match the config & vty to pass this test */
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002720 for (var integer i := 0; i < count; i := i + 1) {
2721 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002722 cells[i] := tr_CellSelIndValue_EUTRAN_Descr(earfcn, '1'B, 3);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002723 }
2724
2725 return tr_CellSelIndValue_EUTRAN(cells);
2726}
2727
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002728private function f_tc_si2quater_n_earfcns(integer n) runs on test_CT
2729{
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002730 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrol8ab62e42020-12-18 16:19:11 +01002731 sic.si2quater := f_tr_si2quater_earfcns(n);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002732 var template CellSelIndValue cells := f_tr_rr_chan_rel_earfcns(n);
2733 f_test_si2quater(n, sic, cells);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002734}
2735
2736testcase TC_si2quater_2_earfcns() runs on test_CT {
2737 f_tc_si2quater_n_earfcns(2);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002738 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002739}
2740
2741testcase TC_si2quater_3_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002742 f_tc_si2quater_n_earfcns(3);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002743 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002744}
2745
2746testcase TC_si2quater_4_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002747 f_tc_si2quater_n_earfcns(4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002748 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002749}
2750
2751testcase TC_si2quater_5_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002752 f_tc_si2quater_n_earfcns(5);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002753 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002754}
2755
2756testcase TC_si2quater_6_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002757 f_tc_si2quater_n_earfcns(6);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002758 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002759}
2760
2761testcase TC_si2quater_12_earfcns() runs on test_CT {
2762 f_tc_si2quater_n_earfcns(12);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002763 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002764}
2765
2766testcase TC_si2quater_23_earfcns() runs on test_CT {
2767 f_tc_si2quater_n_earfcns(23);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002768 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002769}
2770
2771testcase TC_si2quater_32_earfcns() runs on test_CT {
2772 f_tc_si2quater_n_earfcns(32);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002773 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002774}
2775
2776testcase TC_si2quater_33_earfcns() runs on test_CT {
2777 f_tc_si2quater_n_earfcns(33);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002778 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002779}
2780
2781testcase TC_si2quater_42_earfcns() runs on test_CT {
2782 f_tc_si2quater_n_earfcns(42);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002783 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002784}
2785
2786testcase TC_si2quater_48_earfcns() runs on test_CT {
2787 f_tc_si2quater_n_earfcns(48);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002788 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002789}
2790
2791/* verify the VTY error response when adding too many EARFCNs, and showing that osmo-bsc still sends 16 SI2quater with
2792 * 48 EARFCNs. */
2793testcase TC_si2quater_49_earfcns() runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002794 var template SystemInformationConfig sic := SystemInformationConfig_default;
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002795 sic.si2quater := f_tr_si2quater_earfcns(48); /* 48, not 49! */
2796 f_init(0);
2797
2798 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002799 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2800 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002801 }
2802
2803 /* The 49th EARFCN no longer fits, expect VTY error */
2804 f_vty_enter_cfg_bts(BSCVTY, 0);
2805 var charstring vty_error;
2806 vty_error := f_vty_transceive_ret(BSCVTY,
2807 "si2quater neighbor-list add earfcn 70 thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3")
2808 f_vty_transceive(BSCVTY, "end");
2809
2810 if (f_strstr(vty_error, "Unable to add ARFCN 70") >= 0) {
2811 log("Got expected VTY error: ", vty_error);
2812 setverdict(pass);
2813 } else {
2814 setverdict(fail, "Expected the 49th EUTRAN ARFCN to be rejected by vty config, got: ", vty_error);
2815 }
2816
2817 f_init_bts_and_check_sysinfo(0, expect_si := sic);
2818
2819 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002820 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 +02002821 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002822 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002823}
2824
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002825private function f_acc09_count_allowed(AccessControlClass acc) return uint8_t
2826{
2827 var uint8_t count := 0;
2828 for (var integer i := 5; i < 16; i := i + 1) {
2829 if (acc[i] == '0'B) { /* the list marks barred, we count allowed */
2830 count := count + 1;
2831 }
2832 }
2833 return count;
2834}
2835
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002836private function f_recv_next_si1(integer rsl_idx := 0) runs on test_CT return SystemInformationType1
2837{
2838 var ASP_RSL_Unitdata rx_rsl_ud;
2839 var SystemInformationType1 last_si1;
2840
2841 timer T := 30.0;
2842 T.start;
2843 alt {
2844 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD((tr_RSL_NO_BCCH_INFO,
2845 tr_RSL_BCCH_INFO,
2846 tr_RSL_NO_SACCH_FILL,
2847 tr_RSL_SACCH_FILL))
2848 ) -> value rx_rsl_ud {
2849 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
2850 if (g_system_information[rsl_idx].si1 == omit) {
2851 repeat;
2852 }
2853 last_si1 := g_system_information[rsl_idx].si1;
2854 g_system_information[rsl_idx].si1 := omit;
2855 T.stop;
2856 }
Vadim Yanitskiy79ebd5e2021-01-04 00:12:55 +01002857 [] IPA_RSL[rsl_idx].receive { repeat; }
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002858 [] T.timeout { setverdict(fail, "Timeout receiving next SI1"); }
2859 }
2860 return last_si1;
2861}
2862
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002863/* verify ACC rotate feature */
2864testcase TC_si_acc_rotate() runs on test_CT {
2865 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002866 var SystemInformationType1 last_si1;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002867 var AccessControlClass acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002868 var uint8_t count;
2869 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2870
2871 f_init(0, guard_timeout := 60.0);
2872
2873 f_bts_0_cfg(BSCVTY, {"rach access-control-class 5 barred",
2874 "access-control-class-rotate 3",
2875 "access-control-class-rotate-quantum 1"});
2876
2877 /* Init and get first sysinfo */
2878 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2879
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002880 for (var integer i:= 0; i < 20; i := i + 1) {
2881 last_si1 := f_recv_next_si1(0);
2882 acc := last_si1.rach_control.acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002883 count := f_acc09_count_allowed(acc);
2884 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2885
2886 if (count != 3) {
2887 log("RSL: EXPECTED SI ACC len=3");
2888 setverdict(fail, "received SI does not match expectations");
2889 break;
2890 }
2891
2892 for (var integer j := 0; j < 10; j := j + 1) {
2893 if (acc[16 - 1 - j] == '0'B) { /* the list marks barred, we count allowed */
2894 times_allowed[j] := times_allowed[j] + 1;
2895 }
2896 }
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002897 }
2898
2899 for (var integer j := 0; j < 10; j := j + 1) {
2900 log("ACC", j, " allowed ", times_allowed[j], " times" );
2901 if (j != 5 and times_allowed[j] < 3) {
2902 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " < 1 times");
2903 } else if (j == 5 and times_allowed[j] > 0) {
2904 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " > 0 times");
2905 }
2906 }
2907
2908 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2909 "rach access-control-class 5 allowed"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002910 f_shutdown_helper();
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002911}
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002912
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002913/* verify ACC startup ramp+rotate feature */
2914testcase TC_si_acc_ramp_rotate() runs on test_CT {
2915 var template SystemInformationConfig sic := SystemInformationConfig_default;
2916 var SystemInformationType1 last_si1;
2917 var AccessControlClass acc;
2918 var ASP_RSL_Unitdata rx_rsl_ud;
2919 var uint8_t count;
2920 var uint8_t prev_count;
2921 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2922
2923 f_init(0, guard_timeout := 80.0);
2924
2925 f_bts_0_cfg(BSCVTY, {"rach access-control-class 4 barred",
2926 "access-control-class-rotate 0",
2927 "access-control-class-rotate-quantum 1",
2928 "access-control-class-ramping",
2929 "access-control-class-ramping-step-interval 5",
2930 "access-control-class-ramping-step-size 5"});
2931
2932 /* Init and get first sysinfo */
2933 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2934 last_si1 := g_system_information[0].si1;
2935 acc := last_si1.rach_control.acc;
2936 count := f_acc09_count_allowed(acc);
2937 /* Adm subset size was set to 0 above, so wait until all ACC are barred */
2938 while (count > 0) {
2939 last_si1 := f_recv_next_si1(0);
2940 acc := last_si1.rach_control.acc;
2941 count := f_acc09_count_allowed(acc);
2942 log("RSL: wait len()=0: GOT SI1 ACC len=", count, ": ", acc);
2943 }
2944
2945 /* Increase adm subset size, we should see ramping start up */
2946 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10"});
2947 prev_count := 0;
2948 while (true) {
2949 last_si1 := f_recv_next_si1(0);
2950 acc := last_si1.rach_control.acc;
2951 count := f_acc09_count_allowed(acc);
2952 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2953
2954 if (prev_count > count) {
2955 setverdict(fail, "ACC allowed count dropped while expecting grow: ", prev_count, " -> ", count);
2956 break;
2957 }
2958
2959 if (count == 9) {
2960 break; /* Maximum reached (10 - 1 perm barred), done here */
2961 }
2962
2963 prev_count := count;
2964 }
2965
2966 setverdict(pass);
2967
2968 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2969 "rach access-control-class 4 allowed",
2970 "no access-control-class-ramping"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002971 f_shutdown_helper();
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002972}
2973
Harald Welte4003d112017-12-09 22:35:39 +01002974testcase TC_ctrl_msc_connection_status() runs on test_CT {
2975 var charstring ctrl_resp;
2976
Harald Welte89d42e82017-12-17 16:42:41 +01002977 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002978
2979 /* See https://osmocom.org/issues/2729 */
2980 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002981 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002982}
2983
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002984testcase TC_ctrl_msc0_connection_status() runs on test_CT {
2985 var charstring ctrl_resp;
2986
2987 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002988
2989 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002990 f_shutdown_helper();
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002991}
2992
Neels Hofmeyr0bc470d2021-08-21 13:37:13 +02002993/* Verify correct stats on the number of configured and connected MSCs */
2994private function f_tc_stat_num_msc_connected_msc_connhdlr(integer expect_num_msc_connected) runs on MSC_ConnHdlr {
2995 g_pars := f_gen_test_hdlr_pars();
2996 var StatsDExpects expect := {
2997 { name := "TTCN3.bsc.0.num_msc.connected", mtype := "g", min := expect_num_msc_connected, max := expect_num_msc_connected },
2998 { name := "TTCN3.bsc.0.num_msc.total", mtype := "g", min := NUM_MSC, max := NUM_MSC }
2999 };
3000 f_statsd_expect(expect);
3001}
3002
3003private function f_tc_stat_num_msc_connected_test_ct(void_fn tc_fn, integer nr_msc) runs on test_CT
3004{
3005 var MSC_ConnHdlr vc_conn;
3006
3007 f_init(nr_bts := 1, handler_mode := true, nr_msc := nr_msc);
3008 f_sleep(1.0);
3009 vc_conn := f_start_handler(tc_fn);
3010 vc_conn.done;
3011
3012 /* Also verify stat exposed on CTRL interface */
3013 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_msc:connected", int2str(nr_msc));
3014 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_msc:total", int2str(NUM_MSC));
3015
3016 f_shutdown_helper();
3017}
3018
3019/* Verify that when 1 MSC is active, that num_msc:connected reports 1. */
3020private function f_tc_stat_num_msc_connected_1(charstring id) runs on MSC_ConnHdlr {
3021 f_tc_stat_num_msc_connected_msc_connhdlr(1);
3022}
3023testcase TC_stat_num_msc_connected_1() runs on test_CT {
3024 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_1), 1);
3025}
3026
3027/* Verify that when 2 MSCs are active, that num_msc:connected reports 2. */
3028private function f_tc_stat_num_msc_connected_2(charstring id) runs on MSC_ConnHdlr {
3029 f_tc_stat_num_msc_connected_msc_connhdlr(2);
3030}
3031testcase TC_stat_num_msc_connected_2() runs on test_CT {
3032 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_2), 2);
3033}
3034
3035/* Verify that when 3 MSCs are active, that num_msc:connected reports 3. */
3036private function f_tc_stat_num_msc_connected_3(charstring id) runs on MSC_ConnHdlr {
3037 f_tc_stat_num_msc_connected_msc_connhdlr(3);
3038}
3039testcase TC_stat_num_msc_connected_3() runs on test_CT {
3040 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_3), 3);
3041}
3042
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +02003043/* Verify correct stats on the number of configured and connected MSCs */
3044private function f_tc_stat_num_bts_connected_msc_connhdlr(integer expect_num_bts_connected) runs on MSC_ConnHdlr {
3045 g_pars := f_gen_test_hdlr_pars();
3046 var StatsDExpects expect := {
3047 { name := "TTCN3.bsc.0.num_bts.oml_connected", mtype := "g", min := expect_num_bts_connected, max := NUM_BTS_CFG },
3048 { name := "TTCN3.bsc.0.num_bts.all_trx_rsl_connected", mtype := "g", min := expect_num_bts_connected, max := expect_num_bts_connected },
3049 { name := "TTCN3.bsc.0.num_bts.total", mtype := "g", min := NUM_BTS_CFG, max := NUM_BTS_CFG },
3050 { name := "TTCN3.bsc.0.num_trx.rsl_connected", mtype := "g", min := expect_num_bts_connected, max := expect_num_bts_connected },
3051 { name := "TTCN3.bsc.0.num_trx.total", mtype := "g", min := NUM_BTS_CFG, max := NUM_BTS_CFG }
3052 };
3053 f_statsd_expect(expect);
3054}
3055
3056private function f_tc_stat_num_bts_connected_test_ct(void_fn tc_fn, integer nr_bts) runs on test_CT {
3057 var MSC_ConnHdlr vc_conn;
3058
3059 f_init(nr_bts := nr_bts, handler_mode := true, nr_msc := 1);
3060 f_sleep(1.0);
3061 vc_conn := f_start_handler(tc_fn);
3062 vc_conn.done;
3063
3064 /* Also verify stat exposed on CTRL interface */
3065 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_bts:all_trx_rsl_connected", int2str(nr_bts));
3066 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_bts:total", int2str(NUM_BTS_CFG));
3067 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_trx:rsl_connected", int2str(nr_bts));
3068 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_trx:total", int2str(NUM_BTS_CFG));
3069
Neels Hofmeyra41ae302021-09-06 22:06:02 +02003070 /* Verify rf_states exposed on CTRL interface */
3071 var charstring expect_net_rf_states := "";
3072 for (var integer i := 0; i < NUM_BTS_CFG; i := i + 1) {
3073 var charstring expect_bts_rf_states := int2str(i) & ",0,";
3074 if (i < NUM_BTS) {
3075 /* In these tests, OML for the first NUM_BTS are always connected via osmo-bts-omldummy */
3076 expect_bts_rf_states := expect_bts_rf_states & "operational,unlocked,";
3077 } else {
3078 /* For remaining i < NUM_BTS_CFG, OML is not connected, i.e. inoperational */
3079 expect_bts_rf_states := expect_bts_rf_states & "inoperational,locked,";
3080 }
3081 /* The RF policy is still global in osmo-bsc, i.e. always "on" */
3082 expect_bts_rf_states := expect_bts_rf_states & "on,";
3083 if (i < nr_bts) {
3084 /* For BTS where RSL is connected, the RSL state will be "up" */
3085 expect_bts_rf_states := expect_bts_rf_states & "rsl-up;";
3086 } else {
3087 expect_bts_rf_states := expect_bts_rf_states & "rsl-down;";
3088 }
3089
3090 f_ctrl_get_exp(IPA_CTRL, "bts." & int2str(i) & ".rf_states", expect_bts_rf_states);
3091 expect_net_rf_states := expect_net_rf_states & expect_bts_rf_states;
3092 }
3093 f_ctrl_get_exp(IPA_CTRL, "rf_states", expect_net_rf_states);
3094
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +02003095 f_shutdown_helper();
3096}
3097
3098/* Verify that when 1 BTS is connected, that num_{bts,trx}:*_connected reports 1. */
3099private function f_tc_stat_num_bts_connected_1(charstring id) runs on MSC_ConnHdlr {
3100 f_tc_stat_num_bts_connected_msc_connhdlr(1);
3101}
3102testcase TC_stat_num_bts_connected_1() runs on test_CT {
3103 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_1), 1);
3104}
3105
3106/* Verify that when 2 BTS is connected, that num_{bts,trx}:*_connected reports 2. */
3107private function f_tc_stat_num_bts_connected_2(charstring id) runs on MSC_ConnHdlr {
3108 f_tc_stat_num_bts_connected_msc_connhdlr(2);
3109}
3110testcase TC_stat_num_bts_connected_2() runs on test_CT {
3111 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_2), 2);
3112}
3113
3114/* Verify that when 3 BTS is connected, that num_{bts,trx}:*_connected reports 3. */
3115private function f_tc_stat_num_bts_connected_3(charstring id) runs on MSC_ConnHdlr {
3116 f_tc_stat_num_bts_connected_msc_connhdlr(3);
3117}
3118testcase TC_stat_num_bts_connected_3() runs on test_CT {
3119 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_3), 3);
3120}
3121
Harald Welte4003d112017-12-09 22:35:39 +01003122testcase TC_ctrl() runs on test_CT {
3123 var charstring ctrl_resp;
3124
Harald Welte89d42e82017-12-17 16:42:41 +01003125 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01003126
3127 /* all below values must match the osmo-bsc.cfg config file used */
3128
Harald Welte6a129692018-03-17 17:30:14 +01003129 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
3130 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Oliver Smith75aa0202019-08-19 14:17:50 +02003131 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "4");
Harald Welte4003d112017-12-09 22:35:39 +01003132
3133 var integer bts_nr := 0;
3134 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
3135 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
3136 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
3137 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
3138 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
3139 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
3140 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
3141
3142 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
3143 f_sleep(2.0);
3144 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
3145 setverdict(fail, "oml-uptime not incrementing as expected");
3146 }
3147 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
3148
3149 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
3150
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003151 f_shutdown_helper();
Harald Welte96c94412017-12-09 03:12:45 +01003152}
3153
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02003154/* Verify that Upon receival of SET "location", BSC forwards a TRAP
3155 "location-state" over the SCCPlite IPA conn */
3156testcase TC_ctrl_location() runs on test_CT {
3157 var MSC_ConnHdlr vc_conn;
3158 var integer bts_nr := 0;
3159
3160 f_init(1, true);
3161 f_sleep(1.0);
3162
3163 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234567,fix3d,0.340000,0.560000,0.780000");
3164 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
3165 "1234567,fix3d,0.340000,0.560000,0.780000,operational,unlocked,on,001,01");
3166
3167 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "1");
3168 f_sleep(2.0);
3169
3170 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234888,fix3d,0.350000,0.570000,0.790000");
3171 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
3172 "1234888,fix3d,0.350000,0.570000,0.790000,operational,locked,off,001,01");
3173
3174 /* should match the one from config */
3175 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "0");
3176
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003177 f_shutdown_helper();
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02003178}
3179
Harald Welte6f521d82017-12-11 19:52:02 +01003180
3181/***********************************************************************
3182 * Paging Testing
3183 ***********************************************************************/
3184
3185type record Cell_Identity {
3186 GsmMcc mcc,
3187 GsmMnc mnc,
3188 GsmLac lac,
3189 GsmCellId ci
3190};
Harald Welte24135bd2018-03-17 19:27:53 +01003191private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01003192private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01003193
Harald Welte5d1a2202017-12-13 19:51:29 +01003194type set of integer BtsIdList;
3195
3196private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
3197 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
3198 if (bts_id == bts_ids[j]) {
3199 return true;
3200 }
3201 }
3202 return false;
3203}
Harald Welte6f521d82017-12-11 19:52:02 +01003204
3205/* core paging test helper function; used by most paging test cases */
3206private function f_pageing_helper(hexstring imsi,
3207 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01003208 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01003209 template RSL_ChanNeeded rsl_chneed := omit,
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003210 template (omit) OCT4 tmsi := omit) runs on test_CT
Harald Welte6f521d82017-12-11 19:52:02 +01003211{
3212 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003213 var template MobileIdentityV mi;
Harald Welte6f521d82017-12-11 19:52:02 +01003214 var RSL_Message rx_rsl;
3215 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01003216 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01003217
3218 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01003219
3220 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01003221 for (i := 0; i < NUM_BTS; i := i + 1) {
3222 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01003223 }
Harald Welte6f521d82017-12-11 19:52:02 +01003224
3225 if (isvalue(rsl_chneed)) {
3226 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
3227 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
3228 } else {
3229 bssmap_chneed := omit;
3230 }
3231
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003232 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[0].sccp_addr_peer, g_bssap[0].sccp_addr_own,
3233 ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed)));
Harald Welte6f521d82017-12-11 19:52:02 +01003234
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003235 if (not istemplatekind(tmsi, "omit")) {
3236 mi := t_MI_TMSI(tmsi);
Harald Welte6f521d82017-12-11 19:52:02 +01003237 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003238 mi := tr_MI_IMSI(imsi);
Harald Welte6f521d82017-12-11 19:52:02 +01003239 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003240
Harald Welte5d1a2202017-12-13 19:51:29 +01003241 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003242 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(mi));
Harald Welte5d1a2202017-12-13 19:51:29 +01003243 /* check channel type, paging group */
3244 if (rx_rsl.ies[1].body.paging_group != paging_group) {
3245 setverdict(fail, "Paging for wrong paging group");
3246 }
3247 if (ispresent(rsl_chneed) and
3248 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
3249 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
3250 }
Harald Welte6f521d82017-12-11 19:52:02 +01003251 }
Harald Welte2fccd982018-01-31 15:48:19 +01003252 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01003253 /* do a quick check on all not-included BTSs if they received paging */
3254 for (i := 0; i < NUM_BTS; i := i + 1) {
3255 timer T := 0.1;
3256 if (f_bts_in_list(i, bts_ids)) {
3257 continue;
3258 }
3259 T.start;
3260 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003261 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(mi))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003262 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
3263 }
3264 [] IPA_RSL[i].receive { repeat; }
3265 [] T.timeout { }
3266 }
Harald Welte6f521d82017-12-11 19:52:02 +01003267 }
3268
3269 setverdict(pass);
3270}
3271
Harald Welte5d1a2202017-12-13 19:51:29 +01003272const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01003273const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01003274const BtsIdList c_BtsId_LAC1 := { 0, 1 };
3275const BtsIdList c_BtsId_LAC2 := { 2 };
3276
Harald Welte6f521d82017-12-11 19:52:02 +01003277/* PAGING by IMSI + TMSI */
3278testcase TC_paging_imsi_nochan() runs on test_CT {
3279 var BSSMAP_FIELD_CellIdentificationList cid_list;
3280 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01003281 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003282 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003283}
3284
3285/* PAGING by IMSI + TMSI */
3286testcase TC_paging_tmsi_nochan() runs on test_CT {
3287 var BSSMAP_FIELD_CellIdentificationList cid_list;
3288 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003289 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003290 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003291}
3292
3293/* Paging with different "channel needed' values */
3294testcase TC_paging_tmsi_any() runs on test_CT {
3295 var BSSMAP_FIELD_CellIdentificationList cid_list;
3296 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003297 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003298 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003299}
3300testcase TC_paging_tmsi_sdcch() runs on test_CT {
3301 var BSSMAP_FIELD_CellIdentificationList cid_list;
3302 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003303 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003304 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003305}
3306testcase TC_paging_tmsi_tch_f() runs on test_CT {
3307 var BSSMAP_FIELD_CellIdentificationList cid_list;
3308 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003309 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003310 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003311}
3312testcase TC_paging_tmsi_tch_hf() runs on test_CT {
3313 var BSSMAP_FIELD_CellIdentificationList cid_list;
3314 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003315 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003316 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003317}
3318
3319/* Paging by CGI */
3320testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
3321 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3322 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003323 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003324 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003325}
3326
3327/* Paging by LAC+CI */
3328testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
3329 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3330 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003331 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003332 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003333}
3334
3335/* Paging by CI */
3336testcase TC_paging_imsi_nochan_ci() runs on test_CT {
3337 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3338 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003339 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003340 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003341}
3342
3343/* Paging by LAI */
3344testcase TC_paging_imsi_nochan_lai() runs on test_CT {
3345 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3346 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003347 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003348 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003349}
3350
3351/* Paging by LAC */
3352testcase TC_paging_imsi_nochan_lac() runs on test_CT {
3353 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3354 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003355 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003356 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003357}
3358
3359/* Paging by "all in BSS" */
3360testcase TC_paging_imsi_nochan_all() runs on test_CT {
3361 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3362 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01003363 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003364 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003365}
3366
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003367/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003368testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
3369 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3370 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 +01003371 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003372 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003373}
Harald Welte6f521d82017-12-11 19:52:02 +01003374
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003375/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003376testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
3377 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3378 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003379 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003380 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003381}
3382
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003383/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003384testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
3385 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3386 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003387 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003388 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003389}
3390
Harald Welte6f521d82017-12-11 19:52:02 +01003391/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01003392testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
3393 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3394 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
3395 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003396 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003397}
3398
3399/* Paging on empty list: Verify none of them page */
3400testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
3401 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3402 cid_list := { cIl_LAC := { } };
3403 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003404 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003405}
3406
Stefan Sperling049a86e2018-03-20 15:51:00 +01003407/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
3408testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
3409 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3410 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
3411 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
3412 f_shutdown_helper();
3413}
3414
Harald Welte6f521d82017-12-11 19:52:02 +01003415/* Verify paging retransmission interval + count */
3416/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01003417/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01003418
Harald Weltee65d40e2017-12-13 00:09:06 +01003419/* Verify PCH load */
3420testcase TC_paging_imsi_load() runs on test_CT {
3421 var BSSMAP_FIELD_CellIdentificationList cid_list;
3422 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01003423 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01003424 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003425 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01003426
3427 /* tell BSC there is no paging space anymore */
3428 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01003429 f_sleep(0.2);
3430 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01003431
3432 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
3433 * there would be 8 retransmissions during 4 seconds */
3434 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01003435 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01003436 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003437 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Weltee65d40e2017-12-13 00:09:06 +01003438 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02003439 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01003440 }
Harald Welte2caa1062018-03-17 18:19:05 +01003441 [] T_retrans.timeout {
3442 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
3443 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
3444 T_retrans.start;
3445 repeat;
3446 }
Harald Weltee65d40e2017-12-13 00:09:06 +01003447 [] T.timeout {
3448 setverdict(pass);
3449 }
3450 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003451
3452 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01003453}
3454
Harald Welte235ebf12017-12-15 14:18:16 +01003455/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01003456testcase TC_paging_counter() runs on test_CT {
3457 var BSSMAP_FIELD_CellIdentificationList cid_list;
3458 timer T := 4.0;
3459 var integer i;
3460 var integer paging_attempted_bsc;
3461 var integer paging_attempted_bts[NUM_BTS];
Oliver Smith8b343d32021-11-26 13:01:42 +01003462 var integer paging_expired_bsc;
Harald Welte1ff69992017-12-14 12:31:17 +01003463 var integer paging_expired_bts[NUM_BTS];
3464 cid_list := valueof(ts_BSSMAP_CIL_noCell);
3465
3466 f_init();
3467
3468 /* read counters before paging */
3469 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
Oliver Smith8b343d32021-11-26 13:01:42 +01003470 if (Misc_Helpers.f_osmo_repo_is("nightly")) { /* osmo-bsc > 1.8.0 */
3471 paging_expired_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:expired");
3472 }
Harald Welte1ff69992017-12-14 12:31:17 +01003473 for (i := 0; i < NUM_BTS; i := i+1) {
3474 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
3475 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
3476 }
3477
3478 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
3479
3480 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
3481 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
3482 for (i := 0; i < NUM_BTS; i := i+1) {
3483 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
3484 paging_attempted_bts[i]+1);
3485 }
3486
3487 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
3488 f_sleep(12.0);
Oliver Smith8b343d32021-11-26 13:01:42 +01003489 if (Misc_Helpers.f_osmo_repo_is("nightly")) { /* osmo-bsc > 1.8.0 */
3490 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:expired", paging_expired_bsc+1);
3491 }
Harald Welte1ff69992017-12-14 12:31:17 +01003492 for (i := 0; i < NUM_BTS; i := i+1) {
3493 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
3494 paging_expired_bts[i]+1);
3495 }
Harald Welte1ff69992017-12-14 12:31:17 +01003496
Philipp Maier282ca4b2018-02-27 17:17:00 +01003497 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01003498}
3499
3500
Harald Welte10985002017-12-12 09:29:15 +01003501/* Verify paging stops after A-RESET */
3502testcase TC_paging_imsi_a_reset() runs on test_CT {
3503 var BSSMAP_FIELD_CellIdentificationList cid_list;
3504 timer T := 3.0;
3505 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003506 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01003507
3508 /* Perform a BSSMAP Reset and wait for ACK */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003509 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 +01003510 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003511 [] 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 +01003512 [] BSSAP.receive { repeat; }
3513 }
3514
Daniel Willmanncbef3982018-07-30 09:22:40 +02003515 /* Wait to avoid a possible race condition if a paging message is
3516 * received right before the reset ACK. */
3517 f_sleep(0.2);
3518
Harald Welte10985002017-12-12 09:29:15 +01003519 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01003520 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
3521 IPA_RSL[i].clear;
3522 }
Harald Welte10985002017-12-12 09:29:15 +01003523
3524 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
3525 T.start;
3526 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003527 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte10985002017-12-12 09:29:15 +01003528 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003529 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01003530 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003531 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003532 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003533 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003534 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003535 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003536 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003537 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003538 }
Harald Welte10985002017-12-12 09:29:15 +01003539 [] T.timeout {
3540 setverdict(pass);
3541 }
3542 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003543
3544 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01003545}
Harald Welteae026692017-12-09 01:03:01 +01003546
Philipp Maierf45824a2019-08-14 14:44:10 +02003547/* Verify how we handle unsolicited Paging Response. In case of an unsolicit
3548 * paging response we can not know which MSC is in charge, so we will blindly
3549 * pick the first configured MSC. This behavior is required in order to make
3550 * MT-CSFB calls working because in those cases the BSC can not know that the
3551 * MSC has already paged the subscriver via SGs. So any MT-CSFB call will look
3552 * like an unsolicited Paging Response to the MSC.
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003553 */
3554testcase TC_paging_resp_unsol() runs on test_CT {
3555
3556 f_init(1);
Philipp Maierf45824a2019-08-14 14:44:10 +02003557 timer T := 5.0;
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003558
3559 var BSSAP_N_CONNECT_ind rx_c_ind;
3560 var DchanTuple dt;
3561 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
Philipp Maierf45824a2019-08-14 14:44:10 +02003562 var octetstring rr_pag_resp := enc_PDU_ML3_MS_NW(l3);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003563
3564 /* Send CHAN RQD and wait for allocation; acknowledge it */
3565 dt.rsl_chan_nr := f_chreq_act_ack();
3566
3567 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
3568 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
3569
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003570
Philipp Maierf45824a2019-08-14 14:44:10 +02003571 /* Expevct a CR with a matching Paging response on the A-Interface */
3572 T.start;
3573 alt {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003574 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(rr_pag_resp))) -> value rx_c_ind {
Philipp Maierf45824a2019-08-14 14:44:10 +02003575 setverdict(pass);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003576 dt.sccp_conn_id := rx_c_ind.connectionId;
3577 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
Philipp Maierf45824a2019-08-14 14:44:10 +02003578 }
3579 [] BSSAP.receive {
3580 setverdict(fail, "Received unexpected message on A-Interface!");
3581 }
3582 [] T.timeout {
3583 setverdict(fail, "Received nothing on A-Interface!");
3584 }
3585 }
3586
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003587 f_perform_clear_test_ct(dt);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003588 f_shutdown_helper();
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003589}
3590
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003591/* Test RSL link drop causes counter increment */
3592testcase TC_rsl_drop_counter() runs on test_CT {
3593 var integer rsl_fail;
3594
Harald Welte89d42e82017-12-17 16:42:41 +01003595 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003596
3597 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
3598
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +01003599 f_ipa_rsl_stop(bts[0].rsl);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003600
3601 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
3602
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003603 f_shutdown_helper();
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003604}
3605
3606/* TODO: Test OML link drop causes counter increment */
3607
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003608/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
3609function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
3610 timer T := 10.0;
3611
3612 bts[0].rsl.id := "IPA-0-RSL";
Harald Welte71389132021-12-09 21:58:18 +01003613 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA") alive;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003614 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
3615 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
Oliver Smith92c2bdb2019-08-20 15:11:24 +02003616 bts[0].rsl.ccm_pars.unit_id := "99/0/0"; /* value which is unknown at BTS */
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003617
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01003618 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003619
3620 f_init_mgcp("VirtMSC");
3621
3622 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
3623 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
3624 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
3625 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
3626
3627 /* wait for IPA OML link to connect and then disconnect */
3628 T.start;
3629 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +07003630 [] IPA_RSL[0].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) {
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003631 T.stop;
3632 return true;
3633 }
3634 [] IPA_RSL[0].receive { repeat }
3635 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02003636 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003637 }
3638 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003639 return false;
3640}
3641
3642/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3643testcase TC_rsl_unknown_unit_id() runs on test_CT {
3644 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
3645 setverdict(pass);
3646 } else {
3647 setverdict(fail, "Timeout RSL waiting for connection to close");
3648 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003649 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003650}
3651
3652
3653/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3654testcase TC_oml_unknown_unit_id() runs on test_CT {
3655 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
3656 setverdict(pass);
3657 } else {
3658 setverdict(fail, "Timeout OML waiting for connection to close");
3659 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003660 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003661}
3662
3663
Harald Weltec1a2fff2017-12-17 11:06:19 +01003664/***********************************************************************
Harald Welte6811d102019-04-14 22:23:14 +02003665 * "New world" test cases using RSL_Emulation + RAN_Emulation
Harald Weltec1a2fff2017-12-17 11:06:19 +01003666 ***********************************************************************/
3667
Harald Welte6811d102019-04-14 22:23:14 +02003668import from RAN_Emulation all;
Harald Welte47cd0e32020-08-21 12:39:11 +02003669import from BSSAP_LE_Emulation all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01003670import from RSL_Emulation all;
3671import from MSC_ConnectionHandler all;
3672
3673type function void_fn(charstring id) runs on MSC_ConnHdlr;
3674
Harald Welte336820c2018-05-31 20:34:52 +02003675/* helper function to create and connect a MSC_ConnHdlr component */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003676private function f_connect_handler(inout MSC_ConnHdlr vc_conn, integer bssap_idx := 0) runs on test_CT {
3677 connect(vc_conn:RAN, g_bssap[bssap_idx].vc_RAN:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01003678 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003679 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01003680 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01003681 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01003682 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
3683 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
3684 }
Neels Hofmeyr91401012019-07-11 00:42:35 +02003685 if (isvalue(bts[2])) {
3686 connect(vc_conn:RSL2, bts[2].rsl.vc_RSL:CLIENT_PT);
3687 connect(vc_conn:RSL2_PROC, bts[2].rsl.vc_RSL:RSL_PROC);
3688 }
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003689 connect(vc_conn:BSSAP, g_bssap[bssap_idx].vc_RAN:CLIENT);
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02003690 if (mp_enable_lcs_tests) {
3691 connect(vc_conn:BSSAP_LE, g_bssap_le.vc_BSSAP_LE:CLIENT);
3692 connect(vc_conn:BSSAP_LE_PROC, g_bssap_le.vc_BSSAP_LE:PROC);
3693 }
Daniel Willmann191e0d92018-01-17 12:44:35 +01003694 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02003695 connect(vc_conn:MGCP_MULTI, vc_MGCP:MGCP_CLIENT_MULTI);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003696 connect(vc_conn:STATSD_PROC, vc_STATSD:STATSD_PROC);
Harald Welte336820c2018-05-31 20:34:52 +02003697}
3698
Neels Hofmeyrda436782021-07-20 22:09:06 +02003699function f_start_handler_create(template (omit) TestHdlrParams pars := omit)
Harald Welte336820c2018-05-31 20:34:52 +02003700runs on test_CT return MSC_ConnHdlr {
3701 var charstring id := testcasename();
3702 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003703 var integer bssap_idx := 0;
3704 if (isvalue(pars)) {
3705 bssap_idx := valueof(pars).mscpool.bssap_idx;
3706 }
Harald Welte336820c2018-05-31 20:34:52 +02003707 vc_conn := MSC_ConnHdlr.create(id);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003708 f_connect_handler(vc_conn, bssap_idx);
Neels Hofmeyrda436782021-07-20 22:09:06 +02003709 return vc_conn;
3710}
3711
3712function f_start_handler_run(MSC_ConnHdlr vc_conn, void_fn fn, template (omit) TestHdlrParams pars := omit)
3713runs on test_CT return MSC_ConnHdlr {
3714 var charstring id := testcasename();
Harald Weltea0630032018-03-20 21:09:55 +01003715 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003716 return vc_conn;
3717}
3718
Neels Hofmeyrda436782021-07-20 22:09:06 +02003719function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
3720runs on test_CT return MSC_ConnHdlr {
3721 return f_start_handler_run(f_start_handler_create(pars), fn, pars);
3722}
3723
Harald Weltea0630032018-03-20 21:09:55 +01003724/* first function inside ConnHdlr component; sets g_pars + starts function */
3725private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
3726runs on MSC_ConnHdlr {
3727 if (isvalue(pars)) {
3728 g_pars := valueof(pars);
3729 }
3730 fn.apply(id);
3731}
3732
Oliver Smith26a3db72021-07-09 13:51:29 +02003733private function f_vty_encryption_a5(charstring options) runs on test_CT {
3734 f_vty_transceive(BSCVTY, "configure terminal");
3735 f_vty_transceive(BSCVTY, "network");
3736 f_vty_transceive(BSCVTY, "encryption a5 " & options);
3737 f_vty_transceive(BSCVTY, "exit");
3738 f_vty_transceive(BSCVTY, "exit");
3739}
3740
3741private function f_vty_encryption_a5_reset() runs on test_CT {
3742 /* keep in sync with docker-playground.git ttcn3-bsc-test/osmo-bsc.cfg */
3743 f_vty_encryption_a5("0 1 3");
3744}
3745
Harald Welte3c86ea02018-05-10 22:28:05 +02003746/* Establish signalling channel (non-assignment case) followed by cipher mode */
3747private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003748 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3749 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02003750 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02003751 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
3752 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
3753 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
3754 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02003755
Philipp Maier23000732018-05-18 11:25:37 +02003756 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003757 f_perform_clear();
Harald Welte3c86ea02018-05-10 22:28:05 +02003758}
3759testcase TC_ciph_mode_a5_0() runs on test_CT {
3760 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003761 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003762 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
3763
3764 f_init(1, true);
3765 f_sleep(1.0);
3766 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3767 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003768 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003769}
3770testcase TC_ciph_mode_a5_1() runs on test_CT {
3771 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003772 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003773 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
3774
3775 f_init(1, true);
3776 f_sleep(1.0);
3777 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3778 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003779 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003780}
Oliver Smith50b98122021-07-09 15:00:28 +02003781/* OS#4975: verify that A5/2 is preferred over A5/0 */
3782testcase TC_ciph_mode_a5_2_0() runs on test_CT {
3783 var MSC_ConnHdlr vc_conn;
3784 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3785
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01003786 pars.encr := f_encr_params('05'O, '04'O); /* A5/0 and A5/2 (0x01|0x04)*/
Oliver Smith50b98122021-07-09 15:00:28 +02003787
3788 f_init(1, true);
3789 f_vty_encryption_a5("0 1 2 3");
3790 f_sleep(1.0);
3791 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3792 vc_conn.done;
3793 f_vty_encryption_a5_reset();
3794 f_shutdown_helper();
3795}
Oliver Smith1dff88d2021-07-09 08:45:51 +02003796/* OS#4975: verify that A5/1 is preferred over A5/2 */
3797testcase TC_ciph_mode_a5_2_1() runs on test_CT {
3798 var MSC_ConnHdlr vc_conn;
3799 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3800
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01003801 pars.encr := f_encr_params('06'O, '02'O); /* A5/1 and A5/2 (0x02|0x04)*/
Oliver Smith1dff88d2021-07-09 08:45:51 +02003802
3803 f_init(1, true);
3804 f_vty_encryption_a5("1 2");
3805 f_sleep(1.0);
3806 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3807 vc_conn.done;
3808 f_vty_encryption_a5_reset();
3809 f_shutdown_helper();
3810}
Harald Welte3c86ea02018-05-10 22:28:05 +02003811testcase TC_ciph_mode_a5_3() runs on test_CT {
3812 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003813 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003814 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
3815
3816 f_init(1, true);
3817 f_sleep(1.0);
3818 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3819 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003820 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003821}
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003822/* Establish a Signalling channel with A5/4 encryption. */
3823testcase TC_ciph_mode_a5_4() runs on test_CT {
3824 var MSC_ConnHdlr vc_conn;
3825 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3826 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Harald Welte3c86ea02018-05-10 22:28:05 +02003827
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003828 f_init(1, true);
Oliver Smith26a3db72021-07-09 13:51:29 +02003829 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003830 f_sleep(1.0);
3831 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3832 vc_conn.done;
Oliver Smith26a3db72021-07-09 13:51:29 +02003833 f_vty_encryption_a5_reset();
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003834 f_shutdown_helper();
3835}
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003836/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
3837private function f_tc_assignment_aoip_tla_v6(charstring id) runs on MSC_ConnHdlr {
3838 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3839 var PDU_BSSAP ass_cmd := f_gen_ass_req(aoip_tla := "::3");
3840 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3841 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3842
3843 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003844 f_perform_clear();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003845}
3846testcase TC_assignment_aoip_tla_v6() runs on test_CT {
3847 var MSC_ConnHdlr vc_conn;
3848 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3849
3850 f_init(1, true);
3851 f_sleep(1.0);
3852 vc_conn := f_start_handler(refers(f_tc_assignment_aoip_tla_v6), pars);
3853 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003854 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003855}
3856
Harald Welte3c86ea02018-05-10 22:28:05 +02003857
3858/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02003859private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003860 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3861 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003862
Harald Welte552620d2017-12-16 23:21:36 +01003863 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3864 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01003865
Harald Weltea0630032018-03-20 21:09:55 +01003866 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003867 f_perform_clear();
Harald Welte552620d2017-12-16 23:21:36 +01003868}
Harald Welte552620d2017-12-16 23:21:36 +01003869testcase TC_assignment_fr_a5_0() runs on test_CT {
3870 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003871 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003872 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01003873
Harald Welte89d42e82017-12-17 16:42:41 +01003874 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003875 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003876 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003877 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003878 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003879}
Harald Welte552620d2017-12-16 23:21:36 +01003880testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01003881 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003882 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003883 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003884
Harald Welte89d42e82017-12-17 16:42:41 +01003885 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003886 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003887 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3888 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003889 f_shutdown_helper();
Harald Welte651fcdc2018-05-10 20:23:16 +02003890}
3891testcase TC_assignment_fr_a5_3() runs on test_CT {
3892 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003893 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003894 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003895
Harald Welte651fcdc2018-05-10 20:23:16 +02003896 f_init(1, true);
3897 f_sleep(1.0);
3898 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003899 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003900 f_shutdown_helper();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003901}
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003902/* Establish a Signalling channel and re-assign to TCH/F with A5/4 encryption. */
3903testcase TC_assignment_fr_a5_4() runs on test_CT {
3904 var MSC_ConnHdlr vc_conn;
3905 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3906 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
3907
3908 f_init(1, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02003909 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003910 f_sleep(1.0);
3911 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3912 vc_conn.done;
Oliver Smith7eabd312021-07-12 14:18:56 +02003913 f_vty_encryption_a5_reset();
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003914 f_shutdown_helper();
3915}
Harald Weltec1a2fff2017-12-17 11:06:19 +01003916
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +02003917/* Allow only A5/4, but omit the Kc128 IE from MSC's msg. Expect Cipher Mode Reject. */
3918testcase TC_assignment_fr_a5_4_fail() runs on test_CT {
3919 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3920 var MSC_ConnHdlr vc_conn;
3921
3922 f_init(1, true);
3923 f_sleep(1.0);
3924
3925 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8))); // A5/4 support, but Kc128 missing!
3926 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
3927 vc_conn.done;
3928 f_shutdown_helper();
3929}
3930
Harald Welte552620d2017-12-16 23:21:36 +01003931/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
3932private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003933 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01003934 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02003935 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003936
3937 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003938 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
3939
Harald Weltea0630032018-03-20 21:09:55 +01003940 f_establish_fully(ass_cmd, exp_fail);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003941 f_perform_clear();
Harald Welte552620d2017-12-16 23:21:36 +01003942}
Harald Welte552620d2017-12-16 23:21:36 +01003943testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
3944 var MSC_ConnHdlr vc_conn;
3945
Harald Welte89d42e82017-12-17 16:42:41 +01003946 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003947 f_sleep(1.0);
3948
Harald Welte8863fa12018-05-10 20:15:27 +02003949 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01003950 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003951 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003952}
3953
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003954private function f_TC_assignment_a5_not_sup(charstring id) runs on MSC_ConnHdlr {
3955 var template PDU_BSSAP exp_ass_cpl := f_gen_exp_compl();
3956 var PDU_BSSAP exp_ass_req := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003957
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003958 exp_ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3959 exp_ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3960
3961 /* this is like the beginning of f_establish_fully(), but only up to ciphering reject */
3962
3963 var BSSMAP_FIELD_CodecType codecType;
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003964
3965 codecType := exp_ass_req.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType;
3966 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
3967
3968 f_create_chan_and_exp();
3969 /* we should now have a COMPL_L3 at the MSC */
3970
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003971 /* Start ciphering, expect Cipher Mode Reject */
Neels Hofmeyr6c388f22021-06-11 02:36:56 +02003972 f_cipher_mode(g_pars.encr, exp_fail := true);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003973 f_perform_clear();
Harald Welte552620d2017-12-16 23:21:36 +01003974}
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003975testcase TC_assignment_fr_a5_not_sup() runs on test_CT {
3976 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01003977 var MSC_ConnHdlr vc_conn;
3978
Harald Welte89d42e82017-12-17 16:42:41 +01003979 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003980 f_sleep(1.0);
3981
Neels Hofmeyr0588cad2021-06-11 01:38:18 +02003982 pars.encr := valueof(t_EncrParams('20'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003983 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003984 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003985 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003986}
3987
3988
Harald Welte4532e0a2017-12-23 02:05:44 +01003989private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003990 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01003991 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02003992 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01003993 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003994
3995 f_statsd_reset();
Harald Weltea0630032018-03-20 21:09:55 +01003996 f_establish_fully(ass_cmd, exp_compl);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003997
3998 var StatsDExpects expect := {
Daniel Willmannc5398f72020-09-21 10:41:35 +02003999 { name := "TTCN3.bts.0.chreq.total", mtype := "c", min := 1, max := 1},
4000 { name := "TTCN3.bts.0.chreq.successful", mtype := "c", min := 1, max := 1},
Daniel Willmannebdecc02020-08-12 15:30:17 +02004001 { name := "TTCN3.bsc.0.assignment.attempted", mtype := "c", min := 1, max := 1},
4002 { name := "TTCN3.bsc.0.assignment.completed", mtype := "c", min := 1, max := 1}
4003 };
4004 f_statsd_expect(expect);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004005 f_perform_clear();
Harald Welte4532e0a2017-12-23 02:05:44 +01004006}
4007
4008testcase TC_assignment_sign() runs on test_CT {
4009 var MSC_ConnHdlr vc_conn;
4010
4011 f_init(1, true);
4012 f_sleep(1.0);
4013
Harald Welte8863fa12018-05-10 20:15:27 +02004014 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01004015 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004016 f_shutdown_helper();
Harald Welte4532e0a2017-12-23 02:05:44 +01004017}
4018
Harald Welte60aa5762018-03-21 19:33:13 +01004019/***********************************************************************
4020 * Codec (list) testing
4021 ***********************************************************************/
4022
4023/* check if the given rsl_mode is compatible with the a_elem */
4024private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
4025return boolean {
4026 select (a_elem.codecType) {
4027 case (GSM_FR) {
4028 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
4029 return true;
4030 }
4031 }
4032 case (GSM_HR) {
4033 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
4034 return true;
4035 }
4036 }
4037 case (GSM_EFR) {
4038 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
4039 return true;
4040 }
4041 }
4042 case (FR_AMR) {
4043 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
4044 return true;
4045 }
4046 }
4047 case (HR_AMR) {
4048 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
4049 return true;
4050 }
4051 }
4052 case else { }
4053 }
4054 return false;
4055}
4056
4057/* check if the given rsl_mode is compatible with the a_list */
4058private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
4059return boolean {
4060 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
4061 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
4062 return true;
4063 }
4064 }
4065 return false;
4066}
4067
4068/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02004069function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01004070return BSSMAP_IE_ChannelType {
4071 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
4072 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
4073 select (a_elem.codecType) {
4074 case (GSM_FR) {
4075 ret.channelRateAndType := ChRate_TCHF;
4076 ret.speechId_DataIndicator := Spdi_TCHF_FR;
4077 }
4078 case (GSM_HR) {
4079 ret.channelRateAndType := ChRate_TCHH;
4080 ret.speechId_DataIndicator := Spdi_TCHH_HR;
4081 }
4082 case (GSM_EFR) {
4083 ret.channelRateAndType := ChRate_TCHF;
4084 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
4085 }
4086 case (FR_AMR) {
4087 ret.channelRateAndType := ChRate_TCHF;
4088 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
4089 }
4090 case (HR_AMR) {
4091 ret.channelRateAndType := ChRate_TCHH;
4092 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
4093 }
4094 case else {
4095 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02004096 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01004097 }
4098 }
4099 return ret;
4100}
4101
Harald Weltea63b9102018-03-22 20:36:16 +01004102private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
4103return template RSL_IE_Body {
4104 var template RSL_IE_Body mode_ie := {
4105 chan_mode := {
4106 len := ?,
4107 reserved := ?,
4108 dtx_d := ?,
4109 dtx_u := ?,
4110 spd_ind := RSL_SPDI_SPEECH,
4111 ch_rate_type := -,
4112 coding_alg_rate := -
4113 }
4114 }
4115
4116 select (a_elem.codecType) {
4117 case (GSM_FR) {
4118 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4119 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
4120 }
4121 case (GSM_HR) {
4122 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
4123 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
4124 }
4125 case (GSM_EFR) {
4126 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4127 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
4128 }
4129 case (FR_AMR) {
4130 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4131 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
4132 }
4133 case (HR_AMR) {
4134 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
4135 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
4136 }
4137 }
4138 return mode_ie;
4139}
4140
Harald Welte60aa5762018-03-21 19:33:13 +01004141type record CodecListTest {
4142 BSSMAP_IE_SpeechCodecList codec_list,
4143 charstring id
4144}
4145type record of CodecListTest CodecListTests
4146
4147private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004148 f_assignment_codec(id);
4149}
4150
4151private function f_assignment_codec(charstring id, boolean do_perform_clear := true) runs on MSC_ConnHdlr {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004152 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
4153 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
Harald Welte60aa5762018-03-21 19:33:13 +01004154
4155 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02004156 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte79f3f542018-05-25 20:02:37 +02004157 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
4158 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
4159 g_pars.ass_codec_list.codecElements[0];
Philipp Maierd0e64b02019-03-13 14:15:23 +01004160 if (isvalue(g_pars.expect_mr_s0_s7)) {
4161 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
4162 g_pars.expect_mr_s0_s7;
4163 }
Harald Welte79f3f542018-05-25 20:02:37 +02004164 }
Harald Welte60aa5762018-03-21 19:33:13 +01004165 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
4166 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01004167 log("expecting ASS COMPL like this: ", exp_compl);
4168
4169 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01004170
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004171 if (not g_pars.expect_channel_mode_modify) {
4172 /* Verify that the RSL-side activation actually matches our expectations */
4173 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
Harald Weltea63b9102018-03-22 20:36:16 +01004174
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004175 var RSL_IE_Body mode_ie;
4176 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
4177 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02004178 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004179 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004180 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
4181 if (not match(mode_ie, t_mode_ie)) {
4182 log("mode_ie ", mode_ie, " != t_mode_ie ", t_mode_ie);
4183 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004184 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004185
4186 var RSL_IE_Body mr_conf;
4187 if (g_pars.expect_mr_conf_ie != omit) {
4188 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
4189 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
4190 mtc.stop;
4191 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004192 log("found RSL MR CONFIG IE: ", mr_conf);
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004193
4194 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
4195 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
4196 g_pars.expect_mr_conf_ie);
4197 }
4198 } else {
4199 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
4200 log("found RSL MR CONFIG IE: ", mr_conf);
4201 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
4202 mtc.stop;
4203 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004204 }
4205 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004206
4207 if (do_perform_clear) {
4208 f_perform_clear();
4209 }
Harald Welte60aa5762018-03-21 19:33:13 +01004210}
4211
Philipp Maierd0e64b02019-03-13 14:15:23 +01004212private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
4213
4214 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4215 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4216
4217 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02004218 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maierd0e64b02019-03-13 14:15:23 +01004219 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
4220 }
4221 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
4222 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
4223 log("expecting ASS FAIL like this: ", exp_fail);
4224
4225 f_establish_fully(ass_cmd, exp_fail);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004226 f_perform_clear();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004227}
4228
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004229const CounterNameVals counternames_bsc_bts_assignment := {
4230 { "assignment:attempted", 0 },
4231 { "assignment:completed", 0 },
4232 { "assignment:stopped", 0 },
4233 { "assignment:no_channel", 0 },
4234 { "assignment:timeout", 0 },
4235 { "assignment:failed", 0 },
4236 { "assignment:error", 0 }
4237};
4238
4239const CounterNameVals counternames_bts_assignment := {
4240 { "assignment:attempted_sign", 0 },
4241 { "assignment:attempted_speech", 0 },
4242 { "assignment:completed_sign", 0 },
4243 { "assignment:completed_speech", 0 },
4244 { "assignment:stopped_sign", 0 },
4245 { "assignment:stopped_speech", 0 },
4246 { "assignment:no_channel_sign", 0 },
4247 { "assignment:no_channel_speech", 0 },
4248 { "assignment:timeout_sign", 0 },
4249 { "assignment:timeout_speech", 0 },
4250 { "assignment:failed_sign", 0 },
4251 { "assignment:failed_speech", 0 },
4252 { "assignment:error_sign", 0 },
4253 { "assignment:error_speech", 0 }
4254};
4255
4256function f_ctrs_bsc_and_bts_assignment_init(integer bts_count := NUM_BTS) runs on test_CT {
4257 var CounterNameVals bts_names := counternames_bsc_bts_assignment & counternames_bts_assignment;
4258 f_ctrs_bts_init(bts_count, bts_names);
4259 f_ctrs_bsc_init(counternames_bsc_bts_assignment);
4260}
4261
Harald Welte60aa5762018-03-21 19:33:13 +01004262testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004263 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004264 var MSC_ConnHdlr vc_conn;
4265
4266 f_init(1, true);
4267 f_sleep(1.0);
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004268 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004269
4270 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004271 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004272 vc_conn.done;
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004273
4274 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4275 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4276 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4277 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4278 f_ctrs_bts_verify();
4279
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004280 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004281}
4282
4283testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004284 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004285 var MSC_ConnHdlr vc_conn;
4286
4287 f_init(1, true);
4288 f_sleep(1.0);
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004289 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004290
4291 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004292 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004293 vc_conn.done;
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004294
4295 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4296 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4297 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4298 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4299 f_ctrs_bts_verify();
4300
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004301 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004302}
4303
4304testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004305 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004306 var MSC_ConnHdlr vc_conn;
4307
4308 f_init(1, true);
4309 f_sleep(1.0);
4310
4311 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004312 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004313 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004314 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004315}
4316
Philipp Maierd0e64b02019-03-13 14:15:23 +01004317/* Allow 5,90k only (current default config) */
4318private function f_allow_amr_rate_5_90k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00004319 f_vty_cfg_msc(BSCVTY, 0, {
4320 "amr-config 12_2k forbidden",
4321 "amr-config 10_2k forbidden",
4322 "amr-config 7_95k forbidden",
4323 "amr-config 7_40k forbidden",
4324 "amr-config 6_70k forbidden",
4325 "amr-config 5_90k allowed",
4326 "amr-config 5_15k forbidden",
4327 "amr-config 4_75k forbidden"
4328 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01004329}
4330
4331/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
4332 * ("Config-NB-Code = 1") */
4333private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00004334 f_vty_cfg_msc(BSCVTY, 0, {
4335 "amr-config 12_2k allowed",
4336 "amr-config 10_2k forbidden",
4337 "amr-config 7_95k forbidden",
4338 "amr-config 7_40k allowed",
4339 "amr-config 6_70k forbidden",
4340 "amr-config 5_90k allowed",
4341 "amr-config 5_15k forbidden",
4342 "amr-config 4_75k allowed"
4343 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01004344}
4345
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004346private function f_vty_amr_start_mode_set(boolean fr, charstring startmode) runs on test_CT {
4347 var charstring tch;
4348 if (fr) {
4349 tch := "tch-f";
4350 } else {
4351 tch := "tch-h";
4352 }
4353 f_vty_cfg_bts(BSCVTY, 0, { "amr " & tch & " start-mode " & startmode });
4354}
4355
4356/* Set the AMR start-mode for this TCH back to the default configuration. */
4357private function f_vty_amr_start_mode_restore(boolean fr) runs on test_CT {
4358 f_vty_amr_start_mode_set(fr, "auto");
4359}
4360
Harald Welte60aa5762018-03-21 19:33:13 +01004361testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004362 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004363 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02004364
4365 /* Note: This setups the codec configuration. The parameter payload in
4366 * mr_conf must be consistant with the parameter codecElements in pars
4367 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004368 var RSL_IE_Body mr_conf := {
4369 other := {
4370 len := 2,
4371 payload := '2804'O
4372 }
4373 };
Harald Welte60aa5762018-03-21 19:33:13 +01004374
Philipp Maier7695a0d2018-09-27 17:52:14 +02004375 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Philipp Maier806f8f12019-03-12 12:13:41 +01004376 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02004377 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
4378 pars.expect_mr_conf_ie := mr_conf;
4379
Harald Welte60aa5762018-03-21 19:33:13 +01004380 f_init(1, true);
4381 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004382 f_vty_amr_start_mode_set(true, "1");
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004383 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004384
Harald Welte8863fa12018-05-10 20:15:27 +02004385 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004386 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004387
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004388 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4389 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4390 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4391 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4392 f_ctrs_bts_verify();
4393
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004394 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004395 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004396}
4397
4398testcase TC_assignment_codec_amr_h() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004399 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004400 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02004401
4402 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004403 var RSL_IE_Body mr_conf := {
4404 other := {
4405 len := 2,
4406 payload := '2804'O
4407 }
4408 };
Harald Welte60aa5762018-03-21 19:33:13 +01004409
Philipp Maier7695a0d2018-09-27 17:52:14 +02004410 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Philipp Maier806f8f12019-03-12 12:13:41 +01004411 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02004412 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4413 pars.expect_mr_conf_ie := mr_conf;
4414
Harald Welte60aa5762018-03-21 19:33:13 +01004415 f_init(1, true);
4416 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004417 f_vty_amr_start_mode_set(false, "1");
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004418 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004419
Harald Welte8863fa12018-05-10 20:15:27 +02004420 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004421 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004422
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004423 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4424 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4425 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4426 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4427 f_ctrs_bts_verify();
4428
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004429 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004430 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004431}
4432
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004433/* Establish signalling on a TCH/F lchan, and then switch to speech mode without a new Assignment. */
4434testcase TC_assignment_codec_fr_by_mode_modify() runs on test_CT {
4435 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4436 var MSC_ConnHdlr vc_conn;
4437
4438 f_init(1, true);
4439 f_sleep(1.0);
4440
4441 /* By disabling all SDCCH, the MS should be given a TCH/F for signalling. Then activating an FR codec should
4442 * merely do a Channel Mode Modify, and not assign to a new lchan. f_establish_fully() already accounts for
4443 * expecting a Channel Mode Modify if the channel type is compatible. */
4444 f_disable_all_sdcch();
4445 f_disable_all_tch_h();
4446
4447 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4448 pars.expect_channel_mode_modify := true;
4449 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4450 vc_conn.done;
4451
4452 f_enable_all_sdcch();
4453 f_enable_all_tch();
4454 f_shutdown_helper();
4455}
4456
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004457/* 'amr start-mode auto' should not keep the (unused) 'smod' bits from previous configuration */
4458testcase TC_assignment_codec_amr_startmode_cruft() runs on test_CT {
4459 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4460 var MSC_ConnHdlr vc_conn;
4461
4462 var RSL_IE_Body mr_conf := {
4463 other := {
4464 len := 2,
4465 payload := '2004'O /* <- expect ICMI=0, smod=00 */
4466 }
4467 };
4468
4469 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4470 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
4471 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
4472 pars.expect_mr_conf_ie := mr_conf;
4473
4474 f_init(1, true);
4475 f_sleep(1.0);
4476
4477 /* First set nonzero start mode bits */
4478 f_vty_amr_start_mode_set(true, "4");
4479 /* Now set to auto, and expect the startmode bits to be zero in the message, i.e. ensure that osmo-bsc does not
4480 * let the startmode bits stick around and has deterministic MultiRate config for 'start-mode auto'; that is
4481 * ensured by above '2004'O, where 'x0xx'O indicates ICMI = 0, spare = 0, smod = 00. */
4482 f_vty_amr_start_mode_set(true, "auto");
4483
4484 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4485 vc_conn.done;
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004486
4487 /* Clear the startmode bits to not affect subsequent tests, in case the bits should indeed stick around. */
4488 f_vty_amr_start_mode_set(true, "1");
4489 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004490 f_shutdown_helper();
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004491}
4492
Neels Hofmeyr21863562020-11-26 00:34:33 +00004493function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0,
4494 charstring start_mode := "1")
Philipp Maierd0e64b02019-03-13 14:15:23 +01004495runs on test_CT {
4496
4497 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4498 var MSC_ConnHdlr vc_conn;
4499
4500 /* See note above */
4501 var RSL_IE_Body mr_conf := {
4502 other := {
4503 len := lengthof(mrconf),
4504 payload := mrconf
4505 }
4506 };
4507
4508 if (fr) {
4509 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4510 } else {
4511 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4512 }
4513 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4514 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4515 pars.expect_mr_conf_ie := mr_conf;
4516 pars.expect_mr_s0_s7 := exp_s8_s0;
4517
4518 f_init(1, true);
4519 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004520 f_vty_amr_start_mode_set(fr, start_mode);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004521 f_sleep(1.0);
4522
4523 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4524 vc_conn.done;
4525 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004526 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004527}
4528
4529function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
4530runs on test_CT {
4531
4532 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4533 var MSC_ConnHdlr vc_conn;
4534
4535 if (fr) {
4536 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4537 } else {
4538 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4539 }
4540 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4541 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4542
4543 f_init(1, true);
4544 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004545 f_vty_amr_start_mode_set(fr, "1");
Philipp Maierd0e64b02019-03-13 14:15:23 +01004546 f_sleep(1.0);
4547
4548 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
4549 vc_conn.done;
4550 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004551 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004552}
4553
4554
4555/* Set S1, we expect an AMR multirate configuration IE with all four rates
4556 * set. */
4557testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004558 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004559 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004560}
4561
4562/* Set S1, we expect an AMR multirate configuration IE with the lower three
4563 * rates set. */
4564testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004565 f_TC_assignment_codec_amr(false, '2815208820'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004566 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004567}
4568
4569/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4570 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4571testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004572 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004573 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004574}
4575
4576/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4577 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4578testcase TC_assignment_codec_amr_h_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004579 f_TC_assignment_codec_amr(false, '2815208820'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004580 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004581}
4582
4583/* The following block of tests selects more and more rates until all four
4584 * possible rates are in the active set (full rate) */
4585testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004586 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004587 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004588}
4589
4590testcase TC_assignment_codec_amr_f_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004591 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004592 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004593}
4594
4595testcase TC_assignment_codec_amr_f_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004596 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004597 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004598}
4599
4600testcase TC_assignment_codec_amr_f_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004601 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004602 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004603}
4604
4605/* The following block of tests selects more and more rates until all three
4606 * possible rates are in the active set (half rate) */
4607testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004608 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004609 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004610}
4611
4612testcase TC_assignment_codec_amr_h_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004613 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004614 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004615}
4616
4617testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004618 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004619 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004620}
4621
4622/* The following block tests what happens when the MSC does offer rate
4623 * configurations that are not supported by the BSC. Normally such situations
4624 * should not happen because the MSC gets informed by the BSC in advance via
4625 * the L3 COMPLETE message which rates are applicable. The MSC should not try
4626 * to offer rates that are not applicable anyway. */
4627
4628testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004629 /* Try to include 12,2k in into the active set even though the channel
4630 * is half rate only. The BSC is expected to remove the 12,0k */
4631 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004632 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004633}
4634
4635testcase TC_assignment_codec_amr_f_S01234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004636 /* See what happens when all rates are selected at once. Since then
4637 * Also S1 is selected, this setting will be prefered and we should
4638 * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
4639 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004640 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004641}
4642
4643testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004644 /* Same as above, but with S1 missing, the MSC is then expected to
4645 * select the currently supported rates, which are also 12.2k, 7,40k,
4646 * 5,90k, and 4,75k, into the active set. */
4647 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004648 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004649}
4650
4651testcase TC_assignment_codec_amr_f_zero() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004652 /* Try to select no rates at all */
4653 f_TC_assignment_codec_amr_fail(true, '00000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004654 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004655}
4656
4657testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004658 /* Try to select only unsupported rates */
4659 f_TC_assignment_codec_amr_fail(true, '01101000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004660 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004661}
4662
4663testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004664 /* Try to select 12,2k for half rate */
4665 f_TC_assignment_codec_amr_fail(false, '10000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004666 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004667}
4668
Neels Hofmeyr21863562020-11-26 00:34:33 +00004669testcase TC_assignment_codec_amr_f_start_mode_auto() runs on test_CT {
4670 f_TC_assignment_codec_amr(true, '209520882208'O, '11111111'B, '00000010'B,
4671 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004672 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004673}
4674
4675testcase TC_assignment_codec_amr_h_start_mode_auto() runs on test_CT {
4676 f_TC_assignment_codec_amr(false, '2015208820'O, '10010101'B, '00010101'B,
4677 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004678 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004679}
4680
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004681testcase TC_assignment_codec_amr_f_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004682 /* "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 +00004683 f_TC_assignment_codec_amr(true, '2b9520882208'O, '11111111'B, '00000010'B,
4684 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004685 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004686}
4687
4688testcase TC_assignment_codec_amr_h_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004689 /* "amr tch-h modes 0 2 4" => total 3 modes and start mode 4 => '10'B on the wire */
4690 f_TC_assignment_codec_amr(false, '2a15208820'O, '10010101'B, '00010101'B,
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004691 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004692 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004693}
4694
Philipp Maierac09bfc2019-01-08 13:41:39 +01004695private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004696 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
4697 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
4698 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
4699 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004700}
4701
4702private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004703 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
4704 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004705}
4706
4707private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004708 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
4709 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
4710 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
4711 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
4712 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
4713 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004714}
4715
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004716private function f_disable_all_sdcch() runs on test_CT {
4717 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 borken");
4718 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 borken");
4719 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 borken");
4720 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 borken");
4721}
4722
4723private function f_enable_all_sdcch() runs on test_CT {
4724 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 unused");
4725 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 unused");
4726 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 unused");
4727 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 unused");
4728}
4729
Philipp Maierac09bfc2019-01-08 13:41:39 +01004730/* Allow HR only */
4731private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
4732 g_pars := f_gen_test_hdlr_pars();
4733 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4734 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4735 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4736 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4737 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4738 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4739 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004740 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004741}
4742
4743/* Allow FR only */
4744private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
4745 g_pars := f_gen_test_hdlr_pars();
4746 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4747 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4748 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4749 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4750 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4751 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4752 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004753 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004754}
4755
4756/* Allow HR only (expect assignment failure) */
4757private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
4758 g_pars := f_gen_test_hdlr_pars();
4759 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4760 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4761 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4762 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4763 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4764 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4765 f_establish_fully(ass_cmd, exp_fail);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004766 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004767}
4768
4769/* Allow FR only (expect assignment failure) */
4770private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(charstring id) runs on MSC_ConnHdlr {
4771 g_pars := f_gen_test_hdlr_pars();
4772 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4773 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4774 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4775 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4776 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4777 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4778 f_establish_fully(ass_cmd, exp_fail);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004779 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004780}
4781
4782/* Allow FR and HR, but prefer FR */
4783private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4784 g_pars := f_gen_test_hdlr_pars();
4785 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4786 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4787 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4788 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4789 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4790 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4791 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4792 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004793 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004794}
4795
4796/* Allow FR and HR, but prefer HR */
4797private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4798 g_pars := f_gen_test_hdlr_pars();
4799 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4800 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4801 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4802 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4803 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4804 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4805 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4806 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004807 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004808}
4809
4810/* Allow FR and HR, but prefer FR */
4811private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4812 g_pars := f_gen_test_hdlr_pars();
4813 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4814 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4815 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4816 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4817 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4818 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4819 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4820 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004821 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004822}
4823
4824/* Allow FR and HR, but prefer HR */
4825private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4826 g_pars := f_gen_test_hdlr_pars();
4827 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4828 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4829 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4830 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4831 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4832 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4833 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4834 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004835 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004836}
4837
4838/* Request a HR channel while all FR channels are exhausted, this is expected
4839 * to work without conflicts */
4840testcase TC_assignment_codec_fr_exhausted_req_hr() runs on test_CT {
4841 var MSC_ConnHdlr vc_conn;
4842 f_init(1, true);
4843 f_sleep(1.0);
4844 f_enable_all_tch();
4845 f_disable_all_tch_f();
4846 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr));
4847 vc_conn.done;
4848 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004849 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004850}
4851
4852/* Request a FR channel while all FR channels are exhausted, this is expected
4853 * to fail. */
4854testcase TC_assignment_codec_fr_exhausted_req_fr() runs on test_CT {
4855 var MSC_ConnHdlr vc_conn;
4856 f_init(1, true);
4857 f_sleep(1.0);
4858 f_enable_all_tch();
4859 f_disable_all_tch_f();
4860 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr_fail));
4861 vc_conn.done;
4862 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004863 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004864}
4865
4866/* Request a FR (prefered) or alternatively a HR channel while all FR channels
4867 * are exhausted, this is expected to be resolved by selecting a HR channel. */
4868testcase TC_assignment_codec_fr_exhausted_req_fr_hr() runs on test_CT {
4869 var MSC_ConnHdlr vc_conn;
4870 f_init(1, true);
4871 f_sleep(1.0);
4872 f_enable_all_tch();
4873 f_disable_all_tch_f();
4874 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
4875 vc_conn.done;
4876 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004877 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004878}
4879
4880/* Request a HR (prefered) or alternatively a FR channel while all FR channels
4881 * are exhausted, this is expected to work without conflicts. */
4882testcase TC_assignment_codec_fr_exhausted_req_hr_fr() runs on test_CT {
4883 var MSC_ConnHdlr vc_conn;
4884 f_init(1, true);
4885 f_sleep(1.0);
4886 f_enable_all_tch();
4887 f_disable_all_tch_f();
4888 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_hr_fr));
4889 vc_conn.done;
4890 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004891 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004892}
4893
4894/* Request a FR channel while all HR channels are exhausted, this is expected
4895 * to work without conflicts */
4896testcase TC_assignment_codec_hr_exhausted_req_fr() runs on test_CT {
4897 var MSC_ConnHdlr vc_conn;
4898 f_init(1, true);
4899 f_sleep(1.0);
4900 f_enable_all_tch();
4901 f_disable_all_tch_h();
4902 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr));
4903 vc_conn.done;
4904 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004905 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004906}
4907
4908/* Request a HR channel while all HR channels are exhausted, this is expected
4909 * to fail. */
4910testcase TC_assignment_codec_hr_exhausted_req_hr() runs on test_CT {
4911 var MSC_ConnHdlr vc_conn;
4912 f_init(1, true);
4913 f_sleep(1.0);
4914 f_enable_all_tch();
4915 f_disable_all_tch_h();
4916 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr_fail));
4917 vc_conn.done;
4918 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004919 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004920}
4921
4922/* Request a HR (prefered) or alternatively a FR channel while all HR channels
4923 * are exhausted, this is expected to be resolved by selecting a FR channel. */
4924testcase TC_assignment_codec_hr_exhausted_req_hr_fr() runs on test_CT {
4925 var MSC_ConnHdlr vc_conn;
4926 f_init(1, true);
4927 f_sleep(1.0);
4928 f_enable_all_tch();
4929 f_disable_all_tch_h();
4930 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_hr_fr));
4931 vc_conn.done;
4932 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004933 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004934}
4935
4936/* Request a FR (prefered) or alternatively a HR channel while all HR channels
4937 * are exhausted, this is expected to work without conflicts. */
4938testcase TC_assignment_codec_hr_exhausted_req_fr_hr() runs on test_CT {
4939 var MSC_ConnHdlr vc_conn;
4940 f_init(1, true);
4941 f_sleep(1.0);
4942 f_enable_all_tch();
4943 f_disable_all_tch_h();
4944 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_fr_hr));
4945 vc_conn.done;
4946 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004947 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004948}
4949
4950/* Allow FR and HR, but prefer HR */
4951private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4952 g_pars := f_gen_test_hdlr_pars();
4953 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4954 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4955 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4956 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4957 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4958 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4959 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4960 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004961 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004962}
4963
4964/* Allow FR and HR, but prefer FR */
4965private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4966 g_pars := f_gen_test_hdlr_pars();
4967 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4968 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4969 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4970 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4971 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4972 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4973 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4974 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004975 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004976}
4977
4978/* Request a HR (prefered) or alternatively a FR channel, it is expected that
4979 * HR, which is the prefered type, is selected. */
4980testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
4981 var MSC_ConnHdlr vc_conn;
4982 f_init(1, true);
4983 f_sleep(1.0);
4984 f_enable_all_tch();
4985 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
4986 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004987 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004988}
4989
4990/* Request a FR (prefered) or alternatively a HR channel, it is expected that
4991 * FR, which is the prefered type, is selected. */
4992testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
4993 var MSC_ConnHdlr vc_conn;
4994 f_init(1, true);
4995 f_sleep(1.0);
4996 f_enable_all_tch();
4997 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
4998 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004999 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01005000}
5001
Pau Espin Pedrol14475352021-07-22 15:48:16 +02005002/* request a signalling channel with all SDCCH exhausted, it is expected that a TCH will be selected */
5003private function f_TC_assignment_sdcch_exhausted_req_signalling(charstring id) runs on MSC_ConnHdlr {
5004 g_pars := f_gen_test_hdlr_pars();
5005 g_pars.ra := '02'O; /* RA containing reason=LU */
5006
5007 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
5008 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
5009 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
5010 var template uint3_t tsc := ?;
5011
5012 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
5013 f_create_bssmap_exp(l3_enc);
5014 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
5015 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, tsc);
5016
5017 /* we should now have a COMPL_L3 at the MSC */
5018 timer T := 10.0;
5019 T.start;
5020 alt {
5021 [] BSSAP.receive(tr_BSSMAP_ComplL3);
5022 [] T.timeout {
5023 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
5024 }
5025 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005026
5027 f_perform_clear();
Pau Espin Pedrol14475352021-07-22 15:48:16 +02005028}
5029testcase TC_assignment_sdcch_exhausted_req_signalling() runs on test_CT {
5030 var MSC_ConnHdlr vc_conn;
5031 f_init(1, true);
5032 f_sleep(1.0);
5033 f_disable_all_sdcch();
5034 vc_conn := f_start_handler(refers(f_TC_assignment_sdcch_exhausted_req_signalling));
5035 vc_conn.done;
5036 f_enable_all_sdcch();
5037 f_shutdown_helper();
5038}
5039
5040/* Request a signalling channel with all SDCCH exhausted, it is
5041 expected that no TCH will be selected for signalling and assigment will fail
5042 because it's dictated by VTY config */
5043testcase TC_assignment_sdcch_exhausted_req_signalling_tch_forbidden() runs on test_CT {
5044 var RSL_Message rsl_unused, rsl_msg;
5045 var GsmRrMessage rr;
5046 f_init(1, false);
5047 f_sleep(1.0);
5048 f_vty_allow_tch_for_signalling(false, 0);
5049 f_disable_all_sdcch();
5050
5051 /* RA containing reason=LU */
5052 f_ipa_tx(0, ts_RSL_CHAN_RQD('02'O, 2342));
5053 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
5054 rr := dec_GsmRrMessage(rsl_msg.ies[1].body.full_imm_ass_info.payload);
5055 if (rr.header.message_type != IMMEDIATE_ASSIGNMENT_REJECT) {
5056 setverdict(fail, "Expected reject");
5057 }
5058
5059 f_vty_allow_tch_for_signalling(true, 0);
5060 f_enable_all_sdcch();
5061 f_shutdown_helper();
5062}
5063
5064/* Request a voice channel with all SDCCH exhausted, it is
5065 * expected that TCH channel will be allocated since the VTY option is only
5066 * aimed at signalling requests */
5067private function f_TC_assignment_sdcch_exhausted_req_voice_tch_forbidden(charstring id) runs on MSC_ConnHdlr {
5068 g_pars := f_gen_test_hdlr_pars();
5069 g_pars.ra := '43'O; /* RA containing reason=originating speech call*/
5070
5071 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
5072 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
5073 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
5074 var template uint3_t tsc := ?;
5075
5076 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
5077 f_create_bssmap_exp(l3_enc);
5078 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
5079 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, tsc);
5080
5081 /* we should now have a COMPL_L3 at the MSC */
5082 timer T := 10.0;
5083 T.start;
5084 alt {
5085 [] BSSAP.receive(tr_BSSMAP_ComplL3);
5086 [] T.timeout {
5087 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
5088 }
5089 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005090 f_perform_clear();
Pau Espin Pedrol14475352021-07-22 15:48:16 +02005091}
5092testcase TC_assignment_sdcch_exhausted_req_voice_tch_forbidden() runs on test_CT {
5093 var MSC_ConnHdlr vc_conn;
5094 f_init(1, true);
5095 f_sleep(1.0);
5096 f_vty_allow_tch_for_signalling(false, 0);
5097 f_disable_all_sdcch();
5098
5099 vc_conn := f_start_handler(refers(f_TC_assignment_sdcch_exhausted_req_voice_tch_forbidden));
5100 vc_conn.done;
5101
5102 f_vty_allow_tch_for_signalling(true, 0);
5103 f_enable_all_sdcch();
5104 f_shutdown_helper();
5105}
5106
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005107testcase TC_assignment_osmux() runs on test_CT {
5108 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5109 var MSC_ConnHdlr vc_conn;
5110
5111 /* See note above */
5112 var RSL_IE_Body mr_conf := {
5113 other := {
5114 len := 2,
5115 payload := '2804'O
5116 }
5117 };
5118
5119 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
5120 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
5121 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
5122 pars.expect_mr_conf_ie := mr_conf;
5123 pars.use_osmux := true;
5124
5125 f_init(1, true, true);
5126 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00005127 f_vty_amr_start_mode_set(false, "1");
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005128
5129 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
5130 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00005131
5132 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01005133 f_shutdown_helper();
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005134}
5135
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02005136/* test the procedure of the MSC requesting a Classmark Update:
5137 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
5138 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01005139private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005140 g_pars := f_gen_test_hdlr_pars();
5141
Harald Weltea0630032018-03-20 21:09:55 +01005142 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01005143 /* we should now have a COMPL_L3 at the MSC */
Harald Welte898113b2018-01-31 18:32:21 +01005144
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02005145 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
5146 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
5147
Harald Welte898113b2018-01-31 18:32:21 +01005148 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
5149 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
5150 setverdict(pass);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005151
5152 f_perform_clear();
Harald Welte898113b2018-01-31 18:32:21 +01005153}
5154testcase TC_classmark() runs on test_CT {
5155 var MSC_ConnHdlr vc_conn;
5156 f_init(1, true);
5157 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005158 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01005159 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005160 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01005161}
5162
Harald Welteeddf0e92020-06-21 19:42:15 +02005163/* Send a CommonID from the simulated MSC and verify that the information is used to
5164 * fill BSC-internal data structures (specifically, bsc_subscr associated with subscr_conn) */
5165private function f_tc_common_id(charstring id) runs on MSC_ConnHdlr {
5166 g_pars := f_gen_test_hdlr_pars();
5167 f_MscConnHdlr_init_vty();
5168
5169 f_create_chan_and_exp();
5170 /* we should now have a COMPL_L3 at the MSC */
Harald Welteeddf0e92020-06-21 19:42:15 +02005171
5172 /* Send CommonID */
5173 BSSAP.send(ts_BSSMAP_CommonId(g_pars.imsi));
5174
5175 /* Use VTY to verify that the IMSI of the subscr_conn is set */
5176 var charstring regex := "*(IMSI: " & hex2str(g_pars.imsi) & ")*";
5177 f_vty_transceive_match_regexp_retry(BSCVTY, "show conns", regex, 0, 4, 1.0);
5178
5179 setverdict(pass);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005180
5181 f_perform_clear();
Harald Welteeddf0e92020-06-21 19:42:15 +02005182}
5183testcase TC_common_id() runs on test_CT {
5184 var MSC_ConnHdlr vc_conn;
5185 f_init(1, true);
5186 f_sleep(1.0);
5187 vc_conn := f_start_handler(refers(f_tc_common_id));
5188 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005189 f_shutdown_helper();
Harald Welteeddf0e92020-06-21 19:42:15 +02005190}
5191
Harald Weltee3bd6582018-01-31 22:51:25 +01005192private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005193 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01005194 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01005195 /* we should now have a COMPL_L3 at the MSC */
Harald Welte898113b2018-01-31 18:32:21 +01005196
Harald Weltee3bd6582018-01-31 22:51:25 +01005197 /* send the single message we want to send */
5198 f_rsl_send_l3(l3);
5199}
5200
5201private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
5202 timer T := sec;
5203 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01005204 T.start;
5205 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01005206 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
5207 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02005208 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01005209 }
5210 [] T.timeout {
5211 setverdict(pass);
5212 }
5213 }
5214}
5215
Harald Weltee3bd6582018-01-31 22:51:25 +01005216/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
5217private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
5218 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
5219 f_bssap_expect_nothing();
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005220 f_perform_clear();
Harald Weltee3bd6582018-01-31 22:51:25 +01005221}
Harald Welte898113b2018-01-31 18:32:21 +01005222testcase TC_unsol_ass_fail() runs on test_CT {
5223 var MSC_ConnHdlr vc_conn;
5224 f_init(1, true);
5225 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005226 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01005227 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005228 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01005229}
Harald Welte552620d2017-12-16 23:21:36 +01005230
Harald Welteea99a002018-01-31 20:46:43 +01005231
5232/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
5233private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01005234 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
5235 f_bssap_expect_nothing();
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005236 f_perform_clear();
Harald Welteea99a002018-01-31 20:46:43 +01005237}
5238testcase TC_unsol_ass_compl() runs on test_CT {
5239 var MSC_ConnHdlr vc_conn;
5240 f_init(1, true);
5241 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005242 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01005243 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005244 f_shutdown_helper();
Harald Welteea99a002018-01-31 20:46:43 +01005245}
5246
5247
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005248/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
5249private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01005250 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
5251 f_bssap_expect_nothing();
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005252 f_perform_clear();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005253}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005254testcase TC_unsol_ho_fail() runs on test_CT {
5255 var MSC_ConnHdlr vc_conn;
5256 f_init(1, true);
5257 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005258 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005259 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005260 f_shutdown_helper();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005261}
5262
5263
Harald Weltee3bd6582018-01-31 22:51:25 +01005264/* short message from MS should be ignored */
5265private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005266 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01005267 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01005268 /* we should now have a COMPL_L3 at the MSC */
Harald Weltee3bd6582018-01-31 22:51:25 +01005269
5270 /* send short message */
5271 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
5272 f_bssap_expect_nothing();
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005273 f_perform_clear();
Harald Weltee3bd6582018-01-31 22:51:25 +01005274}
5275testcase TC_err_82_short_msg() runs on test_CT {
5276 var MSC_ConnHdlr vc_conn;
5277 f_init(1, true);
5278 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005279 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01005280 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005281 f_shutdown_helper();
Harald Weltee3bd6582018-01-31 22:51:25 +01005282}
5283
5284
Harald Weltee9e02e42018-01-31 23:36:25 +01005285/* 24.008 8.4 Unknown message must trigger RR STATUS */
5286private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
5287 f_est_single_l3(ts_RRM_UL_REL('00'O));
5288 timer T := 3.0
5289 alt {
5290 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
5291 setverdict(pass);
5292 }
5293 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01005294 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01005295 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005296 f_perform_clear();
Harald Weltee9e02e42018-01-31 23:36:25 +01005297}
5298testcase TC_err_84_unknown_msg() runs on test_CT {
5299 var MSC_ConnHdlr vc_conn;
5300 f_init(1, true);
5301 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005302 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01005303 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005304 f_shutdown_helper();
Harald Weltee9e02e42018-01-31 23:36:25 +01005305}
5306
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005307/***********************************************************************
5308 * Handover
5309 ***********************************************************************/
5310
Harald Welte94e0c342018-04-07 11:33:23 +02005311/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
5312private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
5313runs on test_CT {
5314 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
5315 " timeslot "&int2str(ts_nr)&" ";
5316 f_vty_transceive(BSCVTY, cmd & suffix);
5317}
5318
Harald Welte261af4b2018-02-12 21:20:39 +01005319/* 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 +07005320private function f_vty_ss_action(TELNETasp_PT pt, charstring suffix,
5321 uint8_t bts_nr, uint8_t trx_nr,
5322 in RslChannelNr chan_nr)
5323{
Harald Welte261af4b2018-02-12 21:20:39 +01005324 /* FIXME: resolve those from component-global state */
5325 var integer ts_nr := chan_nr.tn;
5326 var integer ss_nr;
5327 if (ischosen(chan_nr.u.ch0)) {
5328 ss_nr := 0;
5329 } else if (ischosen(chan_nr.u.lm)) {
5330 ss_nr := chan_nr.u.lm.sub_chan;
5331 } else if (ischosen(chan_nr.u.sdcch4)) {
5332 ss_nr := chan_nr.u.sdcch4.sub_chan;
5333 } else if (ischosen(chan_nr.u.sdcch8)) {
5334 ss_nr := chan_nr.u.sdcch8.sub_chan;
5335 } else {
5336 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02005337 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01005338 }
5339
5340 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
5341 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005342 f_vty_transceive(pt, cmd & suffix);
Harald Welte261af4b2018-02-12 21:20:39 +01005343}
5344
Neels Hofmeyr91401012019-07-11 00:42:35 +02005345/* Even though the VTY command to trigger handover takes a new BTS number as argument, behind the scenes osmo-bsc always
5346 * translates that to a target ARFCN+BSIC first. See bsc_vty.c trigger_ho_or_as(), which puts the selected BTS' neighbor
5347 * ident key (ARFCN + BSIC) in the struct passed on to handover_request(). handover_start() then resolves that to a
5348 * viable actual neighbor cell. So from the internal osmo-bsc perspective, we always request handover to an ARFCN + BSIC
5349 * pair, not really to a specific BTS number. */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005350private function f_vty_handover(TELNETasp_PT pt, uint8_t bts_nr, uint8_t trx_nr,
5351 in RslChannelNr chan_nr, uint8_t new_bts_nr)
5352{
5353 f_vty_ss_action(pt, "handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
Harald Welte261af4b2018-02-12 21:20:39 +01005354}
5355
5356/* intra-BSC hand-over between BTS0 and BTS1 */
5357private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02005358 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5359 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01005360
5361 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5362 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5363
Harald Weltea0630032018-03-20 21:09:55 +01005364 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005365 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Harald Welte261af4b2018-02-12 21:20:39 +01005366
5367 var HandoverState hs := {
5368 rr_ho_cmpl_seen := false,
5369 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02005370 old_chan_nr := -,
5371 expect_target_tsc := BTS_TSC[1]
Harald Welte261af4b2018-02-12 21:20:39 +01005372 };
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005373 /* issue hand-over command on VTY, from BTS 0 to BTS 1 */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005374 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
Harald Welte261af4b2018-02-12 21:20:39 +01005375 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
5376 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005377
5378 /* From the MGW perspective, a handover is is characterized by
5379 * performing one MDCX operation with the MGW. So we expect to see
5380 * one more MDCX during handover. */
5381 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
5382
Harald Welte261af4b2018-02-12 21:20:39 +01005383 alt {
5384 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01005385 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005386
Philipp Maier4dae0652018-11-12 12:03:26 +01005387 /* Since this is an internal handover we expect the BSC to inform the
5388 * MSC about the event */
5389 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
5390
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005391 /* Check the amount of MGCP transactions is still consistant with the
5392 * test expectation */
5393 f_check_mgcp_expectations()
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005394
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005395 var RSL_Message chan_act := f_rslem_get_last_act(RSL1_PROC, 0, g_chan_nr);
5396
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005397 /* Ensure the Channel Activation for the new channel contained the right encryption params. as_handover() set
5398 * 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 +02005399 f_verify_encr_info(chan_act);
5400
5401 f_chan_act_verify_tsc(chan_act, BTS_TSC[1]);
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005402
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005403 f_perform_clear(RSL1, RSL1_PROC);
5404
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01005405 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01005406}
5407
5408testcase TC_ho_int() runs on test_CT {
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02005409 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte261af4b2018-02-12 21:20:39 +01005410 var MSC_ConnHdlr vc_conn;
5411 f_init(2, true);
5412 f_sleep(1.0);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005413
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005414 pars.expect_tsc := BTS_TSC[0];
5415
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005416 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005417
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02005418 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
Harald Welte261af4b2018-02-12 21:20:39 +01005419 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005420
5421 /* from f_establish_fully() */
5422 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5423 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5424 /* from handover */
5425 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5426 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5427 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5428 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005429 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5430 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:completed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005431 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005432 f_shutdown_helper();
Harald Welte261af4b2018-02-12 21:20:39 +01005433}
Harald Weltee9e02e42018-01-31 23:36:25 +01005434
Oliver Smith7eabd312021-07-12 14:18:56 +02005435function 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 +02005436 var MSC_ConnHdlr vc_conn;
5437 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5438 pars.encr := valueof(t_EncrParams(encr_alg, f_rnd_octstring(8), f_rnd_octstring(16)));
5439
5440 f_init(2, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02005441 f_vty_encryption_a5(enc_a5);
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005442 f_sleep(1.0);
5443
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005444 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005445
5446 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
5447 vc_conn.done;
5448
5449 /* from f_establish_fully() */
5450 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5451 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5452 /* from handover */
5453 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5454 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5455 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5456 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005457 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5458 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:completed");
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005459 f_ctrs_bsc_and_bts_verify();
Oliver Smith7eabd312021-07-12 14:18:56 +02005460 f_vty_encryption_a5_reset();
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005461 f_shutdown_helper();
5462}
5463
5464testcase TC_ho_int_a5_0() runs on test_CT {
5465 f_tc_ho_int_a5('01'O);
5466}
5467
5468testcase TC_ho_int_a5_1() runs on test_CT {
5469 f_tc_ho_int_a5('02'O);
5470}
5471
5472testcase TC_ho_int_a5_3() runs on test_CT {
5473 f_tc_ho_int_a5('08'O);
5474}
5475
5476testcase TC_ho_int_a5_4() runs on test_CT {
Oliver Smith7eabd312021-07-12 14:18:56 +02005477 f_tc_ho_int_a5('10'O, "0 1 3 4");
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005478}
5479
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005480/* intra-BSC hand-over with CONNection FAILure and cause Radio Link Failure: check RR release cause */
5481private function f_tc_ho_int_radio_link_failure(charstring id) runs on MSC_ConnHdlr {
5482 g_pars := f_gen_test_hdlr_pars();
5483 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5484 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005485
5486 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5487 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5488
5489 f_establish_fully(ass_cmd, exp_compl);
5490 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
5491
5492 var HandoverState hs := {
5493 rr_ho_cmpl_seen := false,
5494 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02005495 old_chan_nr := -,
5496 expect_target_tsc := BTS_TSC[1]
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005497 };
5498 /* issue hand-over command on VTY */
5499 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
5500 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
5501 f_rslem_suspend(RSL1_PROC);
5502
5503 /* From the MGW perspective, a handover is is characterized by
5504 * performing one MDCX operation with the MGW. So we expect to see
5505 * one more MDCX during handover. */
5506 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
5507
5508 var RSL_Message rsl;
5509 var PDU_ML3_NW_MS l3;
5510 var RslChannelNr new_chan_nr;
5511 var GsmArfcn arfcn;
5512 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
5513 l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
5514 if (not ischosen(l3.msgs.rrm.handoverCommand)) {
5515 setverdict(fail, "Expected handoverCommand");
5516 mtc.stop;
5517 }
5518 }
5519 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
5520 new_chan_nr, arfcn);
5521
5522 f_rslem_register(0, new_chan_nr, RSL1_PROC);
5523
5524 /* resume processing of RSL DChan messages, which was temporarily suspended
5525 * before performing a hand-over */
5526 f_rslem_resume(RSL1_PROC);
5527 RSL1.receive(tr_RSL_IPA_CRCX(new_chan_nr));
5528
5529 f_sleep(1.0);
5530
5531 /* Handover fails because no HANDO DET appears on the new lchan,
5532 * and the old lchan reports a Radio Link Failure. */
5533 RSL.send(ts_RSL_CONN_FAIL_IND(g_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
5534
5535 var PDU_BSSAP rx_clear_request;
5536 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
5537 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5538 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5539
5540 var RR_Cause rr_cause := GSM48_RR_CAUSE_ABNORMAL_UNSPEC;
5541
5542 var MgcpCommand mgcp;
5543 interleave {
5544 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE(int2oct(enum2int(rr_cause), 1)))) {}
5545 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005546 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005547 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005548 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005549 }
5550 [] RSL1.receive(tr_RSL_DEACT_SACCH(new_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005551 [] RSL1.receive(tr_RSL_RF_CHAN_REL(new_chan_nr)) {
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005552 RSL1.send(ts_RSL_RF_CHAN_REL_ACK(new_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005553 f_rslem_unregister(0, g_chan_nr, PT := RSL1_PROC);
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005554 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005555 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
5556 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
5557 }
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005558 }
5559
5560 f_sleep(0.5);
5561 setverdict(pass);
5562}
5563testcase TC_ho_int_radio_link_failure() runs on test_CT {
5564 var MSC_ConnHdlr vc_conn;
5565 f_init(2, true);
5566 f_sleep(1.0);
5567
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005568 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005569
5570 vc_conn := f_start_handler(refers(f_tc_ho_int_radio_link_failure));
5571 vc_conn.done;
5572
5573 /* from f_establish_fully() */
5574 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5575 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5576 /* from handover */
5577 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5578 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
5579 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5580 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:stopped");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005581 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5582 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:stopped");
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005583 f_ctrs_bsc_and_bts_verify();
5584 f_shutdown_helper();
5585}
5586
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005587/* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005588private function f_expect_dlcx_conns() runs on MSC_ConnHdlr {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005589 var MgcpCommand mgcp;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005590 var template MgcpResponse mgcp_resp;
5591 var MGCP_RecvFrom mrf;
5592 var template MgcpMessage msg_resp;
5593 var template MgcpMessage msg_dlcx := {
5594 command := tr_DLCX()
5595 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005596
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005597 if (g_pars.aoip) {
5598 MGCP.receive(tr_DLCX()) -> value mgcp {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005599 log("Got first DLCX: ", mgcp);
5600 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005601 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005602
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005603 MGCP.receive(tr_DLCX()) -> value mgcp {
5604 log("Got second DLCX: ", mgcp);
5605 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
5606 };
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005607 } else {
5608 /* For SCCPLite, BSC doesn't handle the MSC-side */
5609 MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_dlcx)) -> value mrf {
5610 log("Got first DLCX: ", mrf.msg.command);
5611 msg_resp := {
5612 response := ts_DLCX_ACK2(mrf.msg.command.line.trans_id)
5613 }
5614 MGCP_MULTI.send(t_MGCP_SendToMrf(mrf, msg_resp));
5615 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005616 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005617}
5618
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005619private 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 +01005620
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005621 var NcellReports neighbor_rep := {
5622 { rxlev := 20, bcch_freq := 0, bsic := 11 }
5623 };
5624 var octetstring l3_mr := enc_GsmRrL3Message(valueof(ts_MEAS_REP(true, 8, 8, reps := neighbor_rep)));
5625 RSL.send(ts_RSL_MEAS_RES(g_chan_nr, 0, ts_RSL_IE_UplinkMeas, ts_RSL_IE_BS_Power(0), ts_RSL_IE_L1Info,
5626 l3_mr, 0));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005627
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005628 BSSAP.receive(tr_BSSMAP_HandoverRequired(exp_oldToNewBSSIEs));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005629
5630 f_sleep(0.5);
5631 /* The MSC negotiates Handover Request and Handover Request Ack with
5632 * the other BSS and comes back with a BSSMAP Handover Command
5633 * containing an RR Handover Command coming from the target BSS... */
5634
5635 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5636 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5637 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5638 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5639 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5640
5641 /* expect the Handover Command to go out on RR */
5642 var RSL_Message rsl_ho_cmd
5643 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5644 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5645 var RSL_IE_Body rsl_ho_cmd_l3;
5646 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5647 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5648 setverdict(fail);
5649 } else {
5650 log("Found L3 Info: ", rsl_ho_cmd_l3);
5651 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5652 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5653 setverdict(fail);
5654 } else {
5655 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5656 setverdict(pass);
5657 }
5658 }
5659
5660 /* When the other BSS has reported a completed handover, this side is
5661 * torn down. */
5662
5663 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
5664 var BssmapCause cause := enum2int(cause_val);
5665 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5666
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005667 f_expect_dlcx_conns();
Pau Espin Pedrol06199952021-06-15 11:30:00 +02005668
5669 interleave {
5670 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE));
5671 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr));
5672 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr));
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005673 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
5674 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
5675 }
Pau Espin Pedrol06199952021-06-15 11:30:00 +02005676 }
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005677 setverdict(pass);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005678}
5679
5680private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
5681 g_pars := f_gen_test_hdlr_pars();
5682 var PDU_BSSAP ass_req := f_gen_ass_req();
5683 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5684 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5685 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5686 f_establish_fully(ass_req, exp_compl);
5687
5688 f_ho_out_of_this_bsc();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005689}
5690testcase TC_ho_out_of_this_bsc() runs on test_CT {
5691 var MSC_ConnHdlr vc_conn;
5692
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005693 f_init_vty();
5694 f_bts_0_cfg(BSCVTY,
5695 {"neighbor-list mode automatic",
5696 "handover 1",
5697 "handover algorithm 2",
5698 "handover2 window rxlev averaging 1",
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005699 "no neighbors",
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005700 "neighbor lac 99 arfcn 123 bsic any"});
5701 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5702
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005703 f_init(1, true);
5704 f_sleep(1.0);
5705
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005706 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005707
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005708 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
5709 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005710
5711 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5712 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5713 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5714 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5715 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5716 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed");
5717 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005718 f_shutdown_helper();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005719}
5720
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005721private function f_mo_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5722 template (value) RslLinkId link_id := ts_RslLinkID_DCCH(0),
Vadim Yanitskiy2ef6a2f2020-10-08 23:17:32 +07005723 template (present) OCT1 dlci := ?,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005724 octetstring l3 := '0123456789'O)
5725runs on MSC_ConnHdlr {
Neels Hofmeyr43654812020-09-25 01:35:35 +02005726 /* The old lchan and conn should still be active. See that arbitrary L3
5727 * is still going through. */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005728 rsl.send(ts_RSL_DATA_IND(g_chan_nr, link_id, l3));
Neels Hofmeyr43654812020-09-25 01:35:35 +02005729 var template PDU_BSSAP exp_data := {
5730 discriminator := '1'B,
5731 spare := '0000000'B,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005732 dlci := dlci,
5733 lengthIndicator := lengthof(l3),
Neels Hofmeyr43654812020-09-25 01:35:35 +02005734 pdu := {
5735 dtap := l3
5736 }
5737 };
5738 BSSAP.receive(exp_data);
5739 setverdict(pass);
5740}
5741
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005742private function f_mt_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5743 template (present) RslLinkId link_id := tr_RslLinkID_DCCH(0),
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005744 template (value) OCT1 dlci := '00'O,
5745 octetstring l3 := '0123456789'O)
5746runs on MSC_ConnHdlr {
5747 BSSAP.send(PDU_BSSAP:{
5748 discriminator := '1'B,
5749 spare := '0000000'B,
5750 dlci := dlci,
5751 lengthIndicator := lengthof(l3),
5752 pdu := {
5753 dtap := l3
5754 }
5755 });
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005756 rsl.receive(tr_RSL_DATA_REQ(g_chan_nr, link_id, l3));
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005757 setverdict(pass);
5758}
5759
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005760/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
5761 * simply never sends a BSSMAP Handover Command. */
5762private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005763 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005764
5765 var PDU_BSSAP ass_req := f_gen_ass_req();
5766 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5767 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5768 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5769 f_establish_fully(ass_req, exp_compl);
5770
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005771 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005772 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5773
5774 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5775
5776 /* osmo-bsc should time out 10 seconds after the handover started.
5777 * Let's give it a bit extra. */
5778 f_sleep(15.0);
5779
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005780 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005781 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005782 f_perform_clear();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005783}
5784testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
5785 var MSC_ConnHdlr vc_conn;
5786
5787 f_init(1, true);
5788 f_sleep(1.0);
5789
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005790 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005791
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005792 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
5793 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005794
5795 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5796 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5797 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5798 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5799 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5800 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5801 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005802 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005803}
5804
5805/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
5806 * RR Handover Failure. */
5807private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005808 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005809
5810 var PDU_BSSAP ass_req := f_gen_ass_req();
5811 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5812 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5813 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5814 f_establish_fully(ass_req, exp_compl);
5815
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005816 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005817 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5818
5819 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5820
5821 f_sleep(0.5);
5822 /* The MSC negotiates Handover Request and Handover Request Ack with
5823 * the other BSS and comes back with a BSSMAP Handover Command
5824 * containing an RR Handover Command coming from the target BSS... */
5825
5826 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5827 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5828 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5829 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5830 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5831
5832 /* expect the Handover Command to go out on RR */
5833 var RSL_Message rsl_ho_cmd
5834 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5835 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5836 var RSL_IE_Body rsl_ho_cmd_l3;
5837 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5838 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5839 setverdict(fail);
5840 } else {
5841 log("Found L3 Info: ", rsl_ho_cmd_l3);
5842 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5843 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5844 setverdict(fail);
5845 } else {
5846 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5847 setverdict(pass);
5848 }
5849 }
5850
5851 f_sleep(0.2);
5852 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
5853
5854 /* Should tell the MSC about the failure */
5855 BSSAP.receive(tr_BSSMAP_HandoverFailure);
5856
5857 f_sleep(1.0);
5858
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005859 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005860 f_sleep(1.0);
5861
5862 setverdict(pass);
5863 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005864 f_perform_clear();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005865}
5866testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
5867 var MSC_ConnHdlr vc_conn;
5868
5869 f_init(1, true);
5870 f_sleep(1.0);
5871
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005872 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005873
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005874 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
5875 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005876
5877 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5878 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5879 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5880 f_ctrs_bsc_and_bts_add(0, "handover:failed");
5881 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5882 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:failed");
5883 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005884 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005885}
5886
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005887/* BSC asks for inter-BSC-out HO, receives BSSMAP Handover Command, but then no reply is received about HO outcome
5888 * (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 +02005889 * and the lchan is released. */
5890private function f_tc_ho_out_fail_no_result_after_ho_cmd(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005891 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005892
5893 var PDU_BSSAP ass_req := f_gen_ass_req();
5894 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5895 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5896 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5897 f_establish_fully(ass_req, exp_compl);
5898
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005899 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005900 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5901
5902 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5903
5904 f_sleep(0.5);
5905 /* The MSC negotiates Handover Request and Handover Request Ack with
5906 * the other BSS and comes back with a BSSMAP Handover Command
5907 * containing an RR Handover Command coming from the target BSS... */
5908
5909 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5910 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5911 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5912 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5913 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5914
5915 /* expect the Handover Command to go out on RR */
5916 var RSL_Message rsl_ho_cmd
5917 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5918 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5919 var RSL_IE_Body rsl_ho_cmd_l3;
5920 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5921 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5922 setverdict(fail);
5923 } else {
5924 log("Found L3 Info: ", rsl_ho_cmd_l3);
5925 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5926 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5927 setverdict(fail);
5928 } else {
5929 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5930 setverdict(pass);
5931 }
5932 }
5933
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005934 /* We get neither success nor failure report from the remote BSS. Eventually T8 times out and we run into 3GPP
5935 * TS 48.008 3.1.5.3.3 "Abnormal Conditions": Clear Request should go to the MSC, and RR should be released
5936 * after Clear Command */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005937
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005938 var PDU_BSSAP rx_clear_request;
Neels Hofmeyre1797aa2019-07-09 19:34:04 +02005939 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
5940 log("Got BSSMAP Clear Request");
5941 /* Instruct BSC to clear channel */
5942 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5943 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5944
5945 var MgcpCommand mgcp;
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005946 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01005947 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
5948 log("Got Deact SACCH");
5949 }
Harald Welte924b6ea2019-02-04 01:05:34 +01005950 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01005951 log("Got RR Release");
5952 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005953 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005954 log("Got RF Chan Rel");
5955 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005956 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005957 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005958 }
5959
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005960 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02005961 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005962 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005963
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005964 setverdict(pass);
5965 f_sleep(1.0);
5966}
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02005967testcase TC_ho_out_fail_no_result_after_ho_cmd() runs on test_CT {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005968 var MSC_ConnHdlr vc_conn;
5969
5970 f_init(1, true);
5971 f_sleep(1.0);
5972
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005973 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005974
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02005975 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_result_after_ho_cmd));
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005976 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005977
5978 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5979 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5980 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5981 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5982 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5983 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5984 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005985 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005986}
5987
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005988private 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 +01005989 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
5990 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
5991 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
5992 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
5993 * before we get started. */
5994 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
5995 f_rslem_register(0, new_chan_nr);
5996 g_chan_nr := new_chan_nr;
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02005997 var uint3_t expect_target_tsc := BTS_TSC[0];
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005998 f_sleep(1.0);
5999
6000 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6001 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6002 activate(as_Media());
6003
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006004 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006005 f_gen_handover_req(aoip_tla := g_pars.host_aoip_tla,
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006006 oldToNewBSSIEs := oldToNewBSSIEs,
6007 enc := g_pars.encr)));
Harald Welte6811d102019-04-14 22:23:14 +02006008 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006009
6010 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6011
6012 var PDU_BSSAP rx_bssap;
6013 var octetstring ho_command_str;
6014
6015 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
Pau Espin Pedrol76ba5412019-06-10 11:00:33 +02006016
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02006017 /* we're sure that the channel activation is done now, verify the parameters in it */
6018 var RSL_Message chan_act := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
6019 f_verify_encr_info(chan_act);
6020 f_chan_act_verify_tsc(chan_act, expect_target_tsc);
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006021
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006022 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6023 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6024 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6025 log("L3 Info in HO Request Ack is ", ho_command);
6026
6027 var GsmArfcn arfcn;
6028 var RslChannelNr actual_new_chan_nr;
6029 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6030 actual_new_chan_nr, arfcn);
6031
6032 if (actual_new_chan_nr != new_chan_nr) {
6033 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6034 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6035 setverdict(fail);
6036 return;
6037 }
6038 log("Handover Command chan_nr is", actual_new_chan_nr);
6039
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02006040 var uint3_t got_tsc := rr_chan_desc_tsc(ho_command.msgs.rrm.handoverCommand.channelDescription2);
6041 if (not match(got_tsc, expect_target_tsc)) {
6042 setverdict(fail, "RR Handover Command: unexpected TSC in Channel Description: expected ",
6043 expect_target_tsc, " got ", got_tsc);
6044 mtc.stop;
6045 } else {
6046 log("handoverCommand: verified TSC = ", got_tsc);
6047 }
6048
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006049 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6050 * tells the MS to handover to the new lchan. Here comes the new MS on
6051 * the new lchan with a Handover RACH: */
6052
6053 /* send handover detect */
6054
6055 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
6056
6057 BSSAP.receive(tr_BSSMAP_HandoverDetect);
6058
6059 /* send handover complete over the new channel */
6060
6061 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
6062 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
6063 enc_PDU_ML3_MS_NW(l3_tx)));
6064
6065 BSSAP.receive(tr_BSSMAP_HandoverComplete);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006066 setverdict(pass);
6067}
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006068
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006069private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006070 var template PDU_ML3_NW_MS exp_rr_rel_tmpl;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006071 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit;
6072 if (not istemplatekind(g_pars.last_used_eutran_plmn, "omit")) {
6073 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006074 }
6075 if (g_pars.exp_fast_return) {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006076 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE_CellSelectInd;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006077 } else {
6078 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006079 }
6080 f_ho_into_this_bsc(id, oldToNewBSSIEs);
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02006081 f_perform_clear(exp_rr_rel_tmpl := exp_rr_rel_tmpl);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006082 setverdict(pass);
6083}
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006084function f_tc_ho_into_this_bsc_main(TestHdlrParams pars) runs on test_CT {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006085 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006086
6087 f_init(1, true);
6088 f_sleep(1.0);
6089
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006090 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006091
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006092 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6093 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006094
6095 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
6096 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006097
6098 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6099 f_ctrs_bsc_and_bts_add(0, "handover:completed");
6100 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6101 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed");
6102 f_ctrs_bsc_and_bts_verify();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006103}
6104
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006105testcase TC_ho_into_this_bsc() runs on test_CT {
6106 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6107 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006108 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006109}
6110
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01006111function f_tc_ho_into_this_bsc_a5(TestHdlrEncrParams encr) runs on test_CT {
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006112 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01006113 pars.encr := encr;
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006114 f_tc_ho_into_this_bsc_main(pars);
6115 f_shutdown_helper();
6116}
6117
6118testcase TC_ho_into_this_bsc_a5_0() runs on test_CT {
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01006119 f_tc_ho_into_this_bsc_a5(f_encr_params('01'O));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006120}
6121
6122testcase TC_ho_into_this_bsc_a5_1() runs on test_CT {
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01006123 f_tc_ho_into_this_bsc_a5(f_encr_params('02'O));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006124}
6125
6126testcase TC_ho_into_this_bsc_a5_3() runs on test_CT {
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01006127 f_tc_ho_into_this_bsc_a5(f_encr_params('08'O));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006128}
6129
6130testcase TC_ho_into_this_bsc_a5_4() runs on test_CT {
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01006131 f_tc_ho_into_this_bsc_a5(f_encr_params('10'O));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006132}
6133
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006134testcase TC_ho_into_this_bsc_tla_v6() runs on test_CT {
6135 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6136 pars.host_aoip_tla := "::6";
6137 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006138 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006139}
6140
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006141/* Similar to TC_ho_into_this_bsc, but when in SRVCC, HO Req contains "Old BSS
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006142 to New BSS Information" IE with "Last Used E-UTRAN PLMN Id", which, when the
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006143 channel is later released (RR CHannel Release), should trigger inclusion of
6144 IE "Cell Selection Indicator after Release of all TCH and SDCCH" with E-UTRAN
6145 neighbors. */
6146testcase TC_srvcc_eutran_to_geran() runs on test_CT {
6147 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6148 pars.last_used_eutran_plmn := '323454'O;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006149 pars.exp_fast_return := true;
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006150 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02006151
6152 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted");
6153 f_ctrs_bsc_and_bts_add(0, "srvcc:completed");
6154 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006155 f_shutdown_helper();
6156}
6157
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006158/* Same as TC_srvcc_eutran_to_geran, but test explicitly forbiding fast return
6159 on the BTS. As a result, RR Release shouldn't contain the EUTRAN neighbor
6160 list when the channel is released. */
6161testcase TC_srvcc_eutran_to_geran_forbid_fast_return() runs on test_CT {
6162 f_init_vty();
6163 f_vty_allow_srvcc_fast_return(true, 0)
6164
6165 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6166 pars.last_used_eutran_plmn := '323454'O;
6167 pars.exp_fast_return := false;
6168 f_tc_ho_into_this_bsc_main(pars);
6169 f_vty_allow_srvcc_fast_return(false, 0);
6170 f_shutdown_helper();
6171}
6172
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006173private function f_tc_srvcc_eutran_to_geran_ho_out(charstring id) runs on MSC_ConnHdlr {
6174 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs;
6175 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
6176 f_ho_into_this_bsc(id, oldToNewBSSIEs);
6177 f_ho_out_of_this_bsc(oldToNewBSSIEs);
6178 setverdict(pass);
6179}
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006180
6181private function f_tc_srvcc_eutran_to_geran_ho_out_main(boolean disable_fast_return)
6182 runs on test_CT {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006183 var MSC_ConnHdlr vc_conn;
6184 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6185
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01006186 f_init_vty();
6187 f_bts_0_cfg(BSCVTY,
6188 {"neighbor-list mode automatic",
6189 "handover 1",
6190 "handover algorithm 2",
6191 "handover2 window rxlev averaging 1",
6192 "no neighbors",
6193 "neighbor lac 99 arfcn 123 bsic any"});
6194 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6195
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006196 f_init(1, true);
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006197 if (disable_fast_return) {
6198 f_vty_allow_srvcc_fast_return(true, 0);
6199 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006200 f_sleep(1.0);
6201
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006202 f_ctrs_bsc_and_bts_handover_init();
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006203
6204 pars.last_used_eutran_plmn := '323454'O;
6205 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6206 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
6207
6208 vc_conn := f_start_handler(refers(f_tc_srvcc_eutran_to_geran_ho_out), pars);
6209 vc_conn.done;
6210
6211 f_ctrs_bsc_and_bts_add(0, "handover:attempted", 2);
6212 f_ctrs_bsc_and_bts_add(0, "handover:completed", 2);
6213 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted", 1);
6214 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed", 1);
6215 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted", 1);
6216 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed", 1);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02006217
6218 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted", 1);
6219 f_ctrs_bsc_and_bts_add(0, "srvcc:completed", 1);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006220 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006221
6222 if (disable_fast_return) {
6223 f_vty_allow_srvcc_fast_return(false, 0);
6224 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006225 f_shutdown_helper();
6226}
6227
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006228/* First, HO into BSC from EUTRAN (SRVCC): HO Request contains "Old BSS to New
6229 BSS Information" IE with "Last Used E-UTRAN PLMN Id".
6230 Second, HO to another BSC: HO Required contains "Old BSS to New BSS Information"
6231 IE with "Last Used E-UTRAN PLMN Id" from first step. */
6232testcase TC_srvcc_eutran_to_geran_ho_out() runs on test_CT {
6233 f_tc_srvcc_eutran_to_geran_ho_out_main(false);
6234}
6235/* Validate subsequent intra-GSM-HO works the same (with OldBSSToNewBSSInfo IE)
6236 * independently of fast-reture allowed/forbidden in local BTS */
6237testcase TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() runs on test_CT {
6238 f_tc_srvcc_eutran_to_geran_ho_out_main(true);
6239}
6240
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006241private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
6242 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6243 f_rslem_register(0, new_chan_nr);
6244 g_chan_nr := new_chan_nr;
6245 f_sleep(1.0);
6246
6247 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6248 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6249 activate(as_Media());
6250
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006251 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006252 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006253 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006254
6255 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6256
6257 var PDU_BSSAP rx_bssap;
6258 var octetstring ho_command_str;
6259
6260 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6261
6262 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6263 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6264 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6265 log("L3 Info in HO Request Ack is ", ho_command);
6266
6267 var GsmArfcn arfcn;
6268 var RslChannelNr actual_new_chan_nr;
6269 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6270 actual_new_chan_nr, arfcn);
6271
6272 if (actual_new_chan_nr != new_chan_nr) {
6273 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6274 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6275 setverdict(fail);
6276 return;
6277 }
6278 log("Handover Command chan_nr is", actual_new_chan_nr);
6279
Neels Hofmeyr61ca08d2019-05-06 23:52:22 +02006280 /* For deterministic test results, give some time for the MGW endpoint to be configured */
6281 f_sleep(1.0);
6282
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006283 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6284 * tells the MS to handover to the new lchan. In this case, the MS
6285 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
6286 * Handover Failure to the MSC. The procedure according to 3GPP TS
6287 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
6288 * BSSMAP Clear Command: */
6289
6290 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6291 var BssmapCause cause := enum2int(cause_val);
6292 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6293
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006294 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006295 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006296 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006297
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006298 setverdict(pass);
6299 f_sleep(1.0);
6300
6301 setverdict(pass);
6302}
6303testcase TC_ho_in_fail_msc_clears() runs on test_CT {
6304 var MSC_ConnHdlr vc_conn;
6305 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6306
6307 f_init(1, true);
6308 f_sleep(1.0);
6309
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006310 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006311
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006312 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6313 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006314
6315 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
6316 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006317
6318 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6319 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
6320 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6321 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
6322 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006323 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006324}
6325
6326private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
6327 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
6328 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
6329 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
6330 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
6331 * before we get started. */
6332 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6333 f_rslem_register(0, new_chan_nr);
6334 g_chan_nr := new_chan_nr;
6335 f_sleep(1.0);
6336
6337 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6338 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6339 activate(as_Media());
6340
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006341 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006342 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006343 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006344
6345 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6346
6347 var PDU_BSSAP rx_bssap;
6348 var octetstring ho_command_str;
6349
6350 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6351
6352 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6353 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6354 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6355 log("L3 Info in HO Request Ack is ", ho_command);
6356
6357 var GsmArfcn arfcn;
6358 var RslChannelNr actual_new_chan_nr;
6359 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6360 actual_new_chan_nr, arfcn);
6361
6362 if (actual_new_chan_nr != new_chan_nr) {
6363 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6364 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6365 setverdict(fail);
6366 return;
6367 }
6368 log("Handover Command chan_nr is", actual_new_chan_nr);
6369
6370 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6371 * tells the MS to handover to the new lchan. Here comes the new MS on
6372 * the new lchan with a Handover RACH: */
6373
6374 /* send handover detect */
6375
6376 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
6377
6378 BSSAP.receive(tr_BSSMAP_HandoverDetect);
6379
6380 /* The MSC chooses to clear the connection now, maybe we got the
6381 * Handover RACH on the new cell but the MS still signaled Handover
6382 * Failure to the old BSS? */
6383
6384 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6385 var BssmapCause cause := enum2int(cause_val);
6386 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6387
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006388 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006389 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006390 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006391
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006392 f_sleep(1.0);
6393}
6394testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
6395 var MSC_ConnHdlr vc_conn;
6396 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6397
6398 f_init(1, true);
6399 f_sleep(1.0);
6400
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006401 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006402
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006403 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6404 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006405
6406 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
6407 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006408
6409 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6410 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
6411 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6412 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
6413 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006414 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006415}
6416
6417/* The new BSS's lchan times out before the MSC decides that handover failed. */
6418private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
6419 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6420 f_rslem_register(0, new_chan_nr);
6421 g_chan_nr := new_chan_nr;
6422 f_sleep(1.0);
6423
6424 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6425 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6426 activate(as_Media());
6427
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006428 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006429 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006430 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006431
6432 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6433
6434 var PDU_BSSAP rx_bssap;
6435 var octetstring ho_command_str;
6436
6437 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6438
6439 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6440 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6441 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6442 log("L3 Info in HO Request Ack is ", ho_command);
6443
6444 var GsmArfcn arfcn;
6445 var RslChannelNr actual_new_chan_nr;
6446 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6447 actual_new_chan_nr, arfcn);
6448
6449 if (actual_new_chan_nr != new_chan_nr) {
6450 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6451 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6452 setverdict(fail);
6453 return;
6454 }
6455 log("Handover Command chan_nr is", actual_new_chan_nr);
6456
6457 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6458 * tells the MS to handover to the new lchan. But the MS never shows up
6459 * on the new lchan. */
6460
6461 BSSAP.receive(tr_BSSMAP_HandoverFailure);
6462
6463 /* Did osmo-bsc also send a Clear Request? */
6464 timer T := 0.5;
6465 T.start;
6466 alt {
6467 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
6468 [] T.timeout { }
6469 }
6470
6471 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
6472 * asked for it, this is a Handover Failure after all). */
6473
6474 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6475 var BssmapCause cause := enum2int(cause_val);
6476 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6477
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006478 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006479 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006480 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006481
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006482 f_sleep(1.0);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006483}
6484testcase TC_ho_in_fail_no_detect() runs on test_CT {
6485 var MSC_ConnHdlr vc_conn;
6486 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6487
6488 f_init(1, true);
6489 f_sleep(1.0);
6490
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006491 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006492
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006493 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6494 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006495
6496 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
6497 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006498
6499 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6500 f_ctrs_bsc_and_bts_add(0, "handover:error");
6501 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6502 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
6503 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006504 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006505}
6506
6507/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
6508private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
6509 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6510 f_rslem_register(0, new_chan_nr);
6511 g_chan_nr := new_chan_nr;
6512 f_sleep(1.0);
6513
6514 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6515 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6516 activate(as_Media());
6517
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006518 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006519 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006520 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006521
6522 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6523
6524 var PDU_BSSAP rx_bssap;
6525 var octetstring ho_command_str;
6526
6527 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6528
6529 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6530 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6531 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6532 log("L3 Info in HO Request Ack is ", ho_command);
6533
6534 var GsmArfcn arfcn;
6535 var RslChannelNr actual_new_chan_nr;
6536 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6537 actual_new_chan_nr, arfcn);
6538
6539 if (actual_new_chan_nr != new_chan_nr) {
6540 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6541 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6542 setverdict(fail);
6543 return;
6544 }
6545 log("Handover Command chan_nr is", actual_new_chan_nr);
6546
6547 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6548 * tells the MS to handover to the new lchan. But the MS never shows up
6549 * on the new lchan. */
6550
6551 BSSAP.receive(tr_BSSMAP_HandoverFailure);
6552
6553 /* MSC plays dumb and sends no Clear Command */
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006554 var PDU_BSSAP rx_clear_request;
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02006555
6556 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006557 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
6558 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6559 };
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006560 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006561 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006562 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006563
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006564 f_sleep(1.0);
6565}
6566testcase TC_ho_in_fail_no_detect2() runs on test_CT {
6567 var MSC_ConnHdlr vc_conn;
6568 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6569
6570 f_init(1, true);
6571 f_sleep(1.0);
6572
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006573 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006574
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006575 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6576 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006577
6578 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
6579 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006580
6581 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6582 f_ctrs_bsc_and_bts_add(0, "handover:error");
6583 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6584 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
6585 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006586 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006587}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006588
Neels Hofmeyr91401012019-07-11 00:42:35 +02006589type record of charstring Commands;
6590
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006591private function f_bts_0_cfg(TELNETasp_PT pt, Commands cmds := {})
Neels Hofmeyr91401012019-07-11 00:42:35 +02006592{
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006593 f_vty_enter_cfg_bts(pt, 0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006594 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006595 f_vty_transceive(pt, cmds[i]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006596 }
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006597 f_vty_transceive(pt, "end");
Neels Hofmeyr91401012019-07-11 00:42:35 +02006598}
6599
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01006600private function f_cs7_inst_0_cfg(TELNETasp_PT pt, Commands cmds := {})
6601{
6602 f_vty_enter_cfg_cs7_inst(pt, 0);
6603 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
6604 f_vty_transceive(pt, cmds[i]);
6605 }
6606 f_vty_transceive(pt, "end");
6607}
6608
Neels Hofmeyr91401012019-07-11 00:42:35 +02006609private function f_probe_for_handover(charstring log_label,
6610 charstring log_descr,
6611 charstring handover_vty_cmd,
6612 boolean expect_handover,
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006613 boolean is_inter_bsc_handover := false,
6614 template uint3_t expect_target_tsc := ?)
Neels Hofmeyr91401012019-07-11 00:42:35 +02006615runs on MSC_ConnHdlr
6616{
Neels Hofmeyrb3fc8982020-05-11 00:16:42 +02006617 /* We're going to thwart any and all handover attempts, just be ready to handle (and ignore) handover target
6618 * lchans to be established on bts 1 or bts 2. */
6619 f_rslem_suspend(RSL1_PROC);
6620 f_rslem_suspend(RSL2_PROC);
6621
Neels Hofmeyr91401012019-07-11 00:42:35 +02006622 var RSL_Message rsl;
6623
6624 var charstring log_msg := " (expecting handover)"
6625 if (not expect_handover) {
6626 log_msg := " (expecting NO handover)";
6627 }
6628 log("f_probe_for_handover starting: " & log_label & ": " & log_descr & log_msg);
6629 f_vty_transceive(BSCVTY, handover_vty_cmd);
6630
Neels Hofmeyr91401012019-07-11 00:42:35 +02006631 timer T := 2.0;
6632 T.start;
6633
6634 alt {
6635 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
6636 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
6637 log("Rx L3 from net: ", l3);
6638 if (ischosen(l3.msgs.rrm.handoverCommand)) {
6639 var RslChannelNr new_chan_nr;
6640 var GsmArfcn arfcn;
6641 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
6642 new_chan_nr, arfcn);
6643 log("Handover to new chan ", new_chan_nr, " on ARFCN ", arfcn);
6644 log(l3.msgs.rrm.handoverCommand);
6645
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006646 /* Verify correct TSC in handoverCommand */
6647 var uint3_t got_tsc := rr_chan_desc_tsc(l3.msgs.rrm.handoverCommand.channelDescription2);
6648 if (not match(got_tsc, expect_target_tsc)) {
6649 setverdict(fail, "RR Handover Command: unexpected TSC in Channel Description: expected ",
6650 expect_target_tsc, " got ", got_tsc);
6651 mtc.stop;
6652 } else {
6653 log("handoverCommand: verified TSC = ", got_tsc, " (matches ",
6654 expect_target_tsc, ")");
6655 }
6656
Neels Hofmeyr91401012019-07-11 00:42:35 +02006657 /* Need to register for new lchan on new BTS -- it's either bts 1 or bts 2. It doesn't really
6658 * matter on which BTS it really is, we're not going to follow through an entire handover
6659 * anyway. */
6660 f_rslem_register(0, new_chan_nr, RSL1_PROC);
6661 f_rslem_resume(RSL1_PROC);
6662 f_rslem_register(0, new_chan_nr, RSL2_PROC);
6663 f_rslem_resume(RSL2_PROC);
6664
6665 if (expect_handover and not is_inter_bsc_handover) {
6666 setverdict(pass);
6667 log("f_probe_for_handover(" & log_label & "): Got RSL Handover Command as expected.");
6668 } else {
6669 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got RSL Handover Command. "
6670 & log_label & ": " & log_descr);
6671 }
6672
6673 log("f_probe_for_handover(" & log_label & "): Ending the test: Handover Failure stops the procedure.");
6674 /* osmo-bsc has triggered Handover. That's all we need to know for this test, reply with
6675 * Handover Failure. */
6676 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
6677
6678 /* target BTS is told to release lchan again; don't care which BTS nor what messages. */
6679 f_sleep(0.5);
6680 RSL1.clear;
6681 RSL2.clear;
6682 log("f_probe_for_handover(" & log_label & "): done (got RSL Handover Command)");
6683 break;
6684 } else {
6685 repeat;
6686 }
6687 }
6688 [] BSSAP.receive(tr_BSSMAP_HandoverRequired) {
6689 if (expect_handover and is_inter_bsc_handover) {
6690 setverdict(pass);
6691 log("f_probe_for_handover(" & log_label & "): Got BSSMAP Handover Required as expected.");
6692 } else {
6693 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got BSSMAP Handover Required. "
6694 & log_label & ": " & log_descr);
6695 }
6696
6697 log("f_probe_for_handover(" & log_label & "): done (got BSSMAP Handover Required)");
6698
6699 /* Note: f_tc_ho_neighbor_config_start() sets T7, the timeout for BSSMAP Handover Required, to
6700 * 1 second. There is no legal way to quickly abort a handover after a BSSMAP Handover Required,
6701 * setting a short timeout and waiting is the only way. */
6702 log("f_probe_for_handover(" & log_label & "): waiting for inter-BSC HO to time out...");
6703 f_sleep(1.5);
6704 log("f_probe_for_handover(" & log_label & "): ...done");
6705
6706 break;
6707 }
6708 [] T.timeout {
6709 if (expect_handover) {
6710 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected Handover, but got none. "
6711 & log_label & ": " & log_descr);
6712 } else {
6713 setverdict(pass);
6714 log("f_probe_for_handover(" & log_label & "): Got no Handover, as expected.");
6715 }
6716 log("f_probe_for_handover(" & log_label & "): done (got no Handover)");
6717 break;
6718 }
6719 }
6720
6721 f_rslem_resume(RSL1_PROC);
6722 f_rslem_resume(RSL2_PROC);
6723 f_sleep(3.0);
6724 RSL.clear;
6725
6726 log("f_probe_for_handover(" & log_label & "): done clearing");
6727}
6728
6729/* Test the effect of various neighbor configuration scenarios:
6730 *
6731 * To avoid complexity, block off any actual handover operation, and always remain on the lchan at bts 0.
6732 * Reconfigure the neighbors for bts 0, trigger a Handover, and probe whether osmo-bsc does or doesn't start HO.
6733 */
6734private function f_tc_ho_neighbor_config_start() runs on MSC_ConnHdlr {
6735 g_pars := f_gen_test_hdlr_pars();
6736 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
6737 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006738
6739 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
6740 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
6741
6742 /* Establish lchan at bts 0 */
6743 f_establish_fully(ass_cmd, exp_compl);
6744
6745 /* Shorten the inter-BSC Handover timeout, to not wait so long for inter-BSC Handovers */
6746 f_vty_enter_cfg_network(BSCVTY);
6747 f_vty_transceive(BSCVTY, "timer T7 1");
6748 f_vty_transceive(BSCVTY, "end");
6749}
6750
6751private function f_tc_ho_neighbor_config_1(charstring id) runs on MSC_ConnHdlr {
6752 f_tc_ho_neighbor_config_start();
6753
6754 /*
6755 * bts 0 ARFCN 871 BSIC 10
6756 * bts 1 ARFCN 871 BSIC 11
6757 * bts 2 ARFCN 871 BSIC 12
6758 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6759 */
6760
6761 log("f_tc_ho_neighbor_config: 1. No 'neighbor' config");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006762 f_bts_0_cfg(BSCVTY, {"no neighbors"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006763 f_probe_for_handover("1.a", "HO to bts 1 works, implicitly listed as neighbor (legacy behavior when none are configured)",
6764 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006765 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006766
6767 f_probe_for_handover("1.b", "HO to unknown cell does not start",
6768 "handover any to arfcn 13 bsic 39",
6769 false);
6770
6771 f_probe_for_handover("1.c", "HO to 871-12 is ambiguous = error",
6772 "handover any to arfcn 871 bsic 12",
6773 false);
6774
6775 f_probe_for_handover("1.d", "HO to 871-11 still works (verify that this test properly cleans up)",
6776 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006777 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006778
6779 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006780}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006781testcase TC_ho_neighbor_config_1() runs on test_CT {
6782 var MSC_ConnHdlr vc_conn;
6783 f_init(3, true, guard_timeout := 60.0);
6784 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006785 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006786 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_1));
6787 vc_conn.done;
6788
6789 /* f_tc_ho_neighbor_config_start() */
6790 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6791 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6792
6793 /* 1.a */
6794 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6795 * handover quickly by sending a Handover Failure message. */
6796 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6797 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6798 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6799 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006800 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6801 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006802
6803 /* 1.b */
6804 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6805 f_ctrs_bsc_and_bts_add(0, "handover:error");
6806
6807 /* 1.c */
6808 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6809 f_ctrs_bsc_and_bts_add(0, "handover:error");
6810
6811 /* 1.d */
6812 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6813 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6814 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6815 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006816 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6817 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006818
6819 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006820 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006821}
6822
Neels Hofmeyr91401012019-07-11 00:42:35 +02006823private function f_tc_ho_neighbor_config_2(charstring id) runs on MSC_ConnHdlr {
6824 f_tc_ho_neighbor_config_start();
6825
6826 /*
6827 * bts 0 ARFCN 871 BSIC 10
6828 * bts 1 ARFCN 871 BSIC 11
6829 * bts 2 ARFCN 871 BSIC 12
6830 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6831 */
6832
6833 log("f_tc_ho_neighbor_config: 2. explicit local neighbor: 'neighbor bts 1'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006834 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006835 f_sleep(0.5);
6836
6837 f_probe_for_handover("2.a", "HO to bts 1 works, explicitly listed as neighbor",
6838 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006839 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006840
6841 f_probe_for_handover("2.b", "HO to bts 2 doesn't work, not listed as neighbor",
6842 "handover any to arfcn 871 bsic 12",
6843 false);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006844 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006845}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006846testcase TC_ho_neighbor_config_2() runs on test_CT {
6847 var MSC_ConnHdlr vc_conn;
6848 f_init(3, true, guard_timeout := 50.0);
6849 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006850 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006851 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_2));
6852 vc_conn.done;
6853
6854 /* f_tc_ho_neighbor_config_start() */
6855 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6856 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6857
6858 /* 2.a */
6859 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6860 * handover quickly by sending a Handover Failure message. */
6861 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6862 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6863 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6864 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006865 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6866 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006867
6868 /* 2.b */
6869 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6870 f_ctrs_bsc_and_bts_add(0, "handover:error");
6871
6872 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006873 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006874}
6875
Neels Hofmeyr91401012019-07-11 00:42:35 +02006876private function f_tc_ho_neighbor_config_3(charstring id) runs on MSC_ConnHdlr {
6877 f_tc_ho_neighbor_config_start();
6878
6879 /*
6880 * bts 0 ARFCN 871 BSIC 10
6881 * bts 1 ARFCN 871 BSIC 11
6882 * bts 2 ARFCN 871 BSIC 12
6883 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6884 */
6885
6886 log("f_tc_ho_neighbor_config: 3. explicit local neighbor: 'neighbor bts 2'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006887 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006888 f_sleep(0.5);
6889
6890 f_probe_for_handover("3.a", "HO to bts 1 doesn't work, not listed as neighbor",
6891 "handover any to arfcn 871 bsic 11",
6892 false);
6893 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",
6894 "handover any to arfcn 871 bsic 12",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006895 true, expect_target_tsc := BTS_TSC[2]);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006896 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006897}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006898testcase TC_ho_neighbor_config_3() runs on test_CT {
6899 var MSC_ConnHdlr vc_conn;
6900 f_init(3, true, guard_timeout := 50.0);
6901 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006902 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006903 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_3));
6904 vc_conn.done;
6905
6906 /* f_tc_ho_neighbor_config_start() */
6907 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6908 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6909
6910 /* 3.a */
6911 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6912 f_ctrs_bsc_and_bts_add(0, "handover:error");
6913
6914 /* 3.b */
6915 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6916 * handover quickly by sending a Handover Failure message. */
6917 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6918 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6919 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6920 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006921 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:attempted");
6922 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006923
6924 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006925 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006926}
6927
Neels Hofmeyr91401012019-07-11 00:42:35 +02006928private function f_tc_ho_neighbor_config_4(charstring id) runs on MSC_ConnHdlr {
6929 f_tc_ho_neighbor_config_start();
6930
6931 /*
6932 * bts 0 ARFCN 871 BSIC 10
6933 * bts 1 ARFCN 871 BSIC 11
6934 * bts 2 ARFCN 871 BSIC 12
6935 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6936 */
6937
6938 log("f_tc_ho_neighbor_config: 4. explicit remote neighbor: 'neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006939 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006940 f_sleep(0.5);
6941
6942 f_probe_for_handover("4.a", "HO to bts 1 doesn't work, not listed as neighbor",
6943 "handover any to arfcn 871 bsic 11",
6944 false);
6945 f_probe_for_handover("4.b", "HO to bts 2 doesn't work, not listed as neighbor",
6946 "handover any to arfcn 871 bsic 12",
6947 false);
6948 f_probe_for_handover("4.c", "HO to 123-45 triggers inter-BSC HO",
6949 "handover any to arfcn 123 bsic 45",
6950 true, true);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006951 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006952}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006953testcase TC_ho_neighbor_config_4() runs on test_CT {
6954 var MSC_ConnHdlr vc_conn;
6955 f_init(3, true, guard_timeout := 50.0);
6956 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006957 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006958 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_4));
6959 vc_conn.done;
6960
6961 /* f_tc_ho_neighbor_config_start() */
6962 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6963 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6964
6965 /* 4.a */
6966 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6967 f_ctrs_bsc_and_bts_add(0, "handover:error");
6968
6969 /* 4.b */
6970 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6971 f_ctrs_bsc_and_bts_add(0, "handover:error");
6972
6973 /* 4.c */
6974 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6975 * handover quickly by timing out after the Handover Required message */
6976 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6977 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
6978 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
6979 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
6980
6981 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006982 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006983}
6984
Neels Hofmeyr91401012019-07-11 00:42:35 +02006985private function f_tc_ho_neighbor_config_5(charstring id) runs on MSC_ConnHdlr {
6986 f_tc_ho_neighbor_config_start();
6987
6988 /*
6989 * bts 0 ARFCN 871 BSIC 10
6990 * bts 1 ARFCN 871 BSIC 11
6991 * bts 2 ARFCN 871 BSIC 12
6992 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6993 */
6994
6995 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 +02006996 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006997 f_sleep(0.5);
6998
6999 f_probe_for_handover("5.a", "HO to 871-12 triggers inter-BSC HO (ignoring local cells with same ARFCN+BSIC)",
7000 "handover any to arfcn 871 bsic 12",
7001 true, true);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007002 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007003}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007004testcase TC_ho_neighbor_config_5() runs on test_CT {
7005 var MSC_ConnHdlr vc_conn;
7006 f_init(3, true);
7007 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007008 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007009 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_5));
7010 vc_conn.done;
7011
7012 /* f_tc_ho_neighbor_config_start() */
7013 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7014 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7015
7016 /* 5 */
7017 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7018 * handover quickly by timing out after the Handover Required message */
7019 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7020 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
7021 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
7022 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
7023
7024 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007025 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007026}
7027
Neels Hofmeyr91401012019-07-11 00:42:35 +02007028private function f_tc_ho_neighbor_config_6(charstring id) runs on MSC_ConnHdlr {
7029 f_tc_ho_neighbor_config_start();
7030
7031 /*
7032 * bts 0 ARFCN 871 BSIC 10
7033 * bts 1 ARFCN 871 BSIC 11
7034 * bts 2 ARFCN 871 BSIC 12
7035 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7036 */
7037
7038 log("f_tc_ho_neighbor_config: 6. config error: explicit local and remote neighbors with ambiguous ARFCN+BSIC:"
7039 & " 'neighbor bts 2; neighbor lac 99 arfcn 871 bsic 12'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007040 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007041 f_sleep(0.5);
7042
7043 f_probe_for_handover("6.a", "HO to 871-12 is ambiguous = error",
7044 "handover any to arfcn 871 bsic 12",
7045 false);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007046 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007047}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007048testcase TC_ho_neighbor_config_6() runs on test_CT {
7049 var MSC_ConnHdlr vc_conn;
7050 f_init(3, true);
7051 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007052 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007053 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_6));
7054 vc_conn.done;
7055
7056 /* f_tc_ho_neighbor_config_start() */
7057 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7058 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7059
7060 /* 6.a */
7061 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7062 * handover quickly by timing out after the Handover Required message */
7063 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7064 f_ctrs_bsc_and_bts_add(0, "handover:error");
7065
7066 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007067 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007068}
7069
Neels Hofmeyr91401012019-07-11 00:42:35 +02007070private function f_tc_ho_neighbor_config_7(charstring id) runs on MSC_ConnHdlr {
7071 f_tc_ho_neighbor_config_start();
7072
7073 /*
7074 * bts 0 ARFCN 871 BSIC 10
7075 * bts 1 ARFCN 871 BSIC 11
7076 * bts 2 ARFCN 871 BSIC 12
7077 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7078 */
7079
7080 log("f_tc_ho_neighbor_config: 7. explicit local and remote neighbors:"
7081 & " 'neighbor bts 2; neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007082 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007083 f_sleep(0.5);
7084
7085 f_probe_for_handover("7.a", "HO to 871-12 does HO to bts 2",
7086 "handover any to arfcn 871 bsic 12",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02007087 true, expect_target_tsc := BTS_TSC[2]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02007088 f_probe_for_handover("7.b", "HO to 123-45 triggers inter-BSC HO",
7089 "handover any to arfcn 123 bsic 45",
7090 true, true);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007091 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007092}
Neels Hofmeyr91401012019-07-11 00:42:35 +02007093testcase TC_ho_neighbor_config_7() runs on test_CT {
7094 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf2b88032020-06-16 00:35:04 +02007095 f_init(3, true, guard_timeout := 50.0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02007096 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007097 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007098 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_7));
7099 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007100
7101 /* f_tc_ho_neighbor_config_start() */
7102 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7103 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7104
7105 /* 7.a */
7106 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
7107 * handover quickly by sending a Handover Failure message. */
7108 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7109 f_ctrs_bsc_and_bts_add(0, "handover:failed");
7110 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
7111 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007112 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:attempted");
7113 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007114
7115 /* 7.b */
7116 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7117 * handover quickly by timing out after the Handover Required message */
7118 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7119 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
7120 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
7121 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
7122
7123 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007124 f_shutdown_helper();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007125}
7126
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007127/* OS#3041: Open and close N connections in a normal fashion, and expect no
7128 * BSSMAP Reset just because of that. */
7129testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
7130 var default d;
7131 var integer i;
7132 var DchanTuple dt;
7133
7134 f_init();
7135
7136 /* Wait for initial BSSMAP Reset to pass */
7137 f_sleep(4.0);
7138
7139 d := activate(no_bssmap_reset());
7140
7141 /* Setup up a number of connections and RLSD them again from the MSC
7142 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7143 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02007144 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007145 /* Since we're doing a lot of runs, give each one a fresh
7146 * T_guard from the top. */
7147 T_guard.start;
7148
7149 /* Setup a BSSAP connection and clear it right away. This is
7150 * the MSC telling the BSC about a planned release, it's not an
7151 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02007152 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007153
7154 /* MSC disconnects (RLSD). */
7155 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
7156 }
7157
7158 /* In the buggy behavior, a timeout of 2 seconds happens between above
7159 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7160 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7161 f_sleep(4.0);
7162
7163 deactivate(d);
7164 f_shutdown_helper();
7165}
Harald Welte552620d2017-12-16 23:21:36 +01007166
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007167/* OS#3041: Open and close N connections in a normal fashion, and expect no
7168 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
7169 * the MSC. */
7170testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
7171 var default d;
7172 var integer i;
7173 var DchanTuple dt;
7174 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007175 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
7176 var BssmapCause cause := enum2int(cause_val);
7177
7178 f_init();
7179
7180 /* Wait for initial BSSMAP Reset to pass */
7181 f_sleep(4.0);
7182
7183 d := activate(no_bssmap_reset());
7184
7185 /* Setup up a number of connections and RLSD them again from the MSC
7186 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7187 * Let's do it some more times for good measure. */
7188 for (i := 0; i < 8; i := i+1) {
7189 /* Since we're doing a lot of runs, give each one a fresh
7190 * T_guard from the top. */
7191 T_guard.start;
7192
7193 /* Setup a BSSAP connection and clear it right away. This is
7194 * the MSC telling the BSC about a planned release, it's not an
7195 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02007196 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007197
7198 /* Instruct BSC to clear channel */
7199 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7200
7201 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02007202 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007203 }
7204
7205 /* In the buggy behavior, a timeout of 2 seconds happens between above
7206 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7207 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7208 f_sleep(4.0);
7209
7210 deactivate(d);
7211 f_shutdown_helper();
7212}
7213
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007214/* OS#3041: Open and close N connections in a normal fashion, and expect no
7215 * BSSMAP Reset just because of that. Close connections from the MS side with a
7216 * Release Ind on RSL. */
7217testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
7218 var default d;
7219 var integer i;
7220 var DchanTuple dt;
7221 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007222 var integer j;
7223
7224 f_init();
7225
7226 /* Wait for initial BSSMAP Reset to pass */
7227 f_sleep(4.0);
7228
7229 d := activate(no_bssmap_reset());
7230
7231 /* Setup up a number of connections and RLSD them again from the MSC
7232 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7233 * Let's do it some more times for good measure. */
7234 for (i := 0; i < 8; i := i+1) {
7235 /* Since we're doing a lot of runs, give each one a fresh
7236 * T_guard from the top. */
7237 T_guard.start;
7238
7239 /* Setup a BSSAP connection and clear it right away. This is
7240 * the MSC telling the BSC about a planned release, it's not an
7241 * erratic loss of a connection. */
7242 dt := f_est_dchan('23'O, 23, '00010203040506'O);
7243
7244 /* simulate RLL REL IND */
7245 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
7246
7247 /* expect Clear Request on MSC side */
7248 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
7249
7250 /* Instruct BSC to clear channel */
7251 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
7252 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7253
7254 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02007255 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007256 }
7257
7258 /* In the buggy behavior, a timeout of 2 seconds happens between above
7259 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7260 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7261 f_sleep(4.0);
7262
7263 deactivate(d);
7264 f_shutdown_helper();
7265}
7266
Harald Welte94e0c342018-04-07 11:33:23 +02007267/***********************************************************************
7268 * IPA style dynamic PDCH
7269 ***********************************************************************/
7270
7271private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
7272 template (omit) RSL_Cause nack := omit)
7273runs on test_CT {
7274 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
7275 var RSL_Message rsl_unused;
7276 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
7277 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
7278 /* expect the BSC to issue the related RSL command */
7279 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7280 if (istemplatekind(nack, "omit")) {
7281 /* respond with a related acknowledgement */
7282 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7283 } else {
7284 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
7285 }
7286}
7287
7288private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
7289 template (omit) RSL_Cause nack := omit)
7290runs on test_CT {
7291 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
7292 var RSL_Message rsl_unused;
7293 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
7294 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
7295 /* expect the BSC to issue the related RSL command */
7296 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
7297 if (istemplatekind(nack, "omit")) {
7298 /* respond with a related acknowledgement */
7299 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
7300 } else {
7301 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
7302 }
7303}
7304
7305private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
7306runs on test_CT return charstring {
7307 var charstring cmd, resp;
7308 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01007309 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02007310}
7311
7312private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
7313 template charstring exp)
7314runs on test_CT {
7315 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
7316 if (not match(mode, exp)) {
7317 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02007318 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02007319 }
7320}
7321
7322private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
7323runs on test_CT {
7324 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
7325 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
7326 f_vty_transceive(BSCVTY, "end");
7327}
7328
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007329
7330private function f_ts_reset_chcomb(integer bts_nr) runs on test_CT {
7331 var integer i;
7332 for (i := 0; i < 8; i := i + 1) {
7333 f_ts_set_chcomb(bts_nr, 0, i, phys_chan_config[i]);
7334 }
7335}
7336
Harald Welte94e0c342018-04-07 11:33:23 +02007337private const charstring TCHF_MODE := "TCH/F mode";
7338private const charstring TCHH_MODE := "TCH/H mode";
7339private const charstring PDCH_MODE := "PDCH mode";
7340private const charstring NONE_MODE := "NONE mode";
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007341private const charstring SDCCH8_MODE := "SDCCH8 mode";
Harald Welte94e0c342018-04-07 11:33:23 +02007342
7343/* Test IPA PDCH activation / deactivation triggered by VTY */
7344testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
7345 var RSL_Message rsl_unused;
7346
7347 /* change Timeslot 6 before f_init() starts RSL */
7348 f_init_vty();
7349 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
7350 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7351
7352 f_init(1, false);
7353 f_sleep(1.0);
7354
7355 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
7356
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007357 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007358 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7359 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7360 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7361 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7362 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007363 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007364 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7365
7366 /* De-activate it via VTY */
7367 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7368 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007369 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007370 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7371
7372 /* re-activate it via VTY */
7373 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
7374 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007375 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007376 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7377
7378 /* and finally de-activate it again */
7379 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7380 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007381 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007382 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7383
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007384 /* clean up config */
7385 f_ts_set_chcomb(0, 0, 6, "PDCH");
7386
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007387 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007388}
7389
7390/* Test IPA PDCH activation NACK */
7391testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
7392 var RSL_Message rsl_unused;
7393
7394 /* change Timeslot 6 before f_init() starts RSL */
7395 f_init_vty();
7396 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
7397 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7398
7399 f_init(1, false);
7400 f_sleep(1.0);
7401
7402 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
7403
7404 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7405 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7406 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7407 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7408 f_sleep(1.0);
7409 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7410
7411 /* De-activate it via VTY */
7412 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7413 f_sleep(1.0);
7414 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7415
7416 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
7417 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
7418 f_sleep(1.0);
7419 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7420
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007421 /* clean up config */
7422 f_ts_set_chcomb(0, 0, 6, "PDCH");
7423
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007424 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007425}
7426
7427
7428/***********************************************************************
7429 * Osmocom style dynamic PDCH
7430 ***********************************************************************/
7431
7432private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
7433 template (omit) RSL_Cause nack := omit)
7434runs on test_CT {
7435 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
7436 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02007437 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02007438 /* FIXME: no VTY command to activate Osmocom PDCH !! */
7439 /* expect the BSC to issue the related RSL command */
7440 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
7441 if (istemplatekind(nack, "omit")) {
7442 /* respond with a related acknowledgement */
7443 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7444 } else {
7445 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
7446 }
7447}
7448
7449private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
7450 template (omit) RSL_Cause nack := omit)
7451runs on test_CT {
7452 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
7453 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02007454 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02007455 /* FIXME: no VTY command to activate Osmocom PDCH !! */
7456 /* expect the BSC to issue the related RSL command */
7457 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
7458 if (istemplatekind(nack, "omit")) {
7459 /* respond with a related acknowledgement */
7460 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
7461 } else {
7462 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
7463 }
7464}
7465
7466/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
7467testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
7468 var RSL_Message rsl_unused;
7469
7470 /* change Timeslot 6 before f_init() starts RSL */
7471 f_init_vty();
7472 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
7473 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7474
7475 f_init(1, false);
7476 f_sleep(1.0);
7477
7478 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
7479
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007480 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007481 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7482 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007483 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Harald Welte94e0c342018-04-07 11:33:23 +02007484
7485 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7486 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007487 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 +02007488 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7489
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007490 /* clean up config */
7491 f_ts_set_chcomb(0, 0, 6, "PDCH");
7492
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007493 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007494}
7495
7496/* Test Osmocom dyn PDCH activation NACK behavior */
7497testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
7498 var RSL_Message rsl_unused;
7499
7500 /* change Timeslot 6 before f_init() starts RSL */
7501 f_init_vty();
7502 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
7503 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7504
7505 f_init(1, false);
7506 f_sleep(1.0);
7507
7508 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
7509
7510 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7511 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007512 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Harald Welte94e0c342018-04-07 11:33:23 +02007513
7514 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
7515 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
7516 f_sleep(1.0);
7517 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7518
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007519 /* clean up config */
7520 f_ts_set_chcomb(0, 0, 6, "PDCH");
7521
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007522 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007523}
7524
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007525/* Test Osmocom dyn TS SDCCH8 activation / deactivation */
7526testcase TC_dyn_ts_sdcch8_act_deact() runs on test_CT {
7527 var RSL_Message rsl_unused, rsl_msg;
7528 var DchanTuple dt;
7529 var BSSAP_N_CONNECT_ind rx_c_ind;
7530
7531 /* change Timeslot 6 before f_init() starts RSL */
7532 f_init_vty();
7533 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
7534 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7535
7536 f_init(1, false);
7537 f_sleep(1.0);
7538
7539 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7540
7541 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7542 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7543 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007544 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007545
7546 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7547 f_sleep(1.0);
7548 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7549 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7550
7551 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7552 * on CCCH+SDCCH4+CBCH) */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007553 var DchanTuples sdcch_cleanup := {};
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007554 var integer i;
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007555 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007556 dt := f_est_dchan('23'O, i, '00010203040506'O);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007557 sdcch_cleanup := sdcch_cleanup & { dt };
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007558 }
7559
7560 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
7561 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
7562 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7563 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7564
7565 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7566 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7567
7568 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7569 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
7570 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7571 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7572
7573 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
7574 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
7575 dt.sccp_conn_id := rx_c_ind.connectionId;
7576 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
7577
7578 /* Instruct BSC to clear channel */
7579 var BssmapCause cause := 0;
7580 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7581 f_exp_chan_rel_and_clear(dt, 0);
7582
7583 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007584 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007585 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7586 f_sleep(1.0);
7587 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7588
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007589 /* Clean up SDCCH lchans */
7590 for (i := 0; i < lengthof(sdcch_cleanup); i := i + 1) {
7591 f_perform_clear_test_ct(sdcch_cleanup[i]);
7592 }
7593
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007594 /* clean up config */
7595 f_ts_set_chcomb(0, 0, 6, "PDCH");
7596
7597 f_shutdown_helper();
7598}
7599
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007600/* Validate all 8 subslots of a dynamics TS configured as SDCCH8 are used */
7601testcase TC_dyn_ts_sdcch8_all_subslots_used() runs on test_CT {
7602 var ASP_RSL_Unitdata rsl_ud;
7603 var integer i;
7604 var integer chreq_total, chreq_nochan;
7605
7606 f_init_vty();
7607 for (i := 1; i < 8; i := i + 1) {
7608 if (i == 2) {
7609 f_ts_set_chcomb(0, 0, i, "TCH/F_TCH/H_SDCCH8_PDCH");
7610 } else {
7611 f_ts_set_chcomb(0, 0, i, "PDCH");
7612 }
7613 }
7614 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7615
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007616 f_init(1, guard_timeout := 60.0);
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007617
7618 /* The dyn TS want to activate PDCH mode, ACK that. */
7619 var RslChannelNr chan_nr;
7620 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007621 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007622 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7623
7624 f_sleep(1.0);
7625
7626 /* Exhaust all dedicated SDCCH lchans.
7627 /* GSM 44.018 Table 9.1.8.2:
7628 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
7629 */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007630 var DchanTuples chan_cleanup := {};
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007631 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007632 chan_cleanup := chan_cleanup & { f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007633 }
7634
7635 /* Only the dyn TS is still available. Its first lchan gets converted to SDCCH8 */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007636 chan_cleanup := chan_cleanup & { f_est_dchan_dyn('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007637 /* Also occupy the seven other SDCCH of the dyn TS */
7638 for (i := 0; i < 7; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007639 chan_cleanup := chan_cleanup & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
7640 }
7641
7642 /* Clean up SDCCH lchans */
7643 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
7644 f_perform_clear_test_ct(chan_cleanup[i]);
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007645 }
7646
7647 /* clean up config */
7648 f_ts_reset_chcomb(0);
7649
7650 f_shutdown_helper();
7651}
7652
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007653/* Test Osmocom dyn TS SDCCH8 activation / deactivation: If activating dyn TS as
7654 SDCCH8 would end up in having no free TCH, then BSC should decide to activate
7655 it as TCH directly instead. SYS#5309. */
7656testcase TC_dyn_ts_sdcch8_tch_call_act_deact() runs on test_CT {
7657 var RSL_Message rsl_unused, rsl_msg;
7658 var DchanTuple dt;
7659 var BSSAP_N_CONNECT_ind rx_c_ind;
7660 var integer i;
7661
7662 /* change Timeslot 6 before f_init() starts RSL */
7663 f_init_vty();
7664 for (i := 1; i < 8; i := i + 1) {
7665 if (i == 6) {
7666 f_ts_set_chcomb(0, 0, i, "TCH/F_TCH/H_SDCCH8_PDCH");
7667 } else {
7668 f_ts_set_chcomb(0, 0, i, "PDCH");
7669 }
7670 }
7671 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7672
7673 f_init(1, false);
7674 f_sleep(1.0);
7675
7676 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7677
7678 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7679 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7680 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007681 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007682
7683 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7684 f_sleep(1.0);
7685 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7686 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7687
7688 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7689 * on CCCH+SDCCH4+CBCH) */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007690 var DchanTuples chan_cleanup := {};
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007691 var OCT1 ra := '43'O; /* RA containing reason=originating speech call*/
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007692 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007693 dt := f_est_dchan(ra, i, '00010203040506'O);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007694 chan_cleanup := chan_cleanup & { dt };
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007695 }
7696
7697 /* Now the dyn ts is selected. First PDCH is released, then TCH chan is activated */
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007698 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int(ra) + i, 1), 2342));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007699 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7700 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7701
7702 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7703 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7704
7705 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
7706 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
7707 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7708 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
7709
7710 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
7711 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
7712 dt.sccp_conn_id := rx_c_ind.connectionId;
7713 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
7714
7715 /* Instruct BSC to clear channel */
7716 var BssmapCause cause := 0;
7717 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7718 f_exp_chan_rel_and_clear(dt, 0);
7719
7720 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007721 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007722 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7723 f_sleep(1.0);
7724 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7725
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007726 /* Clean up SDCCH lchans */
7727 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
7728 f_perform_clear_test_ct(chan_cleanup[i]);
7729 }
7730
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007731 /* clean up config */
7732 f_ts_reset_chcomb(0);
7733 /* TODO: clean up other channels? */
7734
7735 f_shutdown_helper();
7736}
7737
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007738/* Test Osmocom dyn TS SDCCH8 activation / deactivation when SDCCH fails at BTS */
7739testcase TC_dyn_ts_sdcch8_act_nack() runs on test_CT {
7740 var RSL_Message rsl_unused, rsl_msg;
7741 var DchanTuple dt;
7742 var BSSAP_N_CONNECT_ind rx_c_ind;
7743 var GsmRrMessage rr;
7744
7745 /* change Timeslot 6 before f_init() starts RSL */
7746 f_init_vty();
7747 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
7748 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7749
7750 f_init(1, false);
7751 f_sleep(1.0);
7752
7753 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7754
7755 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7756 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7757 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007758 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007759
7760 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7761 f_sleep(1.0);
7762 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7763 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7764
7765 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7766 * on CCCH+SDCCH4+CBCH) */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007767 var DchanTuples chan_cleanup := {};
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007768 var integer i;
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007769 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007770 dt := f_est_dchan('23'O, i, '00010203040506'O);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007771 chan_cleanup := chan_cleanup & { dt };
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007772 }
7773
7774 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
7775 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
7776 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7777 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7778
7779 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7780 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7781
7782 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7783 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(dt.rsl_chan_nr, RSL_ERR_EQUIPMENT_FAIL));
7784 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7785 rr := dec_GsmRrMessage(rsl_msg.ies[1].body.full_imm_ass_info.payload);
7786 if (rr.header.message_type != IMMEDIATE_ASSIGNMENT_REJECT) {
7787 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Expected reject");
7788 }
7789
7790 /* FIXME? Currently the TS stays in state BORKEN: */
7791
7792 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007793 /* rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007794 * f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7795 * f_sleep(1.0);
7796 * f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE)
7797 */
7798
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007799 /* Clean up SDCCH lchans */
7800 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
7801 f_perform_clear_test_ct(chan_cleanup[i]);
7802 }
7803
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007804 /* clean up config */
7805 f_ts_set_chcomb(0, 0, 6, "PDCH");
7806
7807 f_shutdown_helper();
7808}
7809
Stefan Sperling0796a822018-10-05 13:01:39 +02007810testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02007811 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02007812 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
7813 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
7814 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007815 f_shutdown_helper();
Stefan Sperling0796a822018-10-05 13:01:39 +02007816}
7817
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007818testcase TC_chopped_ipa_payload() runs on test_CT {
7819 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
7820 /* TODO: mp_bsc_ctrl_port does not work yet */};
7821 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
7822 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
7823 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007824 f_shutdown_helper();
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007825}
7826
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01007827/* Verify the BSC sends the MS Power Parameters IE during CHAN ACT to make sure
7828 the BTS does autonomous MS power control loop */
7829testcase TC_assignment_verify_ms_power_params_ie() runs on test_CT {
7830 var MSC_ConnHdlr vc_conn;
7831 var TestHdlrParams pars := f_gen_test_hdlr_pars();
7832 //pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
7833 pars.exp_ms_power_params := true;
7834
7835 f_init(1, true);
7836 f_sleep(1.0);
7837 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
7838 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007839 f_shutdown_helper();
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01007840}
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007841
Vadim Yanitskiy4b233042021-06-30 00:58:43 +02007842/* Verify activation and deactivation of the BCCH carrier power reduction mode */
7843testcase TC_c0_power_red_mode() runs on test_CT {
7844 f_init(1);
7845
7846 for (var integer red := 6; red >= 0; red := red - 2) {
7847 /* Configure BCCH carrier power reduction mode via the VTY */
7848 f_vty_transceive(BSCVTY, "bts 0 c0-power-reduction " & int2str(red));
7849
7850 /* Expect Osmocom specific BS Power Control message on the RSL */
7851 var template RSL_Message tr_rsl_pdu := tr_RSL_BS_PWR_CTRL(
7852 chan_nr := t_RslChanNr_BCCH(0),
7853 bs_power := tr_RSL_IE_BS_Power(red / 2));
7854 tr_rsl_pdu.msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false);
7855 var RSL_Message unused := f_exp_ipa_rx(0, tr_rsl_pdu);
7856
7857 /* Additionally verify the applied value over the CTRL interface */
7858 var CtrlValue cred := f_ctrl_get_bts(IPA_CTRL, 0, "c0-power-reduction");
7859 if (cred != int2str(red)) {
7860 setverdict(fail, "Unexpected BCCH carrier power reduction value ",
7861 cred, " (expected ", red, ")");
7862 }
7863 }
7864
7865 f_shutdown_helper();
7866}
7867
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007868/***********************************************************************
7869 * MSC Pooling
7870 ***********************************************************************/
7871
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007872template MobileIdentityLV ts_MI_TMSI_NRI_LV(integer nri_v, integer nri_bitlen := 10) :=
Harald Weltebf397612021-01-14 20:39:46 +01007873 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 +02007874
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007875private 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 +02007876runs on MSC_ConnHdlr {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007877 interleave {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007878 [] rsl_pt.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007879 f_logp(BSCVTY, "Got RSL RR Release");
7880 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007881 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007882 f_logp(BSCVTY, "Got RSL Deact SACCH");
7883 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02007884 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007885 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007886 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
7887 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007888 break;
7889 }
7890 }
7891}
7892
Neels Hofmeyr6289af12021-12-16 18:17:49 +01007893private altstep as_mgcp_ack_all_dlcx() runs on MSC_ConnHdlr {
7894 var MgcpCommand mgcp_cmd;
7895 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
7896 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
7897 repeat;
7898 }
7899}
7900
7901private altstep as_rsl_ack_all_rel_req() runs on MSC_ConnHdlr {
7902 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
7903 [] RSL.receive(tr_RSL_REL_REQ(g_chan_nr, ?)) {
7904 RSL.send(ts_RSL_REL_CONF(g_chan_nr, main_dcch));
7905 repeat;
7906 }
7907}
7908
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007909friend function f_perform_clear(RSL_DCHAN_PT rsl_pt := RSL, RSLEM_PROC_PT rsl_proc_pt := RSL_PROC,
7910 template PDU_ML3_NW_MS exp_rr_rel_tmpl := tr_RRM_RR_RELEASE)
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02007911runs on MSC_ConnHdlr {
Neels Hofmeyr6289af12021-12-16 18:17:49 +01007912 var default ack_dlcx := activate(as_mgcp_ack_all_dlcx());
7913 var default ack_rel_req := activate(as_rsl_ack_all_rel_req());
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007914 f_logp(BSCVTY, "MSC instructs BSC to clear channel");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007915 BSSAP.send(ts_BSSMAP_ClearCommand(0));
7916 interleave {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007917 [] rsl_pt.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007918 f_logp(BSCVTY, "Got RSL RR Release");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007919 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007920 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007921 f_logp(BSCVTY, "Got RSL Deact SACCH");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007922 }
7923 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007924 f_logp(BSCVTY, "Got BSSMAP Clear Complete");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007925 /* Also drop the SCCP connection */
7926 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
7927 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02007928 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007929 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007930 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
7931 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007932 }
7933 }
Neels Hofmeyr6289af12021-12-16 18:17:49 +01007934 deactivate(ack_dlcx);
7935 deactivate(ack_rel_req);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007936}
7937
Neels Hofmeyrc3c6ee62022-01-26 01:22:12 +01007938friend function f_perform_clear_no_rr_rel(RSL_DCHAN_PT rsl_pt := RSL, RSLEM_PROC_PT rsl_proc_pt := RSL_PROC)
7939runs on MSC_ConnHdlr {
7940 var default ack_dlcx := activate(as_mgcp_ack_all_dlcx());
7941 var default ack_rel_req := activate(as_rsl_ack_all_rel_req());
7942 f_logp(BSCVTY, "MSC instructs BSC to clear channel");
7943 BSSAP.send(ts_BSSMAP_ClearCommand(0));
7944 interleave {
7945 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
7946 f_logp(BSCVTY, "Got RSL Deact SACCH");
7947 }
7948 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
7949 f_logp(BSCVTY, "Got BSSMAP Clear Complete");
7950 /* Also drop the SCCP connection */
7951 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
7952 }
7953 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
7954 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
7955 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
7956 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
7957 }
7958 }
7959 deactivate(ack_dlcx);
7960 deactivate(ack_rel_req);
7961}
7962
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007963private function f_perform_clear_test_ct(DchanTuple dt)
7964 runs on test_CT
7965{
7966 /* Instruct BSC to clear channel */
7967 var BssmapCause cause := 0;
7968 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7969 f_exp_chan_rel_and_clear(dt, 0);
7970}
7971
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007972private function f_perform_compl_l3(RSL_DCHAN_PT rsl_pt, RSLEM_PROC_PT rsl_proc_pt,
7973 template PDU_ML3_MS_NW l3_info, boolean do_clear := true, boolean expect_bssmap_l3 := true)
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007974runs on MSC_ConnHdlr {
7975 timer T := 10.0;
7976 var octetstring l3_enc := enc_PDU_ML3_MS_NW(valueof(l3_info));
7977
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007978 f_logp(BSCVTY, "establish channel, send Complete Layer 3 Info");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007979 f_create_bssmap_exp(l3_enc);
7980
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007981 /* RSL_Emulation.f_chan_est() on rsl_pt:
7982 * This is basically code dup with s/RSL/rsl_pt from:
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007983 * RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
7984 */
7985 var RSL_Message rx_rsl;
7986 var GsmRrMessage rr;
7987
7988 /* request a channel to be established */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007989 rsl_pt.send(ts_RSLDC_ChanRqd(g_pars.ra, g_pars.fn));
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007990 /* expect immediate assignment.
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007991 * Code dup with s/RSL/rsl_pt from:
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007992 * rx_rsl := f_rx_or_fail(tr_RSL_IMM_ASSIGN);
7993 */
7994 timer Tt := 10.0;
7995
7996 /* request a channel to be established */
7997 Tt.start;
7998 alt {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007999 [] rsl_pt.receive(tr_RSL_IMM_ASSIGN) -> value rx_rsl {
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008000 Tt.stop;
8001 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008002 [] rsl_pt.receive {
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008003 setverdict(fail, "Unexpected RSL message on DCHAN");
8004 mtc.stop;
8005 }
8006 [] Tt.timeout {
8007 setverdict(fail, "Timeout waiting for RSL on DCHAN");
8008 mtc.stop;
8009 }
8010 }
8011 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
8012 g_chan_nr := rr.payload.imm_ass.chan_desc.chan_nr;
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008013 rsl_pt.send(ts_RSL_EST_IND(g_chan_nr, valueof(g_pars.link_id), l3_enc));
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008014
8015
Neels Hofmeyr66e15092020-10-12 18:44:41 +00008016 if (expect_bssmap_l3) {
8017 f_logp(BSCVTY, "expect BSSAP Complete Layer 3 Info at MSC");
8018 var template PDU_BSSAP exp_l3_compl;
8019 exp_l3_compl := tr_BSSMAP_ComplL3()
8020 if (g_pars.aoip == false) {
8021 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := omit;
8022 } else {
8023 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := ?;
8024 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008025
Neels Hofmeyr66e15092020-10-12 18:44:41 +00008026 var PDU_BSSAP bssap;
8027 T.start;
8028 alt {
8029 [] BSSAP.receive(exp_l3_compl) -> value bssap {
8030 f_logp(BSCVTY, "received expected Complete Layer 3 Info at MSC");
8031 log("rx exp_l3_compl = ", bssap);
8032 }
8033 [] BSSAP.receive(tr_BSSMAP_ComplL3) {
8034 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching COMPLETE LAYER 3 INFORMATION");
8035 }
8036 [] T.timeout {
8037 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
8038 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008039 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008040
Neels Hofmeyr66e15092020-10-12 18:44:41 +00008041 /* start ciphering, if requested */
8042 if (ispresent(g_pars.encr)) {
8043 f_logp(BSCVTY, "start ciphering");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008044 f_cipher_mode(g_pars.encr, rsl_pt := rsl_pt, rsl_proc_pt := rsl_proc_pt);
Neels Hofmeyr66e15092020-10-12 18:44:41 +00008045 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008046 }
8047
8048 if (do_clear) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008049 f_perform_clear(rsl_pt, rsl_proc_pt);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008050 }
8051 setverdict(pass);
8052 f_sleep(1.0);
8053}
8054
8055private function f_tc_mscpool_compl_l3(charstring id) runs on MSC_ConnHdlr {
8056 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8057 if (g_pars.mscpool.rsl_idx == 0) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008058 f_perform_compl_l3(RSL, RSL_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008059 } else if (g_pars.mscpool.rsl_idx == 1) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008060 f_perform_compl_l3(RSL1, RSL1_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008061 } else if (g_pars.mscpool.rsl_idx == 2) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008062 f_perform_compl_l3(RSL2, RSL2_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008063 }
8064}
8065
8066/* Various Complete Layer 3 by IMSI all end up with the first MSC, because the other MSCs are not connected. */
8067private function f_tc_mscpool_L3Compl_on_1_msc(charstring id) runs on MSC_ConnHdlr {
8068 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008069 f_perform_compl_l3(RSL, RSL_PROC, ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O) );
8070 f_perform_compl_l3(RSL, RSL_PROC, ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_IMSI_LV('001010000000002'H))) );
8071 f_perform_compl_l3(RSL, RSL_PROC, ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))) );
8072 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 +02008073}
8074testcase TC_mscpool_L3Compl_on_1_msc() runs on test_CT {
8075
8076 f_init(1, true);
8077 f_sleep(1.0);
8078 var MSC_ConnHdlr vc_conn;
8079 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008080
8081 f_ctrs_msc_init();
8082
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008083 vc_conn := f_start_handler(refers(f_tc_mscpool_L3Compl_on_1_msc), pars);
8084 vc_conn.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008085
8086 f_ctrs_msc_expect(0, "mscpool:subscr:new", 4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008087 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008088}
8089
8090/* Three Layer 3 Complete by IMSI are round-robin'ed across two connected MSCs */
8091/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8092 * just as well using only RSL. */
8093testcase TC_mscpool_L3Complete_by_imsi_round_robin() runs on test_CT {
8094
8095 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8096 f_sleep(1.0);
8097
8098 /* Control which MSC gets chosen next by the round-robin, otherwise
8099 * would be randomly affected by which other tests ran before this. */
8100 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8101
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008102 f_ctrs_msc_init();
8103
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008104 var MSC_ConnHdlr vc_conn1;
8105 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8106 pars1.mscpool.rsl_idx := 0;
8107 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
8108 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8109 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008110 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008111
8112 var MSC_ConnHdlr vc_conn2;
8113 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8114 pars2.mscpool.rsl_idx := 1;
8115 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8116 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8117 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008118 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008119
8120 /* Test round-robin wrap to the first MSC */
8121 var MSC_ConnHdlr vc_conn3;
8122 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8123 pars3.mscpool.rsl_idx := 2;
8124 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
8125 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8126 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008127 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008128 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008129}
8130
8131/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 0
8132 * (configured in osmo-bsc.cfg). */
8133/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8134 * just as well using only RSL. */
8135testcase TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() runs on test_CT {
8136
8137 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8138 f_sleep(1.0);
8139
8140 /* Control which MSC gets chosen next by the round-robin, otherwise
8141 * would be randomly affected by which other tests ran before this. */
8142 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8143
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008144 f_ctrs_msc_init();
8145
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008146 var MSC_ConnHdlr vc_conn1;
8147 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8148 pars1.mscpool.rsl_idx := 0;
8149 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
8150 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8151 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008152 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008153
8154 var MSC_ConnHdlr vc_conn2;
8155 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8156 pars2.mscpool.rsl_idx := 1;
8157 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
8158 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8159 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008160 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008161
8162 /* Test round-robin wrap to the first MSC */
8163 var MSC_ConnHdlr vc_conn3;
8164 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8165 pars3.mscpool.rsl_idx := 2;
8166 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
8167 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8168 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008169 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008170 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008171}
8172
8173/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 1
8174 * (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
8175 * NULL-NRI setting is stronger than that. */
8176/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8177 * just as well using only RSL. */
8178testcase TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() runs on test_CT {
8179
8180 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8181 f_sleep(1.0);
8182
8183 /* Control which MSC gets chosen next by the round-robin, otherwise
8184 * would be randomly affected by which other tests ran before this. */
8185 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8186
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008187 f_ctrs_msc_init();
8188
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008189 var MSC_ConnHdlr vc_conn1;
8190 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8191 pars1.mscpool.rsl_idx := 0;
8192 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8193 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8194 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008195 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008196
8197 var MSC_ConnHdlr vc_conn2;
8198 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8199 pars2.mscpool.rsl_idx := 1;
8200 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8201 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8202 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008203 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008204
8205 /* Test round-robin wrap to the first MSC */
8206 var MSC_ConnHdlr vc_conn3;
8207 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8208 pars3.mscpool.rsl_idx := 2;
8209 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8210 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8211 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008212 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008213 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008214}
8215
8216/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI not
8217 * assigned to any MSC (configured in osmo-bsc.cfg). */
8218/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8219 * just as well using only RSL. */
8220testcase TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() runs on test_CT {
8221
8222 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8223 f_sleep(1.0);
8224
8225 /* Control which MSC gets chosen next by the round-robin, otherwise
8226 * would be randomly affected by which other tests ran before this. */
8227 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8228
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008229 f_ctrs_msc_init();
8230
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008231 var MSC_ConnHdlr vc_conn1;
8232 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8233 pars1.mscpool.rsl_idx := 0;
8234 /* An NRI that is not assigned to any MSC */
8235 pars1.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(1023))));
8236 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8237 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008238 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008239
8240 var MSC_ConnHdlr vc_conn2;
8241 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8242 pars2.mscpool.rsl_idx := 1;
8243 /* An NRI that is not assigned to any MSC */
8244 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(768)), '00F110'O));
8245 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8246 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008247 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008248
8249 /* Test round-robin wrap to the first MSC */
8250 var MSC_ConnHdlr vc_conn3;
8251 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8252 pars3.mscpool.rsl_idx := 2;
8253 /* An NRI that is not assigned to any MSC */
8254 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, valueof(ts_MI_TMSI_NRI_LV(819))));
8255 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8256 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008257 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008258 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008259}
8260
8261/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI
8262 * assigned to an MSC that is currently not connected (configured in osmo-bsc.cfg). */
8263/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8264 * just as well using only RSL. */
8265testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() runs on test_CT {
8266
8267 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8268 f_sleep(1.0);
8269
8270 /* Control which MSC gets chosen next by the round-robin, otherwise
8271 * would be randomly affected by which other tests ran before this. */
8272 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8273
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008274 f_ctrs_msc_init();
8275
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008276 var MSC_ConnHdlr vc_conn1;
8277 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8278 pars1.mscpool.rsl_idx := 0;
8279 /* An NRI that is assigned to an unconnected MSC */
8280 pars1.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(512))));
8281 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8282 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008283 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8284 f_ctrs_msc_add(0, "mscpool:subscr:new");
8285 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008286
8287 var MSC_ConnHdlr vc_conn2;
8288 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8289 pars2.mscpool.rsl_idx := 1;
8290 /* An NRI that is assigned to an unconnected MSC */
8291 pars2.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(767))));
8292 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8293 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008294 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8295 f_ctrs_msc_add(1, "mscpool:subscr:new");
8296 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008297
8298 /* Test round-robin wrap to the first MSC */
8299 var MSC_ConnHdlr vc_conn3;
8300 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8301 pars3.mscpool.rsl_idx := 2;
8302 /* An NRI that is assigned to an unconnected MSC */
8303 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(750)), '00F110'O));
8304 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8305 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008306 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8307 f_ctrs_msc_add(0, "mscpool:subscr:new");
8308 f_ctrs_msc_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008309 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008310}
8311
8312/* Three Layer 3 Complete by TMSI with valid NRI for the second MSC are all directed to the second MSC (configured in
8313 * osmo-bsc.cfg). */
8314/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8315 * just as well using only RSL. */
8316testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_1() runs on test_CT {
8317
8318 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8319 f_sleep(1.0);
8320
8321 /* All TMSIs in this test point at the second MSC, set the round robin to point at the first MSC to make sure
8322 * this is not using round-robin. */
8323 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8324
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008325 f_ctrs_msc_init();
8326
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008327 var MSC_ConnHdlr vc_conn1;
8328 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
8329 pars1.mscpool.rsl_idx := 0;
8330 /* An NRI of the second MSC's range (256-511) */
8331 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(256))));
8332 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8333 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008334 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008335
8336 var MSC_ConnHdlr vc_conn2;
8337 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8338 pars2.mscpool.rsl_idx := 1;
8339 /* An NRI of the second MSC's range (256-511) */
8340 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(260))));
8341 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8342 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008343 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008344
8345 var MSC_ConnHdlr vc_conn3;
8346 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
8347 pars3.mscpool.rsl_idx := 2;
8348 /* An NRI of the second MSC's range (256-511) */
8349 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(511)), '00F110'O));
8350 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8351 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008352 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008353 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008354}
8355
8356/* Layer 3 Complete by TMSI with valid NRI for the third MSC are directed to the third MSC (configured in osmo-bsc.cfg),
8357 * while a round-robin remains unaffected by that. */
8358/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8359 * just as well using only RSL. */
8360testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_2() runs on test_CT {
8361
8362 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8363 f_sleep(1.0);
8364
8365 /* All TMSIs in this test point at the third MSC, set the round robin to point at the second MSC to make sure
8366 * this is not using round-robin. */
8367 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
8368
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008369 f_ctrs_msc_init();
8370
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008371 var MSC_ConnHdlr vc_conn1;
8372 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 2);
8373 pars1.mscpool.rsl_idx := 0;
8374 /* An NRI of the third MSC's range (512-767) */
8375 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(512))));
8376 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8377 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008378 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008379
8380 var MSC_ConnHdlr vc_conn2;
8381 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8382 pars2.mscpool.rsl_idx := 1;
8383 /* An NRI of the third MSC's range (512-767) */
8384 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(678))));
8385 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8386 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008387 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008388
8389 /* The above forwardings to third MSC have not affected the round robin, which still points at the second MSC */
8390 var MSC_ConnHdlr vc_conn3;
8391 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
8392 pars3.mscpool.rsl_idx := 2;
8393 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000013'H)), '00F110'O));
8394 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8395 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008396 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008397 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008398}
8399
8400/* LU with a TMSI but indicating a different PLMN in its previous LAI: ignore the NRI. */
8401/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8402 * just as well using only RSL. */
8403testcase TC_mscpool_LU_by_tmsi_from_other_PLMN() runs on test_CT {
8404
8405 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8406 f_sleep(1.0);
8407
8408 /* The TMSIs in this test points at the second MSC, but since it is from a different PLMN, round-robin is used
8409 * instead, and hits msc 0. */
8410 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8411
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008412 f_ctrs_msc_init();
8413
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008414 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-bsc.cfg */
8415 var MSC_ConnHdlr vc_conn1;
8416 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8417 pars1.mscpool.rsl_idx := 0;
8418 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(260)), '99F999'O));
8419 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8420 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008421 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008422
8423 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
8424 var MSC_ConnHdlr vc_conn2;
8425 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8426 pars2.mscpool.rsl_idx := 1;
8427 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(555)), '00F110'O));
8428 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8429 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008430 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008431 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008432}
8433
8434/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by IMSI, which would be
8435 * round-robined to another MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
8436private function f_tc_mscpool_paging_imsi(charstring id) runs on MSC_ConnHdlr {
8437 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
8438 //cid_list := { cIl_allInBSS := ''O };
8439 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
8440 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
8441 var BSSAP_N_UNITDATA_req paging;
8442 var hexstring imsi := '001010000000123'H;
8443
8444 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8445
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008446 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008447 valueof(ts_BSSMAP_Paging(imsi, cid_list, omit, bssmap_chneed))));
8448 BSSAP.send(paging);
8449
8450 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
8451 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
8452 * channel number is picked here. */
8453 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
8454 f_rslem_register(0, new_chan_nr);
8455 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(imsi)));
8456 f_rslem_unregister(0, new_chan_nr);
8457
8458 /* Despite the round robin pointing at the second MSC ('roundrobin next 1'), the earlier Paging for the same IMSI
8459 * causes this Paging Response to go to the first MSC (bssap_idx := 0). */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008460 f_perform_compl_l3(RSL, RSL_PROC, ts_PAG_RESP(valueof(ts_MI_IMSI_LV(imsi))) );
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008461 f_sleep(1.0);
8462}
8463testcase TC_mscpool_paging_and_response_imsi() runs on test_CT {
8464 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
8465 f_sleep(1.0);
8466
8467 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
8468 * second MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
8469 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
8470
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008471 f_ctrs_msc_init();
8472
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008473 var MSC_ConnHdlr vc_conn1;
8474 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8475 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008476 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
8477 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008478 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_imsi), pars1);
8479 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008480 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008481 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008482}
8483
8484/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by TMSI with an NRI value
8485 * that matches a different MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
8486private function f_tc_mscpool_paging_tmsi(charstring id) runs on MSC_ConnHdlr {
8487 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
8488 //cid_list := { cIl_allInBSS := ''O };
8489 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
8490 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
8491 var integer nri_v := 300; /* <-- second MSC's NRI */
Harald Weltebf397612021-01-14 20:39:46 +01008492 var octetstring tmsi := f_gen_tmsi(suffix := 0, nri_v := nri_v);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008493 var BSSAP_N_UNITDATA_req paging;
8494
8495 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8496
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008497 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008498 valueof(ts_BSSMAP_Paging('001010000000011'H, cid_list, tmsi, bssmap_chneed))));
8499 BSSAP.send(paging);
8500
8501 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
8502 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
8503 * channel number is picked here. */
8504 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
8505 f_rslem_register(0, new_chan_nr);
8506 RSL.receive(tr_RSL_PAGING_CMD(t_MI_TMSI(tmsi)));
8507 f_rslem_unregister(0, new_chan_nr);
8508
8509 /* Despite the NRI matching the second MSC (NRI from 'msc 1' in osmo-bsc.cfg) and round robin pointing at the
8510 * third MSC ('roundrobin next 2'), the earlier Paging for the same TMSI causes this Paging Response to go to
8511 * the first MSC (bssap_idx := 0). */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008512 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 +02008513 f_sleep(1.0);
8514}
8515testcase TC_mscpool_paging_and_response_tmsi() runs on test_CT {
8516 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
8517 f_sleep(1.0);
8518
8519 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
8520 * third MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
8521 f_vty_transceive(BSCVTY, "mscpool roundrobin next 2");
8522
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008523 f_ctrs_msc_init();
8524
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008525 var MSC_ConnHdlr vc_conn1;
8526 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8527 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008528 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
8529 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008530 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_tmsi), pars1);
8531 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008532 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008533 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008534}
8535
8536/* For round-robin, skip an MSC that has 'no allow-attach' set. */
8537/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8538 * just as well using only RSL. */
8539testcase TC_mscpool_no_allow_attach_round_robin() runs on test_CT {
8540
8541 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8542 f_sleep(1.0);
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00008543 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
8544 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008545
8546 /* Control which MSC gets chosen next by the round-robin, otherwise
8547 * would be randomly affected by which other tests ran before this. */
8548 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8549
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008550 f_ctrs_msc_init();
8551
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008552 var MSC_ConnHdlr vc_conn1;
8553 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8554 pars1.mscpool.rsl_idx := 0;
8555 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
8556 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8557 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008558 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008559
8560 var MSC_ConnHdlr vc_conn2;
8561 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8562 pars2.mscpool.rsl_idx := 1;
8563 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8564 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8565 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008566 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008567
8568 var MSC_ConnHdlr vc_conn3;
8569 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8570 pars3.mscpool.rsl_idx := 2;
8571 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
8572 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8573 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008574 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008575 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008576}
8577
8578/* An MSC that has 'no allow-attach' set should still serve subscribers that are already attached according to their
8579 * TMSI NRI. */
8580testcase TC_mscpool_no_allow_attach_valid_nri() runs on test_CT {
8581
8582 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8583 f_sleep(1.0);
8584
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00008585 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
8586 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
8587
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008588 /* Control which MSC gets chosen next by the round-robin, otherwise
8589 * would be randomly affected by which other tests ran before this. */
8590 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8591
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008592 f_ctrs_msc_init();
8593
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008594 /* Round robin points at msc 0, but the valid NRI directs to msc 1, even though msc 1 has 'no allow-attach'. */
8595 var MSC_ConnHdlr vc_conn1;
8596 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
8597 pars1.mscpool.rsl_idx := 0;
8598 /* An NRI of the second MSC's range (256-511) */
8599 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_TMSI_NRI_LV(260))));
8600 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8601 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008602 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008603
8604 var MSC_ConnHdlr vc_conn2;
8605 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 0);
8606 pars2.mscpool.rsl_idx := 1;
8607 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8608 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8609 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008610 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008611
8612 var MSC_ConnHdlr vc_conn3;
8613 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 2);
8614 pars3.mscpool.rsl_idx := 2;
8615 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000003'H))));
8616 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8617 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008618 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008619 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008620}
8621
Philipp Maier783681c2020-07-16 16:47:06 +02008622/* Allow/Deny emergency calls globally via VTY */
8623private function f_vty_allow_emerg_msc(boolean allow) runs on test_CT {
8624 f_vty_enter_cfg_msc(BSCVTY, 0);
8625 if (allow) {
8626 f_vty_transceive(BSCVTY, "allow-emergency allow");
8627 } else {
8628 f_vty_transceive(BSCVTY, "allow-emergency deny");
8629 }
8630 f_vty_transceive(BSCVTY, "exit");
8631 f_vty_transceive(BSCVTY, "exit");
8632}
8633
8634/* Allow/Deny emergency calls per BTS via VTY */
8635private function f_vty_allow_emerg_bts(boolean allow, integer bts_nr) runs on test_CT {
8636 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8637 if (allow) {
8638 f_vty_transceive(BSCVTY, "rach emergency call allowed 1");
8639 } else {
8640 f_vty_transceive(BSCVTY, "rach emergency call allowed 0");
8641 }
8642 f_vty_transceive(BSCVTY, "exit");
8643 f_vty_transceive(BSCVTY, "exit");
Neels Hofmeyrb6ed80c2020-10-12 22:52:39 +00008644 f_vty_transceive(BSCVTY, "exit");
Philipp Maier783681c2020-07-16 16:47:06 +02008645}
8646
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02008647/* Allow/Forbid Fast Return after SRVCC on a given BTS via VTY */
8648private function f_vty_allow_srvcc_fast_return(boolean allow, integer bts_nr) runs on test_CT {
8649 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8650 if (allow) {
8651 f_vty_transceive(BSCVTY, "srvcc fast-return allow");
8652 } else {
8653 f_vty_transceive(BSCVTY, "srvcc fast-return forbid");
8654 }
8655 f_vty_transceive(BSCVTY, "exit");
8656 f_vty_transceive(BSCVTY, "exit");
8657 f_vty_transceive(BSCVTY, "exit");
8658}
8659
Pau Espin Pedrol14475352021-07-22 15:48:16 +02008660/* Allow/Forbid TCH for signalling if SDCCH exhausted on a given BTS via VTY */
8661private function f_vty_allow_tch_for_signalling(boolean allow, integer bts_nr) runs on test_CT {
8662 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8663 if (allow) {
8664 f_vty_transceive(BSCVTY, "channel allocator allow-tch-for-signalling 1");
8665 } else {
8666 f_vty_transceive(BSCVTY, "channel allocator allow-tch-for-signalling 0");
8667 }
8668 f_vty_transceive(BSCVTY, "exit");
8669 f_vty_transceive(BSCVTY, "exit");
8670 f_vty_transceive(BSCVTY, "exit");
8671}
8672
Philipp Maier783681c2020-07-16 16:47:06 +02008673/* Begin assignmet procedure and send an EMERGENCY SETUP (RR) */
8674private function f_assignment_emerg_setup() runs on MSC_ConnHdlr {
8675 var PDU_ML3_MS_NW emerg_setup;
8676 var octetstring emerg_setup_enc;
8677 var RSL_Message emerg_setup_data_ind;
8678
8679 f_establish_fully(omit, omit);
8680
8681 emerg_setup := valueof(ts_ML3_MO_CC_EMERG_SETUP(1, valueof(ts_Bcap_voice)));
8682 emerg_setup_enc := enc_PDU_ML3_MS_NW(emerg_setup);
8683 emerg_setup_data_ind := valueof(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), emerg_setup_enc));
8684
8685 RSL.send(emerg_setup_data_ind);
8686}
8687
8688/* Test if the EMERGENCY SETUP gets passed on to the MSC via A when EMERGENCY
8689 * CALLS are permitted by the BSC config. */
8690private function f_TC_assignment_emerg_setup_allow(charstring id) runs on MSC_ConnHdlr {
8691 var PDU_BSSAP emerg_setup_data_ind_bssap;
8692 var PDU_ML3_MS_NW emerg_setup;
8693 timer T := 3.0;
8694
8695 f_assignment_emerg_setup()
8696
8697 T.start;
8698 alt {
8699 [] BSSAP.receive(tr_BSSAP_DTAP) -> value emerg_setup_data_ind_bssap {
8700 emerg_setup := dec_PDU_ML3_MS_NW(emerg_setup_data_ind_bssap.pdu.dtap);
8701 if (not isbound(emerg_setup.msgs.cc.emergencySetup)) {
8702 setverdict(fail, "no emergency setup");
8703 }
8704 }
8705 [] BSSAP.receive {
8706 setverdict(fail, "unexpected BSSAP message!");
8707 }
8708 [] T.timeout {
8709 setverdict(fail, "timout waiting for EMERGENCY SETUP!");
8710 }
8711 }
8712
8713 setverdict(pass);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01008714 f_perform_clear();
Philipp Maier783681c2020-07-16 16:47:06 +02008715}
8716
8717/* Test if the EMERGENCY SETUP gets blocked by the BSC if EMERGENCY CALLS are
8718 * forbidden by the BSC config. */
8719private function f_TC_assignment_emerg_setup_deny(charstring id) runs on MSC_ConnHdlr {
8720 var PDU_BSSAP emerg_setup_data_ind_bssap;
8721 timer T := 3.0;
8722
8723 f_assignment_emerg_setup()
8724
8725 T.start;
8726 alt {
8727 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
8728 setverdict(pass);
8729 }
8730 [] RSL.receive {
8731 setverdict(fail, "unexpected RSL message!");
8732 }
8733 [] T.timeout {
8734 setverdict(fail, "timout waiting for RR CHANNEL RELEASE!");
8735 }
8736 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01008737 BSSAP.receive(tr_BSSMAP_ClearRequest);
Neels Hofmeyrc3c6ee62022-01-26 01:22:12 +01008738 f_perform_clear_no_rr_rel();
Philipp Maier783681c2020-07-16 16:47:06 +02008739}
8740
8741/* EMERGENCY CALL situation #1, allowed globally and by BTS */
8742testcase TC_assignment_emerg_setup_allow() runs on test_CT {
8743 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8744 var MSC_ConnHdlr vc_conn;
8745
8746 f_init(1, true);
8747 f_sleep(1.0);
8748
8749 f_vty_allow_emerg_msc(true);
8750 f_vty_allow_emerg_bts(true, 0);
8751 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_allow), pars);
8752 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008753 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008754}
8755
8756/* EMERGENCY CALL situation #2, forbidden globally but allowed by BTS */
8757testcase TC_assignment_emerg_setup_deny_msc() runs on test_CT {
8758 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8759 var MSC_ConnHdlr vc_conn;
8760
8761 f_init(1, true);
8762 f_sleep(1.0);
8763
8764 f_vty_allow_emerg_msc(false);
8765 f_vty_allow_emerg_bts(true, 0);
8766 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
8767 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008768 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008769}
8770
8771/* EMERGENCY CALL situation #3, allowed globally but forbidden by BTS */
8772testcase TC_assignment_emerg_setup_deny_bts() runs on test_CT {
8773 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8774 var MSC_ConnHdlr vc_conn;
8775
8776 /* Note: This simulates a spec violation by the MS, correct MS
8777 * implementations would not try to establish an emergency call because
8778 * the system information tells in advance that emergency calls are
8779 * not forbidden */
8780
8781 f_init(1, true);
8782 f_sleep(1.0);
8783
8784 f_vty_allow_emerg_msc(true);
8785 f_vty_allow_emerg_bts(false, 0);
8786 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
8787 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008788 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008789}
8790
Philipp Maier82812002020-08-13 18:48:27 +02008791/* Test what happens when an emergency call arrives while all TCH channels are
8792 * busy, the BSC is expected to terminate one call in favor of the incoming
8793 * emergency call */
8794testcase TC_emerg_premption() runs on test_CT {
8795 var ASP_RSL_Unitdata rsl_ud;
8796 var integer i;
8797 var integer chreq_total, chreq_nochan;
8798 var RSL_Message rx_rsl;
8799 var RslChannelNr chan_nr;
8800
8801 f_init(1);
8802 f_sleep(1.0);
8803
8804 f_vty_allow_emerg_msc(true);
8805 f_vty_allow_emerg_bts(true, 0);
8806
8807 /* Fill up all channels on the BTS */
8808 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
8809 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
8810 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS; i := i+1) {
8811 chan_nr := f_chreq_act_ack('33'O, i);
8812 }
8813 IPA_RSL[0].clear;
8814 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
8815 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
8816
8817 /* Send Channel request for emegergency call */
8818 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
8819
8820 /* Expect the BSC to release one (the first) TCH/F on the BTS */
8821 chan_nr := valueof(t_RslChanNr_Bm(1));
8822 f_expect_chan_rel(0, chan_nr, expect_rr_chan_rel := false, expect_rll_rel_req := false);
8823
8824 /* Expect the BSC to send activate/assign the a channel for the emergency call */
8825 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8826 chan_nr := rx_rsl.ies[0].body.chan_nr;
8827 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 33));
8828 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Philipp Maier104f4c02020-09-11 18:12:18 +02008829
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008830 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008831}
8832
8833/* Hopping parameters per a timeslot */
Vadim Yanitskiybc6654a2020-09-13 01:27:40 +07008834private type record length(0..64) of GsmArfcn ArfcnList;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008835private type record FHParamsTs {
8836 boolean enabled,
8837 uint6_t hsn,
8838 uint6_t maio,
8839 ArfcnList ma
8840};
8841
8842/* Hopping parameters per a transceiver */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008843private type record FHParamsTrx {
Philipp Maier798d8952021-10-19 14:43:19 +02008844 GsmBandArfcn arfcn,
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008845 FHParamsTs ts[8]
8846};
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008847
8848/* Randomly generate the hopping parameters for the given timeslot numbers */
8849private function f_TC_fh_params_gen(template integer tr_tn := (1, 3, 5))
8850runs on test_CT return FHParamsTrx {
8851 var FHParamsTrx fhp;
8852
Philipp Maier798d8952021-10-19 14:43:19 +02008853 /* Generate a random ARFCN in the range of 0 - 3. This ARFCN will
8854 * fall in the GSM900 band. */
8855 fhp.arfcn.arfcn := f_rnd_int(3);
8856 fhp.arfcn.pcs := false;
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008857
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008858 for (var integer tn := 0; tn < 8; tn := tn + 1) {
8859 if (not match(tn, tr_tn)) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008860 fhp.ts[tn].enabled := false;
8861 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008862 continue;
8863 }
8864
8865 /* Random HSN / MAIO values: 0..63 */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008866 fhp.ts[tn].hsn := f_rnd_int(64);
8867 fhp.ts[tn].maio := f_rnd_int(64);
8868 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008869
8870 /* Random Mobile Allocation (hopping channels) */
8871 var integer ma_len := 2 + f_rnd_int(9); /* 2..10 channels */
8872 var integer step := 3 + f_rnd_int(4); /* 3..6 stepping */
8873 for (var integer i := 1; i <= ma_len; i := i + 1) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008874 fhp.ts[tn].ma := fhp.ts[tn].ma & { i * step };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008875 }
8876
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008877 fhp.ts[tn].enabled := true;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008878 }
8879
8880 log("f_TC_fh_params_gen(): ", fhp);
8881 return fhp;
8882}
8883
8884/* Make sure that the given Channel Description IE matches the hopping configuration */
8885private function f_TC_fh_params_match_chan_desc(in FHParamsTrx fhp, in ChannelDescription cd)
8886{
8887 var template (present) ChannelDescription tr_cd;
8888 var template (present) MaioHsn tr_maio_hsn;
8889 var uint3_t tn := cd.chan_nr.tn;
8890
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008891 if (fhp.ts[tn].enabled) {
8892 tr_maio_hsn := tr_HsnMaio(fhp.ts[tn].hsn, fhp.ts[tn].maio);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008893 tr_cd := tr_ChanDescH1(cd.chan_nr, tr_maio_hsn);
8894 } else {
Philipp Maier798d8952021-10-19 14:43:19 +02008895 tr_cd := tr_ChanDescH0(cd.chan_nr, fhp.arfcn.arfcn);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008896 }
8897
8898 if (not match(cd, tr_cd)) {
8899 setverdict(fail, "Channel Description IE does not match: ",
8900 cd, " vs expected ", tr_cd);
8901 }
8902}
8903
8904/* Make sure that the given Mobile Allocation IE matches the hopping configuration */
8905private function f_TC_fh_params_match_ma(in FHParamsTrx fhp, uint3_t tn,
8906 in MobileAllocationLV ma)
8907{
8908 var template MobileAllocationLV tr_ma := f_TC_fh_params_gen_tr_ma(fhp, tn, ma);
8909
8910 if (not match(ma, tr_ma)) {
8911 setverdict(fail, "Mobile Allocation IE does not match (tn := ",
8912 tn, "): ", ma, " vs expected: ", tr_ma);
8913 } else {
8914 setverdict(pass);
8915 }
8916}
8917
8918private function f_TC_fh_params_gen_tr_ma(in FHParamsTrx fhp, uint3_t tn,
8919 in MobileAllocationLV ma)
8920return template MobileAllocationLV {
8921 /* Mobile Allocation IE is expected to be empty if hopping is not enabled */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008922 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008923 return { len := 0, ma := ''B };
8924 }
8925
8926 var bitstring full_mask := f_pad_bit(''B, 1024, '0'B);
8927 var bitstring slot_mask := f_pad_bit(''B, 1024, '0'B);
8928 var bitstring ma_mask := ''B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008929
8930 /* Compose the full bit-mask (all channels, up to 1024 entries) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008931 for (var integer i := 0; i < lengthof(fhp.ts); i := i + 1) {
8932 for (var integer j := 0; j < lengthof(fhp.ts[i].ma); j := j + 1) {
8933 if (full_mask[fhp.ts[i].ma[j]] == '1'B)
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008934 { continue; }
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008935 full_mask[fhp.ts[i].ma[j]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008936 }
8937 }
8938
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008939 /* Take ARFCN of the TRX itself into account */
Philipp Maier798d8952021-10-19 14:43:19 +02008940 full_mask[fhp.arfcn.arfcn] := '1'B;
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008941
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008942 /* Compose a bit-mask for the given timeslot number */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008943 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
8944 slot_mask[fhp.ts[tn].ma[i]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008945 }
8946
8947 /* Finally, compose the Mobile Allocation bit-mask */
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07008948 for (var integer i := 1; i < lengthof(full_mask); i := i + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008949 if (full_mask[i] != '1'B)
8950 { continue; }
8951
8952 /* FIXME: ma_mask := ma_mask & slot_mask[i]; // triggers a bug in TITAN */
8953 if (slot_mask[i] == '1'B) {
8954 ma_mask := ma_mask & '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008955 } else {
8956 ma_mask := ma_mask & '0'B;
8957 }
8958 }
8959
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07008960 /* ARFCN 0 (if present) goes to the last position of the bit-mask */
8961 if (full_mask[0] == '1'B) {
8962 /* FIXME: ma_mask := ma_mask & slot_mask[0]; // triggers a bug in TITAN */
8963 if (slot_mask[0] == '1'B) {
8964 ma_mask := ma_mask & '1'B;
8965 } else {
8966 ma_mask := ma_mask & '0'B;
8967 }
8968 }
8969
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008970 /* Ensure that ma_mask is octet-aligned */
Vadim Yanitskiy2aa02522020-09-06 14:05:23 +07008971 var integer ma_mask_len := (lengthof(ma_mask) + 8 - 1) / 8;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008972 ma_mask := f_pad_bit(ma_mask, ma_mask_len * 8, '0'B);
8973
8974 return { len := ma_mask_len, ma := ma_mask };
8975}
8976
Philipp Maier798d8952021-10-19 14:43:19 +02008977/* Configure the appropriate band for a given arfcn, exc */
8978private function f_TC_set_band_by_arfcn(integer bts_nr, GsmBandArfcn arfcn) runs on test_CT
8979{
8980 var charstring band;
8981 var GsmBandArfcn arfcn_ := valueof(ts_GsmBandArfcn(arfcn.arfcn, arfcn.pcs, false));
8982
8983 select (arfcn_) {
8984 case (tr_GsmBandArfcn((259..293), false, ?)) { band := "GSM450"; }
8985 case (tr_GsmBandArfcn((306..340), false, ?)) { band := "GSM480"; }
8986 case (tr_GsmBandArfcn((438..511), false, ?)) { band := "GSM750"; }
8987 case (tr_GsmBandArfcn((128..251), false, ?)) { band := "GSM850"; }
8988 case (tr_GsmBandArfcn((0..124), false, ?)) { band := "GSM900"; }
8989 case (tr_GsmBandArfcn((955..1023), false, ?)) { band := "GSM900"; }
8990 case (tr_GsmBandArfcn((512..885), false, ?)) { band := "DCS1800"; }
8991 case (tr_GsmBandArfcn((512..810), true, ?)) { band := "PCS1900"; }
8992 case else { return; }
8993 }
8994
8995 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8996 f_vty_transceive(BSCVTY, "band " & band);
8997 f_vty_transceive(BSCVTY, "end");
8998}
8999
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009000/* Configure the hopping parameters in accordance with the given record */
9001private function f_TC_fh_params_set(in FHParamsTrx fhp,
9002 uint8_t bts_nr := 0,
9003 uint8_t trx_nr := 0)
9004runs on test_CT {
Philipp Maier798d8952021-10-19 14:43:19 +02009005
9006 f_TC_set_band_by_arfcn(bts_nr, fhp.arfcn);
9007
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009008 /* Enter the configuration node for the given BTS/TRX numbers */
9009 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
9010
Philipp Maier798d8952021-10-19 14:43:19 +02009011 f_vty_transceive(BSCVTY, "arfcn " & int2str(fhp.arfcn.arfcn));
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009012
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009013 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009014 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
9015
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009016 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009017 f_vty_transceive(BSCVTY, "hopping enabled 0");
9018 f_vty_transceive(BSCVTY, "exit"); /* go back */
9019 continue;
9020 }
9021
9022 /* Configure HSN / MAIO values */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009023 f_vty_transceive(BSCVTY, "hopping sequence-number " & int2str(fhp.ts[tn].hsn));
9024 f_vty_transceive(BSCVTY, "hopping maio " & int2str(fhp.ts[tn].maio));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009025
9026 /* Configure the Mobile Allocation (hopping channels) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009027 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
9028 f_vty_transceive(BSCVTY, "hopping arfcn add " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009029 }
9030
9031 f_vty_transceive(BSCVTY, "hopping enabled 1");
9032 f_vty_transceive(BSCVTY, "exit"); /* go back */
9033 }
9034
9035 f_vty_transceive(BSCVTY, "end");
9036}
9037
9038/* Disable frequency hopping on all timeslots */
9039private function f_TC_fh_params_unset(in FHParamsTrx fhp,
9040 uint8_t bts_nr := 0,
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009041 uint8_t trx_nr := 0,
Philipp Maier798d8952021-10-19 14:43:19 +02009042 GsmBandArfcn arfcn := {pcs := false, arfcn := 871})
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009043runs on test_CT {
Philipp Maier798d8952021-10-19 14:43:19 +02009044
9045 f_TC_set_band_by_arfcn(bts_nr, arfcn);
9046
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009047 /* Enter the configuration node for the given BTS/TRX numbers */
9048 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
9049
Philipp Maier798d8952021-10-19 14:43:19 +02009050 f_vty_transceive(BSCVTY, "arfcn " & int2str(arfcn.arfcn));
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009051
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009052 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009053 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
9054
9055 /* Delete all ARFCNs from the Mobile Allocation (if any) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009056 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
9057 f_vty_transceive(BSCVTY, "hopping arfcn del " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009058 }
9059
9060 f_vty_transceive(BSCVTY, "hopping enabled 0");
9061 f_vty_transceive(BSCVTY, "exit"); /* go back */
9062 }
9063
9064 f_vty_transceive(BSCVTY, "end");
9065 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9066}
9067
9068/* Verify presence and correctness of the hopping parameters (HSN, MAIO)
9069 * in the Channel Identification IE of the RSL CHANnel ACTIVation message. */
9070testcase TC_fh_params_chan_activ() runs on test_CT {
9071 var FHParamsTrx fhp := f_TC_fh_params_gen();
9072 var RSL_Message rsl_msg;
9073 var RSL_IE_Body ie;
9074
9075 f_init_vty();
9076
9077 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9078 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9079
9080 f_init(1);
9081
9082 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
9083 for (var integer i := 0; i < 9; i := i + 1) {
9084 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
9085 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9086
9087 /* Make sure that Channel Identification IE is present */
9088 if (not f_rsl_find_ie(rsl_msg, RSL_IE_CHAN_IDENT, ie)) {
9089 setverdict(fail, "RSL Channel Identification IE is absent");
9090 continue;
9091 }
9092
9093 /* Make sure that hopping parameters (HSN/MAIO) match */
9094 f_TC_fh_params_match_chan_desc(fhp, ie.chan_ident.ch_desc.v);
9095
9096 /* "Mobile Allocation shall be included but empty" - let's check this */
9097 if (ie.chan_ident.ma.v.len != 0) {
9098 setverdict(fail, "Mobile Allocation IE is not empty: ",
9099 ie.chan_ident.ma, ", despite it shall be");
9100 continue;
9101 }
9102 }
9103
9104 /* Disable frequency hopping */
9105 f_TC_fh_params_unset(fhp);
9106
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009107 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009108}
9109
9110/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Immediate Assignment */
9111testcase TC_fh_params_imm_ass() runs on test_CT {
9112 var FHParamsTrx fhp := f_TC_fh_params_gen();
9113 var RSL_Message rsl_msg;
9114 var RSL_IE_Body ie;
9115
9116 f_init_vty();
9117
9118 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9119 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9120
9121 f_init(1);
9122
9123 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
9124 for (var integer i := 0; i < 9; i := i + 1) {
9125 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
9126 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9127
9128 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9129 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
9130
9131 /* Make sure that Full Immediate Assign Info IE is present */
9132 if (not f_rsl_find_ie(rsl_msg, RSL_IE_FULL_IMM_ASS_INFO, ie)) {
9133 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
9134 continue;
9135 }
9136
9137 /* Decode the actual Immediate Assignment message */
9138 var GsmRrMessage rr_msg := dec_GsmRrMessage(ie.full_imm_ass_info.payload);
9139 if (not match(rr_msg.header, t_RrHeader(IMMEDIATE_ASSIGNMENT, ?))) {
9140 setverdict(fail, "Failed to match Immediate Assignment: ", rr_msg);
9141 continue;
9142 }
9143
9144 /* Make sure that hopping parameters (HSN/MAIO) match */
9145 f_TC_fh_params_match_chan_desc(fhp, rr_msg.payload.imm_ass.chan_desc);
9146
9147 /* Make sure that the Mobile Allocation IE matches */
9148 f_TC_fh_params_match_ma(fhp, rr_msg.payload.imm_ass.chan_desc.chan_nr.tn,
9149 rr_msg.payload.imm_ass.mobile_allocation);
9150 }
9151
9152 /* Disable frequency hopping */
9153 f_TC_fh_params_unset(fhp);
Philipp Maier82812002020-08-13 18:48:27 +02009154
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009155 f_shutdown_helper();
Philipp Maier82812002020-08-13 18:48:27 +02009156}
9157
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009158/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Assignment Command */
9159testcase TC_fh_params_assignment_cmd() runs on test_CT {
9160 var FHParamsTrx fhp := f_TC_fh_params_gen();
9161 var RSL_Message rsl_msg;
9162 var RSL_IE_Body ie;
9163
9164 f_init_vty();
9165
9166 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9167 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9168
9169 f_init(1);
9170
9171 /* HACK: work around "Couldn't find Expect for CRCX" */
9172 vc_MGCP.stop;
9173
9174 var template PDU_BSSAP ass_cmd := f_gen_ass_req();
9175 ass_cmd.pdu.bssmap.assignmentRequest.codecList := ts_BSSMAP_IE_CodecList({ts_CodecFR});
9176
9177 /* CS domain (TCH): 4 (TCH/F) + 2 (TCH/H) channels available
9178 * NOTE: only 3 SDCCH/4 channels are available on CCCH+SDCCH4+CBCH */
9179 for (var integer i := 0; i < 3; i := i + 1) {
9180 /* Establish a dedicated channel, so we can trigger (late) TCH assignment */
9181 var DchanTuple dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
9182
9183 /* Send a BSSMAP Assignment Command, expect CHANnel ACTIVation */
9184 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
9185 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9186
9187 /* ACKnowledge CHANnel ACTIVation, expect RSL DATA REQuest */
9188 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9189 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
9190
9191 /* Make sure that L3 Information IE is present */
9192 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
9193 setverdict(fail, "RSL L3 Information IE is absent");
9194 continue;
9195 }
9196
9197 /* Decode the L3 message and make sure it is (RR) Assignment Command */
9198 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
9199 if (not match(l3_msg.header, t_RrL3Header(ASSIGNMENT_COMMAND))) {
9200 setverdict(fail, "Failed to match Assignment Command: ", l3_msg);
9201 continue;
9202 }
9203
9204 /* Make sure that hopping parameters (HSN/MAIO) match */
9205 var ChannelDescription chan_desc := l3_msg.payload.ass_cmd.chan_desc;
9206 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9207
9208 /* Make sure that Cell Channel Description IE is present if FH is enabled */
9209 if (chan_desc.h and not ispresent(l3_msg.payload.ass_cmd.cell_chan_desc)) {
Vadim Yanitskiy38d069d2020-09-02 17:18:57 +07009210 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009211 continue;
9212 }
9213
9214 /* Make sure that the Mobile Allocation IE matches (if present) */
9215 var boolean ma_present := ispresent(l3_msg.payload.ass_cmd.mobile_allocation);
9216 if (chan_desc.h and ma_present) {
9217 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9218 l3_msg.payload.ass_cmd.mobile_allocation.v);
9219 } else if (chan_desc.h and not ma_present) {
9220 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9221 continue;
9222 } else if (not chan_desc.h and ma_present) {
9223 setverdict(fail, "FH disabled, but Mobile Allocation IE is present");
9224 continue;
9225 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01009226
9227 f_perform_clear_test_ct(dt);
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009228 }
9229
9230 /* Give the IUT some time to release all channels */
9231 f_sleep(3.0);
9232
9233 /* Disable frequency hopping */
9234 f_TC_fh_params_unset(fhp);
9235
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009236 f_shutdown_helper();
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009237}
9238
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009239/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Handover Command */
9240private function f_TC_fh_params_handover_cmd(in FHParamsTrx fhp)
9241runs on test_CT {
9242 var RSL_Message rsl_msg;
9243 var RSL_IE_Body ie;
9244 var DchanTuple dt;
9245
9246 /* Establish a dedicated channel, so we can trigger handover */
9247 dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
Vadim Yanitskiyc18ff472021-11-18 20:15:37 +03009248 f_sleep(0.5);
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009249
9250 /* Trigger handover from BTS0 to BTS1 */
9251 f_bts_0_cfg(BSCVTY, { "neighbor bts 1" });
9252 f_vty_handover(BSCVTY, 0, 0, dt.rsl_chan_nr, 1);
9253
9254 /* Expect RSL CHANnel ACTIVation on BTS1/TRX0/TS1 */
9255 rsl_msg := f_exp_ipa_rx(1, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9256
9257 /* ACKnowledge channel activation and expect (RR) Handover Command */
9258 f_ipa_tx(1, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9259 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
9260
9261 /* Make sure that L3 Information IE is present */
9262 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
9263 setverdict(fail, "RSL L3 Information IE is absent");
9264 return;
9265 }
9266
9267 /* Decode the L3 message and make sure it is (RR) Handover Command */
9268 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
9269 if (not match(l3_msg.header, t_RrL3Header(HANDOVER_COMMAND))) {
9270 setverdict(fail, "Failed to match Handover Command: ", l3_msg);
9271 return;
9272 }
9273
9274 /* Make sure that we've got SDCCH/8 on TS1 (expected to be hopping) */
9275 var ChannelDescription chan_desc := l3_msg.payload.ho_cmd.chan_desc;
9276 if (not match(chan_desc.chan_nr, t_RslChanNr_SDCCH8(1, ?))) {
9277 setverdict(fail, "Unexpected channel number: ", chan_desc.chan_nr);
9278 return;
9279 }
9280
9281 /* Make sure that hopping parameters (HSN/MAIO) match */
9282 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9283
9284 /* Make sure that Cell Channel Description IE is present */
9285 if (not ispresent(l3_msg.payload.ho_cmd.cell_chan_desc)) {
9286 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
9287 return;
9288 }
9289
9290 /* Make sure that the Mobile Allocation (after time) IE is present and matches */
9291 var boolean ma_present := ispresent(l3_msg.payload.ho_cmd.mobile_allocation);
9292 if (ma_present) {
9293 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9294 l3_msg.payload.ho_cmd.mobile_allocation.v);
9295 } else {
9296 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9297 return;
9298 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01009299
9300 f_perform_clear_test_ct(dt);
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009301}
9302testcase TC_fh_params_handover_cmd() runs on test_CT {
9303 var FHParamsTrx fhp := f_TC_fh_params_gen();
9304
9305 f_init_vty();
9306
9307 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8 on BTS1/TRX0 */
9308 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
9309
9310 f_vty_transceive(BSCVTY, "timeslot 0");
9311 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
9312 f_vty_transceive(BSCVTY, "exit"); /* go back */
9313
9314 f_vty_transceive(BSCVTY, "timeslot 1");
9315 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8");
9316 f_vty_transceive(BSCVTY, "end"); /* we're done */
9317
9318 f_TC_fh_params_set(fhp, 1); /* Enable frequency hopping on BTS1 */
9319 f_vty_transceive(BSCVTY, "drop bts connection 1 oml");
9320
9321 f_init(2);
9322
9323 f_TC_fh_params_handover_cmd(fhp);
9324
9325 /* Disable frequency hopping on BTS1 */
9326 f_TC_fh_params_unset(fhp, 1);
9327
9328 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
9329 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
9330
9331 f_vty_transceive(BSCVTY, "timeslot 0");
9332 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
9333 f_vty_transceive(BSCVTY, "exit"); /* go back */
9334
9335 f_vty_transceive(BSCVTY, "timeslot 1");
9336 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
9337 f_vty_transceive(BSCVTY, "end"); /* we're done */
9338
9339 f_shutdown_helper();
9340}
9341
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009342/* Verify the hopping parameters in System Information Type 4 */
9343testcase TC_fh_params_si4_cbch() runs on test_CT {
9344 var FHParamsTrx fhp := f_TC_fh_params_gen(tr_tn := 1);
9345 var ASP_RSL_Unitdata rx_rsl_ud;
9346 timer T := 5.0;
9347
9348 f_init_vty();
9349
9350 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8+CBCH */
9351 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
9352
9353 f_vty_transceive(BSCVTY, "timeslot 0");
9354 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
9355 f_vty_transceive(BSCVTY, "exit"); /* go back */
9356
9357 f_vty_transceive(BSCVTY, "timeslot 1");
9358 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8+cbch");
9359 f_vty_transceive(BSCVTY, "end"); /* we're done */
9360
9361 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9362 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9363
9364 f_init(1);
9365
9366 T.start;
9367 alt {
9368 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO(RSL_SYSTEM_INFO_4))) -> value rx_rsl_ud {
9369 var RSL_IE_Body ie := rx_rsl_ud.rsl.ies[2].body; /* FULL BCCH Information IE */
9370 var SystemInformation si := dec_SystemInformation(ie.other.payload);
9371
9372 /* Make sure that what we decoded is System Information Type 4 */
9373 if (si.header.message_type != SYSTEM_INFORMATION_TYPE_4) {
9374 setverdict(fail, "RSL FULL BCCH Information IE contains: ", si);
9375 repeat;
9376 }
9377
9378 /* Make sure that CBCH Channel Description IE is present */
9379 if (not ispresent(si.payload.si4.cbch_chan_desc)) {
9380 setverdict(fail, "CBCH Channel Description IE is absent");
9381 break;
9382 }
9383
9384 /* Finally, check the hopping parameters (HSN, MAIO) */
9385 var ChannelDescription chan_desc := si.payload.si4.cbch_chan_desc.v;
9386 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9387
9388 /* 3GPP TS 44.018, section 9.1.36.2 "CBCH Mobile Allocation":
9389 * The CBCH Mobile Allocation IE *shall* be present if FH is enabled. */
9390 if (chan_desc.h and not ispresent(si.payload.si4.cbch_mobile_alloc)) {
9391 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9392 break;
9393 } else if (chan_desc.h and ispresent(si.payload.si4.cbch_mobile_alloc)) {
9394 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9395 si.payload.si4.cbch_mobile_alloc.v);
9396 }
9397 }
9398 [] IPA_RSL[0].receive { repeat; }
9399 [] T.timeout {
9400 setverdict(fail, "Timeout waiting for RSL BCCH INFOrmation (SI4)");
9401 }
9402 }
9403
9404 /* Disable frequency hopping */
9405 f_TC_fh_params_unset(fhp);
9406
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07009407 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009408 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
9409
9410 f_vty_transceive(BSCVTY, "timeslot 0");
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07009411 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009412 f_vty_transceive(BSCVTY, "exit"); /* go back */
9413
9414 f_vty_transceive(BSCVTY, "timeslot 1");
9415 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
9416 f_vty_transceive(BSCVTY, "end"); /* we're done */
9417
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009418 f_shutdown_helper();
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009419}
9420
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009421template (value) PDU_BSSAP_LE ts_BSSMAP_LE_BSSLAP(template (value) BSSLAP_PDU bsslap)
9422 := ts_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, data := enc_BSSLAP_PDU(valueof(bsslap)));
9423
9424private function f_match_bsslap(PDU_BSSAP_LE got_bsslap_msg,
9425 template (present) BSSLAP_PDU expect_bsslap)
9426{
9427 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(got_bsslap_msg.pdu.bssmap.co_info.bsslap_apdu.data);
9428 if (not match(bsslap, expect_bsslap)) {
9429 log("EXPECTING BSSLAP: ", expect_bsslap);
9430 log("GOT BSSLAP: ", bsslap);
9431 setverdict(fail, "BSSLAP is not as expected");
9432 mtc.stop;
9433 }
9434 setverdict(pass);
9435}
9436
9437/* GAD: this is an Ellipsoid point with uncertainty circle, encoded as in 3GPP TS 23.032 §7.3.2. */
9438const octetstring gad_ell_point_unc_circle := '10b0646d0d5f6627'O;
9439
9440private function f_expect_bsslap(template (present) BSSLAP_PDU expect_rx_bsslap) runs on MSC_ConnHdlr {
9441 var PDU_BSSAP_LE rx_bsslap;
9442 BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap);
9443 f_match_bsslap(rx_bsslap, expect_rx_bsslap);
9444}
9445
9446/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9447 * Request on Lb interface. Either with or without the SMLC doing a BSSLAP TA Request. */
9448private function f_lcs_loc_req_for_active_ms(boolean do_ta_request := false) runs on MSC_ConnHdlr {
9449 f_sleep(1.0);
9450
9451 f_establish_fully(omit, omit);
9452 f_bssap_le_register_imsi(g_pars.imsi, omit);
9453
9454 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9455 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9456
9457 var PDU_BSSAP_LE plr;
9458 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9459
9460 if (not do_ta_request) {
9461 /* verify TA Layer 3 in APDU. First the APDU type (BSSLAP), then the BSSLAP data contents. */
9462 var template BSSMAP_LE_IE_APDU expect_apdu := tr_BSSMAP_LE_APDU(BSSMAP_LE_PROT_BSSLAP, ?);
9463 if (not match(plr.pdu.bssmap.perf_loc_req.bsslap_apdu, expect_apdu)) {
9464 log("EXPECTING BSSMAP-LE APDU IE ", expect_apdu);
9465 log("GOT BSSMAP-LE APDU IE ", plr.pdu.bssmap.perf_loc_req.bsslap_apdu);
9466 setverdict(fail, "BSSMAP-LE APDU IE is not as expected");
9467 mtc.stop;
9468 }
9469 var template BSSLAP_PDU expect_ta_layer3 := tr_BSSLAP_TA_Layer3(tr_BSSLAP_IE_TA(0));
9470 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(plr.pdu.bssmap.perf_loc_req.bsslap_apdu.data);
9471 if (not match(bsslap, expect_ta_layer3)) {
9472 log("EXPECTING BSSLAP TA Layer 3: ", expect_ta_layer3);
9473 log("GOT BSSLAP: ", bsslap);
9474 setverdict(fail, "BSSLAP is not as expected");
9475 mtc.stop;
9476 }
9477 /* OsmoBSC directly sent the TA as BSSLAP APDU in the BSSMAP-LE Perform Location Request to the SMLC. The SMLC
9478 * has no need to request the TA from the BSC and directly responds. */
9479 } else {
9480 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9481 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9482 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9483 }
9484
9485 /* SMLC got the TA from the BSC, now responds with geo information data. */
9486 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9487 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9488 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9489
9490 /* The LCS was using an active A-interface conn. It should still remain active after this. */
9491 f_mo_l3_transceive();
9492
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009493 f_perform_clear();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009494
9495 f_sleep(2.0);
9496 setverdict(pass);
9497}
9498
9499/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9500 * Request on Lb interface. Without the SMLC doing a BSSLAP TA Request. */
9501private function f_tc_lcs_loc_req_for_active_ms(charstring id) runs on MSC_ConnHdlr {
9502 f_lcs_loc_req_for_active_ms(false);
9503}
9504testcase TC_lcs_loc_req_for_active_ms() runs on test_CT {
9505 var MSC_ConnHdlr vc_conn;
9506 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9507
9508 f_init(1, true);
9509 f_sleep(1.0);
9510 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms), pars);
9511 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009512 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009513}
9514
9515/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9516 * Request on Lb interface. With the SMLC doing a BSSLAP TA Request. */
9517private function f_tc_lcs_loc_req_for_active_ms_ta_req(charstring id) runs on MSC_ConnHdlr {
9518 f_lcs_loc_req_for_active_ms(true);
9519}
9520testcase TC_lcs_loc_req_for_active_ms_ta_req() runs on test_CT {
9521 var MSC_ConnHdlr vc_conn;
9522 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9523
9524 f_init(1, true);
9525 f_sleep(1.0);
9526 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_ta_req), pars);
9527 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009528 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009529}
9530
9531/* Clear the A-interface conn only, without doing anything on Abis. Useful for LCS, for cases where there is only an A
9532 * conn without an active lchan. */
9533private function f_clear_A_conn() runs on MSC_ConnHdlr
9534{
9535 var BssmapCause cause := 0;
9536 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
9537 BSSAP.receive(tr_BSSMAP_ClearComplete);
9538 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
9539
9540 timer no_more_bssap := 5.0;
9541 no_more_bssap.start;
9542 alt {
9543 [] no_more_bssap.timeout { break; }
9544 [] BSSAP.receive(tr_BSSAP_BSSMAP) {
9545 setverdict(fail, "Expected no more BSSAP after Clear Complete");
9546 mtc.stop;
9547 }
9548 }
9549 setverdict(pass);
9550}
9551
9552/* Verify that the A-interface connection is still working, and then clear it, without doing anything on Abis. Useful
9553 * for LCS, for cases where there is only an A conn without an active lchan. */
9554private function f_verify_active_A_conn_and_clear() runs on MSC_ConnHdlr
9555{
9556 f_logp(BSCVTY, "f_verify_active_A_conn_and_clear: test A link, then clear");
9557
9558 /* When an lchan is active, we can send some L3 data from the BTS side and verify that it shows up on the other
9559 * side towards the MSC. When there is no lchan, this is not possible. To probe whether the A-interface
9560 * connection is still up, we need something that echos back on the A-interface. Another LCS request! */
9561 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9562 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9563 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?));
9564
9565 /* Right, the Perform Location Request showed up on Lb, now we can clear the A conn. */
9566 f_clear_A_conn();
9567 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
9568 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9569}
9570
9571/* With *no* active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9572 * Request on Lb interface. BSC will Page for the subscriber as soon as we (virtual SMLC) request the TA via BSSLAP.
9573 */
9574private function f_tc_lcs_loc_req_for_idle_ms(charstring id) runs on MSC_ConnHdlr {
9575 f_sleep(1.0);
9576
9577 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9578 f_bssap_le_register_imsi(g_pars.imsi, omit);
9579
9580 /* Register to receive the Paging Command */
9581 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9582 g_chan_nr := new_chan_nr;
9583 f_rslem_register(0, g_chan_nr);
9584
9585 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9586 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9587 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9588 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9589
9590 var PDU_BSSAP_LE plr;
9591 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9592
9593 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9594 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9595
9596 /* OsmoBSC needs to Page */
9597 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi)));
9598 f_logp(BSCVTY, "got Paging Command");
9599
9600 /* MS requests channel. Since the Paging was for LCS, the Paging Response does not trigger a Complete Layer 3 to
9601 * the MSC, and releases the lchan directly. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009602 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);
9603 f_expect_lchan_rel(RSL, RSL_PROC);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009604
9605 /* From the Paging Response, the TA is now known to the BSC, and it responds to the SMLC. */
9606
9607 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9608
9609 /* SMLC got the TA from the BSC, now responds with geo information data. */
9610 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9611 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9612
9613 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9614
9615 /* The lchan is gone, the A-interface conn was created for the LCS only.
9616 * Still it is clearly the MSC's job to decide whether to tear down the conn or not. */
9617 f_verify_active_A_conn_and_clear();
9618
9619 f_sleep(2.0);
9620 setverdict(pass);
9621}
9622testcase TC_lcs_loc_req_for_idle_ms() runs on test_CT {
9623 var MSC_ConnHdlr vc_conn;
9624 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9625
9626 f_init(1, true);
9627 f_sleep(1.0);
9628
9629 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9630 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9631
9632 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms), pars);
9633 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009634 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009635}
9636
9637/* With no active lchan, start BSSMAP Perform Location Request on A interface, but omit IMSI; expect failure response.
9638 */
9639private function f_tc_lcs_loc_req_no_subscriber(charstring id) runs on MSC_ConnHdlr {
9640 f_sleep(1.0);
9641
9642 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9643 f_bssap_le_register_imsi(g_pars.imsi, omit);
9644
9645 /* provoke an abort by omitting both IMSI and IMEI */
9646 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9647 valueof(ts_BSSMAP_Perform_Location_Request(omit,
9648 ts_CellId_CGI('262'H, '42'H, 23, 42)))));
9649 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9650
9651 /* BSC tells MSC about failure */
9652 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9653 locationEstimate := omit, positioningData := omit,
9654 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_DATA_MISSING_IN_REQ)));
9655
9656 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9657 f_verify_active_A_conn_and_clear();
9658
9659 f_sleep(2.0);
9660 setverdict(pass);
9661}
9662testcase TC_lcs_loc_req_no_subscriber() runs on test_CT {
9663 var MSC_ConnHdlr vc_conn;
9664 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9665
9666 f_init(1, true);
9667 f_sleep(1.0);
9668
9669 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9670 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9671
9672 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_no_subscriber), pars);
9673 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009674 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009675}
9676
9677/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9678 * BSSMAP-LE Perform Location Response (before or after sending a BSSLAP TA Request) */
9679private function f_lcs_loc_req_for_active_ms_le_timeout(boolean do_ta) runs on MSC_ConnHdlr {
9680 f_sleep(1.0);
9681
9682 f_establish_fully(omit, omit);
9683 f_bssap_le_register_imsi(g_pars.imsi, omit);
9684
9685 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9686 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9687
9688 var PDU_BSSAP_LE plr;
9689 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9690
9691 if (do_ta) {
9692 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9693 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9694 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9695 }
9696
9697 /* SMLC fails to respond, BSC runs into timeout */
9698 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_SYSTEM_FAILURE));
9699 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9700
9701 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9702 locationEstimate := omit, positioningData := omit,
9703 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_SYSTEM_FAILURE)));
9704
9705 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9706 f_verify_active_A_conn_and_clear();
9707
9708 f_sleep(2.0);
9709 setverdict(pass);
9710}
9711
9712/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9713 * BSSMAP-LE Perform Location Response, without sending a BSSLAP TA Request. */
9714private function f_tc_lcs_loc_req_for_active_ms_le_timeout(charstring id) runs on MSC_ConnHdlr {
9715 f_lcs_loc_req_for_active_ms_le_timeout(false);
9716}
9717
9718testcase TC_lcs_loc_req_for_active_ms_le_timeout() runs on test_CT {
9719 var MSC_ConnHdlr vc_conn;
9720 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9721
9722 f_init(1, true);
9723 f_sleep(1.0);
9724 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout), pars);
9725 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009726 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009727}
9728
9729/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9730 * BSSMAP-LE Perform Location Response, after sending a BSSLAP TA Request. */
9731private function f_tc_lcs_loc_req_for_active_ms_le_timeout2(charstring id) runs on MSC_ConnHdlr {
9732 f_lcs_loc_req_for_active_ms_le_timeout(true);
9733}
9734
9735testcase TC_lcs_loc_req_for_active_ms_le_timeout2() runs on test_CT {
9736 var MSC_ConnHdlr vc_conn;
9737 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9738
9739 f_init(1, true);
9740 f_sleep(1.0);
9741 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout2), pars);
9742 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009743 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009744}
9745
9746/* With *no* active lchan, start a Perform Location Request, expecting that the MS will be Paged. */
9747private function f_tc_lcs_loc_req_for_idle_ms_no_pag_resp(charstring id) runs on MSC_ConnHdlr {
9748 f_sleep(1.0);
9749
9750 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9751 f_bssap_le_register_imsi(g_pars.imsi, omit);
9752
9753 /* Register to receive the Paging Command */
9754 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9755 g_chan_nr := new_chan_nr;
9756 f_rslem_register(0, g_chan_nr);
9757
9758 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9759 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9760 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9761 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9762
9763 var PDU_BSSAP_LE plr;
9764 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9765
9766 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9767 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9768
9769 /* OsmoBSC needs to Page */
9770 var PDU_BSSAP_LE rx_bsslap;
9771 alt {
9772 [] RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi))) {
9773 f_logp(BSCVTY, "got Paging Command");
9774 repeat;
9775 }
9776 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
9777 /* MS does not respond to Paging, TA Req runs into timeout. */
9778 f_match_bsslap(rx_bsslap, tr_BSSLAP_Abort(?));
9779 }
9780 }
9781
9782 /* SMLC responds with failure */
9783 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(omit, BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
9784 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9785
9786 /* BSC tells MSC about failure */
9787 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9788 locationEstimate := omit, positioningData := omit,
9789 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_REQUEST_ABORTED)));
9790
9791 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9792 f_verify_active_A_conn_and_clear();
9793
9794 f_sleep(2.0);
9795 setverdict(pass);
9796}
9797testcase TC_lcs_loc_req_for_idle_ms_no_pag_resp() runs on test_CT {
9798 var MSC_ConnHdlr vc_conn;
9799 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9800
9801 f_init(1, true);
9802 f_sleep(1.0);
9803
9804 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9805 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9806
9807 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms_no_pag_resp), pars);
9808 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009809 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009810}
9811
9812/* During an ongoing Location Request, the MS sends a CM Service Request. Expect the same A-conn to be re-used / taken
9813 * over. */
9814private function f_tc_cm_service_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
9815 f_sleep(1.0);
9816
9817 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9818 f_bssap_le_register_imsi(g_pars.imsi, omit);
9819
9820 /* Register to receive the Paging Command */
9821 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9822 g_chan_nr := new_chan_nr;
9823 f_rslem_register(0, g_chan_nr);
9824
9825 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9826 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9827 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9828 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9829
9830 var PDU_BSSAP_LE plr;
9831 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9832
9833 /* As the A-interface conn was established for LCS, the MS coincidentally decides to issue a CM Service Request
9834 * and establish Layer 3. It should use the existing A-interface conn. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009835 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 +02009836 do_clear := false, expect_bssmap_l3 := true);
9837
9838 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9839 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9840
9841 /* OsmoBSC already has an lchan, no need to Page, just returns the TA */
9842 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9843
9844 /* SMLC got the TA from the BSC, now responds with geo information data. */
9845 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9846 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9847 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9848
9849 /* The lchan should still exist, it was from a CM Service Request. */
9850 f_mo_l3_transceive();
9851
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009852 f_perform_clear();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009853
9854 f_sleep(2.0);
9855 setverdict(pass);
9856}
9857testcase TC_cm_service_during_lcs_loc_req() runs on test_CT {
9858 var MSC_ConnHdlr vc_conn;
9859 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9860
9861 f_init(1, true);
9862 f_sleep(1.0);
9863
9864 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9865 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9866
9867 vc_conn := f_start_handler(refers(f_tc_cm_service_during_lcs_loc_req), pars);
9868 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009869 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009870}
9871
9872/* During an ongoing Perform Location Request, do a Handover, an expect a BSSLAP Reset message from the BSC to indicate
9873 * the new lchan after handover. */
9874private function f_tc_ho_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
9875 f_sleep(1.0);
9876
9877 f_establish_fully(omit, omit);
9878 f_bssap_le_register_imsi(g_pars.imsi, omit);
9879
9880 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9881 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9882
9883 var PDU_BSSAP_LE plr;
9884 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9885
9886 /* SMLC ponders the Location Request, in the meantime the BSC decides to handover */
9887 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
9888
9889 var HandoverState hs := {
9890 rr_ho_cmpl_seen := false,
9891 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02009892 old_chan_nr := -,
9893 expect_target_tsc := BTS_TSC[1]
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009894 };
9895 /* issue hand-over command on VTY */
9896 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
9897 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
9898 f_rslem_suspend(RSL1_PROC);
9899
9900 /* From the MGW perspective, a handover is is characterized by
9901 * performing one MDCX operation with the MGW. So we expect to see
9902 * one more MDCX during handover. */
9903 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
9904
9905 alt {
9906 [] as_handover(hs);
9907 }
9908
9909 var PDU_BSSAP_LE rx_bsslap;
9910
9911 interleave {
9912 /* Expect the BSC to inform the MSC about the handover */
9913 [] BSSAP.receive(tr_BSSMAP_HandoverPerformed);
9914
9915 /* Expect the BSC to inform the SMLC about the handover */
9916 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
9917 f_match_bsslap(rx_bsslap, tr_BSSLAP_Reset(BSSLAP_CAUSE_INTRA_BSS_HO));
9918 }
9919 }
9920
9921 /* SMLC now responds with geo information data. */
9922 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9923 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9924 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9925
9926 /* lchan still active */
9927 f_mo_l3_transceive(RSL1);
9928
9929 /* MSC decides it is done now. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009930 f_perform_clear(RSL1, RSL1_PROC);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009931
9932 f_sleep(2.0);
9933 setverdict(pass);
9934}
9935testcase TC_ho_during_lcs_loc_req() runs on test_CT {
9936 var MSC_ConnHdlr vc_conn;
9937 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9938
9939 f_init(2, true);
9940 f_sleep(1.0);
9941 vc_conn := f_start_handler(refers(f_tc_ho_during_lcs_loc_req), pars);
9942 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009943 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009944}
9945
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009946/* Attempt Complete Layer 3 without any MSC available (OS#4832) */
9947private function f_tc_no_msc(charstring id) runs on MSC_ConnHdlr {
9948 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9949
9950 /* Also disable attach for the single connected MSC */
9951 f_vty_msc_allow_attach(BSCVTY, { false });
9952
9953 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) ));
9954 f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
9955
9956 /* No MSC is found, expecting a proper release on RSL */
9957 interleave {
9958 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
9959 f_logp(BSCVTY, "Got RSL RR Release");
9960 }
9961 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
9962 f_logp(BSCVTY, "Got RSL Deact SACCH");
9963 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02009964 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009965 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
9966 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02009967 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009968 }
9969 }
9970 setverdict(pass);
9971}
9972testcase TC_no_msc() runs on test_CT {
9973
9974 f_init(1, true);
9975 f_sleep(1.0);
9976 var MSC_ConnHdlr vc_conn;
9977 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9978
9979 f_ctrs_bsc_init(counternames_bsc_mscpool);
9980
9981 vc_conn := f_start_handler(refers(f_tc_no_msc), pars);
9982 vc_conn.done;
9983
9984 f_ctrs_bsc_add("mscpool:subscr:no_msc");
9985 f_ctrs_bsc_verify();
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009986 f_shutdown_helper();
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009987}
9988
Harald Welte0ea2d5e2018-04-07 21:40:29 +02009989/* Dyn PDCH todo:
9990 * activate OSMO as TCH/F
9991 * activate OSMO as TCH/H
9992 * does the BSC-located PCU socket get the updated INFO?
9993 * what if no PCU is connected at the time?
9994 * is the info correct on delayed PCU (re)connect?
9995 */
Harald Welte94e0c342018-04-07 11:33:23 +02009996
Neels Hofmeyr87857ec2021-04-25 16:17:47 +00009997private function f_TC_refuse_mode_modif_to_vamos(charstring id) runs on MSC_ConnHdlr {
9998 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
9999 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
10000
10001 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
10002 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
10003 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
10004 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
10005 g_pars.ass_codec_list.codecElements[0];
10006 if (isvalue(g_pars.expect_mr_s0_s7)) {
10007 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
10008 g_pars.expect_mr_s0_s7;
10009 }
10010 }
10011 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
10012 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
10013 log("expecting ASS COMPL like this: ", exp_compl);
10014
10015 f_establish_fully(ass_cmd, exp_compl);
10016
Neels Hofmeyr8746b0d2021-06-01 17:25:39 +020010017 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 +000010018
10019 var RSL_Message rsl;
10020
10021 timer T := 5.0;
10022 T.start;
10023 alt {
10024 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
10025 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
10026 log("Rx L3 from net: ", l3);
10027 if (ischosen(l3.msgs.rrm.channelModeModify)) {
10028 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
10029 mtc.stop;
10030 }
10031 }
10032 [] RSL.receive(tr_RSL_MODE_MODIFY_REQ(g_chan_nr, ?)) -> value rsl {
10033 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
10034 mtc.stop;
10035 }
10036 [] T.timeout {
10037 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related Mode Modify should happen. */
10038 setverdict(pass);
10039 }
10040 }
10041 T.stop;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010042
10043 f_perform_clear();
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000010044}
10045
10046/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel Mode Modify to VAMOS mode is refused by
10047 * osmo-bsc. */
10048testcase TC_refuse_mode_modif_to_vamos() runs on test_CT {
10049 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10050 var MSC_ConnHdlr vc_conn;
10051
10052 f_init(1, true);
10053 f_sleep(1.0);
10054
10055 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10056 vc_conn := f_start_handler(refers(f_TC_refuse_mode_modif_to_vamos), pars);
10057 vc_conn.done;
10058 f_shutdown_helper();
10059}
10060
10061/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel activation to VAMOS mode is refused by osmo-bsc.
10062 */
10063testcase TC_refuse_chan_act_to_vamos() runs on test_CT {
10064 f_init_vty();
10065
10066 f_init(1, false);
10067 f_sleep(1.0);
10068
10069 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 activate-vamos fr");
10070
10071 var ASP_RSL_Unitdata rx_rsl_ud;
10072 timer T := 5.0;
10073
10074 T.start;
10075 alt {
10076 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(?, IPAC_PROTO_RSL_TRX0)) -> value rx_rsl_ud {
10077 if (rx_rsl_ud.rsl.msg_type == RSL_MT_CHAN_ACTIV) {
10078 T.stop;
10079 setverdict(fail, "CHANnel ACTivate in VAMOS mode succeeded even though BTS does not support VAMOS");
10080 mtc.stop;
10081 }
10082 repeat;
10083 }
10084 [] T.timeout {
10085 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related CHANnel ACTivate should happen. */
10086 setverdict(pass);
10087 }
10088 }
10089}
10090
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010091private function f_TC_reassignment_codec(charstring id) runs on MSC_ConnHdlr {
10092 /* First fully set up a speech lchan */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010093 f_assignment_codec(id, do_perform_clear := false);
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010094
10095 /* Trigger re-assignment to another lchan */
10096 var AssignmentState assignment_st := valueof(ts_AssignmentStateInit);
10097
10098 /* Re-Assignment should tell the MGW endpoint the new lchan's RTP address and port, so expecting to see exactly
10099 * one MDCX on MGCP. */
10100 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].mdcx_seen_exp + 1;
10101
10102 /* The new lchan will see all-new IPAC_CRCX and IPAC_MDCX messages telling the BTS the same RTP address and port
10103 * as the old lchan used. */
10104 g_media.bts.ipa_crcx_seen := false;
10105 g_media.bts.ipa_mdcx_seen := false;
10106
10107 /* Send different BTS side RTP port number for the new lchan */
10108 g_media.bts.bts.port_nr := 4223;
10109
10110 f_rslem_register(0, valueof(ts_RslChanNr_Bm(2))); /* <-- FIXME: can we somehow infer the timeslot that will be used? */
10111
10112 /* Trigger re-assignment. */
10113 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot " & int2str(g_chan_nr.tn) & " sub-slot 0 assignment");
10114
10115 timer T := 5.0;
10116 T.start;
10117 alt {
10118 [] as_assignment(assignment_st);
10119 [] as_Media();
10120 [] T.timeout {
10121 break;
10122 }
10123 }
10124
10125 if (not assignment_st.assignment_done) {
10126 setverdict(fail, "Assignment did not complete");
10127 mtc.stop;
10128 }
10129
10130 f_check_mgcp_expectations()
10131 setverdict(pass);
10132
10133 f_sleep(2.0);
10134 log("show lchan summary: ", f_vty_transceive_ret(BSCVTY, "show lchan summary"));
10135
10136 /* Instruct BSC to clear channel */
10137 var BssmapCause cause := 0;
10138 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
10139 interleave {
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010140 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {}
10141 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +020010142 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010143 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +020010144 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010145 }
10146 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
10147 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
10148 }
10149 }
Neels Hofmeyr40a45d12021-09-23 22:57:12 +020010150 f_expect_dlcx_conns();
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010151
10152 f_sleep(0.5);
10153}
10154
10155testcase TC_reassignment_fr() runs on test_CT {
10156 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10157 var MSC_ConnHdlr vc_conn;
10158
10159 f_init(1, true);
10160 f_sleep(1.0);
10161
Neels Hofmeyrac432fa2021-11-02 16:45:56 +010010162 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010163
10164 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10165 vc_conn := f_start_handler(refers(f_TC_reassignment_codec), pars);
10166 vc_conn.done;
10167
10168 /* from f_establish_fully() */
10169 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
10170 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
10171 /* from re-assignment */
10172 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
10173 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
10174 f_ctrs_bsc_and_bts_verify();
10175 f_shutdown_helper();
10176}
10177
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010178const charstring REEST_LOST_CONNECTION := "REEST_LOST_CONNECTION";
10179const charstring REEST_CLEAR := "REEST_CLEAR";
10180const charstring REEST_CLEAR_DONE := "REEST_CLEAR_DONE";
10181
10182/* CM Re-Establishment, 3GPP TS 24.008 4.5.1.6.
10183 * The MS <-> BTS loses radio connection, MS shows up on second BTS and asks for CM Re-Establishment.
10184 * BSC should establish a separate A conn for the same MS, the original A conn is then cleared by
10185 * the MSC as the CM Re-Establishment is handled.
10186 *
10187 * MS bts0 bts1 bsc msc test-component
10188 * |<----->|<----------------->|<-0-->| _1 Establish channel on bts 0
10189 * | | _1 wait a bit, to settle down
10190 * |<-x x--| | _1 "lose connection"
10191 * | | REEST_LOST_CONNECTION
10192 * |----------------->|------->|--1-->| _2 new A-conn: Chan Rqd, Imm Ass, Compl L3 with CM Re-Establishment Req
10193 * | | REEST_CLEAR
10194 * | |<-0---| _1 Clear Command on first A-conn
10195 * | |--0-->| _1 Clear Complete
10196 * | |<----------------->| | _1 Release first channel
10197 * | | REEST_CLEAR_DONE
10198 * |<-----------------|<-------|<-1---| _2 Chan Activ, Assignment Command
10199 * |<-----------------|<-------|<-1---| _2 Clear Command, Release
10200 *
10201 */
10202private function f_tc_cm_reestablishment_1(charstring id) runs on MSC_ConnHdlr {
10203 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
10204 var PDU_BSSAP ass_cmd := f_gen_ass_req();
10205
10206 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10207 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10208
10209 f_establish_fully(ass_cmd, exp_compl);
10210
10211 /* The original channel loses connection, MS attemts CM Re-Establishment on another cell, see
10212 * f_tc_cm_reestablishment_2(). This established channel stays active until MSC sends a Clear Command. The time
10213 * when exactly that happens is determined by f_tc_cm_reestablishment_2(). */
10214 f_sleep(2.0);
10215 COORD.send(REEST_LOST_CONNECTION);
10216
10217 alt {
10218 [] COORD.receive(REEST_CLEAR);
10219 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
10220 setverdict(fail, "Unexpected channel release");
10221 mtc.stop;
10222 }
10223 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
10224 setverdict(fail, "Unexpected channel release");
10225 mtc.stop;
10226 }
10227 }
10228 f_perform_clear()
Neels Hofmeyr969abd02021-09-23 22:24:08 +020010229 f_create_mgcp_delete_ep(g_media.mgcp_ep);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010230 COORD.send(REEST_CLEAR_DONE);
10231}
10232
10233private function f_tc_cm_reestablishment_2(charstring id) runs on MSC_ConnHdlr {
10234 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
10235
10236 /* The MS lost the connection on the first channel, now establishes another one */
10237 COORD.receive(REEST_LOST_CONNECTION);
10238
10239 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
10240 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_REESTABL_REQ(mi));
10241 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
10242
10243 f_create_bssmap_exp(l3_enc);
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010244 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 +020010245 BSSAP.receive(tr_BSSMAP_ComplL3(l3_enc));
10246
10247 /* MSC got the CM Re-Establishment request and first off clears the previous conn. */
10248 COORD.send(REEST_CLEAR);
10249 COORD.receive(REEST_CLEAR_DONE);
10250
10251 f_sleep(2.0);
10252
10253 /* Answer the CM Re-Establishment with an Assignment Command. */
10254 var template PDU_BSSAP expect_assignment_compl := f_gen_exp_compl();
10255 var PDU_BSSAP ass_cmd := f_gen_ass_req();
10256 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10257 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10258
10259 var AssignmentState st := valueof(ts_AssignmentStateInit);
10260 st.voice_call := true;
10261 st.is_assignment := true;
10262
10263 var ExpectCriteria mgcpcrit := {
10264 connid := omit,
10265 endpoint := omit,
10266 transid := omit
10267 };
10268 f_create_mgcp_expect(mgcpcrit);
10269
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010270 f_rslem_dchan_queue_enable(RSL1_PROC);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010271
10272 BSSAP.send(ass_cmd);
10273
10274 var PDU_BSSAP bssap;
10275
10276 alt {
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010277 [] as_assignment(st, rsl_pt := RSL1, rsl_proc_pt := RSL1_PROC);
10278 [] as_Media_ipacc(RSL1, RSL2);
10279 [] as_Media_mgw();
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010280 [st.assignment_done] BSSAP.receive(expect_assignment_compl) {
10281 break;
10282 }
10283 }
10284
10285 f_sleep(3.0);
10286
10287 f_logp(BSCVTY, "f_tc_cm_reestablishment_2 clearing");
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010288 f_perform_clear(RSL1, RSL1_PROC);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010289}
10290
10291testcase TC_cm_reestablishment() runs on test_CT {
10292 var TestHdlrParams pars1 := f_gen_test_hdlr_pars();
10293 var MSC_ConnHdlr vc_conn1;
10294
10295 var TestHdlrParams pars2 := f_gen_test_hdlr_pars();
10296 var MSC_ConnHdlr vc_conn2;
10297 pars2.imsi := pars1.imsi;
10298 pars2.media_nr := 2;
Neels Hofmeyrbf720202021-10-02 12:58:24 +020010299 pars2.expect_tsc := BTS_TSC[1];
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010300
10301 f_init(2, true, guard_timeout := 40.0);
10302 f_sleep(1.0);
10303
10304 vc_conn1 := f_start_handler_create(pars1);
10305 vc_conn2 := f_start_handler_create(pars2);
10306 connect(vc_conn1:COORD, vc_conn2:COORD);
10307 f_start_handler_run(vc_conn1, refers(f_tc_cm_reestablishment_1), pars1);
10308 f_start_handler_run(vc_conn2, refers(f_tc_cm_reestablishment_2), pars2);
10309 vc_conn1.done;
10310 vc_conn2.done;
10311
10312 f_shutdown_helper();
10313}
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000010314
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010315function f_exp_ipa_rx_nonfatal(integer bts_nr, template (present) RSL_Message t_rx, float t_secs := 2.0,
10316 IpaStreamId sid := IPAC_PROTO_RSL_TRX0, boolean ignore_other_rx := true)
10317runs on test_CT return template (omit) RSL_Message {
10318 var ASP_RSL_Unitdata rx_rsl_ud;
10319 timer T := t_secs;
10320
10321 T.start;
10322 alt {
10323 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
10324 T.stop;
10325 }
10326 [ignore_other_rx] IPA_RSL[bts_nr].receive { repeat; }
10327 [not ignore_other_rx] IPA_RSL[bts_nr].receive {
10328 log("f_exp_ipa_rx_nonfatal(): Got different message than ", t_rx);
10329 T.stop;
10330 return omit;
10331 }
10332 [] T.timeout {
10333 return omit;
10334 }
10335 }
10336 return rx_rsl_ud.rsl;
10337}
10338
10339private function f_vty_set_imm_ass(TELNETasp_PT pt, BtsNr bts_nr := 0, charstring imm_ass_setting := "post-chan-ack") {
10340 f_vty_enter_cfg_bts(pt, bts_nr);
10341 f_vty_transceive(pt, "immediate-assignment " & imm_ass_setting);
10342 f_vty_transceive(pt, "exit");
10343 f_vty_transceive(pt, "exit");
10344 f_vty_transceive(pt, "exit");
10345}
10346
10347private function f_verify_imm_ass(RSL_Message imm_ass, template uint8_t ra := ?, template GsmFrameNumber fn := ?,
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010348 template RslChannelNr chan_nr := ?,
10349 template (present) uint12_t arfcn := ?,
10350 template (present) uint3_t tsc := ?)
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010351{
10352 var RSL_IE_Body full_imm_ass_info;
10353 if (not f_rsl_find_ie(imm_ass, RSL_IE_FULL_IMM_ASS_INFO, full_imm_ass_info)) {
10354 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
10355 mtc.stop;
10356 }
10357
10358 var GsmRrMessage rr_imm_ass := dec_GsmRrMessage(full_imm_ass_info.full_imm_ass_info.payload);
10359 var template GsmRrMessage expect_imm_ass := tr_IMM_ASS(ra := ra,
10360 fn := fn,
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010361 ch_desc := tr_ChanDescH0(chan_nr, arfcn, tsc),
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010362 page_mode := ?);
10363 if (not match(rr_imm_ass, expect_imm_ass)) {
10364 log("Error: expected ", expect_imm_ass, " got ", rr_imm_ass);
10365 setverdict(fail, "Failed to match Immediate Assignment");
10366 mtc.stop;
10367 }
10368}
10369
10370testcase TC_imm_ass_post_chan_ack() runs on test_CT {
10371 var RSL_Message chan_act;
10372 var RSL_Message imm_ass;
10373
10374 f_init(1, false);
10375 f_sleep(1.0);
10376
10377 /* (should be the default anyway, just to make things clear) */
10378 f_vty_set_imm_ass(BSCVTY, 0, "post-chan-ack");
10379
10380 /* RA containing reason=LU */
10381 var GsmFrameNumber fn := 2342;
10382 var uint8_t ra := 2;
10383 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10384
10385 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10386
10387 /* First send the Chan Act ACK */
10388 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010389 var DchanTuple dt;
10390 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010391 var RSL_IE_Body chan_ident_ie;
10392 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10393 setverdict(fail, "RSL Channel Identification IE is absent");
10394 mtc.stop;
10395 }
10396
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010397 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn + 10));
10398
10399 /* Then expect the Immediate Assignment, after we ACKed the chan act */
10400 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10401
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010402 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10403 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010404
10405 /* Check that the lchan is working */
10406 var octetstring l3 := '00010203040506'O;
10407 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10408
10409 var BSSAP_N_CONNECT_ind rx_c_ind;
10410 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010411 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010412 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10413
10414 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010415 f_perform_clear_test_ct(dt);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010416 f_shutdown_helper();
10417}
10418
10419testcase TC_imm_ass_pre_chan_ack() runs on test_CT {
10420 var RSL_Message chan_act;
10421 var RSL_Message imm_ass;
10422
10423 f_init(1, false);
10424 f_sleep(1.0);
10425
10426 f_vty_set_imm_ass(BSCVTY, 0, "pre-chan-ack");
10427
10428 /* RA containing reason=LU */
10429 var GsmFrameNumber fn := 2342;
10430 var uint8_t ra := 2;
10431 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10432
10433 /* (set bts 0 cfg back to default) */
10434 f_vty_set_imm_ass(BSCVTY);
10435
10436 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10437 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010438 var DchanTuple dt;
10439 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010440 var RSL_IE_Body chan_ident_ie;
10441 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10442 setverdict(fail, "RSL Channel Identification IE is absent");
10443 mtc.stop;
10444 }
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010445
10446 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10447 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010448 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10449 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010450
10451 /* Only now send the Chan Act ACK */
10452 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10453
10454 /* Check that the lchan is working */
10455 var octetstring l3 := '00010203040506'O;
10456 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10457
10458 var BSSAP_N_CONNECT_ind rx_c_ind;
10459 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010460 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010461 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10462
10463 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010464 f_perform_clear_test_ct(dt);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010465 f_shutdown_helper();
10466}
10467
Neels Hofmeyr23158742021-09-07 19:08:07 +020010468testcase TC_imm_ass_pre_ts_ack() runs on test_CT {
10469 var RSL_Message chan_act;
10470 var RSL_Message imm_ass;
10471
10472 f_init(1, false);
10473 f_sleep(1.0);
10474
10475 f_vty_set_imm_ass(BSCVTY, 0, "pre-ts-ack");
10476
10477 /* RA containing reason=LU */
10478 var GsmFrameNumber fn := 2342;
10479 var uint8_t ra := 2;
10480 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10481
10482 /* (set bts 0 cfg back to default) */
10483 f_vty_set_imm_ass(BSCVTY);
10484
10485 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10486 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010487 var DchanTuple dt;
10488 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyr23158742021-09-07 19:08:07 +020010489 var RSL_IE_Body chan_ident_ie;
10490 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10491 setverdict(fail, "RSL Channel Identification IE is absent");
10492 mtc.stop;
10493 }
10494
10495 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10496 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10497 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10498 chan_ident_ie.chan_ident.ch_desc.v.tsc);
10499
10500 /* Only now send the Chan Act ACK */
10501 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10502
10503 /* Check that the lchan is working */
10504 var octetstring l3 := '00010203040506'O;
10505 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10506
10507 var BSSAP_N_CONNECT_ind rx_c_ind;
10508 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010509 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyr23158742021-09-07 19:08:07 +020010510 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10511
10512 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010513 f_perform_clear_test_ct(dt);
Neels Hofmeyr23158742021-09-07 19:08:07 +020010514 f_shutdown_helper();
10515}
10516
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010517testcase TC_imm_ass_pre_chan_ack_dyn_ts() runs on test_CT {
10518 /* change Timeslot 6 before f_init() starts RSL */
10519 f_init_vty();
10520 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
10521 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10522
10523 f_init(1, false);
10524 f_sleep(1.0);
10525
10526 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
10527 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010528 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010529 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2323));
10530
10531 /* clean up timeslot 6 config, will only take effect when the OML drops the next time */
10532 f_ts_set_chcomb(0, 0, 6, "PDCH");
10533
10534 /* block all static timeslots so that the dyn TS will be used */
10535 f_disable_all_tch_f();
10536 f_disable_all_tch_h();
10537 f_disable_all_sdcch();
10538
10539 var RSL_Message chan_act;
10540 var RSL_Message imm_ass;
10541
10542 f_init(1, false);
10543 f_sleep(1.0);
10544
10545 f_vty_set_imm_ass(BSCVTY, 0, "pre-chan-ack");
10546
10547 /* RA containing reason=LU */
10548 var GsmFrameNumber fn := 2342;
10549 var uint8_t ra := 2;
10550 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10551
10552 /* (set bts 0 cfg back to default) */
10553 f_vty_set_imm_ass(BSCVTY);
10554
10555 /* Expect the dyn TS to deactivate PDCH first */
10556 f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
10557 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
10558
10559 /* Now activation as SDCCH8 */
10560 chan_nr := valueof(t_RslChanNr_SDCCH8(tn := 6, sub_slot := 0));
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010561 var DchanTuple dt;
10562 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010563
10564 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010565 var RSL_IE_Body chan_ident_ie;
10566 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10567 setverdict(fail, "RSL Channel Identification IE is absent");
10568 mtc.stop;
10569 }
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010570
10571 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10572 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010573 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10574 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010575
10576 /* Only now send the Chan Act ACK */
10577 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10578
10579 /* Check that the lchan is working */
10580 var octetstring l3 := '00010203040506'O;
10581 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10582
10583 var BSSAP_N_CONNECT_ind rx_c_ind;
10584 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010585 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010586 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10587
10588 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010589 f_perform_clear_test_ct(dt);
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010590 f_shutdown_helper();
10591}
10592
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010593testcase TC_imm_ass_pre_ts_ack_dyn_ts() runs on test_CT {
10594 /* change Timeslot 6 before f_init() starts RSL */
10595 f_init_vty();
10596 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
10597 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10598
10599 f_init(1, false);
10600 f_sleep(1.0);
10601
10602 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
10603 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010604 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010605 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2323));
10606
10607 /* clean up timeslot 6 config, will only take effect when the OML drops the next time */
10608 f_ts_set_chcomb(0, 0, 6, "PDCH");
10609
10610 /* block all static timeslots so that the dyn TS will be used */
10611 f_disable_all_tch_f();
10612 f_disable_all_tch_h();
10613 f_disable_all_sdcch();
10614
10615 var RSL_Message chan_act;
10616 var RSL_Message imm_ass;
10617
10618 f_init(1, false);
10619 f_sleep(1.0);
10620
10621 f_vty_set_imm_ass(BSCVTY, 0, "pre-ts-ack");
10622
10623 /* RA containing reason=LU */
10624 var GsmFrameNumber fn := 2342;
10625 var uint8_t ra := 2;
10626 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10627
10628 /* (set bts 0 cfg back to default) */
10629 f_vty_set_imm_ass(BSCVTY);
10630
10631 /* Expect the dyn TS to deactivate PDCH first */
10632 f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
10633
10634 /* And already the Immediate Assignment even before the PDCH Deact ACK */
10635 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10636
10637 /* continue the Osmo style PDCH Deact (usual chan rel) */
10638 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
10639
10640 /* Now activation as SDCCH8 */
10641 chan_nr := valueof(t_RslChanNr_SDCCH8(tn := 6, sub_slot := 0));
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010642 var DchanTuple dt;
10643 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010644
10645 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010646 var RSL_IE_Body chan_ident_ie;
10647 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10648 setverdict(fail, "RSL Channel Identification IE is absent");
10649 mtc.stop;
10650 }
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010651 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10652
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010653 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10654 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010655
10656 /* Check that the lchan is working */
10657 var octetstring l3 := '00010203040506'O;
10658 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10659
10660 var BSSAP_N_CONNECT_ind rx_c_ind;
10661 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010662 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010663 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10664
10665 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010666 f_perform_clear_test_ct(dt);
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010667 f_shutdown_helper();
10668}
10669
Neels Hofmeyr5d7d13f2021-09-07 14:44:36 +020010670/* GET and SET the bts.N.trx.M.rf_locked CTRL variable */
10671testcase TC_ctrl_trx_rf_locked() runs on test_CT {
10672 var MSC_ConnHdlr vc_conn;
10673
10674 f_init(nr_bts := 2, handler_mode := true, nr_msc := 1);
10675 f_sleep(1.0);
10676
10677 /* BTS 0, 1, 2 are OML unlocked, only BTS 0, 1 are actually connected to RSL. */
10678 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10679 "0,0,operational,unlocked,on,rsl-up;" &
10680 "1,0,operational,unlocked,on,rsl-up;" &
10681 "2,0,operational,unlocked,on,rsl-down;" &
10682 "3,0,inoperational,locked,on,rsl-down;");
10683
10684 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: lock BTS 1 TRX 0");
10685 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "1");
10686 /* give it a moment to settle the FSM status */
10687 f_sleep(1.0);
10688
10689 /* Now BTS 1 TRX 0 should reflect "locked". Note the RF policy stays "on", because this is still handled
10690 * globally in osmo-bsc. Probably after sending "rf_locked 1" for a TRX, that TRX should reflect an RF policy
10691 * of "off"? But that's for a future patch if at all. */
10692 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10693 "0,0,operational,unlocked,on,rsl-up;" &
10694 "1,0,operational,locked,on,rsl-up;" &
10695 "2,0,operational,unlocked,on,rsl-down;" &
10696 "3,0,inoperational,locked,on,rsl-down;");
10697
10698 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: lock the already locked TRX, nothing should change");
10699 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "1");
10700 f_sleep(1.0);
10701 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10702 "0,0,operational,unlocked,on,rsl-up;" &
10703 "1,0,operational,locked,on,rsl-up;" &
10704 "2,0,operational,unlocked,on,rsl-down;" &
10705 "3,0,inoperational,locked,on,rsl-down;");
10706
10707 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock BTS 1 TRX 0");
10708 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "0");
10709 f_sleep(1.0);
10710 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10711 "0,0,operational,unlocked,on,rsl-up;" &
10712 "1,0,operational,unlocked,on,rsl-up;" &
10713 "2,0,operational,unlocked,on,rsl-down;" &
10714 "3,0,inoperational,locked,on,rsl-down;");
10715
10716 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock an already unlocked TRX, nothing should change");
10717 f_ctrl_set(IPA_CTRL, "bts.0.trx.0.rf_locked", "0");
10718 f_sleep(1.0);
10719 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10720 "0,0,operational,unlocked,on,rsl-up;" &
10721 "1,0,operational,unlocked,on,rsl-up;" &
10722 "2,0,operational,unlocked,on,rsl-down;" &
10723 "3,0,inoperational,locked,on,rsl-down;");
10724
10725 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock an inoperational TRX");
10726 f_ctrl_set(IPA_CTRL, "bts.3.trx.0.rf_locked", "0");
10727 f_sleep(1.0);
10728 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10729 "0,0,operational,unlocked,on,rsl-up;" &
10730 "1,0,operational,unlocked,on,rsl-up;" &
10731 "2,0,operational,unlocked,on,rsl-down;" &
10732 "3,0,inoperational,locked,on,rsl-down;");
10733
10734 f_shutdown_helper();
10735}
10736
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010737const CounterNameVals counternames_cm_serv_rej := {
10738 { "cm_serv_rej", 0 },
10739 { "cm_serv_rej:imsi_unknown_in_hlr", 0 },
10740 { "cm_serv_rej:illegal_ms", 0 },
10741 { "cm_serv_rej:imsi_unknown_in_vlr", 0 },
10742 { "cm_serv_rej:imei_not_accepted", 0 },
10743 { "cm_serv_rej:illegal_me", 0 },
10744 { "cm_serv_rej:plmn_not_allowed", 0 },
10745 { "cm_serv_rej:loc_not_allowed", 0 },
10746 { "cm_serv_rej:roaming_not_allowed", 0 },
10747 { "cm_serv_rej:network_failure", 0 },
10748 { "cm_serv_rej:synch_failure", 0 },
10749 { "cm_serv_rej:congestion", 0 },
10750 { "cm_serv_rej:srv_opt_not_supported", 0 },
10751 { "cm_serv_rej:rqd_srv_opt_not_supported", 0 },
10752 { "cm_serv_rej:srv_opt_tmp_out_of_order", 0 },
10753 { "cm_serv_rej:call_can_not_be_identified", 0 },
10754 { "cm_serv_rej:incorrect_message", 0 },
10755 { "cm_serv_rej:invalid_mandantory_inf", 0 },
10756 { "cm_serv_rej:msg_type_not_implemented", 0 },
10757 { "cm_serv_rej:msg_type_not_compatible", 0 },
10758 { "cm_serv_rej:inf_eleme_not_implemented", 0 },
10759 { "cm_serv_rej:condtional_ie_error", 0 },
10760 { "cm_serv_rej:msg_not_compatible", 0 },
10761 { "cm_serv_rej:protocol_error", 0 },
10762 { "cm_serv_rej:retry_in_new_cell", 0 }
10763};
10764
10765private function f_TC_cm_serv_rej(charstring id) runs on MSC_ConnHdlr
10766{
10767 f_create_chan_and_exp();
Vadim Yanitskiya7fc5a62021-12-04 20:10:08 +030010768 /* we should now have a COMPL_L3 at the MSC */
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010769 BSSAP.send(ts_PDU_DTAP_MT(ts_CM_SERV_REJ('02'O), '00'O));
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010770 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_CM_SERV_REJ));
10771 f_perform_clear();
Neels Hofmeyr87a65612021-11-16 15:56:45 +010010772 f_sleep(1.0);
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010773}
10774testcase TC_cm_serv_rej() runs on test_CT {
10775 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10776 var MSC_ConnHdlr vc_conn;
10777
10778 f_init(1, true);
10779 f_sleep(1.0);
10780
10781 f_ctrs_bts_init(1, counternames_cm_serv_rej);
10782
10783 vc_conn := f_start_handler(refers(f_TC_cm_serv_rej), pars);
10784 vc_conn.done;
10785
10786 f_ctrs_bts_add(0, "cm_serv_rej", 1);
10787 f_ctrs_bts_add(0, "cm_serv_rej:imsi_unknown_in_hlr", 1);
10788 f_ctrs_bts_verify();
10789
Neels Hofmeyr87a65612021-11-16 15:56:45 +010010790 f_sleep(1.0);
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010791 f_shutdown_helper();
10792}
10793
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010794/* Reproduce a segfault happening when the SDCCH (primary) lchan is lost in-between a TCH Channel Activ and its Channel
10795 * Activ Ack (SYS#5627). */
10796private function f_TC_lost_sdcch_during_assignment(charstring id) runs on MSC_ConnHdlr {
10797 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Vadim Yanitskiyf0310e32021-10-26 00:30:59 +030010798
10799 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10800 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010801
10802 var BSSMAP_FIELD_CodecType codecType;
10803 codecType := valueof(ass_cmd.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType);
10804
10805 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
10806
10807 /* First establish a signalling lchan */
10808 f_create_chan_and_exp();
10809 f_rslem_dchan_queue_enable();
10810
10811 /* we should now have a COMPL_L3 at the MSC */
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010812
10813 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
10814 activate(as_Media_mgw());
10815
10816 var RslChannelNr chan_nr := { u := { ch0 := RSL_CHAN_NR_Bm_ACCH }, tn := 1 };
10817 f_rslem_register(0, chan_nr);
10818
10819 f_rslem_set_auto_chan_act_ack(RSL_PROC, false);
10820 BSSAP.send(ass_cmd);
10821
10822
10823 /* Wait for the Channel Activ for the TCH channel */
10824 var ASP_RSL_Unitdata rx_rsl_ud;
10825 RSL.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV), sid := ?)) -> value rx_rsl_ud;
10826
10827 /* make the original SDCCH disappear */
10828 RSL.send(ts_RSL_REL_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
10829
10830 /* and ACK the TCH channel activation. This caused a segfault up to OsmoBSC 1.7.0 (SYS#5627) */
10831 RSL.send(ts_ASP_RSL_UD(ts_RSL_CHAN_ACT_ACK(chan_nr, 23), rx_rsl_ud.streamId));
10832
10833 interleave {
10834 [] BSSAP.receive(tr_BSSMAP_AssignmentFail);
10835 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
10836 }
10837
10838 BSSAP.send(ts_BSSMAP_ClearCommand(0));
10839 BSSAP.receive(tr_BSSMAP_ClearComplete);
10840 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
10841
10842 var MgcpCommand mgcp;
10843 MGCP.receive(tr_DLCX()) -> value mgcp {
10844 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
10845 };
10846
10847 f_sleep(0.5);
10848}
10849testcase TC_lost_sdcch_during_assignment() runs on test_CT {
10850 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10851 var MSC_ConnHdlr vc_conn;
10852
10853 f_init(1, true);
10854 f_sleep(1.0);
10855
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010856 vc_conn := f_start_handler(refers(f_TC_lost_sdcch_during_assignment), pars);
10857 vc_conn.done;
10858
10859 f_shutdown_helper();
10860}
10861
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010862const CounterNameVals counternames_bsc_bts_all_available_allocated := {
10863 { "all_allocated:sdcch", 0 },
10864 { "all_allocated:static_sdcch", 0 },
10865 { "all_allocated:tch", 0 },
10866 { "all_allocated:static_tch", 0 }
10867}
10868
10869private function f_all_allocated_expect_counter_change(charstring_list expect_changed) runs on test_CT
10870{
10871 /* Make sure counters settle first */
10872 f_sleep(1.0);
10873
10874 /* Take a baseline of counters */
10875 f_ctrs_bsc_and_bts_init(1, counternames_bsc_bts_all_available_allocated);
10876
10877 /* Elapse some time so that we see changes in counters, hopefully where expected */
10878 f_sleep(2.0);
10879
10880 /* Get new counters */
10881 var charstring_list all_changed := {};
10882 all_changed := all_changed & f_counter_name_vals_get_changed_n(IPA_CTRL, "bsc", g_ctr_bsc);
10883 all_changed := all_changed & f_counter_name_vals_get_changed_n(IPA_CTRL, "bts", g_ctr_bts);
10884
10885 /* Compare with expectations */
10886 var charstring_list all_expect_changed := {};
10887 for (var integer i := 0; i < lengthof(expect_changed); i := i + 1) {
10888 all_expect_changed := all_expect_changed & { "bsc.0." & expect_changed[i], "bts.0." & expect_changed[i] };
10889 }
10890 f_counter_name_vals_expect_changed_list(all_changed, all_expect_changed);
10891}
10892
10893testcase TC_ratectr_all_available_allocated() runs on test_CT {
10894 var ASP_RSL_Unitdata rsl_ud;
10895 var integer i;
10896 var integer chreq_total, chreq_nochan;
10897
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010898 f_init(1, guard_timeout := 60.0);
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010899 f_sleep(1.0);
10900
10901 /* Exhaust all dedicated SDCCH lchans.
10902 /* GSM 44.018 Table 9.1.8.2:
10903 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
10904 */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010905 var DchanTuples chan_cleanup := {};
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010906 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010907 chan_cleanup := chan_cleanup & { f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010908 }
10909
10910 /* Since only bts 0 is connected, expecting all_allocated to become true for both bts 0 and the "global" bsc
10911 * level.
10912 * All SDCCH are now occupied. */
10913 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch"});
10914
10915 /* Also fill up all remaining (TCH) channels */
10916 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010917 chan_cleanup := chan_cleanup & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010918 }
10919
10920 /* All TCH are now also occupied */
10921 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch",
10922 "all_allocated:tch", "all_allocated:static_tch"});
10923
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010924 /* Clean up SDCCH lchans */
10925 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
10926 f_perform_clear_test_ct(chan_cleanup[i]);
10927 }
10928
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010929 f_shutdown_helper();
10930}
10931
10932testcase TC_ratectr_all_available_allocated_dyn() runs on test_CT {
10933 var ASP_RSL_Unitdata rsl_ud;
10934 var integer i;
10935 var integer chreq_total, chreq_nochan;
10936
10937 f_init_vty();
10938 f_ts_set_chcomb(0, 0, 2, "TCH/F_TCH/H_PDCH");
10939 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10940 /* Now we have 3 TCH/F, 1 OSMO_DYN, 1 TCH/H */
10941
10942 f_init(1, guard_timeout := 60.0);
10943 f_sleep(1.0);
10944
10945 /* The dyn TS wants to activate PDCH mode, ACK that. */
10946 var RslChannelNr chan_nr;
10947 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010948 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010949 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
10950
10951 /* Exhaust all dedicated SDCCH lchans.
10952 /* GSM 44.018 Table 9.1.8.2:
10953 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
10954 */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010955 var DchanTuples chan_cleanup := {};
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010956 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010957 chan_cleanup := chan_cleanup & { f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010958 }
10959
10960 /* The static SDCCH should now be occupied, while still 3x8 dynamic SDCCH potentially remain. So only
10961 * all_allocated:static_sdcch is counted, all_allocated:sdcch remains zero. */
10962 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch"});
10963
10964 /* Request more SDCCH, hence convert the first dyn TS to SDCCH8.
10965 * Will release them later, so remember all the DchanTuples. */
10966 var DchanTuples dyn_sddch := {};
10967 dyn_sddch := dyn_sddch & { f_est_dchan_dyn('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
10968
10969 /* Also occupy the seven other SDCCH of the dyn TS */
10970 for (i := 0; i < 7; i := i+1) {
10971 dyn_sddch := dyn_sddch & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
10972 }
10973
10974 /* Now all dynamic SDCCH are also occupied, so for the first time all_allocated:sdcch will trigger... */
10975 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch"});
10976
10977 /* occupy the remaining TCH, three TCH/F and two TCH/H lchans */
10978 for (i := 0; i < 5; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010979 chan_cleanup := chan_cleanup & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010980 }
10981
10982 /* All TCH lchans are now also occupied, both static and dynamic */
10983 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch",
10984 "all_allocated:tch", "all_allocated:static_tch"});
10985
10986 /* Starting to release the dyn TS: as soon as the first SDCCH gets released, all_allocated:sdcch stops
10987 * incrementing. */
10988 var BssmapCause cause := 0;
10989 var DchanTuple dt := dyn_sddch[0];
10990 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
10991 f_exp_chan_rel_and_clear(dt, 0);
10992
10993 /* one dyn TS SDCCH is free again, so only the static_sdcch should increment. For tch, both static and dynamic
10994 * count as occupied, so those still both increment. */
10995 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch",
10996 "all_allocated:tch", "all_allocated:static_tch"});
10997
10998 /* Release the remaining SDCCH of the dyn TS, so it becomes available as TCH again */
10999 for (i := 1; i < lengthof(dyn_sddch); i := i+1) {
11000 dt := dyn_sddch[i];
11001 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
11002 f_exp_chan_rel_and_clear(dt, 0);
11003 }
11004
11005 /* All SDCCH on the dyn TS are released, the dyn TS wants to activate PDCH again */
11006 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060011007 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011008 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
11009
11010 /* Now all channels are occupied except the dyn TS, so expecting only the static counters to increment */
11011 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch", "all_allocated:static_tch"});
11012
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011013 /* Clean up SDCCH lchans */
11014 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
11015 f_perform_clear_test_ct(chan_cleanup[i]);
11016 }
11017
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011018 /* clean up config */
11019 f_ts_reset_chcomb(0);
11020
11021 f_shutdown_helper();
11022}
11023
Harald Welte28d943e2017-11-25 15:00:50 +010011024control {
Harald Welte898113b2018-01-31 18:32:21 +010011025 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +010011026 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +010011027 execute( TC_ctrl_msc0_connection_status() );
Neels Hofmeyrf65ce872021-09-23 18:40:10 +020011028 /* In SCCPlite tests, only one MSC is configured. These tests assume that three MSCs are configured, so only run
11029 * these in the AoIP test suite. */
11030 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11031 execute( TC_stat_num_msc_connected_1() );
11032 execute( TC_stat_num_msc_connected_2() );
11033 execute( TC_stat_num_msc_connected_3() );
11034 }
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +020011035 execute( TC_stat_num_bts_connected_1() );
11036 execute( TC_stat_num_bts_connected_2() );
11037 execute( TC_stat_num_bts_connected_3() );
Harald Welte96c94412017-12-09 03:12:45 +010011038 execute( TC_ctrl() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +020011039 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER) {
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +020011040 execute( TC_ctrl_location() );
11041 }
Harald Welte898113b2018-01-31 18:32:21 +010011042
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020011043 execute( TC_si_default() );
Neels Hofmeyr66aeba42020-07-06 02:21:21 +020011044 execute( TC_si2quater_2_earfcns() );
11045 execute( TC_si2quater_3_earfcns() );
11046 execute( TC_si2quater_4_earfcns() );
11047 execute( TC_si2quater_5_earfcns() );
11048 execute( TC_si2quater_6_earfcns() );
Neels Hofmeyrad132f22020-07-08 02:20:16 +020011049 execute( TC_si2quater_12_earfcns() );
11050 execute( TC_si2quater_23_earfcns() );
11051 execute( TC_si2quater_32_earfcns() );
11052 execute( TC_si2quater_33_earfcns() );
11053 execute( TC_si2quater_42_earfcns() );
11054 execute( TC_si2quater_48_earfcns() );
11055 execute( TC_si2quater_49_earfcns() );
Pau Espin Pedrol85a84432020-07-20 18:45:03 +020011056 execute( TC_si_acc_rotate() );
Alexander Couzens4ad3a352020-09-10 22:29:12 +020011057 execute( TC_si_acc_ramp_rotate() );
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020011058
Harald Welte898113b2018-01-31 18:32:21 +010011059 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +010011060 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +010011061 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +010011062 execute( TC_chan_act_ack_noest() );
Philipp Maier9c60a622020-07-09 15:08:46 +020011063 execute( TC_chan_act_ack_noest_emerg() );
Philipp Maier606f07d2020-08-12 17:21:58 +020011064 execute( TC_chan_rqd_emerg_deny() );
Harald Welteae026692017-12-09 01:03:01 +010011065 execute( TC_chan_act_ack_est_ind_noreply() );
11066 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +010011067 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +010011068 execute( TC_chan_exhaustion() );
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +070011069 execute( TC_chan_deact_silence() );
Harald Welte4003d112017-12-09 22:35:39 +010011070 execute( TC_chan_rel_rll_rel_ind() );
11071 execute( TC_chan_rel_conn_fail() );
11072 execute( TC_chan_rel_hard_clear() );
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +020011073 execute( TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() );
11074 execute( TC_chan_rel_last_eutran_plmn_hard_clear_csfb() );
Harald Welte99787102019-02-04 10:41:36 +010011075 execute( TC_chan_rel_hard_clear_csfb() );
Harald Welted8c36cd2017-12-09 23:05:31 +010011076 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +020011077 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +010011078 execute( TC_chan_rel_a_reset() );
Pau Espin Pedrolc675b612020-01-09 19:55:40 +010011079 execute( TC_chan_rel_sccp_tiar_timeout() );
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +020011080 execute( TC_chan_rel_rr_cause() );
Harald Welte6f521d82017-12-11 19:52:02 +010011081
Harald Weltecfe2c962017-12-15 12:09:32 +010011082 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +010011083
11084 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +010011085 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +010011086 execute( TC_assignment_csd() );
11087 execute( TC_assignment_ctm() );
11088 execute( TC_assignment_sign() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +020011089 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11090 execute( TC_assignment_aoip_tla_v6() );
11091 }
Harald Welte235ebf12017-12-15 14:18:16 +010011092 execute( TC_assignment_fr_a5_0() );
11093 execute( TC_assignment_fr_a5_1() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +020011094 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte8f67d1d2018-05-25 20:38:42 +020011095 execute( TC_assignment_fr_a5_1_codec_missing() );
11096 }
Harald Welte235ebf12017-12-15 14:18:16 +010011097 execute( TC_assignment_fr_a5_3() );
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +020011098 execute( TC_assignment_fr_a5_4() );
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +020011099 execute( TC_assignment_fr_a5_4_fail() );
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +020011100 execute( TC_assignment_fr_a5_not_sup() );
Harald Welte3c86ea02018-05-10 22:28:05 +020011101 execute( TC_ciph_mode_a5_0() );
11102 execute( TC_ciph_mode_a5_1() );
Oliver Smith50b98122021-07-09 15:00:28 +020011103 execute( TC_ciph_mode_a5_2_0() );
Oliver Smith1dff88d2021-07-09 08:45:51 +020011104 execute( TC_ciph_mode_a5_2_1() );
Harald Welte3c86ea02018-05-10 22:28:05 +020011105 execute( TC_ciph_mode_a5_3() );
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +020011106 execute( TC_ciph_mode_a5_4() );
Harald Welte16a4adf2017-12-14 18:54:01 +010011107
Harald Welte60aa5762018-03-21 19:33:13 +010011108 execute( TC_assignment_codec_fr() );
Neels Hofmeyr559d5d02021-04-16 16:50:49 +020011109 execute( TC_assignment_codec_fr_by_mode_modify() );
Harald Welte60aa5762018-03-21 19:33:13 +010011110 execute( TC_assignment_codec_hr() );
11111 execute( TC_assignment_codec_efr() );
11112 execute( TC_assignment_codec_amr_f() );
11113 execute( TC_assignment_codec_amr_h() );
Philipp Maier8a581d22019-03-26 18:32:48 +010011114
Neels Hofmeyrf246a922020-05-13 02:27:10 +020011115 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier8a581d22019-03-26 18:32:48 +010011116 execute( TC_assignment_codec_amr_f_S1() );
11117 execute( TC_assignment_codec_amr_h_S1() );
11118 execute( TC_assignment_codec_amr_f_S124() );
11119 execute( TC_assignment_codec_amr_h_S124() );
11120 execute( TC_assignment_codec_amr_f_S0() );
11121 execute( TC_assignment_codec_amr_f_S02() );
11122 execute( TC_assignment_codec_amr_f_S024() );
11123 execute( TC_assignment_codec_amr_f_S0247() );
11124 execute( TC_assignment_codec_amr_h_S0() );
11125 execute( TC_assignment_codec_amr_h_S02() );
11126 execute( TC_assignment_codec_amr_h_S024() );
11127 execute( TC_assignment_codec_amr_h_S0247() );
11128 execute( TC_assignment_codec_amr_f_S01234567() );
11129 execute( TC_assignment_codec_amr_f_S0234567() );
11130 execute( TC_assignment_codec_amr_f_zero() );
11131 execute( TC_assignment_codec_amr_f_unsupp() );
11132 execute( TC_assignment_codec_amr_h_S7() );
Neels Hofmeyr21863562020-11-26 00:34:33 +000011133 execute( TC_assignment_codec_amr_f_start_mode_auto() );
11134 execute( TC_assignment_codec_amr_h_start_mode_auto() );
Neels Hofmeyr3eb94562020-11-26 02:40:26 +000011135 execute( TC_assignment_codec_amr_f_start_mode_4() );
11136 execute( TC_assignment_codec_amr_h_start_mode_4() );
Neels Hofmeyr454d7922020-11-26 02:24:57 +000011137 execute( TC_assignment_codec_amr_startmode_cruft() );
Philipp Maier8a581d22019-03-26 18:32:48 +010011138 }
Harald Welte60aa5762018-03-21 19:33:13 +010011139
Philipp Maierac09bfc2019-01-08 13:41:39 +010011140 execute( TC_assignment_codec_fr_exhausted_req_hr() );
11141 execute( TC_assignment_codec_fr_exhausted_req_fr() );
11142 execute( TC_assignment_codec_fr_exhausted_req_fr_hr() );
11143 execute( TC_assignment_codec_fr_exhausted_req_hr_fr() );
11144 execute( TC_assignment_codec_hr_exhausted_req_fr() );
11145 execute( TC_assignment_codec_hr_exhausted_req_hr() );
11146 execute( TC_assignment_codec_hr_exhausted_req_hr_fr() );
11147 execute( TC_assignment_codec_hr_exhausted_req_fr_hr() );
11148 execute( TC_assignment_codec_req_hr_fr() );
11149 execute( TC_assignment_codec_req_fr_hr() );
Pau Espin Pedrol14475352021-07-22 15:48:16 +020011150 execute( TC_assignment_sdcch_exhausted_req_signalling() );
11151 execute( TC_assignment_sdcch_exhausted_req_signalling_tch_forbidden() );
11152 execute( TC_assignment_sdcch_exhausted_req_voice_tch_forbidden() );
Philipp Maierac09bfc2019-01-08 13:41:39 +010011153
Pau Espin Pedrol23510fb2021-07-20 17:00:38 +020011154 execute( TC_assignment_osmux() );
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +020011155
Harald Welte898113b2018-01-31 18:32:21 +010011156 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +010011157 execute( TC_rll_est_ind_inact_lchan() );
11158 execute( TC_rll_est_ind_inval_sapi1() );
11159 execute( TC_rll_est_ind_inval_sapi3() );
11160 execute( TC_rll_est_ind_inval_sacch() );
11161
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +070011162 /* DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
11163 execute( TC_tch_dlci_link_id_sapi() );
11164
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +070011165 /* SAPI N Reject triggered by RLL establishment failures */
11166 execute( TC_rll_rel_ind_sapi_n_reject() );
11167 execute( TC_rll_err_ind_sapi_n_reject() );
11168 execute( TC_rll_timeout_sapi_n_reject() );
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +070011169 execute( TC_rll_sapi_n_reject_dlci_cc() );
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +070011170
Harald Welte898113b2018-01-31 18:32:21 +010011171 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +010011172 execute( TC_paging_imsi_nochan() );
11173 execute( TC_paging_tmsi_nochan() );
11174 execute( TC_paging_tmsi_any() );
11175 execute( TC_paging_tmsi_sdcch() );
11176 execute( TC_paging_tmsi_tch_f() );
11177 execute( TC_paging_tmsi_tch_hf() );
11178 execute( TC_paging_imsi_nochan_cgi() );
11179 execute( TC_paging_imsi_nochan_lac_ci() );
11180 execute( TC_paging_imsi_nochan_ci() );
11181 execute( TC_paging_imsi_nochan_lai() );
11182 execute( TC_paging_imsi_nochan_lac() );
11183 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +010011184 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
11185 execute( TC_paging_imsi_nochan_rnc() );
11186 execute( TC_paging_imsi_nochan_lac_rnc() );
11187 execute( TC_paging_imsi_nochan_lacs() );
11188 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +010011189 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +010011190 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +010011191 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +010011192 execute( TC_paging_counter() );
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +010011193 execute( TC_paging_resp_unsol() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +010011194
11195 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +010011196 execute( TC_rsl_unknown_unit_id() );
11197
11198 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +010011199
11200 execute( TC_classmark() );
Harald Welteeddf0e92020-06-21 19:42:15 +020011201 execute( TC_common_id() );
Harald Welte898113b2018-01-31 18:32:21 +010011202 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +010011203 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +010011204 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +010011205 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +010011206 execute( TC_err_84_unknown_msg() );
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010011207
Harald Welte261af4b2018-02-12 21:20:39 +010011208 execute( TC_ho_int() );
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +020011209 execute( TC_ho_int_a5_0() );
11210 execute( TC_ho_int_a5_1() );
11211 execute( TC_ho_int_a5_3() );
11212 execute( TC_ho_int_a5_4() );
Neels Hofmeyr5f144212020-11-03 15:41:58 +000011213 execute( TC_ho_int_radio_link_failure() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011214
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +010011215 /* TC_ho_out_of_this_bsc is run last, see comment below */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +020011216 execute( TC_ho_out_fail_no_msc_response() );
11217 execute( TC_ho_out_fail_rr_ho_failure() );
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +020011218 execute( TC_ho_out_fail_no_result_after_ho_cmd() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011219
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010011220 execute( TC_ho_into_this_bsc() );
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +020011221 execute( TC_ho_into_this_bsc_a5_0() );
11222 execute( TC_ho_into_this_bsc_a5_1() );
11223 execute( TC_ho_into_this_bsc_a5_3() );
11224 execute( TC_ho_into_this_bsc_a5_4() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +020011225 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11226 execute( TC_ho_into_this_bsc_tla_v6() );
11227 }
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +020011228 execute( TC_srvcc_eutran_to_geran() );
Pau Espin Pedrol35801c32021-04-19 13:03:20 +020011229 execute( TC_srvcc_eutran_to_geran_ho_out() );
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +020011230 execute( TC_srvcc_eutran_to_geran_forbid_fast_return() );
11231 execute( TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011232 execute( TC_ho_in_fail_msc_clears() );
11233 execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
11234 execute( TC_ho_in_fail_no_detect() );
11235 execute( TC_ho_in_fail_no_detect2() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +010011236
Neels Hofmeyr91401012019-07-11 00:42:35 +020011237 execute( TC_ho_neighbor_config_1() );
11238 execute( TC_ho_neighbor_config_2() );
11239 execute( TC_ho_neighbor_config_3() );
11240 execute( TC_ho_neighbor_config_4() );
11241 execute( TC_ho_neighbor_config_5() );
11242 execute( TC_ho_neighbor_config_6() );
11243 execute( TC_ho_neighbor_config_7() );
11244
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +010011245 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010011246 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +010011247 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +020011248
11249 execute( TC_dyn_pdch_ipa_act_deact() );
11250 execute( TC_dyn_pdch_ipa_act_nack() );
11251 execute( TC_dyn_pdch_osmo_act_deact() );
11252 execute( TC_dyn_pdch_osmo_act_nack() );
Pau Espin Pedrol37a4c152021-11-16 19:02:23 +010011253 execute( TC_dyn_ts_sdcch8_act_deact() );
11254 execute( TC_dyn_ts_sdcch8_all_subslots_used() );
11255 execute( TC_dyn_ts_sdcch8_tch_call_act_deact() );
11256 execute( TC_dyn_ts_sdcch8_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +020011257
Stefan Sperling0796a822018-10-05 13:01:39 +020011258 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +020011259 execute( TC_chopped_ipa_payload() );
Stefan Sperling0796a822018-10-05 13:01:39 +020011260
Pau Espin Pedrol8f773632019-11-05 11:46:53 +010011261 /* Power control related */
11262 execute( TC_assignment_verify_ms_power_params_ie() );
Vadim Yanitskiy4b233042021-06-30 00:58:43 +020011263 execute( TC_c0_power_red_mode() );
Neels Hofmeyr4f118412020-06-04 15:25:10 +020011264
11265 /* MSC pooling */
11266 /* FIXME: in SCCPlite, indicating how many MSCs should be connected does currently not work. Since
11267 * RESET->RESET-ACK is unconditionally negotiated for all configured MSCs, they always all appear as connected
11268 * to osmo-bsc. The MSC pooling tests however require disconnecting selected MSCs, and hence don't work out as
11269 * intended on SCCPlite. So for now, run these only for SCCP/M3UA. */
11270 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11271 execute( TC_mscpool_L3Compl_on_1_msc() );
11272 execute( TC_mscpool_L3Complete_by_imsi_round_robin() );
11273 execute( TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() );
11274 execute( TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() );
11275 execute( TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() );
11276 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() );
11277 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_1() );
11278 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_2() );
11279 execute( TC_mscpool_LU_by_tmsi_from_other_PLMN() );
11280 execute( TC_mscpool_paging_and_response_imsi() );
11281 execute( TC_mscpool_paging_and_response_tmsi() );
11282 execute( TC_mscpool_no_allow_attach_round_robin() );
11283 execute( TC_mscpool_no_allow_attach_valid_nri() );
11284 }
11285
Harald Welte99f3ca02018-06-14 13:40:29 +020011286 execute( TC_early_conn_fail() );
11287 execute( TC_late_conn_fail() );
Oliver Smithaf03bef2021-08-24 15:34:51 +020011288 execute( TC_stats_conn_fail() );
Harald Welte99f3ca02018-06-14 13:40:29 +020011289
Philipp Maier783681c2020-07-16 16:47:06 +020011290 /* Emergency call handling (deny / allow) */
11291 execute( TC_assignment_emerg_setup_allow() );
11292 execute( TC_assignment_emerg_setup_deny_msc() );
11293 execute( TC_assignment_emerg_setup_deny_bts() );
Philipp Maier82812002020-08-13 18:48:27 +020011294 execute( TC_emerg_premption() );
11295
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +070011296 /* Frequency hopping parameters handling */
11297 execute( TC_fh_params_chan_activ() );
11298 execute( TC_fh_params_imm_ass() );
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +070011299 execute( TC_fh_params_assignment_cmd() );
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +070011300 execute( TC_fh_params_handover_cmd() );
Vadim Yanitskiyca974032020-09-01 07:20:39 +070011301 execute( TC_fh_params_si4_cbch() );
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020011302
11303 if (mp_enable_lcs_tests) {
11304 execute( TC_lcs_loc_req_for_active_ms() );
11305 execute( TC_lcs_loc_req_for_active_ms_ta_req() );
11306 execute( TC_lcs_loc_req_for_idle_ms() );
11307 execute( TC_lcs_loc_req_no_subscriber() );
11308 execute( TC_lcs_loc_req_for_active_ms_le_timeout() );
11309 execute( TC_lcs_loc_req_for_active_ms_le_timeout2() );
11310 execute( TC_lcs_loc_req_for_idle_ms_no_pag_resp() );
11311 execute( TC_cm_service_during_lcs_loc_req() );
11312 execute( TC_ho_during_lcs_loc_req() );
11313 }
Neels Hofmeyrbf037052020-10-28 22:52:02 +000011314
11315 execute( TC_no_msc() );
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000011316
11317 execute( TC_refuse_chan_act_to_vamos() );
11318 execute( TC_refuse_mode_modif_to_vamos() );
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000011319
11320 execute( TC_reassignment_fr() );
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020011321
11322 execute( TC_cm_reestablishment() );
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020011323
11324 execute( TC_imm_ass_post_chan_ack() );
11325 execute( TC_imm_ass_pre_chan_ack() );
Neels Hofmeyr23158742021-09-07 19:08:07 +020011326 execute( TC_imm_ass_pre_ts_ack() );
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020011327 execute( TC_imm_ass_pre_chan_ack_dyn_ts() );
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020011328 execute( TC_imm_ass_pre_ts_ack_dyn_ts() );
Neels Hofmeyr5d7d13f2021-09-07 14:44:36 +020011329
11330 execute( TC_ctrl_trx_rf_locked() );
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011331
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011332 execute( TC_ratectr_all_available_allocated() );
11333 execute( TC_ratectr_all_available_allocated_dyn() );
11334
Neels Hofmeyrb7581872021-11-07 14:02:49 +010011335 execute( TC_cm_serv_rej() );
11336
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011337 execute( TC_lost_sdcch_during_assignment() );
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +010011338
11339 /* Run TC_ho_out_of_this_bsc last, because it may trigger a segfault before osmo-bsc's patch
11340 * with change-id I5a3345ab0005a73597f5c27207480912a2f5aae6 */
11341 execute( TC_ho_out_of_this_bsc() );
Harald Welte28d943e2017-11-25 15:00:50 +010011342}
11343
11344}