blob: f562df307448f988ee8b13f8f62560da55cba950 [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 Pedrol58cf6822019-05-28 18:11:33 +0200683 /* Whether to enable osmux tests. Can be dropped completely and enable
684 unconditionally once new version of osmo-bsc is released (current
685 version: 1.4.1) */
686 boolean mp_enable_osmux_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 Pedrol58cf6822019-05-28 18:11:33 +02001119 if (mp_enable_osmux_test) {
1120 f_vty_allow_osmux(allow_osmux);
1121 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001122
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001123 var my_BooleanList allow_attach := { false, false, false };
Daniel Willmannebdecc02020-08-12 15:30:17 +02001124 f_init_statsd("VirtMSC", vc_STATSD, mp_test_ip, mp_bsc_statsd_port);
1125
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001126 for (bssap_idx := 0; bssap_idx < nr_msc; bssap_idx := bssap_idx+1) {
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001127 allow_attach[bssap_idx] := true;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001128 /* Call a function of our 'parent component' RAN_Adapter_CT to start the
1129 * MSC-side BSSAP emulation */
1130 if (handler_mode) {
1131 var RanOps ranops := MSC_RanOps;
1132 ranops.use_osmux := g_osmux_enabled;
1133 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", ranops);
1134 connect(self:SCCPLITE_IPA_CTRL, g_bssap[bssap_idx].vc_RAN:CTRL_CLIENT);
1135 f_ran_adapter_start(g_bssap[bssap_idx]);
1136 } else {
1137 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", omit);
1138 connect(self:BSSAP, g_bssap[bssap_idx].vc_SCCP:SCCP_SP_PORT);
1139 f_ran_adapter_start(g_bssap[bssap_idx]);
1140 f_legacy_bssap_reset();
1141 }
Harald Welte67089ee2018-01-17 22:19:03 +01001142 }
Harald Welted5833a82018-05-27 16:52:56 +02001143
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02001144 if (mp_enable_lcs_tests) {
1145 if (handler_mode) {
1146 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", SMLC_BssapLeOps);
1147 } else {
1148 f_bssap_le_adapter_init(g_bssap_le, mp_bssap_le_cfg, "VirtSMLC", omit);
1149 connect(self:BSSAP_LE, g_bssap_le.vc_SCCP:SCCP_SP_PORT);
1150 }
1151 f_bssap_le_adapter_start(g_bssap_le);
Harald Welte47cd0e32020-08-21 12:39:11 +02001152 }
Harald Welte47cd0e32020-08-21 12:39:11 +02001153
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001154 /* start the test with exactly all enabled MSCs allowed to attach */
1155 f_vty_msc_allow_attach(BSCVTY, allow_attach);
1156
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01001157 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +01001158
Daniel Willmann191e0d92018-01-17 12:44:35 +01001159 f_init_mgcp("VirtMSC");
1160
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001161 for (var integer i := 0; i < nr_bts; i := i+1) {
1162 f_init_bts(i, handler_mode);
Harald Welte696ddb62017-12-08 14:01:43 +01001163 }
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001164}
Harald Welte696ddb62017-12-08 14:01:43 +01001165
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001166function f_init_bts(integer bts_idx := 0, boolean handler_mode := false)
1167runs on test_CT {
1168 /* wait until osmo-bts-omldummy has respawned */
1169 f_wait_oml(bts_idx, "degraded", 5.0);
1170
1171 /* start RSL connection */
1172 f_ipa_rsl_start(bts[bts_idx].rsl, mp_bsc_ip, mp_bsc_rsl_port, bts_idx, handler_mode);
1173 /* wait until BSC tells us "connected" */
1174 f_wait_oml(bts_idx, "connected", 5.0);
Harald Welte28d943e2017-11-25 15:00:50 +01001175}
1176
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001177function f_init_bts_and_check_sysinfo(integer bts_idx := 0, boolean handler_mode := false,
1178 template SystemInformationConfig expect_si)
1179runs on test_CT {
1180 var default sysinfo := activate(as_catch_RSL_sysinfo(bts_idx));
1181
1182 f_init_bts(bts_idx, handler_mode);
1183
1184 /* Give some time to (hopefully/most likely) collect all system informations from RSL startup.
1185 * We could stop as soon as all expected SI are received, but then we might miss SI that we don't expect and
1186 * that might be sent afterwards. So rather give a generous timeout and be quite sure to catch all SI.
1187 */
1188 f_sleep(5.0);
1189 log("RSL ", bts_idx, " SYSTEM INFORMATION: ", g_system_information[bts_idx]);
1190
1191 deactivate(sysinfo);
1192
1193 if (match(g_system_information[bts_idx], expect_si)) {
1194 setverdict(pass);
1195 } else {
1196 log("RSL ", bts_idx, ": EXPECTED SI: ", expect_si);
1197 log("RSL ", bts_idx, ": GOT SI: ", g_system_information[bts_idx]);
1198 setverdict(fail, "received SI does not match expectations");
1199 return;
1200 }
1201}
1202
Maxd4e56962018-10-31 19:08:25 +01001203/* expect to receive a RSL message matching a specified template on a given BTS / stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001204function 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 +01001205runs on test_CT return RSL_Message {
1206 var ASP_RSL_Unitdata rx_rsl_ud;
1207 timer T := t_secs;
1208
1209 T.start;
1210 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001211 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
Harald Welteae026692017-12-09 01:03:01 +01001212 T.stop;
1213 }
1214 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +01001215 [] T.timeout {
1216 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +02001217 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +01001218 }
Harald Welteae026692017-12-09 01:03:01 +01001219 }
1220 return rx_rsl_ud.rsl;
1221}
1222
Harald Welte21b46bd2017-12-17 19:46:32 +01001223/* helper function to transmit RSL on a given BTS/stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001224function 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 +01001225runs on test_CT {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001226 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(t_tx, sid));
Harald Welteae026692017-12-09 01:03:01 +01001227}
1228
1229
Harald Welte4003d112017-12-09 22:35:39 +01001230/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +01001231testcase TC_chan_act_noreply() runs on test_CT {
1232 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +01001233 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +01001234
Harald Welte89d42e82017-12-17 16:42:41 +01001235 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +01001236
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001237 IPA_RSL[0].send(ts_ASP_RSL_UD(ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +01001238 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001239 f_shutdown_helper();
Harald Welte28d943e2017-11-25 15:00:50 +01001240}
1241
Harald Welte4003d112017-12-09 22:35:39 +01001242/* verify if the "chreq:total" counter increments as expected */
1243testcase TC_chan_act_counter() runs on test_CT {
1244 var BSSAP_N_UNITDATA_ind ud_ind;
1245 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +01001246 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +01001247
Harald Welte89d42e82017-12-17 16:42:41 +01001248 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001249
1250 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001251 IPA_RSL[0].send(ts_ASP_RSL_UD(ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +01001252 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welte4003d112017-12-09 22:35:39 +01001253 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total", chreq_total+1);
1254
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001255 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001256}
1257
Harald Welteae026692017-12-09 01:03:01 +01001258/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
Philipp Maier9c60a622020-07-09 15:08:46 +02001259private function f_TC_chan_act_ack_noest(OCT1 ra := '23'O) runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +01001260 var RSL_Message rx_rsl;
1261
Harald Welteae026692017-12-09 01:03:01 +01001262 /* Send CHAN RQD and wait for allocation; acknowledge it */
Philipp Maier9c60a622020-07-09 15:08:46 +02001263 var RslChannelNr chan_nr := f_chreq_act_ack(ra);
Harald Welteae026692017-12-09 01:03:01 +01001264
1265 /* expect BSC to disable the channel again if there's no RLL EST IND */
1266 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1267
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001268 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001269}
1270
Philipp Maier9c60a622020-07-09 15:08:46 +02001271/* Normal variant */
1272testcase TC_chan_act_ack_noest() runs on test_CT {
Philipp Maieraf58db22020-08-12 17:24:40 +02001273 f_init(1);
Philipp Maier9c60a622020-07-09 15:08:46 +02001274 f_TC_chan_act_ack_noest();
1275}
1276
1277/* Emergency call variant */
1278testcase TC_chan_act_ack_noest_emerg() runs on test_CT {
1279 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
Philipp Maieraf58db22020-08-12 17:24:40 +02001280 f_init(1);
1281 f_vty_allow_emerg_bts(true, 0);
Philipp Maier9c60a622020-07-09 15:08:46 +02001282 f_TC_chan_act_ack_noest(ra := 'A5'O);
1283}
1284
Philipp Maier606f07d2020-08-12 17:21:58 +02001285/* Emergency call variant, but emergency calls are not allowed */
1286testcase TC_chan_rqd_emerg_deny() runs on test_CT {
1287 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
1288
1289 var RSL_Message rx_rsl;
1290 var GsmRrMessage rr;
1291
1292 f_init(1);
1293 f_vty_allow_emerg_bts(false, 0);
1294
1295 IPA_RSL[0].clear;
1296 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
1297
1298 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
1299 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
1300 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1301 setverdict(pass);
1302 } else {
1303 setverdict(fail, "immediate assignment not rejected");
1304 }
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01001305
1306 f_shutdown_helper();
Philipp Maier606f07d2020-08-12 17:21:58 +02001307}
1308
Harald Welteae026692017-12-09 01:03:01 +01001309/* Test behavior if MSC never answers to CR */
1310testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +01001311 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
1312 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +01001313 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +01001314 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +01001315
Harald Welte89d42e82017-12-17 16:42:41 +01001316 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001317
1318 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001319 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001320
1321 var octetstring l3 := '00010203040506'O
1322 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1323
1324 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
1325
1326 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +01001327 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001328 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001329 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001330}
1331
1332/* Test behavior if MSC answers with CREF to CR */
1333testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
1334 var BSSAP_N_CONNECT_ind rx_c_ind;
1335 var RSL_Message rx_rsl;
1336
Harald Welte89d42e82017-12-17 16:42:41 +01001337 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001338
1339 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001340 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001341
1342 var octetstring l3 := '00010203040506'O
1343 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1344
1345 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1346 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
1347
1348 /* expect BSC to disable the channel */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001349 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001350 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001351}
1352
Harald Welte618ef642017-12-14 14:58:20 +01001353/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
1354testcase TC_chan_act_nack() runs on test_CT {
1355 var RSL_Message rx_rsl;
1356 var integer chact_nack;
1357
Harald Welte89d42e82017-12-17 16:42:41 +01001358 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +01001359
1360 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
1361
1362 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
1363 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1364 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1365
1366 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
1367
1368 /* wait for some time to hope the NACK arrives before the CTRL GET below */
1369 f_sleep(0.5);
1370
1371 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
1372
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001373 f_shutdown_helper();
Harald Welte618ef642017-12-14 14:58:20 +01001374}
1375
Harald Welte799c97b2017-12-14 17:50:30 +01001376/* Test for channel exhaustion due to RACH overload */
1377testcase TC_chan_exhaustion() runs on test_CT {
1378 var ASP_RSL_Unitdata rsl_ud;
1379 var integer i;
1380 var integer chreq_total, chreq_nochan;
1381
Harald Welte89d42e82017-12-17 16:42:41 +01001382 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +01001383
1384 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
1385 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
1386
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +01001387 /* GSM 04.08 Table 9.9a:
1388 * RA = '33'O -> Establishment cause = 0011xxxx (MS dual rate capable and asks for "TCH/H or TCH/F").
1389 * With current setup, expect 4xSDCCH + 4xTCH/F + 1xTCH/H to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +02001390 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 +01001391 var RslChannelNr chan_nr := f_chreq_act_ack('33'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +01001392 }
1393
1394 IPA_RSL[0].clear;
1395
Harald Weltedd8cbf32018-01-28 12:07:52 +01001396 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001397 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +01001398
1399 /* now expect additional channel activations to fail */
1400 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
1401
1402 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001403 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
Harald Welte799c97b2017-12-14 17:50:30 +01001404 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
1405 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001406 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
Harald Welte799c97b2017-12-14 17:50:30 +01001407 var GsmRrMessage rr;
1408 /* match on IMM ASS REJ */
1409 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
1410 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1411 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001412 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +01001413 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
1414 chreq_nochan+1);
1415 setverdict(pass);
1416 } else {
1417 repeat;
1418 }
1419 }
1420 [] IPA_RSL[0].receive { repeat; }
1421 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001422 f_shutdown_helper();
Harald Welte799c97b2017-12-14 17:50:30 +01001423}
1424
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001425/* Test channel deactivation due to silence from MS */
1426testcase TC_chan_deact_silence() runs on test_CT {
1427 var RslChannelNr chan_nr;
1428
1429 f_init(1);
1430
1431 /* Request for a dedicated channel */
1432 chan_nr := f_chreq_act_ack('23'O);
1433
1434 /* Wait some time until the channel is released */
1435 f_sleep(2.0);
1436
1437 /* Expect CHANnel RELease */
1438 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001439 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001440 log("Received CHANnel RELease");
1441 setverdict(pass);
1442 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001443 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001444 /* See OS#3709, OsmoBSC should not send Immediate
1445 * Assignment Reject since a dedicated channel was
1446 * already allocated, and Immediate Assignment was
1447 * already sent. */
1448 setverdict(fail, "Unexpected Immediate Assignment!");
1449 }
1450 [] IPA_RSL[0].receive {
1451 setverdict(fail, "Unexpected RSL message!");
1452 }
1453 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001454 f_shutdown_helper();
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001455}
1456
Harald Weltecfe2c962017-12-15 12:09:32 +01001457/***********************************************************************
1458 * Assignment Testing
1459 ***********************************************************************/
1460
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001461/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction,
1462 * except for the inter-BSC handover, MT side) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001463testcase TC_outbound_connect(integer bssap_idx := 0) runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +01001464 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +01001465
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001466 BSSAP.send(ts_BSSAP_CONNECT_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
1467 2342, ts_BSSMAP_AssignmentReq));
Harald Weltecfe2c962017-12-15 12:09:32 +01001468 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001469 f_shutdown_helper();
Harald Weltecfe2c962017-12-15 12:09:32 +01001470}
1471
Harald Welte16a4adf2017-12-14 18:54:01 +01001472/* Test behavior if MSC answers with CREF to CR */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001473testcase TC_assignment_cic_only(integer bssap_idx := 0) runs on test_CT {
Harald Welte16a4adf2017-12-14 18:54:01 +01001474 var BSSAP_N_CONNECT_ind rx_c_ind;
1475 var RSL_Message rx_rsl;
1476 var DchanTuple dt;
1477
Harald Welte89d42e82017-12-17 16:42:41 +01001478 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +01001479
1480 dt := f_est_dchan('23'O, 23, '00000000'O);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001481 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte17b27da2018-05-25 20:33:53 +02001482 /* send assignment without AoIP IEs */
1483 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
1484 } else {
1485 /* Send assignmetn without CIC in IPA case */
1486 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
1487 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
1488 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
1489 }
Harald Welte16a4adf2017-12-14 18:54:01 +01001490 alt {
1491 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1492 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
1493 }
Harald Welte235ebf12017-12-15 14:18:16 +01001494 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +01001495 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1496 setverdict(pass);
1497 }
1498 [] BSSAP.receive { repeat; }
1499 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001500 f_shutdown_helper();
Harald Welte16a4adf2017-12-14 18:54:01 +01001501}
1502
Harald Welteed848512018-05-24 22:27:58 +02001503/* generate an assignment request for either AoIP or SCCPlite */
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001504function 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 +02001505 var PDU_BSSAP ass_cmd;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001506 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001507 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welteed848512018-05-24 22:27:58 +02001508 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001509 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001510 if (osmux_enabled) {
1511 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla, osmux_cid));
1512 } else {
1513 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
1514 }
Harald Welteed848512018-05-24 22:27:58 +02001515 } else {
1516 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001517 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
Harald Welteed848512018-05-24 22:27:58 +02001518 }
1519 return ass_cmd;
1520}
1521
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02001522function f_gen_handover_req(integer bssap_idx := 0, charstring aoip_tla := "1.2.3.4",
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001523 template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit,
1524 template (omit) TestHdlrEncrParams enc := omit) return PDU_BSSAP {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001525 var PDU_BSSAP ho_req;
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001526
1527 var BSSMAP_IE_EncryptionInformation encryptionInformation :=
1528 valueof(ts_BSSMAP_IE_EncrInfo('0000000000000000'O,'01'O));
1529 var template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm := omit;
1530 var template BSSMAP_IE_KC128 kc128 := omit;
1531 if (ispresent(enc)) {
1532 var TestHdlrEncrParams v_enc := valueof(enc);
1533 encryptionInformation := valueof(ts_BSSMAP_IE_EncrInfo(v_enc.enc_key, v_enc.enc_alg));
1534 chosenEncryptionAlgorithm := valueof(
1535 ts_BSSMAP_IE_ChosenEncryptionAlgorithm(int2oct(enum2int(
Oliver Smith598e1ed2021-07-09 10:28:40 +02001536 f_cipher_mode_bssmap_to_rsl(v_enc.enc_alg)), 1)));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001537 if (ispresent(v_enc.enc_kc128)) {
1538 kc128 := ts_BSSMAP_IE_Kc128(v_enc.enc_kc128);
1539 }
1540 }
1541
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001542 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001543 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001544 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001545 ho_req := valueof(ts_BSSMAP_HandoverRequest(omit, tla, oldToNewBSSIEs := oldToNewBSSIEs,
1546 encryptionInformation := encryptionInformation,
1547 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
1548 kC128 := kc128));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001549 } else {
1550 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02001551 ho_req := valueof(ts_BSSMAP_HandoverRequest(cic, omit, oldToNewBSSIEs := oldToNewBSSIEs,
1552 encryptionInformation := encryptionInformation,
1553 chosenEncryptionAlgorithm := chosenEncryptionAlgorithm,
1554 kC128 := kc128));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001555 }
1556 return ho_req;
1557}
1558
Harald Welteed848512018-05-24 22:27:58 +02001559/* generate an assignment complete template for either AoIP or SCCPlite */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001560function f_gen_exp_compl(boolean expect_osmux := false, integer bssap_idx := 0) return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +02001561 var template PDU_BSSAP exp_compl;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001562 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001563 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001564 if (expect_osmux) {
1565 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, osmux_cid);
1566 } else {
1567 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, omit);
1568 }
Harald Welteed848512018-05-24 22:27:58 +02001569 } else {
1570 /* CIC is optional "*" as the MSC allocated it */
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001571 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
Harald Welteed848512018-05-24 22:27:58 +02001572 }
1573 return exp_compl;
1574}
1575
Harald Welte235ebf12017-12-15 14:18:16 +01001576/* Run everything required up to sending a caller-specified assignment command and expect response */
1577function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
1578runs on test_CT {
1579 var BSSAP_N_CONNECT_ind rx_c_ind;
1580 var RSL_Message rx_rsl;
1581 var DchanTuple dt;
1582
Harald Welte89d42e82017-12-17 16:42:41 +01001583 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +01001584
1585 dt := f_est_dchan('23'O, 23, '00000000'O);
1586 /* send assignment without AoIP IEs */
1587 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
1588 alt {
1589 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1590 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
1591 setverdict(pass);
1592 } else {
1593 setverdict(fail, fail_text);
1594 }
1595 }
1596 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1597 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
1598 setverdict(pass);
1599 } else {
1600 setverdict(fail, fail_text);
1601 }
1602 }
1603 [] BSSAP.receive { repeat; }
1604 }
1605}
1606testcase TC_assignment_csd() runs on test_CT {
1607 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001608 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001609 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1610 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
1611 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001612 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001613}
1614
1615testcase TC_assignment_ctm() runs on test_CT {
1616 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001617 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001618 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
1619 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
1620 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001621 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001622}
1623
Harald Welte4003d112017-12-09 22:35:39 +01001624type record DchanTuple {
1625 integer sccp_conn_id,
1626 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +01001627}
1628
Harald Welted6939652017-12-13 21:02:46 +01001629/* Send CHAN RQD and wait for allocation; acknowledge it */
1630private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
1631runs on test_CT return RslChannelNr {
1632 var RSL_Message rx_rsl;
1633 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1634 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1635 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1636 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
Daniel Willmannf4ac4ce2018-08-02 14:06:30 +02001637 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Harald Welted6939652017-12-13 21:02:46 +01001638 return chan_nr;
1639}
1640
Harald Welte4003d112017-12-09 22:35:39 +01001641/* helper function to establish a dedicated channel via BTS and MSC */
1642function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1643runs on test_CT return DchanTuple {
1644 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +01001645 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001646
Harald Welte4003d112017-12-09 22:35:39 +01001647 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001648 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +01001649
1650 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1651
1652 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1653 dt.sccp_conn_id := rx_c_ind.connectionId;
1654 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1655
1656 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001657}
1658
Harald Welte641fcbe2018-06-14 10:58:35 +02001659/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
1660private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
1661 var RSL_Message rx_rsl;
1662 /* expect BSC to disable the channel */
1663 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1664 /* respond with CHAN REL ACK */
1665 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1666
1667 /* expect Clear Complete from BSC */
1668 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1669
1670 /* MSC disconnects as instructed. */
1671 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1672}
1673
Harald Welte4003d112017-12-09 22:35:39 +01001674/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
1675testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001676 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001677 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +01001678
Harald Welte89d42e82017-12-17 16:42:41 +01001679 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +01001680
Harald Welte4003d112017-12-09 22:35:39 +01001681 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1682
1683 /* simulate RLL REL IND */
1684 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
1685
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001686 /* expect Clear Request on MSC side */
1687 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1688
1689 /* Instruct BSC to clear channel */
1690 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1691 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1692
Harald Welte4003d112017-12-09 22:35:39 +01001693 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001694 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001695
1696 /* wait for SCCP emulation to do its job */
1697 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +01001698
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001699 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001700}
1701
1702/* Test behavior of channel release after CONN FAIL IND from BTS */
1703testcase TC_chan_rel_conn_fail() runs on test_CT {
1704 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001705 var DchanTuple dt;
1706
Harald Welte89d42e82017-12-17 16:42:41 +01001707 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001708
1709 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1710
1711 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +01001712 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 +01001713 /* TODO: different cause values? */
1714
Harald Welte4003d112017-12-09 22:35:39 +01001715 /* expect Clear Request from BSC */
1716 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1717
1718 /* Instruct BSC to clear channel */
1719 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1720 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1721
Harald Welte6ff76ea2018-01-28 13:08:01 +01001722 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001723 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +01001724
1725 /* wait for SCCP emulation to do its job */
1726 f_sleep(1.0);
1727
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001728 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001729}
1730
Harald Welte99f3ca02018-06-14 13:40:29 +02001731/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
1732/* See also https://www.osmocom.org/issues/3182 */
1733testcase TC_early_conn_fail() runs on test_CT {
1734 var RSL_Message rx_rsl;
1735 var DchanTuple dt;
1736
1737 f_init(1);
1738
1739 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
Harald Weltec46ea3c2020-10-10 18:46:12 +02001740 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_ra_cs(), 23);
Harald Welte99f3ca02018-06-14 13:40:29 +02001741
1742 /* BTS->BSC: simulate CONN FAIL IND */
1743 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1744
1745 /* BTS->BSC: Expect RF channel release from BSC on Abis */
1746 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1747
1748 /* BTS<-BSC: respond with CHAN REL ACK */
1749 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1750
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001751 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001752}
1753
1754/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
1755/* See also https://www.osmocom.org/issues/3182 */
1756testcase TC_late_conn_fail() runs on test_CT {
1757 var RSL_Message rx_rsl;
1758 var DchanTuple dt;
1759
1760 f_init(1);
1761
1762 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1763
1764 /* BSC<-MSC: Instruct BSC to clear connection */
1765 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
1766
1767 /* BTS->BSC: expect BSC to deactivate SACCH */
1768 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
1769
1770 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
1771 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1772
1773 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
1774 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1775 /* BTS->BSC: respond with CHAN REL ACK */
1776 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1777
1778 /* BSC->MSC: expect Clear Complete from BSC */
1779 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1780
1781 /* BSC<-MSC: MSC disconnects as requested. */
1782 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1783
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001784 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001785}
1786
Neels Hofmeyrf44ccd12018-11-05 19:15:23 +01001787function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr,
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001788 boolean expect_deact_sacch := true,
1789 boolean expect_rr_chan_rel := true,
1790 boolean expect_rll_rel_req := true,
Harald Welte99787102019-02-04 10:41:36 +01001791 boolean handle_rll_rel := true,
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02001792 template CellSelIndValue expect_cells := omit,
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001793 template RR_Cause expect_rr_cause := ?
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001794 ) runs on test_CT {
Harald Welte91d54a52018-01-28 15:35:07 +01001795
1796 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001797 var boolean got_deact_sacch := false;
1798 var boolean got_rr_chan_rel := false;
1799 var boolean got_rll_rel_req := false;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02001800 var ASP_RSL_Unitdata ud;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001801 var RSL_IE_Body l3_ie;
1802 var PDU_ML3_NW_MS l3;
1803 var RR_Cause got_cause;
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001804 log("f_expect_chan_rel() expecting: expect_deact_sacch=", expect_deact_sacch, " expect_rr_chan_rel=", expect_rr_chan_rel,
1805 " expect_rll_rel_req=", expect_rll_rel_req);
Harald Welte91d54a52018-01-28 15:35:07 +01001806 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001807 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001808 got_deact_sacch := true;
Harald Welte91d54a52018-01-28 15:35:07 +01001809 repeat;
1810 }
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02001811 [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 +01001812 got_rr_chan_rel := true;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02001813
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001814 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
1815 setverdict(fail, "cannot find L3");
1816 mtc.stop;
1817 }
1818 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
1819
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02001820 if (not istemplatekind(expect_cells, "omit")) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02001821 var CellSelIndValue cells := dec_CellSelIndValue(
1822 l3.msgs.rrm.channelRelease.cellSelectionIndicator.cellSelectionIndicatorValue);
1823
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02001824 log("GOT RR CHANNEL RELEASE WITH CELLS: ", cells);
1825 if (match(cells, expect_cells)) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02001826 setverdict(pass);
1827 } else {
Pau Espin Pedrol36bd4fa2021-04-15 13:00:24 +02001828 log("EXPECTED CELLS: ", expect_cells);
1829 setverdict(fail, "Received cells list on RR Channel Release does not match expectations");
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02001830 }
1831 }
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001832
1833 if (not istemplatekind(expect_rr_cause, "omit")) {
1834 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
1835 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
1836 if (match(got_cause, expect_rr_cause)) {
1837 setverdict(pass);
1838 } else {
1839 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
1840 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
1841 }
1842 }
Harald Welte99787102019-02-04 10:41:36 +01001843 repeat;
1844 }
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02001845 [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 +01001846 got_rr_chan_rel := true;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001847
1848 if (not istemplatekind(expect_rr_cause, "omit")) {
1849 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
1850 setverdict(fail, "cannot find L3");
1851 mtc.stop;
1852 }
1853 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
1854
1855 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
1856 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
1857 if (match(got_cause, expect_rr_cause)) {
1858 setverdict(pass);
1859 } else {
1860 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
1861 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
1862 }
1863 }
Neels Hofmeyr211169d2018-11-07 00:37:29 +01001864 repeat;
1865 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001866 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001867 got_rll_rel_req := true;
Harald Welte91d54a52018-01-28 15:35:07 +01001868 /* FIXME: Why are we getting this for LinkID SACCH? */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001869 if (handle_rll_rel) {
1870 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
1871 }
Harald Welte91d54a52018-01-28 15:35:07 +01001872 repeat;
1873 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001874 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Harald Welte91d54a52018-01-28 15:35:07 +01001875 /* respond with CHAN REL ACK */
1876 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
1877 }
1878 /* ignore any user data */
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001879 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeR(?))) {
Harald Welte91d54a52018-01-28 15:35:07 +01001880 repeat;
1881 }
1882 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001883
1884 log("f_expect_chan_rel() summary: got_deact_sacch=", got_deact_sacch, " got_rr_chan_rel=", got_rr_chan_rel,
1885 " got_rll_rel_req=", got_rll_rel_req);
1886
1887 if (expect_deact_sacch != got_deact_sacch) {
1888 setverdict(fail, "f_expect_chan_rel(): expect_deact_sacch=", expect_deact_sacch, " got_deact_sacch=", got_deact_sacch);
1889 }
1890 if (expect_rr_chan_rel != got_rr_chan_rel) {
1891 setverdict(fail, "f_expect_chan_rel(): expect_rr_chan_rel=", expect_rr_chan_rel, " got_rr_chan_rel=", got_rr_chan_rel);
1892 }
1893 if (expect_rll_rel_req != got_rll_rel_req) {
1894 setverdict(fail, "f_expect_chan_rel(): expect_rll_rel_req=", expect_rll_rel_req, " got_rll_rel_req=", got_rll_rel_req);
1895 }
Harald Welte91d54a52018-01-28 15:35:07 +01001896}
1897
Harald Welte4003d112017-12-09 22:35:39 +01001898/* Test behavior of channel release after hard Clear Command from MSC */
1899testcase TC_chan_rel_hard_clear() runs on test_CT {
1900 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001901 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +01001902
Harald Welte89d42e82017-12-17 16:42:41 +01001903 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001904
1905 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1906
1907 /* Instruct BSC to clear channel */
1908 var BssmapCause cause := 0;
1909 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1910
1911 /* expect Clear Complete from BSC on A */
1912 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
1913 /* release the SCCP connection */
1914 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1915 }
1916
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001917 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001918 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001919}
1920
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02001921function f_TC_chan_rel_last_eutran_plmn_hard_clear(boolean tx_csfb_ind) runs on test_CT {
1922 var BSSAP_N_DATA_ind rx_di;
1923 var DchanTuple dt;
1924
1925 f_init(1);
1926
1927 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1928 /* Send CommonID with some random PLMN (BSC doesn't take it into account
1929 /* yet when generating the EUTRAN neigh list in RR CHannel Release) */
1930 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
1931
1932 /* Instruct BSC to clear channel */
1933 var BssmapCause cause := 0;
1934 if (tx_csfb_ind) {
1935 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
1936 } else {
1937 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1938 }
1939
1940 /* expect Clear Complete from BSC on A */
1941 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
1942 /* release the SCCP connection */
1943 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1944 }
1945
1946 /* 1 neighbor is added by default in osmo-bts.cfg and
1947 SystemInformationConfig_default, use that: */
1948 var template CellSelIndValue exp_cells := f_tr_rr_chan_rel_earfcns(1);
1949
1950 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, expect_cells := exp_cells);
1951 f_shutdown_helper();
1952}
1953
1954/* Test behavior of RR Channel rRelease after Clear Command without CSFB indicator
1955 from MSC, previously receiving any CommonID containing the "Last Used E-UTRAN
1956 PLMN Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
1957 EUTRAN neighbor list sent later on by BSC in RR Channel, so receiving CSFB
1958 Indicator or not shouldn't matter at all. */
1959testcase TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() runs on test_CT {
1960 f_TC_chan_rel_last_eutran_plmn_hard_clear(false);
1961}
1962
1963/* Test behavior of RR Channel rRelease after Clear Command with CSFB indicator from
1964 MSC, previously receiving any CommonID containing the "Last Used E-UTRAN PLMN
1965 Id". According to spec (3GPP TS 48.008 sec 3.1.30) that's the bit requesting
1966 EUTRAN neighbor list sent later on by BSC in RR Channel. */
1967testcase TC_chan_rel_last_eutran_plmn_hard_clear_csfb() runs on test_CT {
1968 f_TC_chan_rel_last_eutran_plmn_hard_clear(true);
1969}
1970
1971/* Test behavior of RR Channel Release after Clear Command with CSFB indicator from
1972 MSC, without receiving any CommonID containing the "Last Used E-UTRAN PLMN
1973 Id". According to spec (TS 48.008 version 16.0.0 Release 16 "3.2.1.21") the
1974 CSFB Indicator should not be used anymore, and hence, there should be no
1975 EUTRAN neighbor list sent by BSC in RR Channel release since no CommonId with
1976 Last Used E-UTRAN PLMN Id" IE was sent for this conn. */
Harald Welte99787102019-02-04 10:41:36 +01001977testcase TC_chan_rel_hard_clear_csfb() runs on test_CT {
1978 var BSSAP_N_DATA_ind rx_di;
1979 var DchanTuple dt;
1980
1981 f_init(1);
1982
1983 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1984
1985 /* Instruct BSC to clear channel */
1986 var BssmapCause cause := 0;
1987 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
1988
1989 /* expect Clear Complete from BSC on A */
1990 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
1991 /* release the SCCP connection */
1992 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1993 }
1994
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02001995 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001996 f_shutdown_helper();
Harald Welte99787102019-02-04 10:41:36 +01001997}
1998
Harald Welted8c36cd2017-12-09 23:05:31 +01001999/* Test behavior of channel release after hard RLSD from MSC */
2000testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +01002001 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +01002002
Harald Welte89d42e82017-12-17 16:42:41 +01002003 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +01002004
2005 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2006
2007 /* release the SCCP connection */
2008 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2009
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002010 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002011 f_shutdown_helper();
Harald Welted8c36cd2017-12-09 23:05:31 +01002012}
2013
Harald Welte550daf92018-06-11 19:22:13 +02002014/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
2015testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
2016 var DchanTuple dt;
2017
2018 f_init(1);
2019
2020 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2021
2022 /* release the SCCP connection */
2023 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2024
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002025 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002026 f_shutdown_helper();
Harald Welte550daf92018-06-11 19:22:13 +02002027}
2028
Harald Welte85804d42017-12-10 14:11:58 +01002029/* Test behavior of channel release after BSSMAP RESET from MSC */
2030testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +01002031 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +01002032
Harald Welte89d42e82017-12-17 16:42:41 +01002033 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +01002034
2035 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2036
2037 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
2038 IPA_RSL[0].clear;
2039
2040 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002041 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 +01002042 interleave {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002043 [] 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 +01002044 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
2045 }
2046
Neels Hofmeyra5302c82018-11-04 23:09:58 +01002047 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002048 f_shutdown_helper();
Harald Welte85804d42017-12-10 14:11:58 +01002049}
2050
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002051/* Verify T(iar) triggers and releases the channel */
2052testcase TC_chan_rel_sccp_tiar_timeout() runs on test_CT {
2053 var DchanTuple dt;
2054
2055 /* Set T(iar) in BSC low enough that it will trigger before other side
2056 has time to keep alive with a T(ias). Keep recommended ratio of
2057 T(iar) >= T(ias)*2 */
2058 g_bsc_sccp_timer_ias := 2;
2059 g_bsc_sccp_timer_iar := 5;
2060
2061 f_init(1);
2062
2063 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2064 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002065 f_shutdown_helper();
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01002066}
2067
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002068private function f_tc_chan_rel_rr_cause(myBSSMAP_Cause clear_cmd_cause, template RR_Cause expect_rr_cause)
2069runs on test_CT
2070{
2071 var DchanTuple dt;
2072
2073 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2074 var BssmapCause cause := 0;
2075 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(enum2int(clear_cmd_cause))));
2076 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2077 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2078 }
2079
2080 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 +02002081}
2082
2083/* Test that Clear Command cause codes affect the RR Channel Release cause code */
2084testcase TC_chan_rel_rr_cause() runs on test_CT {
2085 f_init(1);
2086
2087 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_CALL_CONTROL, GSM48_RR_CAUSE_NORMAL);
2088 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_HANDOVER_SUCCESSFUL, GSM48_RR_CAUSE_NORMAL);
2089 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_PREEMPTION, GSM48_RR_CAUSE_PREMPTIVE_REL);
2090 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE, GSM48_RR_CAUSE_PROT_ERROR_UNSPC);
2091 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
2092 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_EQUIPMENT_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
Vadim Yanitskiye18aebb2021-01-03 13:10:43 +01002093
2094 f_shutdown_helper();
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02002095}
2096
Harald Welte5cd20ed2017-12-13 21:03:20 +01002097/* Test behavior if RSL EST IND for non-active channel */
2098testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
2099 timer T := 2.0;
2100
Harald Welte89d42e82017-12-17 16:42:41 +01002101 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002102
2103 var octetstring l3 := '00010203040506'O;
2104 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
2105 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
2106
2107 T.start;
2108 alt {
2109 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2110 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
2111 }
2112 [] BSSAP.receive {}
2113 [] IPA_RSL[0].receive {}
2114 [] T.timeout {}
2115 }
2116
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002117 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002118}
2119
2120/* Test behavior if RSL EST IND for invalid SAPI */
2121testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
2122 var RslChannelNr chan_nr;
2123
Harald Welte89d42e82017-12-17 16:42:41 +01002124 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002125
2126 chan_nr := f_chreq_act_ack()
2127
2128 var octetstring l3 := '00010203040506'O;
2129 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
2130
2131 timer T := 2.0;
2132 T.start;
2133 alt {
2134 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2135 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
2136 }
2137 [] BSSAP.receive { repeat; }
2138 [] IPA_RSL[0].receive { repeat; }
2139 [] T.timeout {}
2140 }
2141
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002142 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002143}
2144
2145/* Test behavior if RSL EST IND for invalid SAPI */
2146testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
2147 timer T := 2.0;
2148
Harald Welte89d42e82017-12-17 16:42:41 +01002149 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002150
2151 var RslChannelNr chan_nr := f_chreq_act_ack();
2152
2153 var octetstring l3 := '00010203040506'O;
2154 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
2155
2156 T.start;
2157 alt {
2158 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2159 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
2160 }
2161 [] BSSAP.receive { repeat; }
2162 [] IPA_RSL[0].receive { repeat; }
2163 [] T.timeout {}
2164 }
2165
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002166 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002167}
2168
2169/* Test behavior if RSL EST IND for invalid SACCH */
2170testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
2171 timer T := 2.0;
2172
Harald Welte89d42e82017-12-17 16:42:41 +01002173 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002174
2175 var RslChannelNr chan_nr := f_chreq_act_ack();
2176
2177 var octetstring l3 := '00010203040506'O;
2178 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
2179
2180 T.start;
2181 alt {
2182 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2183 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
2184 }
2185 [] BSSAP.receive { repeat; }
2186 [] IPA_RSL[0].receive { repeat; }
2187 [] T.timeout {}
2188 }
2189
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002190 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002191}
2192
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002193/* Verify DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
2194private function f_TC_tch_dlci_link_id_sapi(charstring id) runs on MSC_ConnHdlr {
2195 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
2196 var PDU_BSSAP ass_cmd := f_gen_ass_req();
2197
2198 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
2199 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
2200
2201 f_establish_fully(ass_cmd, exp_compl);
2202
2203 /* SAPI0 has already been established by f_establish_fully(), establish SAPI3 */
2204 RSL.send(ts_RSL_EST_IND(g_chan_nr, ts_RslLinkID_SACCH(3), '0904'O));
2205 /* Expect BSSAP/DTAP on SAPI3 (DLCI IE) */
2206 BSSAP.receive(PDU_BSSAP:{
2207 discriminator := '1'B,
2208 spare := '0000000'B,
2209 dlci := 'C3'O,
2210 lengthIndicator := ?,
2211 pdu := { dtap := '0904'O }
2212 });
2213
2214 /* Send messages on DCCH/SAPI0 and ACCH/SAPI3 */
2215 for (var integer i := 0; i < 32; i := i + 1) {
2216 var octetstring l3 := '09'O & f_rnd_octstring(14);
2217 var template (value) RslLinkId link_id;
2218 var template (value) OCT1 dlci;
2219
2220 if (i mod 2 == 0) {
2221 /* SAPI0 on FACCH or SDCCH */
2222 link_id := ts_RslLinkID_DCCH(0);
2223 dlci := '80'O;
2224 } else {
2225 /* SAPI3 on SACCH */
2226 link_id := ts_RslLinkID_SACCH(3);
2227 dlci := 'C3'O;
2228 }
2229
2230 /* Send MO message: RSL -> BSSAP */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002231 f_mo_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002232 /* Send MT message: BSSAP -> RSL */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00002233 f_mt_l3_transceive(RSL, link_id, dlci, l3);
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07002234 }
2235}
2236testcase TC_tch_dlci_link_id_sapi() runs on test_CT {
2237 var TestHdlrParams pars := f_gen_test_hdlr_pars();
2238 var MSC_ConnHdlr vc_conn;
2239
2240 f_init(1, true);
2241 f_sleep(1.0);
2242
2243 vc_conn := f_start_handler(refers(f_TC_tch_dlci_link_id_sapi), pars);
2244 vc_conn.done;
2245
2246 f_shutdown_helper();
2247}
2248
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002249private function f_exp_sapi_n_reject(template (present) GsmSapi sapi := ?,
2250 template myBSSMAP_Cause cause := ?,
2251 float T_val := 2.0)
2252runs on test_CT {
2253 var BSSAP_N_DATA_ind rx_di;
2254 timer T;
2255
2256 var template BSSMAP_IE_Cause tr_cause := tr_BSSMAP_IE_Cause(cause);
2257 var template PDU_BSSAP tr_pdu := tr_BSSMAP_SAPInReject(sapi);
2258
2259 T.start(T_val);
2260 alt {
2261 [] BSSAP.receive(tr_BSSAP_DATA_ind(?, tr_pdu)) -> value rx_di {
2262 var BSSMAP_IE_Cause rx_cause := rx_di.userData.pdu.bssmap.sAPInReject.cause;
2263 if (not match(rx_cause, tr_cause)) {
2264 setverdict(fail, "Rx unexpected Cause IE: ",
2265 rx_cause, " vs expected ", tr_cause);
2266 }
2267 setverdict(pass);
2268 }
2269 [] BSSAP.receive(BSSAP_N_DATA_ind:?) -> value rx_di {
2270 setverdict(fail, "Rx unexpected BSSAP PDU: ", rx_di);
2271 }
2272 [] T.timeout {
2273 setverdict(fail, "Timeout waiting for BSSMAP SAPI N Reject");
2274 }
2275 }
2276}
2277
2278/* Check if we get SAPI N Reject on receipt of unexpected RLL RELease INDication */
2279testcase TC_rll_rel_ind_sapi_n_reject() runs on test_CT {
2280 var octetstring rnd_data := f_rnd_octstring(16);
2281 var RSL_Message rx_rsl;
2282 var DchanTuple dt;
2283
2284 f_init(1);
2285
2286 /* MS establishes a SAPI=0 link on DCCH */
2287 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2288
2289 /* MSC sends some data on (not yet established) SAPI=3 link */
2290 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2291 /* BSC attempts to establish a SAPI=3 link on DCCH */
2292 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2293
2294 /* MS sends unexpected RELease INDication on SAPI=3 */
2295 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3)));
2296 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2297 f_exp_sapi_n_reject(3, GSM0808_CAUSE_MS_NOT_EQUIPPED);
2298
2299 /* Clean up the connection */
2300 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2301 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2302
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002303 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002304}
2305
2306/* Check if we get SAPI N Reject on receipt of unexpected RLL ERROR INDication */
2307testcase TC_rll_err_ind_sapi_n_reject() runs on test_CT {
2308 var octetstring rnd_data := f_rnd_octstring(16);
2309 var RSL_Message rx_rsl;
2310 var DchanTuple dt;
2311
2312 f_init(1);
2313
2314 /* MS establishes a SAPI=0 link on DCCH */
2315 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2316
2317 /* MSC sends some data on (not yet established) SAPI=3 link */
2318 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2319 /* BSC attempts to establish a SAPI=3 link on DCCH */
2320 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2321
2322 /* BTS sends unexpected ERROR INDication on SAPI=3 */
2323 f_ipa_tx(0, ts_RSL_ERROR_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3), ''O));
2324 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2325 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED);
2326
2327 /* Clean up the connection */
2328 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2329 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2330
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002331 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002332}
2333
2334/* Check if we get SAPI N Reject due to a SAPI=3 link establishment timeout */
2335testcase TC_rll_timeout_sapi_n_reject() runs on test_CT {
2336 var octetstring rnd_data := f_rnd_octstring(16);
2337 var RSL_Message rx_rsl;
2338 var DchanTuple dt;
2339
2340 f_init(1);
2341
2342 /* MS establishes a SAPI=0 link on DCCH */
2343 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2344
2345 /* MSC sends some data on (not yet established) SAPI=3 link */
2346 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2347 /* BSC attempts to establish a SAPI=3 link on DCCH */
2348 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2349
2350 /* MS does not respond, so the link establishment timeout triggers SAPI N Reject */
2351 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED, T_val := 8.0);
2352
2353 /* Clean up the connection */
2354 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2355 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2356
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002357 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002358}
2359
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002360testcase TC_si_default() runs on test_CT {
2361 f_init(0);
2362 f_init_bts_and_check_sysinfo(0, expect_si := SystemInformationConfig_default);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002363 f_shutdown_helper();
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002364}
Harald Welte4003d112017-12-09 22:35:39 +01002365
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002366/* We're testing SI2quater with lists of EARFCNs. Instead of just incrementing EARFCNs, also pick some from the edges of
2367 * the entire value range. This function provides the same EARFCN numbers for the same earfcn_index */
2368private function f_test_si2quater_earfcn_by_idx(integer earfcn_index) return uint16_t
2369{
2370 select (earfcn_index) {
2371 case (0) {
2372 /* E-ARFCN 111 is already added in the osmo-bsc.cfg */
2373 return 111;
2374 }
2375 case (1) {
2376 return 1;
2377 }
2378 case (2) {
2379 return 0;
2380 }
2381 case (3) {
2382 return 65535;
2383 }
2384 case else {
2385 return 23 * (earfcn_index - 3);
2386 }
2387 }
2388}
2389
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002390function f_test_si2quater(integer total_earfcns, template SystemInformationConfig expect_si,
2391 template CellSelIndValue expect_cells := omit) runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002392
2393 f_init(0);
2394
2395 /* E-ARFCN 111 is already added in the osmo-bsc.cfg, so only add more arfcns if total_earfcns > 1 */
2396 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002397 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2398 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002399 }
2400
2401 f_init_bts_and_check_sysinfo(0, expect_si := expect_si);
2402
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002403 if (not istemplatekind(expect_cells, "omit")) {
2404 /* Also check that RR Channel Release contains these EARFCNs.
2405 * (copied code from TC_chan_rel_hard_clear_csfb) */
2406 var BSSAP_N_DATA_ind rx_di;
2407 var DchanTuple dt;
2408
2409 dt := f_est_dchan('23'O, 23, '00010203040506'O);
Pau Espin Pedrold0046312021-04-19 16:35:58 +02002410 /* Send CommonID with some random PLMN (BSC doesn't take it into account
2411 * yet when generating the EUTRAN neigh list in RR CHannel Release) */
2412 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_CommonId('001019876543210'H, '323454'O)));
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002413
2414 /* Instruct BSC to clear channel */
2415 var BssmapCause cause := 0;
2416 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2417
2418 /* expect Clear Complete from BSC on A */
2419 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2420 /* release the SCCP connection */
2421 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2422 }
2423
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02002424 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 +02002425 }
2426
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002427 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002428 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 +02002429 }
2430}
2431
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002432private function f_tr_si2quater_earfcns(integer count) return template SI2quaterRestOctetsList
2433{
2434 var template SI2quaterRestOctetsList si2quater := {};
2435 var integer si2quater_count := (count + 2) / 3;
2436
2437 for (var integer i := 0; i < count; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002438 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002439 var integer index := i / 3;
2440 var integer earfcn_index := i mod 3;
2441 if (index >= lengthof(si2quater)) {
2442 si2quater[index] := tr_SI2quaterRestOctets_EUTRAN(index := index, count := si2quater_count - 1);
2443 }
2444 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);
2445 }
2446
2447 return si2quater;
2448}
2449
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002450private function f_tr_rr_chan_rel_earfcns(integer count) return template CellSelIndValue
2451{
2452 var template CellSelIndValue_EUTRAN_Descrs cells := {};
2453
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002454 /* the lte neighbors must match the config & vty to pass this test */
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002455 for (var integer i := 0; i < count; i := i + 1) {
2456 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002457 cells[i] := tr_CellSelIndValue_EUTRAN_Descr(earfcn, '1'B, 3);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002458 }
2459
2460 return tr_CellSelIndValue_EUTRAN(cells);
2461}
2462
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002463private function f_tc_si2quater_n_earfcns(integer n) runs on test_CT
2464{
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002465 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrol8ab62e42020-12-18 16:19:11 +01002466 sic.si2quater := f_tr_si2quater_earfcns(n);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002467 var template CellSelIndValue cells := f_tr_rr_chan_rel_earfcns(n);
2468 f_test_si2quater(n, sic, cells);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002469}
2470
2471testcase TC_si2quater_2_earfcns() runs on test_CT {
2472 f_tc_si2quater_n_earfcns(2);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002473 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002474}
2475
2476testcase TC_si2quater_3_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002477 f_tc_si2quater_n_earfcns(3);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002478 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002479}
2480
2481testcase TC_si2quater_4_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002482 f_tc_si2quater_n_earfcns(4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002483 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002484}
2485
2486testcase TC_si2quater_5_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002487 f_tc_si2quater_n_earfcns(5);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002488 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002489}
2490
2491testcase TC_si2quater_6_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002492 f_tc_si2quater_n_earfcns(6);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002493 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002494}
2495
2496testcase TC_si2quater_12_earfcns() runs on test_CT {
2497 f_tc_si2quater_n_earfcns(12);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002498 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002499}
2500
2501testcase TC_si2quater_23_earfcns() runs on test_CT {
2502 f_tc_si2quater_n_earfcns(23);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002503 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002504}
2505
2506testcase TC_si2quater_32_earfcns() runs on test_CT {
2507 f_tc_si2quater_n_earfcns(32);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002508 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002509}
2510
2511testcase TC_si2quater_33_earfcns() runs on test_CT {
2512 f_tc_si2quater_n_earfcns(33);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002513 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002514}
2515
2516testcase TC_si2quater_42_earfcns() runs on test_CT {
2517 f_tc_si2quater_n_earfcns(42);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002518 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002519}
2520
2521testcase TC_si2quater_48_earfcns() runs on test_CT {
2522 f_tc_si2quater_n_earfcns(48);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002523 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002524}
2525
2526/* verify the VTY error response when adding too many EARFCNs, and showing that osmo-bsc still sends 16 SI2quater with
2527 * 48 EARFCNs. */
2528testcase TC_si2quater_49_earfcns() runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002529 var template SystemInformationConfig sic := SystemInformationConfig_default;
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002530 sic.si2quater := f_tr_si2quater_earfcns(48); /* 48, not 49! */
2531 f_init(0);
2532
2533 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002534 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2535 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002536 }
2537
2538 /* The 49th EARFCN no longer fits, expect VTY error */
2539 f_vty_enter_cfg_bts(BSCVTY, 0);
2540 var charstring vty_error;
2541 vty_error := f_vty_transceive_ret(BSCVTY,
2542 "si2quater neighbor-list add earfcn 70 thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3")
2543 f_vty_transceive(BSCVTY, "end");
2544
2545 if (f_strstr(vty_error, "Unable to add ARFCN 70") >= 0) {
2546 log("Got expected VTY error: ", vty_error);
2547 setverdict(pass);
2548 } else {
2549 setverdict(fail, "Expected the 49th EUTRAN ARFCN to be rejected by vty config, got: ", vty_error);
2550 }
2551
2552 f_init_bts_and_check_sysinfo(0, expect_si := sic);
2553
2554 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002555 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 +02002556 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002557 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002558}
2559
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002560private function f_acc09_count_allowed(AccessControlClass acc) return uint8_t
2561{
2562 var uint8_t count := 0;
2563 for (var integer i := 5; i < 16; i := i + 1) {
2564 if (acc[i] == '0'B) { /* the list marks barred, we count allowed */
2565 count := count + 1;
2566 }
2567 }
2568 return count;
2569}
2570
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002571private function f_recv_next_si1(integer rsl_idx := 0) runs on test_CT return SystemInformationType1
2572{
2573 var ASP_RSL_Unitdata rx_rsl_ud;
2574 var SystemInformationType1 last_si1;
2575
2576 timer T := 30.0;
2577 T.start;
2578 alt {
2579 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD((tr_RSL_NO_BCCH_INFO,
2580 tr_RSL_BCCH_INFO,
2581 tr_RSL_NO_SACCH_FILL,
2582 tr_RSL_SACCH_FILL))
2583 ) -> value rx_rsl_ud {
2584 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
2585 if (g_system_information[rsl_idx].si1 == omit) {
2586 repeat;
2587 }
2588 last_si1 := g_system_information[rsl_idx].si1;
2589 g_system_information[rsl_idx].si1 := omit;
2590 T.stop;
2591 }
Vadim Yanitskiy79ebd5e2021-01-04 00:12:55 +01002592 [] IPA_RSL[rsl_idx].receive { repeat; }
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002593 [] T.timeout { setverdict(fail, "Timeout receiving next SI1"); }
2594 }
2595 return last_si1;
2596}
2597
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002598/* verify ACC rotate feature */
2599testcase TC_si_acc_rotate() runs on test_CT {
2600 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002601 var SystemInformationType1 last_si1;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002602 var AccessControlClass acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002603 var uint8_t count;
2604 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2605
2606 f_init(0, guard_timeout := 60.0);
2607
2608 f_bts_0_cfg(BSCVTY, {"rach access-control-class 5 barred",
2609 "access-control-class-rotate 3",
2610 "access-control-class-rotate-quantum 1"});
2611
2612 /* Init and get first sysinfo */
2613 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2614
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002615 for (var integer i:= 0; i < 20; i := i + 1) {
2616 last_si1 := f_recv_next_si1(0);
2617 acc := last_si1.rach_control.acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002618 count := f_acc09_count_allowed(acc);
2619 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2620
2621 if (count != 3) {
2622 log("RSL: EXPECTED SI ACC len=3");
2623 setverdict(fail, "received SI does not match expectations");
2624 break;
2625 }
2626
2627 for (var integer j := 0; j < 10; j := j + 1) {
2628 if (acc[16 - 1 - j] == '0'B) { /* the list marks barred, we count allowed */
2629 times_allowed[j] := times_allowed[j] + 1;
2630 }
2631 }
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002632 }
2633
2634 for (var integer j := 0; j < 10; j := j + 1) {
2635 log("ACC", j, " allowed ", times_allowed[j], " times" );
2636 if (j != 5 and times_allowed[j] < 3) {
2637 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " < 1 times");
2638 } else if (j == 5 and times_allowed[j] > 0) {
2639 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " > 0 times");
2640 }
2641 }
2642
2643 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2644 "rach access-control-class 5 allowed"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002645 f_shutdown_helper();
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002646}
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002647
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002648/* verify ACC startup ramp+rotate feature */
2649testcase TC_si_acc_ramp_rotate() runs on test_CT {
2650 var template SystemInformationConfig sic := SystemInformationConfig_default;
2651 var SystemInformationType1 last_si1;
2652 var AccessControlClass acc;
2653 var ASP_RSL_Unitdata rx_rsl_ud;
2654 var uint8_t count;
2655 var uint8_t prev_count;
2656 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2657
2658 f_init(0, guard_timeout := 80.0);
2659
2660 f_bts_0_cfg(BSCVTY, {"rach access-control-class 4 barred",
2661 "access-control-class-rotate 0",
2662 "access-control-class-rotate-quantum 1",
2663 "access-control-class-ramping",
2664 "access-control-class-ramping-step-interval 5",
2665 "access-control-class-ramping-step-size 5"});
2666
2667 /* Init and get first sysinfo */
2668 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2669 last_si1 := g_system_information[0].si1;
2670 acc := last_si1.rach_control.acc;
2671 count := f_acc09_count_allowed(acc);
2672 /* Adm subset size was set to 0 above, so wait until all ACC are barred */
2673 while (count > 0) {
2674 last_si1 := f_recv_next_si1(0);
2675 acc := last_si1.rach_control.acc;
2676 count := f_acc09_count_allowed(acc);
2677 log("RSL: wait len()=0: GOT SI1 ACC len=", count, ": ", acc);
2678 }
2679
2680 /* Increase adm subset size, we should see ramping start up */
2681 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10"});
2682 prev_count := 0;
2683 while (true) {
2684 last_si1 := f_recv_next_si1(0);
2685 acc := last_si1.rach_control.acc;
2686 count := f_acc09_count_allowed(acc);
2687 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2688
2689 if (prev_count > count) {
2690 setverdict(fail, "ACC allowed count dropped while expecting grow: ", prev_count, " -> ", count);
2691 break;
2692 }
2693
2694 if (count == 9) {
2695 break; /* Maximum reached (10 - 1 perm barred), done here */
2696 }
2697
2698 prev_count := count;
2699 }
2700
2701 setverdict(pass);
2702
2703 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2704 "rach access-control-class 4 allowed",
2705 "no access-control-class-ramping"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002706 f_shutdown_helper();
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002707}
2708
Harald Welte4003d112017-12-09 22:35:39 +01002709testcase TC_ctrl_msc_connection_status() runs on test_CT {
2710 var charstring ctrl_resp;
2711
Harald Welte89d42e82017-12-17 16:42:41 +01002712 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002713
2714 /* See https://osmocom.org/issues/2729 */
2715 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002716 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002717}
2718
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002719testcase TC_ctrl_msc0_connection_status() runs on test_CT {
2720 var charstring ctrl_resp;
2721
2722 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002723
2724 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002725 f_shutdown_helper();
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002726}
2727
Harald Welte4003d112017-12-09 22:35:39 +01002728testcase TC_ctrl() runs on test_CT {
2729 var charstring ctrl_resp;
2730
Harald Welte89d42e82017-12-17 16:42:41 +01002731 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002732
2733 /* all below values must match the osmo-bsc.cfg config file used */
2734
Harald Welte6a129692018-03-17 17:30:14 +01002735 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
2736 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Oliver Smith75aa0202019-08-19 14:17:50 +02002737 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "4");
Harald Welte4003d112017-12-09 22:35:39 +01002738
2739 var integer bts_nr := 0;
2740 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
2741 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
2742 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
2743 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
2744 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
2745 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
2746 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
2747
2748 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
2749 f_sleep(2.0);
2750 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
2751 setverdict(fail, "oml-uptime not incrementing as expected");
2752 }
2753 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
2754
2755 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
2756
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002757 f_shutdown_helper();
Harald Welte96c94412017-12-09 03:12:45 +01002758}
2759
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02002760/* Verify that Upon receival of SET "location", BSC forwards a TRAP
2761 "location-state" over the SCCPlite IPA conn */
2762testcase TC_ctrl_location() runs on test_CT {
2763 var MSC_ConnHdlr vc_conn;
2764 var integer bts_nr := 0;
2765
2766 f_init(1, true);
2767 f_sleep(1.0);
2768
2769 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234567,fix3d,0.340000,0.560000,0.780000");
2770 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
2771 "1234567,fix3d,0.340000,0.560000,0.780000,operational,unlocked,on,001,01");
2772
2773 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "1");
2774 f_sleep(2.0);
2775
2776 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234888,fix3d,0.350000,0.570000,0.790000");
2777 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
2778 "1234888,fix3d,0.350000,0.570000,0.790000,operational,locked,off,001,01");
2779
2780 /* should match the one from config */
2781 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "0");
2782
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002783 f_shutdown_helper();
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02002784}
2785
Harald Welte6f521d82017-12-11 19:52:02 +01002786
2787/***********************************************************************
2788 * Paging Testing
2789 ***********************************************************************/
2790
2791type record Cell_Identity {
2792 GsmMcc mcc,
2793 GsmMnc mnc,
2794 GsmLac lac,
2795 GsmCellId ci
2796};
Harald Welte24135bd2018-03-17 19:27:53 +01002797private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01002798private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01002799
Harald Welte5d1a2202017-12-13 19:51:29 +01002800type set of integer BtsIdList;
2801
2802private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
2803 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
2804 if (bts_id == bts_ids[j]) {
2805 return true;
2806 }
2807 }
2808 return false;
2809}
Harald Welte6f521d82017-12-11 19:52:02 +01002810
2811/* core paging test helper function; used by most paging test cases */
2812private function f_pageing_helper(hexstring imsi,
2813 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01002814 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01002815 template RSL_ChanNeeded rsl_chneed := omit,
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002816 template (omit) OCT4 tmsi := omit) runs on test_CT
Harald Welte6f521d82017-12-11 19:52:02 +01002817{
2818 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002819 var template MobileIdentityV mi;
Harald Welte6f521d82017-12-11 19:52:02 +01002820 var RSL_Message rx_rsl;
2821 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01002822 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01002823
2824 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01002825
2826 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01002827 for (i := 0; i < NUM_BTS; i := i + 1) {
2828 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01002829 }
Harald Welte6f521d82017-12-11 19:52:02 +01002830
2831 if (isvalue(rsl_chneed)) {
2832 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
2833 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
2834 } else {
2835 bssmap_chneed := omit;
2836 }
2837
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002838 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[0].sccp_addr_peer, g_bssap[0].sccp_addr_own,
2839 ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed)));
Harald Welte6f521d82017-12-11 19:52:02 +01002840
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002841 if (not istemplatekind(tmsi, "omit")) {
2842 mi := t_MI_TMSI(tmsi);
Harald Welte6f521d82017-12-11 19:52:02 +01002843 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002844 mi := tr_MI_IMSI(imsi);
Harald Welte6f521d82017-12-11 19:52:02 +01002845 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002846
Harald Welte5d1a2202017-12-13 19:51:29 +01002847 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002848 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(mi));
Harald Welte5d1a2202017-12-13 19:51:29 +01002849 /* check channel type, paging group */
2850 if (rx_rsl.ies[1].body.paging_group != paging_group) {
2851 setverdict(fail, "Paging for wrong paging group");
2852 }
2853 if (ispresent(rsl_chneed) and
2854 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
2855 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
2856 }
Harald Welte6f521d82017-12-11 19:52:02 +01002857 }
Harald Welte2fccd982018-01-31 15:48:19 +01002858 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01002859 /* do a quick check on all not-included BTSs if they received paging */
2860 for (i := 0; i < NUM_BTS; i := i + 1) {
2861 timer T := 0.1;
2862 if (f_bts_in_list(i, bts_ids)) {
2863 continue;
2864 }
2865 T.start;
2866 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002867 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(mi))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01002868 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
2869 }
2870 [] IPA_RSL[i].receive { repeat; }
2871 [] T.timeout { }
2872 }
Harald Welte6f521d82017-12-11 19:52:02 +01002873 }
2874
2875 setverdict(pass);
2876}
2877
Harald Welte5d1a2202017-12-13 19:51:29 +01002878const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01002879const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01002880const BtsIdList c_BtsId_LAC1 := { 0, 1 };
2881const BtsIdList c_BtsId_LAC2 := { 2 };
2882
Harald Welte6f521d82017-12-11 19:52:02 +01002883/* PAGING by IMSI + TMSI */
2884testcase TC_paging_imsi_nochan() runs on test_CT {
2885 var BSSMAP_FIELD_CellIdentificationList cid_list;
2886 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01002887 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002888 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002889}
2890
2891/* PAGING by IMSI + TMSI */
2892testcase TC_paging_tmsi_nochan() runs on test_CT {
2893 var BSSMAP_FIELD_CellIdentificationList cid_list;
2894 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01002895 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002896 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002897}
2898
2899/* Paging with different "channel needed' values */
2900testcase TC_paging_tmsi_any() runs on test_CT {
2901 var BSSMAP_FIELD_CellIdentificationList cid_list;
2902 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01002903 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002904 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002905}
2906testcase TC_paging_tmsi_sdcch() runs on test_CT {
2907 var BSSMAP_FIELD_CellIdentificationList cid_list;
2908 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01002909 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002910 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002911}
2912testcase TC_paging_tmsi_tch_f() runs on test_CT {
2913 var BSSMAP_FIELD_CellIdentificationList cid_list;
2914 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01002915 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002916 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002917}
2918testcase TC_paging_tmsi_tch_hf() runs on test_CT {
2919 var BSSMAP_FIELD_CellIdentificationList cid_list;
2920 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01002921 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002922 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002923}
2924
2925/* Paging by CGI */
2926testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
2927 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2928 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01002929 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01002930 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002931}
2932
2933/* Paging by LAC+CI */
2934testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
2935 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2936 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01002937 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01002938 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002939}
2940
2941/* Paging by CI */
2942testcase TC_paging_imsi_nochan_ci() runs on test_CT {
2943 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2944 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01002945 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01002946 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002947}
2948
2949/* Paging by LAI */
2950testcase TC_paging_imsi_nochan_lai() runs on test_CT {
2951 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2952 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01002953 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002954 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002955}
2956
2957/* Paging by LAC */
2958testcase TC_paging_imsi_nochan_lac() runs on test_CT {
2959 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2960 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01002961 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002962 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002963}
2964
2965/* Paging by "all in BSS" */
2966testcase TC_paging_imsi_nochan_all() runs on test_CT {
2967 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2968 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01002969 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002970 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002971}
2972
Stefan Sperling7b5e1782018-03-20 19:32:43 +01002973/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01002974testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
2975 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2976 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 +01002977 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002978 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01002979}
Harald Welte6f521d82017-12-11 19:52:02 +01002980
Stefan Sperling7b5e1782018-03-20 19:32:43 +01002981/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01002982testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
2983 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2984 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01002985 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002986 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01002987}
2988
Stefan Sperling7b5e1782018-03-20 19:32:43 +01002989/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01002990testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
2991 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2992 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01002993 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002994 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01002995}
2996
Harald Welte6f521d82017-12-11 19:52:02 +01002997/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01002998testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
2999 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3000 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
3001 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003002 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003003}
3004
3005/* Paging on empty list: Verify none of them page */
3006testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
3007 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3008 cid_list := { cIl_LAC := { } };
3009 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01003010 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01003011}
3012
Stefan Sperling049a86e2018-03-20 15:51:00 +01003013/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
3014testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
3015 var template BSSMAP_FIELD_CellIdentificationList cid_list;
3016 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
3017 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
3018 f_shutdown_helper();
3019}
3020
Harald Welte6f521d82017-12-11 19:52:02 +01003021/* Verify paging retransmission interval + count */
3022/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01003023/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01003024
Harald Weltee65d40e2017-12-13 00:09:06 +01003025/* Verify PCH load */
3026testcase TC_paging_imsi_load() runs on test_CT {
3027 var BSSMAP_FIELD_CellIdentificationList cid_list;
3028 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01003029 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01003030 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003031 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01003032
3033 /* tell BSC there is no paging space anymore */
3034 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01003035 f_sleep(0.2);
3036 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01003037
3038 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
3039 * there would be 8 retransmissions during 4 seconds */
3040 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01003041 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01003042 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003043 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Weltee65d40e2017-12-13 00:09:06 +01003044 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02003045 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01003046 }
Harald Welte2caa1062018-03-17 18:19:05 +01003047 [] T_retrans.timeout {
3048 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
3049 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
3050 T_retrans.start;
3051 repeat;
3052 }
Harald Weltee65d40e2017-12-13 00:09:06 +01003053 [] T.timeout {
3054 setverdict(pass);
3055 }
3056 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003057
3058 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01003059}
3060
Harald Welte235ebf12017-12-15 14:18:16 +01003061/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01003062testcase TC_paging_counter() runs on test_CT {
3063 var BSSMAP_FIELD_CellIdentificationList cid_list;
3064 timer T := 4.0;
3065 var integer i;
3066 var integer paging_attempted_bsc;
3067 var integer paging_attempted_bts[NUM_BTS];
3068 var integer paging_expired_bts[NUM_BTS];
3069 cid_list := valueof(ts_BSSMAP_CIL_noCell);
3070
3071 f_init();
3072
3073 /* read counters before paging */
3074 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
3075 for (i := 0; i < NUM_BTS; i := i+1) {
3076 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
3077 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
3078 }
3079
3080 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
3081
3082 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
3083 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
3084 for (i := 0; i < NUM_BTS; i := i+1) {
3085 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
3086 paging_attempted_bts[i]+1);
3087 }
3088
3089 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
3090 f_sleep(12.0);
3091 for (i := 0; i < NUM_BTS; i := i+1) {
3092 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
3093 paging_expired_bts[i]+1);
3094 }
Harald Welte1ff69992017-12-14 12:31:17 +01003095
Philipp Maier282ca4b2018-02-27 17:17:00 +01003096 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01003097}
3098
3099
Harald Welte10985002017-12-12 09:29:15 +01003100/* Verify paging stops after A-RESET */
3101testcase TC_paging_imsi_a_reset() runs on test_CT {
3102 var BSSMAP_FIELD_CellIdentificationList cid_list;
3103 timer T := 3.0;
3104 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01003105 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01003106
3107 /* Perform a BSSMAP Reset and wait for ACK */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003108 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 +01003109 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003110 [] 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 +01003111 [] BSSAP.receive { repeat; }
3112 }
3113
Daniel Willmanncbef3982018-07-30 09:22:40 +02003114 /* Wait to avoid a possible race condition if a paging message is
3115 * received right before the reset ACK. */
3116 f_sleep(0.2);
3117
Harald Welte10985002017-12-12 09:29:15 +01003118 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01003119 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
3120 IPA_RSL[i].clear;
3121 }
Harald Welte10985002017-12-12 09:29:15 +01003122
3123 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
3124 T.start;
3125 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003126 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte10985002017-12-12 09:29:15 +01003127 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003128 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01003129 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003130 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003131 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003132 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003133 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07003134 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01003135 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02003136 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01003137 }
Harald Welte10985002017-12-12 09:29:15 +01003138 [] T.timeout {
3139 setverdict(pass);
3140 }
3141 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01003142
3143 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01003144}
Harald Welteae026692017-12-09 01:03:01 +01003145
Philipp Maierf45824a2019-08-14 14:44:10 +02003146/* Verify how we handle unsolicited Paging Response. In case of an unsolicit
3147 * paging response we can not know which MSC is in charge, so we will blindly
3148 * pick the first configured MSC. This behavior is required in order to make
3149 * MT-CSFB calls working because in those cases the BSC can not know that the
3150 * MSC has already paged the subscriver via SGs. So any MT-CSFB call will look
3151 * like an unsolicited Paging Response to the MSC.
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003152 */
3153testcase TC_paging_resp_unsol() runs on test_CT {
3154
3155 f_init(1);
Philipp Maierf45824a2019-08-14 14:44:10 +02003156 timer T := 5.0;
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003157
3158 var BSSAP_N_CONNECT_ind rx_c_ind;
3159 var DchanTuple dt;
3160 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
Philipp Maierf45824a2019-08-14 14:44:10 +02003161 var octetstring rr_pag_resp := enc_PDU_ML3_MS_NW(l3);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003162
3163 /* Send CHAN RQD and wait for allocation; acknowledge it */
3164 dt.rsl_chan_nr := f_chreq_act_ack();
3165
3166 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
3167 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
3168
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003169
Philipp Maierf45824a2019-08-14 14:44:10 +02003170 /* Expevct a CR with a matching Paging response on the A-Interface */
3171 T.start;
3172 alt {
3173 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(rr_pag_resp))) {
3174 setverdict(pass);
3175 }
3176 [] BSSAP.receive {
3177 setverdict(fail, "Received unexpected message on A-Interface!");
3178 }
3179 [] T.timeout {
3180 setverdict(fail, "Received nothing on A-Interface!");
3181 }
3182 }
3183
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003184 f_shutdown_helper();
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01003185}
3186
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003187/* Test RSL link drop causes counter increment */
3188testcase TC_rsl_drop_counter() runs on test_CT {
3189 var integer rsl_fail;
3190
Harald Welte89d42e82017-12-17 16:42:41 +01003191 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003192
3193 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
3194
3195 bts[0].rsl.vc_IPA.stop;
3196
3197 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
3198
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003199 f_shutdown_helper();
Harald Welte4e9b9cc2017-12-14 18:31:02 +01003200}
3201
3202/* TODO: Test OML link drop causes counter increment */
3203
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003204/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
3205function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
3206 timer T := 10.0;
3207
3208 bts[0].rsl.id := "IPA-0-RSL";
3209 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
3210 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
3211 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
Oliver Smith92c2bdb2019-08-20 15:11:24 +02003212 bts[0].rsl.ccm_pars.unit_id := "99/0/0"; /* value which is unknown at BTS */
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003213
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +01003214 f_ipa_ctrl_start_client(mp_bsc_ip, mp_bsc_ctrl_port);
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003215
3216 f_init_mgcp("VirtMSC");
3217
3218 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
3219 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
3220 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
3221 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
3222
3223 /* wait for IPA OML link to connect and then disconnect */
3224 T.start;
3225 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +07003226 [] IPA_RSL[0].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) {
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003227 T.stop;
3228 return true;
3229 }
3230 [] IPA_RSL[0].receive { repeat }
3231 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02003232 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003233 }
3234 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003235 return false;
3236}
3237
3238/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3239testcase TC_rsl_unknown_unit_id() runs on test_CT {
3240 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
3241 setverdict(pass);
3242 } else {
3243 setverdict(fail, "Timeout RSL waiting for connection to close");
3244 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003245 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003246}
3247
3248
3249/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3250testcase TC_oml_unknown_unit_id() runs on test_CT {
3251 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
3252 setverdict(pass);
3253 } else {
3254 setverdict(fail, "Timeout OML waiting for connection to close");
3255 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003256 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003257}
3258
3259
Harald Weltec1a2fff2017-12-17 11:06:19 +01003260/***********************************************************************
Harald Welte6811d102019-04-14 22:23:14 +02003261 * "New world" test cases using RSL_Emulation + RAN_Emulation
Harald Weltec1a2fff2017-12-17 11:06:19 +01003262 ***********************************************************************/
3263
Harald Welte6811d102019-04-14 22:23:14 +02003264import from RAN_Emulation all;
Harald Welte47cd0e32020-08-21 12:39:11 +02003265import from BSSAP_LE_Emulation all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01003266import from RSL_Emulation all;
3267import from MSC_ConnectionHandler all;
3268
3269type function void_fn(charstring id) runs on MSC_ConnHdlr;
3270
Harald Welte336820c2018-05-31 20:34:52 +02003271/* helper function to create and connect a MSC_ConnHdlr component */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003272private function f_connect_handler(inout MSC_ConnHdlr vc_conn, integer bssap_idx := 0) runs on test_CT {
3273 connect(vc_conn:RAN, g_bssap[bssap_idx].vc_RAN:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01003274 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003275 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01003276 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01003277 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01003278 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
3279 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
3280 }
Neels Hofmeyr91401012019-07-11 00:42:35 +02003281 if (isvalue(bts[2])) {
3282 connect(vc_conn:RSL2, bts[2].rsl.vc_RSL:CLIENT_PT);
3283 connect(vc_conn:RSL2_PROC, bts[2].rsl.vc_RSL:RSL_PROC);
3284 }
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003285 connect(vc_conn:BSSAP, g_bssap[bssap_idx].vc_RAN:CLIENT);
Neels Hofmeyrcfe44062020-10-15 02:28:08 +02003286 if (mp_enable_lcs_tests) {
3287 connect(vc_conn:BSSAP_LE, g_bssap_le.vc_BSSAP_LE:CLIENT);
3288 connect(vc_conn:BSSAP_LE_PROC, g_bssap_le.vc_BSSAP_LE:PROC);
3289 }
Daniel Willmann191e0d92018-01-17 12:44:35 +01003290 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02003291 connect(vc_conn:MGCP_MULTI, vc_MGCP:MGCP_CLIENT_MULTI);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003292 connect(vc_conn:STATSD_PROC, vc_STATSD:STATSD_PROC);
Harald Welte336820c2018-05-31 20:34:52 +02003293}
3294
3295function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
3296runs on test_CT return MSC_ConnHdlr {
3297 var charstring id := testcasename();
3298 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003299 var integer bssap_idx := 0;
3300 if (isvalue(pars)) {
3301 bssap_idx := valueof(pars).mscpool.bssap_idx;
3302 }
Harald Welte336820c2018-05-31 20:34:52 +02003303 vc_conn := MSC_ConnHdlr.create(id);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003304 f_connect_handler(vc_conn, bssap_idx);
Neels Hofmeyr1708d1b2020-10-10 16:56:48 +02003305 /* Emit a marker to appear in the SUT's own logging output */
3306 f_logp(BSCVTY, testcasename() & "() start");
Harald Weltea0630032018-03-20 21:09:55 +01003307 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003308 return vc_conn;
3309}
3310
Harald Weltea0630032018-03-20 21:09:55 +01003311/* first function inside ConnHdlr component; sets g_pars + starts function */
3312private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
3313runs on MSC_ConnHdlr {
3314 if (isvalue(pars)) {
3315 g_pars := valueof(pars);
3316 }
3317 fn.apply(id);
3318}
3319
Oliver Smith26a3db72021-07-09 13:51:29 +02003320private function f_vty_encryption_a5(charstring options) runs on test_CT {
3321 f_vty_transceive(BSCVTY, "configure terminal");
3322 f_vty_transceive(BSCVTY, "network");
3323 f_vty_transceive(BSCVTY, "encryption a5 " & options);
3324 f_vty_transceive(BSCVTY, "exit");
3325 f_vty_transceive(BSCVTY, "exit");
3326}
3327
3328private function f_vty_encryption_a5_reset() runs on test_CT {
3329 /* keep in sync with docker-playground.git ttcn3-bsc-test/osmo-bsc.cfg */
3330 f_vty_encryption_a5("0 1 3");
3331}
3332
Harald Welte3c86ea02018-05-10 22:28:05 +02003333/* Establish signalling channel (non-assignment case) followed by cipher mode */
3334private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003335 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3336 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02003337 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02003338 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
3339 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
3340 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
3341 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02003342
Philipp Maier23000732018-05-18 11:25:37 +02003343 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02003344}
3345testcase TC_ciph_mode_a5_0() runs on test_CT {
3346 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003347 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003348 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
3349
3350 f_init(1, true);
3351 f_sleep(1.0);
3352 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3353 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003354 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003355}
3356testcase TC_ciph_mode_a5_1() runs on test_CT {
3357 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003358 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003359 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
3360
3361 f_init(1, true);
3362 f_sleep(1.0);
3363 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3364 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003365 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003366}
Oliver Smith50b98122021-07-09 15:00:28 +02003367/* OS#4975: verify that A5/2 is preferred over A5/0 */
3368testcase TC_ciph_mode_a5_2_0() runs on test_CT {
3369 var MSC_ConnHdlr vc_conn;
3370 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3371
3372 pars.encr := valueof(t_EncrParams('05'O, f_rnd_octstring(8))); /* A5/0 and A5/2 (0x01|0x04)*/
3373 pars.encr_exp_enc_alg := '04'O; /* A5/2 */
3374
3375 f_init(1, true);
3376 f_vty_encryption_a5("0 1 2 3");
3377 f_sleep(1.0);
3378 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3379 vc_conn.done;
3380 f_vty_encryption_a5_reset();
3381 f_shutdown_helper();
3382}
Oliver Smith1dff88d2021-07-09 08:45:51 +02003383/* OS#4975: verify that A5/1 is preferred over A5/2 */
3384testcase TC_ciph_mode_a5_2_1() runs on test_CT {
3385 var MSC_ConnHdlr vc_conn;
3386 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3387
3388 pars.encr := valueof(t_EncrParams('06'O, f_rnd_octstring(8))); /* A5/1 and A5/2 (0x02|0x04)*/
3389 pars.encr_exp_enc_alg := '02'O; /* A5/1 */
3390
3391 f_init(1, true);
3392 f_vty_encryption_a5("1 2");
3393 f_sleep(1.0);
3394 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3395 vc_conn.done;
3396 f_vty_encryption_a5_reset();
3397 f_shutdown_helper();
3398}
Harald Welte3c86ea02018-05-10 22:28:05 +02003399testcase TC_ciph_mode_a5_3() runs on test_CT {
3400 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003401 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003402 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
3403
3404 f_init(1, true);
3405 f_sleep(1.0);
3406 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3407 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003408 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003409}
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003410/* Establish a Signalling channel with A5/4 encryption. */
3411testcase TC_ciph_mode_a5_4() runs on test_CT {
3412 var MSC_ConnHdlr vc_conn;
3413 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3414 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Harald Welte3c86ea02018-05-10 22:28:05 +02003415
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003416 f_init(1, true);
Oliver Smith26a3db72021-07-09 13:51:29 +02003417 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003418 f_sleep(1.0);
3419 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3420 vc_conn.done;
Oliver Smith26a3db72021-07-09 13:51:29 +02003421 f_vty_encryption_a5_reset();
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02003422 f_shutdown_helper();
3423}
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003424/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
3425private function f_tc_assignment_aoip_tla_v6(charstring id) runs on MSC_ConnHdlr {
3426 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3427 var PDU_BSSAP ass_cmd := f_gen_ass_req(aoip_tla := "::3");
3428 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3429 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3430
3431 f_establish_fully(ass_cmd, exp_compl);
3432}
3433testcase TC_assignment_aoip_tla_v6() runs on test_CT {
3434 var MSC_ConnHdlr vc_conn;
3435 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3436
3437 f_init(1, true);
3438 f_sleep(1.0);
3439 vc_conn := f_start_handler(refers(f_tc_assignment_aoip_tla_v6), pars);
3440 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003441 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003442}
3443
Harald Welte3c86ea02018-05-10 22:28:05 +02003444
3445/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02003446private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003447 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3448 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003449
Harald Welte552620d2017-12-16 23:21:36 +01003450 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3451 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01003452
Harald Weltea0630032018-03-20 21:09:55 +01003453 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01003454}
Harald Welte552620d2017-12-16 23:21:36 +01003455testcase TC_assignment_fr_a5_0() runs on test_CT {
3456 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003457 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003458 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01003459
Harald Welte89d42e82017-12-17 16:42:41 +01003460 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003461 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003462 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003463 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003464 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003465}
Harald Welte552620d2017-12-16 23:21:36 +01003466testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01003467 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003468 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003469 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003470
Harald Welte89d42e82017-12-17 16:42:41 +01003471 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003472 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003473 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3474 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003475 f_shutdown_helper();
Harald Welte651fcdc2018-05-10 20:23:16 +02003476}
3477testcase TC_assignment_fr_a5_3() runs on test_CT {
3478 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003479 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003480 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003481
Harald Welte651fcdc2018-05-10 20:23:16 +02003482 f_init(1, true);
3483 f_sleep(1.0);
3484 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003485 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003486 f_shutdown_helper();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003487}
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003488/* Establish a Signalling channel and re-assign to TCH/F with A5/4 encryption. */
3489testcase TC_assignment_fr_a5_4() runs on test_CT {
3490 var MSC_ConnHdlr vc_conn;
3491 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3492 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8), f_rnd_octstring(16)));
3493
3494 f_init(1, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02003495 f_vty_encryption_a5("0 1 3 4");
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003496 f_sleep(1.0);
3497 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3498 vc_conn.done;
Oliver Smith7eabd312021-07-12 14:18:56 +02003499 f_vty_encryption_a5_reset();
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02003500 f_shutdown_helper();
3501}
Harald Weltec1a2fff2017-12-17 11:06:19 +01003502
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +02003503/* Allow only A5/4, but omit the Kc128 IE from MSC's msg. Expect Cipher Mode Reject. */
3504testcase TC_assignment_fr_a5_4_fail() runs on test_CT {
3505 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3506 var MSC_ConnHdlr vc_conn;
3507
3508 f_init(1, true);
3509 f_sleep(1.0);
3510
3511 pars.encr := valueof(t_EncrParams('10'O, f_rnd_octstring(8))); // A5/4 support, but Kc128 missing!
3512 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
3513 vc_conn.done;
3514 f_shutdown_helper();
3515}
3516
Harald Welte552620d2017-12-16 23:21:36 +01003517/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
3518private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003519 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01003520 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02003521 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003522
3523 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003524 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
3525
Harald Weltea0630032018-03-20 21:09:55 +01003526 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01003527}
Harald Welte552620d2017-12-16 23:21:36 +01003528testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
3529 var MSC_ConnHdlr vc_conn;
3530
Harald Welte89d42e82017-12-17 16:42:41 +01003531 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003532 f_sleep(1.0);
3533
Harald Welte8863fa12018-05-10 20:15:27 +02003534 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01003535 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003536 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003537}
3538
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003539private function f_TC_assignment_a5_not_sup(charstring id) runs on MSC_ConnHdlr {
3540 var template PDU_BSSAP exp_ass_cpl := f_gen_exp_compl();
3541 var PDU_BSSAP exp_ass_req := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003542
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003543 exp_ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3544 exp_ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3545
3546 /* this is like the beginning of f_establish_fully(), but only up to ciphering reject */
3547
3548 var BSSMAP_FIELD_CodecType codecType;
3549 timer T := 10.0;
3550
3551 codecType := exp_ass_req.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType;
3552 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
3553
3554 f_create_chan_and_exp();
3555 /* we should now have a COMPL_L3 at the MSC */
3556
3557 var template PDU_BSSAP exp_l3_compl;
3558 exp_l3_compl := tr_BSSMAP_ComplL3()
3559 if (g_pars.aoip == false) {
3560 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := omit;
3561 } else {
3562 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := ?;
3563 }
3564 T.start;
3565 alt {
3566 [] BSSAP.receive(exp_l3_compl);
3567 [] BSSAP.receive(tr_BSSMAP_ComplL3) {
3568 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching COMPLETE LAYER 3 INFORMATION");
3569 }
3570 [] T.timeout {
3571 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
3572 }
3573 }
3574
3575 /* Start ciphering, expect Cipher Mode Reject */
Neels Hofmeyr6c388f22021-06-11 02:36:56 +02003576 f_cipher_mode(g_pars.encr, exp_fail := true);
Harald Welte552620d2017-12-16 23:21:36 +01003577}
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003578testcase TC_assignment_fr_a5_not_sup() runs on test_CT {
3579 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01003580 var MSC_ConnHdlr vc_conn;
3581
Harald Welte89d42e82017-12-17 16:42:41 +01003582 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003583 f_sleep(1.0);
3584
Neels Hofmeyr0588cad2021-06-11 01:38:18 +02003585 pars.encr := valueof(t_EncrParams('20'O, f_rnd_octstring(8), f_rnd_octstring(16)));
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02003586 vc_conn := f_start_handler(refers(f_TC_assignment_a5_not_sup), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003587 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003588 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003589}
3590
3591
Harald Welte4532e0a2017-12-23 02:05:44 +01003592private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003593 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01003594 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02003595 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01003596 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003597
3598 f_statsd_reset();
Harald Weltea0630032018-03-20 21:09:55 +01003599 f_establish_fully(ass_cmd, exp_compl);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003600
3601 var StatsDExpects expect := {
Daniel Willmannc5398f72020-09-21 10:41:35 +02003602 { name := "TTCN3.bts.0.chreq.total", mtype := "c", min := 1, max := 1},
3603 { name := "TTCN3.bts.0.chreq.successful", mtype := "c", min := 1, max := 1},
Daniel Willmannebdecc02020-08-12 15:30:17 +02003604 { name := "TTCN3.bsc.0.assignment.attempted", mtype := "c", min := 1, max := 1},
3605 { name := "TTCN3.bsc.0.assignment.completed", mtype := "c", min := 1, max := 1}
3606 };
3607 f_statsd_expect(expect);
Harald Welte4532e0a2017-12-23 02:05:44 +01003608}
3609
3610testcase TC_assignment_sign() runs on test_CT {
3611 var MSC_ConnHdlr vc_conn;
3612
3613 f_init(1, true);
3614 f_sleep(1.0);
3615
Harald Welte8863fa12018-05-10 20:15:27 +02003616 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01003617 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003618 f_shutdown_helper();
Harald Welte4532e0a2017-12-23 02:05:44 +01003619}
3620
Harald Welte60aa5762018-03-21 19:33:13 +01003621/***********************************************************************
3622 * Codec (list) testing
3623 ***********************************************************************/
3624
3625/* check if the given rsl_mode is compatible with the a_elem */
3626private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
3627return boolean {
3628 select (a_elem.codecType) {
3629 case (GSM_FR) {
3630 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
3631 return true;
3632 }
3633 }
3634 case (GSM_HR) {
3635 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
3636 return true;
3637 }
3638 }
3639 case (GSM_EFR) {
3640 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
3641 return true;
3642 }
3643 }
3644 case (FR_AMR) {
3645 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
3646 return true;
3647 }
3648 }
3649 case (HR_AMR) {
3650 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
3651 return true;
3652 }
3653 }
3654 case else { }
3655 }
3656 return false;
3657}
3658
3659/* check if the given rsl_mode is compatible with the a_list */
3660private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
3661return boolean {
3662 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
3663 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
3664 return true;
3665 }
3666 }
3667 return false;
3668}
3669
3670/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02003671function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01003672return BSSMAP_IE_ChannelType {
3673 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
3674 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
3675 select (a_elem.codecType) {
3676 case (GSM_FR) {
3677 ret.channelRateAndType := ChRate_TCHF;
3678 ret.speechId_DataIndicator := Spdi_TCHF_FR;
3679 }
3680 case (GSM_HR) {
3681 ret.channelRateAndType := ChRate_TCHH;
3682 ret.speechId_DataIndicator := Spdi_TCHH_HR;
3683 }
3684 case (GSM_EFR) {
3685 ret.channelRateAndType := ChRate_TCHF;
3686 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
3687 }
3688 case (FR_AMR) {
3689 ret.channelRateAndType := ChRate_TCHF;
3690 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
3691 }
3692 case (HR_AMR) {
3693 ret.channelRateAndType := ChRate_TCHH;
3694 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
3695 }
3696 case else {
3697 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02003698 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01003699 }
3700 }
3701 return ret;
3702}
3703
Harald Weltea63b9102018-03-22 20:36:16 +01003704private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
3705return template RSL_IE_Body {
3706 var template RSL_IE_Body mode_ie := {
3707 chan_mode := {
3708 len := ?,
3709 reserved := ?,
3710 dtx_d := ?,
3711 dtx_u := ?,
3712 spd_ind := RSL_SPDI_SPEECH,
3713 ch_rate_type := -,
3714 coding_alg_rate := -
3715 }
3716 }
3717
3718 select (a_elem.codecType) {
3719 case (GSM_FR) {
3720 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
3721 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
3722 }
3723 case (GSM_HR) {
3724 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
3725 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
3726 }
3727 case (GSM_EFR) {
3728 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
3729 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
3730 }
3731 case (FR_AMR) {
3732 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
3733 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
3734 }
3735 case (HR_AMR) {
3736 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
3737 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
3738 }
3739 }
3740 return mode_ie;
3741}
3742
Harald Welte60aa5762018-03-21 19:33:13 +01003743type record CodecListTest {
3744 BSSMAP_IE_SpeechCodecList codec_list,
3745 charstring id
3746}
3747type record of CodecListTest CodecListTests
3748
3749private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02003750 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
3751 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
Harald Welte60aa5762018-03-21 19:33:13 +01003752
3753 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003754 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte79f3f542018-05-25 20:02:37 +02003755 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
3756 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
3757 g_pars.ass_codec_list.codecElements[0];
Philipp Maierd0e64b02019-03-13 14:15:23 +01003758 if (isvalue(g_pars.expect_mr_s0_s7)) {
3759 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
3760 g_pars.expect_mr_s0_s7;
3761 }
Harald Welte79f3f542018-05-25 20:02:37 +02003762 }
Harald Welte60aa5762018-03-21 19:33:13 +01003763 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
3764 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01003765 log("expecting ASS COMPL like this: ", exp_compl);
3766
3767 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01003768
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02003769 if (not g_pars.expect_channel_mode_modify) {
3770 /* Verify that the RSL-side activation actually matches our expectations */
3771 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
Harald Weltea63b9102018-03-22 20:36:16 +01003772
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02003773 var RSL_IE_Body mode_ie;
3774 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
3775 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02003776 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02003777 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02003778 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
3779 if (not match(mode_ie, t_mode_ie)) {
3780 log("mode_ie ", mode_ie, " != t_mode_ie ", t_mode_ie);
3781 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02003782 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02003783
3784 var RSL_IE_Body mr_conf;
3785 if (g_pars.expect_mr_conf_ie != omit) {
3786 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
3787 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
3788 mtc.stop;
3789 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02003790 log("found RSL MR CONFIG IE: ", mr_conf);
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02003791
3792 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
3793 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
3794 g_pars.expect_mr_conf_ie);
3795 }
3796 } else {
3797 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
3798 log("found RSL MR CONFIG IE: ", mr_conf);
3799 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
3800 mtc.stop;
3801 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02003802 }
3803 }
Harald Welte60aa5762018-03-21 19:33:13 +01003804}
3805
Philipp Maierd0e64b02019-03-13 14:15:23 +01003806private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
3807
3808 var PDU_BSSAP ass_cmd := f_gen_ass_req();
3809 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
3810
3811 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003812 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maierd0e64b02019-03-13 14:15:23 +01003813 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
3814 }
3815 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
3816 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
3817 log("expecting ASS FAIL like this: ", exp_fail);
3818
3819 f_establish_fully(ass_cmd, exp_fail);
3820}
3821
Harald Welte60aa5762018-03-21 19:33:13 +01003822testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02003823 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01003824 var MSC_ConnHdlr vc_conn;
3825
3826 f_init(1, true);
3827 f_sleep(1.0);
3828
3829 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02003830 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01003831 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003832 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01003833}
3834
3835testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02003836 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01003837 var MSC_ConnHdlr vc_conn;
3838
3839 f_init(1, true);
3840 f_sleep(1.0);
3841
3842 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02003843 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01003844 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003845 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01003846}
3847
3848testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02003849 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01003850 var MSC_ConnHdlr vc_conn;
3851
3852 f_init(1, true);
3853 f_sleep(1.0);
3854
3855 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02003856 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01003857 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003858 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01003859}
3860
Philipp Maierd0e64b02019-03-13 14:15:23 +01003861/* Allow 5,90k only (current default config) */
3862private function f_allow_amr_rate_5_90k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00003863 f_vty_cfg_msc(BSCVTY, 0, {
3864 "amr-config 12_2k forbidden",
3865 "amr-config 10_2k forbidden",
3866 "amr-config 7_95k forbidden",
3867 "amr-config 7_40k forbidden",
3868 "amr-config 6_70k forbidden",
3869 "amr-config 5_90k allowed",
3870 "amr-config 5_15k forbidden",
3871 "amr-config 4_75k forbidden"
3872 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01003873}
3874
3875/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
3876 * ("Config-NB-Code = 1") */
3877private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
Neels Hofmeyr2a5670b2020-11-25 23:39:57 +00003878 f_vty_cfg_msc(BSCVTY, 0, {
3879 "amr-config 12_2k allowed",
3880 "amr-config 10_2k forbidden",
3881 "amr-config 7_95k forbidden",
3882 "amr-config 7_40k allowed",
3883 "amr-config 6_70k forbidden",
3884 "amr-config 5_90k allowed",
3885 "amr-config 5_15k forbidden",
3886 "amr-config 4_75k allowed"
3887 });
Philipp Maierd0e64b02019-03-13 14:15:23 +01003888}
3889
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00003890private function f_vty_amr_start_mode_set(boolean fr, charstring startmode) runs on test_CT {
3891 var charstring tch;
3892 if (fr) {
3893 tch := "tch-f";
3894 } else {
3895 tch := "tch-h";
3896 }
3897 f_vty_cfg_bts(BSCVTY, 0, { "amr " & tch & " start-mode " & startmode });
3898}
3899
3900/* Set the AMR start-mode for this TCH back to the default configuration. */
3901private function f_vty_amr_start_mode_restore(boolean fr) runs on test_CT {
3902 f_vty_amr_start_mode_set(fr, "auto");
3903}
3904
Harald Welte60aa5762018-03-21 19:33:13 +01003905testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02003906 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01003907 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02003908
3909 /* Note: This setups the codec configuration. The parameter payload in
3910 * mr_conf must be consistant with the parameter codecElements in pars
3911 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02003912 var RSL_IE_Body mr_conf := {
3913 other := {
3914 len := 2,
3915 payload := '2804'O
3916 }
3917 };
Harald Welte60aa5762018-03-21 19:33:13 +01003918
Philipp Maier7695a0d2018-09-27 17:52:14 +02003919 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Philipp Maier806f8f12019-03-12 12:13:41 +01003920 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02003921 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
3922 pars.expect_mr_conf_ie := mr_conf;
3923
Harald Welte60aa5762018-03-21 19:33:13 +01003924 f_init(1, true);
3925 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00003926 f_vty_amr_start_mode_set(true, "1");
Harald Welte60aa5762018-03-21 19:33:13 +01003927
Harald Welte8863fa12018-05-10 20:15:27 +02003928 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01003929 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00003930
3931 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01003932 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01003933}
3934
3935testcase TC_assignment_codec_amr_h() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02003936 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01003937 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02003938
3939 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02003940 var RSL_IE_Body mr_conf := {
3941 other := {
3942 len := 2,
3943 payload := '2804'O
3944 }
3945 };
Harald Welte60aa5762018-03-21 19:33:13 +01003946
Philipp Maier7695a0d2018-09-27 17:52:14 +02003947 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Philipp Maier806f8f12019-03-12 12:13:41 +01003948 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02003949 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
3950 pars.expect_mr_conf_ie := mr_conf;
3951
Harald Welte60aa5762018-03-21 19:33:13 +01003952 f_init(1, true);
3953 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00003954 f_vty_amr_start_mode_set(false, "1");
Harald Welte60aa5762018-03-21 19:33:13 +01003955
Harald Welte8863fa12018-05-10 20:15:27 +02003956 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01003957 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00003958
3959 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01003960 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01003961}
3962
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02003963/* Establish signalling on a TCH/F lchan, and then switch to speech mode without a new Assignment. */
3964testcase TC_assignment_codec_fr_by_mode_modify() runs on test_CT {
3965 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3966 var MSC_ConnHdlr vc_conn;
3967
3968 f_init(1, true);
3969 f_sleep(1.0);
3970
3971 /* By disabling all SDCCH, the MS should be given a TCH/F for signalling. Then activating an FR codec should
3972 * merely do a Channel Mode Modify, and not assign to a new lchan. f_establish_fully() already accounts for
3973 * expecting a Channel Mode Modify if the channel type is compatible. */
3974 f_disable_all_sdcch();
3975 f_disable_all_tch_h();
3976
3977 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3978 pars.expect_channel_mode_modify := true;
3979 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
3980 vc_conn.done;
3981
3982 f_enable_all_sdcch();
3983 f_enable_all_tch();
3984 f_shutdown_helper();
3985}
3986
Neels Hofmeyr454d7922020-11-26 02:24:57 +00003987/* 'amr start-mode auto' should not keep the (unused) 'smod' bits from previous configuration */
3988testcase TC_assignment_codec_amr_startmode_cruft() runs on test_CT {
3989 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3990 var MSC_ConnHdlr vc_conn;
3991
3992 var RSL_IE_Body mr_conf := {
3993 other := {
3994 len := 2,
3995 payload := '2004'O /* <- expect ICMI=0, smod=00 */
3996 }
3997 };
3998
3999 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4000 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
4001 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
4002 pars.expect_mr_conf_ie := mr_conf;
4003
4004 f_init(1, true);
4005 f_sleep(1.0);
4006
4007 /* First set nonzero start mode bits */
4008 f_vty_amr_start_mode_set(true, "4");
4009 /* Now set to auto, and expect the startmode bits to be zero in the message, i.e. ensure that osmo-bsc does not
4010 * let the startmode bits stick around and has deterministic MultiRate config for 'start-mode auto'; that is
4011 * ensured by above '2004'O, where 'x0xx'O indicates ICMI = 0, spare = 0, smod = 00. */
4012 f_vty_amr_start_mode_set(true, "auto");
4013
4014 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4015 vc_conn.done;
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004016
4017 /* Clear the startmode bits to not affect subsequent tests, in case the bits should indeed stick around. */
4018 f_vty_amr_start_mode_set(true, "1");
4019 f_vty_amr_start_mode_restore(true);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004020 f_shutdown_helper();
Neels Hofmeyr454d7922020-11-26 02:24:57 +00004021}
4022
Neels Hofmeyr21863562020-11-26 00:34:33 +00004023function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0,
4024 charstring start_mode := "1")
Philipp Maierd0e64b02019-03-13 14:15:23 +01004025runs on test_CT {
4026
4027 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4028 var MSC_ConnHdlr vc_conn;
4029
4030 /* See note above */
4031 var RSL_IE_Body mr_conf := {
4032 other := {
4033 len := lengthof(mrconf),
4034 payload := mrconf
4035 }
4036 };
4037
4038 if (fr) {
4039 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4040 } else {
4041 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4042 }
4043 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4044 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4045 pars.expect_mr_conf_ie := mr_conf;
4046 pars.expect_mr_s0_s7 := exp_s8_s0;
4047
4048 f_init(1, true);
4049 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004050 f_vty_amr_start_mode_set(fr, start_mode);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004051 f_sleep(1.0);
4052
4053 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4054 vc_conn.done;
4055 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004056 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004057}
4058
4059function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
4060runs on test_CT {
4061
4062 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4063 var MSC_ConnHdlr vc_conn;
4064
4065 if (fr) {
4066 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
4067 } else {
4068 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4069 }
4070 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
4071 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4072
4073 f_init(1, true);
4074 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004075 f_vty_amr_start_mode_set(fr, "1");
Philipp Maierd0e64b02019-03-13 14:15:23 +01004076 f_sleep(1.0);
4077
4078 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
4079 vc_conn.done;
4080 f_allow_amr_rate_5_90k();
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004081 f_vty_amr_start_mode_restore(fr);
Philipp Maierd0e64b02019-03-13 14:15:23 +01004082}
4083
4084
4085/* Set S1, we expect an AMR multirate configuration IE with all four rates
4086 * set. */
4087testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004088 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004089 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004090}
4091
4092/* Set S1, we expect an AMR multirate configuration IE with the lower three
4093 * rates set. */
4094testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004095 f_TC_assignment_codec_amr(false, '2815208820'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004096 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004097}
4098
4099/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4100 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4101testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004102 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004103 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004104}
4105
4106/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
4107 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
4108testcase TC_assignment_codec_amr_h_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004109 f_TC_assignment_codec_amr(false, '2815208820'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004110 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004111}
4112
4113/* The following block of tests selects more and more rates until all four
4114 * possible rates are in the active set (full rate) */
4115testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004116 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004117 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004118}
4119
4120testcase TC_assignment_codec_amr_f_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004121 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004122 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004123}
4124
4125testcase TC_assignment_codec_amr_f_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004126 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004127 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004128}
4129
4130testcase TC_assignment_codec_amr_f_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004131 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004132 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004133}
4134
4135/* The following block of tests selects more and more rates until all three
4136 * possible rates are in the active set (half rate) */
4137testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004138 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004139 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004140}
4141
4142testcase TC_assignment_codec_amr_h_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004143 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004144 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004145}
4146
4147testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004148 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004149 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004150}
4151
4152/* The following block tests what happens when the MSC does offer rate
4153 * configurations that are not supported by the BSC. Normally such situations
4154 * should not happen because the MSC gets informed by the BSC in advance via
4155 * the L3 COMPLETE message which rates are applicable. The MSC should not try
4156 * to offer rates that are not applicable anyway. */
4157
4158testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004159 /* Try to include 12,2k in into the active set even though the channel
4160 * is half rate only. The BSC is expected to remove the 12,0k */
4161 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004162 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004163}
4164
4165testcase TC_assignment_codec_amr_f_S01234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004166 /* See what happens when all rates are selected at once. Since then
4167 * Also S1 is selected, this setting will be prefered and we should
4168 * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
4169 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004170 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004171}
4172
4173testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004174 /* Same as above, but with S1 missing, the MSC is then expected to
4175 * select the currently supported rates, which are also 12.2k, 7,40k,
4176 * 5,90k, and 4,75k, into the active set. */
4177 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004178 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004179}
4180
4181testcase TC_assignment_codec_amr_f_zero() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004182 /* Try to select no rates at all */
4183 f_TC_assignment_codec_amr_fail(true, '00000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004184 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004185}
4186
4187testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004188 /* Try to select only unsupported rates */
4189 f_TC_assignment_codec_amr_fail(true, '01101000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004190 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004191}
4192
4193testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02004194 /* Try to select 12,2k for half rate */
4195 f_TC_assignment_codec_amr_fail(false, '10000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004196 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01004197}
4198
Neels Hofmeyr21863562020-11-26 00:34:33 +00004199testcase TC_assignment_codec_amr_f_start_mode_auto() runs on test_CT {
4200 f_TC_assignment_codec_amr(true, '209520882208'O, '11111111'B, '00000010'B,
4201 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004202 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004203}
4204
4205testcase TC_assignment_codec_amr_h_start_mode_auto() runs on test_CT {
4206 f_TC_assignment_codec_amr(false, '2015208820'O, '10010101'B, '00010101'B,
4207 start_mode := "auto");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004208 f_shutdown_helper();
Neels Hofmeyr21863562020-11-26 00:34:33 +00004209}
4210
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004211testcase TC_assignment_codec_amr_f_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004212 /* "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 +00004213 f_TC_assignment_codec_amr(true, '2b9520882208'O, '11111111'B, '00000010'B,
4214 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004215 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004216}
4217
4218testcase TC_assignment_codec_amr_h_start_mode_4() runs on test_CT {
Vadim Yanitskiy7815f482021-01-03 17:07:37 +01004219 /* "amr tch-h modes 0 2 4" => total 3 modes and start mode 4 => '10'B on the wire */
4220 f_TC_assignment_codec_amr(false, '2a15208820'O, '10010101'B, '00010101'B,
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004221 start_mode := "4");
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01004222 f_shutdown_helper();
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00004223}
4224
Philipp Maierac09bfc2019-01-08 13:41:39 +01004225private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004226 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
4227 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
4228 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
4229 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004230}
4231
4232private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004233 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
4234 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004235}
4236
4237private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01004238 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
4239 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
4240 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
4241 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
4242 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
4243 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01004244}
4245
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02004246private function f_disable_all_sdcch() runs on test_CT {
4247 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 borken");
4248 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 borken");
4249 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 borken");
4250 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 borken");
4251}
4252
4253private function f_enable_all_sdcch() runs on test_CT {
4254 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 0 unused");
4255 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 1 unused");
4256 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 2 unused");
4257 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 0 sub-slot 3 unused");
4258}
4259
Philipp Maierac09bfc2019-01-08 13:41:39 +01004260/* Allow HR only */
4261private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
4262 g_pars := f_gen_test_hdlr_pars();
4263 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4264 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4265 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4266 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4267 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4268 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4269 f_establish_fully(ass_cmd, exp_compl);
4270}
4271
4272/* Allow FR only */
4273private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
4274 g_pars := f_gen_test_hdlr_pars();
4275 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4276 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4277 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4278 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4279 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4280 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4281 f_establish_fully(ass_cmd, exp_compl);
4282}
4283
4284/* Allow HR only (expect assignment failure) */
4285private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
4286 g_pars := f_gen_test_hdlr_pars();
4287 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4288 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4289 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4290 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
4291 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
4292 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
4293 f_establish_fully(ass_cmd, exp_fail);
4294}
4295
4296/* Allow FR only (expect assignment failure) */
4297private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(charstring id) runs on MSC_ConnHdlr {
4298 g_pars := f_gen_test_hdlr_pars();
4299 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4300 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
4301 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4302 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
4303 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
4304 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4305 f_establish_fully(ass_cmd, exp_fail);
4306}
4307
4308/* Allow FR and HR, but prefer FR */
4309private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4310 g_pars := f_gen_test_hdlr_pars();
4311 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4312 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4313 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4314 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4315 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4316 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4317 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4318 f_establish_fully(ass_cmd, exp_compl);
4319}
4320
4321/* Allow FR and HR, but prefer HR */
4322private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4323 g_pars := f_gen_test_hdlr_pars();
4324 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4325 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4326 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4327 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4328 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4329 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4330 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4331 f_establish_fully(ass_cmd, exp_compl);
4332}
4333
4334/* Allow FR and HR, but prefer FR */
4335private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4336 g_pars := f_gen_test_hdlr_pars();
4337 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4338 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4339 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4340 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4341 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4342 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4343 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4344 f_establish_fully(ass_cmd, exp_compl);
4345}
4346
4347/* Allow FR and HR, but prefer HR */
4348private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4349 g_pars := f_gen_test_hdlr_pars();
4350 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4351 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4352 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4353 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4354 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4355 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4356 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4357 f_establish_fully(ass_cmd, exp_compl);
4358}
4359
4360/* Request a HR channel while all FR channels are exhausted, this is expected
4361 * to work without conflicts */
4362testcase TC_assignment_codec_fr_exhausted_req_hr() runs on test_CT {
4363 var MSC_ConnHdlr vc_conn;
4364 f_init(1, true);
4365 f_sleep(1.0);
4366 f_enable_all_tch();
4367 f_disable_all_tch_f();
4368 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr));
4369 vc_conn.done;
4370 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004371 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004372}
4373
4374/* Request a FR channel while all FR channels are exhausted, this is expected
4375 * to fail. */
4376testcase TC_assignment_codec_fr_exhausted_req_fr() runs on test_CT {
4377 var MSC_ConnHdlr vc_conn;
4378 f_init(1, true);
4379 f_sleep(1.0);
4380 f_enable_all_tch();
4381 f_disable_all_tch_f();
4382 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr_fail));
4383 vc_conn.done;
4384 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004385 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004386}
4387
4388/* Request a FR (prefered) or alternatively a HR channel while all FR channels
4389 * are exhausted, this is expected to be resolved by selecting a HR channel. */
4390testcase TC_assignment_codec_fr_exhausted_req_fr_hr() runs on test_CT {
4391 var MSC_ConnHdlr vc_conn;
4392 f_init(1, true);
4393 f_sleep(1.0);
4394 f_enable_all_tch();
4395 f_disable_all_tch_f();
4396 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
4397 vc_conn.done;
4398 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004399 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004400}
4401
4402/* Request a HR (prefered) or alternatively a FR channel while all FR channels
4403 * are exhausted, this is expected to work without conflicts. */
4404testcase TC_assignment_codec_fr_exhausted_req_hr_fr() runs on test_CT {
4405 var MSC_ConnHdlr vc_conn;
4406 f_init(1, true);
4407 f_sleep(1.0);
4408 f_enable_all_tch();
4409 f_disable_all_tch_f();
4410 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_hr_fr));
4411 vc_conn.done;
4412 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004413 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004414}
4415
4416/* Request a FR channel while all HR channels are exhausted, this is expected
4417 * to work without conflicts */
4418testcase TC_assignment_codec_hr_exhausted_req_fr() runs on test_CT {
4419 var MSC_ConnHdlr vc_conn;
4420 f_init(1, true);
4421 f_sleep(1.0);
4422 f_enable_all_tch();
4423 f_disable_all_tch_h();
4424 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr));
4425 vc_conn.done;
4426 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004427 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004428}
4429
4430/* Request a HR channel while all HR channels are exhausted, this is expected
4431 * to fail. */
4432testcase TC_assignment_codec_hr_exhausted_req_hr() runs on test_CT {
4433 var MSC_ConnHdlr vc_conn;
4434 f_init(1, true);
4435 f_sleep(1.0);
4436 f_enable_all_tch();
4437 f_disable_all_tch_h();
4438 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr_fail));
4439 vc_conn.done;
4440 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004441 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004442}
4443
4444/* Request a HR (prefered) or alternatively a FR channel while all HR channels
4445 * are exhausted, this is expected to be resolved by selecting a FR channel. */
4446testcase TC_assignment_codec_hr_exhausted_req_hr_fr() runs on test_CT {
4447 var MSC_ConnHdlr vc_conn;
4448 f_init(1, true);
4449 f_sleep(1.0);
4450 f_enable_all_tch();
4451 f_disable_all_tch_h();
4452 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_hr_fr));
4453 vc_conn.done;
4454 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004455 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004456}
4457
4458/* Request a FR (prefered) or alternatively a HR channel while all HR channels
4459 * are exhausted, this is expected to work without conflicts. */
4460testcase TC_assignment_codec_hr_exhausted_req_fr_hr() runs on test_CT {
4461 var MSC_ConnHdlr vc_conn;
4462 f_init(1, true);
4463 f_sleep(1.0);
4464 f_enable_all_tch();
4465 f_disable_all_tch_h();
4466 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_fr_hr));
4467 vc_conn.done;
4468 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004469 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004470}
4471
4472/* Allow FR and HR, but prefer HR */
4473private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4474 g_pars := f_gen_test_hdlr_pars();
4475 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4476 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4477 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4478 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4479 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4480 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4481 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4482 f_establish_fully(ass_cmd, exp_compl);
4483}
4484
4485/* Allow FR and HR, but prefer FR */
4486private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4487 g_pars := f_gen_test_hdlr_pars();
4488 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4489 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4490 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4491 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4492 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4493 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4494 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4495 f_establish_fully(ass_cmd, exp_compl);
4496}
4497
4498/* Request a HR (prefered) or alternatively a FR channel, it is expected that
4499 * HR, which is the prefered type, is selected. */
4500testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
4501 var MSC_ConnHdlr vc_conn;
4502 f_init(1, true);
4503 f_sleep(1.0);
4504 f_enable_all_tch();
4505 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
4506 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004507 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004508}
4509
4510/* Request a FR (prefered) or alternatively a HR channel, it is expected that
4511 * FR, which is the prefered type, is selected. */
4512testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
4513 var MSC_ConnHdlr vc_conn;
4514 f_init(1, true);
4515 f_sleep(1.0);
4516 f_enable_all_tch();
4517 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
4518 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004519 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004520}
4521
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004522testcase TC_assignment_osmux() runs on test_CT {
4523 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4524 var MSC_ConnHdlr vc_conn;
4525
4526 /* See note above */
4527 var RSL_IE_Body mr_conf := {
4528 other := {
4529 len := 2,
4530 payload := '2804'O
4531 }
4532 };
4533
4534 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4535 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
4536 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4537 pars.expect_mr_conf_ie := mr_conf;
4538 pars.use_osmux := true;
4539
4540 f_init(1, true, true);
4541 f_sleep(1.0);
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004542 f_vty_amr_start_mode_set(false, "1");
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004543
4544 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4545 vc_conn.done;
Neels Hofmeyra6ab8212020-11-25 23:57:47 +00004546
4547 f_vty_amr_start_mode_restore(false);
Vadim Yanitskiy292e5962021-01-03 14:18:47 +01004548 f_shutdown_helper();
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004549}
4550
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02004551/* test the procedure of the MSC requesting a Classmark Update:
4552 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
4553 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01004554private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02004555 g_pars := f_gen_test_hdlr_pars();
4556
Harald Weltea0630032018-03-20 21:09:55 +01004557 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01004558 /* we should now have a COMPL_L3 at the MSC */
4559 BSSAP.receive(tr_BSSMAP_ComplL3);
4560
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02004561 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
4562 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
4563
Harald Welte898113b2018-01-31 18:32:21 +01004564 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
4565 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
4566 setverdict(pass);
4567}
4568testcase TC_classmark() runs on test_CT {
4569 var MSC_ConnHdlr vc_conn;
4570 f_init(1, true);
4571 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02004572 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01004573 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004574 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01004575}
4576
Harald Welteeddf0e92020-06-21 19:42:15 +02004577/* Send a CommonID from the simulated MSC and verify that the information is used to
4578 * fill BSC-internal data structures (specifically, bsc_subscr associated with subscr_conn) */
4579private function f_tc_common_id(charstring id) runs on MSC_ConnHdlr {
4580 g_pars := f_gen_test_hdlr_pars();
4581 f_MscConnHdlr_init_vty();
4582
4583 f_create_chan_and_exp();
4584 /* we should now have a COMPL_L3 at the MSC */
4585 BSSAP.receive(tr_BSSMAP_ComplL3);
4586
4587 /* Send CommonID */
4588 BSSAP.send(ts_BSSMAP_CommonId(g_pars.imsi));
4589
4590 /* Use VTY to verify that the IMSI of the subscr_conn is set */
4591 var charstring regex := "*(IMSI: " & hex2str(g_pars.imsi) & ")*";
4592 f_vty_transceive_match_regexp_retry(BSCVTY, "show conns", regex, 0, 4, 1.0);
4593
4594 setverdict(pass);
4595}
4596testcase TC_common_id() runs on test_CT {
4597 var MSC_ConnHdlr vc_conn;
4598 f_init(1, true);
4599 f_sleep(1.0);
4600 vc_conn := f_start_handler(refers(f_tc_common_id));
4601 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004602 f_shutdown_helper();
Harald Welteeddf0e92020-06-21 19:42:15 +02004603}
4604
Harald Weltee3bd6582018-01-31 22:51:25 +01004605private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02004606 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01004607 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01004608 /* we should now have a COMPL_L3 at the MSC */
4609 BSSAP.receive(tr_BSSMAP_ComplL3);
4610
Harald Weltee3bd6582018-01-31 22:51:25 +01004611 /* send the single message we want to send */
4612 f_rsl_send_l3(l3);
4613}
4614
4615private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
4616 timer T := sec;
4617 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01004618 T.start;
4619 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01004620 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
4621 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02004622 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01004623 }
4624 [] T.timeout {
4625 setverdict(pass);
4626 }
4627 }
4628}
4629
Harald Weltee3bd6582018-01-31 22:51:25 +01004630/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
4631private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
4632 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
4633 f_bssap_expect_nothing();
4634}
Harald Welte898113b2018-01-31 18:32:21 +01004635testcase TC_unsol_ass_fail() runs on test_CT {
4636 var MSC_ConnHdlr vc_conn;
4637 f_init(1, true);
4638 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02004639 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01004640 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004641 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01004642}
Harald Welte552620d2017-12-16 23:21:36 +01004643
Harald Welteea99a002018-01-31 20:46:43 +01004644
4645/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
4646private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01004647 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
4648 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01004649}
4650testcase TC_unsol_ass_compl() runs on test_CT {
4651 var MSC_ConnHdlr vc_conn;
4652 f_init(1, true);
4653 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02004654 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01004655 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004656 f_shutdown_helper();
Harald Welteea99a002018-01-31 20:46:43 +01004657}
4658
4659
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004660/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
4661private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01004662 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
4663 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004664}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004665testcase TC_unsol_ho_fail() runs on test_CT {
4666 var MSC_ConnHdlr vc_conn;
4667 f_init(1, true);
4668 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02004669 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004670 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004671 f_shutdown_helper();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004672}
4673
4674
Harald Weltee3bd6582018-01-31 22:51:25 +01004675/* short message from MS should be ignored */
4676private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02004677 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01004678 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01004679 /* we should now have a COMPL_L3 at the MSC */
4680 BSSAP.receive(tr_BSSMAP_ComplL3);
4681
4682 /* send short message */
4683 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
4684 f_bssap_expect_nothing();
4685}
4686testcase TC_err_82_short_msg() runs on test_CT {
4687 var MSC_ConnHdlr vc_conn;
4688 f_init(1, true);
4689 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02004690 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01004691 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004692 f_shutdown_helper();
Harald Weltee3bd6582018-01-31 22:51:25 +01004693}
4694
4695
Harald Weltee9e02e42018-01-31 23:36:25 +01004696/* 24.008 8.4 Unknown message must trigger RR STATUS */
4697private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
4698 f_est_single_l3(ts_RRM_UL_REL('00'O));
4699 timer T := 3.0
4700 alt {
4701 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
4702 setverdict(pass);
4703 }
4704 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01004705 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01004706 }
4707}
4708testcase TC_err_84_unknown_msg() runs on test_CT {
4709 var MSC_ConnHdlr vc_conn;
4710 f_init(1, true);
4711 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02004712 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01004713 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004714 f_shutdown_helper();
Harald Weltee9e02e42018-01-31 23:36:25 +01004715}
4716
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004717/***********************************************************************
4718 * Handover
4719 ***********************************************************************/
4720
Harald Welte94e0c342018-04-07 11:33:23 +02004721/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
4722private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
4723runs on test_CT {
4724 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
4725 " timeslot "&int2str(ts_nr)&" ";
4726 f_vty_transceive(BSCVTY, cmd & suffix);
4727}
4728
Harald Welte261af4b2018-02-12 21:20:39 +01004729/* 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 +07004730private function f_vty_ss_action(TELNETasp_PT pt, charstring suffix,
4731 uint8_t bts_nr, uint8_t trx_nr,
4732 in RslChannelNr chan_nr)
4733{
Harald Welte261af4b2018-02-12 21:20:39 +01004734 /* FIXME: resolve those from component-global state */
4735 var integer ts_nr := chan_nr.tn;
4736 var integer ss_nr;
4737 if (ischosen(chan_nr.u.ch0)) {
4738 ss_nr := 0;
4739 } else if (ischosen(chan_nr.u.lm)) {
4740 ss_nr := chan_nr.u.lm.sub_chan;
4741 } else if (ischosen(chan_nr.u.sdcch4)) {
4742 ss_nr := chan_nr.u.sdcch4.sub_chan;
4743 } else if (ischosen(chan_nr.u.sdcch8)) {
4744 ss_nr := chan_nr.u.sdcch8.sub_chan;
4745 } else {
4746 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02004747 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01004748 }
4749
4750 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
4751 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
Vadim Yanitskiy00070722020-09-02 17:27:57 +07004752 f_vty_transceive(pt, cmd & suffix);
Harald Welte261af4b2018-02-12 21:20:39 +01004753}
4754
Neels Hofmeyr91401012019-07-11 00:42:35 +02004755/* Even though the VTY command to trigger handover takes a new BTS number as argument, behind the scenes osmo-bsc always
4756 * translates that to a target ARFCN+BSIC first. See bsc_vty.c trigger_ho_or_as(), which puts the selected BTS' neighbor
4757 * ident key (ARFCN + BSIC) in the struct passed on to handover_request(). handover_start() then resolves that to a
4758 * viable actual neighbor cell. So from the internal osmo-bsc perspective, we always request handover to an ARFCN + BSIC
4759 * pair, not really to a specific BTS number. */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07004760private function f_vty_handover(TELNETasp_PT pt, uint8_t bts_nr, uint8_t trx_nr,
4761 in RslChannelNr chan_nr, uint8_t new_bts_nr)
4762{
4763 f_vty_ss_action(pt, "handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
Harald Welte261af4b2018-02-12 21:20:39 +01004764}
4765
4766/* intra-BSC hand-over between BTS0 and BTS1 */
4767private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02004768 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4769 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01004770
4771 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4772 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4773
Harald Weltea0630032018-03-20 21:09:55 +01004774 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr666f0432020-07-04 00:53:07 +02004775 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Harald Welte261af4b2018-02-12 21:20:39 +01004776
4777 var HandoverState hs := {
4778 rr_ho_cmpl_seen := false,
4779 handover_done := false,
4780 old_chan_nr := -
4781 };
4782 /* issue hand-over command on VTY */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07004783 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
Harald Welte261af4b2018-02-12 21:20:39 +01004784 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
4785 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02004786
4787 /* From the MGW perspective, a handover is is characterized by
4788 * performing one MDCX operation with the MGW. So we expect to see
4789 * one more MDCX during handover. */
4790 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
4791
Harald Welte261af4b2018-02-12 21:20:39 +01004792 alt {
4793 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01004794 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02004795
Philipp Maier4dae0652018-11-12 12:03:26 +01004796 /* Since this is an internal handover we expect the BSC to inform the
4797 * MSC about the event */
4798 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
4799
Philipp Maier3e2af5d2018-07-11 17:01:05 +02004800 /* Check the amount of MGCP transactions is still consistant with the
4801 * test expectation */
4802 f_check_mgcp_expectations()
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02004803
4804 /* Ensure the Channel Activation for the new channel contained the right encryption params. as_handover() set
4805 * g_chan_nr to the new lchan that was handed over to. It lives in bts 1, so look it up at RSL1_PROC. */
4806 f_verify_encr_info(f_rslem_get_last_act(RSL1_PROC, 0, g_chan_nr));
4807
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01004808 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01004809}
4810
4811testcase TC_ho_int() runs on test_CT {
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02004812 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte261af4b2018-02-12 21:20:39 +01004813 var MSC_ConnHdlr vc_conn;
4814 f_init(2, true);
4815 f_sleep(1.0);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00004816
4817 f_ctrs_bsc_and_bts_init();
4818
Neels Hofmeyr5f7a9df2021-06-21 01:30:43 +02004819 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
Harald Welte261af4b2018-02-12 21:20:39 +01004820 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00004821
4822 /* from f_establish_fully() */
4823 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
4824 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
4825 /* from handover */
4826 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
4827 f_ctrs_bsc_and_bts_add(0, "handover:completed");
4828 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
4829 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
4830 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004831 f_shutdown_helper();
Harald Welte261af4b2018-02-12 21:20:39 +01004832}
Harald Weltee9e02e42018-01-31 23:36:25 +01004833
Oliver Smith7eabd312021-07-12 14:18:56 +02004834function 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 +02004835 var MSC_ConnHdlr vc_conn;
4836 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4837 pars.encr := valueof(t_EncrParams(encr_alg, f_rnd_octstring(8), f_rnd_octstring(16)));
4838
4839 f_init(2, true);
Oliver Smith7eabd312021-07-12 14:18:56 +02004840 f_vty_encryption_a5(enc_a5);
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02004841 f_sleep(1.0);
4842
4843 f_ctrs_bsc_and_bts_init();
4844
4845 vc_conn := f_start_handler(refers(f_tc_ho_int), pars);
4846 vc_conn.done;
4847
4848 /* from f_establish_fully() */
4849 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
4850 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
4851 /* from handover */
4852 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
4853 f_ctrs_bsc_and_bts_add(0, "handover:completed");
4854 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
4855 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
4856 f_ctrs_bsc_and_bts_verify();
Oliver Smith7eabd312021-07-12 14:18:56 +02004857 f_vty_encryption_a5_reset();
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02004858 f_shutdown_helper();
4859}
4860
4861testcase TC_ho_int_a5_0() runs on test_CT {
4862 f_tc_ho_int_a5('01'O);
4863}
4864
4865testcase TC_ho_int_a5_1() runs on test_CT {
4866 f_tc_ho_int_a5('02'O);
4867}
4868
4869testcase TC_ho_int_a5_3() runs on test_CT {
4870 f_tc_ho_int_a5('08'O);
4871}
4872
4873testcase TC_ho_int_a5_4() runs on test_CT {
Oliver Smith7eabd312021-07-12 14:18:56 +02004874 f_tc_ho_int_a5('10'O, "0 1 3 4");
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02004875}
4876
Neels Hofmeyr5f144212020-11-03 15:41:58 +00004877/* intra-BSC hand-over with CONNection FAILure and cause Radio Link Failure: check RR release cause */
4878private function f_tc_ho_int_radio_link_failure(charstring id) runs on MSC_ConnHdlr {
4879 g_pars := f_gen_test_hdlr_pars();
4880 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4881 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr5f144212020-11-03 15:41:58 +00004882
4883 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4884 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4885
4886 f_establish_fully(ass_cmd, exp_compl);
4887 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
4888
4889 var HandoverState hs := {
4890 rr_ho_cmpl_seen := false,
4891 handover_done := false,
4892 old_chan_nr := -
4893 };
4894 /* issue hand-over command on VTY */
4895 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
4896 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
4897 f_rslem_suspend(RSL1_PROC);
4898
4899 /* From the MGW perspective, a handover is is characterized by
4900 * performing one MDCX operation with the MGW. So we expect to see
4901 * one more MDCX during handover. */
4902 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
4903
4904 var RSL_Message rsl;
4905 var PDU_ML3_NW_MS l3;
4906 var RslChannelNr new_chan_nr;
4907 var GsmArfcn arfcn;
4908 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
4909 l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
4910 if (not ischosen(l3.msgs.rrm.handoverCommand)) {
4911 setverdict(fail, "Expected handoverCommand");
4912 mtc.stop;
4913 }
4914 }
4915 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
4916 new_chan_nr, arfcn);
4917
4918 f_rslem_register(0, new_chan_nr, RSL1_PROC);
4919
4920 /* resume processing of RSL DChan messages, which was temporarily suspended
4921 * before performing a hand-over */
4922 f_rslem_resume(RSL1_PROC);
4923 RSL1.receive(tr_RSL_IPA_CRCX(new_chan_nr));
4924
4925 f_sleep(1.0);
4926
4927 /* Handover fails because no HANDO DET appears on the new lchan,
4928 * and the old lchan reports a Radio Link Failure. */
4929 RSL.send(ts_RSL_CONN_FAIL_IND(g_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
4930
4931 var PDU_BSSAP rx_clear_request;
4932 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
4933 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
4934 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
4935
4936 var RR_Cause rr_cause := GSM48_RR_CAUSE_ABNORMAL_UNSPEC;
4937
4938 var MgcpCommand mgcp;
4939 interleave {
4940 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE(int2oct(enum2int(rr_cause), 1)))) {}
4941 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
4942 [] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
4943 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
4944 }
4945 [] RSL1.receive(tr_RSL_DEACT_SACCH(new_chan_nr)) {}
4946 [] RSL1.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
4947 RSL1.send(ts_RSL_RF_CHAN_REL_ACK(new_chan_nr));
4948 }
4949 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {}
4950 }
4951
4952 f_sleep(0.5);
4953 setverdict(pass);
4954}
4955testcase TC_ho_int_radio_link_failure() runs on test_CT {
4956 var MSC_ConnHdlr vc_conn;
4957 f_init(2, true);
4958 f_sleep(1.0);
4959
4960 f_ctrs_bsc_and_bts_init();
4961
4962 vc_conn := f_start_handler(refers(f_tc_ho_int_radio_link_failure));
4963 vc_conn.done;
4964
4965 /* from f_establish_fully() */
4966 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
4967 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
4968 /* from handover */
4969 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
4970 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
4971 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
4972 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:stopped");
4973 f_ctrs_bsc_and_bts_verify();
4974 f_shutdown_helper();
4975}
4976
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004977/* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02004978private function f_expect_dlcx_conns() runs on MSC_ConnHdlr {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004979 var MgcpCommand mgcp;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02004980 var template MgcpResponse mgcp_resp;
4981 var MGCP_RecvFrom mrf;
4982 var template MgcpMessage msg_resp;
4983 var template MgcpMessage msg_dlcx := {
4984 command := tr_DLCX()
4985 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004986
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02004987 if (g_pars.aoip) {
4988 MGCP.receive(tr_DLCX()) -> value mgcp {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004989 log("Got first DLCX: ", mgcp);
4990 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02004991 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004992
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004993 MGCP.receive(tr_DLCX()) -> value mgcp {
4994 log("Got second DLCX: ", mgcp);
4995 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
4996 };
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02004997 } else {
4998 /* For SCCPLite, BSC doesn't handle the MSC-side */
4999 MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_dlcx)) -> value mrf {
5000 log("Got first DLCX: ", mrf.msg.command);
5001 msg_resp := {
5002 response := ts_DLCX_ACK2(mrf.msg.command.line.trans_id)
5003 }
5004 MGCP_MULTI.send(t_MGCP_SendToMrf(mrf, msg_resp));
5005 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005006 }
5007
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005008 BSSAP.receive(tr_BSSMAP_ClearComplete);
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005009}
5010
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005011private 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 +01005012
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005013 f_bts_0_cfg(BSCVTY, {"neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005014 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5015
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005016 BSSAP.receive(tr_BSSMAP_HandoverRequired(exp_oldToNewBSSIEs));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005017
5018 f_sleep(0.5);
5019 /* The MSC negotiates Handover Request and Handover Request Ack with
5020 * the other BSS and comes back with a BSSMAP Handover Command
5021 * containing an RR Handover Command coming from the target BSS... */
5022
5023 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5024 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5025 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5026 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5027 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5028
5029 /* expect the Handover Command to go out on RR */
5030 var RSL_Message rsl_ho_cmd
5031 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5032 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5033 var RSL_IE_Body rsl_ho_cmd_l3;
5034 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5035 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5036 setverdict(fail);
5037 } else {
5038 log("Found L3 Info: ", rsl_ho_cmd_l3);
5039 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5040 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5041 setverdict(fail);
5042 } else {
5043 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5044 setverdict(pass);
5045 }
5046 }
5047
5048 /* When the other BSS has reported a completed handover, this side is
5049 * torn down. */
5050
5051 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
5052 var BssmapCause cause := enum2int(cause_val);
5053 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5054
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005055 f_expect_dlcx_conns();
Pau Espin Pedrol06199952021-06-15 11:30:00 +02005056
5057 interleave {
5058 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE));
5059 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr));
5060 [] RSL.receive(tr_RSL_RF_CHAN_REL(g_chan_nr));
5061 }
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005062 setverdict(pass);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005063}
5064
5065private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
5066 g_pars := f_gen_test_hdlr_pars();
5067 var PDU_BSSAP ass_req := f_gen_ass_req();
5068 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5069 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5070 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5071 f_establish_fully(ass_req, exp_compl);
5072
5073 f_ho_out_of_this_bsc();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005074}
5075testcase TC_ho_out_of_this_bsc() runs on test_CT {
5076 var MSC_ConnHdlr vc_conn;
5077
5078 f_init(1, true);
5079 f_sleep(1.0);
5080
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005081 f_ctrs_bsc_and_bts_init();
5082
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005083 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
5084 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005085
5086 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5087 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5088 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5089 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5090 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5091 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed");
5092 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005093 f_shutdown_helper();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005094}
5095
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005096private function f_mo_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5097 template (value) RslLinkId link_id := ts_RslLinkID_DCCH(0),
Vadim Yanitskiy2ef6a2f2020-10-08 23:17:32 +07005098 template (present) OCT1 dlci := ?,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005099 octetstring l3 := '0123456789'O)
5100runs on MSC_ConnHdlr {
Neels Hofmeyr43654812020-09-25 01:35:35 +02005101 /* The old lchan and conn should still be active. See that arbitrary L3
5102 * is still going through. */
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005103 rsl.send(ts_RSL_DATA_IND(g_chan_nr, link_id, l3));
Neels Hofmeyr43654812020-09-25 01:35:35 +02005104 var template PDU_BSSAP exp_data := {
5105 discriminator := '1'B,
5106 spare := '0000000'B,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07005107 dlci := dlci,
5108 lengthIndicator := lengthof(l3),
Neels Hofmeyr43654812020-09-25 01:35:35 +02005109 pdu := {
5110 dtap := l3
5111 }
5112 };
5113 BSSAP.receive(exp_data);
5114 setverdict(pass);
5115}
5116
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005117private function f_mt_l3_transceive(RSL_DCHAN_PT rsl := RSL,
5118 template (present) RslLinkId link_id := tr_RslLinkID_DCCH(0),
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005119 template (value) OCT1 dlci := '00'O,
5120 octetstring l3 := '0123456789'O)
5121runs on MSC_ConnHdlr {
5122 BSSAP.send(PDU_BSSAP:{
5123 discriminator := '1'B,
5124 spare := '0000000'B,
5125 dlci := dlci,
5126 lengthIndicator := lengthof(l3),
5127 pdu := {
5128 dtap := l3
5129 }
5130 });
Neels Hofmeyr0aa719b2020-10-12 18:43:09 +00005131 rsl.receive(tr_RSL_DATA_REQ(g_chan_nr, link_id, l3));
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07005132 setverdict(pass);
5133}
5134
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005135/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
5136 * simply never sends a BSSMAP Handover Command. */
5137private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005138 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005139
5140 var PDU_BSSAP ass_req := f_gen_ass_req();
5141 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5142 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5143 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5144 f_establish_fully(ass_req, exp_compl);
5145
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005146 f_bts_0_cfg(BSCVTY, {"neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005147 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5148
5149 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5150
5151 /* osmo-bsc should time out 10 seconds after the handover started.
5152 * Let's give it a bit extra. */
5153 f_sleep(15.0);
5154
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005155 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005156 f_sleep(1.0);
5157}
5158testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
5159 var MSC_ConnHdlr vc_conn;
5160
5161 f_init(1, true);
5162 f_sleep(1.0);
5163
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005164 f_ctrs_bsc_and_bts_init();
5165
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005166 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
5167 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005168
5169 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5170 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5171 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5172 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5173 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5174 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5175 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005176 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005177}
5178
5179/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
5180 * RR Handover Failure. */
5181private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005182 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005183
5184 var PDU_BSSAP ass_req := f_gen_ass_req();
5185 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5186 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5187 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5188 f_establish_fully(ass_req, exp_compl);
5189
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005190 f_bts_0_cfg(BSCVTY, {"neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005191 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5192
5193 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5194
5195 f_sleep(0.5);
5196 /* The MSC negotiates Handover Request and Handover Request Ack with
5197 * the other BSS and comes back with a BSSMAP Handover Command
5198 * containing an RR Handover Command coming from the target BSS... */
5199
5200 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5201 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5202 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5203 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5204 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5205
5206 /* expect the Handover Command to go out on RR */
5207 var RSL_Message rsl_ho_cmd
5208 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5209 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5210 var RSL_IE_Body rsl_ho_cmd_l3;
5211 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5212 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5213 setverdict(fail);
5214 } else {
5215 log("Found L3 Info: ", rsl_ho_cmd_l3);
5216 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5217 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5218 setverdict(fail);
5219 } else {
5220 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5221 setverdict(pass);
5222 }
5223 }
5224
5225 f_sleep(0.2);
5226 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
5227
5228 /* Should tell the MSC about the failure */
5229 BSSAP.receive(tr_BSSMAP_HandoverFailure);
5230
5231 f_sleep(1.0);
5232
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07005233 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005234 f_sleep(1.0);
5235
5236 setverdict(pass);
5237 f_sleep(1.0);
5238}
5239testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
5240 var MSC_ConnHdlr vc_conn;
5241
5242 f_init(1, true);
5243 f_sleep(1.0);
5244
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005245 f_ctrs_bsc_and_bts_init();
5246
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005247 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
5248 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005249
5250 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5251 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5252 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5253 f_ctrs_bsc_and_bts_add(0, "handover:failed");
5254 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5255 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:failed");
5256 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005257 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005258}
5259
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005260/* BSC asks for inter-BSC-out HO, receives BSSMAP Handover Command, but then no reply is received about HO outcome
5261 * (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 +02005262 * and the lchan is released. */
5263private function f_tc_ho_out_fail_no_result_after_ho_cmd(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01005264 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005265
5266 var PDU_BSSAP ass_req := f_gen_ass_req();
5267 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5268 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5269 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5270 f_establish_fully(ass_req, exp_compl);
5271
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005272 f_bts_0_cfg(BSCVTY, {"neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005273 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
5274
5275 BSSAP.receive(tr_BSSMAP_HandoverRequired);
5276
5277 f_sleep(0.5);
5278 /* The MSC negotiates Handover Request and Handover Request Ack with
5279 * the other BSS and comes back with a BSSMAP Handover Command
5280 * containing an RR Handover Command coming from the target BSS... */
5281
5282 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
5283 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
5284 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
5285 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
5286 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
5287
5288 /* expect the Handover Command to go out on RR */
5289 var RSL_Message rsl_ho_cmd
5290 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
5291 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
5292 var RSL_IE_Body rsl_ho_cmd_l3;
5293 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
5294 log("RSL message contains no L3 Info IE, expected RR Handover Command");
5295 setverdict(fail);
5296 } else {
5297 log("Found L3 Info: ", rsl_ho_cmd_l3);
5298 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
5299 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
5300 setverdict(fail);
5301 } else {
5302 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
5303 setverdict(pass);
5304 }
5305 }
5306
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02005307 /* We get neither success nor failure report from the remote BSS. Eventually T8 times out and we run into 3GPP
5308 * TS 48.008 3.1.5.3.3 "Abnormal Conditions": Clear Request should go to the MSC, and RR should be released
5309 * after Clear Command */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005310
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005311 var PDU_BSSAP rx_clear_request;
Neels Hofmeyre1797aa2019-07-09 19:34:04 +02005312 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
5313 log("Got BSSMAP Clear Request");
5314 /* Instruct BSC to clear channel */
5315 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5316 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5317
5318 var MgcpCommand mgcp;
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005319 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01005320 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
5321 log("Got Deact SACCH");
5322 }
Harald Welte924b6ea2019-02-04 01:05:34 +01005323 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01005324 log("Got RR Release");
5325 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005326 [] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
5327 log("Got RF Chan Rel");
5328 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
5329 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005330 }
5331
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005332 f_expect_dlcx_conns();
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005333
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005334 setverdict(pass);
5335 f_sleep(1.0);
5336}
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02005337testcase TC_ho_out_fail_no_result_after_ho_cmd() runs on test_CT {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005338 var MSC_ConnHdlr vc_conn;
5339
5340 f_init(1, true);
5341 f_sleep(1.0);
5342
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005343 f_ctrs_bsc_and_bts_init();
5344
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02005345 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_result_after_ho_cmd));
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005346 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005347
5348 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5349 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5350 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5351 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5352 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5353 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5354 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005355 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02005356}
5357
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005358private 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 +01005359 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
5360 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
5361 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
5362 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
5363 * before we get started. */
5364 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
5365 f_rslem_register(0, new_chan_nr);
5366 g_chan_nr := new_chan_nr;
5367 f_sleep(1.0);
5368
5369 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
5370 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
5371 activate(as_Media());
5372
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005373 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005374 f_gen_handover_req(aoip_tla := g_pars.host_aoip_tla,
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02005375 oldToNewBSSIEs := oldToNewBSSIEs,
5376 enc := g_pars.encr)));
Harald Welte6811d102019-04-14 22:23:14 +02005377 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005378
5379 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
5380
5381 var PDU_BSSAP rx_bssap;
5382 var octetstring ho_command_str;
5383
5384 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
Pau Espin Pedrol76ba5412019-06-10 11:00:33 +02005385
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02005386 /* we're sure that the channel activation is done now, verify the encryption parameters in it */
5387 f_verify_encr_info(f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr));
5388
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005389 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
5390 log("Received L3 Info in HO Request Ack: ", ho_command_str);
5391 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
5392 log("L3 Info in HO Request Ack is ", ho_command);
5393
5394 var GsmArfcn arfcn;
5395 var RslChannelNr actual_new_chan_nr;
5396 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
5397 actual_new_chan_nr, arfcn);
5398
5399 if (actual_new_chan_nr != new_chan_nr) {
5400 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
5401 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
5402 setverdict(fail);
5403 return;
5404 }
5405 log("Handover Command chan_nr is", actual_new_chan_nr);
5406
5407 /* Now the MSC forwards the RR Handover Command to the other BSC, which
5408 * tells the MS to handover to the new lchan. Here comes the new MS on
5409 * the new lchan with a Handover RACH: */
5410
5411 /* send handover detect */
5412
5413 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
5414
5415 BSSAP.receive(tr_BSSMAP_HandoverDetect);
5416
5417 /* send handover complete over the new channel */
5418
5419 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
5420 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
5421 enc_PDU_ML3_MS_NW(l3_tx)));
5422
5423 BSSAP.receive(tr_BSSMAP_HandoverComplete);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005424 setverdict(pass);
5425}
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005426
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005427private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005428 var template PDU_ML3_NW_MS exp_rr_rel_tmpl;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005429 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs := omit;
5430 if (not istemplatekind(g_pars.last_used_eutran_plmn, "omit")) {
5431 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005432 }
5433 if (g_pars.exp_fast_return) {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005434 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE_CellSelectInd;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005435 } else {
5436 exp_rr_rel_tmpl := tr_RRM_RR_RELEASE;
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005437 }
5438 f_ho_into_this_bsc(id, oldToNewBSSIEs);
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005439 f_perform_clear(RSL, exp_rr_rel_tmpl);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005440 setverdict(pass);
5441}
Pau Espin Pedrol07866632020-09-03 19:10:55 +02005442function f_tc_ho_into_this_bsc_main(TestHdlrParams pars) runs on test_CT {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005443 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005444
5445 f_init(1, true);
5446 f_sleep(1.0);
5447
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005448 f_ctrs_bsc_and_bts_init();
5449
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005450 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
5451 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005452
5453 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
5454 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005455
5456 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5457 f_ctrs_bsc_and_bts_add(0, "handover:completed");
5458 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
5459 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed");
5460 f_ctrs_bsc_and_bts_verify();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005461}
5462
Pau Espin Pedrol07866632020-09-03 19:10:55 +02005463testcase TC_ho_into_this_bsc() runs on test_CT {
5464 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5465 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005466 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02005467}
5468
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02005469function f_tc_ho_into_this_bsc_a5(OCT1 encr_alg) runs on test_CT {
5470 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5471 pars.encr := valueof(t_EncrParams(encr_alg, f_rnd_octstring(8), f_rnd_octstring(16)));
5472 f_tc_ho_into_this_bsc_main(pars);
5473 f_shutdown_helper();
5474}
5475
5476testcase TC_ho_into_this_bsc_a5_0() runs on test_CT {
5477 f_tc_ho_into_this_bsc_a5('01'O);
5478}
5479
5480testcase TC_ho_into_this_bsc_a5_1() runs on test_CT {
5481 f_tc_ho_into_this_bsc_a5('02'O);
5482}
5483
5484testcase TC_ho_into_this_bsc_a5_3() runs on test_CT {
5485 f_tc_ho_into_this_bsc_a5('08'O);
5486}
5487
5488testcase TC_ho_into_this_bsc_a5_4() runs on test_CT {
5489 f_tc_ho_into_this_bsc_a5('10'O);
5490}
5491
Pau Espin Pedrol07866632020-09-03 19:10:55 +02005492testcase TC_ho_into_this_bsc_tla_v6() runs on test_CT {
5493 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5494 pars.host_aoip_tla := "::6";
5495 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005496 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02005497}
5498
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005499/* Similar to TC_ho_into_this_bsc, but when in SRVCC, HO Req contains "Old BSS
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005500 to New BSS Information" IE with "Last Used E-UTRAN PLMN Id", which, when the
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005501 channel is later released (RR CHannel Release), should trigger inclusion of
5502 IE "Cell Selection Indicator after Release of all TCH and SDCCH" with E-UTRAN
5503 neighbors. */
5504testcase TC_srvcc_eutran_to_geran() runs on test_CT {
5505 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5506 pars.last_used_eutran_plmn := '323454'O;
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005507 pars.exp_fast_return := true;
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005508 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02005509
5510 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted");
5511 f_ctrs_bsc_and_bts_add(0, "srvcc:completed");
5512 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02005513 f_shutdown_helper();
5514}
5515
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005516/* Same as TC_srvcc_eutran_to_geran, but test explicitly forbiding fast return
5517 on the BTS. As a result, RR Release shouldn't contain the EUTRAN neighbor
5518 list when the channel is released. */
5519testcase TC_srvcc_eutran_to_geran_forbid_fast_return() runs on test_CT {
5520 f_init_vty();
5521 f_vty_allow_srvcc_fast_return(true, 0)
5522
5523 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5524 pars.last_used_eutran_plmn := '323454'O;
5525 pars.exp_fast_return := false;
5526 f_tc_ho_into_this_bsc_main(pars);
5527 f_vty_allow_srvcc_fast_return(false, 0);
5528 f_shutdown_helper();
5529}
5530
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005531private function f_tc_srvcc_eutran_to_geran_ho_out(charstring id) runs on MSC_ConnHdlr {
5532 var template (omit) BSSMAP_oldToNewBSSIEs oldToNewBSSIEs;
5533 oldToNewBSSIEs := f_ts_BSSMAP_oldToNewBSSIEs(ts_BSSMAP_LastUsedEUTRANPLMNId(g_pars.last_used_eutran_plmn));
5534 f_ho_into_this_bsc(id, oldToNewBSSIEs);
5535 f_ho_out_of_this_bsc(oldToNewBSSIEs);
5536 setverdict(pass);
5537}
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005538
5539private function f_tc_srvcc_eutran_to_geran_ho_out_main(boolean disable_fast_return)
5540 runs on test_CT {
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005541 var MSC_ConnHdlr vc_conn;
5542 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5543
5544 f_init(1, true);
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005545 if (disable_fast_return) {
5546 f_vty_allow_srvcc_fast_return(true, 0);
5547 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005548 f_sleep(1.0);
5549
5550 f_ctrs_bsc_and_bts_init();
5551
5552 pars.last_used_eutran_plmn := '323454'O;
5553 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
5554 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
5555
5556 vc_conn := f_start_handler(refers(f_tc_srvcc_eutran_to_geran_ho_out), pars);
5557 vc_conn.done;
5558
5559 f_ctrs_bsc_and_bts_add(0, "handover:attempted", 2);
5560 f_ctrs_bsc_and_bts_add(0, "handover:completed", 2);
5561 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted", 1);
5562 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed", 1);
5563 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted", 1);
5564 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed", 1);
Pau Espin Pedrol211a7142021-06-15 16:43:03 +02005565
5566 f_ctrs_bsc_and_bts_add(0, "srvcc:attempted", 1);
5567 f_ctrs_bsc_and_bts_add(0, "srvcc:completed", 1);
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005568 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005569
5570 if (disable_fast_return) {
5571 f_vty_allow_srvcc_fast_return(false, 0);
5572 }
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02005573 f_shutdown_helper();
5574}
5575
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02005576/* First, HO into BSC from EUTRAN (SRVCC): HO Request contains "Old BSS to New
5577 BSS Information" IE with "Last Used E-UTRAN PLMN Id".
5578 Second, HO to another BSC: HO Required contains "Old BSS to New BSS Information"
5579 IE with "Last Used E-UTRAN PLMN Id" from first step. */
5580testcase TC_srvcc_eutran_to_geran_ho_out() runs on test_CT {
5581 f_tc_srvcc_eutran_to_geran_ho_out_main(false);
5582}
5583/* Validate subsequent intra-GSM-HO works the same (with OldBSSToNewBSSInfo IE)
5584 * independently of fast-reture allowed/forbidden in local BTS */
5585testcase TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() runs on test_CT {
5586 f_tc_srvcc_eutran_to_geran_ho_out_main(true);
5587}
5588
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005589private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
5590 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
5591 f_rslem_register(0, new_chan_nr);
5592 g_chan_nr := new_chan_nr;
5593 f_sleep(1.0);
5594
5595 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
5596 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
5597 activate(as_Media());
5598
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005599 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005600 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02005601 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005602
5603 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
5604
5605 var PDU_BSSAP rx_bssap;
5606 var octetstring ho_command_str;
5607
5608 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
5609
5610 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
5611 log("Received L3 Info in HO Request Ack: ", ho_command_str);
5612 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
5613 log("L3 Info in HO Request Ack is ", ho_command);
5614
5615 var GsmArfcn arfcn;
5616 var RslChannelNr actual_new_chan_nr;
5617 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
5618 actual_new_chan_nr, arfcn);
5619
5620 if (actual_new_chan_nr != new_chan_nr) {
5621 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
5622 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
5623 setverdict(fail);
5624 return;
5625 }
5626 log("Handover Command chan_nr is", actual_new_chan_nr);
5627
Neels Hofmeyr61ca08d2019-05-06 23:52:22 +02005628 /* For deterministic test results, give some time for the MGW endpoint to be configured */
5629 f_sleep(1.0);
5630
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005631 /* Now the MSC forwards the RR Handover Command to the other BSC, which
5632 * tells the MS to handover to the new lchan. In this case, the MS
5633 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
5634 * Handover Failure to the MSC. The procedure according to 3GPP TS
5635 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
5636 * BSSMAP Clear Command: */
5637
5638 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
5639 var BssmapCause cause := enum2int(cause_val);
5640 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5641
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005642 f_expect_dlcx_conns();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005643 setverdict(pass);
5644 f_sleep(1.0);
5645
5646 setverdict(pass);
5647}
5648testcase TC_ho_in_fail_msc_clears() runs on test_CT {
5649 var MSC_ConnHdlr vc_conn;
5650 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5651
5652 f_init(1, true);
5653 f_sleep(1.0);
5654
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005655 f_ctrs_bsc_and_bts_init();
5656
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005657 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
5658 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005659
5660 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
5661 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005662
5663 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5664 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
5665 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
5666 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
5667 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005668 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005669}
5670
5671private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
5672 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
5673 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
5674 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
5675 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
5676 * before we get started. */
5677 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
5678 f_rslem_register(0, new_chan_nr);
5679 g_chan_nr := new_chan_nr;
5680 f_sleep(1.0);
5681
5682 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
5683 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
5684 activate(as_Media());
5685
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005686 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005687 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02005688 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005689
5690 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
5691
5692 var PDU_BSSAP rx_bssap;
5693 var octetstring ho_command_str;
5694
5695 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
5696
5697 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
5698 log("Received L3 Info in HO Request Ack: ", ho_command_str);
5699 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
5700 log("L3 Info in HO Request Ack is ", ho_command);
5701
5702 var GsmArfcn arfcn;
5703 var RslChannelNr actual_new_chan_nr;
5704 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
5705 actual_new_chan_nr, arfcn);
5706
5707 if (actual_new_chan_nr != new_chan_nr) {
5708 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
5709 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
5710 setverdict(fail);
5711 return;
5712 }
5713 log("Handover Command chan_nr is", actual_new_chan_nr);
5714
5715 /* Now the MSC forwards the RR Handover Command to the other BSC, which
5716 * tells the MS to handover to the new lchan. Here comes the new MS on
5717 * the new lchan with a Handover RACH: */
5718
5719 /* send handover detect */
5720
5721 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
5722
5723 BSSAP.receive(tr_BSSMAP_HandoverDetect);
5724
5725 /* The MSC chooses to clear the connection now, maybe we got the
5726 * Handover RACH on the new cell but the MS still signaled Handover
5727 * Failure to the old BSS? */
5728
5729 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
5730 var BssmapCause cause := enum2int(cause_val);
5731 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5732
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005733 f_expect_dlcx_conns();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005734 f_sleep(1.0);
5735}
5736testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
5737 var MSC_ConnHdlr vc_conn;
5738 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5739
5740 f_init(1, true);
5741 f_sleep(1.0);
5742
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005743 f_ctrs_bsc_and_bts_init();
5744
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005745 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
5746 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005747
5748 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
5749 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005750
5751 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5752 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
5753 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
5754 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
5755 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005756 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005757}
5758
5759/* The new BSS's lchan times out before the MSC decides that handover failed. */
5760private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
5761 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
5762 f_rslem_register(0, new_chan_nr);
5763 g_chan_nr := new_chan_nr;
5764 f_sleep(1.0);
5765
5766 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
5767 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
5768 activate(as_Media());
5769
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005770 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005771 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02005772 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005773
5774 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
5775
5776 var PDU_BSSAP rx_bssap;
5777 var octetstring ho_command_str;
5778
5779 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
5780
5781 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
5782 log("Received L3 Info in HO Request Ack: ", ho_command_str);
5783 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
5784 log("L3 Info in HO Request Ack is ", ho_command);
5785
5786 var GsmArfcn arfcn;
5787 var RslChannelNr actual_new_chan_nr;
5788 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
5789 actual_new_chan_nr, arfcn);
5790
5791 if (actual_new_chan_nr != new_chan_nr) {
5792 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
5793 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
5794 setverdict(fail);
5795 return;
5796 }
5797 log("Handover Command chan_nr is", actual_new_chan_nr);
5798
5799 /* Now the MSC forwards the RR Handover Command to the other BSC, which
5800 * tells the MS to handover to the new lchan. But the MS never shows up
5801 * on the new lchan. */
5802
5803 BSSAP.receive(tr_BSSMAP_HandoverFailure);
5804
5805 /* Did osmo-bsc also send a Clear Request? */
5806 timer T := 0.5;
5807 T.start;
5808 alt {
5809 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
5810 [] T.timeout { }
5811 }
5812
5813 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
5814 * asked for it, this is a Handover Failure after all). */
5815
5816 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
5817 var BssmapCause cause := enum2int(cause_val);
5818 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5819
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005820 f_expect_dlcx_conns();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005821 f_sleep(1.0);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005822}
5823testcase TC_ho_in_fail_no_detect() runs on test_CT {
5824 var MSC_ConnHdlr vc_conn;
5825 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5826
5827 f_init(1, true);
5828 f_sleep(1.0);
5829
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005830 f_ctrs_bsc_and_bts_init();
5831
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005832 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
5833 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005834
5835 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
5836 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005837
5838 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5839 f_ctrs_bsc_and_bts_add(0, "handover:error");
5840 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
5841 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
5842 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005843 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005844}
5845
5846/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
5847private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
5848 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
5849 f_rslem_register(0, new_chan_nr);
5850 g_chan_nr := new_chan_nr;
5851 f_sleep(1.0);
5852
5853 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
5854 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
5855 activate(as_Media());
5856
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005857 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005858 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02005859 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005860
5861 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
5862
5863 var PDU_BSSAP rx_bssap;
5864 var octetstring ho_command_str;
5865
5866 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
5867
5868 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
5869 log("Received L3 Info in HO Request Ack: ", ho_command_str);
5870 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
5871 log("L3 Info in HO Request Ack is ", ho_command);
5872
5873 var GsmArfcn arfcn;
5874 var RslChannelNr actual_new_chan_nr;
5875 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
5876 actual_new_chan_nr, arfcn);
5877
5878 if (actual_new_chan_nr != new_chan_nr) {
5879 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
5880 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
5881 setverdict(fail);
5882 return;
5883 }
5884 log("Handover Command chan_nr is", actual_new_chan_nr);
5885
5886 /* Now the MSC forwards the RR Handover Command to the other BSC, which
5887 * tells the MS to handover to the new lchan. But the MS never shows up
5888 * on the new lchan. */
5889
5890 BSSAP.receive(tr_BSSMAP_HandoverFailure);
5891
5892 /* MSC plays dumb and sends no Clear Command */
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005893 var PDU_BSSAP rx_clear_request;
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005894
5895 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005896 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5897 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5898 };
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005899 f_expect_dlcx_conns();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005900 f_sleep(1.0);
5901}
5902testcase TC_ho_in_fail_no_detect2() runs on test_CT {
5903 var MSC_ConnHdlr vc_conn;
5904 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5905
5906 f_init(1, true);
5907 f_sleep(1.0);
5908
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005909 f_ctrs_bsc_and_bts_init();
5910
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005911 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
5912 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005913
5914 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
5915 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005916
5917 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5918 f_ctrs_bsc_and_bts_add(0, "handover:error");
5919 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
5920 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
5921 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005922 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005923}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005924
Neels Hofmeyr91401012019-07-11 00:42:35 +02005925type record of charstring Commands;
5926
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005927private function f_bts_0_cfg(TELNETasp_PT pt, Commands cmds := {})
Neels Hofmeyr91401012019-07-11 00:42:35 +02005928{
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005929 f_vty_enter_cfg_bts(pt, 0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02005930 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005931 f_vty_transceive(pt, cmds[i]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02005932 }
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005933 f_vty_transceive(pt, "end");
Neels Hofmeyr91401012019-07-11 00:42:35 +02005934}
5935
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01005936private function f_cs7_inst_0_cfg(TELNETasp_PT pt, Commands cmds := {})
5937{
5938 f_vty_enter_cfg_cs7_inst(pt, 0);
5939 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
5940 f_vty_transceive(pt, cmds[i]);
5941 }
5942 f_vty_transceive(pt, "end");
5943}
5944
Neels Hofmeyr91401012019-07-11 00:42:35 +02005945private function f_probe_for_handover(charstring log_label,
5946 charstring log_descr,
5947 charstring handover_vty_cmd,
5948 boolean expect_handover,
5949 boolean is_inter_bsc_handover := false)
5950runs on MSC_ConnHdlr
5951{
Neels Hofmeyrb3fc8982020-05-11 00:16:42 +02005952 /* We're going to thwart any and all handover attempts, just be ready to handle (and ignore) handover target
5953 * lchans to be established on bts 1 or bts 2. */
5954 f_rslem_suspend(RSL1_PROC);
5955 f_rslem_suspend(RSL2_PROC);
5956
Neels Hofmeyr91401012019-07-11 00:42:35 +02005957 var RSL_Message rsl;
5958
5959 var charstring log_msg := " (expecting handover)"
5960 if (not expect_handover) {
5961 log_msg := " (expecting NO handover)";
5962 }
5963 log("f_probe_for_handover starting: " & log_label & ": " & log_descr & log_msg);
5964 f_vty_transceive(BSCVTY, handover_vty_cmd);
5965
Neels Hofmeyr91401012019-07-11 00:42:35 +02005966 timer T := 2.0;
5967 T.start;
5968
5969 alt {
5970 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
5971 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
5972 log("Rx L3 from net: ", l3);
5973 if (ischosen(l3.msgs.rrm.handoverCommand)) {
5974 var RslChannelNr new_chan_nr;
5975 var GsmArfcn arfcn;
5976 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
5977 new_chan_nr, arfcn);
5978 log("Handover to new chan ", new_chan_nr, " on ARFCN ", arfcn);
5979 log(l3.msgs.rrm.handoverCommand);
5980
5981 /* Need to register for new lchan on new BTS -- it's either bts 1 or bts 2. It doesn't really
5982 * matter on which BTS it really is, we're not going to follow through an entire handover
5983 * anyway. */
5984 f_rslem_register(0, new_chan_nr, RSL1_PROC);
5985 f_rslem_resume(RSL1_PROC);
5986 f_rslem_register(0, new_chan_nr, RSL2_PROC);
5987 f_rslem_resume(RSL2_PROC);
5988
5989 if (expect_handover and not is_inter_bsc_handover) {
5990 setverdict(pass);
5991 log("f_probe_for_handover(" & log_label & "): Got RSL Handover Command as expected.");
5992 } else {
5993 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got RSL Handover Command. "
5994 & log_label & ": " & log_descr);
5995 }
5996
5997 log("f_probe_for_handover(" & log_label & "): Ending the test: Handover Failure stops the procedure.");
5998 /* osmo-bsc has triggered Handover. That's all we need to know for this test, reply with
5999 * Handover Failure. */
6000 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
6001
6002 /* target BTS is told to release lchan again; don't care which BTS nor what messages. */
6003 f_sleep(0.5);
6004 RSL1.clear;
6005 RSL2.clear;
6006 log("f_probe_for_handover(" & log_label & "): done (got RSL Handover Command)");
6007 break;
6008 } else {
6009 repeat;
6010 }
6011 }
6012 [] BSSAP.receive(tr_BSSMAP_HandoverRequired) {
6013 if (expect_handover and is_inter_bsc_handover) {
6014 setverdict(pass);
6015 log("f_probe_for_handover(" & log_label & "): Got BSSMAP Handover Required as expected.");
6016 } else {
6017 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got BSSMAP Handover Required. "
6018 & log_label & ": " & log_descr);
6019 }
6020
6021 log("f_probe_for_handover(" & log_label & "): done (got BSSMAP Handover Required)");
6022
6023 /* Note: f_tc_ho_neighbor_config_start() sets T7, the timeout for BSSMAP Handover Required, to
6024 * 1 second. There is no legal way to quickly abort a handover after a BSSMAP Handover Required,
6025 * setting a short timeout and waiting is the only way. */
6026 log("f_probe_for_handover(" & log_label & "): waiting for inter-BSC HO to time out...");
6027 f_sleep(1.5);
6028 log("f_probe_for_handover(" & log_label & "): ...done");
6029
6030 break;
6031 }
6032 [] T.timeout {
6033 if (expect_handover) {
6034 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected Handover, but got none. "
6035 & log_label & ": " & log_descr);
6036 } else {
6037 setverdict(pass);
6038 log("f_probe_for_handover(" & log_label & "): Got no Handover, as expected.");
6039 }
6040 log("f_probe_for_handover(" & log_label & "): done (got no Handover)");
6041 break;
6042 }
6043 }
6044
6045 f_rslem_resume(RSL1_PROC);
6046 f_rslem_resume(RSL2_PROC);
6047 f_sleep(3.0);
6048 RSL.clear;
6049
6050 log("f_probe_for_handover(" & log_label & "): done clearing");
6051}
6052
6053/* Test the effect of various neighbor configuration scenarios:
6054 *
6055 * To avoid complexity, block off any actual handover operation, and always remain on the lchan at bts 0.
6056 * Reconfigure the neighbors for bts 0, trigger a Handover, and probe whether osmo-bsc does or doesn't start HO.
6057 */
6058private function f_tc_ho_neighbor_config_start() runs on MSC_ConnHdlr {
6059 g_pars := f_gen_test_hdlr_pars();
6060 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
6061 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006062
6063 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
6064 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
6065
6066 /* Establish lchan at bts 0 */
6067 f_establish_fully(ass_cmd, exp_compl);
6068
6069 /* Shorten the inter-BSC Handover timeout, to not wait so long for inter-BSC Handovers */
6070 f_vty_enter_cfg_network(BSCVTY);
6071 f_vty_transceive(BSCVTY, "timer T7 1");
6072 f_vty_transceive(BSCVTY, "end");
6073}
6074
6075private function f_tc_ho_neighbor_config_1(charstring id) runs on MSC_ConnHdlr {
6076 f_tc_ho_neighbor_config_start();
6077
6078 /*
6079 * bts 0 ARFCN 871 BSIC 10
6080 * bts 1 ARFCN 871 BSIC 11
6081 * bts 2 ARFCN 871 BSIC 12
6082 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6083 */
6084
6085 log("f_tc_ho_neighbor_config: 1. No 'neighbor' config");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006086 f_bts_0_cfg(BSCVTY, {"no neighbors"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006087 f_probe_for_handover("1.a", "HO to bts 1 works, implicitly listed as neighbor (legacy behavior when none are configured)",
6088 "handover any to arfcn 871 bsic 11",
6089 true);
6090
6091 f_probe_for_handover("1.b", "HO to unknown cell does not start",
6092 "handover any to arfcn 13 bsic 39",
6093 false);
6094
6095 f_probe_for_handover("1.c", "HO to 871-12 is ambiguous = error",
6096 "handover any to arfcn 871 bsic 12",
6097 false);
6098
6099 f_probe_for_handover("1.d", "HO to 871-11 still works (verify that this test properly cleans up)",
6100 "handover any to arfcn 871 bsic 11",
6101 true);
6102}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006103testcase TC_ho_neighbor_config_1() runs on test_CT {
6104 var MSC_ConnHdlr vc_conn;
6105 f_init(3, true, guard_timeout := 60.0);
6106 f_sleep(1.0);
6107 f_ctrs_bsc_and_bts_init();
6108 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_1));
6109 vc_conn.done;
6110
6111 /* f_tc_ho_neighbor_config_start() */
6112 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6113 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6114
6115 /* 1.a */
6116 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6117 * handover quickly by sending a Handover Failure message. */
6118 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6119 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6120 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6121 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
6122
6123 /* 1.b */
6124 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6125 f_ctrs_bsc_and_bts_add(0, "handover:error");
6126
6127 /* 1.c */
6128 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6129 f_ctrs_bsc_and_bts_add(0, "handover:error");
6130
6131 /* 1.d */
6132 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6133 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6134 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6135 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
6136
6137 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006138 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006139}
6140
Neels Hofmeyr91401012019-07-11 00:42:35 +02006141private function f_tc_ho_neighbor_config_2(charstring id) runs on MSC_ConnHdlr {
6142 f_tc_ho_neighbor_config_start();
6143
6144 /*
6145 * bts 0 ARFCN 871 BSIC 10
6146 * bts 1 ARFCN 871 BSIC 11
6147 * bts 2 ARFCN 871 BSIC 12
6148 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6149 */
6150
6151 log("f_tc_ho_neighbor_config: 2. explicit local neighbor: 'neighbor bts 1'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006152 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006153 f_sleep(0.5);
6154
6155 f_probe_for_handover("2.a", "HO to bts 1 works, explicitly listed as neighbor",
6156 "handover any to arfcn 871 bsic 11",
6157 true);
6158
6159 f_probe_for_handover("2.b", "HO to bts 2 doesn't work, not listed as neighbor",
6160 "handover any to arfcn 871 bsic 12",
6161 false);
6162}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006163testcase TC_ho_neighbor_config_2() runs on test_CT {
6164 var MSC_ConnHdlr vc_conn;
6165 f_init(3, true, guard_timeout := 50.0);
6166 f_sleep(1.0);
6167 f_ctrs_bsc_and_bts_init();
6168 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_2));
6169 vc_conn.done;
6170
6171 /* f_tc_ho_neighbor_config_start() */
6172 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6173 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6174
6175 /* 2.a */
6176 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6177 * handover quickly by sending a Handover Failure message. */
6178 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6179 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6180 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6181 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
6182
6183 /* 2.b */
6184 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6185 f_ctrs_bsc_and_bts_add(0, "handover:error");
6186
6187 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006188 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006189}
6190
Neels Hofmeyr91401012019-07-11 00:42:35 +02006191private function f_tc_ho_neighbor_config_3(charstring id) runs on MSC_ConnHdlr {
6192 f_tc_ho_neighbor_config_start();
6193
6194 /*
6195 * bts 0 ARFCN 871 BSIC 10
6196 * bts 1 ARFCN 871 BSIC 11
6197 * bts 2 ARFCN 871 BSIC 12
6198 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6199 */
6200
6201 log("f_tc_ho_neighbor_config: 3. explicit local neighbor: 'neighbor bts 2'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006202 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006203 f_sleep(0.5);
6204
6205 f_probe_for_handover("3.a", "HO to bts 1 doesn't work, not listed as neighbor",
6206 "handover any to arfcn 871 bsic 11",
6207 false);
6208 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",
6209 "handover any to arfcn 871 bsic 12",
6210 true);
6211}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006212testcase TC_ho_neighbor_config_3() runs on test_CT {
6213 var MSC_ConnHdlr vc_conn;
6214 f_init(3, true, guard_timeout := 50.0);
6215 f_sleep(1.0);
6216 f_ctrs_bsc_and_bts_init();
6217 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_3));
6218 vc_conn.done;
6219
6220 /* f_tc_ho_neighbor_config_start() */
6221 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6222 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6223
6224 /* 3.a */
6225 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6226 f_ctrs_bsc_and_bts_add(0, "handover:error");
6227
6228 /* 3.b */
6229 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6230 * handover quickly by sending a Handover Failure message. */
6231 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6232 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6233 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6234 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
6235
6236 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006237 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006238}
6239
Neels Hofmeyr91401012019-07-11 00:42:35 +02006240private function f_tc_ho_neighbor_config_4(charstring id) runs on MSC_ConnHdlr {
6241 f_tc_ho_neighbor_config_start();
6242
6243 /*
6244 * bts 0 ARFCN 871 BSIC 10
6245 * bts 1 ARFCN 871 BSIC 11
6246 * bts 2 ARFCN 871 BSIC 12
6247 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6248 */
6249
6250 log("f_tc_ho_neighbor_config: 4. explicit remote neighbor: 'neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006251 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006252 f_sleep(0.5);
6253
6254 f_probe_for_handover("4.a", "HO to bts 1 doesn't work, not listed as neighbor",
6255 "handover any to arfcn 871 bsic 11",
6256 false);
6257 f_probe_for_handover("4.b", "HO to bts 2 doesn't work, not listed as neighbor",
6258 "handover any to arfcn 871 bsic 12",
6259 false);
6260 f_probe_for_handover("4.c", "HO to 123-45 triggers inter-BSC HO",
6261 "handover any to arfcn 123 bsic 45",
6262 true, true);
6263}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006264testcase TC_ho_neighbor_config_4() runs on test_CT {
6265 var MSC_ConnHdlr vc_conn;
6266 f_init(3, true, guard_timeout := 50.0);
6267 f_sleep(1.0);
6268 f_ctrs_bsc_and_bts_init();
6269 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_4));
6270 vc_conn.done;
6271
6272 /* f_tc_ho_neighbor_config_start() */
6273 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6274 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6275
6276 /* 4.a */
6277 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6278 f_ctrs_bsc_and_bts_add(0, "handover:error");
6279
6280 /* 4.b */
6281 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6282 f_ctrs_bsc_and_bts_add(0, "handover:error");
6283
6284 /* 4.c */
6285 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6286 * handover quickly by timing out after the Handover Required message */
6287 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6288 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
6289 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
6290 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
6291
6292 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006293 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006294}
6295
Neels Hofmeyr91401012019-07-11 00:42:35 +02006296private function f_tc_ho_neighbor_config_5(charstring id) runs on MSC_ConnHdlr {
6297 f_tc_ho_neighbor_config_start();
6298
6299 /*
6300 * bts 0 ARFCN 871 BSIC 10
6301 * bts 1 ARFCN 871 BSIC 11
6302 * bts 2 ARFCN 871 BSIC 12
6303 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6304 */
6305
6306 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 +02006307 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006308 f_sleep(0.5);
6309
6310 f_probe_for_handover("5.a", "HO to 871-12 triggers inter-BSC HO (ignoring local cells with same ARFCN+BSIC)",
6311 "handover any to arfcn 871 bsic 12",
6312 true, true);
6313}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006314testcase TC_ho_neighbor_config_5() runs on test_CT {
6315 var MSC_ConnHdlr vc_conn;
6316 f_init(3, true);
6317 f_sleep(1.0);
6318 f_ctrs_bsc_and_bts_init();
6319 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_5));
6320 vc_conn.done;
6321
6322 /* f_tc_ho_neighbor_config_start() */
6323 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6324 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6325
6326 /* 5 */
6327 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6328 * handover quickly by timing out after the Handover Required message */
6329 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6330 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
6331 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
6332 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
6333
6334 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006335 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006336}
6337
Neels Hofmeyr91401012019-07-11 00:42:35 +02006338private function f_tc_ho_neighbor_config_6(charstring id) runs on MSC_ConnHdlr {
6339 f_tc_ho_neighbor_config_start();
6340
6341 /*
6342 * bts 0 ARFCN 871 BSIC 10
6343 * bts 1 ARFCN 871 BSIC 11
6344 * bts 2 ARFCN 871 BSIC 12
6345 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6346 */
6347
6348 log("f_tc_ho_neighbor_config: 6. config error: explicit local and remote neighbors with ambiguous ARFCN+BSIC:"
6349 & " 'neighbor bts 2; neighbor lac 99 arfcn 871 bsic 12'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006350 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006351 f_sleep(0.5);
6352
6353 f_probe_for_handover("6.a", "HO to 871-12 is ambiguous = error",
6354 "handover any to arfcn 871 bsic 12",
6355 false);
6356}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006357testcase TC_ho_neighbor_config_6() runs on test_CT {
6358 var MSC_ConnHdlr vc_conn;
6359 f_init(3, true);
6360 f_sleep(1.0);
6361 f_ctrs_bsc_and_bts_init();
6362 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_6));
6363 vc_conn.done;
6364
6365 /* f_tc_ho_neighbor_config_start() */
6366 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6367 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6368
6369 /* 6.a */
6370 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6371 * handover quickly by timing out after the Handover Required message */
6372 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6373 f_ctrs_bsc_and_bts_add(0, "handover:error");
6374
6375 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006376 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006377}
6378
Neels Hofmeyr91401012019-07-11 00:42:35 +02006379private function f_tc_ho_neighbor_config_7(charstring id) runs on MSC_ConnHdlr {
6380 f_tc_ho_neighbor_config_start();
6381
6382 /*
6383 * bts 0 ARFCN 871 BSIC 10
6384 * bts 1 ARFCN 871 BSIC 11
6385 * bts 2 ARFCN 871 BSIC 12
6386 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
6387 */
6388
6389 log("f_tc_ho_neighbor_config: 7. explicit local and remote neighbors:"
6390 & " 'neighbor bts 2; neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02006391 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02006392 f_sleep(0.5);
6393
6394 f_probe_for_handover("7.a", "HO to 871-12 does HO to bts 2",
6395 "handover any to arfcn 871 bsic 12",
6396 true);
6397 f_probe_for_handover("7.b", "HO to 123-45 triggers inter-BSC HO",
6398 "handover any to arfcn 123 bsic 45",
6399 true, true);
6400}
Neels Hofmeyr91401012019-07-11 00:42:35 +02006401testcase TC_ho_neighbor_config_7() runs on test_CT {
6402 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf2b88032020-06-16 00:35:04 +02006403 f_init(3, true, guard_timeout := 50.0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02006404 f_sleep(1.0);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006405 f_ctrs_bsc_and_bts_init();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006406 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_7));
6407 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00006408
6409 /* f_tc_ho_neighbor_config_start() */
6410 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
6411 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
6412
6413 /* 7.a */
6414 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
6415 * handover quickly by sending a Handover Failure message. */
6416 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6417 f_ctrs_bsc_and_bts_add(0, "handover:failed");
6418 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
6419 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
6420
6421 /* 7.b */
6422 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
6423 * handover quickly by timing out after the Handover Required message */
6424 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
6425 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
6426 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
6427 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
6428
6429 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006430 f_shutdown_helper();
Neels Hofmeyr91401012019-07-11 00:42:35 +02006431}
6432
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01006433/* OS#3041: Open and close N connections in a normal fashion, and expect no
6434 * BSSMAP Reset just because of that. */
6435testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
6436 var default d;
6437 var integer i;
6438 var DchanTuple dt;
6439
6440 f_init();
6441
6442 /* Wait for initial BSSMAP Reset to pass */
6443 f_sleep(4.0);
6444
6445 d := activate(no_bssmap_reset());
6446
6447 /* Setup up a number of connections and RLSD them again from the MSC
6448 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
6449 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02006450 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01006451 /* Since we're doing a lot of runs, give each one a fresh
6452 * T_guard from the top. */
6453 T_guard.start;
6454
6455 /* Setup a BSSAP connection and clear it right away. This is
6456 * the MSC telling the BSC about a planned release, it's not an
6457 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02006458 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01006459
6460 /* MSC disconnects (RLSD). */
6461 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
6462 }
6463
6464 /* In the buggy behavior, a timeout of 2 seconds happens between above
6465 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
6466 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
6467 f_sleep(4.0);
6468
6469 deactivate(d);
6470 f_shutdown_helper();
6471}
Harald Welte552620d2017-12-16 23:21:36 +01006472
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01006473/* OS#3041: Open and close N connections in a normal fashion, and expect no
6474 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
6475 * the MSC. */
6476testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
6477 var default d;
6478 var integer i;
6479 var DchanTuple dt;
6480 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01006481 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
6482 var BssmapCause cause := enum2int(cause_val);
6483
6484 f_init();
6485
6486 /* Wait for initial BSSMAP Reset to pass */
6487 f_sleep(4.0);
6488
6489 d := activate(no_bssmap_reset());
6490
6491 /* Setup up a number of connections and RLSD them again from the MSC
6492 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
6493 * Let's do it some more times for good measure. */
6494 for (i := 0; i < 8; i := i+1) {
6495 /* Since we're doing a lot of runs, give each one a fresh
6496 * T_guard from the top. */
6497 T_guard.start;
6498
6499 /* Setup a BSSAP connection and clear it right away. This is
6500 * the MSC telling the BSC about a planned release, it's not an
6501 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02006502 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01006503
6504 /* Instruct BSC to clear channel */
6505 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
6506
6507 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02006508 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01006509 }
6510
6511 /* In the buggy behavior, a timeout of 2 seconds happens between above
6512 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
6513 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
6514 f_sleep(4.0);
6515
6516 deactivate(d);
6517 f_shutdown_helper();
6518}
6519
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01006520/* OS#3041: Open and close N connections in a normal fashion, and expect no
6521 * BSSMAP Reset just because of that. Close connections from the MS side with a
6522 * Release Ind on RSL. */
6523testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
6524 var default d;
6525 var integer i;
6526 var DchanTuple dt;
6527 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01006528 var integer j;
6529
6530 f_init();
6531
6532 /* Wait for initial BSSMAP Reset to pass */
6533 f_sleep(4.0);
6534
6535 d := activate(no_bssmap_reset());
6536
6537 /* Setup up a number of connections and RLSD them again from the MSC
6538 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
6539 * Let's do it some more times for good measure. */
6540 for (i := 0; i < 8; i := i+1) {
6541 /* Since we're doing a lot of runs, give each one a fresh
6542 * T_guard from the top. */
6543 T_guard.start;
6544
6545 /* Setup a BSSAP connection and clear it right away. This is
6546 * the MSC telling the BSC about a planned release, it's not an
6547 * erratic loss of a connection. */
6548 dt := f_est_dchan('23'O, 23, '00010203040506'O);
6549
6550 /* simulate RLL REL IND */
6551 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
6552
6553 /* expect Clear Request on MSC side */
6554 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
6555
6556 /* Instruct BSC to clear channel */
6557 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
6558 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
6559
6560 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02006561 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01006562 }
6563
6564 /* In the buggy behavior, a timeout of 2 seconds happens between above
6565 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
6566 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
6567 f_sleep(4.0);
6568
6569 deactivate(d);
6570 f_shutdown_helper();
6571}
6572
Harald Welte94e0c342018-04-07 11:33:23 +02006573/***********************************************************************
6574 * IPA style dynamic PDCH
6575 ***********************************************************************/
6576
6577private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
6578 template (omit) RSL_Cause nack := omit)
6579runs on test_CT {
6580 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
6581 var RSL_Message rsl_unused;
6582 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
6583 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
6584 /* expect the BSC to issue the related RSL command */
6585 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
6586 if (istemplatekind(nack, "omit")) {
6587 /* respond with a related acknowledgement */
6588 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
6589 } else {
6590 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
6591 }
6592}
6593
6594private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
6595 template (omit) RSL_Cause nack := omit)
6596runs on test_CT {
6597 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
6598 var RSL_Message rsl_unused;
6599 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
6600 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
6601 /* expect the BSC to issue the related RSL command */
6602 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
6603 if (istemplatekind(nack, "omit")) {
6604 /* respond with a related acknowledgement */
6605 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
6606 } else {
6607 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
6608 }
6609}
6610
6611private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
6612runs on test_CT return charstring {
6613 var charstring cmd, resp;
6614 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01006615 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02006616}
6617
6618private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
6619 template charstring exp)
6620runs on test_CT {
6621 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
6622 if (not match(mode, exp)) {
6623 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02006624 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02006625 }
6626}
6627
6628private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
6629runs on test_CT {
6630 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
6631 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
6632 f_vty_transceive(BSCVTY, "end");
6633}
6634
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02006635
6636private function f_ts_reset_chcomb(integer bts_nr) runs on test_CT {
6637 var integer i;
6638 for (i := 0; i < 8; i := i + 1) {
6639 f_ts_set_chcomb(bts_nr, 0, i, phys_chan_config[i]);
6640 }
6641}
6642
Harald Welte94e0c342018-04-07 11:33:23 +02006643private const charstring TCHF_MODE := "TCH/F mode";
6644private const charstring TCHH_MODE := "TCH/H mode";
6645private const charstring PDCH_MODE := "PDCH mode";
6646private const charstring NONE_MODE := "NONE mode";
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02006647private const charstring SDCCH8_MODE := "SDCCH8 mode";
Harald Welte94e0c342018-04-07 11:33:23 +02006648
6649/* Test IPA PDCH activation / deactivation triggered by VTY */
6650testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
6651 var RSL_Message rsl_unused;
6652
6653 /* change Timeslot 6 before f_init() starts RSL */
6654 f_init_vty();
6655 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
6656 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6657
6658 f_init(1, false);
6659 f_sleep(1.0);
6660
6661 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
6662
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02006663 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02006664 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
6665 /* The BSC will activate the dynamic PDCH by default, so confirm that */
6666 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
6667 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
6668 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02006669 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02006670 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
6671
6672 /* De-activate it via VTY */
6673 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
6674 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02006675 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02006676 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
6677
6678 /* re-activate it via VTY */
6679 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
6680 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02006681 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02006682 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
6683
6684 /* and finally de-activate it again */
6685 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
6686 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02006687 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02006688 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
6689
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02006690 /* clean up config */
6691 f_ts_set_chcomb(0, 0, 6, "PDCH");
6692
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006693 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02006694}
6695
6696/* Test IPA PDCH activation NACK */
6697testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
6698 var RSL_Message rsl_unused;
6699
6700 /* change Timeslot 6 before f_init() starts RSL */
6701 f_init_vty();
6702 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
6703 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6704
6705 f_init(1, false);
6706 f_sleep(1.0);
6707
6708 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
6709
6710 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
6711 /* The BSC will activate the dynamic PDCH by default, so confirm that */
6712 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
6713 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
6714 f_sleep(1.0);
6715 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
6716
6717 /* De-activate it via VTY */
6718 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
6719 f_sleep(1.0);
6720 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
6721
6722 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
6723 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
6724 f_sleep(1.0);
6725 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
6726
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02006727 /* clean up config */
6728 f_ts_set_chcomb(0, 0, 6, "PDCH");
6729
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006730 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02006731}
6732
6733
6734/***********************************************************************
6735 * Osmocom style dynamic PDCH
6736 ***********************************************************************/
6737
6738private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
6739 template (omit) RSL_Cause nack := omit)
6740runs on test_CT {
6741 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
6742 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02006743 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02006744 /* FIXME: no VTY command to activate Osmocom PDCH !! */
6745 /* expect the BSC to issue the related RSL command */
6746 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
6747 if (istemplatekind(nack, "omit")) {
6748 /* respond with a related acknowledgement */
6749 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
6750 } else {
6751 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
6752 }
6753}
6754
6755private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
6756 template (omit) RSL_Cause nack := omit)
6757runs on test_CT {
6758 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
6759 var RSL_Message rsl_unused;
Pau Espin Pedrol64adf372021-06-28 16:25:47 +02006760 /* ask BSC via VTY to activate a given OSMO style chan as PDCH */
Harald Welte94e0c342018-04-07 11:33:23 +02006761 /* FIXME: no VTY command to activate Osmocom PDCH !! */
6762 /* expect the BSC to issue the related RSL command */
6763 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
6764 if (istemplatekind(nack, "omit")) {
6765 /* respond with a related acknowledgement */
6766 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
6767 } else {
6768 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
6769 }
6770}
6771
6772/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
6773testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
6774 var RSL_Message rsl_unused;
6775
6776 /* change Timeslot 6 before f_init() starts RSL */
6777 f_init_vty();
6778 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
6779 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6780
6781 f_init(1, false);
6782 f_sleep(1.0);
6783
6784 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
6785
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02006786 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02006787 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
6788 /* The BSC will activate the dynamic PDCH by default, so confirm that */
6789 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
6790
6791 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
6792 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02006793 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 +02006794 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
6795
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02006796 /* clean up config */
6797 f_ts_set_chcomb(0, 0, 6, "PDCH");
6798
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006799 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02006800}
6801
6802/* Test Osmocom dyn PDCH activation NACK behavior */
6803testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
6804 var RSL_Message rsl_unused;
6805
6806 /* change Timeslot 6 before f_init() starts RSL */
6807 f_init_vty();
6808 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
6809 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6810
6811 f_init(1, false);
6812 f_sleep(1.0);
6813
6814 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
6815
6816 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
6817 /* The BSC will activate the dynamic PDCH by default, so confirm that */
6818 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
6819
6820 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
6821 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
6822 f_sleep(1.0);
6823 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
6824
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02006825 /* clean up config */
6826 f_ts_set_chcomb(0, 0, 6, "PDCH");
6827
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006828 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02006829}
6830
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02006831/* Test Osmocom dyn TS SDCCH8 activation / deactivation */
6832testcase TC_dyn_ts_sdcch8_act_deact() runs on test_CT {
6833 var RSL_Message rsl_unused, rsl_msg;
6834 var DchanTuple dt;
6835 var BSSAP_N_CONNECT_ind rx_c_ind;
6836
6837 /* change Timeslot 6 before f_init() starts RSL */
6838 f_init_vty();
6839 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
6840 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6841
6842 f_init(1, false);
6843 f_sleep(1.0);
6844
6845 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
6846
6847 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
6848 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
6849 /* The BSC will activate the dynamic PDCH by default, so confirm that */
6850 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr, ?));
6851
6852 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
6853 f_sleep(1.0);
6854 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
6855 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
6856
6857 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
6858 * on CCCH+SDCCH4+CBCH) */
6859 var integer i;
6860 for (i := 0; i < 3; i := i + 1) {
6861 dt := f_est_dchan('23'O, i, '00010203040506'O);
6862 }
6863
6864 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
6865 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
6866 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
6867 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
6868
6869 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
6870 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
6871
6872 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
6873 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
6874 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
6875 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
6876
6877 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
6878 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
6879 dt.sccp_conn_id := rx_c_ind.connectionId;
6880 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
6881
6882 /* Instruct BSC to clear channel */
6883 var BssmapCause cause := 0;
6884 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
6885 f_exp_chan_rel_and_clear(dt, 0);
6886
6887 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
6888 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr, ?));
6889 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
6890 f_sleep(1.0);
6891 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
6892
6893 /* clean up config */
6894 f_ts_set_chcomb(0, 0, 6, "PDCH");
6895
6896 f_shutdown_helper();
6897}
6898
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02006899/* Test Osmocom dyn TS SDCCH8 activation / deactivation: If activating dyn TS as
6900 SDCCH8 would end up in having no free TCH, then BSC should decide to activate
6901 it as TCH directly instead. SYS#5309. */
6902testcase TC_dyn_ts_sdcch8_tch_call_act_deact() runs on test_CT {
6903 var RSL_Message rsl_unused, rsl_msg;
6904 var DchanTuple dt;
6905 var BSSAP_N_CONNECT_ind rx_c_ind;
6906 var integer i;
6907
6908 /* change Timeslot 6 before f_init() starts RSL */
6909 f_init_vty();
6910 for (i := 1; i < 8; i := i + 1) {
6911 if (i == 6) {
6912 f_ts_set_chcomb(0, 0, i, "TCH/F_TCH/H_SDCCH8_PDCH");
6913 } else {
6914 f_ts_set_chcomb(0, 0, i, "PDCH");
6915 }
6916 }
6917 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6918
6919 f_init(1, false);
6920 f_sleep(1.0);
6921
6922 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
6923
6924 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
6925 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
6926 /* The BSC will activate the dynamic PDCH by default, so confirm that */
6927 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr, ?));
6928
6929 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
6930 f_sleep(1.0);
6931 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
6932 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
6933
6934 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
6935 * on CCCH+SDCCH4+CBCH) */
6936 for (i := 0; i < 3; i := i + 1) {
6937 dt := f_est_dchan('23'O, i, '00010203040506'O);
6938 }
6939
6940 /* Now the dyn ts is selected. First PDCH is released, then TCH chan is activated */
6941 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
6942 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
6943 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
6944
6945 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
6946 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
6947
6948 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
6949 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(dt.rsl_chan_nr, 2342));
6950 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
6951 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, TCHH_MODE);
6952
6953 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), '1234'O));
6954 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3('1234'O))) -> value rx_c_ind;
6955 dt.sccp_conn_id := rx_c_ind.connectionId;
6956 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
6957
6958 /* Instruct BSC to clear channel */
6959 var BssmapCause cause := 0;
6960 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
6961 f_exp_chan_rel_and_clear(dt, 0);
6962
6963 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
6964 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr, ?));
6965 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
6966 f_sleep(1.0);
6967 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
6968
6969 /* clean up config */
6970 f_ts_reset_chcomb(0);
6971 /* TODO: clean up other channels? */
6972
6973 f_shutdown_helper();
6974}
6975
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02006976/* Test Osmocom dyn TS SDCCH8 activation / deactivation when SDCCH fails at BTS */
6977testcase TC_dyn_ts_sdcch8_act_nack() runs on test_CT {
6978 var RSL_Message rsl_unused, rsl_msg;
6979 var DchanTuple dt;
6980 var BSSAP_N_CONNECT_ind rx_c_ind;
6981 var GsmRrMessage rr;
6982
6983 /* change Timeslot 6 before f_init() starts RSL */
6984 f_init_vty();
6985 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_SDCCH8_PDCH");
6986 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6987
6988 f_init(1, false);
6989 f_sleep(1.0);
6990
6991 var RslChannelNr pdch_chan_nr := valueof(t_RslChanNr_PDCH(6));
6992
6993 log("TCH/F_TCH/H_SDCCH8_PDCH pchan starts out in disabled mode:");
6994 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, NONE_MODE);
6995 /* The BSC will activate the dynamic PDCH by default, so confirm that */
6996 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr, ?));
6997
6998 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
6999 f_sleep(1.0);
7000 log("TCH/F_TCH/H_SDCCH8_PDC requested to PDCH ACT on startup, which was ACKed, so now in PDCH:");
7001 f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE);
7002
7003 /* Fill TS0 SDCCH channels (NOTE: only 3 SDCCH/4 channels are available
7004 * on CCCH+SDCCH4+CBCH) */
7005 var integer i;
7006 for (i := 0; i < 3; i := i + 1) {
7007 dt := f_est_dchan('23'O, i, '00010203040506'O);
7008 }
7009
7010 /* Now the dyn ts is selected. First PDCH is released, then sdcch chan is activated */
7011 f_ipa_tx(0, ts_RSL_CHAN_RQD(int2oct(oct2int('23'O) + i, 1), 2342));
7012 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(pdch_chan_nr));
7013 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(pdch_chan_nr));
7014
7015 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7016 dt.rsl_chan_nr := rsl_msg.ies[0].body.chan_nr;
7017
7018 f_ts_dyn_mode_assert(0, 0, dt.rsl_chan_nr.tn, SDCCH8_MODE);
7019 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(dt.rsl_chan_nr, RSL_ERR_EQUIPMENT_FAIL));
7020 rsl_msg := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
7021 rr := dec_GsmRrMessage(rsl_msg.ies[1].body.full_imm_ass_info.payload);
7022 if (rr.header.message_type != IMMEDIATE_ASSIGNMENT_REJECT) {
7023 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Expected reject");
7024 }
7025
7026 /* FIXME? Currently the TS stays in state BORKEN: */
7027
7028 /* The BSC will switch the TS back to PDCH once the only lchan using it is released: */
7029 /* rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(pdch_chan_nr, ?));
7030 * f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(pdch_chan_nr, 2342));
7031 * f_sleep(1.0);
7032 * f_ts_dyn_mode_assert(0, 0, pdch_chan_nr.tn, PDCH_MODE)
7033 */
7034
7035 /* clean up config */
7036 f_ts_set_chcomb(0, 0, 6, "PDCH");
7037
7038 f_shutdown_helper();
7039}
7040
Stefan Sperling0796a822018-10-05 13:01:39 +02007041testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02007042 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02007043 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
7044 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
7045 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007046 f_shutdown_helper();
Stefan Sperling0796a822018-10-05 13:01:39 +02007047}
7048
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007049testcase TC_chopped_ipa_payload() runs on test_CT {
7050 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
7051 /* TODO: mp_bsc_ctrl_port does not work yet */};
7052 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
7053 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
7054 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007055 f_shutdown_helper();
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007056}
7057
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01007058/* Verify the BSC sends the MS Power Parameters IE during CHAN ACT to make sure
7059 the BTS does autonomous MS power control loop */
7060testcase TC_assignment_verify_ms_power_params_ie() runs on test_CT {
7061 var MSC_ConnHdlr vc_conn;
7062 var TestHdlrParams pars := f_gen_test_hdlr_pars();
7063 //pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
7064 pars.exp_ms_power_params := true;
7065
7066 f_init(1, true);
7067 f_sleep(1.0);
7068 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
7069 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007070 f_shutdown_helper();
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01007071}
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007072
Vadim Yanitskiy4b233042021-06-30 00:58:43 +02007073/* Verify activation and deactivation of the BCCH carrier power reduction mode */
7074testcase TC_c0_power_red_mode() runs on test_CT {
7075 f_init(1);
7076
7077 for (var integer red := 6; red >= 0; red := red - 2) {
7078 /* Configure BCCH carrier power reduction mode via the VTY */
7079 f_vty_transceive(BSCVTY, "bts 0 c0-power-reduction " & int2str(red));
7080
7081 /* Expect Osmocom specific BS Power Control message on the RSL */
7082 var template RSL_Message tr_rsl_pdu := tr_RSL_BS_PWR_CTRL(
7083 chan_nr := t_RslChanNr_BCCH(0),
7084 bs_power := tr_RSL_IE_BS_Power(red / 2));
7085 tr_rsl_pdu.msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false);
7086 var RSL_Message unused := f_exp_ipa_rx(0, tr_rsl_pdu);
7087
7088 /* Additionally verify the applied value over the CTRL interface */
7089 var CtrlValue cred := f_ctrl_get_bts(IPA_CTRL, 0, "c0-power-reduction");
7090 if (cred != int2str(red)) {
7091 setverdict(fail, "Unexpected BCCH carrier power reduction value ",
7092 cred, " (expected ", red, ")");
7093 }
7094 }
7095
7096 f_shutdown_helper();
7097}
7098
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007099/***********************************************************************
7100 * MSC Pooling
7101 ***********************************************************************/
7102
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007103template MobileIdentityLV ts_MI_TMSI_NRI_LV(integer nri_v, integer nri_bitlen := 10) :=
Harald Weltebf397612021-01-14 20:39:46 +01007104 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 +02007105
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02007106private function f_expect_lchan_rel(RSL_DCHAN_PT rsl, template PDU_ML3_NW_MS exp_rr_rel_tmpl := tr_RRM_RR_RELEASE)
7107runs on MSC_ConnHdlr {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007108 interleave {
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02007109 [] rsl.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02007110 f_logp(BSCVTY, "Got RSL RR Release");
7111 }
7112 [] rsl.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
7113 f_logp(BSCVTY, "Got RSL Deact SACCH");
7114 }
7115 [] rsl.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
7116 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
7117 rsl.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
7118 break;
7119 }
7120 }
7121}
7122
Neels Hofmeyr9f3e6ac2021-04-08 23:09:24 +02007123friend 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 +02007124runs on MSC_ConnHdlr {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007125 f_logp(BSCVTY, "MSC instructs BSC to clear channel");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007126 BSSAP.send(ts_BSSMAP_ClearCommand(0));
7127 interleave {
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02007128 [] rsl.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch exp_rr_rel_tmpl)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007129 f_logp(BSCVTY, "Got RSL RR Release");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007130 }
7131 [] rsl.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007132 f_logp(BSCVTY, "Got RSL Deact SACCH");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007133 }
7134 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007135 f_logp(BSCVTY, "Got BSSMAP Clear Complete");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007136 /* Also drop the SCCP connection */
7137 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
7138 }
7139 [] rsl.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007140 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007141 rsl.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
7142 }
7143 }
7144}
7145
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007146private 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 +02007147runs on MSC_ConnHdlr {
7148 timer T := 10.0;
7149 var octetstring l3_enc := enc_PDU_ML3_MS_NW(valueof(l3_info));
7150
Neels Hofmeyr767548a2020-08-09 20:26:07 +00007151 f_logp(BSCVTY, "establish channel, send Complete Layer 3 Info");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007152 f_create_bssmap_exp(l3_enc);
7153
7154 /* RSL_Emulation.f_chan_est() on rsl:
7155 * This is basically code dup with s/RSL/rsl from:
7156 * RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
7157 */
7158 var RSL_Message rx_rsl;
7159 var GsmRrMessage rr;
7160
7161 /* request a channel to be established */
7162 rsl.send(ts_RSLDC_ChanRqd(g_pars.ra, g_pars.fn));
7163 /* expect immediate assignment.
7164 * Code dup with s/RSL/rsl from:
7165 * rx_rsl := f_rx_or_fail(tr_RSL_IMM_ASSIGN);
7166 */
7167 timer Tt := 10.0;
7168
7169 /* request a channel to be established */
7170 Tt.start;
7171 alt {
7172 [] rsl.receive(tr_RSL_IMM_ASSIGN) -> value rx_rsl {
7173 Tt.stop;
7174 }
7175 [] rsl.receive {
7176 setverdict(fail, "Unexpected RSL message on DCHAN");
7177 mtc.stop;
7178 }
7179 [] Tt.timeout {
7180 setverdict(fail, "Timeout waiting for RSL on DCHAN");
7181 mtc.stop;
7182 }
7183 }
7184 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
7185 g_chan_nr := rr.payload.imm_ass.chan_desc.chan_nr;
7186 rsl.send(ts_RSL_EST_IND(g_chan_nr, valueof(g_pars.link_id), l3_enc));
7187
7188
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007189 if (expect_bssmap_l3) {
7190 f_logp(BSCVTY, "expect BSSAP Complete Layer 3 Info at MSC");
7191 var template PDU_BSSAP exp_l3_compl;
7192 exp_l3_compl := tr_BSSMAP_ComplL3()
7193 if (g_pars.aoip == false) {
7194 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := omit;
7195 } else {
7196 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := ?;
7197 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007198
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007199 var PDU_BSSAP bssap;
7200 T.start;
7201 alt {
7202 [] BSSAP.receive(exp_l3_compl) -> value bssap {
7203 f_logp(BSCVTY, "received expected Complete Layer 3 Info at MSC");
7204 log("rx exp_l3_compl = ", bssap);
7205 }
7206 [] BSSAP.receive(tr_BSSMAP_ComplL3) {
7207 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching COMPLETE LAYER 3 INFORMATION");
7208 }
7209 [] T.timeout {
7210 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
7211 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007212 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007213
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007214 /* start ciphering, if requested */
7215 if (ispresent(g_pars.encr)) {
7216 f_logp(BSCVTY, "start ciphering");
Neels Hofmeyr6c388f22021-06-11 02:36:56 +02007217 f_cipher_mode(g_pars.encr);
Neels Hofmeyr66e15092020-10-12 18:44:41 +00007218 }
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007219 }
7220
7221 if (do_clear) {
7222 f_perform_clear(rsl);
7223 }
7224 setverdict(pass);
7225 f_sleep(1.0);
7226}
7227
7228private function f_tc_mscpool_compl_l3(charstring id) runs on MSC_ConnHdlr {
7229 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
7230 if (g_pars.mscpool.rsl_idx == 0) {
7231 f_perform_compl_l3(RSL, g_pars.mscpool.l3_info);
7232 } else if (g_pars.mscpool.rsl_idx == 1) {
7233 f_perform_compl_l3(RSL1, g_pars.mscpool.l3_info);
7234 } else if (g_pars.mscpool.rsl_idx == 2) {
7235 f_perform_compl_l3(RSL2, g_pars.mscpool.l3_info);
7236 }
7237}
7238
7239/* Various Complete Layer 3 by IMSI all end up with the first MSC, because the other MSCs are not connected. */
7240private function f_tc_mscpool_L3Compl_on_1_msc(charstring id) runs on MSC_ConnHdlr {
7241 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
7242 f_perform_compl_l3(RSL, ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O) );
7243 f_perform_compl_l3(RSL, ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_IMSI_LV('001010000000002'H))) );
7244 f_perform_compl_l3(RSL, ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))) );
7245 f_perform_compl_l3(RSL, ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_IMSI_LV('001010000000004'H))) );
7246}
7247testcase TC_mscpool_L3Compl_on_1_msc() runs on test_CT {
7248
7249 f_init(1, true);
7250 f_sleep(1.0);
7251 var MSC_ConnHdlr vc_conn;
7252 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007253
7254 f_ctrs_msc_init();
7255
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007256 vc_conn := f_start_handler(refers(f_tc_mscpool_L3Compl_on_1_msc), pars);
7257 vc_conn.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007258
7259 f_ctrs_msc_expect(0, "mscpool:subscr:new", 4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007260 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007261}
7262
7263/* Three Layer 3 Complete by IMSI are round-robin'ed across two connected MSCs */
7264/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7265 * just as well using only RSL. */
7266testcase TC_mscpool_L3Complete_by_imsi_round_robin() runs on test_CT {
7267
7268 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7269 f_sleep(1.0);
7270
7271 /* Control which MSC gets chosen next by the round-robin, otherwise
7272 * would be randomly affected by which other tests ran before this. */
7273 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7274
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007275 f_ctrs_msc_init();
7276
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007277 var MSC_ConnHdlr vc_conn1;
7278 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7279 pars1.mscpool.rsl_idx := 0;
7280 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
7281 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7282 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007283 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007284
7285 var MSC_ConnHdlr vc_conn2;
7286 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7287 pars2.mscpool.rsl_idx := 1;
7288 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
7289 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7290 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007291 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007292
7293 /* Test round-robin wrap to the first MSC */
7294 var MSC_ConnHdlr vc_conn3;
7295 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
7296 pars3.mscpool.rsl_idx := 2;
7297 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
7298 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7299 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007300 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007301 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007302}
7303
7304/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 0
7305 * (configured in osmo-bsc.cfg). */
7306/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7307 * just as well using only RSL. */
7308testcase TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() runs on test_CT {
7309
7310 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7311 f_sleep(1.0);
7312
7313 /* Control which MSC gets chosen next by the round-robin, otherwise
7314 * would be randomly affected by which other tests ran before this. */
7315 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7316
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007317 f_ctrs_msc_init();
7318
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007319 var MSC_ConnHdlr vc_conn1;
7320 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7321 pars1.mscpool.rsl_idx := 0;
7322 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
7323 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7324 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007325 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007326
7327 var MSC_ConnHdlr vc_conn2;
7328 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7329 pars2.mscpool.rsl_idx := 1;
7330 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
7331 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7332 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007333 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007334
7335 /* Test round-robin wrap to the first MSC */
7336 var MSC_ConnHdlr vc_conn3;
7337 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
7338 pars3.mscpool.rsl_idx := 2;
7339 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
7340 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7341 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007342 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007343 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007344}
7345
7346/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 1
7347 * (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
7348 * NULL-NRI setting is stronger than that. */
7349/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7350 * just as well using only RSL. */
7351testcase TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() runs on test_CT {
7352
7353 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7354 f_sleep(1.0);
7355
7356 /* Control which MSC gets chosen next by the round-robin, otherwise
7357 * would be randomly affected by which other tests ran before this. */
7358 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7359
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007360 f_ctrs_msc_init();
7361
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007362 var MSC_ConnHdlr vc_conn1;
7363 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7364 pars1.mscpool.rsl_idx := 0;
7365 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
7366 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7367 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007368 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007369
7370 var MSC_ConnHdlr vc_conn2;
7371 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7372 pars2.mscpool.rsl_idx := 1;
7373 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
7374 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7375 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007376 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007377
7378 /* Test round-robin wrap to the first MSC */
7379 var MSC_ConnHdlr vc_conn3;
7380 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
7381 pars3.mscpool.rsl_idx := 2;
7382 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
7383 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7384 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007385 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007386 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007387}
7388
7389/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI not
7390 * assigned to any MSC (configured in osmo-bsc.cfg). */
7391/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7392 * just as well using only RSL. */
7393testcase TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() runs on test_CT {
7394
7395 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7396 f_sleep(1.0);
7397
7398 /* Control which MSC gets chosen next by the round-robin, otherwise
7399 * would be randomly affected by which other tests ran before this. */
7400 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7401
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007402 f_ctrs_msc_init();
7403
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007404 var MSC_ConnHdlr vc_conn1;
7405 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7406 pars1.mscpool.rsl_idx := 0;
7407 /* An NRI that is not assigned to any MSC */
7408 pars1.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(1023))));
7409 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7410 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007411 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007412
7413 var MSC_ConnHdlr vc_conn2;
7414 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7415 pars2.mscpool.rsl_idx := 1;
7416 /* An NRI that is not assigned to any MSC */
7417 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(768)), '00F110'O));
7418 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7419 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007420 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007421
7422 /* Test round-robin wrap to the first MSC */
7423 var MSC_ConnHdlr vc_conn3;
7424 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
7425 pars3.mscpool.rsl_idx := 2;
7426 /* An NRI that is not assigned to any MSC */
7427 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, valueof(ts_MI_TMSI_NRI_LV(819))));
7428 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7429 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007430 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007431 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007432}
7433
7434/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI
7435 * assigned to an MSC that is currently not connected (configured in osmo-bsc.cfg). */
7436/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7437 * just as well using only RSL. */
7438testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() runs on test_CT {
7439
7440 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7441 f_sleep(1.0);
7442
7443 /* Control which MSC gets chosen next by the round-robin, otherwise
7444 * would be randomly affected by which other tests ran before this. */
7445 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7446
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007447 f_ctrs_msc_init();
7448
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007449 var MSC_ConnHdlr vc_conn1;
7450 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7451 pars1.mscpool.rsl_idx := 0;
7452 /* An NRI that is assigned to an unconnected MSC */
7453 pars1.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(512))));
7454 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7455 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007456 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
7457 f_ctrs_msc_add(0, "mscpool:subscr:new");
7458 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007459
7460 var MSC_ConnHdlr vc_conn2;
7461 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7462 pars2.mscpool.rsl_idx := 1;
7463 /* An NRI that is assigned to an unconnected MSC */
7464 pars2.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(767))));
7465 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7466 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007467 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
7468 f_ctrs_msc_add(1, "mscpool:subscr:new");
7469 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007470
7471 /* Test round-robin wrap to the first MSC */
7472 var MSC_ConnHdlr vc_conn3;
7473 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
7474 pars3.mscpool.rsl_idx := 2;
7475 /* An NRI that is assigned to an unconnected MSC */
7476 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(750)), '00F110'O));
7477 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7478 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007479 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
7480 f_ctrs_msc_add(0, "mscpool:subscr:new");
7481 f_ctrs_msc_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007482 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007483}
7484
7485/* Three Layer 3 Complete by TMSI with valid NRI for the second MSC are all directed to the second MSC (configured in
7486 * osmo-bsc.cfg). */
7487/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7488 * just as well using only RSL. */
7489testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_1() runs on test_CT {
7490
7491 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
7492 f_sleep(1.0);
7493
7494 /* All TMSIs in this test point at the second MSC, set the round robin to point at the first MSC to make sure
7495 * this is not using round-robin. */
7496 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7497
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007498 f_ctrs_msc_init();
7499
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007500 var MSC_ConnHdlr vc_conn1;
7501 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
7502 pars1.mscpool.rsl_idx := 0;
7503 /* An NRI of the second MSC's range (256-511) */
7504 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(256))));
7505 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7506 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007507 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007508
7509 var MSC_ConnHdlr vc_conn2;
7510 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
7511 pars2.mscpool.rsl_idx := 1;
7512 /* An NRI of the second MSC's range (256-511) */
7513 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(260))));
7514 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7515 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007516 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007517
7518 var MSC_ConnHdlr vc_conn3;
7519 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
7520 pars3.mscpool.rsl_idx := 2;
7521 /* An NRI of the second MSC's range (256-511) */
7522 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(511)), '00F110'O));
7523 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7524 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007525 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007526 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007527}
7528
7529/* Layer 3 Complete by TMSI with valid NRI for the third MSC are directed to the third MSC (configured in osmo-bsc.cfg),
7530 * while a round-robin remains unaffected by that. */
7531/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7532 * just as well using only RSL. */
7533testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_2() runs on test_CT {
7534
7535 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
7536 f_sleep(1.0);
7537
7538 /* All TMSIs in this test point at the third MSC, set the round robin to point at the second MSC to make sure
7539 * this is not using round-robin. */
7540 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
7541
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007542 f_ctrs_msc_init();
7543
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007544 var MSC_ConnHdlr vc_conn1;
7545 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 2);
7546 pars1.mscpool.rsl_idx := 0;
7547 /* An NRI of the third MSC's range (512-767) */
7548 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(512))));
7549 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7550 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007551 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007552
7553 var MSC_ConnHdlr vc_conn2;
7554 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
7555 pars2.mscpool.rsl_idx := 1;
7556 /* An NRI of the third MSC's range (512-767) */
7557 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(678))));
7558 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7559 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007560 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007561
7562 /* The above forwardings to third MSC have not affected the round robin, which still points at the second MSC */
7563 var MSC_ConnHdlr vc_conn3;
7564 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
7565 pars3.mscpool.rsl_idx := 2;
7566 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000013'H)), '00F110'O));
7567 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7568 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007569 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007570 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007571}
7572
7573/* LU with a TMSI but indicating a different PLMN in its previous LAI: ignore the NRI. */
7574/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7575 * just as well using only RSL. */
7576testcase TC_mscpool_LU_by_tmsi_from_other_PLMN() runs on test_CT {
7577
7578 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
7579 f_sleep(1.0);
7580
7581 /* The TMSIs in this test points at the second MSC, but since it is from a different PLMN, round-robin is used
7582 * instead, and hits msc 0. */
7583 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7584
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007585 f_ctrs_msc_init();
7586
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007587 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-bsc.cfg */
7588 var MSC_ConnHdlr vc_conn1;
7589 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7590 pars1.mscpool.rsl_idx := 0;
7591 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(260)), '99F999'O));
7592 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7593 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007594 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007595
7596 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
7597 var MSC_ConnHdlr vc_conn2;
7598 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
7599 pars2.mscpool.rsl_idx := 1;
7600 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(555)), '00F110'O));
7601 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7602 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007603 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007604 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007605}
7606
7607/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by IMSI, which would be
7608 * round-robined to another MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
7609private function f_tc_mscpool_paging_imsi(charstring id) runs on MSC_ConnHdlr {
7610 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
7611 //cid_list := { cIl_allInBSS := ''O };
7612 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
7613 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
7614 var BSSAP_N_UNITDATA_req paging;
7615 var hexstring imsi := '001010000000123'H;
7616
7617 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
7618
Neels Hofmeyr90f80962020-06-12 16:16:55 +02007619 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007620 valueof(ts_BSSMAP_Paging(imsi, cid_list, omit, bssmap_chneed))));
7621 BSSAP.send(paging);
7622
7623 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
7624 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
7625 * channel number is picked here. */
7626 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
7627 f_rslem_register(0, new_chan_nr);
7628 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(imsi)));
7629 f_rslem_unregister(0, new_chan_nr);
7630
7631 /* Despite the round robin pointing at the second MSC ('roundrobin next 1'), the earlier Paging for the same IMSI
7632 * causes this Paging Response to go to the first MSC (bssap_idx := 0). */
7633 f_perform_compl_l3(RSL, ts_PAG_RESP(valueof(ts_MI_IMSI_LV(imsi))) );
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007634 f_sleep(1.0);
7635}
7636testcase TC_mscpool_paging_and_response_imsi() runs on test_CT {
7637 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
7638 f_sleep(1.0);
7639
7640 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
7641 * second MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
7642 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
7643
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007644 f_ctrs_msc_init();
7645
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007646 var MSC_ConnHdlr vc_conn1;
7647 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7648 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02007649 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
7650 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007651 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_imsi), pars1);
7652 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007653 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007654 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007655}
7656
7657/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by TMSI with an NRI value
7658 * that matches a different MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
7659private function f_tc_mscpool_paging_tmsi(charstring id) runs on MSC_ConnHdlr {
7660 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
7661 //cid_list := { cIl_allInBSS := ''O };
7662 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
7663 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
7664 var integer nri_v := 300; /* <-- second MSC's NRI */
Harald Weltebf397612021-01-14 20:39:46 +01007665 var octetstring tmsi := f_gen_tmsi(suffix := 0, nri_v := nri_v);
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007666 var BSSAP_N_UNITDATA_req paging;
7667
7668 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
7669
Neels Hofmeyr90f80962020-06-12 16:16:55 +02007670 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007671 valueof(ts_BSSMAP_Paging('001010000000011'H, cid_list, tmsi, bssmap_chneed))));
7672 BSSAP.send(paging);
7673
7674 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
7675 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
7676 * channel number is picked here. */
7677 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
7678 f_rslem_register(0, new_chan_nr);
7679 RSL.receive(tr_RSL_PAGING_CMD(t_MI_TMSI(tmsi)));
7680 f_rslem_unregister(0, new_chan_nr);
7681
7682 /* Despite the NRI matching the second MSC (NRI from 'msc 1' in osmo-bsc.cfg) and round robin pointing at the
7683 * third MSC ('roundrobin next 2'), the earlier Paging for the same TMSI causes this Paging Response to go to
7684 * the first MSC (bssap_idx := 0). */
7685 f_perform_compl_l3(RSL, ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(nri_v))) );
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007686 f_sleep(1.0);
7687}
7688testcase TC_mscpool_paging_and_response_tmsi() runs on test_CT {
7689 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
7690 f_sleep(1.0);
7691
7692 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
7693 * third MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
7694 f_vty_transceive(BSCVTY, "mscpool roundrobin next 2");
7695
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007696 f_ctrs_msc_init();
7697
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007698 var MSC_ConnHdlr vc_conn1;
7699 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7700 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02007701 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
7702 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007703 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_tmsi), pars1);
7704 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007705 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007706 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007707}
7708
7709/* For round-robin, skip an MSC that has 'no allow-attach' set. */
7710/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
7711 * just as well using only RSL. */
7712testcase TC_mscpool_no_allow_attach_round_robin() runs on test_CT {
7713
7714 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
7715 f_sleep(1.0);
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00007716 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
7717 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007718
7719 /* Control which MSC gets chosen next by the round-robin, otherwise
7720 * would be randomly affected by which other tests ran before this. */
7721 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7722
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007723 f_ctrs_msc_init();
7724
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007725 var MSC_ConnHdlr vc_conn1;
7726 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
7727 pars1.mscpool.rsl_idx := 0;
7728 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
7729 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7730 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007731 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007732
7733 var MSC_ConnHdlr vc_conn2;
7734 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
7735 pars2.mscpool.rsl_idx := 1;
7736 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
7737 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7738 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007739 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007740
7741 var MSC_ConnHdlr vc_conn3;
7742 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
7743 pars3.mscpool.rsl_idx := 2;
7744 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
7745 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7746 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007747 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007748 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007749}
7750
7751/* An MSC that has 'no allow-attach' set should still serve subscribers that are already attached according to their
7752 * TMSI NRI. */
7753testcase TC_mscpool_no_allow_attach_valid_nri() runs on test_CT {
7754
7755 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
7756 f_sleep(1.0);
7757
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00007758 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
7759 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
7760
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007761 /* Control which MSC gets chosen next by the round-robin, otherwise
7762 * would be randomly affected by which other tests ran before this. */
7763 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
7764
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007765 f_ctrs_msc_init();
7766
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007767 /* Round robin points at msc 0, but the valid NRI directs to msc 1, even though msc 1 has 'no allow-attach'. */
7768 var MSC_ConnHdlr vc_conn1;
7769 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
7770 pars1.mscpool.rsl_idx := 0;
7771 /* An NRI of the second MSC's range (256-511) */
7772 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_TMSI_NRI_LV(260))));
7773 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
7774 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007775 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007776
7777 var MSC_ConnHdlr vc_conn2;
7778 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 0);
7779 pars2.mscpool.rsl_idx := 1;
7780 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
7781 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
7782 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007783 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007784
7785 var MSC_ConnHdlr vc_conn3;
7786 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 2);
7787 pars3.mscpool.rsl_idx := 2;
7788 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000003'H))));
7789 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
7790 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02007791 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007792 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007793}
7794
Philipp Maier783681c2020-07-16 16:47:06 +02007795/* Allow/Deny emergency calls globally via VTY */
7796private function f_vty_allow_emerg_msc(boolean allow) runs on test_CT {
7797 f_vty_enter_cfg_msc(BSCVTY, 0);
7798 if (allow) {
7799 f_vty_transceive(BSCVTY, "allow-emergency allow");
7800 } else {
7801 f_vty_transceive(BSCVTY, "allow-emergency deny");
7802 }
7803 f_vty_transceive(BSCVTY, "exit");
7804 f_vty_transceive(BSCVTY, "exit");
7805}
7806
7807/* Allow/Deny emergency calls per BTS via VTY */
7808private function f_vty_allow_emerg_bts(boolean allow, integer bts_nr) runs on test_CT {
7809 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
7810 if (allow) {
7811 f_vty_transceive(BSCVTY, "rach emergency call allowed 1");
7812 } else {
7813 f_vty_transceive(BSCVTY, "rach emergency call allowed 0");
7814 }
7815 f_vty_transceive(BSCVTY, "exit");
7816 f_vty_transceive(BSCVTY, "exit");
Neels Hofmeyrb6ed80c2020-10-12 22:52:39 +00007817 f_vty_transceive(BSCVTY, "exit");
Philipp Maier783681c2020-07-16 16:47:06 +02007818}
7819
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02007820/* Allow/Forbid Fast Return after SRVCC on a given BTS via VTY */
7821private function f_vty_allow_srvcc_fast_return(boolean allow, integer bts_nr) runs on test_CT {
7822 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
7823 if (allow) {
7824 f_vty_transceive(BSCVTY, "srvcc fast-return allow");
7825 } else {
7826 f_vty_transceive(BSCVTY, "srvcc fast-return forbid");
7827 }
7828 f_vty_transceive(BSCVTY, "exit");
7829 f_vty_transceive(BSCVTY, "exit");
7830 f_vty_transceive(BSCVTY, "exit");
7831}
7832
Philipp Maier783681c2020-07-16 16:47:06 +02007833/* Begin assignmet procedure and send an EMERGENCY SETUP (RR) */
7834private function f_assignment_emerg_setup() runs on MSC_ConnHdlr {
7835 var PDU_ML3_MS_NW emerg_setup;
7836 var octetstring emerg_setup_enc;
7837 var RSL_Message emerg_setup_data_ind;
7838
7839 f_establish_fully(omit, omit);
7840
7841 emerg_setup := valueof(ts_ML3_MO_CC_EMERG_SETUP(1, valueof(ts_Bcap_voice)));
7842 emerg_setup_enc := enc_PDU_ML3_MS_NW(emerg_setup);
7843 emerg_setup_data_ind := valueof(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), emerg_setup_enc));
7844
7845 RSL.send(emerg_setup_data_ind);
7846}
7847
7848/* Test if the EMERGENCY SETUP gets passed on to the MSC via A when EMERGENCY
7849 * CALLS are permitted by the BSC config. */
7850private function f_TC_assignment_emerg_setup_allow(charstring id) runs on MSC_ConnHdlr {
7851 var PDU_BSSAP emerg_setup_data_ind_bssap;
7852 var PDU_ML3_MS_NW emerg_setup;
7853 timer T := 3.0;
7854
7855 f_assignment_emerg_setup()
7856
7857 T.start;
7858 alt {
7859 [] BSSAP.receive(tr_BSSAP_DTAP) -> value emerg_setup_data_ind_bssap {
7860 emerg_setup := dec_PDU_ML3_MS_NW(emerg_setup_data_ind_bssap.pdu.dtap);
7861 if (not isbound(emerg_setup.msgs.cc.emergencySetup)) {
7862 setverdict(fail, "no emergency setup");
7863 }
7864 }
7865 [] BSSAP.receive {
7866 setverdict(fail, "unexpected BSSAP message!");
7867 }
7868 [] T.timeout {
7869 setverdict(fail, "timout waiting for EMERGENCY SETUP!");
7870 }
7871 }
7872
7873 setverdict(pass);
7874}
7875
7876/* Test if the EMERGENCY SETUP gets blocked by the BSC if EMERGENCY CALLS are
7877 * forbidden by the BSC config. */
7878private function f_TC_assignment_emerg_setup_deny(charstring id) runs on MSC_ConnHdlr {
7879 var PDU_BSSAP emerg_setup_data_ind_bssap;
7880 timer T := 3.0;
7881
7882 f_assignment_emerg_setup()
7883
7884 T.start;
7885 alt {
7886 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
7887 setverdict(pass);
7888 }
7889 [] RSL.receive {
7890 setverdict(fail, "unexpected RSL message!");
7891 }
7892 [] T.timeout {
7893 setverdict(fail, "timout waiting for RR CHANNEL RELEASE!");
7894 }
7895 }
7896}
7897
7898/* EMERGENCY CALL situation #1, allowed globally and by BTS */
7899testcase TC_assignment_emerg_setup_allow() runs on test_CT {
7900 var TestHdlrParams pars := f_gen_test_hdlr_pars();
7901 var MSC_ConnHdlr vc_conn;
7902
7903 f_init(1, true);
7904 f_sleep(1.0);
7905
7906 f_vty_allow_emerg_msc(true);
7907 f_vty_allow_emerg_bts(true, 0);
7908 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_allow), pars);
7909 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007910 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02007911}
7912
7913/* EMERGENCY CALL situation #2, forbidden globally but allowed by BTS */
7914testcase TC_assignment_emerg_setup_deny_msc() runs on test_CT {
7915 var TestHdlrParams pars := f_gen_test_hdlr_pars();
7916 var MSC_ConnHdlr vc_conn;
7917
7918 f_init(1, true);
7919 f_sleep(1.0);
7920
7921 f_vty_allow_emerg_msc(false);
7922 f_vty_allow_emerg_bts(true, 0);
7923 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
7924 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007925 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02007926}
7927
7928/* EMERGENCY CALL situation #3, allowed globally but forbidden by BTS */
7929testcase TC_assignment_emerg_setup_deny_bts() runs on test_CT {
7930 var TestHdlrParams pars := f_gen_test_hdlr_pars();
7931 var MSC_ConnHdlr vc_conn;
7932
7933 /* Note: This simulates a spec violation by the MS, correct MS
7934 * implementations would not try to establish an emergency call because
7935 * the system information tells in advance that emergency calls are
7936 * not forbidden */
7937
7938 f_init(1, true);
7939 f_sleep(1.0);
7940
7941 f_vty_allow_emerg_msc(true);
7942 f_vty_allow_emerg_bts(false, 0);
7943 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
7944 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007945 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02007946}
7947
Philipp Maier82812002020-08-13 18:48:27 +02007948/* Test what happens when an emergency call arrives while all TCH channels are
7949 * busy, the BSC is expected to terminate one call in favor of the incoming
7950 * emergency call */
7951testcase TC_emerg_premption() runs on test_CT {
7952 var ASP_RSL_Unitdata rsl_ud;
7953 var integer i;
7954 var integer chreq_total, chreq_nochan;
7955 var RSL_Message rx_rsl;
7956 var RslChannelNr chan_nr;
7957
7958 f_init(1);
7959 f_sleep(1.0);
7960
7961 f_vty_allow_emerg_msc(true);
7962 f_vty_allow_emerg_bts(true, 0);
7963
7964 /* Fill up all channels on the BTS */
7965 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
7966 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
7967 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS; i := i+1) {
7968 chan_nr := f_chreq_act_ack('33'O, i);
7969 }
7970 IPA_RSL[0].clear;
7971 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
7972 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
7973
7974 /* Send Channel request for emegergency call */
7975 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
7976
7977 /* Expect the BSC to release one (the first) TCH/F on the BTS */
7978 chan_nr := valueof(t_RslChanNr_Bm(1));
7979 f_expect_chan_rel(0, chan_nr, expect_rr_chan_rel := false, expect_rll_rel_req := false);
7980
7981 /* Expect the BSC to send activate/assign the a channel for the emergency call */
7982 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7983 chan_nr := rx_rsl.ies[0].body.chan_nr;
7984 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 33));
7985 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Philipp Maier104f4c02020-09-11 18:12:18 +02007986
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02007987 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007988}
7989
7990/* Hopping parameters per a timeslot */
Vadim Yanitskiybc6654a2020-09-13 01:27:40 +07007991private type record length(0..64) of GsmArfcn ArfcnList;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007992private type record FHParamsTs {
7993 boolean enabled,
7994 uint6_t hsn,
7995 uint6_t maio,
7996 ArfcnList ma
7997};
7998
7999/* Hopping parameters per a transceiver */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008000private type record FHParamsTrx {
8001 GsmArfcn arfcn,
8002 FHParamsTs ts[8]
8003};
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008004
8005/* Randomly generate the hopping parameters for the given timeslot numbers */
8006private function f_TC_fh_params_gen(template integer tr_tn := (1, 3, 5))
8007runs on test_CT return FHParamsTrx {
8008 var FHParamsTrx fhp;
8009
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07008010 /* Generate a random ARFCN, including ARFCN 0 */
8011 fhp.arfcn := f_rnd_int(3);
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008012
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008013 for (var integer tn := 0; tn < 8; tn := tn + 1) {
8014 if (not match(tn, tr_tn)) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008015 fhp.ts[tn].enabled := false;
8016 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008017 continue;
8018 }
8019
8020 /* Random HSN / MAIO values: 0..63 */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008021 fhp.ts[tn].hsn := f_rnd_int(64);
8022 fhp.ts[tn].maio := f_rnd_int(64);
8023 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008024
8025 /* Random Mobile Allocation (hopping channels) */
8026 var integer ma_len := 2 + f_rnd_int(9); /* 2..10 channels */
8027 var integer step := 3 + f_rnd_int(4); /* 3..6 stepping */
8028 for (var integer i := 1; i <= ma_len; i := i + 1) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008029 fhp.ts[tn].ma := fhp.ts[tn].ma & { i * step };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008030 }
8031
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008032 fhp.ts[tn].enabled := true;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008033 }
8034
8035 log("f_TC_fh_params_gen(): ", fhp);
8036 return fhp;
8037}
8038
8039/* Make sure that the given Channel Description IE matches the hopping configuration */
8040private function f_TC_fh_params_match_chan_desc(in FHParamsTrx fhp, in ChannelDescription cd)
8041{
8042 var template (present) ChannelDescription tr_cd;
8043 var template (present) MaioHsn tr_maio_hsn;
8044 var uint3_t tn := cd.chan_nr.tn;
8045
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008046 if (fhp.ts[tn].enabled) {
8047 tr_maio_hsn := tr_HsnMaio(fhp.ts[tn].hsn, fhp.ts[tn].maio);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008048 tr_cd := tr_ChanDescH1(cd.chan_nr, tr_maio_hsn);
8049 } else {
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008050 tr_cd := tr_ChanDescH0(cd.chan_nr, fhp.arfcn);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008051 }
8052
8053 if (not match(cd, tr_cd)) {
8054 setverdict(fail, "Channel Description IE does not match: ",
8055 cd, " vs expected ", tr_cd);
8056 }
8057}
8058
8059/* Make sure that the given Mobile Allocation IE matches the hopping configuration */
8060private function f_TC_fh_params_match_ma(in FHParamsTrx fhp, uint3_t tn,
8061 in MobileAllocationLV ma)
8062{
8063 var template MobileAllocationLV tr_ma := f_TC_fh_params_gen_tr_ma(fhp, tn, ma);
8064
8065 if (not match(ma, tr_ma)) {
8066 setverdict(fail, "Mobile Allocation IE does not match (tn := ",
8067 tn, "): ", ma, " vs expected: ", tr_ma);
8068 } else {
8069 setverdict(pass);
8070 }
8071}
8072
8073private function f_TC_fh_params_gen_tr_ma(in FHParamsTrx fhp, uint3_t tn,
8074 in MobileAllocationLV ma)
8075return template MobileAllocationLV {
8076 /* Mobile Allocation IE is expected to be empty if hopping is not enabled */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008077 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008078 return { len := 0, ma := ''B };
8079 }
8080
8081 var bitstring full_mask := f_pad_bit(''B, 1024, '0'B);
8082 var bitstring slot_mask := f_pad_bit(''B, 1024, '0'B);
8083 var bitstring ma_mask := ''B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008084
8085 /* Compose the full bit-mask (all channels, up to 1024 entries) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008086 for (var integer i := 0; i < lengthof(fhp.ts); i := i + 1) {
8087 for (var integer j := 0; j < lengthof(fhp.ts[i].ma); j := j + 1) {
8088 if (full_mask[fhp.ts[i].ma[j]] == '1'B)
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008089 { continue; }
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008090 full_mask[fhp.ts[i].ma[j]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008091 }
8092 }
8093
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008094 /* Take ARFCN of the TRX itself into account */
8095 full_mask[fhp.arfcn] := '1'B;
8096
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008097 /* Compose a bit-mask for the given timeslot number */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008098 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
8099 slot_mask[fhp.ts[tn].ma[i]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008100 }
8101
8102 /* Finally, compose the Mobile Allocation bit-mask */
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07008103 for (var integer i := 1; i < lengthof(full_mask); i := i + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008104 if (full_mask[i] != '1'B)
8105 { continue; }
8106
8107 /* FIXME: ma_mask := ma_mask & slot_mask[i]; // triggers a bug in TITAN */
8108 if (slot_mask[i] == '1'B) {
8109 ma_mask := ma_mask & '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008110 } else {
8111 ma_mask := ma_mask & '0'B;
8112 }
8113 }
8114
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07008115 /* ARFCN 0 (if present) goes to the last position of the bit-mask */
8116 if (full_mask[0] == '1'B) {
8117 /* FIXME: ma_mask := ma_mask & slot_mask[0]; // triggers a bug in TITAN */
8118 if (slot_mask[0] == '1'B) {
8119 ma_mask := ma_mask & '1'B;
8120 } else {
8121 ma_mask := ma_mask & '0'B;
8122 }
8123 }
8124
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008125 /* Ensure that ma_mask is octet-aligned */
Vadim Yanitskiy2aa02522020-09-06 14:05:23 +07008126 var integer ma_mask_len := (lengthof(ma_mask) + 8 - 1) / 8;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008127 ma_mask := f_pad_bit(ma_mask, ma_mask_len * 8, '0'B);
8128
8129 return { len := ma_mask_len, ma := ma_mask };
8130}
8131
8132/* Configure the hopping parameters in accordance with the given record */
8133private function f_TC_fh_params_set(in FHParamsTrx fhp,
8134 uint8_t bts_nr := 0,
8135 uint8_t trx_nr := 0)
8136runs on test_CT {
8137 /* Enter the configuration node for the given BTS/TRX numbers */
8138 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
8139
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008140 f_vty_transceive(BSCVTY, "arfcn " & int2str(fhp.arfcn));
8141
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008142 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008143 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
8144
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008145 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008146 f_vty_transceive(BSCVTY, "hopping enabled 0");
8147 f_vty_transceive(BSCVTY, "exit"); /* go back */
8148 continue;
8149 }
8150
8151 /* Configure HSN / MAIO values */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008152 f_vty_transceive(BSCVTY, "hopping sequence-number " & int2str(fhp.ts[tn].hsn));
8153 f_vty_transceive(BSCVTY, "hopping maio " & int2str(fhp.ts[tn].maio));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008154
8155 /* Configure the Mobile Allocation (hopping channels) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008156 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
8157 f_vty_transceive(BSCVTY, "hopping arfcn add " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008158 }
8159
8160 f_vty_transceive(BSCVTY, "hopping enabled 1");
8161 f_vty_transceive(BSCVTY, "exit"); /* go back */
8162 }
8163
8164 f_vty_transceive(BSCVTY, "end");
8165}
8166
8167/* Disable frequency hopping on all timeslots */
8168private function f_TC_fh_params_unset(in FHParamsTrx fhp,
8169 uint8_t bts_nr := 0,
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008170 uint8_t trx_nr := 0,
8171 GsmArfcn arfcn := 871)
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008172runs on test_CT {
8173 /* Enter the configuration node for the given BTS/TRX numbers */
8174 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
8175
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07008176 f_vty_transceive(BSCVTY, "arfcn " & int2str(arfcn));
8177
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008178 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008179 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
8180
8181 /* Delete all ARFCNs from the Mobile Allocation (if any) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07008182 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
8183 f_vty_transceive(BSCVTY, "hopping arfcn del " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008184 }
8185
8186 f_vty_transceive(BSCVTY, "hopping enabled 0");
8187 f_vty_transceive(BSCVTY, "exit"); /* go back */
8188 }
8189
8190 f_vty_transceive(BSCVTY, "end");
8191 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8192}
8193
8194/* Verify presence and correctness of the hopping parameters (HSN, MAIO)
8195 * in the Channel Identification IE of the RSL CHANnel ACTIVation message. */
8196testcase TC_fh_params_chan_activ() runs on test_CT {
8197 var FHParamsTrx fhp := f_TC_fh_params_gen();
8198 var RSL_Message rsl_msg;
8199 var RSL_IE_Body ie;
8200
8201 f_init_vty();
8202
8203 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
8204 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8205
8206 f_init(1);
8207
8208 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
8209 for (var integer i := 0; i < 9; i := i + 1) {
8210 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
8211 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8212
8213 /* Make sure that Channel Identification IE is present */
8214 if (not f_rsl_find_ie(rsl_msg, RSL_IE_CHAN_IDENT, ie)) {
8215 setverdict(fail, "RSL Channel Identification IE is absent");
8216 continue;
8217 }
8218
8219 /* Make sure that hopping parameters (HSN/MAIO) match */
8220 f_TC_fh_params_match_chan_desc(fhp, ie.chan_ident.ch_desc.v);
8221
8222 /* "Mobile Allocation shall be included but empty" - let's check this */
8223 if (ie.chan_ident.ma.v.len != 0) {
8224 setverdict(fail, "Mobile Allocation IE is not empty: ",
8225 ie.chan_ident.ma, ", despite it shall be");
8226 continue;
8227 }
8228 }
8229
8230 /* Disable frequency hopping */
8231 f_TC_fh_params_unset(fhp);
8232
Vadim Yanitskiy21726312020-09-04 01:45:36 +07008233 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07008234}
8235
8236/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Immediate Assignment */
8237testcase TC_fh_params_imm_ass() runs on test_CT {
8238 var FHParamsTrx fhp := f_TC_fh_params_gen();
8239 var RSL_Message rsl_msg;
8240 var RSL_IE_Body ie;
8241
8242 f_init_vty();
8243
8244 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
8245 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8246
8247 f_init(1);
8248
8249 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
8250 for (var integer i := 0; i < 9; i := i + 1) {
8251 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
8252 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8253
8254 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
8255 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
8256
8257 /* Make sure that Full Immediate Assign Info IE is present */
8258 if (not f_rsl_find_ie(rsl_msg, RSL_IE_FULL_IMM_ASS_INFO, ie)) {
8259 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
8260 continue;
8261 }
8262
8263 /* Decode the actual Immediate Assignment message */
8264 var GsmRrMessage rr_msg := dec_GsmRrMessage(ie.full_imm_ass_info.payload);
8265 if (not match(rr_msg.header, t_RrHeader(IMMEDIATE_ASSIGNMENT, ?))) {
8266 setverdict(fail, "Failed to match Immediate Assignment: ", rr_msg);
8267 continue;
8268 }
8269
8270 /* Make sure that hopping parameters (HSN/MAIO) match */
8271 f_TC_fh_params_match_chan_desc(fhp, rr_msg.payload.imm_ass.chan_desc);
8272
8273 /* Make sure that the Mobile Allocation IE matches */
8274 f_TC_fh_params_match_ma(fhp, rr_msg.payload.imm_ass.chan_desc.chan_nr.tn,
8275 rr_msg.payload.imm_ass.mobile_allocation);
8276 }
8277
8278 /* Disable frequency hopping */
8279 f_TC_fh_params_unset(fhp);
Philipp Maier82812002020-08-13 18:48:27 +02008280
Vadim Yanitskiy21726312020-09-04 01:45:36 +07008281 f_shutdown_helper();
Philipp Maier82812002020-08-13 18:48:27 +02008282}
8283
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07008284/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Assignment Command */
8285testcase TC_fh_params_assignment_cmd() runs on test_CT {
8286 var FHParamsTrx fhp := f_TC_fh_params_gen();
8287 var RSL_Message rsl_msg;
8288 var RSL_IE_Body ie;
8289
8290 f_init_vty();
8291
8292 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
8293 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8294
8295 f_init(1);
8296
8297 /* HACK: work around "Couldn't find Expect for CRCX" */
8298 vc_MGCP.stop;
8299
8300 var template PDU_BSSAP ass_cmd := f_gen_ass_req();
8301 ass_cmd.pdu.bssmap.assignmentRequest.codecList := ts_BSSMAP_IE_CodecList({ts_CodecFR});
8302
8303 /* CS domain (TCH): 4 (TCH/F) + 2 (TCH/H) channels available
8304 * NOTE: only 3 SDCCH/4 channels are available on CCCH+SDCCH4+CBCH */
8305 for (var integer i := 0; i < 3; i := i + 1) {
8306 /* Establish a dedicated channel, so we can trigger (late) TCH assignment */
8307 var DchanTuple dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
8308
8309 /* Send a BSSMAP Assignment Command, expect CHANnel ACTIVation */
8310 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
8311 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8312
8313 /* ACKnowledge CHANnel ACTIVation, expect RSL DATA REQuest */
8314 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
8315 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
8316
8317 /* Make sure that L3 Information IE is present */
8318 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
8319 setverdict(fail, "RSL L3 Information IE is absent");
8320 continue;
8321 }
8322
8323 /* Decode the L3 message and make sure it is (RR) Assignment Command */
8324 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
8325 if (not match(l3_msg.header, t_RrL3Header(ASSIGNMENT_COMMAND))) {
8326 setverdict(fail, "Failed to match Assignment Command: ", l3_msg);
8327 continue;
8328 }
8329
8330 /* Make sure that hopping parameters (HSN/MAIO) match */
8331 var ChannelDescription chan_desc := l3_msg.payload.ass_cmd.chan_desc;
8332 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
8333
8334 /* Make sure that Cell Channel Description IE is present if FH is enabled */
8335 if (chan_desc.h and not ispresent(l3_msg.payload.ass_cmd.cell_chan_desc)) {
Vadim Yanitskiy38d069d2020-09-02 17:18:57 +07008336 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07008337 continue;
8338 }
8339
8340 /* Make sure that the Mobile Allocation IE matches (if present) */
8341 var boolean ma_present := ispresent(l3_msg.payload.ass_cmd.mobile_allocation);
8342 if (chan_desc.h and ma_present) {
8343 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
8344 l3_msg.payload.ass_cmd.mobile_allocation.v);
8345 } else if (chan_desc.h and not ma_present) {
8346 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
8347 continue;
8348 } else if (not chan_desc.h and ma_present) {
8349 setverdict(fail, "FH disabled, but Mobile Allocation IE is present");
8350 continue;
8351 }
8352 }
8353
8354 /* Give the IUT some time to release all channels */
8355 f_sleep(3.0);
8356
8357 /* Disable frequency hopping */
8358 f_TC_fh_params_unset(fhp);
8359
Vadim Yanitskiy21726312020-09-04 01:45:36 +07008360 f_shutdown_helper();
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07008361}
8362
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07008363/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Handover Command */
8364private function f_TC_fh_params_handover_cmd(in FHParamsTrx fhp)
8365runs on test_CT {
8366 var RSL_Message rsl_msg;
8367 var RSL_IE_Body ie;
8368 var DchanTuple dt;
8369
8370 /* Establish a dedicated channel, so we can trigger handover */
8371 dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
8372
8373 /* Trigger handover from BTS0 to BTS1 */
8374 f_bts_0_cfg(BSCVTY, { "neighbor bts 1" });
8375 f_vty_handover(BSCVTY, 0, 0, dt.rsl_chan_nr, 1);
8376
8377 /* Expect RSL CHANnel ACTIVation on BTS1/TRX0/TS1 */
8378 rsl_msg := f_exp_ipa_rx(1, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
8379
8380 /* ACKnowledge channel activation and expect (RR) Handover Command */
8381 f_ipa_tx(1, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
8382 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
8383
8384 /* Make sure that L3 Information IE is present */
8385 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
8386 setverdict(fail, "RSL L3 Information IE is absent");
8387 return;
8388 }
8389
8390 /* Decode the L3 message and make sure it is (RR) Handover Command */
8391 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
8392 if (not match(l3_msg.header, t_RrL3Header(HANDOVER_COMMAND))) {
8393 setverdict(fail, "Failed to match Handover Command: ", l3_msg);
8394 return;
8395 }
8396
8397 /* Make sure that we've got SDCCH/8 on TS1 (expected to be hopping) */
8398 var ChannelDescription chan_desc := l3_msg.payload.ho_cmd.chan_desc;
8399 if (not match(chan_desc.chan_nr, t_RslChanNr_SDCCH8(1, ?))) {
8400 setverdict(fail, "Unexpected channel number: ", chan_desc.chan_nr);
8401 return;
8402 }
8403
8404 /* Make sure that hopping parameters (HSN/MAIO) match */
8405 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
8406
8407 /* Make sure that Cell Channel Description IE is present */
8408 if (not ispresent(l3_msg.payload.ho_cmd.cell_chan_desc)) {
8409 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
8410 return;
8411 }
8412
8413 /* Make sure that the Mobile Allocation (after time) IE is present and matches */
8414 var boolean ma_present := ispresent(l3_msg.payload.ho_cmd.mobile_allocation);
8415 if (ma_present) {
8416 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
8417 l3_msg.payload.ho_cmd.mobile_allocation.v);
8418 } else {
8419 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
8420 return;
8421 }
8422}
8423testcase TC_fh_params_handover_cmd() runs on test_CT {
8424 var FHParamsTrx fhp := f_TC_fh_params_gen();
8425
8426 f_init_vty();
8427
8428 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8 on BTS1/TRX0 */
8429 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
8430
8431 f_vty_transceive(BSCVTY, "timeslot 0");
8432 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
8433 f_vty_transceive(BSCVTY, "exit"); /* go back */
8434
8435 f_vty_transceive(BSCVTY, "timeslot 1");
8436 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8");
8437 f_vty_transceive(BSCVTY, "end"); /* we're done */
8438
8439 f_TC_fh_params_set(fhp, 1); /* Enable frequency hopping on BTS1 */
8440 f_vty_transceive(BSCVTY, "drop bts connection 1 oml");
8441
8442 f_init(2);
8443
8444 f_TC_fh_params_handover_cmd(fhp);
8445
8446 /* Disable frequency hopping on BTS1 */
8447 f_TC_fh_params_unset(fhp, 1);
8448
8449 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
8450 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
8451
8452 f_vty_transceive(BSCVTY, "timeslot 0");
8453 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
8454 f_vty_transceive(BSCVTY, "exit"); /* go back */
8455
8456 f_vty_transceive(BSCVTY, "timeslot 1");
8457 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
8458 f_vty_transceive(BSCVTY, "end"); /* we're done */
8459
8460 f_shutdown_helper();
8461}
8462
Vadim Yanitskiyca974032020-09-01 07:20:39 +07008463/* Verify the hopping parameters in System Information Type 4 */
8464testcase TC_fh_params_si4_cbch() runs on test_CT {
8465 var FHParamsTrx fhp := f_TC_fh_params_gen(tr_tn := 1);
8466 var ASP_RSL_Unitdata rx_rsl_ud;
8467 timer T := 5.0;
8468
8469 f_init_vty();
8470
8471 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8+CBCH */
8472 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
8473
8474 f_vty_transceive(BSCVTY, "timeslot 0");
8475 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
8476 f_vty_transceive(BSCVTY, "exit"); /* go back */
8477
8478 f_vty_transceive(BSCVTY, "timeslot 1");
8479 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8+cbch");
8480 f_vty_transceive(BSCVTY, "end"); /* we're done */
8481
8482 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
8483 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
8484
8485 f_init(1);
8486
8487 T.start;
8488 alt {
8489 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO(RSL_SYSTEM_INFO_4))) -> value rx_rsl_ud {
8490 var RSL_IE_Body ie := rx_rsl_ud.rsl.ies[2].body; /* FULL BCCH Information IE */
8491 var SystemInformation si := dec_SystemInformation(ie.other.payload);
8492
8493 /* Make sure that what we decoded is System Information Type 4 */
8494 if (si.header.message_type != SYSTEM_INFORMATION_TYPE_4) {
8495 setverdict(fail, "RSL FULL BCCH Information IE contains: ", si);
8496 repeat;
8497 }
8498
8499 /* Make sure that CBCH Channel Description IE is present */
8500 if (not ispresent(si.payload.si4.cbch_chan_desc)) {
8501 setverdict(fail, "CBCH Channel Description IE is absent");
8502 break;
8503 }
8504
8505 /* Finally, check the hopping parameters (HSN, MAIO) */
8506 var ChannelDescription chan_desc := si.payload.si4.cbch_chan_desc.v;
8507 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
8508
8509 /* 3GPP TS 44.018, section 9.1.36.2 "CBCH Mobile Allocation":
8510 * The CBCH Mobile Allocation IE *shall* be present if FH is enabled. */
8511 if (chan_desc.h and not ispresent(si.payload.si4.cbch_mobile_alloc)) {
8512 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
8513 break;
8514 } else if (chan_desc.h and ispresent(si.payload.si4.cbch_mobile_alloc)) {
8515 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
8516 si.payload.si4.cbch_mobile_alloc.v);
8517 }
8518 }
8519 [] IPA_RSL[0].receive { repeat; }
8520 [] T.timeout {
8521 setverdict(fail, "Timeout waiting for RSL BCCH INFOrmation (SI4)");
8522 }
8523 }
8524
8525 /* Disable frequency hopping */
8526 f_TC_fh_params_unset(fhp);
8527
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07008528 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
Vadim Yanitskiyca974032020-09-01 07:20:39 +07008529 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
8530
8531 f_vty_transceive(BSCVTY, "timeslot 0");
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07008532 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
Vadim Yanitskiyca974032020-09-01 07:20:39 +07008533 f_vty_transceive(BSCVTY, "exit"); /* go back */
8534
8535 f_vty_transceive(BSCVTY, "timeslot 1");
8536 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
8537 f_vty_transceive(BSCVTY, "end"); /* we're done */
8538
Vadim Yanitskiy21726312020-09-04 01:45:36 +07008539 f_shutdown_helper();
Vadim Yanitskiyca974032020-09-01 07:20:39 +07008540}
8541
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008542template (value) PDU_BSSAP_LE ts_BSSMAP_LE_BSSLAP(template (value) BSSLAP_PDU bsslap)
8543 := ts_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, data := enc_BSSLAP_PDU(valueof(bsslap)));
8544
8545private function f_match_bsslap(PDU_BSSAP_LE got_bsslap_msg,
8546 template (present) BSSLAP_PDU expect_bsslap)
8547{
8548 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(got_bsslap_msg.pdu.bssmap.co_info.bsslap_apdu.data);
8549 if (not match(bsslap, expect_bsslap)) {
8550 log("EXPECTING BSSLAP: ", expect_bsslap);
8551 log("GOT BSSLAP: ", bsslap);
8552 setverdict(fail, "BSSLAP is not as expected");
8553 mtc.stop;
8554 }
8555 setverdict(pass);
8556}
8557
8558/* GAD: this is an Ellipsoid point with uncertainty circle, encoded as in 3GPP TS 23.032 §7.3.2. */
8559const octetstring gad_ell_point_unc_circle := '10b0646d0d5f6627'O;
8560
8561private function f_expect_bsslap(template (present) BSSLAP_PDU expect_rx_bsslap) runs on MSC_ConnHdlr {
8562 var PDU_BSSAP_LE rx_bsslap;
8563 BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap);
8564 f_match_bsslap(rx_bsslap, expect_rx_bsslap);
8565}
8566
8567/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
8568 * Request on Lb interface. Either with or without the SMLC doing a BSSLAP TA Request. */
8569private function f_lcs_loc_req_for_active_ms(boolean do_ta_request := false) runs on MSC_ConnHdlr {
8570 f_sleep(1.0);
8571
8572 f_establish_fully(omit, omit);
8573 f_bssap_le_register_imsi(g_pars.imsi, omit);
8574
8575 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
8576 ts_CellId_CGI('262'H, '42'H, 23, 42))));
8577
8578 var PDU_BSSAP_LE plr;
8579 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
8580
8581 if (not do_ta_request) {
8582 /* verify TA Layer 3 in APDU. First the APDU type (BSSLAP), then the BSSLAP data contents. */
8583 var template BSSMAP_LE_IE_APDU expect_apdu := tr_BSSMAP_LE_APDU(BSSMAP_LE_PROT_BSSLAP, ?);
8584 if (not match(plr.pdu.bssmap.perf_loc_req.bsslap_apdu, expect_apdu)) {
8585 log("EXPECTING BSSMAP-LE APDU IE ", expect_apdu);
8586 log("GOT BSSMAP-LE APDU IE ", plr.pdu.bssmap.perf_loc_req.bsslap_apdu);
8587 setverdict(fail, "BSSMAP-LE APDU IE is not as expected");
8588 mtc.stop;
8589 }
8590 var template BSSLAP_PDU expect_ta_layer3 := tr_BSSLAP_TA_Layer3(tr_BSSLAP_IE_TA(0));
8591 var BSSLAP_PDU bsslap := dec_BSSLAP_PDU(plr.pdu.bssmap.perf_loc_req.bsslap_apdu.data);
8592 if (not match(bsslap, expect_ta_layer3)) {
8593 log("EXPECTING BSSLAP TA Layer 3: ", expect_ta_layer3);
8594 log("GOT BSSLAP: ", bsslap);
8595 setverdict(fail, "BSSLAP is not as expected");
8596 mtc.stop;
8597 }
8598 /* OsmoBSC directly sent the TA as BSSLAP APDU in the BSSMAP-LE Perform Location Request to the SMLC. The SMLC
8599 * has no need to request the TA from the BSC and directly responds. */
8600 } else {
8601 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
8602 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
8603 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
8604 }
8605
8606 /* SMLC got the TA from the BSC, now responds with geo information data. */
8607 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
8608 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
8609 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
8610
8611 /* The LCS was using an active A-interface conn. It should still remain active after this. */
8612 f_mo_l3_transceive();
8613
8614 f_perform_clear(RSL);
8615
8616 f_sleep(2.0);
8617 setverdict(pass);
8618}
8619
8620/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
8621 * Request on Lb interface. Without the SMLC doing a BSSLAP TA Request. */
8622private function f_tc_lcs_loc_req_for_active_ms(charstring id) runs on MSC_ConnHdlr {
8623 f_lcs_loc_req_for_active_ms(false);
8624}
8625testcase TC_lcs_loc_req_for_active_ms() runs on test_CT {
8626 var MSC_ConnHdlr vc_conn;
8627 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8628
8629 f_init(1, true);
8630 f_sleep(1.0);
8631 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms), pars);
8632 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01008633 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008634}
8635
8636/* With an active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
8637 * Request on Lb interface. With the SMLC doing a BSSLAP TA Request. */
8638private function f_tc_lcs_loc_req_for_active_ms_ta_req(charstring id) runs on MSC_ConnHdlr {
8639 f_lcs_loc_req_for_active_ms(true);
8640}
8641testcase TC_lcs_loc_req_for_active_ms_ta_req() runs on test_CT {
8642 var MSC_ConnHdlr vc_conn;
8643 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8644
8645 f_init(1, true);
8646 f_sleep(1.0);
8647 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_ta_req), pars);
8648 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01008649 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008650}
8651
8652/* Clear the A-interface conn only, without doing anything on Abis. Useful for LCS, for cases where there is only an A
8653 * conn without an active lchan. */
8654private function f_clear_A_conn() runs on MSC_ConnHdlr
8655{
8656 var BssmapCause cause := 0;
8657 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
8658 BSSAP.receive(tr_BSSMAP_ClearComplete);
8659 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
8660
8661 timer no_more_bssap := 5.0;
8662 no_more_bssap.start;
8663 alt {
8664 [] no_more_bssap.timeout { break; }
8665 [] BSSAP.receive(tr_BSSAP_BSSMAP) {
8666 setverdict(fail, "Expected no more BSSAP after Clear Complete");
8667 mtc.stop;
8668 }
8669 }
8670 setverdict(pass);
8671}
8672
8673/* Verify that the A-interface connection is still working, and then clear it, without doing anything on Abis. Useful
8674 * for LCS, for cases where there is only an A conn without an active lchan. */
8675private function f_verify_active_A_conn_and_clear() runs on MSC_ConnHdlr
8676{
8677 f_logp(BSCVTY, "f_verify_active_A_conn_and_clear: test A link, then clear");
8678
8679 /* When an lchan is active, we can send some L3 data from the BTS side and verify that it shows up on the other
8680 * side towards the MSC. When there is no lchan, this is not possible. To probe whether the A-interface
8681 * connection is still up, we need something that echos back on the A-interface. Another LCS request! */
8682 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
8683 ts_CellId_CGI('262'H, '42'H, 23, 42))));
8684 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?));
8685
8686 /* Right, the Perform Location Request showed up on Lb, now we can clear the A conn. */
8687 f_clear_A_conn();
8688 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
8689 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
8690}
8691
8692/* With *no* active lchan, start BSSMAP Perform Location Request on A interface, starting BSSMAP-LE Perform Location
8693 * Request on Lb interface. BSC will Page for the subscriber as soon as we (virtual SMLC) request the TA via BSSLAP.
8694 */
8695private function f_tc_lcs_loc_req_for_idle_ms(charstring id) runs on MSC_ConnHdlr {
8696 f_sleep(1.0);
8697
8698 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8699 f_bssap_le_register_imsi(g_pars.imsi, omit);
8700
8701 /* Register to receive the Paging Command */
8702 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
8703 g_chan_nr := new_chan_nr;
8704 f_rslem_register(0, g_chan_nr);
8705
8706 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
8707 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
8708 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
8709 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
8710
8711 var PDU_BSSAP_LE plr;
8712 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
8713
8714 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
8715 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
8716
8717 /* OsmoBSC needs to Page */
8718 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi)));
8719 f_logp(BSCVTY, "got Paging Command");
8720
8721 /* MS requests channel. Since the Paging was for LCS, the Paging Response does not trigger a Complete Layer 3 to
8722 * the MSC, and releases the lchan directly. */
8723 f_perform_compl_l3(RSL, ts_PAG_RESP(valueof(ts_MI_IMSI_LV(g_pars.imsi))), do_clear := false, expect_bssmap_l3 := false);
8724 f_expect_lchan_rel(RSL);
8725
8726 /* From the Paging Response, the TA is now known to the BSC, and it responds to the SMLC. */
8727
8728 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
8729
8730 /* SMLC got the TA from the BSC, now responds with geo information data. */
8731 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
8732 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
8733
8734 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
8735
8736 /* The lchan is gone, the A-interface conn was created for the LCS only.
8737 * Still it is clearly the MSC's job to decide whether to tear down the conn or not. */
8738 f_verify_active_A_conn_and_clear();
8739
8740 f_sleep(2.0);
8741 setverdict(pass);
8742}
8743testcase TC_lcs_loc_req_for_idle_ms() runs on test_CT {
8744 var MSC_ConnHdlr vc_conn;
8745 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8746
8747 f_init(1, true);
8748 f_sleep(1.0);
8749
8750 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
8751 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
8752
8753 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms), pars);
8754 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01008755 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008756}
8757
8758/* With no active lchan, start BSSMAP Perform Location Request on A interface, but omit IMSI; expect failure response.
8759 */
8760private function f_tc_lcs_loc_req_no_subscriber(charstring id) runs on MSC_ConnHdlr {
8761 f_sleep(1.0);
8762
8763 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8764 f_bssap_le_register_imsi(g_pars.imsi, omit);
8765
8766 /* provoke an abort by omitting both IMSI and IMEI */
8767 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
8768 valueof(ts_BSSMAP_Perform_Location_Request(omit,
8769 ts_CellId_CGI('262'H, '42'H, 23, 42)))));
8770 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
8771
8772 /* BSC tells MSC about failure */
8773 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
8774 locationEstimate := omit, positioningData := omit,
8775 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_DATA_MISSING_IN_REQ)));
8776
8777 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
8778 f_verify_active_A_conn_and_clear();
8779
8780 f_sleep(2.0);
8781 setverdict(pass);
8782}
8783testcase TC_lcs_loc_req_no_subscriber() runs on test_CT {
8784 var MSC_ConnHdlr vc_conn;
8785 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8786
8787 f_init(1, true);
8788 f_sleep(1.0);
8789
8790 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
8791 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
8792
8793 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_no_subscriber), pars);
8794 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01008795 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008796}
8797
8798/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
8799 * BSSMAP-LE Perform Location Response (before or after sending a BSSLAP TA Request) */
8800private function f_lcs_loc_req_for_active_ms_le_timeout(boolean do_ta) runs on MSC_ConnHdlr {
8801 f_sleep(1.0);
8802
8803 f_establish_fully(omit, omit);
8804 f_bssap_le_register_imsi(g_pars.imsi, omit);
8805
8806 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
8807 ts_CellId_CGI('262'H, '42'H, 23, 42))));
8808
8809 var PDU_BSSAP_LE plr;
8810 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
8811
8812 if (do_ta) {
8813 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
8814 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
8815 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
8816 }
8817
8818 /* SMLC fails to respond, BSC runs into timeout */
8819 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocAbort(BSSMAP_LE_LCS_CAUSE_SYSTEM_FAILURE));
8820 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
8821
8822 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
8823 locationEstimate := omit, positioningData := omit,
8824 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_SYSTEM_FAILURE)));
8825
8826 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
8827 f_verify_active_A_conn_and_clear();
8828
8829 f_sleep(2.0);
8830 setverdict(pass);
8831}
8832
8833/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
8834 * BSSMAP-LE Perform Location Response, without sending a BSSLAP TA Request. */
8835private function f_tc_lcs_loc_req_for_active_ms_le_timeout(charstring id) runs on MSC_ConnHdlr {
8836 f_lcs_loc_req_for_active_ms_le_timeout(false);
8837}
8838
8839testcase TC_lcs_loc_req_for_active_ms_le_timeout() runs on test_CT {
8840 var MSC_ConnHdlr vc_conn;
8841 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8842
8843 f_init(1, true);
8844 f_sleep(1.0);
8845 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout), pars);
8846 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01008847 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008848}
8849
8850/* With an active lchan, start a Perform Location Request on the A-interface, but virtual SMLC does not answer with
8851 * BSSMAP-LE Perform Location Response, after sending a BSSLAP TA Request. */
8852private function f_tc_lcs_loc_req_for_active_ms_le_timeout2(charstring id) runs on MSC_ConnHdlr {
8853 f_lcs_loc_req_for_active_ms_le_timeout(true);
8854}
8855
8856testcase TC_lcs_loc_req_for_active_ms_le_timeout2() runs on test_CT {
8857 var MSC_ConnHdlr vc_conn;
8858 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8859
8860 f_init(1, true);
8861 f_sleep(1.0);
8862 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_active_ms_le_timeout2), pars);
8863 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01008864 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008865}
8866
8867/* With *no* active lchan, start a Perform Location Request, expecting that the MS will be Paged. */
8868private function f_tc_lcs_loc_req_for_idle_ms_no_pag_resp(charstring id) runs on MSC_ConnHdlr {
8869 f_sleep(1.0);
8870
8871 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8872 f_bssap_le_register_imsi(g_pars.imsi, omit);
8873
8874 /* Register to receive the Paging Command */
8875 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
8876 g_chan_nr := new_chan_nr;
8877 f_rslem_register(0, g_chan_nr);
8878
8879 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
8880 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
8881 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
8882 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
8883
8884 var PDU_BSSAP_LE plr;
8885 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
8886
8887 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
8888 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
8889
8890 /* OsmoBSC needs to Page */
8891 var PDU_BSSAP_LE rx_bsslap;
8892 alt {
8893 [] RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(g_pars.imsi))) {
8894 f_logp(BSCVTY, "got Paging Command");
8895 repeat;
8896 }
8897 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
8898 /* MS does not respond to Paging, TA Req runs into timeout. */
8899 f_match_bsslap(rx_bsslap, tr_BSSLAP_Abort(?));
8900 }
8901 }
8902
8903 /* SMLC responds with failure */
8904 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(omit, BSSMAP_LE_LCS_CAUSE_REQUEST_ABORTED));
8905 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
8906
8907 /* BSC tells MSC about failure */
8908 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(
8909 locationEstimate := omit, positioningData := omit,
8910 lCS_Cause := tr_BSSMAP_LcsCause(BSSMAP_LCS_CAUSE_REQUEST_ABORTED)));
8911
8912 /* There is no lchan. Still the MSC's job to decide whether to tear down the conn or not. */
8913 f_verify_active_A_conn_and_clear();
8914
8915 f_sleep(2.0);
8916 setverdict(pass);
8917}
8918testcase TC_lcs_loc_req_for_idle_ms_no_pag_resp() runs on test_CT {
8919 var MSC_ConnHdlr vc_conn;
8920 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8921
8922 f_init(1, true);
8923 f_sleep(1.0);
8924
8925 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
8926 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
8927
8928 vc_conn := f_start_handler(refers(f_tc_lcs_loc_req_for_idle_ms_no_pag_resp), pars);
8929 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01008930 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008931}
8932
8933/* During an ongoing Location Request, the MS sends a CM Service Request. Expect the same A-conn to be re-used / taken
8934 * over. */
8935private function f_tc_cm_service_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
8936 f_sleep(1.0);
8937
8938 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
8939 f_bssap_le_register_imsi(g_pars.imsi, omit);
8940
8941 /* Register to receive the Paging Command */
8942 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
8943 g_chan_nr := new_chan_nr;
8944 f_rslem_register(0, g_chan_nr);
8945
8946 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
8947 valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
8948 ts_CellId_CGI('001'H, '01'H, 1, 0)))));
8949 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
8950
8951 var PDU_BSSAP_LE plr;
8952 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
8953
8954 /* As the A-interface conn was established for LCS, the MS coincidentally decides to issue a CM Service Request
8955 * and establish Layer 3. It should use the existing A-interface conn. */
8956 f_perform_compl_l3(RSL, valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV(g_pars.imsi)))),
8957 do_clear := false, expect_bssmap_l3 := true);
8958
8959 /* SMLC wants to ask the TA from the BSC explicitly in a BSSLAP TA Request message */
8960 BSSAP_LE.send(ts_BSSMAP_LE_BSSLAP(ts_BSSLAP_TA_Req));
8961
8962 /* OsmoBSC already has an lchan, no need to Page, just returns the TA */
8963 f_expect_bsslap(tr_BSSLAP_TA_Resp(?, ?));
8964
8965 /* SMLC got the TA from the BSC, now responds with geo information data. */
8966 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
8967 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
8968 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
8969
8970 /* The lchan should still exist, it was from a CM Service Request. */
8971 f_mo_l3_transceive();
8972
8973 f_perform_clear(RSL);
8974
8975 f_sleep(2.0);
8976 setverdict(pass);
8977}
8978testcase TC_cm_service_during_lcs_loc_req() runs on test_CT {
8979 var MSC_ConnHdlr vc_conn;
8980 var TestHdlrParams pars := f_gen_test_hdlr_pars();
8981
8982 f_init(1, true);
8983 f_sleep(1.0);
8984
8985 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
8986 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
8987
8988 vc_conn := f_start_handler(refers(f_tc_cm_service_during_lcs_loc_req), pars);
8989 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01008990 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02008991}
8992
8993/* During an ongoing Perform Location Request, do a Handover, an expect a BSSLAP Reset message from the BSC to indicate
8994 * the new lchan after handover. */
8995private function f_tc_ho_during_lcs_loc_req(charstring id) runs on MSC_ConnHdlr {
8996 f_sleep(1.0);
8997
8998 f_establish_fully(omit, omit);
8999 f_bssap_le_register_imsi(g_pars.imsi, omit);
9000
9001 BSSAP.send(valueof(ts_BSSMAP_Perform_Location_Request(ts_BSSMAP_Imsi(g_pars.imsi),
9002 ts_CellId_CGI('262'H, '42'H, 23, 42))));
9003
9004 var PDU_BSSAP_LE plr;
9005 BSSAP_LE.receive(tr_BSSMAP_LE_PerfLocReq(BSSMAP_LE_LOC_INFO_CURRENT_GEOGRAPHIC_LOC, ?, ?)) -> value(plr);
9006
9007 /* SMLC ponders the Location Request, in the meantime the BSC decides to handover */
9008 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
9009
9010 var HandoverState hs := {
9011 rr_ho_cmpl_seen := false,
9012 handover_done := false,
9013 old_chan_nr := -
9014 };
9015 /* issue hand-over command on VTY */
9016 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
9017 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
9018 f_rslem_suspend(RSL1_PROC);
9019
9020 /* From the MGW perspective, a handover is is characterized by
9021 * performing one MDCX operation with the MGW. So we expect to see
9022 * one more MDCX during handover. */
9023 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
9024
9025 alt {
9026 [] as_handover(hs);
9027 }
9028
9029 var PDU_BSSAP_LE rx_bsslap;
9030
9031 interleave {
9032 /* Expect the BSC to inform the MSC about the handover */
9033 [] BSSAP.receive(tr_BSSMAP_HandoverPerformed);
9034
9035 /* Expect the BSC to inform the SMLC about the handover */
9036 [] BSSAP_LE.receive(tr_BSSMAP_LE_ConnInfo(BSSMAP_LE_PROT_BSSLAP, ?)) -> value(rx_bsslap) {
9037 f_match_bsslap(rx_bsslap, tr_BSSLAP_Reset(BSSLAP_CAUSE_INTRA_BSS_HO));
9038 }
9039 }
9040
9041 /* SMLC now responds with geo information data. */
9042 BSSAP_LE.send(ts_BSSMAP_LE_PerfLocResp(gad_ell_point_unc_circle, omit));
9043 BSSAP_LE.receive(BSSAP_LE_Conn_Prim:CONN_PRIM_DISC_IND);
9044 BSSAP.receive(tr_BSSMAP_Perform_Location_Response(tr_BSSMAP_IE_LocationEstimate(gad_ell_point_unc_circle)));
9045
9046 /* lchan still active */
9047 f_mo_l3_transceive(RSL1);
9048
9049 /* MSC decides it is done now. */
9050 f_perform_clear(RSL1);
9051
9052 f_sleep(2.0);
9053 setverdict(pass);
9054}
9055testcase TC_ho_during_lcs_loc_req() runs on test_CT {
9056 var MSC_ConnHdlr vc_conn;
9057 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9058
9059 f_init(2, true);
9060 f_sleep(1.0);
9061 vc_conn := f_start_handler(refers(f_tc_ho_during_lcs_loc_req), pars);
9062 vc_conn.done;
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009063 f_shutdown_helper();
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009064}
9065
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009066/* Attempt Complete Layer 3 without any MSC available (OS#4832) */
9067private function f_tc_no_msc(charstring id) runs on MSC_ConnHdlr {
9068 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
9069
9070 /* Also disable attach for the single connected MSC */
9071 f_vty_msc_allow_attach(BSCVTY, { false });
9072
9073 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) ));
9074 f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
9075
9076 /* No MSC is found, expecting a proper release on RSL */
9077 interleave {
9078 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
9079 f_logp(BSCVTY, "Got RSL RR Release");
9080 }
9081 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
9082 f_logp(BSCVTY, "Got RSL Deact SACCH");
9083 }
9084 [] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
9085 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
9086 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
9087 }
9088 }
9089 setverdict(pass);
9090}
9091testcase TC_no_msc() runs on test_CT {
9092
9093 f_init(1, true);
9094 f_sleep(1.0);
9095 var MSC_ConnHdlr vc_conn;
9096 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9097
9098 f_ctrs_bsc_init(counternames_bsc_mscpool);
9099
9100 vc_conn := f_start_handler(refers(f_tc_no_msc), pars);
9101 vc_conn.done;
9102
9103 f_ctrs_bsc_add("mscpool:subscr:no_msc");
9104 f_ctrs_bsc_verify();
Vadim Yanitskiy8ca840e2021-01-03 14:16:35 +01009105 f_shutdown_helper();
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009106}
9107
Harald Welte0ea2d5e2018-04-07 21:40:29 +02009108/* Dyn PDCH todo:
9109 * activate OSMO as TCH/F
9110 * activate OSMO as TCH/H
9111 * does the BSC-located PCU socket get the updated INFO?
9112 * what if no PCU is connected at the time?
9113 * is the info correct on delayed PCU (re)connect?
9114 */
Harald Welte94e0c342018-04-07 11:33:23 +02009115
Neels Hofmeyr87857ec2021-04-25 16:17:47 +00009116private function f_TC_refuse_mode_modif_to_vamos(charstring id) runs on MSC_ConnHdlr {
9117 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
9118 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
9119
9120 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
9121 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
9122 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
9123 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
9124 g_pars.ass_codec_list.codecElements[0];
9125 if (isvalue(g_pars.expect_mr_s0_s7)) {
9126 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
9127 g_pars.expect_mr_s0_s7;
9128 }
9129 }
9130 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
9131 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
9132 log("expecting ASS COMPL like this: ", exp_compl);
9133
9134 f_establish_fully(ass_cmd, exp_compl);
9135
Neels Hofmeyr8746b0d2021-06-01 17:25:39 +02009136 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 +00009137
9138 var RSL_Message rsl;
9139
9140 timer T := 5.0;
9141 T.start;
9142 alt {
9143 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
9144 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
9145 log("Rx L3 from net: ", l3);
9146 if (ischosen(l3.msgs.rrm.channelModeModify)) {
9147 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
9148 mtc.stop;
9149 }
9150 }
9151 [] RSL.receive(tr_RSL_MODE_MODIFY_REQ(g_chan_nr, ?)) -> value rsl {
9152 setverdict(fail, "Mode Modify to VAMOS succeeded even though BTS does not support VAMOS");
9153 mtc.stop;
9154 }
9155 [] T.timeout {
9156 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related Mode Modify should happen. */
9157 setverdict(pass);
9158 }
9159 }
9160 T.stop;
9161}
9162
9163/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel Mode Modify to VAMOS mode is refused by
9164 * osmo-bsc. */
9165testcase TC_refuse_mode_modif_to_vamos() runs on test_CT {
9166 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9167 var MSC_ConnHdlr vc_conn;
9168
9169 f_init(1, true);
9170 f_sleep(1.0);
9171
9172 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
9173 vc_conn := f_start_handler(refers(f_TC_refuse_mode_modif_to_vamos), pars);
9174 vc_conn.done;
9175 f_shutdown_helper();
9176}
9177
9178/* The BSC does *not* indicate BTS_FEAT_VAMOS; make sure that a channel activation to VAMOS mode is refused by osmo-bsc.
9179 */
9180testcase TC_refuse_chan_act_to_vamos() runs on test_CT {
9181 f_init_vty();
9182
9183 f_init(1, false);
9184 f_sleep(1.0);
9185
9186 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 activate-vamos fr");
9187
9188 var ASP_RSL_Unitdata rx_rsl_ud;
9189 timer T := 5.0;
9190
9191 T.start;
9192 alt {
9193 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(?, IPAC_PROTO_RSL_TRX0)) -> value rx_rsl_ud {
9194 if (rx_rsl_ud.rsl.msg_type == RSL_MT_CHAN_ACTIV) {
9195 T.stop;
9196 setverdict(fail, "CHANnel ACTivate in VAMOS mode succeeded even though BTS does not support VAMOS");
9197 mtc.stop;
9198 }
9199 repeat;
9200 }
9201 [] T.timeout {
9202 /* The BTS does not exhibit BTS_FEAT_VAMOS, so no VAMOS related CHANnel ACTivate should happen. */
9203 setverdict(pass);
9204 }
9205 }
9206}
9207
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009208private function f_TC_reassignment_codec(charstring id) runs on MSC_ConnHdlr {
9209 /* First fully set up a speech lchan */
9210 f_TC_assignment_codec(id);
9211
9212 /* Trigger re-assignment to another lchan */
9213 var AssignmentState assignment_st := valueof(ts_AssignmentStateInit);
9214
9215 /* Re-Assignment should tell the MGW endpoint the new lchan's RTP address and port, so expecting to see exactly
9216 * one MDCX on MGCP. */
9217 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].mdcx_seen_exp + 1;
9218
9219 /* The new lchan will see all-new IPAC_CRCX and IPAC_MDCX messages telling the BTS the same RTP address and port
9220 * as the old lchan used. */
9221 g_media.bts.ipa_crcx_seen := false;
9222 g_media.bts.ipa_mdcx_seen := false;
9223
9224 /* Send different BTS side RTP port number for the new lchan */
9225 g_media.bts.bts.port_nr := 4223;
9226
9227 f_rslem_register(0, valueof(ts_RslChanNr_Bm(2))); /* <-- FIXME: can we somehow infer the timeslot that will be used? */
9228
9229 /* Trigger re-assignment. */
9230 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot " & int2str(g_chan_nr.tn) & " sub-slot 0 assignment");
9231
9232 timer T := 5.0;
9233 T.start;
9234 alt {
9235 [] as_assignment(assignment_st);
9236 [] as_Media();
9237 [] T.timeout {
9238 break;
9239 }
9240 }
9241
9242 if (not assignment_st.assignment_done) {
9243 setverdict(fail, "Assignment did not complete");
9244 mtc.stop;
9245 }
9246
9247 f_check_mgcp_expectations()
9248 setverdict(pass);
9249
9250 f_sleep(2.0);
9251 log("show lchan summary: ", f_vty_transceive_ret(BSCVTY, "show lchan summary"));
9252
9253 /* Instruct BSC to clear channel */
9254 var BssmapCause cause := 0;
9255 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
9256 interleave {
9257 [] MGCP.receive(tr_DLCX) {}
9258 [] MGCP.receive(tr_DLCX) {}
9259 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {}
9260 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {}
9261 [] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
9262 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
9263 }
9264 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
9265 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
9266 }
9267 }
9268
9269 f_sleep(0.5);
9270}
9271
9272testcase TC_reassignment_fr() runs on test_CT {
9273 var TestHdlrParams pars := f_gen_test_hdlr_pars();
9274 var MSC_ConnHdlr vc_conn;
9275
9276 f_init(1, true);
9277 f_sleep(1.0);
9278
9279 f_ctrs_bsc_and_bts_init();
9280
9281 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
9282 vc_conn := f_start_handler(refers(f_TC_reassignment_codec), pars);
9283 vc_conn.done;
9284
9285 /* from f_establish_fully() */
9286 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
9287 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
9288 /* from re-assignment */
9289 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
9290 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
9291 f_ctrs_bsc_and_bts_verify();
9292 f_shutdown_helper();
9293}
9294
Neels Hofmeyr87857ec2021-04-25 16:17:47 +00009295
Harald Welte28d943e2017-11-25 15:00:50 +01009296control {
Harald Welte898113b2018-01-31 18:32:21 +01009297 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +01009298 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01009299 execute( TC_ctrl_msc0_connection_status() );
Harald Welte96c94412017-12-09 03:12:45 +01009300 execute( TC_ctrl() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +02009301 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER) {
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02009302 execute( TC_ctrl_location() );
9303 }
Harald Welte898113b2018-01-31 18:32:21 +01009304
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02009305 execute( TC_si_default() );
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02009306 execute( TC_si2quater_2_earfcns() );
9307 execute( TC_si2quater_3_earfcns() );
9308 execute( TC_si2quater_4_earfcns() );
9309 execute( TC_si2quater_5_earfcns() );
9310 execute( TC_si2quater_6_earfcns() );
Neels Hofmeyrad132f22020-07-08 02:20:16 +02009311 execute( TC_si2quater_12_earfcns() );
9312 execute( TC_si2quater_23_earfcns() );
9313 execute( TC_si2quater_32_earfcns() );
9314 execute( TC_si2quater_33_earfcns() );
9315 execute( TC_si2quater_42_earfcns() );
9316 execute( TC_si2quater_48_earfcns() );
9317 execute( TC_si2quater_49_earfcns() );
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02009318 execute( TC_si_acc_rotate() );
Alexander Couzens4ad3a352020-09-10 22:29:12 +02009319 execute( TC_si_acc_ramp_rotate() );
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02009320
Harald Welte898113b2018-01-31 18:32:21 +01009321 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +01009322 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +01009323 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +01009324 execute( TC_chan_act_ack_noest() );
Philipp Maier9c60a622020-07-09 15:08:46 +02009325 execute( TC_chan_act_ack_noest_emerg() );
Philipp Maier606f07d2020-08-12 17:21:58 +02009326 execute( TC_chan_rqd_emerg_deny() );
Harald Welteae026692017-12-09 01:03:01 +01009327 execute( TC_chan_act_ack_est_ind_noreply() );
9328 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +01009329 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +01009330 execute( TC_chan_exhaustion() );
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07009331 execute( TC_chan_deact_silence() );
Harald Welte4003d112017-12-09 22:35:39 +01009332 execute( TC_chan_rel_rll_rel_ind() );
9333 execute( TC_chan_rel_conn_fail() );
9334 execute( TC_chan_rel_hard_clear() );
Pau Espin Pedrol841b90d2021-04-15 16:42:52 +02009335 execute( TC_chan_rel_last_eutran_plmn_hard_clear_no_csfb() );
9336 execute( TC_chan_rel_last_eutran_plmn_hard_clear_csfb() );
Harald Welte99787102019-02-04 10:41:36 +01009337 execute( TC_chan_rel_hard_clear_csfb() );
Harald Welted8c36cd2017-12-09 23:05:31 +01009338 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +02009339 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +01009340 execute( TC_chan_rel_a_reset() );
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01009341 execute( TC_chan_rel_sccp_tiar_timeout() );
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02009342 execute( TC_chan_rel_rr_cause() );
Harald Welte6f521d82017-12-11 19:52:02 +01009343
Harald Weltecfe2c962017-12-15 12:09:32 +01009344 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +01009345
9346 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +01009347 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +01009348 execute( TC_assignment_csd() );
9349 execute( TC_assignment_ctm() );
9350 execute( TC_assignment_sign() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +02009351 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
9352 execute( TC_assignment_aoip_tla_v6() );
9353 }
Harald Welte235ebf12017-12-15 14:18:16 +01009354 execute( TC_assignment_fr_a5_0() );
9355 execute( TC_assignment_fr_a5_1() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +02009356 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte8f67d1d2018-05-25 20:38:42 +02009357 execute( TC_assignment_fr_a5_1_codec_missing() );
9358 }
Harald Welte235ebf12017-12-15 14:18:16 +01009359 execute( TC_assignment_fr_a5_3() );
Neels Hofmeyr0d8ec532021-06-11 00:09:48 +02009360 execute( TC_assignment_fr_a5_4() );
Neels Hofmeyr0faeb7a2021-06-10 23:59:35 +02009361 execute( TC_assignment_fr_a5_4_fail() );
Neels Hofmeyr04d6e6a2021-06-11 00:10:02 +02009362 execute( TC_assignment_fr_a5_not_sup() );
Harald Welte3c86ea02018-05-10 22:28:05 +02009363 execute( TC_ciph_mode_a5_0() );
9364 execute( TC_ciph_mode_a5_1() );
Oliver Smith50b98122021-07-09 15:00:28 +02009365 execute( TC_ciph_mode_a5_2_0() );
Oliver Smith1dff88d2021-07-09 08:45:51 +02009366 execute( TC_ciph_mode_a5_2_1() );
Harald Welte3c86ea02018-05-10 22:28:05 +02009367 execute( TC_ciph_mode_a5_3() );
Neels Hofmeyr81ad27f2021-06-11 00:09:40 +02009368 execute( TC_ciph_mode_a5_4() );
Harald Welte16a4adf2017-12-14 18:54:01 +01009369
Harald Welte60aa5762018-03-21 19:33:13 +01009370 execute( TC_assignment_codec_fr() );
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02009371 execute( TC_assignment_codec_fr_by_mode_modify() );
Harald Welte60aa5762018-03-21 19:33:13 +01009372 execute( TC_assignment_codec_hr() );
9373 execute( TC_assignment_codec_efr() );
9374 execute( TC_assignment_codec_amr_f() );
9375 execute( TC_assignment_codec_amr_h() );
Philipp Maier8a581d22019-03-26 18:32:48 +01009376
Neels Hofmeyrf246a922020-05-13 02:27:10 +02009377 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier8a581d22019-03-26 18:32:48 +01009378 execute( TC_assignment_codec_amr_f_S1() );
9379 execute( TC_assignment_codec_amr_h_S1() );
9380 execute( TC_assignment_codec_amr_f_S124() );
9381 execute( TC_assignment_codec_amr_h_S124() );
9382 execute( TC_assignment_codec_amr_f_S0() );
9383 execute( TC_assignment_codec_amr_f_S02() );
9384 execute( TC_assignment_codec_amr_f_S024() );
9385 execute( TC_assignment_codec_amr_f_S0247() );
9386 execute( TC_assignment_codec_amr_h_S0() );
9387 execute( TC_assignment_codec_amr_h_S02() );
9388 execute( TC_assignment_codec_amr_h_S024() );
9389 execute( TC_assignment_codec_amr_h_S0247() );
9390 execute( TC_assignment_codec_amr_f_S01234567() );
9391 execute( TC_assignment_codec_amr_f_S0234567() );
9392 execute( TC_assignment_codec_amr_f_zero() );
9393 execute( TC_assignment_codec_amr_f_unsupp() );
9394 execute( TC_assignment_codec_amr_h_S7() );
Neels Hofmeyr21863562020-11-26 00:34:33 +00009395 execute( TC_assignment_codec_amr_f_start_mode_auto() );
9396 execute( TC_assignment_codec_amr_h_start_mode_auto() );
Neels Hofmeyr3eb94562020-11-26 02:40:26 +00009397 execute( TC_assignment_codec_amr_f_start_mode_4() );
9398 execute( TC_assignment_codec_amr_h_start_mode_4() );
Neels Hofmeyr454d7922020-11-26 02:24:57 +00009399 execute( TC_assignment_codec_amr_startmode_cruft() );
Philipp Maier8a581d22019-03-26 18:32:48 +01009400 }
Harald Welte60aa5762018-03-21 19:33:13 +01009401
Philipp Maierac09bfc2019-01-08 13:41:39 +01009402 execute( TC_assignment_codec_fr_exhausted_req_hr() );
9403 execute( TC_assignment_codec_fr_exhausted_req_fr() );
9404 execute( TC_assignment_codec_fr_exhausted_req_fr_hr() );
9405 execute( TC_assignment_codec_fr_exhausted_req_hr_fr() );
9406 execute( TC_assignment_codec_hr_exhausted_req_fr() );
9407 execute( TC_assignment_codec_hr_exhausted_req_hr() );
9408 execute( TC_assignment_codec_hr_exhausted_req_hr_fr() );
9409 execute( TC_assignment_codec_hr_exhausted_req_fr_hr() );
9410 execute( TC_assignment_codec_req_hr_fr() );
9411 execute( TC_assignment_codec_req_fr_hr() );
9412
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +02009413 if (mp_enable_osmux_test) {
9414 execute( TC_assignment_osmux() );
9415 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02009416
Harald Welte898113b2018-01-31 18:32:21 +01009417 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +01009418 execute( TC_rll_est_ind_inact_lchan() );
9419 execute( TC_rll_est_ind_inval_sapi1() );
9420 execute( TC_rll_est_ind_inval_sapi3() );
9421 execute( TC_rll_est_ind_inval_sacch() );
9422
Vadim Yanitskiy61f784a2020-10-01 21:12:19 +07009423 /* DLCI / RSL Link ID conversion for MO/MT messages on SAPI0/SAPI3 */
9424 execute( TC_tch_dlci_link_id_sapi() );
9425
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07009426 /* SAPI N Reject triggered by RLL establishment failures */
9427 execute( TC_rll_rel_ind_sapi_n_reject() );
9428 execute( TC_rll_err_ind_sapi_n_reject() );
9429 execute( TC_rll_timeout_sapi_n_reject() );
9430
Harald Welte898113b2018-01-31 18:32:21 +01009431 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +01009432 execute( TC_paging_imsi_nochan() );
9433 execute( TC_paging_tmsi_nochan() );
9434 execute( TC_paging_tmsi_any() );
9435 execute( TC_paging_tmsi_sdcch() );
9436 execute( TC_paging_tmsi_tch_f() );
9437 execute( TC_paging_tmsi_tch_hf() );
9438 execute( TC_paging_imsi_nochan_cgi() );
9439 execute( TC_paging_imsi_nochan_lac_ci() );
9440 execute( TC_paging_imsi_nochan_ci() );
9441 execute( TC_paging_imsi_nochan_lai() );
9442 execute( TC_paging_imsi_nochan_lac() );
9443 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +01009444 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
9445 execute( TC_paging_imsi_nochan_rnc() );
9446 execute( TC_paging_imsi_nochan_lac_rnc() );
9447 execute( TC_paging_imsi_nochan_lacs() );
9448 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +01009449 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +01009450 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +01009451 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +01009452 execute( TC_paging_counter() );
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01009453 execute( TC_paging_resp_unsol() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +01009454
9455 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +01009456 execute( TC_rsl_unknown_unit_id() );
9457
9458 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +01009459
9460 execute( TC_classmark() );
Harald Welteeddf0e92020-06-21 19:42:15 +02009461 execute( TC_common_id() );
Harald Welte898113b2018-01-31 18:32:21 +01009462 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +01009463 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +01009464 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +01009465 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +01009466 execute( TC_err_84_unknown_msg() );
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01009467
Harald Welte261af4b2018-02-12 21:20:39 +01009468 execute( TC_ho_int() );
Neels Hofmeyraf88d9d2021-06-21 02:14:27 +02009469 execute( TC_ho_int_a5_0() );
9470 execute( TC_ho_int_a5_1() );
9471 execute( TC_ho_int_a5_3() );
9472 execute( TC_ho_int_a5_4() );
Neels Hofmeyr5f144212020-11-03 15:41:58 +00009473 execute( TC_ho_int_radio_link_failure() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01009474
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01009475 execute( TC_ho_out_of_this_bsc() );
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02009476 execute( TC_ho_out_fail_no_msc_response() );
9477 execute( TC_ho_out_fail_rr_ho_failure() );
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02009478 execute( TC_ho_out_fail_no_result_after_ho_cmd() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01009479
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01009480 execute( TC_ho_into_this_bsc() );
Neels Hofmeyr8ebf19c2021-06-21 05:24:01 +02009481 execute( TC_ho_into_this_bsc_a5_0() );
9482 execute( TC_ho_into_this_bsc_a5_1() );
9483 execute( TC_ho_into_this_bsc_a5_3() );
9484 execute( TC_ho_into_this_bsc_a5_4() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +02009485 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
9486 execute( TC_ho_into_this_bsc_tla_v6() );
9487 }
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +02009488 execute( TC_srvcc_eutran_to_geran() );
Pau Espin Pedrol35801c32021-04-19 13:03:20 +02009489 execute( TC_srvcc_eutran_to_geran_ho_out() );
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +02009490 execute( TC_srvcc_eutran_to_geran_forbid_fast_return() );
9491 execute( TC_srvcc_eutran_to_geran_ho_out_forbid_fast_return() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01009492 execute( TC_ho_in_fail_msc_clears() );
9493 execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
9494 execute( TC_ho_in_fail_no_detect() );
9495 execute( TC_ho_in_fail_no_detect2() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01009496
Neels Hofmeyr91401012019-07-11 00:42:35 +02009497 execute( TC_ho_neighbor_config_1() );
9498 execute( TC_ho_neighbor_config_2() );
9499 execute( TC_ho_neighbor_config_3() );
9500 execute( TC_ho_neighbor_config_4() );
9501 execute( TC_ho_neighbor_config_5() );
9502 execute( TC_ho_neighbor_config_6() );
9503 execute( TC_ho_neighbor_config_7() );
9504
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01009505 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01009506 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01009507 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +02009508
9509 execute( TC_dyn_pdch_ipa_act_deact() );
9510 execute( TC_dyn_pdch_ipa_act_nack() );
9511 execute( TC_dyn_pdch_osmo_act_deact() );
9512 execute( TC_dyn_pdch_osmo_act_nack() );
Pau Espin Pedrol5b381082021-06-28 17:14:03 +02009513 execute( TC_dyn_ts_sdcch8_act_deact() );
Pau Espin Pedrol0953bf82021-07-09 13:20:19 +02009514 execute (TC_dyn_ts_sdcch8_tch_call_act_deact() );
Pau Espin Pedrolcdf26142021-06-28 17:14:03 +02009515 execute( TC_dyn_ts_sdcch8_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +02009516
Stefan Sperling0796a822018-10-05 13:01:39 +02009517 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02009518 execute( TC_chopped_ipa_payload() );
Stefan Sperling0796a822018-10-05 13:01:39 +02009519
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01009520 /* Power control related */
9521 execute( TC_assignment_verify_ms_power_params_ie() );
Vadim Yanitskiy4b233042021-06-30 00:58:43 +02009522 execute( TC_c0_power_red_mode() );
Neels Hofmeyr4f118412020-06-04 15:25:10 +02009523
9524 /* MSC pooling */
9525 /* FIXME: in SCCPlite, indicating how many MSCs should be connected does currently not work. Since
9526 * RESET->RESET-ACK is unconditionally negotiated for all configured MSCs, they always all appear as connected
9527 * to osmo-bsc. The MSC pooling tests however require disconnecting selected MSCs, and hence don't work out as
9528 * intended on SCCPlite. So for now, run these only for SCCP/M3UA. */
9529 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
9530 execute( TC_mscpool_L3Compl_on_1_msc() );
9531 execute( TC_mscpool_L3Complete_by_imsi_round_robin() );
9532 execute( TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() );
9533 execute( TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() );
9534 execute( TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() );
9535 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() );
9536 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_1() );
9537 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_2() );
9538 execute( TC_mscpool_LU_by_tmsi_from_other_PLMN() );
9539 execute( TC_mscpool_paging_and_response_imsi() );
9540 execute( TC_mscpool_paging_and_response_tmsi() );
9541 execute( TC_mscpool_no_allow_attach_round_robin() );
9542 execute( TC_mscpool_no_allow_attach_valid_nri() );
9543 }
9544
Harald Welte99f3ca02018-06-14 13:40:29 +02009545 /* at bottom as they might crash OsmoBSC before OS#3182 is fixed */
9546 execute( TC_early_conn_fail() );
9547 execute( TC_late_conn_fail() );
9548
Philipp Maier783681c2020-07-16 16:47:06 +02009549 /* Emergency call handling (deny / allow) */
9550 execute( TC_assignment_emerg_setup_allow() );
9551 execute( TC_assignment_emerg_setup_deny_msc() );
9552 execute( TC_assignment_emerg_setup_deny_bts() );
Philipp Maier82812002020-08-13 18:48:27 +02009553 execute( TC_emerg_premption() );
9554
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07009555 /* Frequency hopping parameters handling */
9556 execute( TC_fh_params_chan_activ() );
9557 execute( TC_fh_params_imm_ass() );
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07009558 execute( TC_fh_params_assignment_cmd() );
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07009559 execute( TC_fh_params_handover_cmd() );
Vadim Yanitskiyca974032020-09-01 07:20:39 +07009560 execute( TC_fh_params_si4_cbch() );
Neels Hofmeyr2b910dc2020-10-01 06:36:04 +02009561
9562 if (mp_enable_lcs_tests) {
9563 execute( TC_lcs_loc_req_for_active_ms() );
9564 execute( TC_lcs_loc_req_for_active_ms_ta_req() );
9565 execute( TC_lcs_loc_req_for_idle_ms() );
9566 execute( TC_lcs_loc_req_no_subscriber() );
9567 execute( TC_lcs_loc_req_for_active_ms_le_timeout() );
9568 execute( TC_lcs_loc_req_for_active_ms_le_timeout2() );
9569 execute( TC_lcs_loc_req_for_idle_ms_no_pag_resp() );
9570 execute( TC_cm_service_during_lcs_loc_req() );
9571 execute( TC_ho_during_lcs_loc_req() );
9572 }
Neels Hofmeyrbf037052020-10-28 22:52:02 +00009573
9574 execute( TC_no_msc() );
Neels Hofmeyr87857ec2021-04-25 16:17:47 +00009575
9576 execute( TC_refuse_chan_act_to_vamos() );
9577 execute( TC_refuse_mode_modif_to_vamos() );
Neels Hofmeyrd2d9f332021-04-28 22:23:36 +00009578
9579 execute( TC_reassignment_fr() );
Harald Welte28d943e2017-11-25 15:00:50 +01009580}
9581
9582}