blob: 0632852a86b2ed36b27cdf8179c2c88c52ff3812 [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 Hofmeyr4f118412020-06-04 15:25:10 +020023import from Misc_Helpers all;
Harald Welte4003d112017-12-09 22:35:39 +010024import from General_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010025import from Osmocom_Types all;
Harald Welteae026692017-12-09 01:03:01 +010026import from GSM_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +010027import from IPL4asp_Types all;
28
Harald Welte6f521d82017-12-11 19:52:02 +010029import from BSSAP_Types all;
Harald Welte6811d102019-04-14 22:23:14 +020030import from RAN_Adapter all;
Harald Welteae026692017-12-09 01:03:01 +010031import from BSSAP_CodecPort all;
32import from BSSMAP_Templates all;
Harald Welte28d943e2017-11-25 15:00:50 +010033import from IPA_Emulation all;
Stefan Sperling830dc9d2018-02-12 21:08:28 +010034import from IPA_CodecPort all;
Harald Welteae026692017-12-09 01:03:01 +010035import from IPA_Types all;
Stefan Sperling0796a822018-10-05 13:01:39 +020036import from IPA_Testing all;
Harald Welteae026692017-12-09 01:03:01 +010037import from RSL_Types all;
Harald Welte624f9632017-12-16 19:26:04 +010038import from RSL_Emulation all;
Daniel Willmann191e0d92018-01-17 12:44:35 +010039import from MGCP_Emulation all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010040import from MGCP_Templates all;
41import from MGCP_Types all;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +020042import from MGCP_CodecPort all;
Harald Welte28d943e2017-11-25 15:00:50 +010043
Harald Welte96c94412017-12-09 03:12:45 +010044import from Osmocom_CTRL_Functions all;
Harald Weltea5d2ab22017-12-09 14:21:42 +010045import from Osmocom_CTRL_Types all;
Harald Welteffe55fc2018-01-17 22:39:54 +010046import from Osmocom_CTRL_Adapter all;
Harald Welte96c94412017-12-09 03:12:45 +010047
Daniel Willmannebdecc02020-08-12 15:30:17 +020048import from StatsD_Types all;
49import from StatsD_CodecPort all;
50import from StatsD_CodecPort_CtrlFunct all;
51import from StatsD_Checker all;
52
Harald Weltebc03c762018-02-12 18:09:38 +010053import from Osmocom_VTY_Functions all;
54import from TELNETasp_PortType all;
55
Harald Welte6f521d82017-12-11 19:52:02 +010056import from MobileL3_CommonIE_Types all;
Harald Weltee3bd6582018-01-31 22:51:25 +010057import from MobileL3_Types all;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010058import from MobileL3_RRM_Types all;
Harald Welte6f521d82017-12-11 19:52:02 +010059import from L3_Templates all;
60import from GSM_RR_Types all;
61
Stefan Sperlingc307e682018-06-14 15:15:46 +020062import from SCCP_Templates all;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +010063import from BSSMAP_Templates all;
64
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +010065import from SCCPasp_Types all;
66
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020067import from GSM_SystemInformation all;
68import from GSM_RestOctets all;
Neels Hofmeyrad132f22020-07-08 02:20:16 +020069import from TCCConversion_Functions all;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +020070
Harald Welte5d1a2202017-12-13 19:51:29 +010071const integer NUM_BTS := 3;
Neels Hofmeyrf246a922020-05-13 02:27:10 +020072const integer NUM_MSC := 3;
Harald Welteae026692017-12-09 01:03:01 +010073const float T3101_MAX := 12.0;
Harald Welte28d943e2017-11-25 15:00:50 +010074
Harald Welte799c97b2017-12-14 17:50:30 +010075/* make sure to sync this with the osmo-bts.cfg you're using */
Philipp Maiercb6cc482018-03-26 13:08:00 +020076const integer NUM_TCHH_PER_BTS := 2;
77const integer NUM_TCHF_PER_BTS := 4;
Neels Hofmeyr74083c22020-07-29 00:43:01 +020078const integer NUM_SDCCH_PER_BTS := 3;
Harald Welte799c97b2017-12-14 17:50:30 +010079
Harald Welte4003d112017-12-09 22:35:39 +010080
Harald Welte21b46bd2017-12-17 19:46:32 +010081/* per-BTS state which we keep */
Harald Welte96c94412017-12-09 03:12:45 +010082type record BTS_State {
Harald Welte21b46bd2017-12-17 19:46:32 +010083 /* component reference to the IPA_Client component used for RSL */
Harald Weltea5d2ab22017-12-09 14:21:42 +010084 IPA_Client rsl
Harald Welte96c94412017-12-09 03:12:45 +010085}
86
Neels Hofmeyr22c3f792020-06-17 02:49:28 +020087/* Default list of counters for an 'msc' entity. */
88const CounterNameVals counternames_msc_mscpool := {
89 { "mscpool:subscr:new", 0 },
90 { "mscpool:subscr:known", 0 },
91 { "mscpool:subscr:reattach", 0 },
92 { "mscpool:subscr:attach_lost", 0 },
93 { "mscpool:subscr:paged", 0 }
94};
95
Neels Hofmeyr12941bd2020-08-29 03:21:26 +000096/* Default list of counters for 'bsc' and 'bts' entities. */
97const CounterNameVals counternames_bsc_bts_handover := {
98 { "assignment:attempted", 0 },
99 { "assignment:completed", 0 },
100 { "assignment:stopped", 0 },
101 { "assignment:no_channel", 0 },
102 { "assignment:timeout", 0 },
103 { "assignment:failed", 0 },
104 { "assignment:error", 0 },
105
106 { "handover:attempted", 0 },
107 { "handover:completed", 0 },
108 { "handover:stopped", 0 },
109 { "handover:no_channel", 0 },
110 { "handover:timeout", 0 },
111 { "handover:failed", 0 },
112 { "handover:error", 0 },
113
114 { "intra_cell_ho:attempted", 0 },
115 { "intra_cell_ho:completed", 0 },
116 { "intra_cell_ho:stopped", 0 },
117 { "intra_cell_ho:no_channel", 0 },
118 { "intra_cell_ho:timeout", 0 },
119 { "intra_cell_ho:failed", 0 },
120 { "intra_cell_ho:error", 0 },
121
122 { "intra_bsc_ho:attempted", 0 },
123 { "intra_bsc_ho:completed", 0 },
124 { "intra_bsc_ho:stopped", 0 },
125 { "intra_bsc_ho:no_channel", 0 },
126 { "intra_bsc_ho:timeout", 0 },
127 { "intra_bsc_ho:failed", 0 },
128 { "intra_bsc_ho:error", 0 },
129
130 { "interbsc_ho_out:attempted", 0 },
131 { "interbsc_ho_out:completed", 0 },
132 { "interbsc_ho_out:stopped", 0 },
133 { "interbsc_ho_out:timeout", 0 },
134 { "interbsc_ho_out:failed", 0 },
135 { "interbsc_ho_out:error", 0 },
136
137 { "interbsc_ho_in:attempted", 0 },
138 { "interbsc_ho_in:completed", 0 },
139 { "interbsc_ho_in:stopped", 0 },
140 { "interbsc_ho_in:no_channel", 0 },
141 { "interbsc_ho_in:timeout", 0 },
142 { "interbsc_ho_in:failed", 0 },
143 { "interbsc_ho_in:error", 0 }
144};
145
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200146/* Set of all System Information received during one RSL port's startup.
147 * Note that some System Information may be sent on RSL, but lacking actual SI data, to indicate that the BTS should not
148 * broadcast that SI type. That will be reflected as 'omit' here.
149 */
150type record SystemInformationConfig {
151 SystemInformationType1 si1 optional,
152 SystemInformationType2 si2 optional,
153 SystemInformationType2bis si2bis optional,
154 SystemInformationType2ter si2ter optional,
Neels Hofmeyrad132f22020-07-08 02:20:16 +0200155 SI2quaterRestOctetsList si2quater optional,
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200156 SystemInformationType3 si3 optional,
157 SystemInformationType4 si4 optional,
158 /* TODO: replace with proper decoding of SI13, implement SI13 in GSM_SystemInformation.ttcn */
159 octetstring si13 optional,
160 SystemInformationType5 si5 optional,
161 SystemInformationType5bis si5bis optional,
162 SystemInformationType5ter si5ter optional,
163 SystemInformationType6 si6 optional
164};
165
166const SystemInformationConfig SystemInformationConfig_omit := {
167 si1 := omit,
168 si2 := omit,
169 si2bis := omit,
170 si2ter := omit,
171 si2quater := omit,
172 si3 := omit,
173 si4 := omit,
174 si13 := omit,
175 si5 := omit,
176 si5bis := omit,
177 si5ter := omit,
178 si6 := omit
179};
180
181/* tr_EUTRAN_CellDesc with defaults used in BSC_Tests.ttcn */
182template EUTRAN_CellDesc tr_EUTRAN_CellDesc_default(template (present) uint16_t e_arfcn := ?,
183 template uint3_t meas_bw := 3)
184:= tr_EUTRAN_CellDesc(e_arfcn := e_arfcn,
185 meas_bw_presence := '1'B,
186 meas_bw := meas_bw);
187
188/* tr_EUTRAN_NeighbourCells with defaults used in BSC_Tests.ttcn */
Harald Welte65e419a2020-08-21 12:38:33 +0200189template EUTRAN_NeighbourCells tr_EUTRAN_NeighbourCells_default(template (present) EUTRAN_CellDescs cell_desc_list := { tr_EUTRAN_CellDesc_default },
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200190 template uint3_t prio := 3,
191 template (present) uint5_t thresh_high := 20,
192 template uint5_t thresh_low := 10,
193 template uint5_t qrxlevmin := 22)
194:= tr_EUTRAN_NeighbourCells(
195 cell_desc_list := cell_desc_list,
196 prio_presence := '1'B,
197 prio := prio,
198 thresh_high := thresh_high,
199 thresh_low_presence := '1'B,
200 thresh_low := thresh_low,
201 qrxlevmin_presence := '1'B,
202 qrxlevmin := qrxlevmin);
203
204template SystemInformationConfig SystemInformationConfig_default := {
205 si1 := {
206 cell_chan_desc := '8FB38000000000000000000000000000'O,
207 rach_control := {
208 max_retrans := RACH_MAX_RETRANS_7,
209 tx_integer := '1001'B,
210 cell_barr_access := false,
211 re_not_allowed := true,
212 acc := '0000010000000000'B
213 },
214 rest_octets := ?
215 },
216 si2 := {
217 bcch_freq_list := '00000000000000000000000000000000'O,
218 ncc_permitted := '11111111'B,
219 rach_control := {
220 max_retrans := RACH_MAX_RETRANS_7,
221 tx_integer := '1001'B,
222 cell_barr_access := false,
223 re_not_allowed := true,
224 acc := '0000010000000000'B
225 }
226 },
227 si2bis := omit,
228 si2ter := {
229 extd_bcch_freq_list := '8E320000000000000000000000000800'O,
230 rest_octets := ?
231 },
232 si2quater := {
233 tr_SI2quaterRestOctets_EUTRAN( repeated_neigh_cells := { tr_EUTRAN_NeighbourCells_default } )
234 },
235 si3 := {
236 cell_id := 0,
237 lai := {
238 mcc_mnc := '001F01'H,
239 lac := 1
240 },
241 ctrl_chan_desc := {
242 msc_r99 := true,
243 att := true,
244 bs_ag_blks_res := 1,
245 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
246 si22ind := false,
247 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
248 spare := '00'B,
249 bs_pa_mfrms := 3,
250 t3212 := 30
251 },
252 cell_options := {
253 dn_ind := false,
254 pwrc := false,
255 dtx := MS_SHALL_USE_UL_DTX,
256 radio_link_tout_div4 := 7
257 },
258 cell_sel_par := {
259 cell_resel_hyst_2dB := 2,
260 ms_txpwr_max_cch := 7,
261 acs := '0'B,
262 neci := true,
263 rxlev_access_min := 0
264 },
265 rach_control := {
266 max_retrans := RACH_MAX_RETRANS_7,
267 tx_integer := '1001'B,
268 cell_barr_access := false,
269 re_not_allowed := true,
270 acc := '0000010000000000'B
271 },
272 rest_octets := {
273 sel_params := {
274 presence := '0'B,
275 params := omit
276 },
277 pwr_offset := {
278 presence := '0'B,
279 offset := omit
280 },
281 si_2ter_ind := '1'B,
282 early_cm_ind := '0'B,
283 sched_where := {
284 presence := '0'B,
285 where := omit
286 },
287 gprs_ind := {
288 presence := '1'B,
289 ind := {
290 ra_colour := 0,
291 si13_pos := '0'B
292 }
293 },
294 umts_early_cm_ind := '1'B,
295 si2_quater_ind := {
296 presence := '1'B,
297 ind := '0'B
298 },
299 iu_mode_ind := omit,
300 si21_ind := {
301 presence := '0'B,
302 pos := omit
303 }
304 }
305 },
306 si4 := {
307 lai := {
308 mcc_mnc := '001F01'H,
309 lac := 1
310 },
311 cell_sel_par := {
312 cell_resel_hyst_2dB := 2,
313 ms_txpwr_max_cch := 7,
314 acs := '0'B,
315 neci := true,
316 rxlev_access_min := 0
317 },
318 rach_control := {
319 max_retrans := RACH_MAX_RETRANS_7,
320 tx_integer := '1001'B,
321 cell_barr_access := false,
322 re_not_allowed := true,
323 acc := '0000010000000000'B
324 },
Neels Hofmeyr74083c22020-07-29 00:43:01 +0200325 cbch_chan_desc := {
326 iei := '64'O,
327 v := {
328 chan_nr := {
329 u := {
330 sdcch4 := {
331 tag := '001'B,
332 sub_chan := 2
333 }
334 },
335 tn := 0
336 },
337 tsc := 2,
338 h := false,
339 arfcn := 871,
340 maio_hsn := omit
341 }
342 },
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200343 cbch_mobile_alloc := omit,
344 rest_octets := {
345 sel_params := {
346 presence := '0'B,
347 params := omit
348 },
349 pwr_offset := {
350 presence := '0'B,
351 offset := omit
352 },
353 gprs_ind := {
354 presence := '1'B,
355 ind := {
356 ra_colour := 0,
357 si13_pos := '0'B
358 }
359 },
360 s_presence := '0'B,
361 s := omit
362 }
363 },
364 si13 := '9000185A6FC9E08410AB2B2B2B2B2B2B2B2B2B2B'O,
365 si5 := {
366 bcch_freq_list := '10000000000000000000000000000000'O
367 },
368 si5bis := omit,
369 si5ter := {
370 extd_bcch_freq_list := '9E050020000000000000000000000000'O
371 },
372 si6 := {
373 cell_id := 0,
374 lai := {
375 mcc_mnc := '001F01'H,
376 lac := 1
377 },
378 cell_options := {
379 dtx_ext := '1'B,
380 pwrc := false,
381 dtx := '01'B,
382 radio_link_timeout := '0111'B
383 },
384 ncc_permitted := '11111111'B,
385 rest_octets := ?
386 }
387 };
388
389
390/* List of all the System Information received on all RSL ports */
391type record of SystemInformationConfig SystemInformationConfig_list;
392
393function f_sysinfo_dec_raw(inout SystemInformationConfig si, RSL_Message rsl)
394{
395 var RSL_IE_Body sysinfo_type_ie;
396 var RSL_IE_SysinfoType si_type;
397 var octetstring data;
398
399 if (f_rsl_find_ie(rsl, RSL_IE_SYSINFO_TYPE, sysinfo_type_ie) == false) {
400 setverdict(fail, "Cannot find RSL_IE_SYSINFO_TYPE");
401 mtc.stop;
402 }
403 si_type := sysinfo_type_ie.sysinfo_type;
404
405 if (rsl.msg_type == RSL_MT_BCCH_INFO) {
406 var RSL_IE_Body bcch_ie;
407 if (f_rsl_find_ie(rsl, RSL_IE_FULL_BCCH_INFO, bcch_ie)) {
408 data := bcch_ie.other.payload;
409 }
410 } else if (rsl.msg_type == RSL_MT_SACCH_FILL) {
411 var RSL_IE_Body l3_ie;
412 if (f_rsl_find_ie(rsl, RSL_IE_L3_INFO, l3_ie)) {
413 data := l3_ie.l3_info.payload;
414 }
415 } else {
416 setverdict(fail, "Don't understand this System Information message");
417 mtc.stop;
418 }
419
420 var boolean handled := false;
421
422 if (rsl.msg_type == RSL_MT_BCCH_INFO) {
423 handled := true;
424
425 if (si_type == RSL_SYSTEM_INFO_1) {
426 if (not isbound(data)) {
427 si.si1 := omit;
428 } else {
429 si.si1 := dec_SystemInformation(data).payload.si1;
430 }
431 } else if (si_type == RSL_SYSTEM_INFO_2) {
432 if (not isbound(data)) {
433 si.si2 := omit;
434 } else {
435 si.si2 := dec_SystemInformation(data).payload.si2;
436 }
437 } else if (si_type == RSL_SYSTEM_INFO_2bis) {
438 if (not isbound(data)) {
439 si.si2bis := omit;
440 } else {
441 si.si2bis := dec_SystemInformation(data).payload.si2bis;
442 }
443 } else if (si_type == RSL_SYSTEM_INFO_2ter) {
444 if (not isbound(data)) {
445 si.si2ter := omit;
446 } else {
447 si.si2ter := dec_SystemInformation(data).payload.si2ter;
448 }
449 } else if (si_type == RSL_SYSTEM_INFO_2quater) {
450 if (not isbound(data)) {
451 si.si2quater := {};
452 } else {
453 var SystemInformationType2quater decoded := dec_SystemInformation(data).payload.si2quater;
454 /* this is a *record* of SI2quaterRestOctets! (multiplexed) */
455 si.si2quater[decoded.rest_octets.si2quater_index] := decoded.rest_octets;
456 }
457 } else if (si_type == RSL_SYSTEM_INFO_3) {
458 if (not isbound(data)) {
459 si.si3 := omit;
460 } else {
461 si.si3 := dec_SystemInformation(data).payload.si3;
462 }
463 } else if (si_type == RSL_SYSTEM_INFO_4) {
464 if (not isbound(data)) {
465 si.si4 := omit;
466 } else {
467 si.si4 := dec_SystemInformation(data).payload.si4;
468 }
469 } else if (si_type == RSL_SYSTEM_INFO_13) {
470 if (not isbound(data)) {
471 si.si13 := omit;
472 } else {
473 si.si13 := dec_SystemInformation(data).payload.other;
474 }
475 } else {
476 handled := false;
477 }
478 } else if (rsl.msg_type == RSL_MT_SACCH_FILL) {
479 handled := true;
480
481 if (si_type == RSL_SYSTEM_INFO_5) {
482 if (not isbound(data)) {
483 si.si5 := omit;
484 } else {
485 si.si5 := dec_SystemInformation(data).payload.si5;
486 }
487 } else if (si_type == RSL_SYSTEM_INFO_5bis) {
488 if (not isbound(data)) {
489 si.si5bis := omit;
490 } else {
491 si.si5bis := dec_SystemInformation(data).payload.si5bis;
492 }
493 } else if (si_type == RSL_SYSTEM_INFO_5ter) {
494 if (not isbound(data)) {
495 si.si5ter := omit;
496 } else {
497 si.si5ter := dec_SystemInformation(data).payload.si5ter;
498 }
499 } else if (si_type == RSL_SYSTEM_INFO_6) {
500 if (not isbound(data)) {
501 si.si6 := omit;
502 } else {
503 si.si6 := dec_SystemInformation(data).payload.si6;
504 }
505 } else {
506 handled := false;
507 }
508 }
509
510 if (not handled) {
511 setverdict(fail, "Unexpected SI type in ", rsl.msg_type, " message: ", si_type);
512 }
513}
514
Harald Weltea4ca4462018-02-09 00:17:14 +0100515type component test_CT extends CTRL_Adapter_CT {
Harald Welte21b46bd2017-12-17 19:46:32 +0100516 /* Array of per-BTS state */
Harald Welte96c94412017-12-09 03:12:45 +0100517 var BTS_State bts[NUM_BTS];
Harald Welte89ab1912018-02-23 18:56:29 +0100518 /* RSL common Channel Port (for RSL_Emulation) */
519 port RSL_CCHAN_PT RSL_CCHAN[NUM_BTS];
Harald Welte21b46bd2017-12-17 19:46:32 +0100520 /* array of per-BTS RSL test ports */
Harald Welteae026692017-12-09 01:03:01 +0100521 port IPA_RSL_PT IPA_RSL[NUM_BTS];
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100522 port IPA_CODEC_PT IPA; /* Required for compilation of TC_rsl_unknown_unit_id() */
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +0200523 /* CTRL muxed over IPA in SCCPlite conn BSC<->MSC (or BSC-NAT) */
524 port IPA_CTRL_PT SCCPLITE_IPA_CTRL;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100525
Daniel Willmann191e0d92018-01-17 12:44:35 +0100526 var MGCP_Emulation_CT vc_MGCP;
Harald Weltebc03c762018-02-12 18:09:38 +0100527 port TELNETasp_PT BSCVTY;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100528
Daniel Willmannebdecc02020-08-12 15:30:17 +0200529 /* StatsD */
530 var StatsD_Checker_CT vc_STATSD;
531
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200532 var RAN_Adapter g_bssap[NUM_MSC];
Harald Weltea4ca4462018-02-09 00:17:14 +0100533 /* for old legacy-tests only */
534 port BSSAP_CODEC_PT BSSAP;
535
Harald Welte21b46bd2017-12-17 19:46:32 +0100536 /* are we initialized yet */
Harald Welte28d943e2017-11-25 15:00:50 +0100537 var boolean g_initialized := false;
Harald Welte21b46bd2017-12-17 19:46:32 +0100538
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200539 /* Osmux is enabled through VTY */
540 var boolean g_osmux_enabled := false;
541
Pau Espin Pedrolc675b612020-01-09 19:55:40 +0100542 /*Configure T(tias) over VTY, seconds */
543 var integer g_bsc_sccp_timer_ias := 7 * 60;
544 /*Configure T(tiar) over VTY, seconds */
545 var integer g_bsc_sccp_timer_iar := 15 * 60;
546
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +0200547 /* global test case guard timer (actual timeout value is set in f_init()) */
Harald Welteae026692017-12-09 01:03:01 +0100548 timer T_guard := 30.0;
549
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200550 var CounterNameValsList g_ctr_msc;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000551 var CounterNameValsList g_ctr_bsc;
552 var CounterNameValsList g_ctr_bts;
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200553
554 /* System Information bytes as received during RSL startup, for each RSL[idx]. */
555 var SystemInformationConfig_list g_system_information := {};
Harald Welte28d943e2017-11-25 15:00:50 +0100556}
557
558modulepar {
Harald Welte21b46bd2017-12-17 19:46:32 +0100559 /* IP address at which the BSC can be reached */
Harald Welte696ddb62017-12-08 14:01:43 +0100560 charstring mp_bsc_ip := "127.0.0.1";
Stefan Sperling830dc9d2018-02-12 21:08:28 +0100561 /* port number to which to establish the IPA OML connections */
562 integer mp_bsc_oml_port := 3002;
Harald Welte21b46bd2017-12-17 19:46:32 +0100563 /* port number to which to establish the IPA RSL connections */
Harald Welte696ddb62017-12-08 14:01:43 +0100564 integer mp_bsc_rsl_port := 3003;
Harald Welte21b46bd2017-12-17 19:46:32 +0100565 /* port number to which to establish the IPA CTRL connection */
Harald Welte96c94412017-12-09 03:12:45 +0100566 integer mp_bsc_ctrl_port := 4249;
Daniel Willmannebdecc02020-08-12 15:30:17 +0200567 /* port number to which to listen for STATSD metrics */
568 integer mp_bsc_statsd_port := 8125;
Daniel Willmann191e0d92018-01-17 12:44:35 +0100569 /* IP address at which the test binds */
570 charstring mp_test_ip := "127.0.0.1";
Harald Weltea4ca4462018-02-09 00:17:14 +0100571
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200572 RAN_Configurations mp_bssap_cfg := {
573 {
574 transport := BSSAP_TRANSPORT_AoIP,
575 sccp_service_type := "mtp3_itu",
576 sctp_addr := { 23905, "127.0.0.1", 2905, "127.0.0.1" },
577 own_pc := 185, /* 0.23.1 first MSC emulation */
578 own_ssn := 254,
579 peer_pc := 187, /* 0.23.3 osmo-bsc */
580 peer_ssn := 254,
581 sio := '83'O,
Harald Weltecb0cc432020-06-21 19:42:31 +0200582 rctx := 1
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200583 },
584 {
585 transport := BSSAP_TRANSPORT_AoIP,
586 sccp_service_type := "mtp3_itu",
587 sctp_addr := { 23906, "127.0.0.1", 2905, "127.0.0.1" },
588 own_pc := 2, /* 0.0.2 second MSC emulation */
589 own_ssn := 254,
590 peer_pc := 187, /* 0.23.3 osmo-bsc */
591 peer_ssn := 254,
592 sio := '83'O,
593 rctx := 2
594 },
595 {
596 transport := BSSAP_TRANSPORT_AoIP,
597 sccp_service_type := "mtp3_itu",
598 sctp_addr := { 23907, "127.0.0.1", 2905, "127.0.0.1" },
599 own_pc := 3, /* 0.0.3 third MSC emulation */
600 own_ssn := 254,
601 peer_pc := 187, /* 0.23.3 osmo-bsc */
602 peer_ssn := 254,
603 sio := '83'O,
604 rctx := 3
605 }
Harald Weltea4ca4462018-02-09 00:17:14 +0100606 };
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +0200607
608 /* Whether to enable osmux tests. Can be dropped completely and enable
609 unconditionally once new version of osmo-bsc is released (current
610 version: 1.4.1) */
611 boolean mp_enable_osmux_test := true;
Pau Espin Pedrol8f30ccd2019-11-01 17:30:57 +0100612 /* Value set in osmo-bsc.cfg "ms max power" */
613 uint8_t mp_exp_ms_power_level := 7;
Philipp Maiera2083892020-09-21 14:18:36 +0200614
615 boolean mp_media_mgw_offer_ipv6 := true;
Harald Weltea4ca4462018-02-09 00:17:14 +0100616}
617
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200618private function f_gen_test_hdlr_pars(integer bssap_idx := 0) return TestHdlrParams {
Philipp Maier48604732018-10-09 15:00:37 +0200619
620 var TestHdlrParams pars := valueof(t_def_TestHdlrPars);
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200621 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier48604732018-10-09 15:00:37 +0200622 pars.aoip := true;
623 } else {
624 pars.aoip := false;
625 }
Pau Espin Pedrol8f30ccd2019-11-01 17:30:57 +0100626 pars.exp_ms_power_level := mp_exp_ms_power_level;
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200627 pars.mscpool.bssap_idx := bssap_idx;
Philipp Maiera2083892020-09-21 14:18:36 +0200628 pars.media_mgw_offer_ipv6 := mp_media_mgw_offer_ipv6;
Philipp Maier48604732018-10-09 15:00:37 +0200629
630 return pars;
631}
632
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200633/* Convenience functions for rate counters using g_ctr_msc. */
634
635private function f_ctrs_msc_init(integer mscs_count := NUM_MSC, CounterNameVals counternames := counternames_msc_mscpool) runs on test_CT {
636 g_ctr_msc := f_counter_name_vals_get_n(IPA_CTRL, "msc", mscs_count, counternames);
637 log("initial msc rate counters: ", g_ctr_msc);
638}
639
640private function f_ctrs_msc_add(integer msc_nr, charstring countername, integer val := 1) runs on test_CT {
Neels Hofmeyr9656e922020-06-30 01:27:01 +0200641 f_counter_name_vals_list_add(g_ctr_msc, msc_nr, countername, val);
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200642}
643
644/* f_ctrs_msc_init();
645 * f_do_thing(on_msc := 0);
646 * f_do_thing(on_msc := 0);
647 * f_do_other(on_msc := 1);
648 * f_ctrs_msc_add(0, "thing", 2);
649 * f_ctrs_msc_add(1, "other");
650 * f_ctrs_msc_verify();
651 */
652private function f_ctrs_msc_verify() runs on test_CT {
653 log("verifying msc rate counters: ", g_ctr_msc);
654 f_counter_name_vals_expect_n(IPA_CTRL, "msc", g_ctr_msc);
655}
656
657/* convenience: f_ctrs_msc_add() and f_ctrs_msc_verify() in one call.
658 * f_ctrs_msc_init();
659 * f_do_thing(on_msc := 0);
660 * f_do_thing(on_msc := 0);
661 * f_do_thing(on_msc := 0);
662 * f_ctrs_msc_expect(0, "thing", 3);
663 */
664private function f_ctrs_msc_expect(integer msc_nr, charstring countername, integer val := 1) runs on test_CT {
665 f_ctrs_msc_add(msc_nr, countername, val);
666 f_ctrs_msc_verify();
667}
668
Neels Hofmeyr12941bd2020-08-29 03:21:26 +0000669/* Convenience functions for rate counters using g_ctr_bts, always also including g_ctr_bsc. */
670
671private function f_ctrs_bsc_and_bts_init(integer bts_count := NUM_BTS, CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
672 g_ctr_bts := f_counter_name_vals_get_n(IPA_CTRL, "bts", bts_count, counternames);
673 log("initial bts rate counters: ", g_ctr_bts);
674 f_ctrs_bsc_init(counternames);
675}
676
677private function f_ctrs_bsc_and_bts_add(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
678 f_counter_name_vals_list_add(g_ctr_bts, bts_nr, countername, val);
679 f_ctrs_bsc_add(countername, val);
680}
681
682/* f_ctrs_bsc_and_bts_init();
683 * f_do_thing(on_bts := 0);
684 * f_do_thing(on_bts := 0);
685 * f_do_other(on_bts := 1);
686 * f_ctrs_bsc_and_bts_add(0, "thing", 2);
687 * f_ctrs_bsc_and_bts_add(1, "other");
688 * f_ctrs_bsc_and_bts_verify();
689 */
690private function f_ctrs_bsc_and_bts_verify() runs on test_CT {
691 f_counter_name_vals_expect_n(IPA_CTRL, "bts", g_ctr_bts);
692 f_ctrs_bsc_verify();
693}
694
695/* convenience: f_ctrs_bsc_and_bts_add() and f_ctrs_bsc_and_bts_verify() in one call.
696 * f_ctrs_bsc_and_bts_init();
697 * f_do_thing(on_bts := 0);
698 * f_do_thing(on_bts := 0);
699 * f_do_thing(on_bts := 0);
700 * f_ctrs_bsc_and_bts_expect(0, "thing", 3);
701 */
702private function f_ctrs_bsc_and_bts_expect(integer bts_nr, charstring countername, integer val := 1) runs on test_CT {
703 f_ctrs_bsc_and_bts_add(bts_nr, countername, val);
704 f_ctrs_bsc_and_bts_verify();
705}
706
707
708/* Convenience functions for rate counters using g_ctr_bsc. */
709
710private function f_ctrs_bsc_init(CounterNameVals counternames := counternames_bsc_bts_handover) runs on test_CT {
711 g_ctr_bsc := f_counter_name_vals_get_n(IPA_CTRL, "bsc", 1, counternames);
712 log("initial bsc rate counters: ", g_ctr_bsc);
713}
714
715private function f_ctrs_bsc_add(charstring countername, integer val := 1) runs on test_CT {
716 f_counter_name_vals_list_add(g_ctr_bsc, 0, countername, val);
717}
718
719/* f_ctrs_bsc_init();
720 * f_do_thing();
721 * f_do_thing();
722 * f_do_other();
723 * f_ctrs_bsc_add("thing", 2);
724 * f_ctrs_bsc_add("other");
725 * f_ctrs_bsc_verify();
726 */
727private function f_ctrs_bsc_verify() runs on test_CT {
728 f_counter_name_vals_expect_n(IPA_CTRL, "bsc", g_ctr_bsc);
729}
730
731/* convenience: f_ctrs_bsc_add() and f_ctrs_bsc_verify() in one call.
732 * f_ctrs_bsc_init();
733 * f_do_thing();
734 * f_ctrs_bsc_expect("thing", 1);
735 */
736private function f_ctrs_bsc_expect(charstring countername, integer val := 1) runs on test_CT {
737 f_ctrs_bsc_add(countername, val);
738 f_ctrs_bsc_verify();
739}
740
Neels Hofmeyr22c3f792020-06-17 02:49:28 +0200741
Philipp Maier282ca4b2018-02-27 17:17:00 +0100742private function f_shutdown_helper() runs on test_CT {
Daniel Willmann637ef6c2018-07-25 10:49:09 +0200743 all component.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100744 setverdict(pass);
Daniel Willmannafce8662018-07-06 23:11:32 +0200745 mtc.stop;
Philipp Maier282ca4b2018-02-27 17:17:00 +0100746}
747
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200748private function f_legacy_bssap_reset(integer bssap_idx := 0) runs on test_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +0100749 var BSSAP_N_UNITDATA_ind ud_ind;
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200750 var boolean reset_received := false;
Harald Weltea4ca4462018-02-09 00:17:14 +0100751 timer T := 5.0;
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200752 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
753 ts_BSSMAP_Reset(0, g_osmux_enabled)));
Harald Weltea4ca4462018-02-09 00:17:14 +0100754 T.start;
755 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200756 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(g_bssap[bssap_idx].sccp_addr_own, g_bssap[bssap_idx].sccp_addr_peer,
757 tr_BSSMAP_ResetAck(g_osmux_enabled))) {
Harald Weltea4ca4462018-02-09 00:17:14 +0100758 log("Received RESET-ACK in response to RESET, we're ready to go!");
759 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200760 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Weltea4ca4462018-02-09 00:17:14 +0100761 log("Respoding to inbound RESET with RESET-ACK");
762 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200763 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200764 reset_received := true;
Harald Weltea4ca4462018-02-09 00:17:14 +0100765 repeat;
766 }
767 [] BSSAP.receive { repeat; }
Pau Espin Pedrol24c05992020-09-01 12:54:12 +0200768 [] T.timeout {
769 log("Timeout waiting for RESET-ACK after sending RESET");
770 /* If we received a RESET after ours was sent, it
771 may be a race condition where the other peer beacame
772 available after we sent it, but we are in a desired
773 state anyway, so go forward. */
774 if (not reset_received) {
775 setverdict(fail);
776 }
777 }
Harald Weltea4ca4462018-02-09 00:17:14 +0100778 }
Harald Welte28d943e2017-11-25 15:00:50 +0100779}
780
Harald Welteae026692017-12-09 01:03:01 +0100781type record IPA_Client {
Harald Welte21b46bd2017-12-17 19:46:32 +0100782 /* IPA Emulation component reference */
Harald Welteae026692017-12-09 01:03:01 +0100783 IPA_Emulation_CT vc_IPA,
Harald Welte21b46bd2017-12-17 19:46:32 +0100784 /* Unit-ID and other CCM parameters to use for IPA client emulation */
Harald Welteae026692017-12-09 01:03:01 +0100785 IPA_CCM_Parameters ccm_pars,
Harald Welte21b46bd2017-12-17 19:46:32 +0100786 /* String identifier for this IPA Client */
Harald Welte624f9632017-12-16 19:26:04 +0100787 charstring id,
Harald Welte21b46bd2017-12-17 19:46:32 +0100788 /* Associated RSL Emulation Component (if any). Only used in "Handler mode" */
Harald Welte624f9632017-12-16 19:26:04 +0100789 RSL_Emulation_CT vc_RSL optional
Harald Welte28d943e2017-11-25 15:00:50 +0100790}
791
Harald Welte21b46bd2017-12-17 19:46:32 +0100792/*! Start the IPA/RSL related bits for one IPA_Client.
793 * \param clnt IPA_Client for which to establish
794 * \param bsc_host IP address / hostname of the BSC
795 * \param bsc_port TCP port number of the BSC
796 * \param i number identifying this BTS
797 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false) */
Harald Welte624f9632017-12-16 19:26:04 +0100798function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i,
799 boolean handler_mode := false)
Harald Welte28d943e2017-11-25 15:00:50 +0100800runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +0100801 timer T := 10.0;
802
Harald Welte96c94412017-12-09 03:12:45 +0100803 clnt.id := "IPA" & int2str(i) & "-RSL";
Harald Welteae026692017-12-09 01:03:01 +0100804 clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA");
805 clnt.ccm_pars := c_IPA_default_ccm_pars;
806 clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
807 clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0";
Harald Welte624f9632017-12-16 19:26:04 +0100808 if (handler_mode) {
809 clnt.vc_RSL := RSL_Emulation_CT.create(clnt.id & "-RSL");
Harald Welte89ab1912018-02-23 18:56:29 +0100810 connect(clnt.vc_RSL:CCHAN_PT, self:RSL_CCHAN[i]);
Harald Welte624f9632017-12-16 19:26:04 +0100811 }
Harald Welteae026692017-12-09 01:03:01 +0100812
813 map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
Harald Welte624f9632017-12-16 19:26:04 +0100814 if (handler_mode) {
815 connect(clnt.vc_IPA:IPA_RSL_PORT, clnt.vc_RSL:IPA_PT);
816 } else {
817 connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]);
818 }
Harald Welteae026692017-12-09 01:03:01 +0100819
Harald Welte5d1a2202017-12-13 19:51:29 +0100820 clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", 10000+i, clnt.ccm_pars));
Harald Welte624f9632017-12-16 19:26:04 +0100821 if (handler_mode) {
822 clnt.vc_RSL.start(RSL_Emulation.main());
823 return;
824 }
Harald Welteae026692017-12-09 01:03:01 +0100825
826 /* wait for IPA RSL link to connect and send ID ACK */
827 T.start;
828 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700829 [] IPA_RSL[i].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) {
Harald Welteae026692017-12-09 01:03:01 +0100830 T.stop;
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +0700831 IPA_RSL[i].send(ts_ASP_RSL_UD(ts_RSL_PAGING_LOAD_IND(23)));
Harald Welteae026692017-12-09 01:03:01 +0100832 }
Harald Welte60e823a2017-12-10 14:10:59 +0100833 [] IPA_RSL[i].receive(ASP_IPA_Event:?) { repeat }
Harald Welteae026692017-12-09 01:03:01 +0100834 [] IPA_RSL[i].receive { repeat }
835 [] T.timeout {
Harald Welte96c94412017-12-09 03:12:45 +0100836 setverdict(fail, "Timeout RSL waiting for ASP_IPA_EVENT_ID_ACK");
Daniel Willmannafce8662018-07-06 23:11:32 +0200837 mtc.stop;
Harald Welteae026692017-12-09 01:03:01 +0100838 }
839 }
840}
841
Harald Welte12055472018-03-17 20:10:08 +0100842function f_ipa_rsl_stop(inout IPA_Client clnt) runs on test_CT {
843 if (not isbound(clnt) or not isbound(clnt.vc_IPA)) {
844 return;
845 }
846 clnt.vc_IPA.stop;
847 if (isbound(clnt.vc_RSL)) {
848 clnt.vc_RSL.stop;
849 }
850}
851
Harald Welte21b46bd2017-12-17 19:46:32 +0100852/* Wait for the OML connection to be brought up by the external osmo-bts-omldummy */
Harald Weltea5d2ab22017-12-09 14:21:42 +0100853function f_wait_oml(integer bts_nr, charstring status, float secs_max) runs on test_CT {
854 timer T := secs_max;
855 T.start;
856 while (true) {
857 if (f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-connection-state") == status) {
858 T.stop;
Harald Weltebd868bd2017-12-10 18:28:40 +0100859 /* the 'degraded' state exists from OML connection time, and we have to wait
860 * until all MO's are initialized */
861 T.start(1.0);
862 T.timeout;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100863 return;
864 }
Harald Weltef0d6ac62017-12-17 17:02:21 +0100865 f_sleep(0.1);
Harald Weltea5d2ab22017-12-09 14:21:42 +0100866 if (not T.running) {
Max99253902018-11-16 17:57:39 +0100867 setverdict(fail, "Timeout waiting for BTS" & int2str(bts_nr) & " oml-connection-state ", status);
Daniel Willmannafce8662018-07-06 23:11:32 +0200868 mtc.stop;
Harald Weltea5d2ab22017-12-09 14:21:42 +0100869 }
870 }
871}
872
Harald Welte21b46bd2017-12-17 19:46:32 +0100873/* global altstep for global guard timer; also takes care of responding RESET witH RESET-ACK */
Harald Welteae026692017-12-09 01:03:01 +0100874altstep as_Tguard() runs on test_CT {
Harald Welte60e823a2017-12-10 14:10:59 +0100875 var BSSAP_N_UNITDATA_ind ud_ind;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100876 [] T_guard.timeout {
877 setverdict(fail, "Timeout of T_guard");
Daniel Willmannafce8662018-07-06 23:11:32 +0200878 mtc.stop;
Neels Hofmeyrcc3f76a2018-03-12 01:43:25 +0100879 }
Harald Welte60e823a2017-12-10 14:10:59 +0100880 /* always respond with RESET ACK to RESET */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200881 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) -> value ud_ind {
Harald Welte60e823a2017-12-10 14:10:59 +0100882 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200883 ts_BSSMAP_ResetAck(g_osmux_enabled)));
Harald Welte69c1c262017-12-13 21:02:08 +0100884 repeat;
Harald Welte60e823a2017-12-10 14:10:59 +0100885 }
Harald Welte28d943e2017-11-25 15:00:50 +0100886}
887
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100888altstep no_bssmap_reset() runs on test_CT {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200889 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(g_osmux_enabled))) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100890 setverdict(fail, "unexpected BSSMAP Reset");
Daniel Willmannafce8662018-07-06 23:11:32 +0200891 mtc.stop;
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +0100892 }
893}
894
Daniel Willmann191e0d92018-01-17 12:44:35 +0100895function f_init_mgcp(charstring id) runs on test_CT {
896 id := id & "-MGCP";
897
898 var MGCPOps ops := {
899 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
900 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
901 };
902 var MGCP_conn_parameters mgcp_pars := {
903 callagent_ip := mp_bsc_ip,
Harald Welte9e4273e2018-01-29 22:01:22 +0100904 callagent_udp_port := -1,
Daniel Willmann191e0d92018-01-17 12:44:35 +0100905 mgw_ip := mp_test_ip,
Pau Espin Pedrol1a026a52019-06-18 17:21:52 +0200906 mgw_udp_port := 2427,
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200907 /* Enable it for SCCPlite, since we have 2 MGCP sockets towards MGW (UDP one +
908 the on with MGCP over IPA forwarded from MSC one) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200909 multi_conn_mode := (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER)
Daniel Willmann191e0d92018-01-17 12:44:35 +0100910 };
911
912 vc_MGCP := MGCP_Emulation_CT.create(id);
913 vc_MGCP.start(MGCP_Emulation.main(ops, mgcp_pars, id));
914}
915
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200916/* Enable or disable (current default) Osmux. When enabling, BSSMAP Reset
917 * contains extra IE (OsmuxSupport) and osmo-bsc will handle AssignReq with
918 * OsmuxCID IE.
919 */
920private function f_vty_allow_osmux(boolean allow) runs on test_CT {
921 f_vty_enter_cfg_msc(BSCVTY, 0);
922 if (allow) {
923 f_vty_transceive(BSCVTY, "osmux on");
924 } else {
925 f_vty_transceive(BSCVTY, "osmux off");
926 }
927 f_vty_transceive(BSCVTY, "exit");
928 f_vty_transceive(BSCVTY, "exit");
929 g_osmux_enabled := allow;
930}
931
Max2253c0b2018-11-06 19:28:05 +0100932function f_init_vty(charstring id := "foo") runs on test_CT {
Harald Welte94e0c342018-04-07 11:33:23 +0200933 if (BSCVTY.checkstate("Mapped")) {
934 /* skip initialization if already executed once */
935 return;
936 }
Harald Weltebc03c762018-02-12 18:09:38 +0100937 map(self:BSCVTY, system:BSCVTY);
938 f_vty_set_prompts(BSCVTY);
939 f_vty_transceive(BSCVTY, "enable");
Pau Espin Pedrolc675b612020-01-09 19:55:40 +0100940 f_cs7_inst_0_cfg(BSCVTY, {"sccp-timer ias " & int2str(g_bsc_sccp_timer_ias),
941 "sccp-timer iar " & int2str(g_bsc_sccp_timer_iar)});
Harald Weltebc03c762018-02-12 18:09:38 +0100942}
943
Neels Hofmeyr767548a2020-08-09 20:26:07 +0000944private function f_logp(TELNETasp_PT pt, charstring log_msg)
Neels Hofmeyr4f118412020-06-04 15:25:10 +0200945{
946 // log on TTCN3 log output
947 log(log_msg);
948 // log in stderr log
Neels Hofmeyr767548a2020-08-09 20:26:07 +0000949 f_vty_transceive(pt, "logp lglobal notice TTCN3 f_logp(): " & log_msg);
Neels Hofmeyr4f118412020-06-04 15:25:10 +0200950}
951
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +0200952private function f_sysinfo_seen(integer rsl_idx, RSL_Message rsl) runs on test_CT
953{
954 if (rsl_idx >= lengthof(g_system_information)) {
955 g_system_information[rsl_idx] := SystemInformationConfig_omit
956 }
957 f_sysinfo_dec_raw(g_system_information[rsl_idx], rsl);
958}
959
960altstep as_catch_RSL_sysinfo(integer rsl_idx) runs on test_CT {
961 var ASP_RSL_Unitdata rx_rsl_ud;
962
963 /* For handler_mode := false, receiving the RSL bootstrap messages directly on IPA_RSL */
964 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
965 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
966 repeat;
967 }
968 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
969 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
970 repeat;
971 }
972 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> value rx_rsl_ud {
973 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
974 repeat;
975 }
976 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_SACCH_FILL)) -> value rx_rsl_ud {
977 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
978 repeat;
979 }
980
981 /* For handler_mode := true, receiving the RSL bootstrap messages via RSL_Emulation */
982 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_BCCH_INFO)) -> value rx_rsl_ud {
983 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
984 repeat;
985 }
986 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO)) -> value rx_rsl_ud {
987 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
988 repeat;
989 }
990 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_NO_SACCH_FILL)) -> value rx_rsl_ud {
991 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
992 repeat;
993 }
994 [] RSL_CCHAN[rsl_idx].receive(tr_ASP_RSL_UD(tr_RSL_SACCH_FILL)) -> value rx_rsl_ud {
995 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
996 repeat;
997 }
998}
999
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001000/* TODO: use BooleanList from COMMON/src/General_Types.ttcn */
1001private type record of boolean my_BooleanList;
1002
1003private function f_vty_msc_allow_attach(TELNETasp_PT pt, my_BooleanList allow_attach_list)
1004{
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001005 var charstring config := f_vty_transceive_ret(pt, "show running-config");
1006
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001007 for (var integer msc_nr := 0; msc_nr < sizeof(allow_attach_list); msc_nr := msc_nr+1) {
Neels Hofmeyr8f576712020-08-12 22:49:53 +00001008 if (f_strstr(config, "\nmsc " & int2str(msc_nr) & "\n") < 0) {
1009 /* There is no 'msc N' for this msc_nr in the running config, so don't create an empty msc by
1010 * stepping into that config node. */
1011 log("msc ", msc_nr, " is not configured, skipping");
1012 continue;
1013 }
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001014 f_vty_enter_cfg_msc(pt, msc_nr);
1015 if (allow_attach_list[msc_nr]) {
1016 /* strict := false: ignore if osmo-bsc does not support this config option (latest build) */
1017 f_vty_transceive(pt, "allow-attach", strict := false);
1018 } else {
1019 f_vty_transceive(pt, "no allow-attach", strict := false);
1020 }
1021 f_vty_transceive(pt, "exit");
1022 f_vty_transceive(pt, "exit");
1023 }
1024}
1025
Harald Welte21b46bd2017-12-17 19:46:32 +01001026/* global initialization function
1027 * \param nr_bts Number of BTSs we should start/bring up
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001028 * \param handler_mode Start an RSL_Emulation_CT component (true) or not (false).
1029 * \param nr_msc Number of virtual MSCs to bring up to connect to osmo-bsc.
1030 */
1031function f_init(integer nr_bts := NUM_BTS, boolean handler_mode := false, boolean allow_osmux := false,
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001032 integer nr_msc := 1, float guard_timeout := 30.0) runs on test_CT {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001033 var integer bssap_idx;
Harald Welte28d943e2017-11-25 15:00:50 +01001034
Harald Welteae026692017-12-09 01:03:01 +01001035 if (g_initialized) {
1036 return;
Harald Welte28d943e2017-11-25 15:00:50 +01001037 }
Harald Welteae026692017-12-09 01:03:01 +01001038 g_initialized := true;
1039
Neels Hofmeyr4fbad7f2020-06-16 00:30:47 +02001040 T_guard.start(guard_timeout);
Daniel Willmanne68f9272018-11-27 15:15:28 +01001041 activate(as_Tguard());
1042
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001043 f_init_vty("VirtMSC");
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +02001044 if (mp_enable_osmux_test) {
1045 f_vty_allow_osmux(allow_osmux);
1046 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001047
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001048 var my_BooleanList allow_attach := { false, false, false };
Daniel Willmannebdecc02020-08-12 15:30:17 +02001049 f_init_statsd("VirtMSC", vc_STATSD, mp_test_ip, mp_bsc_statsd_port);
1050
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001051 for (bssap_idx := 0; bssap_idx < nr_msc; bssap_idx := bssap_idx+1) {
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001052 allow_attach[bssap_idx] := true;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001053 /* Call a function of our 'parent component' RAN_Adapter_CT to start the
1054 * MSC-side BSSAP emulation */
1055 if (handler_mode) {
1056 var RanOps ranops := MSC_RanOps;
1057 ranops.use_osmux := g_osmux_enabled;
1058 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", ranops);
1059 connect(self:SCCPLITE_IPA_CTRL, g_bssap[bssap_idx].vc_RAN:CTRL_CLIENT);
1060 f_ran_adapter_start(g_bssap[bssap_idx]);
1061 } else {
1062 f_ran_adapter_init(g_bssap[bssap_idx], mp_bssap_cfg[bssap_idx], "VirtMSC", omit);
1063 connect(self:BSSAP, g_bssap[bssap_idx].vc_SCCP:SCCP_SP_PORT);
1064 f_ran_adapter_start(g_bssap[bssap_idx]);
1065 f_legacy_bssap_reset();
1066 }
Harald Welte67089ee2018-01-17 22:19:03 +01001067 }
Harald Welted5833a82018-05-27 16:52:56 +02001068
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00001069 /* start the test with exactly all enabled MSCs allowed to attach */
1070 f_vty_msc_allow_attach(BSCVTY, allow_attach);
1071
Harald Welteffe55fc2018-01-17 22:39:54 +01001072 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
Harald Welte28d943e2017-11-25 15:00:50 +01001073
Daniel Willmann191e0d92018-01-17 12:44:35 +01001074 f_init_mgcp("VirtMSC");
1075
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001076 for (var integer i := 0; i < nr_bts; i := i+1) {
1077 f_init_bts(i, handler_mode);
Harald Welte696ddb62017-12-08 14:01:43 +01001078 }
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001079}
Harald Welte696ddb62017-12-08 14:01:43 +01001080
Neels Hofmeyr0b7365b2020-07-04 00:52:34 +02001081function f_init_bts(integer bts_idx := 0, boolean handler_mode := false)
1082runs on test_CT {
1083 /* wait until osmo-bts-omldummy has respawned */
1084 f_wait_oml(bts_idx, "degraded", 5.0);
1085
1086 /* start RSL connection */
1087 f_ipa_rsl_start(bts[bts_idx].rsl, mp_bsc_ip, mp_bsc_rsl_port, bts_idx, handler_mode);
1088 /* wait until BSC tells us "connected" */
1089 f_wait_oml(bts_idx, "connected", 5.0);
Harald Welte28d943e2017-11-25 15:00:50 +01001090}
1091
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02001092function f_init_bts_and_check_sysinfo(integer bts_idx := 0, boolean handler_mode := false,
1093 template SystemInformationConfig expect_si)
1094runs on test_CT {
1095 var default sysinfo := activate(as_catch_RSL_sysinfo(bts_idx));
1096
1097 f_init_bts(bts_idx, handler_mode);
1098
1099 /* Give some time to (hopefully/most likely) collect all system informations from RSL startup.
1100 * We could stop as soon as all expected SI are received, but then we might miss SI that we don't expect and
1101 * that might be sent afterwards. So rather give a generous timeout and be quite sure to catch all SI.
1102 */
1103 f_sleep(5.0);
1104 log("RSL ", bts_idx, " SYSTEM INFORMATION: ", g_system_information[bts_idx]);
1105
1106 deactivate(sysinfo);
1107
1108 if (match(g_system_information[bts_idx], expect_si)) {
1109 setverdict(pass);
1110 } else {
1111 log("RSL ", bts_idx, ": EXPECTED SI: ", expect_si);
1112 log("RSL ", bts_idx, ": GOT SI: ", g_system_information[bts_idx]);
1113 setverdict(fail, "received SI does not match expectations");
1114 return;
1115 }
1116}
1117
Maxd4e56962018-10-31 19:08:25 +01001118/* expect to receive a RSL message matching a specified template on a given BTS / stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001119function 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 +01001120runs on test_CT return RSL_Message {
1121 var ASP_RSL_Unitdata rx_rsl_ud;
1122 timer T := t_secs;
1123
1124 T.start;
1125 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001126 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(t_rx, sid)) -> value rx_rsl_ud {
Harald Welteae026692017-12-09 01:03:01 +01001127 T.stop;
1128 }
1129 [] IPA_RSL[bts_nr].receive { repeat; }
Harald Welteb2917702017-12-10 15:48:52 +01001130 [] T.timeout {
1131 setverdict(fail, "Timeout expecting ", t_rx);
Daniel Willmannafce8662018-07-06 23:11:32 +02001132 mtc.stop;
Harald Welteb2917702017-12-10 15:48:52 +01001133 }
Harald Welteae026692017-12-09 01:03:01 +01001134 }
1135 return rx_rsl_ud.rsl;
1136}
1137
Harald Welte21b46bd2017-12-17 19:46:32 +01001138/* helper function to transmit RSL on a given BTS/stream */
Harald Welte65e419a2020-08-21 12:38:33 +02001139function 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 +01001140runs on test_CT {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001141 IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(t_tx, sid));
Harald Welteae026692017-12-09 01:03:01 +01001142}
1143
1144
Harald Welte4003d112017-12-09 22:35:39 +01001145/* verify we get a CHAN_ACT after CHAN RQD */
Harald Welteae026692017-12-09 01:03:01 +01001146testcase TC_chan_act_noreply() runs on test_CT {
1147 var BSSAP_N_UNITDATA_ind ud_ind;
Harald Welte930d0a72018-03-22 22:08:40 +01001148 var RSL_Message rsl_unused;
Harald Welte28d943e2017-11-25 15:00:50 +01001149
Harald Welte89d42e82017-12-17 16:42:41 +01001150 f_init(1);
Harald Welte28d943e2017-11-25 15:00:50 +01001151
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001152 IPA_RSL[0].send(ts_ASP_RSL_UD(ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +01001153 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001154 f_shutdown_helper();
Harald Welte28d943e2017-11-25 15:00:50 +01001155}
1156
Harald Welte4003d112017-12-09 22:35:39 +01001157/* verify if the "chreq:total" counter increments as expected */
1158testcase TC_chan_act_counter() runs on test_CT {
1159 var BSSAP_N_UNITDATA_ind ud_ind;
1160 var integer chreq_total;
Harald Welte930d0a72018-03-22 22:08:40 +01001161 var RSL_Message rsl_unused;
Harald Welte4003d112017-12-09 22:35:39 +01001162
Harald Welte89d42e82017-12-17 16:42:41 +01001163 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001164
1165 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001166 IPA_RSL[0].send(ts_ASP_RSL_UD(ts_RSL_CHAN_RQD('23'O, 23)));
Harald Welte930d0a72018-03-22 22:08:40 +01001167 rsl_unused := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
Harald Welte4003d112017-12-09 22:35:39 +01001168 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total", chreq_total+1);
1169
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001170 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001171}
1172
Harald Welteae026692017-12-09 01:03:01 +01001173/* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */
Philipp Maier9c60a622020-07-09 15:08:46 +02001174private function f_TC_chan_act_ack_noest(OCT1 ra := '23'O) runs on test_CT {
Harald Welteae026692017-12-09 01:03:01 +01001175 var RSL_Message rx_rsl;
1176
Harald Welteae026692017-12-09 01:03:01 +01001177 /* Send CHAN RQD and wait for allocation; acknowledge it */
Philipp Maier9c60a622020-07-09 15:08:46 +02001178 var RslChannelNr chan_nr := f_chreq_act_ack(ra);
Harald Welteae026692017-12-09 01:03:01 +01001179
1180 /* expect BSC to disable the channel again if there's no RLL EST IND */
1181 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1182
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001183 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001184}
1185
Philipp Maier9c60a622020-07-09 15:08:46 +02001186/* Normal variant */
1187testcase TC_chan_act_ack_noest() runs on test_CT {
Philipp Maieraf58db22020-08-12 17:24:40 +02001188 f_init(1);
Philipp Maier9c60a622020-07-09 15:08:46 +02001189 f_TC_chan_act_ack_noest();
1190}
1191
1192/* Emergency call variant */
1193testcase TC_chan_act_ack_noest_emerg() runs on test_CT {
1194 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
Philipp Maieraf58db22020-08-12 17:24:40 +02001195 f_init(1);
1196 f_vty_allow_emerg_bts(true, 0);
Philipp Maier9c60a622020-07-09 15:08:46 +02001197 f_TC_chan_act_ack_noest(ra := 'A5'O);
1198}
1199
Philipp Maier606f07d2020-08-12 17:21:58 +02001200/* Emergency call variant, but emergency calls are not allowed */
1201testcase TC_chan_rqd_emerg_deny() runs on test_CT {
1202 /* See also: 3GPP TS 04.08, Table 9.9, ra=101xxxxx */
1203
1204 var RSL_Message rx_rsl;
1205 var GsmRrMessage rr;
1206
1207 f_init(1);
1208 f_vty_allow_emerg_bts(false, 0);
1209
1210 IPA_RSL[0].clear;
1211 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
1212
1213 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
1214 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
1215 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1216 setverdict(pass);
1217 } else {
1218 setverdict(fail, "immediate assignment not rejected");
1219 }
1220}
1221
Harald Welteae026692017-12-09 01:03:01 +01001222/* Test behavior if MSC never answers to CR */
1223testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT {
Harald Weltef77aef62018-01-28 15:35:42 +01001224 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
1225 var IpaStreamId sid := IPAC_PROTO_RSL_TRX0;
Harald Welteae026692017-12-09 01:03:01 +01001226 var RSL_Message rx_rsl;
Harald Weltef77aef62018-01-28 15:35:42 +01001227 var ASP_RSL_Unitdata rx_rsl_ud;
Harald Welteae026692017-12-09 01:03:01 +01001228
Harald Welte89d42e82017-12-17 16:42:41 +01001229 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001230
1231 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001232 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001233
1234 var octetstring l3 := '00010203040506'O
1235 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1236
1237 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3)));
1238
1239 /* expect BSC to disable the channel again if there's no response from MSC */
Harald Weltef77aef62018-01-28 15:35:42 +01001240 /* MS waits 20s (T3210) at LU; 10s (T3230) at CM SERV REQ and 5s (T3220) AT detach */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001241 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001242 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001243}
1244
1245/* Test behavior if MSC answers with CREF to CR */
1246testcase TC_chan_act_ack_est_ind_refused() runs on test_CT {
1247 var BSSAP_N_CONNECT_ind rx_c_ind;
1248 var RSL_Message rx_rsl;
1249
Harald Welte89d42e82017-12-17 16:42:41 +01001250 f_init(1);
Harald Welteae026692017-12-09 01:03:01 +01001251
1252 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001253 var RslChannelNr chan_nr := f_chreq_act_ack();
Harald Welteae026692017-12-09 01:03:01 +01001254
1255 var octetstring l3 := '00010203040506'O
1256 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1257
1258 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1259 BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0));
1260
1261 /* expect BSC to disable the channel */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001262 f_expect_chan_rel(0, chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001263 f_shutdown_helper();
Harald Welteae026692017-12-09 01:03:01 +01001264}
1265
Harald Welte618ef642017-12-14 14:58:20 +01001266/* CHAN RQD -> CHAN ACT -> CHAN ACT NACK -> RF CHAN REL */
1267testcase TC_chan_act_nack() runs on test_CT {
1268 var RSL_Message rx_rsl;
1269 var integer chact_nack;
1270
Harald Welte89d42e82017-12-17 16:42:41 +01001271 f_init(1);
Harald Welte618ef642017-12-14 14:58:20 +01001272
1273 chact_nack := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack");
1274
1275 f_ipa_tx(0, ts_RSL_CHAN_RQD('33'O, 33));
1276 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1277 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1278
1279 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
1280
1281 /* wait for some time to hope the NACK arrives before the CTRL GET below */
1282 f_sleep(0.5);
1283
1284 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chan_act:nack", chact_nack+1);
1285
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001286 f_shutdown_helper();
Harald Welte618ef642017-12-14 14:58:20 +01001287}
1288
Harald Welte799c97b2017-12-14 17:50:30 +01001289/* Test for channel exhaustion due to RACH overload */
1290testcase TC_chan_exhaustion() runs on test_CT {
1291 var ASP_RSL_Unitdata rsl_ud;
1292 var integer i;
1293 var integer chreq_total, chreq_nochan;
1294
Harald Welte89d42e82017-12-17 16:42:41 +01001295 f_init(1);
Harald Welte799c97b2017-12-14 17:50:30 +01001296
1297 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
1298 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
1299
Pau Espin Pedrolfe200d72018-12-10 12:41:04 +01001300 /* GSM 04.08 Table 9.9a:
1301 * RA = '33'O -> Establishment cause = 0011xxxx (MS dual rate capable and asks for "TCH/H or TCH/F").
1302 * With current setup, expect 4xSDCCH + 4xTCH/F + 1xTCH/H to succeed */
Philipp Maiercb6cc482018-03-26 13:08:00 +02001303 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 +01001304 var RslChannelNr chan_nr := f_chreq_act_ack('33'O, i);
Harald Welte799c97b2017-12-14 17:50:30 +01001305 }
1306
1307 IPA_RSL[0].clear;
1308
Harald Weltedd8cbf32018-01-28 12:07:52 +01001309 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001310 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
Harald Welte799c97b2017-12-14 17:50:30 +01001311
1312 /* now expect additional channel activations to fail */
1313 f_ipa_tx(0, ts_RSL_CHAN_RQD('42'O, 42));
1314
1315 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001316 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) {
Harald Welte799c97b2017-12-14 17:50:30 +01001317 setverdict(fail, "Received CHAN ACT ACK without resources?!?");
1318 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001319 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) -> value rsl_ud {
Harald Welte799c97b2017-12-14 17:50:30 +01001320 var GsmRrMessage rr;
1321 /* match on IMM ASS REJ */
1322 rr := dec_GsmRrMessage(rsl_ud.rsl.ies[1].body.full_imm_ass_info.payload);
1323 if (rr.header.message_type == IMMEDIATE_ASSIGNMENT_REJECT) {
1324 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
Philipp Maiercb6cc482018-03-26 13:08:00 +02001325 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS+1);
Harald Welte799c97b2017-12-14 17:50:30 +01001326 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel",
1327 chreq_nochan+1);
1328 setverdict(pass);
1329 } else {
1330 repeat;
1331 }
1332 }
1333 [] IPA_RSL[0].receive { repeat; }
1334 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001335 f_shutdown_helper();
Harald Welte799c97b2017-12-14 17:50:30 +01001336}
1337
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001338/* Test channel deactivation due to silence from MS */
1339testcase TC_chan_deact_silence() runs on test_CT {
1340 var RslChannelNr chan_nr;
1341
1342 f_init(1);
1343
1344 /* Request for a dedicated channel */
1345 chan_nr := f_chreq_act_ack('23'O);
1346
1347 /* Wait some time until the channel is released */
1348 f_sleep(2.0);
1349
1350 /* Expect CHANnel RELease */
1351 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001352 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001353 log("Received CHANnel RELease");
1354 setverdict(pass);
1355 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001356 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN(?))) {
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001357 /* See OS#3709, OsmoBSC should not send Immediate
1358 * Assignment Reject since a dedicated channel was
1359 * already allocated, and Immediate Assignment was
1360 * already sent. */
1361 setverdict(fail, "Unexpected Immediate Assignment!");
1362 }
1363 [] IPA_RSL[0].receive {
1364 setverdict(fail, "Unexpected RSL message!");
1365 }
1366 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001367 f_shutdown_helper();
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07001368}
1369
Harald Weltecfe2c962017-12-15 12:09:32 +01001370/***********************************************************************
1371 * Assignment Testing
1372 ***********************************************************************/
1373
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02001374/* Verify that the BSC refuses any BSSAP connection from the MSC (They are all BSC->MSC direction,
1375 * except for the inter-BSC handover, MT side) */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001376testcase TC_outbound_connect(integer bssap_idx := 0) runs on test_CT {
Harald Welte89d42e82017-12-17 16:42:41 +01001377 f_init(1);
Harald Weltecfe2c962017-12-15 12:09:32 +01001378
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001379 BSSAP.send(ts_BSSAP_CONNECT_req(g_bssap[bssap_idx].sccp_addr_peer, g_bssap[bssap_idx].sccp_addr_own,
1380 2342, ts_BSSMAP_AssignmentReq));
Harald Weltecfe2c962017-12-15 12:09:32 +01001381 BSSAP.receive(tr_BSSAP_DISC_ind(2342, ?, ?));
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001382 f_shutdown_helper();
Harald Weltecfe2c962017-12-15 12:09:32 +01001383}
1384
Harald Welte16a4adf2017-12-14 18:54:01 +01001385/* Test behavior if MSC answers with CREF to CR */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001386testcase TC_assignment_cic_only(integer bssap_idx := 0) runs on test_CT {
Harald Welte16a4adf2017-12-14 18:54:01 +01001387 var BSSAP_N_CONNECT_ind rx_c_ind;
1388 var RSL_Message rx_rsl;
1389 var DchanTuple dt;
1390
Harald Welte89d42e82017-12-17 16:42:41 +01001391 f_init(1);
Harald Welte16a4adf2017-12-14 18:54:01 +01001392
1393 dt := f_est_dchan('23'O, 23, '00000000'O);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001394 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte17b27da2018-05-25 20:33:53 +02001395 /* send assignment without AoIP IEs */
1396 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(ts_BSSMAP_IE_CIC(0, 1))));
1397 } else {
1398 /* Send assignmetn without CIC in IPA case */
1399 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
1400 valueof(ts_BSSMAP_IE_AoIP_TLA4('01020304'O, 2342));
1401 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_AssignmentReq(omit, tla)));
1402 }
Harald Welte16a4adf2017-12-14 18:54:01 +01001403 alt {
1404 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1405 setverdict(fail, "AoIP BSC cannot accept ASSIGNMENT without AoIP Transport IE");
1406 }
Harald Welte235ebf12017-12-15 14:18:16 +01001407 /* TODO: Actually expect GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP */
Harald Welte16a4adf2017-12-14 18:54:01 +01001408 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1409 setverdict(pass);
1410 }
1411 [] BSSAP.receive { repeat; }
1412 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001413 f_shutdown_helper();
Harald Welte16a4adf2017-12-14 18:54:01 +01001414}
1415
Harald Welteed848512018-05-24 22:27:58 +02001416/* generate an assignment request for either AoIP or SCCPlite */
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001417function 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 +02001418 var PDU_BSSAP ass_cmd;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001419 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001420 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welteed848512018-05-24 22:27:58 +02001421 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001422 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001423 if (osmux_enabled) {
1424 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla, osmux_cid));
1425 } else {
1426 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(omit, tla));
1427 }
Harald Welteed848512018-05-24 22:27:58 +02001428 } else {
1429 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001430 ass_cmd := valueof(ts_BSSMAP_AssignmentReq(cic, omit));
Harald Welteed848512018-05-24 22:27:58 +02001431 }
1432 return ass_cmd;
1433}
1434
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001435function f_gen_handover_req(integer bssap_idx := 0, charstring aoip_tla := "1.2.3.4") return PDU_BSSAP {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001436 var PDU_BSSAP ho_req;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001437 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001438 var BSSMAP_IE_AoIP_TransportLayerAddress tla :=
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001439 valueof(f_ts_BSSMAP_IE_AoIP_TLA(aoip_tla, 2342));
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01001440 ho_req := valueof(ts_BSSMAP_HandoverRequest(omit, tla));
1441 } else {
1442 var BSSMAP_IE_CircuitIdentityCode cic := valueof(ts_BSSMAP_IE_CIC(0,1));
1443 ho_req := valueof(ts_BSSMAP_HandoverRequest(cic, omit));
1444 }
1445 return ho_req;
1446}
1447
Harald Welteed848512018-05-24 22:27:58 +02001448/* generate an assignment complete template for either AoIP or SCCPlite */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001449function f_gen_exp_compl(boolean expect_osmux := false, integer bssap_idx := 0) return template PDU_BSSAP {
Harald Welteed848512018-05-24 22:27:58 +02001450 var template PDU_BSSAP exp_compl;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001451 var BSSMAP_IE_Osmo_OsmuxCID osmux_cid := valueof(ts_OsmuxCID(0));
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001452 if (mp_bssap_cfg[bssap_idx].transport == BSSAP_TRANSPORT_AoIP) {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02001453 if (expect_osmux) {
1454 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, osmux_cid);
1455 } else {
1456 exp_compl := tr_BSSMAP_AssignmentComplete(omit, ?, omit);
1457 }
Harald Welteed848512018-05-24 22:27:58 +02001458 } else {
1459 /* CIC is optional "*" as the MSC allocated it */
Pau Espin Pedrol096d73d2019-06-06 12:49:17 +02001460 exp_compl := tr_BSSMAP_AssignmentComplete(*, omit);
Harald Welteed848512018-05-24 22:27:58 +02001461 }
1462 return exp_compl;
1463}
1464
Harald Welte235ebf12017-12-15 14:18:16 +01001465/* Run everything required up to sending a caller-specified assignment command and expect response */
1466function f_assignment_exp(PDU_BSSAP ass_cmd, template PDU_BSSAP exp, charstring fail_text)
1467runs on test_CT {
1468 var BSSAP_N_CONNECT_ind rx_c_ind;
1469 var RSL_Message rx_rsl;
1470 var DchanTuple dt;
1471
Harald Welte89d42e82017-12-17 16:42:41 +01001472 f_init(1);
Harald Welte235ebf12017-12-15 14:18:16 +01001473
1474 dt := f_est_dchan('23'O, 23, '00000000'O);
1475 /* send assignment without AoIP IEs */
1476 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
1477 alt {
1478 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentComplete)) {
1479 if (ischosen(exp.pdu.bssmap.assignmentComplete)) {
1480 setverdict(pass);
1481 } else {
1482 setverdict(fail, fail_text);
1483 }
1484 }
1485 [] BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_AssignmentFail)) {
1486 if (ischosen(exp.pdu.bssmap.assignmentFailure)) {
1487 setverdict(pass);
1488 } else {
1489 setverdict(fail, fail_text);
1490 }
1491 }
1492 [] BSSAP.receive { repeat; }
1493 }
1494}
1495testcase TC_assignment_csd() runs on test_CT {
1496 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001497 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001498 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCSD);
1499 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
1500 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for CSD");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001501 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001502}
1503
1504testcase TC_assignment_ctm() runs on test_CT {
1505 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02001506 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte235ebf12017-12-15 14:18:16 +01001507 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeCTM);
1508 //exp_fail.pdu.bssmap.assignmentFailure.cause.causeValue := int2bit(enum2int(GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL), 7);
1509 f_assignment_exp(ass_cmd, exp_fail, "BSC accepted Assignment for Speech+CTM");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001510 f_shutdown_helper();
Harald Welte235ebf12017-12-15 14:18:16 +01001511}
1512
Harald Welte4003d112017-12-09 22:35:39 +01001513type record DchanTuple {
1514 integer sccp_conn_id,
1515 RslChannelNr rsl_chan_nr
Harald Weltea5d2ab22017-12-09 14:21:42 +01001516}
1517
Harald Welted6939652017-12-13 21:02:46 +01001518/* Send CHAN RQD and wait for allocation; acknowledge it */
1519private function f_chreq_act_ack(OCT1 ra := '23'O, GsmFrameNumber fn := 23)
1520runs on test_CT return RslChannelNr {
1521 var RSL_Message rx_rsl;
1522 f_ipa_tx(0, ts_RSL_CHAN_RQD(ra, fn));
1523 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
1524 var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr;
1525 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, fn+10));
Daniel Willmannf4ac4ce2018-08-02 14:06:30 +02001526 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Harald Welted6939652017-12-13 21:02:46 +01001527 return chan_nr;
1528}
1529
Harald Welte4003d112017-12-09 22:35:39 +01001530/* helper function to establish a dedicated channel via BTS and MSC */
1531function f_est_dchan(OCT1 ra, GsmFrameNumber fn, octetstring l3)
1532runs on test_CT return DchanTuple {
1533 var BSSAP_N_CONNECT_ind rx_c_ind;
Harald Welte4003d112017-12-09 22:35:39 +01001534 var DchanTuple dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001535
Harald Welte4003d112017-12-09 22:35:39 +01001536 /* Send CHAN RQD and wait for allocation; acknowledge it */
Harald Welted6939652017-12-13 21:02:46 +01001537 dt.rsl_chan_nr := f_chreq_act_ack(ra, fn);
Harald Welte4003d112017-12-09 22:35:39 +01001538
1539 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1540
1541 BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind;
1542 dt.sccp_conn_id := rx_c_ind.connectionId;
1543 BSSAP.send(ts_BSSAP_CONNECT_res(dt.sccp_conn_id));
1544
1545 return dt;
Harald Weltea5d2ab22017-12-09 14:21:42 +01001546}
1547
Harald Welte641fcbe2018-06-14 10:58:35 +02001548/* expect RF CAN REL from BTS, acknowledge it and clear the MSC side */
1549private function f_exp_chan_rel_and_clear(DchanTuple dt, integer bts_nr := 0) runs on test_CT {
1550 var RSL_Message rx_rsl;
1551 /* expect BSC to disable the channel */
1552 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX);
1553 /* respond with CHAN REL ACK */
1554 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1555
1556 /* expect Clear Complete from BSC */
1557 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1558
1559 /* MSC disconnects as instructed. */
1560 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1561}
1562
Harald Welte4003d112017-12-09 22:35:39 +01001563/* Test behavior of channel release after unilateral RLL REL IND (DISC from MS) */
1564testcase TC_chan_rel_rll_rel_ind() runs on test_CT {
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001565 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001566 var DchanTuple dt;
Harald Welte96c94412017-12-09 03:12:45 +01001567
Harald Welte89d42e82017-12-17 16:42:41 +01001568 f_init(1);
Harald Welte96c94412017-12-09 03:12:45 +01001569
Harald Welte4003d112017-12-09 22:35:39 +01001570 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1571
1572 /* simulate RLL REL IND */
1573 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
1574
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001575 /* expect Clear Request on MSC side */
1576 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1577
1578 /* Instruct BSC to clear channel */
1579 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1580 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1581
Harald Welte4003d112017-12-09 22:35:39 +01001582 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001583 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr27f64362018-03-12 01:44:00 +01001584
1585 /* wait for SCCP emulation to do its job */
1586 f_sleep(1.0);
Harald Welte4003d112017-12-09 22:35:39 +01001587
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001588 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001589}
1590
1591/* Test behavior of channel release after CONN FAIL IND from BTS */
1592testcase TC_chan_rel_conn_fail() runs on test_CT {
1593 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001594 var DchanTuple dt;
1595
Harald Welte89d42e82017-12-17 16:42:41 +01001596 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001597
1598 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1599
1600 /* simulate CONN FAIL IND */
Harald Weltea8ed9062017-12-14 09:46:01 +01001601 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 +01001602 /* TODO: different cause values? */
1603
Harald Welte4003d112017-12-09 22:35:39 +01001604 /* expect Clear Request from BSC */
1605 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
1606
1607 /* Instruct BSC to clear channel */
1608 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
1609 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1610
Harald Welte6ff76ea2018-01-28 13:08:01 +01001611 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02001612 f_exp_chan_rel_and_clear(dt, 0);
Harald Welte4003d112017-12-09 22:35:39 +01001613
1614 /* wait for SCCP emulation to do its job */
1615 f_sleep(1.0);
1616
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001617 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001618}
1619
Harald Welte99f3ca02018-06-14 13:40:29 +02001620/* Test behavior of early CONN FAIL IND from BTS (before EST IND!) */
1621/* See also https://www.osmocom.org/issues/3182 */
1622testcase TC_early_conn_fail() runs on test_CT {
1623 var RSL_Message rx_rsl;
1624 var DchanTuple dt;
1625
1626 f_init(1);
1627
1628 /* BTS->BSC: Send CHAN RQD and wait for allocation; acknowledge it */
1629 dt.rsl_chan_nr := f_chreq_act_ack(f_rnd_octstring(1), 23);
1630
1631 /* BTS->BSC: simulate CONN FAIL IND */
1632 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1633
1634 /* BTS->BSC: Expect RF channel release from BSC on Abis */
1635 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1636
1637 /* BTS<-BSC: respond with CHAN REL ACK */
1638 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1639
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001640 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001641}
1642
1643/* Test behavior of late CONN FAIL IND from BTS (ater REL IND!) */
1644/* See also https://www.osmocom.org/issues/3182 */
1645testcase TC_late_conn_fail() runs on test_CT {
1646 var RSL_Message rx_rsl;
1647 var DchanTuple dt;
1648
1649 f_init(1);
1650
1651 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1652
1653 /* BSC<-MSC: Instruct BSC to clear connection */
1654 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(0)));
1655
1656 /* BTS->BSC: expect BSC to deactivate SACCH */
1657 rx_rsl := f_exp_ipa_rx(0, tr_RSL_DEACT_SACCH(dt.rsl_chan_nr));
1658
1659 /* BTS->BSC: simulate a late CONN FAIL IND from BTS */
1660 f_ipa_tx(0, ts_RSL_CONN_FAIL_IND(dt.rsl_chan_nr, RSL_ERR_RADIO_LINK_FAIL));
1661
1662 /* BTS<-BSC: Expect RF channel release from BSC on Abis */
1663 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), 10.0);
1664 /* BTS->BSC: respond with CHAN REL ACK */
1665 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(dt.rsl_chan_nr));
1666
1667 /* BSC->MSC: expect Clear Complete from BSC */
1668 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete));
1669
1670 /* BSC<-MSC: MSC disconnects as requested. */
1671 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1672
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001673 f_shutdown_helper();
Harald Welte99f3ca02018-06-14 13:40:29 +02001674}
1675
Neels Hofmeyrf44ccd12018-11-05 19:15:23 +01001676function f_expect_chan_rel(integer bts_nr, RslChannelNr rsl_chan_nr,
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001677 boolean expect_deact_sacch := true,
1678 boolean expect_rr_chan_rel := true,
1679 boolean expect_rll_rel_req := true,
Harald Welte99787102019-02-04 10:41:36 +01001680 boolean handle_rll_rel := true,
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02001681 boolean is_csfb := false,
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001682 template CellSelIndValue csfb_expect_cells := omit,
1683 template RR_Cause expect_rr_cause := ?
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001684 ) runs on test_CT {
Harald Welte91d54a52018-01-28 15:35:07 +01001685
1686 var RslLinkId main_dcch := valueof(ts_RslLinkID_DCCH(0));
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001687 var boolean got_deact_sacch := false;
1688 var boolean got_rr_chan_rel := false;
1689 var boolean got_rll_rel_req := false;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02001690 var ASP_RSL_Unitdata ud;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001691 var RSL_IE_Body l3_ie;
1692 var PDU_ML3_NW_MS l3;
1693 var RR_Cause got_cause;
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001694 log("f_expect_chan_rel() expecting: expect_deact_sacch=", expect_deact_sacch, " expect_rr_chan_rel=", expect_rr_chan_rel,
1695 " expect_rll_rel_req=", expect_rll_rel_req);
Harald Welte91d54a52018-01-28 15:35:07 +01001696 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001697 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_DEACT_SACCH(rsl_chan_nr))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001698 got_deact_sacch := true;
Harald Welte91d54a52018-01-28 15:35:07 +01001699 repeat;
1700 }
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02001701 [is_csfb] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_DATA_REQ(rsl_chan_nr, ?, decmatch tr_RRM_RR_RELEASE_CSFB))) -> value ud {
Harald Welte99787102019-02-04 10:41:36 +01001702 got_rr_chan_rel := true;
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02001703
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001704 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
1705 setverdict(fail, "cannot find L3");
1706 mtc.stop;
1707 }
1708 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
1709
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02001710 if (not istemplatekind(csfb_expect_cells, "omit")) {
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02001711 var CellSelIndValue cells := dec_CellSelIndValue(
1712 l3.msgs.rrm.channelRelease.cellSelectionIndicator.cellSelectionIndicatorValue);
1713
1714 log("GOT RR CHANNEL RELEASE CSFB CELLS: ", cells);
1715 if (match(cells, csfb_expect_cells)) {
1716 setverdict(pass);
1717 } else {
1718 log("EXPECTED CSFB CELLS: ", csfb_expect_cells);
1719 setverdict(fail, "Received CSFB cells list on RR Channel Release does not match expectations");
1720 }
1721 }
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001722
1723 if (not istemplatekind(expect_rr_cause, "omit")) {
1724 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
1725 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
1726 if (match(got_cause, expect_rr_cause)) {
1727 setverdict(pass);
1728 } else {
1729 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
1730 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
1731 }
1732 }
Harald Welte99787102019-02-04 10:41:36 +01001733 repeat;
1734 }
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001735 [not is_csfb] 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 +01001736 got_rr_chan_rel := true;
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001737
1738 if (not istemplatekind(expect_rr_cause, "omit")) {
1739 if (f_rsl_find_ie(ud.rsl, RSL_IE_L3_INFO, l3_ie) == false) {
1740 setverdict(fail, "cannot find L3");
1741 mtc.stop;
1742 }
1743 l3 := dec_PDU_ML3_NW_MS(l3_ie.l3_info.payload);
1744
1745 int2enum(oct2int(l3.msgs.rrm.channelRelease.rRCause.valuePart), got_cause);
1746 log("GOT CAUSE CODE: ", l3.msgs.rrm.channelRelease.rRCause.valuePart, " = ", got_cause);
1747 if (match(got_cause, expect_rr_cause)) {
1748 setverdict(pass);
1749 } else {
1750 log("EXPECTED CAUSE CODE: ", expect_rr_cause);
1751 setverdict(fail, "Received RR Channel Release Cause code does not match expectations");
1752 }
1753 }
Neels Hofmeyr211169d2018-11-07 00:37:29 +01001754 repeat;
1755 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001756 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_REL_REQ(rsl_chan_nr, ?))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001757 got_rll_rel_req := true;
Harald Welte91d54a52018-01-28 15:35:07 +01001758 /* FIXME: Why are we getting this for LinkID SACCH? */
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001759 if (handle_rll_rel) {
1760 f_ipa_tx(0, ts_RSL_REL_CONF(rsl_chan_nr, main_dcch));
1761 }
Harald Welte91d54a52018-01-28 15:35:07 +01001762 repeat;
1763 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001764 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL))) {
Harald Welte91d54a52018-01-28 15:35:07 +01001765 /* respond with CHAN REL ACK */
1766 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(rsl_chan_nr));
1767 }
1768 /* ignore any user data */
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07001769 [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeR(?))) {
Harald Welte91d54a52018-01-28 15:35:07 +01001770 repeat;
1771 }
1772 }
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001773
1774 log("f_expect_chan_rel() summary: got_deact_sacch=", got_deact_sacch, " got_rr_chan_rel=", got_rr_chan_rel,
1775 " got_rll_rel_req=", got_rll_rel_req);
1776
1777 if (expect_deact_sacch != got_deact_sacch) {
1778 setverdict(fail, "f_expect_chan_rel(): expect_deact_sacch=", expect_deact_sacch, " got_deact_sacch=", got_deact_sacch);
1779 }
1780 if (expect_rr_chan_rel != got_rr_chan_rel) {
1781 setverdict(fail, "f_expect_chan_rel(): expect_rr_chan_rel=", expect_rr_chan_rel, " got_rr_chan_rel=", got_rr_chan_rel);
1782 }
1783 if (expect_rll_rel_req != got_rll_rel_req) {
1784 setverdict(fail, "f_expect_chan_rel(): expect_rll_rel_req=", expect_rll_rel_req, " got_rll_rel_req=", got_rll_rel_req);
1785 }
Harald Welte91d54a52018-01-28 15:35:07 +01001786}
1787
Harald Welte4003d112017-12-09 22:35:39 +01001788/* Test behavior of channel release after hard Clear Command from MSC */
1789testcase TC_chan_rel_hard_clear() runs on test_CT {
1790 var BSSAP_N_DATA_ind rx_di;
Harald Welte4003d112017-12-09 22:35:39 +01001791 var DchanTuple dt;
Harald Welte4003d112017-12-09 22:35:39 +01001792
Harald Welte89d42e82017-12-17 16:42:41 +01001793 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01001794
1795 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1796
1797 /* Instruct BSC to clear channel */
1798 var BssmapCause cause := 0;
1799 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
1800
1801 /* expect Clear Complete from BSC on A */
1802 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
1803 /* release the SCCP connection */
1804 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1805 }
1806
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001807 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001808 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01001809}
1810
Harald Welte99787102019-02-04 10:41:36 +01001811/* Test behavior of channel release after Clear Command with CSFB indicator from MSC */
1812testcase TC_chan_rel_hard_clear_csfb() runs on test_CT {
1813 var BSSAP_N_DATA_ind rx_di;
1814 var DchanTuple dt;
1815
1816 f_init(1);
1817
1818 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1819
1820 /* Instruct BSC to clear channel */
1821 var BssmapCause cause := 0;
1822 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
1823
1824 /* expect Clear Complete from BSC on A */
1825 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
1826 /* release the SCCP connection */
1827 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1828 }
1829
1830 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, is_csfb := true);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001831 f_shutdown_helper();
Harald Welte99787102019-02-04 10:41:36 +01001832}
1833
Harald Welted8c36cd2017-12-09 23:05:31 +01001834/* Test behavior of channel release after hard RLSD from MSC */
1835testcase TC_chan_rel_hard_rlsd() runs on test_CT {
Harald Welted8c36cd2017-12-09 23:05:31 +01001836 var DchanTuple dt;
Harald Welted8c36cd2017-12-09 23:05:31 +01001837
Harald Welte89d42e82017-12-17 16:42:41 +01001838 f_init(1);
Harald Welted8c36cd2017-12-09 23:05:31 +01001839
1840 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1841
1842 /* release the SCCP connection */
1843 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1844
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001845 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001846 f_shutdown_helper();
Harald Welted8c36cd2017-12-09 23:05:31 +01001847}
1848
Harald Welte550daf92018-06-11 19:22:13 +02001849/* Test behavior of channel release after hard RLSD from MSC and MS is not responding to RLL REL REQ */
1850testcase TC_chan_rel_hard_rlsd_ms_dead() runs on test_CT {
1851 var DchanTuple dt;
1852
1853 f_init(1);
1854
1855 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1856
1857 /* release the SCCP connection */
1858 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1859
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001860 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001861 f_shutdown_helper();
Harald Welte550daf92018-06-11 19:22:13 +02001862}
1863
Harald Welte85804d42017-12-10 14:11:58 +01001864/* Test behavior of channel release after BSSMAP RESET from MSC */
1865testcase TC_chan_rel_a_reset() runs on test_CT {
Harald Welte85804d42017-12-10 14:11:58 +01001866 var DchanTuple dt;
Harald Welte85804d42017-12-10 14:11:58 +01001867
Harald Welte89d42e82017-12-17 16:42:41 +01001868 f_init(1);
Harald Welte85804d42017-12-10 14:11:58 +01001869
1870 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1871
1872 /* Clear the queue, it might still contain stuff like IMMEDIATE ASSIGN */
1873 IPA_RSL[0].clear;
1874
1875 /* perform BSSAP RESET, expect RESET ACK and DISC.ind on connection */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001876 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 +01001877 interleave {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02001878 [] 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 +01001879 [] BSSAP.receive(tr_BSSAP_DISC_ind(dt.sccp_conn_id, ?, ?)) { }
1880 }
1881
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001882 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001883 f_shutdown_helper();
Harald Welte85804d42017-12-10 14:11:58 +01001884}
1885
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01001886/* Verify T(iar) triggers and releases the channel */
1887testcase TC_chan_rel_sccp_tiar_timeout() runs on test_CT {
1888 var DchanTuple dt;
1889
1890 /* Set T(iar) in BSC low enough that it will trigger before other side
1891 has time to keep alive with a T(ias). Keep recommended ratio of
1892 T(iar) >= T(ias)*2 */
1893 g_bsc_sccp_timer_ias := 2;
1894 g_bsc_sccp_timer_iar := 5;
1895
1896 f_init(1);
1897
1898 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1899 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001900 f_shutdown_helper();
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01001901}
1902
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001903private function f_tc_chan_rel_rr_cause(myBSSMAP_Cause clear_cmd_cause, template RR_Cause expect_rr_cause)
1904runs on test_CT
1905{
1906 var DchanTuple dt;
1907
1908 dt := f_est_dchan('23'O, 23, '00010203040506'O);
1909 var BssmapCause cause := 0;
1910 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(enum2int(clear_cmd_cause))));
1911 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
1912 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
1913 }
1914
1915 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, expect_rr_cause := expect_rr_cause);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001916 f_shutdown_helper();
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02001917}
1918
1919/* Test that Clear Command cause codes affect the RR Channel Release cause code */
1920testcase TC_chan_rel_rr_cause() runs on test_CT {
1921 f_init(1);
1922
1923 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_CALL_CONTROL, GSM48_RR_CAUSE_NORMAL);
1924 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_HANDOVER_SUCCESSFUL, GSM48_RR_CAUSE_NORMAL);
1925 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_PREEMPTION, GSM48_RR_CAUSE_PREMPTIVE_REL);
1926 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE, GSM48_RR_CAUSE_PROT_ERROR_UNSPC);
1927 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
1928 f_tc_chan_rel_rr_cause(GSM0808_CAUSE_EQUIPMENT_FAILURE, GSM48_RR_CAUSE_ABNORMAL_UNSPEC);
1929}
1930
Harald Welte5cd20ed2017-12-13 21:03:20 +01001931/* Test behavior if RSL EST IND for non-active channel */
1932testcase TC_rll_est_ind_inact_lchan() runs on test_CT {
1933 timer T := 2.0;
1934
Harald Welte89d42e82017-12-17 16:42:41 +01001935 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001936
1937 var octetstring l3 := '00010203040506'O;
1938 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
1939 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3));
1940
1941 T.start;
1942 alt {
1943 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1944 setverdict(fail, "MSC received COMPL L3 for non-active lchan");
1945 }
1946 [] BSSAP.receive {}
1947 [] IPA_RSL[0].receive {}
1948 [] T.timeout {}
1949 }
1950
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001951 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01001952}
1953
1954/* Test behavior if RSL EST IND for invalid SAPI */
1955testcase TC_rll_est_ind_inval_sapi1() runs on test_CT {
1956 var RslChannelNr chan_nr;
1957
Harald Welte89d42e82017-12-17 16:42:41 +01001958 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001959
1960 chan_nr := f_chreq_act_ack()
1961
1962 var octetstring l3 := '00010203040506'O;
1963 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(1)), l3));
1964
1965 timer T := 2.0;
1966 T.start;
1967 alt {
1968 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1969 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 1");
1970 }
1971 [] BSSAP.receive { repeat; }
1972 [] IPA_RSL[0].receive { repeat; }
1973 [] T.timeout {}
1974 }
1975
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02001976 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01001977}
1978
1979/* Test behavior if RSL EST IND for invalid SAPI */
1980testcase TC_rll_est_ind_inval_sapi3() runs on test_CT {
1981 timer T := 2.0;
1982
Harald Welte89d42e82017-12-17 16:42:41 +01001983 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01001984
1985 var RslChannelNr chan_nr := f_chreq_act_ack();
1986
1987 var octetstring l3 := '00010203040506'O;
1988 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(3)), l3));
1989
1990 T.start;
1991 alt {
1992 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
1993 setverdict(fail, "MSC received COMPL L3 for invalid SAPI 3");
1994 }
1995 [] BSSAP.receive { repeat; }
1996 [] IPA_RSL[0].receive { repeat; }
1997 [] T.timeout {}
1998 }
1999
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002000 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002001}
2002
2003/* Test behavior if RSL EST IND for invalid SACCH */
2004testcase TC_rll_est_ind_inval_sacch() runs on test_CT {
2005 timer T := 2.0;
2006
Harald Welte89d42e82017-12-17 16:42:41 +01002007 f_init(1);
Harald Welte5cd20ed2017-12-13 21:03:20 +01002008
2009 var RslChannelNr chan_nr := f_chreq_act_ack();
2010
2011 var octetstring l3 := '00010203040506'O;
2012 f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_SACCH(0)), l3));
2013
2014 T.start;
2015 alt {
2016 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) {
2017 setverdict(fail, "MSC received COMPL L3 for invalid Link SACCH");
2018 }
2019 [] BSSAP.receive { repeat; }
2020 [] IPA_RSL[0].receive { repeat; }
2021 [] T.timeout {}
2022 }
2023
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002024 f_shutdown_helper();
Harald Welte5cd20ed2017-12-13 21:03:20 +01002025}
2026
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002027private function f_exp_sapi_n_reject(template (present) GsmSapi sapi := ?,
2028 template myBSSMAP_Cause cause := ?,
2029 float T_val := 2.0)
2030runs on test_CT {
2031 var BSSAP_N_DATA_ind rx_di;
2032 timer T;
2033
2034 var template BSSMAP_IE_Cause tr_cause := tr_BSSMAP_IE_Cause(cause);
2035 var template PDU_BSSAP tr_pdu := tr_BSSMAP_SAPInReject(sapi);
2036
2037 T.start(T_val);
2038 alt {
2039 [] BSSAP.receive(tr_BSSAP_DATA_ind(?, tr_pdu)) -> value rx_di {
2040 var BSSMAP_IE_Cause rx_cause := rx_di.userData.pdu.bssmap.sAPInReject.cause;
2041 if (not match(rx_cause, tr_cause)) {
2042 setverdict(fail, "Rx unexpected Cause IE: ",
2043 rx_cause, " vs expected ", tr_cause);
2044 }
2045 setverdict(pass);
2046 }
2047 [] BSSAP.receive(BSSAP_N_DATA_ind:?) -> value rx_di {
2048 setverdict(fail, "Rx unexpected BSSAP PDU: ", rx_di);
2049 }
2050 [] T.timeout {
2051 setverdict(fail, "Timeout waiting for BSSMAP SAPI N Reject");
2052 }
2053 }
2054}
2055
2056/* Check if we get SAPI N Reject on receipt of unexpected RLL RELease INDication */
2057testcase TC_rll_rel_ind_sapi_n_reject() runs on test_CT {
2058 var octetstring rnd_data := f_rnd_octstring(16);
2059 var RSL_Message rx_rsl;
2060 var DchanTuple dt;
2061
2062 f_init(1);
2063
2064 /* MS establishes a SAPI=0 link on DCCH */
2065 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2066
2067 /* MSC sends some data on (not yet established) SAPI=3 link */
2068 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2069 /* BSC attempts to establish a SAPI=3 link on DCCH */
2070 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2071
2072 /* MS sends unexpected RELease INDication on SAPI=3 */
2073 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3)));
2074 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2075 f_exp_sapi_n_reject(3, GSM0808_CAUSE_MS_NOT_EQUIPPED);
2076
2077 /* Clean up the connection */
2078 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2079 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2080
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002081 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002082}
2083
2084/* Check if we get SAPI N Reject on receipt of unexpected RLL ERROR INDication */
2085testcase TC_rll_err_ind_sapi_n_reject() runs on test_CT {
2086 var octetstring rnd_data := f_rnd_octstring(16);
2087 var RSL_Message rx_rsl;
2088 var DchanTuple dt;
2089
2090 f_init(1);
2091
2092 /* MS establishes a SAPI=0 link on DCCH */
2093 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2094
2095 /* MSC sends some data on (not yet established) SAPI=3 link */
2096 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2097 /* BSC attempts to establish a SAPI=3 link on DCCH */
2098 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2099
2100 /* BTS sends unexpected ERROR INDication on SAPI=3 */
2101 f_ipa_tx(0, ts_RSL_ERROR_IND(dt.rsl_chan_nr, ts_RslLinkID_DCCH(3), ''O));
2102 /* We expect to receive BSSMAP SAPI N Reject message from the BSC */
2103 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED);
2104
2105 /* Clean up the connection */
2106 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2107 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2108
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002109 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002110}
2111
2112/* Check if we get SAPI N Reject due to a SAPI=3 link establishment timeout */
2113testcase TC_rll_timeout_sapi_n_reject() runs on test_CT {
2114 var octetstring rnd_data := f_rnd_octstring(16);
2115 var RSL_Message rx_rsl;
2116 var DchanTuple dt;
2117
2118 f_init(1);
2119
2120 /* MS establishes a SAPI=0 link on DCCH */
2121 dt := f_est_dchan(f_rnd_ra_cs(), 23, rnd_data);
2122
2123 /* MSC sends some data on (not yet established) SAPI=3 link */
2124 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSAP_DTAP(rnd_data, '03'O)));
2125 /* BSC attempts to establish a SAPI=3 link on DCCH */
2126 rx_rsl := f_exp_ipa_rx(0, tr_RSL_EST_REQ(dt.rsl_chan_nr, tr_RslLinkID_DCCH(3)));
2127
2128 /* MS does not respond, so the link establishment timeout triggers SAPI N Reject */
2129 f_exp_sapi_n_reject(3, GSM0808_CAUSE_BSS_NOT_EQUIPPED, T_val := 8.0);
2130
2131 /* Clean up the connection */
2132 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2133 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false);
2134
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002135 f_shutdown_helper();
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07002136}
2137
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002138testcase TC_si_default() runs on test_CT {
2139 f_init(0);
2140 f_init_bts_and_check_sysinfo(0, expect_si := SystemInformationConfig_default);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002141 f_shutdown_helper();
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02002142}
Harald Welte4003d112017-12-09 22:35:39 +01002143
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002144/* We're testing SI2quater with lists of EARFCNs. Instead of just incrementing EARFCNs, also pick some from the edges of
2145 * the entire value range. This function provides the same EARFCN numbers for the same earfcn_index */
2146private function f_test_si2quater_earfcn_by_idx(integer earfcn_index) return uint16_t
2147{
2148 select (earfcn_index) {
2149 case (0) {
2150 /* E-ARFCN 111 is already added in the osmo-bsc.cfg */
2151 return 111;
2152 }
2153 case (1) {
2154 return 1;
2155 }
2156 case (2) {
2157 return 0;
2158 }
2159 case (3) {
2160 return 65535;
2161 }
2162 case else {
2163 return 23 * (earfcn_index - 3);
2164 }
2165 }
2166}
2167
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002168function f_test_si2quater(integer total_earfcns, template SystemInformationConfig expect_si,
2169 template CellSelIndValue expect_cells := omit) runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002170
2171 f_init(0);
2172
2173 /* E-ARFCN 111 is already added in the osmo-bsc.cfg, so only add more arfcns if total_earfcns > 1 */
2174 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002175 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2176 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002177 }
2178
2179 f_init_bts_and_check_sysinfo(0, expect_si := expect_si);
2180
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002181 f_init(1);
2182
2183 if (not istemplatekind(expect_cells, "omit")) {
2184 /* Also check that RR Channel Release contains these EARFCNs.
2185 * (copied code from TC_chan_rel_hard_clear_csfb) */
2186 var BSSAP_N_DATA_ind rx_di;
2187 var DchanTuple dt;
2188
2189 dt := f_est_dchan('23'O, 23, '00010203040506'O);
2190
2191 /* Instruct BSC to clear channel */
2192 var BssmapCause cause := 0;
2193 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommandCSFB(cause)));
2194
2195 /* expect Clear Complete from BSC on A */
2196 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearComplete)) {
2197 /* release the SCCP connection */
2198 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
2199 }
2200
2201 f_expect_chan_rel(0, dt.rsl_chan_nr, expect_rll_rel_req := false, is_csfb := true,
2202 csfb_expect_cells := expect_cells);
2203 }
2204
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002205 for (var integer i := 1; i < total_earfcns; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002206 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 +02002207 }
2208}
2209
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002210private function f_tr_si2quater_earfcns(integer count) return template SI2quaterRestOctetsList
2211{
2212 var template SI2quaterRestOctetsList si2quater := {};
2213 var integer si2quater_count := (count + 2) / 3;
2214
2215 for (var integer i := 0; i < count; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002216 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002217 var integer index := i / 3;
2218 var integer earfcn_index := i mod 3;
2219 if (index >= lengthof(si2quater)) {
2220 si2quater[index] := tr_SI2quaterRestOctets_EUTRAN(index := index, count := si2quater_count - 1);
2221 }
2222 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);
2223 }
2224
2225 return si2quater;
2226}
2227
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002228private function f_tr_rr_chan_rel_earfcns(integer count) return template CellSelIndValue
2229{
2230 var template CellSelIndValue_EUTRAN_Descrs cells := {};
2231
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002232 /* the lte neighbors must match the config & vty to pass this test */
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002233 for (var integer i := 0; i < count; i := i + 1) {
2234 var integer earfcn := f_test_si2quater_earfcn_by_idx(i);
Alexander Couzensf74b5cb2020-09-10 22:28:40 +02002235 cells[i] := tr_CellSelIndValue_EUTRAN_Descr(earfcn, '1'B, 3);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002236 }
2237
2238 return tr_CellSelIndValue_EUTRAN(cells);
2239}
2240
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002241private function f_tc_si2quater_n_earfcns(integer n) runs on test_CT
2242{
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002243 var template SystemInformationConfig sic := SystemInformationConfig_default;
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002244 sic.si2quater := f_tr_si2quater_earfcns(n);
Neels Hofmeyr0edf4ac2020-07-10 17:33:24 +02002245 var template CellSelIndValue cells := f_tr_rr_chan_rel_earfcns(n);
2246 f_test_si2quater(n, sic, cells);
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002247}
2248
2249testcase TC_si2quater_2_earfcns() runs on test_CT {
2250 f_tc_si2quater_n_earfcns(2);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002251 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002252}
2253
2254testcase TC_si2quater_3_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002255 f_tc_si2quater_n_earfcns(3);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002256 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002257}
2258
2259testcase TC_si2quater_4_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002260 f_tc_si2quater_n_earfcns(4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002261 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002262}
2263
2264testcase TC_si2quater_5_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002265 f_tc_si2quater_n_earfcns(5);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002266 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002267}
2268
2269testcase TC_si2quater_6_earfcns() runs on test_CT {
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002270 f_tc_si2quater_n_earfcns(6);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002271 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002272}
2273
2274testcase TC_si2quater_12_earfcns() runs on test_CT {
2275 f_tc_si2quater_n_earfcns(12);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002276 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002277}
2278
2279testcase TC_si2quater_23_earfcns() runs on test_CT {
2280 f_tc_si2quater_n_earfcns(23);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002281 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002282}
2283
2284testcase TC_si2quater_32_earfcns() runs on test_CT {
2285 f_tc_si2quater_n_earfcns(32);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002286 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002287}
2288
2289testcase TC_si2quater_33_earfcns() runs on test_CT {
2290 f_tc_si2quater_n_earfcns(33);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002291 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002292}
2293
2294testcase TC_si2quater_42_earfcns() runs on test_CT {
2295 f_tc_si2quater_n_earfcns(42);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002296 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002297}
2298
2299testcase TC_si2quater_48_earfcns() runs on test_CT {
2300 f_tc_si2quater_n_earfcns(48);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002301 f_shutdown_helper();
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002302}
2303
2304/* verify the VTY error response when adding too many EARFCNs, and showing that osmo-bsc still sends 16 SI2quater with
2305 * 48 EARFCNs. */
2306testcase TC_si2quater_49_earfcns() runs on test_CT {
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002307 var template SystemInformationConfig sic := SystemInformationConfig_default;
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002308 sic.si2quater := f_tr_si2quater_earfcns(48); /* 48, not 49! */
2309 f_init(0);
2310
2311 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002312 f_bts_0_cfg(BSCVTY, {"si2quater neighbor-list add earfcn " & int2str(f_test_si2quater_earfcn_by_idx(i))
2313 & " thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3"});
Neels Hofmeyrad132f22020-07-08 02:20:16 +02002314 }
2315
2316 /* The 49th EARFCN no longer fits, expect VTY error */
2317 f_vty_enter_cfg_bts(BSCVTY, 0);
2318 var charstring vty_error;
2319 vty_error := f_vty_transceive_ret(BSCVTY,
2320 "si2quater neighbor-list add earfcn 70 thresh-hi 20 thresh-lo 10 prio 3 qrxlv 22 meas 3")
2321 f_vty_transceive(BSCVTY, "end");
2322
2323 if (f_strstr(vty_error, "Unable to add ARFCN 70") >= 0) {
2324 log("Got expected VTY error: ", vty_error);
2325 setverdict(pass);
2326 } else {
2327 setverdict(fail, "Expected the 49th EUTRAN ARFCN to be rejected by vty config, got: ", vty_error);
2328 }
2329
2330 f_init_bts_and_check_sysinfo(0, expect_si := sic);
2331
2332 for (var integer i := 1; i < 48; i := i + 1) {
Neels Hofmeyr56f24782020-07-09 00:50:49 +02002333 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 +02002334 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002335 f_shutdown_helper();
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002336}
2337
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002338private function f_acc09_count_allowed(AccessControlClass acc) return uint8_t
2339{
2340 var uint8_t count := 0;
2341 for (var integer i := 5; i < 16; i := i + 1) {
2342 if (acc[i] == '0'B) { /* the list marks barred, we count allowed */
2343 count := count + 1;
2344 }
2345 }
2346 return count;
2347}
2348
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002349private function f_recv_next_si1(integer rsl_idx := 0) runs on test_CT return SystemInformationType1
2350{
2351 var ASP_RSL_Unitdata rx_rsl_ud;
2352 var SystemInformationType1 last_si1;
2353
2354 timer T := 30.0;
2355 T.start;
2356 alt {
2357 [] IPA_RSL[rsl_idx].receive(tr_ASP_RSL_UD((tr_RSL_NO_BCCH_INFO,
2358 tr_RSL_BCCH_INFO,
2359 tr_RSL_NO_SACCH_FILL,
2360 tr_RSL_SACCH_FILL))
2361 ) -> value rx_rsl_ud {
2362 f_sysinfo_seen(rsl_idx, rx_rsl_ud.rsl);
2363 if (g_system_information[rsl_idx].si1 == omit) {
2364 repeat;
2365 }
2366 last_si1 := g_system_information[rsl_idx].si1;
2367 g_system_information[rsl_idx].si1 := omit;
2368 T.stop;
2369 }
2370 [] T.timeout { setverdict(fail, "Timeout receiving next SI1"); }
2371 }
2372 return last_si1;
2373}
2374
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002375/* verify ACC rotate feature */
2376testcase TC_si_acc_rotate() runs on test_CT {
2377 var template SystemInformationConfig sic := SystemInformationConfig_default;
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002378 var SystemInformationType1 last_si1;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002379 var AccessControlClass acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002380 var uint8_t count;
2381 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2382
2383 f_init(0, guard_timeout := 60.0);
2384
2385 f_bts_0_cfg(BSCVTY, {"rach access-control-class 5 barred",
2386 "access-control-class-rotate 3",
2387 "access-control-class-rotate-quantum 1"});
2388
2389 /* Init and get first sysinfo */
2390 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2391
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002392 for (var integer i:= 0; i < 20; i := i + 1) {
2393 last_si1 := f_recv_next_si1(0);
2394 acc := last_si1.rach_control.acc;
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002395 count := f_acc09_count_allowed(acc);
2396 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2397
2398 if (count != 3) {
2399 log("RSL: EXPECTED SI ACC len=3");
2400 setverdict(fail, "received SI does not match expectations");
2401 break;
2402 }
2403
2404 for (var integer j := 0; j < 10; j := j + 1) {
2405 if (acc[16 - 1 - j] == '0'B) { /* the list marks barred, we count allowed */
2406 times_allowed[j] := times_allowed[j] + 1;
2407 }
2408 }
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002409 }
2410
2411 for (var integer j := 0; j < 10; j := j + 1) {
2412 log("ACC", j, " allowed ", times_allowed[j], " times" );
2413 if (j != 5 and times_allowed[j] < 3) {
2414 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " < 1 times");
2415 } else if (j == 5 and times_allowed[j] > 0) {
2416 setverdict(fail, "ACC", j, " ERROR: allowed ", times_allowed[j], " > 0 times");
2417 }
2418 }
2419
2420 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2421 "rach access-control-class 5 allowed"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002422 f_shutdown_helper();
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02002423}
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02002424
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002425/* verify ACC startup ramp+rotate feature */
2426testcase TC_si_acc_ramp_rotate() runs on test_CT {
2427 var template SystemInformationConfig sic := SystemInformationConfig_default;
2428 var SystemInformationType1 last_si1;
2429 var AccessControlClass acc;
2430 var ASP_RSL_Unitdata rx_rsl_ud;
2431 var uint8_t count;
2432 var uint8_t prev_count;
2433 var integer times_allowed[10] := { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2434
2435 f_init(0, guard_timeout := 80.0);
2436
2437 f_bts_0_cfg(BSCVTY, {"rach access-control-class 4 barred",
2438 "access-control-class-rotate 0",
2439 "access-control-class-rotate-quantum 1",
2440 "access-control-class-ramping",
2441 "access-control-class-ramping-step-interval 5",
2442 "access-control-class-ramping-step-size 5"});
2443
2444 /* Init and get first sysinfo */
2445 f_init_bts_and_check_sysinfo(0, expect_si := ?);
2446 last_si1 := g_system_information[0].si1;
2447 acc := last_si1.rach_control.acc;
2448 count := f_acc09_count_allowed(acc);
2449 /* Adm subset size was set to 0 above, so wait until all ACC are barred */
2450 while (count > 0) {
2451 last_si1 := f_recv_next_si1(0);
2452 acc := last_si1.rach_control.acc;
2453 count := f_acc09_count_allowed(acc);
2454 log("RSL: wait len()=0: GOT SI1 ACC len=", count, ": ", acc);
2455 }
2456
2457 /* Increase adm subset size, we should see ramping start up */
2458 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10"});
2459 prev_count := 0;
2460 while (true) {
2461 last_si1 := f_recv_next_si1(0);
2462 acc := last_si1.rach_control.acc;
2463 count := f_acc09_count_allowed(acc);
2464 log("RSL: GOT SI1 ACC len=", count, ": ", acc);
2465
2466 if (prev_count > count) {
2467 setverdict(fail, "ACC allowed count dropped while expecting grow: ", prev_count, " -> ", count);
2468 break;
2469 }
2470
2471 if (count == 9) {
2472 break; /* Maximum reached (10 - 1 perm barred), done here */
2473 }
2474
2475 prev_count := count;
2476 }
2477
2478 setverdict(pass);
2479
2480 f_bts_0_cfg(BSCVTY, {"access-control-class-rotate 10",
2481 "rach access-control-class 4 allowed",
2482 "no access-control-class-ramping"});
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002483 f_shutdown_helper();
Pau Espin Pedrolc6136cd2020-07-24 13:20:02 +02002484}
2485
Harald Welte4003d112017-12-09 22:35:39 +01002486testcase TC_ctrl_msc_connection_status() runs on test_CT {
2487 var charstring ctrl_resp;
2488
Harald Welte89d42e82017-12-17 16:42:41 +01002489 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002490
2491 /* See https://osmocom.org/issues/2729 */
2492 f_ctrl_get_exp(IPA_CTRL, "msc_connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002493 f_shutdown_helper();
Harald Welte4003d112017-12-09 22:35:39 +01002494}
2495
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002496testcase TC_ctrl_msc0_connection_status() runs on test_CT {
2497 var charstring ctrl_resp;
2498
2499 f_init(1);
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002500
2501 f_ctrl_get_exp(IPA_CTRL, "msc.0.connection_status", "connected");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002502 f_shutdown_helper();
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01002503}
2504
Harald Welte4003d112017-12-09 22:35:39 +01002505testcase TC_ctrl() runs on test_CT {
2506 var charstring ctrl_resp;
2507
Harald Welte89d42e82017-12-17 16:42:41 +01002508 f_init(1);
Harald Welte4003d112017-12-09 22:35:39 +01002509
2510 /* all below values must match the osmo-bsc.cfg config file used */
2511
Harald Welte6a129692018-03-17 17:30:14 +01002512 f_ctrl_get_exp(IPA_CTRL, "mcc", "001");
2513 f_ctrl_get_exp(IPA_CTRL, "mnc", "01");
Oliver Smith75aa0202019-08-19 14:17:50 +02002514 f_ctrl_get_exp(IPA_CTRL, "number-of-bts", "4");
Harald Welte4003d112017-12-09 22:35:39 +01002515
2516 var integer bts_nr := 0;
2517 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "location-area-code", "1");
2518 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "cell-identity", "0");
2519 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "oml-connection-state", "connected");
2520 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "gprs-mode", "gprs");
2521 f_ctrl_get_exp_bts(IPA_CTRL, bts_nr, "rf_state", "operational,unlocked,on");
2522 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "arfcn", "871");
2523 f_ctrl_get_exp_trx(IPA_CTRL, bts_nr, 0, "max-power-reduction", "20");
2524
2525 var integer uptime := str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime"));
2526 f_sleep(2.0);
2527 if (str2int(f_ctrl_get_bts(IPA_CTRL, bts_nr, "oml-uptime")) < uptime+1) {
2528 setverdict(fail, "oml-uptime not incrementing as expected");
2529 }
2530 /* TODO: Disconnect RSL, imply that OML is disconnected and check for uptime zero? */
2531
2532 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", 0);
2533
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002534 f_shutdown_helper();
Harald Welte96c94412017-12-09 03:12:45 +01002535}
2536
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02002537/* Verify that Upon receival of SET "location", BSC forwards a TRAP
2538 "location-state" over the SCCPlite IPA conn */
2539testcase TC_ctrl_location() runs on test_CT {
2540 var MSC_ConnHdlr vc_conn;
2541 var integer bts_nr := 0;
2542
2543 f_init(1, true);
2544 f_sleep(1.0);
2545
2546 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234567,fix3d,0.340000,0.560000,0.780000");
2547 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
2548 "1234567,fix3d,0.340000,0.560000,0.780000,operational,unlocked,on,001,01");
2549
2550 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "1");
2551 f_sleep(2.0);
2552
2553 f_ctrl_set_bts(IPA_CTRL, bts_nr, "location", "1234888,fix3d,0.350000,0.570000,0.790000");
2554 f_ctrl_exp_trap(SCCPLITE_IPA_CTRL, "bts." & int2str(bts_nr) & ".location-state",
2555 "1234888,fix3d,0.350000,0.570000,0.790000,operational,locked,off,001,01");
2556
2557 /* should match the one from config */
2558 f_ctrl_set(SCCPLITE_IPA_CTRL, "rf_locked", "0");
2559
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002560 f_shutdown_helper();
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02002561}
2562
Harald Welte6f521d82017-12-11 19:52:02 +01002563
2564/***********************************************************************
2565 * Paging Testing
2566 ***********************************************************************/
2567
2568type record Cell_Identity {
2569 GsmMcc mcc,
2570 GsmMnc mnc,
2571 GsmLac lac,
2572 GsmCellId ci
2573};
Harald Welte24135bd2018-03-17 19:27:53 +01002574private const Cell_Identity cid := { '001'H, '01'H, 1, 0 };
Stefan Sperling049a86e2018-03-20 15:51:00 +01002575private const Cell_Identity unknown_cid := { '678'H, 'f90'H, 1, 0 };
Harald Welte6f521d82017-12-11 19:52:02 +01002576
Harald Welte5d1a2202017-12-13 19:51:29 +01002577type set of integer BtsIdList;
2578
2579private function f_bts_in_list(integer bts_id, BtsIdList bts_ids) return boolean {
2580 for (var integer j := 0; j < sizeof(bts_ids); j := j + 1) {
2581 if (bts_id == bts_ids[j]) {
2582 return true;
2583 }
2584 }
2585 return false;
2586}
Harald Welte6f521d82017-12-11 19:52:02 +01002587
2588/* core paging test helper function; used by most paging test cases */
2589private function f_pageing_helper(hexstring imsi,
2590 template BSSMAP_FIELD_CellIdentificationList cid_list,
Harald Welte5d1a2202017-12-13 19:51:29 +01002591 BtsIdList bts_ids := { 0 },
Harald Welte6f521d82017-12-11 19:52:02 +01002592 template RSL_ChanNeeded rsl_chneed := omit,
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002593 template (omit) OCT4 tmsi := omit) runs on test_CT
Harald Welte6f521d82017-12-11 19:52:02 +01002594{
2595 var template BSSMAP_IE_ChannelNeeded bssmap_chneed;
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002596 var template MobileIdentityV mi;
Harald Welte6f521d82017-12-11 19:52:02 +01002597 var RSL_Message rx_rsl;
2598 var integer paging_group := hex2int(imsi[lengthof(imsi)-1]);
Harald Welte5d1a2202017-12-13 19:51:29 +01002599 var integer i;
Harald Welte6f521d82017-12-11 19:52:02 +01002600
2601 f_init();
Harald Welte6f521d82017-12-11 19:52:02 +01002602
2603 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Harald Weltec3068592018-03-17 19:55:31 +01002604 for (i := 0; i < NUM_BTS; i := i + 1) {
2605 IPA_RSL[i].clear;
Harald Welte5d1a2202017-12-13 19:51:29 +01002606 }
Harald Welte6f521d82017-12-11 19:52:02 +01002607
2608 if (isvalue(rsl_chneed)) {
2609 /* The values of 08.08 3.2.2.36 and 08.58 9.3.40 are luckily identical */
2610 bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
2611 } else {
2612 bssmap_chneed := omit;
2613 }
2614
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002615 BSSAP.send(ts_BSSAP_UNITDATA_req(g_bssap[0].sccp_addr_peer, g_bssap[0].sccp_addr_own,
2616 ts_BSSMAP_Paging(imsi, cid_list, tmsi, bssmap_chneed)));
Harald Welte6f521d82017-12-11 19:52:02 +01002617
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002618 if (not istemplatekind(tmsi, "omit")) {
2619 mi := t_MI_TMSI(tmsi);
Harald Welte6f521d82017-12-11 19:52:02 +01002620 } else {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002621 mi := tr_MI_IMSI(imsi);
Harald Welte6f521d82017-12-11 19:52:02 +01002622 }
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002623
Harald Welte5d1a2202017-12-13 19:51:29 +01002624 for (i := 0; i < sizeof(bts_ids); i := i + 1) {
Vadim Yanitskiycc4623d2020-03-28 06:14:06 +07002625 rx_rsl := f_exp_ipa_rx(bts_ids[i], tr_RSL_PAGING_CMD(mi));
Harald Welte5d1a2202017-12-13 19:51:29 +01002626 /* check channel type, paging group */
2627 if (rx_rsl.ies[1].body.paging_group != paging_group) {
2628 setverdict(fail, "Paging for wrong paging group");
2629 }
2630 if (ispresent(rsl_chneed) and
2631 rx_rsl.ies[3].body.chan_needed.chan_needed != valueof(rsl_chneed)) {
2632 setverdict(fail, "RSL Channel Needed != BSSMAP Channel Needed");
2633 }
Harald Welte6f521d82017-12-11 19:52:02 +01002634 }
Harald Welte2fccd982018-01-31 15:48:19 +01002635 f_sleep(2.0);
Harald Welte5d1a2202017-12-13 19:51:29 +01002636 /* do a quick check on all not-included BTSs if they received paging */
2637 for (i := 0; i < NUM_BTS; i := i + 1) {
2638 timer T := 0.1;
2639 if (f_bts_in_list(i, bts_ids)) {
2640 continue;
2641 }
2642 T.start;
2643 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002644 [] IPA_RSL[i].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(mi))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01002645 setverdict(fail, "Paging on BTS ", i, " which is not part of ", bts_ids);
2646 }
2647 [] IPA_RSL[i].receive { repeat; }
2648 [] T.timeout { }
2649 }
Harald Welte6f521d82017-12-11 19:52:02 +01002650 }
2651
2652 setverdict(pass);
2653}
2654
Harald Welte5d1a2202017-12-13 19:51:29 +01002655const BtsIdList c_BtsId_all := { 0, 1, 2 };
Harald Welte751d3eb2018-01-31 15:51:06 +01002656const BtsIdList c_BtsId_none := { };
Harald Welte5d1a2202017-12-13 19:51:29 +01002657const BtsIdList c_BtsId_LAC1 := { 0, 1 };
2658const BtsIdList c_BtsId_LAC2 := { 2 };
2659
Harald Welte6f521d82017-12-11 19:52:02 +01002660/* PAGING by IMSI + TMSI */
2661testcase TC_paging_imsi_nochan() runs on test_CT {
2662 var BSSMAP_FIELD_CellIdentificationList cid_list;
2663 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Philipp Maier8c04b0a2018-02-23 13:48:48 +01002664 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, omit);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002665 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002666}
2667
2668/* PAGING by IMSI + TMSI */
2669testcase TC_paging_tmsi_nochan() runs on test_CT {
2670 var BSSMAP_FIELD_CellIdentificationList cid_list;
2671 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01002672 f_pageing_helper('001010100000001'H, cid_list, c_BtsId_all, omit, 'A1B2C301'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002673 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002674}
2675
2676/* Paging with different "channel needed' values */
2677testcase TC_paging_tmsi_any() runs on test_CT {
2678 var BSSMAP_FIELD_CellIdentificationList cid_list;
2679 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01002680 f_pageing_helper('001010100000002'H, cid_list, c_BtsId_all, RSL_CHANNEED_ANY, 'A1B2C302'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002681 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002682}
2683testcase TC_paging_tmsi_sdcch() runs on test_CT {
2684 var BSSMAP_FIELD_CellIdentificationList cid_list;
2685 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01002686 f_pageing_helper('001010100000003'H, cid_list, c_BtsId_all, RSL_CHANNEED_SDCCH, 'A1B2C303'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002687 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002688}
2689testcase TC_paging_tmsi_tch_f() runs on test_CT {
2690 var BSSMAP_FIELD_CellIdentificationList cid_list;
2691 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01002692 f_pageing_helper('001010000000004'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_F, 'A1B2C304'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002693 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002694}
2695testcase TC_paging_tmsi_tch_hf() runs on test_CT {
2696 var BSSMAP_FIELD_CellIdentificationList cid_list;
2697 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01002698 f_pageing_helper('001010000000005'H, cid_list, c_BtsId_all, RSL_CHANNEED_TCH_ForH, 'A1B2C305'O);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002699 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002700}
2701
2702/* Paging by CGI */
2703testcase TC_paging_imsi_nochan_cgi() runs on test_CT {
2704 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2705 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(cid.mcc, cid.mnc, cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01002706 f_pageing_helper('001010000000006'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01002707 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002708}
2709
2710/* Paging by LAC+CI */
2711testcase TC_paging_imsi_nochan_lac_ci() runs on test_CT {
2712 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2713 cid_list := { cIl_LAC_CI := { ts_BSSMAP_CI_LAC_CI(cid.lac, cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01002714 f_pageing_helper('001010000000007'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01002715 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002716}
2717
2718/* Paging by CI */
2719testcase TC_paging_imsi_nochan_ci() runs on test_CT {
2720 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2721 cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(cid.ci) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01002722 f_pageing_helper('001010000000008'H, cid_list, { 0 });
Philipp Maier282ca4b2018-02-27 17:17:00 +01002723 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002724}
2725
2726/* Paging by LAI */
2727testcase TC_paging_imsi_nochan_lai() runs on test_CT {
2728 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2729 cid_list := { cIl_LAI := { ts_BSSMAP_CI_LAI(cid.mcc, cid.mnc, cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01002730 f_pageing_helper('001010000000009'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002731 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002732}
2733
2734/* Paging by LAC */
2735testcase TC_paging_imsi_nochan_lac() runs on test_CT {
2736 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2737 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(cid.lac) } };
Harald Welte5d1a2202017-12-13 19:51:29 +01002738 f_pageing_helper('001010000000010'H, cid_list, c_BtsId_LAC1);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002739 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002740}
2741
2742/* Paging by "all in BSS" */
2743testcase TC_paging_imsi_nochan_all() runs on test_CT {
2744 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2745 cid_list := { cIl_allInBSS := ''O };
Harald Welte5d1a2202017-12-13 19:51:29 +01002746 f_pageing_helper('001010000000011'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002747 f_shutdown_helper();
Harald Welte6f521d82017-12-11 19:52:02 +01002748}
2749
Stefan Sperling7b5e1782018-03-20 19:32:43 +01002750/* Paging by PLMN+LAC+RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01002751testcase TC_paging_imsi_nochan_plmn_lac_rnc() runs on test_CT {
2752 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2753 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 +01002754 f_pageing_helper('001010000000012'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002755 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01002756}
Harald Welte6f521d82017-12-11 19:52:02 +01002757
Stefan Sperling7b5e1782018-03-20 19:32:43 +01002758/* Paging by RNC; We do not implement this; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01002759testcase TC_paging_imsi_nochan_rnc() runs on test_CT {
2760 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2761 cid_list := { cIl_RNC := { int2oct(13, 2) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01002762 f_pageing_helper('001010000000013'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002763 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01002764}
2765
Stefan Sperling7b5e1782018-03-20 19:32:43 +01002766/* Paging by LAC+RNC; We do not implement; Verify nothing is paged */
Harald Welte751d3eb2018-01-31 15:51:06 +01002767testcase TC_paging_imsi_nochan_lac_rnc() runs on test_CT {
2768 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2769 cid_list := { cIl_LAC_RNC := { ts_BSSMAP_CI_LAC_RNC(cid.lac, 14) } };
Stefan Sperling7b5e1782018-03-20 19:32:43 +01002770 f_pageing_helper('001010000000014'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002771 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01002772}
2773
Harald Welte6f521d82017-12-11 19:52:02 +01002774/* Paging on multiple cells (multiple entries in list): Verify all of them page */
Harald Welte751d3eb2018-01-31 15:51:06 +01002775testcase TC_paging_imsi_nochan_lacs() runs on test_CT {
2776 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2777 cid_list := { cIl_LAC := { ts_BSSMAP_CI_LAC(1), ts_BSSMAP_CI_LAC(2) } };
2778 f_pageing_helper('001010000000015'H, cid_list, c_BtsId_all);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002779 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01002780}
2781
2782/* Paging on empty list: Verify none of them page */
2783testcase TC_paging_imsi_nochan_lacs_empty() runs on test_CT {
2784 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2785 cid_list := { cIl_LAC := { } };
2786 f_pageing_helper('001010000000016'H, cid_list, c_BtsId_none);
Philipp Maier282ca4b2018-02-27 17:17:00 +01002787 f_shutdown_helper();
Harald Welte751d3eb2018-01-31 15:51:06 +01002788}
2789
Stefan Sperling049a86e2018-03-20 15:51:00 +01002790/* Paging by CGI with unknown MCC/MNC: Verify nothing is paged. */
2791testcase TC_paging_imsi_nochan_cgi_unknown_cid() runs on test_CT {
2792 var template BSSMAP_FIELD_CellIdentificationList cid_list;
2793 cid_list := { cIl_CGI := { ts_BSSMAP_CI_CGI(unknown_cid.mcc, unknown_cid.mnc, unknown_cid.lac, unknown_cid.ci) } };
2794 f_pageing_helper('001010000000006'H, cid_list, c_BtsId_none);
2795 f_shutdown_helper();
2796}
2797
Harald Welte6f521d82017-12-11 19:52:02 +01002798/* Verify paging retransmission interval + count */
2799/* Verify paging stops after channel establishment */
Harald Welte6f521d82017-12-11 19:52:02 +01002800/* Test behavior under paging overload */
Harald Welteae026692017-12-09 01:03:01 +01002801
Harald Weltee65d40e2017-12-13 00:09:06 +01002802/* Verify PCH load */
2803testcase TC_paging_imsi_load() runs on test_CT {
2804 var BSSMAP_FIELD_CellIdentificationList cid_list;
2805 timer T := 4.0;
Harald Welte2caa1062018-03-17 18:19:05 +01002806 timer T_retrans := 1.0;
Harald Weltee65d40e2017-12-13 00:09:06 +01002807 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01002808 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Weltee65d40e2017-12-13 00:09:06 +01002809
2810 /* tell BSC there is no paging space anymore */
2811 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
Harald Welte3b57ab52018-03-17 18:01:10 +01002812 f_sleep(0.2);
2813 IPA_RSL[0].clear;
Harald Weltee65d40e2017-12-13 00:09:06 +01002814
2815 /* Wait for 4 seconds if any more PAGING CMD are received on RSL. Normally,
2816 * there would be 8 retransmissions during 4 seconds */
2817 T.start;
Harald Welte2caa1062018-03-17 18:19:05 +01002818 T_retrans.start;
Harald Weltee65d40e2017-12-13 00:09:06 +01002819 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002820 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Weltee65d40e2017-12-13 00:09:06 +01002821 setverdict(fail, "Received PAGING after LOAD_IND(0)");
Daniel Willmannafce8662018-07-06 23:11:32 +02002822 mtc.stop;
Harald Weltee65d40e2017-12-13 00:09:06 +01002823 }
Harald Welte2caa1062018-03-17 18:19:05 +01002824 [] T_retrans.timeout {
2825 /* re-trnsmit the zero-space LOAD IND to avoid BSC 'auto credit' */
2826 f_ipa_tx(0, ts_RSL_PAGING_LOAD_IND(0));
2827 T_retrans.start;
2828 repeat;
2829 }
Harald Weltee65d40e2017-12-13 00:09:06 +01002830 [] T.timeout {
2831 setverdict(pass);
2832 }
2833 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01002834
2835 f_shutdown_helper();
Harald Weltee65d40e2017-12-13 00:09:06 +01002836}
2837
Harald Welte235ebf12017-12-15 14:18:16 +01002838/* Verify Paging Counter */
Harald Welte1ff69992017-12-14 12:31:17 +01002839testcase TC_paging_counter() runs on test_CT {
2840 var BSSMAP_FIELD_CellIdentificationList cid_list;
2841 timer T := 4.0;
2842 var integer i;
2843 var integer paging_attempted_bsc;
2844 var integer paging_attempted_bts[NUM_BTS];
2845 var integer paging_expired_bts[NUM_BTS];
2846 cid_list := valueof(ts_BSSMAP_CIL_noCell);
2847
2848 f_init();
2849
2850 /* read counters before paging */
2851 paging_attempted_bsc := f_ctrl_get_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted");
2852 for (i := 0; i < NUM_BTS; i := i+1) {
2853 paging_attempted_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted");
2854 paging_expired_bts[i] := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired");
2855 }
2856
2857 f_pageing_helper('001230000000001'H, cid_list, c_BtsId_all);
2858
2859 /* expect the attempted pages on BSC and each BTSs to have incremented by one */
2860 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bsc", 0, "paging:attempted", paging_attempted_bsc+1);
2861 for (i := 0; i < NUM_BTS; i := i+1) {
2862 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:attempted",
2863 paging_attempted_bts[i]+1);
2864 }
2865
2866 /* assume that 12s later the paging on all BTSs have expired and hence incremented by 1 */
2867 f_sleep(12.0);
2868 for (i := 0; i < NUM_BTS; i := i+1) {
2869 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", i, "paging:expired",
2870 paging_expired_bts[i]+1);
2871 }
Harald Welte1ff69992017-12-14 12:31:17 +01002872
Philipp Maier282ca4b2018-02-27 17:17:00 +01002873 f_shutdown_helper();
Harald Welte1ff69992017-12-14 12:31:17 +01002874}
2875
2876
Harald Welte10985002017-12-12 09:29:15 +01002877/* Verify paging stops after A-RESET */
2878testcase TC_paging_imsi_a_reset() runs on test_CT {
2879 var BSSMAP_FIELD_CellIdentificationList cid_list;
2880 timer T := 3.0;
2881 cid_list := valueof(ts_BSSMAP_CIL_noCell);
Harald Welte5d1a2202017-12-13 19:51:29 +01002882 f_pageing_helper('001010123456789'H, cid_list, c_BtsId_all);
Harald Welte10985002017-12-12 09:29:15 +01002883
2884 /* Perform a BSSMAP Reset and wait for ACK */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002885 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 +01002886 alt {
Neels Hofmeyrf246a922020-05-13 02:27:10 +02002887 [] 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 +01002888 [] BSSAP.receive { repeat; }
2889 }
2890
Daniel Willmanncbef3982018-07-30 09:22:40 +02002891 /* Wait to avoid a possible race condition if a paging message is
2892 * received right before the reset ACK. */
2893 f_sleep(0.2);
2894
Harald Welte10985002017-12-12 09:29:15 +01002895 /* Clear the queue, it might still contain stuff like BCCH FILLING */
Philipp Maier1e6b4422018-02-23 14:02:13 +01002896 for (var integer i := 0; i < sizeof(IPA_RSL); i := i+1) {
2897 IPA_RSL[i].clear;
2898 }
Harald Welte10985002017-12-12 09:29:15 +01002899
2900 /* Wait for 3 seconds if any more PAGING CMD are received on RSL */
2901 T.start;
2902 alt {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002903 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte10985002017-12-12 09:29:15 +01002904 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02002905 mtc.stop;
Harald Welte10985002017-12-12 09:29:15 +01002906 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002907 [] IPA_RSL[1].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01002908 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02002909 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01002910 }
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +07002911 [] IPA_RSL[2].receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?))) {
Harald Welte5d1a2202017-12-13 19:51:29 +01002912 setverdict(fail, "Received PAGING after A-RESET");
Daniel Willmannafce8662018-07-06 23:11:32 +02002913 mtc.stop;
Harald Welte5d1a2202017-12-13 19:51:29 +01002914 }
Harald Welte10985002017-12-12 09:29:15 +01002915 [] T.timeout {
2916 setverdict(pass);
2917 }
2918 }
Philipp Maier282ca4b2018-02-27 17:17:00 +01002919
2920 f_shutdown_helper();
Harald Welte10985002017-12-12 09:29:15 +01002921}
Harald Welteae026692017-12-09 01:03:01 +01002922
Philipp Maierf45824a2019-08-14 14:44:10 +02002923/* Verify how we handle unsolicited Paging Response. In case of an unsolicit
2924 * paging response we can not know which MSC is in charge, so we will blindly
2925 * pick the first configured MSC. This behavior is required in order to make
2926 * MT-CSFB calls working because in those cases the BSC can not know that the
2927 * MSC has already paged the subscriver via SGs. So any MT-CSFB call will look
2928 * like an unsolicited Paging Response to the MSC.
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01002929 */
2930testcase TC_paging_resp_unsol() runs on test_CT {
2931
2932 f_init(1);
Philipp Maierf45824a2019-08-14 14:44:10 +02002933 timer T := 5.0;
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01002934
2935 var BSSAP_N_CONNECT_ind rx_c_ind;
2936 var DchanTuple dt;
2937 var PDU_ML3_MS_NW l3 := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010008880018'H))));
Philipp Maierf45824a2019-08-14 14:44:10 +02002938 var octetstring rr_pag_resp := enc_PDU_ML3_MS_NW(l3);
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01002939
2940 /* Send CHAN RQD and wait for allocation; acknowledge it */
2941 dt.rsl_chan_nr := f_chreq_act_ack();
2942
2943 /* Send unsolicited Paging response (no matching Paging CMD stored in BSC) */
2944 f_ipa_tx(0, ts_RSL_EST_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0)), enc_PDU_ML3_MS_NW(l3)));
2945
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01002946
Philipp Maierf45824a2019-08-14 14:44:10 +02002947 /* Expevct a CR with a matching Paging response on the A-Interface */
2948 T.start;
2949 alt {
2950 [] BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(rr_pag_resp))) {
2951 setverdict(pass);
2952 }
2953 [] BSSAP.receive {
2954 setverdict(fail, "Received unexpected message on A-Interface!");
2955 }
2956 [] T.timeout {
2957 setverdict(fail, "Received nothing on A-Interface!");
2958 }
2959 }
2960
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002961 f_shutdown_helper();
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01002962}
2963
Harald Welte4e9b9cc2017-12-14 18:31:02 +01002964/* Test RSL link drop causes counter increment */
2965testcase TC_rsl_drop_counter() runs on test_CT {
2966 var integer rsl_fail;
2967
Harald Welte89d42e82017-12-17 16:42:41 +01002968 f_init(1);
Harald Welte4e9b9cc2017-12-14 18:31:02 +01002969
2970 rsl_fail := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail");
2971
2972 bts[0].rsl.vc_IPA.stop;
2973
2974 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "rsl_fail", rsl_fail+1);
2975
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02002976 f_shutdown_helper();
Harald Welte4e9b9cc2017-12-14 18:31:02 +01002977}
2978
2979/* TODO: Test OML link drop causes counter increment */
2980
Stefan Sperling830dc9d2018-02-12 21:08:28 +01002981/* The body of TC_rsl_unknown_unit_id() and TC_oml_unknown_unit_id() tests. */
2982function f_ipa_unknown_unit_id(integer mp_bsc_ipa_port) runs on test_CT return boolean {
2983 timer T := 10.0;
2984
2985 bts[0].rsl.id := "IPA-0-RSL";
2986 bts[0].rsl.vc_IPA := IPA_Emulation_CT.create(bts[0].rsl.id & "-IPA");
2987 bts[0].rsl.ccm_pars := c_IPA_default_ccm_pars;
2988 bts[0].rsl.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator";
Oliver Smith92c2bdb2019-08-20 15:11:24 +02002989 bts[0].rsl.ccm_pars.unit_id := "99/0/0"; /* value which is unknown at BTS */
Stefan Sperling830dc9d2018-02-12 21:08:28 +01002990
Stefan Sperling830dc9d2018-02-12 21:08:28 +01002991 f_ipa_ctrl_start(mp_bsc_ip, mp_bsc_ctrl_port);
2992
2993 f_init_mgcp("VirtMSC");
2994
2995 /* start RSL/OML connection (XXX re-uses RSL port/protocol definitions for OML) */
2996 map(bts[0].rsl.vc_IPA:IPA_PORT, system:IPA);
2997 connect(bts[0].rsl.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[0]);
2998 bts[0].rsl.vc_IPA.start(IPA_Emulation.main_client(mp_bsc_ip, mp_bsc_ipa_port, "", 10000, bts[0].rsl.ccm_pars));
2999
3000 /* wait for IPA OML link to connect and then disconnect */
3001 T.start;
3002 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +07003003 [] IPA_RSL[0].receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) {
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003004 T.stop;
3005 return true;
3006 }
3007 [] IPA_RSL[0].receive { repeat }
3008 [] T.timeout {
Daniel Willmannafce8662018-07-06 23:11:32 +02003009 return false;
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003010 }
3011 }
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003012 return false;
3013}
3014
3015/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3016testcase TC_rsl_unknown_unit_id() runs on test_CT {
3017 if (f_ipa_unknown_unit_id(mp_bsc_rsl_port)) {
3018 setverdict(pass);
3019 } else {
3020 setverdict(fail, "Timeout RSL waiting for connection to close");
3021 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003022 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003023}
3024
3025
3026/* BSC should close an RSL connection from a BTS with unknown unit ID (OS#2714). */
3027testcase TC_oml_unknown_unit_id() runs on test_CT {
3028 if (f_ipa_unknown_unit_id(mp_bsc_oml_port)) {
3029 setverdict(pass);
3030 } else {
3031 setverdict(fail, "Timeout OML waiting for connection to close");
3032 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003033 f_shutdown_helper();
Stefan Sperling830dc9d2018-02-12 21:08:28 +01003034}
3035
3036
Harald Weltec1a2fff2017-12-17 11:06:19 +01003037/***********************************************************************
Harald Welte6811d102019-04-14 22:23:14 +02003038 * "New world" test cases using RSL_Emulation + RAN_Emulation
Harald Weltec1a2fff2017-12-17 11:06:19 +01003039 ***********************************************************************/
3040
Harald Welte6811d102019-04-14 22:23:14 +02003041import from RAN_Emulation all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01003042import from RSL_Emulation all;
3043import from MSC_ConnectionHandler all;
3044
3045type function void_fn(charstring id) runs on MSC_ConnHdlr;
3046
Harald Welte336820c2018-05-31 20:34:52 +02003047/* helper function to create and connect a MSC_ConnHdlr component */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003048private function f_connect_handler(inout MSC_ConnHdlr vc_conn, integer bssap_idx := 0) runs on test_CT {
3049 connect(vc_conn:RAN, g_bssap[bssap_idx].vc_RAN:PROC);
Daniel Willmann191e0d92018-01-17 12:44:35 +01003050 connect(vc_conn:MGCP_PROC, vc_MGCP:MGCP_PROC);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003051 connect(vc_conn:RSL, bts[0].rsl.vc_RSL:CLIENT_PT);
Harald Weltef70df652018-01-29 22:00:23 +01003052 connect(vc_conn:RSL_PROC, bts[0].rsl.vc_RSL:RSL_PROC);
Philipp Maier88f4ae82018-03-01 14:00:58 +01003053 if (isvalue(bts[1])) {
Philipp Maier956a92f2018-02-16 10:58:07 +01003054 connect(vc_conn:RSL1, bts[1].rsl.vc_RSL:CLIENT_PT);
3055 connect(vc_conn:RSL1_PROC, bts[1].rsl.vc_RSL:RSL_PROC);
3056 }
Neels Hofmeyr91401012019-07-11 00:42:35 +02003057 if (isvalue(bts[2])) {
3058 connect(vc_conn:RSL2, bts[2].rsl.vc_RSL:CLIENT_PT);
3059 connect(vc_conn:RSL2_PROC, bts[2].rsl.vc_RSL:RSL_PROC);
3060 }
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003061 connect(vc_conn:BSSAP, g_bssap[bssap_idx].vc_RAN:CLIENT);
Daniel Willmann191e0d92018-01-17 12:44:35 +01003062 connect(vc_conn:MGCP, vc_MGCP:MGCP_CLIENT);
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02003063 connect(vc_conn:MGCP_MULTI, vc_MGCP:MGCP_CLIENT_MULTI);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003064 connect(vc_conn:STATSD_PROC, vc_STATSD:STATSD_PROC);
Harald Welte336820c2018-05-31 20:34:52 +02003065}
3066
3067function f_start_handler(void_fn fn, template (omit) TestHdlrParams pars := omit)
3068runs on test_CT return MSC_ConnHdlr {
3069 var charstring id := testcasename();
3070 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003071 var integer bssap_idx := 0;
3072 if (isvalue(pars)) {
3073 bssap_idx := valueof(pars).mscpool.bssap_idx;
3074 }
Harald Welte336820c2018-05-31 20:34:52 +02003075 vc_conn := MSC_ConnHdlr.create(id);
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003076 f_connect_handler(vc_conn, bssap_idx);
Harald Weltea0630032018-03-20 21:09:55 +01003077 vc_conn.start(f_handler_init(fn, id, pars));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003078 return vc_conn;
3079}
3080
Harald Weltea0630032018-03-20 21:09:55 +01003081/* first function inside ConnHdlr component; sets g_pars + starts function */
3082private function f_handler_init(void_fn fn, charstring id, template (omit) TestHdlrParams pars := omit)
3083runs on MSC_ConnHdlr {
3084 if (isvalue(pars)) {
3085 g_pars := valueof(pars);
3086 }
3087 fn.apply(id);
3088}
3089
Harald Welte3c86ea02018-05-10 22:28:05 +02003090/* Establish signalling channel (non-assignment case) followed by cipher mode */
3091private function f_tc_ciph_mode_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003092 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3093 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte3c86ea02018-05-10 22:28:05 +02003094 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Philipp Maier23000732018-05-18 11:25:37 +02003095 ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode := omit;
3096 ass_cmd.pdu.bssmap.assignmentRequest.aoIPTransportLayer := omit;
3097 exp_compl.pdu.bssmap.assignmentComplete.circuitIdentityCode := omit;
3098 exp_compl.pdu.bssmap.assignmentComplete.aoIPTransportLayer := omit;
Harald Welte3c86ea02018-05-10 22:28:05 +02003099
Philipp Maier23000732018-05-18 11:25:37 +02003100 f_establish_fully(ass_cmd, exp_compl);
Harald Welte3c86ea02018-05-10 22:28:05 +02003101}
3102testcase TC_ciph_mode_a5_0() runs on test_CT {
3103 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003104 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003105 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
3106
3107 f_init(1, true);
3108 f_sleep(1.0);
3109 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3110 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003111 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003112}
3113testcase TC_ciph_mode_a5_1() runs on test_CT {
3114 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003115 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003116 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
3117
3118 f_init(1, true);
3119 f_sleep(1.0);
3120 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3121 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003122 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003123}
3124testcase TC_ciph_mode_a5_3() runs on test_CT {
3125 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003126 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte3c86ea02018-05-10 22:28:05 +02003127 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
3128
3129 f_init(1, true);
3130 f_sleep(1.0);
3131 vc_conn := f_start_handler(refers(f_tc_ciph_mode_a5), pars);
3132 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003133 f_shutdown_helper();
Harald Welte3c86ea02018-05-10 22:28:05 +02003134}
3135
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003136/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
3137private function f_tc_assignment_aoip_tla_v6(charstring id) runs on MSC_ConnHdlr {
3138 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3139 var PDU_BSSAP ass_cmd := f_gen_ass_req(aoip_tla := "::3");
3140 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3141 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3142
3143 f_establish_fully(ass_cmd, exp_compl);
3144}
3145testcase TC_assignment_aoip_tla_v6() runs on test_CT {
3146 var MSC_ConnHdlr vc_conn;
3147 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3148
3149 f_init(1, true);
3150 f_sleep(1.0);
3151 vc_conn := f_start_handler(refers(f_tc_assignment_aoip_tla_v6), pars);
3152 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003153 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02003154}
3155
Harald Welte3c86ea02018-05-10 22:28:05 +02003156
3157/* establish initial channel, enable ciphering followed by assignment to ciphered channel */
Harald Welte651fcdc2018-05-10 20:23:16 +02003158private function f_tc_assignment_fr_a5(charstring id) runs on MSC_ConnHdlr {
Harald Welteed848512018-05-24 22:27:58 +02003159 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3160 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003161
Harald Welte552620d2017-12-16 23:21:36 +01003162 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3163 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte73cd2712017-12-17 00:44:52 +01003164
Harald Weltea0630032018-03-20 21:09:55 +01003165 f_establish_fully(ass_cmd, exp_compl);
Harald Welte552620d2017-12-16 23:21:36 +01003166}
Harald Welte552620d2017-12-16 23:21:36 +01003167testcase TC_assignment_fr_a5_0() runs on test_CT {
3168 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003169 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003170 pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
Harald Welte552620d2017-12-16 23:21:36 +01003171
Harald Welte89d42e82017-12-17 16:42:41 +01003172 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003173 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003174 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Welte552620d2017-12-16 23:21:36 +01003175 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003176 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003177}
Harald Welte552620d2017-12-16 23:21:36 +01003178testcase TC_assignment_fr_a5_1() runs on test_CT {
Harald Weltec1a2fff2017-12-17 11:06:19 +01003179 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003180 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003181 pars.encr := valueof(t_EncrParams('02'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003182
Harald Welte89d42e82017-12-17 16:42:41 +01003183 f_init(1, true);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003184 f_sleep(1.0);
Harald Welte651fcdc2018-05-10 20:23:16 +02003185 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
3186 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003187 f_shutdown_helper();
Harald Welte651fcdc2018-05-10 20:23:16 +02003188}
3189testcase TC_assignment_fr_a5_3() runs on test_CT {
3190 var MSC_ConnHdlr vc_conn;
Philipp Maier48604732018-10-09 15:00:37 +02003191 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte651fcdc2018-05-10 20:23:16 +02003192 pars.encr := valueof(t_EncrParams('08'O, f_rnd_octstring(8)));
Harald Weltec1a2fff2017-12-17 11:06:19 +01003193
Harald Welte651fcdc2018-05-10 20:23:16 +02003194 f_init(1, true);
3195 f_sleep(1.0);
3196 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
Harald Weltec1a2fff2017-12-17 11:06:19 +01003197 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003198 f_shutdown_helper();
Harald Weltec1a2fff2017-12-17 11:06:19 +01003199}
3200
Harald Welte552620d2017-12-16 23:21:36 +01003201/* Expect ASSIGNMENT FAIL if mandatory IE is missing */
3202private function f_tc_assignment_fr_a5_1_codec_missing(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003203 g_pars := f_gen_test_hdlr_pars();
Harald Welte552620d2017-12-16 23:21:36 +01003204 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
Harald Welteed848512018-05-24 22:27:58 +02003205 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003206 const OCT8 kc := '0001020304050607'O;
3207
3208 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02003209 /* Omit: ass_cmd.pdu.bssmap.assignmentRequest.codecList */
3210
Harald Weltea0630032018-03-20 21:09:55 +01003211 f_establish_fully(ass_cmd, exp_fail);
Harald Welte552620d2017-12-16 23:21:36 +01003212}
Harald Welte552620d2017-12-16 23:21:36 +01003213testcase TC_assignment_fr_a5_1_codec_missing() runs on test_CT {
3214 var MSC_ConnHdlr vc_conn;
3215
Harald Welte89d42e82017-12-17 16:42:41 +01003216 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003217 f_sleep(1.0);
3218
Harald Welte8863fa12018-05-10 20:15:27 +02003219 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_1_codec_missing));
Harald Welte552620d2017-12-16 23:21:36 +01003220 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003221 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003222}
3223
Harald Welte552620d2017-12-16 23:21:36 +01003224private function f_tc_assignment_fr_a5_4(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003225 g_pars := f_gen_test_hdlr_pars();
Harald Welteed848512018-05-24 22:27:58 +02003226 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3227 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte552620d2017-12-16 23:21:36 +01003228 const OCT8 kc := '0001020304050607'O;
3229 const OCT16 kc128 := kc & kc;
3230
3231 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3232 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Weltea0630032018-03-20 21:09:55 +01003233 f_establish_fully(ass_cmd, exp_compl);
Harald Welte38b2a102017-12-23 02:42:58 +01003234 f_cipher_mode('10'O, kc, kc128, true);
Harald Welte552620d2017-12-16 23:21:36 +01003235 /* TODO: expect GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED cause value */
Harald Welte552620d2017-12-16 23:21:36 +01003236}
Harald Welte552620d2017-12-16 23:21:36 +01003237testcase TC_assignment_fr_a5_4() runs on test_CT {
3238 var MSC_ConnHdlr vc_conn;
3239
Harald Welte89d42e82017-12-17 16:42:41 +01003240 f_init(1, true);
Harald Welte552620d2017-12-16 23:21:36 +01003241 f_sleep(1.0);
3242
Harald Welte8863fa12018-05-10 20:15:27 +02003243 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5_4));
Harald Welte552620d2017-12-16 23:21:36 +01003244 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003245 f_shutdown_helper();
Harald Welte552620d2017-12-16 23:21:36 +01003246}
3247
3248
Harald Welte4532e0a2017-12-23 02:05:44 +01003249private function f_tc_assignment_sign(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02003250 g_pars := f_gen_test_hdlr_pars();
Harald Welte4532e0a2017-12-23 02:05:44 +01003251 var template PDU_BSSAP exp_compl := tr_BSSMAP_AssignmentComplete(omit, omit);
Philipp Maier48604732018-10-09 15:00:37 +02003252 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte4532e0a2017-12-23 02:05:44 +01003253 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelTypeSIGNAL);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003254
3255 f_statsd_reset();
Harald Weltea0630032018-03-20 21:09:55 +01003256 f_establish_fully(ass_cmd, exp_compl);
Daniel Willmannebdecc02020-08-12 15:30:17 +02003257
3258 var StatsDExpects expect := {
Daniel Willmannc5398f72020-09-21 10:41:35 +02003259 { name := "TTCN3.bts.0.chreq.total", mtype := "c", min := 1, max := 1},
3260 { name := "TTCN3.bts.0.chreq.successful", mtype := "c", min := 1, max := 1},
Daniel Willmannebdecc02020-08-12 15:30:17 +02003261 { name := "TTCN3.bsc.0.assignment.attempted", mtype := "c", min := 1, max := 1},
3262 { name := "TTCN3.bsc.0.assignment.completed", mtype := "c", min := 1, max := 1}
3263 };
3264 f_statsd_expect(expect);
Harald Welte4532e0a2017-12-23 02:05:44 +01003265}
3266
3267testcase TC_assignment_sign() runs on test_CT {
3268 var MSC_ConnHdlr vc_conn;
3269
3270 f_init(1, true);
3271 f_sleep(1.0);
3272
Harald Welte8863fa12018-05-10 20:15:27 +02003273 vc_conn := f_start_handler(refers(f_tc_assignment_sign));
Harald Welte4532e0a2017-12-23 02:05:44 +01003274 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003275 f_shutdown_helper();
Harald Welte4532e0a2017-12-23 02:05:44 +01003276}
3277
Harald Welte60aa5762018-03-21 19:33:13 +01003278/***********************************************************************
3279 * Codec (list) testing
3280 ***********************************************************************/
3281
3282/* check if the given rsl_mode is compatible with the a_elem */
3283private function f_match_codec(BSSMAP_FIELD_CodecElement a_elem, RSL_IE_ChannelMode rsl_mode)
3284return boolean {
3285 select (a_elem.codecType) {
3286 case (GSM_FR) {
3287 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM1))) {
3288 return true;
3289 }
3290 }
3291 case (GSM_HR) {
3292 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM1))) {
3293 return true;
3294 }
3295 }
3296 case (GSM_EFR) {
3297 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM2))) {
3298 return true;
3299 }
3300 }
3301 case (FR_AMR) {
3302 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_F, RSL_CMOD_SP_GSM3))) {
3303 return true;
3304 }
3305 }
3306 case (HR_AMR) {
3307 if (match(rsl_mode, tr_RSL_ChanMode(RSL_CHRT_TCH_H, RSL_CMOD_SP_GSM3))) {
3308 return true;
3309 }
3310 }
3311 case else { }
3312 }
3313 return false;
3314}
3315
3316/* check if the given rsl_mode is compatible with the a_list */
3317private function f_match_codecs(BSSMAP_IE_SpeechCodecList a_list, RSL_IE_ChannelMode rsl_mode)
3318return boolean {
3319 for (var integer i := 0; i < sizeof(a_list); i := i+1) {
3320 if (f_match_codec(a_list.codecElements[i], rsl_mode)) {
3321 return true;
3322 }
3323 }
3324 return false;
3325}
3326
3327/* determine BSSMAP_IE_ChannelType from *first* element of BSSMAP_FIELD_CodecElement */
Philipp Maier61f6b572018-07-06 14:03:38 +02003328function f_BSSMAP_chtype_from_codec(BSSMAP_FIELD_CodecElement a_elem)
Harald Welte60aa5762018-03-21 19:33:13 +01003329return BSSMAP_IE_ChannelType {
3330 /* FIXME: actually look at all elements of BSSMAP_IE_SpeechCodecList */
3331 var BSSMAP_IE_ChannelType ret := valueof(ts_BSSMAP_IE_ChannelType);
3332 select (a_elem.codecType) {
3333 case (GSM_FR) {
3334 ret.channelRateAndType := ChRate_TCHF;
3335 ret.speechId_DataIndicator := Spdi_TCHF_FR;
3336 }
3337 case (GSM_HR) {
3338 ret.channelRateAndType := ChRate_TCHH;
3339 ret.speechId_DataIndicator := Spdi_TCHH_HR;
3340 }
3341 case (GSM_EFR) {
3342 ret.channelRateAndType := ChRate_TCHF;
3343 ret.speechId_DataIndicator := Spdi_TCHF_EFR;
3344 }
3345 case (FR_AMR) {
3346 ret.channelRateAndType := ChRate_TCHF;
3347 ret.speechId_DataIndicator := Spdi_TCHF_AMR;
3348 }
3349 case (HR_AMR) {
3350 ret.channelRateAndType := ChRate_TCHH;
3351 ret.speechId_DataIndicator := Spdi_TCHH_AMR;
3352 }
3353 case else {
3354 setverdict(fail, "Unsupported codec ", a_elem);
Daniel Willmannafce8662018-07-06 23:11:32 +02003355 mtc.stop;
Harald Welte60aa5762018-03-21 19:33:13 +01003356 }
3357 }
3358 return ret;
3359}
3360
Harald Weltea63b9102018-03-22 20:36:16 +01003361private function f_rsl_chmod_tmpl_from_codec(BSSMAP_FIELD_CodecElement a_elem)
3362return template RSL_IE_Body {
3363 var template RSL_IE_Body mode_ie := {
3364 chan_mode := {
3365 len := ?,
3366 reserved := ?,
3367 dtx_d := ?,
3368 dtx_u := ?,
3369 spd_ind := RSL_SPDI_SPEECH,
3370 ch_rate_type := -,
3371 coding_alg_rate := -
3372 }
3373 }
3374
3375 select (a_elem.codecType) {
3376 case (GSM_FR) {
3377 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
3378 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
3379 }
3380 case (GSM_HR) {
3381 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
3382 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM1;
3383 }
3384 case (GSM_EFR) {
3385 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
3386 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM2;
3387 }
3388 case (FR_AMR) {
3389 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_F;
3390 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
3391 }
3392 case (HR_AMR) {
3393 mode_ie.chan_mode.ch_rate_type := RSL_CHRT_TCH_H;
3394 mode_ie.chan_mode.coding_alg_rate := RSL_CMOD_SP_GSM3;
3395 }
3396 }
3397 return mode_ie;
3398}
3399
Harald Welte60aa5762018-03-21 19:33:13 +01003400type record CodecListTest {
3401 BSSMAP_IE_SpeechCodecList codec_list,
3402 charstring id
3403}
3404type record of CodecListTest CodecListTests
3405
3406private function f_TC_assignment_codec(charstring id) runs on MSC_ConnHdlr {
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02003407 var PDU_BSSAP ass_cmd := f_gen_ass_req(g_pars.use_osmux);
3408 var template PDU_BSSAP exp_compl := f_gen_exp_compl(g_pars.use_osmux);
Harald Welte60aa5762018-03-21 19:33:13 +01003409
3410 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003411 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte79f3f542018-05-25 20:02:37 +02003412 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
3413 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0] :=
3414 g_pars.ass_codec_list.codecElements[0];
Philipp Maierd0e64b02019-03-13 14:15:23 +01003415 if (isvalue(g_pars.expect_mr_s0_s7)) {
3416 exp_compl.pdu.bssmap.assignmentComplete.speechCodec.codecElements[0].s0_7 :=
3417 g_pars.expect_mr_s0_s7;
3418 }
Harald Welte79f3f542018-05-25 20:02:37 +02003419 }
Harald Welte60aa5762018-03-21 19:33:13 +01003420 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
3421 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
Harald Welte60aa5762018-03-21 19:33:13 +01003422 log("expecting ASS COMPL like this: ", exp_compl);
3423
3424 f_establish_fully(ass_cmd, exp_compl);
Harald Weltea63b9102018-03-22 20:36:16 +01003425
3426 /* Verify that the RSL-side activation actually matches our expectations */
3427 var RSL_Message rsl := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
3428
3429 var RSL_IE_Body mode_ie;
3430 if (f_rsl_find_ie(rsl, RSL_IE_CHAN_MODE, mode_ie) == false) {
3431 setverdict(fail, "Couldn't find CHAN_MODE IE");
Daniel Willmannafce8662018-07-06 23:11:32 +02003432 mtc.stop;
Harald Weltea63b9102018-03-22 20:36:16 +01003433 }
3434 var template RSL_IE_Body t_mode_ie := f_rsl_chmod_tmpl_from_codec(g_pars.ass_codec_list.codecElements[0]);
3435 if (not match(mode_ie, t_mode_ie)) {
3436 setverdict(fail, "RSL Channel Mode IE doesn't match expectation");
3437 }
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02003438
3439 var RSL_IE_Body mr_conf;
3440 if (g_pars.expect_mr_conf_ie != omit) {
3441 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == false) {
3442 setverdict(fail, "Missing MR CONFIG IE in RSL Chan Activ");
Daniel Willmannafce8662018-07-06 23:11:32 +02003443 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02003444 }
3445 log("found RSL MR CONFIG IE: ", mr_conf);
3446
3447 if (not match(mr_conf, g_pars.expect_mr_conf_ie)) {
3448 setverdict(fail, "RSL MR CONFIG IE does not match expectation. Expected: ",
3449 g_pars.expect_mr_conf_ie);
3450 }
3451 } else {
3452 if (f_rsl_find_ie(rsl, RSL_IE_MR_CONFIG, mr_conf) == true) {
3453 log("found RSL MR CONFIG IE: ", mr_conf);
3454 setverdict(fail, "Found MR CONFIG IE in RSL Chan Activ, expecting omit");
Daniel Willmannafce8662018-07-06 23:11:32 +02003455 mtc.stop;
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02003456 }
3457 }
Harald Welte60aa5762018-03-21 19:33:13 +01003458}
3459
Philipp Maierd0e64b02019-03-13 14:15:23 +01003460private function f_TC_assignment_codec_fail(charstring id) runs on MSC_ConnHdlr {
3461
3462 var PDU_BSSAP ass_cmd := f_gen_ass_req();
3463 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
3464
3465 /* puzzle together the ASSIGNMENT REQ for given codec[s] */
Neels Hofmeyrf246a922020-05-13 02:27:10 +02003466 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maierd0e64b02019-03-13 14:15:23 +01003467 ass_cmd.pdu.bssmap.assignmentRequest.codecList := g_pars.ass_codec_list;
3468 }
3469 ass_cmd.pdu.bssmap.assignmentRequest.channelType :=
3470 f_BSSMAP_chtype_from_codec(g_pars.ass_codec_list.codecElements[0]);
3471 log("expecting ASS FAIL like this: ", exp_fail);
3472
3473 f_establish_fully(ass_cmd, exp_fail);
3474}
3475
Harald Welte60aa5762018-03-21 19:33:13 +01003476testcase TC_assignment_codec_fr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02003477 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01003478 var MSC_ConnHdlr vc_conn;
3479
3480 f_init(1, true);
3481 f_sleep(1.0);
3482
3483 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02003484 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01003485 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003486 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01003487}
3488
3489testcase TC_assignment_codec_hr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02003490 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01003491 var MSC_ConnHdlr vc_conn;
3492
3493 f_init(1, true);
3494 f_sleep(1.0);
3495
3496 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
Harald Welte8863fa12018-05-10 20:15:27 +02003497 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01003498 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003499 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01003500}
3501
3502testcase TC_assignment_codec_efr() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02003503 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01003504 var MSC_ConnHdlr vc_conn;
3505
3506 f_init(1, true);
3507 f_sleep(1.0);
3508
3509 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecEFR}));
Harald Welte8863fa12018-05-10 20:15:27 +02003510 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01003511 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003512 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01003513}
3514
Philipp Maierd0e64b02019-03-13 14:15:23 +01003515/* Allow 5,90k only (current default config) */
3516private function f_allow_amr_rate_5_90k() runs on test_CT {
3517 f_vty_enter_cfg_msc(BSCVTY, 0);
3518 f_vty_transceive(BSCVTY, "amr-config 12_2k forbidden");
3519 f_vty_transceive(BSCVTY, "amr-config 10_2k forbidden");
3520 f_vty_transceive(BSCVTY, "amr-config 7_95k forbidden");
3521 f_vty_transceive(BSCVTY, "amr-config 7_40k forbidden");
3522 f_vty_transceive(BSCVTY, "amr-config 6_70k forbidden");
3523 f_vty_transceive(BSCVTY, "amr-config 5_90k allowed");
3524 f_vty_transceive(BSCVTY, "amr-config 5_15k forbidden");
3525 f_vty_transceive(BSCVTY, "amr-config 4_75k forbidden");
3526 f_vty_transceive(BSCVTY, "exit");
3527 f_vty_transceive(BSCVTY, "exit");
3528}
3529
3530/* Allow 4,75k, 5,90k, 4,70k and 12,2k, which are the most common rates
3531 * ("Config-NB-Code = 1") */
3532private function f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k() runs on test_CT {
3533 f_vty_enter_cfg_msc(BSCVTY, 0);
3534 f_vty_transceive(BSCVTY, "amr-config 12_2k allowed");
3535 f_vty_transceive(BSCVTY, "amr-config 10_2k forbidden");
3536 f_vty_transceive(BSCVTY, "amr-config 7_95k forbidden");
3537 f_vty_transceive(BSCVTY, "amr-config 7_40k allowed");
3538 f_vty_transceive(BSCVTY, "amr-config 6_70k forbidden");
3539 f_vty_transceive(BSCVTY, "amr-config 5_90k allowed");
3540 f_vty_transceive(BSCVTY, "amr-config 5_15k forbidden");
3541 f_vty_transceive(BSCVTY, "amr-config 4_75k allowed");
3542 f_vty_transceive(BSCVTY, "exit");
3543 f_vty_transceive(BSCVTY, "exit");
3544}
3545
Harald Welte60aa5762018-03-21 19:33:13 +01003546testcase TC_assignment_codec_amr_f() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02003547 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01003548 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02003549
3550 /* Note: This setups the codec configuration. The parameter payload in
3551 * mr_conf must be consistant with the parameter codecElements in pars
3552 * and also must match the amr-config in osmo-bsc.cfg! */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02003553 var RSL_IE_Body mr_conf := {
3554 other := {
3555 len := 2,
3556 payload := '2804'O
3557 }
3558 };
Harald Welte60aa5762018-03-21 19:33:13 +01003559
Philipp Maier7695a0d2018-09-27 17:52:14 +02003560 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
Philipp Maier806f8f12019-03-12 12:13:41 +01003561 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02003562 pars.ass_codec_list.codecElements[0].s8_15 := '01010111'B;
3563 pars.expect_mr_conf_ie := mr_conf;
3564
Harald Welte60aa5762018-03-21 19:33:13 +01003565 f_init(1, true);
3566 f_sleep(1.0);
3567
Harald Welte8863fa12018-05-10 20:15:27 +02003568 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01003569 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003570 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01003571}
3572
3573testcase TC_assignment_codec_amr_h() runs on test_CT {
Philipp Maier48604732018-10-09 15:00:37 +02003574 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Harald Welte60aa5762018-03-21 19:33:13 +01003575 var MSC_ConnHdlr vc_conn;
Philipp Maier7695a0d2018-09-27 17:52:14 +02003576
3577 /* See note above */
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +02003578 var RSL_IE_Body mr_conf := {
3579 other := {
3580 len := 2,
3581 payload := '2804'O
3582 }
3583 };
Harald Welte60aa5762018-03-21 19:33:13 +01003584
Philipp Maier7695a0d2018-09-27 17:52:14 +02003585 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
Philipp Maier806f8f12019-03-12 12:13:41 +01003586 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
Philipp Maier7695a0d2018-09-27 17:52:14 +02003587 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
3588 pars.expect_mr_conf_ie := mr_conf;
3589
Harald Welte60aa5762018-03-21 19:33:13 +01003590 f_init(1, true);
3591 f_sleep(1.0);
3592
Harald Welte8863fa12018-05-10 20:15:27 +02003593 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
Harald Welte60aa5762018-03-21 19:33:13 +01003594 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003595 f_shutdown_helper();
Harald Welte60aa5762018-03-21 19:33:13 +01003596}
3597
Philipp Maierd0e64b02019-03-13 14:15:23 +01003598function f_TC_assignment_codec_amr(boolean fr, octetstring mrconf, bitstring s8_s0, bitstring exp_s8_s0)
3599runs on test_CT {
3600
3601 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3602 var MSC_ConnHdlr vc_conn;
3603
3604 /* See note above */
3605 var RSL_IE_Body mr_conf := {
3606 other := {
3607 len := lengthof(mrconf),
3608 payload := mrconf
3609 }
3610 };
3611
3612 if (fr) {
3613 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
3614 } else {
3615 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
3616 }
3617 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
3618 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
3619 pars.expect_mr_conf_ie := mr_conf;
3620 pars.expect_mr_s0_s7 := exp_s8_s0;
3621
3622 f_init(1, true);
3623 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
3624 f_sleep(1.0);
3625
3626 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
3627 vc_conn.done;
3628 f_allow_amr_rate_5_90k();
3629}
3630
3631function f_TC_assignment_codec_amr_fail(boolean fr, bitstring s8_s0)
3632runs on test_CT {
3633
3634 var TestHdlrParams pars := f_gen_test_hdlr_pars();
3635 var MSC_ConnHdlr vc_conn;
3636
3637 if (fr) {
3638 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_F}));
3639 } else {
3640 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
3641 }
3642 pars.ass_codec_list.codecElements[0].s0_7 := s8_s0;
3643 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
3644
3645 f_init(1, true);
3646 f_allow_amr_rate_4_75k_5_90k_7_40k_12_20k();
3647 f_sleep(1.0);
3648
3649 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fail), pars);
3650 vc_conn.done;
3651 f_allow_amr_rate_5_90k();
3652}
3653
3654
3655/* Set S1, we expect an AMR multirate configuration IE with all four rates
3656 * set. */
3657testcase TC_assignment_codec_amr_f_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02003658 f_TC_assignment_codec_amr(true, '289520882208'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003659 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01003660}
3661
3662/* Set S1, we expect an AMR multirate configuration IE with the lower three
3663 * rates set. */
3664testcase TC_assignment_codec_amr_h_S1() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02003665 f_TC_assignment_codec_amr(false, '2815208820'O, '00000010'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003666 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01003667}
3668
3669/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
3670 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
3671testcase TC_assignment_codec_amr_f_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02003672 f_TC_assignment_codec_amr(true, '289520882208'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003673 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01003674}
3675
3676/* Set S1 and two other rates, we expect an AMR MULTIRATE CONFIGURATION IE with
3677 * all four rates (and only S1 set in the ASSIGNMENT COMPLETE) */
3678testcase TC_assignment_codec_amr_h_S124() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02003679 f_TC_assignment_codec_amr(false, '2815208820'O, '00010110'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003680 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01003681}
3682
3683/* The following block of tests selects more and more rates until all four
3684 * possible rates are in the active set (full rate) */
3685testcase TC_assignment_codec_amr_f_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02003686 f_TC_assignment_codec_amr(true, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003687 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01003688}
3689
3690testcase TC_assignment_codec_amr_f_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02003691 f_TC_assignment_codec_amr(true, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003692 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01003693}
3694
3695testcase TC_assignment_codec_amr_f_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02003696 f_TC_assignment_codec_amr(true, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003697 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01003698}
3699
3700testcase TC_assignment_codec_amr_f_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02003701 f_TC_assignment_codec_amr(true, '289520882208'O, '10010101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003702 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01003703}
3704
3705/* The following block of tests selects more and more rates until all three
3706 * possible rates are in the active set (half rate) */
3707testcase TC_assignment_codec_amr_h_S0() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02003708 f_TC_assignment_codec_amr(false, '2801'O, '00000001'B, '00000001'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003709 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01003710}
3711
3712testcase TC_assignment_codec_amr_h_S02() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02003713 f_TC_assignment_codec_amr(false, '28052080'O, '00000101'B, '00000101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003714 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01003715}
3716
3717testcase TC_assignment_codec_amr_h_S024() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02003718 f_TC_assignment_codec_amr(false, '2815208820'O, '00010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003719 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01003720}
3721
3722/* The following block tests what happens when the MSC does offer rate
3723 * configurations that are not supported by the BSC. Normally such situations
3724 * should not happen because the MSC gets informed by the BSC in advance via
3725 * the L3 COMPLETE message which rates are applicable. The MSC should not try
3726 * to offer rates that are not applicable anyway. */
3727
3728testcase TC_assignment_codec_amr_h_S0247() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02003729 /* Try to include 12,2k in into the active set even though the channel
3730 * is half rate only. The BSC is expected to remove the 12,0k */
3731 f_TC_assignment_codec_amr(false, '2815208820'O, '10010101'B, '00010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003732 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01003733}
3734
3735testcase TC_assignment_codec_amr_f_S01234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02003736 /* See what happens when all rates are selected at once. Since then
3737 * Also S1 is selected, this setting will be prefered and we should
3738 * get 12.2k, 7,40k, 5,90k, and 4,75k in the active set. */
3739 f_TC_assignment_codec_amr(true, '289520882208'O, '11111111'B, '00000010'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003740 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01003741}
3742
3743testcase TC_assignment_codec_amr_f_S0234567() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02003744 /* Same as above, but with S1 missing, the MSC is then expected to
3745 * select the currently supported rates, which are also 12.2k, 7,40k,
3746 * 5,90k, and 4,75k, into the active set. */
3747 f_TC_assignment_codec_amr(true, '289520882208'O, '11111101'B, '10010101'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003748 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01003749}
3750
3751testcase TC_assignment_codec_amr_f_zero() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02003752 /* Try to select no rates at all */
3753 f_TC_assignment_codec_amr_fail(true, '00000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003754 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01003755}
3756
3757testcase TC_assignment_codec_amr_f_unsupp() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02003758 /* Try to select only unsupported rates */
3759 f_TC_assignment_codec_amr_fail(true, '01101000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003760 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01003761}
3762
3763testcase TC_assignment_codec_amr_h_S7() runs on test_CT {
Pau Espin Pedrol00f40e82020-09-23 14:16:04 +02003764 /* Try to select 12,2k for half rate */
3765 f_TC_assignment_codec_amr_fail(false, '10000000'B);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003766 f_shutdown_helper();
Philipp Maierd0e64b02019-03-13 14:15:23 +01003767}
3768
Philipp Maierac09bfc2019-01-08 13:41:39 +01003769private function f_disable_all_tch_f() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01003770 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 borken");
3771 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 borken");
3772 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 borken");
3773 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01003774}
3775
3776private function f_disable_all_tch_h() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01003777 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 borken");
3778 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 borken");
Philipp Maierac09bfc2019-01-08 13:41:39 +01003779}
3780
3781private function f_enable_all_tch() runs on test_CT {
Philipp Maierc704a882019-01-29 15:58:52 +01003782 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 1 sub-slot 0 unused");
3783 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 2 sub-slot 0 unused");
3784 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 3 sub-slot 0 unused");
3785 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 4 sub-slot 0 unused");
3786 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 0 unused");
3787 f_vty_transceive(BSCVTY, "bts 0 trx 0 timeslot 5 sub-slot 1 unused");
Philipp Maierac09bfc2019-01-08 13:41:39 +01003788}
3789
3790/* Allow HR only */
3791private function f_TC_assignment_codec_xr_exhausted_req_hr(charstring id) runs on MSC_ConnHdlr {
3792 g_pars := f_gen_test_hdlr_pars();
3793 var PDU_BSSAP ass_cmd := f_gen_ass_req();
3794 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3795 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3796 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
3797 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
3798 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
3799 f_establish_fully(ass_cmd, exp_compl);
3800}
3801
3802/* Allow FR only */
3803private function f_TC_assignment_codec_xr_exhausted_req_fr(charstring id) runs on MSC_ConnHdlr {
3804 g_pars := f_gen_test_hdlr_pars();
3805 var PDU_BSSAP ass_cmd := f_gen_ass_req();
3806 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3807 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3808 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
3809 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
3810 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3811 f_establish_fully(ass_cmd, exp_compl);
3812}
3813
3814/* Allow HR only (expect assignment failure) */
3815private function f_TC_assignment_codec_xr_exhausted_req_hr_fail(charstring id) runs on MSC_ConnHdlr {
3816 g_pars := f_gen_test_hdlr_pars();
3817 var PDU_BSSAP ass_cmd := f_gen_ass_req();
3818 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
3819 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3820 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '09'O;
3821 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '05'O;
3822 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR}));
3823 f_establish_fully(ass_cmd, exp_fail);
3824}
3825
3826/* Allow FR only (expect assignment failure) */
3827private function f_TC_assignment_codec_xr_exhausted_req_fr_fail(charstring id) runs on MSC_ConnHdlr {
3828 g_pars := f_gen_test_hdlr_pars();
3829 var PDU_BSSAP ass_cmd := f_gen_ass_req();
3830 var template PDU_BSSAP exp_fail := tr_BSSMAP_AssignmentFail;
3831 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3832 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '08'O;
3833 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '01'O;
3834 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
3835 f_establish_fully(ass_cmd, exp_fail);
3836}
3837
3838/* Allow FR and HR, but prefer FR */
3839private function f_TC_assignment_codec_fr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
3840 g_pars := f_gen_test_hdlr_pars();
3841 var PDU_BSSAP ass_cmd := f_gen_ass_req();
3842 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3843 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3844 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
3845 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
3846 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
3847 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
3848 f_establish_fully(ass_cmd, exp_compl);
3849}
3850
3851/* Allow FR and HR, but prefer HR */
3852private function f_TC_assignment_codec_fr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
3853 g_pars := f_gen_test_hdlr_pars();
3854 var PDU_BSSAP ass_cmd := f_gen_ass_req();
3855 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3856 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3857 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
3858 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
3859 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
3860 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
3861 f_establish_fully(ass_cmd, exp_compl);
3862}
3863
3864/* Allow FR and HR, but prefer FR */
3865private function f_TC_assignment_codec_hr_exhausted_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
3866 g_pars := f_gen_test_hdlr_pars();
3867 var PDU_BSSAP ass_cmd := f_gen_ass_req();
3868 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3869 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3870 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
3871 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
3872 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
3873 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
3874 f_establish_fully(ass_cmd, exp_compl);
3875}
3876
3877/* Allow FR and HR, but prefer HR */
3878private function f_TC_assignment_codec_hr_exhausted_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
3879 g_pars := f_gen_test_hdlr_pars();
3880 var PDU_BSSAP ass_cmd := f_gen_ass_req();
3881 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
3882 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
3883 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
3884 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
3885 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
3886 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
3887 f_establish_fully(ass_cmd, exp_compl);
3888}
3889
3890/* Request a HR channel while all FR channels are exhausted, this is expected
3891 * to work without conflicts */
3892testcase TC_assignment_codec_fr_exhausted_req_hr() runs on test_CT {
3893 var MSC_ConnHdlr vc_conn;
3894 f_init(1, true);
3895 f_sleep(1.0);
3896 f_enable_all_tch();
3897 f_disable_all_tch_f();
3898 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr));
3899 vc_conn.done;
3900 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003901 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01003902}
3903
3904/* Request a FR channel while all FR channels are exhausted, this is expected
3905 * to fail. */
3906testcase TC_assignment_codec_fr_exhausted_req_fr() runs on test_CT {
3907 var MSC_ConnHdlr vc_conn;
3908 f_init(1, true);
3909 f_sleep(1.0);
3910 f_enable_all_tch();
3911 f_disable_all_tch_f();
3912 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr_fail));
3913 vc_conn.done;
3914 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003915 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01003916}
3917
3918/* Request a FR (prefered) or alternatively a HR channel while all FR channels
3919 * are exhausted, this is expected to be resolved by selecting a HR channel. */
3920testcase TC_assignment_codec_fr_exhausted_req_fr_hr() runs on test_CT {
3921 var MSC_ConnHdlr vc_conn;
3922 f_init(1, true);
3923 f_sleep(1.0);
3924 f_enable_all_tch();
3925 f_disable_all_tch_f();
3926 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_fr_hr));
3927 vc_conn.done;
3928 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003929 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01003930}
3931
3932/* Request a HR (prefered) or alternatively a FR channel while all FR channels
3933 * are exhausted, this is expected to work without conflicts. */
3934testcase TC_assignment_codec_fr_exhausted_req_hr_fr() runs on test_CT {
3935 var MSC_ConnHdlr vc_conn;
3936 f_init(1, true);
3937 f_sleep(1.0);
3938 f_enable_all_tch();
3939 f_disable_all_tch_f();
3940 vc_conn := f_start_handler(refers(f_TC_assignment_codec_fr_exhausted_req_hr_fr));
3941 vc_conn.done;
3942 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003943 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01003944}
3945
3946/* Request a FR channel while all HR channels are exhausted, this is expected
3947 * to work without conflicts */
3948testcase TC_assignment_codec_hr_exhausted_req_fr() runs on test_CT {
3949 var MSC_ConnHdlr vc_conn;
3950 f_init(1, true);
3951 f_sleep(1.0);
3952 f_enable_all_tch();
3953 f_disable_all_tch_h();
3954 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_fr));
3955 vc_conn.done;
3956 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003957 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01003958}
3959
3960/* Request a HR channel while all HR channels are exhausted, this is expected
3961 * to fail. */
3962testcase TC_assignment_codec_hr_exhausted_req_hr() runs on test_CT {
3963 var MSC_ConnHdlr vc_conn;
3964 f_init(1, true);
3965 f_sleep(1.0);
3966 f_enable_all_tch();
3967 f_disable_all_tch_h();
3968 vc_conn := f_start_handler(refers(f_TC_assignment_codec_xr_exhausted_req_hr_fail));
3969 vc_conn.done;
3970 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003971 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01003972}
3973
3974/* Request a HR (prefered) or alternatively a FR channel while all HR channels
3975 * are exhausted, this is expected to be resolved by selecting a FR channel. */
3976testcase TC_assignment_codec_hr_exhausted_req_hr_fr() runs on test_CT {
3977 var MSC_ConnHdlr vc_conn;
3978 f_init(1, true);
3979 f_sleep(1.0);
3980 f_enable_all_tch();
3981 f_disable_all_tch_h();
3982 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_hr_fr));
3983 vc_conn.done;
3984 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003985 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01003986}
3987
3988/* Request a FR (prefered) or alternatively a HR channel while all HR channels
3989 * are exhausted, this is expected to work without conflicts. */
3990testcase TC_assignment_codec_hr_exhausted_req_fr_hr() runs on test_CT {
3991 var MSC_ConnHdlr vc_conn;
3992 f_init(1, true);
3993 f_sleep(1.0);
3994 f_enable_all_tch();
3995 f_disable_all_tch_h();
3996 vc_conn := f_start_handler(refers(f_TC_assignment_codec_hr_exhausted_req_fr_hr));
3997 vc_conn.done;
3998 f_enable_all_tch();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02003999 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004000}
4001
4002/* Allow FR and HR, but prefer HR */
4003private function f_TC_assignment_codec_req_hr_fr(charstring id) runs on MSC_ConnHdlr {
4004 g_pars := f_gen_test_hdlr_pars();
4005 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4006 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4007 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4008 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0B'O; /* Prefer HR */
4009 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8501'O;
4010 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecHR, ts_CodecFR}));
4011 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000101'B; /* Expect HR */
4012 f_establish_fully(ass_cmd, exp_compl);
4013}
4014
4015/* Allow FR and HR, but prefer FR */
4016private function f_TC_assignment_codec_req_fr_hr(charstring id) runs on MSC_ConnHdlr {
4017 g_pars := f_gen_test_hdlr_pars();
4018 var PDU_BSSAP ass_cmd := f_gen_ass_req();
4019 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4020 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4021 ass_cmd.pdu.bssmap.assignmentRequest.channelType.channelRateAndType := '0A'O; /* Prefer FR */
4022 ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechId_DataIndicator := '8105'O;
4023 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR, ts_CodecHR}));
4024 exp_compl.pdu.bssmap.assignmentComplete.speechVersion.speechVersionIdentifier := '0000001'B; /* Expect FR */
4025 f_establish_fully(ass_cmd, exp_compl);
4026}
4027
4028/* Request a HR (prefered) or alternatively a FR channel, it is expected that
4029 * HR, which is the prefered type, is selected. */
4030testcase TC_assignment_codec_req_hr_fr() runs on test_CT {
4031 var MSC_ConnHdlr vc_conn;
4032 f_init(1, true);
4033 f_sleep(1.0);
4034 f_enable_all_tch();
4035 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_hr_fr));
4036 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004037 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004038}
4039
4040/* Request a FR (prefered) or alternatively a HR channel, it is expected that
4041 * FR, which is the prefered type, is selected. */
4042testcase TC_assignment_codec_req_fr_hr() runs on test_CT {
4043 var MSC_ConnHdlr vc_conn;
4044 f_init(1, true);
4045 f_sleep(1.0);
4046 f_enable_all_tch();
4047 vc_conn := f_start_handler(refers(f_TC_assignment_codec_req_fr_hr));
4048 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004049 f_shutdown_helper();
Philipp Maierac09bfc2019-01-08 13:41:39 +01004050}
4051
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004052testcase TC_assignment_osmux() runs on test_CT {
4053 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4054 var MSC_ConnHdlr vc_conn;
4055
4056 /* See note above */
4057 var RSL_IE_Body mr_conf := {
4058 other := {
4059 len := 2,
4060 payload := '2804'O
4061 }
4062 };
4063
4064 pars.ass_codec_list := valueof(ts_BSSMAP_IE_CodecList({ts_CodecAMR_H}));
4065 pars.ass_codec_list.codecElements[0].s0_7 := '00000100'B; /* 5,90k */
4066 pars.ass_codec_list.codecElements[0].s8_15 := '00000111'B;
4067 pars.expect_mr_conf_ie := mr_conf;
4068 pars.use_osmux := true;
4069
4070 f_init(1, true, true);
4071 f_sleep(1.0);
4072
4073 vc_conn := f_start_handler(refers(f_TC_assignment_codec), pars);
4074 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004075 f_shutdown_helper();
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02004076}
4077
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02004078/* test the procedure of the MSC requesting a Classmark Update:
4079 * a) BSSMAP Classmark Request should result in RR CLASSMARK ENQUIRY,
4080 * b) L3 RR CLASSMARK CHANGE should result in BSSMAP CLASSMARK UPDATE */
Harald Welte898113b2018-01-31 18:32:21 +01004081private function f_tc_classmark(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02004082 g_pars := f_gen_test_hdlr_pars();
4083
Harald Weltea0630032018-03-20 21:09:55 +01004084 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01004085 /* we should now have a COMPL_L3 at the MSC */
4086 BSSAP.receive(tr_BSSMAP_ComplL3);
4087
Neels Hofmeyr92b12b72018-09-18 14:30:23 +02004088 BSSAP.send(ts_BSSMAP_ClassmarkRequest);
4089 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_CM_ENQUIRY));
4090
Harald Welte898113b2018-01-31 18:32:21 +01004091 f_rsl_send_l3(ts_RRM_CM_CHG(valueof(ts_CM2)));
4092 BSSAP.receive(tr_BSSMAP_ClassmarkUpd(?, omit));
4093 setverdict(pass);
4094}
4095testcase TC_classmark() runs on test_CT {
4096 var MSC_ConnHdlr vc_conn;
4097 f_init(1, true);
4098 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02004099 vc_conn := f_start_handler(refers(f_tc_classmark));
Harald Welte898113b2018-01-31 18:32:21 +01004100 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004101 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01004102}
4103
Harald Welteeddf0e92020-06-21 19:42:15 +02004104/* Send a CommonID from the simulated MSC and verify that the information is used to
4105 * fill BSC-internal data structures (specifically, bsc_subscr associated with subscr_conn) */
4106private function f_tc_common_id(charstring id) runs on MSC_ConnHdlr {
4107 g_pars := f_gen_test_hdlr_pars();
4108 f_MscConnHdlr_init_vty();
4109
4110 f_create_chan_and_exp();
4111 /* we should now have a COMPL_L3 at the MSC */
4112 BSSAP.receive(tr_BSSMAP_ComplL3);
4113
4114 /* Send CommonID */
4115 BSSAP.send(ts_BSSMAP_CommonId(g_pars.imsi));
4116
4117 /* Use VTY to verify that the IMSI of the subscr_conn is set */
4118 var charstring regex := "*(IMSI: " & hex2str(g_pars.imsi) & ")*";
4119 f_vty_transceive_match_regexp_retry(BSCVTY, "show conns", regex, 0, 4, 1.0);
4120
4121 setverdict(pass);
4122}
4123testcase TC_common_id() runs on test_CT {
4124 var MSC_ConnHdlr vc_conn;
4125 f_init(1, true);
4126 f_sleep(1.0);
4127 vc_conn := f_start_handler(refers(f_tc_common_id));
4128 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004129 f_shutdown_helper();
Harald Welteeddf0e92020-06-21 19:42:15 +02004130}
4131
Harald Weltee3bd6582018-01-31 22:51:25 +01004132private function f_est_single_l3(template PDU_ML3_MS_NW l3) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02004133 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01004134 f_create_chan_and_exp();
Harald Welte898113b2018-01-31 18:32:21 +01004135 /* we should now have a COMPL_L3 at the MSC */
4136 BSSAP.receive(tr_BSSMAP_ComplL3);
4137
Harald Weltee3bd6582018-01-31 22:51:25 +01004138 /* send the single message we want to send */
4139 f_rsl_send_l3(l3);
4140}
4141
4142private function f_bssap_expect_nothing(float sec := 5.00) runs on MSC_ConnHdlr {
4143 timer T := sec;
4144 var PDU_BSSAP bssap;
Harald Welte898113b2018-01-31 18:32:21 +01004145 T.start;
4146 alt {
Harald Weltee3bd6582018-01-31 22:51:25 +01004147 [] BSSAP.receive(PDU_BSSAP:?) -> value bssap {
4148 setverdict(fail, "Unexpected BSSMAP ", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02004149 mtc.stop;
Harald Welte898113b2018-01-31 18:32:21 +01004150 }
4151 [] T.timeout {
4152 setverdict(pass);
4153 }
4154 }
4155}
4156
Harald Weltee3bd6582018-01-31 22:51:25 +01004157/* unsolicited ASSIGNMENT FAIL (without ASSIGN) from MS shouldn't bring BSC down */
4158private function f_tc_unsol_ass_fail(charstring id) runs on MSC_ConnHdlr {
4159 f_est_single_l3(ts_RRM_AssignmentFailure('00'O));
4160 f_bssap_expect_nothing();
4161}
Harald Welte898113b2018-01-31 18:32:21 +01004162testcase TC_unsol_ass_fail() runs on test_CT {
4163 var MSC_ConnHdlr vc_conn;
4164 f_init(1, true);
4165 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02004166 vc_conn := f_start_handler(refers(f_tc_unsol_ass_fail));
Harald Welte898113b2018-01-31 18:32:21 +01004167 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004168 f_shutdown_helper();
Harald Welte898113b2018-01-31 18:32:21 +01004169}
Harald Welte552620d2017-12-16 23:21:36 +01004170
Harald Welteea99a002018-01-31 20:46:43 +01004171
4172/* unsolicited ASSIGNMENT COMPLETE (without ASSIGN) from MS shouldn't bring BSC down */
4173private function f_tc_unsol_ass_compl(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01004174 f_est_single_l3(ts_RRM_AssignmentComplete('00'O));
4175 f_bssap_expect_nothing();
Harald Welteea99a002018-01-31 20:46:43 +01004176}
4177testcase TC_unsol_ass_compl() runs on test_CT {
4178 var MSC_ConnHdlr vc_conn;
4179 f_init(1, true);
4180 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02004181 vc_conn := f_start_handler(refers(f_tc_unsol_ass_compl));
Harald Welteea99a002018-01-31 20:46:43 +01004182 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004183 f_shutdown_helper();
Harald Welteea99a002018-01-31 20:46:43 +01004184}
4185
4186
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004187/* unsolicited HANDOVER FAIL (without ASSIGN) from MS shouldn't bring BSC down */
4188private function f_tc_unsol_ho_fail(charstring id) runs on MSC_ConnHdlr {
Harald Weltee3bd6582018-01-31 22:51:25 +01004189 f_est_single_l3(ts_RRM_HandoverFailure('00'O));
4190 f_bssap_expect_nothing();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004191}
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004192testcase TC_unsol_ho_fail() runs on test_CT {
4193 var MSC_ConnHdlr vc_conn;
4194 f_init(1, true);
4195 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02004196 vc_conn := f_start_handler(refers(f_tc_unsol_ho_fail));
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004197 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004198 f_shutdown_helper();
Harald Weltefbf9b5e2018-01-31 20:41:23 +01004199}
4200
4201
Harald Weltee3bd6582018-01-31 22:51:25 +01004202/* short message from MS should be ignored */
4203private function f_tc_err_82_short_msg(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02004204 g_pars := f_gen_test_hdlr_pars();
Harald Weltea0630032018-03-20 21:09:55 +01004205 f_create_chan_and_exp();
Harald Weltee3bd6582018-01-31 22:51:25 +01004206 /* we should now have a COMPL_L3 at the MSC */
4207 BSSAP.receive(tr_BSSMAP_ComplL3);
4208
4209 /* send short message */
4210 RSL.send(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), ''O));
4211 f_bssap_expect_nothing();
4212}
4213testcase TC_err_82_short_msg() runs on test_CT {
4214 var MSC_ConnHdlr vc_conn;
4215 f_init(1, true);
4216 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02004217 vc_conn := f_start_handler(refers(f_tc_err_82_short_msg));
Harald Weltee3bd6582018-01-31 22:51:25 +01004218 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004219 f_shutdown_helper();
Harald Weltee3bd6582018-01-31 22:51:25 +01004220}
4221
4222
Harald Weltee9e02e42018-01-31 23:36:25 +01004223/* 24.008 8.4 Unknown message must trigger RR STATUS */
4224private function f_tc_err_84_unknown_msg(charstring id) runs on MSC_ConnHdlr {
4225 f_est_single_l3(ts_RRM_UL_REL('00'O));
4226 timer T := 3.0
4227 alt {
4228 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_STATUS)) {
4229 setverdict(pass);
4230 }
4231 [] BSSAP.receive { setverdict(fail, "unexpected BSSAP"); }
Harald Welte458fd372018-03-21 11:26:23 +01004232 [] T.timeout { setverdict(fail, "Timeout waiting for RR STATUS"); }
Harald Weltee9e02e42018-01-31 23:36:25 +01004233 }
4234}
4235testcase TC_err_84_unknown_msg() runs on test_CT {
4236 var MSC_ConnHdlr vc_conn;
4237 f_init(1, true);
4238 f_sleep(1.0);
Harald Welte8863fa12018-05-10 20:15:27 +02004239 vc_conn := f_start_handler(refers(f_tc_err_84_unknown_msg));
Harald Weltee9e02e42018-01-31 23:36:25 +01004240 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004241 f_shutdown_helper();
Harald Weltee9e02e42018-01-31 23:36:25 +01004242}
4243
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004244/***********************************************************************
4245 * Handover
4246 ***********************************************************************/
4247
Harald Welte94e0c342018-04-07 11:33:23 +02004248/* execute a "bts <0-255> trx <0-255> timeslot <0-7> " command on given Dchan */
4249private function f_vty_ts_action(charstring suffix, integer bts_nr, integer trx_nr, integer ts_nr)
4250runs on test_CT {
4251 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
4252 " timeslot "&int2str(ts_nr)&" ";
4253 f_vty_transceive(BSCVTY, cmd & suffix);
4254}
4255
Harald Welte261af4b2018-02-12 21:20:39 +01004256/* 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 +07004257private function f_vty_ss_action(TELNETasp_PT pt, charstring suffix,
4258 uint8_t bts_nr, uint8_t trx_nr,
4259 in RslChannelNr chan_nr)
4260{
Harald Welte261af4b2018-02-12 21:20:39 +01004261 /* FIXME: resolve those from component-global state */
4262 var integer ts_nr := chan_nr.tn;
4263 var integer ss_nr;
4264 if (ischosen(chan_nr.u.ch0)) {
4265 ss_nr := 0;
4266 } else if (ischosen(chan_nr.u.lm)) {
4267 ss_nr := chan_nr.u.lm.sub_chan;
4268 } else if (ischosen(chan_nr.u.sdcch4)) {
4269 ss_nr := chan_nr.u.sdcch4.sub_chan;
4270 } else if (ischosen(chan_nr.u.sdcch8)) {
4271 ss_nr := chan_nr.u.sdcch8.sub_chan;
4272 } else {
4273 setverdict(fail, "Invalid ChanNr ", chan_nr);
Daniel Willmannafce8662018-07-06 23:11:32 +02004274 mtc.stop;
Harald Welte261af4b2018-02-12 21:20:39 +01004275 }
4276
4277 var charstring cmd := "bts "&int2str(bts_nr)&" trx "&int2str(trx_nr)&
4278 " timeslot "&int2str(ts_nr)&" sub-slot "&int2str(ss_nr)&" ";
Vadim Yanitskiy00070722020-09-02 17:27:57 +07004279 f_vty_transceive(pt, cmd & suffix);
Harald Welte261af4b2018-02-12 21:20:39 +01004280}
4281
Neels Hofmeyr91401012019-07-11 00:42:35 +02004282/* Even though the VTY command to trigger handover takes a new BTS number as argument, behind the scenes osmo-bsc always
4283 * translates that to a target ARFCN+BSIC first. See bsc_vty.c trigger_ho_or_as(), which puts the selected BTS' neighbor
4284 * ident key (ARFCN + BSIC) in the struct passed on to handover_request(). handover_start() then resolves that to a
4285 * viable actual neighbor cell. So from the internal osmo-bsc perspective, we always request handover to an ARFCN + BSIC
4286 * pair, not really to a specific BTS number. */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07004287private function f_vty_handover(TELNETasp_PT pt, uint8_t bts_nr, uint8_t trx_nr,
4288 in RslChannelNr chan_nr, uint8_t new_bts_nr)
4289{
4290 f_vty_ss_action(pt, "handover " & int2str(new_bts_nr), bts_nr, trx_nr, chan_nr);
Harald Welte261af4b2018-02-12 21:20:39 +01004291}
4292
4293/* intra-BSC hand-over between BTS0 and BTS1 */
4294private function f_tc_ho_int(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02004295 g_pars := f_gen_test_hdlr_pars();
Harald Welteed848512018-05-24 22:27:58 +02004296 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4297 var PDU_BSSAP ass_cmd := f_gen_ass_req();
Harald Welte261af4b2018-02-12 21:20:39 +01004298 const OCT8 kc := '0001020304050607'O;
4299
4300 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4301 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4302
Harald Weltea0630032018-03-20 21:09:55 +01004303 f_establish_fully(ass_cmd, exp_compl);
Neels Hofmeyr666f0432020-07-04 00:53:07 +02004304 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Harald Welte261af4b2018-02-12 21:20:39 +01004305
4306 var HandoverState hs := {
4307 rr_ho_cmpl_seen := false,
4308 handover_done := false,
4309 old_chan_nr := -
4310 };
4311 /* issue hand-over command on VTY */
Vadim Yanitskiy00070722020-09-02 17:27:57 +07004312 f_vty_handover(BSCVTY, 0, 0, g_chan_nr, 1);
Harald Welte261af4b2018-02-12 21:20:39 +01004313 /* temporarily suspend DChan processing on BTS1 to avoid race with RSLEM_register */
4314 f_rslem_suspend(RSL1_PROC);
Philipp Maier3e2af5d2018-07-11 17:01:05 +02004315
4316 /* From the MGW perspective, a handover is is characterized by
4317 * performing one MDCX operation with the MGW. So we expect to see
4318 * one more MDCX during handover. */
4319 g_media.mgcp_conn[0].mdcx_seen_exp := g_media.mgcp_conn[0].crcx_seen_exp + 1;
4320
Harald Welte261af4b2018-02-12 21:20:39 +01004321 alt {
4322 [] as_handover(hs);
Harald Welte261af4b2018-02-12 21:20:39 +01004323 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02004324
Philipp Maier4dae0652018-11-12 12:03:26 +01004325 /* Since this is an internal handover we expect the BSC to inform the
4326 * MSC about the event */
4327 BSSAP.receive(tr_BSSMAP_HandoverPerformed);
4328
Philipp Maier3e2af5d2018-07-11 17:01:05 +02004329 /* Check the amount of MGCP transactions is still consistant with the
4330 * test expectation */
4331 f_check_mgcp_expectations()
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01004332 f_sleep(0.5);
Harald Welte261af4b2018-02-12 21:20:39 +01004333}
4334
4335testcase TC_ho_int() runs on test_CT {
4336 var MSC_ConnHdlr vc_conn;
4337 f_init(2, true);
4338 f_sleep(1.0);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00004339
4340 f_ctrs_bsc_and_bts_init();
4341
Harald Welte8863fa12018-05-10 20:15:27 +02004342 vc_conn := f_start_handler(refers(f_tc_ho_int));
Harald Welte261af4b2018-02-12 21:20:39 +01004343 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00004344
4345 /* from f_establish_fully() */
4346 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
4347 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
4348 /* from handover */
4349 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
4350 f_ctrs_bsc_and_bts_add(0, "handover:completed");
4351 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
4352 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:completed");
4353 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004354 f_shutdown_helper();
Harald Welte261af4b2018-02-12 21:20:39 +01004355}
Harald Weltee9e02e42018-01-31 23:36:25 +01004356
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004357/* Expecting MGCP to DLCX the endpoint's two connections: towards BTS and towards MSC */
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02004358private function f_expect_dlcx_conns() runs on MSC_ConnHdlr {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004359 var MgcpCommand mgcp;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02004360 var template MgcpResponse mgcp_resp;
4361 var MGCP_RecvFrom mrf;
4362 var template MgcpMessage msg_resp;
4363 var template MgcpMessage msg_dlcx := {
4364 command := tr_DLCX()
4365 }
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004366
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02004367 if (g_pars.aoip) {
4368 MGCP.receive(tr_DLCX()) -> value mgcp {
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004369 log("Got first DLCX: ", mgcp);
4370 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02004371 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004372
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004373 MGCP.receive(tr_DLCX()) -> value mgcp {
4374 log("Got second DLCX: ", mgcp);
4375 MGCP.send(ts_DLCX_ACK2(mgcp.line.trans_id));
4376 };
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02004377 } else {
4378 /* For SCCPLite, BSC doesn't handle the MSC-side */
4379 MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_dlcx)) -> value mrf {
4380 log("Got first DLCX: ", mrf.msg.command);
4381 msg_resp := {
4382 response := ts_DLCX_ACK2(mrf.msg.command.line.trans_id)
4383 }
4384 MGCP_MULTI.send(t_MGCP_SendToMrf(mrf, msg_resp));
4385 };
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004386 }
4387
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02004388 BSSAP.receive(tr_BSSMAP_ClearComplete);
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004389}
4390
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004391private function f_tc_ho_out_of_this_bsc(charstring id) runs on MSC_ConnHdlr {
Philipp Maier48604732018-10-09 15:00:37 +02004392 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004393
4394 var PDU_BSSAP ass_req := f_gen_ass_req();
4395 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4396 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4397 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4398 f_establish_fully(ass_req, exp_compl);
4399
Neels Hofmeyr666f0432020-07-04 00:53:07 +02004400 f_bts_0_cfg(BSCVTY, {"neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004401 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
4402
4403 BSSAP.receive(tr_BSSMAP_HandoverRequired);
4404
4405 f_sleep(0.5);
4406 /* The MSC negotiates Handover Request and Handover Request Ack with
4407 * the other BSS and comes back with a BSSMAP Handover Command
4408 * containing an RR Handover Command coming from the target BSS... */
4409
4410 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
4411 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
4412 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
4413 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
4414 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
4415
4416 /* expect the Handover Command to go out on RR */
4417 var RSL_Message rsl_ho_cmd
4418 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
4419 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
4420 var RSL_IE_Body rsl_ho_cmd_l3;
4421 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
4422 log("RSL message contains no L3 Info IE, expected RR Handover Command");
4423 setverdict(fail);
4424 } else {
4425 log("Found L3 Info: ", rsl_ho_cmd_l3);
4426 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
4427 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
4428 setverdict(fail);
4429 } else {
4430 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
4431 setverdict(pass);
4432 }
4433 }
4434
4435 /* When the other BSS has reported a completed handover, this side is
4436 * torn down. */
4437
4438 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_HANDOVER_SUCCESSFUL;
4439 var BssmapCause cause := enum2int(cause_val);
4440 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
4441
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02004442 f_expect_dlcx_conns();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004443 setverdict(pass);
4444 f_sleep(1.0);
4445}
4446testcase TC_ho_out_of_this_bsc() runs on test_CT {
4447 var MSC_ConnHdlr vc_conn;
4448
4449 f_init(1, true);
4450 f_sleep(1.0);
4451
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00004452 f_ctrs_bsc_and_bts_init();
4453
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004454 vc_conn := f_start_handler(refers(f_tc_ho_out_of_this_bsc));
4455 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00004456
4457 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
4458 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
4459 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
4460 f_ctrs_bsc_and_bts_add(0, "handover:completed");
4461 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
4462 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:completed");
4463 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004464 f_shutdown_helper();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004465}
4466
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07004467private function f_mo_l3_transceive(template (value) RslLinkId link_id := ts_RslLinkID_DCCH(0),
4468 template (present) OCT1 dlci := '00'O,
4469 octetstring l3 := '0123456789'O)
4470runs on MSC_ConnHdlr {
Neels Hofmeyr43654812020-09-25 01:35:35 +02004471 /* The old lchan and conn should still be active. See that arbitrary L3
4472 * is still going through. */
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07004473 RSL.send(ts_RSL_DATA_IND(g_chan_nr, link_id, l3));
Neels Hofmeyr43654812020-09-25 01:35:35 +02004474 var template PDU_BSSAP exp_data := {
4475 discriminator := '1'B,
4476 spare := '0000000'B,
Vadim Yanitskiyb93aa432020-10-01 14:23:11 +07004477 dlci := dlci,
4478 lengthIndicator := lengthof(l3),
Neels Hofmeyr43654812020-09-25 01:35:35 +02004479 pdu := {
4480 dtap := l3
4481 }
4482 };
4483 BSSAP.receive(exp_data);
4484 setverdict(pass);
4485}
4486
Vadim Yanitskiy0033a3b2020-10-01 22:21:16 +07004487private function f_mt_l3_transceive(template (present) RslLinkId link_id := tr_RslLinkID_DCCH(0),
4488 template (value) OCT1 dlci := '00'O,
4489 octetstring l3 := '0123456789'O)
4490runs on MSC_ConnHdlr {
4491 BSSAP.send(PDU_BSSAP:{
4492 discriminator := '1'B,
4493 spare := '0000000'B,
4494 dlci := dlci,
4495 lengthIndicator := lengthof(l3),
4496 pdu := {
4497 dtap := l3
4498 }
4499 });
4500 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, link_id, l3));
4501 setverdict(pass);
4502}
4503
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004504/* BSC asks for inter-BSC HO, but the MSC decides that it won't happen and
4505 * simply never sends a BSSMAP Handover Command. */
4506private function f_tc_ho_out_fail_no_msc_response(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01004507 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004508
4509 var PDU_BSSAP ass_req := f_gen_ass_req();
4510 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4511 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4512 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4513 f_establish_fully(ass_req, exp_compl);
4514
Neels Hofmeyr666f0432020-07-04 00:53:07 +02004515 f_bts_0_cfg(BSCVTY, {"neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004516 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
4517
4518 BSSAP.receive(tr_BSSMAP_HandoverRequired);
4519
4520 /* osmo-bsc should time out 10 seconds after the handover started.
4521 * Let's give it a bit extra. */
4522 f_sleep(15.0);
4523
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07004524 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004525 f_sleep(1.0);
4526}
4527testcase TC_ho_out_fail_no_msc_response() runs on test_CT {
4528 var MSC_ConnHdlr vc_conn;
4529
4530 f_init(1, true);
4531 f_sleep(1.0);
4532
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00004533 f_ctrs_bsc_and_bts_init();
4534
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004535 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_msc_response));
4536 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00004537
4538 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
4539 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
4540 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
4541 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
4542 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
4543 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
4544 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004545 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004546}
4547
4548/* BSC asks for inter-BSC HO, receives BSSMAP Handover Command, but MS reports
4549 * RR Handover Failure. */
4550private function f_tc_ho_out_fail_rr_ho_failure(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01004551 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004552
4553 var PDU_BSSAP ass_req := f_gen_ass_req();
4554 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4555 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4556 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4557 f_establish_fully(ass_req, exp_compl);
4558
Neels Hofmeyr666f0432020-07-04 00:53:07 +02004559 f_bts_0_cfg(BSCVTY, {"neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004560 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
4561
4562 BSSAP.receive(tr_BSSMAP_HandoverRequired);
4563
4564 f_sleep(0.5);
4565 /* The MSC negotiates Handover Request and Handover Request Ack with
4566 * the other BSS and comes back with a BSSMAP Handover Command
4567 * containing an RR Handover Command coming from the target BSS... */
4568
4569 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
4570 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
4571 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
4572 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
4573 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
4574
4575 /* expect the Handover Command to go out on RR */
4576 var RSL_Message rsl_ho_cmd
4577 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
4578 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
4579 var RSL_IE_Body rsl_ho_cmd_l3;
4580 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
4581 log("RSL message contains no L3 Info IE, expected RR Handover Command");
4582 setverdict(fail);
4583 } else {
4584 log("Found L3 Info: ", rsl_ho_cmd_l3);
4585 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
4586 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
4587 setverdict(fail);
4588 } else {
4589 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
4590 setverdict(pass);
4591 }
4592 }
4593
4594 f_sleep(0.2);
4595 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
4596
4597 /* Should tell the MSC about the failure */
4598 BSSAP.receive(tr_BSSMAP_HandoverFailure);
4599
4600 f_sleep(1.0);
4601
Vadim Yanitskiy74ae5eb2020-10-01 22:13:29 +07004602 f_mo_l3_transceive();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004603 f_sleep(1.0);
4604
4605 setverdict(pass);
4606 f_sleep(1.0);
4607}
4608testcase TC_ho_out_fail_rr_ho_failure() runs on test_CT {
4609 var MSC_ConnHdlr vc_conn;
4610
4611 f_init(1, true);
4612 f_sleep(1.0);
4613
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00004614 f_ctrs_bsc_and_bts_init();
4615
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004616 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_rr_ho_failure));
4617 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00004618
4619 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
4620 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
4621 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
4622 f_ctrs_bsc_and_bts_add(0, "handover:failed");
4623 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
4624 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:failed");
4625 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004626 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004627}
4628
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02004629/* BSC asks for inter-BSC-out HO, receives BSSMAP Handover Command, but then no reply is received about HO outcome
4630 * (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 +02004631 * and the lchan is released. */
4632private function f_tc_ho_out_fail_no_result_after_ho_cmd(charstring id) runs on MSC_ConnHdlr {
Daniel Willmann3b59eb52018-10-29 15:40:55 +01004633 g_pars := f_gen_test_hdlr_pars();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004634
4635 var PDU_BSSAP ass_req := f_gen_ass_req();
4636 ass_req.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
4637 ass_req.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
4638 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
4639 f_establish_fully(ass_req, exp_compl);
4640
Neels Hofmeyr666f0432020-07-04 00:53:07 +02004641 f_bts_0_cfg(BSCVTY, {"neighbor lac 99 arfcn 123 bsic any"});
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004642 f_vty_transceive(BSCVTY, "handover any to arfcn 123 bsic any");
4643
4644 BSSAP.receive(tr_BSSMAP_HandoverRequired);
4645
4646 f_sleep(0.5);
4647 /* The MSC negotiates Handover Request and Handover Request Ack with
4648 * the other BSS and comes back with a BSSMAP Handover Command
4649 * containing an RR Handover Command coming from the target BSS... */
4650
4651 var PDU_ML3_NW_MS rr_ho_cmd := valueof(ts_RR_HandoverCommand);
4652 log("Remote cell's RR Handover Command passed through as L3 Info: ", rr_ho_cmd);
4653 var octetstring rr_ho_cmd_enc := enc_PDU_ML3_NW_MS(rr_ho_cmd);
4654 log("Remote cell's RR Handover Command passed through as L3 Info, encoded: ", rr_ho_cmd_enc);
4655 BSSAP.send(ts_BSSMAP_HandoverCommand(rr_ho_cmd_enc));
4656
4657 /* expect the Handover Command to go out on RR */
4658 var RSL_Message rsl_ho_cmd
4659 RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, ?)) -> value rsl_ho_cmd;
4660 log("RSL Data Req went out to first BTS: ", rsl_ho_cmd);
4661 var RSL_IE_Body rsl_ho_cmd_l3;
4662 if (not f_rsl_find_ie(rsl_ho_cmd, RSL_IE_L3_INFO, rsl_ho_cmd_l3)) {
4663 log("RSL message contains no L3 Info IE, expected RR Handover Command");
4664 setverdict(fail);
4665 } else {
4666 log("Found L3 Info: ", rsl_ho_cmd_l3);
4667 if (rsl_ho_cmd_l3.l3_info.payload != rr_ho_cmd_enc) {
4668 log("FAIL: the BSC sent out a different L3 Info, not matching the RR Handover Command the other BSS forwarded.");
4669 setverdict(fail);
4670 } else {
4671 log("Success: the BSC sent out the same RR Handover Command the other BSS forwarded.");
4672 setverdict(pass);
4673 }
4674 }
4675
Neels Hofmeyr10f2bfa2019-07-09 19:33:29 +02004676 /* We get neither success nor failure report from the remote BSS. Eventually T8 times out and we run into 3GPP
4677 * TS 48.008 3.1.5.3.3 "Abnormal Conditions": Clear Request should go to the MSC, and RR should be released
4678 * after Clear Command */
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004679
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02004680 var PDU_BSSAP rx_clear_request;
Neels Hofmeyre1797aa2019-07-09 19:34:04 +02004681 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request;
4682 log("Got BSSMAP Clear Request");
4683 /* Instruct BSC to clear channel */
4684 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
4685 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
4686
4687 var MgcpCommand mgcp;
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004688 interleave {
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01004689 [] RSL.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
4690 log("Got Deact SACCH");
4691 }
Harald Welte924b6ea2019-02-04 01:05:34 +01004692 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr211169d2018-11-07 00:37:29 +01004693 log("Got RR Release");
4694 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004695 [] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
4696 log("Got RF Chan Rel");
4697 RSL.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
4698 }
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004699 }
4700
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02004701 f_expect_dlcx_conns();
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02004702
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004703 setverdict(pass);
4704 f_sleep(1.0);
4705}
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02004706testcase TC_ho_out_fail_no_result_after_ho_cmd() runs on test_CT {
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004707 var MSC_ConnHdlr vc_conn;
4708
4709 f_init(1, true);
4710 f_sleep(1.0);
4711
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00004712 f_ctrs_bsc_and_bts_init();
4713
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02004714 vc_conn := f_start_handler(refers(f_tc_ho_out_fail_no_result_after_ho_cmd));
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004715 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00004716
4717 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
4718 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
4719 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
4720 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
4721 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
4722 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
4723 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004724 f_shutdown_helper();
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02004725}
4726
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004727private function f_tc_ho_into_this_bsc(charstring id) runs on MSC_ConnHdlr {
4728 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
4729 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
4730 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
4731 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
4732 * before we get started. */
4733 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
4734 f_rslem_register(0, new_chan_nr);
4735 g_chan_nr := new_chan_nr;
4736 f_sleep(1.0);
4737
4738 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
4739 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
4740 activate(as_Media());
4741
Neels Hofmeyr90f80962020-06-12 16:16:55 +02004742 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Pau Espin Pedrol07866632020-09-03 19:10:55 +02004743 f_gen_handover_req(aoip_tla := g_pars.host_aoip_tla)));
Harald Welte6811d102019-04-14 22:23:14 +02004744 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004745
4746 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
4747
4748 var PDU_BSSAP rx_bssap;
4749 var octetstring ho_command_str;
4750
4751 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
Pau Espin Pedrol76ba5412019-06-10 11:00:33 +02004752
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004753 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
4754 log("Received L3 Info in HO Request Ack: ", ho_command_str);
4755 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
4756 log("L3 Info in HO Request Ack is ", ho_command);
4757
4758 var GsmArfcn arfcn;
4759 var RslChannelNr actual_new_chan_nr;
4760 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
4761 actual_new_chan_nr, arfcn);
4762
4763 if (actual_new_chan_nr != new_chan_nr) {
4764 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
4765 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
4766 setverdict(fail);
4767 return;
4768 }
4769 log("Handover Command chan_nr is", actual_new_chan_nr);
4770
4771 /* Now the MSC forwards the RR Handover Command to the other BSC, which
4772 * tells the MS to handover to the new lchan. Here comes the new MS on
4773 * the new lchan with a Handover RACH: */
4774
4775 /* send handover detect */
4776
4777 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
4778
4779 BSSAP.receive(tr_BSSMAP_HandoverDetect);
4780
4781 /* send handover complete over the new channel */
4782
4783 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
4784 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
4785 enc_PDU_ML3_MS_NW(l3_tx)));
4786
4787 BSSAP.receive(tr_BSSMAP_HandoverComplete);
4788 setverdict(pass);
4789}
Pau Espin Pedrol07866632020-09-03 19:10:55 +02004790function f_tc_ho_into_this_bsc_main(TestHdlrParams pars) runs on test_CT {
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004791 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004792
4793 f_init(1, true);
4794 f_sleep(1.0);
4795
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00004796 f_ctrs_bsc_and_bts_init();
4797
Neels Hofmeyr90f80962020-06-12 16:16:55 +02004798 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
4799 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004800
4801 vc_conn := f_start_handler(refers(f_tc_ho_into_this_bsc), pars);
4802 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00004803
4804 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
4805 f_ctrs_bsc_and_bts_add(0, "handover:completed");
4806 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
4807 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:completed");
4808 f_ctrs_bsc_and_bts_verify();
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01004809}
4810
Pau Espin Pedrol07866632020-09-03 19:10:55 +02004811testcase TC_ho_into_this_bsc() runs on test_CT {
4812 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4813 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004814 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02004815}
4816
4817testcase TC_ho_into_this_bsc_tla_v6() runs on test_CT {
4818 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4819 pars.host_aoip_tla := "::6";
4820 f_tc_ho_into_this_bsc_main(pars);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004821 f_shutdown_helper();
Pau Espin Pedrol07866632020-09-03 19:10:55 +02004822}
4823
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004824private function f_tc_ho_in_fail_msc_clears(charstring id) runs on MSC_ConnHdlr {
4825 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
4826 f_rslem_register(0, new_chan_nr);
4827 g_chan_nr := new_chan_nr;
4828 f_sleep(1.0);
4829
4830 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
4831 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
4832 activate(as_Media());
4833
Neels Hofmeyr90f80962020-06-12 16:16:55 +02004834 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004835 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02004836 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004837
4838 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
4839
4840 var PDU_BSSAP rx_bssap;
4841 var octetstring ho_command_str;
4842
4843 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
4844
4845 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
4846 log("Received L3 Info in HO Request Ack: ", ho_command_str);
4847 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
4848 log("L3 Info in HO Request Ack is ", ho_command);
4849
4850 var GsmArfcn arfcn;
4851 var RslChannelNr actual_new_chan_nr;
4852 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
4853 actual_new_chan_nr, arfcn);
4854
4855 if (actual_new_chan_nr != new_chan_nr) {
4856 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
4857 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
4858 setverdict(fail);
4859 return;
4860 }
4861 log("Handover Command chan_nr is", actual_new_chan_nr);
4862
Neels Hofmeyr61ca08d2019-05-06 23:52:22 +02004863 /* For deterministic test results, give some time for the MGW endpoint to be configured */
4864 f_sleep(1.0);
4865
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004866 /* Now the MSC forwards the RR Handover Command to the other BSC, which
4867 * tells the MS to handover to the new lchan. In this case, the MS
4868 * reports a Handover Failure to the old BSS, which forwards a BSSMAP
4869 * Handover Failure to the MSC. The procedure according to 3GPP TS
4870 * 48.008 3.1.5.3.2 "Handover Failure" is then that the MSC sends a
4871 * BSSMAP Clear Command: */
4872
4873 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
4874 var BssmapCause cause := enum2int(cause_val);
4875 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
4876
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02004877 f_expect_dlcx_conns();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004878 setverdict(pass);
4879 f_sleep(1.0);
4880
4881 setverdict(pass);
4882}
4883testcase TC_ho_in_fail_msc_clears() runs on test_CT {
4884 var MSC_ConnHdlr vc_conn;
4885 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4886
4887 f_init(1, true);
4888 f_sleep(1.0);
4889
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00004890 f_ctrs_bsc_and_bts_init();
4891
Neels Hofmeyr90f80962020-06-12 16:16:55 +02004892 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
4893 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004894
4895 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears), pars);
4896 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00004897
4898 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
4899 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
4900 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
4901 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
4902 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004903 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004904}
4905
4906private function f_tc_ho_in_fail_msc_clears_after_ho_detect(charstring id) runs on MSC_ConnHdlr {
4907 /* Hack: the proper way would be to wait for the BSSMAP Handover Request ACK and extract the
4908 * actual assigned chan_nr from its L3 (RR Handover Command) message. But osmo-bsc starts acting
4909 * on the lchan even before we get a chance to evaluate the BSSMAP Handover Request ACK. So we
4910 * need to assume that osmo-bsc will activate TS 1 and already set up this lchan's RSL emulation
4911 * before we get started. */
4912 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
4913 f_rslem_register(0, new_chan_nr);
4914 g_chan_nr := new_chan_nr;
4915 f_sleep(1.0);
4916
4917 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
4918 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
4919 activate(as_Media());
4920
Neels Hofmeyr90f80962020-06-12 16:16:55 +02004921 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004922 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02004923 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004924
4925 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
4926
4927 var PDU_BSSAP rx_bssap;
4928 var octetstring ho_command_str;
4929
4930 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
4931
4932 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
4933 log("Received L3 Info in HO Request Ack: ", ho_command_str);
4934 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
4935 log("L3 Info in HO Request Ack is ", ho_command);
4936
4937 var GsmArfcn arfcn;
4938 var RslChannelNr actual_new_chan_nr;
4939 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
4940 actual_new_chan_nr, arfcn);
4941
4942 if (actual_new_chan_nr != new_chan_nr) {
4943 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
4944 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
4945 setverdict(fail);
4946 return;
4947 }
4948 log("Handover Command chan_nr is", actual_new_chan_nr);
4949
4950 /* Now the MSC forwards the RR Handover Command to the other BSC, which
4951 * tells the MS to handover to the new lchan. Here comes the new MS on
4952 * the new lchan with a Handover RACH: */
4953
4954 /* send handover detect */
4955
4956 RSL.send(ts_RSL_HANDO_DET(new_chan_nr));
4957
4958 BSSAP.receive(tr_BSSMAP_HandoverDetect);
4959
4960 /* The MSC chooses to clear the connection now, maybe we got the
4961 * Handover RACH on the new cell but the MS still signaled Handover
4962 * Failure to the old BSS? */
4963
4964 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
4965 var BssmapCause cause := enum2int(cause_val);
4966 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
4967
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02004968 f_expect_dlcx_conns();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004969 f_sleep(1.0);
4970}
4971testcase TC_ho_in_fail_msc_clears_after_ho_detect() runs on test_CT {
4972 var MSC_ConnHdlr vc_conn;
4973 var TestHdlrParams pars := f_gen_test_hdlr_pars();
4974
4975 f_init(1, true);
4976 f_sleep(1.0);
4977
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00004978 f_ctrs_bsc_and_bts_init();
4979
Neels Hofmeyr90f80962020-06-12 16:16:55 +02004980 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
4981 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004982
4983 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_msc_clears_after_ho_detect), pars);
4984 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00004985
4986 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
4987 f_ctrs_bsc_and_bts_add(0, "handover:stopped");
4988 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
4989 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:stopped");
4990 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02004991 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01004992}
4993
4994/* The new BSS's lchan times out before the MSC decides that handover failed. */
4995private function f_tc_ho_in_fail_no_detect(charstring id) runs on MSC_ConnHdlr {
4996 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
4997 f_rslem_register(0, new_chan_nr);
4998 g_chan_nr := new_chan_nr;
4999 f_sleep(1.0);
5000
5001 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
5002 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
5003 activate(as_Media());
5004
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005005 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005006 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02005007 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005008
5009 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
5010
5011 var PDU_BSSAP rx_bssap;
5012 var octetstring ho_command_str;
5013
5014 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
5015
5016 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
5017 log("Received L3 Info in HO Request Ack: ", ho_command_str);
5018 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
5019 log("L3 Info in HO Request Ack is ", ho_command);
5020
5021 var GsmArfcn arfcn;
5022 var RslChannelNr actual_new_chan_nr;
5023 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
5024 actual_new_chan_nr, arfcn);
5025
5026 if (actual_new_chan_nr != new_chan_nr) {
5027 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
5028 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
5029 setverdict(fail);
5030 return;
5031 }
5032 log("Handover Command chan_nr is", actual_new_chan_nr);
5033
5034 /* Now the MSC forwards the RR Handover Command to the other BSC, which
5035 * tells the MS to handover to the new lchan. But the MS never shows up
5036 * on the new lchan. */
5037
5038 BSSAP.receive(tr_BSSMAP_HandoverFailure);
5039
5040 /* Did osmo-bsc also send a Clear Request? */
5041 timer T := 0.5;
5042 T.start;
5043 alt {
5044 [] BSSAP.receive(tr_BSSMAP_ClearRequest);
5045 [] T.timeout { }
5046 }
5047
5048 /* MSC plays along with a Clear Command (no matter whether osmo-bsc
5049 * asked for it, this is a Handover Failure after all). */
5050
5051 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION;
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();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005056 f_sleep(1.0);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005057}
5058testcase TC_ho_in_fail_no_detect() runs on test_CT {
5059 var MSC_ConnHdlr vc_conn;
5060 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5061
5062 f_init(1, true);
5063 f_sleep(1.0);
5064
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005065 f_ctrs_bsc_and_bts_init();
5066
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005067 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
5068 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005069
5070 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect), pars);
5071 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005072
5073 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5074 f_ctrs_bsc_and_bts_add(0, "handover:error");
5075 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
5076 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
5077 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005078 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005079}
5080
5081/* Same as f_tc_ho_in_fail_no_detect, but MSC fails to send a Clear Command */
5082private function f_tc_ho_in_fail_no_detect2(charstring id) runs on MSC_ConnHdlr {
5083 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(1, RSL_CHAN_NR_Bm_ACCH));
5084 f_rslem_register(0, new_chan_nr);
5085 g_chan_nr := new_chan_nr;
5086 f_sleep(1.0);
5087
5088 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
5089 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
5090 activate(as_Media());
5091
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005092 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005093 f_gen_handover_req()));
Harald Welte6811d102019-04-14 22:23:14 +02005094 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND);
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005095
5096 /* The RSL Emulation magically accepts the Chan Activ behind the scenes. */
5097
5098 var PDU_BSSAP rx_bssap;
5099 var octetstring ho_command_str;
5100
5101 BSSAP.receive(tr_BSSMAP_HandoverRequestAcknowledge(?)) -> value rx_bssap;
5102
5103 ho_command_str := rx_bssap.pdu.bssmap.handoverRequestAck.layer3Information.layer3info;
5104 log("Received L3 Info in HO Request Ack: ", ho_command_str);
5105 var PDU_ML3_NW_MS ho_command := dec_PDU_ML3_NW_MS(ho_command_str);
5106 log("L3 Info in HO Request Ack is ", ho_command);
5107
5108 var GsmArfcn arfcn;
5109 var RslChannelNr actual_new_chan_nr;
5110 f_ChDesc2RslChanNr(ho_command.msgs.rrm.handoverCommand.channelDescription2,
5111 actual_new_chan_nr, arfcn);
5112
5113 if (actual_new_chan_nr != new_chan_nr) {
5114 log("ERROR: osmo-bsc assigned a different lchan than we assumed above -- this test will fail now.",
5115 " Assumed: ", new_chan_nr, " Assigned: ", actual_new_chan_nr);
5116 setverdict(fail);
5117 return;
5118 }
5119 log("Handover Command chan_nr is", actual_new_chan_nr);
5120
5121 /* Now the MSC forwards the RR Handover Command to the other BSC, which
5122 * tells the MS to handover to the new lchan. But the MS never shows up
5123 * on the new lchan. */
5124
5125 BSSAP.receive(tr_BSSMAP_HandoverFailure);
5126
5127 /* MSC plays dumb and sends no Clear Command */
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005128 var PDU_BSSAP rx_clear_request;
Pau Espin Pedrol1fc30b92019-06-18 13:08:22 +02005129
5130 BSSAP.receive(tr_BSSMAP_ClearRequest) -> value rx_clear_request {
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005131 var BssmapCause cause := bit2int(rx_clear_request.pdu.bssmap.clearRequest.cause.causeValue);
5132 BSSAP.send(ts_BSSMAP_ClearCommand(cause));
5133 };
Pau Espin Pedrol7aa02742019-06-26 16:30:14 +02005134 f_expect_dlcx_conns();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005135 f_sleep(1.0);
5136}
5137testcase TC_ho_in_fail_no_detect2() runs on test_CT {
5138 var MSC_ConnHdlr vc_conn;
5139 var TestHdlrParams pars := f_gen_test_hdlr_pars();
5140
5141 f_init(1, true);
5142 f_sleep(1.0);
5143
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005144 f_ctrs_bsc_and_bts_init();
5145
Neels Hofmeyr90f80962020-06-12 16:16:55 +02005146 pars.sccp_addr_msc := g_bssap[0].sccp_addr_own;
5147 pars.sccp_addr_bsc := g_bssap[0].sccp_addr_peer;
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005148
5149 vc_conn := f_start_handler(refers(f_tc_ho_in_fail_no_detect2), pars);
5150 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005151
5152 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5153 f_ctrs_bsc_and_bts_add(0, "handover:error");
5154 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:attempted");
5155 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_in:error");
5156 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005157 f_shutdown_helper();
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01005158}
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01005159
Neels Hofmeyr91401012019-07-11 00:42:35 +02005160type record of charstring Commands;
5161
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005162private function f_bts_0_cfg(TELNETasp_PT pt, Commands cmds := {})
Neels Hofmeyr91401012019-07-11 00:42:35 +02005163{
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005164 f_vty_enter_cfg_bts(pt, 0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02005165 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005166 f_vty_transceive(pt, cmds[i]);
Neels Hofmeyr91401012019-07-11 00:42:35 +02005167 }
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005168 f_vty_transceive(pt, "end");
Neels Hofmeyr91401012019-07-11 00:42:35 +02005169}
5170
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01005171private function f_cs7_inst_0_cfg(TELNETasp_PT pt, Commands cmds := {})
5172{
5173 f_vty_enter_cfg_cs7_inst(pt, 0);
5174 for (var integer i := 0; i < sizeof(cmds); i := i+1) {
5175 f_vty_transceive(pt, cmds[i]);
5176 }
5177 f_vty_transceive(pt, "end");
5178}
5179
Neels Hofmeyr91401012019-07-11 00:42:35 +02005180private function f_probe_for_handover(charstring log_label,
5181 charstring log_descr,
5182 charstring handover_vty_cmd,
5183 boolean expect_handover,
5184 boolean is_inter_bsc_handover := false)
5185runs on MSC_ConnHdlr
5186{
Neels Hofmeyrb3fc8982020-05-11 00:16:42 +02005187 /* We're going to thwart any and all handover attempts, just be ready to handle (and ignore) handover target
5188 * lchans to be established on bts 1 or bts 2. */
5189 f_rslem_suspend(RSL1_PROC);
5190 f_rslem_suspend(RSL2_PROC);
5191
Neels Hofmeyr91401012019-07-11 00:42:35 +02005192 var RSL_Message rsl;
5193
5194 var charstring log_msg := " (expecting handover)"
5195 if (not expect_handover) {
5196 log_msg := " (expecting NO handover)";
5197 }
5198 log("f_probe_for_handover starting: " & log_label & ": " & log_descr & log_msg);
5199 f_vty_transceive(BSCVTY, handover_vty_cmd);
5200
Neels Hofmeyr91401012019-07-11 00:42:35 +02005201 timer T := 2.0;
5202 T.start;
5203
5204 alt {
5205 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
5206 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
5207 log("Rx L3 from net: ", l3);
5208 if (ischosen(l3.msgs.rrm.handoverCommand)) {
5209 var RslChannelNr new_chan_nr;
5210 var GsmArfcn arfcn;
5211 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
5212 new_chan_nr, arfcn);
5213 log("Handover to new chan ", new_chan_nr, " on ARFCN ", arfcn);
5214 log(l3.msgs.rrm.handoverCommand);
5215
5216 /* Need to register for new lchan on new BTS -- it's either bts 1 or bts 2. It doesn't really
5217 * matter on which BTS it really is, we're not going to follow through an entire handover
5218 * anyway. */
5219 f_rslem_register(0, new_chan_nr, RSL1_PROC);
5220 f_rslem_resume(RSL1_PROC);
5221 f_rslem_register(0, new_chan_nr, RSL2_PROC);
5222 f_rslem_resume(RSL2_PROC);
5223
5224 if (expect_handover and not is_inter_bsc_handover) {
5225 setverdict(pass);
5226 log("f_probe_for_handover(" & log_label & "): Got RSL Handover Command as expected.");
5227 } else {
5228 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got RSL Handover Command. "
5229 & log_label & ": " & log_descr);
5230 }
5231
5232 log("f_probe_for_handover(" & log_label & "): Ending the test: Handover Failure stops the procedure.");
5233 /* osmo-bsc has triggered Handover. That's all we need to know for this test, reply with
5234 * Handover Failure. */
5235 f_rsl_send_l3(ts_RRM_HandoverFailure('00'O));
5236
5237 /* target BTS is told to release lchan again; don't care which BTS nor what messages. */
5238 f_sleep(0.5);
5239 RSL1.clear;
5240 RSL2.clear;
5241 log("f_probe_for_handover(" & log_label & "): done (got RSL Handover Command)");
5242 break;
5243 } else {
5244 repeat;
5245 }
5246 }
5247 [] BSSAP.receive(tr_BSSMAP_HandoverRequired) {
5248 if (expect_handover and is_inter_bsc_handover) {
5249 setverdict(pass);
5250 log("f_probe_for_handover(" & log_label & "): Got BSSMAP Handover Required as expected.");
5251 } else {
5252 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected none, but got BSSMAP Handover Required. "
5253 & log_label & ": " & log_descr);
5254 }
5255
5256 log("f_probe_for_handover(" & log_label & "): done (got BSSMAP Handover Required)");
5257
5258 /* Note: f_tc_ho_neighbor_config_start() sets T7, the timeout for BSSMAP Handover Required, to
5259 * 1 second. There is no legal way to quickly abort a handover after a BSSMAP Handover Required,
5260 * setting a short timeout and waiting is the only way. */
5261 log("f_probe_for_handover(" & log_label & "): waiting for inter-BSC HO to time out...");
5262 f_sleep(1.5);
5263 log("f_probe_for_handover(" & log_label & "): ...done");
5264
5265 break;
5266 }
5267 [] T.timeout {
5268 if (expect_handover) {
5269 setverdict(fail, "f_probe_for_handover(" & log_label & "): Expected Handover, but got none. "
5270 & log_label & ": " & log_descr);
5271 } else {
5272 setverdict(pass);
5273 log("f_probe_for_handover(" & log_label & "): Got no Handover, as expected.");
5274 }
5275 log("f_probe_for_handover(" & log_label & "): done (got no Handover)");
5276 break;
5277 }
5278 }
5279
5280 f_rslem_resume(RSL1_PROC);
5281 f_rslem_resume(RSL2_PROC);
5282 f_sleep(3.0);
5283 RSL.clear;
5284
5285 log("f_probe_for_handover(" & log_label & "): done clearing");
5286}
5287
5288/* Test the effect of various neighbor configuration scenarios:
5289 *
5290 * To avoid complexity, block off any actual handover operation, and always remain on the lchan at bts 0.
5291 * Reconfigure the neighbors for bts 0, trigger a Handover, and probe whether osmo-bsc does or doesn't start HO.
5292 */
5293private function f_tc_ho_neighbor_config_start() runs on MSC_ConnHdlr {
5294 g_pars := f_gen_test_hdlr_pars();
5295 var template PDU_BSSAP exp_compl := f_gen_exp_compl();
5296 var PDU_BSSAP ass_cmd := f_gen_ass_req();
5297 const OCT8 kc := '0001020304050607'O;
5298
5299 ass_cmd.pdu.bssmap.assignmentRequest.channelType := valueof(ts_BSSMAP_IE_ChannelType);
5300 ass_cmd.pdu.bssmap.assignmentRequest.codecList := valueof(ts_BSSMAP_IE_CodecList({ts_CodecFR}));
5301
5302 /* Establish lchan at bts 0 */
5303 f_establish_fully(ass_cmd, exp_compl);
5304
5305 /* Shorten the inter-BSC Handover timeout, to not wait so long for inter-BSC Handovers */
5306 f_vty_enter_cfg_network(BSCVTY);
5307 f_vty_transceive(BSCVTY, "timer T7 1");
5308 f_vty_transceive(BSCVTY, "end");
5309}
5310
5311private function f_tc_ho_neighbor_config_1(charstring id) runs on MSC_ConnHdlr {
5312 f_tc_ho_neighbor_config_start();
5313
5314 /*
5315 * bts 0 ARFCN 871 BSIC 10
5316 * bts 1 ARFCN 871 BSIC 11
5317 * bts 2 ARFCN 871 BSIC 12
5318 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
5319 */
5320
5321 log("f_tc_ho_neighbor_config: 1. No 'neighbor' config");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005322 f_bts_0_cfg(BSCVTY, {"no neighbors"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02005323 f_probe_for_handover("1.a", "HO to bts 1 works, implicitly listed as neighbor (legacy behavior when none are configured)",
5324 "handover any to arfcn 871 bsic 11",
5325 true);
5326
5327 f_probe_for_handover("1.b", "HO to unknown cell does not start",
5328 "handover any to arfcn 13 bsic 39",
5329 false);
5330
5331 f_probe_for_handover("1.c", "HO to 871-12 is ambiguous = error",
5332 "handover any to arfcn 871 bsic 12",
5333 false);
5334
5335 f_probe_for_handover("1.d", "HO to 871-11 still works (verify that this test properly cleans up)",
5336 "handover any to arfcn 871 bsic 11",
5337 true);
5338}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005339testcase TC_ho_neighbor_config_1() runs on test_CT {
5340 var MSC_ConnHdlr vc_conn;
5341 f_init(3, true, guard_timeout := 60.0);
5342 f_sleep(1.0);
5343 f_ctrs_bsc_and_bts_init();
5344 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_1));
5345 vc_conn.done;
5346
5347 /* f_tc_ho_neighbor_config_start() */
5348 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5349 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5350
5351 /* 1.a */
5352 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
5353 * handover quickly by sending a Handover Failure message. */
5354 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5355 f_ctrs_bsc_and_bts_add(0, "handover:failed");
5356 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5357 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
5358
5359 /* 1.b */
5360 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5361 f_ctrs_bsc_and_bts_add(0, "handover:error");
5362
5363 /* 1.c */
5364 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5365 f_ctrs_bsc_and_bts_add(0, "handover:error");
5366
5367 /* 1.d */
5368 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5369 f_ctrs_bsc_and_bts_add(0, "handover:failed");
5370 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5371 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
5372
5373 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005374 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005375}
5376
Neels Hofmeyr91401012019-07-11 00:42:35 +02005377private function f_tc_ho_neighbor_config_2(charstring id) runs on MSC_ConnHdlr {
5378 f_tc_ho_neighbor_config_start();
5379
5380 /*
5381 * bts 0 ARFCN 871 BSIC 10
5382 * bts 1 ARFCN 871 BSIC 11
5383 * bts 2 ARFCN 871 BSIC 12
5384 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
5385 */
5386
5387 log("f_tc_ho_neighbor_config: 2. explicit local neighbor: 'neighbor bts 1'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005388 f_bts_0_cfg(BSCVTY, {"neighbor bts 1"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02005389 f_sleep(0.5);
5390
5391 f_probe_for_handover("2.a", "HO to bts 1 works, explicitly listed as neighbor",
5392 "handover any to arfcn 871 bsic 11",
5393 true);
5394
5395 f_probe_for_handover("2.b", "HO to bts 2 doesn't work, not listed as neighbor",
5396 "handover any to arfcn 871 bsic 12",
5397 false);
5398}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005399testcase TC_ho_neighbor_config_2() runs on test_CT {
5400 var MSC_ConnHdlr vc_conn;
5401 f_init(3, true, guard_timeout := 50.0);
5402 f_sleep(1.0);
5403 f_ctrs_bsc_and_bts_init();
5404 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_2));
5405 vc_conn.done;
5406
5407 /* f_tc_ho_neighbor_config_start() */
5408 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5409 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5410
5411 /* 2.a */
5412 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
5413 * handover quickly by sending a Handover Failure message. */
5414 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5415 f_ctrs_bsc_and_bts_add(0, "handover:failed");
5416 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5417 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
5418
5419 /* 2.b */
5420 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5421 f_ctrs_bsc_and_bts_add(0, "handover:error");
5422
5423 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005424 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005425}
5426
Neels Hofmeyr91401012019-07-11 00:42:35 +02005427private function f_tc_ho_neighbor_config_3(charstring id) runs on MSC_ConnHdlr {
5428 f_tc_ho_neighbor_config_start();
5429
5430 /*
5431 * bts 0 ARFCN 871 BSIC 10
5432 * bts 1 ARFCN 871 BSIC 11
5433 * bts 2 ARFCN 871 BSIC 12
5434 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
5435 */
5436
5437 log("f_tc_ho_neighbor_config: 3. explicit local neighbor: 'neighbor bts 2'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005438 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02005439 f_sleep(0.5);
5440
5441 f_probe_for_handover("3.a", "HO to bts 1 doesn't work, not listed as neighbor",
5442 "handover any to arfcn 871 bsic 11",
5443 false);
5444 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",
5445 "handover any to arfcn 871 bsic 12",
5446 true);
5447}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005448testcase TC_ho_neighbor_config_3() runs on test_CT {
5449 var MSC_ConnHdlr vc_conn;
5450 f_init(3, true, guard_timeout := 50.0);
5451 f_sleep(1.0);
5452 f_ctrs_bsc_and_bts_init();
5453 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_3));
5454 vc_conn.done;
5455
5456 /* f_tc_ho_neighbor_config_start() */
5457 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5458 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5459
5460 /* 3.a */
5461 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5462 f_ctrs_bsc_and_bts_add(0, "handover:error");
5463
5464 /* 3.b */
5465 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
5466 * handover quickly by sending a Handover Failure message. */
5467 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5468 f_ctrs_bsc_and_bts_add(0, "handover:failed");
5469 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5470 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
5471
5472 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005473 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005474}
5475
Neels Hofmeyr91401012019-07-11 00:42:35 +02005476private function f_tc_ho_neighbor_config_4(charstring id) runs on MSC_ConnHdlr {
5477 f_tc_ho_neighbor_config_start();
5478
5479 /*
5480 * bts 0 ARFCN 871 BSIC 10
5481 * bts 1 ARFCN 871 BSIC 11
5482 * bts 2 ARFCN 871 BSIC 12
5483 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
5484 */
5485
5486 log("f_tc_ho_neighbor_config: 4. explicit remote neighbor: 'neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005487 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02005488 f_sleep(0.5);
5489
5490 f_probe_for_handover("4.a", "HO to bts 1 doesn't work, not listed as neighbor",
5491 "handover any to arfcn 871 bsic 11",
5492 false);
5493 f_probe_for_handover("4.b", "HO to bts 2 doesn't work, not listed as neighbor",
5494 "handover any to arfcn 871 bsic 12",
5495 false);
5496 f_probe_for_handover("4.c", "HO to 123-45 triggers inter-BSC HO",
5497 "handover any to arfcn 123 bsic 45",
5498 true, true);
5499}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005500testcase TC_ho_neighbor_config_4() runs on test_CT {
5501 var MSC_ConnHdlr vc_conn;
5502 f_init(3, true, guard_timeout := 50.0);
5503 f_sleep(1.0);
5504 f_ctrs_bsc_and_bts_init();
5505 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_4));
5506 vc_conn.done;
5507
5508 /* f_tc_ho_neighbor_config_start() */
5509 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5510 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5511
5512 /* 4.a */
5513 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5514 f_ctrs_bsc_and_bts_add(0, "handover:error");
5515
5516 /* 4.b */
5517 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5518 f_ctrs_bsc_and_bts_add(0, "handover:error");
5519
5520 /* 4.c */
5521 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
5522 * handover quickly by timing out after the Handover Required message */
5523 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5524 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5525 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5526 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5527
5528 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005529 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005530}
5531
Neels Hofmeyr91401012019-07-11 00:42:35 +02005532private function f_tc_ho_neighbor_config_5(charstring id) runs on MSC_ConnHdlr {
5533 f_tc_ho_neighbor_config_start();
5534
5535 /*
5536 * bts 0 ARFCN 871 BSIC 10
5537 * bts 1 ARFCN 871 BSIC 11
5538 * bts 2 ARFCN 871 BSIC 12
5539 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
5540 */
5541
5542 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 +02005543 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02005544 f_sleep(0.5);
5545
5546 f_probe_for_handover("5.a", "HO to 871-12 triggers inter-BSC HO (ignoring local cells with same ARFCN+BSIC)",
5547 "handover any to arfcn 871 bsic 12",
5548 true, true);
5549}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005550testcase TC_ho_neighbor_config_5() runs on test_CT {
5551 var MSC_ConnHdlr vc_conn;
5552 f_init(3, true);
5553 f_sleep(1.0);
5554 f_ctrs_bsc_and_bts_init();
5555 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_5));
5556 vc_conn.done;
5557
5558 /* f_tc_ho_neighbor_config_start() */
5559 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5560 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5561
5562 /* 5 */
5563 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
5564 * handover quickly by timing out after the Handover Required message */
5565 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5566 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5567 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5568 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5569
5570 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005571 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005572}
5573
Neels Hofmeyr91401012019-07-11 00:42:35 +02005574private function f_tc_ho_neighbor_config_6(charstring id) runs on MSC_ConnHdlr {
5575 f_tc_ho_neighbor_config_start();
5576
5577 /*
5578 * bts 0 ARFCN 871 BSIC 10
5579 * bts 1 ARFCN 871 BSIC 11
5580 * bts 2 ARFCN 871 BSIC 12
5581 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
5582 */
5583
5584 log("f_tc_ho_neighbor_config: 6. config error: explicit local and remote neighbors with ambiguous ARFCN+BSIC:"
5585 & " 'neighbor bts 2; neighbor lac 99 arfcn 871 bsic 12'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005586 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 871 bsic 12"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02005587 f_sleep(0.5);
5588
5589 f_probe_for_handover("6.a", "HO to 871-12 is ambiguous = error",
5590 "handover any to arfcn 871 bsic 12",
5591 false);
5592}
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005593testcase TC_ho_neighbor_config_6() runs on test_CT {
5594 var MSC_ConnHdlr vc_conn;
5595 f_init(3, true);
5596 f_sleep(1.0);
5597 f_ctrs_bsc_and_bts_init();
5598 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_6));
5599 vc_conn.done;
5600
5601 /* f_tc_ho_neighbor_config_start() */
5602 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5603 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5604
5605 /* 6.a */
5606 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
5607 * handover quickly by timing out after the Handover Required message */
5608 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5609 f_ctrs_bsc_and_bts_add(0, "handover:error");
5610
5611 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005612 f_shutdown_helper();
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005613}
5614
Neels Hofmeyr91401012019-07-11 00:42:35 +02005615private function f_tc_ho_neighbor_config_7(charstring id) runs on MSC_ConnHdlr {
5616 f_tc_ho_neighbor_config_start();
5617
5618 /*
5619 * bts 0 ARFCN 871 BSIC 10
5620 * bts 1 ARFCN 871 BSIC 11
5621 * bts 2 ARFCN 871 BSIC 12
5622 * bts 3 ARFCN 871 BSIC 12 serves as ambiguity for bts 2, re-using the ARFCN+BSIC
5623 */
5624
5625 log("f_tc_ho_neighbor_config: 7. explicit local and remote neighbors:"
5626 & " 'neighbor bts 2; neighbor lac 99 arfcn 123 bsic 45'");
Neels Hofmeyr666f0432020-07-04 00:53:07 +02005627 f_bts_0_cfg(BSCVTY, {"no neighbors", "neighbor bts 2", "neighbor lac 99 arfcn 123 bsic 45"});
Neels Hofmeyr91401012019-07-11 00:42:35 +02005628 f_sleep(0.5);
5629
5630 f_probe_for_handover("7.a", "HO to 871-12 does HO to bts 2",
5631 "handover any to arfcn 871 bsic 12",
5632 true);
5633 f_probe_for_handover("7.b", "HO to 123-45 triggers inter-BSC HO",
5634 "handover any to arfcn 123 bsic 45",
5635 true, true);
5636}
Neels Hofmeyr91401012019-07-11 00:42:35 +02005637testcase TC_ho_neighbor_config_7() runs on test_CT {
5638 var MSC_ConnHdlr vc_conn;
Neels Hofmeyrf2b88032020-06-16 00:35:04 +02005639 f_init(3, true, guard_timeout := 50.0);
Neels Hofmeyr91401012019-07-11 00:42:35 +02005640 f_sleep(1.0);
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005641 f_ctrs_bsc_and_bts_init();
Neels Hofmeyr91401012019-07-11 00:42:35 +02005642 vc_conn := f_start_handler(refers(f_tc_ho_neighbor_config_7));
5643 vc_conn.done;
Neels Hofmeyr12941bd2020-08-29 03:21:26 +00005644
5645 /* f_tc_ho_neighbor_config_start() */
5646 f_ctrs_bsc_and_bts_add(0, "assignment:attempted");
5647 f_ctrs_bsc_and_bts_add(0, "assignment:completed");
5648
5649 /* 7.a */
5650 /* "failed" means a handover was triggered and started (which is all this test aims for) and the test ended the
5651 * handover quickly by sending a Handover Failure message. */
5652 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5653 f_ctrs_bsc_and_bts_add(0, "handover:failed");
5654 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:attempted");
5655 f_ctrs_bsc_and_bts_add(0, "intra_bsc_ho:failed");
5656
5657 /* 7.b */
5658 /* "timeout" means a handover was triggered and started (which is all this test aims for) and the test ended the
5659 * handover quickly by timing out after the Handover Required message */
5660 f_ctrs_bsc_and_bts_add(0, "handover:attempted");
5661 f_ctrs_bsc_and_bts_add(0, "handover:timeout");
5662 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:attempted");
5663 f_ctrs_bsc_and_bts_add(0, "interbsc_ho_out:timeout");
5664
5665 f_ctrs_bsc_and_bts_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005666 f_shutdown_helper();
Neels Hofmeyr91401012019-07-11 00:42:35 +02005667}
5668
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01005669/* OS#3041: Open and close N connections in a normal fashion, and expect no
5670 * BSSMAP Reset just because of that. */
5671testcase TC_bssap_rlsd_does_not_cause_bssmap_reset() runs on test_CT {
5672 var default d;
5673 var integer i;
5674 var DchanTuple dt;
5675
5676 f_init();
5677
5678 /* Wait for initial BSSMAP Reset to pass */
5679 f_sleep(4.0);
5680
5681 d := activate(no_bssmap_reset());
5682
5683 /* Setup up a number of connections and RLSD them again from the MSC
5684 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
5685 * Let's do it some more times for good measure. */
Harald Weltec3260d92018-06-11 17:48:16 +02005686 for (i := 0; i < 4; i := i+1) {
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01005687 /* Since we're doing a lot of runs, give each one a fresh
5688 * T_guard from the top. */
5689 T_guard.start;
5690
5691 /* Setup a BSSAP connection and clear it right away. This is
5692 * the MSC telling the BSC about a planned release, it's not an
5693 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02005694 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01005695
5696 /* MSC disconnects (RLSD). */
5697 BSSAP.send(ts_BSSAP_DISC_req(dt.sccp_conn_id, 0));
5698 }
5699
5700 /* In the buggy behavior, a timeout of 2 seconds happens between above
5701 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
5702 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
5703 f_sleep(4.0);
5704
5705 deactivate(d);
5706 f_shutdown_helper();
5707}
Harald Welte552620d2017-12-16 23:21:36 +01005708
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01005709/* OS#3041: Open and close N connections in a normal fashion, and expect no
5710 * BSSMAP Reset just because of that. Invoke the release by a BSSMAP Clear from
5711 * the MSC. */
5712testcase TC_bssmap_clear_does_not_cause_bssmap_reset() runs on test_CT {
5713 var default d;
5714 var integer i;
5715 var DchanTuple dt;
5716 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01005717 var myBSSMAP_Cause cause_val := GSM0808_CAUSE_CALL_CONTROL;
5718 var BssmapCause cause := enum2int(cause_val);
5719
5720 f_init();
5721
5722 /* Wait for initial BSSMAP Reset to pass */
5723 f_sleep(4.0);
5724
5725 d := activate(no_bssmap_reset());
5726
5727 /* Setup up a number of connections and RLSD them again from the MSC
5728 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
5729 * Let's do it some more times for good measure. */
5730 for (i := 0; i < 8; i := i+1) {
5731 /* Since we're doing a lot of runs, give each one a fresh
5732 * T_guard from the top. */
5733 T_guard.start;
5734
5735 /* Setup a BSSAP connection and clear it right away. This is
5736 * the MSC telling the BSC about a planned release, it's not an
5737 * erratic loss of a connection. */
Harald Weltea1897182018-06-11 13:53:09 +02005738 dt := f_est_dchan(int2oct(i,1), 23+i, '00010203040506'O);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01005739
5740 /* Instruct BSC to clear channel */
5741 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
5742
5743 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02005744 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01005745 }
5746
5747 /* In the buggy behavior, a timeout of 2 seconds happens between above
5748 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
5749 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
5750 f_sleep(4.0);
5751
5752 deactivate(d);
5753 f_shutdown_helper();
5754}
5755
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01005756/* OS#3041: Open and close N connections in a normal fashion, and expect no
5757 * BSSMAP Reset just because of that. Close connections from the MS side with a
5758 * Release Ind on RSL. */
5759testcase TC_ms_rel_ind_does_not_cause_bssmap_reset() runs on test_CT {
5760 var default d;
5761 var integer i;
5762 var DchanTuple dt;
5763 var BSSAP_N_DATA_ind rx_di;
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01005764 var integer j;
5765
5766 f_init();
5767
5768 /* Wait for initial BSSMAP Reset to pass */
5769 f_sleep(4.0);
5770
5771 d := activate(no_bssmap_reset());
5772
5773 /* Setup up a number of connections and RLSD them again from the MSC
5774 * side. In the buggy behavior, the fourth one triggers BSSMAP Reset.
5775 * Let's do it some more times for good measure. */
5776 for (i := 0; i < 8; i := i+1) {
5777 /* Since we're doing a lot of runs, give each one a fresh
5778 * T_guard from the top. */
5779 T_guard.start;
5780
5781 /* Setup a BSSAP connection and clear it right away. This is
5782 * the MSC telling the BSC about a planned release, it's not an
5783 * erratic loss of a connection. */
5784 dt := f_est_dchan('23'O, 23, '00010203040506'O);
5785
5786 /* simulate RLL REL IND */
5787 f_ipa_tx(0, ts_RSL_REL_IND(dt.rsl_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
5788
5789 /* expect Clear Request on MSC side */
5790 BSSAP.receive(tr_BSSAP_DATA_ind(dt.sccp_conn_id, tr_BSSMAP_ClearRequest)) -> value rx_di;
5791
5792 /* Instruct BSC to clear channel */
5793 var BssmapCause cause := bit2int(rx_di.userData.pdu.bssmap.clearRequest.cause.causeValue);
5794 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ts_BSSMAP_ClearCommand(cause)));
5795
5796 /* expect BSC to disable the channel */
Harald Welte641fcbe2018-06-14 10:58:35 +02005797 f_exp_chan_rel_and_clear(dt, 0);
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01005798 }
5799
5800 /* In the buggy behavior, a timeout of 2 seconds happens between above
5801 * trigger (logs "SIGTRAN connection down, reconnecting...") and the
5802 * actual BSSMAP Reset. Wait a bit longer just to make sure. */
5803 f_sleep(4.0);
5804
5805 deactivate(d);
5806 f_shutdown_helper();
5807}
5808
Harald Welte94e0c342018-04-07 11:33:23 +02005809/***********************************************************************
5810 * IPA style dynamic PDCH
5811 ***********************************************************************/
5812
5813private function f_dyn_ipa_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
5814 template (omit) RSL_Cause nack := omit)
5815runs on test_CT {
5816 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
5817 var RSL_Message rsl_unused;
5818 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
5819 f_vty_ts_action("pdch activate", bts_nr, trx_nr, ts_nr);
5820 /* expect the BSC to issue the related RSL command */
5821 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
5822 if (istemplatekind(nack, "omit")) {
5823 /* respond with a related acknowledgement */
5824 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
5825 } else {
5826 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_NACK(chan_nr, valueof(nack)));
5827 }
5828}
5829
5830private function f_dyn_ipa_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
5831 template (omit) RSL_Cause nack := omit)
5832runs on test_CT {
5833 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(ts_nr));
5834 var RSL_Message rsl_unused;
5835 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
5836 f_vty_ts_action("pdch deactivate", bts_nr, trx_nr, ts_nr);
5837 /* expect the BSC to issue the related RSL command */
5838 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_DEACT(chan_nr));
5839 if (istemplatekind(nack, "omit")) {
5840 /* respond with a related acknowledgement */
5841 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_ACK(chan_nr));
5842 } else {
5843 f_ipa_tx(0, ts_RSL_IPA_PDCH_DEACT_NACK(chan_nr, valueof(nack)));
5844 }
5845}
5846
5847private function f_ts_dyn_mode_get(integer bts_nr, integer trx_nr, integer ts_nr)
5848runs on test_CT return charstring {
5849 var charstring cmd, resp;
5850 cmd := "show timeslot "&int2str(bts_nr)&" "&int2str(trx_nr)&" "&int2str(ts_nr);
Stefan Sperlingcff13562018-11-13 15:24:06 +01005851 return f_vty_transceive_match_regexp_retry(BSCVTY, cmd, "*\((*)\)*", 0, 4, 1.0);
Harald Welte94e0c342018-04-07 11:33:23 +02005852}
5853
5854private function f_ts_dyn_mode_assert(integer bts_nr, integer trx_nr, integer ts_nr,
5855 template charstring exp)
5856runs on test_CT {
5857 var charstring mode := f_ts_dyn_mode_get(bts_nr, trx_nr, ts_nr);
5858 if (not match(mode, exp)) {
5859 setverdict(fail, "Unexpected TS Mode: ", mode);
Daniel Willmannafce8662018-07-06 23:11:32 +02005860 mtc.stop;
Harald Welte94e0c342018-04-07 11:33:23 +02005861 }
5862}
5863
5864private function f_ts_set_chcomb(integer bts_nr, integer trx_nr, integer ts_nr, charstring chcomb)
5865runs on test_CT {
5866 f_vty_enter_cfg_ts(BSCVTY, bts_nr, trx_nr, ts_nr);
5867 f_vty_transceive(BSCVTY, "phys_chan_config " & chcomb);
5868 f_vty_transceive(BSCVTY, "end");
5869}
5870
5871private const charstring TCHF_MODE := "TCH/F mode";
5872private const charstring TCHH_MODE := "TCH/H mode";
5873private const charstring PDCH_MODE := "PDCH mode";
5874private const charstring NONE_MODE := "NONE mode";
5875
5876/* Test IPA PDCH activation / deactivation triggered by VTY */
5877testcase TC_dyn_pdch_ipa_act_deact() runs on test_CT {
5878 var RSL_Message rsl_unused;
5879
5880 /* change Timeslot 6 before f_init() starts RSL */
5881 f_init_vty();
5882 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
5883 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5884
5885 f_init(1, false);
5886 f_sleep(1.0);
5887
5888 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
5889
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02005890 log("TCH/F_PDCH pchan starts out in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02005891 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
5892 /* The BSC will activate the dynamic PDCH by default, so confirm that */
5893 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
5894 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
5895 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02005896 log("TCH/F_PDCH pchan, PDCH ACT was ACKed, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02005897 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
5898
5899 /* De-activate it via VTY */
5900 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
5901 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02005902 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02005903 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
5904
5905 /* re-activate it via VTY */
5906 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn);
5907 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02005908 log("TCH/F_PDCH pchan, PDCH ACT via VTY, so now in PDCH mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02005909 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
5910
5911 /* and finally de-activate it again */
5912 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
5913 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02005914 log("TCH/F_PDCH pchan, PDCH DEACT via VTY, so now back in TCH/F mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02005915 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
5916
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02005917 /* clean up config */
5918 f_ts_set_chcomb(0, 0, 6, "PDCH");
5919
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005920 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02005921}
5922
5923/* Test IPA PDCH activation NACK */
5924testcase TC_dyn_pdch_ipa_act_nack() runs on test_CT {
5925 var RSL_Message rsl_unused;
5926
5927 /* change Timeslot 6 before f_init() starts RSL */
5928 f_init_vty();
5929 f_ts_set_chcomb(0, 0, 6, "TCH/F_PDCH");
5930 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
5931
5932 f_init(1, false);
5933 f_sleep(1.0);
5934
5935 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(6));
5936
5937 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
5938 /* The BSC will activate the dynamic PDCH by default, so confirm that */
5939 rsl_unused := f_exp_ipa_rx(0, tr_RSL_IPA_PDCH_ACT(chan_nr));
5940 f_ipa_tx(0, ts_RSL_IPA_PDCH_ACT_ACK(chan_nr, ts_RSL_IE_FrameNumber(2342)));
5941 f_sleep(1.0);
5942 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
5943
5944 /* De-activate it via VTY */
5945 f_dyn_ipa_pdch_deact(0, 0, chan_nr.tn);
5946 f_sleep(1.0);
5947 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
5948
5949 /* re-activate it via VTY, but fail that; check BSC still assumes TCH/F mode */
5950 f_dyn_ipa_pdch_act(0, 0, chan_nr.tn, RSL_ERR_EQUIPMENT_FAIL);
5951 f_sleep(1.0);
5952 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, TCHF_MODE);
5953
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02005954 /* clean up config */
5955 f_ts_set_chcomb(0, 0, 6, "PDCH");
5956
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02005957 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02005958}
5959
5960
5961/***********************************************************************
5962 * Osmocom style dynamic PDCH
5963 ***********************************************************************/
5964
5965private function f_dyn_osmo_pdch_act(integer bts_nr, integer trx_nr, integer ts_nr,
5966 template (omit) RSL_Cause nack := omit)
5967runs on test_CT {
5968 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
5969 var RSL_Message rsl_unused;
5970 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
5971 /* FIXME: no VTY command to activate Osmocom PDCH !! */
5972 /* expect the BSC to issue the related RSL command */
5973 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT(chan_nr, ?));
5974 if (istemplatekind(nack, "omit")) {
5975 /* respond with a related acknowledgement */
5976 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
5977 } else {
5978 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, valueof(nack)));
5979 }
5980}
5981
5982private function f_dyn_osmo_pdch_deact(integer bts_nr, integer trx_nr, integer ts_nr,
5983 template (omit) RSL_Cause nack := omit)
5984runs on test_CT {
5985 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(ts_nr));
5986 var RSL_Message rsl_unused;
5987 /* ask BSC via VTY to activate a given IPA style chan as PDCH */
5988 /* FIXME: no VTY command to activate Osmocom PDCH !! */
5989 /* expect the BSC to issue the related RSL command */
5990 rsl_unused := f_exp_ipa_rx(0, tr_RSL_RF_CHAN_REL(chan_nr));
5991 if (istemplatekind(nack, "omit")) {
5992 /* respond with a related acknowledgement */
5993 f_ipa_tx(0, ts_RSL_RF_CHAN_REL_ACK(chan_nr));
5994 } else {
5995 //f_ipa_tx(0, ts_RSL_RF_CHAN_REL_NACK(chan_nr, valueof(nack)));
5996 }
5997}
5998
5999/* Test Osmocom dyn PDCH activation / deactivation triggered by VTY */
6000testcase TC_dyn_pdch_osmo_act_deact() runs on test_CT {
6001 var RSL_Message rsl_unused;
6002
6003 /* change Timeslot 6 before f_init() starts RSL */
6004 f_init_vty();
6005 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
6006 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6007
6008 f_init(1, false);
6009 f_sleep(1.0);
6010
6011 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
6012
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02006013 log("TCH/F_TCH/H_PDCH pchan starts out in disabled mode:");
Harald Welte94e0c342018-04-07 11:33:23 +02006014 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
6015 /* The BSC will activate the dynamic PDCH by default, so confirm that */
6016 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
6017
6018 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 2342));
6019 f_sleep(1.0);
Neels Hofmeyrda4a6952018-06-14 04:02:49 +02006020 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 +02006021 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, PDCH_MODE);
6022
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02006023 /* clean up config */
6024 f_ts_set_chcomb(0, 0, 6, "PDCH");
6025
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006026 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02006027}
6028
6029/* Test Osmocom dyn PDCH activation NACK behavior */
6030testcase TC_dyn_pdch_osmo_act_nack() runs on test_CT {
6031 var RSL_Message rsl_unused;
6032
6033 /* change Timeslot 6 before f_init() starts RSL */
6034 f_init_vty();
6035 f_ts_set_chcomb(0, 0, 6, "TCH/F_TCH/H_PDCH");
6036 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
6037
6038 f_init(1, false);
6039 f_sleep(1.0);
6040
6041 var RslChannelNr chan_nr := valueof(t_RslChanNr_PDCH(6));
6042
6043 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
6044 /* The BSC will activate the dynamic PDCH by default, so confirm that */
6045 rsl_unused := f_exp_ipa_rx(0, tr_RSL_CHAN_ACT_PDCH(chan_nr, ?));
6046
6047 /* NACK this activation and expect the "show timeslot" mode still to be NONE */
6048 f_ipa_tx(0, ts_RSL_CHAN_ACT_NACK(chan_nr, RSL_ERR_EQUIPMENT_FAIL));
6049 f_sleep(1.0);
6050 f_ts_dyn_mode_assert(0, 0, chan_nr.tn, NONE_MODE);
6051
Neels Hofmeyr887e8f12018-06-27 01:01:55 +02006052 /* clean up config */
6053 f_ts_set_chcomb(0, 0, 6, "PDCH");
6054
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006055 f_shutdown_helper();
Harald Welte94e0c342018-04-07 11:33:23 +02006056}
6057
Stefan Sperling0796a822018-10-05 13:01:39 +02006058testcase TC_chopped_ipa_ping() runs on test_CT {
Stefan Sperling554123f2018-10-09 14:12:30 +02006059 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port, mp_bsc_ctrl_port};
Stefan Sperling0796a822018-10-05 13:01:39 +02006060 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
6061 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
6062 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006063 f_shutdown_helper();
Stefan Sperling0796a822018-10-05 13:01:39 +02006064}
6065
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006066testcase TC_chopped_ipa_payload() runs on test_CT {
6067 const Integers bsc_ipa_ports := {mp_bsc_rsl_port, mp_bsc_oml_port
6068 /* TODO: mp_bsc_ctrl_port does not work yet */};
6069 for (var integer i := 0; i < lengthof(bsc_ipa_ports); i := i + 1) {
6070 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_bsc_ip, bsc_ipa_ports[i], CONNECT_TO_SERVER);
6071 }
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006072 f_shutdown_helper();
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006073}
6074
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01006075/* Verify the BSC sends the MS Power Parameters IE during CHAN ACT to make sure
6076 the BTS does autonomous MS power control loop */
6077testcase TC_assignment_verify_ms_power_params_ie() runs on test_CT {
6078 var MSC_ConnHdlr vc_conn;
6079 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6080 //pars.encr := valueof(t_EncrParams('01'O, f_rnd_octstring(8)));
6081 pars.exp_ms_power_params := true;
6082
6083 f_init(1, true);
6084 f_sleep(1.0);
6085 vc_conn := f_start_handler(refers(f_tc_assignment_fr_a5), pars);
6086 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006087 f_shutdown_helper();
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01006088}
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02006089
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006090/***********************************************************************
6091 * MSC Pooling
6092 ***********************************************************************/
6093
6094function f_tmsi_nri(integer nri_v, octetstring base_tmsi := '42000023'O, integer nri_bitlen := 10) return octetstring
6095{
6096 return int2oct( oct2int(base_tmsi) + bit2int( (int2bit(nri_v, 32) << ( 24 - nri_bitlen)) ),
6097 4);
6098}
6099
6100template MobileIdentityLV ts_MI_TMSI_NRI_LV(integer nri_v, integer nri_bitlen := 10) :=
6101 ts_MI_TMSI_LV(tmsi := f_tmsi_nri(nri_v, nri_bitlen := nri_bitlen));
6102
6103private function f_perform_clear(RSL_DCHAN_PT rsl) runs on MSC_ConnHdlr {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00006104 f_logp(BSCVTY, "MSC instructs BSC to clear channel");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006105 BSSAP.send(ts_BSSMAP_ClearCommand(0));
6106 interleave {
6107 [] rsl.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00006108 f_logp(BSCVTY, "Got RSL RR Release");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006109 }
6110 [] rsl.receive(tr_RSL_DEACT_SACCH(g_chan_nr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00006111 f_logp(BSCVTY, "Got RSL Deact SACCH");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006112 }
6113 [] BSSAP.receive(tr_BSSMAP_ClearComplete) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00006114 f_logp(BSCVTY, "Got BSSMAP Clear Complete");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006115 /* Also drop the SCCP connection */
6116 BSSAP.send(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ);
6117 }
6118 [] rsl.receive(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00006119 f_logp(BSCVTY, "Got RSL RF Chan Rel, sending Rel Ack");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006120 rsl.send(ts_RSL_RF_CHAN_REL_ACK(g_chan_nr));
6121 }
6122 }
6123}
6124
6125private function f_perform_compl_l3(RSL_DCHAN_PT rsl, template PDU_ML3_MS_NW l3_info, boolean do_clear := true)
6126runs on MSC_ConnHdlr {
6127 timer T := 10.0;
6128 var octetstring l3_enc := enc_PDU_ML3_MS_NW(valueof(l3_info));
6129
Neels Hofmeyr767548a2020-08-09 20:26:07 +00006130 f_logp(BSCVTY, "establish channel, send Complete Layer 3 Info");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006131 f_create_bssmap_exp(l3_enc);
6132
6133 /* RSL_Emulation.f_chan_est() on rsl:
6134 * This is basically code dup with s/RSL/rsl from:
6135 * RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
6136 */
6137 var RSL_Message rx_rsl;
6138 var GsmRrMessage rr;
6139
6140 /* request a channel to be established */
6141 rsl.send(ts_RSLDC_ChanRqd(g_pars.ra, g_pars.fn));
6142 /* expect immediate assignment.
6143 * Code dup with s/RSL/rsl from:
6144 * rx_rsl := f_rx_or_fail(tr_RSL_IMM_ASSIGN);
6145 */
6146 timer Tt := 10.0;
6147
6148 /* request a channel to be established */
6149 Tt.start;
6150 alt {
6151 [] rsl.receive(tr_RSL_IMM_ASSIGN) -> value rx_rsl {
6152 Tt.stop;
6153 }
6154 [] rsl.receive {
6155 setverdict(fail, "Unexpected RSL message on DCHAN");
6156 mtc.stop;
6157 }
6158 [] Tt.timeout {
6159 setverdict(fail, "Timeout waiting for RSL on DCHAN");
6160 mtc.stop;
6161 }
6162 }
6163 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
6164 g_chan_nr := rr.payload.imm_ass.chan_desc.chan_nr;
6165 rsl.send(ts_RSL_EST_IND(g_chan_nr, valueof(g_pars.link_id), l3_enc));
6166
6167
Neels Hofmeyr767548a2020-08-09 20:26:07 +00006168 f_logp(BSCVTY, "expect BSSAP Complete Layer 3 Info at MSC");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006169 var template PDU_BSSAP exp_l3_compl;
6170 exp_l3_compl := tr_BSSMAP_ComplL3()
6171 if (g_pars.aoip == false) {
6172 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := omit;
6173 } else {
6174 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := ?;
6175 }
6176
6177 var PDU_BSSAP bssap;
6178 T.start;
6179 alt {
6180 [] BSSAP.receive(exp_l3_compl) -> value bssap {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00006181 f_logp(BSCVTY, "received expected Complete Layer 3 Info at MSC");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006182 log("rx exp_l3_compl = ", bssap);
6183 }
6184 [] BSSAP.receive(tr_BSSMAP_ComplL3) {
6185 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching COMPLETE LAYER 3 INFORMATION");
6186 }
6187 [] T.timeout {
6188 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
6189 }
6190 }
6191
6192 /* start ciphering, if requested */
6193 if (ispresent(g_pars.encr)) {
Neels Hofmeyr767548a2020-08-09 20:26:07 +00006194 f_logp(BSCVTY, "start ciphering");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006195 f_cipher_mode(g_pars.encr.enc_alg, g_pars.encr.enc_key);
6196 }
6197
6198 if (do_clear) {
6199 f_perform_clear(rsl);
6200 }
6201 setverdict(pass);
6202 f_sleep(1.0);
6203}
6204
6205private function f_tc_mscpool_compl_l3(charstring id) runs on MSC_ConnHdlr {
6206 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6207 if (g_pars.mscpool.rsl_idx == 0) {
6208 f_perform_compl_l3(RSL, g_pars.mscpool.l3_info);
6209 } else if (g_pars.mscpool.rsl_idx == 1) {
6210 f_perform_compl_l3(RSL1, g_pars.mscpool.l3_info);
6211 } else if (g_pars.mscpool.rsl_idx == 2) {
6212 f_perform_compl_l3(RSL2, g_pars.mscpool.l3_info);
6213 }
6214}
6215
6216/* Various Complete Layer 3 by IMSI all end up with the first MSC, because the other MSCs are not connected. */
6217private function f_tc_mscpool_L3Compl_on_1_msc(charstring id) runs on MSC_ConnHdlr {
6218 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6219 f_perform_compl_l3(RSL, ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O) );
6220 f_perform_compl_l3(RSL, ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_IMSI_LV('001010000000002'H))) );
6221 f_perform_compl_l3(RSL, ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))) );
6222 f_perform_compl_l3(RSL, ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_IMSI_LV('001010000000004'H))) );
6223}
6224testcase TC_mscpool_L3Compl_on_1_msc() runs on test_CT {
6225
6226 f_init(1, true);
6227 f_sleep(1.0);
6228 var MSC_ConnHdlr vc_conn;
6229 var TestHdlrParams pars := f_gen_test_hdlr_pars();
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006230
6231 f_ctrs_msc_init();
6232
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006233 vc_conn := f_start_handler(refers(f_tc_mscpool_L3Compl_on_1_msc), pars);
6234 vc_conn.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006235
6236 f_ctrs_msc_expect(0, "mscpool:subscr:new", 4);
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006237 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006238}
6239
6240/* Three Layer 3 Complete by IMSI are round-robin'ed across two connected MSCs */
6241/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
6242 * just as well using only RSL. */
6243testcase TC_mscpool_L3Complete_by_imsi_round_robin() runs on test_CT {
6244
6245 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
6246 f_sleep(1.0);
6247
6248 /* Control which MSC gets chosen next by the round-robin, otherwise
6249 * would be randomly affected by which other tests ran before this. */
6250 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
6251
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006252 f_ctrs_msc_init();
6253
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006254 var MSC_ConnHdlr vc_conn1;
6255 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
6256 pars1.mscpool.rsl_idx := 0;
6257 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
6258 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
6259 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006260 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006261
6262 var MSC_ConnHdlr vc_conn2;
6263 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
6264 pars2.mscpool.rsl_idx := 1;
6265 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
6266 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
6267 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006268 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006269
6270 /* Test round-robin wrap to the first MSC */
6271 var MSC_ConnHdlr vc_conn3;
6272 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
6273 pars3.mscpool.rsl_idx := 2;
6274 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
6275 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
6276 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006277 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006278 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006279}
6280
6281/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 0
6282 * (configured in osmo-bsc.cfg). */
6283/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
6284 * just as well using only RSL. */
6285testcase TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() runs on test_CT {
6286
6287 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
6288 f_sleep(1.0);
6289
6290 /* Control which MSC gets chosen next by the round-robin, otherwise
6291 * would be randomly affected by which other tests ran before this. */
6292 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
6293
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006294 f_ctrs_msc_init();
6295
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006296 var MSC_ConnHdlr vc_conn1;
6297 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
6298 pars1.mscpool.rsl_idx := 0;
6299 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
6300 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
6301 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006302 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006303
6304 var MSC_ConnHdlr vc_conn2;
6305 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
6306 pars2.mscpool.rsl_idx := 1;
6307 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
6308 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
6309 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006310 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006311
6312 /* Test round-robin wrap to the first MSC */
6313 var MSC_ConnHdlr vc_conn3;
6314 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
6315 pars3.mscpool.rsl_idx := 2;
6316 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(0)), '00F110'O));
6317 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
6318 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006319 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006320 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006321}
6322
6323/* Three LU by TMSI are round-robin'ed across two connected MSCs, because they contain the NULL-NRI 1
6324 * (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
6325 * NULL-NRI setting is stronger than that. */
6326/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
6327 * just as well using only RSL. */
6328testcase TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() runs on test_CT {
6329
6330 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
6331 f_sleep(1.0);
6332
6333 /* Control which MSC gets chosen next by the round-robin, otherwise
6334 * would be randomly affected by which other tests ran before this. */
6335 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
6336
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006337 f_ctrs_msc_init();
6338
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006339 var MSC_ConnHdlr vc_conn1;
6340 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
6341 pars1.mscpool.rsl_idx := 0;
6342 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
6343 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
6344 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006345 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006346
6347 var MSC_ConnHdlr vc_conn2;
6348 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
6349 pars2.mscpool.rsl_idx := 1;
6350 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
6351 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
6352 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006353 f_ctrs_msc_expect(1, "mscpool:subscr:reattach");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006354
6355 /* Test round-robin wrap to the first MSC */
6356 var MSC_ConnHdlr vc_conn3;
6357 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
6358 pars3.mscpool.rsl_idx := 2;
6359 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(1)), '00F110'O));
6360 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
6361 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006362 f_ctrs_msc_expect(0, "mscpool:subscr:reattach");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006363 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006364}
6365
6366/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI not
6367 * assigned to any MSC (configured in osmo-bsc.cfg). */
6368/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
6369 * just as well using only RSL. */
6370testcase TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() runs on test_CT {
6371
6372 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
6373 f_sleep(1.0);
6374
6375 /* Control which MSC gets chosen next by the round-robin, otherwise
6376 * would be randomly affected by which other tests ran before this. */
6377 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
6378
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006379 f_ctrs_msc_init();
6380
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006381 var MSC_ConnHdlr vc_conn1;
6382 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
6383 pars1.mscpool.rsl_idx := 0;
6384 /* An NRI that is not assigned to any MSC */
6385 pars1.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(1023))));
6386 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
6387 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006388 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006389
6390 var MSC_ConnHdlr vc_conn2;
6391 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
6392 pars2.mscpool.rsl_idx := 1;
6393 /* An NRI that is not assigned to any MSC */
6394 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(768)), '00F110'O));
6395 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
6396 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006397 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006398
6399 /* Test round-robin wrap to the first MSC */
6400 var MSC_ConnHdlr vc_conn3;
6401 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
6402 pars3.mscpool.rsl_idx := 2;
6403 /* An NRI that is not assigned to any MSC */
6404 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, valueof(ts_MI_TMSI_NRI_LV(819))));
6405 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
6406 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006407 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006408 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006409}
6410
6411/* Three Layer 3 Complete by TMSI are round-robin'ed across two connected MSCs, because they contain an NRI
6412 * assigned to an MSC that is currently not connected (configured in osmo-bsc.cfg). */
6413/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
6414 * just as well using only RSL. */
6415testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() runs on test_CT {
6416
6417 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
6418 f_sleep(1.0);
6419
6420 /* Control which MSC gets chosen next by the round-robin, otherwise
6421 * would be randomly affected by which other tests ran before this. */
6422 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
6423
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006424 f_ctrs_msc_init();
6425
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006426 var MSC_ConnHdlr vc_conn1;
6427 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
6428 pars1.mscpool.rsl_idx := 0;
6429 /* An NRI that is assigned to an unconnected MSC */
6430 pars1.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(512))));
6431 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
6432 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006433 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
6434 f_ctrs_msc_add(0, "mscpool:subscr:new");
6435 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006436
6437 var MSC_ConnHdlr vc_conn2;
6438 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
6439 pars2.mscpool.rsl_idx := 1;
6440 /* An NRI that is assigned to an unconnected MSC */
6441 pars2.mscpool.l3_info := valueof(ts_ML3_MO_MM_IMSI_DET_Ind(valueof(ts_MI_TMSI_NRI_LV(767))));
6442 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
6443 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006444 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
6445 f_ctrs_msc_add(1, "mscpool:subscr:new");
6446 f_ctrs_msc_verify();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006447
6448 /* Test round-robin wrap to the first MSC */
6449 var MSC_ConnHdlr vc_conn3;
6450 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
6451 pars3.mscpool.rsl_idx := 2;
6452 /* An NRI that is assigned to an unconnected MSC */
6453 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(750)), '00F110'O));
6454 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
6455 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006456 f_ctrs_msc_add(2, "mscpool:subscr:attach_lost");
6457 f_ctrs_msc_add(0, "mscpool:subscr:new");
6458 f_ctrs_msc_verify();
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006459 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006460}
6461
6462/* Three Layer 3 Complete by TMSI with valid NRI for the second MSC are all directed to the second MSC (configured in
6463 * osmo-bsc.cfg). */
6464/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
6465 * just as well using only RSL. */
6466testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_1() runs on test_CT {
6467
6468 f_init(nr_bts := 3, handler_mode := true, nr_msc := 2);
6469 f_sleep(1.0);
6470
6471 /* All TMSIs in this test point at the second MSC, set the round robin to point at the first MSC to make sure
6472 * this is not using round-robin. */
6473 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
6474
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006475 f_ctrs_msc_init();
6476
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006477 var MSC_ConnHdlr vc_conn1;
6478 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
6479 pars1.mscpool.rsl_idx := 0;
6480 /* An NRI of the second MSC's range (256-511) */
6481 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(256))));
6482 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
6483 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006484 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006485
6486 var MSC_ConnHdlr vc_conn2;
6487 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 1);
6488 pars2.mscpool.rsl_idx := 1;
6489 /* An NRI of the second MSC's range (256-511) */
6490 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(260))));
6491 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
6492 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006493 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006494
6495 var MSC_ConnHdlr vc_conn3;
6496 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
6497 pars3.mscpool.rsl_idx := 2;
6498 /* An NRI of the second MSC's range (256-511) */
6499 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(511)), '00F110'O));
6500 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
6501 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006502 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006503 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006504}
6505
6506/* Layer 3 Complete by TMSI with valid NRI for the third MSC are directed to the third MSC (configured in osmo-bsc.cfg),
6507 * while a round-robin remains unaffected by that. */
6508/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
6509 * just as well using only RSL. */
6510testcase TC_mscpool_L3Complete_by_tmsi_valid_nri_2() runs on test_CT {
6511
6512 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
6513 f_sleep(1.0);
6514
6515 /* All TMSIs in this test point at the third MSC, set the round robin to point at the second MSC to make sure
6516 * this is not using round-robin. */
6517 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
6518
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006519 f_ctrs_msc_init();
6520
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006521 var MSC_ConnHdlr vc_conn1;
6522 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 2);
6523 pars1.mscpool.rsl_idx := 0;
6524 /* An NRI of the third MSC's range (512-767) */
6525 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, valueof(ts_MI_TMSI_NRI_LV(512))));
6526 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
6527 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006528 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006529
6530 var MSC_ConnHdlr vc_conn2;
6531 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
6532 pars2.mscpool.rsl_idx := 1;
6533 /* An NRI of the third MSC's range (512-767) */
6534 pars2.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(678))));
6535 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
6536 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006537 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006538
6539 /* The above forwardings to third MSC have not affected the round robin, which still points at the second MSC */
6540 var MSC_ConnHdlr vc_conn3;
6541 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 1);
6542 pars3.mscpool.rsl_idx := 2;
6543 pars3.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000013'H)), '00F110'O));
6544 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
6545 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006546 f_ctrs_msc_expect(1, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006547 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006548}
6549
6550/* LU with a TMSI but indicating a different PLMN in its previous LAI: ignore the NRI. */
6551/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
6552 * just as well using only RSL. */
6553testcase TC_mscpool_LU_by_tmsi_from_other_PLMN() runs on test_CT {
6554
6555 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
6556 f_sleep(1.0);
6557
6558 /* The TMSIs in this test points at the second MSC, but since it is from a different PLMN, round-robin is used
6559 * instead, and hits msc 0. */
6560 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
6561
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006562 f_ctrs_msc_init();
6563
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006564 /* An NRI of the second MSC's range (256-511), but a PLMN that doesn't match with osmo-bsc.cfg */
6565 var MSC_ConnHdlr vc_conn1;
6566 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
6567 pars1.mscpool.rsl_idx := 0;
6568 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(260)), '99F999'O));
6569 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
6570 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006571 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006572
6573 /* An NRI of the third MSC's range (512-767) and a matching PLMN gets directed by NRI. */
6574 var MSC_ConnHdlr vc_conn2;
6575 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
6576 pars2.mscpool.rsl_idx := 1;
6577 pars2.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_TMSI_NRI_LV(555)), '00F110'O));
6578 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
6579 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006580 f_ctrs_msc_expect(2, "mscpool:subscr:known");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006581 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006582}
6583
6584/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by IMSI, which would be
6585 * round-robined to another MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
6586private function f_tc_mscpool_paging_imsi(charstring id) runs on MSC_ConnHdlr {
6587 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
6588 //cid_list := { cIl_allInBSS := ''O };
6589 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
6590 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
6591 var BSSAP_N_UNITDATA_req paging;
6592 var hexstring imsi := '001010000000123'H;
6593
6594 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6595
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006596 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006597 valueof(ts_BSSMAP_Paging(imsi, cid_list, omit, bssmap_chneed))));
6598 BSSAP.send(paging);
6599
6600 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
6601 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
6602 * channel number is picked here. */
6603 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
6604 f_rslem_register(0, new_chan_nr);
6605 RSL.receive(tr_RSL_PAGING_CMD(tr_MI_IMSI(imsi)));
6606 f_rslem_unregister(0, new_chan_nr);
6607
6608 /* Despite the round robin pointing at the second MSC ('roundrobin next 1'), the earlier Paging for the same IMSI
6609 * causes this Paging Response to go to the first MSC (bssap_idx := 0). */
6610 f_perform_compl_l3(RSL, ts_PAG_RESP(valueof(ts_MI_IMSI_LV(imsi))) );
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006611 f_sleep(1.0);
6612}
6613testcase TC_mscpool_paging_and_response_imsi() runs on test_CT {
6614 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
6615 f_sleep(1.0);
6616
6617 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
6618 * second MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
6619 f_vty_transceive(BSCVTY, "mscpool roundrobin next 1");
6620
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006621 f_ctrs_msc_init();
6622
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006623 var MSC_ConnHdlr vc_conn1;
6624 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
6625 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006626 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
6627 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006628 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_imsi), pars1);
6629 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006630 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006631 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006632}
6633
6634/* Make sure that whichever MSC paged a subscriber will also get the Paging Response. Page by TMSI with an NRI value
6635 * that matches a different MSC, to make sure the Paging->Response relation is stronger than the NRI->MSC mapping. */
6636private function f_tc_mscpool_paging_tmsi(charstring id) runs on MSC_ConnHdlr {
6637 var template BSSMAP_FIELD_CellIdentificationList cid_list := { cIl_CI := { ts_BSSMAP_CI_CI(0) } };
6638 //cid_list := { cIl_allInBSS := ''O };
6639 var RSL_ChanNeeded rsl_chneed := RSL_CHANNEED_SDCCH;
6640 var template BSSMAP_IE_ChannelNeeded bssmap_chneed := ts_BSSMAP_IE_ChanNeeded(int2bit(enum2int(valueof(rsl_chneed)),2));
6641 var integer nri_v := 300; /* <-- second MSC's NRI */
6642 var octetstring tmsi := f_tmsi_nri(nri_v);
6643 var BSSAP_N_UNITDATA_req paging;
6644
6645 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", FR_AMR);
6646
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006647 paging := valueof(ts_BSSAP_UNITDATA_req(g_pars.sccp_addr_bsc, g_pars.sccp_addr_msc,
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006648 valueof(ts_BSSMAP_Paging('001010000000011'H, cid_list, tmsi, bssmap_chneed))));
6649 BSSAP.send(paging);
6650
6651 /* Register any RSL conn so that the Paging Command gets received here. With the current RSL_Emulation's main()
6652 * handling of '[bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD()))' it doesn't matter at all which
6653 * channel number is picked here. */
6654 var RslChannelNr new_chan_nr := valueof(t_RslChanNr0(0, RSL_CHAN_NR_INVALID));
6655 f_rslem_register(0, new_chan_nr);
6656 RSL.receive(tr_RSL_PAGING_CMD(t_MI_TMSI(tmsi)));
6657 f_rslem_unregister(0, new_chan_nr);
6658
6659 /* Despite the NRI matching the second MSC (NRI from 'msc 1' in osmo-bsc.cfg) and round robin pointing at the
6660 * third MSC ('roundrobin next 2'), the earlier Paging for the same TMSI causes this Paging Response to go to
6661 * the first MSC (bssap_idx := 0). */
6662 f_perform_compl_l3(RSL, ts_PAG_RESP(valueof(ts_MI_TMSI_NRI_LV(nri_v))) );
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006663 f_sleep(1.0);
6664}
6665testcase TC_mscpool_paging_and_response_tmsi() runs on test_CT {
6666 f_init(nr_bts := 1, handler_mode := true, nr_msc := 3);
6667 f_sleep(1.0);
6668
6669 /* Testing a Paging on the first MSC to get a Paging Response back to the first MSC. Set round robin to the
6670 * third MSC to make sure we're getting the Paging logic, not a coincidental round robin match. */
6671 f_vty_transceive(BSCVTY, "mscpool roundrobin next 2");
6672
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006673 f_ctrs_msc_init();
6674
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006675 var MSC_ConnHdlr vc_conn1;
6676 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
6677 pars1.mscpool.rsl_idx := 0;
Neels Hofmeyr90f80962020-06-12 16:16:55 +02006678 pars1.sccp_addr_bsc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_peer;
6679 pars1.sccp_addr_msc := g_bssap[pars1.mscpool.bssap_idx].sccp_addr_own;
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006680 vc_conn1 := f_start_handler(refers(f_tc_mscpool_paging_tmsi), pars1);
6681 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006682 f_ctrs_msc_expect(0, "mscpool:subscr:paged");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006683 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006684}
6685
6686/* For round-robin, skip an MSC that has 'no allow-attach' set. */
6687/* FIXME: each run is using a separate RSLem: RSL, RSL1, RSL2. It should work
6688 * just as well using only RSL. */
6689testcase TC_mscpool_no_allow_attach_round_robin() runs on test_CT {
6690
6691 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
6692 f_sleep(1.0);
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00006693 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
6694 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006695
6696 /* Control which MSC gets chosen next by the round-robin, otherwise
6697 * would be randomly affected by which other tests ran before this. */
6698 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
6699
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006700 f_ctrs_msc_init();
6701
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006702 var MSC_ConnHdlr vc_conn1;
6703 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 0);
6704 pars1.mscpool.rsl_idx := 0;
6705 pars1.mscpool.l3_info := valueof(ts_LU_REQ(LU_Type_IMSI_Attach, valueof(ts_MI_IMSI_LV('001010000000001'H)), '00F110'O));
6706 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
6707 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006708 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006709
6710 var MSC_ConnHdlr vc_conn2;
6711 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 2);
6712 pars2.mscpool.rsl_idx := 1;
6713 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
6714 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
6715 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006716 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006717
6718 var MSC_ConnHdlr vc_conn3;
6719 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 0);
6720 pars3.mscpool.rsl_idx := 2;
6721 pars3.mscpool.l3_info := valueof(ts_PAG_RESP(valueof(ts_MI_IMSI_LV('001010000000003'H))));
6722 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
6723 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006724 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006725 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006726}
6727
6728/* An MSC that has 'no allow-attach' set should still serve subscribers that are already attached according to their
6729 * TMSI NRI. */
6730testcase TC_mscpool_no_allow_attach_valid_nri() runs on test_CT {
6731
6732 f_init(nr_bts := 3, handler_mode := true, nr_msc := 3);
6733 f_sleep(1.0);
6734
Neels Hofmeyra460f1f2020-08-09 20:17:03 +00006735 /* Mark the second MSC as offloading, round-robin should skip this MSC now. */
6736 f_vty_msc_allow_attach(BSCVTY, {true, false, true});
6737
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006738 /* Control which MSC gets chosen next by the round-robin, otherwise
6739 * would be randomly affected by which other tests ran before this. */
6740 f_vty_transceive(BSCVTY, "mscpool roundrobin next 0");
6741
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006742 f_ctrs_msc_init();
6743
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006744 /* Round robin points at msc 0, but the valid NRI directs to msc 1, even though msc 1 has 'no allow-attach'. */
6745 var MSC_ConnHdlr vc_conn1;
6746 var TestHdlrParams pars1 := f_gen_test_hdlr_pars(bssap_idx := 1);
6747 pars1.mscpool.rsl_idx := 0;
6748 /* An NRI of the second MSC's range (256-511) */
6749 pars1.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_TMSI_NRI_LV(260))));
6750 vc_conn1 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars1);
6751 vc_conn1.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006752 f_ctrs_msc_expect(1, "mscpool:subscr:known");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006753
6754 var MSC_ConnHdlr vc_conn2;
6755 var TestHdlrParams pars2 := f_gen_test_hdlr_pars(bssap_idx := 0);
6756 pars2.mscpool.rsl_idx := 1;
6757 pars2.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000002'H))));
6758 vc_conn2 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars2);
6759 vc_conn2.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006760 f_ctrs_msc_expect(0, "mscpool:subscr:new");
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006761
6762 var MSC_ConnHdlr vc_conn3;
6763 var TestHdlrParams pars3 := f_gen_test_hdlr_pars(bssap_idx := 2);
6764 pars3.mscpool.rsl_idx := 2;
6765 pars3.mscpool.l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, valueof(ts_MI_IMSI_LV('001010000000003'H))));
6766 vc_conn3 := f_start_handler(refers(f_tc_mscpool_compl_l3), pars3);
6767 vc_conn3.done;
Neels Hofmeyr22c3f792020-06-17 02:49:28 +02006768 f_ctrs_msc_expect(2, "mscpool:subscr:new");
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006769 f_shutdown_helper();
Neels Hofmeyr4f118412020-06-04 15:25:10 +02006770}
6771
Philipp Maier783681c2020-07-16 16:47:06 +02006772/* Allow/Deny emergency calls globally via VTY */
6773private function f_vty_allow_emerg_msc(boolean allow) runs on test_CT {
6774 f_vty_enter_cfg_msc(BSCVTY, 0);
6775 if (allow) {
6776 f_vty_transceive(BSCVTY, "allow-emergency allow");
6777 } else {
6778 f_vty_transceive(BSCVTY, "allow-emergency deny");
6779 }
6780 f_vty_transceive(BSCVTY, "exit");
6781 f_vty_transceive(BSCVTY, "exit");
6782}
6783
6784/* Allow/Deny emergency calls per BTS via VTY */
6785private function f_vty_allow_emerg_bts(boolean allow, integer bts_nr) runs on test_CT {
6786 f_vty_enter_cfg_bts(BSCVTY, bts_nr);
6787 if (allow) {
6788 f_vty_transceive(BSCVTY, "rach emergency call allowed 1");
6789 } else {
6790 f_vty_transceive(BSCVTY, "rach emergency call allowed 0");
6791 }
6792 f_vty_transceive(BSCVTY, "exit");
6793 f_vty_transceive(BSCVTY, "exit");
6794}
6795
6796/* Begin assignmet procedure and send an EMERGENCY SETUP (RR) */
6797private function f_assignment_emerg_setup() runs on MSC_ConnHdlr {
6798 var PDU_ML3_MS_NW emerg_setup;
6799 var octetstring emerg_setup_enc;
6800 var RSL_Message emerg_setup_data_ind;
6801
6802 f_establish_fully(omit, omit);
6803
6804 emerg_setup := valueof(ts_ML3_MO_CC_EMERG_SETUP(1, valueof(ts_Bcap_voice)));
6805 emerg_setup_enc := enc_PDU_ML3_MS_NW(emerg_setup);
6806 emerg_setup_data_ind := valueof(ts_RSL_DATA_IND(g_chan_nr, valueof(ts_RslLinkID_DCCH(0)), emerg_setup_enc));
6807
6808 RSL.send(emerg_setup_data_ind);
6809}
6810
6811/* Test if the EMERGENCY SETUP gets passed on to the MSC via A when EMERGENCY
6812 * CALLS are permitted by the BSC config. */
6813private function f_TC_assignment_emerg_setup_allow(charstring id) runs on MSC_ConnHdlr {
6814 var PDU_BSSAP emerg_setup_data_ind_bssap;
6815 var PDU_ML3_MS_NW emerg_setup;
6816 timer T := 3.0;
6817
6818 f_assignment_emerg_setup()
6819
6820 T.start;
6821 alt {
6822 [] BSSAP.receive(tr_BSSAP_DTAP) -> value emerg_setup_data_ind_bssap {
6823 emerg_setup := dec_PDU_ML3_MS_NW(emerg_setup_data_ind_bssap.pdu.dtap);
6824 if (not isbound(emerg_setup.msgs.cc.emergencySetup)) {
6825 setverdict(fail, "no emergency setup");
6826 }
6827 }
6828 [] BSSAP.receive {
6829 setverdict(fail, "unexpected BSSAP message!");
6830 }
6831 [] T.timeout {
6832 setverdict(fail, "timout waiting for EMERGENCY SETUP!");
6833 }
6834 }
6835
6836 setverdict(pass);
6837}
6838
6839/* Test if the EMERGENCY SETUP gets blocked by the BSC if EMERGENCY CALLS are
6840 * forbidden by the BSC config. */
6841private function f_TC_assignment_emerg_setup_deny(charstring id) runs on MSC_ConnHdlr {
6842 var PDU_BSSAP emerg_setup_data_ind_bssap;
6843 timer T := 3.0;
6844
6845 f_assignment_emerg_setup()
6846
6847 T.start;
6848 alt {
6849 [] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr, ?, decmatch tr_RRM_RR_RELEASE)) {
6850 setverdict(pass);
6851 }
6852 [] RSL.receive {
6853 setverdict(fail, "unexpected RSL message!");
6854 }
6855 [] T.timeout {
6856 setverdict(fail, "timout waiting for RR CHANNEL RELEASE!");
6857 }
6858 }
6859}
6860
6861/* EMERGENCY CALL situation #1, allowed globally and by BTS */
6862testcase TC_assignment_emerg_setup_allow() runs on test_CT {
6863 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6864 var MSC_ConnHdlr vc_conn;
6865
6866 f_init(1, true);
6867 f_sleep(1.0);
6868
6869 f_vty_allow_emerg_msc(true);
6870 f_vty_allow_emerg_bts(true, 0);
6871 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_allow), pars);
6872 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006873 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02006874}
6875
6876/* EMERGENCY CALL situation #2, forbidden globally but allowed by BTS */
6877testcase TC_assignment_emerg_setup_deny_msc() runs on test_CT {
6878 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6879 var MSC_ConnHdlr vc_conn;
6880
6881 f_init(1, true);
6882 f_sleep(1.0);
6883
6884 f_vty_allow_emerg_msc(false);
6885 f_vty_allow_emerg_bts(true, 0);
6886 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
6887 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006888 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02006889}
6890
6891/* EMERGENCY CALL situation #3, allowed globally but forbidden by BTS */
6892testcase TC_assignment_emerg_setup_deny_bts() runs on test_CT {
6893 var TestHdlrParams pars := f_gen_test_hdlr_pars();
6894 var MSC_ConnHdlr vc_conn;
6895
6896 /* Note: This simulates a spec violation by the MS, correct MS
6897 * implementations would not try to establish an emergency call because
6898 * the system information tells in advance that emergency calls are
6899 * not forbidden */
6900
6901 f_init(1, true);
6902 f_sleep(1.0);
6903
6904 f_vty_allow_emerg_msc(true);
6905 f_vty_allow_emerg_bts(false, 0);
6906 vc_conn := f_start_handler(refers(f_TC_assignment_emerg_setup_deny), pars);
6907 vc_conn.done;
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006908 f_shutdown_helper();
Philipp Maier783681c2020-07-16 16:47:06 +02006909}
6910
Philipp Maier82812002020-08-13 18:48:27 +02006911/* Test what happens when an emergency call arrives while all TCH channels are
6912 * busy, the BSC is expected to terminate one call in favor of the incoming
6913 * emergency call */
6914testcase TC_emerg_premption() runs on test_CT {
6915 var ASP_RSL_Unitdata rsl_ud;
6916 var integer i;
6917 var integer chreq_total, chreq_nochan;
6918 var RSL_Message rx_rsl;
6919 var RslChannelNr chan_nr;
6920
6921 f_init(1);
6922 f_sleep(1.0);
6923
6924 f_vty_allow_emerg_msc(true);
6925 f_vty_allow_emerg_bts(true, 0);
6926
6927 /* Fill up all channels on the BTS */
6928 chreq_total := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total");
6929 chreq_nochan := f_ctrl_get_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:no_channel");
6930 for (i := 0; i < NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS; i := i+1) {
6931 chan_nr := f_chreq_act_ack('33'O, i);
6932 }
6933 IPA_RSL[0].clear;
6934 f_ctrl_get_exp_ratectr_abs(IPA_CTRL, "bts", 0, "chreq:total",
6935 chreq_total + NUM_TCHF_PER_BTS + NUM_TCHH_PER_BTS + NUM_SDCCH_PER_BTS);
6936
6937 /* Send Channel request for emegergency call */
6938 f_ipa_tx(0, ts_RSL_CHAN_RQD('A5'O, 23));
6939
6940 /* Expect the BSC to release one (the first) TCH/F on the BTS */
6941 chan_nr := valueof(t_RslChanNr_Bm(1));
6942 f_expect_chan_rel(0, chan_nr, expect_rr_chan_rel := false, expect_rll_rel_req := false);
6943
6944 /* Expect the BSC to send activate/assign the a channel for the emergency call */
6945 rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
6946 chan_nr := rx_rsl.ies[0].body.chan_nr;
6947 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 33));
6948 rx_rsl := f_exp_ipa_rx(0, tr_RSL_IMM_ASSIGN(0));
Philipp Maier104f4c02020-09-11 18:12:18 +02006949
Pau Espin Pedrol6ed083c2020-09-23 14:16:58 +02006950 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07006951}
6952
6953/* Hopping parameters per a timeslot */
Vadim Yanitskiybc6654a2020-09-13 01:27:40 +07006954private type record length(0..64) of GsmArfcn ArfcnList;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07006955private type record FHParamsTs {
6956 boolean enabled,
6957 uint6_t hsn,
6958 uint6_t maio,
6959 ArfcnList ma
6960};
6961
6962/* Hopping parameters per a transceiver */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07006963private type record FHParamsTrx {
6964 GsmArfcn arfcn,
6965 FHParamsTs ts[8]
6966};
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07006967
6968/* Randomly generate the hopping parameters for the given timeslot numbers */
6969private function f_TC_fh_params_gen(template integer tr_tn := (1, 3, 5))
6970runs on test_CT return FHParamsTrx {
6971 var FHParamsTrx fhp;
6972
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07006973 /* Generate a random ARFCN, including ARFCN 0 */
6974 fhp.arfcn := f_rnd_int(3);
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07006975
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07006976 for (var integer tn := 0; tn < 8; tn := tn + 1) {
6977 if (not match(tn, tr_tn)) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07006978 fhp.ts[tn].enabled := false;
6979 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07006980 continue;
6981 }
6982
6983 /* Random HSN / MAIO values: 0..63 */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07006984 fhp.ts[tn].hsn := f_rnd_int(64);
6985 fhp.ts[tn].maio := f_rnd_int(64);
6986 fhp.ts[tn].ma := { };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07006987
6988 /* Random Mobile Allocation (hopping channels) */
6989 var integer ma_len := 2 + f_rnd_int(9); /* 2..10 channels */
6990 var integer step := 3 + f_rnd_int(4); /* 3..6 stepping */
6991 for (var integer i := 1; i <= ma_len; i := i + 1) {
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07006992 fhp.ts[tn].ma := fhp.ts[tn].ma & { i * step };
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07006993 }
6994
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07006995 fhp.ts[tn].enabled := true;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07006996 }
6997
6998 log("f_TC_fh_params_gen(): ", fhp);
6999 return fhp;
7000}
7001
7002/* Make sure that the given Channel Description IE matches the hopping configuration */
7003private function f_TC_fh_params_match_chan_desc(in FHParamsTrx fhp, in ChannelDescription cd)
7004{
7005 var template (present) ChannelDescription tr_cd;
7006 var template (present) MaioHsn tr_maio_hsn;
7007 var uint3_t tn := cd.chan_nr.tn;
7008
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07007009 if (fhp.ts[tn].enabled) {
7010 tr_maio_hsn := tr_HsnMaio(fhp.ts[tn].hsn, fhp.ts[tn].maio);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007011 tr_cd := tr_ChanDescH1(cd.chan_nr, tr_maio_hsn);
7012 } else {
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07007013 tr_cd := tr_ChanDescH0(cd.chan_nr, fhp.arfcn);
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007014 }
7015
7016 if (not match(cd, tr_cd)) {
7017 setverdict(fail, "Channel Description IE does not match: ",
7018 cd, " vs expected ", tr_cd);
7019 }
7020}
7021
7022/* Make sure that the given Mobile Allocation IE matches the hopping configuration */
7023private function f_TC_fh_params_match_ma(in FHParamsTrx fhp, uint3_t tn,
7024 in MobileAllocationLV ma)
7025{
7026 var template MobileAllocationLV tr_ma := f_TC_fh_params_gen_tr_ma(fhp, tn, ma);
7027
7028 if (not match(ma, tr_ma)) {
7029 setverdict(fail, "Mobile Allocation IE does not match (tn := ",
7030 tn, "): ", ma, " vs expected: ", tr_ma);
7031 } else {
7032 setverdict(pass);
7033 }
7034}
7035
7036private function f_TC_fh_params_gen_tr_ma(in FHParamsTrx fhp, uint3_t tn,
7037 in MobileAllocationLV ma)
7038return template MobileAllocationLV {
7039 /* Mobile Allocation IE is expected to be empty if hopping is not enabled */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07007040 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007041 return { len := 0, ma := ''B };
7042 }
7043
7044 var bitstring full_mask := f_pad_bit(''B, 1024, '0'B);
7045 var bitstring slot_mask := f_pad_bit(''B, 1024, '0'B);
7046 var bitstring ma_mask := ''B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007047
7048 /* Compose the full bit-mask (all channels, up to 1024 entries) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07007049 for (var integer i := 0; i < lengthof(fhp.ts); i := i + 1) {
7050 for (var integer j := 0; j < lengthof(fhp.ts[i].ma); j := j + 1) {
7051 if (full_mask[fhp.ts[i].ma[j]] == '1'B)
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007052 { continue; }
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07007053 full_mask[fhp.ts[i].ma[j]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007054 }
7055 }
7056
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07007057 /* Take ARFCN of the TRX itself into account */
7058 full_mask[fhp.arfcn] := '1'B;
7059
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007060 /* Compose a bit-mask for the given timeslot number */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07007061 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
7062 slot_mask[fhp.ts[tn].ma[i]] := '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007063 }
7064
7065 /* Finally, compose the Mobile Allocation bit-mask */
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07007066 for (var integer i := 1; i < lengthof(full_mask); i := i + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007067 if (full_mask[i] != '1'B)
7068 { continue; }
7069
7070 /* FIXME: ma_mask := ma_mask & slot_mask[i]; // triggers a bug in TITAN */
7071 if (slot_mask[i] == '1'B) {
7072 ma_mask := ma_mask & '1'B;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007073 } else {
7074 ma_mask := ma_mask & '0'B;
7075 }
7076 }
7077
Vadim Yanitskiy3e997362020-09-05 21:08:34 +07007078 /* ARFCN 0 (if present) goes to the last position of the bit-mask */
7079 if (full_mask[0] == '1'B) {
7080 /* FIXME: ma_mask := ma_mask & slot_mask[0]; // triggers a bug in TITAN */
7081 if (slot_mask[0] == '1'B) {
7082 ma_mask := ma_mask & '1'B;
7083 } else {
7084 ma_mask := ma_mask & '0'B;
7085 }
7086 }
7087
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007088 /* Ensure that ma_mask is octet-aligned */
Vadim Yanitskiy2aa02522020-09-06 14:05:23 +07007089 var integer ma_mask_len := (lengthof(ma_mask) + 8 - 1) / 8;
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007090 ma_mask := f_pad_bit(ma_mask, ma_mask_len * 8, '0'B);
7091
7092 return { len := ma_mask_len, ma := ma_mask };
7093}
7094
7095/* Configure the hopping parameters in accordance with the given record */
7096private function f_TC_fh_params_set(in FHParamsTrx fhp,
7097 uint8_t bts_nr := 0,
7098 uint8_t trx_nr := 0)
7099runs on test_CT {
7100 /* Enter the configuration node for the given BTS/TRX numbers */
7101 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
7102
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07007103 f_vty_transceive(BSCVTY, "arfcn " & int2str(fhp.arfcn));
7104
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07007105 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007106 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
7107
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07007108 if (not fhp.ts[tn].enabled) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007109 f_vty_transceive(BSCVTY, "hopping enabled 0");
7110 f_vty_transceive(BSCVTY, "exit"); /* go back */
7111 continue;
7112 }
7113
7114 /* Configure HSN / MAIO values */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07007115 f_vty_transceive(BSCVTY, "hopping sequence-number " & int2str(fhp.ts[tn].hsn));
7116 f_vty_transceive(BSCVTY, "hopping maio " & int2str(fhp.ts[tn].maio));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007117
7118 /* Configure the Mobile Allocation (hopping channels) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07007119 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
7120 f_vty_transceive(BSCVTY, "hopping arfcn add " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007121 }
7122
7123 f_vty_transceive(BSCVTY, "hopping enabled 1");
7124 f_vty_transceive(BSCVTY, "exit"); /* go back */
7125 }
7126
7127 f_vty_transceive(BSCVTY, "end");
7128}
7129
7130/* Disable frequency hopping on all timeslots */
7131private function f_TC_fh_params_unset(in FHParamsTrx fhp,
7132 uint8_t bts_nr := 0,
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07007133 uint8_t trx_nr := 0,
7134 GsmArfcn arfcn := 871)
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007135runs on test_CT {
7136 /* Enter the configuration node for the given BTS/TRX numbers */
7137 f_vty_enter_cfg_trx(BSCVTY, bts_nr, trx_nr);
7138
Vadim Yanitskiye7c8c6e2020-09-13 14:33:03 +07007139 f_vty_transceive(BSCVTY, "arfcn " & int2str(arfcn));
7140
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07007141 for (var integer tn := 0; tn < lengthof(fhp.ts); tn := tn + 1) {
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007142 f_vty_transceive(BSCVTY, "timeslot " & int2str(tn));
7143
7144 /* Delete all ARFCNs from the Mobile Allocation (if any) */
Vadim Yanitskiy1b996612020-09-13 13:22:34 +07007145 for (var integer i := 0; i < lengthof(fhp.ts[tn].ma); i := i + 1) {
7146 f_vty_transceive(BSCVTY, "hopping arfcn del " & int2str(fhp.ts[tn].ma[i]));
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007147 }
7148
7149 f_vty_transceive(BSCVTY, "hopping enabled 0");
7150 f_vty_transceive(BSCVTY, "exit"); /* go back */
7151 }
7152
7153 f_vty_transceive(BSCVTY, "end");
7154 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7155}
7156
7157/* Verify presence and correctness of the hopping parameters (HSN, MAIO)
7158 * in the Channel Identification IE of the RSL CHANnel ACTIVation message. */
7159testcase TC_fh_params_chan_activ() runs on test_CT {
7160 var FHParamsTrx fhp := f_TC_fh_params_gen();
7161 var RSL_Message rsl_msg;
7162 var RSL_IE_Body ie;
7163
7164 f_init_vty();
7165
7166 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
7167 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7168
7169 f_init(1);
7170
7171 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
7172 for (var integer i := 0; i < 9; i := i + 1) {
7173 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
7174 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7175
7176 /* Make sure that Channel Identification IE is present */
7177 if (not f_rsl_find_ie(rsl_msg, RSL_IE_CHAN_IDENT, ie)) {
7178 setverdict(fail, "RSL Channel Identification IE is absent");
7179 continue;
7180 }
7181
7182 /* Make sure that hopping parameters (HSN/MAIO) match */
7183 f_TC_fh_params_match_chan_desc(fhp, ie.chan_ident.ch_desc.v);
7184
7185 /* "Mobile Allocation shall be included but empty" - let's check this */
7186 if (ie.chan_ident.ma.v.len != 0) {
7187 setverdict(fail, "Mobile Allocation IE is not empty: ",
7188 ie.chan_ident.ma, ", despite it shall be");
7189 continue;
7190 }
7191 }
7192
7193 /* Disable frequency hopping */
7194 f_TC_fh_params_unset(fhp);
7195
Vadim Yanitskiy21726312020-09-04 01:45:36 +07007196 f_shutdown_helper();
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007197}
7198
7199/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Immediate Assignment */
7200testcase TC_fh_params_imm_ass() runs on test_CT {
7201 var FHParamsTrx fhp := f_TC_fh_params_gen();
7202 var RSL_Message rsl_msg;
7203 var RSL_IE_Body ie;
7204
7205 f_init_vty();
7206
7207 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
7208 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7209
7210 f_init(1);
7211
7212 /* CS domain: 3 (SDCCH/4+CBCH) + 4 (TCH/F) + 2 (TCH/H) channels available */
7213 for (var integer i := 0; i < 9; i := i + 1) {
7214 f_ipa_tx(0, ts_RSL_CHAN_RQD(f_rnd_ra_cs(), 23));
7215 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7216
7217 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
7218 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeC(RSL_MT_IMMEDIATE_ASSIGN_CMD));
7219
7220 /* Make sure that Full Immediate Assign Info IE is present */
7221 if (not f_rsl_find_ie(rsl_msg, RSL_IE_FULL_IMM_ASS_INFO, ie)) {
7222 setverdict(fail, "RSL Full Immediate Assign Info IE is absent");
7223 continue;
7224 }
7225
7226 /* Decode the actual Immediate Assignment message */
7227 var GsmRrMessage rr_msg := dec_GsmRrMessage(ie.full_imm_ass_info.payload);
7228 if (not match(rr_msg.header, t_RrHeader(IMMEDIATE_ASSIGNMENT, ?))) {
7229 setverdict(fail, "Failed to match Immediate Assignment: ", rr_msg);
7230 continue;
7231 }
7232
7233 /* Make sure that hopping parameters (HSN/MAIO) match */
7234 f_TC_fh_params_match_chan_desc(fhp, rr_msg.payload.imm_ass.chan_desc);
7235
7236 /* Make sure that the Mobile Allocation IE matches */
7237 f_TC_fh_params_match_ma(fhp, rr_msg.payload.imm_ass.chan_desc.chan_nr.tn,
7238 rr_msg.payload.imm_ass.mobile_allocation);
7239 }
7240
7241 /* Disable frequency hopping */
7242 f_TC_fh_params_unset(fhp);
Philipp Maier82812002020-08-13 18:48:27 +02007243
Vadim Yanitskiy21726312020-09-04 01:45:36 +07007244 f_shutdown_helper();
Philipp Maier82812002020-08-13 18:48:27 +02007245}
7246
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07007247/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Assignment Command */
7248testcase TC_fh_params_assignment_cmd() runs on test_CT {
7249 var FHParamsTrx fhp := f_TC_fh_params_gen();
7250 var RSL_Message rsl_msg;
7251 var RSL_IE_Body ie;
7252
7253 f_init_vty();
7254
7255 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
7256 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7257
7258 f_init(1);
7259
7260 /* HACK: work around "Couldn't find Expect for CRCX" */
7261 vc_MGCP.stop;
7262
7263 var template PDU_BSSAP ass_cmd := f_gen_ass_req();
7264 ass_cmd.pdu.bssmap.assignmentRequest.codecList := ts_BSSMAP_IE_CodecList({ts_CodecFR});
7265
7266 /* CS domain (TCH): 4 (TCH/F) + 2 (TCH/H) channels available
7267 * NOTE: only 3 SDCCH/4 channels are available on CCCH+SDCCH4+CBCH */
7268 for (var integer i := 0; i < 3; i := i + 1) {
7269 /* Establish a dedicated channel, so we can trigger (late) TCH assignment */
7270 var DchanTuple dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
7271
7272 /* Send a BSSMAP Assignment Command, expect CHANnel ACTIVation */
7273 BSSAP.send(ts_BSSAP_DATA_req(dt.sccp_conn_id, ass_cmd));
7274 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7275
7276 /* ACKnowledge CHANnel ACTIVation, expect RSL DATA REQuest */
7277 f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
7278 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
7279
7280 /* Make sure that L3 Information IE is present */
7281 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
7282 setverdict(fail, "RSL L3 Information IE is absent");
7283 continue;
7284 }
7285
7286 /* Decode the L3 message and make sure it is (RR) Assignment Command */
7287 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
7288 if (not match(l3_msg.header, t_RrL3Header(ASSIGNMENT_COMMAND))) {
7289 setverdict(fail, "Failed to match Assignment Command: ", l3_msg);
7290 continue;
7291 }
7292
7293 /* Make sure that hopping parameters (HSN/MAIO) match */
7294 var ChannelDescription chan_desc := l3_msg.payload.ass_cmd.chan_desc;
7295 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
7296
7297 /* Make sure that Cell Channel Description IE is present if FH is enabled */
7298 if (chan_desc.h and not ispresent(l3_msg.payload.ass_cmd.cell_chan_desc)) {
Vadim Yanitskiy38d069d2020-09-02 17:18:57 +07007299 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07007300 continue;
7301 }
7302
7303 /* Make sure that the Mobile Allocation IE matches (if present) */
7304 var boolean ma_present := ispresent(l3_msg.payload.ass_cmd.mobile_allocation);
7305 if (chan_desc.h and ma_present) {
7306 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
7307 l3_msg.payload.ass_cmd.mobile_allocation.v);
7308 } else if (chan_desc.h and not ma_present) {
7309 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
7310 continue;
7311 } else if (not chan_desc.h and ma_present) {
7312 setverdict(fail, "FH disabled, but Mobile Allocation IE is present");
7313 continue;
7314 }
7315 }
7316
7317 /* Give the IUT some time to release all channels */
7318 f_sleep(3.0);
7319
7320 /* Disable frequency hopping */
7321 f_TC_fh_params_unset(fhp);
7322
Vadim Yanitskiy21726312020-09-04 01:45:36 +07007323 f_shutdown_helper();
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07007324}
7325
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07007326/* Verify the hopping parameters (HSN, MAIO, MA) in (RR) Handover Command */
7327private function f_TC_fh_params_handover_cmd(in FHParamsTrx fhp)
7328runs on test_CT {
7329 var RSL_Message rsl_msg;
7330 var RSL_IE_Body ie;
7331 var DchanTuple dt;
7332
7333 /* Establish a dedicated channel, so we can trigger handover */
7334 dt := f_est_dchan(f_rnd_ra_cs(), 23, f_rnd_octstring(16));
7335
7336 /* Trigger handover from BTS0 to BTS1 */
7337 f_bts_0_cfg(BSCVTY, { "neighbor bts 1" });
7338 f_vty_handover(BSCVTY, 0, 0, dt.rsl_chan_nr, 1);
7339
7340 /* Expect RSL CHANnel ACTIVation on BTS1/TRX0/TS1 */
7341 rsl_msg := f_exp_ipa_rx(1, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV));
7342
7343 /* ACKnowledge channel activation and expect (RR) Handover Command */
7344 f_ipa_tx(1, ts_RSL_CHAN_ACT_ACK(rsl_msg.ies[0].body.chan_nr, 33));
7345 rsl_msg := f_exp_ipa_rx(0, tr_RSL_MsgTypeR(RSL_MT_DATA_REQ));
7346
7347 /* Make sure that L3 Information IE is present */
7348 if (not f_rsl_find_ie(rsl_msg, RSL_IE_L3_INFO, ie)) {
7349 setverdict(fail, "RSL L3 Information IE is absent");
7350 return;
7351 }
7352
7353 /* Decode the L3 message and make sure it is (RR) Handover Command */
7354 var GsmRrL3Message l3_msg := dec_GsmRrL3Message(ie.l3_info.payload);
7355 if (not match(l3_msg.header, t_RrL3Header(HANDOVER_COMMAND))) {
7356 setverdict(fail, "Failed to match Handover Command: ", l3_msg);
7357 return;
7358 }
7359
7360 /* Make sure that we've got SDCCH/8 on TS1 (expected to be hopping) */
7361 var ChannelDescription chan_desc := l3_msg.payload.ho_cmd.chan_desc;
7362 if (not match(chan_desc.chan_nr, t_RslChanNr_SDCCH8(1, ?))) {
7363 setverdict(fail, "Unexpected channel number: ", chan_desc.chan_nr);
7364 return;
7365 }
7366
7367 /* Make sure that hopping parameters (HSN/MAIO) match */
7368 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
7369
7370 /* Make sure that Cell Channel Description IE is present */
7371 if (not ispresent(l3_msg.payload.ho_cmd.cell_chan_desc)) {
7372 setverdict(fail, "FH enabled, but Cell Channel Description IE is absent");
7373 return;
7374 }
7375
7376 /* Make sure that the Mobile Allocation (after time) IE is present and matches */
7377 var boolean ma_present := ispresent(l3_msg.payload.ho_cmd.mobile_allocation);
7378 if (ma_present) {
7379 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
7380 l3_msg.payload.ho_cmd.mobile_allocation.v);
7381 } else {
7382 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
7383 return;
7384 }
7385}
7386testcase TC_fh_params_handover_cmd() runs on test_CT {
7387 var FHParamsTrx fhp := f_TC_fh_params_gen();
7388
7389 f_init_vty();
7390
7391 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8 on BTS1/TRX0 */
7392 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
7393
7394 f_vty_transceive(BSCVTY, "timeslot 0");
7395 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
7396 f_vty_transceive(BSCVTY, "exit"); /* go back */
7397
7398 f_vty_transceive(BSCVTY, "timeslot 1");
7399 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8");
7400 f_vty_transceive(BSCVTY, "end"); /* we're done */
7401
7402 f_TC_fh_params_set(fhp, 1); /* Enable frequency hopping on BTS1 */
7403 f_vty_transceive(BSCVTY, "drop bts connection 1 oml");
7404
7405 f_init(2);
7406
7407 f_TC_fh_params_handover_cmd(fhp);
7408
7409 /* Disable frequency hopping on BTS1 */
7410 f_TC_fh_params_unset(fhp, 1);
7411
7412 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
7413 f_vty_enter_cfg_trx(BSCVTY, bts := 1, trx := 0);
7414
7415 f_vty_transceive(BSCVTY, "timeslot 0");
7416 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
7417 f_vty_transceive(BSCVTY, "exit"); /* go back */
7418
7419 f_vty_transceive(BSCVTY, "timeslot 1");
7420 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
7421 f_vty_transceive(BSCVTY, "end"); /* we're done */
7422
7423 f_shutdown_helper();
7424}
7425
Vadim Yanitskiyca974032020-09-01 07:20:39 +07007426/* Verify the hopping parameters in System Information Type 4 */
7427testcase TC_fh_params_si4_cbch() runs on test_CT {
7428 var FHParamsTrx fhp := f_TC_fh_params_gen(tr_tn := 1);
7429 var ASP_RSL_Unitdata rx_rsl_ud;
7430 timer T := 5.0;
7431
7432 f_init_vty();
7433
7434 /* (Re)configure TS0 as BCCH and TS1 as SDCCH8+CBCH */
7435 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
7436
7437 f_vty_transceive(BSCVTY, "timeslot 0");
7438 f_vty_transceive(BSCVTY, "phys_chan_config ccch");
7439 f_vty_transceive(BSCVTY, "exit"); /* go back */
7440
7441 f_vty_transceive(BSCVTY, "timeslot 1");
7442 f_vty_transceive(BSCVTY, "phys_chan_config sdcch8+cbch");
7443 f_vty_transceive(BSCVTY, "end"); /* we're done */
7444
7445 f_TC_fh_params_set(fhp); /* Enable frequency hopping */
7446 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
7447
7448 f_init(1);
7449
7450 T.start;
7451 alt {
7452 [] IPA_RSL[0].receive(tr_ASP_RSL_UD(tr_RSL_BCCH_INFO(RSL_SYSTEM_INFO_4))) -> value rx_rsl_ud {
7453 var RSL_IE_Body ie := rx_rsl_ud.rsl.ies[2].body; /* FULL BCCH Information IE */
7454 var SystemInformation si := dec_SystemInformation(ie.other.payload);
7455
7456 /* Make sure that what we decoded is System Information Type 4 */
7457 if (si.header.message_type != SYSTEM_INFORMATION_TYPE_4) {
7458 setverdict(fail, "RSL FULL BCCH Information IE contains: ", si);
7459 repeat;
7460 }
7461
7462 /* Make sure that CBCH Channel Description IE is present */
7463 if (not ispresent(si.payload.si4.cbch_chan_desc)) {
7464 setverdict(fail, "CBCH Channel Description IE is absent");
7465 break;
7466 }
7467
7468 /* Finally, check the hopping parameters (HSN, MAIO) */
7469 var ChannelDescription chan_desc := si.payload.si4.cbch_chan_desc.v;
7470 f_TC_fh_params_match_chan_desc(fhp, chan_desc);
7471
7472 /* 3GPP TS 44.018, section 9.1.36.2 "CBCH Mobile Allocation":
7473 * The CBCH Mobile Allocation IE *shall* be present if FH is enabled. */
7474 if (chan_desc.h and not ispresent(si.payload.si4.cbch_mobile_alloc)) {
7475 setverdict(fail, "FH enabled, but Mobile Allocation IE is absent");
7476 break;
7477 } else if (chan_desc.h and ispresent(si.payload.si4.cbch_mobile_alloc)) {
7478 f_TC_fh_params_match_ma(fhp, chan_desc.chan_nr.tn,
7479 si.payload.si4.cbch_mobile_alloc.v);
7480 }
7481 }
7482 [] IPA_RSL[0].receive { repeat; }
7483 [] T.timeout {
7484 setverdict(fail, "Timeout waiting for RSL BCCH INFOrmation (SI4)");
7485 }
7486 }
7487
7488 /* Disable frequency hopping */
7489 f_TC_fh_params_unset(fhp);
7490
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07007491 /* (Re)configure TS0 as CCCH+SDCCH4+CBCH and TS1 as TCH/F */
Vadim Yanitskiyca974032020-09-01 07:20:39 +07007492 f_vty_enter_cfg_trx(BSCVTY, trx := 0);
7493
7494 f_vty_transceive(BSCVTY, "timeslot 0");
Vadim Yanitskiy8bc46012020-09-06 12:38:01 +07007495 f_vty_transceive(BSCVTY, "phys_chan_config ccch+sdcch4+cbch");
Vadim Yanitskiyca974032020-09-01 07:20:39 +07007496 f_vty_transceive(BSCVTY, "exit"); /* go back */
7497
7498 f_vty_transceive(BSCVTY, "timeslot 1");
7499 f_vty_transceive(BSCVTY, "phys_chan_config tch/f");
7500 f_vty_transceive(BSCVTY, "end"); /* we're done */
7501
Vadim Yanitskiy21726312020-09-04 01:45:36 +07007502 f_shutdown_helper();
Vadim Yanitskiyca974032020-09-01 07:20:39 +07007503}
7504
Harald Welte0ea2d5e2018-04-07 21:40:29 +02007505/* Dyn PDCH todo:
7506 * activate OSMO as TCH/F
7507 * activate OSMO as TCH/H
7508 * does the BSC-located PCU socket get the updated INFO?
7509 * what if no PCU is connected at the time?
7510 * is the info correct on delayed PCU (re)connect?
7511 */
Harald Welte94e0c342018-04-07 11:33:23 +02007512
Harald Welte28d943e2017-11-25 15:00:50 +01007513control {
Harald Welte898113b2018-01-31 18:32:21 +01007514 /* CTRL interface testing */
Harald Welte4003d112017-12-09 22:35:39 +01007515 execute( TC_ctrl_msc_connection_status() );
Stefan Sperlingb041b3d2018-01-03 17:14:55 +01007516 execute( TC_ctrl_msc0_connection_status() );
Harald Welte96c94412017-12-09 03:12:45 +01007517 execute( TC_ctrl() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +02007518 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_SCCPlite_SERVER) {
Pau Espin Pedrol5a2d7432019-06-07 19:43:45 +02007519 execute( TC_ctrl_location() );
7520 }
Harald Welte898113b2018-01-31 18:32:21 +01007521
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02007522 execute( TC_si_default() );
Neels Hofmeyr66aeba42020-07-06 02:21:21 +02007523 execute( TC_si2quater_2_earfcns() );
7524 execute( TC_si2quater_3_earfcns() );
7525 execute( TC_si2quater_4_earfcns() );
7526 execute( TC_si2quater_5_earfcns() );
7527 execute( TC_si2quater_6_earfcns() );
Neels Hofmeyrad132f22020-07-08 02:20:16 +02007528 execute( TC_si2quater_12_earfcns() );
7529 execute( TC_si2quater_23_earfcns() );
7530 execute( TC_si2quater_32_earfcns() );
7531 execute( TC_si2quater_33_earfcns() );
7532 execute( TC_si2quater_42_earfcns() );
7533 execute( TC_si2quater_48_earfcns() );
7534 execute( TC_si2quater_49_earfcns() );
Pau Espin Pedrol85a84432020-07-20 18:45:03 +02007535 execute( TC_si_acc_rotate() );
Alexander Couzens4ad3a352020-09-10 22:29:12 +02007536 execute( TC_si_acc_ramp_rotate() );
Neels Hofmeyr5e686dc2020-06-30 01:26:53 +02007537
Harald Welte898113b2018-01-31 18:32:21 +01007538 /* RSL DCHAN Channel ACtivation / Deactivation */
Harald Welteae026692017-12-09 01:03:01 +01007539 execute( TC_chan_act_noreply() );
Harald Welte4003d112017-12-09 22:35:39 +01007540 execute( TC_chan_act_counter() );
Harald Welteae026692017-12-09 01:03:01 +01007541 execute( TC_chan_act_ack_noest() );
Philipp Maier9c60a622020-07-09 15:08:46 +02007542 execute( TC_chan_act_ack_noest_emerg() );
Philipp Maier606f07d2020-08-12 17:21:58 +02007543 execute( TC_chan_rqd_emerg_deny() );
Harald Welteae026692017-12-09 01:03:01 +01007544 execute( TC_chan_act_ack_est_ind_noreply() );
7545 execute( TC_chan_act_ack_est_ind_refused() );
Harald Welte618ef642017-12-14 14:58:20 +01007546 execute( TC_chan_act_nack() );
Harald Welte799c97b2017-12-14 17:50:30 +01007547 execute( TC_chan_exhaustion() );
Vadim Yanitskiy1ff1fdf2018-11-27 01:32:57 +07007548 execute( TC_chan_deact_silence() );
Harald Welte4003d112017-12-09 22:35:39 +01007549 execute( TC_chan_rel_rll_rel_ind() );
7550 execute( TC_chan_rel_conn_fail() );
7551 execute( TC_chan_rel_hard_clear() );
Harald Welte99787102019-02-04 10:41:36 +01007552 execute( TC_chan_rel_hard_clear_csfb() );
Harald Welted8c36cd2017-12-09 23:05:31 +01007553 execute( TC_chan_rel_hard_rlsd() );
Harald Welte550daf92018-06-11 19:22:13 +02007554 execute( TC_chan_rel_hard_rlsd_ms_dead() );
Harald Welte85804d42017-12-10 14:11:58 +01007555 execute( TC_chan_rel_a_reset() );
Pau Espin Pedrolc675b612020-01-09 19:55:40 +01007556 execute( TC_chan_rel_sccp_tiar_timeout() );
Neels Hofmeyr95a5edc2020-07-11 02:57:04 +02007557 execute( TC_chan_rel_rr_cause() );
Harald Welte6f521d82017-12-11 19:52:02 +01007558
Harald Weltecfe2c962017-12-15 12:09:32 +01007559 execute( TC_outbound_connect() );
Harald Welte898113b2018-01-31 18:32:21 +01007560
7561 /* Assignment related */
Harald Welte16a4adf2017-12-14 18:54:01 +01007562 execute( TC_assignment_cic_only() );
Harald Welte235ebf12017-12-15 14:18:16 +01007563 execute( TC_assignment_csd() );
7564 execute( TC_assignment_ctm() );
7565 execute( TC_assignment_sign() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +02007566 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
7567 execute( TC_assignment_aoip_tla_v6() );
7568 }
Harald Welte235ebf12017-12-15 14:18:16 +01007569 execute( TC_assignment_fr_a5_0() );
7570 execute( TC_assignment_fr_a5_1() );
Neels Hofmeyrf246a922020-05-13 02:27:10 +02007571 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Harald Welte8f67d1d2018-05-25 20:38:42 +02007572 execute( TC_assignment_fr_a5_1_codec_missing() );
7573 }
Harald Welte235ebf12017-12-15 14:18:16 +01007574 execute( TC_assignment_fr_a5_3() );
7575 execute( TC_assignment_fr_a5_4() );
Harald Welte3c86ea02018-05-10 22:28:05 +02007576 execute( TC_ciph_mode_a5_0() );
7577 execute( TC_ciph_mode_a5_1() );
7578 execute( TC_ciph_mode_a5_3() );
Harald Welte16a4adf2017-12-14 18:54:01 +01007579
Harald Welte60aa5762018-03-21 19:33:13 +01007580 execute( TC_assignment_codec_fr() );
7581 execute( TC_assignment_codec_hr() );
7582 execute( TC_assignment_codec_efr() );
7583 execute( TC_assignment_codec_amr_f() );
7584 execute( TC_assignment_codec_amr_h() );
Philipp Maier8a581d22019-03-26 18:32:48 +01007585
Neels Hofmeyrf246a922020-05-13 02:27:10 +02007586 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
Philipp Maier8a581d22019-03-26 18:32:48 +01007587 execute( TC_assignment_codec_amr_f_S1() );
7588 execute( TC_assignment_codec_amr_h_S1() );
7589 execute( TC_assignment_codec_amr_f_S124() );
7590 execute( TC_assignment_codec_amr_h_S124() );
7591 execute( TC_assignment_codec_amr_f_S0() );
7592 execute( TC_assignment_codec_amr_f_S02() );
7593 execute( TC_assignment_codec_amr_f_S024() );
7594 execute( TC_assignment_codec_amr_f_S0247() );
7595 execute( TC_assignment_codec_amr_h_S0() );
7596 execute( TC_assignment_codec_amr_h_S02() );
7597 execute( TC_assignment_codec_amr_h_S024() );
7598 execute( TC_assignment_codec_amr_h_S0247() );
7599 execute( TC_assignment_codec_amr_f_S01234567() );
7600 execute( TC_assignment_codec_amr_f_S0234567() );
7601 execute( TC_assignment_codec_amr_f_zero() );
7602 execute( TC_assignment_codec_amr_f_unsupp() );
7603 execute( TC_assignment_codec_amr_h_S7() );
7604 }
Harald Welte60aa5762018-03-21 19:33:13 +01007605
Philipp Maierac09bfc2019-01-08 13:41:39 +01007606 execute( TC_assignment_codec_fr_exhausted_req_hr() );
7607 execute( TC_assignment_codec_fr_exhausted_req_fr() );
7608 execute( TC_assignment_codec_fr_exhausted_req_fr_hr() );
7609 execute( TC_assignment_codec_fr_exhausted_req_hr_fr() );
7610 execute( TC_assignment_codec_hr_exhausted_req_fr() );
7611 execute( TC_assignment_codec_hr_exhausted_req_hr() );
7612 execute( TC_assignment_codec_hr_exhausted_req_hr_fr() );
7613 execute( TC_assignment_codec_hr_exhausted_req_fr_hr() );
7614 execute( TC_assignment_codec_req_hr_fr() );
7615 execute( TC_assignment_codec_req_fr_hr() );
7616
Pau Espin Pedrol58cf6822019-05-28 18:11:33 +02007617 if (mp_enable_osmux_test) {
7618 execute( TC_assignment_osmux() );
7619 }
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +02007620
Harald Welte898113b2018-01-31 18:32:21 +01007621 /* RLL Establish Indication on inactive DCHAN / SAPI */
Harald Welte5cd20ed2017-12-13 21:03:20 +01007622 execute( TC_rll_est_ind_inact_lchan() );
7623 execute( TC_rll_est_ind_inval_sapi1() );
7624 execute( TC_rll_est_ind_inval_sapi3() );
7625 execute( TC_rll_est_ind_inval_sacch() );
7626
Vadim Yanitskiy6ef5dfa2020-08-28 18:04:41 +07007627 /* SAPI N Reject triggered by RLL establishment failures */
7628 execute( TC_rll_rel_ind_sapi_n_reject() );
7629 execute( TC_rll_err_ind_sapi_n_reject() );
7630 execute( TC_rll_timeout_sapi_n_reject() );
7631
Harald Welte898113b2018-01-31 18:32:21 +01007632 /* Paging related tests */
Harald Welte6f521d82017-12-11 19:52:02 +01007633 execute( TC_paging_imsi_nochan() );
7634 execute( TC_paging_tmsi_nochan() );
7635 execute( TC_paging_tmsi_any() );
7636 execute( TC_paging_tmsi_sdcch() );
7637 execute( TC_paging_tmsi_tch_f() );
7638 execute( TC_paging_tmsi_tch_hf() );
7639 execute( TC_paging_imsi_nochan_cgi() );
7640 execute( TC_paging_imsi_nochan_lac_ci() );
7641 execute( TC_paging_imsi_nochan_ci() );
7642 execute( TC_paging_imsi_nochan_lai() );
7643 execute( TC_paging_imsi_nochan_lac() );
7644 execute( TC_paging_imsi_nochan_all() );
Harald Welte751d3eb2018-01-31 15:51:06 +01007645 execute( TC_paging_imsi_nochan_plmn_lac_rnc() );
7646 execute( TC_paging_imsi_nochan_rnc() );
7647 execute( TC_paging_imsi_nochan_lac_rnc() );
7648 execute( TC_paging_imsi_nochan_lacs() );
7649 execute( TC_paging_imsi_nochan_lacs_empty() );
Stefan Sperling049a86e2018-03-20 15:51:00 +01007650 execute( TC_paging_imsi_nochan_cgi_unknown_cid() );
Harald Welte10985002017-12-12 09:29:15 +01007651 execute( TC_paging_imsi_a_reset() );
Harald Weltee65d40e2017-12-13 00:09:06 +01007652 execute( TC_paging_imsi_load() );
Philipp Maier779a7922018-02-16 11:00:37 +01007653 execute( TC_paging_counter() );
Pau Espin Pedrol3466cc52018-11-05 12:41:05 +01007654 execute( TC_paging_resp_unsol() );
Harald Welte4e9b9cc2017-12-14 18:31:02 +01007655
7656 execute( TC_rsl_drop_counter() );
Stefan Sperling830dc9d2018-02-12 21:08:28 +01007657 execute( TC_rsl_unknown_unit_id() );
7658
7659 execute( TC_oml_unknown_unit_id() );
Harald Welte898113b2018-01-31 18:32:21 +01007660
7661 execute( TC_classmark() );
Harald Welteeddf0e92020-06-21 19:42:15 +02007662 execute( TC_common_id() );
Harald Welte898113b2018-01-31 18:32:21 +01007663 execute( TC_unsol_ass_fail() );
Harald Welteea99a002018-01-31 20:46:43 +01007664 execute( TC_unsol_ass_compl() );
Harald Weltefbf9b5e2018-01-31 20:41:23 +01007665 execute( TC_unsol_ho_fail() );
Harald Weltee3bd6582018-01-31 22:51:25 +01007666 execute( TC_err_82_short_msg() );
Harald Weltee9e02e42018-01-31 23:36:25 +01007667 execute( TC_err_84_unknown_msg() );
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01007668
Harald Welte261af4b2018-02-12 21:20:39 +01007669 execute( TC_ho_int() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01007670
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01007671 execute( TC_ho_out_of_this_bsc() );
Neels Hofmeyr61ebb8b2018-10-09 18:28:06 +02007672 execute( TC_ho_out_fail_no_msc_response() );
7673 execute( TC_ho_out_fail_rr_ho_failure() );
Neels Hofmeyrd8a602c2019-07-09 19:46:01 +02007674 execute( TC_ho_out_fail_no_result_after_ho_cmd() );
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01007675
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +01007676 execute( TC_ho_into_this_bsc() );
Pau Espin Pedrol07866632020-09-03 19:10:55 +02007677 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
7678 execute( TC_ho_into_this_bsc_tla_v6() );
7679 }
Neels Hofmeyr20bc3e22018-11-09 01:40:16 +01007680 execute( TC_ho_in_fail_msc_clears() );
7681 execute( TC_ho_in_fail_msc_clears_after_ho_detect() );
7682 execute( TC_ho_in_fail_no_detect() );
7683 execute( TC_ho_in_fail_no_detect2() );
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007684
Neels Hofmeyr91401012019-07-11 00:42:35 +02007685 execute( TC_ho_neighbor_config_1() );
7686 execute( TC_ho_neighbor_config_2() );
7687 execute( TC_ho_neighbor_config_3() );
7688 execute( TC_ho_neighbor_config_4() );
7689 execute( TC_ho_neighbor_config_5() );
7690 execute( TC_ho_neighbor_config_6() );
7691 execute( TC_ho_neighbor_config_7() );
7692
Neels Hofmeyrcdc2d762018-03-12 01:48:11 +01007693 execute( TC_bssap_rlsd_does_not_cause_bssmap_reset() );
Neels Hofmeyr4ff93282018-03-12 04:25:35 +01007694 execute( TC_bssmap_clear_does_not_cause_bssmap_reset() );
Neels Hofmeyrfd445c32018-03-09 15:39:31 +01007695 execute( TC_ms_rel_ind_does_not_cause_bssmap_reset() );
Harald Welte94e0c342018-04-07 11:33:23 +02007696
7697 execute( TC_dyn_pdch_ipa_act_deact() );
7698 execute( TC_dyn_pdch_ipa_act_nack() );
7699 execute( TC_dyn_pdch_osmo_act_deact() );
7700 execute( TC_dyn_pdch_osmo_act_nack() );
Harald Welte99f3ca02018-06-14 13:40:29 +02007701
Stefan Sperling0796a822018-10-05 13:01:39 +02007702 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02007703 execute( TC_chopped_ipa_payload() );
Stefan Sperling0796a822018-10-05 13:01:39 +02007704
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01007705 /* Power control related */
7706 execute( TC_assignment_verify_ms_power_params_ie() );
Neels Hofmeyr4f118412020-06-04 15:25:10 +02007707
7708 /* MSC pooling */
7709 /* FIXME: in SCCPlite, indicating how many MSCs should be connected does currently not work. Since
7710 * RESET->RESET-ACK is unconditionally negotiated for all configured MSCs, they always all appear as connected
7711 * to osmo-bsc. The MSC pooling tests however require disconnecting selected MSCs, and hence don't work out as
7712 * intended on SCCPlite. So for now, run these only for SCCP/M3UA. */
7713 if (mp_bssap_cfg[0].transport == BSSAP_TRANSPORT_AoIP) {
7714 execute( TC_mscpool_L3Compl_on_1_msc() );
7715 execute( TC_mscpool_L3Complete_by_imsi_round_robin() );
7716 execute( TC_mscpool_LU_by_tmsi_null_nri_0_round_robin() );
7717 execute( TC_mscpool_LU_by_tmsi_null_nri_1_round_robin() );
7718 execute( TC_mscpool_L3Complete_by_tmsi_unassigned_nri_round_robin() );
7719 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_msc_not_connected_round_robin() );
7720 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_1() );
7721 execute( TC_mscpool_L3Complete_by_tmsi_valid_nri_2() );
7722 execute( TC_mscpool_LU_by_tmsi_from_other_PLMN() );
7723 execute( TC_mscpool_paging_and_response_imsi() );
7724 execute( TC_mscpool_paging_and_response_tmsi() );
7725 execute( TC_mscpool_no_allow_attach_round_robin() );
7726 execute( TC_mscpool_no_allow_attach_valid_nri() );
7727 }
7728
Harald Welte99f3ca02018-06-14 13:40:29 +02007729 /* at bottom as they might crash OsmoBSC before OS#3182 is fixed */
7730 execute( TC_early_conn_fail() );
7731 execute( TC_late_conn_fail() );
7732
Philipp Maier783681c2020-07-16 16:47:06 +02007733 /* Emergency call handling (deny / allow) */
7734 execute( TC_assignment_emerg_setup_allow() );
7735 execute( TC_assignment_emerg_setup_deny_msc() );
7736 execute( TC_assignment_emerg_setup_deny_bts() );
Philipp Maier82812002020-08-13 18:48:27 +02007737 execute( TC_emerg_premption() );
7738
Vadim Yanitskiy16bbde92020-08-28 05:30:45 +07007739 /* Frequency hopping parameters handling */
7740 execute( TC_fh_params_chan_activ() );
7741 execute( TC_fh_params_imm_ass() );
Vadim Yanitskiyaeb54a22020-09-01 06:25:25 +07007742 execute( TC_fh_params_assignment_cmd() );
Vadim Yanitskiy8f5430d2020-09-02 18:51:38 +07007743 execute( TC_fh_params_handover_cmd() );
Vadim Yanitskiyca974032020-09-01 07:20:39 +07007744 execute( TC_fh_params_si4_cbch() );
Harald Welte28d943e2017-11-25 15:00:50 +01007745}
7746
7747}