blob: ae805e361cbe2345e3620bea89c7502a6c7437f7 [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
Harald Welte5d1a2202017-12-13 19:51:29 +010078const integer NUM_BTS := 3;
Neels Hofmeyrf246a922020-05-13 02:27:10 +020079const integer NUM_MSC := 3;
Harald Welteae026692017-12-09 01:03:01 +010080const float T3101_MAX := 12.0;
Harald Welte28d943e2017-11-25 15:00:50 +010081
Harald Welte799c97b2017-12-14 17:50:30 +010082/* make sure to sync this with the osmo-bts.cfg you're using */
Philipp Maiercb6cc482018-03-26 13:08:00 +020083const integer NUM_TCHH_PER_BTS := 2;
84const integer NUM_TCHF_PER_BTS := 4;
Neels Hofmeyr74083c22020-07-29 00:43:01 +020085const integer NUM_SDCCH_PER_BTS := 3;
Harald Welte799c97b2017-12-14 17:50:30 +010086
Harald Welte4003d112017-12-09 22:35:39 +010087
Harald Welte21b46bd2017-12-17 19:46:32 +010088/* per-BTS state which we keep */
Harald Welte96c94412017-12-09 03:12:45 +010089type record BTS_State {
Harald Welte21b46bd2017-12-17 19:46:32 +010090 /* component reference to the IPA_Client component used for RSL */
Harald Weltea5d2ab22017-12-09 14:21:42 +010091 IPA_Client rsl
Harald Welte96c94412017-12-09 03:12:45 +010092}
93
Neels Hofmeyr22c3f792020-06-17 02:49:28 +020094/* Default list of counters for an 'msc' entity. */
95const CounterNameVals counternames_msc_mscpool := {
96 { "mscpool:subscr:new", 0 },
97 { "mscpool:subscr:known", 0 },
98 { "mscpool:subscr:reattach", 0 },
99 { "mscpool:subscr:attach_lost", 0 },
100 { "mscpool:subscr:paged", 0 }
101};
102
Neels Hofmeyrbf037052020-10-28 22:52:02 +0000103/* List of global mscpool counters, not related to a specific 'msc' entity. */
104const CounterNameVals counternames_bsc_mscpool := {
105 { "mscpool:subscr:no_msc", 0 }
106};
107
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000108/* Default list of counters for 'bsc' and 'bts' entities. */
109const CounterNameVals counternames_bsc_bts_handover := {
110 { "assignment:attempted", 0 },
111 { "assignment:completed", 0 },
112 { "assignment:stopped", 0 },
113 { "assignment:no_channel", 0 },
114 { "assignment:timeout", 0 },
115 { "assignment:failed", 0 },
116 { "assignment:error", 0 },
117
118 { "handover:attempted", 0 },
119 { "handover:completed", 0 },
120 { "handover:stopped", 0 },
121 { "handover:no_channel", 0 },
122 { "handover:timeout", 0 },
123 { "handover:failed", 0 },
124 { "handover:error", 0 },
125
126 { "intra_cell_ho:attempted", 0 },
127 { "intra_cell_ho:completed", 0 },
128 { "intra_cell_ho:stopped", 0 },
129 { "intra_cell_ho:no_channel", 0 },
130 { "intra_cell_ho:timeout", 0 },
131 { "intra_cell_ho:failed", 0 },
132 { "intra_cell_ho:error", 0 },
133
134 { "intra_bsc_ho:attempted", 0 },
135 { "intra_bsc_ho:completed", 0 },
136 { "intra_bsc_ho:stopped", 0 },
137 { "intra_bsc_ho:no_channel", 0 },
138 { "intra_bsc_ho:timeout", 0 },
139 { "intra_bsc_ho:failed", 0 },
140 { "intra_bsc_ho:error", 0 },
141
142 { "interbsc_ho_out:attempted", 0 },
143 { "interbsc_ho_out:completed", 0 },
144 { "interbsc_ho_out:stopped", 0 },
145 { "interbsc_ho_out:timeout", 0 },
146 { "interbsc_ho_out:failed", 0 },
147 { "interbsc_ho_out:error", 0 },
148
149 { "interbsc_ho_in:attempted", 0 },
150 { "interbsc_ho_in:completed", 0 },
151 { "interbsc_ho_in:stopped", 0 },
152 { "interbsc_ho_in:no_channel", 0 },
153 { "interbsc_ho_in:timeout", 0 },
154 { "interbsc_ho_in:failed", 0 },
155 { "interbsc_ho_in:error", 0 }
156};
157
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200158/* Set of all System Information received during one RSL port's startup.
159 * Note that some System Information may be sent on RSL, but lacking actual SI data, to indicate that the BTS should not
160 * broadcast that SI type. That will be reflected as 'omit' here.
161 */
162type record SystemInformationConfig {
163 SystemInformationType1 si1 optional,
164 SystemInformationType2 si2 optional,
165 SystemInformationType2bis si2bis optional,
166 SystemInformationType2ter si2ter optional,
Neels Hofmeyrad132f22020-07-08 02:20:16 +0200167 SI2quaterRestOctetsList si2quater optional,
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200168 SystemInformationType3 si3 optional,
169 SystemInformationType4 si4 optional,
Pau Espin Pedrol28652d82021-02-09 20:20:17 +0100170 SystemInformationType13 si13 optional,
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200171 SystemInformationType5 si5 optional,
172 SystemInformationType5bis si5bis optional,
173 SystemInformationType5ter si5ter optional,
174 SystemInformationType6 si6 optional
175};
176
177const SystemInformationConfig SystemInformationConfig_omit := {
178 si1 := omit,
179 si2 := omit,
180 si2bis := omit,
181 si2ter := omit,
182 si2quater := omit,
183 si3 := omit,
184 si4 := omit,
185 si13 := omit,
186 si5 := omit,
187 si5bis := omit,
188 si5ter := omit,
189 si6 := omit
190};
191
192/* tr_EUTRAN_CellDesc with defaults used in BSC_Tests.ttcn */
193template EUTRAN_CellDesc tr_EUTRAN_CellDesc_default(template (present) uint16_t e_arfcn := ?,
194 template uint3_t meas_bw := 3)
195:= tr_EUTRAN_CellDesc(e_arfcn := e_arfcn,
196 meas_bw_presence := '1'B,
197 meas_bw := meas_bw);
198
199/* tr_EUTRAN_NeighbourCells with defaults used in BSC_Tests.ttcn */
Harald Welte65e419a2020-08-21 12:38:33 +0200200template EUTRAN_NeighbourCells tr_EUTRAN_NeighbourCells_default(template (present) EUTRAN_CellDescs cell_desc_list := { tr_EUTRAN_CellDesc_default },
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200201 template uint3_t prio := 3,
202 template (present) uint5_t thresh_high := 20,
203 template uint5_t thresh_low := 10,
204 template uint5_t qrxlevmin := 22)
205:= tr_EUTRAN_NeighbourCells(
206 cell_desc_list := cell_desc_list,
207 prio_presence := '1'B,
208 prio := prio,
209 thresh_high := thresh_high,
210 thresh_low_presence := '1'B,
211 thresh_low := thresh_low,
212 qrxlevmin_presence := '1'B,
213 qrxlevmin := qrxlevmin);
214
215template SystemInformationConfig SystemInformationConfig_default := {
216 si1 := {
217 cell_chan_desc := '8FB38000000000000000000000000000'O,
218 rach_control := {
219 max_retrans := RACH_MAX_RETRANS_7,
220 tx_integer := '1001'B,
221 cell_barr_access := false,
222 re_not_allowed := true,
223 acc := '0000010000000000'B
224 },
225 rest_octets := ?
226 },
227 si2 := {
228 bcch_freq_list := '00000000000000000000000000000000'O,
229 ncc_permitted := '11111111'B,
230 rach_control := {
231 max_retrans := RACH_MAX_RETRANS_7,
232 tx_integer := '1001'B,
233 cell_barr_access := false,
234 re_not_allowed := true,
235 acc := '0000010000000000'B
236 }
237 },
238 si2bis := omit,
239 si2ter := {
240 extd_bcch_freq_list := '8E320000000000000000000000000800'O,
241 rest_octets := ?
242 },
243 si2quater := {
244 tr_SI2quaterRestOctets_EUTRAN( repeated_neigh_cells := { tr_EUTRAN_NeighbourCells_default } )
245 },
246 si3 := {
247 cell_id := 0,
248 lai := {
249 mcc_mnc := '001F01'H,
250 lac := 1
251 },
252 ctrl_chan_desc := {
253 msc_r99 := true,
254 att := true,
255 bs_ag_blks_res := 1,
256 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
257 si22ind := false,
258 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
259 spare := '00'B,
260 bs_pa_mfrms := 3,
261 t3212 := 30
262 },
263 cell_options := {
264 dn_ind := false,
265 pwrc := false,
266 dtx := MS_SHALL_USE_UL_DTX,
267 radio_link_tout_div4 := 7
268 },
269 cell_sel_par := {
270 cell_resel_hyst_2dB := 2,
271 ms_txpwr_max_cch := 7,
272 acs := '0'B,
273 neci := true,
274 rxlev_access_min := 0
275 },
276 rach_control := {
277 max_retrans := RACH_MAX_RETRANS_7,
278 tx_integer := '1001'B,
279 cell_barr_access := false,
280 re_not_allowed := true,
281 acc := '0000010000000000'B
282 },
283 rest_octets := {
284 sel_params := {
285 presence := '0'B,
286 params := omit
287 },
288 pwr_offset := {
289 presence := '0'B,
290 offset := omit
291 },
292 si_2ter_ind := '1'B,
293 early_cm_ind := '0'B,
294 sched_where := {
295 presence := '0'B,
296 where := omit
297 },
298 gprs_ind := {
299 presence := '1'B,
300 ind := {
301 ra_colour := 0,
302 si13_pos := '0'B
303 }
304 },
305 umts_early_cm_ind := '1'B,
306 si2_quater_ind := {
307 presence := '1'B,
308 ind := '0'B
309 },
310 iu_mode_ind := omit,
311 si21_ind := {
312 presence := '0'B,
313 pos := omit
314 }
315 }
316 },
317 si4 := {
318 lai := {
319 mcc_mnc := '001F01'H,
320 lac := 1
321 },
322 cell_sel_par := {
323 cell_resel_hyst_2dB := 2,
324 ms_txpwr_max_cch := 7,
325 acs := '0'B,
326 neci := true,
327 rxlev_access_min := 0
328 },
329 rach_control := {
330 max_retrans := RACH_MAX_RETRANS_7,
331 tx_integer := '1001'B,
332 cell_barr_access := false,
333 re_not_allowed := true,
334 acc := '0000010000000000'B
335 },
Neels Hofmeyr74083c22020-07-29 00:43:01 +0200336 cbch_chan_desc := {
337 iei := '64'O,
338 v := {
339 chan_nr := {
340 u := {
341 sdcch4 := {
342 tag := '001'B,
343 sub_chan := 2
344 }
345 },
346 tn := 0
347 },
348 tsc := 2,
349 h := false,
350 arfcn := 871,
351 maio_hsn := omit
352 }
353 },
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200354 cbch_mobile_alloc := omit,
355 rest_octets := {
356 sel_params := {
357 presence := '0'B,
358 params := omit
359 },
360 pwr_offset := {
361 presence := '0'B,
362 offset := omit
363 },
364 gprs_ind := {
365 presence := '1'B,
366 ind := {
367 ra_colour := 0,
368 si13_pos := '0'B
369 }
370 },
371 s_presence := '0'B,
372 s := omit
373 }
374 },
Pau Espin Pedrol28652d82021-02-09 20:20:17 +0100375 si13 := {
376 rest_octets := {
377 presence := '1'B,
378 bcch_change_mark := ?,
379 si_change_field := '0000'B,
380 presence2 := '0'B,
381 si13_change_mark := omit,
382 gprs_ma := omit,
383 zero := '0'B, /* PBCCH not present in cell */
384 rac := 0,
385 spgc_ccch_sup := '0'B,
386 priority_access_thr := '110'B,
387 network_control_order := '00'B,
388 gprs_cell_opts := {
389 nmo := '01'B,
390 t3168 := '011'B,
391 t3192 := '010'B,
392 drx_timer_max := '011'B,
393 access_burst_type := '0'B,
394 control_ack_type := '1'B,
395 bs_cv_max := 15,
396 pan_presence := '1'B,
397 pan_dec := 1,
398 pan_inc := 1,
399 pan_max := '111'B,
400 ext_info_presence := ?,
401 ext_info_length := *,
402 ext_info := *
403 },
404 gprs_pwr_ctrl_params := {
405 alpha := 0,
406 t_avg_w := '10000'B,
407 t_avg_t := '10000'B,
408 pc_meas_chan := '0'B,
409 n_avg_i := '1000'B
410 }
411 }
412 },
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200413 si5 := {
414 bcch_freq_list := '10000000000000000000000000000000'O
415 },
416 si5bis := omit,
417 si5ter := {
418 extd_bcch_freq_list := '9E050020000000000000000000000000'O
419 },
420 si6 := {
421 cell_id := 0,
422 lai := {
423 mcc_mnc := '001F01'H,
424 lac := 1
425 },
426 cell_options := {
427 dtx_ext := '1'B,
428 pwrc := false,
429 dtx := '01'B,
430 radio_link_timeout := '0111'B
431 },
432 ncc_permitted := '11111111'B,
433 rest_octets := ?
434 }
435 };
436
437
438/* List of all the System Information received on all RSL ports */
439type record of SystemInformationConfig SystemInformationConfig_list;
440
441function f_sysinfo_dec_raw(inout SystemInformationConfig si, RSL_Message rsl)
442{
443 var RSL_IE_Body sysinfo_type_ie;
444 var RSL_IE_SysinfoType si_type;
445 var octetstring data;
446
447 if (f_rsl_find_ie(rsl, RSL_IE_SYSINFO_TYPE, sysinfo_type_ie) == false) {
448 setverdict(fail, "Cannot find RSL_IE_SYSINFO_TYPE");
449 mtc.stop;
450 }
451 si_type := sysinfo_type_ie.sysinfo_type;
452
453 if (rsl.msg_type == RSL_MT_BCCH_INFO) {
454 var RSL_IE_Body bcch_ie;
455 if (f_rsl_find_ie(rsl, RSL_IE_FULL_BCCH_INFO, bcch_ie)) {
456 data := bcch_ie.other.payload;
457 }
458 } else if (rsl.msg_type == RSL_MT_SACCH_FILL) {
459 var RSL_IE_Body l3_ie;
460 if (f_rsl_find_ie(rsl, RSL_IE_L3_INFO, l3_ie)) {
461 data := l3_ie.l3_info.payload;
462 }
463 } else {
464 setverdict(fail, "Don't understand this System Information message");
465 mtc.stop;
466 }
467
468 var boolean handled := false;
469
470 if (rsl.msg_type == RSL_MT_BCCH_INFO) {
471 handled := true;
472
473 if (si_type == RSL_SYSTEM_INFO_1) {
474 if (not isbound(data)) {
475 si.si1 := omit;
476 } else {
477 si.si1 := dec_SystemInformation(data).payload.si1;
478 }
479 } else if (si_type == RSL_SYSTEM_INFO_2) {
480 if (not isbound(data)) {
481 si.si2 := omit;
482 } else {
483 si.si2 := dec_SystemInformation(data).payload.si2;
484 }
485 } else if (si_type == RSL_SYSTEM_INFO_2bis) {
486 if (not isbound(data)) {
487 si.si2bis := omit;
488 } else {
489 si.si2bis := dec_SystemInformation(data).payload.si2bis;
490 }
491 } else if (si_type == RSL_SYSTEM_INFO_2ter) {
492 if (not isbound(data)) {
493 si.si2ter := omit;
494 } else {
495 si.si2ter := dec_SystemInformation(data).payload.si2ter;
496 }
497 } else if (si_type == RSL_SYSTEM_INFO_2quater) {
498 if (not isbound(data)) {
499 si.si2quater := {};
500 } else {
501 var SystemInformationType2quater decoded := dec_SystemInformation(data).payload.si2quater;
502 /* this is a *record* of SI2quaterRestOctets! (multiplexed) */
503 si.si2quater[decoded.rest_octets.si2quater_index] := decoded.rest_octets;
504 }
505 } else if (si_type == RSL_SYSTEM_INFO_3) {
506 if (not isbound(data)) {
507 si.si3 := omit;
508 } else {
509 si.si3 := dec_SystemInformation(data).payload.si3;
510 }
511 } else if (si_type == RSL_SYSTEM_INFO_4) {
512 if (not isbound(data)) {
513 si.si4 := omit;
514 } else {
515 si.si4 := dec_SystemInformation(data).payload.si4;
516 }
517 } else if (si_type == RSL_SYSTEM_INFO_13) {
518 if (not isbound(data)) {
519 si.si13 := omit;
520 } else {
Pau Espin Pedrol28652d82021-02-09 20:20:17 +0100521 si.si13 := dec_SystemInformation(data).payload.si13;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200522 }
523 } else {
524 handled := false;
525 }
526 } else if (rsl.msg_type == RSL_MT_SACCH_FILL) {
527 handled := true;
528
529 if (si_type == RSL_SYSTEM_INFO_5) {
530 if (not isbound(data)) {
531 si.si5 := omit;
532 } else {
533 si.si5 := dec_SystemInformation(data).payload.si5;
534 }
535 } else if (si_type == RSL_SYSTEM_INFO_5bis) {
536 if (not isbound(data)) {
537 si.si5bis := omit;
538 } else {
539 si.si5bis := dec_SystemInformation(data).payload.si5bis;
540 }
541 } else if (si_type == RSL_SYSTEM_INFO_5ter) {
542 if (not isbound(data)) {
543 si.si5ter := omit;
544 } else {
545 si.si5ter := dec_SystemInformation(data).payload.si5ter;
546 }
547 } else if (si_type == RSL_SYSTEM_INFO_6) {
548 if (not isbound(data)) {
549 si.si6 := omit;
550 } else {
551 si.si6 := dec_SystemInformation(data).payload.si6;
552 }
553 } else {
554 handled := false;
555 }
556 }
557
558 if (not handled) {
559 setverdict(fail, "Unexpected SI type in ", rsl.msg_type, " message: ", si_type);
560 }
561}
562
Harald Weltea4ca4462018-02-09 00:17:14 +0100563type component test_CT extends CTRL_Adapter_CT {
Harald Welte21b46bd2017-12-17 19:46:32 +0100564 /* Array of per-BTS state */
Harald Welte96c94412017-12-09 03:12:45 +0100565 var BTS_State bts[NUM_BTS];
Harald Welte89ab1912018-02-23 18:56:29 +0100566 /* RSL common Channel Port (for RSL_Emulation) */
567 port RSL_CCHAN_PT RSL_CCHAN[NUM_BTS];
Harald Welte21b46bd2017-12-17 19:46:32 +0100568 /* array of per-BTS RSL test ports */
Harald Welteae026692017-12-09 01:03:01 +0100569 port IPA_RSL_PT IPA_RSL[NUM_BTS];
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100570 port IPA_CODEC_PT IPA; /* Required for compilation of TC_rsl_unknown_unit_id() */
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +0200571 /* CTRL muxed over IPA in SCCPlite conn BSC<->MSC (or BSC-NAT) */
572 port IPA_CTRL_PT SCCPLITE_IPA_CTRL;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100573
Daniel Willmann191e0d92018-01-17 12:44:35 +0100574 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +0100575 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100576
Daniel Willmannebdecc02020-08-12 15:30:17 +0200577 /* StatsD */
578 var StatsD_Checker_CT vc_STATSD;
579
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200580 var RAN_Adapter g_bssap[NUM_MSC];
Harald Welte47cd0e32020-08-21 12:39:11 +0200581 var BSSAP_LE_Adapter g_bssap_le;
Harald Weltea4ca4462018-02-09 00:17:14 +0100582 /* for old legacy-tests only */
583 port BSSAP_CODEC_PT BSSAP;
Harald Welte47cd0e32020-08-21 12:39:11 +0200584 port BSSAP_LE_CODEC_PT BSSAP_LE;
Harald Weltea4ca4462018-02-09 00:17:14 +0100585
Harald Welte21b46bd2017-12-17 19:46:32 +0100586 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +0100587 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +0100588
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200589 /* Osmux is enabled through VTY */
590 var boolean g_osmux_enabled := false;
591
Pau Espin Pedrolc675b612020-01-09 19:55:40 +0100592 /*Configure T(tias) over VTY, seconds */
593 var integer g_bsc_sccp_timer_ias := 7 * 60;
594 /*Configure T(tiar) over VTY, seconds */
595 var integer g_bsc_sccp_timer_iar := 15 * 60;
596
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +0200597 /* global test case guard timer (actual timeout value is set in f_init()) */
Harald Welteae026692017-12-09 01:03:01 +0100598 timer T_guard := 30.0;
599
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200600 var CounterNameValsList g_ctr_msc;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000601 var CounterNameValsList g_ctr_bsc;
602 var CounterNameValsList g_ctr_bts;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200603
604 /* System Information bytes as received during RSL startup, for each RSL[idx]. */
605 var SystemInformationConfig_list g_system_information := {};
Harald Welte28d943e2017-11-25 15:00:50 +0100606}
607
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200608type record of charstring phys_chan_configs;
Harald Welte28d943e2017-11-25 15:00:50 +0100609modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +0100610 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +0100611 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100612 /* port number to which to establish the IPA OML connections */
613 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +0100614 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +0100615 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +0100616 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +0100617 integer mp_bsc_ctrl_port := 4249;
Daniel Willmannebdecc02020-08-12 15:30:17 +0200618 /* port number to which to listen for STATSD metrics */
619 integer mp_bsc_statsd_port := 8125;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100620 /* IP address at which the test binds */
621 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100622
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200623 RAN_Configurations mp_bssap_cfg := {
624 {
625 transport := BSSAP_TRANSPORT_AoIP,
626 sccp_service_type := "mtp3_itu",
627 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
628 own_pc := 185, /* 0.23.1 first MSC emulation */
629 own_ssn := 254,
630 peer_pc := 187, /* 0.23.3 osmo-bsc */
631 peer_ssn := 254,
632 sio := '83'O,
Harald Weltecb0cc432020-06-21 19:42:31 +0200633 rctx := 1
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200634 },
635 {
636 transport := BSSAP_TRANSPORT_AoIP,
637 sccp_service_type := "mtp3_itu",
638 sctp_addr := { 23906, "127.0.0.1", 2905, "127.0.0.1" },
639 own_pc := 2, /* 0.0.2 second MSC emulation */
640 own_ssn := 254,
641 peer_pc := 187, /* 0.23.3 osmo-bsc */
642 peer_ssn := 254,
643 sio := '83'O,
644 rctx := 2
645 },
646 {
647 transport := BSSAP_TRANSPORT_AoIP,
648 sccp_service_type := "mtp3_itu",
649 sctp_addr := { 23907, "127.0.0.1", 2905, "127.0.0.1" },
650 own_pc := 3, /* 0.0.3 third MSC emulation */
651 own_ssn := 254,
652 peer_pc := 187, /* 0.23.3 osmo-bsc */
653 peer_ssn := 254,
654 sio := '83'O,
655 rctx := 3
656 }
Harald Weltea4ca4462018-02-09 00:17:14 +0100657 };
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +0200658
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200659 /* Must match per BTS config in osmo-bsc.cfg */
660 phys_chan_configs phys_chan_config := {
661 "CCCH+SDCCH4+CBCH",
662 "TCH/F",
663 "TCH/F",
664 "TCH/F",
665 "TCH/F",
Vadim Yanitskiy343c9eb2021-07-16 18:36:01 +0600666 "TCH/H",
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +0200667 "PDCH",
668 "PDCH"
669 };
670
Harald Welte47cd0e32020-08-21 12:39:11 +0200671 BSSAP_LE_Configuration mp_bssap_le_cfg := {
672 sccp_service_type := "mtp3_itu",
673 sctp_addr := { 23908, "127.0.0.1", 2905, "127.0.0.1" },
Neels Hofmeyrac086c12020-09-18 23:46:42 +0200674 own_pc := 190, /* 0.23.6 SMLC emulation */
Harald Welte47cd0e32020-08-21 12:39:11 +0200675 own_ssn := 252, /* SMLC side SSN */
676 peer_pc := 187, /* 0.23.3 osmo-bsc */
677 peer_ssn := 250, /* BSC side SSN */
678 sio := '83'O,
679 rctx := 6
680 };
Neels Hofmeyrcfe44062020-10-15 02:28:08 +0200681 boolean mp_enable_lcs_tests := true;
Harald Welte47cd0e32020-08-21 12:39:11 +0200682
Pau Espin Pedrole076b3f2021-07-20 16:45:57 +0200683 /* Whether to enable dyn TS SDCCH8 tests. Can be dropped completely and enable
684 unconditionally once new version of osmo-bsc is released (current
685 version: 1.7.0) */
686 boolean mp_enable_dyn_sdcch8_test := true;
Pau Espin Pedrol8f30ccd2019-11-01 17:30:57 +0100687 /* Value set in osmo-bsc.cfg "ms max power" */
688 uint8_t mp_exp_ms_power_level := 7;
Harald Weltea4ca4462018-02-09 00:17:14 +0100689}
690
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +0200691friend function f_gen_test_hdlr_pars(integer bssap_idx := 0) return TestHdlrParams {
Philipp Maier48604732018-10-09 15:00:37 +0200692
693 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200694 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier48604732018-10-09 15:00:37 +0200695 pars.aoip := true;
696 } else {
697 pars.aoip := false;
698 }
Pau Espin Pedrol8f30ccd2019-11-01 17:30:57 +0100699 pars.exp_ms_power_level := mp_exp_ms_power_level;
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200700 pars.mscpool.bssap_idx := bssap_idx;
Philipp Maier48604732018-10-09 15:00:37 +0200701
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200702 /* BTS 0 has BSIC 10 (and no explicit timeslot training_sequence_code config), so expecting TSC = (BSIC & 7) = 2 */
703 pars.expect_tsc := 2;
704
Philipp Maier48604732018-10-09 15:00:37 +0200705 return pars;
706}
707
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200708/* Convenience functions for rate counters using g_ctr_msc. */
709
710private function f_ctrs_msc_init(integer mscs_count := NUM_MSC, CounterNameVals counternames := counternames_msc_mscpool) runs on test_CT {
711 g_ctr_msc := f_counter_name_vals_get_n(IPA_CTRL, "msc", mscs_count, counternames);
712 log("initial msc rate counters: ", g_ctr_msc);
713}
714
715private function f_ctrs_msc_add(integer msc_nr, charstring countername, integer val := 1) runs on test_CT {
Neels Hofmeyr9656e922020-06-30 01:27:01 +0200716 f_counter_name_vals_list_add(g_ctr_msc, msc_nr, countername, val);
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200717}
718
719/* f_ctrs_msc_init();
720 * f_do_thing(on_msc := 0);
721 * f_do_thing(on_msc := 0);
722 * f_do_other(on_msc := 1);
723 * f_ctrs_msc_add(0, "thing", 2);
724 * f_ctrs_msc_add(1, "other");
725 * f_ctrs_msc_verify();
726 */
727private function f_ctrs_msc_verify() runs on test_CT {
728 log("verifying msc rate counters: ", g_ctr_msc);
729 f_counter_name_vals_expect_n(IPA_CTRL, "msc", g_ctr_msc);
730}
731
732/* convenience: f_ctrs_msc_add() and f_ctrs_msc_verify() in one call.
733 * f_ctrs_msc_init();
734 * f_do_thing(on_msc := 0);
735 * f_do_thing(on_msc := 0);
736 * f_do_thing(on_msc := 0);
737 * f_ctrs_msc_expect(0, "thing", 3);
738 */
739private function f_ctrs_msc_expect(integer msc_nr, charstring countername, integer val := 1) runs on test_CT {
740 f_ctrs_msc_add(msc_nr, countername, val);
741 f_ctrs_msc_verify();
742}
743
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000744/* Convenience functions for rate counters using g_ctr_bts, always also including g_ctr_bsc. */
745
746private function f_ctrs_bsc_and_bts_init(integer bts_count := NUM_BTS, CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
747 g_ctr_bts := f_counter_name_vals_get_n(IPA_CTRL, "bts", bts_count, counternames);
748 log("initial bts rate counters: ", g_ctr_bts);
749 f_ctrs_bsc_init(counternames);
750}
751
752private function f_ctrs_bsc_and_bts_add(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
753 f_counter_name_vals_list_add(g_ctr_bts, bts_nr, countername, val);
754 f_ctrs_bsc_add(countername, val);
755}
756
757/* f_ctrs_bsc_and_bts_init();
758 * f_do_thing(on_bts := 0);
759 * f_do_thing(on_bts := 0);
760 * f_do_other(on_bts := 1);
761 * f_ctrs_bsc_and_bts_add(0, "thing", 2);
762 * f_ctrs_bsc_and_bts_add(1, "other");
763 * f_ctrs_bsc_and_bts_verify();
764 */
765private function f_ctrs_bsc_and_bts_verify() runs on test_CT {
766 f_counter_name_vals_expect_n(IPA_CTRL, "bts", g_ctr_bts);
767 f_ctrs_bsc_verify();
768}
769
770/* convenience: f_ctrs_bsc_and_bts_add() and f_ctrs_bsc_and_bts_verify() in one call.
771 * f_ctrs_bsc_and_bts_init();
772 * f_do_thing(on_bts := 0);
773 * f_do_thing(on_bts := 0);
774 * f_do_thing(on_bts := 0);
775 * f_ctrs_bsc_and_bts_expect(0, "thing", 3);
776 */
777private function f_ctrs_bsc_and_bts_expect(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
778 f_ctrs_bsc_and_bts_add(bts_nr, countername, val);
779 f_ctrs_bsc_and_bts_verify();
780}
781
782
783/* Convenience functions for rate counters using g_ctr_bsc. */
784
785private function f_ctrs_bsc_init(CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
786 g_ctr_bsc := f_counter_name_vals_get_n(IPA_CTRL, "bsc", 1, counternames);
787 log("initial bsc rate counters: ", g_ctr_bsc);
788}
789
790private function f_ctrs_bsc_add(charstring countername, integer val := 1) runs on test_CT {
791 f_counter_name_vals_list_add(g_ctr_bsc, 0, countername, val);
792}
793
794/* f_ctrs_bsc_init();
795 * f_do_thing();
796 * f_do_thing();
797 * f_do_other();
798 * f_ctrs_bsc_add("thing", 2);
799 * f_ctrs_bsc_add("other");
800 * f_ctrs_bsc_verify();
801 */
802private function f_ctrs_bsc_verify() runs on test_CT {
803 f_counter_name_vals_expect_n(IPA_CTRL, "bsc", g_ctr_bsc);
804}
805
806/* convenience: f_ctrs_bsc_add() and f_ctrs_bsc_verify() in one call.
807 * f_ctrs_bsc_init();
808 * f_do_thing();
809 * f_ctrs_bsc_expect("thing", 1);
810 */
811private function f_ctrs_bsc_expect(charstring countername, integer val := 1) runs on test_CT {
812 f_ctrs_bsc_add(countername, val);
813 f_ctrs_bsc_verify();
814}
815
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200816
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +0200817friend function f_shutdown_helper() runs on test_CT {
Daniel Willmann637ef6c2018-07-25 10:49:09 +0200818 all component.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100819 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200820 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100821}
822
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200823private function f_legacy_bssap_reset(integer bssap_idx := 0) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +0100824 var BSSAP_N_UNITDATA_ind ud_ind;
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200825 var boolean reset_received := false;
Harald Weltea4ca4462018-02-09 00:17:14 +0100826 timer T := 5.0;
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200827 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
828 ts_BSSMAP_Reset(0, g_osmux_enabled)));
Harald Weltea4ca4462018-02-09 00:17:14 +0100829 T.start;
830 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200831 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap[bssap_idx].sccp_addr_own, g_bssap[bssap_idx].sccp_addr_peer,
832 tr_BSSMAP_ResetAck(g_osmux_enabled))) {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200833 log("BSSMAP: Received RESET-ACK in response to RESET, we're ready to go!");
Harald Weltea4ca4462018-02-09 00:17:14 +0100834 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200835 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200836 log("BSSMAP: Respoding to inbound RESET with RESET-ACK");
Harald Weltea4ca4462018-02-09 00:17:14 +0100837 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200838 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200839 reset_received := true;
Harald Weltea4ca4462018-02-09 00:17:14 +0100840 repeat;
841 }
842 [] BSSAP.receive { repeat; }
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200843 [] T.timeout {
Neels Hofmeyr4f5d7be2020-10-16 16:28:16 +0200844 log("BSSMAP: Timeout waiting for RESET-ACK after sending RESET");
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200845 /* If we received a RESET after ours was sent, it
846 may be a race condition where the other peer beacame
847 available after we sent it, but we are in a desired
848 state anyway, so go forward. */
849 if (not reset_received) {
850 setverdict(fail);
851 }
852 }
Harald Weltea4ca4462018-02-09 00:17:14 +0100853 }
Harald Welte28d943e2017-11-25 15:00:50 +0100854}
855
Harald Welteae026692017-12-09 01:03:01 +0100856type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100857 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100858 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100859 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100860 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100861 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100862 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100863 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100864 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100865}
866
Harald Welte21b46bd2017-12-17 19:46:32 +0100867/*! Start the IPA/RSL related bits for one IPA_Client.
868 * \param clnt IPA_Client for which to establish
869 * \param bsc_host IP address / hostname of the BSC
870 * \param bsc_port TCP port number of the BSC
871 * \param i number identifying this BTS
872 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100873function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
874 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100875runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100876 timer T := 10.0;
877
Harald Welte96c94412017-12-09 03:12:45 +0100878 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welteae026692017-12-09 01:03:01 +0100879 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA");
880 clnt.ccm_pars := c_IPA_default_ccm_pars;
881 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
882 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100883 if (handler_mode) {
884 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL");
Harald Welte89ab1912018-02-23 18:56:29 +0100885 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100886 }
Harald Welteae026692017-12-09 01:03:01 +0100887
888 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Harald Welte624f9632017-12-16 19:26:04 +0100889 if (handler_mode) {
890 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
891 } else {
892 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
893 }
Harald Welteae026692017-12-09 01:03:01 +0100894
Harald Welte5d1a2202017-12-13 19:51:29 +0100895 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100896 if (handler_mode) {
897 clnt.vc_RSL.start(RSL_Emulation.main());
898 return;
899 }
Harald Welteae026692017-12-09 01:03:01 +0100900
901 /* wait for IPA RSL link to connect and send ID ACK */
902 T.start;
903 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700904 [] IPA_RSL[i].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) {
Harald Welteae026692017-12-09 01:03:01 +0100905 T.stop;
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +0700906 IPA_RSL[i].send(ts_ASP_RSL_UD(ts_RSL_PAGING_LOAD_IND(23)));
Harald Welteae026692017-12-09 01:03:01 +0100907 }
Harald Welte60e823a2017-12-10 14:10:59 +0100908 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100909 [] IPA_RSL[i].receive { repeat }
910 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100911 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200912 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100913 }
914 }
915}
916
Harald Welte12055472018-03-17 20:10:08 +0100917function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
918 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
919 return;
920 }
921 clnt.vc_IPA.stop;
922 if (isbound(clnt.vc_RSL)) {
923 clnt.vc_RSL.stop;
924 }
925}
926
Harald Welte21b46bd2017-12-17 19:46:32 +0100927/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100928function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
929 timer T := secs_max;
930 T.start;
931 while (true) {
932 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
933 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100934 /* the 'degraded' state exists from OML connection time, and we have to wait
935 * until all MO's are initialized */
936 T.start(1.0);
937 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100938 return;
939 }
Harald Weltef0d6ac62017-12-17 17:02:21 +0100940 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100941 if (not T.running) {
Max99253902018-11-16 17:57:39 +0100942 setverdict(fail, "Timeout waiting for BTS" & int2str(bts_nr) & " oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +0200943 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100944 }
945 }
946}
947
Harald Welte21b46bd2017-12-17 19:46:32 +0100948/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +0100949altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +0100950 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100951 [] T_guard.timeout {
952 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +0200953 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100954 }
Harald Welte60e823a2017-12-10 14:10:59 +0100955 /* always respond with RESET ACK to RESET */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200956 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Welte60e823a2017-12-10 14:10:59 +0100957 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200958 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Welte69c1c262017-12-13 21:02:08 +0100959 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +0100960 }
Harald Welte28d943e2017-11-25 15:00:50 +0100961}
962
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100963altstep no_bssmap_reset() runs on test_CT {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200964 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100965 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +0200966 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100967 }
968}
969
Daniel Willmann191e0d92018-01-17 12:44:35 +0100970function f_init_mgcp(charstring id) runs on test_CT {
971 id := id & "-MGCP";
972
973 var MGCPOps ops := {
974 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
975 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
976 };
977 var MGCP_conn_parameters mgcp_pars := {
978 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +0100979 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +0100980 mgw_ip := mp_test_ip,
Pau Espin Pedrol1a026a52019-06-18 17:21:52 +0200981 mgw_udp_port := 2427,
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200982 /* Enable it for SCCPlite, since we have 2 MGCP sockets towards MGW (UDP one +
983 the on with MGCP over IPA forwarded from MSC one) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200984 multi_conn_mode := (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER)
Daniel Willmann191e0d92018-01-17 12:44:35 +0100985 };
986
987 vc_MGCP := MGCP_Emulation_CT.create(id);
988 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
989}
990
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200991/* Enable or disable (current default) Osmux. When enabling, BSSMAP Reset
992 * contains extra IE (OsmuxSupport) and osmo-bsc will handle AssignReq with
993 * OsmuxCID IE.
994 */
995private function f_vty_allow_osmux(boolean allow) runs on test_CT {
996 f_vty_enter_cfg_msc(BSCVTY, 0);
997 if (allow) {
998 f_vty_transceive(BSCVTY, "osmux on");
999 } else {
1000 f_vty_transceive(BSCVTY, "osmux off");
1001 }
1002 f_vty_transceive(BSCVTY, "exit");
1003 f_vty_transceive(BSCVTY, "exit");
1004 g_osmux_enabled := allow;
1005}
1006
Max2253c0b2018-11-06 19:28:05 +01001007function f_init_vty(charstring id := "foo") runs on test_CT {
Harald Welte94e0c342018-04-07 11:33:23 +02001008 if (BSCVTY.checkstate("Mapped")) {
1009 /* skip initialization if already executed once */
1010 return;
1011 }
Harald Weltebc03c762018-02-12 18:09:38 +01001012 map(self:BSCVTY, system:BSCVTY);
1013 f_vty_set_prompts(BSCVTY);
1014 f_vty_transceive(BSCVTY, "enable");
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01001015 f_cs7_inst_0_cfg(BSCVTY, {"sccp-timer ias " & int2str(g_bsc_sccp_timer_ias),
1016 "sccp-timer iar " & int2str(g_bsc_sccp_timer_iar)});
Harald Weltebc03c762018-02-12 18:09:38 +01001017}
1018
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +02001019friend function f_logp(TELNETasp_PT pt, charstring log_msg)
Neels Hofmeyr4f118412020-06-04 15:25:10 +02001020{
1021 // log on TTCN3 log output
1022 log(log_msg);
1023 // log in stderr log
Neels Hofmeyr767548a2020-08-09 20:26:07 +00001024 f_vty_transceive(pt, "logp lglobal notice TTCN3 f_logp(): " & log_msg);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02001025}
1026
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001027private function f_sysinfo_seen(integer rsl_idx, RSL_Message rsl) runs on test_CT
1028{
1029 if (rsl_idx >= lengthof(g_system_information)) {
1030 g_system_information[rsl_idx] := SystemInformationConfig_omit
1031 }
1032 f_sysinfo_dec_raw(g_system_information[rsl_idx], rsl);
1033}
1034
1035altstep as_catch_RSL_sysinfo(integer rsl_idx) runs on test_CT {
1036 var ASP_RSL_Unitdata rx_rsl_ud;
1037
1038 /* For handler_mode := false, receiving the RSL bootstrap messages directly on IPA_RSL */
1039 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
1040 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1041 repeat;
1042 }
1043 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
1044 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1045 repeat;
1046 }
1047 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> value rx_rsl_ud {
1048 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1049 repeat;
1050 }
1051 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_SACCH_FILL)) -> value rx_rsl_ud {
1052 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1053 repeat;
1054 }
1055
1056 /* For handler_mode := true, receiving the RSL bootstrap messages via RSL_Emulation */
1057 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
1058 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1059 repeat;
1060 }
1061 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
1062 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1063 repeat;
1064 }
1065 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> value rx_rsl_ud {
1066 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1067 repeat;
1068 }
1069 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_SACCH_FILL)) -> value rx_rsl_ud {
1070 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
1071 repeat;
1072 }
1073}
1074
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001075/* TODO: use BooleanList from COMMON/src/General_Types.ttcn */
1076private type record of boolean my_BooleanList;
1077
1078private function f_vty_msc_allow_attach(TELNETasp_PT pt, my_BooleanList allow_attach_list)
1079{
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001080 var charstring config := f_vty_transceive_ret(pt, "show running-config");
1081
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001082 for (var integer msc_nr := 0; msc_nr < sizeof(allow_attach_list); msc_nr := msc_nr+1) {
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001083 if (f_strstr(config, "\nmsc " & int2str(msc_nr) & "\n") < 0) {
1084 /* There is no 'msc N' for this msc_nr in the running config, so don't create an empty msc by
1085 * stepping into that config node. */
1086 log("msc ", msc_nr, " is not configured, skipping");
1087 continue;
1088 }
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001089 f_vty_enter_cfg_msc(pt, msc_nr);
1090 if (allow_attach_list[msc_nr]) {
1091 /* strict := false: ignore if osmo-bsc does not support this config option (latest build) */
1092 f_vty_transceive(pt, "allow-attach", strict := false);
1093 } else {
1094 f_vty_transceive(pt, "no allow-attach", strict := false);
1095 }
1096 f_vty_transceive(pt, "exit");
1097 f_vty_transceive(pt, "exit");
1098 }
1099}
1100
Harald Welte21b46bd2017-12-17 19:46:32 +01001101/* global initialization function
1102 * \param nr_bts Number of BTSs we should start/bring up
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001103 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false).
1104 * \param nr_msc Number of virtual MSCs to bring up to connect to osmo-bsc.
1105 */
1106function f_init(integer nr_bts := NUM_BTS, boolean handler_mode := false, boolean allow_osmux := false,
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001107 integer nr_msc := 1, float guard_timeout := 30.0) runs on test_CT {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001108 var integer bssap_idx;
Harald Welte28d943e2017-11-25 15:00:50 +01001109
Harald Welteae026692017-12-09 01:03:01 +01001110 if (g_initialized) {
1111 return;
Harald Welte28d943e2017-11-25 15:00:50 +01001112 }
Harald Welteae026692017-12-09 01:03:01 +01001113 g_initialized := true;
1114
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001115 T_guard.start(guard_timeout);
Daniel Willmanne68f9272018-11-27 15:15:28 +01001116 activate(as_Tguard());
1117
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001118 f_init_vty("VirtMSC");
Pau Espin Pedrol23510fb2021-07-20 17:00:38 +02001119 f_vty_allow_osmux(allow_osmux);
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001120
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001121 var my_BooleanList allow_attach := { false, false, false };
Daniel Willmannebdecc02020-08-12 15:30:17 +02001122 f_init_statsd("VirtMSC", vc_STATSD, mp_test_ip, mp_bsc_statsd_port);
1123
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001124 for (bssap_idx := 0; bssap_idx < nr_msc; bssap_idx := bssap_idx+1) {
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001125 allow_attach[bssap_idx] := true;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001126 /* Call a function of our 'parent component' RAN_Adapter_CT to start the
1127 * MSC-side BSSAP emulation */
1128 if (handler_mode) {
1129 var RanOps ranops := MSC_RanOps;
1130 ranops.use_osmux := g_osmux_enabled;
1131 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", ranops);
1132 connect(self:SCCPLITE_IPA_CTRL, g_bssap[bssap_idx].vc_RAN:CTRL_CLIENT);
1133 f_ran_adapter_start(g_bssap[bssap_idx]);
1134 } else {
1135 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", omit);
1136 connect(self:BSSAP, g_bssap[bssap_idx].vc_SCCP:SCCP_SP_PORT);
1137 f_ran_adapter_start(g_bssap[bssap_idx]);
1138 f_legacy_bssap_reset();
1139 }
Harald Welte67089ee2018-01-17 22:19:03 +01001140 }
Harald Welted5833a82018-05-27 16:52:56 +02001141
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02001142 if (mp_enable_lcs_tests) {
1143 if (handler_mode) {
1144 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", SMLC_BssapLeOps);
1145 } else {
1146 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", omit);
1147 connect(self:BSSAP_LE, g_bssap_le.vc_SCCP:SCCP_SP_PORT);
1148 }
1149 f_bssap_le_adapter_start(g_bssap_le);
Harald Welte47cd0e32020-08-21 12:39:11 +02001150 }
Harald Welte47cd0e32020-08-21 12:39:11 +02001151
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001152 /* start the test with exactly all enabled MSCs allowed to attach */
1153 f_vty_msc_allow_attach(BSCVTY, allow_attach);
1154
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01001155 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +01001156
Daniel Willmann191e0d92018-01-17 12:44:35 +01001157 f_init_mgcp("VirtMSC");
1158
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001159 for (var integer i := 0; i < nr_bts; i := i+1) {
1160 f_init_bts(i, handler_mode);
Harald Welte696ddb62017-12-08 14:01:43 +01001161 }
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001162}
Harald Welte696ddb62017-12-08 14:01:43 +01001163
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001164function f_init_bts(integer bts_idx := 0, boolean handler_mode := false)
1165runs on test_CT {
1166 /* wait until osmo-bts-omldummy has respawned */
1167 f_wait_oml(bts_idx, "degraded", 5.0);
1168
1169 /* start RSL connection */
1170 f_ipa_rsl_start(bts[bts_idx].rsl, mp_bsc_ip, mp_bsc_rsl_port, bts_idx, handler_mode);
1171 /* wait until BSC tells us "connected" */
1172 f_wait_oml(bts_idx, "connected", 5.0);
Harald Welte28d943e2017-11-25 15:00:50 +01001173}
1174
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001175function f_init_bts_and_check_sysinfo(integer bts_idx := 0, boolean handler_mode := false,
1176 template SystemInformationConfig expect_si)
1177runs on test_CT {
1178 var default sysinfo := activate(as_catch_RSL_sysinfo(bts_idx));
1179
1180 f_init_bts(bts_idx, handler_mode);
1181
1182 /* Give some time to (hopefully/most likely) collect all system informations from RSL startup.
1183 * We could stop as soon as all expected SI are received, but then we might miss SI that we don't expect and
1184 * that might be sent afterwards. So rather give a generous timeout and be quite sure to catch all SI.
1185 */
1186 f_sleep(5.0);
1187 log("RSL ", bts_idx, " SYSTEM INFORMATION: ", g_system_information[bts_idx]);
1188
1189 deactivate(sysinfo);
1190
1191 if (match(g_system_information[bts_idx], expect_si)) {
1192 setverdict(pass);
1193 } else {
1194 log("RSL ", bts_idx, ": EXPECTED SI: ", expect_si);
1195 log("RSL ", bts_idx, ": GOT SI: ", g_system_information[bts_idx]);
1196 setverdict(fail, "received SI does not match expectations");
1197 return;
1198 }
1199}
1200
Maxd4e56962018-10-31 19:08:25 +01001201/* expect to receive a RSL message matching a specified template on a given BTS / stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001202function 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 +01001203runs on test_CT return RSL_Message {
1204 var ASP_RSL_Unitdata rx_rsl_ud;
1205 timer T := t_secs;
1206
1207 T.start;
1208 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001209 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
Harald Welteae026692017-12-09 01:03:01 +01001210 T.stop;
1211 }
1212 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +01001213 [] T.timeout {
1214 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +02001215 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +01001216 }
Harald Welteae026692017-12-09 01:03:01 +01001217 }
1218 return rx_rsl_ud.rsl;
1219}
1220
Harald Welte21b46bd2017-12-17 19:46:32 +01001221/* helper function to transmit RSL on a given BTS/stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001222function 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 +01001223runs on test_CT {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001224 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(t_tx, sid));
Harald Welteae026692017-12-09 01:03:01 +01001225}
1226
1227
Harald Welte4003d112017-12-09 22:35:39 +01001228/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +01001229testcase TC_chan_act_noreply() runs on test_CT {
1230 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +01001231 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +01001232
Harald Welte89d42e82017-12-17 16:42:41 +01001233 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +01001234
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001235 IPA_RSL[0].send(ts_ASP_RSL_UD(ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +01001236 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001237 f_shutdown_helper();
Harald Welte28d943e2017-11-25 15:00:50 +01001238}
1239
Harald Welte4003d112017-12-09 22:35:39 +01001240/* verify if the "chreq:total" counter increments as expected */
1241testcase TC_chan_act_counter() runs on test_CT {
1242 var BSSAP_N_UNITDATA_ind ud_ind;
1243 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +01001244 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +01001245
Harald Welte89d42e82017-12-17 16:42:41 +01001246 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001247
1248 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001249 IPA_RSL[0].send(ts_ASP_RSL_UD(ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +01001250 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welte4003d112017-12-09 22:35:39 +01001251 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total", chreq_total+1);
1252
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001253 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001254}
1255
Harald Welteae026692017-12-09 01:03:01 +01001256/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
Philipp Maier9c60a622020-07-09 15:08:46 +02001257private function f_TC_chan_act_ack_noest(OCT1 ra := '23'O) runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +01001258 var RSL_Message rx_rsl;
1259
Harald Welteae026692017-12-09 01:03:01 +01001260 /* Send CHAN RQD and wait for allocation; acknowledge it */
Philipp Maier9c60a622020-07-09 15:08:46 +02001261 var RslChannelNr chan_nr := f_chreq_act_ack(ra);
Harald Welteae026692017-12-09 01:03:01 +01001262
1263 /* expect BSC to disable the channel again if there's no RLL EST IND */
1264 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1265
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001266 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001267}
1268
Philipp Maier9c60a622020-07-09 15:08:46 +02001269/* Normal variant */
1270testcase TC_chan_act_ack_noest() runs on test_CT {
Philipp Maieraf58db22020-08-12 17:24:40 +02001271 f_init(1);
Philipp Maier9c60a622020-07-09 15:08:46 +02001272 f_TC_chan_act_ack_noest();
1273}
1274
1275/* Emergency call variant */
1276testcase TC_chan_act_ack_noest_emerg() runs on test_CT {
1277 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
Philipp Maieraf58db22020-08-12 17:24:40 +02001278 f_init(1);
1279 f_vty_allow_emerg_bts(true, 0);
Philipp Maier9c60a622020-07-09 15:08:46 +02001280 f_TC_chan_act_ack_noest(ra := 'A5'O);
1281}
1282
Philipp Maier606f07d2020-08-12 17:21:58 +02001283/* Emergency call variant, but emergency calls are not allowed */
1284testcase TC_chan_rqd_emerg_deny() runs on test_CT {
1285 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
1286
1287 var RSL_Message rx_rsl;
1288 var GsmRrMessage rr;
1289
1290 f_init(1);
1291 f_vty_allow_emerg_bts(false, 0);
1292
1293 IPA_RSL[0].clear;
1294 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
1295
1296 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
1297 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
1298 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1299 setverdict(pass);
1300 } else {
1301 setverdict(fail, "immediate assignment not rejected");
1302 }
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01001303
1304 f_shutdown_helper();
Philipp Maier606f07d2020-08-12 17:21:58 +02001305}
1306
Harald Welteae026692017-12-09 01:03:01 +01001307/* Test behavior if MSC never answers to CR */
1308testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +01001309 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
1310 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +01001311 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +01001312 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +01001313
Harald Welte89d42e82017-12-17 16:42:41 +01001314 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001315
1316 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001317 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001318
1319 var octetstring l3 := '00010203040506'O
1320 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1321
1322 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
1323
1324 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +01001325 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001326 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001327 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001328}
1329
1330/* Test behavior if MSC answers with CREF to CR */
1331testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
1332 var BSSAP_N_CONNECT_ind rx_c_ind;
1333 var RSL_Message rx_rsl;
1334
Harald Welte89d42e82017-12-17 16:42:41 +01001335 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001336
1337 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001338 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001339
1340 var octetstring l3 := '00010203040506'O
1341 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1342
1343 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1344 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
1345
1346 /* expect BSC to disable the channel */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001347 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001348 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001349}
1350
Harald Welte618ef642017-12-14 14:58:20 +01001351/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
1352testcase TC_chan_act_nack() runs on test_CT {
1353 var RSL_Message rx_rsl;
1354 var integer chact_nack;
1355
Harald Welte89d42e82017-12-17 16:42:41 +01001356 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +01001357
1358 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
1359
1360 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
1361 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1362 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1363
1364 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
1365
1366 /* wait for some time to hope the NACK arrives before the CTRL GET below */
1367 f_sleep(0.5);
1368
1369 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
1370
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001371 f_shutdown_helper();
Harald Welte618ef642017-12-14 14:58:20 +01001372}
1373
Harald Welte799c97b2017-12-14 17:50:30 +01001374/* Test for channel exhaustion due to RACH overload */
1375testcase TC_chan_exhaustion() runs on test_CT {
1376 var ASP_RSL_Unitdata rsl_ud;
1377 var integer i;
1378 var integer chreq_total, chreq_nochan;
1379
Harald Welte89d42e82017-12-17 16:42:41 +01001380 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +01001381
1382 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
1383 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
1384
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +01001385 /* GSM 04.08 Table 9.9a:
1386 * RA = '33'O -> Establishment cause = 0011xxxx (MS dual rate capable and asks for "TCH/H or TCH/F").
1387 * With current setup, expect 4xSDCCH + 4xTCH/F + 1xTCH/H to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +02001388 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 +01001389 var RslChannelNr chan_nr := f_chreq_act_ack('33'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +01001390 }
1391
1392 IPA_RSL[0].clear;
1393
Harald Weltedd8cbf32018-01-28 12:07:52 +01001394 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001395 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +01001396
1397 /* now expect additional channel activations to fail */
1398 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
1399
1400 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001401 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
Harald Welte799c97b2017-12-14 17:50:30 +01001402 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
1403 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001404 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
Harald Welte799c97b2017-12-14 17:50:30 +01001405 var GsmRrMessage rr;
1406 /* match on IMM ASS REJ */
1407 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
1408 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1409 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001410 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +01001411 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
1412 chreq_nochan+1);
1413 setverdict(pass);
1414 } else {
1415 repeat;
1416 }
1417 }
1418 [] IPA_RSL[0].receive { repeat; }
1419 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001420 f_shutdown_helper();
Harald Welte799c97b2017-12-14 17:50:30 +01001421}
1422
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001423/* Test channel deactivation due to silence from MS */
1424testcase TC_chan_deact_silence() runs on test_CT {
1425 var RslChannelNr chan_nr;
1426
1427 f_init(1);
1428
1429 /* Request for a dedicated channel */
1430 chan_nr := f_chreq_act_ack('23'O);
1431
1432 /* Wait some time until the channel is released */
1433 f_sleep(2.0);
1434
1435 /* Expect CHANnel RELease */
1436 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001437 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001438 log("Received CHANnel RELease");
1439 setverdict(pass);
1440 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001441 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001442 /* See OS#3709, OsmoBSC should not send Immediate
1443 * Assignment Reject since a dedicated channel was
1444 * already allocated, and Immediate Assignment was
1445 * already sent. */
1446 setverdict(fail, "Unexpected Immediate Assignment!");
1447 }
1448 [] IPA_RSL[0].receive {
1449 setverdict(fail, "Unexpected RSL message!");
1450 }
1451 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001452 f_shutdown_helper();
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001453}
1454
Harald Weltecfe2c962017-12-15 12:09:32 +01001455/***********************************************************************
1456 * Assignment Testing
1457 ***********************************************************************/
1458
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001459/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction,
1460 * except for the inter-BSC handover, MT side) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001461testcase TC_outbound_connect(integer bssap_idx := 0) runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +01001462 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +01001463
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001464 BSSAP.send(ts_BSSAP_CONNECT_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
1465 2342, ts_BSSMAP_AssignmentReq));
Harald Weltecfe2c962017-12-15 12:09:32 +01001466 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001467 f_shutdown_helper();
Harald Weltecfe2c962017-12-15 12:09:32 +01001468}
1469
Harald Welte16a4adf2017-12-14 18:54:01 +01001470/* Test behavior if MSC answers with CREF to CR */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001471testcase TC_assignment_cic_only(integer bssap_idx := 0) runs on test_CT {
Harald Welte16a4adf2017-12-14 18:54:01 +01001472 var BSSAP_N_CONNECT_ind rx_c_ind;
1473 var RSL_Message rx_rsl;
1474 var DchanTuple dt;
1475
Harald Welte89d42e82017-12-17 16:42:41 +01001476 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +01001477
1478 dt := f_est_dchan('23'O, 23, '00000000'O);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001479 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte17b27da2018-05-25 20:33:53 +02001480 /* send assignment without AoIP IEs */
1481 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
1482 } else {
1483 /* Send assignmetn without CIC in IPA case */
1484 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
1485 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
1486 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
1487 }
Harald Welte16a4adf2017-12-14 18:54:01 +01001488 alt {
1489 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1490 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
1491 }
Harald Welte235ebf12017-12-15 14:18:16 +01001492 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +01001493 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1494 setverdict(pass);
1495 }
1496 [] BSSAP.receive { repeat; }
1497 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001498 f_shutdown_helper();
Harald Welte16a4adf2017-12-14 18:54:01 +01001499}
1500
Harald Welteed848512018-05-24 22:27:58 +02001501/* generate an assignment request for either AoIP or SCCPlite */
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001502function 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 +02001503 var PDU_BSSAP ass_cmd;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001504 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001505 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welteed848512018-05-24 22:27:58 +02001506 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001507 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001508 if (osmux_enabled) {
1509 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla, osmux_cid));
1510 } else {
1511 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
1512 }
Harald Welteed848512018-05-24 22:27:58 +02001513 } else {
1514 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001515 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
Harald Welteed848512018-05-24 22:27:58 +02001516 }
1517 return ass_cmd;
1518}
1519
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02001520function f_gen_handover_req(integer bssap_idx := 0, charstring aoip_tla := "1.2.3.4",
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001521 template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit,
1522 template (omit) TestHdlrEncrParams enc := omit) return PDU_BSSAP {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001523 var PDU_BSSAP ho_req;
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001524
1525 var BSSMAP_IE_EncryptionInformation encryptionInformation :=
1526 valueof(ts_BSSMAP_IE_EncrInfo('0000000000000000'O,'01'O));
1527 var template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm := omit;
1528 var template BSSMAP_IE_KC128 kc128 := omit;
1529 if (ispresent(enc)) {
1530 var TestHdlrEncrParams v_enc := valueof(enc);
1531 encryptionInformation := valueof(ts_BSSMAP_IE_EncrInfo(v_enc.enc_key, v_enc.enc_alg));
1532 chosenEncryptionAlgorithm := valueof(
1533 ts_BSSMAP_IE_ChosenEncryptionAlgorithm(int2oct(enum2int(
Oliver Smith598e1ed2021-07-09 10:28:40 +02001534 f_cipher_mode_bssmap_to_rsl(v_enc.enc_alg)), 1)));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001535 if (ispresent(v_enc.enc_kc128)) {
1536 kc128 := ts_BSSMAP_IE_Kc128(v_enc.enc_kc128);
1537 }
1538 }
1539
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001540 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001541 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001542 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001543 ho_req := valueof(ts_BSSMAP_HandoverRequest(omit, tla, oldToNewBSSIEs := oldToNewBSSIEs,
1544 encryptionInformation := encryptionInformation,
1545 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
1546 kC128 := kc128));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001547 } else {
1548 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001549 ho_req := valueof(ts_BSSMAP_HandoverRequest(cic, omit, oldToNewBSSIEs := oldToNewBSSIEs,
1550 encryptionInformation := encryptionInformation,
1551 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
1552 kC128 := kc128));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001553 }
1554 return ho_req;
1555}
1556
Harald Welteed848512018-05-24 22:27:58 +02001557/* generate an assignment complete template for either AoIP or SCCPlite */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001558function f_gen_exp_compl(boolean expect_osmux := false, integer bssap_idx := 0) return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +02001559 var template PDU_BSSAP exp_compl;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001560 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001561 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001562 if (expect_osmux) {
1563 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, osmux_cid);
1564 } else {
1565 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, omit);
1566 }
Harald Welteed848512018-05-24 22:27:58 +02001567 } else {
1568 /* CIC is optional "*" as the MSC allocated it */
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001569 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
Harald Welteed848512018-05-24 22:27:58 +02001570 }
1571 return exp_compl;
1572}
1573
Harald Welte235ebf12017-12-15 14:18:16 +01001574/* Run everything required up to sending a caller-specified assignment command and expect response */
1575function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
1576runs on test_CT {
1577 var BSSAP_N_CONNECT_ind rx_c_ind;
1578 var RSL_Message rx_rsl;
1579 var DchanTuple dt;
1580
Harald Welte89d42e82017-12-17 16:42:41 +01001581 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +01001582
1583 dt := f_est_dchan('23'O, 23, '00000000'O);
1584 /* send assignment without AoIP IEs */
1585 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
1586 alt {
1587 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1588 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
1589 setverdict(pass);
1590 } else {
1591 setverdict(fail, fail_text);
1592 }
1593 }
1594 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1595 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
1596 setverdict(pass);
1597 } else {
1598 setverdict(fail, fail_text);
1599 }
1600 }
1601 [] BSSAP.receive { repeat; }
1602 }
1603}
1604testcase TC_assignment_csd() runs on test_CT {
1605 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001606 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001607 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1608 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
1609 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001610 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001611}
1612
1613testcase TC_assignment_ctm() runs on test_CT {
1614 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001615 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001616 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
1617 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
1618 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001619 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001620}
1621
Harald Welte4003d112017-12-09 22:35:39 +01001622type record DchanTuple {
1623 integer sccp_conn_id,
1624 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +01001625}
1626
Harald Welted6939652017-12-13 21:02:46 +01001627/* Send CHAN RQD and wait for allocation; acknowledge it */
1628private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
1629runs on test_CT return RslChannelNr {
1630 var RSL_Message rx_rsl;
1631 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1632 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1633 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1634 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
Daniel Willmannf4ac4ce2018-08-02 14:06:30 +02001635 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Harald Welted6939652017-12-13 21:02:46 +01001636 return chan_nr;
1637}
1638
Harald Welte4003d112017-12-09 22:35:39 +01001639/* helper function to establish a dedicated channel via BTS and MSC */
1640function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1641runs on test_CT return DchanTuple {
1642 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +01001643 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001644
Harald Welte4003d112017-12-09 22:35:39 +01001645 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001646 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +01001647
1648 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1649
1650 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1651 dt.sccp_conn_id := rx_c_ind.connectionId;
1652 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1653
1654 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001655}
1656
Harald Welte641fcbe2018-06-14 10:58:35 +02001657/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
1658private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
1659 var RSL_Message rx_rsl;
1660 /* expect BSC to disable the channel */
1661 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1662 /* respond with CHAN REL ACK */
1663 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1664
1665 /* expect Clear Complete from BSC */
1666 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1667
1668 /* MSC disconnects as instructed. */
1669 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1670}
1671
Harald Welte4003d112017-12-09 22:35:39 +01001672/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
1673testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001674 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001675 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +01001676
Harald Welte89d42e82017-12-17 16:42:41 +01001677 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +01001678
Harald Welte4003d112017-12-09 22:35:39 +01001679 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1680
1681 /* simulate RLL REL IND */
1682 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
1683
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001684 /* expect Clear Request on MSC side */
1685 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1686
1687 /* Instruct BSC to clear channel */
1688 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1689 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1690
Harald Welte4003d112017-12-09 22:35:39 +01001691 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001692 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001693
1694 /* wait for SCCP emulation to do its job */
1695 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +01001696
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001697 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001698}
1699
1700/* Test behavior of channel release after CONN FAIL IND from BTS */
1701testcase TC_chan_rel_conn_fail() runs on test_CT {
1702 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001703 var DchanTuple dt;
1704
Harald Welte89d42e82017-12-17 16:42:41 +01001705 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001706
1707 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1708
1709 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +01001710 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 +01001711 /* TODO: different cause values? */
1712
Harald Welte4003d112017-12-09 22:35:39 +01001713 /* expect Clear Request from BSC */
1714 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1715
1716 /* Instruct BSC to clear channel */
1717 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1718 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1719
Harald Welte6ff76ea2018-01-28 13:08:01 +01001720 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001721 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +01001722
1723 /* wait for SCCP emulation to do its job */
1724 f_sleep(1.0);
1725
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001726 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001727}
1728
Harald Welte99f3ca02018-06-14 13:40:29 +02001729/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
1730/* See also https://www.osmocom.org/issues/3182 */
1731testcase TC_early_conn_fail() runs on test_CT {
1732 var RSL_Message rx_rsl;
1733 var DchanTuple dt;
1734
1735 f_init(1);
1736
1737 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
Harald Weltec46ea3c2020-10-10 18:46:12 +02001738 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_ra_cs(), 23);
Harald Welte99f3ca02018-06-14 13:40:29 +02001739
1740 /* BTS->BSC: simulate CONN FAIL IND */
1741 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1742
1743 /* BTS->BSC: Expect RF channel release from BSC on Abis */
1744 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1745
1746 /* BTS<-BSC: respond with CHAN REL ACK */
1747 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1748
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001749 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001750}
1751
1752/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
1753/* See also https://www.osmocom.org/issues/3182 */
1754testcase TC_late_conn_fail() runs on test_CT {
1755 var RSL_Message rx_rsl;
1756 var DchanTuple dt;
1757
1758 f_init(1);
1759
1760 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1761
1762 /* BSC<-MSC: Instruct BSC to clear connection */
1763 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
1764
1765 /* BTS->BSC: expect BSC to deactivate SACCH */
1766 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
1767
1768 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
1769 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1770
1771 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
1772 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1773 /* BTS->BSC: respond with CHAN REL ACK */
1774 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1775
1776 /* BSC->MSC: expect Clear Complete from BSC */
1777 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1778
1779 /* BSC<-MSC: MSC disconnects as requested. */
1780 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1781
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001782 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001783}
1784
Neels Hofmeyrf44ccd12018-11-05 19:15:23 +01001785function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr,
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001786 boolean expect_deact_sacch := true,
1787 boolean expect_rr_chan_rel := true,
1788 boolean expect_rll_rel_req := true,
Harald Welte99787102019-02-04 10:41:36 +01001789 boolean handle_rll_rel := true,
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02001790 template CellSelIndValue expect_cells := omit,
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001791 template RR_Cause expect_rr_cause := ?
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001792 ) runs on test_CT {
Harald Welte91d54a52018-01-28 15:35:07 +01001793
1794 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001795 var boolean got_deact_sacch := false;
1796 var boolean got_rr_chan_rel := false;
1797 var boolean got_rll_rel_req := false;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02001798 var ASP_RSL_Unitdata ud;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001799 var RSL_IE_Body l3_ie;
1800 var PDU_ML3_NW_MS l3;
1801 var RR_Cause got_cause;
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001802 log("f_expect_chan_rel() expecting: expect_deact_sacch=", expect_deact_sacch, " expect_rr_chan_rel=", expect_rr_chan_rel,
1803 " expect_rll_rel_req=", expect_rll_rel_req);
Harald Welte91d54a52018-01-28 15:35:07 +01001804 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001805 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001806 got_deact_sacch := true;
Harald Welte91d54a52018-01-28 15:35:07 +01001807 repeat;
1808 }
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02001809 [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 +01001810 got_rr_chan_rel := true;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02001811
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001812 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
1813 setverdict(fail, "cannot find L3");
1814 mtc.stop;
1815 }
1816 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
1817
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02001818 if (not istemplatekind(expect_cells, "omit")) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02001819 var CellSelIndValue cells := dec_CellSelIndValue(
1820 l3.msgs.rrm.channelRelease.cellSelectionIndicator.cellSelectionIndicatorValue);
1821
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02001822 log("GOT RR CHANNEL RELEASE WITH CELLS: ", cells);
1823 if (match(cells, expect_cells)) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02001824 setverdict(pass);
1825 } else {
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02001826 log("EXPECTED CELLS: ", expect_cells);
1827 setverdict(fail, "Received cells list on RR Channel Release does not match expectations");
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02001828 }
1829 }
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001830
1831 if (not istemplatekind(expect_rr_cause, "omit")) {
1832 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
1833 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
1834 if (match(got_cause, expect_rr_cause)) {
1835 setverdict(pass);
1836 } else {
1837 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
1838 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
1839 }
1840 }
Harald Welte99787102019-02-04 10:41:36 +01001841 repeat;
1842 }
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02001843 [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 +01001844 got_rr_chan_rel := true;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001845
1846 if (not istemplatekind(expect_rr_cause, "omit")) {
1847 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
1848 setverdict(fail, "cannot find L3");
1849 mtc.stop;
1850 }
1851 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
1852
1853 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
1854 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
1855 if (match(got_cause, expect_rr_cause)) {
1856 setverdict(pass);
1857 } else {
1858 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
1859 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
1860 }
1861 }
Neels Hofmeyr211169d2018-11-07 00:37:29 +01001862 repeat;
1863 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001864 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001865 got_rll_rel_req := true;
Harald Welte91d54a52018-01-28 15:35:07 +01001866 /* FIXME: Why are we getting this for LinkID SACCH? */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001867 if (handle_rll_rel) {
1868 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
1869 }
Harald Welte91d54a52018-01-28 15:35:07 +01001870 repeat;
1871 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001872 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Harald Welte91d54a52018-01-28 15:35:07 +01001873 /* respond with CHAN REL ACK */
1874 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
1875 }
1876 /* ignore any user data */
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001877 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeR(?))) {
Harald Welte91d54a52018-01-28 15:35:07 +01001878 repeat;
1879 }
1880 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001881
1882 log("f_expect_chan_rel() summary: got_deact_sacch=", got_deact_sacch, " got_rr_chan_rel=", got_rr_chan_rel,
1883 " got_rll_rel_req=", got_rll_rel_req);
1884
1885 if (expect_deact_sacch != got_deact_sacch) {
1886 setverdict(fail, "f_expect_chan_rel(): expect_deact_sacch=", expect_deact_sacch, " got_deact_sacch=", got_deact_sacch);
1887 }
1888 if (expect_rr_chan_rel != got_rr_chan_rel) {
1889 setverdict(fail, "f_expect_chan_rel(): expect_rr_chan_rel=", expect_rr_chan_rel, " got_rr_chan_rel=", got_rr_chan_rel);
1890 }
1891 if (expect_rll_rel_req != got_rll_rel_req) {
1892 setverdict(fail, "f_expect_chan_rel(): expect_rll_rel_req=", expect_rll_rel_req, " got_rll_rel_req=", got_rll_rel_req);
1893 }
Harald Welte91d54a52018-01-28 15:35:07 +01001894}
1895
Harald Welte4003d112017-12-09 22:35:39 +01001896/* Test behavior of channel release after hard Clear Command from MSC */
1897testcase TC_chan_rel_hard_clear() runs on test_CT {
1898 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001899 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +01001900
Harald Welte89d42e82017-12-17 16:42:41 +01001901 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001902
1903 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1904
1905 /* Instruct BSC to clear channel */
1906 var BssmapCause cause := 0;
1907 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1908
1909 /* expect Clear Complete from BSC on A */
1910 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
1911 /* release the SCCP connection */
1912 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1913 }
1914
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001915 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001916 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001917}
1918
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02001919function f_TC_chan_rel_last_eutran_plmn_hard_clear(boolean tx_csfb_ind) runs on test_CT {
1920 var BSSAP_N_DATA_ind rx_di;
1921 var DchanTuple dt;
1922
1923 f_init(1);
1924
1925 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1926 /* Send CommonID with some random PLMN (BSC doesn't take it into account
1927 /* yet when generating the EUTRAN neigh list in RR CHannel Release) */
1928 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
1929
1930 /* Instruct BSC to clear channel */
1931 var BssmapCause cause := 0;
1932 if (tx_csfb_ind) {
1933 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
1934 } else {
1935 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1936 }
1937
1938 /* expect Clear Complete from BSC on A */
1939 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
1940 /* release the SCCP connection */
1941 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1942 }
1943
1944 /* 1 neighbor is added by default in osmo-bts.cfg and
1945 SystemInformationConfig_default, use that: */
1946 var template CellSelIndValue exp_cells := f_tr_rr_chan_rel_earfcns(1);
1947
1948 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, expect_cells := exp_cells);
1949 f_shutdown_helper();
1950}
1951
1952/* Test behavior of RR Channel rRelease after Clear Command without CSFB indicator
1953 from MSC, previously receiving any CommonID containing the "Last Used E-UTRAN
1954 PLMN Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
1955 EUTRAN neighbor list sent later on by BSC in RR Channel, so receiving CSFB
1956 Indicator or not shouldn't matter at all. */
1957testcase TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() runs on test_CT {
1958 f_TC_chan_rel_last_eutran_plmn_hard_clear(false);
1959}
1960
1961/* Test behavior of RR Channel rRelease after Clear Command with CSFB indicator from
1962 MSC, previously receiving any CommonID containing the "Last Used E-UTRAN PLMN
1963 Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
1964 EUTRAN neighbor list sent later on by BSC in RR Channel. */
1965testcase TC_chan_rel_last_eutran_plmn_hard_clear_csfb() runs on test_CT {
1966 f_TC_chan_rel_last_eutran_plmn_hard_clear(true);
1967}
1968
1969/* Test behavior of RR Channel Release after Clear Command with CSFB indicator from
1970 MSC, without receiving any CommonID containing the "Last Used E-UTRAN PLMN
1971 Id". According to spec (TS 48.008 version 16.0.0 Release 16 "3.2.1.21") the
1972 CSFB Indicator should not be used anymore, and hence, there should be no
1973 EUTRAN neighbor list sent by BSC in RR Channel release since no CommonId with
1974 Last Used E-UTRAN PLMN Id" IE was sent for this conn. */
Harald Welte99787102019-02-04 10:41:36 +01001975testcase TC_chan_rel_hard_clear_csfb() runs on test_CT {
1976 var BSSAP_N_DATA_ind rx_di;
1977 var DchanTuple dt;
1978
1979 f_init(1);
1980
1981 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1982
1983 /* Instruct BSC to clear channel */
1984 var BssmapCause cause := 0;
1985 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
1986
1987 /* expect Clear Complete from BSC on A */
1988 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
1989 /* release the SCCP connection */
1990 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1991 }
1992
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02001993 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001994 f_shutdown_helper();
Harald Welte99787102019-02-04 10:41:36 +01001995}
1996
Harald Welted8c36cd2017-12-09 23:05:31 +01001997/* Test behavior of channel release after hard RLSD from MSC */
1998testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +01001999 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +01002000
Harald Welte89d42e82017-12-17 16:42:41 +01002001 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +01002002
2003 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2004
2005 /* release the SCCP connection */
2006 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2007
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002008 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002009 f_shutdown_helper();
Harald Welted8c36cd2017-12-09 23:05:31 +01002010}
2011
Harald Welte550daf92018-06-11 19:22:13 +02002012/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
2013testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
2014 var DchanTuple dt;
2015
2016 f_init(1);
2017
2018 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2019
2020 /* release the SCCP connection */
2021 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2022
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002023 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002024 f_shutdown_helper();
Harald Welte550daf92018-06-11 19:22:13 +02002025}
2026
Harald Welte85804d42017-12-10 14:11:58 +01002027/* Test behavior of channel release after BSSMAP RESET from MSC */
2028testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +01002029 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +01002030
Harald Welte89d42e82017-12-17 16:42:41 +01002031 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +01002032
2033 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2034
2035 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
2036 IPA_RSL[0].clear;
2037
2038 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002039 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 +01002040 interleave {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002041 [] 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 +01002042 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
2043 }
2044
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002045 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002046 f_shutdown_helper();
Harald Welte85804d42017-12-10 14:11:58 +01002047}
2048
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002049/* Verify T(iar) triggers and releases the channel */
2050testcase TC_chan_rel_sccp_tiar_timeout() runs on test_CT {
2051 var DchanTuple dt;
2052
2053 /* Set T(iar) in BSC low enough that it will trigger before other side
2054 has time to keep alive with a T(ias). Keep recommended ratio of
2055 T(iar) >= T(ias)*2 */
2056 g_bsc_sccp_timer_ias := 2;
2057 g_bsc_sccp_timer_iar := 5;
2058
2059 f_init(1);
2060
2061 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2062 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002063 f_shutdown_helper();
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002064}
2065
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002066private function f_tc_chan_rel_rr_cause(myBSSMAP_Cause clear_cmd_cause, template RR_Cause expect_rr_cause)
2067runs on test_CT
2068{
2069 var DchanTuple dt;
2070
2071 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2072 var BssmapCause cause := 0;
2073 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(enum2int(clear_cmd_cause))));
2074 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2075 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2076 }
2077
2078 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 +02002079}
2080
2081/* Test that Clear Command cause codes affect the RR Channel Release cause code */
2082testcase TC_chan_rel_rr_cause() runs on test_CT {
2083 f_init(1);
2084
2085 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_CALL_CONTROL, GSM48_RR_CAUSE_NORMAL);
2086 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_HANDOVER_SUCCESSFUL, GSM48_RR_CAUSE_NORMAL);
2087 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_PREEMPTION, GSM48_RR_CAUSE_PREMPTIVE_REL);
2088 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE, GSM48_RR_CAUSE_PROT_ERROR_UNSPC);
2089 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
2090 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_EQUIPMENT_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
Vadim Yanitskiye18aebb2021-01-03 13:10:43 +01002091
2092 f_shutdown_helper();
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002093}
2094
Harald Welte5cd20ed2017-12-13 21:03:20 +01002095/* Test behavior if RSL EST IND for non-active channel */
2096testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
2097 timer T := 2.0;
2098
Harald Welte89d42e82017-12-17 16:42:41 +01002099 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002100
2101 var octetstring l3 := '00010203040506'O;
2102 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2103 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
2104
2105 T.start;
2106 alt {
2107 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2108 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
2109 }
2110 [] BSSAP.receive {}
2111 [] IPA_RSL[0].receive {}
2112 [] T.timeout {}
2113 }
2114
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002115 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002116}
2117
2118/* Test behavior if RSL EST IND for invalid SAPI */
2119testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
2120 var RslChannelNr chan_nr;
2121
Harald Welte89d42e82017-12-17 16:42:41 +01002122 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002123
2124 chan_nr := f_chreq_act_ack()
2125
2126 var octetstring l3 := '00010203040506'O;
2127 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
2128
2129 timer T := 2.0;
2130 T.start;
2131 alt {
2132 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2133 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
2134 }
2135 [] BSSAP.receive { repeat; }
2136 [] IPA_RSL[0].receive { repeat; }
2137 [] T.timeout {}
2138 }
2139
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002140 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002141}
2142
2143/* Test behavior if RSL EST IND for invalid SAPI */
2144testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
2145 timer T := 2.0;
2146
Harald Welte89d42e82017-12-17 16:42:41 +01002147 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002148
2149 var RslChannelNr chan_nr := f_chreq_act_ack();
2150
2151 var octetstring l3 := '00010203040506'O;
2152 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
2153
2154 T.start;
2155 alt {
2156 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2157 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
2158 }
2159 [] BSSAP.receive { repeat; }
2160 [] IPA_RSL[0].receive { repeat; }
2161 [] T.timeout {}
2162 }
2163
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002164 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002165}
2166
2167/* Test behavior if RSL EST IND for invalid SACCH */
2168testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
2169 timer T := 2.0;
2170
Harald Welte89d42e82017-12-17 16:42:41 +01002171 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002172
2173 var RslChannelNr chan_nr := f_chreq_act_ack();
2174
2175 var octetstring l3 := '00010203040506'O;
2176 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
2177
2178 T.start;
2179 alt {
2180 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2181 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
2182 }
2183 [] BSSAP.receive { repeat; }
2184 [] IPA_RSL[0].receive { repeat; }
2185 [] T.timeout {}
2186 }
2187
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002188 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002189}
2190
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002191/* Verify DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
2192private function f_TC_tch_dlci_link_id_sapi(charstring id) runs on MSC_ConnHdlr {
2193 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2194 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2195
2196 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2197 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2198
2199 f_establish_fully(ass_cmd, exp_compl);
2200
2201 /* SAPI0 has already been established by f_establish_fully(), establish SAPI3 */
2202 RSL.send(ts_RSL_EST_IND(g_chan_nr, ts_RslLinkID_SACCH(3), '0904'O));
2203 /* Expect BSSAP/DTAP on SAPI3 (DLCI IE) */
2204 BSSAP.receive(PDU_BSSAP:{
2205 discriminator := '1'B,
2206 spare := '0000000'B,
2207 dlci := 'C3'O,
2208 lengthIndicator := ?,
2209 pdu := { dtap := '0904'O }
2210 });
2211
2212 /* Send messages on DCCH/SAPI0 and ACCH/SAPI3 */
2213 for (var integer i := 0; i < 32; i := i + 1) {
2214 var octetstring l3 := '09'O & f_rnd_octstring(14);
2215 var template (value) RslLinkId link_id;
2216 var template (value) OCT1 dlci;
2217
2218 if (i mod 2 == 0) {
2219 /* SAPI0 on FACCH or SDCCH */
2220 link_id := ts_RslLinkID_DCCH(0);
2221 dlci := '80'O;
2222 } else {
2223 /* SAPI3 on SACCH */
2224 link_id := ts_RslLinkID_SACCH(3);
2225 dlci := 'C3'O;
2226 }
2227
2228 /* Send MO message: RSL -> BSSAP */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002229 f_mo_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002230 /* Send MT message: BSSAP -> RSL */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002231 f_mt_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002232 }
2233}
2234testcase TC_tch_dlci_link_id_sapi() runs on test_CT {
2235 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2236 var MSC_ConnHdlr vc_conn;
2237
2238 f_init(1, true);
2239 f_sleep(1.0);
2240
2241 vc_conn := f_start_handler(refers(f_TC_tch_dlci_link_id_sapi), pars);
2242 vc_conn.done;
2243
2244 f_shutdown_helper();
2245}
2246
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002247private function f_exp_sapi_n_reject(template (present) GsmSapi sapi := ?,
2248 template myBSSMAP_Cause cause := ?,
2249 float T_val := 2.0)
2250runs on test_CT {
2251 var BSSAP_N_DATA_ind rx_di;
2252 timer T;
2253
2254 var template BSSMAP_IE_Cause tr_cause := tr_BSSMAP_IE_Cause(cause);
2255 var template PDU_BSSAP tr_pdu := tr_BSSMAP_SAPInReject(sapi);
2256
2257 T.start(T_val);
2258 alt {
2259 [] BSSAP.receive(tr_BSSAP_DATA_ind(?, tr_pdu)) -> value rx_di {
2260 var BSSMAP_IE_Cause rx_cause := rx_di.userData.pdu.bssmap.sAPInReject.cause;
2261 if (not match(rx_cause, tr_cause)) {
2262 setverdict(fail, "Rx unexpected Cause IE: ",
2263 rx_cause, " vs expected ", tr_cause);
2264 }
2265 setverdict(pass);
2266 }
2267 [] BSSAP.receive(BSSAP_N_DATA_ind:?) -> value rx_di {
2268 setverdict(fail, "Rx unexpected BSSAP PDU: ", rx_di);
2269 }
2270 [] T.timeout {
2271 setverdict(fail, "Timeout waiting for BSSMAP SAPI N Reject");
2272 }
2273 }
2274}
2275
2276/* Check if we get SAPI N Reject on receipt of unexpected RLL RELease INDication */
2277testcase TC_rll_rel_ind_sapi_n_reject() runs on test_CT {
2278 var octetstring rnd_data := f_rnd_octstring(16);
2279 var RSL_Message rx_rsl;
2280 var DchanTuple dt;
2281
2282 f_init(1);
2283
2284 /* MS establishes a SAPI=0 link on DCCH */
2285 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2286
2287 /* MSC sends some data on (not yet established) SAPI=3 link */
2288 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2289 /* BSC attempts to establish a SAPI=3 link on DCCH */
2290 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2291
2292 /* MS sends unexpected RELease INDication on SAPI=3 */
2293 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3)));
2294 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2295 f_exp_sapi_n_reject(3, GSM0808_CAUSE_MS_NOT_EQUIPPED);
2296
2297 /* Clean up the connection */
2298 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2299 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2300
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002301 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002302}
2303
2304/* Check if we get SAPI N Reject on receipt of unexpected RLL ERROR INDication */
2305testcase TC_rll_err_ind_sapi_n_reject() runs on test_CT {
2306 var octetstring rnd_data := f_rnd_octstring(16);
2307 var RSL_Message rx_rsl;
2308 var DchanTuple dt;
2309
2310 f_init(1);
2311
2312 /* MS establishes a SAPI=0 link on DCCH */
2313 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2314
2315 /* MSC sends some data on (not yet established) SAPI=3 link */
2316 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2317 /* BSC attempts to establish a SAPI=3 link on DCCH */
2318 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2319
2320 /* BTS sends unexpected ERROR INDication on SAPI=3 */
2321 f_ipa_tx(0, ts_RSL_ERROR_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3), ''O));
2322 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2323 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED);
2324
2325 /* Clean up the connection */
2326 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2327 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2328
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002329 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002330}
2331
2332/* Check if we get SAPI N Reject due to a SAPI=3 link establishment timeout */
2333testcase TC_rll_timeout_sapi_n_reject() runs on test_CT {
2334 var octetstring rnd_data := f_rnd_octstring(16);
2335 var RSL_Message rx_rsl;
2336 var DchanTuple dt;
2337
2338 f_init(1);
2339
2340 /* MS establishes a SAPI=0 link on DCCH */
2341 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2342
2343 /* MSC sends some data on (not yet established) SAPI=3 link */
2344 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2345 /* BSC attempts to establish a SAPI=3 link on DCCH */
2346 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2347
2348 /* MS does not respond, so the link establishment timeout triggers SAPI N Reject */
2349 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED, T_val := 8.0);
2350
2351 /* Clean up the connection */
2352 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2353 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2354
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002355 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002356}
2357
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002358testcase TC_si_default() runs on test_CT {
2359 f_init(0);
2360 f_init_bts_and_check_sysinfo(0, expect_si := SystemInformationConfig_default);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002361 f_shutdown_helper();
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002362}
Harald Welte4003d112017-12-09 22:35:39 +01002363
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002364/* We're testing SI2quater with lists of EARFCNs. Instead of just incrementing EARFCNs, also pick some from the edges of
2365 * the entire value range. This function provides the same EARFCN numbers for the same earfcn_index */
2366private function f_test_si2quater_earfcn_by_idx(integer earfcn_index) return uint16_t
2367{
2368 select (earfcn_index) {
2369 case (0) {
2370 /* E-ARFCN 111 is already added in the osmo-bsc.cfg */
2371 return 111;
2372 }
2373 case (1) {
2374 return 1;
2375 }
2376 case (2) {
2377 return 0;
2378 }
2379 case (3) {
2380 return 65535;
2381 }
2382 case else {
2383 return 23 * (earfcn_index - 3);
2384 }
2385 }
2386}
2387
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002388function f_test_si2quater(integer total_earfcns, template SystemInformationConfig expect_si,
2389 template CellSelIndValue expect_cells := omit) runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002390
2391 f_init(0);
2392
2393 /* E-ARFCN 111 is already added in the osmo-bsc.cfg, so only add more arfcns if total_earfcns > 1 */
2394 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002395 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2396 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002397 }
2398
2399 f_init_bts_and_check_sysinfo(0, expect_si := expect_si);
2400
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002401 if (not istemplatekind(expect_cells, "omit")) {
2402 /* Also check that RR Channel Release contains these EARFCNs.
2403 * (copied code from TC_chan_rel_hard_clear_csfb) */
2404 var BSSAP_N_DATA_ind rx_di;
2405 var DchanTuple dt;
2406
2407 dt := f_est_dchan('23'O, 23, '00010203040506'O);
Pau Espin Pedrold0046312021-04-19 16:35:58 +02002408 /* Send CommonID with some random PLMN (BSC doesn't take it into account
2409 * yet when generating the EUTRAN neigh list in RR CHannel Release) */
2410 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002411
2412 /* Instruct BSC to clear channel */
2413 var BssmapCause cause := 0;
2414 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2415
2416 /* expect Clear Complete from BSC on A */
2417 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2418 /* release the SCCP connection */
2419 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2420 }
2421
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002422 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 +02002423 }
2424
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002425 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002426 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 +02002427 }
2428}
2429
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002430private function f_tr_si2quater_earfcns(integer count) return template SI2quaterRestOctetsList
2431{
2432 var template SI2quaterRestOctetsList si2quater := {};
2433 var integer si2quater_count := (count + 2) / 3;
2434
2435 for (var integer i := 0; i < count; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002436 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002437 var integer index := i / 3;
2438 var integer earfcn_index := i mod 3;
2439 if (index >= lengthof(si2quater)) {
2440 si2quater[index] := tr_SI2quaterRestOctets_EUTRAN(index := index, count := si2quater_count - 1);
2441 }
2442 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);
2443 }
2444
2445 return si2quater;
2446}
2447
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002448private function f_tr_rr_chan_rel_earfcns(integer count) return template CellSelIndValue
2449{
2450 var template CellSelIndValue_EUTRAN_Descrs cells := {};
2451
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002452 /* the lte neighbors must match the config & vty to pass this test */
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002453 for (var integer i := 0; i < count; i := i + 1) {
2454 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002455 cells[i] := tr_CellSelIndValue_EUTRAN_Descr(earfcn, '1'B, 3);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002456 }
2457
2458 return tr_CellSelIndValue_EUTRAN(cells);
2459}
2460
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002461private function f_tc_si2quater_n_earfcns(integer n) runs on test_CT
2462{
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002463 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrol8ab62e42020-12-18 16:19:11 +01002464 sic.si2quater := f_tr_si2quater_earfcns(n);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002465 var template CellSelIndValue cells := f_tr_rr_chan_rel_earfcns(n);
2466 f_test_si2quater(n, sic, cells);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002467}
2468
2469testcase TC_si2quater_2_earfcns() runs on test_CT {
2470 f_tc_si2quater_n_earfcns(2);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002471 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002472}
2473
2474testcase TC_si2quater_3_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002475 f_tc_si2quater_n_earfcns(3);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002476 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002477}
2478
2479testcase TC_si2quater_4_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002480 f_tc_si2quater_n_earfcns(4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002481 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002482}
2483
2484testcase TC_si2quater_5_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002485 f_tc_si2quater_n_earfcns(5);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002486 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002487}
2488
2489testcase TC_si2quater_6_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002490 f_tc_si2quater_n_earfcns(6);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002491 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002492}
2493
2494testcase TC_si2quater_12_earfcns() runs on test_CT {
2495 f_tc_si2quater_n_earfcns(12);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002496 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002497}
2498
2499testcase TC_si2quater_23_earfcns() runs on test_CT {
2500 f_tc_si2quater_n_earfcns(23);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002501 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002502}
2503
2504testcase TC_si2quater_32_earfcns() runs on test_CT {
2505 f_tc_si2quater_n_earfcns(32);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002506 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002507}
2508
2509testcase TC_si2quater_33_earfcns() runs on test_CT {
2510 f_tc_si2quater_n_earfcns(33);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002511 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002512}
2513
2514testcase TC_si2quater_42_earfcns() runs on test_CT {
2515 f_tc_si2quater_n_earfcns(42);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002516 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002517}
2518
2519testcase TC_si2quater_48_earfcns() runs on test_CT {
2520 f_tc_si2quater_n_earfcns(48);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002521 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002522}
2523
2524/* verify the VTY error response when adding too many EARFCNs, and showing that osmo-bsc still sends 16 SI2quater with
2525 * 48 EARFCNs. */
2526testcase TC_si2quater_49_earfcns() runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002527 var template SystemInformationConfig sic := SystemInformationConfig_default;
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002528 sic.si2quater := f_tr_si2quater_earfcns(48); /* 48, not 49! */
2529 f_init(0);
2530
2531 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002532 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2533 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002534 }
2535
2536 /* The 49th EARFCN no longer fits, expect VTY error */
2537 f_vty_enter_cfg_bts(BSCVTY, 0);
2538 var charstring vty_error;
2539 vty_error := f_vty_transceive_ret(BSCVTY,
2540 "si2quater neighbor-list add earfcn 70 thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3")
2541 f_vty_transceive(BSCVTY, "end");
2542
2543 if (f_strstr(vty_error, "Unable to add ARFCN 70") >= 0) {
2544 log("Got expected VTY error: ", vty_error);
2545 setverdict(pass);
2546 } else {
2547 setverdict(fail, "Expected the 49th EUTRAN ARFCN to be rejected by vty config, got: ", vty_error);
2548 }
2549
2550 f_init_bts_and_check_sysinfo(0, expect_si := sic);
2551
2552 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002553 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 +02002554 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002555 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002556}
2557
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002558private function f_acc09_count_allowed(AccessControlClass acc) return uint8_t
2559{
2560 var uint8_t count := 0;
2561 for (var integer i := 5; i < 16; i := i + 1) {
2562 if (acc[i] == '0'B) { /* the list marks barred, we count allowed */
2563 count := count + 1;
2564 }
2565 }
2566 return count;
2567}
2568
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002569private function f_recv_next_si1(integer rsl_idx := 0) runs on test_CT return SystemInformationType1
2570{
2571 var ASP_RSL_Unitdata rx_rsl_ud;
2572 var SystemInformationType1 last_si1;
2573
2574 timer T := 30.0;
2575 T.start;
2576 alt {
2577 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD((tr_RSL_NO_BCCH_INFO,
2578 tr_RSL_BCCH_INFO,
2579 tr_RSL_NO_SACCH_FILL,
2580 tr_RSL_SACCH_FILL))
2581 ) -> value rx_rsl_ud {
2582 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
2583 if (g_system_information[rsl_idx].si1 == omit) {
2584 repeat;
2585 }
2586 last_si1 := g_system_information[rsl_idx].si1;
2587 g_system_information[rsl_idx].si1 := omit;
2588 T.stop;
2589 }
Vadim Yanitskiy79ebd5e2021-01-04 00:12:55 +01002590 [] IPA_RSL[rsl_idx].receive { repeat; }
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002591 [] T.timeout { setverdict(fail, "Timeout receiving next SI1"); }
2592 }
2593 return last_si1;
2594}
2595
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002596/* verify ACC rotate feature */
2597testcase TC_si_acc_rotate() runs on test_CT {
2598 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002599 var SystemInformationType1 last_si1;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002600 var AccessControlClass acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002601 var uint8_t count;
2602 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2603
2604 f_init(0, guard_timeout := 60.0);
2605
2606 f_bts_0_cfg(BSCVTY, {"rach access-control-class 5 barred",
2607 "access-control-class-rotate 3",
2608 "access-control-class-rotate-quantum 1"});
2609
2610 /* Init and get first sysinfo */
2611 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2612
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002613 for (var integer i:= 0; i < 20; i := i + 1) {
2614 last_si1 := f_recv_next_si1(0);
2615 acc := last_si1.rach_control.acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002616 count := f_acc09_count_allowed(acc);
2617 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2618
2619 if (count != 3) {
2620 log("RSL: EXPECTED SI ACC len=3");
2621 setverdict(fail, "received SI does not match expectations");
2622 break;
2623 }
2624
2625 for (var integer j := 0; j < 10; j := j + 1) {
2626 if (acc[16 - 1 - j] == '0'B) { /* the list marks barred, we count allowed */
2627 times_allowed[j] := times_allowed[j] + 1;
2628 }
2629 }
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002630 }
2631
2632 for (var integer j := 0; j < 10; j := j + 1) {
2633 log("ACC", j, " allowed ", times_allowed[j], " times" );
2634 if (j != 5 and times_allowed[j] < 3) {
2635 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " < 1 times");
2636 } else if (j == 5 and times_allowed[j] > 0) {
2637 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " > 0 times");
2638 }
2639 }
2640
2641 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2642 "rach access-control-class 5 allowed"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002643 f_shutdown_helper();
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002644}
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002645
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002646/* verify ACC startup ramp+rotate feature */
2647testcase TC_si_acc_ramp_rotate() runs on test_CT {
2648 var template SystemInformationConfig sic := SystemInformationConfig_default;
2649 var SystemInformationType1 last_si1;
2650 var AccessControlClass acc;
2651 var ASP_RSL_Unitdata rx_rsl_ud;
2652 var uint8_t count;
2653 var uint8_t prev_count;
2654 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2655
2656 f_init(0, guard_timeout := 80.0);
2657
2658 f_bts_0_cfg(BSCVTY, {"rach access-control-class 4 barred",
2659 "access-control-class-rotate 0",
2660 "access-control-class-rotate-quantum 1",
2661 "access-control-class-ramping",
2662 "access-control-class-ramping-step-interval 5",
2663 "access-control-class-ramping-step-size 5"});
2664
2665 /* Init and get first sysinfo */
2666 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2667 last_si1 := g_system_information[0].si1;
2668 acc := last_si1.rach_control.acc;
2669 count := f_acc09_count_allowed(acc);
2670 /* Adm subset size was set to 0 above, so wait until all ACC are barred */
2671 while (count > 0) {
2672 last_si1 := f_recv_next_si1(0);
2673 acc := last_si1.rach_control.acc;
2674 count := f_acc09_count_allowed(acc);
2675 log("RSL: wait len()=0: GOT SI1 ACC len=", count, ": ", acc);
2676 }
2677
2678 /* Increase adm subset size, we should see ramping start up */
2679 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10"});
2680 prev_count := 0;
2681 while (true) {
2682 last_si1 := f_recv_next_si1(0);
2683 acc := last_si1.rach_control.acc;
2684 count := f_acc09_count_allowed(acc);
2685 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2686
2687 if (prev_count > count) {
2688 setverdict(fail, "ACC allowed count dropped while expecting grow: ", prev_count, " -> ", count);
2689 break;
2690 }
2691
2692 if (count == 9) {
2693 break; /* Maximum reached (10 - 1 perm barred), done here */
2694 }
2695
2696 prev_count := count;
2697 }
2698
2699 setverdict(pass);
2700
2701 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2702 "rach access-control-class 4 allowed",
2703 "no access-control-class-ramping"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002704 f_shutdown_helper();
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002705}
2706
Harald Welte4003d112017-12-09 22:35:39 +01002707testcase TC_ctrl_msc_connection_status() runs on test_CT {
2708 var charstring ctrl_resp;
2709
Harald Welte89d42e82017-12-17 16:42:41 +01002710 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002711
2712 /* See https://osmocom.org/issues/2729 */
2713 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002714 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002715}
2716
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002717testcase TC_ctrl_msc0_connection_status() runs on test_CT {
2718 var charstring ctrl_resp;
2719
2720 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002721
2722 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002723 f_shutdown_helper();
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002724}
2725
Harald Welte4003d112017-12-09 22:35:39 +01002726testcase TC_ctrl() runs on test_CT {
2727 var charstring ctrl_resp;
2728
Harald Welte89d42e82017-12-17 16:42:41 +01002729 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002730
2731 /* all below values must match the osmo-bsc.cfg config file used */
2732
Harald Welte6a129692018-03-17 17:30:14 +01002733 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
2734 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Oliver Smith75aa0202019-08-19 14:17:50 +02002735 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "4");
Harald Welte4003d112017-12-09 22:35:39 +01002736
2737 var integer bts_nr := 0;
2738 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
2739 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
2740 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
2741 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
2742 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
2743 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
2744 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
2745
2746 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
2747 f_sleep(2.0);
2748 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
2749 setverdict(fail, "oml-uptime not incrementing as expected");
2750 }
2751 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
2752
2753 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
2754
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002755 f_shutdown_helper();
Harald Welte96c94412017-12-09 03:12:45 +01002756}
2757
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02002758/* Verify that Upon receival of SET "location", BSC forwards a TRAP
2759 "location-state" over the SCCPlite IPA conn */
2760testcase TC_ctrl_location() runs on test_CT {
2761 var MSC_ConnHdlr vc_conn;
2762 var integer bts_nr := 0;
2763
2764 f_init(1, true);
2765 f_sleep(1.0);
2766
2767 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234567,fix3d,0.340000,0.560000,0.780000");
2768 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
2769 "1234567,fix3d,0.340000,0.560000,0.780000,operational,unlocked,on,001,01");
2770
2771 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "1");
2772 f_sleep(2.0);
2773
2774 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234888,fix3d,0.350000,0.570000,0.790000");
2775 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
2776 "1234888,fix3d,0.350000,0.570000,0.790000,operational,locked,off,001,01");
2777
2778 /* should match the one from config */
2779 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "0");
2780
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002781 f_shutdown_helper();
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02002782}
2783
Harald Welte6f521d82017-12-11 19:52:02 +01002784
2785/***********************************************************************
2786 * Paging Testing
2787 ***********************************************************************/
2788
2789type record Cell_Identity {
2790 GsmMcc mcc,
2791 GsmMnc mnc,
2792 GsmLac lac,
2793 GsmCellId ci
2794};
Harald Welte24135bd2018-03-17 19:27:53 +01002795private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01002796private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01002797
Harald Welte5d1a2202017-12-13 19:51:29 +01002798type set of integer BtsIdList;
2799
2800private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
2801 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
2802 if (bts_id == bts_ids[j]) {
2803 return true;
2804 }
2805 }
2806 return false;
2807}
Harald Welte6f521d82017-12-11 19:52:02 +01002808
2809/* core paging test helper function; used by most paging test cases */
2810private function f_pageing_helper(hexstring imsi,
2811 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01002812 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01002813 template RSL_ChanNeeded rsl_chneed := omit,
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002814 template (omit) OCT4 tmsi := omit) runs on test_CT
Harald Welte6f521d82017-12-11 19:52:02 +01002815{
2816 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002817 var template MobileIdentityV mi;
Harald Welte6f521d82017-12-11 19:52:02 +01002818 var RSL_Message rx_rsl;
2819 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01002820 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01002821
2822 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01002823
2824 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01002825 for (i := 0; i < NUM_BTS; i := i + 1) {
2826 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01002827 }
Harald Welte6f521d82017-12-11 19:52:02 +01002828
2829 if (isvalue(rsl_chneed)) {
2830 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
2831 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
2832 } else {
2833 bssmap_chneed := omit;
2834 }
2835
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002836 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[0].sccp_addr_peer, g_bssap[0].sccp_addr_own,
2837 ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed)));
Harald Welte6f521d82017-12-11 19:52:02 +01002838
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002839 if (not istemplatekind(tmsi, "omit")) {
2840 mi := t_MI_TMSI(tmsi);
Harald Welte6f521d82017-12-11 19:52:02 +01002841 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002842 mi := tr_MI_IMSI(imsi);
Harald Welte6f521d82017-12-11 19:52:02 +01002843 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002844
Harald Welte5d1a2202017-12-13 19:51:29 +01002845 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002846 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(mi));
Harald Welte5d1a2202017-12-13 19:51:29 +01002847 /* check channel type, paging group */
2848 if (rx_rsl.ies[1].body.paging_group != paging_group) {
2849 setverdict(fail, "Paging for wrong paging group");
2850 }
2851 if (ispresent(rsl_chneed) and
2852 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
2853 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
2854 }
Harald Welte6f521d82017-12-11 19:52:02 +01002855 }
Harald Welte2fccd982018-01-31 15:48:19 +01002856 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01002857 /* do a quick check on all not-included BTSs if they received paging */
2858 for (i := 0; i < NUM_BTS; i := i + 1) {
2859 timer T := 0.1;
2860 if (f_bts_in_list(i, bts_ids)) {
2861 continue;
2862 }
2863 T.start;
2864 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002865 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(mi))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01002866 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
2867 }
2868 [] IPA_RSL[i].receive { repeat; }
2869 [] T.timeout { }
2870 }
Harald Welte6f521d82017-12-11 19:52:02 +01002871 }
2872
2873 setverdict(pass);
2874}
2875
Harald Welte5d1a2202017-12-13 19:51:29 +01002876const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01002877const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01002878const BtsIdList c_BtsId_LAC1 := { 0, 1 };
2879const BtsIdList c_BtsId_LAC2 := { 2 };
2880
Harald Welte6f521d82017-12-11 19:52:02 +01002881/* PAGING by IMSI + TMSI */
2882testcase TC_paging_imsi_nochan() runs on test_CT {
2883 var BSSMAP_FIELD_CellIdentificationList cid_list;
2884 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01002885 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002886 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002887}
2888
2889/* PAGING by IMSI + TMSI */
2890testcase TC_paging_tmsi_nochan() runs on test_CT {
2891 var BSSMAP_FIELD_CellIdentificationList cid_list;
2892 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01002893 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002894 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002895}
2896
2897/* Paging with different "channel needed' values */
2898testcase TC_paging_tmsi_any() runs on test_CT {
2899 var BSSMAP_FIELD_CellIdentificationList cid_list;
2900 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01002901 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002902 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002903}
2904testcase TC_paging_tmsi_sdcch() runs on test_CT {
2905 var BSSMAP_FIELD_CellIdentificationList cid_list;
2906 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01002907 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002908 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002909}
2910testcase TC_paging_tmsi_tch_f() runs on test_CT {
2911 var BSSMAP_FIELD_CellIdentificationList cid_list;
2912 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01002913 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002914 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002915}
2916testcase TC_paging_tmsi_tch_hf() runs on test_CT {
2917 var BSSMAP_FIELD_CellIdentificationList cid_list;
2918 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01002919 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002920 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002921}
2922
2923/* Paging by CGI */
2924testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
2925 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2926 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01002927 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01002928 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002929}
2930
2931/* Paging by LAC+CI */
2932testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
2933 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2934 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01002935 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01002936 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002937}
2938
2939/* Paging by CI */
2940testcase TC_paging_imsi_nochan_ci() runs on test_CT {
2941 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2942 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01002943 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01002944 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002945}
2946
2947/* Paging by LAI */
2948testcase TC_paging_imsi_nochan_lai() runs on test_CT {
2949 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2950 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01002951 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002952 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002953}
2954
2955/* Paging by LAC */
2956testcase TC_paging_imsi_nochan_lac() runs on test_CT {
2957 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2958 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01002959 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002960 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002961}
2962
2963/* Paging by "all in BSS" */
2964testcase TC_paging_imsi_nochan_all() runs on test_CT {
2965 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2966 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01002967 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002968 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002969}
2970
Stefan Sperling7b5e1782018-03-20 19:32:43 +01002971/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01002972testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
2973 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2974 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 +01002975 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002976 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01002977}
Harald Welte6f521d82017-12-11 19:52:02 +01002978
Stefan Sperling7b5e1782018-03-20 19:32:43 +01002979/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01002980testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
2981 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2982 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01002983 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002984 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01002985}
2986
Stefan Sperling7b5e1782018-03-20 19:32:43 +01002987/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01002988testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
2989 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2990 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01002991 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002992 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01002993}
2994
Harald Welte6f521d82017-12-11 19:52:02 +01002995/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01002996testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
2997 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2998 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
2999 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003000 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003001}
3002
3003/* Paging on empty list: Verify none of them page */
3004testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
3005 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3006 cid_list := { cIl_LAC := { } };
3007 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003008 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003009}
3010
Stefan Sperling049a86e2018-03-20 15:51:00 +01003011/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
3012testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
3013 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3014 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
3015 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
3016 f_shutdown_helper();
3017}
3018
Harald Welte6f521d82017-12-11 19:52:02 +01003019/* Verify paging retransmission interval + count */
3020/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01003021/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01003022
Harald Weltee65d40e2017-12-13 00:09:06 +01003023/* Verify PCH load */
3024testcase TC_paging_imsi_load() runs on test_CT {
3025 var BSSMAP_FIELD_CellIdentificationList cid_list;
3026 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01003027 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01003028 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003029 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01003030
3031 /* tell BSC there is no paging space anymore */
3032 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01003033 f_sleep(0.2);
3034 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01003035
3036 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
3037 * there would be 8 retransmissions during 4 seconds */
3038 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01003039 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01003040 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003041 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Weltee65d40e2017-12-13 00:09:06 +01003042 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02003043 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01003044 }
Harald Welte2caa1062018-03-17 18:19:05 +01003045 [] T_retrans.timeout {
3046 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
3047 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
3048 T_retrans.start;
3049 repeat;
3050 }
Harald Weltee65d40e2017-12-13 00:09:06 +01003051 [] T.timeout {
3052 setverdict(pass);
3053 }
3054 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003055
3056 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01003057}
3058
Harald Welte235ebf12017-12-15 14:18:16 +01003059/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01003060testcase TC_paging_counter() runs on test_CT {
3061 var BSSMAP_FIELD_CellIdentificationList cid_list;
3062 timer T := 4.0;
3063 var integer i;
3064 var integer paging_attempted_bsc;
3065 var integer paging_attempted_bts[NUM_BTS];
3066 var integer paging_expired_bts[NUM_BTS];
3067 cid_list := valueof(ts_BSSMAP_CIL_noCell);
3068
3069 f_init();
3070
3071 /* read counters before paging */
3072 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
3073 for (i := 0; i < NUM_BTS; i := i+1) {
3074 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
3075 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
3076 }
3077
3078 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
3079
3080 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
3081 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
3082 for (i := 0; i < NUM_BTS; i := i+1) {
3083 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
3084 paging_attempted_bts[i]+1);
3085 }
3086
3087 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
3088 f_sleep(12.0);
3089 for (i := 0; i < NUM_BTS; i := i+1) {
3090 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
3091 paging_expired_bts[i]+1);
3092 }
Harald Welte1ff69992017-12-14 12:31:17 +01003093
Philipp Maier282ca4b2018-02-27 17:17:00 +01003094 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01003095}
3096
3097
Harald Welte10985002017-12-12 09:29:15 +01003098/* Verify paging stops after A-RESET */
3099testcase TC_paging_imsi_a_reset() runs on test_CT {
3100 var BSSMAP_FIELD_CellIdentificationList cid_list;
3101 timer T := 3.0;
3102 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003103 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01003104
3105 /* Perform a BSSMAP Reset and wait for ACK */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003106 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 +01003107 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003108 [] 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 +01003109 [] BSSAP.receive { repeat; }
3110 }
3111
Daniel Willmanncbef3982018-07-30 09:22:40 +02003112 /* Wait to avoid a possible race condition if a paging message is
3113 * received right before the reset ACK. */
3114 f_sleep(0.2);
3115
Harald Welte10985002017-12-12 09:29:15 +01003116 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01003117 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
3118 IPA_RSL[i].clear;
3119 }
Harald Welte10985002017-12-12 09:29:15 +01003120
3121 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
3122 T.start;
3123 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003124 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte10985002017-12-12 09:29:15 +01003125 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003126 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01003127 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003128 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003129 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003130 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003131 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003132 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003133 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003134 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003135 }
Harald Welte10985002017-12-12 09:29:15 +01003136 [] T.timeout {
3137 setverdict(pass);
3138 }
3139 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003140
3141 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01003142}
Harald Welteae026692017-12-09 01:03:01 +01003143
Philipp Maierf45824a2019-08-14 14:44:10 +02003144/* Verify how we handle unsolicited Paging Response. In case of an unsolicit
3145 * paging response we can not know which MSC is in charge, so we will blindly
3146 * pick the first configured MSC. This behavior is required in order to make
3147 * MT-CSFB calls working because in those cases the BSC can not know that the
3148 * MSC has already paged the subscriver via SGs. So any MT-CSFB call will look
3149 * like an unsolicited Paging Response to the MSC.
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003150 */
3151testcase TC_paging_resp_unsol() runs on test_CT {
3152
3153 f_init(1);
Philipp Maierf45824a2019-08-14 14:44:10 +02003154 timer T := 5.0;
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003155
3156 var BSSAP_N_CONNECT_ind rx_c_ind;
3157 var DchanTuple dt;
3158 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
Philipp Maierf45824a2019-08-14 14:44:10 +02003159 var octetstring rr_pag_resp := enc_PDU_ML3_MS_NW(l3);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003160
3161 /* Send CHAN RQD and wait for allocation; acknowledge it */
3162 dt.rsl_chan_nr := f_chreq_act_ack();
3163
3164 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
3165 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
3166
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003167
Philipp Maierf45824a2019-08-14 14:44:10 +02003168 /* Expevct a CR with a matching Paging response on the A-Interface */
3169 T.start;
3170 alt {
3171 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(rr_pag_resp))) {
3172 setverdict(pass);
3173 }
3174 [] BSSAP.receive {
3175 setverdict(fail, "Received unexpected message on A-Interface!");
3176 }
3177 [] T.timeout {
3178 setverdict(fail, "Received nothing on A-Interface!");
3179 }
3180 }
3181
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003182 f_shutdown_helper();
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003183}
3184
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003185/* Test RSL link drop causes counter increment */
3186testcase TC_rsl_drop_counter() runs on test_CT {
3187 var integer rsl_fail;
3188
Harald Welte89d42e82017-12-17 16:42:41 +01003189 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003190
3191 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
3192
3193 bts[0].rsl.vc_IPA.stop;
3194
3195 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
3196
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003197 f_shutdown_helper();
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003198}
3199
3200/* TODO: Test OML link drop causes counter increment */
3201
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003202/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
3203function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
3204 timer T := 10.0;
3205
3206 bts[0].rsl.id := "IPA-0-RSL";
3207 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
3208 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
3209 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
Oliver Smith92c2bdb2019-08-20 15:11:24 +02003210 bts[0].rsl.ccm_pars.unit_id := "99/0/0"; /* value which is unknown at BTS */
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003211
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01003212 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003213
3214 f_init_mgcp("VirtMSC");
3215
3216 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
3217 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
3218 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
3219 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
3220
3221 /* wait for IPA OML link to connect and then disconnect */
3222 T.start;
3223 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +07003224 [] IPA_RSL[0].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) {
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003225 T.stop;
3226 return true;
3227 }
3228 [] IPA_RSL[0].receive { repeat }
3229 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02003230 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003231 }
3232 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003233 return false;
3234}
3235
3236/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3237testcase TC_rsl_unknown_unit_id() runs on test_CT {
3238 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
3239 setverdict(pass);
3240 } else {
3241 setverdict(fail, "Timeout RSL waiting for connection to close");
3242 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003243 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003244}
3245
3246
3247/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3248testcase TC_oml_unknown_unit_id() runs on test_CT {
3249 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
3250 setverdict(pass);
3251 } else {
3252 setverdict(fail, "Timeout OML waiting for connection to close");
3253 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003254 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003255}
3256
3257
Harald Weltec1a2fff2017-12-17 11:06:19 +01003258/***********************************************************************
Harald Welte6811d102019-04-14 22:23:14 +02003259 * "New world" test cases using RSL_Emulation + RAN_Emulation
Harald Weltec1a2fff2017-12-17 11:06:19 +01003260 ***********************************************************************/
3261
Harald Welte6811d102019-04-14 22:23:14 +02003262import from RAN_Emulation all;
Harald Welte47cd0e32020-08-21 12:39:11 +02003263import from BSSAP_LE_Emulation all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01003264import from RSL_Emulation all;
3265import from MSC_ConnectionHandler all;
3266
3267type function void_fn(charstring id) runs on MSC_ConnHdlr;
3268
Harald Welte336820c2018-05-31 20:34:52 +02003269/* helper function to create and connect a MSC_ConnHdlr component */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003270private function f_connect_handler(inout MSC_ConnHdlr vc_conn, integer bssap_idx := 0) runs on test_CT {
3271 connect(vc_conn:RAN, g_bssap[bssap_idx].vc_RAN:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01003272 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003273 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01003274 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01003275 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01003276 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
3277 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
3278 }
Neels Hofmeyr91401012019-07-11 00:42:35 +02003279 if (isvalue(bts[2])) {
3280 connect(vc_conn:RSL2, bts[2].rsl.vc_RSL:CLIENT_PT);
3281 connect(vc_conn:RSL2_PROC, bts[2].rsl.vc_RSL:RSL_PROC);
3282 }
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003283 connect(vc_conn:BSSAP, g_bssap[bssap_idx].vc_RAN:CLIENT);
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02003284 if (mp_enable_lcs_tests) {
3285 connect(vc_conn:BSSAP_LE, g_bssap_le.vc_BSSAP_LE:CLIENT);
3286 connect(vc_conn:BSSAP_LE_PROC, g_bssap_le.vc_BSSAP_LE:PROC);
3287 }
Daniel Willmann191e0d92018-01-17 12:44:35 +01003288 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02003289 connect(vc_conn:MGCP_MULTI, vc_MGCP:MGCP_CLIENT_MULTI);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003290 connect(vc_conn:STATSD_PROC, vc_STATSD:STATSD_PROC);
Harald Welte336820c2018-05-31 20:34:52 +02003291}
3292
3293function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
3294runs on test_CT return MSC_ConnHdlr {
3295 var charstring id := testcasename();
3296 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003297 var integer bssap_idx := 0;
3298 if (isvalue(pars)) {
3299 bssap_idx := valueof(pars).mscpool.bssap_idx;
3300 }
Harald Welte336820c2018-05-31 20:34:52 +02003301 vc_conn := MSC_ConnHdlr.create(id);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003302 f_connect_handler(vc_conn, bssap_idx);
Neels Hofmeyr1708d1b2020-10-10 16:56:48 +02003303 /* Emit a marker to appear in the SUT's own logging output */
3304 f_logp(BSCVTY, testcasename() & "() start");
Harald Weltea0630032018-03-20 21:09:55 +01003305 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003306 return vc_conn;
3307}
3308
Harald Weltea0630032018-03-20 21:09:55 +01003309/* first function inside ConnHdlr component; sets g_pars + starts function */
3310private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
3311runs on MSC_ConnHdlr {
3312 if (isvalue(pars)) {
3313 g_pars := valueof(pars);
3314 }
3315 fn.apply(id);
3316}
3317
Oliver Smith26a3db72021-07-09 13:51:29 +02003318private function f_vty_encryption_a5(charstring options) runs on test_CT {
3319 f_vty_transceive(BSCVTY, "configure terminal");
3320 f_vty_transceive(BSCVTY, "network");
3321 f_vty_transceive(BSCVTY, "encryption a5 " & options);
3322 f_vty_transceive(BSCVTY, "exit");
3323 f_vty_transceive(BSCVTY, "exit");
3324}
3325
3326private function f_vty_encryption_a5_reset() runs on test_CT {
3327 /* keep in sync with docker-playground.git ttcn3-bsc-test/osmo-bsc.cfg */
3328 f_vty_encryption_a5("0 1 3");
3329}
3330
Harald Welte3c86ea02018-05-10 22:28:05 +02003331/* Establish signalling channel (non-assignment case) followed by cipher mode */
3332private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003333 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3334 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02003335 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02003336 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
3337 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
3338 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
3339 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02003340
Philipp Maier23000732018-05-18 11:25:37 +02003341 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02003342}
3343testcase TC_ciph_mode_a5_0() runs on test_CT {
3344 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003345 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003346 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
3347
3348 f_init(1, true);
3349 f_sleep(1.0);
3350 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3351 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003352 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003353}
3354testcase TC_ciph_mode_a5_1() runs on test_CT {
3355 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003356 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003357 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
3358
3359 f_init(1, true);
3360 f_sleep(1.0);
3361 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3362 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003363 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003364}
Oliver Smith50b98122021-07-09 15:00:28 +02003365/* OS#4975: verify that A5/2 is preferred over A5/0 */
3366testcase TC_ciph_mode_a5_2_0() runs on test_CT {
3367 var MSC_ConnHdlr vc_conn;
3368 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3369
3370 pars.encr := valueof(t_EncrParams('05'O, f_rnd_octstring(8))); /* A5/0 and A5/2 (0x01|0x04)*/
3371 pars.encr_exp_enc_alg := '04'O; /* A5/2 */
3372
3373 f_init(1, true);
3374 f_vty_encryption_a5("0 1 2 3");
3375 f_sleep(1.0);
3376 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3377 vc_conn.done;
3378 f_vty_encryption_a5_reset();
3379 f_shutdown_helper();
3380}
Oliver Smith1dff88d2021-07-09 08:45:51 +02003381/* OS#4975: verify that A5/1 is preferred over A5/2 */
3382testcase TC_ciph_mode_a5_2_1() runs on test_CT {
3383 var MSC_ConnHdlr vc_conn;
3384 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3385
3386 pars.encr := valueof(t_EncrParams('06'O, f_rnd_octstring(8))); /* A5/1 and A5/2 (0x02|0x04)*/
3387 pars.encr_exp_enc_alg := '02'O; /* A5/1 */
3388
3389 f_init(1, true);
3390 f_vty_encryption_a5("1 2");
3391 f_sleep(1.0);
3392 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3393 vc_conn.done;
3394 f_vty_encryption_a5_reset();
3395 f_shutdown_helper();
3396}
Harald Welte3c86ea02018-05-10 22:28:05 +02003397testcase TC_ciph_mode_a5_3() runs on test_CT {
3398 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003399 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003400 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
3401
3402 f_init(1, true);
3403 f_sleep(1.0);
3404 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3405 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003406 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003407}
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003408/* Establish a Signalling channel with A5/4 encryption. */
3409testcase TC_ciph_mode_a5_4() runs on test_CT {
3410 var MSC_ConnHdlr vc_conn;
3411 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3412 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Harald Welte3c86ea02018-05-10 22:28:05 +02003413
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003414 f_init(1, true);
Oliver Smith26a3db72021-07-09 13:51:29 +02003415 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003416 f_sleep(1.0);
3417 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3418 vc_conn.done;
Oliver Smith26a3db72021-07-09 13:51:29 +02003419 f_vty_encryption_a5_reset();
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003420 f_shutdown_helper();
3421}
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003422/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
3423private function f_tc_assignment_aoip_tla_v6(charstring id) runs on MSC_ConnHdlr {
3424 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3425 var PDU_BSSAP ass_cmd := f_gen_ass_req(aoip_tla := "::3");
3426 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3427 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3428
3429 f_establish_fully(ass_cmd, exp_compl);
3430}
3431testcase TC_assignment_aoip_tla_v6() runs on test_CT {
3432 var MSC_ConnHdlr vc_conn;
3433 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3434
3435 f_init(1, true);
3436 f_sleep(1.0);
3437 vc_conn := f_start_handler(refers(f_tc_assignment_aoip_tla_v6), pars);
3438 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003439 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003440}
3441
Harald Welte3c86ea02018-05-10 22:28:05 +02003442
3443/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02003444private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003445 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3446 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003447
Harald Welte552620d2017-12-16 23:21:36 +01003448 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3449 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01003450
Harald Weltea0630032018-03-20 21:09:55 +01003451 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01003452}
Harald Welte552620d2017-12-16 23:21:36 +01003453testcase TC_assignment_fr_a5_0() runs on test_CT {
3454 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003455 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003456 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01003457
Harald Welte89d42e82017-12-17 16:42:41 +01003458 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003459 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003460 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003461 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003462 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003463}
Harald Welte552620d2017-12-16 23:21:36 +01003464testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01003465 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003466 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003467 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003468
Harald Welte89d42e82017-12-17 16:42:41 +01003469 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003470 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003471 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3472 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003473 f_shutdown_helper();
Harald Welte651fcdc2018-05-10 20:23:16 +02003474}
3475testcase TC_assignment_fr_a5_3() runs on test_CT {
3476 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003477 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003478 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003479
Harald Welte651fcdc2018-05-10 20:23:16 +02003480 f_init(1, true);
3481 f_sleep(1.0);
3482 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003483 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003484 f_shutdown_helper();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003485}
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003486/* Establish a Signalling channel and re-assign to TCH/F with A5/4 encryption. */
3487testcase TC_assignment_fr_a5_4() runs on test_CT {
3488 var MSC_ConnHdlr vc_conn;
3489 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3490 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
3491
3492 f_init(1, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02003493 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003494 f_sleep(1.0);
3495 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3496 vc_conn.done;
Oliver Smith7eabd312021-07-12 14:18:56 +02003497 f_vty_encryption_a5_reset();
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003498 f_shutdown_helper();
3499}
Harald Weltec1a2fff2017-12-17 11:06:19 +01003500
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +02003501/* Allow only A5/4, but omit the Kc128 IE from MSC's msg. Expect Cipher Mode Reject. */
3502testcase TC_assignment_fr_a5_4_fail() runs on test_CT {
3503 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3504 var MSC_ConnHdlr vc_conn;
3505
3506 f_init(1, true);
3507 f_sleep(1.0);
3508
3509 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8))); // A5/4 support, but Kc128 missing!
3510 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
3511 vc_conn.done;
3512 f_shutdown_helper();
3513}
3514
Harald Welte552620d2017-12-16 23:21:36 +01003515/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
3516private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003517 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01003518 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02003519 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003520
3521 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003522 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
3523
Harald Weltea0630032018-03-20 21:09:55 +01003524 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01003525}
Harald Welte552620d2017-12-16 23:21:36 +01003526testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
3527 var MSC_ConnHdlr vc_conn;
3528
Harald Welte89d42e82017-12-17 16:42:41 +01003529 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003530 f_sleep(1.0);
3531
Harald Welte8863fa12018-05-10 20:15:27 +02003532 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01003533 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003534 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003535}
3536
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003537private function f_TC_assignment_a5_not_sup(charstring id) runs on MSC_ConnHdlr {
3538 var template PDU_BSSAP exp_ass_cpl := f_gen_exp_compl();
3539 var PDU_BSSAP exp_ass_req := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003540
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003541 exp_ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3542 exp_ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3543
3544 /* this is like the beginning of f_establish_fully(), but only up to ciphering reject */
3545
3546 var BSSMAP_FIELD_CodecType codecType;
3547 timer T := 10.0;
3548
3549 codecType := exp_ass_req.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType;
3550 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
3551
3552 f_create_chan_and_exp();
3553 /* we should now have a COMPL_L3 at the MSC */
3554
3555 var template PDU_BSSAP exp_l3_compl;
3556 exp_l3_compl := tr_BSSMAP_ComplL3()
3557 if (g_pars.aoip == false) {
3558 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := omit;
3559 } else {
3560 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := ?;
3561 }
3562 T.start;
3563 alt {
3564 [] BSSAP.receive(exp_l3_compl);
3565 [] BSSAP.receive(tr_BSSMAP_ComplL3) {
3566 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching COMPLETE LAYER 3 INFORMATION");
3567 }
3568 [] T.timeout {
3569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
3570 }
3571 }
3572
3573 /* Start ciphering, expect Cipher Mode Reject */
Neels Hofmeyr6c388f22021-06-11 02:36:56 +02003574 f_cipher_mode(g_pars.encr, exp_fail := true);
Harald Welte552620d2017-12-16 23:21:36 +01003575}
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003576testcase TC_assignment_fr_a5_not_sup() runs on test_CT {
3577 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01003578 var MSC_ConnHdlr vc_conn;
3579
Harald Welte89d42e82017-12-17 16:42:41 +01003580 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003581 f_sleep(1.0);
3582
Neels Hofmeyr0588cad2021-06-11 01:38:18 +02003583 pars.encr := valueof(t_EncrParams('20'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003584 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003585 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003586 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003587}
3588
3589
Harald Welte4532e0a2017-12-23 02:05:44 +01003590private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003591 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01003592 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02003593 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01003594 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003595
3596 f_statsd_reset();
Harald Weltea0630032018-03-20 21:09:55 +01003597 f_establish_fully(ass_cmd, exp_compl);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003598
3599 var StatsDExpects expect := {
Daniel Willmannc5398f72020-09-21 10:41:35 +02003600 { name := "TTCN3.bts.0.chreq.total", mtype := "c", min := 1, max := 1},
3601 { name := "TTCN3.bts.0.chreq.successful", mtype := "c", min := 1, max := 1},
Daniel Willmannebdecc02020-08-12 15:30:17 +02003602 { name := "TTCN3.bsc.0.assignment.attempted", mtype := "c", min := 1, max := 1},
3603 { name := "TTCN3.bsc.0.assignment.completed", mtype := "c", min := 1, max := 1}
3604 };
3605 f_statsd_expect(expect);
Harald Welte4532e0a2017-12-23 02:05:44 +01003606}
3607
3608testcase TC_assignment_sign() runs on test_CT {
3609 var MSC_ConnHdlr vc_conn;
3610
3611 f_init(1, true);
3612 f_sleep(1.0);
3613
Harald Welte8863fa12018-05-10 20:15:27 +02003614 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01003615 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003616 f_shutdown_helper();
Harald Welte4532e0a2017-12-23 02:05:44 +01003617}
3618
Harald Welte60aa5762018-03-21 19:33:13 +01003619/***********************************************************************
3620 * Codec (list) testing
3621 ***********************************************************************/
3622
3623/* check if the given rsl_mode is compatible with the a_elem */
3624private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
3625return boolean {
3626 select (a_elem.codecType) {
3627 case (GSM_FR) {
3628 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
3629 return true;
3630 }
3631 }
3632 case (GSM_HR) {
3633 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
3634 return true;
3635 }
3636 }
3637 case (GSM_EFR) {
3638 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
3639 return true;
3640 }
3641 }
3642 case (FR_AMR) {
3643 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
3644 return true;
3645 }
3646 }
3647 case (HR_AMR) {
3648 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
3649 return true;
3650 }
3651 }
3652 case else { }
3653 }
3654 return false;
3655}
3656
3657/* check if the given rsl_mode is compatible with the a_list */
3658private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
3659return boolean {
3660 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
3661 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
3662 return true;
3663 }
3664 }
3665 return false;
3666}
3667
3668/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02003669function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01003670return BSSMAP_IE_ChannelType {
3671 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
3672 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
3673 select (a_elem.codecType) {
3674 case (GSM_FR) {
3675 ret.channelRateAndType := ChRate_TCHF;
3676 ret.speechId_DataIndicator := Spdi_TCHF_FR;
3677 }
3678 case (GSM_HR) {
3679 ret.channelRateAndType := ChRate_TCHH;
3680 ret.speechId_DataIndicator := Spdi_TCHH_HR;
3681 }
3682 case (GSM_EFR) {
3683 ret.channelRateAndType := ChRate_TCHF;
3684 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
3685 }
3686 case (FR_AMR) {
3687 ret.channelRateAndType := ChRate_TCHF;
3688 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
3689 }
3690 case (HR_AMR) {
3691 ret.channelRateAndType := ChRate_TCHH;
3692 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
3693 }
3694 case else {
3695 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02003696 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01003697 }
3698 }
3699 return ret;
3700}
3701
Harald Weltea63b9102018-03-22 20:36:16 +01003702private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
3703return template RSL_IE_Body {
3704 var template RSL_IE_Body mode_ie := {
3705 chan_mode := {
3706 len := ?,
3707 reserved := ?,
3708 dtx_d := ?,
3709 dtx_u := ?,
3710 spd_ind := RSL_SPDI_SPEECH,
3711 ch_rate_type := -,
3712 coding_alg_rate := -
3713 }
3714 }
3715
3716 select (a_elem.codecType) {
3717 case (GSM_FR) {
3718 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
3719 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
3720 }
3721 case (GSM_HR) {
3722 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
3723 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
3724 }
3725 case (GSM_EFR) {
3726 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
3727 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
3728 }
3729 case (FR_AMR) {
3730 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
3731 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
3732 }
3733 case (HR_AMR) {
3734 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
3735 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
3736 }
3737 }
3738 return mode_ie;
3739}
3740
Harald Welte60aa5762018-03-21 19:33:13 +01003741type record CodecListTest {
3742 BSSMAP_IE_SpeechCodecList codec_list,
3743 charstring id
3744}
3745type record of CodecListTest CodecListTests
3746
3747private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02003748 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
3749 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
Harald Welte60aa5762018-03-21 19:33:13 +01003750
3751 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003752 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte79f3f542018-05-25 20:02:37 +02003753 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
3754 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
3755 g_pars.ass_codec_list.codecElements[0];
Philipp Maierd0e64b02019-03-13 14:15:23 +01003756 if (isvalue(g_pars.expect_mr_s0_s7)) {
3757 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
3758 g_pars.expect_mr_s0_s7;
3759 }
Harald Welte79f3f542018-05-25 20:02:37 +02003760 }
Harald Welte60aa5762018-03-21 19:33:13 +01003761 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
3762 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01003763 log("expecting ASS COMPL like this: ", exp_compl);
3764
3765 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01003766
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02003767 if (not g_pars.expect_channel_mode_modify) {
3768 /* Verify that the RSL-side activation actually matches our expectations */
3769 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
Harald Weltea63b9102018-03-22 20:36:16 +01003770
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02003771 var RSL_IE_Body mode_ie;
3772 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
3773 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02003774 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02003775 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02003776 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
3777 if (not match(mode_ie, t_mode_ie)) {
3778 log("mode_ie ", mode_ie, " != t_mode_ie ", t_mode_ie);
3779 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02003780 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02003781
3782 var RSL_IE_Body mr_conf;
3783 if (g_pars.expect_mr_conf_ie != omit) {
3784 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
3785 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
3786 mtc.stop;
3787 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02003788 log("found RSL MR CONFIG IE: ", mr_conf);
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02003789
3790 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
3791 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
3792 g_pars.expect_mr_conf_ie);
3793 }
3794 } else {
3795 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
3796 log("found RSL MR CONFIG IE: ", mr_conf);
3797 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
3798 mtc.stop;
3799 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02003800 }
3801 }
Harald Welte60aa5762018-03-21 19:33:13 +01003802}
3803
Philipp Maierd0e64b02019-03-13 14:15:23 +01003804private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
3805
3806 var PDU_BSSAP ass_cmd := f_gen_ass_req();
3807 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
3808
3809 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003810 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maierd0e64b02019-03-13 14:15:23 +01003811 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
3812 }
3813 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
3814 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
3815 log("expecting ASS FAIL like this: ", exp_fail);
3816
3817 f_establish_fully(ass_cmd, exp_fail);
3818}
3819
Harald Welte60aa5762018-03-21 19:33:13 +01003820testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02003821 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01003822 var MSC_ConnHdlr vc_conn;
3823
3824 f_init(1, true);
3825 f_sleep(1.0);
3826
3827 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02003828 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01003829 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003830 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01003831}
3832
3833testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02003834 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01003835 var MSC_ConnHdlr vc_conn;
3836
3837 f_init(1, true);
3838 f_sleep(1.0);
3839
3840 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02003841 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01003842 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003843 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01003844}
3845
3846testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02003847 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01003848 var MSC_ConnHdlr vc_conn;
3849
3850 f_init(1, true);
3851 f_sleep(1.0);
3852
3853 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02003854 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01003855 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003856 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01003857}
3858
Philipp Maierd0e64b02019-03-13 14:15:23 +01003859/* Allow 5,90k only (current default config) */
3860private function f_allow_amr_rate_5_90k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00003861 f_vty_cfg_msc(BSCVTY, 0, {
3862 "amr-config 12_2k forbidden",
3863 "amr-config 10_2k forbidden",
3864 "amr-config 7_95k forbidden",
3865 "amr-config 7_40k forbidden",
3866 "amr-config 6_70k forbidden",
3867 "amr-config 5_90k allowed",
3868 "amr-config 5_15k forbidden",
3869 "amr-config 4_75k forbidden"
3870 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01003871}
3872
3873/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
3874 * ("Config-NB-Code = 1") */
3875private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00003876 f_vty_cfg_msc(BSCVTY, 0, {
3877 "amr-config 12_2k allowed",
3878 "amr-config 10_2k forbidden",
3879 "amr-config 7_95k forbidden",
3880 "amr-config 7_40k allowed",
3881 "amr-config 6_70k forbidden",
3882 "amr-config 5_90k allowed",
3883 "amr-config 5_15k forbidden",
3884 "amr-config 4_75k allowed"
3885 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01003886}
3887
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00003888private function f_vty_amr_start_mode_set(boolean fr, charstring startmode) runs on test_CT {
3889 var charstring tch;
3890 if (fr) {
3891 tch := "tch-f";
3892 } else {
3893 tch := "tch-h";
3894 }
3895 f_vty_cfg_bts(BSCVTY, 0, { "amr " & tch & " start-mode " & startmode });
3896}
3897
3898/* Set the AMR start-mode for this TCH back to the default configuration. */
3899private function f_vty_amr_start_mode_restore(boolean fr) runs on test_CT {
3900 f_vty_amr_start_mode_set(fr, "auto");
3901}
3902
Harald Welte60aa5762018-03-21 19:33:13 +01003903testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02003904 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01003905 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02003906
3907 /* Note: This setups the codec configuration. The parameter payload in
3908 * mr_conf must be consistant with the parameter codecElements in pars
3909 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02003910 var RSL_IE_Body mr_conf := {
3911 other := {
3912 len := 2,
3913 payload := '2804'O
3914 }
3915 };
Harald Welte60aa5762018-03-21 19:33:13 +01003916
Philipp Maier7695a0d2018-09-27 17:52:14 +02003917 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Philipp Maier806f8f12019-03-12 12:13:41 +01003918 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02003919 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
3920 pars.expect_mr_conf_ie := mr_conf;
3921
Harald Welte60aa5762018-03-21 19:33:13 +01003922 f_init(1, true);
3923 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00003924 f_vty_amr_start_mode_set(true, "1");
Harald Welte60aa5762018-03-21 19:33:13 +01003925
Harald Welte8863fa12018-05-10 20:15:27 +02003926 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01003927 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00003928
3929 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01003930 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01003931}
3932
3933testcase TC_assignment_codec_amr_h() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02003934 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01003935 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02003936
3937 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02003938 var RSL_IE_Body mr_conf := {
3939 other := {
3940 len := 2,
3941 payload := '2804'O
3942 }
3943 };
Harald Welte60aa5762018-03-21 19:33:13 +01003944
Philipp Maier7695a0d2018-09-27 17:52:14 +02003945 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Philipp Maier806f8f12019-03-12 12:13:41 +01003946 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02003947 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
3948 pars.expect_mr_conf_ie := mr_conf;
3949
Harald Welte60aa5762018-03-21 19:33:13 +01003950 f_init(1, true);
3951 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00003952 f_vty_amr_start_mode_set(false, "1");
Harald Welte60aa5762018-03-21 19:33:13 +01003953
Harald Welte8863fa12018-05-10 20:15:27 +02003954 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01003955 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00003956
3957 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01003958 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01003959}
3960
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02003961/* Establish signalling on a TCH/F lchan, and then switch to speech mode without a new Assignment. */
3962testcase TC_assignment_codec_fr_by_mode_modify() runs on test_CT {
3963 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3964 var MSC_ConnHdlr vc_conn;
3965
3966 f_init(1, true);
3967 f_sleep(1.0);
3968
3969 /* By disabling all SDCCH, the MS should be given a TCH/F for signalling. Then activating an FR codec should
3970 * merely do a Channel Mode Modify, and not assign to a new lchan. f_establish_fully() already accounts for
3971 * expecting a Channel Mode Modify if the channel type is compatible. */
3972 f_disable_all_sdcch();
3973 f_disable_all_tch_h();
3974
3975 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3976 pars.expect_channel_mode_modify := true;
3977 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
3978 vc_conn.done;
3979
3980 f_enable_all_sdcch();
3981 f_enable_all_tch();
3982 f_shutdown_helper();
3983}
3984
Neels Hofmeyr454d7922020-11-26 02:24:57 +00003985/* 'amr start-mode auto' should not keep the (unused) 'smod' bits from previous configuration */
3986testcase TC_assignment_codec_amr_startmode_cruft() runs on test_CT {
3987 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3988 var MSC_ConnHdlr vc_conn;
3989
3990 var RSL_IE_Body mr_conf := {
3991 other := {
3992 len := 2,
3993 payload := '2004'O /* <- expect ICMI=0, smod=00 */
3994 }
3995 };
3996
3997 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
3998 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
3999 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
4000 pars.expect_mr_conf_ie := mr_conf;
4001
4002 f_init(1, true);
4003 f_sleep(1.0);
4004
4005 /* First set nonzero start mode bits */
4006 f_vty_amr_start_mode_set(true, "4");
4007 /* Now set to auto, and expect the startmode bits to be zero in the message, i.e. ensure that osmo-bsc does not
4008 * let the startmode bits stick around and has deterministic MultiRate config for 'start-mode auto'; that is
4009 * ensured by above '2004'O, where 'x0xx'O indicates ICMI = 0, spare = 0, smod = 00. */
4010 f_vty_amr_start_mode_set(true, "auto");
4011
4012 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4013 vc_conn.done;
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004014
4015 /* Clear the startmode bits to not affect subsequent tests, in case the bits should indeed stick around. */
4016 f_vty_amr_start_mode_set(true, "1");
4017 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004018 f_shutdown_helper();
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004019}
4020
Neels Hofmeyr21863562020-11-26 00:34:33 +00004021function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0,
4022 charstring start_mode := "1")
Philipp Maierd0e64b02019-03-13 14:15:23 +01004023runs on test_CT {
4024
4025 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4026 var MSC_ConnHdlr vc_conn;
4027
4028 /* See note above */
4029 var RSL_IE_Body mr_conf := {
4030 other := {
4031 len := lengthof(mrconf),
4032 payload := mrconf
4033 }
4034 };
4035
4036 if (fr) {
4037 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4038 } else {
4039 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4040 }
4041 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4042 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4043 pars.expect_mr_conf_ie := mr_conf;
4044 pars.expect_mr_s0_s7 := exp_s8_s0;
4045
4046 f_init(1, true);
4047 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004048 f_vty_amr_start_mode_set(fr, start_mode);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004049 f_sleep(1.0);
4050
4051 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4052 vc_conn.done;
4053 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004054 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004055}
4056
4057function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
4058runs on test_CT {
4059
4060 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4061 var MSC_ConnHdlr vc_conn;
4062
4063 if (fr) {
4064 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4065 } else {
4066 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4067 }
4068 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4069 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4070
4071 f_init(1, true);
4072 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004073 f_vty_amr_start_mode_set(fr, "1");
Philipp Maierd0e64b02019-03-13 14:15:23 +01004074 f_sleep(1.0);
4075
4076 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
4077 vc_conn.done;
4078 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004079 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004080}
4081
4082
4083/* Set S1, we expect an AMR multirate configuration IE with all four rates
4084 * set. */
4085testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004086 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004087 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004088}
4089
4090/* Set S1, we expect an AMR multirate configuration IE with the lower three
4091 * rates set. */
4092testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004093 f_TC_assignment_codec_amr(false, '2815208820'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004094 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004095}
4096
4097/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4098 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4099testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004100 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004101 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004102}
4103
4104/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4105 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4106testcase TC_assignment_codec_amr_h_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004107 f_TC_assignment_codec_amr(false, '2815208820'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004108 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004109}
4110
4111/* The following block of tests selects more and more rates until all four
4112 * possible rates are in the active set (full rate) */
4113testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004114 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004115 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004116}
4117
4118testcase TC_assignment_codec_amr_f_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004119 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004120 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004121}
4122
4123testcase TC_assignment_codec_amr_f_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004124 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004125 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004126}
4127
4128testcase TC_assignment_codec_amr_f_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004129 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004130 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004131}
4132
4133/* The following block of tests selects more and more rates until all three
4134 * possible rates are in the active set (half rate) */
4135testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004136 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004137 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004138}
4139
4140testcase TC_assignment_codec_amr_h_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004141 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004142 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004143}
4144
4145testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004146 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004147 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004148}
4149
4150/* The following block tests what happens when the MSC does offer rate
4151 * configurations that are not supported by the BSC. Normally such situations
4152 * should not happen because the MSC gets informed by the BSC in advance via
4153 * the L3 COMPLETE message which rates are applicable. The MSC should not try
4154 * to offer rates that are not applicable anyway. */
4155
4156testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004157 /* Try to include 12,2k in into the active set even though the channel
4158 * is half rate only. The BSC is expected to remove the 12,0k */
4159 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004160 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004161}
4162
4163testcase TC_assignment_codec_amr_f_S01234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004164 /* See what happens when all rates are selected at once. Since then
4165 * Also S1 is selected, this setting will be prefered and we should
4166 * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
4167 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004168 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004169}
4170
4171testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004172 /* Same as above, but with S1 missing, the MSC is then expected to
4173 * select the currently supported rates, which are also 12.2k, 7,40k,
4174 * 5,90k, and 4,75k, into the active set. */
4175 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004176 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004177}
4178
4179testcase TC_assignment_codec_amr_f_zero() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004180 /* Try to select no rates at all */
4181 f_TC_assignment_codec_amr_fail(true, '00000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004182 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004183}
4184
4185testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004186 /* Try to select only unsupported rates */
4187 f_TC_assignment_codec_amr_fail(true, '01101000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004188 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004189}
4190
4191testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004192 /* Try to select 12,2k for half rate */
4193 f_TC_assignment_codec_amr_fail(false, '10000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004194 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004195}
4196
Neels Hofmeyr21863562020-11-26 00:34:33 +00004197testcase TC_assignment_codec_amr_f_start_mode_auto() runs on test_CT {
4198 f_TC_assignment_codec_amr(true, '209520882208'O, '11111111'B, '00000010'B,
4199 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004200 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004201}
4202
4203testcase TC_assignment_codec_amr_h_start_mode_auto() runs on test_CT {
4204 f_TC_assignment_codec_amr(false, '2015208820'O, '10010101'B, '00010101'B,
4205 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004206 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004207}
4208
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004209testcase TC_assignment_codec_amr_f_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004210 /* "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 +00004211 f_TC_assignment_codec_amr(true, '2b9520882208'O, '11111111'B, '00000010'B,
4212 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004213 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004214}
4215
4216testcase TC_assignment_codec_amr_h_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004217 /* "amr tch-h modes 0 2 4" => total 3 modes and start mode 4 => '10'B on the wire */
4218 f_TC_assignment_codec_amr(false, '2a15208820'O, '10010101'B, '00010101'B,
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004219 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004220 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004221}
4222
Philipp Maierac09bfc2019-01-08 13:41:39 +01004223private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004224 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
4225 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
4226 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
4227 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004228}
4229
4230private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004231 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
4232 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004233}
4234
4235private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004236 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
4237 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
4238 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
4239 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
4240 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
4241 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004242}
4243
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004244private function f_disable_all_sdcch() runs on test_CT {
4245 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 borken");
4246 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 borken");
4247 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 borken");
4248 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 borken");
4249}
4250
4251private function f_enable_all_sdcch() runs on test_CT {
4252 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 unused");
4253 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 unused");
4254 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 unused");
4255 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 unused");
4256}
4257
Philipp Maierac09bfc2019-01-08 13:41:39 +01004258/* Allow HR only */
4259private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
4260 g_pars := f_gen_test_hdlr_pars();
4261 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4262 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4263 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4264 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4265 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4266 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4267 f_establish_fully(ass_cmd, exp_compl);
4268}
4269
4270/* Allow FR only */
4271private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
4272 g_pars := f_gen_test_hdlr_pars();
4273 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4274 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4275 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4276 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4277 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4278 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4279 f_establish_fully(ass_cmd, exp_compl);
4280}
4281
4282/* Allow HR only (expect assignment failure) */
4283private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
4284 g_pars := f_gen_test_hdlr_pars();
4285 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4286 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4287 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4288 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4289 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4290 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4291 f_establish_fully(ass_cmd, exp_fail);
4292}
4293
4294/* Allow FR only (expect assignment failure) */
4295private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(charstring id) runs on MSC_ConnHdlr {
4296 g_pars := f_gen_test_hdlr_pars();
4297 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4298 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4299 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4300 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4301 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4302 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4303 f_establish_fully(ass_cmd, exp_fail);
4304}
4305
4306/* Allow FR and HR, but prefer FR */
4307private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4308 g_pars := f_gen_test_hdlr_pars();
4309 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4310 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4311 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4312 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4313 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4314 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4315 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4316 f_establish_fully(ass_cmd, exp_compl);
4317}
4318
4319/* Allow FR and HR, but prefer HR */
4320private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4321 g_pars := f_gen_test_hdlr_pars();
4322 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4323 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4324 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4325 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4326 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4327 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4328 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4329 f_establish_fully(ass_cmd, exp_compl);
4330}
4331
4332/* Allow FR and HR, but prefer FR */
4333private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4334 g_pars := f_gen_test_hdlr_pars();
4335 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4336 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4337 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4338 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4339 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4340 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4341 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4342 f_establish_fully(ass_cmd, exp_compl);
4343}
4344
4345/* Allow FR and HR, but prefer HR */
4346private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4347 g_pars := f_gen_test_hdlr_pars();
4348 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4349 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4350 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4351 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4352 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4353 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4354 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4355 f_establish_fully(ass_cmd, exp_compl);
4356}
4357
4358/* Request a HR channel while all FR channels are exhausted, this is expected
4359 * to work without conflicts */
4360testcase TC_assignment_codec_fr_exhausted_req_hr() runs on test_CT {
4361 var MSC_ConnHdlr vc_conn;
4362 f_init(1, true);
4363 f_sleep(1.0);
4364 f_enable_all_tch();
4365 f_disable_all_tch_f();
4366 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr));
4367 vc_conn.done;
4368 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004369 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004370}
4371
4372/* Request a FR channel while all FR channels are exhausted, this is expected
4373 * to fail. */
4374testcase TC_assignment_codec_fr_exhausted_req_fr() runs on test_CT {
4375 var MSC_ConnHdlr vc_conn;
4376 f_init(1, true);
4377 f_sleep(1.0);
4378 f_enable_all_tch();
4379 f_disable_all_tch_f();
4380 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr_fail));
4381 vc_conn.done;
4382 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004383 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004384}
4385
4386/* Request a FR (prefered) or alternatively a HR channel while all FR channels
4387 * are exhausted, this is expected to be resolved by selecting a HR channel. */
4388testcase TC_assignment_codec_fr_exhausted_req_fr_hr() runs on test_CT {
4389 var MSC_ConnHdlr vc_conn;
4390 f_init(1, true);
4391 f_sleep(1.0);
4392 f_enable_all_tch();
4393 f_disable_all_tch_f();
4394 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
4395 vc_conn.done;
4396 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004397 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004398}
4399
4400/* Request a HR (prefered) or alternatively a FR channel while all FR channels
4401 * are exhausted, this is expected to work without conflicts. */
4402testcase TC_assignment_codec_fr_exhausted_req_hr_fr() runs on test_CT {
4403 var MSC_ConnHdlr vc_conn;
4404 f_init(1, true);
4405 f_sleep(1.0);
4406 f_enable_all_tch();
4407 f_disable_all_tch_f();
4408 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_hr_fr));
4409 vc_conn.done;
4410 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004411 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004412}
4413
4414/* Request a FR channel while all HR channels are exhausted, this is expected
4415 * to work without conflicts */
4416testcase TC_assignment_codec_hr_exhausted_req_fr() runs on test_CT {
4417 var MSC_ConnHdlr vc_conn;
4418 f_init(1, true);
4419 f_sleep(1.0);
4420 f_enable_all_tch();
4421 f_disable_all_tch_h();
4422 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr));
4423 vc_conn.done;
4424 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004425 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004426}
4427
4428/* Request a HR channel while all HR channels are exhausted, this is expected
4429 * to fail. */
4430testcase TC_assignment_codec_hr_exhausted_req_hr() runs on test_CT {
4431 var MSC_ConnHdlr vc_conn;
4432 f_init(1, true);
4433 f_sleep(1.0);
4434 f_enable_all_tch();
4435 f_disable_all_tch_h();
4436 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr_fail));
4437 vc_conn.done;
4438 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004439 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004440}
4441
4442/* Request a HR (prefered) or alternatively a FR channel while all HR channels
4443 * are exhausted, this is expected to be resolved by selecting a FR channel. */
4444testcase TC_assignment_codec_hr_exhausted_req_hr_fr() runs on test_CT {
4445 var MSC_ConnHdlr vc_conn;
4446 f_init(1, true);
4447 f_sleep(1.0);
4448 f_enable_all_tch();
4449 f_disable_all_tch_h();
4450 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_hr_fr));
4451 vc_conn.done;
4452 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004453 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004454}
4455
4456/* Request a FR (prefered) or alternatively a HR channel while all HR channels
4457 * are exhausted, this is expected to work without conflicts. */
4458testcase TC_assignment_codec_hr_exhausted_req_fr_hr() runs on test_CT {
4459 var MSC_ConnHdlr vc_conn;
4460 f_init(1, true);
4461 f_sleep(1.0);
4462 f_enable_all_tch();
4463 f_disable_all_tch_h();
4464 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_fr_hr));
4465 vc_conn.done;
4466 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004467 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004468}
4469
4470/* Allow FR and HR, but prefer HR */
4471private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4472 g_pars := f_gen_test_hdlr_pars();
4473 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4474 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4475 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4476 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4477 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4478 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4479 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4480 f_establish_fully(ass_cmd, exp_compl);
4481}
4482
4483/* Allow FR and HR, but prefer FR */
4484private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4485 g_pars := f_gen_test_hdlr_pars();
4486 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4487 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4488 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4489 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4490 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4491 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4492 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4493 f_establish_fully(ass_cmd, exp_compl);
4494}
4495
4496/* Request a HR (prefered) or alternatively a FR channel, it is expected that
4497 * HR, which is the prefered type, is selected. */
4498testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
4499 var MSC_ConnHdlr vc_conn;
4500 f_init(1, true);
4501 f_sleep(1.0);
4502 f_enable_all_tch();
4503 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
4504 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004505 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004506}
4507
4508/* Request a FR (prefered) or alternatively a HR channel, it is expected that
4509 * FR, which is the prefered type, is selected. */
4510testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
4511 var MSC_ConnHdlr vc_conn;
4512 f_init(1, true);
4513 f_sleep(1.0);
4514 f_enable_all_tch();
4515 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
4516 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004517 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004518}
4519
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004520testcase TC_assignment_osmux() runs on test_CT {
4521 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4522 var MSC_ConnHdlr vc_conn;
4523
4524 /* See note above */
4525 var RSL_IE_Body mr_conf := {
4526 other := {
4527 len := 2,
4528 payload := '2804'O
4529 }
4530 };
4531
4532 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4533 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
4534 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4535 pars.expect_mr_conf_ie := mr_conf;
4536 pars.use_osmux := true;
4537
4538 f_init(1, true, true);
4539 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004540 f_vty_amr_start_mode_set(false, "1");
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004541
4542 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4543 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004544
4545 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004546 f_shutdown_helper();
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004547}
4548
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02004549/* test the procedure of the MSC requesting a Classmark Update:
4550 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
4551 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01004552private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02004553 g_pars := f_gen_test_hdlr_pars();
4554
Harald Weltea0630032018-03-20 21:09:55 +01004555 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01004556 /* we should now have a COMPL_L3 at the MSC */
4557 BSSAP.receive(tr_BSSMAP_ComplL3);
4558
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02004559 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
4560 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
4561
Harald Welte898113b2018-01-31 18:32:21 +01004562 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
4563 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
4564 setverdict(pass);
4565}
4566testcase TC_classmark() runs on test_CT {
4567 var MSC_ConnHdlr vc_conn;
4568 f_init(1, true);
4569 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02004570 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01004571 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004572 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01004573}
4574
Harald Welteeddf0e92020-06-21 19:42:15 +02004575/* Send a CommonID from the simulated MSC and verify that the information is used to
4576 * fill BSC-internal data structures (specifically, bsc_subscr associated with subscr_conn) */
4577private function f_tc_common_id(charstring id) runs on MSC_ConnHdlr {
4578 g_pars := f_gen_test_hdlr_pars();
4579 f_MscConnHdlr_init_vty();
4580
4581 f_create_chan_and_exp();
4582 /* we should now have a COMPL_L3 at the MSC */
4583 BSSAP.receive(tr_BSSMAP_ComplL3);
4584
4585 /* Send CommonID */
4586 BSSAP.send(ts_BSSMAP_CommonId(g_pars.imsi));
4587
4588 /* Use VTY to verify that the IMSI of the subscr_conn is set */
4589 var charstring regex := "*(IMSI: " & hex2str(g_pars.imsi) & ")*";
4590 f_vty_transceive_match_regexp_retry(BSCVTY, "show conns", regex, 0, 4, 1.0);
4591
4592 setverdict(pass);
4593}
4594testcase TC_common_id() runs on test_CT {
4595 var MSC_ConnHdlr vc_conn;
4596 f_init(1, true);
4597 f_sleep(1.0);
4598 vc_conn := f_start_handler(refers(f_tc_common_id));
4599 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004600 f_shutdown_helper();
Harald Welteeddf0e92020-06-21 19:42:15 +02004601}
4602
Harald Weltee3bd6582018-01-31 22:51:25 +01004603private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02004604 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01004605 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01004606 /* we should now have a COMPL_L3 at the MSC */
4607 BSSAP.receive(tr_BSSMAP_ComplL3);
4608
Harald Weltee3bd6582018-01-31 22:51:25 +01004609 /* send the single message we want to send */
4610 f_rsl_send_l3(l3);
4611}
4612
4613private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
4614 timer T := sec;
4615 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01004616 T.start;
4617 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01004618 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
4619 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02004620 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01004621 }
4622 [] T.timeout {
4623 setverdict(pass);
4624 }
4625 }
4626}
4627
Harald Weltee3bd6582018-01-31 22:51:25 +01004628/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
4629private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
4630 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
4631 f_bssap_expect_nothing();
4632}
Harald Welte898113b2018-01-31 18:32:21 +01004633testcase TC_unsol_ass_fail() runs on test_CT {
4634 var MSC_ConnHdlr vc_conn;
4635 f_init(1, true);
4636 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02004637 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01004638 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004639 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01004640}
Harald Welte552620d2017-12-16 23:21:36 +01004641
Harald Welteea99a002018-01-31 20:46:43 +01004642
4643/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
4644private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01004645 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
4646 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01004647}
4648testcase TC_unsol_ass_compl() runs on test_CT {
4649 var MSC_ConnHdlr vc_conn;
4650 f_init(1, true);
4651 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02004652 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01004653 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004654 f_shutdown_helper();
Harald Welteea99a002018-01-31 20:46:43 +01004655}
4656
4657
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004658/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
4659private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01004660 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
4661 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004662}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004663testcase TC_unsol_ho_fail() runs on test_CT {
4664 var MSC_ConnHdlr vc_conn;
4665 f_init(1, true);
4666 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02004667 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004668 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004669 f_shutdown_helper();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004670}
4671
4672
Harald Weltee3bd6582018-01-31 22:51:25 +01004673/* short message from MS should be ignored */
4674private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02004675 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01004676 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01004677 /* we should now have a COMPL_L3 at the MSC */
4678 BSSAP.receive(tr_BSSMAP_ComplL3);
4679
4680 /* send short message */
4681 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
4682 f_bssap_expect_nothing();
4683}
4684testcase TC_err_82_short_msg() runs on test_CT {
4685 var MSC_ConnHdlr vc_conn;
4686 f_init(1, true);
4687 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02004688 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01004689 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004690 f_shutdown_helper();
Harald Weltee3bd6582018-01-31 22:51:25 +01004691}
4692
4693
Harald Weltee9e02e42018-01-31 23:36:25 +01004694/* 24.008 8.4 Unknown message must trigger RR STATUS */
4695private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
4696 f_est_single_l3(ts_RRM_UL_REL('00'O));
4697 timer T := 3.0
4698 alt {
4699 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
4700 setverdict(pass);
4701 }
4702 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01004703 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01004704 }
4705}
4706testcase TC_err_84_unknown_msg() runs on test_CT {
4707 var MSC_ConnHdlr vc_conn;
4708 f_init(1, true);
4709 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02004710 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01004711 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004712 f_shutdown_helper();
Harald Weltee9e02e42018-01-31 23:36:25 +01004713}
4714
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004715/***********************************************************************
4716 * Handover
4717 ***********************************************************************/
4718
Harald Welte94e0c342018-04-07 11:33:23 +02004719/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
4720private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
4721runs on test_CT {
4722 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
4723 " timeslot "&int2str(ts_nr)&" ";
4724 f_vty_transceive(BSCVTY, cmd & suffix);
4725}
4726
Harald Welte261af4b2018-02-12 21:20:39 +01004727/* 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 +07004728private function f_vty_ss_action(TELNETasp_PT pt, charstring suffix,
4729 uint8_t bts_nr, uint8_t trx_nr,
4730 in RslChannelNr chan_nr)
4731{
Harald Welte261af4b2018-02-12 21:20:39 +01004732 /* FIXME: resolve those from component-global state */
4733 var integer ts_nr := chan_nr.tn;
4734 var integer ss_nr;
4735 if (ischosen(chan_nr.u.ch0)) {
4736 ss_nr := 0;
4737 } else if (ischosen(chan_nr.u.lm)) {
4738 ss_nr := chan_nr.u.lm.sub_chan;
4739 } else if (ischosen(chan_nr.u.sdcch4)) {
4740 ss_nr := chan_nr.u.sdcch4.sub_chan;
4741 } else if (ischosen(chan_nr.u.sdcch8)) {
4742 ss_nr := chan_nr.u.sdcch8.sub_chan;
4743 } else {
4744 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02004745 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01004746 }
4747
4748 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
4749 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
Vadim Yanitskiy00070722020-09-02 17:27:57 +07004750 f_vty_transceive(pt, cmd & suffix);
Harald Welte261af4b2018-02-12 21:20:39 +01004751}
4752
Neels Hofmeyr91401012019-07-11 00:42:35 +02004753/* Even though the VTY command to trigger handover takes a new BTS number as argument, behind the scenes osmo-bsc always
4754 * translates that to a target ARFCN+BSIC first. See bsc_vty.c trigger_ho_or_as(), which puts the selected BTS' neighbor
4755 * ident key (ARFCN + BSIC) in the struct passed on to handover_request(). handover_start() then resolves that to a
4756 * viable actual neighbor cell. So from the internal osmo-bsc perspective, we always request handover to an ARFCN + BSIC
4757 * pair, not really to a specific BTS number. */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07004758private function f_vty_handover(TELNETasp_PT pt, uint8_t bts_nr, uint8_t trx_nr,
4759 in RslChannelNr chan_nr, uint8_t new_bts_nr)
4760{
4761 f_vty_ss_action(pt, "handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
Harald Welte261af4b2018-02-12 21:20:39 +01004762}
4763
4764/* intra-BSC hand-over between BTS0 and BTS1 */
4765private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02004766 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4767 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01004768
4769 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4770 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4771
Harald Weltea0630032018-03-20 21:09:55 +01004772 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr666f0432020-07-04 00:53:07 +02004773 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Harald Welte261af4b2018-02-12 21:20:39 +01004774
4775 var HandoverState hs := {
4776 rr_ho_cmpl_seen := false,
4777 handover_done := false,
4778 old_chan_nr := -
4779 };
4780 /* issue hand-over command on VTY */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07004781 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
Harald Welte261af4b2018-02-12 21:20:39 +01004782 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
4783 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02004784
4785 /* From the MGW perspective, a handover is is characterized by
4786 * performing one MDCX operation with the MGW. So we expect to see
4787 * one more MDCX during handover. */
4788 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
4789
Harald Welte261af4b2018-02-12 21:20:39 +01004790 alt {
4791 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01004792 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02004793
Philipp Maier4dae0652018-11-12 12:03:26 +01004794 /* Since this is an internal handover we expect the BSC to inform the
4795 * MSC about the event */
4796 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
4797
Philipp Maier3e2af5d2018-07-11 17:01:05 +02004798 /* Check the amount of MGCP transactions is still consistant with the
4799 * test expectation */
4800 f_check_mgcp_expectations()
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02004801
4802 /* Ensure the Channel Activation for the new channel contained the right encryption params. as_handover() set
4803 * g_chan_nr to the new lchan that was handed over to. It lives in bts 1, so look it up at RSL1_PROC. */
4804 f_verify_encr_info(f_rslem_get_last_act(RSL1_PROC, 0, g_chan_nr));
4805
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01004806 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01004807}
4808
4809testcase TC_ho_int() runs on test_CT {
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02004810 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte261af4b2018-02-12 21:20:39 +01004811 var MSC_ConnHdlr vc_conn;
4812 f_init(2, true);
4813 f_sleep(1.0);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00004814
4815 f_ctrs_bsc_and_bts_init();
4816
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02004817 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
Harald Welte261af4b2018-02-12 21:20:39 +01004818 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00004819
4820 /* from f_establish_fully() */
4821 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
4822 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
4823 /* from handover */
4824 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
4825 f_ctrs_bsc_and_bts_add(0, "handover:completed");
4826 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
4827 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
4828 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004829 f_shutdown_helper();
Harald Welte261af4b2018-02-12 21:20:39 +01004830}
Harald Weltee9e02e42018-01-31 23:36:25 +01004831
Oliver Smith7eabd312021-07-12 14:18:56 +02004832function 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 +02004833 var MSC_ConnHdlr vc_conn;
4834 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4835 pars.encr := valueof(t_EncrParams(encr_alg, f_rnd_octstring(8), f_rnd_octstring(16)));
4836
4837 f_init(2, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02004838 f_vty_encryption_a5(enc_a5);
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02004839 f_sleep(1.0);
4840
4841 f_ctrs_bsc_and_bts_init();
4842
4843 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
4844 vc_conn.done;
4845
4846 /* from f_establish_fully() */
4847 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
4848 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
4849 /* from handover */
4850 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
4851 f_ctrs_bsc_and_bts_add(0, "handover:completed");
4852 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
4853 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
4854 f_ctrs_bsc_and_bts_verify();
Oliver Smith7eabd312021-07-12 14:18:56 +02004855 f_vty_encryption_a5_reset();
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02004856 f_shutdown_helper();
4857}
4858
4859testcase TC_ho_int_a5_0() runs on test_CT {
4860 f_tc_ho_int_a5('01'O);
4861}
4862
4863testcase TC_ho_int_a5_1() runs on test_CT {
4864 f_tc_ho_int_a5('02'O);
4865}
4866
4867testcase TC_ho_int_a5_3() runs on test_CT {
4868 f_tc_ho_int_a5('08'O);
4869}
4870
4871testcase TC_ho_int_a5_4() runs on test_CT {
Oliver Smith7eabd312021-07-12 14:18:56 +02004872 f_tc_ho_int_a5('10'O, "0 1 3 4");
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02004873}
4874
Neels Hofmeyr5f144212020-11-03 15:41:58 +00004875/* intra-BSC hand-over with CONNection FAILure and cause Radio Link Failure: check RR release cause */
4876private function f_tc_ho_int_radio_link_failure(charstring id) runs on MSC_ConnHdlr {
4877 g_pars := f_gen_test_hdlr_pars();
4878 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4879 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr5f144212020-11-03 15:41:58 +00004880
4881 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4882 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4883
4884 f_establish_fully(ass_cmd, exp_compl);
4885 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
4886
4887 var HandoverState hs := {
4888 rr_ho_cmpl_seen := false,
4889 handover_done := false,
4890 old_chan_nr := -
4891 };
4892 /* issue hand-over command on VTY */
4893 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
4894 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
4895 f_rslem_suspend(RSL1_PROC);
4896
4897 /* From the MGW perspective, a handover is is characterized by
4898 * performing one MDCX operation with the MGW. So we expect to see
4899 * one more MDCX during handover. */
4900 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
4901
4902 var RSL_Message rsl;
4903 var PDU_ML3_NW_MS l3;
4904 var RslChannelNr new_chan_nr;
4905 var GsmArfcn arfcn;
4906 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
4907 l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
4908 if (not ischosen(l3.msgs.rrm.handoverCommand)) {
4909 setverdict(fail, "Expected handoverCommand");
4910 mtc.stop;
4911 }
4912 }
4913 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
4914 new_chan_nr, arfcn);
4915
4916 f_rslem_register(0, new_chan_nr, RSL1_PROC);
4917
4918 /* resume processing of RSL DChan messages, which was temporarily suspended
4919 * before performing a hand-over */
4920 f_rslem_resume(RSL1_PROC);
4921 RSL1.receive(tr_RSL_IPA_CRCX(new_chan_nr));
4922
4923 f_sleep(1.0);
4924
4925 /* Handover fails because no HANDO DET appears on the new lchan,
4926 * and the old lchan reports a Radio Link Failure. */
4927 RSL.send(ts_RSL_CONN_FAIL_IND(g_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
4928
4929 var PDU_BSSAP rx_clear_request;
4930 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
4931 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
4932 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
4933
4934 var RR_Cause rr_cause := GSM48_RR_CAUSE_ABNORMAL_UNSPEC;
4935
4936 var MgcpCommand mgcp;
4937 interleave {
4938 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE(int2oct(enum2int(rr_cause), 1)))) {}
4939 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
4940 [] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
4941 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
4942 }
4943 [] RSL1.receive(tr_RSL_DEACT_SACCH(new_chan_nr)) {}
4944 [] RSL1.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
4945 RSL1.send(ts_RSL_RF_CHAN_REL_ACK(new_chan_nr));
4946 }
4947 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {}
4948 }
4949
4950 f_sleep(0.5);
4951 setverdict(pass);
4952}
4953testcase TC_ho_int_radio_link_failure() runs on test_CT {
4954 var MSC_ConnHdlr vc_conn;
4955 f_init(2, true);
4956 f_sleep(1.0);
4957
4958 f_ctrs_bsc_and_bts_init();
4959
4960 vc_conn := f_start_handler(refers(f_tc_ho_int_radio_link_failure));
4961 vc_conn.done;
4962
4963 /* from f_establish_fully() */
4964 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
4965 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
4966 /* from handover */
4967 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
4968 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
4969 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
4970 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:stopped");
4971 f_ctrs_bsc_and_bts_verify();
4972 f_shutdown_helper();
4973}
4974
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004975/* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02004976private function f_expect_dlcx_conns() runs on MSC_ConnHdlr {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004977 var MgcpCommand mgcp;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02004978 var template MgcpResponse mgcp_resp;
4979 var MGCP_RecvFrom mrf;
4980 var template MgcpMessage msg_resp;
4981 var template MgcpMessage msg_dlcx := {
4982 command := tr_DLCX()
4983 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004984
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02004985 if (g_pars.aoip) {
4986 MGCP.receive(tr_DLCX()) -> value mgcp {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004987 log("Got first DLCX: ", mgcp);
4988 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02004989 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004990
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004991 MGCP.receive(tr_DLCX()) -> value mgcp {
4992 log("Got second DLCX: ", mgcp);
4993 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
4994 };
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02004995 } else {
4996 /* For SCCPLite, BSC doesn't handle the MSC-side */
4997 MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_dlcx)) -> value mrf {
4998 log("Got first DLCX: ", mrf.msg.command);
4999 msg_resp := {
5000 response := ts_DLCX_ACK2(mrf.msg.command.line.trans_id)
5001 }
5002 MGCP_MULTI.send(t_MGCP_SendToMrf(mrf, msg_resp));
5003 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005004 }
5005
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005006 BSSAP.receive(tr_BSSMAP_ClearComplete);
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005007}
5008
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005009private 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 +01005010
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005011 f_bts_0_cfg(BSCVTY, {"neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005012 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5013
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005014 BSSAP.receive(tr_BSSMAP_HandoverRequired(exp_oldToNewBSSIEs));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005015
5016 f_sleep(0.5);
5017 /* The MSC negotiates Handover Request and Handover Request Ack with
5018 * the other BSS and comes back with a BSSMAP Handover Command
5019 * containing an RR Handover Command coming from the target BSS... */
5020
5021 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5022 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5023 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5024 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5025 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5026
5027 /* expect the Handover Command to go out on RR */
5028 var RSL_Message rsl_ho_cmd
5029 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5030 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5031 var RSL_IE_Body rsl_ho_cmd_l3;
5032 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5033 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5034 setverdict(fail);
5035 } else {
5036 log("Found L3 Info: ", rsl_ho_cmd_l3);
5037 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5038 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5039 setverdict(fail);
5040 } else {
5041 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5042 setverdict(pass);
5043 }
5044 }
5045
5046 /* When the other BSS has reported a completed handover, this side is
5047 * torn down. */
5048
5049 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
5050 var BssmapCause cause := enum2int(cause_val);
5051 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5052
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005053 f_expect_dlcx_conns();
Pau Espin Pedrol06199952021-06-15 11:30:00 +02005054
5055 interleave {
5056 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE));
5057 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr));
5058 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr));
5059 }
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005060 setverdict(pass);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005061}
5062
5063private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
5064 g_pars := f_gen_test_hdlr_pars();
5065 var PDU_BSSAP ass_req := f_gen_ass_req();
5066 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5067 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5068 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5069 f_establish_fully(ass_req, exp_compl);
5070
5071 f_ho_out_of_this_bsc();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005072}
5073testcase TC_ho_out_of_this_bsc() runs on test_CT {
5074 var MSC_ConnHdlr vc_conn;
5075
5076 f_init(1, true);
5077 f_sleep(1.0);
5078
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005079 f_ctrs_bsc_and_bts_init();
5080
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005081 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
5082 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005083
5084 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5085 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5086 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5087 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5088 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5089 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed");
5090 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005091 f_shutdown_helper();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005092}
5093
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005094private function f_mo_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5095 template (value) RslLinkId link_id := ts_RslLinkID_DCCH(0),
Vadim Yanitskiy2ef6a2f2020-10-08 23:17:32 +07005096 template (present) OCT1 dlci := ?,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005097 octetstring l3 := '0123456789'O)
5098runs on MSC_ConnHdlr {
Neels Hofmeyr43654812020-09-25 01:35:35 +02005099 /* The old lchan and conn should still be active. See that arbitrary L3
5100 * is still going through. */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005101 rsl.send(ts_RSL_DATA_IND(g_chan_nr, link_id, l3));
Neels Hofmeyr43654812020-09-25 01:35:35 +02005102 var template PDU_BSSAP exp_data := {
5103 discriminator := '1'B,
5104 spare := '0000000'B,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005105 dlci := dlci,
5106 lengthIndicator := lengthof(l3),
Neels Hofmeyr43654812020-09-25 01:35:35 +02005107 pdu := {
5108 dtap := l3
5109 }
5110 };
5111 BSSAP.receive(exp_data);
5112 setverdict(pass);
5113}
5114
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005115private function f_mt_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5116 template (present) RslLinkId link_id := tr_RslLinkID_DCCH(0),
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005117 template (value) OCT1 dlci := '00'O,
5118 octetstring l3 := '0123456789'O)
5119runs on MSC_ConnHdlr {
5120 BSSAP.send(PDU_BSSAP:{
5121 discriminator := '1'B,
5122 spare := '0000000'B,
5123 dlci := dlci,
5124 lengthIndicator := lengthof(l3),
5125 pdu := {
5126 dtap := l3
5127 }
5128 });
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005129 rsl.receive(tr_RSL_DATA_REQ(g_chan_nr, link_id, l3));
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005130 setverdict(pass);
5131}
5132
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005133/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
5134 * simply never sends a BSSMAP Handover Command. */
5135private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005136 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005137
5138 var PDU_BSSAP ass_req := f_gen_ass_req();
5139 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5140 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5141 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5142 f_establish_fully(ass_req, exp_compl);
5143
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005144 f_bts_0_cfg(BSCVTY, {"neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005145 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5146
5147 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5148
5149 /* osmo-bsc should time out 10 seconds after the handover started.
5150 * Let's give it a bit extra. */
5151 f_sleep(15.0);
5152
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005153 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005154 f_sleep(1.0);
5155}
5156testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
5157 var MSC_ConnHdlr vc_conn;
5158
5159 f_init(1, true);
5160 f_sleep(1.0);
5161
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005162 f_ctrs_bsc_and_bts_init();
5163
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005164 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
5165 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005166
5167 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5168 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5169 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5170 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5171 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5172 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5173 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005174 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005175}
5176
5177/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
5178 * RR Handover Failure. */
5179private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005180 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005181
5182 var PDU_BSSAP ass_req := f_gen_ass_req();
5183 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5184 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5185 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5186 f_establish_fully(ass_req, exp_compl);
5187
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005188 f_bts_0_cfg(BSCVTY, {"neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005189 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5190
5191 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5192
5193 f_sleep(0.5);
5194 /* The MSC negotiates Handover Request and Handover Request Ack with
5195 * the other BSS and comes back with a BSSMAP Handover Command
5196 * containing an RR Handover Command coming from the target BSS... */
5197
5198 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5199 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5200 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5201 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5202 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5203
5204 /* expect the Handover Command to go out on RR */
5205 var RSL_Message rsl_ho_cmd
5206 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5207 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5208 var RSL_IE_Body rsl_ho_cmd_l3;
5209 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5210 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5211 setverdict(fail);
5212 } else {
5213 log("Found L3 Info: ", rsl_ho_cmd_l3);
5214 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5215 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5216 setverdict(fail);
5217 } else {
5218 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5219 setverdict(pass);
5220 }
5221 }
5222
5223 f_sleep(0.2);
5224 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
5225
5226 /* Should tell the MSC about the failure */
5227 BSSAP.receive(tr_BSSMAP_HandoverFailure);
5228
5229 f_sleep(1.0);
5230
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005231 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005232 f_sleep(1.0);
5233
5234 setverdict(pass);
5235 f_sleep(1.0);
5236}
5237testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
5238 var MSC_ConnHdlr vc_conn;
5239
5240 f_init(1, true);
5241 f_sleep(1.0);
5242
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005243 f_ctrs_bsc_and_bts_init();
5244
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005245 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
5246 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005247
5248 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5249 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5250 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5251 f_ctrs_bsc_and_bts_add(0, "handover:failed");
5252 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5253 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:failed");
5254 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005255 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005256}
5257
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005258/* BSC asks for inter-BSC-out HO, receives BSSMAP Handover Command, but then no reply is received about HO outcome
5259 * (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 +02005260 * and the lchan is released. */
5261private function f_tc_ho_out_fail_no_result_after_ho_cmd(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005262 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005263
5264 var PDU_BSSAP ass_req := f_gen_ass_req();
5265 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5266 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5267 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5268 f_establish_fully(ass_req, exp_compl);
5269
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005270 f_bts_0_cfg(BSCVTY, {"neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005271 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5272
5273 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5274
5275 f_sleep(0.5);
5276 /* The MSC negotiates Handover Request and Handover Request Ack with
5277 * the other BSS and comes back with a BSSMAP Handover Command
5278 * containing an RR Handover Command coming from the target BSS... */
5279
5280 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5281 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5282 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5283 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5284 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5285
5286 /* expect the Handover Command to go out on RR */
5287 var RSL_Message rsl_ho_cmd
5288 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5289 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5290 var RSL_IE_Body rsl_ho_cmd_l3;
5291 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5292 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5293 setverdict(fail);
5294 } else {
5295 log("Found L3 Info: ", rsl_ho_cmd_l3);
5296 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5297 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5298 setverdict(fail);
5299 } else {
5300 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5301 setverdict(pass);
5302 }
5303 }
5304
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005305 /* We get neither success nor failure report from the remote BSS. Eventually T8 times out and we run into 3GPP
5306 * TS 48.008 3.1.5.3.3 "Abnormal Conditions": Clear Request should go to the MSC, and RR should be released
5307 * after Clear Command */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005308
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005309 var PDU_BSSAP rx_clear_request;
Neels Hofmeyre1797aa2019-07-09 19:34:04 +02005310 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
5311 log("Got BSSMAP Clear Request");
5312 /* Instruct BSC to clear channel */
5313 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5314 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5315
5316 var MgcpCommand mgcp;
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005317 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01005318 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
5319 log("Got Deact SACCH");
5320 }
Harald Welte924b6ea2019-02-04 01:05:34 +01005321 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01005322 log("Got RR Release");
5323 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005324 [] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
5325 log("Got RF Chan Rel");
5326 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
5327 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005328 }
5329
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005330 f_expect_dlcx_conns();
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005331
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005332 setverdict(pass);
5333 f_sleep(1.0);
5334}
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02005335testcase TC_ho_out_fail_no_result_after_ho_cmd() runs on test_CT {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005336 var MSC_ConnHdlr vc_conn;
5337
5338 f_init(1, true);
5339 f_sleep(1.0);
5340
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005341 f_ctrs_bsc_and_bts_init();
5342
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02005343 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_result_after_ho_cmd));
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005344 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005345
5346 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5347 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5348 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5349 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5350 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5351 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5352 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005353 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005354}
5355
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005356private 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 +01005357 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
5358 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
5359 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
5360 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
5361 * before we get started. */
5362 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
5363 f_rslem_register(0, new_chan_nr);
5364 g_chan_nr := new_chan_nr;
5365 f_sleep(1.0);
5366
5367 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
5368 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
5369 activate(as_Media());
5370
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005371 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005372 f_gen_handover_req(aoip_tla := g_pars.host_aoip_tla,
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02005373 oldToNewBSSIEs := oldToNewBSSIEs,
5374 enc := g_pars.encr)));
Harald Welte6811d102019-04-14 22:23:14 +02005375 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005376
5377 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
5378
5379 var PDU_BSSAP rx_bssap;
5380 var octetstring ho_command_str;
5381
5382 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
Pau Espin Pedrol76ba5412019-06-10 11:00:33 +02005383
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02005384 /* we're sure that the channel activation is done now, verify the encryption parameters in it */
5385 f_verify_encr_info(f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr));
5386
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005387 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
5388 log("Received L3 Info in HO Request Ack: ", ho_command_str);
5389 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
5390 log("L3 Info in HO Request Ack is ", ho_command);
5391
5392 var GsmArfcn arfcn;
5393 var RslChannelNr actual_new_chan_nr;
5394 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
5395 actual_new_chan_nr, arfcn);
5396
5397 if (actual_new_chan_nr != new_chan_nr) {
5398 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
5399 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
5400 setverdict(fail);
5401 return;
5402 }
5403 log("Handover Command chan_nr is", actual_new_chan_nr);
5404
5405 /* Now the MSC forwards the RR Handover Command to the other BSC, which
5406 * tells the MS to handover to the new lchan. Here comes the new MS on
5407 * the new lchan with a Handover RACH: */
5408
5409 /* send handover detect */
5410
5411 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
5412
5413 BSSAP.receive(tr_BSSMAP_HandoverDetect);
5414
5415 /* send handover complete over the new channel */
5416
5417 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
5418 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
5419 enc_PDU_ML3_MS_NW(l3_tx)));
5420
5421 BSSAP.receive(tr_BSSMAP_HandoverComplete);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005422 setverdict(pass);
5423}
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005424
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005425private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005426 var template PDU_ML3_NW_MS exp_rr_rel_tmpl;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005427 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit;
5428 if (not istemplatekind(g_pars.last_used_eutran_plmn, "omit")) {
5429 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005430 }
5431 if (g_pars.exp_fast_return) {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005432 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE_CellSelectInd;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005433 } else {
5434 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005435 }
5436 f_ho_into_this_bsc(id, oldToNewBSSIEs);
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005437 f_perform_clear(RSL, exp_rr_rel_tmpl);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005438 setverdict(pass);
5439}
Pau Espin Pedrol07866632020-09-03 19:10:55 +02005440function f_tc_ho_into_this_bsc_main(TestHdlrParams pars) runs on test_CT {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005441 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005442
5443 f_init(1, true);
5444 f_sleep(1.0);
5445
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005446 f_ctrs_bsc_and_bts_init();
5447
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005448 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
5449 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005450
5451 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
5452 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005453
5454 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5455 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5456 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
5457 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed");
5458 f_ctrs_bsc_and_bts_verify();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005459}
5460
Pau Espin Pedrol07866632020-09-03 19:10:55 +02005461testcase TC_ho_into_this_bsc() runs on test_CT {
5462 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5463 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005464 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02005465}
5466
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02005467function f_tc_ho_into_this_bsc_a5(OCT1 encr_alg) runs on test_CT {
5468 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5469 pars.encr := valueof(t_EncrParams(encr_alg, f_rnd_octstring(8), f_rnd_octstring(16)));
5470 f_tc_ho_into_this_bsc_main(pars);
5471 f_shutdown_helper();
5472}
5473
5474testcase TC_ho_into_this_bsc_a5_0() runs on test_CT {
5475 f_tc_ho_into_this_bsc_a5('01'O);
5476}
5477
5478testcase TC_ho_into_this_bsc_a5_1() runs on test_CT {
5479 f_tc_ho_into_this_bsc_a5('02'O);
5480}
5481
5482testcase TC_ho_into_this_bsc_a5_3() runs on test_CT {
5483 f_tc_ho_into_this_bsc_a5('08'O);
5484}
5485
5486testcase TC_ho_into_this_bsc_a5_4() runs on test_CT {
5487 f_tc_ho_into_this_bsc_a5('10'O);
5488}
5489
Pau Espin Pedrol07866632020-09-03 19:10:55 +02005490testcase TC_ho_into_this_bsc_tla_v6() runs on test_CT {
5491 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5492 pars.host_aoip_tla := "::6";
5493 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005494 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02005495}
5496
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005497/* Similar to TC_ho_into_this_bsc, but when in SRVCC, HO Req contains "Old BSS
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005498 to New BSS Information" IE with "Last Used E-UTRAN PLMN Id", which, when the
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005499 channel is later released (RR CHannel Release), should trigger inclusion of
5500 IE "Cell Selection Indicator after Release of all TCH and SDCCH" with E-UTRAN
5501 neighbors. */
5502testcase TC_srvcc_eutran_to_geran() runs on test_CT {
5503 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5504 pars.last_used_eutran_plmn := '323454'O;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005505 pars.exp_fast_return := true;
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005506 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02005507
5508 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted");
5509 f_ctrs_bsc_and_bts_add(0, "srvcc:completed");
5510 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005511 f_shutdown_helper();
5512}
5513
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005514/* Same as TC_srvcc_eutran_to_geran, but test explicitly forbiding fast return
5515 on the BTS. As a result, RR Release shouldn't contain the EUTRAN neighbor
5516 list when the channel is released. */
5517testcase TC_srvcc_eutran_to_geran_forbid_fast_return() runs on test_CT {
5518 f_init_vty();
5519 f_vty_allow_srvcc_fast_return(true, 0)
5520
5521 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5522 pars.last_used_eutran_plmn := '323454'O;
5523 pars.exp_fast_return := false;
5524 f_tc_ho_into_this_bsc_main(pars);
5525 f_vty_allow_srvcc_fast_return(false, 0);
5526 f_shutdown_helper();
5527}
5528
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005529private function f_tc_srvcc_eutran_to_geran_ho_out(charstring id) runs on MSC_ConnHdlr {
5530 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs;
5531 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
5532 f_ho_into_this_bsc(id, oldToNewBSSIEs);
5533 f_ho_out_of_this_bsc(oldToNewBSSIEs);
5534 setverdict(pass);
5535}
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005536
5537private function f_tc_srvcc_eutran_to_geran_ho_out_main(boolean disable_fast_return)
5538 runs on test_CT {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005539 var MSC_ConnHdlr vc_conn;
5540 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5541
5542 f_init(1, true);
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005543 if (disable_fast_return) {
5544 f_vty_allow_srvcc_fast_return(true, 0);
5545 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005546 f_sleep(1.0);
5547
5548 f_ctrs_bsc_and_bts_init();
5549
5550 pars.last_used_eutran_plmn := '323454'O;
5551 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
5552 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
5553
5554 vc_conn := f_start_handler(refers(f_tc_srvcc_eutran_to_geran_ho_out), pars);
5555 vc_conn.done;
5556
5557 f_ctrs_bsc_and_bts_add(0, "handover:attempted", 2);
5558 f_ctrs_bsc_and_bts_add(0, "handover:completed", 2);
5559 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted", 1);
5560 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed", 1);
5561 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted", 1);
5562 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed", 1);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02005563
5564 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted", 1);
5565 f_ctrs_bsc_and_bts_add(0, "srvcc:completed", 1);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005566 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005567
5568 if (disable_fast_return) {
5569 f_vty_allow_srvcc_fast_return(false, 0);
5570 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005571 f_shutdown_helper();
5572}
5573
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005574/* First, HO into BSC from EUTRAN (SRVCC): HO Request contains "Old BSS to New
5575 BSS Information" IE with "Last Used E-UTRAN PLMN Id".
5576 Second, HO to another BSC: HO Required contains "Old BSS to New BSS Information"
5577 IE with "Last Used E-UTRAN PLMN Id" from first step. */
5578testcase TC_srvcc_eutran_to_geran_ho_out() runs on test_CT {
5579 f_tc_srvcc_eutran_to_geran_ho_out_main(false);
5580}
5581/* Validate subsequent intra-GSM-HO works the same (with OldBSSToNewBSSInfo IE)
5582 * independently of fast-reture allowed/forbidden in local BTS */
5583testcase TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() runs on test_CT {
5584 f_tc_srvcc_eutran_to_geran_ho_out_main(true);
5585}
5586
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005587private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
5588 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
5589 f_rslem_register(0, new_chan_nr);
5590 g_chan_nr := new_chan_nr;
5591 f_sleep(1.0);
5592
5593 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
5594 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
5595 activate(as_Media());
5596
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005597 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005598 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02005599 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005600
5601 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
5602
5603 var PDU_BSSAP rx_bssap;
5604 var octetstring ho_command_str;
5605
5606 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
5607
5608 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
5609 log("Received L3 Info in HO Request Ack: ", ho_command_str);
5610 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
5611 log("L3 Info in HO Request Ack is ", ho_command);
5612
5613 var GsmArfcn arfcn;
5614 var RslChannelNr actual_new_chan_nr;
5615 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
5616 actual_new_chan_nr, arfcn);
5617
5618 if (actual_new_chan_nr != new_chan_nr) {
5619 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
5620 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
5621 setverdict(fail);
5622 return;
5623 }
5624 log("Handover Command chan_nr is", actual_new_chan_nr);
5625
Neels Hofmeyr61ca08d2019-05-06 23:52:22 +02005626 /* For deterministic test results, give some time for the MGW endpoint to be configured */
5627 f_sleep(1.0);
5628
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005629 /* Now the MSC forwards the RR Handover Command to the other BSC, which
5630 * tells the MS to handover to the new lchan. In this case, the MS
5631 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
5632 * Handover Failure to the MSC. The procedure according to 3GPP TS
5633 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
5634 * BSSMAP Clear Command: */
5635
5636 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
5637 var BssmapCause cause := enum2int(cause_val);
5638 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5639
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005640 f_expect_dlcx_conns();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005641 setverdict(pass);
5642 f_sleep(1.0);
5643
5644 setverdict(pass);
5645}
5646testcase TC_ho_in_fail_msc_clears() runs on test_CT {
5647 var MSC_ConnHdlr vc_conn;
5648 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5649
5650 f_init(1, true);
5651 f_sleep(1.0);
5652
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005653 f_ctrs_bsc_and_bts_init();
5654
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005655 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
5656 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005657
5658 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
5659 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005660
5661 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5662 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
5663 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
5664 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
5665 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005666 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005667}
5668
5669private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
5670 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
5671 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
5672 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
5673 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
5674 * before we get started. */
5675 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
5676 f_rslem_register(0, new_chan_nr);
5677 g_chan_nr := new_chan_nr;
5678 f_sleep(1.0);
5679
5680 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
5681 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
5682 activate(as_Media());
5683
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005684 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005685 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02005686 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005687
5688 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
5689
5690 var PDU_BSSAP rx_bssap;
5691 var octetstring ho_command_str;
5692
5693 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
5694
5695 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
5696 log("Received L3 Info in HO Request Ack: ", ho_command_str);
5697 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
5698 log("L3 Info in HO Request Ack is ", ho_command);
5699
5700 var GsmArfcn arfcn;
5701 var RslChannelNr actual_new_chan_nr;
5702 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
5703 actual_new_chan_nr, arfcn);
5704
5705 if (actual_new_chan_nr != new_chan_nr) {
5706 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
5707 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
5708 setverdict(fail);
5709 return;
5710 }
5711 log("Handover Command chan_nr is", actual_new_chan_nr);
5712
5713 /* Now the MSC forwards the RR Handover Command to the other BSC, which
5714 * tells the MS to handover to the new lchan. Here comes the new MS on
5715 * the new lchan with a Handover RACH: */
5716
5717 /* send handover detect */
5718
5719 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
5720
5721 BSSAP.receive(tr_BSSMAP_HandoverDetect);
5722
5723 /* The MSC chooses to clear the connection now, maybe we got the
5724 * Handover RACH on the new cell but the MS still signaled Handover
5725 * Failure to the old BSS? */
5726
5727 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
5728 var BssmapCause cause := enum2int(cause_val);
5729 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5730
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005731 f_expect_dlcx_conns();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005732 f_sleep(1.0);
5733}
5734testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
5735 var MSC_ConnHdlr vc_conn;
5736 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5737
5738 f_init(1, true);
5739 f_sleep(1.0);
5740
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005741 f_ctrs_bsc_and_bts_init();
5742
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005743 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
5744 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005745
5746 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
5747 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005748
5749 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5750 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
5751 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
5752 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
5753 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005754 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005755}
5756
5757/* The new BSS's lchan times out before the MSC decides that handover failed. */
5758private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
5759 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
5760 f_rslem_register(0, new_chan_nr);
5761 g_chan_nr := new_chan_nr;
5762 f_sleep(1.0);
5763
5764 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
5765 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
5766 activate(as_Media());
5767
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005768 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005769 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02005770 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005771
5772 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
5773
5774 var PDU_BSSAP rx_bssap;
5775 var octetstring ho_command_str;
5776
5777 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
5778
5779 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
5780 log("Received L3 Info in HO Request Ack: ", ho_command_str);
5781 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
5782 log("L3 Info in HO Request Ack is ", ho_command);
5783
5784 var GsmArfcn arfcn;
5785 var RslChannelNr actual_new_chan_nr;
5786 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
5787 actual_new_chan_nr, arfcn);
5788
5789 if (actual_new_chan_nr != new_chan_nr) {
5790 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
5791 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
5792 setverdict(fail);
5793 return;
5794 }
5795 log("Handover Command chan_nr is", actual_new_chan_nr);
5796
5797 /* Now the MSC forwards the RR Handover Command to the other BSC, which
5798 * tells the MS to handover to the new lchan. But the MS never shows up
5799 * on the new lchan. */
5800
5801 BSSAP.receive(tr_BSSMAP_HandoverFailure);
5802
5803 /* Did osmo-bsc also send a Clear Request? */
5804 timer T := 0.5;
5805 T.start;
5806 alt {
5807 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
5808 [] T.timeout { }
5809 }
5810
5811 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
5812 * asked for it, this is a Handover Failure after all). */
5813
5814 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
5815 var BssmapCause cause := enum2int(cause_val);
5816 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5817
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005818 f_expect_dlcx_conns();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005819 f_sleep(1.0);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005820}
5821testcase TC_ho_in_fail_no_detect() runs on test_CT {
5822 var MSC_ConnHdlr vc_conn;
5823 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5824
5825 f_init(1, true);
5826 f_sleep(1.0);
5827
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005828 f_ctrs_bsc_and_bts_init();
5829
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005830 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
5831 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005832
5833 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
5834 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005835
5836 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5837 f_ctrs_bsc_and_bts_add(0, "handover:error");
5838 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
5839 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
5840 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005841 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005842}
5843
5844/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
5845private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
5846 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
5847 f_rslem_register(0, new_chan_nr);
5848 g_chan_nr := new_chan_nr;
5849 f_sleep(1.0);
5850
5851 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
5852 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
5853 activate(as_Media());
5854
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005855 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005856 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02005857 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005858
5859 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
5860
5861 var PDU_BSSAP rx_bssap;
5862 var octetstring ho_command_str;
5863
5864 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
5865
5866 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
5867 log("Received L3 Info in HO Request Ack: ", ho_command_str);
5868 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
5869 log("L3 Info in HO Request Ack is ", ho_command);
5870
5871 var GsmArfcn arfcn;
5872 var RslChannelNr actual_new_chan_nr;
5873 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
5874 actual_new_chan_nr, arfcn);
5875
5876 if (actual_new_chan_nr != new_chan_nr) {
5877 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
5878 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
5879 setverdict(fail);
5880 return;
5881 }
5882 log("Handover Command chan_nr is", actual_new_chan_nr);
5883
5884 /* Now the MSC forwards the RR Handover Command to the other BSC, which
5885 * tells the MS to handover to the new lchan. But the MS never shows up
5886 * on the new lchan. */
5887
5888 BSSAP.receive(tr_BSSMAP_HandoverFailure);
5889
5890 /* MSC plays dumb and sends no Clear Command */
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005891 var PDU_BSSAP rx_clear_request;
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005892
5893 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005894 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5895 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5896 };
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005897 f_expect_dlcx_conns();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005898 f_sleep(1.0);
5899}
5900testcase TC_ho_in_fail_no_detect2() runs on test_CT {
5901 var MSC_ConnHdlr vc_conn;
5902 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5903
5904 f_init(1, true);
5905 f_sleep(1.0);
5906
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005907 f_ctrs_bsc_and_bts_init();
5908
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005909 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
5910 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005911
5912 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
5913 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005914
5915 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5916 f_ctrs_bsc_and_bts_add(0, "handover:error");
5917 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
5918 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
5919 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005920 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005921}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005922
Neels Hofmeyr91401012019-07-11 00:42:35 +02005923type record of charstring Commands;
5924
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005925private function f_bts_0_cfg(TELNETasp_PT pt, Commands cmds := {})
Neels Hofmeyr91401012019-07-11 00:42:35 +02005926{
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005927 f_vty_enter_cfg_bts(pt, 0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02005928 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005929 f_vty_transceive(pt, cmds[i]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02005930 }
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005931 f_vty_transceive(pt, "end");
Neels Hofmeyr91401012019-07-11 00:42:35 +02005932}
5933
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01005934private function f_cs7_inst_0_cfg(TELNETasp_PT pt, Commands cmds := {})
5935{
5936 f_vty_enter_cfg_cs7_inst(pt, 0);
5937 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
5938 f_vty_transceive(pt, cmds[i]);
5939 }
5940 f_vty_transceive(pt, "end");
5941}
5942
Neels Hofmeyr91401012019-07-11 00:42:35 +02005943private function f_probe_for_handover(charstring log_label,
5944 charstring log_descr,
5945 charstring handover_vty_cmd,
5946 boolean expect_handover,
5947 boolean is_inter_bsc_handover := false)
5948runs on MSC_ConnHdlr
5949{
Neels Hofmeyrb3fc8982020-05-11 00:16:42 +02005950 /* We're going to thwart any and all handover attempts, just be ready to handle (and ignore) handover target
5951 * lchans to be established on bts 1 or bts 2. */
5952 f_rslem_suspend(RSL1_PROC);
5953 f_rslem_suspend(RSL2_PROC);
5954
Neels Hofmeyr91401012019-07-11 00:42:35 +02005955 var RSL_Message rsl;
5956
5957 var charstring log_msg := " (expecting handover)"
5958 if (not expect_handover) {
5959 log_msg := " (expecting NO handover)";
5960 }
5961 log("f_probe_for_handover starting: " & log_label & ": " & log_descr & log_msg);
5962 f_vty_transceive(BSCVTY, handover_vty_cmd);
5963
Neels Hofmeyr91401012019-07-11 00:42:35 +02005964 timer T := 2.0;
5965 T.start;
5966
5967 alt {
5968 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
5969 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
5970 log("Rx L3 from net: ", l3);
5971 if (ischosen(l3.msgs.rrm.handoverCommand)) {
5972 var RslChannelNr new_chan_nr;
5973 var GsmArfcn arfcn;
5974 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
5975 new_chan_nr, arfcn);
5976 log("Handover to new chan ", new_chan_nr, " on ARFCN ", arfcn);
5977 log(l3.msgs.rrm.handoverCommand);
5978
5979 /* Need to register for new lchan on new BTS -- it's either bts 1 or bts 2. It doesn't really
5980 * matter on which BTS it really is, we're not going to follow through an entire handover
5981 * anyway. */
5982 f_rslem_register(0, new_chan_nr, RSL1_PROC);
5983 f_rslem_resume(RSL1_PROC);
5984 f_rslem_register(0, new_chan_nr, RSL2_PROC);
5985 f_rslem_resume(RSL2_PROC);
5986
5987 if (expect_handover and not is_inter_bsc_handover) {
5988 setverdict(pass);
5989 log("f_probe_for_handover(" & log_label & "): Got RSL Handover Command as expected.");
5990 } else {
5991 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got RSL Handover Command. "
5992 & log_label & ": " & log_descr);
5993 }
5994
5995 log("f_probe_for_handover(" & log_label & "): Ending the test: Handover Failure stops the procedure.");
5996 /* osmo-bsc has triggered Handover. That's all we need to know for this test, reply with
5997 * Handover Failure. */
5998 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
5999
6000 /* target BTS is told to release lchan again; don't care which BTS nor what messages. */
6001 f_sleep(0.5);
6002 RSL1.clear;
6003 RSL2.clear;
6004 log("f_probe_for_handover(" & log_label & "): done (got RSL Handover Command)");
6005 break;
6006 } else {
6007 repeat;
6008 }
6009 }
6010 [] BSSAP.receive(tr_BSSMAP_HandoverRequired) {
6011 if (expect_handover and is_inter_bsc_handover) {
6012 setverdict(pass);
6013 log("f_probe_for_handover(" & log_label & "): Got BSSMAP Handover Required as expected.");
6014 } else {
6015 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got BSSMAP Handover Required. "
6016 & log_label & ": " & log_descr);
6017 }
6018
6019 log("f_probe_for_handover(" & log_label & "): done (got BSSMAP Handover Required)");
6020
6021 /* Note: f_tc_ho_neighbor_config_start() sets T7, the timeout for BSSMAP Handover Required, to
6022 * 1 second. There is no legal way to quickly abort a handover after a BSSMAP Handover Required,
6023 * setting a short timeout and waiting is the only way. */
6024 log("f_probe_for_handover(" & log_label & "): waiting for inter-BSC HO to time out...");
6025 f_sleep(1.5);
6026 log("f_probe_for_handover(" & log_label & "): ...done");
6027
6028 break;
6029 }
6030 [] T.timeout {
6031 if (expect_handover) {
6032 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected Handover, but got none. "
6033 & log_label & ": " & log_descr);
6034 } else {
6035 setverdict(pass);
6036 log("f_probe_for_handover(" & log_label & "): Got no Handover, as expected.");
6037 }
6038 log("f_probe_for_handover(" & log_label & "): done (got no Handover)");
6039 break;
6040 }
6041 }
6042
6043 f_rslem_resume(RSL1_PROC);
6044 f_rslem_resume(RSL2_PROC);
6045 f_sleep(3.0);
6046 RSL.clear;
6047
6048 log("f_probe_for_handover(" & log_label & "): done clearing");
6049}
6050
6051/* Test the effect of various neighbor configuration scenarios:
6052 *
6053 * To avoid complexity, block off any actual handover operation, and always remain on the lchan at bts 0.
6054 * Reconfigure the neighbors for bts 0, trigger a Handover, and probe whether osmo-bsc does or doesn't start HO.
6055 */
6056private function f_tc_ho_neighbor_config_start() runs on MSC_ConnHdlr {
6057 g_pars := f_gen_test_hdlr_pars();
6058 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
6059 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006060
6061 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
6062 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
6063
6064 /* Establish lchan at bts 0 */
6065 f_establish_fully(ass_cmd, exp_compl);
6066
6067 /* Shorten the inter-BSC Handover timeout, to not wait so long for inter-BSC Handovers */
6068 f_vty_enter_cfg_network(BSCVTY);
6069 f_vty_transceive(BSCVTY, "timer T7 1");
6070 f_vty_transceive(BSCVTY, "end");
6071}
6072
6073private function f_tc_ho_neighbor_config_1(charstring id) runs on MSC_ConnHdlr {
6074 f_tc_ho_neighbor_config_start();
6075
6076 /*
6077 * bts 0 ARFCN 871 BSIC 10
6078 * bts 1 ARFCN 871 BSIC 11
6079 * bts 2 ARFCN 871 BSIC 12
6080 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6081 */
6082
6083 log("f_tc_ho_neighbor_config: 1. No 'neighbor' config");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006084 f_bts_0_cfg(BSCVTY, {"no neighbors"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006085 f_probe_for_handover("1.a", "HO to bts 1 works, implicitly listed as neighbor (legacy behavior when none are configured)",
6086 "handover any to arfcn 871 bsic 11",
6087 true);
6088
6089 f_probe_for_handover("1.b", "HO to unknown cell does not start",
6090 "handover any to arfcn 13 bsic 39",
6091 false);
6092
6093 f_probe_for_handover("1.c", "HO to 871-12 is ambiguous = error",
6094 "handover any to arfcn 871 bsic 12",
6095 false);
6096
6097 f_probe_for_handover("1.d", "HO to 871-11 still works (verify that this test properly cleans up)",
6098 "handover any to arfcn 871 bsic 11",
6099 true);
6100}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006101testcase TC_ho_neighbor_config_1() runs on test_CT {
6102 var MSC_ConnHdlr vc_conn;
6103 f_init(3, true, guard_timeout := 60.0);
6104 f_sleep(1.0);
6105 f_ctrs_bsc_and_bts_init();
6106 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_1));
6107 vc_conn.done;
6108
6109 /* f_tc_ho_neighbor_config_start() */
6110 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6111 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6112
6113 /* 1.a */
6114 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6115 * handover quickly by sending a Handover Failure message. */
6116 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6117 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6118 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6119 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
6120
6121 /* 1.b */
6122 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6123 f_ctrs_bsc_and_bts_add(0, "handover:error");
6124
6125 /* 1.c */
6126 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6127 f_ctrs_bsc_and_bts_add(0, "handover:error");
6128
6129 /* 1.d */
6130 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6131 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6132 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6133 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
6134
6135 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006136 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006137}
6138
Neels Hofmeyr91401012019-07-11 00:42:35 +02006139private function f_tc_ho_neighbor_config_2(charstring id) runs on MSC_ConnHdlr {
6140 f_tc_ho_neighbor_config_start();
6141
6142 /*
6143 * bts 0 ARFCN 871 BSIC 10
6144 * bts 1 ARFCN 871 BSIC 11
6145 * bts 2 ARFCN 871 BSIC 12
6146 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6147 */
6148
6149 log("f_tc_ho_neighbor_config: 2. explicit local neighbor: 'neighbor bts 1'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006150 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006151 f_sleep(0.5);
6152
6153 f_probe_for_handover("2.a", "HO to bts 1 works, explicitly listed as neighbor",
6154 "handover any to arfcn 871 bsic 11",
6155 true);
6156
6157 f_probe_for_handover("2.b", "HO to bts 2 doesn't work, not listed as neighbor",
6158 "handover any to arfcn 871 bsic 12",
6159 false);
6160}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006161testcase TC_ho_neighbor_config_2() runs on test_CT {
6162 var MSC_ConnHdlr vc_conn;
6163 f_init(3, true, guard_timeout := 50.0);
6164 f_sleep(1.0);
6165 f_ctrs_bsc_and_bts_init();
6166 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_2));
6167 vc_conn.done;
6168
6169 /* f_tc_ho_neighbor_config_start() */
6170 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6171 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6172
6173 /* 2.a */
6174 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6175 * handover quickly by sending a Handover Failure message. */
6176 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6177 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6178 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6179 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
6180
6181 /* 2.b */
6182 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6183 f_ctrs_bsc_and_bts_add(0, "handover:error");
6184
6185 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006186 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006187}
6188
Neels Hofmeyr91401012019-07-11 00:42:35 +02006189private function f_tc_ho_neighbor_config_3(charstring id) runs on MSC_ConnHdlr {
6190 f_tc_ho_neighbor_config_start();
6191
6192 /*
6193 * bts 0 ARFCN 871 BSIC 10
6194 * bts 1 ARFCN 871 BSIC 11
6195 * bts 2 ARFCN 871 BSIC 12
6196 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6197 */
6198
6199 log("f_tc_ho_neighbor_config: 3. explicit local neighbor: 'neighbor bts 2'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006200 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006201 f_sleep(0.5);
6202
6203 f_probe_for_handover("3.a", "HO to bts 1 doesn't work, not listed as neighbor",
6204 "handover any to arfcn 871 bsic 11",
6205 false);
6206 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",
6207 "handover any to arfcn 871 bsic 12",
6208 true);
6209}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006210testcase TC_ho_neighbor_config_3() runs on test_CT {
6211 var MSC_ConnHdlr vc_conn;
6212 f_init(3, true, guard_timeout := 50.0);
6213 f_sleep(1.0);
6214 f_ctrs_bsc_and_bts_init();
6215 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_3));
6216 vc_conn.done;
6217
6218 /* f_tc_ho_neighbor_config_start() */
6219 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6220 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6221
6222 /* 3.a */
6223 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6224 f_ctrs_bsc_and_bts_add(0, "handover:error");
6225
6226 /* 3.b */
6227 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6228 * handover quickly by sending a Handover Failure message. */
6229 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6230 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6231 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6232 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
6233
6234 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006235 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006236}
6237
Neels Hofmeyr91401012019-07-11 00:42:35 +02006238private function f_tc_ho_neighbor_config_4(charstring id) runs on MSC_ConnHdlr {
6239 f_tc_ho_neighbor_config_start();
6240
6241 /*
6242 * bts 0 ARFCN 871 BSIC 10
6243 * bts 1 ARFCN 871 BSIC 11
6244 * bts 2 ARFCN 871 BSIC 12
6245 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6246 */
6247
6248 log("f_tc_ho_neighbor_config: 4. explicit remote neighbor: 'neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006249 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006250 f_sleep(0.5);
6251
6252 f_probe_for_handover("4.a", "HO to bts 1 doesn't work, not listed as neighbor",
6253 "handover any to arfcn 871 bsic 11",
6254 false);
6255 f_probe_for_handover("4.b", "HO to bts 2 doesn't work, not listed as neighbor",
6256 "handover any to arfcn 871 bsic 12",
6257 false);
6258 f_probe_for_handover("4.c", "HO to 123-45 triggers inter-BSC HO",
6259 "handover any to arfcn 123 bsic 45",
6260 true, true);
6261}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006262testcase TC_ho_neighbor_config_4() runs on test_CT {
6263 var MSC_ConnHdlr vc_conn;
6264 f_init(3, true, guard_timeout := 50.0);
6265 f_sleep(1.0);
6266 f_ctrs_bsc_and_bts_init();
6267 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_4));
6268 vc_conn.done;
6269
6270 /* f_tc_ho_neighbor_config_start() */
6271 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6272 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6273
6274 /* 4.a */
6275 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6276 f_ctrs_bsc_and_bts_add(0, "handover:error");
6277
6278 /* 4.b */
6279 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6280 f_ctrs_bsc_and_bts_add(0, "handover:error");
6281
6282 /* 4.c */
6283 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6284 * handover quickly by timing out after the Handover Required message */
6285 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6286 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
6287 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
6288 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
6289
6290 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006291 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006292}
6293
Neels Hofmeyr91401012019-07-11 00:42:35 +02006294private function f_tc_ho_neighbor_config_5(charstring id) runs on MSC_ConnHdlr {
6295 f_tc_ho_neighbor_config_start();
6296
6297 /*
6298 * bts 0 ARFCN 871 BSIC 10
6299 * bts 1 ARFCN 871 BSIC 11
6300 * bts 2 ARFCN 871 BSIC 12
6301 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6302 */
6303
6304 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 +02006305 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006306 f_sleep(0.5);
6307
6308 f_probe_for_handover("5.a", "HO to 871-12 triggers inter-BSC HO (ignoring local cells with same ARFCN+BSIC)",
6309 "handover any to arfcn 871 bsic 12",
6310 true, true);
6311}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006312testcase TC_ho_neighbor_config_5() runs on test_CT {
6313 var MSC_ConnHdlr vc_conn;
6314 f_init(3, true);
6315 f_sleep(1.0);
6316 f_ctrs_bsc_and_bts_init();
6317 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_5));
6318 vc_conn.done;
6319
6320 /* f_tc_ho_neighbor_config_start() */
6321 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6322 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6323
6324 /* 5 */
6325 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6326 * handover quickly by timing out after the Handover Required message */
6327 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6328 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
6329 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
6330 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
6331
6332 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006333 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006334}
6335
Neels Hofmeyr91401012019-07-11 00:42:35 +02006336private function f_tc_ho_neighbor_config_6(charstring id) runs on MSC_ConnHdlr {
6337 f_tc_ho_neighbor_config_start();
6338
6339 /*
6340 * bts 0 ARFCN 871 BSIC 10
6341 * bts 1 ARFCN 871 BSIC 11
6342 * bts 2 ARFCN 871 BSIC 12
6343 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6344 */
6345
6346 log("f_tc_ho_neighbor_config: 6. config error: explicit local and remote neighbors with ambiguous ARFCN+BSIC:"
6347 & " 'neighbor bts 2; neighbor lac 99 arfcn 871 bsic 12'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006348 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006349 f_sleep(0.5);
6350
6351 f_probe_for_handover("6.a", "HO to 871-12 is ambiguous = error",
6352 "handover any to arfcn 871 bsic 12",
6353 false);
6354}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006355testcase TC_ho_neighbor_config_6() runs on test_CT {
6356 var MSC_ConnHdlr vc_conn;
6357 f_init(3, true);
6358 f_sleep(1.0);
6359 f_ctrs_bsc_and_bts_init();
6360 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_6));
6361 vc_conn.done;
6362
6363 /* f_tc_ho_neighbor_config_start() */
6364 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6365 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6366
6367 /* 6.a */
6368 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6369 * handover quickly by timing out after the Handover Required message */
6370 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6371 f_ctrs_bsc_and_bts_add(0, "handover:error");
6372
6373 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006374 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006375}
6376
Neels Hofmeyr91401012019-07-11 00:42:35 +02006377private function f_tc_ho_neighbor_config_7(charstring id) runs on MSC_ConnHdlr {
6378 f_tc_ho_neighbor_config_start();
6379
6380 /*
6381 * bts 0 ARFCN 871 BSIC 10
6382 * bts 1 ARFCN 871 BSIC 11
6383 * bts 2 ARFCN 871 BSIC 12
6384 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6385 */
6386
6387 log("f_tc_ho_neighbor_config: 7. explicit local and remote neighbors:"
6388 & " 'neighbor bts 2; neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006389 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006390 f_sleep(0.5);
6391
6392 f_probe_for_handover("7.a", "HO to 871-12 does HO to bts 2",
6393 "handover any to arfcn 871 bsic 12",
6394 true);
6395 f_probe_for_handover("7.b", "HO to 123-45 triggers inter-BSC HO",
6396 "handover any to arfcn 123 bsic 45",
6397 true, true);
6398}
Neels Hofmeyr91401012019-07-11 00:42:35 +02006399testcase TC_ho_neighbor_config_7() runs on test_CT {
6400 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf2b88032020-06-16 00:35:04 +02006401 f_init(3, true, guard_timeout := 50.0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006402 f_sleep(1.0);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006403 f_ctrs_bsc_and_bts_init();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006404 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_7));
6405 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006406
6407 /* f_tc_ho_neighbor_config_start() */
6408 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6409 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6410
6411 /* 7.a */
6412 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6413 * handover quickly by sending a Handover Failure message. */
6414 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6415 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6416 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6417 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
6418
6419 /* 7.b */
6420 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6421 * handover quickly by timing out after the Handover Required message */
6422 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6423 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
6424 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
6425 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
6426
6427 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006428 f_shutdown_helper();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006429}
6430
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01006431/* OS#3041: Open and close N connections in a normal fashion, and expect no
6432 * BSSMAP Reset just because of that. */
6433testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
6434 var default d;
6435 var integer i;
6436 var DchanTuple dt;
6437
6438 f_init();
6439
6440 /* Wait for initial BSSMAP Reset to pass */
6441 f_sleep(4.0);
6442
6443 d := activate(no_bssmap_reset());
6444
6445 /* Setup up a number of connections and RLSD them again from the MSC
6446 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
6447 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02006448 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01006449 /* Since we're doing a lot of runs, give each one a fresh
6450 * T_guard from the top. */
6451 T_guard.start;
6452
6453 /* Setup a BSSAP connection and clear it right away. This is
6454 * the MSC telling the BSC about a planned release, it's not an
6455 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02006456 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01006457
6458 /* MSC disconnects (RLSD). */
6459 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
6460 }
6461
6462 /* In the buggy behavior, a timeout of 2 seconds happens between above
6463 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
6464 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
6465 f_sleep(4.0);
6466
6467 deactivate(d);
6468 f_shutdown_helper();
6469}
Harald Welte552620d2017-12-16 23:21:36 +01006470
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01006471/* OS#3041: Open and close N connections in a normal fashion, and expect no
6472 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
6473 * the MSC. */
6474testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
6475 var default d;
6476 var integer i;
6477 var DchanTuple dt;
6478 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01006479 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
6480 var BssmapCause cause := enum2int(cause_val);
6481
6482 f_init();
6483
6484 /* Wait for initial BSSMAP Reset to pass */
6485 f_sleep(4.0);
6486
6487 d := activate(no_bssmap_reset());
6488
6489 /* Setup up a number of connections and RLSD them again from the MSC
6490 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
6491 * Let's do it some more times for good measure. */
6492 for (i := 0; i < 8; i := i+1) {
6493 /* Since we're doing a lot of runs, give each one a fresh
6494 * T_guard from the top. */
6495 T_guard.start;
6496
6497 /* Setup a BSSAP connection and clear it right away. This is
6498 * the MSC telling the BSC about a planned release, it's not an
6499 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02006500 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01006501
6502 /* Instruct BSC to clear channel */
6503 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
6504
6505 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02006506 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01006507 }
6508
6509 /* In the buggy behavior, a timeout of 2 seconds happens between above
6510 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
6511 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
6512 f_sleep(4.0);
6513
6514 deactivate(d);
6515 f_shutdown_helper();
6516}
6517
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01006518/* OS#3041: Open and close N connections in a normal fashion, and expect no
6519 * BSSMAP Reset just because of that. Close connections from the MS side with a
6520 * Release Ind on RSL. */
6521testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
6522 var default d;
6523 var integer i;
6524 var DchanTuple dt;
6525 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01006526 var integer j;
6527
6528 f_init();
6529
6530 /* Wait for initial BSSMAP Reset to pass */
6531 f_sleep(4.0);
6532
6533 d := activate(no_bssmap_reset());
6534
6535 /* Setup up a number of connections and RLSD them again from the MSC
6536 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
6537 * Let's do it some more times for good measure. */
6538 for (i := 0; i < 8; i := i+1) {
6539 /* Since we're doing a lot of runs, give each one a fresh
6540 * T_guard from the top. */
6541 T_guard.start;
6542
6543 /* Setup a BSSAP connection and clear it right away. This is
6544 * the MSC telling the BSC about a planned release, it's not an
6545 * erratic loss of a connection. */
6546 dt := f_est_dchan('23'O, 23, '00010203040506'O);
6547
6548 /* simulate RLL REL IND */
6549 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
6550
6551 /* expect Clear Request on MSC side */
6552 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
6553
6554 /* Instruct BSC to clear channel */
6555 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
6556 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
6557
6558 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02006559 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01006560 }
6561
6562 /* In the buggy behavior, a timeout of 2 seconds happens between above
6563 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
6564 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
6565 f_sleep(4.0);
6566
6567 deactivate(d);
6568 f_shutdown_helper();
6569}
6570
Harald Welte94e0c342018-04-07 11:33:23 +02006571/***********************************************************************
6572 * IPA style dynamic PDCH
6573 ***********************************************************************/
6574
6575private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
6576 template (omit) RSL_Cause nack := omit)
6577runs on test_CT {
6578 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
6579 var RSL_Message rsl_unused;
6580 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
6581 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
6582 /* expect the BSC to issue the related RSL command */
6583 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
6584 if (istemplatekind(nack, "omit")) {
6585 /* respond with a related acknowledgement */
6586 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
6587 } else {
6588 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
6589 }
6590}
6591
6592private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
6593 template (omit) RSL_Cause nack := omit)
6594runs on test_CT {
6595 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
6596 var RSL_Message rsl_unused;
6597 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
6598 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
6599 /* expect the BSC to issue the related RSL command */
6600 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
6601 if (istemplatekind(nack, "omit")) {
6602 /* respond with a related acknowledgement */
6603 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
6604 } else {
6605 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
6606 }
6607}
6608
6609private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
6610runs on test_CT return charstring {
6611 var charstring cmd, resp;
6612 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01006613 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02006614}
6615
6616private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
6617 template charstring exp)
6618runs on test_CT {
6619 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
6620 if (not match(mode, exp)) {
6621 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02006622 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02006623 }
6624}
6625
6626private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
6627runs on test_CT {
6628 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
6629 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
6630 f_vty_transceive(BSCVTY, "end");
6631}
6632
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02006633
6634private function f_ts_reset_chcomb(integer bts_nr) runs on test_CT {
6635 var integer i;
6636 for (i := 0; i < 8; i := i + 1) {
6637 f_ts_set_chcomb(bts_nr, 0, i, phys_chan_config[i]);
6638 }
6639}
6640
Harald Welte94e0c342018-04-07 11:33:23 +02006641private const charstring TCHF_MODE := "TCH/F mode";
6642private const charstring TCHH_MODE := "TCH/H mode";
6643private const charstring PDCH_MODE := "PDCH mode";
6644private const charstring NONE_MODE := "NONE mode";
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02006645private const charstring SDCCH8_MODE := "SDCCH8 mode";
Harald Welte94e0c342018-04-07 11:33:23 +02006646
6647/* Test IPA PDCH activation / deactivation triggered by VTY */
6648testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
6649 var RSL_Message rsl_unused;
6650
6651 /* change Timeslot 6 before f_init() starts RSL */
6652 f_init_vty();
6653 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
6654 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6655
6656 f_init(1, false);
6657 f_sleep(1.0);
6658
6659 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
6660
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02006661 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02006662 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
6663 /* The BSC will activate the dynamic PDCH by default, so confirm that */
6664 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
6665 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
6666 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02006667 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02006668 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
6669
6670 /* De-activate it via VTY */
6671 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
6672 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02006673 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02006674 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
6675
6676 /* re-activate it via VTY */
6677 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
6678 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02006679 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02006680 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
6681
6682 /* and finally de-activate it again */
6683 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
6684 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02006685 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02006686 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
6687
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02006688 /* clean up config */
6689 f_ts_set_chcomb(0, 0, 6, "PDCH");
6690
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006691 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02006692}
6693
6694/* Test IPA PDCH activation NACK */
6695testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
6696 var RSL_Message rsl_unused;
6697
6698 /* change Timeslot 6 before f_init() starts RSL */
6699 f_init_vty();
6700 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
6701 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6702
6703 f_init(1, false);
6704 f_sleep(1.0);
6705
6706 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
6707
6708 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
6709 /* The BSC will activate the dynamic PDCH by default, so confirm that */
6710 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
6711 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
6712 f_sleep(1.0);
6713 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
6714
6715 /* De-activate it via VTY */
6716 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
6717 f_sleep(1.0);
6718 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
6719
6720 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
6721 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
6722 f_sleep(1.0);
6723 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
6724
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02006725 /* clean up config */
6726 f_ts_set_chcomb(0, 0, 6, "PDCH");
6727
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006728 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02006729}
6730
6731
6732/***********************************************************************
6733 * Osmocom style dynamic PDCH
6734 ***********************************************************************/
6735
6736private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
6737 template (omit) RSL_Cause nack := omit)
6738runs on test_CT {
6739 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
6740 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02006741 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02006742 /* FIXME: no VTY command to activate Osmocom PDCH !! */
6743 /* expect the BSC to issue the related RSL command */
6744 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
6745 if (istemplatekind(nack, "omit")) {
6746 /* respond with a related acknowledgement */
6747 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
6748 } else {
6749 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
6750 }
6751}
6752
6753private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
6754 template (omit) RSL_Cause nack := omit)
6755runs on test_CT {
6756 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
6757 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02006758 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02006759 /* FIXME: no VTY command to activate Osmocom PDCH !! */
6760 /* expect the BSC to issue the related RSL command */
6761 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
6762 if (istemplatekind(nack, "omit")) {
6763 /* respond with a related acknowledgement */
6764 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
6765 } else {
6766 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
6767 }
6768}
6769
6770/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
6771testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
6772 var RSL_Message rsl_unused;
6773
6774 /* change Timeslot 6 before f_init() starts RSL */
6775 f_init_vty();
6776 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
6777 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6778
6779 f_init(1, false);
6780 f_sleep(1.0);
6781
6782 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
6783
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02006784 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02006785 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
6786 /* The BSC will activate the dynamic PDCH by default, so confirm that */
6787 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
6788
6789 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
6790 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02006791 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 +02006792 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
6793
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02006794 /* clean up config */
6795 f_ts_set_chcomb(0, 0, 6, "PDCH");
6796
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006797 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02006798}
6799
6800/* Test Osmocom dyn PDCH activation NACK behavior */
6801testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
6802 var RSL_Message rsl_unused;
6803
6804 /* change Timeslot 6 before f_init() starts RSL */
6805 f_init_vty();
6806 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
6807 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6808
6809 f_init(1, false);
6810 f_sleep(1.0);
6811
6812 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
6813
6814 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
6815 /* The BSC will activate the dynamic PDCH by default, so confirm that */
6816 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
6817
6818 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
6819 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
6820 f_sleep(1.0);
6821 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
6822
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02006823 /* clean up config */
6824 f_ts_set_chcomb(0, 0, 6, "PDCH");
6825
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006826 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02006827}
6828
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02006829/* Test Osmocom dyn TS SDCCH8 activation / deactivation */
6830testcase TC_dyn_ts_sdcch8_act_deact() runs on test_CT {
6831 var RSL_Message rsl_unused, rsl_msg;
6832 var DchanTuple dt;
6833 var BSSAP_N_CONNECT_ind rx_c_ind;
6834
6835 /* change Timeslot 6 before f_init() starts RSL */
6836 f_init_vty();
6837 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
6838 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6839
6840 f_init(1, false);
6841 f_sleep(1.0);
6842
6843 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
6844
6845 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
6846 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
6847 /* The BSC will activate the dynamic PDCH by default, so confirm that */
6848 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr, ?));
6849
6850 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
6851 f_sleep(1.0);
6852 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
6853 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
6854
6855 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
6856 * on CCCH+SDCCH4+CBCH) */
6857 var integer i;
6858 for (i := 0; i < 3; i := i + 1) {
6859 dt := f_est_dchan('23'O, i, '00010203040506'O);
6860 }
6861
6862 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
6863 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
6864 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
6865 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
6866
6867 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
6868 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
6869
6870 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
6871 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
6872 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
6873 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
6874
6875 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
6876 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
6877 dt.sccp_conn_id := rx_c_ind.connectionId;
6878 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
6879
6880 /* Instruct BSC to clear channel */
6881 var BssmapCause cause := 0;
6882 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
6883 f_exp_chan_rel_and_clear(dt, 0);
6884
6885 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
6886 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr, ?));
6887 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
6888 f_sleep(1.0);
6889 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
6890
6891 /* clean up config */
6892 f_ts_set_chcomb(0, 0, 6, "PDCH");
6893
6894 f_shutdown_helper();
6895}
6896
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02006897/* Test Osmocom dyn TS SDCCH8 activation / deactivation: If activating dyn TS as
6898 SDCCH8 would end up in having no free TCH, then BSC should decide to activate
6899 it as TCH directly instead. SYS#5309. */
6900testcase TC_dyn_ts_sdcch8_tch_call_act_deact() runs on test_CT {
6901 var RSL_Message rsl_unused, rsl_msg;
6902 var DchanTuple dt;
6903 var BSSAP_N_CONNECT_ind rx_c_ind;
6904 var integer i;
6905
6906 /* change Timeslot 6 before f_init() starts RSL */
6907 f_init_vty();
6908 for (i := 1; i < 8; i := i + 1) {
6909 if (i == 6) {
6910 f_ts_set_chcomb(0, 0, i, "TCH/F_TCH/H_SDCCH8_PDCH");
6911 } else {
6912 f_ts_set_chcomb(0, 0, i, "PDCH");
6913 }
6914 }
6915 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6916
6917 f_init(1, false);
6918 f_sleep(1.0);
6919
6920 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
6921
6922 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
6923 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
6924 /* The BSC will activate the dynamic PDCH by default, so confirm that */
6925 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr, ?));
6926
6927 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
6928 f_sleep(1.0);
6929 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
6930 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
6931
6932 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
6933 * on CCCH+SDCCH4+CBCH) */
6934 for (i := 0; i < 3; i := i + 1) {
6935 dt := f_est_dchan('23'O, i, '00010203040506'O);
6936 }
6937
6938 /* Now the dyn ts is selected. First PDCH is released, then TCH chan is activated */
6939 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
6940 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
6941 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
6942
6943 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
6944 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
6945
6946 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
6947 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
6948 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
6949 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
6950
6951 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
6952 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
6953 dt.sccp_conn_id := rx_c_ind.connectionId;
6954 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
6955
6956 /* Instruct BSC to clear channel */
6957 var BssmapCause cause := 0;
6958 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
6959 f_exp_chan_rel_and_clear(dt, 0);
6960
6961 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
6962 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr, ?));
6963 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
6964 f_sleep(1.0);
6965 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
6966
6967 /* clean up config */
6968 f_ts_reset_chcomb(0);
6969 /* TODO: clean up other channels? */
6970
6971 f_shutdown_helper();
6972}
6973
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02006974/* Test Osmocom dyn TS SDCCH8 activation / deactivation when SDCCH fails at BTS */
6975testcase TC_dyn_ts_sdcch8_act_nack() runs on test_CT {
6976 var RSL_Message rsl_unused, rsl_msg;
6977 var DchanTuple dt;
6978 var BSSAP_N_CONNECT_ind rx_c_ind;
6979 var GsmRrMessage rr;
6980
6981 /* change Timeslot 6 before f_init() starts RSL */
6982 f_init_vty();
6983 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
6984 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6985
6986 f_init(1, false);
6987 f_sleep(1.0);
6988
6989 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
6990
6991 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
6992 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
6993 /* The BSC will activate the dynamic PDCH by default, so confirm that */
6994 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr, ?));
6995
6996 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
6997 f_sleep(1.0);
6998 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
6999 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7000
7001 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7002 * on CCCH+SDCCH4+CBCH) */
7003 var integer i;
7004 for (i := 0; i < 3; i := i + 1) {
7005 dt := f_est_dchan('23'O, i, '00010203040506'O);
7006 }
7007
7008 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
7009 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
7010 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7011 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7012
7013 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7014 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7015
7016 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7017 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(dt.rsl_chan_nr, RSL_ERR_EQUIPMENT_FAIL));
7018 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7019 rr := dec_GsmRrMessage(rsl_msg.ies[1].body.full_imm_ass_info.payload);
7020 if (rr.header.message_type != IMMEDIATE_ASSIGNMENT_REJECT) {
7021 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Expected reject");
7022 }
7023
7024 /* FIXME? Currently the TS stays in state BORKEN: */
7025
7026 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
7027 /* rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr, ?));
7028 * f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7029 * f_sleep(1.0);
7030 * f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE)
7031 */
7032
7033 /* clean up config */
7034 f_ts_set_chcomb(0, 0, 6, "PDCH");
7035
7036 f_shutdown_helper();
7037}
7038
Stefan Sperling0796a822018-10-05 13:01:39 +02007039testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02007040 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02007041 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
7042 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
7043 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007044 f_shutdown_helper();
Stefan Sperling0796a822018-10-05 13:01:39 +02007045}
7046
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007047testcase TC_chopped_ipa_payload() runs on test_CT {
7048 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
7049 /* TODO: mp_bsc_ctrl_port does not work yet */};
7050 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
7051 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
7052 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007053 f_shutdown_helper();
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007054}
7055
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01007056/* Verify the BSC sends the MS Power Parameters IE during CHAN ACT to make sure
7057 the BTS does autonomous MS power control loop */
7058testcase TC_assignment_verify_ms_power_params_ie() runs on test_CT {
7059 var MSC_ConnHdlr vc_conn;
7060 var TestHdlrParams pars := f_gen_test_hdlr_pars();
7061 //pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
7062 pars.exp_ms_power_params := true;
7063
7064 f_init(1, true);
7065 f_sleep(1.0);
7066 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
7067 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007068 f_shutdown_helper();
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01007069}
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007070
Vadim Yanitskiy4b233042021-06-30 00:58:43 +02007071/* Verify activation and deactivation of the BCCH carrier power reduction mode */
7072testcase TC_c0_power_red_mode() runs on test_CT {
7073 f_init(1);
7074
7075 for (var integer red := 6; red >= 0; red := red - 2) {
7076 /* Configure BCCH carrier power reduction mode via the VTY */
7077 f_vty_transceive(BSCVTY, "bts 0 c0-power-reduction " & int2str(red));
7078
7079 /* Expect Osmocom specific BS Power Control message on the RSL */
7080 var template RSL_Message tr_rsl_pdu := tr_RSL_BS_PWR_CTRL(
7081 chan_nr := t_RslChanNr_BCCH(0),
7082 bs_power := tr_RSL_IE_BS_Power(red / 2));
7083 tr_rsl_pdu.msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false);
7084 var RSL_Message unused := f_exp_ipa_rx(0, tr_rsl_pdu);
7085
7086 /* Additionally verify the applied value over the CTRL interface */
7087 var CtrlValue cred := f_ctrl_get_bts(IPA_CTRL, 0, "c0-power-reduction");
7088 if (cred != int2str(red)) {
7089 setverdict(fail, "Unexpected BCCH carrier power reduction value ",
7090 cred, " (expected ", red, ")");
7091 }
7092 }
7093
7094 f_shutdown_helper();
7095}
7096
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007097/***********************************************************************
7098 * MSC Pooling
7099 ***********************************************************************/
7100
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007101template MobileIdentityLV ts_MI_TMSI_NRI_LV(integer nri_v, integer nri_bitlen := 10) :=
Harald Weltebf397612021-01-14 20:39:46 +01007102 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 +02007103
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02007104private function f_expect_lchan_rel(RSL_DCHAN_PT rsl, template PDU_ML3_NW_MS exp_rr_rel_tmpl := tr_RRM_RR_RELEASE)
7105runs on MSC_ConnHdlr {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007106 interleave {
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02007107 [] rsl.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007108 f_logp(BSCVTY, "Got RSL RR Release");
7109 }
7110 [] rsl.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
7111 f_logp(BSCVTY, "Got RSL Deact SACCH");
7112 }
7113 [] rsl.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
7114 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
7115 rsl.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
7116 break;
7117 }
7118 }
7119}
7120
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +02007121friend function f_perform_clear(RSL_DCHAN_PT rsl, template PDU_ML3_NW_MS exp_rr_rel_tmpl := tr_RRM_RR_RELEASE)
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02007122runs on MSC_ConnHdlr {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007123 f_logp(BSCVTY, "MSC instructs BSC to clear channel");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007124 BSSAP.send(ts_BSSMAP_ClearCommand(0));
7125 interleave {
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02007126 [] rsl.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007127 f_logp(BSCVTY, "Got RSL RR Release");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007128 }
7129 [] rsl.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007130 f_logp(BSCVTY, "Got RSL Deact SACCH");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007131 }
7132 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007133 f_logp(BSCVTY, "Got BSSMAP Clear Complete");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007134 /* Also drop the SCCP connection */
7135 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
7136 }
7137 [] rsl.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007138 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007139 rsl.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
7140 }
7141 }
7142}
7143
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007144private function f_perform_compl_l3(RSL_DCHAN_PT rsl, template PDU_ML3_MS_NW l3_info, boolean do_clear := true, boolean expect_bssmap_l3 := true)
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007145runs on MSC_ConnHdlr {
7146 timer T := 10.0;
7147 var octetstring l3_enc := enc_PDU_ML3_MS_NW(valueof(l3_info));
7148
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007149 f_logp(BSCVTY, "establish channel, send Complete Layer 3 Info");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007150 f_create_bssmap_exp(l3_enc);
7151
7152 /* RSL_Emulation.f_chan_est() on rsl:
7153 * This is basically code dup with s/RSL/rsl from:
7154 * RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
7155 */
7156 var RSL_Message rx_rsl;
7157 var GsmRrMessage rr;
7158
7159 /* request a channel to be established */
7160 rsl.send(ts_RSLDC_ChanRqd(g_pars.ra, g_pars.fn));
7161 /* expect immediate assignment.
7162 * Code dup with s/RSL/rsl from:
7163 * rx_rsl := f_rx_or_fail(tr_RSL_IMM_ASSIGN);
7164 */
7165 timer Tt := 10.0;
7166
7167 /* request a channel to be established */
7168 Tt.start;
7169 alt {
7170 [] rsl.receive(tr_RSL_IMM_ASSIGN) -> value rx_rsl {
7171 Tt.stop;
7172 }
7173 [] rsl.receive {
7174 setverdict(fail, "Unexpected RSL message on DCHAN");
7175 mtc.stop;
7176 }
7177 [] Tt.timeout {
7178 setverdict(fail, "Timeout waiting for RSL on DCHAN");
7179 mtc.stop;
7180 }
7181 }
7182 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
7183 g_chan_nr := rr.payload.imm_ass.chan_desc.chan_nr;
7184 rsl.send(ts_RSL_EST_IND(g_chan_nr, valueof(g_pars.link_id), l3_enc));
7185
7186
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007187 if (expect_bssmap_l3) {
7188 f_logp(BSCVTY, "expect BSSAP Complete Layer 3 Info at MSC");
7189 var template PDU_BSSAP exp_l3_compl;
7190 exp_l3_compl := tr_BSSMAP_ComplL3()
7191 if (g_pars.aoip == false) {
7192 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := omit;
7193 } else {
7194 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := ?;
7195 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007196
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007197 var PDU_BSSAP bssap;
7198 T.start;
7199 alt {
7200 [] BSSAP.receive(exp_l3_compl) -> value bssap {
7201 f_logp(BSCVTY, "received expected Complete Layer 3 Info at MSC");
7202 log("rx exp_l3_compl = ", bssap);
7203 }
7204 [] BSSAP.receive(tr_BSSMAP_ComplL3) {
7205 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching COMPLETE LAYER 3 INFORMATION");
7206 }
7207 [] T.timeout {
7208 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
7209 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007210 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007211
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007212 /* start ciphering, if requested */
7213 if (ispresent(g_pars.encr)) {
7214 f_logp(BSCVTY, "start ciphering");
Neels Hofmeyr6c388f22021-06-11 02:36:56 +02007215 f_cipher_mode(g_pars.encr);
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007216 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007217 }
7218
7219 if (do_clear) {
7220 f_perform_clear(rsl);
7221 }
7222 setverdict(pass);
7223 f_sleep(1.0);
7224}
7225
7226private function f_tc_mscpool_compl_l3(charstring id) runs on MSC_ConnHdlr {
7227 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
7228 if (g_pars.mscpool.rsl_idx == 0) {
7229 f_perform_compl_l3(RSL, g_pars.mscpool.l3_info);
7230 } else if (g_pars.mscpool.rsl_idx == 1) {
7231 f_perform_compl_l3(RSL1, g_pars.mscpool.l3_info);
7232 } else if (g_pars.mscpool.rsl_idx == 2) {
7233 f_perform_compl_l3(RSL2, g_pars.mscpool.l3_info);
7234 }
7235}
7236
7237/* Various Complete Layer 3 by IMSI all end up with the first MSC, because the other MSCs are not connected. */
7238private function f_tc_mscpool_L3Compl_on_1_msc(charstring id) runs on MSC_ConnHdlr {
7239 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
7240 f_perform_compl_l3(RSL, ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O) );
7241 f_perform_compl_l3(RSL, ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_IMSI_LV('001010000000002'H))) );
7242 f_perform_compl_l3(RSL, ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))) );
7243 f_perform_compl_l3(RSL, ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_IMSI_LV('001010000000004'H))) );
7244}
7245testcase TC_mscpool_L3Compl_on_1_msc() runs on test_CT {
7246
7247 f_init(1, true);
7248 f_sleep(1.0);
7249 var MSC_ConnHdlr vc_conn;
7250 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007251
7252 f_ctrs_msc_init();
7253
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007254 vc_conn := f_start_handler(refers(f_tc_mscpool_L3Compl_on_1_msc), pars);
7255 vc_conn.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007256
7257 f_ctrs_msc_expect(0, "mscpool:subscr:new", 4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007258 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007259}
7260
7261/* Three Layer 3 Complete by IMSI are round-robin'ed across two connected MSCs */
7262/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7263 * just as well using only RSL. */
7264testcase TC_mscpool_L3Complete_by_imsi_round_robin() runs on test_CT {
7265
7266 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7267 f_sleep(1.0);
7268
7269 /* Control which MSC gets chosen next by the round-robin, otherwise
7270 * would be randomly affected by which other tests ran before this. */
7271 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7272
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007273 f_ctrs_msc_init();
7274
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007275 var MSC_ConnHdlr vc_conn1;
7276 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7277 pars1.mscpool.rsl_idx := 0;
7278 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
7279 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7280 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007281 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007282
7283 var MSC_ConnHdlr vc_conn2;
7284 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7285 pars2.mscpool.rsl_idx := 1;
7286 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
7287 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7288 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007289 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007290
7291 /* Test round-robin wrap to the first MSC */
7292 var MSC_ConnHdlr vc_conn3;
7293 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
7294 pars3.mscpool.rsl_idx := 2;
7295 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
7296 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7297 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007298 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007299 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007300}
7301
7302/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 0
7303 * (configured in osmo-bsc.cfg). */
7304/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7305 * just as well using only RSL. */
7306testcase TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() runs on test_CT {
7307
7308 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7309 f_sleep(1.0);
7310
7311 /* Control which MSC gets chosen next by the round-robin, otherwise
7312 * would be randomly affected by which other tests ran before this. */
7313 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7314
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007315 f_ctrs_msc_init();
7316
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007317 var MSC_ConnHdlr vc_conn1;
7318 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7319 pars1.mscpool.rsl_idx := 0;
7320 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
7321 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7322 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007323 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007324
7325 var MSC_ConnHdlr vc_conn2;
7326 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7327 pars2.mscpool.rsl_idx := 1;
7328 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
7329 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7330 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007331 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007332
7333 /* Test round-robin wrap to the first MSC */
7334 var MSC_ConnHdlr vc_conn3;
7335 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
7336 pars3.mscpool.rsl_idx := 2;
7337 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
7338 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7339 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007340 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007341 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007342}
7343
7344/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 1
7345 * (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
7346 * NULL-NRI setting is stronger than that. */
7347/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7348 * just as well using only RSL. */
7349testcase TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() runs on test_CT {
7350
7351 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7352 f_sleep(1.0);
7353
7354 /* Control which MSC gets chosen next by the round-robin, otherwise
7355 * would be randomly affected by which other tests ran before this. */
7356 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7357
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007358 f_ctrs_msc_init();
7359
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007360 var MSC_ConnHdlr vc_conn1;
7361 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7362 pars1.mscpool.rsl_idx := 0;
7363 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
7364 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7365 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007366 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007367
7368 var MSC_ConnHdlr vc_conn2;
7369 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7370 pars2.mscpool.rsl_idx := 1;
7371 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
7372 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7373 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007374 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007375
7376 /* Test round-robin wrap to the first MSC */
7377 var MSC_ConnHdlr vc_conn3;
7378 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
7379 pars3.mscpool.rsl_idx := 2;
7380 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
7381 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7382 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007383 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007384 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007385}
7386
7387/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI not
7388 * assigned to any MSC (configured in osmo-bsc.cfg). */
7389/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7390 * just as well using only RSL. */
7391testcase TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() runs on test_CT {
7392
7393 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7394 f_sleep(1.0);
7395
7396 /* Control which MSC gets chosen next by the round-robin, otherwise
7397 * would be randomly affected by which other tests ran before this. */
7398 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7399
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007400 f_ctrs_msc_init();
7401
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007402 var MSC_ConnHdlr vc_conn1;
7403 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7404 pars1.mscpool.rsl_idx := 0;
7405 /* An NRI that is not assigned to any MSC */
7406 pars1.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(1023))));
7407 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7408 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007409 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007410
7411 var MSC_ConnHdlr vc_conn2;
7412 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7413 pars2.mscpool.rsl_idx := 1;
7414 /* An NRI that is not assigned to any MSC */
7415 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(768)), '00F110'O));
7416 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7417 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007418 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007419
7420 /* Test round-robin wrap to the first MSC */
7421 var MSC_ConnHdlr vc_conn3;
7422 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
7423 pars3.mscpool.rsl_idx := 2;
7424 /* An NRI that is not assigned to any MSC */
7425 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, valueof(ts_MI_TMSI_NRI_LV(819))));
7426 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7427 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007428 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007429 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007430}
7431
7432/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI
7433 * assigned to an MSC that is currently not connected (configured in osmo-bsc.cfg). */
7434/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7435 * just as well using only RSL. */
7436testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() runs on test_CT {
7437
7438 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7439 f_sleep(1.0);
7440
7441 /* Control which MSC gets chosen next by the round-robin, otherwise
7442 * would be randomly affected by which other tests ran before this. */
7443 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7444
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007445 f_ctrs_msc_init();
7446
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007447 var MSC_ConnHdlr vc_conn1;
7448 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7449 pars1.mscpool.rsl_idx := 0;
7450 /* An NRI that is assigned to an unconnected MSC */
7451 pars1.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(512))));
7452 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7453 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007454 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
7455 f_ctrs_msc_add(0, "mscpool:subscr:new");
7456 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007457
7458 var MSC_ConnHdlr vc_conn2;
7459 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7460 pars2.mscpool.rsl_idx := 1;
7461 /* An NRI that is assigned to an unconnected MSC */
7462 pars2.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(767))));
7463 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7464 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007465 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
7466 f_ctrs_msc_add(1, "mscpool:subscr:new");
7467 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007468
7469 /* Test round-robin wrap to the first MSC */
7470 var MSC_ConnHdlr vc_conn3;
7471 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
7472 pars3.mscpool.rsl_idx := 2;
7473 /* An NRI that is assigned to an unconnected MSC */
7474 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(750)), '00F110'O));
7475 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7476 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007477 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
7478 f_ctrs_msc_add(0, "mscpool:subscr:new");
7479 f_ctrs_msc_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007480 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007481}
7482
7483/* Three Layer 3 Complete by TMSI with valid NRI for the second MSC are all directed to the second MSC (configured in
7484 * osmo-bsc.cfg). */
7485/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7486 * just as well using only RSL. */
7487testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_1() runs on test_CT {
7488
7489 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7490 f_sleep(1.0);
7491
7492 /* All TMSIs in this test point at the second MSC, set the round robin to point at the first MSC to make sure
7493 * this is not using round-robin. */
7494 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7495
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007496 f_ctrs_msc_init();
7497
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007498 var MSC_ConnHdlr vc_conn1;
7499 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
7500 pars1.mscpool.rsl_idx := 0;
7501 /* An NRI of the second MSC's range (256-511) */
7502 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(256))));
7503 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7504 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007505 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007506
7507 var MSC_ConnHdlr vc_conn2;
7508 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7509 pars2.mscpool.rsl_idx := 1;
7510 /* An NRI of the second MSC's range (256-511) */
7511 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(260))));
7512 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7513 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007514 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007515
7516 var MSC_ConnHdlr vc_conn3;
7517 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
7518 pars3.mscpool.rsl_idx := 2;
7519 /* An NRI of the second MSC's range (256-511) */
7520 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(511)), '00F110'O));
7521 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7522 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007523 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007524 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007525}
7526
7527/* Layer 3 Complete by TMSI with valid NRI for the third MSC are directed to the third MSC (configured in osmo-bsc.cfg),
7528 * while a round-robin remains unaffected by that. */
7529/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7530 * just as well using only RSL. */
7531testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_2() runs on test_CT {
7532
7533 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
7534 f_sleep(1.0);
7535
7536 /* All TMSIs in this test point at the third MSC, set the round robin to point at the second MSC to make sure
7537 * this is not using round-robin. */
7538 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
7539
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007540 f_ctrs_msc_init();
7541
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007542 var MSC_ConnHdlr vc_conn1;
7543 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 2);
7544 pars1.mscpool.rsl_idx := 0;
7545 /* An NRI of the third MSC's range (512-767) */
7546 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(512))));
7547 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7548 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007549 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007550
7551 var MSC_ConnHdlr vc_conn2;
7552 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
7553 pars2.mscpool.rsl_idx := 1;
7554 /* An NRI of the third MSC's range (512-767) */
7555 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(678))));
7556 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7557 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007558 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007559
7560 /* The above forwardings to third MSC have not affected the round robin, which still points at the second MSC */
7561 var MSC_ConnHdlr vc_conn3;
7562 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
7563 pars3.mscpool.rsl_idx := 2;
7564 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000013'H)), '00F110'O));
7565 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7566 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007567 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007568 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007569}
7570
7571/* LU with a TMSI but indicating a different PLMN in its previous LAI: ignore the NRI. */
7572/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7573 * just as well using only RSL. */
7574testcase TC_mscpool_LU_by_tmsi_from_other_PLMN() runs on test_CT {
7575
7576 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
7577 f_sleep(1.0);
7578
7579 /* The TMSIs in this test points at the second MSC, but since it is from a different PLMN, round-robin is used
7580 * instead, and hits msc 0. */
7581 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7582
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007583 f_ctrs_msc_init();
7584
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007585 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-bsc.cfg */
7586 var MSC_ConnHdlr vc_conn1;
7587 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7588 pars1.mscpool.rsl_idx := 0;
7589 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(260)), '99F999'O));
7590 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7591 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007592 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007593
7594 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
7595 var MSC_ConnHdlr vc_conn2;
7596 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
7597 pars2.mscpool.rsl_idx := 1;
7598 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(555)), '00F110'O));
7599 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7600 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007601 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007602 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007603}
7604
7605/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by IMSI, which would be
7606 * round-robined to another MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
7607private function f_tc_mscpool_paging_imsi(charstring id) runs on MSC_ConnHdlr {
7608 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
7609 //cid_list := { cIl_allInBSS := ''O };
7610 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
7611 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
7612 var BSSAP_N_UNITDATA_req paging;
7613 var hexstring imsi := '001010000000123'H;
7614
7615 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
7616
Neels Hofmeyr90f80962020-06-12 16:16:55 +02007617 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007618 valueof(ts_BSSMAP_Paging(imsi, cid_list, omit, bssmap_chneed))));
7619 BSSAP.send(paging);
7620
7621 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
7622 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
7623 * channel number is picked here. */
7624 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
7625 f_rslem_register(0, new_chan_nr);
7626 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(imsi)));
7627 f_rslem_unregister(0, new_chan_nr);
7628
7629 /* Despite the round robin pointing at the second MSC ('roundrobin next 1'), the earlier Paging for the same IMSI
7630 * causes this Paging Response to go to the first MSC (bssap_idx := 0). */
7631 f_perform_compl_l3(RSL, ts_PAG_RESP(valueof(ts_MI_IMSI_LV(imsi))) );
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007632 f_sleep(1.0);
7633}
7634testcase TC_mscpool_paging_and_response_imsi() runs on test_CT {
7635 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
7636 f_sleep(1.0);
7637
7638 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
7639 * second MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
7640 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
7641
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007642 f_ctrs_msc_init();
7643
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007644 var MSC_ConnHdlr vc_conn1;
7645 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7646 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02007647 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
7648 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007649 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_imsi), pars1);
7650 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007651 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007652 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007653}
7654
7655/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by TMSI with an NRI value
7656 * that matches a different MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
7657private function f_tc_mscpool_paging_tmsi(charstring id) runs on MSC_ConnHdlr {
7658 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
7659 //cid_list := { cIl_allInBSS := ''O };
7660 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
7661 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
7662 var integer nri_v := 300; /* <-- second MSC's NRI */
Harald Weltebf397612021-01-14 20:39:46 +01007663 var octetstring tmsi := f_gen_tmsi(suffix := 0, nri_v := nri_v);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007664 var BSSAP_N_UNITDATA_req paging;
7665
7666 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
7667
Neels Hofmeyr90f80962020-06-12 16:16:55 +02007668 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007669 valueof(ts_BSSMAP_Paging('001010000000011'H, cid_list, tmsi, bssmap_chneed))));
7670 BSSAP.send(paging);
7671
7672 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
7673 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
7674 * channel number is picked here. */
7675 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
7676 f_rslem_register(0, new_chan_nr);
7677 RSL.receive(tr_RSL_PAGING_CMD(t_MI_TMSI(tmsi)));
7678 f_rslem_unregister(0, new_chan_nr);
7679
7680 /* Despite the NRI matching the second MSC (NRI from 'msc 1' in osmo-bsc.cfg) and round robin pointing at the
7681 * third MSC ('roundrobin next 2'), the earlier Paging for the same TMSI causes this Paging Response to go to
7682 * the first MSC (bssap_idx := 0). */
7683 f_perform_compl_l3(RSL, ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(nri_v))) );
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007684 f_sleep(1.0);
7685}
7686testcase TC_mscpool_paging_and_response_tmsi() runs on test_CT {
7687 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
7688 f_sleep(1.0);
7689
7690 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
7691 * third MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
7692 f_vty_transceive(BSCVTY, "mscpool roundrobin next 2");
7693
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007694 f_ctrs_msc_init();
7695
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007696 var MSC_ConnHdlr vc_conn1;
7697 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7698 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02007699 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
7700 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007701 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_tmsi), pars1);
7702 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007703 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007704 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007705}
7706
7707/* For round-robin, skip an MSC that has 'no allow-attach' set. */
7708/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7709 * just as well using only RSL. */
7710testcase TC_mscpool_no_allow_attach_round_robin() runs on test_CT {
7711
7712 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
7713 f_sleep(1.0);
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00007714 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
7715 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007716
7717 /* Control which MSC gets chosen next by the round-robin, otherwise
7718 * would be randomly affected by which other tests ran before this. */
7719 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7720
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007721 f_ctrs_msc_init();
7722
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007723 var MSC_ConnHdlr vc_conn1;
7724 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7725 pars1.mscpool.rsl_idx := 0;
7726 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
7727 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7728 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007729 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007730
7731 var MSC_ConnHdlr vc_conn2;
7732 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
7733 pars2.mscpool.rsl_idx := 1;
7734 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
7735 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7736 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007737 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007738
7739 var MSC_ConnHdlr vc_conn3;
7740 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
7741 pars3.mscpool.rsl_idx := 2;
7742 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
7743 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7744 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007745 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007746 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007747}
7748
7749/* An MSC that has 'no allow-attach' set should still serve subscribers that are already attached according to their
7750 * TMSI NRI. */
7751testcase TC_mscpool_no_allow_attach_valid_nri() runs on test_CT {
7752
7753 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
7754 f_sleep(1.0);
7755
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00007756 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
7757 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
7758
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007759 /* Control which MSC gets chosen next by the round-robin, otherwise
7760 * would be randomly affected by which other tests ran before this. */
7761 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7762
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007763 f_ctrs_msc_init();
7764
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007765 /* Round robin points at msc 0, but the valid NRI directs to msc 1, even though msc 1 has 'no allow-attach'. */
7766 var MSC_ConnHdlr vc_conn1;
7767 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
7768 pars1.mscpool.rsl_idx := 0;
7769 /* An NRI of the second MSC's range (256-511) */
7770 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_TMSI_NRI_LV(260))));
7771 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7772 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007773 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007774
7775 var MSC_ConnHdlr vc_conn2;
7776 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 0);
7777 pars2.mscpool.rsl_idx := 1;
7778 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
7779 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7780 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007781 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007782
7783 var MSC_ConnHdlr vc_conn3;
7784 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 2);
7785 pars3.mscpool.rsl_idx := 2;
7786 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000003'H))));
7787 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7788 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007789 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007790 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007791}
7792
Philipp Maier783681c2020-07-16 16:47:06 +02007793/* Allow/Deny emergency calls globally via VTY */
7794private function f_vty_allow_emerg_msc(boolean allow) runs on test_CT {
7795 f_vty_enter_cfg_msc(BSCVTY, 0);
7796 if (allow) {
7797 f_vty_transceive(BSCVTY, "allow-emergency allow");
7798 } else {
7799 f_vty_transceive(BSCVTY, "allow-emergency deny");
7800 }
7801 f_vty_transceive(BSCVTY, "exit");
7802 f_vty_transceive(BSCVTY, "exit");
7803}
7804
7805/* Allow/Deny emergency calls per BTS via VTY */
7806private function f_vty_allow_emerg_bts(boolean allow, integer bts_nr) runs on test_CT {
7807 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
7808 if (allow) {
7809 f_vty_transceive(BSCVTY, "rach emergency call allowed 1");
7810 } else {
7811 f_vty_transceive(BSCVTY, "rach emergency call allowed 0");
7812 }
7813 f_vty_transceive(BSCVTY, "exit");
7814 f_vty_transceive(BSCVTY, "exit");
Neels Hofmeyrb6ed80c2020-10-12 22:52:39 +00007815 f_vty_transceive(BSCVTY, "exit");
Philipp Maier783681c2020-07-16 16:47:06 +02007816}
7817
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02007818/* Allow/Forbid Fast Return after SRVCC on a given BTS via VTY */
7819private function f_vty_allow_srvcc_fast_return(boolean allow, integer bts_nr) runs on test_CT {
7820 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
7821 if (allow) {
7822 f_vty_transceive(BSCVTY, "srvcc fast-return allow");
7823 } else {
7824 f_vty_transceive(BSCVTY, "srvcc fast-return forbid");
7825 }
7826 f_vty_transceive(BSCVTY, "exit");
7827 f_vty_transceive(BSCVTY, "exit");
7828 f_vty_transceive(BSCVTY, "exit");
7829}
7830
Philipp Maier783681c2020-07-16 16:47:06 +02007831/* Begin assignmet procedure and send an EMERGENCY SETUP (RR) */
7832private function f_assignment_emerg_setup() runs on MSC_ConnHdlr {
7833 var PDU_ML3_MS_NW emerg_setup;
7834 var octetstring emerg_setup_enc;
7835 var RSL_Message emerg_setup_data_ind;
7836
7837 f_establish_fully(omit, omit);
7838
7839 emerg_setup := valueof(ts_ML3_MO_CC_EMERG_SETUP(1, valueof(ts_Bcap_voice)));
7840 emerg_setup_enc := enc_PDU_ML3_MS_NW(emerg_setup);
7841 emerg_setup_data_ind := valueof(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), emerg_setup_enc));
7842
7843 RSL.send(emerg_setup_data_ind);
7844}
7845
7846/* Test if the EMERGENCY SETUP gets passed on to the MSC via A when EMERGENCY
7847 * CALLS are permitted by the BSC config. */
7848private function f_TC_assignment_emerg_setup_allow(charstring id) runs on MSC_ConnHdlr {
7849 var PDU_BSSAP emerg_setup_data_ind_bssap;
7850 var PDU_ML3_MS_NW emerg_setup;
7851 timer T := 3.0;
7852
7853 f_assignment_emerg_setup()
7854
7855 T.start;
7856 alt {
7857 [] BSSAP.receive(tr_BSSAP_DTAP) -> value emerg_setup_data_ind_bssap {
7858 emerg_setup := dec_PDU_ML3_MS_NW(emerg_setup_data_ind_bssap.pdu.dtap);
7859 if (not isbound(emerg_setup.msgs.cc.emergencySetup)) {
7860 setverdict(fail, "no emergency setup");
7861 }
7862 }
7863 [] BSSAP.receive {
7864 setverdict(fail, "unexpected BSSAP message!");
7865 }
7866 [] T.timeout {
7867 setverdict(fail, "timout waiting for EMERGENCY SETUP!");
7868 }
7869 }
7870
7871 setverdict(pass);
7872}
7873
7874/* Test if the EMERGENCY SETUP gets blocked by the BSC if EMERGENCY CALLS are
7875 * forbidden by the BSC config. */
7876private function f_TC_assignment_emerg_setup_deny(charstring id) runs on MSC_ConnHdlr {
7877 var PDU_BSSAP emerg_setup_data_ind_bssap;
7878 timer T := 3.0;
7879
7880 f_assignment_emerg_setup()
7881
7882 T.start;
7883 alt {
7884 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
7885 setverdict(pass);
7886 }
7887 [] RSL.receive {
7888 setverdict(fail, "unexpected RSL message!");
7889 }
7890 [] T.timeout {
7891 setverdict(fail, "timout waiting for RR CHANNEL RELEASE!");
7892 }
7893 }
7894}
7895
7896/* EMERGENCY CALL situation #1, allowed globally and by BTS */
7897testcase TC_assignment_emerg_setup_allow() runs on test_CT {
7898 var TestHdlrParams pars := f_gen_test_hdlr_pars();
7899 var MSC_ConnHdlr vc_conn;
7900
7901 f_init(1, true);
7902 f_sleep(1.0);
7903
7904 f_vty_allow_emerg_msc(true);
7905 f_vty_allow_emerg_bts(true, 0);
7906 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_allow), pars);
7907 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007908 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02007909}
7910
7911/* EMERGENCY CALL situation #2, forbidden globally but allowed by BTS */
7912testcase TC_assignment_emerg_setup_deny_msc() runs on test_CT {
7913 var TestHdlrParams pars := f_gen_test_hdlr_pars();
7914 var MSC_ConnHdlr vc_conn;
7915
7916 f_init(1, true);
7917 f_sleep(1.0);
7918
7919 f_vty_allow_emerg_msc(false);
7920 f_vty_allow_emerg_bts(true, 0);
7921 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
7922 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007923 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02007924}
7925
7926/* EMERGENCY CALL situation #3, allowed globally but forbidden by BTS */
7927testcase TC_assignment_emerg_setup_deny_bts() runs on test_CT {
7928 var TestHdlrParams pars := f_gen_test_hdlr_pars();
7929 var MSC_ConnHdlr vc_conn;
7930
7931 /* Note: This simulates a spec violation by the MS, correct MS
7932 * implementations would not try to establish an emergency call because
7933 * the system information tells in advance that emergency calls are
7934 * not forbidden */
7935
7936 f_init(1, true);
7937 f_sleep(1.0);
7938
7939 f_vty_allow_emerg_msc(true);
7940 f_vty_allow_emerg_bts(false, 0);
7941 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
7942 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007943 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02007944}
7945
Philipp Maier82812002020-08-13 18:48:27 +02007946/* Test what happens when an emergency call arrives while all TCH channels are
7947 * busy, the BSC is expected to terminate one call in favor of the incoming
7948 * emergency call */
7949testcase TC_emerg_premption() runs on test_CT {
7950 var ASP_RSL_Unitdata rsl_ud;
7951 var integer i;
7952 var integer chreq_total, chreq_nochan;
7953 var RSL_Message rx_rsl;
7954 var RslChannelNr chan_nr;
7955
7956 f_init(1);
7957 f_sleep(1.0);
7958
7959 f_vty_allow_emerg_msc(true);
7960 f_vty_allow_emerg_bts(true, 0);
7961
7962 /* Fill up all channels on the BTS */
7963 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
7964 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
7965 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS; i := i+1) {
7966 chan_nr := f_chreq_act_ack('33'O, i);
7967 }
7968 IPA_RSL[0].clear;
7969 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
7970 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
7971
7972 /* Send Channel request for emegergency call */
7973 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
7974
7975 /* Expect the BSC to release one (the first) TCH/F on the BTS */
7976 chan_nr := valueof(t_RslChanNr_Bm(1));
7977 f_expect_chan_rel(0, chan_nr, expect_rr_chan_rel := false, expect_rll_rel_req := false);
7978
7979 /* Expect the BSC to send activate/assign the a channel for the emergency call */
7980 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7981 chan_nr := rx_rsl.ies[0].body.chan_nr;
7982 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 33));
7983 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Philipp Maier104f4c02020-09-11 18:12:18 +02007984
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007985 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007986}
7987
7988/* Hopping parameters per a timeslot */
Vadim Yanitskiybc6654a2020-09-13 01:27:40 +07007989private type record length(0..64) of GsmArfcn ArfcnList;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007990private type record FHParamsTs {
7991 boolean enabled,
7992 uint6_t hsn,
7993 uint6_t maio,
7994 ArfcnList ma
7995};
7996
7997/* Hopping parameters per a transceiver */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07007998private type record FHParamsTrx {
7999 GsmArfcn arfcn,
8000 FHParamsTs ts[8]
8001};
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008002
8003/* Randomly generate the hopping parameters for the given timeslot numbers */
8004private function f_TC_fh_params_gen(template integer tr_tn := (1, 3, 5))
8005runs on test_CT return FHParamsTrx {
8006 var FHParamsTrx fhp;
8007
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07008008 /* Generate a random ARFCN, including ARFCN 0 */
8009 fhp.arfcn := f_rnd_int(3);
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008010
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008011 for (var integer tn := 0; tn < 8; tn := tn + 1) {
8012 if (not match(tn, tr_tn)) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008013 fhp.ts[tn].enabled := false;
8014 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008015 continue;
8016 }
8017
8018 /* Random HSN / MAIO values: 0..63 */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008019 fhp.ts[tn].hsn := f_rnd_int(64);
8020 fhp.ts[tn].maio := f_rnd_int(64);
8021 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008022
8023 /* Random Mobile Allocation (hopping channels) */
8024 var integer ma_len := 2 + f_rnd_int(9); /* 2..10 channels */
8025 var integer step := 3 + f_rnd_int(4); /* 3..6 stepping */
8026 for (var integer i := 1; i <= ma_len; i := i + 1) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008027 fhp.ts[tn].ma := fhp.ts[tn].ma & { i * step };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008028 }
8029
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008030 fhp.ts[tn].enabled := true;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008031 }
8032
8033 log("f_TC_fh_params_gen(): ", fhp);
8034 return fhp;
8035}
8036
8037/* Make sure that the given Channel Description IE matches the hopping configuration */
8038private function f_TC_fh_params_match_chan_desc(in FHParamsTrx fhp, in ChannelDescription cd)
8039{
8040 var template (present) ChannelDescription tr_cd;
8041 var template (present) MaioHsn tr_maio_hsn;
8042 var uint3_t tn := cd.chan_nr.tn;
8043
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008044 if (fhp.ts[tn].enabled) {
8045 tr_maio_hsn := tr_HsnMaio(fhp.ts[tn].hsn, fhp.ts[tn].maio);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008046 tr_cd := tr_ChanDescH1(cd.chan_nr, tr_maio_hsn);
8047 } else {
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008048 tr_cd := tr_ChanDescH0(cd.chan_nr, fhp.arfcn);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008049 }
8050
8051 if (not match(cd, tr_cd)) {
8052 setverdict(fail, "Channel Description IE does not match: ",
8053 cd, " vs expected ", tr_cd);
8054 }
8055}
8056
8057/* Make sure that the given Mobile Allocation IE matches the hopping configuration */
8058private function f_TC_fh_params_match_ma(in FHParamsTrx fhp, uint3_t tn,
8059 in MobileAllocationLV ma)
8060{
8061 var template MobileAllocationLV tr_ma := f_TC_fh_params_gen_tr_ma(fhp, tn, ma);
8062
8063 if (not match(ma, tr_ma)) {
8064 setverdict(fail, "Mobile Allocation IE does not match (tn := ",
8065 tn, "): ", ma, " vs expected: ", tr_ma);
8066 } else {
8067 setverdict(pass);
8068 }
8069}
8070
8071private function f_TC_fh_params_gen_tr_ma(in FHParamsTrx fhp, uint3_t tn,
8072 in MobileAllocationLV ma)
8073return template MobileAllocationLV {
8074 /* Mobile Allocation IE is expected to be empty if hopping is not enabled */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008075 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008076 return { len := 0, ma := ''B };
8077 }
8078
8079 var bitstring full_mask := f_pad_bit(''B, 1024, '0'B);
8080 var bitstring slot_mask := f_pad_bit(''B, 1024, '0'B);
8081 var bitstring ma_mask := ''B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008082
8083 /* Compose the full bit-mask (all channels, up to 1024 entries) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008084 for (var integer i := 0; i < lengthof(fhp.ts); i := i + 1) {
8085 for (var integer j := 0; j < lengthof(fhp.ts[i].ma); j := j + 1) {
8086 if (full_mask[fhp.ts[i].ma[j]] == '1'B)
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008087 { continue; }
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008088 full_mask[fhp.ts[i].ma[j]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008089 }
8090 }
8091
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008092 /* Take ARFCN of the TRX itself into account */
8093 full_mask[fhp.arfcn] := '1'B;
8094
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008095 /* Compose a bit-mask for the given timeslot number */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008096 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
8097 slot_mask[fhp.ts[tn].ma[i]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008098 }
8099
8100 /* Finally, compose the Mobile Allocation bit-mask */
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07008101 for (var integer i := 1; i < lengthof(full_mask); i := i + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008102 if (full_mask[i] != '1'B)
8103 { continue; }
8104
8105 /* FIXME: ma_mask := ma_mask & slot_mask[i]; // triggers a bug in TITAN */
8106 if (slot_mask[i] == '1'B) {
8107 ma_mask := ma_mask & '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008108 } else {
8109 ma_mask := ma_mask & '0'B;
8110 }
8111 }
8112
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07008113 /* ARFCN 0 (if present) goes to the last position of the bit-mask */
8114 if (full_mask[0] == '1'B) {
8115 /* FIXME: ma_mask := ma_mask & slot_mask[0]; // triggers a bug in TITAN */
8116 if (slot_mask[0] == '1'B) {
8117 ma_mask := ma_mask & '1'B;
8118 } else {
8119 ma_mask := ma_mask & '0'B;
8120 }
8121 }
8122
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008123 /* Ensure that ma_mask is octet-aligned */
Vadim Yanitskiy2aa02522020-09-06 14:05:23 +07008124 var integer ma_mask_len := (lengthof(ma_mask) + 8 - 1) / 8;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008125 ma_mask := f_pad_bit(ma_mask, ma_mask_len * 8, '0'B);
8126
8127 return { len := ma_mask_len, ma := ma_mask };
8128}
8129
8130/* Configure the hopping parameters in accordance with the given record */
8131private function f_TC_fh_params_set(in FHParamsTrx fhp,
8132 uint8_t bts_nr := 0,
8133 uint8_t trx_nr := 0)
8134runs on test_CT {
8135 /* Enter the configuration node for the given BTS/TRX numbers */
8136 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
8137
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008138 f_vty_transceive(BSCVTY, "arfcn " & int2str(fhp.arfcn));
8139
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008140 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008141 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
8142
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008143 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008144 f_vty_transceive(BSCVTY, "hopping enabled 0");
8145 f_vty_transceive(BSCVTY, "exit"); /* go back */
8146 continue;
8147 }
8148
8149 /* Configure HSN / MAIO values */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008150 f_vty_transceive(BSCVTY, "hopping sequence-number " & int2str(fhp.ts[tn].hsn));
8151 f_vty_transceive(BSCVTY, "hopping maio " & int2str(fhp.ts[tn].maio));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008152
8153 /* Configure the Mobile Allocation (hopping channels) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008154 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
8155 f_vty_transceive(BSCVTY, "hopping arfcn add " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008156 }
8157
8158 f_vty_transceive(BSCVTY, "hopping enabled 1");
8159 f_vty_transceive(BSCVTY, "exit"); /* go back */
8160 }
8161
8162 f_vty_transceive(BSCVTY, "end");
8163}
8164
8165/* Disable frequency hopping on all timeslots */
8166private function f_TC_fh_params_unset(in FHParamsTrx fhp,
8167 uint8_t bts_nr := 0,
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008168 uint8_t trx_nr := 0,
8169 GsmArfcn arfcn := 871)
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008170runs on test_CT {
8171 /* Enter the configuration node for the given BTS/TRX numbers */
8172 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
8173
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008174 f_vty_transceive(BSCVTY, "arfcn " & int2str(arfcn));
8175
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008176 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008177 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
8178
8179 /* Delete all ARFCNs from the Mobile Allocation (if any) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008180 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
8181 f_vty_transceive(BSCVTY, "hopping arfcn del " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008182 }
8183
8184 f_vty_transceive(BSCVTY, "hopping enabled 0");
8185 f_vty_transceive(BSCVTY, "exit"); /* go back */
8186 }
8187
8188 f_vty_transceive(BSCVTY, "end");
8189 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8190}
8191
8192/* Verify presence and correctness of the hopping parameters (HSN, MAIO)
8193 * in the Channel Identification IE of the RSL CHANnel ACTIVation message. */
8194testcase TC_fh_params_chan_activ() runs on test_CT {
8195 var FHParamsTrx fhp := f_TC_fh_params_gen();
8196 var RSL_Message rsl_msg;
8197 var RSL_IE_Body ie;
8198
8199 f_init_vty();
8200
8201 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
8202 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8203
8204 f_init(1);
8205
8206 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
8207 for (var integer i := 0; i < 9; i := i + 1) {
8208 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
8209 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8210
8211 /* Make sure that Channel Identification IE is present */
8212 if (not f_rsl_find_ie(rsl_msg, RSL_IE_CHAN_IDENT, ie)) {
8213 setverdict(fail, "RSL Channel Identification IE is absent");
8214 continue;
8215 }
8216
8217 /* Make sure that hopping parameters (HSN/MAIO) match */
8218 f_TC_fh_params_match_chan_desc(fhp, ie.chan_ident.ch_desc.v);
8219
8220 /* "Mobile Allocation shall be included but empty" - let's check this */
8221 if (ie.chan_ident.ma.v.len != 0) {
8222 setverdict(fail, "Mobile Allocation IE is not empty: ",
8223 ie.chan_ident.ma, ", despite it shall be");
8224 continue;
8225 }
8226 }
8227
8228 /* Disable frequency hopping */
8229 f_TC_fh_params_unset(fhp);
8230
Vadim Yanitskiy21726312020-09-04 01:45:36 +07008231 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008232}
8233
8234/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Immediate Assignment */
8235testcase TC_fh_params_imm_ass() runs on test_CT {
8236 var FHParamsTrx fhp := f_TC_fh_params_gen();
8237 var RSL_Message rsl_msg;
8238 var RSL_IE_Body ie;
8239
8240 f_init_vty();
8241
8242 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
8243 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8244
8245 f_init(1);
8246
8247 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
8248 for (var integer i := 0; i < 9; i := i + 1) {
8249 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
8250 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8251
8252 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
8253 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
8254
8255 /* Make sure that Full Immediate Assign Info IE is present */
8256 if (not f_rsl_find_ie(rsl_msg, RSL_IE_FULL_IMM_ASS_INFO, ie)) {
8257 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
8258 continue;
8259 }
8260
8261 /* Decode the actual Immediate Assignment message */
8262 var GsmRrMessage rr_msg := dec_GsmRrMessage(ie.full_imm_ass_info.payload);
8263 if (not match(rr_msg.header, t_RrHeader(IMMEDIATE_ASSIGNMENT, ?))) {
8264 setverdict(fail, "Failed to match Immediate Assignment: ", rr_msg);
8265 continue;
8266 }
8267
8268 /* Make sure that hopping parameters (HSN/MAIO) match */
8269 f_TC_fh_params_match_chan_desc(fhp, rr_msg.payload.imm_ass.chan_desc);
8270
8271 /* Make sure that the Mobile Allocation IE matches */
8272 f_TC_fh_params_match_ma(fhp, rr_msg.payload.imm_ass.chan_desc.chan_nr.tn,
8273 rr_msg.payload.imm_ass.mobile_allocation);
8274 }
8275
8276 /* Disable frequency hopping */
8277 f_TC_fh_params_unset(fhp);
Philipp Maier82812002020-08-13 18:48:27 +02008278
Vadim Yanitskiy21726312020-09-04 01:45:36 +07008279 f_shutdown_helper();
Philipp Maier82812002020-08-13 18:48:27 +02008280}
8281
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07008282/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Assignment Command */
8283testcase TC_fh_params_assignment_cmd() runs on test_CT {
8284 var FHParamsTrx fhp := f_TC_fh_params_gen();
8285 var RSL_Message rsl_msg;
8286 var RSL_IE_Body ie;
8287
8288 f_init_vty();
8289
8290 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
8291 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8292
8293 f_init(1);
8294
8295 /* HACK: work around "Couldn't find Expect for CRCX" */
8296 vc_MGCP.stop;
8297
8298 var template PDU_BSSAP ass_cmd := f_gen_ass_req();
8299 ass_cmd.pdu.bssmap.assignmentRequest.codecList := ts_BSSMAP_IE_CodecList({ts_CodecFR});
8300
8301 /* CS domain (TCH): 4 (TCH/F) + 2 (TCH/H) channels available
8302 * NOTE: only 3 SDCCH/4 channels are available on CCCH+SDCCH4+CBCH */
8303 for (var integer i := 0; i < 3; i := i + 1) {
8304 /* Establish a dedicated channel, so we can trigger (late) TCH assignment */
8305 var DchanTuple dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
8306
8307 /* Send a BSSMAP Assignment Command, expect CHANnel ACTIVation */
8308 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
8309 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8310
8311 /* ACKnowledge CHANnel ACTIVation, expect RSL DATA REQuest */
8312 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
8313 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
8314
8315 /* Make sure that L3 Information IE is present */
8316 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
8317 setverdict(fail, "RSL L3 Information IE is absent");
8318 continue;
8319 }
8320
8321 /* Decode the L3 message and make sure it is (RR) Assignment Command */
8322 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
8323 if (not match(l3_msg.header, t_RrL3Header(ASSIGNMENT_COMMAND))) {
8324 setverdict(fail, "Failed to match Assignment Command: ", l3_msg);
8325 continue;
8326 }
8327
8328 /* Make sure that hopping parameters (HSN/MAIO) match */
8329 var ChannelDescription chan_desc := l3_msg.payload.ass_cmd.chan_desc;
8330 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
8331
8332 /* Make sure that Cell Channel Description IE is present if FH is enabled */
8333 if (chan_desc.h and not ispresent(l3_msg.payload.ass_cmd.cell_chan_desc)) {
Vadim Yanitskiy38d069d2020-09-02 17:18:57 +07008334 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07008335 continue;
8336 }
8337
8338 /* Make sure that the Mobile Allocation IE matches (if present) */
8339 var boolean ma_present := ispresent(l3_msg.payload.ass_cmd.mobile_allocation);
8340 if (chan_desc.h and ma_present) {
8341 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
8342 l3_msg.payload.ass_cmd.mobile_allocation.v);
8343 } else if (chan_desc.h and not ma_present) {
8344 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
8345 continue;
8346 } else if (not chan_desc.h and ma_present) {
8347 setverdict(fail, "FH disabled, but Mobile Allocation IE is present");
8348 continue;
8349 }
8350 }
8351
8352 /* Give the IUT some time to release all channels */
8353 f_sleep(3.0);
8354
8355 /* Disable frequency hopping */
8356 f_TC_fh_params_unset(fhp);
8357
Vadim Yanitskiy21726312020-09-04 01:45:36 +07008358 f_shutdown_helper();
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07008359}
8360
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07008361/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Handover Command */
8362private function f_TC_fh_params_handover_cmd(in FHParamsTrx fhp)
8363runs on test_CT {
8364 var RSL_Message rsl_msg;
8365 var RSL_IE_Body ie;
8366 var DchanTuple dt;
8367
8368 /* Establish a dedicated channel, so we can trigger handover */
8369 dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
8370
8371 /* Trigger handover from BTS0 to BTS1 */
8372 f_bts_0_cfg(BSCVTY, { "neighbor bts 1" });
8373 f_vty_handover(BSCVTY, 0, 0, dt.rsl_chan_nr, 1);
8374
8375 /* Expect RSL CHANnel ACTIVation on BTS1/TRX0/TS1 */
8376 rsl_msg := f_exp_ipa_rx(1, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8377
8378 /* ACKnowledge channel activation and expect (RR) Handover Command */
8379 f_ipa_tx(1, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
8380 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
8381
8382 /* Make sure that L3 Information IE is present */
8383 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
8384 setverdict(fail, "RSL L3 Information IE is absent");
8385 return;
8386 }
8387
8388 /* Decode the L3 message and make sure it is (RR) Handover Command */
8389 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
8390 if (not match(l3_msg.header, t_RrL3Header(HANDOVER_COMMAND))) {
8391 setverdict(fail, "Failed to match Handover Command: ", l3_msg);
8392 return;
8393 }
8394
8395 /* Make sure that we've got SDCCH/8 on TS1 (expected to be hopping) */
8396 var ChannelDescription chan_desc := l3_msg.payload.ho_cmd.chan_desc;
8397 if (not match(chan_desc.chan_nr, t_RslChanNr_SDCCH8(1, ?))) {
8398 setverdict(fail, "Unexpected channel number: ", chan_desc.chan_nr);
8399 return;
8400 }
8401
8402 /* Make sure that hopping parameters (HSN/MAIO) match */
8403 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
8404
8405 /* Make sure that Cell Channel Description IE is present */
8406 if (not ispresent(l3_msg.payload.ho_cmd.cell_chan_desc)) {
8407 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
8408 return;
8409 }
8410
8411 /* Make sure that the Mobile Allocation (after time) IE is present and matches */
8412 var boolean ma_present := ispresent(l3_msg.payload.ho_cmd.mobile_allocation);
8413 if (ma_present) {
8414 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
8415 l3_msg.payload.ho_cmd.mobile_allocation.v);
8416 } else {
8417 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
8418 return;
8419 }
8420}
8421testcase TC_fh_params_handover_cmd() runs on test_CT {
8422 var FHParamsTrx fhp := f_TC_fh_params_gen();
8423
8424 f_init_vty();
8425
8426 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8 on BTS1/TRX0 */
8427 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
8428
8429 f_vty_transceive(BSCVTY, "timeslot 0");
8430 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
8431 f_vty_transceive(BSCVTY, "exit"); /* go back */
8432
8433 f_vty_transceive(BSCVTY, "timeslot 1");
8434 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8");
8435 f_vty_transceive(BSCVTY, "end"); /* we're done */
8436
8437 f_TC_fh_params_set(fhp, 1); /* Enable frequency hopping on BTS1 */
8438 f_vty_transceive(BSCVTY, "drop bts connection 1 oml");
8439
8440 f_init(2);
8441
8442 f_TC_fh_params_handover_cmd(fhp);
8443
8444 /* Disable frequency hopping on BTS1 */
8445 f_TC_fh_params_unset(fhp, 1);
8446
8447 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
8448 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
8449
8450 f_vty_transceive(BSCVTY, "timeslot 0");
8451 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
8452 f_vty_transceive(BSCVTY, "exit"); /* go back */
8453
8454 f_vty_transceive(BSCVTY, "timeslot 1");
8455 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
8456 f_vty_transceive(BSCVTY, "end"); /* we're done */
8457
8458 f_shutdown_helper();
8459}
8460
Vadim Yanitskiyca974032020-09-01 07:20:39 +07008461/* Verify the hopping parameters in System Information Type 4 */
8462testcase TC_fh_params_si4_cbch() runs on test_CT {
8463 var FHParamsTrx fhp := f_TC_fh_params_gen(tr_tn := 1);
8464 var ASP_RSL_Unitdata rx_rsl_ud;
8465 timer T := 5.0;
8466
8467 f_init_vty();
8468
8469 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8+CBCH */
8470 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
8471
8472 f_vty_transceive(BSCVTY, "timeslot 0");
8473 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
8474 f_vty_transceive(BSCVTY, "exit"); /* go back */
8475
8476 f_vty_transceive(BSCVTY, "timeslot 1");
8477 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8+cbch");
8478 f_vty_transceive(BSCVTY, "end"); /* we're done */
8479
8480 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
8481 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8482
8483 f_init(1);
8484
8485 T.start;
8486 alt {
8487 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO(RSL_SYSTEM_INFO_4))) -> value rx_rsl_ud {
8488 var RSL_IE_Body ie := rx_rsl_ud.rsl.ies[2].body; /* FULL BCCH Information IE */
8489 var SystemInformation si := dec_SystemInformation(ie.other.payload);
8490
8491 /* Make sure that what we decoded is System Information Type 4 */
8492 if (si.header.message_type != SYSTEM_INFORMATION_TYPE_4) {
8493 setverdict(fail, "RSL FULL BCCH Information IE contains: ", si);
8494 repeat;
8495 }
8496
8497 /* Make sure that CBCH Channel Description IE is present */
8498 if (not ispresent(si.payload.si4.cbch_chan_desc)) {
8499 setverdict(fail, "CBCH Channel Description IE is absent");
8500 break;
8501 }
8502
8503 /* Finally, check the hopping parameters (HSN, MAIO) */
8504 var ChannelDescription chan_desc := si.payload.si4.cbch_chan_desc.v;
8505 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
8506
8507 /* 3GPP TS 44.018, section 9.1.36.2 "CBCH Mobile Allocation":
8508 * The CBCH Mobile Allocation IE *shall* be present if FH is enabled. */
8509 if (chan_desc.h and not ispresent(si.payload.si4.cbch_mobile_alloc)) {
8510 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
8511 break;
8512 } else if (chan_desc.h and ispresent(si.payload.si4.cbch_mobile_alloc)) {
8513 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
8514 si.payload.si4.cbch_mobile_alloc.v);
8515 }
8516 }
8517 [] IPA_RSL[0].receive { repeat; }
8518 [] T.timeout {
8519 setverdict(fail, "Timeout waiting for RSL BCCH INFOrmation (SI4)");
8520 }
8521 }
8522
8523 /* Disable frequency hopping */
8524 f_TC_fh_params_unset(fhp);
8525
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07008526 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
Vadim Yanitskiyca974032020-09-01 07:20:39 +07008527 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
8528
8529 f_vty_transceive(BSCVTY, "timeslot 0");
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07008530 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
Vadim Yanitskiyca974032020-09-01 07:20:39 +07008531 f_vty_transceive(BSCVTY, "exit"); /* go back */
8532
8533 f_vty_transceive(BSCVTY, "timeslot 1");
8534 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
8535 f_vty_transceive(BSCVTY, "end"); /* we're done */
8536
Vadim Yanitskiy21726312020-09-04 01:45:36 +07008537 f_shutdown_helper();
Vadim Yanitskiyca974032020-09-01 07:20:39 +07008538}
8539
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008540template (value) PDU_BSSAP_LE ts_BSSMAP_LE_BSSLAP(template (value) BSSLAP_PDU bsslap)
8541 := ts_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, data := enc_BSSLAP_PDU(valueof(bsslap)));
8542
8543private function f_match_bsslap(PDU_BSSAP_LE got_bsslap_msg,
8544 template (present) BSSLAP_PDU expect_bsslap)
8545{
8546 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(got_bsslap_msg.pdu.bssmap.co_info.bsslap_apdu.data);
8547 if (not match(bsslap, expect_bsslap)) {
8548 log("EXPECTING BSSLAP: ", expect_bsslap);
8549 log("GOT BSSLAP: ", bsslap);
8550 setverdict(fail, "BSSLAP is not as expected");
8551 mtc.stop;
8552 }
8553 setverdict(pass);
8554}
8555
8556/* GAD: this is an Ellipsoid point with uncertainty circle, encoded as in 3GPP TS 23.032 §7.3.2. */
8557const octetstring gad_ell_point_unc_circle := '10b0646d0d5f6627'O;
8558
8559private function f_expect_bsslap(template (present) BSSLAP_PDU expect_rx_bsslap) runs on MSC_ConnHdlr {
8560 var PDU_BSSAP_LE rx_bsslap;
8561 BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap);
8562 f_match_bsslap(rx_bsslap, expect_rx_bsslap);
8563}
8564
8565/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
8566 * Request on Lb interface. Either with or without the SMLC doing a BSSLAP TA Request. */
8567private function f_lcs_loc_req_for_active_ms(boolean do_ta_request := false) runs on MSC_ConnHdlr {
8568 f_sleep(1.0);
8569
8570 f_establish_fully(omit, omit);
8571 f_bssap_le_register_imsi(g_pars.imsi, omit);
8572
8573 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
8574 ts_CellId_CGI('262'H, '42'H, 23, 42))));
8575
8576 var PDU_BSSAP_LE plr;
8577 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
8578
8579 if (not do_ta_request) {
8580 /* verify TA Layer 3 in APDU. First the APDU type (BSSLAP), then the BSSLAP data contents. */
8581 var template BSSMAP_LE_IE_APDU expect_apdu := tr_BSSMAP_LE_APDU(BSSMAP_LE_PROT_BSSLAP, ?);
8582 if (not match(plr.pdu.bssmap.perf_loc_req.bsslap_apdu, expect_apdu)) {
8583 log("EXPECTING BSSMAP-LE APDU IE ", expect_apdu);
8584 log("GOT BSSMAP-LE APDU IE ", plr.pdu.bssmap.perf_loc_req.bsslap_apdu);
8585 setverdict(fail, "BSSMAP-LE APDU IE is not as expected");
8586 mtc.stop;
8587 }
8588 var template BSSLAP_PDU expect_ta_layer3 := tr_BSSLAP_TA_Layer3(tr_BSSLAP_IE_TA(0));
8589 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(plr.pdu.bssmap.perf_loc_req.bsslap_apdu.data);
8590 if (not match(bsslap, expect_ta_layer3)) {
8591 log("EXPECTING BSSLAP TA Layer 3: ", expect_ta_layer3);
8592 log("GOT BSSLAP: ", bsslap);
8593 setverdict(fail, "BSSLAP is not as expected");
8594 mtc.stop;
8595 }
8596 /* OsmoBSC directly sent the TA as BSSLAP APDU in the BSSMAP-LE Perform Location Request to the SMLC. The SMLC
8597 * has no need to request the TA from the BSC and directly responds. */
8598 } else {
8599 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
8600 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
8601 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
8602 }
8603
8604 /* SMLC got the TA from the BSC, now responds with geo information data. */
8605 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
8606 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
8607 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
8608
8609 /* The LCS was using an active A-interface conn. It should still remain active after this. */
8610 f_mo_l3_transceive();
8611
8612 f_perform_clear(RSL);
8613
8614 f_sleep(2.0);
8615 setverdict(pass);
8616}
8617
8618/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
8619 * Request on Lb interface. Without the SMLC doing a BSSLAP TA Request. */
8620private function f_tc_lcs_loc_req_for_active_ms(charstring id) runs on MSC_ConnHdlr {
8621 f_lcs_loc_req_for_active_ms(false);
8622}
8623testcase TC_lcs_loc_req_for_active_ms() runs on test_CT {
8624 var MSC_ConnHdlr vc_conn;
8625 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8626
8627 f_init(1, true);
8628 f_sleep(1.0);
8629 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms), pars);
8630 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01008631 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008632}
8633
8634/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
8635 * Request on Lb interface. With the SMLC doing a BSSLAP TA Request. */
8636private function f_tc_lcs_loc_req_for_active_ms_ta_req(charstring id) runs on MSC_ConnHdlr {
8637 f_lcs_loc_req_for_active_ms(true);
8638}
8639testcase TC_lcs_loc_req_for_active_ms_ta_req() runs on test_CT {
8640 var MSC_ConnHdlr vc_conn;
8641 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8642
8643 f_init(1, true);
8644 f_sleep(1.0);
8645 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_ta_req), pars);
8646 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01008647 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008648}
8649
8650/* Clear the A-interface conn only, without doing anything on Abis. Useful for LCS, for cases where there is only an A
8651 * conn without an active lchan. */
8652private function f_clear_A_conn() runs on MSC_ConnHdlr
8653{
8654 var BssmapCause cause := 0;
8655 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
8656 BSSAP.receive(tr_BSSMAP_ClearComplete);
8657 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
8658
8659 timer no_more_bssap := 5.0;
8660 no_more_bssap.start;
8661 alt {
8662 [] no_more_bssap.timeout { break; }
8663 [] BSSAP.receive(tr_BSSAP_BSSMAP) {
8664 setverdict(fail, "Expected no more BSSAP after Clear Complete");
8665 mtc.stop;
8666 }
8667 }
8668 setverdict(pass);
8669}
8670
8671/* Verify that the A-interface connection is still working, and then clear it, without doing anything on Abis. Useful
8672 * for LCS, for cases where there is only an A conn without an active lchan. */
8673private function f_verify_active_A_conn_and_clear() runs on MSC_ConnHdlr
8674{
8675 f_logp(BSCVTY, "f_verify_active_A_conn_and_clear: test A link, then clear");
8676
8677 /* When an lchan is active, we can send some L3 data from the BTS side and verify that it shows up on the other
8678 * side towards the MSC. When there is no lchan, this is not possible. To probe whether the A-interface
8679 * connection is still up, we need something that echos back on the A-interface. Another LCS request! */
8680 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
8681 ts_CellId_CGI('262'H, '42'H, 23, 42))));
8682 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?));
8683
8684 /* Right, the Perform Location Request showed up on Lb, now we can clear the A conn. */
8685 f_clear_A_conn();
8686 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
8687 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
8688}
8689
8690/* With *no* active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
8691 * Request on Lb interface. BSC will Page for the subscriber as soon as we (virtual SMLC) request the TA via BSSLAP.
8692 */
8693private function f_tc_lcs_loc_req_for_idle_ms(charstring id) runs on MSC_ConnHdlr {
8694 f_sleep(1.0);
8695
8696 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8697 f_bssap_le_register_imsi(g_pars.imsi, omit);
8698
8699 /* Register to receive the Paging Command */
8700 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
8701 g_chan_nr := new_chan_nr;
8702 f_rslem_register(0, g_chan_nr);
8703
8704 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
8705 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
8706 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
8707 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
8708
8709 var PDU_BSSAP_LE plr;
8710 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
8711
8712 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
8713 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
8714
8715 /* OsmoBSC needs to Page */
8716 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi)));
8717 f_logp(BSCVTY, "got Paging Command");
8718
8719 /* MS requests channel. Since the Paging was for LCS, the Paging Response does not trigger a Complete Layer 3 to
8720 * the MSC, and releases the lchan directly. */
8721 f_perform_compl_l3(RSL, ts_PAG_RESP(valueof(ts_MI_IMSI_LV(g_pars.imsi))), do_clear := false, expect_bssmap_l3 := false);
8722 f_expect_lchan_rel(RSL);
8723
8724 /* From the Paging Response, the TA is now known to the BSC, and it responds to the SMLC. */
8725
8726 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
8727
8728 /* SMLC got the TA from the BSC, now responds with geo information data. */
8729 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
8730 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
8731
8732 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
8733
8734 /* The lchan is gone, the A-interface conn was created for the LCS only.
8735 * Still it is clearly the MSC's job to decide whether to tear down the conn or not. */
8736 f_verify_active_A_conn_and_clear();
8737
8738 f_sleep(2.0);
8739 setverdict(pass);
8740}
8741testcase TC_lcs_loc_req_for_idle_ms() runs on test_CT {
8742 var MSC_ConnHdlr vc_conn;
8743 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8744
8745 f_init(1, true);
8746 f_sleep(1.0);
8747
8748 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
8749 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
8750
8751 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms), pars);
8752 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01008753 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008754}
8755
8756/* With no active lchan, start BSSMAP Perform Location Request on A interface, but omit IMSI; expect failure response.
8757 */
8758private function f_tc_lcs_loc_req_no_subscriber(charstring id) runs on MSC_ConnHdlr {
8759 f_sleep(1.0);
8760
8761 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8762 f_bssap_le_register_imsi(g_pars.imsi, omit);
8763
8764 /* provoke an abort by omitting both IMSI and IMEI */
8765 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
8766 valueof(ts_BSSMAP_Perform_Location_Request(omit,
8767 ts_CellId_CGI('262'H, '42'H, 23, 42)))));
8768 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
8769
8770 /* BSC tells MSC about failure */
8771 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
8772 locationEstimate := omit, positioningData := omit,
8773 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_DATA_MISSING_IN_REQ)));
8774
8775 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
8776 f_verify_active_A_conn_and_clear();
8777
8778 f_sleep(2.0);
8779 setverdict(pass);
8780}
8781testcase TC_lcs_loc_req_no_subscriber() runs on test_CT {
8782 var MSC_ConnHdlr vc_conn;
8783 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8784
8785 f_init(1, true);
8786 f_sleep(1.0);
8787
8788 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
8789 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
8790
8791 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_no_subscriber), pars);
8792 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01008793 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008794}
8795
8796/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
8797 * BSSMAP-LE Perform Location Response (before or after sending a BSSLAP TA Request) */
8798private function f_lcs_loc_req_for_active_ms_le_timeout(boolean do_ta) runs on MSC_ConnHdlr {
8799 f_sleep(1.0);
8800
8801 f_establish_fully(omit, omit);
8802 f_bssap_le_register_imsi(g_pars.imsi, omit);
8803
8804 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
8805 ts_CellId_CGI('262'H, '42'H, 23, 42))));
8806
8807 var PDU_BSSAP_LE plr;
8808 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
8809
8810 if (do_ta) {
8811 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
8812 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
8813 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
8814 }
8815
8816 /* SMLC fails to respond, BSC runs into timeout */
8817 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_SYSTEM_FAILURE));
8818 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
8819
8820 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
8821 locationEstimate := omit, positioningData := omit,
8822 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_SYSTEM_FAILURE)));
8823
8824 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
8825 f_verify_active_A_conn_and_clear();
8826
8827 f_sleep(2.0);
8828 setverdict(pass);
8829}
8830
8831/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
8832 * BSSMAP-LE Perform Location Response, without sending a BSSLAP TA Request. */
8833private function f_tc_lcs_loc_req_for_active_ms_le_timeout(charstring id) runs on MSC_ConnHdlr {
8834 f_lcs_loc_req_for_active_ms_le_timeout(false);
8835}
8836
8837testcase TC_lcs_loc_req_for_active_ms_le_timeout() runs on test_CT {
8838 var MSC_ConnHdlr vc_conn;
8839 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8840
8841 f_init(1, true);
8842 f_sleep(1.0);
8843 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout), pars);
8844 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01008845 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008846}
8847
8848/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
8849 * BSSMAP-LE Perform Location Response, after sending a BSSLAP TA Request. */
8850private function f_tc_lcs_loc_req_for_active_ms_le_timeout2(charstring id) runs on MSC_ConnHdlr {
8851 f_lcs_loc_req_for_active_ms_le_timeout(true);
8852}
8853
8854testcase TC_lcs_loc_req_for_active_ms_le_timeout2() runs on test_CT {
8855 var MSC_ConnHdlr vc_conn;
8856 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8857
8858 f_init(1, true);
8859 f_sleep(1.0);
8860 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout2), pars);
8861 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01008862 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008863}
8864
8865/* With *no* active lchan, start a Perform Location Request, expecting that the MS will be Paged. */
8866private function f_tc_lcs_loc_req_for_idle_ms_no_pag_resp(charstring id) runs on MSC_ConnHdlr {
8867 f_sleep(1.0);
8868
8869 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8870 f_bssap_le_register_imsi(g_pars.imsi, omit);
8871
8872 /* Register to receive the Paging Command */
8873 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
8874 g_chan_nr := new_chan_nr;
8875 f_rslem_register(0, g_chan_nr);
8876
8877 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
8878 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
8879 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
8880 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
8881
8882 var PDU_BSSAP_LE plr;
8883 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
8884
8885 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
8886 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
8887
8888 /* OsmoBSC needs to Page */
8889 var PDU_BSSAP_LE rx_bsslap;
8890 alt {
8891 [] RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi))) {
8892 f_logp(BSCVTY, "got Paging Command");
8893 repeat;
8894 }
8895 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
8896 /* MS does not respond to Paging, TA Req runs into timeout. */
8897 f_match_bsslap(rx_bsslap, tr_BSSLAP_Abort(?));
8898 }
8899 }
8900
8901 /* SMLC responds with failure */
8902 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(omit, BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
8903 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
8904
8905 /* BSC tells MSC about failure */
8906 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
8907 locationEstimate := omit, positioningData := omit,
8908 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_REQUEST_ABORTED)));
8909
8910 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
8911 f_verify_active_A_conn_and_clear();
8912
8913 f_sleep(2.0);
8914 setverdict(pass);
8915}
8916testcase TC_lcs_loc_req_for_idle_ms_no_pag_resp() runs on test_CT {
8917 var MSC_ConnHdlr vc_conn;
8918 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8919
8920 f_init(1, true);
8921 f_sleep(1.0);
8922
8923 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
8924 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
8925
8926 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms_no_pag_resp), pars);
8927 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01008928 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008929}
8930
8931/* During an ongoing Location Request, the MS sends a CM Service Request. Expect the same A-conn to be re-used / taken
8932 * over. */
8933private function f_tc_cm_service_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
8934 f_sleep(1.0);
8935
8936 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8937 f_bssap_le_register_imsi(g_pars.imsi, omit);
8938
8939 /* Register to receive the Paging Command */
8940 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
8941 g_chan_nr := new_chan_nr;
8942 f_rslem_register(0, g_chan_nr);
8943
8944 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
8945 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
8946 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
8947 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
8948
8949 var PDU_BSSAP_LE plr;
8950 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
8951
8952 /* As the A-interface conn was established for LCS, the MS coincidentally decides to issue a CM Service Request
8953 * and establish Layer 3. It should use the existing A-interface conn. */
8954 f_perform_compl_l3(RSL, valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV(g_pars.imsi)))),
8955 do_clear := false, expect_bssmap_l3 := true);
8956
8957 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
8958 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
8959
8960 /* OsmoBSC already has an lchan, no need to Page, just returns the TA */
8961 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
8962
8963 /* SMLC got the TA from the BSC, now responds with geo information data. */
8964 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
8965 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
8966 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
8967
8968 /* The lchan should still exist, it was from a CM Service Request. */
8969 f_mo_l3_transceive();
8970
8971 f_perform_clear(RSL);
8972
8973 f_sleep(2.0);
8974 setverdict(pass);
8975}
8976testcase TC_cm_service_during_lcs_loc_req() runs on test_CT {
8977 var MSC_ConnHdlr vc_conn;
8978 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8979
8980 f_init(1, true);
8981 f_sleep(1.0);
8982
8983 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
8984 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
8985
8986 vc_conn := f_start_handler(refers(f_tc_cm_service_during_lcs_loc_req), pars);
8987 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01008988 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008989}
8990
8991/* During an ongoing Perform Location Request, do a Handover, an expect a BSSLAP Reset message from the BSC to indicate
8992 * the new lchan after handover. */
8993private function f_tc_ho_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
8994 f_sleep(1.0);
8995
8996 f_establish_fully(omit, omit);
8997 f_bssap_le_register_imsi(g_pars.imsi, omit);
8998
8999 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9000 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9001
9002 var PDU_BSSAP_LE plr;
9003 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9004
9005 /* SMLC ponders the Location Request, in the meantime the BSC decides to handover */
9006 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
9007
9008 var HandoverState hs := {
9009 rr_ho_cmpl_seen := false,
9010 handover_done := false,
9011 old_chan_nr := -
9012 };
9013 /* issue hand-over command on VTY */
9014 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
9015 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
9016 f_rslem_suspend(RSL1_PROC);
9017
9018 /* From the MGW perspective, a handover is is characterized by
9019 * performing one MDCX operation with the MGW. So we expect to see
9020 * one more MDCX during handover. */
9021 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
9022
9023 alt {
9024 [] as_handover(hs);
9025 }
9026
9027 var PDU_BSSAP_LE rx_bsslap;
9028
9029 interleave {
9030 /* Expect the BSC to inform the MSC about the handover */
9031 [] BSSAP.receive(tr_BSSMAP_HandoverPerformed);
9032
9033 /* Expect the BSC to inform the SMLC about the handover */
9034 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
9035 f_match_bsslap(rx_bsslap, tr_BSSLAP_Reset(BSSLAP_CAUSE_INTRA_BSS_HO));
9036 }
9037 }
9038
9039 /* SMLC now responds with geo information data. */
9040 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9041 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9042 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9043
9044 /* lchan still active */
9045 f_mo_l3_transceive(RSL1);
9046
9047 /* MSC decides it is done now. */
9048 f_perform_clear(RSL1);
9049
9050 f_sleep(2.0);
9051 setverdict(pass);
9052}
9053testcase TC_ho_during_lcs_loc_req() runs on test_CT {
9054 var MSC_ConnHdlr vc_conn;
9055 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9056
9057 f_init(2, true);
9058 f_sleep(1.0);
9059 vc_conn := f_start_handler(refers(f_tc_ho_during_lcs_loc_req), pars);
9060 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009061 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009062}
9063
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009064/* Attempt Complete Layer 3 without any MSC available (OS#4832) */
9065private function f_tc_no_msc(charstring id) runs on MSC_ConnHdlr {
9066 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9067
9068 /* Also disable attach for the single connected MSC */
9069 f_vty_msc_allow_attach(BSCVTY, { false });
9070
9071 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) ));
9072 f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
9073
9074 /* No MSC is found, expecting a proper release on RSL */
9075 interleave {
9076 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
9077 f_logp(BSCVTY, "Got RSL RR Release");
9078 }
9079 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
9080 f_logp(BSCVTY, "Got RSL Deact SACCH");
9081 }
9082 [] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
9083 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
9084 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
9085 }
9086 }
9087 setverdict(pass);
9088}
9089testcase TC_no_msc() runs on test_CT {
9090
9091 f_init(1, true);
9092 f_sleep(1.0);
9093 var MSC_ConnHdlr vc_conn;
9094 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9095
9096 f_ctrs_bsc_init(counternames_bsc_mscpool);
9097
9098 vc_conn := f_start_handler(refers(f_tc_no_msc), pars);
9099 vc_conn.done;
9100
9101 f_ctrs_bsc_add("mscpool:subscr:no_msc");
9102 f_ctrs_bsc_verify();
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009103 f_shutdown_helper();
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009104}
9105
Harald Welte0ea2d5e2018-04-07 21:40:29 +02009106/* Dyn PDCH todo:
9107 * activate OSMO as TCH/F
9108 * activate OSMO as TCH/H
9109 * does the BSC-located PCU socket get the updated INFO?
9110 * what if no PCU is connected at the time?
9111 * is the info correct on delayed PCU (re)connect?
9112 */
Harald Welte94e0c342018-04-07 11:33:23 +02009113
Neels Hofmeyr87857ec2021-04-25 16:17:47 +00009114private function f_TC_refuse_mode_modif_to_vamos(charstring id) runs on MSC_ConnHdlr {
9115 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
9116 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
9117
9118 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
9119 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
9120 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
9121 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
9122 g_pars.ass_codec_list.codecElements[0];
9123 if (isvalue(g_pars.expect_mr_s0_s7)) {
9124 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
9125 g_pars.expect_mr_s0_s7;
9126 }
9127 }
9128 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
9129 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
9130 log("expecting ASS COMPL like this: ", exp_compl);
9131
9132 f_establish_fully(ass_cmd, exp_compl);
9133
Neels Hofmeyr8746b0d2021-06-01 17:25:39 +02009134 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 +00009135
9136 var RSL_Message rsl;
9137
9138 timer T := 5.0;
9139 T.start;
9140 alt {
9141 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
9142 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
9143 log("Rx L3 from net: ", l3);
9144 if (ischosen(l3.msgs.rrm.channelModeModify)) {
9145 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
9146 mtc.stop;
9147 }
9148 }
9149 [] RSL.receive(tr_RSL_MODE_MODIFY_REQ(g_chan_nr, ?)) -> value rsl {
9150 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
9151 mtc.stop;
9152 }
9153 [] T.timeout {
9154 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related Mode Modify should happen. */
9155 setverdict(pass);
9156 }
9157 }
9158 T.stop;
9159}
9160
9161/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel Mode Modify to VAMOS mode is refused by
9162 * osmo-bsc. */
9163testcase TC_refuse_mode_modif_to_vamos() runs on test_CT {
9164 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9165 var MSC_ConnHdlr vc_conn;
9166
9167 f_init(1, true);
9168 f_sleep(1.0);
9169
9170 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
9171 vc_conn := f_start_handler(refers(f_TC_refuse_mode_modif_to_vamos), pars);
9172 vc_conn.done;
9173 f_shutdown_helper();
9174}
9175
9176/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel activation to VAMOS mode is refused by osmo-bsc.
9177 */
9178testcase TC_refuse_chan_act_to_vamos() runs on test_CT {
9179 f_init_vty();
9180
9181 f_init(1, false);
9182 f_sleep(1.0);
9183
9184 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 activate-vamos fr");
9185
9186 var ASP_RSL_Unitdata rx_rsl_ud;
9187 timer T := 5.0;
9188
9189 T.start;
9190 alt {
9191 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(?, IPAC_PROTO_RSL_TRX0)) -> value rx_rsl_ud {
9192 if (rx_rsl_ud.rsl.msg_type == RSL_MT_CHAN_ACTIV) {
9193 T.stop;
9194 setverdict(fail, "CHANnel ACTivate in VAMOS mode succeeded even though BTS does not support VAMOS");
9195 mtc.stop;
9196 }
9197 repeat;
9198 }
9199 [] T.timeout {
9200 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related CHANnel ACTivate should happen. */
9201 setverdict(pass);
9202 }
9203 }
9204}
9205
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009206private function f_TC_reassignment_codec(charstring id) runs on MSC_ConnHdlr {
9207 /* First fully set up a speech lchan */
9208 f_TC_assignment_codec(id);
9209
9210 /* Trigger re-assignment to another lchan */
9211 var AssignmentState assignment_st := valueof(ts_AssignmentStateInit);
9212
9213 /* Re-Assignment should tell the MGW endpoint the new lchan's RTP address and port, so expecting to see exactly
9214 * one MDCX on MGCP. */
9215 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].mdcx_seen_exp + 1;
9216
9217 /* The new lchan will see all-new IPAC_CRCX and IPAC_MDCX messages telling the BTS the same RTP address and port
9218 * as the old lchan used. */
9219 g_media.bts.ipa_crcx_seen := false;
9220 g_media.bts.ipa_mdcx_seen := false;
9221
9222 /* Send different BTS side RTP port number for the new lchan */
9223 g_media.bts.bts.port_nr := 4223;
9224
9225 f_rslem_register(0, valueof(ts_RslChanNr_Bm(2))); /* <-- FIXME: can we somehow infer the timeslot that will be used? */
9226
9227 /* Trigger re-assignment. */
9228 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot " & int2str(g_chan_nr.tn) & " sub-slot 0 assignment");
9229
9230 timer T := 5.0;
9231 T.start;
9232 alt {
9233 [] as_assignment(assignment_st);
9234 [] as_Media();
9235 [] T.timeout {
9236 break;
9237 }
9238 }
9239
9240 if (not assignment_st.assignment_done) {
9241 setverdict(fail, "Assignment did not complete");
9242 mtc.stop;
9243 }
9244
9245 f_check_mgcp_expectations()
9246 setverdict(pass);
9247
9248 f_sleep(2.0);
9249 log("show lchan summary: ", f_vty_transceive_ret(BSCVTY, "show lchan summary"));
9250
9251 /* Instruct BSC to clear channel */
9252 var BssmapCause cause := 0;
9253 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
9254 interleave {
9255 [] MGCP.receive(tr_DLCX) {}
9256 [] MGCP.receive(tr_DLCX) {}
9257 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {}
9258 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
9259 [] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
9260 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
9261 }
9262 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
9263 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
9264 }
9265 }
9266
9267 f_sleep(0.5);
9268}
9269
9270testcase TC_reassignment_fr() runs on test_CT {
9271 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9272 var MSC_ConnHdlr vc_conn;
9273
9274 f_init(1, true);
9275 f_sleep(1.0);
9276
9277 f_ctrs_bsc_and_bts_init();
9278
9279 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
9280 vc_conn := f_start_handler(refers(f_TC_reassignment_codec), pars);
9281 vc_conn.done;
9282
9283 /* from f_establish_fully() */
9284 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
9285 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
9286 /* from re-assignment */
9287 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
9288 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
9289 f_ctrs_bsc_and_bts_verify();
9290 f_shutdown_helper();
9291}
9292
Neels Hofmeyr87857ec2021-04-25 16:17:47 +00009293
Harald Welte28d943e2017-11-25 15:00:50 +01009294control {
Harald Welte898113b2018-01-31 18:32:21 +01009295 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +01009296 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01009297 execute( TC_ctrl_msc0_connection_status() );
Harald Welte96c94412017-12-09 03:12:45 +01009298 execute( TC_ctrl() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +02009299 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER) {
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02009300 execute( TC_ctrl_location() );
9301 }
Harald Welte898113b2018-01-31 18:32:21 +01009302
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02009303 execute( TC_si_default() );
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02009304 execute( TC_si2quater_2_earfcns() );
9305 execute( TC_si2quater_3_earfcns() );
9306 execute( TC_si2quater_4_earfcns() );
9307 execute( TC_si2quater_5_earfcns() );
9308 execute( TC_si2quater_6_earfcns() );
Neels Hofmeyrad132f22020-07-08 02:20:16 +02009309 execute( TC_si2quater_12_earfcns() );
9310 execute( TC_si2quater_23_earfcns() );
9311 execute( TC_si2quater_32_earfcns() );
9312 execute( TC_si2quater_33_earfcns() );
9313 execute( TC_si2quater_42_earfcns() );
9314 execute( TC_si2quater_48_earfcns() );
9315 execute( TC_si2quater_49_earfcns() );
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02009316 execute( TC_si_acc_rotate() );
Alexander Couzens4ad3a352020-09-10 22:29:12 +02009317 execute( TC_si_acc_ramp_rotate() );
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02009318
Harald Welte898113b2018-01-31 18:32:21 +01009319 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +01009320 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +01009321 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +01009322 execute( TC_chan_act_ack_noest() );
Philipp Maier9c60a622020-07-09 15:08:46 +02009323 execute( TC_chan_act_ack_noest_emerg() );
Philipp Maier606f07d2020-08-12 17:21:58 +02009324 execute( TC_chan_rqd_emerg_deny() );
Harald Welteae026692017-12-09 01:03:01 +01009325 execute( TC_chan_act_ack_est_ind_noreply() );
9326 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +01009327 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +01009328 execute( TC_chan_exhaustion() );
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07009329 execute( TC_chan_deact_silence() );
Harald Welte4003d112017-12-09 22:35:39 +01009330 execute( TC_chan_rel_rll_rel_ind() );
9331 execute( TC_chan_rel_conn_fail() );
9332 execute( TC_chan_rel_hard_clear() );
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02009333 execute( TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() );
9334 execute( TC_chan_rel_last_eutran_plmn_hard_clear_csfb() );
Harald Welte99787102019-02-04 10:41:36 +01009335 execute( TC_chan_rel_hard_clear_csfb() );
Harald Welted8c36cd2017-12-09 23:05:31 +01009336 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +02009337 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +01009338 execute( TC_chan_rel_a_reset() );
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01009339 execute( TC_chan_rel_sccp_tiar_timeout() );
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02009340 execute( TC_chan_rel_rr_cause() );
Harald Welte6f521d82017-12-11 19:52:02 +01009341
Harald Weltecfe2c962017-12-15 12:09:32 +01009342 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +01009343
9344 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +01009345 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +01009346 execute( TC_assignment_csd() );
9347 execute( TC_assignment_ctm() );
9348 execute( TC_assignment_sign() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +02009349 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
9350 execute( TC_assignment_aoip_tla_v6() );
9351 }
Harald Welte235ebf12017-12-15 14:18:16 +01009352 execute( TC_assignment_fr_a5_0() );
9353 execute( TC_assignment_fr_a5_1() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +02009354 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte8f67d1d2018-05-25 20:38:42 +02009355 execute( TC_assignment_fr_a5_1_codec_missing() );
9356 }
Harald Welte235ebf12017-12-15 14:18:16 +01009357 execute( TC_assignment_fr_a5_3() );
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02009358 execute( TC_assignment_fr_a5_4() );
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +02009359 execute( TC_assignment_fr_a5_4_fail() );
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02009360 execute( TC_assignment_fr_a5_not_sup() );
Harald Welte3c86ea02018-05-10 22:28:05 +02009361 execute( TC_ciph_mode_a5_0() );
9362 execute( TC_ciph_mode_a5_1() );
Oliver Smith50b98122021-07-09 15:00:28 +02009363 execute( TC_ciph_mode_a5_2_0() );
Oliver Smith1dff88d2021-07-09 08:45:51 +02009364 execute( TC_ciph_mode_a5_2_1() );
Harald Welte3c86ea02018-05-10 22:28:05 +02009365 execute( TC_ciph_mode_a5_3() );
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02009366 execute( TC_ciph_mode_a5_4() );
Harald Welte16a4adf2017-12-14 18:54:01 +01009367
Harald Welte60aa5762018-03-21 19:33:13 +01009368 execute( TC_assignment_codec_fr() );
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02009369 execute( TC_assignment_codec_fr_by_mode_modify() );
Harald Welte60aa5762018-03-21 19:33:13 +01009370 execute( TC_assignment_codec_hr() );
9371 execute( TC_assignment_codec_efr() );
9372 execute( TC_assignment_codec_amr_f() );
9373 execute( TC_assignment_codec_amr_h() );
Philipp Maier8a581d22019-03-26 18:32:48 +01009374
Neels Hofmeyrf246a922020-05-13 02:27:10 +02009375 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier8a581d22019-03-26 18:32:48 +01009376 execute( TC_assignment_codec_amr_f_S1() );
9377 execute( TC_assignment_codec_amr_h_S1() );
9378 execute( TC_assignment_codec_amr_f_S124() );
9379 execute( TC_assignment_codec_amr_h_S124() );
9380 execute( TC_assignment_codec_amr_f_S0() );
9381 execute( TC_assignment_codec_amr_f_S02() );
9382 execute( TC_assignment_codec_amr_f_S024() );
9383 execute( TC_assignment_codec_amr_f_S0247() );
9384 execute( TC_assignment_codec_amr_h_S0() );
9385 execute( TC_assignment_codec_amr_h_S02() );
9386 execute( TC_assignment_codec_amr_h_S024() );
9387 execute( TC_assignment_codec_amr_h_S0247() );
9388 execute( TC_assignment_codec_amr_f_S01234567() );
9389 execute( TC_assignment_codec_amr_f_S0234567() );
9390 execute( TC_assignment_codec_amr_f_zero() );
9391 execute( TC_assignment_codec_amr_f_unsupp() );
9392 execute( TC_assignment_codec_amr_h_S7() );
Neels Hofmeyr21863562020-11-26 00:34:33 +00009393 execute( TC_assignment_codec_amr_f_start_mode_auto() );
9394 execute( TC_assignment_codec_amr_h_start_mode_auto() );
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00009395 execute( TC_assignment_codec_amr_f_start_mode_4() );
9396 execute( TC_assignment_codec_amr_h_start_mode_4() );
Neels Hofmeyr454d7922020-11-26 02:24:57 +00009397 execute( TC_assignment_codec_amr_startmode_cruft() );
Philipp Maier8a581d22019-03-26 18:32:48 +01009398 }
Harald Welte60aa5762018-03-21 19:33:13 +01009399
Philipp Maierac09bfc2019-01-08 13:41:39 +01009400 execute( TC_assignment_codec_fr_exhausted_req_hr() );
9401 execute( TC_assignment_codec_fr_exhausted_req_fr() );
9402 execute( TC_assignment_codec_fr_exhausted_req_fr_hr() );
9403 execute( TC_assignment_codec_fr_exhausted_req_hr_fr() );
9404 execute( TC_assignment_codec_hr_exhausted_req_fr() );
9405 execute( TC_assignment_codec_hr_exhausted_req_hr() );
9406 execute( TC_assignment_codec_hr_exhausted_req_hr_fr() );
9407 execute( TC_assignment_codec_hr_exhausted_req_fr_hr() );
9408 execute( TC_assignment_codec_req_hr_fr() );
9409 execute( TC_assignment_codec_req_fr_hr() );
9410
Pau Espin Pedrol23510fb2021-07-20 17:00:38 +02009411 execute( TC_assignment_osmux() );
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02009412
Harald Welte898113b2018-01-31 18:32:21 +01009413 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +01009414 execute( TC_rll_est_ind_inact_lchan() );
9415 execute( TC_rll_est_ind_inval_sapi1() );
9416 execute( TC_rll_est_ind_inval_sapi3() );
9417 execute( TC_rll_est_ind_inval_sacch() );
9418
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07009419 /* DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
9420 execute( TC_tch_dlci_link_id_sapi() );
9421
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07009422 /* SAPI N Reject triggered by RLL establishment failures */
9423 execute( TC_rll_rel_ind_sapi_n_reject() );
9424 execute( TC_rll_err_ind_sapi_n_reject() );
9425 execute( TC_rll_timeout_sapi_n_reject() );
9426
Harald Welte898113b2018-01-31 18:32:21 +01009427 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +01009428 execute( TC_paging_imsi_nochan() );
9429 execute( TC_paging_tmsi_nochan() );
9430 execute( TC_paging_tmsi_any() );
9431 execute( TC_paging_tmsi_sdcch() );
9432 execute( TC_paging_tmsi_tch_f() );
9433 execute( TC_paging_tmsi_tch_hf() );
9434 execute( TC_paging_imsi_nochan_cgi() );
9435 execute( TC_paging_imsi_nochan_lac_ci() );
9436 execute( TC_paging_imsi_nochan_ci() );
9437 execute( TC_paging_imsi_nochan_lai() );
9438 execute( TC_paging_imsi_nochan_lac() );
9439 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +01009440 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
9441 execute( TC_paging_imsi_nochan_rnc() );
9442 execute( TC_paging_imsi_nochan_lac_rnc() );
9443 execute( TC_paging_imsi_nochan_lacs() );
9444 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +01009445 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +01009446 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +01009447 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +01009448 execute( TC_paging_counter() );
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01009449 execute( TC_paging_resp_unsol() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +01009450
9451 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +01009452 execute( TC_rsl_unknown_unit_id() );
9453
9454 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +01009455
9456 execute( TC_classmark() );
Harald Welteeddf0e92020-06-21 19:42:15 +02009457 execute( TC_common_id() );
Harald Welte898113b2018-01-31 18:32:21 +01009458 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +01009459 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +01009460 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +01009461 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +01009462 execute( TC_err_84_unknown_msg() );
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01009463
Harald Welte261af4b2018-02-12 21:20:39 +01009464 execute( TC_ho_int() );
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02009465 execute( TC_ho_int_a5_0() );
9466 execute( TC_ho_int_a5_1() );
9467 execute( TC_ho_int_a5_3() );
9468 execute( TC_ho_int_a5_4() );
Neels Hofmeyr5f144212020-11-03 15:41:58 +00009469 execute( TC_ho_int_radio_link_failure() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01009470
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01009471 execute( TC_ho_out_of_this_bsc() );
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02009472 execute( TC_ho_out_fail_no_msc_response() );
9473 execute( TC_ho_out_fail_rr_ho_failure() );
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02009474 execute( TC_ho_out_fail_no_result_after_ho_cmd() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01009475
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01009476 execute( TC_ho_into_this_bsc() );
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02009477 execute( TC_ho_into_this_bsc_a5_0() );
9478 execute( TC_ho_into_this_bsc_a5_1() );
9479 execute( TC_ho_into_this_bsc_a5_3() );
9480 execute( TC_ho_into_this_bsc_a5_4() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +02009481 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
9482 execute( TC_ho_into_this_bsc_tla_v6() );
9483 }
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02009484 execute( TC_srvcc_eutran_to_geran() );
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02009485 execute( TC_srvcc_eutran_to_geran_ho_out() );
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02009486 execute( TC_srvcc_eutran_to_geran_forbid_fast_return() );
9487 execute( TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01009488 execute( TC_ho_in_fail_msc_clears() );
9489 execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
9490 execute( TC_ho_in_fail_no_detect() );
9491 execute( TC_ho_in_fail_no_detect2() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01009492
Neels Hofmeyr91401012019-07-11 00:42:35 +02009493 execute( TC_ho_neighbor_config_1() );
9494 execute( TC_ho_neighbor_config_2() );
9495 execute( TC_ho_neighbor_config_3() );
9496 execute( TC_ho_neighbor_config_4() );
9497 execute( TC_ho_neighbor_config_5() );
9498 execute( TC_ho_neighbor_config_6() );
9499 execute( TC_ho_neighbor_config_7() );
9500
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01009501 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01009502 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01009503 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +02009504
9505 execute( TC_dyn_pdch_ipa_act_deact() );
9506 execute( TC_dyn_pdch_ipa_act_nack() );
9507 execute( TC_dyn_pdch_osmo_act_deact() );
9508 execute( TC_dyn_pdch_osmo_act_nack() );
Pau Espin Pedrole076b3f2021-07-20 16:45:57 +02009509 if (mp_enable_dyn_sdcch8_test) {
9510 execute( TC_dyn_ts_sdcch8_act_deact() );
9511 execute (TC_dyn_ts_sdcch8_tch_call_act_deact() );
9512 execute( TC_dyn_ts_sdcch8_act_nack() );
9513 }
Harald Welte99f3ca02018-06-14 13:40:29 +02009514
Stefan Sperling0796a822018-10-05 13:01:39 +02009515 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02009516 execute( TC_chopped_ipa_payload() );
Stefan Sperling0796a822018-10-05 13:01:39 +02009517
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01009518 /* Power control related */
9519 execute( TC_assignment_verify_ms_power_params_ie() );
Vadim Yanitskiy4b233042021-06-30 00:58:43 +02009520 execute( TC_c0_power_red_mode() );
Neels Hofmeyr4f118412020-06-04 15:25:10 +02009521
9522 /* MSC pooling */
9523 /* FIXME: in SCCPlite, indicating how many MSCs should be connected does currently not work. Since
9524 * RESET->RESET-ACK is unconditionally negotiated for all configured MSCs, they always all appear as connected
9525 * to osmo-bsc. The MSC pooling tests however require disconnecting selected MSCs, and hence don't work out as
9526 * intended on SCCPlite. So for now, run these only for SCCP/M3UA. */
9527 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
9528 execute( TC_mscpool_L3Compl_on_1_msc() );
9529 execute( TC_mscpool_L3Complete_by_imsi_round_robin() );
9530 execute( TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() );
9531 execute( TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() );
9532 execute( TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() );
9533 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() );
9534 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_1() );
9535 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_2() );
9536 execute( TC_mscpool_LU_by_tmsi_from_other_PLMN() );
9537 execute( TC_mscpool_paging_and_response_imsi() );
9538 execute( TC_mscpool_paging_and_response_tmsi() );
9539 execute( TC_mscpool_no_allow_attach_round_robin() );
9540 execute( TC_mscpool_no_allow_attach_valid_nri() );
9541 }
9542
Harald Welte99f3ca02018-06-14 13:40:29 +02009543 /* at bottom as they might crash OsmoBSC before OS#3182 is fixed */
9544 execute( TC_early_conn_fail() );
9545 execute( TC_late_conn_fail() );
9546
Philipp Maier783681c2020-07-16 16:47:06 +02009547 /* Emergency call handling (deny / allow) */
9548 execute( TC_assignment_emerg_setup_allow() );
9549 execute( TC_assignment_emerg_setup_deny_msc() );
9550 execute( TC_assignment_emerg_setup_deny_bts() );
Philipp Maier82812002020-08-13 18:48:27 +02009551 execute( TC_emerg_premption() );
9552
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009553 /* Frequency hopping parameters handling */
9554 execute( TC_fh_params_chan_activ() );
9555 execute( TC_fh_params_imm_ass() );
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009556 execute( TC_fh_params_assignment_cmd() );
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009557 execute( TC_fh_params_handover_cmd() );
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009558 execute( TC_fh_params_si4_cbch() );
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009559
9560 if (mp_enable_lcs_tests) {
9561 execute( TC_lcs_loc_req_for_active_ms() );
9562 execute( TC_lcs_loc_req_for_active_ms_ta_req() );
9563 execute( TC_lcs_loc_req_for_idle_ms() );
9564 execute( TC_lcs_loc_req_no_subscriber() );
9565 execute( TC_lcs_loc_req_for_active_ms_le_timeout() );
9566 execute( TC_lcs_loc_req_for_active_ms_le_timeout2() );
9567 execute( TC_lcs_loc_req_for_idle_ms_no_pag_resp() );
9568 execute( TC_cm_service_during_lcs_loc_req() );
9569 execute( TC_ho_during_lcs_loc_req() );
9570 }
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009571
9572 execute( TC_no_msc() );
Neels Hofmeyr87857ec2021-04-25 16:17:47 +00009573
9574 execute( TC_refuse_chan_act_to_vamos() );
9575 execute( TC_refuse_mode_modif_to_vamos() );
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009576
9577 execute( TC_reassignment_fr() );
Harald Welte28d943e2017-11-25 15:00:50 +01009578}
9579
9580}