blob: 7bfc3870a767115a478c39460a26205a7b0624eb [file] [log] [blame]
Harald Welte28d943e2017-11-25 15:00:50 +01001module BSC_Tests {
2
Harald Welte21b46bd2017-12-17 19:46:32 +01003/* Integration Tests for OsmoBSC
Harald Weltea0630032018-03-20 21:09:55 +01004 * (C) 2017-2018 by Harald Welte <laforge@gnumonks.org>
Harald Welte21b46bd2017-12-17 19:46:32 +01005 * All rights reserved.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
Harald Welte34b5a952019-05-27 11:54:11 +020010 * SPDX-License-Identifier: GPL-2.0-or-later
11 *
Harald Welte21b46bd2017-12-17 19:46:32 +010012 * This test suite tests OsmoBSC while emulating both multiple BTS + MS as
13 * well as the MSC. See README for more details.
14 *
15 * There are test cases that run in so-called 'handler mode' and test cases
16 * that run directly on top of the BSSAP and RSL CodecPorts. The "handler mode"
17 * tests abstract the multiplexing/demultiplexing of multiple SCCP connections
18 * and/or RSL channels and are hence suitable for higher-level test cases, while
19 * the "raw" tests directly on top of the CodecPorts are more suitable for lower-
20 * level testing.
21 */
22
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +020023friend module BSC_Tests_VAMOS;
24
Neels Hofmeyr4f118412020-06-04 15:25:10 +020025import from Misc_Helpers all;
Harald Welte4003d112017-12-09 22:35:39 +010026import from General_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010027import from Osmocom_Types all;
Harald Welteae026692017-12-09 01:03:01 +010028import from GSM_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010029import from IPL4asp_Types all;
30
Harald Welte6f521d82017-12-11 19:52:02 +010031import from BSSAP_Types all;
Harald Welte6811d102019-04-14 22:23:14 +020032import from RAN_Adapter all;
Harald Welte47cd0e32020-08-21 12:39:11 +020033import from BSSAP_LE_Adapter all;
34import from BSSAP_LE_CodecPort all;
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020035import from BSSAP_LE_Types all;
36import from BSSLAP_Types all;
Harald Welteae026692017-12-09 01:03:01 +010037import from BSSAP_CodecPort all;
38import from BSSMAP_Templates all;
Harald Welte28d943e2017-11-25 15:00:50 +010039import from IPA_Emulation all;
Stefan Sperling830dc9d2018-02-12 21:08:28 +010040import from IPA_CodecPort all;
Harald Welteae026692017-12-09 01:03:01 +010041import from IPA_Types all;
Stefan Sperling0796a822018-10-05 13:01:39 +020042import from IPA_Testing all;
Harald Welteae026692017-12-09 01:03:01 +010043import from RSL_Types all;
Harald Welte624f9632017-12-16 19:26:04 +010044import from RSL_Emulation all;
Daniel Willmann191e0d92018-01-17 12:44:35 +010045import from MGCP_Emulation all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010046import from MGCP_Templates all;
47import from MGCP_Types all;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +020048import from MGCP_CodecPort all;
Harald Welte28d943e2017-11-25 15:00:50 +010049
Harald Welte96c94412017-12-09 03:12:45 +010050import from Osmocom_CTRL_Functions all;
Harald Weltea5d2ab22017-12-09 14:21:42 +010051import from Osmocom_CTRL_Types all;
Harald Welteffe55fc2018-01-17 22:39:54 +010052import from Osmocom_CTRL_Adapter all;
Harald Welte96c94412017-12-09 03:12:45 +010053
Daniel Willmannebdecc02020-08-12 15:30:17 +020054import from StatsD_Types all;
55import from StatsD_CodecPort all;
56import from StatsD_CodecPort_CtrlFunct all;
57import from StatsD_Checker all;
58
Harald Weltebc03c762018-02-12 18:09:38 +010059import from Osmocom_VTY_Functions all;
60import from TELNETasp_PortType all;
61
Harald Welte6f521d82017-12-11 19:52:02 +010062import from MobileL3_CommonIE_Types all;
Harald Weltee3bd6582018-01-31 22:51:25 +010063import from MobileL3_Types all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010064import from MobileL3_RRM_Types all;
Harald Welte6f521d82017-12-11 19:52:02 +010065import from L3_Templates all;
66import from GSM_RR_Types all;
67
Stefan Sperlingc307e682018-06-14 15:15:46 +020068import from SCCP_Templates all;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010069import from BSSMAP_Templates all;
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020070import from BSSMAP_LE_Templates all;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010071
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010072import from SCCPasp_Types all;
73
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020074import from GSM_SystemInformation all;
75import from GSM_RestOctets all;
Neels Hofmeyrad132f22020-07-08 02:20:16 +020076import from TCCConversion_Functions all;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020077
Neels Hofmeyrbf720202021-10-02 12:58:24 +020078type record of integer integer_list;
79
Harald Welte5d1a2202017-12-13 19:51:29 +010080const integer NUM_BTS := 3;
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +020081const integer NUM_BTS_CFG := 4; /* we have 4 BTS in the osmo-bsc.cfg (for inter-BSC HO tests) but use only 3 */
Neels Hofmeyrf246a922020-05-13 02:27:10 +020082const integer NUM_MSC := 3;
Harald Welteae026692017-12-09 01:03:01 +010083const float T3101_MAX := 12.0;
Harald Welte28d943e2017-11-25 15:00:50 +010084
Harald Welte799c97b2017-12-14 17:50:30 +010085/* make sure to sync this with the osmo-bts.cfg you're using */
Philipp Maiercb6cc482018-03-26 13:08:00 +020086const integer NUM_TCHH_PER_BTS := 2;
87const integer NUM_TCHF_PER_BTS := 4;
Neels Hofmeyr74083c22020-07-29 00:43:01 +020088const integer NUM_SDCCH_PER_BTS := 3;
Harald Welte799c97b2017-12-14 17:50:30 +010089
Neels Hofmeyrbf720202021-10-02 12:58:24 +020090/* Default Training Sequence Code expected for bts[i]:
91 * BTS 0 has BSIC 10 (and no explicit timeslot training_sequence_code config), so expecting TSC = (BSIC & 7) = 2.
92 * BTS 1 has BSIC 11, TSC = (BSIC & 7) = 3.
93 * BTS 2 has BSIC 12, TSC = (BSIC & 7) = 4.
94 * BTS 2 has BSIC 12, TSC = (BSIC & 7) = 4.
95 */
96const integer_list BTS_TSC := {
97 2,
98 3,
99 4,
100 4
101}
Harald Welte4003d112017-12-09 22:35:39 +0100102
Harald Welte21b46bd2017-12-17 19:46:32 +0100103/* per-BTS state which we keep */
Harald Welte96c94412017-12-09 03:12:45 +0100104type record BTS_State {
Harald Welte21b46bd2017-12-17 19:46:32 +0100105 /* component reference to the IPA_Client component used for RSL */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100106 IPA_Client rsl
Harald Welte96c94412017-12-09 03:12:45 +0100107}
108
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200109/* Default list of counters for an 'msc' entity. */
110const CounterNameVals counternames_msc_mscpool := {
111 { "mscpool:subscr:new", 0 },
112 { "mscpool:subscr:known", 0 },
113 { "mscpool:subscr:reattach", 0 },
114 { "mscpool:subscr:attach_lost", 0 },
115 { "mscpool:subscr:paged", 0 }
116};
117
Neels Hofmeyrbf037052020-10-28 22:52:02 +0000118/* List of global mscpool counters, not related to a specific 'msc' entity. */
119const CounterNameVals counternames_bsc_mscpool := {
120 { "mscpool:subscr:no_msc", 0 }
121};
122
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000123/* Default list of counters for 'bsc' and 'bts' entities. */
124const CounterNameVals counternames_bsc_bts_handover := {
125 { "assignment:attempted", 0 },
126 { "assignment:completed", 0 },
127 { "assignment:stopped", 0 },
128 { "assignment:no_channel", 0 },
129 { "assignment:timeout", 0 },
130 { "assignment:failed", 0 },
131 { "assignment:error", 0 },
132
133 { "handover:attempted", 0 },
134 { "handover:completed", 0 },
135 { "handover:stopped", 0 },
136 { "handover:no_channel", 0 },
137 { "handover:timeout", 0 },
138 { "handover:failed", 0 },
139 { "handover:error", 0 },
140
141 { "intra_cell_ho:attempted", 0 },
142 { "intra_cell_ho:completed", 0 },
143 { "intra_cell_ho:stopped", 0 },
144 { "intra_cell_ho:no_channel", 0 },
145 { "intra_cell_ho:timeout", 0 },
146 { "intra_cell_ho:failed", 0 },
147 { "intra_cell_ho:error", 0 },
148
149 { "intra_bsc_ho:attempted", 0 },
150 { "intra_bsc_ho:completed", 0 },
151 { "intra_bsc_ho:stopped", 0 },
152 { "intra_bsc_ho:no_channel", 0 },
153 { "intra_bsc_ho:timeout", 0 },
154 { "intra_bsc_ho:failed", 0 },
155 { "intra_bsc_ho:error", 0 },
156
157 { "interbsc_ho_out:attempted", 0 },
158 { "interbsc_ho_out:completed", 0 },
159 { "interbsc_ho_out:stopped", 0 },
160 { "interbsc_ho_out:timeout", 0 },
161 { "interbsc_ho_out:failed", 0 },
162 { "interbsc_ho_out:error", 0 },
163
164 { "interbsc_ho_in:attempted", 0 },
165 { "interbsc_ho_in:completed", 0 },
166 { "interbsc_ho_in:stopped", 0 },
167 { "interbsc_ho_in:no_channel", 0 },
168 { "interbsc_ho_in:timeout", 0 },
169 { "interbsc_ho_in:failed", 0 },
170 { "interbsc_ho_in:error", 0 }
171};
172
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100173const CounterNameVals counternames_bts_handover := {
174 { "incoming_intra_bsc_ho:attempted", 0 },
175 { "incoming_intra_bsc_ho:completed", 0 },
176 { "incoming_intra_bsc_ho:stopped", 0 },
177 { "incoming_intra_bsc_ho:no_channel", 0 },
178 { "incoming_intra_bsc_ho:timeout", 0 },
179 { "incoming_intra_bsc_ho:failed", 0 },
180 { "incoming_intra_bsc_ho:error", 0 }
181};
182
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200183/* Set of all System Information received during one RSL port's startup.
184 * Note that some System Information may be sent on RSL, but lacking actual SI data, to indicate that the BTS should not
185 * broadcast that SI type. That will be reflected as 'omit' here.
186 */
187type record SystemInformationConfig {
188 SystemInformationType1 si1 optional,
189 SystemInformationType2 si2 optional,
190 SystemInformationType2bis si2bis optional,
191 SystemInformationType2ter si2ter optional,
Neels Hofmeyrad132f22020-07-08 02:20:16 +0200192 SI2quaterRestOctetsList si2quater optional,
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200193 SystemInformationType3 si3 optional,
194 SystemInformationType4 si4 optional,
Pau Espin Pedrol28652d82021-02-09 20:20:17 +0100195 SystemInformationType13 si13 optional,
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200196 SystemInformationType5 si5 optional,
197 SystemInformationType5bis si5bis optional,
198 SystemInformationType5ter si5ter optional,
199 SystemInformationType6 si6 optional
200};
201
202const SystemInformationConfig SystemInformationConfig_omit := {
203 si1 := omit,
204 si2 := omit,
205 si2bis := omit,
206 si2ter := omit,
207 si2quater := omit,
208 si3 := omit,
209 si4 := omit,
210 si13 := omit,
211 si5 := omit,
212 si5bis := omit,
213 si5ter := omit,
214 si6 := omit
215};
216
217/* tr_EUTRAN_CellDesc with defaults used in BSC_Tests.ttcn */
218template EUTRAN_CellDesc tr_EUTRAN_CellDesc_default(template (present) uint16_t e_arfcn := ?,
219 template uint3_t meas_bw := 3)
220:= tr_EUTRAN_CellDesc(e_arfcn := e_arfcn,
221 meas_bw_presence := '1'B,
222 meas_bw := meas_bw);
223
224/* tr_EUTRAN_NeighbourCells with defaults used in BSC_Tests.ttcn */
Harald Welte65e419a2020-08-21 12:38:33 +0200225template EUTRAN_NeighbourCells tr_EUTRAN_NeighbourCells_default(template (present) EUTRAN_CellDescs cell_desc_list := { tr_EUTRAN_CellDesc_default },
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200226 template uint3_t prio := 3,
227 template (present) uint5_t thresh_high := 20,
228 template uint5_t thresh_low := 10,
229 template uint5_t qrxlevmin := 22)
230:= tr_EUTRAN_NeighbourCells(
231 cell_desc_list := cell_desc_list,
232 prio_presence := '1'B,
233 prio := prio,
234 thresh_high := thresh_high,
235 thresh_low_presence := '1'B,
236 thresh_low := thresh_low,
237 qrxlevmin_presence := '1'B,
238 qrxlevmin := qrxlevmin);
239
240template SystemInformationConfig SystemInformationConfig_default := {
241 si1 := {
242 cell_chan_desc := '8FB38000000000000000000000000000'O,
243 rach_control := {
244 max_retrans := RACH_MAX_RETRANS_7,
245 tx_integer := '1001'B,
246 cell_barr_access := false,
247 re_not_allowed := true,
248 acc := '0000010000000000'B
249 },
250 rest_octets := ?
251 },
252 si2 := {
253 bcch_freq_list := '00000000000000000000000000000000'O,
254 ncc_permitted := '11111111'B,
255 rach_control := {
256 max_retrans := RACH_MAX_RETRANS_7,
257 tx_integer := '1001'B,
258 cell_barr_access := false,
259 re_not_allowed := true,
260 acc := '0000010000000000'B
261 }
262 },
263 si2bis := omit,
264 si2ter := {
265 extd_bcch_freq_list := '8E320000000000000000000000000800'O,
266 rest_octets := ?
267 },
268 si2quater := {
269 tr_SI2quaterRestOctets_EUTRAN( repeated_neigh_cells := { tr_EUTRAN_NeighbourCells_default } )
270 },
271 si3 := {
272 cell_id := 0,
273 lai := {
274 mcc_mnc := '001F01'H,
275 lac := 1
276 },
277 ctrl_chan_desc := {
278 msc_r99 := true,
279 att := true,
280 bs_ag_blks_res := 1,
281 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
282 si22ind := false,
283 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
284 spare := '00'B,
285 bs_pa_mfrms := 3,
286 t3212 := 30
287 },
288 cell_options := {
289 dn_ind := false,
290 pwrc := false,
291 dtx := MS_SHALL_USE_UL_DTX,
292 radio_link_tout_div4 := 7
293 },
294 cell_sel_par := {
295 cell_resel_hyst_2dB := 2,
296 ms_txpwr_max_cch := 7,
297 acs := '0'B,
298 neci := true,
299 rxlev_access_min := 0
300 },
301 rach_control := {
302 max_retrans := RACH_MAX_RETRANS_7,
303 tx_integer := '1001'B,
304 cell_barr_access := false,
305 re_not_allowed := true,
306 acc := '0000010000000000'B
307 },
308 rest_octets := {
309 sel_params := {
310 presence := '0'B,
311 params := omit
312 },
313 pwr_offset := {
314 presence := '0'B,
315 offset := omit
316 },
317 si_2ter_ind := '1'B,
318 early_cm_ind := '0'B,
319 sched_where := {
320 presence := '0'B,
321 where := omit
322 },
323 gprs_ind := {
324 presence := '1'B,
325 ind := {
326 ra_colour := 0,
327 si13_pos := '0'B
328 }
329 },
330 umts_early_cm_ind := '1'B,
331 si2_quater_ind := {
332 presence := '1'B,
333 ind := '0'B
334 },
335 iu_mode_ind := omit,
336 si21_ind := {
337 presence := '0'B,
338 pos := omit
339 }
340 }
341 },
342 si4 := {
343 lai := {
344 mcc_mnc := '001F01'H,
345 lac := 1
346 },
347 cell_sel_par := {
348 cell_resel_hyst_2dB := 2,
349 ms_txpwr_max_cch := 7,
350 acs := '0'B,
351 neci := true,
352 rxlev_access_min := 0
353 },
354 rach_control := {
355 max_retrans := RACH_MAX_RETRANS_7,
356 tx_integer := '1001'B,
357 cell_barr_access := false,
358 re_not_allowed := true,
359 acc := '0000010000000000'B
360 },
Neels Hofmeyr74083c22020-07-29 00:43:01 +0200361 cbch_chan_desc := {
362 iei := '64'O,
363 v := {
364 chan_nr := {
365 u := {
366 sdcch4 := {
367 tag := '001'B,
368 sub_chan := 2
369 }
370 },
371 tn := 0
372 },
373 tsc := 2,
374 h := false,
375 arfcn := 871,
376 maio_hsn := omit
377 }
378 },
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200379 cbch_mobile_alloc := omit,
380 rest_octets := {
381 sel_params := {
382 presence := '0'B,
383 params := omit
384 },
385 pwr_offset := {
386 presence := '0'B,
387 offset := omit
388 },
389 gprs_ind := {
390 presence := '1'B,
391 ind := {
392 ra_colour := 0,
393 si13_pos := '0'B
394 }
395 },
396 s_presence := '0'B,
397 s := omit
398 }
399 },
Pau Espin Pedrol28652d82021-02-09 20:20:17 +0100400 si13 := {
401 rest_octets := {
402 presence := '1'B,
403 bcch_change_mark := ?,
404 si_change_field := '0000'B,
405 presence2 := '0'B,
406 si13_change_mark := omit,
407 gprs_ma := omit,
408 zero := '0'B, /* PBCCH not present in cell */
409 rac := 0,
410 spgc_ccch_sup := '0'B,
411 priority_access_thr := '110'B,
412 network_control_order := '00'B,
413 gprs_cell_opts := {
414 nmo := '01'B,
415 t3168 := '011'B,
416 t3192 := '010'B,
417 drx_timer_max := '011'B,
418 access_burst_type := '0'B,
419 control_ack_type := '1'B,
420 bs_cv_max := 15,
421 pan_presence := '1'B,
422 pan_dec := 1,
423 pan_inc := 1,
424 pan_max := '111'B,
425 ext_info_presence := ?,
426 ext_info_length := *,
427 ext_info := *
428 },
429 gprs_pwr_ctrl_params := {
430 alpha := 0,
431 t_avg_w := '10000'B,
432 t_avg_t := '10000'B,
433 pc_meas_chan := '0'B,
434 n_avg_i := '1000'B
435 }
436 }
437 },
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200438 si5 := {
439 bcch_freq_list := '10000000000000000000000000000000'O
440 },
441 si5bis := omit,
442 si5ter := {
443 extd_bcch_freq_list := '9E050020000000000000000000000000'O
444 },
445 si6 := {
446 cell_id := 0,
447 lai := {
448 mcc_mnc := '001F01'H,
449 lac := 1
450 },
451 cell_options := {
452 dtx_ext := '1'B,
453 pwrc := false,
454 dtx := '01'B,
455 radio_link_timeout := '0111'B
456 },
457 ncc_permitted := '11111111'B,
458 rest_octets := ?
459 }
460 };
461
462
463/* List of all the System Information received on all RSL ports */
464type record of SystemInformationConfig SystemInformationConfig_list;
465
466function f_sysinfo_dec_raw(inout SystemInformationConfig si, RSL_Message rsl)
467{
468 var RSL_IE_Body sysinfo_type_ie;
469 var RSL_IE_SysinfoType si_type;
470 var octetstring data;
471
472 if (f_rsl_find_ie(rsl, RSL_IE_SYSINFO_TYPE, sysinfo_type_ie) == false) {
473 setverdict(fail, "Cannot find RSL_IE_SYSINFO_TYPE");
474 mtc.stop;
475 }
476 si_type := sysinfo_type_ie.sysinfo_type;
477
478 if (rsl.msg_type == RSL_MT_BCCH_INFO) {
479 var RSL_IE_Body bcch_ie;
480 if (f_rsl_find_ie(rsl, RSL_IE_FULL_BCCH_INFO, bcch_ie)) {
481 data := bcch_ie.other.payload;
482 }
483 } else if (rsl.msg_type == RSL_MT_SACCH_FILL) {
484 var RSL_IE_Body l3_ie;
485 if (f_rsl_find_ie(rsl, RSL_IE_L3_INFO, l3_ie)) {
486 data := l3_ie.l3_info.payload;
487 }
488 } else {
489 setverdict(fail, "Don't understand this System Information message");
490 mtc.stop;
491 }
492
493 var boolean handled := false;
494
495 if (rsl.msg_type == RSL_MT_BCCH_INFO) {
496 handled := true;
497
498 if (si_type == RSL_SYSTEM_INFO_1) {
499 if (not isbound(data)) {
500 si.si1 := omit;
501 } else {
502 si.si1 := dec_SystemInformation(data).payload.si1;
503 }
504 } else if (si_type == RSL_SYSTEM_INFO_2) {
505 if (not isbound(data)) {
506 si.si2 := omit;
507 } else {
508 si.si2 := dec_SystemInformation(data).payload.si2;
509 }
510 } else if (si_type == RSL_SYSTEM_INFO_2bis) {
511 if (not isbound(data)) {
512 si.si2bis := omit;
513 } else {
514 si.si2bis := dec_SystemInformation(data).payload.si2bis;
515 }
516 } else if (si_type == RSL_SYSTEM_INFO_2ter) {
517 if (not isbound(data)) {
518 si.si2ter := omit;
519 } else {
520 si.si2ter := dec_SystemInformation(data).payload.si2ter;
521 }
522 } else if (si_type == RSL_SYSTEM_INFO_2quater) {
523 if (not isbound(data)) {
524 si.si2quater := {};
525 } else {
526 var SystemInformationType2quater decoded := dec_SystemInformation(data).payload.si2quater;
527 /* this is a *record* of SI2quaterRestOctets! (multiplexed) */
528 si.si2quater[decoded.rest_octets.si2quater_index] := decoded.rest_octets;
529 }
530 } else if (si_type == RSL_SYSTEM_INFO_3) {
531 if (not isbound(data)) {
532 si.si3 := omit;
533 } else {
534 si.si3 := dec_SystemInformation(data).payload.si3;
535 }
536 } else if (si_type == RSL_SYSTEM_INFO_4) {
537 if (not isbound(data)) {
538 si.si4 := omit;
539 } else {
540 si.si4 := dec_SystemInformation(data).payload.si4;
541 }
542 } else if (si_type == RSL_SYSTEM_INFO_13) {
543 if (not isbound(data)) {
544 si.si13 := omit;
545 } else {
Pau Espin Pedrol28652d82021-02-09 20:20:17 +0100546 si.si13 := dec_SystemInformation(data).payload.si13;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200547 }
548 } else {
549 handled := false;
550 }
551 } else if (rsl.msg_type == RSL_MT_SACCH_FILL) {
552 handled := true;
553
554 if (si_type == RSL_SYSTEM_INFO_5) {
555 if (not isbound(data)) {
556 si.si5 := omit;
557 } else {
558 si.si5 := dec_SystemInformation(data).payload.si5;
559 }
560 } else if (si_type == RSL_SYSTEM_INFO_5bis) {
561 if (not isbound(data)) {
562 si.si5bis := omit;
563 } else {
564 si.si5bis := dec_SystemInformation(data).payload.si5bis;
565 }
566 } else if (si_type == RSL_SYSTEM_INFO_5ter) {
567 if (not isbound(data)) {
568 si.si5ter := omit;
569 } else {
570 si.si5ter := dec_SystemInformation(data).payload.si5ter;
571 }
572 } else if (si_type == RSL_SYSTEM_INFO_6) {
573 if (not isbound(data)) {
574 si.si6 := omit;
575 } else {
576 si.si6 := dec_SystemInformation(data).payload.si6;
577 }
578 } else {
579 handled := false;
580 }
581 }
582
583 if (not handled) {
584 setverdict(fail, "Unexpected SI type in ", rsl.msg_type, " message: ", si_type);
585 }
586}
587
Harald Weltea4ca4462018-02-09 00:17:14 +0100588type component test_CT extends CTRL_Adapter_CT {
Harald Welte21b46bd2017-12-17 19:46:32 +0100589 /* Array of per-BTS state */
Harald Welte96c94412017-12-09 03:12:45 +0100590 var BTS_State bts[NUM_BTS];
Harald Welte89ab1912018-02-23 18:56:29 +0100591 /* RSL common Channel Port (for RSL_Emulation) */
592 port RSL_CCHAN_PT RSL_CCHAN[NUM_BTS];
Harald Welte21b46bd2017-12-17 19:46:32 +0100593 /* array of per-BTS RSL test ports */
Harald Welteae026692017-12-09 01:03:01 +0100594 port IPA_RSL_PT IPA_RSL[NUM_BTS];
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100595 port IPA_CODEC_PT IPA; /* Required for compilation of TC_rsl_unknown_unit_id() */
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +0200596 /* CTRL muxed over IPA in SCCPlite conn BSC<->MSC (or BSC-NAT) */
597 port IPA_CTRL_PT SCCPLITE_IPA_CTRL;
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100598 /* Configure/manage IPA_Emulation: */
599 port IPA_CFG_PT IPA_CFG_PORT;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100600
Daniel Willmann191e0d92018-01-17 12:44:35 +0100601 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +0100602 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100603
Daniel Willmannebdecc02020-08-12 15:30:17 +0200604 /* StatsD */
605 var StatsD_Checker_CT vc_STATSD;
606
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200607 var RAN_Adapter g_bssap[NUM_MSC];
Harald Welte47cd0e32020-08-21 12:39:11 +0200608 var BSSAP_LE_Adapter g_bssap_le;
Harald Weltea4ca4462018-02-09 00:17:14 +0100609 /* for old legacy-tests only */
610 port BSSAP_CODEC_PT BSSAP;
Harald Welte47cd0e32020-08-21 12:39:11 +0200611 port BSSAP_LE_CODEC_PT BSSAP_LE;
Harald Weltea4ca4462018-02-09 00:17:14 +0100612
Harald Welte21b46bd2017-12-17 19:46:32 +0100613 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +0100614 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +0100615
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200616 /* Osmux is enabled through VTY */
617 var boolean g_osmux_enabled := false;
618
Pau Espin Pedrolc675b612020-01-09 19:55:40 +0100619 /*Configure T(tias) over VTY, seconds */
620 var integer g_bsc_sccp_timer_ias := 7 * 60;
621 /*Configure T(tiar) over VTY, seconds */
622 var integer g_bsc_sccp_timer_iar := 15 * 60;
623
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +0200624 /* global test case guard timer (actual timeout value is set in f_init()) */
Harald Welteae026692017-12-09 01:03:01 +0100625 timer T_guard := 30.0;
626
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200627 var CounterNameValsList g_ctr_msc;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000628 var CounterNameValsList g_ctr_bsc;
629 var CounterNameValsList g_ctr_bts;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200630
631 /* System Information bytes as received during RSL startup, for each RSL[idx]. */
632 var SystemInformationConfig_list g_system_information := {};
Harald Welte28d943e2017-11-25 15:00:50 +0100633}
634
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200635type record of charstring phys_chan_configs;
Harald Welte28d943e2017-11-25 15:00:50 +0100636modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +0100637 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +0100638 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100639 /* port number to which to establish the IPA OML connections */
640 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +0100641 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +0100642 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +0100643 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +0100644 integer mp_bsc_ctrl_port := 4249;
Daniel Willmannebdecc02020-08-12 15:30:17 +0200645 /* port number to which to listen for STATSD metrics */
646 integer mp_bsc_statsd_port := 8125;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100647 /* IP address at which the test binds */
648 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100649
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200650 RAN_Configurations mp_bssap_cfg := {
651 {
652 transport := BSSAP_TRANSPORT_AoIP,
653 sccp_service_type := "mtp3_itu",
654 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
655 own_pc := 185, /* 0.23.1 first MSC emulation */
656 own_ssn := 254,
657 peer_pc := 187, /* 0.23.3 osmo-bsc */
658 peer_ssn := 254,
659 sio := '83'O,
Harald Weltecb0cc432020-06-21 19:42:31 +0200660 rctx := 1
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200661 },
662 {
663 transport := BSSAP_TRANSPORT_AoIP,
664 sccp_service_type := "mtp3_itu",
665 sctp_addr := { 23906, "127.0.0.1", 2905, "127.0.0.1" },
666 own_pc := 2, /* 0.0.2 second MSC emulation */
667 own_ssn := 254,
668 peer_pc := 187, /* 0.23.3 osmo-bsc */
669 peer_ssn := 254,
670 sio := '83'O,
671 rctx := 2
672 },
673 {
674 transport := BSSAP_TRANSPORT_AoIP,
675 sccp_service_type := "mtp3_itu",
676 sctp_addr := { 23907, "127.0.0.1", 2905, "127.0.0.1" },
677 own_pc := 3, /* 0.0.3 third MSC emulation */
678 own_ssn := 254,
679 peer_pc := 187, /* 0.23.3 osmo-bsc */
680 peer_ssn := 254,
681 sio := '83'O,
682 rctx := 3
683 }
Harald Weltea4ca4462018-02-09 00:17:14 +0100684 };
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +0200685
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200686 /* Must match per BTS config in osmo-bsc.cfg */
687 phys_chan_configs phys_chan_config := {
688 "CCCH+SDCCH4+CBCH",
689 "TCH/F",
690 "TCH/F",
691 "TCH/F",
692 "TCH/F",
Vadim Yanitskiy343c9eb2021-07-16 18:36:01 +0600693 "TCH/H",
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200694 "PDCH",
695 "PDCH"
696 };
697
Harald Welte47cd0e32020-08-21 12:39:11 +0200698 BSSAP_LE_Configuration mp_bssap_le_cfg := {
699 sccp_service_type := "mtp3_itu",
700 sctp_addr := { 23908, "127.0.0.1", 2905, "127.0.0.1" },
Neels Hofmeyrac086c12020-09-18 23:46:42 +0200701 own_pc := 190, /* 0.23.6 SMLC emulation */
Harald Welte47cd0e32020-08-21 12:39:11 +0200702 own_ssn := 252, /* SMLC side SSN */
703 peer_pc := 187, /* 0.23.3 osmo-bsc */
704 peer_ssn := 250, /* BSC side SSN */
705 sio := '83'O,
706 rctx := 6
707 };
Neels Hofmeyrcfe44062020-10-15 02:28:08 +0200708 boolean mp_enable_lcs_tests := true;
Harald Welte47cd0e32020-08-21 12:39:11 +0200709
Pau Espin Pedrol8f30ccd2019-11-01 17:30:57 +0100710 /* Value set in osmo-bsc.cfg "ms max power" */
711 uint8_t mp_exp_ms_power_level := 7;
Harald Weltea4ca4462018-02-09 00:17:14 +0100712}
713
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +0200714friend function f_gen_test_hdlr_pars(integer bssap_idx := 0) return TestHdlrParams {
Philipp Maier48604732018-10-09 15:00:37 +0200715
716 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200717 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier48604732018-10-09 15:00:37 +0200718 pars.aoip := true;
719 } else {
720 pars.aoip := false;
721 }
Pau Espin Pedrol8f30ccd2019-11-01 17:30:57 +0100722 pars.exp_ms_power_level := mp_exp_ms_power_level;
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200723 pars.mscpool.bssap_idx := bssap_idx;
Neels Hofmeyrbf720202021-10-02 12:58:24 +0200724 pars.expect_tsc := BTS_TSC[0];
Vadim Yanitskiy96bb9cb2021-12-10 21:14:15 +0300725 pars.imsi := f_rnd_imsi('00101'H);
726
727 log(testcasename(), ": using IMSI ", pars.imsi);
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200728
Philipp Maier48604732018-10-09 15:00:37 +0200729 return pars;
730}
731
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200732/* Convenience functions for rate counters using g_ctr_msc. */
733
734private function f_ctrs_msc_init(integer mscs_count := NUM_MSC, CounterNameVals counternames := counternames_msc_mscpool) runs on test_CT {
735 g_ctr_msc := f_counter_name_vals_get_n(IPA_CTRL, "msc", mscs_count, counternames);
736 log("initial msc rate counters: ", g_ctr_msc);
737}
738
739private function f_ctrs_msc_add(integer msc_nr, charstring countername, integer val := 1) runs on test_CT {
Neels Hofmeyr9656e922020-06-30 01:27:01 +0200740 f_counter_name_vals_list_add(g_ctr_msc, msc_nr, countername, val);
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200741}
742
743/* f_ctrs_msc_init();
744 * f_do_thing(on_msc := 0);
745 * f_do_thing(on_msc := 0);
746 * f_do_other(on_msc := 1);
747 * f_ctrs_msc_add(0, "thing", 2);
748 * f_ctrs_msc_add(1, "other");
749 * f_ctrs_msc_verify();
750 */
751private function f_ctrs_msc_verify() runs on test_CT {
752 log("verifying msc rate counters: ", g_ctr_msc);
753 f_counter_name_vals_expect_n(IPA_CTRL, "msc", g_ctr_msc);
754}
755
756/* convenience: f_ctrs_msc_add() and f_ctrs_msc_verify() in one call.
757 * f_ctrs_msc_init();
758 * f_do_thing(on_msc := 0);
759 * f_do_thing(on_msc := 0);
760 * f_do_thing(on_msc := 0);
761 * f_ctrs_msc_expect(0, "thing", 3);
762 */
763private function f_ctrs_msc_expect(integer msc_nr, charstring countername, integer val := 1) runs on test_CT {
764 f_ctrs_msc_add(msc_nr, countername, val);
765 f_ctrs_msc_verify();
766}
767
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000768/* Convenience functions for rate counters using g_ctr_bts, always also including g_ctr_bsc. */
769
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100770private function f_ctrs_bts_init(integer bts_count := NUM_BTS, CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000771 g_ctr_bts := f_counter_name_vals_get_n(IPA_CTRL, "bts", bts_count, counternames);
Neels Hofmeyr4dec8cc2021-11-29 15:59:44 +0100772 log("initial bts rate counters: ", g_ctr_bts);
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100773}
774
775function f_ctrs_bsc_and_bts_init(integer bts_count := NUM_BTS, CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
776 f_ctrs_bts_init(bts_count, counternames);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000777 f_ctrs_bsc_init(counternames);
778}
779
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100780private function f_ctrs_bsc_and_bts_handover_init(integer bts_count := NUM_BTS) runs on test_CT {
781 var CounterNameVals bts_names := counternames_bsc_bts_handover & counternames_bts_handover;
Neels Hofmeyr4dec8cc2021-11-29 15:59:44 +0100782 f_ctrs_bts_init(bts_count, bts_names);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100783 f_ctrs_bsc_init(counternames_bsc_bts_handover);
784}
785
786private function f_ctrs_bts_add(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000787 f_counter_name_vals_list_add(g_ctr_bts, bts_nr, countername, val);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100788}
789
790private function f_ctrs_bsc_and_bts_add(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
791 f_ctrs_bts_add(bts_nr, countername, val);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000792 f_ctrs_bsc_add(countername, val);
793}
794
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100795function f_ctrs_bts_verify() runs on test_CT {
796 f_counter_name_vals_expect_n(IPA_CTRL, "bts", g_ctr_bts);
797}
798
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000799/* f_ctrs_bsc_and_bts_init();
800 * f_do_thing(on_bts := 0);
801 * f_do_thing(on_bts := 0);
802 * f_do_other(on_bts := 1);
803 * f_ctrs_bsc_and_bts_add(0, "thing", 2);
804 * f_ctrs_bsc_and_bts_add(1, "other");
805 * f_ctrs_bsc_and_bts_verify();
806 */
807private function f_ctrs_bsc_and_bts_verify() runs on test_CT {
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100808 f_ctrs_bts_verify();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000809 f_ctrs_bsc_verify();
810}
811
812/* convenience: f_ctrs_bsc_and_bts_add() and f_ctrs_bsc_and_bts_verify() in one call.
813 * f_ctrs_bsc_and_bts_init();
814 * f_do_thing(on_bts := 0);
815 * f_do_thing(on_bts := 0);
816 * f_do_thing(on_bts := 0);
817 * f_ctrs_bsc_and_bts_expect(0, "thing", 3);
818 */
819private function f_ctrs_bsc_and_bts_expect(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
820 f_ctrs_bsc_and_bts_add(bts_nr, countername, val);
821 f_ctrs_bsc_and_bts_verify();
822}
823
824
825/* Convenience functions for rate counters using g_ctr_bsc. */
826
827private function f_ctrs_bsc_init(CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
828 g_ctr_bsc := f_counter_name_vals_get_n(IPA_CTRL, "bsc", 1, counternames);
829 log("initial bsc rate counters: ", g_ctr_bsc);
830}
831
832private function f_ctrs_bsc_add(charstring countername, integer val := 1) runs on test_CT {
833 f_counter_name_vals_list_add(g_ctr_bsc, 0, countername, val);
834}
835
836/* f_ctrs_bsc_init();
837 * f_do_thing();
838 * f_do_thing();
839 * f_do_other();
840 * f_ctrs_bsc_add("thing", 2);
841 * f_ctrs_bsc_add("other");
842 * f_ctrs_bsc_verify();
843 */
844private function f_ctrs_bsc_verify() runs on test_CT {
845 f_counter_name_vals_expect_n(IPA_CTRL, "bsc", g_ctr_bsc);
846}
847
848/* convenience: f_ctrs_bsc_add() and f_ctrs_bsc_verify() in one call.
849 * f_ctrs_bsc_init();
850 * f_do_thing();
851 * f_ctrs_bsc_expect("thing", 1);
852 */
853private function f_ctrs_bsc_expect(charstring countername, integer val := 1) runs on test_CT {
854 f_ctrs_bsc_add(countername, val);
855 f_ctrs_bsc_verify();
856}
857
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200858
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +0200859friend function f_shutdown_helper() runs on test_CT {
Daniel Willmann637ef6c2018-07-25 10:49:09 +0200860 all component.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100861 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200862 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100863}
864
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200865private function f_legacy_bssap_reset(integer bssap_idx := 0) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +0100866 var BSSAP_N_UNITDATA_ind ud_ind;
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200867 var boolean reset_received := false;
Harald Weltea4ca4462018-02-09 00:17:14 +0100868 timer T := 5.0;
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200869 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
870 ts_BSSMAP_Reset(0, g_osmux_enabled)));
Harald Weltea4ca4462018-02-09 00:17:14 +0100871 T.start;
872 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200873 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap[bssap_idx].sccp_addr_own, g_bssap[bssap_idx].sccp_addr_peer,
874 tr_BSSMAP_ResetAck(g_osmux_enabled))) {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200875 log("BSSMAP: Received RESET-ACK in response to RESET, we're ready to go!");
Harald Weltea4ca4462018-02-09 00:17:14 +0100876 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200877 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200878 log("BSSMAP: Respoding to inbound RESET with RESET-ACK");
Harald Weltea4ca4462018-02-09 00:17:14 +0100879 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200880 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200881 reset_received := true;
Harald Weltea4ca4462018-02-09 00:17:14 +0100882 repeat;
883 }
884 [] BSSAP.receive { repeat; }
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200885 [] T.timeout {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200886 log("BSSMAP: Timeout waiting for RESET-ACK after sending RESET");
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200887 /* If we received a RESET after ours was sent, it
888 may be a race condition where the other peer beacame
889 available after we sent it, but we are in a desired
890 state anyway, so go forward. */
891 if (not reset_received) {
892 setverdict(fail);
893 }
894 }
Harald Weltea4ca4462018-02-09 00:17:14 +0100895 }
Harald Welte28d943e2017-11-25 15:00:50 +0100896}
897
Harald Welteae026692017-12-09 01:03:01 +0100898type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100899 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100900 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100901 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100902 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100903 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100904 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100905 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100906 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100907}
908
Harald Welte21b46bd2017-12-17 19:46:32 +0100909/*! Start the IPA/RSL related bits for one IPA_Client.
910 * \param clnt IPA_Client for which to establish
911 * \param bsc_host IP address / hostname of the BSC
912 * \param bsc_port TCP port number of the BSC
913 * \param i number identifying this BTS
914 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100915function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
916 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100917runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100918 timer T := 10.0;
919
Harald Welte96c94412017-12-09 03:12:45 +0100920 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welte71389132021-12-09 21:58:18 +0100921 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA") alive;
Harald Welteae026692017-12-09 01:03:01 +0100922 clnt.ccm_pars := c_IPA_default_ccm_pars;
923 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
924 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100925 if (handler_mode) {
Harald Welte71389132021-12-09 21:58:18 +0100926 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL") alive;
Harald Welte89ab1912018-02-23 18:56:29 +0100927 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100928 }
Harald Welteae026692017-12-09 01:03:01 +0100929
930 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100931 connect(clnt.vc_IPA:CFG_PORT, self:IPA_CFG_PORT);
Harald Welte624f9632017-12-16 19:26:04 +0100932 if (handler_mode) {
933 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
934 } else {
935 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
936 }
Harald Welteae026692017-12-09 01:03:01 +0100937
Harald Welte5d1a2202017-12-13 19:51:29 +0100938 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100939 if (handler_mode) {
940 clnt.vc_RSL.start(RSL_Emulation.main());
941 return;
942 }
Harald Welteae026692017-12-09 01:03:01 +0100943
944 /* wait for IPA RSL link to connect and send ID ACK */
945 T.start;
946 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700947 [] IPA_RSL[i].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) {
Harald Welteae026692017-12-09 01:03:01 +0100948 T.stop;
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +0700949 IPA_RSL[i].send(ts_ASP_RSL_UD(ts_RSL_PAGING_LOAD_IND(23)));
Harald Welteae026692017-12-09 01:03:01 +0100950 }
Harald Welte60e823a2017-12-10 14:10:59 +0100951 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100952 [] IPA_RSL[i].receive { repeat }
953 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100954 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200955 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100956 }
957 }
958}
959
Harald Welte12055472018-03-17 20:10:08 +0100960function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100961 var IPL4asp_Types.Result res := {
962 errorCode := omit,
963 connId := omit,
964 os_error_code := omit,
965 os_error_text := omit
966 };
967
Harald Welte12055472018-03-17 20:10:08 +0100968 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
969 return;
970 }
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100971
972 /* Alive components don't finish sockets (TCP FIN) when they are
973 * stopped. Hence, we need to manually call close() on them to make sure
974 * the IUT knows about it. */
975 f_ipa_cfg_disconnect(IPA_CFG_PORT, res);
976
Harald Welte12055472018-03-17 20:10:08 +0100977 clnt.vc_IPA.stop;
978 if (isbound(clnt.vc_RSL)) {
979 clnt.vc_RSL.stop;
980 }
981}
982
Harald Welte21b46bd2017-12-17 19:46:32 +0100983/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100984function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
985 timer T := secs_max;
986 T.start;
987 while (true) {
988 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
989 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100990 /* the 'degraded' state exists from OML connection time, and we have to wait
991 * until all MO's are initialized */
992 T.start(1.0);
993 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100994 return;
995 }
Harald Weltef0d6ac62017-12-17 17:02:21 +0100996 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100997 if (not T.running) {
Max99253902018-11-16 17:57:39 +0100998 setverdict(fail, "Timeout waiting for BTS" & int2str(bts_nr) & " oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +0200999 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001000 }
1001 }
1002}
1003
Harald Welte21b46bd2017-12-17 19:46:32 +01001004/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +01001005altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +01001006 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +01001007 [] T_guard.timeout {
1008 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +02001009 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +01001010 }
Harald Welte60e823a2017-12-10 14:10:59 +01001011 /* always respond with RESET ACK to RESET */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001012 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Welte60e823a2017-12-10 14:10:59 +01001013 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001014 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Welte69c1c262017-12-13 21:02:08 +01001015 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +01001016 }
Harald Welte28d943e2017-11-25 15:00:50 +01001017}
1018
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001019altstep no_bssmap_reset() runs on test_CT {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001020 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001021 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +02001022 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001023 }
1024}
1025
Daniel Willmann191e0d92018-01-17 12:44:35 +01001026function f_init_mgcp(charstring id) runs on test_CT {
1027 id := id & "-MGCP";
1028
1029 var MGCPOps ops := {
1030 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
1031 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
1032 };
1033 var MGCP_conn_parameters mgcp_pars := {
1034 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +01001035 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +01001036 mgw_ip := mp_test_ip,
Pau Espin Pedrol1a026a52019-06-18 17:21:52 +02001037 mgw_udp_port := 2427,
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02001038 /* Enable it for SCCPlite, since we have 2 MGCP sockets towards MGW (UDP one +
1039 the on with MGCP over IPA forwarded from MSC one) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001040 multi_conn_mode := (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER)
Daniel Willmann191e0d92018-01-17 12:44:35 +01001041 };
1042
Harald Welte71389132021-12-09 21:58:18 +01001043 vc_MGCP := MGCP_Emulation_CT.create(id) alive;
Daniel Willmann191e0d92018-01-17 12:44:35 +01001044 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
1045}
1046
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001047/* Enable or disable (current default) Osmux. When enabling, BSSMAP Reset
1048 * contains extra IE (OsmuxSupport) and osmo-bsc will handle AssignReq with
1049 * OsmuxCID IE.
1050 */
1051private function f_vty_allow_osmux(boolean allow) runs on test_CT {
1052 f_vty_enter_cfg_msc(BSCVTY, 0);
1053 if (allow) {
1054 f_vty_transceive(BSCVTY, "osmux on");
1055 } else {
1056 f_vty_transceive(BSCVTY, "osmux off");
1057 }
1058 f_vty_transceive(BSCVTY, "exit");
1059 f_vty_transceive(BSCVTY, "exit");
1060 g_osmux_enabled := allow;
1061}
1062
Max2253c0b2018-11-06 19:28:05 +01001063function f_init_vty(charstring id := "foo") runs on test_CT {
Harald Welte94e0c342018-04-07 11:33:23 +02001064 if (BSCVTY.checkstate("Mapped")) {
1065 /* skip initialization if already executed once */
1066 return;
1067 }
Harald Weltebc03c762018-02-12 18:09:38 +01001068 map(self:BSCVTY, system:BSCVTY);
1069 f_vty_set_prompts(BSCVTY);
1070 f_vty_transceive(BSCVTY, "enable");
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01001071 f_cs7_inst_0_cfg(BSCVTY, {"sccp-timer ias " & int2str(g_bsc_sccp_timer_ias),
1072 "sccp-timer iar " & int2str(g_bsc_sccp_timer_iar)});
Harald Weltebc03c762018-02-12 18:09:38 +01001073}
1074
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +02001075friend function f_logp(TELNETasp_PT pt, charstring log_msg)
Neels Hofmeyr4f118412020-06-04 15:25:10 +02001076{
1077 // log on TTCN3 log output
1078 log(log_msg);
1079 // log in stderr log
Neels Hofmeyr767548a2020-08-09 20:26:07 +00001080 f_vty_transceive(pt, "logp lglobal notice TTCN3 f_logp(): " & log_msg);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02001081}
1082
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001083private function f_sysinfo_seen(integer rsl_idx, RSL_Message rsl) runs on test_CT
1084{
1085 if (rsl_idx >= lengthof(g_system_information)) {
1086 g_system_information[rsl_idx] := SystemInformationConfig_omit
1087 }
1088 f_sysinfo_dec_raw(g_system_information[rsl_idx], rsl);
1089}
1090
1091altstep as_catch_RSL_sysinfo(integer rsl_idx) runs on test_CT {
1092 var ASP_RSL_Unitdata rx_rsl_ud;
1093
1094 /* For handler_mode := false, receiving the RSL bootstrap messages directly on IPA_RSL */
1095 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
1096 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1097 repeat;
1098 }
1099 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
1100 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1101 repeat;
1102 }
1103 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> value rx_rsl_ud {
1104 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1105 repeat;
1106 }
1107 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_SACCH_FILL)) -> value rx_rsl_ud {
1108 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1109 repeat;
1110 }
1111
1112 /* For handler_mode := true, receiving the RSL bootstrap messages via RSL_Emulation */
1113 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
1114 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1115 repeat;
1116 }
1117 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
1118 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1119 repeat;
1120 }
1121 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> value rx_rsl_ud {
1122 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1123 repeat;
1124 }
1125 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_SACCH_FILL)) -> value rx_rsl_ud {
1126 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1127 repeat;
1128 }
1129}
1130
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001131/* TODO: use BooleanList from COMMON/src/General_Types.ttcn */
1132private type record of boolean my_BooleanList;
1133
1134private function f_vty_msc_allow_attach(TELNETasp_PT pt, my_BooleanList allow_attach_list)
1135{
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001136 var charstring config := f_vty_transceive_ret(pt, "show running-config");
1137
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001138 for (var integer msc_nr := 0; msc_nr < sizeof(allow_attach_list); msc_nr := msc_nr+1) {
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001139 if (f_strstr(config, "\nmsc " & int2str(msc_nr) & "\n") < 0) {
1140 /* There is no 'msc N' for this msc_nr in the running config, so don't create an empty msc by
1141 * stepping into that config node. */
1142 log("msc ", msc_nr, " is not configured, skipping");
1143 continue;
1144 }
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001145 f_vty_enter_cfg_msc(pt, msc_nr);
1146 if (allow_attach_list[msc_nr]) {
1147 /* strict := false: ignore if osmo-bsc does not support this config option (latest build) */
1148 f_vty_transceive(pt, "allow-attach", strict := false);
1149 } else {
1150 f_vty_transceive(pt, "no allow-attach", strict := false);
1151 }
1152 f_vty_transceive(pt, "exit");
1153 f_vty_transceive(pt, "exit");
1154 }
1155}
1156
Harald Welte21b46bd2017-12-17 19:46:32 +01001157/* global initialization function
1158 * \param nr_bts Number of BTSs we should start/bring up
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001159 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false).
1160 * \param nr_msc Number of virtual MSCs to bring up to connect to osmo-bsc.
1161 */
1162function f_init(integer nr_bts := NUM_BTS, boolean handler_mode := false, boolean allow_osmux := false,
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001163 integer nr_msc := 1, float guard_timeout := 30.0) runs on test_CT {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001164 var integer bssap_idx;
Harald Welte28d943e2017-11-25 15:00:50 +01001165
Harald Welteae026692017-12-09 01:03:01 +01001166 if (g_initialized) {
1167 return;
Harald Welte28d943e2017-11-25 15:00:50 +01001168 }
Harald Welteae026692017-12-09 01:03:01 +01001169 g_initialized := true;
1170
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001171 T_guard.start(guard_timeout);
Daniel Willmanne68f9272018-11-27 15:15:28 +01001172 activate(as_Tguard());
1173
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001174 f_init_vty("VirtMSC");
Pau Espin Pedrol23510fb2021-07-20 17:00:38 +02001175 f_vty_allow_osmux(allow_osmux);
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001176
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001177 var my_BooleanList allow_attach := { false, false, false };
Daniel Willmannebdecc02020-08-12 15:30:17 +02001178 f_init_statsd("VirtMSC", vc_STATSD, mp_test_ip, mp_bsc_statsd_port);
1179
Neels Hofmeyr9db8e0e2021-08-23 20:45:58 +02001180 /* Make sure each MSC's internal state is "DISCONNECTED" at first */
1181 for (bssap_idx := 0; bssap_idx < NUM_MSC; bssap_idx := bssap_idx+1) {
1182 f_vty_transceive(BSCVTY, "msc " & int2str(bssap_idx) & " bssmap reset", strict := false);
1183 }
1184
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001185 for (bssap_idx := 0; bssap_idx < nr_msc; bssap_idx := bssap_idx+1) {
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001186 allow_attach[bssap_idx] := true;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001187 /* Call a function of our 'parent component' RAN_Adapter_CT to start the
1188 * MSC-side BSSAP emulation */
1189 if (handler_mode) {
1190 var RanOps ranops := MSC_RanOps;
1191 ranops.use_osmux := g_osmux_enabled;
1192 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", ranops);
1193 connect(self:SCCPLITE_IPA_CTRL, g_bssap[bssap_idx].vc_RAN:CTRL_CLIENT);
1194 f_ran_adapter_start(g_bssap[bssap_idx]);
1195 } else {
1196 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", omit);
1197 connect(self:BSSAP, g_bssap[bssap_idx].vc_SCCP:SCCP_SP_PORT);
1198 f_ran_adapter_start(g_bssap[bssap_idx]);
1199 f_legacy_bssap_reset();
1200 }
Harald Welte67089ee2018-01-17 22:19:03 +01001201 }
Harald Welted5833a82018-05-27 16:52:56 +02001202
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02001203 if (mp_enable_lcs_tests) {
1204 if (handler_mode) {
1205 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", SMLC_BssapLeOps);
1206 } else {
1207 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", omit);
1208 connect(self:BSSAP_LE, g_bssap_le.vc_SCCP:SCCP_SP_PORT);
1209 }
1210 f_bssap_le_adapter_start(g_bssap_le);
Harald Welte47cd0e32020-08-21 12:39:11 +02001211 }
Harald Welte47cd0e32020-08-21 12:39:11 +02001212
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001213 /* start the test with exactly all enabled MSCs allowed to attach */
1214 f_vty_msc_allow_attach(BSCVTY, allow_attach);
1215
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01001216 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +01001217
Daniel Willmann191e0d92018-01-17 12:44:35 +01001218 f_init_mgcp("VirtMSC");
1219
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001220 for (var integer i := 0; i < nr_bts; i := i+1) {
1221 f_init_bts(i, handler_mode);
Harald Welte696ddb62017-12-08 14:01:43 +01001222 }
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001223}
Harald Welte696ddb62017-12-08 14:01:43 +01001224
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001225function f_init_bts(integer bts_idx := 0, boolean handler_mode := false)
1226runs on test_CT {
1227 /* wait until osmo-bts-omldummy has respawned */
1228 f_wait_oml(bts_idx, "degraded", 5.0);
1229
1230 /* start RSL connection */
1231 f_ipa_rsl_start(bts[bts_idx].rsl, mp_bsc_ip, mp_bsc_rsl_port, bts_idx, handler_mode);
1232 /* wait until BSC tells us "connected" */
1233 f_wait_oml(bts_idx, "connected", 5.0);
Harald Welte28d943e2017-11-25 15:00:50 +01001234}
1235
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001236function f_init_bts_and_check_sysinfo(integer bts_idx := 0, boolean handler_mode := false,
1237 template SystemInformationConfig expect_si)
1238runs on test_CT {
1239 var default sysinfo := activate(as_catch_RSL_sysinfo(bts_idx));
1240
1241 f_init_bts(bts_idx, handler_mode);
1242
1243 /* Give some time to (hopefully/most likely) collect all system informations from RSL startup.
1244 * We could stop as soon as all expected SI are received, but then we might miss SI that we don't expect and
1245 * that might be sent afterwards. So rather give a generous timeout and be quite sure to catch all SI.
1246 */
1247 f_sleep(5.0);
1248 log("RSL ", bts_idx, " SYSTEM INFORMATION: ", g_system_information[bts_idx]);
1249
1250 deactivate(sysinfo);
1251
1252 if (match(g_system_information[bts_idx], expect_si)) {
1253 setverdict(pass);
1254 } else {
1255 log("RSL ", bts_idx, ": EXPECTED SI: ", expect_si);
1256 log("RSL ", bts_idx, ": GOT SI: ", g_system_information[bts_idx]);
1257 setverdict(fail, "received SI does not match expectations");
1258 return;
1259 }
1260}
1261
Maxd4e56962018-10-31 19:08:25 +01001262/* expect to receive a RSL message matching a specified template on a given BTS / stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001263function 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 +01001264runs on test_CT return RSL_Message {
1265 var ASP_RSL_Unitdata rx_rsl_ud;
1266 timer T := t_secs;
1267
1268 T.start;
1269 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001270 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
Harald Welteae026692017-12-09 01:03:01 +01001271 T.stop;
1272 }
1273 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +01001274 [] T.timeout {
1275 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +02001276 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +01001277 }
Harald Welteae026692017-12-09 01:03:01 +01001278 }
1279 return rx_rsl_ud.rsl;
1280}
1281
Harald Welte21b46bd2017-12-17 19:46:32 +01001282/* helper function to transmit RSL on a given BTS/stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001283function 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 +01001284runs on test_CT {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001285 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(t_tx, sid));
Harald Welteae026692017-12-09 01:03:01 +01001286}
1287
1288
Harald Welte4003d112017-12-09 22:35:39 +01001289/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +01001290testcase TC_chan_act_noreply() runs on test_CT {
1291 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +01001292 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +01001293
Harald Welte89d42e82017-12-17 16:42:41 +01001294 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +01001295
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001296 IPA_RSL[0].send(ts_ASP_RSL_UD(ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +01001297 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001298 f_shutdown_helper();
Harald Welte28d943e2017-11-25 15:00:50 +01001299}
1300
Neels Hofmeyr734b1a32021-11-29 16:00:17 +01001301const CounterNameVals counternames_bts_chreq := {
1302 { "chreq:total", 0 },
1303 { "chreq:attempted_emerg", 0 },
1304 { "chreq:attempted_call", 0 },
1305 { "chreq:attempted_location_upd", 0 },
1306 { "chreq:attempted_pag", 0 },
1307 { "chreq:attempted_pdch", 0 },
1308 { "chreq:attempted_other", 0 },
1309 { "chreq:attempted_unknown", 0 },
1310 { "chreq:successful", 0 },
1311 { "chreq:successful_emerg", 0 },
1312 { "chreq:successful_call", 0 },
1313 { "chreq:successful_location_upd", 0 },
1314 { "chreq:successful_pag", 0 },
1315 { "chreq:successful_pdch", 0 },
1316 { "chreq:successful_other", 0 },
1317 { "chreq:successful_unknown", 0 },
1318 { "chreq:no_channel", 0 },
1319 { "chreq:max_delay_exceeded", 0 }
1320};
1321
1322/* verify the "chreq:*" counters */
1323private function f_chan_act_counter(OCT1 ra, charstring chreq_ctr_suffix) runs on test_CT
1324{
1325 var GsmFrameNumber fn := 23;
1326
1327 f_logp(BSCVTY, "f_chan_act_counter(" & chreq_ctr_suffix & ")");
1328
1329 var RSL_Message rx_rsl;
1330 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1331 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1332 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1333
1334 f_ctrs_bts_add(0, "chreq:total");
1335 f_ctrs_bts_add(0, "chreq:attempted_" & chreq_ctr_suffix);
1336 f_ctrs_bts_verify();
1337
1338 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
1339 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
1340
1341 f_ctrs_bts_add(0, "chreq:successful");
1342 f_ctrs_bts_add(0, "chreq:successful_" & chreq_ctr_suffix);
1343 f_ctrs_bts_verify();
1344
1345 /* test is done, release RSL Conn Fail Ind to clean up */
1346 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1347 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1348 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
1349 f_sleep(1.0);
1350}
1351
Harald Welte4003d112017-12-09 22:35:39 +01001352testcase TC_chan_act_counter() runs on test_CT {
1353 var BSSAP_N_UNITDATA_ind ud_ind;
1354 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +01001355 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +01001356
Harald Welte89d42e82017-12-17 16:42:41 +01001357 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001358
Neels Hofmeyr734b1a32021-11-29 16:00:17 +01001359 f_vty_allow_emerg_bts(true, 0);
1360
1361 f_ctrs_bts_init(1, counternames_bts_chreq);
1362
1363 /* emergency call: RA & 0xe0 == 0xa0 --> CHREQ_T_EMERG_CALL */
1364 f_chan_act_counter('a3'O, "emerg");
1365
1366 /* voice TCH/H: RA & 0xf0 == 0x40 --> CHREQ_T_VOICE_CALL_TCH_H */
1367 f_chan_act_counter('43'O, "call");
1368
1369 /* LU: RA & 0xf0 == 0x00 --> CHREQ_T_LOCATION_UPD */
1370 f_chan_act_counter('03'O, "location_upd");
1371
1372 /* Paging: RA & 0xf0 == 0x20 --> CHREQ_T_PAG_R_TCH_F */
1373 f_chan_act_counter('23'O, "pag");
1374 /* Paging: RA & 0xf0 == 0x30 --> CHREQ_T_PAG_R_TCH_FH */
1375 f_chan_act_counter('33'O, "pag");
1376
1377 /* LU: RA & 0xfc == 0x78 --> CHREQ_T_PDCH_TWO_PHASE */
1378 /* no PCU, so PDCH not allowed. Skip this test for now. */
1379 /* f_chan_act_counter('7b'O, "pdch"); */
1380
1381 /* LU: RA & 0xf0 == 0x10 --> CHREQ_T_SDCCH */
1382 f_chan_act_counter('13'O, "other");
Harald Welte4003d112017-12-09 22:35:39 +01001383
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001384 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001385}
1386
Harald Welteae026692017-12-09 01:03:01 +01001387/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
Philipp Maier9c60a622020-07-09 15:08:46 +02001388private function f_TC_chan_act_ack_noest(OCT1 ra := '23'O) runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +01001389 var RSL_Message rx_rsl;
1390
Harald Welteae026692017-12-09 01:03:01 +01001391 /* Send CHAN RQD and wait for allocation; acknowledge it */
Philipp Maier9c60a622020-07-09 15:08:46 +02001392 var RslChannelNr chan_nr := f_chreq_act_ack(ra);
Harald Welteae026692017-12-09 01:03:01 +01001393
1394 /* expect BSC to disable the channel again if there's no RLL EST IND */
1395 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1396
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001397 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001398}
1399
Philipp Maier9c60a622020-07-09 15:08:46 +02001400/* Normal variant */
1401testcase TC_chan_act_ack_noest() runs on test_CT {
Philipp Maieraf58db22020-08-12 17:24:40 +02001402 f_init(1);
Philipp Maier9c60a622020-07-09 15:08:46 +02001403 f_TC_chan_act_ack_noest();
1404}
1405
1406/* Emergency call variant */
1407testcase TC_chan_act_ack_noest_emerg() runs on test_CT {
1408 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
Philipp Maieraf58db22020-08-12 17:24:40 +02001409 f_init(1);
1410 f_vty_allow_emerg_bts(true, 0);
Philipp Maier9c60a622020-07-09 15:08:46 +02001411 f_TC_chan_act_ack_noest(ra := 'A5'O);
1412}
1413
Philipp Maier606f07d2020-08-12 17:21:58 +02001414/* Emergency call variant, but emergency calls are not allowed */
1415testcase TC_chan_rqd_emerg_deny() runs on test_CT {
1416 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
1417
1418 var RSL_Message rx_rsl;
1419 var GsmRrMessage rr;
1420
1421 f_init(1);
1422 f_vty_allow_emerg_bts(false, 0);
1423
1424 IPA_RSL[0].clear;
1425 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
1426
1427 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
1428 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
1429 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1430 setverdict(pass);
1431 } else {
1432 setverdict(fail, "immediate assignment not rejected");
1433 }
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01001434
1435 f_shutdown_helper();
Philipp Maier606f07d2020-08-12 17:21:58 +02001436}
1437
Harald Welteae026692017-12-09 01:03:01 +01001438/* Test behavior if MSC never answers to CR */
1439testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +01001440 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
1441 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +01001442 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +01001443 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +01001444
Harald Welte89d42e82017-12-17 16:42:41 +01001445 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001446
1447 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001448 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001449
1450 var octetstring l3 := '00010203040506'O
1451 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1452
1453 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
1454
1455 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +01001456 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001457 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001458 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001459}
1460
1461/* Test behavior if MSC answers with CREF to CR */
1462testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
1463 var BSSAP_N_CONNECT_ind rx_c_ind;
1464 var RSL_Message rx_rsl;
1465
Harald Welte89d42e82017-12-17 16:42:41 +01001466 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001467
1468 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001469 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001470
1471 var octetstring l3 := '00010203040506'O
1472 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1473
1474 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1475 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
1476
1477 /* expect BSC to disable the channel */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001478 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001479 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001480}
1481
Harald Welte618ef642017-12-14 14:58:20 +01001482/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
1483testcase TC_chan_act_nack() runs on test_CT {
1484 var RSL_Message rx_rsl;
1485 var integer chact_nack;
1486
Harald Welte89d42e82017-12-17 16:42:41 +01001487 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +01001488
1489 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
1490
1491 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
1492 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1493 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1494
1495 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
1496
1497 /* wait for some time to hope the NACK arrives before the CTRL GET below */
1498 f_sleep(0.5);
1499
1500 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
1501
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001502 f_shutdown_helper();
Harald Welte618ef642017-12-14 14:58:20 +01001503}
1504
Harald Welte799c97b2017-12-14 17:50:30 +01001505/* Test for channel exhaustion due to RACH overload */
1506testcase TC_chan_exhaustion() runs on test_CT {
1507 var ASP_RSL_Unitdata rsl_ud;
1508 var integer i;
1509 var integer chreq_total, chreq_nochan;
1510
Harald Welte89d42e82017-12-17 16:42:41 +01001511 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +01001512
1513 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
1514 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
1515
Neels Hofmeyr85fa37f2021-10-06 13:50:38 +02001516 /* GSM 44.018 Table 9.1.8.2:
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +01001517 * RA = '33'O -> Establishment cause = 0011xxxx (MS dual rate capable and asks for "TCH/H or TCH/F").
1518 * With current setup, expect 4xSDCCH + 4xTCH/F + 1xTCH/H to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +02001519 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 +01001520 var RslChannelNr chan_nr := f_chreq_act_ack('33'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +01001521 }
1522
1523 IPA_RSL[0].clear;
1524
Harald Weltedd8cbf32018-01-28 12:07:52 +01001525 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001526 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +01001527
1528 /* now expect additional channel activations to fail */
1529 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
1530
1531 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001532 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
Harald Welte799c97b2017-12-14 17:50:30 +01001533 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
1534 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001535 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
Harald Welte799c97b2017-12-14 17:50:30 +01001536 var GsmRrMessage rr;
1537 /* match on IMM ASS REJ */
1538 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
1539 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1540 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001541 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +01001542 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
1543 chreq_nochan+1);
1544 setverdict(pass);
1545 } else {
1546 repeat;
1547 }
1548 }
1549 [] IPA_RSL[0].receive { repeat; }
1550 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001551 f_shutdown_helper();
Harald Welte799c97b2017-12-14 17:50:30 +01001552}
1553
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001554/* Test channel deactivation due to silence from MS */
1555testcase TC_chan_deact_silence() runs on test_CT {
1556 var RslChannelNr chan_nr;
1557
1558 f_init(1);
1559
1560 /* Request for a dedicated channel */
1561 chan_nr := f_chreq_act_ack('23'O);
1562
1563 /* Wait some time until the channel is released */
1564 f_sleep(2.0);
1565
1566 /* Expect CHANnel RELease */
1567 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001568 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001569 log("Received CHANnel RELease");
1570 setverdict(pass);
1571 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001572 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001573 /* See OS#3709, OsmoBSC should not send Immediate
1574 * Assignment Reject since a dedicated channel was
1575 * already allocated, and Immediate Assignment was
1576 * already sent. */
1577 setverdict(fail, "Unexpected Immediate Assignment!");
1578 }
1579 [] IPA_RSL[0].receive {
1580 setverdict(fail, "Unexpected RSL message!");
1581 }
1582 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001583 f_shutdown_helper();
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001584}
1585
Harald Weltecfe2c962017-12-15 12:09:32 +01001586/***********************************************************************
1587 * Assignment Testing
1588 ***********************************************************************/
1589
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001590/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction,
1591 * except for the inter-BSC handover, MT side) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001592testcase TC_outbound_connect(integer bssap_idx := 0) runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +01001593 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +01001594
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001595 BSSAP.send(ts_BSSAP_CONNECT_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
1596 2342, ts_BSSMAP_AssignmentReq));
Harald Weltecfe2c962017-12-15 12:09:32 +01001597 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001598 f_shutdown_helper();
Harald Weltecfe2c962017-12-15 12:09:32 +01001599}
1600
Harald Welte16a4adf2017-12-14 18:54:01 +01001601/* Test behavior if MSC answers with CREF to CR */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001602testcase TC_assignment_cic_only(integer bssap_idx := 0) runs on test_CT {
Harald Welte16a4adf2017-12-14 18:54:01 +01001603 var BSSAP_N_CONNECT_ind rx_c_ind;
1604 var RSL_Message rx_rsl;
1605 var DchanTuple dt;
1606
Harald Welte89d42e82017-12-17 16:42:41 +01001607 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +01001608
1609 dt := f_est_dchan('23'O, 23, '00000000'O);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001610 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte17b27da2018-05-25 20:33:53 +02001611 /* send assignment without AoIP IEs */
1612 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
1613 } else {
1614 /* Send assignmetn without CIC in IPA case */
1615 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
1616 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
1617 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
1618 }
Harald Welte16a4adf2017-12-14 18:54:01 +01001619 alt {
1620 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1621 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
1622 }
Harald Welte235ebf12017-12-15 14:18:16 +01001623 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +01001624 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1625 setverdict(pass);
1626 }
1627 [] BSSAP.receive { repeat; }
1628 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001629 f_shutdown_helper();
Harald Welte16a4adf2017-12-14 18:54:01 +01001630}
1631
Harald Welteed848512018-05-24 22:27:58 +02001632/* generate an assignment request for either AoIP or SCCPlite */
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001633function 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 +02001634 var PDU_BSSAP ass_cmd;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001635 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001636 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welteed848512018-05-24 22:27:58 +02001637 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001638 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001639 if (osmux_enabled) {
1640 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla, osmux_cid));
1641 } else {
1642 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
1643 }
Harald Welteed848512018-05-24 22:27:58 +02001644 } else {
1645 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001646 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
Harald Welteed848512018-05-24 22:27:58 +02001647 }
1648 return ass_cmd;
1649}
1650
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02001651function f_gen_handover_req(integer bssap_idx := 0, charstring aoip_tla := "1.2.3.4",
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001652 template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit,
1653 template (omit) TestHdlrEncrParams enc := omit) return PDU_BSSAP {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001654 var PDU_BSSAP ho_req;
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001655
1656 var BSSMAP_IE_EncryptionInformation encryptionInformation :=
1657 valueof(ts_BSSMAP_IE_EncrInfo('0000000000000000'O,'01'O));
1658 var template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm := omit;
1659 var template BSSMAP_IE_KC128 kc128 := omit;
1660 if (ispresent(enc)) {
1661 var TestHdlrEncrParams v_enc := valueof(enc);
1662 encryptionInformation := valueof(ts_BSSMAP_IE_EncrInfo(v_enc.enc_key, v_enc.enc_alg));
1663 chosenEncryptionAlgorithm := valueof(
1664 ts_BSSMAP_IE_ChosenEncryptionAlgorithm(int2oct(enum2int(
Oliver Smith598e1ed2021-07-09 10:28:40 +02001665 f_cipher_mode_bssmap_to_rsl(v_enc.enc_alg)), 1)));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001666 if (ispresent(v_enc.enc_kc128)) {
1667 kc128 := ts_BSSMAP_IE_Kc128(v_enc.enc_kc128);
1668 }
1669 }
1670
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001671 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001672 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001673 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001674 ho_req := valueof(ts_BSSMAP_HandoverRequest(omit, tla, oldToNewBSSIEs := oldToNewBSSIEs,
1675 encryptionInformation := encryptionInformation,
1676 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
1677 kC128 := kc128));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001678 } else {
1679 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001680 ho_req := valueof(ts_BSSMAP_HandoverRequest(cic, omit, oldToNewBSSIEs := oldToNewBSSIEs,
1681 encryptionInformation := encryptionInformation,
1682 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
1683 kC128 := kc128));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001684 }
1685 return ho_req;
1686}
1687
Harald Welteed848512018-05-24 22:27:58 +02001688/* generate an assignment complete template for either AoIP or SCCPlite */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001689function f_gen_exp_compl(boolean expect_osmux := false, integer bssap_idx := 0) return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +02001690 var template PDU_BSSAP exp_compl;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001691 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001692 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001693 if (expect_osmux) {
1694 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, osmux_cid);
1695 } else {
1696 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, omit);
1697 }
Harald Welteed848512018-05-24 22:27:58 +02001698 } else {
1699 /* CIC is optional "*" as the MSC allocated it */
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001700 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
Harald Welteed848512018-05-24 22:27:58 +02001701 }
1702 return exp_compl;
1703}
1704
Harald Welte235ebf12017-12-15 14:18:16 +01001705/* Run everything required up to sending a caller-specified assignment command and expect response */
1706function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
1707runs on test_CT {
1708 var BSSAP_N_CONNECT_ind rx_c_ind;
1709 var RSL_Message rx_rsl;
1710 var DchanTuple dt;
1711
Harald Welte89d42e82017-12-17 16:42:41 +01001712 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +01001713
1714 dt := f_est_dchan('23'O, 23, '00000000'O);
1715 /* send assignment without AoIP IEs */
1716 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
1717 alt {
1718 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1719 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
1720 setverdict(pass);
1721 } else {
1722 setverdict(fail, fail_text);
1723 }
1724 }
1725 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1726 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
1727 setverdict(pass);
1728 } else {
1729 setverdict(fail, fail_text);
1730 }
1731 }
1732 [] BSSAP.receive { repeat; }
1733 }
1734}
1735testcase TC_assignment_csd() runs on test_CT {
1736 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001737 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001738 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1739 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
1740 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001741 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001742}
1743
1744testcase TC_assignment_ctm() runs on test_CT {
1745 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001746 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001747 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
1748 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
1749 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001750 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001751}
1752
Harald Welte4003d112017-12-09 22:35:39 +01001753type record DchanTuple {
1754 integer sccp_conn_id,
1755 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +01001756}
1757
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +02001758type record of DchanTuple DchanTuples;
1759
Harald Welted6939652017-12-13 21:02:46 +01001760/* Send CHAN RQD and wait for allocation; acknowledge it */
1761private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
1762runs on test_CT return RslChannelNr {
1763 var RSL_Message rx_rsl;
1764 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1765 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1766 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1767 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
Daniel Willmannf4ac4ce2018-08-02 14:06:30 +02001768 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Harald Welted6939652017-12-13 21:02:46 +01001769 return chan_nr;
1770}
1771
Harald Welte4003d112017-12-09 22:35:39 +01001772/* helper function to establish a dedicated channel via BTS and MSC */
1773function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1774runs on test_CT return DchanTuple {
1775 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +01001776 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001777
Harald Welte4003d112017-12-09 22:35:39 +01001778 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001779 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +01001780
1781 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1782
1783 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1784 dt.sccp_conn_id := rx_c_ind.connectionId;
1785 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1786
1787 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001788}
1789
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02001790/* Like f_est_dchan(), but for the first lchan of a dynamic timeslot: first ACK the deactivation of PDCH. */
1791function f_est_dchan_dyn(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1792runs on test_CT return DchanTuple {
1793 var BSSAP_N_CONNECT_ind rx_c_ind;
1794 var DchanTuple dt;
1795
1796 /* Send CHAN RQD */
1797 var RSL_Message rx_rsl;
1798 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1799
1800 /* The dyn TS first deactivates PDCH */
1801 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1802 dt.rsl_chan_nr := rx_rsl.ies[0].body.chan_nr;
1803 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1804
1805 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1806 dt.rsl_chan_nr := rx_rsl.ies[0].body.chan_nr;
1807
1808 /* Now activates the signalling channel */
1809 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, fn+10));
1810 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
1811
1812 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1813
1814 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1815 dt.sccp_conn_id := rx_c_ind.connectionId;
1816 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1817
1818 return dt;
1819}
1820
Harald Welte641fcbe2018-06-14 10:58:35 +02001821/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
1822private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
1823 var RSL_Message rx_rsl;
1824 /* expect BSC to disable the channel */
1825 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1826 /* respond with CHAN REL ACK */
1827 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1828
1829 /* expect Clear Complete from BSC */
1830 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1831
1832 /* MSC disconnects as instructed. */
1833 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1834}
1835
Harald Welte4003d112017-12-09 22:35:39 +01001836/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
1837testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001838 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001839 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +01001840
Harald Welte89d42e82017-12-17 16:42:41 +01001841 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +01001842
Harald Welte4003d112017-12-09 22:35:39 +01001843 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1844
1845 /* simulate RLL REL IND */
1846 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
1847
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001848 /* expect Clear Request on MSC side */
1849 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1850
1851 /* Instruct BSC to clear channel */
1852 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1853 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1854
Harald Welte4003d112017-12-09 22:35:39 +01001855 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001856 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001857
1858 /* wait for SCCP emulation to do its job */
1859 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +01001860
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001861 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001862}
1863
1864/* Test behavior of channel release after CONN FAIL IND from BTS */
1865testcase TC_chan_rel_conn_fail() runs on test_CT {
1866 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001867 var DchanTuple dt;
1868
Harald Welte89d42e82017-12-17 16:42:41 +01001869 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001870
1871 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1872
1873 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +01001874 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 +01001875 /* TODO: different cause values? */
1876
Harald Welte4003d112017-12-09 22:35:39 +01001877 /* expect Clear Request from BSC */
1878 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1879
1880 /* Instruct BSC to clear channel */
1881 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1882 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1883
Harald Welte6ff76ea2018-01-28 13:08:01 +01001884 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001885 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +01001886
1887 /* wait for SCCP emulation to do its job */
1888 f_sleep(1.0);
1889
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001890 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001891}
1892
Harald Welte99f3ca02018-06-14 13:40:29 +02001893/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
1894/* See also https://www.osmocom.org/issues/3182 */
1895testcase TC_early_conn_fail() runs on test_CT {
1896 var RSL_Message rx_rsl;
1897 var DchanTuple dt;
1898
1899 f_init(1);
1900
1901 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
Harald Weltec46ea3c2020-10-10 18:46:12 +02001902 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_ra_cs(), 23);
Harald Welte99f3ca02018-06-14 13:40:29 +02001903
1904 /* BTS->BSC: simulate CONN FAIL IND */
1905 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1906
1907 /* BTS->BSC: Expect RF channel release from BSC on Abis */
1908 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1909
1910 /* BTS<-BSC: respond with CHAN REL ACK */
1911 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1912
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001913 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001914}
1915
1916/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
1917/* See also https://www.osmocom.org/issues/3182 */
1918testcase TC_late_conn_fail() runs on test_CT {
1919 var RSL_Message rx_rsl;
1920 var DchanTuple dt;
1921
1922 f_init(1);
1923
1924 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1925
1926 /* BSC<-MSC: Instruct BSC to clear connection */
1927 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
1928
1929 /* BTS->BSC: expect BSC to deactivate SACCH */
1930 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
1931
1932 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
1933 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1934
1935 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
1936 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1937 /* BTS->BSC: respond with CHAN REL ACK */
1938 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1939
1940 /* BSC->MSC: expect Clear Complete from BSC */
1941 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1942
1943 /* BSC<-MSC: MSC disconnects as requested. */
1944 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1945
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001946 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001947}
1948
Oliver Smithaf03bef2021-08-24 15:34:51 +02001949private function f_TC_stats_conn_fail(charstring id) runs on MSC_ConnHdlr {
1950 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
1951 var PDU_BSSAP ass_cmd := f_gen_ass_req();
1952
1953 f_statsd_reset();
1954
1955 /* Establish SDCCH */
1956 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1957 f_establish_fully(ass_cmd, exp_fail);
1958
1959 /* Expect stats to be 0 */
1960 var StatsDExpects expect := {
1961 {name := "TTCN3.bts.0.chan.rf_fail", mtype := "c", min := 0, max := 0},
1962 {name := "TTCN3.bts.0.chan.rf_fail_sdcch", mtype := "c", min := 0, max := 0}
1963 };
1964 f_statsd_expect(expect);
1965
1966 /* Simulate CONN FAIL IND on SDCCH */
1967 RSL.send(ts_ASP_RSL_UD(
1968 ts_RSL_CONN_FAIL_IND(g_chan_nr, RSL_ERR_RADIO_LINK_FAIL),
1969 IPAC_PROTO_RSL_TRX0));
1970
Neels Hofmeyr58be48a2021-09-07 18:39:21 +02001971 f_sleep(1.0);
1972
Oliver Smithaf03bef2021-08-24 15:34:51 +02001973 /* Expect stats to be 1 */
1974 expect := {
1975 {name := "TTCN3.bts.0.chan.rf_fail", mtype := "c", min := 1, max := 1},
1976 {name := "TTCN3.bts.0.chan.rf_fail_sdcch", mtype := "c", min := 1, max := 1}
1977 };
1978 f_statsd_expect(expect);
1979}
1980testcase TC_stats_conn_fail() runs on test_CT {
1981 var TestHdlrParams pars := f_gen_test_hdlr_pars();
1982 var MSC_ConnHdlr vc_conn;
1983
1984 f_init(1, true);
1985 f_sleep(1.0);
1986
1987 vc_conn := f_start_handler(refers(f_TC_stats_conn_fail), pars);
1988 vc_conn.done;
1989
1990 f_shutdown_helper();
1991}
1992
Neels Hofmeyrf44ccd12018-11-05 19:15:23 +01001993function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr,
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001994 boolean expect_deact_sacch := true,
1995 boolean expect_rr_chan_rel := true,
1996 boolean expect_rll_rel_req := true,
Harald Welte99787102019-02-04 10:41:36 +01001997 boolean handle_rll_rel := true,
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02001998 template CellSelIndValue expect_cells := omit,
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001999 template RR_Cause expect_rr_cause := ?
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002000 ) runs on test_CT {
Harald Welte91d54a52018-01-28 15:35:07 +01002001
2002 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002003 var boolean got_deact_sacch := false;
2004 var boolean got_rr_chan_rel := false;
2005 var boolean got_rll_rel_req := false;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002006 var ASP_RSL_Unitdata ud;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002007 var RSL_IE_Body l3_ie;
2008 var PDU_ML3_NW_MS l3;
2009 var RR_Cause got_cause;
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002010 log("f_expect_chan_rel() expecting: expect_deact_sacch=", expect_deact_sacch, " expect_rr_chan_rel=", expect_rr_chan_rel,
2011 " expect_rll_rel_req=", expect_rll_rel_req);
Harald Welte91d54a52018-01-28 15:35:07 +01002012 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002013 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002014 got_deact_sacch := true;
Harald Welte91d54a52018-01-28 15:35:07 +01002015 repeat;
2016 }
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002017 [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 +01002018 got_rr_chan_rel := true;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002019
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002020 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
2021 setverdict(fail, "cannot find L3");
2022 mtc.stop;
2023 }
2024 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
2025
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002026 if (not istemplatekind(expect_cells, "omit")) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002027 var CellSelIndValue cells := dec_CellSelIndValue(
2028 l3.msgs.rrm.channelRelease.cellSelectionIndicator.cellSelectionIndicatorValue);
2029
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002030 log("GOT RR CHANNEL RELEASE WITH CELLS: ", cells);
2031 if (match(cells, expect_cells)) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002032 setverdict(pass);
2033 } else {
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002034 log("EXPECTED CELLS: ", expect_cells);
2035 setverdict(fail, "Received cells list on RR Channel Release does not match expectations");
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002036 }
2037 }
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002038
2039 if (not istemplatekind(expect_rr_cause, "omit")) {
2040 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
2041 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
2042 if (match(got_cause, expect_rr_cause)) {
2043 setverdict(pass);
2044 } else {
2045 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
2046 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
2047 }
2048 }
Harald Welte99787102019-02-04 10:41:36 +01002049 repeat;
2050 }
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002051 [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 +01002052 got_rr_chan_rel := true;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002053
2054 if (not istemplatekind(expect_rr_cause, "omit")) {
2055 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
2056 setverdict(fail, "cannot find L3");
2057 mtc.stop;
2058 }
2059 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
2060
2061 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
2062 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
2063 if (match(got_cause, expect_rr_cause)) {
2064 setverdict(pass);
2065 } else {
2066 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
2067 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
2068 }
2069 }
Neels Hofmeyr211169d2018-11-07 00:37:29 +01002070 repeat;
2071 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002072 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002073 got_rll_rel_req := true;
Harald Welte91d54a52018-01-28 15:35:07 +01002074 /* FIXME: Why are we getting this for LinkID SACCH? */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002075 if (handle_rll_rel) {
2076 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
2077 }
Harald Welte91d54a52018-01-28 15:35:07 +01002078 repeat;
2079 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002080 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Harald Welte91d54a52018-01-28 15:35:07 +01002081 /* respond with CHAN REL ACK */
2082 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
2083 }
2084 /* ignore any user data */
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002085 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeR(?))) {
Harald Welte91d54a52018-01-28 15:35:07 +01002086 repeat;
2087 }
2088 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002089
2090 log("f_expect_chan_rel() summary: got_deact_sacch=", got_deact_sacch, " got_rr_chan_rel=", got_rr_chan_rel,
2091 " got_rll_rel_req=", got_rll_rel_req);
2092
2093 if (expect_deact_sacch != got_deact_sacch) {
2094 setverdict(fail, "f_expect_chan_rel(): expect_deact_sacch=", expect_deact_sacch, " got_deact_sacch=", got_deact_sacch);
2095 }
2096 if (expect_rr_chan_rel != got_rr_chan_rel) {
2097 setverdict(fail, "f_expect_chan_rel(): expect_rr_chan_rel=", expect_rr_chan_rel, " got_rr_chan_rel=", got_rr_chan_rel);
2098 }
2099 if (expect_rll_rel_req != got_rll_rel_req) {
2100 setverdict(fail, "f_expect_chan_rel(): expect_rll_rel_req=", expect_rll_rel_req, " got_rll_rel_req=", got_rll_rel_req);
2101 }
Harald Welte91d54a52018-01-28 15:35:07 +01002102}
2103
Harald Welte4003d112017-12-09 22:35:39 +01002104/* Test behavior of channel release after hard Clear Command from MSC */
2105testcase TC_chan_rel_hard_clear() runs on test_CT {
2106 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01002107 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +01002108
Harald Welte89d42e82017-12-17 16:42:41 +01002109 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002110
2111 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2112
2113 /* Instruct BSC to clear channel */
2114 var BssmapCause cause := 0;
2115 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2116
2117 /* expect Clear Complete from BSC on A */
2118 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2119 /* release the SCCP connection */
2120 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2121 }
2122
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002123 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002124 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002125}
2126
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002127function f_TC_chan_rel_last_eutran_plmn_hard_clear(boolean tx_csfb_ind) runs on test_CT {
2128 var BSSAP_N_DATA_ind rx_di;
2129 var DchanTuple dt;
2130
2131 f_init(1);
2132
2133 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2134 /* Send CommonID with some random PLMN (BSC doesn't take it into account
2135 /* yet when generating the EUTRAN neigh list in RR CHannel Release) */
2136 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
2137
2138 /* Instruct BSC to clear channel */
2139 var BssmapCause cause := 0;
2140 if (tx_csfb_ind) {
2141 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2142 } else {
2143 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2144 }
2145
2146 /* expect Clear Complete from BSC on A */
2147 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2148 /* release the SCCP connection */
2149 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2150 }
2151
2152 /* 1 neighbor is added by default in osmo-bts.cfg and
2153 SystemInformationConfig_default, use that: */
2154 var template CellSelIndValue exp_cells := f_tr_rr_chan_rel_earfcns(1);
2155
2156 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, expect_cells := exp_cells);
2157 f_shutdown_helper();
2158}
2159
2160/* Test behavior of RR Channel rRelease after Clear Command without CSFB indicator
2161 from MSC, previously receiving any CommonID containing the "Last Used E-UTRAN
2162 PLMN Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
2163 EUTRAN neighbor list sent later on by BSC in RR Channel, so receiving CSFB
2164 Indicator or not shouldn't matter at all. */
2165testcase TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() runs on test_CT {
2166 f_TC_chan_rel_last_eutran_plmn_hard_clear(false);
2167}
2168
2169/* Test behavior of RR Channel rRelease after Clear Command with CSFB indicator from
2170 MSC, previously receiving any CommonID containing the "Last Used E-UTRAN PLMN
2171 Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
2172 EUTRAN neighbor list sent later on by BSC in RR Channel. */
2173testcase TC_chan_rel_last_eutran_plmn_hard_clear_csfb() runs on test_CT {
2174 f_TC_chan_rel_last_eutran_plmn_hard_clear(true);
2175}
2176
2177/* Test behavior of RR Channel Release after Clear Command with CSFB indicator from
2178 MSC, without receiving any CommonID containing the "Last Used E-UTRAN PLMN
2179 Id". According to spec (TS 48.008 version 16.0.0 Release 16 "3.2.1.21") the
2180 CSFB Indicator should not be used anymore, and hence, there should be no
2181 EUTRAN neighbor list sent by BSC in RR Channel release since no CommonId with
2182 Last Used E-UTRAN PLMN Id" IE was sent for this conn. */
Harald Welte99787102019-02-04 10:41:36 +01002183testcase TC_chan_rel_hard_clear_csfb() runs on test_CT {
2184 var BSSAP_N_DATA_ind rx_di;
2185 var DchanTuple dt;
2186
2187 f_init(1);
2188
2189 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2190
2191 /* Instruct BSC to clear channel */
2192 var BssmapCause cause := 0;
2193 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2194
2195 /* expect Clear Complete from BSC on A */
2196 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2197 /* release the SCCP connection */
2198 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2199 }
2200
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002201 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002202 f_shutdown_helper();
Harald Welte99787102019-02-04 10:41:36 +01002203}
2204
Harald Welted8c36cd2017-12-09 23:05:31 +01002205/* Test behavior of channel release after hard RLSD from MSC */
2206testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +01002207 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +01002208
Harald Welte89d42e82017-12-17 16:42:41 +01002209 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +01002210
2211 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2212
2213 /* release the SCCP connection */
2214 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2215
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002216 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002217 f_shutdown_helper();
Harald Welted8c36cd2017-12-09 23:05:31 +01002218}
2219
Harald Welte550daf92018-06-11 19:22:13 +02002220/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
2221testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
2222 var DchanTuple dt;
2223
2224 f_init(1);
2225
2226 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2227
2228 /* release the SCCP connection */
2229 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2230
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002231 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002232 f_shutdown_helper();
Harald Welte550daf92018-06-11 19:22:13 +02002233}
2234
Harald Welte85804d42017-12-10 14:11:58 +01002235/* Test behavior of channel release after BSSMAP RESET from MSC */
2236testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +01002237 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +01002238
Harald Welte89d42e82017-12-17 16:42:41 +01002239 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +01002240
2241 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2242
2243 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
2244 IPA_RSL[0].clear;
2245
2246 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002247 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 +01002248 interleave {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002249 [] 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 +01002250 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
2251 }
2252
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002253 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002254 f_shutdown_helper();
Harald Welte85804d42017-12-10 14:11:58 +01002255}
2256
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002257/* Verify T(iar) triggers and releases the channel */
2258testcase TC_chan_rel_sccp_tiar_timeout() runs on test_CT {
2259 var DchanTuple dt;
2260
2261 /* Set T(iar) in BSC low enough that it will trigger before other side
2262 has time to keep alive with a T(ias). Keep recommended ratio of
2263 T(iar) >= T(ias)*2 */
2264 g_bsc_sccp_timer_ias := 2;
2265 g_bsc_sccp_timer_iar := 5;
2266
2267 f_init(1);
2268
2269 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2270 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002271 f_shutdown_helper();
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002272}
2273
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002274private function f_tc_chan_rel_rr_cause(myBSSMAP_Cause clear_cmd_cause, template RR_Cause expect_rr_cause)
2275runs on test_CT
2276{
2277 var DchanTuple dt;
2278
2279 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2280 var BssmapCause cause := 0;
2281 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(enum2int(clear_cmd_cause))));
2282 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2283 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2284 }
2285
2286 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 +02002287}
2288
2289/* Test that Clear Command cause codes affect the RR Channel Release cause code */
2290testcase TC_chan_rel_rr_cause() runs on test_CT {
2291 f_init(1);
2292
2293 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_CALL_CONTROL, GSM48_RR_CAUSE_NORMAL);
2294 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_HANDOVER_SUCCESSFUL, GSM48_RR_CAUSE_NORMAL);
2295 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_PREEMPTION, GSM48_RR_CAUSE_PREMPTIVE_REL);
2296 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE, GSM48_RR_CAUSE_PROT_ERROR_UNSPC);
2297 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
2298 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_EQUIPMENT_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
Vadim Yanitskiye18aebb2021-01-03 13:10:43 +01002299
2300 f_shutdown_helper();
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002301}
2302
Harald Welte5cd20ed2017-12-13 21:03:20 +01002303/* Test behavior if RSL EST IND for non-active channel */
2304testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
2305 timer T := 2.0;
2306
Harald Welte89d42e82017-12-17 16:42:41 +01002307 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002308
2309 var octetstring l3 := '00010203040506'O;
2310 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2311 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
2312
2313 T.start;
2314 alt {
2315 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2316 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
2317 }
2318 [] BSSAP.receive {}
2319 [] IPA_RSL[0].receive {}
2320 [] T.timeout {}
2321 }
2322
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002323 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002324}
2325
2326/* Test behavior if RSL EST IND for invalid SAPI */
2327testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
2328 var RslChannelNr chan_nr;
2329
Harald Welte89d42e82017-12-17 16:42:41 +01002330 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002331
2332 chan_nr := f_chreq_act_ack()
2333
2334 var octetstring l3 := '00010203040506'O;
2335 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
2336
2337 timer T := 2.0;
2338 T.start;
2339 alt {
2340 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2341 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
2342 }
2343 [] BSSAP.receive { repeat; }
2344 [] IPA_RSL[0].receive { repeat; }
2345 [] T.timeout {}
2346 }
2347
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002348 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002349}
2350
2351/* Test behavior if RSL EST IND for invalid SAPI */
2352testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
2353 timer T := 2.0;
2354
Harald Welte89d42e82017-12-17 16:42:41 +01002355 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002356
2357 var RslChannelNr chan_nr := f_chreq_act_ack();
2358
2359 var octetstring l3 := '00010203040506'O;
2360 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
2361
2362 T.start;
2363 alt {
2364 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2365 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
2366 }
2367 [] BSSAP.receive { repeat; }
2368 [] IPA_RSL[0].receive { repeat; }
2369 [] T.timeout {}
2370 }
2371
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002372 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002373}
2374
2375/* Test behavior if RSL EST IND for invalid SACCH */
2376testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
2377 timer T := 2.0;
2378
Harald Welte89d42e82017-12-17 16:42:41 +01002379 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002380
2381 var RslChannelNr chan_nr := f_chreq_act_ack();
2382
2383 var octetstring l3 := '00010203040506'O;
2384 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
2385
2386 T.start;
2387 alt {
2388 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2389 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
2390 }
2391 [] BSSAP.receive { repeat; }
2392 [] IPA_RSL[0].receive { repeat; }
2393 [] T.timeout {}
2394 }
2395
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002396 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002397}
2398
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002399/* Verify DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
2400private function f_TC_tch_dlci_link_id_sapi(charstring id) runs on MSC_ConnHdlr {
2401 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2402 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2403
2404 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2405 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2406
2407 f_establish_fully(ass_cmd, exp_compl);
2408
2409 /* SAPI0 has already been established by f_establish_fully(), establish SAPI3 */
2410 RSL.send(ts_RSL_EST_IND(g_chan_nr, ts_RslLinkID_SACCH(3), '0904'O));
2411 /* Expect BSSAP/DTAP on SAPI3 (DLCI IE) */
2412 BSSAP.receive(PDU_BSSAP:{
2413 discriminator := '1'B,
2414 spare := '0000000'B,
2415 dlci := 'C3'O,
2416 lengthIndicator := ?,
2417 pdu := { dtap := '0904'O }
2418 });
2419
2420 /* Send messages on DCCH/SAPI0 and ACCH/SAPI3 */
2421 for (var integer i := 0; i < 32; i := i + 1) {
2422 var octetstring l3 := '09'O & f_rnd_octstring(14);
2423 var template (value) RslLinkId link_id;
2424 var template (value) OCT1 dlci;
2425
2426 if (i mod 2 == 0) {
2427 /* SAPI0 on FACCH or SDCCH */
2428 link_id := ts_RslLinkID_DCCH(0);
2429 dlci := '80'O;
2430 } else {
2431 /* SAPI3 on SACCH */
2432 link_id := ts_RslLinkID_SACCH(3);
2433 dlci := 'C3'O;
2434 }
2435
2436 /* Send MO message: RSL -> BSSAP */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002437 f_mo_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002438 /* Send MT message: BSSAP -> RSL */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002439 f_mt_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002440 }
2441}
2442testcase TC_tch_dlci_link_id_sapi() runs on test_CT {
2443 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2444 var MSC_ConnHdlr vc_conn;
2445
2446 f_init(1, true);
2447 f_sleep(1.0);
2448
2449 vc_conn := f_start_handler(refers(f_TC_tch_dlci_link_id_sapi), pars);
2450 vc_conn.done;
2451
2452 f_shutdown_helper();
2453}
2454
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002455private function f_exp_sapi_n_reject(template (present) GsmSapi sapi := ?,
2456 template myBSSMAP_Cause cause := ?,
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002457 template (present) BIT2 cc := ?,
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002458 float T_val := 2.0)
2459runs on test_CT {
2460 var BSSAP_N_DATA_ind rx_di;
2461 timer T;
2462
2463 var template BSSMAP_IE_Cause tr_cause := tr_BSSMAP_IE_Cause(cause);
2464 var template PDU_BSSAP tr_pdu := tr_BSSMAP_SAPInReject(sapi);
2465
2466 T.start(T_val);
2467 alt {
2468 [] BSSAP.receive(tr_BSSAP_DATA_ind(?, tr_pdu)) -> value rx_di {
2469 var BSSMAP_IE_Cause rx_cause := rx_di.userData.pdu.bssmap.sAPInReject.cause;
2470 if (not match(rx_cause, tr_cause)) {
2471 setverdict(fail, "Rx unexpected Cause IE: ",
2472 rx_cause, " vs expected ", tr_cause);
2473 }
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002474
2475 /* Who ever on the earth decided to define this field as two separate bits?!? */
2476 var BIT2 rx_cc := rx_di.userData.pdu.bssmap.sAPInReject.dLCI.c2
2477 & rx_di.userData.pdu.bssmap.sAPInReject.dLCI.c1;
2478 if (not match(rx_cc, cc)) {
2479 setverdict(fail, "Rx unexpected Control Channel type: ",
2480 rx_cc, " vs expected ", cc);
2481 }
2482
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002483 setverdict(pass);
2484 }
2485 [] BSSAP.receive(BSSAP_N_DATA_ind:?) -> value rx_di {
2486 setverdict(fail, "Rx unexpected BSSAP PDU: ", rx_di);
2487 }
2488 [] T.timeout {
2489 setverdict(fail, "Timeout waiting for BSSMAP SAPI N Reject");
2490 }
2491 }
2492}
2493
2494/* Check if we get SAPI N Reject on receipt of unexpected RLL RELease INDication */
2495testcase TC_rll_rel_ind_sapi_n_reject() runs on test_CT {
2496 var octetstring rnd_data := f_rnd_octstring(16);
2497 var RSL_Message rx_rsl;
2498 var DchanTuple dt;
2499
2500 f_init(1);
2501
2502 /* MS establishes a SAPI=0 link on DCCH */
2503 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2504
2505 /* MSC sends some data on (not yet established) SAPI=3 link */
2506 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2507 /* BSC attempts to establish a SAPI=3 link on DCCH */
2508 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2509
2510 /* MS sends unexpected RELease INDication on SAPI=3 */
2511 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3)));
2512 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2513 f_exp_sapi_n_reject(3, GSM0808_CAUSE_MS_NOT_EQUIPPED);
2514
2515 /* Clean up the connection */
2516 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2517 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2518
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002519 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002520}
2521
2522/* Check if we get SAPI N Reject on receipt of unexpected RLL ERROR INDication */
2523testcase TC_rll_err_ind_sapi_n_reject() runs on test_CT {
2524 var octetstring rnd_data := f_rnd_octstring(16);
2525 var RSL_Message rx_rsl;
2526 var DchanTuple dt;
2527
2528 f_init(1);
2529
2530 /* MS establishes a SAPI=0 link on DCCH */
2531 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2532
2533 /* MSC sends some data on (not yet established) SAPI=3 link */
2534 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2535 /* BSC attempts to establish a SAPI=3 link on DCCH */
2536 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2537
2538 /* BTS sends unexpected ERROR INDication on SAPI=3 */
2539 f_ipa_tx(0, ts_RSL_ERROR_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3), ''O));
2540 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2541 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED);
2542
2543 /* Clean up the connection */
2544 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2545 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2546
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002547 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002548}
2549
2550/* Check if we get SAPI N Reject due to a SAPI=3 link establishment timeout */
2551testcase TC_rll_timeout_sapi_n_reject() runs on test_CT {
2552 var octetstring rnd_data := f_rnd_octstring(16);
2553 var RSL_Message rx_rsl;
2554 var DchanTuple dt;
2555
2556 f_init(1);
2557
2558 /* MS establishes a SAPI=0 link on DCCH */
2559 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2560
2561 /* MSC sends some data on (not yet established) SAPI=3 link */
2562 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2563 /* BSC attempts to establish a SAPI=3 link on DCCH */
2564 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2565
2566 /* MS does not respond, so the link establishment timeout triggers SAPI N Reject */
2567 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED, T_val := 8.0);
2568
2569 /* Clean up the connection */
2570 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2571 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2572
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002573 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002574}
2575
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002576/* Check DLCI CC (Control Channel type) bits in SAPI N Reject */
2577testcase TC_rll_sapi_n_reject_dlci_cc() runs on test_CT {
2578 var octetstring rnd_data := f_rnd_octstring(16);
2579 var RSL_Message rx_rsl;
2580 var DchanTuple dt;
2581
2582 f_init(1);
2583
2584 /* MS establishes a SAPI=0 link on DCCH */
2585 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2586
2587 /* MSC sends some data on (not yet established) SAPI=3 link */
2588 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2589 /* BSC attempts to establish a SAPI=3 link on DCCH */
2590 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2591
2592 /* MS sends unexpected ERROR INDication on DCCH/ACCH SAPI=3 */
2593 f_ipa_tx(0, ts_RSL_ERROR_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3), ''O));
2594 f_exp_sapi_n_reject(3, GSM0808_CAUSE_MS_NOT_EQUIPPED, '10'B);
2595
2596 /* Clean up the connection */
2597 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2598 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2599
2600 f_shutdown_helper();
2601}
2602
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002603testcase TC_si_default() runs on test_CT {
2604 f_init(0);
2605 f_init_bts_and_check_sysinfo(0, expect_si := SystemInformationConfig_default);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002606 f_shutdown_helper();
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002607}
Harald Welte4003d112017-12-09 22:35:39 +01002608
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002609/* We're testing SI2quater with lists of EARFCNs. Instead of just incrementing EARFCNs, also pick some from the edges of
2610 * the entire value range. This function provides the same EARFCN numbers for the same earfcn_index */
2611private function f_test_si2quater_earfcn_by_idx(integer earfcn_index) return uint16_t
2612{
2613 select (earfcn_index) {
2614 case (0) {
2615 /* E-ARFCN 111 is already added in the osmo-bsc.cfg */
2616 return 111;
2617 }
2618 case (1) {
2619 return 1;
2620 }
2621 case (2) {
2622 return 0;
2623 }
2624 case (3) {
2625 return 65535;
2626 }
2627 case else {
2628 return 23 * (earfcn_index - 3);
2629 }
2630 }
2631}
2632
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002633function f_test_si2quater(integer total_earfcns, template SystemInformationConfig expect_si,
2634 template CellSelIndValue expect_cells := omit) runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002635
2636 f_init(0);
2637
2638 /* E-ARFCN 111 is already added in the osmo-bsc.cfg, so only add more arfcns if total_earfcns > 1 */
2639 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002640 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2641 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002642 }
2643
2644 f_init_bts_and_check_sysinfo(0, expect_si := expect_si);
2645
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002646 if (not istemplatekind(expect_cells, "omit")) {
2647 /* Also check that RR Channel Release contains these EARFCNs.
2648 * (copied code from TC_chan_rel_hard_clear_csfb) */
2649 var BSSAP_N_DATA_ind rx_di;
2650 var DchanTuple dt;
2651
2652 dt := f_est_dchan('23'O, 23, '00010203040506'O);
Pau Espin Pedrold0046312021-04-19 16:35:58 +02002653 /* Send CommonID with some random PLMN (BSC doesn't take it into account
2654 * yet when generating the EUTRAN neigh list in RR CHannel Release) */
2655 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002656
2657 /* Instruct BSC to clear channel */
2658 var BssmapCause cause := 0;
2659 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2660
2661 /* expect Clear Complete from BSC on A */
2662 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2663 /* release the SCCP connection */
2664 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2665 }
2666
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002667 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 +02002668 }
2669
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002670 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002671 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 +02002672 }
2673}
2674
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002675private function f_tr_si2quater_earfcns(integer count) return template SI2quaterRestOctetsList
2676{
2677 var template SI2quaterRestOctetsList si2quater := {};
2678 var integer si2quater_count := (count + 2) / 3;
2679
2680 for (var integer i := 0; i < count; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002681 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002682 var integer index := i / 3;
2683 var integer earfcn_index := i mod 3;
2684 if (index >= lengthof(si2quater)) {
2685 si2quater[index] := tr_SI2quaterRestOctets_EUTRAN(index := index, count := si2quater_count - 1);
2686 }
2687 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);
2688 }
2689
2690 return si2quater;
2691}
2692
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002693private function f_tr_rr_chan_rel_earfcns(integer count) return template CellSelIndValue
2694{
2695 var template CellSelIndValue_EUTRAN_Descrs cells := {};
2696
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002697 /* the lte neighbors must match the config & vty to pass this test */
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002698 for (var integer i := 0; i < count; i := i + 1) {
2699 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002700 cells[i] := tr_CellSelIndValue_EUTRAN_Descr(earfcn, '1'B, 3);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002701 }
2702
2703 return tr_CellSelIndValue_EUTRAN(cells);
2704}
2705
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002706private function f_tc_si2quater_n_earfcns(integer n) runs on test_CT
2707{
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002708 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrol8ab62e42020-12-18 16:19:11 +01002709 sic.si2quater := f_tr_si2quater_earfcns(n);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002710 var template CellSelIndValue cells := f_tr_rr_chan_rel_earfcns(n);
2711 f_test_si2quater(n, sic, cells);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002712}
2713
2714testcase TC_si2quater_2_earfcns() runs on test_CT {
2715 f_tc_si2quater_n_earfcns(2);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002716 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002717}
2718
2719testcase TC_si2quater_3_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002720 f_tc_si2quater_n_earfcns(3);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002721 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002722}
2723
2724testcase TC_si2quater_4_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002725 f_tc_si2quater_n_earfcns(4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002726 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002727}
2728
2729testcase TC_si2quater_5_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002730 f_tc_si2quater_n_earfcns(5);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002731 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002732}
2733
2734testcase TC_si2quater_6_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002735 f_tc_si2quater_n_earfcns(6);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002736 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002737}
2738
2739testcase TC_si2quater_12_earfcns() runs on test_CT {
2740 f_tc_si2quater_n_earfcns(12);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002741 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002742}
2743
2744testcase TC_si2quater_23_earfcns() runs on test_CT {
2745 f_tc_si2quater_n_earfcns(23);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002746 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002747}
2748
2749testcase TC_si2quater_32_earfcns() runs on test_CT {
2750 f_tc_si2quater_n_earfcns(32);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002751 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002752}
2753
2754testcase TC_si2quater_33_earfcns() runs on test_CT {
2755 f_tc_si2quater_n_earfcns(33);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002756 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002757}
2758
2759testcase TC_si2quater_42_earfcns() runs on test_CT {
2760 f_tc_si2quater_n_earfcns(42);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002761 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002762}
2763
2764testcase TC_si2quater_48_earfcns() runs on test_CT {
2765 f_tc_si2quater_n_earfcns(48);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002766 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002767}
2768
2769/* verify the VTY error response when adding too many EARFCNs, and showing that osmo-bsc still sends 16 SI2quater with
2770 * 48 EARFCNs. */
2771testcase TC_si2quater_49_earfcns() runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002772 var template SystemInformationConfig sic := SystemInformationConfig_default;
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002773 sic.si2quater := f_tr_si2quater_earfcns(48); /* 48, not 49! */
2774 f_init(0);
2775
2776 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002777 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2778 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002779 }
2780
2781 /* The 49th EARFCN no longer fits, expect VTY error */
2782 f_vty_enter_cfg_bts(BSCVTY, 0);
2783 var charstring vty_error;
2784 vty_error := f_vty_transceive_ret(BSCVTY,
2785 "si2quater neighbor-list add earfcn 70 thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3")
2786 f_vty_transceive(BSCVTY, "end");
2787
2788 if (f_strstr(vty_error, "Unable to add ARFCN 70") >= 0) {
2789 log("Got expected VTY error: ", vty_error);
2790 setverdict(pass);
2791 } else {
2792 setverdict(fail, "Expected the 49th EUTRAN ARFCN to be rejected by vty config, got: ", vty_error);
2793 }
2794
2795 f_init_bts_and_check_sysinfo(0, expect_si := sic);
2796
2797 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002798 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 +02002799 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002800 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002801}
2802
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002803private function f_acc09_count_allowed(AccessControlClass acc) return uint8_t
2804{
2805 var uint8_t count := 0;
2806 for (var integer i := 5; i < 16; i := i + 1) {
2807 if (acc[i] == '0'B) { /* the list marks barred, we count allowed */
2808 count := count + 1;
2809 }
2810 }
2811 return count;
2812}
2813
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002814private function f_recv_next_si1(integer rsl_idx := 0) runs on test_CT return SystemInformationType1
2815{
2816 var ASP_RSL_Unitdata rx_rsl_ud;
2817 var SystemInformationType1 last_si1;
2818
2819 timer T := 30.0;
2820 T.start;
2821 alt {
2822 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD((tr_RSL_NO_BCCH_INFO,
2823 tr_RSL_BCCH_INFO,
2824 tr_RSL_NO_SACCH_FILL,
2825 tr_RSL_SACCH_FILL))
2826 ) -> value rx_rsl_ud {
2827 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
2828 if (g_system_information[rsl_idx].si1 == omit) {
2829 repeat;
2830 }
2831 last_si1 := g_system_information[rsl_idx].si1;
2832 g_system_information[rsl_idx].si1 := omit;
2833 T.stop;
2834 }
Vadim Yanitskiy79ebd5e2021-01-04 00:12:55 +01002835 [] IPA_RSL[rsl_idx].receive { repeat; }
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002836 [] T.timeout { setverdict(fail, "Timeout receiving next SI1"); }
2837 }
2838 return last_si1;
2839}
2840
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002841/* verify ACC rotate feature */
2842testcase TC_si_acc_rotate() runs on test_CT {
2843 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002844 var SystemInformationType1 last_si1;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002845 var AccessControlClass acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002846 var uint8_t count;
2847 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2848
2849 f_init(0, guard_timeout := 60.0);
2850
2851 f_bts_0_cfg(BSCVTY, {"rach access-control-class 5 barred",
2852 "access-control-class-rotate 3",
2853 "access-control-class-rotate-quantum 1"});
2854
2855 /* Init and get first sysinfo */
2856 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2857
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002858 for (var integer i:= 0; i < 20; i := i + 1) {
2859 last_si1 := f_recv_next_si1(0);
2860 acc := last_si1.rach_control.acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002861 count := f_acc09_count_allowed(acc);
2862 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2863
2864 if (count != 3) {
2865 log("RSL: EXPECTED SI ACC len=3");
2866 setverdict(fail, "received SI does not match expectations");
2867 break;
2868 }
2869
2870 for (var integer j := 0; j < 10; j := j + 1) {
2871 if (acc[16 - 1 - j] == '0'B) { /* the list marks barred, we count allowed */
2872 times_allowed[j] := times_allowed[j] + 1;
2873 }
2874 }
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002875 }
2876
2877 for (var integer j := 0; j < 10; j := j + 1) {
2878 log("ACC", j, " allowed ", times_allowed[j], " times" );
2879 if (j != 5 and times_allowed[j] < 3) {
2880 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " < 1 times");
2881 } else if (j == 5 and times_allowed[j] > 0) {
2882 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " > 0 times");
2883 }
2884 }
2885
2886 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2887 "rach access-control-class 5 allowed"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002888 f_shutdown_helper();
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002889}
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002890
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002891/* verify ACC startup ramp+rotate feature */
2892testcase TC_si_acc_ramp_rotate() runs on test_CT {
2893 var template SystemInformationConfig sic := SystemInformationConfig_default;
2894 var SystemInformationType1 last_si1;
2895 var AccessControlClass acc;
2896 var ASP_RSL_Unitdata rx_rsl_ud;
2897 var uint8_t count;
2898 var uint8_t prev_count;
2899 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2900
2901 f_init(0, guard_timeout := 80.0);
2902
2903 f_bts_0_cfg(BSCVTY, {"rach access-control-class 4 barred",
2904 "access-control-class-rotate 0",
2905 "access-control-class-rotate-quantum 1",
2906 "access-control-class-ramping",
2907 "access-control-class-ramping-step-interval 5",
2908 "access-control-class-ramping-step-size 5"});
2909
2910 /* Init and get first sysinfo */
2911 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2912 last_si1 := g_system_information[0].si1;
2913 acc := last_si1.rach_control.acc;
2914 count := f_acc09_count_allowed(acc);
2915 /* Adm subset size was set to 0 above, so wait until all ACC are barred */
2916 while (count > 0) {
2917 last_si1 := f_recv_next_si1(0);
2918 acc := last_si1.rach_control.acc;
2919 count := f_acc09_count_allowed(acc);
2920 log("RSL: wait len()=0: GOT SI1 ACC len=", count, ": ", acc);
2921 }
2922
2923 /* Increase adm subset size, we should see ramping start up */
2924 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10"});
2925 prev_count := 0;
2926 while (true) {
2927 last_si1 := f_recv_next_si1(0);
2928 acc := last_si1.rach_control.acc;
2929 count := f_acc09_count_allowed(acc);
2930 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2931
2932 if (prev_count > count) {
2933 setverdict(fail, "ACC allowed count dropped while expecting grow: ", prev_count, " -> ", count);
2934 break;
2935 }
2936
2937 if (count == 9) {
2938 break; /* Maximum reached (10 - 1 perm barred), done here */
2939 }
2940
2941 prev_count := count;
2942 }
2943
2944 setverdict(pass);
2945
2946 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2947 "rach access-control-class 4 allowed",
2948 "no access-control-class-ramping"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002949 f_shutdown_helper();
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002950}
2951
Harald Welte4003d112017-12-09 22:35:39 +01002952testcase TC_ctrl_msc_connection_status() runs on test_CT {
2953 var charstring ctrl_resp;
2954
Harald Welte89d42e82017-12-17 16:42:41 +01002955 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002956
2957 /* See https://osmocom.org/issues/2729 */
2958 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002959 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002960}
2961
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002962testcase TC_ctrl_msc0_connection_status() runs on test_CT {
2963 var charstring ctrl_resp;
2964
2965 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002966
2967 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002968 f_shutdown_helper();
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002969}
2970
Neels Hofmeyr0bc470d2021-08-21 13:37:13 +02002971/* Verify correct stats on the number of configured and connected MSCs */
2972private function f_tc_stat_num_msc_connected_msc_connhdlr(integer expect_num_msc_connected) runs on MSC_ConnHdlr {
2973 g_pars := f_gen_test_hdlr_pars();
2974 var StatsDExpects expect := {
2975 { name := "TTCN3.bsc.0.num_msc.connected", mtype := "g", min := expect_num_msc_connected, max := expect_num_msc_connected },
2976 { name := "TTCN3.bsc.0.num_msc.total", mtype := "g", min := NUM_MSC, max := NUM_MSC }
2977 };
2978 f_statsd_expect(expect);
2979}
2980
2981private function f_tc_stat_num_msc_connected_test_ct(void_fn tc_fn, integer nr_msc) runs on test_CT
2982{
2983 var MSC_ConnHdlr vc_conn;
2984
2985 f_init(nr_bts := 1, handler_mode := true, nr_msc := nr_msc);
2986 f_sleep(1.0);
2987 vc_conn := f_start_handler(tc_fn);
2988 vc_conn.done;
2989
2990 /* Also verify stat exposed on CTRL interface */
2991 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_msc:connected", int2str(nr_msc));
2992 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_msc:total", int2str(NUM_MSC));
2993
2994 f_shutdown_helper();
2995}
2996
2997/* Verify that when 1 MSC is active, that num_msc:connected reports 1. */
2998private function f_tc_stat_num_msc_connected_1(charstring id) runs on MSC_ConnHdlr {
2999 f_tc_stat_num_msc_connected_msc_connhdlr(1);
3000}
3001testcase TC_stat_num_msc_connected_1() runs on test_CT {
3002 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_1), 1);
3003}
3004
3005/* Verify that when 2 MSCs are active, that num_msc:connected reports 2. */
3006private function f_tc_stat_num_msc_connected_2(charstring id) runs on MSC_ConnHdlr {
3007 f_tc_stat_num_msc_connected_msc_connhdlr(2);
3008}
3009testcase TC_stat_num_msc_connected_2() runs on test_CT {
3010 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_2), 2);
3011}
3012
3013/* Verify that when 3 MSCs are active, that num_msc:connected reports 3. */
3014private function f_tc_stat_num_msc_connected_3(charstring id) runs on MSC_ConnHdlr {
3015 f_tc_stat_num_msc_connected_msc_connhdlr(3);
3016}
3017testcase TC_stat_num_msc_connected_3() runs on test_CT {
3018 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_3), 3);
3019}
3020
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +02003021/* Verify correct stats on the number of configured and connected MSCs */
3022private function f_tc_stat_num_bts_connected_msc_connhdlr(integer expect_num_bts_connected) runs on MSC_ConnHdlr {
3023 g_pars := f_gen_test_hdlr_pars();
3024 var StatsDExpects expect := {
3025 { name := "TTCN3.bsc.0.num_bts.oml_connected", mtype := "g", min := expect_num_bts_connected, max := NUM_BTS_CFG },
3026 { name := "TTCN3.bsc.0.num_bts.all_trx_rsl_connected", mtype := "g", min := expect_num_bts_connected, max := expect_num_bts_connected },
3027 { name := "TTCN3.bsc.0.num_bts.total", mtype := "g", min := NUM_BTS_CFG, max := NUM_BTS_CFG },
3028 { name := "TTCN3.bsc.0.num_trx.rsl_connected", mtype := "g", min := expect_num_bts_connected, max := expect_num_bts_connected },
3029 { name := "TTCN3.bsc.0.num_trx.total", mtype := "g", min := NUM_BTS_CFG, max := NUM_BTS_CFG }
3030 };
3031 f_statsd_expect(expect);
3032}
3033
3034private function f_tc_stat_num_bts_connected_test_ct(void_fn tc_fn, integer nr_bts) runs on test_CT {
3035 var MSC_ConnHdlr vc_conn;
3036
3037 f_init(nr_bts := nr_bts, handler_mode := true, nr_msc := 1);
3038 f_sleep(1.0);
3039 vc_conn := f_start_handler(tc_fn);
3040 vc_conn.done;
3041
3042 /* Also verify stat exposed on CTRL interface */
3043 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_bts:all_trx_rsl_connected", int2str(nr_bts));
3044 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_bts:total", int2str(NUM_BTS_CFG));
3045 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_trx:rsl_connected", int2str(nr_bts));
3046 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_trx:total", int2str(NUM_BTS_CFG));
3047
Neels Hofmeyra41ae302021-09-06 22:06:02 +02003048 /* Verify rf_states exposed on CTRL interface */
3049 var charstring expect_net_rf_states := "";
3050 for (var integer i := 0; i < NUM_BTS_CFG; i := i + 1) {
3051 var charstring expect_bts_rf_states := int2str(i) & ",0,";
3052 if (i < NUM_BTS) {
3053 /* In these tests, OML for the first NUM_BTS are always connected via osmo-bts-omldummy */
3054 expect_bts_rf_states := expect_bts_rf_states & "operational,unlocked,";
3055 } else {
3056 /* For remaining i < NUM_BTS_CFG, OML is not connected, i.e. inoperational */
3057 expect_bts_rf_states := expect_bts_rf_states & "inoperational,locked,";
3058 }
3059 /* The RF policy is still global in osmo-bsc, i.e. always "on" */
3060 expect_bts_rf_states := expect_bts_rf_states & "on,";
3061 if (i < nr_bts) {
3062 /* For BTS where RSL is connected, the RSL state will be "up" */
3063 expect_bts_rf_states := expect_bts_rf_states & "rsl-up;";
3064 } else {
3065 expect_bts_rf_states := expect_bts_rf_states & "rsl-down;";
3066 }
3067
3068 f_ctrl_get_exp(IPA_CTRL, "bts." & int2str(i) & ".rf_states", expect_bts_rf_states);
3069 expect_net_rf_states := expect_net_rf_states & expect_bts_rf_states;
3070 }
3071 f_ctrl_get_exp(IPA_CTRL, "rf_states", expect_net_rf_states);
3072
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +02003073 f_shutdown_helper();
3074}
3075
3076/* Verify that when 1 BTS is connected, that num_{bts,trx}:*_connected reports 1. */
3077private function f_tc_stat_num_bts_connected_1(charstring id) runs on MSC_ConnHdlr {
3078 f_tc_stat_num_bts_connected_msc_connhdlr(1);
3079}
3080testcase TC_stat_num_bts_connected_1() runs on test_CT {
3081 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_1), 1);
3082}
3083
3084/* Verify that when 2 BTS is connected, that num_{bts,trx}:*_connected reports 2. */
3085private function f_tc_stat_num_bts_connected_2(charstring id) runs on MSC_ConnHdlr {
3086 f_tc_stat_num_bts_connected_msc_connhdlr(2);
3087}
3088testcase TC_stat_num_bts_connected_2() runs on test_CT {
3089 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_2), 2);
3090}
3091
3092/* Verify that when 3 BTS is connected, that num_{bts,trx}:*_connected reports 3. */
3093private function f_tc_stat_num_bts_connected_3(charstring id) runs on MSC_ConnHdlr {
3094 f_tc_stat_num_bts_connected_msc_connhdlr(3);
3095}
3096testcase TC_stat_num_bts_connected_3() runs on test_CT {
3097 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_3), 3);
3098}
3099
Harald Welte4003d112017-12-09 22:35:39 +01003100testcase TC_ctrl() runs on test_CT {
3101 var charstring ctrl_resp;
3102
Harald Welte89d42e82017-12-17 16:42:41 +01003103 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01003104
3105 /* all below values must match the osmo-bsc.cfg config file used */
3106
Harald Welte6a129692018-03-17 17:30:14 +01003107 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
3108 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Oliver Smith75aa0202019-08-19 14:17:50 +02003109 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "4");
Harald Welte4003d112017-12-09 22:35:39 +01003110
3111 var integer bts_nr := 0;
3112 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
3113 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
3114 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
3115 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
3116 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
3117 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
3118 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
3119
3120 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
3121 f_sleep(2.0);
3122 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
3123 setverdict(fail, "oml-uptime not incrementing as expected");
3124 }
3125 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
3126
3127 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
3128
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003129 f_shutdown_helper();
Harald Welte96c94412017-12-09 03:12:45 +01003130}
3131
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02003132/* Verify that Upon receival of SET "location", BSC forwards a TRAP
3133 "location-state" over the SCCPlite IPA conn */
3134testcase TC_ctrl_location() runs on test_CT {
3135 var MSC_ConnHdlr vc_conn;
3136 var integer bts_nr := 0;
3137
3138 f_init(1, true);
3139 f_sleep(1.0);
3140
3141 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234567,fix3d,0.340000,0.560000,0.780000");
3142 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
3143 "1234567,fix3d,0.340000,0.560000,0.780000,operational,unlocked,on,001,01");
3144
3145 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "1");
3146 f_sleep(2.0);
3147
3148 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234888,fix3d,0.350000,0.570000,0.790000");
3149 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
3150 "1234888,fix3d,0.350000,0.570000,0.790000,operational,locked,off,001,01");
3151
3152 /* should match the one from config */
3153 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "0");
3154
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003155 f_shutdown_helper();
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02003156}
3157
Harald Welte6f521d82017-12-11 19:52:02 +01003158
3159/***********************************************************************
3160 * Paging Testing
3161 ***********************************************************************/
3162
3163type record Cell_Identity {
3164 GsmMcc mcc,
3165 GsmMnc mnc,
3166 GsmLac lac,
3167 GsmCellId ci
3168};
Harald Welte24135bd2018-03-17 19:27:53 +01003169private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01003170private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01003171
Harald Welte5d1a2202017-12-13 19:51:29 +01003172type set of integer BtsIdList;
3173
3174private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
3175 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
3176 if (bts_id == bts_ids[j]) {
3177 return true;
3178 }
3179 }
3180 return false;
3181}
Harald Welte6f521d82017-12-11 19:52:02 +01003182
3183/* core paging test helper function; used by most paging test cases */
3184private function f_pageing_helper(hexstring imsi,
3185 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01003186 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01003187 template RSL_ChanNeeded rsl_chneed := omit,
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003188 template (omit) OCT4 tmsi := omit) runs on test_CT
Harald Welte6f521d82017-12-11 19:52:02 +01003189{
3190 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003191 var template MobileIdentityV mi;
Harald Welte6f521d82017-12-11 19:52:02 +01003192 var RSL_Message rx_rsl;
3193 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01003194 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01003195
3196 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01003197
3198 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01003199 for (i := 0; i < NUM_BTS; i := i + 1) {
3200 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01003201 }
Harald Welte6f521d82017-12-11 19:52:02 +01003202
3203 if (isvalue(rsl_chneed)) {
3204 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
3205 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
3206 } else {
3207 bssmap_chneed := omit;
3208 }
3209
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003210 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[0].sccp_addr_peer, g_bssap[0].sccp_addr_own,
3211 ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed)));
Harald Welte6f521d82017-12-11 19:52:02 +01003212
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003213 if (not istemplatekind(tmsi, "omit")) {
3214 mi := t_MI_TMSI(tmsi);
Harald Welte6f521d82017-12-11 19:52:02 +01003215 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003216 mi := tr_MI_IMSI(imsi);
Harald Welte6f521d82017-12-11 19:52:02 +01003217 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003218
Harald Welte5d1a2202017-12-13 19:51:29 +01003219 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003220 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(mi));
Harald Welte5d1a2202017-12-13 19:51:29 +01003221 /* check channel type, paging group */
3222 if (rx_rsl.ies[1].body.paging_group != paging_group) {
3223 setverdict(fail, "Paging for wrong paging group");
3224 }
3225 if (ispresent(rsl_chneed) and
3226 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
3227 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
3228 }
Harald Welte6f521d82017-12-11 19:52:02 +01003229 }
Harald Welte2fccd982018-01-31 15:48:19 +01003230 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01003231 /* do a quick check on all not-included BTSs if they received paging */
3232 for (i := 0; i < NUM_BTS; i := i + 1) {
3233 timer T := 0.1;
3234 if (f_bts_in_list(i, bts_ids)) {
3235 continue;
3236 }
3237 T.start;
3238 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003239 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(mi))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003240 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
3241 }
3242 [] IPA_RSL[i].receive { repeat; }
3243 [] T.timeout { }
3244 }
Harald Welte6f521d82017-12-11 19:52:02 +01003245 }
3246
3247 setverdict(pass);
3248}
3249
Harald Welte5d1a2202017-12-13 19:51:29 +01003250const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01003251const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01003252const BtsIdList c_BtsId_LAC1 := { 0, 1 };
3253const BtsIdList c_BtsId_LAC2 := { 2 };
3254
Harald Welte6f521d82017-12-11 19:52:02 +01003255/* PAGING by IMSI + TMSI */
3256testcase TC_paging_imsi_nochan() runs on test_CT {
3257 var BSSMAP_FIELD_CellIdentificationList cid_list;
3258 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01003259 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003260 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003261}
3262
3263/* PAGING by IMSI + TMSI */
3264testcase TC_paging_tmsi_nochan() runs on test_CT {
3265 var BSSMAP_FIELD_CellIdentificationList cid_list;
3266 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003267 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003268 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003269}
3270
3271/* Paging with different "channel needed' values */
3272testcase TC_paging_tmsi_any() runs on test_CT {
3273 var BSSMAP_FIELD_CellIdentificationList cid_list;
3274 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003275 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003276 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003277}
3278testcase TC_paging_tmsi_sdcch() runs on test_CT {
3279 var BSSMAP_FIELD_CellIdentificationList cid_list;
3280 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003281 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003282 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003283}
3284testcase TC_paging_tmsi_tch_f() runs on test_CT {
3285 var BSSMAP_FIELD_CellIdentificationList cid_list;
3286 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003287 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003288 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003289}
3290testcase TC_paging_tmsi_tch_hf() runs on test_CT {
3291 var BSSMAP_FIELD_CellIdentificationList cid_list;
3292 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003293 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003294 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003295}
3296
3297/* Paging by CGI */
3298testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
3299 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3300 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003301 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003302 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003303}
3304
3305/* Paging by LAC+CI */
3306testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
3307 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3308 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003309 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003310 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003311}
3312
3313/* Paging by CI */
3314testcase TC_paging_imsi_nochan_ci() runs on test_CT {
3315 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3316 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003317 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003318 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003319}
3320
3321/* Paging by LAI */
3322testcase TC_paging_imsi_nochan_lai() runs on test_CT {
3323 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3324 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003325 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003326 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003327}
3328
3329/* Paging by LAC */
3330testcase TC_paging_imsi_nochan_lac() runs on test_CT {
3331 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3332 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003333 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003334 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003335}
3336
3337/* Paging by "all in BSS" */
3338testcase TC_paging_imsi_nochan_all() runs on test_CT {
3339 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3340 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01003341 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003342 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003343}
3344
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003345/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003346testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
3347 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3348 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 +01003349 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003350 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003351}
Harald Welte6f521d82017-12-11 19:52:02 +01003352
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003353/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003354testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
3355 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3356 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003357 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003358 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003359}
3360
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003361/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003362testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
3363 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3364 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003365 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003366 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003367}
3368
Harald Welte6f521d82017-12-11 19:52:02 +01003369/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01003370testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
3371 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3372 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
3373 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003374 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003375}
3376
3377/* Paging on empty list: Verify none of them page */
3378testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
3379 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3380 cid_list := { cIl_LAC := { } };
3381 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003382 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003383}
3384
Stefan Sperling049a86e2018-03-20 15:51:00 +01003385/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
3386testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
3387 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3388 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
3389 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
3390 f_shutdown_helper();
3391}
3392
Harald Welte6f521d82017-12-11 19:52:02 +01003393/* Verify paging retransmission interval + count */
3394/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01003395/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01003396
Harald Weltee65d40e2017-12-13 00:09:06 +01003397/* Verify PCH load */
3398testcase TC_paging_imsi_load() runs on test_CT {
3399 var BSSMAP_FIELD_CellIdentificationList cid_list;
3400 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01003401 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01003402 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003403 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01003404
3405 /* tell BSC there is no paging space anymore */
3406 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01003407 f_sleep(0.2);
3408 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01003409
3410 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
3411 * there would be 8 retransmissions during 4 seconds */
3412 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01003413 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01003414 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003415 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Weltee65d40e2017-12-13 00:09:06 +01003416 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02003417 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01003418 }
Harald Welte2caa1062018-03-17 18:19:05 +01003419 [] T_retrans.timeout {
3420 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
3421 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
3422 T_retrans.start;
3423 repeat;
3424 }
Harald Weltee65d40e2017-12-13 00:09:06 +01003425 [] T.timeout {
3426 setverdict(pass);
3427 }
3428 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003429
3430 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01003431}
3432
Harald Welte235ebf12017-12-15 14:18:16 +01003433/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01003434testcase TC_paging_counter() runs on test_CT {
3435 var BSSMAP_FIELD_CellIdentificationList cid_list;
3436 timer T := 4.0;
3437 var integer i;
3438 var integer paging_attempted_bsc;
3439 var integer paging_attempted_bts[NUM_BTS];
Oliver Smith8b343d32021-11-26 13:01:42 +01003440 var integer paging_expired_bsc;
Harald Welte1ff69992017-12-14 12:31:17 +01003441 var integer paging_expired_bts[NUM_BTS];
3442 cid_list := valueof(ts_BSSMAP_CIL_noCell);
3443
3444 f_init();
3445
3446 /* read counters before paging */
3447 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
Oliver Smith8b343d32021-11-26 13:01:42 +01003448 if (Misc_Helpers.f_osmo_repo_is("nightly")) { /* osmo-bsc > 1.8.0 */
3449 paging_expired_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:expired");
3450 }
Harald Welte1ff69992017-12-14 12:31:17 +01003451 for (i := 0; i < NUM_BTS; i := i+1) {
3452 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
3453 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
3454 }
3455
3456 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
3457
3458 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
3459 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
3460 for (i := 0; i < NUM_BTS; i := i+1) {
3461 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
3462 paging_attempted_bts[i]+1);
3463 }
3464
3465 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
3466 f_sleep(12.0);
Oliver Smith8b343d32021-11-26 13:01:42 +01003467 if (Misc_Helpers.f_osmo_repo_is("nightly")) { /* osmo-bsc > 1.8.0 */
3468 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:expired", paging_expired_bsc+1);
3469 }
Harald Welte1ff69992017-12-14 12:31:17 +01003470 for (i := 0; i < NUM_BTS; i := i+1) {
3471 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
3472 paging_expired_bts[i]+1);
3473 }
Harald Welte1ff69992017-12-14 12:31:17 +01003474
Philipp Maier282ca4b2018-02-27 17:17:00 +01003475 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01003476}
3477
3478
Harald Welte10985002017-12-12 09:29:15 +01003479/* Verify paging stops after A-RESET */
3480testcase TC_paging_imsi_a_reset() runs on test_CT {
3481 var BSSMAP_FIELD_CellIdentificationList cid_list;
3482 timer T := 3.0;
3483 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003484 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01003485
3486 /* Perform a BSSMAP Reset and wait for ACK */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003487 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 +01003488 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003489 [] 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 +01003490 [] BSSAP.receive { repeat; }
3491 }
3492
Daniel Willmanncbef3982018-07-30 09:22:40 +02003493 /* Wait to avoid a possible race condition if a paging message is
3494 * received right before the reset ACK. */
3495 f_sleep(0.2);
3496
Harald Welte10985002017-12-12 09:29:15 +01003497 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01003498 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
3499 IPA_RSL[i].clear;
3500 }
Harald Welte10985002017-12-12 09:29:15 +01003501
3502 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
3503 T.start;
3504 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003505 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte10985002017-12-12 09:29:15 +01003506 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003507 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01003508 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003509 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003510 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003511 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003512 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003513 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003514 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003515 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003516 }
Harald Welte10985002017-12-12 09:29:15 +01003517 [] T.timeout {
3518 setverdict(pass);
3519 }
3520 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003521
3522 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01003523}
Harald Welteae026692017-12-09 01:03:01 +01003524
Philipp Maierf45824a2019-08-14 14:44:10 +02003525/* Verify how we handle unsolicited Paging Response. In case of an unsolicit
3526 * paging response we can not know which MSC is in charge, so we will blindly
3527 * pick the first configured MSC. This behavior is required in order to make
3528 * MT-CSFB calls working because in those cases the BSC can not know that the
3529 * MSC has already paged the subscriver via SGs. So any MT-CSFB call will look
3530 * like an unsolicited Paging Response to the MSC.
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003531 */
3532testcase TC_paging_resp_unsol() runs on test_CT {
3533
3534 f_init(1);
Philipp Maierf45824a2019-08-14 14:44:10 +02003535 timer T := 5.0;
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003536
3537 var BSSAP_N_CONNECT_ind rx_c_ind;
3538 var DchanTuple dt;
3539 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
Philipp Maierf45824a2019-08-14 14:44:10 +02003540 var octetstring rr_pag_resp := enc_PDU_ML3_MS_NW(l3);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003541
3542 /* Send CHAN RQD and wait for allocation; acknowledge it */
3543 dt.rsl_chan_nr := f_chreq_act_ack();
3544
3545 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
3546 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
3547
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003548
Philipp Maierf45824a2019-08-14 14:44:10 +02003549 /* Expevct a CR with a matching Paging response on the A-Interface */
3550 T.start;
3551 alt {
3552 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(rr_pag_resp))) {
3553 setverdict(pass);
3554 }
3555 [] BSSAP.receive {
3556 setverdict(fail, "Received unexpected message on A-Interface!");
3557 }
3558 [] T.timeout {
3559 setverdict(fail, "Received nothing on A-Interface!");
3560 }
3561 }
3562
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003563 f_shutdown_helper();
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003564}
3565
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003566/* Test RSL link drop causes counter increment */
3567testcase TC_rsl_drop_counter() runs on test_CT {
3568 var integer rsl_fail;
3569
Harald Welte89d42e82017-12-17 16:42:41 +01003570 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003571
3572 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
3573
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +01003574 f_ipa_rsl_stop(bts[0].rsl);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003575
3576 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
3577
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003578 f_shutdown_helper();
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003579}
3580
3581/* TODO: Test OML link drop causes counter increment */
3582
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003583/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
3584function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
3585 timer T := 10.0;
3586
3587 bts[0].rsl.id := "IPA-0-RSL";
Harald Welte71389132021-12-09 21:58:18 +01003588 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA") alive;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003589 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
3590 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
Oliver Smith92c2bdb2019-08-20 15:11:24 +02003591 bts[0].rsl.ccm_pars.unit_id := "99/0/0"; /* value which is unknown at BTS */
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003592
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01003593 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003594
3595 f_init_mgcp("VirtMSC");
3596
3597 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
3598 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
3599 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
3600 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
3601
3602 /* wait for IPA OML link to connect and then disconnect */
3603 T.start;
3604 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +07003605 [] IPA_RSL[0].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) {
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003606 T.stop;
3607 return true;
3608 }
3609 [] IPA_RSL[0].receive { repeat }
3610 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02003611 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003612 }
3613 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003614 return false;
3615}
3616
3617/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3618testcase TC_rsl_unknown_unit_id() runs on test_CT {
3619 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
3620 setverdict(pass);
3621 } else {
3622 setverdict(fail, "Timeout RSL waiting for connection to close");
3623 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003624 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003625}
3626
3627
3628/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3629testcase TC_oml_unknown_unit_id() runs on test_CT {
3630 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
3631 setverdict(pass);
3632 } else {
3633 setverdict(fail, "Timeout OML waiting for connection to close");
3634 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003635 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003636}
3637
3638
Harald Weltec1a2fff2017-12-17 11:06:19 +01003639/***********************************************************************
Harald Welte6811d102019-04-14 22:23:14 +02003640 * "New world" test cases using RSL_Emulation + RAN_Emulation
Harald Weltec1a2fff2017-12-17 11:06:19 +01003641 ***********************************************************************/
3642
Harald Welte6811d102019-04-14 22:23:14 +02003643import from RAN_Emulation all;
Harald Welte47cd0e32020-08-21 12:39:11 +02003644import from BSSAP_LE_Emulation all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01003645import from RSL_Emulation all;
3646import from MSC_ConnectionHandler all;
3647
3648type function void_fn(charstring id) runs on MSC_ConnHdlr;
3649
Harald Welte336820c2018-05-31 20:34:52 +02003650/* helper function to create and connect a MSC_ConnHdlr component */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003651private function f_connect_handler(inout MSC_ConnHdlr vc_conn, integer bssap_idx := 0) runs on test_CT {
3652 connect(vc_conn:RAN, g_bssap[bssap_idx].vc_RAN:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01003653 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003654 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01003655 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01003656 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01003657 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
3658 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
3659 }
Neels Hofmeyr91401012019-07-11 00:42:35 +02003660 if (isvalue(bts[2])) {
3661 connect(vc_conn:RSL2, bts[2].rsl.vc_RSL:CLIENT_PT);
3662 connect(vc_conn:RSL2_PROC, bts[2].rsl.vc_RSL:RSL_PROC);
3663 }
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003664 connect(vc_conn:BSSAP, g_bssap[bssap_idx].vc_RAN:CLIENT);
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02003665 if (mp_enable_lcs_tests) {
3666 connect(vc_conn:BSSAP_LE, g_bssap_le.vc_BSSAP_LE:CLIENT);
3667 connect(vc_conn:BSSAP_LE_PROC, g_bssap_le.vc_BSSAP_LE:PROC);
3668 }
Daniel Willmann191e0d92018-01-17 12:44:35 +01003669 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02003670 connect(vc_conn:MGCP_MULTI, vc_MGCP:MGCP_CLIENT_MULTI);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003671 connect(vc_conn:STATSD_PROC, vc_STATSD:STATSD_PROC);
Harald Welte336820c2018-05-31 20:34:52 +02003672}
3673
Neels Hofmeyrda436782021-07-20 22:09:06 +02003674function f_start_handler_create(template (omit) TestHdlrParams pars := omit)
Harald Welte336820c2018-05-31 20:34:52 +02003675runs on test_CT return MSC_ConnHdlr {
3676 var charstring id := testcasename();
3677 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003678 var integer bssap_idx := 0;
3679 if (isvalue(pars)) {
3680 bssap_idx := valueof(pars).mscpool.bssap_idx;
3681 }
Harald Welte336820c2018-05-31 20:34:52 +02003682 vc_conn := MSC_ConnHdlr.create(id);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003683 f_connect_handler(vc_conn, bssap_idx);
Neels Hofmeyrda436782021-07-20 22:09:06 +02003684 return vc_conn;
3685}
3686
3687function f_start_handler_run(MSC_ConnHdlr vc_conn, void_fn fn, template (omit) TestHdlrParams pars := omit)
3688runs on test_CT return MSC_ConnHdlr {
3689 var charstring id := testcasename();
Neels Hofmeyr1708d1b2020-10-10 16:56:48 +02003690 /* Emit a marker to appear in the SUT's own logging output */
Neels Hofmeyrda436782021-07-20 22:09:06 +02003691 f_logp(BSCVTY, id & "() start");
Harald Weltea0630032018-03-20 21:09:55 +01003692 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003693 return vc_conn;
3694}
3695
Neels Hofmeyrda436782021-07-20 22:09:06 +02003696function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
3697runs on test_CT return MSC_ConnHdlr {
3698 return f_start_handler_run(f_start_handler_create(pars), fn, pars);
3699}
3700
Harald Weltea0630032018-03-20 21:09:55 +01003701/* first function inside ConnHdlr component; sets g_pars + starts function */
3702private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
3703runs on MSC_ConnHdlr {
3704 if (isvalue(pars)) {
3705 g_pars := valueof(pars);
3706 }
3707 fn.apply(id);
3708}
3709
Oliver Smith26a3db72021-07-09 13:51:29 +02003710private function f_vty_encryption_a5(charstring options) runs on test_CT {
3711 f_vty_transceive(BSCVTY, "configure terminal");
3712 f_vty_transceive(BSCVTY, "network");
3713 f_vty_transceive(BSCVTY, "encryption a5 " & options);
3714 f_vty_transceive(BSCVTY, "exit");
3715 f_vty_transceive(BSCVTY, "exit");
3716}
3717
3718private function f_vty_encryption_a5_reset() runs on test_CT {
3719 /* keep in sync with docker-playground.git ttcn3-bsc-test/osmo-bsc.cfg */
3720 f_vty_encryption_a5("0 1 3");
3721}
3722
Harald Welte3c86ea02018-05-10 22:28:05 +02003723/* Establish signalling channel (non-assignment case) followed by cipher mode */
3724private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003725 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3726 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02003727 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02003728 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
3729 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
3730 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
3731 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02003732
Philipp Maier23000732018-05-18 11:25:37 +02003733 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02003734}
3735testcase TC_ciph_mode_a5_0() runs on test_CT {
3736 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003737 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003738 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
3739
3740 f_init(1, true);
3741 f_sleep(1.0);
3742 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3743 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003744 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003745}
3746testcase TC_ciph_mode_a5_1() runs on test_CT {
3747 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003748 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003749 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
3750
3751 f_init(1, true);
3752 f_sleep(1.0);
3753 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3754 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003755 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003756}
Oliver Smith50b98122021-07-09 15:00:28 +02003757/* OS#4975: verify that A5/2 is preferred over A5/0 */
3758testcase TC_ciph_mode_a5_2_0() runs on test_CT {
3759 var MSC_ConnHdlr vc_conn;
3760 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3761
3762 pars.encr := valueof(t_EncrParams('05'O, f_rnd_octstring(8))); /* A5/0 and A5/2 (0x01|0x04)*/
3763 pars.encr_exp_enc_alg := '04'O; /* A5/2 */
3764
3765 f_init(1, true);
3766 f_vty_encryption_a5("0 1 2 3");
3767 f_sleep(1.0);
3768 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3769 vc_conn.done;
3770 f_vty_encryption_a5_reset();
3771 f_shutdown_helper();
3772}
Oliver Smith1dff88d2021-07-09 08:45:51 +02003773/* OS#4975: verify that A5/1 is preferred over A5/2 */
3774testcase TC_ciph_mode_a5_2_1() runs on test_CT {
3775 var MSC_ConnHdlr vc_conn;
3776 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3777
3778 pars.encr := valueof(t_EncrParams('06'O, f_rnd_octstring(8))); /* A5/1 and A5/2 (0x02|0x04)*/
3779 pars.encr_exp_enc_alg := '02'O; /* A5/1 */
3780
3781 f_init(1, true);
3782 f_vty_encryption_a5("1 2");
3783 f_sleep(1.0);
3784 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3785 vc_conn.done;
3786 f_vty_encryption_a5_reset();
3787 f_shutdown_helper();
3788}
Harald Welte3c86ea02018-05-10 22:28:05 +02003789testcase TC_ciph_mode_a5_3() runs on test_CT {
3790 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003791 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003792 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
3793
3794 f_init(1, true);
3795 f_sleep(1.0);
3796 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3797 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003798 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003799}
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003800/* Establish a Signalling channel with A5/4 encryption. */
3801testcase TC_ciph_mode_a5_4() runs on test_CT {
3802 var MSC_ConnHdlr vc_conn;
3803 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3804 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Harald Welte3c86ea02018-05-10 22:28:05 +02003805
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003806 f_init(1, true);
Oliver Smith26a3db72021-07-09 13:51:29 +02003807 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003808 f_sleep(1.0);
3809 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3810 vc_conn.done;
Oliver Smith26a3db72021-07-09 13:51:29 +02003811 f_vty_encryption_a5_reset();
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003812 f_shutdown_helper();
3813}
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003814/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
3815private function f_tc_assignment_aoip_tla_v6(charstring id) runs on MSC_ConnHdlr {
3816 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3817 var PDU_BSSAP ass_cmd := f_gen_ass_req(aoip_tla := "::3");
3818 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3819 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3820
3821 f_establish_fully(ass_cmd, exp_compl);
3822}
3823testcase TC_assignment_aoip_tla_v6() runs on test_CT {
3824 var MSC_ConnHdlr vc_conn;
3825 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3826
3827 f_init(1, true);
3828 f_sleep(1.0);
3829 vc_conn := f_start_handler(refers(f_tc_assignment_aoip_tla_v6), pars);
3830 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003831 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003832}
3833
Harald Welte3c86ea02018-05-10 22:28:05 +02003834
3835/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02003836private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003837 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3838 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003839
Harald Welte552620d2017-12-16 23:21:36 +01003840 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3841 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01003842
Harald Weltea0630032018-03-20 21:09:55 +01003843 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01003844}
Harald Welte552620d2017-12-16 23:21:36 +01003845testcase TC_assignment_fr_a5_0() runs on test_CT {
3846 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003847 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003848 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01003849
Harald Welte89d42e82017-12-17 16:42:41 +01003850 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003851 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003852 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003853 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003854 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003855}
Harald Welte552620d2017-12-16 23:21:36 +01003856testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01003857 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003858 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003859 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003860
Harald Welte89d42e82017-12-17 16:42:41 +01003861 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003862 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003863 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3864 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003865 f_shutdown_helper();
Harald Welte651fcdc2018-05-10 20:23:16 +02003866}
3867testcase TC_assignment_fr_a5_3() runs on test_CT {
3868 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003869 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003870 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003871
Harald Welte651fcdc2018-05-10 20:23:16 +02003872 f_init(1, true);
3873 f_sleep(1.0);
3874 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003875 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003876 f_shutdown_helper();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003877}
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003878/* Establish a Signalling channel and re-assign to TCH/F with A5/4 encryption. */
3879testcase TC_assignment_fr_a5_4() runs on test_CT {
3880 var MSC_ConnHdlr vc_conn;
3881 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3882 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
3883
3884 f_init(1, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02003885 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003886 f_sleep(1.0);
3887 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3888 vc_conn.done;
Oliver Smith7eabd312021-07-12 14:18:56 +02003889 f_vty_encryption_a5_reset();
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003890 f_shutdown_helper();
3891}
Harald Weltec1a2fff2017-12-17 11:06:19 +01003892
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +02003893/* Allow only A5/4, but omit the Kc128 IE from MSC's msg. Expect Cipher Mode Reject. */
3894testcase TC_assignment_fr_a5_4_fail() runs on test_CT {
3895 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3896 var MSC_ConnHdlr vc_conn;
3897
3898 f_init(1, true);
3899 f_sleep(1.0);
3900
3901 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8))); // A5/4 support, but Kc128 missing!
3902 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
3903 vc_conn.done;
3904 f_shutdown_helper();
3905}
3906
Harald Welte552620d2017-12-16 23:21:36 +01003907/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
3908private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003909 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01003910 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02003911 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003912
3913 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003914 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
3915
Harald Weltea0630032018-03-20 21:09:55 +01003916 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01003917}
Harald Welte552620d2017-12-16 23:21:36 +01003918testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
3919 var MSC_ConnHdlr vc_conn;
3920
Harald Welte89d42e82017-12-17 16:42:41 +01003921 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003922 f_sleep(1.0);
3923
Harald Welte8863fa12018-05-10 20:15:27 +02003924 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01003925 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003926 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003927}
3928
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003929private function f_TC_assignment_a5_not_sup(charstring id) runs on MSC_ConnHdlr {
3930 var template PDU_BSSAP exp_ass_cpl := f_gen_exp_compl();
3931 var PDU_BSSAP exp_ass_req := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003932
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003933 exp_ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3934 exp_ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3935
3936 /* this is like the beginning of f_establish_fully(), but only up to ciphering reject */
3937
3938 var BSSMAP_FIELD_CodecType codecType;
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003939
3940 codecType := exp_ass_req.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType;
3941 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
3942
3943 f_create_chan_and_exp();
3944 /* we should now have a COMPL_L3 at the MSC */
3945
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003946 /* Start ciphering, expect Cipher Mode Reject */
Neels Hofmeyr6c388f22021-06-11 02:36:56 +02003947 f_cipher_mode(g_pars.encr, exp_fail := true);
Harald Welte552620d2017-12-16 23:21:36 +01003948}
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003949testcase TC_assignment_fr_a5_not_sup() runs on test_CT {
3950 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01003951 var MSC_ConnHdlr vc_conn;
3952
Harald Welte89d42e82017-12-17 16:42:41 +01003953 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003954 f_sleep(1.0);
3955
Neels Hofmeyr0588cad2021-06-11 01:38:18 +02003956 pars.encr := valueof(t_EncrParams('20'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003957 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003958 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003959 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003960}
3961
3962
Harald Welte4532e0a2017-12-23 02:05:44 +01003963private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003964 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01003965 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02003966 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01003967 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003968
3969 f_statsd_reset();
Harald Weltea0630032018-03-20 21:09:55 +01003970 f_establish_fully(ass_cmd, exp_compl);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003971
3972 var StatsDExpects expect := {
Daniel Willmannc5398f72020-09-21 10:41:35 +02003973 { name := "TTCN3.bts.0.chreq.total", mtype := "c", min := 1, max := 1},
3974 { name := "TTCN3.bts.0.chreq.successful", mtype := "c", min := 1, max := 1},
Daniel Willmannebdecc02020-08-12 15:30:17 +02003975 { name := "TTCN3.bsc.0.assignment.attempted", mtype := "c", min := 1, max := 1},
3976 { name := "TTCN3.bsc.0.assignment.completed", mtype := "c", min := 1, max := 1}
3977 };
3978 f_statsd_expect(expect);
Harald Welte4532e0a2017-12-23 02:05:44 +01003979}
3980
3981testcase TC_assignment_sign() runs on test_CT {
3982 var MSC_ConnHdlr vc_conn;
3983
3984 f_init(1, true);
3985 f_sleep(1.0);
3986
Harald Welte8863fa12018-05-10 20:15:27 +02003987 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01003988 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003989 f_shutdown_helper();
Harald Welte4532e0a2017-12-23 02:05:44 +01003990}
3991
Harald Welte60aa5762018-03-21 19:33:13 +01003992/***********************************************************************
3993 * Codec (list) testing
3994 ***********************************************************************/
3995
3996/* check if the given rsl_mode is compatible with the a_elem */
3997private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
3998return boolean {
3999 select (a_elem.codecType) {
4000 case (GSM_FR) {
4001 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
4002 return true;
4003 }
4004 }
4005 case (GSM_HR) {
4006 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
4007 return true;
4008 }
4009 }
4010 case (GSM_EFR) {
4011 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
4012 return true;
4013 }
4014 }
4015 case (FR_AMR) {
4016 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
4017 return true;
4018 }
4019 }
4020 case (HR_AMR) {
4021 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
4022 return true;
4023 }
4024 }
4025 case else { }
4026 }
4027 return false;
4028}
4029
4030/* check if the given rsl_mode is compatible with the a_list */
4031private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
4032return boolean {
4033 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
4034 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
4035 return true;
4036 }
4037 }
4038 return false;
4039}
4040
4041/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02004042function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01004043return BSSMAP_IE_ChannelType {
4044 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
4045 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
4046 select (a_elem.codecType) {
4047 case (GSM_FR) {
4048 ret.channelRateAndType := ChRate_TCHF;
4049 ret.speechId_DataIndicator := Spdi_TCHF_FR;
4050 }
4051 case (GSM_HR) {
4052 ret.channelRateAndType := ChRate_TCHH;
4053 ret.speechId_DataIndicator := Spdi_TCHH_HR;
4054 }
4055 case (GSM_EFR) {
4056 ret.channelRateAndType := ChRate_TCHF;
4057 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
4058 }
4059 case (FR_AMR) {
4060 ret.channelRateAndType := ChRate_TCHF;
4061 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
4062 }
4063 case (HR_AMR) {
4064 ret.channelRateAndType := ChRate_TCHH;
4065 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
4066 }
4067 case else {
4068 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02004069 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01004070 }
4071 }
4072 return ret;
4073}
4074
Harald Weltea63b9102018-03-22 20:36:16 +01004075private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
4076return template RSL_IE_Body {
4077 var template RSL_IE_Body mode_ie := {
4078 chan_mode := {
4079 len := ?,
4080 reserved := ?,
4081 dtx_d := ?,
4082 dtx_u := ?,
4083 spd_ind := RSL_SPDI_SPEECH,
4084 ch_rate_type := -,
4085 coding_alg_rate := -
4086 }
4087 }
4088
4089 select (a_elem.codecType) {
4090 case (GSM_FR) {
4091 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4092 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
4093 }
4094 case (GSM_HR) {
4095 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
4096 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
4097 }
4098 case (GSM_EFR) {
4099 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4100 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
4101 }
4102 case (FR_AMR) {
4103 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4104 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
4105 }
4106 case (HR_AMR) {
4107 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
4108 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
4109 }
4110 }
4111 return mode_ie;
4112}
4113
Harald Welte60aa5762018-03-21 19:33:13 +01004114type record CodecListTest {
4115 BSSMAP_IE_SpeechCodecList codec_list,
4116 charstring id
4117}
4118type record of CodecListTest CodecListTests
4119
4120private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004121 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
4122 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
Harald Welte60aa5762018-03-21 19:33:13 +01004123
4124 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02004125 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte79f3f542018-05-25 20:02:37 +02004126 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
4127 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
4128 g_pars.ass_codec_list.codecElements[0];
Philipp Maierd0e64b02019-03-13 14:15:23 +01004129 if (isvalue(g_pars.expect_mr_s0_s7)) {
4130 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
4131 g_pars.expect_mr_s0_s7;
4132 }
Harald Welte79f3f542018-05-25 20:02:37 +02004133 }
Harald Welte60aa5762018-03-21 19:33:13 +01004134 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
4135 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01004136 log("expecting ASS COMPL like this: ", exp_compl);
4137
4138 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01004139
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004140 if (not g_pars.expect_channel_mode_modify) {
4141 /* Verify that the RSL-side activation actually matches our expectations */
4142 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
Harald Weltea63b9102018-03-22 20:36:16 +01004143
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004144 var RSL_IE_Body mode_ie;
4145 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
4146 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02004147 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004148 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004149 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
4150 if (not match(mode_ie, t_mode_ie)) {
4151 log("mode_ie ", mode_ie, " != t_mode_ie ", t_mode_ie);
4152 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004153 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004154
4155 var RSL_IE_Body mr_conf;
4156 if (g_pars.expect_mr_conf_ie != omit) {
4157 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
4158 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
4159 mtc.stop;
4160 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004161 log("found RSL MR CONFIG IE: ", mr_conf);
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004162
4163 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
4164 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
4165 g_pars.expect_mr_conf_ie);
4166 }
4167 } else {
4168 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
4169 log("found RSL MR CONFIG IE: ", mr_conf);
4170 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
4171 mtc.stop;
4172 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004173 }
4174 }
Harald Welte60aa5762018-03-21 19:33:13 +01004175}
4176
Philipp Maierd0e64b02019-03-13 14:15:23 +01004177private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
4178
4179 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4180 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4181
4182 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02004183 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maierd0e64b02019-03-13 14:15:23 +01004184 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
4185 }
4186 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
4187 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
4188 log("expecting ASS FAIL like this: ", exp_fail);
4189
4190 f_establish_fully(ass_cmd, exp_fail);
4191}
4192
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004193const CounterNameVals counternames_bsc_bts_assignment := {
4194 { "assignment:attempted", 0 },
4195 { "assignment:completed", 0 },
4196 { "assignment:stopped", 0 },
4197 { "assignment:no_channel", 0 },
4198 { "assignment:timeout", 0 },
4199 { "assignment:failed", 0 },
4200 { "assignment:error", 0 }
4201};
4202
4203const CounterNameVals counternames_bts_assignment := {
4204 { "assignment:attempted_sign", 0 },
4205 { "assignment:attempted_speech", 0 },
4206 { "assignment:completed_sign", 0 },
4207 { "assignment:completed_speech", 0 },
4208 { "assignment:stopped_sign", 0 },
4209 { "assignment:stopped_speech", 0 },
4210 { "assignment:no_channel_sign", 0 },
4211 { "assignment:no_channel_speech", 0 },
4212 { "assignment:timeout_sign", 0 },
4213 { "assignment:timeout_speech", 0 },
4214 { "assignment:failed_sign", 0 },
4215 { "assignment:failed_speech", 0 },
4216 { "assignment:error_sign", 0 },
4217 { "assignment:error_speech", 0 }
4218};
4219
4220function f_ctrs_bsc_and_bts_assignment_init(integer bts_count := NUM_BTS) runs on test_CT {
4221 var CounterNameVals bts_names := counternames_bsc_bts_assignment & counternames_bts_assignment;
4222 f_ctrs_bts_init(bts_count, bts_names);
4223 f_ctrs_bsc_init(counternames_bsc_bts_assignment);
4224}
4225
Harald Welte60aa5762018-03-21 19:33:13 +01004226testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004227 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004228 var MSC_ConnHdlr vc_conn;
4229
4230 f_init(1, true);
4231 f_sleep(1.0);
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004232 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004233
4234 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004235 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004236 vc_conn.done;
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004237
4238 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4239 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4240 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4241 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4242 f_ctrs_bts_verify();
4243
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004244 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004245}
4246
4247testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004248 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004249 var MSC_ConnHdlr vc_conn;
4250
4251 f_init(1, true);
4252 f_sleep(1.0);
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004253 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004254
4255 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004256 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004257 vc_conn.done;
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004258
4259 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4260 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4261 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4262 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4263 f_ctrs_bts_verify();
4264
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004265 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004266}
4267
4268testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004269 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004270 var MSC_ConnHdlr vc_conn;
4271
4272 f_init(1, true);
4273 f_sleep(1.0);
4274
4275 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004276 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004277 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004278 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004279}
4280
Philipp Maierd0e64b02019-03-13 14:15:23 +01004281/* Allow 5,90k only (current default config) */
4282private function f_allow_amr_rate_5_90k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00004283 f_vty_cfg_msc(BSCVTY, 0, {
4284 "amr-config 12_2k forbidden",
4285 "amr-config 10_2k forbidden",
4286 "amr-config 7_95k forbidden",
4287 "amr-config 7_40k forbidden",
4288 "amr-config 6_70k forbidden",
4289 "amr-config 5_90k allowed",
4290 "amr-config 5_15k forbidden",
4291 "amr-config 4_75k forbidden"
4292 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01004293}
4294
4295/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
4296 * ("Config-NB-Code = 1") */
4297private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00004298 f_vty_cfg_msc(BSCVTY, 0, {
4299 "amr-config 12_2k allowed",
4300 "amr-config 10_2k forbidden",
4301 "amr-config 7_95k forbidden",
4302 "amr-config 7_40k allowed",
4303 "amr-config 6_70k forbidden",
4304 "amr-config 5_90k allowed",
4305 "amr-config 5_15k forbidden",
4306 "amr-config 4_75k allowed"
4307 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01004308}
4309
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004310private function f_vty_amr_start_mode_set(boolean fr, charstring startmode) runs on test_CT {
4311 var charstring tch;
4312 if (fr) {
4313 tch := "tch-f";
4314 } else {
4315 tch := "tch-h";
4316 }
4317 f_vty_cfg_bts(BSCVTY, 0, { "amr " & tch & " start-mode " & startmode });
4318}
4319
4320/* Set the AMR start-mode for this TCH back to the default configuration. */
4321private function f_vty_amr_start_mode_restore(boolean fr) runs on test_CT {
4322 f_vty_amr_start_mode_set(fr, "auto");
4323}
4324
Harald Welte60aa5762018-03-21 19:33:13 +01004325testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004326 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004327 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02004328
4329 /* Note: This setups the codec configuration. The parameter payload in
4330 * mr_conf must be consistant with the parameter codecElements in pars
4331 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004332 var RSL_IE_Body mr_conf := {
4333 other := {
4334 len := 2,
4335 payload := '2804'O
4336 }
4337 };
Harald Welte60aa5762018-03-21 19:33:13 +01004338
Philipp Maier7695a0d2018-09-27 17:52:14 +02004339 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Philipp Maier806f8f12019-03-12 12:13:41 +01004340 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02004341 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
4342 pars.expect_mr_conf_ie := mr_conf;
4343
Harald Welte60aa5762018-03-21 19:33:13 +01004344 f_init(1, true);
4345 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004346 f_vty_amr_start_mode_set(true, "1");
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004347 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004348
Harald Welte8863fa12018-05-10 20:15:27 +02004349 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004350 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004351
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004352 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4353 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4354 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4355 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4356 f_ctrs_bts_verify();
4357
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004358 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004359 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004360}
4361
4362testcase TC_assignment_codec_amr_h() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004363 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004364 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02004365
4366 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004367 var RSL_IE_Body mr_conf := {
4368 other := {
4369 len := 2,
4370 payload := '2804'O
4371 }
4372 };
Harald Welte60aa5762018-03-21 19:33:13 +01004373
Philipp Maier7695a0d2018-09-27 17:52:14 +02004374 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Philipp Maier806f8f12019-03-12 12:13:41 +01004375 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02004376 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4377 pars.expect_mr_conf_ie := mr_conf;
4378
Harald Welte60aa5762018-03-21 19:33:13 +01004379 f_init(1, true);
4380 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004381 f_vty_amr_start_mode_set(false, "1");
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004382 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004383
Harald Welte8863fa12018-05-10 20:15:27 +02004384 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004385 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004386
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004387 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4388 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4389 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4390 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4391 f_ctrs_bts_verify();
4392
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004393 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004394 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004395}
4396
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004397/* Establish signalling on a TCH/F lchan, and then switch to speech mode without a new Assignment. */
4398testcase TC_assignment_codec_fr_by_mode_modify() runs on test_CT {
4399 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4400 var MSC_ConnHdlr vc_conn;
4401
4402 f_init(1, true);
4403 f_sleep(1.0);
4404
4405 /* By disabling all SDCCH, the MS should be given a TCH/F for signalling. Then activating an FR codec should
4406 * merely do a Channel Mode Modify, and not assign to a new lchan. f_establish_fully() already accounts for
4407 * expecting a Channel Mode Modify if the channel type is compatible. */
4408 f_disable_all_sdcch();
4409 f_disable_all_tch_h();
4410
4411 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4412 pars.expect_channel_mode_modify := true;
4413 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4414 vc_conn.done;
4415
4416 f_enable_all_sdcch();
4417 f_enable_all_tch();
4418 f_shutdown_helper();
4419}
4420
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004421/* 'amr start-mode auto' should not keep the (unused) 'smod' bits from previous configuration */
4422testcase TC_assignment_codec_amr_startmode_cruft() runs on test_CT {
4423 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4424 var MSC_ConnHdlr vc_conn;
4425
4426 var RSL_IE_Body mr_conf := {
4427 other := {
4428 len := 2,
4429 payload := '2004'O /* <- expect ICMI=0, smod=00 */
4430 }
4431 };
4432
4433 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4434 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
4435 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
4436 pars.expect_mr_conf_ie := mr_conf;
4437
4438 f_init(1, true);
4439 f_sleep(1.0);
4440
4441 /* First set nonzero start mode bits */
4442 f_vty_amr_start_mode_set(true, "4");
4443 /* Now set to auto, and expect the startmode bits to be zero in the message, i.e. ensure that osmo-bsc does not
4444 * let the startmode bits stick around and has deterministic MultiRate config for 'start-mode auto'; that is
4445 * ensured by above '2004'O, where 'x0xx'O indicates ICMI = 0, spare = 0, smod = 00. */
4446 f_vty_amr_start_mode_set(true, "auto");
4447
4448 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4449 vc_conn.done;
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004450
4451 /* Clear the startmode bits to not affect subsequent tests, in case the bits should indeed stick around. */
4452 f_vty_amr_start_mode_set(true, "1");
4453 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004454 f_shutdown_helper();
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004455}
4456
Neels Hofmeyr21863562020-11-26 00:34:33 +00004457function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0,
4458 charstring start_mode := "1")
Philipp Maierd0e64b02019-03-13 14:15:23 +01004459runs on test_CT {
4460
4461 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4462 var MSC_ConnHdlr vc_conn;
4463
4464 /* See note above */
4465 var RSL_IE_Body mr_conf := {
4466 other := {
4467 len := lengthof(mrconf),
4468 payload := mrconf
4469 }
4470 };
4471
4472 if (fr) {
4473 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4474 } else {
4475 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4476 }
4477 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4478 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4479 pars.expect_mr_conf_ie := mr_conf;
4480 pars.expect_mr_s0_s7 := exp_s8_s0;
4481
4482 f_init(1, true);
4483 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004484 f_vty_amr_start_mode_set(fr, start_mode);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004485 f_sleep(1.0);
4486
4487 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4488 vc_conn.done;
4489 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004490 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004491}
4492
4493function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
4494runs on test_CT {
4495
4496 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4497 var MSC_ConnHdlr vc_conn;
4498
4499 if (fr) {
4500 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4501 } else {
4502 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4503 }
4504 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4505 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4506
4507 f_init(1, true);
4508 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004509 f_vty_amr_start_mode_set(fr, "1");
Philipp Maierd0e64b02019-03-13 14:15:23 +01004510 f_sleep(1.0);
4511
4512 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
4513 vc_conn.done;
4514 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004515 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004516}
4517
4518
4519/* Set S1, we expect an AMR multirate configuration IE with all four rates
4520 * set. */
4521testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004522 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004523 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004524}
4525
4526/* Set S1, we expect an AMR multirate configuration IE with the lower three
4527 * rates set. */
4528testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004529 f_TC_assignment_codec_amr(false, '2815208820'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 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4534 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4535testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004536 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'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_h_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004543 f_TC_assignment_codec_amr(false, '2815208820'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/* The following block of tests selects more and more rates until all four
4548 * possible rates are in the active set (full rate) */
4549testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004550 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004551 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004552}
4553
4554testcase TC_assignment_codec_amr_f_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004555 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004556 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004557}
4558
4559testcase TC_assignment_codec_amr_f_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004560 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004561 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004562}
4563
4564testcase TC_assignment_codec_amr_f_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004565 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004566 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004567}
4568
4569/* The following block of tests selects more and more rates until all three
4570 * possible rates are in the active set (half rate) */
4571testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004572 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004573 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004574}
4575
4576testcase TC_assignment_codec_amr_h_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004577 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004578 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004579}
4580
4581testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004582 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004583 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004584}
4585
4586/* The following block tests what happens when the MSC does offer rate
4587 * configurations that are not supported by the BSC. Normally such situations
4588 * should not happen because the MSC gets informed by the BSC in advance via
4589 * the L3 COMPLETE message which rates are applicable. The MSC should not try
4590 * to offer rates that are not applicable anyway. */
4591
4592testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004593 /* Try to include 12,2k in into the active set even though the channel
4594 * is half rate only. The BSC is expected to remove the 12,0k */
4595 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004596 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004597}
4598
4599testcase TC_assignment_codec_amr_f_S01234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004600 /* See what happens when all rates are selected at once. Since then
4601 * Also S1 is selected, this setting will be prefered and we should
4602 * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
4603 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004604 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004605}
4606
4607testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004608 /* Same as above, but with S1 missing, the MSC is then expected to
4609 * select the currently supported rates, which are also 12.2k, 7,40k,
4610 * 5,90k, and 4,75k, into the active set. */
4611 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004612 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004613}
4614
4615testcase TC_assignment_codec_amr_f_zero() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004616 /* Try to select no rates at all */
4617 f_TC_assignment_codec_amr_fail(true, '00000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004618 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004619}
4620
4621testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004622 /* Try to select only unsupported rates */
4623 f_TC_assignment_codec_amr_fail(true, '01101000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004624 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004625}
4626
4627testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004628 /* Try to select 12,2k for half rate */
4629 f_TC_assignment_codec_amr_fail(false, '10000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004630 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004631}
4632
Neels Hofmeyr21863562020-11-26 00:34:33 +00004633testcase TC_assignment_codec_amr_f_start_mode_auto() runs on test_CT {
4634 f_TC_assignment_codec_amr(true, '209520882208'O, '11111111'B, '00000010'B,
4635 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004636 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004637}
4638
4639testcase TC_assignment_codec_amr_h_start_mode_auto() runs on test_CT {
4640 f_TC_assignment_codec_amr(false, '2015208820'O, '10010101'B, '00010101'B,
4641 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004642 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004643}
4644
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004645testcase TC_assignment_codec_amr_f_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004646 /* "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 +00004647 f_TC_assignment_codec_amr(true, '2b9520882208'O, '11111111'B, '00000010'B,
4648 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004649 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004650}
4651
4652testcase TC_assignment_codec_amr_h_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004653 /* "amr tch-h modes 0 2 4" => total 3 modes and start mode 4 => '10'B on the wire */
4654 f_TC_assignment_codec_amr(false, '2a15208820'O, '10010101'B, '00010101'B,
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004655 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004656 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004657}
4658
Philipp Maierac09bfc2019-01-08 13:41:39 +01004659private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004660 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
4661 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
4662 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
4663 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004664}
4665
4666private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004667 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
4668 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004669}
4670
4671private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004672 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
4673 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
4674 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
4675 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
4676 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
4677 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004678}
4679
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004680private function f_disable_all_sdcch() runs on test_CT {
4681 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 borken");
4682 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 borken");
4683 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 borken");
4684 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 borken");
4685}
4686
4687private function f_enable_all_sdcch() runs on test_CT {
4688 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 unused");
4689 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 unused");
4690 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 unused");
4691 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 unused");
4692}
4693
Philipp Maierac09bfc2019-01-08 13:41:39 +01004694/* Allow HR only */
4695private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
4696 g_pars := f_gen_test_hdlr_pars();
4697 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4698 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4699 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4700 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4701 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4702 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4703 f_establish_fully(ass_cmd, exp_compl);
4704}
4705
4706/* Allow FR only */
4707private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
4708 g_pars := f_gen_test_hdlr_pars();
4709 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4710 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4711 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4712 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4713 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4714 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4715 f_establish_fully(ass_cmd, exp_compl);
4716}
4717
4718/* Allow HR only (expect assignment failure) */
4719private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
4720 g_pars := f_gen_test_hdlr_pars();
4721 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4722 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4723 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4724 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4725 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4726 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4727 f_establish_fully(ass_cmd, exp_fail);
4728}
4729
4730/* Allow FR only (expect assignment failure) */
4731private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(charstring id) runs on MSC_ConnHdlr {
4732 g_pars := f_gen_test_hdlr_pars();
4733 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4734 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4735 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4736 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4737 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4738 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4739 f_establish_fully(ass_cmd, exp_fail);
4740}
4741
4742/* Allow FR and HR, but prefer FR */
4743private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4744 g_pars := f_gen_test_hdlr_pars();
4745 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4746 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4747 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4748 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4749 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4750 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4751 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4752 f_establish_fully(ass_cmd, exp_compl);
4753}
4754
4755/* Allow FR and HR, but prefer HR */
4756private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4757 g_pars := f_gen_test_hdlr_pars();
4758 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4759 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4760 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4761 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4762 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4763 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4764 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4765 f_establish_fully(ass_cmd, exp_compl);
4766}
4767
4768/* Allow FR and HR, but prefer FR */
4769private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4770 g_pars := f_gen_test_hdlr_pars();
4771 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4772 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4773 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4774 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4775 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4776 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4777 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4778 f_establish_fully(ass_cmd, exp_compl);
4779}
4780
4781/* Allow FR and HR, but prefer HR */
4782private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4783 g_pars := f_gen_test_hdlr_pars();
4784 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4785 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4786 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4787 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4788 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4789 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4790 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4791 f_establish_fully(ass_cmd, exp_compl);
4792}
4793
4794/* Request a HR channel while all FR channels are exhausted, this is expected
4795 * to work without conflicts */
4796testcase TC_assignment_codec_fr_exhausted_req_hr() runs on test_CT {
4797 var MSC_ConnHdlr vc_conn;
4798 f_init(1, true);
4799 f_sleep(1.0);
4800 f_enable_all_tch();
4801 f_disable_all_tch_f();
4802 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr));
4803 vc_conn.done;
4804 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004805 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004806}
4807
4808/* Request a FR channel while all FR channels are exhausted, this is expected
4809 * to fail. */
4810testcase TC_assignment_codec_fr_exhausted_req_fr() runs on test_CT {
4811 var MSC_ConnHdlr vc_conn;
4812 f_init(1, true);
4813 f_sleep(1.0);
4814 f_enable_all_tch();
4815 f_disable_all_tch_f();
4816 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr_fail));
4817 vc_conn.done;
4818 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004819 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004820}
4821
4822/* Request a FR (prefered) or alternatively a HR channel while all FR channels
4823 * are exhausted, this is expected to be resolved by selecting a HR channel. */
4824testcase TC_assignment_codec_fr_exhausted_req_fr_hr() runs on test_CT {
4825 var MSC_ConnHdlr vc_conn;
4826 f_init(1, true);
4827 f_sleep(1.0);
4828 f_enable_all_tch();
4829 f_disable_all_tch_f();
4830 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
4831 vc_conn.done;
4832 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004833 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004834}
4835
4836/* Request a HR (prefered) or alternatively a FR channel while all FR channels
4837 * are exhausted, this is expected to work without conflicts. */
4838testcase TC_assignment_codec_fr_exhausted_req_hr_fr() runs on test_CT {
4839 var MSC_ConnHdlr vc_conn;
4840 f_init(1, true);
4841 f_sleep(1.0);
4842 f_enable_all_tch();
4843 f_disable_all_tch_f();
4844 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_hr_fr));
4845 vc_conn.done;
4846 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004847 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004848}
4849
4850/* Request a FR channel while all HR channels are exhausted, this is expected
4851 * to work without conflicts */
4852testcase TC_assignment_codec_hr_exhausted_req_fr() runs on test_CT {
4853 var MSC_ConnHdlr vc_conn;
4854 f_init(1, true);
4855 f_sleep(1.0);
4856 f_enable_all_tch();
4857 f_disable_all_tch_h();
4858 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr));
4859 vc_conn.done;
4860 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004861 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004862}
4863
4864/* Request a HR channel while all HR channels are exhausted, this is expected
4865 * to fail. */
4866testcase TC_assignment_codec_hr_exhausted_req_hr() runs on test_CT {
4867 var MSC_ConnHdlr vc_conn;
4868 f_init(1, true);
4869 f_sleep(1.0);
4870 f_enable_all_tch();
4871 f_disable_all_tch_h();
4872 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr_fail));
4873 vc_conn.done;
4874 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004875 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004876}
4877
4878/* Request a HR (prefered) or alternatively a FR channel while all HR channels
4879 * are exhausted, this is expected to be resolved by selecting a FR channel. */
4880testcase TC_assignment_codec_hr_exhausted_req_hr_fr() runs on test_CT {
4881 var MSC_ConnHdlr vc_conn;
4882 f_init(1, true);
4883 f_sleep(1.0);
4884 f_enable_all_tch();
4885 f_disable_all_tch_h();
4886 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_hr_fr));
4887 vc_conn.done;
4888 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004889 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004890}
4891
4892/* Request a FR (prefered) or alternatively a HR channel while all HR channels
4893 * are exhausted, this is expected to work without conflicts. */
4894testcase TC_assignment_codec_hr_exhausted_req_fr_hr() runs on test_CT {
4895 var MSC_ConnHdlr vc_conn;
4896 f_init(1, true);
4897 f_sleep(1.0);
4898 f_enable_all_tch();
4899 f_disable_all_tch_h();
4900 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_fr_hr));
4901 vc_conn.done;
4902 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004903 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004904}
4905
4906/* Allow FR and HR, but prefer HR */
4907private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4908 g_pars := f_gen_test_hdlr_pars();
4909 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4910 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4911 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4912 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4913 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4914 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4915 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4916 f_establish_fully(ass_cmd, exp_compl);
4917}
4918
4919/* Allow FR and HR, but prefer FR */
4920private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4921 g_pars := f_gen_test_hdlr_pars();
4922 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4923 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4924 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4925 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4926 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4927 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4928 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4929 f_establish_fully(ass_cmd, exp_compl);
4930}
4931
4932/* Request a HR (prefered) or alternatively a FR channel, it is expected that
4933 * HR, which is the prefered type, is selected. */
4934testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
4935 var MSC_ConnHdlr vc_conn;
4936 f_init(1, true);
4937 f_sleep(1.0);
4938 f_enable_all_tch();
4939 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
4940 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004941 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004942}
4943
4944/* Request a FR (prefered) or alternatively a HR channel, it is expected that
4945 * FR, which is the prefered type, is selected. */
4946testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
4947 var MSC_ConnHdlr vc_conn;
4948 f_init(1, true);
4949 f_sleep(1.0);
4950 f_enable_all_tch();
4951 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
4952 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004953 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004954}
4955
Pau Espin Pedrol14475352021-07-22 15:48:16 +02004956/* request a signalling channel with all SDCCH exhausted, it is expected that a TCH will be selected */
4957private function f_TC_assignment_sdcch_exhausted_req_signalling(charstring id) runs on MSC_ConnHdlr {
4958 g_pars := f_gen_test_hdlr_pars();
4959 g_pars.ra := '02'O; /* RA containing reason=LU */
4960
4961 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
4962 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
4963 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
4964 var template uint3_t tsc := ?;
4965
4966 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
4967 f_create_bssmap_exp(l3_enc);
4968 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
4969 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, tsc);
4970
4971 /* we should now have a COMPL_L3 at the MSC */
4972 timer T := 10.0;
4973 T.start;
4974 alt {
4975 [] BSSAP.receive(tr_BSSMAP_ComplL3);
4976 [] T.timeout {
4977 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
4978 }
4979 }
4980}
4981testcase TC_assignment_sdcch_exhausted_req_signalling() runs on test_CT {
4982 var MSC_ConnHdlr vc_conn;
4983 f_init(1, true);
4984 f_sleep(1.0);
4985 f_disable_all_sdcch();
4986 vc_conn := f_start_handler(refers(f_TC_assignment_sdcch_exhausted_req_signalling));
4987 vc_conn.done;
4988 f_enable_all_sdcch();
4989 f_shutdown_helper();
4990}
4991
4992/* Request a signalling channel with all SDCCH exhausted, it is
4993 expected that no TCH will be selected for signalling and assigment will fail
4994 because it's dictated by VTY config */
4995testcase TC_assignment_sdcch_exhausted_req_signalling_tch_forbidden() runs on test_CT {
4996 var RSL_Message rsl_unused, rsl_msg;
4997 var GsmRrMessage rr;
4998 f_init(1, false);
4999 f_sleep(1.0);
5000 f_vty_allow_tch_for_signalling(false, 0);
5001 f_disable_all_sdcch();
5002
5003 /* RA containing reason=LU */
5004 f_ipa_tx(0, ts_RSL_CHAN_RQD('02'O, 2342));
5005 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
5006 rr := dec_GsmRrMessage(rsl_msg.ies[1].body.full_imm_ass_info.payload);
5007 if (rr.header.message_type != IMMEDIATE_ASSIGNMENT_REJECT) {
5008 setverdict(fail, "Expected reject");
5009 }
5010
5011 f_vty_allow_tch_for_signalling(true, 0);
5012 f_enable_all_sdcch();
5013 f_shutdown_helper();
5014}
5015
5016/* Request a voice channel with all SDCCH exhausted, it is
5017 * expected that TCH channel will be allocated since the VTY option is only
5018 * aimed at signalling requests */
5019private function f_TC_assignment_sdcch_exhausted_req_voice_tch_forbidden(charstring id) runs on MSC_ConnHdlr {
5020 g_pars := f_gen_test_hdlr_pars();
5021 g_pars.ra := '43'O; /* RA containing reason=originating speech call*/
5022
5023 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
5024 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
5025 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
5026 var template uint3_t tsc := ?;
5027
5028 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
5029 f_create_bssmap_exp(l3_enc);
5030 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
5031 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, tsc);
5032
5033 /* we should now have a COMPL_L3 at the MSC */
5034 timer T := 10.0;
5035 T.start;
5036 alt {
5037 [] BSSAP.receive(tr_BSSMAP_ComplL3);
5038 [] T.timeout {
5039 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
5040 }
5041 }
5042}
5043testcase TC_assignment_sdcch_exhausted_req_voice_tch_forbidden() runs on test_CT {
5044 var MSC_ConnHdlr vc_conn;
5045 f_init(1, true);
5046 f_sleep(1.0);
5047 f_vty_allow_tch_for_signalling(false, 0);
5048 f_disable_all_sdcch();
5049
5050 vc_conn := f_start_handler(refers(f_TC_assignment_sdcch_exhausted_req_voice_tch_forbidden));
5051 vc_conn.done;
5052
5053 f_vty_allow_tch_for_signalling(true, 0);
5054 f_enable_all_sdcch();
5055 f_shutdown_helper();
5056}
5057
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005058testcase TC_assignment_osmux() runs on test_CT {
5059 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5060 var MSC_ConnHdlr vc_conn;
5061
5062 /* See note above */
5063 var RSL_IE_Body mr_conf := {
5064 other := {
5065 len := 2,
5066 payload := '2804'O
5067 }
5068 };
5069
5070 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
5071 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
5072 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
5073 pars.expect_mr_conf_ie := mr_conf;
5074 pars.use_osmux := true;
5075
5076 f_init(1, true, true);
5077 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00005078 f_vty_amr_start_mode_set(false, "1");
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005079
5080 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
5081 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00005082
5083 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01005084 f_shutdown_helper();
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005085}
5086
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02005087/* test the procedure of the MSC requesting a Classmark Update:
5088 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
5089 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01005090private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005091 g_pars := f_gen_test_hdlr_pars();
5092
Harald Weltea0630032018-03-20 21:09:55 +01005093 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01005094 /* we should now have a COMPL_L3 at the MSC */
Harald Welte898113b2018-01-31 18:32:21 +01005095
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02005096 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
5097 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
5098
Harald Welte898113b2018-01-31 18:32:21 +01005099 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
5100 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
5101 setverdict(pass);
5102}
5103testcase TC_classmark() runs on test_CT {
5104 var MSC_ConnHdlr vc_conn;
5105 f_init(1, true);
5106 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005107 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01005108 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005109 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01005110}
5111
Harald Welteeddf0e92020-06-21 19:42:15 +02005112/* Send a CommonID from the simulated MSC and verify that the information is used to
5113 * fill BSC-internal data structures (specifically, bsc_subscr associated with subscr_conn) */
5114private function f_tc_common_id(charstring id) runs on MSC_ConnHdlr {
5115 g_pars := f_gen_test_hdlr_pars();
5116 f_MscConnHdlr_init_vty();
5117
5118 f_create_chan_and_exp();
5119 /* we should now have a COMPL_L3 at the MSC */
Harald Welteeddf0e92020-06-21 19:42:15 +02005120
5121 /* Send CommonID */
5122 BSSAP.send(ts_BSSMAP_CommonId(g_pars.imsi));
5123
5124 /* Use VTY to verify that the IMSI of the subscr_conn is set */
5125 var charstring regex := "*(IMSI: " & hex2str(g_pars.imsi) & ")*";
5126 f_vty_transceive_match_regexp_retry(BSCVTY, "show conns", regex, 0, 4, 1.0);
5127
5128 setverdict(pass);
5129}
5130testcase TC_common_id() runs on test_CT {
5131 var MSC_ConnHdlr vc_conn;
5132 f_init(1, true);
5133 f_sleep(1.0);
5134 vc_conn := f_start_handler(refers(f_tc_common_id));
5135 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005136 f_shutdown_helper();
Harald Welteeddf0e92020-06-21 19:42:15 +02005137}
5138
Harald Weltee3bd6582018-01-31 22:51:25 +01005139private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005140 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01005141 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01005142 /* we should now have a COMPL_L3 at the MSC */
Harald Welte898113b2018-01-31 18:32:21 +01005143
Harald Weltee3bd6582018-01-31 22:51:25 +01005144 /* send the single message we want to send */
5145 f_rsl_send_l3(l3);
5146}
5147
5148private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
5149 timer T := sec;
5150 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01005151 T.start;
5152 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01005153 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
5154 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02005155 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01005156 }
5157 [] T.timeout {
5158 setverdict(pass);
5159 }
5160 }
5161}
5162
Harald Weltee3bd6582018-01-31 22:51:25 +01005163/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
5164private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
5165 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
5166 f_bssap_expect_nothing();
5167}
Harald Welte898113b2018-01-31 18:32:21 +01005168testcase TC_unsol_ass_fail() runs on test_CT {
5169 var MSC_ConnHdlr vc_conn;
5170 f_init(1, true);
5171 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005172 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01005173 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005174 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01005175}
Harald Welte552620d2017-12-16 23:21:36 +01005176
Harald Welteea99a002018-01-31 20:46:43 +01005177
5178/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
5179private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01005180 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
5181 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01005182}
5183testcase TC_unsol_ass_compl() runs on test_CT {
5184 var MSC_ConnHdlr vc_conn;
5185 f_init(1, true);
5186 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005187 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01005188 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005189 f_shutdown_helper();
Harald Welteea99a002018-01-31 20:46:43 +01005190}
5191
5192
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005193/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
5194private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01005195 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
5196 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005197}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005198testcase TC_unsol_ho_fail() runs on test_CT {
5199 var MSC_ConnHdlr vc_conn;
5200 f_init(1, true);
5201 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005202 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005203 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005204 f_shutdown_helper();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005205}
5206
5207
Harald Weltee3bd6582018-01-31 22:51:25 +01005208/* short message from MS should be ignored */
5209private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005210 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01005211 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01005212 /* we should now have a COMPL_L3 at the MSC */
Harald Weltee3bd6582018-01-31 22:51:25 +01005213
5214 /* send short message */
5215 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
5216 f_bssap_expect_nothing();
5217}
5218testcase TC_err_82_short_msg() runs on test_CT {
5219 var MSC_ConnHdlr vc_conn;
5220 f_init(1, true);
5221 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005222 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01005223 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005224 f_shutdown_helper();
Harald Weltee3bd6582018-01-31 22:51:25 +01005225}
5226
5227
Harald Weltee9e02e42018-01-31 23:36:25 +01005228/* 24.008 8.4 Unknown message must trigger RR STATUS */
5229private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
5230 f_est_single_l3(ts_RRM_UL_REL('00'O));
5231 timer T := 3.0
5232 alt {
5233 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
5234 setverdict(pass);
5235 }
5236 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01005237 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01005238 }
5239}
5240testcase TC_err_84_unknown_msg() runs on test_CT {
5241 var MSC_ConnHdlr vc_conn;
5242 f_init(1, true);
5243 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005244 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01005245 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005246 f_shutdown_helper();
Harald Weltee9e02e42018-01-31 23:36:25 +01005247}
5248
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005249/***********************************************************************
5250 * Handover
5251 ***********************************************************************/
5252
Harald Welte94e0c342018-04-07 11:33:23 +02005253/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
5254private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
5255runs on test_CT {
5256 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
5257 " timeslot "&int2str(ts_nr)&" ";
5258 f_vty_transceive(BSCVTY, cmd & suffix);
5259}
5260
Harald Welte261af4b2018-02-12 21:20:39 +01005261/* 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 +07005262private function f_vty_ss_action(TELNETasp_PT pt, charstring suffix,
5263 uint8_t bts_nr, uint8_t trx_nr,
5264 in RslChannelNr chan_nr)
5265{
Harald Welte261af4b2018-02-12 21:20:39 +01005266 /* FIXME: resolve those from component-global state */
5267 var integer ts_nr := chan_nr.tn;
5268 var integer ss_nr;
5269 if (ischosen(chan_nr.u.ch0)) {
5270 ss_nr := 0;
5271 } else if (ischosen(chan_nr.u.lm)) {
5272 ss_nr := chan_nr.u.lm.sub_chan;
5273 } else if (ischosen(chan_nr.u.sdcch4)) {
5274 ss_nr := chan_nr.u.sdcch4.sub_chan;
5275 } else if (ischosen(chan_nr.u.sdcch8)) {
5276 ss_nr := chan_nr.u.sdcch8.sub_chan;
5277 } else {
5278 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02005279 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01005280 }
5281
5282 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
5283 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005284 f_vty_transceive(pt, cmd & suffix);
Harald Welte261af4b2018-02-12 21:20:39 +01005285}
5286
Neels Hofmeyr91401012019-07-11 00:42:35 +02005287/* Even though the VTY command to trigger handover takes a new BTS number as argument, behind the scenes osmo-bsc always
5288 * translates that to a target ARFCN+BSIC first. See bsc_vty.c trigger_ho_or_as(), which puts the selected BTS' neighbor
5289 * ident key (ARFCN + BSIC) in the struct passed on to handover_request(). handover_start() then resolves that to a
5290 * viable actual neighbor cell. So from the internal osmo-bsc perspective, we always request handover to an ARFCN + BSIC
5291 * pair, not really to a specific BTS number. */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005292private function f_vty_handover(TELNETasp_PT pt, uint8_t bts_nr, uint8_t trx_nr,
5293 in RslChannelNr chan_nr, uint8_t new_bts_nr)
5294{
5295 f_vty_ss_action(pt, "handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
Harald Welte261af4b2018-02-12 21:20:39 +01005296}
5297
5298/* intra-BSC hand-over between BTS0 and BTS1 */
5299private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02005300 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5301 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01005302
5303 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5304 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5305
Harald Weltea0630032018-03-20 21:09:55 +01005306 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005307 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Harald Welte261af4b2018-02-12 21:20:39 +01005308
5309 var HandoverState hs := {
5310 rr_ho_cmpl_seen := false,
5311 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02005312 old_chan_nr := -,
5313 expect_target_tsc := BTS_TSC[1]
Harald Welte261af4b2018-02-12 21:20:39 +01005314 };
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005315 /* issue hand-over command on VTY, from BTS 0 to BTS 1 */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005316 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
Harald Welte261af4b2018-02-12 21:20:39 +01005317 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
5318 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005319
5320 /* From the MGW perspective, a handover is is characterized by
5321 * performing one MDCX operation with the MGW. So we expect to see
5322 * one more MDCX during handover. */
5323 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
5324
Harald Welte261af4b2018-02-12 21:20:39 +01005325 alt {
5326 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01005327 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005328
Philipp Maier4dae0652018-11-12 12:03:26 +01005329 /* Since this is an internal handover we expect the BSC to inform the
5330 * MSC about the event */
5331 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
5332
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005333 /* Check the amount of MGCP transactions is still consistant with the
5334 * test expectation */
5335 f_check_mgcp_expectations()
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005336
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005337 var RSL_Message chan_act := f_rslem_get_last_act(RSL1_PROC, 0, g_chan_nr);
5338
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005339 /* Ensure the Channel Activation for the new channel contained the right encryption params. as_handover() set
5340 * 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 +02005341 f_verify_encr_info(chan_act);
5342
5343 f_chan_act_verify_tsc(chan_act, BTS_TSC[1]);
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005344
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01005345 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01005346}
5347
5348testcase TC_ho_int() runs on test_CT {
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02005349 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte261af4b2018-02-12 21:20:39 +01005350 var MSC_ConnHdlr vc_conn;
5351 f_init(2, true);
5352 f_sleep(1.0);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005353
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005354 pars.expect_tsc := BTS_TSC[0];
5355
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005356 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005357
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02005358 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
Harald Welte261af4b2018-02-12 21:20:39 +01005359 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005360
5361 /* from f_establish_fully() */
5362 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5363 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5364 /* from handover */
5365 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5366 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5367 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5368 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005369 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5370 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:completed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005371 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005372 f_shutdown_helper();
Harald Welte261af4b2018-02-12 21:20:39 +01005373}
Harald Weltee9e02e42018-01-31 23:36:25 +01005374
Oliver Smith7eabd312021-07-12 14:18:56 +02005375function 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 +02005376 var MSC_ConnHdlr vc_conn;
5377 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5378 pars.encr := valueof(t_EncrParams(encr_alg, f_rnd_octstring(8), f_rnd_octstring(16)));
5379
5380 f_init(2, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02005381 f_vty_encryption_a5(enc_a5);
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005382 f_sleep(1.0);
5383
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005384 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005385
5386 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
5387 vc_conn.done;
5388
5389 /* from f_establish_fully() */
5390 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5391 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5392 /* from handover */
5393 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5394 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5395 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5396 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005397 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5398 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:completed");
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005399 f_ctrs_bsc_and_bts_verify();
Oliver Smith7eabd312021-07-12 14:18:56 +02005400 f_vty_encryption_a5_reset();
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005401 f_shutdown_helper();
5402}
5403
5404testcase TC_ho_int_a5_0() runs on test_CT {
5405 f_tc_ho_int_a5('01'O);
5406}
5407
5408testcase TC_ho_int_a5_1() runs on test_CT {
5409 f_tc_ho_int_a5('02'O);
5410}
5411
5412testcase TC_ho_int_a5_3() runs on test_CT {
5413 f_tc_ho_int_a5('08'O);
5414}
5415
5416testcase TC_ho_int_a5_4() runs on test_CT {
Oliver Smith7eabd312021-07-12 14:18:56 +02005417 f_tc_ho_int_a5('10'O, "0 1 3 4");
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005418}
5419
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005420/* intra-BSC hand-over with CONNection FAILure and cause Radio Link Failure: check RR release cause */
5421private function f_tc_ho_int_radio_link_failure(charstring id) runs on MSC_ConnHdlr {
5422 g_pars := f_gen_test_hdlr_pars();
5423 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5424 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005425
5426 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5427 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5428
5429 f_establish_fully(ass_cmd, exp_compl);
5430 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
5431
5432 var HandoverState hs := {
5433 rr_ho_cmpl_seen := false,
5434 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02005435 old_chan_nr := -,
5436 expect_target_tsc := BTS_TSC[1]
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005437 };
5438 /* issue hand-over command on VTY */
5439 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
5440 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
5441 f_rslem_suspend(RSL1_PROC);
5442
5443 /* From the MGW perspective, a handover is is characterized by
5444 * performing one MDCX operation with the MGW. So we expect to see
5445 * one more MDCX during handover. */
5446 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
5447
5448 var RSL_Message rsl;
5449 var PDU_ML3_NW_MS l3;
5450 var RslChannelNr new_chan_nr;
5451 var GsmArfcn arfcn;
5452 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
5453 l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
5454 if (not ischosen(l3.msgs.rrm.handoverCommand)) {
5455 setverdict(fail, "Expected handoverCommand");
5456 mtc.stop;
5457 }
5458 }
5459 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
5460 new_chan_nr, arfcn);
5461
5462 f_rslem_register(0, new_chan_nr, RSL1_PROC);
5463
5464 /* resume processing of RSL DChan messages, which was temporarily suspended
5465 * before performing a hand-over */
5466 f_rslem_resume(RSL1_PROC);
5467 RSL1.receive(tr_RSL_IPA_CRCX(new_chan_nr));
5468
5469 f_sleep(1.0);
5470
5471 /* Handover fails because no HANDO DET appears on the new lchan,
5472 * and the old lchan reports a Radio Link Failure. */
5473 RSL.send(ts_RSL_CONN_FAIL_IND(g_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
5474
5475 var PDU_BSSAP rx_clear_request;
5476 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
5477 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5478 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5479
5480 var RR_Cause rr_cause := GSM48_RR_CAUSE_ABNORMAL_UNSPEC;
5481
5482 var MgcpCommand mgcp;
5483 interleave {
5484 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE(int2oct(enum2int(rr_cause), 1)))) {}
5485 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005486 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005487 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005488 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005489 }
5490 [] RSL1.receive(tr_RSL_DEACT_SACCH(new_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005491 [] RSL1.receive(tr_RSL_RF_CHAN_REL(new_chan_nr)) {
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005492 RSL1.send(ts_RSL_RF_CHAN_REL_ACK(new_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005493 f_rslem_unregister(0, g_chan_nr, PT := RSL1_PROC);
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005494 }
5495 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {}
5496 }
5497
5498 f_sleep(0.5);
5499 setverdict(pass);
5500}
5501testcase TC_ho_int_radio_link_failure() runs on test_CT {
5502 var MSC_ConnHdlr vc_conn;
5503 f_init(2, true);
5504 f_sleep(1.0);
5505
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005506 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005507
5508 vc_conn := f_start_handler(refers(f_tc_ho_int_radio_link_failure));
5509 vc_conn.done;
5510
5511 /* from f_establish_fully() */
5512 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5513 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5514 /* from handover */
5515 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5516 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
5517 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5518 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:stopped");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005519 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5520 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:stopped");
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005521 f_ctrs_bsc_and_bts_verify();
5522 f_shutdown_helper();
5523}
5524
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005525/* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005526private function f_expect_dlcx_conns() runs on MSC_ConnHdlr {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005527 var MgcpCommand mgcp;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005528 var template MgcpResponse mgcp_resp;
5529 var MGCP_RecvFrom mrf;
5530 var template MgcpMessage msg_resp;
5531 var template MgcpMessage msg_dlcx := {
5532 command := tr_DLCX()
5533 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005534
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005535 if (g_pars.aoip) {
5536 MGCP.receive(tr_DLCX()) -> value mgcp {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005537 log("Got first DLCX: ", mgcp);
5538 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005539 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005540
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005541 MGCP.receive(tr_DLCX()) -> value mgcp {
5542 log("Got second DLCX: ", mgcp);
5543 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
5544 };
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005545 } else {
5546 /* For SCCPLite, BSC doesn't handle the MSC-side */
5547 MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_dlcx)) -> value mrf {
5548 log("Got first DLCX: ", mrf.msg.command);
5549 msg_resp := {
5550 response := ts_DLCX_ACK2(mrf.msg.command.line.trans_id)
5551 }
5552 MGCP_MULTI.send(t_MGCP_SendToMrf(mrf, msg_resp));
5553 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005554 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005555}
5556
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005557private 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 +01005558
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005559 var NcellReports neighbor_rep := {
5560 { rxlev := 20, bcch_freq := 0, bsic := 11 }
5561 };
5562 var octetstring l3_mr := enc_GsmRrL3Message(valueof(ts_MEAS_REP(true, 8, 8, reps := neighbor_rep)));
5563 RSL.send(ts_RSL_MEAS_RES(g_chan_nr, 0, ts_RSL_IE_UplinkMeas, ts_RSL_IE_BS_Power(0), ts_RSL_IE_L1Info,
5564 l3_mr, 0));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005565
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005566 BSSAP.receive(tr_BSSMAP_HandoverRequired(exp_oldToNewBSSIEs));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005567
5568 f_sleep(0.5);
5569 /* The MSC negotiates Handover Request and Handover Request Ack with
5570 * the other BSS and comes back with a BSSMAP Handover Command
5571 * containing an RR Handover Command coming from the target BSS... */
5572
5573 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5574 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5575 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5576 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5577 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5578
5579 /* expect the Handover Command to go out on RR */
5580 var RSL_Message rsl_ho_cmd
5581 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5582 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5583 var RSL_IE_Body rsl_ho_cmd_l3;
5584 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5585 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5586 setverdict(fail);
5587 } else {
5588 log("Found L3 Info: ", rsl_ho_cmd_l3);
5589 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5590 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5591 setverdict(fail);
5592 } else {
5593 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5594 setverdict(pass);
5595 }
5596 }
5597
5598 /* When the other BSS has reported a completed handover, this side is
5599 * torn down. */
5600
5601 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
5602 var BssmapCause cause := enum2int(cause_val);
5603 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5604
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005605 f_expect_dlcx_conns();
Pau Espin Pedrol06199952021-06-15 11:30:00 +02005606
5607 interleave {
5608 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE));
5609 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr));
5610 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr));
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02005611 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
Pau Espin Pedrol06199952021-06-15 11:30:00 +02005612 }
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005613 setverdict(pass);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005614}
5615
5616private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
5617 g_pars := f_gen_test_hdlr_pars();
5618 var PDU_BSSAP ass_req := f_gen_ass_req();
5619 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5620 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5621 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5622 f_establish_fully(ass_req, exp_compl);
5623
5624 f_ho_out_of_this_bsc();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005625}
5626testcase TC_ho_out_of_this_bsc() runs on test_CT {
5627 var MSC_ConnHdlr vc_conn;
5628
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005629 f_init_vty();
5630 f_bts_0_cfg(BSCVTY,
5631 {"neighbor-list mode automatic",
5632 "handover 1",
5633 "handover algorithm 2",
5634 "handover2 window rxlev averaging 1",
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005635 "no neighbors",
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005636 "neighbor lac 99 arfcn 123 bsic any"});
5637 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5638
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005639 f_init(1, true);
5640 f_sleep(1.0);
5641
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005642 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005643
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005644 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
5645 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005646
5647 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5648 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5649 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5650 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5651 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5652 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed");
5653 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005654 f_shutdown_helper();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005655}
5656
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005657private function f_mo_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5658 template (value) RslLinkId link_id := ts_RslLinkID_DCCH(0),
Vadim Yanitskiy2ef6a2f2020-10-08 23:17:32 +07005659 template (present) OCT1 dlci := ?,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005660 octetstring l3 := '0123456789'O)
5661runs on MSC_ConnHdlr {
Neels Hofmeyr43654812020-09-25 01:35:35 +02005662 /* The old lchan and conn should still be active. See that arbitrary L3
5663 * is still going through. */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005664 rsl.send(ts_RSL_DATA_IND(g_chan_nr, link_id, l3));
Neels Hofmeyr43654812020-09-25 01:35:35 +02005665 var template PDU_BSSAP exp_data := {
5666 discriminator := '1'B,
5667 spare := '0000000'B,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005668 dlci := dlci,
5669 lengthIndicator := lengthof(l3),
Neels Hofmeyr43654812020-09-25 01:35:35 +02005670 pdu := {
5671 dtap := l3
5672 }
5673 };
5674 BSSAP.receive(exp_data);
5675 setverdict(pass);
5676}
5677
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005678private function f_mt_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5679 template (present) RslLinkId link_id := tr_RslLinkID_DCCH(0),
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005680 template (value) OCT1 dlci := '00'O,
5681 octetstring l3 := '0123456789'O)
5682runs on MSC_ConnHdlr {
5683 BSSAP.send(PDU_BSSAP:{
5684 discriminator := '1'B,
5685 spare := '0000000'B,
5686 dlci := dlci,
5687 lengthIndicator := lengthof(l3),
5688 pdu := {
5689 dtap := l3
5690 }
5691 });
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005692 rsl.receive(tr_RSL_DATA_REQ(g_chan_nr, link_id, l3));
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005693 setverdict(pass);
5694}
5695
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005696/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
5697 * simply never sends a BSSMAP Handover Command. */
5698private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005699 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005700
5701 var PDU_BSSAP ass_req := f_gen_ass_req();
5702 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5703 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5704 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5705 f_establish_fully(ass_req, exp_compl);
5706
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005707 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005708 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5709
5710 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5711
5712 /* osmo-bsc should time out 10 seconds after the handover started.
5713 * Let's give it a bit extra. */
5714 f_sleep(15.0);
5715
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005716 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005717 f_sleep(1.0);
5718}
5719testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
5720 var MSC_ConnHdlr vc_conn;
5721
5722 f_init(1, true);
5723 f_sleep(1.0);
5724
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005725 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005726
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005727 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
5728 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005729
5730 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5731 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5732 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5733 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5734 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5735 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5736 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005737 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005738}
5739
5740/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
5741 * RR Handover Failure. */
5742private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005743 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005744
5745 var PDU_BSSAP ass_req := f_gen_ass_req();
5746 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5747 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5748 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5749 f_establish_fully(ass_req, exp_compl);
5750
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005751 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005752 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5753
5754 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5755
5756 f_sleep(0.5);
5757 /* The MSC negotiates Handover Request and Handover Request Ack with
5758 * the other BSS and comes back with a BSSMAP Handover Command
5759 * containing an RR Handover Command coming from the target BSS... */
5760
5761 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5762 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5763 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5764 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5765 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5766
5767 /* expect the Handover Command to go out on RR */
5768 var RSL_Message rsl_ho_cmd
5769 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5770 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5771 var RSL_IE_Body rsl_ho_cmd_l3;
5772 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5773 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5774 setverdict(fail);
5775 } else {
5776 log("Found L3 Info: ", rsl_ho_cmd_l3);
5777 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5778 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5779 setverdict(fail);
5780 } else {
5781 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5782 setverdict(pass);
5783 }
5784 }
5785
5786 f_sleep(0.2);
5787 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
5788
5789 /* Should tell the MSC about the failure */
5790 BSSAP.receive(tr_BSSMAP_HandoverFailure);
5791
5792 f_sleep(1.0);
5793
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005794 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005795 f_sleep(1.0);
5796
5797 setverdict(pass);
5798 f_sleep(1.0);
5799}
5800testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
5801 var MSC_ConnHdlr vc_conn;
5802
5803 f_init(1, true);
5804 f_sleep(1.0);
5805
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005806 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005807
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005808 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
5809 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005810
5811 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5812 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5813 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5814 f_ctrs_bsc_and_bts_add(0, "handover:failed");
5815 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5816 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:failed");
5817 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005818 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005819}
5820
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005821/* BSC asks for inter-BSC-out HO, receives BSSMAP Handover Command, but then no reply is received about HO outcome
5822 * (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 +02005823 * and the lchan is released. */
5824private function f_tc_ho_out_fail_no_result_after_ho_cmd(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005825 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005826
5827 var PDU_BSSAP ass_req := f_gen_ass_req();
5828 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5829 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5830 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5831 f_establish_fully(ass_req, exp_compl);
5832
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005833 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005834 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5835
5836 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5837
5838 f_sleep(0.5);
5839 /* The MSC negotiates Handover Request and Handover Request Ack with
5840 * the other BSS and comes back with a BSSMAP Handover Command
5841 * containing an RR Handover Command coming from the target BSS... */
5842
5843 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5844 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5845 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5846 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5847 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5848
5849 /* expect the Handover Command to go out on RR */
5850 var RSL_Message rsl_ho_cmd
5851 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5852 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5853 var RSL_IE_Body rsl_ho_cmd_l3;
5854 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5855 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5856 setverdict(fail);
5857 } else {
5858 log("Found L3 Info: ", rsl_ho_cmd_l3);
5859 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5860 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5861 setverdict(fail);
5862 } else {
5863 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5864 setverdict(pass);
5865 }
5866 }
5867
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005868 /* We get neither success nor failure report from the remote BSS. Eventually T8 times out and we run into 3GPP
5869 * TS 48.008 3.1.5.3.3 "Abnormal Conditions": Clear Request should go to the MSC, and RR should be released
5870 * after Clear Command */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005871
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005872 var PDU_BSSAP rx_clear_request;
Neels Hofmeyre1797aa2019-07-09 19:34:04 +02005873 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
5874 log("Got BSSMAP Clear Request");
5875 /* Instruct BSC to clear channel */
5876 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5877 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5878
5879 var MgcpCommand mgcp;
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005880 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01005881 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
5882 log("Got Deact SACCH");
5883 }
Harald Welte924b6ea2019-02-04 01:05:34 +01005884 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01005885 log("Got RR Release");
5886 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005887 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005888 log("Got RF Chan Rel");
5889 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005890 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005891 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005892 }
5893
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005894 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02005895 BSSAP.receive(tr_BSSMAP_ClearComplete);
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005896
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005897 setverdict(pass);
5898 f_sleep(1.0);
5899}
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02005900testcase TC_ho_out_fail_no_result_after_ho_cmd() runs on test_CT {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005901 var MSC_ConnHdlr vc_conn;
5902
5903 f_init(1, true);
5904 f_sleep(1.0);
5905
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005906 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005907
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02005908 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_result_after_ho_cmd));
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005909 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005910
5911 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5912 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5913 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5914 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5915 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5916 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5917 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005918 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005919}
5920
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005921private 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 +01005922 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
5923 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
5924 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
5925 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
5926 * before we get started. */
5927 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
5928 f_rslem_register(0, new_chan_nr);
5929 g_chan_nr := new_chan_nr;
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02005930 var uint3_t expect_target_tsc := BTS_TSC[0];
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005931 f_sleep(1.0);
5932
5933 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
5934 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
5935 activate(as_Media());
5936
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005937 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005938 f_gen_handover_req(aoip_tla := g_pars.host_aoip_tla,
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02005939 oldToNewBSSIEs := oldToNewBSSIEs,
5940 enc := g_pars.encr)));
Harald Welte6811d102019-04-14 22:23:14 +02005941 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005942
5943 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
5944
5945 var PDU_BSSAP rx_bssap;
5946 var octetstring ho_command_str;
5947
5948 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
Pau Espin Pedrol76ba5412019-06-10 11:00:33 +02005949
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02005950 /* we're sure that the channel activation is done now, verify the parameters in it */
5951 var RSL_Message chan_act := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
5952 f_verify_encr_info(chan_act);
5953 f_chan_act_verify_tsc(chan_act, expect_target_tsc);
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02005954
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005955 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
5956 log("Received L3 Info in HO Request Ack: ", ho_command_str);
5957 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
5958 log("L3 Info in HO Request Ack is ", ho_command);
5959
5960 var GsmArfcn arfcn;
5961 var RslChannelNr actual_new_chan_nr;
5962 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
5963 actual_new_chan_nr, arfcn);
5964
5965 if (actual_new_chan_nr != new_chan_nr) {
5966 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
5967 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
5968 setverdict(fail);
5969 return;
5970 }
5971 log("Handover Command chan_nr is", actual_new_chan_nr);
5972
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02005973 var uint3_t got_tsc := rr_chan_desc_tsc(ho_command.msgs.rrm.handoverCommand.channelDescription2);
5974 if (not match(got_tsc, expect_target_tsc)) {
5975 setverdict(fail, "RR Handover Command: unexpected TSC in Channel Description: expected ",
5976 expect_target_tsc, " got ", got_tsc);
5977 mtc.stop;
5978 } else {
5979 log("handoverCommand: verified TSC = ", got_tsc);
5980 }
5981
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005982 /* Now the MSC forwards the RR Handover Command to the other BSC, which
5983 * tells the MS to handover to the new lchan. Here comes the new MS on
5984 * the new lchan with a Handover RACH: */
5985
5986 /* send handover detect */
5987
5988 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
5989
5990 BSSAP.receive(tr_BSSMAP_HandoverDetect);
5991
5992 /* send handover complete over the new channel */
5993
5994 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
5995 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
5996 enc_PDU_ML3_MS_NW(l3_tx)));
5997
5998 BSSAP.receive(tr_BSSMAP_HandoverComplete);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005999 setverdict(pass);
6000}
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006001
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006002private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006003 var template PDU_ML3_NW_MS exp_rr_rel_tmpl;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006004 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit;
6005 if (not istemplatekind(g_pars.last_used_eutran_plmn, "omit")) {
6006 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006007 }
6008 if (g_pars.exp_fast_return) {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006009 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE_CellSelectInd;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006010 } else {
6011 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006012 }
6013 f_ho_into_this_bsc(id, oldToNewBSSIEs);
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02006014 f_perform_clear(exp_rr_rel_tmpl := exp_rr_rel_tmpl);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006015 setverdict(pass);
6016}
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006017function f_tc_ho_into_this_bsc_main(TestHdlrParams pars) runs on test_CT {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006018 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006019
6020 f_init(1, true);
6021 f_sleep(1.0);
6022
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006023 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006024
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006025 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6026 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006027
6028 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
6029 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006030
6031 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6032 f_ctrs_bsc_and_bts_add(0, "handover:completed");
6033 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6034 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed");
6035 f_ctrs_bsc_and_bts_verify();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006036}
6037
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006038testcase TC_ho_into_this_bsc() runs on test_CT {
6039 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6040 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006041 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006042}
6043
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006044function f_tc_ho_into_this_bsc_a5(OCT1 encr_alg) runs on test_CT {
6045 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6046 pars.encr := valueof(t_EncrParams(encr_alg, f_rnd_octstring(8), f_rnd_octstring(16)));
6047 f_tc_ho_into_this_bsc_main(pars);
6048 f_shutdown_helper();
6049}
6050
6051testcase TC_ho_into_this_bsc_a5_0() runs on test_CT {
6052 f_tc_ho_into_this_bsc_a5('01'O);
6053}
6054
6055testcase TC_ho_into_this_bsc_a5_1() runs on test_CT {
6056 f_tc_ho_into_this_bsc_a5('02'O);
6057}
6058
6059testcase TC_ho_into_this_bsc_a5_3() runs on test_CT {
6060 f_tc_ho_into_this_bsc_a5('08'O);
6061}
6062
6063testcase TC_ho_into_this_bsc_a5_4() runs on test_CT {
6064 f_tc_ho_into_this_bsc_a5('10'O);
6065}
6066
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006067testcase TC_ho_into_this_bsc_tla_v6() runs on test_CT {
6068 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6069 pars.host_aoip_tla := "::6";
6070 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006071 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006072}
6073
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006074/* Similar to TC_ho_into_this_bsc, but when in SRVCC, HO Req contains "Old BSS
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006075 to New BSS Information" IE with "Last Used E-UTRAN PLMN Id", which, when the
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006076 channel is later released (RR CHannel Release), should trigger inclusion of
6077 IE "Cell Selection Indicator after Release of all TCH and SDCCH" with E-UTRAN
6078 neighbors. */
6079testcase TC_srvcc_eutran_to_geran() runs on test_CT {
6080 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6081 pars.last_used_eutran_plmn := '323454'O;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006082 pars.exp_fast_return := true;
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006083 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02006084
6085 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted");
6086 f_ctrs_bsc_and_bts_add(0, "srvcc:completed");
6087 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006088 f_shutdown_helper();
6089}
6090
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006091/* Same as TC_srvcc_eutran_to_geran, but test explicitly forbiding fast return
6092 on the BTS. As a result, RR Release shouldn't contain the EUTRAN neighbor
6093 list when the channel is released. */
6094testcase TC_srvcc_eutran_to_geran_forbid_fast_return() runs on test_CT {
6095 f_init_vty();
6096 f_vty_allow_srvcc_fast_return(true, 0)
6097
6098 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6099 pars.last_used_eutran_plmn := '323454'O;
6100 pars.exp_fast_return := false;
6101 f_tc_ho_into_this_bsc_main(pars);
6102 f_vty_allow_srvcc_fast_return(false, 0);
6103 f_shutdown_helper();
6104}
6105
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006106private function f_tc_srvcc_eutran_to_geran_ho_out(charstring id) runs on MSC_ConnHdlr {
6107 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs;
6108 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
6109 f_ho_into_this_bsc(id, oldToNewBSSIEs);
6110 f_ho_out_of_this_bsc(oldToNewBSSIEs);
6111 setverdict(pass);
6112}
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006113
6114private function f_tc_srvcc_eutran_to_geran_ho_out_main(boolean disable_fast_return)
6115 runs on test_CT {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006116 var MSC_ConnHdlr vc_conn;
6117 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6118
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01006119 f_init_vty();
6120 f_bts_0_cfg(BSCVTY,
6121 {"neighbor-list mode automatic",
6122 "handover 1",
6123 "handover algorithm 2",
6124 "handover2 window rxlev averaging 1",
6125 "no neighbors",
6126 "neighbor lac 99 arfcn 123 bsic any"});
6127 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6128
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006129 f_init(1, true);
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006130 if (disable_fast_return) {
6131 f_vty_allow_srvcc_fast_return(true, 0);
6132 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006133 f_sleep(1.0);
6134
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006135 f_ctrs_bsc_and_bts_handover_init();
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006136
6137 pars.last_used_eutran_plmn := '323454'O;
6138 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6139 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
6140
6141 vc_conn := f_start_handler(refers(f_tc_srvcc_eutran_to_geran_ho_out), pars);
6142 vc_conn.done;
6143
6144 f_ctrs_bsc_and_bts_add(0, "handover:attempted", 2);
6145 f_ctrs_bsc_and_bts_add(0, "handover:completed", 2);
6146 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted", 1);
6147 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed", 1);
6148 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted", 1);
6149 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed", 1);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02006150
6151 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted", 1);
6152 f_ctrs_bsc_and_bts_add(0, "srvcc:completed", 1);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006153 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006154
6155 if (disable_fast_return) {
6156 f_vty_allow_srvcc_fast_return(false, 0);
6157 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006158 f_shutdown_helper();
6159}
6160
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006161/* First, HO into BSC from EUTRAN (SRVCC): HO Request contains "Old BSS to New
6162 BSS Information" IE with "Last Used E-UTRAN PLMN Id".
6163 Second, HO to another BSC: HO Required contains "Old BSS to New BSS Information"
6164 IE with "Last Used E-UTRAN PLMN Id" from first step. */
6165testcase TC_srvcc_eutran_to_geran_ho_out() runs on test_CT {
6166 f_tc_srvcc_eutran_to_geran_ho_out_main(false);
6167}
6168/* Validate subsequent intra-GSM-HO works the same (with OldBSSToNewBSSInfo IE)
6169 * independently of fast-reture allowed/forbidden in local BTS */
6170testcase TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() runs on test_CT {
6171 f_tc_srvcc_eutran_to_geran_ho_out_main(true);
6172}
6173
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006174private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
6175 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6176 f_rslem_register(0, new_chan_nr);
6177 g_chan_nr := new_chan_nr;
6178 f_sleep(1.0);
6179
6180 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6181 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6182 activate(as_Media());
6183
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006184 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006185 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006186 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006187
6188 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6189
6190 var PDU_BSSAP rx_bssap;
6191 var octetstring ho_command_str;
6192
6193 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6194
6195 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6196 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6197 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6198 log("L3 Info in HO Request Ack is ", ho_command);
6199
6200 var GsmArfcn arfcn;
6201 var RslChannelNr actual_new_chan_nr;
6202 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6203 actual_new_chan_nr, arfcn);
6204
6205 if (actual_new_chan_nr != new_chan_nr) {
6206 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6207 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6208 setverdict(fail);
6209 return;
6210 }
6211 log("Handover Command chan_nr is", actual_new_chan_nr);
6212
Neels Hofmeyr61ca08d2019-05-06 23:52:22 +02006213 /* For deterministic test results, give some time for the MGW endpoint to be configured */
6214 f_sleep(1.0);
6215
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006216 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6217 * tells the MS to handover to the new lchan. In this case, the MS
6218 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
6219 * Handover Failure to the MSC. The procedure according to 3GPP TS
6220 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
6221 * BSSMAP Clear Command: */
6222
6223 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6224 var BssmapCause cause := enum2int(cause_val);
6225 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6226
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006227 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006228 BSSAP.receive(tr_BSSMAP_ClearComplete);
6229
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006230 setverdict(pass);
6231 f_sleep(1.0);
6232
6233 setverdict(pass);
6234}
6235testcase TC_ho_in_fail_msc_clears() runs on test_CT {
6236 var MSC_ConnHdlr vc_conn;
6237 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6238
6239 f_init(1, true);
6240 f_sleep(1.0);
6241
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006242 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006243
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006244 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6245 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006246
6247 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
6248 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006249
6250 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6251 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
6252 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6253 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
6254 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006255 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006256}
6257
6258private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
6259 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
6260 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
6261 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
6262 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
6263 * before we get started. */
6264 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6265 f_rslem_register(0, new_chan_nr);
6266 g_chan_nr := new_chan_nr;
6267 f_sleep(1.0);
6268
6269 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6270 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6271 activate(as_Media());
6272
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006273 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006274 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006275 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006276
6277 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6278
6279 var PDU_BSSAP rx_bssap;
6280 var octetstring ho_command_str;
6281
6282 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6283
6284 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6285 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6286 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6287 log("L3 Info in HO Request Ack is ", ho_command);
6288
6289 var GsmArfcn arfcn;
6290 var RslChannelNr actual_new_chan_nr;
6291 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6292 actual_new_chan_nr, arfcn);
6293
6294 if (actual_new_chan_nr != new_chan_nr) {
6295 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6296 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6297 setverdict(fail);
6298 return;
6299 }
6300 log("Handover Command chan_nr is", actual_new_chan_nr);
6301
6302 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6303 * tells the MS to handover to the new lchan. Here comes the new MS on
6304 * the new lchan with a Handover RACH: */
6305
6306 /* send handover detect */
6307
6308 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
6309
6310 BSSAP.receive(tr_BSSMAP_HandoverDetect);
6311
6312 /* The MSC chooses to clear the connection now, maybe we got the
6313 * Handover RACH on the new cell but the MS still signaled Handover
6314 * Failure to the old BSS? */
6315
6316 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6317 var BssmapCause cause := enum2int(cause_val);
6318 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6319
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006320 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006321 BSSAP.receive(tr_BSSMAP_ClearComplete);
6322
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006323 f_sleep(1.0);
6324}
6325testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
6326 var MSC_ConnHdlr vc_conn;
6327 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6328
6329 f_init(1, true);
6330 f_sleep(1.0);
6331
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006332 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006333
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006334 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6335 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006336
6337 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
6338 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006339
6340 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6341 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
6342 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6343 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
6344 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006345 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006346}
6347
6348/* The new BSS's lchan times out before the MSC decides that handover failed. */
6349private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
6350 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6351 f_rslem_register(0, new_chan_nr);
6352 g_chan_nr := new_chan_nr;
6353 f_sleep(1.0);
6354
6355 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6356 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6357 activate(as_Media());
6358
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006359 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006360 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006361 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006362
6363 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6364
6365 var PDU_BSSAP rx_bssap;
6366 var octetstring ho_command_str;
6367
6368 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6369
6370 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6371 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6372 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6373 log("L3 Info in HO Request Ack is ", ho_command);
6374
6375 var GsmArfcn arfcn;
6376 var RslChannelNr actual_new_chan_nr;
6377 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6378 actual_new_chan_nr, arfcn);
6379
6380 if (actual_new_chan_nr != new_chan_nr) {
6381 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6382 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6383 setverdict(fail);
6384 return;
6385 }
6386 log("Handover Command chan_nr is", actual_new_chan_nr);
6387
6388 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6389 * tells the MS to handover to the new lchan. But the MS never shows up
6390 * on the new lchan. */
6391
6392 BSSAP.receive(tr_BSSMAP_HandoverFailure);
6393
6394 /* Did osmo-bsc also send a Clear Request? */
6395 timer T := 0.5;
6396 T.start;
6397 alt {
6398 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
6399 [] T.timeout { }
6400 }
6401
6402 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
6403 * asked for it, this is a Handover Failure after all). */
6404
6405 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6406 var BssmapCause cause := enum2int(cause_val);
6407 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6408
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006409 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006410 BSSAP.receive(tr_BSSMAP_ClearComplete);
6411
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006412 f_sleep(1.0);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006413}
6414testcase TC_ho_in_fail_no_detect() runs on test_CT {
6415 var MSC_ConnHdlr vc_conn;
6416 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6417
6418 f_init(1, true);
6419 f_sleep(1.0);
6420
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006421 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006422
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006423 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6424 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006425
6426 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
6427 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006428
6429 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6430 f_ctrs_bsc_and_bts_add(0, "handover:error");
6431 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6432 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
6433 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006434 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006435}
6436
6437/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
6438private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
6439 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6440 f_rslem_register(0, new_chan_nr);
6441 g_chan_nr := new_chan_nr;
6442 f_sleep(1.0);
6443
6444 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6445 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6446 activate(as_Media());
6447
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006448 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006449 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006450 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006451
6452 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6453
6454 var PDU_BSSAP rx_bssap;
6455 var octetstring ho_command_str;
6456
6457 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6458
6459 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6460 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6461 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6462 log("L3 Info in HO Request Ack is ", ho_command);
6463
6464 var GsmArfcn arfcn;
6465 var RslChannelNr actual_new_chan_nr;
6466 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6467 actual_new_chan_nr, arfcn);
6468
6469 if (actual_new_chan_nr != new_chan_nr) {
6470 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6471 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6472 setverdict(fail);
6473 return;
6474 }
6475 log("Handover Command chan_nr is", actual_new_chan_nr);
6476
6477 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6478 * tells the MS to handover to the new lchan. But the MS never shows up
6479 * on the new lchan. */
6480
6481 BSSAP.receive(tr_BSSMAP_HandoverFailure);
6482
6483 /* MSC plays dumb and sends no Clear Command */
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006484 var PDU_BSSAP rx_clear_request;
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02006485
6486 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006487 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
6488 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6489 };
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006490 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006491 BSSAP.receive(tr_BSSMAP_ClearComplete);
6492
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006493 f_sleep(1.0);
6494}
6495testcase TC_ho_in_fail_no_detect2() runs on test_CT {
6496 var MSC_ConnHdlr vc_conn;
6497 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6498
6499 f_init(1, true);
6500 f_sleep(1.0);
6501
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006502 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006503
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006504 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6505 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006506
6507 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
6508 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006509
6510 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6511 f_ctrs_bsc_and_bts_add(0, "handover:error");
6512 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6513 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
6514 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006515 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006516}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006517
Neels Hofmeyr91401012019-07-11 00:42:35 +02006518type record of charstring Commands;
6519
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006520private function f_bts_0_cfg(TELNETasp_PT pt, Commands cmds := {})
Neels Hofmeyr91401012019-07-11 00:42:35 +02006521{
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006522 f_vty_enter_cfg_bts(pt, 0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006523 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006524 f_vty_transceive(pt, cmds[i]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006525 }
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006526 f_vty_transceive(pt, "end");
Neels Hofmeyr91401012019-07-11 00:42:35 +02006527}
6528
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01006529private function f_cs7_inst_0_cfg(TELNETasp_PT pt, Commands cmds := {})
6530{
6531 f_vty_enter_cfg_cs7_inst(pt, 0);
6532 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
6533 f_vty_transceive(pt, cmds[i]);
6534 }
6535 f_vty_transceive(pt, "end");
6536}
6537
Neels Hofmeyr91401012019-07-11 00:42:35 +02006538private function f_probe_for_handover(charstring log_label,
6539 charstring log_descr,
6540 charstring handover_vty_cmd,
6541 boolean expect_handover,
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006542 boolean is_inter_bsc_handover := false,
6543 template uint3_t expect_target_tsc := ?)
Neels Hofmeyr91401012019-07-11 00:42:35 +02006544runs on MSC_ConnHdlr
6545{
Neels Hofmeyrb3fc8982020-05-11 00:16:42 +02006546 /* We're going to thwart any and all handover attempts, just be ready to handle (and ignore) handover target
6547 * lchans to be established on bts 1 or bts 2. */
6548 f_rslem_suspend(RSL1_PROC);
6549 f_rslem_suspend(RSL2_PROC);
6550
Neels Hofmeyr91401012019-07-11 00:42:35 +02006551 var RSL_Message rsl;
6552
6553 var charstring log_msg := " (expecting handover)"
6554 if (not expect_handover) {
6555 log_msg := " (expecting NO handover)";
6556 }
6557 log("f_probe_for_handover starting: " & log_label & ": " & log_descr & log_msg);
6558 f_vty_transceive(BSCVTY, handover_vty_cmd);
6559
Neels Hofmeyr91401012019-07-11 00:42:35 +02006560 timer T := 2.0;
6561 T.start;
6562
6563 alt {
6564 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
6565 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
6566 log("Rx L3 from net: ", l3);
6567 if (ischosen(l3.msgs.rrm.handoverCommand)) {
6568 var RslChannelNr new_chan_nr;
6569 var GsmArfcn arfcn;
6570 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
6571 new_chan_nr, arfcn);
6572 log("Handover to new chan ", new_chan_nr, " on ARFCN ", arfcn);
6573 log(l3.msgs.rrm.handoverCommand);
6574
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006575 /* Verify correct TSC in handoverCommand */
6576 var uint3_t got_tsc := rr_chan_desc_tsc(l3.msgs.rrm.handoverCommand.channelDescription2);
6577 if (not match(got_tsc, expect_target_tsc)) {
6578 setverdict(fail, "RR Handover Command: unexpected TSC in Channel Description: expected ",
6579 expect_target_tsc, " got ", got_tsc);
6580 mtc.stop;
6581 } else {
6582 log("handoverCommand: verified TSC = ", got_tsc, " (matches ",
6583 expect_target_tsc, ")");
6584 }
6585
Neels Hofmeyr91401012019-07-11 00:42:35 +02006586 /* Need to register for new lchan on new BTS -- it's either bts 1 or bts 2. It doesn't really
6587 * matter on which BTS it really is, we're not going to follow through an entire handover
6588 * anyway. */
6589 f_rslem_register(0, new_chan_nr, RSL1_PROC);
6590 f_rslem_resume(RSL1_PROC);
6591 f_rslem_register(0, new_chan_nr, RSL2_PROC);
6592 f_rslem_resume(RSL2_PROC);
6593
6594 if (expect_handover and not is_inter_bsc_handover) {
6595 setverdict(pass);
6596 log("f_probe_for_handover(" & log_label & "): Got RSL Handover Command as expected.");
6597 } else {
6598 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got RSL Handover Command. "
6599 & log_label & ": " & log_descr);
6600 }
6601
6602 log("f_probe_for_handover(" & log_label & "): Ending the test: Handover Failure stops the procedure.");
6603 /* osmo-bsc has triggered Handover. That's all we need to know for this test, reply with
6604 * Handover Failure. */
6605 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
6606
6607 /* target BTS is told to release lchan again; don't care which BTS nor what messages. */
6608 f_sleep(0.5);
6609 RSL1.clear;
6610 RSL2.clear;
6611 log("f_probe_for_handover(" & log_label & "): done (got RSL Handover Command)");
6612 break;
6613 } else {
6614 repeat;
6615 }
6616 }
6617 [] BSSAP.receive(tr_BSSMAP_HandoverRequired) {
6618 if (expect_handover and is_inter_bsc_handover) {
6619 setverdict(pass);
6620 log("f_probe_for_handover(" & log_label & "): Got BSSMAP Handover Required as expected.");
6621 } else {
6622 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got BSSMAP Handover Required. "
6623 & log_label & ": " & log_descr);
6624 }
6625
6626 log("f_probe_for_handover(" & log_label & "): done (got BSSMAP Handover Required)");
6627
6628 /* Note: f_tc_ho_neighbor_config_start() sets T7, the timeout for BSSMAP Handover Required, to
6629 * 1 second. There is no legal way to quickly abort a handover after a BSSMAP Handover Required,
6630 * setting a short timeout and waiting is the only way. */
6631 log("f_probe_for_handover(" & log_label & "): waiting for inter-BSC HO to time out...");
6632 f_sleep(1.5);
6633 log("f_probe_for_handover(" & log_label & "): ...done");
6634
6635 break;
6636 }
6637 [] T.timeout {
6638 if (expect_handover) {
6639 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected Handover, but got none. "
6640 & log_label & ": " & log_descr);
6641 } else {
6642 setverdict(pass);
6643 log("f_probe_for_handover(" & log_label & "): Got no Handover, as expected.");
6644 }
6645 log("f_probe_for_handover(" & log_label & "): done (got no Handover)");
6646 break;
6647 }
6648 }
6649
6650 f_rslem_resume(RSL1_PROC);
6651 f_rslem_resume(RSL2_PROC);
6652 f_sleep(3.0);
6653 RSL.clear;
6654
6655 log("f_probe_for_handover(" & log_label & "): done clearing");
6656}
6657
6658/* Test the effect of various neighbor configuration scenarios:
6659 *
6660 * To avoid complexity, block off any actual handover operation, and always remain on the lchan at bts 0.
6661 * Reconfigure the neighbors for bts 0, trigger a Handover, and probe whether osmo-bsc does or doesn't start HO.
6662 */
6663private function f_tc_ho_neighbor_config_start() runs on MSC_ConnHdlr {
6664 g_pars := f_gen_test_hdlr_pars();
6665 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
6666 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006667
6668 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
6669 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
6670
6671 /* Establish lchan at bts 0 */
6672 f_establish_fully(ass_cmd, exp_compl);
6673
6674 /* Shorten the inter-BSC Handover timeout, to not wait so long for inter-BSC Handovers */
6675 f_vty_enter_cfg_network(BSCVTY);
6676 f_vty_transceive(BSCVTY, "timer T7 1");
6677 f_vty_transceive(BSCVTY, "end");
6678}
6679
6680private function f_tc_ho_neighbor_config_1(charstring id) runs on MSC_ConnHdlr {
6681 f_tc_ho_neighbor_config_start();
6682
6683 /*
6684 * bts 0 ARFCN 871 BSIC 10
6685 * bts 1 ARFCN 871 BSIC 11
6686 * bts 2 ARFCN 871 BSIC 12
6687 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6688 */
6689
6690 log("f_tc_ho_neighbor_config: 1. No 'neighbor' config");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006691 f_bts_0_cfg(BSCVTY, {"no neighbors"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006692 f_probe_for_handover("1.a", "HO to bts 1 works, implicitly listed as neighbor (legacy behavior when none are configured)",
6693 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006694 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006695
6696 f_probe_for_handover("1.b", "HO to unknown cell does not start",
6697 "handover any to arfcn 13 bsic 39",
6698 false);
6699
6700 f_probe_for_handover("1.c", "HO to 871-12 is ambiguous = error",
6701 "handover any to arfcn 871 bsic 12",
6702 false);
6703
6704 f_probe_for_handover("1.d", "HO to 871-11 still works (verify that this test properly cleans up)",
6705 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006706 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006707}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006708testcase TC_ho_neighbor_config_1() runs on test_CT {
6709 var MSC_ConnHdlr vc_conn;
6710 f_init(3, true, guard_timeout := 60.0);
6711 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006712 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006713 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_1));
6714 vc_conn.done;
6715
6716 /* f_tc_ho_neighbor_config_start() */
6717 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6718 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6719
6720 /* 1.a */
6721 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6722 * handover quickly by sending a Handover Failure message. */
6723 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6724 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6725 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6726 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006727 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6728 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006729
6730 /* 1.b */
6731 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6732 f_ctrs_bsc_and_bts_add(0, "handover:error");
6733
6734 /* 1.c */
6735 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6736 f_ctrs_bsc_and_bts_add(0, "handover:error");
6737
6738 /* 1.d */
6739 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6740 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6741 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6742 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006743 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6744 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006745
6746 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006747 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006748}
6749
Neels Hofmeyr91401012019-07-11 00:42:35 +02006750private function f_tc_ho_neighbor_config_2(charstring id) runs on MSC_ConnHdlr {
6751 f_tc_ho_neighbor_config_start();
6752
6753 /*
6754 * bts 0 ARFCN 871 BSIC 10
6755 * bts 1 ARFCN 871 BSIC 11
6756 * bts 2 ARFCN 871 BSIC 12
6757 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6758 */
6759
6760 log("f_tc_ho_neighbor_config: 2. explicit local neighbor: 'neighbor bts 1'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006761 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006762 f_sleep(0.5);
6763
6764 f_probe_for_handover("2.a", "HO to bts 1 works, explicitly listed as neighbor",
6765 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006766 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006767
6768 f_probe_for_handover("2.b", "HO to bts 2 doesn't work, not listed as neighbor",
6769 "handover any to arfcn 871 bsic 12",
6770 false);
6771}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006772testcase TC_ho_neighbor_config_2() runs on test_CT {
6773 var MSC_ConnHdlr vc_conn;
6774 f_init(3, true, guard_timeout := 50.0);
6775 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006776 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006777 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_2));
6778 vc_conn.done;
6779
6780 /* f_tc_ho_neighbor_config_start() */
6781 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6782 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6783
6784 /* 2.a */
6785 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6786 * handover quickly by sending a Handover Failure message. */
6787 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6788 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6789 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6790 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006791 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6792 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006793
6794 /* 2.b */
6795 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6796 f_ctrs_bsc_and_bts_add(0, "handover:error");
6797
6798 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006799 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006800}
6801
Neels Hofmeyr91401012019-07-11 00:42:35 +02006802private function f_tc_ho_neighbor_config_3(charstring id) runs on MSC_ConnHdlr {
6803 f_tc_ho_neighbor_config_start();
6804
6805 /*
6806 * bts 0 ARFCN 871 BSIC 10
6807 * bts 1 ARFCN 871 BSIC 11
6808 * bts 2 ARFCN 871 BSIC 12
6809 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6810 */
6811
6812 log("f_tc_ho_neighbor_config: 3. explicit local neighbor: 'neighbor bts 2'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006813 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006814 f_sleep(0.5);
6815
6816 f_probe_for_handover("3.a", "HO to bts 1 doesn't work, not listed as neighbor",
6817 "handover any to arfcn 871 bsic 11",
6818 false);
6819 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",
6820 "handover any to arfcn 871 bsic 12",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006821 true, expect_target_tsc := BTS_TSC[2]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006822}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006823testcase TC_ho_neighbor_config_3() runs on test_CT {
6824 var MSC_ConnHdlr vc_conn;
6825 f_init(3, true, guard_timeout := 50.0);
6826 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006827 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006828 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_3));
6829 vc_conn.done;
6830
6831 /* f_tc_ho_neighbor_config_start() */
6832 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6833 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6834
6835 /* 3.a */
6836 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6837 f_ctrs_bsc_and_bts_add(0, "handover:error");
6838
6839 /* 3.b */
6840 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6841 * handover quickly by sending a Handover Failure message. */
6842 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6843 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6844 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6845 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006846 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:attempted");
6847 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006848
6849 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006850 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006851}
6852
Neels Hofmeyr91401012019-07-11 00:42:35 +02006853private function f_tc_ho_neighbor_config_4(charstring id) runs on MSC_ConnHdlr {
6854 f_tc_ho_neighbor_config_start();
6855
6856 /*
6857 * bts 0 ARFCN 871 BSIC 10
6858 * bts 1 ARFCN 871 BSIC 11
6859 * bts 2 ARFCN 871 BSIC 12
6860 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6861 */
6862
6863 log("f_tc_ho_neighbor_config: 4. explicit remote neighbor: 'neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006864 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006865 f_sleep(0.5);
6866
6867 f_probe_for_handover("4.a", "HO to bts 1 doesn't work, not listed as neighbor",
6868 "handover any to arfcn 871 bsic 11",
6869 false);
6870 f_probe_for_handover("4.b", "HO to bts 2 doesn't work, not listed as neighbor",
6871 "handover any to arfcn 871 bsic 12",
6872 false);
6873 f_probe_for_handover("4.c", "HO to 123-45 triggers inter-BSC HO",
6874 "handover any to arfcn 123 bsic 45",
6875 true, true);
6876}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006877testcase TC_ho_neighbor_config_4() runs on test_CT {
6878 var MSC_ConnHdlr vc_conn;
6879 f_init(3, true, guard_timeout := 50.0);
6880 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006881 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006882 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_4));
6883 vc_conn.done;
6884
6885 /* f_tc_ho_neighbor_config_start() */
6886 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6887 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6888
6889 /* 4.a */
6890 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6891 f_ctrs_bsc_and_bts_add(0, "handover:error");
6892
6893 /* 4.b */
6894 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6895 f_ctrs_bsc_and_bts_add(0, "handover:error");
6896
6897 /* 4.c */
6898 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6899 * handover quickly by timing out after the Handover Required message */
6900 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6901 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
6902 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
6903 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
6904
6905 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006906 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006907}
6908
Neels Hofmeyr91401012019-07-11 00:42:35 +02006909private function f_tc_ho_neighbor_config_5(charstring id) runs on MSC_ConnHdlr {
6910 f_tc_ho_neighbor_config_start();
6911
6912 /*
6913 * bts 0 ARFCN 871 BSIC 10
6914 * bts 1 ARFCN 871 BSIC 11
6915 * bts 2 ARFCN 871 BSIC 12
6916 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6917 */
6918
6919 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 +02006920 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006921 f_sleep(0.5);
6922
6923 f_probe_for_handover("5.a", "HO to 871-12 triggers inter-BSC HO (ignoring local cells with same ARFCN+BSIC)",
6924 "handover any to arfcn 871 bsic 12",
6925 true, true);
6926}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006927testcase TC_ho_neighbor_config_5() runs on test_CT {
6928 var MSC_ConnHdlr vc_conn;
6929 f_init(3, true);
6930 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006931 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006932 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_5));
6933 vc_conn.done;
6934
6935 /* f_tc_ho_neighbor_config_start() */
6936 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6937 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6938
6939 /* 5 */
6940 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6941 * handover quickly by timing out after the Handover Required message */
6942 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6943 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
6944 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
6945 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
6946
6947 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006948 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006949}
6950
Neels Hofmeyr91401012019-07-11 00:42:35 +02006951private function f_tc_ho_neighbor_config_6(charstring id) runs on MSC_ConnHdlr {
6952 f_tc_ho_neighbor_config_start();
6953
6954 /*
6955 * bts 0 ARFCN 871 BSIC 10
6956 * bts 1 ARFCN 871 BSIC 11
6957 * bts 2 ARFCN 871 BSIC 12
6958 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6959 */
6960
6961 log("f_tc_ho_neighbor_config: 6. config error: explicit local and remote neighbors with ambiguous ARFCN+BSIC:"
6962 & " 'neighbor bts 2; neighbor lac 99 arfcn 871 bsic 12'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006963 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006964 f_sleep(0.5);
6965
6966 f_probe_for_handover("6.a", "HO to 871-12 is ambiguous = error",
6967 "handover any to arfcn 871 bsic 12",
6968 false);
6969}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006970testcase TC_ho_neighbor_config_6() runs on test_CT {
6971 var MSC_ConnHdlr vc_conn;
6972 f_init(3, true);
6973 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006974 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006975 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_6));
6976 vc_conn.done;
6977
6978 /* f_tc_ho_neighbor_config_start() */
6979 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6980 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6981
6982 /* 6.a */
6983 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6984 * handover quickly by timing out after the Handover Required message */
6985 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6986 f_ctrs_bsc_and_bts_add(0, "handover:error");
6987
6988 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006989 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006990}
6991
Neels Hofmeyr91401012019-07-11 00:42:35 +02006992private function f_tc_ho_neighbor_config_7(charstring id) runs on MSC_ConnHdlr {
6993 f_tc_ho_neighbor_config_start();
6994
6995 /*
6996 * bts 0 ARFCN 871 BSIC 10
6997 * bts 1 ARFCN 871 BSIC 11
6998 * bts 2 ARFCN 871 BSIC 12
6999 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7000 */
7001
7002 log("f_tc_ho_neighbor_config: 7. explicit local and remote neighbors:"
7003 & " 'neighbor bts 2; neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007004 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007005 f_sleep(0.5);
7006
7007 f_probe_for_handover("7.a", "HO to 871-12 does HO to bts 2",
7008 "handover any to arfcn 871 bsic 12",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02007009 true, expect_target_tsc := BTS_TSC[2]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02007010 f_probe_for_handover("7.b", "HO to 123-45 triggers inter-BSC HO",
7011 "handover any to arfcn 123 bsic 45",
7012 true, true);
7013}
Neels Hofmeyr91401012019-07-11 00:42:35 +02007014testcase TC_ho_neighbor_config_7() runs on test_CT {
7015 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf2b88032020-06-16 00:35:04 +02007016 f_init(3, true, guard_timeout := 50.0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02007017 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007018 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007019 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_7));
7020 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007021
7022 /* f_tc_ho_neighbor_config_start() */
7023 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7024 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7025
7026 /* 7.a */
7027 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
7028 * handover quickly by sending a Handover Failure message. */
7029 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7030 f_ctrs_bsc_and_bts_add(0, "handover:failed");
7031 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
7032 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007033 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:attempted");
7034 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007035
7036 /* 7.b */
7037 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7038 * handover quickly by timing out after the Handover Required message */
7039 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7040 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
7041 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
7042 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
7043
7044 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007045 f_shutdown_helper();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007046}
7047
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007048/* OS#3041: Open and close N connections in a normal fashion, and expect no
7049 * BSSMAP Reset just because of that. */
7050testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
7051 var default d;
7052 var integer i;
7053 var DchanTuple dt;
7054
7055 f_init();
7056
7057 /* Wait for initial BSSMAP Reset to pass */
7058 f_sleep(4.0);
7059
7060 d := activate(no_bssmap_reset());
7061
7062 /* Setup up a number of connections and RLSD them again from the MSC
7063 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7064 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02007065 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007066 /* Since we're doing a lot of runs, give each one a fresh
7067 * T_guard from the top. */
7068 T_guard.start;
7069
7070 /* Setup a BSSAP connection and clear it right away. This is
7071 * the MSC telling the BSC about a planned release, it's not an
7072 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02007073 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007074
7075 /* MSC disconnects (RLSD). */
7076 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
7077 }
7078
7079 /* In the buggy behavior, a timeout of 2 seconds happens between above
7080 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7081 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7082 f_sleep(4.0);
7083
7084 deactivate(d);
7085 f_shutdown_helper();
7086}
Harald Welte552620d2017-12-16 23:21:36 +01007087
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007088/* OS#3041: Open and close N connections in a normal fashion, and expect no
7089 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
7090 * the MSC. */
7091testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
7092 var default d;
7093 var integer i;
7094 var DchanTuple dt;
7095 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007096 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
7097 var BssmapCause cause := enum2int(cause_val);
7098
7099 f_init();
7100
7101 /* Wait for initial BSSMAP Reset to pass */
7102 f_sleep(4.0);
7103
7104 d := activate(no_bssmap_reset());
7105
7106 /* Setup up a number of connections and RLSD them again from the MSC
7107 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7108 * Let's do it some more times for good measure. */
7109 for (i := 0; i < 8; i := i+1) {
7110 /* Since we're doing a lot of runs, give each one a fresh
7111 * T_guard from the top. */
7112 T_guard.start;
7113
7114 /* Setup a BSSAP connection and clear it right away. This is
7115 * the MSC telling the BSC about a planned release, it's not an
7116 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02007117 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007118
7119 /* Instruct BSC to clear channel */
7120 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7121
7122 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02007123 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007124 }
7125
7126 /* In the buggy behavior, a timeout of 2 seconds happens between above
7127 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7128 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7129 f_sleep(4.0);
7130
7131 deactivate(d);
7132 f_shutdown_helper();
7133}
7134
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007135/* OS#3041: Open and close N connections in a normal fashion, and expect no
7136 * BSSMAP Reset just because of that. Close connections from the MS side with a
7137 * Release Ind on RSL. */
7138testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
7139 var default d;
7140 var integer i;
7141 var DchanTuple dt;
7142 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007143 var integer j;
7144
7145 f_init();
7146
7147 /* Wait for initial BSSMAP Reset to pass */
7148 f_sleep(4.0);
7149
7150 d := activate(no_bssmap_reset());
7151
7152 /* Setup up a number of connections and RLSD them again from the MSC
7153 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7154 * Let's do it some more times for good measure. */
7155 for (i := 0; i < 8; i := i+1) {
7156 /* Since we're doing a lot of runs, give each one a fresh
7157 * T_guard from the top. */
7158 T_guard.start;
7159
7160 /* Setup a BSSAP connection and clear it right away. This is
7161 * the MSC telling the BSC about a planned release, it's not an
7162 * erratic loss of a connection. */
7163 dt := f_est_dchan('23'O, 23, '00010203040506'O);
7164
7165 /* simulate RLL REL IND */
7166 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
7167
7168 /* expect Clear Request on MSC side */
7169 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
7170
7171 /* Instruct BSC to clear channel */
7172 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
7173 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7174
7175 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02007176 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007177 }
7178
7179 /* In the buggy behavior, a timeout of 2 seconds happens between above
7180 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7181 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7182 f_sleep(4.0);
7183
7184 deactivate(d);
7185 f_shutdown_helper();
7186}
7187
Harald Welte94e0c342018-04-07 11:33:23 +02007188/***********************************************************************
7189 * IPA style dynamic PDCH
7190 ***********************************************************************/
7191
7192private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
7193 template (omit) RSL_Cause nack := omit)
7194runs on test_CT {
7195 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
7196 var RSL_Message rsl_unused;
7197 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
7198 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
7199 /* expect the BSC to issue the related RSL command */
7200 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7201 if (istemplatekind(nack, "omit")) {
7202 /* respond with a related acknowledgement */
7203 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7204 } else {
7205 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
7206 }
7207}
7208
7209private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
7210 template (omit) RSL_Cause nack := omit)
7211runs on test_CT {
7212 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
7213 var RSL_Message rsl_unused;
7214 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
7215 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
7216 /* expect the BSC to issue the related RSL command */
7217 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
7218 if (istemplatekind(nack, "omit")) {
7219 /* respond with a related acknowledgement */
7220 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
7221 } else {
7222 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
7223 }
7224}
7225
7226private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
7227runs on test_CT return charstring {
7228 var charstring cmd, resp;
7229 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01007230 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02007231}
7232
7233private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
7234 template charstring exp)
7235runs on test_CT {
7236 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
7237 if (not match(mode, exp)) {
7238 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02007239 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02007240 }
7241}
7242
7243private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
7244runs on test_CT {
7245 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
7246 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
7247 f_vty_transceive(BSCVTY, "end");
7248}
7249
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007250
7251private function f_ts_reset_chcomb(integer bts_nr) runs on test_CT {
7252 var integer i;
7253 for (i := 0; i < 8; i := i + 1) {
7254 f_ts_set_chcomb(bts_nr, 0, i, phys_chan_config[i]);
7255 }
7256}
7257
Harald Welte94e0c342018-04-07 11:33:23 +02007258private const charstring TCHF_MODE := "TCH/F mode";
7259private const charstring TCHH_MODE := "TCH/H mode";
7260private const charstring PDCH_MODE := "PDCH mode";
7261private const charstring NONE_MODE := "NONE mode";
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007262private const charstring SDCCH8_MODE := "SDCCH8 mode";
Harald Welte94e0c342018-04-07 11:33:23 +02007263
7264/* Test IPA PDCH activation / deactivation triggered by VTY */
7265testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
7266 var RSL_Message rsl_unused;
7267
7268 /* change Timeslot 6 before f_init() starts RSL */
7269 f_init_vty();
7270 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
7271 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7272
7273 f_init(1, false);
7274 f_sleep(1.0);
7275
7276 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
7277
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007278 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007279 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7280 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7281 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7282 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7283 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007284 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007285 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7286
7287 /* De-activate it via VTY */
7288 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7289 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007290 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007291 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7292
7293 /* re-activate it via VTY */
7294 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
7295 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007296 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007297 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7298
7299 /* and finally de-activate it again */
7300 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7301 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007302 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007303 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7304
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007305 /* clean up config */
7306 f_ts_set_chcomb(0, 0, 6, "PDCH");
7307
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007308 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007309}
7310
7311/* Test IPA PDCH activation NACK */
7312testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
7313 var RSL_Message rsl_unused;
7314
7315 /* change Timeslot 6 before f_init() starts RSL */
7316 f_init_vty();
7317 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
7318 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7319
7320 f_init(1, false);
7321 f_sleep(1.0);
7322
7323 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
7324
7325 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7326 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7327 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7328 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7329 f_sleep(1.0);
7330 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7331
7332 /* De-activate it via VTY */
7333 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7334 f_sleep(1.0);
7335 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7336
7337 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
7338 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
7339 f_sleep(1.0);
7340 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7341
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007342 /* clean up config */
7343 f_ts_set_chcomb(0, 0, 6, "PDCH");
7344
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007345 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007346}
7347
7348
7349/***********************************************************************
7350 * Osmocom style dynamic PDCH
7351 ***********************************************************************/
7352
7353private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
7354 template (omit) RSL_Cause nack := omit)
7355runs on test_CT {
7356 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
7357 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02007358 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02007359 /* FIXME: no VTY command to activate Osmocom PDCH !! */
7360 /* expect the BSC to issue the related RSL command */
7361 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
7362 if (istemplatekind(nack, "omit")) {
7363 /* respond with a related acknowledgement */
7364 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7365 } else {
7366 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
7367 }
7368}
7369
7370private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
7371 template (omit) RSL_Cause nack := omit)
7372runs on test_CT {
7373 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
7374 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02007375 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02007376 /* FIXME: no VTY command to activate Osmocom PDCH !! */
7377 /* expect the BSC to issue the related RSL command */
7378 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
7379 if (istemplatekind(nack, "omit")) {
7380 /* respond with a related acknowledgement */
7381 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
7382 } else {
7383 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
7384 }
7385}
7386
7387/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
7388testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
7389 var RSL_Message rsl_unused;
7390
7391 /* change Timeslot 6 before f_init() starts RSL */
7392 f_init_vty();
7393 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
7394 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7395
7396 f_init(1, false);
7397 f_sleep(1.0);
7398
7399 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
7400
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007401 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007402 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7403 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007404 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Harald Welte94e0c342018-04-07 11:33:23 +02007405
7406 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7407 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007408 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 +02007409 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7410
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007411 /* clean up config */
7412 f_ts_set_chcomb(0, 0, 6, "PDCH");
7413
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007414 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007415}
7416
7417/* Test Osmocom dyn PDCH activation NACK behavior */
7418testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
7419 var RSL_Message rsl_unused;
7420
7421 /* change Timeslot 6 before f_init() starts RSL */
7422 f_init_vty();
7423 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
7424 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7425
7426 f_init(1, false);
7427 f_sleep(1.0);
7428
7429 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
7430
7431 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7432 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007433 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Harald Welte94e0c342018-04-07 11:33:23 +02007434
7435 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
7436 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
7437 f_sleep(1.0);
7438 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7439
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007440 /* clean up config */
7441 f_ts_set_chcomb(0, 0, 6, "PDCH");
7442
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007443 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007444}
7445
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007446/* Test Osmocom dyn TS SDCCH8 activation / deactivation */
7447testcase TC_dyn_ts_sdcch8_act_deact() runs on test_CT {
7448 var RSL_Message rsl_unused, rsl_msg;
7449 var DchanTuple dt;
7450 var BSSAP_N_CONNECT_ind rx_c_ind;
7451
7452 /* change Timeslot 6 before f_init() starts RSL */
7453 f_init_vty();
7454 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
7455 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7456
7457 f_init(1, false);
7458 f_sleep(1.0);
7459
7460 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7461
7462 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7463 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7464 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007465 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007466
7467 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7468 f_sleep(1.0);
7469 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7470 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7471
7472 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7473 * on CCCH+SDCCH4+CBCH) */
7474 var integer i;
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007475 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007476 dt := f_est_dchan('23'O, i, '00010203040506'O);
7477 }
7478
7479 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
7480 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
7481 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7482 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7483
7484 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7485 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7486
7487 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7488 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
7489 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7490 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7491
7492 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
7493 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
7494 dt.sccp_conn_id := rx_c_ind.connectionId;
7495 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
7496
7497 /* Instruct BSC to clear channel */
7498 var BssmapCause cause := 0;
7499 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7500 f_exp_chan_rel_and_clear(dt, 0);
7501
7502 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007503 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007504 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7505 f_sleep(1.0);
7506 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7507
7508 /* clean up config */
7509 f_ts_set_chcomb(0, 0, 6, "PDCH");
7510
7511 f_shutdown_helper();
7512}
7513
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007514/* Validate all 8 subslots of a dynamics TS configured as SDCCH8 are used */
7515testcase TC_dyn_ts_sdcch8_all_subslots_used() runs on test_CT {
7516 var ASP_RSL_Unitdata rsl_ud;
7517 var integer i;
7518 var integer chreq_total, chreq_nochan;
7519
7520 f_init_vty();
7521 for (i := 1; i < 8; i := i + 1) {
7522 if (i == 2) {
7523 f_ts_set_chcomb(0, 0, i, "TCH/F_TCH/H_SDCCH8_PDCH");
7524 } else {
7525 f_ts_set_chcomb(0, 0, i, "PDCH");
7526 }
7527 }
7528 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7529
7530 f_init(1);
7531
7532 /* The dyn TS want to activate PDCH mode, ACK that. */
7533 var RslChannelNr chan_nr;
7534 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007535 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007536 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7537
7538 f_sleep(1.0);
7539
7540 /* Exhaust all dedicated SDCCH lchans.
7541 /* GSM 44.018 Table 9.1.8.2:
7542 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
7543 */
7544 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
7545 f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
7546 }
7547
7548 /* Only the dyn TS is still available. Its first lchan gets converted to SDCCH8 */
7549 f_est_dchan_dyn('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
7550 /* Also occupy the seven other SDCCH of the dyn TS */
7551 for (i := 0; i < 7; i := i+1) {
7552 f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
7553 }
7554
7555 /* clean up config */
7556 f_ts_reset_chcomb(0);
7557
7558 f_shutdown_helper();
7559}
7560
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007561/* Test Osmocom dyn TS SDCCH8 activation / deactivation: If activating dyn TS as
7562 SDCCH8 would end up in having no free TCH, then BSC should decide to activate
7563 it as TCH directly instead. SYS#5309. */
7564testcase TC_dyn_ts_sdcch8_tch_call_act_deact() runs on test_CT {
7565 var RSL_Message rsl_unused, rsl_msg;
7566 var DchanTuple dt;
7567 var BSSAP_N_CONNECT_ind rx_c_ind;
7568 var integer i;
7569
7570 /* change Timeslot 6 before f_init() starts RSL */
7571 f_init_vty();
7572 for (i := 1; i < 8; i := i + 1) {
7573 if (i == 6) {
7574 f_ts_set_chcomb(0, 0, i, "TCH/F_TCH/H_SDCCH8_PDCH");
7575 } else {
7576 f_ts_set_chcomb(0, 0, i, "PDCH");
7577 }
7578 }
7579 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7580
7581 f_init(1, false);
7582 f_sleep(1.0);
7583
7584 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7585
7586 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7587 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7588 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007589 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007590
7591 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7592 f_sleep(1.0);
7593 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7594 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7595
7596 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7597 * on CCCH+SDCCH4+CBCH) */
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007598 var OCT1 ra := '43'O; /* RA containing reason=originating speech call*/
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007599 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007600 dt := f_est_dchan(ra, i, '00010203040506'O);
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007601 }
7602
7603 /* Now the dyn ts is selected. First PDCH is released, then TCH chan is activated */
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007604 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int(ra) + i, 1), 2342));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007605 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7606 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7607
7608 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7609 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7610
7611 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
7612 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
7613 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7614 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
7615
7616 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
7617 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
7618 dt.sccp_conn_id := rx_c_ind.connectionId;
7619 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
7620
7621 /* Instruct BSC to clear channel */
7622 var BssmapCause cause := 0;
7623 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7624 f_exp_chan_rel_and_clear(dt, 0);
7625
7626 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007627 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007628 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7629 f_sleep(1.0);
7630 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7631
7632 /* clean up config */
7633 f_ts_reset_chcomb(0);
7634 /* TODO: clean up other channels? */
7635
7636 f_shutdown_helper();
7637}
7638
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007639/* Test Osmocom dyn TS SDCCH8 activation / deactivation when SDCCH fails at BTS */
7640testcase TC_dyn_ts_sdcch8_act_nack() runs on test_CT {
7641 var RSL_Message rsl_unused, rsl_msg;
7642 var DchanTuple dt;
7643 var BSSAP_N_CONNECT_ind rx_c_ind;
7644 var GsmRrMessage rr;
7645
7646 /* change Timeslot 6 before f_init() starts RSL */
7647 f_init_vty();
7648 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
7649 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7650
7651 f_init(1, false);
7652 f_sleep(1.0);
7653
7654 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7655
7656 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7657 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7658 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007659 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007660
7661 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7662 f_sleep(1.0);
7663 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7664 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7665
7666 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7667 * on CCCH+SDCCH4+CBCH) */
7668 var integer i;
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007669 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007670 dt := f_est_dchan('23'O, i, '00010203040506'O);
7671 }
7672
7673 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
7674 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
7675 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7676 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7677
7678 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7679 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7680
7681 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7682 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(dt.rsl_chan_nr, RSL_ERR_EQUIPMENT_FAIL));
7683 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7684 rr := dec_GsmRrMessage(rsl_msg.ies[1].body.full_imm_ass_info.payload);
7685 if (rr.header.message_type != IMMEDIATE_ASSIGNMENT_REJECT) {
7686 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Expected reject");
7687 }
7688
7689 /* FIXME? Currently the TS stays in state BORKEN: */
7690
7691 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007692 /* rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007693 * f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7694 * f_sleep(1.0);
7695 * f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE)
7696 */
7697
7698 /* clean up config */
7699 f_ts_set_chcomb(0, 0, 6, "PDCH");
7700
7701 f_shutdown_helper();
7702}
7703
Stefan Sperling0796a822018-10-05 13:01:39 +02007704testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02007705 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02007706 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
7707 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
7708 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007709 f_shutdown_helper();
Stefan Sperling0796a822018-10-05 13:01:39 +02007710}
7711
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007712testcase TC_chopped_ipa_payload() runs on test_CT {
7713 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
7714 /* TODO: mp_bsc_ctrl_port does not work yet */};
7715 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
7716 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
7717 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007718 f_shutdown_helper();
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007719}
7720
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01007721/* Verify the BSC sends the MS Power Parameters IE during CHAN ACT to make sure
7722 the BTS does autonomous MS power control loop */
7723testcase TC_assignment_verify_ms_power_params_ie() runs on test_CT {
7724 var MSC_ConnHdlr vc_conn;
7725 var TestHdlrParams pars := f_gen_test_hdlr_pars();
7726 //pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
7727 pars.exp_ms_power_params := true;
7728
7729 f_init(1, true);
7730 f_sleep(1.0);
7731 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
7732 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007733 f_shutdown_helper();
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01007734}
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007735
Vadim Yanitskiy4b233042021-06-30 00:58:43 +02007736/* Verify activation and deactivation of the BCCH carrier power reduction mode */
7737testcase TC_c0_power_red_mode() runs on test_CT {
7738 f_init(1);
7739
7740 for (var integer red := 6; red >= 0; red := red - 2) {
7741 /* Configure BCCH carrier power reduction mode via the VTY */
7742 f_vty_transceive(BSCVTY, "bts 0 c0-power-reduction " & int2str(red));
7743
7744 /* Expect Osmocom specific BS Power Control message on the RSL */
7745 var template RSL_Message tr_rsl_pdu := tr_RSL_BS_PWR_CTRL(
7746 chan_nr := t_RslChanNr_BCCH(0),
7747 bs_power := tr_RSL_IE_BS_Power(red / 2));
7748 tr_rsl_pdu.msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false);
7749 var RSL_Message unused := f_exp_ipa_rx(0, tr_rsl_pdu);
7750
7751 /* Additionally verify the applied value over the CTRL interface */
7752 var CtrlValue cred := f_ctrl_get_bts(IPA_CTRL, 0, "c0-power-reduction");
7753 if (cred != int2str(red)) {
7754 setverdict(fail, "Unexpected BCCH carrier power reduction value ",
7755 cred, " (expected ", red, ")");
7756 }
7757 }
7758
7759 f_shutdown_helper();
7760}
7761
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007762/***********************************************************************
7763 * MSC Pooling
7764 ***********************************************************************/
7765
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007766template MobileIdentityLV ts_MI_TMSI_NRI_LV(integer nri_v, integer nri_bitlen := 10) :=
Harald Weltebf397612021-01-14 20:39:46 +01007767 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 +02007768
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007769private 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 +02007770runs on MSC_ConnHdlr {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007771 interleave {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007772 [] rsl_pt.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007773 f_logp(BSCVTY, "Got RSL RR Release");
7774 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007775 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007776 f_logp(BSCVTY, "Got RSL Deact SACCH");
7777 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02007778 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007779 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007780 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
7781 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007782 break;
7783 }
7784 }
7785}
7786
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007787friend function f_perform_clear(RSL_DCHAN_PT rsl_pt := RSL, RSLEM_PROC_PT rsl_proc_pt := RSL_PROC,
7788 template PDU_ML3_NW_MS exp_rr_rel_tmpl := tr_RRM_RR_RELEASE)
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02007789runs on MSC_ConnHdlr {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007790 f_logp(BSCVTY, "MSC instructs BSC to clear channel");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007791 BSSAP.send(ts_BSSMAP_ClearCommand(0));
7792 interleave {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007793 [] rsl_pt.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007794 f_logp(BSCVTY, "Got RSL RR Release");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007795 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007796 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007797 f_logp(BSCVTY, "Got RSL Deact SACCH");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007798 }
7799 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007800 f_logp(BSCVTY, "Got BSSMAP Clear Complete");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007801 /* Also drop the SCCP connection */
7802 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
7803 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02007804 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007805 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007806 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
7807 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007808 }
7809 }
7810}
7811
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007812private function f_perform_compl_l3(RSL_DCHAN_PT rsl_pt, RSLEM_PROC_PT rsl_proc_pt,
7813 template PDU_ML3_MS_NW l3_info, boolean do_clear := true, boolean expect_bssmap_l3 := true)
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007814runs on MSC_ConnHdlr {
7815 timer T := 10.0;
7816 var octetstring l3_enc := enc_PDU_ML3_MS_NW(valueof(l3_info));
7817
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007818 f_logp(BSCVTY, "establish channel, send Complete Layer 3 Info");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007819 f_create_bssmap_exp(l3_enc);
7820
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007821 /* RSL_Emulation.f_chan_est() on rsl_pt:
7822 * This is basically code dup with s/RSL/rsl_pt from:
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007823 * RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
7824 */
7825 var RSL_Message rx_rsl;
7826 var GsmRrMessage rr;
7827
7828 /* request a channel to be established */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007829 rsl_pt.send(ts_RSLDC_ChanRqd(g_pars.ra, g_pars.fn));
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007830 /* expect immediate assignment.
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007831 * Code dup with s/RSL/rsl_pt from:
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007832 * rx_rsl := f_rx_or_fail(tr_RSL_IMM_ASSIGN);
7833 */
7834 timer Tt := 10.0;
7835
7836 /* request a channel to be established */
7837 Tt.start;
7838 alt {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007839 [] rsl_pt.receive(tr_RSL_IMM_ASSIGN) -> value rx_rsl {
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007840 Tt.stop;
7841 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007842 [] rsl_pt.receive {
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007843 setverdict(fail, "Unexpected RSL message on DCHAN");
7844 mtc.stop;
7845 }
7846 [] Tt.timeout {
7847 setverdict(fail, "Timeout waiting for RSL on DCHAN");
7848 mtc.stop;
7849 }
7850 }
7851 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
7852 g_chan_nr := rr.payload.imm_ass.chan_desc.chan_nr;
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007853 rsl_pt.send(ts_RSL_EST_IND(g_chan_nr, valueof(g_pars.link_id), l3_enc));
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007854
7855
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007856 if (expect_bssmap_l3) {
7857 f_logp(BSCVTY, "expect BSSAP Complete Layer 3 Info at MSC");
7858 var template PDU_BSSAP exp_l3_compl;
7859 exp_l3_compl := tr_BSSMAP_ComplL3()
7860 if (g_pars.aoip == false) {
7861 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := omit;
7862 } else {
7863 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := ?;
7864 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007865
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007866 var PDU_BSSAP bssap;
7867 T.start;
7868 alt {
7869 [] BSSAP.receive(exp_l3_compl) -> value bssap {
7870 f_logp(BSCVTY, "received expected Complete Layer 3 Info at MSC");
7871 log("rx exp_l3_compl = ", bssap);
7872 }
7873 [] BSSAP.receive(tr_BSSMAP_ComplL3) {
7874 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching COMPLETE LAYER 3 INFORMATION");
7875 }
7876 [] T.timeout {
7877 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
7878 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007879 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007880
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007881 /* start ciphering, if requested */
7882 if (ispresent(g_pars.encr)) {
7883 f_logp(BSCVTY, "start ciphering");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007884 f_cipher_mode(g_pars.encr, rsl_pt := rsl_pt, rsl_proc_pt := rsl_proc_pt);
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007885 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007886 }
7887
7888 if (do_clear) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007889 f_perform_clear(rsl_pt, rsl_proc_pt);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007890 }
7891 setverdict(pass);
7892 f_sleep(1.0);
7893}
7894
7895private function f_tc_mscpool_compl_l3(charstring id) runs on MSC_ConnHdlr {
7896 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
7897 if (g_pars.mscpool.rsl_idx == 0) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007898 f_perform_compl_l3(RSL, RSL_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007899 } else if (g_pars.mscpool.rsl_idx == 1) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007900 f_perform_compl_l3(RSL1, RSL1_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007901 } else if (g_pars.mscpool.rsl_idx == 2) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007902 f_perform_compl_l3(RSL2, RSL2_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007903 }
7904}
7905
7906/* Various Complete Layer 3 by IMSI all end up with the first MSC, because the other MSCs are not connected. */
7907private function f_tc_mscpool_L3Compl_on_1_msc(charstring id) runs on MSC_ConnHdlr {
7908 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007909 f_perform_compl_l3(RSL, RSL_PROC, ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O) );
7910 f_perform_compl_l3(RSL, RSL_PROC, ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_IMSI_LV('001010000000002'H))) );
7911 f_perform_compl_l3(RSL, RSL_PROC, ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))) );
7912 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 +02007913}
7914testcase TC_mscpool_L3Compl_on_1_msc() runs on test_CT {
7915
7916 f_init(1, true);
7917 f_sleep(1.0);
7918 var MSC_ConnHdlr vc_conn;
7919 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007920
7921 f_ctrs_msc_init();
7922
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007923 vc_conn := f_start_handler(refers(f_tc_mscpool_L3Compl_on_1_msc), pars);
7924 vc_conn.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007925
7926 f_ctrs_msc_expect(0, "mscpool:subscr:new", 4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007927 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007928}
7929
7930/* Three Layer 3 Complete by IMSI are round-robin'ed across two connected MSCs */
7931/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7932 * just as well using only RSL. */
7933testcase TC_mscpool_L3Complete_by_imsi_round_robin() runs on test_CT {
7934
7935 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7936 f_sleep(1.0);
7937
7938 /* Control which MSC gets chosen next by the round-robin, otherwise
7939 * would be randomly affected by which other tests ran before this. */
7940 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7941
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007942 f_ctrs_msc_init();
7943
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007944 var MSC_ConnHdlr vc_conn1;
7945 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7946 pars1.mscpool.rsl_idx := 0;
7947 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
7948 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7949 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007950 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007951
7952 var MSC_ConnHdlr vc_conn2;
7953 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7954 pars2.mscpool.rsl_idx := 1;
7955 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
7956 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7957 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007958 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007959
7960 /* Test round-robin wrap to the first MSC */
7961 var MSC_ConnHdlr vc_conn3;
7962 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
7963 pars3.mscpool.rsl_idx := 2;
7964 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
7965 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7966 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007967 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007968 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007969}
7970
7971/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 0
7972 * (configured in osmo-bsc.cfg). */
7973/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7974 * just as well using only RSL. */
7975testcase TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() runs on test_CT {
7976
7977 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7978 f_sleep(1.0);
7979
7980 /* Control which MSC gets chosen next by the round-robin, otherwise
7981 * would be randomly affected by which other tests ran before this. */
7982 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7983
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007984 f_ctrs_msc_init();
7985
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007986 var MSC_ConnHdlr vc_conn1;
7987 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7988 pars1.mscpool.rsl_idx := 0;
7989 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
7990 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7991 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007992 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007993
7994 var MSC_ConnHdlr vc_conn2;
7995 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7996 pars2.mscpool.rsl_idx := 1;
7997 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
7998 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7999 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008000 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008001
8002 /* Test round-robin wrap to the first MSC */
8003 var MSC_ConnHdlr vc_conn3;
8004 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8005 pars3.mscpool.rsl_idx := 2;
8006 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
8007 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8008 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008009 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008010 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008011}
8012
8013/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 1
8014 * (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
8015 * NULL-NRI setting is stronger than that. */
8016/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8017 * just as well using only RSL. */
8018testcase TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() runs on test_CT {
8019
8020 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8021 f_sleep(1.0);
8022
8023 /* Control which MSC gets chosen next by the round-robin, otherwise
8024 * would be randomly affected by which other tests ran before this. */
8025 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8026
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008027 f_ctrs_msc_init();
8028
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008029 var MSC_ConnHdlr vc_conn1;
8030 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8031 pars1.mscpool.rsl_idx := 0;
8032 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8033 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8034 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008035 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008036
8037 var MSC_ConnHdlr vc_conn2;
8038 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8039 pars2.mscpool.rsl_idx := 1;
8040 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8041 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8042 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008043 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008044
8045 /* Test round-robin wrap to the first MSC */
8046 var MSC_ConnHdlr vc_conn3;
8047 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8048 pars3.mscpool.rsl_idx := 2;
8049 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8050 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8051 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008052 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008053 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008054}
8055
8056/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI not
8057 * assigned to any MSC (configured in osmo-bsc.cfg). */
8058/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8059 * just as well using only RSL. */
8060testcase TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() runs on test_CT {
8061
8062 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8063 f_sleep(1.0);
8064
8065 /* Control which MSC gets chosen next by the round-robin, otherwise
8066 * would be randomly affected by which other tests ran before this. */
8067 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8068
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008069 f_ctrs_msc_init();
8070
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008071 var MSC_ConnHdlr vc_conn1;
8072 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8073 pars1.mscpool.rsl_idx := 0;
8074 /* An NRI that is not assigned to any MSC */
8075 pars1.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(1023))));
8076 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8077 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008078 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008079
8080 var MSC_ConnHdlr vc_conn2;
8081 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8082 pars2.mscpool.rsl_idx := 1;
8083 /* An NRI that is not assigned to any MSC */
8084 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(768)), '00F110'O));
8085 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8086 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008087 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008088
8089 /* Test round-robin wrap to the first MSC */
8090 var MSC_ConnHdlr vc_conn3;
8091 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8092 pars3.mscpool.rsl_idx := 2;
8093 /* An NRI that is not assigned to any MSC */
8094 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, valueof(ts_MI_TMSI_NRI_LV(819))));
8095 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8096 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008097 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008098 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008099}
8100
8101/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI
8102 * assigned to an MSC that is currently not connected (configured in osmo-bsc.cfg). */
8103/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8104 * just as well using only RSL. */
8105testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() runs on test_CT {
8106
8107 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8108 f_sleep(1.0);
8109
8110 /* Control which MSC gets chosen next by the round-robin, otherwise
8111 * would be randomly affected by which other tests ran before this. */
8112 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8113
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008114 f_ctrs_msc_init();
8115
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008116 var MSC_ConnHdlr vc_conn1;
8117 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8118 pars1.mscpool.rsl_idx := 0;
8119 /* An NRI that is assigned to an unconnected MSC */
8120 pars1.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(512))));
8121 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8122 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008123 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8124 f_ctrs_msc_add(0, "mscpool:subscr:new");
8125 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008126
8127 var MSC_ConnHdlr vc_conn2;
8128 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8129 pars2.mscpool.rsl_idx := 1;
8130 /* An NRI that is assigned to an unconnected MSC */
8131 pars2.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(767))));
8132 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8133 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008134 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8135 f_ctrs_msc_add(1, "mscpool:subscr:new");
8136 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008137
8138 /* Test round-robin wrap to the first MSC */
8139 var MSC_ConnHdlr vc_conn3;
8140 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8141 pars3.mscpool.rsl_idx := 2;
8142 /* An NRI that is assigned to an unconnected MSC */
8143 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(750)), '00F110'O));
8144 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8145 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008146 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8147 f_ctrs_msc_add(0, "mscpool:subscr:new");
8148 f_ctrs_msc_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008149 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008150}
8151
8152/* Three Layer 3 Complete by TMSI with valid NRI for the second MSC are all directed to the second MSC (configured in
8153 * osmo-bsc.cfg). */
8154/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8155 * just as well using only RSL. */
8156testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_1() runs on test_CT {
8157
8158 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8159 f_sleep(1.0);
8160
8161 /* All TMSIs in this test point at the second MSC, set the round robin to point at the first MSC to make sure
8162 * this is not using round-robin. */
8163 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8164
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008165 f_ctrs_msc_init();
8166
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008167 var MSC_ConnHdlr vc_conn1;
8168 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
8169 pars1.mscpool.rsl_idx := 0;
8170 /* An NRI of the second MSC's range (256-511) */
8171 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(256))));
8172 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8173 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008174 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008175
8176 var MSC_ConnHdlr vc_conn2;
8177 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8178 pars2.mscpool.rsl_idx := 1;
8179 /* An NRI of the second MSC's range (256-511) */
8180 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(260))));
8181 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8182 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008183 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008184
8185 var MSC_ConnHdlr vc_conn3;
8186 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
8187 pars3.mscpool.rsl_idx := 2;
8188 /* An NRI of the second MSC's range (256-511) */
8189 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(511)), '00F110'O));
8190 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8191 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008192 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008193 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008194}
8195
8196/* Layer 3 Complete by TMSI with valid NRI for the third MSC are directed to the third MSC (configured in osmo-bsc.cfg),
8197 * while a round-robin remains unaffected by that. */
8198/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8199 * just as well using only RSL. */
8200testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_2() runs on test_CT {
8201
8202 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8203 f_sleep(1.0);
8204
8205 /* All TMSIs in this test point at the third MSC, set the round robin to point at the second MSC to make sure
8206 * this is not using round-robin. */
8207 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
8208
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008209 f_ctrs_msc_init();
8210
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008211 var MSC_ConnHdlr vc_conn1;
8212 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 2);
8213 pars1.mscpool.rsl_idx := 0;
8214 /* An NRI of the third MSC's range (512-767) */
8215 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(512))));
8216 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8217 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008218 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008219
8220 var MSC_ConnHdlr vc_conn2;
8221 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8222 pars2.mscpool.rsl_idx := 1;
8223 /* An NRI of the third MSC's range (512-767) */
8224 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(678))));
8225 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8226 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008227 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008228
8229 /* The above forwardings to third MSC have not affected the round robin, which still points at the second MSC */
8230 var MSC_ConnHdlr vc_conn3;
8231 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
8232 pars3.mscpool.rsl_idx := 2;
8233 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000013'H)), '00F110'O));
8234 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8235 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008236 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008237 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008238}
8239
8240/* LU with a TMSI but indicating a different PLMN in its previous LAI: ignore the NRI. */
8241/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8242 * just as well using only RSL. */
8243testcase TC_mscpool_LU_by_tmsi_from_other_PLMN() runs on test_CT {
8244
8245 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8246 f_sleep(1.0);
8247
8248 /* The TMSIs in this test points at the second MSC, but since it is from a different PLMN, round-robin is used
8249 * instead, and hits msc 0. */
8250 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8251
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008252 f_ctrs_msc_init();
8253
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008254 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-bsc.cfg */
8255 var MSC_ConnHdlr vc_conn1;
8256 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8257 pars1.mscpool.rsl_idx := 0;
8258 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(260)), '99F999'O));
8259 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8260 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008261 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008262
8263 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
8264 var MSC_ConnHdlr vc_conn2;
8265 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8266 pars2.mscpool.rsl_idx := 1;
8267 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(555)), '00F110'O));
8268 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8269 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008270 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008271 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008272}
8273
8274/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by IMSI, which would be
8275 * round-robined to another MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
8276private function f_tc_mscpool_paging_imsi(charstring id) runs on MSC_ConnHdlr {
8277 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
8278 //cid_list := { cIl_allInBSS := ''O };
8279 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
8280 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
8281 var BSSAP_N_UNITDATA_req paging;
8282 var hexstring imsi := '001010000000123'H;
8283
8284 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8285
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008286 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008287 valueof(ts_BSSMAP_Paging(imsi, cid_list, omit, bssmap_chneed))));
8288 BSSAP.send(paging);
8289
8290 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
8291 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
8292 * channel number is picked here. */
8293 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
8294 f_rslem_register(0, new_chan_nr);
8295 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(imsi)));
8296 f_rslem_unregister(0, new_chan_nr);
8297
8298 /* Despite the round robin pointing at the second MSC ('roundrobin next 1'), the earlier Paging for the same IMSI
8299 * causes this Paging Response to go to the first MSC (bssap_idx := 0). */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008300 f_perform_compl_l3(RSL, RSL_PROC, ts_PAG_RESP(valueof(ts_MI_IMSI_LV(imsi))) );
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008301 f_sleep(1.0);
8302}
8303testcase TC_mscpool_paging_and_response_imsi() runs on test_CT {
8304 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
8305 f_sleep(1.0);
8306
8307 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
8308 * second MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
8309 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
8310
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008311 f_ctrs_msc_init();
8312
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008313 var MSC_ConnHdlr vc_conn1;
8314 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8315 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008316 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
8317 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008318 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_imsi), pars1);
8319 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008320 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008321 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008322}
8323
8324/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by TMSI with an NRI value
8325 * that matches a different MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
8326private function f_tc_mscpool_paging_tmsi(charstring id) runs on MSC_ConnHdlr {
8327 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
8328 //cid_list := { cIl_allInBSS := ''O };
8329 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
8330 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
8331 var integer nri_v := 300; /* <-- second MSC's NRI */
Harald Weltebf397612021-01-14 20:39:46 +01008332 var octetstring tmsi := f_gen_tmsi(suffix := 0, nri_v := nri_v);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008333 var BSSAP_N_UNITDATA_req paging;
8334
8335 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8336
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008337 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008338 valueof(ts_BSSMAP_Paging('001010000000011'H, cid_list, tmsi, bssmap_chneed))));
8339 BSSAP.send(paging);
8340
8341 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
8342 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
8343 * channel number is picked here. */
8344 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
8345 f_rslem_register(0, new_chan_nr);
8346 RSL.receive(tr_RSL_PAGING_CMD(t_MI_TMSI(tmsi)));
8347 f_rslem_unregister(0, new_chan_nr);
8348
8349 /* Despite the NRI matching the second MSC (NRI from 'msc 1' in osmo-bsc.cfg) and round robin pointing at the
8350 * third MSC ('roundrobin next 2'), the earlier Paging for the same TMSI causes this Paging Response to go to
8351 * the first MSC (bssap_idx := 0). */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008352 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 +02008353 f_sleep(1.0);
8354}
8355testcase TC_mscpool_paging_and_response_tmsi() runs on test_CT {
8356 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
8357 f_sleep(1.0);
8358
8359 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
8360 * third MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
8361 f_vty_transceive(BSCVTY, "mscpool roundrobin next 2");
8362
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008363 f_ctrs_msc_init();
8364
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008365 var MSC_ConnHdlr vc_conn1;
8366 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8367 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008368 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
8369 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008370 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_tmsi), pars1);
8371 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008372 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008373 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008374}
8375
8376/* For round-robin, skip an MSC that has 'no allow-attach' set. */
8377/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8378 * just as well using only RSL. */
8379testcase TC_mscpool_no_allow_attach_round_robin() runs on test_CT {
8380
8381 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8382 f_sleep(1.0);
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00008383 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
8384 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008385
8386 /* Control which MSC gets chosen next by the round-robin, otherwise
8387 * would be randomly affected by which other tests ran before this. */
8388 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
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;
8395 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
8396 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8397 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008398 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008399
8400 var MSC_ConnHdlr vc_conn2;
8401 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8402 pars2.mscpool.rsl_idx := 1;
8403 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8404 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8405 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008406 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008407
8408 var MSC_ConnHdlr vc_conn3;
8409 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8410 pars3.mscpool.rsl_idx := 2;
8411 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
8412 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8413 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008414 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008415 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008416}
8417
8418/* An MSC that has 'no allow-attach' set should still serve subscribers that are already attached according to their
8419 * TMSI NRI. */
8420testcase TC_mscpool_no_allow_attach_valid_nri() runs on test_CT {
8421
8422 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8423 f_sleep(1.0);
8424
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00008425 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
8426 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
8427
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008428 /* Control which MSC gets chosen next by the round-robin, otherwise
8429 * would be randomly affected by which other tests ran before this. */
8430 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8431
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008432 f_ctrs_msc_init();
8433
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008434 /* Round robin points at msc 0, but the valid NRI directs to msc 1, even though msc 1 has 'no allow-attach'. */
8435 var MSC_ConnHdlr vc_conn1;
8436 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
8437 pars1.mscpool.rsl_idx := 0;
8438 /* An NRI of the second MSC's range (256-511) */
8439 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_TMSI_NRI_LV(260))));
8440 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8441 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008442 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008443
8444 var MSC_ConnHdlr vc_conn2;
8445 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 0);
8446 pars2.mscpool.rsl_idx := 1;
8447 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8448 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8449 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008450 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008451
8452 var MSC_ConnHdlr vc_conn3;
8453 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 2);
8454 pars3.mscpool.rsl_idx := 2;
8455 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000003'H))));
8456 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8457 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008458 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008459 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008460}
8461
Philipp Maier783681c2020-07-16 16:47:06 +02008462/* Allow/Deny emergency calls globally via VTY */
8463private function f_vty_allow_emerg_msc(boolean allow) runs on test_CT {
8464 f_vty_enter_cfg_msc(BSCVTY, 0);
8465 if (allow) {
8466 f_vty_transceive(BSCVTY, "allow-emergency allow");
8467 } else {
8468 f_vty_transceive(BSCVTY, "allow-emergency deny");
8469 }
8470 f_vty_transceive(BSCVTY, "exit");
8471 f_vty_transceive(BSCVTY, "exit");
8472}
8473
8474/* Allow/Deny emergency calls per BTS via VTY */
8475private function f_vty_allow_emerg_bts(boolean allow, integer bts_nr) runs on test_CT {
8476 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8477 if (allow) {
8478 f_vty_transceive(BSCVTY, "rach emergency call allowed 1");
8479 } else {
8480 f_vty_transceive(BSCVTY, "rach emergency call allowed 0");
8481 }
8482 f_vty_transceive(BSCVTY, "exit");
8483 f_vty_transceive(BSCVTY, "exit");
Neels Hofmeyrb6ed80c2020-10-12 22:52:39 +00008484 f_vty_transceive(BSCVTY, "exit");
Philipp Maier783681c2020-07-16 16:47:06 +02008485}
8486
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02008487/* Allow/Forbid Fast Return after SRVCC on a given BTS via VTY */
8488private function f_vty_allow_srvcc_fast_return(boolean allow, integer bts_nr) runs on test_CT {
8489 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8490 if (allow) {
8491 f_vty_transceive(BSCVTY, "srvcc fast-return allow");
8492 } else {
8493 f_vty_transceive(BSCVTY, "srvcc fast-return forbid");
8494 }
8495 f_vty_transceive(BSCVTY, "exit");
8496 f_vty_transceive(BSCVTY, "exit");
8497 f_vty_transceive(BSCVTY, "exit");
8498}
8499
Pau Espin Pedrol14475352021-07-22 15:48:16 +02008500/* Allow/Forbid TCH for signalling if SDCCH exhausted on a given BTS via VTY */
8501private function f_vty_allow_tch_for_signalling(boolean allow, integer bts_nr) runs on test_CT {
8502 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8503 if (allow) {
8504 f_vty_transceive(BSCVTY, "channel allocator allow-tch-for-signalling 1");
8505 } else {
8506 f_vty_transceive(BSCVTY, "channel allocator allow-tch-for-signalling 0");
8507 }
8508 f_vty_transceive(BSCVTY, "exit");
8509 f_vty_transceive(BSCVTY, "exit");
8510 f_vty_transceive(BSCVTY, "exit");
8511}
8512
Philipp Maier783681c2020-07-16 16:47:06 +02008513/* Begin assignmet procedure and send an EMERGENCY SETUP (RR) */
8514private function f_assignment_emerg_setup() runs on MSC_ConnHdlr {
8515 var PDU_ML3_MS_NW emerg_setup;
8516 var octetstring emerg_setup_enc;
8517 var RSL_Message emerg_setup_data_ind;
8518
8519 f_establish_fully(omit, omit);
8520
8521 emerg_setup := valueof(ts_ML3_MO_CC_EMERG_SETUP(1, valueof(ts_Bcap_voice)));
8522 emerg_setup_enc := enc_PDU_ML3_MS_NW(emerg_setup);
8523 emerg_setup_data_ind := valueof(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), emerg_setup_enc));
8524
8525 RSL.send(emerg_setup_data_ind);
8526}
8527
8528/* Test if the EMERGENCY SETUP gets passed on to the MSC via A when EMERGENCY
8529 * CALLS are permitted by the BSC config. */
8530private function f_TC_assignment_emerg_setup_allow(charstring id) runs on MSC_ConnHdlr {
8531 var PDU_BSSAP emerg_setup_data_ind_bssap;
8532 var PDU_ML3_MS_NW emerg_setup;
8533 timer T := 3.0;
8534
8535 f_assignment_emerg_setup()
8536
8537 T.start;
8538 alt {
8539 [] BSSAP.receive(tr_BSSAP_DTAP) -> value emerg_setup_data_ind_bssap {
8540 emerg_setup := dec_PDU_ML3_MS_NW(emerg_setup_data_ind_bssap.pdu.dtap);
8541 if (not isbound(emerg_setup.msgs.cc.emergencySetup)) {
8542 setverdict(fail, "no emergency setup");
8543 }
8544 }
8545 [] BSSAP.receive {
8546 setverdict(fail, "unexpected BSSAP message!");
8547 }
8548 [] T.timeout {
8549 setverdict(fail, "timout waiting for EMERGENCY SETUP!");
8550 }
8551 }
8552
8553 setverdict(pass);
8554}
8555
8556/* Test if the EMERGENCY SETUP gets blocked by the BSC if EMERGENCY CALLS are
8557 * forbidden by the BSC config. */
8558private function f_TC_assignment_emerg_setup_deny(charstring id) runs on MSC_ConnHdlr {
8559 var PDU_BSSAP emerg_setup_data_ind_bssap;
8560 timer T := 3.0;
8561
8562 f_assignment_emerg_setup()
8563
8564 T.start;
8565 alt {
8566 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
8567 setverdict(pass);
8568 }
8569 [] RSL.receive {
8570 setverdict(fail, "unexpected RSL message!");
8571 }
8572 [] T.timeout {
8573 setverdict(fail, "timout waiting for RR CHANNEL RELEASE!");
8574 }
8575 }
8576}
8577
8578/* EMERGENCY CALL situation #1, allowed globally and by BTS */
8579testcase TC_assignment_emerg_setup_allow() runs on test_CT {
8580 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8581 var MSC_ConnHdlr vc_conn;
8582
8583 f_init(1, true);
8584 f_sleep(1.0);
8585
8586 f_vty_allow_emerg_msc(true);
8587 f_vty_allow_emerg_bts(true, 0);
8588 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_allow), pars);
8589 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008590 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008591}
8592
8593/* EMERGENCY CALL situation #2, forbidden globally but allowed by BTS */
8594testcase TC_assignment_emerg_setup_deny_msc() runs on test_CT {
8595 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8596 var MSC_ConnHdlr vc_conn;
8597
8598 f_init(1, true);
8599 f_sleep(1.0);
8600
8601 f_vty_allow_emerg_msc(false);
8602 f_vty_allow_emerg_bts(true, 0);
8603 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
8604 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008605 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008606}
8607
8608/* EMERGENCY CALL situation #3, allowed globally but forbidden by BTS */
8609testcase TC_assignment_emerg_setup_deny_bts() runs on test_CT {
8610 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8611 var MSC_ConnHdlr vc_conn;
8612
8613 /* Note: This simulates a spec violation by the MS, correct MS
8614 * implementations would not try to establish an emergency call because
8615 * the system information tells in advance that emergency calls are
8616 * not forbidden */
8617
8618 f_init(1, true);
8619 f_sleep(1.0);
8620
8621 f_vty_allow_emerg_msc(true);
8622 f_vty_allow_emerg_bts(false, 0);
8623 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
8624 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008625 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008626}
8627
Philipp Maier82812002020-08-13 18:48:27 +02008628/* Test what happens when an emergency call arrives while all TCH channels are
8629 * busy, the BSC is expected to terminate one call in favor of the incoming
8630 * emergency call */
8631testcase TC_emerg_premption() runs on test_CT {
8632 var ASP_RSL_Unitdata rsl_ud;
8633 var integer i;
8634 var integer chreq_total, chreq_nochan;
8635 var RSL_Message rx_rsl;
8636 var RslChannelNr chan_nr;
8637
8638 f_init(1);
8639 f_sleep(1.0);
8640
8641 f_vty_allow_emerg_msc(true);
8642 f_vty_allow_emerg_bts(true, 0);
8643
8644 /* Fill up all channels on the BTS */
8645 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
8646 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
8647 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS; i := i+1) {
8648 chan_nr := f_chreq_act_ack('33'O, i);
8649 }
8650 IPA_RSL[0].clear;
8651 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
8652 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
8653
8654 /* Send Channel request for emegergency call */
8655 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
8656
8657 /* Expect the BSC to release one (the first) TCH/F on the BTS */
8658 chan_nr := valueof(t_RslChanNr_Bm(1));
8659 f_expect_chan_rel(0, chan_nr, expect_rr_chan_rel := false, expect_rll_rel_req := false);
8660
8661 /* Expect the BSC to send activate/assign the a channel for the emergency call */
8662 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8663 chan_nr := rx_rsl.ies[0].body.chan_nr;
8664 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 33));
8665 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Philipp Maier104f4c02020-09-11 18:12:18 +02008666
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008667 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008668}
8669
8670/* Hopping parameters per a timeslot */
Vadim Yanitskiybc6654a2020-09-13 01:27:40 +07008671private type record length(0..64) of GsmArfcn ArfcnList;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008672private type record FHParamsTs {
8673 boolean enabled,
8674 uint6_t hsn,
8675 uint6_t maio,
8676 ArfcnList ma
8677};
8678
8679/* Hopping parameters per a transceiver */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008680private type record FHParamsTrx {
Philipp Maier798d8952021-10-19 14:43:19 +02008681 GsmBandArfcn arfcn,
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008682 FHParamsTs ts[8]
8683};
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008684
8685/* Randomly generate the hopping parameters for the given timeslot numbers */
8686private function f_TC_fh_params_gen(template integer tr_tn := (1, 3, 5))
8687runs on test_CT return FHParamsTrx {
8688 var FHParamsTrx fhp;
8689
Philipp Maier798d8952021-10-19 14:43:19 +02008690 /* Generate a random ARFCN in the range of 0 - 3. This ARFCN will
8691 * fall in the GSM900 band. */
8692 fhp.arfcn.arfcn := f_rnd_int(3);
8693 fhp.arfcn.pcs := false;
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008694
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008695 for (var integer tn := 0; tn < 8; tn := tn + 1) {
8696 if (not match(tn, tr_tn)) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008697 fhp.ts[tn].enabled := false;
8698 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008699 continue;
8700 }
8701
8702 /* Random HSN / MAIO values: 0..63 */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008703 fhp.ts[tn].hsn := f_rnd_int(64);
8704 fhp.ts[tn].maio := f_rnd_int(64);
8705 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008706
8707 /* Random Mobile Allocation (hopping channels) */
8708 var integer ma_len := 2 + f_rnd_int(9); /* 2..10 channels */
8709 var integer step := 3 + f_rnd_int(4); /* 3..6 stepping */
8710 for (var integer i := 1; i <= ma_len; i := i + 1) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008711 fhp.ts[tn].ma := fhp.ts[tn].ma & { i * step };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008712 }
8713
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008714 fhp.ts[tn].enabled := true;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008715 }
8716
8717 log("f_TC_fh_params_gen(): ", fhp);
8718 return fhp;
8719}
8720
8721/* Make sure that the given Channel Description IE matches the hopping configuration */
8722private function f_TC_fh_params_match_chan_desc(in FHParamsTrx fhp, in ChannelDescription cd)
8723{
8724 var template (present) ChannelDescription tr_cd;
8725 var template (present) MaioHsn tr_maio_hsn;
8726 var uint3_t tn := cd.chan_nr.tn;
8727
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008728 if (fhp.ts[tn].enabled) {
8729 tr_maio_hsn := tr_HsnMaio(fhp.ts[tn].hsn, fhp.ts[tn].maio);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008730 tr_cd := tr_ChanDescH1(cd.chan_nr, tr_maio_hsn);
8731 } else {
Philipp Maier798d8952021-10-19 14:43:19 +02008732 tr_cd := tr_ChanDescH0(cd.chan_nr, fhp.arfcn.arfcn);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008733 }
8734
8735 if (not match(cd, tr_cd)) {
8736 setverdict(fail, "Channel Description IE does not match: ",
8737 cd, " vs expected ", tr_cd);
8738 }
8739}
8740
8741/* Make sure that the given Mobile Allocation IE matches the hopping configuration */
8742private function f_TC_fh_params_match_ma(in FHParamsTrx fhp, uint3_t tn,
8743 in MobileAllocationLV ma)
8744{
8745 var template MobileAllocationLV tr_ma := f_TC_fh_params_gen_tr_ma(fhp, tn, ma);
8746
8747 if (not match(ma, tr_ma)) {
8748 setverdict(fail, "Mobile Allocation IE does not match (tn := ",
8749 tn, "): ", ma, " vs expected: ", tr_ma);
8750 } else {
8751 setverdict(pass);
8752 }
8753}
8754
8755private function f_TC_fh_params_gen_tr_ma(in FHParamsTrx fhp, uint3_t tn,
8756 in MobileAllocationLV ma)
8757return template MobileAllocationLV {
8758 /* Mobile Allocation IE is expected to be empty if hopping is not enabled */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008759 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008760 return { len := 0, ma := ''B };
8761 }
8762
8763 var bitstring full_mask := f_pad_bit(''B, 1024, '0'B);
8764 var bitstring slot_mask := f_pad_bit(''B, 1024, '0'B);
8765 var bitstring ma_mask := ''B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008766
8767 /* Compose the full bit-mask (all channels, up to 1024 entries) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008768 for (var integer i := 0; i < lengthof(fhp.ts); i := i + 1) {
8769 for (var integer j := 0; j < lengthof(fhp.ts[i].ma); j := j + 1) {
8770 if (full_mask[fhp.ts[i].ma[j]] == '1'B)
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008771 { continue; }
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008772 full_mask[fhp.ts[i].ma[j]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008773 }
8774 }
8775
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008776 /* Take ARFCN of the TRX itself into account */
Philipp Maier798d8952021-10-19 14:43:19 +02008777 full_mask[fhp.arfcn.arfcn] := '1'B;
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008778
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008779 /* Compose a bit-mask for the given timeslot number */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008780 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
8781 slot_mask[fhp.ts[tn].ma[i]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008782 }
8783
8784 /* Finally, compose the Mobile Allocation bit-mask */
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07008785 for (var integer i := 1; i < lengthof(full_mask); i := i + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008786 if (full_mask[i] != '1'B)
8787 { continue; }
8788
8789 /* FIXME: ma_mask := ma_mask & slot_mask[i]; // triggers a bug in TITAN */
8790 if (slot_mask[i] == '1'B) {
8791 ma_mask := ma_mask & '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008792 } else {
8793 ma_mask := ma_mask & '0'B;
8794 }
8795 }
8796
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07008797 /* ARFCN 0 (if present) goes to the last position of the bit-mask */
8798 if (full_mask[0] == '1'B) {
8799 /* FIXME: ma_mask := ma_mask & slot_mask[0]; // triggers a bug in TITAN */
8800 if (slot_mask[0] == '1'B) {
8801 ma_mask := ma_mask & '1'B;
8802 } else {
8803 ma_mask := ma_mask & '0'B;
8804 }
8805 }
8806
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008807 /* Ensure that ma_mask is octet-aligned */
Vadim Yanitskiy2aa02522020-09-06 14:05:23 +07008808 var integer ma_mask_len := (lengthof(ma_mask) + 8 - 1) / 8;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008809 ma_mask := f_pad_bit(ma_mask, ma_mask_len * 8, '0'B);
8810
8811 return { len := ma_mask_len, ma := ma_mask };
8812}
8813
Philipp Maier798d8952021-10-19 14:43:19 +02008814/* Configure the appropriate band for a given arfcn, exc */
8815private function f_TC_set_band_by_arfcn(integer bts_nr, GsmBandArfcn arfcn) runs on test_CT
8816{
8817 var charstring band;
8818 var GsmBandArfcn arfcn_ := valueof(ts_GsmBandArfcn(arfcn.arfcn, arfcn.pcs, false));
8819
8820 select (arfcn_) {
8821 case (tr_GsmBandArfcn((259..293), false, ?)) { band := "GSM450"; }
8822 case (tr_GsmBandArfcn((306..340), false, ?)) { band := "GSM480"; }
8823 case (tr_GsmBandArfcn((438..511), false, ?)) { band := "GSM750"; }
8824 case (tr_GsmBandArfcn((128..251), false, ?)) { band := "GSM850"; }
8825 case (tr_GsmBandArfcn((0..124), false, ?)) { band := "GSM900"; }
8826 case (tr_GsmBandArfcn((955..1023), false, ?)) { band := "GSM900"; }
8827 case (tr_GsmBandArfcn((512..885), false, ?)) { band := "DCS1800"; }
8828 case (tr_GsmBandArfcn((512..810), true, ?)) { band := "PCS1900"; }
8829 case else { return; }
8830 }
8831
8832 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8833 f_vty_transceive(BSCVTY, "band " & band);
8834 f_vty_transceive(BSCVTY, "end");
8835}
8836
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008837/* Configure the hopping parameters in accordance with the given record */
8838private function f_TC_fh_params_set(in FHParamsTrx fhp,
8839 uint8_t bts_nr := 0,
8840 uint8_t trx_nr := 0)
8841runs on test_CT {
Philipp Maier798d8952021-10-19 14:43:19 +02008842
8843 f_TC_set_band_by_arfcn(bts_nr, fhp.arfcn);
8844
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008845 /* Enter the configuration node for the given BTS/TRX numbers */
8846 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
8847
Philipp Maier798d8952021-10-19 14:43:19 +02008848 f_vty_transceive(BSCVTY, "arfcn " & int2str(fhp.arfcn.arfcn));
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008849
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008850 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008851 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
8852
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008853 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008854 f_vty_transceive(BSCVTY, "hopping enabled 0");
8855 f_vty_transceive(BSCVTY, "exit"); /* go back */
8856 continue;
8857 }
8858
8859 /* Configure HSN / MAIO values */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008860 f_vty_transceive(BSCVTY, "hopping sequence-number " & int2str(fhp.ts[tn].hsn));
8861 f_vty_transceive(BSCVTY, "hopping maio " & int2str(fhp.ts[tn].maio));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008862
8863 /* Configure the Mobile Allocation (hopping channels) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008864 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
8865 f_vty_transceive(BSCVTY, "hopping arfcn add " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008866 }
8867
8868 f_vty_transceive(BSCVTY, "hopping enabled 1");
8869 f_vty_transceive(BSCVTY, "exit"); /* go back */
8870 }
8871
8872 f_vty_transceive(BSCVTY, "end");
8873}
8874
8875/* Disable frequency hopping on all timeslots */
8876private function f_TC_fh_params_unset(in FHParamsTrx fhp,
8877 uint8_t bts_nr := 0,
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008878 uint8_t trx_nr := 0,
Philipp Maier798d8952021-10-19 14:43:19 +02008879 GsmBandArfcn arfcn := {pcs := false, arfcn := 871})
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008880runs on test_CT {
Philipp Maier798d8952021-10-19 14:43:19 +02008881
8882 f_TC_set_band_by_arfcn(bts_nr, arfcn);
8883
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008884 /* Enter the configuration node for the given BTS/TRX numbers */
8885 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
8886
Philipp Maier798d8952021-10-19 14:43:19 +02008887 f_vty_transceive(BSCVTY, "arfcn " & int2str(arfcn.arfcn));
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008888
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008889 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008890 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
8891
8892 /* Delete all ARFCNs from the Mobile Allocation (if any) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008893 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
8894 f_vty_transceive(BSCVTY, "hopping arfcn del " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008895 }
8896
8897 f_vty_transceive(BSCVTY, "hopping enabled 0");
8898 f_vty_transceive(BSCVTY, "exit"); /* go back */
8899 }
8900
8901 f_vty_transceive(BSCVTY, "end");
8902 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8903}
8904
8905/* Verify presence and correctness of the hopping parameters (HSN, MAIO)
8906 * in the Channel Identification IE of the RSL CHANnel ACTIVation message. */
8907testcase TC_fh_params_chan_activ() runs on test_CT {
8908 var FHParamsTrx fhp := f_TC_fh_params_gen();
8909 var RSL_Message rsl_msg;
8910 var RSL_IE_Body ie;
8911
8912 f_init_vty();
8913
8914 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
8915 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8916
8917 f_init(1);
8918
8919 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
8920 for (var integer i := 0; i < 9; i := i + 1) {
8921 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
8922 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8923
8924 /* Make sure that Channel Identification IE is present */
8925 if (not f_rsl_find_ie(rsl_msg, RSL_IE_CHAN_IDENT, ie)) {
8926 setverdict(fail, "RSL Channel Identification IE is absent");
8927 continue;
8928 }
8929
8930 /* Make sure that hopping parameters (HSN/MAIO) match */
8931 f_TC_fh_params_match_chan_desc(fhp, ie.chan_ident.ch_desc.v);
8932
8933 /* "Mobile Allocation shall be included but empty" - let's check this */
8934 if (ie.chan_ident.ma.v.len != 0) {
8935 setverdict(fail, "Mobile Allocation IE is not empty: ",
8936 ie.chan_ident.ma, ", despite it shall be");
8937 continue;
8938 }
8939 }
8940
8941 /* Disable frequency hopping */
8942 f_TC_fh_params_unset(fhp);
8943
Vadim Yanitskiy21726312020-09-04 01:45:36 +07008944 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008945}
8946
8947/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Immediate Assignment */
8948testcase TC_fh_params_imm_ass() runs on test_CT {
8949 var FHParamsTrx fhp := f_TC_fh_params_gen();
8950 var RSL_Message rsl_msg;
8951 var RSL_IE_Body ie;
8952
8953 f_init_vty();
8954
8955 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
8956 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8957
8958 f_init(1);
8959
8960 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
8961 for (var integer i := 0; i < 9; i := i + 1) {
8962 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
8963 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8964
8965 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
8966 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
8967
8968 /* Make sure that Full Immediate Assign Info IE is present */
8969 if (not f_rsl_find_ie(rsl_msg, RSL_IE_FULL_IMM_ASS_INFO, ie)) {
8970 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
8971 continue;
8972 }
8973
8974 /* Decode the actual Immediate Assignment message */
8975 var GsmRrMessage rr_msg := dec_GsmRrMessage(ie.full_imm_ass_info.payload);
8976 if (not match(rr_msg.header, t_RrHeader(IMMEDIATE_ASSIGNMENT, ?))) {
8977 setverdict(fail, "Failed to match Immediate Assignment: ", rr_msg);
8978 continue;
8979 }
8980
8981 /* Make sure that hopping parameters (HSN/MAIO) match */
8982 f_TC_fh_params_match_chan_desc(fhp, rr_msg.payload.imm_ass.chan_desc);
8983
8984 /* Make sure that the Mobile Allocation IE matches */
8985 f_TC_fh_params_match_ma(fhp, rr_msg.payload.imm_ass.chan_desc.chan_nr.tn,
8986 rr_msg.payload.imm_ass.mobile_allocation);
8987 }
8988
8989 /* Disable frequency hopping */
8990 f_TC_fh_params_unset(fhp);
Philipp Maier82812002020-08-13 18:48:27 +02008991
Vadim Yanitskiy21726312020-09-04 01:45:36 +07008992 f_shutdown_helper();
Philipp Maier82812002020-08-13 18:48:27 +02008993}
8994
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07008995/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Assignment Command */
8996testcase TC_fh_params_assignment_cmd() runs on test_CT {
8997 var FHParamsTrx fhp := f_TC_fh_params_gen();
8998 var RSL_Message rsl_msg;
8999 var RSL_IE_Body ie;
9000
9001 f_init_vty();
9002
9003 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9004 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9005
9006 f_init(1);
9007
9008 /* HACK: work around "Couldn't find Expect for CRCX" */
9009 vc_MGCP.stop;
9010
9011 var template PDU_BSSAP ass_cmd := f_gen_ass_req();
9012 ass_cmd.pdu.bssmap.assignmentRequest.codecList := ts_BSSMAP_IE_CodecList({ts_CodecFR});
9013
9014 /* CS domain (TCH): 4 (TCH/F) + 2 (TCH/H) channels available
9015 * NOTE: only 3 SDCCH/4 channels are available on CCCH+SDCCH4+CBCH */
9016 for (var integer i := 0; i < 3; i := i + 1) {
9017 /* Establish a dedicated channel, so we can trigger (late) TCH assignment */
9018 var DchanTuple dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
9019
9020 /* Send a BSSMAP Assignment Command, expect CHANnel ACTIVation */
9021 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
9022 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9023
9024 /* ACKnowledge CHANnel ACTIVation, expect RSL DATA REQuest */
9025 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9026 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
9027
9028 /* Make sure that L3 Information IE is present */
9029 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
9030 setverdict(fail, "RSL L3 Information IE is absent");
9031 continue;
9032 }
9033
9034 /* Decode the L3 message and make sure it is (RR) Assignment Command */
9035 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
9036 if (not match(l3_msg.header, t_RrL3Header(ASSIGNMENT_COMMAND))) {
9037 setverdict(fail, "Failed to match Assignment Command: ", l3_msg);
9038 continue;
9039 }
9040
9041 /* Make sure that hopping parameters (HSN/MAIO) match */
9042 var ChannelDescription chan_desc := l3_msg.payload.ass_cmd.chan_desc;
9043 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9044
9045 /* Make sure that Cell Channel Description IE is present if FH is enabled */
9046 if (chan_desc.h and not ispresent(l3_msg.payload.ass_cmd.cell_chan_desc)) {
Vadim Yanitskiy38d069d2020-09-02 17:18:57 +07009047 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009048 continue;
9049 }
9050
9051 /* Make sure that the Mobile Allocation IE matches (if present) */
9052 var boolean ma_present := ispresent(l3_msg.payload.ass_cmd.mobile_allocation);
9053 if (chan_desc.h and ma_present) {
9054 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9055 l3_msg.payload.ass_cmd.mobile_allocation.v);
9056 } else if (chan_desc.h and not ma_present) {
9057 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9058 continue;
9059 } else if (not chan_desc.h and ma_present) {
9060 setverdict(fail, "FH disabled, but Mobile Allocation IE is present");
9061 continue;
9062 }
9063 }
9064
9065 /* Give the IUT some time to release all channels */
9066 f_sleep(3.0);
9067
9068 /* Disable frequency hopping */
9069 f_TC_fh_params_unset(fhp);
9070
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009071 f_shutdown_helper();
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009072}
9073
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009074/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Handover Command */
9075private function f_TC_fh_params_handover_cmd(in FHParamsTrx fhp)
9076runs on test_CT {
9077 var RSL_Message rsl_msg;
9078 var RSL_IE_Body ie;
9079 var DchanTuple dt;
9080
9081 /* Establish a dedicated channel, so we can trigger handover */
9082 dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
Vadim Yanitskiyc18ff472021-11-18 20:15:37 +03009083 f_sleep(0.5);
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009084
9085 /* Trigger handover from BTS0 to BTS1 */
9086 f_bts_0_cfg(BSCVTY, { "neighbor bts 1" });
9087 f_vty_handover(BSCVTY, 0, 0, dt.rsl_chan_nr, 1);
9088
9089 /* Expect RSL CHANnel ACTIVation on BTS1/TRX0/TS1 */
9090 rsl_msg := f_exp_ipa_rx(1, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9091
9092 /* ACKnowledge channel activation and expect (RR) Handover Command */
9093 f_ipa_tx(1, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9094 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
9095
9096 /* Make sure that L3 Information IE is present */
9097 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
9098 setverdict(fail, "RSL L3 Information IE is absent");
9099 return;
9100 }
9101
9102 /* Decode the L3 message and make sure it is (RR) Handover Command */
9103 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
9104 if (not match(l3_msg.header, t_RrL3Header(HANDOVER_COMMAND))) {
9105 setverdict(fail, "Failed to match Handover Command: ", l3_msg);
9106 return;
9107 }
9108
9109 /* Make sure that we've got SDCCH/8 on TS1 (expected to be hopping) */
9110 var ChannelDescription chan_desc := l3_msg.payload.ho_cmd.chan_desc;
9111 if (not match(chan_desc.chan_nr, t_RslChanNr_SDCCH8(1, ?))) {
9112 setverdict(fail, "Unexpected channel number: ", chan_desc.chan_nr);
9113 return;
9114 }
9115
9116 /* Make sure that hopping parameters (HSN/MAIO) match */
9117 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9118
9119 /* Make sure that Cell Channel Description IE is present */
9120 if (not ispresent(l3_msg.payload.ho_cmd.cell_chan_desc)) {
9121 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
9122 return;
9123 }
9124
9125 /* Make sure that the Mobile Allocation (after time) IE is present and matches */
9126 var boolean ma_present := ispresent(l3_msg.payload.ho_cmd.mobile_allocation);
9127 if (ma_present) {
9128 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9129 l3_msg.payload.ho_cmd.mobile_allocation.v);
9130 } else {
9131 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9132 return;
9133 }
9134}
9135testcase TC_fh_params_handover_cmd() runs on test_CT {
9136 var FHParamsTrx fhp := f_TC_fh_params_gen();
9137
9138 f_init_vty();
9139
9140 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8 on BTS1/TRX0 */
9141 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
9142
9143 f_vty_transceive(BSCVTY, "timeslot 0");
9144 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
9145 f_vty_transceive(BSCVTY, "exit"); /* go back */
9146
9147 f_vty_transceive(BSCVTY, "timeslot 1");
9148 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8");
9149 f_vty_transceive(BSCVTY, "end"); /* we're done */
9150
9151 f_TC_fh_params_set(fhp, 1); /* Enable frequency hopping on BTS1 */
9152 f_vty_transceive(BSCVTY, "drop bts connection 1 oml");
9153
9154 f_init(2);
9155
9156 f_TC_fh_params_handover_cmd(fhp);
9157
9158 /* Disable frequency hopping on BTS1 */
9159 f_TC_fh_params_unset(fhp, 1);
9160
9161 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
9162 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
9163
9164 f_vty_transceive(BSCVTY, "timeslot 0");
9165 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
9166 f_vty_transceive(BSCVTY, "exit"); /* go back */
9167
9168 f_vty_transceive(BSCVTY, "timeslot 1");
9169 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
9170 f_vty_transceive(BSCVTY, "end"); /* we're done */
9171
9172 f_shutdown_helper();
9173}
9174
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009175/* Verify the hopping parameters in System Information Type 4 */
9176testcase TC_fh_params_si4_cbch() runs on test_CT {
9177 var FHParamsTrx fhp := f_TC_fh_params_gen(tr_tn := 1);
9178 var ASP_RSL_Unitdata rx_rsl_ud;
9179 timer T := 5.0;
9180
9181 f_init_vty();
9182
9183 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8+CBCH */
9184 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
9185
9186 f_vty_transceive(BSCVTY, "timeslot 0");
9187 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
9188 f_vty_transceive(BSCVTY, "exit"); /* go back */
9189
9190 f_vty_transceive(BSCVTY, "timeslot 1");
9191 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8+cbch");
9192 f_vty_transceive(BSCVTY, "end"); /* we're done */
9193
9194 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9195 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9196
9197 f_init(1);
9198
9199 T.start;
9200 alt {
9201 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO(RSL_SYSTEM_INFO_4))) -> value rx_rsl_ud {
9202 var RSL_IE_Body ie := rx_rsl_ud.rsl.ies[2].body; /* FULL BCCH Information IE */
9203 var SystemInformation si := dec_SystemInformation(ie.other.payload);
9204
9205 /* Make sure that what we decoded is System Information Type 4 */
9206 if (si.header.message_type != SYSTEM_INFORMATION_TYPE_4) {
9207 setverdict(fail, "RSL FULL BCCH Information IE contains: ", si);
9208 repeat;
9209 }
9210
9211 /* Make sure that CBCH Channel Description IE is present */
9212 if (not ispresent(si.payload.si4.cbch_chan_desc)) {
9213 setverdict(fail, "CBCH Channel Description IE is absent");
9214 break;
9215 }
9216
9217 /* Finally, check the hopping parameters (HSN, MAIO) */
9218 var ChannelDescription chan_desc := si.payload.si4.cbch_chan_desc.v;
9219 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9220
9221 /* 3GPP TS 44.018, section 9.1.36.2 "CBCH Mobile Allocation":
9222 * The CBCH Mobile Allocation IE *shall* be present if FH is enabled. */
9223 if (chan_desc.h and not ispresent(si.payload.si4.cbch_mobile_alloc)) {
9224 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9225 break;
9226 } else if (chan_desc.h and ispresent(si.payload.si4.cbch_mobile_alloc)) {
9227 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9228 si.payload.si4.cbch_mobile_alloc.v);
9229 }
9230 }
9231 [] IPA_RSL[0].receive { repeat; }
9232 [] T.timeout {
9233 setverdict(fail, "Timeout waiting for RSL BCCH INFOrmation (SI4)");
9234 }
9235 }
9236
9237 /* Disable frequency hopping */
9238 f_TC_fh_params_unset(fhp);
9239
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07009240 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009241 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
9242
9243 f_vty_transceive(BSCVTY, "timeslot 0");
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07009244 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009245 f_vty_transceive(BSCVTY, "exit"); /* go back */
9246
9247 f_vty_transceive(BSCVTY, "timeslot 1");
9248 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
9249 f_vty_transceive(BSCVTY, "end"); /* we're done */
9250
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009251 f_shutdown_helper();
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009252}
9253
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009254template (value) PDU_BSSAP_LE ts_BSSMAP_LE_BSSLAP(template (value) BSSLAP_PDU bsslap)
9255 := ts_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, data := enc_BSSLAP_PDU(valueof(bsslap)));
9256
9257private function f_match_bsslap(PDU_BSSAP_LE got_bsslap_msg,
9258 template (present) BSSLAP_PDU expect_bsslap)
9259{
9260 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(got_bsslap_msg.pdu.bssmap.co_info.bsslap_apdu.data);
9261 if (not match(bsslap, expect_bsslap)) {
9262 log("EXPECTING BSSLAP: ", expect_bsslap);
9263 log("GOT BSSLAP: ", bsslap);
9264 setverdict(fail, "BSSLAP is not as expected");
9265 mtc.stop;
9266 }
9267 setverdict(pass);
9268}
9269
9270/* GAD: this is an Ellipsoid point with uncertainty circle, encoded as in 3GPP TS 23.032 §7.3.2. */
9271const octetstring gad_ell_point_unc_circle := '10b0646d0d5f6627'O;
9272
9273private function f_expect_bsslap(template (present) BSSLAP_PDU expect_rx_bsslap) runs on MSC_ConnHdlr {
9274 var PDU_BSSAP_LE rx_bsslap;
9275 BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap);
9276 f_match_bsslap(rx_bsslap, expect_rx_bsslap);
9277}
9278
9279/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9280 * Request on Lb interface. Either with or without the SMLC doing a BSSLAP TA Request. */
9281private function f_lcs_loc_req_for_active_ms(boolean do_ta_request := false) runs on MSC_ConnHdlr {
9282 f_sleep(1.0);
9283
9284 f_establish_fully(omit, omit);
9285 f_bssap_le_register_imsi(g_pars.imsi, omit);
9286
9287 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9288 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9289
9290 var PDU_BSSAP_LE plr;
9291 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9292
9293 if (not do_ta_request) {
9294 /* verify TA Layer 3 in APDU. First the APDU type (BSSLAP), then the BSSLAP data contents. */
9295 var template BSSMAP_LE_IE_APDU expect_apdu := tr_BSSMAP_LE_APDU(BSSMAP_LE_PROT_BSSLAP, ?);
9296 if (not match(plr.pdu.bssmap.perf_loc_req.bsslap_apdu, expect_apdu)) {
9297 log("EXPECTING BSSMAP-LE APDU IE ", expect_apdu);
9298 log("GOT BSSMAP-LE APDU IE ", plr.pdu.bssmap.perf_loc_req.bsslap_apdu);
9299 setverdict(fail, "BSSMAP-LE APDU IE is not as expected");
9300 mtc.stop;
9301 }
9302 var template BSSLAP_PDU expect_ta_layer3 := tr_BSSLAP_TA_Layer3(tr_BSSLAP_IE_TA(0));
9303 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(plr.pdu.bssmap.perf_loc_req.bsslap_apdu.data);
9304 if (not match(bsslap, expect_ta_layer3)) {
9305 log("EXPECTING BSSLAP TA Layer 3: ", expect_ta_layer3);
9306 log("GOT BSSLAP: ", bsslap);
9307 setverdict(fail, "BSSLAP is not as expected");
9308 mtc.stop;
9309 }
9310 /* OsmoBSC directly sent the TA as BSSLAP APDU in the BSSMAP-LE Perform Location Request to the SMLC. The SMLC
9311 * has no need to request the TA from the BSC and directly responds. */
9312 } else {
9313 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9314 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9315 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9316 }
9317
9318 /* SMLC got the TA from the BSC, now responds with geo information data. */
9319 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9320 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9321 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9322
9323 /* The LCS was using an active A-interface conn. It should still remain active after this. */
9324 f_mo_l3_transceive();
9325
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009326 f_perform_clear();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009327
9328 f_sleep(2.0);
9329 setverdict(pass);
9330}
9331
9332/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9333 * Request on Lb interface. Without the SMLC doing a BSSLAP TA Request. */
9334private function f_tc_lcs_loc_req_for_active_ms(charstring id) runs on MSC_ConnHdlr {
9335 f_lcs_loc_req_for_active_ms(false);
9336}
9337testcase TC_lcs_loc_req_for_active_ms() runs on test_CT {
9338 var MSC_ConnHdlr vc_conn;
9339 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9340
9341 f_init(1, true);
9342 f_sleep(1.0);
9343 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms), pars);
9344 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009345 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009346}
9347
9348/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9349 * Request on Lb interface. With the SMLC doing a BSSLAP TA Request. */
9350private function f_tc_lcs_loc_req_for_active_ms_ta_req(charstring id) runs on MSC_ConnHdlr {
9351 f_lcs_loc_req_for_active_ms(true);
9352}
9353testcase TC_lcs_loc_req_for_active_ms_ta_req() runs on test_CT {
9354 var MSC_ConnHdlr vc_conn;
9355 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9356
9357 f_init(1, true);
9358 f_sleep(1.0);
9359 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_ta_req), pars);
9360 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009361 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009362}
9363
9364/* Clear the A-interface conn only, without doing anything on Abis. Useful for LCS, for cases where there is only an A
9365 * conn without an active lchan. */
9366private function f_clear_A_conn() runs on MSC_ConnHdlr
9367{
9368 var BssmapCause cause := 0;
9369 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
9370 BSSAP.receive(tr_BSSMAP_ClearComplete);
9371 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
9372
9373 timer no_more_bssap := 5.0;
9374 no_more_bssap.start;
9375 alt {
9376 [] no_more_bssap.timeout { break; }
9377 [] BSSAP.receive(tr_BSSAP_BSSMAP) {
9378 setverdict(fail, "Expected no more BSSAP after Clear Complete");
9379 mtc.stop;
9380 }
9381 }
9382 setverdict(pass);
9383}
9384
9385/* Verify that the A-interface connection is still working, and then clear it, without doing anything on Abis. Useful
9386 * for LCS, for cases where there is only an A conn without an active lchan. */
9387private function f_verify_active_A_conn_and_clear() runs on MSC_ConnHdlr
9388{
9389 f_logp(BSCVTY, "f_verify_active_A_conn_and_clear: test A link, then clear");
9390
9391 /* When an lchan is active, we can send some L3 data from the BTS side and verify that it shows up on the other
9392 * side towards the MSC. When there is no lchan, this is not possible. To probe whether the A-interface
9393 * connection is still up, we need something that echos back on the A-interface. Another LCS request! */
9394 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9395 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9396 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?));
9397
9398 /* Right, the Perform Location Request showed up on Lb, now we can clear the A conn. */
9399 f_clear_A_conn();
9400 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
9401 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9402}
9403
9404/* With *no* active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9405 * Request on Lb interface. BSC will Page for the subscriber as soon as we (virtual SMLC) request the TA via BSSLAP.
9406 */
9407private function f_tc_lcs_loc_req_for_idle_ms(charstring id) runs on MSC_ConnHdlr {
9408 f_sleep(1.0);
9409
9410 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9411 f_bssap_le_register_imsi(g_pars.imsi, omit);
9412
9413 /* Register to receive the Paging Command */
9414 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9415 g_chan_nr := new_chan_nr;
9416 f_rslem_register(0, g_chan_nr);
9417
9418 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9419 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9420 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9421 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9422
9423 var PDU_BSSAP_LE plr;
9424 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9425
9426 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9427 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9428
9429 /* OsmoBSC needs to Page */
9430 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi)));
9431 f_logp(BSCVTY, "got Paging Command");
9432
9433 /* MS requests channel. Since the Paging was for LCS, the Paging Response does not trigger a Complete Layer 3 to
9434 * the MSC, and releases the lchan directly. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009435 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);
9436 f_expect_lchan_rel(RSL, RSL_PROC);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009437
9438 /* From the Paging Response, the TA is now known to the BSC, and it responds to the SMLC. */
9439
9440 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9441
9442 /* SMLC got the TA from the BSC, now responds with geo information data. */
9443 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9444 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9445
9446 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9447
9448 /* The lchan is gone, the A-interface conn was created for the LCS only.
9449 * Still it is clearly the MSC's job to decide whether to tear down the conn or not. */
9450 f_verify_active_A_conn_and_clear();
9451
9452 f_sleep(2.0);
9453 setverdict(pass);
9454}
9455testcase TC_lcs_loc_req_for_idle_ms() runs on test_CT {
9456 var MSC_ConnHdlr vc_conn;
9457 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9458
9459 f_init(1, true);
9460 f_sleep(1.0);
9461
9462 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9463 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9464
9465 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms), pars);
9466 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009467 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009468}
9469
9470/* With no active lchan, start BSSMAP Perform Location Request on A interface, but omit IMSI; expect failure response.
9471 */
9472private function f_tc_lcs_loc_req_no_subscriber(charstring id) runs on MSC_ConnHdlr {
9473 f_sleep(1.0);
9474
9475 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9476 f_bssap_le_register_imsi(g_pars.imsi, omit);
9477
9478 /* provoke an abort by omitting both IMSI and IMEI */
9479 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9480 valueof(ts_BSSMAP_Perform_Location_Request(omit,
9481 ts_CellId_CGI('262'H, '42'H, 23, 42)))));
9482 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9483
9484 /* BSC tells MSC about failure */
9485 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9486 locationEstimate := omit, positioningData := omit,
9487 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_DATA_MISSING_IN_REQ)));
9488
9489 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9490 f_verify_active_A_conn_and_clear();
9491
9492 f_sleep(2.0);
9493 setverdict(pass);
9494}
9495testcase TC_lcs_loc_req_no_subscriber() runs on test_CT {
9496 var MSC_ConnHdlr vc_conn;
9497 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9498
9499 f_init(1, true);
9500 f_sleep(1.0);
9501
9502 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9503 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9504
9505 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_no_subscriber), pars);
9506 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009507 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009508}
9509
9510/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9511 * BSSMAP-LE Perform Location Response (before or after sending a BSSLAP TA Request) */
9512private function f_lcs_loc_req_for_active_ms_le_timeout(boolean do_ta) runs on MSC_ConnHdlr {
9513 f_sleep(1.0);
9514
9515 f_establish_fully(omit, omit);
9516 f_bssap_le_register_imsi(g_pars.imsi, omit);
9517
9518 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9519 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9520
9521 var PDU_BSSAP_LE plr;
9522 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9523
9524 if (do_ta) {
9525 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9526 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9527 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9528 }
9529
9530 /* SMLC fails to respond, BSC runs into timeout */
9531 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_SYSTEM_FAILURE));
9532 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9533
9534 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9535 locationEstimate := omit, positioningData := omit,
9536 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_SYSTEM_FAILURE)));
9537
9538 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9539 f_verify_active_A_conn_and_clear();
9540
9541 f_sleep(2.0);
9542 setverdict(pass);
9543}
9544
9545/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9546 * BSSMAP-LE Perform Location Response, without sending a BSSLAP TA Request. */
9547private function f_tc_lcs_loc_req_for_active_ms_le_timeout(charstring id) runs on MSC_ConnHdlr {
9548 f_lcs_loc_req_for_active_ms_le_timeout(false);
9549}
9550
9551testcase TC_lcs_loc_req_for_active_ms_le_timeout() runs on test_CT {
9552 var MSC_ConnHdlr vc_conn;
9553 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9554
9555 f_init(1, true);
9556 f_sleep(1.0);
9557 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout), pars);
9558 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009559 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009560}
9561
9562/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9563 * BSSMAP-LE Perform Location Response, after sending a BSSLAP TA Request. */
9564private function f_tc_lcs_loc_req_for_active_ms_le_timeout2(charstring id) runs on MSC_ConnHdlr {
9565 f_lcs_loc_req_for_active_ms_le_timeout(true);
9566}
9567
9568testcase TC_lcs_loc_req_for_active_ms_le_timeout2() runs on test_CT {
9569 var MSC_ConnHdlr vc_conn;
9570 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9571
9572 f_init(1, true);
9573 f_sleep(1.0);
9574 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout2), pars);
9575 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009576 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009577}
9578
9579/* With *no* active lchan, start a Perform Location Request, expecting that the MS will be Paged. */
9580private function f_tc_lcs_loc_req_for_idle_ms_no_pag_resp(charstring id) runs on MSC_ConnHdlr {
9581 f_sleep(1.0);
9582
9583 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9584 f_bssap_le_register_imsi(g_pars.imsi, omit);
9585
9586 /* Register to receive the Paging Command */
9587 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9588 g_chan_nr := new_chan_nr;
9589 f_rslem_register(0, g_chan_nr);
9590
9591 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9592 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9593 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9594 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9595
9596 var PDU_BSSAP_LE plr;
9597 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9598
9599 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9600 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9601
9602 /* OsmoBSC needs to Page */
9603 var PDU_BSSAP_LE rx_bsslap;
9604 alt {
9605 [] RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi))) {
9606 f_logp(BSCVTY, "got Paging Command");
9607 repeat;
9608 }
9609 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
9610 /* MS does not respond to Paging, TA Req runs into timeout. */
9611 f_match_bsslap(rx_bsslap, tr_BSSLAP_Abort(?));
9612 }
9613 }
9614
9615 /* SMLC responds with failure */
9616 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(omit, BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
9617 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9618
9619 /* BSC tells MSC about failure */
9620 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9621 locationEstimate := omit, positioningData := omit,
9622 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_REQUEST_ABORTED)));
9623
9624 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9625 f_verify_active_A_conn_and_clear();
9626
9627 f_sleep(2.0);
9628 setverdict(pass);
9629}
9630testcase TC_lcs_loc_req_for_idle_ms_no_pag_resp() runs on test_CT {
9631 var MSC_ConnHdlr vc_conn;
9632 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9633
9634 f_init(1, true);
9635 f_sleep(1.0);
9636
9637 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9638 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9639
9640 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms_no_pag_resp), pars);
9641 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009642 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009643}
9644
9645/* During an ongoing Location Request, the MS sends a CM Service Request. Expect the same A-conn to be re-used / taken
9646 * over. */
9647private function f_tc_cm_service_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
9648 f_sleep(1.0);
9649
9650 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9651 f_bssap_le_register_imsi(g_pars.imsi, omit);
9652
9653 /* Register to receive the Paging Command */
9654 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9655 g_chan_nr := new_chan_nr;
9656 f_rslem_register(0, g_chan_nr);
9657
9658 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9659 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9660 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9661 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9662
9663 var PDU_BSSAP_LE plr;
9664 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9665
9666 /* As the A-interface conn was established for LCS, the MS coincidentally decides to issue a CM Service Request
9667 * and establish Layer 3. It should use the existing A-interface conn. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009668 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 +02009669 do_clear := false, expect_bssmap_l3 := true);
9670
9671 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9672 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9673
9674 /* OsmoBSC already has an lchan, no need to Page, just returns the TA */
9675 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9676
9677 /* SMLC got the TA from the BSC, now responds with geo information data. */
9678 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9679 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9680 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9681
9682 /* The lchan should still exist, it was from a CM Service Request. */
9683 f_mo_l3_transceive();
9684
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009685 f_perform_clear();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009686
9687 f_sleep(2.0);
9688 setverdict(pass);
9689}
9690testcase TC_cm_service_during_lcs_loc_req() runs on test_CT {
9691 var MSC_ConnHdlr vc_conn;
9692 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9693
9694 f_init(1, true);
9695 f_sleep(1.0);
9696
9697 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9698 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9699
9700 vc_conn := f_start_handler(refers(f_tc_cm_service_during_lcs_loc_req), pars);
9701 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009702 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009703}
9704
9705/* During an ongoing Perform Location Request, do a Handover, an expect a BSSLAP Reset message from the BSC to indicate
9706 * the new lchan after handover. */
9707private function f_tc_ho_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
9708 f_sleep(1.0);
9709
9710 f_establish_fully(omit, omit);
9711 f_bssap_le_register_imsi(g_pars.imsi, omit);
9712
9713 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9714 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9715
9716 var PDU_BSSAP_LE plr;
9717 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9718
9719 /* SMLC ponders the Location Request, in the meantime the BSC decides to handover */
9720 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
9721
9722 var HandoverState hs := {
9723 rr_ho_cmpl_seen := false,
9724 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02009725 old_chan_nr := -,
9726 expect_target_tsc := BTS_TSC[1]
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009727 };
9728 /* issue hand-over command on VTY */
9729 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
9730 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
9731 f_rslem_suspend(RSL1_PROC);
9732
9733 /* From the MGW perspective, a handover is is characterized by
9734 * performing one MDCX operation with the MGW. So we expect to see
9735 * one more MDCX during handover. */
9736 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
9737
9738 alt {
9739 [] as_handover(hs);
9740 }
9741
9742 var PDU_BSSAP_LE rx_bsslap;
9743
9744 interleave {
9745 /* Expect the BSC to inform the MSC about the handover */
9746 [] BSSAP.receive(tr_BSSMAP_HandoverPerformed);
9747
9748 /* Expect the BSC to inform the SMLC about the handover */
9749 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
9750 f_match_bsslap(rx_bsslap, tr_BSSLAP_Reset(BSSLAP_CAUSE_INTRA_BSS_HO));
9751 }
9752 }
9753
9754 /* SMLC now responds with geo information data. */
9755 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9756 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9757 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9758
9759 /* lchan still active */
9760 f_mo_l3_transceive(RSL1);
9761
9762 /* MSC decides it is done now. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009763 f_perform_clear(RSL1, RSL1_PROC);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009764
9765 f_sleep(2.0);
9766 setverdict(pass);
9767}
9768testcase TC_ho_during_lcs_loc_req() runs on test_CT {
9769 var MSC_ConnHdlr vc_conn;
9770 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9771
9772 f_init(2, true);
9773 f_sleep(1.0);
9774 vc_conn := f_start_handler(refers(f_tc_ho_during_lcs_loc_req), pars);
9775 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009776 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009777}
9778
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009779/* Attempt Complete Layer 3 without any MSC available (OS#4832) */
9780private function f_tc_no_msc(charstring id) runs on MSC_ConnHdlr {
9781 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9782
9783 /* Also disable attach for the single connected MSC */
9784 f_vty_msc_allow_attach(BSCVTY, { false });
9785
9786 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) ));
9787 f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
9788
9789 /* No MSC is found, expecting a proper release on RSL */
9790 interleave {
9791 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
9792 f_logp(BSCVTY, "Got RSL RR Release");
9793 }
9794 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
9795 f_logp(BSCVTY, "Got RSL Deact SACCH");
9796 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02009797 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009798 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
9799 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02009800 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009801 }
9802 }
9803 setverdict(pass);
9804}
9805testcase TC_no_msc() runs on test_CT {
9806
9807 f_init(1, true);
9808 f_sleep(1.0);
9809 var MSC_ConnHdlr vc_conn;
9810 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9811
9812 f_ctrs_bsc_init(counternames_bsc_mscpool);
9813
9814 vc_conn := f_start_handler(refers(f_tc_no_msc), pars);
9815 vc_conn.done;
9816
9817 f_ctrs_bsc_add("mscpool:subscr:no_msc");
9818 f_ctrs_bsc_verify();
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009819 f_shutdown_helper();
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009820}
9821
Harald Welte0ea2d5e2018-04-07 21:40:29 +02009822/* Dyn PDCH todo:
9823 * activate OSMO as TCH/F
9824 * activate OSMO as TCH/H
9825 * does the BSC-located PCU socket get the updated INFO?
9826 * what if no PCU is connected at the time?
9827 * is the info correct on delayed PCU (re)connect?
9828 */
Harald Welte94e0c342018-04-07 11:33:23 +02009829
Neels Hofmeyr87857ec2021-04-25 16:17:47 +00009830private function f_TC_refuse_mode_modif_to_vamos(charstring id) runs on MSC_ConnHdlr {
9831 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
9832 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
9833
9834 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
9835 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
9836 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
9837 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
9838 g_pars.ass_codec_list.codecElements[0];
9839 if (isvalue(g_pars.expect_mr_s0_s7)) {
9840 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
9841 g_pars.expect_mr_s0_s7;
9842 }
9843 }
9844 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
9845 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
9846 log("expecting ASS COMPL like this: ", exp_compl);
9847
9848 f_establish_fully(ass_cmd, exp_compl);
9849
Neels Hofmeyr8746b0d2021-06-01 17:25:39 +02009850 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 +00009851
9852 var RSL_Message rsl;
9853
9854 timer T := 5.0;
9855 T.start;
9856 alt {
9857 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
9858 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
9859 log("Rx L3 from net: ", l3);
9860 if (ischosen(l3.msgs.rrm.channelModeModify)) {
9861 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
9862 mtc.stop;
9863 }
9864 }
9865 [] RSL.receive(tr_RSL_MODE_MODIFY_REQ(g_chan_nr, ?)) -> value rsl {
9866 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
9867 mtc.stop;
9868 }
9869 [] T.timeout {
9870 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related Mode Modify should happen. */
9871 setverdict(pass);
9872 }
9873 }
9874 T.stop;
9875}
9876
9877/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel Mode Modify to VAMOS mode is refused by
9878 * osmo-bsc. */
9879testcase TC_refuse_mode_modif_to_vamos() runs on test_CT {
9880 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9881 var MSC_ConnHdlr vc_conn;
9882
9883 f_init(1, true);
9884 f_sleep(1.0);
9885
9886 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
9887 vc_conn := f_start_handler(refers(f_TC_refuse_mode_modif_to_vamos), pars);
9888 vc_conn.done;
9889 f_shutdown_helper();
9890}
9891
9892/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel activation to VAMOS mode is refused by osmo-bsc.
9893 */
9894testcase TC_refuse_chan_act_to_vamos() runs on test_CT {
9895 f_init_vty();
9896
9897 f_init(1, false);
9898 f_sleep(1.0);
9899
9900 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 activate-vamos fr");
9901
9902 var ASP_RSL_Unitdata rx_rsl_ud;
9903 timer T := 5.0;
9904
9905 T.start;
9906 alt {
9907 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(?, IPAC_PROTO_RSL_TRX0)) -> value rx_rsl_ud {
9908 if (rx_rsl_ud.rsl.msg_type == RSL_MT_CHAN_ACTIV) {
9909 T.stop;
9910 setverdict(fail, "CHANnel ACTivate in VAMOS mode succeeded even though BTS does not support VAMOS");
9911 mtc.stop;
9912 }
9913 repeat;
9914 }
9915 [] T.timeout {
9916 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related CHANnel ACTivate should happen. */
9917 setverdict(pass);
9918 }
9919 }
9920}
9921
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009922private function f_TC_reassignment_codec(charstring id) runs on MSC_ConnHdlr {
9923 /* First fully set up a speech lchan */
9924 f_TC_assignment_codec(id);
9925
9926 /* Trigger re-assignment to another lchan */
9927 var AssignmentState assignment_st := valueof(ts_AssignmentStateInit);
9928
9929 /* Re-Assignment should tell the MGW endpoint the new lchan's RTP address and port, so expecting to see exactly
9930 * one MDCX on MGCP. */
9931 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].mdcx_seen_exp + 1;
9932
9933 /* The new lchan will see all-new IPAC_CRCX and IPAC_MDCX messages telling the BTS the same RTP address and port
9934 * as the old lchan used. */
9935 g_media.bts.ipa_crcx_seen := false;
9936 g_media.bts.ipa_mdcx_seen := false;
9937
9938 /* Send different BTS side RTP port number for the new lchan */
9939 g_media.bts.bts.port_nr := 4223;
9940
9941 f_rslem_register(0, valueof(ts_RslChanNr_Bm(2))); /* <-- FIXME: can we somehow infer the timeslot that will be used? */
9942
9943 /* Trigger re-assignment. */
9944 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot " & int2str(g_chan_nr.tn) & " sub-slot 0 assignment");
9945
9946 timer T := 5.0;
9947 T.start;
9948 alt {
9949 [] as_assignment(assignment_st);
9950 [] as_Media();
9951 [] T.timeout {
9952 break;
9953 }
9954 }
9955
9956 if (not assignment_st.assignment_done) {
9957 setverdict(fail, "Assignment did not complete");
9958 mtc.stop;
9959 }
9960
9961 f_check_mgcp_expectations()
9962 setverdict(pass);
9963
9964 f_sleep(2.0);
9965 log("show lchan summary: ", f_vty_transceive_ret(BSCVTY, "show lchan summary"));
9966
9967 /* Instruct BSC to clear channel */
9968 var BssmapCause cause := 0;
9969 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
9970 interleave {
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009971 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {}
9972 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02009973 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009974 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02009975 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009976 }
9977 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
9978 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
9979 }
9980 }
Neels Hofmeyr40a45d12021-09-23 22:57:12 +02009981 f_expect_dlcx_conns();
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009982
9983 f_sleep(0.5);
9984}
9985
9986testcase TC_reassignment_fr() runs on test_CT {
9987 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9988 var MSC_ConnHdlr vc_conn;
9989
9990 f_init(1, true);
9991 f_sleep(1.0);
9992
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01009993 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009994
9995 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
9996 vc_conn := f_start_handler(refers(f_TC_reassignment_codec), pars);
9997 vc_conn.done;
9998
9999 /* from f_establish_fully() */
10000 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
10001 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
10002 /* from re-assignment */
10003 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
10004 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
10005 f_ctrs_bsc_and_bts_verify();
10006 f_shutdown_helper();
10007}
10008
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010009const charstring REEST_LOST_CONNECTION := "REEST_LOST_CONNECTION";
10010const charstring REEST_CLEAR := "REEST_CLEAR";
10011const charstring REEST_CLEAR_DONE := "REEST_CLEAR_DONE";
10012
10013/* CM Re-Establishment, 3GPP TS 24.008 4.5.1.6.
10014 * The MS <-> BTS loses radio connection, MS shows up on second BTS and asks for CM Re-Establishment.
10015 * BSC should establish a separate A conn for the same MS, the original A conn is then cleared by
10016 * the MSC as the CM Re-Establishment is handled.
10017 *
10018 * MS bts0 bts1 bsc msc test-component
10019 * |<----->|<----------------->|<-0-->| _1 Establish channel on bts 0
10020 * | | _1 wait a bit, to settle down
10021 * |<-x x--| | _1 "lose connection"
10022 * | | REEST_LOST_CONNECTION
10023 * |----------------->|------->|--1-->| _2 new A-conn: Chan Rqd, Imm Ass, Compl L3 with CM Re-Establishment Req
10024 * | | REEST_CLEAR
10025 * | |<-0---| _1 Clear Command on first A-conn
10026 * | |--0-->| _1 Clear Complete
10027 * | |<----------------->| | _1 Release first channel
10028 * | | REEST_CLEAR_DONE
10029 * |<-----------------|<-------|<-1---| _2 Chan Activ, Assignment Command
10030 * |<-----------------|<-------|<-1---| _2 Clear Command, Release
10031 *
10032 */
10033private function f_tc_cm_reestablishment_1(charstring id) runs on MSC_ConnHdlr {
10034 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
10035 var PDU_BSSAP ass_cmd := f_gen_ass_req();
10036
10037 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10038 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10039
10040 f_establish_fully(ass_cmd, exp_compl);
10041
10042 /* The original channel loses connection, MS attemts CM Re-Establishment on another cell, see
10043 * f_tc_cm_reestablishment_2(). This established channel stays active until MSC sends a Clear Command. The time
10044 * when exactly that happens is determined by f_tc_cm_reestablishment_2(). */
10045 f_sleep(2.0);
10046 COORD.send(REEST_LOST_CONNECTION);
10047
10048 alt {
10049 [] COORD.receive(REEST_CLEAR);
10050 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
10051 setverdict(fail, "Unexpected channel release");
10052 mtc.stop;
10053 }
10054 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
10055 setverdict(fail, "Unexpected channel release");
10056 mtc.stop;
10057 }
10058 }
10059 f_perform_clear()
10060 f_expect_dlcx_conns();
Neels Hofmeyr969abd02021-09-23 22:24:08 +020010061 f_create_mgcp_delete_ep(g_media.mgcp_ep);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010062 COORD.send(REEST_CLEAR_DONE);
10063}
10064
10065private function f_tc_cm_reestablishment_2(charstring id) runs on MSC_ConnHdlr {
10066 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
10067
10068 /* The MS lost the connection on the first channel, now establishes another one */
10069 COORD.receive(REEST_LOST_CONNECTION);
10070
10071 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
10072 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_REESTABL_REQ(mi));
10073 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
10074
10075 f_create_bssmap_exp(l3_enc);
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010076 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 +020010077 BSSAP.receive(tr_BSSMAP_ComplL3(l3_enc));
10078
10079 /* MSC got the CM Re-Establishment request and first off clears the previous conn. */
10080 COORD.send(REEST_CLEAR);
10081 COORD.receive(REEST_CLEAR_DONE);
10082
10083 f_sleep(2.0);
10084
10085 /* Answer the CM Re-Establishment with an Assignment Command. */
10086 var template PDU_BSSAP expect_assignment_compl := f_gen_exp_compl();
10087 var PDU_BSSAP ass_cmd := f_gen_ass_req();
10088 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10089 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10090
10091 var AssignmentState st := valueof(ts_AssignmentStateInit);
10092 st.voice_call := true;
10093 st.is_assignment := true;
10094
10095 var ExpectCriteria mgcpcrit := {
10096 connid := omit,
10097 endpoint := omit,
10098 transid := omit
10099 };
10100 f_create_mgcp_expect(mgcpcrit);
10101
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010102 f_rslem_dchan_queue_enable(RSL1_PROC);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010103
10104 BSSAP.send(ass_cmd);
10105
10106 var PDU_BSSAP bssap;
10107
10108 alt {
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010109 [] as_assignment(st, rsl_pt := RSL1, rsl_proc_pt := RSL1_PROC);
10110 [] as_Media_ipacc(RSL1, RSL2);
10111 [] as_Media_mgw();
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010112 [st.assignment_done] BSSAP.receive(expect_assignment_compl) {
10113 break;
10114 }
10115 }
10116
10117 f_sleep(3.0);
10118
10119 f_logp(BSCVTY, "f_tc_cm_reestablishment_2 clearing");
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010120 f_perform_clear(RSL1, RSL1_PROC);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010121 f_expect_dlcx_conns();
10122}
10123
10124testcase TC_cm_reestablishment() runs on test_CT {
10125 var TestHdlrParams pars1 := f_gen_test_hdlr_pars();
10126 var MSC_ConnHdlr vc_conn1;
10127
10128 var TestHdlrParams pars2 := f_gen_test_hdlr_pars();
10129 var MSC_ConnHdlr vc_conn2;
10130 pars2.imsi := pars1.imsi;
10131 pars2.media_nr := 2;
Neels Hofmeyrbf720202021-10-02 12:58:24 +020010132 pars2.expect_tsc := BTS_TSC[1];
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010133
10134 f_init(2, true, guard_timeout := 40.0);
10135 f_sleep(1.0);
10136
10137 vc_conn1 := f_start_handler_create(pars1);
10138 vc_conn2 := f_start_handler_create(pars2);
10139 connect(vc_conn1:COORD, vc_conn2:COORD);
10140 f_start_handler_run(vc_conn1, refers(f_tc_cm_reestablishment_1), pars1);
10141 f_start_handler_run(vc_conn2, refers(f_tc_cm_reestablishment_2), pars2);
10142 vc_conn1.done;
10143 vc_conn2.done;
10144
10145 f_shutdown_helper();
10146}
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000010147
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010148function f_exp_ipa_rx_nonfatal(integer bts_nr, template (present) RSL_Message t_rx, float t_secs := 2.0,
10149 IpaStreamId sid := IPAC_PROTO_RSL_TRX0, boolean ignore_other_rx := true)
10150runs on test_CT return template (omit) RSL_Message {
10151 var ASP_RSL_Unitdata rx_rsl_ud;
10152 timer T := t_secs;
10153
10154 T.start;
10155 alt {
10156 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
10157 T.stop;
10158 }
10159 [ignore_other_rx] IPA_RSL[bts_nr].receive { repeat; }
10160 [not ignore_other_rx] IPA_RSL[bts_nr].receive {
10161 log("f_exp_ipa_rx_nonfatal(): Got different message than ", t_rx);
10162 T.stop;
10163 return omit;
10164 }
10165 [] T.timeout {
10166 return omit;
10167 }
10168 }
10169 return rx_rsl_ud.rsl;
10170}
10171
10172private function f_vty_set_imm_ass(TELNETasp_PT pt, BtsNr bts_nr := 0, charstring imm_ass_setting := "post-chan-ack") {
10173 f_vty_enter_cfg_bts(pt, bts_nr);
10174 f_vty_transceive(pt, "immediate-assignment " & imm_ass_setting);
10175 f_vty_transceive(pt, "exit");
10176 f_vty_transceive(pt, "exit");
10177 f_vty_transceive(pt, "exit");
10178}
10179
10180private function f_verify_imm_ass(RSL_Message imm_ass, template uint8_t ra := ?, template GsmFrameNumber fn := ?,
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010181 template RslChannelNr chan_nr := ?,
10182 template (present) uint12_t arfcn := ?,
10183 template (present) uint3_t tsc := ?)
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010184{
10185 var RSL_IE_Body full_imm_ass_info;
10186 if (not f_rsl_find_ie(imm_ass, RSL_IE_FULL_IMM_ASS_INFO, full_imm_ass_info)) {
10187 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
10188 mtc.stop;
10189 }
10190
10191 var GsmRrMessage rr_imm_ass := dec_GsmRrMessage(full_imm_ass_info.full_imm_ass_info.payload);
10192 var template GsmRrMessage expect_imm_ass := tr_IMM_ASS(ra := ra,
10193 fn := fn,
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010194 ch_desc := tr_ChanDescH0(chan_nr, arfcn, tsc),
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010195 page_mode := ?);
10196 if (not match(rr_imm_ass, expect_imm_ass)) {
10197 log("Error: expected ", expect_imm_ass, " got ", rr_imm_ass);
10198 setverdict(fail, "Failed to match Immediate Assignment");
10199 mtc.stop;
10200 }
10201}
10202
10203testcase TC_imm_ass_post_chan_ack() runs on test_CT {
10204 var RSL_Message chan_act;
10205 var RSL_Message imm_ass;
10206
10207 f_init(1, false);
10208 f_sleep(1.0);
10209
10210 /* (should be the default anyway, just to make things clear) */
10211 f_vty_set_imm_ass(BSCVTY, 0, "post-chan-ack");
10212
10213 /* RA containing reason=LU */
10214 var GsmFrameNumber fn := 2342;
10215 var uint8_t ra := 2;
10216 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10217
10218 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10219
10220 /* First send the Chan Act ACK */
10221 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010222 var RSL_IE_Body chan_ident_ie;
10223 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10224 setverdict(fail, "RSL Channel Identification IE is absent");
10225 mtc.stop;
10226 }
10227
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010228 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn + 10));
10229
10230 /* Then expect the Immediate Assignment, after we ACKed the chan act */
10231 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10232
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010233 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10234 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010235
10236 /* Check that the lchan is working */
10237 var octetstring l3 := '00010203040506'O;
10238 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10239
10240 var BSSAP_N_CONNECT_ind rx_c_ind;
10241 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
10242 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10243
10244 f_sleep(1.0);
10245 f_shutdown_helper();
10246}
10247
10248testcase TC_imm_ass_pre_chan_ack() runs on test_CT {
10249 var RSL_Message chan_act;
10250 var RSL_Message imm_ass;
10251
10252 f_init(1, false);
10253 f_sleep(1.0);
10254
10255 f_vty_set_imm_ass(BSCVTY, 0, "pre-chan-ack");
10256
10257 /* RA containing reason=LU */
10258 var GsmFrameNumber fn := 2342;
10259 var uint8_t ra := 2;
10260 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10261
10262 /* (set bts 0 cfg back to default) */
10263 f_vty_set_imm_ass(BSCVTY);
10264
10265 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10266 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010267 var RSL_IE_Body chan_ident_ie;
10268 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10269 setverdict(fail, "RSL Channel Identification IE is absent");
10270 mtc.stop;
10271 }
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010272
10273 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10274 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010275 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10276 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010277
10278 /* Only now send the Chan Act ACK */
10279 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10280
10281 /* Check that the lchan is working */
10282 var octetstring l3 := '00010203040506'O;
10283 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10284
10285 var BSSAP_N_CONNECT_ind rx_c_ind;
10286 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
10287 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10288
10289 f_sleep(1.0);
10290 f_shutdown_helper();
10291}
10292
Neels Hofmeyr23158742021-09-07 19:08:07 +020010293testcase TC_imm_ass_pre_ts_ack() runs on test_CT {
10294 var RSL_Message chan_act;
10295 var RSL_Message imm_ass;
10296
10297 f_init(1, false);
10298 f_sleep(1.0);
10299
10300 f_vty_set_imm_ass(BSCVTY, 0, "pre-ts-ack");
10301
10302 /* RA containing reason=LU */
10303 var GsmFrameNumber fn := 2342;
10304 var uint8_t ra := 2;
10305 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10306
10307 /* (set bts 0 cfg back to default) */
10308 f_vty_set_imm_ass(BSCVTY);
10309
10310 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10311 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
10312 var RSL_IE_Body chan_ident_ie;
10313 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10314 setverdict(fail, "RSL Channel Identification IE is absent");
10315 mtc.stop;
10316 }
10317
10318 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10319 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10320 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10321 chan_ident_ie.chan_ident.ch_desc.v.tsc);
10322
10323 /* Only now send the Chan Act ACK */
10324 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10325
10326 /* Check that the lchan is working */
10327 var octetstring l3 := '00010203040506'O;
10328 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10329
10330 var BSSAP_N_CONNECT_ind rx_c_ind;
10331 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
10332 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10333
10334 f_sleep(1.0);
10335 f_shutdown_helper();
10336}
10337
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010338testcase TC_imm_ass_pre_chan_ack_dyn_ts() runs on test_CT {
10339 /* change Timeslot 6 before f_init() starts RSL */
10340 f_init_vty();
10341 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
10342 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10343
10344 f_init(1, false);
10345 f_sleep(1.0);
10346
10347 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
10348 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010349 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010350 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2323));
10351
10352 /* clean up timeslot 6 config, will only take effect when the OML drops the next time */
10353 f_ts_set_chcomb(0, 0, 6, "PDCH");
10354
10355 /* block all static timeslots so that the dyn TS will be used */
10356 f_disable_all_tch_f();
10357 f_disable_all_tch_h();
10358 f_disable_all_sdcch();
10359
10360 var RSL_Message chan_act;
10361 var RSL_Message imm_ass;
10362
10363 f_init(1, false);
10364 f_sleep(1.0);
10365
10366 f_vty_set_imm_ass(BSCVTY, 0, "pre-chan-ack");
10367
10368 /* RA containing reason=LU */
10369 var GsmFrameNumber fn := 2342;
10370 var uint8_t ra := 2;
10371 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10372
10373 /* (set bts 0 cfg back to default) */
10374 f_vty_set_imm_ass(BSCVTY);
10375
10376 /* Expect the dyn TS to deactivate PDCH first */
10377 f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
10378 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
10379
10380 /* Now activation as SDCCH8 */
10381 chan_nr := valueof(t_RslChanNr_SDCCH8(tn := 6, sub_slot := 0));
10382
10383 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010384 var RSL_IE_Body chan_ident_ie;
10385 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10386 setverdict(fail, "RSL Channel Identification IE is absent");
10387 mtc.stop;
10388 }
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010389
10390 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10391 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010392 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10393 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010394
10395 /* Only now send the Chan Act ACK */
10396 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10397
10398 /* Check that the lchan is working */
10399 var octetstring l3 := '00010203040506'O;
10400 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10401
10402 var BSSAP_N_CONNECT_ind rx_c_ind;
10403 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
10404 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10405
10406 f_sleep(1.0);
10407 f_shutdown_helper();
10408}
10409
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010410testcase TC_imm_ass_pre_ts_ack_dyn_ts() runs on test_CT {
10411 /* change Timeslot 6 before f_init() starts RSL */
10412 f_init_vty();
10413 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
10414 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10415
10416 f_init(1, false);
10417 f_sleep(1.0);
10418
10419 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
10420 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010421 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010422 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2323));
10423
10424 /* clean up timeslot 6 config, will only take effect when the OML drops the next time */
10425 f_ts_set_chcomb(0, 0, 6, "PDCH");
10426
10427 /* block all static timeslots so that the dyn TS will be used */
10428 f_disable_all_tch_f();
10429 f_disable_all_tch_h();
10430 f_disable_all_sdcch();
10431
10432 var RSL_Message chan_act;
10433 var RSL_Message imm_ass;
10434
10435 f_init(1, false);
10436 f_sleep(1.0);
10437
10438 f_vty_set_imm_ass(BSCVTY, 0, "pre-ts-ack");
10439
10440 /* RA containing reason=LU */
10441 var GsmFrameNumber fn := 2342;
10442 var uint8_t ra := 2;
10443 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10444
10445 /* (set bts 0 cfg back to default) */
10446 f_vty_set_imm_ass(BSCVTY);
10447
10448 /* Expect the dyn TS to deactivate PDCH first */
10449 f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
10450
10451 /* And already the Immediate Assignment even before the PDCH Deact ACK */
10452 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10453
10454 /* continue the Osmo style PDCH Deact (usual chan rel) */
10455 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
10456
10457 /* Now activation as SDCCH8 */
10458 chan_nr := valueof(t_RslChanNr_SDCCH8(tn := 6, sub_slot := 0));
10459
10460 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010461 var RSL_IE_Body chan_ident_ie;
10462 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10463 setverdict(fail, "RSL Channel Identification IE is absent");
10464 mtc.stop;
10465 }
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010466 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10467
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010468 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10469 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010470
10471 /* Check that the lchan is working */
10472 var octetstring l3 := '00010203040506'O;
10473 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10474
10475 var BSSAP_N_CONNECT_ind rx_c_ind;
10476 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
10477 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10478
10479 f_sleep(1.0);
10480 f_shutdown_helper();
10481}
10482
Neels Hofmeyr5d7d13f2021-09-07 14:44:36 +020010483/* GET and SET the bts.N.trx.M.rf_locked CTRL variable */
10484testcase TC_ctrl_trx_rf_locked() runs on test_CT {
10485 var MSC_ConnHdlr vc_conn;
10486
10487 f_init(nr_bts := 2, handler_mode := true, nr_msc := 1);
10488 f_sleep(1.0);
10489
10490 /* BTS 0, 1, 2 are OML unlocked, only BTS 0, 1 are actually connected to RSL. */
10491 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10492 "0,0,operational,unlocked,on,rsl-up;" &
10493 "1,0,operational,unlocked,on,rsl-up;" &
10494 "2,0,operational,unlocked,on,rsl-down;" &
10495 "3,0,inoperational,locked,on,rsl-down;");
10496
10497 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: lock BTS 1 TRX 0");
10498 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "1");
10499 /* give it a moment to settle the FSM status */
10500 f_sleep(1.0);
10501
10502 /* Now BTS 1 TRX 0 should reflect "locked". Note the RF policy stays "on", because this is still handled
10503 * globally in osmo-bsc. Probably after sending "rf_locked 1" for a TRX, that TRX should reflect an RF policy
10504 * of "off"? But that's for a future patch if at all. */
10505 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10506 "0,0,operational,unlocked,on,rsl-up;" &
10507 "1,0,operational,locked,on,rsl-up;" &
10508 "2,0,operational,unlocked,on,rsl-down;" &
10509 "3,0,inoperational,locked,on,rsl-down;");
10510
10511 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: lock the already locked TRX, nothing should change");
10512 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "1");
10513 f_sleep(1.0);
10514 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10515 "0,0,operational,unlocked,on,rsl-up;" &
10516 "1,0,operational,locked,on,rsl-up;" &
10517 "2,0,operational,unlocked,on,rsl-down;" &
10518 "3,0,inoperational,locked,on,rsl-down;");
10519
10520 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock BTS 1 TRX 0");
10521 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "0");
10522 f_sleep(1.0);
10523 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10524 "0,0,operational,unlocked,on,rsl-up;" &
10525 "1,0,operational,unlocked,on,rsl-up;" &
10526 "2,0,operational,unlocked,on,rsl-down;" &
10527 "3,0,inoperational,locked,on,rsl-down;");
10528
10529 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock an already unlocked TRX, nothing should change");
10530 f_ctrl_set(IPA_CTRL, "bts.0.trx.0.rf_locked", "0");
10531 f_sleep(1.0);
10532 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10533 "0,0,operational,unlocked,on,rsl-up;" &
10534 "1,0,operational,unlocked,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: unlock an inoperational TRX");
10539 f_ctrl_set(IPA_CTRL, "bts.3.trx.0.rf_locked", "0");
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,unlocked,on,rsl-up;" &
10544 "2,0,operational,unlocked,on,rsl-down;" &
10545 "3,0,inoperational,locked,on,rsl-down;");
10546
10547 f_shutdown_helper();
10548}
10549
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010550const CounterNameVals counternames_cm_serv_rej := {
10551 { "cm_serv_rej", 0 },
10552 { "cm_serv_rej:imsi_unknown_in_hlr", 0 },
10553 { "cm_serv_rej:illegal_ms", 0 },
10554 { "cm_serv_rej:imsi_unknown_in_vlr", 0 },
10555 { "cm_serv_rej:imei_not_accepted", 0 },
10556 { "cm_serv_rej:illegal_me", 0 },
10557 { "cm_serv_rej:plmn_not_allowed", 0 },
10558 { "cm_serv_rej:loc_not_allowed", 0 },
10559 { "cm_serv_rej:roaming_not_allowed", 0 },
10560 { "cm_serv_rej:network_failure", 0 },
10561 { "cm_serv_rej:synch_failure", 0 },
10562 { "cm_serv_rej:congestion", 0 },
10563 { "cm_serv_rej:srv_opt_not_supported", 0 },
10564 { "cm_serv_rej:rqd_srv_opt_not_supported", 0 },
10565 { "cm_serv_rej:srv_opt_tmp_out_of_order", 0 },
10566 { "cm_serv_rej:call_can_not_be_identified", 0 },
10567 { "cm_serv_rej:incorrect_message", 0 },
10568 { "cm_serv_rej:invalid_mandantory_inf", 0 },
10569 { "cm_serv_rej:msg_type_not_implemented", 0 },
10570 { "cm_serv_rej:msg_type_not_compatible", 0 },
10571 { "cm_serv_rej:inf_eleme_not_implemented", 0 },
10572 { "cm_serv_rej:condtional_ie_error", 0 },
10573 { "cm_serv_rej:msg_not_compatible", 0 },
10574 { "cm_serv_rej:protocol_error", 0 },
10575 { "cm_serv_rej:retry_in_new_cell", 0 }
10576};
10577
10578private function f_TC_cm_serv_rej(charstring id) runs on MSC_ConnHdlr
10579{
10580 f_create_chan_and_exp();
Vadim Yanitskiya7fc5a62021-12-04 20:10:08 +030010581 /* we should now have a COMPL_L3 at the MSC */
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010582 BSSAP.send(ts_PDU_DTAP_MT(ts_CM_SERV_REJ('02'O), '00'O));
Neels Hofmeyr87a65612021-11-16 15:56:45 +010010583 f_sleep(1.0);
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010584}
10585testcase TC_cm_serv_rej() runs on test_CT {
10586 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10587 var MSC_ConnHdlr vc_conn;
10588
10589 f_init(1, true);
10590 f_sleep(1.0);
10591
10592 f_ctrs_bts_init(1, counternames_cm_serv_rej);
10593
10594 vc_conn := f_start_handler(refers(f_TC_cm_serv_rej), pars);
10595 vc_conn.done;
10596
10597 f_ctrs_bts_add(0, "cm_serv_rej", 1);
10598 f_ctrs_bts_add(0, "cm_serv_rej:imsi_unknown_in_hlr", 1);
10599 f_ctrs_bts_verify();
10600
Neels Hofmeyr87a65612021-11-16 15:56:45 +010010601 f_sleep(1.0);
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010602 f_shutdown_helper();
10603}
10604
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010605/* Reproduce a segfault happening when the SDCCH (primary) lchan is lost in-between a TCH Channel Activ and its Channel
10606 * Activ Ack (SYS#5627). */
10607private function f_TC_lost_sdcch_during_assignment(charstring id) runs on MSC_ConnHdlr {
10608 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Vadim Yanitskiyf0310e32021-10-26 00:30:59 +030010609
10610 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10611 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010612
10613 var BSSMAP_FIELD_CodecType codecType;
10614 codecType := valueof(ass_cmd.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType);
10615
10616 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
10617
10618 /* First establish a signalling lchan */
10619 f_create_chan_and_exp();
10620 f_rslem_dchan_queue_enable();
10621
10622 /* we should now have a COMPL_L3 at the MSC */
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010623
10624 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
10625 activate(as_Media_mgw());
10626
10627 var RslChannelNr chan_nr := { u := { ch0 := RSL_CHAN_NR_Bm_ACCH }, tn := 1 };
10628 f_rslem_register(0, chan_nr);
10629
10630 f_rslem_set_auto_chan_act_ack(RSL_PROC, false);
10631 BSSAP.send(ass_cmd);
10632
10633
10634 /* Wait for the Channel Activ for the TCH channel */
10635 var ASP_RSL_Unitdata rx_rsl_ud;
10636 RSL.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV), sid := ?)) -> value rx_rsl_ud;
10637
10638 /* make the original SDCCH disappear */
10639 RSL.send(ts_RSL_REL_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
10640
10641 /* and ACK the TCH channel activation. This caused a segfault up to OsmoBSC 1.7.0 (SYS#5627) */
10642 RSL.send(ts_ASP_RSL_UD(ts_RSL_CHAN_ACT_ACK(chan_nr, 23), rx_rsl_ud.streamId));
10643
10644 interleave {
10645 [] BSSAP.receive(tr_BSSMAP_AssignmentFail);
10646 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
10647 }
10648
10649 BSSAP.send(ts_BSSMAP_ClearCommand(0));
10650 BSSAP.receive(tr_BSSMAP_ClearComplete);
10651 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
10652
10653 var MgcpCommand mgcp;
10654 MGCP.receive(tr_DLCX()) -> value mgcp {
10655 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
10656 };
10657
10658 f_sleep(0.5);
10659}
10660testcase TC_lost_sdcch_during_assignment() runs on test_CT {
10661 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10662 var MSC_ConnHdlr vc_conn;
10663
10664 f_init(1, true);
10665 f_sleep(1.0);
10666
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010667 vc_conn := f_start_handler(refers(f_TC_lost_sdcch_during_assignment), pars);
10668 vc_conn.done;
10669
10670 f_shutdown_helper();
10671}
10672
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010673const CounterNameVals counternames_bsc_bts_all_available_allocated := {
10674 { "all_allocated:sdcch", 0 },
10675 { "all_allocated:static_sdcch", 0 },
10676 { "all_allocated:tch", 0 },
10677 { "all_allocated:static_tch", 0 }
10678}
10679
10680private function f_all_allocated_expect_counter_change(charstring_list expect_changed) runs on test_CT
10681{
10682 /* Make sure counters settle first */
10683 f_sleep(1.0);
10684
10685 /* Take a baseline of counters */
10686 f_ctrs_bsc_and_bts_init(1, counternames_bsc_bts_all_available_allocated);
10687
10688 /* Elapse some time so that we see changes in counters, hopefully where expected */
10689 f_sleep(2.0);
10690
10691 /* Get new counters */
10692 var charstring_list all_changed := {};
10693 all_changed := all_changed & f_counter_name_vals_get_changed_n(IPA_CTRL, "bsc", g_ctr_bsc);
10694 all_changed := all_changed & f_counter_name_vals_get_changed_n(IPA_CTRL, "bts", g_ctr_bts);
10695
10696 /* Compare with expectations */
10697 var charstring_list all_expect_changed := {};
10698 for (var integer i := 0; i < lengthof(expect_changed); i := i + 1) {
10699 all_expect_changed := all_expect_changed & { "bsc.0." & expect_changed[i], "bts.0." & expect_changed[i] };
10700 }
10701 f_counter_name_vals_expect_changed_list(all_changed, all_expect_changed);
10702}
10703
10704testcase TC_ratectr_all_available_allocated() runs on test_CT {
10705 var ASP_RSL_Unitdata rsl_ud;
10706 var integer i;
10707 var integer chreq_total, chreq_nochan;
10708
10709 f_init(1);
10710 f_sleep(1.0);
10711
10712 /* Exhaust all dedicated SDCCH lchans.
10713 /* GSM 44.018 Table 9.1.8.2:
10714 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
10715 */
10716 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
10717 f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
10718 }
10719
10720 /* Since only bts 0 is connected, expecting all_allocated to become true for both bts 0 and the "global" bsc
10721 * level.
10722 * All SDCCH are now occupied. */
10723 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch"});
10724
10725 /* Also fill up all remaining (TCH) channels */
10726 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS; i := i+1) {
10727 f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
10728 }
10729
10730 /* All TCH are now also occupied */
10731 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch",
10732 "all_allocated:tch", "all_allocated:static_tch"});
10733
10734 f_shutdown_helper();
10735}
10736
10737testcase TC_ratectr_all_available_allocated_dyn() runs on test_CT {
10738 var ASP_RSL_Unitdata rsl_ud;
10739 var integer i;
10740 var integer chreq_total, chreq_nochan;
10741
10742 f_init_vty();
10743 f_ts_set_chcomb(0, 0, 2, "TCH/F_TCH/H_PDCH");
10744 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10745 /* Now we have 3 TCH/F, 1 OSMO_DYN, 1 TCH/H */
10746
10747 f_init(1, guard_timeout := 60.0);
10748 f_sleep(1.0);
10749
10750 /* The dyn TS wants to activate PDCH mode, ACK that. */
10751 var RslChannelNr chan_nr;
10752 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010753 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010754 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
10755
10756 /* Exhaust all dedicated SDCCH lchans.
10757 /* GSM 44.018 Table 9.1.8.2:
10758 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
10759 */
10760 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
10761 f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
10762 }
10763
10764 /* The static SDCCH should now be occupied, while still 3x8 dynamic SDCCH potentially remain. So only
10765 * all_allocated:static_sdcch is counted, all_allocated:sdcch remains zero. */
10766 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch"});
10767
10768 /* Request more SDCCH, hence convert the first dyn TS to SDCCH8.
10769 * Will release them later, so remember all the DchanTuples. */
10770 var DchanTuples dyn_sddch := {};
10771 dyn_sddch := dyn_sddch & { f_est_dchan_dyn('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
10772
10773 /* Also occupy the seven other SDCCH of the dyn TS */
10774 for (i := 0; i < 7; i := i+1) {
10775 dyn_sddch := dyn_sddch & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
10776 }
10777
10778 /* Now all dynamic SDCCH are also occupied, so for the first time all_allocated:sdcch will trigger... */
10779 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch"});
10780
10781 /* occupy the remaining TCH, three TCH/F and two TCH/H lchans */
10782 for (i := 0; i < 5; i := i+1) {
10783 f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
10784 }
10785
10786 /* All TCH lchans are now also occupied, both static and dynamic */
10787 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch",
10788 "all_allocated:tch", "all_allocated:static_tch"});
10789
10790 /* Starting to release the dyn TS: as soon as the first SDCCH gets released, all_allocated:sdcch stops
10791 * incrementing. */
10792 var BssmapCause cause := 0;
10793 var DchanTuple dt := dyn_sddch[0];
10794 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
10795 f_exp_chan_rel_and_clear(dt, 0);
10796
10797 /* one dyn TS SDCCH is free again, so only the static_sdcch should increment. For tch, both static and dynamic
10798 * count as occupied, so those still both increment. */
10799 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch",
10800 "all_allocated:tch", "all_allocated:static_tch"});
10801
10802 /* Release the remaining SDCCH of the dyn TS, so it becomes available as TCH again */
10803 for (i := 1; i < lengthof(dyn_sddch); i := i+1) {
10804 dt := dyn_sddch[i];
10805 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
10806 f_exp_chan_rel_and_clear(dt, 0);
10807 }
10808
10809 /* All SDCCH on the dyn TS are released, the dyn TS wants to activate PDCH again */
10810 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010811 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010812 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
10813
10814 /* Now all channels are occupied except the dyn TS, so expecting only the static counters to increment */
10815 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch", "all_allocated:static_tch"});
10816
10817 /* clean up config */
10818 f_ts_reset_chcomb(0);
10819
10820 f_shutdown_helper();
10821}
10822
Harald Welte28d943e2017-11-25 15:00:50 +010010823control {
Harald Welte898113b2018-01-31 18:32:21 +010010824 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +010010825 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +010010826 execute( TC_ctrl_msc0_connection_status() );
Neels Hofmeyrf65ce872021-09-23 18:40:10 +020010827 /* In SCCPlite tests, only one MSC is configured. These tests assume that three MSCs are configured, so only run
10828 * these in the AoIP test suite. */
10829 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
10830 execute( TC_stat_num_msc_connected_1() );
10831 execute( TC_stat_num_msc_connected_2() );
10832 execute( TC_stat_num_msc_connected_3() );
10833 }
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +020010834 execute( TC_stat_num_bts_connected_1() );
10835 execute( TC_stat_num_bts_connected_2() );
10836 execute( TC_stat_num_bts_connected_3() );
Harald Welte96c94412017-12-09 03:12:45 +010010837 execute( TC_ctrl() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +020010838 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER) {
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +020010839 execute( TC_ctrl_location() );
10840 }
Harald Welte898113b2018-01-31 18:32:21 +010010841
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020010842 execute( TC_si_default() );
Neels Hofmeyr66aeba42020-07-06 02:21:21 +020010843 execute( TC_si2quater_2_earfcns() );
10844 execute( TC_si2quater_3_earfcns() );
10845 execute( TC_si2quater_4_earfcns() );
10846 execute( TC_si2quater_5_earfcns() );
10847 execute( TC_si2quater_6_earfcns() );
Neels Hofmeyrad132f22020-07-08 02:20:16 +020010848 execute( TC_si2quater_12_earfcns() );
10849 execute( TC_si2quater_23_earfcns() );
10850 execute( TC_si2quater_32_earfcns() );
10851 execute( TC_si2quater_33_earfcns() );
10852 execute( TC_si2quater_42_earfcns() );
10853 execute( TC_si2quater_48_earfcns() );
10854 execute( TC_si2quater_49_earfcns() );
Pau Espin Pedrol85a84432020-07-20 18:45:03 +020010855 execute( TC_si_acc_rotate() );
Alexander Couzens4ad3a352020-09-10 22:29:12 +020010856 execute( TC_si_acc_ramp_rotate() );
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020010857
Harald Welte898113b2018-01-31 18:32:21 +010010858 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +010010859 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +010010860 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +010010861 execute( TC_chan_act_ack_noest() );
Philipp Maier9c60a622020-07-09 15:08:46 +020010862 execute( TC_chan_act_ack_noest_emerg() );
Philipp Maier606f07d2020-08-12 17:21:58 +020010863 execute( TC_chan_rqd_emerg_deny() );
Harald Welteae026692017-12-09 01:03:01 +010010864 execute( TC_chan_act_ack_est_ind_noreply() );
10865 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +010010866 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +010010867 execute( TC_chan_exhaustion() );
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +070010868 execute( TC_chan_deact_silence() );
Harald Welte4003d112017-12-09 22:35:39 +010010869 execute( TC_chan_rel_rll_rel_ind() );
10870 execute( TC_chan_rel_conn_fail() );
10871 execute( TC_chan_rel_hard_clear() );
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +020010872 execute( TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() );
10873 execute( TC_chan_rel_last_eutran_plmn_hard_clear_csfb() );
Harald Welte99787102019-02-04 10:41:36 +010010874 execute( TC_chan_rel_hard_clear_csfb() );
Harald Welted8c36cd2017-12-09 23:05:31 +010010875 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +020010876 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +010010877 execute( TC_chan_rel_a_reset() );
Pau Espin Pedrolc675b612020-01-09 19:55:40 +010010878 execute( TC_chan_rel_sccp_tiar_timeout() );
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +020010879 execute( TC_chan_rel_rr_cause() );
Harald Welte6f521d82017-12-11 19:52:02 +010010880
Harald Weltecfe2c962017-12-15 12:09:32 +010010881 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +010010882
10883 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +010010884 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +010010885 execute( TC_assignment_csd() );
10886 execute( TC_assignment_ctm() );
10887 execute( TC_assignment_sign() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +020010888 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
10889 execute( TC_assignment_aoip_tla_v6() );
10890 }
Harald Welte235ebf12017-12-15 14:18:16 +010010891 execute( TC_assignment_fr_a5_0() );
10892 execute( TC_assignment_fr_a5_1() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +020010893 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte8f67d1d2018-05-25 20:38:42 +020010894 execute( TC_assignment_fr_a5_1_codec_missing() );
10895 }
Harald Welte235ebf12017-12-15 14:18:16 +010010896 execute( TC_assignment_fr_a5_3() );
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +020010897 execute( TC_assignment_fr_a5_4() );
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +020010898 execute( TC_assignment_fr_a5_4_fail() );
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +020010899 execute( TC_assignment_fr_a5_not_sup() );
Harald Welte3c86ea02018-05-10 22:28:05 +020010900 execute( TC_ciph_mode_a5_0() );
10901 execute( TC_ciph_mode_a5_1() );
Oliver Smith50b98122021-07-09 15:00:28 +020010902 execute( TC_ciph_mode_a5_2_0() );
Oliver Smith1dff88d2021-07-09 08:45:51 +020010903 execute( TC_ciph_mode_a5_2_1() );
Harald Welte3c86ea02018-05-10 22:28:05 +020010904 execute( TC_ciph_mode_a5_3() );
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +020010905 execute( TC_ciph_mode_a5_4() );
Harald Welte16a4adf2017-12-14 18:54:01 +010010906
Harald Welte60aa5762018-03-21 19:33:13 +010010907 execute( TC_assignment_codec_fr() );
Neels Hofmeyr559d5d02021-04-16 16:50:49 +020010908 execute( TC_assignment_codec_fr_by_mode_modify() );
Harald Welte60aa5762018-03-21 19:33:13 +010010909 execute( TC_assignment_codec_hr() );
10910 execute( TC_assignment_codec_efr() );
10911 execute( TC_assignment_codec_amr_f() );
10912 execute( TC_assignment_codec_amr_h() );
Philipp Maier8a581d22019-03-26 18:32:48 +010010913
Neels Hofmeyrf246a922020-05-13 02:27:10 +020010914 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier8a581d22019-03-26 18:32:48 +010010915 execute( TC_assignment_codec_amr_f_S1() );
10916 execute( TC_assignment_codec_amr_h_S1() );
10917 execute( TC_assignment_codec_amr_f_S124() );
10918 execute( TC_assignment_codec_amr_h_S124() );
10919 execute( TC_assignment_codec_amr_f_S0() );
10920 execute( TC_assignment_codec_amr_f_S02() );
10921 execute( TC_assignment_codec_amr_f_S024() );
10922 execute( TC_assignment_codec_amr_f_S0247() );
10923 execute( TC_assignment_codec_amr_h_S0() );
10924 execute( TC_assignment_codec_amr_h_S02() );
10925 execute( TC_assignment_codec_amr_h_S024() );
10926 execute( TC_assignment_codec_amr_h_S0247() );
10927 execute( TC_assignment_codec_amr_f_S01234567() );
10928 execute( TC_assignment_codec_amr_f_S0234567() );
10929 execute( TC_assignment_codec_amr_f_zero() );
10930 execute( TC_assignment_codec_amr_f_unsupp() );
10931 execute( TC_assignment_codec_amr_h_S7() );
Neels Hofmeyr21863562020-11-26 00:34:33 +000010932 execute( TC_assignment_codec_amr_f_start_mode_auto() );
10933 execute( TC_assignment_codec_amr_h_start_mode_auto() );
Neels Hofmeyr3eb94562020-11-26 02:40:26 +000010934 execute( TC_assignment_codec_amr_f_start_mode_4() );
10935 execute( TC_assignment_codec_amr_h_start_mode_4() );
Neels Hofmeyr454d7922020-11-26 02:24:57 +000010936 execute( TC_assignment_codec_amr_startmode_cruft() );
Philipp Maier8a581d22019-03-26 18:32:48 +010010937 }
Harald Welte60aa5762018-03-21 19:33:13 +010010938
Philipp Maierac09bfc2019-01-08 13:41:39 +010010939 execute( TC_assignment_codec_fr_exhausted_req_hr() );
10940 execute( TC_assignment_codec_fr_exhausted_req_fr() );
10941 execute( TC_assignment_codec_fr_exhausted_req_fr_hr() );
10942 execute( TC_assignment_codec_fr_exhausted_req_hr_fr() );
10943 execute( TC_assignment_codec_hr_exhausted_req_fr() );
10944 execute( TC_assignment_codec_hr_exhausted_req_hr() );
10945 execute( TC_assignment_codec_hr_exhausted_req_hr_fr() );
10946 execute( TC_assignment_codec_hr_exhausted_req_fr_hr() );
10947 execute( TC_assignment_codec_req_hr_fr() );
10948 execute( TC_assignment_codec_req_fr_hr() );
Pau Espin Pedrol14475352021-07-22 15:48:16 +020010949 execute( TC_assignment_sdcch_exhausted_req_signalling() );
10950 execute( TC_assignment_sdcch_exhausted_req_signalling_tch_forbidden() );
10951 execute( TC_assignment_sdcch_exhausted_req_voice_tch_forbidden() );
Philipp Maierac09bfc2019-01-08 13:41:39 +010010952
Pau Espin Pedrol23510fb2021-07-20 17:00:38 +020010953 execute( TC_assignment_osmux() );
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +020010954
Harald Welte898113b2018-01-31 18:32:21 +010010955 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +010010956 execute( TC_rll_est_ind_inact_lchan() );
10957 execute( TC_rll_est_ind_inval_sapi1() );
10958 execute( TC_rll_est_ind_inval_sapi3() );
10959 execute( TC_rll_est_ind_inval_sacch() );
10960
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +070010961 /* DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
10962 execute( TC_tch_dlci_link_id_sapi() );
10963
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +070010964 /* SAPI N Reject triggered by RLL establishment failures */
10965 execute( TC_rll_rel_ind_sapi_n_reject() );
10966 execute( TC_rll_err_ind_sapi_n_reject() );
10967 execute( TC_rll_timeout_sapi_n_reject() );
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +070010968 execute( TC_rll_sapi_n_reject_dlci_cc() );
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +070010969
Harald Welte898113b2018-01-31 18:32:21 +010010970 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +010010971 execute( TC_paging_imsi_nochan() );
10972 execute( TC_paging_tmsi_nochan() );
10973 execute( TC_paging_tmsi_any() );
10974 execute( TC_paging_tmsi_sdcch() );
10975 execute( TC_paging_tmsi_tch_f() );
10976 execute( TC_paging_tmsi_tch_hf() );
10977 execute( TC_paging_imsi_nochan_cgi() );
10978 execute( TC_paging_imsi_nochan_lac_ci() );
10979 execute( TC_paging_imsi_nochan_ci() );
10980 execute( TC_paging_imsi_nochan_lai() );
10981 execute( TC_paging_imsi_nochan_lac() );
10982 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +010010983 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
10984 execute( TC_paging_imsi_nochan_rnc() );
10985 execute( TC_paging_imsi_nochan_lac_rnc() );
10986 execute( TC_paging_imsi_nochan_lacs() );
10987 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +010010988 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +010010989 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +010010990 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +010010991 execute( TC_paging_counter() );
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +010010992 execute( TC_paging_resp_unsol() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +010010993
10994 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +010010995 execute( TC_rsl_unknown_unit_id() );
10996
10997 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +010010998
10999 execute( TC_classmark() );
Harald Welteeddf0e92020-06-21 19:42:15 +020011000 execute( TC_common_id() );
Harald Welte898113b2018-01-31 18:32:21 +010011001 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +010011002 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +010011003 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +010011004 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +010011005 execute( TC_err_84_unknown_msg() );
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010011006
Harald Welte261af4b2018-02-12 21:20:39 +010011007 execute( TC_ho_int() );
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +020011008 execute( TC_ho_int_a5_0() );
11009 execute( TC_ho_int_a5_1() );
11010 execute( TC_ho_int_a5_3() );
11011 execute( TC_ho_int_a5_4() );
Neels Hofmeyr5f144212020-11-03 15:41:58 +000011012 execute( TC_ho_int_radio_link_failure() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011013
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +010011014 /* TC_ho_out_of_this_bsc is run last, see comment below */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +020011015 execute( TC_ho_out_fail_no_msc_response() );
11016 execute( TC_ho_out_fail_rr_ho_failure() );
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +020011017 execute( TC_ho_out_fail_no_result_after_ho_cmd() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011018
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010011019 execute( TC_ho_into_this_bsc() );
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +020011020 execute( TC_ho_into_this_bsc_a5_0() );
11021 execute( TC_ho_into_this_bsc_a5_1() );
11022 execute( TC_ho_into_this_bsc_a5_3() );
11023 execute( TC_ho_into_this_bsc_a5_4() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +020011024 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11025 execute( TC_ho_into_this_bsc_tla_v6() );
11026 }
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +020011027 execute( TC_srvcc_eutran_to_geran() );
Pau Espin Pedrol35801c32021-04-19 13:03:20 +020011028 execute( TC_srvcc_eutran_to_geran_ho_out() );
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +020011029 execute( TC_srvcc_eutran_to_geran_forbid_fast_return() );
11030 execute( TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011031 execute( TC_ho_in_fail_msc_clears() );
11032 execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
11033 execute( TC_ho_in_fail_no_detect() );
11034 execute( TC_ho_in_fail_no_detect2() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +010011035
Neels Hofmeyr91401012019-07-11 00:42:35 +020011036 execute( TC_ho_neighbor_config_1() );
11037 execute( TC_ho_neighbor_config_2() );
11038 execute( TC_ho_neighbor_config_3() );
11039 execute( TC_ho_neighbor_config_4() );
11040 execute( TC_ho_neighbor_config_5() );
11041 execute( TC_ho_neighbor_config_6() );
11042 execute( TC_ho_neighbor_config_7() );
11043
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +010011044 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010011045 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +010011046 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +020011047
11048 execute( TC_dyn_pdch_ipa_act_deact() );
11049 execute( TC_dyn_pdch_ipa_act_nack() );
11050 execute( TC_dyn_pdch_osmo_act_deact() );
11051 execute( TC_dyn_pdch_osmo_act_nack() );
Pau Espin Pedrol37a4c152021-11-16 19:02:23 +010011052 execute( TC_dyn_ts_sdcch8_act_deact() );
11053 execute( TC_dyn_ts_sdcch8_all_subslots_used() );
11054 execute( TC_dyn_ts_sdcch8_tch_call_act_deact() );
11055 execute( TC_dyn_ts_sdcch8_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +020011056
Stefan Sperling0796a822018-10-05 13:01:39 +020011057 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +020011058 execute( TC_chopped_ipa_payload() );
Stefan Sperling0796a822018-10-05 13:01:39 +020011059
Pau Espin Pedrol8f773632019-11-05 11:46:53 +010011060 /* Power control related */
11061 execute( TC_assignment_verify_ms_power_params_ie() );
Vadim Yanitskiy4b233042021-06-30 00:58:43 +020011062 execute( TC_c0_power_red_mode() );
Neels Hofmeyr4f118412020-06-04 15:25:10 +020011063
11064 /* MSC pooling */
11065 /* FIXME: in SCCPlite, indicating how many MSCs should be connected does currently not work. Since
11066 * RESET->RESET-ACK is unconditionally negotiated for all configured MSCs, they always all appear as connected
11067 * to osmo-bsc. The MSC pooling tests however require disconnecting selected MSCs, and hence don't work out as
11068 * intended on SCCPlite. So for now, run these only for SCCP/M3UA. */
11069 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11070 execute( TC_mscpool_L3Compl_on_1_msc() );
11071 execute( TC_mscpool_L3Complete_by_imsi_round_robin() );
11072 execute( TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() );
11073 execute( TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() );
11074 execute( TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() );
11075 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() );
11076 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_1() );
11077 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_2() );
11078 execute( TC_mscpool_LU_by_tmsi_from_other_PLMN() );
11079 execute( TC_mscpool_paging_and_response_imsi() );
11080 execute( TC_mscpool_paging_and_response_tmsi() );
11081 execute( TC_mscpool_no_allow_attach_round_robin() );
11082 execute( TC_mscpool_no_allow_attach_valid_nri() );
11083 }
11084
Harald Welte99f3ca02018-06-14 13:40:29 +020011085 execute( TC_early_conn_fail() );
11086 execute( TC_late_conn_fail() );
Oliver Smithaf03bef2021-08-24 15:34:51 +020011087 execute( TC_stats_conn_fail() );
Harald Welte99f3ca02018-06-14 13:40:29 +020011088
Philipp Maier783681c2020-07-16 16:47:06 +020011089 /* Emergency call handling (deny / allow) */
11090 execute( TC_assignment_emerg_setup_allow() );
11091 execute( TC_assignment_emerg_setup_deny_msc() );
11092 execute( TC_assignment_emerg_setup_deny_bts() );
Philipp Maier82812002020-08-13 18:48:27 +020011093 execute( TC_emerg_premption() );
11094
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +070011095 /* Frequency hopping parameters handling */
11096 execute( TC_fh_params_chan_activ() );
11097 execute( TC_fh_params_imm_ass() );
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +070011098 execute( TC_fh_params_assignment_cmd() );
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +070011099 execute( TC_fh_params_handover_cmd() );
Vadim Yanitskiyca974032020-09-01 07:20:39 +070011100 execute( TC_fh_params_si4_cbch() );
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020011101
11102 if (mp_enable_lcs_tests) {
11103 execute( TC_lcs_loc_req_for_active_ms() );
11104 execute( TC_lcs_loc_req_for_active_ms_ta_req() );
11105 execute( TC_lcs_loc_req_for_idle_ms() );
11106 execute( TC_lcs_loc_req_no_subscriber() );
11107 execute( TC_lcs_loc_req_for_active_ms_le_timeout() );
11108 execute( TC_lcs_loc_req_for_active_ms_le_timeout2() );
11109 execute( TC_lcs_loc_req_for_idle_ms_no_pag_resp() );
11110 execute( TC_cm_service_during_lcs_loc_req() );
11111 execute( TC_ho_during_lcs_loc_req() );
11112 }
Neels Hofmeyrbf037052020-10-28 22:52:02 +000011113
11114 execute( TC_no_msc() );
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000011115
11116 execute( TC_refuse_chan_act_to_vamos() );
11117 execute( TC_refuse_mode_modif_to_vamos() );
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000011118
11119 execute( TC_reassignment_fr() );
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020011120
11121 execute( TC_cm_reestablishment() );
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020011122
11123 execute( TC_imm_ass_post_chan_ack() );
11124 execute( TC_imm_ass_pre_chan_ack() );
Neels Hofmeyr23158742021-09-07 19:08:07 +020011125 execute( TC_imm_ass_pre_ts_ack() );
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020011126 execute( TC_imm_ass_pre_chan_ack_dyn_ts() );
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020011127 execute( TC_imm_ass_pre_ts_ack_dyn_ts() );
Neels Hofmeyr5d7d13f2021-09-07 14:44:36 +020011128
11129 execute( TC_ctrl_trx_rf_locked() );
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011130
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011131 execute( TC_ratectr_all_available_allocated() );
11132 execute( TC_ratectr_all_available_allocated_dyn() );
11133
Neels Hofmeyrb7581872021-11-07 14:02:49 +010011134 execute( TC_cm_serv_rej() );
11135
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011136 execute( TC_lost_sdcch_during_assignment() );
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +010011137
11138 /* Run TC_ho_out_of_this_bsc last, because it may trigger a segfault before osmo-bsc's patch
11139 * with change-id I5a3345ab0005a73597f5c27207480912a2f5aae6 */
11140 execute( TC_ho_out_of_this_bsc() );
Harald Welte28d943e2017-11-25 15:00:50 +010011141}
11142
11143}