blob: 0c03bde2184110884890ae8077511fd4c345f437 [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;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100598
Daniel Willmann191e0d92018-01-17 12:44:35 +0100599 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +0100600 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100601
Daniel Willmannebdecc02020-08-12 15:30:17 +0200602 /* StatsD */
603 var StatsD_Checker_CT vc_STATSD;
604
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200605 var RAN_Adapter g_bssap[NUM_MSC];
Harald Welte47cd0e32020-08-21 12:39:11 +0200606 var BSSAP_LE_Adapter g_bssap_le;
Harald Weltea4ca4462018-02-09 00:17:14 +0100607 /* for old legacy-tests only */
608 port BSSAP_CODEC_PT BSSAP;
Harald Welte47cd0e32020-08-21 12:39:11 +0200609 port BSSAP_LE_CODEC_PT BSSAP_LE;
Harald Weltea4ca4462018-02-09 00:17:14 +0100610
Harald Welte21b46bd2017-12-17 19:46:32 +0100611 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +0100612 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +0100613
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200614 /* Osmux is enabled through VTY */
615 var boolean g_osmux_enabled := false;
616
Pau Espin Pedrolc675b612020-01-09 19:55:40 +0100617 /*Configure T(tias) over VTY, seconds */
618 var integer g_bsc_sccp_timer_ias := 7 * 60;
619 /*Configure T(tiar) over VTY, seconds */
620 var integer g_bsc_sccp_timer_iar := 15 * 60;
621
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +0200622 /* global test case guard timer (actual timeout value is set in f_init()) */
Harald Welteae026692017-12-09 01:03:01 +0100623 timer T_guard := 30.0;
624
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200625 var CounterNameValsList g_ctr_msc;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000626 var CounterNameValsList g_ctr_bsc;
627 var CounterNameValsList g_ctr_bts;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200628
629 /* System Information bytes as received during RSL startup, for each RSL[idx]. */
630 var SystemInformationConfig_list g_system_information := {};
Harald Welte28d943e2017-11-25 15:00:50 +0100631}
632
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200633type record of charstring phys_chan_configs;
Harald Welte28d943e2017-11-25 15:00:50 +0100634modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +0100635 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +0100636 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100637 /* port number to which to establish the IPA OML connections */
638 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +0100639 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +0100640 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +0100641 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +0100642 integer mp_bsc_ctrl_port := 4249;
Daniel Willmannebdecc02020-08-12 15:30:17 +0200643 /* port number to which to listen for STATSD metrics */
644 integer mp_bsc_statsd_port := 8125;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100645 /* IP address at which the test binds */
646 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100647
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200648 RAN_Configurations mp_bssap_cfg := {
649 {
650 transport := BSSAP_TRANSPORT_AoIP,
651 sccp_service_type := "mtp3_itu",
652 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
653 own_pc := 185, /* 0.23.1 first MSC emulation */
654 own_ssn := 254,
655 peer_pc := 187, /* 0.23.3 osmo-bsc */
656 peer_ssn := 254,
657 sio := '83'O,
Harald Weltecb0cc432020-06-21 19:42:31 +0200658 rctx := 1
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200659 },
660 {
661 transport := BSSAP_TRANSPORT_AoIP,
662 sccp_service_type := "mtp3_itu",
663 sctp_addr := { 23906, "127.0.0.1", 2905, "127.0.0.1" },
664 own_pc := 2, /* 0.0.2 second MSC emulation */
665 own_ssn := 254,
666 peer_pc := 187, /* 0.23.3 osmo-bsc */
667 peer_ssn := 254,
668 sio := '83'O,
669 rctx := 2
670 },
671 {
672 transport := BSSAP_TRANSPORT_AoIP,
673 sccp_service_type := "mtp3_itu",
674 sctp_addr := { 23907, "127.0.0.1", 2905, "127.0.0.1" },
675 own_pc := 3, /* 0.0.3 third MSC emulation */
676 own_ssn := 254,
677 peer_pc := 187, /* 0.23.3 osmo-bsc */
678 peer_ssn := 254,
679 sio := '83'O,
680 rctx := 3
681 }
Harald Weltea4ca4462018-02-09 00:17:14 +0100682 };
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +0200683
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200684 /* Must match per BTS config in osmo-bsc.cfg */
685 phys_chan_configs phys_chan_config := {
686 "CCCH+SDCCH4+CBCH",
687 "TCH/F",
688 "TCH/F",
689 "TCH/F",
690 "TCH/F",
Vadim Yanitskiy343c9eb2021-07-16 18:36:01 +0600691 "TCH/H",
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200692 "PDCH",
693 "PDCH"
694 };
695
Harald Welte47cd0e32020-08-21 12:39:11 +0200696 BSSAP_LE_Configuration mp_bssap_le_cfg := {
697 sccp_service_type := "mtp3_itu",
698 sctp_addr := { 23908, "127.0.0.1", 2905, "127.0.0.1" },
Neels Hofmeyrac086c12020-09-18 23:46:42 +0200699 own_pc := 190, /* 0.23.6 SMLC emulation */
Harald Welte47cd0e32020-08-21 12:39:11 +0200700 own_ssn := 252, /* SMLC side SSN */
701 peer_pc := 187, /* 0.23.3 osmo-bsc */
702 peer_ssn := 250, /* BSC side SSN */
703 sio := '83'O,
704 rctx := 6
705 };
Neels Hofmeyrcfe44062020-10-15 02:28:08 +0200706 boolean mp_enable_lcs_tests := true;
Harald Welte47cd0e32020-08-21 12:39:11 +0200707
Pau Espin Pedrol8f30ccd2019-11-01 17:30:57 +0100708 /* Value set in osmo-bsc.cfg "ms max power" */
709 uint8_t mp_exp_ms_power_level := 7;
Harald Weltea4ca4462018-02-09 00:17:14 +0100710}
711
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +0200712friend function f_gen_test_hdlr_pars(integer bssap_idx := 0) return TestHdlrParams {
Philipp Maier48604732018-10-09 15:00:37 +0200713
714 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200715 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier48604732018-10-09 15:00:37 +0200716 pars.aoip := true;
717 } else {
718 pars.aoip := false;
719 }
Pau Espin Pedrol8f30ccd2019-11-01 17:30:57 +0100720 pars.exp_ms_power_level := mp_exp_ms_power_level;
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200721 pars.mscpool.bssap_idx := bssap_idx;
Neels Hofmeyrbf720202021-10-02 12:58:24 +0200722 pars.expect_tsc := BTS_TSC[0];
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200723
Philipp Maier48604732018-10-09 15:00:37 +0200724 return pars;
725}
726
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200727/* Convenience functions for rate counters using g_ctr_msc. */
728
729private function f_ctrs_msc_init(integer mscs_count := NUM_MSC, CounterNameVals counternames := counternames_msc_mscpool) runs on test_CT {
730 g_ctr_msc := f_counter_name_vals_get_n(IPA_CTRL, "msc", mscs_count, counternames);
731 log("initial msc rate counters: ", g_ctr_msc);
732}
733
734private function f_ctrs_msc_add(integer msc_nr, charstring countername, integer val := 1) runs on test_CT {
Neels Hofmeyr9656e922020-06-30 01:27:01 +0200735 f_counter_name_vals_list_add(g_ctr_msc, msc_nr, countername, val);
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200736}
737
738/* f_ctrs_msc_init();
739 * f_do_thing(on_msc := 0);
740 * f_do_thing(on_msc := 0);
741 * f_do_other(on_msc := 1);
742 * f_ctrs_msc_add(0, "thing", 2);
743 * f_ctrs_msc_add(1, "other");
744 * f_ctrs_msc_verify();
745 */
746private function f_ctrs_msc_verify() runs on test_CT {
747 log("verifying msc rate counters: ", g_ctr_msc);
748 f_counter_name_vals_expect_n(IPA_CTRL, "msc", g_ctr_msc);
749}
750
751/* convenience: f_ctrs_msc_add() and f_ctrs_msc_verify() in one call.
752 * f_ctrs_msc_init();
753 * f_do_thing(on_msc := 0);
754 * f_do_thing(on_msc := 0);
755 * f_do_thing(on_msc := 0);
756 * f_ctrs_msc_expect(0, "thing", 3);
757 */
758private function f_ctrs_msc_expect(integer msc_nr, charstring countername, integer val := 1) runs on test_CT {
759 f_ctrs_msc_add(msc_nr, countername, val);
760 f_ctrs_msc_verify();
761}
762
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000763/* Convenience functions for rate counters using g_ctr_bts, always also including g_ctr_bsc. */
764
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100765private 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 +0000766 g_ctr_bts := f_counter_name_vals_get_n(IPA_CTRL, "bts", bts_count, counternames);
Neels Hofmeyr4dec8cc2021-11-29 15:59:44 +0100767 log("initial bts rate counters: ", g_ctr_bts);
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100768}
769
770function f_ctrs_bsc_and_bts_init(integer bts_count := NUM_BTS, CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
771 f_ctrs_bts_init(bts_count, counternames);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000772 f_ctrs_bsc_init(counternames);
773}
774
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100775private function f_ctrs_bsc_and_bts_handover_init(integer bts_count := NUM_BTS) runs on test_CT {
776 var CounterNameVals bts_names := counternames_bsc_bts_handover & counternames_bts_handover;
Neels Hofmeyr4dec8cc2021-11-29 15:59:44 +0100777 f_ctrs_bts_init(bts_count, bts_names);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100778 f_ctrs_bsc_init(counternames_bsc_bts_handover);
779}
780
781private function f_ctrs_bts_add(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000782 f_counter_name_vals_list_add(g_ctr_bts, bts_nr, countername, val);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +0100783}
784
785private function f_ctrs_bsc_and_bts_add(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
786 f_ctrs_bts_add(bts_nr, countername, val);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000787 f_ctrs_bsc_add(countername, val);
788}
789
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100790function f_ctrs_bts_verify() runs on test_CT {
791 f_counter_name_vals_expect_n(IPA_CTRL, "bts", g_ctr_bts);
792}
793
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000794/* f_ctrs_bsc_and_bts_init();
795 * f_do_thing(on_bts := 0);
796 * f_do_thing(on_bts := 0);
797 * f_do_other(on_bts := 1);
798 * f_ctrs_bsc_and_bts_add(0, "thing", 2);
799 * f_ctrs_bsc_and_bts_add(1, "other");
800 * f_ctrs_bsc_and_bts_verify();
801 */
802private function f_ctrs_bsc_and_bts_verify() runs on test_CT {
Neels Hofmeyrb7581872021-11-07 14:02:49 +0100803 f_ctrs_bts_verify();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000804 f_ctrs_bsc_verify();
805}
806
807/* convenience: f_ctrs_bsc_and_bts_add() and f_ctrs_bsc_and_bts_verify() in one call.
808 * f_ctrs_bsc_and_bts_init();
809 * f_do_thing(on_bts := 0);
810 * f_do_thing(on_bts := 0);
811 * f_do_thing(on_bts := 0);
812 * f_ctrs_bsc_and_bts_expect(0, "thing", 3);
813 */
814private function f_ctrs_bsc_and_bts_expect(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
815 f_ctrs_bsc_and_bts_add(bts_nr, countername, val);
816 f_ctrs_bsc_and_bts_verify();
817}
818
819
820/* Convenience functions for rate counters using g_ctr_bsc. */
821
822private function f_ctrs_bsc_init(CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
823 g_ctr_bsc := f_counter_name_vals_get_n(IPA_CTRL, "bsc", 1, counternames);
824 log("initial bsc rate counters: ", g_ctr_bsc);
825}
826
827private function f_ctrs_bsc_add(charstring countername, integer val := 1) runs on test_CT {
828 f_counter_name_vals_list_add(g_ctr_bsc, 0, countername, val);
829}
830
831/* f_ctrs_bsc_init();
832 * f_do_thing();
833 * f_do_thing();
834 * f_do_other();
835 * f_ctrs_bsc_add("thing", 2);
836 * f_ctrs_bsc_add("other");
837 * f_ctrs_bsc_verify();
838 */
839private function f_ctrs_bsc_verify() runs on test_CT {
840 f_counter_name_vals_expect_n(IPA_CTRL, "bsc", g_ctr_bsc);
841}
842
843/* convenience: f_ctrs_bsc_add() and f_ctrs_bsc_verify() in one call.
844 * f_ctrs_bsc_init();
845 * f_do_thing();
846 * f_ctrs_bsc_expect("thing", 1);
847 */
848private function f_ctrs_bsc_expect(charstring countername, integer val := 1) runs on test_CT {
849 f_ctrs_bsc_add(countername, val);
850 f_ctrs_bsc_verify();
851}
852
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200853
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +0200854friend function f_shutdown_helper() runs on test_CT {
Daniel Willmann637ef6c2018-07-25 10:49:09 +0200855 all component.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100856 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200857 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100858}
859
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200860private function f_legacy_bssap_reset(integer bssap_idx := 0) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +0100861 var BSSAP_N_UNITDATA_ind ud_ind;
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200862 var boolean reset_received := false;
Harald Weltea4ca4462018-02-09 00:17:14 +0100863 timer T := 5.0;
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200864 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
865 ts_BSSMAP_Reset(0, g_osmux_enabled)));
Harald Weltea4ca4462018-02-09 00:17:14 +0100866 T.start;
867 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200868 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap[bssap_idx].sccp_addr_own, g_bssap[bssap_idx].sccp_addr_peer,
869 tr_BSSMAP_ResetAck(g_osmux_enabled))) {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200870 log("BSSMAP: Received RESET-ACK in response to RESET, we're ready to go!");
Harald Weltea4ca4462018-02-09 00:17:14 +0100871 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200872 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200873 log("BSSMAP: Respoding to inbound RESET with RESET-ACK");
Harald Weltea4ca4462018-02-09 00:17:14 +0100874 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200875 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200876 reset_received := true;
Harald Weltea4ca4462018-02-09 00:17:14 +0100877 repeat;
878 }
879 [] BSSAP.receive { repeat; }
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200880 [] T.timeout {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200881 log("BSSMAP: Timeout waiting for RESET-ACK after sending RESET");
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200882 /* If we received a RESET after ours was sent, it
883 may be a race condition where the other peer beacame
884 available after we sent it, but we are in a desired
885 state anyway, so go forward. */
886 if (not reset_received) {
887 setverdict(fail);
888 }
889 }
Harald Weltea4ca4462018-02-09 00:17:14 +0100890 }
Harald Welte28d943e2017-11-25 15:00:50 +0100891}
892
Harald Welteae026692017-12-09 01:03:01 +0100893type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100894 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100895 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100896 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100897 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100898 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100899 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100900 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100901 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100902}
903
Harald Welte21b46bd2017-12-17 19:46:32 +0100904/*! Start the IPA/RSL related bits for one IPA_Client.
905 * \param clnt IPA_Client for which to establish
906 * \param bsc_host IP address / hostname of the BSC
907 * \param bsc_port TCP port number of the BSC
908 * \param i number identifying this BTS
909 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100910function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
911 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100912runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100913 timer T := 10.0;
914
Harald Welte96c94412017-12-09 03:12:45 +0100915 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welteae026692017-12-09 01:03:01 +0100916 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA");
917 clnt.ccm_pars := c_IPA_default_ccm_pars;
918 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
919 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100920 if (handler_mode) {
921 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL");
Harald Welte89ab1912018-02-23 18:56:29 +0100922 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100923 }
Harald Welteae026692017-12-09 01:03:01 +0100924
925 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Harald Welte624f9632017-12-16 19:26:04 +0100926 if (handler_mode) {
927 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
928 } else {
929 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
930 }
Harald Welteae026692017-12-09 01:03:01 +0100931
Harald Welte5d1a2202017-12-13 19:51:29 +0100932 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100933 if (handler_mode) {
934 clnt.vc_RSL.start(RSL_Emulation.main());
935 return;
936 }
Harald Welteae026692017-12-09 01:03:01 +0100937
938 /* wait for IPA RSL link to connect and send ID ACK */
939 T.start;
940 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700941 [] IPA_RSL[i].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) {
Harald Welteae026692017-12-09 01:03:01 +0100942 T.stop;
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +0700943 IPA_RSL[i].send(ts_ASP_RSL_UD(ts_RSL_PAGING_LOAD_IND(23)));
Harald Welteae026692017-12-09 01:03:01 +0100944 }
Harald Welte60e823a2017-12-10 14:10:59 +0100945 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100946 [] IPA_RSL[i].receive { repeat }
947 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100948 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200949 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100950 }
951 }
952}
953
Harald Welte12055472018-03-17 20:10:08 +0100954function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
955 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
956 return;
957 }
958 clnt.vc_IPA.stop;
959 if (isbound(clnt.vc_RSL)) {
960 clnt.vc_RSL.stop;
961 }
962}
963
Harald Welte21b46bd2017-12-17 19:46:32 +0100964/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100965function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
966 timer T := secs_max;
967 T.start;
968 while (true) {
969 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
970 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100971 /* the 'degraded' state exists from OML connection time, and we have to wait
972 * until all MO's are initialized */
973 T.start(1.0);
974 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100975 return;
976 }
Harald Weltef0d6ac62017-12-17 17:02:21 +0100977 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100978 if (not T.running) {
Max99253902018-11-16 17:57:39 +0100979 setverdict(fail, "Timeout waiting for BTS" & int2str(bts_nr) & " oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +0200980 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100981 }
982 }
983}
984
Harald Welte21b46bd2017-12-17 19:46:32 +0100985/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +0100986altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +0100987 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100988 [] T_guard.timeout {
989 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +0200990 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100991 }
Harald Welte60e823a2017-12-10 14:10:59 +0100992 /* always respond with RESET ACK to RESET */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200993 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Welte60e823a2017-12-10 14:10:59 +0100994 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200995 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Welte69c1c262017-12-13 21:02:08 +0100996 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +0100997 }
Harald Welte28d943e2017-11-25 15:00:50 +0100998}
999
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001000altstep no_bssmap_reset() runs on test_CT {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001001 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001002 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +02001003 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01001004 }
1005}
1006
Daniel Willmann191e0d92018-01-17 12:44:35 +01001007function f_init_mgcp(charstring id) runs on test_CT {
1008 id := id & "-MGCP";
1009
1010 var MGCPOps ops := {
1011 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
1012 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
1013 };
1014 var MGCP_conn_parameters mgcp_pars := {
1015 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +01001016 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +01001017 mgw_ip := mp_test_ip,
Pau Espin Pedrol1a026a52019-06-18 17:21:52 +02001018 mgw_udp_port := 2427,
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02001019 /* Enable it for SCCPlite, since we have 2 MGCP sockets towards MGW (UDP one +
1020 the on with MGCP over IPA forwarded from MSC one) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001021 multi_conn_mode := (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER)
Daniel Willmann191e0d92018-01-17 12:44:35 +01001022 };
1023
1024 vc_MGCP := MGCP_Emulation_CT.create(id);
1025 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
1026}
1027
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001028/* Enable or disable (current default) Osmux. When enabling, BSSMAP Reset
1029 * contains extra IE (OsmuxSupport) and osmo-bsc will handle AssignReq with
1030 * OsmuxCID IE.
1031 */
1032private function f_vty_allow_osmux(boolean allow) runs on test_CT {
1033 f_vty_enter_cfg_msc(BSCVTY, 0);
1034 if (allow) {
1035 f_vty_transceive(BSCVTY, "osmux on");
1036 } else {
1037 f_vty_transceive(BSCVTY, "osmux off");
1038 }
1039 f_vty_transceive(BSCVTY, "exit");
1040 f_vty_transceive(BSCVTY, "exit");
1041 g_osmux_enabled := allow;
1042}
1043
Max2253c0b2018-11-06 19:28:05 +01001044function f_init_vty(charstring id := "foo") runs on test_CT {
Harald Welte94e0c342018-04-07 11:33:23 +02001045 if (BSCVTY.checkstate("Mapped")) {
1046 /* skip initialization if already executed once */
1047 return;
1048 }
Harald Weltebc03c762018-02-12 18:09:38 +01001049 map(self:BSCVTY, system:BSCVTY);
1050 f_vty_set_prompts(BSCVTY);
1051 f_vty_transceive(BSCVTY, "enable");
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01001052 f_cs7_inst_0_cfg(BSCVTY, {"sccp-timer ias " & int2str(g_bsc_sccp_timer_ias),
1053 "sccp-timer iar " & int2str(g_bsc_sccp_timer_iar)});
Harald Weltebc03c762018-02-12 18:09:38 +01001054}
1055
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +02001056friend function f_logp(TELNETasp_PT pt, charstring log_msg)
Neels Hofmeyr4f118412020-06-04 15:25:10 +02001057{
1058 // log on TTCN3 log output
1059 log(log_msg);
1060 // log in stderr log
Neels Hofmeyr767548a2020-08-09 20:26:07 +00001061 f_vty_transceive(pt, "logp lglobal notice TTCN3 f_logp(): " & log_msg);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02001062}
1063
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001064private function f_sysinfo_seen(integer rsl_idx, RSL_Message rsl) runs on test_CT
1065{
1066 if (rsl_idx >= lengthof(g_system_information)) {
1067 g_system_information[rsl_idx] := SystemInformationConfig_omit
1068 }
1069 f_sysinfo_dec_raw(g_system_information[rsl_idx], rsl);
1070}
1071
1072altstep as_catch_RSL_sysinfo(integer rsl_idx) runs on test_CT {
1073 var ASP_RSL_Unitdata rx_rsl_ud;
1074
1075 /* For handler_mode := false, receiving the RSL bootstrap messages directly on IPA_RSL */
1076 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
1077 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1078 repeat;
1079 }
1080 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
1081 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1082 repeat;
1083 }
1084 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> value rx_rsl_ud {
1085 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1086 repeat;
1087 }
1088 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_SACCH_FILL)) -> value rx_rsl_ud {
1089 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1090 repeat;
1091 }
1092
1093 /* For handler_mode := true, receiving the RSL bootstrap messages via RSL_Emulation */
1094 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
1095 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1096 repeat;
1097 }
1098 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
1099 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1100 repeat;
1101 }
1102 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> value rx_rsl_ud {
1103 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1104 repeat;
1105 }
1106 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_SACCH_FILL)) -> value rx_rsl_ud {
1107 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1108 repeat;
1109 }
1110}
1111
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001112/* TODO: use BooleanList from COMMON/src/General_Types.ttcn */
1113private type record of boolean my_BooleanList;
1114
1115private function f_vty_msc_allow_attach(TELNETasp_PT pt, my_BooleanList allow_attach_list)
1116{
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001117 var charstring config := f_vty_transceive_ret(pt, "show running-config");
1118
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001119 for (var integer msc_nr := 0; msc_nr < sizeof(allow_attach_list); msc_nr := msc_nr+1) {
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001120 if (f_strstr(config, "\nmsc " & int2str(msc_nr) & "\n") < 0) {
1121 /* There is no 'msc N' for this msc_nr in the running config, so don't create an empty msc by
1122 * stepping into that config node. */
1123 log("msc ", msc_nr, " is not configured, skipping");
1124 continue;
1125 }
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001126 f_vty_enter_cfg_msc(pt, msc_nr);
1127 if (allow_attach_list[msc_nr]) {
1128 /* strict := false: ignore if osmo-bsc does not support this config option (latest build) */
1129 f_vty_transceive(pt, "allow-attach", strict := false);
1130 } else {
1131 f_vty_transceive(pt, "no allow-attach", strict := false);
1132 }
1133 f_vty_transceive(pt, "exit");
1134 f_vty_transceive(pt, "exit");
1135 }
1136}
1137
Harald Welte21b46bd2017-12-17 19:46:32 +01001138/* global initialization function
1139 * \param nr_bts Number of BTSs we should start/bring up
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001140 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false).
1141 * \param nr_msc Number of virtual MSCs to bring up to connect to osmo-bsc.
1142 */
1143function f_init(integer nr_bts := NUM_BTS, boolean handler_mode := false, boolean allow_osmux := false,
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001144 integer nr_msc := 1, float guard_timeout := 30.0) runs on test_CT {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001145 var integer bssap_idx;
Harald Welte28d943e2017-11-25 15:00:50 +01001146
Harald Welteae026692017-12-09 01:03:01 +01001147 if (g_initialized) {
1148 return;
Harald Welte28d943e2017-11-25 15:00:50 +01001149 }
Harald Welteae026692017-12-09 01:03:01 +01001150 g_initialized := true;
1151
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001152 T_guard.start(guard_timeout);
Daniel Willmanne68f9272018-11-27 15:15:28 +01001153 activate(as_Tguard());
1154
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001155 f_init_vty("VirtMSC");
Pau Espin Pedrol23510fb2021-07-20 17:00:38 +02001156 f_vty_allow_osmux(allow_osmux);
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001157
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001158 var my_BooleanList allow_attach := { false, false, false };
Daniel Willmannebdecc02020-08-12 15:30:17 +02001159 f_init_statsd("VirtMSC", vc_STATSD, mp_test_ip, mp_bsc_statsd_port);
1160
Neels Hofmeyr9db8e0e2021-08-23 20:45:58 +02001161 /* Make sure each MSC's internal state is "DISCONNECTED" at first */
1162 for (bssap_idx := 0; bssap_idx < NUM_MSC; bssap_idx := bssap_idx+1) {
1163 f_vty_transceive(BSCVTY, "msc " & int2str(bssap_idx) & " bssmap reset", strict := false);
1164 }
1165
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001166 for (bssap_idx := 0; bssap_idx < nr_msc; bssap_idx := bssap_idx+1) {
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001167 allow_attach[bssap_idx] := true;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001168 /* Call a function of our 'parent component' RAN_Adapter_CT to start the
1169 * MSC-side BSSAP emulation */
1170 if (handler_mode) {
1171 var RanOps ranops := MSC_RanOps;
1172 ranops.use_osmux := g_osmux_enabled;
1173 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", ranops);
1174 connect(self:SCCPLITE_IPA_CTRL, g_bssap[bssap_idx].vc_RAN:CTRL_CLIENT);
1175 f_ran_adapter_start(g_bssap[bssap_idx]);
1176 } else {
1177 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", omit);
1178 connect(self:BSSAP, g_bssap[bssap_idx].vc_SCCP:SCCP_SP_PORT);
1179 f_ran_adapter_start(g_bssap[bssap_idx]);
1180 f_legacy_bssap_reset();
1181 }
Harald Welte67089ee2018-01-17 22:19:03 +01001182 }
Harald Welted5833a82018-05-27 16:52:56 +02001183
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02001184 if (mp_enable_lcs_tests) {
1185 if (handler_mode) {
1186 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", SMLC_BssapLeOps);
1187 } else {
1188 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", omit);
1189 connect(self:BSSAP_LE, g_bssap_le.vc_SCCP:SCCP_SP_PORT);
1190 }
1191 f_bssap_le_adapter_start(g_bssap_le);
Harald Welte47cd0e32020-08-21 12:39:11 +02001192 }
Harald Welte47cd0e32020-08-21 12:39:11 +02001193
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001194 /* start the test with exactly all enabled MSCs allowed to attach */
1195 f_vty_msc_allow_attach(BSCVTY, allow_attach);
1196
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01001197 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +01001198
Daniel Willmann191e0d92018-01-17 12:44:35 +01001199 f_init_mgcp("VirtMSC");
1200
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001201 for (var integer i := 0; i < nr_bts; i := i+1) {
1202 f_init_bts(i, handler_mode);
Harald Welte696ddb62017-12-08 14:01:43 +01001203 }
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001204}
Harald Welte696ddb62017-12-08 14:01:43 +01001205
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001206function f_init_bts(integer bts_idx := 0, boolean handler_mode := false)
1207runs on test_CT {
1208 /* wait until osmo-bts-omldummy has respawned */
1209 f_wait_oml(bts_idx, "degraded", 5.0);
1210
1211 /* start RSL connection */
1212 f_ipa_rsl_start(bts[bts_idx].rsl, mp_bsc_ip, mp_bsc_rsl_port, bts_idx, handler_mode);
1213 /* wait until BSC tells us "connected" */
1214 f_wait_oml(bts_idx, "connected", 5.0);
Harald Welte28d943e2017-11-25 15:00:50 +01001215}
1216
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001217function f_init_bts_and_check_sysinfo(integer bts_idx := 0, boolean handler_mode := false,
1218 template SystemInformationConfig expect_si)
1219runs on test_CT {
1220 var default sysinfo := activate(as_catch_RSL_sysinfo(bts_idx));
1221
1222 f_init_bts(bts_idx, handler_mode);
1223
1224 /* Give some time to (hopefully/most likely) collect all system informations from RSL startup.
1225 * We could stop as soon as all expected SI are received, but then we might miss SI that we don't expect and
1226 * that might be sent afterwards. So rather give a generous timeout and be quite sure to catch all SI.
1227 */
1228 f_sleep(5.0);
1229 log("RSL ", bts_idx, " SYSTEM INFORMATION: ", g_system_information[bts_idx]);
1230
1231 deactivate(sysinfo);
1232
1233 if (match(g_system_information[bts_idx], expect_si)) {
1234 setverdict(pass);
1235 } else {
1236 log("RSL ", bts_idx, ": EXPECTED SI: ", expect_si);
1237 log("RSL ", bts_idx, ": GOT SI: ", g_system_information[bts_idx]);
1238 setverdict(fail, "received SI does not match expectations");
1239 return;
1240 }
1241}
1242
Maxd4e56962018-10-31 19:08:25 +01001243/* expect to receive a RSL message matching a specified template on a given BTS / stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001244function 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 +01001245runs on test_CT return RSL_Message {
1246 var ASP_RSL_Unitdata rx_rsl_ud;
1247 timer T := t_secs;
1248
1249 T.start;
1250 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001251 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
Harald Welteae026692017-12-09 01:03:01 +01001252 T.stop;
1253 }
1254 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +01001255 [] T.timeout {
1256 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +02001257 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +01001258 }
Harald Welteae026692017-12-09 01:03:01 +01001259 }
1260 return rx_rsl_ud.rsl;
1261}
1262
Harald Welte21b46bd2017-12-17 19:46:32 +01001263/* helper function to transmit RSL on a given BTS/stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001264function 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 +01001265runs on test_CT {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001266 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(t_tx, sid));
Harald Welteae026692017-12-09 01:03:01 +01001267}
1268
1269
Harald Welte4003d112017-12-09 22:35:39 +01001270/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +01001271testcase TC_chan_act_noreply() runs on test_CT {
1272 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +01001273 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +01001274
Harald Welte89d42e82017-12-17 16:42:41 +01001275 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +01001276
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001277 IPA_RSL[0].send(ts_ASP_RSL_UD(ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +01001278 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001279 f_shutdown_helper();
Harald Welte28d943e2017-11-25 15:00:50 +01001280}
1281
Neels Hofmeyr734b1a32021-11-29 16:00:17 +01001282const CounterNameVals counternames_bts_chreq := {
1283 { "chreq:total", 0 },
1284 { "chreq:attempted_emerg", 0 },
1285 { "chreq:attempted_call", 0 },
1286 { "chreq:attempted_location_upd", 0 },
1287 { "chreq:attempted_pag", 0 },
1288 { "chreq:attempted_pdch", 0 },
1289 { "chreq:attempted_other", 0 },
1290 { "chreq:attempted_unknown", 0 },
1291 { "chreq:successful", 0 },
1292 { "chreq:successful_emerg", 0 },
1293 { "chreq:successful_call", 0 },
1294 { "chreq:successful_location_upd", 0 },
1295 { "chreq:successful_pag", 0 },
1296 { "chreq:successful_pdch", 0 },
1297 { "chreq:successful_other", 0 },
1298 { "chreq:successful_unknown", 0 },
1299 { "chreq:no_channel", 0 },
1300 { "chreq:max_delay_exceeded", 0 }
1301};
1302
1303/* verify the "chreq:*" counters */
1304private function f_chan_act_counter(OCT1 ra, charstring chreq_ctr_suffix) runs on test_CT
1305{
1306 var GsmFrameNumber fn := 23;
1307
1308 f_logp(BSCVTY, "f_chan_act_counter(" & chreq_ctr_suffix & ")");
1309
1310 var RSL_Message rx_rsl;
1311 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1312 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1313 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1314
1315 f_ctrs_bts_add(0, "chreq:total");
1316 f_ctrs_bts_add(0, "chreq:attempted_" & chreq_ctr_suffix);
1317 f_ctrs_bts_verify();
1318
1319 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
1320 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
1321
1322 f_ctrs_bts_add(0, "chreq:successful");
1323 f_ctrs_bts_add(0, "chreq:successful_" & chreq_ctr_suffix);
1324 f_ctrs_bts_verify();
1325
1326 /* test is done, release RSL Conn Fail Ind to clean up */
1327 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1328 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1329 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
1330 f_sleep(1.0);
1331}
1332
Harald Welte4003d112017-12-09 22:35:39 +01001333testcase TC_chan_act_counter() runs on test_CT {
1334 var BSSAP_N_UNITDATA_ind ud_ind;
1335 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +01001336 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +01001337
Harald Welte89d42e82017-12-17 16:42:41 +01001338 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001339
Neels Hofmeyr734b1a32021-11-29 16:00:17 +01001340 f_vty_allow_emerg_bts(true, 0);
1341
1342 f_ctrs_bts_init(1, counternames_bts_chreq);
1343
1344 /* emergency call: RA & 0xe0 == 0xa0 --> CHREQ_T_EMERG_CALL */
1345 f_chan_act_counter('a3'O, "emerg");
1346
1347 /* voice TCH/H: RA & 0xf0 == 0x40 --> CHREQ_T_VOICE_CALL_TCH_H */
1348 f_chan_act_counter('43'O, "call");
1349
1350 /* LU: RA & 0xf0 == 0x00 --> CHREQ_T_LOCATION_UPD */
1351 f_chan_act_counter('03'O, "location_upd");
1352
1353 /* Paging: RA & 0xf0 == 0x20 --> CHREQ_T_PAG_R_TCH_F */
1354 f_chan_act_counter('23'O, "pag");
1355 /* Paging: RA & 0xf0 == 0x30 --> CHREQ_T_PAG_R_TCH_FH */
1356 f_chan_act_counter('33'O, "pag");
1357
1358 /* LU: RA & 0xfc == 0x78 --> CHREQ_T_PDCH_TWO_PHASE */
1359 /* no PCU, so PDCH not allowed. Skip this test for now. */
1360 /* f_chan_act_counter('7b'O, "pdch"); */
1361
1362 /* LU: RA & 0xf0 == 0x10 --> CHREQ_T_SDCCH */
1363 f_chan_act_counter('13'O, "other");
Harald Welte4003d112017-12-09 22:35:39 +01001364
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001365 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001366}
1367
Harald Welteae026692017-12-09 01:03:01 +01001368/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
Philipp Maier9c60a622020-07-09 15:08:46 +02001369private function f_TC_chan_act_ack_noest(OCT1 ra := '23'O) runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +01001370 var RSL_Message rx_rsl;
1371
Harald Welteae026692017-12-09 01:03:01 +01001372 /* Send CHAN RQD and wait for allocation; acknowledge it */
Philipp Maier9c60a622020-07-09 15:08:46 +02001373 var RslChannelNr chan_nr := f_chreq_act_ack(ra);
Harald Welteae026692017-12-09 01:03:01 +01001374
1375 /* expect BSC to disable the channel again if there's no RLL EST IND */
1376 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1377
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001378 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001379}
1380
Philipp Maier9c60a622020-07-09 15:08:46 +02001381/* Normal variant */
1382testcase TC_chan_act_ack_noest() runs on test_CT {
Philipp Maieraf58db22020-08-12 17:24:40 +02001383 f_init(1);
Philipp Maier9c60a622020-07-09 15:08:46 +02001384 f_TC_chan_act_ack_noest();
1385}
1386
1387/* Emergency call variant */
1388testcase TC_chan_act_ack_noest_emerg() runs on test_CT {
1389 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
Philipp Maieraf58db22020-08-12 17:24:40 +02001390 f_init(1);
1391 f_vty_allow_emerg_bts(true, 0);
Philipp Maier9c60a622020-07-09 15:08:46 +02001392 f_TC_chan_act_ack_noest(ra := 'A5'O);
1393}
1394
Philipp Maier606f07d2020-08-12 17:21:58 +02001395/* Emergency call variant, but emergency calls are not allowed */
1396testcase TC_chan_rqd_emerg_deny() runs on test_CT {
1397 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
1398
1399 var RSL_Message rx_rsl;
1400 var GsmRrMessage rr;
1401
1402 f_init(1);
1403 f_vty_allow_emerg_bts(false, 0);
1404
1405 IPA_RSL[0].clear;
1406 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
1407
1408 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
1409 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
1410 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1411 setverdict(pass);
1412 } else {
1413 setverdict(fail, "immediate assignment not rejected");
1414 }
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01001415
1416 f_shutdown_helper();
Philipp Maier606f07d2020-08-12 17:21:58 +02001417}
1418
Harald Welteae026692017-12-09 01:03:01 +01001419/* Test behavior if MSC never answers to CR */
1420testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +01001421 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
1422 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +01001423 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +01001424 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +01001425
Harald Welte89d42e82017-12-17 16:42:41 +01001426 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001427
1428 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001429 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001430
1431 var octetstring l3 := '00010203040506'O
1432 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1433
1434 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
1435
1436 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +01001437 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001438 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001439 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001440}
1441
1442/* Test behavior if MSC answers with CREF to CR */
1443testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
1444 var BSSAP_N_CONNECT_ind rx_c_ind;
1445 var RSL_Message rx_rsl;
1446
Harald Welte89d42e82017-12-17 16:42:41 +01001447 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001448
1449 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001450 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001451
1452 var octetstring l3 := '00010203040506'O
1453 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1454
1455 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1456 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
1457
1458 /* expect BSC to disable the channel */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001459 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001460 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001461}
1462
Harald Welte618ef642017-12-14 14:58:20 +01001463/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
1464testcase TC_chan_act_nack() runs on test_CT {
1465 var RSL_Message rx_rsl;
1466 var integer chact_nack;
1467
Harald Welte89d42e82017-12-17 16:42:41 +01001468 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +01001469
1470 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
1471
1472 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
1473 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1474 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1475
1476 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
1477
1478 /* wait for some time to hope the NACK arrives before the CTRL GET below */
1479 f_sleep(0.5);
1480
1481 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
1482
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001483 f_shutdown_helper();
Harald Welte618ef642017-12-14 14:58:20 +01001484}
1485
Harald Welte799c97b2017-12-14 17:50:30 +01001486/* Test for channel exhaustion due to RACH overload */
1487testcase TC_chan_exhaustion() runs on test_CT {
1488 var ASP_RSL_Unitdata rsl_ud;
1489 var integer i;
1490 var integer chreq_total, chreq_nochan;
1491
Harald Welte89d42e82017-12-17 16:42:41 +01001492 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +01001493
1494 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
1495 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
1496
Neels Hofmeyr85fa37f2021-10-06 13:50:38 +02001497 /* GSM 44.018 Table 9.1.8.2:
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +01001498 * RA = '33'O -> Establishment cause = 0011xxxx (MS dual rate capable and asks for "TCH/H or TCH/F").
1499 * With current setup, expect 4xSDCCH + 4xTCH/F + 1xTCH/H to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +02001500 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 +01001501 var RslChannelNr chan_nr := f_chreq_act_ack('33'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +01001502 }
1503
1504 IPA_RSL[0].clear;
1505
Harald Weltedd8cbf32018-01-28 12:07:52 +01001506 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001507 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +01001508
1509 /* now expect additional channel activations to fail */
1510 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
1511
1512 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001513 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
Harald Welte799c97b2017-12-14 17:50:30 +01001514 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
1515 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001516 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
Harald Welte799c97b2017-12-14 17:50:30 +01001517 var GsmRrMessage rr;
1518 /* match on IMM ASS REJ */
1519 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
1520 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1521 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001522 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +01001523 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
1524 chreq_nochan+1);
1525 setverdict(pass);
1526 } else {
1527 repeat;
1528 }
1529 }
1530 [] IPA_RSL[0].receive { repeat; }
1531 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001532 f_shutdown_helper();
Harald Welte799c97b2017-12-14 17:50:30 +01001533}
1534
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001535/* Test channel deactivation due to silence from MS */
1536testcase TC_chan_deact_silence() runs on test_CT {
1537 var RslChannelNr chan_nr;
1538
1539 f_init(1);
1540
1541 /* Request for a dedicated channel */
1542 chan_nr := f_chreq_act_ack('23'O);
1543
1544 /* Wait some time until the channel is released */
1545 f_sleep(2.0);
1546
1547 /* Expect CHANnel RELease */
1548 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001549 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001550 log("Received CHANnel RELease");
1551 setverdict(pass);
1552 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001553 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001554 /* See OS#3709, OsmoBSC should not send Immediate
1555 * Assignment Reject since a dedicated channel was
1556 * already allocated, and Immediate Assignment was
1557 * already sent. */
1558 setverdict(fail, "Unexpected Immediate Assignment!");
1559 }
1560 [] IPA_RSL[0].receive {
1561 setverdict(fail, "Unexpected RSL message!");
1562 }
1563 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001564 f_shutdown_helper();
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001565}
1566
Harald Weltecfe2c962017-12-15 12:09:32 +01001567/***********************************************************************
1568 * Assignment Testing
1569 ***********************************************************************/
1570
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001571/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction,
1572 * except for the inter-BSC handover, MT side) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001573testcase TC_outbound_connect(integer bssap_idx := 0) runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +01001574 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +01001575
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001576 BSSAP.send(ts_BSSAP_CONNECT_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
1577 2342, ts_BSSMAP_AssignmentReq));
Harald Weltecfe2c962017-12-15 12:09:32 +01001578 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001579 f_shutdown_helper();
Harald Weltecfe2c962017-12-15 12:09:32 +01001580}
1581
Harald Welte16a4adf2017-12-14 18:54:01 +01001582/* Test behavior if MSC answers with CREF to CR */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001583testcase TC_assignment_cic_only(integer bssap_idx := 0) runs on test_CT {
Harald Welte16a4adf2017-12-14 18:54:01 +01001584 var BSSAP_N_CONNECT_ind rx_c_ind;
1585 var RSL_Message rx_rsl;
1586 var DchanTuple dt;
1587
Harald Welte89d42e82017-12-17 16:42:41 +01001588 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +01001589
1590 dt := f_est_dchan('23'O, 23, '00000000'O);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001591 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte17b27da2018-05-25 20:33:53 +02001592 /* send assignment without AoIP IEs */
1593 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
1594 } else {
1595 /* Send assignmetn without CIC in IPA case */
1596 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
1597 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
1598 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
1599 }
Harald Welte16a4adf2017-12-14 18:54:01 +01001600 alt {
1601 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1602 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
1603 }
Harald Welte235ebf12017-12-15 14:18:16 +01001604 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +01001605 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1606 setverdict(pass);
1607 }
1608 [] BSSAP.receive { repeat; }
1609 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001610 f_shutdown_helper();
Harald Welte16a4adf2017-12-14 18:54:01 +01001611}
1612
Harald Welteed848512018-05-24 22:27:58 +02001613/* generate an assignment request for either AoIP or SCCPlite */
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001614function 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 +02001615 var PDU_BSSAP ass_cmd;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001616 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001617 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welteed848512018-05-24 22:27:58 +02001618 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001619 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001620 if (osmux_enabled) {
1621 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla, osmux_cid));
1622 } else {
1623 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
1624 }
Harald Welteed848512018-05-24 22:27:58 +02001625 } else {
1626 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001627 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
Harald Welteed848512018-05-24 22:27:58 +02001628 }
1629 return ass_cmd;
1630}
1631
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02001632function f_gen_handover_req(integer bssap_idx := 0, charstring aoip_tla := "1.2.3.4",
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001633 template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit,
1634 template (omit) TestHdlrEncrParams enc := omit) return PDU_BSSAP {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001635 var PDU_BSSAP ho_req;
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001636
1637 var BSSMAP_IE_EncryptionInformation encryptionInformation :=
1638 valueof(ts_BSSMAP_IE_EncrInfo('0000000000000000'O,'01'O));
1639 var template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm := omit;
1640 var template BSSMAP_IE_KC128 kc128 := omit;
1641 if (ispresent(enc)) {
1642 var TestHdlrEncrParams v_enc := valueof(enc);
1643 encryptionInformation := valueof(ts_BSSMAP_IE_EncrInfo(v_enc.enc_key, v_enc.enc_alg));
1644 chosenEncryptionAlgorithm := valueof(
1645 ts_BSSMAP_IE_ChosenEncryptionAlgorithm(int2oct(enum2int(
Oliver Smith598e1ed2021-07-09 10:28:40 +02001646 f_cipher_mode_bssmap_to_rsl(v_enc.enc_alg)), 1)));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001647 if (ispresent(v_enc.enc_kc128)) {
1648 kc128 := ts_BSSMAP_IE_Kc128(v_enc.enc_kc128);
1649 }
1650 }
1651
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001652 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001653 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001654 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001655 ho_req := valueof(ts_BSSMAP_HandoverRequest(omit, tla, oldToNewBSSIEs := oldToNewBSSIEs,
1656 encryptionInformation := encryptionInformation,
1657 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
1658 kC128 := kc128));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001659 } else {
1660 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001661 ho_req := valueof(ts_BSSMAP_HandoverRequest(cic, omit, oldToNewBSSIEs := oldToNewBSSIEs,
1662 encryptionInformation := encryptionInformation,
1663 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
1664 kC128 := kc128));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001665 }
1666 return ho_req;
1667}
1668
Harald Welteed848512018-05-24 22:27:58 +02001669/* generate an assignment complete template for either AoIP or SCCPlite */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001670function f_gen_exp_compl(boolean expect_osmux := false, integer bssap_idx := 0) return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +02001671 var template PDU_BSSAP exp_compl;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001672 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001673 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001674 if (expect_osmux) {
1675 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, osmux_cid);
1676 } else {
1677 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, omit);
1678 }
Harald Welteed848512018-05-24 22:27:58 +02001679 } else {
1680 /* CIC is optional "*" as the MSC allocated it */
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001681 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
Harald Welteed848512018-05-24 22:27:58 +02001682 }
1683 return exp_compl;
1684}
1685
Harald Welte235ebf12017-12-15 14:18:16 +01001686/* Run everything required up to sending a caller-specified assignment command and expect response */
1687function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
1688runs on test_CT {
1689 var BSSAP_N_CONNECT_ind rx_c_ind;
1690 var RSL_Message rx_rsl;
1691 var DchanTuple dt;
1692
Harald Welte89d42e82017-12-17 16:42:41 +01001693 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +01001694
1695 dt := f_est_dchan('23'O, 23, '00000000'O);
1696 /* send assignment without AoIP IEs */
1697 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
1698 alt {
1699 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1700 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
1701 setverdict(pass);
1702 } else {
1703 setverdict(fail, fail_text);
1704 }
1705 }
1706 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1707 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
1708 setverdict(pass);
1709 } else {
1710 setverdict(fail, fail_text);
1711 }
1712 }
1713 [] BSSAP.receive { repeat; }
1714 }
1715}
1716testcase TC_assignment_csd() runs on test_CT {
1717 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001718 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001719 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1720 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
1721 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001722 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001723}
1724
1725testcase TC_assignment_ctm() runs on test_CT {
1726 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001727 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001728 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
1729 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
1730 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001731 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001732}
1733
Harald Welte4003d112017-12-09 22:35:39 +01001734type record DchanTuple {
1735 integer sccp_conn_id,
1736 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +01001737}
1738
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +02001739type record of DchanTuple DchanTuples;
1740
Harald Welted6939652017-12-13 21:02:46 +01001741/* Send CHAN RQD and wait for allocation; acknowledge it */
1742private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
1743runs on test_CT return RslChannelNr {
1744 var RSL_Message rx_rsl;
1745 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1746 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1747 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1748 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
Daniel Willmannf4ac4ce2018-08-02 14:06:30 +02001749 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Harald Welted6939652017-12-13 21:02:46 +01001750 return chan_nr;
1751}
1752
Harald Welte4003d112017-12-09 22:35:39 +01001753/* helper function to establish a dedicated channel via BTS and MSC */
1754function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1755runs on test_CT return DchanTuple {
1756 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +01001757 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001758
Harald Welte4003d112017-12-09 22:35:39 +01001759 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001760 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +01001761
1762 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1763
1764 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1765 dt.sccp_conn_id := rx_c_ind.connectionId;
1766 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1767
1768 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001769}
1770
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02001771/* Like f_est_dchan(), but for the first lchan of a dynamic timeslot: first ACK the deactivation of PDCH. */
1772function f_est_dchan_dyn(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1773runs on test_CT return DchanTuple {
1774 var BSSAP_N_CONNECT_ind rx_c_ind;
1775 var DchanTuple dt;
1776
1777 /* Send CHAN RQD */
1778 var RSL_Message rx_rsl;
1779 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1780
1781 /* The dyn TS first deactivates PDCH */
1782 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1783 dt.rsl_chan_nr := rx_rsl.ies[0].body.chan_nr;
1784 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1785
1786 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1787 dt.rsl_chan_nr := rx_rsl.ies[0].body.chan_nr;
1788
1789 /* Now activates the signalling channel */
1790 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, fn+10));
1791 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
1792
1793 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1794
1795 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1796 dt.sccp_conn_id := rx_c_ind.connectionId;
1797 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1798
1799 return dt;
1800}
1801
Harald Welte641fcbe2018-06-14 10:58:35 +02001802/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
1803private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
1804 var RSL_Message rx_rsl;
1805 /* expect BSC to disable the channel */
1806 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1807 /* respond with CHAN REL ACK */
1808 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1809
1810 /* expect Clear Complete from BSC */
1811 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1812
1813 /* MSC disconnects as instructed. */
1814 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1815}
1816
Harald Welte4003d112017-12-09 22:35:39 +01001817/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
1818testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001819 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001820 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +01001821
Harald Welte89d42e82017-12-17 16:42:41 +01001822 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +01001823
Harald Welte4003d112017-12-09 22:35:39 +01001824 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1825
1826 /* simulate RLL REL IND */
1827 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
1828
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001829 /* expect Clear Request on MSC side */
1830 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1831
1832 /* Instruct BSC to clear channel */
1833 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1834 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1835
Harald Welte4003d112017-12-09 22:35:39 +01001836 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001837 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001838
1839 /* wait for SCCP emulation to do its job */
1840 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +01001841
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001842 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001843}
1844
1845/* Test behavior of channel release after CONN FAIL IND from BTS */
1846testcase TC_chan_rel_conn_fail() runs on test_CT {
1847 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001848 var DchanTuple dt;
1849
Harald Welte89d42e82017-12-17 16:42:41 +01001850 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001851
1852 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1853
1854 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +01001855 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 +01001856 /* TODO: different cause values? */
1857
Harald Welte4003d112017-12-09 22:35:39 +01001858 /* expect Clear Request from BSC */
1859 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1860
1861 /* Instruct BSC to clear channel */
1862 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1863 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1864
Harald Welte6ff76ea2018-01-28 13:08:01 +01001865 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001866 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +01001867
1868 /* wait for SCCP emulation to do its job */
1869 f_sleep(1.0);
1870
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001871 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001872}
1873
Harald Welte99f3ca02018-06-14 13:40:29 +02001874/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
1875/* See also https://www.osmocom.org/issues/3182 */
1876testcase TC_early_conn_fail() runs on test_CT {
1877 var RSL_Message rx_rsl;
1878 var DchanTuple dt;
1879
1880 f_init(1);
1881
1882 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
Harald Weltec46ea3c2020-10-10 18:46:12 +02001883 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_ra_cs(), 23);
Harald Welte99f3ca02018-06-14 13:40:29 +02001884
1885 /* BTS->BSC: simulate CONN FAIL IND */
1886 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1887
1888 /* BTS->BSC: Expect RF channel release from BSC on Abis */
1889 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1890
1891 /* BTS<-BSC: respond with CHAN REL ACK */
1892 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1893
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001894 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001895}
1896
1897/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
1898/* See also https://www.osmocom.org/issues/3182 */
1899testcase TC_late_conn_fail() runs on test_CT {
1900 var RSL_Message rx_rsl;
1901 var DchanTuple dt;
1902
1903 f_init(1);
1904
1905 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1906
1907 /* BSC<-MSC: Instruct BSC to clear connection */
1908 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
1909
1910 /* BTS->BSC: expect BSC to deactivate SACCH */
1911 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
1912
1913 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
1914 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1915
1916 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
1917 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1918 /* BTS->BSC: respond with CHAN REL ACK */
1919 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1920
1921 /* BSC->MSC: expect Clear Complete from BSC */
1922 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1923
1924 /* BSC<-MSC: MSC disconnects as requested. */
1925 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1926
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001927 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001928}
1929
Oliver Smithaf03bef2021-08-24 15:34:51 +02001930private function f_TC_stats_conn_fail(charstring id) runs on MSC_ConnHdlr {
1931 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
1932 var PDU_BSSAP ass_cmd := f_gen_ass_req();
1933
1934 f_statsd_reset();
1935
1936 /* Establish SDCCH */
1937 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1938 f_establish_fully(ass_cmd, exp_fail);
1939
1940 /* Expect stats to be 0 */
1941 var StatsDExpects expect := {
1942 {name := "TTCN3.bts.0.chan.rf_fail", mtype := "c", min := 0, max := 0},
1943 {name := "TTCN3.bts.0.chan.rf_fail_sdcch", mtype := "c", min := 0, max := 0}
1944 };
1945 f_statsd_expect(expect);
1946
1947 /* Simulate CONN FAIL IND on SDCCH */
1948 RSL.send(ts_ASP_RSL_UD(
1949 ts_RSL_CONN_FAIL_IND(g_chan_nr, RSL_ERR_RADIO_LINK_FAIL),
1950 IPAC_PROTO_RSL_TRX0));
1951
Neels Hofmeyr58be48a2021-09-07 18:39:21 +02001952 f_sleep(1.0);
1953
Oliver Smithaf03bef2021-08-24 15:34:51 +02001954 /* Expect stats to be 1 */
1955 expect := {
1956 {name := "TTCN3.bts.0.chan.rf_fail", mtype := "c", min := 1, max := 1},
1957 {name := "TTCN3.bts.0.chan.rf_fail_sdcch", mtype := "c", min := 1, max := 1}
1958 };
1959 f_statsd_expect(expect);
1960}
1961testcase TC_stats_conn_fail() runs on test_CT {
1962 var TestHdlrParams pars := f_gen_test_hdlr_pars();
1963 var MSC_ConnHdlr vc_conn;
1964
1965 f_init(1, true);
1966 f_sleep(1.0);
1967
1968 vc_conn := f_start_handler(refers(f_TC_stats_conn_fail), pars);
1969 vc_conn.done;
1970
1971 f_shutdown_helper();
1972}
1973
Neels Hofmeyrf44ccd12018-11-05 19:15:23 +01001974function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr,
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001975 boolean expect_deact_sacch := true,
1976 boolean expect_rr_chan_rel := true,
1977 boolean expect_rll_rel_req := true,
Harald Welte99787102019-02-04 10:41:36 +01001978 boolean handle_rll_rel := true,
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02001979 template CellSelIndValue expect_cells := omit,
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001980 template RR_Cause expect_rr_cause := ?
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001981 ) runs on test_CT {
Harald Welte91d54a52018-01-28 15:35:07 +01001982
1983 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001984 var boolean got_deact_sacch := false;
1985 var boolean got_rr_chan_rel := false;
1986 var boolean got_rll_rel_req := false;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02001987 var ASP_RSL_Unitdata ud;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001988 var RSL_IE_Body l3_ie;
1989 var PDU_ML3_NW_MS l3;
1990 var RR_Cause got_cause;
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001991 log("f_expect_chan_rel() expecting: expect_deact_sacch=", expect_deact_sacch, " expect_rr_chan_rel=", expect_rr_chan_rel,
1992 " expect_rll_rel_req=", expect_rll_rel_req);
Harald Welte91d54a52018-01-28 15:35:07 +01001993 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001994 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001995 got_deact_sacch := true;
Harald Welte91d54a52018-01-28 15:35:07 +01001996 repeat;
1997 }
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02001998 [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 +01001999 got_rr_chan_rel := true;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002000
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002001 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
2002 setverdict(fail, "cannot find L3");
2003 mtc.stop;
2004 }
2005 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
2006
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002007 if (not istemplatekind(expect_cells, "omit")) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002008 var CellSelIndValue cells := dec_CellSelIndValue(
2009 l3.msgs.rrm.channelRelease.cellSelectionIndicator.cellSelectionIndicatorValue);
2010
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002011 log("GOT RR CHANNEL RELEASE WITH CELLS: ", cells);
2012 if (match(cells, expect_cells)) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002013 setverdict(pass);
2014 } else {
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02002015 log("EXPECTED CELLS: ", expect_cells);
2016 setverdict(fail, "Received cells list on RR Channel Release does not match expectations");
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002017 }
2018 }
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002019
2020 if (not istemplatekind(expect_rr_cause, "omit")) {
2021 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
2022 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
2023 if (match(got_cause, expect_rr_cause)) {
2024 setverdict(pass);
2025 } else {
2026 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
2027 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
2028 }
2029 }
Harald Welte99787102019-02-04 10:41:36 +01002030 repeat;
2031 }
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002032 [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 +01002033 got_rr_chan_rel := true;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002034
2035 if (not istemplatekind(expect_rr_cause, "omit")) {
2036 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
2037 setverdict(fail, "cannot find L3");
2038 mtc.stop;
2039 }
2040 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
2041
2042 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
2043 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
2044 if (match(got_cause, expect_rr_cause)) {
2045 setverdict(pass);
2046 } else {
2047 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
2048 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
2049 }
2050 }
Neels Hofmeyr211169d2018-11-07 00:37:29 +01002051 repeat;
2052 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002053 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002054 got_rll_rel_req := true;
Harald Welte91d54a52018-01-28 15:35:07 +01002055 /* FIXME: Why are we getting this for LinkID SACCH? */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002056 if (handle_rll_rel) {
2057 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
2058 }
Harald Welte91d54a52018-01-28 15:35:07 +01002059 repeat;
2060 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002061 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Harald Welte91d54a52018-01-28 15:35:07 +01002062 /* respond with CHAN REL ACK */
2063 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
2064 }
2065 /* ignore any user data */
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002066 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeR(?))) {
Harald Welte91d54a52018-01-28 15:35:07 +01002067 repeat;
2068 }
2069 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002070
2071 log("f_expect_chan_rel() summary: got_deact_sacch=", got_deact_sacch, " got_rr_chan_rel=", got_rr_chan_rel,
2072 " got_rll_rel_req=", got_rll_rel_req);
2073
2074 if (expect_deact_sacch != got_deact_sacch) {
2075 setverdict(fail, "f_expect_chan_rel(): expect_deact_sacch=", expect_deact_sacch, " got_deact_sacch=", got_deact_sacch);
2076 }
2077 if (expect_rr_chan_rel != got_rr_chan_rel) {
2078 setverdict(fail, "f_expect_chan_rel(): expect_rr_chan_rel=", expect_rr_chan_rel, " got_rr_chan_rel=", got_rr_chan_rel);
2079 }
2080 if (expect_rll_rel_req != got_rll_rel_req) {
2081 setverdict(fail, "f_expect_chan_rel(): expect_rll_rel_req=", expect_rll_rel_req, " got_rll_rel_req=", got_rll_rel_req);
2082 }
Harald Welte91d54a52018-01-28 15:35:07 +01002083}
2084
Harald Welte4003d112017-12-09 22:35:39 +01002085/* Test behavior of channel release after hard Clear Command from MSC */
2086testcase TC_chan_rel_hard_clear() runs on test_CT {
2087 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01002088 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +01002089
Harald Welte89d42e82017-12-17 16:42:41 +01002090 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002091
2092 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2093
2094 /* Instruct BSC to clear channel */
2095 var BssmapCause cause := 0;
2096 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2097
2098 /* expect Clear Complete from BSC on A */
2099 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2100 /* release the SCCP connection */
2101 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2102 }
2103
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002104 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002105 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002106}
2107
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002108function f_TC_chan_rel_last_eutran_plmn_hard_clear(boolean tx_csfb_ind) runs on test_CT {
2109 var BSSAP_N_DATA_ind rx_di;
2110 var DchanTuple dt;
2111
2112 f_init(1);
2113
2114 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2115 /* Send CommonID with some random PLMN (BSC doesn't take it into account
2116 /* yet when generating the EUTRAN neigh list in RR CHannel Release) */
2117 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
2118
2119 /* Instruct BSC to clear channel */
2120 var BssmapCause cause := 0;
2121 if (tx_csfb_ind) {
2122 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2123 } else {
2124 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
2125 }
2126
2127 /* expect Clear Complete from BSC on A */
2128 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2129 /* release the SCCP connection */
2130 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2131 }
2132
2133 /* 1 neighbor is added by default in osmo-bts.cfg and
2134 SystemInformationConfig_default, use that: */
2135 var template CellSelIndValue exp_cells := f_tr_rr_chan_rel_earfcns(1);
2136
2137 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, expect_cells := exp_cells);
2138 f_shutdown_helper();
2139}
2140
2141/* Test behavior of RR Channel rRelease after Clear Command without CSFB indicator
2142 from MSC, previously receiving any CommonID containing the "Last Used E-UTRAN
2143 PLMN Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
2144 EUTRAN neighbor list sent later on by BSC in RR Channel, so receiving CSFB
2145 Indicator or not shouldn't matter at all. */
2146testcase TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() runs on test_CT {
2147 f_TC_chan_rel_last_eutran_plmn_hard_clear(false);
2148}
2149
2150/* Test behavior of RR Channel rRelease after Clear Command with CSFB indicator from
2151 MSC, previously receiving any CommonID containing the "Last Used E-UTRAN PLMN
2152 Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
2153 EUTRAN neighbor list sent later on by BSC in RR Channel. */
2154testcase TC_chan_rel_last_eutran_plmn_hard_clear_csfb() runs on test_CT {
2155 f_TC_chan_rel_last_eutran_plmn_hard_clear(true);
2156}
2157
2158/* Test behavior of RR Channel Release after Clear Command with CSFB indicator from
2159 MSC, without receiving any CommonID containing the "Last Used E-UTRAN PLMN
2160 Id". According to spec (TS 48.008 version 16.0.0 Release 16 "3.2.1.21") the
2161 CSFB Indicator should not be used anymore, and hence, there should be no
2162 EUTRAN neighbor list sent by BSC in RR Channel release since no CommonId with
2163 Last Used E-UTRAN PLMN Id" IE was sent for this conn. */
Harald Welte99787102019-02-04 10:41:36 +01002164testcase TC_chan_rel_hard_clear_csfb() runs on test_CT {
2165 var BSSAP_N_DATA_ind rx_di;
2166 var DchanTuple dt;
2167
2168 f_init(1);
2169
2170 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2171
2172 /* Instruct BSC to clear channel */
2173 var BssmapCause cause := 0;
2174 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2175
2176 /* expect Clear Complete from BSC on A */
2177 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2178 /* release the SCCP connection */
2179 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2180 }
2181
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002182 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002183 f_shutdown_helper();
Harald Welte99787102019-02-04 10:41:36 +01002184}
2185
Harald Welted8c36cd2017-12-09 23:05:31 +01002186/* Test behavior of channel release after hard RLSD from MSC */
2187testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +01002188 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +01002189
Harald Welte89d42e82017-12-17 16:42:41 +01002190 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +01002191
2192 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2193
2194 /* release the SCCP connection */
2195 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2196
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002197 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002198 f_shutdown_helper();
Harald Welted8c36cd2017-12-09 23:05:31 +01002199}
2200
Harald Welte550daf92018-06-11 19:22:13 +02002201/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
2202testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
2203 var DchanTuple dt;
2204
2205 f_init(1);
2206
2207 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2208
2209 /* release the SCCP connection */
2210 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2211
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002212 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002213 f_shutdown_helper();
Harald Welte550daf92018-06-11 19:22:13 +02002214}
2215
Harald Welte85804d42017-12-10 14:11:58 +01002216/* Test behavior of channel release after BSSMAP RESET from MSC */
2217testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +01002218 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +01002219
Harald Welte89d42e82017-12-17 16:42:41 +01002220 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +01002221
2222 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2223
2224 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
2225 IPA_RSL[0].clear;
2226
2227 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002228 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 +01002229 interleave {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002230 [] 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 +01002231 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
2232 }
2233
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002234 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002235 f_shutdown_helper();
Harald Welte85804d42017-12-10 14:11:58 +01002236}
2237
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002238/* Verify T(iar) triggers and releases the channel */
2239testcase TC_chan_rel_sccp_tiar_timeout() runs on test_CT {
2240 var DchanTuple dt;
2241
2242 /* Set T(iar) in BSC low enough that it will trigger before other side
2243 has time to keep alive with a T(ias). Keep recommended ratio of
2244 T(iar) >= T(ias)*2 */
2245 g_bsc_sccp_timer_ias := 2;
2246 g_bsc_sccp_timer_iar := 5;
2247
2248 f_init(1);
2249
2250 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2251 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002252 f_shutdown_helper();
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002253}
2254
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002255private function f_tc_chan_rel_rr_cause(myBSSMAP_Cause clear_cmd_cause, template RR_Cause expect_rr_cause)
2256runs on test_CT
2257{
2258 var DchanTuple dt;
2259
2260 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2261 var BssmapCause cause := 0;
2262 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(enum2int(clear_cmd_cause))));
2263 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2264 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2265 }
2266
2267 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 +02002268}
2269
2270/* Test that Clear Command cause codes affect the RR Channel Release cause code */
2271testcase TC_chan_rel_rr_cause() runs on test_CT {
2272 f_init(1);
2273
2274 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_CALL_CONTROL, GSM48_RR_CAUSE_NORMAL);
2275 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_HANDOVER_SUCCESSFUL, GSM48_RR_CAUSE_NORMAL);
2276 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_PREEMPTION, GSM48_RR_CAUSE_PREMPTIVE_REL);
2277 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE, GSM48_RR_CAUSE_PROT_ERROR_UNSPC);
2278 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
2279 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_EQUIPMENT_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
Vadim Yanitskiye18aebb2021-01-03 13:10:43 +01002280
2281 f_shutdown_helper();
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002282}
2283
Harald Welte5cd20ed2017-12-13 21:03:20 +01002284/* Test behavior if RSL EST IND for non-active channel */
2285testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
2286 timer T := 2.0;
2287
Harald Welte89d42e82017-12-17 16:42:41 +01002288 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002289
2290 var octetstring l3 := '00010203040506'O;
2291 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2292 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
2293
2294 T.start;
2295 alt {
2296 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2297 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
2298 }
2299 [] BSSAP.receive {}
2300 [] IPA_RSL[0].receive {}
2301 [] T.timeout {}
2302 }
2303
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002304 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002305}
2306
2307/* Test behavior if RSL EST IND for invalid SAPI */
2308testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
2309 var RslChannelNr chan_nr;
2310
Harald Welte89d42e82017-12-17 16:42:41 +01002311 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002312
2313 chan_nr := f_chreq_act_ack()
2314
2315 var octetstring l3 := '00010203040506'O;
2316 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
2317
2318 timer T := 2.0;
2319 T.start;
2320 alt {
2321 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2322 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
2323 }
2324 [] BSSAP.receive { repeat; }
2325 [] IPA_RSL[0].receive { repeat; }
2326 [] T.timeout {}
2327 }
2328
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002329 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002330}
2331
2332/* Test behavior if RSL EST IND for invalid SAPI */
2333testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
2334 timer T := 2.0;
2335
Harald Welte89d42e82017-12-17 16:42:41 +01002336 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002337
2338 var RslChannelNr chan_nr := f_chreq_act_ack();
2339
2340 var octetstring l3 := '00010203040506'O;
2341 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
2342
2343 T.start;
2344 alt {
2345 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2346 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
2347 }
2348 [] BSSAP.receive { repeat; }
2349 [] IPA_RSL[0].receive { repeat; }
2350 [] T.timeout {}
2351 }
2352
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002353 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002354}
2355
2356/* Test behavior if RSL EST IND for invalid SACCH */
2357testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
2358 timer T := 2.0;
2359
Harald Welte89d42e82017-12-17 16:42:41 +01002360 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002361
2362 var RslChannelNr chan_nr := f_chreq_act_ack();
2363
2364 var octetstring l3 := '00010203040506'O;
2365 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
2366
2367 T.start;
2368 alt {
2369 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2370 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
2371 }
2372 [] BSSAP.receive { repeat; }
2373 [] IPA_RSL[0].receive { repeat; }
2374 [] T.timeout {}
2375 }
2376
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002377 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002378}
2379
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002380/* Verify DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
2381private function f_TC_tch_dlci_link_id_sapi(charstring id) runs on MSC_ConnHdlr {
2382 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2383 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2384
2385 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2386 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2387
2388 f_establish_fully(ass_cmd, exp_compl);
2389
2390 /* SAPI0 has already been established by f_establish_fully(), establish SAPI3 */
2391 RSL.send(ts_RSL_EST_IND(g_chan_nr, ts_RslLinkID_SACCH(3), '0904'O));
2392 /* Expect BSSAP/DTAP on SAPI3 (DLCI IE) */
2393 BSSAP.receive(PDU_BSSAP:{
2394 discriminator := '1'B,
2395 spare := '0000000'B,
2396 dlci := 'C3'O,
2397 lengthIndicator := ?,
2398 pdu := { dtap := '0904'O }
2399 });
2400
2401 /* Send messages on DCCH/SAPI0 and ACCH/SAPI3 */
2402 for (var integer i := 0; i < 32; i := i + 1) {
2403 var octetstring l3 := '09'O & f_rnd_octstring(14);
2404 var template (value) RslLinkId link_id;
2405 var template (value) OCT1 dlci;
2406
2407 if (i mod 2 == 0) {
2408 /* SAPI0 on FACCH or SDCCH */
2409 link_id := ts_RslLinkID_DCCH(0);
2410 dlci := '80'O;
2411 } else {
2412 /* SAPI3 on SACCH */
2413 link_id := ts_RslLinkID_SACCH(3);
2414 dlci := 'C3'O;
2415 }
2416
2417 /* Send MO message: RSL -> BSSAP */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002418 f_mo_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002419 /* Send MT message: BSSAP -> RSL */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002420 f_mt_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002421 }
2422}
2423testcase TC_tch_dlci_link_id_sapi() runs on test_CT {
2424 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2425 var MSC_ConnHdlr vc_conn;
2426
2427 f_init(1, true);
2428 f_sleep(1.0);
2429
2430 vc_conn := f_start_handler(refers(f_TC_tch_dlci_link_id_sapi), pars);
2431 vc_conn.done;
2432
2433 f_shutdown_helper();
2434}
2435
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002436private function f_exp_sapi_n_reject(template (present) GsmSapi sapi := ?,
2437 template myBSSMAP_Cause cause := ?,
2438 float T_val := 2.0)
2439runs on test_CT {
2440 var BSSAP_N_DATA_ind rx_di;
2441 timer T;
2442
2443 var template BSSMAP_IE_Cause tr_cause := tr_BSSMAP_IE_Cause(cause);
2444 var template PDU_BSSAP tr_pdu := tr_BSSMAP_SAPInReject(sapi);
2445
2446 T.start(T_val);
2447 alt {
2448 [] BSSAP.receive(tr_BSSAP_DATA_ind(?, tr_pdu)) -> value rx_di {
2449 var BSSMAP_IE_Cause rx_cause := rx_di.userData.pdu.bssmap.sAPInReject.cause;
2450 if (not match(rx_cause, tr_cause)) {
2451 setverdict(fail, "Rx unexpected Cause IE: ",
2452 rx_cause, " vs expected ", tr_cause);
2453 }
2454 setverdict(pass);
2455 }
2456 [] BSSAP.receive(BSSAP_N_DATA_ind:?) -> value rx_di {
2457 setverdict(fail, "Rx unexpected BSSAP PDU: ", rx_di);
2458 }
2459 [] T.timeout {
2460 setverdict(fail, "Timeout waiting for BSSMAP SAPI N Reject");
2461 }
2462 }
2463}
2464
2465/* Check if we get SAPI N Reject on receipt of unexpected RLL RELease INDication */
2466testcase TC_rll_rel_ind_sapi_n_reject() runs on test_CT {
2467 var octetstring rnd_data := f_rnd_octstring(16);
2468 var RSL_Message rx_rsl;
2469 var DchanTuple dt;
2470
2471 f_init(1);
2472
2473 /* MS establishes a SAPI=0 link on DCCH */
2474 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2475
2476 /* MSC sends some data on (not yet established) SAPI=3 link */
2477 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2478 /* BSC attempts to establish a SAPI=3 link on DCCH */
2479 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2480
2481 /* MS sends unexpected RELease INDication on SAPI=3 */
2482 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3)));
2483 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2484 f_exp_sapi_n_reject(3, GSM0808_CAUSE_MS_NOT_EQUIPPED);
2485
2486 /* Clean up the connection */
2487 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2488 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2489
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002490 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002491}
2492
2493/* Check if we get SAPI N Reject on receipt of unexpected RLL ERROR INDication */
2494testcase TC_rll_err_ind_sapi_n_reject() runs on test_CT {
2495 var octetstring rnd_data := f_rnd_octstring(16);
2496 var RSL_Message rx_rsl;
2497 var DchanTuple dt;
2498
2499 f_init(1);
2500
2501 /* MS establishes a SAPI=0 link on DCCH */
2502 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2503
2504 /* MSC sends some data on (not yet established) SAPI=3 link */
2505 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2506 /* BSC attempts to establish a SAPI=3 link on DCCH */
2507 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2508
2509 /* BTS sends unexpected ERROR INDication on SAPI=3 */
2510 f_ipa_tx(0, ts_RSL_ERROR_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3), ''O));
2511 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2512 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED);
2513
2514 /* Clean up the connection */
2515 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2516 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2517
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002518 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002519}
2520
2521/* Check if we get SAPI N Reject due to a SAPI=3 link establishment timeout */
2522testcase TC_rll_timeout_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 does not respond, so the link establishment timeout triggers SAPI N Reject */
2538 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED, T_val := 8.0);
2539
2540 /* Clean up the connection */
2541 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2542 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2543
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002544 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002545}
2546
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002547testcase TC_si_default() runs on test_CT {
2548 f_init(0);
2549 f_init_bts_and_check_sysinfo(0, expect_si := SystemInformationConfig_default);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002550 f_shutdown_helper();
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002551}
Harald Welte4003d112017-12-09 22:35:39 +01002552
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002553/* We're testing SI2quater with lists of EARFCNs. Instead of just incrementing EARFCNs, also pick some from the edges of
2554 * the entire value range. This function provides the same EARFCN numbers for the same earfcn_index */
2555private function f_test_si2quater_earfcn_by_idx(integer earfcn_index) return uint16_t
2556{
2557 select (earfcn_index) {
2558 case (0) {
2559 /* E-ARFCN 111 is already added in the osmo-bsc.cfg */
2560 return 111;
2561 }
2562 case (1) {
2563 return 1;
2564 }
2565 case (2) {
2566 return 0;
2567 }
2568 case (3) {
2569 return 65535;
2570 }
2571 case else {
2572 return 23 * (earfcn_index - 3);
2573 }
2574 }
2575}
2576
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002577function f_test_si2quater(integer total_earfcns, template SystemInformationConfig expect_si,
2578 template CellSelIndValue expect_cells := omit) runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002579
2580 f_init(0);
2581
2582 /* E-ARFCN 111 is already added in the osmo-bsc.cfg, so only add more arfcns if total_earfcns > 1 */
2583 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002584 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2585 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002586 }
2587
2588 f_init_bts_and_check_sysinfo(0, expect_si := expect_si);
2589
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002590 if (not istemplatekind(expect_cells, "omit")) {
2591 /* Also check that RR Channel Release contains these EARFCNs.
2592 * (copied code from TC_chan_rel_hard_clear_csfb) */
2593 var BSSAP_N_DATA_ind rx_di;
2594 var DchanTuple dt;
2595
2596 dt := f_est_dchan('23'O, 23, '00010203040506'O);
Pau Espin Pedrold0046312021-04-19 16:35:58 +02002597 /* Send CommonID with some random PLMN (BSC doesn't take it into account
2598 * yet when generating the EUTRAN neigh list in RR CHannel Release) */
2599 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002600
2601 /* Instruct BSC to clear channel */
2602 var BssmapCause cause := 0;
2603 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2604
2605 /* expect Clear Complete from BSC on A */
2606 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2607 /* release the SCCP connection */
2608 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2609 }
2610
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002611 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 +02002612 }
2613
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002614 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002615 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 +02002616 }
2617}
2618
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002619private function f_tr_si2quater_earfcns(integer count) return template SI2quaterRestOctetsList
2620{
2621 var template SI2quaterRestOctetsList si2quater := {};
2622 var integer si2quater_count := (count + 2) / 3;
2623
2624 for (var integer i := 0; i < count; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002625 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002626 var integer index := i / 3;
2627 var integer earfcn_index := i mod 3;
2628 if (index >= lengthof(si2quater)) {
2629 si2quater[index] := tr_SI2quaterRestOctets_EUTRAN(index := index, count := si2quater_count - 1);
2630 }
2631 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);
2632 }
2633
2634 return si2quater;
2635}
2636
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002637private function f_tr_rr_chan_rel_earfcns(integer count) return template CellSelIndValue
2638{
2639 var template CellSelIndValue_EUTRAN_Descrs cells := {};
2640
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002641 /* the lte neighbors must match the config & vty to pass this test */
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002642 for (var integer i := 0; i < count; i := i + 1) {
2643 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002644 cells[i] := tr_CellSelIndValue_EUTRAN_Descr(earfcn, '1'B, 3);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002645 }
2646
2647 return tr_CellSelIndValue_EUTRAN(cells);
2648}
2649
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002650private function f_tc_si2quater_n_earfcns(integer n) runs on test_CT
2651{
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002652 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrol8ab62e42020-12-18 16:19:11 +01002653 sic.si2quater := f_tr_si2quater_earfcns(n);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002654 var template CellSelIndValue cells := f_tr_rr_chan_rel_earfcns(n);
2655 f_test_si2quater(n, sic, cells);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002656}
2657
2658testcase TC_si2quater_2_earfcns() runs on test_CT {
2659 f_tc_si2quater_n_earfcns(2);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002660 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002661}
2662
2663testcase TC_si2quater_3_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002664 f_tc_si2quater_n_earfcns(3);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002665 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002666}
2667
2668testcase TC_si2quater_4_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002669 f_tc_si2quater_n_earfcns(4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002670 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002671}
2672
2673testcase TC_si2quater_5_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002674 f_tc_si2quater_n_earfcns(5);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002675 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002676}
2677
2678testcase TC_si2quater_6_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002679 f_tc_si2quater_n_earfcns(6);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002680 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002681}
2682
2683testcase TC_si2quater_12_earfcns() runs on test_CT {
2684 f_tc_si2quater_n_earfcns(12);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002685 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002686}
2687
2688testcase TC_si2quater_23_earfcns() runs on test_CT {
2689 f_tc_si2quater_n_earfcns(23);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002690 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002691}
2692
2693testcase TC_si2quater_32_earfcns() runs on test_CT {
2694 f_tc_si2quater_n_earfcns(32);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002695 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002696}
2697
2698testcase TC_si2quater_33_earfcns() runs on test_CT {
2699 f_tc_si2quater_n_earfcns(33);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002700 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002701}
2702
2703testcase TC_si2quater_42_earfcns() runs on test_CT {
2704 f_tc_si2quater_n_earfcns(42);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002705 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002706}
2707
2708testcase TC_si2quater_48_earfcns() runs on test_CT {
2709 f_tc_si2quater_n_earfcns(48);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002710 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002711}
2712
2713/* verify the VTY error response when adding too many EARFCNs, and showing that osmo-bsc still sends 16 SI2quater with
2714 * 48 EARFCNs. */
2715testcase TC_si2quater_49_earfcns() runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002716 var template SystemInformationConfig sic := SystemInformationConfig_default;
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002717 sic.si2quater := f_tr_si2quater_earfcns(48); /* 48, not 49! */
2718 f_init(0);
2719
2720 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002721 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2722 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002723 }
2724
2725 /* The 49th EARFCN no longer fits, expect VTY error */
2726 f_vty_enter_cfg_bts(BSCVTY, 0);
2727 var charstring vty_error;
2728 vty_error := f_vty_transceive_ret(BSCVTY,
2729 "si2quater neighbor-list add earfcn 70 thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3")
2730 f_vty_transceive(BSCVTY, "end");
2731
2732 if (f_strstr(vty_error, "Unable to add ARFCN 70") >= 0) {
2733 log("Got expected VTY error: ", vty_error);
2734 setverdict(pass);
2735 } else {
2736 setverdict(fail, "Expected the 49th EUTRAN ARFCN to be rejected by vty config, got: ", vty_error);
2737 }
2738
2739 f_init_bts_and_check_sysinfo(0, expect_si := sic);
2740
2741 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002742 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 +02002743 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002744 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002745}
2746
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002747private function f_acc09_count_allowed(AccessControlClass acc) return uint8_t
2748{
2749 var uint8_t count := 0;
2750 for (var integer i := 5; i < 16; i := i + 1) {
2751 if (acc[i] == '0'B) { /* the list marks barred, we count allowed */
2752 count := count + 1;
2753 }
2754 }
2755 return count;
2756}
2757
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002758private function f_recv_next_si1(integer rsl_idx := 0) runs on test_CT return SystemInformationType1
2759{
2760 var ASP_RSL_Unitdata rx_rsl_ud;
2761 var SystemInformationType1 last_si1;
2762
2763 timer T := 30.0;
2764 T.start;
2765 alt {
2766 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD((tr_RSL_NO_BCCH_INFO,
2767 tr_RSL_BCCH_INFO,
2768 tr_RSL_NO_SACCH_FILL,
2769 tr_RSL_SACCH_FILL))
2770 ) -> value rx_rsl_ud {
2771 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
2772 if (g_system_information[rsl_idx].si1 == omit) {
2773 repeat;
2774 }
2775 last_si1 := g_system_information[rsl_idx].si1;
2776 g_system_information[rsl_idx].si1 := omit;
2777 T.stop;
2778 }
Vadim Yanitskiy79ebd5e2021-01-04 00:12:55 +01002779 [] IPA_RSL[rsl_idx].receive { repeat; }
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002780 [] T.timeout { setverdict(fail, "Timeout receiving next SI1"); }
2781 }
2782 return last_si1;
2783}
2784
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002785/* verify ACC rotate feature */
2786testcase TC_si_acc_rotate() runs on test_CT {
2787 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002788 var SystemInformationType1 last_si1;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002789 var AccessControlClass acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002790 var uint8_t count;
2791 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2792
2793 f_init(0, guard_timeout := 60.0);
2794
2795 f_bts_0_cfg(BSCVTY, {"rach access-control-class 5 barred",
2796 "access-control-class-rotate 3",
2797 "access-control-class-rotate-quantum 1"});
2798
2799 /* Init and get first sysinfo */
2800 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2801
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002802 for (var integer i:= 0; i < 20; i := i + 1) {
2803 last_si1 := f_recv_next_si1(0);
2804 acc := last_si1.rach_control.acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002805 count := f_acc09_count_allowed(acc);
2806 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2807
2808 if (count != 3) {
2809 log("RSL: EXPECTED SI ACC len=3");
2810 setverdict(fail, "received SI does not match expectations");
2811 break;
2812 }
2813
2814 for (var integer j := 0; j < 10; j := j + 1) {
2815 if (acc[16 - 1 - j] == '0'B) { /* the list marks barred, we count allowed */
2816 times_allowed[j] := times_allowed[j] + 1;
2817 }
2818 }
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002819 }
2820
2821 for (var integer j := 0; j < 10; j := j + 1) {
2822 log("ACC", j, " allowed ", times_allowed[j], " times" );
2823 if (j != 5 and times_allowed[j] < 3) {
2824 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " < 1 times");
2825 } else if (j == 5 and times_allowed[j] > 0) {
2826 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " > 0 times");
2827 }
2828 }
2829
2830 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2831 "rach access-control-class 5 allowed"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002832 f_shutdown_helper();
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002833}
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002834
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002835/* verify ACC startup ramp+rotate feature */
2836testcase TC_si_acc_ramp_rotate() runs on test_CT {
2837 var template SystemInformationConfig sic := SystemInformationConfig_default;
2838 var SystemInformationType1 last_si1;
2839 var AccessControlClass acc;
2840 var ASP_RSL_Unitdata rx_rsl_ud;
2841 var uint8_t count;
2842 var uint8_t prev_count;
2843 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2844
2845 f_init(0, guard_timeout := 80.0);
2846
2847 f_bts_0_cfg(BSCVTY, {"rach access-control-class 4 barred",
2848 "access-control-class-rotate 0",
2849 "access-control-class-rotate-quantum 1",
2850 "access-control-class-ramping",
2851 "access-control-class-ramping-step-interval 5",
2852 "access-control-class-ramping-step-size 5"});
2853
2854 /* Init and get first sysinfo */
2855 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2856 last_si1 := g_system_information[0].si1;
2857 acc := last_si1.rach_control.acc;
2858 count := f_acc09_count_allowed(acc);
2859 /* Adm subset size was set to 0 above, so wait until all ACC are barred */
2860 while (count > 0) {
2861 last_si1 := f_recv_next_si1(0);
2862 acc := last_si1.rach_control.acc;
2863 count := f_acc09_count_allowed(acc);
2864 log("RSL: wait len()=0: GOT SI1 ACC len=", count, ": ", acc);
2865 }
2866
2867 /* Increase adm subset size, we should see ramping start up */
2868 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10"});
2869 prev_count := 0;
2870 while (true) {
2871 last_si1 := f_recv_next_si1(0);
2872 acc := last_si1.rach_control.acc;
2873 count := f_acc09_count_allowed(acc);
2874 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2875
2876 if (prev_count > count) {
2877 setverdict(fail, "ACC allowed count dropped while expecting grow: ", prev_count, " -> ", count);
2878 break;
2879 }
2880
2881 if (count == 9) {
2882 break; /* Maximum reached (10 - 1 perm barred), done here */
2883 }
2884
2885 prev_count := count;
2886 }
2887
2888 setverdict(pass);
2889
2890 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2891 "rach access-control-class 4 allowed",
2892 "no access-control-class-ramping"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002893 f_shutdown_helper();
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002894}
2895
Harald Welte4003d112017-12-09 22:35:39 +01002896testcase TC_ctrl_msc_connection_status() runs on test_CT {
2897 var charstring ctrl_resp;
2898
Harald Welte89d42e82017-12-17 16:42:41 +01002899 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002900
2901 /* See https://osmocom.org/issues/2729 */
2902 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002903 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002904}
2905
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002906testcase TC_ctrl_msc0_connection_status() runs on test_CT {
2907 var charstring ctrl_resp;
2908
2909 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002910
2911 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002912 f_shutdown_helper();
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002913}
2914
Neels Hofmeyr0bc470d2021-08-21 13:37:13 +02002915/* Verify correct stats on the number of configured and connected MSCs */
2916private function f_tc_stat_num_msc_connected_msc_connhdlr(integer expect_num_msc_connected) runs on MSC_ConnHdlr {
2917 g_pars := f_gen_test_hdlr_pars();
2918 var StatsDExpects expect := {
2919 { name := "TTCN3.bsc.0.num_msc.connected", mtype := "g", min := expect_num_msc_connected, max := expect_num_msc_connected },
2920 { name := "TTCN3.bsc.0.num_msc.total", mtype := "g", min := NUM_MSC, max := NUM_MSC }
2921 };
2922 f_statsd_expect(expect);
2923}
2924
2925private function f_tc_stat_num_msc_connected_test_ct(void_fn tc_fn, integer nr_msc) runs on test_CT
2926{
2927 var MSC_ConnHdlr vc_conn;
2928
2929 f_init(nr_bts := 1, handler_mode := true, nr_msc := nr_msc);
2930 f_sleep(1.0);
2931 vc_conn := f_start_handler(tc_fn);
2932 vc_conn.done;
2933
2934 /* Also verify stat exposed on CTRL interface */
2935 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_msc:connected", int2str(nr_msc));
2936 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_msc:total", int2str(NUM_MSC));
2937
2938 f_shutdown_helper();
2939}
2940
2941/* Verify that when 1 MSC is active, that num_msc:connected reports 1. */
2942private function f_tc_stat_num_msc_connected_1(charstring id) runs on MSC_ConnHdlr {
2943 f_tc_stat_num_msc_connected_msc_connhdlr(1);
2944}
2945testcase TC_stat_num_msc_connected_1() runs on test_CT {
2946 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_1), 1);
2947}
2948
2949/* Verify that when 2 MSCs are active, that num_msc:connected reports 2. */
2950private function f_tc_stat_num_msc_connected_2(charstring id) runs on MSC_ConnHdlr {
2951 f_tc_stat_num_msc_connected_msc_connhdlr(2);
2952}
2953testcase TC_stat_num_msc_connected_2() runs on test_CT {
2954 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_2), 2);
2955}
2956
2957/* Verify that when 3 MSCs are active, that num_msc:connected reports 3. */
2958private function f_tc_stat_num_msc_connected_3(charstring id) runs on MSC_ConnHdlr {
2959 f_tc_stat_num_msc_connected_msc_connhdlr(3);
2960}
2961testcase TC_stat_num_msc_connected_3() runs on test_CT {
2962 f_tc_stat_num_msc_connected_test_ct(refers(f_tc_stat_num_msc_connected_3), 3);
2963}
2964
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +02002965/* Verify correct stats on the number of configured and connected MSCs */
2966private function f_tc_stat_num_bts_connected_msc_connhdlr(integer expect_num_bts_connected) runs on MSC_ConnHdlr {
2967 g_pars := f_gen_test_hdlr_pars();
2968 var StatsDExpects expect := {
2969 { name := "TTCN3.bsc.0.num_bts.oml_connected", mtype := "g", min := expect_num_bts_connected, max := NUM_BTS_CFG },
2970 { name := "TTCN3.bsc.0.num_bts.all_trx_rsl_connected", mtype := "g", min := expect_num_bts_connected, max := expect_num_bts_connected },
2971 { name := "TTCN3.bsc.0.num_bts.total", mtype := "g", min := NUM_BTS_CFG, max := NUM_BTS_CFG },
2972 { name := "TTCN3.bsc.0.num_trx.rsl_connected", mtype := "g", min := expect_num_bts_connected, max := expect_num_bts_connected },
2973 { name := "TTCN3.bsc.0.num_trx.total", mtype := "g", min := NUM_BTS_CFG, max := NUM_BTS_CFG }
2974 };
2975 f_statsd_expect(expect);
2976}
2977
2978private function f_tc_stat_num_bts_connected_test_ct(void_fn tc_fn, integer nr_bts) runs on test_CT {
2979 var MSC_ConnHdlr vc_conn;
2980
2981 f_init(nr_bts := nr_bts, handler_mode := true, nr_msc := 1);
2982 f_sleep(1.0);
2983 vc_conn := f_start_handler(tc_fn);
2984 vc_conn.done;
2985
2986 /* Also verify stat exposed on CTRL interface */
2987 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_bts:all_trx_rsl_connected", int2str(nr_bts));
2988 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_bts:total", int2str(NUM_BTS_CFG));
2989 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_trx:rsl_connected", int2str(nr_bts));
2990 f_ctrl_get_exp(IPA_CTRL, "stat_item.last.bsc.0.num_trx:total", int2str(NUM_BTS_CFG));
2991
Neels Hofmeyra41ae302021-09-06 22:06:02 +02002992 /* Verify rf_states exposed on CTRL interface */
2993 var charstring expect_net_rf_states := "";
2994 for (var integer i := 0; i < NUM_BTS_CFG; i := i + 1) {
2995 var charstring expect_bts_rf_states := int2str(i) & ",0,";
2996 if (i < NUM_BTS) {
2997 /* In these tests, OML for the first NUM_BTS are always connected via osmo-bts-omldummy */
2998 expect_bts_rf_states := expect_bts_rf_states & "operational,unlocked,";
2999 } else {
3000 /* For remaining i < NUM_BTS_CFG, OML is not connected, i.e. inoperational */
3001 expect_bts_rf_states := expect_bts_rf_states & "inoperational,locked,";
3002 }
3003 /* The RF policy is still global in osmo-bsc, i.e. always "on" */
3004 expect_bts_rf_states := expect_bts_rf_states & "on,";
3005 if (i < nr_bts) {
3006 /* For BTS where RSL is connected, the RSL state will be "up" */
3007 expect_bts_rf_states := expect_bts_rf_states & "rsl-up;";
3008 } else {
3009 expect_bts_rf_states := expect_bts_rf_states & "rsl-down;";
3010 }
3011
3012 f_ctrl_get_exp(IPA_CTRL, "bts." & int2str(i) & ".rf_states", expect_bts_rf_states);
3013 expect_net_rf_states := expect_net_rf_states & expect_bts_rf_states;
3014 }
3015 f_ctrl_get_exp(IPA_CTRL, "rf_states", expect_net_rf_states);
3016
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +02003017 f_shutdown_helper();
3018}
3019
3020/* Verify that when 1 BTS is connected, that num_{bts,trx}:*_connected reports 1. */
3021private function f_tc_stat_num_bts_connected_1(charstring id) runs on MSC_ConnHdlr {
3022 f_tc_stat_num_bts_connected_msc_connhdlr(1);
3023}
3024testcase TC_stat_num_bts_connected_1() runs on test_CT {
3025 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_1), 1);
3026}
3027
3028/* Verify that when 2 BTS is connected, that num_{bts,trx}:*_connected reports 2. */
3029private function f_tc_stat_num_bts_connected_2(charstring id) runs on MSC_ConnHdlr {
3030 f_tc_stat_num_bts_connected_msc_connhdlr(2);
3031}
3032testcase TC_stat_num_bts_connected_2() runs on test_CT {
3033 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_2), 2);
3034}
3035
3036/* Verify that when 3 BTS is connected, that num_{bts,trx}:*_connected reports 3. */
3037private function f_tc_stat_num_bts_connected_3(charstring id) runs on MSC_ConnHdlr {
3038 f_tc_stat_num_bts_connected_msc_connhdlr(3);
3039}
3040testcase TC_stat_num_bts_connected_3() runs on test_CT {
3041 f_tc_stat_num_bts_connected_test_ct(refers(f_tc_stat_num_bts_connected_3), 3);
3042}
3043
Harald Welte4003d112017-12-09 22:35:39 +01003044testcase TC_ctrl() runs on test_CT {
3045 var charstring ctrl_resp;
3046
Harald Welte89d42e82017-12-17 16:42:41 +01003047 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01003048
3049 /* all below values must match the osmo-bsc.cfg config file used */
3050
Harald Welte6a129692018-03-17 17:30:14 +01003051 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
3052 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Oliver Smith75aa0202019-08-19 14:17:50 +02003053 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "4");
Harald Welte4003d112017-12-09 22:35:39 +01003054
3055 var integer bts_nr := 0;
3056 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
3057 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
3058 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
3059 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
3060 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
3061 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
3062 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
3063
3064 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
3065 f_sleep(2.0);
3066 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
3067 setverdict(fail, "oml-uptime not incrementing as expected");
3068 }
3069 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
3070
3071 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
3072
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003073 f_shutdown_helper();
Harald Welte96c94412017-12-09 03:12:45 +01003074}
3075
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02003076/* Verify that Upon receival of SET "location", BSC forwards a TRAP
3077 "location-state" over the SCCPlite IPA conn */
3078testcase TC_ctrl_location() runs on test_CT {
3079 var MSC_ConnHdlr vc_conn;
3080 var integer bts_nr := 0;
3081
3082 f_init(1, true);
3083 f_sleep(1.0);
3084
3085 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234567,fix3d,0.340000,0.560000,0.780000");
3086 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
3087 "1234567,fix3d,0.340000,0.560000,0.780000,operational,unlocked,on,001,01");
3088
3089 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "1");
3090 f_sleep(2.0);
3091
3092 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234888,fix3d,0.350000,0.570000,0.790000");
3093 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
3094 "1234888,fix3d,0.350000,0.570000,0.790000,operational,locked,off,001,01");
3095
3096 /* should match the one from config */
3097 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "0");
3098
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003099 f_shutdown_helper();
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02003100}
3101
Harald Welte6f521d82017-12-11 19:52:02 +01003102
3103/***********************************************************************
3104 * Paging Testing
3105 ***********************************************************************/
3106
3107type record Cell_Identity {
3108 GsmMcc mcc,
3109 GsmMnc mnc,
3110 GsmLac lac,
3111 GsmCellId ci
3112};
Harald Welte24135bd2018-03-17 19:27:53 +01003113private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01003114private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01003115
Harald Welte5d1a2202017-12-13 19:51:29 +01003116type set of integer BtsIdList;
3117
3118private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
3119 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
3120 if (bts_id == bts_ids[j]) {
3121 return true;
3122 }
3123 }
3124 return false;
3125}
Harald Welte6f521d82017-12-11 19:52:02 +01003126
3127/* core paging test helper function; used by most paging test cases */
3128private function f_pageing_helper(hexstring imsi,
3129 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01003130 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01003131 template RSL_ChanNeeded rsl_chneed := omit,
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003132 template (omit) OCT4 tmsi := omit) runs on test_CT
Harald Welte6f521d82017-12-11 19:52:02 +01003133{
3134 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003135 var template MobileIdentityV mi;
Harald Welte6f521d82017-12-11 19:52:02 +01003136 var RSL_Message rx_rsl;
3137 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01003138 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01003139
3140 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01003141
3142 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01003143 for (i := 0; i < NUM_BTS; i := i + 1) {
3144 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01003145 }
Harald Welte6f521d82017-12-11 19:52:02 +01003146
3147 if (isvalue(rsl_chneed)) {
3148 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
3149 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
3150 } else {
3151 bssmap_chneed := omit;
3152 }
3153
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003154 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[0].sccp_addr_peer, g_bssap[0].sccp_addr_own,
3155 ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed)));
Harald Welte6f521d82017-12-11 19:52:02 +01003156
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003157 if (not istemplatekind(tmsi, "omit")) {
3158 mi := t_MI_TMSI(tmsi);
Harald Welte6f521d82017-12-11 19:52:02 +01003159 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003160 mi := tr_MI_IMSI(imsi);
Harald Welte6f521d82017-12-11 19:52:02 +01003161 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003162
Harald Welte5d1a2202017-12-13 19:51:29 +01003163 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07003164 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(mi));
Harald Welte5d1a2202017-12-13 19:51:29 +01003165 /* check channel type, paging group */
3166 if (rx_rsl.ies[1].body.paging_group != paging_group) {
3167 setverdict(fail, "Paging for wrong paging group");
3168 }
3169 if (ispresent(rsl_chneed) and
3170 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
3171 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
3172 }
Harald Welte6f521d82017-12-11 19:52:02 +01003173 }
Harald Welte2fccd982018-01-31 15:48:19 +01003174 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01003175 /* do a quick check on all not-included BTSs if they received paging */
3176 for (i := 0; i < NUM_BTS; i := i + 1) {
3177 timer T := 0.1;
3178 if (f_bts_in_list(i, bts_ids)) {
3179 continue;
3180 }
3181 T.start;
3182 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003183 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(mi))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003184 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
3185 }
3186 [] IPA_RSL[i].receive { repeat; }
3187 [] T.timeout { }
3188 }
Harald Welte6f521d82017-12-11 19:52:02 +01003189 }
3190
3191 setverdict(pass);
3192}
3193
Harald Welte5d1a2202017-12-13 19:51:29 +01003194const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01003195const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01003196const BtsIdList c_BtsId_LAC1 := { 0, 1 };
3197const BtsIdList c_BtsId_LAC2 := { 2 };
3198
Harald Welte6f521d82017-12-11 19:52:02 +01003199/* PAGING by IMSI + TMSI */
3200testcase TC_paging_imsi_nochan() runs on test_CT {
3201 var BSSMAP_FIELD_CellIdentificationList cid_list;
3202 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01003203 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003204 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003205}
3206
3207/* PAGING by IMSI + TMSI */
3208testcase TC_paging_tmsi_nochan() runs on test_CT {
3209 var BSSMAP_FIELD_CellIdentificationList cid_list;
3210 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003211 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003212 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003213}
3214
3215/* Paging with different "channel needed' values */
3216testcase TC_paging_tmsi_any() runs on test_CT {
3217 var BSSMAP_FIELD_CellIdentificationList cid_list;
3218 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003219 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003220 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003221}
3222testcase TC_paging_tmsi_sdcch() runs on test_CT {
3223 var BSSMAP_FIELD_CellIdentificationList cid_list;
3224 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003225 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003226 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003227}
3228testcase TC_paging_tmsi_tch_f() runs on test_CT {
3229 var BSSMAP_FIELD_CellIdentificationList cid_list;
3230 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003231 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003232 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003233}
3234testcase TC_paging_tmsi_tch_hf() runs on test_CT {
3235 var BSSMAP_FIELD_CellIdentificationList cid_list;
3236 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003237 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003238 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003239}
3240
3241/* Paging by CGI */
3242testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
3243 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3244 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003245 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003246 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003247}
3248
3249/* Paging by LAC+CI */
3250testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
3251 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3252 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003253 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003254 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003255}
3256
3257/* Paging by CI */
3258testcase TC_paging_imsi_nochan_ci() runs on test_CT {
3259 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3260 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003261 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01003262 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003263}
3264
3265/* Paging by LAI */
3266testcase TC_paging_imsi_nochan_lai() runs on test_CT {
3267 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3268 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003269 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003270 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003271}
3272
3273/* Paging by LAC */
3274testcase TC_paging_imsi_nochan_lac() runs on test_CT {
3275 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3276 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01003277 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003278 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003279}
3280
3281/* Paging by "all in BSS" */
3282testcase TC_paging_imsi_nochan_all() runs on test_CT {
3283 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3284 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01003285 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003286 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01003287}
3288
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003289/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003290testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
3291 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3292 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 +01003293 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003294 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003295}
Harald Welte6f521d82017-12-11 19:52:02 +01003296
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003297/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003298testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
3299 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3300 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003301 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003302 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003303}
3304
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003305/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01003306testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
3307 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3308 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01003309 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003310 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003311}
3312
Harald Welte6f521d82017-12-11 19:52:02 +01003313/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01003314testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
3315 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3316 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
3317 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003318 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003319}
3320
3321/* Paging on empty list: Verify none of them page */
3322testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
3323 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3324 cid_list := { cIl_LAC := { } };
3325 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003326 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003327}
3328
Stefan Sperling049a86e2018-03-20 15:51:00 +01003329/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
3330testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
3331 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3332 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
3333 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
3334 f_shutdown_helper();
3335}
3336
Harald Welte6f521d82017-12-11 19:52:02 +01003337/* Verify paging retransmission interval + count */
3338/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01003339/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01003340
Harald Weltee65d40e2017-12-13 00:09:06 +01003341/* Verify PCH load */
3342testcase TC_paging_imsi_load() runs on test_CT {
3343 var BSSMAP_FIELD_CellIdentificationList cid_list;
3344 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01003345 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01003346 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003347 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01003348
3349 /* tell BSC there is no paging space anymore */
3350 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01003351 f_sleep(0.2);
3352 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01003353
3354 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
3355 * there would be 8 retransmissions during 4 seconds */
3356 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01003357 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01003358 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003359 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Weltee65d40e2017-12-13 00:09:06 +01003360 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02003361 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01003362 }
Harald Welte2caa1062018-03-17 18:19:05 +01003363 [] T_retrans.timeout {
3364 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
3365 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
3366 T_retrans.start;
3367 repeat;
3368 }
Harald Weltee65d40e2017-12-13 00:09:06 +01003369 [] T.timeout {
3370 setverdict(pass);
3371 }
3372 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003373
3374 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01003375}
3376
Harald Welte235ebf12017-12-15 14:18:16 +01003377/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01003378testcase TC_paging_counter() runs on test_CT {
3379 var BSSMAP_FIELD_CellIdentificationList cid_list;
3380 timer T := 4.0;
3381 var integer i;
3382 var integer paging_attempted_bsc;
3383 var integer paging_attempted_bts[NUM_BTS];
Oliver Smith8b343d32021-11-26 13:01:42 +01003384 var integer paging_expired_bsc;
Harald Welte1ff69992017-12-14 12:31:17 +01003385 var integer paging_expired_bts[NUM_BTS];
3386 cid_list := valueof(ts_BSSMAP_CIL_noCell);
3387
3388 f_init();
3389
3390 /* read counters before paging */
3391 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
Oliver Smith8b343d32021-11-26 13:01:42 +01003392 if (Misc_Helpers.f_osmo_repo_is("nightly")) { /* osmo-bsc > 1.8.0 */
3393 paging_expired_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:expired");
3394 }
Harald Welte1ff69992017-12-14 12:31:17 +01003395 for (i := 0; i < NUM_BTS; i := i+1) {
3396 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
3397 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
3398 }
3399
3400 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
3401
3402 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
3403 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
3404 for (i := 0; i < NUM_BTS; i := i+1) {
3405 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
3406 paging_attempted_bts[i]+1);
3407 }
3408
3409 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
3410 f_sleep(12.0);
Oliver Smith8b343d32021-11-26 13:01:42 +01003411 if (Misc_Helpers.f_osmo_repo_is("nightly")) { /* osmo-bsc > 1.8.0 */
3412 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:expired", paging_expired_bsc+1);
3413 }
Harald Welte1ff69992017-12-14 12:31:17 +01003414 for (i := 0; i < NUM_BTS; i := i+1) {
3415 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
3416 paging_expired_bts[i]+1);
3417 }
Harald Welte1ff69992017-12-14 12:31:17 +01003418
Philipp Maier282ca4b2018-02-27 17:17:00 +01003419 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01003420}
3421
3422
Harald Welte10985002017-12-12 09:29:15 +01003423/* Verify paging stops after A-RESET */
3424testcase TC_paging_imsi_a_reset() runs on test_CT {
3425 var BSSMAP_FIELD_CellIdentificationList cid_list;
3426 timer T := 3.0;
3427 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003428 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01003429
3430 /* Perform a BSSMAP Reset and wait for ACK */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003431 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 +01003432 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003433 [] 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 +01003434 [] BSSAP.receive { repeat; }
3435 }
3436
Daniel Willmanncbef3982018-07-30 09:22:40 +02003437 /* Wait to avoid a possible race condition if a paging message is
3438 * received right before the reset ACK. */
3439 f_sleep(0.2);
3440
Harald Welte10985002017-12-12 09:29:15 +01003441 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01003442 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
3443 IPA_RSL[i].clear;
3444 }
Harald Welte10985002017-12-12 09:29:15 +01003445
3446 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
3447 T.start;
3448 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003449 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte10985002017-12-12 09:29:15 +01003450 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003451 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01003452 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003453 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003454 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003455 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003456 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003457 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003458 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003459 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003460 }
Harald Welte10985002017-12-12 09:29:15 +01003461 [] T.timeout {
3462 setverdict(pass);
3463 }
3464 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003465
3466 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01003467}
Harald Welteae026692017-12-09 01:03:01 +01003468
Philipp Maierf45824a2019-08-14 14:44:10 +02003469/* Verify how we handle unsolicited Paging Response. In case of an unsolicit
3470 * paging response we can not know which MSC is in charge, so we will blindly
3471 * pick the first configured MSC. This behavior is required in order to make
3472 * MT-CSFB calls working because in those cases the BSC can not know that the
3473 * MSC has already paged the subscriver via SGs. So any MT-CSFB call will look
3474 * like an unsolicited Paging Response to the MSC.
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003475 */
3476testcase TC_paging_resp_unsol() runs on test_CT {
3477
3478 f_init(1);
Philipp Maierf45824a2019-08-14 14:44:10 +02003479 timer T := 5.0;
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003480
3481 var BSSAP_N_CONNECT_ind rx_c_ind;
3482 var DchanTuple dt;
3483 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
Philipp Maierf45824a2019-08-14 14:44:10 +02003484 var octetstring rr_pag_resp := enc_PDU_ML3_MS_NW(l3);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003485
3486 /* Send CHAN RQD and wait for allocation; acknowledge it */
3487 dt.rsl_chan_nr := f_chreq_act_ack();
3488
3489 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
3490 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
3491
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003492
Philipp Maierf45824a2019-08-14 14:44:10 +02003493 /* Expevct a CR with a matching Paging response on the A-Interface */
3494 T.start;
3495 alt {
3496 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(rr_pag_resp))) {
3497 setverdict(pass);
3498 }
3499 [] BSSAP.receive {
3500 setverdict(fail, "Received unexpected message on A-Interface!");
3501 }
3502 [] T.timeout {
3503 setverdict(fail, "Received nothing on A-Interface!");
3504 }
3505 }
3506
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003507 f_shutdown_helper();
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003508}
3509
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003510/* Test RSL link drop causes counter increment */
3511testcase TC_rsl_drop_counter() runs on test_CT {
3512 var integer rsl_fail;
3513
Harald Welte89d42e82017-12-17 16:42:41 +01003514 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003515
3516 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
3517
3518 bts[0].rsl.vc_IPA.stop;
3519
3520 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
3521
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003522 f_shutdown_helper();
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003523}
3524
3525/* TODO: Test OML link drop causes counter increment */
3526
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003527/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
3528function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
3529 timer T := 10.0;
3530
3531 bts[0].rsl.id := "IPA-0-RSL";
3532 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
3533 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
3534 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
Oliver Smith92c2bdb2019-08-20 15:11:24 +02003535 bts[0].rsl.ccm_pars.unit_id := "99/0/0"; /* value which is unknown at BTS */
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003536
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01003537 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003538
3539 f_init_mgcp("VirtMSC");
3540
3541 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
3542 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
3543 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
3544 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
3545
3546 /* wait for IPA OML link to connect and then disconnect */
3547 T.start;
3548 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +07003549 [] IPA_RSL[0].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) {
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003550 T.stop;
3551 return true;
3552 }
3553 [] IPA_RSL[0].receive { repeat }
3554 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02003555 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003556 }
3557 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003558 return false;
3559}
3560
3561/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3562testcase TC_rsl_unknown_unit_id() runs on test_CT {
3563 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
3564 setverdict(pass);
3565 } else {
3566 setverdict(fail, "Timeout RSL waiting for connection to close");
3567 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003568 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003569}
3570
3571
3572/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3573testcase TC_oml_unknown_unit_id() runs on test_CT {
3574 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
3575 setverdict(pass);
3576 } else {
3577 setverdict(fail, "Timeout OML waiting for connection to close");
3578 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003579 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003580}
3581
3582
Harald Weltec1a2fff2017-12-17 11:06:19 +01003583/***********************************************************************
Harald Welte6811d102019-04-14 22:23:14 +02003584 * "New world" test cases using RSL_Emulation + RAN_Emulation
Harald Weltec1a2fff2017-12-17 11:06:19 +01003585 ***********************************************************************/
3586
Harald Welte6811d102019-04-14 22:23:14 +02003587import from RAN_Emulation all;
Harald Welte47cd0e32020-08-21 12:39:11 +02003588import from BSSAP_LE_Emulation all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01003589import from RSL_Emulation all;
3590import from MSC_ConnectionHandler all;
3591
3592type function void_fn(charstring id) runs on MSC_ConnHdlr;
3593
Harald Welte336820c2018-05-31 20:34:52 +02003594/* helper function to create and connect a MSC_ConnHdlr component */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003595private function f_connect_handler(inout MSC_ConnHdlr vc_conn, integer bssap_idx := 0) runs on test_CT {
3596 connect(vc_conn:RAN, g_bssap[bssap_idx].vc_RAN:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01003597 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003598 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01003599 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01003600 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01003601 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
3602 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
3603 }
Neels Hofmeyr91401012019-07-11 00:42:35 +02003604 if (isvalue(bts[2])) {
3605 connect(vc_conn:RSL2, bts[2].rsl.vc_RSL:CLIENT_PT);
3606 connect(vc_conn:RSL2_PROC, bts[2].rsl.vc_RSL:RSL_PROC);
3607 }
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003608 connect(vc_conn:BSSAP, g_bssap[bssap_idx].vc_RAN:CLIENT);
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02003609 if (mp_enable_lcs_tests) {
3610 connect(vc_conn:BSSAP_LE, g_bssap_le.vc_BSSAP_LE:CLIENT);
3611 connect(vc_conn:BSSAP_LE_PROC, g_bssap_le.vc_BSSAP_LE:PROC);
3612 }
Daniel Willmann191e0d92018-01-17 12:44:35 +01003613 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02003614 connect(vc_conn:MGCP_MULTI, vc_MGCP:MGCP_CLIENT_MULTI);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003615 connect(vc_conn:STATSD_PROC, vc_STATSD:STATSD_PROC);
Harald Welte336820c2018-05-31 20:34:52 +02003616}
3617
Neels Hofmeyrda436782021-07-20 22:09:06 +02003618function f_start_handler_create(template (omit) TestHdlrParams pars := omit)
Harald Welte336820c2018-05-31 20:34:52 +02003619runs on test_CT return MSC_ConnHdlr {
3620 var charstring id := testcasename();
3621 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003622 var integer bssap_idx := 0;
3623 if (isvalue(pars)) {
3624 bssap_idx := valueof(pars).mscpool.bssap_idx;
3625 }
Harald Welte336820c2018-05-31 20:34:52 +02003626 vc_conn := MSC_ConnHdlr.create(id);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003627 f_connect_handler(vc_conn, bssap_idx);
Neels Hofmeyrda436782021-07-20 22:09:06 +02003628 return vc_conn;
3629}
3630
3631function f_start_handler_run(MSC_ConnHdlr vc_conn, void_fn fn, template (omit) TestHdlrParams pars := omit)
3632runs on test_CT return MSC_ConnHdlr {
3633 var charstring id := testcasename();
Neels Hofmeyr1708d1b2020-10-10 16:56:48 +02003634 /* Emit a marker to appear in the SUT's own logging output */
Neels Hofmeyrda436782021-07-20 22:09:06 +02003635 f_logp(BSCVTY, id & "() start");
Harald Weltea0630032018-03-20 21:09:55 +01003636 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003637 return vc_conn;
3638}
3639
Neels Hofmeyrda436782021-07-20 22:09:06 +02003640function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
3641runs on test_CT return MSC_ConnHdlr {
3642 return f_start_handler_run(f_start_handler_create(pars), fn, pars);
3643}
3644
Harald Weltea0630032018-03-20 21:09:55 +01003645/* first function inside ConnHdlr component; sets g_pars + starts function */
3646private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
3647runs on MSC_ConnHdlr {
3648 if (isvalue(pars)) {
3649 g_pars := valueof(pars);
3650 }
3651 fn.apply(id);
3652}
3653
Oliver Smith26a3db72021-07-09 13:51:29 +02003654private function f_vty_encryption_a5(charstring options) runs on test_CT {
3655 f_vty_transceive(BSCVTY, "configure terminal");
3656 f_vty_transceive(BSCVTY, "network");
3657 f_vty_transceive(BSCVTY, "encryption a5 " & options);
3658 f_vty_transceive(BSCVTY, "exit");
3659 f_vty_transceive(BSCVTY, "exit");
3660}
3661
3662private function f_vty_encryption_a5_reset() runs on test_CT {
3663 /* keep in sync with docker-playground.git ttcn3-bsc-test/osmo-bsc.cfg */
3664 f_vty_encryption_a5("0 1 3");
3665}
3666
Harald Welte3c86ea02018-05-10 22:28:05 +02003667/* Establish signalling channel (non-assignment case) followed by cipher mode */
3668private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003669 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3670 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02003671 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02003672 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
3673 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
3674 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
3675 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02003676
Philipp Maier23000732018-05-18 11:25:37 +02003677 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02003678}
3679testcase TC_ciph_mode_a5_0() runs on test_CT {
3680 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003681 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003682 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
3683
3684 f_init(1, true);
3685 f_sleep(1.0);
3686 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3687 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003688 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003689}
3690testcase TC_ciph_mode_a5_1() runs on test_CT {
3691 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003692 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003693 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
3694
3695 f_init(1, true);
3696 f_sleep(1.0);
3697 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3698 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003699 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003700}
Oliver Smith50b98122021-07-09 15:00:28 +02003701/* OS#4975: verify that A5/2 is preferred over A5/0 */
3702testcase TC_ciph_mode_a5_2_0() runs on test_CT {
3703 var MSC_ConnHdlr vc_conn;
3704 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3705
3706 pars.encr := valueof(t_EncrParams('05'O, f_rnd_octstring(8))); /* A5/0 and A5/2 (0x01|0x04)*/
3707 pars.encr_exp_enc_alg := '04'O; /* A5/2 */
3708
3709 f_init(1, true);
3710 f_vty_encryption_a5("0 1 2 3");
3711 f_sleep(1.0);
3712 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3713 vc_conn.done;
3714 f_vty_encryption_a5_reset();
3715 f_shutdown_helper();
3716}
Oliver Smith1dff88d2021-07-09 08:45:51 +02003717/* OS#4975: verify that A5/1 is preferred over A5/2 */
3718testcase TC_ciph_mode_a5_2_1() runs on test_CT {
3719 var MSC_ConnHdlr vc_conn;
3720 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3721
3722 pars.encr := valueof(t_EncrParams('06'O, f_rnd_octstring(8))); /* A5/1 and A5/2 (0x02|0x04)*/
3723 pars.encr_exp_enc_alg := '02'O; /* A5/1 */
3724
3725 f_init(1, true);
3726 f_vty_encryption_a5("1 2");
3727 f_sleep(1.0);
3728 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3729 vc_conn.done;
3730 f_vty_encryption_a5_reset();
3731 f_shutdown_helper();
3732}
Harald Welte3c86ea02018-05-10 22:28:05 +02003733testcase TC_ciph_mode_a5_3() runs on test_CT {
3734 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003735 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003736 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
3737
3738 f_init(1, true);
3739 f_sleep(1.0);
3740 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3741 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003742 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003743}
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003744/* Establish a Signalling channel with A5/4 encryption. */
3745testcase TC_ciph_mode_a5_4() runs on test_CT {
3746 var MSC_ConnHdlr vc_conn;
3747 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3748 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Harald Welte3c86ea02018-05-10 22:28:05 +02003749
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003750 f_init(1, true);
Oliver Smith26a3db72021-07-09 13:51:29 +02003751 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003752 f_sleep(1.0);
3753 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3754 vc_conn.done;
Oliver Smith26a3db72021-07-09 13:51:29 +02003755 f_vty_encryption_a5_reset();
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003756 f_shutdown_helper();
3757}
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003758/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
3759private function f_tc_assignment_aoip_tla_v6(charstring id) runs on MSC_ConnHdlr {
3760 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3761 var PDU_BSSAP ass_cmd := f_gen_ass_req(aoip_tla := "::3");
3762 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3763 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3764
3765 f_establish_fully(ass_cmd, exp_compl);
3766}
3767testcase TC_assignment_aoip_tla_v6() runs on test_CT {
3768 var MSC_ConnHdlr vc_conn;
3769 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3770
3771 f_init(1, true);
3772 f_sleep(1.0);
3773 vc_conn := f_start_handler(refers(f_tc_assignment_aoip_tla_v6), pars);
3774 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003775 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003776}
3777
Harald Welte3c86ea02018-05-10 22:28:05 +02003778
3779/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02003780private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003781 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3782 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003783
Harald Welte552620d2017-12-16 23:21:36 +01003784 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3785 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01003786
Harald Weltea0630032018-03-20 21:09:55 +01003787 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01003788}
Harald Welte552620d2017-12-16 23:21:36 +01003789testcase TC_assignment_fr_a5_0() runs on test_CT {
3790 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003791 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003792 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01003793
Harald Welte89d42e82017-12-17 16:42:41 +01003794 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003795 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003796 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003797 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003798 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003799}
Harald Welte552620d2017-12-16 23:21:36 +01003800testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01003801 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003802 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003803 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003804
Harald Welte89d42e82017-12-17 16:42:41 +01003805 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003806 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003807 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3808 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003809 f_shutdown_helper();
Harald Welte651fcdc2018-05-10 20:23:16 +02003810}
3811testcase TC_assignment_fr_a5_3() runs on test_CT {
3812 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003813 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003814 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003815
Harald Welte651fcdc2018-05-10 20:23:16 +02003816 f_init(1, true);
3817 f_sleep(1.0);
3818 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003819 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003820 f_shutdown_helper();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003821}
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003822/* Establish a Signalling channel and re-assign to TCH/F with A5/4 encryption. */
3823testcase TC_assignment_fr_a5_4() runs on test_CT {
3824 var MSC_ConnHdlr vc_conn;
3825 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3826 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
3827
3828 f_init(1, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02003829 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003830 f_sleep(1.0);
3831 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3832 vc_conn.done;
Oliver Smith7eabd312021-07-12 14:18:56 +02003833 f_vty_encryption_a5_reset();
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003834 f_shutdown_helper();
3835}
Harald Weltec1a2fff2017-12-17 11:06:19 +01003836
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +02003837/* Allow only A5/4, but omit the Kc128 IE from MSC's msg. Expect Cipher Mode Reject. */
3838testcase TC_assignment_fr_a5_4_fail() runs on test_CT {
3839 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3840 var MSC_ConnHdlr vc_conn;
3841
3842 f_init(1, true);
3843 f_sleep(1.0);
3844
3845 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8))); // A5/4 support, but Kc128 missing!
3846 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
3847 vc_conn.done;
3848 f_shutdown_helper();
3849}
3850
Harald Welte552620d2017-12-16 23:21:36 +01003851/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
3852private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003853 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01003854 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02003855 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003856
3857 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003858 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
3859
Harald Weltea0630032018-03-20 21:09:55 +01003860 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01003861}
Harald Welte552620d2017-12-16 23:21:36 +01003862testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
3863 var MSC_ConnHdlr vc_conn;
3864
Harald Welte89d42e82017-12-17 16:42:41 +01003865 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003866 f_sleep(1.0);
3867
Harald Welte8863fa12018-05-10 20:15:27 +02003868 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01003869 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003870 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003871}
3872
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003873private function f_TC_assignment_a5_not_sup(charstring id) runs on MSC_ConnHdlr {
3874 var template PDU_BSSAP exp_ass_cpl := f_gen_exp_compl();
3875 var PDU_BSSAP exp_ass_req := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003876
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003877 exp_ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3878 exp_ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3879
3880 /* this is like the beginning of f_establish_fully(), but only up to ciphering reject */
3881
3882 var BSSMAP_FIELD_CodecType codecType;
3883 timer T := 10.0;
3884
3885 codecType := exp_ass_req.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType;
3886 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
3887
3888 f_create_chan_and_exp();
3889 /* we should now have a COMPL_L3 at the MSC */
3890
3891 var template PDU_BSSAP exp_l3_compl;
3892 exp_l3_compl := tr_BSSMAP_ComplL3()
3893 if (g_pars.aoip == false) {
3894 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := omit;
3895 } else {
3896 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := ?;
3897 }
3898 T.start;
3899 alt {
3900 [] BSSAP.receive(exp_l3_compl);
3901 [] BSSAP.receive(tr_BSSMAP_ComplL3) {
3902 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching COMPLETE LAYER 3 INFORMATION");
3903 }
3904 [] T.timeout {
3905 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
3906 }
3907 }
3908
3909 /* Start ciphering, expect Cipher Mode Reject */
Neels Hofmeyr6c388f22021-06-11 02:36:56 +02003910 f_cipher_mode(g_pars.encr, exp_fail := true);
Harald Welte552620d2017-12-16 23:21:36 +01003911}
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003912testcase TC_assignment_fr_a5_not_sup() runs on test_CT {
3913 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01003914 var MSC_ConnHdlr vc_conn;
3915
Harald Welte89d42e82017-12-17 16:42:41 +01003916 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003917 f_sleep(1.0);
3918
Neels Hofmeyr0588cad2021-06-11 01:38:18 +02003919 pars.encr := valueof(t_EncrParams('20'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003920 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003921 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003922 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003923}
3924
3925
Harald Welte4532e0a2017-12-23 02:05:44 +01003926private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003927 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01003928 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02003929 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01003930 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003931
3932 f_statsd_reset();
Harald Weltea0630032018-03-20 21:09:55 +01003933 f_establish_fully(ass_cmd, exp_compl);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003934
3935 var StatsDExpects expect := {
Daniel Willmannc5398f72020-09-21 10:41:35 +02003936 { name := "TTCN3.bts.0.chreq.total", mtype := "c", min := 1, max := 1},
3937 { name := "TTCN3.bts.0.chreq.successful", mtype := "c", min := 1, max := 1},
Daniel Willmannebdecc02020-08-12 15:30:17 +02003938 { name := "TTCN3.bsc.0.assignment.attempted", mtype := "c", min := 1, max := 1},
3939 { name := "TTCN3.bsc.0.assignment.completed", mtype := "c", min := 1, max := 1}
3940 };
3941 f_statsd_expect(expect);
Harald Welte4532e0a2017-12-23 02:05:44 +01003942}
3943
3944testcase TC_assignment_sign() runs on test_CT {
3945 var MSC_ConnHdlr vc_conn;
3946
3947 f_init(1, true);
3948 f_sleep(1.0);
3949
Harald Welte8863fa12018-05-10 20:15:27 +02003950 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01003951 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003952 f_shutdown_helper();
Harald Welte4532e0a2017-12-23 02:05:44 +01003953}
3954
Harald Welte60aa5762018-03-21 19:33:13 +01003955/***********************************************************************
3956 * Codec (list) testing
3957 ***********************************************************************/
3958
3959/* check if the given rsl_mode is compatible with the a_elem */
3960private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
3961return boolean {
3962 select (a_elem.codecType) {
3963 case (GSM_FR) {
3964 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
3965 return true;
3966 }
3967 }
3968 case (GSM_HR) {
3969 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
3970 return true;
3971 }
3972 }
3973 case (GSM_EFR) {
3974 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
3975 return true;
3976 }
3977 }
3978 case (FR_AMR) {
3979 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
3980 return true;
3981 }
3982 }
3983 case (HR_AMR) {
3984 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
3985 return true;
3986 }
3987 }
3988 case else { }
3989 }
3990 return false;
3991}
3992
3993/* check if the given rsl_mode is compatible with the a_list */
3994private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
3995return boolean {
3996 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
3997 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
3998 return true;
3999 }
4000 }
4001 return false;
4002}
4003
4004/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02004005function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01004006return BSSMAP_IE_ChannelType {
4007 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
4008 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
4009 select (a_elem.codecType) {
4010 case (GSM_FR) {
4011 ret.channelRateAndType := ChRate_TCHF;
4012 ret.speechId_DataIndicator := Spdi_TCHF_FR;
4013 }
4014 case (GSM_HR) {
4015 ret.channelRateAndType := ChRate_TCHH;
4016 ret.speechId_DataIndicator := Spdi_TCHH_HR;
4017 }
4018 case (GSM_EFR) {
4019 ret.channelRateAndType := ChRate_TCHF;
4020 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
4021 }
4022 case (FR_AMR) {
4023 ret.channelRateAndType := ChRate_TCHF;
4024 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
4025 }
4026 case (HR_AMR) {
4027 ret.channelRateAndType := ChRate_TCHH;
4028 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
4029 }
4030 case else {
4031 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02004032 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01004033 }
4034 }
4035 return ret;
4036}
4037
Harald Weltea63b9102018-03-22 20:36:16 +01004038private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
4039return template RSL_IE_Body {
4040 var template RSL_IE_Body mode_ie := {
4041 chan_mode := {
4042 len := ?,
4043 reserved := ?,
4044 dtx_d := ?,
4045 dtx_u := ?,
4046 spd_ind := RSL_SPDI_SPEECH,
4047 ch_rate_type := -,
4048 coding_alg_rate := -
4049 }
4050 }
4051
4052 select (a_elem.codecType) {
4053 case (GSM_FR) {
4054 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4055 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
4056 }
4057 case (GSM_HR) {
4058 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
4059 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
4060 }
4061 case (GSM_EFR) {
4062 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4063 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
4064 }
4065 case (FR_AMR) {
4066 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
4067 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
4068 }
4069 case (HR_AMR) {
4070 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
4071 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
4072 }
4073 }
4074 return mode_ie;
4075}
4076
Harald Welte60aa5762018-03-21 19:33:13 +01004077type record CodecListTest {
4078 BSSMAP_IE_SpeechCodecList codec_list,
4079 charstring id
4080}
4081type record of CodecListTest CodecListTests
4082
4083private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004084 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
4085 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
Harald Welte60aa5762018-03-21 19:33:13 +01004086
4087 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02004088 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte79f3f542018-05-25 20:02:37 +02004089 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
4090 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
4091 g_pars.ass_codec_list.codecElements[0];
Philipp Maierd0e64b02019-03-13 14:15:23 +01004092 if (isvalue(g_pars.expect_mr_s0_s7)) {
4093 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
4094 g_pars.expect_mr_s0_s7;
4095 }
Harald Welte79f3f542018-05-25 20:02:37 +02004096 }
Harald Welte60aa5762018-03-21 19:33:13 +01004097 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
4098 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01004099 log("expecting ASS COMPL like this: ", exp_compl);
4100
4101 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01004102
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004103 if (not g_pars.expect_channel_mode_modify) {
4104 /* Verify that the RSL-side activation actually matches our expectations */
4105 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
Harald Weltea63b9102018-03-22 20:36:16 +01004106
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004107 var RSL_IE_Body mode_ie;
4108 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
4109 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02004110 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004111 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004112 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
4113 if (not match(mode_ie, t_mode_ie)) {
4114 log("mode_ie ", mode_ie, " != t_mode_ie ", t_mode_ie);
4115 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004116 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004117
4118 var RSL_IE_Body mr_conf;
4119 if (g_pars.expect_mr_conf_ie != omit) {
4120 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
4121 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
4122 mtc.stop;
4123 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004124 log("found RSL MR CONFIG IE: ", mr_conf);
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004125
4126 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
4127 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
4128 g_pars.expect_mr_conf_ie);
4129 }
4130 } else {
4131 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
4132 log("found RSL MR CONFIG IE: ", mr_conf);
4133 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
4134 mtc.stop;
4135 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004136 }
4137 }
Harald Welte60aa5762018-03-21 19:33:13 +01004138}
4139
Philipp Maierd0e64b02019-03-13 14:15:23 +01004140private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
4141
4142 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4143 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4144
4145 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02004146 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maierd0e64b02019-03-13 14:15:23 +01004147 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
4148 }
4149 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
4150 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
4151 log("expecting ASS FAIL like this: ", exp_fail);
4152
4153 f_establish_fully(ass_cmd, exp_fail);
4154}
4155
Harald Welte60aa5762018-03-21 19:33:13 +01004156testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004157 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004158 var MSC_ConnHdlr vc_conn;
4159
4160 f_init(1, true);
4161 f_sleep(1.0);
4162
4163 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004164 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004165 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004166 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004167}
4168
4169testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004170 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004171 var MSC_ConnHdlr vc_conn;
4172
4173 f_init(1, true);
4174 f_sleep(1.0);
4175
4176 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004177 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004178 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004179 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004180}
4181
4182testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004183 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004184 var MSC_ConnHdlr vc_conn;
4185
4186 f_init(1, true);
4187 f_sleep(1.0);
4188
4189 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02004190 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004191 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004192 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004193}
4194
Philipp Maierd0e64b02019-03-13 14:15:23 +01004195/* Allow 5,90k only (current default config) */
4196private function f_allow_amr_rate_5_90k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00004197 f_vty_cfg_msc(BSCVTY, 0, {
4198 "amr-config 12_2k forbidden",
4199 "amr-config 10_2k forbidden",
4200 "amr-config 7_95k forbidden",
4201 "amr-config 7_40k forbidden",
4202 "amr-config 6_70k forbidden",
4203 "amr-config 5_90k allowed",
4204 "amr-config 5_15k forbidden",
4205 "amr-config 4_75k forbidden"
4206 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01004207}
4208
4209/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
4210 * ("Config-NB-Code = 1") */
4211private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00004212 f_vty_cfg_msc(BSCVTY, 0, {
4213 "amr-config 12_2k allowed",
4214 "amr-config 10_2k forbidden",
4215 "amr-config 7_95k forbidden",
4216 "amr-config 7_40k allowed",
4217 "amr-config 6_70k forbidden",
4218 "amr-config 5_90k allowed",
4219 "amr-config 5_15k forbidden",
4220 "amr-config 4_75k allowed"
4221 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01004222}
4223
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004224private function f_vty_amr_start_mode_set(boolean fr, charstring startmode) runs on test_CT {
4225 var charstring tch;
4226 if (fr) {
4227 tch := "tch-f";
4228 } else {
4229 tch := "tch-h";
4230 }
4231 f_vty_cfg_bts(BSCVTY, 0, { "amr " & tch & " start-mode " & startmode });
4232}
4233
4234/* Set the AMR start-mode for this TCH back to the default configuration. */
4235private function f_vty_amr_start_mode_restore(boolean fr) runs on test_CT {
4236 f_vty_amr_start_mode_set(fr, "auto");
4237}
4238
Harald Welte60aa5762018-03-21 19:33:13 +01004239testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02004240 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01004241 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02004242
4243 /* Note: This setups the codec configuration. The parameter payload in
4244 * mr_conf must be consistant with the parameter codecElements in pars
4245 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004246 var RSL_IE_Body mr_conf := {
4247 other := {
4248 len := 2,
4249 payload := '2804'O
4250 }
4251 };
Harald Welte60aa5762018-03-21 19:33:13 +01004252
Philipp Maier7695a0d2018-09-27 17:52:14 +02004253 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Philipp Maier806f8f12019-03-12 12:13:41 +01004254 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02004255 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
4256 pars.expect_mr_conf_ie := mr_conf;
4257
Harald Welte60aa5762018-03-21 19:33:13 +01004258 f_init(1, true);
4259 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004260 f_vty_amr_start_mode_set(true, "1");
Harald Welte60aa5762018-03-21 19:33:13 +01004261
Harald Welte8863fa12018-05-10 20:15:27 +02004262 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004263 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004264
4265 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004266 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004267}
4268
4269testcase TC_assignment_codec_amr_h() 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;
Philipp Maier7695a0d2018-09-27 17:52:14 +02004272
4273 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02004274 var RSL_IE_Body mr_conf := {
4275 other := {
4276 len := 2,
4277 payload := '2804'O
4278 }
4279 };
Harald Welte60aa5762018-03-21 19:33:13 +01004280
Philipp Maier7695a0d2018-09-27 17:52:14 +02004281 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Philipp Maier806f8f12019-03-12 12:13:41 +01004282 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02004283 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4284 pars.expect_mr_conf_ie := mr_conf;
4285
Harald Welte60aa5762018-03-21 19:33:13 +01004286 f_init(1, true);
4287 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004288 f_vty_amr_start_mode_set(false, "1");
Harald Welte60aa5762018-03-21 19:33:13 +01004289
Harald Welte8863fa12018-05-10 20:15:27 +02004290 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01004291 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004292
4293 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004294 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01004295}
4296
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004297/* Establish signalling on a TCH/F lchan, and then switch to speech mode without a new Assignment. */
4298testcase TC_assignment_codec_fr_by_mode_modify() runs on test_CT {
4299 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4300 var MSC_ConnHdlr vc_conn;
4301
4302 f_init(1, true);
4303 f_sleep(1.0);
4304
4305 /* By disabling all SDCCH, the MS should be given a TCH/F for signalling. Then activating an FR codec should
4306 * merely do a Channel Mode Modify, and not assign to a new lchan. f_establish_fully() already accounts for
4307 * expecting a Channel Mode Modify if the channel type is compatible. */
4308 f_disable_all_sdcch();
4309 f_disable_all_tch_h();
4310
4311 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4312 pars.expect_channel_mode_modify := true;
4313 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4314 vc_conn.done;
4315
4316 f_enable_all_sdcch();
4317 f_enable_all_tch();
4318 f_shutdown_helper();
4319}
4320
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004321/* 'amr start-mode auto' should not keep the (unused) 'smod' bits from previous configuration */
4322testcase TC_assignment_codec_amr_startmode_cruft() runs on test_CT {
4323 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4324 var MSC_ConnHdlr vc_conn;
4325
4326 var RSL_IE_Body mr_conf := {
4327 other := {
4328 len := 2,
4329 payload := '2004'O /* <- expect ICMI=0, smod=00 */
4330 }
4331 };
4332
4333 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4334 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
4335 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
4336 pars.expect_mr_conf_ie := mr_conf;
4337
4338 f_init(1, true);
4339 f_sleep(1.0);
4340
4341 /* First set nonzero start mode bits */
4342 f_vty_amr_start_mode_set(true, "4");
4343 /* Now set to auto, and expect the startmode bits to be zero in the message, i.e. ensure that osmo-bsc does not
4344 * let the startmode bits stick around and has deterministic MultiRate config for 'start-mode auto'; that is
4345 * ensured by above '2004'O, where 'x0xx'O indicates ICMI = 0, spare = 0, smod = 00. */
4346 f_vty_amr_start_mode_set(true, "auto");
4347
4348 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4349 vc_conn.done;
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004350
4351 /* Clear the startmode bits to not affect subsequent tests, in case the bits should indeed stick around. */
4352 f_vty_amr_start_mode_set(true, "1");
4353 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004354 f_shutdown_helper();
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004355}
4356
Neels Hofmeyr21863562020-11-26 00:34:33 +00004357function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0,
4358 charstring start_mode := "1")
Philipp Maierd0e64b02019-03-13 14:15:23 +01004359runs on test_CT {
4360
4361 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4362 var MSC_ConnHdlr vc_conn;
4363
4364 /* See note above */
4365 var RSL_IE_Body mr_conf := {
4366 other := {
4367 len := lengthof(mrconf),
4368 payload := mrconf
4369 }
4370 };
4371
4372 if (fr) {
4373 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4374 } else {
4375 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4376 }
4377 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4378 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4379 pars.expect_mr_conf_ie := mr_conf;
4380 pars.expect_mr_s0_s7 := exp_s8_s0;
4381
4382 f_init(1, true);
4383 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004384 f_vty_amr_start_mode_set(fr, start_mode);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004385 f_sleep(1.0);
4386
4387 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4388 vc_conn.done;
4389 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004390 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004391}
4392
4393function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
4394runs on test_CT {
4395
4396 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4397 var MSC_ConnHdlr vc_conn;
4398
4399 if (fr) {
4400 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4401 } else {
4402 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4403 }
4404 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4405 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4406
4407 f_init(1, true);
4408 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004409 f_vty_amr_start_mode_set(fr, "1");
Philipp Maierd0e64b02019-03-13 14:15:23 +01004410 f_sleep(1.0);
4411
4412 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
4413 vc_conn.done;
4414 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004415 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004416}
4417
4418
4419/* Set S1, we expect an AMR multirate configuration IE with all four rates
4420 * set. */
4421testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004422 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004423 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004424}
4425
4426/* Set S1, we expect an AMR multirate configuration IE with the lower three
4427 * rates set. */
4428testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004429 f_TC_assignment_codec_amr(false, '2815208820'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004430 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004431}
4432
4433/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4434 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4435testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004436 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004437 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004438}
4439
4440/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4441 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4442testcase TC_assignment_codec_amr_h_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004443 f_TC_assignment_codec_amr(false, '2815208820'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004444 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004445}
4446
4447/* The following block of tests selects more and more rates until all four
4448 * possible rates are in the active set (full rate) */
4449testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004450 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004451 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004452}
4453
4454testcase TC_assignment_codec_amr_f_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004455 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004456 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004457}
4458
4459testcase TC_assignment_codec_amr_f_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004460 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004461 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004462}
4463
4464testcase TC_assignment_codec_amr_f_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004465 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004466 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004467}
4468
4469/* The following block of tests selects more and more rates until all three
4470 * possible rates are in the active set (half rate) */
4471testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004472 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004473 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004474}
4475
4476testcase TC_assignment_codec_amr_h_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004477 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004478 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004479}
4480
4481testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004482 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004483 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004484}
4485
4486/* The following block tests what happens when the MSC does offer rate
4487 * configurations that are not supported by the BSC. Normally such situations
4488 * should not happen because the MSC gets informed by the BSC in advance via
4489 * the L3 COMPLETE message which rates are applicable. The MSC should not try
4490 * to offer rates that are not applicable anyway. */
4491
4492testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004493 /* Try to include 12,2k in into the active set even though the channel
4494 * is half rate only. The BSC is expected to remove the 12,0k */
4495 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004496 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004497}
4498
4499testcase TC_assignment_codec_amr_f_S01234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004500 /* See what happens when all rates are selected at once. Since then
4501 * Also S1 is selected, this setting will be prefered and we should
4502 * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
4503 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004504 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004505}
4506
4507testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004508 /* Same as above, but with S1 missing, the MSC is then expected to
4509 * select the currently supported rates, which are also 12.2k, 7,40k,
4510 * 5,90k, and 4,75k, into the active set. */
4511 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004512 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004513}
4514
4515testcase TC_assignment_codec_amr_f_zero() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004516 /* Try to select no rates at all */
4517 f_TC_assignment_codec_amr_fail(true, '00000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004518 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004519}
4520
4521testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004522 /* Try to select only unsupported rates */
4523 f_TC_assignment_codec_amr_fail(true, '01101000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004524 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004525}
4526
4527testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004528 /* Try to select 12,2k for half rate */
4529 f_TC_assignment_codec_amr_fail(false, '10000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004530 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004531}
4532
Neels Hofmeyr21863562020-11-26 00:34:33 +00004533testcase TC_assignment_codec_amr_f_start_mode_auto() runs on test_CT {
4534 f_TC_assignment_codec_amr(true, '209520882208'O, '11111111'B, '00000010'B,
4535 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004536 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004537}
4538
4539testcase TC_assignment_codec_amr_h_start_mode_auto() runs on test_CT {
4540 f_TC_assignment_codec_amr(false, '2015208820'O, '10010101'B, '00010101'B,
4541 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004542 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004543}
4544
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004545testcase TC_assignment_codec_amr_f_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004546 /* "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 +00004547 f_TC_assignment_codec_amr(true, '2b9520882208'O, '11111111'B, '00000010'B,
4548 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004549 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004550}
4551
4552testcase TC_assignment_codec_amr_h_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004553 /* "amr tch-h modes 0 2 4" => total 3 modes and start mode 4 => '10'B on the wire */
4554 f_TC_assignment_codec_amr(false, '2a15208820'O, '10010101'B, '00010101'B,
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004555 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004556 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004557}
4558
Philipp Maierac09bfc2019-01-08 13:41:39 +01004559private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004560 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
4561 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
4562 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
4563 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004564}
4565
4566private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004567 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
4568 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004569}
4570
4571private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004572 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
4573 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
4574 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
4575 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
4576 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
4577 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004578}
4579
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004580private function f_disable_all_sdcch() runs on test_CT {
4581 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 borken");
4582 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 borken");
4583 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 borken");
4584 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 borken");
4585}
4586
4587private function f_enable_all_sdcch() runs on test_CT {
4588 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 unused");
4589 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 unused");
4590 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 unused");
4591 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 unused");
4592}
4593
Philipp Maierac09bfc2019-01-08 13:41:39 +01004594/* Allow HR only */
4595private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
4596 g_pars := f_gen_test_hdlr_pars();
4597 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4598 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4599 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4600 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4601 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4602 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4603 f_establish_fully(ass_cmd, exp_compl);
4604}
4605
4606/* Allow FR only */
4607private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
4608 g_pars := f_gen_test_hdlr_pars();
4609 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4610 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4611 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4612 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4613 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4614 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4615 f_establish_fully(ass_cmd, exp_compl);
4616}
4617
4618/* Allow HR only (expect assignment failure) */
4619private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
4620 g_pars := f_gen_test_hdlr_pars();
4621 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4622 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4623 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4624 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4625 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4626 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4627 f_establish_fully(ass_cmd, exp_fail);
4628}
4629
4630/* Allow FR only (expect assignment failure) */
4631private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(charstring id) runs on MSC_ConnHdlr {
4632 g_pars := f_gen_test_hdlr_pars();
4633 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4634 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4635 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4636 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4637 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4638 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4639 f_establish_fully(ass_cmd, exp_fail);
4640}
4641
4642/* Allow FR and HR, but prefer FR */
4643private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4644 g_pars := f_gen_test_hdlr_pars();
4645 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4646 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4647 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4648 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4649 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4650 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4651 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4652 f_establish_fully(ass_cmd, exp_compl);
4653}
4654
4655/* Allow FR and HR, but prefer HR */
4656private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4657 g_pars := f_gen_test_hdlr_pars();
4658 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4659 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4660 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4661 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4662 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4663 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4664 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4665 f_establish_fully(ass_cmd, exp_compl);
4666}
4667
4668/* Allow FR and HR, but prefer FR */
4669private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4670 g_pars := f_gen_test_hdlr_pars();
4671 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4672 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4673 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4674 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4675 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4676 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4677 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4678 f_establish_fully(ass_cmd, exp_compl);
4679}
4680
4681/* Allow FR and HR, but prefer HR */
4682private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4683 g_pars := f_gen_test_hdlr_pars();
4684 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4685 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4686 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4687 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4688 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4689 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4690 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4691 f_establish_fully(ass_cmd, exp_compl);
4692}
4693
4694/* Request a HR channel while all FR channels are exhausted, this is expected
4695 * to work without conflicts */
4696testcase TC_assignment_codec_fr_exhausted_req_hr() runs on test_CT {
4697 var MSC_ConnHdlr vc_conn;
4698 f_init(1, true);
4699 f_sleep(1.0);
4700 f_enable_all_tch();
4701 f_disable_all_tch_f();
4702 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr));
4703 vc_conn.done;
4704 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004705 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004706}
4707
4708/* Request a FR channel while all FR channels are exhausted, this is expected
4709 * to fail. */
4710testcase TC_assignment_codec_fr_exhausted_req_fr() runs on test_CT {
4711 var MSC_ConnHdlr vc_conn;
4712 f_init(1, true);
4713 f_sleep(1.0);
4714 f_enable_all_tch();
4715 f_disable_all_tch_f();
4716 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr_fail));
4717 vc_conn.done;
4718 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004719 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004720}
4721
4722/* Request a FR (prefered) or alternatively a HR channel while all FR channels
4723 * are exhausted, this is expected to be resolved by selecting a HR channel. */
4724testcase TC_assignment_codec_fr_exhausted_req_fr_hr() runs on test_CT {
4725 var MSC_ConnHdlr vc_conn;
4726 f_init(1, true);
4727 f_sleep(1.0);
4728 f_enable_all_tch();
4729 f_disable_all_tch_f();
4730 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
4731 vc_conn.done;
4732 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004733 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004734}
4735
4736/* Request a HR (prefered) or alternatively a FR channel while all FR channels
4737 * are exhausted, this is expected to work without conflicts. */
4738testcase TC_assignment_codec_fr_exhausted_req_hr_fr() runs on test_CT {
4739 var MSC_ConnHdlr vc_conn;
4740 f_init(1, true);
4741 f_sleep(1.0);
4742 f_enable_all_tch();
4743 f_disable_all_tch_f();
4744 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_hr_fr));
4745 vc_conn.done;
4746 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004747 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004748}
4749
4750/* Request a FR channel while all HR channels are exhausted, this is expected
4751 * to work without conflicts */
4752testcase TC_assignment_codec_hr_exhausted_req_fr() runs on test_CT {
4753 var MSC_ConnHdlr vc_conn;
4754 f_init(1, true);
4755 f_sleep(1.0);
4756 f_enable_all_tch();
4757 f_disable_all_tch_h();
4758 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr));
4759 vc_conn.done;
4760 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004761 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004762}
4763
4764/* Request a HR channel while all HR channels are exhausted, this is expected
4765 * to fail. */
4766testcase TC_assignment_codec_hr_exhausted_req_hr() runs on test_CT {
4767 var MSC_ConnHdlr vc_conn;
4768 f_init(1, true);
4769 f_sleep(1.0);
4770 f_enable_all_tch();
4771 f_disable_all_tch_h();
4772 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr_fail));
4773 vc_conn.done;
4774 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004775 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004776}
4777
4778/* Request a HR (prefered) or alternatively a FR channel while all HR channels
4779 * are exhausted, this is expected to be resolved by selecting a FR channel. */
4780testcase TC_assignment_codec_hr_exhausted_req_hr_fr() runs on test_CT {
4781 var MSC_ConnHdlr vc_conn;
4782 f_init(1, true);
4783 f_sleep(1.0);
4784 f_enable_all_tch();
4785 f_disable_all_tch_h();
4786 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_hr_fr));
4787 vc_conn.done;
4788 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004789 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004790}
4791
4792/* Request a FR (prefered) or alternatively a HR channel while all HR channels
4793 * are exhausted, this is expected to work without conflicts. */
4794testcase TC_assignment_codec_hr_exhausted_req_fr_hr() runs on test_CT {
4795 var MSC_ConnHdlr vc_conn;
4796 f_init(1, true);
4797 f_sleep(1.0);
4798 f_enable_all_tch();
4799 f_disable_all_tch_h();
4800 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_fr_hr));
4801 vc_conn.done;
4802 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004803 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004804}
4805
4806/* Allow FR and HR, but prefer HR */
4807private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4808 g_pars := f_gen_test_hdlr_pars();
4809 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4810 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4811 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4812 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4813 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4814 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4815 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4816 f_establish_fully(ass_cmd, exp_compl);
4817}
4818
4819/* Allow FR and HR, but prefer FR */
4820private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4821 g_pars := f_gen_test_hdlr_pars();
4822 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4823 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4824 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4825 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4826 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4827 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4828 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4829 f_establish_fully(ass_cmd, exp_compl);
4830}
4831
4832/* Request a HR (prefered) or alternatively a FR channel, it is expected that
4833 * HR, which is the prefered type, is selected. */
4834testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
4835 var MSC_ConnHdlr vc_conn;
4836 f_init(1, true);
4837 f_sleep(1.0);
4838 f_enable_all_tch();
4839 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
4840 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004841 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004842}
4843
4844/* Request a FR (prefered) or alternatively a HR channel, it is expected that
4845 * FR, which is the prefered type, is selected. */
4846testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
4847 var MSC_ConnHdlr vc_conn;
4848 f_init(1, true);
4849 f_sleep(1.0);
4850 f_enable_all_tch();
4851 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
4852 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004853 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004854}
4855
Pau Espin Pedrol14475352021-07-22 15:48:16 +02004856/* request a signalling channel with all SDCCH exhausted, it is expected that a TCH will be selected */
4857private function f_TC_assignment_sdcch_exhausted_req_signalling(charstring id) runs on MSC_ConnHdlr {
4858 g_pars := f_gen_test_hdlr_pars();
4859 g_pars.ra := '02'O; /* RA containing reason=LU */
4860
4861 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
4862 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
4863 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
4864 var template uint3_t tsc := ?;
4865
4866 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
4867 f_create_bssmap_exp(l3_enc);
4868 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
4869 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, tsc);
4870
4871 /* we should now have a COMPL_L3 at the MSC */
4872 timer T := 10.0;
4873 T.start;
4874 alt {
4875 [] BSSAP.receive(tr_BSSMAP_ComplL3);
4876 [] T.timeout {
4877 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
4878 }
4879 }
4880}
4881testcase TC_assignment_sdcch_exhausted_req_signalling() runs on test_CT {
4882 var MSC_ConnHdlr vc_conn;
4883 f_init(1, true);
4884 f_sleep(1.0);
4885 f_disable_all_sdcch();
4886 vc_conn := f_start_handler(refers(f_TC_assignment_sdcch_exhausted_req_signalling));
4887 vc_conn.done;
4888 f_enable_all_sdcch();
4889 f_shutdown_helper();
4890}
4891
4892/* Request a signalling channel with all SDCCH exhausted, it is
4893 expected that no TCH will be selected for signalling and assigment will fail
4894 because it's dictated by VTY config */
4895testcase TC_assignment_sdcch_exhausted_req_signalling_tch_forbidden() runs on test_CT {
4896 var RSL_Message rsl_unused, rsl_msg;
4897 var GsmRrMessage rr;
4898 f_init(1, false);
4899 f_sleep(1.0);
4900 f_vty_allow_tch_for_signalling(false, 0);
4901 f_disable_all_sdcch();
4902
4903 /* RA containing reason=LU */
4904 f_ipa_tx(0, ts_RSL_CHAN_RQD('02'O, 2342));
4905 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
4906 rr := dec_GsmRrMessage(rsl_msg.ies[1].body.full_imm_ass_info.payload);
4907 if (rr.header.message_type != IMMEDIATE_ASSIGNMENT_REJECT) {
4908 setverdict(fail, "Expected reject");
4909 }
4910
4911 f_vty_allow_tch_for_signalling(true, 0);
4912 f_enable_all_sdcch();
4913 f_shutdown_helper();
4914}
4915
4916/* Request a voice channel with all SDCCH exhausted, it is
4917 * expected that TCH channel will be allocated since the VTY option is only
4918 * aimed at signalling requests */
4919private function f_TC_assignment_sdcch_exhausted_req_voice_tch_forbidden(charstring id) runs on MSC_ConnHdlr {
4920 g_pars := f_gen_test_hdlr_pars();
4921 g_pars.ra := '43'O; /* RA containing reason=originating speech call*/
4922
4923 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
4924 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
4925 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
4926 var template uint3_t tsc := ?;
4927
4928 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
4929 f_create_bssmap_exp(l3_enc);
4930 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
4931 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, tsc);
4932
4933 /* we should now have a COMPL_L3 at the MSC */
4934 timer T := 10.0;
4935 T.start;
4936 alt {
4937 [] BSSAP.receive(tr_BSSMAP_ComplL3);
4938 [] T.timeout {
4939 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
4940 }
4941 }
4942}
4943testcase TC_assignment_sdcch_exhausted_req_voice_tch_forbidden() runs on test_CT {
4944 var MSC_ConnHdlr vc_conn;
4945 f_init(1, true);
4946 f_sleep(1.0);
4947 f_vty_allow_tch_for_signalling(false, 0);
4948 f_disable_all_sdcch();
4949
4950 vc_conn := f_start_handler(refers(f_TC_assignment_sdcch_exhausted_req_voice_tch_forbidden));
4951 vc_conn.done;
4952
4953 f_vty_allow_tch_for_signalling(true, 0);
4954 f_enable_all_sdcch();
4955 f_shutdown_helper();
4956}
4957
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004958testcase TC_assignment_osmux() runs on test_CT {
4959 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4960 var MSC_ConnHdlr vc_conn;
4961
4962 /* See note above */
4963 var RSL_IE_Body mr_conf := {
4964 other := {
4965 len := 2,
4966 payload := '2804'O
4967 }
4968 };
4969
4970 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4971 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
4972 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4973 pars.expect_mr_conf_ie := mr_conf;
4974 pars.use_osmux := true;
4975
4976 f_init(1, true, true);
4977 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004978 f_vty_amr_start_mode_set(false, "1");
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004979
4980 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4981 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004982
4983 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004984 f_shutdown_helper();
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004985}
4986
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02004987/* test the procedure of the MSC requesting a Classmark Update:
4988 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
4989 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01004990private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02004991 g_pars := f_gen_test_hdlr_pars();
4992
Harald Weltea0630032018-03-20 21:09:55 +01004993 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01004994 /* we should now have a COMPL_L3 at the MSC */
4995 BSSAP.receive(tr_BSSMAP_ComplL3);
4996
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02004997 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
4998 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
4999
Harald Welte898113b2018-01-31 18:32:21 +01005000 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
5001 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
5002 setverdict(pass);
5003}
5004testcase TC_classmark() runs on test_CT {
5005 var MSC_ConnHdlr vc_conn;
5006 f_init(1, true);
5007 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005008 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01005009 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005010 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01005011}
5012
Harald Welteeddf0e92020-06-21 19:42:15 +02005013/* Send a CommonID from the simulated MSC and verify that the information is used to
5014 * fill BSC-internal data structures (specifically, bsc_subscr associated with subscr_conn) */
5015private function f_tc_common_id(charstring id) runs on MSC_ConnHdlr {
5016 g_pars := f_gen_test_hdlr_pars();
5017 f_MscConnHdlr_init_vty();
5018
5019 f_create_chan_and_exp();
5020 /* we should now have a COMPL_L3 at the MSC */
5021 BSSAP.receive(tr_BSSMAP_ComplL3);
5022
5023 /* Send CommonID */
5024 BSSAP.send(ts_BSSMAP_CommonId(g_pars.imsi));
5025
5026 /* Use VTY to verify that the IMSI of the subscr_conn is set */
5027 var charstring regex := "*(IMSI: " & hex2str(g_pars.imsi) & ")*";
5028 f_vty_transceive_match_regexp_retry(BSCVTY, "show conns", regex, 0, 4, 1.0);
5029
5030 setverdict(pass);
5031}
5032testcase TC_common_id() runs on test_CT {
5033 var MSC_ConnHdlr vc_conn;
5034 f_init(1, true);
5035 f_sleep(1.0);
5036 vc_conn := f_start_handler(refers(f_tc_common_id));
5037 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005038 f_shutdown_helper();
Harald Welteeddf0e92020-06-21 19:42:15 +02005039}
5040
Harald Weltee3bd6582018-01-31 22:51:25 +01005041private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005042 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01005043 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01005044 /* we should now have a COMPL_L3 at the MSC */
5045 BSSAP.receive(tr_BSSMAP_ComplL3);
5046
Harald Weltee3bd6582018-01-31 22:51:25 +01005047 /* send the single message we want to send */
5048 f_rsl_send_l3(l3);
5049}
5050
5051private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
5052 timer T := sec;
5053 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01005054 T.start;
5055 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01005056 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
5057 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02005058 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01005059 }
5060 [] T.timeout {
5061 setverdict(pass);
5062 }
5063 }
5064}
5065
Harald Weltee3bd6582018-01-31 22:51:25 +01005066/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
5067private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
5068 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
5069 f_bssap_expect_nothing();
5070}
Harald Welte898113b2018-01-31 18:32:21 +01005071testcase TC_unsol_ass_fail() runs on test_CT {
5072 var MSC_ConnHdlr vc_conn;
5073 f_init(1, true);
5074 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005075 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01005076 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005077 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01005078}
Harald Welte552620d2017-12-16 23:21:36 +01005079
Harald Welteea99a002018-01-31 20:46:43 +01005080
5081/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
5082private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01005083 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
5084 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01005085}
5086testcase TC_unsol_ass_compl() runs on test_CT {
5087 var MSC_ConnHdlr vc_conn;
5088 f_init(1, true);
5089 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005090 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01005091 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005092 f_shutdown_helper();
Harald Welteea99a002018-01-31 20:46:43 +01005093}
5094
5095
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005096/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
5097private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01005098 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
5099 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005100}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005101testcase TC_unsol_ho_fail() runs on test_CT {
5102 var MSC_ConnHdlr vc_conn;
5103 f_init(1, true);
5104 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005105 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005106 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005107 f_shutdown_helper();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01005108}
5109
5110
Harald Weltee3bd6582018-01-31 22:51:25 +01005111/* short message from MS should be ignored */
5112private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02005113 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01005114 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01005115 /* we should now have a COMPL_L3 at the MSC */
5116 BSSAP.receive(tr_BSSMAP_ComplL3);
5117
5118 /* send short message */
5119 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
5120 f_bssap_expect_nothing();
5121}
5122testcase TC_err_82_short_msg() runs on test_CT {
5123 var MSC_ConnHdlr vc_conn;
5124 f_init(1, true);
5125 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005126 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01005127 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005128 f_shutdown_helper();
Harald Weltee3bd6582018-01-31 22:51:25 +01005129}
5130
5131
Harald Weltee9e02e42018-01-31 23:36:25 +01005132/* 24.008 8.4 Unknown message must trigger RR STATUS */
5133private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
5134 f_est_single_l3(ts_RRM_UL_REL('00'O));
5135 timer T := 3.0
5136 alt {
5137 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
5138 setverdict(pass);
5139 }
5140 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01005141 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01005142 }
5143}
5144testcase TC_err_84_unknown_msg() runs on test_CT {
5145 var MSC_ConnHdlr vc_conn;
5146 f_init(1, true);
5147 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02005148 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01005149 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005150 f_shutdown_helper();
Harald Weltee9e02e42018-01-31 23:36:25 +01005151}
5152
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005153/***********************************************************************
5154 * Handover
5155 ***********************************************************************/
5156
Harald Welte94e0c342018-04-07 11:33:23 +02005157/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
5158private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
5159runs on test_CT {
5160 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
5161 " timeslot "&int2str(ts_nr)&" ";
5162 f_vty_transceive(BSCVTY, cmd & suffix);
5163}
5164
Harald Welte261af4b2018-02-12 21:20:39 +01005165/* 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 +07005166private function f_vty_ss_action(TELNETasp_PT pt, charstring suffix,
5167 uint8_t bts_nr, uint8_t trx_nr,
5168 in RslChannelNr chan_nr)
5169{
Harald Welte261af4b2018-02-12 21:20:39 +01005170 /* FIXME: resolve those from component-global state */
5171 var integer ts_nr := chan_nr.tn;
5172 var integer ss_nr;
5173 if (ischosen(chan_nr.u.ch0)) {
5174 ss_nr := 0;
5175 } else if (ischosen(chan_nr.u.lm)) {
5176 ss_nr := chan_nr.u.lm.sub_chan;
5177 } else if (ischosen(chan_nr.u.sdcch4)) {
5178 ss_nr := chan_nr.u.sdcch4.sub_chan;
5179 } else if (ischosen(chan_nr.u.sdcch8)) {
5180 ss_nr := chan_nr.u.sdcch8.sub_chan;
5181 } else {
5182 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02005183 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01005184 }
5185
5186 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
5187 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005188 f_vty_transceive(pt, cmd & suffix);
Harald Welte261af4b2018-02-12 21:20:39 +01005189}
5190
Neels Hofmeyr91401012019-07-11 00:42:35 +02005191/* Even though the VTY command to trigger handover takes a new BTS number as argument, behind the scenes osmo-bsc always
5192 * translates that to a target ARFCN+BSIC first. See bsc_vty.c trigger_ho_or_as(), which puts the selected BTS' neighbor
5193 * ident key (ARFCN + BSIC) in the struct passed on to handover_request(). handover_start() then resolves that to a
5194 * viable actual neighbor cell. So from the internal osmo-bsc perspective, we always request handover to an ARFCN + BSIC
5195 * pair, not really to a specific BTS number. */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005196private function f_vty_handover(TELNETasp_PT pt, uint8_t bts_nr, uint8_t trx_nr,
5197 in RslChannelNr chan_nr, uint8_t new_bts_nr)
5198{
5199 f_vty_ss_action(pt, "handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
Harald Welte261af4b2018-02-12 21:20:39 +01005200}
5201
5202/* intra-BSC hand-over between BTS0 and BTS1 */
5203private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02005204 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5205 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01005206
5207 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5208 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5209
Harald Weltea0630032018-03-20 21:09:55 +01005210 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005211 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Harald Welte261af4b2018-02-12 21:20:39 +01005212
5213 var HandoverState hs := {
5214 rr_ho_cmpl_seen := false,
5215 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02005216 old_chan_nr := -,
5217 expect_target_tsc := BTS_TSC[1]
Harald Welte261af4b2018-02-12 21:20:39 +01005218 };
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005219 /* issue hand-over command on VTY, from BTS 0 to BTS 1 */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07005220 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
Harald Welte261af4b2018-02-12 21:20:39 +01005221 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
5222 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005223
5224 /* From the MGW perspective, a handover is is characterized by
5225 * performing one MDCX operation with the MGW. So we expect to see
5226 * one more MDCX during handover. */
5227 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
5228
Harald Welte261af4b2018-02-12 21:20:39 +01005229 alt {
5230 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01005231 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005232
Philipp Maier4dae0652018-11-12 12:03:26 +01005233 /* Since this is an internal handover we expect the BSC to inform the
5234 * MSC about the event */
5235 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
5236
Philipp Maier3e2af5d2018-07-11 17:01:05 +02005237 /* Check the amount of MGCP transactions is still consistant with the
5238 * test expectation */
5239 f_check_mgcp_expectations()
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005240
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005241 var RSL_Message chan_act := f_rslem_get_last_act(RSL1_PROC, 0, g_chan_nr);
5242
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005243 /* Ensure the Channel Activation for the new channel contained the right encryption params. as_handover() set
5244 * 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 +02005245 f_verify_encr_info(chan_act);
5246
5247 f_chan_act_verify_tsc(chan_act, BTS_TSC[1]);
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005248
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01005249 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01005250}
5251
5252testcase TC_ho_int() runs on test_CT {
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02005253 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte261af4b2018-02-12 21:20:39 +01005254 var MSC_ConnHdlr vc_conn;
5255 f_init(2, true);
5256 f_sleep(1.0);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005257
Neels Hofmeyrc2cf4542021-10-02 12:26:38 +02005258 pars.expect_tsc := BTS_TSC[0];
5259
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005260 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005261
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02005262 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
Harald Welte261af4b2018-02-12 21:20:39 +01005263 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005264
5265 /* from f_establish_fully() */
5266 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5267 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5268 /* from handover */
5269 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5270 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5271 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5272 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005273 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5274 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:completed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005275 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005276 f_shutdown_helper();
Harald Welte261af4b2018-02-12 21:20:39 +01005277}
Harald Weltee9e02e42018-01-31 23:36:25 +01005278
Oliver Smith7eabd312021-07-12 14:18:56 +02005279function 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 +02005280 var MSC_ConnHdlr vc_conn;
5281 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5282 pars.encr := valueof(t_EncrParams(encr_alg, f_rnd_octstring(8), f_rnd_octstring(16)));
5283
5284 f_init(2, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02005285 f_vty_encryption_a5(enc_a5);
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005286 f_sleep(1.0);
5287
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005288 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005289
5290 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
5291 vc_conn.done;
5292
5293 /* from f_establish_fully() */
5294 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5295 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5296 /* from handover */
5297 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5298 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5299 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5300 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005301 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5302 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:completed");
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005303 f_ctrs_bsc_and_bts_verify();
Oliver Smith7eabd312021-07-12 14:18:56 +02005304 f_vty_encryption_a5_reset();
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005305 f_shutdown_helper();
5306}
5307
5308testcase TC_ho_int_a5_0() runs on test_CT {
5309 f_tc_ho_int_a5('01'O);
5310}
5311
5312testcase TC_ho_int_a5_1() runs on test_CT {
5313 f_tc_ho_int_a5('02'O);
5314}
5315
5316testcase TC_ho_int_a5_3() runs on test_CT {
5317 f_tc_ho_int_a5('08'O);
5318}
5319
5320testcase TC_ho_int_a5_4() runs on test_CT {
Oliver Smith7eabd312021-07-12 14:18:56 +02005321 f_tc_ho_int_a5('10'O, "0 1 3 4");
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02005322}
5323
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005324/* intra-BSC hand-over with CONNection FAILure and cause Radio Link Failure: check RR release cause */
5325private function f_tc_ho_int_radio_link_failure(charstring id) runs on MSC_ConnHdlr {
5326 g_pars := f_gen_test_hdlr_pars();
5327 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5328 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005329
5330 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5331 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5332
5333 f_establish_fully(ass_cmd, exp_compl);
5334 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
5335
5336 var HandoverState hs := {
5337 rr_ho_cmpl_seen := false,
5338 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02005339 old_chan_nr := -,
5340 expect_target_tsc := BTS_TSC[1]
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005341 };
5342 /* issue hand-over command on VTY */
5343 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
5344 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
5345 f_rslem_suspend(RSL1_PROC);
5346
5347 /* From the MGW perspective, a handover is is characterized by
5348 * performing one MDCX operation with the MGW. So we expect to see
5349 * one more MDCX during handover. */
5350 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
5351
5352 var RSL_Message rsl;
5353 var PDU_ML3_NW_MS l3;
5354 var RslChannelNr new_chan_nr;
5355 var GsmArfcn arfcn;
5356 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
5357 l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
5358 if (not ischosen(l3.msgs.rrm.handoverCommand)) {
5359 setverdict(fail, "Expected handoverCommand");
5360 mtc.stop;
5361 }
5362 }
5363 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
5364 new_chan_nr, arfcn);
5365
5366 f_rslem_register(0, new_chan_nr, RSL1_PROC);
5367
5368 /* resume processing of RSL DChan messages, which was temporarily suspended
5369 * before performing a hand-over */
5370 f_rslem_resume(RSL1_PROC);
5371 RSL1.receive(tr_RSL_IPA_CRCX(new_chan_nr));
5372
5373 f_sleep(1.0);
5374
5375 /* Handover fails because no HANDO DET appears on the new lchan,
5376 * and the old lchan reports a Radio Link Failure. */
5377 RSL.send(ts_RSL_CONN_FAIL_IND(g_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
5378
5379 var PDU_BSSAP rx_clear_request;
5380 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
5381 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5382 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5383
5384 var RR_Cause rr_cause := GSM48_RR_CAUSE_ABNORMAL_UNSPEC;
5385
5386 var MgcpCommand mgcp;
5387 interleave {
5388 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE(int2oct(enum2int(rr_cause), 1)))) {}
5389 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005390 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005391 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005392 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005393 }
5394 [] RSL1.receive(tr_RSL_DEACT_SACCH(new_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005395 [] RSL1.receive(tr_RSL_RF_CHAN_REL(new_chan_nr)) {
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005396 RSL1.send(ts_RSL_RF_CHAN_REL_ACK(new_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005397 f_rslem_unregister(0, g_chan_nr, PT := RSL1_PROC);
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005398 }
5399 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {}
5400 }
5401
5402 f_sleep(0.5);
5403 setverdict(pass);
5404}
5405testcase TC_ho_int_radio_link_failure() runs on test_CT {
5406 var MSC_ConnHdlr vc_conn;
5407 f_init(2, true);
5408 f_sleep(1.0);
5409
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005410 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005411
5412 vc_conn := f_start_handler(refers(f_tc_ho_int_radio_link_failure));
5413 vc_conn.done;
5414
5415 /* from f_establish_fully() */
5416 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5417 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5418 /* from handover */
5419 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5420 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
5421 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5422 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:stopped");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005423 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
5424 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:stopped");
Neels Hofmeyr5f144212020-11-03 15:41:58 +00005425 f_ctrs_bsc_and_bts_verify();
5426 f_shutdown_helper();
5427}
5428
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005429/* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005430private function f_expect_dlcx_conns() runs on MSC_ConnHdlr {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005431 var MgcpCommand mgcp;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005432 var template MgcpResponse mgcp_resp;
5433 var MGCP_RecvFrom mrf;
5434 var template MgcpMessage msg_resp;
5435 var template MgcpMessage msg_dlcx := {
5436 command := tr_DLCX()
5437 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005438
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005439 if (g_pars.aoip) {
5440 MGCP.receive(tr_DLCX()) -> value mgcp {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005441 log("Got first DLCX: ", mgcp);
5442 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005443 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005444
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005445 MGCP.receive(tr_DLCX()) -> value mgcp {
5446 log("Got second DLCX: ", mgcp);
5447 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
5448 };
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02005449 } else {
5450 /* For SCCPLite, BSC doesn't handle the MSC-side */
5451 MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_dlcx)) -> value mrf {
5452 log("Got first DLCX: ", mrf.msg.command);
5453 msg_resp := {
5454 response := ts_DLCX_ACK2(mrf.msg.command.line.trans_id)
5455 }
5456 MGCP_MULTI.send(t_MGCP_SendToMrf(mrf, msg_resp));
5457 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005458 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005459}
5460
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005461private 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 +01005462
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005463 var NcellReports neighbor_rep := {
5464 { rxlev := 20, bcch_freq := 0, bsic := 11 }
5465 };
5466 var octetstring l3_mr := enc_GsmRrL3Message(valueof(ts_MEAS_REP(true, 8, 8, reps := neighbor_rep)));
5467 RSL.send(ts_RSL_MEAS_RES(g_chan_nr, 0, ts_RSL_IE_UplinkMeas, ts_RSL_IE_BS_Power(0), ts_RSL_IE_L1Info,
5468 l3_mr, 0));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005469
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005470 BSSAP.receive(tr_BSSMAP_HandoverRequired(exp_oldToNewBSSIEs));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005471
5472 f_sleep(0.5);
5473 /* The MSC negotiates Handover Request and Handover Request Ack with
5474 * the other BSS and comes back with a BSSMAP Handover Command
5475 * containing an RR Handover Command coming from the target BSS... */
5476
5477 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5478 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5479 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5480 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5481 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5482
5483 /* expect the Handover Command to go out on RR */
5484 var RSL_Message rsl_ho_cmd
5485 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5486 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5487 var RSL_IE_Body rsl_ho_cmd_l3;
5488 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5489 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5490 setverdict(fail);
5491 } else {
5492 log("Found L3 Info: ", rsl_ho_cmd_l3);
5493 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5494 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5495 setverdict(fail);
5496 } else {
5497 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5498 setverdict(pass);
5499 }
5500 }
5501
5502 /* When the other BSS has reported a completed handover, this side is
5503 * torn down. */
5504
5505 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
5506 var BssmapCause cause := enum2int(cause_val);
5507 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5508
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005509 f_expect_dlcx_conns();
Pau Espin Pedrol06199952021-06-15 11:30:00 +02005510
5511 interleave {
5512 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE));
5513 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr));
5514 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr));
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02005515 [] BSSAP.receive(tr_BSSMAP_ClearComplete);
Pau Espin Pedrol06199952021-06-15 11:30:00 +02005516 }
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005517 setverdict(pass);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005518}
5519
5520private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
5521 g_pars := f_gen_test_hdlr_pars();
5522 var PDU_BSSAP ass_req := f_gen_ass_req();
5523 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5524 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5525 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5526 f_establish_fully(ass_req, exp_compl);
5527
5528 f_ho_out_of_this_bsc();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005529}
5530testcase TC_ho_out_of_this_bsc() runs on test_CT {
5531 var MSC_ConnHdlr vc_conn;
5532
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +01005533 f_init_vty();
5534 f_bts_0_cfg(BSCVTY,
5535 {"neighbor-list mode automatic",
5536 "handover 1",
5537 "handover algorithm 2",
5538 "handover2 window rxlev averaging 1",
5539 "neighbor lac 99 arfcn 123 bsic any"});
5540 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5541
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005542 f_init(1, true);
5543 f_sleep(1.0);
5544
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005545 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005546
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005547 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
5548 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005549
5550 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5551 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5552 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5553 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5554 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5555 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed");
5556 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005557 f_shutdown_helper();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005558}
5559
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005560private function f_mo_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5561 template (value) RslLinkId link_id := ts_RslLinkID_DCCH(0),
Vadim Yanitskiy2ef6a2f2020-10-08 23:17:32 +07005562 template (present) OCT1 dlci := ?,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005563 octetstring l3 := '0123456789'O)
5564runs on MSC_ConnHdlr {
Neels Hofmeyr43654812020-09-25 01:35:35 +02005565 /* The old lchan and conn should still be active. See that arbitrary L3
5566 * is still going through. */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005567 rsl.send(ts_RSL_DATA_IND(g_chan_nr, link_id, l3));
Neels Hofmeyr43654812020-09-25 01:35:35 +02005568 var template PDU_BSSAP exp_data := {
5569 discriminator := '1'B,
5570 spare := '0000000'B,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005571 dlci := dlci,
5572 lengthIndicator := lengthof(l3),
Neels Hofmeyr43654812020-09-25 01:35:35 +02005573 pdu := {
5574 dtap := l3
5575 }
5576 };
5577 BSSAP.receive(exp_data);
5578 setverdict(pass);
5579}
5580
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005581private function f_mt_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5582 template (present) RslLinkId link_id := tr_RslLinkID_DCCH(0),
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005583 template (value) OCT1 dlci := '00'O,
5584 octetstring l3 := '0123456789'O)
5585runs on MSC_ConnHdlr {
5586 BSSAP.send(PDU_BSSAP:{
5587 discriminator := '1'B,
5588 spare := '0000000'B,
5589 dlci := dlci,
5590 lengthIndicator := lengthof(l3),
5591 pdu := {
5592 dtap := l3
5593 }
5594 });
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005595 rsl.receive(tr_RSL_DATA_REQ(g_chan_nr, link_id, l3));
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005596 setverdict(pass);
5597}
5598
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005599/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
5600 * simply never sends a BSSMAP Handover Command. */
5601private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005602 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005603
5604 var PDU_BSSAP ass_req := f_gen_ass_req();
5605 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5606 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5607 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5608 f_establish_fully(ass_req, exp_compl);
5609
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005610 f_bts_0_cfg(BSCVTY, {"neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005611 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5612
5613 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5614
5615 /* osmo-bsc should time out 10 seconds after the handover started.
5616 * Let's give it a bit extra. */
5617 f_sleep(15.0);
5618
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005619 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005620 f_sleep(1.0);
5621}
5622testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
5623 var MSC_ConnHdlr vc_conn;
5624
5625 f_init(1, true);
5626 f_sleep(1.0);
5627
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005628 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005629
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005630 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
5631 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005632
5633 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5634 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5635 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5636 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5637 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5638 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5639 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005640 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005641}
5642
5643/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
5644 * RR Handover Failure. */
5645private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005646 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005647
5648 var PDU_BSSAP ass_req := f_gen_ass_req();
5649 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5650 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5651 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5652 f_establish_fully(ass_req, exp_compl);
5653
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005654 f_bts_0_cfg(BSCVTY, {"neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005655 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5656
5657 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5658
5659 f_sleep(0.5);
5660 /* The MSC negotiates Handover Request and Handover Request Ack with
5661 * the other BSS and comes back with a BSSMAP Handover Command
5662 * containing an RR Handover Command coming from the target BSS... */
5663
5664 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5665 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5666 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5667 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5668 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5669
5670 /* expect the Handover Command to go out on RR */
5671 var RSL_Message rsl_ho_cmd
5672 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5673 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5674 var RSL_IE_Body rsl_ho_cmd_l3;
5675 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5676 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5677 setverdict(fail);
5678 } else {
5679 log("Found L3 Info: ", rsl_ho_cmd_l3);
5680 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5681 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5682 setverdict(fail);
5683 } else {
5684 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5685 setverdict(pass);
5686 }
5687 }
5688
5689 f_sleep(0.2);
5690 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
5691
5692 /* Should tell the MSC about the failure */
5693 BSSAP.receive(tr_BSSMAP_HandoverFailure);
5694
5695 f_sleep(1.0);
5696
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005697 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005698 f_sleep(1.0);
5699
5700 setverdict(pass);
5701 f_sleep(1.0);
5702}
5703testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
5704 var MSC_ConnHdlr vc_conn;
5705
5706 f_init(1, true);
5707 f_sleep(1.0);
5708
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005709 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005710
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005711 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
5712 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005713
5714 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5715 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5716 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5717 f_ctrs_bsc_and_bts_add(0, "handover:failed");
5718 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5719 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:failed");
5720 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005721 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005722}
5723
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005724/* BSC asks for inter-BSC-out HO, receives BSSMAP Handover Command, but then no reply is received about HO outcome
5725 * (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 +02005726 * and the lchan is released. */
5727private function f_tc_ho_out_fail_no_result_after_ho_cmd(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005728 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005729
5730 var PDU_BSSAP ass_req := f_gen_ass_req();
5731 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5732 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5733 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5734 f_establish_fully(ass_req, exp_compl);
5735
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005736 f_bts_0_cfg(BSCVTY, {"neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005737 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5738
5739 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5740
5741 f_sleep(0.5);
5742 /* The MSC negotiates Handover Request and Handover Request Ack with
5743 * the other BSS and comes back with a BSSMAP Handover Command
5744 * containing an RR Handover Command coming from the target BSS... */
5745
5746 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5747 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5748 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5749 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5750 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5751
5752 /* expect the Handover Command to go out on RR */
5753 var RSL_Message rsl_ho_cmd
5754 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5755 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5756 var RSL_IE_Body rsl_ho_cmd_l3;
5757 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5758 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5759 setverdict(fail);
5760 } else {
5761 log("Found L3 Info: ", rsl_ho_cmd_l3);
5762 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5763 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5764 setverdict(fail);
5765 } else {
5766 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5767 setverdict(pass);
5768 }
5769 }
5770
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005771 /* We get neither success nor failure report from the remote BSS. Eventually T8 times out and we run into 3GPP
5772 * TS 48.008 3.1.5.3.3 "Abnormal Conditions": Clear Request should go to the MSC, and RR should be released
5773 * after Clear Command */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005774
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005775 var PDU_BSSAP rx_clear_request;
Neels Hofmeyre1797aa2019-07-09 19:34:04 +02005776 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
5777 log("Got BSSMAP Clear Request");
5778 /* Instruct BSC to clear channel */
5779 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5780 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5781
5782 var MgcpCommand mgcp;
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005783 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01005784 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
5785 log("Got Deact SACCH");
5786 }
Harald Welte924b6ea2019-02-04 01:05:34 +01005787 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01005788 log("Got RR Release");
5789 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02005790 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005791 log("Got RF Chan Rel");
5792 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02005793 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005794 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005795 }
5796
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005797 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02005798 BSSAP.receive(tr_BSSMAP_ClearComplete);
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005799
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005800 setverdict(pass);
5801 f_sleep(1.0);
5802}
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02005803testcase TC_ho_out_fail_no_result_after_ho_cmd() runs on test_CT {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005804 var MSC_ConnHdlr vc_conn;
5805
5806 f_init(1, true);
5807 f_sleep(1.0);
5808
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005809 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005810
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02005811 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_result_after_ho_cmd));
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005812 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005813
5814 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5815 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5816 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5817 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5818 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5819 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5820 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005821 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005822}
5823
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005824private function f_ho_into_this_bsc(charstring id, template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit) runs on MSC_ConnHdlr {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005825 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
5826 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
5827 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
5828 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
5829 * before we get started. */
5830 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
5831 f_rslem_register(0, new_chan_nr);
5832 g_chan_nr := new_chan_nr;
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02005833 var uint3_t expect_target_tsc := BTS_TSC[0];
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005834 f_sleep(1.0);
5835
5836 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
5837 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
5838 activate(as_Media());
5839
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005840 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005841 f_gen_handover_req(aoip_tla := g_pars.host_aoip_tla,
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02005842 oldToNewBSSIEs := oldToNewBSSIEs,
5843 enc := g_pars.encr)));
Harald Welte6811d102019-04-14 22:23:14 +02005844 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005845
5846 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
5847
5848 var PDU_BSSAP rx_bssap;
5849 var octetstring ho_command_str;
5850
5851 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
Pau Espin Pedrol76ba5412019-06-10 11:00:33 +02005852
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02005853 /* we're sure that the channel activation is done now, verify the parameters in it */
5854 var RSL_Message chan_act := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
5855 f_verify_encr_info(chan_act);
5856 f_chan_act_verify_tsc(chan_act, expect_target_tsc);
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02005857
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005858 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
5859 log("Received L3 Info in HO Request Ack: ", ho_command_str);
5860 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
5861 log("L3 Info in HO Request Ack is ", ho_command);
5862
5863 var GsmArfcn arfcn;
5864 var RslChannelNr actual_new_chan_nr;
5865 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
5866 actual_new_chan_nr, arfcn);
5867
5868 if (actual_new_chan_nr != new_chan_nr) {
5869 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
5870 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
5871 setverdict(fail);
5872 return;
5873 }
5874 log("Handover Command chan_nr is", actual_new_chan_nr);
5875
Neels Hofmeyr34174bd2021-10-02 14:52:57 +02005876 var uint3_t got_tsc := rr_chan_desc_tsc(ho_command.msgs.rrm.handoverCommand.channelDescription2);
5877 if (not match(got_tsc, expect_target_tsc)) {
5878 setverdict(fail, "RR Handover Command: unexpected TSC in Channel Description: expected ",
5879 expect_target_tsc, " got ", got_tsc);
5880 mtc.stop;
5881 } else {
5882 log("handoverCommand: verified TSC = ", got_tsc);
5883 }
5884
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005885 /* Now the MSC forwards the RR Handover Command to the other BSC, which
5886 * tells the MS to handover to the new lchan. Here comes the new MS on
5887 * the new lchan with a Handover RACH: */
5888
5889 /* send handover detect */
5890
5891 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
5892
5893 BSSAP.receive(tr_BSSMAP_HandoverDetect);
5894
5895 /* send handover complete over the new channel */
5896
5897 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
5898 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
5899 enc_PDU_ML3_MS_NW(l3_tx)));
5900
5901 BSSAP.receive(tr_BSSMAP_HandoverComplete);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005902 setverdict(pass);
5903}
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005904
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005905private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005906 var template PDU_ML3_NW_MS exp_rr_rel_tmpl;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005907 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit;
5908 if (not istemplatekind(g_pars.last_used_eutran_plmn, "omit")) {
5909 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005910 }
5911 if (g_pars.exp_fast_return) {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005912 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE_CellSelectInd;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005913 } else {
5914 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005915 }
5916 f_ho_into_this_bsc(id, oldToNewBSSIEs);
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02005917 f_perform_clear(exp_rr_rel_tmpl := exp_rr_rel_tmpl);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005918 setverdict(pass);
5919}
Pau Espin Pedrol07866632020-09-03 19:10:55 +02005920function f_tc_ho_into_this_bsc_main(TestHdlrParams pars) runs on test_CT {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005921 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005922
5923 f_init(1, true);
5924 f_sleep(1.0);
5925
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01005926 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005927
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005928 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
5929 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005930
5931 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
5932 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005933
5934 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5935 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5936 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
5937 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed");
5938 f_ctrs_bsc_and_bts_verify();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005939}
5940
Pau Espin Pedrol07866632020-09-03 19:10:55 +02005941testcase TC_ho_into_this_bsc() runs on test_CT {
5942 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5943 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005944 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02005945}
5946
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02005947function f_tc_ho_into_this_bsc_a5(OCT1 encr_alg) runs on test_CT {
5948 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5949 pars.encr := valueof(t_EncrParams(encr_alg, f_rnd_octstring(8), f_rnd_octstring(16)));
5950 f_tc_ho_into_this_bsc_main(pars);
5951 f_shutdown_helper();
5952}
5953
5954testcase TC_ho_into_this_bsc_a5_0() runs on test_CT {
5955 f_tc_ho_into_this_bsc_a5('01'O);
5956}
5957
5958testcase TC_ho_into_this_bsc_a5_1() runs on test_CT {
5959 f_tc_ho_into_this_bsc_a5('02'O);
5960}
5961
5962testcase TC_ho_into_this_bsc_a5_3() runs on test_CT {
5963 f_tc_ho_into_this_bsc_a5('08'O);
5964}
5965
5966testcase TC_ho_into_this_bsc_a5_4() runs on test_CT {
5967 f_tc_ho_into_this_bsc_a5('10'O);
5968}
5969
Pau Espin Pedrol07866632020-09-03 19:10:55 +02005970testcase TC_ho_into_this_bsc_tla_v6() runs on test_CT {
5971 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5972 pars.host_aoip_tla := "::6";
5973 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005974 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02005975}
5976
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005977/* Similar to TC_ho_into_this_bsc, but when in SRVCC, HO Req contains "Old BSS
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005978 to New BSS Information" IE with "Last Used E-UTRAN PLMN Id", which, when the
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005979 channel is later released (RR CHannel Release), should trigger inclusion of
5980 IE "Cell Selection Indicator after Release of all TCH and SDCCH" with E-UTRAN
5981 neighbors. */
5982testcase TC_srvcc_eutran_to_geran() runs on test_CT {
5983 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5984 pars.last_used_eutran_plmn := '323454'O;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005985 pars.exp_fast_return := true;
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005986 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02005987
5988 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted");
5989 f_ctrs_bsc_and_bts_add(0, "srvcc:completed");
5990 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005991 f_shutdown_helper();
5992}
5993
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005994/* Same as TC_srvcc_eutran_to_geran, but test explicitly forbiding fast return
5995 on the BTS. As a result, RR Release shouldn't contain the EUTRAN neighbor
5996 list when the channel is released. */
5997testcase TC_srvcc_eutran_to_geran_forbid_fast_return() runs on test_CT {
5998 f_init_vty();
5999 f_vty_allow_srvcc_fast_return(true, 0)
6000
6001 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6002 pars.last_used_eutran_plmn := '323454'O;
6003 pars.exp_fast_return := false;
6004 f_tc_ho_into_this_bsc_main(pars);
6005 f_vty_allow_srvcc_fast_return(false, 0);
6006 f_shutdown_helper();
6007}
6008
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006009private function f_tc_srvcc_eutran_to_geran_ho_out(charstring id) runs on MSC_ConnHdlr {
6010 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs;
6011 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
6012 f_ho_into_this_bsc(id, oldToNewBSSIEs);
6013 f_ho_out_of_this_bsc(oldToNewBSSIEs);
6014 setverdict(pass);
6015}
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006016
6017private function f_tc_srvcc_eutran_to_geran_ho_out_main(boolean disable_fast_return)
6018 runs on test_CT {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006019 var MSC_ConnHdlr vc_conn;
6020 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6021
6022 f_init(1, true);
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006023 if (disable_fast_return) {
6024 f_vty_allow_srvcc_fast_return(true, 0);
6025 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006026 f_sleep(1.0);
6027
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006028 f_ctrs_bsc_and_bts_handover_init();
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006029
6030 pars.last_used_eutran_plmn := '323454'O;
6031 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6032 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
6033
6034 vc_conn := f_start_handler(refers(f_tc_srvcc_eutran_to_geran_ho_out), pars);
6035 vc_conn.done;
6036
6037 f_ctrs_bsc_and_bts_add(0, "handover:attempted", 2);
6038 f_ctrs_bsc_and_bts_add(0, "handover:completed", 2);
6039 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted", 1);
6040 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed", 1);
6041 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted", 1);
6042 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed", 1);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02006043
6044 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted", 1);
6045 f_ctrs_bsc_and_bts_add(0, "srvcc:completed", 1);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006046 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006047
6048 if (disable_fast_return) {
6049 f_vty_allow_srvcc_fast_return(false, 0);
6050 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02006051 f_shutdown_helper();
6052}
6053
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02006054/* First, HO into BSC from EUTRAN (SRVCC): HO Request contains "Old BSS to New
6055 BSS Information" IE with "Last Used E-UTRAN PLMN Id".
6056 Second, HO to another BSC: HO Required contains "Old BSS to New BSS Information"
6057 IE with "Last Used E-UTRAN PLMN Id" from first step. */
6058testcase TC_srvcc_eutran_to_geran_ho_out() runs on test_CT {
6059 f_tc_srvcc_eutran_to_geran_ho_out_main(false);
6060}
6061/* Validate subsequent intra-GSM-HO works the same (with OldBSSToNewBSSInfo IE)
6062 * independently of fast-reture allowed/forbidden in local BTS */
6063testcase TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() runs on test_CT {
6064 f_tc_srvcc_eutran_to_geran_ho_out_main(true);
6065}
6066
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006067private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
6068 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6069 f_rslem_register(0, new_chan_nr);
6070 g_chan_nr := new_chan_nr;
6071 f_sleep(1.0);
6072
6073 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6074 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6075 activate(as_Media());
6076
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006077 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006078 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006079 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006080
6081 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6082
6083 var PDU_BSSAP rx_bssap;
6084 var octetstring ho_command_str;
6085
6086 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6087
6088 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6089 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6090 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6091 log("L3 Info in HO Request Ack is ", ho_command);
6092
6093 var GsmArfcn arfcn;
6094 var RslChannelNr actual_new_chan_nr;
6095 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6096 actual_new_chan_nr, arfcn);
6097
6098 if (actual_new_chan_nr != new_chan_nr) {
6099 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6100 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6101 setverdict(fail);
6102 return;
6103 }
6104 log("Handover Command chan_nr is", actual_new_chan_nr);
6105
Neels Hofmeyr61ca08d2019-05-06 23:52:22 +02006106 /* For deterministic test results, give some time for the MGW endpoint to be configured */
6107 f_sleep(1.0);
6108
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006109 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6110 * tells the MS to handover to the new lchan. In this case, the MS
6111 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
6112 * Handover Failure to the MSC. The procedure according to 3GPP TS
6113 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
6114 * BSSMAP Clear Command: */
6115
6116 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6117 var BssmapCause cause := enum2int(cause_val);
6118 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6119
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006120 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006121 BSSAP.receive(tr_BSSMAP_ClearComplete);
6122
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006123 setverdict(pass);
6124 f_sleep(1.0);
6125
6126 setverdict(pass);
6127}
6128testcase TC_ho_in_fail_msc_clears() runs on test_CT {
6129 var MSC_ConnHdlr vc_conn;
6130 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6131
6132 f_init(1, true);
6133 f_sleep(1.0);
6134
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006135 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006136
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006137 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6138 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006139
6140 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
6141 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006142
6143 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6144 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
6145 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6146 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
6147 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006148 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006149}
6150
6151private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
6152 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
6153 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
6154 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
6155 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
6156 * before we get started. */
6157 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6158 f_rslem_register(0, new_chan_nr);
6159 g_chan_nr := new_chan_nr;
6160 f_sleep(1.0);
6161
6162 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6163 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6164 activate(as_Media());
6165
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006166 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006167 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006168 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006169
6170 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6171
6172 var PDU_BSSAP rx_bssap;
6173 var octetstring ho_command_str;
6174
6175 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6176
6177 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6178 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6179 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6180 log("L3 Info in HO Request Ack is ", ho_command);
6181
6182 var GsmArfcn arfcn;
6183 var RslChannelNr actual_new_chan_nr;
6184 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6185 actual_new_chan_nr, arfcn);
6186
6187 if (actual_new_chan_nr != new_chan_nr) {
6188 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6189 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6190 setverdict(fail);
6191 return;
6192 }
6193 log("Handover Command chan_nr is", actual_new_chan_nr);
6194
6195 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6196 * tells the MS to handover to the new lchan. Here comes the new MS on
6197 * the new lchan with a Handover RACH: */
6198
6199 /* send handover detect */
6200
6201 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
6202
6203 BSSAP.receive(tr_BSSMAP_HandoverDetect);
6204
6205 /* The MSC chooses to clear the connection now, maybe we got the
6206 * Handover RACH on the new cell but the MS still signaled Handover
6207 * Failure to the old BSS? */
6208
6209 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6210 var BssmapCause cause := enum2int(cause_val);
6211 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6212
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006213 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006214 BSSAP.receive(tr_BSSMAP_ClearComplete);
6215
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006216 f_sleep(1.0);
6217}
6218testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
6219 var MSC_ConnHdlr vc_conn;
6220 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6221
6222 f_init(1, true);
6223 f_sleep(1.0);
6224
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006225 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006226
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006227 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6228 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006229
6230 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
6231 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006232
6233 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6234 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
6235 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6236 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
6237 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006238 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006239}
6240
6241/* The new BSS's lchan times out before the MSC decides that handover failed. */
6242private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
6243 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6244 f_rslem_register(0, new_chan_nr);
6245 g_chan_nr := new_chan_nr;
6246 f_sleep(1.0);
6247
6248 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6249 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6250 activate(as_Media());
6251
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006252 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006253 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006254 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006255
6256 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6257
6258 var PDU_BSSAP rx_bssap;
6259 var octetstring ho_command_str;
6260
6261 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6262
6263 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6264 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6265 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6266 log("L3 Info in HO Request Ack is ", ho_command);
6267
6268 var GsmArfcn arfcn;
6269 var RslChannelNr actual_new_chan_nr;
6270 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6271 actual_new_chan_nr, arfcn);
6272
6273 if (actual_new_chan_nr != new_chan_nr) {
6274 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6275 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6276 setverdict(fail);
6277 return;
6278 }
6279 log("Handover Command chan_nr is", actual_new_chan_nr);
6280
6281 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6282 * tells the MS to handover to the new lchan. But the MS never shows up
6283 * on the new lchan. */
6284
6285 BSSAP.receive(tr_BSSMAP_HandoverFailure);
6286
6287 /* Did osmo-bsc also send a Clear Request? */
6288 timer T := 0.5;
6289 T.start;
6290 alt {
6291 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
6292 [] T.timeout { }
6293 }
6294
6295 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
6296 * asked for it, this is a Handover Failure after all). */
6297
6298 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
6299 var BssmapCause cause := enum2int(cause_val);
6300 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6301
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006302 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006303 BSSAP.receive(tr_BSSMAP_ClearComplete);
6304
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006305 f_sleep(1.0);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006306}
6307testcase TC_ho_in_fail_no_detect() runs on test_CT {
6308 var MSC_ConnHdlr vc_conn;
6309 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6310
6311 f_init(1, true);
6312 f_sleep(1.0);
6313
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006314 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006315
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006316 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6317 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006318
6319 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
6320 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006321
6322 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6323 f_ctrs_bsc_and_bts_add(0, "handover:error");
6324 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6325 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
6326 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006327 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006328}
6329
6330/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
6331private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
6332 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
6333 f_rslem_register(0, new_chan_nr);
6334 g_chan_nr := new_chan_nr;
6335 f_sleep(1.0);
6336
6337 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
6338 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6339 activate(as_Media());
6340
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006341 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006342 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02006343 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006344
6345 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
6346
6347 var PDU_BSSAP rx_bssap;
6348 var octetstring ho_command_str;
6349
6350 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
6351
6352 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
6353 log("Received L3 Info in HO Request Ack: ", ho_command_str);
6354 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
6355 log("L3 Info in HO Request Ack is ", ho_command);
6356
6357 var GsmArfcn arfcn;
6358 var RslChannelNr actual_new_chan_nr;
6359 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
6360 actual_new_chan_nr, arfcn);
6361
6362 if (actual_new_chan_nr != new_chan_nr) {
6363 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
6364 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
6365 setverdict(fail);
6366 return;
6367 }
6368 log("Handover Command chan_nr is", actual_new_chan_nr);
6369
6370 /* Now the MSC forwards the RR Handover Command to the other BSC, which
6371 * tells the MS to handover to the new lchan. But the MS never shows up
6372 * on the new lchan. */
6373
6374 BSSAP.receive(tr_BSSMAP_HandoverFailure);
6375
6376 /* MSC plays dumb and sends no Clear Command */
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006377 var PDU_BSSAP rx_clear_request;
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02006378
6379 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006380 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
6381 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
6382 };
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02006383 f_expect_dlcx_conns();
Neels Hofmeyr8fcd8772021-07-22 16:12:57 +02006384 BSSAP.receive(tr_BSSMAP_ClearComplete);
6385
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006386 f_sleep(1.0);
6387}
6388testcase TC_ho_in_fail_no_detect2() runs on test_CT {
6389 var MSC_ConnHdlr vc_conn;
6390 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6391
6392 f_init(1, true);
6393 f_sleep(1.0);
6394
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006395 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006396
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006397 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
6398 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006399
6400 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
6401 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006402
6403 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6404 f_ctrs_bsc_and_bts_add(0, "handover:error");
6405 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
6406 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
6407 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006408 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01006409}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01006410
Neels Hofmeyr91401012019-07-11 00:42:35 +02006411type record of charstring Commands;
6412
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006413private function f_bts_0_cfg(TELNETasp_PT pt, Commands cmds := {})
Neels Hofmeyr91401012019-07-11 00:42:35 +02006414{
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006415 f_vty_enter_cfg_bts(pt, 0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006416 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006417 f_vty_transceive(pt, cmds[i]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006418 }
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006419 f_vty_transceive(pt, "end");
Neels Hofmeyr91401012019-07-11 00:42:35 +02006420}
6421
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01006422private function f_cs7_inst_0_cfg(TELNETasp_PT pt, Commands cmds := {})
6423{
6424 f_vty_enter_cfg_cs7_inst(pt, 0);
6425 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
6426 f_vty_transceive(pt, cmds[i]);
6427 }
6428 f_vty_transceive(pt, "end");
6429}
6430
Neels Hofmeyr91401012019-07-11 00:42:35 +02006431private function f_probe_for_handover(charstring log_label,
6432 charstring log_descr,
6433 charstring handover_vty_cmd,
6434 boolean expect_handover,
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006435 boolean is_inter_bsc_handover := false,
6436 template uint3_t expect_target_tsc := ?)
Neels Hofmeyr91401012019-07-11 00:42:35 +02006437runs on MSC_ConnHdlr
6438{
Neels Hofmeyrb3fc8982020-05-11 00:16:42 +02006439 /* We're going to thwart any and all handover attempts, just be ready to handle (and ignore) handover target
6440 * lchans to be established on bts 1 or bts 2. */
6441 f_rslem_suspend(RSL1_PROC);
6442 f_rslem_suspend(RSL2_PROC);
6443
Neels Hofmeyr91401012019-07-11 00:42:35 +02006444 var RSL_Message rsl;
6445
6446 var charstring log_msg := " (expecting handover)"
6447 if (not expect_handover) {
6448 log_msg := " (expecting NO handover)";
6449 }
6450 log("f_probe_for_handover starting: " & log_label & ": " & log_descr & log_msg);
6451 f_vty_transceive(BSCVTY, handover_vty_cmd);
6452
Neels Hofmeyr91401012019-07-11 00:42:35 +02006453 timer T := 2.0;
6454 T.start;
6455
6456 alt {
6457 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
6458 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
6459 log("Rx L3 from net: ", l3);
6460 if (ischosen(l3.msgs.rrm.handoverCommand)) {
6461 var RslChannelNr new_chan_nr;
6462 var GsmArfcn arfcn;
6463 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
6464 new_chan_nr, arfcn);
6465 log("Handover to new chan ", new_chan_nr, " on ARFCN ", arfcn);
6466 log(l3.msgs.rrm.handoverCommand);
6467
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006468 /* Verify correct TSC in handoverCommand */
6469 var uint3_t got_tsc := rr_chan_desc_tsc(l3.msgs.rrm.handoverCommand.channelDescription2);
6470 if (not match(got_tsc, expect_target_tsc)) {
6471 setverdict(fail, "RR Handover Command: unexpected TSC in Channel Description: expected ",
6472 expect_target_tsc, " got ", got_tsc);
6473 mtc.stop;
6474 } else {
6475 log("handoverCommand: verified TSC = ", got_tsc, " (matches ",
6476 expect_target_tsc, ")");
6477 }
6478
Neels Hofmeyr91401012019-07-11 00:42:35 +02006479 /* Need to register for new lchan on new BTS -- it's either bts 1 or bts 2. It doesn't really
6480 * matter on which BTS it really is, we're not going to follow through an entire handover
6481 * anyway. */
6482 f_rslem_register(0, new_chan_nr, RSL1_PROC);
6483 f_rslem_resume(RSL1_PROC);
6484 f_rslem_register(0, new_chan_nr, RSL2_PROC);
6485 f_rslem_resume(RSL2_PROC);
6486
6487 if (expect_handover and not is_inter_bsc_handover) {
6488 setverdict(pass);
6489 log("f_probe_for_handover(" & log_label & "): Got RSL Handover Command as expected.");
6490 } else {
6491 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got RSL Handover Command. "
6492 & log_label & ": " & log_descr);
6493 }
6494
6495 log("f_probe_for_handover(" & log_label & "): Ending the test: Handover Failure stops the procedure.");
6496 /* osmo-bsc has triggered Handover. That's all we need to know for this test, reply with
6497 * Handover Failure. */
6498 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
6499
6500 /* target BTS is told to release lchan again; don't care which BTS nor what messages. */
6501 f_sleep(0.5);
6502 RSL1.clear;
6503 RSL2.clear;
6504 log("f_probe_for_handover(" & log_label & "): done (got RSL Handover Command)");
6505 break;
6506 } else {
6507 repeat;
6508 }
6509 }
6510 [] BSSAP.receive(tr_BSSMAP_HandoverRequired) {
6511 if (expect_handover and is_inter_bsc_handover) {
6512 setverdict(pass);
6513 log("f_probe_for_handover(" & log_label & "): Got BSSMAP Handover Required as expected.");
6514 } else {
6515 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got BSSMAP Handover Required. "
6516 & log_label & ": " & log_descr);
6517 }
6518
6519 log("f_probe_for_handover(" & log_label & "): done (got BSSMAP Handover Required)");
6520
6521 /* Note: f_tc_ho_neighbor_config_start() sets T7, the timeout for BSSMAP Handover Required, to
6522 * 1 second. There is no legal way to quickly abort a handover after a BSSMAP Handover Required,
6523 * setting a short timeout and waiting is the only way. */
6524 log("f_probe_for_handover(" & log_label & "): waiting for inter-BSC HO to time out...");
6525 f_sleep(1.5);
6526 log("f_probe_for_handover(" & log_label & "): ...done");
6527
6528 break;
6529 }
6530 [] T.timeout {
6531 if (expect_handover) {
6532 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected Handover, but got none. "
6533 & log_label & ": " & log_descr);
6534 } else {
6535 setverdict(pass);
6536 log("f_probe_for_handover(" & log_label & "): Got no Handover, as expected.");
6537 }
6538 log("f_probe_for_handover(" & log_label & "): done (got no Handover)");
6539 break;
6540 }
6541 }
6542
6543 f_rslem_resume(RSL1_PROC);
6544 f_rslem_resume(RSL2_PROC);
6545 f_sleep(3.0);
6546 RSL.clear;
6547
6548 log("f_probe_for_handover(" & log_label & "): done clearing");
6549}
6550
6551/* Test the effect of various neighbor configuration scenarios:
6552 *
6553 * To avoid complexity, block off any actual handover operation, and always remain on the lchan at bts 0.
6554 * Reconfigure the neighbors for bts 0, trigger a Handover, and probe whether osmo-bsc does or doesn't start HO.
6555 */
6556private function f_tc_ho_neighbor_config_start() runs on MSC_ConnHdlr {
6557 g_pars := f_gen_test_hdlr_pars();
6558 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
6559 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006560
6561 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
6562 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
6563
6564 /* Establish lchan at bts 0 */
6565 f_establish_fully(ass_cmd, exp_compl);
6566
6567 /* Shorten the inter-BSC Handover timeout, to not wait so long for inter-BSC Handovers */
6568 f_vty_enter_cfg_network(BSCVTY);
6569 f_vty_transceive(BSCVTY, "timer T7 1");
6570 f_vty_transceive(BSCVTY, "end");
6571}
6572
6573private function f_tc_ho_neighbor_config_1(charstring id) runs on MSC_ConnHdlr {
6574 f_tc_ho_neighbor_config_start();
6575
6576 /*
6577 * bts 0 ARFCN 871 BSIC 10
6578 * bts 1 ARFCN 871 BSIC 11
6579 * bts 2 ARFCN 871 BSIC 12
6580 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6581 */
6582
6583 log("f_tc_ho_neighbor_config: 1. No 'neighbor' config");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006584 f_bts_0_cfg(BSCVTY, {"no neighbors"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006585 f_probe_for_handover("1.a", "HO to bts 1 works, implicitly listed as neighbor (legacy behavior when none are configured)",
6586 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006587 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006588
6589 f_probe_for_handover("1.b", "HO to unknown cell does not start",
6590 "handover any to arfcn 13 bsic 39",
6591 false);
6592
6593 f_probe_for_handover("1.c", "HO to 871-12 is ambiguous = error",
6594 "handover any to arfcn 871 bsic 12",
6595 false);
6596
6597 f_probe_for_handover("1.d", "HO to 871-11 still works (verify that this test properly cleans up)",
6598 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006599 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006600}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006601testcase TC_ho_neighbor_config_1() runs on test_CT {
6602 var MSC_ConnHdlr vc_conn;
6603 f_init(3, true, guard_timeout := 60.0);
6604 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006605 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006606 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_1));
6607 vc_conn.done;
6608
6609 /* f_tc_ho_neighbor_config_start() */
6610 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6611 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6612
6613 /* 1.a */
6614 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6615 * handover quickly by sending a Handover Failure message. */
6616 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6617 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6618 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6619 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006620 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6621 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006622
6623 /* 1.b */
6624 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6625 f_ctrs_bsc_and_bts_add(0, "handover:error");
6626
6627 /* 1.c */
6628 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6629 f_ctrs_bsc_and_bts_add(0, "handover:error");
6630
6631 /* 1.d */
6632 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6633 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6634 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6635 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006636 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6637 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006638
6639 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006640 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006641}
6642
Neels Hofmeyr91401012019-07-11 00:42:35 +02006643private function f_tc_ho_neighbor_config_2(charstring id) runs on MSC_ConnHdlr {
6644 f_tc_ho_neighbor_config_start();
6645
6646 /*
6647 * bts 0 ARFCN 871 BSIC 10
6648 * bts 1 ARFCN 871 BSIC 11
6649 * bts 2 ARFCN 871 BSIC 12
6650 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6651 */
6652
6653 log("f_tc_ho_neighbor_config: 2. explicit local neighbor: 'neighbor bts 1'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006654 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006655 f_sleep(0.5);
6656
6657 f_probe_for_handover("2.a", "HO to bts 1 works, explicitly listed as neighbor",
6658 "handover any to arfcn 871 bsic 11",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006659 true, expect_target_tsc := BTS_TSC[1]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006660
6661 f_probe_for_handover("2.b", "HO to bts 2 doesn't work, not listed as neighbor",
6662 "handover any to arfcn 871 bsic 12",
6663 false);
6664}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006665testcase TC_ho_neighbor_config_2() runs on test_CT {
6666 var MSC_ConnHdlr vc_conn;
6667 f_init(3, true, guard_timeout := 50.0);
6668 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006669 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006670 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_2));
6671 vc_conn.done;
6672
6673 /* f_tc_ho_neighbor_config_start() */
6674 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6675 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6676
6677 /* 2.a */
6678 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6679 * handover quickly by sending a Handover Failure message. */
6680 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6681 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6682 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6683 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006684 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:attempted");
6685 f_ctrs_bts_add(1, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006686
6687 /* 2.b */
6688 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6689 f_ctrs_bsc_and_bts_add(0, "handover:error");
6690
6691 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006692 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006693}
6694
Neels Hofmeyr91401012019-07-11 00:42:35 +02006695private function f_tc_ho_neighbor_config_3(charstring id) runs on MSC_ConnHdlr {
6696 f_tc_ho_neighbor_config_start();
6697
6698 /*
6699 * bts 0 ARFCN 871 BSIC 10
6700 * bts 1 ARFCN 871 BSIC 11
6701 * bts 2 ARFCN 871 BSIC 12
6702 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6703 */
6704
6705 log("f_tc_ho_neighbor_config: 3. explicit local neighbor: 'neighbor bts 2'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006706 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006707 f_sleep(0.5);
6708
6709 f_probe_for_handover("3.a", "HO to bts 1 doesn't work, not listed as neighbor",
6710 "handover any to arfcn 871 bsic 11",
6711 false);
6712 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",
6713 "handover any to arfcn 871 bsic 12",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006714 true, expect_target_tsc := BTS_TSC[2]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006715}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006716testcase TC_ho_neighbor_config_3() runs on test_CT {
6717 var MSC_ConnHdlr vc_conn;
6718 f_init(3, true, guard_timeout := 50.0);
6719 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006720 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006721 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_3));
6722 vc_conn.done;
6723
6724 /* f_tc_ho_neighbor_config_start() */
6725 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6726 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6727
6728 /* 3.a */
6729 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6730 f_ctrs_bsc_and_bts_add(0, "handover:error");
6731
6732 /* 3.b */
6733 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6734 * handover quickly by sending a Handover Failure message. */
6735 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6736 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6737 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6738 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006739 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:attempted");
6740 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006741
6742 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006743 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006744}
6745
Neels Hofmeyr91401012019-07-11 00:42:35 +02006746private function f_tc_ho_neighbor_config_4(charstring id) runs on MSC_ConnHdlr {
6747 f_tc_ho_neighbor_config_start();
6748
6749 /*
6750 * bts 0 ARFCN 871 BSIC 10
6751 * bts 1 ARFCN 871 BSIC 11
6752 * bts 2 ARFCN 871 BSIC 12
6753 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6754 */
6755
6756 log("f_tc_ho_neighbor_config: 4. explicit remote neighbor: 'neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006757 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006758 f_sleep(0.5);
6759
6760 f_probe_for_handover("4.a", "HO to bts 1 doesn't work, not listed as neighbor",
6761 "handover any to arfcn 871 bsic 11",
6762 false);
6763 f_probe_for_handover("4.b", "HO to bts 2 doesn't work, not listed as neighbor",
6764 "handover any to arfcn 871 bsic 12",
6765 false);
6766 f_probe_for_handover("4.c", "HO to 123-45 triggers inter-BSC HO",
6767 "handover any to arfcn 123 bsic 45",
6768 true, true);
6769}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006770testcase TC_ho_neighbor_config_4() runs on test_CT {
6771 var MSC_ConnHdlr vc_conn;
6772 f_init(3, true, guard_timeout := 50.0);
6773 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006774 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006775 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_4));
6776 vc_conn.done;
6777
6778 /* f_tc_ho_neighbor_config_start() */
6779 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6780 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6781
6782 /* 4.a */
6783 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6784 f_ctrs_bsc_and_bts_add(0, "handover:error");
6785
6786 /* 4.b */
6787 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6788 f_ctrs_bsc_and_bts_add(0, "handover:error");
6789
6790 /* 4.c */
6791 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6792 * handover quickly by timing out after the Handover Required message */
6793 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6794 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
6795 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
6796 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
6797
6798 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006799 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006800}
6801
Neels Hofmeyr91401012019-07-11 00:42:35 +02006802private function f_tc_ho_neighbor_config_5(charstring id) runs on MSC_ConnHdlr {
6803 f_tc_ho_neighbor_config_start();
6804
6805 /*
6806 * bts 0 ARFCN 871 BSIC 10
6807 * bts 1 ARFCN 871 BSIC 11
6808 * bts 2 ARFCN 871 BSIC 12
6809 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6810 */
6811
6812 log("f_tc_ho_neighbor_config: 5. explicit remote neighbor re-using ARFCN+BSIC: 'neighbor lac 99 arfcn 871 bsic 12'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006813 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006814 f_sleep(0.5);
6815
6816 f_probe_for_handover("5.a", "HO to 871-12 triggers inter-BSC HO (ignoring local cells with same ARFCN+BSIC)",
6817 "handover any to arfcn 871 bsic 12",
6818 true, true);
6819}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006820testcase TC_ho_neighbor_config_5() runs on test_CT {
6821 var MSC_ConnHdlr vc_conn;
6822 f_init(3, true);
6823 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006824 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006825 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_5));
6826 vc_conn.done;
6827
6828 /* f_tc_ho_neighbor_config_start() */
6829 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6830 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6831
6832 /* 5 */
6833 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6834 * handover quickly by timing out after the Handover Required message */
6835 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6836 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
6837 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
6838 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
6839
6840 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006841 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006842}
6843
Neels Hofmeyr91401012019-07-11 00:42:35 +02006844private function f_tc_ho_neighbor_config_6(charstring id) runs on MSC_ConnHdlr {
6845 f_tc_ho_neighbor_config_start();
6846
6847 /*
6848 * bts 0 ARFCN 871 BSIC 10
6849 * bts 1 ARFCN 871 BSIC 11
6850 * bts 2 ARFCN 871 BSIC 12
6851 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6852 */
6853
6854 log("f_tc_ho_neighbor_config: 6. config error: explicit local and remote neighbors with ambiguous ARFCN+BSIC:"
6855 & " 'neighbor bts 2; neighbor lac 99 arfcn 871 bsic 12'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006856 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006857 f_sleep(0.5);
6858
6859 f_probe_for_handover("6.a", "HO to 871-12 is ambiguous = error",
6860 "handover any to arfcn 871 bsic 12",
6861 false);
6862}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006863testcase TC_ho_neighbor_config_6() runs on test_CT {
6864 var MSC_ConnHdlr vc_conn;
6865 f_init(3, true);
6866 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006867 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006868 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_6));
6869 vc_conn.done;
6870
6871 /* f_tc_ho_neighbor_config_start() */
6872 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6873 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6874
6875 /* 6.a */
6876 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6877 * handover quickly by timing out after the Handover Required message */
6878 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6879 f_ctrs_bsc_and_bts_add(0, "handover:error");
6880
6881 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006882 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006883}
6884
Neels Hofmeyr91401012019-07-11 00:42:35 +02006885private function f_tc_ho_neighbor_config_7(charstring id) runs on MSC_ConnHdlr {
6886 f_tc_ho_neighbor_config_start();
6887
6888 /*
6889 * bts 0 ARFCN 871 BSIC 10
6890 * bts 1 ARFCN 871 BSIC 11
6891 * bts 2 ARFCN 871 BSIC 12
6892 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6893 */
6894
6895 log("f_tc_ho_neighbor_config: 7. explicit local and remote neighbors:"
6896 & " 'neighbor bts 2; neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006897 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006898 f_sleep(0.5);
6899
6900 f_probe_for_handover("7.a", "HO to 871-12 does HO to bts 2",
6901 "handover any to arfcn 871 bsic 12",
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02006902 true, expect_target_tsc := BTS_TSC[2]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006903 f_probe_for_handover("7.b", "HO to 123-45 triggers inter-BSC HO",
6904 "handover any to arfcn 123 bsic 45",
6905 true, true);
6906}
Neels Hofmeyr91401012019-07-11 00:42:35 +02006907testcase TC_ho_neighbor_config_7() runs on test_CT {
6908 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf2b88032020-06-16 00:35:04 +02006909 f_init(3, true, guard_timeout := 50.0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006910 f_sleep(1.0);
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006911 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006912 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_7));
6913 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006914
6915 /* f_tc_ho_neighbor_config_start() */
6916 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6917 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6918
6919 /* 7.a */
6920 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6921 * handover quickly by sending a Handover Failure message. */
6922 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6923 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6924 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6925 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01006926 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:attempted");
6927 f_ctrs_bts_add(2, "incoming_intra_bsc_ho:failed");
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006928
6929 /* 7.b */
6930 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6931 * handover quickly by timing out after the Handover Required message */
6932 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6933 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
6934 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
6935 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
6936
6937 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006938 f_shutdown_helper();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006939}
6940
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01006941/* OS#3041: Open and close N connections in a normal fashion, and expect no
6942 * BSSMAP Reset just because of that. */
6943testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
6944 var default d;
6945 var integer i;
6946 var DchanTuple dt;
6947
6948 f_init();
6949
6950 /* Wait for initial BSSMAP Reset to pass */
6951 f_sleep(4.0);
6952
6953 d := activate(no_bssmap_reset());
6954
6955 /* Setup up a number of connections and RLSD them again from the MSC
6956 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
6957 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02006958 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01006959 /* Since we're doing a lot of runs, give each one a fresh
6960 * T_guard from the top. */
6961 T_guard.start;
6962
6963 /* Setup a BSSAP connection and clear it right away. This is
6964 * the MSC telling the BSC about a planned release, it's not an
6965 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02006966 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01006967
6968 /* MSC disconnects (RLSD). */
6969 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
6970 }
6971
6972 /* In the buggy behavior, a timeout of 2 seconds happens between above
6973 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
6974 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
6975 f_sleep(4.0);
6976
6977 deactivate(d);
6978 f_shutdown_helper();
6979}
Harald Welte552620d2017-12-16 23:21:36 +01006980
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01006981/* OS#3041: Open and close N connections in a normal fashion, and expect no
6982 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
6983 * the MSC. */
6984testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
6985 var default d;
6986 var integer i;
6987 var DchanTuple dt;
6988 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01006989 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
6990 var BssmapCause cause := enum2int(cause_val);
6991
6992 f_init();
6993
6994 /* Wait for initial BSSMAP Reset to pass */
6995 f_sleep(4.0);
6996
6997 d := activate(no_bssmap_reset());
6998
6999 /* Setup up a number of connections and RLSD them again from the MSC
7000 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7001 * Let's do it some more times for good measure. */
7002 for (i := 0; i < 8; i := i+1) {
7003 /* Since we're doing a lot of runs, give each one a fresh
7004 * T_guard from the top. */
7005 T_guard.start;
7006
7007 /* Setup a BSSAP connection and clear it right away. This is
7008 * the MSC telling the BSC about a planned release, it's not an
7009 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02007010 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007011
7012 /* Instruct BSC to clear channel */
7013 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7014
7015 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02007016 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007017 }
7018
7019 /* In the buggy behavior, a timeout of 2 seconds happens between above
7020 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7021 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7022 f_sleep(4.0);
7023
7024 deactivate(d);
7025 f_shutdown_helper();
7026}
7027
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007028/* OS#3041: Open and close N connections in a normal fashion, and expect no
7029 * BSSMAP Reset just because of that. Close connections from the MS side with a
7030 * Release Ind on RSL. */
7031testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
7032 var default d;
7033 var integer i;
7034 var DchanTuple dt;
7035 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007036 var integer j;
7037
7038 f_init();
7039
7040 /* Wait for initial BSSMAP Reset to pass */
7041 f_sleep(4.0);
7042
7043 d := activate(no_bssmap_reset());
7044
7045 /* Setup up a number of connections and RLSD them again from the MSC
7046 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
7047 * Let's do it some more times for good measure. */
7048 for (i := 0; i < 8; i := i+1) {
7049 /* Since we're doing a lot of runs, give each one a fresh
7050 * T_guard from the top. */
7051 T_guard.start;
7052
7053 /* Setup a BSSAP connection and clear it right away. This is
7054 * the MSC telling the BSC about a planned release, it's not an
7055 * erratic loss of a connection. */
7056 dt := f_est_dchan('23'O, 23, '00010203040506'O);
7057
7058 /* simulate RLL REL IND */
7059 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
7060
7061 /* expect Clear Request on MSC side */
7062 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
7063
7064 /* Instruct BSC to clear channel */
7065 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
7066 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7067
7068 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02007069 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007070 }
7071
7072 /* In the buggy behavior, a timeout of 2 seconds happens between above
7073 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
7074 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
7075 f_sleep(4.0);
7076
7077 deactivate(d);
7078 f_shutdown_helper();
7079}
7080
Harald Welte94e0c342018-04-07 11:33:23 +02007081/***********************************************************************
7082 * IPA style dynamic PDCH
7083 ***********************************************************************/
7084
7085private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
7086 template (omit) RSL_Cause nack := omit)
7087runs on test_CT {
7088 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
7089 var RSL_Message rsl_unused;
7090 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
7091 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
7092 /* expect the BSC to issue the related RSL command */
7093 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7094 if (istemplatekind(nack, "omit")) {
7095 /* respond with a related acknowledgement */
7096 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7097 } else {
7098 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
7099 }
7100}
7101
7102private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
7103 template (omit) RSL_Cause nack := omit)
7104runs on test_CT {
7105 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
7106 var RSL_Message rsl_unused;
7107 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
7108 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
7109 /* expect the BSC to issue the related RSL command */
7110 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
7111 if (istemplatekind(nack, "omit")) {
7112 /* respond with a related acknowledgement */
7113 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
7114 } else {
7115 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
7116 }
7117}
7118
7119private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
7120runs on test_CT return charstring {
7121 var charstring cmd, resp;
7122 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01007123 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02007124}
7125
7126private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
7127 template charstring exp)
7128runs on test_CT {
7129 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
7130 if (not match(mode, exp)) {
7131 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02007132 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02007133 }
7134}
7135
7136private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
7137runs on test_CT {
7138 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
7139 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
7140 f_vty_transceive(BSCVTY, "end");
7141}
7142
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007143
7144private function f_ts_reset_chcomb(integer bts_nr) runs on test_CT {
7145 var integer i;
7146 for (i := 0; i < 8; i := i + 1) {
7147 f_ts_set_chcomb(bts_nr, 0, i, phys_chan_config[i]);
7148 }
7149}
7150
Harald Welte94e0c342018-04-07 11:33:23 +02007151private const charstring TCHF_MODE := "TCH/F mode";
7152private const charstring TCHH_MODE := "TCH/H mode";
7153private const charstring PDCH_MODE := "PDCH mode";
7154private const charstring NONE_MODE := "NONE mode";
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007155private const charstring SDCCH8_MODE := "SDCCH8 mode";
Harald Welte94e0c342018-04-07 11:33:23 +02007156
7157/* Test IPA PDCH activation / deactivation triggered by VTY */
7158testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
7159 var RSL_Message rsl_unused;
7160
7161 /* change Timeslot 6 before f_init() starts RSL */
7162 f_init_vty();
7163 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
7164 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7165
7166 f_init(1, false);
7167 f_sleep(1.0);
7168
7169 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
7170
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007171 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007172 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7173 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7174 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7175 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7176 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007177 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007178 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7179
7180 /* De-activate it via VTY */
7181 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7182 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007183 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007184 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7185
7186 /* re-activate it via VTY */
7187 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
7188 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007189 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007190 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7191
7192 /* and finally de-activate it again */
7193 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7194 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007195 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007196 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7197
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007198 /* clean up config */
7199 f_ts_set_chcomb(0, 0, 6, "PDCH");
7200
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007201 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007202}
7203
7204/* Test IPA PDCH activation NACK */
7205testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
7206 var RSL_Message rsl_unused;
7207
7208 /* change Timeslot 6 before f_init() starts RSL */
7209 f_init_vty();
7210 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
7211 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7212
7213 f_init(1, false);
7214 f_sleep(1.0);
7215
7216 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
7217
7218 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7219 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7220 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
7221 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
7222 f_sleep(1.0);
7223 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7224
7225 /* De-activate it via VTY */
7226 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
7227 f_sleep(1.0);
7228 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7229
7230 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
7231 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
7232 f_sleep(1.0);
7233 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
7234
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007235 /* clean up config */
7236 f_ts_set_chcomb(0, 0, 6, "PDCH");
7237
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007238 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007239}
7240
7241
7242/***********************************************************************
7243 * Osmocom style dynamic PDCH
7244 ***********************************************************************/
7245
7246private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
7247 template (omit) RSL_Cause nack := omit)
7248runs on test_CT {
7249 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
7250 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02007251 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02007252 /* FIXME: no VTY command to activate Osmocom PDCH !! */
7253 /* expect the BSC to issue the related RSL command */
7254 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
7255 if (istemplatekind(nack, "omit")) {
7256 /* respond with a related acknowledgement */
7257 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7258 } else {
7259 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
7260 }
7261}
7262
7263private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
7264 template (omit) RSL_Cause nack := omit)
7265runs on test_CT {
7266 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
7267 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02007268 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02007269 /* FIXME: no VTY command to activate Osmocom PDCH !! */
7270 /* expect the BSC to issue the related RSL command */
7271 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
7272 if (istemplatekind(nack, "omit")) {
7273 /* respond with a related acknowledgement */
7274 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
7275 } else {
7276 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
7277 }
7278}
7279
7280/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
7281testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
7282 var RSL_Message rsl_unused;
7283
7284 /* change Timeslot 6 before f_init() starts RSL */
7285 f_init_vty();
7286 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
7287 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7288
7289 f_init(1, false);
7290 f_sleep(1.0);
7291
7292 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
7293
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007294 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02007295 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7296 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7297 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
7298
7299 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7300 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02007301 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 +02007302 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
7303
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007304 /* clean up config */
7305 f_ts_set_chcomb(0, 0, 6, "PDCH");
7306
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007307 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007308}
7309
7310/* Test Osmocom dyn PDCH activation NACK behavior */
7311testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
7312 var RSL_Message rsl_unused;
7313
7314 /* change Timeslot 6 before f_init() starts RSL */
7315 f_init_vty();
7316 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
7317 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7318
7319 f_init(1, false);
7320 f_sleep(1.0);
7321
7322 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
7323
7324 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7325 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7326 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
7327
7328 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
7329 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
7330 f_sleep(1.0);
7331 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
7332
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02007333 /* clean up config */
7334 f_ts_set_chcomb(0, 0, 6, "PDCH");
7335
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007336 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02007337}
7338
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007339/* Test Osmocom dyn TS SDCCH8 activation / deactivation */
7340testcase TC_dyn_ts_sdcch8_act_deact() runs on test_CT {
7341 var RSL_Message rsl_unused, rsl_msg;
7342 var DchanTuple dt;
7343 var BSSAP_N_CONNECT_ind rx_c_ind;
7344
7345 /* change Timeslot 6 before f_init() starts RSL */
7346 f_init_vty();
7347 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
7348 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7349
7350 f_init(1, false);
7351 f_sleep(1.0);
7352
7353 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7354
7355 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7356 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7357 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7358 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr, ?));
7359
7360 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7361 f_sleep(1.0);
7362 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7363 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7364
7365 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7366 * on CCCH+SDCCH4+CBCH) */
7367 var integer i;
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007368 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02007369 dt := f_est_dchan('23'O, i, '00010203040506'O);
7370 }
7371
7372 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
7373 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
7374 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7375 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7376
7377 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7378 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7379
7380 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7381 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
7382 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7383 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7384
7385 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
7386 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
7387 dt.sccp_conn_id := rx_c_ind.connectionId;
7388 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
7389
7390 /* Instruct BSC to clear channel */
7391 var BssmapCause cause := 0;
7392 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7393 f_exp_chan_rel_and_clear(dt, 0);
7394
7395 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
7396 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr, ?));
7397 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7398 f_sleep(1.0);
7399 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7400
7401 /* clean up config */
7402 f_ts_set_chcomb(0, 0, 6, "PDCH");
7403
7404 f_shutdown_helper();
7405}
7406
Neels Hofmeyre1a7c4d2021-10-23 23:13:01 +02007407/* Validate all 8 subslots of a dynamics TS configured as SDCCH8 are used */
7408testcase TC_dyn_ts_sdcch8_all_subslots_used() runs on test_CT {
7409 var ASP_RSL_Unitdata rsl_ud;
7410 var integer i;
7411 var integer chreq_total, chreq_nochan;
7412
7413 f_init_vty();
7414 for (i := 1; i < 8; i := i + 1) {
7415 if (i == 2) {
7416 f_ts_set_chcomb(0, 0, i, "TCH/F_TCH/H_SDCCH8_PDCH");
7417 } else {
7418 f_ts_set_chcomb(0, 0, i, "PDCH");
7419 }
7420 }
7421 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7422
7423 f_init(1);
7424
7425 /* The dyn TS want to activate PDCH mode, ACK that. */
7426 var RslChannelNr chan_nr;
7427 chan_nr := valueof(t_RslChanNr_PDCH(2));
7428 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
7429 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
7430
7431 f_sleep(1.0);
7432
7433 /* Exhaust all dedicated SDCCH lchans.
7434 /* GSM 44.018 Table 9.1.8.2:
7435 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
7436 */
7437 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
7438 f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
7439 }
7440
7441 /* Only the dyn TS is still available. Its first lchan gets converted to SDCCH8 */
7442 f_est_dchan_dyn('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
7443 /* Also occupy the seven other SDCCH of the dyn TS */
7444 for (i := 0; i < 7; i := i+1) {
7445 f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
7446 }
7447
7448 /* clean up config */
7449 f_ts_reset_chcomb(0);
7450
7451 f_shutdown_helper();
7452}
7453
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007454/* Test Osmocom dyn TS SDCCH8 activation / deactivation: If activating dyn TS as
7455 SDCCH8 would end up in having no free TCH, then BSC should decide to activate
7456 it as TCH directly instead. SYS#5309. */
7457testcase TC_dyn_ts_sdcch8_tch_call_act_deact() runs on test_CT {
7458 var RSL_Message rsl_unused, rsl_msg;
7459 var DchanTuple dt;
7460 var BSSAP_N_CONNECT_ind rx_c_ind;
7461 var integer i;
7462
7463 /* change Timeslot 6 before f_init() starts RSL */
7464 f_init_vty();
7465 for (i := 1; i < 8; i := i + 1) {
7466 if (i == 6) {
7467 f_ts_set_chcomb(0, 0, i, "TCH/F_TCH/H_SDCCH8_PDCH");
7468 } else {
7469 f_ts_set_chcomb(0, 0, i, "PDCH");
7470 }
7471 }
7472 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7473
7474 f_init(1, false);
7475 f_sleep(1.0);
7476
7477 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7478
7479 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7480 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7481 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7482 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr, ?));
7483
7484 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7485 f_sleep(1.0);
7486 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7487 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7488
7489 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7490 * on CCCH+SDCCH4+CBCH) */
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007491 var OCT1 ra := '43'O; /* RA containing reason=originating speech call*/
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007492 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007493 dt := f_est_dchan(ra, i, '00010203040506'O);
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007494 }
7495
7496 /* Now the dyn ts is selected. First PDCH is released, then TCH chan is activated */
Pau Espin Pedrol2ebbe7c2021-07-23 16:17:09 +02007497 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int(ra) + i, 1), 2342));
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02007498 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7499 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7500
7501 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7502 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7503
7504 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
7505 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
7506 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7507 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
7508
7509 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
7510 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
7511 dt.sccp_conn_id := rx_c_ind.connectionId;
7512 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
7513
7514 /* Instruct BSC to clear channel */
7515 var BssmapCause cause := 0;
7516 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
7517 f_exp_chan_rel_and_clear(dt, 0);
7518
7519 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
7520 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr, ?));
7521 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7522 f_sleep(1.0);
7523 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7524
7525 /* clean up config */
7526 f_ts_reset_chcomb(0);
7527 /* TODO: clean up other channels? */
7528
7529 f_shutdown_helper();
7530}
7531
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007532/* Test Osmocom dyn TS SDCCH8 activation / deactivation when SDCCH fails at BTS */
7533testcase TC_dyn_ts_sdcch8_act_nack() runs on test_CT {
7534 var RSL_Message rsl_unused, rsl_msg;
7535 var DchanTuple dt;
7536 var BSSAP_N_CONNECT_ind rx_c_ind;
7537 var GsmRrMessage rr;
7538
7539 /* change Timeslot 6 before f_init() starts RSL */
7540 f_init_vty();
7541 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
7542 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7543
7544 f_init(1, false);
7545 f_sleep(1.0);
7546
7547 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
7548
7549 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
7550 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
7551 /* The BSC will activate the dynamic PDCH by default, so confirm that */
7552 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr, ?));
7553
7554 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7555 f_sleep(1.0);
7556 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7557 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7558
7559 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7560 * on CCCH+SDCCH4+CBCH) */
7561 var integer i;
Pau Espin Pedrolce4d5bb2021-10-25 13:31:25 +02007562 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i + 1) {
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02007563 dt := f_est_dchan('23'O, i, '00010203040506'O);
7564 }
7565
7566 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
7567 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
7568 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7569 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7570
7571 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7572 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7573
7574 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7575 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(dt.rsl_chan_nr, RSL_ERR_EQUIPMENT_FAIL));
7576 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7577 rr := dec_GsmRrMessage(rsl_msg.ies[1].body.full_imm_ass_info.payload);
7578 if (rr.header.message_type != IMMEDIATE_ASSIGNMENT_REJECT) {
7579 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Expected reject");
7580 }
7581
7582 /* FIXME? Currently the TS stays in state BORKEN: */
7583
7584 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
7585 /* rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr, ?));
7586 * f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7587 * f_sleep(1.0);
7588 * f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE)
7589 */
7590
7591 /* clean up config */
7592 f_ts_set_chcomb(0, 0, 6, "PDCH");
7593
7594 f_shutdown_helper();
7595}
7596
Stefan Sperling0796a822018-10-05 13:01:39 +02007597testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02007598 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02007599 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
7600 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
7601 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007602 f_shutdown_helper();
Stefan Sperling0796a822018-10-05 13:01:39 +02007603}
7604
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007605testcase TC_chopped_ipa_payload() runs on test_CT {
7606 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
7607 /* TODO: mp_bsc_ctrl_port does not work yet */};
7608 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
7609 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
7610 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007611 f_shutdown_helper();
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007612}
7613
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01007614/* Verify the BSC sends the MS Power Parameters IE during CHAN ACT to make sure
7615 the BTS does autonomous MS power control loop */
7616testcase TC_assignment_verify_ms_power_params_ie() runs on test_CT {
7617 var MSC_ConnHdlr vc_conn;
7618 var TestHdlrParams pars := f_gen_test_hdlr_pars();
7619 //pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
7620 pars.exp_ms_power_params := true;
7621
7622 f_init(1, true);
7623 f_sleep(1.0);
7624 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
7625 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007626 f_shutdown_helper();
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01007627}
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007628
Vadim Yanitskiy4b233042021-06-30 00:58:43 +02007629/* Verify activation and deactivation of the BCCH carrier power reduction mode */
7630testcase TC_c0_power_red_mode() runs on test_CT {
7631 f_init(1);
7632
7633 for (var integer red := 6; red >= 0; red := red - 2) {
7634 /* Configure BCCH carrier power reduction mode via the VTY */
7635 f_vty_transceive(BSCVTY, "bts 0 c0-power-reduction " & int2str(red));
7636
7637 /* Expect Osmocom specific BS Power Control message on the RSL */
7638 var template RSL_Message tr_rsl_pdu := tr_RSL_BS_PWR_CTRL(
7639 chan_nr := t_RslChanNr_BCCH(0),
7640 bs_power := tr_RSL_IE_BS_Power(red / 2));
7641 tr_rsl_pdu.msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false);
7642 var RSL_Message unused := f_exp_ipa_rx(0, tr_rsl_pdu);
7643
7644 /* Additionally verify the applied value over the CTRL interface */
7645 var CtrlValue cred := f_ctrl_get_bts(IPA_CTRL, 0, "c0-power-reduction");
7646 if (cred != int2str(red)) {
7647 setverdict(fail, "Unexpected BCCH carrier power reduction value ",
7648 cred, " (expected ", red, ")");
7649 }
7650 }
7651
7652 f_shutdown_helper();
7653}
7654
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007655/***********************************************************************
7656 * MSC Pooling
7657 ***********************************************************************/
7658
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007659template MobileIdentityLV ts_MI_TMSI_NRI_LV(integer nri_v, integer nri_bitlen := 10) :=
Harald Weltebf397612021-01-14 20:39:46 +01007660 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 +02007661
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007662private 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 +02007663runs on MSC_ConnHdlr {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007664 interleave {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007665 [] rsl_pt.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007666 f_logp(BSCVTY, "Got RSL RR Release");
7667 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007668 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007669 f_logp(BSCVTY, "Got RSL Deact SACCH");
7670 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02007671 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007672 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007673 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
7674 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007675 break;
7676 }
7677 }
7678}
7679
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007680friend function f_perform_clear(RSL_DCHAN_PT rsl_pt := RSL, RSLEM_PROC_PT rsl_proc_pt := RSL_PROC,
7681 template PDU_ML3_NW_MS exp_rr_rel_tmpl := tr_RRM_RR_RELEASE)
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02007682runs on MSC_ConnHdlr {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007683 f_logp(BSCVTY, "MSC instructs BSC to clear channel");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007684 BSSAP.send(ts_BSSMAP_ClearCommand(0));
7685 interleave {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007686 [] rsl_pt.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007687 f_logp(BSCVTY, "Got RSL RR Release");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007688 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007689 [] rsl_pt.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007690 f_logp(BSCVTY, "Got RSL Deact SACCH");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007691 }
7692 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007693 f_logp(BSCVTY, "Got BSSMAP Clear Complete");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007694 /* Also drop the SCCP connection */
7695 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
7696 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02007697 [] rsl_pt.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007698 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007699 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
7700 f_rslem_unregister(0, g_chan_nr, PT := rsl_proc_pt);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007701 }
7702 }
7703}
7704
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007705private function f_perform_compl_l3(RSL_DCHAN_PT rsl_pt, RSLEM_PROC_PT rsl_proc_pt,
7706 template PDU_ML3_MS_NW l3_info, boolean do_clear := true, boolean expect_bssmap_l3 := true)
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007707runs on MSC_ConnHdlr {
7708 timer T := 10.0;
7709 var octetstring l3_enc := enc_PDU_ML3_MS_NW(valueof(l3_info));
7710
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007711 f_logp(BSCVTY, "establish channel, send Complete Layer 3 Info");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007712 f_create_bssmap_exp(l3_enc);
7713
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007714 /* RSL_Emulation.f_chan_est() on rsl_pt:
7715 * This is basically code dup with s/RSL/rsl_pt from:
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007716 * RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
7717 */
7718 var RSL_Message rx_rsl;
7719 var GsmRrMessage rr;
7720
7721 /* request a channel to be established */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007722 rsl_pt.send(ts_RSLDC_ChanRqd(g_pars.ra, g_pars.fn));
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007723 /* expect immediate assignment.
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007724 * Code dup with s/RSL/rsl_pt from:
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007725 * rx_rsl := f_rx_or_fail(tr_RSL_IMM_ASSIGN);
7726 */
7727 timer Tt := 10.0;
7728
7729 /* request a channel to be established */
7730 Tt.start;
7731 alt {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007732 [] rsl_pt.receive(tr_RSL_IMM_ASSIGN) -> value rx_rsl {
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007733 Tt.stop;
7734 }
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007735 [] rsl_pt.receive {
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007736 setverdict(fail, "Unexpected RSL message on DCHAN");
7737 mtc.stop;
7738 }
7739 [] Tt.timeout {
7740 setverdict(fail, "Timeout waiting for RSL on DCHAN");
7741 mtc.stop;
7742 }
7743 }
7744 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
7745 g_chan_nr := rr.payload.imm_ass.chan_desc.chan_nr;
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007746 rsl_pt.send(ts_RSL_EST_IND(g_chan_nr, valueof(g_pars.link_id), l3_enc));
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007747
7748
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007749 if (expect_bssmap_l3) {
7750 f_logp(BSCVTY, "expect BSSAP Complete Layer 3 Info at MSC");
7751 var template PDU_BSSAP exp_l3_compl;
7752 exp_l3_compl := tr_BSSMAP_ComplL3()
7753 if (g_pars.aoip == false) {
7754 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := omit;
7755 } else {
7756 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := ?;
7757 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007758
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007759 var PDU_BSSAP bssap;
7760 T.start;
7761 alt {
7762 [] BSSAP.receive(exp_l3_compl) -> value bssap {
7763 f_logp(BSCVTY, "received expected Complete Layer 3 Info at MSC");
7764 log("rx exp_l3_compl = ", bssap);
7765 }
7766 [] BSSAP.receive(tr_BSSMAP_ComplL3) {
7767 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching COMPLETE LAYER 3 INFORMATION");
7768 }
7769 [] T.timeout {
7770 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
7771 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007772 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007773
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007774 /* start ciphering, if requested */
7775 if (ispresent(g_pars.encr)) {
7776 f_logp(BSCVTY, "start ciphering");
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007777 f_cipher_mode(g_pars.encr, rsl_pt := rsl_pt, rsl_proc_pt := rsl_proc_pt);
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007778 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007779 }
7780
7781 if (do_clear) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007782 f_perform_clear(rsl_pt, rsl_proc_pt);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007783 }
7784 setverdict(pass);
7785 f_sleep(1.0);
7786}
7787
7788private function f_tc_mscpool_compl_l3(charstring id) runs on MSC_ConnHdlr {
7789 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
7790 if (g_pars.mscpool.rsl_idx == 0) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007791 f_perform_compl_l3(RSL, RSL_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007792 } else if (g_pars.mscpool.rsl_idx == 1) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007793 f_perform_compl_l3(RSL1, RSL1_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007794 } else if (g_pars.mscpool.rsl_idx == 2) {
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007795 f_perform_compl_l3(RSL2, RSL2_PROC, g_pars.mscpool.l3_info);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007796 }
7797}
7798
7799/* Various Complete Layer 3 by IMSI all end up with the first MSC, because the other MSCs are not connected. */
7800private function f_tc_mscpool_L3Compl_on_1_msc(charstring id) runs on MSC_ConnHdlr {
7801 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02007802 f_perform_compl_l3(RSL, RSL_PROC, ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O) );
7803 f_perform_compl_l3(RSL, RSL_PROC, ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_IMSI_LV('001010000000002'H))) );
7804 f_perform_compl_l3(RSL, RSL_PROC, ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))) );
7805 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 +02007806}
7807testcase TC_mscpool_L3Compl_on_1_msc() runs on test_CT {
7808
7809 f_init(1, true);
7810 f_sleep(1.0);
7811 var MSC_ConnHdlr vc_conn;
7812 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007813
7814 f_ctrs_msc_init();
7815
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007816 vc_conn := f_start_handler(refers(f_tc_mscpool_L3Compl_on_1_msc), pars);
7817 vc_conn.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007818
7819 f_ctrs_msc_expect(0, "mscpool:subscr:new", 4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007820 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007821}
7822
7823/* Three Layer 3 Complete by IMSI are round-robin'ed across two connected MSCs */
7824/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7825 * just as well using only RSL. */
7826testcase TC_mscpool_L3Complete_by_imsi_round_robin() runs on test_CT {
7827
7828 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7829 f_sleep(1.0);
7830
7831 /* Control which MSC gets chosen next by the round-robin, otherwise
7832 * would be randomly affected by which other tests ran before this. */
7833 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7834
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007835 f_ctrs_msc_init();
7836
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007837 var MSC_ConnHdlr vc_conn1;
7838 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7839 pars1.mscpool.rsl_idx := 0;
7840 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
7841 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7842 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007843 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007844
7845 var MSC_ConnHdlr vc_conn2;
7846 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7847 pars2.mscpool.rsl_idx := 1;
7848 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
7849 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7850 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007851 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007852
7853 /* Test round-robin wrap to the first MSC */
7854 var MSC_ConnHdlr vc_conn3;
7855 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
7856 pars3.mscpool.rsl_idx := 2;
7857 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
7858 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7859 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007860 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007861 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007862}
7863
7864/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 0
7865 * (configured in osmo-bsc.cfg). */
7866/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7867 * just as well using only RSL. */
7868testcase TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() runs on test_CT {
7869
7870 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7871 f_sleep(1.0);
7872
7873 /* Control which MSC gets chosen next by the round-robin, otherwise
7874 * would be randomly affected by which other tests ran before this. */
7875 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7876
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007877 f_ctrs_msc_init();
7878
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007879 var MSC_ConnHdlr vc_conn1;
7880 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7881 pars1.mscpool.rsl_idx := 0;
7882 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
7883 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7884 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007885 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007886
7887 var MSC_ConnHdlr vc_conn2;
7888 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7889 pars2.mscpool.rsl_idx := 1;
7890 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
7891 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7892 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007893 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007894
7895 /* Test round-robin wrap to the first MSC */
7896 var MSC_ConnHdlr vc_conn3;
7897 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
7898 pars3.mscpool.rsl_idx := 2;
7899 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
7900 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7901 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007902 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007903 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007904}
7905
7906/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 1
7907 * (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
7908 * NULL-NRI setting is stronger than that. */
7909/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7910 * just as well using only RSL. */
7911testcase TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() runs on test_CT {
7912
7913 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7914 f_sleep(1.0);
7915
7916 /* Control which MSC gets chosen next by the round-robin, otherwise
7917 * would be randomly affected by which other tests ran before this. */
7918 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7919
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007920 f_ctrs_msc_init();
7921
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007922 var MSC_ConnHdlr vc_conn1;
7923 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7924 pars1.mscpool.rsl_idx := 0;
7925 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
7926 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7927 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007928 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007929
7930 var MSC_ConnHdlr vc_conn2;
7931 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7932 pars2.mscpool.rsl_idx := 1;
7933 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
7934 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7935 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007936 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007937
7938 /* Test round-robin wrap to the first MSC */
7939 var MSC_ConnHdlr vc_conn3;
7940 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
7941 pars3.mscpool.rsl_idx := 2;
7942 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
7943 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7944 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007945 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007946 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007947}
7948
7949/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI not
7950 * assigned to any MSC (configured in osmo-bsc.cfg). */
7951/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7952 * just as well using only RSL. */
7953testcase TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() runs on test_CT {
7954
7955 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7956 f_sleep(1.0);
7957
7958 /* Control which MSC gets chosen next by the round-robin, otherwise
7959 * would be randomly affected by which other tests ran before this. */
7960 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7961
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007962 f_ctrs_msc_init();
7963
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007964 var MSC_ConnHdlr vc_conn1;
7965 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7966 pars1.mscpool.rsl_idx := 0;
7967 /* An NRI that is not assigned to any MSC */
7968 pars1.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(1023))));
7969 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7970 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007971 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007972
7973 var MSC_ConnHdlr vc_conn2;
7974 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7975 pars2.mscpool.rsl_idx := 1;
7976 /* An NRI that is not assigned to any MSC */
7977 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(768)), '00F110'O));
7978 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7979 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007980 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007981
7982 /* Test round-robin wrap to the first MSC */
7983 var MSC_ConnHdlr vc_conn3;
7984 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
7985 pars3.mscpool.rsl_idx := 2;
7986 /* An NRI that is not assigned to any MSC */
7987 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, valueof(ts_MI_TMSI_NRI_LV(819))));
7988 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7989 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007990 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007991 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007992}
7993
7994/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI
7995 * assigned to an MSC that is currently not connected (configured in osmo-bsc.cfg). */
7996/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7997 * just as well using only RSL. */
7998testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() runs on test_CT {
7999
8000 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8001 f_sleep(1.0);
8002
8003 /* Control which MSC gets chosen next by the round-robin, otherwise
8004 * would be randomly affected by which other tests ran before this. */
8005 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8006
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008007 f_ctrs_msc_init();
8008
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008009 var MSC_ConnHdlr vc_conn1;
8010 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8011 pars1.mscpool.rsl_idx := 0;
8012 /* An NRI that is assigned to an unconnected MSC */
8013 pars1.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(512))));
8014 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8015 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008016 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8017 f_ctrs_msc_add(0, "mscpool:subscr:new");
8018 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008019
8020 var MSC_ConnHdlr vc_conn2;
8021 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8022 pars2.mscpool.rsl_idx := 1;
8023 /* An NRI that is assigned to an unconnected MSC */
8024 pars2.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(767))));
8025 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8026 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008027 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8028 f_ctrs_msc_add(1, "mscpool:subscr:new");
8029 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008030
8031 /* Test round-robin wrap to the first MSC */
8032 var MSC_ConnHdlr vc_conn3;
8033 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8034 pars3.mscpool.rsl_idx := 2;
8035 /* An NRI that is assigned to an unconnected MSC */
8036 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(750)), '00F110'O));
8037 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8038 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008039 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
8040 f_ctrs_msc_add(0, "mscpool:subscr:new");
8041 f_ctrs_msc_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008042 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008043}
8044
8045/* Three Layer 3 Complete by TMSI with valid NRI for the second MSC are all directed to the second MSC (configured in
8046 * osmo-bsc.cfg). */
8047/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8048 * just as well using only RSL. */
8049testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_1() runs on test_CT {
8050
8051 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
8052 f_sleep(1.0);
8053
8054 /* All TMSIs in this test point at the second MSC, set the round robin to point at the first MSC to make sure
8055 * this is not using round-robin. */
8056 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8057
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008058 f_ctrs_msc_init();
8059
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008060 var MSC_ConnHdlr vc_conn1;
8061 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
8062 pars1.mscpool.rsl_idx := 0;
8063 /* An NRI of the second MSC's range (256-511) */
8064 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(256))));
8065 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8066 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008067 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008068
8069 var MSC_ConnHdlr vc_conn2;
8070 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
8071 pars2.mscpool.rsl_idx := 1;
8072 /* An NRI of the second MSC's range (256-511) */
8073 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(260))));
8074 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8075 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008076 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008077
8078 var MSC_ConnHdlr vc_conn3;
8079 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
8080 pars3.mscpool.rsl_idx := 2;
8081 /* An NRI of the second MSC's range (256-511) */
8082 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(511)), '00F110'O));
8083 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8084 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008085 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008086 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008087}
8088
8089/* Layer 3 Complete by TMSI with valid NRI for the third MSC are directed to the third MSC (configured in osmo-bsc.cfg),
8090 * while a round-robin remains unaffected by that. */
8091/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8092 * just as well using only RSL. */
8093testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_2() runs on test_CT {
8094
8095 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8096 f_sleep(1.0);
8097
8098 /* All TMSIs in this test point at the third MSC, set the round robin to point at the second MSC to make sure
8099 * this is not using round-robin. */
8100 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
8101
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008102 f_ctrs_msc_init();
8103
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008104 var MSC_ConnHdlr vc_conn1;
8105 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 2);
8106 pars1.mscpool.rsl_idx := 0;
8107 /* An NRI of the third MSC's range (512-767) */
8108 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(512))));
8109 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8110 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008111 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008112
8113 var MSC_ConnHdlr vc_conn2;
8114 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8115 pars2.mscpool.rsl_idx := 1;
8116 /* An NRI of the third MSC's range (512-767) */
8117 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(678))));
8118 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8119 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008120 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008121
8122 /* The above forwardings to third MSC have not affected the round robin, which still points at the second MSC */
8123 var MSC_ConnHdlr vc_conn3;
8124 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
8125 pars3.mscpool.rsl_idx := 2;
8126 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000013'H)), '00F110'O));
8127 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8128 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008129 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008130 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008131}
8132
8133/* LU with a TMSI but indicating a different PLMN in its previous LAI: ignore the NRI. */
8134/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8135 * just as well using only RSL. */
8136testcase TC_mscpool_LU_by_tmsi_from_other_PLMN() runs on test_CT {
8137
8138 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8139 f_sleep(1.0);
8140
8141 /* The TMSIs in this test points at the second MSC, but since it is from a different PLMN, round-robin is used
8142 * instead, and hits msc 0. */
8143 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8144
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008145 f_ctrs_msc_init();
8146
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008147 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-bsc.cfg */
8148 var MSC_ConnHdlr vc_conn1;
8149 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8150 pars1.mscpool.rsl_idx := 0;
8151 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(260)), '99F999'O));
8152 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8153 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008154 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008155
8156 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
8157 var MSC_ConnHdlr vc_conn2;
8158 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8159 pars2.mscpool.rsl_idx := 1;
8160 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(555)), '00F110'O));
8161 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8162 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008163 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008164 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008165}
8166
8167/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by IMSI, which would be
8168 * round-robined to another MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
8169private function f_tc_mscpool_paging_imsi(charstring id) runs on MSC_ConnHdlr {
8170 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
8171 //cid_list := { cIl_allInBSS := ''O };
8172 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
8173 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
8174 var BSSAP_N_UNITDATA_req paging;
8175 var hexstring imsi := '001010000000123'H;
8176
8177 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8178
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008179 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008180 valueof(ts_BSSMAP_Paging(imsi, cid_list, omit, bssmap_chneed))));
8181 BSSAP.send(paging);
8182
8183 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
8184 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
8185 * channel number is picked here. */
8186 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
8187 f_rslem_register(0, new_chan_nr);
8188 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(imsi)));
8189 f_rslem_unregister(0, new_chan_nr);
8190
8191 /* Despite the round robin pointing at the second MSC ('roundrobin next 1'), the earlier Paging for the same IMSI
8192 * causes this Paging Response to go to the first MSC (bssap_idx := 0). */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008193 f_perform_compl_l3(RSL, RSL_PROC, ts_PAG_RESP(valueof(ts_MI_IMSI_LV(imsi))) );
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008194 f_sleep(1.0);
8195}
8196testcase TC_mscpool_paging_and_response_imsi() runs on test_CT {
8197 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
8198 f_sleep(1.0);
8199
8200 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
8201 * second MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
8202 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
8203
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008204 f_ctrs_msc_init();
8205
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008206 var MSC_ConnHdlr vc_conn1;
8207 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8208 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008209 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
8210 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008211 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_imsi), pars1);
8212 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008213 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008214 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008215}
8216
8217/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by TMSI with an NRI value
8218 * that matches a different MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
8219private function f_tc_mscpool_paging_tmsi(charstring id) runs on MSC_ConnHdlr {
8220 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
8221 //cid_list := { cIl_allInBSS := ''O };
8222 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
8223 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
8224 var integer nri_v := 300; /* <-- second MSC's NRI */
Harald Weltebf397612021-01-14 20:39:46 +01008225 var octetstring tmsi := f_gen_tmsi(suffix := 0, nri_v := nri_v);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008226 var BSSAP_N_UNITDATA_req paging;
8227
8228 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8229
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008230 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008231 valueof(ts_BSSMAP_Paging('001010000000011'H, cid_list, tmsi, bssmap_chneed))));
8232 BSSAP.send(paging);
8233
8234 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
8235 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
8236 * channel number is picked here. */
8237 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
8238 f_rslem_register(0, new_chan_nr);
8239 RSL.receive(tr_RSL_PAGING_CMD(t_MI_TMSI(tmsi)));
8240 f_rslem_unregister(0, new_chan_nr);
8241
8242 /* Despite the NRI matching the second MSC (NRI from 'msc 1' in osmo-bsc.cfg) and round robin pointing at the
8243 * third MSC ('roundrobin next 2'), the earlier Paging for the same TMSI causes this Paging Response to go to
8244 * the first MSC (bssap_idx := 0). */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02008245 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 +02008246 f_sleep(1.0);
8247}
8248testcase TC_mscpool_paging_and_response_tmsi() runs on test_CT {
8249 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
8250 f_sleep(1.0);
8251
8252 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
8253 * third MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
8254 f_vty_transceive(BSCVTY, "mscpool roundrobin next 2");
8255
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008256 f_ctrs_msc_init();
8257
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008258 var MSC_ConnHdlr vc_conn1;
8259 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8260 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02008261 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
8262 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008263 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_tmsi), pars1);
8264 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008265 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008266 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008267}
8268
8269/* For round-robin, skip an MSC that has 'no allow-attach' set. */
8270/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
8271 * just as well using only RSL. */
8272testcase TC_mscpool_no_allow_attach_round_robin() runs on test_CT {
8273
8274 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8275 f_sleep(1.0);
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00008276 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
8277 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008278
8279 /* Control which MSC gets chosen next by the round-robin, otherwise
8280 * would be randomly affected by which other tests ran before this. */
8281 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8282
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008283 f_ctrs_msc_init();
8284
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008285 var MSC_ConnHdlr vc_conn1;
8286 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
8287 pars1.mscpool.rsl_idx := 0;
8288 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
8289 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8290 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008291 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008292
8293 var MSC_ConnHdlr vc_conn2;
8294 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
8295 pars2.mscpool.rsl_idx := 1;
8296 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8297 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8298 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008299 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008300
8301 var MSC_ConnHdlr vc_conn3;
8302 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
8303 pars3.mscpool.rsl_idx := 2;
8304 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
8305 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8306 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008307 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008308 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008309}
8310
8311/* An MSC that has 'no allow-attach' set should still serve subscribers that are already attached according to their
8312 * TMSI NRI. */
8313testcase TC_mscpool_no_allow_attach_valid_nri() runs on test_CT {
8314
8315 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
8316 f_sleep(1.0);
8317
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00008318 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
8319 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
8320
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008321 /* Control which MSC gets chosen next by the round-robin, otherwise
8322 * would be randomly affected by which other tests ran before this. */
8323 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
8324
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008325 f_ctrs_msc_init();
8326
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008327 /* Round robin points at msc 0, but the valid NRI directs to msc 1, even though msc 1 has 'no allow-attach'. */
8328 var MSC_ConnHdlr vc_conn1;
8329 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
8330 pars1.mscpool.rsl_idx := 0;
8331 /* An NRI of the second MSC's range (256-511) */
8332 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_TMSI_NRI_LV(260))));
8333 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
8334 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008335 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008336
8337 var MSC_ConnHdlr vc_conn2;
8338 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 0);
8339 pars2.mscpool.rsl_idx := 1;
8340 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
8341 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
8342 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008343 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008344
8345 var MSC_ConnHdlr vc_conn3;
8346 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 2);
8347 pars3.mscpool.rsl_idx := 2;
8348 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000003'H))));
8349 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
8350 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02008351 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008352 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02008353}
8354
Philipp Maier783681c2020-07-16 16:47:06 +02008355/* Allow/Deny emergency calls globally via VTY */
8356private function f_vty_allow_emerg_msc(boolean allow) runs on test_CT {
8357 f_vty_enter_cfg_msc(BSCVTY, 0);
8358 if (allow) {
8359 f_vty_transceive(BSCVTY, "allow-emergency allow");
8360 } else {
8361 f_vty_transceive(BSCVTY, "allow-emergency deny");
8362 }
8363 f_vty_transceive(BSCVTY, "exit");
8364 f_vty_transceive(BSCVTY, "exit");
8365}
8366
8367/* Allow/Deny emergency calls per BTS via VTY */
8368private function f_vty_allow_emerg_bts(boolean allow, integer bts_nr) runs on test_CT {
8369 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8370 if (allow) {
8371 f_vty_transceive(BSCVTY, "rach emergency call allowed 1");
8372 } else {
8373 f_vty_transceive(BSCVTY, "rach emergency call allowed 0");
8374 }
8375 f_vty_transceive(BSCVTY, "exit");
8376 f_vty_transceive(BSCVTY, "exit");
Neels Hofmeyrb6ed80c2020-10-12 22:52:39 +00008377 f_vty_transceive(BSCVTY, "exit");
Philipp Maier783681c2020-07-16 16:47:06 +02008378}
8379
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02008380/* Allow/Forbid Fast Return after SRVCC on a given BTS via VTY */
8381private function f_vty_allow_srvcc_fast_return(boolean allow, integer bts_nr) runs on test_CT {
8382 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8383 if (allow) {
8384 f_vty_transceive(BSCVTY, "srvcc fast-return allow");
8385 } else {
8386 f_vty_transceive(BSCVTY, "srvcc fast-return forbid");
8387 }
8388 f_vty_transceive(BSCVTY, "exit");
8389 f_vty_transceive(BSCVTY, "exit");
8390 f_vty_transceive(BSCVTY, "exit");
8391}
8392
Pau Espin Pedrol14475352021-07-22 15:48:16 +02008393/* Allow/Forbid TCH for signalling if SDCCH exhausted on a given BTS via VTY */
8394private function f_vty_allow_tch_for_signalling(boolean allow, integer bts_nr) runs on test_CT {
8395 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8396 if (allow) {
8397 f_vty_transceive(BSCVTY, "channel allocator allow-tch-for-signalling 1");
8398 } else {
8399 f_vty_transceive(BSCVTY, "channel allocator allow-tch-for-signalling 0");
8400 }
8401 f_vty_transceive(BSCVTY, "exit");
8402 f_vty_transceive(BSCVTY, "exit");
8403 f_vty_transceive(BSCVTY, "exit");
8404}
8405
Philipp Maier783681c2020-07-16 16:47:06 +02008406/* Begin assignmet procedure and send an EMERGENCY SETUP (RR) */
8407private function f_assignment_emerg_setup() runs on MSC_ConnHdlr {
8408 var PDU_ML3_MS_NW emerg_setup;
8409 var octetstring emerg_setup_enc;
8410 var RSL_Message emerg_setup_data_ind;
8411
8412 f_establish_fully(omit, omit);
8413
8414 emerg_setup := valueof(ts_ML3_MO_CC_EMERG_SETUP(1, valueof(ts_Bcap_voice)));
8415 emerg_setup_enc := enc_PDU_ML3_MS_NW(emerg_setup);
8416 emerg_setup_data_ind := valueof(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), emerg_setup_enc));
8417
8418 RSL.send(emerg_setup_data_ind);
8419}
8420
8421/* Test if the EMERGENCY SETUP gets passed on to the MSC via A when EMERGENCY
8422 * CALLS are permitted by the BSC config. */
8423private function f_TC_assignment_emerg_setup_allow(charstring id) runs on MSC_ConnHdlr {
8424 var PDU_BSSAP emerg_setup_data_ind_bssap;
8425 var PDU_ML3_MS_NW emerg_setup;
8426 timer T := 3.0;
8427
8428 f_assignment_emerg_setup()
8429
8430 T.start;
8431 alt {
8432 [] BSSAP.receive(tr_BSSAP_DTAP) -> value emerg_setup_data_ind_bssap {
8433 emerg_setup := dec_PDU_ML3_MS_NW(emerg_setup_data_ind_bssap.pdu.dtap);
8434 if (not isbound(emerg_setup.msgs.cc.emergencySetup)) {
8435 setverdict(fail, "no emergency setup");
8436 }
8437 }
8438 [] BSSAP.receive {
8439 setverdict(fail, "unexpected BSSAP message!");
8440 }
8441 [] T.timeout {
8442 setverdict(fail, "timout waiting for EMERGENCY SETUP!");
8443 }
8444 }
8445
8446 setverdict(pass);
8447}
8448
8449/* Test if the EMERGENCY SETUP gets blocked by the BSC if EMERGENCY CALLS are
8450 * forbidden by the BSC config. */
8451private function f_TC_assignment_emerg_setup_deny(charstring id) runs on MSC_ConnHdlr {
8452 var PDU_BSSAP emerg_setup_data_ind_bssap;
8453 timer T := 3.0;
8454
8455 f_assignment_emerg_setup()
8456
8457 T.start;
8458 alt {
8459 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
8460 setverdict(pass);
8461 }
8462 [] RSL.receive {
8463 setverdict(fail, "unexpected RSL message!");
8464 }
8465 [] T.timeout {
8466 setverdict(fail, "timout waiting for RR CHANNEL RELEASE!");
8467 }
8468 }
8469}
8470
8471/* EMERGENCY CALL situation #1, allowed globally and by BTS */
8472testcase TC_assignment_emerg_setup_allow() runs on test_CT {
8473 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8474 var MSC_ConnHdlr vc_conn;
8475
8476 f_init(1, true);
8477 f_sleep(1.0);
8478
8479 f_vty_allow_emerg_msc(true);
8480 f_vty_allow_emerg_bts(true, 0);
8481 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_allow), pars);
8482 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008483 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008484}
8485
8486/* EMERGENCY CALL situation #2, forbidden globally but allowed by BTS */
8487testcase TC_assignment_emerg_setup_deny_msc() runs on test_CT {
8488 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8489 var MSC_ConnHdlr vc_conn;
8490
8491 f_init(1, true);
8492 f_sleep(1.0);
8493
8494 f_vty_allow_emerg_msc(false);
8495 f_vty_allow_emerg_bts(true, 0);
8496 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
8497 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008498 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008499}
8500
8501/* EMERGENCY CALL situation #3, allowed globally but forbidden by BTS */
8502testcase TC_assignment_emerg_setup_deny_bts() runs on test_CT {
8503 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8504 var MSC_ConnHdlr vc_conn;
8505
8506 /* Note: This simulates a spec violation by the MS, correct MS
8507 * implementations would not try to establish an emergency call because
8508 * the system information tells in advance that emergency calls are
8509 * not forbidden */
8510
8511 f_init(1, true);
8512 f_sleep(1.0);
8513
8514 f_vty_allow_emerg_msc(true);
8515 f_vty_allow_emerg_bts(false, 0);
8516 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
8517 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008518 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02008519}
8520
Philipp Maier82812002020-08-13 18:48:27 +02008521/* Test what happens when an emergency call arrives while all TCH channels are
8522 * busy, the BSC is expected to terminate one call in favor of the incoming
8523 * emergency call */
8524testcase TC_emerg_premption() runs on test_CT {
8525 var ASP_RSL_Unitdata rsl_ud;
8526 var integer i;
8527 var integer chreq_total, chreq_nochan;
8528 var RSL_Message rx_rsl;
8529 var RslChannelNr chan_nr;
8530
8531 f_init(1);
8532 f_sleep(1.0);
8533
8534 f_vty_allow_emerg_msc(true);
8535 f_vty_allow_emerg_bts(true, 0);
8536
8537 /* Fill up all channels on the BTS */
8538 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
8539 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
8540 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS; i := i+1) {
8541 chan_nr := f_chreq_act_ack('33'O, i);
8542 }
8543 IPA_RSL[0].clear;
8544 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
8545 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
8546
8547 /* Send Channel request for emegergency call */
8548 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
8549
8550 /* Expect the BSC to release one (the first) TCH/F on the BTS */
8551 chan_nr := valueof(t_RslChanNr_Bm(1));
8552 f_expect_chan_rel(0, chan_nr, expect_rr_chan_rel := false, expect_rll_rel_req := false);
8553
8554 /* Expect the BSC to send activate/assign the a channel for the emergency call */
8555 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8556 chan_nr := rx_rsl.ies[0].body.chan_nr;
8557 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 33));
8558 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Philipp Maier104f4c02020-09-11 18:12:18 +02008559
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02008560 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008561}
8562
8563/* Hopping parameters per a timeslot */
Vadim Yanitskiybc6654a2020-09-13 01:27:40 +07008564private type record length(0..64) of GsmArfcn ArfcnList;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008565private type record FHParamsTs {
8566 boolean enabled,
8567 uint6_t hsn,
8568 uint6_t maio,
8569 ArfcnList ma
8570};
8571
8572/* Hopping parameters per a transceiver */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008573private type record FHParamsTrx {
Philipp Maier798d8952021-10-19 14:43:19 +02008574 GsmBandArfcn arfcn,
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008575 FHParamsTs ts[8]
8576};
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008577
8578/* Randomly generate the hopping parameters for the given timeslot numbers */
8579private function f_TC_fh_params_gen(template integer tr_tn := (1, 3, 5))
8580runs on test_CT return FHParamsTrx {
8581 var FHParamsTrx fhp;
8582
Philipp Maier798d8952021-10-19 14:43:19 +02008583 /* Generate a random ARFCN in the range of 0 - 3. This ARFCN will
8584 * fall in the GSM900 band. */
8585 fhp.arfcn.arfcn := f_rnd_int(3);
8586 fhp.arfcn.pcs := false;
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008587
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008588 for (var integer tn := 0; tn < 8; tn := tn + 1) {
8589 if (not match(tn, tr_tn)) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008590 fhp.ts[tn].enabled := false;
8591 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008592 continue;
8593 }
8594
8595 /* Random HSN / MAIO values: 0..63 */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008596 fhp.ts[tn].hsn := f_rnd_int(64);
8597 fhp.ts[tn].maio := f_rnd_int(64);
8598 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008599
8600 /* Random Mobile Allocation (hopping channels) */
8601 var integer ma_len := 2 + f_rnd_int(9); /* 2..10 channels */
8602 var integer step := 3 + f_rnd_int(4); /* 3..6 stepping */
8603 for (var integer i := 1; i <= ma_len; i := i + 1) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008604 fhp.ts[tn].ma := fhp.ts[tn].ma & { i * step };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008605 }
8606
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008607 fhp.ts[tn].enabled := true;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008608 }
8609
8610 log("f_TC_fh_params_gen(): ", fhp);
8611 return fhp;
8612}
8613
8614/* Make sure that the given Channel Description IE matches the hopping configuration */
8615private function f_TC_fh_params_match_chan_desc(in FHParamsTrx fhp, in ChannelDescription cd)
8616{
8617 var template (present) ChannelDescription tr_cd;
8618 var template (present) MaioHsn tr_maio_hsn;
8619 var uint3_t tn := cd.chan_nr.tn;
8620
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008621 if (fhp.ts[tn].enabled) {
8622 tr_maio_hsn := tr_HsnMaio(fhp.ts[tn].hsn, fhp.ts[tn].maio);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008623 tr_cd := tr_ChanDescH1(cd.chan_nr, tr_maio_hsn);
8624 } else {
Philipp Maier798d8952021-10-19 14:43:19 +02008625 tr_cd := tr_ChanDescH0(cd.chan_nr, fhp.arfcn.arfcn);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008626 }
8627
8628 if (not match(cd, tr_cd)) {
8629 setverdict(fail, "Channel Description IE does not match: ",
8630 cd, " vs expected ", tr_cd);
8631 }
8632}
8633
8634/* Make sure that the given Mobile Allocation IE matches the hopping configuration */
8635private function f_TC_fh_params_match_ma(in FHParamsTrx fhp, uint3_t tn,
8636 in MobileAllocationLV ma)
8637{
8638 var template MobileAllocationLV tr_ma := f_TC_fh_params_gen_tr_ma(fhp, tn, ma);
8639
8640 if (not match(ma, tr_ma)) {
8641 setverdict(fail, "Mobile Allocation IE does not match (tn := ",
8642 tn, "): ", ma, " vs expected: ", tr_ma);
8643 } else {
8644 setverdict(pass);
8645 }
8646}
8647
8648private function f_TC_fh_params_gen_tr_ma(in FHParamsTrx fhp, uint3_t tn,
8649 in MobileAllocationLV ma)
8650return template MobileAllocationLV {
8651 /* Mobile Allocation IE is expected to be empty if hopping is not enabled */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008652 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008653 return { len := 0, ma := ''B };
8654 }
8655
8656 var bitstring full_mask := f_pad_bit(''B, 1024, '0'B);
8657 var bitstring slot_mask := f_pad_bit(''B, 1024, '0'B);
8658 var bitstring ma_mask := ''B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008659
8660 /* Compose the full bit-mask (all channels, up to 1024 entries) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008661 for (var integer i := 0; i < lengthof(fhp.ts); i := i + 1) {
8662 for (var integer j := 0; j < lengthof(fhp.ts[i].ma); j := j + 1) {
8663 if (full_mask[fhp.ts[i].ma[j]] == '1'B)
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008664 { continue; }
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008665 full_mask[fhp.ts[i].ma[j]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008666 }
8667 }
8668
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008669 /* Take ARFCN of the TRX itself into account */
Philipp Maier798d8952021-10-19 14:43:19 +02008670 full_mask[fhp.arfcn.arfcn] := '1'B;
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008671
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008672 /* Compose a bit-mask for the given timeslot number */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008673 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
8674 slot_mask[fhp.ts[tn].ma[i]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008675 }
8676
8677 /* Finally, compose the Mobile Allocation bit-mask */
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07008678 for (var integer i := 1; i < lengthof(full_mask); i := i + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008679 if (full_mask[i] != '1'B)
8680 { continue; }
8681
8682 /* FIXME: ma_mask := ma_mask & slot_mask[i]; // triggers a bug in TITAN */
8683 if (slot_mask[i] == '1'B) {
8684 ma_mask := ma_mask & '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008685 } else {
8686 ma_mask := ma_mask & '0'B;
8687 }
8688 }
8689
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07008690 /* ARFCN 0 (if present) goes to the last position of the bit-mask */
8691 if (full_mask[0] == '1'B) {
8692 /* FIXME: ma_mask := ma_mask & slot_mask[0]; // triggers a bug in TITAN */
8693 if (slot_mask[0] == '1'B) {
8694 ma_mask := ma_mask & '1'B;
8695 } else {
8696 ma_mask := ma_mask & '0'B;
8697 }
8698 }
8699
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008700 /* Ensure that ma_mask is octet-aligned */
Vadim Yanitskiy2aa02522020-09-06 14:05:23 +07008701 var integer ma_mask_len := (lengthof(ma_mask) + 8 - 1) / 8;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008702 ma_mask := f_pad_bit(ma_mask, ma_mask_len * 8, '0'B);
8703
8704 return { len := ma_mask_len, ma := ma_mask };
8705}
8706
Philipp Maier798d8952021-10-19 14:43:19 +02008707/* Configure the appropriate band for a given arfcn, exc */
8708private function f_TC_set_band_by_arfcn(integer bts_nr, GsmBandArfcn arfcn) runs on test_CT
8709{
8710 var charstring band;
8711 var GsmBandArfcn arfcn_ := valueof(ts_GsmBandArfcn(arfcn.arfcn, arfcn.pcs, false));
8712
8713 select (arfcn_) {
8714 case (tr_GsmBandArfcn((259..293), false, ?)) { band := "GSM450"; }
8715 case (tr_GsmBandArfcn((306..340), false, ?)) { band := "GSM480"; }
8716 case (tr_GsmBandArfcn((438..511), false, ?)) { band := "GSM750"; }
8717 case (tr_GsmBandArfcn((128..251), false, ?)) { band := "GSM850"; }
8718 case (tr_GsmBandArfcn((0..124), false, ?)) { band := "GSM900"; }
8719 case (tr_GsmBandArfcn((955..1023), false, ?)) { band := "GSM900"; }
8720 case (tr_GsmBandArfcn((512..885), false, ?)) { band := "DCS1800"; }
8721 case (tr_GsmBandArfcn((512..810), true, ?)) { band := "PCS1900"; }
8722 case else { return; }
8723 }
8724
8725 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
8726 f_vty_transceive(BSCVTY, "band " & band);
8727 f_vty_transceive(BSCVTY, "end");
8728}
8729
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008730/* Configure the hopping parameters in accordance with the given record */
8731private function f_TC_fh_params_set(in FHParamsTrx fhp,
8732 uint8_t bts_nr := 0,
8733 uint8_t trx_nr := 0)
8734runs on test_CT {
Philipp Maier798d8952021-10-19 14:43:19 +02008735
8736 f_TC_set_band_by_arfcn(bts_nr, fhp.arfcn);
8737
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008738 /* Enter the configuration node for the given BTS/TRX numbers */
8739 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
8740
Philipp Maier798d8952021-10-19 14:43:19 +02008741 f_vty_transceive(BSCVTY, "arfcn " & int2str(fhp.arfcn.arfcn));
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008742
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008743 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008744 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
8745
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008746 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008747 f_vty_transceive(BSCVTY, "hopping enabled 0");
8748 f_vty_transceive(BSCVTY, "exit"); /* go back */
8749 continue;
8750 }
8751
8752 /* Configure HSN / MAIO values */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008753 f_vty_transceive(BSCVTY, "hopping sequence-number " & int2str(fhp.ts[tn].hsn));
8754 f_vty_transceive(BSCVTY, "hopping maio " & int2str(fhp.ts[tn].maio));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008755
8756 /* Configure the Mobile Allocation (hopping channels) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008757 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
8758 f_vty_transceive(BSCVTY, "hopping arfcn add " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008759 }
8760
8761 f_vty_transceive(BSCVTY, "hopping enabled 1");
8762 f_vty_transceive(BSCVTY, "exit"); /* go back */
8763 }
8764
8765 f_vty_transceive(BSCVTY, "end");
8766}
8767
8768/* Disable frequency hopping on all timeslots */
8769private function f_TC_fh_params_unset(in FHParamsTrx fhp,
8770 uint8_t bts_nr := 0,
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008771 uint8_t trx_nr := 0,
Philipp Maier798d8952021-10-19 14:43:19 +02008772 GsmBandArfcn arfcn := {pcs := false, arfcn := 871})
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008773runs on test_CT {
Philipp Maier798d8952021-10-19 14:43:19 +02008774
8775 f_TC_set_band_by_arfcn(bts_nr, arfcn);
8776
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008777 /* Enter the configuration node for the given BTS/TRX numbers */
8778 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
8779
Philipp Maier798d8952021-10-19 14:43:19 +02008780 f_vty_transceive(BSCVTY, "arfcn " & int2str(arfcn.arfcn));
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008781
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008782 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008783 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
8784
8785 /* Delete all ARFCNs from the Mobile Allocation (if any) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008786 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
8787 f_vty_transceive(BSCVTY, "hopping arfcn del " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008788 }
8789
8790 f_vty_transceive(BSCVTY, "hopping enabled 0");
8791 f_vty_transceive(BSCVTY, "exit"); /* go back */
8792 }
8793
8794 f_vty_transceive(BSCVTY, "end");
8795 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8796}
8797
8798/* Verify presence and correctness of the hopping parameters (HSN, MAIO)
8799 * in the Channel Identification IE of the RSL CHANnel ACTIVation message. */
8800testcase TC_fh_params_chan_activ() runs on test_CT {
8801 var FHParamsTrx fhp := f_TC_fh_params_gen();
8802 var RSL_Message rsl_msg;
8803 var RSL_IE_Body ie;
8804
8805 f_init_vty();
8806
8807 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
8808 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8809
8810 f_init(1);
8811
8812 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
8813 for (var integer i := 0; i < 9; i := i + 1) {
8814 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
8815 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8816
8817 /* Make sure that Channel Identification IE is present */
8818 if (not f_rsl_find_ie(rsl_msg, RSL_IE_CHAN_IDENT, ie)) {
8819 setverdict(fail, "RSL Channel Identification IE is absent");
8820 continue;
8821 }
8822
8823 /* Make sure that hopping parameters (HSN/MAIO) match */
8824 f_TC_fh_params_match_chan_desc(fhp, ie.chan_ident.ch_desc.v);
8825
8826 /* "Mobile Allocation shall be included but empty" - let's check this */
8827 if (ie.chan_ident.ma.v.len != 0) {
8828 setverdict(fail, "Mobile Allocation IE is not empty: ",
8829 ie.chan_ident.ma, ", despite it shall be");
8830 continue;
8831 }
8832 }
8833
8834 /* Disable frequency hopping */
8835 f_TC_fh_params_unset(fhp);
8836
Vadim Yanitskiy21726312020-09-04 01:45:36 +07008837 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008838}
8839
8840/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Immediate Assignment */
8841testcase TC_fh_params_imm_ass() runs on test_CT {
8842 var FHParamsTrx fhp := f_TC_fh_params_gen();
8843 var RSL_Message rsl_msg;
8844 var RSL_IE_Body ie;
8845
8846 f_init_vty();
8847
8848 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
8849 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8850
8851 f_init(1);
8852
8853 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
8854 for (var integer i := 0; i < 9; i := i + 1) {
8855 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
8856 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8857
8858 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
8859 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
8860
8861 /* Make sure that Full Immediate Assign Info IE is present */
8862 if (not f_rsl_find_ie(rsl_msg, RSL_IE_FULL_IMM_ASS_INFO, ie)) {
8863 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
8864 continue;
8865 }
8866
8867 /* Decode the actual Immediate Assignment message */
8868 var GsmRrMessage rr_msg := dec_GsmRrMessage(ie.full_imm_ass_info.payload);
8869 if (not match(rr_msg.header, t_RrHeader(IMMEDIATE_ASSIGNMENT, ?))) {
8870 setverdict(fail, "Failed to match Immediate Assignment: ", rr_msg);
8871 continue;
8872 }
8873
8874 /* Make sure that hopping parameters (HSN/MAIO) match */
8875 f_TC_fh_params_match_chan_desc(fhp, rr_msg.payload.imm_ass.chan_desc);
8876
8877 /* Make sure that the Mobile Allocation IE matches */
8878 f_TC_fh_params_match_ma(fhp, rr_msg.payload.imm_ass.chan_desc.chan_nr.tn,
8879 rr_msg.payload.imm_ass.mobile_allocation);
8880 }
8881
8882 /* Disable frequency hopping */
8883 f_TC_fh_params_unset(fhp);
Philipp Maier82812002020-08-13 18:48:27 +02008884
Vadim Yanitskiy21726312020-09-04 01:45:36 +07008885 f_shutdown_helper();
Philipp Maier82812002020-08-13 18:48:27 +02008886}
8887
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07008888/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Assignment Command */
8889testcase TC_fh_params_assignment_cmd() runs on test_CT {
8890 var FHParamsTrx fhp := f_TC_fh_params_gen();
8891 var RSL_Message rsl_msg;
8892 var RSL_IE_Body ie;
8893
8894 f_init_vty();
8895
8896 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
8897 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8898
8899 f_init(1);
8900
8901 /* HACK: work around "Couldn't find Expect for CRCX" */
8902 vc_MGCP.stop;
8903
8904 var template PDU_BSSAP ass_cmd := f_gen_ass_req();
8905 ass_cmd.pdu.bssmap.assignmentRequest.codecList := ts_BSSMAP_IE_CodecList({ts_CodecFR});
8906
8907 /* CS domain (TCH): 4 (TCH/F) + 2 (TCH/H) channels available
8908 * NOTE: only 3 SDCCH/4 channels are available on CCCH+SDCCH4+CBCH */
8909 for (var integer i := 0; i < 3; i := i + 1) {
8910 /* Establish a dedicated channel, so we can trigger (late) TCH assignment */
8911 var DchanTuple dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
8912
8913 /* Send a BSSMAP Assignment Command, expect CHANnel ACTIVation */
8914 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
8915 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8916
8917 /* ACKnowledge CHANnel ACTIVation, expect RSL DATA REQuest */
8918 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
8919 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
8920
8921 /* Make sure that L3 Information IE is present */
8922 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
8923 setverdict(fail, "RSL L3 Information IE is absent");
8924 continue;
8925 }
8926
8927 /* Decode the L3 message and make sure it is (RR) Assignment Command */
8928 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
8929 if (not match(l3_msg.header, t_RrL3Header(ASSIGNMENT_COMMAND))) {
8930 setverdict(fail, "Failed to match Assignment Command: ", l3_msg);
8931 continue;
8932 }
8933
8934 /* Make sure that hopping parameters (HSN/MAIO) match */
8935 var ChannelDescription chan_desc := l3_msg.payload.ass_cmd.chan_desc;
8936 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
8937
8938 /* Make sure that Cell Channel Description IE is present if FH is enabled */
8939 if (chan_desc.h and not ispresent(l3_msg.payload.ass_cmd.cell_chan_desc)) {
Vadim Yanitskiy38d069d2020-09-02 17:18:57 +07008940 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07008941 continue;
8942 }
8943
8944 /* Make sure that the Mobile Allocation IE matches (if present) */
8945 var boolean ma_present := ispresent(l3_msg.payload.ass_cmd.mobile_allocation);
8946 if (chan_desc.h and ma_present) {
8947 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
8948 l3_msg.payload.ass_cmd.mobile_allocation.v);
8949 } else if (chan_desc.h and not ma_present) {
8950 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
8951 continue;
8952 } else if (not chan_desc.h and ma_present) {
8953 setverdict(fail, "FH disabled, but Mobile Allocation IE is present");
8954 continue;
8955 }
8956 }
8957
8958 /* Give the IUT some time to release all channels */
8959 f_sleep(3.0);
8960
8961 /* Disable frequency hopping */
8962 f_TC_fh_params_unset(fhp);
8963
Vadim Yanitskiy21726312020-09-04 01:45:36 +07008964 f_shutdown_helper();
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07008965}
8966
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07008967/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Handover Command */
8968private function f_TC_fh_params_handover_cmd(in FHParamsTrx fhp)
8969runs on test_CT {
8970 var RSL_Message rsl_msg;
8971 var RSL_IE_Body ie;
8972 var DchanTuple dt;
8973
8974 /* Establish a dedicated channel, so we can trigger handover */
8975 dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
Vadim Yanitskiyc18ff472021-11-18 20:15:37 +03008976 f_sleep(0.5);
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07008977
8978 /* Trigger handover from BTS0 to BTS1 */
8979 f_bts_0_cfg(BSCVTY, { "neighbor bts 1" });
8980 f_vty_handover(BSCVTY, 0, 0, dt.rsl_chan_nr, 1);
8981
8982 /* Expect RSL CHANnel ACTIVation on BTS1/TRX0/TS1 */
8983 rsl_msg := f_exp_ipa_rx(1, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8984
8985 /* ACKnowledge channel activation and expect (RR) Handover Command */
8986 f_ipa_tx(1, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
8987 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
8988
8989 /* Make sure that L3 Information IE is present */
8990 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
8991 setverdict(fail, "RSL L3 Information IE is absent");
8992 return;
8993 }
8994
8995 /* Decode the L3 message and make sure it is (RR) Handover Command */
8996 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
8997 if (not match(l3_msg.header, t_RrL3Header(HANDOVER_COMMAND))) {
8998 setverdict(fail, "Failed to match Handover Command: ", l3_msg);
8999 return;
9000 }
9001
9002 /* Make sure that we've got SDCCH/8 on TS1 (expected to be hopping) */
9003 var ChannelDescription chan_desc := l3_msg.payload.ho_cmd.chan_desc;
9004 if (not match(chan_desc.chan_nr, t_RslChanNr_SDCCH8(1, ?))) {
9005 setverdict(fail, "Unexpected channel number: ", chan_desc.chan_nr);
9006 return;
9007 }
9008
9009 /* Make sure that hopping parameters (HSN/MAIO) match */
9010 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9011
9012 /* Make sure that Cell Channel Description IE is present */
9013 if (not ispresent(l3_msg.payload.ho_cmd.cell_chan_desc)) {
9014 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
9015 return;
9016 }
9017
9018 /* Make sure that the Mobile Allocation (after time) IE is present and matches */
9019 var boolean ma_present := ispresent(l3_msg.payload.ho_cmd.mobile_allocation);
9020 if (ma_present) {
9021 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9022 l3_msg.payload.ho_cmd.mobile_allocation.v);
9023 } else {
9024 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9025 return;
9026 }
9027}
9028testcase TC_fh_params_handover_cmd() runs on test_CT {
9029 var FHParamsTrx fhp := f_TC_fh_params_gen();
9030
9031 f_init_vty();
9032
9033 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8 on BTS1/TRX0 */
9034 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
9035
9036 f_vty_transceive(BSCVTY, "timeslot 0");
9037 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
9038 f_vty_transceive(BSCVTY, "exit"); /* go back */
9039
9040 f_vty_transceive(BSCVTY, "timeslot 1");
9041 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8");
9042 f_vty_transceive(BSCVTY, "end"); /* we're done */
9043
9044 f_TC_fh_params_set(fhp, 1); /* Enable frequency hopping on BTS1 */
9045 f_vty_transceive(BSCVTY, "drop bts connection 1 oml");
9046
9047 f_init(2);
9048
9049 f_TC_fh_params_handover_cmd(fhp);
9050
9051 /* Disable frequency hopping on BTS1 */
9052 f_TC_fh_params_unset(fhp, 1);
9053
9054 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
9055 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
9056
9057 f_vty_transceive(BSCVTY, "timeslot 0");
9058 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
9059 f_vty_transceive(BSCVTY, "exit"); /* go back */
9060
9061 f_vty_transceive(BSCVTY, "timeslot 1");
9062 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
9063 f_vty_transceive(BSCVTY, "end"); /* we're done */
9064
9065 f_shutdown_helper();
9066}
9067
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009068/* Verify the hopping parameters in System Information Type 4 */
9069testcase TC_fh_params_si4_cbch() runs on test_CT {
9070 var FHParamsTrx fhp := f_TC_fh_params_gen(tr_tn := 1);
9071 var ASP_RSL_Unitdata rx_rsl_ud;
9072 timer T := 5.0;
9073
9074 f_init_vty();
9075
9076 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8+CBCH */
9077 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
9078
9079 f_vty_transceive(BSCVTY, "timeslot 0");
9080 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
9081 f_vty_transceive(BSCVTY, "exit"); /* go back */
9082
9083 f_vty_transceive(BSCVTY, "timeslot 1");
9084 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8+cbch");
9085 f_vty_transceive(BSCVTY, "end"); /* we're done */
9086
9087 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
9088 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
9089
9090 f_init(1);
9091
9092 T.start;
9093 alt {
9094 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO(RSL_SYSTEM_INFO_4))) -> value rx_rsl_ud {
9095 var RSL_IE_Body ie := rx_rsl_ud.rsl.ies[2].body; /* FULL BCCH Information IE */
9096 var SystemInformation si := dec_SystemInformation(ie.other.payload);
9097
9098 /* Make sure that what we decoded is System Information Type 4 */
9099 if (si.header.message_type != SYSTEM_INFORMATION_TYPE_4) {
9100 setverdict(fail, "RSL FULL BCCH Information IE contains: ", si);
9101 repeat;
9102 }
9103
9104 /* Make sure that CBCH Channel Description IE is present */
9105 if (not ispresent(si.payload.si4.cbch_chan_desc)) {
9106 setverdict(fail, "CBCH Channel Description IE is absent");
9107 break;
9108 }
9109
9110 /* Finally, check the hopping parameters (HSN, MAIO) */
9111 var ChannelDescription chan_desc := si.payload.si4.cbch_chan_desc.v;
9112 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
9113
9114 /* 3GPP TS 44.018, section 9.1.36.2 "CBCH Mobile Allocation":
9115 * The CBCH Mobile Allocation IE *shall* be present if FH is enabled. */
9116 if (chan_desc.h and not ispresent(si.payload.si4.cbch_mobile_alloc)) {
9117 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
9118 break;
9119 } else if (chan_desc.h and ispresent(si.payload.si4.cbch_mobile_alloc)) {
9120 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
9121 si.payload.si4.cbch_mobile_alloc.v);
9122 }
9123 }
9124 [] IPA_RSL[0].receive { repeat; }
9125 [] T.timeout {
9126 setverdict(fail, "Timeout waiting for RSL BCCH INFOrmation (SI4)");
9127 }
9128 }
9129
9130 /* Disable frequency hopping */
9131 f_TC_fh_params_unset(fhp);
9132
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07009133 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009134 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
9135
9136 f_vty_transceive(BSCVTY, "timeslot 0");
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07009137 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009138 f_vty_transceive(BSCVTY, "exit"); /* go back */
9139
9140 f_vty_transceive(BSCVTY, "timeslot 1");
9141 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
9142 f_vty_transceive(BSCVTY, "end"); /* we're done */
9143
Vadim Yanitskiy21726312020-09-04 01:45:36 +07009144 f_shutdown_helper();
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009145}
9146
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009147template (value) PDU_BSSAP_LE ts_BSSMAP_LE_BSSLAP(template (value) BSSLAP_PDU bsslap)
9148 := ts_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, data := enc_BSSLAP_PDU(valueof(bsslap)));
9149
9150private function f_match_bsslap(PDU_BSSAP_LE got_bsslap_msg,
9151 template (present) BSSLAP_PDU expect_bsslap)
9152{
9153 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(got_bsslap_msg.pdu.bssmap.co_info.bsslap_apdu.data);
9154 if (not match(bsslap, expect_bsslap)) {
9155 log("EXPECTING BSSLAP: ", expect_bsslap);
9156 log("GOT BSSLAP: ", bsslap);
9157 setverdict(fail, "BSSLAP is not as expected");
9158 mtc.stop;
9159 }
9160 setverdict(pass);
9161}
9162
9163/* GAD: this is an Ellipsoid point with uncertainty circle, encoded as in 3GPP TS 23.032 §7.3.2. */
9164const octetstring gad_ell_point_unc_circle := '10b0646d0d5f6627'O;
9165
9166private function f_expect_bsslap(template (present) BSSLAP_PDU expect_rx_bsslap) runs on MSC_ConnHdlr {
9167 var PDU_BSSAP_LE rx_bsslap;
9168 BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap);
9169 f_match_bsslap(rx_bsslap, expect_rx_bsslap);
9170}
9171
9172/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9173 * Request on Lb interface. Either with or without the SMLC doing a BSSLAP TA Request. */
9174private function f_lcs_loc_req_for_active_ms(boolean do_ta_request := false) runs on MSC_ConnHdlr {
9175 f_sleep(1.0);
9176
9177 f_establish_fully(omit, omit);
9178 f_bssap_le_register_imsi(g_pars.imsi, omit);
9179
9180 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9181 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9182
9183 var PDU_BSSAP_LE plr;
9184 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9185
9186 if (not do_ta_request) {
9187 /* verify TA Layer 3 in APDU. First the APDU type (BSSLAP), then the BSSLAP data contents. */
9188 var template BSSMAP_LE_IE_APDU expect_apdu := tr_BSSMAP_LE_APDU(BSSMAP_LE_PROT_BSSLAP, ?);
9189 if (not match(plr.pdu.bssmap.perf_loc_req.bsslap_apdu, expect_apdu)) {
9190 log("EXPECTING BSSMAP-LE APDU IE ", expect_apdu);
9191 log("GOT BSSMAP-LE APDU IE ", plr.pdu.bssmap.perf_loc_req.bsslap_apdu);
9192 setverdict(fail, "BSSMAP-LE APDU IE is not as expected");
9193 mtc.stop;
9194 }
9195 var template BSSLAP_PDU expect_ta_layer3 := tr_BSSLAP_TA_Layer3(tr_BSSLAP_IE_TA(0));
9196 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(plr.pdu.bssmap.perf_loc_req.bsslap_apdu.data);
9197 if (not match(bsslap, expect_ta_layer3)) {
9198 log("EXPECTING BSSLAP TA Layer 3: ", expect_ta_layer3);
9199 log("GOT BSSLAP: ", bsslap);
9200 setverdict(fail, "BSSLAP is not as expected");
9201 mtc.stop;
9202 }
9203 /* OsmoBSC directly sent the TA as BSSLAP APDU in the BSSMAP-LE Perform Location Request to the SMLC. The SMLC
9204 * has no need to request the TA from the BSC and directly responds. */
9205 } else {
9206 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9207 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9208 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9209 }
9210
9211 /* SMLC got the TA from the BSC, now responds with geo information data. */
9212 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9213 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9214 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9215
9216 /* The LCS was using an active A-interface conn. It should still remain active after this. */
9217 f_mo_l3_transceive();
9218
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009219 f_perform_clear();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009220
9221 f_sleep(2.0);
9222 setverdict(pass);
9223}
9224
9225/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9226 * Request on Lb interface. Without the SMLC doing a BSSLAP TA Request. */
9227private function f_tc_lcs_loc_req_for_active_ms(charstring id) runs on MSC_ConnHdlr {
9228 f_lcs_loc_req_for_active_ms(false);
9229}
9230testcase TC_lcs_loc_req_for_active_ms() runs on test_CT {
9231 var MSC_ConnHdlr vc_conn;
9232 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9233
9234 f_init(1, true);
9235 f_sleep(1.0);
9236 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms), pars);
9237 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009238 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009239}
9240
9241/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9242 * Request on Lb interface. With the SMLC doing a BSSLAP TA Request. */
9243private function f_tc_lcs_loc_req_for_active_ms_ta_req(charstring id) runs on MSC_ConnHdlr {
9244 f_lcs_loc_req_for_active_ms(true);
9245}
9246testcase TC_lcs_loc_req_for_active_ms_ta_req() runs on test_CT {
9247 var MSC_ConnHdlr vc_conn;
9248 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9249
9250 f_init(1, true);
9251 f_sleep(1.0);
9252 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_ta_req), pars);
9253 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009254 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009255}
9256
9257/* Clear the A-interface conn only, without doing anything on Abis. Useful for LCS, for cases where there is only an A
9258 * conn without an active lchan. */
9259private function f_clear_A_conn() runs on MSC_ConnHdlr
9260{
9261 var BssmapCause cause := 0;
9262 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
9263 BSSAP.receive(tr_BSSMAP_ClearComplete);
9264 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
9265
9266 timer no_more_bssap := 5.0;
9267 no_more_bssap.start;
9268 alt {
9269 [] no_more_bssap.timeout { break; }
9270 [] BSSAP.receive(tr_BSSAP_BSSMAP) {
9271 setverdict(fail, "Expected no more BSSAP after Clear Complete");
9272 mtc.stop;
9273 }
9274 }
9275 setverdict(pass);
9276}
9277
9278/* Verify that the A-interface connection is still working, and then clear it, without doing anything on Abis. Useful
9279 * for LCS, for cases where there is only an A conn without an active lchan. */
9280private function f_verify_active_A_conn_and_clear() runs on MSC_ConnHdlr
9281{
9282 f_logp(BSCVTY, "f_verify_active_A_conn_and_clear: test A link, then clear");
9283
9284 /* When an lchan is active, we can send some L3 data from the BTS side and verify that it shows up on the other
9285 * side towards the MSC. When there is no lchan, this is not possible. To probe whether the A-interface
9286 * connection is still up, we need something that echos back on the A-interface. Another LCS request! */
9287 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9288 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9289 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?));
9290
9291 /* Right, the Perform Location Request showed up on Lb, now we can clear the A conn. */
9292 f_clear_A_conn();
9293 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
9294 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9295}
9296
9297/* With *no* active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
9298 * Request on Lb interface. BSC will Page for the subscriber as soon as we (virtual SMLC) request the TA via BSSLAP.
9299 */
9300private function f_tc_lcs_loc_req_for_idle_ms(charstring id) runs on MSC_ConnHdlr {
9301 f_sleep(1.0);
9302
9303 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9304 f_bssap_le_register_imsi(g_pars.imsi, omit);
9305
9306 /* Register to receive the Paging Command */
9307 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9308 g_chan_nr := new_chan_nr;
9309 f_rslem_register(0, g_chan_nr);
9310
9311 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9312 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9313 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9314 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9315
9316 var PDU_BSSAP_LE plr;
9317 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9318
9319 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9320 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9321
9322 /* OsmoBSC needs to Page */
9323 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi)));
9324 f_logp(BSCVTY, "got Paging Command");
9325
9326 /* MS requests channel. Since the Paging was for LCS, the Paging Response does not trigger a Complete Layer 3 to
9327 * the MSC, and releases the lchan directly. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009328 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);
9329 f_expect_lchan_rel(RSL, RSL_PROC);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009330
9331 /* From the Paging Response, the TA is now known to the BSC, and it responds to the SMLC. */
9332
9333 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9334
9335 /* SMLC got the TA from the BSC, now responds with geo information data. */
9336 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9337 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9338
9339 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9340
9341 /* The lchan is gone, the A-interface conn was created for the LCS only.
9342 * Still it is clearly the MSC's job to decide whether to tear down the conn or not. */
9343 f_verify_active_A_conn_and_clear();
9344
9345 f_sleep(2.0);
9346 setverdict(pass);
9347}
9348testcase TC_lcs_loc_req_for_idle_ms() runs on test_CT {
9349 var MSC_ConnHdlr vc_conn;
9350 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9351
9352 f_init(1, true);
9353 f_sleep(1.0);
9354
9355 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9356 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9357
9358 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms), pars);
9359 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009360 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009361}
9362
9363/* With no active lchan, start BSSMAP Perform Location Request on A interface, but omit IMSI; expect failure response.
9364 */
9365private function f_tc_lcs_loc_req_no_subscriber(charstring id) runs on MSC_ConnHdlr {
9366 f_sleep(1.0);
9367
9368 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9369 f_bssap_le_register_imsi(g_pars.imsi, omit);
9370
9371 /* provoke an abort by omitting both IMSI and IMEI */
9372 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9373 valueof(ts_BSSMAP_Perform_Location_Request(omit,
9374 ts_CellId_CGI('262'H, '42'H, 23, 42)))));
9375 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9376
9377 /* BSC tells MSC about failure */
9378 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9379 locationEstimate := omit, positioningData := omit,
9380 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_DATA_MISSING_IN_REQ)));
9381
9382 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9383 f_verify_active_A_conn_and_clear();
9384
9385 f_sleep(2.0);
9386 setverdict(pass);
9387}
9388testcase TC_lcs_loc_req_no_subscriber() runs on test_CT {
9389 var MSC_ConnHdlr vc_conn;
9390 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9391
9392 f_init(1, true);
9393 f_sleep(1.0);
9394
9395 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9396 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9397
9398 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_no_subscriber), pars);
9399 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009400 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009401}
9402
9403/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9404 * BSSMAP-LE Perform Location Response (before or after sending a BSSLAP TA Request) */
9405private function f_lcs_loc_req_for_active_ms_le_timeout(boolean do_ta) runs on MSC_ConnHdlr {
9406 f_sleep(1.0);
9407
9408 f_establish_fully(omit, omit);
9409 f_bssap_le_register_imsi(g_pars.imsi, omit);
9410
9411 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9412 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9413
9414 var PDU_BSSAP_LE plr;
9415 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9416
9417 if (do_ta) {
9418 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9419 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9420 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9421 }
9422
9423 /* SMLC fails to respond, BSC runs into timeout */
9424 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_SYSTEM_FAILURE));
9425 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9426
9427 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9428 locationEstimate := omit, positioningData := omit,
9429 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_SYSTEM_FAILURE)));
9430
9431 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9432 f_verify_active_A_conn_and_clear();
9433
9434 f_sleep(2.0);
9435 setverdict(pass);
9436}
9437
9438/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9439 * BSSMAP-LE Perform Location Response, without sending a BSSLAP TA Request. */
9440private function f_tc_lcs_loc_req_for_active_ms_le_timeout(charstring id) runs on MSC_ConnHdlr {
9441 f_lcs_loc_req_for_active_ms_le_timeout(false);
9442}
9443
9444testcase TC_lcs_loc_req_for_active_ms_le_timeout() runs on test_CT {
9445 var MSC_ConnHdlr vc_conn;
9446 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9447
9448 f_init(1, true);
9449 f_sleep(1.0);
9450 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout), pars);
9451 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009452 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009453}
9454
9455/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
9456 * BSSMAP-LE Perform Location Response, after sending a BSSLAP TA Request. */
9457private function f_tc_lcs_loc_req_for_active_ms_le_timeout2(charstring id) runs on MSC_ConnHdlr {
9458 f_lcs_loc_req_for_active_ms_le_timeout(true);
9459}
9460
9461testcase TC_lcs_loc_req_for_active_ms_le_timeout2() runs on test_CT {
9462 var MSC_ConnHdlr vc_conn;
9463 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9464
9465 f_init(1, true);
9466 f_sleep(1.0);
9467 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout2), pars);
9468 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009469 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009470}
9471
9472/* With *no* active lchan, start a Perform Location Request, expecting that the MS will be Paged. */
9473private function f_tc_lcs_loc_req_for_idle_ms_no_pag_resp(charstring id) runs on MSC_ConnHdlr {
9474 f_sleep(1.0);
9475
9476 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9477 f_bssap_le_register_imsi(g_pars.imsi, omit);
9478
9479 /* Register to receive the Paging Command */
9480 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9481 g_chan_nr := new_chan_nr;
9482 f_rslem_register(0, g_chan_nr);
9483
9484 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9485 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9486 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9487 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9488
9489 var PDU_BSSAP_LE plr;
9490 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9491
9492 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9493 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9494
9495 /* OsmoBSC needs to Page */
9496 var PDU_BSSAP_LE rx_bsslap;
9497 alt {
9498 [] RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi))) {
9499 f_logp(BSCVTY, "got Paging Command");
9500 repeat;
9501 }
9502 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
9503 /* MS does not respond to Paging, TA Req runs into timeout. */
9504 f_match_bsslap(rx_bsslap, tr_BSSLAP_Abort(?));
9505 }
9506 }
9507
9508 /* SMLC responds with failure */
9509 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(omit, BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
9510 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9511
9512 /* BSC tells MSC about failure */
9513 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
9514 locationEstimate := omit, positioningData := omit,
9515 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_REQUEST_ABORTED)));
9516
9517 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
9518 f_verify_active_A_conn_and_clear();
9519
9520 f_sleep(2.0);
9521 setverdict(pass);
9522}
9523testcase TC_lcs_loc_req_for_idle_ms_no_pag_resp() runs on test_CT {
9524 var MSC_ConnHdlr vc_conn;
9525 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9526
9527 f_init(1, true);
9528 f_sleep(1.0);
9529
9530 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9531 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9532
9533 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms_no_pag_resp), pars);
9534 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009535 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009536}
9537
9538/* During an ongoing Location Request, the MS sends a CM Service Request. Expect the same A-conn to be re-used / taken
9539 * over. */
9540private function f_tc_cm_service_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
9541 f_sleep(1.0);
9542
9543 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9544 f_bssap_le_register_imsi(g_pars.imsi, omit);
9545
9546 /* Register to receive the Paging Command */
9547 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
9548 g_chan_nr := new_chan_nr;
9549 f_rslem_register(0, g_chan_nr);
9550
9551 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
9552 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9553 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
9554 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
9555
9556 var PDU_BSSAP_LE plr;
9557 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9558
9559 /* As the A-interface conn was established for LCS, the MS coincidentally decides to issue a CM Service Request
9560 * and establish Layer 3. It should use the existing A-interface conn. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009561 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 +02009562 do_clear := false, expect_bssmap_l3 := true);
9563
9564 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
9565 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
9566
9567 /* OsmoBSC already has an lchan, no need to Page, just returns the TA */
9568 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
9569
9570 /* SMLC got the TA from the BSC, now responds with geo information data. */
9571 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9572 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9573 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9574
9575 /* The lchan should still exist, it was from a CM Service Request. */
9576 f_mo_l3_transceive();
9577
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009578 f_perform_clear();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009579
9580 f_sleep(2.0);
9581 setverdict(pass);
9582}
9583testcase TC_cm_service_during_lcs_loc_req() runs on test_CT {
9584 var MSC_ConnHdlr vc_conn;
9585 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9586
9587 f_init(1, true);
9588 f_sleep(1.0);
9589
9590 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
9591 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
9592
9593 vc_conn := f_start_handler(refers(f_tc_cm_service_during_lcs_loc_req), pars);
9594 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009595 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009596}
9597
9598/* During an ongoing Perform Location Request, do a Handover, an expect a BSSLAP Reset message from the BSC to indicate
9599 * the new lchan after handover. */
9600private function f_tc_ho_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
9601 f_sleep(1.0);
9602
9603 f_establish_fully(omit, omit);
9604 f_bssap_le_register_imsi(g_pars.imsi, omit);
9605
9606 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9607 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9608
9609 var PDU_BSSAP_LE plr;
9610 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9611
9612 /* SMLC ponders the Location Request, in the meantime the BSC decides to handover */
9613 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
9614
9615 var HandoverState hs := {
9616 rr_ho_cmpl_seen := false,
9617 handover_done := false,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02009618 old_chan_nr := -,
9619 expect_target_tsc := BTS_TSC[1]
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009620 };
9621 /* issue hand-over command on VTY */
9622 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
9623 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
9624 f_rslem_suspend(RSL1_PROC);
9625
9626 /* From the MGW perspective, a handover is is characterized by
9627 * performing one MDCX operation with the MGW. So we expect to see
9628 * one more MDCX during handover. */
9629 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
9630
9631 alt {
9632 [] as_handover(hs);
9633 }
9634
9635 var PDU_BSSAP_LE rx_bsslap;
9636
9637 interleave {
9638 /* Expect the BSC to inform the MSC about the handover */
9639 [] BSSAP.receive(tr_BSSMAP_HandoverPerformed);
9640
9641 /* Expect the BSC to inform the SMLC about the handover */
9642 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
9643 f_match_bsslap(rx_bsslap, tr_BSSLAP_Reset(BSSLAP_CAUSE_INTRA_BSS_HO));
9644 }
9645 }
9646
9647 /* SMLC now responds with geo information data. */
9648 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9649 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9650 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9651
9652 /* lchan still active */
9653 f_mo_l3_transceive(RSL1);
9654
9655 /* MSC decides it is done now. */
Neels Hofmeyr85bcd272021-07-22 19:14:48 +02009656 f_perform_clear(RSL1, RSL1_PROC);
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009657
9658 f_sleep(2.0);
9659 setverdict(pass);
9660}
9661testcase TC_ho_during_lcs_loc_req() runs on test_CT {
9662 var MSC_ConnHdlr vc_conn;
9663 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9664
9665 f_init(2, true);
9666 f_sleep(1.0);
9667 vc_conn := f_start_handler(refers(f_tc_ho_during_lcs_loc_req), pars);
9668 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009669 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009670}
9671
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009672/* Attempt Complete Layer 3 without any MSC available (OS#4832) */
9673private function f_tc_no_msc(charstring id) runs on MSC_ConnHdlr {
9674 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9675
9676 /* Also disable attach for the single connected MSC */
9677 f_vty_msc_allow_attach(BSCVTY, { false });
9678
9679 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) ));
9680 f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
9681
9682 /* No MSC is found, expecting a proper release on RSL */
9683 interleave {
9684 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
9685 f_logp(BSCVTY, "Got RSL RR Release");
9686 }
9687 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
9688 f_logp(BSCVTY, "Got RSL Deact SACCH");
9689 }
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02009690 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009691 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
9692 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02009693 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009694 }
9695 }
9696 setverdict(pass);
9697}
9698testcase TC_no_msc() runs on test_CT {
9699
9700 f_init(1, true);
9701 f_sleep(1.0);
9702 var MSC_ConnHdlr vc_conn;
9703 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9704
9705 f_ctrs_bsc_init(counternames_bsc_mscpool);
9706
9707 vc_conn := f_start_handler(refers(f_tc_no_msc), pars);
9708 vc_conn.done;
9709
9710 f_ctrs_bsc_add("mscpool:subscr:no_msc");
9711 f_ctrs_bsc_verify();
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009712 f_shutdown_helper();
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009713}
9714
Harald Welte0ea2d5e2018-04-07 21:40:29 +02009715/* Dyn PDCH todo:
9716 * activate OSMO as TCH/F
9717 * activate OSMO as TCH/H
9718 * does the BSC-located PCU socket get the updated INFO?
9719 * what if no PCU is connected at the time?
9720 * is the info correct on delayed PCU (re)connect?
9721 */
Harald Welte94e0c342018-04-07 11:33:23 +02009722
Neels Hofmeyr87857ec2021-04-25 16:17:47 +00009723private function f_TC_refuse_mode_modif_to_vamos(charstring id) runs on MSC_ConnHdlr {
9724 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
9725 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
9726
9727 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
9728 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
9729 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
9730 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
9731 g_pars.ass_codec_list.codecElements[0];
9732 if (isvalue(g_pars.expect_mr_s0_s7)) {
9733 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
9734 g_pars.expect_mr_s0_s7;
9735 }
9736 }
9737 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
9738 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
9739 log("expecting ASS COMPL like this: ", exp_compl);
9740
9741 f_establish_fully(ass_cmd, exp_compl);
9742
Neels Hofmeyr8746b0d2021-06-01 17:25:39 +02009743 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 +00009744
9745 var RSL_Message rsl;
9746
9747 timer T := 5.0;
9748 T.start;
9749 alt {
9750 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
9751 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
9752 log("Rx L3 from net: ", l3);
9753 if (ischosen(l3.msgs.rrm.channelModeModify)) {
9754 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
9755 mtc.stop;
9756 }
9757 }
9758 [] RSL.receive(tr_RSL_MODE_MODIFY_REQ(g_chan_nr, ?)) -> value rsl {
9759 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
9760 mtc.stop;
9761 }
9762 [] T.timeout {
9763 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related Mode Modify should happen. */
9764 setverdict(pass);
9765 }
9766 }
9767 T.stop;
9768}
9769
9770/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel Mode Modify to VAMOS mode is refused by
9771 * osmo-bsc. */
9772testcase TC_refuse_mode_modif_to_vamos() runs on test_CT {
9773 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9774 var MSC_ConnHdlr vc_conn;
9775
9776 f_init(1, true);
9777 f_sleep(1.0);
9778
9779 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
9780 vc_conn := f_start_handler(refers(f_TC_refuse_mode_modif_to_vamos), pars);
9781 vc_conn.done;
9782 f_shutdown_helper();
9783}
9784
9785/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel activation to VAMOS mode is refused by osmo-bsc.
9786 */
9787testcase TC_refuse_chan_act_to_vamos() runs on test_CT {
9788 f_init_vty();
9789
9790 f_init(1, false);
9791 f_sleep(1.0);
9792
9793 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 activate-vamos fr");
9794
9795 var ASP_RSL_Unitdata rx_rsl_ud;
9796 timer T := 5.0;
9797
9798 T.start;
9799 alt {
9800 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(?, IPAC_PROTO_RSL_TRX0)) -> value rx_rsl_ud {
9801 if (rx_rsl_ud.rsl.msg_type == RSL_MT_CHAN_ACTIV) {
9802 T.stop;
9803 setverdict(fail, "CHANnel ACTivate in VAMOS mode succeeded even though BTS does not support VAMOS");
9804 mtc.stop;
9805 }
9806 repeat;
9807 }
9808 [] T.timeout {
9809 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related CHANnel ACTivate should happen. */
9810 setverdict(pass);
9811 }
9812 }
9813}
9814
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009815private function f_TC_reassignment_codec(charstring id) runs on MSC_ConnHdlr {
9816 /* First fully set up a speech lchan */
9817 f_TC_assignment_codec(id);
9818
9819 /* Trigger re-assignment to another lchan */
9820 var AssignmentState assignment_st := valueof(ts_AssignmentStateInit);
9821
9822 /* Re-Assignment should tell the MGW endpoint the new lchan's RTP address and port, so expecting to see exactly
9823 * one MDCX on MGCP. */
9824 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].mdcx_seen_exp + 1;
9825
9826 /* The new lchan will see all-new IPAC_CRCX and IPAC_MDCX messages telling the BTS the same RTP address and port
9827 * as the old lchan used. */
9828 g_media.bts.ipa_crcx_seen := false;
9829 g_media.bts.ipa_mdcx_seen := false;
9830
9831 /* Send different BTS side RTP port number for the new lchan */
9832 g_media.bts.bts.port_nr := 4223;
9833
9834 f_rslem_register(0, valueof(ts_RslChanNr_Bm(2))); /* <-- FIXME: can we somehow infer the timeslot that will be used? */
9835
9836 /* Trigger re-assignment. */
9837 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot " & int2str(g_chan_nr.tn) & " sub-slot 0 assignment");
9838
9839 timer T := 5.0;
9840 T.start;
9841 alt {
9842 [] as_assignment(assignment_st);
9843 [] as_Media();
9844 [] T.timeout {
9845 break;
9846 }
9847 }
9848
9849 if (not assignment_st.assignment_done) {
9850 setverdict(fail, "Assignment did not complete");
9851 mtc.stop;
9852 }
9853
9854 f_check_mgcp_expectations()
9855 setverdict(pass);
9856
9857 f_sleep(2.0);
9858 log("show lchan summary: ", f_vty_transceive_ret(BSCVTY, "show lchan summary"));
9859
9860 /* Instruct BSC to clear channel */
9861 var BssmapCause cause := 0;
9862 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
9863 interleave {
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009864 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {}
9865 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
Neels Hofmeyr3c5127e2021-07-22 19:18:40 +02009866 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009867 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Neels Hofmeyre680b012021-07-22 19:19:09 +02009868 f_rslem_unregister(0, g_chan_nr);
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009869 }
9870 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
9871 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
9872 }
9873 }
Neels Hofmeyr40a45d12021-09-23 22:57:12 +02009874 f_expect_dlcx_conns();
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009875
9876 f_sleep(0.5);
9877}
9878
9879testcase TC_reassignment_fr() runs on test_CT {
9880 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9881 var MSC_ConnHdlr vc_conn;
9882
9883 f_init(1, true);
9884 f_sleep(1.0);
9885
Neels Hofmeyrac432fa2021-11-02 16:45:56 +01009886 f_ctrs_bsc_and_bts_handover_init();
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009887
9888 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
9889 vc_conn := f_start_handler(refers(f_TC_reassignment_codec), pars);
9890 vc_conn.done;
9891
9892 /* from f_establish_fully() */
9893 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
9894 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
9895 /* from re-assignment */
9896 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
9897 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
9898 f_ctrs_bsc_and_bts_verify();
9899 f_shutdown_helper();
9900}
9901
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +02009902const charstring REEST_LOST_CONNECTION := "REEST_LOST_CONNECTION";
9903const charstring REEST_CLEAR := "REEST_CLEAR";
9904const charstring REEST_CLEAR_DONE := "REEST_CLEAR_DONE";
9905
9906/* CM Re-Establishment, 3GPP TS 24.008 4.5.1.6.
9907 * The MS <-> BTS loses radio connection, MS shows up on second BTS and asks for CM Re-Establishment.
9908 * BSC should establish a separate A conn for the same MS, the original A conn is then cleared by
9909 * the MSC as the CM Re-Establishment is handled.
9910 *
9911 * MS bts0 bts1 bsc msc test-component
9912 * |<----->|<----------------->|<-0-->| _1 Establish channel on bts 0
9913 * | | _1 wait a bit, to settle down
9914 * |<-x x--| | _1 "lose connection"
9915 * | | REEST_LOST_CONNECTION
9916 * |----------------->|------->|--1-->| _2 new A-conn: Chan Rqd, Imm Ass, Compl L3 with CM Re-Establishment Req
9917 * | | REEST_CLEAR
9918 * | |<-0---| _1 Clear Command on first A-conn
9919 * | |--0-->| _1 Clear Complete
9920 * | |<----------------->| | _1 Release first channel
9921 * | | REEST_CLEAR_DONE
9922 * |<-----------------|<-------|<-1---| _2 Chan Activ, Assignment Command
9923 * |<-----------------|<-------|<-1---| _2 Clear Command, Release
9924 *
9925 */
9926private function f_tc_cm_reestablishment_1(charstring id) runs on MSC_ConnHdlr {
9927 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
9928 var PDU_BSSAP ass_cmd := f_gen_ass_req();
9929
9930 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
9931 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
9932
9933 f_establish_fully(ass_cmd, exp_compl);
9934
9935 /* The original channel loses connection, MS attemts CM Re-Establishment on another cell, see
9936 * f_tc_cm_reestablishment_2(). This established channel stays active until MSC sends a Clear Command. The time
9937 * when exactly that happens is determined by f_tc_cm_reestablishment_2(). */
9938 f_sleep(2.0);
9939 COORD.send(REEST_LOST_CONNECTION);
9940
9941 alt {
9942 [] COORD.receive(REEST_CLEAR);
9943 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
9944 setverdict(fail, "Unexpected channel release");
9945 mtc.stop;
9946 }
9947 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr)) {
9948 setverdict(fail, "Unexpected channel release");
9949 mtc.stop;
9950 }
9951 }
9952 f_perform_clear()
9953 f_expect_dlcx_conns();
Neels Hofmeyr969abd02021-09-23 22:24:08 +02009954 f_create_mgcp_delete_ep(g_media.mgcp_ep);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +02009955 COORD.send(REEST_CLEAR_DONE);
9956}
9957
9958private function f_tc_cm_reestablishment_2(charstring id) runs on MSC_ConnHdlr {
9959 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, FR_AMR);
9960
9961 /* The MS lost the connection on the first channel, now establishes another one */
9962 COORD.receive(REEST_LOST_CONNECTION);
9963
9964 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
9965 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_REESTABL_REQ(mi));
9966 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
9967
9968 f_create_bssmap_exp(l3_enc);
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +02009969 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 +02009970 BSSAP.receive(tr_BSSMAP_ComplL3(l3_enc));
9971
9972 /* MSC got the CM Re-Establishment request and first off clears the previous conn. */
9973 COORD.send(REEST_CLEAR);
9974 COORD.receive(REEST_CLEAR_DONE);
9975
9976 f_sleep(2.0);
9977
9978 /* Answer the CM Re-Establishment with an Assignment Command. */
9979 var template PDU_BSSAP expect_assignment_compl := f_gen_exp_compl();
9980 var PDU_BSSAP ass_cmd := f_gen_ass_req();
9981 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
9982 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
9983
9984 var AssignmentState st := valueof(ts_AssignmentStateInit);
9985 st.voice_call := true;
9986 st.is_assignment := true;
9987
9988 var ExpectCriteria mgcpcrit := {
9989 connid := omit,
9990 endpoint := omit,
9991 transid := omit
9992 };
9993 f_create_mgcp_expect(mgcpcrit);
9994
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +02009995 f_rslem_dchan_queue_enable(RSL1_PROC);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +02009996
9997 BSSAP.send(ass_cmd);
9998
9999 var PDU_BSSAP bssap;
10000
10001 alt {
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010002 [] as_assignment(st, rsl_pt := RSL1, rsl_proc_pt := RSL1_PROC);
10003 [] as_Media_ipacc(RSL1, RSL2);
10004 [] as_Media_mgw();
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010005 [st.assignment_done] BSSAP.receive(expect_assignment_compl) {
10006 break;
10007 }
10008 }
10009
10010 f_sleep(3.0);
10011
10012 f_logp(BSCVTY, "f_tc_cm_reestablishment_2 clearing");
Neels Hofmeyrc7b1f6d2021-07-20 23:21:36 +020010013 f_perform_clear(RSL1, RSL1_PROC);
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010014 f_expect_dlcx_conns();
10015}
10016
10017testcase TC_cm_reestablishment() runs on test_CT {
10018 var TestHdlrParams pars1 := f_gen_test_hdlr_pars();
10019 var MSC_ConnHdlr vc_conn1;
10020
10021 var TestHdlrParams pars2 := f_gen_test_hdlr_pars();
10022 var MSC_ConnHdlr vc_conn2;
10023 pars2.imsi := pars1.imsi;
10024 pars2.media_nr := 2;
Neels Hofmeyrbf720202021-10-02 12:58:24 +020010025 pars2.expect_tsc := BTS_TSC[1];
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020010026
10027 f_init(2, true, guard_timeout := 40.0);
10028 f_sleep(1.0);
10029
10030 vc_conn1 := f_start_handler_create(pars1);
10031 vc_conn2 := f_start_handler_create(pars2);
10032 connect(vc_conn1:COORD, vc_conn2:COORD);
10033 f_start_handler_run(vc_conn1, refers(f_tc_cm_reestablishment_1), pars1);
10034 f_start_handler_run(vc_conn2, refers(f_tc_cm_reestablishment_2), pars2);
10035 vc_conn1.done;
10036 vc_conn2.done;
10037
10038 f_shutdown_helper();
10039}
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000010040
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010041function f_exp_ipa_rx_nonfatal(integer bts_nr, template (present) RSL_Message t_rx, float t_secs := 2.0,
10042 IpaStreamId sid := IPAC_PROTO_RSL_TRX0, boolean ignore_other_rx := true)
10043runs on test_CT return template (omit) RSL_Message {
10044 var ASP_RSL_Unitdata rx_rsl_ud;
10045 timer T := t_secs;
10046
10047 T.start;
10048 alt {
10049 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
10050 T.stop;
10051 }
10052 [ignore_other_rx] IPA_RSL[bts_nr].receive { repeat; }
10053 [not ignore_other_rx] IPA_RSL[bts_nr].receive {
10054 log("f_exp_ipa_rx_nonfatal(): Got different message than ", t_rx);
10055 T.stop;
10056 return omit;
10057 }
10058 [] T.timeout {
10059 return omit;
10060 }
10061 }
10062 return rx_rsl_ud.rsl;
10063}
10064
10065private function f_vty_set_imm_ass(TELNETasp_PT pt, BtsNr bts_nr := 0, charstring imm_ass_setting := "post-chan-ack") {
10066 f_vty_enter_cfg_bts(pt, bts_nr);
10067 f_vty_transceive(pt, "immediate-assignment " & imm_ass_setting);
10068 f_vty_transceive(pt, "exit");
10069 f_vty_transceive(pt, "exit");
10070 f_vty_transceive(pt, "exit");
10071}
10072
10073private function f_verify_imm_ass(RSL_Message imm_ass, template uint8_t ra := ?, template GsmFrameNumber fn := ?,
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010074 template RslChannelNr chan_nr := ?,
10075 template (present) uint12_t arfcn := ?,
10076 template (present) uint3_t tsc := ?)
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010077{
10078 var RSL_IE_Body full_imm_ass_info;
10079 if (not f_rsl_find_ie(imm_ass, RSL_IE_FULL_IMM_ASS_INFO, full_imm_ass_info)) {
10080 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
10081 mtc.stop;
10082 }
10083
10084 var GsmRrMessage rr_imm_ass := dec_GsmRrMessage(full_imm_ass_info.full_imm_ass_info.payload);
10085 var template GsmRrMessage expect_imm_ass := tr_IMM_ASS(ra := ra,
10086 fn := fn,
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010087 ch_desc := tr_ChanDescH0(chan_nr, arfcn, tsc),
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010088 page_mode := ?);
10089 if (not match(rr_imm_ass, expect_imm_ass)) {
10090 log("Error: expected ", expect_imm_ass, " got ", rr_imm_ass);
10091 setverdict(fail, "Failed to match Immediate Assignment");
10092 mtc.stop;
10093 }
10094}
10095
10096testcase TC_imm_ass_post_chan_ack() runs on test_CT {
10097 var RSL_Message chan_act;
10098 var RSL_Message imm_ass;
10099
10100 f_init(1, false);
10101 f_sleep(1.0);
10102
10103 /* (should be the default anyway, just to make things clear) */
10104 f_vty_set_imm_ass(BSCVTY, 0, "post-chan-ack");
10105
10106 /* RA containing reason=LU */
10107 var GsmFrameNumber fn := 2342;
10108 var uint8_t ra := 2;
10109 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10110
10111 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10112
10113 /* First send the Chan Act ACK */
10114 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010115 var RSL_IE_Body chan_ident_ie;
10116 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10117 setverdict(fail, "RSL Channel Identification IE is absent");
10118 mtc.stop;
10119 }
10120
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010121 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn + 10));
10122
10123 /* Then expect the Immediate Assignment, after we ACKed the chan act */
10124 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10125
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010126 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10127 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010128
10129 /* Check that the lchan is working */
10130 var octetstring l3 := '00010203040506'O;
10131 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10132
10133 var BSSAP_N_CONNECT_ind rx_c_ind;
10134 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
10135 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10136
10137 f_sleep(1.0);
10138 f_shutdown_helper();
10139}
10140
10141testcase TC_imm_ass_pre_chan_ack() runs on test_CT {
10142 var RSL_Message chan_act;
10143 var RSL_Message imm_ass;
10144
10145 f_init(1, false);
10146 f_sleep(1.0);
10147
10148 f_vty_set_imm_ass(BSCVTY, 0, "pre-chan-ack");
10149
10150 /* RA containing reason=LU */
10151 var GsmFrameNumber fn := 2342;
10152 var uint8_t ra := 2;
10153 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10154
10155 /* (set bts 0 cfg back to default) */
10156 f_vty_set_imm_ass(BSCVTY);
10157
10158 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10159 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010160 var RSL_IE_Body chan_ident_ie;
10161 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10162 setverdict(fail, "RSL Channel Identification IE is absent");
10163 mtc.stop;
10164 }
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010165
10166 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10167 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010168 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10169 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020010170
10171 /* Only now send the Chan Act ACK */
10172 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10173
10174 /* Check that the lchan is working */
10175 var octetstring l3 := '00010203040506'O;
10176 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10177
10178 var BSSAP_N_CONNECT_ind rx_c_ind;
10179 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
10180 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10181
10182 f_sleep(1.0);
10183 f_shutdown_helper();
10184}
10185
Neels Hofmeyr23158742021-09-07 19:08:07 +020010186testcase TC_imm_ass_pre_ts_ack() runs on test_CT {
10187 var RSL_Message chan_act;
10188 var RSL_Message imm_ass;
10189
10190 f_init(1, false);
10191 f_sleep(1.0);
10192
10193 f_vty_set_imm_ass(BSCVTY, 0, "pre-ts-ack");
10194
10195 /* RA containing reason=LU */
10196 var GsmFrameNumber fn := 2342;
10197 var uint8_t ra := 2;
10198 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10199
10200 /* (set bts 0 cfg back to default) */
10201 f_vty_set_imm_ass(BSCVTY);
10202
10203 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
10204 var RslChannelNr chan_nr := chan_act.ies[0].body.chan_nr;
10205 var RSL_IE_Body chan_ident_ie;
10206 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10207 setverdict(fail, "RSL Channel Identification IE is absent");
10208 mtc.stop;
10209 }
10210
10211 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10212 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10213 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10214 chan_ident_ie.chan_ident.ch_desc.v.tsc);
10215
10216 /* Only now send the Chan Act ACK */
10217 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10218
10219 /* Check that the lchan is working */
10220 var octetstring l3 := '00010203040506'O;
10221 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10222
10223 var BSSAP_N_CONNECT_ind rx_c_ind;
10224 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
10225 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10226
10227 f_sleep(1.0);
10228 f_shutdown_helper();
10229}
10230
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010231testcase TC_imm_ass_pre_chan_ack_dyn_ts() runs on test_CT {
10232 /* change Timeslot 6 before f_init() starts RSL */
10233 f_init_vty();
10234 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
10235 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10236
10237 f_init(1, false);
10238 f_sleep(1.0);
10239
10240 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
10241 /* The BSC will activate the dynamic PDCH by default, so confirm that */
10242 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
10243 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2323));
10244
10245 /* clean up timeslot 6 config, will only take effect when the OML drops the next time */
10246 f_ts_set_chcomb(0, 0, 6, "PDCH");
10247
10248 /* block all static timeslots so that the dyn TS will be used */
10249 f_disable_all_tch_f();
10250 f_disable_all_tch_h();
10251 f_disable_all_sdcch();
10252
10253 var RSL_Message chan_act;
10254 var RSL_Message imm_ass;
10255
10256 f_init(1, false);
10257 f_sleep(1.0);
10258
10259 f_vty_set_imm_ass(BSCVTY, 0, "pre-chan-ack");
10260
10261 /* RA containing reason=LU */
10262 var GsmFrameNumber fn := 2342;
10263 var uint8_t ra := 2;
10264 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10265
10266 /* (set bts 0 cfg back to default) */
10267 f_vty_set_imm_ass(BSCVTY);
10268
10269 /* Expect the dyn TS to deactivate PDCH first */
10270 f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
10271 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
10272
10273 /* Now activation as SDCCH8 */
10274 chan_nr := valueof(t_RslChanNr_SDCCH8(tn := 6, sub_slot := 0));
10275
10276 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010277 var RSL_IE_Body chan_ident_ie;
10278 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10279 setverdict(fail, "RSL Channel Identification IE is absent");
10280 mtc.stop;
10281 }
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010282
10283 /* *FIRST* expect the Immediate Assignment, before we ACK the chan act */
10284 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010285 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10286 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020010287
10288 /* Only now send the Chan Act ACK */
10289 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10290
10291 /* Check that the lchan is working */
10292 var octetstring l3 := '00010203040506'O;
10293 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10294
10295 var BSSAP_N_CONNECT_ind rx_c_ind;
10296 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
10297 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10298
10299 f_sleep(1.0);
10300 f_shutdown_helper();
10301}
10302
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010303testcase TC_imm_ass_pre_ts_ack_dyn_ts() runs on test_CT {
10304 /* change Timeslot 6 before f_init() starts RSL */
10305 f_init_vty();
10306 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
10307 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10308
10309 f_init(1, false);
10310 f_sleep(1.0);
10311
10312 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
10313 /* The BSC will activate the dynamic PDCH by default, so confirm that */
10314 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
10315 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2323));
10316
10317 /* clean up timeslot 6 config, will only take effect when the OML drops the next time */
10318 f_ts_set_chcomb(0, 0, 6, "PDCH");
10319
10320 /* block all static timeslots so that the dyn TS will be used */
10321 f_disable_all_tch_f();
10322 f_disable_all_tch_h();
10323 f_disable_all_sdcch();
10324
10325 var RSL_Message chan_act;
10326 var RSL_Message imm_ass;
10327
10328 f_init(1, false);
10329 f_sleep(1.0);
10330
10331 f_vty_set_imm_ass(BSCVTY, 0, "pre-ts-ack");
10332
10333 /* RA containing reason=LU */
10334 var GsmFrameNumber fn := 2342;
10335 var uint8_t ra := 2;
10336 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(ra, 1), fn));
10337
10338 /* (set bts 0 cfg back to default) */
10339 f_vty_set_imm_ass(BSCVTY);
10340
10341 /* Expect the dyn TS to deactivate PDCH first */
10342 f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
10343
10344 /* And already the Immediate Assignment even before the PDCH Deact ACK */
10345 imm_ass := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
10346
10347 /* continue the Osmo style PDCH Deact (usual chan rel) */
10348 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
10349
10350 /* Now activation as SDCCH8 */
10351 chan_nr := valueof(t_RslChanNr_SDCCH8(tn := 6, sub_slot := 0));
10352
10353 chan_act := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010354 var RSL_IE_Body chan_ident_ie;
10355 if (not f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, chan_ident_ie)) {
10356 setverdict(fail, "RSL Channel Identification IE is absent");
10357 mtc.stop;
10358 }
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010359 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
10360
Neels Hofmeyr07603cf2021-09-07 19:05:52 +020010361 f_verify_imm_ass(imm_ass, ra, fn, chan_nr, chan_ident_ie.chan_ident.ch_desc.v.arfcn,
10362 chan_ident_ie.chan_ident.ch_desc.v.tsc);
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020010363
10364 /* Check that the lchan is working */
10365 var octetstring l3 := '00010203040506'O;
10366 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
10367
10368 var BSSAP_N_CONNECT_ind rx_c_ind;
10369 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
10370 BSSAP.send(ts_BSSAP_CONNECT_res(rx_c_ind.connectionId));
10371
10372 f_sleep(1.0);
10373 f_shutdown_helper();
10374}
10375
Neels Hofmeyr5d7d13f2021-09-07 14:44:36 +020010376/* GET and SET the bts.N.trx.M.rf_locked CTRL variable */
10377testcase TC_ctrl_trx_rf_locked() runs on test_CT {
10378 var MSC_ConnHdlr vc_conn;
10379
10380 f_init(nr_bts := 2, handler_mode := true, nr_msc := 1);
10381 f_sleep(1.0);
10382
10383 /* BTS 0, 1, 2 are OML unlocked, only BTS 0, 1 are actually connected to RSL. */
10384 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10385 "0,0,operational,unlocked,on,rsl-up;" &
10386 "1,0,operational,unlocked,on,rsl-up;" &
10387 "2,0,operational,unlocked,on,rsl-down;" &
10388 "3,0,inoperational,locked,on,rsl-down;");
10389
10390 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: lock BTS 1 TRX 0");
10391 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "1");
10392 /* give it a moment to settle the FSM status */
10393 f_sleep(1.0);
10394
10395 /* Now BTS 1 TRX 0 should reflect "locked". Note the RF policy stays "on", because this is still handled
10396 * globally in osmo-bsc. Probably after sending "rf_locked 1" for a TRX, that TRX should reflect an RF policy
10397 * of "off"? But that's for a future patch if at all. */
10398 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10399 "0,0,operational,unlocked,on,rsl-up;" &
10400 "1,0,operational,locked,on,rsl-up;" &
10401 "2,0,operational,unlocked,on,rsl-down;" &
10402 "3,0,inoperational,locked,on,rsl-down;");
10403
10404 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: lock the already locked TRX, nothing should change");
10405 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "1");
10406 f_sleep(1.0);
10407 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10408 "0,0,operational,unlocked,on,rsl-up;" &
10409 "1,0,operational,locked,on,rsl-up;" &
10410 "2,0,operational,unlocked,on,rsl-down;" &
10411 "3,0,inoperational,locked,on,rsl-down;");
10412
10413 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock BTS 1 TRX 0");
10414 f_ctrl_set(IPA_CTRL, "bts.1.trx.0.rf_locked", "0");
10415 f_sleep(1.0);
10416 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10417 "0,0,operational,unlocked,on,rsl-up;" &
10418 "1,0,operational,unlocked,on,rsl-up;" &
10419 "2,0,operational,unlocked,on,rsl-down;" &
10420 "3,0,inoperational,locked,on,rsl-down;");
10421
10422 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock an already unlocked TRX, nothing should change");
10423 f_ctrl_set(IPA_CTRL, "bts.0.trx.0.rf_locked", "0");
10424 f_sleep(1.0);
10425 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10426 "0,0,operational,unlocked,on,rsl-up;" &
10427 "1,0,operational,unlocked,on,rsl-up;" &
10428 "2,0,operational,unlocked,on,rsl-down;" &
10429 "3,0,inoperational,locked,on,rsl-down;");
10430
10431 f_logp(BSCVTY, "TC_ctrl_trx_rf_locked: unlock an inoperational TRX");
10432 f_ctrl_set(IPA_CTRL, "bts.3.trx.0.rf_locked", "0");
10433 f_sleep(1.0);
10434 f_ctrl_get_exp(IPA_CTRL, "rf_states",
10435 "0,0,operational,unlocked,on,rsl-up;" &
10436 "1,0,operational,unlocked,on,rsl-up;" &
10437 "2,0,operational,unlocked,on,rsl-down;" &
10438 "3,0,inoperational,locked,on,rsl-down;");
10439
10440 f_shutdown_helper();
10441}
10442
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010443const CounterNameVals counternames_cm_serv_rej := {
10444 { "cm_serv_rej", 0 },
10445 { "cm_serv_rej:imsi_unknown_in_hlr", 0 },
10446 { "cm_serv_rej:illegal_ms", 0 },
10447 { "cm_serv_rej:imsi_unknown_in_vlr", 0 },
10448 { "cm_serv_rej:imei_not_accepted", 0 },
10449 { "cm_serv_rej:illegal_me", 0 },
10450 { "cm_serv_rej:plmn_not_allowed", 0 },
10451 { "cm_serv_rej:loc_not_allowed", 0 },
10452 { "cm_serv_rej:roaming_not_allowed", 0 },
10453 { "cm_serv_rej:network_failure", 0 },
10454 { "cm_serv_rej:synch_failure", 0 },
10455 { "cm_serv_rej:congestion", 0 },
10456 { "cm_serv_rej:srv_opt_not_supported", 0 },
10457 { "cm_serv_rej:rqd_srv_opt_not_supported", 0 },
10458 { "cm_serv_rej:srv_opt_tmp_out_of_order", 0 },
10459 { "cm_serv_rej:call_can_not_be_identified", 0 },
10460 { "cm_serv_rej:incorrect_message", 0 },
10461 { "cm_serv_rej:invalid_mandantory_inf", 0 },
10462 { "cm_serv_rej:msg_type_not_implemented", 0 },
10463 { "cm_serv_rej:msg_type_not_compatible", 0 },
10464 { "cm_serv_rej:inf_eleme_not_implemented", 0 },
10465 { "cm_serv_rej:condtional_ie_error", 0 },
10466 { "cm_serv_rej:msg_not_compatible", 0 },
10467 { "cm_serv_rej:protocol_error", 0 },
10468 { "cm_serv_rej:retry_in_new_cell", 0 }
10469};
10470
10471private function f_TC_cm_serv_rej(charstring id) runs on MSC_ConnHdlr
10472{
10473 f_create_chan_and_exp();
10474 BSSAP.send(ts_PDU_DTAP_MT(ts_CM_SERV_REJ('02'O), '00'O));
Neels Hofmeyr87a65612021-11-16 15:56:45 +010010475 f_sleep(1.0);
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010476}
10477testcase TC_cm_serv_rej() runs on test_CT {
10478 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10479 var MSC_ConnHdlr vc_conn;
10480
10481 f_init(1, true);
10482 f_sleep(1.0);
10483
10484 f_ctrs_bts_init(1, counternames_cm_serv_rej);
10485
10486 vc_conn := f_start_handler(refers(f_TC_cm_serv_rej), pars);
10487 vc_conn.done;
10488
10489 f_ctrs_bts_add(0, "cm_serv_rej", 1);
10490 f_ctrs_bts_add(0, "cm_serv_rej:imsi_unknown_in_hlr", 1);
10491 f_ctrs_bts_verify();
10492
Neels Hofmeyr87a65612021-11-16 15:56:45 +010010493 f_sleep(1.0);
Neels Hofmeyrb7581872021-11-07 14:02:49 +010010494 f_shutdown_helper();
10495}
10496
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010497/* Reproduce a segfault happening when the SDCCH (primary) lchan is lost in-between a TCH Channel Activ and its Channel
10498 * Activ Ack (SYS#5627). */
10499private function f_TC_lost_sdcch_during_assignment(charstring id) runs on MSC_ConnHdlr {
10500 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Vadim Yanitskiyf0310e32021-10-26 00:30:59 +030010501
10502 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
10503 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010504
10505 var BSSMAP_FIELD_CodecType codecType;
10506 codecType := valueof(ass_cmd.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType);
10507
10508 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
10509
10510 /* First establish a signalling lchan */
10511 f_create_chan_and_exp();
10512 f_rslem_dchan_queue_enable();
10513
10514 /* we should now have a COMPL_L3 at the MSC */
10515 var template PDU_BSSAP exp_l3_compl;
10516 exp_l3_compl := tr_BSSMAP_ComplL3()
10517 if (g_pars.aoip == false) {
10518 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := omit;
10519 } else {
10520 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := ?;
10521 }
10522 timer T := 10.0;
10523 T.start;
10524 alt {
10525 [] BSSAP.receive(exp_l3_compl);
10526 [] BSSAP.receive(tr_BSSMAP_ComplL3) {
10527 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching COMPLETE LAYER 3 INFORMATION");
10528 }
10529 [] T.timeout {
10530 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
10531 }
10532 }
10533
10534 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
10535 activate(as_Media_mgw());
10536
10537 var RslChannelNr chan_nr := { u := { ch0 := RSL_CHAN_NR_Bm_ACCH }, tn := 1 };
10538 f_rslem_register(0, chan_nr);
10539
10540 f_rslem_set_auto_chan_act_ack(RSL_PROC, false);
10541 BSSAP.send(ass_cmd);
10542
10543
10544 /* Wait for the Channel Activ for the TCH channel */
10545 var ASP_RSL_Unitdata rx_rsl_ud;
10546 RSL.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV), sid := ?)) -> value rx_rsl_ud;
10547
10548 /* make the original SDCCH disappear */
10549 RSL.send(ts_RSL_REL_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
10550
10551 /* and ACK the TCH channel activation. This caused a segfault up to OsmoBSC 1.7.0 (SYS#5627) */
10552 RSL.send(ts_ASP_RSL_UD(ts_RSL_CHAN_ACT_ACK(chan_nr, 23), rx_rsl_ud.streamId));
10553
10554 interleave {
10555 [] BSSAP.receive(tr_BSSMAP_AssignmentFail);
10556 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
10557 }
10558
10559 BSSAP.send(ts_BSSMAP_ClearCommand(0));
10560 BSSAP.receive(tr_BSSMAP_ClearComplete);
10561 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
10562
10563 var MgcpCommand mgcp;
10564 MGCP.receive(tr_DLCX()) -> value mgcp {
10565 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
10566 };
10567
10568 f_sleep(0.5);
10569}
10570testcase TC_lost_sdcch_during_assignment() runs on test_CT {
10571 var TestHdlrParams pars := f_gen_test_hdlr_pars();
10572 var MSC_ConnHdlr vc_conn;
10573
10574 f_init(1, true);
10575 f_sleep(1.0);
10576
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020010577 vc_conn := f_start_handler(refers(f_TC_lost_sdcch_during_assignment), pars);
10578 vc_conn.done;
10579
10580 f_shutdown_helper();
10581}
10582
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020010583const CounterNameVals counternames_bsc_bts_all_available_allocated := {
10584 { "all_allocated:sdcch", 0 },
10585 { "all_allocated:static_sdcch", 0 },
10586 { "all_allocated:tch", 0 },
10587 { "all_allocated:static_tch", 0 }
10588}
10589
10590private function f_all_allocated_expect_counter_change(charstring_list expect_changed) runs on test_CT
10591{
10592 /* Make sure counters settle first */
10593 f_sleep(1.0);
10594
10595 /* Take a baseline of counters */
10596 f_ctrs_bsc_and_bts_init(1, counternames_bsc_bts_all_available_allocated);
10597
10598 /* Elapse some time so that we see changes in counters, hopefully where expected */
10599 f_sleep(2.0);
10600
10601 /* Get new counters */
10602 var charstring_list all_changed := {};
10603 all_changed := all_changed & f_counter_name_vals_get_changed_n(IPA_CTRL, "bsc", g_ctr_bsc);
10604 all_changed := all_changed & f_counter_name_vals_get_changed_n(IPA_CTRL, "bts", g_ctr_bts);
10605
10606 /* Compare with expectations */
10607 var charstring_list all_expect_changed := {};
10608 for (var integer i := 0; i < lengthof(expect_changed); i := i + 1) {
10609 all_expect_changed := all_expect_changed & { "bsc.0." & expect_changed[i], "bts.0." & expect_changed[i] };
10610 }
10611 f_counter_name_vals_expect_changed_list(all_changed, all_expect_changed);
10612}
10613
10614testcase TC_ratectr_all_available_allocated() runs on test_CT {
10615 var ASP_RSL_Unitdata rsl_ud;
10616 var integer i;
10617 var integer chreq_total, chreq_nochan;
10618
10619 f_init(1);
10620 f_sleep(1.0);
10621
10622 /* Exhaust all dedicated SDCCH lchans.
10623 /* GSM 44.018 Table 9.1.8.2:
10624 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
10625 */
10626 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
10627 f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
10628 }
10629
10630 /* Since only bts 0 is connected, expecting all_allocated to become true for both bts 0 and the "global" bsc
10631 * level.
10632 * All SDCCH are now occupied. */
10633 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch"});
10634
10635 /* Also fill up all remaining (TCH) channels */
10636 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS; i := i+1) {
10637 f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
10638 }
10639
10640 /* All TCH are now also occupied */
10641 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch",
10642 "all_allocated:tch", "all_allocated:static_tch"});
10643
10644 f_shutdown_helper();
10645}
10646
10647testcase TC_ratectr_all_available_allocated_dyn() runs on test_CT {
10648 var ASP_RSL_Unitdata rsl_ud;
10649 var integer i;
10650 var integer chreq_total, chreq_nochan;
10651
10652 f_init_vty();
10653 f_ts_set_chcomb(0, 0, 2, "TCH/F_TCH/H_PDCH");
10654 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
10655 /* Now we have 3 TCH/F, 1 OSMO_DYN, 1 TCH/H */
10656
10657 f_init(1, guard_timeout := 60.0);
10658 f_sleep(1.0);
10659
10660 /* The dyn TS wants to activate PDCH mode, ACK that. */
10661 var RslChannelNr chan_nr;
10662 chan_nr := valueof(t_RslChanNr_PDCH(2));
10663 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
10664 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
10665
10666 /* Exhaust all dedicated SDCCH lchans.
10667 /* GSM 44.018 Table 9.1.8.2:
10668 * RA = '13'O -> Establishment cause = 0001xxxx (MS dual rate capable and asks for "SDCCH").
10669 */
10670 for (i := 0; i < NUM_SDCCH_PER_BTS; i := i+1) {
10671 f_est_dchan('13'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
10672 }
10673
10674 /* The static SDCCH should now be occupied, while still 3x8 dynamic SDCCH potentially remain. So only
10675 * all_allocated:static_sdcch is counted, all_allocated:sdcch remains zero. */
10676 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch"});
10677
10678 /* Request more SDCCH, hence convert the first dyn TS to SDCCH8.
10679 * Will release them later, so remember all the DchanTuples. */
10680 var DchanTuples dyn_sddch := {};
10681 dyn_sddch := dyn_sddch & { f_est_dchan_dyn('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
10682
10683 /* Also occupy the seven other SDCCH of the dyn TS */
10684 for (i := 0; i < 7; i := i+1) {
10685 dyn_sddch := dyn_sddch & { f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O) };
10686 }
10687
10688 /* Now all dynamic SDCCH are also occupied, so for the first time all_allocated:sdcch will trigger... */
10689 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch"});
10690
10691 /* occupy the remaining TCH, three TCH/F and two TCH/H lchans */
10692 for (i := 0; i < 5; i := i+1) {
10693 f_est_dchan('33'O, NUM_SDCCH_PER_BTS + i, '00010203040506'O);
10694 }
10695
10696 /* All TCH lchans are now also occupied, both static and dynamic */
10697 f_all_allocated_expect_counter_change({"all_allocated:sdcch", "all_allocated:static_sdcch",
10698 "all_allocated:tch", "all_allocated:static_tch"});
10699
10700 /* Starting to release the dyn TS: as soon as the first SDCCH gets released, all_allocated:sdcch stops
10701 * incrementing. */
10702 var BssmapCause cause := 0;
10703 var DchanTuple dt := dyn_sddch[0];
10704 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
10705 f_exp_chan_rel_and_clear(dt, 0);
10706
10707 /* one dyn TS SDCCH is free again, so only the static_sdcch should increment. For tch, both static and dynamic
10708 * count as occupied, so those still both increment. */
10709 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch",
10710 "all_allocated:tch", "all_allocated:static_tch"});
10711
10712 /* Release the remaining SDCCH of the dyn TS, so it becomes available as TCH again */
10713 for (i := 1; i < lengthof(dyn_sddch); i := i+1) {
10714 dt := dyn_sddch[i];
10715 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
10716 f_exp_chan_rel_and_clear(dt, 0);
10717 }
10718
10719 /* All SDCCH on the dyn TS are released, the dyn TS wants to activate PDCH again */
10720 chan_nr := valueof(t_RslChanNr_PDCH(2));
10721 f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
10722 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
10723
10724 /* Now all channels are occupied except the dyn TS, so expecting only the static counters to increment */
10725 f_all_allocated_expect_counter_change({"all_allocated:static_sdcch", "all_allocated:static_tch"});
10726
10727 /* clean up config */
10728 f_ts_reset_chcomb(0);
10729
10730 f_shutdown_helper();
10731}
10732
Harald Welte28d943e2017-11-25 15:00:50 +010010733control {
Harald Welte898113b2018-01-31 18:32:21 +010010734 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +010010735 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +010010736 execute( TC_ctrl_msc0_connection_status() );
Neels Hofmeyrf65ce872021-09-23 18:40:10 +020010737 /* In SCCPlite tests, only one MSC is configured. These tests assume that three MSCs are configured, so only run
10738 * these in the AoIP test suite. */
10739 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
10740 execute( TC_stat_num_msc_connected_1() );
10741 execute( TC_stat_num_msc_connected_2() );
10742 execute( TC_stat_num_msc_connected_3() );
10743 }
Neels Hofmeyr5ce3ae42021-08-29 15:32:00 +020010744 execute( TC_stat_num_bts_connected_1() );
10745 execute( TC_stat_num_bts_connected_2() );
10746 execute( TC_stat_num_bts_connected_3() );
Harald Welte96c94412017-12-09 03:12:45 +010010747 execute( TC_ctrl() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +020010748 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER) {
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +020010749 execute( TC_ctrl_location() );
10750 }
Harald Welte898113b2018-01-31 18:32:21 +010010751
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020010752 execute( TC_si_default() );
Neels Hofmeyr66aeba42020-07-06 02:21:21 +020010753 execute( TC_si2quater_2_earfcns() );
10754 execute( TC_si2quater_3_earfcns() );
10755 execute( TC_si2quater_4_earfcns() );
10756 execute( TC_si2quater_5_earfcns() );
10757 execute( TC_si2quater_6_earfcns() );
Neels Hofmeyrad132f22020-07-08 02:20:16 +020010758 execute( TC_si2quater_12_earfcns() );
10759 execute( TC_si2quater_23_earfcns() );
10760 execute( TC_si2quater_32_earfcns() );
10761 execute( TC_si2quater_33_earfcns() );
10762 execute( TC_si2quater_42_earfcns() );
10763 execute( TC_si2quater_48_earfcns() );
10764 execute( TC_si2quater_49_earfcns() );
Pau Espin Pedrol85a84432020-07-20 18:45:03 +020010765 execute( TC_si_acc_rotate() );
Alexander Couzens4ad3a352020-09-10 22:29:12 +020010766 execute( TC_si_acc_ramp_rotate() );
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020010767
Harald Welte898113b2018-01-31 18:32:21 +010010768 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +010010769 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +010010770 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +010010771 execute( TC_chan_act_ack_noest() );
Philipp Maier9c60a622020-07-09 15:08:46 +020010772 execute( TC_chan_act_ack_noest_emerg() );
Philipp Maier606f07d2020-08-12 17:21:58 +020010773 execute( TC_chan_rqd_emerg_deny() );
Harald Welteae026692017-12-09 01:03:01 +010010774 execute( TC_chan_act_ack_est_ind_noreply() );
10775 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +010010776 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +010010777 execute( TC_chan_exhaustion() );
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +070010778 execute( TC_chan_deact_silence() );
Harald Welte4003d112017-12-09 22:35:39 +010010779 execute( TC_chan_rel_rll_rel_ind() );
10780 execute( TC_chan_rel_conn_fail() );
10781 execute( TC_chan_rel_hard_clear() );
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +020010782 execute( TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() );
10783 execute( TC_chan_rel_last_eutran_plmn_hard_clear_csfb() );
Harald Welte99787102019-02-04 10:41:36 +010010784 execute( TC_chan_rel_hard_clear_csfb() );
Harald Welted8c36cd2017-12-09 23:05:31 +010010785 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +020010786 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +010010787 execute( TC_chan_rel_a_reset() );
Pau Espin Pedrolc675b612020-01-09 19:55:40 +010010788 execute( TC_chan_rel_sccp_tiar_timeout() );
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +020010789 execute( TC_chan_rel_rr_cause() );
Harald Welte6f521d82017-12-11 19:52:02 +010010790
Harald Weltecfe2c962017-12-15 12:09:32 +010010791 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +010010792
10793 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +010010794 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +010010795 execute( TC_assignment_csd() );
10796 execute( TC_assignment_ctm() );
10797 execute( TC_assignment_sign() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +020010798 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
10799 execute( TC_assignment_aoip_tla_v6() );
10800 }
Harald Welte235ebf12017-12-15 14:18:16 +010010801 execute( TC_assignment_fr_a5_0() );
10802 execute( TC_assignment_fr_a5_1() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +020010803 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte8f67d1d2018-05-25 20:38:42 +020010804 execute( TC_assignment_fr_a5_1_codec_missing() );
10805 }
Harald Welte235ebf12017-12-15 14:18:16 +010010806 execute( TC_assignment_fr_a5_3() );
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +020010807 execute( TC_assignment_fr_a5_4() );
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +020010808 execute( TC_assignment_fr_a5_4_fail() );
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +020010809 execute( TC_assignment_fr_a5_not_sup() );
Harald Welte3c86ea02018-05-10 22:28:05 +020010810 execute( TC_ciph_mode_a5_0() );
10811 execute( TC_ciph_mode_a5_1() );
Oliver Smith50b98122021-07-09 15:00:28 +020010812 execute( TC_ciph_mode_a5_2_0() );
Oliver Smith1dff88d2021-07-09 08:45:51 +020010813 execute( TC_ciph_mode_a5_2_1() );
Harald Welte3c86ea02018-05-10 22:28:05 +020010814 execute( TC_ciph_mode_a5_3() );
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +020010815 execute( TC_ciph_mode_a5_4() );
Harald Welte16a4adf2017-12-14 18:54:01 +010010816
Harald Welte60aa5762018-03-21 19:33:13 +010010817 execute( TC_assignment_codec_fr() );
Neels Hofmeyr559d5d02021-04-16 16:50:49 +020010818 execute( TC_assignment_codec_fr_by_mode_modify() );
Harald Welte60aa5762018-03-21 19:33:13 +010010819 execute( TC_assignment_codec_hr() );
10820 execute( TC_assignment_codec_efr() );
10821 execute( TC_assignment_codec_amr_f() );
10822 execute( TC_assignment_codec_amr_h() );
Philipp Maier8a581d22019-03-26 18:32:48 +010010823
Neels Hofmeyrf246a922020-05-13 02:27:10 +020010824 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier8a581d22019-03-26 18:32:48 +010010825 execute( TC_assignment_codec_amr_f_S1() );
10826 execute( TC_assignment_codec_amr_h_S1() );
10827 execute( TC_assignment_codec_amr_f_S124() );
10828 execute( TC_assignment_codec_amr_h_S124() );
10829 execute( TC_assignment_codec_amr_f_S0() );
10830 execute( TC_assignment_codec_amr_f_S02() );
10831 execute( TC_assignment_codec_amr_f_S024() );
10832 execute( TC_assignment_codec_amr_f_S0247() );
10833 execute( TC_assignment_codec_amr_h_S0() );
10834 execute( TC_assignment_codec_amr_h_S02() );
10835 execute( TC_assignment_codec_amr_h_S024() );
10836 execute( TC_assignment_codec_amr_h_S0247() );
10837 execute( TC_assignment_codec_amr_f_S01234567() );
10838 execute( TC_assignment_codec_amr_f_S0234567() );
10839 execute( TC_assignment_codec_amr_f_zero() );
10840 execute( TC_assignment_codec_amr_f_unsupp() );
10841 execute( TC_assignment_codec_amr_h_S7() );
Neels Hofmeyr21863562020-11-26 00:34:33 +000010842 execute( TC_assignment_codec_amr_f_start_mode_auto() );
10843 execute( TC_assignment_codec_amr_h_start_mode_auto() );
Neels Hofmeyr3eb94562020-11-26 02:40:26 +000010844 execute( TC_assignment_codec_amr_f_start_mode_4() );
10845 execute( TC_assignment_codec_amr_h_start_mode_4() );
Neels Hofmeyr454d7922020-11-26 02:24:57 +000010846 execute( TC_assignment_codec_amr_startmode_cruft() );
Philipp Maier8a581d22019-03-26 18:32:48 +010010847 }
Harald Welte60aa5762018-03-21 19:33:13 +010010848
Philipp Maierac09bfc2019-01-08 13:41:39 +010010849 execute( TC_assignment_codec_fr_exhausted_req_hr() );
10850 execute( TC_assignment_codec_fr_exhausted_req_fr() );
10851 execute( TC_assignment_codec_fr_exhausted_req_fr_hr() );
10852 execute( TC_assignment_codec_fr_exhausted_req_hr_fr() );
10853 execute( TC_assignment_codec_hr_exhausted_req_fr() );
10854 execute( TC_assignment_codec_hr_exhausted_req_hr() );
10855 execute( TC_assignment_codec_hr_exhausted_req_hr_fr() );
10856 execute( TC_assignment_codec_hr_exhausted_req_fr_hr() );
10857 execute( TC_assignment_codec_req_hr_fr() );
10858 execute( TC_assignment_codec_req_fr_hr() );
Pau Espin Pedrol14475352021-07-22 15:48:16 +020010859 execute( TC_assignment_sdcch_exhausted_req_signalling() );
10860 execute( TC_assignment_sdcch_exhausted_req_signalling_tch_forbidden() );
10861 execute( TC_assignment_sdcch_exhausted_req_voice_tch_forbidden() );
Philipp Maierac09bfc2019-01-08 13:41:39 +010010862
Pau Espin Pedrol23510fb2021-07-20 17:00:38 +020010863 execute( TC_assignment_osmux() );
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +020010864
Harald Welte898113b2018-01-31 18:32:21 +010010865 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +010010866 execute( TC_rll_est_ind_inact_lchan() );
10867 execute( TC_rll_est_ind_inval_sapi1() );
10868 execute( TC_rll_est_ind_inval_sapi3() );
10869 execute( TC_rll_est_ind_inval_sacch() );
10870
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +070010871 /* DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
10872 execute( TC_tch_dlci_link_id_sapi() );
10873
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +070010874 /* SAPI N Reject triggered by RLL establishment failures */
10875 execute( TC_rll_rel_ind_sapi_n_reject() );
10876 execute( TC_rll_err_ind_sapi_n_reject() );
10877 execute( TC_rll_timeout_sapi_n_reject() );
10878
Harald Welte898113b2018-01-31 18:32:21 +010010879 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +010010880 execute( TC_paging_imsi_nochan() );
10881 execute( TC_paging_tmsi_nochan() );
10882 execute( TC_paging_tmsi_any() );
10883 execute( TC_paging_tmsi_sdcch() );
10884 execute( TC_paging_tmsi_tch_f() );
10885 execute( TC_paging_tmsi_tch_hf() );
10886 execute( TC_paging_imsi_nochan_cgi() );
10887 execute( TC_paging_imsi_nochan_lac_ci() );
10888 execute( TC_paging_imsi_nochan_ci() );
10889 execute( TC_paging_imsi_nochan_lai() );
10890 execute( TC_paging_imsi_nochan_lac() );
10891 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +010010892 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
10893 execute( TC_paging_imsi_nochan_rnc() );
10894 execute( TC_paging_imsi_nochan_lac_rnc() );
10895 execute( TC_paging_imsi_nochan_lacs() );
10896 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +010010897 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +010010898 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +010010899 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +010010900 execute( TC_paging_counter() );
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +010010901 execute( TC_paging_resp_unsol() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +010010902
10903 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +010010904 execute( TC_rsl_unknown_unit_id() );
10905
10906 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +010010907
10908 execute( TC_classmark() );
Harald Welteeddf0e92020-06-21 19:42:15 +020010909 execute( TC_common_id() );
Harald Welte898113b2018-01-31 18:32:21 +010010910 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +010010911 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +010010912 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +010010913 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +010010914 execute( TC_err_84_unknown_msg() );
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010010915
Harald Welte261af4b2018-02-12 21:20:39 +010010916 execute( TC_ho_int() );
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +020010917 execute( TC_ho_int_a5_0() );
10918 execute( TC_ho_int_a5_1() );
10919 execute( TC_ho_int_a5_3() );
10920 execute( TC_ho_int_a5_4() );
Neels Hofmeyr5f144212020-11-03 15:41:58 +000010921 execute( TC_ho_int_radio_link_failure() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010010922
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +010010923 /* TC_ho_out_of_this_bsc is run last, see comment below */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +020010924 execute( TC_ho_out_fail_no_msc_response() );
10925 execute( TC_ho_out_fail_rr_ho_failure() );
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +020010926 execute( TC_ho_out_fail_no_result_after_ho_cmd() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010010927
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010010928 execute( TC_ho_into_this_bsc() );
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +020010929 execute( TC_ho_into_this_bsc_a5_0() );
10930 execute( TC_ho_into_this_bsc_a5_1() );
10931 execute( TC_ho_into_this_bsc_a5_3() );
10932 execute( TC_ho_into_this_bsc_a5_4() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +020010933 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
10934 execute( TC_ho_into_this_bsc_tla_v6() );
10935 }
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +020010936 execute( TC_srvcc_eutran_to_geran() );
Pau Espin Pedrol35801c32021-04-19 13:03:20 +020010937 execute( TC_srvcc_eutran_to_geran_ho_out() );
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +020010938 execute( TC_srvcc_eutran_to_geran_forbid_fast_return() );
10939 execute( TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +010010940 execute( TC_ho_in_fail_msc_clears() );
10941 execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
10942 execute( TC_ho_in_fail_no_detect() );
10943 execute( TC_ho_in_fail_no_detect2() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +010010944
Neels Hofmeyr91401012019-07-11 00:42:35 +020010945 execute( TC_ho_neighbor_config_1() );
10946 execute( TC_ho_neighbor_config_2() );
10947 execute( TC_ho_neighbor_config_3() );
10948 execute( TC_ho_neighbor_config_4() );
10949 execute( TC_ho_neighbor_config_5() );
10950 execute( TC_ho_neighbor_config_6() );
10951 execute( TC_ho_neighbor_config_7() );
10952
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +010010953 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010010954 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +010010955 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +020010956
10957 execute( TC_dyn_pdch_ipa_act_deact() );
10958 execute( TC_dyn_pdch_ipa_act_nack() );
10959 execute( TC_dyn_pdch_osmo_act_deact() );
10960 execute( TC_dyn_pdch_osmo_act_nack() );
Pau Espin Pedrol37a4c152021-11-16 19:02:23 +010010961 execute( TC_dyn_ts_sdcch8_act_deact() );
10962 execute( TC_dyn_ts_sdcch8_all_subslots_used() );
10963 execute( TC_dyn_ts_sdcch8_tch_call_act_deact() );
10964 execute( TC_dyn_ts_sdcch8_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +020010965
Stefan Sperling0796a822018-10-05 13:01:39 +020010966 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +020010967 execute( TC_chopped_ipa_payload() );
Stefan Sperling0796a822018-10-05 13:01:39 +020010968
Pau Espin Pedrol8f773632019-11-05 11:46:53 +010010969 /* Power control related */
10970 execute( TC_assignment_verify_ms_power_params_ie() );
Vadim Yanitskiy4b233042021-06-30 00:58:43 +020010971 execute( TC_c0_power_red_mode() );
Neels Hofmeyr4f118412020-06-04 15:25:10 +020010972
10973 /* MSC pooling */
10974 /* FIXME: in SCCPlite, indicating how many MSCs should be connected does currently not work. Since
10975 * RESET->RESET-ACK is unconditionally negotiated for all configured MSCs, they always all appear as connected
10976 * to osmo-bsc. The MSC pooling tests however require disconnecting selected MSCs, and hence don't work out as
10977 * intended on SCCPlite. So for now, run these only for SCCP/M3UA. */
10978 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
10979 execute( TC_mscpool_L3Compl_on_1_msc() );
10980 execute( TC_mscpool_L3Complete_by_imsi_round_robin() );
10981 execute( TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() );
10982 execute( TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() );
10983 execute( TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() );
10984 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() );
10985 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_1() );
10986 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_2() );
10987 execute( TC_mscpool_LU_by_tmsi_from_other_PLMN() );
10988 execute( TC_mscpool_paging_and_response_imsi() );
10989 execute( TC_mscpool_paging_and_response_tmsi() );
10990 execute( TC_mscpool_no_allow_attach_round_robin() );
10991 execute( TC_mscpool_no_allow_attach_valid_nri() );
10992 }
10993
Harald Welte99f3ca02018-06-14 13:40:29 +020010994 execute( TC_early_conn_fail() );
10995 execute( TC_late_conn_fail() );
Oliver Smithaf03bef2021-08-24 15:34:51 +020010996 execute( TC_stats_conn_fail() );
Harald Welte99f3ca02018-06-14 13:40:29 +020010997
Philipp Maier783681c2020-07-16 16:47:06 +020010998 /* Emergency call handling (deny / allow) */
10999 execute( TC_assignment_emerg_setup_allow() );
11000 execute( TC_assignment_emerg_setup_deny_msc() );
11001 execute( TC_assignment_emerg_setup_deny_bts() );
Philipp Maier82812002020-08-13 18:48:27 +020011002 execute( TC_emerg_premption() );
11003
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +070011004 /* Frequency hopping parameters handling */
11005 execute( TC_fh_params_chan_activ() );
11006 execute( TC_fh_params_imm_ass() );
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +070011007 execute( TC_fh_params_assignment_cmd() );
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +070011008 execute( TC_fh_params_handover_cmd() );
Vadim Yanitskiyca974032020-09-01 07:20:39 +070011009 execute( TC_fh_params_si4_cbch() );
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +020011010
11011 if (mp_enable_lcs_tests) {
11012 execute( TC_lcs_loc_req_for_active_ms() );
11013 execute( TC_lcs_loc_req_for_active_ms_ta_req() );
11014 execute( TC_lcs_loc_req_for_idle_ms() );
11015 execute( TC_lcs_loc_req_no_subscriber() );
11016 execute( TC_lcs_loc_req_for_active_ms_le_timeout() );
11017 execute( TC_lcs_loc_req_for_active_ms_le_timeout2() );
11018 execute( TC_lcs_loc_req_for_idle_ms_no_pag_resp() );
11019 execute( TC_cm_service_during_lcs_loc_req() );
11020 execute( TC_ho_during_lcs_loc_req() );
11021 }
Neels Hofmeyrbf037052020-10-28 22:52:02 +000011022
11023 execute( TC_no_msc() );
Neels Hofmeyr87857ec2021-04-25 16:17:47 +000011024
11025 execute( TC_refuse_chan_act_to_vamos() );
11026 execute( TC_refuse_mode_modif_to_vamos() );
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +000011027
11028 execute( TC_reassignment_fr() );
Neels Hofmeyrfeda88e2021-07-19 13:51:29 +020011029
11030 execute( TC_cm_reestablishment() );
Neels Hofmeyrb07b2952021-08-07 04:23:14 +020011031
11032 execute( TC_imm_ass_post_chan_ack() );
11033 execute( TC_imm_ass_pre_chan_ack() );
Neels Hofmeyr23158742021-09-07 19:08:07 +020011034 execute( TC_imm_ass_pre_ts_ack() );
Neels Hofmeyr7a6d0602021-08-07 04:23:50 +020011035 execute( TC_imm_ass_pre_chan_ack_dyn_ts() );
Neels Hofmeyrc8b95c12021-08-07 04:24:02 +020011036 execute( TC_imm_ass_pre_ts_ack_dyn_ts() );
Neels Hofmeyr5d7d13f2021-09-07 14:44:36 +020011037
11038 execute( TC_ctrl_trx_rf_locked() );
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011039
Neels Hofmeyrbd94fe72021-10-26 22:04:53 +020011040 execute( TC_ratectr_all_available_allocated() );
11041 execute( TC_ratectr_all_available_allocated_dyn() );
11042
Neels Hofmeyrb7581872021-11-07 14:02:49 +010011043 execute( TC_cm_serv_rej() );
11044
Neels Hofmeyr92cfa1c2021-09-28 18:29:44 +020011045 execute( TC_lost_sdcch_during_assignment() );
Neels Hofmeyrafe2ea52021-11-24 15:16:12 +010011046
11047 /* Run TC_ho_out_of_this_bsc last, because it may trigger a segfault before osmo-bsc's patch
11048 * with change-id I5a3345ab0005a73597f5c27207480912a2f5aae6 */
11049 execute( TC_ho_out_of_this_bsc() );
Harald Welte28d943e2017-11-25 15:00:50 +010011050}
11051
11052}