blob: 907b4362248eff963d64d3ed8f5561401c3cd8c1 [file] [log] [blame]
Harald Welte28d943e2017-11-25 15:00:50 +01001module BSC_Tests {
2
Harald Welte21b46bd2017-12-17 19:46:32 +01003/* Integration Tests for OsmoBSC
Harald Weltea0630032018-03-20 21:09:55 +01004 * (C) 2017-2018 by Harald Welte <laforge@gnumonks.org>
Harald Welte21b46bd2017-12-17 19:46:32 +01005 * All rights reserved.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
Harald Welte34b5a952019-05-27 11:54:11 +020010 * SPDX-License-Identifier: GPL-2.0-or-later
11 *
Harald Welte21b46bd2017-12-17 19:46:32 +010012 * This test suite tests OsmoBSC while emulating both multiple BTS + MS as
13 * well as the MSC. See README for more details.
14 *
15 * There are test cases that run in so-called 'handler mode' and test cases
16 * that run directly on top of the BSSAP and RSL CodecPorts. The "handler mode"
17 * tests abstract the multiplexing/demultiplexing of multiple SCCP connections
18 * and/or RSL channels and are hence suitable for higher-level test cases, while
19 * the "raw" tests directly on top of the CodecPorts are more suitable for lower-
20 * level testing.
21 */
22
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +020023friend module BSC_Tests_VAMOS;
24
Neels Hofmeyr4f118412020-06-04 15:25:10 +020025import from Misc_Helpers all;
Harald Welte4003d112017-12-09 22:35:39 +010026import from General_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010027import from Osmocom_Types all;
Harald Welteae026692017-12-09 01:03:01 +010028import from GSM_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010029import from IPL4asp_Types all;
30
Harald Welte6f521d82017-12-11 19:52:02 +010031import from BSSAP_Types all;
Harald Welte6811d102019-04-14 22:23:14 +020032import from RAN_Adapter all;
Harald Welte47cd0e32020-08-21 12:39:11 +020033import from BSSAP_LE_Adapter all;
34import from BSSAP_LE_CodecPort all;
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020035import from BSSAP_LE_Types all;
36import from BSSLAP_Types all;
Harald Welteae026692017-12-09 01:03:01 +010037import from BSSAP_CodecPort all;
38import from BSSMAP_Templates all;
Harald Welte28d943e2017-11-25 15:00:50 +010039import from IPA_Emulation all;
Stefan Sperling830dc9d2018-02-12 21:08:28 +010040import from IPA_CodecPort all;
Harald Welteae026692017-12-09 01:03:01 +010041import from IPA_Types all;
Stefan Sperling0796a822018-10-05 13:01:39 +020042import from IPA_Testing all;
Harald Welteae026692017-12-09 01:03:01 +010043import from RSL_Types all;
Harald Welte624f9632017-12-16 19:26:04 +010044import from RSL_Emulation all;
Daniel Willmann191e0d92018-01-17 12:44:35 +010045import from MGCP_Emulation all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010046import from MGCP_Templates all;
47import from MGCP_Types all;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +020048import from MGCP_CodecPort all;
Harald Welte28d943e2017-11-25 15:00:50 +010049
Harald Welte96c94412017-12-09 03:12:45 +010050import from Osmocom_CTRL_Functions all;
Harald Weltea5d2ab22017-12-09 14:21:42 +010051import from Osmocom_CTRL_Types all;
Harald Welteffe55fc2018-01-17 22:39:54 +010052import from Osmocom_CTRL_Adapter all;
Harald Welte96c94412017-12-09 03:12:45 +010053
Daniel Willmannebdecc02020-08-12 15:30:17 +020054import from StatsD_Types all;
55import from StatsD_CodecPort all;
56import from StatsD_CodecPort_CtrlFunct all;
57import from StatsD_Checker all;
58
Harald Weltebc03c762018-02-12 18:09:38 +010059import from Osmocom_VTY_Functions all;
60import from TELNETasp_PortType all;
61
Harald Welte6f521d82017-12-11 19:52:02 +010062import from MobileL3_CommonIE_Types all;
Harald Weltee3bd6582018-01-31 22:51:25 +010063import from MobileL3_Types all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010064import from MobileL3_RRM_Types all;
Harald Welte6f521d82017-12-11 19:52:02 +010065import from L3_Templates all;
66import from GSM_RR_Types all;
67
Stefan Sperlingc307e682018-06-14 15:15:46 +020068import from SCCP_Templates all;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010069import from BSSMAP_Templates all;
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020070import from BSSMAP_LE_Templates all;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010071
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010072import from SCCPasp_Types all;
73
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020074import from GSM_SystemInformation all;
75import from GSM_RestOctets all;
Neels Hofmeyrad132f22020-07-08 02:20:16 +020076import from TCCConversion_Functions all;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020077
Neels Hofmeyrbf720202021-10-02 12:58:24 +020078type record of integer integer_list;
79
Harald Welte5d1a2202017-12-13 19:51:29 +010080const integer NUM_BTS := 3;
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +020081const integer NUM_BTS_CFG := 4; /* we have 4 BTS in the osmo-bsc.cfg (for inter-BSC HO tests) but use only 3 */
Neels Hofmeyrf246a922020-05-13 02:27:10 +020082const integer NUM_MSC := 3;
Harald Welteae026692017-12-09 01:03:01 +010083const float T3101_MAX := 12.0;
Harald Welte28d943e2017-11-25 15:00:50 +010084
Harald Welte799c97b2017-12-14 17:50:30 +010085/* make sure to sync this with the osmo-bts.cfg you're using */
Philipp Maiercb6cc482018-03-26 13:08:00 +020086const integer NUM_TCHH_PER_BTS := 2;
87const integer NUM_TCHF_PER_BTS := 4;
Neels Hofmeyr74083c22020-07-29 00:43:01 +020088const integer NUM_SDCCH_PER_BTS := 3;
Harald Welte799c97b2017-12-14 17:50:30 +010089
Neels Hofmeyrbf720202021-10-02 12:58:24 +020090/* Default Training Sequence Code expected for bts[i]:
91 * BTS 0 has BSIC 10 (and no explicit timeslot training_sequence_code config), so expecting TSC = (BSIC & 7) = 2.
92 * BTS 1 has BSIC 11, TSC = (BSIC & 7) = 3.
93 * BTS 2 has BSIC 12, TSC = (BSIC & 7) = 4.
94 * BTS 2 has BSIC 12, TSC = (BSIC & 7) = 4.
95 */
96const integer_list BTS_TSC := {
97 2,
98 3,
99 4,
100 4
101}
Harald Welte4003d112017-12-09 22:35:39 +0100102
Harald Welte21b46bd2017-12-17 19:46:32 +0100103/* per-BTS state which we keep */
Harald Welte96c94412017-12-09 03:12:45 +0100104type record BTS_State {
Harald Welte21b46bd2017-12-17 19:46:32 +0100105 /* component reference to the IPA_Client component used for RSL */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100106 IPA_Client rsl
Harald Welte96c94412017-12-09 03:12:45 +0100107}
108
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200109/* Default list of counters for an 'msc' entity. */
110const CounterNameVals counternames_msc_mscpool := {
111 { "mscpool:subscr:new", 0 },
112 { "mscpool:subscr:known", 0 },
113 { "mscpool:subscr:reattach", 0 },
114 { "mscpool:subscr:attach_lost", 0 },
115 { "mscpool:subscr:paged", 0 }
116};
117
Neels Hofmeyrbf037052020-10-28 22:52:02 +0000118/* List of global mscpool counters, not related to a specific 'msc' entity. */
119const CounterNameVals counternames_bsc_mscpool := {
120 { "mscpool:subscr:no_msc", 0 }
121};
122
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000123/* Default list of counters for 'bsc' and 'bts' entities. */
124const CounterNameVals counternames_bsc_bts_handover := {
125 { "assignment:attempted", 0 },
126 { "assignment:completed", 0 },
127 { "assignment:stopped", 0 },
128 { "assignment:no_channel", 0 },
129 { "assignment:timeout", 0 },
130 { "assignment:failed", 0 },
131 { "assignment:error", 0 },
132
133 { "handover:attempted", 0 },
134 { "handover:completed", 0 },
135 { "handover:stopped", 0 },
136 { "handover:no_channel", 0 },
137 { "handover:timeout", 0 },
138 { "handover:failed", 0 },
139 { "handover:error", 0 },
140
141 { "intra_cell_ho:attempted", 0 },
142 { "intra_cell_ho:completed", 0 },
143 { "intra_cell_ho:stopped", 0 },
144 { "intra_cell_ho:no_channel", 0 },
145 { "intra_cell_ho:timeout", 0 },
146 { "intra_cell_ho:failed", 0 },
147 { "intra_cell_ho:error", 0 },
148
149 { "intra_bsc_ho:attempted", 0 },
150 { "intra_bsc_ho:completed", 0 },
151 { "intra_bsc_ho:stopped", 0 },
152 { "intra_bsc_ho:no_channel", 0 },
153 { "intra_bsc_ho:timeout", 0 },
154 { "intra_bsc_ho:failed", 0 },
155 { "intra_bsc_ho:error", 0 },
156
157 { "interbsc_ho_out:attempted", 0 },
158 { "interbsc_ho_out:completed", 0 },
159 { "interbsc_ho_out:stopped", 0 },
160 { "interbsc_ho_out:timeout", 0 },
161 { "interbsc_ho_out:failed", 0 },
162 { "interbsc_ho_out:error", 0 },
163
164 { "interbsc_ho_in:attempted", 0 },
165 { "interbsc_ho_in:completed", 0 },
166 { "interbsc_ho_in:stopped", 0 },
167 { "interbsc_ho_in:no_channel", 0 },
168 { "interbsc_ho_in:timeout", 0 },
169 { "interbsc_ho_in:failed", 0 },
170 { "interbsc_ho_in:error", 0 }
171};
172
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100173const CounterNameVals counternames_bts_handover := {
174 { "incoming_intra_bsc_ho:attempted", 0 },
175 { "incoming_intra_bsc_ho:completed", 0 },
176 { "incoming_intra_bsc_ho:stopped", 0 },
177 { "incoming_intra_bsc_ho:no_channel", 0 },
178 { "incoming_intra_bsc_ho:timeout", 0 },
179 { "incoming_intra_bsc_ho:failed", 0 },
180 { "incoming_intra_bsc_ho:error", 0 }
181};
182
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200183/* Set of all System Information received during one RSL port's startup.
184 * Note that some System Information may be sent on RSL, but lacking actual SI data, to indicate that the BTS should not
185 * broadcast that SI type. That will be reflected as 'omit' here.
186 */
187type record SystemInformationConfig {
188 SystemInformationType1 si1 optional,
189 SystemInformationType2 si2 optional,
190 SystemInformationType2bis si2bis optional,
191 SystemInformationType2ter si2ter optional,
Neels Hofmeyrad132f22020-07-08 02:20:16 +0200192 SI2quaterRestOctetsList si2quater optional,
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200193 SystemInformationType3 si3 optional,
194 SystemInformationType4 si4 optional,
Pau Espin Pedrol28652d82021-02-09 20:20:17 +0100195 SystemInformationType13 si13 optional,
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200196 SystemInformationType5 si5 optional,
197 SystemInformationType5bis si5bis optional,
198 SystemInformationType5ter si5ter optional,
199 SystemInformationType6 si6 optional
200};
201
202const SystemInformationConfig SystemInformationConfig_omit := {
203 si1 := omit,
204 si2 := omit,
205 si2bis := omit,
206 si2ter := omit,
207 si2quater := omit,
208 si3 := omit,
209 si4 := omit,
210 si13 := omit,
211 si5 := omit,
212 si5bis := omit,
213 si5ter := omit,
214 si6 := omit
215};
216
217/* tr_EUTRAN_CellDesc with defaults used in BSC_Tests.ttcn */
218template EUTRAN_CellDesc tr_EUTRAN_CellDesc_default(template (present) uint16_t e_arfcn := ?,
219 template uint3_t meas_bw := 3)
220:= tr_EUTRAN_CellDesc(e_arfcn := e_arfcn,
221 meas_bw_presence := '1'B,
222 meas_bw := meas_bw);
223
224/* tr_EUTRAN_NeighbourCells with defaults used in BSC_Tests.ttcn */
Harald Welte65e419a2020-08-21 12:38:33 +0200225template EUTRAN_NeighbourCells tr_EUTRAN_NeighbourCells_default(template (present) EUTRAN_CellDescs cell_desc_list := { tr_EUTRAN_CellDesc_default },
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200226 template uint3_t prio := 3,
227 template (present) uint5_t thresh_high := 20,
228 template uint5_t thresh_low := 10,
229 template uint5_t qrxlevmin := 22)
230:= tr_EUTRAN_NeighbourCells(
231 cell_desc_list := cell_desc_list,
232 prio_presence := '1'B,
233 prio := prio,
234 thresh_high := thresh_high,
235 thresh_low_presence := '1'B,
236 thresh_low := thresh_low,
237 qrxlevmin_presence := '1'B,
238 qrxlevmin := qrxlevmin);
239
240template SystemInformationConfig SystemInformationConfig_default := {
241 si1 := {
242 cell_chan_desc := '8FB38000000000000000000000000000'O,
243 rach_control := {
244 max_retrans := RACH_MAX_RETRANS_7,
245 tx_integer := '1001'B,
246 cell_barr_access := false,
247 re_not_allowed := true,
248 acc := '0000010000000000'B
249 },
250 rest_octets := ?
251 },
252 si2 := {
253 bcch_freq_list := '00000000000000000000000000000000'O,
254 ncc_permitted := '11111111'B,
255 rach_control := {
256 max_retrans := RACH_MAX_RETRANS_7,
257 tx_integer := '1001'B,
258 cell_barr_access := false,
259 re_not_allowed := true,
260 acc := '0000010000000000'B
261 }
262 },
263 si2bis := omit,
264 si2ter := {
265 extd_bcch_freq_list := '8E320000000000000000000000000800'O,
266 rest_octets := ?
267 },
268 si2quater := {
269 tr_SI2quaterRestOctets_EUTRAN( repeated_neigh_cells := { tr_EUTRAN_NeighbourCells_default } )
270 },
271 si3 := {
272 cell_id := 0,
273 lai := {
274 mcc_mnc := '001F01'H,
275 lac := 1
276 },
277 ctrl_chan_desc := {
278 msc_r99 := true,
279 att := true,
280 bs_ag_blks_res := 1,
281 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
282 si22ind := false,
283 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
284 spare := '00'B,
285 bs_pa_mfrms := 3,
286 t3212 := 30
287 },
288 cell_options := {
289 dn_ind := false,
290 pwrc := false,
291 dtx := MS_SHALL_USE_UL_DTX,
292 radio_link_tout_div4 := 7
293 },
294 cell_sel_par := {
295 cell_resel_hyst_2dB := 2,
296 ms_txpwr_max_cch := 7,
297 acs := '0'B,
298 neci := true,
299 rxlev_access_min := 0
300 },
301 rach_control := {
302 max_retrans := RACH_MAX_RETRANS_7,
303 tx_integer := '1001'B,
304 cell_barr_access := false,
305 re_not_allowed := true,
306 acc := '0000010000000000'B
307 },
308 rest_octets := {
309 sel_params := {
310 presence := '0'B,
311 params := omit
312 },
313 pwr_offset := {
314 presence := '0'B,
315 offset := omit
316 },
317 si_2ter_ind := '1'B,
318 early_cm_ind := '0'B,
319 sched_where := {
320 presence := '0'B,
321 where := omit
322 },
323 gprs_ind := {
324 presence := '1'B,
325 ind := {
326 ra_colour := 0,
327 si13_pos := '0'B
328 }
329 },
330 umts_early_cm_ind := '1'B,
331 si2_quater_ind := {
332 presence := '1'B,
333 ind := '0'B
334 },
335 iu_mode_ind := omit,
336 si21_ind := {
337 presence := '0'B,
338 pos := omit
339 }
340 }
341 },
342 si4 := {
343 lai := {
344 mcc_mnc := '001F01'H,
345 lac := 1
346 },
347 cell_sel_par := {
348 cell_resel_hyst_2dB := 2,
349 ms_txpwr_max_cch := 7,
350 acs := '0'B,
351 neci := true,
352 rxlev_access_min := 0
353 },
354 rach_control := {
355 max_retrans := RACH_MAX_RETRANS_7,
356 tx_integer := '1001'B,
357 cell_barr_access := false,
358 re_not_allowed := true,
359 acc := '0000010000000000'B
360 },
Neels Hofmeyr74083c22020-07-29 00:43:01 +0200361 cbch_chan_desc := {
362 iei := '64'O,
363 v := {
364 chan_nr := {
365 u := {
366 sdcch4 := {
367 tag := '001'B,
368 sub_chan := 2
369 }
370 },
371 tn := 0
372 },
373 tsc := 2,
374 h := false,
375 arfcn := 871,
376 maio_hsn := omit
377 }
378 },
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200379 cbch_mobile_alloc := omit,
380 rest_octets := {
381 sel_params := {
382 presence := '0'B,
383 params := omit
384 },
385 pwr_offset := {
386 presence := '0'B,
387 offset := omit
388 },
389 gprs_ind := {
390 presence := '1'B,
391 ind := {
392 ra_colour := 0,
393 si13_pos := '0'B
394 }
395 },
396 s_presence := '0'B,
397 s := omit
398 }
399 },
Pau Espin Pedrol28652d82021-02-09 20:20:17 +0100400 si13 := {
401 rest_octets := {
402 presence := '1'B,
403 bcch_change_mark := ?,
404 si_change_field := '0000'B,
405 presence2 := '0'B,
406 si13_change_mark := omit,
407 gprs_ma := omit,
408 zero := '0'B, /* PBCCH not present in cell */
409 rac := 0,
410 spgc_ccch_sup := '0'B,
411 priority_access_thr := '110'B,
412 network_control_order := '00'B,
413 gprs_cell_opts := {
414 nmo := '01'B,
415 t3168 := '011'B,
416 t3192 := '010'B,
417 drx_timer_max := '011'B,
418 access_burst_type := '0'B,
419 control_ack_type := '1'B,
420 bs_cv_max := 15,
421 pan_presence := '1'B,
422 pan_dec := 1,
423 pan_inc := 1,
424 pan_max := '111'B,
425 ext_info_presence := ?,
426 ext_info_length := *,
427 ext_info := *
428 },
429 gprs_pwr_ctrl_params := {
430 alpha := 0,
431 t_avg_w := '10000'B,
432 t_avg_t := '10000'B,
433 pc_meas_chan := '0'B,
434 n_avg_i := '1000'B
435 }
436 }
437 },
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200438 si5 := {
439 bcch_freq_list := '10000000000000000000000000000000'O
440 },
441 si5bis := omit,
442 si5ter := {
443 extd_bcch_freq_list := '9E050020000000000000000000000000'O
444 },
445 si6 := {
446 cell_id := 0,
447 lai := {
448 mcc_mnc := '001F01'H,
449 lac := 1
450 },
451 cell_options := {
452 dtx_ext := '1'B,
453 pwrc := false,
454 dtx := '01'B,
455 radio_link_timeout := '0111'B
456 },
457 ncc_permitted := '11111111'B,
458 rest_octets := ?
459 }
460 };
461
462
463/* List of all the System Information received on all RSL ports */
464type record of SystemInformationConfig SystemInformationConfig_list;
465
466function f_sysinfo_dec_raw(inout SystemInformationConfig si, RSL_Message rsl)
467{
468 var RSL_IE_Body sysinfo_type_ie;
469 var RSL_IE_SysinfoType si_type;
470 var octetstring data;
471
472 if (f_rsl_find_ie(rsl, RSL_IE_SYSINFO_TYPE, sysinfo_type_ie) == false) {
473 setverdict(fail, "Cannot find RSL_IE_SYSINFO_TYPE");
474 mtc.stop;
475 }
476 si_type := sysinfo_type_ie.sysinfo_type;
477
478 if (rsl.msg_type == RSL_MT_BCCH_INFO) {
479 var RSL_IE_Body bcch_ie;
480 if (f_rsl_find_ie(rsl, RSL_IE_FULL_BCCH_INFO, bcch_ie)) {
481 data := bcch_ie.other.payload;
482 }
483 } else if (rsl.msg_type == RSL_MT_SACCH_FILL) {
484 var RSL_IE_Body l3_ie;
485 if (f_rsl_find_ie(rsl, RSL_IE_L3_INFO, l3_ie)) {
486 data := l3_ie.l3_info.payload;
487 }
488 } else {
489 setverdict(fail, "Don't understand this System Information message");
490 mtc.stop;
491 }
492
493 var boolean handled := false;
494
495 if (rsl.msg_type == RSL_MT_BCCH_INFO) {
496 handled := true;
497
498 if (si_type == RSL_SYSTEM_INFO_1) {
499 if (not isbound(data)) {
500 si.si1 := omit;
501 } else {
502 si.si1 := dec_SystemInformation(data).payload.si1;
503 }
504 } else if (si_type == RSL_SYSTEM_INFO_2) {
505 if (not isbound(data)) {
506 si.si2 := omit;
507 } else {
508 si.si2 := dec_SystemInformation(data).payload.si2;
509 }
510 } else if (si_type == RSL_SYSTEM_INFO_2bis) {
511 if (not isbound(data)) {
512 si.si2bis := omit;
513 } else {
514 si.si2bis := dec_SystemInformation(data).payload.si2bis;
515 }
516 } else if (si_type == RSL_SYSTEM_INFO_2ter) {
517 if (not isbound(data)) {
518 si.si2ter := omit;
519 } else {
520 si.si2ter := dec_SystemInformation(data).payload.si2ter;
521 }
522 } else if (si_type == RSL_SYSTEM_INFO_2quater) {
523 if (not isbound(data)) {
524 si.si2quater := {};
525 } else {
526 var SystemInformationType2quater decoded := dec_SystemInformation(data).payload.si2quater;
527 /* this is a *record* of SI2quaterRestOctets! (multiplexed) */
528 si.si2quater[decoded.rest_octets.si2quater_index] := decoded.rest_octets;
529 }
530 } else if (si_type == RSL_SYSTEM_INFO_3) {
531 if (not isbound(data)) {
532 si.si3 := omit;
533 } else {
534 si.si3 := dec_SystemInformation(data).payload.si3;
535 }
536 } else if (si_type == RSL_SYSTEM_INFO_4) {
537 if (not isbound(data)) {
538 si.si4 := omit;
539 } else {
540 si.si4 := dec_SystemInformation(data).payload.si4;
541 }
542 } else if (si_type == RSL_SYSTEM_INFO_13) {
543 if (not isbound(data)) {
544 si.si13 := omit;
545 } else {
Pau Espin Pedrol28652d82021-02-09 20:20:17 +0100546 si.si13 := dec_SystemInformation(data).payload.si13;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200547 }
548 } else {
549 handled := false;
550 }
551 } else if (rsl.msg_type == RSL_MT_SACCH_FILL) {
552 handled := true;
553
554 if (si_type == RSL_SYSTEM_INFO_5) {
555 if (not isbound(data)) {
556 si.si5 := omit;
557 } else {
558 si.si5 := dec_SystemInformation(data).payload.si5;
559 }
560 } else if (si_type == RSL_SYSTEM_INFO_5bis) {
561 if (not isbound(data)) {
562 si.si5bis := omit;
563 } else {
564 si.si5bis := dec_SystemInformation(data).payload.si5bis;
565 }
566 } else if (si_type == RSL_SYSTEM_INFO_5ter) {
567 if (not isbound(data)) {
568 si.si5ter := omit;
569 } else {
570 si.si5ter := dec_SystemInformation(data).payload.si5ter;
571 }
572 } else if (si_type == RSL_SYSTEM_INFO_6) {
573 if (not isbound(data)) {
574 si.si6 := omit;
575 } else {
576 si.si6 := dec_SystemInformation(data).payload.si6;
577 }
578 } else {
579 handled := false;
580 }
581 }
582
583 if (not handled) {
584 setverdict(fail, "Unexpected SI type in ", rsl.msg_type, " message: ", si_type);
585 }
586}
587
Harald Weltea4ca4462018-02-09 00:17:14 +0100588type component test_CT extends CTRL_Adapter_CT {
Harald Welte21b46bd2017-12-17 19:46:32 +0100589 /* Array of per-BTS state */
Harald Welte96c94412017-12-09 03:12:45 +0100590 var BTS_State bts[NUM_BTS];
Harald Welte89ab1912018-02-23 18:56:29 +0100591 /* RSL common Channel Port (for RSL_Emulation) */
592 port RSL_CCHAN_PT RSL_CCHAN[NUM_BTS];
Harald Welte21b46bd2017-12-17 19:46:32 +0100593 /* array of per-BTS RSL test ports */
Harald Welteae026692017-12-09 01:03:01 +0100594 port IPA_RSL_PT IPA_RSL[NUM_BTS];
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100595 port IPA_CODEC_PT IPA; /* Required for compilation of TC_rsl_unknown_unit_id() */
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +0200596 /* CTRL muxed over IPA in SCCPlite conn BSC<->MSC (or BSC-NAT) */
597 port IPA_CTRL_PT SCCPLITE_IPA_CTRL;
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100598 /* Configure/manage IPA_Emulation: */
599 port IPA_CFG_PT IPA_CFG_PORT;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100600
Daniel Willmann191e0d92018-01-17 12:44:35 +0100601 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +0100602 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100603
Daniel Willmannebdecc02020-08-12 15:30:17 +0200604 /* StatsD */
605 var StatsD_Checker_CT vc_STATSD;
606
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200607 var RAN_Adapter g_bssap[NUM_MSC];
Harald Welte47cd0e32020-08-21 12:39:11 +0200608 var BSSAP_LE_Adapter g_bssap_le;
Harald Weltea4ca4462018-02-09 00:17:14 +0100609 /* for old legacy-tests only */
610 port BSSAP_CODEC_PT BSSAP;
Harald Welte47cd0e32020-08-21 12:39:11 +0200611 port BSSAP_LE_CODEC_PT BSSAP_LE;
Harald Weltea4ca4462018-02-09 00:17:14 +0100612
Harald Welte21b46bd2017-12-17 19:46:32 +0100613 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +0100614 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +0100615
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200616 /* Osmux is enabled through VTY */
617 var boolean g_osmux_enabled := false;
618
Pau Espin Pedrolc675b612020-01-09 19:55:40 +0100619 /*Configure T(tias) over VTY, seconds */
620 var integer g_bsc_sccp_timer_ias := 7 * 60;
621 /*Configure T(tiar) over VTY, seconds */
622 var integer g_bsc_sccp_timer_iar := 15 * 60;
623
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +0200624 /* global test case guard timer (actual timeout value is set in f_init()) */
Harald Welteae026692017-12-09 01:03:01 +0100625 timer T_guard := 30.0;
626
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200627 var CounterNameValsList g_ctr_msc;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000628 var CounterNameValsList g_ctr_bsc;
629 var CounterNameValsList g_ctr_bts;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200630
631 /* System Information bytes as received during RSL startup, for each RSL[idx]. */
632 var SystemInformationConfig_list g_system_information := {};
Harald Welte28d943e2017-11-25 15:00:50 +0100633}
634
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200635type record of charstring phys_chan_configs;
Harald Welte28d943e2017-11-25 15:00:50 +0100636modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +0100637 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +0100638 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100639 /* port number to which to establish the IPA OML connections */
640 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +0100641 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +0100642 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +0100643 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +0100644 integer mp_bsc_ctrl_port := 4249;
Daniel Willmannebdecc02020-08-12 15:30:17 +0200645 /* port number to which to listen for STATSD metrics */
646 integer mp_bsc_statsd_port := 8125;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100647 /* IP address at which the test binds */
648 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100649
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200650 RAN_Configurations mp_bssap_cfg := {
651 {
652 transport := BSSAP_TRANSPORT_AoIP,
653 sccp_service_type := "mtp3_itu",
654 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
655 own_pc := 185, /* 0.23.1 first MSC emulation */
656 own_ssn := 254,
657 peer_pc := 187, /* 0.23.3 osmo-bsc */
658 peer_ssn := 254,
659 sio := '83'O,
Harald Weltecb0cc432020-06-21 19:42:31 +0200660 rctx := 1
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200661 },
662 {
663 transport := BSSAP_TRANSPORT_AoIP,
664 sccp_service_type := "mtp3_itu",
665 sctp_addr := { 23906, "127.0.0.1", 2905, "127.0.0.1" },
666 own_pc := 2, /* 0.0.2 second MSC emulation */
667 own_ssn := 254,
668 peer_pc := 187, /* 0.23.3 osmo-bsc */
669 peer_ssn := 254,
670 sio := '83'O,
671 rctx := 2
672 },
673 {
674 transport := BSSAP_TRANSPORT_AoIP,
675 sccp_service_type := "mtp3_itu",
676 sctp_addr := { 23907, "127.0.0.1", 2905, "127.0.0.1" },
677 own_pc := 3, /* 0.0.3 third MSC emulation */
678 own_ssn := 254,
679 peer_pc := 187, /* 0.23.3 osmo-bsc */
680 peer_ssn := 254,
681 sio := '83'O,
682 rctx := 3
683 }
Harald Weltea4ca4462018-02-09 00:17:14 +0100684 };
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +0200685
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200686 /* Must match per BTS config in osmo-bsc.cfg */
687 phys_chan_configs phys_chan_config := {
688 "CCCH+SDCCH4+CBCH",
689 "TCH/F",
690 "TCH/F",
691 "TCH/F",
692 "TCH/F",
Vadim Yanitskiy343c9eb2021-07-16 18:36:01 +0600693 "TCH/H",
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200694 "PDCH",
695 "PDCH"
696 };
697
Harald Welte47cd0e32020-08-21 12:39:11 +0200698 BSSAP_LE_Configuration mp_bssap_le_cfg := {
699 sccp_service_type := "mtp3_itu",
700 sctp_addr := { 23908, "127.0.0.1", 2905, "127.0.0.1" },
Neels Hofmeyrac086c12020-09-18 23:46:42 +0200701 own_pc := 190, /* 0.23.6 SMLC emulation */
Harald Welte47cd0e32020-08-21 12:39:11 +0200702 own_ssn := 252, /* SMLC side SSN */
703 peer_pc := 187, /* 0.23.3 osmo-bsc */
704 peer_ssn := 250, /* BSC side SSN */
705 sio := '83'O,
706 rctx := 6
707 };
Neels Hofmeyrcfe44062020-10-15 02:28:08 +0200708 boolean mp_enable_lcs_tests := true;
Harald Welte47cd0e32020-08-21 12:39:11 +0200709
Pau Espin Pedrol8f30ccd2019-11-01 17:30:57 +0100710 /* Value set in osmo-bsc.cfg "ms max power" */
711 uint8_t mp_exp_ms_power_level := 7;
Vadim Yanitskiy6e068012022-02-05 21:35:43 +0600712
713 /* Whether to check for memory leaks */
714 boolean mp_verify_talloc_count := true;
Harald Weltea4ca4462018-02-09 00:17:14 +0100715}
716
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +0200717friend function f_gen_test_hdlr_pars(integer bssap_idx := 0) return TestHdlrParams {
Philipp Maier48604732018-10-09 15:00:37 +0200718
719 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200720 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier48604732018-10-09 15:00:37 +0200721 pars.aoip := true;
722 } else {
723 pars.aoip := false;
724 }
Pau Espin Pedrol8f30ccd2019-11-01 17:30:57 +0100725 pars.exp_ms_power_level := mp_exp_ms_power_level;
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200726 pars.mscpool.bssap_idx := bssap_idx;
Neels Hofmeyrbf720202021-10-02 12:58:24 +0200727 pars.expect_tsc := BTS_TSC[0];
Vadim Yanitskiy96bb9cb2021-12-10 21:14:15 +0300728 pars.imsi := f_rnd_imsi('00101'H);
729
730 log(testcasename(), ": using IMSI ", pars.imsi);
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200731
Philipp Maier48604732018-10-09 15:00:37 +0200732 return pars;
733}
734
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200735/* Convenience functions for rate counters using g_ctr_msc. */
736
737private function f_ctrs_msc_init(integer mscs_count := NUM_MSC, CounterNameVals counternames := counternames_msc_mscpool) runs on test_CT {
738 g_ctr_msc := f_counter_name_vals_get_n(IPA_CTRL, "msc", mscs_count, counternames);
739 log("initial msc rate counters: ", g_ctr_msc);
740}
741
742private function f_ctrs_msc_add(integer msc_nr, charstring countername, integer val := 1) runs on test_CT {
Neels Hofmeyr9656e922020-06-30 01:27:01 +0200743 f_counter_name_vals_list_add(g_ctr_msc, msc_nr, countername, val);
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200744}
745
746/* f_ctrs_msc_init();
747 * f_do_thing(on_msc := 0);
748 * f_do_thing(on_msc := 0);
749 * f_do_other(on_msc := 1);
750 * f_ctrs_msc_add(0, "thing", 2);
751 * f_ctrs_msc_add(1, "other");
752 * f_ctrs_msc_verify();
753 */
754private function f_ctrs_msc_verify() runs on test_CT {
755 log("verifying msc rate counters: ", g_ctr_msc);
756 f_counter_name_vals_expect_n(IPA_CTRL, "msc", g_ctr_msc);
757}
758
759/* convenience: f_ctrs_msc_add() and f_ctrs_msc_verify() in one call.
760 * f_ctrs_msc_init();
761 * f_do_thing(on_msc := 0);
762 * f_do_thing(on_msc := 0);
763 * f_do_thing(on_msc := 0);
764 * f_ctrs_msc_expect(0, "thing", 3);
765 */
766private function f_ctrs_msc_expect(integer msc_nr, charstring countername, integer val := 1) runs on test_CT {
767 f_ctrs_msc_add(msc_nr, countername, val);
768 f_ctrs_msc_verify();
769}
770
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000771/* Convenience functions for rate counters using g_ctr_bts, always also including g_ctr_bsc. */
772
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100773private function f_ctrs_bts_init(integer bts_count := NUM_BTS, CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000774 g_ctr_bts := f_counter_name_vals_get_n(IPA_CTRL, "bts", bts_count, counternames);
Neels Hofmeyr4dec8cc2021-11-29 15:59:44 +0100775 log("initial bts rate counters: ", g_ctr_bts);
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100776}
777
778function f_ctrs_bsc_and_bts_init(integer bts_count := NUM_BTS, CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
779 f_ctrs_bts_init(bts_count, counternames);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000780 f_ctrs_bsc_init(counternames);
781}
782
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100783private function f_ctrs_bsc_and_bts_handover_init(integer bts_count := NUM_BTS) runs on test_CT {
784 var CounterNameVals bts_names := counternames_bsc_bts_handover & counternames_bts_handover;
Neels Hofmeyr4dec8cc2021-11-29 15:59:44 +0100785 f_ctrs_bts_init(bts_count, bts_names);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100786 f_ctrs_bsc_init(counternames_bsc_bts_handover);
787}
788
789private function f_ctrs_bts_add(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000790 f_counter_name_vals_list_add(g_ctr_bts, bts_nr, countername, val);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100791}
792
793private function f_ctrs_bsc_and_bts_add(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
794 f_ctrs_bts_add(bts_nr, countername, val);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000795 f_ctrs_bsc_add(countername, val);
796}
797
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100798function f_ctrs_bts_verify() runs on test_CT {
799 f_counter_name_vals_expect_n(IPA_CTRL, "bts", g_ctr_bts);
800}
801
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000802/* f_ctrs_bsc_and_bts_init();
803 * f_do_thing(on_bts := 0);
804 * f_do_thing(on_bts := 0);
805 * f_do_other(on_bts := 1);
806 * f_ctrs_bsc_and_bts_add(0, "thing", 2);
807 * f_ctrs_bsc_and_bts_add(1, "other");
808 * f_ctrs_bsc_and_bts_verify();
809 */
810private function f_ctrs_bsc_and_bts_verify() runs on test_CT {
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100811 f_ctrs_bts_verify();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000812 f_ctrs_bsc_verify();
813}
814
815/* convenience: f_ctrs_bsc_and_bts_add() and f_ctrs_bsc_and_bts_verify() in one call.
816 * f_ctrs_bsc_and_bts_init();
817 * f_do_thing(on_bts := 0);
818 * f_do_thing(on_bts := 0);
819 * f_do_thing(on_bts := 0);
820 * f_ctrs_bsc_and_bts_expect(0, "thing", 3);
821 */
822private function f_ctrs_bsc_and_bts_expect(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
823 f_ctrs_bsc_and_bts_add(bts_nr, countername, val);
824 f_ctrs_bsc_and_bts_verify();
825}
826
827
828/* Convenience functions for rate counters using g_ctr_bsc. */
829
830private function f_ctrs_bsc_init(CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
831 g_ctr_bsc := f_counter_name_vals_get_n(IPA_CTRL, "bsc", 1, counternames);
832 log("initial bsc rate counters: ", g_ctr_bsc);
833}
834
835private function f_ctrs_bsc_add(charstring countername, integer val := 1) runs on test_CT {
836 f_counter_name_vals_list_add(g_ctr_bsc, 0, countername, val);
837}
838
839/* f_ctrs_bsc_init();
840 * f_do_thing();
841 * f_do_thing();
842 * f_do_other();
843 * f_ctrs_bsc_add("thing", 2);
844 * f_ctrs_bsc_add("other");
845 * f_ctrs_bsc_verify();
846 */
847private function f_ctrs_bsc_verify() runs on test_CT {
848 f_counter_name_vals_expect_n(IPA_CTRL, "bsc", g_ctr_bsc);
849}
850
851/* convenience: f_ctrs_bsc_add() and f_ctrs_bsc_verify() in one call.
852 * f_ctrs_bsc_init();
853 * f_do_thing();
854 * f_ctrs_bsc_expect("thing", 1);
855 */
856private function f_ctrs_bsc_expect(charstring countername, integer val := 1) runs on test_CT {
857 f_ctrs_bsc_add(countername, val);
858 f_ctrs_bsc_verify();
859}
860
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200861
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +0200862friend function f_shutdown_helper() runs on test_CT {
Neels Hofmeyr18997492021-12-13 17:30:35 +0100863 /* Run the subscr and conn leak test only when the VTY is initialized */
Vadim Yanitskiy6e068012022-02-05 21:35:43 +0600864 if (BSCVTY.checkstate("Mapped") and mp_verify_talloc_count) {
Neels Hofmeyr18997492021-12-13 17:30:35 +0100865 f_verify_talloc_count(BSCVTY, {"struct bsc_subscr", "struct gsm_subscriber_connection"});
866 }
867
Daniel Willmann637ef6c2018-07-25 10:49:09 +0200868 all component.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100869 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200870 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100871}
872
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200873private function f_legacy_bssap_reset(integer bssap_idx := 0) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +0100874 var BSSAP_N_UNITDATA_ind ud_ind;
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200875 var boolean reset_received := false;
Harald Weltea4ca4462018-02-09 00:17:14 +0100876 timer T := 5.0;
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200877 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
878 ts_BSSMAP_Reset(0, g_osmux_enabled)));
Harald Weltea4ca4462018-02-09 00:17:14 +0100879 T.start;
880 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200881 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap[bssap_idx].sccp_addr_own, g_bssap[bssap_idx].sccp_addr_peer,
882 tr_BSSMAP_ResetAck(g_osmux_enabled))) {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200883 log("BSSMAP: Received RESET-ACK in response to RESET, we're ready to go!");
Harald Weltea4ca4462018-02-09 00:17:14 +0100884 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200885 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200886 log("BSSMAP: Respoding to inbound RESET with RESET-ACK");
Harald Weltea4ca4462018-02-09 00:17:14 +0100887 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200888 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200889 reset_received := true;
Harald Weltea4ca4462018-02-09 00:17:14 +0100890 repeat;
891 }
892 [] BSSAP.receive { repeat; }
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200893 [] T.timeout {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200894 log("BSSMAP: Timeout waiting for RESET-ACK after sending RESET");
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200895 /* If we received a RESET after ours was sent, it
896 may be a race condition where the other peer beacame
897 available after we sent it, but we are in a desired
898 state anyway, so go forward. */
899 if (not reset_received) {
900 setverdict(fail);
901 }
902 }
Harald Weltea4ca4462018-02-09 00:17:14 +0100903 }
Harald Welte28d943e2017-11-25 15:00:50 +0100904}
905
Harald Welteae026692017-12-09 01:03:01 +0100906type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100907 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100908 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100909 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100910 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100911 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100912 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100913 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100914 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100915}
916
Harald Welte21b46bd2017-12-17 19:46:32 +0100917/*! Start the IPA/RSL related bits for one IPA_Client.
918 * \param clnt IPA_Client for which to establish
919 * \param bsc_host IP address / hostname of the BSC
920 * \param bsc_port TCP port number of the BSC
921 * \param i number identifying this BTS
922 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100923function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
924 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100925runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100926 timer T := 10.0;
927
Harald Welte96c94412017-12-09 03:12:45 +0100928 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welte71389132021-12-09 21:58:18 +0100929 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA") alive;
Harald Welteae026692017-12-09 01:03:01 +0100930 clnt.ccm_pars := c_IPA_default_ccm_pars;
931 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
932 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100933 if (handler_mode) {
Harald Welte71389132021-12-09 21:58:18 +0100934 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL") alive;
Harald Welte89ab1912018-02-23 18:56:29 +0100935 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100936 }
Harald Welteae026692017-12-09 01:03:01 +0100937
938 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100939 connect(clnt.vc_IPA:CFG_PORT, self:IPA_CFG_PORT);
Harald Welte624f9632017-12-16 19:26:04 +0100940 if (handler_mode) {
941 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
942 } else {
943 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
944 }
Harald Welteae026692017-12-09 01:03:01 +0100945
Harald Welte5d1a2202017-12-13 19:51:29 +0100946 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100947 if (handler_mode) {
948 clnt.vc_RSL.start(RSL_Emulation.main());
949 return;
950 }
Harald Welteae026692017-12-09 01:03:01 +0100951
952 /* wait for IPA RSL link to connect and send ID ACK */
953 T.start;
954 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700955 [] IPA_RSL[i].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) {
Harald Welteae026692017-12-09 01:03:01 +0100956 T.stop;
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +0700957 IPA_RSL[i].send(ts_ASP_RSL_UD(ts_RSL_PAGING_LOAD_IND(23)));
Harald Welteae026692017-12-09 01:03:01 +0100958 }
Harald Welte60e823a2017-12-10 14:10:59 +0100959 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100960 [] IPA_RSL[i].receive { repeat }
961 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100962 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200963 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100964 }
965 }
966}
967
Harald Welte12055472018-03-17 20:10:08 +0100968function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100969 var IPL4asp_Types.Result res := {
970 errorCode := omit,
971 connId := omit,
972 os_error_code := omit,
973 os_error_text := omit
974 };
975
Harald Welte12055472018-03-17 20:10:08 +0100976 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
977 return;
978 }
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +0100979
980 /* Alive components don't finish sockets (TCP FIN) when they are
981 * stopped. Hence, we need to manually call close() on them to make sure
982 * the IUT knows about it. */
983 f_ipa_cfg_disconnect(IPA_CFG_PORT, res);
984
Harald Welte12055472018-03-17 20:10:08 +0100985 clnt.vc_IPA.stop;
986 if (isbound(clnt.vc_RSL)) {
987 clnt.vc_RSL.stop;
988 }
989}
990
Harald Welte21b46bd2017-12-17 19:46:32 +0100991/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100992function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
993 timer T := secs_max;
994 T.start;
995 while (true) {
996 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
997 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100998 /* the 'degraded' state exists from OML connection time, and we have to wait
999 * until all MO's are initialized */
1000 T.start(1.0);
1001 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001002 return;
1003 }
Harald Weltef0d6ac62017-12-17 17:02:21 +01001004 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +01001005 if (not T.running) {
Max99253902018-11-16 17:57:39 +01001006 setverdict(fail, "Timeout waiting for BTS" & int2str(bts_nr) & " oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +02001007 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001008 }
1009 }
1010}
1011
Harald Welte21b46bd2017-12-17 19:46:32 +01001012/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +01001013altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +01001014 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +01001015 [] T_guard.timeout {
1016 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +02001017 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +01001018 }
Harald Welte60e823a2017-12-10 14:10:59 +01001019 /* always respond with RESET ACK to RESET */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001020 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Welte60e823a2017-12-10 14:10:59 +01001021 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001022 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Welte69c1c262017-12-13 21:02:08 +01001023 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +01001024 }
Harald Welte28d943e2017-11-25 15:00:50 +01001025}
1026
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001027altstep no_bssmap_reset() runs on test_CT {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001028 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001029 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +02001030 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001031 }
1032}
1033
Daniel Willmann191e0d92018-01-17 12:44:35 +01001034function f_init_mgcp(charstring id) runs on test_CT {
1035 id := id & "-MGCP";
1036
1037 var MGCPOps ops := {
1038 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
1039 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
1040 };
1041 var MGCP_conn_parameters mgcp_pars := {
1042 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +01001043 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +01001044 mgw_ip := mp_test_ip,
Pau Espin Pedrol1a026a52019-06-18 17:21:52 +02001045 mgw_udp_port := 2427,
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02001046 /* Enable it for SCCPlite, since we have 2 MGCP sockets towards MGW (UDP one +
1047 the on with MGCP over IPA forwarded from MSC one) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001048 multi_conn_mode := (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER)
Daniel Willmann191e0d92018-01-17 12:44:35 +01001049 };
1050
Harald Welte71389132021-12-09 21:58:18 +01001051 vc_MGCP := MGCP_Emulation_CT.create(id) alive;
Daniel Willmann191e0d92018-01-17 12:44:35 +01001052 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
1053}
1054
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001055/* Enable or disable (current default) Osmux. When enabling, BSSMAP Reset
1056 * contains extra IE (OsmuxSupport) and osmo-bsc will handle AssignReq with
1057 * OsmuxCID IE.
1058 */
1059private function f_vty_allow_osmux(boolean allow) runs on test_CT {
1060 f_vty_enter_cfg_msc(BSCVTY, 0);
1061 if (allow) {
1062 f_vty_transceive(BSCVTY, "osmux on");
1063 } else {
1064 f_vty_transceive(BSCVTY, "osmux off");
1065 }
1066 f_vty_transceive(BSCVTY, "exit");
1067 f_vty_transceive(BSCVTY, "exit");
1068 g_osmux_enabled := allow;
1069}
1070
Max2253c0b2018-11-06 19:28:05 +01001071function f_init_vty(charstring id := "foo") runs on test_CT {
Harald Welte94e0c342018-04-07 11:33:23 +02001072 if (BSCVTY.checkstate("Mapped")) {
1073 /* skip initialization if already executed once */
1074 return;
1075 }
Harald Weltebc03c762018-02-12 18:09:38 +01001076 map(self:BSCVTY, system:BSCVTY);
1077 f_vty_set_prompts(BSCVTY);
1078 f_vty_transceive(BSCVTY, "enable");
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01001079 f_cs7_inst_0_cfg(BSCVTY, {"sccp-timer ias " & int2str(g_bsc_sccp_timer_ias),
1080 "sccp-timer iar " & int2str(g_bsc_sccp_timer_iar)});
Harald Weltebc03c762018-02-12 18:09:38 +01001081}
1082
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +02001083friend function f_logp(TELNETasp_PT pt, charstring log_msg)
Neels Hofmeyr4f118412020-06-04 15:25:10 +02001084{
1085 // log on TTCN3 log output
1086 log(log_msg);
1087 // log in stderr log
Neels Hofmeyr8bdafe52021-12-14 17:25:48 +01001088 if (pt.checkstate("Mapped")) {
1089 f_vty_transceive(pt, "logp lglobal notice TTCN3 f_logp(): " & log_msg);
1090 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02001091}
1092
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001093private function f_sysinfo_seen(integer rsl_idx, RSL_Message rsl) runs on test_CT
1094{
1095 if (rsl_idx >= lengthof(g_system_information)) {
1096 g_system_information[rsl_idx] := SystemInformationConfig_omit
1097 }
1098 f_sysinfo_dec_raw(g_system_information[rsl_idx], rsl);
1099}
1100
1101altstep as_catch_RSL_sysinfo(integer rsl_idx) runs on test_CT {
1102 var ASP_RSL_Unitdata rx_rsl_ud;
1103
1104 /* For handler_mode := false, receiving the RSL bootstrap messages directly on IPA_RSL */
1105 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
1106 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1107 repeat;
1108 }
1109 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
1110 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1111 repeat;
1112 }
1113 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> value rx_rsl_ud {
1114 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1115 repeat;
1116 }
1117 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_SACCH_FILL)) -> value rx_rsl_ud {
1118 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1119 repeat;
1120 }
1121
1122 /* For handler_mode := true, receiving the RSL bootstrap messages via RSL_Emulation */
1123 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
1124 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1125 repeat;
1126 }
1127 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
1128 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1129 repeat;
1130 }
1131 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> value rx_rsl_ud {
1132 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1133 repeat;
1134 }
1135 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_SACCH_FILL)) -> value rx_rsl_ud {
1136 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1137 repeat;
1138 }
1139}
1140
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001141/* TODO: use BooleanList from COMMON/src/General_Types.ttcn */
1142private type record of boolean my_BooleanList;
1143
1144private function f_vty_msc_allow_attach(TELNETasp_PT pt, my_BooleanList allow_attach_list)
1145{
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001146 var charstring config := f_vty_transceive_ret(pt, "show running-config");
1147
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001148 for (var integer msc_nr := 0; msc_nr < sizeof(allow_attach_list); msc_nr := msc_nr+1) {
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001149 if (f_strstr(config, "\nmsc " & int2str(msc_nr) & "\n") < 0) {
1150 /* There is no 'msc N' for this msc_nr in the running config, so don't create an empty msc by
1151 * stepping into that config node. */
1152 log("msc ", msc_nr, " is not configured, skipping");
1153 continue;
1154 }
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001155 f_vty_enter_cfg_msc(pt, msc_nr);
1156 if (allow_attach_list[msc_nr]) {
1157 /* strict := false: ignore if osmo-bsc does not support this config option (latest build) */
1158 f_vty_transceive(pt, "allow-attach", strict := false);
1159 } else {
1160 f_vty_transceive(pt, "no allow-attach", strict := false);
1161 }
1162 f_vty_transceive(pt, "exit");
1163 f_vty_transceive(pt, "exit");
1164 }
1165}
1166
Harald Welte21b46bd2017-12-17 19:46:32 +01001167/* global initialization function
1168 * \param nr_bts Number of BTSs we should start/bring up
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001169 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false).
1170 * \param nr_msc Number of virtual MSCs to bring up to connect to osmo-bsc.
1171 */
1172function f_init(integer nr_bts := NUM_BTS, boolean handler_mode := false, boolean allow_osmux := false,
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001173 integer nr_msc := 1, float guard_timeout := 30.0) runs on test_CT {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001174 var integer bssap_idx;
Harald Welte28d943e2017-11-25 15:00:50 +01001175
Harald Welteae026692017-12-09 01:03:01 +01001176 if (g_initialized) {
1177 return;
Harald Welte28d943e2017-11-25 15:00:50 +01001178 }
Harald Welteae026692017-12-09 01:03:01 +01001179 g_initialized := true;
1180
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001181 T_guard.start(guard_timeout);
Daniel Willmanne68f9272018-11-27 15:15:28 +01001182 activate(as_Tguard());
1183
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001184 f_init_vty("VirtMSC");
Pau Espin Pedrol23510fb2021-07-20 17:00:38 +02001185 f_vty_allow_osmux(allow_osmux);
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001186
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001187 var my_BooleanList allow_attach := { false, false, false };
Daniel Willmannebdecc02020-08-12 15:30:17 +02001188 f_init_statsd("VirtMSC", vc_STATSD, mp_test_ip, mp_bsc_statsd_port);
1189
Neels Hofmeyr9db8e0e2021-08-23 20:45:58 +02001190 /* Make sure each MSC's internal state is "DISCONNECTED" at first */
1191 for (bssap_idx := 0; bssap_idx < NUM_MSC; bssap_idx := bssap_idx+1) {
1192 f_vty_transceive(BSCVTY, "msc " & int2str(bssap_idx) & " bssmap reset", strict := false);
1193 }
1194
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001195 for (bssap_idx := 0; bssap_idx < nr_msc; bssap_idx := bssap_idx+1) {
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001196 allow_attach[bssap_idx] := true;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001197 /* Call a function of our 'parent component' RAN_Adapter_CT to start the
1198 * MSC-side BSSAP emulation */
1199 if (handler_mode) {
1200 var RanOps ranops := MSC_RanOps;
1201 ranops.use_osmux := g_osmux_enabled;
1202 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", ranops);
1203 connect(self:SCCPLITE_IPA_CTRL, g_bssap[bssap_idx].vc_RAN:CTRL_CLIENT);
1204 f_ran_adapter_start(g_bssap[bssap_idx]);
1205 } else {
1206 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", omit);
1207 connect(self:BSSAP, g_bssap[bssap_idx].vc_SCCP:SCCP_SP_PORT);
1208 f_ran_adapter_start(g_bssap[bssap_idx]);
1209 f_legacy_bssap_reset();
1210 }
Harald Welte67089ee2018-01-17 22:19:03 +01001211 }
Harald Welted5833a82018-05-27 16:52:56 +02001212
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02001213 if (mp_enable_lcs_tests) {
1214 if (handler_mode) {
1215 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", SMLC_BssapLeOps);
1216 } else {
1217 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", omit);
1218 connect(self:BSSAP_LE, g_bssap_le.vc_SCCP:SCCP_SP_PORT);
1219 }
1220 f_bssap_le_adapter_start(g_bssap_le);
Harald Welte47cd0e32020-08-21 12:39:11 +02001221 }
Harald Welte47cd0e32020-08-21 12:39:11 +02001222
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001223 /* start the test with exactly all enabled MSCs allowed to attach */
1224 f_vty_msc_allow_attach(BSCVTY, allow_attach);
1225
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01001226 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +01001227
Daniel Willmann191e0d92018-01-17 12:44:35 +01001228 f_init_mgcp("VirtMSC");
1229
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001230 for (var integer i := 0; i < nr_bts; i := i+1) {
1231 f_init_bts(i, handler_mode);
Harald Welte696ddb62017-12-08 14:01:43 +01001232 }
Neels Hofmeyr9c0f9c82022-01-23 01:20:28 +01001233
1234 /* Emit a marker to appear in the SUT's own logging output */
1235 f_logp(BSCVTY, testcasename() & "() start");
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001236}
Harald Welte696ddb62017-12-08 14:01:43 +01001237
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001238function f_init_bts(integer bts_idx := 0, boolean handler_mode := false)
1239runs on test_CT {
1240 /* wait until osmo-bts-omldummy has respawned */
1241 f_wait_oml(bts_idx, "degraded", 5.0);
1242
1243 /* start RSL connection */
1244 f_ipa_rsl_start(bts[bts_idx].rsl, mp_bsc_ip, mp_bsc_rsl_port, bts_idx, handler_mode);
1245 /* wait until BSC tells us "connected" */
1246 f_wait_oml(bts_idx, "connected", 5.0);
Harald Welte28d943e2017-11-25 15:00:50 +01001247}
1248
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001249function f_init_bts_and_check_sysinfo(integer bts_idx := 0, boolean handler_mode := false,
1250 template SystemInformationConfig expect_si)
1251runs on test_CT {
1252 var default sysinfo := activate(as_catch_RSL_sysinfo(bts_idx));
1253
1254 f_init_bts(bts_idx, handler_mode);
1255
1256 /* Give some time to (hopefully/most likely) collect all system informations from RSL startup.
1257 * We could stop as soon as all expected SI are received, but then we might miss SI that we don't expect and
1258 * that might be sent afterwards. So rather give a generous timeout and be quite sure to catch all SI.
1259 */
1260 f_sleep(5.0);
1261 log("RSL ", bts_idx, " SYSTEM INFORMATION: ", g_system_information[bts_idx]);
1262
1263 deactivate(sysinfo);
1264
1265 if (match(g_system_information[bts_idx], expect_si)) {
1266 setverdict(pass);
1267 } else {
1268 log("RSL ", bts_idx, ": EXPECTED SI: ", expect_si);
1269 log("RSL ", bts_idx, ": GOT SI: ", g_system_information[bts_idx]);
1270 setverdict(fail, "received SI does not match expectations");
1271 return;
1272 }
1273}
1274
Maxd4e56962018-10-31 19:08:25 +01001275/* expect to receive a RSL message matching a specified template on a given BTS / stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001276function f_exp_ipa_rx(integer bts_nr, template (present) RSL_Message t_rx, float t_secs := 2.0, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
Harald Welteae026692017-12-09 01:03:01 +01001277runs on test_CT return RSL_Message {
1278 var ASP_RSL_Unitdata rx_rsl_ud;
1279 timer T := t_secs;
1280
1281 T.start;
1282 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001283 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
Harald Welteae026692017-12-09 01:03:01 +01001284 T.stop;
1285 }
1286 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +01001287 [] T.timeout {
1288 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +02001289 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +01001290 }
Harald Welteae026692017-12-09 01:03:01 +01001291 }
1292 return rx_rsl_ud.rsl;
1293}
1294
Harald Welte21b46bd2017-12-17 19:46:32 +01001295/* helper function to transmit RSL on a given BTS/stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001296function f_ipa_tx(integer bts_nr, template (value) RSL_Message t_tx, IpaStreamId sid := IPAC_PROTO_RSL_TRX0)
Harald Welteae026692017-12-09 01:03:01 +01001297runs on test_CT {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001298 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(t_tx, sid));
Harald Welteae026692017-12-09 01:03:01 +01001299}
1300
1301
Harald Welte4003d112017-12-09 22:35:39 +01001302/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +01001303testcase TC_chan_act_noreply() runs on test_CT {
1304 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +01001305 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +01001306
Harald Welte89d42e82017-12-17 16:42:41 +01001307 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +01001308
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001309 IPA_RSL[0].send(ts_ASP_RSL_UD(ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +01001310 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001311 f_shutdown_helper();
Harald Welte28d943e2017-11-25 15:00:50 +01001312}
1313
Neels Hofmeyr734b1a32021-11-29 16:00:17 +01001314const CounterNameVals counternames_bts_chreq := {
1315 { "chreq:total", 0 },
1316 { "chreq:attempted_emerg", 0 },
1317 { "chreq:attempted_call", 0 },
1318 { "chreq:attempted_location_upd", 0 },
1319 { "chreq:attempted_pag", 0 },
1320 { "chreq:attempted_pdch", 0 },
1321 { "chreq:attempted_other", 0 },
1322 { "chreq:attempted_unknown", 0 },
1323 { "chreq:successful", 0 },
1324 { "chreq:successful_emerg", 0 },
1325 { "chreq:successful_call", 0 },
1326 { "chreq:successful_location_upd", 0 },
1327 { "chreq:successful_pag", 0 },
1328 { "chreq:successful_pdch", 0 },
1329 { "chreq:successful_other", 0 },
1330 { "chreq:successful_unknown", 0 },
1331 { "chreq:no_channel", 0 },
1332 { "chreq:max_delay_exceeded", 0 }
1333};
1334
1335/* verify the "chreq:*" counters */
1336private function f_chan_act_counter(OCT1 ra, charstring chreq_ctr_suffix) runs on test_CT
1337{
1338 var GsmFrameNumber fn := 23;
1339
1340 f_logp(BSCVTY, "f_chan_act_counter(" & chreq_ctr_suffix & ")");
1341
1342 var RSL_Message rx_rsl;
1343 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1344 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1345 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1346
1347 f_ctrs_bts_add(0, "chreq:total");
1348 f_ctrs_bts_add(0, "chreq:attempted_" & chreq_ctr_suffix);
1349 f_ctrs_bts_verify();
1350
1351 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
1352 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
1353
1354 f_ctrs_bts_add(0, "chreq:successful");
1355 f_ctrs_bts_add(0, "chreq:successful_" & chreq_ctr_suffix);
1356 f_ctrs_bts_verify();
1357
1358 /* test is done, release RSL Conn Fail Ind to clean up */
1359 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1360 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1361 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
1362 f_sleep(1.0);
1363}
1364
Harald Welte4003d112017-12-09 22:35:39 +01001365testcase TC_chan_act_counter() runs on test_CT {
1366 var BSSAP_N_UNITDATA_ind ud_ind;
1367 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +01001368 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +01001369
Harald Welte89d42e82017-12-17 16:42:41 +01001370 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001371
Neels Hofmeyr734b1a32021-11-29 16:00:17 +01001372 f_vty_allow_emerg_bts(true, 0);
1373
1374 f_ctrs_bts_init(1, counternames_bts_chreq);
1375
1376 /* emergency call: RA & 0xe0 == 0xa0 --> CHREQ_T_EMERG_CALL */
1377 f_chan_act_counter('a3'O, "emerg");
1378
1379 /* voice TCH/H: RA & 0xf0 == 0x40 --> CHREQ_T_VOICE_CALL_TCH_H */
1380 f_chan_act_counter('43'O, "call");
1381
1382 /* LU: RA & 0xf0 == 0x00 --> CHREQ_T_LOCATION_UPD */
1383 f_chan_act_counter('03'O, "location_upd");
1384
1385 /* Paging: RA & 0xf0 == 0x20 --> CHREQ_T_PAG_R_TCH_F */
1386 f_chan_act_counter('23'O, "pag");
1387 /* Paging: RA & 0xf0 == 0x30 --> CHREQ_T_PAG_R_TCH_FH */
1388 f_chan_act_counter('33'O, "pag");
1389
1390 /* LU: RA & 0xfc == 0x78 --> CHREQ_T_PDCH_TWO_PHASE */
1391 /* no PCU, so PDCH not allowed. Skip this test for now. */
1392 /* f_chan_act_counter('7b'O, "pdch"); */
1393
1394 /* LU: RA & 0xf0 == 0x10 --> CHREQ_T_SDCCH */
1395 f_chan_act_counter('13'O, "other");
Harald Welte4003d112017-12-09 22:35:39 +01001396
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001397 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001398}
1399
Harald Welteae026692017-12-09 01:03:01 +01001400/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
Philipp Maier9c60a622020-07-09 15:08:46 +02001401private function f_TC_chan_act_ack_noest(OCT1 ra := '23'O) runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +01001402 var RSL_Message rx_rsl;
1403
Harald Welteae026692017-12-09 01:03:01 +01001404 /* Send CHAN RQD and wait for allocation; acknowledge it */
Philipp Maier9c60a622020-07-09 15:08:46 +02001405 var RslChannelNr chan_nr := f_chreq_act_ack(ra);
Harald Welteae026692017-12-09 01:03:01 +01001406
1407 /* expect BSC to disable the channel again if there's no RLL EST IND */
1408 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1409
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001410 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001411}
1412
Philipp Maier9c60a622020-07-09 15:08:46 +02001413/* Normal variant */
1414testcase TC_chan_act_ack_noest() runs on test_CT {
Philipp Maieraf58db22020-08-12 17:24:40 +02001415 f_init(1);
Philipp Maier9c60a622020-07-09 15:08:46 +02001416 f_TC_chan_act_ack_noest();
1417}
1418
1419/* Emergency call variant */
1420testcase TC_chan_act_ack_noest_emerg() runs on test_CT {
1421 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
Philipp Maieraf58db22020-08-12 17:24:40 +02001422 f_init(1);
1423 f_vty_allow_emerg_bts(true, 0);
Philipp Maier9c60a622020-07-09 15:08:46 +02001424 f_TC_chan_act_ack_noest(ra := 'A5'O);
1425}
1426
Philipp Maier606f07d2020-08-12 17:21:58 +02001427/* Emergency call variant, but emergency calls are not allowed */
1428testcase TC_chan_rqd_emerg_deny() runs on test_CT {
1429 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
1430
1431 var RSL_Message rx_rsl;
1432 var GsmRrMessage rr;
1433
1434 f_init(1);
1435 f_vty_allow_emerg_bts(false, 0);
1436
1437 IPA_RSL[0].clear;
1438 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
1439
1440 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
1441 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
1442 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1443 setverdict(pass);
1444 } else {
1445 setverdict(fail, "immediate assignment not rejected");
1446 }
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01001447
1448 f_shutdown_helper();
Philipp Maier606f07d2020-08-12 17:21:58 +02001449}
1450
Harald Welteae026692017-12-09 01:03:01 +01001451/* Test behavior if MSC never answers to CR */
1452testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +01001453 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
1454 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +01001455 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +01001456 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +01001457
Harald Welte89d42e82017-12-17 16:42:41 +01001458 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001459
1460 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001461 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001462
1463 var octetstring l3 := '00010203040506'O
1464 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1465
1466 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
1467
1468 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +01001469 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001470 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001471 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001472}
1473
1474/* Test behavior if MSC answers with CREF to CR */
1475testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
1476 var BSSAP_N_CONNECT_ind rx_c_ind;
1477 var RSL_Message rx_rsl;
1478
Harald Welte89d42e82017-12-17 16:42:41 +01001479 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001480
1481 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001482 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001483
1484 var octetstring l3 := '00010203040506'O
1485 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1486
1487 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1488 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
1489
1490 /* expect BSC to disable the channel */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001491 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001492 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001493}
1494
Harald Welte618ef642017-12-14 14:58:20 +01001495/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
1496testcase TC_chan_act_nack() runs on test_CT {
1497 var RSL_Message rx_rsl;
1498 var integer chact_nack;
1499
Harald Welte89d42e82017-12-17 16:42:41 +01001500 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +01001501
1502 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
1503
1504 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
1505 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1506 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1507
1508 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
1509
1510 /* wait for some time to hope the NACK arrives before the CTRL GET below */
1511 f_sleep(0.5);
1512
1513 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
1514
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001515 f_shutdown_helper();
Harald Welte618ef642017-12-14 14:58:20 +01001516}
1517
Harald Welte799c97b2017-12-14 17:50:30 +01001518/* Test for channel exhaustion due to RACH overload */
1519testcase TC_chan_exhaustion() runs on test_CT {
1520 var ASP_RSL_Unitdata rsl_ud;
1521 var integer i;
1522 var integer chreq_total, chreq_nochan;
1523
Harald Welte89d42e82017-12-17 16:42:41 +01001524 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +01001525
1526 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
1527 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
1528
Neels Hofmeyr85fa37f2021-10-06 13:50:38 +02001529 /* GSM 44.018 Table 9.1.8.2:
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +01001530 * RA = '33'O -> Establishment cause = 0011xxxx (MS dual rate capable and asks for "TCH/H or TCH/F").
1531 * With current setup, expect 4xSDCCH + 4xTCH/F + 1xTCH/H to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +02001532 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS; i := i+1) {
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +01001533 var RslChannelNr chan_nr := f_chreq_act_ack('33'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +01001534 }
1535
1536 IPA_RSL[0].clear;
1537
Harald Weltedd8cbf32018-01-28 12:07:52 +01001538 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001539 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +01001540
1541 /* now expect additional channel activations to fail */
1542 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
1543
1544 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001545 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
Harald Welte799c97b2017-12-14 17:50:30 +01001546 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
1547 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001548 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
Harald Welte799c97b2017-12-14 17:50:30 +01001549 var GsmRrMessage rr;
1550 /* match on IMM ASS REJ */
1551 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
1552 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1553 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001554 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +01001555 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
1556 chreq_nochan+1);
1557 setverdict(pass);
1558 } else {
1559 repeat;
1560 }
1561 }
1562 [] IPA_RSL[0].receive { repeat; }
1563 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001564 f_shutdown_helper();
Harald Welte799c97b2017-12-14 17:50:30 +01001565}
1566
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001567/* Test channel deactivation due to silence from MS */
1568testcase TC_chan_deact_silence() runs on test_CT {
1569 var RslChannelNr chan_nr;
1570
1571 f_init(1);
1572
1573 /* Request for a dedicated channel */
1574 chan_nr := f_chreq_act_ack('23'O);
1575
1576 /* Wait some time until the channel is released */
1577 f_sleep(2.0);
1578
1579 /* Expect CHANnel RELease */
1580 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001581 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001582 log("Received CHANnel RELease");
1583 setverdict(pass);
1584 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001585 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001586 /* See OS#3709, OsmoBSC should not send Immediate
1587 * Assignment Reject since a dedicated channel was
1588 * already allocated, and Immediate Assignment was
1589 * already sent. */
1590 setverdict(fail, "Unexpected Immediate Assignment!");
1591 }
1592 [] IPA_RSL[0].receive {
1593 setverdict(fail, "Unexpected RSL message!");
1594 }
1595 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001596 f_shutdown_helper();
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001597}
1598
Harald Weltecfe2c962017-12-15 12:09:32 +01001599/***********************************************************************
1600 * Assignment Testing
1601 ***********************************************************************/
1602
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001603/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction,
1604 * except for the inter-BSC handover, MT side) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001605testcase TC_outbound_connect(integer bssap_idx := 0) runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +01001606 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +01001607
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001608 BSSAP.send(ts_BSSAP_CONNECT_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
1609 2342, ts_BSSMAP_AssignmentReq));
Harald Weltecfe2c962017-12-15 12:09:32 +01001610 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001611 f_shutdown_helper();
Harald Weltecfe2c962017-12-15 12:09:32 +01001612}
1613
Harald Welte16a4adf2017-12-14 18:54:01 +01001614/* Test behavior if MSC answers with CREF to CR */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001615testcase TC_assignment_cic_only(integer bssap_idx := 0) runs on test_CT {
Harald Welte16a4adf2017-12-14 18:54:01 +01001616 var BSSAP_N_CONNECT_ind rx_c_ind;
1617 var RSL_Message rx_rsl;
1618 var DchanTuple dt;
1619
Harald Welte89d42e82017-12-17 16:42:41 +01001620 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +01001621
1622 dt := f_est_dchan('23'O, 23, '00000000'O);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001623 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte17b27da2018-05-25 20:33:53 +02001624 /* send assignment without AoIP IEs */
1625 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
1626 } else {
1627 /* Send assignmetn without CIC in IPA case */
1628 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
1629 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
1630 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
1631 }
Harald Welte16a4adf2017-12-14 18:54:01 +01001632 alt {
1633 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1634 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
1635 }
Harald Welte235ebf12017-12-15 14:18:16 +01001636 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +01001637 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1638 setverdict(pass);
1639 }
1640 [] BSSAP.receive { repeat; }
1641 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001642 f_perform_clear_test_ct(dt);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001643 f_shutdown_helper();
Harald Welte16a4adf2017-12-14 18:54:01 +01001644}
1645
Harald Welteed848512018-05-24 22:27:58 +02001646/* generate an assignment request for either AoIP or SCCPlite */
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001647function f_gen_ass_req(boolean osmux_enabled := false, integer bssap_idx := 0, charstring aoip_tla := "1.2.3.4") return PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +02001648 var PDU_BSSAP ass_cmd;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001649 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001650 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welteed848512018-05-24 22:27:58 +02001651 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001652 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001653 if (osmux_enabled) {
1654 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla, osmux_cid));
1655 } else {
1656 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
1657 }
Harald Welteed848512018-05-24 22:27:58 +02001658 } else {
1659 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001660 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
Harald Welteed848512018-05-24 22:27:58 +02001661 }
1662 return ass_cmd;
1663}
1664
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02001665function f_gen_handover_req(integer bssap_idx := 0, charstring aoip_tla := "1.2.3.4",
Pau Espin Pedrola8ef3be2022-02-16 16:21:17 +01001666 template (value) BSSMAP_IE_CellIdentifier cell_id_source := ts_CellID_LAC_CI(1, 1),
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001667 template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit,
1668 template (omit) TestHdlrEncrParams enc := omit) return PDU_BSSAP {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001669 var PDU_BSSAP ho_req;
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001670
1671 var BSSMAP_IE_EncryptionInformation encryptionInformation :=
1672 valueof(ts_BSSMAP_IE_EncrInfo('0000000000000000'O,'01'O));
1673 var template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm := omit;
1674 var template BSSMAP_IE_KC128 kc128 := omit;
1675 if (ispresent(enc)) {
1676 var TestHdlrEncrParams v_enc := valueof(enc);
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01001677 encryptionInformation := valueof(ts_BSSMAP_IE_EncrInfo(v_enc.enc_key, v_enc.enc_alg_permitted));
1678 if (ispresent(v_enc.enc_alg_chosen)) {
1679 chosenEncryptionAlgorithm := valueof(
1680 ts_BSSMAP_IE_ChosenEncryptionAlgorithm(int2oct(enum2int(
1681 f_cipher_mode_bssmap_to_rsl(v_enc.enc_alg_chosen)), 1)));
1682 }
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001683 if (ispresent(v_enc.enc_kc128)) {
1684 kc128 := ts_BSSMAP_IE_Kc128(v_enc.enc_kc128);
1685 }
1686 }
1687
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001688 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001689 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001690 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Pau Espin Pedrola8ef3be2022-02-16 16:21:17 +01001691 ho_req := valueof(ts_BSSMAP_HandoverRequest(omit, tla,
1692 cell_id_source := cell_id_source,
1693 oldToNewBSSIEs := oldToNewBSSIEs,
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001694 encryptionInformation := encryptionInformation,
1695 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
1696 kC128 := kc128));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001697 } else {
1698 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrola8ef3be2022-02-16 16:21:17 +01001699 ho_req := valueof(ts_BSSMAP_HandoverRequest(cic, omit,
1700 cell_id_source := cell_id_source,
1701 oldToNewBSSIEs := oldToNewBSSIEs,
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001702 encryptionInformation := encryptionInformation,
1703 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
1704 kC128 := kc128));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001705 }
1706 return ho_req;
1707}
1708
Harald Welteed848512018-05-24 22:27:58 +02001709/* generate an assignment complete template for either AoIP or SCCPlite */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001710function f_gen_exp_compl(boolean expect_osmux := false, integer bssap_idx := 0) return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +02001711 var template PDU_BSSAP exp_compl;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001712 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001713 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001714 if (expect_osmux) {
1715 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, osmux_cid);
1716 } else {
1717 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, omit);
1718 }
Harald Welteed848512018-05-24 22:27:58 +02001719 } else {
1720 /* CIC is optional "*" as the MSC allocated it */
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001721 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
Harald Welteed848512018-05-24 22:27:58 +02001722 }
1723 return exp_compl;
1724}
1725
Harald Welte235ebf12017-12-15 14:18:16 +01001726/* Run everything required up to sending a caller-specified assignment command and expect response */
1727function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001728runs on test_CT return DchanTuple {
Harald Welte235ebf12017-12-15 14:18:16 +01001729 var BSSAP_N_CONNECT_ind rx_c_ind;
1730 var RSL_Message rx_rsl;
1731 var DchanTuple dt;
1732
Harald Welte89d42e82017-12-17 16:42:41 +01001733 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +01001734
1735 dt := f_est_dchan('23'O, 23, '00000000'O);
1736 /* send assignment without AoIP IEs */
1737 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
1738 alt {
1739 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1740 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
1741 setverdict(pass);
1742 } else {
1743 setverdict(fail, fail_text);
1744 }
1745 }
1746 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1747 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
1748 setverdict(pass);
1749 } else {
1750 setverdict(fail, fail_text);
1751 }
1752 }
1753 [] BSSAP.receive { repeat; }
1754 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001755 return dt;
Harald Welte235ebf12017-12-15 14:18:16 +01001756}
1757testcase TC_assignment_csd() runs on test_CT {
1758 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001759 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001760 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1761 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001762 var DchanTuple dt := f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
1763 f_perform_clear_test_ct(dt);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001764 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001765}
1766
1767testcase TC_assignment_ctm() runs on test_CT {
1768 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001769 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001770 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
1771 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01001772 var DchanTuple dt := f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
1773 f_perform_clear_test_ct(dt);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001774 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001775}
1776
Harald Welte4003d112017-12-09 22:35:39 +01001777type record DchanTuple {
1778 integer sccp_conn_id,
1779 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +01001780}
1781
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +02001782type record of DchanTuple DchanTuples;
1783
Harald Welted6939652017-12-13 21:02:46 +01001784/* Send CHAN RQD and wait for allocation; acknowledge it */
1785private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
1786runs on test_CT return RslChannelNr {
1787 var RSL_Message rx_rsl;
1788 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1789 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1790 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1791 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
Daniel Willmannf4ac4ce2018-08-02 14:06:30 +02001792 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Harald Welted6939652017-12-13 21:02:46 +01001793 return chan_nr;
1794}
1795
Harald Welte4003d112017-12-09 22:35:39 +01001796/* helper function to establish a dedicated channel via BTS and MSC */
1797function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1798runs on test_CT return DchanTuple {
1799 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +01001800 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001801
Harald Welte4003d112017-12-09 22:35:39 +01001802 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001803 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +01001804
1805 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1806
1807 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1808 dt.sccp_conn_id := rx_c_ind.connectionId;
1809 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1810
1811 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001812}
1813
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02001814/* Like f_est_dchan(), but for the first lchan of a dynamic timeslot: first ACK the deactivation of PDCH. */
1815function f_est_dchan_dyn(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1816runs on test_CT return DchanTuple {
1817 var BSSAP_N_CONNECT_ind rx_c_ind;
1818 var DchanTuple dt;
1819
1820 /* Send CHAN RQD */
1821 var RSL_Message rx_rsl;
1822 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1823
1824 /* The dyn TS first deactivates PDCH */
1825 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1826 dt.rsl_chan_nr := rx_rsl.ies[0].body.chan_nr;
1827 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1828
1829 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1830 dt.rsl_chan_nr := rx_rsl.ies[0].body.chan_nr;
1831
1832 /* Now activates the signalling channel */
1833 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, fn+10));
1834 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
1835
1836 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1837
1838 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1839 dt.sccp_conn_id := rx_c_ind.connectionId;
1840 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1841
1842 return dt;
1843}
1844
Harald Welte641fcbe2018-06-14 10:58:35 +02001845/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
1846private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
1847 var RSL_Message rx_rsl;
1848 /* expect BSC to disable the channel */
1849 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1850 /* respond with CHAN REL ACK */
1851 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1852
1853 /* expect Clear Complete from BSC */
1854 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1855
1856 /* MSC disconnects as instructed. */
1857 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1858}
1859
Harald Welte4003d112017-12-09 22:35:39 +01001860/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
1861testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001862 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001863 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +01001864
Harald Welte89d42e82017-12-17 16:42:41 +01001865 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +01001866
Harald Welte4003d112017-12-09 22:35:39 +01001867 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1868
1869 /* simulate RLL REL IND */
1870 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
1871
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001872 /* expect Clear Request on MSC side */
1873 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1874
1875 /* Instruct BSC to clear channel */
1876 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1877 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1878
Harald Welte4003d112017-12-09 22:35:39 +01001879 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001880 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001881
1882 /* wait for SCCP emulation to do its job */
1883 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +01001884
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001885 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001886}
1887
1888/* Test behavior of channel release after CONN FAIL IND from BTS */
1889testcase TC_chan_rel_conn_fail() runs on test_CT {
1890 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001891 var DchanTuple dt;
1892
Harald Welte89d42e82017-12-17 16:42:41 +01001893 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001894
1895 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1896
1897 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +01001898 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 +01001899 /* TODO: different cause values? */
1900
Harald Welte4003d112017-12-09 22:35:39 +01001901 /* expect Clear Request from BSC */
1902 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1903
1904 /* Instruct BSC to clear channel */
1905 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1906 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1907
Harald Welte6ff76ea2018-01-28 13:08:01 +01001908 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001909 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +01001910
1911 /* wait for SCCP emulation to do its job */
1912 f_sleep(1.0);
1913
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001914 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001915}
1916
Harald Welte99f3ca02018-06-14 13:40:29 +02001917/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
1918/* See also https://www.osmocom.org/issues/3182 */
1919testcase TC_early_conn_fail() runs on test_CT {
1920 var RSL_Message rx_rsl;
1921 var DchanTuple dt;
1922
1923 f_init(1);
1924
1925 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
Harald Weltec46ea3c2020-10-10 18:46:12 +02001926 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_ra_cs(), 23);
Harald Welte99f3ca02018-06-14 13:40:29 +02001927
1928 /* BTS->BSC: simulate CONN FAIL IND */
1929 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1930
1931 /* BTS->BSC: Expect RF channel release from BSC on Abis */
1932 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1933
1934 /* BTS<-BSC: respond with CHAN REL ACK */
1935 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1936
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001937 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001938}
1939
1940/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
1941/* See also https://www.osmocom.org/issues/3182 */
1942testcase TC_late_conn_fail() runs on test_CT {
1943 var RSL_Message rx_rsl;
1944 var DchanTuple dt;
1945
1946 f_init(1);
1947
1948 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1949
1950 /* BSC<-MSC: Instruct BSC to clear connection */
1951 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
1952
1953 /* BTS->BSC: expect BSC to deactivate SACCH */
1954 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
1955
1956 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
1957 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1958
1959 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
1960 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1961 /* BTS->BSC: respond with CHAN REL ACK */
1962 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1963
1964 /* BSC->MSC: expect Clear Complete from BSC */
1965 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1966
1967 /* BSC<-MSC: MSC disconnects as requested. */
1968 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1969
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001970 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001971}
1972
Oliver Smithaf03bef2021-08-24 15:34:51 +02001973private function f_TC_stats_conn_fail(charstring id) runs on MSC_ConnHdlr {
1974 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
1975 var PDU_BSSAP ass_cmd := f_gen_ass_req();
1976
1977 f_statsd_reset();
1978
1979 /* Establish SDCCH */
1980 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1981 f_establish_fully(ass_cmd, exp_fail);
1982
1983 /* Expect stats to be 0 */
1984 var StatsDExpects expect := {
1985 {name := "TTCN3.bts.0.chan.rf_fail", mtype := "c", min := 0, max := 0},
1986 {name := "TTCN3.bts.0.chan.rf_fail_sdcch", mtype := "c", min := 0, max := 0}
1987 };
1988 f_statsd_expect(expect);
1989
1990 /* Simulate CONN FAIL IND on SDCCH */
1991 RSL.send(ts_ASP_RSL_UD(
1992 ts_RSL_CONN_FAIL_IND(g_chan_nr, RSL_ERR_RADIO_LINK_FAIL),
1993 IPAC_PROTO_RSL_TRX0));
1994
Neels Hofmeyr58be48a2021-09-07 18:39:21 +02001995 f_sleep(1.0);
1996
Oliver Smithaf03bef2021-08-24 15:34:51 +02001997 /* Expect stats to be 1 */
1998 expect := {
1999 {name := "TTCN3.bts.0.chan.rf_fail", mtype := "c", min := 1, max := 1},
2000 {name := "TTCN3.bts.0.chan.rf_fail_sdcch", mtype := "c", min := 1, max := 1}
2001 };
2002 f_statsd_expect(expect);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01002003 BSSAP.receive(tr_BSSMAP_ClearRequest);
2004 f_perform_clear();
Oliver Smithaf03bef2021-08-24 15:34:51 +02002005}
2006testcase TC_stats_conn_fail() runs on test_CT {
2007 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2008 var MSC_ConnHdlr vc_conn;
2009
2010 f_init(1, true);
2011 f_sleep(1.0);
2012
2013 vc_conn := f_start_handler(refers(f_TC_stats_conn_fail), pars);
2014 vc_conn.done;
2015
2016 f_shutdown_helper();
2017}
2018
Neels Hofmeyrf44ccd12018-11-05 19:15:23 +01002019function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr,
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002020 boolean expect_deact_sacch := true,
2021 boolean expect_rr_chan_rel := true,
2022 boolean expect_rll_rel_req := true,
Harald Welte99787102019-02-04 10:41:36 +01002023 boolean handle_rll_rel := true,
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002024 template CellSelIndValue expect_cells := omit,
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002025 template RR_Cause expect_rr_cause := ?
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002026 ) runs on test_CT {
Harald Welte91d54a52018-01-28 15:35:07 +01002027
2028 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002029 var boolean got_deact_sacch := false;
2030 var boolean got_rr_chan_rel := false;
2031 var boolean got_rll_rel_req := false;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002032 var ASP_RSL_Unitdata ud;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002033 var RSL_IE_Body l3_ie;
2034 var PDU_ML3_NW_MS l3;
2035 var RR_Cause got_cause;
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002036 log("f_expect_chan_rel() expecting: expect_deact_sacch=", expect_deact_sacch, " expect_rr_chan_rel=", expect_rr_chan_rel,
2037 " expect_rll_rel_req=", expect_rll_rel_req);
Harald Welte91d54a52018-01-28 15:35:07 +01002038 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002039 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002040 got_deact_sacch := true;
Harald Welte91d54a52018-01-28 15:35:07 +01002041 repeat;
2042 }
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002043 [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 +01002044 got_rr_chan_rel := true;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002045
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002046 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
2047 setverdict(fail, "cannot find L3");
2048 mtc.stop;
2049 }
2050 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
2051
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002052 if (not istemplatekind(expect_cells, "omit")) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002053 var CellSelIndValue cells := dec_CellSelIndValue(
2054 l3.msgs.rrm.channelRelease.cellSelectionIndicator.cellSelectionIndicatorValue);
2055
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002056 log("GOT RR CHANNEL RELEASE WITH CELLS: ", cells);
2057 if (match(cells, expect_cells)) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002058 setverdict(pass);
2059 } else {
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002060 log("EXPECTED CELLS: ", expect_cells);
2061 setverdict(fail, "Received cells list on RR Channel Release does not match expectations");
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002062 }
2063 }
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002064
2065 if (not istemplatekind(expect_rr_cause, "omit")) {
2066 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
2067 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
2068 if (match(got_cause, expect_rr_cause)) {
2069 setverdict(pass);
2070 } else {
2071 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
2072 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
2073 }
2074 }
Harald Welte99787102019-02-04 10:41:36 +01002075 repeat;
2076 }
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002077 [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 +01002078 got_rr_chan_rel := true;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002079
2080 if (not istemplatekind(expect_rr_cause, "omit")) {
2081 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
2082 setverdict(fail, "cannot find L3");
2083 mtc.stop;
2084 }
2085 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
2086
2087 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
2088 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
2089 if (match(got_cause, expect_rr_cause)) {
2090 setverdict(pass);
2091 } else {
2092 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
2093 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
2094 }
2095 }
Neels Hofmeyr211169d2018-11-07 00:37:29 +01002096 repeat;
2097 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002098 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002099 got_rll_rel_req := true;
Harald Welte91d54a52018-01-28 15:35:07 +01002100 /* FIXME: Why are we getting this for LinkID SACCH? */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002101 if (handle_rll_rel) {
2102 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
2103 }
Harald Welte91d54a52018-01-28 15:35:07 +01002104 repeat;
2105 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002106 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Harald Welte91d54a52018-01-28 15:35:07 +01002107 /* respond with CHAN REL ACK */
2108 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
2109 }
2110 /* ignore any user data */
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002111 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeR(?))) {
Harald Welte91d54a52018-01-28 15:35:07 +01002112 repeat;
2113 }
2114 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002115
2116 log("f_expect_chan_rel() summary: got_deact_sacch=", got_deact_sacch, " got_rr_chan_rel=", got_rr_chan_rel,
2117 " got_rll_rel_req=", got_rll_rel_req);
2118
2119 if (expect_deact_sacch != got_deact_sacch) {
2120 setverdict(fail, "f_expect_chan_rel(): expect_deact_sacch=", expect_deact_sacch, " got_deact_sacch=", got_deact_sacch);
2121 }
2122 if (expect_rr_chan_rel != got_rr_chan_rel) {
2123 setverdict(fail, "f_expect_chan_rel(): expect_rr_chan_rel=", expect_rr_chan_rel, " got_rr_chan_rel=", got_rr_chan_rel);
2124 }
2125 if (expect_rll_rel_req != got_rll_rel_req) {
2126 setverdict(fail, "f_expect_chan_rel(): expect_rll_rel_req=", expect_rll_rel_req, " got_rll_rel_req=", got_rll_rel_req);
2127 }
Harald Welte91d54a52018-01-28 15:35:07 +01002128}
2129
Harald Welte4003d112017-12-09 22:35:39 +01002130/* Test behavior of channel release after hard Clear Command from MSC */
2131testcase TC_chan_rel_hard_clear() runs on test_CT {
2132 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01002133 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +01002134
Harald Welte89d42e82017-12-17 16:42:41 +01002135 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002136
2137 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2138
2139 /* Instruct BSC to clear channel */
2140 var BssmapCause cause := 0;
2141 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2142
2143 /* expect Clear Complete from BSC on A */
2144 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2145 /* release the SCCP connection */
2146 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2147 }
2148
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002149 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002150 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002151}
2152
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002153function f_TC_chan_rel_last_eutran_plmn_hard_clear(boolean tx_csfb_ind) runs on test_CT {
2154 var BSSAP_N_DATA_ind rx_di;
2155 var DchanTuple dt;
2156
2157 f_init(1);
2158
2159 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2160 /* Send CommonID with some random PLMN (BSC doesn't take it into account
2161 /* yet when generating the EUTRAN neigh list in RR CHannel Release) */
2162 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
2163
2164 /* Instruct BSC to clear channel */
2165 var BssmapCause cause := 0;
2166 if (tx_csfb_ind) {
2167 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2168 } else {
2169 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2170 }
2171
2172 /* expect Clear Complete from BSC on A */
2173 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2174 /* release the SCCP connection */
2175 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2176 }
2177
2178 /* 1 neighbor is added by default in osmo-bts.cfg and
2179 SystemInformationConfig_default, use that: */
2180 var template CellSelIndValue exp_cells := f_tr_rr_chan_rel_earfcns(1);
2181
2182 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, expect_cells := exp_cells);
2183 f_shutdown_helper();
2184}
2185
2186/* Test behavior of RR Channel rRelease after Clear Command without CSFB indicator
2187 from MSC, previously receiving any CommonID containing the "Last Used E-UTRAN
2188 PLMN Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
2189 EUTRAN neighbor list sent later on by BSC in RR Channel, so receiving CSFB
2190 Indicator or not shouldn't matter at all. */
2191testcase TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() runs on test_CT {
2192 f_TC_chan_rel_last_eutran_plmn_hard_clear(false);
2193}
2194
2195/* Test behavior of RR Channel rRelease after Clear Command with CSFB indicator from
2196 MSC, previously receiving any CommonID containing the "Last Used E-UTRAN PLMN
2197 Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
2198 EUTRAN neighbor list sent later on by BSC in RR Channel. */
2199testcase TC_chan_rel_last_eutran_plmn_hard_clear_csfb() runs on test_CT {
2200 f_TC_chan_rel_last_eutran_plmn_hard_clear(true);
2201}
2202
2203/* Test behavior of RR Channel Release after Clear Command with CSFB indicator from
2204 MSC, without receiving any CommonID containing the "Last Used E-UTRAN PLMN
2205 Id". According to spec (TS 48.008 version 16.0.0 Release 16 "3.2.1.21") the
2206 CSFB Indicator should not be used anymore, and hence, there should be no
2207 EUTRAN neighbor list sent by BSC in RR Channel release since no CommonId with
2208 Last Used E-UTRAN PLMN Id" IE was sent for this conn. */
Harald Welte99787102019-02-04 10:41:36 +01002209testcase TC_chan_rel_hard_clear_csfb() runs on test_CT {
2210 var BSSAP_N_DATA_ind rx_di;
2211 var DchanTuple dt;
2212
2213 f_init(1);
2214
2215 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2216
2217 /* Instruct BSC to clear channel */
2218 var BssmapCause cause := 0;
2219 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2220
2221 /* expect Clear Complete from BSC on A */
2222 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2223 /* release the SCCP connection */
2224 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2225 }
2226
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002227 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002228 f_shutdown_helper();
Harald Welte99787102019-02-04 10:41:36 +01002229}
2230
Harald Welted8c36cd2017-12-09 23:05:31 +01002231/* Test behavior of channel release after hard RLSD from MSC */
2232testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +01002233 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +01002234
Harald Welte89d42e82017-12-17 16:42:41 +01002235 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +01002236
2237 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2238
2239 /* release the SCCP connection */
2240 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2241
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002242 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002243 f_shutdown_helper();
Harald Welted8c36cd2017-12-09 23:05:31 +01002244}
2245
Harald Welte550daf92018-06-11 19:22:13 +02002246/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
2247testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
2248 var DchanTuple dt;
2249
2250 f_init(1);
2251
2252 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2253
2254 /* release the SCCP connection */
2255 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2256
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002257 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002258 f_shutdown_helper();
Harald Welte550daf92018-06-11 19:22:13 +02002259}
2260
Harald Welte85804d42017-12-10 14:11:58 +01002261/* Test behavior of channel release after BSSMAP RESET from MSC */
2262testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +01002263 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +01002264
Harald Welte89d42e82017-12-17 16:42:41 +01002265 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +01002266
2267 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2268
2269 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
2270 IPA_RSL[0].clear;
2271
2272 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002273 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 +01002274 interleave {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002275 [] 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 +01002276 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
2277 }
2278
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002279 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002280 f_shutdown_helper();
Harald Welte85804d42017-12-10 14:11:58 +01002281}
2282
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002283/* Verify T(iar) triggers and releases the channel */
2284testcase TC_chan_rel_sccp_tiar_timeout() runs on test_CT {
2285 var DchanTuple dt;
2286
2287 /* Set T(iar) in BSC low enough that it will trigger before other side
2288 has time to keep alive with a T(ias). Keep recommended ratio of
2289 T(iar) >= T(ias)*2 */
2290 g_bsc_sccp_timer_ias := 2;
2291 g_bsc_sccp_timer_iar := 5;
2292
2293 f_init(1);
2294
2295 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2296 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002297 f_shutdown_helper();
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002298}
2299
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002300private function f_tc_chan_rel_rr_cause(myBSSMAP_Cause clear_cmd_cause, template RR_Cause expect_rr_cause)
2301runs on test_CT
2302{
2303 var DchanTuple dt;
2304
2305 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2306 var BssmapCause cause := 0;
2307 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(enum2int(clear_cmd_cause))));
2308 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2309 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2310 }
2311
2312 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 +02002313}
2314
2315/* Test that Clear Command cause codes affect the RR Channel Release cause code */
2316testcase TC_chan_rel_rr_cause() runs on test_CT {
2317 f_init(1);
2318
2319 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_CALL_CONTROL, GSM48_RR_CAUSE_NORMAL);
2320 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_HANDOVER_SUCCESSFUL, GSM48_RR_CAUSE_NORMAL);
2321 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_PREEMPTION, GSM48_RR_CAUSE_PREMPTIVE_REL);
2322 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE, GSM48_RR_CAUSE_PROT_ERROR_UNSPC);
2323 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
2324 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_EQUIPMENT_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
Vadim Yanitskiye18aebb2021-01-03 13:10:43 +01002325
2326 f_shutdown_helper();
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002327}
2328
Harald Welte5cd20ed2017-12-13 21:03:20 +01002329/* Test behavior if RSL EST IND for non-active channel */
2330testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
2331 timer T := 2.0;
2332
Harald Welte89d42e82017-12-17 16:42:41 +01002333 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002334
2335 var octetstring l3 := '00010203040506'O;
2336 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2337 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
2338
2339 T.start;
2340 alt {
2341 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2342 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
2343 }
2344 [] BSSAP.receive {}
2345 [] IPA_RSL[0].receive {}
2346 [] T.timeout {}
2347 }
2348
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002349 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002350}
2351
2352/* Test behavior if RSL EST IND for invalid SAPI */
2353testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
2354 var RslChannelNr chan_nr;
2355
Harald Welte89d42e82017-12-17 16:42:41 +01002356 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002357
2358 chan_nr := f_chreq_act_ack()
2359
2360 var octetstring l3 := '00010203040506'O;
2361 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
2362
2363 timer T := 2.0;
2364 T.start;
2365 alt {
2366 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2367 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
2368 }
2369 [] BSSAP.receive { repeat; }
2370 [] IPA_RSL[0].receive { repeat; }
2371 [] T.timeout {}
2372 }
2373
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002374 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002375}
2376
2377/* Test behavior if RSL EST IND for invalid SAPI */
2378testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
2379 timer T := 2.0;
2380
Harald Welte89d42e82017-12-17 16:42:41 +01002381 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002382
2383 var RslChannelNr chan_nr := f_chreq_act_ack();
2384
2385 var octetstring l3 := '00010203040506'O;
2386 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
2387
2388 T.start;
2389 alt {
2390 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2391 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
2392 }
2393 [] BSSAP.receive { repeat; }
2394 [] IPA_RSL[0].receive { repeat; }
2395 [] T.timeout {}
2396 }
2397
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002398 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002399}
2400
2401/* Test behavior if RSL EST IND for invalid SACCH */
2402testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
2403 timer T := 2.0;
2404
Harald Welte89d42e82017-12-17 16:42:41 +01002405 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002406
2407 var RslChannelNr chan_nr := f_chreq_act_ack();
2408
2409 var octetstring l3 := '00010203040506'O;
2410 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
2411
2412 T.start;
2413 alt {
2414 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2415 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
2416 }
2417 [] BSSAP.receive { repeat; }
2418 [] IPA_RSL[0].receive { repeat; }
2419 [] T.timeout {}
2420 }
2421
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002422 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002423}
2424
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002425/* Verify DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
2426private function f_TC_tch_dlci_link_id_sapi(charstring id) runs on MSC_ConnHdlr {
2427 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2428 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2429
2430 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2431 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2432
2433 f_establish_fully(ass_cmd, exp_compl);
2434
2435 /* SAPI0 has already been established by f_establish_fully(), establish SAPI3 */
2436 RSL.send(ts_RSL_EST_IND(g_chan_nr, ts_RslLinkID_SACCH(3), '0904'O));
2437 /* Expect BSSAP/DTAP on SAPI3 (DLCI IE) */
2438 BSSAP.receive(PDU_BSSAP:{
2439 discriminator := '1'B,
2440 spare := '0000000'B,
2441 dlci := 'C3'O,
2442 lengthIndicator := ?,
2443 pdu := { dtap := '0904'O }
2444 });
2445
2446 /* Send messages on DCCH/SAPI0 and ACCH/SAPI3 */
2447 for (var integer i := 0; i < 32; i := i + 1) {
2448 var octetstring l3 := '09'O & f_rnd_octstring(14);
2449 var template (value) RslLinkId link_id;
2450 var template (value) OCT1 dlci;
2451
2452 if (i mod 2 == 0) {
2453 /* SAPI0 on FACCH or SDCCH */
2454 link_id := ts_RslLinkID_DCCH(0);
2455 dlci := '80'O;
2456 } else {
2457 /* SAPI3 on SACCH */
2458 link_id := ts_RslLinkID_SACCH(3);
2459 dlci := 'C3'O;
2460 }
2461
2462 /* Send MO message: RSL -> BSSAP */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002463 f_mo_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002464 /* Send MT message: BSSAP -> RSL */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002465 f_mt_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002466 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01002467 f_perform_clear();
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002468}
2469testcase TC_tch_dlci_link_id_sapi() runs on test_CT {
2470 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2471 var MSC_ConnHdlr vc_conn;
2472
2473 f_init(1, true);
2474 f_sleep(1.0);
2475
2476 vc_conn := f_start_handler(refers(f_TC_tch_dlci_link_id_sapi), pars);
2477 vc_conn.done;
2478
2479 f_shutdown_helper();
2480}
2481
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002482private function f_exp_sapi_n_reject(template (present) GsmSapi sapi := ?,
2483 template myBSSMAP_Cause cause := ?,
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002484 template (present) BIT2 cc := ?,
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002485 float T_val := 2.0)
2486runs on test_CT {
2487 var BSSAP_N_DATA_ind rx_di;
2488 timer T;
2489
2490 var template BSSMAP_IE_Cause tr_cause := tr_BSSMAP_IE_Cause(cause);
2491 var template PDU_BSSAP tr_pdu := tr_BSSMAP_SAPInReject(sapi);
2492
2493 T.start(T_val);
2494 alt {
2495 [] BSSAP.receive(tr_BSSAP_DATA_ind(?, tr_pdu)) -> value rx_di {
2496 var BSSMAP_IE_Cause rx_cause := rx_di.userData.pdu.bssmap.sAPInReject.cause;
2497 if (not match(rx_cause, tr_cause)) {
2498 setverdict(fail, "Rx unexpected Cause IE: ",
2499 rx_cause, " vs expected ", tr_cause);
2500 }
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002501
2502 /* Who ever on the earth decided to define this field as two separate bits?!? */
2503 var BIT2 rx_cc := rx_di.userData.pdu.bssmap.sAPInReject.dLCI.c2
2504 & rx_di.userData.pdu.bssmap.sAPInReject.dLCI.c1;
2505 if (not match(rx_cc, cc)) {
2506 setverdict(fail, "Rx unexpected Control Channel type: ",
2507 rx_cc, " vs expected ", cc);
2508 }
2509
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002510 setverdict(pass);
2511 }
2512 [] BSSAP.receive(BSSAP_N_DATA_ind:?) -> value rx_di {
2513 setverdict(fail, "Rx unexpected BSSAP PDU: ", rx_di);
2514 }
2515 [] T.timeout {
2516 setverdict(fail, "Timeout waiting for BSSMAP SAPI N Reject");
2517 }
2518 }
2519}
2520
2521/* Check if we get SAPI N Reject on receipt of unexpected RLL RELease INDication */
2522testcase TC_rll_rel_ind_sapi_n_reject() runs on test_CT {
2523 var octetstring rnd_data := f_rnd_octstring(16);
2524 var RSL_Message rx_rsl;
2525 var DchanTuple dt;
2526
2527 f_init(1);
2528
2529 /* MS establishes a SAPI=0 link on DCCH */
2530 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2531
2532 /* MSC sends some data on (not yet established) SAPI=3 link */
2533 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2534 /* BSC attempts to establish a SAPI=3 link on DCCH */
2535 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2536
2537 /* MS sends unexpected RELease INDication on SAPI=3 */
2538 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3)));
2539 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2540 f_exp_sapi_n_reject(3, GSM0808_CAUSE_MS_NOT_EQUIPPED);
2541
2542 /* Clean up the connection */
2543 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2544 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2545
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002546 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002547}
2548
2549/* Check if we get SAPI N Reject on receipt of unexpected RLL ERROR INDication */
2550testcase TC_rll_err_ind_sapi_n_reject() runs on test_CT {
2551 var octetstring rnd_data := f_rnd_octstring(16);
2552 var RSL_Message rx_rsl;
2553 var DchanTuple dt;
2554
2555 f_init(1);
2556
2557 /* MS establishes a SAPI=0 link on DCCH */
2558 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2559
2560 /* MSC sends some data on (not yet established) SAPI=3 link */
2561 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2562 /* BSC attempts to establish a SAPI=3 link on DCCH */
2563 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2564
2565 /* BTS sends unexpected ERROR INDication on SAPI=3 */
2566 f_ipa_tx(0, ts_RSL_ERROR_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3), ''O));
2567 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2568 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED);
2569
2570 /* Clean up the connection */
2571 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2572 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2573
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002574 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002575}
2576
2577/* Check if we get SAPI N Reject due to a SAPI=3 link establishment timeout */
2578testcase TC_rll_timeout_sapi_n_reject() runs on test_CT {
2579 var octetstring rnd_data := f_rnd_octstring(16);
2580 var RSL_Message rx_rsl;
2581 var DchanTuple dt;
2582
2583 f_init(1);
2584
2585 /* MS establishes a SAPI=0 link on DCCH */
2586 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2587
2588 /* MSC sends some data on (not yet established) SAPI=3 link */
2589 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2590 /* BSC attempts to establish a SAPI=3 link on DCCH */
2591 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2592
2593 /* MS does not respond, so the link establishment timeout triggers SAPI N Reject */
2594 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED, T_val := 8.0);
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
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002600 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002601}
2602
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002603/* Check DLCI CC (Control Channel type) bits in SAPI N Reject */
2604testcase TC_rll_sapi_n_reject_dlci_cc() runs on test_CT {
2605 var octetstring rnd_data := f_rnd_octstring(16);
2606 var RSL_Message rx_rsl;
2607 var DchanTuple dt;
2608
2609 f_init(1);
2610
2611 /* MS establishes a SAPI=0 link on DCCH */
2612 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2613
2614 /* MSC sends some data on (not yet established) SAPI=3 link */
2615 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2616 /* BSC attempts to establish a SAPI=3 link on DCCH */
2617 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2618
2619 /* MS sends unexpected ERROR INDication on DCCH/ACCH SAPI=3 */
2620 f_ipa_tx(0, ts_RSL_ERROR_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3), ''O));
Pau Espin Pedrol121f27f2022-01-12 12:02:10 +01002621 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED, '10'B);
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +07002622
2623 /* Clean up the connection */
2624 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2625 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2626
2627 f_shutdown_helper();
2628}
2629
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002630testcase TC_si_default() runs on test_CT {
2631 f_init(0);
2632 f_init_bts_and_check_sysinfo(0, expect_si := SystemInformationConfig_default);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002633 f_shutdown_helper();
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002634}
Harald Welte4003d112017-12-09 22:35:39 +01002635
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002636/* We're testing SI2quater with lists of EARFCNs. Instead of just incrementing EARFCNs, also pick some from the edges of
2637 * the entire value range. This function provides the same EARFCN numbers for the same earfcn_index */
2638private function f_test_si2quater_earfcn_by_idx(integer earfcn_index) return uint16_t
2639{
2640 select (earfcn_index) {
2641 case (0) {
2642 /* E-ARFCN 111 is already added in the osmo-bsc.cfg */
2643 return 111;
2644 }
2645 case (1) {
2646 return 1;
2647 }
2648 case (2) {
2649 return 0;
2650 }
2651 case (3) {
2652 return 65535;
2653 }
2654 case else {
2655 return 23 * (earfcn_index - 3);
2656 }
2657 }
2658}
2659
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002660function f_test_si2quater(integer total_earfcns, template SystemInformationConfig expect_si,
2661 template CellSelIndValue expect_cells := omit) runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002662
2663 f_init(0);
2664
2665 /* E-ARFCN 111 is already added in the osmo-bsc.cfg, so only add more arfcns if total_earfcns > 1 */
2666 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002667 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2668 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002669 }
2670
2671 f_init_bts_and_check_sysinfo(0, expect_si := expect_si);
2672
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002673 if (not istemplatekind(expect_cells, "omit")) {
2674 /* Also check that RR Channel Release contains these EARFCNs.
2675 * (copied code from TC_chan_rel_hard_clear_csfb) */
2676 var BSSAP_N_DATA_ind rx_di;
2677 var DchanTuple dt;
2678
2679 dt := f_est_dchan('23'O, 23, '00010203040506'O);
Pau Espin Pedrold0046312021-04-19 16:35:58 +02002680 /* Send CommonID with some random PLMN (BSC doesn't take it into account
2681 * yet when generating the EUTRAN neigh list in RR CHannel Release) */
2682 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002683
2684 /* Instruct BSC to clear channel */
2685 var BssmapCause cause := 0;
2686 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2687
2688 /* expect Clear Complete from BSC on A */
2689 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2690 /* release the SCCP connection */
2691 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2692 }
2693
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002694 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 +02002695 }
2696
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002697 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002698 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 +02002699 }
2700}
2701
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002702private function f_tr_si2quater_earfcns(integer count) return template SI2quaterRestOctetsList
2703{
2704 var template SI2quaterRestOctetsList si2quater := {};
2705 var integer si2quater_count := (count + 2) / 3;
2706
2707 for (var integer i := 0; i < count; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002708 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002709 var integer index := i / 3;
2710 var integer earfcn_index := i mod 3;
2711 if (index >= lengthof(si2quater)) {
2712 si2quater[index] := tr_SI2quaterRestOctets_EUTRAN(index := index, count := si2quater_count - 1);
2713 }
2714 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);
2715 }
2716
2717 return si2quater;
2718}
2719
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002720private function f_tr_rr_chan_rel_earfcns(integer count) return template CellSelIndValue
2721{
2722 var template CellSelIndValue_EUTRAN_Descrs cells := {};
2723
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002724 /* the lte neighbors must match the config & vty to pass this test */
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002725 for (var integer i := 0; i < count; i := i + 1) {
2726 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002727 cells[i] := tr_CellSelIndValue_EUTRAN_Descr(earfcn, '1'B, 3);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002728 }
2729
2730 return tr_CellSelIndValue_EUTRAN(cells);
2731}
2732
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002733private function f_tc_si2quater_n_earfcns(integer n) runs on test_CT
2734{
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002735 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrol8ab62e42020-12-18 16:19:11 +01002736 sic.si2quater := f_tr_si2quater_earfcns(n);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002737 var template CellSelIndValue cells := f_tr_rr_chan_rel_earfcns(n);
2738 f_test_si2quater(n, sic, cells);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002739}
2740
2741testcase TC_si2quater_2_earfcns() runs on test_CT {
2742 f_tc_si2quater_n_earfcns(2);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002743 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002744}
2745
2746testcase TC_si2quater_3_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002747 f_tc_si2quater_n_earfcns(3);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002748 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002749}
2750
2751testcase TC_si2quater_4_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002752 f_tc_si2quater_n_earfcns(4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002753 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002754}
2755
2756testcase TC_si2quater_5_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002757 f_tc_si2quater_n_earfcns(5);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002758 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002759}
2760
2761testcase TC_si2quater_6_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002762 f_tc_si2quater_n_earfcns(6);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002763 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002764}
2765
2766testcase TC_si2quater_12_earfcns() runs on test_CT {
2767 f_tc_si2quater_n_earfcns(12);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002768 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002769}
2770
2771testcase TC_si2quater_23_earfcns() runs on test_CT {
2772 f_tc_si2quater_n_earfcns(23);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002773 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002774}
2775
2776testcase TC_si2quater_32_earfcns() runs on test_CT {
2777 f_tc_si2quater_n_earfcns(32);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002778 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002779}
2780
2781testcase TC_si2quater_33_earfcns() runs on test_CT {
2782 f_tc_si2quater_n_earfcns(33);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002783 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002784}
2785
2786testcase TC_si2quater_42_earfcns() runs on test_CT {
2787 f_tc_si2quater_n_earfcns(42);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002788 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002789}
2790
2791testcase TC_si2quater_48_earfcns() runs on test_CT {
2792 f_tc_si2quater_n_earfcns(48);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002793 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002794}
2795
2796/* verify the VTY error response when adding too many EARFCNs, and showing that osmo-bsc still sends 16 SI2quater with
2797 * 48 EARFCNs. */
2798testcase TC_si2quater_49_earfcns() runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002799 var template SystemInformationConfig sic := SystemInformationConfig_default;
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002800 sic.si2quater := f_tr_si2quater_earfcns(48); /* 48, not 49! */
2801 f_init(0);
2802
2803 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002804 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2805 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002806 }
2807
2808 /* The 49th EARFCN no longer fits, expect VTY error */
2809 f_vty_enter_cfg_bts(BSCVTY, 0);
2810 var charstring vty_error;
2811 vty_error := f_vty_transceive_ret(BSCVTY,
2812 "si2quater neighbor-list add earfcn 70 thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3")
2813 f_vty_transceive(BSCVTY, "end");
2814
2815 if (f_strstr(vty_error, "Unable to add ARFCN 70") >= 0) {
2816 log("Got expected VTY error: ", vty_error);
2817 setverdict(pass);
2818 } else {
2819 setverdict(fail, "Expected the 49th EUTRAN ARFCN to be rejected by vty config, got: ", vty_error);
2820 }
2821
2822 f_init_bts_and_check_sysinfo(0, expect_si := sic);
2823
2824 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002825 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 +02002826 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002827 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002828}
2829
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002830private function f_acc09_count_allowed(AccessControlClass acc) return uint8_t
2831{
2832 var uint8_t count := 0;
2833 for (var integer i := 5; i < 16; i := i + 1) {
2834 if (acc[i] == '0'B) { /* the list marks barred, we count allowed */
2835 count := count + 1;
2836 }
2837 }
2838 return count;
2839}
2840
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002841private function f_recv_next_si1(integer rsl_idx := 0) runs on test_CT return SystemInformationType1
2842{
2843 var ASP_RSL_Unitdata rx_rsl_ud;
2844 var SystemInformationType1 last_si1;
2845
2846 timer T := 30.0;
2847 T.start;
2848 alt {
2849 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD((tr_RSL_NO_BCCH_INFO,
2850 tr_RSL_BCCH_INFO,
2851 tr_RSL_NO_SACCH_FILL,
2852 tr_RSL_SACCH_FILL))
2853 ) -> value rx_rsl_ud {
2854 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
2855 if (g_system_information[rsl_idx].si1 == omit) {
2856 repeat;
2857 }
2858 last_si1 := g_system_information[rsl_idx].si1;
2859 g_system_information[rsl_idx].si1 := omit;
2860 T.stop;
2861 }
Vadim Yanitskiy79ebd5e2021-01-04 00:12:55 +01002862 [] IPA_RSL[rsl_idx].receive { repeat; }
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002863 [] T.timeout { setverdict(fail, "Timeout receiving next SI1"); }
2864 }
2865 return last_si1;
2866}
2867
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002868/* verify ACC rotate feature */
2869testcase TC_si_acc_rotate() runs on test_CT {
2870 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002871 var SystemInformationType1 last_si1;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002872 var AccessControlClass acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002873 var uint8_t count;
2874 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2875
2876 f_init(0, guard_timeout := 60.0);
2877
2878 f_bts_0_cfg(BSCVTY, {"rach access-control-class 5 barred",
2879 "access-control-class-rotate 3",
2880 "access-control-class-rotate-quantum 1"});
2881
2882 /* Init and get first sysinfo */
2883 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2884
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002885 for (var integer i:= 0; i < 20; i := i + 1) {
2886 last_si1 := f_recv_next_si1(0);
2887 acc := last_si1.rach_control.acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002888 count := f_acc09_count_allowed(acc);
2889 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2890
2891 if (count != 3) {
2892 log("RSL: EXPECTED SI ACC len=3");
2893 setverdict(fail, "received SI does not match expectations");
2894 break;
2895 }
2896
2897 for (var integer j := 0; j < 10; j := j + 1) {
2898 if (acc[16 - 1 - j] == '0'B) { /* the list marks barred, we count allowed */
2899 times_allowed[j] := times_allowed[j] + 1;
2900 }
2901 }
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002902 }
2903
2904 for (var integer j := 0; j < 10; j := j + 1) {
2905 log("ACC", j, " allowed ", times_allowed[j], " times" );
2906 if (j != 5 and times_allowed[j] < 3) {
2907 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " < 1 times");
2908 } else if (j == 5 and times_allowed[j] > 0) {
2909 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " > 0 times");
2910 }
2911 }
2912
2913 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2914 "rach access-control-class 5 allowed"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002915 f_shutdown_helper();
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002916}
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002917
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002918/* verify ACC startup ramp+rotate feature */
2919testcase TC_si_acc_ramp_rotate() runs on test_CT {
2920 var template SystemInformationConfig sic := SystemInformationConfig_default;
2921 var SystemInformationType1 last_si1;
2922 var AccessControlClass acc;
2923 var ASP_RSL_Unitdata rx_rsl_ud;
2924 var uint8_t count;
2925 var uint8_t prev_count;
2926 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2927
2928 f_init(0, guard_timeout := 80.0);
2929
2930 f_bts_0_cfg(BSCVTY, {"rach access-control-class 4 barred",
2931 "access-control-class-rotate 0",
2932 "access-control-class-rotate-quantum 1",
2933 "access-control-class-ramping",
2934 "access-control-class-ramping-step-interval 5",
2935 "access-control-class-ramping-step-size 5"});
2936
2937 /* Init and get first sysinfo */
2938 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2939 last_si1 := g_system_information[0].si1;
2940 acc := last_si1.rach_control.acc;
2941 count := f_acc09_count_allowed(acc);
2942 /* Adm subset size was set to 0 above, so wait until all ACC are barred */
2943 while (count > 0) {
2944 last_si1 := f_recv_next_si1(0);
2945 acc := last_si1.rach_control.acc;
2946 count := f_acc09_count_allowed(acc);
2947 log("RSL: wait len()=0: GOT SI1 ACC len=", count, ": ", acc);
2948 }
2949
2950 /* Increase adm subset size, we should see ramping start up */
2951 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10"});
2952 prev_count := 0;
2953 while (true) {
2954 last_si1 := f_recv_next_si1(0);
2955 acc := last_si1.rach_control.acc;
2956 count := f_acc09_count_allowed(acc);
2957 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2958
2959 if (prev_count > count) {
2960 setverdict(fail, "ACC allowed count dropped while expecting grow: ", prev_count, " -> ", count);
2961 break;
2962 }
2963
2964 if (count == 9) {
2965 break; /* Maximum reached (10 - 1 perm barred), done here */
2966 }
2967
2968 prev_count := count;
2969 }
2970
2971 setverdict(pass);
2972
2973 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2974 "rach access-control-class 4 allowed",
2975 "no access-control-class-ramping"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002976 f_shutdown_helper();
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002977}
2978
Harald Welte4003d112017-12-09 22:35:39 +01002979testcase TC_ctrl_msc_connection_status() runs on test_CT {
2980 var charstring ctrl_resp;
2981
Harald Welte89d42e82017-12-17 16:42:41 +01002982 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002983
2984 /* See https://osmocom.org/issues/2729 */
2985 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002986 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002987}
2988
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002989testcase TC_ctrl_msc0_connection_status() runs on test_CT {
2990 var charstring ctrl_resp;
2991
2992 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002993
2994 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002995 f_shutdown_helper();
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002996}
2997
Neels Hofmeyr0bc470d2021-08-21 13:37:13 +02002998/* Verify correct stats on the number of configured and connected MSCs */
2999private function f_tc_stat_num_msc_connected_msc_connhdlr(integer expect_num_msc_connected) runs on MSC_ConnHdlr {
3000 g_pars := f_gen_test_hdlr_pars();
3001 var StatsDExpects expect := {
3002 { name := "TTCN3.bsc.0.num_msc.connected", mtype := "g", min := expect_num_msc_connected, max := expect_num_msc_connected },
3003 { name := "TTCN3.bsc.0.num_msc.total", mtype := "g", min := NUM_MSC, max := NUM_MSC }
3004 };
3005 f_statsd_expect(expect);
3006}
3007
3008private function f_tc_stat_num_msc_connected_test_ct(void_fn tc_fn, integer nr_msc) runs on test_CT
3009{
3010 var MSC_ConnHdlr vc_conn;
3011
3012 f_init(nr_bts := 1, handler_mode := true, nr_msc := nr_msc);
3013 f_sleep(1.0);
3014 vc_conn := f_start_handler(tc_fn);
3015 vc_conn.done;
3016
3017 /* Also verify stat exposed on CTRL interface */
3018 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_msc:connected", int2str(nr_msc));
3019 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_msc:total", int2str(NUM_MSC));
3020
3021 f_shutdown_helper();
3022}
3023
3024/* Verify that when 1 MSC is active, that num_msc:connected reports 1. */
3025private function f_tc_stat_num_msc_connected_1(charstring id) runs on MSC_ConnHdlr {
3026 f_tc_stat_num_msc_connected_msc_connhdlr(1);
3027}
3028testcase TC_stat_num_msc_connected_1() runs on test_CT {
3029 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_1), 1);
3030}
3031
3032/* Verify that when 2 MSCs are active, that num_msc:connected reports 2. */
3033private function f_tc_stat_num_msc_connected_2(charstring id) runs on MSC_ConnHdlr {
3034 f_tc_stat_num_msc_connected_msc_connhdlr(2);
3035}
3036testcase TC_stat_num_msc_connected_2() runs on test_CT {
3037 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_2), 2);
3038}
3039
3040/* Verify that when 3 MSCs are active, that num_msc:connected reports 3. */
3041private function f_tc_stat_num_msc_connected_3(charstring id) runs on MSC_ConnHdlr {
3042 f_tc_stat_num_msc_connected_msc_connhdlr(3);
3043}
3044testcase TC_stat_num_msc_connected_3() runs on test_CT {
3045 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_3), 3);
3046}
3047
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +02003048/* Verify correct stats on the number of configured and connected MSCs */
3049private function f_tc_stat_num_bts_connected_msc_connhdlr(integer expect_num_bts_connected) runs on MSC_ConnHdlr {
3050 g_pars := f_gen_test_hdlr_pars();
3051 var StatsDExpects expect := {
3052 { name := "TTCN3.bsc.0.num_bts.oml_connected", mtype := "g", min := expect_num_bts_connected, max := NUM_BTS_CFG },
3053 { name := "TTCN3.bsc.0.num_bts.all_trx_rsl_connected", mtype := "g", min := expect_num_bts_connected, max := expect_num_bts_connected },
3054 { name := "TTCN3.bsc.0.num_bts.total", mtype := "g", min := NUM_BTS_CFG, max := NUM_BTS_CFG },
3055 { name := "TTCN3.bsc.0.num_trx.rsl_connected", mtype := "g", min := expect_num_bts_connected, max := expect_num_bts_connected },
3056 { name := "TTCN3.bsc.0.num_trx.total", mtype := "g", min := NUM_BTS_CFG, max := NUM_BTS_CFG }
3057 };
3058 f_statsd_expect(expect);
3059}
3060
3061private function f_tc_stat_num_bts_connected_test_ct(void_fn tc_fn, integer nr_bts) runs on test_CT {
3062 var MSC_ConnHdlr vc_conn;
3063
3064 f_init(nr_bts := nr_bts, handler_mode := true, nr_msc := 1);
3065 f_sleep(1.0);
3066 vc_conn := f_start_handler(tc_fn);
3067 vc_conn.done;
3068
3069 /* Also verify stat exposed on CTRL interface */
3070 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_bts:all_trx_rsl_connected", int2str(nr_bts));
3071 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_bts:total", int2str(NUM_BTS_CFG));
3072 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_trx:rsl_connected", int2str(nr_bts));
3073 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_trx:total", int2str(NUM_BTS_CFG));
3074
Neels Hofmeyra41ae302021-09-06 22:06:02 +02003075 /* Verify rf_states exposed on CTRL interface */
3076 var charstring expect_net_rf_states := "";
3077 for (var integer i := 0; i < NUM_BTS_CFG; i := i + 1) {
3078 var charstring expect_bts_rf_states := int2str(i) & ",0,";
3079 if (i < NUM_BTS) {
3080 /* In these tests, OML for the first NUM_BTS are always connected via osmo-bts-omldummy */
3081 expect_bts_rf_states := expect_bts_rf_states & "operational,unlocked,";
3082 } else {
3083 /* For remaining i < NUM_BTS_CFG, OML is not connected, i.e. inoperational */
3084 expect_bts_rf_states := expect_bts_rf_states & "inoperational,locked,";
3085 }
3086 /* The RF policy is still global in osmo-bsc, i.e. always "on" */
3087 expect_bts_rf_states := expect_bts_rf_states & "on,";
3088 if (i < nr_bts) {
3089 /* For BTS where RSL is connected, the RSL state will be "up" */
3090 expect_bts_rf_states := expect_bts_rf_states & "rsl-up;";
3091 } else {
3092 expect_bts_rf_states := expect_bts_rf_states & "rsl-down;";
3093 }
3094
3095 f_ctrl_get_exp(IPA_CTRL, "bts." & int2str(i) & ".rf_states", expect_bts_rf_states);
3096 expect_net_rf_states := expect_net_rf_states & expect_bts_rf_states;
3097 }
3098 f_ctrl_get_exp(IPA_CTRL, "rf_states", expect_net_rf_states);
3099
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +02003100 f_shutdown_helper();
3101}
3102
3103/* Verify that when 1 BTS is connected, that num_{bts,trx}:*_connected reports 1. */
3104private function f_tc_stat_num_bts_connected_1(charstring id) runs on MSC_ConnHdlr {
3105 f_tc_stat_num_bts_connected_msc_connhdlr(1);
3106}
3107testcase TC_stat_num_bts_connected_1() runs on test_CT {
3108 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_1), 1);
3109}
3110
3111/* Verify that when 2 BTS is connected, that num_{bts,trx}:*_connected reports 2. */
3112private function f_tc_stat_num_bts_connected_2(charstring id) runs on MSC_ConnHdlr {
3113 f_tc_stat_num_bts_connected_msc_connhdlr(2);
3114}
3115testcase TC_stat_num_bts_connected_2() runs on test_CT {
3116 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_2), 2);
3117}
3118
3119/* Verify that when 3 BTS is connected, that num_{bts,trx}:*_connected reports 3. */
3120private function f_tc_stat_num_bts_connected_3(charstring id) runs on MSC_ConnHdlr {
3121 f_tc_stat_num_bts_connected_msc_connhdlr(3);
3122}
3123testcase TC_stat_num_bts_connected_3() runs on test_CT {
3124 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_3), 3);
3125}
3126
Harald Welte4003d112017-12-09 22:35:39 +01003127testcase TC_ctrl() runs on test_CT {
3128 var charstring ctrl_resp;
3129
Harald Welte89d42e82017-12-17 16:42:41 +01003130 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01003131
3132 /* all below values must match the osmo-bsc.cfg config file used */
3133
Harald Welte6a129692018-03-17 17:30:14 +01003134 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
3135 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Oliver Smith75aa0202019-08-19 14:17:50 +02003136 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "4");
Harald Welte4003d112017-12-09 22:35:39 +01003137
3138 var integer bts_nr := 0;
3139 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
3140 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
3141 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
3142 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
3143 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
3144 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
3145 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
3146
3147 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
3148 f_sleep(2.0);
3149 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
3150 setverdict(fail, "oml-uptime not incrementing as expected");
3151 }
3152 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
3153
3154 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
3155
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003156 f_shutdown_helper();
Harald Welte96c94412017-12-09 03:12:45 +01003157}
3158
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02003159/* Verify that Upon receival of SET "location", BSC forwards a TRAP
3160 "location-state" over the SCCPlite IPA conn */
3161testcase TC_ctrl_location() runs on test_CT {
3162 var MSC_ConnHdlr vc_conn;
3163 var integer bts_nr := 0;
3164
3165 f_init(1, true);
3166 f_sleep(1.0);
3167
3168 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234567,fix3d,0.340000,0.560000,0.780000");
3169 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
3170 "1234567,fix3d,0.340000,0.560000,0.780000,operational,unlocked,on,001,01");
3171
3172 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "1");
3173 f_sleep(2.0);
3174
3175 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234888,fix3d,0.350000,0.570000,0.790000");
3176 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
3177 "1234888,fix3d,0.350000,0.570000,0.790000,operational,locked,off,001,01");
3178
3179 /* should match the one from config */
3180 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "0");
3181
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003182 f_shutdown_helper();
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02003183}
3184
Harald Welte6f521d82017-12-11 19:52:02 +01003185
3186/***********************************************************************
3187 * Paging Testing
3188 ***********************************************************************/
3189
3190type record Cell_Identity {
3191 GsmMcc mcc,
3192 GsmMnc mnc,
3193 GsmLac lac,
3194 GsmCellId ci
3195};
Harald Welte24135bd2018-03-17 19:27:53 +01003196private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01003197private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01003198
Harald Welte5d1a2202017-12-13 19:51:29 +01003199type set of integer BtsIdList;
3200
3201private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
3202 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
3203 if (bts_id == bts_ids[j]) {
3204 return true;
3205 }
3206 }
3207 return false;
3208}
Harald Welte6f521d82017-12-11 19:52:02 +01003209
3210/* core paging test helper function; used by most paging test cases */
3211private function f_pageing_helper(hexstring imsi,
3212 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01003213 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01003214 template RSL_ChanNeeded rsl_chneed := omit,
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003215 template (omit) OCT4 tmsi := omit) runs on test_CT
Harald Welte6f521d82017-12-11 19:52:02 +01003216{
3217 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003218 var template MobileIdentityV mi;
Harald Welte6f521d82017-12-11 19:52:02 +01003219 var RSL_Message rx_rsl;
3220 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01003221 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01003222
3223 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01003224
3225 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01003226 for (i := 0; i < NUM_BTS; i := i + 1) {
3227 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01003228 }
Harald Welte6f521d82017-12-11 19:52:02 +01003229
3230 if (isvalue(rsl_chneed)) {
3231 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
3232 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
3233 } else {
3234 bssmap_chneed := omit;
3235 }
3236
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003237 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[0].sccp_addr_peer, g_bssap[0].sccp_addr_own,
3238 ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed)));
Harald Welte6f521d82017-12-11 19:52:02 +01003239
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003240 if (not istemplatekind(tmsi, "omit")) {
3241 mi := t_MI_TMSI(tmsi);
Harald Welte6f521d82017-12-11 19:52:02 +01003242 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003243 mi := tr_MI_IMSI(imsi);
Harald Welte6f521d82017-12-11 19:52:02 +01003244 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003245
Harald Welte5d1a2202017-12-13 19:51:29 +01003246 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003247 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(mi));
Harald Welte5d1a2202017-12-13 19:51:29 +01003248 /* check channel type, paging group */
3249 if (rx_rsl.ies[1].body.paging_group != paging_group) {
3250 setverdict(fail, "Paging for wrong paging group");
3251 }
3252 if (ispresent(rsl_chneed) and
3253 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
3254 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
3255 }
Harald Welte6f521d82017-12-11 19:52:02 +01003256 }
Harald Welte2fccd982018-01-31 15:48:19 +01003257 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01003258 /* do a quick check on all not-included BTSs if they received paging */
3259 for (i := 0; i < NUM_BTS; i := i + 1) {
3260 timer T := 0.1;
3261 if (f_bts_in_list(i, bts_ids)) {
3262 continue;
3263 }
3264 T.start;
3265 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003266 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(mi))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003267 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
3268 }
3269 [] IPA_RSL[i].receive { repeat; }
3270 [] T.timeout { }
3271 }
Harald Welte6f521d82017-12-11 19:52:02 +01003272 }
3273
3274 setverdict(pass);
3275}
3276
Harald Welte5d1a2202017-12-13 19:51:29 +01003277const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01003278const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01003279const BtsIdList c_BtsId_LAC1 := { 0, 1 };
3280const BtsIdList c_BtsId_LAC2 := { 2 };
3281
Harald Welte6f521d82017-12-11 19:52:02 +01003282/* PAGING by IMSI + TMSI */
3283testcase TC_paging_imsi_nochan() runs on test_CT {
3284 var BSSMAP_FIELD_CellIdentificationList cid_list;
3285 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01003286 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003287 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003288}
3289
3290/* PAGING by IMSI + TMSI */
3291testcase TC_paging_tmsi_nochan() runs on test_CT {
3292 var BSSMAP_FIELD_CellIdentificationList cid_list;
3293 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003294 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003295 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003296}
3297
3298/* Paging with different "channel needed' values */
3299testcase TC_paging_tmsi_any() runs on test_CT {
3300 var BSSMAP_FIELD_CellIdentificationList cid_list;
3301 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003302 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003303 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003304}
3305testcase TC_paging_tmsi_sdcch() runs on test_CT {
3306 var BSSMAP_FIELD_CellIdentificationList cid_list;
3307 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003308 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003309 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003310}
3311testcase TC_paging_tmsi_tch_f() runs on test_CT {
3312 var BSSMAP_FIELD_CellIdentificationList cid_list;
3313 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003314 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003315 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003316}
3317testcase TC_paging_tmsi_tch_hf() runs on test_CT {
3318 var BSSMAP_FIELD_CellIdentificationList cid_list;
3319 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003320 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003321 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003322}
3323
3324/* Paging by CGI */
3325testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
3326 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3327 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003328 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003329 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003330}
3331
3332/* Paging by LAC+CI */
3333testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
3334 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3335 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003336 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003337 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003338}
3339
3340/* Paging by CI */
3341testcase TC_paging_imsi_nochan_ci() runs on test_CT {
3342 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3343 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003344 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003345 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003346}
3347
3348/* Paging by LAI */
3349testcase TC_paging_imsi_nochan_lai() runs on test_CT {
3350 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3351 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003352 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003353 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003354}
3355
3356/* Paging by LAC */
3357testcase TC_paging_imsi_nochan_lac() runs on test_CT {
3358 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3359 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003360 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003361 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003362}
3363
3364/* Paging by "all in BSS" */
3365testcase TC_paging_imsi_nochan_all() runs on test_CT {
3366 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3367 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01003368 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003369 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003370}
3371
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003372/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003373testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
3374 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3375 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 +01003376 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003377 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003378}
Harald Welte6f521d82017-12-11 19:52:02 +01003379
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003380/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003381testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
3382 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3383 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003384 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003385 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003386}
3387
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003388/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003389testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
3390 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3391 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003392 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003393 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003394}
3395
Harald Welte6f521d82017-12-11 19:52:02 +01003396/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01003397testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
3398 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3399 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
3400 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003401 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003402}
3403
3404/* Paging on empty list: Verify none of them page */
3405testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
3406 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3407 cid_list := { cIl_LAC := { } };
3408 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003409 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003410}
3411
Stefan Sperling049a86e2018-03-20 15:51:00 +01003412/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
3413testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
3414 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3415 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
3416 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
3417 f_shutdown_helper();
3418}
3419
Harald Welte6f521d82017-12-11 19:52:02 +01003420/* Verify paging retransmission interval + count */
3421/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01003422/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01003423
Harald Weltee65d40e2017-12-13 00:09:06 +01003424/* Verify PCH load */
3425testcase TC_paging_imsi_load() runs on test_CT {
3426 var BSSMAP_FIELD_CellIdentificationList cid_list;
3427 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01003428 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01003429 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003430 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01003431
3432 /* tell BSC there is no paging space anymore */
3433 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01003434 f_sleep(0.2);
3435 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01003436
3437 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
3438 * there would be 8 retransmissions during 4 seconds */
3439 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01003440 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01003441 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003442 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Weltee65d40e2017-12-13 00:09:06 +01003443 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02003444 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01003445 }
Harald Welte2caa1062018-03-17 18:19:05 +01003446 [] T_retrans.timeout {
3447 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
3448 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
3449 T_retrans.start;
3450 repeat;
3451 }
Harald Weltee65d40e2017-12-13 00:09:06 +01003452 [] T.timeout {
3453 setverdict(pass);
3454 }
3455 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003456
3457 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01003458}
3459
Harald Welte235ebf12017-12-15 14:18:16 +01003460/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01003461testcase TC_paging_counter() runs on test_CT {
3462 var BSSMAP_FIELD_CellIdentificationList cid_list;
3463 timer T := 4.0;
3464 var integer i;
3465 var integer paging_attempted_bsc;
3466 var integer paging_attempted_bts[NUM_BTS];
Oliver Smith8b343d32021-11-26 13:01:42 +01003467 var integer paging_expired_bsc;
Harald Welte1ff69992017-12-14 12:31:17 +01003468 var integer paging_expired_bts[NUM_BTS];
3469 cid_list := valueof(ts_BSSMAP_CIL_noCell);
3470
3471 f_init();
3472
3473 /* read counters before paging */
3474 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
Oliver Smith8b343d32021-11-26 13:01:42 +01003475 if (Misc_Helpers.f_osmo_repo_is("nightly")) { /* osmo-bsc > 1.8.0 */
3476 paging_expired_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:expired");
3477 }
Harald Welte1ff69992017-12-14 12:31:17 +01003478 for (i := 0; i < NUM_BTS; i := i+1) {
3479 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
3480 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
3481 }
3482
3483 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
3484
3485 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
3486 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
3487 for (i := 0; i < NUM_BTS; i := i+1) {
3488 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
3489 paging_attempted_bts[i]+1);
3490 }
3491
3492 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
3493 f_sleep(12.0);
Oliver Smith8b343d32021-11-26 13:01:42 +01003494 if (Misc_Helpers.f_osmo_repo_is("nightly")) { /* osmo-bsc > 1.8.0 */
3495 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:expired", paging_expired_bsc+1);
3496 }
Harald Welte1ff69992017-12-14 12:31:17 +01003497 for (i := 0; i < NUM_BTS; i := i+1) {
3498 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
3499 paging_expired_bts[i]+1);
3500 }
Harald Welte1ff69992017-12-14 12:31:17 +01003501
Philipp Maier282ca4b2018-02-27 17:17:00 +01003502 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01003503}
3504
3505
Harald Welte10985002017-12-12 09:29:15 +01003506/* Verify paging stops after A-RESET */
3507testcase TC_paging_imsi_a_reset() runs on test_CT {
3508 var BSSMAP_FIELD_CellIdentificationList cid_list;
3509 timer T := 3.0;
3510 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003511 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01003512
3513 /* Perform a BSSMAP Reset and wait for ACK */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003514 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 +01003515 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003516 [] 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 +01003517 [] BSSAP.receive { repeat; }
3518 }
3519
Daniel Willmanncbef3982018-07-30 09:22:40 +02003520 /* Wait to avoid a possible race condition if a paging message is
3521 * received right before the reset ACK. */
3522 f_sleep(0.2);
3523
Harald Welte10985002017-12-12 09:29:15 +01003524 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01003525 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
3526 IPA_RSL[i].clear;
3527 }
Harald Welte10985002017-12-12 09:29:15 +01003528
3529 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
3530 T.start;
3531 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003532 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte10985002017-12-12 09:29:15 +01003533 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003534 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01003535 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003536 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003537 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003538 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003539 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003540 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003541 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003542 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003543 }
Harald Welte10985002017-12-12 09:29:15 +01003544 [] T.timeout {
3545 setverdict(pass);
3546 }
3547 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003548
3549 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01003550}
Harald Welteae026692017-12-09 01:03:01 +01003551
Philipp Maierf45824a2019-08-14 14:44:10 +02003552/* Verify how we handle unsolicited Paging Response. In case of an unsolicit
3553 * paging response we can not know which MSC is in charge, so we will blindly
3554 * pick the first configured MSC. This behavior is required in order to make
3555 * MT-CSFB calls working because in those cases the BSC can not know that the
3556 * MSC has already paged the subscriver via SGs. So any MT-CSFB call will look
3557 * like an unsolicited Paging Response to the MSC.
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003558 */
3559testcase TC_paging_resp_unsol() runs on test_CT {
3560
3561 f_init(1);
Philipp Maierf45824a2019-08-14 14:44:10 +02003562 timer T := 5.0;
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003563
3564 var BSSAP_N_CONNECT_ind rx_c_ind;
3565 var DchanTuple dt;
3566 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
Philipp Maierf45824a2019-08-14 14:44:10 +02003567 var octetstring rr_pag_resp := enc_PDU_ML3_MS_NW(l3);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003568
3569 /* Send CHAN RQD and wait for allocation; acknowledge it */
3570 dt.rsl_chan_nr := f_chreq_act_ack();
3571
3572 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
3573 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
3574
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003575
Philipp Maierf45824a2019-08-14 14:44:10 +02003576 /* Expevct a CR with a matching Paging response on the A-Interface */
3577 T.start;
3578 alt {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003579 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(rr_pag_resp))) -> value rx_c_ind {
Philipp Maierf45824a2019-08-14 14:44:10 +02003580 setverdict(pass);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003581 dt.sccp_conn_id := rx_c_ind.connectionId;
3582 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
Philipp Maierf45824a2019-08-14 14:44:10 +02003583 }
3584 [] BSSAP.receive {
3585 setverdict(fail, "Received unexpected message on A-Interface!");
3586 }
3587 [] T.timeout {
3588 setverdict(fail, "Received nothing on A-Interface!");
3589 }
3590 }
3591
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003592 f_perform_clear_test_ct(dt);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003593 f_shutdown_helper();
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003594}
3595
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003596/* Test RSL link drop causes counter increment */
3597testcase TC_rsl_drop_counter() runs on test_CT {
3598 var integer rsl_fail;
3599
Harald Welte89d42e82017-12-17 16:42:41 +01003600 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003601
3602 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
3603
Pau Espin Pedrolaf0c61e2022-01-11 12:48:34 +01003604 f_ipa_rsl_stop(bts[0].rsl);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003605
3606 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
3607
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003608 f_shutdown_helper();
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003609}
3610
3611/* TODO: Test OML link drop causes counter increment */
3612
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003613/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
3614function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
3615 timer T := 10.0;
3616
3617 bts[0].rsl.id := "IPA-0-RSL";
Harald Welte71389132021-12-09 21:58:18 +01003618 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA") alive;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003619 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
3620 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
Oliver Smith92c2bdb2019-08-20 15:11:24 +02003621 bts[0].rsl.ccm_pars.unit_id := "99/0/0"; /* value which is unknown at BTS */
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003622
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01003623 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003624
3625 f_init_mgcp("VirtMSC");
3626
3627 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
3628 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
3629 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
3630 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
3631
3632 /* wait for IPA OML link to connect and then disconnect */
3633 T.start;
3634 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +07003635 [] IPA_RSL[0].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) {
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003636 T.stop;
3637 return true;
3638 }
3639 [] IPA_RSL[0].receive { repeat }
3640 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02003641 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003642 }
3643 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003644 return false;
3645}
3646
3647/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3648testcase TC_rsl_unknown_unit_id() runs on test_CT {
3649 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
3650 setverdict(pass);
3651 } else {
3652 setverdict(fail, "Timeout RSL waiting for connection to close");
3653 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003654 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003655}
3656
3657
3658/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3659testcase TC_oml_unknown_unit_id() runs on test_CT {
3660 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
3661 setverdict(pass);
3662 } else {
3663 setverdict(fail, "Timeout OML waiting for connection to close");
3664 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003665 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003666}
3667
3668
Harald Weltec1a2fff2017-12-17 11:06:19 +01003669/***********************************************************************
Harald Welte6811d102019-04-14 22:23:14 +02003670 * "New world" test cases using RSL_Emulation + RAN_Emulation
Harald Weltec1a2fff2017-12-17 11:06:19 +01003671 ***********************************************************************/
3672
Harald Welte6811d102019-04-14 22:23:14 +02003673import from RAN_Emulation all;
Harald Welte47cd0e32020-08-21 12:39:11 +02003674import from BSSAP_LE_Emulation all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01003675import from RSL_Emulation all;
3676import from MSC_ConnectionHandler all;
3677
3678type function void_fn(charstring id) runs on MSC_ConnHdlr;
3679
Harald Welte336820c2018-05-31 20:34:52 +02003680/* helper function to create and connect a MSC_ConnHdlr component */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003681private function f_connect_handler(inout MSC_ConnHdlr vc_conn, integer bssap_idx := 0) runs on test_CT {
3682 connect(vc_conn:RAN, g_bssap[bssap_idx].vc_RAN:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01003683 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003684 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01003685 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01003686 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01003687 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
3688 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
3689 }
Neels Hofmeyr91401012019-07-11 00:42:35 +02003690 if (isvalue(bts[2])) {
3691 connect(vc_conn:RSL2, bts[2].rsl.vc_RSL:CLIENT_PT);
3692 connect(vc_conn:RSL2_PROC, bts[2].rsl.vc_RSL:RSL_PROC);
3693 }
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003694 connect(vc_conn:BSSAP, g_bssap[bssap_idx].vc_RAN:CLIENT);
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02003695 if (mp_enable_lcs_tests) {
3696 connect(vc_conn:BSSAP_LE, g_bssap_le.vc_BSSAP_LE:CLIENT);
3697 connect(vc_conn:BSSAP_LE_PROC, g_bssap_le.vc_BSSAP_LE:PROC);
3698 }
Daniel Willmann191e0d92018-01-17 12:44:35 +01003699 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02003700 connect(vc_conn:MGCP_MULTI, vc_MGCP:MGCP_CLIENT_MULTI);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003701 connect(vc_conn:STATSD_PROC, vc_STATSD:STATSD_PROC);
Harald Welte336820c2018-05-31 20:34:52 +02003702}
3703
Neels Hofmeyrda436782021-07-20 22:09:06 +02003704function f_start_handler_create(template (omit) TestHdlrParams pars := omit)
Harald Welte336820c2018-05-31 20:34:52 +02003705runs on test_CT return MSC_ConnHdlr {
3706 var charstring id := testcasename();
3707 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003708 var integer bssap_idx := 0;
3709 if (isvalue(pars)) {
3710 bssap_idx := valueof(pars).mscpool.bssap_idx;
3711 }
Harald Welte336820c2018-05-31 20:34:52 +02003712 vc_conn := MSC_ConnHdlr.create(id);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003713 f_connect_handler(vc_conn, bssap_idx);
Neels Hofmeyrda436782021-07-20 22:09:06 +02003714 return vc_conn;
3715}
3716
3717function f_start_handler_run(MSC_ConnHdlr vc_conn, void_fn fn, template (omit) TestHdlrParams pars := omit)
3718runs on test_CT return MSC_ConnHdlr {
3719 var charstring id := testcasename();
Harald Weltea0630032018-03-20 21:09:55 +01003720 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003721 return vc_conn;
3722}
3723
Neels Hofmeyrda436782021-07-20 22:09:06 +02003724function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
3725runs on test_CT return MSC_ConnHdlr {
3726 return f_start_handler_run(f_start_handler_create(pars), fn, pars);
3727}
3728
Harald Weltea0630032018-03-20 21:09:55 +01003729/* first function inside ConnHdlr component; sets g_pars + starts function */
3730private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
3731runs on MSC_ConnHdlr {
3732 if (isvalue(pars)) {
3733 g_pars := valueof(pars);
3734 }
3735 fn.apply(id);
3736}
3737
Oliver Smith26a3db72021-07-09 13:51:29 +02003738private function f_vty_encryption_a5(charstring options) runs on test_CT {
3739 f_vty_transceive(BSCVTY, "configure terminal");
3740 f_vty_transceive(BSCVTY, "network");
3741 f_vty_transceive(BSCVTY, "encryption a5 " & options);
3742 f_vty_transceive(BSCVTY, "exit");
3743 f_vty_transceive(BSCVTY, "exit");
3744}
3745
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01003746const charstring VTY_A5_DEFAULT := "0 1 3";
3747
Oliver Smith26a3db72021-07-09 13:51:29 +02003748private function f_vty_encryption_a5_reset() runs on test_CT {
3749 /* keep in sync with docker-playground.git ttcn3-bsc-test/osmo-bsc.cfg */
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01003750 f_vty_encryption_a5(VTY_A5_DEFAULT);
Oliver Smith26a3db72021-07-09 13:51:29 +02003751}
3752
Harald Welte3c86ea02018-05-10 22:28:05 +02003753/* Establish signalling channel (non-assignment case) followed by cipher mode */
3754private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003755 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3756 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02003757 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02003758 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
3759 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
3760 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
3761 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02003762
Philipp Maier23000732018-05-18 11:25:37 +02003763 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003764 f_perform_clear();
Harald Welte3c86ea02018-05-10 22:28:05 +02003765}
3766testcase TC_ciph_mode_a5_0() runs on test_CT {
3767 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003768 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003769 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
3770
3771 f_init(1, true);
3772 f_sleep(1.0);
3773 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3774 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003775 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003776}
3777testcase TC_ciph_mode_a5_1() runs on test_CT {
3778 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003779 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003780 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
3781
3782 f_init(1, true);
3783 f_sleep(1.0);
3784 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3785 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003786 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003787}
Oliver Smith50b98122021-07-09 15:00:28 +02003788/* OS#4975: verify that A5/2 is preferred over A5/0 */
3789testcase TC_ciph_mode_a5_2_0() runs on test_CT {
3790 var MSC_ConnHdlr vc_conn;
3791 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3792
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01003793 pars.encr := f_encr_params('05'O, '04'O); /* A5/0 and A5/2 (0x01|0x04)*/
Oliver Smith50b98122021-07-09 15:00:28 +02003794
3795 f_init(1, true);
3796 f_vty_encryption_a5("0 1 2 3");
3797 f_sleep(1.0);
3798 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3799 vc_conn.done;
3800 f_vty_encryption_a5_reset();
3801 f_shutdown_helper();
3802}
Oliver Smith1dff88d2021-07-09 08:45:51 +02003803/* OS#4975: verify that A5/1 is preferred over A5/2 */
3804testcase TC_ciph_mode_a5_2_1() runs on test_CT {
3805 var MSC_ConnHdlr vc_conn;
3806 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3807
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01003808 pars.encr := f_encr_params('06'O, '02'O); /* A5/1 and A5/2 (0x02|0x04)*/
Oliver Smith1dff88d2021-07-09 08:45:51 +02003809
3810 f_init(1, true);
3811 f_vty_encryption_a5("1 2");
3812 f_sleep(1.0);
3813 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3814 vc_conn.done;
3815 f_vty_encryption_a5_reset();
3816 f_shutdown_helper();
3817}
Harald Welte3c86ea02018-05-10 22:28:05 +02003818testcase TC_ciph_mode_a5_3() runs on test_CT {
3819 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003820 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003821 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
3822
3823 f_init(1, true);
3824 f_sleep(1.0);
3825 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3826 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003827 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003828}
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003829/* Establish a Signalling channel with A5/4 encryption. */
3830testcase TC_ciph_mode_a5_4() runs on test_CT {
3831 var MSC_ConnHdlr vc_conn;
3832 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3833 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Harald Welte3c86ea02018-05-10 22:28:05 +02003834
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003835 f_init(1, true);
Oliver Smith26a3db72021-07-09 13:51:29 +02003836 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003837 f_sleep(1.0);
3838 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3839 vc_conn.done;
Oliver Smith26a3db72021-07-09 13:51:29 +02003840 f_vty_encryption_a5_reset();
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003841 f_shutdown_helper();
3842}
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003843/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
3844private function f_tc_assignment_aoip_tla_v6(charstring id) runs on MSC_ConnHdlr {
3845 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3846 var PDU_BSSAP ass_cmd := f_gen_ass_req(aoip_tla := "::3");
3847 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3848 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3849
3850 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003851 f_perform_clear();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003852}
3853testcase TC_assignment_aoip_tla_v6() runs on test_CT {
3854 var MSC_ConnHdlr vc_conn;
3855 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3856
3857 f_init(1, true);
3858 f_sleep(1.0);
3859 vc_conn := f_start_handler(refers(f_tc_assignment_aoip_tla_v6), pars);
3860 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003861 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003862}
3863
Harald Welte3c86ea02018-05-10 22:28:05 +02003864
3865/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02003866private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003867 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3868 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003869
Harald Welte552620d2017-12-16 23:21:36 +01003870 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3871 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01003872
Harald Weltea0630032018-03-20 21:09:55 +01003873 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003874 f_perform_clear();
Harald Welte552620d2017-12-16 23:21:36 +01003875}
Harald Welte552620d2017-12-16 23:21:36 +01003876testcase TC_assignment_fr_a5_0() runs on test_CT {
3877 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003878 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003879 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01003880
Harald Welte89d42e82017-12-17 16:42:41 +01003881 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003882 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003883 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003884 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003885 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003886}
Harald Welte552620d2017-12-16 23:21:36 +01003887testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01003888 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003889 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003890 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003891
Harald Welte89d42e82017-12-17 16:42:41 +01003892 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003893 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003894 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3895 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003896 f_shutdown_helper();
Harald Welte651fcdc2018-05-10 20:23:16 +02003897}
3898testcase TC_assignment_fr_a5_3() runs on test_CT {
3899 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003900 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003901 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003902
Harald Welte651fcdc2018-05-10 20:23:16 +02003903 f_init(1, true);
3904 f_sleep(1.0);
3905 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003906 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003907 f_shutdown_helper();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003908}
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003909/* Establish a Signalling channel and re-assign to TCH/F with A5/4 encryption. */
3910testcase TC_assignment_fr_a5_4() runs on test_CT {
3911 var MSC_ConnHdlr vc_conn;
3912 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3913 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
3914
3915 f_init(1, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02003916 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003917 f_sleep(1.0);
3918 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3919 vc_conn.done;
Oliver Smith7eabd312021-07-12 14:18:56 +02003920 f_vty_encryption_a5_reset();
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003921 f_shutdown_helper();
3922}
Harald Weltec1a2fff2017-12-17 11:06:19 +01003923
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +02003924/* Allow only A5/4, but omit the Kc128 IE from MSC's msg. Expect Cipher Mode Reject. */
3925testcase TC_assignment_fr_a5_4_fail() runs on test_CT {
3926 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3927 var MSC_ConnHdlr vc_conn;
3928
3929 f_init(1, true);
3930 f_sleep(1.0);
3931
3932 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8))); // A5/4 support, but Kc128 missing!
3933 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
3934 vc_conn.done;
3935 f_shutdown_helper();
3936}
3937
Harald Welte552620d2017-12-16 23:21:36 +01003938/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
3939private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003940 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01003941 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02003942 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003943
3944 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003945 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
3946
Harald Weltea0630032018-03-20 21:09:55 +01003947 f_establish_fully(ass_cmd, exp_fail);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003948 f_perform_clear();
Harald Welte552620d2017-12-16 23:21:36 +01003949}
Harald Welte552620d2017-12-16 23:21:36 +01003950testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
3951 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
Harald Welte8863fa12018-05-10 20:15:27 +02003956 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01003957 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003958 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003959}
3960
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003961private function f_TC_assignment_a5_not_sup(charstring id) runs on MSC_ConnHdlr {
3962 var template PDU_BSSAP exp_ass_cpl := f_gen_exp_compl();
3963 var PDU_BSSAP exp_ass_req := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003964
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003965 exp_ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3966 exp_ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3967
3968 /* this is like the beginning of f_establish_fully(), but only up to ciphering reject */
3969
3970 var BSSMAP_FIELD_CodecType codecType;
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003971
3972 codecType := exp_ass_req.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType;
3973 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
3974
3975 f_create_chan_and_exp();
3976 /* we should now have a COMPL_L3 at the MSC */
3977
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003978 /* Start ciphering, expect Cipher Mode Reject */
Neels Hofmeyr6c388f22021-06-11 02:36:56 +02003979 f_cipher_mode(g_pars.encr, exp_fail := true);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01003980 f_perform_clear();
Harald Welte552620d2017-12-16 23:21:36 +01003981}
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003982testcase TC_assignment_fr_a5_not_sup() runs on test_CT {
3983 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01003984 var MSC_ConnHdlr vc_conn;
3985
Harald Welte89d42e82017-12-17 16:42:41 +01003986 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003987 f_sleep(1.0);
3988
Neels Hofmeyr0588cad2021-06-11 01:38:18 +02003989 pars.encr := valueof(t_EncrParams('20'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003990 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003991 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003992 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003993}
3994
3995
Harald Welte4532e0a2017-12-23 02:05:44 +01003996private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003997 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01003998 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02003999 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01004000 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Daniel Willmannebdecc02020-08-12 15:30:17 +02004001
4002 f_statsd_reset();
Harald Weltea0630032018-03-20 21:09:55 +01004003 f_establish_fully(ass_cmd, exp_compl);
Daniel Willmannebdecc02020-08-12 15:30:17 +02004004
4005 var StatsDExpects expect := {
Daniel Willmannc5398f72020-09-21 10:41:35 +02004006 { name := "TTCN3.bts.0.chreq.total", mtype := "c", min := 1, max := 1},
4007 { name := "TTCN3.bts.0.chreq.successful", mtype := "c", min := 1, max := 1},
Daniel Willmannebdecc02020-08-12 15:30:17 +02004008 { name := "TTCN3.bsc.0.assignment.attempted", mtype := "c", min := 1, max := 1},
4009 { name := "TTCN3.bsc.0.assignment.completed", mtype := "c", min := 1, max := 1}
4010 };
4011 f_statsd_expect(expect);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004012 f_perform_clear();
Harald Welte4532e0a2017-12-23 02:05:44 +01004013}
4014
4015testcase TC_assignment_sign() runs on test_CT {
4016 var MSC_ConnHdlr vc_conn;
4017
4018 f_init(1, true);
4019 f_sleep(1.0);
4020
Harald Welte8863fa12018-05-10 20:15:27 +02004021 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01004022 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004023 f_shutdown_helper();
Harald Welte4532e0a2017-12-23 02:05:44 +01004024}
4025
Harald Welte60aa5762018-03-21 19:33:13 +01004026/***********************************************************************
4027 * Codec (list) testing
4028 ***********************************************************************/
4029
4030/* check if the given rsl_mode is compatible with the a_elem */
4031private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
4032return boolean {
4033 select (a_elem.codecType) {
4034 case (GSM_FR) {
4035 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
4036 return true;
4037 }
4038 }
4039 case (GSM_HR) {
4040 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
4041 return true;
4042 }
4043 }
4044 case (GSM_EFR) {
4045 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
4046 return true;
4047 }
4048 }
4049 case (FR_AMR) {
4050 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
4051 return true;
4052 }
4053 }
4054 case (HR_AMR) {
4055 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
4056 return true;
4057 }
4058 }
4059 case else { }
4060 }
4061 return false;
4062}
4063
4064/* check if the given rsl_mode is compatible with the a_list */
4065private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
4066return boolean {
4067 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
4068 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
4069 return true;
4070 }
4071 }
4072 return false;
4073}
4074
4075/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02004076function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01004077return BSSMAP_IE_ChannelType {
4078 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
4079 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
4080 select (a_elem.codecType) {
4081 case (GSM_FR) {
4082 ret.channelRateAndType := ChRate_TCHF;
4083 ret.speechId_DataIndicator := Spdi_TCHF_FR;
4084 }
4085 case (GSM_HR) {
4086 ret.channelRateAndType := ChRate_TCHH;
4087 ret.speechId_DataIndicator := Spdi_TCHH_HR;
4088 }
4089 case (GSM_EFR) {
4090 ret.channelRateAndType := ChRate_TCHF;
4091 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
4092 }
4093 case (FR_AMR) {
4094 ret.channelRateAndType := ChRate_TCHF;
4095 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
4096 }
4097 case (HR_AMR) {
4098 ret.channelRateAndType := ChRate_TCHH;
4099 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
4100 }
4101 case else {
4102 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02004103 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01004104 }
4105 }
4106 return ret;
4107}
4108
Harald Weltea63b9102018-03-22 20:36:16 +01004109private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
4110return template RSL_IE_Body {
4111 var template RSL_IE_Body mode_ie := {
4112 chan_mode := {
4113 len := ?,
4114 reserved := ?,
4115 dtx_d := ?,
4116 dtx_u := ?,
4117 spd_ind := RSL_SPDI_SPEECH,
4118 ch_rate_type := -,
4119 coding_alg_rate := -
4120 }
4121 }
4122
4123 select (a_elem.codecType) {
4124 case (GSM_FR) {
4125 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4126 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
4127 }
4128 case (GSM_HR) {
4129 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
4130 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
4131 }
4132 case (GSM_EFR) {
4133 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4134 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
4135 }
4136 case (FR_AMR) {
4137 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4138 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
4139 }
4140 case (HR_AMR) {
4141 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
4142 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
4143 }
4144 }
4145 return mode_ie;
4146}
4147
Harald Welte60aa5762018-03-21 19:33:13 +01004148type record CodecListTest {
4149 BSSMAP_IE_SpeechCodecList codec_list,
4150 charstring id
4151}
4152type record of CodecListTest CodecListTests
4153
4154private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004155 f_assignment_codec(id);
4156}
4157
4158private function f_assignment_codec(charstring id, boolean do_perform_clear := true) runs on MSC_ConnHdlr {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004159 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
4160 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
Harald Welte60aa5762018-03-21 19:33:13 +01004161
4162 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02004163 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte79f3f542018-05-25 20:02:37 +02004164 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
4165 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
4166 g_pars.ass_codec_list.codecElements[0];
Philipp Maierd0e64b02019-03-13 14:15:23 +01004167 if (isvalue(g_pars.expect_mr_s0_s7)) {
4168 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
4169 g_pars.expect_mr_s0_s7;
4170 }
Harald Welte79f3f542018-05-25 20:02:37 +02004171 }
Harald Welte60aa5762018-03-21 19:33:13 +01004172 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
4173 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01004174 log("expecting ASS COMPL like this: ", exp_compl);
4175
4176 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01004177
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004178 if (not g_pars.expect_channel_mode_modify) {
4179 /* Verify that the RSL-side activation actually matches our expectations */
4180 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
Harald Weltea63b9102018-03-22 20:36:16 +01004181
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004182 var RSL_IE_Body mode_ie;
4183 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
4184 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02004185 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004186 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004187 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
4188 if (not match(mode_ie, t_mode_ie)) {
4189 log("mode_ie ", mode_ie, " != t_mode_ie ", t_mode_ie);
4190 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004191 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004192
4193 var RSL_IE_Body mr_conf;
4194 if (g_pars.expect_mr_conf_ie != omit) {
4195 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
4196 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
4197 mtc.stop;
4198 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004199 log("found RSL MR CONFIG IE: ", mr_conf);
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004200
4201 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
4202 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
4203 g_pars.expect_mr_conf_ie);
4204 }
4205 } else {
4206 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
4207 log("found RSL MR CONFIG IE: ", mr_conf);
4208 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
4209 mtc.stop;
4210 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004211 }
4212 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004213
4214 if (do_perform_clear) {
4215 f_perform_clear();
4216 }
Harald Welte60aa5762018-03-21 19:33:13 +01004217}
4218
Philipp Maierd0e64b02019-03-13 14:15:23 +01004219private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
4220
4221 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4222 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4223
4224 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02004225 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maierd0e64b02019-03-13 14:15:23 +01004226 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
4227 }
4228 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
4229 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
4230 log("expecting ASS FAIL like this: ", exp_fail);
4231
4232 f_establish_fully(ass_cmd, exp_fail);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004233 f_perform_clear();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004234}
4235
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004236const CounterNameVals counternames_bsc_bts_assignment := {
4237 { "assignment:attempted", 0 },
4238 { "assignment:completed", 0 },
4239 { "assignment:stopped", 0 },
4240 { "assignment:no_channel", 0 },
4241 { "assignment:timeout", 0 },
4242 { "assignment:failed", 0 },
4243 { "assignment:error", 0 }
4244};
4245
4246const CounterNameVals counternames_bts_assignment := {
4247 { "assignment:attempted_sign", 0 },
4248 { "assignment:attempted_speech", 0 },
4249 { "assignment:completed_sign", 0 },
4250 { "assignment:completed_speech", 0 },
4251 { "assignment:stopped_sign", 0 },
4252 { "assignment:stopped_speech", 0 },
4253 { "assignment:no_channel_sign", 0 },
4254 { "assignment:no_channel_speech", 0 },
4255 { "assignment:timeout_sign", 0 },
4256 { "assignment:timeout_speech", 0 },
4257 { "assignment:failed_sign", 0 },
4258 { "assignment:failed_speech", 0 },
4259 { "assignment:error_sign", 0 },
4260 { "assignment:error_speech", 0 }
4261};
4262
4263function f_ctrs_bsc_and_bts_assignment_init(integer bts_count := NUM_BTS) runs on test_CT {
4264 var CounterNameVals bts_names := counternames_bsc_bts_assignment & counternames_bts_assignment;
4265 f_ctrs_bts_init(bts_count, bts_names);
4266 f_ctrs_bsc_init(counternames_bsc_bts_assignment);
4267}
4268
Harald Welte60aa5762018-03-21 19:33:13 +01004269testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004270 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004271 var MSC_ConnHdlr vc_conn;
4272
4273 f_init(1, true);
4274 f_sleep(1.0);
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004275 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004276
4277 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004278 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004279 vc_conn.done;
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004280
4281 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4282 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4283 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4284 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4285 f_ctrs_bts_verify();
4286
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004287 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004288}
4289
4290testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004291 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004292 var MSC_ConnHdlr vc_conn;
4293
4294 f_init(1, true);
4295 f_sleep(1.0);
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004296 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004297
4298 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004299 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004300 vc_conn.done;
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004301
4302 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4303 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4304 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4305 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4306 f_ctrs_bts_verify();
4307
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004308 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004309}
4310
4311testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004312 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004313 var MSC_ConnHdlr vc_conn;
4314
4315 f_init(1, true);
4316 f_sleep(1.0);
4317
4318 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004319 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004320 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004321 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004322}
4323
Philipp Maierd0e64b02019-03-13 14:15:23 +01004324/* Allow 5,90k only (current default config) */
4325private function f_allow_amr_rate_5_90k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00004326 f_vty_cfg_msc(BSCVTY, 0, {
4327 "amr-config 12_2k forbidden",
4328 "amr-config 10_2k forbidden",
4329 "amr-config 7_95k forbidden",
4330 "amr-config 7_40k forbidden",
4331 "amr-config 6_70k forbidden",
4332 "amr-config 5_90k allowed",
4333 "amr-config 5_15k forbidden",
4334 "amr-config 4_75k forbidden"
4335 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01004336}
4337
4338/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
4339 * ("Config-NB-Code = 1") */
4340private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00004341 f_vty_cfg_msc(BSCVTY, 0, {
4342 "amr-config 12_2k allowed",
4343 "amr-config 10_2k forbidden",
4344 "amr-config 7_95k forbidden",
4345 "amr-config 7_40k allowed",
4346 "amr-config 6_70k forbidden",
4347 "amr-config 5_90k allowed",
4348 "amr-config 5_15k forbidden",
4349 "amr-config 4_75k allowed"
4350 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01004351}
4352
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004353private function f_vty_amr_start_mode_set(boolean fr, charstring startmode) runs on test_CT {
4354 var charstring tch;
4355 if (fr) {
4356 tch := "tch-f";
4357 } else {
4358 tch := "tch-h";
4359 }
4360 f_vty_cfg_bts(BSCVTY, 0, { "amr " & tch & " start-mode " & startmode });
4361}
4362
4363/* Set the AMR start-mode for this TCH back to the default configuration. */
4364private function f_vty_amr_start_mode_restore(boolean fr) runs on test_CT {
4365 f_vty_amr_start_mode_set(fr, "auto");
4366}
4367
Harald Welte60aa5762018-03-21 19:33:13 +01004368testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004369 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004370 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02004371
4372 /* Note: This setups the codec configuration. The parameter payload in
4373 * mr_conf must be consistant with the parameter codecElements in pars
4374 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004375 var RSL_IE_Body mr_conf := {
4376 other := {
4377 len := 2,
4378 payload := '2804'O
4379 }
4380 };
Harald Welte60aa5762018-03-21 19:33:13 +01004381
Philipp Maier7695a0d2018-09-27 17:52:14 +02004382 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Philipp Maier806f8f12019-03-12 12:13:41 +01004383 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02004384 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
4385 pars.expect_mr_conf_ie := mr_conf;
4386
Harald Welte60aa5762018-03-21 19:33:13 +01004387 f_init(1, true);
4388 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004389 f_vty_amr_start_mode_set(true, "1");
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004390 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004391
Harald Welte8863fa12018-05-10 20:15:27 +02004392 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004393 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004394
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004395 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4396 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4397 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4398 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4399 f_ctrs_bts_verify();
4400
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004401 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004402 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004403}
4404
4405testcase TC_assignment_codec_amr_h() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004406 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004407 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02004408
4409 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004410 var RSL_IE_Body mr_conf := {
4411 other := {
4412 len := 2,
4413 payload := '2804'O
4414 }
4415 };
Harald Welte60aa5762018-03-21 19:33:13 +01004416
Philipp Maier7695a0d2018-09-27 17:52:14 +02004417 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Philipp Maier806f8f12019-03-12 12:13:41 +01004418 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02004419 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4420 pars.expect_mr_conf_ie := mr_conf;
4421
Harald Welte60aa5762018-03-21 19:33:13 +01004422 f_init(1, true);
4423 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004424 f_vty_amr_start_mode_set(false, "1");
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004425 f_ctrs_bsc_and_bts_assignment_init(1);
Harald Welte60aa5762018-03-21 19:33:13 +01004426
Harald Welte8863fa12018-05-10 20:15:27 +02004427 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004428 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004429
Neels Hofmeyrbcfc9442021-11-29 16:44:08 +01004430 f_ctrs_bsc_and_bts_add(0, "assignment:attempted", 1);
4431 f_ctrs_bts_add(0, "assignment:attempted_speech", 1);
4432 f_ctrs_bsc_and_bts_add(0, "assignment:completed", 1);
4433 f_ctrs_bts_add(0, "assignment:completed_speech", 1);
4434 f_ctrs_bts_verify();
4435
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004436 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004437 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004438}
4439
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004440/* Establish signalling on a TCH/F lchan, and then switch to speech mode without a new Assignment. */
4441testcase TC_assignment_codec_fr_by_mode_modify() runs on test_CT {
4442 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4443 var MSC_ConnHdlr vc_conn;
4444
4445 f_init(1, true);
4446 f_sleep(1.0);
4447
4448 /* By disabling all SDCCH, the MS should be given a TCH/F for signalling. Then activating an FR codec should
4449 * merely do a Channel Mode Modify, and not assign to a new lchan. f_establish_fully() already accounts for
4450 * expecting a Channel Mode Modify if the channel type is compatible. */
4451 f_disable_all_sdcch();
4452 f_disable_all_tch_h();
4453
4454 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4455 pars.expect_channel_mode_modify := true;
4456 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4457 vc_conn.done;
4458
4459 f_enable_all_sdcch();
4460 f_enable_all_tch();
4461 f_shutdown_helper();
4462}
4463
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004464/* 'amr start-mode auto' should not keep the (unused) 'smod' bits from previous configuration */
4465testcase TC_assignment_codec_amr_startmode_cruft() runs on test_CT {
4466 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4467 var MSC_ConnHdlr vc_conn;
4468
4469 var RSL_IE_Body mr_conf := {
4470 other := {
4471 len := 2,
4472 payload := '2004'O /* <- expect ICMI=0, smod=00 */
4473 }
4474 };
4475
4476 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4477 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
4478 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
4479 pars.expect_mr_conf_ie := mr_conf;
4480
4481 f_init(1, true);
4482 f_sleep(1.0);
4483
4484 /* First set nonzero start mode bits */
4485 f_vty_amr_start_mode_set(true, "4");
4486 /* Now set to auto, and expect the startmode bits to be zero in the message, i.e. ensure that osmo-bsc does not
4487 * let the startmode bits stick around and has deterministic MultiRate config for 'start-mode auto'; that is
4488 * ensured by above '2004'O, where 'x0xx'O indicates ICMI = 0, spare = 0, smod = 00. */
4489 f_vty_amr_start_mode_set(true, "auto");
4490
4491 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4492 vc_conn.done;
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004493
4494 /* Clear the startmode bits to not affect subsequent tests, in case the bits should indeed stick around. */
4495 f_vty_amr_start_mode_set(true, "1");
4496 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004497 f_shutdown_helper();
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004498}
4499
Neels Hofmeyr21863562020-11-26 00:34:33 +00004500function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0,
4501 charstring start_mode := "1")
Philipp Maierd0e64b02019-03-13 14:15:23 +01004502runs on test_CT {
4503
4504 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4505 var MSC_ConnHdlr vc_conn;
4506
4507 /* See note above */
4508 var RSL_IE_Body mr_conf := {
4509 other := {
4510 len := lengthof(mrconf),
4511 payload := mrconf
4512 }
4513 };
4514
4515 if (fr) {
4516 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4517 } else {
4518 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4519 }
4520 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4521 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4522 pars.expect_mr_conf_ie := mr_conf;
4523 pars.expect_mr_s0_s7 := exp_s8_s0;
4524
4525 f_init(1, true);
4526 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004527 f_vty_amr_start_mode_set(fr, start_mode);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004528 f_sleep(1.0);
4529
4530 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4531 vc_conn.done;
4532 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004533 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004534}
4535
4536function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
4537runs on test_CT {
4538
4539 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4540 var MSC_ConnHdlr vc_conn;
4541
4542 if (fr) {
4543 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4544 } else {
4545 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4546 }
4547 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4548 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4549
4550 f_init(1, true);
4551 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004552 f_vty_amr_start_mode_set(fr, "1");
Philipp Maierd0e64b02019-03-13 14:15:23 +01004553 f_sleep(1.0);
4554
4555 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
4556 vc_conn.done;
4557 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004558 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004559}
4560
4561
4562/* Set S1, we expect an AMR multirate configuration IE with all four rates
4563 * set. */
4564testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004565 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004566 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004567}
4568
4569/* Set S1, we expect an AMR multirate configuration IE with the lower three
4570 * rates set. */
4571testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004572 f_TC_assignment_codec_amr(false, '2815208820'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004573 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004574}
4575
4576/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4577 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4578testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004579 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004580 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004581}
4582
4583/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4584 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4585testcase TC_assignment_codec_amr_h_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004586 f_TC_assignment_codec_amr(false, '2815208820'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004587 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004588}
4589
4590/* The following block of tests selects more and more rates until all four
4591 * possible rates are in the active set (full rate) */
4592testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004593 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004594 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004595}
4596
4597testcase TC_assignment_codec_amr_f_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004598 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004599 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004600}
4601
4602testcase TC_assignment_codec_amr_f_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004603 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'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_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004608 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004609 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004610}
4611
4612/* The following block of tests selects more and more rates until all three
4613 * possible rates are in the active set (half rate) */
4614testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004615 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004616 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004617}
4618
4619testcase TC_assignment_codec_amr_h_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004620 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004621 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004622}
4623
4624testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004625 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004626 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004627}
4628
4629/* The following block tests what happens when the MSC does offer rate
4630 * configurations that are not supported by the BSC. Normally such situations
4631 * should not happen because the MSC gets informed by the BSC in advance via
4632 * the L3 COMPLETE message which rates are applicable. The MSC should not try
4633 * to offer rates that are not applicable anyway. */
4634
4635testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004636 /* Try to include 12,2k in into the active set even though the channel
4637 * is half rate only. The BSC is expected to remove the 12,0k */
4638 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004639 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004640}
4641
4642testcase TC_assignment_codec_amr_f_S01234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004643 /* See what happens when all rates are selected at once. Since then
4644 * Also S1 is selected, this setting will be prefered and we should
4645 * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
4646 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004647 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004648}
4649
4650testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004651 /* Same as above, but with S1 missing, the MSC is then expected to
4652 * select the currently supported rates, which are also 12.2k, 7,40k,
4653 * 5,90k, and 4,75k, into the active set. */
4654 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004655 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004656}
4657
4658testcase TC_assignment_codec_amr_f_zero() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004659 /* Try to select no rates at all */
4660 f_TC_assignment_codec_amr_fail(true, '00000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004661 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004662}
4663
4664testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004665 /* Try to select only unsupported rates */
4666 f_TC_assignment_codec_amr_fail(true, '01101000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004667 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004668}
4669
4670testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004671 /* Try to select 12,2k for half rate */
4672 f_TC_assignment_codec_amr_fail(false, '10000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004673 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004674}
4675
Neels Hofmeyr21863562020-11-26 00:34:33 +00004676testcase TC_assignment_codec_amr_f_start_mode_auto() runs on test_CT {
4677 f_TC_assignment_codec_amr(true, '209520882208'O, '11111111'B, '00000010'B,
4678 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004679 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004680}
4681
4682testcase TC_assignment_codec_amr_h_start_mode_auto() runs on test_CT {
4683 f_TC_assignment_codec_amr(false, '2015208820'O, '10010101'B, '00010101'B,
4684 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004685 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004686}
4687
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004688testcase TC_assignment_codec_amr_f_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004689 /* "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 +00004690 f_TC_assignment_codec_amr(true, '2b9520882208'O, '11111111'B, '00000010'B,
4691 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004692 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004693}
4694
4695testcase TC_assignment_codec_amr_h_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004696 /* "amr tch-h modes 0 2 4" => total 3 modes and start mode 4 => '10'B on the wire */
4697 f_TC_assignment_codec_amr(false, '2a15208820'O, '10010101'B, '00010101'B,
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004698 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004699 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004700}
4701
Philipp Maierac09bfc2019-01-08 13:41:39 +01004702private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004703 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
4704 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
4705 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
4706 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004707}
4708
4709private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004710 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
4711 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004712}
4713
4714private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004715 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
4716 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
4717 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
4718 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
4719 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
4720 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004721}
4722
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004723private function f_disable_all_sdcch() runs on test_CT {
4724 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 borken");
4725 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 borken");
4726 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 borken");
4727 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 borken");
4728}
4729
4730private function f_enable_all_sdcch() runs on test_CT {
4731 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 unused");
4732 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 unused");
4733 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 unused");
4734 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 unused");
4735}
4736
Philipp Maierac09bfc2019-01-08 13:41:39 +01004737/* Allow HR only */
4738private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
4739 g_pars := f_gen_test_hdlr_pars();
4740 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4741 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4742 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4743 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4744 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4745 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4746 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004747 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004748}
4749
4750/* Allow FR only */
4751private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
4752 g_pars := f_gen_test_hdlr_pars();
4753 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4754 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4755 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4756 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4757 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4758 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4759 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004760 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004761}
4762
4763/* Allow HR only (expect assignment failure) */
4764private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
4765 g_pars := f_gen_test_hdlr_pars();
4766 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4767 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4768 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4769 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4770 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4771 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4772 f_establish_fully(ass_cmd, exp_fail);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004773 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004774}
4775
4776/* Allow FR only (expect assignment failure) */
4777private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(charstring id) runs on MSC_ConnHdlr {
4778 g_pars := f_gen_test_hdlr_pars();
4779 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4780 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4781 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4782 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4783 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4784 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4785 f_establish_fully(ass_cmd, exp_fail);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004786 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004787}
4788
4789/* Allow FR and HR, but prefer FR */
4790private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4791 g_pars := f_gen_test_hdlr_pars();
4792 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4793 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4794 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4795 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4796 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4797 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4798 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4799 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004800 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004801}
4802
4803/* Allow FR and HR, but prefer HR */
4804private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4805 g_pars := f_gen_test_hdlr_pars();
4806 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4807 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4808 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4809 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4810 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4811 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4812 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4813 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004814 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004815}
4816
4817/* Allow FR and HR, but prefer FR */
4818private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4819 g_pars := f_gen_test_hdlr_pars();
4820 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4821 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4822 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4823 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4824 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4825 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4826 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4827 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004828 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004829}
4830
4831/* Allow FR and HR, but prefer HR */
4832private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4833 g_pars := f_gen_test_hdlr_pars();
4834 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4835 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4836 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4837 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4838 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4839 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4840 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4841 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004842 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004843}
4844
4845/* Request a HR channel while all FR channels are exhausted, this is expected
4846 * to work without conflicts */
4847testcase TC_assignment_codec_fr_exhausted_req_hr() runs on test_CT {
4848 var MSC_ConnHdlr vc_conn;
4849 f_init(1, true);
4850 f_sleep(1.0);
4851 f_enable_all_tch();
4852 f_disable_all_tch_f();
4853 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr));
4854 vc_conn.done;
4855 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004856 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004857}
4858
4859/* Request a FR channel while all FR channels are exhausted, this is expected
4860 * to fail. */
4861testcase TC_assignment_codec_fr_exhausted_req_fr() runs on test_CT {
4862 var MSC_ConnHdlr vc_conn;
4863 f_init(1, true);
4864 f_sleep(1.0);
4865 f_enable_all_tch();
4866 f_disable_all_tch_f();
4867 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr_fail));
4868 vc_conn.done;
4869 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004870 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004871}
4872
4873/* Request a FR (prefered) or alternatively a HR channel while all FR channels
4874 * are exhausted, this is expected to be resolved by selecting a HR channel. */
4875testcase TC_assignment_codec_fr_exhausted_req_fr_hr() runs on test_CT {
4876 var MSC_ConnHdlr vc_conn;
4877 f_init(1, true);
4878 f_sleep(1.0);
4879 f_enable_all_tch();
4880 f_disable_all_tch_f();
4881 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
4882 vc_conn.done;
4883 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004884 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004885}
4886
4887/* Request a HR (prefered) or alternatively a FR channel while all FR channels
4888 * are exhausted, this is expected to work without conflicts. */
4889testcase TC_assignment_codec_fr_exhausted_req_hr_fr() runs on test_CT {
4890 var MSC_ConnHdlr vc_conn;
4891 f_init(1, true);
4892 f_sleep(1.0);
4893 f_enable_all_tch();
4894 f_disable_all_tch_f();
4895 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_hr_fr));
4896 vc_conn.done;
4897 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004898 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004899}
4900
4901/* Request a FR channel while all HR channels are exhausted, this is expected
4902 * to work without conflicts */
4903testcase TC_assignment_codec_hr_exhausted_req_fr() runs on test_CT {
4904 var MSC_ConnHdlr vc_conn;
4905 f_init(1, true);
4906 f_sleep(1.0);
4907 f_enable_all_tch();
4908 f_disable_all_tch_h();
4909 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr));
4910 vc_conn.done;
4911 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004912 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004913}
4914
4915/* Request a HR channel while all HR channels are exhausted, this is expected
4916 * to fail. */
4917testcase TC_assignment_codec_hr_exhausted_req_hr() runs on test_CT {
4918 var MSC_ConnHdlr vc_conn;
4919 f_init(1, true);
4920 f_sleep(1.0);
4921 f_enable_all_tch();
4922 f_disable_all_tch_h();
4923 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr_fail));
4924 vc_conn.done;
4925 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004926 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004927}
4928
4929/* Request a HR (prefered) or alternatively a FR channel while all HR channels
4930 * are exhausted, this is expected to be resolved by selecting a FR channel. */
4931testcase TC_assignment_codec_hr_exhausted_req_hr_fr() runs on test_CT {
4932 var MSC_ConnHdlr vc_conn;
4933 f_init(1, true);
4934 f_sleep(1.0);
4935 f_enable_all_tch();
4936 f_disable_all_tch_h();
4937 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_hr_fr));
4938 vc_conn.done;
4939 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004940 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004941}
4942
4943/* Request a FR (prefered) or alternatively a HR channel while all HR channels
4944 * are exhausted, this is expected to work without conflicts. */
4945testcase TC_assignment_codec_hr_exhausted_req_fr_hr() runs on test_CT {
4946 var MSC_ConnHdlr vc_conn;
4947 f_init(1, true);
4948 f_sleep(1.0);
4949 f_enable_all_tch();
4950 f_disable_all_tch_h();
4951 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_fr_hr));
4952 vc_conn.done;
4953 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004954 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004955}
4956
4957/* Allow FR and HR, but prefer HR */
4958private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4959 g_pars := f_gen_test_hdlr_pars();
4960 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4961 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4962 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4963 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4964 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4965 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4966 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4967 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004968 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004969}
4970
4971/* Allow FR and HR, but prefer FR */
4972private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4973 g_pars := f_gen_test_hdlr_pars();
4974 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4975 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4976 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4977 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4978 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4979 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4980 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4981 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01004982 f_perform_clear();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004983}
4984
4985/* Request a HR (prefered) or alternatively a FR channel, it is expected that
4986 * HR, which is the prefered type, is selected. */
4987testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
4988 var MSC_ConnHdlr vc_conn;
4989 f_init(1, true);
4990 f_sleep(1.0);
4991 f_enable_all_tch();
4992 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
4993 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004994 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004995}
4996
4997/* Request a FR (prefered) or alternatively a HR channel, it is expected that
4998 * FR, which is the prefered type, is selected. */
4999testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
5000 var MSC_ConnHdlr vc_conn;
5001 f_init(1, true);
5002 f_sleep(1.0);
5003 f_enable_all_tch();
5004 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
5005 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005006 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01005007}
5008
Pau Espin Pedrol14475352021-07-22 15:48:16 +02005009/* request a signalling channel with all SDCCH exhausted, it is expected that a TCH will be selected */
5010private function f_TC_assignment_sdcch_exhausted_req_signalling(charstring id) runs on MSC_ConnHdlr {
5011 g_pars := f_gen_test_hdlr_pars();
5012 g_pars.ra := '02'O; /* RA containing reason=LU */
5013
5014 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
5015 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
5016 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
5017 var template uint3_t tsc := ?;
5018
5019 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
5020 f_create_bssmap_exp(l3_enc);
5021 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
5022 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, tsc);
5023
5024 /* we should now have a COMPL_L3 at the MSC */
5025 timer T := 10.0;
5026 T.start;
5027 alt {
5028 [] BSSAP.receive(tr_BSSMAP_ComplL3);
5029 [] T.timeout {
5030 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
5031 }
5032 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005033
5034 f_perform_clear();
Pau Espin Pedrol14475352021-07-22 15:48:16 +02005035}
5036testcase TC_assignment_sdcch_exhausted_req_signalling() runs on test_CT {
5037 var MSC_ConnHdlr vc_conn;
5038 f_init(1, true);
5039 f_sleep(1.0);
5040 f_disable_all_sdcch();
5041 vc_conn := f_start_handler(refers(f_TC_assignment_sdcch_exhausted_req_signalling));
5042 vc_conn.done;
5043 f_enable_all_sdcch();
5044 f_shutdown_helper();
5045}
5046
5047/* Request a signalling channel with all SDCCH exhausted, it is
5048 expected that no TCH will be selected for signalling and assigment will fail
5049 because it's dictated by VTY config */
5050testcase TC_assignment_sdcch_exhausted_req_signalling_tch_forbidden() runs on test_CT {
5051 var RSL_Message rsl_unused, rsl_msg;
5052 var GsmRrMessage rr;
5053 f_init(1, false);
5054 f_sleep(1.0);
5055 f_vty_allow_tch_for_signalling(false, 0);
5056 f_disable_all_sdcch();
5057
5058 /* RA containing reason=LU */
5059 f_ipa_tx(0, ts_RSL_CHAN_RQD('02'O, 2342));
5060 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
5061 rr := dec_GsmRrMessage(rsl_msg.ies[1].body.full_imm_ass_info.payload);
5062 if (rr.header.message_type != IMMEDIATE_ASSIGNMENT_REJECT) {
5063 setverdict(fail, "Expected reject");
5064 }
5065
5066 f_vty_allow_tch_for_signalling(true, 0);
5067 f_enable_all_sdcch();
5068 f_shutdown_helper();
5069}
5070
5071/* Request a voice channel with all SDCCH exhausted, it is
5072 * expected that TCH channel will be allocated since the VTY option is only
5073 * aimed at signalling requests */
5074private function f_TC_assignment_sdcch_exhausted_req_voice_tch_forbidden(charstring id) runs on MSC_ConnHdlr {
5075 g_pars := f_gen_test_hdlr_pars();
5076 g_pars.ra := '43'O; /* RA containing reason=originating speech call*/
5077
5078 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
5079 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
5080 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
5081 var template uint3_t tsc := ?;
5082
5083 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
5084 f_create_bssmap_exp(l3_enc);
5085 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
5086 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, tsc);
5087
5088 /* we should now have a COMPL_L3 at the MSC */
5089 timer T := 10.0;
5090 T.start;
5091 alt {
5092 [] BSSAP.receive(tr_BSSMAP_ComplL3);
5093 [] T.timeout {
5094 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
5095 }
5096 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005097 f_perform_clear();
Pau Espin Pedrol14475352021-07-22 15:48:16 +02005098}
5099testcase TC_assignment_sdcch_exhausted_req_voice_tch_forbidden() runs on test_CT {
5100 var MSC_ConnHdlr vc_conn;
5101 f_init(1, true);
5102 f_sleep(1.0);
5103 f_vty_allow_tch_for_signalling(false, 0);
5104 f_disable_all_sdcch();
5105
5106 vc_conn := f_start_handler(refers(f_TC_assignment_sdcch_exhausted_req_voice_tch_forbidden));
5107 vc_conn.done;
5108
5109 f_vty_allow_tch_for_signalling(true, 0);
5110 f_enable_all_sdcch();
5111 f_shutdown_helper();
5112}
5113
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005114testcase TC_assignment_osmux() runs on test_CT {
5115 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5116 var MSC_ConnHdlr vc_conn;
5117
5118 /* See note above */
5119 var RSL_IE_Body mr_conf := {
5120 other := {
5121 len := 2,
5122 payload := '2804'O
5123 }
5124 };
5125
5126 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
5127 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
5128 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
5129 pars.expect_mr_conf_ie := mr_conf;
5130 pars.use_osmux := true;
5131
5132 f_init(1, true, true);
5133 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00005134 f_vty_amr_start_mode_set(false, "1");
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005135
5136 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
5137 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00005138
5139 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01005140 f_shutdown_helper();
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02005141}
5142
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02005143/* test the procedure of the MSC requesting a Classmark Update:
5144 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
5145 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01005146private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005147 g_pars := f_gen_test_hdlr_pars();
5148
Harald Weltea0630032018-03-20 21:09:55 +01005149 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01005150 /* we should now have a COMPL_L3 at the MSC */
Harald Welte898113b2018-01-31 18:32:21 +01005151
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02005152 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
5153 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
5154
Harald Welte898113b2018-01-31 18:32:21 +01005155 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
5156 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
5157 setverdict(pass);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005158
5159 f_perform_clear();
Harald Welte898113b2018-01-31 18:32:21 +01005160}
5161testcase TC_classmark() runs on test_CT {
5162 var MSC_ConnHdlr vc_conn;
5163 f_init(1, true);
5164 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005165 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01005166 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005167 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01005168}
5169
Harald Welteeddf0e92020-06-21 19:42:15 +02005170/* Send a CommonID from the simulated MSC and verify that the information is used to
5171 * fill BSC-internal data structures (specifically, bsc_subscr associated with subscr_conn) */
5172private function f_tc_common_id(charstring id) runs on MSC_ConnHdlr {
5173 g_pars := f_gen_test_hdlr_pars();
5174 f_MscConnHdlr_init_vty();
5175
5176 f_create_chan_and_exp();
5177 /* we should now have a COMPL_L3 at the MSC */
Harald Welteeddf0e92020-06-21 19:42:15 +02005178
5179 /* Send CommonID */
5180 BSSAP.send(ts_BSSMAP_CommonId(g_pars.imsi));
5181
5182 /* Use VTY to verify that the IMSI of the subscr_conn is set */
5183 var charstring regex := "*(IMSI: " & hex2str(g_pars.imsi) & ")*";
5184 f_vty_transceive_match_regexp_retry(BSCVTY, "show conns", regex, 0, 4, 1.0);
5185
5186 setverdict(pass);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005187
5188 f_perform_clear();
Harald Welteeddf0e92020-06-21 19:42:15 +02005189}
5190testcase TC_common_id() runs on test_CT {
5191 var MSC_ConnHdlr vc_conn;
5192 f_init(1, true);
5193 f_sleep(1.0);
5194 vc_conn := f_start_handler(refers(f_tc_common_id));
5195 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005196 f_shutdown_helper();
Harald Welteeddf0e92020-06-21 19:42:15 +02005197}
5198
Harald Weltee3bd6582018-01-31 22:51:25 +01005199private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005200 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01005201 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01005202 /* we should now have a COMPL_L3 at the MSC */
Harald Welte898113b2018-01-31 18:32:21 +01005203
Harald Weltee3bd6582018-01-31 22:51:25 +01005204 /* send the single message we want to send */
5205 f_rsl_send_l3(l3);
5206}
5207
5208private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
5209 timer T := sec;
5210 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01005211 T.start;
5212 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01005213 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
5214 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02005215 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01005216 }
5217 [] T.timeout {
5218 setverdict(pass);
5219 }
5220 }
5221}
5222
Harald Weltee3bd6582018-01-31 22:51:25 +01005223/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
5224private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
5225 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
5226 f_bssap_expect_nothing();
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005227 f_perform_clear();
Harald Weltee3bd6582018-01-31 22:51:25 +01005228}
Harald Welte898113b2018-01-31 18:32:21 +01005229testcase TC_unsol_ass_fail() runs on test_CT {
5230 var MSC_ConnHdlr vc_conn;
5231 f_init(1, true);
5232 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005233 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01005234 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005235 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01005236}
Harald Welte552620d2017-12-16 23:21:36 +01005237
Harald Welteea99a002018-01-31 20:46:43 +01005238
5239/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
5240private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01005241 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
5242 f_bssap_expect_nothing();
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005243 f_perform_clear();
Harald Welteea99a002018-01-31 20:46:43 +01005244}
5245testcase TC_unsol_ass_compl() runs on test_CT {
5246 var MSC_ConnHdlr vc_conn;
5247 f_init(1, true);
5248 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005249 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01005250 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005251 f_shutdown_helper();
Harald Welteea99a002018-01-31 20:46:43 +01005252}
5253
5254
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005255/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
5256private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01005257 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
5258 f_bssap_expect_nothing();
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005259 f_perform_clear();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005260}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005261testcase TC_unsol_ho_fail() runs on test_CT {
5262 var MSC_ConnHdlr vc_conn;
5263 f_init(1, true);
5264 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005265 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005266 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005267 f_shutdown_helper();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005268}
5269
5270
Harald Weltee3bd6582018-01-31 22:51:25 +01005271/* short message from MS should be ignored */
5272private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005273 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01005274 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01005275 /* we should now have a COMPL_L3 at the MSC */
Harald Weltee3bd6582018-01-31 22:51:25 +01005276
5277 /* send short message */
5278 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
5279 f_bssap_expect_nothing();
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005280 f_perform_clear();
Harald Weltee3bd6582018-01-31 22:51:25 +01005281}
5282testcase TC_err_82_short_msg() runs on test_CT {
5283 var MSC_ConnHdlr vc_conn;
5284 f_init(1, true);
5285 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005286 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01005287 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005288 f_shutdown_helper();
Harald Weltee3bd6582018-01-31 22:51:25 +01005289}
5290
5291
Harald Weltee9e02e42018-01-31 23:36:25 +01005292/* 24.008 8.4 Unknown message must trigger RR STATUS */
5293private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
5294 f_est_single_l3(ts_RRM_UL_REL('00'O));
5295 timer T := 3.0
5296 alt {
5297 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
5298 setverdict(pass);
5299 }
5300 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01005301 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01005302 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005303 f_perform_clear();
Harald Weltee9e02e42018-01-31 23:36:25 +01005304}
5305testcase TC_err_84_unknown_msg() runs on test_CT {
5306 var MSC_ConnHdlr vc_conn;
5307 f_init(1, true);
5308 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005309 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01005310 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005311 f_shutdown_helper();
Harald Weltee9e02e42018-01-31 23:36:25 +01005312}
5313
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005314/***********************************************************************
5315 * Handover
5316 ***********************************************************************/
5317
Harald Welte94e0c342018-04-07 11:33:23 +02005318/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
5319private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
5320runs on test_CT {
5321 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
5322 " timeslot "&int2str(ts_nr)&" ";
5323 f_vty_transceive(BSCVTY, cmd & suffix);
5324}
5325
Harald Welte261af4b2018-02-12 21:20:39 +01005326/* 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 +07005327private function f_vty_ss_action(TELNETasp_PT pt, charstring suffix,
5328 uint8_t bts_nr, uint8_t trx_nr,
5329 in RslChannelNr chan_nr)
5330{
Harald Welte261af4b2018-02-12 21:20:39 +01005331 /* FIXME: resolve those from component-global state */
5332 var integer ts_nr := chan_nr.tn;
5333 var integer ss_nr;
5334 if (ischosen(chan_nr.u.ch0)) {
5335 ss_nr := 0;
5336 } else if (ischosen(chan_nr.u.lm)) {
5337 ss_nr := chan_nr.u.lm.sub_chan;
5338 } else if (ischosen(chan_nr.u.sdcch4)) {
5339 ss_nr := chan_nr.u.sdcch4.sub_chan;
5340 } else if (ischosen(chan_nr.u.sdcch8)) {
5341 ss_nr := chan_nr.u.sdcch8.sub_chan;
5342 } else {
5343 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02005344 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01005345 }
5346
5347 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
5348 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005349 f_vty_transceive(pt, cmd & suffix);
Harald Welte261af4b2018-02-12 21:20:39 +01005350}
5351
Neels Hofmeyr91401012019-07-11 00:42:35 +02005352/* Even though the VTY command to trigger handover takes a new BTS number as argument, behind the scenes osmo-bsc always
5353 * translates that to a target ARFCN+BSIC first. See bsc_vty.c trigger_ho_or_as(), which puts the selected BTS' neighbor
5354 * ident key (ARFCN + BSIC) in the struct passed on to handover_request(). handover_start() then resolves that to a
5355 * viable actual neighbor cell. So from the internal osmo-bsc perspective, we always request handover to an ARFCN + BSIC
5356 * pair, not really to a specific BTS number. */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005357private function f_vty_handover(TELNETasp_PT pt, uint8_t bts_nr, uint8_t trx_nr,
5358 in RslChannelNr chan_nr, uint8_t new_bts_nr)
5359{
5360 f_vty_ss_action(pt, "handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
Harald Welte261af4b2018-02-12 21:20:39 +01005361}
5362
5363/* intra-BSC hand-over between BTS0 and BTS1 */
5364private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02005365 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5366 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01005367
5368 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5369 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5370
Harald Weltea0630032018-03-20 21:09:55 +01005371 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005372 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Harald Welte261af4b2018-02-12 21:20:39 +01005373
5374 var HandoverState hs := {
5375 rr_ho_cmpl_seen := false,
5376 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02005377 old_chan_nr := -,
5378 expect_target_tsc := BTS_TSC[1]
Harald Welte261af4b2018-02-12 21:20:39 +01005379 };
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005380 /* issue hand-over command on VTY, from BTS 0 to BTS 1 */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005381 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
Harald Welte261af4b2018-02-12 21:20:39 +01005382 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
5383 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005384
5385 /* From the MGW perspective, a handover is is characterized by
5386 * performing one MDCX operation with the MGW. So we expect to see
5387 * one more MDCX during handover. */
5388 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
5389
Harald Welte261af4b2018-02-12 21:20:39 +01005390 alt {
5391 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01005392 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005393
Philipp Maier4dae0652018-11-12 12:03:26 +01005394 /* Since this is an internal handover we expect the BSC to inform the
5395 * MSC about the event */
5396 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
5397
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005398 /* Check the amount of MGCP transactions is still consistant with the
5399 * test expectation */
5400 f_check_mgcp_expectations()
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005401
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005402 var RSL_Message chan_act := f_rslem_get_last_act(RSL1_PROC, 0, g_chan_nr);
5403
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005404 /* Ensure the Channel Activation for the new channel contained the right encryption params. as_handover() set
5405 * 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 +02005406 f_verify_encr_info(chan_act);
5407
5408 f_chan_act_verify_tsc(chan_act, BTS_TSC[1]);
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005409
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005410 f_perform_clear(RSL1, RSL1_PROC);
5411
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01005412 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01005413}
5414
5415testcase TC_ho_int() runs on test_CT {
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02005416 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte261af4b2018-02-12 21:20:39 +01005417 var MSC_ConnHdlr vc_conn;
5418 f_init(2, true);
5419 f_sleep(1.0);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005420
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005421 pars.expect_tsc := BTS_TSC[0];
5422
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005423 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005424
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02005425 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
Harald Welte261af4b2018-02-12 21:20:39 +01005426 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005427
5428 /* from f_establish_fully() */
5429 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5430 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5431 /* from handover */
5432 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5433 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5434 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5435 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005436 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5437 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:completed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005438 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005439 f_shutdown_helper();
Harald Welte261af4b2018-02-12 21:20:39 +01005440}
Harald Weltee9e02e42018-01-31 23:36:25 +01005441
Oliver Smith7eabd312021-07-12 14:18:56 +02005442function 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 +02005443 var MSC_ConnHdlr vc_conn;
5444 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5445 pars.encr := valueof(t_EncrParams(encr_alg, f_rnd_octstring(8), f_rnd_octstring(16)));
5446
5447 f_init(2, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02005448 f_vty_encryption_a5(enc_a5);
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005449 f_sleep(1.0);
5450
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005451 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005452
5453 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
5454 vc_conn.done;
5455
5456 /* from f_establish_fully() */
5457 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5458 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5459 /* from handover */
5460 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5461 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5462 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5463 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005464 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5465 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:completed");
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005466 f_ctrs_bsc_and_bts_verify();
Oliver Smith7eabd312021-07-12 14:18:56 +02005467 f_vty_encryption_a5_reset();
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005468 f_shutdown_helper();
5469}
5470
5471testcase TC_ho_int_a5_0() runs on test_CT {
5472 f_tc_ho_int_a5('01'O);
5473}
5474
5475testcase TC_ho_int_a5_1() runs on test_CT {
5476 f_tc_ho_int_a5('02'O);
5477}
5478
5479testcase TC_ho_int_a5_3() runs on test_CT {
5480 f_tc_ho_int_a5('08'O);
5481}
5482
5483testcase TC_ho_int_a5_4() runs on test_CT {
Oliver Smith7eabd312021-07-12 14:18:56 +02005484 f_tc_ho_int_a5('10'O, "0 1 3 4");
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005485}
5486
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005487/* intra-BSC hand-over with CONNection FAILure and cause Radio Link Failure: check RR release cause */
5488private function f_tc_ho_int_radio_link_failure(charstring id) runs on MSC_ConnHdlr {
5489 g_pars := f_gen_test_hdlr_pars();
5490 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5491 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005492
5493 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5494 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5495
5496 f_establish_fully(ass_cmd, exp_compl);
5497 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
5498
5499 var HandoverState hs := {
5500 rr_ho_cmpl_seen := false,
5501 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02005502 old_chan_nr := -,
5503 expect_target_tsc := BTS_TSC[1]
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005504 };
5505 /* issue hand-over command on VTY */
5506 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
5507 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
5508 f_rslem_suspend(RSL1_PROC);
5509
5510 /* From the MGW perspective, a handover is is characterized by
5511 * performing one MDCX operation with the MGW. So we expect to see
5512 * one more MDCX during handover. */
5513 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
5514
5515 var RSL_Message rsl;
5516 var PDU_ML3_NW_MS l3;
5517 var RslChannelNr new_chan_nr;
5518 var GsmArfcn arfcn;
5519 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
5520 l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
5521 if (not ischosen(l3.msgs.rrm.handoverCommand)) {
5522 setverdict(fail, "Expected handoverCommand");
5523 mtc.stop;
5524 }
5525 }
5526 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
5527 new_chan_nr, arfcn);
5528
5529 f_rslem_register(0, new_chan_nr, RSL1_PROC);
5530
5531 /* resume processing of RSL DChan messages, which was temporarily suspended
5532 * before performing a hand-over */
5533 f_rslem_resume(RSL1_PROC);
5534 RSL1.receive(tr_RSL_IPA_CRCX(new_chan_nr));
5535
5536 f_sleep(1.0);
5537
5538 /* Handover fails because no HANDO DET appears on the new lchan,
5539 * and the old lchan reports a Radio Link Failure. */
5540 RSL.send(ts_RSL_CONN_FAIL_IND(g_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
5541
5542 var PDU_BSSAP rx_clear_request;
5543 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
5544 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5545 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5546
5547 var RR_Cause rr_cause := GSM48_RR_CAUSE_ABNORMAL_UNSPEC;
5548
5549 var MgcpCommand mgcp;
5550 interleave {
5551 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE(int2oct(enum2int(rr_cause), 1)))) {}
5552 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005553 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005554 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005555 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005556 }
5557 [] RSL1.receive(tr_RSL_DEACT_SACCH(new_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005558 [] RSL1.receive(tr_RSL_RF_CHAN_REL(new_chan_nr)) {
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005559 RSL1.send(ts_RSL_RF_CHAN_REL_ACK(new_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005560 f_rslem_unregister(0, g_chan_nr, PT := RSL1_PROC);
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005561 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005562 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
5563 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
5564 }
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005565 }
5566
5567 f_sleep(0.5);
5568 setverdict(pass);
5569}
5570testcase TC_ho_int_radio_link_failure() runs on test_CT {
5571 var MSC_ConnHdlr vc_conn;
5572 f_init(2, true);
5573 f_sleep(1.0);
5574
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005575 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005576
5577 vc_conn := f_start_handler(refers(f_tc_ho_int_radio_link_failure));
5578 vc_conn.done;
5579
5580 /* from f_establish_fully() */
5581 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5582 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5583 /* from handover */
5584 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5585 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
5586 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5587 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:stopped");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005588 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5589 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:stopped");
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005590 f_ctrs_bsc_and_bts_verify();
5591 f_shutdown_helper();
5592}
5593
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005594/* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005595private function f_expect_dlcx_conns() runs on MSC_ConnHdlr {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005596 var MgcpCommand mgcp;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005597 var template MgcpResponse mgcp_resp;
5598 var MGCP_RecvFrom mrf;
5599 var template MgcpMessage msg_resp;
5600 var template MgcpMessage msg_dlcx := {
5601 command := tr_DLCX()
5602 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005603
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005604 if (g_pars.aoip) {
5605 MGCP.receive(tr_DLCX()) -> value mgcp {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005606 log("Got first DLCX: ", mgcp);
5607 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005608 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005609
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005610 MGCP.receive(tr_DLCX()) -> value mgcp {
5611 log("Got second DLCX: ", mgcp);
5612 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
5613 };
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005614 } else {
5615 /* For SCCPLite, BSC doesn't handle the MSC-side */
5616 MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_dlcx)) -> value mrf {
5617 log("Got first DLCX: ", mrf.msg.command);
5618 msg_resp := {
5619 response := ts_DLCX_ACK2(mrf.msg.command.line.trans_id)
5620 }
5621 MGCP_MULTI.send(t_MGCP_SendToMrf(mrf, msg_resp));
5622 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005623 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005624}
5625
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005626private 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 +01005627
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005628 var NcellReports neighbor_rep := {
5629 { rxlev := 20, bcch_freq := 0, bsic := 11 }
5630 };
5631 var octetstring l3_mr := enc_GsmRrL3Message(valueof(ts_MEAS_REP(true, 8, 8, reps := neighbor_rep)));
5632 RSL.send(ts_RSL_MEAS_RES(g_chan_nr, 0, ts_RSL_IE_UplinkMeas, ts_RSL_IE_BS_Power(0), ts_RSL_IE_L1Info,
5633 l3_mr, 0));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005634
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005635 BSSAP.receive(tr_BSSMAP_HandoverRequired(exp_oldToNewBSSIEs));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005636
5637 f_sleep(0.5);
5638 /* The MSC negotiates Handover Request and Handover Request Ack with
5639 * the other BSS and comes back with a BSSMAP Handover Command
5640 * containing an RR Handover Command coming from the target BSS... */
5641
5642 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5643 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5644 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5645 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5646 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5647
5648 /* expect the Handover Command to go out on RR */
5649 var RSL_Message rsl_ho_cmd
5650 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5651 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5652 var RSL_IE_Body rsl_ho_cmd_l3;
5653 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5654 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5655 setverdict(fail);
5656 } else {
5657 log("Found L3 Info: ", rsl_ho_cmd_l3);
5658 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5659 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5660 setverdict(fail);
5661 } else {
5662 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5663 setverdict(pass);
5664 }
5665 }
5666
5667 /* When the other BSS has reported a completed handover, this side is
5668 * torn down. */
5669
5670 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
5671 var BssmapCause cause := enum2int(cause_val);
5672 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5673
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005674 f_expect_dlcx_conns();
Pau Espin Pedrol06199952021-06-15 11:30:00 +02005675
5676 interleave {
5677 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE));
5678 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr));
5679 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr));
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005680 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
5681 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
5682 }
Pau Espin Pedrol06199952021-06-15 11:30:00 +02005683 }
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005684 setverdict(pass);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005685}
5686
5687private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
5688 g_pars := f_gen_test_hdlr_pars();
5689 var PDU_BSSAP ass_req := f_gen_ass_req();
5690 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5691 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5692 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5693 f_establish_fully(ass_req, exp_compl);
5694
5695 f_ho_out_of_this_bsc();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005696}
5697testcase TC_ho_out_of_this_bsc() runs on test_CT {
5698 var MSC_ConnHdlr vc_conn;
5699
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005700 f_init_vty();
5701 f_bts_0_cfg(BSCVTY,
5702 {"neighbor-list mode automatic",
5703 "handover 1",
5704 "handover algorithm 2",
5705 "handover2 window rxlev averaging 1",
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005706 "no neighbors",
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005707 "neighbor lac 99 arfcn 123 bsic any"});
5708 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5709
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005710 f_init(1, true);
5711 f_sleep(1.0);
5712
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005713 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005714
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005715 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
5716 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005717
5718 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5719 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5720 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5721 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5722 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5723 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed");
5724 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005725 f_shutdown_helper();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005726}
5727
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005728private function f_mo_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5729 template (value) RslLinkId link_id := ts_RslLinkID_DCCH(0),
Vadim Yanitskiy2ef6a2f2020-10-08 23:17:32 +07005730 template (present) OCT1 dlci := ?,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005731 octetstring l3 := '0123456789'O)
5732runs on MSC_ConnHdlr {
Neels Hofmeyr43654812020-09-25 01:35:35 +02005733 /* The old lchan and conn should still be active. See that arbitrary L3
5734 * is still going through. */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005735 rsl.send(ts_RSL_DATA_IND(g_chan_nr, link_id, l3));
Neels Hofmeyr43654812020-09-25 01:35:35 +02005736 var template PDU_BSSAP exp_data := {
5737 discriminator := '1'B,
5738 spare := '0000000'B,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005739 dlci := dlci,
5740 lengthIndicator := lengthof(l3),
Neels Hofmeyr43654812020-09-25 01:35:35 +02005741 pdu := {
5742 dtap := l3
5743 }
5744 };
5745 BSSAP.receive(exp_data);
5746 setverdict(pass);
5747}
5748
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005749private function f_mt_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5750 template (present) RslLinkId link_id := tr_RslLinkID_DCCH(0),
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005751 template (value) OCT1 dlci := '00'O,
5752 octetstring l3 := '0123456789'O)
5753runs on MSC_ConnHdlr {
5754 BSSAP.send(PDU_BSSAP:{
5755 discriminator := '1'B,
5756 spare := '0000000'B,
5757 dlci := dlci,
5758 lengthIndicator := lengthof(l3),
5759 pdu := {
5760 dtap := l3
5761 }
5762 });
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005763 rsl.receive(tr_RSL_DATA_REQ(g_chan_nr, link_id, l3));
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005764 setverdict(pass);
5765}
5766
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005767/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
5768 * simply never sends a BSSMAP Handover Command. */
5769private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005770 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005771
5772 var PDU_BSSAP ass_req := f_gen_ass_req();
5773 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5774 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5775 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5776 f_establish_fully(ass_req, exp_compl);
5777
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005778 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005779 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5780
5781 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5782
5783 /* osmo-bsc should time out 10 seconds after the handover started.
5784 * Let's give it a bit extra. */
5785 f_sleep(15.0);
5786
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005787 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005788 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005789 f_perform_clear();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005790}
5791testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
5792 var MSC_ConnHdlr vc_conn;
5793
5794 f_init(1, true);
5795 f_sleep(1.0);
5796
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005797 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005798
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005799 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
5800 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005801
5802 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5803 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5804 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5805 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5806 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5807 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5808 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005809 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005810}
5811
5812/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
5813 * RR Handover Failure. */
5814private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005815 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005816
5817 var PDU_BSSAP ass_req := f_gen_ass_req();
5818 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5819 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5820 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5821 f_establish_fully(ass_req, exp_compl);
5822
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005823 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005824 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5825
5826 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5827
5828 f_sleep(0.5);
5829 /* The MSC negotiates Handover Request and Handover Request Ack with
5830 * the other BSS and comes back with a BSSMAP Handover Command
5831 * containing an RR Handover Command coming from the target BSS... */
5832
5833 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5834 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5835 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5836 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5837 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5838
5839 /* expect the Handover Command to go out on RR */
5840 var RSL_Message rsl_ho_cmd
5841 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5842 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5843 var RSL_IE_Body rsl_ho_cmd_l3;
5844 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5845 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5846 setverdict(fail);
5847 } else {
5848 log("Found L3 Info: ", rsl_ho_cmd_l3);
5849 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5850 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5851 setverdict(fail);
5852 } else {
5853 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5854 setverdict(pass);
5855 }
5856 }
5857
5858 f_sleep(0.2);
5859 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
5860
5861 /* Should tell the MSC about the failure */
5862 BSSAP.receive(tr_BSSMAP_HandoverFailure);
5863
5864 f_sleep(1.0);
5865
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005866 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005867 f_sleep(1.0);
5868
5869 setverdict(pass);
5870 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005871 f_perform_clear();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005872}
5873testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
5874 var MSC_ConnHdlr vc_conn;
5875
5876 f_init(1, true);
5877 f_sleep(1.0);
5878
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005879 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005880
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005881 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
5882 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005883
5884 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5885 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5886 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5887 f_ctrs_bsc_and_bts_add(0, "handover:failed");
5888 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5889 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:failed");
5890 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005891 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005892}
5893
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005894/* BSC asks for inter-BSC-out HO, receives BSSMAP Handover Command, but then no reply is received about HO outcome
5895 * (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 +02005896 * and the lchan is released. */
5897private function f_tc_ho_out_fail_no_result_after_ho_cmd(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005898 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005899
5900 var PDU_BSSAP ass_req := f_gen_ass_req();
5901 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5902 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5903 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5904 f_establish_fully(ass_req, exp_compl);
5905
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01005906 f_bts_0_cfg(BSCVTY, {"no neighbor lac 99", "neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005907 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5908
5909 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5910
5911 f_sleep(0.5);
5912 /* The MSC negotiates Handover Request and Handover Request Ack with
5913 * the other BSS and comes back with a BSSMAP Handover Command
5914 * containing an RR Handover Command coming from the target BSS... */
5915
5916 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5917 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5918 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5919 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5920 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5921
5922 /* expect the Handover Command to go out on RR */
5923 var RSL_Message rsl_ho_cmd
5924 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5925 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5926 var RSL_IE_Body rsl_ho_cmd_l3;
5927 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5928 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5929 setverdict(fail);
5930 } else {
5931 log("Found L3 Info: ", rsl_ho_cmd_l3);
5932 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5933 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5934 setverdict(fail);
5935 } else {
5936 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5937 setverdict(pass);
5938 }
5939 }
5940
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005941 /* We get neither success nor failure report from the remote BSS. Eventually T8 times out and we run into 3GPP
5942 * TS 48.008 3.1.5.3.3 "Abnormal Conditions": Clear Request should go to the MSC, and RR should be released
5943 * after Clear Command */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005944
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005945 var PDU_BSSAP rx_clear_request;
Neels Hofmeyre1797aa2019-07-09 19:34:04 +02005946 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
5947 log("Got BSSMAP Clear Request");
5948 /* Instruct BSC to clear channel */
5949 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5950 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5951
5952 var MgcpCommand mgcp;
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005953 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01005954 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
5955 log("Got Deact SACCH");
5956 }
Harald Welte924b6ea2019-02-04 01:05:34 +01005957 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01005958 log("Got RR Release");
5959 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005960 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005961 log("Got RF Chan Rel");
5962 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005963 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005964 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005965 }
5966
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005967 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02005968 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01005969 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005970
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005971 setverdict(pass);
5972 f_sleep(1.0);
5973}
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02005974testcase TC_ho_out_fail_no_result_after_ho_cmd() runs on test_CT {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005975 var MSC_ConnHdlr vc_conn;
5976
5977 f_init(1, true);
5978 f_sleep(1.0);
5979
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005980 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005981
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02005982 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_result_after_ho_cmd));
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005983 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005984
5985 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5986 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5987 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5988 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5989 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5990 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5991 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005992 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005993}
5994
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005995private function f_ho_into_this_bsc(charstring id, template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit) runs on MSC_ConnHdlr {
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01005996 var PDU_BSSAP rx_bssap;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005997 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
5998 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
5999 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
6000 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
6001 * before we get started. */
6002 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6003 f_rslem_register(0, new_chan_nr);
6004 g_chan_nr := new_chan_nr;
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02006005 var uint3_t expect_target_tsc := BTS_TSC[0];
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006006 f_sleep(1.0);
6007
6008 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6009 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6010 activate(as_Media());
6011
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006012 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006013 f_gen_handover_req(aoip_tla := g_pars.host_aoip_tla,
Pau Espin Pedrola8ef3be2022-02-16 16:21:17 +01006014 cell_id_source := g_pars.cell_id_source,
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006015 oldToNewBSSIEs := oldToNewBSSIEs,
6016 enc := g_pars.encr)));
Harald Welte6811d102019-04-14 22:23:14 +02006017 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006018
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006019 alt {
6020 [] BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap {
6021 if (g_pars.expect_ho_fail) {
6022 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6023 "Expected Handover Request to fail, but got Handover Request Ack")
6024 }
6025 }
6026 [] BSSAP.receive(tr_BSSMAP_HandoverFailure) -> value rx_bssap {
6027 if (not g_pars.expect_ho_fail) {
6028 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6029 "Expected Handover Request to succeed, but got Handover Failure")
6030 }
6031 // TODO: evaluate correct cause value. But osmo-bsc doesn't seem to send meaningful causes yet!
6032 // For now just accept any cause.
6033 BSSAP.receive(tr_BSSMAP_ClearRequest);
6034 setverdict(pass);
6035 return;
6036 }
6037 }
6038
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006039 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6040
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02006041 /* we're sure that the channel activation is done now, verify the parameters in it */
6042 var RSL_Message chan_act := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
6043 f_verify_encr_info(chan_act);
6044 f_chan_act_verify_tsc(chan_act, expect_target_tsc);
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006045
Neels Hofmeyr46e16e52022-02-23 17:04:00 +01006046 if (ispresent(rx_bssap.pdu.bssmap.handoverRequestAck.codecList)) {
6047 if (not g_pars.aoip) {
6048 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6049 "handoverRequestAck: Expected no Speech Codec List (BSS Supported), because this is not AoIP");
6050 }
6051 /* TODO: check actual codecs? */
6052 } else {
6053 if (g_pars.aoip) {
6054 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6055 "handoverRequestAck: Expected Speech Codec List (BSS Supported), but none found");
6056 }
6057 }
6058
6059 if (ispresent(rx_bssap.pdu.bssmap.handoverRequestAck.speechCodec)) {
6060 if (not g_pars.aoip) {
6061 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6062 "handoverRequestAck: Expected no Speech Codec (Chosen), because this is not AoIP");
6063 }
6064 /* TODO: check actual codec? */
6065 } else {
6066 if (g_pars.aoip) {
6067 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
6068 "handoverRequestAck: Expected Speech Codec (Chosen), but none found");
6069 }
6070 }
6071
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006072 var octetstring ho_command_str;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006073 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6074 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6075 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6076 log("L3 Info in HO Request Ack is ", ho_command);
6077
6078 var GsmArfcn arfcn;
6079 var RslChannelNr actual_new_chan_nr;
6080 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6081 actual_new_chan_nr, arfcn);
6082
6083 if (actual_new_chan_nr != new_chan_nr) {
6084 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6085 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6086 setverdict(fail);
6087 return;
6088 }
6089 log("Handover Command chan_nr is", actual_new_chan_nr);
6090
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02006091 var uint3_t got_tsc := rr_chan_desc_tsc(ho_command.msgs.rrm.handoverCommand.channelDescription2);
6092 if (not match(got_tsc, expect_target_tsc)) {
6093 setverdict(fail, "RR Handover Command: unexpected TSC in Channel Description: expected ",
6094 expect_target_tsc, " got ", got_tsc);
6095 mtc.stop;
6096 } else {
6097 log("handoverCommand: verified TSC = ", got_tsc);
6098 }
6099
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006100 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6101 * tells the MS to handover to the new lchan. Here comes the new MS on
6102 * the new lchan with a Handover RACH: */
6103
6104 /* send handover detect */
6105
6106 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
6107
6108 BSSAP.receive(tr_BSSMAP_HandoverDetect);
6109
6110 /* send handover complete over the new channel */
6111
6112 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
6113 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
6114 enc_PDU_ML3_MS_NW(l3_tx)));
6115
6116 BSSAP.receive(tr_BSSMAP_HandoverComplete);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006117 setverdict(pass);
6118}
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006119
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006120private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006121 var template PDU_ML3_NW_MS exp_rr_rel_tmpl;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006122 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit;
6123 if (not istemplatekind(g_pars.last_used_eutran_plmn, "omit")) {
6124 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006125 }
6126 if (g_pars.exp_fast_return) {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006127 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE_CellSelectInd;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006128 } else {
6129 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006130 }
6131 f_ho_into_this_bsc(id, oldToNewBSSIEs);
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006132 if (g_pars.expect_ho_fail) {
6133 f_perform_clear_no_lchan();
6134 } else {
6135 f_perform_clear(exp_rr_rel_tmpl := exp_rr_rel_tmpl);
6136 }
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006137 setverdict(pass);
6138}
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01006139function f_tc_ho_into_this_bsc_main(TestHdlrParams pars, charstring vty_a5_cfg := VTY_A5_DEFAULT) runs on test_CT {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006140 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006141
6142 f_init(1, true);
6143 f_sleep(1.0);
6144
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01006145 f_vty_encryption_a5(vty_a5_cfg);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006146 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006147
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006148 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6149 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006150
6151 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
6152 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006153
6154 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006155 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006156 if (pars.expect_ho_fail) {
6157 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6158 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:failed");
6159 } else {
6160 f_ctrs_bsc_and_bts_add(0, "handover:completed");
6161 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed");
6162 }
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006163 f_ctrs_bsc_and_bts_verify();
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01006164
6165 f_vty_encryption_a5_reset();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006166}
6167
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006168testcase TC_ho_into_this_bsc() runs on test_CT {
6169 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6170 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006171 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006172}
6173
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006174function f_tc_ho_into_this_bsc_a5(TestHdlrEncrParams encr, charstring vty_a5_cfg := VTY_A5_DEFAULT,
6175 boolean expect_fail := false) runs on test_CT {
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006176 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01006177 pars.encr := encr;
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006178 pars.expect_ho_fail := expect_fail;
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01006179 f_tc_ho_into_this_bsc_main(pars, vty_a5_cfg);
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006180 f_shutdown_helper();
6181}
6182
6183testcase TC_ho_into_this_bsc_a5_0() runs on test_CT {
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01006184 f_tc_ho_into_this_bsc_a5(f_encr_params('01'O));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006185}
6186
6187testcase TC_ho_into_this_bsc_a5_1() runs on test_CT {
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01006188 f_tc_ho_into_this_bsc_a5(f_encr_params('02'O));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006189}
6190
6191testcase TC_ho_into_this_bsc_a5_3() runs on test_CT {
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01006192 f_tc_ho_into_this_bsc_a5(f_encr_params('08'O));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006193}
6194
6195testcase TC_ho_into_this_bsc_a5_4() runs on test_CT {
Neels Hofmeyr731ddc52022-02-17 21:56:15 +01006196 f_tc_ho_into_this_bsc_a5(f_encr_params('10'O, kc128 := true), "3 4");
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02006197}
6198
Neels Hofmeyr1951be22022-02-16 16:21:07 +01006199/* Report: in inter-BSC incoming handover, when the MSC omits the Chosen Encryption Algorithm IE in the Handover Request
6200 * message, then osmo-bsc starts an unencrypted lchan even if A5/0 is not permitted.
6201 *
6202 * This test verifies that the Encryption Information is present in the Channel Activation when the Chosen Enc Alg is
6203 * omitted.
6204 *
6205 * Related: SYS#5839
6206 */
6207testcase TC_ho_into_this_bsc_a5_1_3_no_chosen_enc_alg() runs on test_CT {
6208 f_tc_ho_into_this_bsc_a5(f_encr_params(alg_permitted := '0a'O, alg_expect := '08'O, alg_chosen := omit));
6209}
6210
6211testcase TC_ho_into_this_bsc_a5_1_3() runs on test_CT {
6212 f_tc_ho_into_this_bsc_a5(f_encr_params(alg_permitted := '0a'O, alg_expect := '08'O));
6213}
6214
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01006215/* Send a permitted algo mask that does not intersect with osmo-bsc.cfg */
6216testcase TC_ho_into_this_bsc_a5_mismatch() runs on test_CT {
6217 f_tc_ho_into_this_bsc_a5(f_encr_params(alg_permitted := '18'O, alg_expect := '10'O), "0 1",
6218 expect_fail := true); // 0x18 = A5/3 and A5/4
6219}
6220
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006221testcase TC_ho_into_this_bsc_tla_v6() runs on test_CT {
6222 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6223 pars.host_aoip_tla := "::6";
6224 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006225 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02006226}
6227
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006228/* Similar to TC_ho_into_this_bsc, but when in SRVCC, HO Req contains "Old BSS
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006229 to New BSS Information" IE with "Last Used E-UTRAN PLMN Id", which, when the
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006230 channel is later released (RR CHannel Release), should trigger inclusion of
6231 IE "Cell Selection Indicator after Release of all TCH and SDCCH" with E-UTRAN
6232 neighbors. */
6233testcase TC_srvcc_eutran_to_geran() runs on test_CT {
6234 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6235 pars.last_used_eutran_plmn := '323454'O;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006236 pars.exp_fast_return := true;
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006237 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02006238
6239 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted");
6240 f_ctrs_bsc_and_bts_add(0, "srvcc:completed");
6241 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02006242 f_shutdown_helper();
6243}
6244
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006245/* Same as TC_srvcc_eutran_to_geran, but test explicitly forbiding fast return
6246 on the BTS. As a result, RR Release shouldn't contain the EUTRAN neighbor
6247 list when the channel is released. */
6248testcase TC_srvcc_eutran_to_geran_forbid_fast_return() runs on test_CT {
6249 f_init_vty();
6250 f_vty_allow_srvcc_fast_return(true, 0)
6251
6252 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6253 pars.last_used_eutran_plmn := '323454'O;
6254 pars.exp_fast_return := false;
6255 f_tc_ho_into_this_bsc_main(pars);
6256 f_vty_allow_srvcc_fast_return(false, 0);
6257 f_shutdown_helper();
6258}
6259
Pau Espin Pedrola8ef3be2022-02-16 16:21:17 +01006260/* Same as TC_srvcc_eutran_to_geran, but using SAI as serving Cell Identifier. SYS#5838 */
6261testcase TC_srvcc_eutran_to_geran_src_sai() runs on test_CT {
6262 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6263 pars.last_used_eutran_plmn := '323454'O;
6264 pars.cell_id_source := valueof(ts_CellID_SAI('123456'O, 300, 444));
6265 f_tc_ho_into_this_bsc_main(pars);
6266
6267 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted");
6268 f_ctrs_bsc_and_bts_add(0, "srvcc:completed");
6269 f_ctrs_bsc_and_bts_verify();
6270 f_shutdown_helper();
6271}
6272
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006273private function f_tc_srvcc_eutran_to_geran_ho_out(charstring id) runs on MSC_ConnHdlr {
6274 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs;
6275 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
6276 f_ho_into_this_bsc(id, oldToNewBSSIEs);
6277 f_ho_out_of_this_bsc(oldToNewBSSIEs);
6278 setverdict(pass);
6279}
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006280
6281private function f_tc_srvcc_eutran_to_geran_ho_out_main(boolean disable_fast_return)
6282 runs on test_CT {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006283 var MSC_ConnHdlr vc_conn;
6284 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6285
Neels Hofmeyr6cc90eb2021-12-15 12:49:39 +01006286 f_init_vty();
6287 f_bts_0_cfg(BSCVTY,
6288 {"neighbor-list mode automatic",
6289 "handover 1",
6290 "handover algorithm 2",
6291 "handover2 window rxlev averaging 1",
6292 "no neighbors",
6293 "neighbor lac 99 arfcn 123 bsic any"});
6294 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6295
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006296 f_init(1, true);
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006297 if (disable_fast_return) {
6298 f_vty_allow_srvcc_fast_return(true, 0);
6299 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006300 f_sleep(1.0);
6301
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006302 f_ctrs_bsc_and_bts_handover_init();
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006303
6304 pars.last_used_eutran_plmn := '323454'O;
6305 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6306 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
6307
6308 vc_conn := f_start_handler(refers(f_tc_srvcc_eutran_to_geran_ho_out), pars);
6309 vc_conn.done;
6310
6311 f_ctrs_bsc_and_bts_add(0, "handover:attempted", 2);
6312 f_ctrs_bsc_and_bts_add(0, "handover:completed", 2);
6313 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted", 1);
6314 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed", 1);
6315 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted", 1);
6316 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed", 1);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02006317
6318 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted", 1);
6319 f_ctrs_bsc_and_bts_add(0, "srvcc:completed", 1);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006320 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006321
6322 if (disable_fast_return) {
6323 f_vty_allow_srvcc_fast_return(false, 0);
6324 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006325 f_shutdown_helper();
6326}
6327
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006328/* First, HO into BSC from EUTRAN (SRVCC): HO Request contains "Old BSS to New
6329 BSS Information" IE with "Last Used E-UTRAN PLMN Id".
6330 Second, HO to another BSC: HO Required contains "Old BSS to New BSS Information"
6331 IE with "Last Used E-UTRAN PLMN Id" from first step. */
6332testcase TC_srvcc_eutran_to_geran_ho_out() runs on test_CT {
6333 f_tc_srvcc_eutran_to_geran_ho_out_main(false);
6334}
6335/* Validate subsequent intra-GSM-HO works the same (with OldBSSToNewBSSInfo IE)
6336 * independently of fast-reture allowed/forbidden in local BTS */
6337testcase TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() runs on test_CT {
6338 f_tc_srvcc_eutran_to_geran_ho_out_main(true);
6339}
6340
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006341private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
6342 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6343 f_rslem_register(0, new_chan_nr);
6344 g_chan_nr := new_chan_nr;
6345 f_sleep(1.0);
6346
6347 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6348 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6349 activate(as_Media());
6350
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006351 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006352 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006353 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006354
6355 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6356
6357 var PDU_BSSAP rx_bssap;
6358 var octetstring ho_command_str;
6359
6360 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6361
6362 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6363 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6364 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6365 log("L3 Info in HO Request Ack is ", ho_command);
6366
6367 var GsmArfcn arfcn;
6368 var RslChannelNr actual_new_chan_nr;
6369 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6370 actual_new_chan_nr, arfcn);
6371
6372 if (actual_new_chan_nr != new_chan_nr) {
6373 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6374 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6375 setverdict(fail);
6376 return;
6377 }
6378 log("Handover Command chan_nr is", actual_new_chan_nr);
6379
Neels Hofmeyr61ca08d2019-05-06 23:52:22 +02006380 /* For deterministic test results, give some time for the MGW endpoint to be configured */
6381 f_sleep(1.0);
6382
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006383 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6384 * tells the MS to handover to the new lchan. In this case, the MS
6385 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
6386 * Handover Failure to the MSC. The procedure according to 3GPP TS
6387 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
6388 * BSSMAP Clear Command: */
6389
6390 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6391 var BssmapCause cause := enum2int(cause_val);
6392 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6393
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006394 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006395 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006396 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006397
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006398 setverdict(pass);
6399 f_sleep(1.0);
6400
6401 setverdict(pass);
6402}
6403testcase TC_ho_in_fail_msc_clears() runs on test_CT {
6404 var MSC_ConnHdlr vc_conn;
6405 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6406
6407 f_init(1, true);
6408 f_sleep(1.0);
6409
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006410 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006411
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006412 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6413 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006414
6415 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
6416 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006417
6418 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6419 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
6420 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6421 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
6422 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006423 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006424}
6425
6426private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
6427 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
6428 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
6429 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
6430 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
6431 * before we get started. */
6432 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6433 f_rslem_register(0, new_chan_nr);
6434 g_chan_nr := new_chan_nr;
6435 f_sleep(1.0);
6436
6437 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6438 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6439 activate(as_Media());
6440
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006441 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006442 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006443 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006444
6445 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6446
6447 var PDU_BSSAP rx_bssap;
6448 var octetstring ho_command_str;
6449
6450 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6451
6452 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6453 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6454 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6455 log("L3 Info in HO Request Ack is ", ho_command);
6456
6457 var GsmArfcn arfcn;
6458 var RslChannelNr actual_new_chan_nr;
6459 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6460 actual_new_chan_nr, arfcn);
6461
6462 if (actual_new_chan_nr != new_chan_nr) {
6463 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6464 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6465 setverdict(fail);
6466 return;
6467 }
6468 log("Handover Command chan_nr is", actual_new_chan_nr);
6469
6470 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6471 * tells the MS to handover to the new lchan. Here comes the new MS on
6472 * the new lchan with a Handover RACH: */
6473
6474 /* send handover detect */
6475
6476 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
6477
6478 BSSAP.receive(tr_BSSMAP_HandoverDetect);
6479
6480 /* The MSC chooses to clear the connection now, maybe we got the
6481 * Handover RACH on the new cell but the MS still signaled Handover
6482 * Failure to the old BSS? */
6483
6484 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6485 var BssmapCause cause := enum2int(cause_val);
6486 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6487
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006488 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006489 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006490 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006491
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006492 f_sleep(1.0);
6493}
6494testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
6495 var MSC_ConnHdlr vc_conn;
6496 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6497
6498 f_init(1, true);
6499 f_sleep(1.0);
6500
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006501 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006502
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006503 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6504 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006505
6506 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
6507 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006508
6509 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6510 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
6511 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6512 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
6513 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006514 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006515}
6516
6517/* The new BSS's lchan times out before the MSC decides that handover failed. */
6518private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
6519 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6520 f_rslem_register(0, new_chan_nr);
6521 g_chan_nr := new_chan_nr;
6522 f_sleep(1.0);
6523
6524 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6525 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6526 activate(as_Media());
6527
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006528 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006529 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006530 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006531
6532 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6533
6534 var PDU_BSSAP rx_bssap;
6535 var octetstring ho_command_str;
6536
6537 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6538
6539 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6540 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6541 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6542 log("L3 Info in HO Request Ack is ", ho_command);
6543
6544 var GsmArfcn arfcn;
6545 var RslChannelNr actual_new_chan_nr;
6546 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6547 actual_new_chan_nr, arfcn);
6548
6549 if (actual_new_chan_nr != new_chan_nr) {
6550 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6551 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6552 setverdict(fail);
6553 return;
6554 }
6555 log("Handover Command chan_nr is", actual_new_chan_nr);
6556
6557 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6558 * tells the MS to handover to the new lchan. But the MS never shows up
6559 * on the new lchan. */
6560
6561 BSSAP.receive(tr_BSSMAP_HandoverFailure);
6562
6563 /* Did osmo-bsc also send a Clear Request? */
6564 timer T := 0.5;
6565 T.start;
6566 alt {
6567 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
6568 [] T.timeout { }
6569 }
6570
6571 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
6572 * asked for it, this is a Handover Failure after all). */
6573
6574 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6575 var BssmapCause cause := enum2int(cause_val);
6576 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6577
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006578 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006579 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006580 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006581
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006582 f_sleep(1.0);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006583}
6584testcase TC_ho_in_fail_no_detect() runs on test_CT {
6585 var MSC_ConnHdlr vc_conn;
6586 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6587
6588 f_init(1, true);
6589 f_sleep(1.0);
6590
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006591 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006592
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006593 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6594 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006595
6596 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
6597 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006598
6599 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6600 f_ctrs_bsc_and_bts_add(0, "handover:error");
6601 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6602 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
6603 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006604 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006605}
6606
6607/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
6608private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
6609 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6610 f_rslem_register(0, new_chan_nr);
6611 g_chan_nr := new_chan_nr;
6612 f_sleep(1.0);
6613
6614 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6615 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6616 activate(as_Media());
6617
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006618 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006619 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006620 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006621
6622 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6623
6624 var PDU_BSSAP rx_bssap;
6625 var octetstring ho_command_str;
6626
6627 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6628
6629 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6630 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6631 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6632 log("L3 Info in HO Request Ack is ", ho_command);
6633
6634 var GsmArfcn arfcn;
6635 var RslChannelNr actual_new_chan_nr;
6636 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6637 actual_new_chan_nr, arfcn);
6638
6639 if (actual_new_chan_nr != new_chan_nr) {
6640 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6641 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6642 setverdict(fail);
6643 return;
6644 }
6645 log("Handover Command chan_nr is", actual_new_chan_nr);
6646
6647 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6648 * tells the MS to handover to the new lchan. But the MS never shows up
6649 * on the new lchan. */
6650
6651 BSSAP.receive(tr_BSSMAP_HandoverFailure);
6652
6653 /* MSC plays dumb and sends no Clear Command */
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006654 var PDU_BSSAP rx_clear_request;
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02006655
6656 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006657 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
6658 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6659 };
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006660 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006661 BSSAP.receive(tr_BSSMAP_ClearComplete);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006662 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006663
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006664 f_sleep(1.0);
6665}
6666testcase TC_ho_in_fail_no_detect2() runs on test_CT {
6667 var MSC_ConnHdlr vc_conn;
6668 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6669
6670 f_init(1, true);
6671 f_sleep(1.0);
6672
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006673 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006674
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006675 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6676 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006677
6678 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
6679 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006680
6681 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6682 f_ctrs_bsc_and_bts_add(0, "handover:error");
6683 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6684 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
6685 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006686 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006687}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006688
Neels Hofmeyr91401012019-07-11 00:42:35 +02006689type record of charstring Commands;
6690
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006691private function f_bts_0_cfg(TELNETasp_PT pt, Commands cmds := {})
Neels Hofmeyr91401012019-07-11 00:42:35 +02006692{
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006693 f_vty_enter_cfg_bts(pt, 0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006694 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006695 f_vty_transceive(pt, cmds[i]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006696 }
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006697 f_vty_transceive(pt, "end");
Neels Hofmeyr91401012019-07-11 00:42:35 +02006698}
6699
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01006700private function f_cs7_inst_0_cfg(TELNETasp_PT pt, Commands cmds := {})
6701{
6702 f_vty_enter_cfg_cs7_inst(pt, 0);
6703 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
6704 f_vty_transceive(pt, cmds[i]);
6705 }
6706 f_vty_transceive(pt, "end");
6707}
6708
Neels Hofmeyr91401012019-07-11 00:42:35 +02006709private function f_probe_for_handover(charstring log_label,
6710 charstring log_descr,
6711 charstring handover_vty_cmd,
6712 boolean expect_handover,
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006713 boolean is_inter_bsc_handover := false,
6714 template uint3_t expect_target_tsc := ?)
Neels Hofmeyr91401012019-07-11 00:42:35 +02006715runs on MSC_ConnHdlr
6716{
Neels Hofmeyrb3fc8982020-05-11 00:16:42 +02006717 /* We're going to thwart any and all handover attempts, just be ready to handle (and ignore) handover target
6718 * lchans to be established on bts 1 or bts 2. */
6719 f_rslem_suspend(RSL1_PROC);
6720 f_rslem_suspend(RSL2_PROC);
6721
Neels Hofmeyr91401012019-07-11 00:42:35 +02006722 var RSL_Message rsl;
6723
6724 var charstring log_msg := " (expecting handover)"
6725 if (not expect_handover) {
6726 log_msg := " (expecting NO handover)";
6727 }
6728 log("f_probe_for_handover starting: " & log_label & ": " & log_descr & log_msg);
6729 f_vty_transceive(BSCVTY, handover_vty_cmd);
6730
Neels Hofmeyr91401012019-07-11 00:42:35 +02006731 timer T := 2.0;
6732 T.start;
6733
6734 alt {
6735 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
6736 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
6737 log("Rx L3 from net: ", l3);
6738 if (ischosen(l3.msgs.rrm.handoverCommand)) {
6739 var RslChannelNr new_chan_nr;
6740 var GsmArfcn arfcn;
6741 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
6742 new_chan_nr, arfcn);
6743 log("Handover to new chan ", new_chan_nr, " on ARFCN ", arfcn);
6744 log(l3.msgs.rrm.handoverCommand);
6745
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006746 /* Verify correct TSC in handoverCommand */
6747 var uint3_t got_tsc := rr_chan_desc_tsc(l3.msgs.rrm.handoverCommand.channelDescription2);
6748 if (not match(got_tsc, expect_target_tsc)) {
6749 setverdict(fail, "RR Handover Command: unexpected TSC in Channel Description: expected ",
6750 expect_target_tsc, " got ", got_tsc);
6751 mtc.stop;
6752 } else {
6753 log("handoverCommand: verified TSC = ", got_tsc, " (matches ",
6754 expect_target_tsc, ")");
6755 }
6756
Neels Hofmeyr91401012019-07-11 00:42:35 +02006757 /* Need to register for new lchan on new BTS -- it's either bts 1 or bts 2. It doesn't really
6758 * matter on which BTS it really is, we're not going to follow through an entire handover
6759 * anyway. */
6760 f_rslem_register(0, new_chan_nr, RSL1_PROC);
6761 f_rslem_resume(RSL1_PROC);
6762 f_rslem_register(0, new_chan_nr, RSL2_PROC);
6763 f_rslem_resume(RSL2_PROC);
6764
6765 if (expect_handover and not is_inter_bsc_handover) {
6766 setverdict(pass);
6767 log("f_probe_for_handover(" & log_label & "): Got RSL Handover Command as expected.");
6768 } else {
6769 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got RSL Handover Command. "
6770 & log_label & ": " & log_descr);
6771 }
6772
6773 log("f_probe_for_handover(" & log_label & "): Ending the test: Handover Failure stops the procedure.");
6774 /* osmo-bsc has triggered Handover. That's all we need to know for this test, reply with
6775 * Handover Failure. */
6776 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
6777
6778 /* target BTS is told to release lchan again; don't care which BTS nor what messages. */
6779 f_sleep(0.5);
6780 RSL1.clear;
6781 RSL2.clear;
6782 log("f_probe_for_handover(" & log_label & "): done (got RSL Handover Command)");
6783 break;
6784 } else {
6785 repeat;
6786 }
6787 }
6788 [] BSSAP.receive(tr_BSSMAP_HandoverRequired) {
6789 if (expect_handover and is_inter_bsc_handover) {
6790 setverdict(pass);
6791 log("f_probe_for_handover(" & log_label & "): Got BSSMAP Handover Required as expected.");
6792 } else {
6793 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got BSSMAP Handover Required. "
6794 & log_label & ": " & log_descr);
6795 }
6796
6797 log("f_probe_for_handover(" & log_label & "): done (got BSSMAP Handover Required)");
6798
6799 /* Note: f_tc_ho_neighbor_config_start() sets T7, the timeout for BSSMAP Handover Required, to
6800 * 1 second. There is no legal way to quickly abort a handover after a BSSMAP Handover Required,
6801 * setting a short timeout and waiting is the only way. */
6802 log("f_probe_for_handover(" & log_label & "): waiting for inter-BSC HO to time out...");
6803 f_sleep(1.5);
6804 log("f_probe_for_handover(" & log_label & "): ...done");
6805
6806 break;
6807 }
6808 [] T.timeout {
6809 if (expect_handover) {
6810 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected Handover, but got none. "
6811 & log_label & ": " & log_descr);
6812 } else {
6813 setverdict(pass);
6814 log("f_probe_for_handover(" & log_label & "): Got no Handover, as expected.");
6815 }
6816 log("f_probe_for_handover(" & log_label & "): done (got no Handover)");
6817 break;
6818 }
6819 }
6820
6821 f_rslem_resume(RSL1_PROC);
6822 f_rslem_resume(RSL2_PROC);
6823 f_sleep(3.0);
6824 RSL.clear;
6825
6826 log("f_probe_for_handover(" & log_label & "): done clearing");
6827}
6828
6829/* Test the effect of various neighbor configuration scenarios:
6830 *
6831 * To avoid complexity, block off any actual handover operation, and always remain on the lchan at bts 0.
6832 * Reconfigure the neighbors for bts 0, trigger a Handover, and probe whether osmo-bsc does or doesn't start HO.
6833 */
6834private function f_tc_ho_neighbor_config_start() runs on MSC_ConnHdlr {
6835 g_pars := f_gen_test_hdlr_pars();
6836 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
6837 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006838
6839 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
6840 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
6841
6842 /* Establish lchan at bts 0 */
6843 f_establish_fully(ass_cmd, exp_compl);
6844
6845 /* Shorten the inter-BSC Handover timeout, to not wait so long for inter-BSC Handovers */
6846 f_vty_enter_cfg_network(BSCVTY);
6847 f_vty_transceive(BSCVTY, "timer T7 1");
6848 f_vty_transceive(BSCVTY, "end");
6849}
6850
6851private function f_tc_ho_neighbor_config_1(charstring id) runs on MSC_ConnHdlr {
6852 f_tc_ho_neighbor_config_start();
6853
6854 /*
6855 * bts 0 ARFCN 871 BSIC 10
6856 * bts 1 ARFCN 871 BSIC 11
6857 * bts 2 ARFCN 871 BSIC 12
6858 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6859 */
6860
6861 log("f_tc_ho_neighbor_config: 1. No 'neighbor' config");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006862 f_bts_0_cfg(BSCVTY, {"no neighbors"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006863 f_probe_for_handover("1.a", "HO to bts 1 works, implicitly listed as neighbor (legacy behavior when none are configured)",
6864 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006865 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006866
6867 f_probe_for_handover("1.b", "HO to unknown cell does not start",
6868 "handover any to arfcn 13 bsic 39",
6869 false);
6870
6871 f_probe_for_handover("1.c", "HO to 871-12 is ambiguous = error",
6872 "handover any to arfcn 871 bsic 12",
6873 false);
6874
6875 f_probe_for_handover("1.d", "HO to 871-11 still works (verify that this test properly cleans up)",
6876 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006877 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006878
6879 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006880}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006881testcase TC_ho_neighbor_config_1() runs on test_CT {
6882 var MSC_ConnHdlr vc_conn;
6883 f_init(3, true, guard_timeout := 60.0);
6884 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006885 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006886 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_1));
6887 vc_conn.done;
6888
6889 /* f_tc_ho_neighbor_config_start() */
6890 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6891 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6892
6893 /* 1.a */
6894 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6895 * handover quickly by sending a Handover Failure message. */
6896 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6897 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6898 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6899 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006900 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6901 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006902
6903 /* 1.b */
6904 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6905 f_ctrs_bsc_and_bts_add(0, "handover:error");
6906
6907 /* 1.c */
6908 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6909 f_ctrs_bsc_and_bts_add(0, "handover:error");
6910
6911 /* 1.d */
6912 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6913 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6914 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6915 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006916 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6917 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006918
6919 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006920 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006921}
6922
Neels Hofmeyr91401012019-07-11 00:42:35 +02006923private function f_tc_ho_neighbor_config_2(charstring id) runs on MSC_ConnHdlr {
6924 f_tc_ho_neighbor_config_start();
6925
6926 /*
6927 * bts 0 ARFCN 871 BSIC 10
6928 * bts 1 ARFCN 871 BSIC 11
6929 * bts 2 ARFCN 871 BSIC 12
6930 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6931 */
6932
6933 log("f_tc_ho_neighbor_config: 2. explicit local neighbor: 'neighbor bts 1'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006934 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006935 f_sleep(0.5);
6936
6937 f_probe_for_handover("2.a", "HO to bts 1 works, explicitly listed as neighbor",
6938 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006939 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006940
6941 f_probe_for_handover("2.b", "HO to bts 2 doesn't work, not listed as neighbor",
6942 "handover any to arfcn 871 bsic 12",
6943 false);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006944 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006945}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006946testcase TC_ho_neighbor_config_2() runs on test_CT {
6947 var MSC_ConnHdlr vc_conn;
6948 f_init(3, true, guard_timeout := 50.0);
6949 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006950 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006951 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_2));
6952 vc_conn.done;
6953
6954 /* f_tc_ho_neighbor_config_start() */
6955 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6956 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6957
6958 /* 2.a */
6959 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6960 * handover quickly by sending a Handover Failure message. */
6961 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6962 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6963 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6964 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006965 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6966 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006967
6968 /* 2.b */
6969 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6970 f_ctrs_bsc_and_bts_add(0, "handover:error");
6971
6972 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006973 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006974}
6975
Neels Hofmeyr91401012019-07-11 00:42:35 +02006976private function f_tc_ho_neighbor_config_3(charstring id) runs on MSC_ConnHdlr {
6977 f_tc_ho_neighbor_config_start();
6978
6979 /*
6980 * bts 0 ARFCN 871 BSIC 10
6981 * bts 1 ARFCN 871 BSIC 11
6982 * bts 2 ARFCN 871 BSIC 12
6983 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6984 */
6985
6986 log("f_tc_ho_neighbor_config: 3. explicit local neighbor: 'neighbor bts 2'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006987 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006988 f_sleep(0.5);
6989
6990 f_probe_for_handover("3.a", "HO to bts 1 doesn't work, not listed as neighbor",
6991 "handover any to arfcn 871 bsic 11",
6992 false);
6993 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",
6994 "handover any to arfcn 871 bsic 12",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006995 true, expect_target_tsc := BTS_TSC[2]);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01006996 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006997}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006998testcase TC_ho_neighbor_config_3() runs on test_CT {
6999 var MSC_ConnHdlr vc_conn;
7000 f_init(3, true, guard_timeout := 50.0);
7001 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007002 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007003 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_3));
7004 vc_conn.done;
7005
7006 /* f_tc_ho_neighbor_config_start() */
7007 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7008 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7009
7010 /* 3.a */
7011 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7012 f_ctrs_bsc_and_bts_add(0, "handover:error");
7013
7014 /* 3.b */
7015 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
7016 * handover quickly by sending a Handover Failure message. */
7017 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7018 f_ctrs_bsc_and_bts_add(0, "handover:failed");
7019 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
7020 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007021 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:attempted");
7022 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007023
7024 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007025 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007026}
7027
Neels Hofmeyr91401012019-07-11 00:42:35 +02007028private function f_tc_ho_neighbor_config_4(charstring id) runs on MSC_ConnHdlr {
7029 f_tc_ho_neighbor_config_start();
7030
7031 /*
7032 * bts 0 ARFCN 871 BSIC 10
7033 * bts 1 ARFCN 871 BSIC 11
7034 * bts 2 ARFCN 871 BSIC 12
7035 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7036 */
7037
7038 log("f_tc_ho_neighbor_config: 4. explicit remote neighbor: 'neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007039 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007040 f_sleep(0.5);
7041
7042 f_probe_for_handover("4.a", "HO to bts 1 doesn't work, not listed as neighbor",
7043 "handover any to arfcn 871 bsic 11",
7044 false);
7045 f_probe_for_handover("4.b", "HO to bts 2 doesn't work, not listed as neighbor",
7046 "handover any to arfcn 871 bsic 12",
7047 false);
7048 f_probe_for_handover("4.c", "HO to 123-45 triggers inter-BSC HO",
7049 "handover any to arfcn 123 bsic 45",
7050 true, true);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007051 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007052}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007053testcase TC_ho_neighbor_config_4() runs on test_CT {
7054 var MSC_ConnHdlr vc_conn;
7055 f_init(3, true, guard_timeout := 50.0);
7056 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007057 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007058 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_4));
7059 vc_conn.done;
7060
7061 /* f_tc_ho_neighbor_config_start() */
7062 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7063 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7064
7065 /* 4.a */
7066 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7067 f_ctrs_bsc_and_bts_add(0, "handover:error");
7068
7069 /* 4.b */
7070 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7071 f_ctrs_bsc_and_bts_add(0, "handover:error");
7072
7073 /* 4.c */
7074 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7075 * handover quickly by timing out after the Handover Required message */
7076 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7077 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
7078 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
7079 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
7080
7081 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007082 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007083}
7084
Neels Hofmeyr91401012019-07-11 00:42:35 +02007085private function f_tc_ho_neighbor_config_5(charstring id) runs on MSC_ConnHdlr {
7086 f_tc_ho_neighbor_config_start();
7087
7088 /*
7089 * bts 0 ARFCN 871 BSIC 10
7090 * bts 1 ARFCN 871 BSIC 11
7091 * bts 2 ARFCN 871 BSIC 12
7092 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7093 */
7094
7095 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 +02007096 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007097 f_sleep(0.5);
7098
7099 f_probe_for_handover("5.a", "HO to 871-12 triggers inter-BSC HO (ignoring local cells with same ARFCN+BSIC)",
7100 "handover any to arfcn 871 bsic 12",
7101 true, true);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007102 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007103}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007104testcase TC_ho_neighbor_config_5() runs on test_CT {
7105 var MSC_ConnHdlr vc_conn;
7106 f_init(3, true);
7107 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007108 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007109 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_5));
7110 vc_conn.done;
7111
7112 /* f_tc_ho_neighbor_config_start() */
7113 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7114 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7115
7116 /* 5 */
7117 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7118 * handover quickly by timing out after the Handover Required message */
7119 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7120 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
7121 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
7122 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
7123
7124 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007125 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007126}
7127
Neels Hofmeyr91401012019-07-11 00:42:35 +02007128private function f_tc_ho_neighbor_config_6(charstring id) runs on MSC_ConnHdlr {
7129 f_tc_ho_neighbor_config_start();
7130
7131 /*
7132 * bts 0 ARFCN 871 BSIC 10
7133 * bts 1 ARFCN 871 BSIC 11
7134 * bts 2 ARFCN 871 BSIC 12
7135 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7136 */
7137
7138 log("f_tc_ho_neighbor_config: 6. config error: explicit local and remote neighbors with ambiguous ARFCN+BSIC:"
7139 & " 'neighbor bts 2; neighbor lac 99 arfcn 871 bsic 12'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007140 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007141 f_sleep(0.5);
7142
7143 f_probe_for_handover("6.a", "HO to 871-12 is ambiguous = error",
7144 "handover any to arfcn 871 bsic 12",
7145 false);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007146 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007147}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007148testcase TC_ho_neighbor_config_6() runs on test_CT {
7149 var MSC_ConnHdlr vc_conn;
7150 f_init(3, true);
7151 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007152 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007153 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_6));
7154 vc_conn.done;
7155
7156 /* f_tc_ho_neighbor_config_start() */
7157 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7158 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7159
7160 /* 6.a */
7161 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7162 * handover quickly by timing out after the Handover Required message */
7163 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7164 f_ctrs_bsc_and_bts_add(0, "handover:error");
7165
7166 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007167 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007168}
7169
Neels Hofmeyr91401012019-07-11 00:42:35 +02007170private function f_tc_ho_neighbor_config_7(charstring id) runs on MSC_ConnHdlr {
7171 f_tc_ho_neighbor_config_start();
7172
7173 /*
7174 * bts 0 ARFCN 871 BSIC 10
7175 * bts 1 ARFCN 871 BSIC 11
7176 * bts 2 ARFCN 871 BSIC 12
7177 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
7178 */
7179
7180 log("f_tc_ho_neighbor_config: 7. explicit local and remote neighbors:"
7181 & " 'neighbor bts 2; neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02007182 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02007183 f_sleep(0.5);
7184
7185 f_probe_for_handover("7.a", "HO to 871-12 does HO to bts 2",
7186 "handover any to arfcn 871 bsic 12",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02007187 true, expect_target_tsc := BTS_TSC[2]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02007188 f_probe_for_handover("7.b", "HO to 123-45 triggers inter-BSC HO",
7189 "handover any to arfcn 123 bsic 45",
7190 true, true);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007191 f_perform_clear();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007192}
Neels Hofmeyr91401012019-07-11 00:42:35 +02007193testcase TC_ho_neighbor_config_7() runs on test_CT {
7194 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf2b88032020-06-16 00:35:04 +02007195 f_init(3, true, guard_timeout := 50.0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02007196 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007197 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007198 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_7));
7199 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007200
7201 /* f_tc_ho_neighbor_config_start() */
7202 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
7203 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
7204
7205 /* 7.a */
7206 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
7207 * handover quickly by sending a Handover Failure message. */
7208 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7209 f_ctrs_bsc_and_bts_add(0, "handover:failed");
7210 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
7211 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01007212 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:attempted");
7213 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00007214
7215 /* 7.b */
7216 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
7217 * handover quickly by timing out after the Handover Required message */
7218 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
7219 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
7220 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
7221 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
7222
7223 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007224 f_shutdown_helper();
Neels Hofmeyr91401012019-07-11 00:42:35 +02007225}
7226
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007227/* OS#3041: Open and close N connections in a normal fashion, and expect no
7228 * BSSMAP Reset just because of that. */
7229testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
7230 var default d;
7231 var integer i;
7232 var DchanTuple dt;
7233
7234 f_init();
7235
7236 /* Wait for initial BSSMAP Reset to pass */
7237 f_sleep(4.0);
7238
7239 d := activate(no_bssmap_reset());
7240
7241 /* Setup up a number of connections and RLSD them again from the MSC
7242 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7243 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02007244 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007245 /* Since we're doing a lot of runs, give each one a fresh
7246 * T_guard from the top. */
7247 T_guard.start;
7248
7249 /* Setup a BSSAP connection and clear it right away. This is
7250 * the MSC telling the BSC about a planned release, it's not an
7251 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02007252 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007253
7254 /* MSC disconnects (RLSD). */
7255 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
7256 }
7257
7258 /* In the buggy behavior, a timeout of 2 seconds happens between above
7259 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7260 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7261 f_sleep(4.0);
7262
7263 deactivate(d);
7264 f_shutdown_helper();
7265}
Harald Welte552620d2017-12-16 23:21:36 +01007266
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007267/* OS#3041: Open and close N connections in a normal fashion, and expect no
7268 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
7269 * the MSC. */
7270testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
7271 var default d;
7272 var integer i;
7273 var DchanTuple dt;
7274 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007275 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
7276 var BssmapCause cause := enum2int(cause_val);
7277
7278 f_init();
7279
7280 /* Wait for initial BSSMAP Reset to pass */
7281 f_sleep(4.0);
7282
7283 d := activate(no_bssmap_reset());
7284
7285 /* Setup up a number of connections and RLSD them again from the MSC
7286 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7287 * Let's do it some more times for good measure. */
7288 for (i := 0; i < 8; i := i+1) {
7289 /* Since we're doing a lot of runs, give each one a fresh
7290 * T_guard from the top. */
7291 T_guard.start;
7292
7293 /* Setup a BSSAP connection and clear it right away. This is
7294 * the MSC telling the BSC about a planned release, it's not an
7295 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02007296 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007297
7298 /* Instruct BSC to clear channel */
7299 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7300
7301 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02007302 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007303 }
7304
7305 /* In the buggy behavior, a timeout of 2 seconds happens between above
7306 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7307 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7308 f_sleep(4.0);
7309
7310 deactivate(d);
7311 f_shutdown_helper();
7312}
7313
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007314/* OS#3041: Open and close N connections in a normal fashion, and expect no
7315 * BSSMAP Reset just because of that. Close connections from the MS side with a
7316 * Release Ind on RSL. */
7317testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
7318 var default d;
7319 var integer i;
7320 var DchanTuple dt;
7321 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007322 var integer j;
7323
7324 f_init();
7325
7326 /* Wait for initial BSSMAP Reset to pass */
7327 f_sleep(4.0);
7328
7329 d := activate(no_bssmap_reset());
7330
7331 /* Setup up a number of connections and RLSD them again from the MSC
7332 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7333 * Let's do it some more times for good measure. */
7334 for (i := 0; i < 8; i := i+1) {
7335 /* Since we're doing a lot of runs, give each one a fresh
7336 * T_guard from the top. */
7337 T_guard.start;
7338
7339 /* Setup a BSSAP connection and clear it right away. This is
7340 * the MSC telling the BSC about a planned release, it's not an
7341 * erratic loss of a connection. */
7342 dt := f_est_dchan('23'O, 23, '00010203040506'O);
7343
7344 /* simulate RLL REL IND */
7345 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
7346
7347 /* expect Clear Request on MSC side */
7348 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
7349
7350 /* Instruct BSC to clear channel */
7351 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
7352 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7353
7354 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02007355 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007356 }
7357
7358 /* In the buggy behavior, a timeout of 2 seconds happens between above
7359 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7360 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7361 f_sleep(4.0);
7362
7363 deactivate(d);
7364 f_shutdown_helper();
7365}
7366
Harald Welte94e0c342018-04-07 11:33:23 +02007367/***********************************************************************
7368 * IPA style dynamic PDCH
7369 ***********************************************************************/
7370
7371private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
7372 template (omit) RSL_Cause nack := omit)
7373runs on test_CT {
7374 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
7375 var RSL_Message rsl_unused;
7376 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
7377 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
7378 /* expect the BSC to issue the related RSL command */
7379 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7380 if (istemplatekind(nack, "omit")) {
7381 /* respond with a related acknowledgement */
7382 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7383 } else {
7384 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
7385 }
7386}
7387
7388private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
7389 template (omit) RSL_Cause nack := omit)
7390runs on test_CT {
7391 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
7392 var RSL_Message rsl_unused;
7393 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
7394 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
7395 /* expect the BSC to issue the related RSL command */
7396 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
7397 if (istemplatekind(nack, "omit")) {
7398 /* respond with a related acknowledgement */
7399 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
7400 } else {
7401 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
7402 }
7403}
7404
7405private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
7406runs on test_CT return charstring {
7407 var charstring cmd, resp;
7408 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01007409 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02007410}
7411
7412private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
7413 template charstring exp)
7414runs on test_CT {
7415 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
7416 if (not match(mode, exp)) {
7417 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02007418 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02007419 }
7420}
7421
7422private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
7423runs on test_CT {
7424 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
7425 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
7426 f_vty_transceive(BSCVTY, "end");
7427}
7428
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007429
7430private function f_ts_reset_chcomb(integer bts_nr) runs on test_CT {
7431 var integer i;
7432 for (i := 0; i < 8; i := i + 1) {
7433 f_ts_set_chcomb(bts_nr, 0, i, phys_chan_config[i]);
7434 }
7435}
7436
Harald Welte94e0c342018-04-07 11:33:23 +02007437private const charstring TCHF_MODE := "TCH/F mode";
7438private const charstring TCHH_MODE := "TCH/H mode";
7439private const charstring PDCH_MODE := "PDCH mode";
7440private const charstring NONE_MODE := "NONE mode";
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007441private const charstring SDCCH8_MODE := "SDCCH8 mode";
Harald Welte94e0c342018-04-07 11:33:23 +02007442
7443/* Test IPA PDCH activation / deactivation triggered by VTY */
7444testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
7445 var RSL_Message rsl_unused;
7446
7447 /* change Timeslot 6 before f_init() starts RSL */
7448 f_init_vty();
7449 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
7450 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7451
7452 f_init(1, false);
7453 f_sleep(1.0);
7454
7455 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
7456
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007457 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007458 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7459 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7460 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7461 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7462 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007463 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007464 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7465
7466 /* De-activate it via VTY */
7467 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7468 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007469 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007470 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7471
7472 /* re-activate it via VTY */
7473 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
7474 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007475 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007476 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7477
7478 /* and finally de-activate it again */
7479 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7480 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007481 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007482 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7483
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007484 /* clean up config */
7485 f_ts_set_chcomb(0, 0, 6, "PDCH");
7486
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007487 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007488}
7489
7490/* Test IPA PDCH activation NACK */
7491testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
7492 var RSL_Message rsl_unused;
7493
7494 /* change Timeslot 6 before f_init() starts RSL */
7495 f_init_vty();
7496 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
7497 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7498
7499 f_init(1, false);
7500 f_sleep(1.0);
7501
7502 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
7503
7504 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7505 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7506 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7507 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7508 f_sleep(1.0);
7509 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7510
7511 /* De-activate it via VTY */
7512 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7513 f_sleep(1.0);
7514 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7515
7516 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
7517 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
7518 f_sleep(1.0);
7519 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7520
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007521 /* clean up config */
7522 f_ts_set_chcomb(0, 0, 6, "PDCH");
7523
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007524 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007525}
7526
7527
7528/***********************************************************************
7529 * Osmocom style dynamic PDCH
7530 ***********************************************************************/
7531
7532private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
7533 template (omit) RSL_Cause nack := omit)
7534runs on test_CT {
7535 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
7536 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02007537 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02007538 /* FIXME: no VTY command to activate Osmocom PDCH !! */
7539 /* expect the BSC to issue the related RSL command */
7540 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
7541 if (istemplatekind(nack, "omit")) {
7542 /* respond with a related acknowledgement */
7543 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7544 } else {
7545 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
7546 }
7547}
7548
7549private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
7550 template (omit) RSL_Cause nack := omit)
7551runs on test_CT {
7552 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
7553 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02007554 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02007555 /* FIXME: no VTY command to activate Osmocom PDCH !! */
7556 /* expect the BSC to issue the related RSL command */
7557 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
7558 if (istemplatekind(nack, "omit")) {
7559 /* respond with a related acknowledgement */
7560 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
7561 } else {
7562 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
7563 }
7564}
7565
7566/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
7567testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
7568 var RSL_Message rsl_unused;
7569
7570 /* change Timeslot 6 before f_init() starts RSL */
7571 f_init_vty();
7572 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
7573 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7574
7575 f_init(1, false);
7576 f_sleep(1.0);
7577
7578 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
7579
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007580 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007581 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7582 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007583 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Harald Welte94e0c342018-04-07 11:33:23 +02007584
7585 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7586 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007587 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 +02007588 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7589
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007590 /* clean up config */
7591 f_ts_set_chcomb(0, 0, 6, "PDCH");
7592
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007593 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007594}
7595
7596/* Test Osmocom dyn PDCH activation NACK behavior */
7597testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
7598 var RSL_Message rsl_unused;
7599
7600 /* change Timeslot 6 before f_init() starts RSL */
7601 f_init_vty();
7602 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
7603 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7604
7605 f_init(1, false);
7606 f_sleep(1.0);
7607
7608 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
7609
7610 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7611 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007612 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Harald Welte94e0c342018-04-07 11:33:23 +02007613
7614 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
7615 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
7616 f_sleep(1.0);
7617 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7618
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007619 /* clean up config */
7620 f_ts_set_chcomb(0, 0, 6, "PDCH");
7621
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007622 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007623}
7624
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007625/* Test Osmocom dyn TS SDCCH8 activation / deactivation */
7626testcase TC_dyn_ts_sdcch8_act_deact() runs on test_CT {
7627 var RSL_Message rsl_unused, rsl_msg;
7628 var DchanTuple dt;
7629 var BSSAP_N_CONNECT_ind rx_c_ind;
7630
7631 /* change Timeslot 6 before f_init() starts RSL */
7632 f_init_vty();
7633 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
7634 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7635
7636 f_init(1, false);
7637 f_sleep(1.0);
7638
7639 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7640
7641 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7642 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7643 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007644 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007645
7646 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7647 f_sleep(1.0);
7648 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7649 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7650
7651 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7652 * on CCCH+SDCCH4+CBCH) */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007653 var DchanTuples sdcch_cleanup := {};
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007654 var integer i;
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007655 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007656 dt := f_est_dchan('23'O, i, '00010203040506'O);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007657 sdcch_cleanup := sdcch_cleanup & { dt };
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007658 }
7659
7660 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
7661 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
7662 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7663 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7664
7665 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7666 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7667
7668 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7669 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
7670 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7671 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7672
7673 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
7674 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
7675 dt.sccp_conn_id := rx_c_ind.connectionId;
7676 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
7677
7678 /* Instruct BSC to clear channel */
7679 var BssmapCause cause := 0;
7680 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7681 f_exp_chan_rel_and_clear(dt, 0);
7682
7683 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007684 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007685 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7686 f_sleep(1.0);
7687 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7688
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007689 /* Clean up SDCCH lchans */
7690 for (i := 0; i < lengthof(sdcch_cleanup); i := i + 1) {
7691 f_perform_clear_test_ct(sdcch_cleanup[i]);
7692 }
7693
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007694 /* clean up config */
7695 f_ts_set_chcomb(0, 0, 6, "PDCH");
7696
7697 f_shutdown_helper();
7698}
7699
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007700/* Validate all 8 subslots of a dynamics TS configured as SDCCH8 are used */
7701testcase TC_dyn_ts_sdcch8_all_subslots_used() runs on test_CT {
7702 var ASP_RSL_Unitdata rsl_ud;
7703 var integer i;
7704 var integer chreq_total, chreq_nochan;
7705
7706 f_init_vty();
7707 for (i := 1; i < 8; i := i + 1) {
7708 if (i == 2) {
7709 f_ts_set_chcomb(0, 0, i, "TCH/F_TCH/H_SDCCH8_PDCH");
7710 } else {
7711 f_ts_set_chcomb(0, 0, i, "PDCH");
7712 }
7713 }
7714 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7715
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007716 f_init(1, guard_timeout := 60.0);
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007717
7718 /* The dyn TS want to activate PDCH mode, ACK that. */
7719 var RslChannelNr chan_nr;
7720 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007721 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007722 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7723
7724 f_sleep(1.0);
7725
7726 /* Exhaust all dedicated SDCCH lchans.
7727 /* GSM 44.018 Table 9.1.8.2:
7728 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
7729 */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007730 var DchanTuples chan_cleanup := {};
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007731 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007732 chan_cleanup := chan_cleanup & { f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007733 }
7734
7735 /* Only the dyn TS is still available. Its first lchan gets converted to SDCCH8 */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007736 chan_cleanup := chan_cleanup & { f_est_dchan_dyn('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007737 /* Also occupy the seven other SDCCH of the dyn TS */
7738 for (i := 0; i < 7; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007739 chan_cleanup := chan_cleanup & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
7740 }
7741
7742 /* Clean up SDCCH lchans */
7743 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
7744 f_perform_clear_test_ct(chan_cleanup[i]);
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007745 }
7746
7747 /* clean up config */
7748 f_ts_reset_chcomb(0);
7749
7750 f_shutdown_helper();
7751}
7752
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007753/* Test Osmocom dyn TS SDCCH8 activation / deactivation: If activating dyn TS as
7754 SDCCH8 would end up in having no free TCH, then BSC should decide to activate
7755 it as TCH directly instead. SYS#5309. */
7756testcase TC_dyn_ts_sdcch8_tch_call_act_deact() runs on test_CT {
7757 var RSL_Message rsl_unused, rsl_msg;
7758 var DchanTuple dt;
7759 var BSSAP_N_CONNECT_ind rx_c_ind;
7760 var integer i;
7761
7762 /* change Timeslot 6 before f_init() starts RSL */
7763 f_init_vty();
7764 for (i := 1; i < 8; i := i + 1) {
7765 if (i == 6) {
7766 f_ts_set_chcomb(0, 0, i, "TCH/F_TCH/H_SDCCH8_PDCH");
7767 } else {
7768 f_ts_set_chcomb(0, 0, i, "PDCH");
7769 }
7770 }
7771 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7772
7773 f_init(1, false);
7774 f_sleep(1.0);
7775
7776 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7777
7778 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7779 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7780 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007781 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007782
7783 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7784 f_sleep(1.0);
7785 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7786 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7787
7788 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7789 * on CCCH+SDCCH4+CBCH) */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007790 var DchanTuples chan_cleanup := {};
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007791 var OCT1 ra := '43'O; /* RA containing reason=originating speech call*/
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007792 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007793 dt := f_est_dchan(ra, i, '00010203040506'O);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007794 chan_cleanup := chan_cleanup & { dt };
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007795 }
7796
7797 /* Now the dyn ts is selected. First PDCH is released, then TCH chan is activated */
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007798 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int(ra) + i, 1), 2342));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007799 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7800 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7801
7802 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7803 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7804
7805 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
7806 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
7807 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7808 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
7809
7810 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
7811 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
7812 dt.sccp_conn_id := rx_c_ind.connectionId;
7813 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
7814
7815 /* Instruct BSC to clear channel */
7816 var BssmapCause cause := 0;
7817 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7818 f_exp_chan_rel_and_clear(dt, 0);
7819
7820 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007821 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007822 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7823 f_sleep(1.0);
7824 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7825
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007826 /* Clean up SDCCH lchans */
7827 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
7828 f_perform_clear_test_ct(chan_cleanup[i]);
7829 }
7830
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007831 /* clean up config */
7832 f_ts_reset_chcomb(0);
7833 /* TODO: clean up other channels? */
7834
7835 f_shutdown_helper();
7836}
7837
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007838/* Test Osmocom dyn TS SDCCH8 activation / deactivation when SDCCH fails at BTS */
7839testcase TC_dyn_ts_sdcch8_act_nack() runs on test_CT {
7840 var RSL_Message rsl_unused, rsl_msg;
7841 var DchanTuple dt;
7842 var BSSAP_N_CONNECT_ind rx_c_ind;
7843 var GsmRrMessage rr;
7844
7845 /* change Timeslot 6 before f_init() starts RSL */
7846 f_init_vty();
7847 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
7848 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7849
7850 f_init(1, false);
7851 f_sleep(1.0);
7852
7853 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7854
7855 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7856 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7857 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007858 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007859
7860 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7861 f_sleep(1.0);
7862 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7863 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7864
7865 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7866 * on CCCH+SDCCH4+CBCH) */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007867 var DchanTuples chan_cleanup := {};
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007868 var integer i;
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007869 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007870 dt := f_est_dchan('23'O, i, '00010203040506'O);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007871 chan_cleanup := chan_cleanup & { dt };
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007872 }
7873
7874 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
7875 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
7876 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7877 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7878
7879 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7880 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7881
7882 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7883 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(dt.rsl_chan_nr, RSL_ERR_EQUIPMENT_FAIL));
7884 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7885 rr := dec_GsmRrMessage(rsl_msg.ies[1].body.full_imm_ass_info.payload);
7886 if (rr.header.message_type != IMMEDIATE_ASSIGNMENT_REJECT) {
7887 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Expected reject");
7888 }
7889
7890 /* FIXME? Currently the TS stays in state BORKEN: */
7891
7892 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +06007893 /* rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr));
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007894 * f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7895 * f_sleep(1.0);
7896 * f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE)
7897 */
7898
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01007899 /* Clean up SDCCH lchans */
7900 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
7901 f_perform_clear_test_ct(chan_cleanup[i]);
7902 }
7903
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007904 /* clean up config */
7905 f_ts_set_chcomb(0, 0, 6, "PDCH");
7906
7907 f_shutdown_helper();
7908}
7909
Stefan Sperling0796a822018-10-05 13:01:39 +02007910testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02007911 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02007912 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
7913 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
7914 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007915 f_shutdown_helper();
Stefan Sperling0796a822018-10-05 13:01:39 +02007916}
7917
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007918testcase TC_chopped_ipa_payload() runs on test_CT {
7919 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
7920 /* TODO: mp_bsc_ctrl_port does not work yet */};
7921 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
7922 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
7923 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007924 f_shutdown_helper();
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007925}
7926
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01007927/* Verify the BSC sends the MS Power Parameters IE during CHAN ACT to make sure
7928 the BTS does autonomous MS power control loop */
7929testcase TC_assignment_verify_ms_power_params_ie() runs on test_CT {
7930 var MSC_ConnHdlr vc_conn;
7931 var TestHdlrParams pars := f_gen_test_hdlr_pars();
7932 //pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
7933 pars.exp_ms_power_params := true;
7934
7935 f_init(1, true);
7936 f_sleep(1.0);
7937 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
7938 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007939 f_shutdown_helper();
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01007940}
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007941
Vadim Yanitskiy4b233042021-06-30 00:58:43 +02007942/* Verify activation and deactivation of the BCCH carrier power reduction mode */
7943testcase TC_c0_power_red_mode() runs on test_CT {
7944 f_init(1);
7945
7946 for (var integer red := 6; red >= 0; red := red - 2) {
7947 /* Configure BCCH carrier power reduction mode via the VTY */
7948 f_vty_transceive(BSCVTY, "bts 0 c0-power-reduction " & int2str(red));
7949
7950 /* Expect Osmocom specific BS Power Control message on the RSL */
7951 var template RSL_Message tr_rsl_pdu := tr_RSL_BS_PWR_CTRL(
7952 chan_nr := t_RslChanNr_BCCH(0),
7953 bs_power := tr_RSL_IE_BS_Power(red / 2));
7954 tr_rsl_pdu.msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false);
7955 var RSL_Message unused := f_exp_ipa_rx(0, tr_rsl_pdu);
7956
7957 /* Additionally verify the applied value over the CTRL interface */
7958 var CtrlValue cred := f_ctrl_get_bts(IPA_CTRL, 0, "c0-power-reduction");
7959 if (cred != int2str(red)) {
7960 setverdict(fail, "Unexpected BCCH carrier power reduction value ",
7961 cred, " (expected ", red, ")");
7962 }
7963 }
7964
7965 f_shutdown_helper();
7966}
7967
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007968/***********************************************************************
7969 * MSC Pooling
7970 ***********************************************************************/
7971
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007972template MobileIdentityLV ts_MI_TMSI_NRI_LV(integer nri_v, integer nri_bitlen := 10) :=
Harald Weltebf397612021-01-14 20:39:46 +01007973 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 +02007974
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007975private 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 +02007976runs on MSC_ConnHdlr {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007977 interleave {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007978 [] rsl_pt.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007979 f_logp(BSCVTY, "Got RSL RR Release");
7980 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007981 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007982 f_logp(BSCVTY, "Got RSL Deact SACCH");
7983 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02007984 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007985 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007986 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
7987 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007988 break;
7989 }
7990 }
7991}
7992
Neels Hofmeyr6289af12021-12-16 18:17:49 +01007993private altstep as_mgcp_ack_all_dlcx() runs on MSC_ConnHdlr {
7994 var MgcpCommand mgcp_cmd;
7995 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
7996 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
7997 repeat;
7998 }
7999}
8000
8001private altstep as_rsl_ack_all_rel_req() runs on MSC_ConnHdlr {
8002 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
8003 [] RSL.receive(tr_RSL_REL_REQ(g_chan_nr, ?)) {
8004 RSL.send(ts_RSL_REL_CONF(g_chan_nr, main_dcch));
8005 repeat;
8006 }
8007}
8008
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008009friend function f_perform_clear(RSL_DCHAN_PT rsl_pt := RSL, RSLEM_PROC_PT rsl_proc_pt := RSL_PROC,
8010 template PDU_ML3_NW_MS exp_rr_rel_tmpl := tr_RRM_RR_RELEASE)
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02008011runs on MSC_ConnHdlr {
Neels Hofmeyr6289af12021-12-16 18:17:49 +01008012 var default ack_dlcx := activate(as_mgcp_ack_all_dlcx());
8013 var default ack_rel_req := activate(as_rsl_ack_all_rel_req());
Neels Hofmeyr767548a2020-08-09 20:26:07 +00008014 f_logp(BSCVTY, "MSC instructs BSC to clear channel");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008015 BSSAP.send(ts_BSSMAP_ClearCommand(0));
8016 interleave {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008017 [] rsl_pt.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00008018 f_logp(BSCVTY, "Got RSL RR Release");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008019 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008020 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00008021 f_logp(BSCVTY, "Got RSL Deact SACCH");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008022 }
8023 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00008024 f_logp(BSCVTY, "Got BSSMAP Clear Complete");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008025 /* Also drop the SCCP connection */
8026 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
8027 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02008028 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00008029 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008030 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
8031 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008032 }
8033 }
Neels Hofmeyr6289af12021-12-16 18:17:49 +01008034 deactivate(ack_dlcx);
8035 deactivate(ack_rel_req);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008036}
8037
Neels Hofmeyrc3c6ee62022-01-26 01:22:12 +01008038friend function f_perform_clear_no_rr_rel(RSL_DCHAN_PT rsl_pt := RSL, RSLEM_PROC_PT rsl_proc_pt := RSL_PROC)
8039runs on MSC_ConnHdlr {
8040 var default ack_dlcx := activate(as_mgcp_ack_all_dlcx());
8041 var default ack_rel_req := activate(as_rsl_ack_all_rel_req());
8042 f_logp(BSCVTY, "MSC instructs BSC to clear channel");
8043 BSSAP.send(ts_BSSMAP_ClearCommand(0));
8044 interleave {
8045 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
8046 f_logp(BSCVTY, "Got RSL Deact SACCH");
8047 }
8048 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
8049 f_logp(BSCVTY, "Got BSSMAP Clear Complete");
8050 /* Also drop the SCCP connection */
8051 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
8052 }
8053 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
8054 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
8055 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
8056 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
8057 }
8058 }
8059 deactivate(ack_dlcx);
8060 deactivate(ack_rel_req);
8061}
8062
Neels Hofmeyr907b23b2022-02-17 21:58:47 +01008063friend function f_perform_clear_no_lchan()
8064runs on MSC_ConnHdlr {
8065 f_logp(BSCVTY, "MSC instructs BSC to clear channel");
8066 BSSAP.send(ts_BSSMAP_ClearCommand(0));
8067 BSSAP.receive(tr_BSSMAP_ClearComplete);
8068 f_logp(BSCVTY, "Got BSSMAP Clear Complete");
8069 /* Also drop the SCCP connection */
8070 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
8071}
8072
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01008073private function f_perform_clear_test_ct(DchanTuple dt)
8074 runs on test_CT
8075{
8076 /* Instruct BSC to clear channel */
8077 var BssmapCause cause := 0;
8078 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
8079 f_exp_chan_rel_and_clear(dt, 0);
8080}
8081
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008082private function f_perform_compl_l3(RSL_DCHAN_PT rsl_pt, RSLEM_PROC_PT rsl_proc_pt,
8083 template PDU_ML3_MS_NW l3_info, boolean do_clear := true, boolean expect_bssmap_l3 := true)
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008084runs on MSC_ConnHdlr {
8085 timer T := 10.0;
8086 var octetstring l3_enc := enc_PDU_ML3_MS_NW(valueof(l3_info));
8087
Neels Hofmeyr767548a2020-08-09 20:26:07 +00008088 f_logp(BSCVTY, "establish channel, send Complete Layer 3 Info");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008089 f_create_bssmap_exp(l3_enc);
8090
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008091 /* RSL_Emulation.f_chan_est() on rsl_pt:
8092 * This is basically code dup with s/RSL/rsl_pt from:
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008093 * RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
8094 */
8095 var RSL_Message rx_rsl;
8096 var GsmRrMessage rr;
8097
8098 /* request a channel to be established */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008099 rsl_pt.send(ts_RSLDC_ChanRqd(g_pars.ra, g_pars.fn));
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008100 /* expect immediate assignment.
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008101 * Code dup with s/RSL/rsl_pt from:
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008102 * rx_rsl := f_rx_or_fail(tr_RSL_IMM_ASSIGN);
8103 */
8104 timer Tt := 10.0;
8105
8106 /* request a channel to be established */
8107 Tt.start;
8108 alt {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008109 [] rsl_pt.receive(tr_RSL_IMM_ASSIGN) -> value rx_rsl {
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008110 Tt.stop;
8111 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008112 [] rsl_pt.receive {
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008113 setverdict(fail, "Unexpected RSL message on DCHAN");
8114 mtc.stop;
8115 }
8116 [] Tt.timeout {
8117 setverdict(fail, "Timeout waiting for RSL on DCHAN");
8118 mtc.stop;
8119 }
8120 }
8121 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
8122 g_chan_nr := rr.payload.imm_ass.chan_desc.chan_nr;
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008123 rsl_pt.send(ts_RSL_EST_IND(g_chan_nr, valueof(g_pars.link_id), l3_enc));
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008124
8125
Neels Hofmeyr66e15092020-10-12 18:44:41 +00008126 if (expect_bssmap_l3) {
8127 f_logp(BSCVTY, "expect BSSAP Complete Layer 3 Info at MSC");
8128 var template PDU_BSSAP exp_l3_compl;
8129 exp_l3_compl := tr_BSSMAP_ComplL3()
8130 if (g_pars.aoip == false) {
8131 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := omit;
8132 } else {
8133 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := ?;
8134 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008135
Neels Hofmeyr66e15092020-10-12 18:44:41 +00008136 var PDU_BSSAP bssap;
8137 T.start;
8138 alt {
8139 [] BSSAP.receive(exp_l3_compl) -> value bssap {
8140 f_logp(BSCVTY, "received expected Complete Layer 3 Info at MSC");
8141 log("rx exp_l3_compl = ", bssap);
8142 }
8143 [] BSSAP.receive(tr_BSSMAP_ComplL3) {
8144 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching COMPLETE LAYER 3 INFORMATION");
8145 }
8146 [] T.timeout {
8147 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
8148 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008149 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008150
Neels Hofmeyr66e15092020-10-12 18:44:41 +00008151 /* start ciphering, if requested */
8152 if (ispresent(g_pars.encr)) {
8153 f_logp(BSCVTY, "start ciphering");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008154 f_cipher_mode(g_pars.encr, rsl_pt := rsl_pt, rsl_proc_pt := rsl_proc_pt);
Neels Hofmeyr66e15092020-10-12 18:44:41 +00008155 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008156 }
8157
8158 if (do_clear) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008159 f_perform_clear(rsl_pt, rsl_proc_pt);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008160 }
8161 setverdict(pass);
8162 f_sleep(1.0);
8163}
8164
8165private function f_tc_mscpool_compl_l3(charstring id) runs on MSC_ConnHdlr {
8166 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8167 if (g_pars.mscpool.rsl_idx == 0) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008168 f_perform_compl_l3(RSL, RSL_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008169 } else if (g_pars.mscpool.rsl_idx == 1) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008170 f_perform_compl_l3(RSL1, RSL1_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008171 } else if (g_pars.mscpool.rsl_idx == 2) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008172 f_perform_compl_l3(RSL2, RSL2_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008173 }
8174}
8175
8176/* Various Complete Layer 3 by IMSI all end up with the first MSC, because the other MSCs are not connected. */
8177private function f_tc_mscpool_L3Compl_on_1_msc(charstring id) runs on MSC_ConnHdlr {
8178 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008179 f_perform_compl_l3(RSL, RSL_PROC, ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O) );
8180 f_perform_compl_l3(RSL, RSL_PROC, ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_IMSI_LV('001010000000002'H))) );
8181 f_perform_compl_l3(RSL, RSL_PROC, ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))) );
8182 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 +02008183}
8184testcase TC_mscpool_L3Compl_on_1_msc() runs on test_CT {
8185
8186 f_init(1, true);
8187 f_sleep(1.0);
8188 var MSC_ConnHdlr vc_conn;
8189 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008190
8191 f_ctrs_msc_init();
8192
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008193 vc_conn := f_start_handler(refers(f_tc_mscpool_L3Compl_on_1_msc), pars);
8194 vc_conn.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008195
8196 f_ctrs_msc_expect(0, "mscpool:subscr:new", 4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008197 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008198}
8199
8200/* Three Layer 3 Complete by IMSI are round-robin'ed across two connected MSCs */
8201/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8202 * just as well using only RSL. */
8203testcase TC_mscpool_L3Complete_by_imsi_round_robin() runs on test_CT {
8204
8205 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8206 f_sleep(1.0);
8207
8208 /* Control which MSC gets chosen next by the round-robin, otherwise
8209 * would be randomly affected by which other tests ran before this. */
8210 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8211
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008212 f_ctrs_msc_init();
8213
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008214 var MSC_ConnHdlr vc_conn1;
8215 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8216 pars1.mscpool.rsl_idx := 0;
8217 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
8218 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8219 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008220 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008221
8222 var MSC_ConnHdlr vc_conn2;
8223 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8224 pars2.mscpool.rsl_idx := 1;
8225 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8226 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8227 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008228 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008229
8230 /* Test round-robin wrap to the first MSC */
8231 var MSC_ConnHdlr vc_conn3;
8232 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8233 pars3.mscpool.rsl_idx := 2;
8234 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
8235 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8236 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008237 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008238 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008239}
8240
8241/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 0
8242 * (configured in osmo-bsc.cfg). */
8243/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8244 * just as well using only RSL. */
8245testcase TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() runs on test_CT {
8246
8247 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8248 f_sleep(1.0);
8249
8250 /* Control which MSC gets chosen next by the round-robin, otherwise
8251 * would be randomly affected by which other tests ran before this. */
8252 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8253
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008254 f_ctrs_msc_init();
8255
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008256 var MSC_ConnHdlr vc_conn1;
8257 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8258 pars1.mscpool.rsl_idx := 0;
8259 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
8260 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8261 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008262 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008263
8264 var MSC_ConnHdlr vc_conn2;
8265 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
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(0)), '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(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008271
8272 /* Test round-robin wrap to the first MSC */
8273 var MSC_ConnHdlr vc_conn3;
8274 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8275 pars3.mscpool.rsl_idx := 2;
8276 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
8277 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8278 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008279 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008280 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008281}
8282
8283/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 1
8284 * (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
8285 * NULL-NRI setting is stronger than that. */
8286/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8287 * just as well using only RSL. */
8288testcase TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() runs on test_CT {
8289
8290 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8291 f_sleep(1.0);
8292
8293 /* Control which MSC gets chosen next by the round-robin, otherwise
8294 * would be randomly affected by which other tests ran before this. */
8295 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8296
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008297 f_ctrs_msc_init();
8298
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008299 var MSC_ConnHdlr vc_conn1;
8300 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8301 pars1.mscpool.rsl_idx := 0;
8302 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8303 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8304 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008305 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008306
8307 var MSC_ConnHdlr vc_conn2;
8308 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8309 pars2.mscpool.rsl_idx := 1;
8310 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8311 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8312 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008313 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008314
8315 /* Test round-robin wrap to the first MSC */
8316 var MSC_ConnHdlr vc_conn3;
8317 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8318 pars3.mscpool.rsl_idx := 2;
8319 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
8320 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8321 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008322 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008323 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008324}
8325
8326/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI not
8327 * assigned to any MSC (configured in osmo-bsc.cfg). */
8328/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8329 * just as well using only RSL. */
8330testcase TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() runs on test_CT {
8331
8332 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8333 f_sleep(1.0);
8334
8335 /* Control which MSC gets chosen next by the round-robin, otherwise
8336 * would be randomly affected by which other tests ran before this. */
8337 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8338
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008339 f_ctrs_msc_init();
8340
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008341 var MSC_ConnHdlr vc_conn1;
8342 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8343 pars1.mscpool.rsl_idx := 0;
8344 /* An NRI that is not assigned to any MSC */
8345 pars1.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(1023))));
8346 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8347 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008348 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008349
8350 var MSC_ConnHdlr vc_conn2;
8351 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8352 pars2.mscpool.rsl_idx := 1;
8353 /* An NRI that is not assigned to any MSC */
8354 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(768)), '00F110'O));
8355 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8356 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008357 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008358
8359 /* Test round-robin wrap to the first MSC */
8360 var MSC_ConnHdlr vc_conn3;
8361 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8362 pars3.mscpool.rsl_idx := 2;
8363 /* An NRI that is not assigned to any MSC */
8364 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, valueof(ts_MI_TMSI_NRI_LV(819))));
8365 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8366 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008367 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008368 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008369}
8370
8371/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI
8372 * assigned to an MSC that is currently not connected (configured in osmo-bsc.cfg). */
8373/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8374 * just as well using only RSL. */
8375testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() runs on test_CT {
8376
8377 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8378 f_sleep(1.0);
8379
8380 /* Control which MSC gets chosen next by the round-robin, otherwise
8381 * would be randomly affected by which other tests ran before this. */
8382 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8383
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008384 f_ctrs_msc_init();
8385
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008386 var MSC_ConnHdlr vc_conn1;
8387 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8388 pars1.mscpool.rsl_idx := 0;
8389 /* An NRI that is assigned to an unconnected MSC */
8390 pars1.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(512))));
8391 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8392 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008393 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8394 f_ctrs_msc_add(0, "mscpool:subscr:new");
8395 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008396
8397 var MSC_ConnHdlr vc_conn2;
8398 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8399 pars2.mscpool.rsl_idx := 1;
8400 /* An NRI that is assigned to an unconnected MSC */
8401 pars2.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(767))));
8402 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8403 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008404 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8405 f_ctrs_msc_add(1, "mscpool:subscr:new");
8406 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008407
8408 /* Test round-robin wrap to the first MSC */
8409 var MSC_ConnHdlr vc_conn3;
8410 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8411 pars3.mscpool.rsl_idx := 2;
8412 /* An NRI that is assigned to an unconnected MSC */
8413 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(750)), '00F110'O));
8414 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8415 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008416 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8417 f_ctrs_msc_add(0, "mscpool:subscr:new");
8418 f_ctrs_msc_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008419 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008420}
8421
8422/* Three Layer 3 Complete by TMSI with valid NRI for the second MSC are all directed to the second MSC (configured in
8423 * osmo-bsc.cfg). */
8424/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8425 * just as well using only RSL. */
8426testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_1() runs on test_CT {
8427
8428 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8429 f_sleep(1.0);
8430
8431 /* All TMSIs in this test point at the second MSC, set the round robin to point at the first MSC to make sure
8432 * this is not using round-robin. */
8433 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8434
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008435 f_ctrs_msc_init();
8436
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008437 var MSC_ConnHdlr vc_conn1;
8438 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
8439 pars1.mscpool.rsl_idx := 0;
8440 /* An NRI of the second MSC's range (256-511) */
8441 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(256))));
8442 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8443 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008444 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008445
8446 var MSC_ConnHdlr vc_conn2;
8447 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8448 pars2.mscpool.rsl_idx := 1;
8449 /* An NRI of the second MSC's range (256-511) */
8450 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(260))));
8451 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8452 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008453 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008454
8455 var MSC_ConnHdlr vc_conn3;
8456 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
8457 pars3.mscpool.rsl_idx := 2;
8458 /* An NRI of the second MSC's range (256-511) */
8459 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(511)), '00F110'O));
8460 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8461 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008462 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008463 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008464}
8465
8466/* Layer 3 Complete by TMSI with valid NRI for the third MSC are directed to the third MSC (configured in osmo-bsc.cfg),
8467 * while a round-robin remains unaffected by that. */
8468/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8469 * just as well using only RSL. */
8470testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_2() runs on test_CT {
8471
8472 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8473 f_sleep(1.0);
8474
8475 /* All TMSIs in this test point at the third MSC, set the round robin to point at the second MSC to make sure
8476 * this is not using round-robin. */
8477 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
8478
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008479 f_ctrs_msc_init();
8480
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008481 var MSC_ConnHdlr vc_conn1;
8482 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 2);
8483 pars1.mscpool.rsl_idx := 0;
8484 /* An NRI of the third MSC's range (512-767) */
8485 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(512))));
8486 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8487 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008488 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008489
8490 var MSC_ConnHdlr vc_conn2;
8491 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8492 pars2.mscpool.rsl_idx := 1;
8493 /* An NRI of the third MSC's range (512-767) */
8494 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(678))));
8495 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8496 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008497 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008498
8499 /* The above forwardings to third MSC have not affected the round robin, which still points at the second MSC */
8500 var MSC_ConnHdlr vc_conn3;
8501 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
8502 pars3.mscpool.rsl_idx := 2;
8503 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000013'H)), '00F110'O));
8504 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8505 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008506 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008507 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008508}
8509
8510/* LU with a TMSI but indicating a different PLMN in its previous LAI: ignore the NRI. */
8511/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8512 * just as well using only RSL. */
8513testcase TC_mscpool_LU_by_tmsi_from_other_PLMN() runs on test_CT {
8514
8515 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8516 f_sleep(1.0);
8517
8518 /* The TMSIs in this test points at the second MSC, but since it is from a different PLMN, round-robin is used
8519 * instead, and hits msc 0. */
8520 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8521
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008522 f_ctrs_msc_init();
8523
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008524 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-bsc.cfg */
8525 var MSC_ConnHdlr vc_conn1;
8526 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8527 pars1.mscpool.rsl_idx := 0;
8528 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(260)), '99F999'O));
8529 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8530 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008531 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008532
8533 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
8534 var MSC_ConnHdlr vc_conn2;
8535 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8536 pars2.mscpool.rsl_idx := 1;
8537 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(555)), '00F110'O));
8538 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8539 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008540 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008541 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008542}
8543
8544/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by IMSI, which would be
8545 * round-robined to another MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
8546private function f_tc_mscpool_paging_imsi(charstring id) runs on MSC_ConnHdlr {
8547 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
8548 //cid_list := { cIl_allInBSS := ''O };
8549 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
8550 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
8551 var BSSAP_N_UNITDATA_req paging;
8552 var hexstring imsi := '001010000000123'H;
8553
8554 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8555
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008556 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008557 valueof(ts_BSSMAP_Paging(imsi, cid_list, omit, bssmap_chneed))));
8558 BSSAP.send(paging);
8559
8560 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
8561 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
8562 * channel number is picked here. */
8563 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
8564 f_rslem_register(0, new_chan_nr);
8565 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(imsi)));
8566 f_rslem_unregister(0, new_chan_nr);
8567
8568 /* Despite the round robin pointing at the second MSC ('roundrobin next 1'), the earlier Paging for the same IMSI
8569 * causes this Paging Response to go to the first MSC (bssap_idx := 0). */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008570 f_perform_compl_l3(RSL, RSL_PROC, ts_PAG_RESP(valueof(ts_MI_IMSI_LV(imsi))) );
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008571 f_sleep(1.0);
8572}
8573testcase TC_mscpool_paging_and_response_imsi() runs on test_CT {
8574 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
8575 f_sleep(1.0);
8576
8577 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
8578 * second MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
8579 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
8580
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008581 f_ctrs_msc_init();
8582
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008583 var MSC_ConnHdlr vc_conn1;
8584 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8585 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008586 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
8587 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008588 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_imsi), pars1);
8589 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008590 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008591 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008592}
8593
8594/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by TMSI with an NRI value
8595 * that matches a different MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
8596private function f_tc_mscpool_paging_tmsi(charstring id) runs on MSC_ConnHdlr {
8597 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
8598 //cid_list := { cIl_allInBSS := ''O };
8599 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
8600 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
8601 var integer nri_v := 300; /* <-- second MSC's NRI */
Harald Weltebf397612021-01-14 20:39:46 +01008602 var octetstring tmsi := f_gen_tmsi(suffix := 0, nri_v := nri_v);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008603 var BSSAP_N_UNITDATA_req paging;
8604
8605 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8606
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008607 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008608 valueof(ts_BSSMAP_Paging('001010000000011'H, cid_list, tmsi, bssmap_chneed))));
8609 BSSAP.send(paging);
8610
8611 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
8612 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
8613 * channel number is picked here. */
8614 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
8615 f_rslem_register(0, new_chan_nr);
8616 RSL.receive(tr_RSL_PAGING_CMD(t_MI_TMSI(tmsi)));
8617 f_rslem_unregister(0, new_chan_nr);
8618
8619 /* Despite the NRI matching the second MSC (NRI from 'msc 1' in osmo-bsc.cfg) and round robin pointing at the
8620 * third MSC ('roundrobin next 2'), the earlier Paging for the same TMSI causes this Paging Response to go to
8621 * the first MSC (bssap_idx := 0). */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008622 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 +02008623 f_sleep(1.0);
8624}
8625testcase TC_mscpool_paging_and_response_tmsi() runs on test_CT {
8626 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
8627 f_sleep(1.0);
8628
8629 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
8630 * third MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
8631 f_vty_transceive(BSCVTY, "mscpool roundrobin next 2");
8632
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008633 f_ctrs_msc_init();
8634
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008635 var MSC_ConnHdlr vc_conn1;
8636 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8637 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008638 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
8639 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008640 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_tmsi), pars1);
8641 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008642 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008643 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008644}
8645
8646/* For round-robin, skip an MSC that has 'no allow-attach' set. */
8647/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8648 * just as well using only RSL. */
8649testcase TC_mscpool_no_allow_attach_round_robin() runs on test_CT {
8650
8651 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8652 f_sleep(1.0);
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00008653 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
8654 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008655
8656 /* Control which MSC gets chosen next by the round-robin, otherwise
8657 * would be randomly affected by which other tests ran before this. */
8658 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8659
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008660 f_ctrs_msc_init();
8661
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008662 var MSC_ConnHdlr vc_conn1;
8663 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8664 pars1.mscpool.rsl_idx := 0;
8665 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
8666 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8667 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008668 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008669
8670 var MSC_ConnHdlr vc_conn2;
8671 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8672 pars2.mscpool.rsl_idx := 1;
8673 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8674 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8675 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008676 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008677
8678 var MSC_ConnHdlr vc_conn3;
8679 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8680 pars3.mscpool.rsl_idx := 2;
8681 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
8682 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8683 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008684 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008685 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008686}
8687
8688/* An MSC that has 'no allow-attach' set should still serve subscribers that are already attached according to their
8689 * TMSI NRI. */
8690testcase TC_mscpool_no_allow_attach_valid_nri() runs on test_CT {
8691
8692 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8693 f_sleep(1.0);
8694
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00008695 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
8696 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
8697
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008698 /* Control which MSC gets chosen next by the round-robin, otherwise
8699 * would be randomly affected by which other tests ran before this. */
8700 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8701
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008702 f_ctrs_msc_init();
8703
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008704 /* Round robin points at msc 0, but the valid NRI directs to msc 1, even though msc 1 has 'no allow-attach'. */
8705 var MSC_ConnHdlr vc_conn1;
8706 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
8707 pars1.mscpool.rsl_idx := 0;
8708 /* An NRI of the second MSC's range (256-511) */
8709 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_TMSI_NRI_LV(260))));
8710 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8711 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008712 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008713
8714 var MSC_ConnHdlr vc_conn2;
8715 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 0);
8716 pars2.mscpool.rsl_idx := 1;
8717 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8718 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8719 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008720 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008721
8722 var MSC_ConnHdlr vc_conn3;
8723 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 2);
8724 pars3.mscpool.rsl_idx := 2;
8725 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000003'H))));
8726 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8727 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008728 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008729 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008730}
8731
Philipp Maier783681c2020-07-16 16:47:06 +02008732/* Allow/Deny emergency calls globally via VTY */
8733private function f_vty_allow_emerg_msc(boolean allow) runs on test_CT {
8734 f_vty_enter_cfg_msc(BSCVTY, 0);
8735 if (allow) {
8736 f_vty_transceive(BSCVTY, "allow-emergency allow");
8737 } else {
8738 f_vty_transceive(BSCVTY, "allow-emergency deny");
8739 }
8740 f_vty_transceive(BSCVTY, "exit");
8741 f_vty_transceive(BSCVTY, "exit");
8742}
8743
8744/* Allow/Deny emergency calls per BTS via VTY */
8745private function f_vty_allow_emerg_bts(boolean allow, integer bts_nr) runs on test_CT {
8746 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8747 if (allow) {
8748 f_vty_transceive(BSCVTY, "rach emergency call allowed 1");
8749 } else {
8750 f_vty_transceive(BSCVTY, "rach emergency call allowed 0");
8751 }
8752 f_vty_transceive(BSCVTY, "exit");
8753 f_vty_transceive(BSCVTY, "exit");
Neels Hofmeyrb6ed80c2020-10-12 22:52:39 +00008754 f_vty_transceive(BSCVTY, "exit");
Philipp Maier783681c2020-07-16 16:47:06 +02008755}
8756
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02008757/* Allow/Forbid Fast Return after SRVCC on a given BTS via VTY */
8758private function f_vty_allow_srvcc_fast_return(boolean allow, integer bts_nr) runs on test_CT {
8759 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8760 if (allow) {
8761 f_vty_transceive(BSCVTY, "srvcc fast-return allow");
8762 } else {
8763 f_vty_transceive(BSCVTY, "srvcc fast-return forbid");
8764 }
8765 f_vty_transceive(BSCVTY, "exit");
8766 f_vty_transceive(BSCVTY, "exit");
8767 f_vty_transceive(BSCVTY, "exit");
8768}
8769
Pau Espin Pedrol14475352021-07-22 15:48:16 +02008770/* Allow/Forbid TCH for signalling if SDCCH exhausted on a given BTS via VTY */
8771private function f_vty_allow_tch_for_signalling(boolean allow, integer bts_nr) runs on test_CT {
8772 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8773 if (allow) {
8774 f_vty_transceive(BSCVTY, "channel allocator allow-tch-for-signalling 1");
8775 } else {
8776 f_vty_transceive(BSCVTY, "channel allocator allow-tch-for-signalling 0");
8777 }
8778 f_vty_transceive(BSCVTY, "exit");
8779 f_vty_transceive(BSCVTY, "exit");
8780 f_vty_transceive(BSCVTY, "exit");
8781}
8782
Philipp Maier783681c2020-07-16 16:47:06 +02008783/* Begin assignmet procedure and send an EMERGENCY SETUP (RR) */
8784private function f_assignment_emerg_setup() runs on MSC_ConnHdlr {
8785 var PDU_ML3_MS_NW emerg_setup;
8786 var octetstring emerg_setup_enc;
8787 var RSL_Message emerg_setup_data_ind;
8788
8789 f_establish_fully(omit, omit);
8790
8791 emerg_setup := valueof(ts_ML3_MO_CC_EMERG_SETUP(1, valueof(ts_Bcap_voice)));
8792 emerg_setup_enc := enc_PDU_ML3_MS_NW(emerg_setup);
8793 emerg_setup_data_ind := valueof(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), emerg_setup_enc));
8794
8795 RSL.send(emerg_setup_data_ind);
8796}
8797
8798/* Test if the EMERGENCY SETUP gets passed on to the MSC via A when EMERGENCY
8799 * CALLS are permitted by the BSC config. */
8800private function f_TC_assignment_emerg_setup_allow(charstring id) runs on MSC_ConnHdlr {
8801 var PDU_BSSAP emerg_setup_data_ind_bssap;
8802 var PDU_ML3_MS_NW emerg_setup;
8803 timer T := 3.0;
8804
8805 f_assignment_emerg_setup()
8806
8807 T.start;
8808 alt {
8809 [] BSSAP.receive(tr_BSSAP_DTAP) -> value emerg_setup_data_ind_bssap {
8810 emerg_setup := dec_PDU_ML3_MS_NW(emerg_setup_data_ind_bssap.pdu.dtap);
8811 if (not isbound(emerg_setup.msgs.cc.emergencySetup)) {
8812 setverdict(fail, "no emergency setup");
8813 }
8814 }
8815 [] BSSAP.receive {
8816 setverdict(fail, "unexpected BSSAP message!");
8817 }
8818 [] T.timeout {
8819 setverdict(fail, "timout waiting for EMERGENCY SETUP!");
8820 }
8821 }
8822
8823 setverdict(pass);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01008824 f_perform_clear();
Philipp Maier783681c2020-07-16 16:47:06 +02008825}
8826
8827/* Test if the EMERGENCY SETUP gets blocked by the BSC if EMERGENCY CALLS are
8828 * forbidden by the BSC config. */
8829private function f_TC_assignment_emerg_setup_deny(charstring id) runs on MSC_ConnHdlr {
8830 var PDU_BSSAP emerg_setup_data_ind_bssap;
8831 timer T := 3.0;
8832
8833 f_assignment_emerg_setup()
8834
8835 T.start;
8836 alt {
8837 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
8838 setverdict(pass);
8839 }
8840 [] RSL.receive {
8841 setverdict(fail, "unexpected RSL message!");
8842 }
8843 [] T.timeout {
8844 setverdict(fail, "timout waiting for RR CHANNEL RELEASE!");
8845 }
8846 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01008847 BSSAP.receive(tr_BSSMAP_ClearRequest);
Neels Hofmeyrc3c6ee62022-01-26 01:22:12 +01008848 f_perform_clear_no_rr_rel();
Philipp Maier783681c2020-07-16 16:47:06 +02008849}
8850
8851/* EMERGENCY CALL situation #1, allowed globally and by BTS */
8852testcase TC_assignment_emerg_setup_allow() runs on test_CT {
8853 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8854 var MSC_ConnHdlr vc_conn;
8855
8856 f_init(1, true);
8857 f_sleep(1.0);
8858
8859 f_vty_allow_emerg_msc(true);
8860 f_vty_allow_emerg_bts(true, 0);
8861 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_allow), pars);
8862 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008863 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008864}
8865
8866/* EMERGENCY CALL situation #2, forbidden globally but allowed by BTS */
8867testcase TC_assignment_emerg_setup_deny_msc() runs on test_CT {
8868 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8869 var MSC_ConnHdlr vc_conn;
8870
8871 f_init(1, true);
8872 f_sleep(1.0);
8873
8874 f_vty_allow_emerg_msc(false);
8875 f_vty_allow_emerg_bts(true, 0);
8876 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
8877 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008878 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008879}
8880
8881/* EMERGENCY CALL situation #3, allowed globally but forbidden by BTS */
8882testcase TC_assignment_emerg_setup_deny_bts() runs on test_CT {
8883 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8884 var MSC_ConnHdlr vc_conn;
8885
8886 /* Note: This simulates a spec violation by the MS, correct MS
8887 * implementations would not try to establish an emergency call because
8888 * the system information tells in advance that emergency calls are
8889 * not forbidden */
8890
8891 f_init(1, true);
8892 f_sleep(1.0);
8893
8894 f_vty_allow_emerg_msc(true);
8895 f_vty_allow_emerg_bts(false, 0);
8896 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
8897 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008898 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008899}
8900
Philipp Maier82812002020-08-13 18:48:27 +02008901/* Test what happens when an emergency call arrives while all TCH channels are
8902 * busy, the BSC is expected to terminate one call in favor of the incoming
8903 * emergency call */
8904testcase TC_emerg_premption() runs on test_CT {
8905 var ASP_RSL_Unitdata rsl_ud;
8906 var integer i;
8907 var integer chreq_total, chreq_nochan;
8908 var RSL_Message rx_rsl;
8909 var RslChannelNr chan_nr;
8910
8911 f_init(1);
8912 f_sleep(1.0);
8913
8914 f_vty_allow_emerg_msc(true);
8915 f_vty_allow_emerg_bts(true, 0);
8916
8917 /* Fill up all channels on the BTS */
8918 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
8919 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
8920 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS; i := i+1) {
8921 chan_nr := f_chreq_act_ack('33'O, i);
8922 }
8923 IPA_RSL[0].clear;
8924 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
8925 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
8926
8927 /* Send Channel request for emegergency call */
8928 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
8929
8930 /* Expect the BSC to release one (the first) TCH/F on the BTS */
8931 chan_nr := valueof(t_RslChanNr_Bm(1));
8932 f_expect_chan_rel(0, chan_nr, expect_rr_chan_rel := false, expect_rll_rel_req := false);
8933
8934 /* Expect the BSC to send activate/assign the a channel for the emergency call */
8935 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8936 chan_nr := rx_rsl.ies[0].body.chan_nr;
8937 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 33));
8938 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Philipp Maier104f4c02020-09-11 18:12:18 +02008939
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008940 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008941}
8942
8943/* Hopping parameters per a timeslot */
Vadim Yanitskiybc6654a2020-09-13 01:27:40 +07008944private type record length(0..64) of GsmArfcn ArfcnList;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008945private type record FHParamsTs {
8946 boolean enabled,
8947 uint6_t hsn,
8948 uint6_t maio,
8949 ArfcnList ma
8950};
8951
8952/* Hopping parameters per a transceiver */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008953private type record FHParamsTrx {
Philipp Maier798d8952021-10-19 14:43:19 +02008954 GsmBandArfcn arfcn,
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008955 FHParamsTs ts[8]
8956};
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008957
8958/* Randomly generate the hopping parameters for the given timeslot numbers */
8959private function f_TC_fh_params_gen(template integer tr_tn := (1, 3, 5))
8960runs on test_CT return FHParamsTrx {
8961 var FHParamsTrx fhp;
8962
Philipp Maier798d8952021-10-19 14:43:19 +02008963 /* Generate a random ARFCN in the range of 0 - 3. This ARFCN will
8964 * fall in the GSM900 band. */
8965 fhp.arfcn.arfcn := f_rnd_int(3);
8966 fhp.arfcn.pcs := false;
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008967
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008968 for (var integer tn := 0; tn < 8; tn := tn + 1) {
8969 if (not match(tn, tr_tn)) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008970 fhp.ts[tn].enabled := false;
8971 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008972 continue;
8973 }
8974
8975 /* Random HSN / MAIO values: 0..63 */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008976 fhp.ts[tn].hsn := f_rnd_int(64);
8977 fhp.ts[tn].maio := f_rnd_int(64);
8978 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008979
8980 /* Random Mobile Allocation (hopping channels) */
8981 var integer ma_len := 2 + f_rnd_int(9); /* 2..10 channels */
8982 var integer step := 3 + f_rnd_int(4); /* 3..6 stepping */
8983 for (var integer i := 1; i <= ma_len; i := i + 1) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008984 fhp.ts[tn].ma := fhp.ts[tn].ma & { i * step };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008985 }
8986
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008987 fhp.ts[tn].enabled := true;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008988 }
8989
8990 log("f_TC_fh_params_gen(): ", fhp);
8991 return fhp;
8992}
8993
8994/* Make sure that the given Channel Description IE matches the hopping configuration */
8995private function f_TC_fh_params_match_chan_desc(in FHParamsTrx fhp, in ChannelDescription cd)
8996{
8997 var template (present) ChannelDescription tr_cd;
8998 var template (present) MaioHsn tr_maio_hsn;
8999 var uint3_t tn := cd.chan_nr.tn;
9000
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009001 if (fhp.ts[tn].enabled) {
9002 tr_maio_hsn := tr_HsnMaio(fhp.ts[tn].hsn, fhp.ts[tn].maio);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009003 tr_cd := tr_ChanDescH1(cd.chan_nr, tr_maio_hsn);
9004 } else {
Philipp Maier798d8952021-10-19 14:43:19 +02009005 tr_cd := tr_ChanDescH0(cd.chan_nr, fhp.arfcn.arfcn);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009006 }
9007
9008 if (not match(cd, tr_cd)) {
9009 setverdict(fail, "Channel Description IE does not match: ",
9010 cd, " vs expected ", tr_cd);
9011 }
9012}
9013
9014/* Make sure that the given Mobile Allocation IE matches the hopping configuration */
9015private function f_TC_fh_params_match_ma(in FHParamsTrx fhp, uint3_t tn,
9016 in MobileAllocationLV ma)
9017{
9018 var template MobileAllocationLV tr_ma := f_TC_fh_params_gen_tr_ma(fhp, tn, ma);
9019
9020 if (not match(ma, tr_ma)) {
9021 setverdict(fail, "Mobile Allocation IE does not match (tn := ",
9022 tn, "): ", ma, " vs expected: ", tr_ma);
9023 } else {
9024 setverdict(pass);
9025 }
9026}
9027
9028private function f_TC_fh_params_gen_tr_ma(in FHParamsTrx fhp, uint3_t tn,
9029 in MobileAllocationLV ma)
9030return template MobileAllocationLV {
9031 /* Mobile Allocation IE is expected to be empty if hopping is not enabled */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009032 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009033 return { len := 0, ma := ''B };
9034 }
9035
9036 var bitstring full_mask := f_pad_bit(''B, 1024, '0'B);
9037 var bitstring slot_mask := f_pad_bit(''B, 1024, '0'B);
9038 var bitstring ma_mask := ''B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009039
9040 /* Compose the full bit-mask (all channels, up to 1024 entries) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009041 for (var integer i := 0; i < lengthof(fhp.ts); i := i + 1) {
9042 for (var integer j := 0; j < lengthof(fhp.ts[i].ma); j := j + 1) {
9043 if (full_mask[fhp.ts[i].ma[j]] == '1'B)
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009044 { continue; }
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009045 full_mask[fhp.ts[i].ma[j]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009046 }
9047 }
9048
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009049 /* Take ARFCN of the TRX itself into account */
Philipp Maier798d8952021-10-19 14:43:19 +02009050 full_mask[fhp.arfcn.arfcn] := '1'B;
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009051
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009052 /* Compose a bit-mask for the given timeslot number */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009053 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
9054 slot_mask[fhp.ts[tn].ma[i]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009055 }
9056
9057 /* Finally, compose the Mobile Allocation bit-mask */
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07009058 for (var integer i := 1; i < lengthof(full_mask); i := i + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009059 if (full_mask[i] != '1'B)
9060 { continue; }
9061
9062 /* FIXME: ma_mask := ma_mask & slot_mask[i]; // triggers a bug in TITAN */
9063 if (slot_mask[i] == '1'B) {
9064 ma_mask := ma_mask & '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009065 } else {
9066 ma_mask := ma_mask & '0'B;
9067 }
9068 }
9069
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07009070 /* ARFCN 0 (if present) goes to the last position of the bit-mask */
9071 if (full_mask[0] == '1'B) {
9072 /* FIXME: ma_mask := ma_mask & slot_mask[0]; // triggers a bug in TITAN */
9073 if (slot_mask[0] == '1'B) {
9074 ma_mask := ma_mask & '1'B;
9075 } else {
9076 ma_mask := ma_mask & '0'B;
9077 }
9078 }
9079
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009080 /* Ensure that ma_mask is octet-aligned */
Vadim Yanitskiy2aa02522020-09-06 14:05:23 +07009081 var integer ma_mask_len := (lengthof(ma_mask) + 8 - 1) / 8;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009082 ma_mask := f_pad_bit(ma_mask, ma_mask_len * 8, '0'B);
9083
9084 return { len := ma_mask_len, ma := ma_mask };
9085}
9086
Philipp Maier798d8952021-10-19 14:43:19 +02009087/* Configure the appropriate band for a given arfcn, exc */
9088private function f_TC_set_band_by_arfcn(integer bts_nr, GsmBandArfcn arfcn) runs on test_CT
9089{
9090 var charstring band;
9091 var GsmBandArfcn arfcn_ := valueof(ts_GsmBandArfcn(arfcn.arfcn, arfcn.pcs, false));
9092
9093 select (arfcn_) {
9094 case (tr_GsmBandArfcn((259..293), false, ?)) { band := "GSM450"; }
9095 case (tr_GsmBandArfcn((306..340), false, ?)) { band := "GSM480"; }
9096 case (tr_GsmBandArfcn((438..511), false, ?)) { band := "GSM750"; }
9097 case (tr_GsmBandArfcn((128..251), false, ?)) { band := "GSM850"; }
9098 case (tr_GsmBandArfcn((0..124), false, ?)) { band := "GSM900"; }
9099 case (tr_GsmBandArfcn((955..1023), false, ?)) { band := "GSM900"; }
9100 case (tr_GsmBandArfcn((512..885), false, ?)) { band := "DCS1800"; }
9101 case (tr_GsmBandArfcn((512..810), true, ?)) { band := "PCS1900"; }
9102 case else { return; }
9103 }
9104
9105 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
9106 f_vty_transceive(BSCVTY, "band " & band);
9107 f_vty_transceive(BSCVTY, "end");
9108}
9109
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009110/* Configure the hopping parameters in accordance with the given record */
9111private function f_TC_fh_params_set(in FHParamsTrx fhp,
9112 uint8_t bts_nr := 0,
9113 uint8_t trx_nr := 0)
9114runs on test_CT {
Philipp Maier798d8952021-10-19 14:43:19 +02009115
9116 f_TC_set_band_by_arfcn(bts_nr, fhp.arfcn);
9117
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009118 /* Enter the configuration node for the given BTS/TRX numbers */
9119 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
9120
Philipp Maier798d8952021-10-19 14:43:19 +02009121 f_vty_transceive(BSCVTY, "arfcn " & int2str(fhp.arfcn.arfcn));
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009122
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009123 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009124 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
9125
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009126 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009127 f_vty_transceive(BSCVTY, "hopping enabled 0");
9128 f_vty_transceive(BSCVTY, "exit"); /* go back */
9129 continue;
9130 }
9131
9132 /* Configure HSN / MAIO values */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009133 f_vty_transceive(BSCVTY, "hopping sequence-number " & int2str(fhp.ts[tn].hsn));
9134 f_vty_transceive(BSCVTY, "hopping maio " & int2str(fhp.ts[tn].maio));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009135
9136 /* Configure the Mobile Allocation (hopping channels) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009137 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
9138 f_vty_transceive(BSCVTY, "hopping arfcn add " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009139 }
9140
9141 f_vty_transceive(BSCVTY, "hopping enabled 1");
9142 f_vty_transceive(BSCVTY, "exit"); /* go back */
9143 }
9144
9145 f_vty_transceive(BSCVTY, "end");
9146}
9147
9148/* Disable frequency hopping on all timeslots */
9149private function f_TC_fh_params_unset(in FHParamsTrx fhp,
9150 uint8_t bts_nr := 0,
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009151 uint8_t trx_nr := 0,
Philipp Maier798d8952021-10-19 14:43:19 +02009152 GsmBandArfcn arfcn := {pcs := false, arfcn := 871})
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009153runs on test_CT {
Philipp Maier798d8952021-10-19 14:43:19 +02009154
9155 f_TC_set_band_by_arfcn(bts_nr, arfcn);
9156
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009157 /* Enter the configuration node for the given BTS/TRX numbers */
9158 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
9159
Philipp Maier798d8952021-10-19 14:43:19 +02009160 f_vty_transceive(BSCVTY, "arfcn " & int2str(arfcn.arfcn));
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07009161
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009162 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009163 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
9164
9165 /* Delete all ARFCNs from the Mobile Allocation (if any) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07009166 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
9167 f_vty_transceive(BSCVTY, "hopping arfcn del " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009168 }
9169
9170 f_vty_transceive(BSCVTY, "hopping enabled 0");
9171 f_vty_transceive(BSCVTY, "exit"); /* go back */
9172 }
9173
9174 f_vty_transceive(BSCVTY, "end");
9175 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9176}
9177
9178/* Verify presence and correctness of the hopping parameters (HSN, MAIO)
9179 * in the Channel Identification IE of the RSL CHANnel ACTIVation message. */
9180testcase TC_fh_params_chan_activ() runs on test_CT {
9181 var FHParamsTrx fhp := f_TC_fh_params_gen();
9182 var RSL_Message rsl_msg;
9183 var RSL_IE_Body ie;
9184
9185 f_init_vty();
9186
9187 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9188 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9189
9190 f_init(1);
9191
9192 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
9193 for (var integer i := 0; i < 9; i := i + 1) {
9194 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
9195 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9196
9197 /* Make sure that Channel Identification IE is present */
9198 if (not f_rsl_find_ie(rsl_msg, RSL_IE_CHAN_IDENT, ie)) {
9199 setverdict(fail, "RSL Channel Identification IE is absent");
9200 continue;
9201 }
9202
9203 /* Make sure that hopping parameters (HSN/MAIO) match */
9204 f_TC_fh_params_match_chan_desc(fhp, ie.chan_ident.ch_desc.v);
9205
9206 /* "Mobile Allocation shall be included but empty" - let's check this */
9207 if (ie.chan_ident.ma.v.len != 0) {
9208 setverdict(fail, "Mobile Allocation IE is not empty: ",
9209 ie.chan_ident.ma, ", despite it shall be");
9210 continue;
9211 }
9212 }
9213
9214 /* Disable frequency hopping */
9215 f_TC_fh_params_unset(fhp);
9216
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009217 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009218}
9219
9220/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Immediate Assignment */
9221testcase TC_fh_params_imm_ass() runs on test_CT {
9222 var FHParamsTrx fhp := f_TC_fh_params_gen();
9223 var RSL_Message rsl_msg;
9224 var RSL_IE_Body ie;
9225
9226 f_init_vty();
9227
9228 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9229 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9230
9231 f_init(1);
9232
9233 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
9234 for (var integer i := 0; i < 9; i := i + 1) {
9235 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
9236 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9237
9238 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9239 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
9240
9241 /* Make sure that Full Immediate Assign Info IE is present */
9242 if (not f_rsl_find_ie(rsl_msg, RSL_IE_FULL_IMM_ASS_INFO, ie)) {
9243 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
9244 continue;
9245 }
9246
9247 /* Decode the actual Immediate Assignment message */
9248 var GsmRrMessage rr_msg := dec_GsmRrMessage(ie.full_imm_ass_info.payload);
9249 if (not match(rr_msg.header, t_RrHeader(IMMEDIATE_ASSIGNMENT, ?))) {
9250 setverdict(fail, "Failed to match Immediate Assignment: ", rr_msg);
9251 continue;
9252 }
9253
9254 /* Make sure that hopping parameters (HSN/MAIO) match */
9255 f_TC_fh_params_match_chan_desc(fhp, rr_msg.payload.imm_ass.chan_desc);
9256
9257 /* Make sure that the Mobile Allocation IE matches */
9258 f_TC_fh_params_match_ma(fhp, rr_msg.payload.imm_ass.chan_desc.chan_nr.tn,
9259 rr_msg.payload.imm_ass.mobile_allocation);
9260 }
9261
9262 /* Disable frequency hopping */
9263 f_TC_fh_params_unset(fhp);
Philipp Maier82812002020-08-13 18:48:27 +02009264
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009265 f_shutdown_helper();
Philipp Maier82812002020-08-13 18:48:27 +02009266}
9267
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009268/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Assignment Command */
9269testcase TC_fh_params_assignment_cmd() runs on test_CT {
9270 var FHParamsTrx fhp := f_TC_fh_params_gen();
9271 var RSL_Message rsl_msg;
9272 var RSL_IE_Body ie;
9273
9274 f_init_vty();
9275
9276 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9277 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9278
9279 f_init(1);
9280
9281 /* HACK: work around "Couldn't find Expect for CRCX" */
9282 vc_MGCP.stop;
9283
9284 var template PDU_BSSAP ass_cmd := f_gen_ass_req();
9285 ass_cmd.pdu.bssmap.assignmentRequest.codecList := ts_BSSMAP_IE_CodecList({ts_CodecFR});
9286
9287 /* CS domain (TCH): 4 (TCH/F) + 2 (TCH/H) channels available
9288 * NOTE: only 3 SDCCH/4 channels are available on CCCH+SDCCH4+CBCH */
9289 for (var integer i := 0; i < 3; i := i + 1) {
9290 /* Establish a dedicated channel, so we can trigger (late) TCH assignment */
9291 var DchanTuple dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
9292
9293 /* Send a BSSMAP Assignment Command, expect CHANnel ACTIVation */
9294 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
9295 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9296
9297 /* ACKnowledge CHANnel ACTIVation, expect RSL DATA REQuest */
9298 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9299 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
9300
9301 /* Make sure that L3 Information IE is present */
9302 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
9303 setverdict(fail, "RSL L3 Information IE is absent");
9304 continue;
9305 }
9306
9307 /* Decode the L3 message and make sure it is (RR) Assignment Command */
9308 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
9309 if (not match(l3_msg.header, t_RrL3Header(ASSIGNMENT_COMMAND))) {
9310 setverdict(fail, "Failed to match Assignment Command: ", l3_msg);
9311 continue;
9312 }
9313
9314 /* Make sure that hopping parameters (HSN/MAIO) match */
9315 var ChannelDescription chan_desc := l3_msg.payload.ass_cmd.chan_desc;
9316 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9317
9318 /* Make sure that Cell Channel Description IE is present if FH is enabled */
9319 if (chan_desc.h and not ispresent(l3_msg.payload.ass_cmd.cell_chan_desc)) {
Vadim Yanitskiy38d069d2020-09-02 17:18:57 +07009320 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009321 continue;
9322 }
9323
9324 /* Make sure that the Mobile Allocation IE matches (if present) */
9325 var boolean ma_present := ispresent(l3_msg.payload.ass_cmd.mobile_allocation);
9326 if (chan_desc.h and ma_present) {
9327 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9328 l3_msg.payload.ass_cmd.mobile_allocation.v);
9329 } else if (chan_desc.h and not ma_present) {
9330 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9331 continue;
9332 } else if (not chan_desc.h and ma_present) {
9333 setverdict(fail, "FH disabled, but Mobile Allocation IE is present");
9334 continue;
9335 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01009336
9337 f_perform_clear_test_ct(dt);
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009338 }
9339
9340 /* Give the IUT some time to release all channels */
9341 f_sleep(3.0);
9342
9343 /* Disable frequency hopping */
9344 f_TC_fh_params_unset(fhp);
9345
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009346 f_shutdown_helper();
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009347}
9348
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009349/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Handover Command */
9350private function f_TC_fh_params_handover_cmd(in FHParamsTrx fhp)
9351runs on test_CT {
9352 var RSL_Message rsl_msg;
9353 var RSL_IE_Body ie;
9354 var DchanTuple dt;
9355
9356 /* Establish a dedicated channel, so we can trigger handover */
9357 dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
Vadim Yanitskiyc18ff472021-11-18 20:15:37 +03009358 f_sleep(0.5);
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009359
9360 /* Trigger handover from BTS0 to BTS1 */
9361 f_bts_0_cfg(BSCVTY, { "neighbor bts 1" });
9362 f_vty_handover(BSCVTY, 0, 0, dt.rsl_chan_nr, 1);
9363
9364 /* Expect RSL CHANnel ACTIVation on BTS1/TRX0/TS1 */
9365 rsl_msg := f_exp_ipa_rx(1, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
9366
9367 /* ACKnowledge channel activation and expect (RR) Handover Command */
9368 f_ipa_tx(1, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
9369 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
9370
9371 /* Make sure that L3 Information IE is present */
9372 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
9373 setverdict(fail, "RSL L3 Information IE is absent");
9374 return;
9375 }
9376
9377 /* Decode the L3 message and make sure it is (RR) Handover Command */
9378 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
9379 if (not match(l3_msg.header, t_RrL3Header(HANDOVER_COMMAND))) {
9380 setverdict(fail, "Failed to match Handover Command: ", l3_msg);
9381 return;
9382 }
9383
9384 /* Make sure that we've got SDCCH/8 on TS1 (expected to be hopping) */
9385 var ChannelDescription chan_desc := l3_msg.payload.ho_cmd.chan_desc;
9386 if (not match(chan_desc.chan_nr, t_RslChanNr_SDCCH8(1, ?))) {
9387 setverdict(fail, "Unexpected channel number: ", chan_desc.chan_nr);
9388 return;
9389 }
9390
9391 /* Make sure that hopping parameters (HSN/MAIO) match */
9392 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9393
9394 /* Make sure that Cell Channel Description IE is present */
9395 if (not ispresent(l3_msg.payload.ho_cmd.cell_chan_desc)) {
9396 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
9397 return;
9398 }
9399
9400 /* Make sure that the Mobile Allocation (after time) IE is present and matches */
9401 var boolean ma_present := ispresent(l3_msg.payload.ho_cmd.mobile_allocation);
9402 if (ma_present) {
9403 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9404 l3_msg.payload.ho_cmd.mobile_allocation.v);
9405 } else {
9406 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9407 return;
9408 }
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +01009409
9410 f_perform_clear_test_ct(dt);
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009411}
9412testcase TC_fh_params_handover_cmd() runs on test_CT {
9413 var FHParamsTrx fhp := f_TC_fh_params_gen();
9414
9415 f_init_vty();
9416
9417 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8 on BTS1/TRX0 */
9418 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
9419
9420 f_vty_transceive(BSCVTY, "timeslot 0");
9421 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
9422 f_vty_transceive(BSCVTY, "exit"); /* go back */
9423
9424 f_vty_transceive(BSCVTY, "timeslot 1");
9425 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8");
9426 f_vty_transceive(BSCVTY, "end"); /* we're done */
9427
9428 f_TC_fh_params_set(fhp, 1); /* Enable frequency hopping on BTS1 */
9429 f_vty_transceive(BSCVTY, "drop bts connection 1 oml");
9430
9431 f_init(2);
9432
9433 f_TC_fh_params_handover_cmd(fhp);
9434
9435 /* Disable frequency hopping on BTS1 */
9436 f_TC_fh_params_unset(fhp, 1);
9437
9438 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
9439 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
9440
9441 f_vty_transceive(BSCVTY, "timeslot 0");
9442 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
9443 f_vty_transceive(BSCVTY, "exit"); /* go back */
9444
9445 f_vty_transceive(BSCVTY, "timeslot 1");
9446 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
9447 f_vty_transceive(BSCVTY, "end"); /* we're done */
9448
9449 f_shutdown_helper();
9450}
9451
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009452/* Verify the hopping parameters in System Information Type 4 */
9453testcase TC_fh_params_si4_cbch() runs on test_CT {
9454 var FHParamsTrx fhp := f_TC_fh_params_gen(tr_tn := 1);
9455 var ASP_RSL_Unitdata rx_rsl_ud;
9456 timer T := 5.0;
9457
9458 f_init_vty();
9459
9460 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8+CBCH */
9461 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
9462
9463 f_vty_transceive(BSCVTY, "timeslot 0");
9464 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
9465 f_vty_transceive(BSCVTY, "exit"); /* go back */
9466
9467 f_vty_transceive(BSCVTY, "timeslot 1");
9468 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8+cbch");
9469 f_vty_transceive(BSCVTY, "end"); /* we're done */
9470
9471 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9472 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9473
9474 f_init(1);
9475
9476 T.start;
9477 alt {
9478 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO(RSL_SYSTEM_INFO_4))) -> value rx_rsl_ud {
9479 var RSL_IE_Body ie := rx_rsl_ud.rsl.ies[2].body; /* FULL BCCH Information IE */
9480 var SystemInformation si := dec_SystemInformation(ie.other.payload);
9481
9482 /* Make sure that what we decoded is System Information Type 4 */
9483 if (si.header.message_type != SYSTEM_INFORMATION_TYPE_4) {
9484 setverdict(fail, "RSL FULL BCCH Information IE contains: ", si);
9485 repeat;
9486 }
9487
9488 /* Make sure that CBCH Channel Description IE is present */
9489 if (not ispresent(si.payload.si4.cbch_chan_desc)) {
9490 setverdict(fail, "CBCH Channel Description IE is absent");
9491 break;
9492 }
9493
9494 /* Finally, check the hopping parameters (HSN, MAIO) */
9495 var ChannelDescription chan_desc := si.payload.si4.cbch_chan_desc.v;
9496 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9497
9498 /* 3GPP TS 44.018, section 9.1.36.2 "CBCH Mobile Allocation":
9499 * The CBCH Mobile Allocation IE *shall* be present if FH is enabled. */
9500 if (chan_desc.h and not ispresent(si.payload.si4.cbch_mobile_alloc)) {
9501 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9502 break;
9503 } else if (chan_desc.h and ispresent(si.payload.si4.cbch_mobile_alloc)) {
9504 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9505 si.payload.si4.cbch_mobile_alloc.v);
9506 }
9507 }
9508 [] IPA_RSL[0].receive { repeat; }
9509 [] T.timeout {
9510 setverdict(fail, "Timeout waiting for RSL BCCH INFOrmation (SI4)");
9511 }
9512 }
9513
9514 /* Disable frequency hopping */
9515 f_TC_fh_params_unset(fhp);
9516
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07009517 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009518 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
9519
9520 f_vty_transceive(BSCVTY, "timeslot 0");
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07009521 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009522 f_vty_transceive(BSCVTY, "exit"); /* go back */
9523
9524 f_vty_transceive(BSCVTY, "timeslot 1");
9525 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
9526 f_vty_transceive(BSCVTY, "end"); /* we're done */
9527
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009528 f_shutdown_helper();
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009529}
9530
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009531template (value) PDU_BSSAP_LE ts_BSSMAP_LE_BSSLAP(template (value) BSSLAP_PDU bsslap)
9532 := ts_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, data := enc_BSSLAP_PDU(valueof(bsslap)));
9533
9534private function f_match_bsslap(PDU_BSSAP_LE got_bsslap_msg,
9535 template (present) BSSLAP_PDU expect_bsslap)
9536{
9537 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(got_bsslap_msg.pdu.bssmap.co_info.bsslap_apdu.data);
9538 if (not match(bsslap, expect_bsslap)) {
9539 log("EXPECTING BSSLAP: ", expect_bsslap);
9540 log("GOT BSSLAP: ", bsslap);
9541 setverdict(fail, "BSSLAP is not as expected");
9542 mtc.stop;
9543 }
9544 setverdict(pass);
9545}
9546
9547/* GAD: this is an Ellipsoid point with uncertainty circle, encoded as in 3GPP TS 23.032 §7.3.2. */
9548const octetstring gad_ell_point_unc_circle := '10b0646d0d5f6627'O;
9549
9550private function f_expect_bsslap(template (present) BSSLAP_PDU expect_rx_bsslap) runs on MSC_ConnHdlr {
9551 var PDU_BSSAP_LE rx_bsslap;
9552 BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap);
9553 f_match_bsslap(rx_bsslap, expect_rx_bsslap);
9554}
9555
9556/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9557 * Request on Lb interface. Either with or without the SMLC doing a BSSLAP TA Request. */
9558private function f_lcs_loc_req_for_active_ms(boolean do_ta_request := false) runs on MSC_ConnHdlr {
9559 f_sleep(1.0);
9560
9561 f_establish_fully(omit, omit);
9562 f_bssap_le_register_imsi(g_pars.imsi, omit);
9563
9564 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9565 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9566
9567 var PDU_BSSAP_LE plr;
9568 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9569
9570 if (not do_ta_request) {
9571 /* verify TA Layer 3 in APDU. First the APDU type (BSSLAP), then the BSSLAP data contents. */
9572 var template BSSMAP_LE_IE_APDU expect_apdu := tr_BSSMAP_LE_APDU(BSSMAP_LE_PROT_BSSLAP, ?);
9573 if (not match(plr.pdu.bssmap.perf_loc_req.bsslap_apdu, expect_apdu)) {
9574 log("EXPECTING BSSMAP-LE APDU IE ", expect_apdu);
9575 log("GOT BSSMAP-LE APDU IE ", plr.pdu.bssmap.perf_loc_req.bsslap_apdu);
9576 setverdict(fail, "BSSMAP-LE APDU IE is not as expected");
9577 mtc.stop;
9578 }
9579 var template BSSLAP_PDU expect_ta_layer3 := tr_BSSLAP_TA_Layer3(tr_BSSLAP_IE_TA(0));
9580 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(plr.pdu.bssmap.perf_loc_req.bsslap_apdu.data);
9581 if (not match(bsslap, expect_ta_layer3)) {
9582 log("EXPECTING BSSLAP TA Layer 3: ", expect_ta_layer3);
9583 log("GOT BSSLAP: ", bsslap);
9584 setverdict(fail, "BSSLAP is not as expected");
9585 mtc.stop;
9586 }
9587 /* OsmoBSC directly sent the TA as BSSLAP APDU in the BSSMAP-LE Perform Location Request to the SMLC. The SMLC
9588 * has no need to request the TA from the BSC and directly responds. */
9589 } else {
9590 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9591 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9592 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9593 }
9594
9595 /* SMLC got the TA from the BSC, now responds with geo information data. */
9596 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9597 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9598 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9599
9600 /* The LCS was using an active A-interface conn. It should still remain active after this. */
9601 f_mo_l3_transceive();
9602
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009603 f_perform_clear();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009604
9605 f_sleep(2.0);
9606 setverdict(pass);
9607}
9608
9609/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9610 * Request on Lb interface. Without the SMLC doing a BSSLAP TA Request. */
9611private function f_tc_lcs_loc_req_for_active_ms(charstring id) runs on MSC_ConnHdlr {
9612 f_lcs_loc_req_for_active_ms(false);
9613}
9614testcase TC_lcs_loc_req_for_active_ms() runs on test_CT {
9615 var MSC_ConnHdlr vc_conn;
9616 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9617
9618 f_init(1, true);
9619 f_sleep(1.0);
9620 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms), pars);
9621 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009622 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009623}
9624
9625/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9626 * Request on Lb interface. With the SMLC doing a BSSLAP TA Request. */
9627private function f_tc_lcs_loc_req_for_active_ms_ta_req(charstring id) runs on MSC_ConnHdlr {
9628 f_lcs_loc_req_for_active_ms(true);
9629}
9630testcase TC_lcs_loc_req_for_active_ms_ta_req() 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 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_ta_req), pars);
9637 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009638 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009639}
9640
9641/* Clear the A-interface conn only, without doing anything on Abis. Useful for LCS, for cases where there is only an A
9642 * conn without an active lchan. */
9643private function f_clear_A_conn() runs on MSC_ConnHdlr
9644{
9645 var BssmapCause cause := 0;
9646 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
9647 BSSAP.receive(tr_BSSMAP_ClearComplete);
9648 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
9649
9650 timer no_more_bssap := 5.0;
9651 no_more_bssap.start;
9652 alt {
9653 [] no_more_bssap.timeout { break; }
9654 [] BSSAP.receive(tr_BSSAP_BSSMAP) {
9655 setverdict(fail, "Expected no more BSSAP after Clear Complete");
9656 mtc.stop;
9657 }
9658 }
9659 setverdict(pass);
9660}
9661
9662/* Verify that the A-interface connection is still working, and then clear it, without doing anything on Abis. Useful
9663 * for LCS, for cases where there is only an A conn without an active lchan. */
9664private function f_verify_active_A_conn_and_clear() runs on MSC_ConnHdlr
9665{
9666 f_logp(BSCVTY, "f_verify_active_A_conn_and_clear: test A link, then clear");
9667
9668 /* When an lchan is active, we can send some L3 data from the BTS side and verify that it shows up on the other
9669 * side towards the MSC. When there is no lchan, this is not possible. To probe whether the A-interface
9670 * connection is still up, we need something that echos back on the A-interface. Another LCS request! */
9671 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9672 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9673 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?));
9674
9675 /* Right, the Perform Location Request showed up on Lb, now we can clear the A conn. */
9676 f_clear_A_conn();
9677 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
9678 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9679}
9680
9681/* With *no* active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9682 * Request on Lb interface. BSC will Page for the subscriber as soon as we (virtual SMLC) request the TA via BSSLAP.
9683 */
9684private function f_tc_lcs_loc_req_for_idle_ms(charstring id) runs on MSC_ConnHdlr {
9685 f_sleep(1.0);
9686
9687 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9688 f_bssap_le_register_imsi(g_pars.imsi, omit);
9689
9690 /* Register to receive the Paging Command */
9691 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9692 g_chan_nr := new_chan_nr;
9693 f_rslem_register(0, g_chan_nr);
9694
9695 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9696 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9697 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9698 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9699
9700 var PDU_BSSAP_LE plr;
9701 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9702
9703 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9704 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9705
9706 /* OsmoBSC needs to Page */
9707 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi)));
9708 f_logp(BSCVTY, "got Paging Command");
9709
9710 /* MS requests channel. Since the Paging was for LCS, the Paging Response does not trigger a Complete Layer 3 to
9711 * the MSC, and releases the lchan directly. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009712 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);
9713 f_expect_lchan_rel(RSL, RSL_PROC);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009714
9715 /* From the Paging Response, the TA is now known to the BSC, and it responds to the SMLC. */
9716
9717 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9718
9719 /* SMLC got the TA from the BSC, now responds with geo information data. */
9720 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9721 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9722
9723 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9724
9725 /* The lchan is gone, the A-interface conn was created for the LCS only.
9726 * Still it is clearly the MSC's job to decide whether to tear down the conn or not. */
9727 f_verify_active_A_conn_and_clear();
9728
9729 f_sleep(2.0);
9730 setverdict(pass);
9731}
9732testcase TC_lcs_loc_req_for_idle_ms() runs on test_CT {
9733 var MSC_ConnHdlr vc_conn;
9734 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9735
9736 f_init(1, true);
9737 f_sleep(1.0);
9738
9739 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9740 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9741
9742 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms), pars);
9743 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009744 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009745}
9746
9747/* With no active lchan, start BSSMAP Perform Location Request on A interface, but omit IMSI; expect failure response.
9748 */
9749private function f_tc_lcs_loc_req_no_subscriber(charstring id) runs on MSC_ConnHdlr {
9750 f_sleep(1.0);
9751
9752 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9753 f_bssap_le_register_imsi(g_pars.imsi, omit);
9754
9755 /* provoke an abort by omitting both IMSI and IMEI */
9756 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9757 valueof(ts_BSSMAP_Perform_Location_Request(omit,
9758 ts_CellId_CGI('262'H, '42'H, 23, 42)))));
9759 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9760
9761 /* BSC tells MSC about failure */
9762 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9763 locationEstimate := omit, positioningData := omit,
9764 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_DATA_MISSING_IN_REQ)));
9765
9766 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9767 f_verify_active_A_conn_and_clear();
9768
9769 f_sleep(2.0);
9770 setverdict(pass);
9771}
9772testcase TC_lcs_loc_req_no_subscriber() runs on test_CT {
9773 var MSC_ConnHdlr vc_conn;
9774 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9775
9776 f_init(1, true);
9777 f_sleep(1.0);
9778
9779 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9780 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9781
9782 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_no_subscriber), pars);
9783 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009784 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009785}
9786
9787/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9788 * BSSMAP-LE Perform Location Response (before or after sending a BSSLAP TA Request) */
9789private function f_lcs_loc_req_for_active_ms_le_timeout(boolean do_ta) runs on MSC_ConnHdlr {
9790 f_sleep(1.0);
9791
9792 f_establish_fully(omit, omit);
9793 f_bssap_le_register_imsi(g_pars.imsi, omit);
9794
9795 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9796 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9797
9798 var PDU_BSSAP_LE plr;
9799 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9800
9801 if (do_ta) {
9802 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9803 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9804 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9805 }
9806
9807 /* SMLC fails to respond, BSC runs into timeout */
9808 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_SYSTEM_FAILURE));
9809 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9810
9811 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9812 locationEstimate := omit, positioningData := omit,
9813 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_SYSTEM_FAILURE)));
9814
9815 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9816 f_verify_active_A_conn_and_clear();
9817
9818 f_sleep(2.0);
9819 setverdict(pass);
9820}
9821
9822/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9823 * BSSMAP-LE Perform Location Response, without sending a BSSLAP TA Request. */
9824private function f_tc_lcs_loc_req_for_active_ms_le_timeout(charstring id) runs on MSC_ConnHdlr {
9825 f_lcs_loc_req_for_active_ms_le_timeout(false);
9826}
9827
9828testcase TC_lcs_loc_req_for_active_ms_le_timeout() runs on test_CT {
9829 var MSC_ConnHdlr vc_conn;
9830 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9831
9832 f_init(1, true);
9833 f_sleep(1.0);
9834 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout), pars);
9835 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009836 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009837}
9838
9839/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9840 * BSSMAP-LE Perform Location Response, after sending a BSSLAP TA Request. */
9841private function f_tc_lcs_loc_req_for_active_ms_le_timeout2(charstring id) runs on MSC_ConnHdlr {
9842 f_lcs_loc_req_for_active_ms_le_timeout(true);
9843}
9844
9845testcase TC_lcs_loc_req_for_active_ms_le_timeout2() runs on test_CT {
9846 var MSC_ConnHdlr vc_conn;
9847 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9848
9849 f_init(1, true);
9850 f_sleep(1.0);
9851 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout2), pars);
9852 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009853 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009854}
9855
9856/* With *no* active lchan, start a Perform Location Request, expecting that the MS will be Paged. */
9857private function f_tc_lcs_loc_req_for_idle_ms_no_pag_resp(charstring id) runs on MSC_ConnHdlr {
9858 f_sleep(1.0);
9859
9860 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9861 f_bssap_le_register_imsi(g_pars.imsi, omit);
9862
9863 /* Register to receive the Paging Command */
9864 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9865 g_chan_nr := new_chan_nr;
9866 f_rslem_register(0, g_chan_nr);
9867
9868 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9869 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9870 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9871 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9872
9873 var PDU_BSSAP_LE plr;
9874 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9875
9876 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9877 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9878
9879 /* OsmoBSC needs to Page */
9880 var PDU_BSSAP_LE rx_bsslap;
9881 alt {
9882 [] RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi))) {
9883 f_logp(BSCVTY, "got Paging Command");
9884 repeat;
9885 }
9886 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
9887 /* MS does not respond to Paging, TA Req runs into timeout. */
9888 f_match_bsslap(rx_bsslap, tr_BSSLAP_Abort(?));
9889 }
9890 }
9891
9892 /* SMLC responds with failure */
9893 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(omit, BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
9894 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9895
9896 /* BSC tells MSC about failure */
9897 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9898 locationEstimate := omit, positioningData := omit,
9899 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_REQUEST_ABORTED)));
9900
9901 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9902 f_verify_active_A_conn_and_clear();
9903
9904 f_sleep(2.0);
9905 setverdict(pass);
9906}
9907testcase TC_lcs_loc_req_for_idle_ms_no_pag_resp() runs on test_CT {
9908 var MSC_ConnHdlr vc_conn;
9909 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9910
9911 f_init(1, true);
9912 f_sleep(1.0);
9913
9914 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9915 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9916
9917 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms_no_pag_resp), pars);
9918 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009919 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009920}
9921
9922/* During an ongoing Location Request, the MS sends a CM Service Request. Expect the same A-conn to be re-used / taken
9923 * over. */
9924private function f_tc_cm_service_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
9925 f_sleep(1.0);
9926
9927 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9928 f_bssap_le_register_imsi(g_pars.imsi, omit);
9929
9930 /* Register to receive the Paging Command */
9931 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9932 g_chan_nr := new_chan_nr;
9933 f_rslem_register(0, g_chan_nr);
9934
9935 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9936 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9937 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9938 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9939
9940 var PDU_BSSAP_LE plr;
9941 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9942
9943 /* As the A-interface conn was established for LCS, the MS coincidentally decides to issue a CM Service Request
9944 * and establish Layer 3. It should use the existing A-interface conn. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009945 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 +02009946 do_clear := false, expect_bssmap_l3 := true);
9947
9948 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9949 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9950
9951 /* OsmoBSC already has an lchan, no need to Page, just returns the TA */
9952 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9953
9954 /* SMLC got the TA from the BSC, now responds with geo information data. */
9955 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9956 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9957 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9958
9959 /* The lchan should still exist, it was from a CM Service Request. */
9960 f_mo_l3_transceive();
9961
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009962 f_perform_clear();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009963
9964 f_sleep(2.0);
9965 setverdict(pass);
9966}
9967testcase TC_cm_service_during_lcs_loc_req() runs on test_CT {
9968 var MSC_ConnHdlr vc_conn;
9969 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9970
9971 f_init(1, true);
9972 f_sleep(1.0);
9973
9974 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9975 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9976
9977 vc_conn := f_start_handler(refers(f_tc_cm_service_during_lcs_loc_req), pars);
9978 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009979 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009980}
9981
9982/* During an ongoing Perform Location Request, do a Handover, an expect a BSSLAP Reset message from the BSC to indicate
9983 * the new lchan after handover. */
9984private function f_tc_ho_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
9985 f_sleep(1.0);
9986
9987 f_establish_fully(omit, omit);
9988 f_bssap_le_register_imsi(g_pars.imsi, omit);
9989
9990 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9991 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9992
9993 var PDU_BSSAP_LE plr;
9994 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9995
9996 /* SMLC ponders the Location Request, in the meantime the BSC decides to handover */
9997 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
9998
9999 var HandoverState hs := {
10000 rr_ho_cmpl_seen := false,
10001 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +020010002 old_chan_nr := -,
10003 expect_target_tsc := BTS_TSC[1]
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020010004 };
10005 /* issue hand-over command on VTY */
10006 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
10007 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
10008 f_rslem_suspend(RSL1_PROC);
10009
10010 /* From the MGW perspective, a handover is is characterized by
10011 * performing one MDCX operation with the MGW. So we expect to see
10012 * one more MDCX during handover. */
10013 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
10014
10015 alt {
10016 [] as_handover(hs);
10017 }
10018
10019 var PDU_BSSAP_LE rx_bsslap;
10020
10021 interleave {
10022 /* Expect the BSC to inform the MSC about the handover */
10023 [] BSSAP.receive(tr_BSSMAP_HandoverPerformed);
10024
10025 /* Expect the BSC to inform the SMLC about the handover */
10026 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
10027 f_match_bsslap(rx_bsslap, tr_BSSLAP_Reset(BSSLAP_CAUSE_INTRA_BSS_HO));
10028 }
10029 }
10030
10031 /* SMLC now responds with geo information data. */
10032 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
10033 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
10034 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
10035
10036 /* lchan still active */
10037 f_mo_l3_transceive(RSL1);
10038
10039 /* MSC decides it is done now. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +020010040 f_perform_clear(RSL1, RSL1_PROC);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020010041
10042 f_sleep(2.0);
10043 setverdict(pass);
10044}
10045testcase TC_ho_during_lcs_loc_req() runs on test_CT {
10046 var MSC_ConnHdlr vc_conn;
10047 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10048
10049 f_init(2, true);
10050 f_sleep(1.0);
10051 vc_conn := f_start_handler(refers(f_tc_ho_during_lcs_loc_req), pars);
10052 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +010010053 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020010054}
10055
Neels Hofmeyrbf037052020-10-28 22:52:02 +000010056/* Attempt Complete Layer 3 without any MSC available (OS#4832) */
10057private function f_tc_no_msc(charstring id) runs on MSC_ConnHdlr {
10058 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
10059
10060 /* Also disable attach for the single connected MSC */
10061 f_vty_msc_allow_attach(BSCVTY, { false });
10062
10063 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) ));
10064 f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
10065
10066 /* No MSC is found, expecting a proper release on RSL */
10067 interleave {
10068 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
10069 f_logp(BSCVTY, "Got RSL RR Release");
10070 }
10071 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
10072 f_logp(BSCVTY, "Got RSL Deact SACCH");
10073 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +020010074 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyrbf037052020-10-28 22:52:02 +000010075 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
10076 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +020010077 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyrbf037052020-10-28 22:52:02 +000010078 }
10079 }
10080 setverdict(pass);
10081}
10082testcase TC_no_msc() runs on test_CT {
10083
10084 f_init(1, true);
10085 f_sleep(1.0);
10086 var MSC_ConnHdlr vc_conn;
10087 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10088
10089 f_ctrs_bsc_init(counternames_bsc_mscpool);
10090
10091 vc_conn := f_start_handler(refers(f_tc_no_msc), pars);
10092 vc_conn.done;
10093
10094 f_ctrs_bsc_add("mscpool:subscr:no_msc");
10095 f_ctrs_bsc_verify();
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +010010096 f_shutdown_helper();
Neels Hofmeyrbf037052020-10-28 22:52:02 +000010097}
10098
Harald Welte0ea2d5e2018-04-07 21:40:29 +020010099/* Dyn PDCH todo:
10100 * activate OSMO as TCH/F
10101 * activate OSMO as TCH/H
10102 * does the BSC-located PCU socket get the updated INFO?
10103 * what if no PCU is connected at the time?
10104 * is the info correct on delayed PCU (re)connect?
10105 */
Harald Welte94e0c342018-04-07 11:33:23 +020010106
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000010107private function f_TC_refuse_mode_modif_to_vamos(charstring id) runs on MSC_ConnHdlr {
10108 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
10109 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
10110
10111 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
10112 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
10113 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
10114 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
10115 g_pars.ass_codec_list.codecElements[0];
10116 if (isvalue(g_pars.expect_mr_s0_s7)) {
10117 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
10118 g_pars.expect_mr_s0_s7;
10119 }
10120 }
10121 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
10122 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
10123 log("expecting ASS COMPL like this: ", exp_compl);
10124
10125 f_establish_fully(ass_cmd, exp_compl);
10126
Neels Hofmeyr8746b0d2021-06-01 17:25:39 +020010127 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 +000010128
10129 var RSL_Message rsl;
10130
10131 timer T := 5.0;
10132 T.start;
10133 alt {
10134 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
10135 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
10136 log("Rx L3 from net: ", l3);
10137 if (ischosen(l3.msgs.rrm.channelModeModify)) {
10138 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
10139 mtc.stop;
10140 }
10141 }
10142 [] RSL.receive(tr_RSL_MODE_MODIFY_REQ(g_chan_nr, ?)) -> value rsl {
10143 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
10144 mtc.stop;
10145 }
10146 [] T.timeout {
10147 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related Mode Modify should happen. */
10148 setverdict(pass);
10149 }
10150 }
10151 T.stop;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010152
10153 f_perform_clear();
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000010154}
10155
10156/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel Mode Modify to VAMOS mode is refused by
10157 * osmo-bsc. */
10158testcase TC_refuse_mode_modif_to_vamos() runs on test_CT {
10159 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10160 var MSC_ConnHdlr vc_conn;
10161
10162 f_init(1, true);
10163 f_sleep(1.0);
10164
10165 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10166 vc_conn := f_start_handler(refers(f_TC_refuse_mode_modif_to_vamos), pars);
10167 vc_conn.done;
10168 f_shutdown_helper();
10169}
10170
10171/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel activation to VAMOS mode is refused by osmo-bsc.
10172 */
10173testcase TC_refuse_chan_act_to_vamos() runs on test_CT {
10174 f_init_vty();
10175
10176 f_init(1, false);
10177 f_sleep(1.0);
10178
10179 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 activate-vamos fr");
10180
10181 var ASP_RSL_Unitdata rx_rsl_ud;
10182 timer T := 5.0;
10183
10184 T.start;
10185 alt {
10186 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(?, IPAC_PROTO_RSL_TRX0)) -> value rx_rsl_ud {
10187 if (rx_rsl_ud.rsl.msg_type == RSL_MT_CHAN_ACTIV) {
10188 T.stop;
10189 setverdict(fail, "CHANnel ACTivate in VAMOS mode succeeded even though BTS does not support VAMOS");
10190 mtc.stop;
10191 }
10192 repeat;
10193 }
10194 [] T.timeout {
10195 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related CHANnel ACTivate should happen. */
10196 setverdict(pass);
10197 }
10198 }
10199}
10200
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010201private function f_TC_reassignment_codec(charstring id) runs on MSC_ConnHdlr {
10202 /* First fully set up a speech lchan */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010203 f_assignment_codec(id, do_perform_clear := false);
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010204
10205 /* Trigger re-assignment to another lchan */
10206 var AssignmentState assignment_st := valueof(ts_AssignmentStateInit);
10207
10208 /* Re-Assignment should tell the MGW endpoint the new lchan's RTP address and port, so expecting to see exactly
10209 * one MDCX on MGCP. */
10210 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].mdcx_seen_exp + 1;
10211
10212 /* The new lchan will see all-new IPAC_CRCX and IPAC_MDCX messages telling the BTS the same RTP address and port
10213 * as the old lchan used. */
10214 g_media.bts.ipa_crcx_seen := false;
10215 g_media.bts.ipa_mdcx_seen := false;
10216
10217 /* Send different BTS side RTP port number for the new lchan */
10218 g_media.bts.bts.port_nr := 4223;
10219
10220 f_rslem_register(0, valueof(ts_RslChanNr_Bm(2))); /* <-- FIXME: can we somehow infer the timeslot that will be used? */
10221
10222 /* Trigger re-assignment. */
10223 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot " & int2str(g_chan_nr.tn) & " sub-slot 0 assignment");
10224
10225 timer T := 5.0;
10226 T.start;
10227 alt {
10228 [] as_assignment(assignment_st);
10229 [] as_Media();
10230 [] T.timeout {
10231 break;
10232 }
10233 }
10234
10235 if (not assignment_st.assignment_done) {
10236 setverdict(fail, "Assignment did not complete");
10237 mtc.stop;
10238 }
10239
10240 f_check_mgcp_expectations()
10241 setverdict(pass);
10242
10243 f_sleep(2.0);
10244 log("show lchan summary: ", f_vty_transceive_ret(BSCVTY, "show lchan summary"));
10245
10246 /* Instruct BSC to clear channel */
10247 var BssmapCause cause := 0;
10248 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
10249 interleave {
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010250 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {}
10251 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +020010252 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010253 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +020010254 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010255 }
10256 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
10257 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
10258 }
10259 }
Neels Hofmeyr40a45d12021-09-23 22:57:12 +020010260 f_expect_dlcx_conns();
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010261
10262 f_sleep(0.5);
10263}
10264
10265testcase TC_reassignment_fr() runs on test_CT {
10266 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10267 var MSC_ConnHdlr vc_conn;
10268
10269 f_init(1, true);
10270 f_sleep(1.0);
10271
Neels Hofmeyrac432fa2021-11-02 16:45:56 +010010272 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000010273
10274 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10275 vc_conn := f_start_handler(refers(f_TC_reassignment_codec), pars);
10276 vc_conn.done;
10277
10278 /* from f_establish_fully() */
10279 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
10280 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
10281 /* from re-assignment */
10282 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
10283 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
10284 f_ctrs_bsc_and_bts_verify();
10285 f_shutdown_helper();
10286}
10287
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010288const charstring REEST_LOST_CONNECTION := "REEST_LOST_CONNECTION";
10289const charstring REEST_CLEAR := "REEST_CLEAR";
10290const charstring REEST_CLEAR_DONE := "REEST_CLEAR_DONE";
10291
10292/* CM Re-Establishment, 3GPP TS 24.008 4.5.1.6.
10293 * The MS <-> BTS loses radio connection, MS shows up on second BTS and asks for CM Re-Establishment.
10294 * BSC should establish a separate A conn for the same MS, the original A conn is then cleared by
10295 * the MSC as the CM Re-Establishment is handled.
10296 *
10297 * MS bts0 bts1 bsc msc test-component
10298 * |<----->|<----------------->|<-0-->| _1 Establish channel on bts 0
10299 * | | _1 wait a bit, to settle down
10300 * |<-x x--| | _1 "lose connection"
10301 * | | REEST_LOST_CONNECTION
10302 * |----------------->|------->|--1-->| _2 new A-conn: Chan Rqd, Imm Ass, Compl L3 with CM Re-Establishment Req
10303 * | | REEST_CLEAR
10304 * | |<-0---| _1 Clear Command on first A-conn
10305 * | |--0-->| _1 Clear Complete
10306 * | |<----------------->| | _1 Release first channel
10307 * | | REEST_CLEAR_DONE
10308 * |<-----------------|<-------|<-1---| _2 Chan Activ, Assignment Command
10309 * |<-----------------|<-------|<-1---| _2 Clear Command, Release
10310 *
10311 */
10312private function f_tc_cm_reestablishment_1(charstring id) runs on MSC_ConnHdlr {
10313 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
10314 var PDU_BSSAP ass_cmd := f_gen_ass_req();
10315
10316 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10317 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10318
10319 f_establish_fully(ass_cmd, exp_compl);
10320
10321 /* The original channel loses connection, MS attemts CM Re-Establishment on another cell, see
10322 * f_tc_cm_reestablishment_2(). This established channel stays active until MSC sends a Clear Command. The time
10323 * when exactly that happens is determined by f_tc_cm_reestablishment_2(). */
10324 f_sleep(2.0);
10325 COORD.send(REEST_LOST_CONNECTION);
10326
10327 alt {
10328 [] COORD.receive(REEST_CLEAR);
10329 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
10330 setverdict(fail, "Unexpected channel release");
10331 mtc.stop;
10332 }
10333 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
10334 setverdict(fail, "Unexpected channel release");
10335 mtc.stop;
10336 }
10337 }
10338 f_perform_clear()
Neels Hofmeyr969abd02021-09-23 22:24:08 +020010339 f_create_mgcp_delete_ep(g_media.mgcp_ep);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010340 COORD.send(REEST_CLEAR_DONE);
10341}
10342
10343private function f_tc_cm_reestablishment_2(charstring id) runs on MSC_ConnHdlr {
10344 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
10345
10346 /* The MS lost the connection on the first channel, now establishes another one */
10347 COORD.receive(REEST_LOST_CONNECTION);
10348
10349 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
10350 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_REESTABL_REQ(mi));
10351 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
10352
10353 f_create_bssmap_exp(l3_enc);
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010354 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 +020010355 BSSAP.receive(tr_BSSMAP_ComplL3(l3_enc));
10356
10357 /* MSC got the CM Re-Establishment request and first off clears the previous conn. */
10358 COORD.send(REEST_CLEAR);
10359 COORD.receive(REEST_CLEAR_DONE);
10360
10361 f_sleep(2.0);
10362
10363 /* Answer the CM Re-Establishment with an Assignment Command. */
10364 var template PDU_BSSAP expect_assignment_compl := f_gen_exp_compl();
10365 var PDU_BSSAP ass_cmd := f_gen_ass_req();
10366 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10367 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
10368
10369 var AssignmentState st := valueof(ts_AssignmentStateInit);
10370 st.voice_call := true;
10371 st.is_assignment := true;
10372
10373 var ExpectCriteria mgcpcrit := {
10374 connid := omit,
10375 endpoint := omit,
10376 transid := omit
10377 };
10378 f_create_mgcp_expect(mgcpcrit);
10379
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010380 f_rslem_dchan_queue_enable(RSL1_PROC);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010381
10382 BSSAP.send(ass_cmd);
10383
10384 var PDU_BSSAP bssap;
10385
10386 alt {
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010387 [] as_assignment(st, rsl_pt := RSL1, rsl_proc_pt := RSL1_PROC);
10388 [] as_Media_ipacc(RSL1, RSL2);
10389 [] as_Media_mgw();
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010390 [st.assignment_done] BSSAP.receive(expect_assignment_compl) {
10391 break;
10392 }
10393 }
10394
10395 f_sleep(3.0);
10396
10397 f_logp(BSCVTY, "f_tc_cm_reestablishment_2 clearing");
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010398 f_perform_clear(RSL1, RSL1_PROC);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010399}
10400
10401testcase TC_cm_reestablishment() runs on test_CT {
10402 var TestHdlrParams pars1 := f_gen_test_hdlr_pars();
10403 var MSC_ConnHdlr vc_conn1;
10404
10405 var TestHdlrParams pars2 := f_gen_test_hdlr_pars();
10406 var MSC_ConnHdlr vc_conn2;
10407 pars2.imsi := pars1.imsi;
10408 pars2.media_nr := 2;
Neels Hofmeyrbf720202021-10-02 12:58:24 +020010409 pars2.expect_tsc := BTS_TSC[1];
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010410
10411 f_init(2, true, guard_timeout := 40.0);
10412 f_sleep(1.0);
10413
10414 vc_conn1 := f_start_handler_create(pars1);
10415 vc_conn2 := f_start_handler_create(pars2);
10416 connect(vc_conn1:COORD, vc_conn2:COORD);
10417 f_start_handler_run(vc_conn1, refers(f_tc_cm_reestablishment_1), pars1);
10418 f_start_handler_run(vc_conn2, refers(f_tc_cm_reestablishment_2), pars2);
10419 vc_conn1.done;
10420 vc_conn2.done;
10421
10422 f_shutdown_helper();
10423}
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000010424
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010425function f_exp_ipa_rx_nonfatal(integer bts_nr, template (present) RSL_Message t_rx, float t_secs := 2.0,
10426 IpaStreamId sid := IPAC_PROTO_RSL_TRX0, boolean ignore_other_rx := true)
10427runs on test_CT return template (omit) RSL_Message {
10428 var ASP_RSL_Unitdata rx_rsl_ud;
10429 timer T := t_secs;
10430
10431 T.start;
10432 alt {
10433 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
10434 T.stop;
10435 }
10436 [ignore_other_rx] IPA_RSL[bts_nr].receive { repeat; }
10437 [not ignore_other_rx] IPA_RSL[bts_nr].receive {
10438 log("f_exp_ipa_rx_nonfatal(): Got different message than ", t_rx);
10439 T.stop;
10440 return omit;
10441 }
10442 [] T.timeout {
10443 return omit;
10444 }
10445 }
10446 return rx_rsl_ud.rsl;
10447}
10448
10449private function f_vty_set_imm_ass(TELNETasp_PT pt, BtsNr bts_nr := 0, charstring imm_ass_setting := "post-chan-ack") {
10450 f_vty_enter_cfg_bts(pt, bts_nr);
10451 f_vty_transceive(pt, "immediate-assignment " & imm_ass_setting);
10452 f_vty_transceive(pt, "exit");
10453 f_vty_transceive(pt, "exit");
10454 f_vty_transceive(pt, "exit");
10455}
10456
10457private function f_verify_imm_ass(RSL_Message imm_ass, template uint8_t ra := ?, template GsmFrameNumber fn := ?,
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010458 template RslChannelNr chan_nr := ?,
10459 template (present) uint12_t arfcn := ?,
10460 template (present) uint3_t tsc := ?)
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010461{
10462 var RSL_IE_Body full_imm_ass_info;
10463 if (not f_rsl_find_ie(imm_ass, RSL_IE_FULL_IMM_ASS_INFO, full_imm_ass_info)) {
10464 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
10465 mtc.stop;
10466 }
10467
10468 var GsmRrMessage rr_imm_ass := dec_GsmRrMessage(full_imm_ass_info.full_imm_ass_info.payload);
10469 var template GsmRrMessage expect_imm_ass := tr_IMM_ASS(ra := ra,
10470 fn := fn,
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010471 ch_desc := tr_ChanDescH0(chan_nr, arfcn, tsc),
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010472 page_mode := ?);
10473 if (not match(rr_imm_ass, expect_imm_ass)) {
10474 log("Error: expected ", expect_imm_ass, " got ", rr_imm_ass);
10475 setverdict(fail, "Failed to match Immediate Assignment");
10476 mtc.stop;
10477 }
10478}
10479
10480testcase TC_imm_ass_post_chan_ack() runs on test_CT {
10481 var RSL_Message chan_act;
10482 var RSL_Message imm_ass;
10483
10484 f_init(1, false);
10485 f_sleep(1.0);
10486
10487 /* (should be the default anyway, just to make things clear) */
10488 f_vty_set_imm_ass(BSCVTY, 0, "post-chan-ack");
10489
10490 /* RA containing reason=LU */
10491 var GsmFrameNumber fn := 2342;
10492 var uint8_t ra := 2;
10493 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10494
10495 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10496
10497 /* First send the Chan Act ACK */
10498 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010499 var DchanTuple dt;
10500 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010501 var RSL_IE_Body chan_ident_ie;
10502 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10503 setverdict(fail, "RSL Channel Identification IE is absent");
10504 mtc.stop;
10505 }
10506
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010507 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn + 10));
10508
10509 /* Then expect the Immediate Assignment, after we ACKed the chan act */
10510 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10511
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010512 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10513 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010514
10515 /* Check that the lchan is working */
10516 var octetstring l3 := '00010203040506'O;
10517 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10518
10519 var BSSAP_N_CONNECT_ind rx_c_ind;
10520 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010521 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010522 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10523
10524 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010525 f_perform_clear_test_ct(dt);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010526 f_shutdown_helper();
10527}
10528
10529testcase TC_imm_ass_pre_chan_ack() runs on test_CT {
10530 var RSL_Message chan_act;
10531 var RSL_Message imm_ass;
10532
10533 f_init(1, false);
10534 f_sleep(1.0);
10535
10536 f_vty_set_imm_ass(BSCVTY, 0, "pre-chan-ack");
10537
10538 /* RA containing reason=LU */
10539 var GsmFrameNumber fn := 2342;
10540 var uint8_t ra := 2;
10541 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10542
10543 /* (set bts 0 cfg back to default) */
10544 f_vty_set_imm_ass(BSCVTY);
10545
10546 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10547 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010548 var DchanTuple dt;
10549 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010550 var RSL_IE_Body chan_ident_ie;
10551 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10552 setverdict(fail, "RSL Channel Identification IE is absent");
10553 mtc.stop;
10554 }
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010555
10556 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10557 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010558 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10559 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010560
10561 /* Only now send the Chan Act ACK */
10562 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10563
10564 /* Check that the lchan is working */
10565 var octetstring l3 := '00010203040506'O;
10566 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10567
10568 var BSSAP_N_CONNECT_ind rx_c_ind;
10569 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010570 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010571 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10572
10573 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010574 f_perform_clear_test_ct(dt);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010575 f_shutdown_helper();
10576}
10577
Neels Hofmeyr23158742021-09-07 19:08:07 +020010578testcase TC_imm_ass_pre_ts_ack() runs on test_CT {
10579 var RSL_Message chan_act;
10580 var RSL_Message imm_ass;
10581
10582 f_init(1, false);
10583 f_sleep(1.0);
10584
10585 f_vty_set_imm_ass(BSCVTY, 0, "pre-ts-ack");
10586
10587 /* RA containing reason=LU */
10588 var GsmFrameNumber fn := 2342;
10589 var uint8_t ra := 2;
10590 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10591
10592 /* (set bts 0 cfg back to default) */
10593 f_vty_set_imm_ass(BSCVTY);
10594
10595 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10596 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010597 var DchanTuple dt;
10598 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyr23158742021-09-07 19:08:07 +020010599 var RSL_IE_Body chan_ident_ie;
10600 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10601 setverdict(fail, "RSL Channel Identification IE is absent");
10602 mtc.stop;
10603 }
10604
10605 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10606 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10607 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10608 chan_ident_ie.chan_ident.ch_desc.v.tsc);
10609
10610 /* Only now send the Chan Act ACK */
10611 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10612
10613 /* Check that the lchan is working */
10614 var octetstring l3 := '00010203040506'O;
10615 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10616
10617 var BSSAP_N_CONNECT_ind rx_c_ind;
10618 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010619 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyr23158742021-09-07 19:08:07 +020010620 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10621
10622 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010623 f_perform_clear_test_ct(dt);
Neels Hofmeyr23158742021-09-07 19:08:07 +020010624 f_shutdown_helper();
10625}
10626
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010627testcase TC_imm_ass_pre_chan_ack_dyn_ts() runs on test_CT {
10628 /* change Timeslot 6 before f_init() starts RSL */
10629 f_init_vty();
10630 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
10631 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10632
10633 f_init(1, false);
10634 f_sleep(1.0);
10635
10636 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
10637 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010638 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010639 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2323));
10640
10641 /* clean up timeslot 6 config, will only take effect when the OML drops the next time */
10642 f_ts_set_chcomb(0, 0, 6, "PDCH");
10643
10644 /* block all static timeslots so that the dyn TS will be used */
10645 f_disable_all_tch_f();
10646 f_disable_all_tch_h();
10647 f_disable_all_sdcch();
10648
10649 var RSL_Message chan_act;
10650 var RSL_Message imm_ass;
10651
10652 f_init(1, false);
10653 f_sleep(1.0);
10654
10655 f_vty_set_imm_ass(BSCVTY, 0, "pre-chan-ack");
10656
10657 /* RA containing reason=LU */
10658 var GsmFrameNumber fn := 2342;
10659 var uint8_t ra := 2;
10660 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10661
10662 /* (set bts 0 cfg back to default) */
10663 f_vty_set_imm_ass(BSCVTY);
10664
10665 /* Expect the dyn TS to deactivate PDCH first */
10666 f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
10667 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
10668
10669 /* Now activation as SDCCH8 */
10670 chan_nr := valueof(t_RslChanNr_SDCCH8(tn := 6, sub_slot := 0));
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010671 var DchanTuple dt;
10672 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010673
10674 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010675 var RSL_IE_Body chan_ident_ie;
10676 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10677 setverdict(fail, "RSL Channel Identification IE is absent");
10678 mtc.stop;
10679 }
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010680
10681 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10682 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010683 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10684 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010685
10686 /* Only now send the Chan Act ACK */
10687 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10688
10689 /* Check that the lchan is working */
10690 var octetstring l3 := '00010203040506'O;
10691 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10692
10693 var BSSAP_N_CONNECT_ind rx_c_ind;
10694 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010695 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010696 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10697
10698 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010699 f_perform_clear_test_ct(dt);
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010700 f_shutdown_helper();
10701}
10702
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010703testcase TC_imm_ass_pre_ts_ack_dyn_ts() runs on test_CT {
10704 /* change Timeslot 6 before f_init() starts RSL */
10705 f_init_vty();
10706 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
10707 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10708
10709 f_init(1, false);
10710 f_sleep(1.0);
10711
10712 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
10713 /* The BSC will activate the dynamic PDCH by default, so confirm that */
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060010714 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010715 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2323));
10716
10717 /* clean up timeslot 6 config, will only take effect when the OML drops the next time */
10718 f_ts_set_chcomb(0, 0, 6, "PDCH");
10719
10720 /* block all static timeslots so that the dyn TS will be used */
10721 f_disable_all_tch_f();
10722 f_disable_all_tch_h();
10723 f_disable_all_sdcch();
10724
10725 var RSL_Message chan_act;
10726 var RSL_Message imm_ass;
10727
10728 f_init(1, false);
10729 f_sleep(1.0);
10730
10731 f_vty_set_imm_ass(BSCVTY, 0, "pre-ts-ack");
10732
10733 /* RA containing reason=LU */
10734 var GsmFrameNumber fn := 2342;
10735 var uint8_t ra := 2;
10736 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10737
10738 /* (set bts 0 cfg back to default) */
10739 f_vty_set_imm_ass(BSCVTY);
10740
10741 /* Expect the dyn TS to deactivate PDCH first */
10742 f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
10743
10744 /* And already the Immediate Assignment even before the PDCH Deact ACK */
10745 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10746
10747 /* continue the Osmo style PDCH Deact (usual chan rel) */
10748 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
10749
10750 /* Now activation as SDCCH8 */
10751 chan_nr := valueof(t_RslChanNr_SDCCH8(tn := 6, sub_slot := 0));
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010752 var DchanTuple dt;
10753 dt.rsl_chan_nr := chan_nr;
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010754
10755 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010756 var RSL_IE_Body chan_ident_ie;
10757 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10758 setverdict(fail, "RSL Channel Identification IE is absent");
10759 mtc.stop;
10760 }
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010761 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10762
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010763 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10764 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010765
10766 /* Check that the lchan is working */
10767 var octetstring l3 := '00010203040506'O;
10768 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10769
10770 var BSSAP_N_CONNECT_ind rx_c_ind;
10771 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010772 dt.sccp_conn_id := rx_c_ind.connectionId;
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010773 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10774
10775 f_sleep(1.0);
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010776 f_perform_clear_test_ct(dt);
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010777 f_shutdown_helper();
10778}
10779
Neels Hofmeyr5d7d13f2021-09-07 14:44:36 +020010780/* GET and SET the bts.N.trx.M.rf_locked CTRL variable */
10781testcase TC_ctrl_trx_rf_locked() runs on test_CT {
10782 var MSC_ConnHdlr vc_conn;
10783
10784 f_init(nr_bts := 2, handler_mode := true, nr_msc := 1);
10785 f_sleep(1.0);
10786
10787 /* BTS 0, 1, 2 are OML unlocked, only BTS 0, 1 are actually connected to RSL. */
10788 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10789 "0,0,operational,unlocked,on,rsl-up;" &
10790 "1,0,operational,unlocked,on,rsl-up;" &
10791 "2,0,operational,unlocked,on,rsl-down;" &
10792 "3,0,inoperational,locked,on,rsl-down;");
10793
10794 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: lock BTS 1 TRX 0");
10795 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "1");
10796 /* give it a moment to settle the FSM status */
10797 f_sleep(1.0);
10798
10799 /* Now BTS 1 TRX 0 should reflect "locked". Note the RF policy stays "on", because this is still handled
10800 * globally in osmo-bsc. Probably after sending "rf_locked 1" for a TRX, that TRX should reflect an RF policy
10801 * of "off"? But that's for a future patch if at all. */
10802 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10803 "0,0,operational,unlocked,on,rsl-up;" &
10804 "1,0,operational,locked,on,rsl-up;" &
10805 "2,0,operational,unlocked,on,rsl-down;" &
10806 "3,0,inoperational,locked,on,rsl-down;");
10807
10808 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: lock the already locked TRX, nothing should change");
10809 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "1");
10810 f_sleep(1.0);
10811 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10812 "0,0,operational,unlocked,on,rsl-up;" &
10813 "1,0,operational,locked,on,rsl-up;" &
10814 "2,0,operational,unlocked,on,rsl-down;" &
10815 "3,0,inoperational,locked,on,rsl-down;");
10816
10817 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock BTS 1 TRX 0");
10818 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "0");
10819 f_sleep(1.0);
10820 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10821 "0,0,operational,unlocked,on,rsl-up;" &
10822 "1,0,operational,unlocked,on,rsl-up;" &
10823 "2,0,operational,unlocked,on,rsl-down;" &
10824 "3,0,inoperational,locked,on,rsl-down;");
10825
10826 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock an already unlocked TRX, nothing should change");
10827 f_ctrl_set(IPA_CTRL, "bts.0.trx.0.rf_locked", "0");
10828 f_sleep(1.0);
10829 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10830 "0,0,operational,unlocked,on,rsl-up;" &
10831 "1,0,operational,unlocked,on,rsl-up;" &
10832 "2,0,operational,unlocked,on,rsl-down;" &
10833 "3,0,inoperational,locked,on,rsl-down;");
10834
10835 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock an inoperational TRX");
10836 f_ctrl_set(IPA_CTRL, "bts.3.trx.0.rf_locked", "0");
10837 f_sleep(1.0);
10838 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10839 "0,0,operational,unlocked,on,rsl-up;" &
10840 "1,0,operational,unlocked,on,rsl-up;" &
10841 "2,0,operational,unlocked,on,rsl-down;" &
10842 "3,0,inoperational,locked,on,rsl-down;");
10843
10844 f_shutdown_helper();
10845}
10846
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010847const CounterNameVals counternames_cm_serv_rej := {
10848 { "cm_serv_rej", 0 },
10849 { "cm_serv_rej:imsi_unknown_in_hlr", 0 },
10850 { "cm_serv_rej:illegal_ms", 0 },
10851 { "cm_serv_rej:imsi_unknown_in_vlr", 0 },
10852 { "cm_serv_rej:imei_not_accepted", 0 },
10853 { "cm_serv_rej:illegal_me", 0 },
10854 { "cm_serv_rej:plmn_not_allowed", 0 },
10855 { "cm_serv_rej:loc_not_allowed", 0 },
10856 { "cm_serv_rej:roaming_not_allowed", 0 },
10857 { "cm_serv_rej:network_failure", 0 },
10858 { "cm_serv_rej:synch_failure", 0 },
10859 { "cm_serv_rej:congestion", 0 },
10860 { "cm_serv_rej:srv_opt_not_supported", 0 },
10861 { "cm_serv_rej:rqd_srv_opt_not_supported", 0 },
10862 { "cm_serv_rej:srv_opt_tmp_out_of_order", 0 },
10863 { "cm_serv_rej:call_can_not_be_identified", 0 },
10864 { "cm_serv_rej:incorrect_message", 0 },
10865 { "cm_serv_rej:invalid_mandantory_inf", 0 },
10866 { "cm_serv_rej:msg_type_not_implemented", 0 },
10867 { "cm_serv_rej:msg_type_not_compatible", 0 },
10868 { "cm_serv_rej:inf_eleme_not_implemented", 0 },
10869 { "cm_serv_rej:condtional_ie_error", 0 },
10870 { "cm_serv_rej:msg_not_compatible", 0 },
10871 { "cm_serv_rej:protocol_error", 0 },
10872 { "cm_serv_rej:retry_in_new_cell", 0 }
10873};
10874
10875private function f_TC_cm_serv_rej(charstring id) runs on MSC_ConnHdlr
10876{
10877 f_create_chan_and_exp();
Vadim Yanitskiya7fc5a62021-12-04 20:10:08 +030010878 /* we should now have a COMPL_L3 at the MSC */
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010879 BSSAP.send(ts_PDU_DTAP_MT(ts_CM_SERV_REJ('02'O), '00'O));
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010010880 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_CM_SERV_REJ));
10881 f_perform_clear();
Neels Hofmeyr87a65612021-11-16 15:56:45 +010010882 f_sleep(1.0);
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010883}
10884testcase TC_cm_serv_rej() runs on test_CT {
10885 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10886 var MSC_ConnHdlr vc_conn;
10887
10888 f_init(1, true);
10889 f_sleep(1.0);
10890
10891 f_ctrs_bts_init(1, counternames_cm_serv_rej);
10892
10893 vc_conn := f_start_handler(refers(f_TC_cm_serv_rej), pars);
10894 vc_conn.done;
10895
10896 f_ctrs_bts_add(0, "cm_serv_rej", 1);
10897 f_ctrs_bts_add(0, "cm_serv_rej:imsi_unknown_in_hlr", 1);
10898 f_ctrs_bts_verify();
10899
Neels Hofmeyr87a65612021-11-16 15:56:45 +010010900 f_sleep(1.0);
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010901 f_shutdown_helper();
10902}
10903
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010904/* Reproduce a segfault happening when the SDCCH (primary) lchan is lost in-between a TCH Channel Activ and its Channel
10905 * Activ Ack (SYS#5627). */
10906private function f_TC_lost_sdcch_during_assignment(charstring id) runs on MSC_ConnHdlr {
10907 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Vadim Yanitskiyf0310e32021-10-26 00:30:59 +030010908
10909 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10910 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010911
10912 var BSSMAP_FIELD_CodecType codecType;
10913 codecType := valueof(ass_cmd.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType);
10914
10915 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
10916
10917 /* First establish a signalling lchan */
10918 f_create_chan_and_exp();
10919 f_rslem_dchan_queue_enable();
10920
10921 /* we should now have a COMPL_L3 at the MSC */
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010922
10923 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
10924 activate(as_Media_mgw());
10925
10926 var RslChannelNr chan_nr := { u := { ch0 := RSL_CHAN_NR_Bm_ACCH }, tn := 1 };
10927 f_rslem_register(0, chan_nr);
10928
10929 f_rslem_set_auto_chan_act_ack(RSL_PROC, false);
10930 BSSAP.send(ass_cmd);
10931
10932
10933 /* Wait for the Channel Activ for the TCH channel */
10934 var ASP_RSL_Unitdata rx_rsl_ud;
10935 RSL.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV), sid := ?)) -> value rx_rsl_ud;
10936
10937 /* make the original SDCCH disappear */
10938 RSL.send(ts_RSL_REL_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
10939
10940 /* and ACK the TCH channel activation. This caused a segfault up to OsmoBSC 1.7.0 (SYS#5627) */
10941 RSL.send(ts_ASP_RSL_UD(ts_RSL_CHAN_ACT_ACK(chan_nr, 23), rx_rsl_ud.streamId));
10942
10943 interleave {
10944 [] BSSAP.receive(tr_BSSMAP_AssignmentFail);
10945 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
10946 }
10947
10948 BSSAP.send(ts_BSSMAP_ClearCommand(0));
10949 BSSAP.receive(tr_BSSMAP_ClearComplete);
10950 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
10951
10952 var MgcpCommand mgcp;
10953 MGCP.receive(tr_DLCX()) -> value mgcp {
10954 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
10955 };
10956
10957 f_sleep(0.5);
10958}
10959testcase TC_lost_sdcch_during_assignment() runs on test_CT {
10960 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10961 var MSC_ConnHdlr vc_conn;
10962
10963 f_init(1, true);
10964 f_sleep(1.0);
10965
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010966 vc_conn := f_start_handler(refers(f_TC_lost_sdcch_during_assignment), pars);
10967 vc_conn.done;
10968
10969 f_shutdown_helper();
10970}
10971
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010972const CounterNameVals counternames_bsc_bts_all_available_allocated := {
10973 { "all_allocated:sdcch", 0 },
10974 { "all_allocated:static_sdcch", 0 },
10975 { "all_allocated:tch", 0 },
10976 { "all_allocated:static_tch", 0 }
10977}
10978
10979private function f_all_allocated_expect_counter_change(charstring_list expect_changed) runs on test_CT
10980{
10981 /* Make sure counters settle first */
10982 f_sleep(1.0);
10983
10984 /* Take a baseline of counters */
10985 f_ctrs_bsc_and_bts_init(1, counternames_bsc_bts_all_available_allocated);
10986
10987 /* Elapse some time so that we see changes in counters, hopefully where expected */
10988 f_sleep(2.0);
10989
10990 /* Get new counters */
10991 var charstring_list all_changed := {};
10992 all_changed := all_changed & f_counter_name_vals_get_changed_n(IPA_CTRL, "bsc", g_ctr_bsc);
10993 all_changed := all_changed & f_counter_name_vals_get_changed_n(IPA_CTRL, "bts", g_ctr_bts);
10994
10995 /* Compare with expectations */
10996 var charstring_list all_expect_changed := {};
10997 for (var integer i := 0; i < lengthof(expect_changed); i := i + 1) {
10998 all_expect_changed := all_expect_changed & { "bsc.0." & expect_changed[i], "bts.0." & expect_changed[i] };
10999 }
11000 f_counter_name_vals_expect_changed_list(all_changed, all_expect_changed);
11001}
11002
11003testcase TC_ratectr_all_available_allocated() runs on test_CT {
11004 var ASP_RSL_Unitdata rsl_ud;
11005 var integer i;
11006 var integer chreq_total, chreq_nochan;
11007
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011008 f_init(1, guard_timeout := 60.0);
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011009 f_sleep(1.0);
11010
11011 /* Exhaust all dedicated SDCCH lchans.
11012 /* GSM 44.018 Table 9.1.8.2:
11013 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
11014 */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011015 var DchanTuples chan_cleanup := {};
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011016 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011017 chan_cleanup := chan_cleanup & { f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011018 }
11019
11020 /* Since only bts 0 is connected, expecting all_allocated to become true for both bts 0 and the "global" bsc
11021 * level.
11022 * All SDCCH are now occupied. */
11023 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch"});
11024
11025 /* Also fill up all remaining (TCH) channels */
11026 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011027 chan_cleanup := chan_cleanup & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011028 }
11029
11030 /* All TCH are now also occupied */
11031 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch",
11032 "all_allocated:tch", "all_allocated:static_tch"});
11033
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011034 /* Clean up SDCCH lchans */
11035 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
11036 f_perform_clear_test_ct(chan_cleanup[i]);
11037 }
11038
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011039 f_shutdown_helper();
11040}
11041
11042testcase TC_ratectr_all_available_allocated_dyn() runs on test_CT {
11043 var ASP_RSL_Unitdata rsl_ud;
11044 var integer i;
11045 var integer chreq_total, chreq_nochan;
11046
11047 f_init_vty();
11048 f_ts_set_chcomb(0, 0, 2, "TCH/F_TCH/H_PDCH");
11049 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
11050 /* Now we have 3 TCH/F, 1 OSMO_DYN, 1 TCH/H */
11051
11052 f_init(1, guard_timeout := 60.0);
11053 f_sleep(1.0);
11054
11055 /* The dyn TS wants to activate PDCH mode, ACK that. */
11056 var RslChannelNr chan_nr;
11057 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060011058 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011059 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
11060
11061 /* Exhaust all dedicated SDCCH lchans.
11062 /* GSM 44.018 Table 9.1.8.2:
11063 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
11064 */
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011065 var DchanTuples chan_cleanup := {};
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011066 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011067 chan_cleanup := chan_cleanup & { f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011068 }
11069
11070 /* The static SDCCH should now be occupied, while still 3x8 dynamic SDCCH potentially remain. So only
11071 * all_allocated:static_sdcch is counted, all_allocated:sdcch remains zero. */
11072 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch"});
11073
11074 /* Request more SDCCH, hence convert the first dyn TS to SDCCH8.
11075 * Will release them later, so remember all the DchanTuples. */
11076 var DchanTuples dyn_sddch := {};
11077 dyn_sddch := dyn_sddch & { f_est_dchan_dyn('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
11078
11079 /* Also occupy the seven other SDCCH of the dyn TS */
11080 for (i := 0; i < 7; i := i+1) {
11081 dyn_sddch := dyn_sddch & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
11082 }
11083
11084 /* Now all dynamic SDCCH are also occupied, so for the first time all_allocated:sdcch will trigger... */
11085 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch"});
11086
11087 /* occupy the remaining TCH, three TCH/F and two TCH/H lchans */
11088 for (i := 0; i < 5; i := i+1) {
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011089 chan_cleanup := chan_cleanup & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011090 }
11091
11092 /* All TCH lchans are now also occupied, both static and dynamic */
11093 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch",
11094 "all_allocated:tch", "all_allocated:static_tch"});
11095
11096 /* Starting to release the dyn TS: as soon as the first SDCCH gets released, all_allocated:sdcch stops
11097 * incrementing. */
11098 var BssmapCause cause := 0;
11099 var DchanTuple dt := dyn_sddch[0];
11100 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
11101 f_exp_chan_rel_and_clear(dt, 0);
11102
11103 /* one dyn TS SDCCH is free again, so only the static_sdcch should increment. For tch, both static and dynamic
11104 * count as occupied, so those still both increment. */
11105 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch",
11106 "all_allocated:tch", "all_allocated:static_tch"});
11107
11108 /* Release the remaining SDCCH of the dyn TS, so it becomes available as TCH again */
11109 for (i := 1; i < lengthof(dyn_sddch); i := i+1) {
11110 dt := dyn_sddch[i];
11111 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
11112 f_exp_chan_rel_and_clear(dt, 0);
11113 }
11114
11115 /* All SDCCH on the dyn TS are released, the dyn TS wants to activate PDCH again */
11116 chan_nr := valueof(t_RslChanNr_PDCH(2));
Vadim Yanitskiy58b16532021-10-09 20:27:39 +060011117 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr));
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011118 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
11119
11120 /* Now all channels are occupied except the dyn TS, so expecting only the static counters to increment */
11121 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch", "all_allocated:static_tch"});
11122
Neels Hofmeyr4d4cd7e2021-12-14 17:25:36 +010011123 /* Clean up SDCCH lchans */
11124 for (i := 0; i < lengthof(chan_cleanup); i := i + 1) {
11125 f_perform_clear_test_ct(chan_cleanup[i]);
11126 }
11127
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011128 /* clean up config */
11129 f_ts_reset_chcomb(0);
11130
11131 f_shutdown_helper();
11132}
11133
Harald Welte28d943e2017-11-25 15:00:50 +010011134control {
Harald Welte898113b2018-01-31 18:32:21 +010011135 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +010011136 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +010011137 execute( TC_ctrl_msc0_connection_status() );
Neels Hofmeyrf65ce872021-09-23 18:40:10 +020011138 /* In SCCPlite tests, only one MSC is configured. These tests assume that three MSCs are configured, so only run
11139 * these in the AoIP test suite. */
11140 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11141 execute( TC_stat_num_msc_connected_1() );
11142 execute( TC_stat_num_msc_connected_2() );
11143 execute( TC_stat_num_msc_connected_3() );
11144 }
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +020011145 execute( TC_stat_num_bts_connected_1() );
11146 execute( TC_stat_num_bts_connected_2() );
11147 execute( TC_stat_num_bts_connected_3() );
Harald Welte96c94412017-12-09 03:12:45 +010011148 execute( TC_ctrl() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +020011149 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER) {
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +020011150 execute( TC_ctrl_location() );
11151 }
Harald Welte898113b2018-01-31 18:32:21 +010011152
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020011153 execute( TC_si_default() );
Neels Hofmeyr66aeba42020-07-06 02:21:21 +020011154 execute( TC_si2quater_2_earfcns() );
11155 execute( TC_si2quater_3_earfcns() );
11156 execute( TC_si2quater_4_earfcns() );
11157 execute( TC_si2quater_5_earfcns() );
11158 execute( TC_si2quater_6_earfcns() );
Neels Hofmeyrad132f22020-07-08 02:20:16 +020011159 execute( TC_si2quater_12_earfcns() );
11160 execute( TC_si2quater_23_earfcns() );
11161 execute( TC_si2quater_32_earfcns() );
11162 execute( TC_si2quater_33_earfcns() );
11163 execute( TC_si2quater_42_earfcns() );
11164 execute( TC_si2quater_48_earfcns() );
11165 execute( TC_si2quater_49_earfcns() );
Pau Espin Pedrol85a84432020-07-20 18:45:03 +020011166 execute( TC_si_acc_rotate() );
Alexander Couzens4ad3a352020-09-10 22:29:12 +020011167 execute( TC_si_acc_ramp_rotate() );
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020011168
Harald Welte898113b2018-01-31 18:32:21 +010011169 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +010011170 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +010011171 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +010011172 execute( TC_chan_act_ack_noest() );
Philipp Maier9c60a622020-07-09 15:08:46 +020011173 execute( TC_chan_act_ack_noest_emerg() );
Philipp Maier606f07d2020-08-12 17:21:58 +020011174 execute( TC_chan_rqd_emerg_deny() );
Harald Welteae026692017-12-09 01:03:01 +010011175 execute( TC_chan_act_ack_est_ind_noreply() );
11176 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +010011177 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +010011178 execute( TC_chan_exhaustion() );
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +070011179 execute( TC_chan_deact_silence() );
Harald Welte4003d112017-12-09 22:35:39 +010011180 execute( TC_chan_rel_rll_rel_ind() );
11181 execute( TC_chan_rel_conn_fail() );
11182 execute( TC_chan_rel_hard_clear() );
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +020011183 execute( TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() );
11184 execute( TC_chan_rel_last_eutran_plmn_hard_clear_csfb() );
Harald Welte99787102019-02-04 10:41:36 +010011185 execute( TC_chan_rel_hard_clear_csfb() );
Harald Welted8c36cd2017-12-09 23:05:31 +010011186 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +020011187 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +010011188 execute( TC_chan_rel_a_reset() );
Pau Espin Pedrolc675b612020-01-09 19:55:40 +010011189 execute( TC_chan_rel_sccp_tiar_timeout() );
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +020011190 execute( TC_chan_rel_rr_cause() );
Harald Welte6f521d82017-12-11 19:52:02 +010011191
Harald Weltecfe2c962017-12-15 12:09:32 +010011192 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +010011193
11194 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +010011195 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +010011196 execute( TC_assignment_csd() );
11197 execute( TC_assignment_ctm() );
11198 execute( TC_assignment_sign() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +020011199 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11200 execute( TC_assignment_aoip_tla_v6() );
11201 }
Harald Welte235ebf12017-12-15 14:18:16 +010011202 execute( TC_assignment_fr_a5_0() );
11203 execute( TC_assignment_fr_a5_1() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +020011204 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte8f67d1d2018-05-25 20:38:42 +020011205 execute( TC_assignment_fr_a5_1_codec_missing() );
11206 }
Harald Welte235ebf12017-12-15 14:18:16 +010011207 execute( TC_assignment_fr_a5_3() );
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +020011208 execute( TC_assignment_fr_a5_4() );
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +020011209 execute( TC_assignment_fr_a5_4_fail() );
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +020011210 execute( TC_assignment_fr_a5_not_sup() );
Harald Welte3c86ea02018-05-10 22:28:05 +020011211 execute( TC_ciph_mode_a5_0() );
11212 execute( TC_ciph_mode_a5_1() );
Oliver Smith50b98122021-07-09 15:00:28 +020011213 execute( TC_ciph_mode_a5_2_0() );
Oliver Smith1dff88d2021-07-09 08:45:51 +020011214 execute( TC_ciph_mode_a5_2_1() );
Harald Welte3c86ea02018-05-10 22:28:05 +020011215 execute( TC_ciph_mode_a5_3() );
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +020011216 execute( TC_ciph_mode_a5_4() );
Harald Welte16a4adf2017-12-14 18:54:01 +010011217
Harald Welte60aa5762018-03-21 19:33:13 +010011218 execute( TC_assignment_codec_fr() );
Neels Hofmeyr559d5d02021-04-16 16:50:49 +020011219 execute( TC_assignment_codec_fr_by_mode_modify() );
Harald Welte60aa5762018-03-21 19:33:13 +010011220 execute( TC_assignment_codec_hr() );
11221 execute( TC_assignment_codec_efr() );
11222 execute( TC_assignment_codec_amr_f() );
11223 execute( TC_assignment_codec_amr_h() );
Philipp Maier8a581d22019-03-26 18:32:48 +010011224
Neels Hofmeyrf246a922020-05-13 02:27:10 +020011225 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier8a581d22019-03-26 18:32:48 +010011226 execute( TC_assignment_codec_amr_f_S1() );
11227 execute( TC_assignment_codec_amr_h_S1() );
11228 execute( TC_assignment_codec_amr_f_S124() );
11229 execute( TC_assignment_codec_amr_h_S124() );
11230 execute( TC_assignment_codec_amr_f_S0() );
11231 execute( TC_assignment_codec_amr_f_S02() );
11232 execute( TC_assignment_codec_amr_f_S024() );
11233 execute( TC_assignment_codec_amr_f_S0247() );
11234 execute( TC_assignment_codec_amr_h_S0() );
11235 execute( TC_assignment_codec_amr_h_S02() );
11236 execute( TC_assignment_codec_amr_h_S024() );
11237 execute( TC_assignment_codec_amr_h_S0247() );
11238 execute( TC_assignment_codec_amr_f_S01234567() );
11239 execute( TC_assignment_codec_amr_f_S0234567() );
11240 execute( TC_assignment_codec_amr_f_zero() );
11241 execute( TC_assignment_codec_amr_f_unsupp() );
11242 execute( TC_assignment_codec_amr_h_S7() );
Neels Hofmeyr21863562020-11-26 00:34:33 +000011243 execute( TC_assignment_codec_amr_f_start_mode_auto() );
11244 execute( TC_assignment_codec_amr_h_start_mode_auto() );
Neels Hofmeyr3eb94562020-11-26 02:40:26 +000011245 execute( TC_assignment_codec_amr_f_start_mode_4() );
11246 execute( TC_assignment_codec_amr_h_start_mode_4() );
Neels Hofmeyr454d7922020-11-26 02:24:57 +000011247 execute( TC_assignment_codec_amr_startmode_cruft() );
Philipp Maier8a581d22019-03-26 18:32:48 +010011248 }
Harald Welte60aa5762018-03-21 19:33:13 +010011249
Philipp Maierac09bfc2019-01-08 13:41:39 +010011250 execute( TC_assignment_codec_fr_exhausted_req_hr() );
11251 execute( TC_assignment_codec_fr_exhausted_req_fr() );
11252 execute( TC_assignment_codec_fr_exhausted_req_fr_hr() );
11253 execute( TC_assignment_codec_fr_exhausted_req_hr_fr() );
11254 execute( TC_assignment_codec_hr_exhausted_req_fr() );
11255 execute( TC_assignment_codec_hr_exhausted_req_hr() );
11256 execute( TC_assignment_codec_hr_exhausted_req_hr_fr() );
11257 execute( TC_assignment_codec_hr_exhausted_req_fr_hr() );
11258 execute( TC_assignment_codec_req_hr_fr() );
11259 execute( TC_assignment_codec_req_fr_hr() );
Pau Espin Pedrol14475352021-07-22 15:48:16 +020011260 execute( TC_assignment_sdcch_exhausted_req_signalling() );
11261 execute( TC_assignment_sdcch_exhausted_req_signalling_tch_forbidden() );
11262 execute( TC_assignment_sdcch_exhausted_req_voice_tch_forbidden() );
Philipp Maierac09bfc2019-01-08 13:41:39 +010011263
Pau Espin Pedrol23510fb2021-07-20 17:00:38 +020011264 execute( TC_assignment_osmux() );
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +020011265
Harald Welte898113b2018-01-31 18:32:21 +010011266 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +010011267 execute( TC_rll_est_ind_inact_lchan() );
11268 execute( TC_rll_est_ind_inval_sapi1() );
11269 execute( TC_rll_est_ind_inval_sapi3() );
11270 execute( TC_rll_est_ind_inval_sacch() );
11271
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +070011272 /* DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
11273 execute( TC_tch_dlci_link_id_sapi() );
11274
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +070011275 /* SAPI N Reject triggered by RLL establishment failures */
11276 execute( TC_rll_rel_ind_sapi_n_reject() );
11277 execute( TC_rll_err_ind_sapi_n_reject() );
11278 execute( TC_rll_timeout_sapi_n_reject() );
Vadim Yanitskiy999ceb62020-10-04 00:04:49 +070011279 execute( TC_rll_sapi_n_reject_dlci_cc() );
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +070011280
Harald Welte898113b2018-01-31 18:32:21 +010011281 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +010011282 execute( TC_paging_imsi_nochan() );
11283 execute( TC_paging_tmsi_nochan() );
11284 execute( TC_paging_tmsi_any() );
11285 execute( TC_paging_tmsi_sdcch() );
11286 execute( TC_paging_tmsi_tch_f() );
11287 execute( TC_paging_tmsi_tch_hf() );
11288 execute( TC_paging_imsi_nochan_cgi() );
11289 execute( TC_paging_imsi_nochan_lac_ci() );
11290 execute( TC_paging_imsi_nochan_ci() );
11291 execute( TC_paging_imsi_nochan_lai() );
11292 execute( TC_paging_imsi_nochan_lac() );
11293 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +010011294 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
11295 execute( TC_paging_imsi_nochan_rnc() );
11296 execute( TC_paging_imsi_nochan_lac_rnc() );
11297 execute( TC_paging_imsi_nochan_lacs() );
11298 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +010011299 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +010011300 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +010011301 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +010011302 execute( TC_paging_counter() );
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +010011303 execute( TC_paging_resp_unsol() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +010011304
11305 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +010011306 execute( TC_rsl_unknown_unit_id() );
11307
11308 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +010011309
11310 execute( TC_classmark() );
Harald Welteeddf0e92020-06-21 19:42:15 +020011311 execute( TC_common_id() );
Harald Welte898113b2018-01-31 18:32:21 +010011312 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +010011313 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +010011314 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +010011315 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +010011316 execute( TC_err_84_unknown_msg() );
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010011317
Harald Welte261af4b2018-02-12 21:20:39 +010011318 execute( TC_ho_int() );
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +020011319 execute( TC_ho_int_a5_0() );
11320 execute( TC_ho_int_a5_1() );
11321 execute( TC_ho_int_a5_3() );
11322 execute( TC_ho_int_a5_4() );
Neels Hofmeyr5f144212020-11-03 15:41:58 +000011323 execute( TC_ho_int_radio_link_failure() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011324
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +010011325 /* TC_ho_out_of_this_bsc is run last, see comment below */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +020011326 execute( TC_ho_out_fail_no_msc_response() );
11327 execute( TC_ho_out_fail_rr_ho_failure() );
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +020011328 execute( TC_ho_out_fail_no_result_after_ho_cmd() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011329
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010011330 execute( TC_ho_into_this_bsc() );
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +020011331 execute( TC_ho_into_this_bsc_a5_0() );
11332 execute( TC_ho_into_this_bsc_a5_1() );
11333 execute( TC_ho_into_this_bsc_a5_3() );
11334 execute( TC_ho_into_this_bsc_a5_4() );
Neels Hofmeyr93182e02022-02-17 21:59:07 +010011335 execute( TC_ho_into_this_bsc_a5_1_3_no_chosen_enc_alg() );
11336 execute( TC_ho_into_this_bsc_a5_1_3() );
Neels Hofmeyr907b23b2022-02-17 21:58:47 +010011337 execute( TC_ho_into_this_bsc_a5_mismatch() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +020011338 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11339 execute( TC_ho_into_this_bsc_tla_v6() );
11340 }
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +020011341 execute( TC_srvcc_eutran_to_geran() );
Pau Espin Pedrola8ef3be2022-02-16 16:21:17 +010011342 execute( TC_srvcc_eutran_to_geran_src_sai() );
Pau Espin Pedrol35801c32021-04-19 13:03:20 +020011343 execute( TC_srvcc_eutran_to_geran_ho_out() );
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +020011344 execute( TC_srvcc_eutran_to_geran_forbid_fast_return() );
11345 execute( TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010011346 execute( TC_ho_in_fail_msc_clears() );
11347 execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
11348 execute( TC_ho_in_fail_no_detect() );
11349 execute( TC_ho_in_fail_no_detect2() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +010011350
Neels Hofmeyr91401012019-07-11 00:42:35 +020011351 execute( TC_ho_neighbor_config_1() );
11352 execute( TC_ho_neighbor_config_2() );
11353 execute( TC_ho_neighbor_config_3() );
11354 execute( TC_ho_neighbor_config_4() );
11355 execute( TC_ho_neighbor_config_5() );
11356 execute( TC_ho_neighbor_config_6() );
11357 execute( TC_ho_neighbor_config_7() );
11358
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +010011359 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010011360 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +010011361 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +020011362
11363 execute( TC_dyn_pdch_ipa_act_deact() );
11364 execute( TC_dyn_pdch_ipa_act_nack() );
11365 execute( TC_dyn_pdch_osmo_act_deact() );
11366 execute( TC_dyn_pdch_osmo_act_nack() );
Pau Espin Pedrol37a4c152021-11-16 19:02:23 +010011367 execute( TC_dyn_ts_sdcch8_act_deact() );
11368 execute( TC_dyn_ts_sdcch8_all_subslots_used() );
11369 execute( TC_dyn_ts_sdcch8_tch_call_act_deact() );
11370 execute( TC_dyn_ts_sdcch8_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +020011371
Stefan Sperling0796a822018-10-05 13:01:39 +020011372 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +020011373 execute( TC_chopped_ipa_payload() );
Stefan Sperling0796a822018-10-05 13:01:39 +020011374
Pau Espin Pedrol8f773632019-11-05 11:46:53 +010011375 /* Power control related */
11376 execute( TC_assignment_verify_ms_power_params_ie() );
Vadim Yanitskiy4b233042021-06-30 00:58:43 +020011377 execute( TC_c0_power_red_mode() );
Neels Hofmeyr4f118412020-06-04 15:25:10 +020011378
11379 /* MSC pooling */
11380 /* FIXME: in SCCPlite, indicating how many MSCs should be connected does currently not work. Since
11381 * RESET->RESET-ACK is unconditionally negotiated for all configured MSCs, they always all appear as connected
11382 * to osmo-bsc. The MSC pooling tests however require disconnecting selected MSCs, and hence don't work out as
11383 * intended on SCCPlite. So for now, run these only for SCCP/M3UA. */
11384 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
11385 execute( TC_mscpool_L3Compl_on_1_msc() );
11386 execute( TC_mscpool_L3Complete_by_imsi_round_robin() );
11387 execute( TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() );
11388 execute( TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() );
11389 execute( TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() );
11390 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() );
11391 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_1() );
11392 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_2() );
11393 execute( TC_mscpool_LU_by_tmsi_from_other_PLMN() );
11394 execute( TC_mscpool_paging_and_response_imsi() );
11395 execute( TC_mscpool_paging_and_response_tmsi() );
11396 execute( TC_mscpool_no_allow_attach_round_robin() );
11397 execute( TC_mscpool_no_allow_attach_valid_nri() );
11398 }
11399
Harald Welte99f3ca02018-06-14 13:40:29 +020011400 execute( TC_early_conn_fail() );
11401 execute( TC_late_conn_fail() );
Oliver Smithaf03bef2021-08-24 15:34:51 +020011402 execute( TC_stats_conn_fail() );
Harald Welte99f3ca02018-06-14 13:40:29 +020011403
Philipp Maier783681c2020-07-16 16:47:06 +020011404 /* Emergency call handling (deny / allow) */
11405 execute( TC_assignment_emerg_setup_allow() );
11406 execute( TC_assignment_emerg_setup_deny_msc() );
11407 execute( TC_assignment_emerg_setup_deny_bts() );
Philipp Maier82812002020-08-13 18:48:27 +020011408 execute( TC_emerg_premption() );
11409
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +070011410 /* Frequency hopping parameters handling */
11411 execute( TC_fh_params_chan_activ() );
11412 execute( TC_fh_params_imm_ass() );
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +070011413 execute( TC_fh_params_assignment_cmd() );
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +070011414 execute( TC_fh_params_handover_cmd() );
Vadim Yanitskiyca974032020-09-01 07:20:39 +070011415 execute( TC_fh_params_si4_cbch() );
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020011416
11417 if (mp_enable_lcs_tests) {
11418 execute( TC_lcs_loc_req_for_active_ms() );
11419 execute( TC_lcs_loc_req_for_active_ms_ta_req() );
11420 execute( TC_lcs_loc_req_for_idle_ms() );
11421 execute( TC_lcs_loc_req_no_subscriber() );
11422 execute( TC_lcs_loc_req_for_active_ms_le_timeout() );
11423 execute( TC_lcs_loc_req_for_active_ms_le_timeout2() );
11424 execute( TC_lcs_loc_req_for_idle_ms_no_pag_resp() );
11425 execute( TC_cm_service_during_lcs_loc_req() );
11426 execute( TC_ho_during_lcs_loc_req() );
11427 }
Neels Hofmeyrbf037052020-10-28 22:52:02 +000011428
11429 execute( TC_no_msc() );
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000011430
11431 execute( TC_refuse_chan_act_to_vamos() );
11432 execute( TC_refuse_mode_modif_to_vamos() );
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000011433
11434 execute( TC_reassignment_fr() );
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020011435
11436 execute( TC_cm_reestablishment() );
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020011437
11438 execute( TC_imm_ass_post_chan_ack() );
11439 execute( TC_imm_ass_pre_chan_ack() );
Neels Hofmeyr23158742021-09-07 19:08:07 +020011440 execute( TC_imm_ass_pre_ts_ack() );
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020011441 execute( TC_imm_ass_pre_chan_ack_dyn_ts() );
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020011442 execute( TC_imm_ass_pre_ts_ack_dyn_ts() );
Neels Hofmeyr5d7d13f2021-09-07 14:44:36 +020011443
11444 execute( TC_ctrl_trx_rf_locked() );
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011445
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011446 execute( TC_ratectr_all_available_allocated() );
11447 execute( TC_ratectr_all_available_allocated_dyn() );
11448
Neels Hofmeyrb7581872021-11-07 14:02:49 +010011449 execute( TC_cm_serv_rej() );
11450
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011451 execute( TC_lost_sdcch_during_assignment() );
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +010011452
11453 /* Run TC_ho_out_of_this_bsc last, because it may trigger a segfault before osmo-bsc's patch
11454 * with change-id I5a3345ab0005a73597f5c27207480912a2f5aae6 */
11455 execute( TC_ho_out_of_this_bsc() );
Harald Welte28d943e2017-11-25 15:00:50 +010011456}
11457
11458}