blob: 891d3402f90a20e4d46c3b9c6a284680ee36609f [file] [log] [blame]
Harald Welte28d943e2017-11-25 15:00:50 +01001module BSC_Tests {
2
Harald Welte21b46bd2017-12-17 19:46:32 +01003/* Integration Tests for OsmoBSC
Harald Weltea0630032018-03-20 21:09:55 +01004 * (C) 2017-2018 by Harald Welte <laforge@gnumonks.org>
Harald Welte21b46bd2017-12-17 19:46:32 +01005 * All rights reserved.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
Harald Welte34b5a952019-05-27 11:54:11 +020010 * SPDX-License-Identifier: GPL-2.0-or-later
11 *
Harald Welte21b46bd2017-12-17 19:46:32 +010012 * This test suite tests OsmoBSC while emulating both multiple BTS + MS as
13 * well as the MSC. See README for more details.
14 *
15 * There are test cases that run in so-called 'handler mode' and test cases
16 * that run directly on top of the BSSAP and RSL CodecPorts. The "handler mode"
17 * tests abstract the multiplexing/demultiplexing of multiple SCCP connections
18 * and/or RSL channels and are hence suitable for higher-level test cases, while
19 * the "raw" tests directly on top of the CodecPorts are more suitable for lower-
20 * level testing.
21 */
22
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +020023friend module BSC_Tests_VAMOS;
24
Neels Hofmeyr4f118412020-06-04 15:25:10 +020025import from Misc_Helpers all;
Harald Welte4003d112017-12-09 22:35:39 +010026import from General_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010027import from Osmocom_Types all;
Harald Welteae026692017-12-09 01:03:01 +010028import from GSM_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010029import from IPL4asp_Types all;
30
Harald Welte6f521d82017-12-11 19:52:02 +010031import from BSSAP_Types all;
Harald Welte6811d102019-04-14 22:23:14 +020032import from RAN_Adapter all;
Harald Welte47cd0e32020-08-21 12:39:11 +020033import from BSSAP_LE_Adapter all;
34import from BSSAP_LE_CodecPort all;
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020035import from BSSAP_LE_Types all;
36import from BSSLAP_Types all;
Harald Welteae026692017-12-09 01:03:01 +010037import from BSSAP_CodecPort all;
38import from BSSMAP_Templates all;
Harald Welte28d943e2017-11-25 15:00:50 +010039import from IPA_Emulation all;
Stefan Sperling830dc9d2018-02-12 21:08:28 +010040import from IPA_CodecPort all;
Harald Welteae026692017-12-09 01:03:01 +010041import from IPA_Types all;
Stefan Sperling0796a822018-10-05 13:01:39 +020042import from IPA_Testing all;
Harald Welteae026692017-12-09 01:03:01 +010043import from RSL_Types all;
Harald Welte624f9632017-12-16 19:26:04 +010044import from RSL_Emulation all;
Daniel Willmann191e0d92018-01-17 12:44:35 +010045import from MGCP_Emulation all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010046import from MGCP_Templates all;
47import from MGCP_Types all;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +020048import from MGCP_CodecPort all;
Harald Welte28d943e2017-11-25 15:00:50 +010049
Harald Welte96c94412017-12-09 03:12:45 +010050import from Osmocom_CTRL_Functions all;
Harald Weltea5d2ab22017-12-09 14:21:42 +010051import from Osmocom_CTRL_Types all;
Harald Welteffe55fc2018-01-17 22:39:54 +010052import from Osmocom_CTRL_Adapter all;
Harald Welte96c94412017-12-09 03:12:45 +010053
Daniel Willmannebdecc02020-08-12 15:30:17 +020054import from StatsD_Types all;
55import from StatsD_CodecPort all;
56import from StatsD_CodecPort_CtrlFunct all;
57import from StatsD_Checker all;
58
Harald Weltebc03c762018-02-12 18:09:38 +010059import from Osmocom_VTY_Functions all;
60import from TELNETasp_PortType all;
61
Harald Welte6f521d82017-12-11 19:52:02 +010062import from MobileL3_CommonIE_Types all;
Harald Weltee3bd6582018-01-31 22:51:25 +010063import from MobileL3_Types all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010064import from MobileL3_RRM_Types all;
Harald Welte6f521d82017-12-11 19:52:02 +010065import from L3_Templates all;
66import from GSM_RR_Types all;
67
Stefan Sperlingc307e682018-06-14 15:15:46 +020068import from SCCP_Templates all;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010069import from BSSMAP_Templates all;
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020070import from BSSMAP_LE_Templates all;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010071
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010072import from SCCPasp_Types all;
73
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020074import from GSM_SystemInformation all;
75import from GSM_RestOctets all;
Neels Hofmeyrad132f22020-07-08 02:20:16 +020076import from TCCConversion_Functions all;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020077
Neels Hofmeyrbf720202021-10-02 12:58:24 +020078type record of integer integer_list;
79
Harald Welte5d1a2202017-12-13 19:51:29 +010080const integer NUM_BTS := 3;
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +020081const integer NUM_BTS_CFG := 4; /* we have 4 BTS in the osmo-bsc.cfg (for inter-BSC HO tests) but use only 3 */
Neels Hofmeyrf246a922020-05-13 02:27:10 +020082const integer NUM_MSC := 3;
Harald Welteae026692017-12-09 01:03:01 +010083const float T3101_MAX := 12.0;
Harald Welte28d943e2017-11-25 15:00:50 +010084
Harald Welte799c97b2017-12-14 17:50:30 +010085/* make sure to sync this with the osmo-bts.cfg you're using */
Philipp Maiercb6cc482018-03-26 13:08:00 +020086const integer NUM_TCHH_PER_BTS := 2;
87const integer NUM_TCHF_PER_BTS := 4;
Neels Hofmeyr74083c22020-07-29 00:43:01 +020088const integer NUM_SDCCH_PER_BTS := 3;
Harald Welte799c97b2017-12-14 17:50:30 +010089
Neels Hofmeyrbf720202021-10-02 12:58:24 +020090/* Default Training Sequence Code expected for bts[i]:
91 * BTS 0 has BSIC 10 (and no explicit timeslot training_sequence_code config), so expecting TSC = (BSIC & 7) = 2.
92 * BTS 1 has BSIC 11, TSC = (BSIC & 7) = 3.
93 * BTS 2 has BSIC 12, TSC = (BSIC & 7) = 4.
94 * BTS 2 has BSIC 12, TSC = (BSIC & 7) = 4.
95 */
96const integer_list BTS_TSC := {
97 2,
98 3,
99 4,
100 4
101}
Harald Welte4003d112017-12-09 22:35:39 +0100102
Harald Welte21b46bd2017-12-17 19:46:32 +0100103/* per-BTS state which we keep */
Harald Welte96c94412017-12-09 03:12:45 +0100104type record BTS_State {
Harald Welte21b46bd2017-12-17 19:46:32 +0100105 /* component reference to the IPA_Client component used for RSL */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100106 IPA_Client rsl
Harald Welte96c94412017-12-09 03:12:45 +0100107}
108
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200109/* Default list of counters for an 'msc' entity. */
110const CounterNameVals counternames_msc_mscpool := {
111 { "mscpool:subscr:new", 0 },
112 { "mscpool:subscr:known", 0 },
113 { "mscpool:subscr:reattach", 0 },
114 { "mscpool:subscr:attach_lost", 0 },
115 { "mscpool:subscr:paged", 0 }
116};
117
Neels Hofmeyrbf037052020-10-28 22:52:02 +0000118/* List of global mscpool counters, not related to a specific 'msc' entity. */
119const CounterNameVals counternames_bsc_mscpool := {
120 { "mscpool:subscr:no_msc", 0 }
121};
122
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000123/* Default list of counters for 'bsc' and 'bts' entities. */
124const CounterNameVals counternames_bsc_bts_handover := {
125 { "assignment:attempted", 0 },
126 { "assignment:completed", 0 },
127 { "assignment:stopped", 0 },
128 { "assignment:no_channel", 0 },
129 { "assignment:timeout", 0 },
130 { "assignment:failed", 0 },
131 { "assignment:error", 0 },
132
133 { "handover:attempted", 0 },
134 { "handover:completed", 0 },
135 { "handover:stopped", 0 },
136 { "handover:no_channel", 0 },
137 { "handover:timeout", 0 },
138 { "handover:failed", 0 },
139 { "handover:error", 0 },
140
141 { "intra_cell_ho:attempted", 0 },
142 { "intra_cell_ho:completed", 0 },
143 { "intra_cell_ho:stopped", 0 },
144 { "intra_cell_ho:no_channel", 0 },
145 { "intra_cell_ho:timeout", 0 },
146 { "intra_cell_ho:failed", 0 },
147 { "intra_cell_ho:error", 0 },
148
149 { "intra_bsc_ho:attempted", 0 },
150 { "intra_bsc_ho:completed", 0 },
151 { "intra_bsc_ho:stopped", 0 },
152 { "intra_bsc_ho:no_channel", 0 },
153 { "intra_bsc_ho:timeout", 0 },
154 { "intra_bsc_ho:failed", 0 },
155 { "intra_bsc_ho:error", 0 },
156
157 { "interbsc_ho_out:attempted", 0 },
158 { "interbsc_ho_out:completed", 0 },
159 { "interbsc_ho_out:stopped", 0 },
160 { "interbsc_ho_out:timeout", 0 },
161 { "interbsc_ho_out:failed", 0 },
162 { "interbsc_ho_out:error", 0 },
163
164 { "interbsc_ho_in:attempted", 0 },
165 { "interbsc_ho_in:completed", 0 },
166 { "interbsc_ho_in:stopped", 0 },
167 { "interbsc_ho_in:no_channel", 0 },
168 { "interbsc_ho_in:timeout", 0 },
169 { "interbsc_ho_in:failed", 0 },
170 { "interbsc_ho_in:error", 0 }
171};
172
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100173const CounterNameVals counternames_bts_handover := {
174 { "incoming_intra_bsc_ho:attempted", 0 },
175 { "incoming_intra_bsc_ho:completed", 0 },
176 { "incoming_intra_bsc_ho:stopped", 0 },
177 { "incoming_intra_bsc_ho:no_channel", 0 },
178 { "incoming_intra_bsc_ho:timeout", 0 },
179 { "incoming_intra_bsc_ho:failed", 0 },
180 { "incoming_intra_bsc_ho:error", 0 }
181};
182
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200183/* Set of all System Information received during one RSL port's startup.
184 * Note that some System Information may be sent on RSL, but lacking actual SI data, to indicate that the BTS should not
185 * broadcast that SI type. That will be reflected as 'omit' here.
186 */
187type record SystemInformationConfig {
188 SystemInformationType1 si1 optional,
189 SystemInformationType2 si2 optional,
190 SystemInformationType2bis si2bis optional,
191 SystemInformationType2ter si2ter optional,
Neels Hofmeyrad132f22020-07-08 02:20:16 +0200192 SI2quaterRestOctetsList si2quater optional,
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200193 SystemInformationType3 si3 optional,
194 SystemInformationType4 si4 optional,
Pau Espin Pedrol28652d82021-02-09 20:20:17 +0100195 SystemInformationType13 si13 optional,
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200196 SystemInformationType5 si5 optional,
197 SystemInformationType5bis si5bis optional,
198 SystemInformationType5ter si5ter optional,
199 SystemInformationType6 si6 optional
200};
201
202const SystemInformationConfig SystemInformationConfig_omit := {
203 si1 := omit,
204 si2 := omit,
205 si2bis := omit,
206 si2ter := omit,
207 si2quater := omit,
208 si3 := omit,
209 si4 := omit,
210 si13 := omit,
211 si5 := omit,
212 si5bis := omit,
213 si5ter := omit,
214 si6 := omit
215};
216
217/* tr_EUTRAN_CellDesc with defaults used in BSC_Tests.ttcn */
218template EUTRAN_CellDesc tr_EUTRAN_CellDesc_default(template (present) uint16_t e_arfcn := ?,
219 template uint3_t meas_bw := 3)
220:= tr_EUTRAN_CellDesc(e_arfcn := e_arfcn,
221 meas_bw_presence := '1'B,
222 meas_bw := meas_bw);
223
224/* tr_EUTRAN_NeighbourCells with defaults used in BSC_Tests.ttcn */
Harald Welte65e419a2020-08-21 12:38:33 +0200225template EUTRAN_NeighbourCells tr_EUTRAN_NeighbourCells_default(template (present) EUTRAN_CellDescs cell_desc_list := { tr_EUTRAN_CellDesc_default },
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200226 template uint3_t prio := 3,
227 template (present) uint5_t thresh_high := 20,
228 template uint5_t thresh_low := 10,
229 template uint5_t qrxlevmin := 22)
230:= tr_EUTRAN_NeighbourCells(
231 cell_desc_list := cell_desc_list,
232 prio_presence := '1'B,
233 prio := prio,
234 thresh_high := thresh_high,
235 thresh_low_presence := '1'B,
236 thresh_low := thresh_low,
237 qrxlevmin_presence := '1'B,
238 qrxlevmin := qrxlevmin);
239
240template SystemInformationConfig SystemInformationConfig_default := {
241 si1 := {
242 cell_chan_desc := '8FB38000000000000000000000000000'O,
243 rach_control := {
244 max_retrans := RACH_MAX_RETRANS_7,
245 tx_integer := '1001'B,
246 cell_barr_access := false,
247 re_not_allowed := true,
248 acc := '0000010000000000'B
249 },
250 rest_octets := ?
251 },
252 si2 := {
253 bcch_freq_list := '00000000000000000000000000000000'O,
254 ncc_permitted := '11111111'B,
255 rach_control := {
256 max_retrans := RACH_MAX_RETRANS_7,
257 tx_integer := '1001'B,
258 cell_barr_access := false,
259 re_not_allowed := true,
260 acc := '0000010000000000'B
261 }
262 },
263 si2bis := omit,
264 si2ter := {
265 extd_bcch_freq_list := '8E320000000000000000000000000800'O,
266 rest_octets := ?
267 },
268 si2quater := {
269 tr_SI2quaterRestOctets_EUTRAN( repeated_neigh_cells := { tr_EUTRAN_NeighbourCells_default } )
270 },
271 si3 := {
272 cell_id := 0,
273 lai := {
274 mcc_mnc := '001F01'H,
275 lac := 1
276 },
277 ctrl_chan_desc := {
278 msc_r99 := true,
279 att := true,
280 bs_ag_blks_res := 1,
281 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
282 si22ind := false,
283 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
284 spare := '00'B,
285 bs_pa_mfrms := 3,
286 t3212 := 30
287 },
288 cell_options := {
289 dn_ind := false,
290 pwrc := false,
291 dtx := MS_SHALL_USE_UL_DTX,
292 radio_link_tout_div4 := 7
293 },
294 cell_sel_par := {
295 cell_resel_hyst_2dB := 2,
296 ms_txpwr_max_cch := 7,
297 acs := '0'B,
298 neci := true,
299 rxlev_access_min := 0
300 },
301 rach_control := {
302 max_retrans := RACH_MAX_RETRANS_7,
303 tx_integer := '1001'B,
304 cell_barr_access := false,
305 re_not_allowed := true,
306 acc := '0000010000000000'B
307 },
308 rest_octets := {
309 sel_params := {
310 presence := '0'B,
311 params := omit
312 },
313 pwr_offset := {
314 presence := '0'B,
315 offset := omit
316 },
317 si_2ter_ind := '1'B,
318 early_cm_ind := '0'B,
319 sched_where := {
320 presence := '0'B,
321 where := omit
322 },
323 gprs_ind := {
324 presence := '1'B,
325 ind := {
326 ra_colour := 0,
327 si13_pos := '0'B
328 }
329 },
330 umts_early_cm_ind := '1'B,
331 si2_quater_ind := {
332 presence := '1'B,
333 ind := '0'B
334 },
335 iu_mode_ind := omit,
336 si21_ind := {
337 presence := '0'B,
338 pos := omit
339 }
340 }
341 },
342 si4 := {
343 lai := {
344 mcc_mnc := '001F01'H,
345 lac := 1
346 },
347 cell_sel_par := {
348 cell_resel_hyst_2dB := 2,
349 ms_txpwr_max_cch := 7,
350 acs := '0'B,
351 neci := true,
352 rxlev_access_min := 0
353 },
354 rach_control := {
355 max_retrans := RACH_MAX_RETRANS_7,
356 tx_integer := '1001'B,
357 cell_barr_access := false,
358 re_not_allowed := true,
359 acc := '0000010000000000'B
360 },
Neels Hofmeyr74083c22020-07-29 00:43:01 +0200361 cbch_chan_desc := {
362 iei := '64'O,
363 v := {
364 chan_nr := {
365 u := {
366 sdcch4 := {
367 tag := '001'B,
368 sub_chan := 2
369 }
370 },
371 tn := 0
372 },
373 tsc := 2,
374 h := false,
375 arfcn := 871,
376 maio_hsn := omit
377 }
378 },
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200379 cbch_mobile_alloc := omit,
380 rest_octets := {
381 sel_params := {
382 presence := '0'B,
383 params := omit
384 },
385 pwr_offset := {
386 presence := '0'B,
387 offset := omit
388 },
389 gprs_ind := {
390 presence := '1'B,
391 ind := {
392 ra_colour := 0,
393 si13_pos := '0'B
394 }
395 },
396 s_presence := '0'B,
397 s := omit
398 }
399 },
Pau Espin Pedrol28652d82021-02-09 20:20:17 +0100400 si13 := {
401 rest_octets := {
402 presence := '1'B,
403 bcch_change_mark := ?,
404 si_change_field := '0000'B,
405 presence2 := '0'B,
406 si13_change_mark := omit,
407 gprs_ma := omit,
408 zero := '0'B, /* PBCCH not present in cell */
409 rac := 0,
410 spgc_ccch_sup := '0'B,
411 priority_access_thr := '110'B,
412 network_control_order := '00'B,
413 gprs_cell_opts := {
414 nmo := '01'B,
415 t3168 := '011'B,
416 t3192 := '010'B,
417 drx_timer_max := '011'B,
418 access_burst_type := '0'B,
419 control_ack_type := '1'B,
420 bs_cv_max := 15,
421 pan_presence := '1'B,
422 pan_dec := 1,
423 pan_inc := 1,
424 pan_max := '111'B,
425 ext_info_presence := ?,
426 ext_info_length := *,
427 ext_info := *
428 },
429 gprs_pwr_ctrl_params := {
430 alpha := 0,
431 t_avg_w := '10000'B,
432 t_avg_t := '10000'B,
433 pc_meas_chan := '0'B,
434 n_avg_i := '1000'B
435 }
436 }
437 },
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200438 si5 := {
439 bcch_freq_list := '10000000000000000000000000000000'O
440 },
441 si5bis := omit,
442 si5ter := {
443 extd_bcch_freq_list := '9E050020000000000000000000000000'O
444 },
445 si6 := {
446 cell_id := 0,
447 lai := {
448 mcc_mnc := '001F01'H,
449 lac := 1
450 },
451 cell_options := {
452 dtx_ext := '1'B,
453 pwrc := false,
454 dtx := '01'B,
455 radio_link_timeout := '0111'B
456 },
457 ncc_permitted := '11111111'B,
458 rest_octets := ?
459 }
460 };
461
462
463/* List of all the System Information received on all RSL ports */
464type record of SystemInformationConfig SystemInformationConfig_list;
465
466function f_sysinfo_dec_raw(inout SystemInformationConfig si, RSL_Message rsl)
467{
468 var RSL_IE_Body sysinfo_type_ie;
469 var RSL_IE_SysinfoType si_type;
470 var octetstring data;
471
472 if (f_rsl_find_ie(rsl, RSL_IE_SYSINFO_TYPE, sysinfo_type_ie) == false) {
473 setverdict(fail, "Cannot find RSL_IE_SYSINFO_TYPE");
474 mtc.stop;
475 }
476 si_type := sysinfo_type_ie.sysinfo_type;
477
478 if (rsl.msg_type == RSL_MT_BCCH_INFO) {
479 var RSL_IE_Body bcch_ie;
480 if (f_rsl_find_ie(rsl, RSL_IE_FULL_BCCH_INFO, bcch_ie)) {
481 data := bcch_ie.other.payload;
482 }
483 } else if (rsl.msg_type == RSL_MT_SACCH_FILL) {
484 var RSL_IE_Body l3_ie;
485 if (f_rsl_find_ie(rsl, RSL_IE_L3_INFO, l3_ie)) {
486 data := l3_ie.l3_info.payload;
487 }
488 } else {
489 setverdict(fail, "Don't understand this System Information message");
490 mtc.stop;
491 }
492
493 var boolean handled := false;
494
495 if (rsl.msg_type == RSL_MT_BCCH_INFO) {
496 handled := true;
497
498 if (si_type == RSL_SYSTEM_INFO_1) {
499 if (not isbound(data)) {
500 si.si1 := omit;
501 } else {
502 si.si1 := dec_SystemInformation(data).payload.si1;
503 }
504 } else if (si_type == RSL_SYSTEM_INFO_2) {
505 if (not isbound(data)) {
506 si.si2 := omit;
507 } else {
508 si.si2 := dec_SystemInformation(data).payload.si2;
509 }
510 } else if (si_type == RSL_SYSTEM_INFO_2bis) {
511 if (not isbound(data)) {
512 si.si2bis := omit;
513 } else {
514 si.si2bis := dec_SystemInformation(data).payload.si2bis;
515 }
516 } else if (si_type == RSL_SYSTEM_INFO_2ter) {
517 if (not isbound(data)) {
518 si.si2ter := omit;
519 } else {
520 si.si2ter := dec_SystemInformation(data).payload.si2ter;
521 }
522 } else if (si_type == RSL_SYSTEM_INFO_2quater) {
523 if (not isbound(data)) {
524 si.si2quater := {};
525 } else {
526 var SystemInformationType2quater decoded := dec_SystemInformation(data).payload.si2quater;
527 /* this is a *record* of SI2quaterRestOctets! (multiplexed) */
528 si.si2quater[decoded.rest_octets.si2quater_index] := decoded.rest_octets;
529 }
530 } else if (si_type == RSL_SYSTEM_INFO_3) {
531 if (not isbound(data)) {
532 si.si3 := omit;
533 } else {
534 si.si3 := dec_SystemInformation(data).payload.si3;
535 }
536 } else if (si_type == RSL_SYSTEM_INFO_4) {
537 if (not isbound(data)) {
538 si.si4 := omit;
539 } else {
540 si.si4 := dec_SystemInformation(data).payload.si4;
541 }
542 } else if (si_type == RSL_SYSTEM_INFO_13) {
543 if (not isbound(data)) {
544 si.si13 := omit;
545 } else {
Pau Espin Pedrol28652d82021-02-09 20:20:17 +0100546 si.si13 := dec_SystemInformation(data).payload.si13;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200547 }
548 } else {
549 handled := false;
550 }
551 } else if (rsl.msg_type == RSL_MT_SACCH_FILL) {
552 handled := true;
553
554 if (si_type == RSL_SYSTEM_INFO_5) {
555 if (not isbound(data)) {
556 si.si5 := omit;
557 } else {
558 si.si5 := dec_SystemInformation(data).payload.si5;
559 }
560 } else if (si_type == RSL_SYSTEM_INFO_5bis) {
561 if (not isbound(data)) {
562 si.si5bis := omit;
563 } else {
564 si.si5bis := dec_SystemInformation(data).payload.si5bis;
565 }
566 } else if (si_type == RSL_SYSTEM_INFO_5ter) {
567 if (not isbound(data)) {
568 si.si5ter := omit;
569 } else {
570 si.si5ter := dec_SystemInformation(data).payload.si5ter;
571 }
572 } else if (si_type == RSL_SYSTEM_INFO_6) {
573 if (not isbound(data)) {
574 si.si6 := omit;
575 } else {
576 si.si6 := dec_SystemInformation(data).payload.si6;
577 }
578 } else {
579 handled := false;
580 }
581 }
582
583 if (not handled) {
584 setverdict(fail, "Unexpected SI type in ", rsl.msg_type, " message: ", si_type);
585 }
586}
587
Harald Weltea4ca4462018-02-09 00:17:14 +0100588type component test_CT extends CTRL_Adapter_CT {
Harald Welte21b46bd2017-12-17 19:46:32 +0100589 /* Array of per-BTS state */
Harald Welte96c94412017-12-09 03:12:45 +0100590 var BTS_State bts[NUM_BTS];
Harald Welte89ab1912018-02-23 18:56:29 +0100591 /* RSL common Channel Port (for RSL_Emulation) */
592 port RSL_CCHAN_PT RSL_CCHAN[NUM_BTS];
Harald Welte21b46bd2017-12-17 19:46:32 +0100593 /* array of per-BTS RSL test ports */
Harald Welteae026692017-12-09 01:03:01 +0100594 port IPA_RSL_PT IPA_RSL[NUM_BTS];
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100595 port IPA_CODEC_PT IPA; /* Required for compilation of TC_rsl_unknown_unit_id() */
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +0200596 /* CTRL muxed over IPA in SCCPlite conn BSC<->MSC (or BSC-NAT) */
597 port IPA_CTRL_PT SCCPLITE_IPA_CTRL;
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100598 /* Configure/manage IPA_Emulation: */
599 port IPA_CFG_PT IPA_CFG_PORT;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100600
Daniel Willmann191e0d92018-01-17 12:44:35 +0100601 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +0100602 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100603
Daniel Willmannebdecc02020-08-12 15:30:17 +0200604 /* StatsD */
605 var StatsD_Checker_CT vc_STATSD;
606
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200607 var RAN_Adapter g_bssap[NUM_MSC];
Harald Welte47cd0e32020-08-21 12:39:11 +0200608 var BSSAP_LE_Adapter g_bssap_le;
Harald Weltea4ca4462018-02-09 00:17:14 +0100609 /* for old legacy-tests only */
610 port BSSAP_CODEC_PT BSSAP;
Harald Welte47cd0e32020-08-21 12:39:11 +0200611 port BSSAP_LE_CODEC_PT BSSAP_LE;
Harald Weltea4ca4462018-02-09 00:17:14 +0100612
Harald Welte21b46bd2017-12-17 19:46:32 +0100613 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +0100614 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +0100615
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200616 /* Osmux is enabled through VTY */
617 var boolean g_osmux_enabled := false;
618
Pau Espin Pedrolc675b612020-01-09 19:55:40 +0100619 /*Configure T(tias) over VTY, seconds */
620 var integer g_bsc_sccp_timer_ias := 7 * 60;
621 /*Configure T(tiar) over VTY, seconds */
622 var integer g_bsc_sccp_timer_iar := 15 * 60;
623
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +0200624 /* global test case guard timer (actual timeout value is set in f_init()) */
Harald Welteae026692017-12-09 01:03:01 +0100625 timer T_guard := 30.0;
626
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200627 var CounterNameValsList g_ctr_msc;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000628 var CounterNameValsList g_ctr_bsc;
629 var CounterNameValsList g_ctr_bts;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200630
631 /* System Information bytes as received during RSL startup, for each RSL[idx]. */
632 var SystemInformationConfig_list g_system_information := {};
Harald Welte28d943e2017-11-25 15:00:50 +0100633}
634
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200635type record of charstring phys_chan_configs;
Harald Welte28d943e2017-11-25 15:00:50 +0100636modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +0100637 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +0100638 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100639 /* port number to which to establish the IPA OML connections */
640 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +0100641 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +0100642 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +0100643 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +0100644 integer mp_bsc_ctrl_port := 4249;
Daniel Willmannebdecc02020-08-12 15:30:17 +0200645 /* port number to which to listen for STATSD metrics */
646 integer mp_bsc_statsd_port := 8125;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100647 /* IP address at which the test binds */
648 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100649
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200650 RAN_Configurations mp_bssap_cfg := {
651 {
652 transport := BSSAP_TRANSPORT_AoIP,
653 sccp_service_type := "mtp3_itu",
654 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
655 own_pc := 185, /* 0.23.1 first MSC emulation */
656 own_ssn := 254,
657 peer_pc := 187, /* 0.23.3 osmo-bsc */
658 peer_ssn := 254,
659 sio := '83'O,
Harald Weltecb0cc432020-06-21 19:42:31 +0200660 rctx := 1
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200661 },
662 {
663 transport := BSSAP_TRANSPORT_AoIP,
664 sccp_service_type := "mtp3_itu",
665 sctp_addr := { 23906, "127.0.0.1", 2905, "127.0.0.1" },
666 own_pc := 2, /* 0.0.2 second MSC emulation */
667 own_ssn := 254,
668 peer_pc := 187, /* 0.23.3 osmo-bsc */
669 peer_ssn := 254,
670 sio := '83'O,
671 rctx := 2
672 },
673 {
674 transport := BSSAP_TRANSPORT_AoIP,
675 sccp_service_type := "mtp3_itu",
676 sctp_addr := { 23907, "127.0.0.1", 2905, "127.0.0.1" },
677 own_pc := 3, /* 0.0.3 third MSC emulation */
678 own_ssn := 254,
679 peer_pc := 187, /* 0.23.3 osmo-bsc */
680 peer_ssn := 254,
681 sio := '83'O,
682 rctx := 3
683 }
Harald Weltea4ca4462018-02-09 00:17:14 +0100684 };
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +0200685
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200686 /* Must match per BTS config in osmo-bsc.cfg */
687 phys_chan_configs phys_chan_config := {
688 "CCCH+SDCCH4+CBCH",
689 "TCH/F",
690 "TCH/F",
691 "TCH/F",
692 "TCH/F",
Vadim Yanitskiy343c9eb2021-07-16 18:36:01 +0600693 "TCH/H",
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200694 "PDCH",
695 "PDCH"
696 };
697
Harald Welte47cd0e32020-08-21 12:39:11 +0200698 BSSAP_LE_Configuration mp_bssap_le_cfg := {
699 sccp_service_type := "mtp3_itu",
700 sctp_addr := { 23908, "127.0.0.1", 2905, "127.0.0.1" },
Neels Hofmeyrac086c12020-09-18 23:46:42 +0200701 own_pc := 190, /* 0.23.6 SMLC emulation */
Harald Welte47cd0e32020-08-21 12:39:11 +0200702 own_ssn := 252, /* SMLC side SSN */
703 peer_pc := 187, /* 0.23.3 osmo-bsc */
704 peer_ssn := 250, /* BSC side SSN */
705 sio := '83'O,
706 rctx := 6
707 };
Neels Hofmeyrcfe44062020-10-15 02:28:08 +0200708 boolean mp_enable_lcs_tests := true;
Harald Welte47cd0e32020-08-21 12:39:11 +0200709
Pau Espin Pedrol8f30ccd2019-11-01 17:30:57 +0100710 /* Value set in osmo-bsc.cfg "ms max power" */
711 uint8_t mp_exp_ms_power_level := 7;
Harald Weltea4ca4462018-02-09 00:17:14 +0100712}
713
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +0200714friend function f_gen_test_hdlr_pars(integer bssap_idx := 0) return TestHdlrParams {
Philipp Maier48604732018-10-09 15:00:37 +0200715
716 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200717 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier48604732018-10-09 15:00:37 +0200718 pars.aoip := true;
719 } else {
720 pars.aoip := false;
721 }
Pau Espin Pedrol8f30ccd2019-11-01 17:30:57 +0100722 pars.exp_ms_power_level := mp_exp_ms_power_level;
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200723 pars.mscpool.bssap_idx := bssap_idx;
Neels Hofmeyrbf720202021-10-02 12:58:24 +0200724 pars.expect_tsc := BTS_TSC[0];
Vadim Yanitskiy96bb9cb2021-12-10 21:14:15 +0300725 pars.imsi := f_rnd_imsi('00101'H);
726
727 log(testcasename(), ": using IMSI ", pars.imsi);
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200728
Philipp Maier48604732018-10-09 15:00:37 +0200729 return pars;
730}
731
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200732/* Convenience functions for rate counters using g_ctr_msc. */
733
734private function f_ctrs_msc_init(integer mscs_count := NUM_MSC, CounterNameVals counternames := counternames_msc_mscpool) runs on test_CT {
735 g_ctr_msc := f_counter_name_vals_get_n(IPA_CTRL, "msc", mscs_count, counternames);
736 log("initial msc rate counters: ", g_ctr_msc);
737}
738
739private function f_ctrs_msc_add(integer msc_nr, charstring countername, integer val := 1) runs on test_CT {
Neels Hofmeyr9656e922020-06-30 01:27:01 +0200740 f_counter_name_vals_list_add(g_ctr_msc, msc_nr, countername, val);
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200741}
742
743/* f_ctrs_msc_init();
744 * f_do_thing(on_msc := 0);
745 * f_do_thing(on_msc := 0);
746 * f_do_other(on_msc := 1);
747 * f_ctrs_msc_add(0, "thing", 2);
748 * f_ctrs_msc_add(1, "other");
749 * f_ctrs_msc_verify();
750 */
751private function f_ctrs_msc_verify() runs on test_CT {
752 log("verifying msc rate counters: ", g_ctr_msc);
753 f_counter_name_vals_expect_n(IPA_CTRL, "msc", g_ctr_msc);
754}
755
756/* convenience: f_ctrs_msc_add() and f_ctrs_msc_verify() in one call.
757 * f_ctrs_msc_init();
758 * f_do_thing(on_msc := 0);
759 * f_do_thing(on_msc := 0);
760 * f_do_thing(on_msc := 0);
761 * f_ctrs_msc_expect(0, "thing", 3);
762 */
763private function f_ctrs_msc_expect(integer msc_nr, charstring countername, integer val := 1) runs on test_CT {
764 f_ctrs_msc_add(msc_nr, countername, val);
765 f_ctrs_msc_verify();
766}
767
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000768/* Convenience functions for rate counters using g_ctr_bts, always also including g_ctr_bsc. */
769
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100770private function f_ctrs_bts_init(integer bts_count := NUM_BTS, CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000771 g_ctr_bts := f_counter_name_vals_get_n(IPA_CTRL, "bts", bts_count, counternames);
Neels Hofmeyr4dec8cc2021-11-29 15:59:44 +0100772 log("initial bts rate counters: ", g_ctr_bts);
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100773}
774
775function f_ctrs_bsc_and_bts_init(integer bts_count := NUM_BTS, CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
776 f_ctrs_bts_init(bts_count, counternames);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000777 f_ctrs_bsc_init(counternames);
778}
779
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100780private function f_ctrs_bsc_and_bts_handover_init(integer bts_count := NUM_BTS) runs on test_CT {
781 var CounterNameVals bts_names := counternames_bsc_bts_handover & counternames_bts_handover;
Neels Hofmeyr4dec8cc2021-11-29 15:59:44 +0100782 f_ctrs_bts_init(bts_count, bts_names);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100783 f_ctrs_bsc_init(counternames_bsc_bts_handover);
784}
785
786private function f_ctrs_bts_add(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000787 f_counter_name_vals_list_add(g_ctr_bts, bts_nr, countername, val);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100788}
789
790private function f_ctrs_bsc_and_bts_add(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
791 f_ctrs_bts_add(bts_nr, countername, val);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000792 f_ctrs_bsc_add(countername, val);
793}
794
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100795function f_ctrs_bts_verify() runs on test_CT {
796 f_counter_name_vals_expect_n(IPA_CTRL, "bts", g_ctr_bts);
797}
798
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000799/* f_ctrs_bsc_and_bts_init();
800 * f_do_thing(on_bts := 0);
801 * f_do_thing(on_bts := 0);
802 * f_do_other(on_bts := 1);
803 * f_ctrs_bsc_and_bts_add(0, "thing", 2);
804 * f_ctrs_bsc_and_bts_add(1, "other");
805 * f_ctrs_bsc_and_bts_verify();
806 */
807private function f_ctrs_bsc_and_bts_verify() runs on test_CT {
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100808 f_ctrs_bts_verify();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000809 f_ctrs_bsc_verify();
810}
811
812/* convenience: f_ctrs_bsc_and_bts_add() and f_ctrs_bsc_and_bts_verify() in one call.
813 * f_ctrs_bsc_and_bts_init();
814 * f_do_thing(on_bts := 0);
815 * f_do_thing(on_bts := 0);
816 * f_do_thing(on_bts := 0);
817 * f_ctrs_bsc_and_bts_expect(0, "thing", 3);
818 */
819private function f_ctrs_bsc_and_bts_expect(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
820 f_ctrs_bsc_and_bts_add(bts_nr, countername, val);
821 f_ctrs_bsc_and_bts_verify();
822}
823
824
825/* Convenience functions for rate counters using g_ctr_bsc. */
826
827private function f_ctrs_bsc_init(CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
828 g_ctr_bsc := f_counter_name_vals_get_n(IPA_CTRL, "bsc", 1, counternames);
829 log("initial bsc rate counters: ", g_ctr_bsc);
830}
831
832private function f_ctrs_bsc_add(charstring countername, integer val := 1) runs on test_CT {
833 f_counter_name_vals_list_add(g_ctr_bsc, 0, countername, val);
834}
835
836/* f_ctrs_bsc_init();
837 * f_do_thing();
838 * f_do_thing();
839 * f_do_other();
840 * f_ctrs_bsc_add("thing", 2);
841 * f_ctrs_bsc_add("other");
842 * f_ctrs_bsc_verify();
843 */
844private function f_ctrs_bsc_verify() runs on test_CT {
845 f_counter_name_vals_expect_n(IPA_CTRL, "bsc", g_ctr_bsc);
846}
847
848/* convenience: f_ctrs_bsc_add() and f_ctrs_bsc_verify() in one call.
849 * f_ctrs_bsc_init();
850 * f_do_thing();
851 * f_ctrs_bsc_expect("thing", 1);
852 */
853private function f_ctrs_bsc_expect(charstring countername, integer val := 1) runs on test_CT {
854 f_ctrs_bsc_add(countername, val);
855 f_ctrs_bsc_verify();
856}
857
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200858
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +0200859friend function f_shutdown_helper() runs on test_CT {
Daniel Willmann637ef6c2018-07-25 10:49:09 +0200860 all component.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100861 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200862 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100863}
864
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200865private function f_legacy_bssap_reset(integer bssap_idx := 0) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +0100866 var BSSAP_N_UNITDATA_ind ud_ind;
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200867 var boolean reset_received := false;
Harald Weltea4ca4462018-02-09 00:17:14 +0100868 timer T := 5.0;
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200869 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
870 ts_BSSMAP_Reset(0, g_osmux_enabled)));
Harald Weltea4ca4462018-02-09 00:17:14 +0100871 T.start;
872 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200873 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap[bssap_idx].sccp_addr_own, g_bssap[bssap_idx].sccp_addr_peer,
874 tr_BSSMAP_ResetAck(g_osmux_enabled))) {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200875 log("BSSMAP: Received RESET-ACK in response to RESET, we're ready to go!");
Harald Weltea4ca4462018-02-09 00:17:14 +0100876 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200877 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200878 log("BSSMAP: Respoding to inbound RESET with RESET-ACK");
Harald Weltea4ca4462018-02-09 00:17:14 +0100879 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200880 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200881 reset_received := true;
Harald Weltea4ca4462018-02-09 00:17:14 +0100882 repeat;
883 }
884 [] BSSAP.receive { repeat; }
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200885 [] T.timeout {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200886 log("BSSMAP: Timeout waiting for RESET-ACK after sending RESET");
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200887 /* If we received a RESET after ours was sent, it
888 may be a race condition where the other peer beacame
889 available after we sent it, but we are in a desired
890 state anyway, so go forward. */
891 if (not reset_received) {
892 setverdict(fail);
893 }
894 }
Harald Weltea4ca4462018-02-09 00:17:14 +0100895 }
Harald Welte28d943e2017-11-25 15:00:50 +0100896}
897
Harald Welteae026692017-12-09 01:03:01 +0100898type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100899 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100900 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100901 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100902 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100903 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100904 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100905 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100906 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100907}
908
Harald Welte21b46bd2017-12-17 19:46:32 +0100909/*! Start the IPA/RSL related bits for one IPA_Client.
910 * \param clnt IPA_Client for which to establish
911 * \param bsc_host IP address / hostname of the BSC
912 * \param bsc_port TCP port number of the BSC
913 * \param i number identifying this BTS
914 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100915function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
916 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100917runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100918 timer T := 10.0;
919
Harald Welte96c94412017-12-09 03:12:45 +0100920 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welte71389132021-12-09 21:58:18 +0100921 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA") alive;
Harald Welteae026692017-12-09 01:03:01 +0100922 clnt.ccm_pars := c_IPA_default_ccm_pars;
923 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
924 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100925 if (handler_mode) {
Harald Welte71389132021-12-09 21:58:18 +0100926 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL") alive;
Harald Welte89ab1912018-02-23 18:56:29 +0100927 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100928 }
Harald Welteae026692017-12-09 01:03:01 +0100929
930 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100931 connect(clnt.vc_IPA:CFG_PORT, self:IPA_CFG_PORT);
Harald Welte624f9632017-12-16 19:26:04 +0100932 if (handler_mode) {
933 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
934 } else {
935 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
936 }
Harald Welteae026692017-12-09 01:03:01 +0100937
Harald Welte5d1a2202017-12-13 19:51:29 +0100938 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100939 if (handler_mode) {
940 clnt.vc_RSL.start(RSL_Emulation.main());
941 return;
942 }
Harald Welteae026692017-12-09 01:03:01 +0100943
944 /* wait for IPA RSL link to connect and send ID ACK */
945 T.start;
946 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700947 [] IPA_RSL[i].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) {
Harald Welteae026692017-12-09 01:03:01 +0100948 T.stop;
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +0700949 IPA_RSL[i].send(ts_ASP_RSL_UD(ts_RSL_PAGING_LOAD_IND(23)));
Harald Welteae026692017-12-09 01:03:01 +0100950 }
Harald Welte60e823a2017-12-10 14:10:59 +0100951 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100952 [] IPA_RSL[i].receive { repeat }
953 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100954 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200955 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100956 }
957 }
958}
959
Harald Welte12055472018-03-17 20:10:08 +0100960function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100961 var IPL4asp_Types.Result res := {
962 errorCode := omit,
963 connId := omit,
964 os_error_code := omit,
965 os_error_text := omit
966 };
967
Harald Welte12055472018-03-17 20:10:08 +0100968 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
969 return;
970 }
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100971
972 /* Alive components don't finish sockets (TCP FIN) when they are
973 * stopped. Hence, we need to manually call close() on them to make sure
974 * the IUT knows about it. */
975 f_ipa_cfg_disconnect(IPA_CFG_PORT, res);
976
Harald Welte12055472018-03-17 20:10:08 +0100977 clnt.vc_IPA.stop;
978 if (isbound(clnt.vc_RSL)) {
979 clnt.vc_RSL.stop;
980 }
981}
982
Harald Welte21b46bd2017-12-17 19:46:32 +0100983/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100984function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
985 timer T := secs_max;
986 T.start;
987 while (true) {
988 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
989 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100990 /* the 'degraded' state exists from OML connection time, and we have to wait
991 * until all MO's are initialized */
992 T.start(1.0);
993 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100994 return;
995 }
Harald Weltef0d6ac62017-12-17 17:02:21 +0100996 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100997 if (not T.running) {
Max99253902018-11-16 17:57:39 +0100998 setverdict(fail, "Timeout waiting for BTS" & int2str(bts_nr) & " oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +0200999 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001000 }
1001 }
1002}
1003
Harald Welte21b46bd2017-12-17 19:46:32 +01001004/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +01001005altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +01001006 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +01001007 [] T_guard.timeout {
1008 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +02001009 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +01001010 }
Harald Welte60e823a2017-12-10 14:10:59 +01001011 /* always respond with RESET ACK to RESET */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001012 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Welte60e823a2017-12-10 14:10:59 +01001013 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001014 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Welte69c1c262017-12-13 21:02:08 +01001015 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +01001016 }
Harald Welte28d943e2017-11-25 15:00:50 +01001017}
1018
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001019altstep no_bssmap_reset() runs on test_CT {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001020 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001021 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +02001022 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001023 }
1024}
1025
Daniel Willmann191e0d92018-01-17 12:44:35 +01001026function f_init_mgcp(charstring id) runs on test_CT {
1027 id := id & "-MGCP";
1028
1029 var MGCPOps ops := {
1030 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
1031 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
1032 };
1033 var MGCP_conn_parameters mgcp_pars := {
1034 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +01001035 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +01001036 mgw_ip := mp_test_ip,
Pau Espin Pedrol1a026a52019-06-18 17:21:52 +02001037 mgw_udp_port := 2427,
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02001038 /* Enable it for SCCPlite, since we have 2 MGCP sockets towards MGW (UDP one +
1039 the on with MGCP over IPA forwarded from MSC one) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001040 multi_conn_mode := (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER)
Daniel Willmann191e0d92018-01-17 12:44:35 +01001041 };
1042
Harald Welte71389132021-12-09 21:58:18 +01001043 vc_MGCP := MGCP_Emulation_CT.create(id) alive;
Daniel Willmann191e0d92018-01-17 12:44:35 +01001044 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
1045}
1046
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001047/* Enable or disable (current default) Osmux. When enabling, BSSMAP Reset
1048 * contains extra IE (OsmuxSupport) and osmo-bsc will handle AssignReq with
1049 * OsmuxCID IE.
1050 */
1051private function f_vty_allow_osmux(boolean allow) runs on test_CT {
1052 f_vty_enter_cfg_msc(BSCVTY, 0);
1053 if (allow) {
1054 f_vty_transceive(BSCVTY, "osmux on");
1055 } else {
1056 f_vty_transceive(BSCVTY, "osmux off");
1057 }
1058 f_vty_transceive(BSCVTY, "exit");
1059 f_vty_transceive(BSCVTY, "exit");
1060 g_osmux_enabled := allow;
1061}
1062
Max2253c0b2018-11-06 19:28:05 +01001063function f_init_vty(charstring id := "foo") runs on test_CT {
Harald Welte94e0c342018-04-07 11:33:23 +02001064 if (BSCVTY.checkstate("Mapped")) {
1065 /* skip initialization if already executed once */
1066 return;
1067 }
Harald Weltebc03c762018-02-12 18:09:38 +01001068 map(self:BSCVTY, system:BSCVTY);
1069 f_vty_set_prompts(BSCVTY);
1070 f_vty_transceive(BSCVTY, "enable");
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01001071 f_cs7_inst_0_cfg(BSCVTY, {"sccp-timer ias " & int2str(g_bsc_sccp_timer_ias),
1072 "sccp-timer iar " & int2str(g_bsc_sccp_timer_iar)});
Harald Weltebc03c762018-02-12 18:09:38 +01001073}
1074
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +02001075friend function f_logp(TELNETasp_PT pt, charstring log_msg)
Neels Hofmeyr4f118412020-06-04 15:25:10 +02001076{
1077 // log on TTCN3 log output
1078 log(log_msg);
1079 // log in stderr log
Neels Hofmeyr8bdafe52021-12-14 17:25:48 +01001080 if (pt.checkstate("Mapped")) {
1081 f_vty_transceive(pt, "logp lglobal notice TTCN3 f_logp(): " & log_msg);
1082 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02001083}
1084
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001085private function f_sysinfo_seen(integer rsl_idx, RSL_Message rsl) runs on test_CT
1086{
1087 if (rsl_idx >= lengthof(g_system_information)) {
1088 g_system_information[rsl_idx] := SystemInformationConfig_omit
1089 }
1090 f_sysinfo_dec_raw(g_system_information[rsl_idx], rsl);
1091}
1092
1093altstep as_catch_RSL_sysinfo(integer rsl_idx) runs on test_CT {
1094 var ASP_RSL_Unitdata rx_rsl_ud;
1095
1096 /* For handler_mode := false, receiving the RSL bootstrap messages directly on IPA_RSL */
1097 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
1098 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1099 repeat;
1100 }
1101 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
1102 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1103 repeat;
1104 }
1105 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> 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_SACCH_FILL)) -> value rx_rsl_ud {
1110 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1111 repeat;
1112 }
1113
1114 /* For handler_mode := true, receiving the RSL bootstrap messages via RSL_Emulation */
1115 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
1116 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1117 repeat;
1118 }
1119 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
1120 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1121 repeat;
1122 }
1123 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> 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_SACCH_FILL)) -> value rx_rsl_ud {
1128 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1129 repeat;
1130 }
1131}
1132
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001133/* TODO: use BooleanList from COMMON/src/General_Types.ttcn */
1134private type record of boolean my_BooleanList;
1135
1136private function f_vty_msc_allow_attach(TELNETasp_PT pt, my_BooleanList allow_attach_list)
1137{
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001138 var charstring config := f_vty_transceive_ret(pt, "show running-config");
1139
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001140 for (var integer msc_nr := 0; msc_nr < sizeof(allow_attach_list); msc_nr := msc_nr+1) {
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001141 if (f_strstr(config, "\nmsc " & int2str(msc_nr) & "\n") < 0) {
1142 /* There is no 'msc N' for this msc_nr in the running config, so don't create an empty msc by
1143 * stepping into that config node. */
1144 log("msc ", msc_nr, " is not configured, skipping");
1145 continue;
1146 }
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001147 f_vty_enter_cfg_msc(pt, msc_nr);
1148 if (allow_attach_list[msc_nr]) {
1149 /* strict := false: ignore if osmo-bsc does not support this config option (latest build) */
1150 f_vty_transceive(pt, "allow-attach", strict := false);
1151 } else {
1152 f_vty_transceive(pt, "no allow-attach", strict := false);
1153 }
1154 f_vty_transceive(pt, "exit");
1155 f_vty_transceive(pt, "exit");
1156 }
1157}
1158
Harald Welte21b46bd2017-12-17 19:46:32 +01001159/* global initialization function
1160 * \param nr_bts Number of BTSs we should start/bring up
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001161 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false).
1162 * \param nr_msc Number of virtual MSCs to bring up to connect to osmo-bsc.
1163 */
1164function f_init(integer nr_bts := NUM_BTS, boolean handler_mode := false, boolean allow_osmux := false,
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001165 integer nr_msc := 1, float guard_timeout := 30.0) runs on test_CT {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001166 var integer bssap_idx;
Harald Welte28d943e2017-11-25 15:00:50 +01001167
Harald Welteae026692017-12-09 01:03:01 +01001168 if (g_initialized) {
1169 return;
Harald Welte28d943e2017-11-25 15:00:50 +01001170 }
Harald Welteae026692017-12-09 01:03:01 +01001171 g_initialized := true;
1172
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001173 T_guard.start(guard_timeout);
Daniel Willmanne68f9272018-11-27 15:15:28 +01001174 activate(as_Tguard());
1175
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001176 f_init_vty("VirtMSC");
Pau Espin Pedrol23510fb2021-07-20 17:00:38 +02001177 f_vty_allow_osmux(allow_osmux);
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001178
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001179 var my_BooleanList allow_attach := { false, false, false };
Daniel Willmannebdecc02020-08-12 15:30:17 +02001180 f_init_statsd("VirtMSC", vc_STATSD, mp_test_ip, mp_bsc_statsd_port);
1181
Neels Hofmeyr9db8e0e2021-08-23 20:45:58 +02001182 /* Make sure each MSC's internal state is "DISCONNECTED" at first */
1183 for (bssap_idx := 0; bssap_idx < NUM_MSC; bssap_idx := bssap_idx+1) {
1184 f_vty_transceive(BSCVTY, "msc " & int2str(bssap_idx) & " bssmap reset", strict := false);
1185 }
1186
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001187 for (bssap_idx := 0; bssap_idx < nr_msc; bssap_idx := bssap_idx+1) {
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001188 allow_attach[bssap_idx] := true;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001189 /* Call a function of our 'parent component' RAN_Adapter_CT to start the
1190 * MSC-side BSSAP emulation */
1191 if (handler_mode) {
1192 var RanOps ranops := MSC_RanOps;
1193 ranops.use_osmux := g_osmux_enabled;
1194 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", ranops);
1195 connect(self:SCCPLITE_IPA_CTRL, g_bssap[bssap_idx].vc_RAN:CTRL_CLIENT);
1196 f_ran_adapter_start(g_bssap[bssap_idx]);
1197 } else {
1198 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", omit);
1199 connect(self:BSSAP, g_bssap[bssap_idx].vc_SCCP:SCCP_SP_PORT);
1200 f_ran_adapter_start(g_bssap[bssap_idx]);
1201 f_legacy_bssap_reset();
1202 }
Harald Welte67089ee2018-01-17 22:19:03 +01001203 }
Harald Welted5833a82018-05-27 16:52:56 +02001204
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02001205 if (mp_enable_lcs_tests) {
1206 if (handler_mode) {
1207 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", SMLC_BssapLeOps);
1208 } else {
1209 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", omit);
1210 connect(self:BSSAP_LE, g_bssap_le.vc_SCCP:SCCP_SP_PORT);
1211 }
1212 f_bssap_le_adapter_start(g_bssap_le);
Harald Welte47cd0e32020-08-21 12:39:11 +02001213 }
Harald Welte47cd0e32020-08-21 12:39:11 +02001214
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001215 /* start the test with exactly all enabled MSCs allowed to attach */
1216 f_vty_msc_allow_attach(BSCVTY, allow_attach);
1217
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01001218 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +01001219
Daniel Willmann191e0d92018-01-17 12:44:35 +01001220 f_init_mgcp("VirtMSC");
1221
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001222 for (var integer i := 0; i < nr_bts; i := i+1) {
1223 f_init_bts(i, handler_mode);
Harald Welte696ddb62017-12-08 14:01:43 +01001224 }
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001225}
Harald Welte696ddb62017-12-08 14:01:43 +01001226
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001227function f_init_bts(integer bts_idx := 0, boolean handler_mode := false)
1228runs on test_CT {
1229 /* wait until osmo-bts-omldummy has respawned */
1230 f_wait_oml(bts_idx, "degraded", 5.0);
1231
1232 /* start RSL connection */
1233 f_ipa_rsl_start(bts[bts_idx].rsl, mp_bsc_ip, mp_bsc_rsl_port, bts_idx, handler_mode);
1234 /* wait until BSC tells us "connected" */
1235 f_wait_oml(bts_idx, "connected", 5.0);
Harald Welte28d943e2017-11-25 15:00:50 +01001236}
1237
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001238function f_init_bts_and_check_sysinfo(integer bts_idx := 0, boolean handler_mode := false,
1239 template SystemInformationConfig expect_si)
1240runs on test_CT {
1241 var default sysinfo := activate(as_catch_RSL_sysinfo(bts_idx));
1242
1243 f_init_bts(bts_idx, handler_mode);
1244
1245 /* Give some time to (hopefully/most likely) collect all system informations from RSL startup.
1246 * We could stop as soon as all expected SI are received, but then we might miss SI that we don't expect and
1247 * that might be sent afterwards. So rather give a generous timeout and be quite sure to catch all SI.
1248 */
1249 f_sleep(5.0);
1250 log("RSL ", bts_idx, " SYSTEM INFORMATION: ", g_system_information[bts_idx]);
1251
1252 deactivate(sysinfo);
1253
1254 if (match(g_system_information[bts_idx], expect_si)) {
1255 setverdict(pass);
1256 } else {
1257 log("RSL ", bts_idx, ": EXPECTED SI: ", expect_si);
1258 log("RSL ", bts_idx, ": GOT SI: ", g_system_information[bts_idx]);
1259 setverdict(fail, "received SI does not match expectations");
1260 return;
1261 }
1262}
1263
Maxd4e56962018-10-31 19:08:25 +01001264/* expect to receive a RSL message matching a specified template on a given BTS / stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001265function 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 +01001266runs on test_CT return RSL_Message {
1267 var ASP_RSL_Unitdata rx_rsl_ud;
1268 timer T := t_secs;
1269
1270 T.start;
1271 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001272 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
Harald Welteae026692017-12-09 01:03:01 +01001273 T.stop;
1274 }
1275 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +01001276 [] T.timeout {
1277 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +02001278 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +01001279 }
Harald Welteae026692017-12-09 01:03:01 +01001280 }
1281 return rx_rsl_ud.rsl;
1282}
1283
Harald Welte21b46bd2017-12-17 19:46:32 +01001284/* helper function to transmit RSL on a given BTS/stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001285function 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 +01001286runs on test_CT {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001287 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(t_tx, sid));
Harald Welteae026692017-12-09 01:03:01 +01001288}
1289
1290
Harald Welte4003d112017-12-09 22:35:39 +01001291/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +01001292testcase TC_chan_act_noreply() runs on test_CT {
1293 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +01001294 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +01001295
Harald Welte89d42e82017-12-17 16:42:41 +01001296 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +01001297
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001298 IPA_RSL[0].send(ts_ASP_RSL_UD(ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +01001299 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001300 f_shutdown_helper();
Harald Welte28d943e2017-11-25 15:00:50 +01001301}
1302
Neels Hofmeyr734b1a32021-11-29 16:00:17 +01001303const CounterNameVals counternames_bts_chreq := {
1304 { "chreq:total", 0 },
1305 { "chreq:attempted_emerg", 0 },
1306 { "chreq:attempted_call", 0 },
1307 { "chreq:attempted_location_upd", 0 },
1308 { "chreq:attempted_pag", 0 },
1309 { "chreq:attempted_pdch", 0 },
1310 { "chreq:attempted_other", 0 },
1311 { "chreq:attempted_unknown", 0 },
1312 { "chreq:successful", 0 },
1313 { "chreq:successful_emerg", 0 },
1314 { "chreq:successful_call", 0 },
1315 { "chreq:successful_location_upd", 0 },
1316 { "chreq:successful_pag", 0 },
1317 { "chreq:successful_pdch", 0 },
1318 { "chreq:successful_other", 0 },
1319 { "chreq:successful_unknown", 0 },
1320 { "chreq:no_channel", 0 },
1321 { "chreq:max_delay_exceeded", 0 }
1322};
1323
1324/* verify the "chreq:*" counters */
1325private function f_chan_act_counter(OCT1 ra, charstring chreq_ctr_suffix) runs on test_CT
1326{
1327 var GsmFrameNumber fn := 23;
1328
1329 f_logp(BSCVTY, "f_chan_act_counter(" & chreq_ctr_suffix & ")");
1330
1331 var RSL_Message rx_rsl;
1332 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1333 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1334 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1335
1336 f_ctrs_bts_add(0, "chreq:total");
1337 f_ctrs_bts_add(0, "chreq:attempted_" & chreq_ctr_suffix);
1338 f_ctrs_bts_verify();
1339
1340 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
1341 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
1342
1343 f_ctrs_bts_add(0, "chreq:successful");
1344 f_ctrs_bts_add(0, "chreq:successful_" & chreq_ctr_suffix);
1345 f_ctrs_bts_verify();
1346
1347 /* test is done, release RSL Conn Fail Ind to clean up */
1348 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1349 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1350 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
1351 f_sleep(1.0);
1352}
1353
Harald Welte4003d112017-12-09 22:35:39 +01001354testcase TC_chan_act_counter() runs on test_CT {
1355 var BSSAP_N_UNITDATA_ind ud_ind;
1356 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +01001357 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +01001358
Harald Welte89d42e82017-12-17 16:42:41 +01001359 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001360
Neels Hofmeyr734b1a32021-11-29 16:00:17 +01001361 f_vty_allow_emerg_bts(true, 0);
1362
1363 f_ctrs_bts_init(1, counternames_bts_chreq);
1364
1365 /* emergency call: RA & 0xe0 == 0xa0 --> CHREQ_T_EMERG_CALL */
1366 f_chan_act_counter('a3'O, "emerg");
1367
1368 /* voice TCH/H: RA & 0xf0 == 0x40 --> CHREQ_T_VOICE_CALL_TCH_H */
1369 f_chan_act_counter('43'O, "call");
1370
1371 /* LU: RA & 0xf0 == 0x00 --> CHREQ_T_LOCATION_UPD */
1372 f_chan_act_counter('03'O, "location_upd");
1373
1374 /* Paging: RA & 0xf0 == 0x20 --> CHREQ_T_PAG_R_TCH_F */
1375 f_chan_act_counter('23'O, "pag");
1376 /* Paging: RA & 0xf0 == 0x30 --> CHREQ_T_PAG_R_TCH_FH */
1377 f_chan_act_counter('33'O, "pag");
1378
1379 /* LU: RA & 0xfc == 0x78 --> CHREQ_T_PDCH_TWO_PHASE */
1380 /* no PCU, so PDCH not allowed. Skip this test for now. */
1381 /* f_chan_act_counter('7b'O, "pdch"); */
1382
1383 /* LU: RA & 0xf0 == 0x10 --> CHREQ_T_SDCCH */
1384 f_chan_act_counter('13'O, "other");
Harald Welte4003d112017-12-09 22:35:39 +01001385
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001386 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001387}
1388
Harald Welteae026692017-12-09 01:03:01 +01001389/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
Philipp Maier9c60a622020-07-09 15:08:46 +02001390private function f_TC_chan_act_ack_noest(OCT1 ra := '23'O) runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +01001391 var RSL_Message rx_rsl;
1392
Harald Welteae026692017-12-09 01:03:01 +01001393 /* Send CHAN RQD and wait for allocation; acknowledge it */
Philipp Maier9c60a622020-07-09 15:08:46 +02001394 var RslChannelNr chan_nr := f_chreq_act_ack(ra);
Harald Welteae026692017-12-09 01:03:01 +01001395
1396 /* expect BSC to disable the channel again if there's no RLL EST IND */
1397 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1398
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001399 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001400}
1401
Philipp Maier9c60a622020-07-09 15:08:46 +02001402/* Normal variant */
1403testcase TC_chan_act_ack_noest() runs on test_CT {
Philipp Maieraf58db22020-08-12 17:24:40 +02001404 f_init(1);
Philipp Maier9c60a622020-07-09 15:08:46 +02001405 f_TC_chan_act_ack_noest();
1406}
1407
1408/* Emergency call variant */
1409testcase TC_chan_act_ack_noest_emerg() runs on test_CT {
1410 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
Philipp Maieraf58db22020-08-12 17:24:40 +02001411 f_init(1);
1412 f_vty_allow_emerg_bts(true, 0);
Philipp Maier9c60a622020-07-09 15:08:46 +02001413 f_TC_chan_act_ack_noest(ra := 'A5'O);
1414}
1415
Philipp Maier606f07d2020-08-12 17:21:58 +02001416/* Emergency call variant, but emergency calls are not allowed */
1417testcase TC_chan_rqd_emerg_deny() runs on test_CT {
1418 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
1419
1420 var RSL_Message rx_rsl;
1421 var GsmRrMessage rr;
1422
1423 f_init(1);
1424 f_vty_allow_emerg_bts(false, 0);
1425
1426 IPA_RSL[0].clear;
1427 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
1428
1429 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
1430 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
1431 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1432 setverdict(pass);
1433 } else {
1434 setverdict(fail, "immediate assignment not rejected");
1435 }
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01001436
1437 f_shutdown_helper();
Philipp Maier606f07d2020-08-12 17:21:58 +02001438}
1439
Harald Welteae026692017-12-09 01:03:01 +01001440/* Test behavior if MSC never answers to CR */
1441testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +01001442 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
1443 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +01001444 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +01001445 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +01001446
Harald Welte89d42e82017-12-17 16:42:41 +01001447 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001448
1449 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001450 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001451
1452 var octetstring l3 := '00010203040506'O
1453 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1454
1455 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
1456
1457 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +01001458 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001459 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001460 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001461}
1462
1463/* Test behavior if MSC answers with CREF to CR */
1464testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
1465 var BSSAP_N_CONNECT_ind rx_c_ind;
1466 var RSL_Message rx_rsl;
1467
Harald Welte89d42e82017-12-17 16:42:41 +01001468 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001469
1470 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001471 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001472
1473 var octetstring l3 := '00010203040506'O
1474 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1475
1476 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1477 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
1478
1479 /* expect BSC to disable the channel */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001480 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001481 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001482}
1483
Harald Welte618ef642017-12-14 14:58:20 +01001484/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
1485testcase TC_chan_act_nack() runs on test_CT {
1486 var RSL_Message rx_rsl;
1487 var integer chact_nack;
1488
Harald Welte89d42e82017-12-17 16:42:41 +01001489 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +01001490
1491 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
1492
1493 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
1494 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1495 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1496
1497 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
1498
1499 /* wait for some time to hope the NACK arrives before the CTRL GET below */
1500 f_sleep(0.5);
1501
1502 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
1503
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001504 f_shutdown_helper();
Harald Welte618ef642017-12-14 14:58:20 +01001505}
1506
Harald Welte799c97b2017-12-14 17:50:30 +01001507/* Test for channel exhaustion due to RACH overload */
1508testcase TC_chan_exhaustion() runs on test_CT {
1509 var ASP_RSL_Unitdata rsl_ud;
1510 var integer i;
1511 var integer chreq_total, chreq_nochan;
1512
Harald Welte89d42e82017-12-17 16:42:41 +01001513 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +01001514
1515 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
1516 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
1517
Neels Hofmeyr85fa37f2021-10-06 13:50:38 +02001518 /* GSM 44.018 Table 9.1.8.2:
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +01001519 * RA = '33'O -> Establishment cause = 0011xxxx (MS dual rate capable and asks for "TCH/H or TCH/F").
1520 * With current setup, expect 4xSDCCH + 4xTCH/F + 1xTCH/H to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +02001521 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 +01001522 var RslChannelNr chan_nr := f_chreq_act_ack('33'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +01001523 }
1524
1525 IPA_RSL[0].clear;
1526
Harald Weltedd8cbf32018-01-28 12:07:52 +01001527 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001528 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +01001529
1530 /* now expect additional channel activations to fail */
1531 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
1532
1533 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001534 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
Harald Welte799c97b2017-12-14 17:50:30 +01001535 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
1536 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001537 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
Harald Welte799c97b2017-12-14 17:50:30 +01001538 var GsmRrMessage rr;
1539 /* match on IMM ASS REJ */
1540 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
1541 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1542 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001543 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +01001544 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
1545 chreq_nochan+1);
1546 setverdict(pass);
1547 } else {
1548 repeat;
1549 }
1550 }
1551 [] IPA_RSL[0].receive { repeat; }
1552 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001553 f_shutdown_helper();
Harald Welte799c97b2017-12-14 17:50:30 +01001554}
1555
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001556/* Test channel deactivation due to silence from MS */
1557testcase TC_chan_deact_silence() runs on test_CT {
1558 var RslChannelNr chan_nr;
1559
1560 f_init(1);
1561
1562 /* Request for a dedicated channel */
1563 chan_nr := f_chreq_act_ack('23'O);
1564
1565 /* Wait some time until the channel is released */
1566 f_sleep(2.0);
1567
1568 /* Expect CHANnel RELease */
1569 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001570 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001571 log("Received CHANnel RELease");
1572 setverdict(pass);
1573 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001574 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001575 /* See OS#3709, OsmoBSC should not send Immediate
1576 * Assignment Reject since a dedicated channel was
1577 * already allocated, and Immediate Assignment was
1578 * already sent. */
1579 setverdict(fail, "Unexpected Immediate Assignment!");
1580 }
1581 [] IPA_RSL[0].receive {
1582 setverdict(fail, "Unexpected RSL message!");
1583 }
1584 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001585 f_shutdown_helper();
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001586}
1587
Harald Weltecfe2c962017-12-15 12:09:32 +01001588/***********************************************************************
1589 * Assignment Testing
1590 ***********************************************************************/
1591
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001592/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction,
1593 * except for the inter-BSC handover, MT side) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001594testcase TC_outbound_connect(integer bssap_idx := 0) runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +01001595 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +01001596
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001597 BSSAP.send(ts_BSSAP_CONNECT_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
1598 2342, ts_BSSMAP_AssignmentReq));
Harald Weltecfe2c962017-12-15 12:09:32 +01001599 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001600 f_shutdown_helper();
Harald Weltecfe2c962017-12-15 12:09:32 +01001601}
1602
Harald Welte16a4adf2017-12-14 18:54:01 +01001603/* Test behavior if MSC answers with CREF to CR */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001604testcase TC_assignment_cic_only(integer bssap_idx := 0) runs on test_CT {
Harald Welte16a4adf2017-12-14 18:54:01 +01001605 var BSSAP_N_CONNECT_ind rx_c_ind;
1606 var RSL_Message rx_rsl;
1607 var DchanTuple dt;
1608
Harald Welte89d42e82017-12-17 16:42:41 +01001609 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +01001610
1611 dt := f_est_dchan('23'O, 23, '00000000'O);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001612 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte17b27da2018-05-25 20:33:53 +02001613 /* send assignment without AoIP IEs */
1614 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
1615 } else {
1616 /* Send assignmetn without CIC in IPA case */
1617 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
1618 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
1619 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
1620 }
Harald Welte16a4adf2017-12-14 18:54:01 +01001621 alt {
1622 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1623 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
1624 }
Harald Welte235ebf12017-12-15 14:18:16 +01001625 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +01001626 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1627 setverdict(pass);
1628 }
1629 [] BSSAP.receive { repeat; }
1630 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001631 f_shutdown_helper();
Harald Welte16a4adf2017-12-14 18:54:01 +01001632}
1633
Harald Welteed848512018-05-24 22:27:58 +02001634/* generate an assignment request for either AoIP or SCCPlite */
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001635function 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 +02001636 var PDU_BSSAP ass_cmd;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001637 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001638 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welteed848512018-05-24 22:27:58 +02001639 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001640 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001641 if (osmux_enabled) {
1642 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla, osmux_cid));
1643 } else {
1644 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
1645 }
Harald Welteed848512018-05-24 22:27:58 +02001646 } else {
1647 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001648 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
Harald Welteed848512018-05-24 22:27:58 +02001649 }
1650 return ass_cmd;
1651}
1652
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02001653function f_gen_handover_req(integer bssap_idx := 0, charstring aoip_tla := "1.2.3.4",
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001654 template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit,
1655 template (omit) TestHdlrEncrParams enc := omit) return PDU_BSSAP {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001656 var PDU_BSSAP ho_req;
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001657
1658 var BSSMAP_IE_EncryptionInformation encryptionInformation :=
1659 valueof(ts_BSSMAP_IE_EncrInfo('0000000000000000'O,'01'O));
1660 var template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm := omit;
1661 var template BSSMAP_IE_KC128 kc128 := omit;
1662 if (ispresent(enc)) {
1663 var TestHdlrEncrParams v_enc := valueof(enc);
1664 encryptionInformation := valueof(ts_BSSMAP_IE_EncrInfo(v_enc.enc_key, v_enc.enc_alg));
1665 chosenEncryptionAlgorithm := valueof(
1666 ts_BSSMAP_IE_ChosenEncryptionAlgorithm(int2oct(enum2int(
Oliver Smith598e1ed2021-07-09 10:28:40 +02001667 f_cipher_mode_bssmap_to_rsl(v_enc.enc_alg)), 1)));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001668 if (ispresent(v_enc.enc_kc128)) {
1669 kc128 := ts_BSSMAP_IE_Kc128(v_enc.enc_kc128);
1670 }
1671 }
1672
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001673 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001674 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001675 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001676 ho_req := valueof(ts_BSSMAP_HandoverRequest(omit, tla, oldToNewBSSIEs := oldToNewBSSIEs,
1677 encryptionInformation := encryptionInformation,
1678 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
1679 kC128 := kc128));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001680 } else {
1681 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001682 ho_req := valueof(ts_BSSMAP_HandoverRequest(cic, omit, oldToNewBSSIEs := oldToNewBSSIEs,
1683 encryptionInformation := encryptionInformation,
1684 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
1685 kC128 := kc128));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001686 }
1687 return ho_req;
1688}
1689
Harald Welteed848512018-05-24 22:27:58 +02001690/* generate an assignment complete template for either AoIP or SCCPlite */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001691function f_gen_exp_compl(boolean expect_osmux := false, integer bssap_idx := 0) return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +02001692 var template PDU_BSSAP exp_compl;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001693 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001694 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001695 if (expect_osmux) {
1696 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, osmux_cid);
1697 } else {
1698 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, omit);
1699 }
Harald Welteed848512018-05-24 22:27:58 +02001700 } else {
1701 /* CIC is optional "*" as the MSC allocated it */
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001702 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
Harald Welteed848512018-05-24 22:27:58 +02001703 }
1704 return exp_compl;
1705}
1706
Harald Welte235ebf12017-12-15 14:18:16 +01001707/* Run everything required up to sending a caller-specified assignment command and expect response */
1708function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
1709runs on test_CT {
1710 var BSSAP_N_CONNECT_ind rx_c_ind;
1711 var RSL_Message rx_rsl;
1712 var DchanTuple dt;
1713
Harald Welte89d42e82017-12-17 16:42:41 +01001714 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +01001715
1716 dt := f_est_dchan('23'O, 23, '00000000'O);
1717 /* send assignment without AoIP IEs */
1718 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
1719 alt {
1720 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1721 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
1722 setverdict(pass);
1723 } else {
1724 setverdict(fail, fail_text);
1725 }
1726 }
1727 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1728 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
1729 setverdict(pass);
1730 } else {
1731 setverdict(fail, fail_text);
1732 }
1733 }
1734 [] BSSAP.receive { repeat; }
1735 }
1736}
1737testcase TC_assignment_csd() runs on test_CT {
1738 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001739 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001740 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1741 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
1742 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001743 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001744}
1745
1746testcase TC_assignment_ctm() runs on test_CT {
1747 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001748 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001749 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
1750 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
1751 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001752 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001753}
1754
Harald Welte4003d112017-12-09 22:35:39 +01001755type record DchanTuple {
1756 integer sccp_conn_id,
1757 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +01001758}
1759
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +02001760type record of DchanTuple DchanTuples;
1761
Harald Welted6939652017-12-13 21:02:46 +01001762/* Send CHAN RQD and wait for allocation; acknowledge it */
1763private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
1764runs on test_CT return RslChannelNr {
1765 var RSL_Message rx_rsl;
1766 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1767 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1768 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1769 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
Daniel Willmannf4ac4ce2018-08-02 14:06:30 +02001770 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Harald Welted6939652017-12-13 21:02:46 +01001771 return chan_nr;
1772}
1773
Harald Welte4003d112017-12-09 22:35:39 +01001774/* helper function to establish a dedicated channel via BTS and MSC */
1775function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1776runs on test_CT return DchanTuple {
1777 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +01001778 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001779
Harald Welte4003d112017-12-09 22:35:39 +01001780 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001781 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +01001782
1783 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1784
1785 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1786 dt.sccp_conn_id := rx_c_ind.connectionId;
1787 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1788
1789 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001790}
1791
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02001792/* Like f_est_dchan(), but for the first lchan of a dynamic timeslot: first ACK the deactivation of PDCH. */
1793function f_est_dchan_dyn(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1794runs on test_CT return DchanTuple {
1795 var BSSAP_N_CONNECT_ind rx_c_ind;
1796 var DchanTuple dt;
1797
1798 /* Send CHAN RQD */
1799 var RSL_Message rx_rsl;
1800 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1801
1802 /* The dyn TS first deactivates PDCH */
1803 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1804 dt.rsl_chan_nr := rx_rsl.ies[0].body.chan_nr;
1805 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1806
1807 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1808 dt.rsl_chan_nr := rx_rsl.ies[0].body.chan_nr;
1809
1810 /* Now activates the signalling channel */
1811 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, fn+10));
1812 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
1813
1814 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1815
1816 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1817 dt.sccp_conn_id := rx_c_ind.connectionId;
1818 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1819
1820 return dt;
1821}
1822
Harald Welte641fcbe2018-06-14 10:58:35 +02001823/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
1824private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
1825 var RSL_Message rx_rsl;
1826 /* expect BSC to disable the channel */
1827 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1828 /* respond with CHAN REL ACK */
1829 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1830
1831 /* expect Clear Complete from BSC */
1832 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1833
1834 /* MSC disconnects as instructed. */
1835 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1836}
1837
Harald Welte4003d112017-12-09 22:35:39 +01001838/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
1839testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001840 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001841 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +01001842
Harald Welte89d42e82017-12-17 16:42:41 +01001843 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +01001844
Harald Welte4003d112017-12-09 22:35:39 +01001845 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1846
1847 /* simulate RLL REL IND */
1848 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
1849
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001850 /* expect Clear Request on MSC side */
1851 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1852
1853 /* Instruct BSC to clear channel */
1854 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1855 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1856
Harald Welte4003d112017-12-09 22:35:39 +01001857 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001858 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001859
1860 /* wait for SCCP emulation to do its job */
1861 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +01001862
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001863 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001864}
1865
1866/* Test behavior of channel release after CONN FAIL IND from BTS */
1867testcase TC_chan_rel_conn_fail() runs on test_CT {
1868 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001869 var DchanTuple dt;
1870
Harald Welte89d42e82017-12-17 16:42:41 +01001871 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001872
1873 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1874
1875 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +01001876 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 +01001877 /* TODO: different cause values? */
1878
Harald Welte4003d112017-12-09 22:35:39 +01001879 /* expect Clear Request from BSC */
1880 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1881
1882 /* Instruct BSC to clear channel */
1883 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1884 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1885
Harald Welte6ff76ea2018-01-28 13:08:01 +01001886 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001887 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +01001888
1889 /* wait for SCCP emulation to do its job */
1890 f_sleep(1.0);
1891
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001892 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001893}
1894
Harald Welte99f3ca02018-06-14 13:40:29 +02001895/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
1896/* See also https://www.osmocom.org/issues/3182 */
1897testcase TC_early_conn_fail() runs on test_CT {
1898 var RSL_Message rx_rsl;
1899 var DchanTuple dt;
1900
1901 f_init(1);
1902
1903 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
Harald Weltec46ea3c2020-10-10 18:46:12 +02001904 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_ra_cs(), 23);
Harald Welte99f3ca02018-06-14 13:40:29 +02001905
1906 /* BTS->BSC: simulate CONN FAIL IND */
1907 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1908
1909 /* BTS->BSC: Expect RF channel release from BSC on Abis */
1910 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1911
1912 /* BTS<-BSC: respond with CHAN REL ACK */
1913 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1914
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001915 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001916}
1917
1918/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
1919/* See also https://www.osmocom.org/issues/3182 */
1920testcase TC_late_conn_fail() runs on test_CT {
1921 var RSL_Message rx_rsl;
1922 var DchanTuple dt;
1923
1924 f_init(1);
1925
1926 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1927
1928 /* BSC<-MSC: Instruct BSC to clear connection */
1929 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
1930
1931 /* BTS->BSC: expect BSC to deactivate SACCH */
1932 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
1933
1934 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
1935 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1936
1937 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
1938 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1939 /* BTS->BSC: respond with CHAN REL ACK */
1940 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1941
1942 /* BSC->MSC: expect Clear Complete from BSC */
1943 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1944
1945 /* BSC<-MSC: MSC disconnects as requested. */
1946 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1947
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001948 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001949}
1950
Oliver Smithaf03bef2021-08-24 15:34:51 +02001951private function f_TC_stats_conn_fail(charstring id) runs on MSC_ConnHdlr {
1952 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
1953 var PDU_BSSAP ass_cmd := f_gen_ass_req();
1954
1955 f_statsd_reset();
1956
1957 /* Establish SDCCH */
1958 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1959 f_establish_fully(ass_cmd, exp_fail);
1960
1961 /* Expect stats to be 0 */
1962 var StatsDExpects expect := {
1963 {name := "TTCN3.bts.0.chan.rf_fail", mtype := "c", min := 0, max := 0},
1964 {name := "TTCN3.bts.0.chan.rf_fail_sdcch", mtype := "c", min := 0, max := 0}
1965 };
1966 f_statsd_expect(expect);
1967
1968 /* Simulate CONN FAIL IND on SDCCH */
1969 RSL.send(ts_ASP_RSL_UD(
1970 ts_RSL_CONN_FAIL_IND(g_chan_nr, RSL_ERR_RADIO_LINK_FAIL),
1971 IPAC_PROTO_RSL_TRX0));
1972
Neels Hofmeyr58be48a2021-09-07 18:39:21 +02001973 f_sleep(1.0);
1974
Oliver Smithaf03bef2021-08-24 15:34:51 +02001975 /* Expect stats to be 1 */
1976 expect := {
1977 {name := "TTCN3.bts.0.chan.rf_fail", mtype := "c", min := 1, max := 1},
1978 {name := "TTCN3.bts.0.chan.rf_fail_sdcch", mtype := "c", min := 1, max := 1}
1979 };
1980 f_statsd_expect(expect);
1981}
1982testcase TC_stats_conn_fail() runs on test_CT {
1983 var TestHdlrParams pars := f_gen_test_hdlr_pars();
1984 var MSC_ConnHdlr vc_conn;
1985
1986 f_init(1, true);
1987 f_sleep(1.0);
1988
1989 vc_conn := f_start_handler(refers(f_TC_stats_conn_fail), pars);
1990 vc_conn.done;
1991
1992 f_shutdown_helper();
1993}
1994
Neels Hofmeyrf44ccd12018-11-05 19:15:23 +01001995function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr,
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001996 boolean expect_deact_sacch := true,
1997 boolean expect_rr_chan_rel := true,
1998 boolean expect_rll_rel_req := true,
Harald Welte99787102019-02-04 10:41:36 +01001999 boolean handle_rll_rel := true,
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002000 template CellSelIndValue expect_cells := omit,
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002001 template RR_Cause expect_rr_cause := ?
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002002 ) runs on test_CT {
Harald Welte91d54a52018-01-28 15:35:07 +01002003
2004 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002005 var boolean got_deact_sacch := false;
2006 var boolean got_rr_chan_rel := false;
2007 var boolean got_rll_rel_req := false;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002008 var ASP_RSL_Unitdata ud;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002009 var RSL_IE_Body l3_ie;
2010 var PDU_ML3_NW_MS l3;
2011 var RR_Cause got_cause;
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002012 log("f_expect_chan_rel() expecting: expect_deact_sacch=", expect_deact_sacch, " expect_rr_chan_rel=", expect_rr_chan_rel,
2013 " expect_rll_rel_req=", expect_rll_rel_req);
Harald Welte91d54a52018-01-28 15:35:07 +01002014 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002015 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002016 got_deact_sacch := true;
Harald Welte91d54a52018-01-28 15:35:07 +01002017 repeat;
2018 }
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002019 [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 +01002020 got_rr_chan_rel := true;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002021
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002022 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
2023 setverdict(fail, "cannot find L3");
2024 mtc.stop;
2025 }
2026 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
2027
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002028 if (not istemplatekind(expect_cells, "omit")) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002029 var CellSelIndValue cells := dec_CellSelIndValue(
2030 l3.msgs.rrm.channelRelease.cellSelectionIndicator.cellSelectionIndicatorValue);
2031
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002032 log("GOT RR CHANNEL RELEASE WITH CELLS: ", cells);
2033 if (match(cells, expect_cells)) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002034 setverdict(pass);
2035 } else {
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002036 log("EXPECTED CELLS: ", expect_cells);
2037 setverdict(fail, "Received cells list on RR Channel Release does not match expectations");
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002038 }
2039 }
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002040
2041 if (not istemplatekind(expect_rr_cause, "omit")) {
2042 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
2043 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
2044 if (match(got_cause, expect_rr_cause)) {
2045 setverdict(pass);
2046 } else {
2047 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
2048 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
2049 }
2050 }
Harald Welte99787102019-02-04 10:41:36 +01002051 repeat;
2052 }
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002053 [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 +01002054 got_rr_chan_rel := true;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002055
2056 if (not istemplatekind(expect_rr_cause, "omit")) {
2057 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
2058 setverdict(fail, "cannot find L3");
2059 mtc.stop;
2060 }
2061 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
2062
2063 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
2064 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
2065 if (match(got_cause, expect_rr_cause)) {
2066 setverdict(pass);
2067 } else {
2068 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
2069 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
2070 }
2071 }
Neels Hofmeyr211169d2018-11-07 00:37:29 +01002072 repeat;
2073 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002074 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002075 got_rll_rel_req := true;
Harald Welte91d54a52018-01-28 15:35:07 +01002076 /* FIXME: Why are we getting this for LinkID SACCH? */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002077 if (handle_rll_rel) {
2078 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
2079 }
Harald Welte91d54a52018-01-28 15:35:07 +01002080 repeat;
2081 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002082 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Harald Welte91d54a52018-01-28 15:35:07 +01002083 /* respond with CHAN REL ACK */
2084 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
2085 }
2086 /* ignore any user data */
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002087 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeR(?))) {
Harald Welte91d54a52018-01-28 15:35:07 +01002088 repeat;
2089 }
2090 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002091
2092 log("f_expect_chan_rel() summary: got_deact_sacch=", got_deact_sacch, " got_rr_chan_rel=", got_rr_chan_rel,
2093 " got_rll_rel_req=", got_rll_rel_req);
2094
2095 if (expect_deact_sacch != got_deact_sacch) {
2096 setverdict(fail, "f_expect_chan_rel(): expect_deact_sacch=", expect_deact_sacch, " got_deact_sacch=", got_deact_sacch);
2097 }
2098 if (expect_rr_chan_rel != got_rr_chan_rel) {
2099 setverdict(fail, "f_expect_chan_rel(): expect_rr_chan_rel=", expect_rr_chan_rel, " got_rr_chan_rel=", got_rr_chan_rel);
2100 }
2101 if (expect_rll_rel_req != got_rll_rel_req) {
2102 setverdict(fail, "f_expect_chan_rel(): expect_rll_rel_req=", expect_rll_rel_req, " got_rll_rel_req=", got_rll_rel_req);
2103 }
Harald Welte91d54a52018-01-28 15:35:07 +01002104}
2105
Harald Welte4003d112017-12-09 22:35:39 +01002106/* Test behavior of channel release after hard Clear Command from MSC */
2107testcase TC_chan_rel_hard_clear() runs on test_CT {
2108 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01002109 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +01002110
Harald Welte89d42e82017-12-17 16:42:41 +01002111 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002112
2113 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2114
2115 /* Instruct BSC to clear channel */
2116 var BssmapCause cause := 0;
2117 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2118
2119 /* expect Clear Complete from BSC on A */
2120 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2121 /* release the SCCP connection */
2122 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2123 }
2124
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002125 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002126 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002127}
2128
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002129function f_TC_chan_rel_last_eutran_plmn_hard_clear(boolean tx_csfb_ind) runs on test_CT {
2130 var BSSAP_N_DATA_ind rx_di;
2131 var DchanTuple dt;
2132
2133 f_init(1);
2134
2135 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2136 /* Send CommonID with some random PLMN (BSC doesn't take it into account
2137 /* yet when generating the EUTRAN neigh list in RR CHannel Release) */
2138 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
2139
2140 /* Instruct BSC to clear channel */
2141 var BssmapCause cause := 0;
2142 if (tx_csfb_ind) {
2143 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2144 } else {
2145 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2146 }
2147
2148 /* expect Clear Complete from BSC on A */
2149 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2150 /* release the SCCP connection */
2151 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2152 }
2153
2154 /* 1 neighbor is added by default in osmo-bts.cfg and
2155 SystemInformationConfig_default, use that: */
2156 var template CellSelIndValue exp_cells := f_tr_rr_chan_rel_earfcns(1);
2157
2158 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, expect_cells := exp_cells);
2159 f_shutdown_helper();
2160}
2161
2162/* Test behavior of RR Channel rRelease after Clear Command without CSFB indicator
2163 from MSC, previously receiving any CommonID containing the "Last Used E-UTRAN
2164 PLMN Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
2165 EUTRAN neighbor list sent later on by BSC in RR Channel, so receiving CSFB
2166 Indicator or not shouldn't matter at all. */
2167testcase TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() runs on test_CT {
2168 f_TC_chan_rel_last_eutran_plmn_hard_clear(false);
2169}
2170
2171/* Test behavior of RR Channel rRelease after Clear Command with CSFB indicator from
2172 MSC, previously receiving any CommonID containing the "Last Used E-UTRAN PLMN
2173 Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
2174 EUTRAN neighbor list sent later on by BSC in RR Channel. */
2175testcase TC_chan_rel_last_eutran_plmn_hard_clear_csfb() runs on test_CT {
2176 f_TC_chan_rel_last_eutran_plmn_hard_clear(true);
2177}
2178
2179/* Test behavior of RR Channel Release after Clear Command with CSFB indicator from
2180 MSC, without receiving any CommonID containing the "Last Used E-UTRAN PLMN
2181 Id". According to spec (TS 48.008 version 16.0.0 Release 16 "3.2.1.21") the
2182 CSFB Indicator should not be used anymore, and hence, there should be no
2183 EUTRAN neighbor list sent by BSC in RR Channel release since no CommonId with
2184 Last Used E-UTRAN PLMN Id" IE was sent for this conn. */
Harald Welte99787102019-02-04 10:41:36 +01002185testcase TC_chan_rel_hard_clear_csfb() runs on test_CT {
2186 var BSSAP_N_DATA_ind rx_di;
2187 var DchanTuple dt;
2188
2189 f_init(1);
2190
2191 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2192
2193 /* Instruct BSC to clear channel */
2194 var BssmapCause cause := 0;
2195 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2196
2197 /* expect Clear Complete from BSC on A */
2198 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2199 /* release the SCCP connection */
2200 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2201 }
2202
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002203 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002204 f_shutdown_helper();
Harald Welte99787102019-02-04 10:41:36 +01002205}
2206
Harald Welted8c36cd2017-12-09 23:05:31 +01002207/* Test behavior of channel release after hard RLSD from MSC */
2208testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +01002209 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +01002210
Harald Welte89d42e82017-12-17 16:42:41 +01002211 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +01002212
2213 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2214
2215 /* release the SCCP connection */
2216 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2217
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002218 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002219 f_shutdown_helper();
Harald Welted8c36cd2017-12-09 23:05:31 +01002220}
2221
Harald Welte550daf92018-06-11 19:22:13 +02002222/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
2223testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
2224 var DchanTuple dt;
2225
2226 f_init(1);
2227
2228 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2229
2230 /* release the SCCP connection */
2231 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2232
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002233 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002234 f_shutdown_helper();
Harald Welte550daf92018-06-11 19:22:13 +02002235}
2236
Harald Welte85804d42017-12-10 14:11:58 +01002237/* Test behavior of channel release after BSSMAP RESET from MSC */
2238testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +01002239 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +01002240
Harald Welte89d42e82017-12-17 16:42:41 +01002241 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +01002242
2243 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2244
2245 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
2246 IPA_RSL[0].clear;
2247
2248 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002249 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 +01002250 interleave {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002251 [] 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 +01002252 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
2253 }
2254
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002255 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002256 f_shutdown_helper();
Harald Welte85804d42017-12-10 14:11:58 +01002257}
2258
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002259/* Verify T(iar) triggers and releases the channel */
2260testcase TC_chan_rel_sccp_tiar_timeout() runs on test_CT {
2261 var DchanTuple dt;
2262
2263 /* Set T(iar) in BSC low enough that it will trigger before other side
2264 has time to keep alive with a T(ias). Keep recommended ratio of
2265 T(iar) >= T(ias)*2 */
2266 g_bsc_sccp_timer_ias := 2;
2267 g_bsc_sccp_timer_iar := 5;
2268
2269 f_init(1);
2270
2271 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2272 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002273 f_shutdown_helper();
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002274}
2275
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002276private function f_tc_chan_rel_rr_cause(myBSSMAP_Cause clear_cmd_cause, template RR_Cause expect_rr_cause)
2277runs on test_CT
2278{
2279 var DchanTuple dt;
2280
2281 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2282 var BssmapCause cause := 0;
2283 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(enum2int(clear_cmd_cause))));
2284 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2285 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2286 }
2287
2288 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 +02002289}
2290
2291/* Test that Clear Command cause codes affect the RR Channel Release cause code */
2292testcase TC_chan_rel_rr_cause() runs on test_CT {
2293 f_init(1);
2294
2295 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_CALL_CONTROL, GSM48_RR_CAUSE_NORMAL);
2296 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_HANDOVER_SUCCESSFUL, GSM48_RR_CAUSE_NORMAL);
2297 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_PREEMPTION, GSM48_RR_CAUSE_PREMPTIVE_REL);
2298 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE, GSM48_RR_CAUSE_PROT_ERROR_UNSPC);
2299 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
2300 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_EQUIPMENT_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
Vadim Yanitskiye18aebb2021-01-03 13:10:43 +01002301
2302 f_shutdown_helper();
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002303}
2304
Harald Welte5cd20ed2017-12-13 21:03:20 +01002305/* Test behavior if RSL EST IND for non-active channel */
2306testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
2307 timer T := 2.0;
2308
Harald Welte89d42e82017-12-17 16:42:41 +01002309 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002310
2311 var octetstring l3 := '00010203040506'O;
2312 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2313 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
2314
2315 T.start;
2316 alt {
2317 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2318 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
2319 }
2320 [] BSSAP.receive {}
2321 [] IPA_RSL[0].receive {}
2322 [] T.timeout {}
2323 }
2324
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002325 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002326}
2327
2328/* Test behavior if RSL EST IND for invalid SAPI */
2329testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
2330 var RslChannelNr chan_nr;
2331
Harald Welte89d42e82017-12-17 16:42:41 +01002332 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002333
2334 chan_nr := f_chreq_act_ack()
2335
2336 var octetstring l3 := '00010203040506'O;
2337 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
2338
2339 timer T := 2.0;
2340 T.start;
2341 alt {
2342 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2343 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
2344 }
2345 [] BSSAP.receive { repeat; }
2346 [] IPA_RSL[0].receive { repeat; }
2347 [] T.timeout {}
2348 }
2349
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002350 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002351}
2352
2353/* Test behavior if RSL EST IND for invalid SAPI */
2354testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
2355 timer T := 2.0;
2356
Harald Welte89d42e82017-12-17 16:42:41 +01002357 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002358
2359 var RslChannelNr chan_nr := f_chreq_act_ack();
2360
2361 var octetstring l3 := '00010203040506'O;
2362 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
2363
2364 T.start;
2365 alt {
2366 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2367 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
2368 }
2369 [] BSSAP.receive { repeat; }
2370 [] IPA_RSL[0].receive { repeat; }
2371 [] T.timeout {}
2372 }
2373
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002374 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002375}
2376
2377/* Test behavior if RSL EST IND for invalid SACCH */
2378testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
2379 timer T := 2.0;
2380
Harald Welte89d42e82017-12-17 16:42:41 +01002381 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002382
2383 var RslChannelNr chan_nr := f_chreq_act_ack();
2384
2385 var octetstring l3 := '00010203040506'O;
2386 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
2387
2388 T.start;
2389 alt {
2390 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2391 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
2392 }
2393 [] BSSAP.receive { repeat; }
2394 [] IPA_RSL[0].receive { repeat; }
2395 [] T.timeout {}
2396 }
2397
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002398 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002399}
2400
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002401/* Verify DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
2402private function f_TC_tch_dlci_link_id_sapi(charstring id) runs on MSC_ConnHdlr {
2403 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2404 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2405
2406 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2407 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2408
2409 f_establish_fully(ass_cmd, exp_compl);
2410
2411 /* SAPI0 has already been established by f_establish_fully(), establish SAPI3 */
2412 RSL.send(ts_RSL_EST_IND(g_chan_nr, ts_RslLinkID_SACCH(3), '0904'O));
2413 /* Expect BSSAP/DTAP on SAPI3 (DLCI IE) */
2414 BSSAP.receive(PDU_BSSAP:{
2415 discriminator := '1'B,
2416 spare := '0000000'B,
2417 dlci := 'C3'O,
2418 lengthIndicator := ?,
2419 pdu := { dtap := '0904'O }
2420 });
2421
2422 /* Send messages on DCCH/SAPI0 and ACCH/SAPI3 */
2423 for (var integer i := 0; i < 32; i := i + 1) {
2424 var octetstring l3 := '09'O & f_rnd_octstring(14);
2425 var template (value) RslLinkId link_id;
2426 var template (value) OCT1 dlci;
2427
2428 if (i mod 2 == 0) {
2429 /* SAPI0 on FACCH or SDCCH */
2430 link_id := ts_RslLinkID_DCCH(0);
2431 dlci := '80'O;
2432 } else {
2433 /* SAPI3 on SACCH */
2434 link_id := ts_RslLinkID_SACCH(3);
2435 dlci := 'C3'O;
2436 }
2437
2438 /* Send MO message: RSL -> BSSAP */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002439 f_mo_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002440 /* Send MT message: BSSAP -> RSL */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002441 f_mt_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002442 }
2443}
2444testcase TC_tch_dlci_link_id_sapi() runs on test_CT {
2445 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2446 var MSC_ConnHdlr vc_conn;
2447
2448 f_init(1, true);
2449 f_sleep(1.0);
2450
2451 vc_conn := f_start_handler(refers(f_TC_tch_dlci_link_id_sapi), pars);
2452 vc_conn.done;
2453
2454 f_shutdown_helper();
2455}
2456
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002457private function f_exp_sapi_n_reject(template (present) GsmSapi sapi := ?,
2458 template myBSSMAP_Cause cause := ?,
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002459 template (present) BIT2 cc := ?,
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002460 float T_val := 2.0)
2461runs on test_CT {
2462 var BSSAP_N_DATA_ind rx_di;
2463 timer T;
2464
2465 var template BSSMAP_IE_Cause tr_cause := tr_BSSMAP_IE_Cause(cause);
2466 var template PDU_BSSAP tr_pdu := tr_BSSMAP_SAPInReject(sapi);
2467
2468 T.start(T_val);
2469 alt {
2470 [] BSSAP.receive(tr_BSSAP_DATA_ind(?, tr_pdu)) -> value rx_di {
2471 var BSSMAP_IE_Cause rx_cause := rx_di.userData.pdu.bssmap.sAPInReject.cause;
2472 if (not match(rx_cause, tr_cause)) {
2473 setverdict(fail, "Rx unexpected Cause IE: ",
2474 rx_cause, " vs expected ", tr_cause);
2475 }
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002476
2477 /* Who ever on the earth decided to define this field as two separate bits?!? */
2478 var BIT2 rx_cc := rx_di.userData.pdu.bssmap.sAPInReject.dLCI.c2
2479 & rx_di.userData.pdu.bssmap.sAPInReject.dLCI.c1;
2480 if (not match(rx_cc, cc)) {
2481 setverdict(fail, "Rx unexpected Control Channel type: ",
2482 rx_cc, " vs expected ", cc);
2483 }
2484
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002485 setverdict(pass);
2486 }
2487 [] BSSAP.receive(BSSAP_N_DATA_ind:?) -> value rx_di {
2488 setverdict(fail, "Rx unexpected BSSAP PDU: ", rx_di);
2489 }
2490 [] T.timeout {
2491 setverdict(fail, "Timeout waiting for BSSMAP SAPI N Reject");
2492 }
2493 }
2494}
2495
2496/* Check if we get SAPI N Reject on receipt of unexpected RLL RELease INDication */
2497testcase TC_rll_rel_ind_sapi_n_reject() runs on test_CT {
2498 var octetstring rnd_data := f_rnd_octstring(16);
2499 var RSL_Message rx_rsl;
2500 var DchanTuple dt;
2501
2502 f_init(1);
2503
2504 /* MS establishes a SAPI=0 link on DCCH */
2505 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2506
2507 /* MSC sends some data on (not yet established) SAPI=3 link */
2508 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2509 /* BSC attempts to establish a SAPI=3 link on DCCH */
2510 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2511
2512 /* MS sends unexpected RELease INDication on SAPI=3 */
2513 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3)));
2514 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2515 f_exp_sapi_n_reject(3, GSM0808_CAUSE_MS_NOT_EQUIPPED);
2516
2517 /* Clean up the connection */
2518 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2519 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2520
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002521 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002522}
2523
2524/* Check if we get SAPI N Reject on receipt of unexpected RLL ERROR INDication */
2525testcase TC_rll_err_ind_sapi_n_reject() runs on test_CT {
2526 var octetstring rnd_data := f_rnd_octstring(16);
2527 var RSL_Message rx_rsl;
2528 var DchanTuple dt;
2529
2530 f_init(1);
2531
2532 /* MS establishes a SAPI=0 link on DCCH */
2533 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2534
2535 /* MSC sends some data on (not yet established) SAPI=3 link */
2536 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2537 /* BSC attempts to establish a SAPI=3 link on DCCH */
2538 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2539
2540 /* BTS sends unexpected ERROR INDication on SAPI=3 */
2541 f_ipa_tx(0, ts_RSL_ERROR_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3), ''O));
2542 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2543 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED);
2544
2545 /* Clean up the connection */
2546 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2547 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2548
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002549 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002550}
2551
2552/* Check if we get SAPI N Reject due to a SAPI=3 link establishment timeout */
2553testcase TC_rll_timeout_sapi_n_reject() runs on test_CT {
2554 var octetstring rnd_data := f_rnd_octstring(16);
2555 var RSL_Message rx_rsl;
2556 var DchanTuple dt;
2557
2558 f_init(1);
2559
2560 /* MS establishes a SAPI=0 link on DCCH */
2561 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2562
2563 /* MSC sends some data on (not yet established) SAPI=3 link */
2564 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2565 /* BSC attempts to establish a SAPI=3 link on DCCH */
2566 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2567
2568 /* MS does not respond, so the link establishment timeout triggers SAPI N Reject */
2569 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED, T_val := 8.0);
2570
2571 /* Clean up the connection */
2572 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2573 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2574
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002575 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002576}
2577
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002578/* Check DLCI CC (Control Channel type) bits in SAPI N Reject */
2579testcase TC_rll_sapi_n_reject_dlci_cc() runs on test_CT {
2580 var octetstring rnd_data := f_rnd_octstring(16);
2581 var RSL_Message rx_rsl;
2582 var DchanTuple dt;
2583
2584 f_init(1);
2585
2586 /* MS establishes a SAPI=0 link on DCCH */
2587 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2588
2589 /* MSC sends some data on (not yet established) SAPI=3 link */
2590 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2591 /* BSC attempts to establish a SAPI=3 link on DCCH */
2592 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2593
2594 /* MS sends unexpected ERROR INDication on DCCH/ACCH SAPI=3 */
2595 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 +01002596 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED, '10'B);
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002597
2598 /* Clean up the connection */
2599 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2600 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2601
2602 f_shutdown_helper();
2603}
2604
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002605testcase TC_si_default() runs on test_CT {
2606 f_init(0);
2607 f_init_bts_and_check_sysinfo(0, expect_si := SystemInformationConfig_default);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002608 f_shutdown_helper();
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002609}
Harald Welte4003d112017-12-09 22:35:39 +01002610
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002611/* We're testing SI2quater with lists of EARFCNs. Instead of just incrementing EARFCNs, also pick some from the edges of
2612 * the entire value range. This function provides the same EARFCN numbers for the same earfcn_index */
2613private function f_test_si2quater_earfcn_by_idx(integer earfcn_index) return uint16_t
2614{
2615 select (earfcn_index) {
2616 case (0) {
2617 /* E-ARFCN 111 is already added in the osmo-bsc.cfg */
2618 return 111;
2619 }
2620 case (1) {
2621 return 1;
2622 }
2623 case (2) {
2624 return 0;
2625 }
2626 case (3) {
2627 return 65535;
2628 }
2629 case else {
2630 return 23 * (earfcn_index - 3);
2631 }
2632 }
2633}
2634
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002635function f_test_si2quater(integer total_earfcns, template SystemInformationConfig expect_si,
2636 template CellSelIndValue expect_cells := omit) runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002637
2638 f_init(0);
2639
2640 /* E-ARFCN 111 is already added in the osmo-bsc.cfg, so only add more arfcns if total_earfcns > 1 */
2641 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002642 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2643 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002644 }
2645
2646 f_init_bts_and_check_sysinfo(0, expect_si := expect_si);
2647
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002648 if (not istemplatekind(expect_cells, "omit")) {
2649 /* Also check that RR Channel Release contains these EARFCNs.
2650 * (copied code from TC_chan_rel_hard_clear_csfb) */
2651 var BSSAP_N_DATA_ind rx_di;
2652 var DchanTuple dt;
2653
2654 dt := f_est_dchan('23'O, 23, '00010203040506'O);
Pau Espin Pedrold0046312021-04-19 16:35:58 +02002655 /* Send CommonID with some random PLMN (BSC doesn't take it into account
2656 * yet when generating the EUTRAN neigh list in RR CHannel Release) */
2657 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002658
2659 /* Instruct BSC to clear channel */
2660 var BssmapCause cause := 0;
2661 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2662
2663 /* expect Clear Complete from BSC on A */
2664 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2665 /* release the SCCP connection */
2666 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2667 }
2668
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002669 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 +02002670 }
2671
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002672 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002673 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 +02002674 }
2675}
2676
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002677private function f_tr_si2quater_earfcns(integer count) return template SI2quaterRestOctetsList
2678{
2679 var template SI2quaterRestOctetsList si2quater := {};
2680 var integer si2quater_count := (count + 2) / 3;
2681
2682 for (var integer i := 0; i < count; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002683 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002684 var integer index := i / 3;
2685 var integer earfcn_index := i mod 3;
2686 if (index >= lengthof(si2quater)) {
2687 si2quater[index] := tr_SI2quaterRestOctets_EUTRAN(index := index, count := si2quater_count - 1);
2688 }
2689 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);
2690 }
2691
2692 return si2quater;
2693}
2694
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002695private function f_tr_rr_chan_rel_earfcns(integer count) return template CellSelIndValue
2696{
2697 var template CellSelIndValue_EUTRAN_Descrs cells := {};
2698
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002699 /* the lte neighbors must match the config & vty to pass this test */
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002700 for (var integer i := 0; i < count; i := i + 1) {
2701 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002702 cells[i] := tr_CellSelIndValue_EUTRAN_Descr(earfcn, '1'B, 3);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002703 }
2704
2705 return tr_CellSelIndValue_EUTRAN(cells);
2706}
2707
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002708private function f_tc_si2quater_n_earfcns(integer n) runs on test_CT
2709{
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002710 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrol8ab62e42020-12-18 16:19:11 +01002711 sic.si2quater := f_tr_si2quater_earfcns(n);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002712 var template CellSelIndValue cells := f_tr_rr_chan_rel_earfcns(n);
2713 f_test_si2quater(n, sic, cells);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002714}
2715
2716testcase TC_si2quater_2_earfcns() runs on test_CT {
2717 f_tc_si2quater_n_earfcns(2);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002718 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002719}
2720
2721testcase TC_si2quater_3_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002722 f_tc_si2quater_n_earfcns(3);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002723 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002724}
2725
2726testcase TC_si2quater_4_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002727 f_tc_si2quater_n_earfcns(4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002728 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002729}
2730
2731testcase TC_si2quater_5_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002732 f_tc_si2quater_n_earfcns(5);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002733 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002734}
2735
2736testcase TC_si2quater_6_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002737 f_tc_si2quater_n_earfcns(6);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002738 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002739}
2740
2741testcase TC_si2quater_12_earfcns() runs on test_CT {
2742 f_tc_si2quater_n_earfcns(12);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002743 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002744}
2745
2746testcase TC_si2quater_23_earfcns() runs on test_CT {
2747 f_tc_si2quater_n_earfcns(23);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002748 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002749}
2750
2751testcase TC_si2quater_32_earfcns() runs on test_CT {
2752 f_tc_si2quater_n_earfcns(32);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002753 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002754}
2755
2756testcase TC_si2quater_33_earfcns() runs on test_CT {
2757 f_tc_si2quater_n_earfcns(33);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002758 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002759}
2760
2761testcase TC_si2quater_42_earfcns() runs on test_CT {
2762 f_tc_si2quater_n_earfcns(42);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002763 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002764}
2765
2766testcase TC_si2quater_48_earfcns() runs on test_CT {
2767 f_tc_si2quater_n_earfcns(48);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002768 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002769}
2770
2771/* verify the VTY error response when adding too many EARFCNs, and showing that osmo-bsc still sends 16 SI2quater with
2772 * 48 EARFCNs. */
2773testcase TC_si2quater_49_earfcns() runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002774 var template SystemInformationConfig sic := SystemInformationConfig_default;
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002775 sic.si2quater := f_tr_si2quater_earfcns(48); /* 48, not 49! */
2776 f_init(0);
2777
2778 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002779 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2780 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002781 }
2782
2783 /* The 49th EARFCN no longer fits, expect VTY error */
2784 f_vty_enter_cfg_bts(BSCVTY, 0);
2785 var charstring vty_error;
2786 vty_error := f_vty_transceive_ret(BSCVTY,
2787 "si2quater neighbor-list add earfcn 70 thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3")
2788 f_vty_transceive(BSCVTY, "end");
2789
2790 if (f_strstr(vty_error, "Unable to add ARFCN 70") >= 0) {
2791 log("Got expected VTY error: ", vty_error);
2792 setverdict(pass);
2793 } else {
2794 setverdict(fail, "Expected the 49th EUTRAN ARFCN to be rejected by vty config, got: ", vty_error);
2795 }
2796
2797 f_init_bts_and_check_sysinfo(0, expect_si := sic);
2798
2799 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002800 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 +02002801 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002802 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002803}
2804
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002805private function f_acc09_count_allowed(AccessControlClass acc) return uint8_t
2806{
2807 var uint8_t count := 0;
2808 for (var integer i := 5; i < 16; i := i + 1) {
2809 if (acc[i] == '0'B) { /* the list marks barred, we count allowed */
2810 count := count + 1;
2811 }
2812 }
2813 return count;
2814}
2815
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002816private function f_recv_next_si1(integer rsl_idx := 0) runs on test_CT return SystemInformationType1
2817{
2818 var ASP_RSL_Unitdata rx_rsl_ud;
2819 var SystemInformationType1 last_si1;
2820
2821 timer T := 30.0;
2822 T.start;
2823 alt {
2824 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD((tr_RSL_NO_BCCH_INFO,
2825 tr_RSL_BCCH_INFO,
2826 tr_RSL_NO_SACCH_FILL,
2827 tr_RSL_SACCH_FILL))
2828 ) -> value rx_rsl_ud {
2829 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
2830 if (g_system_information[rsl_idx].si1 == omit) {
2831 repeat;
2832 }
2833 last_si1 := g_system_information[rsl_idx].si1;
2834 g_system_information[rsl_idx].si1 := omit;
2835 T.stop;
2836 }
Vadim Yanitskiy79ebd5e2021-01-04 00:12:55 +01002837 [] IPA_RSL[rsl_idx].receive { repeat; }
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002838 [] T.timeout { setverdict(fail, "Timeout receiving next SI1"); }
2839 }
2840 return last_si1;
2841}
2842
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002843/* verify ACC rotate feature */
2844testcase TC_si_acc_rotate() runs on test_CT {
2845 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002846 var SystemInformationType1 last_si1;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002847 var AccessControlClass acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002848 var uint8_t count;
2849 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2850
2851 f_init(0, guard_timeout := 60.0);
2852
2853 f_bts_0_cfg(BSCVTY, {"rach access-control-class 5 barred",
2854 "access-control-class-rotate 3",
2855 "access-control-class-rotate-quantum 1"});
2856
2857 /* Init and get first sysinfo */
2858 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2859
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002860 for (var integer i:= 0; i < 20; i := i + 1) {
2861 last_si1 := f_recv_next_si1(0);
2862 acc := last_si1.rach_control.acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002863 count := f_acc09_count_allowed(acc);
2864 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2865
2866 if (count != 3) {
2867 log("RSL: EXPECTED SI ACC len=3");
2868 setverdict(fail, "received SI does not match expectations");
2869 break;
2870 }
2871
2872 for (var integer j := 0; j < 10; j := j + 1) {
2873 if (acc[16 - 1 - j] == '0'B) { /* the list marks barred, we count allowed */
2874 times_allowed[j] := times_allowed[j] + 1;
2875 }
2876 }
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002877 }
2878
2879 for (var integer j := 0; j < 10; j := j + 1) {
2880 log("ACC", j, " allowed ", times_allowed[j], " times" );
2881 if (j != 5 and times_allowed[j] < 3) {
2882 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " < 1 times");
2883 } else if (j == 5 and times_allowed[j] > 0) {
2884 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " > 0 times");
2885 }
2886 }
2887
2888 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2889 "rach access-control-class 5 allowed"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002890 f_shutdown_helper();
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002891}
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002892
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002893/* verify ACC startup ramp+rotate feature */
2894testcase TC_si_acc_ramp_rotate() runs on test_CT {
2895 var template SystemInformationConfig sic := SystemInformationConfig_default;
2896 var SystemInformationType1 last_si1;
2897 var AccessControlClass acc;
2898 var ASP_RSL_Unitdata rx_rsl_ud;
2899 var uint8_t count;
2900 var uint8_t prev_count;
2901 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2902
2903 f_init(0, guard_timeout := 80.0);
2904
2905 f_bts_0_cfg(BSCVTY, {"rach access-control-class 4 barred",
2906 "access-control-class-rotate 0",
2907 "access-control-class-rotate-quantum 1",
2908 "access-control-class-ramping",
2909 "access-control-class-ramping-step-interval 5",
2910 "access-control-class-ramping-step-size 5"});
2911
2912 /* Init and get first sysinfo */
2913 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2914 last_si1 := g_system_information[0].si1;
2915 acc := last_si1.rach_control.acc;
2916 count := f_acc09_count_allowed(acc);
2917 /* Adm subset size was set to 0 above, so wait until all ACC are barred */
2918 while (count > 0) {
2919 last_si1 := f_recv_next_si1(0);
2920 acc := last_si1.rach_control.acc;
2921 count := f_acc09_count_allowed(acc);
2922 log("RSL: wait len()=0: GOT SI1 ACC len=", count, ": ", acc);
2923 }
2924
2925 /* Increase adm subset size, we should see ramping start up */
2926 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10"});
2927 prev_count := 0;
2928 while (true) {
2929 last_si1 := f_recv_next_si1(0);
2930 acc := last_si1.rach_control.acc;
2931 count := f_acc09_count_allowed(acc);
2932 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2933
2934 if (prev_count > count) {
2935 setverdict(fail, "ACC allowed count dropped while expecting grow: ", prev_count, " -> ", count);
2936 break;
2937 }
2938
2939 if (count == 9) {
2940 break; /* Maximum reached (10 - 1 perm barred), done here */
2941 }
2942
2943 prev_count := count;
2944 }
2945
2946 setverdict(pass);
2947
2948 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2949 "rach access-control-class 4 allowed",
2950 "no access-control-class-ramping"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002951 f_shutdown_helper();
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002952}
2953
Harald Welte4003d112017-12-09 22:35:39 +01002954testcase TC_ctrl_msc_connection_status() runs on test_CT {
2955 var charstring ctrl_resp;
2956
Harald Welte89d42e82017-12-17 16:42:41 +01002957 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002958
2959 /* See https://osmocom.org/issues/2729 */
2960 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002961 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002962}
2963
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002964testcase TC_ctrl_msc0_connection_status() runs on test_CT {
2965 var charstring ctrl_resp;
2966
2967 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002968
2969 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002970 f_shutdown_helper();
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002971}
2972
Neels Hofmeyr0bc470d2021-08-21 13:37:13 +02002973/* Verify correct stats on the number of configured and connected MSCs */
2974private function f_tc_stat_num_msc_connected_msc_connhdlr(integer expect_num_msc_connected) runs on MSC_ConnHdlr {
2975 g_pars := f_gen_test_hdlr_pars();
2976 var StatsDExpects expect := {
2977 { name := "TTCN3.bsc.0.num_msc.connected", mtype := "g", min := expect_num_msc_connected, max := expect_num_msc_connected },
2978 { name := "TTCN3.bsc.0.num_msc.total", mtype := "g", min := NUM_MSC, max := NUM_MSC }
2979 };
2980 f_statsd_expect(expect);
2981}
2982
2983private function f_tc_stat_num_msc_connected_test_ct(void_fn tc_fn, integer nr_msc) runs on test_CT
2984{
2985 var MSC_ConnHdlr vc_conn;
2986
2987 f_init(nr_bts := 1, handler_mode := true, nr_msc := nr_msc);
2988 f_sleep(1.0);
2989 vc_conn := f_start_handler(tc_fn);
2990 vc_conn.done;
2991
2992 /* Also verify stat exposed on CTRL interface */
2993 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_msc:connected", int2str(nr_msc));
2994 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_msc:total", int2str(NUM_MSC));
2995
2996 f_shutdown_helper();
2997}
2998
2999/* Verify that when 1 MSC is active, that num_msc:connected reports 1. */
3000private function f_tc_stat_num_msc_connected_1(charstring id) runs on MSC_ConnHdlr {
3001 f_tc_stat_num_msc_connected_msc_connhdlr(1);
3002}
3003testcase TC_stat_num_msc_connected_1() runs on test_CT {
3004 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_1), 1);
3005}
3006
3007/* Verify that when 2 MSCs are active, that num_msc:connected reports 2. */
3008private function f_tc_stat_num_msc_connected_2(charstring id) runs on MSC_ConnHdlr {
3009 f_tc_stat_num_msc_connected_msc_connhdlr(2);
3010}
3011testcase TC_stat_num_msc_connected_2() runs on test_CT {
3012 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_2), 2);
3013}
3014
3015/* Verify that when 3 MSCs are active, that num_msc:connected reports 3. */
3016private function f_tc_stat_num_msc_connected_3(charstring id) runs on MSC_ConnHdlr {
3017 f_tc_stat_num_msc_connected_msc_connhdlr(3);
3018}
3019testcase TC_stat_num_msc_connected_3() runs on test_CT {
3020 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_3), 3);
3021}
3022
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +02003023/* Verify correct stats on the number of configured and connected MSCs */
3024private function f_tc_stat_num_bts_connected_msc_connhdlr(integer expect_num_bts_connected) runs on MSC_ConnHdlr {
3025 g_pars := f_gen_test_hdlr_pars();
3026 var StatsDExpects expect := {
3027 { name := "TTCN3.bsc.0.num_bts.oml_connected", mtype := "g", min := expect_num_bts_connected, max := NUM_BTS_CFG },
3028 { name := "TTCN3.bsc.0.num_bts.all_trx_rsl_connected", mtype := "g", min := expect_num_bts_connected, max := expect_num_bts_connected },
3029 { name := "TTCN3.bsc.0.num_bts.total", mtype := "g", min := NUM_BTS_CFG, max := NUM_BTS_CFG },
3030 { name := "TTCN3.bsc.0.num_trx.rsl_connected", mtype := "g", min := expect_num_bts_connected, max := expect_num_bts_connected },
3031 { name := "TTCN3.bsc.0.num_trx.total", mtype := "g", min := NUM_BTS_CFG, max := NUM_BTS_CFG }
3032 };
3033 f_statsd_expect(expect);
3034}
3035
3036private function f_tc_stat_num_bts_connected_test_ct(void_fn tc_fn, integer nr_bts) runs on test_CT {
3037 var MSC_ConnHdlr vc_conn;
3038
3039 f_init(nr_bts := nr_bts, handler_mode := true, nr_msc := 1);
3040 f_sleep(1.0);
3041 vc_conn := f_start_handler(tc_fn);
3042 vc_conn.done;
3043
3044 /* Also verify stat exposed on CTRL interface */
3045 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_bts:all_trx_rsl_connected", int2str(nr_bts));
3046 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_bts:total", int2str(NUM_BTS_CFG));
3047 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_trx:rsl_connected", int2str(nr_bts));
3048 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_trx:total", int2str(NUM_BTS_CFG));
3049
Neels Hofmeyra41ae302021-09-06 22:06:02 +02003050 /* Verify rf_states exposed on CTRL interface */
3051 var charstring expect_net_rf_states := "";
3052 for (var integer i := 0; i < NUM_BTS_CFG; i := i + 1) {
3053 var charstring expect_bts_rf_states := int2str(i) & ",0,";
3054 if (i < NUM_BTS) {
3055 /* In these tests, OML for the first NUM_BTS are always connected via osmo-bts-omldummy */
3056 expect_bts_rf_states := expect_bts_rf_states & "operational,unlocked,";
3057 } else {
3058 /* For remaining i < NUM_BTS_CFG, OML is not connected, i.e. inoperational */
3059 expect_bts_rf_states := expect_bts_rf_states & "inoperational,locked,";
3060 }
3061 /* The RF policy is still global in osmo-bsc, i.e. always "on" */
3062 expect_bts_rf_states := expect_bts_rf_states & "on,";
3063 if (i < nr_bts) {
3064 /* For BTS where RSL is connected, the RSL state will be "up" */
3065 expect_bts_rf_states := expect_bts_rf_states & "rsl-up;";
3066 } else {
3067 expect_bts_rf_states := expect_bts_rf_states & "rsl-down;";
3068 }
3069
3070 f_ctrl_get_exp(IPA_CTRL, "bts." & int2str(i) & ".rf_states", expect_bts_rf_states);
3071 expect_net_rf_states := expect_net_rf_states & expect_bts_rf_states;
3072 }
3073 f_ctrl_get_exp(IPA_CTRL, "rf_states", expect_net_rf_states);
3074
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +02003075 f_shutdown_helper();
3076}
3077
3078/* Verify that when 1 BTS is connected, that num_{bts,trx}:*_connected reports 1. */
3079private function f_tc_stat_num_bts_connected_1(charstring id) runs on MSC_ConnHdlr {
3080 f_tc_stat_num_bts_connected_msc_connhdlr(1);
3081}
3082testcase TC_stat_num_bts_connected_1() runs on test_CT {
3083 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_1), 1);
3084}
3085
3086/* Verify that when 2 BTS is connected, that num_{bts,trx}:*_connected reports 2. */
3087private function f_tc_stat_num_bts_connected_2(charstring id) runs on MSC_ConnHdlr {
3088 f_tc_stat_num_bts_connected_msc_connhdlr(2);
3089}
3090testcase TC_stat_num_bts_connected_2() runs on test_CT {
3091 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_2), 2);
3092}
3093
3094/* Verify that when 3 BTS is connected, that num_{bts,trx}:*_connected reports 3. */
3095private function f_tc_stat_num_bts_connected_3(charstring id) runs on MSC_ConnHdlr {
3096 f_tc_stat_num_bts_connected_msc_connhdlr(3);
3097}
3098testcase TC_stat_num_bts_connected_3() runs on test_CT {
3099 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_3), 3);
3100}
3101
Harald Welte4003d112017-12-09 22:35:39 +01003102testcase TC_ctrl() runs on test_CT {
3103 var charstring ctrl_resp;
3104
Harald Welte89d42e82017-12-17 16:42:41 +01003105 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01003106
3107 /* all below values must match the osmo-bsc.cfg config file used */
3108
Harald Welte6a129692018-03-17 17:30:14 +01003109 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
3110 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Oliver Smith75aa0202019-08-19 14:17:50 +02003111 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "4");
Harald Welte4003d112017-12-09 22:35:39 +01003112
3113 var integer bts_nr := 0;
3114 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
3115 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
3116 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
3117 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
3118 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
3119 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
3120 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
3121
3122 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
3123 f_sleep(2.0);
3124 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
3125 setverdict(fail, "oml-uptime not incrementing as expected");
3126 }
3127 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
3128
3129 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
3130
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003131 f_shutdown_helper();
Harald Welte96c94412017-12-09 03:12:45 +01003132}
3133
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02003134/* Verify that Upon receival of SET "location", BSC forwards a TRAP
3135 "location-state" over the SCCPlite IPA conn */
3136testcase TC_ctrl_location() runs on test_CT {
3137 var MSC_ConnHdlr vc_conn;
3138 var integer bts_nr := 0;
3139
3140 f_init(1, true);
3141 f_sleep(1.0);
3142
3143 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234567,fix3d,0.340000,0.560000,0.780000");
3144 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
3145 "1234567,fix3d,0.340000,0.560000,0.780000,operational,unlocked,on,001,01");
3146
3147 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "1");
3148 f_sleep(2.0);
3149
3150 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234888,fix3d,0.350000,0.570000,0.790000");
3151 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
3152 "1234888,fix3d,0.350000,0.570000,0.790000,operational,locked,off,001,01");
3153
3154 /* should match the one from config */
3155 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "0");
3156
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003157 f_shutdown_helper();
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02003158}
3159
Harald Welte6f521d82017-12-11 19:52:02 +01003160
3161/***********************************************************************
3162 * Paging Testing
3163 ***********************************************************************/
3164
3165type record Cell_Identity {
3166 GsmMcc mcc,
3167 GsmMnc mnc,
3168 GsmLac lac,
3169 GsmCellId ci
3170};
Harald Welte24135bd2018-03-17 19:27:53 +01003171private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01003172private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01003173
Harald Welte5d1a2202017-12-13 19:51:29 +01003174type set of integer BtsIdList;
3175
3176private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
3177 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
3178 if (bts_id == bts_ids[j]) {
3179 return true;
3180 }
3181 }
3182 return false;
3183}
Harald Welte6f521d82017-12-11 19:52:02 +01003184
3185/* core paging test helper function; used by most paging test cases */
3186private function f_pageing_helper(hexstring imsi,
3187 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01003188 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01003189 template RSL_ChanNeeded rsl_chneed := omit,
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003190 template (omit) OCT4 tmsi := omit) runs on test_CT
Harald Welte6f521d82017-12-11 19:52:02 +01003191{
3192 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003193 var template MobileIdentityV mi;
Harald Welte6f521d82017-12-11 19:52:02 +01003194 var RSL_Message rx_rsl;
3195 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01003196 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01003197
3198 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01003199
3200 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01003201 for (i := 0; i < NUM_BTS; i := i + 1) {
3202 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01003203 }
Harald Welte6f521d82017-12-11 19:52:02 +01003204
3205 if (isvalue(rsl_chneed)) {
3206 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
3207 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
3208 } else {
3209 bssmap_chneed := omit;
3210 }
3211
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003212 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[0].sccp_addr_peer, g_bssap[0].sccp_addr_own,
3213 ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed)));
Harald Welte6f521d82017-12-11 19:52:02 +01003214
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003215 if (not istemplatekind(tmsi, "omit")) {
3216 mi := t_MI_TMSI(tmsi);
Harald Welte6f521d82017-12-11 19:52:02 +01003217 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003218 mi := tr_MI_IMSI(imsi);
Harald Welte6f521d82017-12-11 19:52:02 +01003219 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003220
Harald Welte5d1a2202017-12-13 19:51:29 +01003221 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003222 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(mi));
Harald Welte5d1a2202017-12-13 19:51:29 +01003223 /* check channel type, paging group */
3224 if (rx_rsl.ies[1].body.paging_group != paging_group) {
3225 setverdict(fail, "Paging for wrong paging group");
3226 }
3227 if (ispresent(rsl_chneed) and
3228 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
3229 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
3230 }
Harald Welte6f521d82017-12-11 19:52:02 +01003231 }
Harald Welte2fccd982018-01-31 15:48:19 +01003232 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01003233 /* do a quick check on all not-included BTSs if they received paging */
3234 for (i := 0; i < NUM_BTS; i := i + 1) {
3235 timer T := 0.1;
3236 if (f_bts_in_list(i, bts_ids)) {
3237 continue;
3238 }
3239 T.start;
3240 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003241 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(mi))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003242 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
3243 }
3244 [] IPA_RSL[i].receive { repeat; }
3245 [] T.timeout { }
3246 }
Harald Welte6f521d82017-12-11 19:52:02 +01003247 }
3248
3249 setverdict(pass);
3250}
3251
Harald Welte5d1a2202017-12-13 19:51:29 +01003252const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01003253const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01003254const BtsIdList c_BtsId_LAC1 := { 0, 1 };
3255const BtsIdList c_BtsId_LAC2 := { 2 };
3256
Harald Welte6f521d82017-12-11 19:52:02 +01003257/* PAGING by IMSI + TMSI */
3258testcase TC_paging_imsi_nochan() runs on test_CT {
3259 var BSSMAP_FIELD_CellIdentificationList cid_list;
3260 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01003261 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003262 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003263}
3264
3265/* PAGING by IMSI + TMSI */
3266testcase TC_paging_tmsi_nochan() runs on test_CT {
3267 var BSSMAP_FIELD_CellIdentificationList cid_list;
3268 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003269 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003270 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003271}
3272
3273/* Paging with different "channel needed' values */
3274testcase TC_paging_tmsi_any() runs on test_CT {
3275 var BSSMAP_FIELD_CellIdentificationList cid_list;
3276 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003277 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003278 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003279}
3280testcase TC_paging_tmsi_sdcch() runs on test_CT {
3281 var BSSMAP_FIELD_CellIdentificationList cid_list;
3282 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003283 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003284 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003285}
3286testcase TC_paging_tmsi_tch_f() 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('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003290 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003291}
3292testcase TC_paging_tmsi_tch_hf() runs on test_CT {
3293 var BSSMAP_FIELD_CellIdentificationList cid_list;
3294 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003295 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003296 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003297}
3298
3299/* Paging by CGI */
3300testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
3301 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3302 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003303 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003304 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003305}
3306
3307/* Paging by LAC+CI */
3308testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
3309 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3310 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003311 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003312 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003313}
3314
3315/* Paging by CI */
3316testcase TC_paging_imsi_nochan_ci() runs on test_CT {
3317 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3318 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003319 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003320 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003321}
3322
3323/* Paging by LAI */
3324testcase TC_paging_imsi_nochan_lai() runs on test_CT {
3325 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3326 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003327 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003328 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003329}
3330
3331/* Paging by LAC */
3332testcase TC_paging_imsi_nochan_lac() runs on test_CT {
3333 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3334 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003335 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003336 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003337}
3338
3339/* Paging by "all in BSS" */
3340testcase TC_paging_imsi_nochan_all() runs on test_CT {
3341 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3342 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01003343 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003344 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003345}
3346
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003347/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003348testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
3349 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3350 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 +01003351 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003352 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003353}
Harald Welte6f521d82017-12-11 19:52:02 +01003354
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003355/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003356testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
3357 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3358 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003359 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003360 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003361}
3362
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003363/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003364testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
3365 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3366 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003367 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003368 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003369}
3370
Harald Welte6f521d82017-12-11 19:52:02 +01003371/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01003372testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
3373 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3374 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
3375 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003376 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003377}
3378
3379/* Paging on empty list: Verify none of them page */
3380testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
3381 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3382 cid_list := { cIl_LAC := { } };
3383 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003384 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003385}
3386
Stefan Sperling049a86e2018-03-20 15:51:00 +01003387/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
3388testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
3389 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3390 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
3391 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
3392 f_shutdown_helper();
3393}
3394
Harald Welte6f521d82017-12-11 19:52:02 +01003395/* Verify paging retransmission interval + count */
3396/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01003397/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01003398
Harald Weltee65d40e2017-12-13 00:09:06 +01003399/* Verify PCH load */
3400testcase TC_paging_imsi_load() runs on test_CT {
3401 var BSSMAP_FIELD_CellIdentificationList cid_list;
3402 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01003403 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01003404 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003405 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01003406
3407 /* tell BSC there is no paging space anymore */
3408 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01003409 f_sleep(0.2);
3410 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01003411
3412 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
3413 * there would be 8 retransmissions during 4 seconds */
3414 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01003415 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01003416 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003417 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Weltee65d40e2017-12-13 00:09:06 +01003418 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02003419 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01003420 }
Harald Welte2caa1062018-03-17 18:19:05 +01003421 [] T_retrans.timeout {
3422 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
3423 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
3424 T_retrans.start;
3425 repeat;
3426 }
Harald Weltee65d40e2017-12-13 00:09:06 +01003427 [] T.timeout {
3428 setverdict(pass);
3429 }
3430 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003431
3432 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01003433}
3434
Harald Welte235ebf12017-12-15 14:18:16 +01003435/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01003436testcase TC_paging_counter() runs on test_CT {
3437 var BSSMAP_FIELD_CellIdentificationList cid_list;
3438 timer T := 4.0;
3439 var integer i;
3440 var integer paging_attempted_bsc;
3441 var integer paging_attempted_bts[NUM_BTS];
Oliver Smith8b343d32021-11-26 13:01:42 +01003442 var integer paging_expired_bsc;
Harald Welte1ff69992017-12-14 12:31:17 +01003443 var integer paging_expired_bts[NUM_BTS];
3444 cid_list := valueof(ts_BSSMAP_CIL_noCell);
3445
3446 f_init();
3447
3448 /* read counters before paging */
3449 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
Oliver Smith8b343d32021-11-26 13:01:42 +01003450 if (Misc_Helpers.f_osmo_repo_is("nightly")) { /* osmo-bsc > 1.8.0 */
3451 paging_expired_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:expired");
3452 }
Harald Welte1ff69992017-12-14 12:31:17 +01003453 for (i := 0; i < NUM_BTS; i := i+1) {
3454 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
3455 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
3456 }
3457
3458 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
3459
3460 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
3461 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
3462 for (i := 0; i < NUM_BTS; i := i+1) {
3463 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
3464 paging_attempted_bts[i]+1);
3465 }
3466
3467 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
3468 f_sleep(12.0);
Oliver Smith8b343d32021-11-26 13:01:42 +01003469 if (Misc_Helpers.f_osmo_repo_is("nightly")) { /* osmo-bsc > 1.8.0 */
3470 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:expired", paging_expired_bsc+1);
3471 }
Harald Welte1ff69992017-12-14 12:31:17 +01003472 for (i := 0; i < NUM_BTS; i := i+1) {
3473 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
3474 paging_expired_bts[i]+1);
3475 }
Harald Welte1ff69992017-12-14 12:31:17 +01003476
Philipp Maier282ca4b2018-02-27 17:17:00 +01003477 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01003478}
3479
3480
Harald Welte10985002017-12-12 09:29:15 +01003481/* Verify paging stops after A-RESET */
3482testcase TC_paging_imsi_a_reset() runs on test_CT {
3483 var BSSMAP_FIELD_CellIdentificationList cid_list;
3484 timer T := 3.0;
3485 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003486 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01003487
3488 /* Perform a BSSMAP Reset and wait for ACK */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003489 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 +01003490 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003491 [] 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 +01003492 [] BSSAP.receive { repeat; }
3493 }
3494
Daniel Willmanncbef3982018-07-30 09:22:40 +02003495 /* Wait to avoid a possible race condition if a paging message is
3496 * received right before the reset ACK. */
3497 f_sleep(0.2);
3498
Harald Welte10985002017-12-12 09:29:15 +01003499 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01003500 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
3501 IPA_RSL[i].clear;
3502 }
Harald Welte10985002017-12-12 09:29:15 +01003503
3504 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
3505 T.start;
3506 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003507 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte10985002017-12-12 09:29:15 +01003508 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003509 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01003510 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003511 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003512 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003513 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003514 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003515 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003516 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003517 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003518 }
Harald Welte10985002017-12-12 09:29:15 +01003519 [] T.timeout {
3520 setverdict(pass);
3521 }
3522 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003523
3524 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01003525}
Harald Welteae026692017-12-09 01:03:01 +01003526
Philipp Maierf45824a2019-08-14 14:44:10 +02003527/* Verify how we handle unsolicited Paging Response. In case of an unsolicit
3528 * paging response we can not know which MSC is in charge, so we will blindly
3529 * pick the first configured MSC. This behavior is required in order to make
3530 * MT-CSFB calls working because in those cases the BSC can not know that the
3531 * MSC has already paged the subscriver via SGs. So any MT-CSFB call will look
3532 * like an unsolicited Paging Response to the MSC.
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003533 */
3534testcase TC_paging_resp_unsol() runs on test_CT {
3535
3536 f_init(1);
Philipp Maierf45824a2019-08-14 14:44:10 +02003537 timer T := 5.0;
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003538
3539 var BSSAP_N_CONNECT_ind rx_c_ind;
3540 var DchanTuple dt;
3541 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
Philipp Maierf45824a2019-08-14 14:44:10 +02003542 var octetstring rr_pag_resp := enc_PDU_ML3_MS_NW(l3);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003543
3544 /* Send CHAN RQD and wait for allocation; acknowledge it */
3545 dt.rsl_chan_nr := f_chreq_act_ack();
3546
3547 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
3548 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
3549
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003550
Philipp Maierf45824a2019-08-14 14:44:10 +02003551 /* Expevct a CR with a matching Paging response on the A-Interface */
3552 T.start;
3553 alt {
3554 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(rr_pag_resp))) {
3555 setverdict(pass);
3556 }
3557 [] BSSAP.receive {
3558 setverdict(fail, "Received unexpected message on A-Interface!");
3559 }
3560 [] T.timeout {
3561 setverdict(fail, "Received nothing on A-Interface!");
3562 }
3563 }
3564
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003565 f_shutdown_helper();
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003566}
3567
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003568/* Test RSL link drop causes counter increment */
3569testcase TC_rsl_drop_counter() runs on test_CT {
3570 var integer rsl_fail;
3571
Harald Welte89d42e82017-12-17 16:42:41 +01003572 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003573
3574 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
3575
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +01003576 f_ipa_rsl_stop(bts[0].rsl);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003577
3578 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
3579
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003580 f_shutdown_helper();
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003581}
3582
3583/* TODO: Test OML link drop causes counter increment */
3584
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003585/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
3586function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
3587 timer T := 10.0;
3588
3589 bts[0].rsl.id := "IPA-0-RSL";
Harald Welte71389132021-12-09 21:58:18 +01003590 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA") alive;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003591 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
3592 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
Oliver Smith92c2bdb2019-08-20 15:11:24 +02003593 bts[0].rsl.ccm_pars.unit_id := "99/0/0"; /* value which is unknown at BTS */
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003594
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01003595 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003596
3597 f_init_mgcp("VirtMSC");
3598
3599 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
3600 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
3601 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
3602 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
3603
3604 /* wait for IPA OML link to connect and then disconnect */
3605 T.start;
3606 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +07003607 [] IPA_RSL[0].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) {
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003608 T.stop;
3609 return true;
3610 }
3611 [] IPA_RSL[0].receive { repeat }
3612 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02003613 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003614 }
3615 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003616 return false;
3617}
3618
3619/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3620testcase TC_rsl_unknown_unit_id() runs on test_CT {
3621 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
3622 setverdict(pass);
3623 } else {
3624 setverdict(fail, "Timeout RSL waiting for connection to close");
3625 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003626 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003627}
3628
3629
3630/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3631testcase TC_oml_unknown_unit_id() runs on test_CT {
3632 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
3633 setverdict(pass);
3634 } else {
3635 setverdict(fail, "Timeout OML waiting for connection to close");
3636 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003637 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003638}
3639
3640
Harald Weltec1a2fff2017-12-17 11:06:19 +01003641/***********************************************************************
Harald Welte6811d102019-04-14 22:23:14 +02003642 * "New world" test cases using RSL_Emulation + RAN_Emulation
Harald Weltec1a2fff2017-12-17 11:06:19 +01003643 ***********************************************************************/
3644
Harald Welte6811d102019-04-14 22:23:14 +02003645import from RAN_Emulation all;
Harald Welte47cd0e32020-08-21 12:39:11 +02003646import from BSSAP_LE_Emulation all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01003647import from RSL_Emulation all;
3648import from MSC_ConnectionHandler all;
3649
3650type function void_fn(charstring id) runs on MSC_ConnHdlr;
3651
Harald Welte336820c2018-05-31 20:34:52 +02003652/* helper function to create and connect a MSC_ConnHdlr component */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003653private function f_connect_handler(inout MSC_ConnHdlr vc_conn, integer bssap_idx := 0) runs on test_CT {
3654 connect(vc_conn:RAN, g_bssap[bssap_idx].vc_RAN:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01003655 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003656 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01003657 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01003658 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01003659 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
3660 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
3661 }
Neels Hofmeyr91401012019-07-11 00:42:35 +02003662 if (isvalue(bts[2])) {
3663 connect(vc_conn:RSL2, bts[2].rsl.vc_RSL:CLIENT_PT);
3664 connect(vc_conn:RSL2_PROC, bts[2].rsl.vc_RSL:RSL_PROC);
3665 }
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003666 connect(vc_conn:BSSAP, g_bssap[bssap_idx].vc_RAN:CLIENT);
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02003667 if (mp_enable_lcs_tests) {
3668 connect(vc_conn:BSSAP_LE, g_bssap_le.vc_BSSAP_LE:CLIENT);
3669 connect(vc_conn:BSSAP_LE_PROC, g_bssap_le.vc_BSSAP_LE:PROC);
3670 }
Daniel Willmann191e0d92018-01-17 12:44:35 +01003671 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02003672 connect(vc_conn:MGCP_MULTI, vc_MGCP:MGCP_CLIENT_MULTI);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003673 connect(vc_conn:STATSD_PROC, vc_STATSD:STATSD_PROC);
Harald Welte336820c2018-05-31 20:34:52 +02003674}
3675
Neels Hofmeyrda436782021-07-20 22:09:06 +02003676function f_start_handler_create(template (omit) TestHdlrParams pars := omit)
Harald Welte336820c2018-05-31 20:34:52 +02003677runs on test_CT return MSC_ConnHdlr {
3678 var charstring id := testcasename();
3679 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003680 var integer bssap_idx := 0;
3681 if (isvalue(pars)) {
3682 bssap_idx := valueof(pars).mscpool.bssap_idx;
3683 }
Harald Welte336820c2018-05-31 20:34:52 +02003684 vc_conn := MSC_ConnHdlr.create(id);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003685 f_connect_handler(vc_conn, bssap_idx);
Neels Hofmeyrda436782021-07-20 22:09:06 +02003686 return vc_conn;
3687}
3688
3689function f_start_handler_run(MSC_ConnHdlr vc_conn, void_fn fn, template (omit) TestHdlrParams pars := omit)
3690runs on test_CT return MSC_ConnHdlr {
3691 var charstring id := testcasename();
Neels Hofmeyr1708d1b2020-10-10 16:56:48 +02003692 /* Emit a marker to appear in the SUT's own logging output */
Neels Hofmeyrda436782021-07-20 22:09:06 +02003693 f_logp(BSCVTY, id & "() start");
Harald Weltea0630032018-03-20 21:09:55 +01003694 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003695 return vc_conn;
3696}
3697
Neels Hofmeyrda436782021-07-20 22:09:06 +02003698function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
3699runs on test_CT return MSC_ConnHdlr {
3700 return f_start_handler_run(f_start_handler_create(pars), fn, pars);
3701}
3702
Harald Weltea0630032018-03-20 21:09:55 +01003703/* first function inside ConnHdlr component; sets g_pars + starts function */
3704private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
3705runs on MSC_ConnHdlr {
3706 if (isvalue(pars)) {
3707 g_pars := valueof(pars);
3708 }
3709 fn.apply(id);
3710}
3711
Oliver Smith26a3db72021-07-09 13:51:29 +02003712private function f_vty_encryption_a5(charstring options) runs on test_CT {
3713 f_vty_transceive(BSCVTY, "configure terminal");
3714 f_vty_transceive(BSCVTY, "network");
3715 f_vty_transceive(BSCVTY, "encryption a5 " & options);
3716 f_vty_transceive(BSCVTY, "exit");
3717 f_vty_transceive(BSCVTY, "exit");
3718}
3719
3720private function f_vty_encryption_a5_reset() runs on test_CT {
3721 /* keep in sync with docker-playground.git ttcn3-bsc-test/osmo-bsc.cfg */
3722 f_vty_encryption_a5("0 1 3");
3723}
3724
Harald Welte3c86ea02018-05-10 22:28:05 +02003725/* Establish signalling channel (non-assignment case) followed by cipher mode */
3726private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003727 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3728 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02003729 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02003730 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
3731 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
3732 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
3733 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02003734
Philipp Maier23000732018-05-18 11:25:37 +02003735 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02003736}
3737testcase TC_ciph_mode_a5_0() runs on test_CT {
3738 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003739 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003740 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
3741
3742 f_init(1, true);
3743 f_sleep(1.0);
3744 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3745 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003746 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003747}
3748testcase TC_ciph_mode_a5_1() runs on test_CT {
3749 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003750 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003751 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
3752
3753 f_init(1, true);
3754 f_sleep(1.0);
3755 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3756 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003757 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003758}
Oliver Smith50b98122021-07-09 15:00:28 +02003759/* OS#4975: verify that A5/2 is preferred over A5/0 */
3760testcase TC_ciph_mode_a5_2_0() runs on test_CT {
3761 var MSC_ConnHdlr vc_conn;
3762 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3763
3764 pars.encr := valueof(t_EncrParams('05'O, f_rnd_octstring(8))); /* A5/0 and A5/2 (0x01|0x04)*/
3765 pars.encr_exp_enc_alg := '04'O; /* A5/2 */
3766
3767 f_init(1, true);
3768 f_vty_encryption_a5("0 1 2 3");
3769 f_sleep(1.0);
3770 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3771 vc_conn.done;
3772 f_vty_encryption_a5_reset();
3773 f_shutdown_helper();
3774}
Oliver Smith1dff88d2021-07-09 08:45:51 +02003775/* OS#4975: verify that A5/1 is preferred over A5/2 */
3776testcase TC_ciph_mode_a5_2_1() runs on test_CT {
3777 var MSC_ConnHdlr vc_conn;
3778 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3779
3780 pars.encr := valueof(t_EncrParams('06'O, f_rnd_octstring(8))); /* A5/1 and A5/2 (0x02|0x04)*/
3781 pars.encr_exp_enc_alg := '02'O; /* A5/1 */
3782
3783 f_init(1, true);
3784 f_vty_encryption_a5("1 2");
3785 f_sleep(1.0);
3786 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3787 vc_conn.done;
3788 f_vty_encryption_a5_reset();
3789 f_shutdown_helper();
3790}
Harald Welte3c86ea02018-05-10 22:28:05 +02003791testcase TC_ciph_mode_a5_3() runs on test_CT {
3792 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003793 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003794 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
3795
3796 f_init(1, true);
3797 f_sleep(1.0);
3798 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3799 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003800 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003801}
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003802/* Establish a Signalling channel with A5/4 encryption. */
3803testcase TC_ciph_mode_a5_4() runs on test_CT {
3804 var MSC_ConnHdlr vc_conn;
3805 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3806 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Harald Welte3c86ea02018-05-10 22:28:05 +02003807
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003808 f_init(1, true);
Oliver Smith26a3db72021-07-09 13:51:29 +02003809 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003810 f_sleep(1.0);
3811 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3812 vc_conn.done;
Oliver Smith26a3db72021-07-09 13:51:29 +02003813 f_vty_encryption_a5_reset();
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003814 f_shutdown_helper();
3815}
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003816/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
3817private function f_tc_assignment_aoip_tla_v6(charstring id) runs on MSC_ConnHdlr {
3818 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3819 var PDU_BSSAP ass_cmd := f_gen_ass_req(aoip_tla := "::3");
3820 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3821 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3822
3823 f_establish_fully(ass_cmd, exp_compl);
3824}
3825testcase TC_assignment_aoip_tla_v6() runs on test_CT {
3826 var MSC_ConnHdlr vc_conn;
3827 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3828
3829 f_init(1, true);
3830 f_sleep(1.0);
3831 vc_conn := f_start_handler(refers(f_tc_assignment_aoip_tla_v6), pars);
3832 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003833 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003834}
3835
Harald Welte3c86ea02018-05-10 22:28:05 +02003836
3837/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02003838private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003839 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3840 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003841
Harald Welte552620d2017-12-16 23:21:36 +01003842 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3843 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01003844
Harald Weltea0630032018-03-20 21:09:55 +01003845 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01003846}
Harald Welte552620d2017-12-16 23:21:36 +01003847testcase TC_assignment_fr_a5_0() runs on test_CT {
3848 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003849 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003850 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01003851
Harald Welte89d42e82017-12-17 16:42:41 +01003852 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003853 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003854 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003855 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003856 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003857}
Harald Welte552620d2017-12-16 23:21:36 +01003858testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01003859 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003860 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003861 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003862
Harald Welte89d42e82017-12-17 16:42:41 +01003863 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003864 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003865 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3866 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003867 f_shutdown_helper();
Harald Welte651fcdc2018-05-10 20:23:16 +02003868}
3869testcase TC_assignment_fr_a5_3() 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('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003873
Harald Welte651fcdc2018-05-10 20:23:16 +02003874 f_init(1, true);
3875 f_sleep(1.0);
3876 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003877 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003878 f_shutdown_helper();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003879}
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003880/* Establish a Signalling channel and re-assign to TCH/F with A5/4 encryption. */
3881testcase TC_assignment_fr_a5_4() runs on test_CT {
3882 var MSC_ConnHdlr vc_conn;
3883 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3884 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
3885
3886 f_init(1, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02003887 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003888 f_sleep(1.0);
3889 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3890 vc_conn.done;
Oliver Smith7eabd312021-07-12 14:18:56 +02003891 f_vty_encryption_a5_reset();
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003892 f_shutdown_helper();
3893}
Harald Weltec1a2fff2017-12-17 11:06:19 +01003894
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +02003895/* Allow only A5/4, but omit the Kc128 IE from MSC's msg. Expect Cipher Mode Reject. */
3896testcase TC_assignment_fr_a5_4_fail() runs on test_CT {
3897 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3898 var MSC_ConnHdlr vc_conn;
3899
3900 f_init(1, true);
3901 f_sleep(1.0);
3902
3903 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8))); // A5/4 support, but Kc128 missing!
3904 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
3905 vc_conn.done;
3906 f_shutdown_helper();
3907}
3908
Harald Welte552620d2017-12-16 23:21:36 +01003909/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
3910private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003911 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01003912 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02003913 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003914
3915 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003916 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
3917
Harald Weltea0630032018-03-20 21:09:55 +01003918 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01003919}
Harald Welte552620d2017-12-16 23:21:36 +01003920testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
3921 var MSC_ConnHdlr vc_conn;
3922
Harald Welte89d42e82017-12-17 16:42:41 +01003923 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003924 f_sleep(1.0);
3925
Harald Welte8863fa12018-05-10 20:15:27 +02003926 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01003927 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003928 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003929}
3930
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003931private function f_TC_assignment_a5_not_sup(charstring id) runs on MSC_ConnHdlr {
3932 var template PDU_BSSAP exp_ass_cpl := f_gen_exp_compl();
3933 var PDU_BSSAP exp_ass_req := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003934
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003935 exp_ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3936 exp_ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3937
3938 /* this is like the beginning of f_establish_fully(), but only up to ciphering reject */
3939
3940 var BSSMAP_FIELD_CodecType codecType;
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003941
3942 codecType := exp_ass_req.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType;
3943 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
3944
3945 f_create_chan_and_exp();
3946 /* we should now have a COMPL_L3 at the MSC */
3947
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003948 /* Start ciphering, expect Cipher Mode Reject */
Neels Hofmeyr6c388f22021-06-11 02:36:56 +02003949 f_cipher_mode(g_pars.encr, exp_fail := true);
Harald Welte552620d2017-12-16 23:21:36 +01003950}
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003951testcase TC_assignment_fr_a5_not_sup() runs on test_CT {
3952 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01003953 var MSC_ConnHdlr vc_conn;
3954
Harald Welte89d42e82017-12-17 16:42:41 +01003955 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003956 f_sleep(1.0);
3957
Neels Hofmeyr0588cad2021-06-11 01:38:18 +02003958 pars.encr := valueof(t_EncrParams('20'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003959 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003960 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003961 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003962}
3963
3964
Harald Welte4532e0a2017-12-23 02:05:44 +01003965private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003966 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01003967 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02003968 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01003969 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003970
3971 f_statsd_reset();
Harald Weltea0630032018-03-20 21:09:55 +01003972 f_establish_fully(ass_cmd, exp_compl);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003973
3974 var StatsDExpects expect := {
Daniel Willmannc5398f72020-09-21 10:41:35 +02003975 { name := "TTCN3.bts.0.chreq.total", mtype := "c", min := 1, max := 1},
3976 { name := "TTCN3.bts.0.chreq.successful", mtype := "c", min := 1, max := 1},
Daniel Willmannebdecc02020-08-12 15:30:17 +02003977 { name := "TTCN3.bsc.0.assignment.attempted", mtype := "c", min := 1, max := 1},
3978 { name := "TTCN3.bsc.0.assignment.completed", mtype := "c", min := 1, max := 1}
3979 };
3980 f_statsd_expect(expect);
Harald Welte4532e0a2017-12-23 02:05:44 +01003981}
3982
3983testcase TC_assignment_sign() runs on test_CT {
3984 var MSC_ConnHdlr vc_conn;
3985
3986 f_init(1, true);
3987 f_sleep(1.0);
3988
Harald Welte8863fa12018-05-10 20:15:27 +02003989 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01003990 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003991 f_shutdown_helper();
Harald Welte4532e0a2017-12-23 02:05:44 +01003992}
3993
Harald Welte60aa5762018-03-21 19:33:13 +01003994/***********************************************************************
3995 * Codec (list) testing
3996 ***********************************************************************/
3997
3998/* check if the given rsl_mode is compatible with the a_elem */
3999private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
4000return boolean {
4001 select (a_elem.codecType) {
4002 case (GSM_FR) {
4003 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
4004 return true;
4005 }
4006 }
4007 case (GSM_HR) {
4008 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
4009 return true;
4010 }
4011 }
4012 case (GSM_EFR) {
4013 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
4014 return true;
4015 }
4016 }
4017 case (FR_AMR) {
4018 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
4019 return true;
4020 }
4021 }
4022 case (HR_AMR) {
4023 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
4024 return true;
4025 }
4026 }
4027 case else { }
4028 }
4029 return false;
4030}
4031
4032/* check if the given rsl_mode is compatible with the a_list */
4033private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
4034return boolean {
4035 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
4036 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
4037 return true;
4038 }
4039 }
4040 return false;
4041}
4042
4043/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02004044function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01004045return BSSMAP_IE_ChannelType {
4046 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
4047 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
4048 select (a_elem.codecType) {
4049 case (GSM_FR) {
4050 ret.channelRateAndType := ChRate_TCHF;
4051 ret.speechId_DataIndicator := Spdi_TCHF_FR;
4052 }
4053 case (GSM_HR) {
4054 ret.channelRateAndType := ChRate_TCHH;
4055 ret.speechId_DataIndicator := Spdi_TCHH_HR;
4056 }
4057 case (GSM_EFR) {
4058 ret.channelRateAndType := ChRate_TCHF;
4059 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
4060 }
4061 case (FR_AMR) {
4062 ret.channelRateAndType := ChRate_TCHF;
4063 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
4064 }
4065 case (HR_AMR) {
4066 ret.channelRateAndType := ChRate_TCHH;
4067 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
4068 }
4069 case else {
4070 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02004071 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01004072 }
4073 }
4074 return ret;
4075}
4076
Harald Weltea63b9102018-03-22 20:36:16 +01004077private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
4078return template RSL_IE_Body {
4079 var template RSL_IE_Body mode_ie := {
4080 chan_mode := {
4081 len := ?,
4082 reserved := ?,
4083 dtx_d := ?,
4084 dtx_u := ?,
4085 spd_ind := RSL_SPDI_SPEECH,
4086 ch_rate_type := -,
4087 coding_alg_rate := -
4088 }
4089 }
4090
4091 select (a_elem.codecType) {
4092 case (GSM_FR) {
4093 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4094 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
4095 }
4096 case (GSM_HR) {
4097 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
4098 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
4099 }
4100 case (GSM_EFR) {
4101 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4102 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
4103 }
4104 case (FR_AMR) {
4105 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4106 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
4107 }
4108 case (HR_AMR) {
4109 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
4110 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
4111 }
4112 }
4113 return mode_ie;
4114}
4115
Harald Welte60aa5762018-03-21 19:33:13 +01004116type record CodecListTest {
4117 BSSMAP_IE_SpeechCodecList codec_list,
4118 charstring id
4119}
4120type record of CodecListTest CodecListTests
4121
4122private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004123 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
4124 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
Harald Welte60aa5762018-03-21 19:33:13 +01004125
4126 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02004127 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte79f3f542018-05-25 20:02:37 +02004128 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
4129 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
4130 g_pars.ass_codec_list.codecElements[0];
Philipp Maierd0e64b02019-03-13 14:15:23 +01004131 if (isvalue(g_pars.expect_mr_s0_s7)) {
4132 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
4133 g_pars.expect_mr_s0_s7;
4134 }
Harald Welte79f3f542018-05-25 20:02:37 +02004135 }
Harald Welte60aa5762018-03-21 19:33:13 +01004136 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
4137 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01004138 log("expecting ASS COMPL like this: ", exp_compl);
4139
4140 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01004141
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004142 if (not g_pars.expect_channel_mode_modify) {
4143 /* Verify that the RSL-side activation actually matches our expectations */
4144 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
Harald Weltea63b9102018-03-22 20:36:16 +01004145
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004146 var RSL_IE_Body mode_ie;
4147 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
4148 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02004149 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004150 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004151 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
4152 if (not match(mode_ie, t_mode_ie)) {
4153 log("mode_ie ", mode_ie, " != t_mode_ie ", t_mode_ie);
4154 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004155 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004156
4157 var RSL_IE_Body mr_conf;
4158 if (g_pars.expect_mr_conf_ie != omit) {
4159 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
4160 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
4161 mtc.stop;
4162 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004163 log("found RSL MR CONFIG IE: ", mr_conf);
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004164
4165 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
4166 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
4167 g_pars.expect_mr_conf_ie);
4168 }
4169 } else {
4170 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
4171 log("found RSL MR CONFIG IE: ", mr_conf);
4172 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
4173 mtc.stop;
4174 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004175 }
4176 }
Harald Welte60aa5762018-03-21 19:33:13 +01004177}
4178
Philipp Maierd0e64b02019-03-13 14:15:23 +01004179private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
4180
4181 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4182 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4183
4184 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02004185 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maierd0e64b02019-03-13 14:15:23 +01004186 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
4187 }
4188 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
4189 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
4190 log("expecting ASS FAIL like this: ", exp_fail);
4191
4192 f_establish_fully(ass_cmd, exp_fail);
4193}
4194
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004195const CounterNameVals counternames_bsc_bts_assignment := {
4196 { "assignment:attempted", 0 },
4197 { "assignment:completed", 0 },
4198 { "assignment:stopped", 0 },
4199 { "assignment:no_channel", 0 },
4200 { "assignment:timeout", 0 },
4201 { "assignment:failed", 0 },
4202 { "assignment:error", 0 }
4203};
4204
4205const CounterNameVals counternames_bts_assignment := {
4206 { "assignment:attempted_sign", 0 },
4207 { "assignment:attempted_speech", 0 },
4208 { "assignment:completed_sign", 0 },
4209 { "assignment:completed_speech", 0 },
4210 { "assignment:stopped_sign", 0 },
4211 { "assignment:stopped_speech", 0 },
4212 { "assignment:no_channel_sign", 0 },
4213 { "assignment:no_channel_speech", 0 },
4214 { "assignment:timeout_sign", 0 },
4215 { "assignment:timeout_speech", 0 },
4216 { "assignment:failed_sign", 0 },
4217 { "assignment:failed_speech", 0 },
4218 { "assignment:error_sign", 0 },
4219 { "assignment:error_speech", 0 }
4220};
4221
4222function f_ctrs_bsc_and_bts_assignment_init(integer bts_count := NUM_BTS) runs on test_CT {
4223 var CounterNameVals bts_names := counternames_bsc_bts_assignment & counternames_bts_assignment;
4224 f_ctrs_bts_init(bts_count, bts_names);
4225 f_ctrs_bsc_init(counternames_bsc_bts_assignment);
4226}
4227
Harald Welte60aa5762018-03-21 19:33:13 +01004228testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004229 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004230 var MSC_ConnHdlr vc_conn;
4231
4232 f_init(1, true);
4233 f_sleep(1.0);
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004234 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004235
4236 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004237 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004238 vc_conn.done;
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004239
4240 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4241 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4242 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4243 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4244 f_ctrs_bts_verify();
4245
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004246 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004247}
4248
4249testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004250 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004251 var MSC_ConnHdlr vc_conn;
4252
4253 f_init(1, true);
4254 f_sleep(1.0);
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004255 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004256
4257 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004258 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004259 vc_conn.done;
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004260
4261 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4262 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4263 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4264 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4265 f_ctrs_bts_verify();
4266
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004267 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004268}
4269
4270testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004271 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004272 var MSC_ConnHdlr vc_conn;
4273
4274 f_init(1, true);
4275 f_sleep(1.0);
4276
4277 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004278 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004279 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004280 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004281}
4282
Philipp Maierd0e64b02019-03-13 14:15:23 +01004283/* Allow 5,90k only (current default config) */
4284private function f_allow_amr_rate_5_90k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00004285 f_vty_cfg_msc(BSCVTY, 0, {
4286 "amr-config 12_2k forbidden",
4287 "amr-config 10_2k forbidden",
4288 "amr-config 7_95k forbidden",
4289 "amr-config 7_40k forbidden",
4290 "amr-config 6_70k forbidden",
4291 "amr-config 5_90k allowed",
4292 "amr-config 5_15k forbidden",
4293 "amr-config 4_75k forbidden"
4294 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01004295}
4296
4297/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
4298 * ("Config-NB-Code = 1") */
4299private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00004300 f_vty_cfg_msc(BSCVTY, 0, {
4301 "amr-config 12_2k allowed",
4302 "amr-config 10_2k forbidden",
4303 "amr-config 7_95k forbidden",
4304 "amr-config 7_40k allowed",
4305 "amr-config 6_70k forbidden",
4306 "amr-config 5_90k allowed",
4307 "amr-config 5_15k forbidden",
4308 "amr-config 4_75k allowed"
4309 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01004310}
4311
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004312private function f_vty_amr_start_mode_set(boolean fr, charstring startmode) runs on test_CT {
4313 var charstring tch;
4314 if (fr) {
4315 tch := "tch-f";
4316 } else {
4317 tch := "tch-h";
4318 }
4319 f_vty_cfg_bts(BSCVTY, 0, { "amr " & tch & " start-mode " & startmode });
4320}
4321
4322/* Set the AMR start-mode for this TCH back to the default configuration. */
4323private function f_vty_amr_start_mode_restore(boolean fr) runs on test_CT {
4324 f_vty_amr_start_mode_set(fr, "auto");
4325}
4326
Harald Welte60aa5762018-03-21 19:33:13 +01004327testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004328 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004329 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02004330
4331 /* Note: This setups the codec configuration. The parameter payload in
4332 * mr_conf must be consistant with the parameter codecElements in pars
4333 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004334 var RSL_IE_Body mr_conf := {
4335 other := {
4336 len := 2,
4337 payload := '2804'O
4338 }
4339 };
Harald Welte60aa5762018-03-21 19:33:13 +01004340
Philipp Maier7695a0d2018-09-27 17:52:14 +02004341 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Philipp Maier806f8f12019-03-12 12:13:41 +01004342 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02004343 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
4344 pars.expect_mr_conf_ie := mr_conf;
4345
Harald Welte60aa5762018-03-21 19:33:13 +01004346 f_init(1, true);
4347 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004348 f_vty_amr_start_mode_set(true, "1");
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004349 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004350
Harald Welte8863fa12018-05-10 20:15:27 +02004351 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004352 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004353
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004354 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4355 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4356 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4357 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4358 f_ctrs_bts_verify();
4359
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004360 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004361 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004362}
4363
4364testcase TC_assignment_codec_amr_h() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004365 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004366 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02004367
4368 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004369 var RSL_IE_Body mr_conf := {
4370 other := {
4371 len := 2,
4372 payload := '2804'O
4373 }
4374 };
Harald Welte60aa5762018-03-21 19:33:13 +01004375
Philipp Maier7695a0d2018-09-27 17:52:14 +02004376 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Philipp Maier806f8f12019-03-12 12:13:41 +01004377 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02004378 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4379 pars.expect_mr_conf_ie := mr_conf;
4380
Harald Welte60aa5762018-03-21 19:33:13 +01004381 f_init(1, true);
4382 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004383 f_vty_amr_start_mode_set(false, "1");
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004384 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004385
Harald Welte8863fa12018-05-10 20:15:27 +02004386 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004387 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004388
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004389 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4390 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4391 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4392 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4393 f_ctrs_bts_verify();
4394
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004395 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004396 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004397}
4398
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004399/* Establish signalling on a TCH/F lchan, and then switch to speech mode without a new Assignment. */
4400testcase TC_assignment_codec_fr_by_mode_modify() runs on test_CT {
4401 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4402 var MSC_ConnHdlr vc_conn;
4403
4404 f_init(1, true);
4405 f_sleep(1.0);
4406
4407 /* By disabling all SDCCH, the MS should be given a TCH/F for signalling. Then activating an FR codec should
4408 * merely do a Channel Mode Modify, and not assign to a new lchan. f_establish_fully() already accounts for
4409 * expecting a Channel Mode Modify if the channel type is compatible. */
4410 f_disable_all_sdcch();
4411 f_disable_all_tch_h();
4412
4413 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4414 pars.expect_channel_mode_modify := true;
4415 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4416 vc_conn.done;
4417
4418 f_enable_all_sdcch();
4419 f_enable_all_tch();
4420 f_shutdown_helper();
4421}
4422
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004423/* 'amr start-mode auto' should not keep the (unused) 'smod' bits from previous configuration */
4424testcase TC_assignment_codec_amr_startmode_cruft() runs on test_CT {
4425 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4426 var MSC_ConnHdlr vc_conn;
4427
4428 var RSL_IE_Body mr_conf := {
4429 other := {
4430 len := 2,
4431 payload := '2004'O /* <- expect ICMI=0, smod=00 */
4432 }
4433 };
4434
4435 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4436 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
4437 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
4438 pars.expect_mr_conf_ie := mr_conf;
4439
4440 f_init(1, true);
4441 f_sleep(1.0);
4442
4443 /* First set nonzero start mode bits */
4444 f_vty_amr_start_mode_set(true, "4");
4445 /* Now set to auto, and expect the startmode bits to be zero in the message, i.e. ensure that osmo-bsc does not
4446 * let the startmode bits stick around and has deterministic MultiRate config for 'start-mode auto'; that is
4447 * ensured by above '2004'O, where 'x0xx'O indicates ICMI = 0, spare = 0, smod = 00. */
4448 f_vty_amr_start_mode_set(true, "auto");
4449
4450 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4451 vc_conn.done;
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004452
4453 /* Clear the startmode bits to not affect subsequent tests, in case the bits should indeed stick around. */
4454 f_vty_amr_start_mode_set(true, "1");
4455 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004456 f_shutdown_helper();
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004457}
4458
Neels Hofmeyr21863562020-11-26 00:34:33 +00004459function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0,
4460 charstring start_mode := "1")
Philipp Maierd0e64b02019-03-13 14:15:23 +01004461runs on test_CT {
4462
4463 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4464 var MSC_ConnHdlr vc_conn;
4465
4466 /* See note above */
4467 var RSL_IE_Body mr_conf := {
4468 other := {
4469 len := lengthof(mrconf),
4470 payload := mrconf
4471 }
4472 };
4473
4474 if (fr) {
4475 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4476 } else {
4477 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4478 }
4479 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4480 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4481 pars.expect_mr_conf_ie := mr_conf;
4482 pars.expect_mr_s0_s7 := exp_s8_s0;
4483
4484 f_init(1, true);
4485 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004486 f_vty_amr_start_mode_set(fr, start_mode);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004487 f_sleep(1.0);
4488
4489 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4490 vc_conn.done;
4491 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004492 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004493}
4494
4495function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
4496runs on test_CT {
4497
4498 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4499 var MSC_ConnHdlr vc_conn;
4500
4501 if (fr) {
4502 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4503 } else {
4504 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4505 }
4506 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4507 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4508
4509 f_init(1, true);
4510 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004511 f_vty_amr_start_mode_set(fr, "1");
Philipp Maierd0e64b02019-03-13 14:15:23 +01004512 f_sleep(1.0);
4513
4514 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
4515 vc_conn.done;
4516 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004517 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004518}
4519
4520
4521/* Set S1, we expect an AMR multirate configuration IE with all four rates
4522 * set. */
4523testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004524 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004525 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004526}
4527
4528/* Set S1, we expect an AMR multirate configuration IE with the lower three
4529 * rates set. */
4530testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004531 f_TC_assignment_codec_amr(false, '2815208820'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004532 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004533}
4534
4535/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4536 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4537testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004538 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004539 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004540}
4541
4542/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4543 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4544testcase TC_assignment_codec_amr_h_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004545 f_TC_assignment_codec_amr(false, '2815208820'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004546 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004547}
4548
4549/* The following block of tests selects more and more rates until all four
4550 * possible rates are in the active set (full rate) */
4551testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004552 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004553 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004554}
4555
4556testcase TC_assignment_codec_amr_f_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004557 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004558 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004559}
4560
4561testcase TC_assignment_codec_amr_f_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004562 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004563 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004564}
4565
4566testcase TC_assignment_codec_amr_f_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004567 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004568 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004569}
4570
4571/* The following block of tests selects more and more rates until all three
4572 * possible rates are in the active set (half rate) */
4573testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004574 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004575 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004576}
4577
4578testcase TC_assignment_codec_amr_h_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004579 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004580 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004581}
4582
4583testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004584 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004585 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004586}
4587
4588/* The following block tests what happens when the MSC does offer rate
4589 * configurations that are not supported by the BSC. Normally such situations
4590 * should not happen because the MSC gets informed by the BSC in advance via
4591 * the L3 COMPLETE message which rates are applicable. The MSC should not try
4592 * to offer rates that are not applicable anyway. */
4593
4594testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004595 /* Try to include 12,2k in into the active set even though the channel
4596 * is half rate only. The BSC is expected to remove the 12,0k */
4597 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004598 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004599}
4600
4601testcase TC_assignment_codec_amr_f_S01234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004602 /* See what happens when all rates are selected at once. Since then
4603 * Also S1 is selected, this setting will be prefered and we should
4604 * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
4605 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004606 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004607}
4608
4609testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004610 /* Same as above, but with S1 missing, the MSC is then expected to
4611 * select the currently supported rates, which are also 12.2k, 7,40k,
4612 * 5,90k, and 4,75k, into the active set. */
4613 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'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_f_zero() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004618 /* Try to select no rates at all */
4619 f_TC_assignment_codec_amr_fail(true, '00000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004620 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004621}
4622
4623testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004624 /* Try to select only unsupported rates */
4625 f_TC_assignment_codec_amr_fail(true, '01101000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004626 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004627}
4628
4629testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004630 /* Try to select 12,2k for half rate */
4631 f_TC_assignment_codec_amr_fail(false, '10000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004632 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004633}
4634
Neels Hofmeyr21863562020-11-26 00:34:33 +00004635testcase TC_assignment_codec_amr_f_start_mode_auto() runs on test_CT {
4636 f_TC_assignment_codec_amr(true, '209520882208'O, '11111111'B, '00000010'B,
4637 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004638 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004639}
4640
4641testcase TC_assignment_codec_amr_h_start_mode_auto() runs on test_CT {
4642 f_TC_assignment_codec_amr(false, '2015208820'O, '10010101'B, '00010101'B,
4643 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004644 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004645}
4646
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004647testcase TC_assignment_codec_amr_f_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004648 /* "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 +00004649 f_TC_assignment_codec_amr(true, '2b9520882208'O, '11111111'B, '00000010'B,
4650 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004651 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004652}
4653
4654testcase TC_assignment_codec_amr_h_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004655 /* "amr tch-h modes 0 2 4" => total 3 modes and start mode 4 => '10'B on the wire */
4656 f_TC_assignment_codec_amr(false, '2a15208820'O, '10010101'B, '00010101'B,
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004657 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004658 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004659}
4660
Philipp Maierac09bfc2019-01-08 13:41:39 +01004661private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004662 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
4663 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
4664 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
4665 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004666}
4667
4668private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004669 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
4670 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004671}
4672
4673private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004674 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
4675 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
4676 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
4677 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
4678 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
4679 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004680}
4681
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004682private function f_disable_all_sdcch() runs on test_CT {
4683 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 borken");
4684 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 borken");
4685 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 borken");
4686 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 borken");
4687}
4688
4689private function f_enable_all_sdcch() runs on test_CT {
4690 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 unused");
4691 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 unused");
4692 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 unused");
4693 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 unused");
4694}
4695
Philipp Maierac09bfc2019-01-08 13:41:39 +01004696/* Allow HR only */
4697private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
4698 g_pars := f_gen_test_hdlr_pars();
4699 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4700 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4701 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4702 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4703 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4704 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4705 f_establish_fully(ass_cmd, exp_compl);
4706}
4707
4708/* Allow FR only */
4709private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
4710 g_pars := f_gen_test_hdlr_pars();
4711 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4712 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4713 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4714 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4715 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4716 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4717 f_establish_fully(ass_cmd, exp_compl);
4718}
4719
4720/* Allow HR only (expect assignment failure) */
4721private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
4722 g_pars := f_gen_test_hdlr_pars();
4723 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4724 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4725 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4726 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4727 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4728 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4729 f_establish_fully(ass_cmd, exp_fail);
4730}
4731
4732/* Allow FR only (expect assignment failure) */
4733private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(charstring id) runs on MSC_ConnHdlr {
4734 g_pars := f_gen_test_hdlr_pars();
4735 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4736 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4737 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4738 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4739 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4740 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4741 f_establish_fully(ass_cmd, exp_fail);
4742}
4743
4744/* Allow FR and HR, but prefer FR */
4745private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4746 g_pars := f_gen_test_hdlr_pars();
4747 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4748 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4749 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4750 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4751 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4752 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4753 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4754 f_establish_fully(ass_cmd, exp_compl);
4755}
4756
4757/* Allow FR and HR, but prefer HR */
4758private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4759 g_pars := f_gen_test_hdlr_pars();
4760 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4761 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4762 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4763 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4764 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4765 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4766 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4767 f_establish_fully(ass_cmd, exp_compl);
4768}
4769
4770/* Allow FR and HR, but prefer FR */
4771private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4772 g_pars := f_gen_test_hdlr_pars();
4773 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4774 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4775 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4776 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4777 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4778 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4779 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4780 f_establish_fully(ass_cmd, exp_compl);
4781}
4782
4783/* Allow FR and HR, but prefer HR */
4784private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4785 g_pars := f_gen_test_hdlr_pars();
4786 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4787 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4788 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4789 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4790 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4791 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4792 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4793 f_establish_fully(ass_cmd, exp_compl);
4794}
4795
4796/* Request a HR channel while all FR channels are exhausted, this is expected
4797 * to work without conflicts */
4798testcase TC_assignment_codec_fr_exhausted_req_hr() runs on test_CT {
4799 var MSC_ConnHdlr vc_conn;
4800 f_init(1, true);
4801 f_sleep(1.0);
4802 f_enable_all_tch();
4803 f_disable_all_tch_f();
4804 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr));
4805 vc_conn.done;
4806 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004807 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004808}
4809
4810/* Request a FR channel while all FR channels are exhausted, this is expected
4811 * to fail. */
4812testcase TC_assignment_codec_fr_exhausted_req_fr() runs on test_CT {
4813 var MSC_ConnHdlr vc_conn;
4814 f_init(1, true);
4815 f_sleep(1.0);
4816 f_enable_all_tch();
4817 f_disable_all_tch_f();
4818 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr_fail));
4819 vc_conn.done;
4820 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004821 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004822}
4823
4824/* Request a FR (prefered) or alternatively a HR channel while all FR channels
4825 * are exhausted, this is expected to be resolved by selecting a HR channel. */
4826testcase TC_assignment_codec_fr_exhausted_req_fr_hr() runs on test_CT {
4827 var MSC_ConnHdlr vc_conn;
4828 f_init(1, true);
4829 f_sleep(1.0);
4830 f_enable_all_tch();
4831 f_disable_all_tch_f();
4832 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
4833 vc_conn.done;
4834 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004835 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004836}
4837
4838/* Request a HR (prefered) or alternatively a FR channel while all FR channels
4839 * are exhausted, this is expected to work without conflicts. */
4840testcase TC_assignment_codec_fr_exhausted_req_hr_fr() 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_fr_exhausted_req_hr_fr));
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 HR channels are exhausted, this is expected
4853 * to work without conflicts */
4854testcase TC_assignment_codec_hr_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_h();
4860 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr));
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 HR channel while all HR channels are exhausted, this is expected
4867 * to fail. */
4868testcase TC_assignment_codec_hr_exhausted_req_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_h();
4874 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr_fail));
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 HR channels
4881 * are exhausted, this is expected to be resolved by selecting a FR channel. */
4882testcase TC_assignment_codec_hr_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_h();
4888 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_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 (prefered) or alternatively a HR channel while all HR channels
4895 * are exhausted, this is expected to work without conflicts. */
4896testcase TC_assignment_codec_hr_exhausted_req_fr_hr() 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_hr_exhausted_req_fr_hr));
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/* Allow FR and HR, but prefer HR */
4909private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4910 g_pars := f_gen_test_hdlr_pars();
4911 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4912 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4913 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4914 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4915 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4916 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4917 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4918 f_establish_fully(ass_cmd, exp_compl);
4919}
4920
4921/* Allow FR and HR, but prefer FR */
4922private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4923 g_pars := f_gen_test_hdlr_pars();
4924 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4925 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4926 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4927 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4928 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4929 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4930 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4931 f_establish_fully(ass_cmd, exp_compl);
4932}
4933
4934/* Request a HR (prefered) or alternatively a FR channel, it is expected that
4935 * HR, which is the prefered type, is selected. */
4936testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
4937 var MSC_ConnHdlr vc_conn;
4938 f_init(1, true);
4939 f_sleep(1.0);
4940 f_enable_all_tch();
4941 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
4942 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004943 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004944}
4945
4946/* Request a FR (prefered) or alternatively a HR channel, it is expected that
4947 * FR, which is the prefered type, is selected. */
4948testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
4949 var MSC_ConnHdlr vc_conn;
4950 f_init(1, true);
4951 f_sleep(1.0);
4952 f_enable_all_tch();
4953 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
4954 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004955 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004956}
4957
Pau Espin Pedrol14475352021-07-22 15:48:16 +02004958/* request a signalling channel with all SDCCH exhausted, it is expected that a TCH will be selected */
4959private function f_TC_assignment_sdcch_exhausted_req_signalling(charstring id) runs on MSC_ConnHdlr {
4960 g_pars := f_gen_test_hdlr_pars();
4961 g_pars.ra := '02'O; /* RA containing reason=LU */
4962
4963 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
4964 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
4965 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
4966 var template uint3_t tsc := ?;
4967
4968 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
4969 f_create_bssmap_exp(l3_enc);
4970 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
4971 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, tsc);
4972
4973 /* we should now have a COMPL_L3 at the MSC */
4974 timer T := 10.0;
4975 T.start;
4976 alt {
4977 [] BSSAP.receive(tr_BSSMAP_ComplL3);
4978 [] T.timeout {
4979 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
4980 }
4981 }
4982}
4983testcase TC_assignment_sdcch_exhausted_req_signalling() runs on test_CT {
4984 var MSC_ConnHdlr vc_conn;
4985 f_init(1, true);
4986 f_sleep(1.0);
4987 f_disable_all_sdcch();
4988 vc_conn := f_start_handler(refers(f_TC_assignment_sdcch_exhausted_req_signalling));
4989 vc_conn.done;
4990 f_enable_all_sdcch();
4991 f_shutdown_helper();
4992}
4993
4994/* Request a signalling channel with all SDCCH exhausted, it is
4995 expected that no TCH will be selected for signalling and assigment will fail
4996 because it's dictated by VTY config */
4997testcase TC_assignment_sdcch_exhausted_req_signalling_tch_forbidden() runs on test_CT {
4998 var RSL_Message rsl_unused, rsl_msg;
4999 var GsmRrMessage rr;
5000 f_init(1, false);
5001 f_sleep(1.0);
5002 f_vty_allow_tch_for_signalling(false, 0);
5003 f_disable_all_sdcch();
5004
5005 /* RA containing reason=LU */
5006 f_ipa_tx(0, ts_RSL_CHAN_RQD('02'O, 2342));
5007 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
5008 rr := dec_GsmRrMessage(rsl_msg.ies[1].body.full_imm_ass_info.payload);
5009 if (rr.header.message_type != IMMEDIATE_ASSIGNMENT_REJECT) {
5010 setverdict(fail, "Expected reject");
5011 }
5012
5013 f_vty_allow_tch_for_signalling(true, 0);
5014 f_enable_all_sdcch();
5015 f_shutdown_helper();
5016}
5017
5018/* Request a voice channel with all SDCCH exhausted, it is
5019 * expected that TCH channel will be allocated since the VTY option is only
5020 * aimed at signalling requests */
5021private function f_TC_assignment_sdcch_exhausted_req_voice_tch_forbidden(charstring id) runs on MSC_ConnHdlr {
5022 g_pars := f_gen_test_hdlr_pars();
5023 g_pars.ra := '43'O; /* RA containing reason=originating speech call*/
5024
5025 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
5026 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
5027 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
5028 var template uint3_t tsc := ?;
5029
5030 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
5031 f_create_bssmap_exp(l3_enc);
5032 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
5033 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, tsc);
5034
5035 /* we should now have a COMPL_L3 at the MSC */
5036 timer T := 10.0;
5037 T.start;
5038 alt {
5039 [] BSSAP.receive(tr_BSSMAP_ComplL3);
5040 [] T.timeout {
5041 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
5042 }
5043 }
5044}
5045testcase TC_assignment_sdcch_exhausted_req_voice_tch_forbidden() runs on test_CT {
5046 var MSC_ConnHdlr vc_conn;
5047 f_init(1, true);
5048 f_sleep(1.0);
5049 f_vty_allow_tch_for_signalling(false, 0);
5050 f_disable_all_sdcch();
5051
5052 vc_conn := f_start_handler(refers(f_TC_assignment_sdcch_exhausted_req_voice_tch_forbidden));
5053 vc_conn.done;
5054
5055 f_vty_allow_tch_for_signalling(true, 0);
5056 f_enable_all_sdcch();
5057 f_shutdown_helper();
5058}
5059
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005060testcase TC_assignment_osmux() runs on test_CT {
5061 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5062 var MSC_ConnHdlr vc_conn;
5063
5064 /* See note above */
5065 var RSL_IE_Body mr_conf := {
5066 other := {
5067 len := 2,
5068 payload := '2804'O
5069 }
5070 };
5071
5072 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
5073 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
5074 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
5075 pars.expect_mr_conf_ie := mr_conf;
5076 pars.use_osmux := true;
5077
5078 f_init(1, true, true);
5079 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00005080 f_vty_amr_start_mode_set(false, "1");
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005081
5082 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
5083 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00005084
5085 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01005086 f_shutdown_helper();
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005087}
5088
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02005089/* test the procedure of the MSC requesting a Classmark Update:
5090 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
5091 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01005092private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005093 g_pars := f_gen_test_hdlr_pars();
5094
Harald Weltea0630032018-03-20 21:09:55 +01005095 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01005096 /* we should now have a COMPL_L3 at the MSC */
Harald Welte898113b2018-01-31 18:32:21 +01005097
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02005098 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
5099 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
5100
Harald Welte898113b2018-01-31 18:32:21 +01005101 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
5102 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
5103 setverdict(pass);
5104}
5105testcase TC_classmark() runs on test_CT {
5106 var MSC_ConnHdlr vc_conn;
5107 f_init(1, true);
5108 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005109 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01005110 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005111 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01005112}
5113
Harald Welteeddf0e92020-06-21 19:42:15 +02005114/* Send a CommonID from the simulated MSC and verify that the information is used to
5115 * fill BSC-internal data structures (specifically, bsc_subscr associated with subscr_conn) */
5116private function f_tc_common_id(charstring id) runs on MSC_ConnHdlr {
5117 g_pars := f_gen_test_hdlr_pars();
5118 f_MscConnHdlr_init_vty();
5119
5120 f_create_chan_and_exp();
5121 /* we should now have a COMPL_L3 at the MSC */
Harald Welteeddf0e92020-06-21 19:42:15 +02005122
5123 /* Send CommonID */
5124 BSSAP.send(ts_BSSMAP_CommonId(g_pars.imsi));
5125
5126 /* Use VTY to verify that the IMSI of the subscr_conn is set */
5127 var charstring regex := "*(IMSI: " & hex2str(g_pars.imsi) & ")*";
5128 f_vty_transceive_match_regexp_retry(BSCVTY, "show conns", regex, 0, 4, 1.0);
5129
5130 setverdict(pass);
5131}
5132testcase TC_common_id() runs on test_CT {
5133 var MSC_ConnHdlr vc_conn;
5134 f_init(1, true);
5135 f_sleep(1.0);
5136 vc_conn := f_start_handler(refers(f_tc_common_id));
5137 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005138 f_shutdown_helper();
Harald Welteeddf0e92020-06-21 19:42:15 +02005139}
5140
Harald Weltee3bd6582018-01-31 22:51:25 +01005141private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005142 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01005143 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01005144 /* we should now have a COMPL_L3 at the MSC */
Harald Welte898113b2018-01-31 18:32:21 +01005145
Harald Weltee3bd6582018-01-31 22:51:25 +01005146 /* send the single message we want to send */
5147 f_rsl_send_l3(l3);
5148}
5149
5150private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
5151 timer T := sec;
5152 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01005153 T.start;
5154 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01005155 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
5156 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02005157 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01005158 }
5159 [] T.timeout {
5160 setverdict(pass);
5161 }
5162 }
5163}
5164
Harald Weltee3bd6582018-01-31 22:51:25 +01005165/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
5166private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
5167 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
5168 f_bssap_expect_nothing();
5169}
Harald Welte898113b2018-01-31 18:32:21 +01005170testcase TC_unsol_ass_fail() runs on test_CT {
5171 var MSC_ConnHdlr vc_conn;
5172 f_init(1, true);
5173 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005174 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01005175 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005176 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01005177}
Harald Welte552620d2017-12-16 23:21:36 +01005178
Harald Welteea99a002018-01-31 20:46:43 +01005179
5180/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
5181private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01005182 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
5183 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01005184}
5185testcase TC_unsol_ass_compl() runs on test_CT {
5186 var MSC_ConnHdlr vc_conn;
5187 f_init(1, true);
5188 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005189 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01005190 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005191 f_shutdown_helper();
Harald Welteea99a002018-01-31 20:46:43 +01005192}
5193
5194
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005195/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
5196private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01005197 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
5198 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005199}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005200testcase TC_unsol_ho_fail() runs on test_CT {
5201 var MSC_ConnHdlr vc_conn;
5202 f_init(1, true);
5203 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005204 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005205 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005206 f_shutdown_helper();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005207}
5208
5209
Harald Weltee3bd6582018-01-31 22:51:25 +01005210/* short message from MS should be ignored */
5211private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005212 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01005213 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01005214 /* we should now have a COMPL_L3 at the MSC */
Harald Weltee3bd6582018-01-31 22:51:25 +01005215
5216 /* send short message */
5217 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
5218 f_bssap_expect_nothing();
5219}
5220testcase TC_err_82_short_msg() runs on test_CT {
5221 var MSC_ConnHdlr vc_conn;
5222 f_init(1, true);
5223 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005224 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01005225 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005226 f_shutdown_helper();
Harald Weltee3bd6582018-01-31 22:51:25 +01005227}
5228
5229
Harald Weltee9e02e42018-01-31 23:36:25 +01005230/* 24.008 8.4 Unknown message must trigger RR STATUS */
5231private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
5232 f_est_single_l3(ts_RRM_UL_REL('00'O));
5233 timer T := 3.0
5234 alt {
5235 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
5236 setverdict(pass);
5237 }
5238 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01005239 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01005240 }
5241}
5242testcase TC_err_84_unknown_msg() runs on test_CT {
5243 var MSC_ConnHdlr vc_conn;
5244 f_init(1, true);
5245 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005246 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01005247 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005248 f_shutdown_helper();
Harald Weltee9e02e42018-01-31 23:36:25 +01005249}
5250
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005251/***********************************************************************
5252 * Handover
5253 ***********************************************************************/
5254
Harald Welte94e0c342018-04-07 11:33:23 +02005255/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
5256private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
5257runs on test_CT {
5258 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
5259 " timeslot "&int2str(ts_nr)&" ";
5260 f_vty_transceive(BSCVTY, cmd & suffix);
5261}
5262
Harald Welte261af4b2018-02-12 21:20:39 +01005263/* 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 +07005264private function f_vty_ss_action(TELNETasp_PT pt, charstring suffix,
5265 uint8_t bts_nr, uint8_t trx_nr,
5266 in RslChannelNr chan_nr)
5267{
Harald Welte261af4b2018-02-12 21:20:39 +01005268 /* FIXME: resolve those from component-global state */
5269 var integer ts_nr := chan_nr.tn;
5270 var integer ss_nr;
5271 if (ischosen(chan_nr.u.ch0)) {
5272 ss_nr := 0;
5273 } else if (ischosen(chan_nr.u.lm)) {
5274 ss_nr := chan_nr.u.lm.sub_chan;
5275 } else if (ischosen(chan_nr.u.sdcch4)) {
5276 ss_nr := chan_nr.u.sdcch4.sub_chan;
5277 } else if (ischosen(chan_nr.u.sdcch8)) {
5278 ss_nr := chan_nr.u.sdcch8.sub_chan;
5279 } else {
5280 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02005281 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01005282 }
5283
5284 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
5285 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005286 f_vty_transceive(pt, cmd & suffix);
Harald Welte261af4b2018-02-12 21:20:39 +01005287}
5288
Neels Hofmeyr91401012019-07-11 00:42:35 +02005289/* Even though the VTY command to trigger handover takes a new BTS number as argument, behind the scenes osmo-bsc always
5290 * translates that to a target ARFCN+BSIC first. See bsc_vty.c trigger_ho_or_as(), which puts the selected BTS' neighbor
5291 * ident key (ARFCN + BSIC) in the struct passed on to handover_request(). handover_start() then resolves that to a
5292 * viable actual neighbor cell. So from the internal osmo-bsc perspective, we always request handover to an ARFCN + BSIC
5293 * pair, not really to a specific BTS number. */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005294private function f_vty_handover(TELNETasp_PT pt, uint8_t bts_nr, uint8_t trx_nr,
5295 in RslChannelNr chan_nr, uint8_t new_bts_nr)
5296{
5297 f_vty_ss_action(pt, "handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
Harald Welte261af4b2018-02-12 21:20:39 +01005298}
5299
5300/* intra-BSC hand-over between BTS0 and BTS1 */
5301private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02005302 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5303 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01005304
5305 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5306 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5307
Harald Weltea0630032018-03-20 21:09:55 +01005308 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005309 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Harald Welte261af4b2018-02-12 21:20:39 +01005310
5311 var HandoverState hs := {
5312 rr_ho_cmpl_seen := false,
5313 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02005314 old_chan_nr := -,
5315 expect_target_tsc := BTS_TSC[1]
Harald Welte261af4b2018-02-12 21:20:39 +01005316 };
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005317 /* issue hand-over command on VTY, from BTS 0 to BTS 1 */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005318 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
Harald Welte261af4b2018-02-12 21:20:39 +01005319 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
5320 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005321
5322 /* From the MGW perspective, a handover is is characterized by
5323 * performing one MDCX operation with the MGW. So we expect to see
5324 * one more MDCX during handover. */
5325 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
5326
Harald Welte261af4b2018-02-12 21:20:39 +01005327 alt {
5328 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01005329 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005330
Philipp Maier4dae0652018-11-12 12:03:26 +01005331 /* Since this is an internal handover we expect the BSC to inform the
5332 * MSC about the event */
5333 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
5334
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005335 /* Check the amount of MGCP transactions is still consistant with the
5336 * test expectation */
5337 f_check_mgcp_expectations()
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005338
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005339 var RSL_Message chan_act := f_rslem_get_last_act(RSL1_PROC, 0, g_chan_nr);
5340
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005341 /* Ensure the Channel Activation for the new channel contained the right encryption params. as_handover() set
5342 * 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 +02005343 f_verify_encr_info(chan_act);
5344
5345 f_chan_act_verify_tsc(chan_act, BTS_TSC[1]);
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005346
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01005347 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01005348}
5349
5350testcase TC_ho_int() runs on test_CT {
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02005351 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte261af4b2018-02-12 21:20:39 +01005352 var MSC_ConnHdlr vc_conn;
5353 f_init(2, true);
5354 f_sleep(1.0);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005355
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005356 pars.expect_tsc := BTS_TSC[0];
5357
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005358 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005359
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02005360 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
Harald Welte261af4b2018-02-12 21:20:39 +01005361 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005362
5363 /* from f_establish_fully() */
5364 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5365 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5366 /* from handover */
5367 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5368 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5369 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5370 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005371 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5372 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:completed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005373 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005374 f_shutdown_helper();
Harald Welte261af4b2018-02-12 21:20:39 +01005375}
Harald Weltee9e02e42018-01-31 23:36:25 +01005376
Oliver Smith7eabd312021-07-12 14:18:56 +02005377function 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 +02005378 var MSC_ConnHdlr vc_conn;
5379 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5380 pars.encr := valueof(t_EncrParams(encr_alg, f_rnd_octstring(8), f_rnd_octstring(16)));
5381
5382 f_init(2, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02005383 f_vty_encryption_a5(enc_a5);
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005384 f_sleep(1.0);
5385
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005386 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005387
5388 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
5389 vc_conn.done;
5390
5391 /* from f_establish_fully() */
5392 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5393 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5394 /* from handover */
5395 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5396 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5397 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5398 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005399 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5400 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:completed");
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005401 f_ctrs_bsc_and_bts_verify();
Oliver Smith7eabd312021-07-12 14:18:56 +02005402 f_vty_encryption_a5_reset();
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005403 f_shutdown_helper();
5404}
5405
5406testcase TC_ho_int_a5_0() runs on test_CT {
5407 f_tc_ho_int_a5('01'O);
5408}
5409
5410testcase TC_ho_int_a5_1() runs on test_CT {
5411 f_tc_ho_int_a5('02'O);
5412}
5413
5414testcase TC_ho_int_a5_3() runs on test_CT {
5415 f_tc_ho_int_a5('08'O);
5416}
5417
5418testcase TC_ho_int_a5_4() runs on test_CT {
Oliver Smith7eabd312021-07-12 14:18:56 +02005419 f_tc_ho_int_a5('10'O, "0 1 3 4");
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005420}
5421
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005422/* intra-BSC hand-over with CONNection FAILure and cause Radio Link Failure: check RR release cause */
5423private function f_tc_ho_int_radio_link_failure(charstring id) runs on MSC_ConnHdlr {
5424 g_pars := f_gen_test_hdlr_pars();
5425 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5426 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005427
5428 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5429 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5430
5431 f_establish_fully(ass_cmd, exp_compl);
5432 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
5433
5434 var HandoverState hs := {
5435 rr_ho_cmpl_seen := false,
5436 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02005437 old_chan_nr := -,
5438 expect_target_tsc := BTS_TSC[1]
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005439 };
5440 /* issue hand-over command on VTY */
5441 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
5442 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
5443 f_rslem_suspend(RSL1_PROC);
5444
5445 /* From the MGW perspective, a handover is is characterized by
5446 * performing one MDCX operation with the MGW. So we expect to see
5447 * one more MDCX during handover. */
5448 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
5449
5450 var RSL_Message rsl;
5451 var PDU_ML3_NW_MS l3;
5452 var RslChannelNr new_chan_nr;
5453 var GsmArfcn arfcn;
5454 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
5455 l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
5456 if (not ischosen(l3.msgs.rrm.handoverCommand)) {
5457 setverdict(fail, "Expected handoverCommand");
5458 mtc.stop;
5459 }
5460 }
5461 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
5462 new_chan_nr, arfcn);
5463
5464 f_rslem_register(0, new_chan_nr, RSL1_PROC);
5465
5466 /* resume processing of RSL DChan messages, which was temporarily suspended
5467 * before performing a hand-over */
5468 f_rslem_resume(RSL1_PROC);
5469 RSL1.receive(tr_RSL_IPA_CRCX(new_chan_nr));
5470
5471 f_sleep(1.0);
5472
5473 /* Handover fails because no HANDO DET appears on the new lchan,
5474 * and the old lchan reports a Radio Link Failure. */
5475 RSL.send(ts_RSL_CONN_FAIL_IND(g_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
5476
5477 var PDU_BSSAP rx_clear_request;
5478 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
5479 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5480 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5481
5482 var RR_Cause rr_cause := GSM48_RR_CAUSE_ABNORMAL_UNSPEC;
5483
5484 var MgcpCommand mgcp;
5485 interleave {
5486 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE(int2oct(enum2int(rr_cause), 1)))) {}
5487 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005488 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005489 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005490 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005491 }
5492 [] RSL1.receive(tr_RSL_DEACT_SACCH(new_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005493 [] RSL1.receive(tr_RSL_RF_CHAN_REL(new_chan_nr)) {
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005494 RSL1.send(ts_RSL_RF_CHAN_REL_ACK(new_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005495 f_rslem_unregister(0, g_chan_nr, PT := RSL1_PROC);
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005496 }
5497 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {}
5498 }
5499
5500 f_sleep(0.5);
5501 setverdict(pass);
5502}
5503testcase TC_ho_int_radio_link_failure() runs on test_CT {
5504 var MSC_ConnHdlr vc_conn;
5505 f_init(2, true);
5506 f_sleep(1.0);
5507
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005508 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005509
5510 vc_conn := f_start_handler(refers(f_tc_ho_int_radio_link_failure));
5511 vc_conn.done;
5512
5513 /* from f_establish_fully() */
5514 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5515 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5516 /* from handover */
5517 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5518 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
5519 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5520 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:stopped");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005521 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5522 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:stopped");
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005523 f_ctrs_bsc_and_bts_verify();
5524 f_shutdown_helper();
5525}
5526
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005527/* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005528private function f_expect_dlcx_conns() runs on MSC_ConnHdlr {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005529 var MgcpCommand mgcp;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005530 var template MgcpResponse mgcp_resp;
5531 var MGCP_RecvFrom mrf;
5532 var template MgcpMessage msg_resp;
5533 var template MgcpMessage msg_dlcx := {
5534 command := tr_DLCX()
5535 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005536
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005537 if (g_pars.aoip) {
5538 MGCP.receive(tr_DLCX()) -> value mgcp {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005539 log("Got first DLCX: ", mgcp);
5540 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005541 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005542
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005543 MGCP.receive(tr_DLCX()) -> value mgcp {
5544 log("Got second DLCX: ", mgcp);
5545 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
5546 };
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005547 } else {
5548 /* For SCCPLite, BSC doesn't handle the MSC-side */
5549 MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_dlcx)) -> value mrf {
5550 log("Got first DLCX: ", mrf.msg.command);
5551 msg_resp := {
5552 response := ts_DLCX_ACK2(mrf.msg.command.line.trans_id)
5553 }
5554 MGCP_MULTI.send(t_MGCP_SendToMrf(mrf, msg_resp));
5555 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005556 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005557}
5558
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005559private 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 +01005560
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005561 var NcellReports neighbor_rep := {
5562 { rxlev := 20, bcch_freq := 0, bsic := 11 }
5563 };
5564 var octetstring l3_mr := enc_GsmRrL3Message(valueof(ts_MEAS_REP(true, 8, 8, reps := neighbor_rep)));
5565 RSL.send(ts_RSL_MEAS_RES(g_chan_nr, 0, ts_RSL_IE_UplinkMeas, ts_RSL_IE_BS_Power(0), ts_RSL_IE_L1Info,
5566 l3_mr, 0));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005567
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005568 BSSAP.receive(tr_BSSMAP_HandoverRequired(exp_oldToNewBSSIEs));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005569
5570 f_sleep(0.5);
5571 /* The MSC negotiates Handover Request and Handover Request Ack with
5572 * the other BSS and comes back with a BSSMAP Handover Command
5573 * containing an RR Handover Command coming from the target BSS... */
5574
5575 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5576 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5577 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5578 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5579 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5580
5581 /* expect the Handover Command to go out on RR */
5582 var RSL_Message rsl_ho_cmd
5583 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5584 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5585 var RSL_IE_Body rsl_ho_cmd_l3;
5586 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5587 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5588 setverdict(fail);
5589 } else {
5590 log("Found L3 Info: ", rsl_ho_cmd_l3);
5591 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5592 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5593 setverdict(fail);
5594 } else {
5595 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5596 setverdict(pass);
5597 }
5598 }
5599
5600 /* When the other BSS has reported a completed handover, this side is
5601 * torn down. */
5602
5603 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
5604 var BssmapCause cause := enum2int(cause_val);
5605 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5606
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005607 f_expect_dlcx_conns();
Pau Espin Pedrol06199952021-06-15 11:30:00 +02005608
5609 interleave {
5610 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE));
5611 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr));
5612 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr));
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02005613 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
Pau Espin Pedrol06199952021-06-15 11:30:00 +02005614 }
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005615 setverdict(pass);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005616}
5617
5618private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
5619 g_pars := f_gen_test_hdlr_pars();
5620 var PDU_BSSAP ass_req := f_gen_ass_req();
5621 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5622 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5623 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5624 f_establish_fully(ass_req, exp_compl);
5625
5626 f_ho_out_of_this_bsc();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005627}
5628testcase TC_ho_out_of_this_bsc() runs on test_CT {
5629 var MSC_ConnHdlr vc_conn;
5630
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005631 f_init_vty();
5632 f_bts_0_cfg(BSCVTY,
5633 {"neighbor-list mode automatic",
5634 "handover 1",
5635 "handover algorithm 2",
5636 "handover2 window rxlev averaging 1",
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005637 "no neighbors",
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005638 "neighbor lac 99 arfcn 123 bsic any"});
5639 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5640
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005641 f_init(1, true);
5642 f_sleep(1.0);
5643
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005644 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005645
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005646 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
5647 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005648
5649 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5650 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5651 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5652 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5653 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5654 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed");
5655 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005656 f_shutdown_helper();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005657}
5658
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005659private function f_mo_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5660 template (value) RslLinkId link_id := ts_RslLinkID_DCCH(0),
Vadim Yanitskiy2ef6a2f2020-10-08 23:17:32 +07005661 template (present) OCT1 dlci := ?,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005662 octetstring l3 := '0123456789'O)
5663runs on MSC_ConnHdlr {
Neels Hofmeyr43654812020-09-25 01:35:35 +02005664 /* The old lchan and conn should still be active. See that arbitrary L3
5665 * is still going through. */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005666 rsl.send(ts_RSL_DATA_IND(g_chan_nr, link_id, l3));
Neels Hofmeyr43654812020-09-25 01:35:35 +02005667 var template PDU_BSSAP exp_data := {
5668 discriminator := '1'B,
5669 spare := '0000000'B,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005670 dlci := dlci,
5671 lengthIndicator := lengthof(l3),
Neels Hofmeyr43654812020-09-25 01:35:35 +02005672 pdu := {
5673 dtap := l3
5674 }
5675 };
5676 BSSAP.receive(exp_data);
5677 setverdict(pass);
5678}
5679
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005680private function f_mt_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5681 template (present) RslLinkId link_id := tr_RslLinkID_DCCH(0),
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005682 template (value) OCT1 dlci := '00'O,
5683 octetstring l3 := '0123456789'O)
5684runs on MSC_ConnHdlr {
5685 BSSAP.send(PDU_BSSAP:{
5686 discriminator := '1'B,
5687 spare := '0000000'B,
5688 dlci := dlci,
5689 lengthIndicator := lengthof(l3),
5690 pdu := {
5691 dtap := l3
5692 }
5693 });
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005694 rsl.receive(tr_RSL_DATA_REQ(g_chan_nr, link_id, l3));
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005695 setverdict(pass);
5696}
5697
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005698/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
5699 * simply never sends a BSSMAP Handover Command. */
5700private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005701 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005702
5703 var PDU_BSSAP ass_req := f_gen_ass_req();
5704 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5705 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5706 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5707 f_establish_fully(ass_req, exp_compl);
5708
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005709 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005710 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5711
5712 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5713
5714 /* osmo-bsc should time out 10 seconds after the handover started.
5715 * Let's give it a bit extra. */
5716 f_sleep(15.0);
5717
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005718 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005719 f_sleep(1.0);
5720}
5721testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
5722 var MSC_ConnHdlr vc_conn;
5723
5724 f_init(1, true);
5725 f_sleep(1.0);
5726
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005727 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005728
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005729 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
5730 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005731
5732 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5733 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5734 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5735 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5736 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5737 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5738 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005739 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005740}
5741
5742/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
5743 * RR Handover Failure. */
5744private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005745 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005746
5747 var PDU_BSSAP ass_req := f_gen_ass_req();
5748 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5749 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5750 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5751 f_establish_fully(ass_req, exp_compl);
5752
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005753 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005754 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5755
5756 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5757
5758 f_sleep(0.5);
5759 /* The MSC negotiates Handover Request and Handover Request Ack with
5760 * the other BSS and comes back with a BSSMAP Handover Command
5761 * containing an RR Handover Command coming from the target BSS... */
5762
5763 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5764 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5765 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5766 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5767 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5768
5769 /* expect the Handover Command to go out on RR */
5770 var RSL_Message rsl_ho_cmd
5771 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5772 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5773 var RSL_IE_Body rsl_ho_cmd_l3;
5774 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5775 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5776 setverdict(fail);
5777 } else {
5778 log("Found L3 Info: ", rsl_ho_cmd_l3);
5779 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5780 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5781 setverdict(fail);
5782 } else {
5783 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5784 setverdict(pass);
5785 }
5786 }
5787
5788 f_sleep(0.2);
5789 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
5790
5791 /* Should tell the MSC about the failure */
5792 BSSAP.receive(tr_BSSMAP_HandoverFailure);
5793
5794 f_sleep(1.0);
5795
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005796 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005797 f_sleep(1.0);
5798
5799 setverdict(pass);
5800 f_sleep(1.0);
5801}
5802testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
5803 var MSC_ConnHdlr vc_conn;
5804
5805 f_init(1, true);
5806 f_sleep(1.0);
5807
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005808 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005809
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005810 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
5811 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005812
5813 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5814 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5815 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5816 f_ctrs_bsc_and_bts_add(0, "handover:failed");
5817 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5818 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:failed");
5819 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005820 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005821}
5822
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005823/* BSC asks for inter-BSC-out HO, receives BSSMAP Handover Command, but then no reply is received about HO outcome
5824 * (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 +02005825 * and the lchan is released. */
5826private function f_tc_ho_out_fail_no_result_after_ho_cmd(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005827 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005828
5829 var PDU_BSSAP ass_req := f_gen_ass_req();
5830 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5831 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5832 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5833 f_establish_fully(ass_req, exp_compl);
5834
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005835 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005836 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5837
5838 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5839
5840 f_sleep(0.5);
5841 /* The MSC negotiates Handover Request and Handover Request Ack with
5842 * the other BSS and comes back with a BSSMAP Handover Command
5843 * containing an RR Handover Command coming from the target BSS... */
5844
5845 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5846 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5847 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5848 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5849 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5850
5851 /* expect the Handover Command to go out on RR */
5852 var RSL_Message rsl_ho_cmd
5853 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5854 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5855 var RSL_IE_Body rsl_ho_cmd_l3;
5856 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5857 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5858 setverdict(fail);
5859 } else {
5860 log("Found L3 Info: ", rsl_ho_cmd_l3);
5861 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5862 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5863 setverdict(fail);
5864 } else {
5865 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5866 setverdict(pass);
5867 }
5868 }
5869
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005870 /* We get neither success nor failure report from the remote BSS. Eventually T8 times out and we run into 3GPP
5871 * TS 48.008 3.1.5.3.3 "Abnormal Conditions": Clear Request should go to the MSC, and RR should be released
5872 * after Clear Command */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005873
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005874 var PDU_BSSAP rx_clear_request;
Neels Hofmeyre1797aa2019-07-09 19:34:04 +02005875 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
5876 log("Got BSSMAP Clear Request");
5877 /* Instruct BSC to clear channel */
5878 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5879 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5880
5881 var MgcpCommand mgcp;
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005882 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01005883 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
5884 log("Got Deact SACCH");
5885 }
Harald Welte924b6ea2019-02-04 01:05:34 +01005886 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01005887 log("Got RR Release");
5888 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005889 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005890 log("Got RF Chan Rel");
5891 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005892 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005893 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005894 }
5895
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005896 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02005897 BSSAP.receive(tr_BSSMAP_ClearComplete);
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005898
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005899 setverdict(pass);
5900 f_sleep(1.0);
5901}
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02005902testcase TC_ho_out_fail_no_result_after_ho_cmd() runs on test_CT {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005903 var MSC_ConnHdlr vc_conn;
5904
5905 f_init(1, true);
5906 f_sleep(1.0);
5907
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005908 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005909
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02005910 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_result_after_ho_cmd));
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005911 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005912
5913 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5914 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5915 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5916 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5917 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5918 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5919 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005920 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005921}
5922
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005923private 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 +01005924 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
5925 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
5926 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
5927 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
5928 * before we get started. */
5929 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
5930 f_rslem_register(0, new_chan_nr);
5931 g_chan_nr := new_chan_nr;
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02005932 var uint3_t expect_target_tsc := BTS_TSC[0];
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005933 f_sleep(1.0);
5934
5935 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
5936 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
5937 activate(as_Media());
5938
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005939 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005940 f_gen_handover_req(aoip_tla := g_pars.host_aoip_tla,
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02005941 oldToNewBSSIEs := oldToNewBSSIEs,
5942 enc := g_pars.encr)));
Harald Welte6811d102019-04-14 22:23:14 +02005943 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005944
5945 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
5946
5947 var PDU_BSSAP rx_bssap;
5948 var octetstring ho_command_str;
5949
5950 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
Pau Espin Pedrol76ba5412019-06-10 11:00:33 +02005951
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02005952 /* we're sure that the channel activation is done now, verify the parameters in it */
5953 var RSL_Message chan_act := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
5954 f_verify_encr_info(chan_act);
5955 f_chan_act_verify_tsc(chan_act, expect_target_tsc);
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02005956
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005957 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
5958 log("Received L3 Info in HO Request Ack: ", ho_command_str);
5959 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
5960 log("L3 Info in HO Request Ack is ", ho_command);
5961
5962 var GsmArfcn arfcn;
5963 var RslChannelNr actual_new_chan_nr;
5964 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
5965 actual_new_chan_nr, arfcn);
5966
5967 if (actual_new_chan_nr != new_chan_nr) {
5968 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
5969 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
5970 setverdict(fail);
5971 return;
5972 }
5973 log("Handover Command chan_nr is", actual_new_chan_nr);
5974
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02005975 var uint3_t got_tsc := rr_chan_desc_tsc(ho_command.msgs.rrm.handoverCommand.channelDescription2);
5976 if (not match(got_tsc, expect_target_tsc)) {
5977 setverdict(fail, "RR Handover Command: unexpected TSC in Channel Description: expected ",
5978 expect_target_tsc, " got ", got_tsc);
5979 mtc.stop;
5980 } else {
5981 log("handoverCommand: verified TSC = ", got_tsc);
5982 }
5983
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005984 /* Now the MSC forwards the RR Handover Command to the other BSC, which
5985 * tells the MS to handover to the new lchan. Here comes the new MS on
5986 * the new lchan with a Handover RACH: */
5987
5988 /* send handover detect */
5989
5990 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
5991
5992 BSSAP.receive(tr_BSSMAP_HandoverDetect);
5993
5994 /* send handover complete over the new channel */
5995
5996 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
5997 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
5998 enc_PDU_ML3_MS_NW(l3_tx)));
5999
6000 BSSAP.receive(tr_BSSMAP_HandoverComplete);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006001 setverdict(pass);
6002}
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006003
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006004private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006005 var template PDU_ML3_NW_MS exp_rr_rel_tmpl;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006006 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit;
6007 if (not istemplatekind(g_pars.last_used_eutran_plmn, "omit")) {
6008 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006009 }
6010 if (g_pars.exp_fast_return) {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006011 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE_CellSelectInd;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006012 } else {
6013 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006014 }
6015 f_ho_into_this_bsc(id, oldToNewBSSIEs);
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02006016 f_perform_clear(exp_rr_rel_tmpl := exp_rr_rel_tmpl);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006017 setverdict(pass);
6018}
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006019function f_tc_ho_into_this_bsc_main(TestHdlrParams pars) runs on test_CT {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006020 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006021
6022 f_init(1, true);
6023 f_sleep(1.0);
6024
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006025 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006026
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006027 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6028 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006029
6030 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
6031 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006032
6033 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6034 f_ctrs_bsc_and_bts_add(0, "handover:completed");
6035 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6036 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed");
6037 f_ctrs_bsc_and_bts_verify();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006038}
6039
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006040testcase TC_ho_into_this_bsc() runs on test_CT {
6041 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6042 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006043 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006044}
6045
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006046function f_tc_ho_into_this_bsc_a5(OCT1 encr_alg) runs on test_CT {
6047 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6048 pars.encr := valueof(t_EncrParams(encr_alg, f_rnd_octstring(8), f_rnd_octstring(16)));
6049 f_tc_ho_into_this_bsc_main(pars);
6050 f_shutdown_helper();
6051}
6052
6053testcase TC_ho_into_this_bsc_a5_0() runs on test_CT {
6054 f_tc_ho_into_this_bsc_a5('01'O);
6055}
6056
6057testcase TC_ho_into_this_bsc_a5_1() runs on test_CT {
6058 f_tc_ho_into_this_bsc_a5('02'O);
6059}
6060
6061testcase TC_ho_into_this_bsc_a5_3() runs on test_CT {
6062 f_tc_ho_into_this_bsc_a5('08'O);
6063}
6064
6065testcase TC_ho_into_this_bsc_a5_4() runs on test_CT {
6066 f_tc_ho_into_this_bsc_a5('10'O);
6067}
6068
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006069testcase TC_ho_into_this_bsc_tla_v6() runs on test_CT {
6070 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6071 pars.host_aoip_tla := "::6";
6072 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006073 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006074}
6075
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006076/* Similar to TC_ho_into_this_bsc, but when in SRVCC, HO Req contains "Old BSS
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006077 to New BSS Information" IE with "Last Used E-UTRAN PLMN Id", which, when the
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006078 channel is later released (RR CHannel Release), should trigger inclusion of
6079 IE "Cell Selection Indicator after Release of all TCH and SDCCH" with E-UTRAN
6080 neighbors. */
6081testcase TC_srvcc_eutran_to_geran() runs on test_CT {
6082 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6083 pars.last_used_eutran_plmn := '323454'O;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006084 pars.exp_fast_return := true;
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006085 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02006086
6087 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted");
6088 f_ctrs_bsc_and_bts_add(0, "srvcc:completed");
6089 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006090 f_shutdown_helper();
6091}
6092
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006093/* Same as TC_srvcc_eutran_to_geran, but test explicitly forbiding fast return
6094 on the BTS. As a result, RR Release shouldn't contain the EUTRAN neighbor
6095 list when the channel is released. */
6096testcase TC_srvcc_eutran_to_geran_forbid_fast_return() runs on test_CT {
6097 f_init_vty();
6098 f_vty_allow_srvcc_fast_return(true, 0)
6099
6100 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6101 pars.last_used_eutran_plmn := '323454'O;
6102 pars.exp_fast_return := false;
6103 f_tc_ho_into_this_bsc_main(pars);
6104 f_vty_allow_srvcc_fast_return(false, 0);
6105 f_shutdown_helper();
6106}
6107
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006108private function f_tc_srvcc_eutran_to_geran_ho_out(charstring id) runs on MSC_ConnHdlr {
6109 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs;
6110 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
6111 f_ho_into_this_bsc(id, oldToNewBSSIEs);
6112 f_ho_out_of_this_bsc(oldToNewBSSIEs);
6113 setverdict(pass);
6114}
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006115
6116private function f_tc_srvcc_eutran_to_geran_ho_out_main(boolean disable_fast_return)
6117 runs on test_CT {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006118 var MSC_ConnHdlr vc_conn;
6119 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6120
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01006121 f_init_vty();
6122 f_bts_0_cfg(BSCVTY,
6123 {"neighbor-list mode automatic",
6124 "handover 1",
6125 "handover algorithm 2",
6126 "handover2 window rxlev averaging 1",
6127 "no neighbors",
6128 "neighbor lac 99 arfcn 123 bsic any"});
6129 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6130
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006131 f_init(1, true);
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006132 if (disable_fast_return) {
6133 f_vty_allow_srvcc_fast_return(true, 0);
6134 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006135 f_sleep(1.0);
6136
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006137 f_ctrs_bsc_and_bts_handover_init();
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006138
6139 pars.last_used_eutran_plmn := '323454'O;
6140 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6141 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
6142
6143 vc_conn := f_start_handler(refers(f_tc_srvcc_eutran_to_geran_ho_out), pars);
6144 vc_conn.done;
6145
6146 f_ctrs_bsc_and_bts_add(0, "handover:attempted", 2);
6147 f_ctrs_bsc_and_bts_add(0, "handover:completed", 2);
6148 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted", 1);
6149 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed", 1);
6150 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted", 1);
6151 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed", 1);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02006152
6153 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted", 1);
6154 f_ctrs_bsc_and_bts_add(0, "srvcc:completed", 1);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006155 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006156
6157 if (disable_fast_return) {
6158 f_vty_allow_srvcc_fast_return(false, 0);
6159 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006160 f_shutdown_helper();
6161}
6162
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006163/* First, HO into BSC from EUTRAN (SRVCC): HO Request contains "Old BSS to New
6164 BSS Information" IE with "Last Used E-UTRAN PLMN Id".
6165 Second, HO to another BSC: HO Required contains "Old BSS to New BSS Information"
6166 IE with "Last Used E-UTRAN PLMN Id" from first step. */
6167testcase TC_srvcc_eutran_to_geran_ho_out() runs on test_CT {
6168 f_tc_srvcc_eutran_to_geran_ho_out_main(false);
6169}
6170/* Validate subsequent intra-GSM-HO works the same (with OldBSSToNewBSSInfo IE)
6171 * independently of fast-reture allowed/forbidden in local BTS */
6172testcase TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() runs on test_CT {
6173 f_tc_srvcc_eutran_to_geran_ho_out_main(true);
6174}
6175
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006176private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
6177 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6178 f_rslem_register(0, new_chan_nr);
6179 g_chan_nr := new_chan_nr;
6180 f_sleep(1.0);
6181
6182 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6183 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6184 activate(as_Media());
6185
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006186 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006187 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006188 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006189
6190 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6191
6192 var PDU_BSSAP rx_bssap;
6193 var octetstring ho_command_str;
6194
6195 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6196
6197 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6198 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6199 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6200 log("L3 Info in HO Request Ack is ", ho_command);
6201
6202 var GsmArfcn arfcn;
6203 var RslChannelNr actual_new_chan_nr;
6204 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6205 actual_new_chan_nr, arfcn);
6206
6207 if (actual_new_chan_nr != new_chan_nr) {
6208 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6209 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6210 setverdict(fail);
6211 return;
6212 }
6213 log("Handover Command chan_nr is", actual_new_chan_nr);
6214
Neels Hofmeyr61ca08d2019-05-06 23:52:22 +02006215 /* For deterministic test results, give some time for the MGW endpoint to be configured */
6216 f_sleep(1.0);
6217
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006218 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6219 * tells the MS to handover to the new lchan. In this case, the MS
6220 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
6221 * Handover Failure to the MSC. The procedure according to 3GPP TS
6222 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
6223 * BSSMAP Clear Command: */
6224
6225 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6226 var BssmapCause cause := enum2int(cause_val);
6227 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6228
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006229 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006230 BSSAP.receive(tr_BSSMAP_ClearComplete);
6231
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006232 setverdict(pass);
6233 f_sleep(1.0);
6234
6235 setverdict(pass);
6236}
6237testcase TC_ho_in_fail_msc_clears() runs on test_CT {
6238 var MSC_ConnHdlr vc_conn;
6239 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6240
6241 f_init(1, true);
6242 f_sleep(1.0);
6243
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006244 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006245
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006246 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6247 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006248
6249 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
6250 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006251
6252 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6253 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
6254 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6255 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
6256 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006257 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006258}
6259
6260private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
6261 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
6262 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
6263 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
6264 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
6265 * before we get started. */
6266 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6267 f_rslem_register(0, new_chan_nr);
6268 g_chan_nr := new_chan_nr;
6269 f_sleep(1.0);
6270
6271 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6272 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6273 activate(as_Media());
6274
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006275 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006276 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006277 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006278
6279 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6280
6281 var PDU_BSSAP rx_bssap;
6282 var octetstring ho_command_str;
6283
6284 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6285
6286 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6287 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6288 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6289 log("L3 Info in HO Request Ack is ", ho_command);
6290
6291 var GsmArfcn arfcn;
6292 var RslChannelNr actual_new_chan_nr;
6293 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6294 actual_new_chan_nr, arfcn);
6295
6296 if (actual_new_chan_nr != new_chan_nr) {
6297 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6298 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6299 setverdict(fail);
6300 return;
6301 }
6302 log("Handover Command chan_nr is", actual_new_chan_nr);
6303
6304 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6305 * tells the MS to handover to the new lchan. Here comes the new MS on
6306 * the new lchan with a Handover RACH: */
6307
6308 /* send handover detect */
6309
6310 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
6311
6312 BSSAP.receive(tr_BSSMAP_HandoverDetect);
6313
6314 /* The MSC chooses to clear the connection now, maybe we got the
6315 * Handover RACH on the new cell but the MS still signaled Handover
6316 * Failure to the old BSS? */
6317
6318 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6319 var BssmapCause cause := enum2int(cause_val);
6320 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6321
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006322 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006323 BSSAP.receive(tr_BSSMAP_ClearComplete);
6324
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006325 f_sleep(1.0);
6326}
6327testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
6328 var MSC_ConnHdlr vc_conn;
6329 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6330
6331 f_init(1, true);
6332 f_sleep(1.0);
6333
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006334 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006335
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006336 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6337 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006338
6339 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
6340 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006341
6342 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6343 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
6344 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6345 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
6346 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006347 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006348}
6349
6350/* The new BSS's lchan times out before the MSC decides that handover failed. */
6351private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
6352 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6353 f_rslem_register(0, new_chan_nr);
6354 g_chan_nr := new_chan_nr;
6355 f_sleep(1.0);
6356
6357 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6358 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6359 activate(as_Media());
6360
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006361 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006362 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006363 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006364
6365 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6366
6367 var PDU_BSSAP rx_bssap;
6368 var octetstring ho_command_str;
6369
6370 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6371
6372 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6373 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6374 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6375 log("L3 Info in HO Request Ack is ", ho_command);
6376
6377 var GsmArfcn arfcn;
6378 var RslChannelNr actual_new_chan_nr;
6379 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6380 actual_new_chan_nr, arfcn);
6381
6382 if (actual_new_chan_nr != new_chan_nr) {
6383 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6384 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6385 setverdict(fail);
6386 return;
6387 }
6388 log("Handover Command chan_nr is", actual_new_chan_nr);
6389
6390 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6391 * tells the MS to handover to the new lchan. But the MS never shows up
6392 * on the new lchan. */
6393
6394 BSSAP.receive(tr_BSSMAP_HandoverFailure);
6395
6396 /* Did osmo-bsc also send a Clear Request? */
6397 timer T := 0.5;
6398 T.start;
6399 alt {
6400 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
6401 [] T.timeout { }
6402 }
6403
6404 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
6405 * asked for it, this is a Handover Failure after all). */
6406
6407 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6408 var BssmapCause cause := enum2int(cause_val);
6409 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6410
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006411 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006412 BSSAP.receive(tr_BSSMAP_ClearComplete);
6413
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006414 f_sleep(1.0);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006415}
6416testcase TC_ho_in_fail_no_detect() runs on test_CT {
6417 var MSC_ConnHdlr vc_conn;
6418 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6419
6420 f_init(1, true);
6421 f_sleep(1.0);
6422
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006423 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006424
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006425 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6426 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006427
6428 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
6429 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006430
6431 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6432 f_ctrs_bsc_and_bts_add(0, "handover:error");
6433 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6434 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
6435 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006436 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006437}
6438
6439/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
6440private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
6441 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6442 f_rslem_register(0, new_chan_nr);
6443 g_chan_nr := new_chan_nr;
6444 f_sleep(1.0);
6445
6446 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6447 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6448 activate(as_Media());
6449
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006450 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006451 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006452 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006453
6454 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6455
6456 var PDU_BSSAP rx_bssap;
6457 var octetstring ho_command_str;
6458
6459 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6460
6461 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6462 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6463 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6464 log("L3 Info in HO Request Ack is ", ho_command);
6465
6466 var GsmArfcn arfcn;
6467 var RslChannelNr actual_new_chan_nr;
6468 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6469 actual_new_chan_nr, arfcn);
6470
6471 if (actual_new_chan_nr != new_chan_nr) {
6472 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6473 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6474 setverdict(fail);
6475 return;
6476 }
6477 log("Handover Command chan_nr is", actual_new_chan_nr);
6478
6479 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6480 * tells the MS to handover to the new lchan. But the MS never shows up
6481 * on the new lchan. */
6482
6483 BSSAP.receive(tr_BSSMAP_HandoverFailure);
6484
6485 /* MSC plays dumb and sends no Clear Command */
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006486 var PDU_BSSAP rx_clear_request;
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02006487
6488 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006489 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
6490 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6491 };
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006492 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006493 BSSAP.receive(tr_BSSMAP_ClearComplete);
6494
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006495 f_sleep(1.0);
6496}
6497testcase TC_ho_in_fail_no_detect2() runs on test_CT {
6498 var MSC_ConnHdlr vc_conn;
6499 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6500
6501 f_init(1, true);
6502 f_sleep(1.0);
6503
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006504 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006505
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006506 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6507 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006508
6509 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
6510 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006511
6512 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6513 f_ctrs_bsc_and_bts_add(0, "handover:error");
6514 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6515 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
6516 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006517 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006518}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006519
Neels Hofmeyr91401012019-07-11 00:42:35 +02006520type record of charstring Commands;
6521
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006522private function f_bts_0_cfg(TELNETasp_PT pt, Commands cmds := {})
Neels Hofmeyr91401012019-07-11 00:42:35 +02006523{
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006524 f_vty_enter_cfg_bts(pt, 0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006525 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006526 f_vty_transceive(pt, cmds[i]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006527 }
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006528 f_vty_transceive(pt, "end");
Neels Hofmeyr91401012019-07-11 00:42:35 +02006529}
6530
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01006531private function f_cs7_inst_0_cfg(TELNETasp_PT pt, Commands cmds := {})
6532{
6533 f_vty_enter_cfg_cs7_inst(pt, 0);
6534 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
6535 f_vty_transceive(pt, cmds[i]);
6536 }
6537 f_vty_transceive(pt, "end");
6538}
6539
Neels Hofmeyr91401012019-07-11 00:42:35 +02006540private function f_probe_for_handover(charstring log_label,
6541 charstring log_descr,
6542 charstring handover_vty_cmd,
6543 boolean expect_handover,
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006544 boolean is_inter_bsc_handover := false,
6545 template uint3_t expect_target_tsc := ?)
Neels Hofmeyr91401012019-07-11 00:42:35 +02006546runs on MSC_ConnHdlr
6547{
Neels Hofmeyrb3fc8982020-05-11 00:16:42 +02006548 /* We're going to thwart any and all handover attempts, just be ready to handle (and ignore) handover target
6549 * lchans to be established on bts 1 or bts 2. */
6550 f_rslem_suspend(RSL1_PROC);
6551 f_rslem_suspend(RSL2_PROC);
6552
Neels Hofmeyr91401012019-07-11 00:42:35 +02006553 var RSL_Message rsl;
6554
6555 var charstring log_msg := " (expecting handover)"
6556 if (not expect_handover) {
6557 log_msg := " (expecting NO handover)";
6558 }
6559 log("f_probe_for_handover starting: " & log_label & ": " & log_descr & log_msg);
6560 f_vty_transceive(BSCVTY, handover_vty_cmd);
6561
Neels Hofmeyr91401012019-07-11 00:42:35 +02006562 timer T := 2.0;
6563 T.start;
6564
6565 alt {
6566 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
6567 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
6568 log("Rx L3 from net: ", l3);
6569 if (ischosen(l3.msgs.rrm.handoverCommand)) {
6570 var RslChannelNr new_chan_nr;
6571 var GsmArfcn arfcn;
6572 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
6573 new_chan_nr, arfcn);
6574 log("Handover to new chan ", new_chan_nr, " on ARFCN ", arfcn);
6575 log(l3.msgs.rrm.handoverCommand);
6576
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006577 /* Verify correct TSC in handoverCommand */
6578 var uint3_t got_tsc := rr_chan_desc_tsc(l3.msgs.rrm.handoverCommand.channelDescription2);
6579 if (not match(got_tsc, expect_target_tsc)) {
6580 setverdict(fail, "RR Handover Command: unexpected TSC in Channel Description: expected ",
6581 expect_target_tsc, " got ", got_tsc);
6582 mtc.stop;
6583 } else {
6584 log("handoverCommand: verified TSC = ", got_tsc, " (matches ",
6585 expect_target_tsc, ")");
6586 }
6587
Neels Hofmeyr91401012019-07-11 00:42:35 +02006588 /* Need to register for new lchan on new BTS -- it's either bts 1 or bts 2. It doesn't really
6589 * matter on which BTS it really is, we're not going to follow through an entire handover
6590 * anyway. */
6591 f_rslem_register(0, new_chan_nr, RSL1_PROC);
6592 f_rslem_resume(RSL1_PROC);
6593 f_rslem_register(0, new_chan_nr, RSL2_PROC);
6594 f_rslem_resume(RSL2_PROC);
6595
6596 if (expect_handover and not is_inter_bsc_handover) {
6597 setverdict(pass);
6598 log("f_probe_for_handover(" & log_label & "): Got RSL Handover Command as expected.");
6599 } else {
6600 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got RSL Handover Command. "
6601 & log_label & ": " & log_descr);
6602 }
6603
6604 log("f_probe_for_handover(" & log_label & "): Ending the test: Handover Failure stops the procedure.");
6605 /* osmo-bsc has triggered Handover. That's all we need to know for this test, reply with
6606 * Handover Failure. */
6607 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
6608
6609 /* target BTS is told to release lchan again; don't care which BTS nor what messages. */
6610 f_sleep(0.5);
6611 RSL1.clear;
6612 RSL2.clear;
6613 log("f_probe_for_handover(" & log_label & "): done (got RSL Handover Command)");
6614 break;
6615 } else {
6616 repeat;
6617 }
6618 }
6619 [] BSSAP.receive(tr_BSSMAP_HandoverRequired) {
6620 if (expect_handover and is_inter_bsc_handover) {
6621 setverdict(pass);
6622 log("f_probe_for_handover(" & log_label & "): Got BSSMAP Handover Required as expected.");
6623 } else {
6624 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got BSSMAP Handover Required. "
6625 & log_label & ": " & log_descr);
6626 }
6627
6628 log("f_probe_for_handover(" & log_label & "): done (got BSSMAP Handover Required)");
6629
6630 /* Note: f_tc_ho_neighbor_config_start() sets T7, the timeout for BSSMAP Handover Required, to
6631 * 1 second. There is no legal way to quickly abort a handover after a BSSMAP Handover Required,
6632 * setting a short timeout and waiting is the only way. */
6633 log("f_probe_for_handover(" & log_label & "): waiting for inter-BSC HO to time out...");
6634 f_sleep(1.5);
6635 log("f_probe_for_handover(" & log_label & "): ...done");
6636
6637 break;
6638 }
6639 [] T.timeout {
6640 if (expect_handover) {
6641 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected Handover, but got none. "
6642 & log_label & ": " & log_descr);
6643 } else {
6644 setverdict(pass);
6645 log("f_probe_for_handover(" & log_label & "): Got no Handover, as expected.");
6646 }
6647 log("f_probe_for_handover(" & log_label & "): done (got no Handover)");
6648 break;
6649 }
6650 }
6651
6652 f_rslem_resume(RSL1_PROC);
6653 f_rslem_resume(RSL2_PROC);
6654 f_sleep(3.0);
6655 RSL.clear;
6656
6657 log("f_probe_for_handover(" & log_label & "): done clearing");
6658}
6659
6660/* Test the effect of various neighbor configuration scenarios:
6661 *
6662 * To avoid complexity, block off any actual handover operation, and always remain on the lchan at bts 0.
6663 * Reconfigure the neighbors for bts 0, trigger a Handover, and probe whether osmo-bsc does or doesn't start HO.
6664 */
6665private function f_tc_ho_neighbor_config_start() runs on MSC_ConnHdlr {
6666 g_pars := f_gen_test_hdlr_pars();
6667 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
6668 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006669
6670 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
6671 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
6672
6673 /* Establish lchan at bts 0 */
6674 f_establish_fully(ass_cmd, exp_compl);
6675
6676 /* Shorten the inter-BSC Handover timeout, to not wait so long for inter-BSC Handovers */
6677 f_vty_enter_cfg_network(BSCVTY);
6678 f_vty_transceive(BSCVTY, "timer T7 1");
6679 f_vty_transceive(BSCVTY, "end");
6680}
6681
6682private function f_tc_ho_neighbor_config_1(charstring id) runs on MSC_ConnHdlr {
6683 f_tc_ho_neighbor_config_start();
6684
6685 /*
6686 * bts 0 ARFCN 871 BSIC 10
6687 * bts 1 ARFCN 871 BSIC 11
6688 * bts 2 ARFCN 871 BSIC 12
6689 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6690 */
6691
6692 log("f_tc_ho_neighbor_config: 1. No 'neighbor' config");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006693 f_bts_0_cfg(BSCVTY, {"no neighbors"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006694 f_probe_for_handover("1.a", "HO to bts 1 works, implicitly listed as neighbor (legacy behavior when none are configured)",
6695 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006696 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006697
6698 f_probe_for_handover("1.b", "HO to unknown cell does not start",
6699 "handover any to arfcn 13 bsic 39",
6700 false);
6701
6702 f_probe_for_handover("1.c", "HO to 871-12 is ambiguous = error",
6703 "handover any to arfcn 871 bsic 12",
6704 false);
6705
6706 f_probe_for_handover("1.d", "HO to 871-11 still works (verify that this test properly cleans up)",
6707 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006708 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006709}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006710testcase TC_ho_neighbor_config_1() runs on test_CT {
6711 var MSC_ConnHdlr vc_conn;
6712 f_init(3, true, guard_timeout := 60.0);
6713 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006714 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006715 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_1));
6716 vc_conn.done;
6717
6718 /* f_tc_ho_neighbor_config_start() */
6719 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6720 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6721
6722 /* 1.a */
6723 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6724 * handover quickly by sending a Handover Failure message. */
6725 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6726 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6727 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6728 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006729 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6730 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006731
6732 /* 1.b */
6733 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6734 f_ctrs_bsc_and_bts_add(0, "handover:error");
6735
6736 /* 1.c */
6737 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6738 f_ctrs_bsc_and_bts_add(0, "handover:error");
6739
6740 /* 1.d */
6741 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6742 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6743 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6744 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006745 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6746 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006747
6748 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006749 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006750}
6751
Neels Hofmeyr91401012019-07-11 00:42:35 +02006752private function f_tc_ho_neighbor_config_2(charstring id) runs on MSC_ConnHdlr {
6753 f_tc_ho_neighbor_config_start();
6754
6755 /*
6756 * bts 0 ARFCN 871 BSIC 10
6757 * bts 1 ARFCN 871 BSIC 11
6758 * bts 2 ARFCN 871 BSIC 12
6759 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6760 */
6761
6762 log("f_tc_ho_neighbor_config: 2. explicit local neighbor: 'neighbor bts 1'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006763 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006764 f_sleep(0.5);
6765
6766 f_probe_for_handover("2.a", "HO to bts 1 works, explicitly listed as neighbor",
6767 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006768 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006769
6770 f_probe_for_handover("2.b", "HO to bts 2 doesn't work, not listed as neighbor",
6771 "handover any to arfcn 871 bsic 12",
6772 false);
6773}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006774testcase TC_ho_neighbor_config_2() runs on test_CT {
6775 var MSC_ConnHdlr vc_conn;
6776 f_init(3, true, guard_timeout := 50.0);
6777 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006778 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006779 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_2));
6780 vc_conn.done;
6781
6782 /* f_tc_ho_neighbor_config_start() */
6783 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6784 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6785
6786 /* 2.a */
6787 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6788 * handover quickly by sending a Handover Failure message. */
6789 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6790 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6791 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6792 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006793 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6794 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006795
6796 /* 2.b */
6797 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6798 f_ctrs_bsc_and_bts_add(0, "handover:error");
6799
6800 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006801 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006802}
6803
Neels Hofmeyr91401012019-07-11 00:42:35 +02006804private function f_tc_ho_neighbor_config_3(charstring id) runs on MSC_ConnHdlr {
6805 f_tc_ho_neighbor_config_start();
6806
6807 /*
6808 * bts 0 ARFCN 871 BSIC 10
6809 * bts 1 ARFCN 871 BSIC 11
6810 * bts 2 ARFCN 871 BSIC 12
6811 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6812 */
6813
6814 log("f_tc_ho_neighbor_config: 3. explicit local neighbor: 'neighbor bts 2'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006815 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006816 f_sleep(0.5);
6817
6818 f_probe_for_handover("3.a", "HO to bts 1 doesn't work, not listed as neighbor",
6819 "handover any to arfcn 871 bsic 11",
6820 false);
6821 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",
6822 "handover any to arfcn 871 bsic 12",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006823 true, expect_target_tsc := BTS_TSC[2]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006824}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006825testcase TC_ho_neighbor_config_3() runs on test_CT {
6826 var MSC_ConnHdlr vc_conn;
6827 f_init(3, true, guard_timeout := 50.0);
6828 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006829 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006830 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_3));
6831 vc_conn.done;
6832
6833 /* f_tc_ho_neighbor_config_start() */
6834 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6835 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6836
6837 /* 3.a */
6838 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6839 f_ctrs_bsc_and_bts_add(0, "handover:error");
6840
6841 /* 3.b */
6842 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6843 * handover quickly by sending a Handover Failure message. */
6844 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6845 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6846 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6847 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006848 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:attempted");
6849 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006850
6851 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006852 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006853}
6854
Neels Hofmeyr91401012019-07-11 00:42:35 +02006855private function f_tc_ho_neighbor_config_4(charstring id) runs on MSC_ConnHdlr {
6856 f_tc_ho_neighbor_config_start();
6857
6858 /*
6859 * bts 0 ARFCN 871 BSIC 10
6860 * bts 1 ARFCN 871 BSIC 11
6861 * bts 2 ARFCN 871 BSIC 12
6862 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6863 */
6864
6865 log("f_tc_ho_neighbor_config: 4. explicit remote neighbor: 'neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006866 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006867 f_sleep(0.5);
6868
6869 f_probe_for_handover("4.a", "HO to bts 1 doesn't work, not listed as neighbor",
6870 "handover any to arfcn 871 bsic 11",
6871 false);
6872 f_probe_for_handover("4.b", "HO to bts 2 doesn't work, not listed as neighbor",
6873 "handover any to arfcn 871 bsic 12",
6874 false);
6875 f_probe_for_handover("4.c", "HO to 123-45 triggers inter-BSC HO",
6876 "handover any to arfcn 123 bsic 45",
6877 true, true);
6878}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006879testcase TC_ho_neighbor_config_4() runs on test_CT {
6880 var MSC_ConnHdlr vc_conn;
6881 f_init(3, true, guard_timeout := 50.0);
6882 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006883 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006884 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_4));
6885 vc_conn.done;
6886
6887 /* f_tc_ho_neighbor_config_start() */
6888 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6889 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6890
6891 /* 4.a */
6892 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6893 f_ctrs_bsc_and_bts_add(0, "handover:error");
6894
6895 /* 4.b */
6896 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6897 f_ctrs_bsc_and_bts_add(0, "handover:error");
6898
6899 /* 4.c */
6900 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6901 * handover quickly by timing out after the Handover Required message */
6902 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6903 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
6904 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
6905 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
6906
6907 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006908 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006909}
6910
Neels Hofmeyr91401012019-07-11 00:42:35 +02006911private function f_tc_ho_neighbor_config_5(charstring id) runs on MSC_ConnHdlr {
6912 f_tc_ho_neighbor_config_start();
6913
6914 /*
6915 * bts 0 ARFCN 871 BSIC 10
6916 * bts 1 ARFCN 871 BSIC 11
6917 * bts 2 ARFCN 871 BSIC 12
6918 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6919 */
6920
6921 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 +02006922 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006923 f_sleep(0.5);
6924
6925 f_probe_for_handover("5.a", "HO to 871-12 triggers inter-BSC HO (ignoring local cells with same ARFCN+BSIC)",
6926 "handover any to arfcn 871 bsic 12",
6927 true, true);
6928}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006929testcase TC_ho_neighbor_config_5() runs on test_CT {
6930 var MSC_ConnHdlr vc_conn;
6931 f_init(3, true);
6932 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006933 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006934 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_5));
6935 vc_conn.done;
6936
6937 /* f_tc_ho_neighbor_config_start() */
6938 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6939 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6940
6941 /* 5 */
6942 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6943 * handover quickly by timing out after the Handover Required message */
6944 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6945 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
6946 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
6947 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
6948
6949 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006950 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006951}
6952
Neels Hofmeyr91401012019-07-11 00:42:35 +02006953private function f_tc_ho_neighbor_config_6(charstring id) runs on MSC_ConnHdlr {
6954 f_tc_ho_neighbor_config_start();
6955
6956 /*
6957 * bts 0 ARFCN 871 BSIC 10
6958 * bts 1 ARFCN 871 BSIC 11
6959 * bts 2 ARFCN 871 BSIC 12
6960 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6961 */
6962
6963 log("f_tc_ho_neighbor_config: 6. config error: explicit local and remote neighbors with ambiguous ARFCN+BSIC:"
6964 & " 'neighbor bts 2; neighbor lac 99 arfcn 871 bsic 12'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006965 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006966 f_sleep(0.5);
6967
6968 f_probe_for_handover("6.a", "HO to 871-12 is ambiguous = error",
6969 "handover any to arfcn 871 bsic 12",
6970 false);
6971}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006972testcase TC_ho_neighbor_config_6() runs on test_CT {
6973 var MSC_ConnHdlr vc_conn;
6974 f_init(3, true);
6975 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006976 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006977 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_6));
6978 vc_conn.done;
6979
6980 /* f_tc_ho_neighbor_config_start() */
6981 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6982 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6983
6984 /* 6.a */
6985 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6986 * handover quickly by timing out after the Handover Required message */
6987 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6988 f_ctrs_bsc_and_bts_add(0, "handover:error");
6989
6990 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006991 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006992}
6993
Neels Hofmeyr91401012019-07-11 00:42:35 +02006994private function f_tc_ho_neighbor_config_7(charstring id) runs on MSC_ConnHdlr {
6995 f_tc_ho_neighbor_config_start();
6996
6997 /*
6998 * bts 0 ARFCN 871 BSIC 10
6999 * bts 1 ARFCN 871 BSIC 11
7000 * bts 2 ARFCN 871 BSIC 12
7001 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7002 */
7003
7004 log("f_tc_ho_neighbor_config: 7. explicit local and remote neighbors:"
7005 & " 'neighbor bts 2; neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007006 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007007 f_sleep(0.5);
7008
7009 f_probe_for_handover("7.a", "HO to 871-12 does HO to bts 2",
7010 "handover any to arfcn 871 bsic 12",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02007011 true, expect_target_tsc := BTS_TSC[2]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02007012 f_probe_for_handover("7.b", "HO to 123-45 triggers inter-BSC HO",
7013 "handover any to arfcn 123 bsic 45",
7014 true, true);
7015}
Neels Hofmeyr91401012019-07-11 00:42:35 +02007016testcase TC_ho_neighbor_config_7() runs on test_CT {
7017 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf2b88032020-06-16 00:35:04 +02007018 f_init(3, true, guard_timeout := 50.0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02007019 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007020 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007021 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_7));
7022 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007023
7024 /* f_tc_ho_neighbor_config_start() */
7025 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7026 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7027
7028 /* 7.a */
7029 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
7030 * handover quickly by sending a Handover Failure message. */
7031 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7032 f_ctrs_bsc_and_bts_add(0, "handover:failed");
7033 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
7034 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007035 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:attempted");
7036 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007037
7038 /* 7.b */
7039 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7040 * handover quickly by timing out after the Handover Required message */
7041 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7042 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
7043 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
7044 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
7045
7046 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007047 f_shutdown_helper();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007048}
7049
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007050/* OS#3041: Open and close N connections in a normal fashion, and expect no
7051 * BSSMAP Reset just because of that. */
7052testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
7053 var default d;
7054 var integer i;
7055 var DchanTuple dt;
7056
7057 f_init();
7058
7059 /* Wait for initial BSSMAP Reset to pass */
7060 f_sleep(4.0);
7061
7062 d := activate(no_bssmap_reset());
7063
7064 /* Setup up a number of connections and RLSD them again from the MSC
7065 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7066 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02007067 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007068 /* Since we're doing a lot of runs, give each one a fresh
7069 * T_guard from the top. */
7070 T_guard.start;
7071
7072 /* Setup a BSSAP connection and clear it right away. This is
7073 * the MSC telling the BSC about a planned release, it's not an
7074 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02007075 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007076
7077 /* MSC disconnects (RLSD). */
7078 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
7079 }
7080
7081 /* In the buggy behavior, a timeout of 2 seconds happens between above
7082 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7083 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7084 f_sleep(4.0);
7085
7086 deactivate(d);
7087 f_shutdown_helper();
7088}
Harald Welte552620d2017-12-16 23:21:36 +01007089
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007090/* OS#3041: Open and close N connections in a normal fashion, and expect no
7091 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
7092 * the MSC. */
7093testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
7094 var default d;
7095 var integer i;
7096 var DchanTuple dt;
7097 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007098 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
7099 var BssmapCause cause := enum2int(cause_val);
7100
7101 f_init();
7102
7103 /* Wait for initial BSSMAP Reset to pass */
7104 f_sleep(4.0);
7105
7106 d := activate(no_bssmap_reset());
7107
7108 /* Setup up a number of connections and RLSD them again from the MSC
7109 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7110 * Let's do it some more times for good measure. */
7111 for (i := 0; i < 8; i := i+1) {
7112 /* Since we're doing a lot of runs, give each one a fresh
7113 * T_guard from the top. */
7114 T_guard.start;
7115
7116 /* Setup a BSSAP connection and clear it right away. This is
7117 * the MSC telling the BSC about a planned release, it's not an
7118 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02007119 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007120
7121 /* Instruct BSC to clear channel */
7122 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7123
7124 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02007125 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007126 }
7127
7128 /* In the buggy behavior, a timeout of 2 seconds happens between above
7129 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7130 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7131 f_sleep(4.0);
7132
7133 deactivate(d);
7134 f_shutdown_helper();
7135}
7136
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007137/* OS#3041: Open and close N connections in a normal fashion, and expect no
7138 * BSSMAP Reset just because of that. Close connections from the MS side with a
7139 * Release Ind on RSL. */
7140testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
7141 var default d;
7142 var integer i;
7143 var DchanTuple dt;
7144 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007145 var integer j;
7146
7147 f_init();
7148
7149 /* Wait for initial BSSMAP Reset to pass */
7150 f_sleep(4.0);
7151
7152 d := activate(no_bssmap_reset());
7153
7154 /* Setup up a number of connections and RLSD them again from the MSC
7155 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7156 * Let's do it some more times for good measure. */
7157 for (i := 0; i < 8; i := i+1) {
7158 /* Since we're doing a lot of runs, give each one a fresh
7159 * T_guard from the top. */
7160 T_guard.start;
7161
7162 /* Setup a BSSAP connection and clear it right away. This is
7163 * the MSC telling the BSC about a planned release, it's not an
7164 * erratic loss of a connection. */
7165 dt := f_est_dchan('23'O, 23, '00010203040506'O);
7166
7167 /* simulate RLL REL IND */
7168 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
7169
7170 /* expect Clear Request on MSC side */
7171 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
7172
7173 /* Instruct BSC to clear channel */
7174 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
7175 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7176
7177 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02007178 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007179 }
7180
7181 /* In the buggy behavior, a timeout of 2 seconds happens between above
7182 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7183 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7184 f_sleep(4.0);
7185
7186 deactivate(d);
7187 f_shutdown_helper();
7188}
7189
Harald Welte94e0c342018-04-07 11:33:23 +02007190/***********************************************************************
7191 * IPA style dynamic PDCH
7192 ***********************************************************************/
7193
7194private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
7195 template (omit) RSL_Cause nack := omit)
7196runs on test_CT {
7197 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
7198 var RSL_Message rsl_unused;
7199 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
7200 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
7201 /* expect the BSC to issue the related RSL command */
7202 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7203 if (istemplatekind(nack, "omit")) {
7204 /* respond with a related acknowledgement */
7205 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7206 } else {
7207 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
7208 }
7209}
7210
7211private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
7212 template (omit) RSL_Cause nack := omit)
7213runs on test_CT {
7214 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
7215 var RSL_Message rsl_unused;
7216 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
7217 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
7218 /* expect the BSC to issue the related RSL command */
7219 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
7220 if (istemplatekind(nack, "omit")) {
7221 /* respond with a related acknowledgement */
7222 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
7223 } else {
7224 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
7225 }
7226}
7227
7228private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
7229runs on test_CT return charstring {
7230 var charstring cmd, resp;
7231 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01007232 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02007233}
7234
7235private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
7236 template charstring exp)
7237runs on test_CT {
7238 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
7239 if (not match(mode, exp)) {
7240 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02007241 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02007242 }
7243}
7244
7245private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
7246runs on test_CT {
7247 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
7248 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
7249 f_vty_transceive(BSCVTY, "end");
7250}
7251
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007252
7253private function f_ts_reset_chcomb(integer bts_nr) runs on test_CT {
7254 var integer i;
7255 for (i := 0; i < 8; i := i + 1) {
7256 f_ts_set_chcomb(bts_nr, 0, i, phys_chan_config[i]);
7257 }
7258}
7259
Harald Welte94e0c342018-04-07 11:33:23 +02007260private const charstring TCHF_MODE := "TCH/F mode";
7261private const charstring TCHH_MODE := "TCH/H mode";
7262private const charstring PDCH_MODE := "PDCH mode";
7263private const charstring NONE_MODE := "NONE mode";
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007264private const charstring SDCCH8_MODE := "SDCCH8 mode";
Harald Welte94e0c342018-04-07 11:33:23 +02007265
7266/* Test IPA PDCH activation / deactivation triggered by VTY */
7267testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
7268 var RSL_Message rsl_unused;
7269
7270 /* change Timeslot 6 before f_init() starts RSL */
7271 f_init_vty();
7272 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
7273 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7274
7275 f_init(1, false);
7276 f_sleep(1.0);
7277
7278 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
7279
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007280 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007281 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7282 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7283 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7284 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7285 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007286 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007287 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7288
7289 /* De-activate it via VTY */
7290 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7291 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007292 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007293 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7294
7295 /* re-activate it via VTY */
7296 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
7297 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007298 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007299 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7300
7301 /* and finally de-activate it again */
7302 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7303 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007304 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007305 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7306
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007307 /* clean up config */
7308 f_ts_set_chcomb(0, 0, 6, "PDCH");
7309
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007310 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007311}
7312
7313/* Test IPA PDCH activation NACK */
7314testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
7315 var RSL_Message rsl_unused;
7316
7317 /* change Timeslot 6 before f_init() starts RSL */
7318 f_init_vty();
7319 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
7320 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7321
7322 f_init(1, false);
7323 f_sleep(1.0);
7324
7325 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
7326
7327 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7328 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7329 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7330 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7331 f_sleep(1.0);
7332 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7333
7334 /* De-activate it via VTY */
7335 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7336 f_sleep(1.0);
7337 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7338
7339 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
7340 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
7341 f_sleep(1.0);
7342 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7343
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007344 /* clean up config */
7345 f_ts_set_chcomb(0, 0, 6, "PDCH");
7346
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007347 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007348}
7349
7350
7351/***********************************************************************
7352 * Osmocom style dynamic PDCH
7353 ***********************************************************************/
7354
7355private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
7356 template (omit) RSL_Cause nack := omit)
7357runs on test_CT {
7358 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
7359 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02007360 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02007361 /* FIXME: no VTY command to activate Osmocom PDCH !! */
7362 /* expect the BSC to issue the related RSL command */
7363 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
7364 if (istemplatekind(nack, "omit")) {
7365 /* respond with a related acknowledgement */
7366 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7367 } else {
7368 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
7369 }
7370}
7371
7372private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
7373 template (omit) RSL_Cause nack := omit)
7374runs on test_CT {
7375 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
7376 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02007377 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02007378 /* FIXME: no VTY command to activate Osmocom PDCH !! */
7379 /* expect the BSC to issue the related RSL command */
7380 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
7381 if (istemplatekind(nack, "omit")) {
7382 /* respond with a related acknowledgement */
7383 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
7384 } else {
7385 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
7386 }
7387}
7388
7389/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
7390testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
7391 var RSL_Message rsl_unused;
7392
7393 /* change Timeslot 6 before f_init() starts RSL */
7394 f_init_vty();
7395 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
7396 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7397
7398 f_init(1, false);
7399 f_sleep(1.0);
7400
7401 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
7402
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007403 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007404 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7405 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007406 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Harald Welte94e0c342018-04-07 11:33:23 +02007407
7408 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7409 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007410 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 +02007411 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7412
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007413 /* clean up config */
7414 f_ts_set_chcomb(0, 0, 6, "PDCH");
7415
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007416 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007417}
7418
7419/* Test Osmocom dyn PDCH activation NACK behavior */
7420testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
7421 var RSL_Message rsl_unused;
7422
7423 /* change Timeslot 6 before f_init() starts RSL */
7424 f_init_vty();
7425 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
7426 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7427
7428 f_init(1, false);
7429 f_sleep(1.0);
7430
7431 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
7432
7433 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7434 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007435 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Harald Welte94e0c342018-04-07 11:33:23 +02007436
7437 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
7438 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
7439 f_sleep(1.0);
7440 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7441
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007442 /* clean up config */
7443 f_ts_set_chcomb(0, 0, 6, "PDCH");
7444
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007445 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007446}
7447
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007448/* Test Osmocom dyn TS SDCCH8 activation / deactivation */
7449testcase TC_dyn_ts_sdcch8_act_deact() runs on test_CT {
7450 var RSL_Message rsl_unused, rsl_msg;
7451 var DchanTuple dt;
7452 var BSSAP_N_CONNECT_ind rx_c_ind;
7453
7454 /* change Timeslot 6 before f_init() starts RSL */
7455 f_init_vty();
7456 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
7457 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7458
7459 f_init(1, false);
7460 f_sleep(1.0);
7461
7462 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7463
7464 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7465 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7466 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007467 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007468
7469 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7470 f_sleep(1.0);
7471 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7472 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7473
7474 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7475 * on CCCH+SDCCH4+CBCH) */
7476 var integer i;
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007477 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007478 dt := f_est_dchan('23'O, i, '00010203040506'O);
7479 }
7480
7481 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
7482 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
7483 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7484 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7485
7486 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7487 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7488
7489 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7490 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
7491 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7492 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7493
7494 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
7495 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
7496 dt.sccp_conn_id := rx_c_ind.connectionId;
7497 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
7498
7499 /* Instruct BSC to clear channel */
7500 var BssmapCause cause := 0;
7501 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7502 f_exp_chan_rel_and_clear(dt, 0);
7503
7504 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007505 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007506 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7507 f_sleep(1.0);
7508 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7509
7510 /* clean up config */
7511 f_ts_set_chcomb(0, 0, 6, "PDCH");
7512
7513 f_shutdown_helper();
7514}
7515
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007516/* Validate all 8 subslots of a dynamics TS configured as SDCCH8 are used */
7517testcase TC_dyn_ts_sdcch8_all_subslots_used() runs on test_CT {
7518 var ASP_RSL_Unitdata rsl_ud;
7519 var integer i;
7520 var integer chreq_total, chreq_nochan;
7521
7522 f_init_vty();
7523 for (i := 1; i < 8; i := i + 1) {
7524 if (i == 2) {
7525 f_ts_set_chcomb(0, 0, i, "TCH/F_TCH/H_SDCCH8_PDCH");
7526 } else {
7527 f_ts_set_chcomb(0, 0, i, "PDCH");
7528 }
7529 }
7530 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7531
7532 f_init(1);
7533
7534 /* The dyn TS want to activate PDCH mode, ACK that. */
7535 var RslChannelNr chan_nr;
7536 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007537 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007538 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7539
7540 f_sleep(1.0);
7541
7542 /* Exhaust all dedicated SDCCH lchans.
7543 /* GSM 44.018 Table 9.1.8.2:
7544 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
7545 */
7546 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
7547 f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
7548 }
7549
7550 /* Only the dyn TS is still available. Its first lchan gets converted to SDCCH8 */
7551 f_est_dchan_dyn('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
7552 /* Also occupy the seven other SDCCH of the dyn TS */
7553 for (i := 0; i < 7; i := i+1) {
7554 f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
7555 }
7556
7557 /* clean up config */
7558 f_ts_reset_chcomb(0);
7559
7560 f_shutdown_helper();
7561}
7562
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007563/* Test Osmocom dyn TS SDCCH8 activation / deactivation: If activating dyn TS as
7564 SDCCH8 would end up in having no free TCH, then BSC should decide to activate
7565 it as TCH directly instead. SYS#5309. */
7566testcase TC_dyn_ts_sdcch8_tch_call_act_deact() runs on test_CT {
7567 var RSL_Message rsl_unused, rsl_msg;
7568 var DchanTuple dt;
7569 var BSSAP_N_CONNECT_ind rx_c_ind;
7570 var integer i;
7571
7572 /* change Timeslot 6 before f_init() starts RSL */
7573 f_init_vty();
7574 for (i := 1; i < 8; i := i + 1) {
7575 if (i == 6) {
7576 f_ts_set_chcomb(0, 0, i, "TCH/F_TCH/H_SDCCH8_PDCH");
7577 } else {
7578 f_ts_set_chcomb(0, 0, i, "PDCH");
7579 }
7580 }
7581 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7582
7583 f_init(1, false);
7584 f_sleep(1.0);
7585
7586 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7587
7588 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7589 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7590 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007591 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007592
7593 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7594 f_sleep(1.0);
7595 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7596 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7597
7598 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7599 * on CCCH+SDCCH4+CBCH) */
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007600 var OCT1 ra := '43'O; /* RA containing reason=originating speech call*/
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007601 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007602 dt := f_est_dchan(ra, i, '00010203040506'O);
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007603 }
7604
7605 /* Now the dyn ts is selected. First PDCH is released, then TCH chan is activated */
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007606 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int(ra) + i, 1), 2342));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007607 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7608 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7609
7610 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7611 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7612
7613 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
7614 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
7615 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7616 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
7617
7618 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
7619 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
7620 dt.sccp_conn_id := rx_c_ind.connectionId;
7621 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
7622
7623 /* Instruct BSC to clear channel */
7624 var BssmapCause cause := 0;
7625 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7626 f_exp_chan_rel_and_clear(dt, 0);
7627
7628 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007629 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007630 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7631 f_sleep(1.0);
7632 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7633
7634 /* clean up config */
7635 f_ts_reset_chcomb(0);
7636 /* TODO: clean up other channels? */
7637
7638 f_shutdown_helper();
7639}
7640
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007641/* Test Osmocom dyn TS SDCCH8 activation / deactivation when SDCCH fails at BTS */
7642testcase TC_dyn_ts_sdcch8_act_nack() runs on test_CT {
7643 var RSL_Message rsl_unused, rsl_msg;
7644 var DchanTuple dt;
7645 var BSSAP_N_CONNECT_ind rx_c_ind;
7646 var GsmRrMessage rr;
7647
7648 /* change Timeslot 6 before f_init() starts RSL */
7649 f_init_vty();
7650 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
7651 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7652
7653 f_init(1, false);
7654 f_sleep(1.0);
7655
7656 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7657
7658 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7659 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7660 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007661 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007662
7663 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7664 f_sleep(1.0);
7665 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7666 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7667
7668 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7669 * on CCCH+SDCCH4+CBCH) */
7670 var integer i;
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007671 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007672 dt := f_est_dchan('23'O, i, '00010203040506'O);
7673 }
7674
7675 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
7676 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
7677 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7678 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7679
7680 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7681 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7682
7683 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7684 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(dt.rsl_chan_nr, RSL_ERR_EQUIPMENT_FAIL));
7685 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7686 rr := dec_GsmRrMessage(rsl_msg.ies[1].body.full_imm_ass_info.payload);
7687 if (rr.header.message_type != IMMEDIATE_ASSIGNMENT_REJECT) {
7688 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Expected reject");
7689 }
7690
7691 /* FIXME? Currently the TS stays in state BORKEN: */
7692
7693 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007694 /* rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007695 * f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7696 * f_sleep(1.0);
7697 * f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE)
7698 */
7699
7700 /* clean up config */
7701 f_ts_set_chcomb(0, 0, 6, "PDCH");
7702
7703 f_shutdown_helper();
7704}
7705
Stefan Sperling0796a822018-10-05 13:01:39 +02007706testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02007707 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02007708 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
7709 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
7710 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007711 f_shutdown_helper();
Stefan Sperling0796a822018-10-05 13:01:39 +02007712}
7713
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007714testcase TC_chopped_ipa_payload() runs on test_CT {
7715 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
7716 /* TODO: mp_bsc_ctrl_port does not work yet */};
7717 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
7718 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
7719 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007720 f_shutdown_helper();
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007721}
7722
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01007723/* Verify the BSC sends the MS Power Parameters IE during CHAN ACT to make sure
7724 the BTS does autonomous MS power control loop */
7725testcase TC_assignment_verify_ms_power_params_ie() runs on test_CT {
7726 var MSC_ConnHdlr vc_conn;
7727 var TestHdlrParams pars := f_gen_test_hdlr_pars();
7728 //pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
7729 pars.exp_ms_power_params := true;
7730
7731 f_init(1, true);
7732 f_sleep(1.0);
7733 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
7734 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007735 f_shutdown_helper();
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01007736}
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007737
Vadim Yanitskiy4b233042021-06-30 00:58:43 +02007738/* Verify activation and deactivation of the BCCH carrier power reduction mode */
7739testcase TC_c0_power_red_mode() runs on test_CT {
7740 f_init(1);
7741
7742 for (var integer red := 6; red >= 0; red := red - 2) {
7743 /* Configure BCCH carrier power reduction mode via the VTY */
7744 f_vty_transceive(BSCVTY, "bts 0 c0-power-reduction " & int2str(red));
7745
7746 /* Expect Osmocom specific BS Power Control message on the RSL */
7747 var template RSL_Message tr_rsl_pdu := tr_RSL_BS_PWR_CTRL(
7748 chan_nr := t_RslChanNr_BCCH(0),
7749 bs_power := tr_RSL_IE_BS_Power(red / 2));
7750 tr_rsl_pdu.msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false);
7751 var RSL_Message unused := f_exp_ipa_rx(0, tr_rsl_pdu);
7752
7753 /* Additionally verify the applied value over the CTRL interface */
7754 var CtrlValue cred := f_ctrl_get_bts(IPA_CTRL, 0, "c0-power-reduction");
7755 if (cred != int2str(red)) {
7756 setverdict(fail, "Unexpected BCCH carrier power reduction value ",
7757 cred, " (expected ", red, ")");
7758 }
7759 }
7760
7761 f_shutdown_helper();
7762}
7763
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007764/***********************************************************************
7765 * MSC Pooling
7766 ***********************************************************************/
7767
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007768template MobileIdentityLV ts_MI_TMSI_NRI_LV(integer nri_v, integer nri_bitlen := 10) :=
Harald Weltebf397612021-01-14 20:39:46 +01007769 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 +02007770
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007771private 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 +02007772runs on MSC_ConnHdlr {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007773 interleave {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007774 [] rsl_pt.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007775 f_logp(BSCVTY, "Got RSL RR Release");
7776 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007777 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007778 f_logp(BSCVTY, "Got RSL Deact SACCH");
7779 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02007780 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007781 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007782 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
7783 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007784 break;
7785 }
7786 }
7787}
7788
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007789friend function f_perform_clear(RSL_DCHAN_PT rsl_pt := RSL, RSLEM_PROC_PT rsl_proc_pt := RSL_PROC,
7790 template PDU_ML3_NW_MS exp_rr_rel_tmpl := tr_RRM_RR_RELEASE)
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02007791runs on MSC_ConnHdlr {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007792 f_logp(BSCVTY, "MSC instructs BSC to clear channel");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007793 BSSAP.send(ts_BSSMAP_ClearCommand(0));
7794 interleave {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007795 [] rsl_pt.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007796 f_logp(BSCVTY, "Got RSL RR Release");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007797 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007798 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007799 f_logp(BSCVTY, "Got RSL Deact SACCH");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007800 }
7801 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007802 f_logp(BSCVTY, "Got BSSMAP Clear Complete");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007803 /* Also drop the SCCP connection */
7804 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
7805 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02007806 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007807 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007808 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
7809 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007810 }
7811 }
7812}
7813
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007814private function f_perform_compl_l3(RSL_DCHAN_PT rsl_pt, RSLEM_PROC_PT rsl_proc_pt,
7815 template PDU_ML3_MS_NW l3_info, boolean do_clear := true, boolean expect_bssmap_l3 := true)
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007816runs on MSC_ConnHdlr {
7817 timer T := 10.0;
7818 var octetstring l3_enc := enc_PDU_ML3_MS_NW(valueof(l3_info));
7819
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007820 f_logp(BSCVTY, "establish channel, send Complete Layer 3 Info");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007821 f_create_bssmap_exp(l3_enc);
7822
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007823 /* RSL_Emulation.f_chan_est() on rsl_pt:
7824 * This is basically code dup with s/RSL/rsl_pt from:
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007825 * RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
7826 */
7827 var RSL_Message rx_rsl;
7828 var GsmRrMessage rr;
7829
7830 /* request a channel to be established */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007831 rsl_pt.send(ts_RSLDC_ChanRqd(g_pars.ra, g_pars.fn));
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007832 /* expect immediate assignment.
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007833 * Code dup with s/RSL/rsl_pt from:
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007834 * rx_rsl := f_rx_or_fail(tr_RSL_IMM_ASSIGN);
7835 */
7836 timer Tt := 10.0;
7837
7838 /* request a channel to be established */
7839 Tt.start;
7840 alt {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007841 [] rsl_pt.receive(tr_RSL_IMM_ASSIGN) -> value rx_rsl {
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007842 Tt.stop;
7843 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007844 [] rsl_pt.receive {
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007845 setverdict(fail, "Unexpected RSL message on DCHAN");
7846 mtc.stop;
7847 }
7848 [] Tt.timeout {
7849 setverdict(fail, "Timeout waiting for RSL on DCHAN");
7850 mtc.stop;
7851 }
7852 }
7853 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
7854 g_chan_nr := rr.payload.imm_ass.chan_desc.chan_nr;
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007855 rsl_pt.send(ts_RSL_EST_IND(g_chan_nr, valueof(g_pars.link_id), l3_enc));
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007856
7857
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007858 if (expect_bssmap_l3) {
7859 f_logp(BSCVTY, "expect BSSAP Complete Layer 3 Info at MSC");
7860 var template PDU_BSSAP exp_l3_compl;
7861 exp_l3_compl := tr_BSSMAP_ComplL3()
7862 if (g_pars.aoip == false) {
7863 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := omit;
7864 } else {
7865 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := ?;
7866 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007867
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007868 var PDU_BSSAP bssap;
7869 T.start;
7870 alt {
7871 [] BSSAP.receive(exp_l3_compl) -> value bssap {
7872 f_logp(BSCVTY, "received expected Complete Layer 3 Info at MSC");
7873 log("rx exp_l3_compl = ", bssap);
7874 }
7875 [] BSSAP.receive(tr_BSSMAP_ComplL3) {
7876 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching COMPLETE LAYER 3 INFORMATION");
7877 }
7878 [] T.timeout {
7879 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
7880 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007881 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007882
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007883 /* start ciphering, if requested */
7884 if (ispresent(g_pars.encr)) {
7885 f_logp(BSCVTY, "start ciphering");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007886 f_cipher_mode(g_pars.encr, rsl_pt := rsl_pt, rsl_proc_pt := rsl_proc_pt);
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007887 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007888 }
7889
7890 if (do_clear) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007891 f_perform_clear(rsl_pt, rsl_proc_pt);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007892 }
7893 setverdict(pass);
7894 f_sleep(1.0);
7895}
7896
7897private function f_tc_mscpool_compl_l3(charstring id) runs on MSC_ConnHdlr {
7898 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
7899 if (g_pars.mscpool.rsl_idx == 0) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007900 f_perform_compl_l3(RSL, RSL_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007901 } else if (g_pars.mscpool.rsl_idx == 1) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007902 f_perform_compl_l3(RSL1, RSL1_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007903 } else if (g_pars.mscpool.rsl_idx == 2) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007904 f_perform_compl_l3(RSL2, RSL2_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007905 }
7906}
7907
7908/* Various Complete Layer 3 by IMSI all end up with the first MSC, because the other MSCs are not connected. */
7909private function f_tc_mscpool_L3Compl_on_1_msc(charstring id) runs on MSC_ConnHdlr {
7910 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007911 f_perform_compl_l3(RSL, RSL_PROC, ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O) );
7912 f_perform_compl_l3(RSL, RSL_PROC, ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_IMSI_LV('001010000000002'H))) );
7913 f_perform_compl_l3(RSL, RSL_PROC, ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))) );
7914 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 +02007915}
7916testcase TC_mscpool_L3Compl_on_1_msc() runs on test_CT {
7917
7918 f_init(1, true);
7919 f_sleep(1.0);
7920 var MSC_ConnHdlr vc_conn;
7921 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007922
7923 f_ctrs_msc_init();
7924
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007925 vc_conn := f_start_handler(refers(f_tc_mscpool_L3Compl_on_1_msc), pars);
7926 vc_conn.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007927
7928 f_ctrs_msc_expect(0, "mscpool:subscr:new", 4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007929 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007930}
7931
7932/* Three Layer 3 Complete by IMSI are round-robin'ed across two connected MSCs */
7933/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7934 * just as well using only RSL. */
7935testcase TC_mscpool_L3Complete_by_imsi_round_robin() runs on test_CT {
7936
7937 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7938 f_sleep(1.0);
7939
7940 /* Control which MSC gets chosen next by the round-robin, otherwise
7941 * would be randomly affected by which other tests ran before this. */
7942 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7943
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007944 f_ctrs_msc_init();
7945
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007946 var MSC_ConnHdlr vc_conn1;
7947 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7948 pars1.mscpool.rsl_idx := 0;
7949 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
7950 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7951 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007952 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007953
7954 var MSC_ConnHdlr vc_conn2;
7955 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7956 pars2.mscpool.rsl_idx := 1;
7957 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
7958 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7959 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007960 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007961
7962 /* Test round-robin wrap to the first MSC */
7963 var MSC_ConnHdlr vc_conn3;
7964 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
7965 pars3.mscpool.rsl_idx := 2;
7966 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
7967 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7968 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007969 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007970 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007971}
7972
7973/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 0
7974 * (configured in osmo-bsc.cfg). */
7975/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7976 * just as well using only RSL. */
7977testcase TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() runs on test_CT {
7978
7979 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7980 f_sleep(1.0);
7981
7982 /* Control which MSC gets chosen next by the round-robin, otherwise
7983 * would be randomly affected by which other tests ran before this. */
7984 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7985
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007986 f_ctrs_msc_init();
7987
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007988 var MSC_ConnHdlr vc_conn1;
7989 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7990 pars1.mscpool.rsl_idx := 0;
7991 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
7992 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7993 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007994 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007995
7996 var MSC_ConnHdlr vc_conn2;
7997 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7998 pars2.mscpool.rsl_idx := 1;
7999 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
8000 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8001 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008002 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008003
8004 /* Test round-robin wrap to the first MSC */
8005 var MSC_ConnHdlr vc_conn3;
8006 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8007 pars3.mscpool.rsl_idx := 2;
8008 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
8009 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8010 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008011 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008012 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008013}
8014
8015/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 1
8016 * (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
8017 * NULL-NRI setting is stronger than that. */
8018/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8019 * just as well using only RSL. */
8020testcase TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() runs on test_CT {
8021
8022 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8023 f_sleep(1.0);
8024
8025 /* Control which MSC gets chosen next by the round-robin, otherwise
8026 * would be randomly affected by which other tests ran before this. */
8027 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8028
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008029 f_ctrs_msc_init();
8030
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008031 var MSC_ConnHdlr vc_conn1;
8032 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8033 pars1.mscpool.rsl_idx := 0;
8034 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8035 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8036 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008037 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008038
8039 var MSC_ConnHdlr vc_conn2;
8040 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8041 pars2.mscpool.rsl_idx := 1;
8042 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8043 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8044 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008045 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008046
8047 /* Test round-robin wrap to the first MSC */
8048 var MSC_ConnHdlr vc_conn3;
8049 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8050 pars3.mscpool.rsl_idx := 2;
8051 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8052 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8053 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008054 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008055 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008056}
8057
8058/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI not
8059 * assigned to any MSC (configured in osmo-bsc.cfg). */
8060/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8061 * just as well using only RSL. */
8062testcase TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() runs on test_CT {
8063
8064 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8065 f_sleep(1.0);
8066
8067 /* Control which MSC gets chosen next by the round-robin, otherwise
8068 * would be randomly affected by which other tests ran before this. */
8069 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8070
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008071 f_ctrs_msc_init();
8072
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008073 var MSC_ConnHdlr vc_conn1;
8074 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8075 pars1.mscpool.rsl_idx := 0;
8076 /* An NRI that is not assigned to any MSC */
8077 pars1.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(1023))));
8078 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8079 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008080 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008081
8082 var MSC_ConnHdlr vc_conn2;
8083 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8084 pars2.mscpool.rsl_idx := 1;
8085 /* An NRI that is not assigned to any MSC */
8086 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(768)), '00F110'O));
8087 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8088 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008089 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008090
8091 /* Test round-robin wrap to the first MSC */
8092 var MSC_ConnHdlr vc_conn3;
8093 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8094 pars3.mscpool.rsl_idx := 2;
8095 /* An NRI that is not assigned to any MSC */
8096 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, valueof(ts_MI_TMSI_NRI_LV(819))));
8097 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8098 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008099 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008100 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008101}
8102
8103/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI
8104 * assigned to an MSC that is currently not connected (configured in osmo-bsc.cfg). */
8105/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8106 * just as well using only RSL. */
8107testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() runs on test_CT {
8108
8109 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8110 f_sleep(1.0);
8111
8112 /* Control which MSC gets chosen next by the round-robin, otherwise
8113 * would be randomly affected by which other tests ran before this. */
8114 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8115
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008116 f_ctrs_msc_init();
8117
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008118 var MSC_ConnHdlr vc_conn1;
8119 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8120 pars1.mscpool.rsl_idx := 0;
8121 /* An NRI that is assigned to an unconnected MSC */
8122 pars1.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(512))));
8123 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8124 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008125 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8126 f_ctrs_msc_add(0, "mscpool:subscr:new");
8127 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008128
8129 var MSC_ConnHdlr vc_conn2;
8130 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8131 pars2.mscpool.rsl_idx := 1;
8132 /* An NRI that is assigned to an unconnected MSC */
8133 pars2.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(767))));
8134 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8135 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008136 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8137 f_ctrs_msc_add(1, "mscpool:subscr:new");
8138 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008139
8140 /* Test round-robin wrap to the first MSC */
8141 var MSC_ConnHdlr vc_conn3;
8142 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8143 pars3.mscpool.rsl_idx := 2;
8144 /* An NRI that is assigned to an unconnected MSC */
8145 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(750)), '00F110'O));
8146 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8147 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008148 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8149 f_ctrs_msc_add(0, "mscpool:subscr:new");
8150 f_ctrs_msc_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008151 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008152}
8153
8154/* Three Layer 3 Complete by TMSI with valid NRI for the second MSC are all directed to the second MSC (configured in
8155 * osmo-bsc.cfg). */
8156/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8157 * just as well using only RSL. */
8158testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_1() runs on test_CT {
8159
8160 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8161 f_sleep(1.0);
8162
8163 /* All TMSIs in this test point at the second MSC, set the round robin to point at the first MSC to make sure
8164 * this is not using round-robin. */
8165 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8166
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008167 f_ctrs_msc_init();
8168
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008169 var MSC_ConnHdlr vc_conn1;
8170 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
8171 pars1.mscpool.rsl_idx := 0;
8172 /* An NRI of the second MSC's range (256-511) */
8173 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(256))));
8174 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8175 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008176 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008177
8178 var MSC_ConnHdlr vc_conn2;
8179 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8180 pars2.mscpool.rsl_idx := 1;
8181 /* An NRI of the second MSC's range (256-511) */
8182 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(260))));
8183 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8184 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008185 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008186
8187 var MSC_ConnHdlr vc_conn3;
8188 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
8189 pars3.mscpool.rsl_idx := 2;
8190 /* An NRI of the second MSC's range (256-511) */
8191 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(511)), '00F110'O));
8192 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8193 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008194 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008195 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008196}
8197
8198/* Layer 3 Complete by TMSI with valid NRI for the third MSC are directed to the third MSC (configured in osmo-bsc.cfg),
8199 * while a round-robin remains unaffected by that. */
8200/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8201 * just as well using only RSL. */
8202testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_2() runs on test_CT {
8203
8204 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8205 f_sleep(1.0);
8206
8207 /* All TMSIs in this test point at the third MSC, set the round robin to point at the second MSC to make sure
8208 * this is not using round-robin. */
8209 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
8210
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008211 f_ctrs_msc_init();
8212
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008213 var MSC_ConnHdlr vc_conn1;
8214 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 2);
8215 pars1.mscpool.rsl_idx := 0;
8216 /* An NRI of the third MSC's range (512-767) */
8217 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(512))));
8218 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8219 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008220 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008221
8222 var MSC_ConnHdlr vc_conn2;
8223 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8224 pars2.mscpool.rsl_idx := 1;
8225 /* An NRI of the third MSC's range (512-767) */
8226 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(678))));
8227 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8228 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008229 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008230
8231 /* The above forwardings to third MSC have not affected the round robin, which still points at the second MSC */
8232 var MSC_ConnHdlr vc_conn3;
8233 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
8234 pars3.mscpool.rsl_idx := 2;
8235 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000013'H)), '00F110'O));
8236 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8237 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008238 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008239 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008240}
8241
8242/* LU with a TMSI but indicating a different PLMN in its previous LAI: ignore the NRI. */
8243/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8244 * just as well using only RSL. */
8245testcase TC_mscpool_LU_by_tmsi_from_other_PLMN() runs on test_CT {
8246
8247 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8248 f_sleep(1.0);
8249
8250 /* The TMSIs in this test points at the second MSC, but since it is from a different PLMN, round-robin is used
8251 * instead, and hits msc 0. */
8252 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8253
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008254 f_ctrs_msc_init();
8255
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008256 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-bsc.cfg */
8257 var MSC_ConnHdlr vc_conn1;
8258 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8259 pars1.mscpool.rsl_idx := 0;
8260 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(260)), '99F999'O));
8261 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8262 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008263 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008264
8265 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
8266 var MSC_ConnHdlr vc_conn2;
8267 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8268 pars2.mscpool.rsl_idx := 1;
8269 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(555)), '00F110'O));
8270 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8271 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008272 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008273 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008274}
8275
8276/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by IMSI, which would be
8277 * round-robined to another MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
8278private function f_tc_mscpool_paging_imsi(charstring id) runs on MSC_ConnHdlr {
8279 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
8280 //cid_list := { cIl_allInBSS := ''O };
8281 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
8282 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
8283 var BSSAP_N_UNITDATA_req paging;
8284 var hexstring imsi := '001010000000123'H;
8285
8286 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8287
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008288 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008289 valueof(ts_BSSMAP_Paging(imsi, cid_list, omit, bssmap_chneed))));
8290 BSSAP.send(paging);
8291
8292 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
8293 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
8294 * channel number is picked here. */
8295 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
8296 f_rslem_register(0, new_chan_nr);
8297 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(imsi)));
8298 f_rslem_unregister(0, new_chan_nr);
8299
8300 /* Despite the round robin pointing at the second MSC ('roundrobin next 1'), the earlier Paging for the same IMSI
8301 * causes this Paging Response to go to the first MSC (bssap_idx := 0). */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008302 f_perform_compl_l3(RSL, RSL_PROC, ts_PAG_RESP(valueof(ts_MI_IMSI_LV(imsi))) );
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008303 f_sleep(1.0);
8304}
8305testcase TC_mscpool_paging_and_response_imsi() runs on test_CT {
8306 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
8307 f_sleep(1.0);
8308
8309 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
8310 * second MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
8311 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
8312
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008313 f_ctrs_msc_init();
8314
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008315 var MSC_ConnHdlr vc_conn1;
8316 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8317 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008318 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
8319 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008320 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_imsi), pars1);
8321 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008322 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008323 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008324}
8325
8326/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by TMSI with an NRI value
8327 * that matches a different MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
8328private function f_tc_mscpool_paging_tmsi(charstring id) runs on MSC_ConnHdlr {
8329 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
8330 //cid_list := { cIl_allInBSS := ''O };
8331 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
8332 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
8333 var integer nri_v := 300; /* <-- second MSC's NRI */
Harald Weltebf397612021-01-14 20:39:46 +01008334 var octetstring tmsi := f_gen_tmsi(suffix := 0, nri_v := nri_v);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008335 var BSSAP_N_UNITDATA_req paging;
8336
8337 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8338
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008339 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008340 valueof(ts_BSSMAP_Paging('001010000000011'H, cid_list, tmsi, bssmap_chneed))));
8341 BSSAP.send(paging);
8342
8343 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
8344 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
8345 * channel number is picked here. */
8346 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
8347 f_rslem_register(0, new_chan_nr);
8348 RSL.receive(tr_RSL_PAGING_CMD(t_MI_TMSI(tmsi)));
8349 f_rslem_unregister(0, new_chan_nr);
8350
8351 /* Despite the NRI matching the second MSC (NRI from 'msc 1' in osmo-bsc.cfg) and round robin pointing at the
8352 * third MSC ('roundrobin next 2'), the earlier Paging for the same TMSI causes this Paging Response to go to
8353 * the first MSC (bssap_idx := 0). */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008354 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 +02008355 f_sleep(1.0);
8356}
8357testcase TC_mscpool_paging_and_response_tmsi() runs on test_CT {
8358 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
8359 f_sleep(1.0);
8360
8361 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
8362 * third MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
8363 f_vty_transceive(BSCVTY, "mscpool roundrobin next 2");
8364
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008365 f_ctrs_msc_init();
8366
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008367 var MSC_ConnHdlr vc_conn1;
8368 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8369 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008370 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
8371 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008372 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_tmsi), pars1);
8373 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008374 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008375 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008376}
8377
8378/* For round-robin, skip an MSC that has 'no allow-attach' set. */
8379/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8380 * just as well using only RSL. */
8381testcase TC_mscpool_no_allow_attach_round_robin() runs on test_CT {
8382
8383 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8384 f_sleep(1.0);
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00008385 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
8386 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008387
8388 /* Control which MSC gets chosen next by the round-robin, otherwise
8389 * would be randomly affected by which other tests ran before this. */
8390 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8391
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008392 f_ctrs_msc_init();
8393
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008394 var MSC_ConnHdlr vc_conn1;
8395 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8396 pars1.mscpool.rsl_idx := 0;
8397 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
8398 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8399 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008400 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008401
8402 var MSC_ConnHdlr vc_conn2;
8403 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8404 pars2.mscpool.rsl_idx := 1;
8405 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8406 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8407 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008408 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008409
8410 var MSC_ConnHdlr vc_conn3;
8411 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8412 pars3.mscpool.rsl_idx := 2;
8413 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
8414 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8415 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008416 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008417 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008418}
8419
8420/* An MSC that has 'no allow-attach' set should still serve subscribers that are already attached according to their
8421 * TMSI NRI. */
8422testcase TC_mscpool_no_allow_attach_valid_nri() runs on test_CT {
8423
8424 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8425 f_sleep(1.0);
8426
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00008427 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
8428 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
8429
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008430 /* Control which MSC gets chosen next by the round-robin, otherwise
8431 * would be randomly affected by which other tests ran before this. */
8432 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8433
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008434 f_ctrs_msc_init();
8435
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008436 /* Round robin points at msc 0, but the valid NRI directs to msc 1, even though msc 1 has 'no allow-attach'. */
8437 var MSC_ConnHdlr vc_conn1;
8438 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
8439 pars1.mscpool.rsl_idx := 0;
8440 /* An NRI of the second MSC's range (256-511) */
8441 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_TMSI_NRI_LV(260))));
8442 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8443 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008444 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008445
8446 var MSC_ConnHdlr vc_conn2;
8447 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 0);
8448 pars2.mscpool.rsl_idx := 1;
8449 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8450 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8451 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008452 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008453
8454 var MSC_ConnHdlr vc_conn3;
8455 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 2);
8456 pars3.mscpool.rsl_idx := 2;
8457 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000003'H))));
8458 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8459 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008460 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008461 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008462}
8463
Philipp Maier783681c2020-07-16 16:47:06 +02008464/* Allow/Deny emergency calls globally via VTY */
8465private function f_vty_allow_emerg_msc(boolean allow) runs on test_CT {
8466 f_vty_enter_cfg_msc(BSCVTY, 0);
8467 if (allow) {
8468 f_vty_transceive(BSCVTY, "allow-emergency allow");
8469 } else {
8470 f_vty_transceive(BSCVTY, "allow-emergency deny");
8471 }
8472 f_vty_transceive(BSCVTY, "exit");
8473 f_vty_transceive(BSCVTY, "exit");
8474}
8475
8476/* Allow/Deny emergency calls per BTS via VTY */
8477private function f_vty_allow_emerg_bts(boolean allow, integer bts_nr) runs on test_CT {
8478 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8479 if (allow) {
8480 f_vty_transceive(BSCVTY, "rach emergency call allowed 1");
8481 } else {
8482 f_vty_transceive(BSCVTY, "rach emergency call allowed 0");
8483 }
8484 f_vty_transceive(BSCVTY, "exit");
8485 f_vty_transceive(BSCVTY, "exit");
Neels Hofmeyrb6ed80c2020-10-12 22:52:39 +00008486 f_vty_transceive(BSCVTY, "exit");
Philipp Maier783681c2020-07-16 16:47:06 +02008487}
8488
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02008489/* Allow/Forbid Fast Return after SRVCC on a given BTS via VTY */
8490private function f_vty_allow_srvcc_fast_return(boolean allow, integer bts_nr) runs on test_CT {
8491 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8492 if (allow) {
8493 f_vty_transceive(BSCVTY, "srvcc fast-return allow");
8494 } else {
8495 f_vty_transceive(BSCVTY, "srvcc fast-return forbid");
8496 }
8497 f_vty_transceive(BSCVTY, "exit");
8498 f_vty_transceive(BSCVTY, "exit");
8499 f_vty_transceive(BSCVTY, "exit");
8500}
8501
Pau Espin Pedrol14475352021-07-22 15:48:16 +02008502/* Allow/Forbid TCH for signalling if SDCCH exhausted on a given BTS via VTY */
8503private function f_vty_allow_tch_for_signalling(boolean allow, integer bts_nr) runs on test_CT {
8504 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8505 if (allow) {
8506 f_vty_transceive(BSCVTY, "channel allocator allow-tch-for-signalling 1");
8507 } else {
8508 f_vty_transceive(BSCVTY, "channel allocator allow-tch-for-signalling 0");
8509 }
8510 f_vty_transceive(BSCVTY, "exit");
8511 f_vty_transceive(BSCVTY, "exit");
8512 f_vty_transceive(BSCVTY, "exit");
8513}
8514
Philipp Maier783681c2020-07-16 16:47:06 +02008515/* Begin assignmet procedure and send an EMERGENCY SETUP (RR) */
8516private function f_assignment_emerg_setup() runs on MSC_ConnHdlr {
8517 var PDU_ML3_MS_NW emerg_setup;
8518 var octetstring emerg_setup_enc;
8519 var RSL_Message emerg_setup_data_ind;
8520
8521 f_establish_fully(omit, omit);
8522
8523 emerg_setup := valueof(ts_ML3_MO_CC_EMERG_SETUP(1, valueof(ts_Bcap_voice)));
8524 emerg_setup_enc := enc_PDU_ML3_MS_NW(emerg_setup);
8525 emerg_setup_data_ind := valueof(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), emerg_setup_enc));
8526
8527 RSL.send(emerg_setup_data_ind);
8528}
8529
8530/* Test if the EMERGENCY SETUP gets passed on to the MSC via A when EMERGENCY
8531 * CALLS are permitted by the BSC config. */
8532private function f_TC_assignment_emerg_setup_allow(charstring id) runs on MSC_ConnHdlr {
8533 var PDU_BSSAP emerg_setup_data_ind_bssap;
8534 var PDU_ML3_MS_NW emerg_setup;
8535 timer T := 3.0;
8536
8537 f_assignment_emerg_setup()
8538
8539 T.start;
8540 alt {
8541 [] BSSAP.receive(tr_BSSAP_DTAP) -> value emerg_setup_data_ind_bssap {
8542 emerg_setup := dec_PDU_ML3_MS_NW(emerg_setup_data_ind_bssap.pdu.dtap);
8543 if (not isbound(emerg_setup.msgs.cc.emergencySetup)) {
8544 setverdict(fail, "no emergency setup");
8545 }
8546 }
8547 [] BSSAP.receive {
8548 setverdict(fail, "unexpected BSSAP message!");
8549 }
8550 [] T.timeout {
8551 setverdict(fail, "timout waiting for EMERGENCY SETUP!");
8552 }
8553 }
8554
8555 setverdict(pass);
8556}
8557
8558/* Test if the EMERGENCY SETUP gets blocked by the BSC if EMERGENCY CALLS are
8559 * forbidden by the BSC config. */
8560private function f_TC_assignment_emerg_setup_deny(charstring id) runs on MSC_ConnHdlr {
8561 var PDU_BSSAP emerg_setup_data_ind_bssap;
8562 timer T := 3.0;
8563
8564 f_assignment_emerg_setup()
8565
8566 T.start;
8567 alt {
8568 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
8569 setverdict(pass);
8570 }
8571 [] RSL.receive {
8572 setverdict(fail, "unexpected RSL message!");
8573 }
8574 [] T.timeout {
8575 setverdict(fail, "timout waiting for RR CHANNEL RELEASE!");
8576 }
8577 }
8578}
8579
8580/* EMERGENCY CALL situation #1, allowed globally and by BTS */
8581testcase TC_assignment_emerg_setup_allow() runs on test_CT {
8582 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8583 var MSC_ConnHdlr vc_conn;
8584
8585 f_init(1, true);
8586 f_sleep(1.0);
8587
8588 f_vty_allow_emerg_msc(true);
8589 f_vty_allow_emerg_bts(true, 0);
8590 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_allow), pars);
8591 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008592 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008593}
8594
8595/* EMERGENCY CALL situation #2, forbidden globally but allowed by BTS */
8596testcase TC_assignment_emerg_setup_deny_msc() runs on test_CT {
8597 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8598 var MSC_ConnHdlr vc_conn;
8599
8600 f_init(1, true);
8601 f_sleep(1.0);
8602
8603 f_vty_allow_emerg_msc(false);
8604 f_vty_allow_emerg_bts(true, 0);
8605 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
8606 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008607 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008608}
8609
8610/* EMERGENCY CALL situation #3, allowed globally but forbidden by BTS */
8611testcase TC_assignment_emerg_setup_deny_bts() runs on test_CT {
8612 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8613 var MSC_ConnHdlr vc_conn;
8614
8615 /* Note: This simulates a spec violation by the MS, correct MS
8616 * implementations would not try to establish an emergency call because
8617 * the system information tells in advance that emergency calls are
8618 * not forbidden */
8619
8620 f_init(1, true);
8621 f_sleep(1.0);
8622
8623 f_vty_allow_emerg_msc(true);
8624 f_vty_allow_emerg_bts(false, 0);
8625 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
8626 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008627 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008628}
8629
Philipp Maier82812002020-08-13 18:48:27 +02008630/* Test what happens when an emergency call arrives while all TCH channels are
8631 * busy, the BSC is expected to terminate one call in favor of the incoming
8632 * emergency call */
8633testcase TC_emerg_premption() runs on test_CT {
8634 var ASP_RSL_Unitdata rsl_ud;
8635 var integer i;
8636 var integer chreq_total, chreq_nochan;
8637 var RSL_Message rx_rsl;
8638 var RslChannelNr chan_nr;
8639
8640 f_init(1);
8641 f_sleep(1.0);
8642
8643 f_vty_allow_emerg_msc(true);
8644 f_vty_allow_emerg_bts(true, 0);
8645
8646 /* Fill up all channels on the BTS */
8647 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
8648 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
8649 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS; i := i+1) {
8650 chan_nr := f_chreq_act_ack('33'O, i);
8651 }
8652 IPA_RSL[0].clear;
8653 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
8654 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
8655
8656 /* Send Channel request for emegergency call */
8657 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
8658
8659 /* Expect the BSC to release one (the first) TCH/F on the BTS */
8660 chan_nr := valueof(t_RslChanNr_Bm(1));
8661 f_expect_chan_rel(0, chan_nr, expect_rr_chan_rel := false, expect_rll_rel_req := false);
8662
8663 /* Expect the BSC to send activate/assign the a channel for the emergency call */
8664 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8665 chan_nr := rx_rsl.ies[0].body.chan_nr;
8666 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 33));
8667 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Philipp Maier104f4c02020-09-11 18:12:18 +02008668
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008669 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008670}
8671
8672/* Hopping parameters per a timeslot */
Vadim Yanitskiybc6654a2020-09-13 01:27:40 +07008673private type record length(0..64) of GsmArfcn ArfcnList;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008674private type record FHParamsTs {
8675 boolean enabled,
8676 uint6_t hsn,
8677 uint6_t maio,
8678 ArfcnList ma
8679};
8680
8681/* Hopping parameters per a transceiver */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008682private type record FHParamsTrx {
Philipp Maier798d8952021-10-19 14:43:19 +02008683 GsmBandArfcn arfcn,
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008684 FHParamsTs ts[8]
8685};
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008686
8687/* Randomly generate the hopping parameters for the given timeslot numbers */
8688private function f_TC_fh_params_gen(template integer tr_tn := (1, 3, 5))
8689runs on test_CT return FHParamsTrx {
8690 var FHParamsTrx fhp;
8691
Philipp Maier798d8952021-10-19 14:43:19 +02008692 /* Generate a random ARFCN in the range of 0 - 3. This ARFCN will
8693 * fall in the GSM900 band. */
8694 fhp.arfcn.arfcn := f_rnd_int(3);
8695 fhp.arfcn.pcs := false;
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008696
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008697 for (var integer tn := 0; tn < 8; tn := tn + 1) {
8698 if (not match(tn, tr_tn)) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008699 fhp.ts[tn].enabled := false;
8700 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008701 continue;
8702 }
8703
8704 /* Random HSN / MAIO values: 0..63 */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008705 fhp.ts[tn].hsn := f_rnd_int(64);
8706 fhp.ts[tn].maio := f_rnd_int(64);
8707 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008708
8709 /* Random Mobile Allocation (hopping channels) */
8710 var integer ma_len := 2 + f_rnd_int(9); /* 2..10 channels */
8711 var integer step := 3 + f_rnd_int(4); /* 3..6 stepping */
8712 for (var integer i := 1; i <= ma_len; i := i + 1) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008713 fhp.ts[tn].ma := fhp.ts[tn].ma & { i * step };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008714 }
8715
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008716 fhp.ts[tn].enabled := true;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008717 }
8718
8719 log("f_TC_fh_params_gen(): ", fhp);
8720 return fhp;
8721}
8722
8723/* Make sure that the given Channel Description IE matches the hopping configuration */
8724private function f_TC_fh_params_match_chan_desc(in FHParamsTrx fhp, in ChannelDescription cd)
8725{
8726 var template (present) ChannelDescription tr_cd;
8727 var template (present) MaioHsn tr_maio_hsn;
8728 var uint3_t tn := cd.chan_nr.tn;
8729
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008730 if (fhp.ts[tn].enabled) {
8731 tr_maio_hsn := tr_HsnMaio(fhp.ts[tn].hsn, fhp.ts[tn].maio);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008732 tr_cd := tr_ChanDescH1(cd.chan_nr, tr_maio_hsn);
8733 } else {
Philipp Maier798d8952021-10-19 14:43:19 +02008734 tr_cd := tr_ChanDescH0(cd.chan_nr, fhp.arfcn.arfcn);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008735 }
8736
8737 if (not match(cd, tr_cd)) {
8738 setverdict(fail, "Channel Description IE does not match: ",
8739 cd, " vs expected ", tr_cd);
8740 }
8741}
8742
8743/* Make sure that the given Mobile Allocation IE matches the hopping configuration */
8744private function f_TC_fh_params_match_ma(in FHParamsTrx fhp, uint3_t tn,
8745 in MobileAllocationLV ma)
8746{
8747 var template MobileAllocationLV tr_ma := f_TC_fh_params_gen_tr_ma(fhp, tn, ma);
8748
8749 if (not match(ma, tr_ma)) {
8750 setverdict(fail, "Mobile Allocation IE does not match (tn := ",
8751 tn, "): ", ma, " vs expected: ", tr_ma);
8752 } else {
8753 setverdict(pass);
8754 }
8755}
8756
8757private function f_TC_fh_params_gen_tr_ma(in FHParamsTrx fhp, uint3_t tn,
8758 in MobileAllocationLV ma)
8759return template MobileAllocationLV {
8760 /* Mobile Allocation IE is expected to be empty if hopping is not enabled */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008761 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008762 return { len := 0, ma := ''B };
8763 }
8764
8765 var bitstring full_mask := f_pad_bit(''B, 1024, '0'B);
8766 var bitstring slot_mask := f_pad_bit(''B, 1024, '0'B);
8767 var bitstring ma_mask := ''B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008768
8769 /* Compose the full bit-mask (all channels, up to 1024 entries) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008770 for (var integer i := 0; i < lengthof(fhp.ts); i := i + 1) {
8771 for (var integer j := 0; j < lengthof(fhp.ts[i].ma); j := j + 1) {
8772 if (full_mask[fhp.ts[i].ma[j]] == '1'B)
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008773 { continue; }
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008774 full_mask[fhp.ts[i].ma[j]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008775 }
8776 }
8777
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008778 /* Take ARFCN of the TRX itself into account */
Philipp Maier798d8952021-10-19 14:43:19 +02008779 full_mask[fhp.arfcn.arfcn] := '1'B;
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008780
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008781 /* Compose a bit-mask for the given timeslot number */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008782 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
8783 slot_mask[fhp.ts[tn].ma[i]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008784 }
8785
8786 /* Finally, compose the Mobile Allocation bit-mask */
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07008787 for (var integer i := 1; i < lengthof(full_mask); i := i + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008788 if (full_mask[i] != '1'B)
8789 { continue; }
8790
8791 /* FIXME: ma_mask := ma_mask & slot_mask[i]; // triggers a bug in TITAN */
8792 if (slot_mask[i] == '1'B) {
8793 ma_mask := ma_mask & '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008794 } else {
8795 ma_mask := ma_mask & '0'B;
8796 }
8797 }
8798
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07008799 /* ARFCN 0 (if present) goes to the last position of the bit-mask */
8800 if (full_mask[0] == '1'B) {
8801 /* FIXME: ma_mask := ma_mask & slot_mask[0]; // triggers a bug in TITAN */
8802 if (slot_mask[0] == '1'B) {
8803 ma_mask := ma_mask & '1'B;
8804 } else {
8805 ma_mask := ma_mask & '0'B;
8806 }
8807 }
8808
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008809 /* Ensure that ma_mask is octet-aligned */
Vadim Yanitskiy2aa02522020-09-06 14:05:23 +07008810 var integer ma_mask_len := (lengthof(ma_mask) + 8 - 1) / 8;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008811 ma_mask := f_pad_bit(ma_mask, ma_mask_len * 8, '0'B);
8812
8813 return { len := ma_mask_len, ma := ma_mask };
8814}
8815
Philipp Maier798d8952021-10-19 14:43:19 +02008816/* Configure the appropriate band for a given arfcn, exc */
8817private function f_TC_set_band_by_arfcn(integer bts_nr, GsmBandArfcn arfcn) runs on test_CT
8818{
8819 var charstring band;
8820 var GsmBandArfcn arfcn_ := valueof(ts_GsmBandArfcn(arfcn.arfcn, arfcn.pcs, false));
8821
8822 select (arfcn_) {
8823 case (tr_GsmBandArfcn((259..293), false, ?)) { band := "GSM450"; }
8824 case (tr_GsmBandArfcn((306..340), false, ?)) { band := "GSM480"; }
8825 case (tr_GsmBandArfcn((438..511), false, ?)) { band := "GSM750"; }
8826 case (tr_GsmBandArfcn((128..251), false, ?)) { band := "GSM850"; }
8827 case (tr_GsmBandArfcn((0..124), false, ?)) { band := "GSM900"; }
8828 case (tr_GsmBandArfcn((955..1023), false, ?)) { band := "GSM900"; }
8829 case (tr_GsmBandArfcn((512..885), false, ?)) { band := "DCS1800"; }
8830 case (tr_GsmBandArfcn((512..810), true, ?)) { band := "PCS1900"; }
8831 case else { return; }
8832 }
8833
8834 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8835 f_vty_transceive(BSCVTY, "band " & band);
8836 f_vty_transceive(BSCVTY, "end");
8837}
8838
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008839/* Configure the hopping parameters in accordance with the given record */
8840private function f_TC_fh_params_set(in FHParamsTrx fhp,
8841 uint8_t bts_nr := 0,
8842 uint8_t trx_nr := 0)
8843runs on test_CT {
Philipp Maier798d8952021-10-19 14:43:19 +02008844
8845 f_TC_set_band_by_arfcn(bts_nr, fhp.arfcn);
8846
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008847 /* Enter the configuration node for the given BTS/TRX numbers */
8848 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
8849
Philipp Maier798d8952021-10-19 14:43:19 +02008850 f_vty_transceive(BSCVTY, "arfcn " & int2str(fhp.arfcn.arfcn));
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008851
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008852 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008853 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
8854
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008855 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008856 f_vty_transceive(BSCVTY, "hopping enabled 0");
8857 f_vty_transceive(BSCVTY, "exit"); /* go back */
8858 continue;
8859 }
8860
8861 /* Configure HSN / MAIO values */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008862 f_vty_transceive(BSCVTY, "hopping sequence-number " & int2str(fhp.ts[tn].hsn));
8863 f_vty_transceive(BSCVTY, "hopping maio " & int2str(fhp.ts[tn].maio));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008864
8865 /* Configure the Mobile Allocation (hopping channels) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008866 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
8867 f_vty_transceive(BSCVTY, "hopping arfcn add " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008868 }
8869
8870 f_vty_transceive(BSCVTY, "hopping enabled 1");
8871 f_vty_transceive(BSCVTY, "exit"); /* go back */
8872 }
8873
8874 f_vty_transceive(BSCVTY, "end");
8875}
8876
8877/* Disable frequency hopping on all timeslots */
8878private function f_TC_fh_params_unset(in FHParamsTrx fhp,
8879 uint8_t bts_nr := 0,
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008880 uint8_t trx_nr := 0,
Philipp Maier798d8952021-10-19 14:43:19 +02008881 GsmBandArfcn arfcn := {pcs := false, arfcn := 871})
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008882runs on test_CT {
Philipp Maier798d8952021-10-19 14:43:19 +02008883
8884 f_TC_set_band_by_arfcn(bts_nr, arfcn);
8885
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008886 /* Enter the configuration node for the given BTS/TRX numbers */
8887 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
8888
Philipp Maier798d8952021-10-19 14:43:19 +02008889 f_vty_transceive(BSCVTY, "arfcn " & int2str(arfcn.arfcn));
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008890
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008891 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008892 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
8893
8894 /* Delete all ARFCNs from the Mobile Allocation (if any) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008895 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
8896 f_vty_transceive(BSCVTY, "hopping arfcn del " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008897 }
8898
8899 f_vty_transceive(BSCVTY, "hopping enabled 0");
8900 f_vty_transceive(BSCVTY, "exit"); /* go back */
8901 }
8902
8903 f_vty_transceive(BSCVTY, "end");
8904 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8905}
8906
8907/* Verify presence and correctness of the hopping parameters (HSN, MAIO)
8908 * in the Channel Identification IE of the RSL CHANnel ACTIVation message. */
8909testcase TC_fh_params_chan_activ() runs on test_CT {
8910 var FHParamsTrx fhp := f_TC_fh_params_gen();
8911 var RSL_Message rsl_msg;
8912 var RSL_IE_Body ie;
8913
8914 f_init_vty();
8915
8916 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
8917 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8918
8919 f_init(1);
8920
8921 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
8922 for (var integer i := 0; i < 9; i := i + 1) {
8923 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
8924 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8925
8926 /* Make sure that Channel Identification IE is present */
8927 if (not f_rsl_find_ie(rsl_msg, RSL_IE_CHAN_IDENT, ie)) {
8928 setverdict(fail, "RSL Channel Identification IE is absent");
8929 continue;
8930 }
8931
8932 /* Make sure that hopping parameters (HSN/MAIO) match */
8933 f_TC_fh_params_match_chan_desc(fhp, ie.chan_ident.ch_desc.v);
8934
8935 /* "Mobile Allocation shall be included but empty" - let's check this */
8936 if (ie.chan_ident.ma.v.len != 0) {
8937 setverdict(fail, "Mobile Allocation IE is not empty: ",
8938 ie.chan_ident.ma, ", despite it shall be");
8939 continue;
8940 }
8941 }
8942
8943 /* Disable frequency hopping */
8944 f_TC_fh_params_unset(fhp);
8945
Vadim Yanitskiy21726312020-09-04 01:45:36 +07008946 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008947}
8948
8949/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Immediate Assignment */
8950testcase TC_fh_params_imm_ass() runs on test_CT {
8951 var FHParamsTrx fhp := f_TC_fh_params_gen();
8952 var RSL_Message rsl_msg;
8953 var RSL_IE_Body ie;
8954
8955 f_init_vty();
8956
8957 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
8958 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8959
8960 f_init(1);
8961
8962 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
8963 for (var integer i := 0; i < 9; i := i + 1) {
8964 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
8965 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8966
8967 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
8968 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
8969
8970 /* Make sure that Full Immediate Assign Info IE is present */
8971 if (not f_rsl_find_ie(rsl_msg, RSL_IE_FULL_IMM_ASS_INFO, ie)) {
8972 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
8973 continue;
8974 }
8975
8976 /* Decode the actual Immediate Assignment message */
8977 var GsmRrMessage rr_msg := dec_GsmRrMessage(ie.full_imm_ass_info.payload);
8978 if (not match(rr_msg.header, t_RrHeader(IMMEDIATE_ASSIGNMENT, ?))) {
8979 setverdict(fail, "Failed to match Immediate Assignment: ", rr_msg);
8980 continue;
8981 }
8982
8983 /* Make sure that hopping parameters (HSN/MAIO) match */
8984 f_TC_fh_params_match_chan_desc(fhp, rr_msg.payload.imm_ass.chan_desc);
8985
8986 /* Make sure that the Mobile Allocation IE matches */
8987 f_TC_fh_params_match_ma(fhp, rr_msg.payload.imm_ass.chan_desc.chan_nr.tn,
8988 rr_msg.payload.imm_ass.mobile_allocation);
8989 }
8990
8991 /* Disable frequency hopping */
8992 f_TC_fh_params_unset(fhp);
Philipp Maier82812002020-08-13 18:48:27 +02008993
Vadim Yanitskiy21726312020-09-04 01:45:36 +07008994 f_shutdown_helper();
Philipp Maier82812002020-08-13 18:48:27 +02008995}
8996
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07008997/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Assignment Command */
8998testcase TC_fh_params_assignment_cmd() runs on test_CT {
8999 var FHParamsTrx fhp := f_TC_fh_params_gen();
9000 var RSL_Message rsl_msg;
9001 var RSL_IE_Body ie;
9002
9003 f_init_vty();
9004
9005 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9006 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9007
9008 f_init(1);
9009
9010 /* HACK: work around "Couldn't find Expect for CRCX" */
9011 vc_MGCP.stop;
9012
9013 var template PDU_BSSAP ass_cmd := f_gen_ass_req();
9014 ass_cmd.pdu.bssmap.assignmentRequest.codecList := ts_BSSMAP_IE_CodecList({ts_CodecFR});
9015
9016 /* CS domain (TCH): 4 (TCH/F) + 2 (TCH/H) channels available
9017 * NOTE: only 3 SDCCH/4 channels are available on CCCH+SDCCH4+CBCH */
9018 for (var integer i := 0; i < 3; i := i + 1) {
9019 /* Establish a dedicated channel, so we can trigger (late) TCH assignment */
9020 var DchanTuple dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
9021
9022 /* Send a BSSMAP Assignment Command, expect CHANnel ACTIVation */
9023 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
9024 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9025
9026 /* ACKnowledge CHANnel ACTIVation, expect RSL DATA REQuest */
9027 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9028 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
9029
9030 /* Make sure that L3 Information IE is present */
9031 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
9032 setverdict(fail, "RSL L3 Information IE is absent");
9033 continue;
9034 }
9035
9036 /* Decode the L3 message and make sure it is (RR) Assignment Command */
9037 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
9038 if (not match(l3_msg.header, t_RrL3Header(ASSIGNMENT_COMMAND))) {
9039 setverdict(fail, "Failed to match Assignment Command: ", l3_msg);
9040 continue;
9041 }
9042
9043 /* Make sure that hopping parameters (HSN/MAIO) match */
9044 var ChannelDescription chan_desc := l3_msg.payload.ass_cmd.chan_desc;
9045 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9046
9047 /* Make sure that Cell Channel Description IE is present if FH is enabled */
9048 if (chan_desc.h and not ispresent(l3_msg.payload.ass_cmd.cell_chan_desc)) {
Vadim Yanitskiy38d069d2020-09-02 17:18:57 +07009049 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009050 continue;
9051 }
9052
9053 /* Make sure that the Mobile Allocation IE matches (if present) */
9054 var boolean ma_present := ispresent(l3_msg.payload.ass_cmd.mobile_allocation);
9055 if (chan_desc.h and ma_present) {
9056 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9057 l3_msg.payload.ass_cmd.mobile_allocation.v);
9058 } else if (chan_desc.h and not ma_present) {
9059 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9060 continue;
9061 } else if (not chan_desc.h and ma_present) {
9062 setverdict(fail, "FH disabled, but Mobile Allocation IE is present");
9063 continue;
9064 }
9065 }
9066
9067 /* Give the IUT some time to release all channels */
9068 f_sleep(3.0);
9069
9070 /* Disable frequency hopping */
9071 f_TC_fh_params_unset(fhp);
9072
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009073 f_shutdown_helper();
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009074}
9075
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009076/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Handover Command */
9077private function f_TC_fh_params_handover_cmd(in FHParamsTrx fhp)
9078runs on test_CT {
9079 var RSL_Message rsl_msg;
9080 var RSL_IE_Body ie;
9081 var DchanTuple dt;
9082
9083 /* Establish a dedicated channel, so we can trigger handover */
9084 dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
Vadim Yanitskiyc18ff472021-11-18 20:15:37 +03009085 f_sleep(0.5);
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009086
9087 /* Trigger handover from BTS0 to BTS1 */
9088 f_bts_0_cfg(BSCVTY, { "neighbor bts 1" });
9089 f_vty_handover(BSCVTY, 0, 0, dt.rsl_chan_nr, 1);
9090
9091 /* Expect RSL CHANnel ACTIVation on BTS1/TRX0/TS1 */
9092 rsl_msg := f_exp_ipa_rx(1, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9093
9094 /* ACKnowledge channel activation and expect (RR) Handover Command */
9095 f_ipa_tx(1, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9096 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
9097
9098 /* Make sure that L3 Information IE is present */
9099 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
9100 setverdict(fail, "RSL L3 Information IE is absent");
9101 return;
9102 }
9103
9104 /* Decode the L3 message and make sure it is (RR) Handover Command */
9105 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
9106 if (not match(l3_msg.header, t_RrL3Header(HANDOVER_COMMAND))) {
9107 setverdict(fail, "Failed to match Handover Command: ", l3_msg);
9108 return;
9109 }
9110
9111 /* Make sure that we've got SDCCH/8 on TS1 (expected to be hopping) */
9112 var ChannelDescription chan_desc := l3_msg.payload.ho_cmd.chan_desc;
9113 if (not match(chan_desc.chan_nr, t_RslChanNr_SDCCH8(1, ?))) {
9114 setverdict(fail, "Unexpected channel number: ", chan_desc.chan_nr);
9115 return;
9116 }
9117
9118 /* Make sure that hopping parameters (HSN/MAIO) match */
9119 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9120
9121 /* Make sure that Cell Channel Description IE is present */
9122 if (not ispresent(l3_msg.payload.ho_cmd.cell_chan_desc)) {
9123 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
9124 return;
9125 }
9126
9127 /* Make sure that the Mobile Allocation (after time) IE is present and matches */
9128 var boolean ma_present := ispresent(l3_msg.payload.ho_cmd.mobile_allocation);
9129 if (ma_present) {
9130 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9131 l3_msg.payload.ho_cmd.mobile_allocation.v);
9132 } else {
9133 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9134 return;
9135 }
9136}
9137testcase TC_fh_params_handover_cmd() runs on test_CT {
9138 var FHParamsTrx fhp := f_TC_fh_params_gen();
9139
9140 f_init_vty();
9141
9142 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8 on BTS1/TRX0 */
9143 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
9144
9145 f_vty_transceive(BSCVTY, "timeslot 0");
9146 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
9147 f_vty_transceive(BSCVTY, "exit"); /* go back */
9148
9149 f_vty_transceive(BSCVTY, "timeslot 1");
9150 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8");
9151 f_vty_transceive(BSCVTY, "end"); /* we're done */
9152
9153 f_TC_fh_params_set(fhp, 1); /* Enable frequency hopping on BTS1 */
9154 f_vty_transceive(BSCVTY, "drop bts connection 1 oml");
9155
9156 f_init(2);
9157
9158 f_TC_fh_params_handover_cmd(fhp);
9159
9160 /* Disable frequency hopping on BTS1 */
9161 f_TC_fh_params_unset(fhp, 1);
9162
9163 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
9164 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
9165
9166 f_vty_transceive(BSCVTY, "timeslot 0");
9167 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
9168 f_vty_transceive(BSCVTY, "exit"); /* go back */
9169
9170 f_vty_transceive(BSCVTY, "timeslot 1");
9171 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
9172 f_vty_transceive(BSCVTY, "end"); /* we're done */
9173
9174 f_shutdown_helper();
9175}
9176
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009177/* Verify the hopping parameters in System Information Type 4 */
9178testcase TC_fh_params_si4_cbch() runs on test_CT {
9179 var FHParamsTrx fhp := f_TC_fh_params_gen(tr_tn := 1);
9180 var ASP_RSL_Unitdata rx_rsl_ud;
9181 timer T := 5.0;
9182
9183 f_init_vty();
9184
9185 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8+CBCH */
9186 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
9187
9188 f_vty_transceive(BSCVTY, "timeslot 0");
9189 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
9190 f_vty_transceive(BSCVTY, "exit"); /* go back */
9191
9192 f_vty_transceive(BSCVTY, "timeslot 1");
9193 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8+cbch");
9194 f_vty_transceive(BSCVTY, "end"); /* we're done */
9195
9196 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9197 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9198
9199 f_init(1);
9200
9201 T.start;
9202 alt {
9203 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO(RSL_SYSTEM_INFO_4))) -> value rx_rsl_ud {
9204 var RSL_IE_Body ie := rx_rsl_ud.rsl.ies[2].body; /* FULL BCCH Information IE */
9205 var SystemInformation si := dec_SystemInformation(ie.other.payload);
9206
9207 /* Make sure that what we decoded is System Information Type 4 */
9208 if (si.header.message_type != SYSTEM_INFORMATION_TYPE_4) {
9209 setverdict(fail, "RSL FULL BCCH Information IE contains: ", si);
9210 repeat;
9211 }
9212
9213 /* Make sure that CBCH Channel Description IE is present */
9214 if (not ispresent(si.payload.si4.cbch_chan_desc)) {
9215 setverdict(fail, "CBCH Channel Description IE is absent");
9216 break;
9217 }
9218
9219 /* Finally, check the hopping parameters (HSN, MAIO) */
9220 var ChannelDescription chan_desc := si.payload.si4.cbch_chan_desc.v;
9221 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9222
9223 /* 3GPP TS 44.018, section 9.1.36.2 "CBCH Mobile Allocation":
9224 * The CBCH Mobile Allocation IE *shall* be present if FH is enabled. */
9225 if (chan_desc.h and not ispresent(si.payload.si4.cbch_mobile_alloc)) {
9226 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9227 break;
9228 } else if (chan_desc.h and ispresent(si.payload.si4.cbch_mobile_alloc)) {
9229 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9230 si.payload.si4.cbch_mobile_alloc.v);
9231 }
9232 }
9233 [] IPA_RSL[0].receive { repeat; }
9234 [] T.timeout {
9235 setverdict(fail, "Timeout waiting for RSL BCCH INFOrmation (SI4)");
9236 }
9237 }
9238
9239 /* Disable frequency hopping */
9240 f_TC_fh_params_unset(fhp);
9241
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07009242 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009243 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
9244
9245 f_vty_transceive(BSCVTY, "timeslot 0");
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07009246 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009247 f_vty_transceive(BSCVTY, "exit"); /* go back */
9248
9249 f_vty_transceive(BSCVTY, "timeslot 1");
9250 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
9251 f_vty_transceive(BSCVTY, "end"); /* we're done */
9252
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009253 f_shutdown_helper();
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009254}
9255
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009256template (value) PDU_BSSAP_LE ts_BSSMAP_LE_BSSLAP(template (value) BSSLAP_PDU bsslap)
9257 := ts_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, data := enc_BSSLAP_PDU(valueof(bsslap)));
9258
9259private function f_match_bsslap(PDU_BSSAP_LE got_bsslap_msg,
9260 template (present) BSSLAP_PDU expect_bsslap)
9261{
9262 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(got_bsslap_msg.pdu.bssmap.co_info.bsslap_apdu.data);
9263 if (not match(bsslap, expect_bsslap)) {
9264 log("EXPECTING BSSLAP: ", expect_bsslap);
9265 log("GOT BSSLAP: ", bsslap);
9266 setverdict(fail, "BSSLAP is not as expected");
9267 mtc.stop;
9268 }
9269 setverdict(pass);
9270}
9271
9272/* GAD: this is an Ellipsoid point with uncertainty circle, encoded as in 3GPP TS 23.032 §7.3.2. */
9273const octetstring gad_ell_point_unc_circle := '10b0646d0d5f6627'O;
9274
9275private function f_expect_bsslap(template (present) BSSLAP_PDU expect_rx_bsslap) runs on MSC_ConnHdlr {
9276 var PDU_BSSAP_LE rx_bsslap;
9277 BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap);
9278 f_match_bsslap(rx_bsslap, expect_rx_bsslap);
9279}
9280
9281/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9282 * Request on Lb interface. Either with or without the SMLC doing a BSSLAP TA Request. */
9283private function f_lcs_loc_req_for_active_ms(boolean do_ta_request := false) runs on MSC_ConnHdlr {
9284 f_sleep(1.0);
9285
9286 f_establish_fully(omit, omit);
9287 f_bssap_le_register_imsi(g_pars.imsi, omit);
9288
9289 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9290 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9291
9292 var PDU_BSSAP_LE plr;
9293 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9294
9295 if (not do_ta_request) {
9296 /* verify TA Layer 3 in APDU. First the APDU type (BSSLAP), then the BSSLAP data contents. */
9297 var template BSSMAP_LE_IE_APDU expect_apdu := tr_BSSMAP_LE_APDU(BSSMAP_LE_PROT_BSSLAP, ?);
9298 if (not match(plr.pdu.bssmap.perf_loc_req.bsslap_apdu, expect_apdu)) {
9299 log("EXPECTING BSSMAP-LE APDU IE ", expect_apdu);
9300 log("GOT BSSMAP-LE APDU IE ", plr.pdu.bssmap.perf_loc_req.bsslap_apdu);
9301 setverdict(fail, "BSSMAP-LE APDU IE is not as expected");
9302 mtc.stop;
9303 }
9304 var template BSSLAP_PDU expect_ta_layer3 := tr_BSSLAP_TA_Layer3(tr_BSSLAP_IE_TA(0));
9305 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(plr.pdu.bssmap.perf_loc_req.bsslap_apdu.data);
9306 if (not match(bsslap, expect_ta_layer3)) {
9307 log("EXPECTING BSSLAP TA Layer 3: ", expect_ta_layer3);
9308 log("GOT BSSLAP: ", bsslap);
9309 setverdict(fail, "BSSLAP is not as expected");
9310 mtc.stop;
9311 }
9312 /* OsmoBSC directly sent the TA as BSSLAP APDU in the BSSMAP-LE Perform Location Request to the SMLC. The SMLC
9313 * has no need to request the TA from the BSC and directly responds. */
9314 } else {
9315 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9316 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9317 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9318 }
9319
9320 /* SMLC got the TA from the BSC, now responds with geo information data. */
9321 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9322 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9323 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9324
9325 /* The LCS was using an active A-interface conn. It should still remain active after this. */
9326 f_mo_l3_transceive();
9327
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009328 f_perform_clear();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009329
9330 f_sleep(2.0);
9331 setverdict(pass);
9332}
9333
9334/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9335 * Request on Lb interface. Without the SMLC doing a BSSLAP TA Request. */
9336private function f_tc_lcs_loc_req_for_active_ms(charstring id) runs on MSC_ConnHdlr {
9337 f_lcs_loc_req_for_active_ms(false);
9338}
9339testcase TC_lcs_loc_req_for_active_ms() runs on test_CT {
9340 var MSC_ConnHdlr vc_conn;
9341 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9342
9343 f_init(1, true);
9344 f_sleep(1.0);
9345 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms), pars);
9346 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009347 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009348}
9349
9350/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9351 * Request on Lb interface. With the SMLC doing a BSSLAP TA Request. */
9352private function f_tc_lcs_loc_req_for_active_ms_ta_req(charstring id) runs on MSC_ConnHdlr {
9353 f_lcs_loc_req_for_active_ms(true);
9354}
9355testcase TC_lcs_loc_req_for_active_ms_ta_req() runs on test_CT {
9356 var MSC_ConnHdlr vc_conn;
9357 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9358
9359 f_init(1, true);
9360 f_sleep(1.0);
9361 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_ta_req), pars);
9362 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009363 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009364}
9365
9366/* Clear the A-interface conn only, without doing anything on Abis. Useful for LCS, for cases where there is only an A
9367 * conn without an active lchan. */
9368private function f_clear_A_conn() runs on MSC_ConnHdlr
9369{
9370 var BssmapCause cause := 0;
9371 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
9372 BSSAP.receive(tr_BSSMAP_ClearComplete);
9373 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
9374
9375 timer no_more_bssap := 5.0;
9376 no_more_bssap.start;
9377 alt {
9378 [] no_more_bssap.timeout { break; }
9379 [] BSSAP.receive(tr_BSSAP_BSSMAP) {
9380 setverdict(fail, "Expected no more BSSAP after Clear Complete");
9381 mtc.stop;
9382 }
9383 }
9384 setverdict(pass);
9385}
9386
9387/* Verify that the A-interface connection is still working, and then clear it, without doing anything on Abis. Useful
9388 * for LCS, for cases where there is only an A conn without an active lchan. */
9389private function f_verify_active_A_conn_and_clear() runs on MSC_ConnHdlr
9390{
9391 f_logp(BSCVTY, "f_verify_active_A_conn_and_clear: test A link, then clear");
9392
9393 /* When an lchan is active, we can send some L3 data from the BTS side and verify that it shows up on the other
9394 * side towards the MSC. When there is no lchan, this is not possible. To probe whether the A-interface
9395 * connection is still up, we need something that echos back on the A-interface. Another LCS request! */
9396 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9397 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9398 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?));
9399
9400 /* Right, the Perform Location Request showed up on Lb, now we can clear the A conn. */
9401 f_clear_A_conn();
9402 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
9403 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9404}
9405
9406/* With *no* active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9407 * Request on Lb interface. BSC will Page for the subscriber as soon as we (virtual SMLC) request the TA via BSSLAP.
9408 */
9409private function f_tc_lcs_loc_req_for_idle_ms(charstring id) runs on MSC_ConnHdlr {
9410 f_sleep(1.0);
9411
9412 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9413 f_bssap_le_register_imsi(g_pars.imsi, omit);
9414
9415 /* Register to receive the Paging Command */
9416 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9417 g_chan_nr := new_chan_nr;
9418 f_rslem_register(0, g_chan_nr);
9419
9420 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9421 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9422 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9423 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9424
9425 var PDU_BSSAP_LE plr;
9426 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9427
9428 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9429 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9430
9431 /* OsmoBSC needs to Page */
9432 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi)));
9433 f_logp(BSCVTY, "got Paging Command");
9434
9435 /* MS requests channel. Since the Paging was for LCS, the Paging Response does not trigger a Complete Layer 3 to
9436 * the MSC, and releases the lchan directly. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009437 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);
9438 f_expect_lchan_rel(RSL, RSL_PROC);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009439
9440 /* From the Paging Response, the TA is now known to the BSC, and it responds to the SMLC. */
9441
9442 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9443
9444 /* SMLC got the TA from the BSC, now responds with geo information data. */
9445 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9446 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9447
9448 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9449
9450 /* The lchan is gone, the A-interface conn was created for the LCS only.
9451 * Still it is clearly the MSC's job to decide whether to tear down the conn or not. */
9452 f_verify_active_A_conn_and_clear();
9453
9454 f_sleep(2.0);
9455 setverdict(pass);
9456}
9457testcase TC_lcs_loc_req_for_idle_ms() runs on test_CT {
9458 var MSC_ConnHdlr vc_conn;
9459 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9460
9461 f_init(1, true);
9462 f_sleep(1.0);
9463
9464 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9465 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9466
9467 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms), pars);
9468 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009469 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009470}
9471
9472/* With no active lchan, start BSSMAP Perform Location Request on A interface, but omit IMSI; expect failure response.
9473 */
9474private function f_tc_lcs_loc_req_no_subscriber(charstring id) runs on MSC_ConnHdlr {
9475 f_sleep(1.0);
9476
9477 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9478 f_bssap_le_register_imsi(g_pars.imsi, omit);
9479
9480 /* provoke an abort by omitting both IMSI and IMEI */
9481 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9482 valueof(ts_BSSMAP_Perform_Location_Request(omit,
9483 ts_CellId_CGI('262'H, '42'H, 23, 42)))));
9484 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9485
9486 /* BSC tells MSC about failure */
9487 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9488 locationEstimate := omit, positioningData := omit,
9489 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_DATA_MISSING_IN_REQ)));
9490
9491 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9492 f_verify_active_A_conn_and_clear();
9493
9494 f_sleep(2.0);
9495 setverdict(pass);
9496}
9497testcase TC_lcs_loc_req_no_subscriber() runs on test_CT {
9498 var MSC_ConnHdlr vc_conn;
9499 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9500
9501 f_init(1, true);
9502 f_sleep(1.0);
9503
9504 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9505 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9506
9507 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_no_subscriber), pars);
9508 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009509 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009510}
9511
9512/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9513 * BSSMAP-LE Perform Location Response (before or after sending a BSSLAP TA Request) */
9514private function f_lcs_loc_req_for_active_ms_le_timeout(boolean do_ta) runs on MSC_ConnHdlr {
9515 f_sleep(1.0);
9516
9517 f_establish_fully(omit, omit);
9518 f_bssap_le_register_imsi(g_pars.imsi, omit);
9519
9520 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9521 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9522
9523 var PDU_BSSAP_LE plr;
9524 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9525
9526 if (do_ta) {
9527 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9528 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9529 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9530 }
9531
9532 /* SMLC fails to respond, BSC runs into timeout */
9533 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_SYSTEM_FAILURE));
9534 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9535
9536 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9537 locationEstimate := omit, positioningData := omit,
9538 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_SYSTEM_FAILURE)));
9539
9540 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9541 f_verify_active_A_conn_and_clear();
9542
9543 f_sleep(2.0);
9544 setverdict(pass);
9545}
9546
9547/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9548 * BSSMAP-LE Perform Location Response, without sending a BSSLAP TA Request. */
9549private function f_tc_lcs_loc_req_for_active_ms_le_timeout(charstring id) runs on MSC_ConnHdlr {
9550 f_lcs_loc_req_for_active_ms_le_timeout(false);
9551}
9552
9553testcase TC_lcs_loc_req_for_active_ms_le_timeout() runs on test_CT {
9554 var MSC_ConnHdlr vc_conn;
9555 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9556
9557 f_init(1, true);
9558 f_sleep(1.0);
9559 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout), pars);
9560 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009561 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009562}
9563
9564/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9565 * BSSMAP-LE Perform Location Response, after sending a BSSLAP TA Request. */
9566private function f_tc_lcs_loc_req_for_active_ms_le_timeout2(charstring id) runs on MSC_ConnHdlr {
9567 f_lcs_loc_req_for_active_ms_le_timeout(true);
9568}
9569
9570testcase TC_lcs_loc_req_for_active_ms_le_timeout2() runs on test_CT {
9571 var MSC_ConnHdlr vc_conn;
9572 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9573
9574 f_init(1, true);
9575 f_sleep(1.0);
9576 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout2), pars);
9577 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009578 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009579}
9580
9581/* With *no* active lchan, start a Perform Location Request, expecting that the MS will be Paged. */
9582private function f_tc_lcs_loc_req_for_idle_ms_no_pag_resp(charstring id) runs on MSC_ConnHdlr {
9583 f_sleep(1.0);
9584
9585 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9586 f_bssap_le_register_imsi(g_pars.imsi, omit);
9587
9588 /* Register to receive the Paging Command */
9589 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9590 g_chan_nr := new_chan_nr;
9591 f_rslem_register(0, g_chan_nr);
9592
9593 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9594 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9595 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9596 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9597
9598 var PDU_BSSAP_LE plr;
9599 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9600
9601 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9602 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9603
9604 /* OsmoBSC needs to Page */
9605 var PDU_BSSAP_LE rx_bsslap;
9606 alt {
9607 [] RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi))) {
9608 f_logp(BSCVTY, "got Paging Command");
9609 repeat;
9610 }
9611 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
9612 /* MS does not respond to Paging, TA Req runs into timeout. */
9613 f_match_bsslap(rx_bsslap, tr_BSSLAP_Abort(?));
9614 }
9615 }
9616
9617 /* SMLC responds with failure */
9618 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(omit, BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
9619 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9620
9621 /* BSC tells MSC about failure */
9622 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9623 locationEstimate := omit, positioningData := omit,
9624 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_REQUEST_ABORTED)));
9625
9626 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9627 f_verify_active_A_conn_and_clear();
9628
9629 f_sleep(2.0);
9630 setverdict(pass);
9631}
9632testcase TC_lcs_loc_req_for_idle_ms_no_pag_resp() runs on test_CT {
9633 var MSC_ConnHdlr vc_conn;
9634 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9635
9636 f_init(1, true);
9637 f_sleep(1.0);
9638
9639 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9640 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9641
9642 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms_no_pag_resp), pars);
9643 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009644 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009645}
9646
9647/* During an ongoing Location Request, the MS sends a CM Service Request. Expect the same A-conn to be re-used / taken
9648 * over. */
9649private function f_tc_cm_service_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
9650 f_sleep(1.0);
9651
9652 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9653 f_bssap_le_register_imsi(g_pars.imsi, omit);
9654
9655 /* Register to receive the Paging Command */
9656 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9657 g_chan_nr := new_chan_nr;
9658 f_rslem_register(0, g_chan_nr);
9659
9660 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9661 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9662 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9663 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9664
9665 var PDU_BSSAP_LE plr;
9666 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9667
9668 /* As the A-interface conn was established for LCS, the MS coincidentally decides to issue a CM Service Request
9669 * and establish Layer 3. It should use the existing A-interface conn. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009670 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 +02009671 do_clear := false, expect_bssmap_l3 := true);
9672
9673 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9674 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9675
9676 /* OsmoBSC already has an lchan, no need to Page, just returns the TA */
9677 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9678
9679 /* SMLC got the TA from the BSC, now responds with geo information data. */
9680 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9681 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9682 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9683
9684 /* The lchan should still exist, it was from a CM Service Request. */
9685 f_mo_l3_transceive();
9686
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009687 f_perform_clear();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009688
9689 f_sleep(2.0);
9690 setverdict(pass);
9691}
9692testcase TC_cm_service_during_lcs_loc_req() runs on test_CT {
9693 var MSC_ConnHdlr vc_conn;
9694 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9695
9696 f_init(1, true);
9697 f_sleep(1.0);
9698
9699 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9700 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9701
9702 vc_conn := f_start_handler(refers(f_tc_cm_service_during_lcs_loc_req), pars);
9703 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009704 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009705}
9706
9707/* During an ongoing Perform Location Request, do a Handover, an expect a BSSLAP Reset message from the BSC to indicate
9708 * the new lchan after handover. */
9709private function f_tc_ho_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
9710 f_sleep(1.0);
9711
9712 f_establish_fully(omit, omit);
9713 f_bssap_le_register_imsi(g_pars.imsi, omit);
9714
9715 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9716 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9717
9718 var PDU_BSSAP_LE plr;
9719 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9720
9721 /* SMLC ponders the Location Request, in the meantime the BSC decides to handover */
9722 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
9723
9724 var HandoverState hs := {
9725 rr_ho_cmpl_seen := false,
9726 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02009727 old_chan_nr := -,
9728 expect_target_tsc := BTS_TSC[1]
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009729 };
9730 /* issue hand-over command on VTY */
9731 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
9732 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
9733 f_rslem_suspend(RSL1_PROC);
9734
9735 /* From the MGW perspective, a handover is is characterized by
9736 * performing one MDCX operation with the MGW. So we expect to see
9737 * one more MDCX during handover. */
9738 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
9739
9740 alt {
9741 [] as_handover(hs);
9742 }
9743
9744 var PDU_BSSAP_LE rx_bsslap;
9745
9746 interleave {
9747 /* Expect the BSC to inform the MSC about the handover */
9748 [] BSSAP.receive(tr_BSSMAP_HandoverPerformed);
9749
9750 /* Expect the BSC to inform the SMLC about the handover */
9751 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
9752 f_match_bsslap(rx_bsslap, tr_BSSLAP_Reset(BSSLAP_CAUSE_INTRA_BSS_HO));
9753 }
9754 }
9755
9756 /* SMLC now responds with geo information data. */
9757 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9758 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9759 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9760
9761 /* lchan still active */
9762 f_mo_l3_transceive(RSL1);
9763
9764 /* MSC decides it is done now. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009765 f_perform_clear(RSL1, RSL1_PROC);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009766
9767 f_sleep(2.0);
9768 setverdict(pass);
9769}
9770testcase TC_ho_during_lcs_loc_req() runs on test_CT {
9771 var MSC_ConnHdlr vc_conn;
9772 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9773
9774 f_init(2, true);
9775 f_sleep(1.0);
9776 vc_conn := f_start_handler(refers(f_tc_ho_during_lcs_loc_req), pars);
9777 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009778 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009779}
9780
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009781/* Attempt Complete Layer 3 without any MSC available (OS#4832) */
9782private function f_tc_no_msc(charstring id) runs on MSC_ConnHdlr {
9783 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9784
9785 /* Also disable attach for the single connected MSC */
9786 f_vty_msc_allow_attach(BSCVTY, { false });
9787
9788 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) ));
9789 f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
9790
9791 /* No MSC is found, expecting a proper release on RSL */
9792 interleave {
9793 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
9794 f_logp(BSCVTY, "Got RSL RR Release");
9795 }
9796 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
9797 f_logp(BSCVTY, "Got RSL Deact SACCH");
9798 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02009799 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009800 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
9801 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02009802 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009803 }
9804 }
9805 setverdict(pass);
9806}
9807testcase TC_no_msc() runs on test_CT {
9808
9809 f_init(1, true);
9810 f_sleep(1.0);
9811 var MSC_ConnHdlr vc_conn;
9812 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9813
9814 f_ctrs_bsc_init(counternames_bsc_mscpool);
9815
9816 vc_conn := f_start_handler(refers(f_tc_no_msc), pars);
9817 vc_conn.done;
9818
9819 f_ctrs_bsc_add("mscpool:subscr:no_msc");
9820 f_ctrs_bsc_verify();
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009821 f_shutdown_helper();
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009822}
9823
Harald Welte0ea2d5e2018-04-07 21:40:29 +02009824/* Dyn PDCH todo:
9825 * activate OSMO as TCH/F
9826 * activate OSMO as TCH/H
9827 * does the BSC-located PCU socket get the updated INFO?
9828 * what if no PCU is connected at the time?
9829 * is the info correct on delayed PCU (re)connect?
9830 */
Harald Welte94e0c342018-04-07 11:33:23 +02009831
Neels Hofmeyr87857ec2021-04-25 16:17:47 +00009832private function f_TC_refuse_mode_modif_to_vamos(charstring id) runs on MSC_ConnHdlr {
9833 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
9834 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
9835
9836 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
9837 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
9838 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
9839 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
9840 g_pars.ass_codec_list.codecElements[0];
9841 if (isvalue(g_pars.expect_mr_s0_s7)) {
9842 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
9843 g_pars.expect_mr_s0_s7;
9844 }
9845 }
9846 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
9847 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
9848 log("expecting ASS COMPL like this: ", exp_compl);
9849
9850 f_establish_fully(ass_cmd, exp_compl);
9851
Neels Hofmeyr8746b0d2021-06-01 17:25:39 +02009852 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 +00009853
9854 var RSL_Message rsl;
9855
9856 timer T := 5.0;
9857 T.start;
9858 alt {
9859 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
9860 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
9861 log("Rx L3 from net: ", l3);
9862 if (ischosen(l3.msgs.rrm.channelModeModify)) {
9863 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
9864 mtc.stop;
9865 }
9866 }
9867 [] RSL.receive(tr_RSL_MODE_MODIFY_REQ(g_chan_nr, ?)) -> value rsl {
9868 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
9869 mtc.stop;
9870 }
9871 [] T.timeout {
9872 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related Mode Modify should happen. */
9873 setverdict(pass);
9874 }
9875 }
9876 T.stop;
9877}
9878
9879/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel Mode Modify to VAMOS mode is refused by
9880 * osmo-bsc. */
9881testcase TC_refuse_mode_modif_to_vamos() runs on test_CT {
9882 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9883 var MSC_ConnHdlr vc_conn;
9884
9885 f_init(1, true);
9886 f_sleep(1.0);
9887
9888 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
9889 vc_conn := f_start_handler(refers(f_TC_refuse_mode_modif_to_vamos), pars);
9890 vc_conn.done;
9891 f_shutdown_helper();
9892}
9893
9894/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel activation to VAMOS mode is refused by osmo-bsc.
9895 */
9896testcase TC_refuse_chan_act_to_vamos() runs on test_CT {
9897 f_init_vty();
9898
9899 f_init(1, false);
9900 f_sleep(1.0);
9901
9902 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 activate-vamos fr");
9903
9904 var ASP_RSL_Unitdata rx_rsl_ud;
9905 timer T := 5.0;
9906
9907 T.start;
9908 alt {
9909 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(?, IPAC_PROTO_RSL_TRX0)) -> value rx_rsl_ud {
9910 if (rx_rsl_ud.rsl.msg_type == RSL_MT_CHAN_ACTIV) {
9911 T.stop;
9912 setverdict(fail, "CHANnel ACTivate in VAMOS mode succeeded even though BTS does not support VAMOS");
9913 mtc.stop;
9914 }
9915 repeat;
9916 }
9917 [] T.timeout {
9918 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related CHANnel ACTivate should happen. */
9919 setverdict(pass);
9920 }
9921 }
9922}
9923
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009924private function f_TC_reassignment_codec(charstring id) runs on MSC_ConnHdlr {
9925 /* First fully set up a speech lchan */
9926 f_TC_assignment_codec(id);
9927
9928 /* Trigger re-assignment to another lchan */
9929 var AssignmentState assignment_st := valueof(ts_AssignmentStateInit);
9930
9931 /* Re-Assignment should tell the MGW endpoint the new lchan's RTP address and port, so expecting to see exactly
9932 * one MDCX on MGCP. */
9933 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].mdcx_seen_exp + 1;
9934
9935 /* The new lchan will see all-new IPAC_CRCX and IPAC_MDCX messages telling the BTS the same RTP address and port
9936 * as the old lchan used. */
9937 g_media.bts.ipa_crcx_seen := false;
9938 g_media.bts.ipa_mdcx_seen := false;
9939
9940 /* Send different BTS side RTP port number for the new lchan */
9941 g_media.bts.bts.port_nr := 4223;
9942
9943 f_rslem_register(0, valueof(ts_RslChanNr_Bm(2))); /* <-- FIXME: can we somehow infer the timeslot that will be used? */
9944
9945 /* Trigger re-assignment. */
9946 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot " & int2str(g_chan_nr.tn) & " sub-slot 0 assignment");
9947
9948 timer T := 5.0;
9949 T.start;
9950 alt {
9951 [] as_assignment(assignment_st);
9952 [] as_Media();
9953 [] T.timeout {
9954 break;
9955 }
9956 }
9957
9958 if (not assignment_st.assignment_done) {
9959 setverdict(fail, "Assignment did not complete");
9960 mtc.stop;
9961 }
9962
9963 f_check_mgcp_expectations()
9964 setverdict(pass);
9965
9966 f_sleep(2.0);
9967 log("show lchan summary: ", f_vty_transceive_ret(BSCVTY, "show lchan summary"));
9968
9969 /* Instruct BSC to clear channel */
9970 var BssmapCause cause := 0;
9971 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
9972 interleave {
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009973 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {}
9974 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02009975 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009976 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02009977 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009978 }
9979 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
9980 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
9981 }
9982 }
Neels Hofmeyr40a45d12021-09-23 22:57:12 +02009983 f_expect_dlcx_conns();
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009984
9985 f_sleep(0.5);
9986}
9987
9988testcase TC_reassignment_fr() runs on test_CT {
9989 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9990 var MSC_ConnHdlr vc_conn;
9991
9992 f_init(1, true);
9993 f_sleep(1.0);
9994
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01009995 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009996
9997 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
9998 vc_conn := f_start_handler(refers(f_TC_reassignment_codec), pars);
9999 vc_conn.done;
10000
10001 /* from f_establish_fully() */
10002 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
10003 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
10004 /* from re-assignment */
10005 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
10006 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
10007 f_ctrs_bsc_and_bts_verify();
10008 f_shutdown_helper();
10009}
10010
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010011const charstring REEST_LOST_CONNECTION := "REEST_LOST_CONNECTION";
10012const charstring REEST_CLEAR := "REEST_CLEAR";
10013const charstring REEST_CLEAR_DONE := "REEST_CLEAR_DONE";
10014
10015/* CM Re-Establishment, 3GPP TS 24.008 4.5.1.6.
10016 * The MS <-> BTS loses radio connection, MS shows up on second BTS and asks for CM Re-Establishment.
10017 * BSC should establish a separate A conn for the same MS, the original A conn is then cleared by
10018 * the MSC as the CM Re-Establishment is handled.
10019 *
10020 * MS bts0 bts1 bsc msc test-component
10021 * |<----->|<----------------->|<-0-->| _1 Establish channel on bts 0
10022 * | | _1 wait a bit, to settle down
10023 * |<-x x--| | _1 "lose connection"
10024 * | | REEST_LOST_CONNECTION
10025 * |----------------->|------->|--1-->| _2 new A-conn: Chan Rqd, Imm Ass, Compl L3 with CM Re-Establishment Req
10026 * | | REEST_CLEAR
10027 * | |<-0---| _1 Clear Command on first A-conn
10028 * | |--0-->| _1 Clear Complete
10029 * | |<----------------->| | _1 Release first channel
10030 * | | REEST_CLEAR_DONE
10031 * |<-----------------|<-------|<-1---| _2 Chan Activ, Assignment Command
10032 * |<-----------------|<-------|<-1---| _2 Clear Command, Release
10033 *
10034 */
10035private function f_tc_cm_reestablishment_1(charstring id) runs on MSC_ConnHdlr {
10036 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
10037 var PDU_BSSAP ass_cmd := f_gen_ass_req();
10038
10039 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10040 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10041
10042 f_establish_fully(ass_cmd, exp_compl);
10043
10044 /* The original channel loses connection, MS attemts CM Re-Establishment on another cell, see
10045 * f_tc_cm_reestablishment_2(). This established channel stays active until MSC sends a Clear Command. The time
10046 * when exactly that happens is determined by f_tc_cm_reestablishment_2(). */
10047 f_sleep(2.0);
10048 COORD.send(REEST_LOST_CONNECTION);
10049
10050 alt {
10051 [] COORD.receive(REEST_CLEAR);
10052 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
10053 setverdict(fail, "Unexpected channel release");
10054 mtc.stop;
10055 }
10056 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
10057 setverdict(fail, "Unexpected channel release");
10058 mtc.stop;
10059 }
10060 }
10061 f_perform_clear()
10062 f_expect_dlcx_conns();
Neels Hofmeyr969abd02021-09-23 22:24:08 +020010063 f_create_mgcp_delete_ep(g_media.mgcp_ep);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010064 COORD.send(REEST_CLEAR_DONE);
10065}
10066
10067private function f_tc_cm_reestablishment_2(charstring id) runs on MSC_ConnHdlr {
10068 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
10069
10070 /* The MS lost the connection on the first channel, now establishes another one */
10071 COORD.receive(REEST_LOST_CONNECTION);
10072
10073 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
10074 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_REESTABL_REQ(mi));
10075 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
10076
10077 f_create_bssmap_exp(l3_enc);
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010078 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 +020010079 BSSAP.receive(tr_BSSMAP_ComplL3(l3_enc));
10080
10081 /* MSC got the CM Re-Establishment request and first off clears the previous conn. */
10082 COORD.send(REEST_CLEAR);
10083 COORD.receive(REEST_CLEAR_DONE);
10084
10085 f_sleep(2.0);
10086
10087 /* Answer the CM Re-Establishment with an Assignment Command. */
10088 var template PDU_BSSAP expect_assignment_compl := f_gen_exp_compl();
10089 var PDU_BSSAP ass_cmd := f_gen_ass_req();
10090 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10091 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10092
10093 var AssignmentState st := valueof(ts_AssignmentStateInit);
10094 st.voice_call := true;
10095 st.is_assignment := true;
10096
10097 var ExpectCriteria mgcpcrit := {
10098 connid := omit,
10099 endpoint := omit,
10100 transid := omit
10101 };
10102 f_create_mgcp_expect(mgcpcrit);
10103
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010104 f_rslem_dchan_queue_enable(RSL1_PROC);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010105
10106 BSSAP.send(ass_cmd);
10107
10108 var PDU_BSSAP bssap;
10109
10110 alt {
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010111 [] as_assignment(st, rsl_pt := RSL1, rsl_proc_pt := RSL1_PROC);
10112 [] as_Media_ipacc(RSL1, RSL2);
10113 [] as_Media_mgw();
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010114 [st.assignment_done] BSSAP.receive(expect_assignment_compl) {
10115 break;
10116 }
10117 }
10118
10119 f_sleep(3.0);
10120
10121 f_logp(BSCVTY, "f_tc_cm_reestablishment_2 clearing");
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010122 f_perform_clear(RSL1, RSL1_PROC);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010123 f_expect_dlcx_conns();
10124}
10125
10126testcase TC_cm_reestablishment() runs on test_CT {
10127 var TestHdlrParams pars1 := f_gen_test_hdlr_pars();
10128 var MSC_ConnHdlr vc_conn1;
10129
10130 var TestHdlrParams pars2 := f_gen_test_hdlr_pars();
10131 var MSC_ConnHdlr vc_conn2;
10132 pars2.imsi := pars1.imsi;
10133 pars2.media_nr := 2;
Neels Hofmeyrbf720202021-10-02 12:58:24 +020010134 pars2.expect_tsc := BTS_TSC[1];
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010135
10136 f_init(2, true, guard_timeout := 40.0);
10137 f_sleep(1.0);
10138
10139 vc_conn1 := f_start_handler_create(pars1);
10140 vc_conn2 := f_start_handler_create(pars2);
10141 connect(vc_conn1:COORD, vc_conn2:COORD);
10142 f_start_handler_run(vc_conn1, refers(f_tc_cm_reestablishment_1), pars1);
10143 f_start_handler_run(vc_conn2, refers(f_tc_cm_reestablishment_2), pars2);
10144 vc_conn1.done;
10145 vc_conn2.done;
10146
10147 f_shutdown_helper();
10148}
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000010149
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010150function f_exp_ipa_rx_nonfatal(integer bts_nr, template (present) RSL_Message t_rx, float t_secs := 2.0,
10151 IpaStreamId sid := IPAC_PROTO_RSL_TRX0, boolean ignore_other_rx := true)
10152runs on test_CT return template (omit) RSL_Message {
10153 var ASP_RSL_Unitdata rx_rsl_ud;
10154 timer T := t_secs;
10155
10156 T.start;
10157 alt {
10158 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
10159 T.stop;
10160 }
10161 [ignore_other_rx] IPA_RSL[bts_nr].receive { repeat; }
10162 [not ignore_other_rx] IPA_RSL[bts_nr].receive {
10163 log("f_exp_ipa_rx_nonfatal(): Got different message than ", t_rx);
10164 T.stop;
10165 return omit;
10166 }
10167 [] T.timeout {
10168 return omit;
10169 }
10170 }
10171 return rx_rsl_ud.rsl;
10172}
10173
10174private function f_vty_set_imm_ass(TELNETasp_PT pt, BtsNr bts_nr := 0, charstring imm_ass_setting := "post-chan-ack") {
10175 f_vty_enter_cfg_bts(pt, bts_nr);
10176 f_vty_transceive(pt, "immediate-assignment " & imm_ass_setting);
10177 f_vty_transceive(pt, "exit");
10178 f_vty_transceive(pt, "exit");
10179 f_vty_transceive(pt, "exit");
10180}
10181
10182private function f_verify_imm_ass(RSL_Message imm_ass, template uint8_t ra := ?, template GsmFrameNumber fn := ?,
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010183 template RslChannelNr chan_nr := ?,
10184 template (present) uint12_t arfcn := ?,
10185 template (present) uint3_t tsc := ?)
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010186{
10187 var RSL_IE_Body full_imm_ass_info;
10188 if (not f_rsl_find_ie(imm_ass, RSL_IE_FULL_IMM_ASS_INFO, full_imm_ass_info)) {
10189 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
10190 mtc.stop;
10191 }
10192
10193 var GsmRrMessage rr_imm_ass := dec_GsmRrMessage(full_imm_ass_info.full_imm_ass_info.payload);
10194 var template GsmRrMessage expect_imm_ass := tr_IMM_ASS(ra := ra,
10195 fn := fn,
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010196 ch_desc := tr_ChanDescH0(chan_nr, arfcn, tsc),
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010197 page_mode := ?);
10198 if (not match(rr_imm_ass, expect_imm_ass)) {
10199 log("Error: expected ", expect_imm_ass, " got ", rr_imm_ass);
10200 setverdict(fail, "Failed to match Immediate Assignment");
10201 mtc.stop;
10202 }
10203}
10204
10205testcase TC_imm_ass_post_chan_ack() runs on test_CT {
10206 var RSL_Message chan_act;
10207 var RSL_Message imm_ass;
10208
10209 f_init(1, false);
10210 f_sleep(1.0);
10211
10212 /* (should be the default anyway, just to make things clear) */
10213 f_vty_set_imm_ass(BSCVTY, 0, "post-chan-ack");
10214
10215 /* RA containing reason=LU */
10216 var GsmFrameNumber fn := 2342;
10217 var uint8_t ra := 2;
10218 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10219
10220 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10221
10222 /* First send the Chan Act ACK */
10223 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010224 var RSL_IE_Body chan_ident_ie;
10225 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10226 setverdict(fail, "RSL Channel Identification IE is absent");
10227 mtc.stop;
10228 }
10229
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010230 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn + 10));
10231
10232 /* Then expect the Immediate Assignment, after we ACKed the chan act */
10233 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10234
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010235 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10236 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010237
10238 /* Check that the lchan is working */
10239 var octetstring l3 := '00010203040506'O;
10240 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10241
10242 var BSSAP_N_CONNECT_ind rx_c_ind;
10243 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
10244 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10245
10246 f_sleep(1.0);
10247 f_shutdown_helper();
10248}
10249
10250testcase TC_imm_ass_pre_chan_ack() runs on test_CT {
10251 var RSL_Message chan_act;
10252 var RSL_Message imm_ass;
10253
10254 f_init(1, false);
10255 f_sleep(1.0);
10256
10257 f_vty_set_imm_ass(BSCVTY, 0, "pre-chan-ack");
10258
10259 /* RA containing reason=LU */
10260 var GsmFrameNumber fn := 2342;
10261 var uint8_t ra := 2;
10262 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10263
10264 /* (set bts 0 cfg back to default) */
10265 f_vty_set_imm_ass(BSCVTY);
10266
10267 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10268 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010269 var RSL_IE_Body chan_ident_ie;
10270 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10271 setverdict(fail, "RSL Channel Identification IE is absent");
10272 mtc.stop;
10273 }
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010274
10275 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10276 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010277 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10278 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010279
10280 /* Only now send the Chan Act ACK */
10281 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10282
10283 /* Check that the lchan is working */
10284 var octetstring l3 := '00010203040506'O;
10285 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10286
10287 var BSSAP_N_CONNECT_ind rx_c_ind;
10288 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
10289 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10290
10291 f_sleep(1.0);
10292 f_shutdown_helper();
10293}
10294
Neels Hofmeyr23158742021-09-07 19:08:07 +020010295testcase TC_imm_ass_pre_ts_ack() runs on test_CT {
10296 var RSL_Message chan_act;
10297 var RSL_Message imm_ass;
10298
10299 f_init(1, false);
10300 f_sleep(1.0);
10301
10302 f_vty_set_imm_ass(BSCVTY, 0, "pre-ts-ack");
10303
10304 /* RA containing reason=LU */
10305 var GsmFrameNumber fn := 2342;
10306 var uint8_t ra := 2;
10307 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10308
10309 /* (set bts 0 cfg back to default) */
10310 f_vty_set_imm_ass(BSCVTY);
10311
10312 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10313 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
10314 var RSL_IE_Body chan_ident_ie;
10315 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10316 setverdict(fail, "RSL Channel Identification IE is absent");
10317 mtc.stop;
10318 }
10319
10320 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10321 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10322 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10323 chan_ident_ie.chan_ident.ch_desc.v.tsc);
10324
10325 /* Only now send the Chan Act ACK */
10326 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10327
10328 /* Check that the lchan is working */
10329 var octetstring l3 := '00010203040506'O;
10330 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10331
10332 var BSSAP_N_CONNECT_ind rx_c_ind;
10333 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
10334 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10335
10336 f_sleep(1.0);
10337 f_shutdown_helper();
10338}
10339
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010340testcase TC_imm_ass_pre_chan_ack_dyn_ts() runs on test_CT {
10341 /* change Timeslot 6 before f_init() starts RSL */
10342 f_init_vty();
10343 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
10344 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10345
10346 f_init(1, false);
10347 f_sleep(1.0);
10348
10349 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
10350 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010351 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010352 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2323));
10353
10354 /* clean up timeslot 6 config, will only take effect when the OML drops the next time */
10355 f_ts_set_chcomb(0, 0, 6, "PDCH");
10356
10357 /* block all static timeslots so that the dyn TS will be used */
10358 f_disable_all_tch_f();
10359 f_disable_all_tch_h();
10360 f_disable_all_sdcch();
10361
10362 var RSL_Message chan_act;
10363 var RSL_Message imm_ass;
10364
10365 f_init(1, false);
10366 f_sleep(1.0);
10367
10368 f_vty_set_imm_ass(BSCVTY, 0, "pre-chan-ack");
10369
10370 /* RA containing reason=LU */
10371 var GsmFrameNumber fn := 2342;
10372 var uint8_t ra := 2;
10373 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10374
10375 /* (set bts 0 cfg back to default) */
10376 f_vty_set_imm_ass(BSCVTY);
10377
10378 /* Expect the dyn TS to deactivate PDCH first */
10379 f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
10380 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
10381
10382 /* Now activation as SDCCH8 */
10383 chan_nr := valueof(t_RslChanNr_SDCCH8(tn := 6, sub_slot := 0));
10384
10385 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010386 var RSL_IE_Body chan_ident_ie;
10387 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10388 setverdict(fail, "RSL Channel Identification IE is absent");
10389 mtc.stop;
10390 }
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010391
10392 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10393 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010394 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10395 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010396
10397 /* Only now send the Chan Act ACK */
10398 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10399
10400 /* Check that the lchan is working */
10401 var octetstring l3 := '00010203040506'O;
10402 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10403
10404 var BSSAP_N_CONNECT_ind rx_c_ind;
10405 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
10406 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10407
10408 f_sleep(1.0);
10409 f_shutdown_helper();
10410}
10411
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010412testcase TC_imm_ass_pre_ts_ack_dyn_ts() runs on test_CT {
10413 /* change Timeslot 6 before f_init() starts RSL */
10414 f_init_vty();
10415 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
10416 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10417
10418 f_init(1, false);
10419 f_sleep(1.0);
10420
10421 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
10422 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010423 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010424 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2323));
10425
10426 /* clean up timeslot 6 config, will only take effect when the OML drops the next time */
10427 f_ts_set_chcomb(0, 0, 6, "PDCH");
10428
10429 /* block all static timeslots so that the dyn TS will be used */
10430 f_disable_all_tch_f();
10431 f_disable_all_tch_h();
10432 f_disable_all_sdcch();
10433
10434 var RSL_Message chan_act;
10435 var RSL_Message imm_ass;
10436
10437 f_init(1, false);
10438 f_sleep(1.0);
10439
10440 f_vty_set_imm_ass(BSCVTY, 0, "pre-ts-ack");
10441
10442 /* RA containing reason=LU */
10443 var GsmFrameNumber fn := 2342;
10444 var uint8_t ra := 2;
10445 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10446
10447 /* (set bts 0 cfg back to default) */
10448 f_vty_set_imm_ass(BSCVTY);
10449
10450 /* Expect the dyn TS to deactivate PDCH first */
10451 f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
10452
10453 /* And already the Immediate Assignment even before the PDCH Deact ACK */
10454 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10455
10456 /* continue the Osmo style PDCH Deact (usual chan rel) */
10457 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
10458
10459 /* Now activation as SDCCH8 */
10460 chan_nr := valueof(t_RslChanNr_SDCCH8(tn := 6, sub_slot := 0));
10461
10462 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010463 var RSL_IE_Body chan_ident_ie;
10464 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10465 setverdict(fail, "RSL Channel Identification IE is absent");
10466 mtc.stop;
10467 }
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010468 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10469
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010470 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10471 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010472
10473 /* Check that the lchan is working */
10474 var octetstring l3 := '00010203040506'O;
10475 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10476
10477 var BSSAP_N_CONNECT_ind rx_c_ind;
10478 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
10479 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10480
10481 f_sleep(1.0);
10482 f_shutdown_helper();
10483}
10484
Neels Hofmeyr5d7d13f2021-09-07 14:44:36 +020010485/* GET and SET the bts.N.trx.M.rf_locked CTRL variable */
10486testcase TC_ctrl_trx_rf_locked() runs on test_CT {
10487 var MSC_ConnHdlr vc_conn;
10488
10489 f_init(nr_bts := 2, handler_mode := true, nr_msc := 1);
10490 f_sleep(1.0);
10491
10492 /* BTS 0, 1, 2 are OML unlocked, only BTS 0, 1 are actually connected to RSL. */
10493 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10494 "0,0,operational,unlocked,on,rsl-up;" &
10495 "1,0,operational,unlocked,on,rsl-up;" &
10496 "2,0,operational,unlocked,on,rsl-down;" &
10497 "3,0,inoperational,locked,on,rsl-down;");
10498
10499 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: lock BTS 1 TRX 0");
10500 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "1");
10501 /* give it a moment to settle the FSM status */
10502 f_sleep(1.0);
10503
10504 /* Now BTS 1 TRX 0 should reflect "locked". Note the RF policy stays "on", because this is still handled
10505 * globally in osmo-bsc. Probably after sending "rf_locked 1" for a TRX, that TRX should reflect an RF policy
10506 * of "off"? But that's for a future patch if at all. */
10507 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10508 "0,0,operational,unlocked,on,rsl-up;" &
10509 "1,0,operational,locked,on,rsl-up;" &
10510 "2,0,operational,unlocked,on,rsl-down;" &
10511 "3,0,inoperational,locked,on,rsl-down;");
10512
10513 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: lock the already locked TRX, nothing should change");
10514 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "1");
10515 f_sleep(1.0);
10516 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10517 "0,0,operational,unlocked,on,rsl-up;" &
10518 "1,0,operational,locked,on,rsl-up;" &
10519 "2,0,operational,unlocked,on,rsl-down;" &
10520 "3,0,inoperational,locked,on,rsl-down;");
10521
10522 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock BTS 1 TRX 0");
10523 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "0");
10524 f_sleep(1.0);
10525 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10526 "0,0,operational,unlocked,on,rsl-up;" &
10527 "1,0,operational,unlocked,on,rsl-up;" &
10528 "2,0,operational,unlocked,on,rsl-down;" &
10529 "3,0,inoperational,locked,on,rsl-down;");
10530
10531 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock an already unlocked TRX, nothing should change");
10532 f_ctrl_set(IPA_CTRL, "bts.0.trx.0.rf_locked", "0");
10533 f_sleep(1.0);
10534 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10535 "0,0,operational,unlocked,on,rsl-up;" &
10536 "1,0,operational,unlocked,on,rsl-up;" &
10537 "2,0,operational,unlocked,on,rsl-down;" &
10538 "3,0,inoperational,locked,on,rsl-down;");
10539
10540 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock an inoperational TRX");
10541 f_ctrl_set(IPA_CTRL, "bts.3.trx.0.rf_locked", "0");
10542 f_sleep(1.0);
10543 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10544 "0,0,operational,unlocked,on,rsl-up;" &
10545 "1,0,operational,unlocked,on,rsl-up;" &
10546 "2,0,operational,unlocked,on,rsl-down;" &
10547 "3,0,inoperational,locked,on,rsl-down;");
10548
10549 f_shutdown_helper();
10550}
10551
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010552const CounterNameVals counternames_cm_serv_rej := {
10553 { "cm_serv_rej", 0 },
10554 { "cm_serv_rej:imsi_unknown_in_hlr", 0 },
10555 { "cm_serv_rej:illegal_ms", 0 },
10556 { "cm_serv_rej:imsi_unknown_in_vlr", 0 },
10557 { "cm_serv_rej:imei_not_accepted", 0 },
10558 { "cm_serv_rej:illegal_me", 0 },
10559 { "cm_serv_rej:plmn_not_allowed", 0 },
10560 { "cm_serv_rej:loc_not_allowed", 0 },
10561 { "cm_serv_rej:roaming_not_allowed", 0 },
10562 { "cm_serv_rej:network_failure", 0 },
10563 { "cm_serv_rej:synch_failure", 0 },
10564 { "cm_serv_rej:congestion", 0 },
10565 { "cm_serv_rej:srv_opt_not_supported", 0 },
10566 { "cm_serv_rej:rqd_srv_opt_not_supported", 0 },
10567 { "cm_serv_rej:srv_opt_tmp_out_of_order", 0 },
10568 { "cm_serv_rej:call_can_not_be_identified", 0 },
10569 { "cm_serv_rej:incorrect_message", 0 },
10570 { "cm_serv_rej:invalid_mandantory_inf", 0 },
10571 { "cm_serv_rej:msg_type_not_implemented", 0 },
10572 { "cm_serv_rej:msg_type_not_compatible", 0 },
10573 { "cm_serv_rej:inf_eleme_not_implemented", 0 },
10574 { "cm_serv_rej:condtional_ie_error", 0 },
10575 { "cm_serv_rej:msg_not_compatible", 0 },
10576 { "cm_serv_rej:protocol_error", 0 },
10577 { "cm_serv_rej:retry_in_new_cell", 0 }
10578};
10579
10580private function f_TC_cm_serv_rej(charstring id) runs on MSC_ConnHdlr
10581{
10582 f_create_chan_and_exp();
Vadim Yanitskiya7fc5a62021-12-04 20:10:08 +030010583 /* we should now have a COMPL_L3 at the MSC */
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010584 BSSAP.send(ts_PDU_DTAP_MT(ts_CM_SERV_REJ('02'O), '00'O));
Neels Hofmeyr87a65612021-11-16 15:56:45 +010010585 f_sleep(1.0);
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010586}
10587testcase TC_cm_serv_rej() runs on test_CT {
10588 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10589 var MSC_ConnHdlr vc_conn;
10590
10591 f_init(1, true);
10592 f_sleep(1.0);
10593
10594 f_ctrs_bts_init(1, counternames_cm_serv_rej);
10595
10596 vc_conn := f_start_handler(refers(f_TC_cm_serv_rej), pars);
10597 vc_conn.done;
10598
10599 f_ctrs_bts_add(0, "cm_serv_rej", 1);
10600 f_ctrs_bts_add(0, "cm_serv_rej:imsi_unknown_in_hlr", 1);
10601 f_ctrs_bts_verify();
10602
Neels Hofmeyr87a65612021-11-16 15:56:45 +010010603 f_sleep(1.0);
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010604 f_shutdown_helper();
10605}
10606
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010607/* Reproduce a segfault happening when the SDCCH (primary) lchan is lost in-between a TCH Channel Activ and its Channel
10608 * Activ Ack (SYS#5627). */
10609private function f_TC_lost_sdcch_during_assignment(charstring id) runs on MSC_ConnHdlr {
10610 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Vadim Yanitskiyf0310e32021-10-26 00:30:59 +030010611
10612 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10613 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010614
10615 var BSSMAP_FIELD_CodecType codecType;
10616 codecType := valueof(ass_cmd.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType);
10617
10618 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
10619
10620 /* First establish a signalling lchan */
10621 f_create_chan_and_exp();
10622 f_rslem_dchan_queue_enable();
10623
10624 /* we should now have a COMPL_L3 at the MSC */
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010625
10626 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
10627 activate(as_Media_mgw());
10628
10629 var RslChannelNr chan_nr := { u := { ch0 := RSL_CHAN_NR_Bm_ACCH }, tn := 1 };
10630 f_rslem_register(0, chan_nr);
10631
10632 f_rslem_set_auto_chan_act_ack(RSL_PROC, false);
10633 BSSAP.send(ass_cmd);
10634
10635
10636 /* Wait for the Channel Activ for the TCH channel */
10637 var ASP_RSL_Unitdata rx_rsl_ud;
10638 RSL.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV), sid := ?)) -> value rx_rsl_ud;
10639
10640 /* make the original SDCCH disappear */
10641 RSL.send(ts_RSL_REL_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
10642
10643 /* and ACK the TCH channel activation. This caused a segfault up to OsmoBSC 1.7.0 (SYS#5627) */
10644 RSL.send(ts_ASP_RSL_UD(ts_RSL_CHAN_ACT_ACK(chan_nr, 23), rx_rsl_ud.streamId));
10645
10646 interleave {
10647 [] BSSAP.receive(tr_BSSMAP_AssignmentFail);
10648 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
10649 }
10650
10651 BSSAP.send(ts_BSSMAP_ClearCommand(0));
10652 BSSAP.receive(tr_BSSMAP_ClearComplete);
10653 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
10654
10655 var MgcpCommand mgcp;
10656 MGCP.receive(tr_DLCX()) -> value mgcp {
10657 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
10658 };
10659
10660 f_sleep(0.5);
10661}
10662testcase TC_lost_sdcch_during_assignment() runs on test_CT {
10663 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10664 var MSC_ConnHdlr vc_conn;
10665
10666 f_init(1, true);
10667 f_sleep(1.0);
10668
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010669 vc_conn := f_start_handler(refers(f_TC_lost_sdcch_during_assignment), pars);
10670 vc_conn.done;
10671
10672 f_shutdown_helper();
10673}
10674
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010675const CounterNameVals counternames_bsc_bts_all_available_allocated := {
10676 { "all_allocated:sdcch", 0 },
10677 { "all_allocated:static_sdcch", 0 },
10678 { "all_allocated:tch", 0 },
10679 { "all_allocated:static_tch", 0 }
10680}
10681
10682private function f_all_allocated_expect_counter_change(charstring_list expect_changed) runs on test_CT
10683{
10684 /* Make sure counters settle first */
10685 f_sleep(1.0);
10686
10687 /* Take a baseline of counters */
10688 f_ctrs_bsc_and_bts_init(1, counternames_bsc_bts_all_available_allocated);
10689
10690 /* Elapse some time so that we see changes in counters, hopefully where expected */
10691 f_sleep(2.0);
10692
10693 /* Get new counters */
10694 var charstring_list all_changed := {};
10695 all_changed := all_changed & f_counter_name_vals_get_changed_n(IPA_CTRL, "bsc", g_ctr_bsc);
10696 all_changed := all_changed & f_counter_name_vals_get_changed_n(IPA_CTRL, "bts", g_ctr_bts);
10697
10698 /* Compare with expectations */
10699 var charstring_list all_expect_changed := {};
10700 for (var integer i := 0; i < lengthof(expect_changed); i := i + 1) {
10701 all_expect_changed := all_expect_changed & { "bsc.0." & expect_changed[i], "bts.0." & expect_changed[i] };
10702 }
10703 f_counter_name_vals_expect_changed_list(all_changed, all_expect_changed);
10704}
10705
10706testcase TC_ratectr_all_available_allocated() runs on test_CT {
10707 var ASP_RSL_Unitdata rsl_ud;
10708 var integer i;
10709 var integer chreq_total, chreq_nochan;
10710
10711 f_init(1);
10712 f_sleep(1.0);
10713
10714 /* Exhaust all dedicated SDCCH lchans.
10715 /* GSM 44.018 Table 9.1.8.2:
10716 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
10717 */
10718 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
10719 f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
10720 }
10721
10722 /* Since only bts 0 is connected, expecting all_allocated to become true for both bts 0 and the "global" bsc
10723 * level.
10724 * All SDCCH are now occupied. */
10725 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch"});
10726
10727 /* Also fill up all remaining (TCH) channels */
10728 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS; i := i+1) {
10729 f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
10730 }
10731
10732 /* All TCH are now also occupied */
10733 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch",
10734 "all_allocated:tch", "all_allocated:static_tch"});
10735
10736 f_shutdown_helper();
10737}
10738
10739testcase TC_ratectr_all_available_allocated_dyn() runs on test_CT {
10740 var ASP_RSL_Unitdata rsl_ud;
10741 var integer i;
10742 var integer chreq_total, chreq_nochan;
10743
10744 f_init_vty();
10745 f_ts_set_chcomb(0, 0, 2, "TCH/F_TCH/H_PDCH");
10746 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10747 /* Now we have 3 TCH/F, 1 OSMO_DYN, 1 TCH/H */
10748
10749 f_init(1, guard_timeout := 60.0);
10750 f_sleep(1.0);
10751
10752 /* The dyn TS wants to activate PDCH mode, ACK that. */
10753 var RslChannelNr chan_nr;
10754 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010755 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010756 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
10757
10758 /* Exhaust all dedicated SDCCH lchans.
10759 /* GSM 44.018 Table 9.1.8.2:
10760 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
10761 */
10762 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
10763 f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
10764 }
10765
10766 /* The static SDCCH should now be occupied, while still 3x8 dynamic SDCCH potentially remain. So only
10767 * all_allocated:static_sdcch is counted, all_allocated:sdcch remains zero. */
10768 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch"});
10769
10770 /* Request more SDCCH, hence convert the first dyn TS to SDCCH8.
10771 * Will release them later, so remember all the DchanTuples. */
10772 var DchanTuples dyn_sddch := {};
10773 dyn_sddch := dyn_sddch & { f_est_dchan_dyn('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
10774
10775 /* Also occupy the seven other SDCCH of the dyn TS */
10776 for (i := 0; i < 7; i := i+1) {
10777 dyn_sddch := dyn_sddch & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
10778 }
10779
10780 /* Now all dynamic SDCCH are also occupied, so for the first time all_allocated:sdcch will trigger... */
10781 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch"});
10782
10783 /* occupy the remaining TCH, three TCH/F and two TCH/H lchans */
10784 for (i := 0; i < 5; i := i+1) {
10785 f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
10786 }
10787
10788 /* All TCH lchans are now also occupied, both static and dynamic */
10789 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch",
10790 "all_allocated:tch", "all_allocated:static_tch"});
10791
10792 /* Starting to release the dyn TS: as soon as the first SDCCH gets released, all_allocated:sdcch stops
10793 * incrementing. */
10794 var BssmapCause cause := 0;
10795 var DchanTuple dt := dyn_sddch[0];
10796 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
10797 f_exp_chan_rel_and_clear(dt, 0);
10798
10799 /* one dyn TS SDCCH is free again, so only the static_sdcch should increment. For tch, both static and dynamic
10800 * count as occupied, so those still both increment. */
10801 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch",
10802 "all_allocated:tch", "all_allocated:static_tch"});
10803
10804 /* Release the remaining SDCCH of the dyn TS, so it becomes available as TCH again */
10805 for (i := 1; i < lengthof(dyn_sddch); i := i+1) {
10806 dt := dyn_sddch[i];
10807 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
10808 f_exp_chan_rel_and_clear(dt, 0);
10809 }
10810
10811 /* All SDCCH on the dyn TS are released, the dyn TS wants to activate PDCH again */
10812 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010813 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010814 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
10815
10816 /* Now all channels are occupied except the dyn TS, so expecting only the static counters to increment */
10817 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch", "all_allocated:static_tch"});
10818
10819 /* clean up config */
10820 f_ts_reset_chcomb(0);
10821
10822 f_shutdown_helper();
10823}
10824
Harald Welte28d943e2017-11-25 15:00:50 +010010825control {
Harald Welte898113b2018-01-31 18:32:21 +010010826 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +010010827 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +010010828 execute( TC_ctrl_msc0_connection_status() );
Neels Hofmeyrf65ce872021-09-23 18:40:10 +020010829 /* In SCCPlite tests, only one MSC is configured. These tests assume that three MSCs are configured, so only run
10830 * these in the AoIP test suite. */
10831 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
10832 execute( TC_stat_num_msc_connected_1() );
10833 execute( TC_stat_num_msc_connected_2() );
10834 execute( TC_stat_num_msc_connected_3() );
10835 }
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +020010836 execute( TC_stat_num_bts_connected_1() );
10837 execute( TC_stat_num_bts_connected_2() );
10838 execute( TC_stat_num_bts_connected_3() );
Harald Welte96c94412017-12-09 03:12:45 +010010839 execute( TC_ctrl() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +020010840 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER) {
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +020010841 execute( TC_ctrl_location() );
10842 }
Harald Welte898113b2018-01-31 18:32:21 +010010843
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020010844 execute( TC_si_default() );
Neels Hofmeyr66aeba42020-07-06 02:21:21 +020010845 execute( TC_si2quater_2_earfcns() );
10846 execute( TC_si2quater_3_earfcns() );
10847 execute( TC_si2quater_4_earfcns() );
10848 execute( TC_si2quater_5_earfcns() );
10849 execute( TC_si2quater_6_earfcns() );
Neels Hofmeyrad132f22020-07-08 02:20:16 +020010850 execute( TC_si2quater_12_earfcns() );
10851 execute( TC_si2quater_23_earfcns() );
10852 execute( TC_si2quater_32_earfcns() );
10853 execute( TC_si2quater_33_earfcns() );
10854 execute( TC_si2quater_42_earfcns() );
10855 execute( TC_si2quater_48_earfcns() );
10856 execute( TC_si2quater_49_earfcns() );
Pau Espin Pedrol85a84432020-07-20 18:45:03 +020010857 execute( TC_si_acc_rotate() );
Alexander Couzens4ad3a352020-09-10 22:29:12 +020010858 execute( TC_si_acc_ramp_rotate() );
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020010859
Harald Welte898113b2018-01-31 18:32:21 +010010860 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +010010861 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +010010862 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +010010863 execute( TC_chan_act_ack_noest() );
Philipp Maier9c60a622020-07-09 15:08:46 +020010864 execute( TC_chan_act_ack_noest_emerg() );
Philipp Maier606f07d2020-08-12 17:21:58 +020010865 execute( TC_chan_rqd_emerg_deny() );
Harald Welteae026692017-12-09 01:03:01 +010010866 execute( TC_chan_act_ack_est_ind_noreply() );
10867 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +010010868 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +010010869 execute( TC_chan_exhaustion() );
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +070010870 execute( TC_chan_deact_silence() );
Harald Welte4003d112017-12-09 22:35:39 +010010871 execute( TC_chan_rel_rll_rel_ind() );
10872 execute( TC_chan_rel_conn_fail() );
10873 execute( TC_chan_rel_hard_clear() );
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +020010874 execute( TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() );
10875 execute( TC_chan_rel_last_eutran_plmn_hard_clear_csfb() );
Harald Welte99787102019-02-04 10:41:36 +010010876 execute( TC_chan_rel_hard_clear_csfb() );
Harald Welted8c36cd2017-12-09 23:05:31 +010010877 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +020010878 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +010010879 execute( TC_chan_rel_a_reset() );
Pau Espin Pedrolc675b612020-01-09 19:55:40 +010010880 execute( TC_chan_rel_sccp_tiar_timeout() );
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +020010881 execute( TC_chan_rel_rr_cause() );
Harald Welte6f521d82017-12-11 19:52:02 +010010882
Harald Weltecfe2c962017-12-15 12:09:32 +010010883 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +010010884
10885 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +010010886 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +010010887 execute( TC_assignment_csd() );
10888 execute( TC_assignment_ctm() );
10889 execute( TC_assignment_sign() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +020010890 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
10891 execute( TC_assignment_aoip_tla_v6() );
10892 }
Harald Welte235ebf12017-12-15 14:18:16 +010010893 execute( TC_assignment_fr_a5_0() );
10894 execute( TC_assignment_fr_a5_1() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +020010895 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte8f67d1d2018-05-25 20:38:42 +020010896 execute( TC_assignment_fr_a5_1_codec_missing() );
10897 }
Harald Welte235ebf12017-12-15 14:18:16 +010010898 execute( TC_assignment_fr_a5_3() );
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +020010899 execute( TC_assignment_fr_a5_4() );
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +020010900 execute( TC_assignment_fr_a5_4_fail() );
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +020010901 execute( TC_assignment_fr_a5_not_sup() );
Harald Welte3c86ea02018-05-10 22:28:05 +020010902 execute( TC_ciph_mode_a5_0() );
10903 execute( TC_ciph_mode_a5_1() );
Oliver Smith50b98122021-07-09 15:00:28 +020010904 execute( TC_ciph_mode_a5_2_0() );
Oliver Smith1dff88d2021-07-09 08:45:51 +020010905 execute( TC_ciph_mode_a5_2_1() );
Harald Welte3c86ea02018-05-10 22:28:05 +020010906 execute( TC_ciph_mode_a5_3() );
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +020010907 execute( TC_ciph_mode_a5_4() );
Harald Welte16a4adf2017-12-14 18:54:01 +010010908
Harald Welte60aa5762018-03-21 19:33:13 +010010909 execute( TC_assignment_codec_fr() );
Neels Hofmeyr559d5d02021-04-16 16:50:49 +020010910 execute( TC_assignment_codec_fr_by_mode_modify() );
Harald Welte60aa5762018-03-21 19:33:13 +010010911 execute( TC_assignment_codec_hr() );
10912 execute( TC_assignment_codec_efr() );
10913 execute( TC_assignment_codec_amr_f() );
10914 execute( TC_assignment_codec_amr_h() );
Philipp Maier8a581d22019-03-26 18:32:48 +010010915
Neels Hofmeyrf246a922020-05-13 02:27:10 +020010916 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier8a581d22019-03-26 18:32:48 +010010917 execute( TC_assignment_codec_amr_f_S1() );
10918 execute( TC_assignment_codec_amr_h_S1() );
10919 execute( TC_assignment_codec_amr_f_S124() );
10920 execute( TC_assignment_codec_amr_h_S124() );
10921 execute( TC_assignment_codec_amr_f_S0() );
10922 execute( TC_assignment_codec_amr_f_S02() );
10923 execute( TC_assignment_codec_amr_f_S024() );
10924 execute( TC_assignment_codec_amr_f_S0247() );
10925 execute( TC_assignment_codec_amr_h_S0() );
10926 execute( TC_assignment_codec_amr_h_S02() );
10927 execute( TC_assignment_codec_amr_h_S024() );
10928 execute( TC_assignment_codec_amr_h_S0247() );
10929 execute( TC_assignment_codec_amr_f_S01234567() );
10930 execute( TC_assignment_codec_amr_f_S0234567() );
10931 execute( TC_assignment_codec_amr_f_zero() );
10932 execute( TC_assignment_codec_amr_f_unsupp() );
10933 execute( TC_assignment_codec_amr_h_S7() );
Neels Hofmeyr21863562020-11-26 00:34:33 +000010934 execute( TC_assignment_codec_amr_f_start_mode_auto() );
10935 execute( TC_assignment_codec_amr_h_start_mode_auto() );
Neels Hofmeyr3eb94562020-11-26 02:40:26 +000010936 execute( TC_assignment_codec_amr_f_start_mode_4() );
10937 execute( TC_assignment_codec_amr_h_start_mode_4() );
Neels Hofmeyr454d7922020-11-26 02:24:57 +000010938 execute( TC_assignment_codec_amr_startmode_cruft() );
Philipp Maier8a581d22019-03-26 18:32:48 +010010939 }
Harald Welte60aa5762018-03-21 19:33:13 +010010940
Philipp Maierac09bfc2019-01-08 13:41:39 +010010941 execute( TC_assignment_codec_fr_exhausted_req_hr() );
10942 execute( TC_assignment_codec_fr_exhausted_req_fr() );
10943 execute( TC_assignment_codec_fr_exhausted_req_fr_hr() );
10944 execute( TC_assignment_codec_fr_exhausted_req_hr_fr() );
10945 execute( TC_assignment_codec_hr_exhausted_req_fr() );
10946 execute( TC_assignment_codec_hr_exhausted_req_hr() );
10947 execute( TC_assignment_codec_hr_exhausted_req_hr_fr() );
10948 execute( TC_assignment_codec_hr_exhausted_req_fr_hr() );
10949 execute( TC_assignment_codec_req_hr_fr() );
10950 execute( TC_assignment_codec_req_fr_hr() );
Pau Espin Pedrol14475352021-07-22 15:48:16 +020010951 execute( TC_assignment_sdcch_exhausted_req_signalling() );
10952 execute( TC_assignment_sdcch_exhausted_req_signalling_tch_forbidden() );
10953 execute( TC_assignment_sdcch_exhausted_req_voice_tch_forbidden() );
Philipp Maierac09bfc2019-01-08 13:41:39 +010010954
Pau Espin Pedrol23510fb2021-07-20 17:00:38 +020010955 execute( TC_assignment_osmux() );
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +020010956
Harald Welte898113b2018-01-31 18:32:21 +010010957 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +010010958 execute( TC_rll_est_ind_inact_lchan() );
10959 execute( TC_rll_est_ind_inval_sapi1() );
10960 execute( TC_rll_est_ind_inval_sapi3() );
10961 execute( TC_rll_est_ind_inval_sacch() );
10962
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +070010963 /* DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
10964 execute( TC_tch_dlci_link_id_sapi() );
10965
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +070010966 /* SAPI N Reject triggered by RLL establishment failures */
10967 execute( TC_rll_rel_ind_sapi_n_reject() );
10968 execute( TC_rll_err_ind_sapi_n_reject() );
10969 execute( TC_rll_timeout_sapi_n_reject() );
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +070010970 execute( TC_rll_sapi_n_reject_dlci_cc() );
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +070010971
Harald Welte898113b2018-01-31 18:32:21 +010010972 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +010010973 execute( TC_paging_imsi_nochan() );
10974 execute( TC_paging_tmsi_nochan() );
10975 execute( TC_paging_tmsi_any() );
10976 execute( TC_paging_tmsi_sdcch() );
10977 execute( TC_paging_tmsi_tch_f() );
10978 execute( TC_paging_tmsi_tch_hf() );
10979 execute( TC_paging_imsi_nochan_cgi() );
10980 execute( TC_paging_imsi_nochan_lac_ci() );
10981 execute( TC_paging_imsi_nochan_ci() );
10982 execute( TC_paging_imsi_nochan_lai() );
10983 execute( TC_paging_imsi_nochan_lac() );
10984 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +010010985 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
10986 execute( TC_paging_imsi_nochan_rnc() );
10987 execute( TC_paging_imsi_nochan_lac_rnc() );
10988 execute( TC_paging_imsi_nochan_lacs() );
10989 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +010010990 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +010010991 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +010010992 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +010010993 execute( TC_paging_counter() );
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +010010994 execute( TC_paging_resp_unsol() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +010010995
10996 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +010010997 execute( TC_rsl_unknown_unit_id() );
10998
10999 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +010011000
11001 execute( TC_classmark() );
Harald Welteeddf0e92020-06-21 19:42:15 +020011002 execute( TC_common_id() );
Harald Welte898113b2018-01-31 18:32:21 +010011003 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +010011004 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +010011005 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +010011006 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +010011007 execute( TC_err_84_unknown_msg() );
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010011008
Harald Welte261af4b2018-02-12 21:20:39 +010011009 execute( TC_ho_int() );
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +020011010 execute( TC_ho_int_a5_0() );
11011 execute( TC_ho_int_a5_1() );
11012 execute( TC_ho_int_a5_3() );
11013 execute( TC_ho_int_a5_4() );
Neels Hofmeyr5f144212020-11-03 15:41:58 +000011014 execute( TC_ho_int_radio_link_failure() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011015
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +010011016 /* TC_ho_out_of_this_bsc is run last, see comment below */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +020011017 execute( TC_ho_out_fail_no_msc_response() );
11018 execute( TC_ho_out_fail_rr_ho_failure() );
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +020011019 execute( TC_ho_out_fail_no_result_after_ho_cmd() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011020
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010011021 execute( TC_ho_into_this_bsc() );
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +020011022 execute( TC_ho_into_this_bsc_a5_0() );
11023 execute( TC_ho_into_this_bsc_a5_1() );
11024 execute( TC_ho_into_this_bsc_a5_3() );
11025 execute( TC_ho_into_this_bsc_a5_4() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +020011026 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11027 execute( TC_ho_into_this_bsc_tla_v6() );
11028 }
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +020011029 execute( TC_srvcc_eutran_to_geran() );
Pau Espin Pedrol35801c32021-04-19 13:03:20 +020011030 execute( TC_srvcc_eutran_to_geran_ho_out() );
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +020011031 execute( TC_srvcc_eutran_to_geran_forbid_fast_return() );
11032 execute( TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011033 execute( TC_ho_in_fail_msc_clears() );
11034 execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
11035 execute( TC_ho_in_fail_no_detect() );
11036 execute( TC_ho_in_fail_no_detect2() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +010011037
Neels Hofmeyr91401012019-07-11 00:42:35 +020011038 execute( TC_ho_neighbor_config_1() );
11039 execute( TC_ho_neighbor_config_2() );
11040 execute( TC_ho_neighbor_config_3() );
11041 execute( TC_ho_neighbor_config_4() );
11042 execute( TC_ho_neighbor_config_5() );
11043 execute( TC_ho_neighbor_config_6() );
11044 execute( TC_ho_neighbor_config_7() );
11045
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +010011046 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010011047 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +010011048 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +020011049
11050 execute( TC_dyn_pdch_ipa_act_deact() );
11051 execute( TC_dyn_pdch_ipa_act_nack() );
11052 execute( TC_dyn_pdch_osmo_act_deact() );
11053 execute( TC_dyn_pdch_osmo_act_nack() );
Pau Espin Pedrol37a4c152021-11-16 19:02:23 +010011054 execute( TC_dyn_ts_sdcch8_act_deact() );
11055 execute( TC_dyn_ts_sdcch8_all_subslots_used() );
11056 execute( TC_dyn_ts_sdcch8_tch_call_act_deact() );
11057 execute( TC_dyn_ts_sdcch8_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +020011058
Stefan Sperling0796a822018-10-05 13:01:39 +020011059 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +020011060 execute( TC_chopped_ipa_payload() );
Stefan Sperling0796a822018-10-05 13:01:39 +020011061
Pau Espin Pedrol8f773632019-11-05 11:46:53 +010011062 /* Power control related */
11063 execute( TC_assignment_verify_ms_power_params_ie() );
Vadim Yanitskiy4b233042021-06-30 00:58:43 +020011064 execute( TC_c0_power_red_mode() );
Neels Hofmeyr4f118412020-06-04 15:25:10 +020011065
11066 /* MSC pooling */
11067 /* FIXME: in SCCPlite, indicating how many MSCs should be connected does currently not work. Since
11068 * RESET->RESET-ACK is unconditionally negotiated for all configured MSCs, they always all appear as connected
11069 * to osmo-bsc. The MSC pooling tests however require disconnecting selected MSCs, and hence don't work out as
11070 * intended on SCCPlite. So for now, run these only for SCCP/M3UA. */
11071 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11072 execute( TC_mscpool_L3Compl_on_1_msc() );
11073 execute( TC_mscpool_L3Complete_by_imsi_round_robin() );
11074 execute( TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() );
11075 execute( TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() );
11076 execute( TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() );
11077 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() );
11078 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_1() );
11079 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_2() );
11080 execute( TC_mscpool_LU_by_tmsi_from_other_PLMN() );
11081 execute( TC_mscpool_paging_and_response_imsi() );
11082 execute( TC_mscpool_paging_and_response_tmsi() );
11083 execute( TC_mscpool_no_allow_attach_round_robin() );
11084 execute( TC_mscpool_no_allow_attach_valid_nri() );
11085 }
11086
Harald Welte99f3ca02018-06-14 13:40:29 +020011087 execute( TC_early_conn_fail() );
11088 execute( TC_late_conn_fail() );
Oliver Smithaf03bef2021-08-24 15:34:51 +020011089 execute( TC_stats_conn_fail() );
Harald Welte99f3ca02018-06-14 13:40:29 +020011090
Philipp Maier783681c2020-07-16 16:47:06 +020011091 /* Emergency call handling (deny / allow) */
11092 execute( TC_assignment_emerg_setup_allow() );
11093 execute( TC_assignment_emerg_setup_deny_msc() );
11094 execute( TC_assignment_emerg_setup_deny_bts() );
Philipp Maier82812002020-08-13 18:48:27 +020011095 execute( TC_emerg_premption() );
11096
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +070011097 /* Frequency hopping parameters handling */
11098 execute( TC_fh_params_chan_activ() );
11099 execute( TC_fh_params_imm_ass() );
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +070011100 execute( TC_fh_params_assignment_cmd() );
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +070011101 execute( TC_fh_params_handover_cmd() );
Vadim Yanitskiyca974032020-09-01 07:20:39 +070011102 execute( TC_fh_params_si4_cbch() );
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020011103
11104 if (mp_enable_lcs_tests) {
11105 execute( TC_lcs_loc_req_for_active_ms() );
11106 execute( TC_lcs_loc_req_for_active_ms_ta_req() );
11107 execute( TC_lcs_loc_req_for_idle_ms() );
11108 execute( TC_lcs_loc_req_no_subscriber() );
11109 execute( TC_lcs_loc_req_for_active_ms_le_timeout() );
11110 execute( TC_lcs_loc_req_for_active_ms_le_timeout2() );
11111 execute( TC_lcs_loc_req_for_idle_ms_no_pag_resp() );
11112 execute( TC_cm_service_during_lcs_loc_req() );
11113 execute( TC_ho_during_lcs_loc_req() );
11114 }
Neels Hofmeyrbf037052020-10-28 22:52:02 +000011115
11116 execute( TC_no_msc() );
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000011117
11118 execute( TC_refuse_chan_act_to_vamos() );
11119 execute( TC_refuse_mode_modif_to_vamos() );
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000011120
11121 execute( TC_reassignment_fr() );
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020011122
11123 execute( TC_cm_reestablishment() );
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020011124
11125 execute( TC_imm_ass_post_chan_ack() );
11126 execute( TC_imm_ass_pre_chan_ack() );
Neels Hofmeyr23158742021-09-07 19:08:07 +020011127 execute( TC_imm_ass_pre_ts_ack() );
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020011128 execute( TC_imm_ass_pre_chan_ack_dyn_ts() );
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020011129 execute( TC_imm_ass_pre_ts_ack_dyn_ts() );
Neels Hofmeyr5d7d13f2021-09-07 14:44:36 +020011130
11131 execute( TC_ctrl_trx_rf_locked() );
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011132
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011133 execute( TC_ratectr_all_available_allocated() );
11134 execute( TC_ratectr_all_available_allocated_dyn() );
11135
Neels Hofmeyrb7581872021-11-07 14:02:49 +010011136 execute( TC_cm_serv_rej() );
11137
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011138 execute( TC_lost_sdcch_during_assignment() );
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +010011139
11140 /* Run TC_ho_out_of_this_bsc last, because it may trigger a segfault before osmo-bsc's patch
11141 * with change-id I5a3345ab0005a73597f5c27207480912a2f5aae6 */
11142 execute( TC_ho_out_of_this_bsc() );
Harald Welte28d943e2017-11-25 15:00:50 +010011143}
11144
11145}