blob: 34d3d036b46b32e99b541e8725cfbf3c0006764a [file] [log] [blame]
Harald Welte28d943e2017-11-25 15:00:50 +01001module BSC_Tests {
2
Harald Welte21b46bd2017-12-17 19:46:32 +01003/* Integration Tests for OsmoBSC
Harald Weltea0630032018-03-20 21:09:55 +01004 * (C) 2017-2018 by Harald Welte <laforge@gnumonks.org>
Harald Welte21b46bd2017-12-17 19:46:32 +01005 * All rights reserved.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
Harald Welte34b5a952019-05-27 11:54:11 +020010 * SPDX-License-Identifier: GPL-2.0-or-later
11 *
Harald Welte21b46bd2017-12-17 19:46:32 +010012 * This test suite tests OsmoBSC while emulating both multiple BTS + MS as
13 * well as the MSC. See README for more details.
14 *
15 * There are test cases that run in so-called 'handler mode' and test cases
16 * that run directly on top of the BSSAP and RSL CodecPorts. The "handler mode"
17 * tests abstract the multiplexing/demultiplexing of multiple SCCP connections
18 * and/or RSL channels and are hence suitable for higher-level test cases, while
19 * the "raw" tests directly on top of the CodecPorts are more suitable for lower-
20 * level testing.
21 */
22
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +020023friend module BSC_Tests_VAMOS;
24
Neels Hofmeyr4f118412020-06-04 15:25:10 +020025import from Misc_Helpers all;
Harald Welte4003d112017-12-09 22:35:39 +010026import from General_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010027import from Osmocom_Types all;
Harald Welteae026692017-12-09 01:03:01 +010028import from GSM_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010029import from IPL4asp_Types all;
30
Harald Welte6f521d82017-12-11 19:52:02 +010031import from BSSAP_Types all;
Harald Welte6811d102019-04-14 22:23:14 +020032import from RAN_Adapter all;
Harald Welte47cd0e32020-08-21 12:39:11 +020033import from BSSAP_LE_Adapter all;
34import from BSSAP_LE_CodecPort all;
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020035import from BSSAP_LE_Types all;
36import from BSSLAP_Types all;
Harald Welteae026692017-12-09 01:03:01 +010037import from BSSAP_CodecPort all;
38import from BSSMAP_Templates all;
Harald Welte28d943e2017-11-25 15:00:50 +010039import from IPA_Emulation all;
Stefan Sperling830dc9d2018-02-12 21:08:28 +010040import from IPA_CodecPort all;
Harald Welteae026692017-12-09 01:03:01 +010041import from IPA_Types all;
Stefan Sperling0796a822018-10-05 13:01:39 +020042import from IPA_Testing all;
Harald Welteae026692017-12-09 01:03:01 +010043import from RSL_Types all;
Harald Welte624f9632017-12-16 19:26:04 +010044import from RSL_Emulation all;
Daniel Willmann191e0d92018-01-17 12:44:35 +010045import from MGCP_Emulation all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010046import from MGCP_Templates all;
47import from MGCP_Types all;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +020048import from MGCP_CodecPort all;
Harald Welte28d943e2017-11-25 15:00:50 +010049
Harald Welte96c94412017-12-09 03:12:45 +010050import from Osmocom_CTRL_Functions all;
Harald Weltea5d2ab22017-12-09 14:21:42 +010051import from Osmocom_CTRL_Types all;
Harald Welteffe55fc2018-01-17 22:39:54 +010052import from Osmocom_CTRL_Adapter all;
Harald Welte96c94412017-12-09 03:12:45 +010053
Daniel Willmannebdecc02020-08-12 15:30:17 +020054import from StatsD_Types all;
55import from StatsD_CodecPort all;
56import from StatsD_CodecPort_CtrlFunct all;
57import from StatsD_Checker all;
58
Harald Weltebc03c762018-02-12 18:09:38 +010059import from Osmocom_VTY_Functions all;
60import from TELNETasp_PortType all;
61
Harald Welte6f521d82017-12-11 19:52:02 +010062import from MobileL3_CommonIE_Types all;
Harald Weltee3bd6582018-01-31 22:51:25 +010063import from MobileL3_Types all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010064import from MobileL3_RRM_Types all;
Harald Welte6f521d82017-12-11 19:52:02 +010065import from L3_Templates all;
66import from GSM_RR_Types all;
67
Stefan Sperlingc307e682018-06-14 15:15:46 +020068import from SCCP_Templates all;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010069import from BSSMAP_Templates all;
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020070import from BSSMAP_LE_Templates all;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010071
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010072import from SCCPasp_Types all;
73
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020074import from GSM_SystemInformation all;
75import from GSM_RestOctets all;
Neels Hofmeyrad132f22020-07-08 02:20:16 +020076import from TCCConversion_Functions all;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020077
Neels Hofmeyrbf720202021-10-02 12:58:24 +020078type record of integer integer_list;
79
Harald Welte5d1a2202017-12-13 19:51:29 +010080const integer NUM_BTS := 3;
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +020081const integer NUM_BTS_CFG := 4; /* we have 4 BTS in the osmo-bsc.cfg (for inter-BSC HO tests) but use only 3 */
Neels Hofmeyrf246a922020-05-13 02:27:10 +020082const integer NUM_MSC := 3;
Harald Welteae026692017-12-09 01:03:01 +010083const float T3101_MAX := 12.0;
Harald Welte28d943e2017-11-25 15:00:50 +010084
Harald Welte799c97b2017-12-14 17:50:30 +010085/* make sure to sync this with the osmo-bts.cfg you're using */
Philipp Maiercb6cc482018-03-26 13:08:00 +020086const integer NUM_TCHH_PER_BTS := 2;
87const integer NUM_TCHF_PER_BTS := 4;
Neels Hofmeyr74083c22020-07-29 00:43:01 +020088const integer NUM_SDCCH_PER_BTS := 3;
Harald Welte799c97b2017-12-14 17:50:30 +010089
Neels Hofmeyrbf720202021-10-02 12:58:24 +020090/* Default Training Sequence Code expected for bts[i]:
91 * BTS 0 has BSIC 10 (and no explicit timeslot training_sequence_code config), so expecting TSC = (BSIC & 7) = 2.
92 * BTS 1 has BSIC 11, TSC = (BSIC & 7) = 3.
93 * BTS 2 has BSIC 12, TSC = (BSIC & 7) = 4.
94 * BTS 2 has BSIC 12, TSC = (BSIC & 7) = 4.
95 */
96const integer_list BTS_TSC := {
97 2,
98 3,
99 4,
100 4
101}
Harald Welte4003d112017-12-09 22:35:39 +0100102
Harald Welte21b46bd2017-12-17 19:46:32 +0100103/* per-BTS state which we keep */
Harald Welte96c94412017-12-09 03:12:45 +0100104type record BTS_State {
Harald Welte21b46bd2017-12-17 19:46:32 +0100105 /* component reference to the IPA_Client component used for RSL */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100106 IPA_Client rsl
Harald Welte96c94412017-12-09 03:12:45 +0100107}
108
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200109/* Default list of counters for an 'msc' entity. */
110const CounterNameVals counternames_msc_mscpool := {
111 { "mscpool:subscr:new", 0 },
112 { "mscpool:subscr:known", 0 },
113 { "mscpool:subscr:reattach", 0 },
114 { "mscpool:subscr:attach_lost", 0 },
115 { "mscpool:subscr:paged", 0 }
116};
117
Neels Hofmeyrbf037052020-10-28 22:52:02 +0000118/* List of global mscpool counters, not related to a specific 'msc' entity. */
119const CounterNameVals counternames_bsc_mscpool := {
120 { "mscpool:subscr:no_msc", 0 }
121};
122
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000123/* Default list of counters for 'bsc' and 'bts' entities. */
124const CounterNameVals counternames_bsc_bts_handover := {
125 { "assignment:attempted", 0 },
126 { "assignment:completed", 0 },
127 { "assignment:stopped", 0 },
128 { "assignment:no_channel", 0 },
129 { "assignment:timeout", 0 },
130 { "assignment:failed", 0 },
131 { "assignment:error", 0 },
132
133 { "handover:attempted", 0 },
134 { "handover:completed", 0 },
135 { "handover:stopped", 0 },
136 { "handover:no_channel", 0 },
137 { "handover:timeout", 0 },
138 { "handover:failed", 0 },
139 { "handover:error", 0 },
140
141 { "intra_cell_ho:attempted", 0 },
142 { "intra_cell_ho:completed", 0 },
143 { "intra_cell_ho:stopped", 0 },
144 { "intra_cell_ho:no_channel", 0 },
145 { "intra_cell_ho:timeout", 0 },
146 { "intra_cell_ho:failed", 0 },
147 { "intra_cell_ho:error", 0 },
148
149 { "intra_bsc_ho:attempted", 0 },
150 { "intra_bsc_ho:completed", 0 },
151 { "intra_bsc_ho:stopped", 0 },
152 { "intra_bsc_ho:no_channel", 0 },
153 { "intra_bsc_ho:timeout", 0 },
154 { "intra_bsc_ho:failed", 0 },
155 { "intra_bsc_ho:error", 0 },
156
157 { "interbsc_ho_out:attempted", 0 },
158 { "interbsc_ho_out:completed", 0 },
159 { "interbsc_ho_out:stopped", 0 },
160 { "interbsc_ho_out:timeout", 0 },
161 { "interbsc_ho_out:failed", 0 },
162 { "interbsc_ho_out:error", 0 },
163
164 { "interbsc_ho_in:attempted", 0 },
165 { "interbsc_ho_in:completed", 0 },
166 { "interbsc_ho_in:stopped", 0 },
167 { "interbsc_ho_in:no_channel", 0 },
168 { "interbsc_ho_in:timeout", 0 },
169 { "interbsc_ho_in:failed", 0 },
170 { "interbsc_ho_in:error", 0 }
171};
172
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100173const CounterNameVals counternames_bts_handover := {
174 { "incoming_intra_bsc_ho:attempted", 0 },
175 { "incoming_intra_bsc_ho:completed", 0 },
176 { "incoming_intra_bsc_ho:stopped", 0 },
177 { "incoming_intra_bsc_ho:no_channel", 0 },
178 { "incoming_intra_bsc_ho:timeout", 0 },
179 { "incoming_intra_bsc_ho:failed", 0 },
180 { "incoming_intra_bsc_ho:error", 0 }
181};
182
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200183/* Set of all System Information received during one RSL port's startup.
184 * Note that some System Information may be sent on RSL, but lacking actual SI data, to indicate that the BTS should not
185 * broadcast that SI type. That will be reflected as 'omit' here.
186 */
187type record SystemInformationConfig {
188 SystemInformationType1 si1 optional,
189 SystemInformationType2 si2 optional,
190 SystemInformationType2bis si2bis optional,
191 SystemInformationType2ter si2ter optional,
Neels Hofmeyrad132f22020-07-08 02:20:16 +0200192 SI2quaterRestOctetsList si2quater optional,
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200193 SystemInformationType3 si3 optional,
194 SystemInformationType4 si4 optional,
Pau Espin Pedrol28652d82021-02-09 20:20:17 +0100195 SystemInformationType13 si13 optional,
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200196 SystemInformationType5 si5 optional,
197 SystemInformationType5bis si5bis optional,
198 SystemInformationType5ter si5ter optional,
199 SystemInformationType6 si6 optional
200};
201
202const SystemInformationConfig SystemInformationConfig_omit := {
203 si1 := omit,
204 si2 := omit,
205 si2bis := omit,
206 si2ter := omit,
207 si2quater := omit,
208 si3 := omit,
209 si4 := omit,
210 si13 := omit,
211 si5 := omit,
212 si5bis := omit,
213 si5ter := omit,
214 si6 := omit
215};
216
217/* tr_EUTRAN_CellDesc with defaults used in BSC_Tests.ttcn */
218template EUTRAN_CellDesc tr_EUTRAN_CellDesc_default(template (present) uint16_t e_arfcn := ?,
219 template uint3_t meas_bw := 3)
220:= tr_EUTRAN_CellDesc(e_arfcn := e_arfcn,
221 meas_bw_presence := '1'B,
222 meas_bw := meas_bw);
223
224/* tr_EUTRAN_NeighbourCells with defaults used in BSC_Tests.ttcn */
Harald Welte65e419a2020-08-21 12:38:33 +0200225template EUTRAN_NeighbourCells tr_EUTRAN_NeighbourCells_default(template (present) EUTRAN_CellDescs cell_desc_list := { tr_EUTRAN_CellDesc_default },
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200226 template uint3_t prio := 3,
227 template (present) uint5_t thresh_high := 20,
228 template uint5_t thresh_low := 10,
229 template uint5_t qrxlevmin := 22)
230:= tr_EUTRAN_NeighbourCells(
231 cell_desc_list := cell_desc_list,
232 prio_presence := '1'B,
233 prio := prio,
234 thresh_high := thresh_high,
235 thresh_low_presence := '1'B,
236 thresh_low := thresh_low,
237 qrxlevmin_presence := '1'B,
238 qrxlevmin := qrxlevmin);
239
240template SystemInformationConfig SystemInformationConfig_default := {
241 si1 := {
242 cell_chan_desc := '8FB38000000000000000000000000000'O,
243 rach_control := {
244 max_retrans := RACH_MAX_RETRANS_7,
245 tx_integer := '1001'B,
246 cell_barr_access := false,
247 re_not_allowed := true,
248 acc := '0000010000000000'B
249 },
250 rest_octets := ?
251 },
252 si2 := {
253 bcch_freq_list := '00000000000000000000000000000000'O,
254 ncc_permitted := '11111111'B,
255 rach_control := {
256 max_retrans := RACH_MAX_RETRANS_7,
257 tx_integer := '1001'B,
258 cell_barr_access := false,
259 re_not_allowed := true,
260 acc := '0000010000000000'B
261 }
262 },
263 si2bis := omit,
264 si2ter := {
265 extd_bcch_freq_list := '8E320000000000000000000000000800'O,
266 rest_octets := ?
267 },
268 si2quater := {
269 tr_SI2quaterRestOctets_EUTRAN( repeated_neigh_cells := { tr_EUTRAN_NeighbourCells_default } )
270 },
271 si3 := {
272 cell_id := 0,
273 lai := {
274 mcc_mnc := '001F01'H,
275 lac := 1
276 },
277 ctrl_chan_desc := {
278 msc_r99 := true,
279 att := true,
280 bs_ag_blks_res := 1,
281 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
282 si22ind := false,
283 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
284 spare := '00'B,
285 bs_pa_mfrms := 3,
286 t3212 := 30
287 },
288 cell_options := {
289 dn_ind := false,
290 pwrc := false,
291 dtx := MS_SHALL_USE_UL_DTX,
292 radio_link_tout_div4 := 7
293 },
294 cell_sel_par := {
295 cell_resel_hyst_2dB := 2,
296 ms_txpwr_max_cch := 7,
297 acs := '0'B,
298 neci := true,
299 rxlev_access_min := 0
300 },
301 rach_control := {
302 max_retrans := RACH_MAX_RETRANS_7,
303 tx_integer := '1001'B,
304 cell_barr_access := false,
305 re_not_allowed := true,
306 acc := '0000010000000000'B
307 },
308 rest_octets := {
309 sel_params := {
310 presence := '0'B,
311 params := omit
312 },
313 pwr_offset := {
314 presence := '0'B,
315 offset := omit
316 },
317 si_2ter_ind := '1'B,
318 early_cm_ind := '0'B,
319 sched_where := {
320 presence := '0'B,
321 where := omit
322 },
323 gprs_ind := {
324 presence := '1'B,
325 ind := {
326 ra_colour := 0,
327 si13_pos := '0'B
328 }
329 },
330 umts_early_cm_ind := '1'B,
331 si2_quater_ind := {
332 presence := '1'B,
333 ind := '0'B
334 },
335 iu_mode_ind := omit,
336 si21_ind := {
337 presence := '0'B,
338 pos := omit
339 }
340 }
341 },
342 si4 := {
343 lai := {
344 mcc_mnc := '001F01'H,
345 lac := 1
346 },
347 cell_sel_par := {
348 cell_resel_hyst_2dB := 2,
349 ms_txpwr_max_cch := 7,
350 acs := '0'B,
351 neci := true,
352 rxlev_access_min := 0
353 },
354 rach_control := {
355 max_retrans := RACH_MAX_RETRANS_7,
356 tx_integer := '1001'B,
357 cell_barr_access := false,
358 re_not_allowed := true,
359 acc := '0000010000000000'B
360 },
Neels Hofmeyr74083c22020-07-29 00:43:01 +0200361 cbch_chan_desc := {
362 iei := '64'O,
363 v := {
364 chan_nr := {
365 u := {
366 sdcch4 := {
367 tag := '001'B,
368 sub_chan := 2
369 }
370 },
371 tn := 0
372 },
373 tsc := 2,
374 h := false,
375 arfcn := 871,
376 maio_hsn := omit
377 }
378 },
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200379 cbch_mobile_alloc := omit,
380 rest_octets := {
381 sel_params := {
382 presence := '0'B,
383 params := omit
384 },
385 pwr_offset := {
386 presence := '0'B,
387 offset := omit
388 },
389 gprs_ind := {
390 presence := '1'B,
391 ind := {
392 ra_colour := 0,
393 si13_pos := '0'B
394 }
395 },
396 s_presence := '0'B,
397 s := omit
398 }
399 },
Pau Espin Pedrol28652d82021-02-09 20:20:17 +0100400 si13 := {
401 rest_octets := {
402 presence := '1'B,
403 bcch_change_mark := ?,
404 si_change_field := '0000'B,
405 presence2 := '0'B,
406 si13_change_mark := omit,
407 gprs_ma := omit,
408 zero := '0'B, /* PBCCH not present in cell */
409 rac := 0,
410 spgc_ccch_sup := '0'B,
411 priority_access_thr := '110'B,
412 network_control_order := '00'B,
413 gprs_cell_opts := {
414 nmo := '01'B,
415 t3168 := '011'B,
416 t3192 := '010'B,
417 drx_timer_max := '011'B,
418 access_burst_type := '0'B,
419 control_ack_type := '1'B,
420 bs_cv_max := 15,
421 pan_presence := '1'B,
422 pan_dec := 1,
423 pan_inc := 1,
424 pan_max := '111'B,
425 ext_info_presence := ?,
426 ext_info_length := *,
427 ext_info := *
428 },
429 gprs_pwr_ctrl_params := {
430 alpha := 0,
431 t_avg_w := '10000'B,
432 t_avg_t := '10000'B,
433 pc_meas_chan := '0'B,
434 n_avg_i := '1000'B
435 }
436 }
437 },
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200438 si5 := {
439 bcch_freq_list := '10000000000000000000000000000000'O
440 },
441 si5bis := omit,
442 si5ter := {
443 extd_bcch_freq_list := '9E050020000000000000000000000000'O
444 },
445 si6 := {
446 cell_id := 0,
447 lai := {
448 mcc_mnc := '001F01'H,
449 lac := 1
450 },
451 cell_options := {
452 dtx_ext := '1'B,
453 pwrc := false,
454 dtx := '01'B,
455 radio_link_timeout := '0111'B
456 },
457 ncc_permitted := '11111111'B,
458 rest_octets := ?
459 }
460 };
461
462
463/* List of all the System Information received on all RSL ports */
464type record of SystemInformationConfig SystemInformationConfig_list;
465
466function f_sysinfo_dec_raw(inout SystemInformationConfig si, RSL_Message rsl)
467{
468 var RSL_IE_Body sysinfo_type_ie;
469 var RSL_IE_SysinfoType si_type;
470 var octetstring data;
471
472 if (f_rsl_find_ie(rsl, RSL_IE_SYSINFO_TYPE, sysinfo_type_ie) == false) {
473 setverdict(fail, "Cannot find RSL_IE_SYSINFO_TYPE");
474 mtc.stop;
475 }
476 si_type := sysinfo_type_ie.sysinfo_type;
477
478 if (rsl.msg_type == RSL_MT_BCCH_INFO) {
479 var RSL_IE_Body bcch_ie;
480 if (f_rsl_find_ie(rsl, RSL_IE_FULL_BCCH_INFO, bcch_ie)) {
481 data := bcch_ie.other.payload;
482 }
483 } else if (rsl.msg_type == RSL_MT_SACCH_FILL) {
484 var RSL_IE_Body l3_ie;
485 if (f_rsl_find_ie(rsl, RSL_IE_L3_INFO, l3_ie)) {
486 data := l3_ie.l3_info.payload;
487 }
488 } else {
489 setverdict(fail, "Don't understand this System Information message");
490 mtc.stop;
491 }
492
493 var boolean handled := false;
494
495 if (rsl.msg_type == RSL_MT_BCCH_INFO) {
496 handled := true;
497
498 if (si_type == RSL_SYSTEM_INFO_1) {
499 if (not isbound(data)) {
500 si.si1 := omit;
501 } else {
502 si.si1 := dec_SystemInformation(data).payload.si1;
503 }
504 } else if (si_type == RSL_SYSTEM_INFO_2) {
505 if (not isbound(data)) {
506 si.si2 := omit;
507 } else {
508 si.si2 := dec_SystemInformation(data).payload.si2;
509 }
510 } else if (si_type == RSL_SYSTEM_INFO_2bis) {
511 if (not isbound(data)) {
512 si.si2bis := omit;
513 } else {
514 si.si2bis := dec_SystemInformation(data).payload.si2bis;
515 }
516 } else if (si_type == RSL_SYSTEM_INFO_2ter) {
517 if (not isbound(data)) {
518 si.si2ter := omit;
519 } else {
520 si.si2ter := dec_SystemInformation(data).payload.si2ter;
521 }
522 } else if (si_type == RSL_SYSTEM_INFO_2quater) {
523 if (not isbound(data)) {
524 si.si2quater := {};
525 } else {
526 var SystemInformationType2quater decoded := dec_SystemInformation(data).payload.si2quater;
527 /* this is a *record* of SI2quaterRestOctets! (multiplexed) */
528 si.si2quater[decoded.rest_octets.si2quater_index] := decoded.rest_octets;
529 }
530 } else if (si_type == RSL_SYSTEM_INFO_3) {
531 if (not isbound(data)) {
532 si.si3 := omit;
533 } else {
534 si.si3 := dec_SystemInformation(data).payload.si3;
535 }
536 } else if (si_type == RSL_SYSTEM_INFO_4) {
537 if (not isbound(data)) {
538 si.si4 := omit;
539 } else {
540 si.si4 := dec_SystemInformation(data).payload.si4;
541 }
542 } else if (si_type == RSL_SYSTEM_INFO_13) {
543 if (not isbound(data)) {
544 si.si13 := omit;
545 } else {
Pau Espin Pedrol28652d82021-02-09 20:20:17 +0100546 si.si13 := dec_SystemInformation(data).payload.si13;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200547 }
548 } else {
549 handled := false;
550 }
551 } else if (rsl.msg_type == RSL_MT_SACCH_FILL) {
552 handled := true;
553
554 if (si_type == RSL_SYSTEM_INFO_5) {
555 if (not isbound(data)) {
556 si.si5 := omit;
557 } else {
558 si.si5 := dec_SystemInformation(data).payload.si5;
559 }
560 } else if (si_type == RSL_SYSTEM_INFO_5bis) {
561 if (not isbound(data)) {
562 si.si5bis := omit;
563 } else {
564 si.si5bis := dec_SystemInformation(data).payload.si5bis;
565 }
566 } else if (si_type == RSL_SYSTEM_INFO_5ter) {
567 if (not isbound(data)) {
568 si.si5ter := omit;
569 } else {
570 si.si5ter := dec_SystemInformation(data).payload.si5ter;
571 }
572 } else if (si_type == RSL_SYSTEM_INFO_6) {
573 if (not isbound(data)) {
574 si.si6 := omit;
575 } else {
576 si.si6 := dec_SystemInformation(data).payload.si6;
577 }
578 } else {
579 handled := false;
580 }
581 }
582
583 if (not handled) {
584 setverdict(fail, "Unexpected SI type in ", rsl.msg_type, " message: ", si_type);
585 }
586}
587
Harald Weltea4ca4462018-02-09 00:17:14 +0100588type component test_CT extends CTRL_Adapter_CT {
Harald Welte21b46bd2017-12-17 19:46:32 +0100589 /* Array of per-BTS state */
Harald Welte96c94412017-12-09 03:12:45 +0100590 var BTS_State bts[NUM_BTS];
Harald Welte89ab1912018-02-23 18:56:29 +0100591 /* RSL common Channel Port (for RSL_Emulation) */
592 port RSL_CCHAN_PT RSL_CCHAN[NUM_BTS];
Harald Welte21b46bd2017-12-17 19:46:32 +0100593 /* array of per-BTS RSL test ports */
Harald Welteae026692017-12-09 01:03:01 +0100594 port IPA_RSL_PT IPA_RSL[NUM_BTS];
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100595 port IPA_CODEC_PT IPA; /* Required for compilation of TC_rsl_unknown_unit_id() */
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +0200596 /* CTRL muxed over IPA in SCCPlite conn BSC<->MSC (or BSC-NAT) */
597 port IPA_CTRL_PT SCCPLITE_IPA_CTRL;
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100598 /* Configure/manage IPA_Emulation: */
599 port IPA_CFG_PT IPA_CFG_PORT;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100600
Daniel Willmann191e0d92018-01-17 12:44:35 +0100601 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +0100602 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100603
Daniel Willmannebdecc02020-08-12 15:30:17 +0200604 /* StatsD */
605 var StatsD_Checker_CT vc_STATSD;
606
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200607 var RAN_Adapter g_bssap[NUM_MSC];
Harald Welte47cd0e32020-08-21 12:39:11 +0200608 var BSSAP_LE_Adapter g_bssap_le;
Harald Weltea4ca4462018-02-09 00:17:14 +0100609 /* for old legacy-tests only */
610 port BSSAP_CODEC_PT BSSAP;
Harald Welte47cd0e32020-08-21 12:39:11 +0200611 port BSSAP_LE_CODEC_PT BSSAP_LE;
Harald Weltea4ca4462018-02-09 00:17:14 +0100612
Harald Welte21b46bd2017-12-17 19:46:32 +0100613 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +0100614 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +0100615
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200616 /* Osmux is enabled through VTY */
617 var boolean g_osmux_enabled := false;
618
Pau Espin Pedrolc675b612020-01-09 19:55:40 +0100619 /*Configure T(tias) over VTY, seconds */
620 var integer g_bsc_sccp_timer_ias := 7 * 60;
621 /*Configure T(tiar) over VTY, seconds */
622 var integer g_bsc_sccp_timer_iar := 15 * 60;
623
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +0200624 /* global test case guard timer (actual timeout value is set in f_init()) */
Harald Welteae026692017-12-09 01:03:01 +0100625 timer T_guard := 30.0;
626
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200627 var CounterNameValsList g_ctr_msc;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000628 var CounterNameValsList g_ctr_bsc;
629 var CounterNameValsList g_ctr_bts;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200630
631 /* System Information bytes as received during RSL startup, for each RSL[idx]. */
632 var SystemInformationConfig_list g_system_information := {};
Harald Welte28d943e2017-11-25 15:00:50 +0100633}
634
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200635type record of charstring phys_chan_configs;
Harald Welte28d943e2017-11-25 15:00:50 +0100636modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +0100637 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +0100638 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100639 /* port number to which to establish the IPA OML connections */
640 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +0100641 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +0100642 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +0100643 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +0100644 integer mp_bsc_ctrl_port := 4249;
Daniel Willmannebdecc02020-08-12 15:30:17 +0200645 /* port number to which to listen for STATSD metrics */
646 integer mp_bsc_statsd_port := 8125;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100647 /* IP address at which the test binds */
648 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100649
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200650 RAN_Configurations mp_bssap_cfg := {
651 {
652 transport := BSSAP_TRANSPORT_AoIP,
653 sccp_service_type := "mtp3_itu",
654 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
655 own_pc := 185, /* 0.23.1 first MSC emulation */
656 own_ssn := 254,
657 peer_pc := 187, /* 0.23.3 osmo-bsc */
658 peer_ssn := 254,
659 sio := '83'O,
Harald Weltecb0cc432020-06-21 19:42:31 +0200660 rctx := 1
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200661 },
662 {
663 transport := BSSAP_TRANSPORT_AoIP,
664 sccp_service_type := "mtp3_itu",
665 sctp_addr := { 23906, "127.0.0.1", 2905, "127.0.0.1" },
666 own_pc := 2, /* 0.0.2 second MSC emulation */
667 own_ssn := 254,
668 peer_pc := 187, /* 0.23.3 osmo-bsc */
669 peer_ssn := 254,
670 sio := '83'O,
671 rctx := 2
672 },
673 {
674 transport := BSSAP_TRANSPORT_AoIP,
675 sccp_service_type := "mtp3_itu",
676 sctp_addr := { 23907, "127.0.0.1", 2905, "127.0.0.1" },
677 own_pc := 3, /* 0.0.3 third MSC emulation */
678 own_ssn := 254,
679 peer_pc := 187, /* 0.23.3 osmo-bsc */
680 peer_ssn := 254,
681 sio := '83'O,
682 rctx := 3
683 }
Harald Weltea4ca4462018-02-09 00:17:14 +0100684 };
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +0200685
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200686 /* Must match per BTS config in osmo-bsc.cfg */
687 phys_chan_configs phys_chan_config := {
688 "CCCH+SDCCH4+CBCH",
689 "TCH/F",
690 "TCH/F",
691 "TCH/F",
692 "TCH/F",
Vadim Yanitskiy343c9eb2021-07-16 18:36:01 +0600693 "TCH/H",
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200694 "PDCH",
695 "PDCH"
696 };
697
Harald Welte47cd0e32020-08-21 12:39:11 +0200698 BSSAP_LE_Configuration mp_bssap_le_cfg := {
699 sccp_service_type := "mtp3_itu",
700 sctp_addr := { 23908, "127.0.0.1", 2905, "127.0.0.1" },
Neels Hofmeyrac086c12020-09-18 23:46:42 +0200701 own_pc := 190, /* 0.23.6 SMLC emulation */
Harald Welte47cd0e32020-08-21 12:39:11 +0200702 own_ssn := 252, /* SMLC side SSN */
703 peer_pc := 187, /* 0.23.3 osmo-bsc */
704 peer_ssn := 250, /* BSC side SSN */
705 sio := '83'O,
706 rctx := 6
707 };
Neels Hofmeyrcfe44062020-10-15 02:28:08 +0200708 boolean mp_enable_lcs_tests := true;
Harald Welte47cd0e32020-08-21 12:39:11 +0200709
Pau Espin Pedrol8f30ccd2019-11-01 17:30:57 +0100710 /* Value set in osmo-bsc.cfg "ms max power" */
711 uint8_t mp_exp_ms_power_level := 7;
Harald Weltea4ca4462018-02-09 00:17:14 +0100712}
713
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +0200714friend function f_gen_test_hdlr_pars(integer bssap_idx := 0) return TestHdlrParams {
Philipp Maier48604732018-10-09 15:00:37 +0200715
716 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200717 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier48604732018-10-09 15:00:37 +0200718 pars.aoip := true;
719 } else {
720 pars.aoip := false;
721 }
Pau Espin Pedrol8f30ccd2019-11-01 17:30:57 +0100722 pars.exp_ms_power_level := mp_exp_ms_power_level;
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200723 pars.mscpool.bssap_idx := bssap_idx;
Neels Hofmeyrbf720202021-10-02 12:58:24 +0200724 pars.expect_tsc := BTS_TSC[0];
Vadim Yanitskiy96bb9cb2021-12-10 21:14:15 +0300725 pars.imsi := f_rnd_imsi('00101'H);
726
727 log(testcasename(), ": using IMSI ", pars.imsi);
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200728
Philipp Maier48604732018-10-09 15:00:37 +0200729 return pars;
730}
731
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200732/* Convenience functions for rate counters using g_ctr_msc. */
733
734private function f_ctrs_msc_init(integer mscs_count := NUM_MSC, CounterNameVals counternames := counternames_msc_mscpool) runs on test_CT {
735 g_ctr_msc := f_counter_name_vals_get_n(IPA_CTRL, "msc", mscs_count, counternames);
736 log("initial msc rate counters: ", g_ctr_msc);
737}
738
739private function f_ctrs_msc_add(integer msc_nr, charstring countername, integer val := 1) runs on test_CT {
Neels Hofmeyr9656e922020-06-30 01:27:01 +0200740 f_counter_name_vals_list_add(g_ctr_msc, msc_nr, countername, val);
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200741}
742
743/* f_ctrs_msc_init();
744 * f_do_thing(on_msc := 0);
745 * f_do_thing(on_msc := 0);
746 * f_do_other(on_msc := 1);
747 * f_ctrs_msc_add(0, "thing", 2);
748 * f_ctrs_msc_add(1, "other");
749 * f_ctrs_msc_verify();
750 */
751private function f_ctrs_msc_verify() runs on test_CT {
752 log("verifying msc rate counters: ", g_ctr_msc);
753 f_counter_name_vals_expect_n(IPA_CTRL, "msc", g_ctr_msc);
754}
755
756/* convenience: f_ctrs_msc_add() and f_ctrs_msc_verify() in one call.
757 * f_ctrs_msc_init();
758 * f_do_thing(on_msc := 0);
759 * f_do_thing(on_msc := 0);
760 * f_do_thing(on_msc := 0);
761 * f_ctrs_msc_expect(0, "thing", 3);
762 */
763private function f_ctrs_msc_expect(integer msc_nr, charstring countername, integer val := 1) runs on test_CT {
764 f_ctrs_msc_add(msc_nr, countername, val);
765 f_ctrs_msc_verify();
766}
767
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000768/* Convenience functions for rate counters using g_ctr_bts, always also including g_ctr_bsc. */
769
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100770private function f_ctrs_bts_init(integer bts_count := NUM_BTS, CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000771 g_ctr_bts := f_counter_name_vals_get_n(IPA_CTRL, "bts", bts_count, counternames);
Neels Hofmeyr4dec8cc2021-11-29 15:59:44 +0100772 log("initial bts rate counters: ", g_ctr_bts);
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100773}
774
775function f_ctrs_bsc_and_bts_init(integer bts_count := NUM_BTS, CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
776 f_ctrs_bts_init(bts_count, counternames);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000777 f_ctrs_bsc_init(counternames);
778}
779
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100780private function f_ctrs_bsc_and_bts_handover_init(integer bts_count := NUM_BTS) runs on test_CT {
781 var CounterNameVals bts_names := counternames_bsc_bts_handover & counternames_bts_handover;
Neels Hofmeyr4dec8cc2021-11-29 15:59:44 +0100782 f_ctrs_bts_init(bts_count, bts_names);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100783 f_ctrs_bsc_init(counternames_bsc_bts_handover);
784}
785
786private function f_ctrs_bts_add(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000787 f_counter_name_vals_list_add(g_ctr_bts, bts_nr, countername, val);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100788}
789
790private function f_ctrs_bsc_and_bts_add(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
791 f_ctrs_bts_add(bts_nr, countername, val);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000792 f_ctrs_bsc_add(countername, val);
793}
794
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100795function f_ctrs_bts_verify() runs on test_CT {
796 f_counter_name_vals_expect_n(IPA_CTRL, "bts", g_ctr_bts);
797}
798
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000799/* f_ctrs_bsc_and_bts_init();
800 * f_do_thing(on_bts := 0);
801 * f_do_thing(on_bts := 0);
802 * f_do_other(on_bts := 1);
803 * f_ctrs_bsc_and_bts_add(0, "thing", 2);
804 * f_ctrs_bsc_and_bts_add(1, "other");
805 * f_ctrs_bsc_and_bts_verify();
806 */
807private function f_ctrs_bsc_and_bts_verify() runs on test_CT {
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100808 f_ctrs_bts_verify();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000809 f_ctrs_bsc_verify();
810}
811
812/* convenience: f_ctrs_bsc_and_bts_add() and f_ctrs_bsc_and_bts_verify() in one call.
813 * f_ctrs_bsc_and_bts_init();
814 * f_do_thing(on_bts := 0);
815 * f_do_thing(on_bts := 0);
816 * f_do_thing(on_bts := 0);
817 * f_ctrs_bsc_and_bts_expect(0, "thing", 3);
818 */
819private function f_ctrs_bsc_and_bts_expect(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
820 f_ctrs_bsc_and_bts_add(bts_nr, countername, val);
821 f_ctrs_bsc_and_bts_verify();
822}
823
824
825/* Convenience functions for rate counters using g_ctr_bsc. */
826
827private function f_ctrs_bsc_init(CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
828 g_ctr_bsc := f_counter_name_vals_get_n(IPA_CTRL, "bsc", 1, counternames);
829 log("initial bsc rate counters: ", g_ctr_bsc);
830}
831
832private function f_ctrs_bsc_add(charstring countername, integer val := 1) runs on test_CT {
833 f_counter_name_vals_list_add(g_ctr_bsc, 0, countername, val);
834}
835
836/* f_ctrs_bsc_init();
837 * f_do_thing();
838 * f_do_thing();
839 * f_do_other();
840 * f_ctrs_bsc_add("thing", 2);
841 * f_ctrs_bsc_add("other");
842 * f_ctrs_bsc_verify();
843 */
844private function f_ctrs_bsc_verify() runs on test_CT {
845 f_counter_name_vals_expect_n(IPA_CTRL, "bsc", g_ctr_bsc);
846}
847
848/* convenience: f_ctrs_bsc_add() and f_ctrs_bsc_verify() in one call.
849 * f_ctrs_bsc_init();
850 * f_do_thing();
851 * f_ctrs_bsc_expect("thing", 1);
852 */
853private function f_ctrs_bsc_expect(charstring countername, integer val := 1) runs on test_CT {
854 f_ctrs_bsc_add(countername, val);
855 f_ctrs_bsc_verify();
856}
857
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200858
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +0200859friend function f_shutdown_helper() runs on test_CT {
Neels Hofmeyr18997492021-12-13 17:30:35 +0100860 /* Run the subscr and conn leak test only when the VTY is initialized */
861 if (BSCVTY.checkstate("Mapped")) {
862 f_verify_talloc_count(BSCVTY, {"struct bsc_subscr", "struct gsm_subscriber_connection"});
863 }
864
Daniel Willmann637ef6c2018-07-25 10:49:09 +0200865 all component.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100866 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200867 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100868}
869
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200870private function f_legacy_bssap_reset(integer bssap_idx := 0) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +0100871 var BSSAP_N_UNITDATA_ind ud_ind;
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200872 var boolean reset_received := false;
Harald Weltea4ca4462018-02-09 00:17:14 +0100873 timer T := 5.0;
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200874 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
875 ts_BSSMAP_Reset(0, g_osmux_enabled)));
Harald Weltea4ca4462018-02-09 00:17:14 +0100876 T.start;
877 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200878 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap[bssap_idx].sccp_addr_own, g_bssap[bssap_idx].sccp_addr_peer,
879 tr_BSSMAP_ResetAck(g_osmux_enabled))) {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200880 log("BSSMAP: Received RESET-ACK in response to RESET, we're ready to go!");
Harald Weltea4ca4462018-02-09 00:17:14 +0100881 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200882 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200883 log("BSSMAP: Respoding to inbound RESET with RESET-ACK");
Harald Weltea4ca4462018-02-09 00:17:14 +0100884 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200885 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200886 reset_received := true;
Harald Weltea4ca4462018-02-09 00:17:14 +0100887 repeat;
888 }
889 [] BSSAP.receive { repeat; }
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200890 [] T.timeout {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200891 log("BSSMAP: Timeout waiting for RESET-ACK after sending RESET");
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200892 /* If we received a RESET after ours was sent, it
893 may be a race condition where the other peer beacame
894 available after we sent it, but we are in a desired
895 state anyway, so go forward. */
896 if (not reset_received) {
897 setverdict(fail);
898 }
899 }
Harald Weltea4ca4462018-02-09 00:17:14 +0100900 }
Harald Welte28d943e2017-11-25 15:00:50 +0100901}
902
Harald Welteae026692017-12-09 01:03:01 +0100903type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100904 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100905 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100906 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100907 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100908 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100909 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100910 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100911 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100912}
913
Harald Welte21b46bd2017-12-17 19:46:32 +0100914/*! Start the IPA/RSL related bits for one IPA_Client.
915 * \param clnt IPA_Client for which to establish
916 * \param bsc_host IP address / hostname of the BSC
917 * \param bsc_port TCP port number of the BSC
918 * \param i number identifying this BTS
919 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100920function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
921 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100922runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100923 timer T := 10.0;
924
Harald Welte96c94412017-12-09 03:12:45 +0100925 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welte71389132021-12-09 21:58:18 +0100926 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA") alive;
Harald Welteae026692017-12-09 01:03:01 +0100927 clnt.ccm_pars := c_IPA_default_ccm_pars;
928 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
929 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100930 if (handler_mode) {
Harald Welte71389132021-12-09 21:58:18 +0100931 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL") alive;
Harald Welte89ab1912018-02-23 18:56:29 +0100932 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100933 }
Harald Welteae026692017-12-09 01:03:01 +0100934
935 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100936 connect(clnt.vc_IPA:CFG_PORT, self:IPA_CFG_PORT);
Harald Welte624f9632017-12-16 19:26:04 +0100937 if (handler_mode) {
938 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
939 } else {
940 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
941 }
Harald Welteae026692017-12-09 01:03:01 +0100942
Harald Welte5d1a2202017-12-13 19:51:29 +0100943 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100944 if (handler_mode) {
945 clnt.vc_RSL.start(RSL_Emulation.main());
946 return;
947 }
Harald Welteae026692017-12-09 01:03:01 +0100948
949 /* wait for IPA RSL link to connect and send ID ACK */
950 T.start;
951 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700952 [] IPA_RSL[i].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) {
Harald Welteae026692017-12-09 01:03:01 +0100953 T.stop;
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +0700954 IPA_RSL[i].send(ts_ASP_RSL_UD(ts_RSL_PAGING_LOAD_IND(23)));
Harald Welteae026692017-12-09 01:03:01 +0100955 }
Harald Welte60e823a2017-12-10 14:10:59 +0100956 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100957 [] IPA_RSL[i].receive { repeat }
958 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100959 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200960 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100961 }
962 }
963}
964
Harald Welte12055472018-03-17 20:10:08 +0100965function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100966 var IPL4asp_Types.Result res := {
967 errorCode := omit,
968 connId := omit,
969 os_error_code := omit,
970 os_error_text := omit
971 };
972
Harald Welte12055472018-03-17 20:10:08 +0100973 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
974 return;
975 }
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100976
977 /* Alive components don't finish sockets (TCP FIN) when they are
978 * stopped. Hence, we need to manually call close() on them to make sure
979 * the IUT knows about it. */
980 f_ipa_cfg_disconnect(IPA_CFG_PORT, res);
981
Harald Welte12055472018-03-17 20:10:08 +0100982 clnt.vc_IPA.stop;
983 if (isbound(clnt.vc_RSL)) {
984 clnt.vc_RSL.stop;
985 }
986}
987
Harald Welte21b46bd2017-12-17 19:46:32 +0100988/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100989function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
990 timer T := secs_max;
991 T.start;
992 while (true) {
993 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
994 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100995 /* the 'degraded' state exists from OML connection time, and we have to wait
996 * until all MO's are initialized */
997 T.start(1.0);
998 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100999 return;
1000 }
Harald Weltef0d6ac62017-12-17 17:02:21 +01001001 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +01001002 if (not T.running) {
Max99253902018-11-16 17:57:39 +01001003 setverdict(fail, "Timeout waiting for BTS" & int2str(bts_nr) & " oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +02001004 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001005 }
1006 }
1007}
1008
Harald Welte21b46bd2017-12-17 19:46:32 +01001009/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +01001010altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +01001011 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +01001012 [] T_guard.timeout {
1013 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +02001014 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +01001015 }
Harald Welte60e823a2017-12-10 14:10:59 +01001016 /* always respond with RESET ACK to RESET */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001017 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Welte60e823a2017-12-10 14:10:59 +01001018 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001019 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Welte69c1c262017-12-13 21:02:08 +01001020 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +01001021 }
Harald Welte28d943e2017-11-25 15:00:50 +01001022}
1023
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001024altstep no_bssmap_reset() runs on test_CT {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001025 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001026 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +02001027 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001028 }
1029}
1030
Daniel Willmann191e0d92018-01-17 12:44:35 +01001031function f_init_mgcp(charstring id) runs on test_CT {
1032 id := id & "-MGCP";
1033
1034 var MGCPOps ops := {
1035 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
1036 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
1037 };
1038 var MGCP_conn_parameters mgcp_pars := {
1039 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +01001040 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +01001041 mgw_ip := mp_test_ip,
Pau Espin Pedrol1a026a52019-06-18 17:21:52 +02001042 mgw_udp_port := 2427,
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02001043 /* Enable it for SCCPlite, since we have 2 MGCP sockets towards MGW (UDP one +
1044 the on with MGCP over IPA forwarded from MSC one) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001045 multi_conn_mode := (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER)
Daniel Willmann191e0d92018-01-17 12:44:35 +01001046 };
1047
Harald Welte71389132021-12-09 21:58:18 +01001048 vc_MGCP := MGCP_Emulation_CT.create(id) alive;
Daniel Willmann191e0d92018-01-17 12:44:35 +01001049 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
1050}
1051
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001052/* Enable or disable (current default) Osmux. When enabling, BSSMAP Reset
1053 * contains extra IE (OsmuxSupport) and osmo-bsc will handle AssignReq with
1054 * OsmuxCID IE.
1055 */
1056private function f_vty_allow_osmux(boolean allow) runs on test_CT {
1057 f_vty_enter_cfg_msc(BSCVTY, 0);
1058 if (allow) {
1059 f_vty_transceive(BSCVTY, "osmux on");
1060 } else {
1061 f_vty_transceive(BSCVTY, "osmux off");
1062 }
1063 f_vty_transceive(BSCVTY, "exit");
1064 f_vty_transceive(BSCVTY, "exit");
1065 g_osmux_enabled := allow;
1066}
1067
Max2253c0b2018-11-06 19:28:05 +01001068function f_init_vty(charstring id := "foo") runs on test_CT {
Harald Welte94e0c342018-04-07 11:33:23 +02001069 if (BSCVTY.checkstate("Mapped")) {
1070 /* skip initialization if already executed once */
1071 return;
1072 }
Harald Weltebc03c762018-02-12 18:09:38 +01001073 map(self:BSCVTY, system:BSCVTY);
1074 f_vty_set_prompts(BSCVTY);
1075 f_vty_transceive(BSCVTY, "enable");
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01001076 f_cs7_inst_0_cfg(BSCVTY, {"sccp-timer ias " & int2str(g_bsc_sccp_timer_ias),
1077 "sccp-timer iar " & int2str(g_bsc_sccp_timer_iar)});
Harald Weltebc03c762018-02-12 18:09:38 +01001078}
1079
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +02001080friend function f_logp(TELNETasp_PT pt, charstring log_msg)
Neels Hofmeyr4f118412020-06-04 15:25:10 +02001081{
1082 // log on TTCN3 log output
1083 log(log_msg);
1084 // log in stderr log
Neels Hofmeyr8bdafe52021-12-14 17:25:48 +01001085 if (pt.checkstate("Mapped")) {
1086 f_vty_transceive(pt, "logp lglobal notice TTCN3 f_logp(): " & log_msg);
1087 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02001088}
1089
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001090private function f_sysinfo_seen(integer rsl_idx, RSL_Message rsl) runs on test_CT
1091{
1092 if (rsl_idx >= lengthof(g_system_information)) {
1093 g_system_information[rsl_idx] := SystemInformationConfig_omit
1094 }
1095 f_sysinfo_dec_raw(g_system_information[rsl_idx], rsl);
1096}
1097
1098altstep as_catch_RSL_sysinfo(integer rsl_idx) runs on test_CT {
1099 var ASP_RSL_Unitdata rx_rsl_ud;
1100
1101 /* For handler_mode := false, receiving the RSL bootstrap messages directly on IPA_RSL */
1102 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
1103 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1104 repeat;
1105 }
1106 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
1107 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1108 repeat;
1109 }
1110 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> value rx_rsl_ud {
1111 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1112 repeat;
1113 }
1114 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_SACCH_FILL)) -> value rx_rsl_ud {
1115 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1116 repeat;
1117 }
1118
1119 /* For handler_mode := true, receiving the RSL bootstrap messages via RSL_Emulation */
1120 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
1121 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1122 repeat;
1123 }
1124 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
1125 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1126 repeat;
1127 }
1128 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> value rx_rsl_ud {
1129 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1130 repeat;
1131 }
1132 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_SACCH_FILL)) -> value rx_rsl_ud {
1133 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1134 repeat;
1135 }
1136}
1137
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001138/* TODO: use BooleanList from COMMON/src/General_Types.ttcn */
1139private type record of boolean my_BooleanList;
1140
1141private function f_vty_msc_allow_attach(TELNETasp_PT pt, my_BooleanList allow_attach_list)
1142{
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001143 var charstring config := f_vty_transceive_ret(pt, "show running-config");
1144
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001145 for (var integer msc_nr := 0; msc_nr < sizeof(allow_attach_list); msc_nr := msc_nr+1) {
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001146 if (f_strstr(config, "\nmsc " & int2str(msc_nr) & "\n") < 0) {
1147 /* There is no 'msc N' for this msc_nr in the running config, so don't create an empty msc by
1148 * stepping into that config node. */
1149 log("msc ", msc_nr, " is not configured, skipping");
1150 continue;
1151 }
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001152 f_vty_enter_cfg_msc(pt, msc_nr);
1153 if (allow_attach_list[msc_nr]) {
1154 /* strict := false: ignore if osmo-bsc does not support this config option (latest build) */
1155 f_vty_transceive(pt, "allow-attach", strict := false);
1156 } else {
1157 f_vty_transceive(pt, "no allow-attach", strict := false);
1158 }
1159 f_vty_transceive(pt, "exit");
1160 f_vty_transceive(pt, "exit");
1161 }
1162}
1163
Harald Welte21b46bd2017-12-17 19:46:32 +01001164/* global initialization function
1165 * \param nr_bts Number of BTSs we should start/bring up
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001166 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false).
1167 * \param nr_msc Number of virtual MSCs to bring up to connect to osmo-bsc.
1168 */
1169function f_init(integer nr_bts := NUM_BTS, boolean handler_mode := false, boolean allow_osmux := false,
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001170 integer nr_msc := 1, float guard_timeout := 30.0) runs on test_CT {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001171 var integer bssap_idx;
Harald Welte28d943e2017-11-25 15:00:50 +01001172
Harald Welteae026692017-12-09 01:03:01 +01001173 if (g_initialized) {
1174 return;
Harald Welte28d943e2017-11-25 15:00:50 +01001175 }
Harald Welteae026692017-12-09 01:03:01 +01001176 g_initialized := true;
1177
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001178 T_guard.start(guard_timeout);
Daniel Willmanne68f9272018-11-27 15:15:28 +01001179 activate(as_Tguard());
1180
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001181 f_init_vty("VirtMSC");
Pau Espin Pedrol23510fb2021-07-20 17:00:38 +02001182 f_vty_allow_osmux(allow_osmux);
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001183
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001184 var my_BooleanList allow_attach := { false, false, false };
Daniel Willmannebdecc02020-08-12 15:30:17 +02001185 f_init_statsd("VirtMSC", vc_STATSD, mp_test_ip, mp_bsc_statsd_port);
1186
Neels Hofmeyr9db8e0e2021-08-23 20:45:58 +02001187 /* Make sure each MSC's internal state is "DISCONNECTED" at first */
1188 for (bssap_idx := 0; bssap_idx < NUM_MSC; bssap_idx := bssap_idx+1) {
1189 f_vty_transceive(BSCVTY, "msc " & int2str(bssap_idx) & " bssmap reset", strict := false);
1190 }
1191
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001192 for (bssap_idx := 0; bssap_idx < nr_msc; bssap_idx := bssap_idx+1) {
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001193 allow_attach[bssap_idx] := true;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001194 /* Call a function of our 'parent component' RAN_Adapter_CT to start the
1195 * MSC-side BSSAP emulation */
1196 if (handler_mode) {
1197 var RanOps ranops := MSC_RanOps;
1198 ranops.use_osmux := g_osmux_enabled;
1199 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", ranops);
1200 connect(self:SCCPLITE_IPA_CTRL, g_bssap[bssap_idx].vc_RAN:CTRL_CLIENT);
1201 f_ran_adapter_start(g_bssap[bssap_idx]);
1202 } else {
1203 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", omit);
1204 connect(self:BSSAP, g_bssap[bssap_idx].vc_SCCP:SCCP_SP_PORT);
1205 f_ran_adapter_start(g_bssap[bssap_idx]);
1206 f_legacy_bssap_reset();
1207 }
Harald Welte67089ee2018-01-17 22:19:03 +01001208 }
Harald Welted5833a82018-05-27 16:52:56 +02001209
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02001210 if (mp_enable_lcs_tests) {
1211 if (handler_mode) {
1212 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", SMLC_BssapLeOps);
1213 } else {
1214 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", omit);
1215 connect(self:BSSAP_LE, g_bssap_le.vc_SCCP:SCCP_SP_PORT);
1216 }
1217 f_bssap_le_adapter_start(g_bssap_le);
Harald Welte47cd0e32020-08-21 12:39:11 +02001218 }
Harald Welte47cd0e32020-08-21 12:39:11 +02001219
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001220 /* start the test with exactly all enabled MSCs allowed to attach */
1221 f_vty_msc_allow_attach(BSCVTY, allow_attach);
1222
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01001223 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +01001224
Daniel Willmann191e0d92018-01-17 12:44:35 +01001225 f_init_mgcp("VirtMSC");
1226
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001227 for (var integer i := 0; i < nr_bts; i := i+1) {
1228 f_init_bts(i, handler_mode);
Harald Welte696ddb62017-12-08 14:01:43 +01001229 }
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001230}
Harald Welte696ddb62017-12-08 14:01:43 +01001231
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001232function f_init_bts(integer bts_idx := 0, boolean handler_mode := false)
1233runs on test_CT {
1234 /* wait until osmo-bts-omldummy has respawned */
1235 f_wait_oml(bts_idx, "degraded", 5.0);
1236
1237 /* start RSL connection */
1238 f_ipa_rsl_start(bts[bts_idx].rsl, mp_bsc_ip, mp_bsc_rsl_port, bts_idx, handler_mode);
1239 /* wait until BSC tells us "connected" */
1240 f_wait_oml(bts_idx, "connected", 5.0);
Harald Welte28d943e2017-11-25 15:00:50 +01001241}
1242
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001243function f_init_bts_and_check_sysinfo(integer bts_idx := 0, boolean handler_mode := false,
1244 template SystemInformationConfig expect_si)
1245runs on test_CT {
1246 var default sysinfo := activate(as_catch_RSL_sysinfo(bts_idx));
1247
1248 f_init_bts(bts_idx, handler_mode);
1249
1250 /* Give some time to (hopefully/most likely) collect all system informations from RSL startup.
1251 * We could stop as soon as all expected SI are received, but then we might miss SI that we don't expect and
1252 * that might be sent afterwards. So rather give a generous timeout and be quite sure to catch all SI.
1253 */
1254 f_sleep(5.0);
1255 log("RSL ", bts_idx, " SYSTEM INFORMATION: ", g_system_information[bts_idx]);
1256
1257 deactivate(sysinfo);
1258
1259 if (match(g_system_information[bts_idx], expect_si)) {
1260 setverdict(pass);
1261 } else {
1262 log("RSL ", bts_idx, ": EXPECTED SI: ", expect_si);
1263 log("RSL ", bts_idx, ": GOT SI: ", g_system_information[bts_idx]);
1264 setverdict(fail, "received SI does not match expectations");
1265 return;
1266 }
1267}
1268
Maxd4e56962018-10-31 19:08:25 +01001269/* expect to receive a RSL message matching a specified template on a given BTS / stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001270function 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 +01001271runs on test_CT return RSL_Message {
1272 var ASP_RSL_Unitdata rx_rsl_ud;
1273 timer T := t_secs;
1274
1275 T.start;
1276 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001277 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
Harald Welteae026692017-12-09 01:03:01 +01001278 T.stop;
1279 }
1280 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +01001281 [] T.timeout {
1282 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +02001283 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +01001284 }
Harald Welteae026692017-12-09 01:03:01 +01001285 }
1286 return rx_rsl_ud.rsl;
1287}
1288
Harald Welte21b46bd2017-12-17 19:46:32 +01001289/* helper function to transmit RSL on a given BTS/stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001290function 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 +01001291runs on test_CT {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001292 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(t_tx, sid));
Harald Welteae026692017-12-09 01:03:01 +01001293}
1294
1295
Harald Welte4003d112017-12-09 22:35:39 +01001296/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +01001297testcase TC_chan_act_noreply() runs on test_CT {
1298 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +01001299 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +01001300
Harald Welte89d42e82017-12-17 16:42:41 +01001301 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +01001302
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001303 IPA_RSL[0].send(ts_ASP_RSL_UD(ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +01001304 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001305 f_shutdown_helper();
Harald Welte28d943e2017-11-25 15:00:50 +01001306}
1307
Neels Hofmeyr734b1a32021-11-29 16:00:17 +01001308const CounterNameVals counternames_bts_chreq := {
1309 { "chreq:total", 0 },
1310 { "chreq:attempted_emerg", 0 },
1311 { "chreq:attempted_call", 0 },
1312 { "chreq:attempted_location_upd", 0 },
1313 { "chreq:attempted_pag", 0 },
1314 { "chreq:attempted_pdch", 0 },
1315 { "chreq:attempted_other", 0 },
1316 { "chreq:attempted_unknown", 0 },
1317 { "chreq:successful", 0 },
1318 { "chreq:successful_emerg", 0 },
1319 { "chreq:successful_call", 0 },
1320 { "chreq:successful_location_upd", 0 },
1321 { "chreq:successful_pag", 0 },
1322 { "chreq:successful_pdch", 0 },
1323 { "chreq:successful_other", 0 },
1324 { "chreq:successful_unknown", 0 },
1325 { "chreq:no_channel", 0 },
1326 { "chreq:max_delay_exceeded", 0 }
1327};
1328
1329/* verify the "chreq:*" counters */
1330private function f_chan_act_counter(OCT1 ra, charstring chreq_ctr_suffix) runs on test_CT
1331{
1332 var GsmFrameNumber fn := 23;
1333
1334 f_logp(BSCVTY, "f_chan_act_counter(" & chreq_ctr_suffix & ")");
1335
1336 var RSL_Message rx_rsl;
1337 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1338 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1339 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1340
1341 f_ctrs_bts_add(0, "chreq:total");
1342 f_ctrs_bts_add(0, "chreq:attempted_" & chreq_ctr_suffix);
1343 f_ctrs_bts_verify();
1344
1345 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
1346 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
1347
1348 f_ctrs_bts_add(0, "chreq:successful");
1349 f_ctrs_bts_add(0, "chreq:successful_" & chreq_ctr_suffix);
1350 f_ctrs_bts_verify();
1351
1352 /* test is done, release RSL Conn Fail Ind to clean up */
1353 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1354 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1355 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
1356 f_sleep(1.0);
1357}
1358
Harald Welte4003d112017-12-09 22:35:39 +01001359testcase TC_chan_act_counter() runs on test_CT {
1360 var BSSAP_N_UNITDATA_ind ud_ind;
1361 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +01001362 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +01001363
Harald Welte89d42e82017-12-17 16:42:41 +01001364 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001365
Neels Hofmeyr734b1a32021-11-29 16:00:17 +01001366 f_vty_allow_emerg_bts(true, 0);
1367
1368 f_ctrs_bts_init(1, counternames_bts_chreq);
1369
1370 /* emergency call: RA & 0xe0 == 0xa0 --> CHREQ_T_EMERG_CALL */
1371 f_chan_act_counter('a3'O, "emerg");
1372
1373 /* voice TCH/H: RA & 0xf0 == 0x40 --> CHREQ_T_VOICE_CALL_TCH_H */
1374 f_chan_act_counter('43'O, "call");
1375
1376 /* LU: RA & 0xf0 == 0x00 --> CHREQ_T_LOCATION_UPD */
1377 f_chan_act_counter('03'O, "location_upd");
1378
1379 /* Paging: RA & 0xf0 == 0x20 --> CHREQ_T_PAG_R_TCH_F */
1380 f_chan_act_counter('23'O, "pag");
1381 /* Paging: RA & 0xf0 == 0x30 --> CHREQ_T_PAG_R_TCH_FH */
1382 f_chan_act_counter('33'O, "pag");
1383
1384 /* LU: RA & 0xfc == 0x78 --> CHREQ_T_PDCH_TWO_PHASE */
1385 /* no PCU, so PDCH not allowed. Skip this test for now. */
1386 /* f_chan_act_counter('7b'O, "pdch"); */
1387
1388 /* LU: RA & 0xf0 == 0x10 --> CHREQ_T_SDCCH */
1389 f_chan_act_counter('13'O, "other");
Harald Welte4003d112017-12-09 22:35:39 +01001390
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001391 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001392}
1393
Harald Welteae026692017-12-09 01:03:01 +01001394/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
Philipp Maier9c60a622020-07-09 15:08:46 +02001395private function f_TC_chan_act_ack_noest(OCT1 ra := '23'O) runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +01001396 var RSL_Message rx_rsl;
1397
Harald Welteae026692017-12-09 01:03:01 +01001398 /* Send CHAN RQD and wait for allocation; acknowledge it */
Philipp Maier9c60a622020-07-09 15:08:46 +02001399 var RslChannelNr chan_nr := f_chreq_act_ack(ra);
Harald Welteae026692017-12-09 01:03:01 +01001400
1401 /* expect BSC to disable the channel again if there's no RLL EST IND */
1402 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1403
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001404 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001405}
1406
Philipp Maier9c60a622020-07-09 15:08:46 +02001407/* Normal variant */
1408testcase TC_chan_act_ack_noest() runs on test_CT {
Philipp Maieraf58db22020-08-12 17:24:40 +02001409 f_init(1);
Philipp Maier9c60a622020-07-09 15:08:46 +02001410 f_TC_chan_act_ack_noest();
1411}
1412
1413/* Emergency call variant */
1414testcase TC_chan_act_ack_noest_emerg() runs on test_CT {
1415 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
Philipp Maieraf58db22020-08-12 17:24:40 +02001416 f_init(1);
1417 f_vty_allow_emerg_bts(true, 0);
Philipp Maier9c60a622020-07-09 15:08:46 +02001418 f_TC_chan_act_ack_noest(ra := 'A5'O);
1419}
1420
Philipp Maier606f07d2020-08-12 17:21:58 +02001421/* Emergency call variant, but emergency calls are not allowed */
1422testcase TC_chan_rqd_emerg_deny() runs on test_CT {
1423 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
1424
1425 var RSL_Message rx_rsl;
1426 var GsmRrMessage rr;
1427
1428 f_init(1);
1429 f_vty_allow_emerg_bts(false, 0);
1430
1431 IPA_RSL[0].clear;
1432 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
1433
1434 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
1435 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
1436 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1437 setverdict(pass);
1438 } else {
1439 setverdict(fail, "immediate assignment not rejected");
1440 }
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01001441
1442 f_shutdown_helper();
Philipp Maier606f07d2020-08-12 17:21:58 +02001443}
1444
Harald Welteae026692017-12-09 01:03:01 +01001445/* Test behavior if MSC never answers to CR */
1446testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +01001447 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
1448 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +01001449 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +01001450 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +01001451
Harald Welte89d42e82017-12-17 16:42:41 +01001452 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001453
1454 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001455 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001456
1457 var octetstring l3 := '00010203040506'O
1458 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1459
1460 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
1461
1462 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +01001463 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001464 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001465 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001466}
1467
1468/* Test behavior if MSC answers with CREF to CR */
1469testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
1470 var BSSAP_N_CONNECT_ind rx_c_ind;
1471 var RSL_Message rx_rsl;
1472
Harald Welte89d42e82017-12-17 16:42:41 +01001473 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001474
1475 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001476 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001477
1478 var octetstring l3 := '00010203040506'O
1479 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1480
1481 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1482 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
1483
1484 /* expect BSC to disable the channel */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001485 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001486 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001487}
1488
Harald Welte618ef642017-12-14 14:58:20 +01001489/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
1490testcase TC_chan_act_nack() runs on test_CT {
1491 var RSL_Message rx_rsl;
1492 var integer chact_nack;
1493
Harald Welte89d42e82017-12-17 16:42:41 +01001494 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +01001495
1496 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
1497
1498 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
1499 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1500 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1501
1502 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
1503
1504 /* wait for some time to hope the NACK arrives before the CTRL GET below */
1505 f_sleep(0.5);
1506
1507 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
1508
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001509 f_shutdown_helper();
Harald Welte618ef642017-12-14 14:58:20 +01001510}
1511
Harald Welte799c97b2017-12-14 17:50:30 +01001512/* Test for channel exhaustion due to RACH overload */
1513testcase TC_chan_exhaustion() runs on test_CT {
1514 var ASP_RSL_Unitdata rsl_ud;
1515 var integer i;
1516 var integer chreq_total, chreq_nochan;
1517
Harald Welte89d42e82017-12-17 16:42:41 +01001518 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +01001519
1520 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
1521 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
1522
Neels Hofmeyr85fa37f2021-10-06 13:50:38 +02001523 /* GSM 44.018 Table 9.1.8.2:
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +01001524 * RA = '33'O -> Establishment cause = 0011xxxx (MS dual rate capable and asks for "TCH/H or TCH/F").
1525 * With current setup, expect 4xSDCCH + 4xTCH/F + 1xTCH/H to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +02001526 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 +01001527 var RslChannelNr chan_nr := f_chreq_act_ack('33'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +01001528 }
1529
1530 IPA_RSL[0].clear;
1531
Harald Weltedd8cbf32018-01-28 12:07:52 +01001532 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001533 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +01001534
1535 /* now expect additional channel activations to fail */
1536 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
1537
1538 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001539 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
Harald Welte799c97b2017-12-14 17:50:30 +01001540 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
1541 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001542 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
Harald Welte799c97b2017-12-14 17:50:30 +01001543 var GsmRrMessage rr;
1544 /* match on IMM ASS REJ */
1545 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
1546 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1547 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001548 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +01001549 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
1550 chreq_nochan+1);
1551 setverdict(pass);
1552 } else {
1553 repeat;
1554 }
1555 }
1556 [] IPA_RSL[0].receive { repeat; }
1557 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001558 f_shutdown_helper();
Harald Welte799c97b2017-12-14 17:50:30 +01001559}
1560
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001561/* Test channel deactivation due to silence from MS */
1562testcase TC_chan_deact_silence() runs on test_CT {
1563 var RslChannelNr chan_nr;
1564
1565 f_init(1);
1566
1567 /* Request for a dedicated channel */
1568 chan_nr := f_chreq_act_ack('23'O);
1569
1570 /* Wait some time until the channel is released */
1571 f_sleep(2.0);
1572
1573 /* Expect CHANnel RELease */
1574 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001575 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001576 log("Received CHANnel RELease");
1577 setverdict(pass);
1578 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001579 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001580 /* See OS#3709, OsmoBSC should not send Immediate
1581 * Assignment Reject since a dedicated channel was
1582 * already allocated, and Immediate Assignment was
1583 * already sent. */
1584 setverdict(fail, "Unexpected Immediate Assignment!");
1585 }
1586 [] IPA_RSL[0].receive {
1587 setverdict(fail, "Unexpected RSL message!");
1588 }
1589 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001590 f_shutdown_helper();
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001591}
1592
Harald Weltecfe2c962017-12-15 12:09:32 +01001593/***********************************************************************
1594 * Assignment Testing
1595 ***********************************************************************/
1596
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001597/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction,
1598 * except for the inter-BSC handover, MT side) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001599testcase TC_outbound_connect(integer bssap_idx := 0) runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +01001600 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +01001601
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001602 BSSAP.send(ts_BSSAP_CONNECT_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
1603 2342, ts_BSSMAP_AssignmentReq));
Harald Weltecfe2c962017-12-15 12:09:32 +01001604 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001605 f_shutdown_helper();
Harald Weltecfe2c962017-12-15 12:09:32 +01001606}
1607
Harald Welte16a4adf2017-12-14 18:54:01 +01001608/* Test behavior if MSC answers with CREF to CR */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001609testcase TC_assignment_cic_only(integer bssap_idx := 0) runs on test_CT {
Harald Welte16a4adf2017-12-14 18:54:01 +01001610 var BSSAP_N_CONNECT_ind rx_c_ind;
1611 var RSL_Message rx_rsl;
1612 var DchanTuple dt;
1613
Harald Welte89d42e82017-12-17 16:42:41 +01001614 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +01001615
1616 dt := f_est_dchan('23'O, 23, '00000000'O);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001617 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte17b27da2018-05-25 20:33:53 +02001618 /* send assignment without AoIP IEs */
1619 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
1620 } else {
1621 /* Send assignmetn without CIC in IPA case */
1622 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
1623 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
1624 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
1625 }
Harald Welte16a4adf2017-12-14 18:54:01 +01001626 alt {
1627 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1628 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
1629 }
Harald Welte235ebf12017-12-15 14:18:16 +01001630 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +01001631 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1632 setverdict(pass);
1633 }
1634 [] BSSAP.receive { repeat; }
1635 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001636 f_shutdown_helper();
Harald Welte16a4adf2017-12-14 18:54:01 +01001637}
1638
Harald Welteed848512018-05-24 22:27:58 +02001639/* generate an assignment request for either AoIP or SCCPlite */
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001640function 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 +02001641 var PDU_BSSAP ass_cmd;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001642 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001643 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welteed848512018-05-24 22:27:58 +02001644 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001645 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001646 if (osmux_enabled) {
1647 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla, osmux_cid));
1648 } else {
1649 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
1650 }
Harald Welteed848512018-05-24 22:27:58 +02001651 } else {
1652 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001653 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
Harald Welteed848512018-05-24 22:27:58 +02001654 }
1655 return ass_cmd;
1656}
1657
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02001658function f_gen_handover_req(integer bssap_idx := 0, charstring aoip_tla := "1.2.3.4",
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001659 template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit,
1660 template (omit) TestHdlrEncrParams enc := omit) return PDU_BSSAP {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001661 var PDU_BSSAP ho_req;
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001662
1663 var BSSMAP_IE_EncryptionInformation encryptionInformation :=
1664 valueof(ts_BSSMAP_IE_EncrInfo('0000000000000000'O,'01'O));
1665 var template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm := omit;
1666 var template BSSMAP_IE_KC128 kc128 := omit;
1667 if (ispresent(enc)) {
1668 var TestHdlrEncrParams v_enc := valueof(enc);
1669 encryptionInformation := valueof(ts_BSSMAP_IE_EncrInfo(v_enc.enc_key, v_enc.enc_alg));
1670 chosenEncryptionAlgorithm := valueof(
1671 ts_BSSMAP_IE_ChosenEncryptionAlgorithm(int2oct(enum2int(
Oliver Smith598e1ed2021-07-09 10:28:40 +02001672 f_cipher_mode_bssmap_to_rsl(v_enc.enc_alg)), 1)));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001673 if (ispresent(v_enc.enc_kc128)) {
1674 kc128 := ts_BSSMAP_IE_Kc128(v_enc.enc_kc128);
1675 }
1676 }
1677
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001678 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001679 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001680 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001681 ho_req := valueof(ts_BSSMAP_HandoverRequest(omit, tla, oldToNewBSSIEs := oldToNewBSSIEs,
1682 encryptionInformation := encryptionInformation,
1683 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
1684 kC128 := kc128));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001685 } else {
1686 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001687 ho_req := valueof(ts_BSSMAP_HandoverRequest(cic, omit, oldToNewBSSIEs := oldToNewBSSIEs,
1688 encryptionInformation := encryptionInformation,
1689 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
1690 kC128 := kc128));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001691 }
1692 return ho_req;
1693}
1694
Harald Welteed848512018-05-24 22:27:58 +02001695/* generate an assignment complete template for either AoIP or SCCPlite */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001696function f_gen_exp_compl(boolean expect_osmux := false, integer bssap_idx := 0) return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +02001697 var template PDU_BSSAP exp_compl;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001698 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001699 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001700 if (expect_osmux) {
1701 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, osmux_cid);
1702 } else {
1703 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, omit);
1704 }
Harald Welteed848512018-05-24 22:27:58 +02001705 } else {
1706 /* CIC is optional "*" as the MSC allocated it */
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001707 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
Harald Welteed848512018-05-24 22:27:58 +02001708 }
1709 return exp_compl;
1710}
1711
Harald Welte235ebf12017-12-15 14:18:16 +01001712/* Run everything required up to sending a caller-specified assignment command and expect response */
1713function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
1714runs on test_CT {
1715 var BSSAP_N_CONNECT_ind rx_c_ind;
1716 var RSL_Message rx_rsl;
1717 var DchanTuple dt;
1718
Harald Welte89d42e82017-12-17 16:42:41 +01001719 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +01001720
1721 dt := f_est_dchan('23'O, 23, '00000000'O);
1722 /* send assignment without AoIP IEs */
1723 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
1724 alt {
1725 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1726 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
1727 setverdict(pass);
1728 } else {
1729 setverdict(fail, fail_text);
1730 }
1731 }
1732 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1733 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
1734 setverdict(pass);
1735 } else {
1736 setverdict(fail, fail_text);
1737 }
1738 }
1739 [] BSSAP.receive { repeat; }
1740 }
1741}
1742testcase TC_assignment_csd() runs on test_CT {
1743 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001744 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001745 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1746 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
1747 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001748 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001749}
1750
1751testcase TC_assignment_ctm() runs on test_CT {
1752 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001753 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001754 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
1755 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
1756 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001757 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001758}
1759
Harald Welte4003d112017-12-09 22:35:39 +01001760type record DchanTuple {
1761 integer sccp_conn_id,
1762 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +01001763}
1764
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +02001765type record of DchanTuple DchanTuples;
1766
Harald Welted6939652017-12-13 21:02:46 +01001767/* Send CHAN RQD and wait for allocation; acknowledge it */
1768private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
1769runs on test_CT return RslChannelNr {
1770 var RSL_Message rx_rsl;
1771 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1772 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1773 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1774 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
Daniel Willmannf4ac4ce2018-08-02 14:06:30 +02001775 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Harald Welted6939652017-12-13 21:02:46 +01001776 return chan_nr;
1777}
1778
Harald Welte4003d112017-12-09 22:35:39 +01001779/* helper function to establish a dedicated channel via BTS and MSC */
1780function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1781runs on test_CT return DchanTuple {
1782 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +01001783 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001784
Harald Welte4003d112017-12-09 22:35:39 +01001785 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001786 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +01001787
1788 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1789
1790 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1791 dt.sccp_conn_id := rx_c_ind.connectionId;
1792 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1793
1794 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001795}
1796
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02001797/* Like f_est_dchan(), but for the first lchan of a dynamic timeslot: first ACK the deactivation of PDCH. */
1798function f_est_dchan_dyn(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1799runs on test_CT return DchanTuple {
1800 var BSSAP_N_CONNECT_ind rx_c_ind;
1801 var DchanTuple dt;
1802
1803 /* Send CHAN RQD */
1804 var RSL_Message rx_rsl;
1805 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1806
1807 /* The dyn TS first deactivates PDCH */
1808 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1809 dt.rsl_chan_nr := rx_rsl.ies[0].body.chan_nr;
1810 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1811
1812 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1813 dt.rsl_chan_nr := rx_rsl.ies[0].body.chan_nr;
1814
1815 /* Now activates the signalling channel */
1816 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, fn+10));
1817 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
1818
1819 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1820
1821 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1822 dt.sccp_conn_id := rx_c_ind.connectionId;
1823 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1824
1825 return dt;
1826}
1827
Harald Welte641fcbe2018-06-14 10:58:35 +02001828/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
1829private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
1830 var RSL_Message rx_rsl;
1831 /* expect BSC to disable the channel */
1832 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1833 /* respond with CHAN REL ACK */
1834 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1835
1836 /* expect Clear Complete from BSC */
1837 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1838
1839 /* MSC disconnects as instructed. */
1840 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1841}
1842
Harald Welte4003d112017-12-09 22:35:39 +01001843/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
1844testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001845 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001846 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +01001847
Harald Welte89d42e82017-12-17 16:42:41 +01001848 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +01001849
Harald Welte4003d112017-12-09 22:35:39 +01001850 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1851
1852 /* simulate RLL REL IND */
1853 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
1854
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001855 /* expect Clear Request on MSC side */
1856 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1857
1858 /* Instruct BSC to clear channel */
1859 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1860 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1861
Harald Welte4003d112017-12-09 22:35:39 +01001862 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001863 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001864
1865 /* wait for SCCP emulation to do its job */
1866 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +01001867
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001868 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001869}
1870
1871/* Test behavior of channel release after CONN FAIL IND from BTS */
1872testcase TC_chan_rel_conn_fail() runs on test_CT {
1873 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001874 var DchanTuple dt;
1875
Harald Welte89d42e82017-12-17 16:42:41 +01001876 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001877
1878 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1879
1880 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +01001881 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 +01001882 /* TODO: different cause values? */
1883
Harald Welte4003d112017-12-09 22:35:39 +01001884 /* expect Clear Request from BSC */
1885 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1886
1887 /* Instruct BSC to clear channel */
1888 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1889 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1890
Harald Welte6ff76ea2018-01-28 13:08:01 +01001891 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001892 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +01001893
1894 /* wait for SCCP emulation to do its job */
1895 f_sleep(1.0);
1896
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001897 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001898}
1899
Harald Welte99f3ca02018-06-14 13:40:29 +02001900/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
1901/* See also https://www.osmocom.org/issues/3182 */
1902testcase TC_early_conn_fail() runs on test_CT {
1903 var RSL_Message rx_rsl;
1904 var DchanTuple dt;
1905
1906 f_init(1);
1907
1908 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
Harald Weltec46ea3c2020-10-10 18:46:12 +02001909 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_ra_cs(), 23);
Harald Welte99f3ca02018-06-14 13:40:29 +02001910
1911 /* BTS->BSC: simulate CONN FAIL IND */
1912 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1913
1914 /* BTS->BSC: Expect RF channel release from BSC on Abis */
1915 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1916
1917 /* BTS<-BSC: respond with CHAN REL ACK */
1918 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1919
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001920 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001921}
1922
1923/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
1924/* See also https://www.osmocom.org/issues/3182 */
1925testcase TC_late_conn_fail() runs on test_CT {
1926 var RSL_Message rx_rsl;
1927 var DchanTuple dt;
1928
1929 f_init(1);
1930
1931 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1932
1933 /* BSC<-MSC: Instruct BSC to clear connection */
1934 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
1935
1936 /* BTS->BSC: expect BSC to deactivate SACCH */
1937 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
1938
1939 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
1940 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1941
1942 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
1943 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1944 /* BTS->BSC: respond with CHAN REL ACK */
1945 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1946
1947 /* BSC->MSC: expect Clear Complete from BSC */
1948 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1949
1950 /* BSC<-MSC: MSC disconnects as requested. */
1951 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1952
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001953 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001954}
1955
Oliver Smithaf03bef2021-08-24 15:34:51 +02001956private function f_TC_stats_conn_fail(charstring id) runs on MSC_ConnHdlr {
1957 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
1958 var PDU_BSSAP ass_cmd := f_gen_ass_req();
1959
1960 f_statsd_reset();
1961
1962 /* Establish SDCCH */
1963 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1964 f_establish_fully(ass_cmd, exp_fail);
1965
1966 /* Expect stats to be 0 */
1967 var StatsDExpects expect := {
1968 {name := "TTCN3.bts.0.chan.rf_fail", mtype := "c", min := 0, max := 0},
1969 {name := "TTCN3.bts.0.chan.rf_fail_sdcch", mtype := "c", min := 0, max := 0}
1970 };
1971 f_statsd_expect(expect);
1972
1973 /* Simulate CONN FAIL IND on SDCCH */
1974 RSL.send(ts_ASP_RSL_UD(
1975 ts_RSL_CONN_FAIL_IND(g_chan_nr, RSL_ERR_RADIO_LINK_FAIL),
1976 IPAC_PROTO_RSL_TRX0));
1977
Neels Hofmeyr58be48a2021-09-07 18:39:21 +02001978 f_sleep(1.0);
1979
Oliver Smithaf03bef2021-08-24 15:34:51 +02001980 /* Expect stats to be 1 */
1981 expect := {
1982 {name := "TTCN3.bts.0.chan.rf_fail", mtype := "c", min := 1, max := 1},
1983 {name := "TTCN3.bts.0.chan.rf_fail_sdcch", mtype := "c", min := 1, max := 1}
1984 };
1985 f_statsd_expect(expect);
1986}
1987testcase TC_stats_conn_fail() runs on test_CT {
1988 var TestHdlrParams pars := f_gen_test_hdlr_pars();
1989 var MSC_ConnHdlr vc_conn;
1990
1991 f_init(1, true);
1992 f_sleep(1.0);
1993
1994 vc_conn := f_start_handler(refers(f_TC_stats_conn_fail), pars);
1995 vc_conn.done;
1996
1997 f_shutdown_helper();
1998}
1999
Neels Hofmeyrf44ccd12018-11-05 19:15:23 +01002000function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr,
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002001 boolean expect_deact_sacch := true,
2002 boolean expect_rr_chan_rel := true,
2003 boolean expect_rll_rel_req := true,
Harald Welte99787102019-02-04 10:41:36 +01002004 boolean handle_rll_rel := true,
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002005 template CellSelIndValue expect_cells := omit,
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002006 template RR_Cause expect_rr_cause := ?
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002007 ) runs on test_CT {
Harald Welte91d54a52018-01-28 15:35:07 +01002008
2009 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002010 var boolean got_deact_sacch := false;
2011 var boolean got_rr_chan_rel := false;
2012 var boolean got_rll_rel_req := false;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002013 var ASP_RSL_Unitdata ud;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002014 var RSL_IE_Body l3_ie;
2015 var PDU_ML3_NW_MS l3;
2016 var RR_Cause got_cause;
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002017 log("f_expect_chan_rel() expecting: expect_deact_sacch=", expect_deact_sacch, " expect_rr_chan_rel=", expect_rr_chan_rel,
2018 " expect_rll_rel_req=", expect_rll_rel_req);
Harald Welte91d54a52018-01-28 15:35:07 +01002019 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002020 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002021 got_deact_sacch := true;
Harald Welte91d54a52018-01-28 15:35:07 +01002022 repeat;
2023 }
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002024 [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 +01002025 got_rr_chan_rel := true;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002026
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002027 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
2028 setverdict(fail, "cannot find L3");
2029 mtc.stop;
2030 }
2031 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
2032
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002033 if (not istemplatekind(expect_cells, "omit")) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002034 var CellSelIndValue cells := dec_CellSelIndValue(
2035 l3.msgs.rrm.channelRelease.cellSelectionIndicator.cellSelectionIndicatorValue);
2036
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002037 log("GOT RR CHANNEL RELEASE WITH CELLS: ", cells);
2038 if (match(cells, expect_cells)) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002039 setverdict(pass);
2040 } else {
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002041 log("EXPECTED CELLS: ", expect_cells);
2042 setverdict(fail, "Received cells list on RR Channel Release does not match expectations");
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002043 }
2044 }
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002045
2046 if (not istemplatekind(expect_rr_cause, "omit")) {
2047 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
2048 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
2049 if (match(got_cause, expect_rr_cause)) {
2050 setverdict(pass);
2051 } else {
2052 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
2053 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
2054 }
2055 }
Harald Welte99787102019-02-04 10:41:36 +01002056 repeat;
2057 }
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002058 [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 +01002059 got_rr_chan_rel := true;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002060
2061 if (not istemplatekind(expect_rr_cause, "omit")) {
2062 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
2063 setverdict(fail, "cannot find L3");
2064 mtc.stop;
2065 }
2066 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
2067
2068 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
2069 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
2070 if (match(got_cause, expect_rr_cause)) {
2071 setverdict(pass);
2072 } else {
2073 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
2074 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
2075 }
2076 }
Neels Hofmeyr211169d2018-11-07 00:37:29 +01002077 repeat;
2078 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002079 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002080 got_rll_rel_req := true;
Harald Welte91d54a52018-01-28 15:35:07 +01002081 /* FIXME: Why are we getting this for LinkID SACCH? */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002082 if (handle_rll_rel) {
2083 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
2084 }
Harald Welte91d54a52018-01-28 15:35:07 +01002085 repeat;
2086 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002087 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Harald Welte91d54a52018-01-28 15:35:07 +01002088 /* respond with CHAN REL ACK */
2089 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
2090 }
2091 /* ignore any user data */
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002092 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeR(?))) {
Harald Welte91d54a52018-01-28 15:35:07 +01002093 repeat;
2094 }
2095 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002096
2097 log("f_expect_chan_rel() summary: got_deact_sacch=", got_deact_sacch, " got_rr_chan_rel=", got_rr_chan_rel,
2098 " got_rll_rel_req=", got_rll_rel_req);
2099
2100 if (expect_deact_sacch != got_deact_sacch) {
2101 setverdict(fail, "f_expect_chan_rel(): expect_deact_sacch=", expect_deact_sacch, " got_deact_sacch=", got_deact_sacch);
2102 }
2103 if (expect_rr_chan_rel != got_rr_chan_rel) {
2104 setverdict(fail, "f_expect_chan_rel(): expect_rr_chan_rel=", expect_rr_chan_rel, " got_rr_chan_rel=", got_rr_chan_rel);
2105 }
2106 if (expect_rll_rel_req != got_rll_rel_req) {
2107 setverdict(fail, "f_expect_chan_rel(): expect_rll_rel_req=", expect_rll_rel_req, " got_rll_rel_req=", got_rll_rel_req);
2108 }
Harald Welte91d54a52018-01-28 15:35:07 +01002109}
2110
Harald Welte4003d112017-12-09 22:35:39 +01002111/* Test behavior of channel release after hard Clear Command from MSC */
2112testcase TC_chan_rel_hard_clear() runs on test_CT {
2113 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01002114 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +01002115
Harald Welte89d42e82017-12-17 16:42:41 +01002116 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002117
2118 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2119
2120 /* Instruct BSC to clear channel */
2121 var BssmapCause cause := 0;
2122 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2123
2124 /* expect Clear Complete from BSC on A */
2125 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2126 /* release the SCCP connection */
2127 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2128 }
2129
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002130 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002131 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002132}
2133
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002134function f_TC_chan_rel_last_eutran_plmn_hard_clear(boolean tx_csfb_ind) runs on test_CT {
2135 var BSSAP_N_DATA_ind rx_di;
2136 var DchanTuple dt;
2137
2138 f_init(1);
2139
2140 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2141 /* Send CommonID with some random PLMN (BSC doesn't take it into account
2142 /* yet when generating the EUTRAN neigh list in RR CHannel Release) */
2143 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
2144
2145 /* Instruct BSC to clear channel */
2146 var BssmapCause cause := 0;
2147 if (tx_csfb_ind) {
2148 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2149 } else {
2150 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2151 }
2152
2153 /* expect Clear Complete from BSC on A */
2154 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2155 /* release the SCCP connection */
2156 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2157 }
2158
2159 /* 1 neighbor is added by default in osmo-bts.cfg and
2160 SystemInformationConfig_default, use that: */
2161 var template CellSelIndValue exp_cells := f_tr_rr_chan_rel_earfcns(1);
2162
2163 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, expect_cells := exp_cells);
2164 f_shutdown_helper();
2165}
2166
2167/* Test behavior of RR Channel rRelease after Clear Command without CSFB indicator
2168 from MSC, previously receiving any CommonID containing the "Last Used E-UTRAN
2169 PLMN Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
2170 EUTRAN neighbor list sent later on by BSC in RR Channel, so receiving CSFB
2171 Indicator or not shouldn't matter at all. */
2172testcase TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() runs on test_CT {
2173 f_TC_chan_rel_last_eutran_plmn_hard_clear(false);
2174}
2175
2176/* Test behavior of RR Channel rRelease after Clear Command with CSFB indicator from
2177 MSC, previously receiving any CommonID containing the "Last Used E-UTRAN PLMN
2178 Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
2179 EUTRAN neighbor list sent later on by BSC in RR Channel. */
2180testcase TC_chan_rel_last_eutran_plmn_hard_clear_csfb() runs on test_CT {
2181 f_TC_chan_rel_last_eutran_plmn_hard_clear(true);
2182}
2183
2184/* Test behavior of RR Channel Release after Clear Command with CSFB indicator from
2185 MSC, without receiving any CommonID containing the "Last Used E-UTRAN PLMN
2186 Id". According to spec (TS 48.008 version 16.0.0 Release 16 "3.2.1.21") the
2187 CSFB Indicator should not be used anymore, and hence, there should be no
2188 EUTRAN neighbor list sent by BSC in RR Channel release since no CommonId with
2189 Last Used E-UTRAN PLMN Id" IE was sent for this conn. */
Harald Welte99787102019-02-04 10:41:36 +01002190testcase TC_chan_rel_hard_clear_csfb() runs on test_CT {
2191 var BSSAP_N_DATA_ind rx_di;
2192 var DchanTuple dt;
2193
2194 f_init(1);
2195
2196 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2197
2198 /* Instruct BSC to clear channel */
2199 var BssmapCause cause := 0;
2200 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2201
2202 /* expect Clear Complete from BSC on A */
2203 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2204 /* release the SCCP connection */
2205 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2206 }
2207
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002208 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002209 f_shutdown_helper();
Harald Welte99787102019-02-04 10:41:36 +01002210}
2211
Harald Welted8c36cd2017-12-09 23:05:31 +01002212/* Test behavior of channel release after hard RLSD from MSC */
2213testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +01002214 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +01002215
Harald Welte89d42e82017-12-17 16:42:41 +01002216 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +01002217
2218 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2219
2220 /* release the SCCP connection */
2221 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2222
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002223 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002224 f_shutdown_helper();
Harald Welted8c36cd2017-12-09 23:05:31 +01002225}
2226
Harald Welte550daf92018-06-11 19:22:13 +02002227/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
2228testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
2229 var DchanTuple dt;
2230
2231 f_init(1);
2232
2233 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2234
2235 /* release the SCCP connection */
2236 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2237
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002238 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002239 f_shutdown_helper();
Harald Welte550daf92018-06-11 19:22:13 +02002240}
2241
Harald Welte85804d42017-12-10 14:11:58 +01002242/* Test behavior of channel release after BSSMAP RESET from MSC */
2243testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +01002244 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +01002245
Harald Welte89d42e82017-12-17 16:42:41 +01002246 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +01002247
2248 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2249
2250 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
2251 IPA_RSL[0].clear;
2252
2253 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002254 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 +01002255 interleave {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002256 [] 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 +01002257 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
2258 }
2259
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002260 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002261 f_shutdown_helper();
Harald Welte85804d42017-12-10 14:11:58 +01002262}
2263
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002264/* Verify T(iar) triggers and releases the channel */
2265testcase TC_chan_rel_sccp_tiar_timeout() runs on test_CT {
2266 var DchanTuple dt;
2267
2268 /* Set T(iar) in BSC low enough that it will trigger before other side
2269 has time to keep alive with a T(ias). Keep recommended ratio of
2270 T(iar) >= T(ias)*2 */
2271 g_bsc_sccp_timer_ias := 2;
2272 g_bsc_sccp_timer_iar := 5;
2273
2274 f_init(1);
2275
2276 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2277 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002278 f_shutdown_helper();
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002279}
2280
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002281private function f_tc_chan_rel_rr_cause(myBSSMAP_Cause clear_cmd_cause, template RR_Cause expect_rr_cause)
2282runs on test_CT
2283{
2284 var DchanTuple dt;
2285
2286 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2287 var BssmapCause cause := 0;
2288 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(enum2int(clear_cmd_cause))));
2289 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2290 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2291 }
2292
2293 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 +02002294}
2295
2296/* Test that Clear Command cause codes affect the RR Channel Release cause code */
2297testcase TC_chan_rel_rr_cause() runs on test_CT {
2298 f_init(1);
2299
2300 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_CALL_CONTROL, GSM48_RR_CAUSE_NORMAL);
2301 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_HANDOVER_SUCCESSFUL, GSM48_RR_CAUSE_NORMAL);
2302 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_PREEMPTION, GSM48_RR_CAUSE_PREMPTIVE_REL);
2303 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE, GSM48_RR_CAUSE_PROT_ERROR_UNSPC);
2304 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
2305 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_EQUIPMENT_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
Vadim Yanitskiye18aebb2021-01-03 13:10:43 +01002306
2307 f_shutdown_helper();
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002308}
2309
Harald Welte5cd20ed2017-12-13 21:03:20 +01002310/* Test behavior if RSL EST IND for non-active channel */
2311testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
2312 timer T := 2.0;
2313
Harald Welte89d42e82017-12-17 16:42:41 +01002314 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002315
2316 var octetstring l3 := '00010203040506'O;
2317 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2318 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
2319
2320 T.start;
2321 alt {
2322 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2323 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
2324 }
2325 [] BSSAP.receive {}
2326 [] IPA_RSL[0].receive {}
2327 [] T.timeout {}
2328 }
2329
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002330 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002331}
2332
2333/* Test behavior if RSL EST IND for invalid SAPI */
2334testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
2335 var RslChannelNr chan_nr;
2336
Harald Welte89d42e82017-12-17 16:42:41 +01002337 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002338
2339 chan_nr := f_chreq_act_ack()
2340
2341 var octetstring l3 := '00010203040506'O;
2342 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
2343
2344 timer T := 2.0;
2345 T.start;
2346 alt {
2347 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2348 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
2349 }
2350 [] BSSAP.receive { repeat; }
2351 [] IPA_RSL[0].receive { repeat; }
2352 [] T.timeout {}
2353 }
2354
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002355 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002356}
2357
2358/* Test behavior if RSL EST IND for invalid SAPI */
2359testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
2360 timer T := 2.0;
2361
Harald Welte89d42e82017-12-17 16:42:41 +01002362 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002363
2364 var RslChannelNr chan_nr := f_chreq_act_ack();
2365
2366 var octetstring l3 := '00010203040506'O;
2367 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
2368
2369 T.start;
2370 alt {
2371 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2372 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
2373 }
2374 [] BSSAP.receive { repeat; }
2375 [] IPA_RSL[0].receive { repeat; }
2376 [] T.timeout {}
2377 }
2378
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002379 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002380}
2381
2382/* Test behavior if RSL EST IND for invalid SACCH */
2383testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
2384 timer T := 2.0;
2385
Harald Welte89d42e82017-12-17 16:42:41 +01002386 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002387
2388 var RslChannelNr chan_nr := f_chreq_act_ack();
2389
2390 var octetstring l3 := '00010203040506'O;
2391 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
2392
2393 T.start;
2394 alt {
2395 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2396 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
2397 }
2398 [] BSSAP.receive { repeat; }
2399 [] IPA_RSL[0].receive { repeat; }
2400 [] T.timeout {}
2401 }
2402
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002403 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002404}
2405
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002406/* Verify DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
2407private function f_TC_tch_dlci_link_id_sapi(charstring id) runs on MSC_ConnHdlr {
2408 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2409 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2410
2411 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2412 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2413
2414 f_establish_fully(ass_cmd, exp_compl);
2415
2416 /* SAPI0 has already been established by f_establish_fully(), establish SAPI3 */
2417 RSL.send(ts_RSL_EST_IND(g_chan_nr, ts_RslLinkID_SACCH(3), '0904'O));
2418 /* Expect BSSAP/DTAP on SAPI3 (DLCI IE) */
2419 BSSAP.receive(PDU_BSSAP:{
2420 discriminator := '1'B,
2421 spare := '0000000'B,
2422 dlci := 'C3'O,
2423 lengthIndicator := ?,
2424 pdu := { dtap := '0904'O }
2425 });
2426
2427 /* Send messages on DCCH/SAPI0 and ACCH/SAPI3 */
2428 for (var integer i := 0; i < 32; i := i + 1) {
2429 var octetstring l3 := '09'O & f_rnd_octstring(14);
2430 var template (value) RslLinkId link_id;
2431 var template (value) OCT1 dlci;
2432
2433 if (i mod 2 == 0) {
2434 /* SAPI0 on FACCH or SDCCH */
2435 link_id := ts_RslLinkID_DCCH(0);
2436 dlci := '80'O;
2437 } else {
2438 /* SAPI3 on SACCH */
2439 link_id := ts_RslLinkID_SACCH(3);
2440 dlci := 'C3'O;
2441 }
2442
2443 /* Send MO message: RSL -> BSSAP */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002444 f_mo_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002445 /* Send MT message: BSSAP -> RSL */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002446 f_mt_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002447 }
2448}
2449testcase TC_tch_dlci_link_id_sapi() runs on test_CT {
2450 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2451 var MSC_ConnHdlr vc_conn;
2452
2453 f_init(1, true);
2454 f_sleep(1.0);
2455
2456 vc_conn := f_start_handler(refers(f_TC_tch_dlci_link_id_sapi), pars);
2457 vc_conn.done;
2458
2459 f_shutdown_helper();
2460}
2461
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002462private function f_exp_sapi_n_reject(template (present) GsmSapi sapi := ?,
2463 template myBSSMAP_Cause cause := ?,
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002464 template (present) BIT2 cc := ?,
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002465 float T_val := 2.0)
2466runs on test_CT {
2467 var BSSAP_N_DATA_ind rx_di;
2468 timer T;
2469
2470 var template BSSMAP_IE_Cause tr_cause := tr_BSSMAP_IE_Cause(cause);
2471 var template PDU_BSSAP tr_pdu := tr_BSSMAP_SAPInReject(sapi);
2472
2473 T.start(T_val);
2474 alt {
2475 [] BSSAP.receive(tr_BSSAP_DATA_ind(?, tr_pdu)) -> value rx_di {
2476 var BSSMAP_IE_Cause rx_cause := rx_di.userData.pdu.bssmap.sAPInReject.cause;
2477 if (not match(rx_cause, tr_cause)) {
2478 setverdict(fail, "Rx unexpected Cause IE: ",
2479 rx_cause, " vs expected ", tr_cause);
2480 }
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002481
2482 /* Who ever on the earth decided to define this field as two separate bits?!? */
2483 var BIT2 rx_cc := rx_di.userData.pdu.bssmap.sAPInReject.dLCI.c2
2484 & rx_di.userData.pdu.bssmap.sAPInReject.dLCI.c1;
2485 if (not match(rx_cc, cc)) {
2486 setverdict(fail, "Rx unexpected Control Channel type: ",
2487 rx_cc, " vs expected ", cc);
2488 }
2489
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002490 setverdict(pass);
2491 }
2492 [] BSSAP.receive(BSSAP_N_DATA_ind:?) -> value rx_di {
2493 setverdict(fail, "Rx unexpected BSSAP PDU: ", rx_di);
2494 }
2495 [] T.timeout {
2496 setverdict(fail, "Timeout waiting for BSSMAP SAPI N Reject");
2497 }
2498 }
2499}
2500
2501/* Check if we get SAPI N Reject on receipt of unexpected RLL RELease INDication */
2502testcase TC_rll_rel_ind_sapi_n_reject() runs on test_CT {
2503 var octetstring rnd_data := f_rnd_octstring(16);
2504 var RSL_Message rx_rsl;
2505 var DchanTuple dt;
2506
2507 f_init(1);
2508
2509 /* MS establishes a SAPI=0 link on DCCH */
2510 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2511
2512 /* MSC sends some data on (not yet established) SAPI=3 link */
2513 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2514 /* BSC attempts to establish a SAPI=3 link on DCCH */
2515 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2516
2517 /* MS sends unexpected RELease INDication on SAPI=3 */
2518 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3)));
2519 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2520 f_exp_sapi_n_reject(3, GSM0808_CAUSE_MS_NOT_EQUIPPED);
2521
2522 /* Clean up the connection */
2523 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2524 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2525
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002526 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002527}
2528
2529/* Check if we get SAPI N Reject on receipt of unexpected RLL ERROR INDication */
2530testcase TC_rll_err_ind_sapi_n_reject() runs on test_CT {
2531 var octetstring rnd_data := f_rnd_octstring(16);
2532 var RSL_Message rx_rsl;
2533 var DchanTuple dt;
2534
2535 f_init(1);
2536
2537 /* MS establishes a SAPI=0 link on DCCH */
2538 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2539
2540 /* MSC sends some data on (not yet established) SAPI=3 link */
2541 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2542 /* BSC attempts to establish a SAPI=3 link on DCCH */
2543 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2544
2545 /* BTS sends unexpected ERROR INDication on SAPI=3 */
2546 f_ipa_tx(0, ts_RSL_ERROR_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3), ''O));
2547 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2548 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED);
2549
2550 /* Clean up the connection */
2551 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2552 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2553
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002554 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002555}
2556
2557/* Check if we get SAPI N Reject due to a SAPI=3 link establishment timeout */
2558testcase TC_rll_timeout_sapi_n_reject() runs on test_CT {
2559 var octetstring rnd_data := f_rnd_octstring(16);
2560 var RSL_Message rx_rsl;
2561 var DchanTuple dt;
2562
2563 f_init(1);
2564
2565 /* MS establishes a SAPI=0 link on DCCH */
2566 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2567
2568 /* MSC sends some data on (not yet established) SAPI=3 link */
2569 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2570 /* BSC attempts to establish a SAPI=3 link on DCCH */
2571 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2572
2573 /* MS does not respond, so the link establishment timeout triggers SAPI N Reject */
2574 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED, T_val := 8.0);
2575
2576 /* Clean up the connection */
2577 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2578 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2579
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002580 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002581}
2582
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002583/* Check DLCI CC (Control Channel type) bits in SAPI N Reject */
2584testcase TC_rll_sapi_n_reject_dlci_cc() runs on test_CT {
2585 var octetstring rnd_data := f_rnd_octstring(16);
2586 var RSL_Message rx_rsl;
2587 var DchanTuple dt;
2588
2589 f_init(1);
2590
2591 /* MS establishes a SAPI=0 link on DCCH */
2592 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2593
2594 /* MSC sends some data on (not yet established) SAPI=3 link */
2595 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2596 /* BSC attempts to establish a SAPI=3 link on DCCH */
2597 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2598
2599 /* MS sends unexpected ERROR INDication on DCCH/ACCH SAPI=3 */
2600 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 +01002601 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED, '10'B);
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002602
2603 /* Clean up the connection */
2604 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2605 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2606
2607 f_shutdown_helper();
2608}
2609
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002610testcase TC_si_default() runs on test_CT {
2611 f_init(0);
2612 f_init_bts_and_check_sysinfo(0, expect_si := SystemInformationConfig_default);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002613 f_shutdown_helper();
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002614}
Harald Welte4003d112017-12-09 22:35:39 +01002615
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002616/* We're testing SI2quater with lists of EARFCNs. Instead of just incrementing EARFCNs, also pick some from the edges of
2617 * the entire value range. This function provides the same EARFCN numbers for the same earfcn_index */
2618private function f_test_si2quater_earfcn_by_idx(integer earfcn_index) return uint16_t
2619{
2620 select (earfcn_index) {
2621 case (0) {
2622 /* E-ARFCN 111 is already added in the osmo-bsc.cfg */
2623 return 111;
2624 }
2625 case (1) {
2626 return 1;
2627 }
2628 case (2) {
2629 return 0;
2630 }
2631 case (3) {
2632 return 65535;
2633 }
2634 case else {
2635 return 23 * (earfcn_index - 3);
2636 }
2637 }
2638}
2639
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002640function f_test_si2quater(integer total_earfcns, template SystemInformationConfig expect_si,
2641 template CellSelIndValue expect_cells := omit) runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002642
2643 f_init(0);
2644
2645 /* E-ARFCN 111 is already added in the osmo-bsc.cfg, so only add more arfcns if total_earfcns > 1 */
2646 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002647 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2648 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002649 }
2650
2651 f_init_bts_and_check_sysinfo(0, expect_si := expect_si);
2652
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002653 if (not istemplatekind(expect_cells, "omit")) {
2654 /* Also check that RR Channel Release contains these EARFCNs.
2655 * (copied code from TC_chan_rel_hard_clear_csfb) */
2656 var BSSAP_N_DATA_ind rx_di;
2657 var DchanTuple dt;
2658
2659 dt := f_est_dchan('23'O, 23, '00010203040506'O);
Pau Espin Pedrold0046312021-04-19 16:35:58 +02002660 /* Send CommonID with some random PLMN (BSC doesn't take it into account
2661 * yet when generating the EUTRAN neigh list in RR CHannel Release) */
2662 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002663
2664 /* Instruct BSC to clear channel */
2665 var BssmapCause cause := 0;
2666 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2667
2668 /* expect Clear Complete from BSC on A */
2669 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2670 /* release the SCCP connection */
2671 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2672 }
2673
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002674 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 +02002675 }
2676
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002677 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002678 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 +02002679 }
2680}
2681
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002682private function f_tr_si2quater_earfcns(integer count) return template SI2quaterRestOctetsList
2683{
2684 var template SI2quaterRestOctetsList si2quater := {};
2685 var integer si2quater_count := (count + 2) / 3;
2686
2687 for (var integer i := 0; i < count; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002688 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002689 var integer index := i / 3;
2690 var integer earfcn_index := i mod 3;
2691 if (index >= lengthof(si2quater)) {
2692 si2quater[index] := tr_SI2quaterRestOctets_EUTRAN(index := index, count := si2quater_count - 1);
2693 }
2694 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);
2695 }
2696
2697 return si2quater;
2698}
2699
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002700private function f_tr_rr_chan_rel_earfcns(integer count) return template CellSelIndValue
2701{
2702 var template CellSelIndValue_EUTRAN_Descrs cells := {};
2703
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002704 /* the lte neighbors must match the config & vty to pass this test */
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002705 for (var integer i := 0; i < count; i := i + 1) {
2706 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002707 cells[i] := tr_CellSelIndValue_EUTRAN_Descr(earfcn, '1'B, 3);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002708 }
2709
2710 return tr_CellSelIndValue_EUTRAN(cells);
2711}
2712
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002713private function f_tc_si2quater_n_earfcns(integer n) runs on test_CT
2714{
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002715 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrol8ab62e42020-12-18 16:19:11 +01002716 sic.si2quater := f_tr_si2quater_earfcns(n);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002717 var template CellSelIndValue cells := f_tr_rr_chan_rel_earfcns(n);
2718 f_test_si2quater(n, sic, cells);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002719}
2720
2721testcase TC_si2quater_2_earfcns() runs on test_CT {
2722 f_tc_si2quater_n_earfcns(2);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002723 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002724}
2725
2726testcase TC_si2quater_3_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002727 f_tc_si2quater_n_earfcns(3);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002728 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002729}
2730
2731testcase TC_si2quater_4_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002732 f_tc_si2quater_n_earfcns(4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002733 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002734}
2735
2736testcase TC_si2quater_5_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002737 f_tc_si2quater_n_earfcns(5);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002738 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002739}
2740
2741testcase TC_si2quater_6_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002742 f_tc_si2quater_n_earfcns(6);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002743 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002744}
2745
2746testcase TC_si2quater_12_earfcns() runs on test_CT {
2747 f_tc_si2quater_n_earfcns(12);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002748 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002749}
2750
2751testcase TC_si2quater_23_earfcns() runs on test_CT {
2752 f_tc_si2quater_n_earfcns(23);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002753 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002754}
2755
2756testcase TC_si2quater_32_earfcns() runs on test_CT {
2757 f_tc_si2quater_n_earfcns(32);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002758 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002759}
2760
2761testcase TC_si2quater_33_earfcns() runs on test_CT {
2762 f_tc_si2quater_n_earfcns(33);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002763 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002764}
2765
2766testcase TC_si2quater_42_earfcns() runs on test_CT {
2767 f_tc_si2quater_n_earfcns(42);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002768 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002769}
2770
2771testcase TC_si2quater_48_earfcns() runs on test_CT {
2772 f_tc_si2quater_n_earfcns(48);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002773 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002774}
2775
2776/* verify the VTY error response when adding too many EARFCNs, and showing that osmo-bsc still sends 16 SI2quater with
2777 * 48 EARFCNs. */
2778testcase TC_si2quater_49_earfcns() runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002779 var template SystemInformationConfig sic := SystemInformationConfig_default;
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002780 sic.si2quater := f_tr_si2quater_earfcns(48); /* 48, not 49! */
2781 f_init(0);
2782
2783 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002784 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2785 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002786 }
2787
2788 /* The 49th EARFCN no longer fits, expect VTY error */
2789 f_vty_enter_cfg_bts(BSCVTY, 0);
2790 var charstring vty_error;
2791 vty_error := f_vty_transceive_ret(BSCVTY,
2792 "si2quater neighbor-list add earfcn 70 thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3")
2793 f_vty_transceive(BSCVTY, "end");
2794
2795 if (f_strstr(vty_error, "Unable to add ARFCN 70") >= 0) {
2796 log("Got expected VTY error: ", vty_error);
2797 setverdict(pass);
2798 } else {
2799 setverdict(fail, "Expected the 49th EUTRAN ARFCN to be rejected by vty config, got: ", vty_error);
2800 }
2801
2802 f_init_bts_and_check_sysinfo(0, expect_si := sic);
2803
2804 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002805 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 +02002806 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002807 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002808}
2809
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002810private function f_acc09_count_allowed(AccessControlClass acc) return uint8_t
2811{
2812 var uint8_t count := 0;
2813 for (var integer i := 5; i < 16; i := i + 1) {
2814 if (acc[i] == '0'B) { /* the list marks barred, we count allowed */
2815 count := count + 1;
2816 }
2817 }
2818 return count;
2819}
2820
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002821private function f_recv_next_si1(integer rsl_idx := 0) runs on test_CT return SystemInformationType1
2822{
2823 var ASP_RSL_Unitdata rx_rsl_ud;
2824 var SystemInformationType1 last_si1;
2825
2826 timer T := 30.0;
2827 T.start;
2828 alt {
2829 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD((tr_RSL_NO_BCCH_INFO,
2830 tr_RSL_BCCH_INFO,
2831 tr_RSL_NO_SACCH_FILL,
2832 tr_RSL_SACCH_FILL))
2833 ) -> value rx_rsl_ud {
2834 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
2835 if (g_system_information[rsl_idx].si1 == omit) {
2836 repeat;
2837 }
2838 last_si1 := g_system_information[rsl_idx].si1;
2839 g_system_information[rsl_idx].si1 := omit;
2840 T.stop;
2841 }
Vadim Yanitskiy79ebd5e2021-01-04 00:12:55 +01002842 [] IPA_RSL[rsl_idx].receive { repeat; }
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002843 [] T.timeout { setverdict(fail, "Timeout receiving next SI1"); }
2844 }
2845 return last_si1;
2846}
2847
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002848/* verify ACC rotate feature */
2849testcase TC_si_acc_rotate() runs on test_CT {
2850 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002851 var SystemInformationType1 last_si1;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002852 var AccessControlClass acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002853 var uint8_t count;
2854 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2855
2856 f_init(0, guard_timeout := 60.0);
2857
2858 f_bts_0_cfg(BSCVTY, {"rach access-control-class 5 barred",
2859 "access-control-class-rotate 3",
2860 "access-control-class-rotate-quantum 1"});
2861
2862 /* Init and get first sysinfo */
2863 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2864
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002865 for (var integer i:= 0; i < 20; i := i + 1) {
2866 last_si1 := f_recv_next_si1(0);
2867 acc := last_si1.rach_control.acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002868 count := f_acc09_count_allowed(acc);
2869 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2870
2871 if (count != 3) {
2872 log("RSL: EXPECTED SI ACC len=3");
2873 setverdict(fail, "received SI does not match expectations");
2874 break;
2875 }
2876
2877 for (var integer j := 0; j < 10; j := j + 1) {
2878 if (acc[16 - 1 - j] == '0'B) { /* the list marks barred, we count allowed */
2879 times_allowed[j] := times_allowed[j] + 1;
2880 }
2881 }
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002882 }
2883
2884 for (var integer j := 0; j < 10; j := j + 1) {
2885 log("ACC", j, " allowed ", times_allowed[j], " times" );
2886 if (j != 5 and times_allowed[j] < 3) {
2887 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " < 1 times");
2888 } else if (j == 5 and times_allowed[j] > 0) {
2889 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " > 0 times");
2890 }
2891 }
2892
2893 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2894 "rach access-control-class 5 allowed"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002895 f_shutdown_helper();
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002896}
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002897
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002898/* verify ACC startup ramp+rotate feature */
2899testcase TC_si_acc_ramp_rotate() runs on test_CT {
2900 var template SystemInformationConfig sic := SystemInformationConfig_default;
2901 var SystemInformationType1 last_si1;
2902 var AccessControlClass acc;
2903 var ASP_RSL_Unitdata rx_rsl_ud;
2904 var uint8_t count;
2905 var uint8_t prev_count;
2906 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2907
2908 f_init(0, guard_timeout := 80.0);
2909
2910 f_bts_0_cfg(BSCVTY, {"rach access-control-class 4 barred",
2911 "access-control-class-rotate 0",
2912 "access-control-class-rotate-quantum 1",
2913 "access-control-class-ramping",
2914 "access-control-class-ramping-step-interval 5",
2915 "access-control-class-ramping-step-size 5"});
2916
2917 /* Init and get first sysinfo */
2918 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2919 last_si1 := g_system_information[0].si1;
2920 acc := last_si1.rach_control.acc;
2921 count := f_acc09_count_allowed(acc);
2922 /* Adm subset size was set to 0 above, so wait until all ACC are barred */
2923 while (count > 0) {
2924 last_si1 := f_recv_next_si1(0);
2925 acc := last_si1.rach_control.acc;
2926 count := f_acc09_count_allowed(acc);
2927 log("RSL: wait len()=0: GOT SI1 ACC len=", count, ": ", acc);
2928 }
2929
2930 /* Increase adm subset size, we should see ramping start up */
2931 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10"});
2932 prev_count := 0;
2933 while (true) {
2934 last_si1 := f_recv_next_si1(0);
2935 acc := last_si1.rach_control.acc;
2936 count := f_acc09_count_allowed(acc);
2937 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2938
2939 if (prev_count > count) {
2940 setverdict(fail, "ACC allowed count dropped while expecting grow: ", prev_count, " -> ", count);
2941 break;
2942 }
2943
2944 if (count == 9) {
2945 break; /* Maximum reached (10 - 1 perm barred), done here */
2946 }
2947
2948 prev_count := count;
2949 }
2950
2951 setverdict(pass);
2952
2953 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2954 "rach access-control-class 4 allowed",
2955 "no access-control-class-ramping"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002956 f_shutdown_helper();
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002957}
2958
Harald Welte4003d112017-12-09 22:35:39 +01002959testcase TC_ctrl_msc_connection_status() runs on test_CT {
2960 var charstring ctrl_resp;
2961
Harald Welte89d42e82017-12-17 16:42:41 +01002962 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002963
2964 /* See https://osmocom.org/issues/2729 */
2965 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002966 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002967}
2968
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002969testcase TC_ctrl_msc0_connection_status() runs on test_CT {
2970 var charstring ctrl_resp;
2971
2972 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002973
2974 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002975 f_shutdown_helper();
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002976}
2977
Neels Hofmeyr0bc470d2021-08-21 13:37:13 +02002978/* Verify correct stats on the number of configured and connected MSCs */
2979private function f_tc_stat_num_msc_connected_msc_connhdlr(integer expect_num_msc_connected) runs on MSC_ConnHdlr {
2980 g_pars := f_gen_test_hdlr_pars();
2981 var StatsDExpects expect := {
2982 { name := "TTCN3.bsc.0.num_msc.connected", mtype := "g", min := expect_num_msc_connected, max := expect_num_msc_connected },
2983 { name := "TTCN3.bsc.0.num_msc.total", mtype := "g", min := NUM_MSC, max := NUM_MSC }
2984 };
2985 f_statsd_expect(expect);
2986}
2987
2988private function f_tc_stat_num_msc_connected_test_ct(void_fn tc_fn, integer nr_msc) runs on test_CT
2989{
2990 var MSC_ConnHdlr vc_conn;
2991
2992 f_init(nr_bts := 1, handler_mode := true, nr_msc := nr_msc);
2993 f_sleep(1.0);
2994 vc_conn := f_start_handler(tc_fn);
2995 vc_conn.done;
2996
2997 /* Also verify stat exposed on CTRL interface */
2998 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_msc:connected", int2str(nr_msc));
2999 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_msc:total", int2str(NUM_MSC));
3000
3001 f_shutdown_helper();
3002}
3003
3004/* Verify that when 1 MSC is active, that num_msc:connected reports 1. */
3005private function f_tc_stat_num_msc_connected_1(charstring id) runs on MSC_ConnHdlr {
3006 f_tc_stat_num_msc_connected_msc_connhdlr(1);
3007}
3008testcase TC_stat_num_msc_connected_1() runs on test_CT {
3009 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_1), 1);
3010}
3011
3012/* Verify that when 2 MSCs are active, that num_msc:connected reports 2. */
3013private function f_tc_stat_num_msc_connected_2(charstring id) runs on MSC_ConnHdlr {
3014 f_tc_stat_num_msc_connected_msc_connhdlr(2);
3015}
3016testcase TC_stat_num_msc_connected_2() runs on test_CT {
3017 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_2), 2);
3018}
3019
3020/* Verify that when 3 MSCs are active, that num_msc:connected reports 3. */
3021private function f_tc_stat_num_msc_connected_3(charstring id) runs on MSC_ConnHdlr {
3022 f_tc_stat_num_msc_connected_msc_connhdlr(3);
3023}
3024testcase TC_stat_num_msc_connected_3() runs on test_CT {
3025 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_3), 3);
3026}
3027
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +02003028/* Verify correct stats on the number of configured and connected MSCs */
3029private function f_tc_stat_num_bts_connected_msc_connhdlr(integer expect_num_bts_connected) runs on MSC_ConnHdlr {
3030 g_pars := f_gen_test_hdlr_pars();
3031 var StatsDExpects expect := {
3032 { name := "TTCN3.bsc.0.num_bts.oml_connected", mtype := "g", min := expect_num_bts_connected, max := NUM_BTS_CFG },
3033 { name := "TTCN3.bsc.0.num_bts.all_trx_rsl_connected", mtype := "g", min := expect_num_bts_connected, max := expect_num_bts_connected },
3034 { name := "TTCN3.bsc.0.num_bts.total", mtype := "g", min := NUM_BTS_CFG, max := NUM_BTS_CFG },
3035 { name := "TTCN3.bsc.0.num_trx.rsl_connected", mtype := "g", min := expect_num_bts_connected, max := expect_num_bts_connected },
3036 { name := "TTCN3.bsc.0.num_trx.total", mtype := "g", min := NUM_BTS_CFG, max := NUM_BTS_CFG }
3037 };
3038 f_statsd_expect(expect);
3039}
3040
3041private function f_tc_stat_num_bts_connected_test_ct(void_fn tc_fn, integer nr_bts) runs on test_CT {
3042 var MSC_ConnHdlr vc_conn;
3043
3044 f_init(nr_bts := nr_bts, handler_mode := true, nr_msc := 1);
3045 f_sleep(1.0);
3046 vc_conn := f_start_handler(tc_fn);
3047 vc_conn.done;
3048
3049 /* Also verify stat exposed on CTRL interface */
3050 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_bts:all_trx_rsl_connected", int2str(nr_bts));
3051 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_bts:total", int2str(NUM_BTS_CFG));
3052 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_trx:rsl_connected", int2str(nr_bts));
3053 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_trx:total", int2str(NUM_BTS_CFG));
3054
Neels Hofmeyra41ae302021-09-06 22:06:02 +02003055 /* Verify rf_states exposed on CTRL interface */
3056 var charstring expect_net_rf_states := "";
3057 for (var integer i := 0; i < NUM_BTS_CFG; i := i + 1) {
3058 var charstring expect_bts_rf_states := int2str(i) & ",0,";
3059 if (i < NUM_BTS) {
3060 /* In these tests, OML for the first NUM_BTS are always connected via osmo-bts-omldummy */
3061 expect_bts_rf_states := expect_bts_rf_states & "operational,unlocked,";
3062 } else {
3063 /* For remaining i < NUM_BTS_CFG, OML is not connected, i.e. inoperational */
3064 expect_bts_rf_states := expect_bts_rf_states & "inoperational,locked,";
3065 }
3066 /* The RF policy is still global in osmo-bsc, i.e. always "on" */
3067 expect_bts_rf_states := expect_bts_rf_states & "on,";
3068 if (i < nr_bts) {
3069 /* For BTS where RSL is connected, the RSL state will be "up" */
3070 expect_bts_rf_states := expect_bts_rf_states & "rsl-up;";
3071 } else {
3072 expect_bts_rf_states := expect_bts_rf_states & "rsl-down;";
3073 }
3074
3075 f_ctrl_get_exp(IPA_CTRL, "bts." & int2str(i) & ".rf_states", expect_bts_rf_states);
3076 expect_net_rf_states := expect_net_rf_states & expect_bts_rf_states;
3077 }
3078 f_ctrl_get_exp(IPA_CTRL, "rf_states", expect_net_rf_states);
3079
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +02003080 f_shutdown_helper();
3081}
3082
3083/* Verify that when 1 BTS is connected, that num_{bts,trx}:*_connected reports 1. */
3084private function f_tc_stat_num_bts_connected_1(charstring id) runs on MSC_ConnHdlr {
3085 f_tc_stat_num_bts_connected_msc_connhdlr(1);
3086}
3087testcase TC_stat_num_bts_connected_1() runs on test_CT {
3088 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_1), 1);
3089}
3090
3091/* Verify that when 2 BTS is connected, that num_{bts,trx}:*_connected reports 2. */
3092private function f_tc_stat_num_bts_connected_2(charstring id) runs on MSC_ConnHdlr {
3093 f_tc_stat_num_bts_connected_msc_connhdlr(2);
3094}
3095testcase TC_stat_num_bts_connected_2() runs on test_CT {
3096 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_2), 2);
3097}
3098
3099/* Verify that when 3 BTS is connected, that num_{bts,trx}:*_connected reports 3. */
3100private function f_tc_stat_num_bts_connected_3(charstring id) runs on MSC_ConnHdlr {
3101 f_tc_stat_num_bts_connected_msc_connhdlr(3);
3102}
3103testcase TC_stat_num_bts_connected_3() runs on test_CT {
3104 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_3), 3);
3105}
3106
Harald Welte4003d112017-12-09 22:35:39 +01003107testcase TC_ctrl() runs on test_CT {
3108 var charstring ctrl_resp;
3109
Harald Welte89d42e82017-12-17 16:42:41 +01003110 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01003111
3112 /* all below values must match the osmo-bsc.cfg config file used */
3113
Harald Welte6a129692018-03-17 17:30:14 +01003114 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
3115 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Oliver Smith75aa0202019-08-19 14:17:50 +02003116 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "4");
Harald Welte4003d112017-12-09 22:35:39 +01003117
3118 var integer bts_nr := 0;
3119 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
3120 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
3121 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
3122 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
3123 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
3124 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
3125 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
3126
3127 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
3128 f_sleep(2.0);
3129 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
3130 setverdict(fail, "oml-uptime not incrementing as expected");
3131 }
3132 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
3133
3134 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
3135
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003136 f_shutdown_helper();
Harald Welte96c94412017-12-09 03:12:45 +01003137}
3138
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02003139/* Verify that Upon receival of SET "location", BSC forwards a TRAP
3140 "location-state" over the SCCPlite IPA conn */
3141testcase TC_ctrl_location() runs on test_CT {
3142 var MSC_ConnHdlr vc_conn;
3143 var integer bts_nr := 0;
3144
3145 f_init(1, true);
3146 f_sleep(1.0);
3147
3148 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234567,fix3d,0.340000,0.560000,0.780000");
3149 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
3150 "1234567,fix3d,0.340000,0.560000,0.780000,operational,unlocked,on,001,01");
3151
3152 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "1");
3153 f_sleep(2.0);
3154
3155 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234888,fix3d,0.350000,0.570000,0.790000");
3156 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
3157 "1234888,fix3d,0.350000,0.570000,0.790000,operational,locked,off,001,01");
3158
3159 /* should match the one from config */
3160 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "0");
3161
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003162 f_shutdown_helper();
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02003163}
3164
Harald Welte6f521d82017-12-11 19:52:02 +01003165
3166/***********************************************************************
3167 * Paging Testing
3168 ***********************************************************************/
3169
3170type record Cell_Identity {
3171 GsmMcc mcc,
3172 GsmMnc mnc,
3173 GsmLac lac,
3174 GsmCellId ci
3175};
Harald Welte24135bd2018-03-17 19:27:53 +01003176private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01003177private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01003178
Harald Welte5d1a2202017-12-13 19:51:29 +01003179type set of integer BtsIdList;
3180
3181private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
3182 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
3183 if (bts_id == bts_ids[j]) {
3184 return true;
3185 }
3186 }
3187 return false;
3188}
Harald Welte6f521d82017-12-11 19:52:02 +01003189
3190/* core paging test helper function; used by most paging test cases */
3191private function f_pageing_helper(hexstring imsi,
3192 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01003193 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01003194 template RSL_ChanNeeded rsl_chneed := omit,
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003195 template (omit) OCT4 tmsi := omit) runs on test_CT
Harald Welte6f521d82017-12-11 19:52:02 +01003196{
3197 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003198 var template MobileIdentityV mi;
Harald Welte6f521d82017-12-11 19:52:02 +01003199 var RSL_Message rx_rsl;
3200 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01003201 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01003202
3203 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01003204
3205 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01003206 for (i := 0; i < NUM_BTS; i := i + 1) {
3207 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01003208 }
Harald Welte6f521d82017-12-11 19:52:02 +01003209
3210 if (isvalue(rsl_chneed)) {
3211 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
3212 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
3213 } else {
3214 bssmap_chneed := omit;
3215 }
3216
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003217 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[0].sccp_addr_peer, g_bssap[0].sccp_addr_own,
3218 ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed)));
Harald Welte6f521d82017-12-11 19:52:02 +01003219
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003220 if (not istemplatekind(tmsi, "omit")) {
3221 mi := t_MI_TMSI(tmsi);
Harald Welte6f521d82017-12-11 19:52:02 +01003222 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003223 mi := tr_MI_IMSI(imsi);
Harald Welte6f521d82017-12-11 19:52:02 +01003224 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003225
Harald Welte5d1a2202017-12-13 19:51:29 +01003226 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003227 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(mi));
Harald Welte5d1a2202017-12-13 19:51:29 +01003228 /* check channel type, paging group */
3229 if (rx_rsl.ies[1].body.paging_group != paging_group) {
3230 setverdict(fail, "Paging for wrong paging group");
3231 }
3232 if (ispresent(rsl_chneed) and
3233 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
3234 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
3235 }
Harald Welte6f521d82017-12-11 19:52:02 +01003236 }
Harald Welte2fccd982018-01-31 15:48:19 +01003237 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01003238 /* do a quick check on all not-included BTSs if they received paging */
3239 for (i := 0; i < NUM_BTS; i := i + 1) {
3240 timer T := 0.1;
3241 if (f_bts_in_list(i, bts_ids)) {
3242 continue;
3243 }
3244 T.start;
3245 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003246 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(mi))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003247 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
3248 }
3249 [] IPA_RSL[i].receive { repeat; }
3250 [] T.timeout { }
3251 }
Harald Welte6f521d82017-12-11 19:52:02 +01003252 }
3253
3254 setverdict(pass);
3255}
3256
Harald Welte5d1a2202017-12-13 19:51:29 +01003257const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01003258const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01003259const BtsIdList c_BtsId_LAC1 := { 0, 1 };
3260const BtsIdList c_BtsId_LAC2 := { 2 };
3261
Harald Welte6f521d82017-12-11 19:52:02 +01003262/* PAGING by IMSI + TMSI */
3263testcase TC_paging_imsi_nochan() runs on test_CT {
3264 var BSSMAP_FIELD_CellIdentificationList cid_list;
3265 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01003266 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003267 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003268}
3269
3270/* PAGING by IMSI + TMSI */
3271testcase TC_paging_tmsi_nochan() runs on test_CT {
3272 var BSSMAP_FIELD_CellIdentificationList cid_list;
3273 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003274 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003275 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003276}
3277
3278/* Paging with different "channel needed' values */
3279testcase TC_paging_tmsi_any() runs on test_CT {
3280 var BSSMAP_FIELD_CellIdentificationList cid_list;
3281 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003282 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003283 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003284}
3285testcase TC_paging_tmsi_sdcch() runs on test_CT {
3286 var BSSMAP_FIELD_CellIdentificationList cid_list;
3287 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003288 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003289 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003290}
3291testcase TC_paging_tmsi_tch_f() runs on test_CT {
3292 var BSSMAP_FIELD_CellIdentificationList cid_list;
3293 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003294 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003295 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003296}
3297testcase TC_paging_tmsi_tch_hf() runs on test_CT {
3298 var BSSMAP_FIELD_CellIdentificationList cid_list;
3299 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003300 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003301 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003302}
3303
3304/* Paging by CGI */
3305testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
3306 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3307 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003308 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003309 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003310}
3311
3312/* Paging by LAC+CI */
3313testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
3314 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3315 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003316 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003317 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003318}
3319
3320/* Paging by CI */
3321testcase TC_paging_imsi_nochan_ci() runs on test_CT {
3322 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3323 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003324 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003325 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003326}
3327
3328/* Paging by LAI */
3329testcase TC_paging_imsi_nochan_lai() runs on test_CT {
3330 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3331 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003332 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003333 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003334}
3335
3336/* Paging by LAC */
3337testcase TC_paging_imsi_nochan_lac() runs on test_CT {
3338 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3339 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003340 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003341 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003342}
3343
3344/* Paging by "all in BSS" */
3345testcase TC_paging_imsi_nochan_all() runs on test_CT {
3346 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3347 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01003348 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003349 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003350}
3351
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003352/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003353testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
3354 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3355 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 +01003356 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003357 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003358}
Harald Welte6f521d82017-12-11 19:52:02 +01003359
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003360/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003361testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
3362 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3363 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003364 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003365 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003366}
3367
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003368/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003369testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
3370 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3371 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003372 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003373 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003374}
3375
Harald Welte6f521d82017-12-11 19:52:02 +01003376/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01003377testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
3378 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3379 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
3380 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003381 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003382}
3383
3384/* Paging on empty list: Verify none of them page */
3385testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
3386 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3387 cid_list := { cIl_LAC := { } };
3388 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003389 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003390}
3391
Stefan Sperling049a86e2018-03-20 15:51:00 +01003392/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
3393testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
3394 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3395 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
3396 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
3397 f_shutdown_helper();
3398}
3399
Harald Welte6f521d82017-12-11 19:52:02 +01003400/* Verify paging retransmission interval + count */
3401/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01003402/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01003403
Harald Weltee65d40e2017-12-13 00:09:06 +01003404/* Verify PCH load */
3405testcase TC_paging_imsi_load() runs on test_CT {
3406 var BSSMAP_FIELD_CellIdentificationList cid_list;
3407 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01003408 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01003409 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003410 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01003411
3412 /* tell BSC there is no paging space anymore */
3413 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01003414 f_sleep(0.2);
3415 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01003416
3417 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
3418 * there would be 8 retransmissions during 4 seconds */
3419 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01003420 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01003421 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003422 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Weltee65d40e2017-12-13 00:09:06 +01003423 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02003424 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01003425 }
Harald Welte2caa1062018-03-17 18:19:05 +01003426 [] T_retrans.timeout {
3427 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
3428 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
3429 T_retrans.start;
3430 repeat;
3431 }
Harald Weltee65d40e2017-12-13 00:09:06 +01003432 [] T.timeout {
3433 setverdict(pass);
3434 }
3435 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003436
3437 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01003438}
3439
Harald Welte235ebf12017-12-15 14:18:16 +01003440/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01003441testcase TC_paging_counter() runs on test_CT {
3442 var BSSMAP_FIELD_CellIdentificationList cid_list;
3443 timer T := 4.0;
3444 var integer i;
3445 var integer paging_attempted_bsc;
3446 var integer paging_attempted_bts[NUM_BTS];
Oliver Smith8b343d32021-11-26 13:01:42 +01003447 var integer paging_expired_bsc;
Harald Welte1ff69992017-12-14 12:31:17 +01003448 var integer paging_expired_bts[NUM_BTS];
3449 cid_list := valueof(ts_BSSMAP_CIL_noCell);
3450
3451 f_init();
3452
3453 /* read counters before paging */
3454 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
Oliver Smith8b343d32021-11-26 13:01:42 +01003455 if (Misc_Helpers.f_osmo_repo_is("nightly")) { /* osmo-bsc > 1.8.0 */
3456 paging_expired_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:expired");
3457 }
Harald Welte1ff69992017-12-14 12:31:17 +01003458 for (i := 0; i < NUM_BTS; i := i+1) {
3459 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
3460 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
3461 }
3462
3463 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
3464
3465 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
3466 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
3467 for (i := 0; i < NUM_BTS; i := i+1) {
3468 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
3469 paging_attempted_bts[i]+1);
3470 }
3471
3472 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
3473 f_sleep(12.0);
Oliver Smith8b343d32021-11-26 13:01:42 +01003474 if (Misc_Helpers.f_osmo_repo_is("nightly")) { /* osmo-bsc > 1.8.0 */
3475 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:expired", paging_expired_bsc+1);
3476 }
Harald Welte1ff69992017-12-14 12:31:17 +01003477 for (i := 0; i < NUM_BTS; i := i+1) {
3478 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
3479 paging_expired_bts[i]+1);
3480 }
Harald Welte1ff69992017-12-14 12:31:17 +01003481
Philipp Maier282ca4b2018-02-27 17:17:00 +01003482 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01003483}
3484
3485
Harald Welte10985002017-12-12 09:29:15 +01003486/* Verify paging stops after A-RESET */
3487testcase TC_paging_imsi_a_reset() runs on test_CT {
3488 var BSSMAP_FIELD_CellIdentificationList cid_list;
3489 timer T := 3.0;
3490 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003491 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01003492
3493 /* Perform a BSSMAP Reset and wait for ACK */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003494 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 +01003495 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003496 [] 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 +01003497 [] BSSAP.receive { repeat; }
3498 }
3499
Daniel Willmanncbef3982018-07-30 09:22:40 +02003500 /* Wait to avoid a possible race condition if a paging message is
3501 * received right before the reset ACK. */
3502 f_sleep(0.2);
3503
Harald Welte10985002017-12-12 09:29:15 +01003504 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01003505 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
3506 IPA_RSL[i].clear;
3507 }
Harald Welte10985002017-12-12 09:29:15 +01003508
3509 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
3510 T.start;
3511 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003512 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte10985002017-12-12 09:29:15 +01003513 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003514 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01003515 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003516 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003517 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003518 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003519 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003520 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003521 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003522 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003523 }
Harald Welte10985002017-12-12 09:29:15 +01003524 [] T.timeout {
3525 setverdict(pass);
3526 }
3527 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003528
3529 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01003530}
Harald Welteae026692017-12-09 01:03:01 +01003531
Philipp Maierf45824a2019-08-14 14:44:10 +02003532/* Verify how we handle unsolicited Paging Response. In case of an unsolicit
3533 * paging response we can not know which MSC is in charge, so we will blindly
3534 * pick the first configured MSC. This behavior is required in order to make
3535 * MT-CSFB calls working because in those cases the BSC can not know that the
3536 * MSC has already paged the subscriver via SGs. So any MT-CSFB call will look
3537 * like an unsolicited Paging Response to the MSC.
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003538 */
3539testcase TC_paging_resp_unsol() runs on test_CT {
3540
3541 f_init(1);
Philipp Maierf45824a2019-08-14 14:44:10 +02003542 timer T := 5.0;
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003543
3544 var BSSAP_N_CONNECT_ind rx_c_ind;
3545 var DchanTuple dt;
3546 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
Philipp Maierf45824a2019-08-14 14:44:10 +02003547 var octetstring rr_pag_resp := enc_PDU_ML3_MS_NW(l3);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003548
3549 /* Send CHAN RQD and wait for allocation; acknowledge it */
3550 dt.rsl_chan_nr := f_chreq_act_ack();
3551
3552 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
3553 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
3554
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003555
Philipp Maierf45824a2019-08-14 14:44:10 +02003556 /* Expevct a CR with a matching Paging response on the A-Interface */
3557 T.start;
3558 alt {
3559 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(rr_pag_resp))) {
3560 setverdict(pass);
3561 }
3562 [] BSSAP.receive {
3563 setverdict(fail, "Received unexpected message on A-Interface!");
3564 }
3565 [] T.timeout {
3566 setverdict(fail, "Received nothing on A-Interface!");
3567 }
3568 }
3569
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003570 f_shutdown_helper();
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003571}
3572
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003573/* Test RSL link drop causes counter increment */
3574testcase TC_rsl_drop_counter() runs on test_CT {
3575 var integer rsl_fail;
3576
Harald Welte89d42e82017-12-17 16:42:41 +01003577 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003578
3579 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
3580
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +01003581 f_ipa_rsl_stop(bts[0].rsl);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003582
3583 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
3584
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003585 f_shutdown_helper();
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003586}
3587
3588/* TODO: Test OML link drop causes counter increment */
3589
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003590/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
3591function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
3592 timer T := 10.0;
3593
3594 bts[0].rsl.id := "IPA-0-RSL";
Harald Welte71389132021-12-09 21:58:18 +01003595 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA") alive;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003596 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
3597 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
Oliver Smith92c2bdb2019-08-20 15:11:24 +02003598 bts[0].rsl.ccm_pars.unit_id := "99/0/0"; /* value which is unknown at BTS */
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003599
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01003600 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003601
3602 f_init_mgcp("VirtMSC");
3603
3604 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
3605 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
3606 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
3607 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
3608
3609 /* wait for IPA OML link to connect and then disconnect */
3610 T.start;
3611 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +07003612 [] IPA_RSL[0].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) {
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003613 T.stop;
3614 return true;
3615 }
3616 [] IPA_RSL[0].receive { repeat }
3617 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02003618 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003619 }
3620 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003621 return false;
3622}
3623
3624/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3625testcase TC_rsl_unknown_unit_id() runs on test_CT {
3626 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
3627 setverdict(pass);
3628 } else {
3629 setverdict(fail, "Timeout RSL waiting for connection to close");
3630 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003631 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003632}
3633
3634
3635/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3636testcase TC_oml_unknown_unit_id() runs on test_CT {
3637 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
3638 setverdict(pass);
3639 } else {
3640 setverdict(fail, "Timeout OML waiting for connection to close");
3641 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003642 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003643}
3644
3645
Harald Weltec1a2fff2017-12-17 11:06:19 +01003646/***********************************************************************
Harald Welte6811d102019-04-14 22:23:14 +02003647 * "New world" test cases using RSL_Emulation + RAN_Emulation
Harald Weltec1a2fff2017-12-17 11:06:19 +01003648 ***********************************************************************/
3649
Harald Welte6811d102019-04-14 22:23:14 +02003650import from RAN_Emulation all;
Harald Welte47cd0e32020-08-21 12:39:11 +02003651import from BSSAP_LE_Emulation all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01003652import from RSL_Emulation all;
3653import from MSC_ConnectionHandler all;
3654
3655type function void_fn(charstring id) runs on MSC_ConnHdlr;
3656
Harald Welte336820c2018-05-31 20:34:52 +02003657/* helper function to create and connect a MSC_ConnHdlr component */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003658private function f_connect_handler(inout MSC_ConnHdlr vc_conn, integer bssap_idx := 0) runs on test_CT {
3659 connect(vc_conn:RAN, g_bssap[bssap_idx].vc_RAN:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01003660 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003661 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01003662 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01003663 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01003664 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
3665 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
3666 }
Neels Hofmeyr91401012019-07-11 00:42:35 +02003667 if (isvalue(bts[2])) {
3668 connect(vc_conn:RSL2, bts[2].rsl.vc_RSL:CLIENT_PT);
3669 connect(vc_conn:RSL2_PROC, bts[2].rsl.vc_RSL:RSL_PROC);
3670 }
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003671 connect(vc_conn:BSSAP, g_bssap[bssap_idx].vc_RAN:CLIENT);
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02003672 if (mp_enable_lcs_tests) {
3673 connect(vc_conn:BSSAP_LE, g_bssap_le.vc_BSSAP_LE:CLIENT);
3674 connect(vc_conn:BSSAP_LE_PROC, g_bssap_le.vc_BSSAP_LE:PROC);
3675 }
Daniel Willmann191e0d92018-01-17 12:44:35 +01003676 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02003677 connect(vc_conn:MGCP_MULTI, vc_MGCP:MGCP_CLIENT_MULTI);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003678 connect(vc_conn:STATSD_PROC, vc_STATSD:STATSD_PROC);
Harald Welte336820c2018-05-31 20:34:52 +02003679}
3680
Neels Hofmeyrda436782021-07-20 22:09:06 +02003681function f_start_handler_create(template (omit) TestHdlrParams pars := omit)
Harald Welte336820c2018-05-31 20:34:52 +02003682runs on test_CT return MSC_ConnHdlr {
3683 var charstring id := testcasename();
3684 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003685 var integer bssap_idx := 0;
3686 if (isvalue(pars)) {
3687 bssap_idx := valueof(pars).mscpool.bssap_idx;
3688 }
Harald Welte336820c2018-05-31 20:34:52 +02003689 vc_conn := MSC_ConnHdlr.create(id);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003690 f_connect_handler(vc_conn, bssap_idx);
Neels Hofmeyrda436782021-07-20 22:09:06 +02003691 return vc_conn;
3692}
3693
3694function f_start_handler_run(MSC_ConnHdlr vc_conn, void_fn fn, template (omit) TestHdlrParams pars := omit)
3695runs on test_CT return MSC_ConnHdlr {
3696 var charstring id := testcasename();
Neels Hofmeyr1708d1b2020-10-10 16:56:48 +02003697 /* Emit a marker to appear in the SUT's own logging output */
Neels Hofmeyrda436782021-07-20 22:09:06 +02003698 f_logp(BSCVTY, id & "() start");
Harald Weltea0630032018-03-20 21:09:55 +01003699 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003700 return vc_conn;
3701}
3702
Neels Hofmeyrda436782021-07-20 22:09:06 +02003703function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
3704runs on test_CT return MSC_ConnHdlr {
3705 return f_start_handler_run(f_start_handler_create(pars), fn, pars);
3706}
3707
Harald Weltea0630032018-03-20 21:09:55 +01003708/* first function inside ConnHdlr component; sets g_pars + starts function */
3709private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
3710runs on MSC_ConnHdlr {
3711 if (isvalue(pars)) {
3712 g_pars := valueof(pars);
3713 }
3714 fn.apply(id);
3715}
3716
Oliver Smith26a3db72021-07-09 13:51:29 +02003717private function f_vty_encryption_a5(charstring options) runs on test_CT {
3718 f_vty_transceive(BSCVTY, "configure terminal");
3719 f_vty_transceive(BSCVTY, "network");
3720 f_vty_transceive(BSCVTY, "encryption a5 " & options);
3721 f_vty_transceive(BSCVTY, "exit");
3722 f_vty_transceive(BSCVTY, "exit");
3723}
3724
3725private function f_vty_encryption_a5_reset() runs on test_CT {
3726 /* keep in sync with docker-playground.git ttcn3-bsc-test/osmo-bsc.cfg */
3727 f_vty_encryption_a5("0 1 3");
3728}
3729
Harald Welte3c86ea02018-05-10 22:28:05 +02003730/* Establish signalling channel (non-assignment case) followed by cipher mode */
3731private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003732 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3733 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02003734 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02003735 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
3736 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
3737 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
3738 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02003739
Philipp Maier23000732018-05-18 11:25:37 +02003740 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02003741}
3742testcase TC_ciph_mode_a5_0() runs on test_CT {
3743 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003744 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003745 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
3746
3747 f_init(1, true);
3748 f_sleep(1.0);
3749 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3750 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003751 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003752}
3753testcase TC_ciph_mode_a5_1() runs on test_CT {
3754 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003755 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003756 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
3757
3758 f_init(1, true);
3759 f_sleep(1.0);
3760 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3761 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003762 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003763}
Oliver Smith50b98122021-07-09 15:00:28 +02003764/* OS#4975: verify that A5/2 is preferred over A5/0 */
3765testcase TC_ciph_mode_a5_2_0() runs on test_CT {
3766 var MSC_ConnHdlr vc_conn;
3767 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3768
3769 pars.encr := valueof(t_EncrParams('05'O, f_rnd_octstring(8))); /* A5/0 and A5/2 (0x01|0x04)*/
3770 pars.encr_exp_enc_alg := '04'O; /* A5/2 */
3771
3772 f_init(1, true);
3773 f_vty_encryption_a5("0 1 2 3");
3774 f_sleep(1.0);
3775 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3776 vc_conn.done;
3777 f_vty_encryption_a5_reset();
3778 f_shutdown_helper();
3779}
Oliver Smith1dff88d2021-07-09 08:45:51 +02003780/* OS#4975: verify that A5/1 is preferred over A5/2 */
3781testcase TC_ciph_mode_a5_2_1() runs on test_CT {
3782 var MSC_ConnHdlr vc_conn;
3783 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3784
3785 pars.encr := valueof(t_EncrParams('06'O, f_rnd_octstring(8))); /* A5/1 and A5/2 (0x02|0x04)*/
3786 pars.encr_exp_enc_alg := '02'O; /* A5/1 */
3787
3788 f_init(1, true);
3789 f_vty_encryption_a5("1 2");
3790 f_sleep(1.0);
3791 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3792 vc_conn.done;
3793 f_vty_encryption_a5_reset();
3794 f_shutdown_helper();
3795}
Harald Welte3c86ea02018-05-10 22:28:05 +02003796testcase TC_ciph_mode_a5_3() runs on test_CT {
3797 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003798 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003799 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
3800
3801 f_init(1, true);
3802 f_sleep(1.0);
3803 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3804 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003805 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003806}
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003807/* Establish a Signalling channel with A5/4 encryption. */
3808testcase TC_ciph_mode_a5_4() runs on test_CT {
3809 var MSC_ConnHdlr vc_conn;
3810 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3811 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Harald Welte3c86ea02018-05-10 22:28:05 +02003812
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003813 f_init(1, true);
Oliver Smith26a3db72021-07-09 13:51:29 +02003814 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003815 f_sleep(1.0);
3816 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3817 vc_conn.done;
Oliver Smith26a3db72021-07-09 13:51:29 +02003818 f_vty_encryption_a5_reset();
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003819 f_shutdown_helper();
3820}
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003821/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
3822private function f_tc_assignment_aoip_tla_v6(charstring id) runs on MSC_ConnHdlr {
3823 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3824 var PDU_BSSAP ass_cmd := f_gen_ass_req(aoip_tla := "::3");
3825 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3826 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3827
3828 f_establish_fully(ass_cmd, exp_compl);
3829}
3830testcase TC_assignment_aoip_tla_v6() runs on test_CT {
3831 var MSC_ConnHdlr vc_conn;
3832 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3833
3834 f_init(1, true);
3835 f_sleep(1.0);
3836 vc_conn := f_start_handler(refers(f_tc_assignment_aoip_tla_v6), pars);
3837 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003838 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003839}
3840
Harald Welte3c86ea02018-05-10 22:28:05 +02003841
3842/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02003843private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003844 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3845 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003846
Harald Welte552620d2017-12-16 23:21:36 +01003847 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3848 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01003849
Harald Weltea0630032018-03-20 21:09:55 +01003850 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01003851}
Harald Welte552620d2017-12-16 23:21:36 +01003852testcase TC_assignment_fr_a5_0() runs on test_CT {
3853 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003854 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003855 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01003856
Harald Welte89d42e82017-12-17 16:42:41 +01003857 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003858 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003859 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003860 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003861 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003862}
Harald Welte552620d2017-12-16 23:21:36 +01003863testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01003864 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003865 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003866 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003867
Harald Welte89d42e82017-12-17 16:42:41 +01003868 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003869 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003870 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3871 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003872 f_shutdown_helper();
Harald Welte651fcdc2018-05-10 20:23:16 +02003873}
3874testcase TC_assignment_fr_a5_3() runs on test_CT {
3875 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003876 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003877 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003878
Harald Welte651fcdc2018-05-10 20:23:16 +02003879 f_init(1, true);
3880 f_sleep(1.0);
3881 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003882 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003883 f_shutdown_helper();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003884}
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003885/* Establish a Signalling channel and re-assign to TCH/F with A5/4 encryption. */
3886testcase TC_assignment_fr_a5_4() runs on test_CT {
3887 var MSC_ConnHdlr vc_conn;
3888 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3889 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
3890
3891 f_init(1, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02003892 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003893 f_sleep(1.0);
3894 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3895 vc_conn.done;
Oliver Smith7eabd312021-07-12 14:18:56 +02003896 f_vty_encryption_a5_reset();
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003897 f_shutdown_helper();
3898}
Harald Weltec1a2fff2017-12-17 11:06:19 +01003899
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +02003900/* Allow only A5/4, but omit the Kc128 IE from MSC's msg. Expect Cipher Mode Reject. */
3901testcase TC_assignment_fr_a5_4_fail() runs on test_CT {
3902 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3903 var MSC_ConnHdlr vc_conn;
3904
3905 f_init(1, true);
3906 f_sleep(1.0);
3907
3908 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8))); // A5/4 support, but Kc128 missing!
3909 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
3910 vc_conn.done;
3911 f_shutdown_helper();
3912}
3913
Harald Welte552620d2017-12-16 23:21:36 +01003914/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
3915private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003916 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01003917 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02003918 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003919
3920 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003921 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
3922
Harald Weltea0630032018-03-20 21:09:55 +01003923 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01003924}
Harald Welte552620d2017-12-16 23:21:36 +01003925testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
3926 var MSC_ConnHdlr vc_conn;
3927
Harald Welte89d42e82017-12-17 16:42:41 +01003928 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003929 f_sleep(1.0);
3930
Harald Welte8863fa12018-05-10 20:15:27 +02003931 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01003932 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003933 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003934}
3935
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003936private function f_TC_assignment_a5_not_sup(charstring id) runs on MSC_ConnHdlr {
3937 var template PDU_BSSAP exp_ass_cpl := f_gen_exp_compl();
3938 var PDU_BSSAP exp_ass_req := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003939
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003940 exp_ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3941 exp_ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3942
3943 /* this is like the beginning of f_establish_fully(), but only up to ciphering reject */
3944
3945 var BSSMAP_FIELD_CodecType codecType;
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003946
3947 codecType := exp_ass_req.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType;
3948 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
3949
3950 f_create_chan_and_exp();
3951 /* we should now have a COMPL_L3 at the MSC */
3952
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003953 /* Start ciphering, expect Cipher Mode Reject */
Neels Hofmeyr6c388f22021-06-11 02:36:56 +02003954 f_cipher_mode(g_pars.encr, exp_fail := true);
Harald Welte552620d2017-12-16 23:21:36 +01003955}
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003956testcase TC_assignment_fr_a5_not_sup() runs on test_CT {
3957 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01003958 var MSC_ConnHdlr vc_conn;
3959
Harald Welte89d42e82017-12-17 16:42:41 +01003960 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003961 f_sleep(1.0);
3962
Neels Hofmeyr0588cad2021-06-11 01:38:18 +02003963 pars.encr := valueof(t_EncrParams('20'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003964 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003965 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003966 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003967}
3968
3969
Harald Welte4532e0a2017-12-23 02:05:44 +01003970private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003971 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01003972 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02003973 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01003974 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003975
3976 f_statsd_reset();
Harald Weltea0630032018-03-20 21:09:55 +01003977 f_establish_fully(ass_cmd, exp_compl);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003978
3979 var StatsDExpects expect := {
Daniel Willmannc5398f72020-09-21 10:41:35 +02003980 { name := "TTCN3.bts.0.chreq.total", mtype := "c", min := 1, max := 1},
3981 { name := "TTCN3.bts.0.chreq.successful", mtype := "c", min := 1, max := 1},
Daniel Willmannebdecc02020-08-12 15:30:17 +02003982 { name := "TTCN3.bsc.0.assignment.attempted", mtype := "c", min := 1, max := 1},
3983 { name := "TTCN3.bsc.0.assignment.completed", mtype := "c", min := 1, max := 1}
3984 };
3985 f_statsd_expect(expect);
Harald Welte4532e0a2017-12-23 02:05:44 +01003986}
3987
3988testcase TC_assignment_sign() runs on test_CT {
3989 var MSC_ConnHdlr vc_conn;
3990
3991 f_init(1, true);
3992 f_sleep(1.0);
3993
Harald Welte8863fa12018-05-10 20:15:27 +02003994 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01003995 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003996 f_shutdown_helper();
Harald Welte4532e0a2017-12-23 02:05:44 +01003997}
3998
Harald Welte60aa5762018-03-21 19:33:13 +01003999/***********************************************************************
4000 * Codec (list) testing
4001 ***********************************************************************/
4002
4003/* check if the given rsl_mode is compatible with the a_elem */
4004private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
4005return boolean {
4006 select (a_elem.codecType) {
4007 case (GSM_FR) {
4008 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
4009 return true;
4010 }
4011 }
4012 case (GSM_HR) {
4013 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
4014 return true;
4015 }
4016 }
4017 case (GSM_EFR) {
4018 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
4019 return true;
4020 }
4021 }
4022 case (FR_AMR) {
4023 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
4024 return true;
4025 }
4026 }
4027 case (HR_AMR) {
4028 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
4029 return true;
4030 }
4031 }
4032 case else { }
4033 }
4034 return false;
4035}
4036
4037/* check if the given rsl_mode is compatible with the a_list */
4038private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
4039return boolean {
4040 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
4041 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
4042 return true;
4043 }
4044 }
4045 return false;
4046}
4047
4048/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02004049function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01004050return BSSMAP_IE_ChannelType {
4051 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
4052 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
4053 select (a_elem.codecType) {
4054 case (GSM_FR) {
4055 ret.channelRateAndType := ChRate_TCHF;
4056 ret.speechId_DataIndicator := Spdi_TCHF_FR;
4057 }
4058 case (GSM_HR) {
4059 ret.channelRateAndType := ChRate_TCHH;
4060 ret.speechId_DataIndicator := Spdi_TCHH_HR;
4061 }
4062 case (GSM_EFR) {
4063 ret.channelRateAndType := ChRate_TCHF;
4064 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
4065 }
4066 case (FR_AMR) {
4067 ret.channelRateAndType := ChRate_TCHF;
4068 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
4069 }
4070 case (HR_AMR) {
4071 ret.channelRateAndType := ChRate_TCHH;
4072 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
4073 }
4074 case else {
4075 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02004076 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01004077 }
4078 }
4079 return ret;
4080}
4081
Harald Weltea63b9102018-03-22 20:36:16 +01004082private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
4083return template RSL_IE_Body {
4084 var template RSL_IE_Body mode_ie := {
4085 chan_mode := {
4086 len := ?,
4087 reserved := ?,
4088 dtx_d := ?,
4089 dtx_u := ?,
4090 spd_ind := RSL_SPDI_SPEECH,
4091 ch_rate_type := -,
4092 coding_alg_rate := -
4093 }
4094 }
4095
4096 select (a_elem.codecType) {
4097 case (GSM_FR) {
4098 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4099 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
4100 }
4101 case (GSM_HR) {
4102 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
4103 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
4104 }
4105 case (GSM_EFR) {
4106 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4107 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
4108 }
4109 case (FR_AMR) {
4110 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4111 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
4112 }
4113 case (HR_AMR) {
4114 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
4115 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
4116 }
4117 }
4118 return mode_ie;
4119}
4120
Harald Welte60aa5762018-03-21 19:33:13 +01004121type record CodecListTest {
4122 BSSMAP_IE_SpeechCodecList codec_list,
4123 charstring id
4124}
4125type record of CodecListTest CodecListTests
4126
4127private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004128 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
4129 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
Harald Welte60aa5762018-03-21 19:33:13 +01004130
4131 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02004132 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte79f3f542018-05-25 20:02:37 +02004133 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
4134 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
4135 g_pars.ass_codec_list.codecElements[0];
Philipp Maierd0e64b02019-03-13 14:15:23 +01004136 if (isvalue(g_pars.expect_mr_s0_s7)) {
4137 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
4138 g_pars.expect_mr_s0_s7;
4139 }
Harald Welte79f3f542018-05-25 20:02:37 +02004140 }
Harald Welte60aa5762018-03-21 19:33:13 +01004141 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
4142 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01004143 log("expecting ASS COMPL like this: ", exp_compl);
4144
4145 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01004146
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004147 if (not g_pars.expect_channel_mode_modify) {
4148 /* Verify that the RSL-side activation actually matches our expectations */
4149 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
Harald Weltea63b9102018-03-22 20:36:16 +01004150
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004151 var RSL_IE_Body mode_ie;
4152 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
4153 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02004154 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004155 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004156 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
4157 if (not match(mode_ie, t_mode_ie)) {
4158 log("mode_ie ", mode_ie, " != t_mode_ie ", t_mode_ie);
4159 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004160 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004161
4162 var RSL_IE_Body mr_conf;
4163 if (g_pars.expect_mr_conf_ie != omit) {
4164 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
4165 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
4166 mtc.stop;
4167 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004168 log("found RSL MR CONFIG IE: ", mr_conf);
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004169
4170 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
4171 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
4172 g_pars.expect_mr_conf_ie);
4173 }
4174 } else {
4175 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
4176 log("found RSL MR CONFIG IE: ", mr_conf);
4177 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
4178 mtc.stop;
4179 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004180 }
4181 }
Harald Welte60aa5762018-03-21 19:33:13 +01004182}
4183
Philipp Maierd0e64b02019-03-13 14:15:23 +01004184private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
4185
4186 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4187 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4188
4189 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02004190 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maierd0e64b02019-03-13 14:15:23 +01004191 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
4192 }
4193 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
4194 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
4195 log("expecting ASS FAIL like this: ", exp_fail);
4196
4197 f_establish_fully(ass_cmd, exp_fail);
4198}
4199
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004200const CounterNameVals counternames_bsc_bts_assignment := {
4201 { "assignment:attempted", 0 },
4202 { "assignment:completed", 0 },
4203 { "assignment:stopped", 0 },
4204 { "assignment:no_channel", 0 },
4205 { "assignment:timeout", 0 },
4206 { "assignment:failed", 0 },
4207 { "assignment:error", 0 }
4208};
4209
4210const CounterNameVals counternames_bts_assignment := {
4211 { "assignment:attempted_sign", 0 },
4212 { "assignment:attempted_speech", 0 },
4213 { "assignment:completed_sign", 0 },
4214 { "assignment:completed_speech", 0 },
4215 { "assignment:stopped_sign", 0 },
4216 { "assignment:stopped_speech", 0 },
4217 { "assignment:no_channel_sign", 0 },
4218 { "assignment:no_channel_speech", 0 },
4219 { "assignment:timeout_sign", 0 },
4220 { "assignment:timeout_speech", 0 },
4221 { "assignment:failed_sign", 0 },
4222 { "assignment:failed_speech", 0 },
4223 { "assignment:error_sign", 0 },
4224 { "assignment:error_speech", 0 }
4225};
4226
4227function f_ctrs_bsc_and_bts_assignment_init(integer bts_count := NUM_BTS) runs on test_CT {
4228 var CounterNameVals bts_names := counternames_bsc_bts_assignment & counternames_bts_assignment;
4229 f_ctrs_bts_init(bts_count, bts_names);
4230 f_ctrs_bsc_init(counternames_bsc_bts_assignment);
4231}
4232
Harald Welte60aa5762018-03-21 19:33:13 +01004233testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004234 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004235 var MSC_ConnHdlr vc_conn;
4236
4237 f_init(1, true);
4238 f_sleep(1.0);
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004239 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004240
4241 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004242 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004243 vc_conn.done;
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004244
4245 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4246 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4247 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4248 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4249 f_ctrs_bts_verify();
4250
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004251 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004252}
4253
4254testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004255 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004256 var MSC_ConnHdlr vc_conn;
4257
4258 f_init(1, true);
4259 f_sleep(1.0);
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004260 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004261
4262 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004263 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004264 vc_conn.done;
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004265
4266 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4267 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4268 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4269 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4270 f_ctrs_bts_verify();
4271
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004272 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004273}
4274
4275testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004276 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004277 var MSC_ConnHdlr vc_conn;
4278
4279 f_init(1, true);
4280 f_sleep(1.0);
4281
4282 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004283 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004284 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004285 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004286}
4287
Philipp Maierd0e64b02019-03-13 14:15:23 +01004288/* Allow 5,90k only (current default config) */
4289private function f_allow_amr_rate_5_90k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00004290 f_vty_cfg_msc(BSCVTY, 0, {
4291 "amr-config 12_2k forbidden",
4292 "amr-config 10_2k forbidden",
4293 "amr-config 7_95k forbidden",
4294 "amr-config 7_40k forbidden",
4295 "amr-config 6_70k forbidden",
4296 "amr-config 5_90k allowed",
4297 "amr-config 5_15k forbidden",
4298 "amr-config 4_75k forbidden"
4299 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01004300}
4301
4302/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
4303 * ("Config-NB-Code = 1") */
4304private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00004305 f_vty_cfg_msc(BSCVTY, 0, {
4306 "amr-config 12_2k allowed",
4307 "amr-config 10_2k forbidden",
4308 "amr-config 7_95k forbidden",
4309 "amr-config 7_40k allowed",
4310 "amr-config 6_70k forbidden",
4311 "amr-config 5_90k allowed",
4312 "amr-config 5_15k forbidden",
4313 "amr-config 4_75k allowed"
4314 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01004315}
4316
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004317private function f_vty_amr_start_mode_set(boolean fr, charstring startmode) runs on test_CT {
4318 var charstring tch;
4319 if (fr) {
4320 tch := "tch-f";
4321 } else {
4322 tch := "tch-h";
4323 }
4324 f_vty_cfg_bts(BSCVTY, 0, { "amr " & tch & " start-mode " & startmode });
4325}
4326
4327/* Set the AMR start-mode for this TCH back to the default configuration. */
4328private function f_vty_amr_start_mode_restore(boolean fr) runs on test_CT {
4329 f_vty_amr_start_mode_set(fr, "auto");
4330}
4331
Harald Welte60aa5762018-03-21 19:33:13 +01004332testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004333 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004334 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02004335
4336 /* Note: This setups the codec configuration. The parameter payload in
4337 * mr_conf must be consistant with the parameter codecElements in pars
4338 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004339 var RSL_IE_Body mr_conf := {
4340 other := {
4341 len := 2,
4342 payload := '2804'O
4343 }
4344 };
Harald Welte60aa5762018-03-21 19:33:13 +01004345
Philipp Maier7695a0d2018-09-27 17:52:14 +02004346 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Philipp Maier806f8f12019-03-12 12:13:41 +01004347 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02004348 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
4349 pars.expect_mr_conf_ie := mr_conf;
4350
Harald Welte60aa5762018-03-21 19:33:13 +01004351 f_init(1, true);
4352 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004353 f_vty_amr_start_mode_set(true, "1");
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004354 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004355
Harald Welte8863fa12018-05-10 20:15:27 +02004356 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004357 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004358
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004359 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4360 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4361 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4362 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4363 f_ctrs_bts_verify();
4364
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004365 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004366 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004367}
4368
4369testcase TC_assignment_codec_amr_h() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004370 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004371 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02004372
4373 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004374 var RSL_IE_Body mr_conf := {
4375 other := {
4376 len := 2,
4377 payload := '2804'O
4378 }
4379 };
Harald Welte60aa5762018-03-21 19:33:13 +01004380
Philipp Maier7695a0d2018-09-27 17:52:14 +02004381 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Philipp Maier806f8f12019-03-12 12:13:41 +01004382 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02004383 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4384 pars.expect_mr_conf_ie := mr_conf;
4385
Harald Welte60aa5762018-03-21 19:33:13 +01004386 f_init(1, true);
4387 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004388 f_vty_amr_start_mode_set(false, "1");
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004389 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004390
Harald Welte8863fa12018-05-10 20:15:27 +02004391 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004392 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004393
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004394 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4395 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4396 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4397 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4398 f_ctrs_bts_verify();
4399
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004400 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004401 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004402}
4403
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004404/* Establish signalling on a TCH/F lchan, and then switch to speech mode without a new Assignment. */
4405testcase TC_assignment_codec_fr_by_mode_modify() runs on test_CT {
4406 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4407 var MSC_ConnHdlr vc_conn;
4408
4409 f_init(1, true);
4410 f_sleep(1.0);
4411
4412 /* By disabling all SDCCH, the MS should be given a TCH/F for signalling. Then activating an FR codec should
4413 * merely do a Channel Mode Modify, and not assign to a new lchan. f_establish_fully() already accounts for
4414 * expecting a Channel Mode Modify if the channel type is compatible. */
4415 f_disable_all_sdcch();
4416 f_disable_all_tch_h();
4417
4418 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4419 pars.expect_channel_mode_modify := true;
4420 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4421 vc_conn.done;
4422
4423 f_enable_all_sdcch();
4424 f_enable_all_tch();
4425 f_shutdown_helper();
4426}
4427
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004428/* 'amr start-mode auto' should not keep the (unused) 'smod' bits from previous configuration */
4429testcase TC_assignment_codec_amr_startmode_cruft() runs on test_CT {
4430 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4431 var MSC_ConnHdlr vc_conn;
4432
4433 var RSL_IE_Body mr_conf := {
4434 other := {
4435 len := 2,
4436 payload := '2004'O /* <- expect ICMI=0, smod=00 */
4437 }
4438 };
4439
4440 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4441 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
4442 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
4443 pars.expect_mr_conf_ie := mr_conf;
4444
4445 f_init(1, true);
4446 f_sleep(1.0);
4447
4448 /* First set nonzero start mode bits */
4449 f_vty_amr_start_mode_set(true, "4");
4450 /* Now set to auto, and expect the startmode bits to be zero in the message, i.e. ensure that osmo-bsc does not
4451 * let the startmode bits stick around and has deterministic MultiRate config for 'start-mode auto'; that is
4452 * ensured by above '2004'O, where 'x0xx'O indicates ICMI = 0, spare = 0, smod = 00. */
4453 f_vty_amr_start_mode_set(true, "auto");
4454
4455 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4456 vc_conn.done;
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004457
4458 /* Clear the startmode bits to not affect subsequent tests, in case the bits should indeed stick around. */
4459 f_vty_amr_start_mode_set(true, "1");
4460 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004461 f_shutdown_helper();
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004462}
4463
Neels Hofmeyr21863562020-11-26 00:34:33 +00004464function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0,
4465 charstring start_mode := "1")
Philipp Maierd0e64b02019-03-13 14:15:23 +01004466runs on test_CT {
4467
4468 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4469 var MSC_ConnHdlr vc_conn;
4470
4471 /* See note above */
4472 var RSL_IE_Body mr_conf := {
4473 other := {
4474 len := lengthof(mrconf),
4475 payload := mrconf
4476 }
4477 };
4478
4479 if (fr) {
4480 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4481 } else {
4482 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4483 }
4484 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4485 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4486 pars.expect_mr_conf_ie := mr_conf;
4487 pars.expect_mr_s0_s7 := exp_s8_s0;
4488
4489 f_init(1, true);
4490 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004491 f_vty_amr_start_mode_set(fr, start_mode);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004492 f_sleep(1.0);
4493
4494 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4495 vc_conn.done;
4496 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004497 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004498}
4499
4500function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
4501runs on test_CT {
4502
4503 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4504 var MSC_ConnHdlr vc_conn;
4505
4506 if (fr) {
4507 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4508 } else {
4509 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4510 }
4511 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4512 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4513
4514 f_init(1, true);
4515 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004516 f_vty_amr_start_mode_set(fr, "1");
Philipp Maierd0e64b02019-03-13 14:15:23 +01004517 f_sleep(1.0);
4518
4519 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
4520 vc_conn.done;
4521 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004522 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004523}
4524
4525
4526/* Set S1, we expect an AMR multirate configuration IE with all four rates
4527 * set. */
4528testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004529 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004530 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004531}
4532
4533/* Set S1, we expect an AMR multirate configuration IE with the lower three
4534 * rates set. */
4535testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004536 f_TC_assignment_codec_amr(false, '2815208820'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004537 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004538}
4539
4540/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4541 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4542testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004543 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004544 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004545}
4546
4547/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4548 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4549testcase TC_assignment_codec_amr_h_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004550 f_TC_assignment_codec_amr(false, '2815208820'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004551 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004552}
4553
4554/* The following block of tests selects more and more rates until all four
4555 * possible rates are in the active set (full rate) */
4556testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004557 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'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_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004562 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'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_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004567 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004568 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004569}
4570
4571testcase TC_assignment_codec_amr_f_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004572 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004573 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004574}
4575
4576/* The following block of tests selects more and more rates until all three
4577 * possible rates are in the active set (half rate) */
4578testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004579 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'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_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004584 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004585 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004586}
4587
4588testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004589 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004590 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004591}
4592
4593/* The following block tests what happens when the MSC does offer rate
4594 * configurations that are not supported by the BSC. Normally such situations
4595 * should not happen because the MSC gets informed by the BSC in advance via
4596 * the L3 COMPLETE message which rates are applicable. The MSC should not try
4597 * to offer rates that are not applicable anyway. */
4598
4599testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004600 /* Try to include 12,2k in into the active set even though the channel
4601 * is half rate only. The BSC is expected to remove the 12,0k */
4602 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004603 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004604}
4605
4606testcase TC_assignment_codec_amr_f_S01234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004607 /* See what happens when all rates are selected at once. Since then
4608 * Also S1 is selected, this setting will be prefered and we should
4609 * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
4610 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004611 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004612}
4613
4614testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004615 /* Same as above, but with S1 missing, the MSC is then expected to
4616 * select the currently supported rates, which are also 12.2k, 7,40k,
4617 * 5,90k, and 4,75k, into the active set. */
4618 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004619 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004620}
4621
4622testcase TC_assignment_codec_amr_f_zero() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004623 /* Try to select no rates at all */
4624 f_TC_assignment_codec_amr_fail(true, '00000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004625 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004626}
4627
4628testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004629 /* Try to select only unsupported rates */
4630 f_TC_assignment_codec_amr_fail(true, '01101000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004631 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004632}
4633
4634testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004635 /* Try to select 12,2k for half rate */
4636 f_TC_assignment_codec_amr_fail(false, '10000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004637 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004638}
4639
Neels Hofmeyr21863562020-11-26 00:34:33 +00004640testcase TC_assignment_codec_amr_f_start_mode_auto() runs on test_CT {
4641 f_TC_assignment_codec_amr(true, '209520882208'O, '11111111'B, '00000010'B,
4642 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004643 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004644}
4645
4646testcase TC_assignment_codec_amr_h_start_mode_auto() runs on test_CT {
4647 f_TC_assignment_codec_amr(false, '2015208820'O, '10010101'B, '00010101'B,
4648 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004649 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004650}
4651
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004652testcase TC_assignment_codec_amr_f_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004653 /* "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 +00004654 f_TC_assignment_codec_amr(true, '2b9520882208'O, '11111111'B, '00000010'B,
4655 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004656 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004657}
4658
4659testcase TC_assignment_codec_amr_h_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004660 /* "amr tch-h modes 0 2 4" => total 3 modes and start mode 4 => '10'B on the wire */
4661 f_TC_assignment_codec_amr(false, '2a15208820'O, '10010101'B, '00010101'B,
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004662 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004663 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004664}
4665
Philipp Maierac09bfc2019-01-08 13:41:39 +01004666private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004667 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
4668 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
4669 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
4670 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004671}
4672
4673private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004674 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
4675 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004676}
4677
4678private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004679 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
4680 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
4681 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
4682 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
4683 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
4684 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004685}
4686
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004687private function f_disable_all_sdcch() runs on test_CT {
4688 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 borken");
4689 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 borken");
4690 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 borken");
4691 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 borken");
4692}
4693
4694private function f_enable_all_sdcch() runs on test_CT {
4695 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 unused");
4696 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 unused");
4697 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 unused");
4698 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 unused");
4699}
4700
Philipp Maierac09bfc2019-01-08 13:41:39 +01004701/* Allow HR only */
4702private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
4703 g_pars := f_gen_test_hdlr_pars();
4704 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4705 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4706 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4707 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4708 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4709 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4710 f_establish_fully(ass_cmd, exp_compl);
4711}
4712
4713/* Allow FR only */
4714private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
4715 g_pars := f_gen_test_hdlr_pars();
4716 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4717 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4718 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4719 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4720 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4721 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4722 f_establish_fully(ass_cmd, exp_compl);
4723}
4724
4725/* Allow HR only (expect assignment failure) */
4726private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
4727 g_pars := f_gen_test_hdlr_pars();
4728 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4729 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4730 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4731 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4732 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4733 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4734 f_establish_fully(ass_cmd, exp_fail);
4735}
4736
4737/* Allow FR only (expect assignment failure) */
4738private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(charstring id) runs on MSC_ConnHdlr {
4739 g_pars := f_gen_test_hdlr_pars();
4740 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4741 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4742 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4743 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4744 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4745 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4746 f_establish_fully(ass_cmd, exp_fail);
4747}
4748
4749/* Allow FR and HR, but prefer FR */
4750private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4751 g_pars := f_gen_test_hdlr_pars();
4752 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4753 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4754 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4755 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4756 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4757 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4758 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4759 f_establish_fully(ass_cmd, exp_compl);
4760}
4761
4762/* Allow FR and HR, but prefer HR */
4763private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4764 g_pars := f_gen_test_hdlr_pars();
4765 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4766 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4767 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4768 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4769 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4770 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4771 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4772 f_establish_fully(ass_cmd, exp_compl);
4773}
4774
4775/* Allow FR and HR, but prefer FR */
4776private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4777 g_pars := f_gen_test_hdlr_pars();
4778 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4779 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4780 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4781 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4782 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4783 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4784 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4785 f_establish_fully(ass_cmd, exp_compl);
4786}
4787
4788/* Allow FR and HR, but prefer HR */
4789private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4790 g_pars := f_gen_test_hdlr_pars();
4791 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4792 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4793 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4794 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4795 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4796 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4797 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4798 f_establish_fully(ass_cmd, exp_compl);
4799}
4800
4801/* Request a HR channel while all FR channels are exhausted, this is expected
4802 * to work without conflicts */
4803testcase TC_assignment_codec_fr_exhausted_req_hr() runs on test_CT {
4804 var MSC_ConnHdlr vc_conn;
4805 f_init(1, true);
4806 f_sleep(1.0);
4807 f_enable_all_tch();
4808 f_disable_all_tch_f();
4809 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr));
4810 vc_conn.done;
4811 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004812 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004813}
4814
4815/* Request a FR channel while all FR channels are exhausted, this is expected
4816 * to fail. */
4817testcase TC_assignment_codec_fr_exhausted_req_fr() runs on test_CT {
4818 var MSC_ConnHdlr vc_conn;
4819 f_init(1, true);
4820 f_sleep(1.0);
4821 f_enable_all_tch();
4822 f_disable_all_tch_f();
4823 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr_fail));
4824 vc_conn.done;
4825 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004826 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004827}
4828
4829/* Request a FR (prefered) or alternatively a HR channel while all FR channels
4830 * are exhausted, this is expected to be resolved by selecting a HR channel. */
4831testcase TC_assignment_codec_fr_exhausted_req_fr_hr() runs on test_CT {
4832 var MSC_ConnHdlr vc_conn;
4833 f_init(1, true);
4834 f_sleep(1.0);
4835 f_enable_all_tch();
4836 f_disable_all_tch_f();
4837 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
4838 vc_conn.done;
4839 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004840 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004841}
4842
4843/* Request a HR (prefered) or alternatively a FR channel while all FR channels
4844 * are exhausted, this is expected to work without conflicts. */
4845testcase TC_assignment_codec_fr_exhausted_req_hr_fr() runs on test_CT {
4846 var MSC_ConnHdlr vc_conn;
4847 f_init(1, true);
4848 f_sleep(1.0);
4849 f_enable_all_tch();
4850 f_disable_all_tch_f();
4851 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_hr_fr));
4852 vc_conn.done;
4853 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004854 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004855}
4856
4857/* Request a FR channel while all HR channels are exhausted, this is expected
4858 * to work without conflicts */
4859testcase TC_assignment_codec_hr_exhausted_req_fr() runs on test_CT {
4860 var MSC_ConnHdlr vc_conn;
4861 f_init(1, true);
4862 f_sleep(1.0);
4863 f_enable_all_tch();
4864 f_disable_all_tch_h();
4865 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr));
4866 vc_conn.done;
4867 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004868 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004869}
4870
4871/* Request a HR channel while all HR channels are exhausted, this is expected
4872 * to fail. */
4873testcase TC_assignment_codec_hr_exhausted_req_hr() runs on test_CT {
4874 var MSC_ConnHdlr vc_conn;
4875 f_init(1, true);
4876 f_sleep(1.0);
4877 f_enable_all_tch();
4878 f_disable_all_tch_h();
4879 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr_fail));
4880 vc_conn.done;
4881 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004882 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004883}
4884
4885/* Request a HR (prefered) or alternatively a FR channel while all HR channels
4886 * are exhausted, this is expected to be resolved by selecting a FR channel. */
4887testcase TC_assignment_codec_hr_exhausted_req_hr_fr() runs on test_CT {
4888 var MSC_ConnHdlr vc_conn;
4889 f_init(1, true);
4890 f_sleep(1.0);
4891 f_enable_all_tch();
4892 f_disable_all_tch_h();
4893 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_hr_fr));
4894 vc_conn.done;
4895 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004896 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004897}
4898
4899/* Request a FR (prefered) or alternatively a HR channel while all HR channels
4900 * are exhausted, this is expected to work without conflicts. */
4901testcase TC_assignment_codec_hr_exhausted_req_fr_hr() runs on test_CT {
4902 var MSC_ConnHdlr vc_conn;
4903 f_init(1, true);
4904 f_sleep(1.0);
4905 f_enable_all_tch();
4906 f_disable_all_tch_h();
4907 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_fr_hr));
4908 vc_conn.done;
4909 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004910 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004911}
4912
4913/* Allow FR and HR, but prefer HR */
4914private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4915 g_pars := f_gen_test_hdlr_pars();
4916 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4917 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4918 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4919 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4920 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4921 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4922 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4923 f_establish_fully(ass_cmd, exp_compl);
4924}
4925
4926/* Allow FR and HR, but prefer FR */
4927private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4928 g_pars := f_gen_test_hdlr_pars();
4929 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4930 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4931 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4932 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4933 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4934 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4935 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4936 f_establish_fully(ass_cmd, exp_compl);
4937}
4938
4939/* Request a HR (prefered) or alternatively a FR channel, it is expected that
4940 * HR, which is the prefered type, is selected. */
4941testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
4942 var MSC_ConnHdlr vc_conn;
4943 f_init(1, true);
4944 f_sleep(1.0);
4945 f_enable_all_tch();
4946 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
4947 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004948 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004949}
4950
4951/* Request a FR (prefered) or alternatively a HR channel, it is expected that
4952 * FR, which is the prefered type, is selected. */
4953testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
4954 var MSC_ConnHdlr vc_conn;
4955 f_init(1, true);
4956 f_sleep(1.0);
4957 f_enable_all_tch();
4958 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
4959 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004960 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004961}
4962
Pau Espin Pedrol14475352021-07-22 15:48:16 +02004963/* request a signalling channel with all SDCCH exhausted, it is expected that a TCH will be selected */
4964private function f_TC_assignment_sdcch_exhausted_req_signalling(charstring id) runs on MSC_ConnHdlr {
4965 g_pars := f_gen_test_hdlr_pars();
4966 g_pars.ra := '02'O; /* RA containing reason=LU */
4967
4968 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
4969 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
4970 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
4971 var template uint3_t tsc := ?;
4972
4973 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
4974 f_create_bssmap_exp(l3_enc);
4975 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
4976 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, tsc);
4977
4978 /* we should now have a COMPL_L3 at the MSC */
4979 timer T := 10.0;
4980 T.start;
4981 alt {
4982 [] BSSAP.receive(tr_BSSMAP_ComplL3);
4983 [] T.timeout {
4984 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
4985 }
4986 }
4987}
4988testcase TC_assignment_sdcch_exhausted_req_signalling() runs on test_CT {
4989 var MSC_ConnHdlr vc_conn;
4990 f_init(1, true);
4991 f_sleep(1.0);
4992 f_disable_all_sdcch();
4993 vc_conn := f_start_handler(refers(f_TC_assignment_sdcch_exhausted_req_signalling));
4994 vc_conn.done;
4995 f_enable_all_sdcch();
4996 f_shutdown_helper();
4997}
4998
4999/* Request a signalling channel with all SDCCH exhausted, it is
5000 expected that no TCH will be selected for signalling and assigment will fail
5001 because it's dictated by VTY config */
5002testcase TC_assignment_sdcch_exhausted_req_signalling_tch_forbidden() runs on test_CT {
5003 var RSL_Message rsl_unused, rsl_msg;
5004 var GsmRrMessage rr;
5005 f_init(1, false);
5006 f_sleep(1.0);
5007 f_vty_allow_tch_for_signalling(false, 0);
5008 f_disable_all_sdcch();
5009
5010 /* RA containing reason=LU */
5011 f_ipa_tx(0, ts_RSL_CHAN_RQD('02'O, 2342));
5012 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
5013 rr := dec_GsmRrMessage(rsl_msg.ies[1].body.full_imm_ass_info.payload);
5014 if (rr.header.message_type != IMMEDIATE_ASSIGNMENT_REJECT) {
5015 setverdict(fail, "Expected reject");
5016 }
5017
5018 f_vty_allow_tch_for_signalling(true, 0);
5019 f_enable_all_sdcch();
5020 f_shutdown_helper();
5021}
5022
5023/* Request a voice channel with all SDCCH exhausted, it is
5024 * expected that TCH channel will be allocated since the VTY option is only
5025 * aimed at signalling requests */
5026private function f_TC_assignment_sdcch_exhausted_req_voice_tch_forbidden(charstring id) runs on MSC_ConnHdlr {
5027 g_pars := f_gen_test_hdlr_pars();
5028 g_pars.ra := '43'O; /* RA containing reason=originating speech call*/
5029
5030 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
5031 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
5032 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
5033 var template uint3_t tsc := ?;
5034
5035 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
5036 f_create_bssmap_exp(l3_enc);
5037 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
5038 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, tsc);
5039
5040 /* we should now have a COMPL_L3 at the MSC */
5041 timer T := 10.0;
5042 T.start;
5043 alt {
5044 [] BSSAP.receive(tr_BSSMAP_ComplL3);
5045 [] T.timeout {
5046 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
5047 }
5048 }
5049}
5050testcase TC_assignment_sdcch_exhausted_req_voice_tch_forbidden() runs on test_CT {
5051 var MSC_ConnHdlr vc_conn;
5052 f_init(1, true);
5053 f_sleep(1.0);
5054 f_vty_allow_tch_for_signalling(false, 0);
5055 f_disable_all_sdcch();
5056
5057 vc_conn := f_start_handler(refers(f_TC_assignment_sdcch_exhausted_req_voice_tch_forbidden));
5058 vc_conn.done;
5059
5060 f_vty_allow_tch_for_signalling(true, 0);
5061 f_enable_all_sdcch();
5062 f_shutdown_helper();
5063}
5064
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005065testcase TC_assignment_osmux() runs on test_CT {
5066 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5067 var MSC_ConnHdlr vc_conn;
5068
5069 /* See note above */
5070 var RSL_IE_Body mr_conf := {
5071 other := {
5072 len := 2,
5073 payload := '2804'O
5074 }
5075 };
5076
5077 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
5078 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
5079 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
5080 pars.expect_mr_conf_ie := mr_conf;
5081 pars.use_osmux := true;
5082
5083 f_init(1, true, true);
5084 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00005085 f_vty_amr_start_mode_set(false, "1");
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005086
5087 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
5088 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00005089
5090 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01005091 f_shutdown_helper();
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005092}
5093
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02005094/* test the procedure of the MSC requesting a Classmark Update:
5095 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
5096 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01005097private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005098 g_pars := f_gen_test_hdlr_pars();
5099
Harald Weltea0630032018-03-20 21:09:55 +01005100 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01005101 /* we should now have a COMPL_L3 at the MSC */
Harald Welte898113b2018-01-31 18:32:21 +01005102
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02005103 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
5104 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
5105
Harald Welte898113b2018-01-31 18:32:21 +01005106 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
5107 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
5108 setverdict(pass);
5109}
5110testcase TC_classmark() runs on test_CT {
5111 var MSC_ConnHdlr vc_conn;
5112 f_init(1, true);
5113 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005114 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01005115 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005116 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01005117}
5118
Harald Welteeddf0e92020-06-21 19:42:15 +02005119/* Send a CommonID from the simulated MSC and verify that the information is used to
5120 * fill BSC-internal data structures (specifically, bsc_subscr associated with subscr_conn) */
5121private function f_tc_common_id(charstring id) runs on MSC_ConnHdlr {
5122 g_pars := f_gen_test_hdlr_pars();
5123 f_MscConnHdlr_init_vty();
5124
5125 f_create_chan_and_exp();
5126 /* we should now have a COMPL_L3 at the MSC */
Harald Welteeddf0e92020-06-21 19:42:15 +02005127
5128 /* Send CommonID */
5129 BSSAP.send(ts_BSSMAP_CommonId(g_pars.imsi));
5130
5131 /* Use VTY to verify that the IMSI of the subscr_conn is set */
5132 var charstring regex := "*(IMSI: " & hex2str(g_pars.imsi) & ")*";
5133 f_vty_transceive_match_regexp_retry(BSCVTY, "show conns", regex, 0, 4, 1.0);
5134
5135 setverdict(pass);
5136}
5137testcase TC_common_id() runs on test_CT {
5138 var MSC_ConnHdlr vc_conn;
5139 f_init(1, true);
5140 f_sleep(1.0);
5141 vc_conn := f_start_handler(refers(f_tc_common_id));
5142 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005143 f_shutdown_helper();
Harald Welteeddf0e92020-06-21 19:42:15 +02005144}
5145
Harald Weltee3bd6582018-01-31 22:51:25 +01005146private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005147 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01005148 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01005149 /* we should now have a COMPL_L3 at the MSC */
Harald Welte898113b2018-01-31 18:32:21 +01005150
Harald Weltee3bd6582018-01-31 22:51:25 +01005151 /* send the single message we want to send */
5152 f_rsl_send_l3(l3);
5153}
5154
5155private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
5156 timer T := sec;
5157 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01005158 T.start;
5159 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01005160 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
5161 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02005162 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01005163 }
5164 [] T.timeout {
5165 setverdict(pass);
5166 }
5167 }
5168}
5169
Harald Weltee3bd6582018-01-31 22:51:25 +01005170/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
5171private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
5172 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
5173 f_bssap_expect_nothing();
5174}
Harald Welte898113b2018-01-31 18:32:21 +01005175testcase TC_unsol_ass_fail() runs on test_CT {
5176 var MSC_ConnHdlr vc_conn;
5177 f_init(1, true);
5178 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005179 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01005180 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005181 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01005182}
Harald Welte552620d2017-12-16 23:21:36 +01005183
Harald Welteea99a002018-01-31 20:46:43 +01005184
5185/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
5186private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01005187 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
5188 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01005189}
5190testcase TC_unsol_ass_compl() runs on test_CT {
5191 var MSC_ConnHdlr vc_conn;
5192 f_init(1, true);
5193 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005194 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01005195 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005196 f_shutdown_helper();
Harald Welteea99a002018-01-31 20:46:43 +01005197}
5198
5199
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005200/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
5201private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01005202 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
5203 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005204}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005205testcase TC_unsol_ho_fail() runs on test_CT {
5206 var MSC_ConnHdlr vc_conn;
5207 f_init(1, true);
5208 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005209 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005210 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005211 f_shutdown_helper();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005212}
5213
5214
Harald Weltee3bd6582018-01-31 22:51:25 +01005215/* short message from MS should be ignored */
5216private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005217 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01005218 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01005219 /* we should now have a COMPL_L3 at the MSC */
Harald Weltee3bd6582018-01-31 22:51:25 +01005220
5221 /* send short message */
5222 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
5223 f_bssap_expect_nothing();
5224}
5225testcase TC_err_82_short_msg() runs on test_CT {
5226 var MSC_ConnHdlr vc_conn;
5227 f_init(1, true);
5228 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005229 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01005230 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005231 f_shutdown_helper();
Harald Weltee3bd6582018-01-31 22:51:25 +01005232}
5233
5234
Harald Weltee9e02e42018-01-31 23:36:25 +01005235/* 24.008 8.4 Unknown message must trigger RR STATUS */
5236private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
5237 f_est_single_l3(ts_RRM_UL_REL('00'O));
5238 timer T := 3.0
5239 alt {
5240 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
5241 setverdict(pass);
5242 }
5243 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01005244 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01005245 }
5246}
5247testcase TC_err_84_unknown_msg() runs on test_CT {
5248 var MSC_ConnHdlr vc_conn;
5249 f_init(1, true);
5250 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005251 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01005252 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005253 f_shutdown_helper();
Harald Weltee9e02e42018-01-31 23:36:25 +01005254}
5255
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005256/***********************************************************************
5257 * Handover
5258 ***********************************************************************/
5259
Harald Welte94e0c342018-04-07 11:33:23 +02005260/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
5261private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
5262runs on test_CT {
5263 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
5264 " timeslot "&int2str(ts_nr)&" ";
5265 f_vty_transceive(BSCVTY, cmd & suffix);
5266}
5267
Harald Welte261af4b2018-02-12 21:20:39 +01005268/* 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 +07005269private function f_vty_ss_action(TELNETasp_PT pt, charstring suffix,
5270 uint8_t bts_nr, uint8_t trx_nr,
5271 in RslChannelNr chan_nr)
5272{
Harald Welte261af4b2018-02-12 21:20:39 +01005273 /* FIXME: resolve those from component-global state */
5274 var integer ts_nr := chan_nr.tn;
5275 var integer ss_nr;
5276 if (ischosen(chan_nr.u.ch0)) {
5277 ss_nr := 0;
5278 } else if (ischosen(chan_nr.u.lm)) {
5279 ss_nr := chan_nr.u.lm.sub_chan;
5280 } else if (ischosen(chan_nr.u.sdcch4)) {
5281 ss_nr := chan_nr.u.sdcch4.sub_chan;
5282 } else if (ischosen(chan_nr.u.sdcch8)) {
5283 ss_nr := chan_nr.u.sdcch8.sub_chan;
5284 } else {
5285 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02005286 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01005287 }
5288
5289 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
5290 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005291 f_vty_transceive(pt, cmd & suffix);
Harald Welte261af4b2018-02-12 21:20:39 +01005292}
5293
Neels Hofmeyr91401012019-07-11 00:42:35 +02005294/* Even though the VTY command to trigger handover takes a new BTS number as argument, behind the scenes osmo-bsc always
5295 * translates that to a target ARFCN+BSIC first. See bsc_vty.c trigger_ho_or_as(), which puts the selected BTS' neighbor
5296 * ident key (ARFCN + BSIC) in the struct passed on to handover_request(). handover_start() then resolves that to a
5297 * viable actual neighbor cell. So from the internal osmo-bsc perspective, we always request handover to an ARFCN + BSIC
5298 * pair, not really to a specific BTS number. */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005299private function f_vty_handover(TELNETasp_PT pt, uint8_t bts_nr, uint8_t trx_nr,
5300 in RslChannelNr chan_nr, uint8_t new_bts_nr)
5301{
5302 f_vty_ss_action(pt, "handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
Harald Welte261af4b2018-02-12 21:20:39 +01005303}
5304
5305/* intra-BSC hand-over between BTS0 and BTS1 */
5306private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02005307 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5308 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01005309
5310 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5311 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5312
Harald Weltea0630032018-03-20 21:09:55 +01005313 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005314 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Harald Welte261af4b2018-02-12 21:20:39 +01005315
5316 var HandoverState hs := {
5317 rr_ho_cmpl_seen := false,
5318 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02005319 old_chan_nr := -,
5320 expect_target_tsc := BTS_TSC[1]
Harald Welte261af4b2018-02-12 21:20:39 +01005321 };
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005322 /* issue hand-over command on VTY, from BTS 0 to BTS 1 */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005323 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
Harald Welte261af4b2018-02-12 21:20:39 +01005324 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
5325 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005326
5327 /* From the MGW perspective, a handover is is characterized by
5328 * performing one MDCX operation with the MGW. So we expect to see
5329 * one more MDCX during handover. */
5330 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
5331
Harald Welte261af4b2018-02-12 21:20:39 +01005332 alt {
5333 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01005334 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005335
Philipp Maier4dae0652018-11-12 12:03:26 +01005336 /* Since this is an internal handover we expect the BSC to inform the
5337 * MSC about the event */
5338 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
5339
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005340 /* Check the amount of MGCP transactions is still consistant with the
5341 * test expectation */
5342 f_check_mgcp_expectations()
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005343
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005344 var RSL_Message chan_act := f_rslem_get_last_act(RSL1_PROC, 0, g_chan_nr);
5345
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005346 /* Ensure the Channel Activation for the new channel contained the right encryption params. as_handover() set
5347 * 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 +02005348 f_verify_encr_info(chan_act);
5349
5350 f_chan_act_verify_tsc(chan_act, BTS_TSC[1]);
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005351
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01005352 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01005353}
5354
5355testcase TC_ho_int() runs on test_CT {
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02005356 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte261af4b2018-02-12 21:20:39 +01005357 var MSC_ConnHdlr vc_conn;
5358 f_init(2, true);
5359 f_sleep(1.0);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005360
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005361 pars.expect_tsc := BTS_TSC[0];
5362
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005363 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005364
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02005365 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
Harald Welte261af4b2018-02-12 21:20:39 +01005366 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005367
5368 /* from f_establish_fully() */
5369 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5370 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5371 /* from handover */
5372 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5373 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5374 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5375 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005376 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5377 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:completed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005378 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005379 f_shutdown_helper();
Harald Welte261af4b2018-02-12 21:20:39 +01005380}
Harald Weltee9e02e42018-01-31 23:36:25 +01005381
Oliver Smith7eabd312021-07-12 14:18:56 +02005382function 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 +02005383 var MSC_ConnHdlr vc_conn;
5384 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5385 pars.encr := valueof(t_EncrParams(encr_alg, f_rnd_octstring(8), f_rnd_octstring(16)));
5386
5387 f_init(2, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02005388 f_vty_encryption_a5(enc_a5);
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005389 f_sleep(1.0);
5390
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005391 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005392
5393 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
5394 vc_conn.done;
5395
5396 /* from f_establish_fully() */
5397 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5398 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5399 /* from handover */
5400 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5401 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5402 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5403 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005404 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5405 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:completed");
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005406 f_ctrs_bsc_and_bts_verify();
Oliver Smith7eabd312021-07-12 14:18:56 +02005407 f_vty_encryption_a5_reset();
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005408 f_shutdown_helper();
5409}
5410
5411testcase TC_ho_int_a5_0() runs on test_CT {
5412 f_tc_ho_int_a5('01'O);
5413}
5414
5415testcase TC_ho_int_a5_1() runs on test_CT {
5416 f_tc_ho_int_a5('02'O);
5417}
5418
5419testcase TC_ho_int_a5_3() runs on test_CT {
5420 f_tc_ho_int_a5('08'O);
5421}
5422
5423testcase TC_ho_int_a5_4() runs on test_CT {
Oliver Smith7eabd312021-07-12 14:18:56 +02005424 f_tc_ho_int_a5('10'O, "0 1 3 4");
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005425}
5426
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005427/* intra-BSC hand-over with CONNection FAILure and cause Radio Link Failure: check RR release cause */
5428private function f_tc_ho_int_radio_link_failure(charstring id) runs on MSC_ConnHdlr {
5429 g_pars := f_gen_test_hdlr_pars();
5430 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5431 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005432
5433 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5434 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5435
5436 f_establish_fully(ass_cmd, exp_compl);
5437 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
5438
5439 var HandoverState hs := {
5440 rr_ho_cmpl_seen := false,
5441 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02005442 old_chan_nr := -,
5443 expect_target_tsc := BTS_TSC[1]
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005444 };
5445 /* issue hand-over command on VTY */
5446 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
5447 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
5448 f_rslem_suspend(RSL1_PROC);
5449
5450 /* From the MGW perspective, a handover is is characterized by
5451 * performing one MDCX operation with the MGW. So we expect to see
5452 * one more MDCX during handover. */
5453 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
5454
5455 var RSL_Message rsl;
5456 var PDU_ML3_NW_MS l3;
5457 var RslChannelNr new_chan_nr;
5458 var GsmArfcn arfcn;
5459 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
5460 l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
5461 if (not ischosen(l3.msgs.rrm.handoverCommand)) {
5462 setverdict(fail, "Expected handoverCommand");
5463 mtc.stop;
5464 }
5465 }
5466 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
5467 new_chan_nr, arfcn);
5468
5469 f_rslem_register(0, new_chan_nr, RSL1_PROC);
5470
5471 /* resume processing of RSL DChan messages, which was temporarily suspended
5472 * before performing a hand-over */
5473 f_rslem_resume(RSL1_PROC);
5474 RSL1.receive(tr_RSL_IPA_CRCX(new_chan_nr));
5475
5476 f_sleep(1.0);
5477
5478 /* Handover fails because no HANDO DET appears on the new lchan,
5479 * and the old lchan reports a Radio Link Failure. */
5480 RSL.send(ts_RSL_CONN_FAIL_IND(g_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
5481
5482 var PDU_BSSAP rx_clear_request;
5483 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
5484 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5485 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5486
5487 var RR_Cause rr_cause := GSM48_RR_CAUSE_ABNORMAL_UNSPEC;
5488
5489 var MgcpCommand mgcp;
5490 interleave {
5491 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE(int2oct(enum2int(rr_cause), 1)))) {}
5492 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005493 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005494 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005495 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005496 }
5497 [] RSL1.receive(tr_RSL_DEACT_SACCH(new_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005498 [] RSL1.receive(tr_RSL_RF_CHAN_REL(new_chan_nr)) {
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005499 RSL1.send(ts_RSL_RF_CHAN_REL_ACK(new_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005500 f_rslem_unregister(0, g_chan_nr, PT := RSL1_PROC);
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005501 }
5502 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {}
5503 }
5504
5505 f_sleep(0.5);
5506 setverdict(pass);
5507}
5508testcase TC_ho_int_radio_link_failure() runs on test_CT {
5509 var MSC_ConnHdlr vc_conn;
5510 f_init(2, true);
5511 f_sleep(1.0);
5512
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005513 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005514
5515 vc_conn := f_start_handler(refers(f_tc_ho_int_radio_link_failure));
5516 vc_conn.done;
5517
5518 /* from f_establish_fully() */
5519 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5520 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5521 /* from handover */
5522 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5523 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
5524 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5525 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:stopped");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005526 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5527 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:stopped");
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005528 f_ctrs_bsc_and_bts_verify();
5529 f_shutdown_helper();
5530}
5531
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005532/* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005533private function f_expect_dlcx_conns() runs on MSC_ConnHdlr {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005534 var MgcpCommand mgcp;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005535 var template MgcpResponse mgcp_resp;
5536 var MGCP_RecvFrom mrf;
5537 var template MgcpMessage msg_resp;
5538 var template MgcpMessage msg_dlcx := {
5539 command := tr_DLCX()
5540 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005541
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005542 if (g_pars.aoip) {
5543 MGCP.receive(tr_DLCX()) -> value mgcp {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005544 log("Got first DLCX: ", mgcp);
5545 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005546 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005547
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005548 MGCP.receive(tr_DLCX()) -> value mgcp {
5549 log("Got second DLCX: ", mgcp);
5550 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
5551 };
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005552 } else {
5553 /* For SCCPLite, BSC doesn't handle the MSC-side */
5554 MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_dlcx)) -> value mrf {
5555 log("Got first DLCX: ", mrf.msg.command);
5556 msg_resp := {
5557 response := ts_DLCX_ACK2(mrf.msg.command.line.trans_id)
5558 }
5559 MGCP_MULTI.send(t_MGCP_SendToMrf(mrf, msg_resp));
5560 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005561 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005562}
5563
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005564private 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 +01005565
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005566 var NcellReports neighbor_rep := {
5567 { rxlev := 20, bcch_freq := 0, bsic := 11 }
5568 };
5569 var octetstring l3_mr := enc_GsmRrL3Message(valueof(ts_MEAS_REP(true, 8, 8, reps := neighbor_rep)));
5570 RSL.send(ts_RSL_MEAS_RES(g_chan_nr, 0, ts_RSL_IE_UplinkMeas, ts_RSL_IE_BS_Power(0), ts_RSL_IE_L1Info,
5571 l3_mr, 0));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005572
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005573 BSSAP.receive(tr_BSSMAP_HandoverRequired(exp_oldToNewBSSIEs));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005574
5575 f_sleep(0.5);
5576 /* The MSC negotiates Handover Request and Handover Request Ack with
5577 * the other BSS and comes back with a BSSMAP Handover Command
5578 * containing an RR Handover Command coming from the target BSS... */
5579
5580 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5581 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5582 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5583 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5584 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5585
5586 /* expect the Handover Command to go out on RR */
5587 var RSL_Message rsl_ho_cmd
5588 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5589 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5590 var RSL_IE_Body rsl_ho_cmd_l3;
5591 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5592 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5593 setverdict(fail);
5594 } else {
5595 log("Found L3 Info: ", rsl_ho_cmd_l3);
5596 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5597 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5598 setverdict(fail);
5599 } else {
5600 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5601 setverdict(pass);
5602 }
5603 }
5604
5605 /* When the other BSS has reported a completed handover, this side is
5606 * torn down. */
5607
5608 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
5609 var BssmapCause cause := enum2int(cause_val);
5610 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5611
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005612 f_expect_dlcx_conns();
Pau Espin Pedrol06199952021-06-15 11:30:00 +02005613
5614 interleave {
5615 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE));
5616 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr));
5617 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr));
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02005618 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
Pau Espin Pedrol06199952021-06-15 11:30:00 +02005619 }
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005620 setverdict(pass);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005621}
5622
5623private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
5624 g_pars := f_gen_test_hdlr_pars();
5625 var PDU_BSSAP ass_req := f_gen_ass_req();
5626 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5627 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5628 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5629 f_establish_fully(ass_req, exp_compl);
5630
5631 f_ho_out_of_this_bsc();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005632}
5633testcase TC_ho_out_of_this_bsc() runs on test_CT {
5634 var MSC_ConnHdlr vc_conn;
5635
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005636 f_init_vty();
5637 f_bts_0_cfg(BSCVTY,
5638 {"neighbor-list mode automatic",
5639 "handover 1",
5640 "handover algorithm 2",
5641 "handover2 window rxlev averaging 1",
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005642 "no neighbors",
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005643 "neighbor lac 99 arfcn 123 bsic any"});
5644 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5645
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005646 f_init(1, true);
5647 f_sleep(1.0);
5648
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005649 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005650
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005651 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
5652 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005653
5654 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5655 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5656 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5657 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5658 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5659 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed");
5660 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005661 f_shutdown_helper();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005662}
5663
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005664private function f_mo_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5665 template (value) RslLinkId link_id := ts_RslLinkID_DCCH(0),
Vadim Yanitskiy2ef6a2f2020-10-08 23:17:32 +07005666 template (present) OCT1 dlci := ?,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005667 octetstring l3 := '0123456789'O)
5668runs on MSC_ConnHdlr {
Neels Hofmeyr43654812020-09-25 01:35:35 +02005669 /* The old lchan and conn should still be active. See that arbitrary L3
5670 * is still going through. */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005671 rsl.send(ts_RSL_DATA_IND(g_chan_nr, link_id, l3));
Neels Hofmeyr43654812020-09-25 01:35:35 +02005672 var template PDU_BSSAP exp_data := {
5673 discriminator := '1'B,
5674 spare := '0000000'B,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005675 dlci := dlci,
5676 lengthIndicator := lengthof(l3),
Neels Hofmeyr43654812020-09-25 01:35:35 +02005677 pdu := {
5678 dtap := l3
5679 }
5680 };
5681 BSSAP.receive(exp_data);
5682 setverdict(pass);
5683}
5684
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005685private function f_mt_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5686 template (present) RslLinkId link_id := tr_RslLinkID_DCCH(0),
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005687 template (value) OCT1 dlci := '00'O,
5688 octetstring l3 := '0123456789'O)
5689runs on MSC_ConnHdlr {
5690 BSSAP.send(PDU_BSSAP:{
5691 discriminator := '1'B,
5692 spare := '0000000'B,
5693 dlci := dlci,
5694 lengthIndicator := lengthof(l3),
5695 pdu := {
5696 dtap := l3
5697 }
5698 });
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005699 rsl.receive(tr_RSL_DATA_REQ(g_chan_nr, link_id, l3));
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005700 setverdict(pass);
5701}
5702
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005703/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
5704 * simply never sends a BSSMAP Handover Command. */
5705private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005706 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005707
5708 var PDU_BSSAP ass_req := f_gen_ass_req();
5709 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5710 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5711 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5712 f_establish_fully(ass_req, exp_compl);
5713
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005714 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005715 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5716
5717 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5718
5719 /* osmo-bsc should time out 10 seconds after the handover started.
5720 * Let's give it a bit extra. */
5721 f_sleep(15.0);
5722
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005723 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005724 f_sleep(1.0);
5725}
5726testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
5727 var MSC_ConnHdlr vc_conn;
5728
5729 f_init(1, true);
5730 f_sleep(1.0);
5731
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005732 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005733
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005734 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
5735 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005736
5737 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5738 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5739 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5740 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5741 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5742 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5743 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005744 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005745}
5746
5747/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
5748 * RR Handover Failure. */
5749private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005750 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005751
5752 var PDU_BSSAP ass_req := f_gen_ass_req();
5753 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5754 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5755 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5756 f_establish_fully(ass_req, exp_compl);
5757
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005758 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005759 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5760
5761 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5762
5763 f_sleep(0.5);
5764 /* The MSC negotiates Handover Request and Handover Request Ack with
5765 * the other BSS and comes back with a BSSMAP Handover Command
5766 * containing an RR Handover Command coming from the target BSS... */
5767
5768 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5769 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5770 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5771 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5772 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5773
5774 /* expect the Handover Command to go out on RR */
5775 var RSL_Message rsl_ho_cmd
5776 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5777 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5778 var RSL_IE_Body rsl_ho_cmd_l3;
5779 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5780 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5781 setverdict(fail);
5782 } else {
5783 log("Found L3 Info: ", rsl_ho_cmd_l3);
5784 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5785 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5786 setverdict(fail);
5787 } else {
5788 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5789 setverdict(pass);
5790 }
5791 }
5792
5793 f_sleep(0.2);
5794 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
5795
5796 /* Should tell the MSC about the failure */
5797 BSSAP.receive(tr_BSSMAP_HandoverFailure);
5798
5799 f_sleep(1.0);
5800
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005801 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005802 f_sleep(1.0);
5803
5804 setverdict(pass);
5805 f_sleep(1.0);
5806}
5807testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
5808 var MSC_ConnHdlr vc_conn;
5809
5810 f_init(1, true);
5811 f_sleep(1.0);
5812
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005813 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005814
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005815 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
5816 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005817
5818 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5819 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5820 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5821 f_ctrs_bsc_and_bts_add(0, "handover:failed");
5822 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5823 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:failed");
5824 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005825 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005826}
5827
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005828/* BSC asks for inter-BSC-out HO, receives BSSMAP Handover Command, but then no reply is received about HO outcome
5829 * (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 +02005830 * and the lchan is released. */
5831private function f_tc_ho_out_fail_no_result_after_ho_cmd(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005832 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005833
5834 var PDU_BSSAP ass_req := f_gen_ass_req();
5835 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5836 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5837 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5838 f_establish_fully(ass_req, exp_compl);
5839
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005840 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005841 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5842
5843 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5844
5845 f_sleep(0.5);
5846 /* The MSC negotiates Handover Request and Handover Request Ack with
5847 * the other BSS and comes back with a BSSMAP Handover Command
5848 * containing an RR Handover Command coming from the target BSS... */
5849
5850 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5851 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5852 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5853 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5854 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5855
5856 /* expect the Handover Command to go out on RR */
5857 var RSL_Message rsl_ho_cmd
5858 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5859 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5860 var RSL_IE_Body rsl_ho_cmd_l3;
5861 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5862 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5863 setverdict(fail);
5864 } else {
5865 log("Found L3 Info: ", rsl_ho_cmd_l3);
5866 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5867 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5868 setverdict(fail);
5869 } else {
5870 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5871 setverdict(pass);
5872 }
5873 }
5874
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005875 /* We get neither success nor failure report from the remote BSS. Eventually T8 times out and we run into 3GPP
5876 * TS 48.008 3.1.5.3.3 "Abnormal Conditions": Clear Request should go to the MSC, and RR should be released
5877 * after Clear Command */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005878
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005879 var PDU_BSSAP rx_clear_request;
Neels Hofmeyre1797aa2019-07-09 19:34:04 +02005880 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
5881 log("Got BSSMAP Clear Request");
5882 /* Instruct BSC to clear channel */
5883 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5884 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5885
5886 var MgcpCommand mgcp;
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005887 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01005888 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
5889 log("Got Deact SACCH");
5890 }
Harald Welte924b6ea2019-02-04 01:05:34 +01005891 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01005892 log("Got RR Release");
5893 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005894 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005895 log("Got RF Chan Rel");
5896 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005897 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005898 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005899 }
5900
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005901 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02005902 BSSAP.receive(tr_BSSMAP_ClearComplete);
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005903
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005904 setverdict(pass);
5905 f_sleep(1.0);
5906}
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02005907testcase TC_ho_out_fail_no_result_after_ho_cmd() runs on test_CT {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005908 var MSC_ConnHdlr vc_conn;
5909
5910 f_init(1, true);
5911 f_sleep(1.0);
5912
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005913 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005914
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02005915 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_result_after_ho_cmd));
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005916 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005917
5918 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5919 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5920 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5921 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5922 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5923 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5924 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005925 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005926}
5927
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005928private 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 +01005929 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
5930 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
5931 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
5932 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
5933 * before we get started. */
5934 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
5935 f_rslem_register(0, new_chan_nr);
5936 g_chan_nr := new_chan_nr;
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02005937 var uint3_t expect_target_tsc := BTS_TSC[0];
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005938 f_sleep(1.0);
5939
5940 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
5941 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
5942 activate(as_Media());
5943
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005944 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005945 f_gen_handover_req(aoip_tla := g_pars.host_aoip_tla,
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02005946 oldToNewBSSIEs := oldToNewBSSIEs,
5947 enc := g_pars.encr)));
Harald Welte6811d102019-04-14 22:23:14 +02005948 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005949
5950 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
5951
5952 var PDU_BSSAP rx_bssap;
5953 var octetstring ho_command_str;
5954
5955 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
Pau Espin Pedrol76ba5412019-06-10 11:00:33 +02005956
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02005957 /* we're sure that the channel activation is done now, verify the parameters in it */
5958 var RSL_Message chan_act := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
5959 f_verify_encr_info(chan_act);
5960 f_chan_act_verify_tsc(chan_act, expect_target_tsc);
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02005961
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005962 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
5963 log("Received L3 Info in HO Request Ack: ", ho_command_str);
5964 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
5965 log("L3 Info in HO Request Ack is ", ho_command);
5966
5967 var GsmArfcn arfcn;
5968 var RslChannelNr actual_new_chan_nr;
5969 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
5970 actual_new_chan_nr, arfcn);
5971
5972 if (actual_new_chan_nr != new_chan_nr) {
5973 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
5974 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
5975 setverdict(fail);
5976 return;
5977 }
5978 log("Handover Command chan_nr is", actual_new_chan_nr);
5979
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02005980 var uint3_t got_tsc := rr_chan_desc_tsc(ho_command.msgs.rrm.handoverCommand.channelDescription2);
5981 if (not match(got_tsc, expect_target_tsc)) {
5982 setverdict(fail, "RR Handover Command: unexpected TSC in Channel Description: expected ",
5983 expect_target_tsc, " got ", got_tsc);
5984 mtc.stop;
5985 } else {
5986 log("handoverCommand: verified TSC = ", got_tsc);
5987 }
5988
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005989 /* Now the MSC forwards the RR Handover Command to the other BSC, which
5990 * tells the MS to handover to the new lchan. Here comes the new MS on
5991 * the new lchan with a Handover RACH: */
5992
5993 /* send handover detect */
5994
5995 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
5996
5997 BSSAP.receive(tr_BSSMAP_HandoverDetect);
5998
5999 /* send handover complete over the new channel */
6000
6001 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
6002 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
6003 enc_PDU_ML3_MS_NW(l3_tx)));
6004
6005 BSSAP.receive(tr_BSSMAP_HandoverComplete);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006006 setverdict(pass);
6007}
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006008
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006009private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006010 var template PDU_ML3_NW_MS exp_rr_rel_tmpl;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006011 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit;
6012 if (not istemplatekind(g_pars.last_used_eutran_plmn, "omit")) {
6013 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006014 }
6015 if (g_pars.exp_fast_return) {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006016 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE_CellSelectInd;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006017 } else {
6018 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006019 }
6020 f_ho_into_this_bsc(id, oldToNewBSSIEs);
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02006021 f_perform_clear(exp_rr_rel_tmpl := exp_rr_rel_tmpl);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006022 setverdict(pass);
6023}
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006024function f_tc_ho_into_this_bsc_main(TestHdlrParams pars) runs on test_CT {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006025 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006026
6027 f_init(1, true);
6028 f_sleep(1.0);
6029
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006030 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006031
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006032 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6033 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006034
6035 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
6036 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006037
6038 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6039 f_ctrs_bsc_and_bts_add(0, "handover:completed");
6040 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6041 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed");
6042 f_ctrs_bsc_and_bts_verify();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006043}
6044
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006045testcase TC_ho_into_this_bsc() runs on test_CT {
6046 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6047 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006048 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006049}
6050
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006051function f_tc_ho_into_this_bsc_a5(OCT1 encr_alg) runs on test_CT {
6052 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6053 pars.encr := valueof(t_EncrParams(encr_alg, f_rnd_octstring(8), f_rnd_octstring(16)));
6054 f_tc_ho_into_this_bsc_main(pars);
6055 f_shutdown_helper();
6056}
6057
6058testcase TC_ho_into_this_bsc_a5_0() runs on test_CT {
6059 f_tc_ho_into_this_bsc_a5('01'O);
6060}
6061
6062testcase TC_ho_into_this_bsc_a5_1() runs on test_CT {
6063 f_tc_ho_into_this_bsc_a5('02'O);
6064}
6065
6066testcase TC_ho_into_this_bsc_a5_3() runs on test_CT {
6067 f_tc_ho_into_this_bsc_a5('08'O);
6068}
6069
6070testcase TC_ho_into_this_bsc_a5_4() runs on test_CT {
6071 f_tc_ho_into_this_bsc_a5('10'O);
6072}
6073
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006074testcase TC_ho_into_this_bsc_tla_v6() runs on test_CT {
6075 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6076 pars.host_aoip_tla := "::6";
6077 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006078 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006079}
6080
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006081/* Similar to TC_ho_into_this_bsc, but when in SRVCC, HO Req contains "Old BSS
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006082 to New BSS Information" IE with "Last Used E-UTRAN PLMN Id", which, when the
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006083 channel is later released (RR CHannel Release), should trigger inclusion of
6084 IE "Cell Selection Indicator after Release of all TCH and SDCCH" with E-UTRAN
6085 neighbors. */
6086testcase TC_srvcc_eutran_to_geran() runs on test_CT {
6087 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6088 pars.last_used_eutran_plmn := '323454'O;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006089 pars.exp_fast_return := true;
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006090 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02006091
6092 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted");
6093 f_ctrs_bsc_and_bts_add(0, "srvcc:completed");
6094 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006095 f_shutdown_helper();
6096}
6097
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006098/* Same as TC_srvcc_eutran_to_geran, but test explicitly forbiding fast return
6099 on the BTS. As a result, RR Release shouldn't contain the EUTRAN neighbor
6100 list when the channel is released. */
6101testcase TC_srvcc_eutran_to_geran_forbid_fast_return() runs on test_CT {
6102 f_init_vty();
6103 f_vty_allow_srvcc_fast_return(true, 0)
6104
6105 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6106 pars.last_used_eutran_plmn := '323454'O;
6107 pars.exp_fast_return := false;
6108 f_tc_ho_into_this_bsc_main(pars);
6109 f_vty_allow_srvcc_fast_return(false, 0);
6110 f_shutdown_helper();
6111}
6112
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006113private function f_tc_srvcc_eutran_to_geran_ho_out(charstring id) runs on MSC_ConnHdlr {
6114 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs;
6115 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
6116 f_ho_into_this_bsc(id, oldToNewBSSIEs);
6117 f_ho_out_of_this_bsc(oldToNewBSSIEs);
6118 setverdict(pass);
6119}
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006120
6121private function f_tc_srvcc_eutran_to_geran_ho_out_main(boolean disable_fast_return)
6122 runs on test_CT {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006123 var MSC_ConnHdlr vc_conn;
6124 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6125
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01006126 f_init_vty();
6127 f_bts_0_cfg(BSCVTY,
6128 {"neighbor-list mode automatic",
6129 "handover 1",
6130 "handover algorithm 2",
6131 "handover2 window rxlev averaging 1",
6132 "no neighbors",
6133 "neighbor lac 99 arfcn 123 bsic any"});
6134 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6135
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006136 f_init(1, true);
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006137 if (disable_fast_return) {
6138 f_vty_allow_srvcc_fast_return(true, 0);
6139 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006140 f_sleep(1.0);
6141
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006142 f_ctrs_bsc_and_bts_handover_init();
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006143
6144 pars.last_used_eutran_plmn := '323454'O;
6145 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6146 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
6147
6148 vc_conn := f_start_handler(refers(f_tc_srvcc_eutran_to_geran_ho_out), pars);
6149 vc_conn.done;
6150
6151 f_ctrs_bsc_and_bts_add(0, "handover:attempted", 2);
6152 f_ctrs_bsc_and_bts_add(0, "handover:completed", 2);
6153 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted", 1);
6154 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed", 1);
6155 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted", 1);
6156 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed", 1);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02006157
6158 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted", 1);
6159 f_ctrs_bsc_and_bts_add(0, "srvcc:completed", 1);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006160 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006161
6162 if (disable_fast_return) {
6163 f_vty_allow_srvcc_fast_return(false, 0);
6164 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006165 f_shutdown_helper();
6166}
6167
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006168/* First, HO into BSC from EUTRAN (SRVCC): HO Request contains "Old BSS to New
6169 BSS Information" IE with "Last Used E-UTRAN PLMN Id".
6170 Second, HO to another BSC: HO Required contains "Old BSS to New BSS Information"
6171 IE with "Last Used E-UTRAN PLMN Id" from first step. */
6172testcase TC_srvcc_eutran_to_geran_ho_out() runs on test_CT {
6173 f_tc_srvcc_eutran_to_geran_ho_out_main(false);
6174}
6175/* Validate subsequent intra-GSM-HO works the same (with OldBSSToNewBSSInfo IE)
6176 * independently of fast-reture allowed/forbidden in local BTS */
6177testcase TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() runs on test_CT {
6178 f_tc_srvcc_eutran_to_geran_ho_out_main(true);
6179}
6180
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006181private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
6182 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6183 f_rslem_register(0, new_chan_nr);
6184 g_chan_nr := new_chan_nr;
6185 f_sleep(1.0);
6186
6187 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6188 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6189 activate(as_Media());
6190
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006191 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006192 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006193 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006194
6195 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6196
6197 var PDU_BSSAP rx_bssap;
6198 var octetstring ho_command_str;
6199
6200 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6201
6202 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6203 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6204 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6205 log("L3 Info in HO Request Ack is ", ho_command);
6206
6207 var GsmArfcn arfcn;
6208 var RslChannelNr actual_new_chan_nr;
6209 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6210 actual_new_chan_nr, arfcn);
6211
6212 if (actual_new_chan_nr != new_chan_nr) {
6213 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6214 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6215 setverdict(fail);
6216 return;
6217 }
6218 log("Handover Command chan_nr is", actual_new_chan_nr);
6219
Neels Hofmeyr61ca08d2019-05-06 23:52:22 +02006220 /* For deterministic test results, give some time for the MGW endpoint to be configured */
6221 f_sleep(1.0);
6222
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006223 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6224 * tells the MS to handover to the new lchan. In this case, the MS
6225 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
6226 * Handover Failure to the MSC. The procedure according to 3GPP TS
6227 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
6228 * BSSMAP Clear Command: */
6229
6230 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6231 var BssmapCause cause := enum2int(cause_val);
6232 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6233
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006234 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006235 BSSAP.receive(tr_BSSMAP_ClearComplete);
6236
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006237 setverdict(pass);
6238 f_sleep(1.0);
6239
6240 setverdict(pass);
6241}
6242testcase TC_ho_in_fail_msc_clears() runs on test_CT {
6243 var MSC_ConnHdlr vc_conn;
6244 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6245
6246 f_init(1, true);
6247 f_sleep(1.0);
6248
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006249 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006250
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006251 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6252 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006253
6254 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
6255 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006256
6257 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6258 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
6259 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6260 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
6261 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006262 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006263}
6264
6265private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
6266 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
6267 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
6268 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
6269 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
6270 * before we get started. */
6271 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6272 f_rslem_register(0, new_chan_nr);
6273 g_chan_nr := new_chan_nr;
6274 f_sleep(1.0);
6275
6276 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6277 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6278 activate(as_Media());
6279
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006280 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006281 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006282 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006283
6284 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6285
6286 var PDU_BSSAP rx_bssap;
6287 var octetstring ho_command_str;
6288
6289 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6290
6291 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6292 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6293 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6294 log("L3 Info in HO Request Ack is ", ho_command);
6295
6296 var GsmArfcn arfcn;
6297 var RslChannelNr actual_new_chan_nr;
6298 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6299 actual_new_chan_nr, arfcn);
6300
6301 if (actual_new_chan_nr != new_chan_nr) {
6302 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6303 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6304 setverdict(fail);
6305 return;
6306 }
6307 log("Handover Command chan_nr is", actual_new_chan_nr);
6308
6309 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6310 * tells the MS to handover to the new lchan. Here comes the new MS on
6311 * the new lchan with a Handover RACH: */
6312
6313 /* send handover detect */
6314
6315 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
6316
6317 BSSAP.receive(tr_BSSMAP_HandoverDetect);
6318
6319 /* The MSC chooses to clear the connection now, maybe we got the
6320 * Handover RACH on the new cell but the MS still signaled Handover
6321 * Failure to the old BSS? */
6322
6323 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6324 var BssmapCause cause := enum2int(cause_val);
6325 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6326
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006327 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006328 BSSAP.receive(tr_BSSMAP_ClearComplete);
6329
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006330 f_sleep(1.0);
6331}
6332testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
6333 var MSC_ConnHdlr vc_conn;
6334 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6335
6336 f_init(1, true);
6337 f_sleep(1.0);
6338
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006339 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006340
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006341 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6342 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006343
6344 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
6345 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006346
6347 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6348 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
6349 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6350 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
6351 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006352 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006353}
6354
6355/* The new BSS's lchan times out before the MSC decides that handover failed. */
6356private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
6357 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6358 f_rslem_register(0, new_chan_nr);
6359 g_chan_nr := new_chan_nr;
6360 f_sleep(1.0);
6361
6362 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6363 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6364 activate(as_Media());
6365
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006366 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006367 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006368 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006369
6370 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6371
6372 var PDU_BSSAP rx_bssap;
6373 var octetstring ho_command_str;
6374
6375 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6376
6377 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6378 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6379 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6380 log("L3 Info in HO Request Ack is ", ho_command);
6381
6382 var GsmArfcn arfcn;
6383 var RslChannelNr actual_new_chan_nr;
6384 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6385 actual_new_chan_nr, arfcn);
6386
6387 if (actual_new_chan_nr != new_chan_nr) {
6388 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6389 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6390 setverdict(fail);
6391 return;
6392 }
6393 log("Handover Command chan_nr is", actual_new_chan_nr);
6394
6395 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6396 * tells the MS to handover to the new lchan. But the MS never shows up
6397 * on the new lchan. */
6398
6399 BSSAP.receive(tr_BSSMAP_HandoverFailure);
6400
6401 /* Did osmo-bsc also send a Clear Request? */
6402 timer T := 0.5;
6403 T.start;
6404 alt {
6405 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
6406 [] T.timeout { }
6407 }
6408
6409 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
6410 * asked for it, this is a Handover Failure after all). */
6411
6412 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6413 var BssmapCause cause := enum2int(cause_val);
6414 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6415
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006416 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006417 BSSAP.receive(tr_BSSMAP_ClearComplete);
6418
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006419 f_sleep(1.0);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006420}
6421testcase TC_ho_in_fail_no_detect() runs on test_CT {
6422 var MSC_ConnHdlr vc_conn;
6423 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6424
6425 f_init(1, true);
6426 f_sleep(1.0);
6427
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006428 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006429
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006430 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6431 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006432
6433 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
6434 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006435
6436 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6437 f_ctrs_bsc_and_bts_add(0, "handover:error");
6438 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6439 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
6440 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006441 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006442}
6443
6444/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
6445private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
6446 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6447 f_rslem_register(0, new_chan_nr);
6448 g_chan_nr := new_chan_nr;
6449 f_sleep(1.0);
6450
6451 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6452 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6453 activate(as_Media());
6454
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006455 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006456 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006457 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006458
6459 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6460
6461 var PDU_BSSAP rx_bssap;
6462 var octetstring ho_command_str;
6463
6464 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6465
6466 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6467 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6468 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6469 log("L3 Info in HO Request Ack is ", ho_command);
6470
6471 var GsmArfcn arfcn;
6472 var RslChannelNr actual_new_chan_nr;
6473 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6474 actual_new_chan_nr, arfcn);
6475
6476 if (actual_new_chan_nr != new_chan_nr) {
6477 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6478 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6479 setverdict(fail);
6480 return;
6481 }
6482 log("Handover Command chan_nr is", actual_new_chan_nr);
6483
6484 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6485 * tells the MS to handover to the new lchan. But the MS never shows up
6486 * on the new lchan. */
6487
6488 BSSAP.receive(tr_BSSMAP_HandoverFailure);
6489
6490 /* MSC plays dumb and sends no Clear Command */
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006491 var PDU_BSSAP rx_clear_request;
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02006492
6493 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006494 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
6495 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6496 };
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006497 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006498 BSSAP.receive(tr_BSSMAP_ClearComplete);
6499
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006500 f_sleep(1.0);
6501}
6502testcase TC_ho_in_fail_no_detect2() runs on test_CT {
6503 var MSC_ConnHdlr vc_conn;
6504 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6505
6506 f_init(1, true);
6507 f_sleep(1.0);
6508
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006509 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006510
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006511 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6512 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006513
6514 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
6515 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006516
6517 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6518 f_ctrs_bsc_and_bts_add(0, "handover:error");
6519 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6520 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
6521 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006522 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006523}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006524
Neels Hofmeyr91401012019-07-11 00:42:35 +02006525type record of charstring Commands;
6526
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006527private function f_bts_0_cfg(TELNETasp_PT pt, Commands cmds := {})
Neels Hofmeyr91401012019-07-11 00:42:35 +02006528{
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006529 f_vty_enter_cfg_bts(pt, 0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006530 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006531 f_vty_transceive(pt, cmds[i]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006532 }
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006533 f_vty_transceive(pt, "end");
Neels Hofmeyr91401012019-07-11 00:42:35 +02006534}
6535
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01006536private function f_cs7_inst_0_cfg(TELNETasp_PT pt, Commands cmds := {})
6537{
6538 f_vty_enter_cfg_cs7_inst(pt, 0);
6539 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
6540 f_vty_transceive(pt, cmds[i]);
6541 }
6542 f_vty_transceive(pt, "end");
6543}
6544
Neels Hofmeyr91401012019-07-11 00:42:35 +02006545private function f_probe_for_handover(charstring log_label,
6546 charstring log_descr,
6547 charstring handover_vty_cmd,
6548 boolean expect_handover,
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006549 boolean is_inter_bsc_handover := false,
6550 template uint3_t expect_target_tsc := ?)
Neels Hofmeyr91401012019-07-11 00:42:35 +02006551runs on MSC_ConnHdlr
6552{
Neels Hofmeyrb3fc8982020-05-11 00:16:42 +02006553 /* We're going to thwart any and all handover attempts, just be ready to handle (and ignore) handover target
6554 * lchans to be established on bts 1 or bts 2. */
6555 f_rslem_suspend(RSL1_PROC);
6556 f_rslem_suspend(RSL2_PROC);
6557
Neels Hofmeyr91401012019-07-11 00:42:35 +02006558 var RSL_Message rsl;
6559
6560 var charstring log_msg := " (expecting handover)"
6561 if (not expect_handover) {
6562 log_msg := " (expecting NO handover)";
6563 }
6564 log("f_probe_for_handover starting: " & log_label & ": " & log_descr & log_msg);
6565 f_vty_transceive(BSCVTY, handover_vty_cmd);
6566
Neels Hofmeyr91401012019-07-11 00:42:35 +02006567 timer T := 2.0;
6568 T.start;
6569
6570 alt {
6571 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
6572 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
6573 log("Rx L3 from net: ", l3);
6574 if (ischosen(l3.msgs.rrm.handoverCommand)) {
6575 var RslChannelNr new_chan_nr;
6576 var GsmArfcn arfcn;
6577 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
6578 new_chan_nr, arfcn);
6579 log("Handover to new chan ", new_chan_nr, " on ARFCN ", arfcn);
6580 log(l3.msgs.rrm.handoverCommand);
6581
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006582 /* Verify correct TSC in handoverCommand */
6583 var uint3_t got_tsc := rr_chan_desc_tsc(l3.msgs.rrm.handoverCommand.channelDescription2);
6584 if (not match(got_tsc, expect_target_tsc)) {
6585 setverdict(fail, "RR Handover Command: unexpected TSC in Channel Description: expected ",
6586 expect_target_tsc, " got ", got_tsc);
6587 mtc.stop;
6588 } else {
6589 log("handoverCommand: verified TSC = ", got_tsc, " (matches ",
6590 expect_target_tsc, ")");
6591 }
6592
Neels Hofmeyr91401012019-07-11 00:42:35 +02006593 /* Need to register for new lchan on new BTS -- it's either bts 1 or bts 2. It doesn't really
6594 * matter on which BTS it really is, we're not going to follow through an entire handover
6595 * anyway. */
6596 f_rslem_register(0, new_chan_nr, RSL1_PROC);
6597 f_rslem_resume(RSL1_PROC);
6598 f_rslem_register(0, new_chan_nr, RSL2_PROC);
6599 f_rslem_resume(RSL2_PROC);
6600
6601 if (expect_handover and not is_inter_bsc_handover) {
6602 setverdict(pass);
6603 log("f_probe_for_handover(" & log_label & "): Got RSL Handover Command as expected.");
6604 } else {
6605 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got RSL Handover Command. "
6606 & log_label & ": " & log_descr);
6607 }
6608
6609 log("f_probe_for_handover(" & log_label & "): Ending the test: Handover Failure stops the procedure.");
6610 /* osmo-bsc has triggered Handover. That's all we need to know for this test, reply with
6611 * Handover Failure. */
6612 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
6613
6614 /* target BTS is told to release lchan again; don't care which BTS nor what messages. */
6615 f_sleep(0.5);
6616 RSL1.clear;
6617 RSL2.clear;
6618 log("f_probe_for_handover(" & log_label & "): done (got RSL Handover Command)");
6619 break;
6620 } else {
6621 repeat;
6622 }
6623 }
6624 [] BSSAP.receive(tr_BSSMAP_HandoverRequired) {
6625 if (expect_handover and is_inter_bsc_handover) {
6626 setverdict(pass);
6627 log("f_probe_for_handover(" & log_label & "): Got BSSMAP Handover Required as expected.");
6628 } else {
6629 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got BSSMAP Handover Required. "
6630 & log_label & ": " & log_descr);
6631 }
6632
6633 log("f_probe_for_handover(" & log_label & "): done (got BSSMAP Handover Required)");
6634
6635 /* Note: f_tc_ho_neighbor_config_start() sets T7, the timeout for BSSMAP Handover Required, to
6636 * 1 second. There is no legal way to quickly abort a handover after a BSSMAP Handover Required,
6637 * setting a short timeout and waiting is the only way. */
6638 log("f_probe_for_handover(" & log_label & "): waiting for inter-BSC HO to time out...");
6639 f_sleep(1.5);
6640 log("f_probe_for_handover(" & log_label & "): ...done");
6641
6642 break;
6643 }
6644 [] T.timeout {
6645 if (expect_handover) {
6646 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected Handover, but got none. "
6647 & log_label & ": " & log_descr);
6648 } else {
6649 setverdict(pass);
6650 log("f_probe_for_handover(" & log_label & "): Got no Handover, as expected.");
6651 }
6652 log("f_probe_for_handover(" & log_label & "): done (got no Handover)");
6653 break;
6654 }
6655 }
6656
6657 f_rslem_resume(RSL1_PROC);
6658 f_rslem_resume(RSL2_PROC);
6659 f_sleep(3.0);
6660 RSL.clear;
6661
6662 log("f_probe_for_handover(" & log_label & "): done clearing");
6663}
6664
6665/* Test the effect of various neighbor configuration scenarios:
6666 *
6667 * To avoid complexity, block off any actual handover operation, and always remain on the lchan at bts 0.
6668 * Reconfigure the neighbors for bts 0, trigger a Handover, and probe whether osmo-bsc does or doesn't start HO.
6669 */
6670private function f_tc_ho_neighbor_config_start() runs on MSC_ConnHdlr {
6671 g_pars := f_gen_test_hdlr_pars();
6672 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
6673 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006674
6675 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
6676 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
6677
6678 /* Establish lchan at bts 0 */
6679 f_establish_fully(ass_cmd, exp_compl);
6680
6681 /* Shorten the inter-BSC Handover timeout, to not wait so long for inter-BSC Handovers */
6682 f_vty_enter_cfg_network(BSCVTY);
6683 f_vty_transceive(BSCVTY, "timer T7 1");
6684 f_vty_transceive(BSCVTY, "end");
6685}
6686
6687private function f_tc_ho_neighbor_config_1(charstring id) runs on MSC_ConnHdlr {
6688 f_tc_ho_neighbor_config_start();
6689
6690 /*
6691 * bts 0 ARFCN 871 BSIC 10
6692 * bts 1 ARFCN 871 BSIC 11
6693 * bts 2 ARFCN 871 BSIC 12
6694 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6695 */
6696
6697 log("f_tc_ho_neighbor_config: 1. No 'neighbor' config");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006698 f_bts_0_cfg(BSCVTY, {"no neighbors"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006699 f_probe_for_handover("1.a", "HO to bts 1 works, implicitly listed as neighbor (legacy behavior when none are configured)",
6700 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006701 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006702
6703 f_probe_for_handover("1.b", "HO to unknown cell does not start",
6704 "handover any to arfcn 13 bsic 39",
6705 false);
6706
6707 f_probe_for_handover("1.c", "HO to 871-12 is ambiguous = error",
6708 "handover any to arfcn 871 bsic 12",
6709 false);
6710
6711 f_probe_for_handover("1.d", "HO to 871-11 still works (verify that this test properly cleans up)",
6712 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006713 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006714}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006715testcase TC_ho_neighbor_config_1() runs on test_CT {
6716 var MSC_ConnHdlr vc_conn;
6717 f_init(3, true, guard_timeout := 60.0);
6718 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006719 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006720 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_1));
6721 vc_conn.done;
6722
6723 /* f_tc_ho_neighbor_config_start() */
6724 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6725 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6726
6727 /* 1.a */
6728 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6729 * handover quickly by sending a Handover Failure message. */
6730 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6731 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6732 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6733 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006734 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6735 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006736
6737 /* 1.b */
6738 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6739 f_ctrs_bsc_and_bts_add(0, "handover:error");
6740
6741 /* 1.c */
6742 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6743 f_ctrs_bsc_and_bts_add(0, "handover:error");
6744
6745 /* 1.d */
6746 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6747 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6748 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6749 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006750 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6751 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006752
6753 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006754 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006755}
6756
Neels Hofmeyr91401012019-07-11 00:42:35 +02006757private function f_tc_ho_neighbor_config_2(charstring id) runs on MSC_ConnHdlr {
6758 f_tc_ho_neighbor_config_start();
6759
6760 /*
6761 * bts 0 ARFCN 871 BSIC 10
6762 * bts 1 ARFCN 871 BSIC 11
6763 * bts 2 ARFCN 871 BSIC 12
6764 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6765 */
6766
6767 log("f_tc_ho_neighbor_config: 2. explicit local neighbor: 'neighbor bts 1'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006768 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006769 f_sleep(0.5);
6770
6771 f_probe_for_handover("2.a", "HO to bts 1 works, explicitly listed as neighbor",
6772 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006773 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006774
6775 f_probe_for_handover("2.b", "HO to bts 2 doesn't work, not listed as neighbor",
6776 "handover any to arfcn 871 bsic 12",
6777 false);
6778}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006779testcase TC_ho_neighbor_config_2() runs on test_CT {
6780 var MSC_ConnHdlr vc_conn;
6781 f_init(3, true, guard_timeout := 50.0);
6782 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006783 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006784 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_2));
6785 vc_conn.done;
6786
6787 /* f_tc_ho_neighbor_config_start() */
6788 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6789 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6790
6791 /* 2.a */
6792 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6793 * handover quickly by sending a Handover Failure message. */
6794 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6795 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6796 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6797 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006798 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6799 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006800
6801 /* 2.b */
6802 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6803 f_ctrs_bsc_and_bts_add(0, "handover:error");
6804
6805 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006806 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006807}
6808
Neels Hofmeyr91401012019-07-11 00:42:35 +02006809private function f_tc_ho_neighbor_config_3(charstring id) runs on MSC_ConnHdlr {
6810 f_tc_ho_neighbor_config_start();
6811
6812 /*
6813 * bts 0 ARFCN 871 BSIC 10
6814 * bts 1 ARFCN 871 BSIC 11
6815 * bts 2 ARFCN 871 BSIC 12
6816 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6817 */
6818
6819 log("f_tc_ho_neighbor_config: 3. explicit local neighbor: 'neighbor bts 2'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006820 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006821 f_sleep(0.5);
6822
6823 f_probe_for_handover("3.a", "HO to bts 1 doesn't work, not listed as neighbor",
6824 "handover any to arfcn 871 bsic 11",
6825 false);
6826 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",
6827 "handover any to arfcn 871 bsic 12",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006828 true, expect_target_tsc := BTS_TSC[2]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006829}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006830testcase TC_ho_neighbor_config_3() runs on test_CT {
6831 var MSC_ConnHdlr vc_conn;
6832 f_init(3, true, guard_timeout := 50.0);
6833 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006834 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006835 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_3));
6836 vc_conn.done;
6837
6838 /* f_tc_ho_neighbor_config_start() */
6839 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6840 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6841
6842 /* 3.a */
6843 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6844 f_ctrs_bsc_and_bts_add(0, "handover:error");
6845
6846 /* 3.b */
6847 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6848 * handover quickly by sending a Handover Failure message. */
6849 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6850 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6851 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6852 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006853 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:attempted");
6854 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006855
6856 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006857 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006858}
6859
Neels Hofmeyr91401012019-07-11 00:42:35 +02006860private function f_tc_ho_neighbor_config_4(charstring id) runs on MSC_ConnHdlr {
6861 f_tc_ho_neighbor_config_start();
6862
6863 /*
6864 * bts 0 ARFCN 871 BSIC 10
6865 * bts 1 ARFCN 871 BSIC 11
6866 * bts 2 ARFCN 871 BSIC 12
6867 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6868 */
6869
6870 log("f_tc_ho_neighbor_config: 4. explicit remote neighbor: 'neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006871 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006872 f_sleep(0.5);
6873
6874 f_probe_for_handover("4.a", "HO to bts 1 doesn't work, not listed as neighbor",
6875 "handover any to arfcn 871 bsic 11",
6876 false);
6877 f_probe_for_handover("4.b", "HO to bts 2 doesn't work, not listed as neighbor",
6878 "handover any to arfcn 871 bsic 12",
6879 false);
6880 f_probe_for_handover("4.c", "HO to 123-45 triggers inter-BSC HO",
6881 "handover any to arfcn 123 bsic 45",
6882 true, true);
6883}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006884testcase TC_ho_neighbor_config_4() runs on test_CT {
6885 var MSC_ConnHdlr vc_conn;
6886 f_init(3, true, guard_timeout := 50.0);
6887 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006888 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006889 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_4));
6890 vc_conn.done;
6891
6892 /* f_tc_ho_neighbor_config_start() */
6893 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6894 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6895
6896 /* 4.a */
6897 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6898 f_ctrs_bsc_and_bts_add(0, "handover:error");
6899
6900 /* 4.b */
6901 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6902 f_ctrs_bsc_and_bts_add(0, "handover:error");
6903
6904 /* 4.c */
6905 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6906 * handover quickly by timing out after the Handover Required message */
6907 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6908 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
6909 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
6910 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
6911
6912 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006913 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006914}
6915
Neels Hofmeyr91401012019-07-11 00:42:35 +02006916private function f_tc_ho_neighbor_config_5(charstring id) runs on MSC_ConnHdlr {
6917 f_tc_ho_neighbor_config_start();
6918
6919 /*
6920 * bts 0 ARFCN 871 BSIC 10
6921 * bts 1 ARFCN 871 BSIC 11
6922 * bts 2 ARFCN 871 BSIC 12
6923 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6924 */
6925
6926 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 +02006927 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006928 f_sleep(0.5);
6929
6930 f_probe_for_handover("5.a", "HO to 871-12 triggers inter-BSC HO (ignoring local cells with same ARFCN+BSIC)",
6931 "handover any to arfcn 871 bsic 12",
6932 true, true);
6933}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006934testcase TC_ho_neighbor_config_5() runs on test_CT {
6935 var MSC_ConnHdlr vc_conn;
6936 f_init(3, true);
6937 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006938 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006939 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_5));
6940 vc_conn.done;
6941
6942 /* f_tc_ho_neighbor_config_start() */
6943 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6944 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6945
6946 /* 5 */
6947 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6948 * handover quickly by timing out after the Handover Required message */
6949 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6950 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
6951 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
6952 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
6953
6954 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006955 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006956}
6957
Neels Hofmeyr91401012019-07-11 00:42:35 +02006958private function f_tc_ho_neighbor_config_6(charstring id) runs on MSC_ConnHdlr {
6959 f_tc_ho_neighbor_config_start();
6960
6961 /*
6962 * bts 0 ARFCN 871 BSIC 10
6963 * bts 1 ARFCN 871 BSIC 11
6964 * bts 2 ARFCN 871 BSIC 12
6965 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6966 */
6967
6968 log("f_tc_ho_neighbor_config: 6. config error: explicit local and remote neighbors with ambiguous ARFCN+BSIC:"
6969 & " 'neighbor bts 2; neighbor lac 99 arfcn 871 bsic 12'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006970 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006971 f_sleep(0.5);
6972
6973 f_probe_for_handover("6.a", "HO to 871-12 is ambiguous = error",
6974 "handover any to arfcn 871 bsic 12",
6975 false);
6976}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006977testcase TC_ho_neighbor_config_6() runs on test_CT {
6978 var MSC_ConnHdlr vc_conn;
6979 f_init(3, true);
6980 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006981 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006982 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_6));
6983 vc_conn.done;
6984
6985 /* f_tc_ho_neighbor_config_start() */
6986 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6987 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6988
6989 /* 6.a */
6990 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6991 * handover quickly by timing out after the Handover Required message */
6992 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6993 f_ctrs_bsc_and_bts_add(0, "handover:error");
6994
6995 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006996 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006997}
6998
Neels Hofmeyr91401012019-07-11 00:42:35 +02006999private function f_tc_ho_neighbor_config_7(charstring id) runs on MSC_ConnHdlr {
7000 f_tc_ho_neighbor_config_start();
7001
7002 /*
7003 * bts 0 ARFCN 871 BSIC 10
7004 * bts 1 ARFCN 871 BSIC 11
7005 * bts 2 ARFCN 871 BSIC 12
7006 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7007 */
7008
7009 log("f_tc_ho_neighbor_config: 7. explicit local and remote neighbors:"
7010 & " 'neighbor bts 2; neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007011 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007012 f_sleep(0.5);
7013
7014 f_probe_for_handover("7.a", "HO to 871-12 does HO to bts 2",
7015 "handover any to arfcn 871 bsic 12",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02007016 true, expect_target_tsc := BTS_TSC[2]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02007017 f_probe_for_handover("7.b", "HO to 123-45 triggers inter-BSC HO",
7018 "handover any to arfcn 123 bsic 45",
7019 true, true);
7020}
Neels Hofmeyr91401012019-07-11 00:42:35 +02007021testcase TC_ho_neighbor_config_7() runs on test_CT {
7022 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf2b88032020-06-16 00:35:04 +02007023 f_init(3, true, guard_timeout := 50.0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02007024 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007025 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007026 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_7));
7027 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007028
7029 /* f_tc_ho_neighbor_config_start() */
7030 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7031 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7032
7033 /* 7.a */
7034 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
7035 * handover quickly by sending a Handover Failure message. */
7036 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7037 f_ctrs_bsc_and_bts_add(0, "handover:failed");
7038 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
7039 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007040 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:attempted");
7041 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007042
7043 /* 7.b */
7044 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7045 * handover quickly by timing out after the Handover Required message */
7046 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7047 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
7048 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
7049 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
7050
7051 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007052 f_shutdown_helper();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007053}
7054
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007055/* OS#3041: Open and close N connections in a normal fashion, and expect no
7056 * BSSMAP Reset just because of that. */
7057testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
7058 var default d;
7059 var integer i;
7060 var DchanTuple dt;
7061
7062 f_init();
7063
7064 /* Wait for initial BSSMAP Reset to pass */
7065 f_sleep(4.0);
7066
7067 d := activate(no_bssmap_reset());
7068
7069 /* Setup up a number of connections and RLSD them again from the MSC
7070 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7071 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02007072 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007073 /* Since we're doing a lot of runs, give each one a fresh
7074 * T_guard from the top. */
7075 T_guard.start;
7076
7077 /* Setup a BSSAP connection and clear it right away. This is
7078 * the MSC telling the BSC about a planned release, it's not an
7079 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02007080 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007081
7082 /* MSC disconnects (RLSD). */
7083 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
7084 }
7085
7086 /* In the buggy behavior, a timeout of 2 seconds happens between above
7087 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7088 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7089 f_sleep(4.0);
7090
7091 deactivate(d);
7092 f_shutdown_helper();
7093}
Harald Welte552620d2017-12-16 23:21:36 +01007094
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007095/* OS#3041: Open and close N connections in a normal fashion, and expect no
7096 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
7097 * the MSC. */
7098testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
7099 var default d;
7100 var integer i;
7101 var DchanTuple dt;
7102 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007103 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
7104 var BssmapCause cause := enum2int(cause_val);
7105
7106 f_init();
7107
7108 /* Wait for initial BSSMAP Reset to pass */
7109 f_sleep(4.0);
7110
7111 d := activate(no_bssmap_reset());
7112
7113 /* Setup up a number of connections and RLSD them again from the MSC
7114 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7115 * Let's do it some more times for good measure. */
7116 for (i := 0; i < 8; i := i+1) {
7117 /* Since we're doing a lot of runs, give each one a fresh
7118 * T_guard from the top. */
7119 T_guard.start;
7120
7121 /* Setup a BSSAP connection and clear it right away. This is
7122 * the MSC telling the BSC about a planned release, it's not an
7123 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02007124 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007125
7126 /* Instruct BSC to clear channel */
7127 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7128
7129 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02007130 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007131 }
7132
7133 /* In the buggy behavior, a timeout of 2 seconds happens between above
7134 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7135 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7136 f_sleep(4.0);
7137
7138 deactivate(d);
7139 f_shutdown_helper();
7140}
7141
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007142/* OS#3041: Open and close N connections in a normal fashion, and expect no
7143 * BSSMAP Reset just because of that. Close connections from the MS side with a
7144 * Release Ind on RSL. */
7145testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
7146 var default d;
7147 var integer i;
7148 var DchanTuple dt;
7149 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007150 var integer j;
7151
7152 f_init();
7153
7154 /* Wait for initial BSSMAP Reset to pass */
7155 f_sleep(4.0);
7156
7157 d := activate(no_bssmap_reset());
7158
7159 /* Setup up a number of connections and RLSD them again from the MSC
7160 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7161 * Let's do it some more times for good measure. */
7162 for (i := 0; i < 8; i := i+1) {
7163 /* Since we're doing a lot of runs, give each one a fresh
7164 * T_guard from the top. */
7165 T_guard.start;
7166
7167 /* Setup a BSSAP connection and clear it right away. This is
7168 * the MSC telling the BSC about a planned release, it's not an
7169 * erratic loss of a connection. */
7170 dt := f_est_dchan('23'O, 23, '00010203040506'O);
7171
7172 /* simulate RLL REL IND */
7173 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
7174
7175 /* expect Clear Request on MSC side */
7176 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
7177
7178 /* Instruct BSC to clear channel */
7179 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
7180 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7181
7182 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02007183 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007184 }
7185
7186 /* In the buggy behavior, a timeout of 2 seconds happens between above
7187 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7188 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7189 f_sleep(4.0);
7190
7191 deactivate(d);
7192 f_shutdown_helper();
7193}
7194
Harald Welte94e0c342018-04-07 11:33:23 +02007195/***********************************************************************
7196 * IPA style dynamic PDCH
7197 ***********************************************************************/
7198
7199private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
7200 template (omit) RSL_Cause nack := omit)
7201runs on test_CT {
7202 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
7203 var RSL_Message rsl_unused;
7204 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
7205 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
7206 /* expect the BSC to issue the related RSL command */
7207 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7208 if (istemplatekind(nack, "omit")) {
7209 /* respond with a related acknowledgement */
7210 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7211 } else {
7212 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
7213 }
7214}
7215
7216private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
7217 template (omit) RSL_Cause nack := omit)
7218runs on test_CT {
7219 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
7220 var RSL_Message rsl_unused;
7221 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
7222 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
7223 /* expect the BSC to issue the related RSL command */
7224 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
7225 if (istemplatekind(nack, "omit")) {
7226 /* respond with a related acknowledgement */
7227 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
7228 } else {
7229 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
7230 }
7231}
7232
7233private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
7234runs on test_CT return charstring {
7235 var charstring cmd, resp;
7236 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01007237 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02007238}
7239
7240private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
7241 template charstring exp)
7242runs on test_CT {
7243 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
7244 if (not match(mode, exp)) {
7245 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02007246 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02007247 }
7248}
7249
7250private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
7251runs on test_CT {
7252 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
7253 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
7254 f_vty_transceive(BSCVTY, "end");
7255}
7256
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007257
7258private function f_ts_reset_chcomb(integer bts_nr) runs on test_CT {
7259 var integer i;
7260 for (i := 0; i < 8; i := i + 1) {
7261 f_ts_set_chcomb(bts_nr, 0, i, phys_chan_config[i]);
7262 }
7263}
7264
Harald Welte94e0c342018-04-07 11:33:23 +02007265private const charstring TCHF_MODE := "TCH/F mode";
7266private const charstring TCHH_MODE := "TCH/H mode";
7267private const charstring PDCH_MODE := "PDCH mode";
7268private const charstring NONE_MODE := "NONE mode";
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007269private const charstring SDCCH8_MODE := "SDCCH8 mode";
Harald Welte94e0c342018-04-07 11:33:23 +02007270
7271/* Test IPA PDCH activation / deactivation triggered by VTY */
7272testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
7273 var RSL_Message rsl_unused;
7274
7275 /* change Timeslot 6 before f_init() starts RSL */
7276 f_init_vty();
7277 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
7278 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7279
7280 f_init(1, false);
7281 f_sleep(1.0);
7282
7283 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
7284
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007285 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007286 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7287 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7288 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7289 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7290 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007291 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007292 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7293
7294 /* De-activate it via VTY */
7295 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7296 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007297 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007298 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7299
7300 /* re-activate it via VTY */
7301 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
7302 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007303 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007304 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7305
7306 /* and finally de-activate it again */
7307 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7308 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007309 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007310 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7311
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007312 /* clean up config */
7313 f_ts_set_chcomb(0, 0, 6, "PDCH");
7314
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007315 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007316}
7317
7318/* Test IPA PDCH activation NACK */
7319testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
7320 var RSL_Message rsl_unused;
7321
7322 /* change Timeslot 6 before f_init() starts RSL */
7323 f_init_vty();
7324 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
7325 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7326
7327 f_init(1, false);
7328 f_sleep(1.0);
7329
7330 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
7331
7332 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7333 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7334 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7335 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7336 f_sleep(1.0);
7337 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7338
7339 /* De-activate it via VTY */
7340 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7341 f_sleep(1.0);
7342 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7343
7344 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
7345 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
7346 f_sleep(1.0);
7347 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7348
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007349 /* clean up config */
7350 f_ts_set_chcomb(0, 0, 6, "PDCH");
7351
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007352 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007353}
7354
7355
7356/***********************************************************************
7357 * Osmocom style dynamic PDCH
7358 ***********************************************************************/
7359
7360private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
7361 template (omit) RSL_Cause nack := omit)
7362runs on test_CT {
7363 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
7364 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02007365 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02007366 /* FIXME: no VTY command to activate Osmocom PDCH !! */
7367 /* expect the BSC to issue the related RSL command */
7368 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
7369 if (istemplatekind(nack, "omit")) {
7370 /* respond with a related acknowledgement */
7371 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7372 } else {
7373 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
7374 }
7375}
7376
7377private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
7378 template (omit) RSL_Cause nack := omit)
7379runs on test_CT {
7380 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
7381 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02007382 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02007383 /* FIXME: no VTY command to activate Osmocom PDCH !! */
7384 /* expect the BSC to issue the related RSL command */
7385 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
7386 if (istemplatekind(nack, "omit")) {
7387 /* respond with a related acknowledgement */
7388 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
7389 } else {
7390 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
7391 }
7392}
7393
7394/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
7395testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
7396 var RSL_Message rsl_unused;
7397
7398 /* change Timeslot 6 before f_init() starts RSL */
7399 f_init_vty();
7400 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
7401 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7402
7403 f_init(1, false);
7404 f_sleep(1.0);
7405
7406 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
7407
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007408 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007409 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7410 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007411 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Harald Welte94e0c342018-04-07 11:33:23 +02007412
7413 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7414 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007415 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 +02007416 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7417
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007418 /* clean up config */
7419 f_ts_set_chcomb(0, 0, 6, "PDCH");
7420
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007421 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007422}
7423
7424/* Test Osmocom dyn PDCH activation NACK behavior */
7425testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
7426 var RSL_Message rsl_unused;
7427
7428 /* change Timeslot 6 before f_init() starts RSL */
7429 f_init_vty();
7430 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
7431 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7432
7433 f_init(1, false);
7434 f_sleep(1.0);
7435
7436 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
7437
7438 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7439 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007440 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Harald Welte94e0c342018-04-07 11:33:23 +02007441
7442 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
7443 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
7444 f_sleep(1.0);
7445 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7446
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007447 /* clean up config */
7448 f_ts_set_chcomb(0, 0, 6, "PDCH");
7449
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007450 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007451}
7452
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007453/* Test Osmocom dyn TS SDCCH8 activation / deactivation */
7454testcase TC_dyn_ts_sdcch8_act_deact() runs on test_CT {
7455 var RSL_Message rsl_unused, rsl_msg;
7456 var DchanTuple dt;
7457 var BSSAP_N_CONNECT_ind rx_c_ind;
7458
7459 /* change Timeslot 6 before f_init() starts RSL */
7460 f_init_vty();
7461 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
7462 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7463
7464 f_init(1, false);
7465 f_sleep(1.0);
7466
7467 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7468
7469 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7470 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7471 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007472 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007473
7474 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7475 f_sleep(1.0);
7476 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7477 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7478
7479 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7480 * on CCCH+SDCCH4+CBCH) */
7481 var integer i;
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007482 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007483 dt := f_est_dchan('23'O, i, '00010203040506'O);
7484 }
7485
7486 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
7487 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
7488 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7489 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7490
7491 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7492 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7493
7494 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7495 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
7496 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7497 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7498
7499 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
7500 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
7501 dt.sccp_conn_id := rx_c_ind.connectionId;
7502 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
7503
7504 /* Instruct BSC to clear channel */
7505 var BssmapCause cause := 0;
7506 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7507 f_exp_chan_rel_and_clear(dt, 0);
7508
7509 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007510 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007511 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7512 f_sleep(1.0);
7513 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7514
7515 /* clean up config */
7516 f_ts_set_chcomb(0, 0, 6, "PDCH");
7517
7518 f_shutdown_helper();
7519}
7520
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007521/* Validate all 8 subslots of a dynamics TS configured as SDCCH8 are used */
7522testcase TC_dyn_ts_sdcch8_all_subslots_used() runs on test_CT {
7523 var ASP_RSL_Unitdata rsl_ud;
7524 var integer i;
7525 var integer chreq_total, chreq_nochan;
7526
7527 f_init_vty();
7528 for (i := 1; i < 8; i := i + 1) {
7529 if (i == 2) {
7530 f_ts_set_chcomb(0, 0, i, "TCH/F_TCH/H_SDCCH8_PDCH");
7531 } else {
7532 f_ts_set_chcomb(0, 0, i, "PDCH");
7533 }
7534 }
7535 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7536
7537 f_init(1);
7538
7539 /* The dyn TS want to activate PDCH mode, ACK that. */
7540 var RslChannelNr chan_nr;
7541 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007542 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007543 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7544
7545 f_sleep(1.0);
7546
7547 /* Exhaust all dedicated SDCCH lchans.
7548 /* GSM 44.018 Table 9.1.8.2:
7549 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
7550 */
7551 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
7552 f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
7553 }
7554
7555 /* Only the dyn TS is still available. Its first lchan gets converted to SDCCH8 */
7556 f_est_dchan_dyn('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
7557 /* Also occupy the seven other SDCCH of the dyn TS */
7558 for (i := 0; i < 7; i := i+1) {
7559 f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
7560 }
7561
7562 /* clean up config */
7563 f_ts_reset_chcomb(0);
7564
7565 f_shutdown_helper();
7566}
7567
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007568/* Test Osmocom dyn TS SDCCH8 activation / deactivation: If activating dyn TS as
7569 SDCCH8 would end up in having no free TCH, then BSC should decide to activate
7570 it as TCH directly instead. SYS#5309. */
7571testcase TC_dyn_ts_sdcch8_tch_call_act_deact() runs on test_CT {
7572 var RSL_Message rsl_unused, rsl_msg;
7573 var DchanTuple dt;
7574 var BSSAP_N_CONNECT_ind rx_c_ind;
7575 var integer i;
7576
7577 /* change Timeslot 6 before f_init() starts RSL */
7578 f_init_vty();
7579 for (i := 1; i < 8; i := i + 1) {
7580 if (i == 6) {
7581 f_ts_set_chcomb(0, 0, i, "TCH/F_TCH/H_SDCCH8_PDCH");
7582 } else {
7583 f_ts_set_chcomb(0, 0, i, "PDCH");
7584 }
7585 }
7586 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7587
7588 f_init(1, false);
7589 f_sleep(1.0);
7590
7591 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7592
7593 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7594 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7595 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007596 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007597
7598 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7599 f_sleep(1.0);
7600 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7601 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7602
7603 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7604 * on CCCH+SDCCH4+CBCH) */
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007605 var OCT1 ra := '43'O; /* RA containing reason=originating speech call*/
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007606 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007607 dt := f_est_dchan(ra, i, '00010203040506'O);
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007608 }
7609
7610 /* Now the dyn ts is selected. First PDCH is released, then TCH chan is activated */
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007611 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int(ra) + i, 1), 2342));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007612 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7613 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7614
7615 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7616 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7617
7618 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
7619 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
7620 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7621 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
7622
7623 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
7624 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
7625 dt.sccp_conn_id := rx_c_ind.connectionId;
7626 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
7627
7628 /* Instruct BSC to clear channel */
7629 var BssmapCause cause := 0;
7630 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7631 f_exp_chan_rel_and_clear(dt, 0);
7632
7633 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007634 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007635 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7636 f_sleep(1.0);
7637 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7638
7639 /* clean up config */
7640 f_ts_reset_chcomb(0);
7641 /* TODO: clean up other channels? */
7642
7643 f_shutdown_helper();
7644}
7645
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007646/* Test Osmocom dyn TS SDCCH8 activation / deactivation when SDCCH fails at BTS */
7647testcase TC_dyn_ts_sdcch8_act_nack() runs on test_CT {
7648 var RSL_Message rsl_unused, rsl_msg;
7649 var DchanTuple dt;
7650 var BSSAP_N_CONNECT_ind rx_c_ind;
7651 var GsmRrMessage rr;
7652
7653 /* change Timeslot 6 before f_init() starts RSL */
7654 f_init_vty();
7655 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
7656 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7657
7658 f_init(1, false);
7659 f_sleep(1.0);
7660
7661 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7662
7663 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7664 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7665 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007666 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007667
7668 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7669 f_sleep(1.0);
7670 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7671 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7672
7673 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7674 * on CCCH+SDCCH4+CBCH) */
7675 var integer i;
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007676 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007677 dt := f_est_dchan('23'O, i, '00010203040506'O);
7678 }
7679
7680 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
7681 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
7682 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7683 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7684
7685 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7686 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7687
7688 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7689 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(dt.rsl_chan_nr, RSL_ERR_EQUIPMENT_FAIL));
7690 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7691 rr := dec_GsmRrMessage(rsl_msg.ies[1].body.full_imm_ass_info.payload);
7692 if (rr.header.message_type != IMMEDIATE_ASSIGNMENT_REJECT) {
7693 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Expected reject");
7694 }
7695
7696 /* FIXME? Currently the TS stays in state BORKEN: */
7697
7698 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007699 /* rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007700 * f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7701 * f_sleep(1.0);
7702 * f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE)
7703 */
7704
7705 /* clean up config */
7706 f_ts_set_chcomb(0, 0, 6, "PDCH");
7707
7708 f_shutdown_helper();
7709}
7710
Stefan Sperling0796a822018-10-05 13:01:39 +02007711testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02007712 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02007713 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
7714 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
7715 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007716 f_shutdown_helper();
Stefan Sperling0796a822018-10-05 13:01:39 +02007717}
7718
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007719testcase TC_chopped_ipa_payload() runs on test_CT {
7720 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
7721 /* TODO: mp_bsc_ctrl_port does not work yet */};
7722 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
7723 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
7724 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007725 f_shutdown_helper();
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007726}
7727
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01007728/* Verify the BSC sends the MS Power Parameters IE during CHAN ACT to make sure
7729 the BTS does autonomous MS power control loop */
7730testcase TC_assignment_verify_ms_power_params_ie() runs on test_CT {
7731 var MSC_ConnHdlr vc_conn;
7732 var TestHdlrParams pars := f_gen_test_hdlr_pars();
7733 //pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
7734 pars.exp_ms_power_params := true;
7735
7736 f_init(1, true);
7737 f_sleep(1.0);
7738 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
7739 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007740 f_shutdown_helper();
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01007741}
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007742
Vadim Yanitskiy4b233042021-06-30 00:58:43 +02007743/* Verify activation and deactivation of the BCCH carrier power reduction mode */
7744testcase TC_c0_power_red_mode() runs on test_CT {
7745 f_init(1);
7746
7747 for (var integer red := 6; red >= 0; red := red - 2) {
7748 /* Configure BCCH carrier power reduction mode via the VTY */
7749 f_vty_transceive(BSCVTY, "bts 0 c0-power-reduction " & int2str(red));
7750
7751 /* Expect Osmocom specific BS Power Control message on the RSL */
7752 var template RSL_Message tr_rsl_pdu := tr_RSL_BS_PWR_CTRL(
7753 chan_nr := t_RslChanNr_BCCH(0),
7754 bs_power := tr_RSL_IE_BS_Power(red / 2));
7755 tr_rsl_pdu.msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false);
7756 var RSL_Message unused := f_exp_ipa_rx(0, tr_rsl_pdu);
7757
7758 /* Additionally verify the applied value over the CTRL interface */
7759 var CtrlValue cred := f_ctrl_get_bts(IPA_CTRL, 0, "c0-power-reduction");
7760 if (cred != int2str(red)) {
7761 setverdict(fail, "Unexpected BCCH carrier power reduction value ",
7762 cred, " (expected ", red, ")");
7763 }
7764 }
7765
7766 f_shutdown_helper();
7767}
7768
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007769/***********************************************************************
7770 * MSC Pooling
7771 ***********************************************************************/
7772
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007773template MobileIdentityLV ts_MI_TMSI_NRI_LV(integer nri_v, integer nri_bitlen := 10) :=
Harald Weltebf397612021-01-14 20:39:46 +01007774 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 +02007775
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007776private 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 +02007777runs on MSC_ConnHdlr {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007778 interleave {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007779 [] rsl_pt.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007780 f_logp(BSCVTY, "Got RSL RR Release");
7781 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007782 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007783 f_logp(BSCVTY, "Got RSL Deact SACCH");
7784 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02007785 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007786 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007787 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
7788 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007789 break;
7790 }
7791 }
7792}
7793
Neels Hofmeyr6289af12021-12-16 18:17:49 +01007794private altstep as_mgcp_ack_all_dlcx() runs on MSC_ConnHdlr {
7795 var MgcpCommand mgcp_cmd;
7796 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
7797 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
7798 repeat;
7799 }
7800}
7801
7802private altstep as_rsl_ack_all_rel_req() runs on MSC_ConnHdlr {
7803 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
7804 [] RSL.receive(tr_RSL_REL_REQ(g_chan_nr, ?)) {
7805 RSL.send(ts_RSL_REL_CONF(g_chan_nr, main_dcch));
7806 repeat;
7807 }
7808}
7809
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007810friend function f_perform_clear(RSL_DCHAN_PT rsl_pt := RSL, RSLEM_PROC_PT rsl_proc_pt := RSL_PROC,
7811 template PDU_ML3_NW_MS exp_rr_rel_tmpl := tr_RRM_RR_RELEASE)
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02007812runs on MSC_ConnHdlr {
Neels Hofmeyr6289af12021-12-16 18:17:49 +01007813 var default ack_dlcx := activate(as_mgcp_ack_all_dlcx());
7814 var default ack_rel_req := activate(as_rsl_ack_all_rel_req());
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007815 f_logp(BSCVTY, "MSC instructs BSC to clear channel");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007816 BSSAP.send(ts_BSSMAP_ClearCommand(0));
7817 interleave {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007818 [] rsl_pt.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007819 f_logp(BSCVTY, "Got RSL RR Release");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007820 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007821 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007822 f_logp(BSCVTY, "Got RSL Deact SACCH");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007823 }
7824 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007825 f_logp(BSCVTY, "Got BSSMAP Clear Complete");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007826 /* Also drop the SCCP connection */
7827 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
7828 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02007829 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007830 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007831 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
7832 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007833 }
7834 }
Neels Hofmeyr6289af12021-12-16 18:17:49 +01007835 deactivate(ack_dlcx);
7836 deactivate(ack_rel_req);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007837}
7838
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007839private function f_perform_compl_l3(RSL_DCHAN_PT rsl_pt, RSLEM_PROC_PT rsl_proc_pt,
7840 template PDU_ML3_MS_NW l3_info, boolean do_clear := true, boolean expect_bssmap_l3 := true)
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007841runs on MSC_ConnHdlr {
7842 timer T := 10.0;
7843 var octetstring l3_enc := enc_PDU_ML3_MS_NW(valueof(l3_info));
7844
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007845 f_logp(BSCVTY, "establish channel, send Complete Layer 3 Info");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007846 f_create_bssmap_exp(l3_enc);
7847
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007848 /* RSL_Emulation.f_chan_est() on rsl_pt:
7849 * This is basically code dup with s/RSL/rsl_pt from:
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007850 * RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
7851 */
7852 var RSL_Message rx_rsl;
7853 var GsmRrMessage rr;
7854
7855 /* request a channel to be established */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007856 rsl_pt.send(ts_RSLDC_ChanRqd(g_pars.ra, g_pars.fn));
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007857 /* expect immediate assignment.
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007858 * Code dup with s/RSL/rsl_pt from:
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007859 * rx_rsl := f_rx_or_fail(tr_RSL_IMM_ASSIGN);
7860 */
7861 timer Tt := 10.0;
7862
7863 /* request a channel to be established */
7864 Tt.start;
7865 alt {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007866 [] rsl_pt.receive(tr_RSL_IMM_ASSIGN) -> value rx_rsl {
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007867 Tt.stop;
7868 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007869 [] rsl_pt.receive {
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007870 setverdict(fail, "Unexpected RSL message on DCHAN");
7871 mtc.stop;
7872 }
7873 [] Tt.timeout {
7874 setverdict(fail, "Timeout waiting for RSL on DCHAN");
7875 mtc.stop;
7876 }
7877 }
7878 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
7879 g_chan_nr := rr.payload.imm_ass.chan_desc.chan_nr;
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007880 rsl_pt.send(ts_RSL_EST_IND(g_chan_nr, valueof(g_pars.link_id), l3_enc));
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007881
7882
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007883 if (expect_bssmap_l3) {
7884 f_logp(BSCVTY, "expect BSSAP Complete Layer 3 Info at MSC");
7885 var template PDU_BSSAP exp_l3_compl;
7886 exp_l3_compl := tr_BSSMAP_ComplL3()
7887 if (g_pars.aoip == false) {
7888 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := omit;
7889 } else {
7890 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := ?;
7891 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007892
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007893 var PDU_BSSAP bssap;
7894 T.start;
7895 alt {
7896 [] BSSAP.receive(exp_l3_compl) -> value bssap {
7897 f_logp(BSCVTY, "received expected Complete Layer 3 Info at MSC");
7898 log("rx exp_l3_compl = ", bssap);
7899 }
7900 [] BSSAP.receive(tr_BSSMAP_ComplL3) {
7901 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching COMPLETE LAYER 3 INFORMATION");
7902 }
7903 [] T.timeout {
7904 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
7905 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007906 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007907
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007908 /* start ciphering, if requested */
7909 if (ispresent(g_pars.encr)) {
7910 f_logp(BSCVTY, "start ciphering");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007911 f_cipher_mode(g_pars.encr, rsl_pt := rsl_pt, rsl_proc_pt := rsl_proc_pt);
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007912 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007913 }
7914
7915 if (do_clear) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007916 f_perform_clear(rsl_pt, rsl_proc_pt);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007917 }
7918 setverdict(pass);
7919 f_sleep(1.0);
7920}
7921
7922private function f_tc_mscpool_compl_l3(charstring id) runs on MSC_ConnHdlr {
7923 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
7924 if (g_pars.mscpool.rsl_idx == 0) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007925 f_perform_compl_l3(RSL, RSL_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007926 } else if (g_pars.mscpool.rsl_idx == 1) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007927 f_perform_compl_l3(RSL1, RSL1_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007928 } else if (g_pars.mscpool.rsl_idx == 2) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007929 f_perform_compl_l3(RSL2, RSL2_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007930 }
7931}
7932
7933/* Various Complete Layer 3 by IMSI all end up with the first MSC, because the other MSCs are not connected. */
7934private function f_tc_mscpool_L3Compl_on_1_msc(charstring id) runs on MSC_ConnHdlr {
7935 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007936 f_perform_compl_l3(RSL, RSL_PROC, ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O) );
7937 f_perform_compl_l3(RSL, RSL_PROC, ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_IMSI_LV('001010000000002'H))) );
7938 f_perform_compl_l3(RSL, RSL_PROC, ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))) );
7939 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 +02007940}
7941testcase TC_mscpool_L3Compl_on_1_msc() runs on test_CT {
7942
7943 f_init(1, true);
7944 f_sleep(1.0);
7945 var MSC_ConnHdlr vc_conn;
7946 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007947
7948 f_ctrs_msc_init();
7949
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007950 vc_conn := f_start_handler(refers(f_tc_mscpool_L3Compl_on_1_msc), pars);
7951 vc_conn.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007952
7953 f_ctrs_msc_expect(0, "mscpool:subscr:new", 4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007954 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007955}
7956
7957/* Three Layer 3 Complete by IMSI are round-robin'ed across two connected MSCs */
7958/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7959 * just as well using only RSL. */
7960testcase TC_mscpool_L3Complete_by_imsi_round_robin() runs on test_CT {
7961
7962 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7963 f_sleep(1.0);
7964
7965 /* Control which MSC gets chosen next by the round-robin, otherwise
7966 * would be randomly affected by which other tests ran before this. */
7967 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7968
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007969 f_ctrs_msc_init();
7970
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007971 var MSC_ConnHdlr vc_conn1;
7972 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7973 pars1.mscpool.rsl_idx := 0;
7974 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
7975 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7976 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007977 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007978
7979 var MSC_ConnHdlr vc_conn2;
7980 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7981 pars2.mscpool.rsl_idx := 1;
7982 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
7983 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7984 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007985 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007986
7987 /* Test round-robin wrap to the first MSC */
7988 var MSC_ConnHdlr vc_conn3;
7989 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
7990 pars3.mscpool.rsl_idx := 2;
7991 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
7992 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7993 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007994 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007995 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007996}
7997
7998/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 0
7999 * (configured in osmo-bsc.cfg). */
8000/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8001 * just as well using only RSL. */
8002testcase TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() runs on test_CT {
8003
8004 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8005 f_sleep(1.0);
8006
8007 /* Control which MSC gets chosen next by the round-robin, otherwise
8008 * would be randomly affected by which other tests ran before this. */
8009 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8010
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008011 f_ctrs_msc_init();
8012
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008013 var MSC_ConnHdlr vc_conn1;
8014 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8015 pars1.mscpool.rsl_idx := 0;
8016 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
8017 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8018 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008019 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008020
8021 var MSC_ConnHdlr vc_conn2;
8022 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8023 pars2.mscpool.rsl_idx := 1;
8024 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
8025 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8026 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008027 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008028
8029 /* Test round-robin wrap to the first MSC */
8030 var MSC_ConnHdlr vc_conn3;
8031 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8032 pars3.mscpool.rsl_idx := 2;
8033 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
8034 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8035 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008036 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008037 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008038}
8039
8040/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 1
8041 * (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
8042 * NULL-NRI setting is stronger than that. */
8043/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8044 * just as well using only RSL. */
8045testcase TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() runs on test_CT {
8046
8047 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8048 f_sleep(1.0);
8049
8050 /* Control which MSC gets chosen next by the round-robin, otherwise
8051 * would be randomly affected by which other tests ran before this. */
8052 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8053
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008054 f_ctrs_msc_init();
8055
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008056 var MSC_ConnHdlr vc_conn1;
8057 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8058 pars1.mscpool.rsl_idx := 0;
8059 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8060 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8061 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008062 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008063
8064 var MSC_ConnHdlr vc_conn2;
8065 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8066 pars2.mscpool.rsl_idx := 1;
8067 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8068 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8069 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008070 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008071
8072 /* Test round-robin wrap to the first MSC */
8073 var MSC_ConnHdlr vc_conn3;
8074 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8075 pars3.mscpool.rsl_idx := 2;
8076 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8077 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8078 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008079 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008080 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008081}
8082
8083/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI not
8084 * assigned to any MSC (configured in osmo-bsc.cfg). */
8085/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8086 * just as well using only RSL. */
8087testcase TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() runs on test_CT {
8088
8089 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8090 f_sleep(1.0);
8091
8092 /* Control which MSC gets chosen next by the round-robin, otherwise
8093 * would be randomly affected by which other tests ran before this. */
8094 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8095
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008096 f_ctrs_msc_init();
8097
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008098 var MSC_ConnHdlr vc_conn1;
8099 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8100 pars1.mscpool.rsl_idx := 0;
8101 /* An NRI that is not assigned to any MSC */
8102 pars1.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(1023))));
8103 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8104 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008105 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008106
8107 var MSC_ConnHdlr vc_conn2;
8108 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8109 pars2.mscpool.rsl_idx := 1;
8110 /* An NRI that is not assigned to any MSC */
8111 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(768)), '00F110'O));
8112 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8113 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008114 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008115
8116 /* Test round-robin wrap to the first MSC */
8117 var MSC_ConnHdlr vc_conn3;
8118 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8119 pars3.mscpool.rsl_idx := 2;
8120 /* An NRI that is not assigned to any MSC */
8121 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, valueof(ts_MI_TMSI_NRI_LV(819))));
8122 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8123 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008124 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008125 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008126}
8127
8128/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI
8129 * assigned to an MSC that is currently not connected (configured in osmo-bsc.cfg). */
8130/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8131 * just as well using only RSL. */
8132testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() runs on test_CT {
8133
8134 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8135 f_sleep(1.0);
8136
8137 /* Control which MSC gets chosen next by the round-robin, otherwise
8138 * would be randomly affected by which other tests ran before this. */
8139 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8140
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008141 f_ctrs_msc_init();
8142
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008143 var MSC_ConnHdlr vc_conn1;
8144 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8145 pars1.mscpool.rsl_idx := 0;
8146 /* An NRI that is assigned to an unconnected MSC */
8147 pars1.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(512))));
8148 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8149 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008150 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8151 f_ctrs_msc_add(0, "mscpool:subscr:new");
8152 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008153
8154 var MSC_ConnHdlr vc_conn2;
8155 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8156 pars2.mscpool.rsl_idx := 1;
8157 /* An NRI that is assigned to an unconnected MSC */
8158 pars2.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(767))));
8159 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8160 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008161 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8162 f_ctrs_msc_add(1, "mscpool:subscr:new");
8163 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008164
8165 /* Test round-robin wrap to the first MSC */
8166 var MSC_ConnHdlr vc_conn3;
8167 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8168 pars3.mscpool.rsl_idx := 2;
8169 /* An NRI that is assigned to an unconnected MSC */
8170 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(750)), '00F110'O));
8171 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8172 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008173 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8174 f_ctrs_msc_add(0, "mscpool:subscr:new");
8175 f_ctrs_msc_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008176 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008177}
8178
8179/* Three Layer 3 Complete by TMSI with valid NRI for the second MSC are all directed to the second MSC (configured in
8180 * osmo-bsc.cfg). */
8181/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8182 * just as well using only RSL. */
8183testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_1() runs on test_CT {
8184
8185 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8186 f_sleep(1.0);
8187
8188 /* All TMSIs in this test point at the second MSC, set the round robin to point at the first MSC to make sure
8189 * this is not using round-robin. */
8190 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8191
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008192 f_ctrs_msc_init();
8193
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008194 var MSC_ConnHdlr vc_conn1;
8195 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
8196 pars1.mscpool.rsl_idx := 0;
8197 /* An NRI of the second MSC's range (256-511) */
8198 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(256))));
8199 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8200 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008201 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008202
8203 var MSC_ConnHdlr vc_conn2;
8204 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8205 pars2.mscpool.rsl_idx := 1;
8206 /* An NRI of the second MSC's range (256-511) */
8207 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(260))));
8208 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8209 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008210 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008211
8212 var MSC_ConnHdlr vc_conn3;
8213 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
8214 pars3.mscpool.rsl_idx := 2;
8215 /* An NRI of the second MSC's range (256-511) */
8216 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(511)), '00F110'O));
8217 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8218 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008219 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008220 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008221}
8222
8223/* Layer 3 Complete by TMSI with valid NRI for the third MSC are directed to the third MSC (configured in osmo-bsc.cfg),
8224 * while a round-robin remains unaffected by that. */
8225/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8226 * just as well using only RSL. */
8227testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_2() runs on test_CT {
8228
8229 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8230 f_sleep(1.0);
8231
8232 /* All TMSIs in this test point at the third MSC, set the round robin to point at the second MSC to make sure
8233 * this is not using round-robin. */
8234 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
8235
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008236 f_ctrs_msc_init();
8237
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008238 var MSC_ConnHdlr vc_conn1;
8239 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 2);
8240 pars1.mscpool.rsl_idx := 0;
8241 /* An NRI of the third MSC's range (512-767) */
8242 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(512))));
8243 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8244 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008245 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008246
8247 var MSC_ConnHdlr vc_conn2;
8248 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8249 pars2.mscpool.rsl_idx := 1;
8250 /* An NRI of the third MSC's range (512-767) */
8251 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(678))));
8252 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8253 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008254 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008255
8256 /* The above forwardings to third MSC have not affected the round robin, which still points at the second MSC */
8257 var MSC_ConnHdlr vc_conn3;
8258 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
8259 pars3.mscpool.rsl_idx := 2;
8260 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000013'H)), '00F110'O));
8261 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8262 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008263 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008264 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008265}
8266
8267/* LU with a TMSI but indicating a different PLMN in its previous LAI: ignore the NRI. */
8268/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8269 * just as well using only RSL. */
8270testcase TC_mscpool_LU_by_tmsi_from_other_PLMN() runs on test_CT {
8271
8272 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8273 f_sleep(1.0);
8274
8275 /* The TMSIs in this test points at the second MSC, but since it is from a different PLMN, round-robin is used
8276 * instead, and hits msc 0. */
8277 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8278
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008279 f_ctrs_msc_init();
8280
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008281 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-bsc.cfg */
8282 var MSC_ConnHdlr vc_conn1;
8283 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8284 pars1.mscpool.rsl_idx := 0;
8285 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(260)), '99F999'O));
8286 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8287 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008288 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008289
8290 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
8291 var MSC_ConnHdlr vc_conn2;
8292 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8293 pars2.mscpool.rsl_idx := 1;
8294 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(555)), '00F110'O));
8295 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8296 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008297 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008298 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008299}
8300
8301/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by IMSI, which would be
8302 * round-robined to another MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
8303private function f_tc_mscpool_paging_imsi(charstring id) runs on MSC_ConnHdlr {
8304 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
8305 //cid_list := { cIl_allInBSS := ''O };
8306 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
8307 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
8308 var BSSAP_N_UNITDATA_req paging;
8309 var hexstring imsi := '001010000000123'H;
8310
8311 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8312
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008313 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008314 valueof(ts_BSSMAP_Paging(imsi, cid_list, omit, bssmap_chneed))));
8315 BSSAP.send(paging);
8316
8317 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
8318 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
8319 * channel number is picked here. */
8320 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
8321 f_rslem_register(0, new_chan_nr);
8322 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(imsi)));
8323 f_rslem_unregister(0, new_chan_nr);
8324
8325 /* Despite the round robin pointing at the second MSC ('roundrobin next 1'), the earlier Paging for the same IMSI
8326 * causes this Paging Response to go to the first MSC (bssap_idx := 0). */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008327 f_perform_compl_l3(RSL, RSL_PROC, ts_PAG_RESP(valueof(ts_MI_IMSI_LV(imsi))) );
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008328 f_sleep(1.0);
8329}
8330testcase TC_mscpool_paging_and_response_imsi() runs on test_CT {
8331 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
8332 f_sleep(1.0);
8333
8334 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
8335 * second MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
8336 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
8337
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008338 f_ctrs_msc_init();
8339
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008340 var MSC_ConnHdlr vc_conn1;
8341 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8342 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008343 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
8344 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008345 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_imsi), pars1);
8346 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008347 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008348 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008349}
8350
8351/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by TMSI with an NRI value
8352 * that matches a different MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
8353private function f_tc_mscpool_paging_tmsi(charstring id) runs on MSC_ConnHdlr {
8354 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
8355 //cid_list := { cIl_allInBSS := ''O };
8356 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
8357 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
8358 var integer nri_v := 300; /* <-- second MSC's NRI */
Harald Weltebf397612021-01-14 20:39:46 +01008359 var octetstring tmsi := f_gen_tmsi(suffix := 0, nri_v := nri_v);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008360 var BSSAP_N_UNITDATA_req paging;
8361
8362 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8363
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008364 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008365 valueof(ts_BSSMAP_Paging('001010000000011'H, cid_list, tmsi, bssmap_chneed))));
8366 BSSAP.send(paging);
8367
8368 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
8369 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
8370 * channel number is picked here. */
8371 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
8372 f_rslem_register(0, new_chan_nr);
8373 RSL.receive(tr_RSL_PAGING_CMD(t_MI_TMSI(tmsi)));
8374 f_rslem_unregister(0, new_chan_nr);
8375
8376 /* Despite the NRI matching the second MSC (NRI from 'msc 1' in osmo-bsc.cfg) and round robin pointing at the
8377 * third MSC ('roundrobin next 2'), the earlier Paging for the same TMSI causes this Paging Response to go to
8378 * the first MSC (bssap_idx := 0). */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008379 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 +02008380 f_sleep(1.0);
8381}
8382testcase TC_mscpool_paging_and_response_tmsi() runs on test_CT {
8383 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
8384 f_sleep(1.0);
8385
8386 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
8387 * third MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
8388 f_vty_transceive(BSCVTY, "mscpool roundrobin next 2");
8389
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008390 f_ctrs_msc_init();
8391
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008392 var MSC_ConnHdlr vc_conn1;
8393 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8394 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008395 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
8396 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008397 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_tmsi), pars1);
8398 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008399 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008400 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008401}
8402
8403/* For round-robin, skip an MSC that has 'no allow-attach' set. */
8404/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8405 * just as well using only RSL. */
8406testcase TC_mscpool_no_allow_attach_round_robin() runs on test_CT {
8407
8408 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8409 f_sleep(1.0);
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00008410 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
8411 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008412
8413 /* Control which MSC gets chosen next by the round-robin, otherwise
8414 * would be randomly affected by which other tests ran before this. */
8415 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8416
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008417 f_ctrs_msc_init();
8418
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008419 var MSC_ConnHdlr vc_conn1;
8420 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8421 pars1.mscpool.rsl_idx := 0;
8422 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
8423 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8424 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008425 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008426
8427 var MSC_ConnHdlr vc_conn2;
8428 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8429 pars2.mscpool.rsl_idx := 1;
8430 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8431 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8432 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008433 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008434
8435 var MSC_ConnHdlr vc_conn3;
8436 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8437 pars3.mscpool.rsl_idx := 2;
8438 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
8439 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8440 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008441 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008442 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008443}
8444
8445/* An MSC that has 'no allow-attach' set should still serve subscribers that are already attached according to their
8446 * TMSI NRI. */
8447testcase TC_mscpool_no_allow_attach_valid_nri() runs on test_CT {
8448
8449 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8450 f_sleep(1.0);
8451
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00008452 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
8453 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
8454
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008455 /* Control which MSC gets chosen next by the round-robin, otherwise
8456 * would be randomly affected by which other tests ran before this. */
8457 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8458
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008459 f_ctrs_msc_init();
8460
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008461 /* Round robin points at msc 0, but the valid NRI directs to msc 1, even though msc 1 has 'no allow-attach'. */
8462 var MSC_ConnHdlr vc_conn1;
8463 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
8464 pars1.mscpool.rsl_idx := 0;
8465 /* An NRI of the second MSC's range (256-511) */
8466 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_TMSI_NRI_LV(260))));
8467 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8468 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008469 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008470
8471 var MSC_ConnHdlr vc_conn2;
8472 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 0);
8473 pars2.mscpool.rsl_idx := 1;
8474 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8475 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8476 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008477 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008478
8479 var MSC_ConnHdlr vc_conn3;
8480 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 2);
8481 pars3.mscpool.rsl_idx := 2;
8482 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000003'H))));
8483 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8484 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008485 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008486 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008487}
8488
Philipp Maier783681c2020-07-16 16:47:06 +02008489/* Allow/Deny emergency calls globally via VTY */
8490private function f_vty_allow_emerg_msc(boolean allow) runs on test_CT {
8491 f_vty_enter_cfg_msc(BSCVTY, 0);
8492 if (allow) {
8493 f_vty_transceive(BSCVTY, "allow-emergency allow");
8494 } else {
8495 f_vty_transceive(BSCVTY, "allow-emergency deny");
8496 }
8497 f_vty_transceive(BSCVTY, "exit");
8498 f_vty_transceive(BSCVTY, "exit");
8499}
8500
8501/* Allow/Deny emergency calls per BTS via VTY */
8502private function f_vty_allow_emerg_bts(boolean allow, integer bts_nr) runs on test_CT {
8503 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8504 if (allow) {
8505 f_vty_transceive(BSCVTY, "rach emergency call allowed 1");
8506 } else {
8507 f_vty_transceive(BSCVTY, "rach emergency call allowed 0");
8508 }
8509 f_vty_transceive(BSCVTY, "exit");
8510 f_vty_transceive(BSCVTY, "exit");
Neels Hofmeyrb6ed80c2020-10-12 22:52:39 +00008511 f_vty_transceive(BSCVTY, "exit");
Philipp Maier783681c2020-07-16 16:47:06 +02008512}
8513
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02008514/* Allow/Forbid Fast Return after SRVCC on a given BTS via VTY */
8515private function f_vty_allow_srvcc_fast_return(boolean allow, integer bts_nr) runs on test_CT {
8516 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8517 if (allow) {
8518 f_vty_transceive(BSCVTY, "srvcc fast-return allow");
8519 } else {
8520 f_vty_transceive(BSCVTY, "srvcc fast-return forbid");
8521 }
8522 f_vty_transceive(BSCVTY, "exit");
8523 f_vty_transceive(BSCVTY, "exit");
8524 f_vty_transceive(BSCVTY, "exit");
8525}
8526
Pau Espin Pedrol14475352021-07-22 15:48:16 +02008527/* Allow/Forbid TCH for signalling if SDCCH exhausted on a given BTS via VTY */
8528private function f_vty_allow_tch_for_signalling(boolean allow, integer bts_nr) runs on test_CT {
8529 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8530 if (allow) {
8531 f_vty_transceive(BSCVTY, "channel allocator allow-tch-for-signalling 1");
8532 } else {
8533 f_vty_transceive(BSCVTY, "channel allocator allow-tch-for-signalling 0");
8534 }
8535 f_vty_transceive(BSCVTY, "exit");
8536 f_vty_transceive(BSCVTY, "exit");
8537 f_vty_transceive(BSCVTY, "exit");
8538}
8539
Philipp Maier783681c2020-07-16 16:47:06 +02008540/* Begin assignmet procedure and send an EMERGENCY SETUP (RR) */
8541private function f_assignment_emerg_setup() runs on MSC_ConnHdlr {
8542 var PDU_ML3_MS_NW emerg_setup;
8543 var octetstring emerg_setup_enc;
8544 var RSL_Message emerg_setup_data_ind;
8545
8546 f_establish_fully(omit, omit);
8547
8548 emerg_setup := valueof(ts_ML3_MO_CC_EMERG_SETUP(1, valueof(ts_Bcap_voice)));
8549 emerg_setup_enc := enc_PDU_ML3_MS_NW(emerg_setup);
8550 emerg_setup_data_ind := valueof(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), emerg_setup_enc));
8551
8552 RSL.send(emerg_setup_data_ind);
8553}
8554
8555/* Test if the EMERGENCY SETUP gets passed on to the MSC via A when EMERGENCY
8556 * CALLS are permitted by the BSC config. */
8557private function f_TC_assignment_emerg_setup_allow(charstring id) runs on MSC_ConnHdlr {
8558 var PDU_BSSAP emerg_setup_data_ind_bssap;
8559 var PDU_ML3_MS_NW emerg_setup;
8560 timer T := 3.0;
8561
8562 f_assignment_emerg_setup()
8563
8564 T.start;
8565 alt {
8566 [] BSSAP.receive(tr_BSSAP_DTAP) -> value emerg_setup_data_ind_bssap {
8567 emerg_setup := dec_PDU_ML3_MS_NW(emerg_setup_data_ind_bssap.pdu.dtap);
8568 if (not isbound(emerg_setup.msgs.cc.emergencySetup)) {
8569 setverdict(fail, "no emergency setup");
8570 }
8571 }
8572 [] BSSAP.receive {
8573 setverdict(fail, "unexpected BSSAP message!");
8574 }
8575 [] T.timeout {
8576 setverdict(fail, "timout waiting for EMERGENCY SETUP!");
8577 }
8578 }
8579
8580 setverdict(pass);
8581}
8582
8583/* Test if the EMERGENCY SETUP gets blocked by the BSC if EMERGENCY CALLS are
8584 * forbidden by the BSC config. */
8585private function f_TC_assignment_emerg_setup_deny(charstring id) runs on MSC_ConnHdlr {
8586 var PDU_BSSAP emerg_setup_data_ind_bssap;
8587 timer T := 3.0;
8588
8589 f_assignment_emerg_setup()
8590
8591 T.start;
8592 alt {
8593 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
8594 setverdict(pass);
8595 }
8596 [] RSL.receive {
8597 setverdict(fail, "unexpected RSL message!");
8598 }
8599 [] T.timeout {
8600 setverdict(fail, "timout waiting for RR CHANNEL RELEASE!");
8601 }
8602 }
8603}
8604
8605/* EMERGENCY CALL situation #1, allowed globally and by BTS */
8606testcase TC_assignment_emerg_setup_allow() runs on test_CT {
8607 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8608 var MSC_ConnHdlr vc_conn;
8609
8610 f_init(1, true);
8611 f_sleep(1.0);
8612
8613 f_vty_allow_emerg_msc(true);
8614 f_vty_allow_emerg_bts(true, 0);
8615 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_allow), pars);
8616 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008617 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008618}
8619
8620/* EMERGENCY CALL situation #2, forbidden globally but allowed by BTS */
8621testcase TC_assignment_emerg_setup_deny_msc() runs on test_CT {
8622 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8623 var MSC_ConnHdlr vc_conn;
8624
8625 f_init(1, true);
8626 f_sleep(1.0);
8627
8628 f_vty_allow_emerg_msc(false);
8629 f_vty_allow_emerg_bts(true, 0);
8630 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
8631 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008632 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008633}
8634
8635/* EMERGENCY CALL situation #3, allowed globally but forbidden by BTS */
8636testcase TC_assignment_emerg_setup_deny_bts() runs on test_CT {
8637 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8638 var MSC_ConnHdlr vc_conn;
8639
8640 /* Note: This simulates a spec violation by the MS, correct MS
8641 * implementations would not try to establish an emergency call because
8642 * the system information tells in advance that emergency calls are
8643 * not forbidden */
8644
8645 f_init(1, true);
8646 f_sleep(1.0);
8647
8648 f_vty_allow_emerg_msc(true);
8649 f_vty_allow_emerg_bts(false, 0);
8650 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
8651 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008652 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008653}
8654
Philipp Maier82812002020-08-13 18:48:27 +02008655/* Test what happens when an emergency call arrives while all TCH channels are
8656 * busy, the BSC is expected to terminate one call in favor of the incoming
8657 * emergency call */
8658testcase TC_emerg_premption() runs on test_CT {
8659 var ASP_RSL_Unitdata rsl_ud;
8660 var integer i;
8661 var integer chreq_total, chreq_nochan;
8662 var RSL_Message rx_rsl;
8663 var RslChannelNr chan_nr;
8664
8665 f_init(1);
8666 f_sleep(1.0);
8667
8668 f_vty_allow_emerg_msc(true);
8669 f_vty_allow_emerg_bts(true, 0);
8670
8671 /* Fill up all channels on the BTS */
8672 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
8673 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
8674 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS; i := i+1) {
8675 chan_nr := f_chreq_act_ack('33'O, i);
8676 }
8677 IPA_RSL[0].clear;
8678 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
8679 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
8680
8681 /* Send Channel request for emegergency call */
8682 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
8683
8684 /* Expect the BSC to release one (the first) TCH/F on the BTS */
8685 chan_nr := valueof(t_RslChanNr_Bm(1));
8686 f_expect_chan_rel(0, chan_nr, expect_rr_chan_rel := false, expect_rll_rel_req := false);
8687
8688 /* Expect the BSC to send activate/assign the a channel for the emergency call */
8689 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8690 chan_nr := rx_rsl.ies[0].body.chan_nr;
8691 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 33));
8692 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Philipp Maier104f4c02020-09-11 18:12:18 +02008693
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008694 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008695}
8696
8697/* Hopping parameters per a timeslot */
Vadim Yanitskiybc6654a2020-09-13 01:27:40 +07008698private type record length(0..64) of GsmArfcn ArfcnList;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008699private type record FHParamsTs {
8700 boolean enabled,
8701 uint6_t hsn,
8702 uint6_t maio,
8703 ArfcnList ma
8704};
8705
8706/* Hopping parameters per a transceiver */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008707private type record FHParamsTrx {
Philipp Maier798d8952021-10-19 14:43:19 +02008708 GsmBandArfcn arfcn,
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008709 FHParamsTs ts[8]
8710};
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008711
8712/* Randomly generate the hopping parameters for the given timeslot numbers */
8713private function f_TC_fh_params_gen(template integer tr_tn := (1, 3, 5))
8714runs on test_CT return FHParamsTrx {
8715 var FHParamsTrx fhp;
8716
Philipp Maier798d8952021-10-19 14:43:19 +02008717 /* Generate a random ARFCN in the range of 0 - 3. This ARFCN will
8718 * fall in the GSM900 band. */
8719 fhp.arfcn.arfcn := f_rnd_int(3);
8720 fhp.arfcn.pcs := false;
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008721
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008722 for (var integer tn := 0; tn < 8; tn := tn + 1) {
8723 if (not match(tn, tr_tn)) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008724 fhp.ts[tn].enabled := false;
8725 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008726 continue;
8727 }
8728
8729 /* Random HSN / MAIO values: 0..63 */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008730 fhp.ts[tn].hsn := f_rnd_int(64);
8731 fhp.ts[tn].maio := f_rnd_int(64);
8732 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008733
8734 /* Random Mobile Allocation (hopping channels) */
8735 var integer ma_len := 2 + f_rnd_int(9); /* 2..10 channels */
8736 var integer step := 3 + f_rnd_int(4); /* 3..6 stepping */
8737 for (var integer i := 1; i <= ma_len; i := i + 1) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008738 fhp.ts[tn].ma := fhp.ts[tn].ma & { i * step };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008739 }
8740
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008741 fhp.ts[tn].enabled := true;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008742 }
8743
8744 log("f_TC_fh_params_gen(): ", fhp);
8745 return fhp;
8746}
8747
8748/* Make sure that the given Channel Description IE matches the hopping configuration */
8749private function f_TC_fh_params_match_chan_desc(in FHParamsTrx fhp, in ChannelDescription cd)
8750{
8751 var template (present) ChannelDescription tr_cd;
8752 var template (present) MaioHsn tr_maio_hsn;
8753 var uint3_t tn := cd.chan_nr.tn;
8754
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008755 if (fhp.ts[tn].enabled) {
8756 tr_maio_hsn := tr_HsnMaio(fhp.ts[tn].hsn, fhp.ts[tn].maio);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008757 tr_cd := tr_ChanDescH1(cd.chan_nr, tr_maio_hsn);
8758 } else {
Philipp Maier798d8952021-10-19 14:43:19 +02008759 tr_cd := tr_ChanDescH0(cd.chan_nr, fhp.arfcn.arfcn);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008760 }
8761
8762 if (not match(cd, tr_cd)) {
8763 setverdict(fail, "Channel Description IE does not match: ",
8764 cd, " vs expected ", tr_cd);
8765 }
8766}
8767
8768/* Make sure that the given Mobile Allocation IE matches the hopping configuration */
8769private function f_TC_fh_params_match_ma(in FHParamsTrx fhp, uint3_t tn,
8770 in MobileAllocationLV ma)
8771{
8772 var template MobileAllocationLV tr_ma := f_TC_fh_params_gen_tr_ma(fhp, tn, ma);
8773
8774 if (not match(ma, tr_ma)) {
8775 setverdict(fail, "Mobile Allocation IE does not match (tn := ",
8776 tn, "): ", ma, " vs expected: ", tr_ma);
8777 } else {
8778 setverdict(pass);
8779 }
8780}
8781
8782private function f_TC_fh_params_gen_tr_ma(in FHParamsTrx fhp, uint3_t tn,
8783 in MobileAllocationLV ma)
8784return template MobileAllocationLV {
8785 /* Mobile Allocation IE is expected to be empty if hopping is not enabled */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008786 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008787 return { len := 0, ma := ''B };
8788 }
8789
8790 var bitstring full_mask := f_pad_bit(''B, 1024, '0'B);
8791 var bitstring slot_mask := f_pad_bit(''B, 1024, '0'B);
8792 var bitstring ma_mask := ''B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008793
8794 /* Compose the full bit-mask (all channels, up to 1024 entries) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008795 for (var integer i := 0; i < lengthof(fhp.ts); i := i + 1) {
8796 for (var integer j := 0; j < lengthof(fhp.ts[i].ma); j := j + 1) {
8797 if (full_mask[fhp.ts[i].ma[j]] == '1'B)
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008798 { continue; }
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008799 full_mask[fhp.ts[i].ma[j]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008800 }
8801 }
8802
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008803 /* Take ARFCN of the TRX itself into account */
Philipp Maier798d8952021-10-19 14:43:19 +02008804 full_mask[fhp.arfcn.arfcn] := '1'B;
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008805
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008806 /* Compose a bit-mask for the given timeslot number */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008807 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
8808 slot_mask[fhp.ts[tn].ma[i]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008809 }
8810
8811 /* Finally, compose the Mobile Allocation bit-mask */
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07008812 for (var integer i := 1; i < lengthof(full_mask); i := i + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008813 if (full_mask[i] != '1'B)
8814 { continue; }
8815
8816 /* FIXME: ma_mask := ma_mask & slot_mask[i]; // triggers a bug in TITAN */
8817 if (slot_mask[i] == '1'B) {
8818 ma_mask := ma_mask & '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008819 } else {
8820 ma_mask := ma_mask & '0'B;
8821 }
8822 }
8823
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07008824 /* ARFCN 0 (if present) goes to the last position of the bit-mask */
8825 if (full_mask[0] == '1'B) {
8826 /* FIXME: ma_mask := ma_mask & slot_mask[0]; // triggers a bug in TITAN */
8827 if (slot_mask[0] == '1'B) {
8828 ma_mask := ma_mask & '1'B;
8829 } else {
8830 ma_mask := ma_mask & '0'B;
8831 }
8832 }
8833
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008834 /* Ensure that ma_mask is octet-aligned */
Vadim Yanitskiy2aa02522020-09-06 14:05:23 +07008835 var integer ma_mask_len := (lengthof(ma_mask) + 8 - 1) / 8;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008836 ma_mask := f_pad_bit(ma_mask, ma_mask_len * 8, '0'B);
8837
8838 return { len := ma_mask_len, ma := ma_mask };
8839}
8840
Philipp Maier798d8952021-10-19 14:43:19 +02008841/* Configure the appropriate band for a given arfcn, exc */
8842private function f_TC_set_band_by_arfcn(integer bts_nr, GsmBandArfcn arfcn) runs on test_CT
8843{
8844 var charstring band;
8845 var GsmBandArfcn arfcn_ := valueof(ts_GsmBandArfcn(arfcn.arfcn, arfcn.pcs, false));
8846
8847 select (arfcn_) {
8848 case (tr_GsmBandArfcn((259..293), false, ?)) { band := "GSM450"; }
8849 case (tr_GsmBandArfcn((306..340), false, ?)) { band := "GSM480"; }
8850 case (tr_GsmBandArfcn((438..511), false, ?)) { band := "GSM750"; }
8851 case (tr_GsmBandArfcn((128..251), false, ?)) { band := "GSM850"; }
8852 case (tr_GsmBandArfcn((0..124), false, ?)) { band := "GSM900"; }
8853 case (tr_GsmBandArfcn((955..1023), false, ?)) { band := "GSM900"; }
8854 case (tr_GsmBandArfcn((512..885), false, ?)) { band := "DCS1800"; }
8855 case (tr_GsmBandArfcn((512..810), true, ?)) { band := "PCS1900"; }
8856 case else { return; }
8857 }
8858
8859 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8860 f_vty_transceive(BSCVTY, "band " & band);
8861 f_vty_transceive(BSCVTY, "end");
8862}
8863
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008864/* Configure the hopping parameters in accordance with the given record */
8865private function f_TC_fh_params_set(in FHParamsTrx fhp,
8866 uint8_t bts_nr := 0,
8867 uint8_t trx_nr := 0)
8868runs on test_CT {
Philipp Maier798d8952021-10-19 14:43:19 +02008869
8870 f_TC_set_band_by_arfcn(bts_nr, fhp.arfcn);
8871
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008872 /* Enter the configuration node for the given BTS/TRX numbers */
8873 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
8874
Philipp Maier798d8952021-10-19 14:43:19 +02008875 f_vty_transceive(BSCVTY, "arfcn " & int2str(fhp.arfcn.arfcn));
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008876
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008877 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008878 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
8879
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008880 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008881 f_vty_transceive(BSCVTY, "hopping enabled 0");
8882 f_vty_transceive(BSCVTY, "exit"); /* go back */
8883 continue;
8884 }
8885
8886 /* Configure HSN / MAIO values */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008887 f_vty_transceive(BSCVTY, "hopping sequence-number " & int2str(fhp.ts[tn].hsn));
8888 f_vty_transceive(BSCVTY, "hopping maio " & int2str(fhp.ts[tn].maio));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008889
8890 /* Configure the Mobile Allocation (hopping channels) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008891 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
8892 f_vty_transceive(BSCVTY, "hopping arfcn add " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008893 }
8894
8895 f_vty_transceive(BSCVTY, "hopping enabled 1");
8896 f_vty_transceive(BSCVTY, "exit"); /* go back */
8897 }
8898
8899 f_vty_transceive(BSCVTY, "end");
8900}
8901
8902/* Disable frequency hopping on all timeslots */
8903private function f_TC_fh_params_unset(in FHParamsTrx fhp,
8904 uint8_t bts_nr := 0,
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008905 uint8_t trx_nr := 0,
Philipp Maier798d8952021-10-19 14:43:19 +02008906 GsmBandArfcn arfcn := {pcs := false, arfcn := 871})
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008907runs on test_CT {
Philipp Maier798d8952021-10-19 14:43:19 +02008908
8909 f_TC_set_band_by_arfcn(bts_nr, arfcn);
8910
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008911 /* Enter the configuration node for the given BTS/TRX numbers */
8912 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
8913
Philipp Maier798d8952021-10-19 14:43:19 +02008914 f_vty_transceive(BSCVTY, "arfcn " & int2str(arfcn.arfcn));
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008915
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008916 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008917 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
8918
8919 /* Delete all ARFCNs from the Mobile Allocation (if any) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008920 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
8921 f_vty_transceive(BSCVTY, "hopping arfcn del " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008922 }
8923
8924 f_vty_transceive(BSCVTY, "hopping enabled 0");
8925 f_vty_transceive(BSCVTY, "exit"); /* go back */
8926 }
8927
8928 f_vty_transceive(BSCVTY, "end");
8929 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8930}
8931
8932/* Verify presence and correctness of the hopping parameters (HSN, MAIO)
8933 * in the Channel Identification IE of the RSL CHANnel ACTIVation message. */
8934testcase TC_fh_params_chan_activ() runs on test_CT {
8935 var FHParamsTrx fhp := f_TC_fh_params_gen();
8936 var RSL_Message rsl_msg;
8937 var RSL_IE_Body ie;
8938
8939 f_init_vty();
8940
8941 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
8942 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8943
8944 f_init(1);
8945
8946 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
8947 for (var integer i := 0; i < 9; i := i + 1) {
8948 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
8949 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8950
8951 /* Make sure that Channel Identification IE is present */
8952 if (not f_rsl_find_ie(rsl_msg, RSL_IE_CHAN_IDENT, ie)) {
8953 setverdict(fail, "RSL Channel Identification IE is absent");
8954 continue;
8955 }
8956
8957 /* Make sure that hopping parameters (HSN/MAIO) match */
8958 f_TC_fh_params_match_chan_desc(fhp, ie.chan_ident.ch_desc.v);
8959
8960 /* "Mobile Allocation shall be included but empty" - let's check this */
8961 if (ie.chan_ident.ma.v.len != 0) {
8962 setverdict(fail, "Mobile Allocation IE is not empty: ",
8963 ie.chan_ident.ma, ", despite it shall be");
8964 continue;
8965 }
8966 }
8967
8968 /* Disable frequency hopping */
8969 f_TC_fh_params_unset(fhp);
8970
Vadim Yanitskiy21726312020-09-04 01:45:36 +07008971 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008972}
8973
8974/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Immediate Assignment */
8975testcase TC_fh_params_imm_ass() runs on test_CT {
8976 var FHParamsTrx fhp := f_TC_fh_params_gen();
8977 var RSL_Message rsl_msg;
8978 var RSL_IE_Body ie;
8979
8980 f_init_vty();
8981
8982 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
8983 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8984
8985 f_init(1);
8986
8987 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
8988 for (var integer i := 0; i < 9; i := i + 1) {
8989 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
8990 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8991
8992 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
8993 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
8994
8995 /* Make sure that Full Immediate Assign Info IE is present */
8996 if (not f_rsl_find_ie(rsl_msg, RSL_IE_FULL_IMM_ASS_INFO, ie)) {
8997 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
8998 continue;
8999 }
9000
9001 /* Decode the actual Immediate Assignment message */
9002 var GsmRrMessage rr_msg := dec_GsmRrMessage(ie.full_imm_ass_info.payload);
9003 if (not match(rr_msg.header, t_RrHeader(IMMEDIATE_ASSIGNMENT, ?))) {
9004 setverdict(fail, "Failed to match Immediate Assignment: ", rr_msg);
9005 continue;
9006 }
9007
9008 /* Make sure that hopping parameters (HSN/MAIO) match */
9009 f_TC_fh_params_match_chan_desc(fhp, rr_msg.payload.imm_ass.chan_desc);
9010
9011 /* Make sure that the Mobile Allocation IE matches */
9012 f_TC_fh_params_match_ma(fhp, rr_msg.payload.imm_ass.chan_desc.chan_nr.tn,
9013 rr_msg.payload.imm_ass.mobile_allocation);
9014 }
9015
9016 /* Disable frequency hopping */
9017 f_TC_fh_params_unset(fhp);
Philipp Maier82812002020-08-13 18:48:27 +02009018
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009019 f_shutdown_helper();
Philipp Maier82812002020-08-13 18:48:27 +02009020}
9021
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009022/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Assignment Command */
9023testcase TC_fh_params_assignment_cmd() runs on test_CT {
9024 var FHParamsTrx fhp := f_TC_fh_params_gen();
9025 var RSL_Message rsl_msg;
9026 var RSL_IE_Body ie;
9027
9028 f_init_vty();
9029
9030 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9031 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9032
9033 f_init(1);
9034
9035 /* HACK: work around "Couldn't find Expect for CRCX" */
9036 vc_MGCP.stop;
9037
9038 var template PDU_BSSAP ass_cmd := f_gen_ass_req();
9039 ass_cmd.pdu.bssmap.assignmentRequest.codecList := ts_BSSMAP_IE_CodecList({ts_CodecFR});
9040
9041 /* CS domain (TCH): 4 (TCH/F) + 2 (TCH/H) channels available
9042 * NOTE: only 3 SDCCH/4 channels are available on CCCH+SDCCH4+CBCH */
9043 for (var integer i := 0; i < 3; i := i + 1) {
9044 /* Establish a dedicated channel, so we can trigger (late) TCH assignment */
9045 var DchanTuple dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
9046
9047 /* Send a BSSMAP Assignment Command, expect CHANnel ACTIVation */
9048 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
9049 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9050
9051 /* ACKnowledge CHANnel ACTIVation, expect RSL DATA REQuest */
9052 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9053 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
9054
9055 /* Make sure that L3 Information IE is present */
9056 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
9057 setverdict(fail, "RSL L3 Information IE is absent");
9058 continue;
9059 }
9060
9061 /* Decode the L3 message and make sure it is (RR) Assignment Command */
9062 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
9063 if (not match(l3_msg.header, t_RrL3Header(ASSIGNMENT_COMMAND))) {
9064 setverdict(fail, "Failed to match Assignment Command: ", l3_msg);
9065 continue;
9066 }
9067
9068 /* Make sure that hopping parameters (HSN/MAIO) match */
9069 var ChannelDescription chan_desc := l3_msg.payload.ass_cmd.chan_desc;
9070 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9071
9072 /* Make sure that Cell Channel Description IE is present if FH is enabled */
9073 if (chan_desc.h and not ispresent(l3_msg.payload.ass_cmd.cell_chan_desc)) {
Vadim Yanitskiy38d069d2020-09-02 17:18:57 +07009074 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009075 continue;
9076 }
9077
9078 /* Make sure that the Mobile Allocation IE matches (if present) */
9079 var boolean ma_present := ispresent(l3_msg.payload.ass_cmd.mobile_allocation);
9080 if (chan_desc.h and ma_present) {
9081 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9082 l3_msg.payload.ass_cmd.mobile_allocation.v);
9083 } else if (chan_desc.h and not ma_present) {
9084 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9085 continue;
9086 } else if (not chan_desc.h and ma_present) {
9087 setverdict(fail, "FH disabled, but Mobile Allocation IE is present");
9088 continue;
9089 }
9090 }
9091
9092 /* Give the IUT some time to release all channels */
9093 f_sleep(3.0);
9094
9095 /* Disable frequency hopping */
9096 f_TC_fh_params_unset(fhp);
9097
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009098 f_shutdown_helper();
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009099}
9100
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009101/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Handover Command */
9102private function f_TC_fh_params_handover_cmd(in FHParamsTrx fhp)
9103runs on test_CT {
9104 var RSL_Message rsl_msg;
9105 var RSL_IE_Body ie;
9106 var DchanTuple dt;
9107
9108 /* Establish a dedicated channel, so we can trigger handover */
9109 dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
Vadim Yanitskiyc18ff472021-11-18 20:15:37 +03009110 f_sleep(0.5);
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009111
9112 /* Trigger handover from BTS0 to BTS1 */
9113 f_bts_0_cfg(BSCVTY, { "neighbor bts 1" });
9114 f_vty_handover(BSCVTY, 0, 0, dt.rsl_chan_nr, 1);
9115
9116 /* Expect RSL CHANnel ACTIVation on BTS1/TRX0/TS1 */
9117 rsl_msg := f_exp_ipa_rx(1, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9118
9119 /* ACKnowledge channel activation and expect (RR) Handover Command */
9120 f_ipa_tx(1, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9121 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
9122
9123 /* Make sure that L3 Information IE is present */
9124 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
9125 setverdict(fail, "RSL L3 Information IE is absent");
9126 return;
9127 }
9128
9129 /* Decode the L3 message and make sure it is (RR) Handover Command */
9130 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
9131 if (not match(l3_msg.header, t_RrL3Header(HANDOVER_COMMAND))) {
9132 setverdict(fail, "Failed to match Handover Command: ", l3_msg);
9133 return;
9134 }
9135
9136 /* Make sure that we've got SDCCH/8 on TS1 (expected to be hopping) */
9137 var ChannelDescription chan_desc := l3_msg.payload.ho_cmd.chan_desc;
9138 if (not match(chan_desc.chan_nr, t_RslChanNr_SDCCH8(1, ?))) {
9139 setverdict(fail, "Unexpected channel number: ", chan_desc.chan_nr);
9140 return;
9141 }
9142
9143 /* Make sure that hopping parameters (HSN/MAIO) match */
9144 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9145
9146 /* Make sure that Cell Channel Description IE is present */
9147 if (not ispresent(l3_msg.payload.ho_cmd.cell_chan_desc)) {
9148 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
9149 return;
9150 }
9151
9152 /* Make sure that the Mobile Allocation (after time) IE is present and matches */
9153 var boolean ma_present := ispresent(l3_msg.payload.ho_cmd.mobile_allocation);
9154 if (ma_present) {
9155 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9156 l3_msg.payload.ho_cmd.mobile_allocation.v);
9157 } else {
9158 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9159 return;
9160 }
9161}
9162testcase TC_fh_params_handover_cmd() runs on test_CT {
9163 var FHParamsTrx fhp := f_TC_fh_params_gen();
9164
9165 f_init_vty();
9166
9167 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8 on BTS1/TRX0 */
9168 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
9169
9170 f_vty_transceive(BSCVTY, "timeslot 0");
9171 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
9172 f_vty_transceive(BSCVTY, "exit"); /* go back */
9173
9174 f_vty_transceive(BSCVTY, "timeslot 1");
9175 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8");
9176 f_vty_transceive(BSCVTY, "end"); /* we're done */
9177
9178 f_TC_fh_params_set(fhp, 1); /* Enable frequency hopping on BTS1 */
9179 f_vty_transceive(BSCVTY, "drop bts connection 1 oml");
9180
9181 f_init(2);
9182
9183 f_TC_fh_params_handover_cmd(fhp);
9184
9185 /* Disable frequency hopping on BTS1 */
9186 f_TC_fh_params_unset(fhp, 1);
9187
9188 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
9189 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
9190
9191 f_vty_transceive(BSCVTY, "timeslot 0");
9192 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
9193 f_vty_transceive(BSCVTY, "exit"); /* go back */
9194
9195 f_vty_transceive(BSCVTY, "timeslot 1");
9196 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
9197 f_vty_transceive(BSCVTY, "end"); /* we're done */
9198
9199 f_shutdown_helper();
9200}
9201
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009202/* Verify the hopping parameters in System Information Type 4 */
9203testcase TC_fh_params_si4_cbch() runs on test_CT {
9204 var FHParamsTrx fhp := f_TC_fh_params_gen(tr_tn := 1);
9205 var ASP_RSL_Unitdata rx_rsl_ud;
9206 timer T := 5.0;
9207
9208 f_init_vty();
9209
9210 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8+CBCH */
9211 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
9212
9213 f_vty_transceive(BSCVTY, "timeslot 0");
9214 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
9215 f_vty_transceive(BSCVTY, "exit"); /* go back */
9216
9217 f_vty_transceive(BSCVTY, "timeslot 1");
9218 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8+cbch");
9219 f_vty_transceive(BSCVTY, "end"); /* we're done */
9220
9221 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9222 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9223
9224 f_init(1);
9225
9226 T.start;
9227 alt {
9228 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO(RSL_SYSTEM_INFO_4))) -> value rx_rsl_ud {
9229 var RSL_IE_Body ie := rx_rsl_ud.rsl.ies[2].body; /* FULL BCCH Information IE */
9230 var SystemInformation si := dec_SystemInformation(ie.other.payload);
9231
9232 /* Make sure that what we decoded is System Information Type 4 */
9233 if (si.header.message_type != SYSTEM_INFORMATION_TYPE_4) {
9234 setverdict(fail, "RSL FULL BCCH Information IE contains: ", si);
9235 repeat;
9236 }
9237
9238 /* Make sure that CBCH Channel Description IE is present */
9239 if (not ispresent(si.payload.si4.cbch_chan_desc)) {
9240 setverdict(fail, "CBCH Channel Description IE is absent");
9241 break;
9242 }
9243
9244 /* Finally, check the hopping parameters (HSN, MAIO) */
9245 var ChannelDescription chan_desc := si.payload.si4.cbch_chan_desc.v;
9246 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9247
9248 /* 3GPP TS 44.018, section 9.1.36.2 "CBCH Mobile Allocation":
9249 * The CBCH Mobile Allocation IE *shall* be present if FH is enabled. */
9250 if (chan_desc.h and not ispresent(si.payload.si4.cbch_mobile_alloc)) {
9251 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9252 break;
9253 } else if (chan_desc.h and ispresent(si.payload.si4.cbch_mobile_alloc)) {
9254 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9255 si.payload.si4.cbch_mobile_alloc.v);
9256 }
9257 }
9258 [] IPA_RSL[0].receive { repeat; }
9259 [] T.timeout {
9260 setverdict(fail, "Timeout waiting for RSL BCCH INFOrmation (SI4)");
9261 }
9262 }
9263
9264 /* Disable frequency hopping */
9265 f_TC_fh_params_unset(fhp);
9266
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07009267 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009268 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
9269
9270 f_vty_transceive(BSCVTY, "timeslot 0");
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07009271 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009272 f_vty_transceive(BSCVTY, "exit"); /* go back */
9273
9274 f_vty_transceive(BSCVTY, "timeslot 1");
9275 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
9276 f_vty_transceive(BSCVTY, "end"); /* we're done */
9277
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009278 f_shutdown_helper();
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009279}
9280
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009281template (value) PDU_BSSAP_LE ts_BSSMAP_LE_BSSLAP(template (value) BSSLAP_PDU bsslap)
9282 := ts_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, data := enc_BSSLAP_PDU(valueof(bsslap)));
9283
9284private function f_match_bsslap(PDU_BSSAP_LE got_bsslap_msg,
9285 template (present) BSSLAP_PDU expect_bsslap)
9286{
9287 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(got_bsslap_msg.pdu.bssmap.co_info.bsslap_apdu.data);
9288 if (not match(bsslap, expect_bsslap)) {
9289 log("EXPECTING BSSLAP: ", expect_bsslap);
9290 log("GOT BSSLAP: ", bsslap);
9291 setverdict(fail, "BSSLAP is not as expected");
9292 mtc.stop;
9293 }
9294 setverdict(pass);
9295}
9296
9297/* GAD: this is an Ellipsoid point with uncertainty circle, encoded as in 3GPP TS 23.032 §7.3.2. */
9298const octetstring gad_ell_point_unc_circle := '10b0646d0d5f6627'O;
9299
9300private function f_expect_bsslap(template (present) BSSLAP_PDU expect_rx_bsslap) runs on MSC_ConnHdlr {
9301 var PDU_BSSAP_LE rx_bsslap;
9302 BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap);
9303 f_match_bsslap(rx_bsslap, expect_rx_bsslap);
9304}
9305
9306/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9307 * Request on Lb interface. Either with or without the SMLC doing a BSSLAP TA Request. */
9308private function f_lcs_loc_req_for_active_ms(boolean do_ta_request := false) runs on MSC_ConnHdlr {
9309 f_sleep(1.0);
9310
9311 f_establish_fully(omit, omit);
9312 f_bssap_le_register_imsi(g_pars.imsi, omit);
9313
9314 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9315 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9316
9317 var PDU_BSSAP_LE plr;
9318 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9319
9320 if (not do_ta_request) {
9321 /* verify TA Layer 3 in APDU. First the APDU type (BSSLAP), then the BSSLAP data contents. */
9322 var template BSSMAP_LE_IE_APDU expect_apdu := tr_BSSMAP_LE_APDU(BSSMAP_LE_PROT_BSSLAP, ?);
9323 if (not match(plr.pdu.bssmap.perf_loc_req.bsslap_apdu, expect_apdu)) {
9324 log("EXPECTING BSSMAP-LE APDU IE ", expect_apdu);
9325 log("GOT BSSMAP-LE APDU IE ", plr.pdu.bssmap.perf_loc_req.bsslap_apdu);
9326 setverdict(fail, "BSSMAP-LE APDU IE is not as expected");
9327 mtc.stop;
9328 }
9329 var template BSSLAP_PDU expect_ta_layer3 := tr_BSSLAP_TA_Layer3(tr_BSSLAP_IE_TA(0));
9330 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(plr.pdu.bssmap.perf_loc_req.bsslap_apdu.data);
9331 if (not match(bsslap, expect_ta_layer3)) {
9332 log("EXPECTING BSSLAP TA Layer 3: ", expect_ta_layer3);
9333 log("GOT BSSLAP: ", bsslap);
9334 setverdict(fail, "BSSLAP is not as expected");
9335 mtc.stop;
9336 }
9337 /* OsmoBSC directly sent the TA as BSSLAP APDU in the BSSMAP-LE Perform Location Request to the SMLC. The SMLC
9338 * has no need to request the TA from the BSC and directly responds. */
9339 } else {
9340 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9341 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9342 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9343 }
9344
9345 /* SMLC got the TA from the BSC, now responds with geo information data. */
9346 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9347 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9348 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9349
9350 /* The LCS was using an active A-interface conn. It should still remain active after this. */
9351 f_mo_l3_transceive();
9352
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009353 f_perform_clear();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009354
9355 f_sleep(2.0);
9356 setverdict(pass);
9357}
9358
9359/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9360 * Request on Lb interface. Without the SMLC doing a BSSLAP TA Request. */
9361private function f_tc_lcs_loc_req_for_active_ms(charstring id) runs on MSC_ConnHdlr {
9362 f_lcs_loc_req_for_active_ms(false);
9363}
9364testcase TC_lcs_loc_req_for_active_ms() runs on test_CT {
9365 var MSC_ConnHdlr vc_conn;
9366 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9367
9368 f_init(1, true);
9369 f_sleep(1.0);
9370 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms), pars);
9371 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009372 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009373}
9374
9375/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9376 * Request on Lb interface. With the SMLC doing a BSSLAP TA Request. */
9377private function f_tc_lcs_loc_req_for_active_ms_ta_req(charstring id) runs on MSC_ConnHdlr {
9378 f_lcs_loc_req_for_active_ms(true);
9379}
9380testcase TC_lcs_loc_req_for_active_ms_ta_req() runs on test_CT {
9381 var MSC_ConnHdlr vc_conn;
9382 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9383
9384 f_init(1, true);
9385 f_sleep(1.0);
9386 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_ta_req), pars);
9387 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009388 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009389}
9390
9391/* Clear the A-interface conn only, without doing anything on Abis. Useful for LCS, for cases where there is only an A
9392 * conn without an active lchan. */
9393private function f_clear_A_conn() runs on MSC_ConnHdlr
9394{
9395 var BssmapCause cause := 0;
9396 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
9397 BSSAP.receive(tr_BSSMAP_ClearComplete);
9398 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
9399
9400 timer no_more_bssap := 5.0;
9401 no_more_bssap.start;
9402 alt {
9403 [] no_more_bssap.timeout { break; }
9404 [] BSSAP.receive(tr_BSSAP_BSSMAP) {
9405 setverdict(fail, "Expected no more BSSAP after Clear Complete");
9406 mtc.stop;
9407 }
9408 }
9409 setverdict(pass);
9410}
9411
9412/* Verify that the A-interface connection is still working, and then clear it, without doing anything on Abis. Useful
9413 * for LCS, for cases where there is only an A conn without an active lchan. */
9414private function f_verify_active_A_conn_and_clear() runs on MSC_ConnHdlr
9415{
9416 f_logp(BSCVTY, "f_verify_active_A_conn_and_clear: test A link, then clear");
9417
9418 /* When an lchan is active, we can send some L3 data from the BTS side and verify that it shows up on the other
9419 * side towards the MSC. When there is no lchan, this is not possible. To probe whether the A-interface
9420 * connection is still up, we need something that echos back on the A-interface. Another LCS request! */
9421 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9422 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9423 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?));
9424
9425 /* Right, the Perform Location Request showed up on Lb, now we can clear the A conn. */
9426 f_clear_A_conn();
9427 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
9428 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9429}
9430
9431/* With *no* active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9432 * Request on Lb interface. BSC will Page for the subscriber as soon as we (virtual SMLC) request the TA via BSSLAP.
9433 */
9434private function f_tc_lcs_loc_req_for_idle_ms(charstring id) runs on MSC_ConnHdlr {
9435 f_sleep(1.0);
9436
9437 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9438 f_bssap_le_register_imsi(g_pars.imsi, omit);
9439
9440 /* Register to receive the Paging Command */
9441 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9442 g_chan_nr := new_chan_nr;
9443 f_rslem_register(0, g_chan_nr);
9444
9445 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9446 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9447 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9448 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9449
9450 var PDU_BSSAP_LE plr;
9451 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9452
9453 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9454 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9455
9456 /* OsmoBSC needs to Page */
9457 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi)));
9458 f_logp(BSCVTY, "got Paging Command");
9459
9460 /* MS requests channel. Since the Paging was for LCS, the Paging Response does not trigger a Complete Layer 3 to
9461 * the MSC, and releases the lchan directly. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009462 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);
9463 f_expect_lchan_rel(RSL, RSL_PROC);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009464
9465 /* From the Paging Response, the TA is now known to the BSC, and it responds to the SMLC. */
9466
9467 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9468
9469 /* SMLC got the TA from the BSC, now responds with geo information data. */
9470 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9471 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9472
9473 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9474
9475 /* The lchan is gone, the A-interface conn was created for the LCS only.
9476 * Still it is clearly the MSC's job to decide whether to tear down the conn or not. */
9477 f_verify_active_A_conn_and_clear();
9478
9479 f_sleep(2.0);
9480 setverdict(pass);
9481}
9482testcase TC_lcs_loc_req_for_idle_ms() runs on test_CT {
9483 var MSC_ConnHdlr vc_conn;
9484 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9485
9486 f_init(1, true);
9487 f_sleep(1.0);
9488
9489 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9490 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9491
9492 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms), pars);
9493 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009494 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009495}
9496
9497/* With no active lchan, start BSSMAP Perform Location Request on A interface, but omit IMSI; expect failure response.
9498 */
9499private function f_tc_lcs_loc_req_no_subscriber(charstring id) runs on MSC_ConnHdlr {
9500 f_sleep(1.0);
9501
9502 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9503 f_bssap_le_register_imsi(g_pars.imsi, omit);
9504
9505 /* provoke an abort by omitting both IMSI and IMEI */
9506 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9507 valueof(ts_BSSMAP_Perform_Location_Request(omit,
9508 ts_CellId_CGI('262'H, '42'H, 23, 42)))));
9509 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9510
9511 /* BSC tells MSC about failure */
9512 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9513 locationEstimate := omit, positioningData := omit,
9514 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_DATA_MISSING_IN_REQ)));
9515
9516 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9517 f_verify_active_A_conn_and_clear();
9518
9519 f_sleep(2.0);
9520 setverdict(pass);
9521}
9522testcase TC_lcs_loc_req_no_subscriber() runs on test_CT {
9523 var MSC_ConnHdlr vc_conn;
9524 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9525
9526 f_init(1, true);
9527 f_sleep(1.0);
9528
9529 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9530 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9531
9532 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_no_subscriber), pars);
9533 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009534 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009535}
9536
9537/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9538 * BSSMAP-LE Perform Location Response (before or after sending a BSSLAP TA Request) */
9539private function f_lcs_loc_req_for_active_ms_le_timeout(boolean do_ta) runs on MSC_ConnHdlr {
9540 f_sleep(1.0);
9541
9542 f_establish_fully(omit, omit);
9543 f_bssap_le_register_imsi(g_pars.imsi, omit);
9544
9545 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9546 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9547
9548 var PDU_BSSAP_LE plr;
9549 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9550
9551 if (do_ta) {
9552 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9553 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9554 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9555 }
9556
9557 /* SMLC fails to respond, BSC runs into timeout */
9558 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_SYSTEM_FAILURE));
9559 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9560
9561 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9562 locationEstimate := omit, positioningData := omit,
9563 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_SYSTEM_FAILURE)));
9564
9565 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9566 f_verify_active_A_conn_and_clear();
9567
9568 f_sleep(2.0);
9569 setverdict(pass);
9570}
9571
9572/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9573 * BSSMAP-LE Perform Location Response, without sending a BSSLAP TA Request. */
9574private function f_tc_lcs_loc_req_for_active_ms_le_timeout(charstring id) runs on MSC_ConnHdlr {
9575 f_lcs_loc_req_for_active_ms_le_timeout(false);
9576}
9577
9578testcase TC_lcs_loc_req_for_active_ms_le_timeout() runs on test_CT {
9579 var MSC_ConnHdlr vc_conn;
9580 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9581
9582 f_init(1, true);
9583 f_sleep(1.0);
9584 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout), pars);
9585 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009586 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009587}
9588
9589/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9590 * BSSMAP-LE Perform Location Response, after sending a BSSLAP TA Request. */
9591private function f_tc_lcs_loc_req_for_active_ms_le_timeout2(charstring id) runs on MSC_ConnHdlr {
9592 f_lcs_loc_req_for_active_ms_le_timeout(true);
9593}
9594
9595testcase TC_lcs_loc_req_for_active_ms_le_timeout2() runs on test_CT {
9596 var MSC_ConnHdlr vc_conn;
9597 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9598
9599 f_init(1, true);
9600 f_sleep(1.0);
9601 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout2), pars);
9602 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009603 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009604}
9605
9606/* With *no* active lchan, start a Perform Location Request, expecting that the MS will be Paged. */
9607private function f_tc_lcs_loc_req_for_idle_ms_no_pag_resp(charstring id) runs on MSC_ConnHdlr {
9608 f_sleep(1.0);
9609
9610 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9611 f_bssap_le_register_imsi(g_pars.imsi, omit);
9612
9613 /* Register to receive the Paging Command */
9614 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9615 g_chan_nr := new_chan_nr;
9616 f_rslem_register(0, g_chan_nr);
9617
9618 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9619 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9620 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9621 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9622
9623 var PDU_BSSAP_LE plr;
9624 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9625
9626 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9627 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9628
9629 /* OsmoBSC needs to Page */
9630 var PDU_BSSAP_LE rx_bsslap;
9631 alt {
9632 [] RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi))) {
9633 f_logp(BSCVTY, "got Paging Command");
9634 repeat;
9635 }
9636 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
9637 /* MS does not respond to Paging, TA Req runs into timeout. */
9638 f_match_bsslap(rx_bsslap, tr_BSSLAP_Abort(?));
9639 }
9640 }
9641
9642 /* SMLC responds with failure */
9643 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(omit, BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
9644 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9645
9646 /* BSC tells MSC about failure */
9647 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9648 locationEstimate := omit, positioningData := omit,
9649 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_REQUEST_ABORTED)));
9650
9651 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9652 f_verify_active_A_conn_and_clear();
9653
9654 f_sleep(2.0);
9655 setverdict(pass);
9656}
9657testcase TC_lcs_loc_req_for_idle_ms_no_pag_resp() runs on test_CT {
9658 var MSC_ConnHdlr vc_conn;
9659 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9660
9661 f_init(1, true);
9662 f_sleep(1.0);
9663
9664 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9665 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9666
9667 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms_no_pag_resp), pars);
9668 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009669 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009670}
9671
9672/* During an ongoing Location Request, the MS sends a CM Service Request. Expect the same A-conn to be re-used / taken
9673 * over. */
9674private function f_tc_cm_service_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
9675 f_sleep(1.0);
9676
9677 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9678 f_bssap_le_register_imsi(g_pars.imsi, omit);
9679
9680 /* Register to receive the Paging Command */
9681 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9682 g_chan_nr := new_chan_nr;
9683 f_rslem_register(0, g_chan_nr);
9684
9685 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9686 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9687 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9688 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9689
9690 var PDU_BSSAP_LE plr;
9691 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9692
9693 /* As the A-interface conn was established for LCS, the MS coincidentally decides to issue a CM Service Request
9694 * and establish Layer 3. It should use the existing A-interface conn. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009695 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 +02009696 do_clear := false, expect_bssmap_l3 := true);
9697
9698 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9699 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9700
9701 /* OsmoBSC already has an lchan, no need to Page, just returns the TA */
9702 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9703
9704 /* SMLC got the TA from the BSC, now responds with geo information data. */
9705 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9706 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9707 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9708
9709 /* The lchan should still exist, it was from a CM Service Request. */
9710 f_mo_l3_transceive();
9711
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009712 f_perform_clear();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009713
9714 f_sleep(2.0);
9715 setverdict(pass);
9716}
9717testcase TC_cm_service_during_lcs_loc_req() runs on test_CT {
9718 var MSC_ConnHdlr vc_conn;
9719 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9720
9721 f_init(1, true);
9722 f_sleep(1.0);
9723
9724 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9725 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9726
9727 vc_conn := f_start_handler(refers(f_tc_cm_service_during_lcs_loc_req), pars);
9728 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009729 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009730}
9731
9732/* During an ongoing Perform Location Request, do a Handover, an expect a BSSLAP Reset message from the BSC to indicate
9733 * the new lchan after handover. */
9734private function f_tc_ho_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
9735 f_sleep(1.0);
9736
9737 f_establish_fully(omit, omit);
9738 f_bssap_le_register_imsi(g_pars.imsi, omit);
9739
9740 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9741 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9742
9743 var PDU_BSSAP_LE plr;
9744 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9745
9746 /* SMLC ponders the Location Request, in the meantime the BSC decides to handover */
9747 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
9748
9749 var HandoverState hs := {
9750 rr_ho_cmpl_seen := false,
9751 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02009752 old_chan_nr := -,
9753 expect_target_tsc := BTS_TSC[1]
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009754 };
9755 /* issue hand-over command on VTY */
9756 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
9757 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
9758 f_rslem_suspend(RSL1_PROC);
9759
9760 /* From the MGW perspective, a handover is is characterized by
9761 * performing one MDCX operation with the MGW. So we expect to see
9762 * one more MDCX during handover. */
9763 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
9764
9765 alt {
9766 [] as_handover(hs);
9767 }
9768
9769 var PDU_BSSAP_LE rx_bsslap;
9770
9771 interleave {
9772 /* Expect the BSC to inform the MSC about the handover */
9773 [] BSSAP.receive(tr_BSSMAP_HandoverPerformed);
9774
9775 /* Expect the BSC to inform the SMLC about the handover */
9776 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
9777 f_match_bsslap(rx_bsslap, tr_BSSLAP_Reset(BSSLAP_CAUSE_INTRA_BSS_HO));
9778 }
9779 }
9780
9781 /* SMLC now responds with geo information data. */
9782 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9783 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9784 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9785
9786 /* lchan still active */
9787 f_mo_l3_transceive(RSL1);
9788
9789 /* MSC decides it is done now. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009790 f_perform_clear(RSL1, RSL1_PROC);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009791
9792 f_sleep(2.0);
9793 setverdict(pass);
9794}
9795testcase TC_ho_during_lcs_loc_req() runs on test_CT {
9796 var MSC_ConnHdlr vc_conn;
9797 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9798
9799 f_init(2, true);
9800 f_sleep(1.0);
9801 vc_conn := f_start_handler(refers(f_tc_ho_during_lcs_loc_req), pars);
9802 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009803 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009804}
9805
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009806/* Attempt Complete Layer 3 without any MSC available (OS#4832) */
9807private function f_tc_no_msc(charstring id) runs on MSC_ConnHdlr {
9808 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9809
9810 /* Also disable attach for the single connected MSC */
9811 f_vty_msc_allow_attach(BSCVTY, { false });
9812
9813 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) ));
9814 f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
9815
9816 /* No MSC is found, expecting a proper release on RSL */
9817 interleave {
9818 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
9819 f_logp(BSCVTY, "Got RSL RR Release");
9820 }
9821 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
9822 f_logp(BSCVTY, "Got RSL Deact SACCH");
9823 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02009824 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009825 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
9826 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02009827 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009828 }
9829 }
9830 setverdict(pass);
9831}
9832testcase TC_no_msc() runs on test_CT {
9833
9834 f_init(1, true);
9835 f_sleep(1.0);
9836 var MSC_ConnHdlr vc_conn;
9837 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9838
9839 f_ctrs_bsc_init(counternames_bsc_mscpool);
9840
9841 vc_conn := f_start_handler(refers(f_tc_no_msc), pars);
9842 vc_conn.done;
9843
9844 f_ctrs_bsc_add("mscpool:subscr:no_msc");
9845 f_ctrs_bsc_verify();
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009846 f_shutdown_helper();
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009847}
9848
Harald Welte0ea2d5e2018-04-07 21:40:29 +02009849/* Dyn PDCH todo:
9850 * activate OSMO as TCH/F
9851 * activate OSMO as TCH/H
9852 * does the BSC-located PCU socket get the updated INFO?
9853 * what if no PCU is connected at the time?
9854 * is the info correct on delayed PCU (re)connect?
9855 */
Harald Welte94e0c342018-04-07 11:33:23 +02009856
Neels Hofmeyr87857ec2021-04-25 16:17:47 +00009857private function f_TC_refuse_mode_modif_to_vamos(charstring id) runs on MSC_ConnHdlr {
9858 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
9859 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
9860
9861 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
9862 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
9863 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
9864 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
9865 g_pars.ass_codec_list.codecElements[0];
9866 if (isvalue(g_pars.expect_mr_s0_s7)) {
9867 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
9868 g_pars.expect_mr_s0_s7;
9869 }
9870 }
9871 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
9872 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
9873 log("expecting ASS COMPL like this: ", exp_compl);
9874
9875 f_establish_fully(ass_cmd, exp_compl);
9876
Neels Hofmeyr8746b0d2021-06-01 17:25:39 +02009877 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 +00009878
9879 var RSL_Message rsl;
9880
9881 timer T := 5.0;
9882 T.start;
9883 alt {
9884 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
9885 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
9886 log("Rx L3 from net: ", l3);
9887 if (ischosen(l3.msgs.rrm.channelModeModify)) {
9888 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
9889 mtc.stop;
9890 }
9891 }
9892 [] RSL.receive(tr_RSL_MODE_MODIFY_REQ(g_chan_nr, ?)) -> value rsl {
9893 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
9894 mtc.stop;
9895 }
9896 [] T.timeout {
9897 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related Mode Modify should happen. */
9898 setverdict(pass);
9899 }
9900 }
9901 T.stop;
9902}
9903
9904/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel Mode Modify to VAMOS mode is refused by
9905 * osmo-bsc. */
9906testcase TC_refuse_mode_modif_to_vamos() runs on test_CT {
9907 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9908 var MSC_ConnHdlr vc_conn;
9909
9910 f_init(1, true);
9911 f_sleep(1.0);
9912
9913 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
9914 vc_conn := f_start_handler(refers(f_TC_refuse_mode_modif_to_vamos), pars);
9915 vc_conn.done;
9916 f_shutdown_helper();
9917}
9918
9919/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel activation to VAMOS mode is refused by osmo-bsc.
9920 */
9921testcase TC_refuse_chan_act_to_vamos() runs on test_CT {
9922 f_init_vty();
9923
9924 f_init(1, false);
9925 f_sleep(1.0);
9926
9927 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 activate-vamos fr");
9928
9929 var ASP_RSL_Unitdata rx_rsl_ud;
9930 timer T := 5.0;
9931
9932 T.start;
9933 alt {
9934 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(?, IPAC_PROTO_RSL_TRX0)) -> value rx_rsl_ud {
9935 if (rx_rsl_ud.rsl.msg_type == RSL_MT_CHAN_ACTIV) {
9936 T.stop;
9937 setverdict(fail, "CHANnel ACTivate in VAMOS mode succeeded even though BTS does not support VAMOS");
9938 mtc.stop;
9939 }
9940 repeat;
9941 }
9942 [] T.timeout {
9943 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related CHANnel ACTivate should happen. */
9944 setverdict(pass);
9945 }
9946 }
9947}
9948
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009949private function f_TC_reassignment_codec(charstring id) runs on MSC_ConnHdlr {
9950 /* First fully set up a speech lchan */
9951 f_TC_assignment_codec(id);
9952
9953 /* Trigger re-assignment to another lchan */
9954 var AssignmentState assignment_st := valueof(ts_AssignmentStateInit);
9955
9956 /* Re-Assignment should tell the MGW endpoint the new lchan's RTP address and port, so expecting to see exactly
9957 * one MDCX on MGCP. */
9958 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].mdcx_seen_exp + 1;
9959
9960 /* The new lchan will see all-new IPAC_CRCX and IPAC_MDCX messages telling the BTS the same RTP address and port
9961 * as the old lchan used. */
9962 g_media.bts.ipa_crcx_seen := false;
9963 g_media.bts.ipa_mdcx_seen := false;
9964
9965 /* Send different BTS side RTP port number for the new lchan */
9966 g_media.bts.bts.port_nr := 4223;
9967
9968 f_rslem_register(0, valueof(ts_RslChanNr_Bm(2))); /* <-- FIXME: can we somehow infer the timeslot that will be used? */
9969
9970 /* Trigger re-assignment. */
9971 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot " & int2str(g_chan_nr.tn) & " sub-slot 0 assignment");
9972
9973 timer T := 5.0;
9974 T.start;
9975 alt {
9976 [] as_assignment(assignment_st);
9977 [] as_Media();
9978 [] T.timeout {
9979 break;
9980 }
9981 }
9982
9983 if (not assignment_st.assignment_done) {
9984 setverdict(fail, "Assignment did not complete");
9985 mtc.stop;
9986 }
9987
9988 f_check_mgcp_expectations()
9989 setverdict(pass);
9990
9991 f_sleep(2.0);
9992 log("show lchan summary: ", f_vty_transceive_ret(BSCVTY, "show lchan summary"));
9993
9994 /* Instruct BSC to clear channel */
9995 var BssmapCause cause := 0;
9996 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
9997 interleave {
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009998 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {}
9999 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +020010000 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010001 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +020010002 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010003 }
10004 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
10005 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
10006 }
10007 }
Neels Hofmeyr40a45d12021-09-23 22:57:12 +020010008 f_expect_dlcx_conns();
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010009
10010 f_sleep(0.5);
10011}
10012
10013testcase TC_reassignment_fr() runs on test_CT {
10014 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10015 var MSC_ConnHdlr vc_conn;
10016
10017 f_init(1, true);
10018 f_sleep(1.0);
10019
Neels Hofmeyrac432fa2021-11-02 16:45:56 +010010020 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010021
10022 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10023 vc_conn := f_start_handler(refers(f_TC_reassignment_codec), pars);
10024 vc_conn.done;
10025
10026 /* from f_establish_fully() */
10027 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
10028 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
10029 /* from re-assignment */
10030 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
10031 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
10032 f_ctrs_bsc_and_bts_verify();
10033 f_shutdown_helper();
10034}
10035
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010036const charstring REEST_LOST_CONNECTION := "REEST_LOST_CONNECTION";
10037const charstring REEST_CLEAR := "REEST_CLEAR";
10038const charstring REEST_CLEAR_DONE := "REEST_CLEAR_DONE";
10039
10040/* CM Re-Establishment, 3GPP TS 24.008 4.5.1.6.
10041 * The MS <-> BTS loses radio connection, MS shows up on second BTS and asks for CM Re-Establishment.
10042 * BSC should establish a separate A conn for the same MS, the original A conn is then cleared by
10043 * the MSC as the CM Re-Establishment is handled.
10044 *
10045 * MS bts0 bts1 bsc msc test-component
10046 * |<----->|<----------------->|<-0-->| _1 Establish channel on bts 0
10047 * | | _1 wait a bit, to settle down
10048 * |<-x x--| | _1 "lose connection"
10049 * | | REEST_LOST_CONNECTION
10050 * |----------------->|------->|--1-->| _2 new A-conn: Chan Rqd, Imm Ass, Compl L3 with CM Re-Establishment Req
10051 * | | REEST_CLEAR
10052 * | |<-0---| _1 Clear Command on first A-conn
10053 * | |--0-->| _1 Clear Complete
10054 * | |<----------------->| | _1 Release first channel
10055 * | | REEST_CLEAR_DONE
10056 * |<-----------------|<-------|<-1---| _2 Chan Activ, Assignment Command
10057 * |<-----------------|<-------|<-1---| _2 Clear Command, Release
10058 *
10059 */
10060private function f_tc_cm_reestablishment_1(charstring id) runs on MSC_ConnHdlr {
10061 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
10062 var PDU_BSSAP ass_cmd := f_gen_ass_req();
10063
10064 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10065 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10066
10067 f_establish_fully(ass_cmd, exp_compl);
10068
10069 /* The original channel loses connection, MS attemts CM Re-Establishment on another cell, see
10070 * f_tc_cm_reestablishment_2(). This established channel stays active until MSC sends a Clear Command. The time
10071 * when exactly that happens is determined by f_tc_cm_reestablishment_2(). */
10072 f_sleep(2.0);
10073 COORD.send(REEST_LOST_CONNECTION);
10074
10075 alt {
10076 [] COORD.receive(REEST_CLEAR);
10077 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
10078 setverdict(fail, "Unexpected channel release");
10079 mtc.stop;
10080 }
10081 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
10082 setverdict(fail, "Unexpected channel release");
10083 mtc.stop;
10084 }
10085 }
10086 f_perform_clear()
10087 f_expect_dlcx_conns();
Neels Hofmeyr969abd02021-09-23 22:24:08 +020010088 f_create_mgcp_delete_ep(g_media.mgcp_ep);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010089 COORD.send(REEST_CLEAR_DONE);
10090}
10091
10092private function f_tc_cm_reestablishment_2(charstring id) runs on MSC_ConnHdlr {
10093 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
10094
10095 /* The MS lost the connection on the first channel, now establishes another one */
10096 COORD.receive(REEST_LOST_CONNECTION);
10097
10098 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
10099 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_REESTABL_REQ(mi));
10100 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
10101
10102 f_create_bssmap_exp(l3_enc);
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010103 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 +020010104 BSSAP.receive(tr_BSSMAP_ComplL3(l3_enc));
10105
10106 /* MSC got the CM Re-Establishment request and first off clears the previous conn. */
10107 COORD.send(REEST_CLEAR);
10108 COORD.receive(REEST_CLEAR_DONE);
10109
10110 f_sleep(2.0);
10111
10112 /* Answer the CM Re-Establishment with an Assignment Command. */
10113 var template PDU_BSSAP expect_assignment_compl := f_gen_exp_compl();
10114 var PDU_BSSAP ass_cmd := f_gen_ass_req();
10115 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10116 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10117
10118 var AssignmentState st := valueof(ts_AssignmentStateInit);
10119 st.voice_call := true;
10120 st.is_assignment := true;
10121
10122 var ExpectCriteria mgcpcrit := {
10123 connid := omit,
10124 endpoint := omit,
10125 transid := omit
10126 };
10127 f_create_mgcp_expect(mgcpcrit);
10128
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010129 f_rslem_dchan_queue_enable(RSL1_PROC);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010130
10131 BSSAP.send(ass_cmd);
10132
10133 var PDU_BSSAP bssap;
10134
10135 alt {
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010136 [] as_assignment(st, rsl_pt := RSL1, rsl_proc_pt := RSL1_PROC);
10137 [] as_Media_ipacc(RSL1, RSL2);
10138 [] as_Media_mgw();
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010139 [st.assignment_done] BSSAP.receive(expect_assignment_compl) {
10140 break;
10141 }
10142 }
10143
10144 f_sleep(3.0);
10145
10146 f_logp(BSCVTY, "f_tc_cm_reestablishment_2 clearing");
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010147 f_perform_clear(RSL1, RSL1_PROC);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010148 f_expect_dlcx_conns();
10149}
10150
10151testcase TC_cm_reestablishment() runs on test_CT {
10152 var TestHdlrParams pars1 := f_gen_test_hdlr_pars();
10153 var MSC_ConnHdlr vc_conn1;
10154
10155 var TestHdlrParams pars2 := f_gen_test_hdlr_pars();
10156 var MSC_ConnHdlr vc_conn2;
10157 pars2.imsi := pars1.imsi;
10158 pars2.media_nr := 2;
Neels Hofmeyrbf720202021-10-02 12:58:24 +020010159 pars2.expect_tsc := BTS_TSC[1];
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010160
10161 f_init(2, true, guard_timeout := 40.0);
10162 f_sleep(1.0);
10163
10164 vc_conn1 := f_start_handler_create(pars1);
10165 vc_conn2 := f_start_handler_create(pars2);
10166 connect(vc_conn1:COORD, vc_conn2:COORD);
10167 f_start_handler_run(vc_conn1, refers(f_tc_cm_reestablishment_1), pars1);
10168 f_start_handler_run(vc_conn2, refers(f_tc_cm_reestablishment_2), pars2);
10169 vc_conn1.done;
10170 vc_conn2.done;
10171
10172 f_shutdown_helper();
10173}
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000010174
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010175function f_exp_ipa_rx_nonfatal(integer bts_nr, template (present) RSL_Message t_rx, float t_secs := 2.0,
10176 IpaStreamId sid := IPAC_PROTO_RSL_TRX0, boolean ignore_other_rx := true)
10177runs on test_CT return template (omit) RSL_Message {
10178 var ASP_RSL_Unitdata rx_rsl_ud;
10179 timer T := t_secs;
10180
10181 T.start;
10182 alt {
10183 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
10184 T.stop;
10185 }
10186 [ignore_other_rx] IPA_RSL[bts_nr].receive { repeat; }
10187 [not ignore_other_rx] IPA_RSL[bts_nr].receive {
10188 log("f_exp_ipa_rx_nonfatal(): Got different message than ", t_rx);
10189 T.stop;
10190 return omit;
10191 }
10192 [] T.timeout {
10193 return omit;
10194 }
10195 }
10196 return rx_rsl_ud.rsl;
10197}
10198
10199private function f_vty_set_imm_ass(TELNETasp_PT pt, BtsNr bts_nr := 0, charstring imm_ass_setting := "post-chan-ack") {
10200 f_vty_enter_cfg_bts(pt, bts_nr);
10201 f_vty_transceive(pt, "immediate-assignment " & imm_ass_setting);
10202 f_vty_transceive(pt, "exit");
10203 f_vty_transceive(pt, "exit");
10204 f_vty_transceive(pt, "exit");
10205}
10206
10207private function f_verify_imm_ass(RSL_Message imm_ass, template uint8_t ra := ?, template GsmFrameNumber fn := ?,
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010208 template RslChannelNr chan_nr := ?,
10209 template (present) uint12_t arfcn := ?,
10210 template (present) uint3_t tsc := ?)
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010211{
10212 var RSL_IE_Body full_imm_ass_info;
10213 if (not f_rsl_find_ie(imm_ass, RSL_IE_FULL_IMM_ASS_INFO, full_imm_ass_info)) {
10214 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
10215 mtc.stop;
10216 }
10217
10218 var GsmRrMessage rr_imm_ass := dec_GsmRrMessage(full_imm_ass_info.full_imm_ass_info.payload);
10219 var template GsmRrMessage expect_imm_ass := tr_IMM_ASS(ra := ra,
10220 fn := fn,
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010221 ch_desc := tr_ChanDescH0(chan_nr, arfcn, tsc),
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010222 page_mode := ?);
10223 if (not match(rr_imm_ass, expect_imm_ass)) {
10224 log("Error: expected ", expect_imm_ass, " got ", rr_imm_ass);
10225 setverdict(fail, "Failed to match Immediate Assignment");
10226 mtc.stop;
10227 }
10228}
10229
10230testcase TC_imm_ass_post_chan_ack() runs on test_CT {
10231 var RSL_Message chan_act;
10232 var RSL_Message imm_ass;
10233
10234 f_init(1, false);
10235 f_sleep(1.0);
10236
10237 /* (should be the default anyway, just to make things clear) */
10238 f_vty_set_imm_ass(BSCVTY, 0, "post-chan-ack");
10239
10240 /* RA containing reason=LU */
10241 var GsmFrameNumber fn := 2342;
10242 var uint8_t ra := 2;
10243 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10244
10245 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10246
10247 /* First send the Chan Act ACK */
10248 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010249 var RSL_IE_Body chan_ident_ie;
10250 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10251 setverdict(fail, "RSL Channel Identification IE is absent");
10252 mtc.stop;
10253 }
10254
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010255 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn + 10));
10256
10257 /* Then expect the Immediate Assignment, after we ACKed the chan act */
10258 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10259
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010260 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10261 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010262
10263 /* Check that the lchan is working */
10264 var octetstring l3 := '00010203040506'O;
10265 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10266
10267 var BSSAP_N_CONNECT_ind rx_c_ind;
10268 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
10269 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10270
10271 f_sleep(1.0);
10272 f_shutdown_helper();
10273}
10274
10275testcase TC_imm_ass_pre_chan_ack() runs on test_CT {
10276 var RSL_Message chan_act;
10277 var RSL_Message imm_ass;
10278
10279 f_init(1, false);
10280 f_sleep(1.0);
10281
10282 f_vty_set_imm_ass(BSCVTY, 0, "pre-chan-ack");
10283
10284 /* RA containing reason=LU */
10285 var GsmFrameNumber fn := 2342;
10286 var uint8_t ra := 2;
10287 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10288
10289 /* (set bts 0 cfg back to default) */
10290 f_vty_set_imm_ass(BSCVTY);
10291
10292 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10293 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010294 var RSL_IE_Body chan_ident_ie;
10295 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10296 setverdict(fail, "RSL Channel Identification IE is absent");
10297 mtc.stop;
10298 }
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010299
10300 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10301 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010302 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10303 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010304
10305 /* Only now send the Chan Act ACK */
10306 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10307
10308 /* Check that the lchan is working */
10309 var octetstring l3 := '00010203040506'O;
10310 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10311
10312 var BSSAP_N_CONNECT_ind rx_c_ind;
10313 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
10314 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10315
10316 f_sleep(1.0);
10317 f_shutdown_helper();
10318}
10319
Neels Hofmeyr23158742021-09-07 19:08:07 +020010320testcase TC_imm_ass_pre_ts_ack() runs on test_CT {
10321 var RSL_Message chan_act;
10322 var RSL_Message imm_ass;
10323
10324 f_init(1, false);
10325 f_sleep(1.0);
10326
10327 f_vty_set_imm_ass(BSCVTY, 0, "pre-ts-ack");
10328
10329 /* RA containing reason=LU */
10330 var GsmFrameNumber fn := 2342;
10331 var uint8_t ra := 2;
10332 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10333
10334 /* (set bts 0 cfg back to default) */
10335 f_vty_set_imm_ass(BSCVTY);
10336
10337 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10338 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
10339 var RSL_IE_Body chan_ident_ie;
10340 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10341 setverdict(fail, "RSL Channel Identification IE is absent");
10342 mtc.stop;
10343 }
10344
10345 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10346 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10347 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10348 chan_ident_ie.chan_ident.ch_desc.v.tsc);
10349
10350 /* Only now send the Chan Act ACK */
10351 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10352
10353 /* Check that the lchan is working */
10354 var octetstring l3 := '00010203040506'O;
10355 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10356
10357 var BSSAP_N_CONNECT_ind rx_c_ind;
10358 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
10359 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10360
10361 f_sleep(1.0);
10362 f_shutdown_helper();
10363}
10364
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010365testcase TC_imm_ass_pre_chan_ack_dyn_ts() runs on test_CT {
10366 /* change Timeslot 6 before f_init() starts RSL */
10367 f_init_vty();
10368 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
10369 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10370
10371 f_init(1, false);
10372 f_sleep(1.0);
10373
10374 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
10375 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010376 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010377 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2323));
10378
10379 /* clean up timeslot 6 config, will only take effect when the OML drops the next time */
10380 f_ts_set_chcomb(0, 0, 6, "PDCH");
10381
10382 /* block all static timeslots so that the dyn TS will be used */
10383 f_disable_all_tch_f();
10384 f_disable_all_tch_h();
10385 f_disable_all_sdcch();
10386
10387 var RSL_Message chan_act;
10388 var RSL_Message imm_ass;
10389
10390 f_init(1, false);
10391 f_sleep(1.0);
10392
10393 f_vty_set_imm_ass(BSCVTY, 0, "pre-chan-ack");
10394
10395 /* RA containing reason=LU */
10396 var GsmFrameNumber fn := 2342;
10397 var uint8_t ra := 2;
10398 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10399
10400 /* (set bts 0 cfg back to default) */
10401 f_vty_set_imm_ass(BSCVTY);
10402
10403 /* Expect the dyn TS to deactivate PDCH first */
10404 f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
10405 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
10406
10407 /* Now activation as SDCCH8 */
10408 chan_nr := valueof(t_RslChanNr_SDCCH8(tn := 6, sub_slot := 0));
10409
10410 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010411 var RSL_IE_Body chan_ident_ie;
10412 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10413 setverdict(fail, "RSL Channel Identification IE is absent");
10414 mtc.stop;
10415 }
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010416
10417 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10418 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010419 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10420 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010421
10422 /* Only now send the Chan Act ACK */
10423 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10424
10425 /* Check that the lchan is working */
10426 var octetstring l3 := '00010203040506'O;
10427 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10428
10429 var BSSAP_N_CONNECT_ind rx_c_ind;
10430 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
10431 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10432
10433 f_sleep(1.0);
10434 f_shutdown_helper();
10435}
10436
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010437testcase TC_imm_ass_pre_ts_ack_dyn_ts() runs on test_CT {
10438 /* change Timeslot 6 before f_init() starts RSL */
10439 f_init_vty();
10440 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
10441 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10442
10443 f_init(1, false);
10444 f_sleep(1.0);
10445
10446 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
10447 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010448 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010449 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2323));
10450
10451 /* clean up timeslot 6 config, will only take effect when the OML drops the next time */
10452 f_ts_set_chcomb(0, 0, 6, "PDCH");
10453
10454 /* block all static timeslots so that the dyn TS will be used */
10455 f_disable_all_tch_f();
10456 f_disable_all_tch_h();
10457 f_disable_all_sdcch();
10458
10459 var RSL_Message chan_act;
10460 var RSL_Message imm_ass;
10461
10462 f_init(1, false);
10463 f_sleep(1.0);
10464
10465 f_vty_set_imm_ass(BSCVTY, 0, "pre-ts-ack");
10466
10467 /* RA containing reason=LU */
10468 var GsmFrameNumber fn := 2342;
10469 var uint8_t ra := 2;
10470 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10471
10472 /* (set bts 0 cfg back to default) */
10473 f_vty_set_imm_ass(BSCVTY);
10474
10475 /* Expect the dyn TS to deactivate PDCH first */
10476 f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
10477
10478 /* And already the Immediate Assignment even before the PDCH Deact ACK */
10479 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10480
10481 /* continue the Osmo style PDCH Deact (usual chan rel) */
10482 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
10483
10484 /* Now activation as SDCCH8 */
10485 chan_nr := valueof(t_RslChanNr_SDCCH8(tn := 6, sub_slot := 0));
10486
10487 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010488 var RSL_IE_Body chan_ident_ie;
10489 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10490 setverdict(fail, "RSL Channel Identification IE is absent");
10491 mtc.stop;
10492 }
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010493 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10494
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010495 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10496 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010497
10498 /* Check that the lchan is working */
10499 var octetstring l3 := '00010203040506'O;
10500 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10501
10502 var BSSAP_N_CONNECT_ind rx_c_ind;
10503 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
10504 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10505
10506 f_sleep(1.0);
10507 f_shutdown_helper();
10508}
10509
Neels Hofmeyr5d7d13f2021-09-07 14:44:36 +020010510/* GET and SET the bts.N.trx.M.rf_locked CTRL variable */
10511testcase TC_ctrl_trx_rf_locked() runs on test_CT {
10512 var MSC_ConnHdlr vc_conn;
10513
10514 f_init(nr_bts := 2, handler_mode := true, nr_msc := 1);
10515 f_sleep(1.0);
10516
10517 /* BTS 0, 1, 2 are OML unlocked, only BTS 0, 1 are actually connected to RSL. */
10518 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10519 "0,0,operational,unlocked,on,rsl-up;" &
10520 "1,0,operational,unlocked,on,rsl-up;" &
10521 "2,0,operational,unlocked,on,rsl-down;" &
10522 "3,0,inoperational,locked,on,rsl-down;");
10523
10524 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: lock BTS 1 TRX 0");
10525 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "1");
10526 /* give it a moment to settle the FSM status */
10527 f_sleep(1.0);
10528
10529 /* Now BTS 1 TRX 0 should reflect "locked". Note the RF policy stays "on", because this is still handled
10530 * globally in osmo-bsc. Probably after sending "rf_locked 1" for a TRX, that TRX should reflect an RF policy
10531 * of "off"? But that's for a future patch if at all. */
10532 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10533 "0,0,operational,unlocked,on,rsl-up;" &
10534 "1,0,operational,locked,on,rsl-up;" &
10535 "2,0,operational,unlocked,on,rsl-down;" &
10536 "3,0,inoperational,locked,on,rsl-down;");
10537
10538 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: lock the already locked TRX, nothing should change");
10539 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "1");
10540 f_sleep(1.0);
10541 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10542 "0,0,operational,unlocked,on,rsl-up;" &
10543 "1,0,operational,locked,on,rsl-up;" &
10544 "2,0,operational,unlocked,on,rsl-down;" &
10545 "3,0,inoperational,locked,on,rsl-down;");
10546
10547 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock BTS 1 TRX 0");
10548 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "0");
10549 f_sleep(1.0);
10550 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10551 "0,0,operational,unlocked,on,rsl-up;" &
10552 "1,0,operational,unlocked,on,rsl-up;" &
10553 "2,0,operational,unlocked,on,rsl-down;" &
10554 "3,0,inoperational,locked,on,rsl-down;");
10555
10556 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock an already unlocked TRX, nothing should change");
10557 f_ctrl_set(IPA_CTRL, "bts.0.trx.0.rf_locked", "0");
10558 f_sleep(1.0);
10559 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10560 "0,0,operational,unlocked,on,rsl-up;" &
10561 "1,0,operational,unlocked,on,rsl-up;" &
10562 "2,0,operational,unlocked,on,rsl-down;" &
10563 "3,0,inoperational,locked,on,rsl-down;");
10564
10565 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock an inoperational TRX");
10566 f_ctrl_set(IPA_CTRL, "bts.3.trx.0.rf_locked", "0");
10567 f_sleep(1.0);
10568 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10569 "0,0,operational,unlocked,on,rsl-up;" &
10570 "1,0,operational,unlocked,on,rsl-up;" &
10571 "2,0,operational,unlocked,on,rsl-down;" &
10572 "3,0,inoperational,locked,on,rsl-down;");
10573
10574 f_shutdown_helper();
10575}
10576
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010577const CounterNameVals counternames_cm_serv_rej := {
10578 { "cm_serv_rej", 0 },
10579 { "cm_serv_rej:imsi_unknown_in_hlr", 0 },
10580 { "cm_serv_rej:illegal_ms", 0 },
10581 { "cm_serv_rej:imsi_unknown_in_vlr", 0 },
10582 { "cm_serv_rej:imei_not_accepted", 0 },
10583 { "cm_serv_rej:illegal_me", 0 },
10584 { "cm_serv_rej:plmn_not_allowed", 0 },
10585 { "cm_serv_rej:loc_not_allowed", 0 },
10586 { "cm_serv_rej:roaming_not_allowed", 0 },
10587 { "cm_serv_rej:network_failure", 0 },
10588 { "cm_serv_rej:synch_failure", 0 },
10589 { "cm_serv_rej:congestion", 0 },
10590 { "cm_serv_rej:srv_opt_not_supported", 0 },
10591 { "cm_serv_rej:rqd_srv_opt_not_supported", 0 },
10592 { "cm_serv_rej:srv_opt_tmp_out_of_order", 0 },
10593 { "cm_serv_rej:call_can_not_be_identified", 0 },
10594 { "cm_serv_rej:incorrect_message", 0 },
10595 { "cm_serv_rej:invalid_mandantory_inf", 0 },
10596 { "cm_serv_rej:msg_type_not_implemented", 0 },
10597 { "cm_serv_rej:msg_type_not_compatible", 0 },
10598 { "cm_serv_rej:inf_eleme_not_implemented", 0 },
10599 { "cm_serv_rej:condtional_ie_error", 0 },
10600 { "cm_serv_rej:msg_not_compatible", 0 },
10601 { "cm_serv_rej:protocol_error", 0 },
10602 { "cm_serv_rej:retry_in_new_cell", 0 }
10603};
10604
10605private function f_TC_cm_serv_rej(charstring id) runs on MSC_ConnHdlr
10606{
10607 f_create_chan_and_exp();
Vadim Yanitskiya7fc5a62021-12-04 20:10:08 +030010608 /* we should now have a COMPL_L3 at the MSC */
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010609 BSSAP.send(ts_PDU_DTAP_MT(ts_CM_SERV_REJ('02'O), '00'O));
Neels Hofmeyr87a65612021-11-16 15:56:45 +010010610 f_sleep(1.0);
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010611}
10612testcase TC_cm_serv_rej() runs on test_CT {
10613 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10614 var MSC_ConnHdlr vc_conn;
10615
10616 f_init(1, true);
10617 f_sleep(1.0);
10618
10619 f_ctrs_bts_init(1, counternames_cm_serv_rej);
10620
10621 vc_conn := f_start_handler(refers(f_TC_cm_serv_rej), pars);
10622 vc_conn.done;
10623
10624 f_ctrs_bts_add(0, "cm_serv_rej", 1);
10625 f_ctrs_bts_add(0, "cm_serv_rej:imsi_unknown_in_hlr", 1);
10626 f_ctrs_bts_verify();
10627
Neels Hofmeyr87a65612021-11-16 15:56:45 +010010628 f_sleep(1.0);
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010629 f_shutdown_helper();
10630}
10631
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010632/* Reproduce a segfault happening when the SDCCH (primary) lchan is lost in-between a TCH Channel Activ and its Channel
10633 * Activ Ack (SYS#5627). */
10634private function f_TC_lost_sdcch_during_assignment(charstring id) runs on MSC_ConnHdlr {
10635 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Vadim Yanitskiyf0310e32021-10-26 00:30:59 +030010636
10637 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10638 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010639
10640 var BSSMAP_FIELD_CodecType codecType;
10641 codecType := valueof(ass_cmd.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType);
10642
10643 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
10644
10645 /* First establish a signalling lchan */
10646 f_create_chan_and_exp();
10647 f_rslem_dchan_queue_enable();
10648
10649 /* we should now have a COMPL_L3 at the MSC */
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010650
10651 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
10652 activate(as_Media_mgw());
10653
10654 var RslChannelNr chan_nr := { u := { ch0 := RSL_CHAN_NR_Bm_ACCH }, tn := 1 };
10655 f_rslem_register(0, chan_nr);
10656
10657 f_rslem_set_auto_chan_act_ack(RSL_PROC, false);
10658 BSSAP.send(ass_cmd);
10659
10660
10661 /* Wait for the Channel Activ for the TCH channel */
10662 var ASP_RSL_Unitdata rx_rsl_ud;
10663 RSL.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV), sid := ?)) -> value rx_rsl_ud;
10664
10665 /* make the original SDCCH disappear */
10666 RSL.send(ts_RSL_REL_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
10667
10668 /* and ACK the TCH channel activation. This caused a segfault up to OsmoBSC 1.7.0 (SYS#5627) */
10669 RSL.send(ts_ASP_RSL_UD(ts_RSL_CHAN_ACT_ACK(chan_nr, 23), rx_rsl_ud.streamId));
10670
10671 interleave {
10672 [] BSSAP.receive(tr_BSSMAP_AssignmentFail);
10673 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
10674 }
10675
10676 BSSAP.send(ts_BSSMAP_ClearCommand(0));
10677 BSSAP.receive(tr_BSSMAP_ClearComplete);
10678 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
10679
10680 var MgcpCommand mgcp;
10681 MGCP.receive(tr_DLCX()) -> value mgcp {
10682 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
10683 };
10684
10685 f_sleep(0.5);
10686}
10687testcase TC_lost_sdcch_during_assignment() runs on test_CT {
10688 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10689 var MSC_ConnHdlr vc_conn;
10690
10691 f_init(1, true);
10692 f_sleep(1.0);
10693
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010694 vc_conn := f_start_handler(refers(f_TC_lost_sdcch_during_assignment), pars);
10695 vc_conn.done;
10696
10697 f_shutdown_helper();
10698}
10699
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010700const CounterNameVals counternames_bsc_bts_all_available_allocated := {
10701 { "all_allocated:sdcch", 0 },
10702 { "all_allocated:static_sdcch", 0 },
10703 { "all_allocated:tch", 0 },
10704 { "all_allocated:static_tch", 0 }
10705}
10706
10707private function f_all_allocated_expect_counter_change(charstring_list expect_changed) runs on test_CT
10708{
10709 /* Make sure counters settle first */
10710 f_sleep(1.0);
10711
10712 /* Take a baseline of counters */
10713 f_ctrs_bsc_and_bts_init(1, counternames_bsc_bts_all_available_allocated);
10714
10715 /* Elapse some time so that we see changes in counters, hopefully where expected */
10716 f_sleep(2.0);
10717
10718 /* Get new counters */
10719 var charstring_list all_changed := {};
10720 all_changed := all_changed & f_counter_name_vals_get_changed_n(IPA_CTRL, "bsc", g_ctr_bsc);
10721 all_changed := all_changed & f_counter_name_vals_get_changed_n(IPA_CTRL, "bts", g_ctr_bts);
10722
10723 /* Compare with expectations */
10724 var charstring_list all_expect_changed := {};
10725 for (var integer i := 0; i < lengthof(expect_changed); i := i + 1) {
10726 all_expect_changed := all_expect_changed & { "bsc.0." & expect_changed[i], "bts.0." & expect_changed[i] };
10727 }
10728 f_counter_name_vals_expect_changed_list(all_changed, all_expect_changed);
10729}
10730
10731testcase TC_ratectr_all_available_allocated() runs on test_CT {
10732 var ASP_RSL_Unitdata rsl_ud;
10733 var integer i;
10734 var integer chreq_total, chreq_nochan;
10735
10736 f_init(1);
10737 f_sleep(1.0);
10738
10739 /* Exhaust all dedicated SDCCH lchans.
10740 /* GSM 44.018 Table 9.1.8.2:
10741 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
10742 */
10743 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
10744 f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
10745 }
10746
10747 /* Since only bts 0 is connected, expecting all_allocated to become true for both bts 0 and the "global" bsc
10748 * level.
10749 * All SDCCH are now occupied. */
10750 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch"});
10751
10752 /* Also fill up all remaining (TCH) channels */
10753 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS; i := i+1) {
10754 f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
10755 }
10756
10757 /* All TCH are now also occupied */
10758 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch",
10759 "all_allocated:tch", "all_allocated:static_tch"});
10760
10761 f_shutdown_helper();
10762}
10763
10764testcase TC_ratectr_all_available_allocated_dyn() runs on test_CT {
10765 var ASP_RSL_Unitdata rsl_ud;
10766 var integer i;
10767 var integer chreq_total, chreq_nochan;
10768
10769 f_init_vty();
10770 f_ts_set_chcomb(0, 0, 2, "TCH/F_TCH/H_PDCH");
10771 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10772 /* Now we have 3 TCH/F, 1 OSMO_DYN, 1 TCH/H */
10773
10774 f_init(1, guard_timeout := 60.0);
10775 f_sleep(1.0);
10776
10777 /* The dyn TS wants to activate PDCH mode, ACK that. */
10778 var RslChannelNr chan_nr;
10779 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010780 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010781 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
10782
10783 /* Exhaust all dedicated SDCCH lchans.
10784 /* GSM 44.018 Table 9.1.8.2:
10785 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
10786 */
10787 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
10788 f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
10789 }
10790
10791 /* The static SDCCH should now be occupied, while still 3x8 dynamic SDCCH potentially remain. So only
10792 * all_allocated:static_sdcch is counted, all_allocated:sdcch remains zero. */
10793 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch"});
10794
10795 /* Request more SDCCH, hence convert the first dyn TS to SDCCH8.
10796 * Will release them later, so remember all the DchanTuples. */
10797 var DchanTuples dyn_sddch := {};
10798 dyn_sddch := dyn_sddch & { f_est_dchan_dyn('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
10799
10800 /* Also occupy the seven other SDCCH of the dyn TS */
10801 for (i := 0; i < 7; i := i+1) {
10802 dyn_sddch := dyn_sddch & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
10803 }
10804
10805 /* Now all dynamic SDCCH are also occupied, so for the first time all_allocated:sdcch will trigger... */
10806 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch"});
10807
10808 /* occupy the remaining TCH, three TCH/F and two TCH/H lchans */
10809 for (i := 0; i < 5; i := i+1) {
10810 f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
10811 }
10812
10813 /* All TCH lchans are now also occupied, both static and dynamic */
10814 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch",
10815 "all_allocated:tch", "all_allocated:static_tch"});
10816
10817 /* Starting to release the dyn TS: as soon as the first SDCCH gets released, all_allocated:sdcch stops
10818 * incrementing. */
10819 var BssmapCause cause := 0;
10820 var DchanTuple dt := dyn_sddch[0];
10821 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
10822 f_exp_chan_rel_and_clear(dt, 0);
10823
10824 /* one dyn TS SDCCH is free again, so only the static_sdcch should increment. For tch, both static and dynamic
10825 * count as occupied, so those still both increment. */
10826 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch",
10827 "all_allocated:tch", "all_allocated:static_tch"});
10828
10829 /* Release the remaining SDCCH of the dyn TS, so it becomes available as TCH again */
10830 for (i := 1; i < lengthof(dyn_sddch); i := i+1) {
10831 dt := dyn_sddch[i];
10832 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
10833 f_exp_chan_rel_and_clear(dt, 0);
10834 }
10835
10836 /* All SDCCH on the dyn TS are released, the dyn TS wants to activate PDCH again */
10837 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010838 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010839 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
10840
10841 /* Now all channels are occupied except the dyn TS, so expecting only the static counters to increment */
10842 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch", "all_allocated:static_tch"});
10843
10844 /* clean up config */
10845 f_ts_reset_chcomb(0);
10846
10847 f_shutdown_helper();
10848}
10849
Harald Welte28d943e2017-11-25 15:00:50 +010010850control {
Harald Welte898113b2018-01-31 18:32:21 +010010851 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +010010852 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +010010853 execute( TC_ctrl_msc0_connection_status() );
Neels Hofmeyrf65ce872021-09-23 18:40:10 +020010854 /* In SCCPlite tests, only one MSC is configured. These tests assume that three MSCs are configured, so only run
10855 * these in the AoIP test suite. */
10856 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
10857 execute( TC_stat_num_msc_connected_1() );
10858 execute( TC_stat_num_msc_connected_2() );
10859 execute( TC_stat_num_msc_connected_3() );
10860 }
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +020010861 execute( TC_stat_num_bts_connected_1() );
10862 execute( TC_stat_num_bts_connected_2() );
10863 execute( TC_stat_num_bts_connected_3() );
Harald Welte96c94412017-12-09 03:12:45 +010010864 execute( TC_ctrl() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +020010865 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER) {
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +020010866 execute( TC_ctrl_location() );
10867 }
Harald Welte898113b2018-01-31 18:32:21 +010010868
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020010869 execute( TC_si_default() );
Neels Hofmeyr66aeba42020-07-06 02:21:21 +020010870 execute( TC_si2quater_2_earfcns() );
10871 execute( TC_si2quater_3_earfcns() );
10872 execute( TC_si2quater_4_earfcns() );
10873 execute( TC_si2quater_5_earfcns() );
10874 execute( TC_si2quater_6_earfcns() );
Neels Hofmeyrad132f22020-07-08 02:20:16 +020010875 execute( TC_si2quater_12_earfcns() );
10876 execute( TC_si2quater_23_earfcns() );
10877 execute( TC_si2quater_32_earfcns() );
10878 execute( TC_si2quater_33_earfcns() );
10879 execute( TC_si2quater_42_earfcns() );
10880 execute( TC_si2quater_48_earfcns() );
10881 execute( TC_si2quater_49_earfcns() );
Pau Espin Pedrol85a84432020-07-20 18:45:03 +020010882 execute( TC_si_acc_rotate() );
Alexander Couzens4ad3a352020-09-10 22:29:12 +020010883 execute( TC_si_acc_ramp_rotate() );
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020010884
Harald Welte898113b2018-01-31 18:32:21 +010010885 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +010010886 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +010010887 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +010010888 execute( TC_chan_act_ack_noest() );
Philipp Maier9c60a622020-07-09 15:08:46 +020010889 execute( TC_chan_act_ack_noest_emerg() );
Philipp Maier606f07d2020-08-12 17:21:58 +020010890 execute( TC_chan_rqd_emerg_deny() );
Harald Welteae026692017-12-09 01:03:01 +010010891 execute( TC_chan_act_ack_est_ind_noreply() );
10892 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +010010893 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +010010894 execute( TC_chan_exhaustion() );
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +070010895 execute( TC_chan_deact_silence() );
Harald Welte4003d112017-12-09 22:35:39 +010010896 execute( TC_chan_rel_rll_rel_ind() );
10897 execute( TC_chan_rel_conn_fail() );
10898 execute( TC_chan_rel_hard_clear() );
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +020010899 execute( TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() );
10900 execute( TC_chan_rel_last_eutran_plmn_hard_clear_csfb() );
Harald Welte99787102019-02-04 10:41:36 +010010901 execute( TC_chan_rel_hard_clear_csfb() );
Harald Welted8c36cd2017-12-09 23:05:31 +010010902 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +020010903 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +010010904 execute( TC_chan_rel_a_reset() );
Pau Espin Pedrolc675b612020-01-09 19:55:40 +010010905 execute( TC_chan_rel_sccp_tiar_timeout() );
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +020010906 execute( TC_chan_rel_rr_cause() );
Harald Welte6f521d82017-12-11 19:52:02 +010010907
Harald Weltecfe2c962017-12-15 12:09:32 +010010908 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +010010909
10910 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +010010911 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +010010912 execute( TC_assignment_csd() );
10913 execute( TC_assignment_ctm() );
10914 execute( TC_assignment_sign() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +020010915 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
10916 execute( TC_assignment_aoip_tla_v6() );
10917 }
Harald Welte235ebf12017-12-15 14:18:16 +010010918 execute( TC_assignment_fr_a5_0() );
10919 execute( TC_assignment_fr_a5_1() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +020010920 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte8f67d1d2018-05-25 20:38:42 +020010921 execute( TC_assignment_fr_a5_1_codec_missing() );
10922 }
Harald Welte235ebf12017-12-15 14:18:16 +010010923 execute( TC_assignment_fr_a5_3() );
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +020010924 execute( TC_assignment_fr_a5_4() );
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +020010925 execute( TC_assignment_fr_a5_4_fail() );
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +020010926 execute( TC_assignment_fr_a5_not_sup() );
Harald Welte3c86ea02018-05-10 22:28:05 +020010927 execute( TC_ciph_mode_a5_0() );
10928 execute( TC_ciph_mode_a5_1() );
Oliver Smith50b98122021-07-09 15:00:28 +020010929 execute( TC_ciph_mode_a5_2_0() );
Oliver Smith1dff88d2021-07-09 08:45:51 +020010930 execute( TC_ciph_mode_a5_2_1() );
Harald Welte3c86ea02018-05-10 22:28:05 +020010931 execute( TC_ciph_mode_a5_3() );
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +020010932 execute( TC_ciph_mode_a5_4() );
Harald Welte16a4adf2017-12-14 18:54:01 +010010933
Harald Welte60aa5762018-03-21 19:33:13 +010010934 execute( TC_assignment_codec_fr() );
Neels Hofmeyr559d5d02021-04-16 16:50:49 +020010935 execute( TC_assignment_codec_fr_by_mode_modify() );
Harald Welte60aa5762018-03-21 19:33:13 +010010936 execute( TC_assignment_codec_hr() );
10937 execute( TC_assignment_codec_efr() );
10938 execute( TC_assignment_codec_amr_f() );
10939 execute( TC_assignment_codec_amr_h() );
Philipp Maier8a581d22019-03-26 18:32:48 +010010940
Neels Hofmeyrf246a922020-05-13 02:27:10 +020010941 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier8a581d22019-03-26 18:32:48 +010010942 execute( TC_assignment_codec_amr_f_S1() );
10943 execute( TC_assignment_codec_amr_h_S1() );
10944 execute( TC_assignment_codec_amr_f_S124() );
10945 execute( TC_assignment_codec_amr_h_S124() );
10946 execute( TC_assignment_codec_amr_f_S0() );
10947 execute( TC_assignment_codec_amr_f_S02() );
10948 execute( TC_assignment_codec_amr_f_S024() );
10949 execute( TC_assignment_codec_amr_f_S0247() );
10950 execute( TC_assignment_codec_amr_h_S0() );
10951 execute( TC_assignment_codec_amr_h_S02() );
10952 execute( TC_assignment_codec_amr_h_S024() );
10953 execute( TC_assignment_codec_amr_h_S0247() );
10954 execute( TC_assignment_codec_amr_f_S01234567() );
10955 execute( TC_assignment_codec_amr_f_S0234567() );
10956 execute( TC_assignment_codec_amr_f_zero() );
10957 execute( TC_assignment_codec_amr_f_unsupp() );
10958 execute( TC_assignment_codec_amr_h_S7() );
Neels Hofmeyr21863562020-11-26 00:34:33 +000010959 execute( TC_assignment_codec_amr_f_start_mode_auto() );
10960 execute( TC_assignment_codec_amr_h_start_mode_auto() );
Neels Hofmeyr3eb94562020-11-26 02:40:26 +000010961 execute( TC_assignment_codec_amr_f_start_mode_4() );
10962 execute( TC_assignment_codec_amr_h_start_mode_4() );
Neels Hofmeyr454d7922020-11-26 02:24:57 +000010963 execute( TC_assignment_codec_amr_startmode_cruft() );
Philipp Maier8a581d22019-03-26 18:32:48 +010010964 }
Harald Welte60aa5762018-03-21 19:33:13 +010010965
Philipp Maierac09bfc2019-01-08 13:41:39 +010010966 execute( TC_assignment_codec_fr_exhausted_req_hr() );
10967 execute( TC_assignment_codec_fr_exhausted_req_fr() );
10968 execute( TC_assignment_codec_fr_exhausted_req_fr_hr() );
10969 execute( TC_assignment_codec_fr_exhausted_req_hr_fr() );
10970 execute( TC_assignment_codec_hr_exhausted_req_fr() );
10971 execute( TC_assignment_codec_hr_exhausted_req_hr() );
10972 execute( TC_assignment_codec_hr_exhausted_req_hr_fr() );
10973 execute( TC_assignment_codec_hr_exhausted_req_fr_hr() );
10974 execute( TC_assignment_codec_req_hr_fr() );
10975 execute( TC_assignment_codec_req_fr_hr() );
Pau Espin Pedrol14475352021-07-22 15:48:16 +020010976 execute( TC_assignment_sdcch_exhausted_req_signalling() );
10977 execute( TC_assignment_sdcch_exhausted_req_signalling_tch_forbidden() );
10978 execute( TC_assignment_sdcch_exhausted_req_voice_tch_forbidden() );
Philipp Maierac09bfc2019-01-08 13:41:39 +010010979
Pau Espin Pedrol23510fb2021-07-20 17:00:38 +020010980 execute( TC_assignment_osmux() );
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +020010981
Harald Welte898113b2018-01-31 18:32:21 +010010982 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +010010983 execute( TC_rll_est_ind_inact_lchan() );
10984 execute( TC_rll_est_ind_inval_sapi1() );
10985 execute( TC_rll_est_ind_inval_sapi3() );
10986 execute( TC_rll_est_ind_inval_sacch() );
10987
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +070010988 /* DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
10989 execute( TC_tch_dlci_link_id_sapi() );
10990
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +070010991 /* SAPI N Reject triggered by RLL establishment failures */
10992 execute( TC_rll_rel_ind_sapi_n_reject() );
10993 execute( TC_rll_err_ind_sapi_n_reject() );
10994 execute( TC_rll_timeout_sapi_n_reject() );
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +070010995 execute( TC_rll_sapi_n_reject_dlci_cc() );
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +070010996
Harald Welte898113b2018-01-31 18:32:21 +010010997 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +010010998 execute( TC_paging_imsi_nochan() );
10999 execute( TC_paging_tmsi_nochan() );
11000 execute( TC_paging_tmsi_any() );
11001 execute( TC_paging_tmsi_sdcch() );
11002 execute( TC_paging_tmsi_tch_f() );
11003 execute( TC_paging_tmsi_tch_hf() );
11004 execute( TC_paging_imsi_nochan_cgi() );
11005 execute( TC_paging_imsi_nochan_lac_ci() );
11006 execute( TC_paging_imsi_nochan_ci() );
11007 execute( TC_paging_imsi_nochan_lai() );
11008 execute( TC_paging_imsi_nochan_lac() );
11009 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +010011010 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
11011 execute( TC_paging_imsi_nochan_rnc() );
11012 execute( TC_paging_imsi_nochan_lac_rnc() );
11013 execute( TC_paging_imsi_nochan_lacs() );
11014 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +010011015 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +010011016 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +010011017 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +010011018 execute( TC_paging_counter() );
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +010011019 execute( TC_paging_resp_unsol() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +010011020
11021 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +010011022 execute( TC_rsl_unknown_unit_id() );
11023
11024 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +010011025
11026 execute( TC_classmark() );
Harald Welteeddf0e92020-06-21 19:42:15 +020011027 execute( TC_common_id() );
Harald Welte898113b2018-01-31 18:32:21 +010011028 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +010011029 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +010011030 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +010011031 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +010011032 execute( TC_err_84_unknown_msg() );
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010011033
Harald Welte261af4b2018-02-12 21:20:39 +010011034 execute( TC_ho_int() );
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +020011035 execute( TC_ho_int_a5_0() );
11036 execute( TC_ho_int_a5_1() );
11037 execute( TC_ho_int_a5_3() );
11038 execute( TC_ho_int_a5_4() );
Neels Hofmeyr5f144212020-11-03 15:41:58 +000011039 execute( TC_ho_int_radio_link_failure() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011040
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +010011041 /* TC_ho_out_of_this_bsc is run last, see comment below */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +020011042 execute( TC_ho_out_fail_no_msc_response() );
11043 execute( TC_ho_out_fail_rr_ho_failure() );
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +020011044 execute( TC_ho_out_fail_no_result_after_ho_cmd() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011045
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010011046 execute( TC_ho_into_this_bsc() );
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +020011047 execute( TC_ho_into_this_bsc_a5_0() );
11048 execute( TC_ho_into_this_bsc_a5_1() );
11049 execute( TC_ho_into_this_bsc_a5_3() );
11050 execute( TC_ho_into_this_bsc_a5_4() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +020011051 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11052 execute( TC_ho_into_this_bsc_tla_v6() );
11053 }
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +020011054 execute( TC_srvcc_eutran_to_geran() );
Pau Espin Pedrol35801c32021-04-19 13:03:20 +020011055 execute( TC_srvcc_eutran_to_geran_ho_out() );
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +020011056 execute( TC_srvcc_eutran_to_geran_forbid_fast_return() );
11057 execute( TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011058 execute( TC_ho_in_fail_msc_clears() );
11059 execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
11060 execute( TC_ho_in_fail_no_detect() );
11061 execute( TC_ho_in_fail_no_detect2() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +010011062
Neels Hofmeyr91401012019-07-11 00:42:35 +020011063 execute( TC_ho_neighbor_config_1() );
11064 execute( TC_ho_neighbor_config_2() );
11065 execute( TC_ho_neighbor_config_3() );
11066 execute( TC_ho_neighbor_config_4() );
11067 execute( TC_ho_neighbor_config_5() );
11068 execute( TC_ho_neighbor_config_6() );
11069 execute( TC_ho_neighbor_config_7() );
11070
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +010011071 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010011072 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +010011073 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +020011074
11075 execute( TC_dyn_pdch_ipa_act_deact() );
11076 execute( TC_dyn_pdch_ipa_act_nack() );
11077 execute( TC_dyn_pdch_osmo_act_deact() );
11078 execute( TC_dyn_pdch_osmo_act_nack() );
Pau Espin Pedrol37a4c152021-11-16 19:02:23 +010011079 execute( TC_dyn_ts_sdcch8_act_deact() );
11080 execute( TC_dyn_ts_sdcch8_all_subslots_used() );
11081 execute( TC_dyn_ts_sdcch8_tch_call_act_deact() );
11082 execute( TC_dyn_ts_sdcch8_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +020011083
Stefan Sperling0796a822018-10-05 13:01:39 +020011084 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +020011085 execute( TC_chopped_ipa_payload() );
Stefan Sperling0796a822018-10-05 13:01:39 +020011086
Pau Espin Pedrol8f773632019-11-05 11:46:53 +010011087 /* Power control related */
11088 execute( TC_assignment_verify_ms_power_params_ie() );
Vadim Yanitskiy4b233042021-06-30 00:58:43 +020011089 execute( TC_c0_power_red_mode() );
Neels Hofmeyr4f118412020-06-04 15:25:10 +020011090
11091 /* MSC pooling */
11092 /* FIXME: in SCCPlite, indicating how many MSCs should be connected does currently not work. Since
11093 * RESET->RESET-ACK is unconditionally negotiated for all configured MSCs, they always all appear as connected
11094 * to osmo-bsc. The MSC pooling tests however require disconnecting selected MSCs, and hence don't work out as
11095 * intended on SCCPlite. So for now, run these only for SCCP/M3UA. */
11096 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11097 execute( TC_mscpool_L3Compl_on_1_msc() );
11098 execute( TC_mscpool_L3Complete_by_imsi_round_robin() );
11099 execute( TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() );
11100 execute( TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() );
11101 execute( TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() );
11102 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() );
11103 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_1() );
11104 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_2() );
11105 execute( TC_mscpool_LU_by_tmsi_from_other_PLMN() );
11106 execute( TC_mscpool_paging_and_response_imsi() );
11107 execute( TC_mscpool_paging_and_response_tmsi() );
11108 execute( TC_mscpool_no_allow_attach_round_robin() );
11109 execute( TC_mscpool_no_allow_attach_valid_nri() );
11110 }
11111
Harald Welte99f3ca02018-06-14 13:40:29 +020011112 execute( TC_early_conn_fail() );
11113 execute( TC_late_conn_fail() );
Oliver Smithaf03bef2021-08-24 15:34:51 +020011114 execute( TC_stats_conn_fail() );
Harald Welte99f3ca02018-06-14 13:40:29 +020011115
Philipp Maier783681c2020-07-16 16:47:06 +020011116 /* Emergency call handling (deny / allow) */
11117 execute( TC_assignment_emerg_setup_allow() );
11118 execute( TC_assignment_emerg_setup_deny_msc() );
11119 execute( TC_assignment_emerg_setup_deny_bts() );
Philipp Maier82812002020-08-13 18:48:27 +020011120 execute( TC_emerg_premption() );
11121
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +070011122 /* Frequency hopping parameters handling */
11123 execute( TC_fh_params_chan_activ() );
11124 execute( TC_fh_params_imm_ass() );
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +070011125 execute( TC_fh_params_assignment_cmd() );
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +070011126 execute( TC_fh_params_handover_cmd() );
Vadim Yanitskiyca974032020-09-01 07:20:39 +070011127 execute( TC_fh_params_si4_cbch() );
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020011128
11129 if (mp_enable_lcs_tests) {
11130 execute( TC_lcs_loc_req_for_active_ms() );
11131 execute( TC_lcs_loc_req_for_active_ms_ta_req() );
11132 execute( TC_lcs_loc_req_for_idle_ms() );
11133 execute( TC_lcs_loc_req_no_subscriber() );
11134 execute( TC_lcs_loc_req_for_active_ms_le_timeout() );
11135 execute( TC_lcs_loc_req_for_active_ms_le_timeout2() );
11136 execute( TC_lcs_loc_req_for_idle_ms_no_pag_resp() );
11137 execute( TC_cm_service_during_lcs_loc_req() );
11138 execute( TC_ho_during_lcs_loc_req() );
11139 }
Neels Hofmeyrbf037052020-10-28 22:52:02 +000011140
11141 execute( TC_no_msc() );
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000011142
11143 execute( TC_refuse_chan_act_to_vamos() );
11144 execute( TC_refuse_mode_modif_to_vamos() );
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000011145
11146 execute( TC_reassignment_fr() );
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020011147
11148 execute( TC_cm_reestablishment() );
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020011149
11150 execute( TC_imm_ass_post_chan_ack() );
11151 execute( TC_imm_ass_pre_chan_ack() );
Neels Hofmeyr23158742021-09-07 19:08:07 +020011152 execute( TC_imm_ass_pre_ts_ack() );
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020011153 execute( TC_imm_ass_pre_chan_ack_dyn_ts() );
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020011154 execute( TC_imm_ass_pre_ts_ack_dyn_ts() );
Neels Hofmeyr5d7d13f2021-09-07 14:44:36 +020011155
11156 execute( TC_ctrl_trx_rf_locked() );
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011157
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011158 execute( TC_ratectr_all_available_allocated() );
11159 execute( TC_ratectr_all_available_allocated_dyn() );
11160
Neels Hofmeyrb7581872021-11-07 14:02:49 +010011161 execute( TC_cm_serv_rej() );
11162
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011163 execute( TC_lost_sdcch_during_assignment() );
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +010011164
11165 /* Run TC_ho_out_of_this_bsc last, because it may trigger a segfault before osmo-bsc's patch
11166 * with change-id I5a3345ab0005a73597f5c27207480912a2f5aae6 */
11167 execute( TC_ho_out_of_this_bsc() );
Harald Welte28d943e2017-11-25 15:00:50 +010011168}
11169
11170}