blob: 50aaee7dc922fc847555c80720584c4c51adc392 [file] [log] [blame]
Harald Welte70767382018-02-21 12:16:40 +01001module BTS_Tests {
2
Harald Welte14906952019-05-27 09:19:49 +02003/* Integration Tests for OsmoBTS
Harald Welte34b5a952019-05-27 11:54:11 +02004 * (C) 2018-2019 by Harald Welte <laforge@gnumonks.org>
Harald Welte14906952019-05-27 09:19:49 +02005 * contributions by Vadim Yanitskiy and sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
Harald Welte34b5a952019-05-27 11:54:11 +020011 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
Harald Welte14906952019-05-27 09:19:49 +020013 * This test suite tests OsmoBTS by attaching to the external interfaces
14 * such as Abis RSL, PCU, VTY as well as by attaching to a MS L1 implementation
15 * using the L1CTL protocol/interface.
16 *
17 * You can run the tests with
18 * a) osmo-bts-trx + trxcon + fake_trx (without any hardware)
19 * b) any osmo-bts-* + OsmocomBB layer1 + osmocon (with real BTS hardware)
20 * c) osmo-bts-virtual + virt_phy (without any hardware)
21 *
22 * Some of the tests will only run on a subset of those three configurations
23 * due to limitations in the respective L1.
24 */
25
Daniel Willmann0fcc4d32018-10-23 20:32:19 +020026import from Misc_Helpers all;
Harald Welte70767382018-02-21 12:16:40 +010027import from General_Types all;
28import from GSM_Types all;
29import from GSM_RR_Types all;
30import from Osmocom_Types all;
31import from GSM_Types all;
Harald Welte82ccef72018-02-25 16:17:33 +010032import from GSM_SystemInformation all;
Harald Welte70767382018-02-21 12:16:40 +010033import from L1CTL_PortType all;
34import from L1CTL_Types all;
35import from LAPDm_Types all;
Harald Weltead033dc2019-05-25 17:28:16 +020036import from LAPDm_RAW_PT all;
Harald Welte70767382018-02-21 12:16:40 +010037import from Osmocom_CTRL_Adapter all;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020038import from Osmocom_CTRL_Functions all;
Harald Welte70767382018-02-21 12:16:40 +010039
40import from RSL_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010041import from IPA_Types all;
Harald Welte70767382018-02-21 12:16:40 +010042import from IPA_Emulation all;
Stefan Sperling0ec1c262018-10-15 15:12:52 +020043import from IPA_Testing all;
Harald Welte70767382018-02-21 12:16:40 +010044import from RSL_Emulation all;
45
46import from IPL4asp_Types all;
47import from TRXC_Types all;
48import from TRXC_CodecPort all;
49import from TRXC_CodecPort_CtrlFunct all;
50
Harald Welte883340c2018-02-28 18:59:29 +010051import from PCUIF_Types all;
52import from PCUIF_CodecPort all;
Harald Weltea2e0e942019-05-27 18:12:53 +020053import from UD_Types all;
Harald Welte883340c2018-02-28 18:59:29 +010054
Harald Welte7484fc42018-02-24 14:09:45 +010055import from MobileL3_CommonIE_Types all;
Harald Welte68e495b2018-02-25 00:05:57 +010056import from MobileL3_RRM_Types all;
57import from MobileL3_Types all;
58import from L3_Templates all;
Harald Welteeaa9a862019-05-26 23:01:08 +020059import from L3_Common all;
60import from MobileL3_GMM_SM_Types all;
Harald Welte7484fc42018-02-24 14:09:45 +010061
Harald Welte8da48242018-02-27 20:41:32 +010062import from Osmocom_VTY_Functions all;
63import from TELNETasp_PortType all;
Harald Welte2f2b2b72019-05-31 22:24:57 +020064import from BTS_Tests_LAPDm all;
Harald Welte8da48242018-02-27 20:41:32 +010065
Harald Welte505cf9b2018-09-15 17:47:23 +030066friend module BTS_Tests_SMSCB;
Harald Weltead033dc2019-05-25 17:28:16 +020067friend module BTS_Tests_virtphy;
Harald Welte2f2b2b72019-05-31 22:24:57 +020068friend module BTS_Tests_LAPDm;
Harald Welte505cf9b2018-09-15 17:47:23 +030069
Harald Welte70767382018-02-21 12:16:40 +010070/* The tests assume a BTS with the following timeslot configuration:
71 * TS0 : Combined CCCH + SDCCH/4
Harald Welte3d04ae62018-04-04 20:29:05 +020072 * TS1 : TCH/F
73 * TS2 : TCH/F
74 * TS3 : TCH/F_PDCH (IPA Style)
75 * TS4 : TCH/F_TCH/H_PDCH (Osmocom Style)
Harald Welte70767382018-02-21 12:16:40 +010076 * TS5 : TCH/H
77 * TS6 : SDCCH/8
78 * TS7 : PDCH
79 */
80
81modulepar {
82 charstring mp_rsl_ip := "127.0.0.2";
83 integer mp_rsl_port := 3003;
84 integer mp_trx0_arfcn := 871;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +070085 charstring mp_bts_trxc_ip := "127.0.0.1";
86 integer mp_bts_trxc_port := 5701;
Harald Welte883340c2018-02-28 18:59:29 +010087 charstring mp_pcu_socket := PCU_SOCK_DEFAULT;
Neels Hofmeyr6a84b232018-04-03 19:12:36 +020088 charstring mp_ctrl_ip := "127.0.0.1";
89 integer mp_ctrl_port := 4238;
Harald Welte07bd2d22019-05-25 11:03:30 +020090 charstring mp_bsc_ctrl_ip := "127.0.0.1";
91 integer mp_bsc_ctrl_port := 4249;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020092 integer mp_tolerance_rxqual := 1;
93 integer mp_tolerance_rxlev := 3;
94 integer mp_tolerance_timing_offset_256syms := 0;
Pau Espin Pedrol752ffd52018-06-07 13:55:45 +020095 integer mp_rxlev_exp := 57;
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +020096 integer mp_ul_rxlev_exp := 10;
Pau Espin Pedroled359cb2018-09-28 16:08:24 +020097 integer mp_ms_power_level_exp := 7;
Pau Espin Pedrol121724c2018-09-28 15:58:12 +020098 integer mp_ms_actual_ta_exp := 0;
99 integer mp_timing_offset_256syms_exp := 512;
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100100 /* Time to wait for RSL conn from BTS during startup of test */
Philipp Maier12567e42019-04-17 14:10:05 +0200101 float mp_ipa_up_timeout := 15.0;
Philipp Maiere63229e2019-04-26 12:21:37 +0200102 float mp_ipa_up_delay := 0.0;
Harald Weltead033dc2019-05-25 17:28:16 +0200103 /* false for now, as only virtphy supports it, not calypso-l1 nor trxcon */
104 boolean mp_l1_supports_gprs := false;
Harald Welte70767382018-02-21 12:16:40 +0100105}
106
Harald Welte629cc6b2018-03-11 17:19:05 +0100107type record of RslChannelNr ChannelNrs;
108
Harald Welte70767382018-02-21 12:16:40 +0100109type component test_CT extends CTRL_Adapter_CT {
Harald Welte68e495b2018-02-25 00:05:57 +0100110 /* IPA Emulation component underneath RSL */
Harald Welte70767382018-02-21 12:16:40 +0100111 var IPA_Emulation_CT vc_IPA;
Harald Welte68e495b2018-02-25 00:05:57 +0100112 /* RSL Emulation component (for ConnHdlr tests) */
Harald Welte70767382018-02-21 12:16:40 +0100113 var RSL_Emulation_CT vc_RSL;
Harald Welte68e495b2018-02-25 00:05:57 +0100114 /* Direct RSL_CCHAN_PT */
Harald Welte70767382018-02-21 12:16:40 +0100115 port RSL_CCHAN_PT RSL_CCHAN;
Harald Welte68e495b2018-02-25 00:05:57 +0100116
117 /* L1CTL port (for classic tests) */
118 port L1CTL_PT L1CTL;
Harald Welte48494ca2018-02-25 16:59:50 +0100119
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700120 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700121 port TRXC_CODEC_PT BTS_TRXC;
122 var integer g_bts_trxc_conn_id;
Harald Welte54a2a2d2018-02-26 09:14:05 +0100123
Harald Weltef50e3ae2018-09-10 10:27:56 +0200124 /* VTY connections to both BTS and BSC */
Harald Welte8da48242018-02-27 20:41:32 +0100125 port TELNETasp_PT BTSVTY;
Harald Weltef50e3ae2018-09-10 10:27:56 +0200126 port TELNETasp_PT BSCVTY;
Harald Welte8da48242018-02-27 20:41:32 +0100127
Harald Welte883340c2018-02-28 18:59:29 +0100128 /* PCU Interface of BTS */
129 port PCUIF_CODEC_PT PCU;
130 var integer g_pcu_conn_id;
131 /* Last PCU INFO IND we received */
132 var PCUIF_Message g_pcu_last_info;
133
Harald Welte48494ca2018-02-25 16:59:50 +0100134 /* SI configuration */
135 var SystemInformationConfig si_cfg := {
136 bcch_extended := false,
137 si1_present := false,
138 si2bis_present := false,
139 si2ter_present := false,
140 si2quater_present := false,
141 si7_present := false,
142 si8_present := false,
143 si9_present := false,
144 si13_present := false,
145 si13alt_present := false,
146 si15_present := false,
147 si16_present := false,
148 si17_present := false,
149 si2n_present := false,
150 si21_present := false,
151 si22_present := false
152 };
Harald Welte629cc6b2018-03-11 17:19:05 +0100153
154 /* all logical channels available on the BTS */
155 var ChannelNrs g_AllChannels;
Harald Welte0472ab42018-03-12 15:02:26 +0100156 var ChannelNrs g_AllChanTypes;
Harald Welte70767382018-02-21 12:16:40 +0100157}
158
159/* an individual call / channel */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200160type component ConnHdlr extends RSL_DchanHdlr, lapdm_test_CT {
Harald Welte70767382018-02-21 12:16:40 +0100161 port L1CTL_PT L1CTL;
162
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700163 /* Optional TRXC connection to FakeTRX (BTS side) */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700164 port TRXC_CODEC_PT BTS_TRXC;
165 var integer g_bts_trxc_conn_id;
Harald Welte70767382018-02-21 12:16:40 +0100166
167 timer g_Tguard;
168 timer g_Tmeas_exp := 2.0; /* >= 103 SACCH multiframe ~ 500ms */
169
170 var ConnHdlrPars g_pars;
171 var uint8_t g_next_meas_res_nr := 0;
Harald Weltefa45e9e2018-03-10 18:59:03 +0100172 var boolean g_first_meas_res := true;
Harald Weltef26de0b2018-04-04 20:28:05 +0200173
174 /* PCU Interface of BTS */
175 port PCUIF_CODEC_PT PCU;
Harald Welte70767382018-02-21 12:16:40 +0100176}
177
178function f_init_rsl(charstring id) runs on test_CT {
179 vc_IPA := IPA_Emulation_CT.create(id & "-RSL-IPA");
180 vc_RSL := RSL_Emulation_CT.create(id & "-RSL");
181
182 map(vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
183 connect(vc_IPA:IPA_RSL_PORT, vc_RSL:IPA_PT);
184 connect(self:RSL_CCHAN, vc_RSL:CCHAN_PT);
185
186 vc_IPA.start(IPA_Emulation.main_server(mp_rsl_ip, mp_rsl_port));
187 vc_RSL.start(RSL_Emulation.main(false));
188}
189
190type record ConnHdlrPars {
191 RslChannelNr chan_nr,
192 RSL_IE_ChannelMode chan_mode,
193 float t_guard,
Harald Welte0472ab42018-03-12 15:02:26 +0100194 ConnL1Pars l1_pars,
Harald Weltee613f962018-04-18 22:38:16 +0200195 TestSpecUnion spec optional,
196 RSL_IE_EncryptionInfo encr optional
Harald Welte0472ab42018-03-12 15:02:26 +0100197}
198
199/* Test-specific parameters */
200type union TestSpecUnion {
201 RllTestCase rll
Harald Welte70767382018-02-21 12:16:40 +0100202}
203
Harald Welte82ccef72018-02-25 16:17:33 +0100204template (value) RachControlParameters ts_RachCtrl_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100205 max_retrans := RACH_MAX_RETRANS_7,
206 tx_integer := '1001'B, /* 12 slots */
Harald Welte82ccef72018-02-25 16:17:33 +0100207 cell_barr_access := false,
208 re_not_allowed := true,
Harald Welteb9585f82018-03-10 17:18:47 +0100209 acc := '0000010000000000'B
Harald Welte82ccef72018-02-25 16:17:33 +0100210};
211
Harald Weltef10153f2018-02-25 16:34:05 +0100212template (value) CellSelectionParameters ts_CellSelPar_default := {
Harald Welte0fd1fb02018-03-10 17:19:50 +0100213 cell_resel_hyst_2dB := 2,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200214 ms_txpwr_max_cch := mp_ms_power_level_exp,
Harald Weltef10153f2018-02-25 16:34:05 +0100215 acs := '0'B,
216 neci := true,
217 rxlev_access_min := 0
218}
219
220template (value) LocationAreaIdentification ts_LAI_default := {
221 mcc_mnc := '262F42'H,
222 lac := 42
223}
224
Harald Welte7484fc42018-02-24 14:09:45 +0100225/* Default SYSTEM INFORMATION 3 */
Harald Weltef8df4cb2018-03-10 15:15:08 +0100226template (value) SystemInformation ts_SI3_default := {
227 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_3, 18),
Harald Welte7484fc42018-02-24 14:09:45 +0100228 payload := {
229 si3 := {
230 cell_id := 23,
Harald Weltef10153f2018-02-25 16:34:05 +0100231 lai := ts_LAI_default,
Harald Welte7484fc42018-02-24 14:09:45 +0100232 ctrl_chan_desc := {
233 msc_r99 := true,
234 att := true,
235 bs_ag_blks_res := 1,
236 ccch_conf := CCHAN_DESC_1CCCH_COMBINED,
Harald Welte82ccef72018-02-25 16:17:33 +0100237 si22ind := false,
Harald Welte7484fc42018-02-24 14:09:45 +0100238 cbq3 := CBQ3_IU_MODE_NOT_SUPPORTED,
239 spare := '00'B,
240 bs_pa_mfrms := 0, /* 2 multiframes */
241 t3212 := 1 /* 6 minutes */
242 },
Harald Welte82ccef72018-02-25 16:17:33 +0100243 cell_options := {
Harald Welte7484fc42018-02-24 14:09:45 +0100244 dn_ind := false,
245 pwrc := false,
246 dtx := MS_MAY_USE_UL_DTX,
Harald Welte0fd1fb02018-03-10 17:19:50 +0100247 radio_link_tout_div4 := (32/4)-1
Harald Welte7484fc42018-02-24 14:09:45 +0100248 },
Harald Weltef10153f2018-02-25 16:34:05 +0100249 cell_sel_par := ts_CellSelPar_default,
Harald Welte82ccef72018-02-25 16:17:33 +0100250 rach_control := ts_RachCtrl_default,
Harald Weltebe030482019-05-27 22:29:35 +0200251 rest_octets := '2C2B2B2B'O /* GPRS present */
Harald Welte7484fc42018-02-24 14:09:45 +0100252 }
253 }
254}
Harald Welte70767382018-02-21 12:16:40 +0100255
Harald Weltef8df4cb2018-03-10 15:15:08 +0100256template (value) SystemInformation ts_SI2_default := {
257 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_2, 22),
Harald Weltef10153f2018-02-25 16:34:05 +0100258 payload := {
259 si2 := {
260 bcch_freq_list := '00000000000000000000000000000000'O,
261 ncc_permitted := '11111111'B,
262 rach_control := ts_RachCtrl_default
263 }
264 }
265}
266
Harald Weltef8df4cb2018-03-10 15:15:08 +0100267template (value) SystemInformation ts_SI4_default := {
268 header := ts_RrHeader(SYSTEM_INFORMATION_TYPE_4, 12), /* no CBCH / restoct */
Harald Weltef10153f2018-02-25 16:34:05 +0100269 payload := {
270 si4 := {
271 lai := ts_LAI_default,
272 cell_sel_par := ts_CellSelPar_default,
273 rach_control := ts_RachCtrl_default,
274 cbch_chan_desc := omit,
275 cbch_mobile_alloc := omit,
276 rest_octets := ''O
277 }
278 }
279}
280
281function f_rsl_bcch_fill_raw(RSL_IE_SysinfoType rsl_si_type, octetstring si_enc)
282runs on test_CT {
283 log("Setting ", rsl_si_type, ": ", si_enc);
284 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_BCCH_INFO(rsl_si_type, si_enc)));
285}
286
287function f_rsl_bcch_fill(RSL_IE_SysinfoType rsl_si_type, template (value) SystemInformation si_dec)
288runs on test_CT {
289 var octetstring si_enc := enc_SystemInformation(valueof(si_dec));
290 log("Setting ", rsl_si_type, ": ", si_dec);
291 f_rsl_bcch_fill_raw(rsl_si_type, si_enc);
292}
293
Harald Welte505cf9b2018-09-15 17:47:23 +0300294friend function f_init_vty(charstring id) runs on test_CT {
Harald Welte8da48242018-02-27 20:41:32 +0100295 map(self:BTSVTY, system:BTSVTY);
296 f_vty_set_prompts(BTSVTY);
297 f_vty_transceive(BTSVTY, "enable");
298}
299
Harald Welte505cf9b2018-09-15 17:47:23 +0300300friend function f_init_vty_bsc() runs on test_CT {
Harald Weltef50e3ae2018-09-10 10:27:56 +0200301 map(self:BSCVTY, system:BSCVTY);
302 f_vty_set_prompts(BSCVTY, "OsmoBSC");
303 f_vty_transceive(BSCVTY, "enable");
304}
305
Harald Welte883340c2018-02-28 18:59:29 +0100306/* PCU socket may at any time receive a new INFO.ind */
Harald Weltef26de0b2018-04-04 20:28:05 +0200307private altstep as_pcu_info_ind(PCUIF_CODEC_PT pt, integer pcu_conn_id,
308 out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100309 var PCUIF_send_data sd;
Harald Weltef26de0b2018-04-04 20:28:05 +0200310 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(0, ?))) -> value sd {
311 pcu_last_info := sd.data;
Harald Welted378a252018-03-13 17:02:14 +0100312 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200313 [] pt.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(?, ?, ?))) -> value sd {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200314 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Invalid PCU Version/BTS Number received");
Harald Welte883340c2018-02-28 18:59:29 +0100315 }
316}
317
Harald Weltef26de0b2018-04-04 20:28:05 +0200318private function f_init_pcu(PCUIF_CODEC_PT pt, charstring id,
319 out integer pcu_conn_id, out PCUIF_Message pcu_last_info) {
Harald Welte883340c2018-02-28 18:59:29 +0100320 timer T := 2.0;
321 var PCUIF_send_data sd;
Harald Welte84271622018-03-10 17:21:03 +0100322 if (mp_pcu_socket == "") {
Harald Weltef26de0b2018-04-04 20:28:05 +0200323 pcu_conn_id := -1;
Harald Welte84271622018-03-10 17:21:03 +0100324 return;
325 }
Harald Weltef26de0b2018-04-04 20:28:05 +0200326 pcu_conn_id := f_pcuif_connect(pt, mp_pcu_socket);
Harald Welte883340c2018-02-28 18:59:29 +0100327
328 T.start;
329 alt {
Harald Weltef26de0b2018-04-04 20:28:05 +0200330 [] as_pcu_info_ind(pt, pcu_conn_id, pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100331 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200332 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU INFO_IND");
Harald Welte883340c2018-02-28 18:59:29 +0100333 }
334 }
335}
336
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700337private function f_init_trxc(TRXC_CODEC_PT pt, charstring id,
338 out integer trxc_conn_id) {
339 var Result res;
340
341 res := TRXC_CodecPort_CtrlFunct.f_IPL4_connect(pt, mp_bts_trxc_ip, mp_bts_trxc_port,
342 "", -1, -1, { udp := {} }, {});
343 if (not ispresent(res.connId)) {
344 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
345 "Could not connect to the control (TRXC) interface " &
346 "of FakeTRX, check your configuration");
347 }
348 trxc_conn_id := res.connId;
349}
350
Harald Welte70767382018-02-21 12:16:40 +0100351/* global init function */
Harald Welte10474062019-05-30 16:48:17 +0200352function f_init() runs on test_CT {
353 var charstring id := testcasename();
Pau Espin Pedrol315e4712018-11-01 16:27:07 +0100354 timer T := mp_ipa_up_timeout;
Harald Welte629cc6b2018-03-11 17:19:05 +0100355 g_AllChannels := {
356 /* TS 1..4: TCH/F */
357 valueof(ts_RslChanNr_Bm(1)), valueof(ts_RslChanNr_Bm(2)),
358 valueof(ts_RslChanNr_Bm(3)), valueof(ts_RslChanNr_Bm(4)),
359 /* TS 5: TCH/H */
360 valueof(ts_RslChanNr_Lm(5,0)), valueof(ts_RslChanNr_Lm(5,1)),
361 /* TS 0: SDCCH/4 */
362 valueof(ts_RslChanNr_SDCCH4(0,0)), valueof(ts_RslChanNr_SDCCH4(0,1)),
363 valueof(ts_RslChanNr_SDCCH4(0,2)), valueof(ts_RslChanNr_SDCCH4(0,3)),
364 /* TS 6: SDCCH/8 */
365 valueof(ts_RslChanNr_SDCCH8(6,0)), valueof(ts_RslChanNr_SDCCH8(6,1)),
366 valueof(ts_RslChanNr_SDCCH8(6,2)), valueof(ts_RslChanNr_SDCCH8(6,3)),
367 valueof(ts_RslChanNr_SDCCH8(6,4)), valueof(ts_RslChanNr_SDCCH8(6,5)),
368 valueof(ts_RslChanNr_SDCCH8(6,6)), valueof(ts_RslChanNr_SDCCH8(6,7))
369 };
370
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200371 /* FIXME: FACCH/H is unreliable with calypso firmware, see OS#3653 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700372 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrol3dcf38f2018-10-22 14:07:54 +0200373 g_AllChanTypes := {
374 /* TS 1..4: TCH/F */
375 valueof(ts_RslChanNr_Bm(1)),
376 /* TS 5: TCH/H */
377 valueof(ts_RslChanNr_Lm(5,1)),
378 /* TS 0: SDCCH/4 */
379 valueof(ts_RslChanNr_SDCCH4(0,2)),
380 /* TS 6: SDCCH/8 */
381 valueof(ts_RslChanNr_SDCCH8(6,4))
382 };
383 } else {
384 g_AllChanTypes := {
385 /* TS 1..4: TCH/F */
386 valueof(ts_RslChanNr_Bm(1)),
387 /* TS 0: SDCCH/4 */
388 valueof(ts_RslChanNr_SDCCH4(0,2)),
389 /* TS 6: SDCCH/8 */
390 valueof(ts_RslChanNr_SDCCH8(6,4))
391 };
392 }
Harald Welte70767382018-02-21 12:16:40 +0100393 f_init_rsl(id);
Harald Welte83f6dbf2018-06-03 18:26:50 +0200394 T.start;
395 alt {
396 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
397 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200398 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
Harald Welte83f6dbf2018-06-03 18:26:50 +0200399 }
400 }
Harald Welte2d142592018-02-25 13:19:44 +0100401 f_sleep(0.5); /* workaround for OS#3000 */
Harald Welte8da48242018-02-27 20:41:32 +0100402 f_init_vty(id);
Neels Hofmeyr6a84b232018-04-03 19:12:36 +0200403 f_ipa_ctrl_start(mp_ctrl_ip, mp_ctrl_port);
Harald Welte7484fc42018-02-24 14:09:45 +0100404
405 /* Send SI3 to the BTS, it is needed for various computations */
Harald Weltef10153f2018-02-25 16:34:05 +0100406 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
407 /* SI2 + SI4 are required for SI testing as they are mandatory defaults */
408 f_rsl_bcch_fill(RSL_SYSTEM_INFO_2, ts_SI2_default);
409 f_rsl_bcch_fill(RSL_SYSTEM_INFO_4, ts_SI4_default);
Harald Welte57fe8232018-02-26 17:52:50 +0100410
Harald Weltef26de0b2018-04-04 20:28:05 +0200411 map(self:PCU, system:PCU);
412 f_init_pcu(PCU, id, g_pcu_conn_id, g_pcu_last_info);
Harald Welte883340c2018-02-28 18:59:29 +0100413
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700414 if (mp_bts_trxc_port != -1) {
Harald Welte84271622018-03-10 17:21:03 +0100415 var TrxcMessage ret;
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700416
417 /* Init TRXC interface to FakeTRX */
418 map(self:BTS_TRXC, system:BTS_TRXC);
419 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
420
Harald Welte84271622018-03-10 17:21:03 +0100421 /* start with a default moderate timing offset equalling TA=2 */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700422 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(2*256)));
Harald Welte84271622018-03-10 17:21:03 +0100423 }
Philipp Maierd95f3402019-04-18 17:50:52 +0200424
425 /* Wait some extra time to make sure the BTS emits a stable carrier.
426 * (this is only relevant when running the tests with a physical BTS.) */
427 f_sleep(mp_ipa_up_delay);
Harald Welte70767382018-02-21 12:16:40 +0100428}
429
Harald Welte68e495b2018-02-25 00:05:57 +0100430/* Attach L1CTL to master test_CT (classic tests, non-handler mode) */
431function f_init_l1ctl() runs on test_CT {
432 map(self:L1CTL, system:L1CTL);
433 f_connect_reset(L1CTL);
434}
435
Harald Welte70767382018-02-21 12:16:40 +0100436type function void_fn(charstring id) runs on ConnHdlr;
437
438/* create a new test component */
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700439function f_start_handler(void_fn fn, ConnHdlrPars pars,
440 boolean pcu_comp := false,
441 boolean trxc_comp := false)
Harald Welte70767382018-02-21 12:16:40 +0100442runs on test_CT return ConnHdlr {
443 var charstring id := testcasename();
444 var ConnHdlr vc_conn;
445
446 vc_conn := ConnHdlr.create(id);
447 /* connect to RSL Emulation main component */
448 connect(vc_conn:RSL, vc_RSL:CLIENT_PT);
449 connect(vc_conn:RSL_PROC, vc_RSL:RSL_PROC);
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700450
451 /* The ConnHdlr component may want to talk to some ports directly,
452 * so we disconnect it from the test_CT and connect it to the component.
453 * This obviously only works for one component, i.e. no concurrency. */
Harald Weltef26de0b2018-04-04 20:28:05 +0200454 if (pcu_comp) {
Harald Weltef26de0b2018-04-04 20:28:05 +0200455 unmap(self:PCU, system:PCU);
456 map(vc_conn:PCU, system:PCU);
457 }
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700458 if (trxc_comp) {
459 unmap(self:BTS_TRXC, system:BTS_TRXC);
460 map(vc_conn:BTS_TRXC, system:BTS_TRXC);
461 }
Harald Welte70767382018-02-21 12:16:40 +0100462
463 vc_conn.start(f_handler_init(fn, id, pars));
464 return vc_conn;
465}
466
Harald Welte7484fc42018-02-24 14:09:45 +0100467template ASP_RSL_Unitdata ts_RSL_UD(template RSL_Message rsl, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
468 streamId := sid,
469 rsl := rsl
470}
471
472template ASP_RSL_Unitdata tr_RSL_UD(template RSL_Message rsl,
473 template IpaStreamId sid := IPAC_PROTO_RSL_TRX0) := {
474 streamId := sid,
475 rsl := rsl
476}
477
Harald Welte70767382018-02-21 12:16:40 +0100478private altstep as_Tguard() runs on ConnHdlr {
479 [] g_Tguard.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200480 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout");
Harald Welte70767382018-02-21 12:16:40 +0100481 }
482}
483
Harald Welte990a3612019-05-27 14:02:13 +0200484friend function f_l1_tune(L1CTL_PT L1CTL, L1ctlCcchMode ccch_mode := CCCH_MODE_COMBINED) {
485 f_L1CTL_FBSB(L1CTL, { false, mp_trx0_arfcn }, ccch_mode, mp_rxlev_exp);
Harald Welte70767382018-02-21 12:16:40 +0100486}
487
Vadim Yanitskiy2f01fbd2019-06-01 01:32:48 +0700488private function f_trxc_fake_rssi(TRXC_RSSI rssi) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100489 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700490 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_RSSI(rssi)));
Harald Welte70767382018-02-21 12:16:40 +0100491}
492
493private function f_trx_fake_toffs256(int16_t toffs256) runs on ConnHdlr {
Harald Weltef8df4cb2018-03-10 15:15:08 +0100494 var TrxcMessage ret;
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700495 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte70767382018-02-21 12:16:40 +0100496}
497
498/* first function started in ConnHdlr component */
499private function f_handler_init(void_fn fn, charstring id, ConnHdlrPars pars)
500runs on ConnHdlr {
501 g_pars := pars;
502 g_chan_nr := pars.chan_nr;
503
504 map(self:L1CTL, system:L1CTL);
505 f_connect_reset(L1CTL);
506
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +0700507 if (mp_bts_trxc_port != -1) {
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +0700508 f_init_trxc(BTS_TRXC, id, g_bts_trxc_conn_id);
Harald Welte84271622018-03-10 17:21:03 +0100509 }
Harald Welte70767382018-02-21 12:16:40 +0100510
511 g_Tguard.start(pars.t_guard);
512 activate(as_Tguard());
513
514 f_rslem_register(0, pars.chan_nr);
515
516 /* call the user-supplied test case function */
517 fn.apply(id);
518}
519
Harald Welteb1726c92018-03-30 11:56:38 +0200520function f_rsl_transceive_ret(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
521 boolean ignore_other := false)
522runs on ConnHdlr return RSL_Message {
523 var RSL_Message rx;
Harald Welte1eba3742018-02-25 12:48:14 +0100524 timer T := 3.0;
525 RSL.send(tx);
526 T.start;
Harald Welte70767382018-02-21 12:16:40 +0100527 alt {
Harald Welteb1726c92018-03-30 11:56:38 +0200528 [] RSL.receive(exp_rx) -> value rx {
Harald Welte1eba3742018-02-25 12:48:14 +0100529 T.stop;
530 setverdict(pass);
Harald Welte70767382018-02-21 12:16:40 +0100531 }
Harald Welte1eba3742018-02-25 12:48:14 +0100532 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200533 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting " & id);
Harald Welte1eba3742018-02-25 12:48:14 +0100534 }
Harald Welte21240e62018-03-11 21:43:35 +0100535 [not ignore_other] as_l1_sacch();
536 [not ignore_other] as_meas_res();
537 [not ignore_other] as_l1_dcch();
538 [not ignore_other] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200539 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message received");
Harald Welte70767382018-02-21 12:16:40 +0100540 }
Harald Welte21240e62018-03-11 21:43:35 +0100541 [ignore_other] RSL.receive { repeat; }
Harald Welte70767382018-02-21 12:16:40 +0100542 }
Harald Welteb1726c92018-03-30 11:56:38 +0200543 return rx;
544}
545
546function f_rsl_transceive(template RSL_Message tx, template RSL_Message exp_rx, charstring id,
547 boolean ignore_other := false)
548runs on ConnHdlr {
549 var RSL_Message rx := f_rsl_transceive_ret(tx, exp_rx, id, ignore_other);
Harald Welte70767382018-02-21 12:16:40 +0100550}
551
Harald Welte8b01c792019-05-19 22:51:25 +0200552function f_rsl_chan_act(RSL_IE_ChannelMode mode, boolean encr_enable := false, RSL_IE_List more_ies := {},
553 RSL_IE_ActivationType act_type := t_RSL_IE_ActType_IA) runs on ConnHdlr {
554 var RSL_Message ch_act := valueof(ts_RSL_CHAN_ACT(g_chan_nr, mode, act_type));
Harald Weltee613f962018-04-18 22:38:16 +0200555 if (encr_enable) {
556 /* append encryption related IEs, if requested */
557 var RSL_IE_EncryptionInfo encr_info;
558 encr_info := valueof(ts_RSL_IE_EncrInfo(g_pars.encr.alg_id, g_pars.encr.key));
559 ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
560encr_info})) };
561 }
Harald Weltec8d363c2019-05-19 20:36:48 +0200562 ch_act.ies := ch_act.ies & more_ies;
Harald Weltee613f962018-04-18 22:38:16 +0200563 f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
Harald Welte1eba3742018-02-25 12:48:14 +0100564}
565
Harald Welte70767382018-02-21 12:16:40 +0100566function f_rsl_chan_deact() runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +0100567 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
Harald Welte21240e62018-03-11 21:43:35 +0100568 "RF CHAN REL", true);
Harald Welte70767382018-02-21 12:16:40 +0100569}
570
Harald Welte2f2b2b72019-05-31 22:24:57 +0200571friend template ConnHdlrPars t_Pars(template RslChannelNr chan_nr,
Harald Welte70767382018-02-21 12:16:40 +0100572 template RSL_IE_ChannelMode chan_mode,
573 float t_guard := 20.0) := {
574 chan_nr := valueof(chan_nr),
575 chan_mode := valueof(chan_mode),
576 t_guard := t_guard,
577 l1_pars := {
578 dtx_enabled := false,
Harald Welte685d5982018-02-27 20:42:05 +0100579 toa256_enabled := false,
Harald Welte70767382018-02-21 12:16:40 +0100580 meas_ul := {
581 full := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200582 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100583 rxqual := 0
584 },
585 sub := {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +0200586 rxlev := mp_ul_rxlev_exp,
Harald Welte70767382018-02-21 12:16:40 +0100587 rxqual := 0
588 }
589 },
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200590 timing_offset_256syms := mp_timing_offset_256syms_exp,
Harald Welte70767382018-02-21 12:16:40 +0100591 bs_power_level := 0,
Pau Espin Pedroled359cb2018-09-28 16:08:24 +0200592 ms_power_level := mp_ms_power_level_exp,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +0200593 ms_actual_ta := mp_ms_actual_ta_exp
Harald Welte0472ab42018-03-12 15:02:26 +0100594 },
Harald Weltee613f962018-04-18 22:38:16 +0200595 spec := omit,
596 encr := omit
Harald Welte70767382018-02-21 12:16:40 +0100597}
598
Harald Welte93640c62018-02-25 16:59:33 +0100599/***********************************************************************
600 * Channel Activation / Deactivation
601 ***********************************************************************/
602
Harald Welte70767382018-02-21 12:16:40 +0100603/* Stress test: Do 500 channel activations/deactivations in rapid succession */
604function f_TC_chan_act_stress(charstring id) runs on ConnHdlr {
605 for (var integer i := 0; i < 500; i := i+1) {
606 f_rsl_chan_act(g_pars.chan_mode);
607 f_rsl_chan_deact();
608 }
609 setverdict(pass);
610}
611testcase TC_chan_act_stress() runs on test_CT {
612 var ConnHdlr vc_conn;
613 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +0200614 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100615 vc_conn := f_start_handler(refers(f_TC_chan_act_stress), pars);
616 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200617 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100618}
619
620/* Test if re-activation of an already active channel fails as expected */
621function f_TC_chan_act_react(charstring id) runs on ConnHdlr {
622 f_rsl_chan_act(g_pars.chan_mode);
623 /* attempt to activate the same lchan again -> expect reject */
624 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
625 alt {
626 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200627 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK on double activation");
Harald Welte70767382018-02-21 12:16:40 +0100628 }
629 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
630 setverdict(pass);
631 }
632 }
633 f_rsl_chan_deact();
634}
635testcase TC_chan_act_react() runs on test_CT {
636 var ConnHdlr vc_conn;
637 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100638 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100639 vc_conn := f_start_handler(refers(f_TC_chan_act_react), pars);
640 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200641 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100642}
643
644/* Attempt to de-activate a channel that's not active */
645function f_TC_chan_deact_not_active(charstring id) runs on ConnHdlr {
646 timer T := 3.0;
647 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
648 T.start;
649 alt {
650 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
651 setverdict(pass);
652 }
653 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200654 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout expecting RF_CHAN_REL_ACK");
Harald Welte70767382018-02-21 12:16:40 +0100655 }
656 }
657}
658testcase TC_chan_deact_not_active() runs on test_CT {
659 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte294b0a22018-03-10 23:26:48 +0100660 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100661 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_chan_deact_not_active), pars);
662 vc_conn.done;
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200663 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100664}
665
666/* attempt to activate channel with wrong RSL Channel Nr IE; expect NACK */
667function f_TC_chan_act_wrong_nr(charstring id) runs on ConnHdlr {
668 RSL.send(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode));
669 alt {
670 [] RSL.receive(tr_RSL_CHAN_ACT_ACK(g_chan_nr)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200671 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN ACT ACK");
Harald Welte70767382018-02-21 12:16:40 +0100672 }
673 [] RSL.receive(tr_RSL_CHAN_ACT_NACK(g_chan_nr)) {
674 setverdict(pass);
675 }
676 }
677}
678private type record WrongChanNrCase {
679 RslChannelNr chan_nr,
680 charstring description
681}
682private type record of WrongChanNrCase WrongChanNrCases;
683private template WrongChanNrCase t_WCN(template RslChannelNr chan_nr, charstring desc) := {
684 chan_nr := chan_nr,
685 description := desc
686}
687
688testcase TC_chan_act_wrong_nr() runs on test_CT {
689 var ConnHdlr vc_conn;
690 var ConnHdlrPars pars;
691
Harald Welte294b0a22018-03-10 23:26:48 +0100692 f_init();
Harald Welte70767382018-02-21 12:16:40 +0100693
694 var WrongChanNrCases wrong := {
695 valueof(t_WCN(t_RslChanNr_RACH(0), "RACH is not a dedicated channel")),
696 valueof(t_WCN(t_RslChanNr_RACH(1), "RACH doesn't exist on timeslot")),
697 valueof(t_WCN(t_RslChanNr_BCCH(0), "BCCH is not a dedicated channel")),
698 valueof(t_WCN(t_RslChanNr_PCH_AGCH(0), "PCH/AGCH is not a dedicated channel")),
699 valueof(t_WCN(t_RslChanNr_Bm(0), "TS0 cannot be TCH/F")),
700 valueof(t_WCN(t_RslChanNr_Lm(0, 0), "TS0 cannot be TCH/H")),
701 valueof(t_WCN(t_RslChanNr_Lm(0, 1), "TS0 cannot be TCH/H")),
702 valueof(t_WCN(t_RslChanNr_PDCH(0), "TS0 cannot be PDCH")),
703 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 0), "TS0 cannot be SDCCH/8")),
704 valueof(t_WCN(t_RslChanNr_SDCCH8(0, 7), "TS0 cannot be SDCCH/8")),
705 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 0), "TS7 cannot be SDCCH/4")),
706 valueof(t_WCN(t_RslChanNr_SDCCH4(7, 3), "TS7 cannot be SDCCH/4")),
707 valueof(t_WCN(t_RslChanNr_Lm(1, 0), "TS1 cannot be TCH/H"))
708 };
709
710 for (var integer i := 0; i < sizeof(wrong); i := i+1) {
711 pars := valueof(t_Pars(wrong[i].chan_nr, ts_RSL_ChanMode_SIGN));
712 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_nr), pars);
713 vc_conn.done;
714 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200715 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +0100716}
717
Harald Weltee613f962018-04-18 22:38:16 +0200718/* execute the same callback function on a variety of logical channels */
Harald Welte2f2b2b72019-05-31 22:24:57 +0200719friend function f_testmatrix_each_chan(ConnHdlrPars pars, void_fn fn) runs on test_CT {
Harald Weltee613f962018-04-18 22:38:16 +0200720 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +0200721 f_init();
Harald Weltee613f962018-04-18 22:38:16 +0200722
723 /* test on each of the channels we have */
724 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
725 pars.chan_nr := valueof(g_AllChanTypes[i]);
726
727 log(testcasename(), ": XXX Starting on ", g_AllChanTypes[i]);
728 vc_conn := f_start_handler(fn, pars);
729 vc_conn.done;
730 }
731
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200732 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Weltee613f962018-04-18 22:38:16 +0200733}
734
Harald Welte93640c62018-02-25 16:59:33 +0100735/***********************************************************************
Harald Welte629cc6b2018-03-11 17:19:05 +0100736 * SACCH handling
737 ***********************************************************************/
738
739private function f_exp_sacch(boolean exp) runs on ConnHdlr {
740 timer T_sacch := 3.0;
741 T_sacch.start;
742 alt {
743 [not exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200744 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received SACCH when not expecting it");
Harald Welte629cc6b2018-03-11 17:19:05 +0100745 }
746 [not exp] T_sacch.timeout {
747 setverdict(pass);
748 }
749 [exp] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) {
750 setverdict(pass);
751 }
752 [exp] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200753 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH on ", g_chan_nr));
Harald Welte629cc6b2018-03-11 17:19:05 +0100754 }
755 [] L1CTL.receive { repeat; }
756 [] RSL.receive { repeat; }
757 }
758}
759
760/* Test if DEACTIVATE SACCH actualy deactivates its transmission (TS 48.058 4.6) */
761private function f_TC_deact_sacch(charstring id) runs on ConnHdlr {
762 f_l1_tune(L1CTL);
763 RSL.clear;
764
765 /* activate the logical channel */
766 f_est_dchan();
767 L1CTL.clear;
768
769 /* check that SACCH actually are received as expected */
770 f_exp_sacch(true);
771
772 /* deactivate SACCH on the logical channel */
773 RSL.send(ts_RSL_DEACT_SACCH(g_chan_nr));
774 f_sleep(1.0);
775 L1CTL.clear;
776
777 /* check that no SACCH are received anymore */
778 f_exp_sacch(false);
779
780 /* release the channel */
781 f_rsl_chan_deact();
782 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
783}
784testcase TC_deact_sacch() runs on test_CT {
785 var ConnHdlr vc_conn;
786 var ConnHdlrPars pars;
787 f_init();
788 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
789 //for (var integer i := 0; i < 1; i := i+1) {
790 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
791 log(testcasename(), ": Starting for ", g_AllChannels[i]);
792 vc_conn := f_start_handler(refers(f_TC_deact_sacch), pars);
793 vc_conn.done;
794 }
795 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200796 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte629cc6b2018-03-11 17:19:05 +0100797}
798
Harald Welte55700662018-03-12 13:15:43 +0100799/* verify that given SACCH payload is present */
Harald Welteea17b912018-03-11 22:29:31 +0100800private function f_sacch_present(template octetstring l3_exp) runs on ConnHdlr {
801 var L1ctlDlMessage dl;
802 /* check that the specified SI5 value is actually sent */
803 timer T_sacch := 3.0;
804 L1CTL.clear;
805 T_sacch.start;
806 alt {
807 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
808 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
809 if (match(l3, l3_exp)) {
810 setverdict(pass);
811 } else {
812 repeat;
813 }
814 }
815 [] L1CTL.receive { repeat; }
816 [] T_sacch.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200817 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for SACCH ", l3_exp));
Harald Welteea17b912018-03-11 22:29:31 +0100818 }
819 }
820}
821
Harald Welte55700662018-03-12 13:15:43 +0100822/* verify that given SACCH payload is not present */
823private function f_sacch_missing(template octetstring l3_exp) runs on ConnHdlr {
824 var L1ctlDlMessage dl;
825 /* check that the specified SI5 value is actually sent */
826 timer T_sacch := 3.0;
827 L1CTL.clear;
828 T_sacch.start;
829 alt {
830 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(0))) -> value dl {
831 var octetstring l3 := substr(dl.payload.data_ind.payload, 4, 19);
832 if (match(l3, l3_exp)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200833 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected SACCH ", dl));
Harald Welte55700662018-03-12 13:15:43 +0100834 } else {
835 repeat;
836 }
837 }
838 [] L1CTL.receive { repeat; }
839 [] T_sacch.timeout {
840 setverdict(pass);
841 }
842 }
843}
844
Harald Welte629cc6b2018-03-11 17:19:05 +0100845/* Test for default SACCH FILL transmitted in DL SACCH (all channel types) */
Harald Welteea17b912018-03-11 22:29:31 +0100846private function f_TC_sacch_filling(charstring id) runs on ConnHdlr {
847 /* Set a known default SACCH filling for SI5 */
848 var octetstring si5 := f_rnd_octstring(19);
849 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
850
851 f_l1_tune(L1CTL);
852 RSL.clear;
853
854 /* activate the logical channel */
855 f_est_dchan();
856
857 /* check that the specified SI5 value is actually sent */
858 f_sacch_present(si5);
859
860 /* release the channel */
861 RSL.clear;
862 f_rsl_chan_deact();
863 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
864}
865testcase TC_sacch_filling() runs on test_CT {
866 var ConnHdlr vc_conn;
867 var ConnHdlrPars pars;
868 f_init();
869 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
870 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
871 log(testcasename(), ": Starting for ", g_AllChannels[i]);
872 vc_conn := f_start_handler(refers(f_TC_sacch_filling), pars);
873 vc_conn.done;
874 }
875 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200876 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100877}
878
Harald Welte629cc6b2018-03-11 17:19:05 +0100879/* Test for lchan-specific SACCH INFO MODIFY (TS 48.058 4.12) */
Harald Welteea17b912018-03-11 22:29:31 +0100880private function f_TC_sacch_info_mod(charstring id) runs on ConnHdlr {
881 /* Set a known default SACCH filling for SI5 */
882 var octetstring si5 := f_rnd_octstring(19);
883 var octetstring si5_diff := f_rnd_octstring(19);
884 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
885
886 f_l1_tune(L1CTL);
887 RSL.clear;
888
889 log("Activating channel, expecting standard SI5");
890 /* activate the logical channel */
891 f_est_dchan();
892 /* check that the specified SI5 value is actually sent */
893 f_sacch_present(si5);
894
895 /* set channel-specific different SI5 */
896 log("Setting channel specific SACCH INFO, expecting it");
897 RSL.send(ts_RSL_SACCH_INF_MOD(g_chan_nr, RSL_SYSTEM_INFO_5, si5_diff))
898 /* check that the specified lchan-specific value is now used */
899 f_sacch_present(si5_diff);
900
901 /* deactivate the channel and re-activate it, this should result in default SI5 */
902 log("De-activating and re-activating channel, expecting standard SI5");
903 f_rsl_chan_deact();
904 f_rsl_chan_act(valueof(ts_RSL_ChanMode_SIGN));
905 /* Verify that the TRX-wide default SACCH filling is present again */
906 f_sacch_present(si5);
907
908 /* release the channel */
909 RSL.clear;
910 f_rsl_chan_deact();
911 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
912}
913testcase TC_sacch_info_mod() runs on test_CT {
914 var ConnHdlr vc_conn;
915 var ConnHdlrPars pars;
916 f_init();
917 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
918 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
919 log(testcasename(), ": Starting for ", g_AllChannels[i]);
920 vc_conn := f_start_handler(refers(f_TC_sacch_info_mod), pars);
921 vc_conn.done;
922 }
923 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200924 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welteea17b912018-03-11 22:29:31 +0100925}
926
Harald Welte075d84c2018-03-12 13:07:24 +0100927/* Test SACCH scheduling of multiple different SI message types */
928private function f_TC_sacch_multi(charstring id) runs on ConnHdlr {
929 var octetstring si5 := f_rnd_octstring(19);
930 var octetstring si5bis := f_rnd_octstring(19);
931 var octetstring si5ter := f_rnd_octstring(19);
932 var octetstring si6 := f_rnd_octstring(19);
933
934 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
935 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5bis, si5bis));
936 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5ter, si5ter));
937 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
938
939 f_l1_tune(L1CTL);
940 RSL.clear;
941
942 /* activate the logical channel */
943 f_est_dchan();
944 L1CTL.clear;
945
946 /* check that SACCH actually are received as expected */
947 f_sacch_present(si5);
948 f_sacch_present(si5bis);
949 f_sacch_present(si5ter);
950 f_sacch_present(si6);
951
952 /* release the channel */
953 f_rsl_chan_deact();
954 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
955}
956testcase TC_sacch_multi() runs on test_CT {
957 var ConnHdlr vc_conn;
958 var ConnHdlrPars pars;
959 f_init();
960 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
961 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
962 log(testcasename(), ": Starting for ", g_AllChannels[i]);
963 vc_conn := f_start_handler(refers(f_TC_sacch_multi), pars);
964 vc_conn.done;
965 }
966 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +0200967 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte075d84c2018-03-12 13:07:24 +0100968}
969
Harald Welte55700662018-03-12 13:15:43 +0100970/* Test if SACH information is modified as expected */
971private function f_TC_sacch_multi_chg(charstring id) runs on ConnHdlr {
972 var octetstring si5 := f_rnd_octstring(19);
973 var octetstring si6 := f_rnd_octstring(19);
974
975 /* First, configure both SI5 and SI6 to be transmitted */
976 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
977 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
978
979 f_l1_tune(L1CTL);
980 RSL.clear;
981
982 /* activate the logical channel */
983 f_est_dchan();
984 L1CTL.clear;
985
986 /* check that SACCH actually are received as expected */
987 f_sacch_present(si5);
988 f_sacch_present(si6);
989
990 /* disable SI6 */
991 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, ''O));
992
993 /* check that SI5 is still transmitted */
994 f_sacch_present(si5);
995 /* check if SI6 is now gone */
996 f_sacch_missing(si6);
997
998 /* release the channel */
999 f_rsl_chan_deact();
1000 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1001}
1002testcase TC_sacch_multi_chg() runs on test_CT {
1003 var ConnHdlr vc_conn;
1004 var ConnHdlrPars pars;
1005 f_init();
1006 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1007 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1008 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1009 vc_conn := f_start_handler(refers(f_TC_sacch_multi_chg), pars);
1010 vc_conn.done;
1011 }
1012 /* TODO: do the above in parallel, rather than sequentially? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001013 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte55700662018-03-12 13:15:43 +01001014}
1015
Harald Weltec8d363c2019-05-19 20:36:48 +02001016/* Test for SACCH information present in RSL CHAN ACT (overrides FILLING) */
1017private function f_TC_sacch_chan_act(charstring id) runs on ConnHdlr {
1018 var octetstring si5 := f_rnd_octstring(19);
1019 var octetstring si6 := f_rnd_octstring(19);
1020 var octetstring si5_specific := f_rnd_octstring(19);
1021 var octetstring si6_specific := f_rnd_octstring(19);
1022
1023 /* First, configure both SI5 and SI6 to be transmitted */
1024 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, si5));
1025 RSL.send(ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_6, si6));
1026
1027 f_l1_tune(L1CTL);
1028 RSL.clear;
1029
1030 /* activate channel with different SACCH filling */
1031 var RSL_SacchInfo sacch_info := valueof(ts_RSL_SacchInfo({
1032 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_5, si5_specific),
1033 ts_RSL_SacchInfoElem(RSL_SYSTEM_INFO_6, si6_specific)
1034 }));
1035 var RSL_IE_List addl_ies := { valueof(t_RSL_IE(RSL_IE_SACCH_INFO,
1036 RSL_IE_Body:{sacch_info := sacch_info})) };
1037 f_est_dchan(more_ies := addl_ies);
1038
1039 /* check that SACCH actually are received as expected */
1040 f_sacch_present(si5_specific);
1041 f_sacch_present(si6_specific);
1042
1043 /* release the channel */
1044 f_rsl_chan_deact();
1045 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1046}
1047testcase TC_sacch_chan_act() runs on test_CT {
1048 var ConnHdlr vc_conn;
1049 var ConnHdlrPars pars;
1050 f_init();
1051
1052 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1053 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1054 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1055 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act), pars);
1056 vc_conn.done;
1057 }
1058 /* TODO: do the above in parallel, rather than sequentially? */
1059 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1060}
1061
Harald Welte8b01c792019-05-19 22:51:25 +02001062/* verify that SACCH DL transmission is started only if MS power IE present
1063 * see section 4.1.3 of 3GPP TS 48.058 */
1064private function f_TC_sacch_chan_act_ho_async(charstring id) runs on ConnHdlr {
1065 var octetstring si5 := f_rnd_octstring(19);
1066
1067 f_l1_tune(L1CTL);
1068 RSL.clear;
1069
1070 /* Step 1: Activate ASYNC HO channel without MS power IE */
1071
1072 /* Activate channel on BTS side */
1073 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_ASYNC);
1074 /* don't perform immediate assignment here, as we're testing non-IA case */
1075 /* enable dedicated mode */
1076 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1077
1078 /* Verify that no DL SACCH is being received */
1079 f_sacch_missing(?);
1080
1081 f_rsl_chan_deact();
1082 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1083
1084
1085 /* Step 2: Activate ASYNC HO channel with MS power IE */
1086
1087 /* Activate channel on BTS side */
1088 var RSL_IE_List addl_ies := {
1089 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1090 };
1091 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_ASYNC);
1092 /* don't perform immediate assignment here, as we're testing non-IA case */
1093 /* enable dedicated mode */
1094 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1095
1096 /* Verify that DL SACCH is being received */
1097 f_sacch_present(si5);
1098
1099 f_rsl_chan_deact();
1100 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1101}
1102testcase TC_sacch_chan_act_ho_async() runs on test_CT {
1103 var ConnHdlr vc_conn;
1104 var ConnHdlrPars pars;
1105 f_init();
1106
1107 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1108 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1109 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1110 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_async), pars);
1111 vc_conn.done;
1112 }
1113 /* TODO: do the above in parallel, rather than sequentially? */
1114 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1115}
1116
1117/* verify that SACCH DL transmission is started only if TA + MS power IEs present,
1118 * see section 4.1.4 of 3GPP TS 48.058 */
1119private function f_TC_sacch_chan_act_ho_sync(charstring id) runs on ConnHdlr {
1120 var octetstring si5 := f_rnd_octstring(19);
1121 var RSL_IE_List addl_ies;
1122
1123 f_l1_tune(L1CTL);
1124 RSL.clear;
1125
1126 /* Step 1: Activate SYNC HO channel without MS power IE */
1127
1128 /* Activate channel on BTS side */
1129 f_rsl_chan_act(g_pars.chan_mode, act_type := t_RSL_IE_ActType_HO_SYNC);
1130 /* don't perform immediate assignment here, as we're testing non-IA case */
1131 /* enable dedicated mode */
1132 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1133
1134 /* Verify that no DL SACCH is being received */
1135 f_sacch_missing(?);
1136
1137 f_rsl_chan_deact();
1138 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1139
1140
1141 /* Step 2a: Activate SYNC HO channel with only MS power IE */
1142
1143 /* Activate channel on BTS side */
1144 addl_ies := {
1145 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1146 };
1147 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1148 /* don't perform immediate assignment here, as we're testing non-IA case */
1149 /* enable dedicated mode */
1150 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1151
1152 /* Verify that no DL SACCH is being received */
1153 f_sacch_missing(?);
1154
1155 f_rsl_chan_deact();
1156 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1157
1158
1159 /* Step 2b: Activate SYNC HO channel with TA IE */
1160
1161 /* Activate channel on BTS side */
1162 addl_ies := {
1163 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0}))
1164 };
1165 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1166 /* don't perform immediate assignment here, as we're testing non-IA case */
1167 /* enable dedicated mode */
1168 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1169
1170 /* Verify that no DL SACCH is being received */
1171 f_sacch_missing(?);
1172
1173 f_rsl_chan_deact();
1174 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1175
1176
1177 /* Step 3: Activate SYNC HO channel with MS power IE and TA IE */
1178
1179 /* Activate channel on BTS side */
1180 addl_ies := {
1181 valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := 0})),
1182 valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(0)}))
1183 };
1184 f_rsl_chan_act(g_pars.chan_mode, more_ies := addl_ies, act_type := t_RSL_IE_ActType_HO_SYNC);
1185 /* don't perform immediate assignment here, as we're testing non-IA case */
1186 /* enable dedicated mode */
1187 f_L1CTL_DM_EST_REQ(L1CTL, {false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1188
1189 /* Verify that DL SACCH is being received */
1190 f_sacch_present(si5);
1191
1192 f_rsl_chan_deact();
1193 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1194}
1195testcase TC_sacch_chan_act_ho_sync() runs on test_CT {
1196 var ConnHdlr vc_conn;
1197 var ConnHdlrPars pars;
1198 f_init();
1199
1200 for (var integer i := 0; i < sizeof(g_AllChannels); i := i+1) {
1201 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1202 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1203 vc_conn := f_start_handler(refers(f_TC_sacch_chan_act_ho_sync), pars);
1204 vc_conn.done;
1205 }
1206 /* TODO: do the above in parallel, rather than sequentially? */
1207 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1208}
Harald Welte629cc6b2018-03-11 17:19:05 +01001209
1210
1211/***********************************************************************
Harald Welte93640c62018-02-25 16:59:33 +01001212 * RACH Handling
1213 ***********************************************************************/
1214
Harald Welte8c24c2b2018-02-26 08:31:31 +01001215/* like L1SAP_IS_PACKET_RACH */
1216private function ra_is_ps(OCT1 ra) return boolean {
Harald Welte56c05802018-02-28 21:39:35 +01001217 if ((ra and4b 'F0'O == '70'O) and (ra and4b '0F'O != '0F'O)) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001218 return true;
1219 }
1220 return false;
1221}
1222
1223/* generate a random RACH for circuit-switched */
1224private function f_rnd_ra_cs() return OCT1 {
1225 var OCT1 ra;
1226 do {
1227 ra := f_rnd_octstring(1);
1228 } while (ra_is_ps(ra));
1229 return ra;
1230}
1231
Harald Welte883340c2018-02-28 18:59:29 +01001232/* generate a random RACH for packet-switched */
1233private function f_rnd_ra_ps() return OCT1 {
1234 var OCT1 ra;
1235 do {
1236 ra := f_rnd_octstring(1);
1237 } while (not ra_is_ps(ra));
1238 return ra;
1239}
1240
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07001241/* generate a random 11-bit RA (packet-switched only) */
1242private function f_rnd_ra11_ps() return BIT11 {
1243 var integer ra11 := f_rnd_int(bit2int('11111111111'B));
1244 return int2bit(ra11, 11);
1245}
1246
Harald Welte8c24c2b2018-02-26 08:31:31 +01001247/* Send 1000 RACH requests and check their RA+FN on the RSL side */
1248testcase TC_rach_content() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001249 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001250 f_init_l1ctl();
Harald Welte68e495b2018-02-25 00:05:57 +01001251 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001252
Harald Welte8c24c2b2018-02-26 08:31:31 +01001253 var GsmFrameNumber fn_last := 0;
Maxa199a2e2019-02-25 16:31:11 +01001254 var boolean test_failed := false;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001255 for (var integer i := 0; i < 1000; i := i+1) {
1256 var OCT1 ra := f_rnd_ra_cs();
1257 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1258 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001259 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001260 }
1261 fn_last := fn;
1262
1263 timer T := 5.0;
Harald Welte56c05802018-02-28 21:39:35 +01001264 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001265 alt {
Vadim Yanitskiyab448a52019-05-31 20:24:03 +07001266 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn, t_RslChanNr_RACH(0)))) {
Harald Welte8c24c2b2018-02-26 08:31:31 +01001267 T.stop;
1268 }
Vadim Yanitskiyab448a52019-05-31 20:24:03 +07001269 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?, ?, ?, ?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001270 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected CHAN RQD");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001271 }
1272 [] RSL_CCHAN.receive { repeat; }
1273 [] T.timeout {
Maxa199a2e2019-02-25 16:31:11 +01001274 test_failed := true;
1275 log("[", i, "] Timeout waiting for CHAN RQD FN=", fn, " RA=", ra);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001276 }
1277 }
1278 }
Maxba06feb2019-03-05 10:52:46 +01001279 if (test_failed) {
1280 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Some out of 1000 RACH requests timed out"));
Maxa199a2e2019-02-25 16:31:11 +01001281 }
Maxba06feb2019-03-05 10:52:46 +01001282 setverdict(pass);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001283 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001284}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001285
1286/* Send 1000 RACH Requests (flood ~ 89/s) and count if count(Abis) == count(Um) */
1287testcase TC_rach_count() runs on test_CT {
Harald Welte294b0a22018-03-10 23:26:48 +01001288 f_init();
Harald Welte8c24c2b2018-02-26 08:31:31 +01001289 f_init_l1ctl();
Harald Welte294b0a22018-03-10 23:26:48 +01001290 f_sleep(1.0);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001291 f_l1_tune(L1CTL);
1292
1293 var GsmFrameNumber fn_last := 0;
1294 for (var integer i := 0; i < 1000; i := i+1) {
1295 var OCT1 ra := f_rnd_ra_cs();
1296 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1297 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001298 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte8c24c2b2018-02-26 08:31:31 +01001299 }
1300 fn_last := fn;
1301 }
1302 var integer rsl_chrqd := 0;
1303 timer T := 3.0;
Harald Welte56c05802018-02-28 21:39:35 +01001304 T.start;
Harald Welte8c24c2b2018-02-26 08:31:31 +01001305 alt {
1306 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(?,?))) {
1307 rsl_chrqd := rsl_chrqd + 1;
Harald Weltec3a3f452018-02-26 17:37:47 +01001308 f_timer_safe_restart(T);
Harald Welte8c24c2b2018-02-26 08:31:31 +01001309 repeat;
1310 }
1311 [] RSL_CCHAN.receive { repeat; }
1312 [] T.timeout { }
1313 }
1314 if (rsl_chrqd == 1000) {
1315 setverdict(pass);
1316 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001317 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received only ", rsl_chrqd, " out of 1000 RACH"));
Harald Welte8c24c2b2018-02-26 08:31:31 +01001318 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001319 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001320}
1321
Harald Welte3453ab42019-05-24 21:19:58 +02001322private function f_vty_load_ind_thresh(integer period := 10, integer bts_nr := 0) runs on test_CT {
1323 var charstring bts_str := "bts " & int2str(bts_nr);
1324 f_vty_config2(BSCVTY, {"network", bts_str}, "ccch load-indication-threshold " & int2str(period));
1325}
1326
1327/* empirical value: Number of RACH slots per reporting interval (1s) on combined CCCH */
1328private template integer tr_rach_slots_per_interval := (90 .. 130);
1329
1330/* Expect 0 RACH load on an idle BTS that has just started up */
1331testcase TC_rach_load_idle_thresh0() runs on test_CT {
1332 var ASP_RSL_Unitdata rx_ud;
1333
1334 f_init_vty_bsc();
1335 /* send load indications even at 0% load */
1336 f_vty_load_ind_thresh(0);
1337 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1338 f_sleep(2.0);
1339
1340 f_init();
1341
1342 timer T := 5.0;
1343 T.start;
1344 alt {
1345 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, 0, 0))) {
1346 setverdict(pass);
1347 repeat;
1348 }
1349 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1350 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1351 repeat;
1352 }
1353 [] RSL_CCHAN.receive {
1354 repeat;
1355 }
1356 [] T.timeout { }
1357 }
1358
1359 f_vty_load_ind_thresh(10);
1360 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1361}
1362
1363/* Expect no RACH load indications on an idle BTS that has just started up (default threshold 10%) */
1364testcase TC_rach_load_idle_below_thresh() runs on test_CT {
1365 var ASP_RSL_Unitdata rx_ud;
1366
1367 f_init_vty_bsc();
1368 f_init();
1369
1370 timer T := 5.0;
1371 T.start;
1372 alt {
1373 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1374 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1375 repeat;
1376 }
1377 [] RSL_CCHAN.receive {
1378 repeat;
1379 }
1380 [] T.timeout {
1381 setverdict(pass);
1382 }
1383 }
1384
1385 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1386}
1387
1388/* Expect 0 RACH load on an idle BTS that has just started up */
1389testcase TC_rach_load_count() runs on test_CT {
1390 var ASP_RSL_Unitdata rx_ud;
1391 var integer load_access_count := 0;
1392
1393 f_init_vty_bsc();
1394 /* send load indications even at 0% load */
1395 f_vty_load_ind_thresh(0);
1396 f_vty_transceive(BSCVTY, "drop bts connection 0 oml");
1397 f_sleep(2.0);
1398 f_init();
1399
1400 f_init_l1ctl();
1401 f_sleep(1.0);
1402 f_l1_tune(L1CTL);
1403
1404 var GsmFrameNumber fn_last := 0;
1405 for (var integer i := 0; i < 1000; i := i+1) {
1406 var OCT1 ra := f_rnd_ra_cs();
1407 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1408 if (fn == fn_last) {
1409 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
1410 }
1411 fn_last := fn;
1412 }
1413
1414 timer T := 5.0;
1415 T.start;
1416 alt {
1417 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(tr_rach_slots_per_interval, ?, ?)))
1418 -> value rx_ud {
1419 var RSL_IE_Body ie;
1420 f_rsl_find_ie(rx_ud.rsl, RSL_IE_RACH_LOAD, ie);
1421 load_access_count := load_access_count + ie.rach_load.access_count;
1422 if (ie.rach_load.busy_count < ie.rach_load.access_count) {
1423 setverdict(fail, "Access count cannot be < Busy count");
1424 }
1425 repeat;
1426 }
1427 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RACH_LOAD_IND(?, ?, ?))) -> value rx_ud {
1428 setverdict(fail, "Unexpected RACH LOAD IND: ", rx_ud);
1429 repeat;
1430 }
1431 [] RSL_CCHAN.receive {
1432 repeat;
1433 }
1434 [] T.timeout { }
1435 }
1436 if (load_access_count == 1000) {
1437 setverdict(pass);
1438 } else {
1439 setverdict(fail, "Load reports state ", load_access_count, " RACH, but we sent 1000");
1440 }
1441
1442 f_vty_load_ind_thresh(10);
1443 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1444}
1445
Harald Welte54a2a2d2018-02-26 09:14:05 +01001446private function f_rach_toffs(int16_t toffs256, boolean expect_pass) runs on test_CT {
Harald Weltef8df4cb2018-03-10 15:15:08 +01001447 var TrxcMessage ret;
Harald Welte54a2a2d2018-02-26 09:14:05 +01001448 /* tell fake_trx to use a given timing offset for all bursts */
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001449 ret := f_TRXC_transceive(BTS_TRXC, g_bts_trxc_conn_id, valueof(ts_TRXC_FAKE_TIMING(toffs256)));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001450 f_sleep(0.5);
1451
1452 /* Transmit RACH request + wait for confirmation */
1453 var OCT1 ra := f_rnd_ra_cs();
1454 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
1455
1456 /* Check for expected result */
1457 timer T := 1.5;
1458 T.start;
1459 alt {
1460 [expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
1461 setverdict(pass);
1462 }
1463 [not expect_pass] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_CHAN_RQD(ra, fn))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001464 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("RACH passed but was expected to be dropped: ", toffs256));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001465 }
1466 [] RSL_CCHAN.receive { repeat; }
1467 [not expect_pass] T.timeout {
1468 setverdict(pass);
1469 }
1470 [expect_pass] T.timeout {
Max6e053042019-03-14 16:34:22 +01001471 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN RQD: FN=", fn, " RA=", ra));
Harald Welte54a2a2d2018-02-26 09:14:05 +01001472 }
1473 }
1474}
1475
1476/* Test if dropping of RACH Based on NM_ATT_MAX_TA works */
1477testcase TC_rach_max_ta() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02001478 f_init();
Harald Welte54a2a2d2018-02-26 09:14:05 +01001479 f_init_l1ctl();
1480 f_l1_tune(L1CTL);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001481 f_sleep(1.0);
1482
1483 /* default max-ta is 63 (full range of GSM timing advance */
1484
Vadim Yanitskiyc81d6e42018-03-05 22:39:01 +07001485 /* We allow early arrival up to 2 symbols */
1486 f_rach_toffs(-1*256, true);
1487 f_rach_toffs(-2*256, true);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001488 f_rach_toffs(-10*256, false);
1489
1490 /* 0 / 32 / 63 bits is legal / permitted */
1491 f_rach_toffs(0, true);
1492 f_rach_toffs(32*256, true);
1493 f_rach_toffs(63*256, true);
1494
1495 /* more than 63 bits is not legal / permitted */
1496 f_rach_toffs(64*256, false);
1497 f_rach_toffs(127*256, false);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001498 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte54a2a2d2018-02-26 09:14:05 +01001499}
Harald Welte8c24c2b2018-02-26 08:31:31 +01001500
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07001501function f_TC_ho_rach(charstring id) runs on ConnHdlr {
1502 var GsmFrameNumber fn;
1503 var RSL_Message rm;
1504
1505 f_l1_tune(L1CTL);
1506 RSL.clear;
1507
1508 /* Generate a random Handover Reference */
1509 var integer ho_ref := oct2int(f_rnd_octstring(1));
1510
1511 /* Handover Reference IE (see 3GPP TS 48.058, 9.3.9) */
1512 var RSL_IE ho_ref_ie := valueof(t_RSL_IE(RSL_IE_HANDO_REF,
1513 RSL_IE_Body:{ handover_ref := ho_ref }));
1514
1515 /* Activate a channel on the BTS side (no encryption) */
1516 f_rsl_chan_act(g_pars.chan_mode, more_ies := { ho_ref_ie },
1517 act_type := t_RSL_IE_ActType_HO_SYNC);
1518
1519 /* Switch the MS side (e.g. trxcon) to a dedicated channel without
1520 * waiting for Immediate Assignment and sending Access Burst */
1521 f_L1CTL_DM_EST_REQ(L1CTL, { false, mp_trx0_arfcn }, g_pars.chan_nr, 7);
1522
1523 /* Send handover Access Burst */
1524 fn := f_L1CTL_RACH(L1CTL, ho_ref, chan_nr := g_pars.chan_nr);
1525
1526 /* TODO: test mismatching Handover Reference, and missing IE */
1527
1528 /* Wait for handover detection */
1529 timer T := 3.0;
1530 T.start;
1531 alt {
1532 [] RSL.receive(tr_RSL_HANDO_DET(g_pars.chan_nr)) -> value rm {
1533 log("Handover RACH has been detected: ", rm);
1534 setverdict(pass);
1535 }
1536 [] RSL.receive(tr_RSL_CHAN_RQD(?, ?, ?, ?)) -> value rm {
1537 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1538 log2str("RSL_CHAN_RQD was not expected: ", rm));
1539 }
1540 [] RSL.receive { repeat; }
1541 [] T.timeout {
1542 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1543 log2str("Timeout waiting for handover RACH: FN=", fn, " RA=", ho_ref));
1544 }
1545 }
1546
1547 /* Release the channel */
1548 f_rsl_chan_deact();
1549 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
1550}
1551
1552/* Test handover RACH detection */
1553testcase TC_ho_rach() runs on test_CT {
1554 var ConnHdlrPars pars;
1555 var ConnHdlr vc_conn;
1556
1557 f_init();
1558
1559 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
1560 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN));
1561 log(testcasename(), ": Starting for ", g_AllChannels[i]);
1562 vc_conn := f_start_handler(refers(f_TC_ho_rach), pars);
1563 vc_conn.done;
1564 }
1565
1566 /* TODO: do the above in parallel, rather than sequentially? */
1567 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
1568}
1569
Harald Welte93640c62018-02-25 16:59:33 +01001570/***********************************************************************
1571 * Measurement Processing / Reporting
1572 ***********************************************************************/
1573
Harald Welte70767382018-02-21 12:16:40 +01001574template LapdmAddressField ts_LapdmAddr(LapdmSapi sapi, boolean c_r) := {
1575 spare := '0'B,
1576 lpd := 0,
1577 sapi := sapi,
1578 c_r := c_r,
1579 ea := true
1580}
1581
Harald Welted879bd92018-03-12 15:01:23 +01001582template LapdmFrameAB ts_LAPDm_AB(LapdmSapi sapi, boolean c_r, boolean p, octetstring pl) := {
Harald Welte70767382018-02-21 12:16:40 +01001583 addr := ts_LapdmAddr(sapi, c_r),
Harald Welted879bd92018-03-12 15:01:23 +01001584 ctrl := ts_LapdmCtrlUI(p),
Harald Welte70767382018-02-21 12:16:40 +01001585 len := 0, /* overwritten */
1586 m := false,
1587 el := 1,
1588 payload := pl
1589}
1590
1591/* handle incoming downlink SACCH and respond with uplink SACCH (meas res) */
1592altstep as_l1_sacch() runs on ConnHdlr {
1593 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001594 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001595 log("SACCH received: ", l1_dl.payload.data_ind.payload);
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001596 var GsmRrL3Message meas_rep := valueof(ts_MEAS_REP(true, mp_rxlev_exp, mp_rxlev_exp, 0, 0, omit));
Harald Welted879bd92018-03-12 15:01:23 +01001597 var LapdmFrameAB lb := valueof(ts_LAPDm_AB(0, false, false, enc_GsmRrL3Message(meas_rep)));
Harald Welte70767382018-02-21 12:16:40 +01001598 log("LAPDm: ", lb);
Pau Espin Pedroled359cb2018-09-28 16:08:24 +02001599
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07001600 var template (value) SacchL1Header l1h := ts_SacchL1Header(
1601 g_pars.l1_pars.ms_power_level, false,
1602 g_pars.l1_pars.ms_actual_ta);
1603
1604 /* TODO: we can use an extension of TTCN-3 for that, i.e. PADDING('2B'O) */
1605 var octetstring l2 := f_pad_oct(enc_LapdmFrameAB(lb), 21, '2B'O);
1606
1607 log("Sending Measurement Report: ", l1h, l2);
1608 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, ts_RslLinkID_SACCH(0), l1h, l2));
Harald Welte70767382018-02-21 12:16:40 +01001609 repeat;
1610 }
1611}
1612
1613altstep as_l1_dcch() runs on ConnHdlr {
1614 var L1ctlDlMessage l1_dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01001615 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_DCCH(?))) -> value l1_dl {
Harald Welte70767382018-02-21 12:16:40 +01001616 log("DCCH received: ", l1_dl.payload.data_ind.payload);
1617 var octetstring pl := '010301'O;
Vadim Yanitskiy31e7c672018-07-27 02:23:16 +07001618 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0),
1619 f_pad_oct(pl, 23, '2B'O)));
Harald Welte70767382018-02-21 12:16:40 +01001620 repeat;
1621 }
1622}
1623
1624type record MeasElem {
1625 uint6_t rxlev,
1626 uint3_t rxqual
1627}
1628
1629type record MeasElemFS {
1630 MeasElem full,
1631 MeasElem sub
1632}
1633
1634type record ConnL1Pars {
1635 boolean dtx_enabled,
Harald Welte685d5982018-02-27 20:42:05 +01001636 boolean toa256_enabled,
Harald Welte70767382018-02-21 12:16:40 +01001637 MeasElemFS meas_ul,
1638 int16_t timing_offset_256syms,
1639 uint5_t bs_power_level,
1640 uint5_t ms_power_level,
1641 uint8_t ms_actual_ta
1642}
1643
1644/* Convert tiing offset from 1/256th symbol to RSL Timing Offset */
1645private function toffs256s_to_rsl(int16_t toffs256s) return uint8_t {
1646 return 63 + (toffs256s/256);
1647}
1648
Harald Welted5684392018-03-10 18:22:04 +01001649private function f_max(integer a, integer b) return integer {
1650 if (a > b) {
1651 return a;
1652 } else {
1653 return b;
1654 }
1655}
1656
1657private function f_min(integer a, integer b) return integer {
1658 if (a < b) {
1659 return a;
1660 } else {
1661 return b;
1662 }
1663}
1664
1665/* compute negative tolerance val-tolerance, ensure >= min */
1666private function f_tolerance_neg(integer val, integer min, integer tolerance) return integer {
1667 val := val - tolerance;
1668 return f_max(val, min);
1669}
1670
1671/* compute positive tolerance val+tolerance, ensure <= max */
1672private function f_tolerance_pos(integer val, integer max, integer tolerance) return integer {
1673 val := val + tolerance;
1674 return f_min(val, max);
1675}
1676
1677/* return a template of (val-tolerance .. val+tolerance) ensuring it is within (min .. max) */
1678private function f_tolerance(integer val, integer min, integer max, integer tolerance)
1679return template integer {
1680 var template integer ret;
1681 ret := (f_tolerance_neg(val, min, tolerance) .. f_tolerance_pos(val, max, tolerance));
1682 return ret;
1683}
1684
1685
Harald Welte70767382018-02-21 12:16:40 +01001686/* build a template for matching measurement results against */
1687private function f_build_meas_res_tmpl() runs on ConnHdlr return template RSL_Message {
1688 var ConnL1Pars l1p := g_pars.l1_pars;
1689 var template RSL_IE_UplinkMeas ul_meas := {
1690 len := 3,
1691 rfu := '0'B,
1692 dtx_d := l1p.dtx_enabled,
Harald Welted5684392018-03-10 18:22:04 +01001693 rxlev_f_u := f_tolerance(l1p.meas_ul.full.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001694 reserved1 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001695 rxlev_s_u := f_tolerance(l1p.meas_ul.sub.rxlev, 0, 63, mp_tolerance_rxlev),
Harald Welte70767382018-02-21 12:16:40 +01001696 reserved2 := '00'B,
Harald Welted5684392018-03-10 18:22:04 +01001697 rxq_f_u := f_tolerance(l1p.meas_ul.full.rxqual, 0, 7, mp_tolerance_rxqual),
1698 rxq_s_u := f_tolerance(l1p.meas_ul.sub.rxqual, 0, 7, mp_tolerance_rxqual),
Harald Welte70767382018-02-21 12:16:40 +01001699 supp_meas_info := omit
1700 };
Harald Welte685d5982018-02-27 20:42:05 +01001701 if (l1p.toa256_enabled) {
Harald Welte15de8ba2018-06-29 08:51:42 +02001702 ul_meas.len := (3+8);
1703 ul_meas.supp_meas_info := {
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001704 toa256_mean := f_tolerance(l1p.timing_offset_256syms, -63*256, 192*256, mp_tolerance_timing_offset_256syms),
Harald Welte15de8ba2018-06-29 08:51:42 +02001705 toa256_min := ?,
1706 toa256_max := ?,
1707 toa256_std_dev := ?
1708 }
Harald Welte685d5982018-02-27 20:42:05 +01001709 }
Harald Welte70767382018-02-21 12:16:40 +01001710 var template RSL_IE_BS_Power bs_power := {
1711 reserved := 0,
1712 epc := false,
1713 fpc := false,
1714 power_level := l1p.bs_power_level
1715 };
1716 var template RSL_IE_L1Info l1_info := {
1717 ms_power_lvl := l1p.ms_power_level,
1718 fpc := false,
1719 reserved := 0,
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001720 actual_ta := f_tolerance(l1p.ms_actual_ta, 0, 63, mp_tolerance_timing_offset_256syms/256)
Harald Welte70767382018-02-21 12:16:40 +01001721 };
1722 var uint8_t offs := toffs256s_to_rsl(l1p.timing_offset_256syms);
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001723 var template uint8_t t_toffs := f_tolerance(offs, 0, 255, mp_tolerance_timing_offset_256syms/256);
Harald Welte70767382018-02-21 12:16:40 +01001724 return tr_RSL_MEAS_RES_OSMO(g_chan_nr, g_next_meas_res_nr, ul_meas, bs_power, l1_info,
1725 ?, t_toffs);
1726}
1727
1728/* verify we regularly receive measurement reports with incrementing numbers */
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001729altstep as_meas_res(boolean verify_meas := true) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001730 var RSL_Message rsl;
Vadim Yanitskiy41baf002018-10-04 17:44:50 +07001731 [not verify_meas] RSL.receive(tr_RSL_MEAS_RES(?)) { repeat; }
Harald Welte70767382018-02-21 12:16:40 +01001732 [] RSL.receive(f_build_meas_res_tmpl()) -> value rsl {
1733 /* increment counter of next to-be-expected meas rep */
1734 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1735 /* Re-start the timer expecting the next MEAS RES */
Harald Weltec3a3f452018-02-26 17:37:47 +01001736 f_timer_safe_restart(g_Tmeas_exp);
Harald Welte70767382018-02-21 12:16:40 +01001737 repeat;
1738 }
1739 [] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr, g_next_meas_res_nr)) -> value rsl {
Harald Weltefa45e9e2018-03-10 18:59:03 +01001740 /* increment counter of next to-be-expected meas rep */
1741 g_next_meas_res_nr := (g_next_meas_res_nr + 1) mod 256;
1742 if (g_first_meas_res) {
1743 g_first_meas_res := false;
1744 repeat;
1745 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001746 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unspecific MEAS RES ", rsl));
Harald Weltefa45e9e2018-03-10 18:59:03 +01001747 }
Harald Welte70767382018-02-21 12:16:40 +01001748 }
1749 [] RSL.receive(tr_RSL_MEAS_RES(?)) -> value rsl {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001750 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Received unexpected MEAS RES ", rsl));
Harald Welte70767382018-02-21 12:16:40 +01001751 }
Pau Espin Pedrol425b62f2018-07-06 16:11:43 +02001752 [g_Tmeas_exp.running] g_Tmeas_exp.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001753 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Didn't receive expected measurement result")
Harald Welte70767382018-02-21 12:16:40 +01001754 }
1755}
1756
Harald Weltee613f962018-04-18 22:38:16 +02001757private function f_alg_id_to_l1ctl(RSL_AlgId rsl_alg_id) return uint8_t {
1758 select (rsl_alg_id) {
1759 case (RSL_ALG_ID_A5_0) { return 0; }
1760 case (RSL_ALG_ID_A5_1) { return 1; }
1761 case (RSL_ALG_ID_A5_2) { return 2; }
1762 case (RSL_ALG_ID_A5_3) { return 3; }
1763 case (RSL_ALG_ID_A5_4) { return 4; }
1764 case (RSL_ALG_ID_A5_5) { return 5; }
1765 case (RSL_ALG_ID_A5_6) { return 6; }
1766 case (RSL_ALG_ID_A5_7) { return 7; }
1767 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001768 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1769 /* Make compiler happy by calling mtc.stop here. It is already
1770 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001771 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001772 }
1773 }
1774}
1775
1776private function f_alg_id_to_l3(RSL_AlgId rsl_alg_id) return BIT3 {
1777 select (rsl_alg_id) {
1778 case (RSL_ALG_ID_A5_1) { return '000'B; }
1779 case (RSL_ALG_ID_A5_2) { return '001'B; }
1780 case (RSL_ALG_ID_A5_3) { return '010'B; }
1781 case (RSL_ALG_ID_A5_4) { return '011'B; }
1782 case (RSL_ALG_ID_A5_5) { return '100'B; }
1783 case (RSL_ALG_ID_A5_6) { return '101'B; }
1784 case (RSL_ALG_ID_A5_7) { return '110'B; }
1785 case else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001786 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknwon Algorithm ID");
1787 /* Make compiler happy by calling mtc.stop here. It is already
1788 * called in f_shutdown */
Daniel Willmann17ddd852018-07-05 17:33:20 +02001789 mtc.stop;
Harald Weltee613f962018-04-18 22:38:16 +02001790 }
1791 }
1792}
1793
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001794/* Send RACH request through l1CTL and wait for ChanReq on RSL BST->BSC */
1795private function f_rach_req_wait_chan_rqd(integer ra) runs on ConnHdlr return GsmFrameNumber {
1796 var GsmFrameNumber fn;
1797 timer T := 8.0;
1798
1799 /* advertise to RSL Emulation that we expect to receive confirmation from RACH */
1800 RSL.send(ts_RSLDC_ChanRqd_anyFN(int2oct(ra,1)));
1801
1802 f_L1CTL_PARAM(L1CTL, g_pars.l1_pars.ms_actual_ta, g_pars.l1_pars.ms_power_level);
1803 /* Send the actual RACH */
1804 fn := f_L1CTL_RACH(L1CTL, ra);
1805
1806 T.start;
1807 alt {
1808 [] RSL.receive(tr_RSL_CHAN_RQD(int2oct(ra,1), fn)) { setverdict(pass, "Received CHAN-RQD from RACH REQ") }
1809 [] T.timeout {
1810 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for CHAN-RQD from RACH REQ <", ra, ", ", fn, ">"));
1811 }
1812 }
1813 T.stop
1814 return fn;
1815}
Harald Weltee613f962018-04-18 22:38:16 +02001816
Harald Welte70767382018-02-21 12:16:40 +01001817/* Establish dedicated channel: L1CTL + RSL side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001818private function f_est_dchan(boolean encr_enable := false, RSL_IE_List more_ies := {}) runs on ConnHdlr {
Harald Welte70767382018-02-21 12:16:40 +01001819 var GsmFrameNumber fn;
1820 var ImmediateAssignment imm_ass;
1821 var integer ra := 23;
1822
Pau Espin Pedrol6451b042018-10-24 20:36:16 +02001823 /* Send RACH request and wait for ChanReq */
1824 fn := f_rach_req_wait_chan_rqd(ra);
Harald Welte70767382018-02-21 12:16:40 +01001825
1826 /* Activate channel on BTS side */
Harald Weltec8d363c2019-05-19 20:36:48 +02001827 f_rsl_chan_act(g_pars.chan_mode, encr_enable, more_ies);
Harald Welte70767382018-02-21 12:16:40 +01001828
1829 /* Send IMM.ASS via CCHAN */
1830 var ChannelDescription ch_desc := {
1831 chan_nr := g_pars.chan_nr,
1832 tsc := 7,
1833 h := false,
1834 arfcn := mp_trx0_arfcn,
1835 maio_hsn := omit
1836 };
1837 var MobileAllocation ma := {
1838 len := 0,
1839 ma := ''B
1840 };
1841 var GsmRrMessage rr_msg := valueof(ts_IMM_ASS(ra, fn, 0, ch_desc, ma));
1842 RSL.send(ts_RSL_IMM_ASSIGN(enc_GsmRrMessage(rr_msg)));
1843
1844 /* receive IMM.ASS on MS side */
1845 var ImmediateAssignment ia_um;
1846 ia_um := f_L1CTL_WAIT_IMM_ASS(L1CTL, ra, fn);
1847 /* enable dedicated mode */
1848 f_L1CTL_DM_EST_REQ_IA(L1CTL, ia_um);
Harald Weltee613f962018-04-18 22:38:16 +02001849 /* enable encryption, if requested */
1850 if (encr_enable) {
1851 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
1852 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
1853 }
Harald Weltefa45e9e2018-03-10 18:59:03 +01001854
1855 g_first_meas_res := true;
Harald Welte70767382018-02-21 12:16:40 +01001856}
1857
1858/* establish DChan, verify existance + contents of measurement reports */
1859function f_TC_meas_res_periodic(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01001860 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01001861 RSL.clear;
1862
Vadim Yanitskiy44ff2142019-01-12 07:04:58 +07001863 if (mp_bts_trxc_port != -1) {
Pau Espin Pedrole9571aa2018-10-22 17:13:07 +02001864 f_trxc_fake_rssi(rxlev2dbm(mp_ul_rxlev_exp));
Pau Espin Pedrol121724c2018-09-28 15:58:12 +02001865 f_trx_fake_toffs256(g_pars.l1_pars.timing_offset_256syms);
1866 }
Harald Welte70767382018-02-21 12:16:40 +01001867
1868 f_est_dchan();
1869
1870 /* run for a number of seconds, send SACCH + FACCH from MS side and verify
1871 * RSL measurement reports on Abis side */
1872 timer T := 8.0;
1873 T.start;
1874 alt {
1875 [] as_l1_sacch();
1876 [] as_meas_res();
1877 [] as_l1_dcch();
1878 [] L1CTL.receive { repeat; }
1879 [g_Tmeas_exp.running] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001880 /* as_meas_res() would have done Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail) in case
Harald Welte70767382018-02-21 12:16:40 +01001881 * of any earlier errors, so if we reach this timeout, we're good */
1882 setverdict(pass);
1883 }
1884 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001885 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No MEAS RES received at all");
Harald Welte70767382018-02-21 12:16:40 +01001886 }
1887 }
1888 f_rsl_chan_deact();
Harald Welte3dc20462018-03-10 23:03:38 +01001889 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Harald Welte70767382018-02-21 12:16:40 +01001890}
Harald Welte0472ab42018-03-12 15:02:26 +01001891
Harald Welte70767382018-02-21 12:16:40 +01001892testcase TC_meas_res_sign_tchf() runs on test_CT {
1893 var ConnHdlr vc_conn;
1894 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02001895 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001896 for (var integer tn := 1; tn <= 4; tn := tn+1) {
1897 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07001898 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars,
1899 pcu_comp := false, trxc_comp := true);
Harald Welte70767382018-02-21 12:16:40 +01001900 vc_conn.done;
1901 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001902 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001903}
1904testcase TC_meas_res_sign_tchh() runs on test_CT {
1905 var ConnHdlr vc_conn;
1906 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02001907 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001908 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1909 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1910 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1911 vc_conn.done;
1912 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001913 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001914}
1915testcase TC_meas_res_sign_sdcch4() runs on test_CT {
1916 var ConnHdlr vc_conn;
1917 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02001918 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001919 for (var integer ss := 0; ss <= 3; ss := ss+1) {
1920 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0, ss), ts_RSL_ChanMode_SIGN));
1921 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1922 vc_conn.done;
1923 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001924 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001925}
1926testcase TC_meas_res_sign_sdcch8() runs on test_CT {
1927 var ConnHdlr vc_conn;
1928 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02001929 f_init();
Harald Welte70767382018-02-21 12:16:40 +01001930 for (var integer ss := 0; ss <= 7; ss := ss+1) {
1931 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, ss), ts_RSL_ChanMode_SIGN));
1932 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1933 vc_conn.done;
1934 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001935 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte70767382018-02-21 12:16:40 +01001936}
Harald Welte685d5982018-02-27 20:42:05 +01001937testcase TC_meas_res_sign_tchh_toa256() runs on test_CT {
1938 var ConnHdlr vc_conn;
1939 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02001940 f_init();
Harald Welte685d5982018-02-27 20:42:05 +01001941 f_vty_config(BTSVTY, "bts 0", "supp-meas-info toa256");
1942 for (var integer ss := 0; ss <= 1; ss := ss+1) {
1943 pars := valueof(t_Pars(t_RslChanNr_Lm(5, ss), ts_RSL_ChanMode_SIGN));
1944 pars.l1_pars.toa256_enabled := true;
1945 vc_conn := f_start_handler(refers(f_TC_meas_res_periodic), pars);
1946 vc_conn.done;
1947 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02001948 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte685d5982018-02-27 20:42:05 +01001949}
1950
Philipp Maier4d1e9c92018-12-20 11:11:56 +01001951/* establish DChan, and send MS POWER CONTROL messages via RSL, verify that
1952 * the BTS is forwarding those values to the MS via the SACCH L1 header. */
1953function f_tc_rsl_ms_pwr_ctrl(charstring id) runs on ConnHdlr {
1954 var L1ctlDlMessage l1_dl;
1955 var RSL_IE_MS_Power ms_power;
1956 var RSL_Message rsl;
1957 var uint5_t power_level := 0;
1958
1959 f_l1_tune(L1CTL);
1960 RSL.clear;
1961
1962 f_est_dchan();
1963
1964 ms_power.reserved := 0;
1965 ms_power.fpc_epc := false;
1966
1967 /* Send the first power control command. This will disable any BTS/TRX
1968 * internal power control and switch the MS (which is not in scope of
1969 * this test) to a constant power level. We start with a power level
1970 * of 0 */
1971 ms_power.power_level := power_level;
1972 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1973 RSL.send(rsl);
1974
1975 alt {
1976
1977 /* Pick all SACCH blocks for checking */
1978 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
1979
1980 /* The first byte of the L1 header contains the power level.
1981 * The reserved bits and the fpc bit is set to 0, so we may
1982 * compare directly. */
1983 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(power_level, 1))) {
1984 setverdict(fail, "Power level in L1 header does not match the signaled (RSL) power level.");
1985 }
1986
1987 /* Signal a new power level via RSL for the next turn. */
1988 if (power_level < 31) {
1989 power_level := power_level + 1;
1990 ms_power.power_level := power_level;
1991 rsl := valueof(ts_RSL_MS_PWR_CTRL(g_chan_nr, ms_power));
1992 RSL.send(rsl);
1993 repeat;
1994 }
1995
1996 }
1997
1998 /* Ignore all other blocks */
1999 [] L1CTL.receive { repeat; }
2000
2001 }
2002
2003 f_rsl_chan_deact();
2004 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2005
2006 setverdict(pass);
2007}
2008
2009testcase TC_rsl_ms_pwr_ctrl() runs on test_CT {
2010 var ConnHdlr vc_conn;
2011 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002012 f_init();
Philipp Maier4d1e9c92018-12-20 11:11:56 +01002013
2014 for (var integer tn := 1; tn <= 4; tn := tn+1) {
2015 pars := valueof(t_Pars(t_RslChanNr_Bm(tn), ts_RSL_ChanMode_SIGN));
2016 vc_conn := f_start_handler(refers(f_tc_rsl_ms_pwr_ctrl), pars);
2017 vc_conn.done;
2018 }
2019 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2020}
Harald Welte70767382018-02-21 12:16:40 +01002021
Eric Wild6833cc92019-05-23 19:34:44 +02002022/* establish DChan, verify that the BTS sets the TA in the first SACCH L1 header.
2023TA for the IMM ASS messages is still controlled by g_pars.l1_pars.ms_actual_ta! */
2024function f_tc_rsl_chan_initial_ta(charstring id) runs on ConnHdlr {
2025 var L1ctlDlMessage l1_dl;
2026 var uint5_t ta_to_test := 16;
2027
2028
2029 f_l1_tune(L1CTL);
2030 RSL.clear;
2031
2032 /* tell fake_trx to use a given timing offset for all bursts */
2033 f_trx_fake_toffs256(ta_to_test*256);
2034
2035 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_TIMING_ADVANCE, RSL_IE_Body:{timing_adv := ta_to_test}))} );
2036
2037
2038 alt {
2039
2040 /* Pick all SACCH blocks for checking */
2041 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2042
2043 /* The second byte of the L1 header contains the TA. */
2044 if (not (l1_dl.payload.data_ind.payload[1] == int2oct(ta_to_test, 1))) {
2045 setverdict(fail, "TA in L1 header does not match the signaled (RSL) TA.");
2046 }
2047
2048 }
2049
2050 /* Ignore all other blocks */
2051 [] L1CTL.receive { repeat; }
2052
2053 }
2054
2055 f_rsl_chan_deact();
2056 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2057
2058 setverdict(pass);
2059}
2060
2061testcase TC_rsl_chan_initial_ta() runs on test_CT {
2062 var ConnHdlr vc_conn;
2063 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002064 f_init();
Eric Wild6833cc92019-05-23 19:34:44 +02002065 pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Vadim Yanitskiyf4e997c2019-06-04 21:40:33 +07002066 vc_conn := f_start_handler(refers(f_tc_rsl_chan_initial_ta), pars,
2067 pcu_comp := false, trxc_comp := true);
Eric Wild6833cc92019-05-23 19:34:44 +02002068 vc_conn.done;
2069 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
2070}
2071
Eric Wilde57e1a62019-05-28 13:30:55 +02002072/* establish DChan, verify that the BTS sets MS power in the first SACCH L1 header. */
2073function f_tc_rsl_chan_initial_ms_pwr(charstring id) runs on ConnHdlr {
2074 var L1ctlDlMessage l1_dl;
2075 var uint5_t ms_power_level := 7;
2076
2077 var RSL_IE_MS_Power ms_power;
2078 ms_power.reserved := 0;
2079 ms_power.fpc_epc := false;
2080 ms_power.power_level := ms_power_level;
2081
2082 f_l1_tune(L1CTL);
2083 RSL.clear;
2084
2085 f_est_dchan(more_ies :={valueof(t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power}))} );
2086
2087 timer T := 1.0;
2088 T.start;
2089 alt {
2090 /* Pick all SACCH blocks for checking */
2091 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, tr_RslLinkID_SACCH(?))) -> value l1_dl {
2092 /* The first byte of the L1 header contains the power level.. */
2093 if (not (l1_dl.payload.data_ind.payload[0] == int2oct(ms_power_level, 1))) {
2094 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2095 }
2096 }
2097 /* Ignore all other blocks */
2098 [] L1CTL.receive { repeat; }
2099 [] T.timeout {
2100 setverdict(fail, "Power Level in L1 header does not match the signaled (RSL) MS Power Level.");
2101 }
2102 }
2103
2104 f_rsl_chan_deact();
2105 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
2106 setverdict(pass);
2107}
2108
2109testcase TC_rsl_chan_initial_ms_pwr() runs on test_CT {
2110 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
2111 f_testmatrix_each_chan(pars, refers(f_tc_rsl_chan_initial_ms_pwr));
2112}
2113
Harald Welte0472ab42018-03-12 15:02:26 +01002114/* Test if a channel without valid uplink bursts generates RSL CONN FAIL IND (TS 48.058 4.10) */
Harald Welte70767382018-02-21 12:16:40 +01002115private function f_TC_conn_fail_crit(charstring id) runs on ConnHdlr {
Harald Welte68e495b2018-02-25 00:05:57 +01002116 f_l1_tune(L1CTL);
Harald Welte70767382018-02-21 12:16:40 +01002117 RSL.clear;
2118
2119 f_est_dchan();
2120 f_sleep(2.0);
Harald Weltef8df4cb2018-03-10 15:15:08 +01002121 L1CTL.send(ts_L1CTL_DM_REL_REQ(g_chan_nr));
Harald Welte70767382018-02-21 12:16:40 +01002122
2123 timer T := 40.0;
2124 T.start;
2125 alt {
2126 [] RSL.receive(tr_RSL_CONN_FAIL_IND(g_chan_nr, ?)) {
2127 setverdict(pass)
2128 }
2129 [] RSL.receive { repeat };
2130 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002131 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No CONN FAIL IND received");
Harald Welte70767382018-02-21 12:16:40 +01002132 }
2133 }
2134 f_rsl_chan_deact();
2135}
2136testcase TC_conn_fail_crit() runs on test_CT {
2137 var ConnHdlr vc_conn;
2138 var ConnHdlrPars pars;
Harald Welte10474062019-05-30 16:48:17 +02002139 f_init();
Harald Welte70767382018-02-21 12:16:40 +01002140 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6, 3), ts_RSL_ChanMode_SIGN));
2141 pars.t_guard := 60.0;
2142 vc_conn := f_start_handler(refers(f_TC_conn_fail_crit), pars);
2143 vc_conn.done;
2144}
2145
Harald Welte93640c62018-02-25 16:59:33 +01002146/***********************************************************************
2147 * Paging
2148 ***********************************************************************/
2149
Harald Welte68e495b2018-02-25 00:05:57 +01002150function tmsi_is_dummy(TMSIP_TMSI_V tmsi) return boolean {
2151 if (tmsi == 'FFFFFFFF'O) {
2152 return true;
2153 } else {
2154 return false;
2155 }
2156}
Harald Welte70767382018-02-21 12:16:40 +01002157
Philipp Maier82cb0b12018-08-31 14:41:39 +02002158type record allowedFn { integer frame_nr }
2159template allowedFn bs_ag_blks_res_0 := { frame_nr := (6, 12, 16, 22, 26, 32, 36, 42, 46) }
2160template allowedFn bs_ag_blks_res_1 := { frame_nr := (12, 16, 22, 26, 32, 36, 42, 46) }
2161template allowedFn bs_ag_blks_res_2 := { frame_nr := (16, 22, 26, 32, 36, 42, 46) }
2162template allowedFn bs_ag_blks_res_3 := { frame_nr := (22, 26, 32, 36, 42, 46) }
2163template allowedFn bs_ag_blks_res_4 := { frame_nr := (26, 32, 36, 42, 46) }
2164template allowedFn bs_ag_blks_res_5 := { frame_nr := (32, 36, 42, 46) }
2165template allowedFn bs_ag_blks_res_6 := { frame_nr := (36, 42, 46) }
2166template allowedFn bs_ag_blks_res_7 := { frame_nr := (42, 46) }
2167function check_pch_fn(integer frame_nr, integer bs_ag_blks_res) runs on test_CT
2168{
2169 var integer frame_nr_51;
2170 frame_nr_51 := frame_nr mod 51
2171
2172 var allowedFn fn_check;
2173 fn_check.frame_nr := frame_nr_51;
2174
2175 if (bs_ag_blks_res < 0 or bs_ag_blks_res > 7) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002176 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "bs_ag_blks_res out of valid range (0..7)");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002177 return;
2178 }
2179
2180 if (bs_ag_blks_res == 0 and match(fn_check, bs_ag_blks_res_0)) {
2181 return;
2182 }
2183 if (bs_ag_blks_res == 1 and match(fn_check, bs_ag_blks_res_1)) {
2184 return;
2185 }
2186 if (bs_ag_blks_res == 2 and match(fn_check, bs_ag_blks_res_2)) {
2187 return;
2188 }
2189 if (bs_ag_blks_res == 3 and match(fn_check, bs_ag_blks_res_3)) {
2190 return;
2191 }
2192 if (bs_ag_blks_res == 4 and match(fn_check, bs_ag_blks_res_4)) {
2193 return;
2194 }
2195 if (bs_ag_blks_res == 5 and match(fn_check, bs_ag_blks_res_5)) {
2196 return;
2197 }
2198 if (bs_ag_blks_res == 6 and match(fn_check, bs_ag_blks_res_6)) {
2199 return;
2200 }
2201 if (bs_ag_blks_res == 7 and match(fn_check, bs_ag_blks_res_7)) {
2202 return;
2203 }
2204
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002205 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "received paging on AGCH");
Philipp Maier82cb0b12018-08-31 14:41:39 +02002206 return;
2207}
2208
2209altstep as_l1_count_paging(inout integer num_paging_rcv_msgs, inout integer num_paging_rcv_ids, PagingTestCfg cfg)
Harald Welte68e495b2018-02-25 00:05:57 +01002210runs on test_CT {
2211 var L1ctlDlMessage dl;
Harald Weltef8df4cb2018-03-10 15:15:08 +01002212 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_DummyUI)) {
Harald Welte68e495b2018-02-25 00:05:57 +01002213 repeat;
2214 }
Harald Weltef8df4cb2018-03-10 15:15:08 +01002215 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0))) -> value dl {
Harald Welte68e495b2018-02-25 00:05:57 +01002216 var octetstring without_plen :=
2217 substr(dl.payload.data_ind.payload, 1, lengthof(dl.payload.data_ind.payload)-1);
2218 var PDU_ML3_NW_MS rr := dec_PDU_ML3_NW_MS(without_plen);
Philipp Maier82cb0b12018-08-31 14:41:39 +02002219
2220 check_pch_fn(dl.dl_info.frame_nr, cfg.bs_ag_blks_res);
2221
Harald Welte68e495b2018-02-25 00:05:57 +01002222 if (match(rr, tr_PAGING_REQ1)) {
2223 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2224 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2225 if (isvalue(rr.msgs.rrm.pagingReq_Type1.mobileIdentity2)) {
2226 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2227 }
2228 } else if (match(rr, tr_PAGING_REQ2)) {
2229 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2230 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity1)) {
2231 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2232 }
2233 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type2.mobileIdentity2)) {
2234 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2235 }
2236 if (isvalue(rr.msgs.rrm.pagingReq_Type2.mobileIdentity3)) {
2237 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2238 }
2239 } else if (match(rr, tr_PAGING_REQ3)) {
2240 num_paging_rcv_msgs := num_paging_rcv_msgs + 1;
2241 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity1)) {
2242 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2243 }
2244 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity2)) {
2245 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2246 }
2247 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity3)) {
2248 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2249 }
2250 if (not tmsi_is_dummy(rr.msgs.rrm.pagingReq_Type3.mobileIdentity4)) {
2251 num_paging_rcv_ids := num_paging_rcv_ids + 1;
2252 }
2253 }
2254 repeat;
2255 }
2256}
2257
2258type record PagingTestCfg {
2259 boolean combined_ccch,
2260 integer bs_ag_blks_res,
2261 float load_factor,
2262 boolean exp_load_ind,
2263 boolean exp_overload,
2264 boolean use_tmsi
2265}
2266
2267type record PagingTestState {
2268 integer num_paging_sent,
2269 integer num_paging_rcv_msgs,
2270 integer num_paging_rcv_ids,
2271 integer num_overload
2272}
2273
2274/* receive + ignore RSL RF RES IND */
2275altstep as_rsl_res_ind() runs on test_CT {
2276 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_RF_RES_IND)) {
2277 repeat;
2278 }
2279}
2280
2281/* Helper function for paging related testing */
2282private function f_TC_paging(PagingTestCfg cfg) runs on test_CT return PagingTestState {
Harald Welte10474062019-05-30 16:48:17 +02002283 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01002284 f_init_l1ctl();
2285 f_l1_tune(L1CTL);
2286
2287 var PagingTestState st := {
2288 num_paging_sent := 0,
2289 num_paging_rcv_msgs := 0,
2290 num_paging_rcv_ids := 0,
2291 num_overload := 0
2292 };
2293
2294 var float max_pch_blocks_per_sec := f_pch_block_rate_est(cfg.combined_ccch, cfg.bs_ag_blks_res);
2295 var float max_pch_imsi_per_sec;
2296 if (cfg.use_tmsi) {
2297 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 4.0; /* Type 3 */
2298 } else {
2299 max_pch_imsi_per_sec := max_pch_blocks_per_sec * 2.0; /* Type 1 */
2300 }
2301 var float pch_blocks_per_sec := max_pch_imsi_per_sec * cfg.load_factor;
2302 var float interval := 1.0 / pch_blocks_per_sec;
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002303 var float time_total := 20.0;
2304 var integer pkt_total := float2int(time_total * pch_blocks_per_sec);
2305 log("pch_blocks_total=", pkt_total," pch_blocks_per_sec=", pch_blocks_per_sec, " interval=", interval);
Harald Welte68e495b2018-02-25 00:05:57 +01002306
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002307 timer T_total := 300.0; /* big value (far bigger than time_total), used to count elapsed time */
2308 T_total.start;
Harald Welte68e495b2018-02-25 00:05:57 +01002309
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002310 timer T_itv := 0.0;
2311 T_itv.start;
2312 while (st.num_paging_sent < pkt_total) {
Harald Welte68e495b2018-02-25 00:05:57 +01002313 alt {
2314 /* check for presence of CCCH LOAD IND (paging load) */
2315 [cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
2316 st.num_overload := st.num_overload + 1;
2317 repeat;
2318 }
2319 [not cfg.exp_overload] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(0))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002320 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PCH Overload");
Harald Welte68e495b2018-02-25 00:05:57 +01002321 }
2322 [cfg.exp_load_ind] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) {
2323 log("Rx LOAD_IND");
2324 /* FIXME: analyze/verify interval + contents */
2325 repeat;
2326 }
2327 /* check if paging requests arrive on Um side */
Philipp Maier82cb0b12018-08-31 14:41:39 +02002328 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002329 [] L1CTL.receive { repeat; }
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002330 [] T_itv.timeout {
2331 /* Send paging cmds based on elapsed time */
2332 var integer new_sent := f_min(pkt_total, float2int(T_total.read * pch_blocks_per_sec) + 1);
2333 while (st.num_paging_sent < new_sent) {
2334 /* build mobile Identity */
2335 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
2336 if (cfg.use_tmsi) {
2337 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
2338 } else {
2339 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(st.num_paging_sent)));
2340 }
2341 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
2342 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
2343
2344 /* Send RSL PAGING COMMAND */
2345 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, st.num_paging_sent mod 4)));
2346
2347 st.num_paging_sent := st.num_paging_sent + 1;
2348 }
2349 if (st.num_paging_sent < pkt_total) {
2350 /* Wait for interval to next PAGING COMMAND */
2351 var float time_now := T_total.read;
2352 var float next_sched := int2float(st.num_paging_sent)*interval;
2353 if (next_sched > time_now) {
2354 T_itv.start(next_sched - time_now);
2355 } else {
2356 T_itv.start(0.0);
2357 }
2358 } else {
2359 /* We are done, no need to keep counting */
2360 T_total.stop;
2361 }
2362 }
2363 [] T_total.timeout { }
Harald Welte68e495b2018-02-25 00:05:57 +01002364 [] as_rsl_res_ind();
2365 }
2366 }
2367
2368 /* wait for max 18s for paging queue to drain (size: 200, ~ 13 per s -> 15s) */
2369 timer T_wait := 18.0;
2370 T_wait.start;
2371 alt {
Philipp Maier82cb0b12018-08-31 14:41:39 +02002372 [] as_l1_count_paging(st.num_paging_rcv_msgs, st.num_paging_rcv_ids, cfg);
Harald Welte68e495b2018-02-25 00:05:57 +01002373 [] L1CTL.receive { repeat; }
2374 /* 65535 == empty paging queue, we can terminate*/
2375 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND(65535))) { }
2376 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_PAGING_LOAD_IND)) { repeat; }
2377 [] T_wait.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002378 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Waiting for empty paging queue");
Harald Welte68e495b2018-02-25 00:05:57 +01002379 }
2380 [] as_rsl_res_ind();
2381 }
2382
2383 log("num_paging_sent=", st.num_paging_sent, " rcvd_msgs=", st.num_paging_rcv_msgs,
2384 " rcvd_ids=", st.num_paging_rcv_ids);
2385 return st;
2386}
2387
2388/* Create ~ 80% paging load (IMSI only) sustained for about 20s, verifying that
2389 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2390 * - that CCCH LOAD IND (PCH) are being generated
2391 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2392testcase TC_paging_imsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002393 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002394 var PagingTestCfg cfg := {
2395 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002396 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002397 load_factor := 0.8,
2398 exp_load_ind := true,
2399 exp_overload := false,
2400 use_tmsi := false
2401 };
2402 var PagingTestState st := f_TC_paging(cfg);
2403 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002404 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2405 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002406 } else {
2407 setverdict(pass);
2408 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002409 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002410}
2411
2412/* Create ~ 80% paging load (TMSI only) sustained for about 20s, verifying that
2413 * - the number of Mobile Identities on Um PCH match the number of pages on RSL
2414 * - that CCCH LOAD IND (PCH) are being generated
2415 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2416testcase TC_paging_tmsi_80percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002417 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002418 var PagingTestCfg cfg := {
2419 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002420 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002421 load_factor := 0.8,
2422 exp_load_ind := true,
2423 exp_overload := false,
2424 use_tmsi := true
2425 };
2426 var PagingTestState st := f_TC_paging(cfg);
2427 if (st.num_paging_sent != st.num_paging_rcv_ids) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", st.num_paging_sent, " pagings but have ",
2429 st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002430 } else {
2431 setverdict(pass);
2432 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002433 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002434}
2435
2436/* Create ~ 200% paging load (IMSI only) sustained for about 20s, verifying that
2437 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2438 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2439 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2440testcase TC_paging_imsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002441 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002442 var PagingTestCfg cfg := {
2443 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002444 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002445 load_factor := 2.0,
2446 exp_load_ind := true,
2447 exp_overload := true,
2448 use_tmsi := false
2449 };
2450 var PagingTestState st := f_TC_paging(cfg);
2451 /* We expect about 80-85% to pass, given that we can fill the paging buffer of 200
2452 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002453 var template integer tpl := (st.num_paging_sent*78/100 .. st.num_paging_sent *85/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002454 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002455 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002456 } else {
2457 setverdict(pass);
2458 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002459 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002460}
2461
2462/* Create ~ 200% paging load (TMSI only) sustained for about 20s, verifying that
2463 * - the number of Mobile Identities on Um PCH are ~ 82% of the number of pages on RSL
2464 * - that CCCH LOAD IND (PCH) are being generated and reach 0 at some point
2465 * - that CCCH LOAD IND (PCH) [no load] is received after paging flood is over */
2466testcase TC_paging_tmsi_200percent() runs on test_CT {
Philipp Maierd65d0562018-08-30 16:25:47 +02002467 var SystemInformation si3 := valueof(ts_SI3_default);
Harald Welte68e495b2018-02-25 00:05:57 +01002468 var PagingTestCfg cfg := {
2469 combined_ccch := true,
Philipp Maierd65d0562018-08-30 16:25:47 +02002470 bs_ag_blks_res := si3.payload.si3.ctrl_chan_desc.bs_ag_blks_res,
Harald Welte68e495b2018-02-25 00:05:57 +01002471 load_factor := 2.0,
2472 exp_load_ind := true,
2473 exp_overload := true,
2474 use_tmsi := true
2475 };
2476 var PagingTestState st := f_TC_paging(cfg);
2477 /* We expect about 70% to pass, given that we can fill the paging buffer of 200
2478 * slots and will fully drain that buffer before returning */
Pau Espin Pedrol9c3ff4e2018-09-26 18:30:16 +02002479 var template integer tpl := (st.num_paging_sent*64/100 .. st.num_paging_sent *72/100);
Harald Welte68e495b2018-02-25 00:05:57 +01002480 if (not match(st.num_paging_rcv_ids, tpl)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002481 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Expected ", tpl, " pagings but have ", st.num_paging_rcv_ids));
Harald Welte68e495b2018-02-25 00:05:57 +01002482 } else {
2483 setverdict(pass);
2484 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002485 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002486}
2487
2488
Harald Welte93640c62018-02-25 16:59:33 +01002489/***********************************************************************
2490 * Immediate Assignment / AGCH
2491 ***********************************************************************/
Harald Weltee8d750e2018-06-10 21:41:35 +02002492const MobileAllocation c_MA_null := {
2493 len := 0,
2494 ma := ''B
2495}
Harald Welte93640c62018-02-25 16:59:33 +01002496
Harald Weltee8d750e2018-06-10 21:41:35 +02002497template (value) ChannelDescription ts_ChanDesc(template (value) RslChannelNr chan_nr, uint3_t tsc := 7,
2498 uint12_t arfcn := 871) := {
2499 chan_nr := chan_nr,
2500 tsc := tsc,
2501 h := false,
2502 arfcn := arfcn,
2503 maio_hsn := omit
2504}
2505
2506private function f_fmt_ia_stats(integer num_tx, integer num_rx, integer num_del) return charstring {
2507 return int2str(num_tx) & " sent, "
2508 & int2str(num_rx) & " received, "
2509 & int2str(num_del) & " deleted";
2510}
2511
2512private function f_TC_imm_ass(integer num_total, float sleep_s, float exp_pass) runs on test_CT {
2513 var L1ctlDlMessage l1_dl;
2514 timer T := 10.0;
2515 var integer num_tx := 0;
2516 var integer num_rx := 0;
2517 var integer num_del := 0;
2518 var charstring res_str;
2519 var float rx_ratio;
2520
Harald Welte10474062019-05-30 16:48:17 +02002521 f_init();
Harald Weltee8d750e2018-06-10 21:41:35 +02002522 f_init_l1ctl();
2523 f_l1_tune(L1CTL);
2524
2525 for (var integer i := 0; i < num_total; i := i+1) {
2526 var ChannelDescription ch_desc := valueof(ts_ChanDesc(valueof(t_RslChanNr_SDCCH4(0, 0))));
2527 var GsmRrMessage ia := valueof(ts_IMM_ASS(42, i, 5, ch_desc, c_MA_null));
2528 var octetstring ia_enc := enc_GsmRrMessage(ia);
Harald Welte68e495b2018-02-25 00:05:57 +01002529 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_IMM_ASSIGN(ia_enc, 0)));
Harald Weltee8d750e2018-06-10 21:41:35 +02002530 num_tx := num_tx+1;
2531 f_sleep(sleep_s);
Harald Welte68e495b2018-02-25 00:05:57 +01002532 }
2533 /* FIXME: check if imm.ass arrive on Um side */
Harald Weltee8d750e2018-06-10 21:41:35 +02002534 T.start;
2535 alt {
2536 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_DELETE_IND(?, 0))) {
2537 num_del := num_del+1;
2538 repeat;
2539 }
2540 [] RSL_CCHAN.receive {
2541 repeat;
2542 }
2543 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?)) -> value l1_dl {
2544 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2545 var GsmRrMessage rr := dec_GsmRrMessage(l1_dl.payload.data_ind.payload);
2546 if (not match(rr, tr_IMM_ASS(42, ?, 5, ?, ?))) {
2547 /* FIXME: Why are we seeing paging requests on PCH/AGCH? */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002548 //Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected IMM-ASS values on AGCH: ", rr));
Harald Weltee8d750e2018-06-10 21:41:35 +02002549 } else {
2550 num_rx := num_rx+1;
2551 }
2552 repeat;
2553 }
2554 [] L1CTL.receive { repeat; }
2555 [] T.timeout { }
2556 }
2557 res_str := f_fmt_ia_stats(num_tx, num_rx, num_del);
2558 log("AGCH test: " & res_str);
2559 if (num_rx + num_del != num_tx) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002560 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX + DEL != TX ?!?: " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02002561 }
2562 rx_ratio := int2float(num_rx) / int2float(num_tx);
2563 if (rx_ratio < exp_pass*0.8 or rx_ratio > exp_pass*1.2) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002564 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RX ratio ("&float2str(rx_ratio)&") far from expected ("&float2str(exp_pass)&") " & res_str);
Harald Weltee8d750e2018-06-10 21:41:35 +02002565 } else {
2566 setverdict(pass);
2567 }
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002568 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01002569}
2570
Harald Weltee8d750e2018-06-10 21:41:35 +02002571/* send a long burst of 1000 IMM.ASS with 20ms spacing (50 per s); expect 75% of them to be deleted */
2572testcase TC_imm_ass_1000_20ms() runs on test_CT {
2573 f_TC_imm_ass(1000, 0.02, 0.25);
2574}
2575
2576/* send a short burst of 200 IMM.ASS without any spacing; expect 95% of them to be deleted */
2577testcase TC_imm_ass_200_0ms() runs on test_CT {
2578 f_TC_imm_ass(200, 0.0, 0.05);
2579}
2580
2581/* send 150 IMM.ASS at rate of 13/s; expect none of them to be deleted */
2582testcase TC_imm_ass_200_76ms() runs on test_CT {
2583 f_TC_imm_ass(150, 0.076, 1.00);
2584}
2585
2586
2587
Harald Welte48494ca2018-02-25 16:59:50 +01002588/***********************************************************************
2589 * BCCH
2590 ***********************************************************************/
2591
2592/* tuple of Frame Number + decoded SI */
2593type record SystemInformationFn {
2594 GsmFrameNumber frame_number,
2595 SystemInformation si
2596}
2597
2598/* an arbitrary-length vector of decoded SI + gsmtap header */
2599type record of SystemInformationFn SystemInformationVector;
2600
2601/* an array of SI-vectors indexed by TC value */
2602type SystemInformationVector SystemInformationVectorPerTc[8];
2603
2604/* determine if a given SI vector contains given SI type at least once */
2605function f_si_vecslot_contains(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2606 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2607 var integer fn_mod51 := arr[i].frame_number mod 51;
2608 if (not bcch_ext and fn_mod51 == 2 or
2609 bcch_ext and fn_mod51 == 6) {
2610 if (arr[i].si.header.message_type == key) {
2611 return true;
2612 }
2613 }
2614 }
2615 return false;
2616}
2617
2618/* ensure a given TC slot of the SI vector contains given SI type at least once at TC */
2619function f_ensure_si_vec_contains(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2620 if (not f_si_vecslot_contains(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002621 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002622 }
2623}
2624
2625/* check if a given SI vector contains given SI type at least once on any TC */
2626function f_si_vec_contains(SystemInformationVectorPerTc arr, RrMessageType key) return boolean {
2627 for (var integer tc:= 0; tc < sizeof(arr); tc := tc + 1) {
2628 if (f_si_vecslot_contains(arr[tc], key) or
2629 f_si_vecslot_contains(arr[tc], key, true)) {
2630 return true;
2631 }
2632 }
2633 return false;
2634}
2635
2636/* determine if a given SI vector contains given SI type at least N of M times */
2637function f_si_vecslot_contains_n_of_m(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false, integer n := 1, integer m := 4) return boolean {
2638 var integer count := 0;
2639 if (sizeof(arr) < m) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002640 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Error: Insufficient SI in array");
Harald Welte48494ca2018-02-25 16:59:50 +01002641 }
2642 for (var integer i:= 0; i < m; i := i + 1) {
2643 var integer fn_mod51 := arr[i].frame_number mod 51;
2644 if (not bcch_ext and fn_mod51 == 2 or
2645 bcch_ext and fn_mod51 == 6) {
2646 if (arr[i].si.header.message_type == key) {
2647 count := count + 1;
2648 }
2649 }
2650 }
2651 if (count >= n) {
2652 return true;
2653 } else {
2654 return false;
2655 }
2656}
2657
2658/* ensure a given TC slot of the SI vector contains given SI type at least N out of M times at TC */
2659function f_ensure_si_vec_contains_n_of_m(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false, integer n, integer m) {
2660 if (not f_si_vecslot_contains_n_of_m(arr[tc], key, ext_bcch, n, m)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002661 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not ", n, "/", m, " of ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002662 }
2663}
2664
2665/* determine if a given SI vector contains given SI type at least once */
2666function f_si_vecslot_contains_only(SystemInformationVector arr, RrMessageType key, boolean bcch_ext := false) return boolean {
2667 for (var integer i:= 0; i< sizeof(arr); i := i + 1) {
2668 var integer fn_mod51 := arr[i].frame_number mod 51;
2669 if (not bcch_ext and fn_mod51 == 2 or
2670 bcch_ext and fn_mod51 == 6) {
2671 if (arr[i].si.header.message_type != key) {
2672 return false;
2673 }
2674 }
2675 }
2676 return true;
2677}
2678
2679/* ensure a given TC slot of the SI vector contains only given SI type */
2680function f_ensure_si_vec_contains_only(SystemInformationVectorPerTc arr, integer tc, RrMessageType key, boolean ext_bcch := false) {
2681 if (not f_si_vecslot_contains_only(arr[tc], key, ext_bcch)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002682 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Not all ", key, " in TC=", tc, "!"));
Harald Welte48494ca2018-02-25 16:59:50 +01002683 }
2684}
2685
2686/* SI configuration of cell, against which we validate actual SI messages */
2687type set SystemInformationConfig {
2688 boolean bcch_extended,
2689 boolean si1_present,
2690 boolean si2bis_present,
2691 boolean si2ter_present,
2692 boolean si2quater_present,
2693 boolean si7_present,
2694 boolean si8_present,
2695 boolean si9_present,
2696 boolean si13_present,
2697 boolean si13alt_present,
2698 boolean si15_present,
2699 boolean si16_present,
2700 boolean si17_present,
2701 boolean si2n_present,
2702 boolean si21_present,
2703 boolean si22_present
2704}
2705
2706/* validate the SI scheduling according to TS 45.002 version 14.1.0 Release 14, Section 6.3.1.3 */
2707function f_validate_si_scheduling(SystemInformationConfig cfg, SystemInformationVectorPerTc si_per_tc) {
2708 var integer i;
2709 for (i := 0; i < sizeof(si_per_tc); i := i + 1) {
2710 if (sizeof(si_per_tc[i]) == 0) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002711 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No SI messages for TC=", i));
Harald Welte48494ca2018-02-25 16:59:50 +01002712 }
2713 }
2714 if (cfg.si1_present) {
2715 /* ii) System Information Type 1 needs to be sent if frequency hopping is in use or
2716 * when the NCH is present in a cell. If the MS finds another message on BCCH Norm
2717 * when TC = 0, it can assume that System Information Type 1 is not in use. */
2718 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2719 /* make sure *ALL* contain SI1 */
2720 f_ensure_si_vec_contains_only(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_1);
2721 }
2722 f_ensure_si_vec_contains(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_2);
2723 /* iii) A SI 2 message will be sent at least every time TC = 1 */
2724 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_3);
2725 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_3);
2726 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_4);
2727 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_4);
2728
2729 /* iii) System information type 2 bis or 2 ter messages are sent if needed, as determined by the
2730 * system operator. If only one of them is needed, it is sent when TC = 5. If both are
2731 * needed, 2bis is sent when TC = 5 and 2ter is sent at least once within any of 4
2732 * consecutive occurrences of TC = 4. */
2733 if (cfg.si2bis_present and not cfg.si2ter_present) {
2734 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2735 } else if (cfg.si2ter_present and not cfg.si2bis_present) {
2736 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2ter);
2737 } else if (cfg.si2ter_present and cfg.si2bis_present) {
2738 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2bis);
2739 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2ter, false, 1, 4);
2740 }
2741
2742 if (cfg.si7_present or cfg.si8_present) {
2743 /* vi) Use of System Information type 7 and 8 is not always necessary. It is necessary
2744 * if System Information type 4 does not contain all information needed for cell
2745 * selection and reselection. */
2746 if (not cfg.bcch_extended) {
2747 testcase.stop("Error: SI7/SI8 require BCCH Extd.");
2748 }
2749 if (cfg.si7_present) {
2750 f_ensure_si_vec_contains(si_per_tc, 7, SYSTEM_INFORMATION_TYPE_7, true);
2751 }
2752 if (cfg.si8_present) {
2753 f_ensure_si_vec_contains(si_per_tc, 3, SYSTEM_INFORMATION_TYPE_8, true);
2754 }
2755 }
2756
2757 if (cfg.si2quater_present) {
2758 /* iii) System information type 2 quater is sent if needed, as determined by the system
2759 * operator. If sent on BCCH Norm, it shall be sent when TC = 5 if neither of 2bis
2760 * and 2ter are used, otherwise it shall be sent at least once within any of 4
2761 * consecutive occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once
2762 * within any of 4 consecutive occurrences of TC = 5. */
2763 if (not (cfg.bcch_extended)) {
2764 if (not (cfg.si2bis_present or cfg.si2ter_present)) {
2765 f_ensure_si_vec_contains(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater);
2766 } else {
2767 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2quater, false, 1, 4);
2768 }
2769 } else {
2770 f_ensure_si_vec_contains_n_of_m(si_per_tc, 5, SYSTEM_INFORMATION_TYPE_2quater, true, 1, 4);
2771 }
2772 }
2773 if (cfg.si9_present) {
2774 /* vi) System Information type 9 is sent in those blocks with TC = 4 which are specified
2775 * in system information type 3 as defined in 3GPP TS 44.018. */
2776 f_ensure_si_vec_contains(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_9); // FIXME SI3
2777 }
2778 if (cfg.si13_present) {
2779 /* vii) System Information type 13 is only related to the GPRS service. System Information
2780 * Type 13 need only be sent if GPRS support is indicated in one or more of System
2781 * Information Type 3 or 4 or 7 or 8 messages. These messages also indicate if the
2782 * message is sent on the BCCH Norm or if the message is transmitted on the BCCH Ext.
2783 * In the case that the message is sent on the BCCH Norm, it is sent at least once
2784 * within any of 4 consecutive occurrences of TC=4. */
2785 if (not cfg.bcch_extended) {
2786 log("not-bccch-extended");
2787 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13, false, 1, 4);
2788 } else {
2789 log("bccch-extended");
2790 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13, true);
2791 }
2792 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13alt)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002793 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002794 }
2795 }
2796 if (cfg.si16_present or cfg.si17_present) {
2797 /* viii) System Information type 16 and 17 are only related to the SoLSA service. They
2798 * should not be sent in a cell where network sharing is used (see rule xv). */
2799 if (cfg.si22_present) {
2800 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2801 }
2802 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_22)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002803 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002804 }
2805 if (not cfg.bcch_extended) {
2806 testcase.stop("Error: SI16/SI17 requires BCCH Extd!");
2807 }
2808 if (cfg.si16_present) {
2809 f_ensure_si_vec_contains(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_16, true);
2810 }
2811 if (cfg.si17_present) {
2812 f_ensure_si_vec_contains(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_17, true);
2813 }
2814 }
2815
2816 /* ix) System Information type 18 and 20 are sent in order to transmit non-GSM
2817 * broadcast information. The frequency with which they are sent is determined by the
2818 * system operator. System Information type 9 identifies the scheduling of System
2819 * Information type 18 and 20 messages. */
2820
2821 /* x) System Information Type 19 is sent if COMPACT neighbours exist. If System
2822 * Information Type 19 is present, then its scheduling shall be indicated in System
2823 * Information Type 9. */
2824
2825 if (cfg.si15_present) {
2826 /* xi) System Information Type 15 is broadcast if dynamic ARFCN mapping is used in the
2827 * PLMN. If sent on BCCH Norm, it is sent at least once within any of 4 consecutive
2828 * occurrences of TC = 4. If sent on BCCH Ext, it is sent at least once within any of
2829 * 4 consecutive occurrences of TC = 1. */
2830 if (not cfg.bcch_extended) {
2831 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_15, false, 1, 4);
2832 } else {
2833 f_ensure_si_vec_contains_n_of_m(si_per_tc, 1, SYSTEM_INFORMATION_TYPE_15, true, 1, 4);
2834 }
2835 }
2836 if (cfg.si13alt_present) {
2837 /* xii) System Information type 13 alt is only related to the GERAN Iu mode. System
2838 * Information Type 13 alt need only be sent if GERAN Iu mode support is indicated in
2839 * one or more of System Information Type 3 or 4 or 7 or 8 messages and SI 13 is not
2840 * broadcast. These messages also indicate if the message is sent on the BCCH Norm or
2841 * if the message is transmitted on the BCCH Ext. In the case that the message is sent
2842 * on the BCCH Norm, it is sent at least once within any of 4 consecutive occurrences
2843 * of TC = 4. */
2844 if (cfg.si13_present) {
2845 testcase.stop("Error: Cannot have SI13alt and SI13");
2846 }
2847 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_13)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002848 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI13alt and SI13");
Harald Welte48494ca2018-02-25 16:59:50 +01002849 }
2850 if (not cfg.bcch_extended) {
2851 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_13alt, false, 1, 4);
2852 } else {
2853 f_ensure_si_vec_contains(si_per_tc, 0, SYSTEM_INFORMATION_TYPE_13alt, true);
2854 }
2855 }
2856 if (cfg.si2n_present) {
2857 /* xiii) System Information Type 2n is optionally sent on BCCH Norm or BCCH Ext if needed,
2858 * as determined by the system operator. In the case that the message is sent on the
2859 * BCCH Norm, it is sent at least once within any of 4 consecutive occurrences of TC =
2860 * 4. If the message is sent on BCCH Ext, it is sent at least once within any of 2
2861 * consecutive occurrences of TC = 4. */
2862 if (not cfg.bcch_extended) {
2863 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, false, 1, 4);
2864 } else {
2865 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_2n, true, 2, 4);
2866 }
2867 }
2868 if (cfg.si21_present) {
2869 /* xiv) System Information Type 21 is optionally sent on BCCH Norm or BCCH Ext, as
2870 * determined by the system operator. If Extended Access Barring is in use in the cell
2871 * then this message is sent at least once within any of 4 consecutive occurrences of
2872 * TC = 4 regardless if it is sent on BCCH Norm or BCCH Ext. If BCCH Ext is used in a
2873 * cell then this message shall only be sent on BCCH Ext. */
2874 if (not cfg.bcch_extended) {
2875 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, false, 1, 4);
2876 } else {
2877 f_ensure_si_vec_contains_n_of_m(si_per_tc, 4, SYSTEM_INFORMATION_TYPE_21, true, 1, 4);
2878 if (f_si_vecslot_contains(si_per_tc[4], SYSTEM_INFORMATION_TYPE_21)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002879 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI21 on BCCH Norm if BCCH Extd enabled!");
Harald Welte48494ca2018-02-25 16:59:50 +01002880 }
2881 }
2882 }
2883 if (cfg.si22_present) {
2884 /* xv) System Information Type 22 is sent if network sharing is in use in the cell. It
2885 * should not be sent in a cell where SoLSA is used (see rule viii). System
2886 * Information Type 22 instances shall be sent on BCCH Ext within any occurrence of TC
2887 * =2 and TC=6. */
2888 if (cfg.si16_present or cfg.si17_present) {
2889 testcase.stop("Error: Cannot have SI16/SI17 and SI22!");
2890 }
2891 if (f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_16) or
2892 f_si_vec_contains(si_per_tc, SYSTEM_INFORMATION_TYPE_17)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002893 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Cannot have SI16/SI17 and SI22!");
Harald Welte48494ca2018-02-25 16:59:50 +01002894 }
2895 if (not cfg.bcch_extended) {
2896 testcase.stop("Error: SI22 requires BCCH Extd!");
2897 } else {
2898 f_ensure_si_vec_contains_only(si_per_tc, 2, SYSTEM_INFORMATION_TYPE_22, true);
2899 f_ensure_si_vec_contains_only(si_per_tc, 6, SYSTEM_INFORMATION_TYPE_22, true);
2900 }
2901 }
2902}
2903
2904/* sample Systme Information for specified duration via L1CTL */
2905function f_l1_sample_si(L1CTL_PT pt, float duration := 8.0) return SystemInformationVectorPerTc {
2906 timer T := duration;
2907 var SystemInformationVectorPerTc si_per_tc;
2908 var L1ctlDlMessage l1_dl;
2909
2910 /* initialize all per-TC vectors empty */
2911 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2912 si_per_tc[i] := {};
2913 }
2914
2915 /* flush all previous L1 queued msgs */
2916 pt.clear;
2917
2918 T.start;
2919 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01002920 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
Harald Welte48494ca2018-02-25 16:59:50 +01002921 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
2922 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
2923 log("Ignoring non-RR SI ", l1_dl);
2924 repeat;
2925 }
2926 var SystemInformationFn sig := {
2927 frame_number := l1_dl.dl_info.frame_nr,
2928 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
2929 }
2930 var integer tc := f_gsm_compute_tc(sig.frame_number);
2931 log("SI received at TC=", tc, ": ", sig.si);
2932 /* append to the per-TC bucket */
2933 si_per_tc[tc] := si_per_tc[tc] & { sig };
2934 repeat;
2935 }
2936 [] pt.receive { repeat; }
2937 [] T.timeout { }
2938 }
2939
2940 for (var integer i:= 0; i < sizeof(si_per_tc); i := i+1) {
2941 log(testcasename(), ": TC=", i, " has #of SI=", sizeof(si_per_tc[i]));
2942 }
2943 log("si_per_tc=", si_per_tc);
2944 return si_per_tc;
2945}
2946
2947/* helper function: Set given SI via RSL + validate scheduling.
2948 * CALLER MUST MAKE SURE TO CHANGE GLOBAL si_cfg! */
2949function f_TC_si_sched() runs on test_CT {
2950 var SystemInformationVectorPerTc si_per_tc;
2951 f_init_l1ctl();
2952 f_l1_tune(L1CTL);
2953
2954 /* Sample + Validate Scheduling */
2955 si_per_tc := f_l1_sample_si(L1CTL);
2956 f_validate_si_scheduling(si_cfg, si_per_tc);
2957
2958 setverdict(pass);
2959}
2960
2961testcase TC_si_sched_default() runs on test_CT {
2962 f_init();
Harald Welte0cae4552018-03-09 22:20:26 +01002963 /* 2+3+4 are mandatory and set in f_init() */
2964 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002965 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0cae4552018-03-09 22:20:26 +01002966}
2967
2968testcase TC_si_sched_1() runs on test_CT {
2969 f_init();
2970 si_cfg.si1_present := true;
2971 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_1, '5506198fb38000000000000000000000000000e504002b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01002972 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002973 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002974}
2975
2976testcase TC_si_sched_2bis() runs on test_CT {
2977 f_init();
2978 si_cfg.si2bis_present := true;
2979 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2980 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002981 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002982}
2983
2984testcase TC_si_sched_2ter() runs on test_CT {
2985 f_init();
2986 si_cfg.si2ter_present := true;
2987 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2988 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002989 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01002990}
2991
2992testcase TC_si_sched_2ter_2bis() runs on test_CT {
2993 f_init();
2994 si_cfg.si2bis_present := true;
2995 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
2996 si_cfg.si2ter_present := true;
2997 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
2998 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02002999 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003000}
3001
3002testcase TC_si_sched_2quater() runs on test_CT {
3003 f_init();
3004 si_cfg.si2quater_present := true;
3005 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3006 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003007 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003008}
3009
3010testcase TC_si_sched_13() runs on test_CT {
3011 f_init();
3012 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003013 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003014 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003015 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003016}
3017
3018testcase TC_si_sched_13_2bis_2ter_2quater() runs on test_CT {
3019 f_init();
3020 si_cfg.si2bis_present := true;
3021 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2bis, '550602bfe809b3ff00000000000000000000007900002b'O);
3022 si_cfg.si2ter_present := true;
3023 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2ter, '010603bf66b0aa0a00000002000000000000002b2b2b2b'O);
3024 si_cfg.si2quater_present := true;
3025 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_2quater, '050607a8a0364aa698d72ff424feee0506d5e7fff02043'O);
3026 si_cfg.si13_present := true;
Harald Welte5618c2a2018-04-15 16:24:46 +02003027 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, '0106009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O);
Harald Welte48494ca2018-02-25 16:59:50 +01003028 f_TC_si_sched();
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte48494ca2018-02-25 16:59:50 +01003030}
3031
3032
Harald Welte68e495b2018-02-25 00:05:57 +01003033testcase TC_bcch_info() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003034 f_init();
Harald Welte68e495b2018-02-25 00:05:57 +01003035 /* FIXME: enable / disable individual BCCH info */
3036 //ts_RSL_BCCH_INFO(si_type, info);
3037 /* expect no ERROR REPORT after either of them *
3038 /* negative test: ensure ERROR REPORT on unsupported types */
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003039 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte68e495b2018-02-25 00:05:57 +01003040}
3041
Harald Welte93640c62018-02-25 16:59:33 +01003042/***********************************************************************
3043 * Low-Level Protocol Errors / ERROR REPORT
3044 ***********************************************************************/
3045
Harald Welte01d982c2018-02-25 01:31:40 +01003046private function f_exp_err_rep(template RSL_Cause cause) runs on test_CT {
3047 timer T := 5.0;
3048 T.start;
3049 alt {
3050 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(cause))) {
3051 setverdict(pass);
3052 }
3053 [] RSL_CCHAN.receive(tr_RSL_UD(tr_RSL_ERROR_REPORT(?))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003054 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong cause in RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003055 }
3056 [] RSL_CCHAN.receive {
3057 repeat;
3058 }
3059 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003060 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RSL ERR REP");
Harald Welte01d982c2018-02-25 01:31:40 +01003061 }
3062 }
3063}
3064
3065/* Provoke a protocol error (message too short) and match on ERROR REPORT */
3066testcase TC_rsl_protocol_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003067 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003068 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3069 rsl.ies := omit;
3070 RSL_CCHAN.send(ts_RSL_UD(rsl));
3071
3072 f_exp_err_rep(RSL_ERR_PROTO);
3073}
3074
3075/* Provoke a mandatory IE error and match on ERROR REPORT */
3076testcase TC_rsl_mand_ie_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003077 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003078
3079 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3080 rsl.ies := { rsl.ies[0] };
3081 RSL_CCHAN.send(ts_RSL_UD(rsl));
3082
3083 f_exp_err_rep(RSL_ERR_MAND_IE_ERROR);
3084}
3085
3086/* Provoke an IE content error and match on ERROR REPORT */
3087testcase TC_rsl_ie_content_error() runs on test_CT {
Harald Welte10474062019-05-30 16:48:17 +02003088 f_init();
Harald Welte01d982c2018-02-25 01:31:40 +01003089 var RSL_Message rsl := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3090 rsl.ies[1].body.sysinfo_type := RSL_SYSTEM_INFO_5;
3091 RSL_CCHAN.send(ts_RSL_UD(rsl));
3092
3093 f_exp_err_rep(RSL_ERR_IE_CONTENT);
3094}
3095
Harald Welteee25aae2019-05-19 14:32:37 +02003096/* attempt to activate channel with wrong RSL Message Discriminator IE */
3097function f_TC_chan_act_wrong_mdisc(charstring id) runs on ConnHdlr {
3098 var template RSL_Message rsl := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3099 rsl.msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RESERVED, false);
3100 RSL.send(rsl);
3101 f_rslem_unregister(0, g_chan_nr);
3102}
3103testcase TC_err_rep_wrong_mdisc() runs on test_CT {
3104 var ConnHdlr vc_conn;
3105 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3106
Harald Welte10474062019-05-30 16:48:17 +02003107 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003108
3109 vc_conn := f_start_handler(refers(f_TC_chan_act_wrong_mdisc), pars);
3110 vc_conn.done;
3111 f_exp_err_rep(RSL_ERR_MSG_DISCR);
3112
3113 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
3114}
3115
3116/* Send messages with wrong message type */
3117function f_TC_wrong_msg_type_dchan(charstring id) runs on ConnHdlr {
3118 var template (value) RSL_Message rsl_tx;
3119 rsl_tx := ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode);
3120 rsl_tx.msg_type := RSL_MT_NOT_CMD;
3121 RSL.send(rsl_tx);
3122 f_rslem_unregister(0, g_chan_nr);
3123}
3124function f_TC_wrong_msg_type_rll(charstring id) runs on ConnHdlr {
3125 var template (value) RSL_Message rsl_tx;
3126 /* we first have to activate the dedicated channel */
3127 f_rsl_chan_act(g_pars.chan_mode);
3128 /* ... to then send an invalid RLL message */
3129 rsl_tx := ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O);
3130 rsl_tx.msg_type := RSL_MT_CBCH_LOAD_IND;
3131 RSL.send(rsl_tx);
3132 f_rslem_unregister(0, g_chan_nr);
3133}
3134testcase TC_err_rep_wrong_msg_type() runs on test_CT {
3135 var ConnHdlr vc_conn;
3136 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3137 var template (value) RSL_Message rsl_tx;
3138
Harald Welte10474062019-05-30 16:48:17 +02003139 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003140
3141 /* Common Channel with wrong message type */
3142 RSL_CCHAN.clear;
3143 rsl_tx := valueof(ts_RSL_BCCH_INFO(RSL_SYSTEM_INFO_1, ''O));
3144 rsl_tx.msg_type := RSL_MT_LOCATION_INFO;
3145 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3146 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3147
3148 /* TRX Management */
3149 RSL_CCHAN.clear;
3150 rsl_tx := ts_RSL_SACCH_FILL(RSL_SYSTEM_INFO_5, ''O);
3151 rsl_tx.msg_type := RSL_MT_UNIT_DATA_IND;
3152 RSL_CCHAN.send(ts_RSL_UD(rsl_tx));
3153 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3154
3155 /* Dedicated Channel */
3156 RSL_CCHAN.clear;
3157 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_dchan), pars);
3158 vc_conn.done;
3159 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3160
3161 /* RLL */
3162 RSL_CCHAN.clear;
3163 vc_conn := f_start_handler(refers(f_TC_wrong_msg_type_rll), pars);
3164 vc_conn.done;
3165 f_exp_err_rep(RSL_ERR_MSG_TYPE);
3166}
3167
3168/* Send messages in wrong sequence (RLL to an inactive lchan) */
3169function f_TC_err_rep_wrong_sequence(charstring id) runs on ConnHdlr {
3170 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, ts_RslLinkID_DCCH(0), '0102'O));
3171 f_rslem_unregister(0, g_chan_nr);
3172}
3173testcase TC_err_rep_wrong_sequence() runs on test_CT {
3174 var ConnHdlr vc_conn;
3175 var ConnHdlrPars pars := valueof(t_Pars(ts_RslChanNr_SDCCH4(0,0), ts_RSL_ChanMode_SIGN));
3176
Harald Welte10474062019-05-30 16:48:17 +02003177 f_init();
Harald Welteee25aae2019-05-19 14:32:37 +02003178
3179 RSL_CCHAN.clear;
3180 vc_conn := f_start_handler(refers(f_TC_err_rep_wrong_sequence), pars);
3181 vc_conn.done;
3182 f_exp_err_rep(RSL_ERR_MSG_SEQ);
3183}
3184
Harald Welte93640c62018-02-25 16:59:33 +01003185/***********************************************************************
3186 * IPA CRCX/MDCX/DLCS media stream handling
3187 ***********************************************************************/
3188
Harald Weltea871a382018-02-25 02:03:14 +01003189/* Send IPA DLCX to inactive lchan */
3190function f_TC_ipa_dlcx_not_active(charstring id) runs on ConnHdlr {
Harald Welte1eba3742018-02-25 12:48:14 +01003191 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, 0), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3192 "IPA DLCX ACK");
Harald Weltea871a382018-02-25 02:03:14 +01003193}
3194testcase TC_ipa_dlcx_not_active() runs on test_CT {
3195 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003196 f_init();
Harald Weltea871a382018-02-25 02:03:14 +01003197 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_dlcx_not_active), pars);
3198 vc_conn.done;
3199}
Harald Welte68e495b2018-02-25 00:05:57 +01003200
Harald Weltea3f1df92018-02-25 12:49:55 +01003201/* Send IPA CRCX twice to inactive lchan */
3202function f_TC_ipa_crcx_twice_not_active(charstring id) runs on ConnHdlr {
3203 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3204 "IPA CRCX ACK");
3205 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, RSL_ERR_RES_UNAVAIL),
3206 "IPA CRCX NACK");
3207}
3208testcase TC_ipa_crcx_twice_not_active() runs on test_CT {
3209 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003210 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01003211 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_twice_not_active), pars);
3212 vc_conn.done;
3213}
3214
3215/* Regular sequence of CRCX/MDCX/DLCX */
3216function f_TC_ipa_crcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3217 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3218 "IPA CRCX ACK");
3219 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3220 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3221 var uint7_t rtp_pt2 := f_rnd_int(127);
3222 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3223 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3224 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3225 "IPA MDCX ACK");
3226 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3227 "IPA DLCX ACK");
3228}
3229testcase TC_ipa_crcx_mdcx_dlcx_not_active() runs on test_CT {
3230 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003231 f_init();
Harald Weltea3f1df92018-02-25 12:49:55 +01003232 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_dlcx_not_active), pars);
3233 vc_conn.done;
3234}
3235
Harald Welte3ae11da2018-02-25 13:36:06 +01003236/* Sequence of CRCX, 2x MDCX, DLCX */
3237function f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active(charstring id) runs on ConnHdlr {
3238 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_ACK(g_chan_nr, ?, ?, ?),
3239 "IPA CRCX ACK");
3240 var uint32_t remote_ip := f_rnd_int(c_UINT32_MAX);
3241 var uint16_t remote_port := f_rnd_int(c_UINT16_MAX);
3242 var uint7_t rtp_pt2 := f_rnd_int(127);
3243 var uint16_t fake_conn_id := 23; /* we're too lazy to read it out from the CRCX ACK above */
3244 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3245 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3246 "IPA MDCX ACK");
3247 /* Second MDCX */
3248 remote_ip := f_rnd_int(c_UINT32_MAX);
3249 remote_port := f_rnd_int(c_UINT16_MAX);
3250 f_rsl_transceive(ts_RSL_IPA_MDCX(g_chan_nr, fake_conn_id, remote_ip, remote_port, rtp_pt2),
3251 tr_RSL_IPA_MDCX_ACK(g_chan_nr, ?, ?, ?, rtp_pt2),
3252 "IPA MDCX ACK");
3253 f_rsl_transceive(ts_RSL_IPA_DLCX(g_chan_nr, fake_conn_id), tr_RSL_IPA_DLCX_ACK(g_chan_nr, ?, ?),
3254 "IPA DLCX ACK");
3255}
3256testcase TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() runs on test_CT {
3257 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
Harald Welte10474062019-05-30 16:48:17 +02003258 f_init();
Harald Welte3ae11da2018-02-25 13:36:06 +01003259 var ConnHdlr vc_conn := f_start_handler(refers(f_TC_ipa_crcx_mdcx_mdcx_dlcx_not_active), pars);
3260 vc_conn.done;
3261}
3262
Harald Welte9912eb52018-02-25 13:30:15 +01003263/* IPA CRCX on SDCCH/4 and SDCCH/8 (doesn't make sense) */
3264function f_TC_ipa_crcx_sdcch_not_active(charstring id) runs on ConnHdlr {
3265 f_rsl_transceive(ts_RSL_IPA_CRCX(g_chan_nr), tr_RSL_IPA_CRCX_NACK(g_chan_nr, ?),
3266 "IPA CRCX NACK");
3267}
3268testcase TC_ipa_crcx_sdcch_not_active() runs on test_CT {
3269 var ConnHdlrPars pars;
3270 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02003271 f_init();
Harald Welte9912eb52018-02-25 13:30:15 +01003272
3273 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,1), ts_RSL_ChanMode_SIGN));
3274 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3275 vc_conn.done;
3276
3277 pars := valueof(t_Pars(t_RslChanNr_SDCCH8(6,5), ts_RSL_ChanMode_SIGN));
3278 vc_conn := f_start_handler(refers(f_TC_ipa_crcx_sdcch_not_active), pars);
3279 vc_conn.done;
3280}
3281
Harald Weltea3f1df92018-02-25 12:49:55 +01003282
Harald Welte883340c2018-02-28 18:59:29 +01003283/***********************************************************************
3284 * PCU Socket related tests
3285 ***********************************************************************/
3286
Harald Welte07bd2d22019-05-25 11:03:30 +02003287/* Verify no RTS before ACT_REQ; verify RTS after ACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003288friend function f_TC_pcu_act_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr, boolean exp_success)
Harald Welte883340c2018-02-28 18:59:29 +01003289runs on test_CT {
3290 timer T := 3.0;
3291
3292 /* we don't expect any RTS.req before PDCH are active */
3293 T.start;
3294 alt {
3295 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003296 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCU RTS.req before PDCH active?");
Harald Welte883340c2018-02-28 18:59:29 +01003297 }
3298 [] PCU.receive { repeat; }
3299 [] T.timeout { }
3300 }
3301
3302 /* Send PDCH activate request for known PDCH timeslot */
3303 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, ts_nr)));
3304
3305 /* we now expect RTS.req for this timeslot (only) */
3306 T.start;
3307 alt {
3308 [exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
3309 setverdict(pass);
3310 }
3311 [not exp_success] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3312 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003313 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RTS.req for supposedly failing activation");
Harald Welte883340c2018-02-28 18:59:29 +01003314 }
3315 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003316 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "RTS.req for wrong TRX/TS");
Harald Welte883340c2018-02-28 18:59:29 +01003317 }
3318 [] PCU.receive { repeat; }
3319 [exp_success] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003320 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003321 }
3322 [not exp_success] T.timeout {
3323 setverdict(pass);
3324 }
3325 }
3326}
3327
Harald Welte07bd2d22019-05-25 11:03:30 +02003328/* verify no more RTS after DEACT_REQ */
Harald Weltead033dc2019-05-25 17:28:16 +02003329friend function f_TC_pcu_deact_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr)
Harald Welte883340c2018-02-28 18:59:29 +01003330runs on test_CT {
3331 timer T := 3.0;
3332
3333 /* Send PDCH activate request for known PDCH timeslot */
3334 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, ts_nr)));
3335
3336 PCU.clear;
3337 /* we now expect no RTS.req for this timeslot */
3338 T.start;
3339 alt {
3340 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr))) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003341 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected PCU RTS.req");
Harald Welte883340c2018-02-28 18:59:29 +01003342 }
3343 [] PCU.receive { repeat; }
3344 [] T.timeout {
3345 setverdict(pass);
3346 }
3347 }
3348}
3349
Harald Weltead033dc2019-05-25 17:28:16 +02003350friend function f_init_pcu_test() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003351 f_init();
3352 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_VERSION, testcasename())));
3353}
3354
Harald Welte883340c2018-02-28 18:59:29 +01003355/* PDCH activation via PCU socket; check for presence of RTS.req */
3356testcase TC_pcu_act_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003357 f_init_pcu_test();
3358
Harald Welte883340c2018-02-28 18:59:29 +01003359 f_TC_pcu_act_req(0, 0, 7, true);
3360}
3361
3362/* PDCH activation via PCU socket on non-PDCU timeslot */
3363testcase TC_pcu_act_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003364 f_init_pcu_test();
3365
Harald Welte883340c2018-02-28 18:59:29 +01003366 f_TC_pcu_act_req(0, 0, 1, false);
3367}
3368
3369/* PDCH activation via PCU socket on wrong BTS */
3370testcase TC_pcu_act_req_wrong_bts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003371 f_init_pcu_test();
3372
Harald Welte883340c2018-02-28 18:59:29 +01003373 f_TC_pcu_act_req(23, 0, 7, false);
3374}
3375
3376/* PDCH activation via PCU socket on wrong TRX */
3377testcase TC_pcu_act_req_wrong_trx() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003378 f_init_pcu_test();
3379
Harald Welte883340c2018-02-28 18:59:29 +01003380 f_TC_pcu_act_req(0, 23, 7, false);
3381}
3382
3383/* PDCH deactivation via PCU socket; check for absence of RTS.req */
3384testcase TC_pcu_deact_req() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003385 f_init_pcu_test();
3386
Harald Welte883340c2018-02-28 18:59:29 +01003387 /* Activate PDCH */
3388 f_TC_pcu_act_req(0, 0, 7, true);
3389 f_sleep(1.0);
3390 /* and De-Activate again */
3391 f_TC_pcu_deact_req(0, 0, 7);
3392}
3393
3394/* Attempt to deactivate a PDCH on a non-PDCH timeslot */
3395testcase TC_pcu_deact_req_wrong_ts() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003396 f_init_pcu_test();
3397
Harald Welte883340c2018-02-28 18:59:29 +01003398 f_TC_pcu_deact_req(0, 0, 1);
3399}
3400
3401/* Test the PCU->BTS Version and BTS->PCU SI13 handshake */
3402testcase TC_pcu_ver_si13() runs on test_CT {
3403 const octetstring si13 := '00010203040506070909'O;
3404 var PCUIF_send_data sd;
3405 timer T:= 3.0;
Max2c6f5632019-03-18 17:25:17 +01003406 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003407
3408 /* Set SI13 via RSL */
3409 f_rsl_bcch_fill_raw(RSL_SYSTEM_INFO_13, si13);
Max2c6f5632019-03-18 17:25:17 +01003410
Harald Welte883340c2018-02-28 18:59:29 +01003411 T.start;
3412 alt {
3413 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_DATA_IND(0, 0, 0, ?, PCU_IF_SAPI_BCCH))) -> value sd {
3414 if (substr(sd.data.u.data_ind.data, 0, lengthof(si13)) == si13) {
3415 setverdict(pass);
3416 } else {
3417 repeat;
3418 }
3419 }
3420 [] PCU.receive { repeat; }
3421 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SI13");
Harald Welte883340c2018-02-28 18:59:29 +01003423 }
3424 }
3425}
3426
3427private const octetstring c_PCU_DATA := '000102030405060708090a0b0c0d0e0f10111213141516'O;
3428
3429/* helper function to send a PCU DATA.req */
Harald Weltead033dc2019-05-25 17:28:16 +02003430friend function f_pcu_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte883340c2018-02-28 18:59:29 +01003431 uint8_t block_nr, uint32_t fn, PCUIF_Sapi sapi, octetstring data)
3432runs on test_CT
3433{
3434 PCU.send(t_SD_PCUIF(g_pcu_conn_id,
3435 ts_PCUIF_DATA_REQ(bts_nr, trx_nr, ts_nr, block_nr, fn, sapi, data)));
3436}
3437
3438/* helper function to wait for RTS.ind for given SAPI on given BTS/TRX/TS and then send */
Harald Weltead033dc2019-05-25 17:28:16 +02003439friend function f_pcu_wait_rts_and_data_req(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
3440 PCUIF_Sapi sapi, octetstring data)
Harald Welte883340c2018-02-28 18:59:29 +01003441runs on test_CT
3442{
3443 var PCUIF_send_data sd;
3444
3445 timer T := 3.0;
3446 T.start;
3447 alt {
3448 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id,
3449 tr_PCUIF_RTS_REQ(bts_nr, trx_nr, ts_nr, sapi))) -> value sd {
3450 f_pcu_data_req(bts_nr, trx_nr, ts_nr, sd.data.u.rts_req.block_nr,
3451 sd.data.u.rts_req.fn, sapi, data);
3452 }
3453 [] PCU.receive { repeat; }
3454 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003455 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RTS.ind");
Harald Welte883340c2018-02-28 18:59:29 +01003456 }
3457 }
3458}
3459
3460/* Send DATA.req on invalid BTS */
3461testcase TC_pcu_data_req_wrong_bts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003462 var TfiUsfArr tua := f_TfiUsfArrInit();
3463 var octetstring data := '0000'O & f_rnd_octstring(21);
3464
3465 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003466
Harald Welte883340c2018-02-28 18:59:29 +01003467 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003468 f_TfiUsfArrSet(tua, 7, 0);
3469 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3470 f_sleep(1.0);
3471
3472 f_pcu_to_l1(23, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003473}
3474
3475/* Send DATA.req on invalid TRX */
3476testcase TC_pcu_data_req_wrong_trx() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003477 var TfiUsfArr tua := f_TfiUsfArrInit();
3478 var octetstring data := '0000'O & f_rnd_octstring(21);
3479
3480 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003481
Harald Welte883340c2018-02-28 18:59:29 +01003482 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003483 f_TfiUsfArrSet(tua, 7, 0);
3484 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3485 f_sleep(1.0);
3486
3487 f_pcu_to_l1(0, 100, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003488}
3489
3490/* Send DATA.req on invalid timeslot */
3491testcase TC_pcu_data_req_wrong_ts() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003492 var TfiUsfArr tua := f_TfiUsfArrInit();
3493 var octetstring data := '0000'O & f_rnd_octstring(21);
3494
3495 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003496
Harald Welte883340c2018-02-28 18:59:29 +01003497 f_TC_pcu_act_req(0, 0, 7, true);
Harald Welte7162a612019-05-26 12:56:09 +02003498 f_TfiUsfArrSet(tua, 7, 0);
3499 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3500 f_sleep(1.0);
3501
3502 f_pcu_to_l1(0, 0, 70, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003503}
3504
3505/* Send DATA.req on timeslot that hasn't been activated */
3506testcase TC_pcu_data_req_ts_inactive() runs on test_CT {
Harald Welte7162a612019-05-26 12:56:09 +02003507 var TfiUsfArr tua := f_TfiUsfArrInit();
3508 var octetstring data := '0000'O & f_rnd_octstring(21);
Max2c6f5632019-03-18 17:25:17 +01003509
Harald Welte7162a612019-05-26 12:56:09 +02003510 f_virtphy_common();
3511
3512 f_TfiUsfArrSet(tua, 7, 0);
3513 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3514 f_sleep(1.0);
3515
3516 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data, false, false);
Harald Welte883340c2018-02-28 18:59:29 +01003517}
3518
Harald Weltead033dc2019-05-25 17:28:16 +02003519private function f_pcu_to_l1(uint8_t bts_nr, uint8_t trx_nr, uint8_t ts_nr,
Harald Welte7162a612019-05-26 12:56:09 +02003520 PCUIF_Sapi sapi, octetstring data, boolean expect_data := true,
3521 boolean wait_rts := true)
3522runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003523 timer T := 5.0;
Harald Welte7162a612019-05-26 12:56:09 +02003524 var L1ctlDlMessage rx_dl;
Harald Weltead033dc2019-05-25 17:28:16 +02003525
3526 PCU.clear;
Harald Welte7162a612019-05-26 12:56:09 +02003527 if (wait_rts) {
3528 f_pcu_wait_rts_and_data_req(bts_nr, trx_nr, ts_nr, sapi, data);
3529 } else {
3530 f_pcu_data_req(bts_nr, trx_nr, ts_nr, 0, 0, sapi, data);
3531 }
Harald Weltead033dc2019-05-25 17:28:16 +02003532
3533 T.start;
3534 alt {
Harald Welte7162a612019-05-26 12:56:09 +02003535 [expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) {
Harald Weltead033dc2019-05-25 17:28:16 +02003536 /* FIXME: why is fn of DATA_IND different to fn of RTS / DATA_REQ above? */
3537 setverdict(pass);
3538 }
Harald Welte7162a612019-05-26 12:56:09 +02003539 [not expect_data] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PDCH(ts_nr), ?, data)) -> value rx_dl {
3540 setverdict(fail, "Received unexpected ", rx_dl);
3541 }
Harald Weltead033dc2019-05-25 17:28:16 +02003542 [] L1CTL.receive {
3543 repeat;
3544 }
Harald Welte7162a612019-05-26 12:56:09 +02003545 [expect_data] T.timeout {
Harald Weltead033dc2019-05-25 17:28:16 +02003546 setverdict(fail, "Timeout waiting for ", data);
3547 }
Harald Welte7162a612019-05-26 12:56:09 +02003548 [not expect_data] T.timeout {
3549 setverdict(pass);
3550 }
Harald Weltead033dc2019-05-25 17:28:16 +02003551 }
3552}
3553
3554private function f_disable_dynamic_ts() runs on test_CT
3555{
3556 f_init_vty_bsc();
3557 /* I'm not quite sure why we need this with osmo-bts-virtual. Somehow it deosn't seem to
3558 * support dynamic timeslots? But it uses the same scheduler as osmo-bts-trx ?!? */
3559 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 3"}, "phys_chan_config TCH/F");
3560 f_vty_config2(BSCVTY, {"network", "bts 0", "trx 0", "timeslot 4"}, "phys_chan_config TCH/F");
Max2c6f5632019-03-18 17:25:17 +01003561 f_init_pcu_test();
Harald Weltead033dc2019-05-25 17:28:16 +02003562}
3563
3564private function f_virtphy_common() runs on test_CT {
3565 f_disable_dynamic_ts();
3566 f_init_l1ctl();
3567 f_l1_tune(L1CTL);
3568}
3569
3570testcase TC_pcu_data_req_pdtch() runs on test_CT {
3571 var TfiUsfArr tua := f_TfiUsfArrInit();
3572 var octetstring data := '0000'O & f_rnd_octstring(21);
3573
3574 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003575
Harald Welte883340c2018-02-28 18:59:29 +01003576 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003577 f_TfiUsfArrSet(tua, 7, 0);
3578 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3579 f_sleep(1.0);
3580
3581 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PDTCH, data); //c_PCU_DATA);
Harald Welte883340c2018-02-28 18:59:29 +01003582}
3583
3584testcase TC_pcu_data_req_ptcch() runs on test_CT {
Harald Weltead033dc2019-05-25 17:28:16 +02003585 var TfiUsfArr tua := f_TfiUsfArrInit();
3586 var octetstring data := '0000'O & f_rnd_octstring(21);
3587
3588 f_virtphy_common();
Max2c6f5632019-03-18 17:25:17 +01003589
Harald Welte883340c2018-02-28 18:59:29 +01003590 f_TC_pcu_act_req(0, 0, 7, true);
Harald Weltead033dc2019-05-25 17:28:16 +02003591 f_TfiUsfArrSet(tua, 7, 0);
3592 f_L1CTL_TBF_CFG(L1CTL, false, tua);
3593 f_sleep(1.0);
3594
3595 f_pcu_to_l1(0, 0, 7, PCU_IF_SAPI_PTCCH, data);
Harald Welte883340c2018-02-28 18:59:29 +01003596}
3597
3598/* Send AGCH from PCU; check it appears on Um side */
3599testcase TC_pcu_data_req_agch() runs on test_CT {
3600 timer T := 3.0;
Max2c6f5632019-03-18 17:25:17 +01003601 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003602 f_init_l1ctl();
3603 f_l1_tune(L1CTL);
3604
3605 f_TC_pcu_act_req(0, 0, 7, true);
3606 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_AGCH, c_PCU_DATA);
3607
3608 T.start;
3609 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003610 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
Harald Welte883340c2018-02-28 18:59:29 +01003611 setverdict(pass);
3612 }
3613 [] L1CTL.receive { repeat; }
3614 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003615 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003616 }
3617 }
3618}
3619
Harald Welte928622b2019-05-26 13:22:59 +02003620/* Send AGCH from PCU; check it appears on Um side */
3621testcase TC_pcu_data_req_pch() runs on test_CT {
3622 timer T := 3.0;
3623 f_init_pcu_test();
3624 f_init_l1ctl();
3625 f_l1_tune(L1CTL);
3626
3627 f_TC_pcu_act_req(0, 0, 7, true);
3628 /* three characters prefix: last 3 digits of IMSI as ASCII */
3629 f_pcu_data_req(0, 0, 7, 0, 0, PCU_IF_SAPI_PCH, '313233'O & c_PCU_DATA);
3630
3631 T.start;
3632 alt {
3633 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, c_PCU_DATA)) {
3634 setverdict(pass);
3635 }
3636 [] L1CTL.receive { repeat; }
3637 [] T.timeout {
3638 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated PCH block on Um");
3639 }
3640 }
3641}
3642
Harald Welte883340c2018-02-28 18:59:29 +01003643/* Send IMM.ASS from PCU for PCH; check it appears on Um side */
3644testcase TC_pcu_data_req_imm_ass_pch() runs on test_CT {
3645 var octetstring imm_ass := f_rnd_octstring(23);
Max2c6f5632019-03-18 17:25:17 +01003646 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003647 f_init_l1ctl();
3648 f_l1_tune(L1CTL);
3649
3650 /* append 3 last imsi digits so BTS can compute pagng group */
3651 var uint32_t fn := f_PCUIF_tx_imm_ass_pch(PCU, g_pcu_conn_id, imm_ass, '123459987'H);
3652
3653 timer T := 0.5;
3654 T.start;
3655 alt {
Harald Weltef8df4cb2018-03-10 15:15:08 +01003656 [] L1CTL.receive(tr_L1CTL_DATA_IND(t_RslChanNr_PCH_AGCH(0), ?, imm_ass)) {
Harald Welte883340c2018-02-28 18:59:29 +01003657 /* TODO: verify paging group */
3658 setverdict(pass);
3659 }
3660 [] L1CTL.receive { repeat; }
3661 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003662 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PCU-originated AGCH block on Um");
Harald Welte883340c2018-02-28 18:59:29 +01003663 }
3664 }
3665}
3666
3667/* Send RACH from Um side, expect it to show up on PCU socket */
3668testcase TC_pcu_rach_content() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003669 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003670 f_init_l1ctl();
3671 f_l1_tune(L1CTL);
3672
3673 var GsmFrameNumber fn_last := 0;
3674 for (var integer i := 0; i < 1000; i := i+1) {
3675 var OCT1 ra := f_rnd_ra_ps();
3676 var GsmFrameNumber fn := f_L1CTL_RACH(L1CTL, oct2int(ra));
3677 if (fn == fn_last) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003678 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Two RACH in same FN?!?");
Harald Welte883340c2018-02-28 18:59:29 +01003679 }
3680 fn_last := fn;
3681
3682 timer T := 2.0;
3683 T.start;
3684 alt {
3685 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND(0, oct2int(ra), 0, ?, fn))) {
3686 T.stop;
3687 }
3688 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003689 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003690 }
3691 [] PCU.receive { repeat; }
3692 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003693 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
Harald Welte883340c2018-02-28 18:59:29 +01003694 }
3695 }
3696 }
3697 setverdict(pass);
3698}
3699
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07003700/* Send extended (11-bit, TS1 & TS2) RACH bursts from the Um side,
3701 * expect them to show up on PCU socket (with proper BURST_TYPE_*). */
3702testcase TC_pcu_ext_rach_content() runs on test_CT {
3703 var template PCUIF_Message pcu_rach_ind;
3704 var GsmFrameNumber fn_last := 0;
3705 var L1ctlRachSynchSeq synch_seq;
3706 var PCUIF_BurstType pcu_bt;
3707 var GsmFrameNumber fn;
3708 var BIT11 ra11;
3709
3710 f_init_pcu_test();
3711 f_init_l1ctl();
3712 f_l1_tune(L1CTL);
3713
3714 for (var integer i := 0; i < 1000; i := i+1) {
3715 /* We need to test both TS1 & TS2 */
3716 if (i rem 2 == 0) {
3717 synch_seq := RACH_SYNCH_SEQ_TS1;
3718 pcu_bt := BURST_TYPE_1;
3719 } else {
3720 synch_seq := RACH_SYNCH_SEQ_TS2;
3721 pcu_bt := BURST_TYPE_2;
3722 }
3723
3724 ra11 := f_rnd_ra11_ps();
3725 fn := f_L1CTL_EXT_RACH(L1CTL, bit2int(ra11), synch_seq);
3726 if (fn == fn_last) {
3727 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
3728 "Two RACH in same FN?!?");
3729 }
3730 fn_last := fn;
3731
3732 /* Compose the expected message */
3733 pcu_rach_ind := tr_PCUIF_RACH_IND(
3734 bts_nr := 0,
3735 ra := bit2int(ra11),
3736 is_11bit := 1,
3737 burst_type := pcu_bt,
3738 fn := fn);
3739
3740 timer T := 2.0;
3741 T.start;
3742 alt {
3743 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, pcu_rach_ind)) {
3744 T.stop;
3745 }
3746 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RACH_IND)) {
3747 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RACH IND");
3748 }
3749 [] PCU.receive { repeat; }
3750 [] T.timeout {
3751 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for RACH IND");
3752 }
3753 }
3754 }
3755 setverdict(pass);
3756}
3757
Harald Welte883340c2018-02-28 18:59:29 +01003758/* Send PAGING via RSL, expect it to shw up on PCU socket */
3759testcase TC_pcu_paging_from_rsl() runs on test_CT {
Max2c6f5632019-03-18 17:25:17 +01003760 f_init_pcu_test();
Harald Welte883340c2018-02-28 18:59:29 +01003761
3762 for (var integer i := 0; i < 100; i := i+1) {
3763 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
3764 timer T := 3.0;
3765 if (i < 50) {
3766 mi := valueof(ts_MI_TMSI_LV(f_rnd_octstring(4)));
3767 } else {
3768 mi := valueof(ts_MI_IMSI_LV(f_gen_imsi(i)));
3769 }
3770 var octetstring mi_enc_lv := enc_MobileIdentityLV(mi);
3771 var octetstring mi_enc := substr(mi_enc_lv, 1, lengthof(mi_enc_lv)-1);
3772 var octetstring t_mi_lv := f_pad_oct(mi_enc_lv, 9, '00'O);
3773
3774 /* Send RSL PAGING COMMAND */
3775 RSL_CCHAN.send(ts_RSL_UD(ts_RSL_PAGING_CMD(mi_enc, i mod 4)));
3776 T.start;
3777 alt {
3778 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ(0, t_mi_lv))) {
3779 }
3780 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_PAG_REQ)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003781 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003782 }
3783 [] PCU.receive { repeat; }
3784 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02003785 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for PAGING REQ");
Harald Welte883340c2018-02-28 18:59:29 +01003786 }
3787 }
3788 }
3789 setverdict(pass);
3790}
3791
Harald Welted66c9b82019-05-25 09:03:15 +02003792/* test for periodic TIME_IND; check number of FN expired and number of TIME_IND within frames */
3793testcase TC_pcu_time_ind() runs on test_CT {
3794 var PCUIF_send_data pcu_sd;
3795 var integer num_time_ind := 0;
3796 var integer first_fn, last_fn;
3797 var float test_duration := 5.0;
3798 timer T;
3799
3800 f_init_pcu_test();
3801 f_TC_pcu_act_req(0, 0, 7, true);
3802
3803 PCU.clear;
3804 T.start(test_duration);
3805 alt {
3806 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(0, ?))) -> value pcu_sd {
3807 num_time_ind := num_time_ind + 1;
3808 if (not isbound(first_fn)) {
3809 first_fn := pcu_sd.data.u.time_ind.fn;
3810 }
3811 last_fn := pcu_sd.data.u.time_ind.fn;
3812 repeat;
3813 }
3814 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_TIME_IND(?, ?))) -> value pcu_sd {
3815 setverdict(fail, "Received unexpected PCUIF_TIME_IND: ", pcu_sd.data);
3816 repeat;
3817 }
3818 [] PCU.receive {
3819 repeat;
3820 }
3821 [] T.timeout {}
3822 }
3823 var integer fn_expired := last_fn - first_fn;
3824 log(fn_expired, " fn expired with ", num_time_ind, " PCU_TIME.ind");
3825
3826 /* verify the number of frames expired matches our expectation */
3827 const float c_GSM_FN_DURATION_MS := 4.61538;
3828 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02003829 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welted66c9b82019-05-25 09:03:15 +02003830 if (not match(fn_expired, t_fn_expected)) {
3831 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3832 }
3833
3834 /* There are three TIME.ind in every fn MOD 13 */
3835 var float time_ind_expected := int2float(fn_expired) * 3.0 / 13.0;
3836 /* Add some tolerance */
3837 var template integer t_time_ind_exp := f_tolerance(float2int(time_ind_expected), 1, 100000, 5);
3838 if (not match(num_time_ind, t_time_ind_exp)) {
3839 setverdict(fail, "Number of TIME.ind (", num_time_ind, ") not matching ", t_time_ind_exp);
3840 }
3841
3842 setverdict(pass);
3843}
3844
Harald Welte4832c862019-05-25 14:57:18 +02003845/* test for periodic RTS_REQ; check number of FN expired and number of RTS_IND per SAPI */
3846testcase TC_pcu_rts_req() runs on test_CT {
3847 var PCUIF_send_data pcu_sd;
3848 var integer first_fn, last_fn;
3849 var integer num_rts_pdtch := 0;
3850 var integer num_rts_ptcch := 0;
3851 var float test_duration := 5.0;
3852 timer T;
3853
3854 f_init_pcu_test();
3855 f_TC_pcu_act_req(0, 0, 7, true);
3856
3857 PCU.clear;
3858 T.start(test_duration);
3859 alt {
3860 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PDTCH, ?, ?)))
3861 -> value pcu_sd {
3862 num_rts_pdtch := num_rts_pdtch + 1;
3863 if (not isbound(first_fn)) {
3864 first_fn := pcu_sd.data.u.rts_req.fn;
3865 }
3866 last_fn := pcu_sd.data.u.rts_req.fn;
3867 repeat;
3868 }
3869 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ(0, 0, 7, PCU_IF_SAPI_PTCCH, ?, ?)))
3870 -> value pcu_sd {
3871 num_rts_ptcch := num_rts_ptcch + 1;
3872 if (not isbound(first_fn)) {
3873 first_fn := pcu_sd.data.u.rts_req.fn;
3874 }
3875 last_fn := pcu_sd.data.u.rts_req.fn;
3876 repeat;
3877 }
3878 [] PCU.receive(t_SD_PCUIF(g_pcu_conn_id, tr_PCUIF_RTS_REQ)) -> value pcu_sd {
3879 setverdict(fail, "Received unexpected PCUIF_RTS_REQ: ", pcu_sd.data);
3880 repeat;
3881 }
3882 [] PCU.receive {
3883 repeat;
3884 }
3885 [] T.timeout {}
3886 }
3887 var integer fn_expired := last_fn - first_fn;
3888 log(fn_expired, " fn expired with num_rts_pdtch=", num_rts_pdtch,
3889 ", num_rts_ptcch=", num_rts_ptcch);
3890
3891 /* verify the number of frames expired matches our expectation */
3892 const float c_GSM_FN_DURATION_MS := 4.61538;
3893 var float fn_expected := test_duration * 1000.0 / c_GSM_FN_DURATION_MS;
Harald Weltec761c542019-05-28 11:59:57 +02003894 var template integer t_fn_expected := f_tolerance(float2int(fn_expected), 1, 100000, 20);
Harald Welte4832c862019-05-25 14:57:18 +02003895 if (not match(fn_expired, t_fn_expected)) {
3896 setverdict(fail, "Number of TDMA Frames (", fn_expired, ") not matching ", t_fn_expected);
3897 }
3898
3899 /* PTCCH is in pos. 12 + 38 of 52-multiframe, but four slots/bursts required per block */
3900 var float ptcch_expected := int2float(fn_expired) / 52.0 * 0.5;
3901 var template integer t_ptcch_exp := f_tolerance(float2int(ptcch_expected), 1, 100000, 1);
3902 if (not match(num_rts_ptcch, t_ptcch_exp)) {
3903 setverdict(fail, "Number of RTS.ind for PTCCH (", num_rts_ptcch, ") not matching ",
3904 t_ptcch_exp);
3905 }
3906
3907 /* We have 12 PDTCH blocks every 52-multiframe */
3908 var float pdtch_expected := int2float(fn_expired) / 52.0 * 12.0;
3909 var template integer t_pdtch_exp := f_tolerance(float2int(pdtch_expected), 1, 100000, 2);
3910 if (not match(num_rts_pdtch, t_pdtch_exp)) {
3911 setverdict(fail, "Number of RTS.ind for PDTCH (", num_rts_pdtch, ") not matching ",
3912 t_pdtch_exp);
3913 }
3914
3915 setverdict(pass);
3916}
3917
Harald Welte07bd2d22019-05-25 11:03:30 +02003918/* test for generating Abis side OML ALERT from the PCU */
3919testcase TC_pcu_oml_alert() runs on test_CT {
3920 var PCUIF_send_data pcu_sd;
3921 var integer num_time_ind := 0;
3922 var integer first_fn, last_fn;
3923 var float test_duration := 5.0;
3924 timer T;
3925
3926 f_init_pcu_test();
3927 f_TC_pcu_act_req(0, 0, 7, true);
3928
3929 /* re-connect CTRL port from BTS to BSC */
3930 f_ipa_ctrl_stop();
3931 f_ipa_ctrl_start(mp_bsc_ctrl_ip, mp_bsc_ctrl_port);
3932
3933 /* Send that OML Alert */
3934 PCU.send(t_SD_PCUIF(g_pcu_conn_id, ts_PCUIF_TXT_IND(0, PCU_OML_ALERT, testcasename())));
3935
3936 /* This requires https://gerrit.osmocom.org/#/c/osmo-bsc/+/14177 to be merged */
3937 f_ctrl_exp_trap(IPA_CTRL, "bts.0.oml_failure_report", ?);
3938 setverdict(pass);
3939}
3940
Harald Welteeaa9a862019-05-26 23:01:08 +02003941template (value) PDU_ML3_MS_NW ts_RRM_GprsSuspReq(template (value) OCT4 tlli,
3942 template (value) RoutingAreaIdentificationV rai,
3943 template (value) OCT1 cause) := {
3944 discriminator := '0000'B, /* overwritten */
3945 tiOrSkip := {
3946 skipIndicator := '0000'B
3947 },
3948 msgs := {
3949 rrm := {
3950 gPRS_suspensionRequest := {
3951 messageType := '00110100'B,
3952 tLLI := tlli,
3953 routingAreaIdentification := rai,
3954 suspensionCause := cause,
3955 service_Support := omit
3956 }
3957 }
3958 }
3959}
3960
3961/* test for forwarding of RR SUSPEND from CS lchan to PCU via PCU socket */
3962private function f_TC_rr_suspend_req(charstring id) runs on ConnHdlr {
3963 var PCUIF_Message first_info;
3964 var integer pcu_conn_id := -1;
3965 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
3966 var RoutingAreaIdentificationV rai := f_RAI('262'H, '42F'H, '2342'O, '55'O);
3967 var OCT4 tlli := '01020304'O;
3968 var OCT1 cause := '23'O;
3969 timer T := 5.0;
3970
3971 f_init_pcu(PCU, id, pcu_conn_id, first_info);
3972
3973 f_l1_tune(L1CTL);
3974 RSL.clear;
3975
3976 f_est_dchan();
3977 L1CTL.clear;
3978
3979 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
3980
3981 var PDU_ML3_MS_NW susp_req := valueof(ts_RRM_GprsSuspReq(tlli, rai, cause));
3982 var octetstring l3 := enc_PDU_ML3_MS_NW(susp_req);
3983 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, true, 1, 0, l3), link_id);
3984
3985 /* ConnHdlr has terminated after sending the RR SUSP REQ over a dedicaed channel */
3986 T.start;
3987 alt {
3988 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(0, tlli, ?, oct2int(cause)))) {
3989 setverdict(pass);
3990 }
3991 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_SUSP_REQ(?, ?, ?, ?))) {
3992 setverdict(fail, "Received unexpected PCUIF SUSPE REQ: ");
3993 }
3994 [] PCU.receive {
3995 repeat;
3996 }
3997 [] T.timeout {
3998 setverdict(fail, "Timeout waiting for SUSP REQ on PCUIF");
3999 }
4000 }
4001}
4002testcase TC_pcu_rr_suspend() runs on test_CT {
4003 var ConnHdlrPars pars;
4004 var ConnHdlr vc_conn;
4005
4006 f_init();
4007
4008 pars := valueof(t_Pars(t_RslChanNr_SDCCH4(0,3), ts_RSL_ChanMode_SIGN));
4009 vc_conn := f_start_handler(refers(f_TC_rr_suspend_req), pars, true);
4010 vc_conn.done;
4011}
Harald Welte07bd2d22019-05-25 11:03:30 +02004012
Harald Weltea2e0e942019-05-27 18:12:53 +02004013/* Ensure that PCUIF socket can accept only a single connection */
4014testcase TC_pcu_socket_connect_multi() runs on test_CT {
4015 timer T := 5.0;
4016
4017 /* this (among other things) establishes the first connection to the PCUIF socket */
4018 f_init();
4019
4020 /* try to establish a second connection, expect it to fail */
4021 PCU.send(UD_connect:{mp_pcu_socket, -1});
4022 T.start;
4023 alt {
4024 [] PCU.receive(UD_connect_result:{id := ?, result := { result_code := ERROR, err := ? }}) {
4025 setverdict(pass);
4026 }
4027 [] PCU.receive(UD_connect_result:?) {
4028 setverdict(fail, "Unexpected unix domain connect result");
4029 }
4030 [] T.timeout {
4031 setverdict(pass);
4032 }
4033 }
4034 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4035}
4036
Harald Weltec8effb72019-05-27 18:23:04 +02004037/* Ensure that PCUIF socket can disconnect + reconnect */
4038testcase TC_pcu_socket_reconnect() runs on test_CT {
4039 /* this (among other things) establishes the first connection to the PCUIF socket */
4040 f_init();
4041
4042 f_sleep(1.0);
4043
4044 f_pcuif_close(PCU, g_pcu_conn_id);
4045 g_pcu_conn_id := -1;
4046
4047 f_sleep(1.0);
4048
4049 /* re-connect */
4050 PCU.clear;
4051 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
4052 setverdict(pass);
4053
4054 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4055}
4056
Harald Weltebe030482019-05-27 22:29:35 +02004057/* Ensure that GPRS capability is not advertised before PCU socket conncet */
4058private function f_get_si3(L1CTL_PT pt) runs on test_CT return SystemInformationType3 {
4059 var L1ctlDlMessage l1_dl;
4060 var SystemInformation si;
4061 timer T := 5.0;
4062 T.start;
4063 alt {
4064 [] pt.receive(tr_L1CTL_DATA_IND(t_RslChanNr_BCCH(0), ?)) -> value l1_dl {
4065 /* somehow dec_SystemInformation will try to decode even non-RR as SI */
4066 if (not (l1_dl.payload.data_ind.payload[1] == '06'O)) {
4067 log("Ignoring non-RR SI ", l1_dl);
4068 repeat;
4069 }
4070 si := dec_SystemInformation(l1_dl.payload.data_ind.payload)
4071 if (not ischosen(si.payload.si3)) {
4072 repeat;
4073 }
4074 }
4075 [] pt.receive {
4076 repeat;
4077 }
4078 [] T.timeout {
4079 setverdict(fail, "Timeout waiting for SI3");
4080 }
4081 }
4082 return si.payload.si3;
4083}
4084
4085/* CSN.1 L/H logic: is the bit at the current position using "inverted logic" (true) or not? */
4086private function f_bitpos_is_inv(integer idx) return boolean {
4087 select (idx mod 8) {
4088 case ((2, 4, 6, 7)) { return true; } /* 1-bits of 0x2B */
4089 case else { return false; } /* 0-bits of 0x2B */
4090 }
4091}
4092/* determine if the bit at position 'idx' in 'str' is a CSN.1 'H' (true) or 'L' (false) */
4093private function f_bit_is_high(bitstring str, integer idx) return boolean {
4094 var boolean invert := f_bitpos_is_inv(idx);
4095 if (invert) {
4096 if (str[idx] == '1'B) {
4097 return false;
4098 } else {
4099 return true;
4100 }
4101 } else {
4102 if (str[idx] == '1'B) {
4103 return true;
4104 } else {
4105 return false;
4106 }
4107 }
4108}
4109/* As the TITAN RAW codec cannot expres the CSN.1 L/H concept yet, we have to do this
4110 manually. Let's hope https://www.eclipse.org/forums/index.php/t/1099087/ takes off and
4111 we can replace this piece of code soon ... */
4112private function f_si3_has_gprs_indicator(OCT4 si3_restoctets) return boolean {
4113 var bitstring bits := oct2bit(si3_restoctets);
4114 var integer idx := 0;
4115
4116 if (f_bit_is_high(bits, idx)) {
4117 /* skip Optional selection parameters */
4118 idx := idx + 16;
4119 } else {
4120 idx := idx + 1;
4121 }
4122
4123 if (f_bit_is_high(bits, idx)) {
4124 /* skip Optional power offset */
4125 idx := idx + 3;
4126 } else {
4127 idx := idx + 1;
4128 }
4129
4130 /* skip SI2ter Indicator */
4131 idx := idx + 1;
4132
4133 /* skip Early CM Sending Control */
4134 idx := idx + 1;
4135
4136 /* skip Scheduling if and where */
4137 if (f_bit_is_high(bits, idx)) {
4138 idx := idx + 4;
4139 } else {
4140 idx := idx + 1;
4141 }
4142
4143 return f_bit_is_high(bits, idx);
4144}
4145
4146testcase TC_pcu_socket_noconnect_nosi3gprs() runs on test_CT {
4147 var SystemInformationType3 si3;
4148 timer T := 5.0;
4149
4150 /* don't call f_init() as this would connect PCU socket */
4151 f_init_rsl(testcasename());
4152 T.start;
4153 alt {
4154 [] RSL_CCHAN.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP});
4155 [] T.timeout {
4156 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASP_IPA_EVENT_UP");
4157 }
4158 }
4159 f_rsl_bcch_fill(RSL_SYSTEM_INFO_3, ts_SI3_default);
4160
4161 f_init_l1ctl();
4162 f_l1_tune(L1CTL);
4163
4164 f_sleep(2.0);
4165 L1CTL.clear;
4166 si3 := f_get_si3(L1CTL);
4167 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
4168 setverdict(fail, "SI3 indicates GPRS even before PCU socket connected");
4169 } else {
4170 setverdict(pass);
4171 }
4172 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4173}
4174
4175/* Ensure that GPRS capability is advertised after PCU socket connect */
4176testcase TC_pcu_socket_connect_si3gprs() runs on test_CT {
4177 var SystemInformationType3 si3;
4178
4179 /* this (among other things) establishes the first connection to the PCUIF socket */
4180 f_init();
4181 f_init_l1ctl();
4182 f_l1_tune(L1CTL);
4183
4184 f_sleep(2.0);
4185 L1CTL.clear;
4186 si3 := f_get_si3(L1CTL);
4187 if (not f_si3_has_gprs_indicator(si3.rest_octets)) {
4188 setverdict(fail, "SI3 indicates no GPRS despite PCU socket connected");
4189 } else {
4190 setverdict(pass);
4191 }
4192 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4193}
4194
4195/* Ensure that GPRS capability is no longer advertised after PCU socket disconnect */
4196testcase TC_pcu_socket_disconnect_nosi3gprs() runs on test_CT {
4197 var SystemInformationType3 si3;
4198
4199 /* this (among other things) establishes the first connection to the PCUIF socket */
4200 f_init();
4201 f_init_l1ctl();
4202 f_l1_tune(L1CTL);
4203
4204 f_pcuif_close(PCU, g_pcu_conn_id);
4205 g_pcu_conn_id := -1;
4206
4207 f_sleep(1.0);
4208
4209 /* re-connect */
4210 PCU.clear;
4211 f_init_pcu(PCU, testcasename(), g_pcu_conn_id, g_pcu_last_info);
4212
4213 f_sleep(2.0);
4214 L1CTL.clear;
4215 si3 := f_get_si3(L1CTL);
4216 if (f_si3_has_gprs_indicator(si3.rest_octets)) {
4217 setverdict(fail, "SI3 indicates GPRS after PCU socket disconnected");
4218 } else {
4219 setverdict(pass);
4220 }
4221
4222 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
4223}
4224
Harald Welted66c9b82019-05-25 09:03:15 +02004225
Harald Welte3d04ae62018-04-04 20:29:05 +02004226/***********************************************************************
Harald Welte9bbbfb52018-04-05 09:33:19 +02004227 * Osmocom Style Dynamic Timeslot Support
Harald Welte3d04ae62018-04-04 20:29:05 +02004228 ***********************************************************************/
4229
4230private function f_dyn_osmo_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4231runs on ConnHdlr {
4232 var PCUIF_send_data sd;
4233 /* Expect BTS to immediately acknowledge activation as PDCH */
4234 PCU.clear;
4235 f_rsl_chan_act(g_pars.chan_mode);
4236 /* expect INFO_IND on PCU interface listing TS as PDCH */
4237 alt {
4238 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4239 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004240 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '1' after PDCH ACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02004241 }
4242 }
4243 [] PCU.receive { repeat; }
4244 }
4245 /* try to activate this PDCH from the PCU point of view */
4246 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4247 /* FIXME: is there a response? */
4248}
4249
4250private function f_dyn_osmo_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4251runs on ConnHdlr {
4252 var PCUIF_send_data sd;
4253 /* Send RSL CHAN REL (deactivate) */
4254 PCU.clear;
4255 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
4256 /* expect BTS to ask PCU to deactivate the channel */
4257 alt {
4258 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4259 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004260 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "PCUIF_INFO_IND PDCH_MASK not '0' after PDCH DEACT");
Harald Welte3d04ae62018-04-04 20:29:05 +02004261 }
4262 }
4263 [] PCU.receive { repeat; }
4264 }
4265 /* Emulate PCU asking BTS to deactivate PDCH */
4266 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4267 alt {
4268 [] RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr)) {
4269 setverdict(pass);
4270 }
4271 [] RSL.receive { repeat; }
4272 }
4273}
4274
4275/* Activate Osmocom-style dynamic PDCH from BSC side */
4276function f_TC_dyn_osmo_pdch_act_deact(charstring id) runs on ConnHdlr {
4277 var PCUIF_Message first_info;
4278 var integer ts_nr := g_chan_nr.tn;
4279 var integer trx_nr := 0;
4280 var integer bts_nr := 0;
4281 var integer pcu_conn_id := -1;
4282
4283 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4284
4285 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4286 f_sleep(3.0);
4287 f_dyn_osmo_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4288 setverdict(pass);
4289}
4290testcase TC_dyn_osmo_pdch_act_deact() runs on test_CT {
4291 var ConnHdlrPars pars;
4292 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004293 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02004294
4295 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4296 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_act_deact), pars, true);
4297 vc_conn.done;
4298}
4299
4300/* send a RF CHAN REL for PDCH on an osmocom dynamci PDCH that's already inactive */
4301function f_TC_dyn_osmo_pdch_unsol_deact(charstring id) runs on ConnHdlr {
4302 var PCUIF_Message first_info;
Harald Welte3d04ae62018-04-04 20:29:05 +02004303 var integer pcu_conn_id := -1;
4304
4305 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4306
Neels Hofmeyr9c50ca52018-05-08 20:37:54 +02004307 RSL.send(ts_RSL_RF_CHAN_REL(g_chan_nr));
4308 /* since the lchan is already released, we don't expect any PCU changes, just a rel ack. */
4309 RSL.receive(tr_RSL_RF_CHAN_REL_ACK(g_chan_nr));
Harald Welte3d04ae62018-04-04 20:29:05 +02004310 setverdict(pass);
4311}
4312testcase TC_dyn_osmo_pdch_unsol_deact() runs on test_CT {
4313 var ConnHdlrPars pars;
4314 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004315 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02004316
4317 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4318 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_unsol_deact), pars, true);
4319 vc_conn.done;
4320}
4321
4322/* try to RSL CHAN ACT a PDCH on an osmocom-style PDCH that's already active */
4323function f_TC_dyn_osmo_pdch_double_act(charstring id) runs on ConnHdlr {
4324 var PCUIF_Message first_info;
4325 var integer ts_nr := g_chan_nr.tn;
4326 var integer trx_nr := 0;
4327 var integer bts_nr := 0;
4328 var integer pcu_conn_id := -1;
4329
4330 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4331
4332 f_dyn_osmo_pdch_act(pcu_conn_id, bts_nr, trx_nr);
Neels Hofmeyrdf936a22018-05-08 22:07:57 +02004333 /* Send a second Chan Activ and expect it to be NACKed */
4334 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4335 "RSL CHAN ACT NACK");
Harald Welte3d04ae62018-04-04 20:29:05 +02004336 setverdict(pass);
4337}
4338testcase TC_dyn_osmo_pdch_double_act() runs on test_CT {
4339 var ConnHdlrPars pars;
4340 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004341 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02004342
4343 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4344 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_double_act), pars, true);
4345 vc_conn.done;
4346}
4347
4348/* try to RSL CHAN ACT a TCH/F on an osmocom-style PDCH */
4349function f_TC_dyn_osmo_pdch_tchf_act(charstring id) runs on ConnHdlr {
4350 var PCUIF_Message first_info;
4351 var integer ts_nr := g_chan_nr.tn;
4352 var integer trx_nr := 0;
4353 var integer bts_nr := 0;
4354 var integer pcu_conn_id := -1;
4355 var RslChannelNr chan_nr := valueof(t_RslChanNr_Bm(g_chan_nr.tn));
4356
4357 /* register for the TCH/F channel number */
4358 f_rslem_register(0, chan_nr);
4359
4360 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4361
4362 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(chan_nr),
4363 "RSL CHAN ACT");
4364 setverdict(pass);
4365}
4366testcase TC_dyn_osmo_pdch_tchf_act() runs on test_CT {
4367 var ConnHdlrPars pars;
4368 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004369 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02004370
4371 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4372 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchf_act), pars, true);
4373 vc_conn.done;
4374}
4375
4376/* try to RSL CHAN ACT the TCH/H on an osmocom-style PDCH */
4377function f_TC_dyn_osmo_pdch_tchh_act(charstring id) runs on ConnHdlr {
4378 var PCUIF_Message first_info;
4379 var integer ts_nr := g_chan_nr.tn;
4380 var integer trx_nr := 0;
4381 var integer bts_nr := 0;
4382 var integer pcu_conn_id := -1;
4383 var RslChannelNr chan_nr[2] := { valueof(t_RslChanNr_Lm(g_chan_nr.tn, 0)),
4384 valueof(t_RslChanNr_Lm(g_chan_nr.tn, 1)) };
4385
4386 /* register for the TCH/H channel numbers */
4387 f_rslem_register(0, chan_nr[0]);
4388 f_rslem_register(0, chan_nr[1]);
4389
4390 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4391
4392 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[1], g_pars.chan_mode),
4393 tr_RSL_CHAN_ACT_ACK(chan_nr[1]), "RSL CHAN ACT [1]");
4394 f_rsl_transceive(ts_RSL_CHAN_ACT(chan_nr[0], g_pars.chan_mode),
4395 tr_RSL_CHAN_ACT_ACK(chan_nr[0]), "RSL CHAN ACT [0]");
4396 setverdict(pass);
4397}
4398testcase TC_dyn_osmo_pdch_tchh_act() runs on test_CT {
4399 var ConnHdlrPars pars;
4400 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004401 f_init();
Harald Welte3d04ae62018-04-04 20:29:05 +02004402
4403 pars := valueof(t_Pars(t_RslChanNr_PDCH(4), ts_RSL_ChanMode_SIGN));
4404 vc_conn := f_start_handler(refers(f_TC_dyn_osmo_pdch_tchh_act), pars, true);
4405 vc_conn.done;
4406}
4407
Harald Welte9bbbfb52018-04-05 09:33:19 +02004408/***********************************************************************
4409 * IPA Style Dynamic Timeslot Support
4410 ***********************************************************************/
4411
4412private function f_dyn_ipa_pdch_act(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4413runs on ConnHdlr {
4414 var PCUIF_send_data sd;
4415 /* Expect BTS to immediately acknowledge activation as PDCH */
4416 PCU.clear;
4417 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4418 /* expect INFO_IND on PCU interface listing TS as PDCH */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004419 timer T_wait := 2.0;
4420 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004421 alt {
4422 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4423 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '1'B) {
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004424 log("PCUIF_INFO_IND PDCH_MASK not yet '1' after PDCH ACT on TS", g_chan_nr.tn,
4425 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4426 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004427 }
4428 }
4429 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004430 [] T_wait.timeout {
4431 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4432 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '1' on TS", g_chan_nr.tn));
4433 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004434 }
4435 /* try to activate this PDCH from the PCU point of view */
4436 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_ACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4437 /* FIXME: is there a response? */
4438
4439 RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?));
4440}
4441
4442private function f_dyn_ipa_pdch_deact(integer pcu_conn_id, integer bts_nr, integer trx_nr)
4443runs on ConnHdlr {
4444 var PCUIF_send_data sd;
4445 /* Send RSL CHAN REL (deactivate) */
4446 RSL.send(ts_RSL_IPA_PDCH_DEACT(g_chan_nr));
4447 PCU.clear;
4448 /* expect BTS to ask PCU to deactivate the channel */
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004449 timer T_wait := 2.0;
4450 T_wait.start;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004451 alt {
4452 [] PCU.receive(t_SD_PCUIF(pcu_conn_id, tr_PCUIF_INFO_IND(bts_nr, ?))) -> value sd {
4453 if (substr(sd.data.u.info_ind.trx[trx_nr].pdch_mask, g_chan_nr.tn, 1) != '0'B) {
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004454 log("PCUIF_INFO_IND PDCH_MASK not yet '0' after PDCH DEACT on TS", g_chan_nr.tn,
4455 " mask:", sd.data.u.info_ind.trx[trx_nr].pdch_mask);
4456 repeat;
Harald Welte9bbbfb52018-04-05 09:33:19 +02004457 }
4458 }
4459 [] PCU.receive { repeat; }
Pau Espin Pedrol446e07b2019-02-18 21:18:36 +01004460 [] T_wait.timeout {
4461 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
4462 log2str("Timeout waiting for PCUIF_INFO_IND PDCH_MASK to be '0' on TS", g_chan_nr.tn));
4463 }
Harald Welte9bbbfb52018-04-05 09:33:19 +02004464 }
4465 /* Emulate PCU asking BTS to deactivate PDCH */
4466 PCU.send(t_SD_PCUIF(pcu_conn_id, ts_PCUIF_DEACT_REQ(bts_nr, trx_nr, g_chan_nr.tn)));
4467 alt {
4468 [] RSL.receive(tr_RSL_IPA_PDCH_DEACT_ACK(g_chan_nr)) {
4469 setverdict(pass);
4470 }
4471 [] RSL.receive { repeat; }
4472 }
4473}
4474
4475/* Activate and de-activate an IPA-style dynamic TCH/F + PDCH */
4476function f_TC_dyn_ipa_pdch_act_deact(charstring id) runs on ConnHdlr {
4477 var PCUIF_Message first_info;
4478 var integer ts_nr := g_chan_nr.tn;
4479 var integer trx_nr := 0;
4480 var integer bts_nr := 0;
4481 var integer pcu_conn_id := -1;
4482
4483 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4484
4485 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4486 f_sleep(3.0);
4487 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4488
4489 setverdict(pass);
4490
4491}
4492testcase TC_dyn_ipa_pdch_act_deact() runs on test_CT {
4493 var ConnHdlrPars pars;
4494 var ConnHdlr vc_conn;
4495 f_init();
4496
4497 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4498 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_deact), pars, true);
4499 vc_conn.done;
4500}
4501
4502/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH */
4503function f_TC_dyn_ipa_pdch_tchf_act(charstring id) runs on ConnHdlr {
4504 var PCUIF_Message first_info;
4505 var integer ts_nr := g_chan_nr.tn;
4506 var integer trx_nr := 0;
4507 var integer bts_nr := 0;
4508 var integer pcu_conn_id := -1;
4509
4510 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4511
4512 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4513 "RSL CHAN ACT");
4514 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4515 "RF CHAN REL", true);
4516 setverdict(pass);
4517}
4518testcase TC_dyn_ipa_pdch_tchf_act() runs on test_CT {
4519 var ConnHdlrPars pars;
4520 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004521 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02004522
4523 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4524 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act), pars, true);
4525 vc_conn.done;
4526}
4527
4528/* Activate IPA style dyn PDCH as TCH/F and then illegally try to activate it as PDCH, too */
4529function f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack(charstring id) runs on ConnHdlr {
4530 var PCUIF_Message first_info;
4531 var integer ts_nr := g_chan_nr.tn;
4532 var integer trx_nr := 0;
4533 var integer bts_nr := 0;
4534 var integer pcu_conn_id := -1;
4535
4536 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4537
4538 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_ACK(g_chan_nr),
4539 "RSL CHAN ACT");
4540
4541 RSL.send(ts_RSL_IPA_PDCH_ACT(g_chan_nr));
4542 alt {
4543 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_NACK(g_chan_nr, ?));
4544 [] RSL.receive(tr_RSL_IPA_PDCH_ACT_ACK(g_chan_nr, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004545 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected PDCH ACT ACK");
Harald Welte9bbbfb52018-04-05 09:33:19 +02004546 }
4547 [] RSL.receive { repeat; }
4548 }
4549
4550 f_rsl_transceive(ts_RSL_RF_CHAN_REL(g_chan_nr), tr_RSL_RF_CHAN_REL_ACK(g_chan_nr),
4551 "RF CHAN REL", true);
4552 setverdict(pass);
4553}
4554testcase TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() runs on test_CT {
4555 var ConnHdlrPars pars;
4556 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004557 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02004558
4559 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4560 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_tchf_act_pdch_act_nack), pars, true);
4561 vc_conn.done;
4562}
4563
4564/* try to RSL CHAN ACT a TCH/F on an IPA-style PDCH that's already in PDCH mode; expect NACK */
4565function f_TC_dyn_ipa_pdch_act_tchf_act_nack(charstring id) runs on ConnHdlr {
4566 var PCUIF_Message first_info;
4567 var integer ts_nr := g_chan_nr.tn;
4568 var integer trx_nr := 0;
4569 var integer bts_nr := 0;
4570 var integer pcu_conn_id := -1;
4571
4572 /* register for the TCH/F channel number */
4573 f_rslem_register(0, g_chan_nr);
4574
4575 f_init_pcu(PCU, id, pcu_conn_id, first_info);
4576
4577 f_dyn_ipa_pdch_act(pcu_conn_id, bts_nr, trx_nr);
4578
4579 f_rsl_transceive(ts_RSL_CHAN_ACT(g_chan_nr, g_pars.chan_mode), tr_RSL_CHAN_ACT_NACK(g_chan_nr),
4580 "RSL CHAN ACT");
4581
4582 f_dyn_ipa_pdch_deact(pcu_conn_id, bts_nr, trx_nr);
4583
4584 setverdict(pass);
4585}
4586testcase TC_dyn_ipa_pdch_act_tchf_act_nack() runs on test_CT {
4587 var ConnHdlrPars pars;
4588 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004589 f_init();
Harald Welte9bbbfb52018-04-05 09:33:19 +02004590
4591 pars := valueof(t_Pars(t_RslChanNr_Bm(3), ts_RSL_ChanMode_SIGN));
4592 vc_conn := f_start_handler(refers(f_TC_dyn_ipa_pdch_act_tchf_act_nack), pars, true);
4593 vc_conn.done;
4594}
4595
4596
Harald Welte0472ab42018-03-12 15:02:26 +01004597/***********************************************************************
4598 * LAPDm / RLL related
4599 ***********************************************************************/
4600
4601private function f_tx_lapdm(template (value) LapdmFrame l,
4602 template (value) RslLinkId link_id) runs on ConnHdlr {
4603 var octetstring l2 := enc_LapdmFrame(valueof(l));
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07004604 var template (value) SacchL1Header l1h;
4605
4606 /* TODO: we can use an extension of TTCN-3 for padding, i.e. PADDING('2B'O) */
Harald Welte0472ab42018-03-12 15:02:26 +01004607 if (valueof(link_id.c) == SACCH) {
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07004608 /* Compose dummy L1 header */
4609 l1h := ts_SacchL1Header(g_pars.l1_pars.ms_power_level, false, g_pars.l1_pars.ms_actual_ta);
4610 L1CTL.send(ts_L1CTL_DATA_REQ_SACCH(g_chan_nr, link_id, l1h, f_pad_oct(l2, 21, '2B'O)));
Pau Espin Pedrola0fb42a2018-10-10 15:56:39 +02004611 } else {
4612 /* If required, pad L2 frame with constant 0x2b filling */
Vadim Yanitskiy0a8d6da2019-05-28 22:18:28 +07004613 L1CTL.send(ts_L1CTL_DATA_REQ(g_chan_nr, link_id, f_pad_oct(l2, 23, '2B'O)));
Harald Welte0472ab42018-03-12 15:02:26 +01004614 }
Harald Welte0472ab42018-03-12 15:02:26 +01004615}
4616
4617type record RllTestCase {
4618 uint3_t sapi,
4619 RslLinkId link_id,
4620 octetstring l3,
4621 boolean exp
4622}
4623type record of RllTestCase RllTestCases;
4624template RllTestCase t_EITC(uint3_t sapi, RslLinkId id, octetstring l3, boolean exp) := {
4625 sapi := sapi,
4626 link_id := id,
4627 l3 := l3,
4628 exp := exp
4629}
4630
4631/* execute the same callback function with a set of different parameters (tcs) on a
4632 * variety of logical channels */
4633private function f_rll_testmatrix(RllTestCases tcs, void_fn fn) runs on test_CT {
4634 var ConnHdlrPars pars;
4635 var ConnHdlr vc_conn;
Harald Welte10474062019-05-30 16:48:17 +02004636 f_init();
Harald Welte0472ab42018-03-12 15:02:26 +01004637
4638 /* test on each of the channels we have */
4639 for (var integer i := 0; i < sizeof(g_AllChanTypes); i := i+1) {
4640 pars := valueof(t_Pars(g_AllChanTypes[i], ts_RSL_ChanMode_SIGN));
4641
4642 /* test each of the test cases on the current channel */
4643 for (var integer j := 0; j < sizeof(tcs); j := j+1) {
4644 pars.spec.rll := tcs[j];
4645 log(testcasename(), ": XXX Starting ", tcs[j] , " on ", g_AllChanTypes[i]);
4646 vc_conn := f_start_handler(fn, pars);
4647 vc_conn.done;
4648 }
4649 }
4650
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004651 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
Harald Welte0472ab42018-03-12 15:02:26 +01004652}
4653
4654/* test if SABM on Um triggers EST IND (TS 48.058 3.1) */
4655private function f_TC_rll_est_ind(charstring id) runs on ConnHdlr {
4656 var RllTestCase tc := g_pars.spec.rll;
4657 timer T := 3.0;
4658
4659 f_l1_tune(L1CTL);
4660 RSL.clear;
4661
4662 /* activate the logical channel */
4663 f_est_dchan();
4664 L1CTL.clear;
4665
4666 f_tx_lapdm(ts_LAPDm_SABM(tc.sapi, cr_MO_CMD, true, tc.l3), tc.link_id);
4667 T.start;
4668 alt {
4669 [tc.l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, tc.link_id, tc.l3)) {
4670 if (tc.exp) {
4671 setverdict(pass);
4672 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004673 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND with L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004674 }
4675 }
4676 [tc.l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, tc.link_id)) {
4677 if (tc.exp) {
4678 setverdict(pass);
4679 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004680 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected EST IND without L3 in ", tc));
Harald Welte0472ab42018-03-12 15:02:26 +01004681 }
4682 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004683 /* We also expect to receive the measurements */
4684 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004685 [tc.exp] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004686 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for EST IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004687 }
4688 [not tc.exp] T.timeout {
4689 setverdict(pass);
4690 }
4691 }
4692
4693 f_rsl_chan_deact();
4694 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4695 f_rslem_unregister(0, g_chan_nr);
4696}
4697testcase TC_rll_est_ind() runs on test_CT {
4698 var RllTestCases tcs := {
Harald Welte7aacbbf2018-05-09 16:56:41 +02004699 /* SAPI0 establishment (contention resolution) */
Harald Welte0472ab42018-03-12 15:02:26 +01004700 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
Harald Welte7aacbbf2018-05-09 16:56:41 +02004701 /* normal SAPI0 establishment */
4702 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), ''O, true)),
Harald Welte0472ab42018-03-12 15:02:26 +01004703 /* SAPI 3 doesn't support contention resolution */
4704 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), '01020304'O, false)),
4705 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), '01020304'O, false)),
4706 /* normal SAPI3 establishment on main DCCH */
4707 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4708 /* normal SAPI3 establishment on SACCH */
4709 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4710 };
4711 f_rll_testmatrix(tcs, refers(f_TC_rll_est_ind));
4712}
4713
4714/* test if RLL EST REQ trigeres SABM on Um; UA on Um triggers EST CONF (TS 48.058 3.2) */
4715private function f_TC_rll_est_req(charstring id) runs on ConnHdlr {
4716 var RllTestCase tc := g_pars.spec.rll;
4717 var L1ctlDlMessage dl;
4718 timer T := 3.0;
4719
4720 f_l1_tune(L1CTL);
4721 RSL.clear;
4722
4723 /* activate the logical channel */
4724 f_est_dchan();
4725 L1CTL.clear;
4726
4727 /* Send a RSL EST REQ for SAPI3 on main DCCH */
4728 RSL.send(ts_RSL_EST_REQ(g_chan_nr, tc.link_id));
4729 T.start;
4730 alt {
4731 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4732 var LapdmFrame lapdm;
4733 var octetstring l2 := dl.payload.data_ind.payload;
4734 if (dl.dl_info.link_id.c == SACCH) {
4735 /* remove L1 header */
4736 l2 := substr(l2, 2, lengthof(l2)-2);
4737 }
4738 lapdm.ab := dec_LapdmFrameAB(l2);
4739 if (match(lapdm, tr_LAPDm_SABM(tc.sapi, cr_MT_CMD, true, ''O))) {
4740 setverdict(pass);
4741 } else {
4742 repeat;
4743 }
4744 }
4745 [] L1CTL.receive { repeat; }
4746 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004747 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for SABM");
Harald Welte0472ab42018-03-12 15:02:26 +01004748 }
4749 }
4750
4751 f_rsl_chan_deact();
4752 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4753 f_rslem_unregister(0, g_chan_nr);
4754}
4755testcase TC_rll_est_req_DCCH_3() runs on test_CT {
4756 var RllTestCases tcs := {
4757 /* normal SAPI3 establishment on main DCCH */
4758 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))//,
4759 };
4760 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4761}
4762testcase TC_rll_est_req_ACCH_3() runs on test_CT {
4763 var RllTestCases tcs := {
4764 /* normal SAPI3 establishment on SACCH */
4765 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4766 }
4767 f_rll_testmatrix(tcs, refers(f_TC_rll_est_req));
4768}
4769
4770/* altstep to receive a LAPDm frame matching the given template */
4771private altstep as_l1_exp_lapdm(template LapdmFrame exp) runs on ConnHdlr {
4772 var L1ctlDlMessage dl;
4773 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
4774 var LapdmFrame lapdm;
4775 var octetstring l2 := dl.payload.data_ind.payload;
4776 if (dl.dl_info.link_id.c == SACCH) {
4777 /* remove L1 header */
4778 l2 := substr(l2, 2, lengthof(l2)-2);
4779 }
4780 if (ischosen(exp.ab)) {
4781 lapdm.ab := dec_LapdmFrameAB(l2);
4782 } else if (ischosen(exp.b4)) {
4783 lapdm.b4 := dec_LapdmFrameB4(l2);
4784 } else if (ischosen(exp.bbis)) {
4785 lapdm.bbis := dec_LapdmFrameBbis(l2);
4786 }
4787 log("Rx LAPDm ", lapdm);
4788 if (match(lapdm, exp)) {
4789 setverdict(pass);
4790 } else {
4791 repeat;
4792 }
4793 }
4794 [] L1CTL.receive { repeat; }
4795}
4796private function f_l1_exp_lapdm(template LapdmFrame exp, float t := 3.0) runs on ConnHdlr {
4797 timer T := t;
4798 T.start;
4799 alt {
4800 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004801 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Timeout waiting for LAPDm ", exp));
Harald Welte0472ab42018-03-12 15:02:26 +01004802 }
4803 [] as_l1_exp_lapdm(exp);
4804 }
4805}
4806
4807/* establish one Radio Link Layer via SABM -> UA. Use l3 for contention resolution */
4808private function f_est_rll_mo(uint3_t sapi, RslLinkId link_id, octetstring l3) runs on ConnHdlr {
4809 /* send SABM from MS -> BTS */
4810 f_tx_lapdm(ts_LAPDm_SABM(sapi, cr_MO_CMD, true, l3), link_id);
4811 /* expect RLL EST IND on Abis */
4812 alt {
4813 [l3 != ''O] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3));
4814 [l3 == ''O] RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
4815 [] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, ?)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02004816 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Failing due to RSL_ERROR_IND");
Harald Welte0472ab42018-03-12 15:02:26 +01004817 }
4818 [] RSL.receive { repeat; }
4819 }
4820 /* expect UA from BTS -> MS */
4821 f_l1_exp_lapdm(tr_LAPDm_UA(sapi, cr_MT_RSP, true, l3));
4822}
4823
4824/* test if DISC on Um triggers RLL REL IND (TS 48.058 3.3) */
4825private function f_TC_rll_rel_ind(charstring id) runs on ConnHdlr {
4826 var RllTestCase tc := g_pars.spec.rll;
4827
4828 f_l1_tune(L1CTL);
4829 RSL.clear;
4830
4831 /* activate the logical channel */
4832 f_est_dchan();
4833 L1CTL.clear;
4834
4835 /* first establish the link-layer */
4836 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4837
4838 /* then send the DISC */
4839 f_tx_lapdm(ts_LAPDm_DISC(tc.sapi, cr_MO_CMD, true), tc.link_id);
4840 /* ... and expect the REL IND on the RSL side */
4841 alt {
4842 [] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tc.link_id)) {
4843 setverdict(pass);
4844 }
Vadim Yanitskiy35677872018-10-04 17:30:21 +07004845 /* We also expect to receive the measurements */
4846 [] as_meas_res(verify_meas := false);
Harald Welte0472ab42018-03-12 15:02:26 +01004847 }
4848
4849 /* release the channel */
4850 f_rsl_chan_deact();
4851 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4852 f_rslem_unregister(0, g_chan_nr);
4853}
4854testcase TC_rll_rel_ind_DCCH_0() runs on test_CT {
4855 var RllTestCases tcs := {
4856 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true))
4857 };
4858 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4859}
4860
4861testcase TC_rll_rel_ind_ACCH_0() runs on test_CT {
4862 var RllTestCases tcs := {
4863 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true))
4864 };
4865 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4866}
4867testcase TC_rll_rel_ind_DCCH_3() runs on test_CT {
4868 var RllTestCases tcs := {
4869 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true))
4870 };
4871 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4872}
4873testcase TC_rll_rel_ind_ACCH_3() runs on test_CT {
4874 var RllTestCases tcs := {
4875 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4876 };
4877 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_ind));
4878}
4879
4880/* test if RLL REL REQ triggers DISC on Um; UA/DM triggers RLL REL CONF (TS 48.058 3.4) */
4881private function f_TC_rll_rel_req(charstring id) runs on ConnHdlr {
4882 var RllTestCase tc := g_pars.spec.rll;
4883 f_l1_tune(L1CTL);
4884 RSL.clear;
4885
4886 /* activate the logical channel */
4887 f_est_dchan();
4888 L1CTL.clear;
4889
4890 /* first establish the link-layer */
4891 f_est_rll_mo(tc.sapi, tc.link_id, tc.l3);
4892
4893 /* then send the REL REQ via RSL */
4894 RSL.send(ts_RSL_REL_REQ(g_chan_nr, tc.link_id, RSL_REL_MODE_NORMAL));
4895 /* ... and expect the DISC on the Um side */
4896 alt {
Harald Weltebc6199f2018-05-10 19:38:18 +02004897 [] as_l1_exp_lapdm(tr_LAPDm_DISC(tc.sapi, cr_MT_CMD, true)) {
Harald Welte0472ab42018-03-12 15:02:26 +01004898 /* FIXME: send a UA in resposne to the DISC */
4899 }
4900 }
4901
4902 /* release the channel */
4903 f_rsl_chan_deact();
4904 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4905 f_rslem_unregister(0, g_chan_nr);
4906}
4907testcase TC_rll_rel_req() runs on test_CT {
4908 var RllTestCases tcs := {
4909 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), '01020304'O, true)),
4910 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), ''O, true)),
4911 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), ''O, true)),
4912 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), ''O, true))
4913 };
4914 f_rll_testmatrix(tcs, refers(f_TC_rll_rel_req));
4915}
4916
4917/* test if RLL DATA REQ triggers I-frames on Um (TS 48.058 3.5) */
4918testcase TC_rll_data_req() runs on test_CT {
4919}
4920
4921/* test if I-frames on Um trigger RLL DATA IND (TS 48.058 3.6) */
4922testcase TC_rll_data_ind() runs on test_CT {
4923}
4924
4925/* test if RLL UNIT DATA REQ triggers UI-frame on Um (TS 48.058 3.7) */
4926private function f_TC_rll_ud_req(charstring id) runs on ConnHdlr {
4927 var RllTestCase tc := g_pars.spec.rll;
4928
4929 f_l1_tune(L1CTL);
4930 RSL.clear;
4931
4932 f_est_dchan();
4933 L1CTL.clear;
4934
4935 /* Send UNITDATA REQ on RSL side */
4936 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, tc.link_id, tc.l3));
4937 /* Expect it to arrive on the other side */
4938 if (tc.link_id.c == SACCH) {
Harald Weltee613f962018-04-18 22:38:16 +02004939 f_l1_exp_lapdm(tr_LAPDm_B4_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004940 } else {
Harald Weltee613f962018-04-18 22:38:16 +02004941 f_l1_exp_lapdm(tr_LAPDm_UI(tc.sapi, cr_MT_CMD, tc.l3));
Harald Welte0472ab42018-03-12 15:02:26 +01004942 }
4943
4944 /* release the channel */
4945 f_rsl_chan_deact();
4946 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4947 f_rslem_unregister(0, g_chan_nr);
4948}
4949testcase TC_rll_unit_data_req_DCCH() runs on test_CT {
4950 var octetstring l3 := f_rnd_octstring(15);
4951 var RllTestCases tcs := {
4952 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4953 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4954 };
4955 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4956}
4957testcase TC_rll_unit_data_req_ACCH() runs on test_CT {
4958 var octetstring l3 := f_rnd_octstring(19);
4959 var RllTestCases tcs := {
4960 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
4961 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
4962 };
4963 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_req));
4964}
4965
4966/* test if UI-frames on Um trigger RLL UNIT DATA IND (TS 48.058 3.8) */
4967private function f_TC_rll_ud_ind(charstring id) runs on ConnHdlr {
4968 var RllTestCase tc := g_pars.spec.rll;
4969
4970 f_l1_tune(L1CTL);
4971 RSL.clear;
4972
4973 f_est_dchan();
4974 L1CTL.clear;
4975
4976 /* Send LAPDm UI frame. There is no B4 format in uplink! */
Harald Weltee613f962018-04-18 22:38:16 +02004977 f_tx_lapdm(ts_LAPDm_UI(tc.sapi, cr_MO_CMD, tc.l3), tc.link_id);
Harald Welte0472ab42018-03-12 15:02:26 +01004978 /* Expdct RLL UNITDATA IND on RSL side */
4979 alt {
4980 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, tc.link_id, tc.l3)) {
4981 setverdict(pass);
4982 }
4983 [] RSL.receive { repeat; }
4984 }
4985
4986 /* release the channel */
4987 f_rsl_chan_deact();
4988 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
4989 f_rslem_unregister(0, g_chan_nr);
4990}
4991testcase TC_rll_unit_data_ind_DCCH() runs on test_CT {
Stefan Sperlingc4181912018-07-25 17:03:08 +02004992 var octetstring l3 := f_rnd_octstring(20);
Harald Welte0472ab42018-03-12 15:02:26 +01004993 var RllTestCases tcs := {
4994 valueof(t_EITC(0, valueof(ts_RslLinkID_DCCH(0)), l3, true)),
4995 valueof(t_EITC(3, valueof(ts_RslLinkID_DCCH(3)), l3, true))
4996 };
4997 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
4998}
4999testcase TC_rll_unit_data_ind_ACCH() runs on test_CT {
5000 var octetstring l3 := f_rnd_octstring(18);
5001 var RllTestCases tcs := {
5002 valueof(t_EITC(0, valueof(ts_RslLinkID_SACCH(0)), l3, true)),
5003 valueof(t_EITC(3, valueof(ts_RslLinkID_SACCH(3)), l3, true))
5004 };
5005 f_rll_testmatrix(tcs, refers(f_TC_rll_ud_ind));
5006}
5007
Harald Weltee613f962018-04-18 22:38:16 +02005008/***********************************************************************
5009 * Encryption Related
5010 ***********************************************************************/
5011
5012/* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5013function f_unitdata_mt(RslLinkId link_id, octetstring l3) runs on ConnHdlr {
5014 RSL.send(ts_RSL_UNITDATA_REQ(g_chan_nr, link_id, l3));
5015 if (link_id.c == SACCH) {
5016 f_l1_exp_lapdm(tr_LAPDm_B4_UI(link_id.sapi, cr_MT_CMD, l3));
5017 } else {
5018 f_l1_exp_lapdm(tr_LAPDm_UI(link_id.sapi, cr_MT_CMD, l3));
5019 }
5020}
5021
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005022/* Expect (or not expect) other kinds of messages */
5023private altstep as_rsl_any_ind(boolean exp_any) runs on ConnHdlr {
5024 [exp_any] RSL.receive { repeat; }
5025 [not exp_any] RSL.receive {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005026 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected RSL message!");
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005027 }
5028}
5029
Harald Weltee613f962018-04-18 22:38:16 +02005030/* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
Vadim Yanitskiy8d8f91c2018-10-04 06:19:45 +07005031private function f_unitdata_mo(
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07005032 RslLinkId link_id,
5033 octetstring l3,
5034 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07005035 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy98e03152018-10-03 18:06:06 +07005036) runs on ConnHdlr {
Harald Weltee613f962018-04-18 22:38:16 +02005037 timer T := 3.0;
5038 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3), link_id);
5039 T.start;
5040 /* Expect RLL UNITDATA IND on RSL side */
5041 alt {
5042 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3)) {
5043 setverdict(pass);
5044 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07005045 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiyad131c82018-10-04 06:18:59 +07005046 [] as_rsl_any_ind(exp_any);
Harald Weltee613f962018-04-18 22:38:16 +02005047 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005048 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for UNIT_DATA_IND");
Harald Weltee613f962018-04-18 22:38:16 +02005049 }
Harald Weltee613f962018-04-18 22:38:16 +02005050 }
5051}
5052
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005053/* Send I-frame from MS and expect it to arrive as RLL DATA IND on Abis */
5054private function f_data_mo(
5055 RslLinkId link_id,
5056 boolean p, uint3_t nr, uint3_t ns,
5057 octetstring l3,
5058 boolean exp_sacch := true, /* Should tolerate SACCH messages? */
Vadim Yanitskiyb9920502018-10-03 18:29:51 +07005059 boolean exp_any := false /* Should tolerate any other RSL messages? */
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005060) runs on ConnHdlr {
5061 timer T := 3.0;
5062 f_tx_lapdm(ts_LAPDm_I(link_id.sapi, cr_MO_CMD, p, nr, ns, l3), link_id);
5063 T.start;
5064 /* Expect RLL DATA IND on RSL side */
5065 alt {
5066 [] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
5067 setverdict(pass);
5068 }
Vadim Yanitskiye0b91a72018-10-04 15:44:40 +07005069 [exp_sacch] as_meas_res(verify_meas := false);
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005070 [] as_rsl_any_ind(exp_any);
5071 [] T.timeout {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005072 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for DATA_IND");
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005073 }
5074 }
5075}
5076
Harald Weltee613f962018-04-18 22:38:16 +02005077/* Test channel activation with A5/n right from the beginning (like in assignment + hand-over) */
5078function f_TC_chan_act_encr(charstring id) runs on ConnHdlr {
5079 f_l1_tune(L1CTL);
5080 f_est_dchan(true);
5081
5082 /* now we actually need to transmit some data both ways to check if the encryption works */
5083 var L1ctlDlMessage dl;
5084
Stefan Sperling603d98e2018-07-25 16:47:28 +02005085 var octetstring l3 := f_rnd_octstring(20);
Harald Weltee613f962018-04-18 22:38:16 +02005086 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5087
5088 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5089 f_unitdata_mt(link_id, l3);
5090
5091 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5092 f_unitdata_mo(link_id, l3);
5093
5094 /* release the channel */
5095 f_rsl_chan_deact();
5096 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5097 f_rslem_unregister(0, g_chan_nr);
5098}
5099testcase TC_chan_act_a51() runs on test_CT {
5100 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5101 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5102 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5103}
5104testcase TC_chan_act_a52() runs on test_CT {
5105 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5106 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
5107 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5108}
5109testcase TC_chan_act_a53() runs on test_CT {
5110 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5111 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
5112 f_testmatrix_each_chan(pars, refers(f_TC_chan_act_encr));
5113}
5114
Eric Wildf1827a72019-05-28 17:37:35 +02005115/* Test channel activation with A5/n right from the beginning and RSL MODE MODIFY
5116 which should break the en/decryption on purpose by supplying a new key that is unknown to the MS*/
5117function f_TC_rsl_modify_encr(charstring id) runs on ConnHdlr {
5118 f_l1_tune(L1CTL);
5119 f_est_dchan(true);
5120
5121 /* now we actually need to transmit some data both ways to check if the encryption works */
5122 var L1ctlDlMessage dl;
5123
5124 var octetstring l3 := f_rnd_octstring(20);
5125 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5126
5127 /* send UNITDATA_REQ from BTS to MS and expect it to arrive */
5128 f_unitdata_mt(link_id, l3);
5129
5130 /* Send UI frame from MS and expect it to arrive as RLL UNITDATA IND on Abis */
5131 f_unitdata_mo(link_id, l3);
5132
5133 var RSL_Message rsl;
5134 rsl := valueof(ts_RSL_MODE_MODIFY_REQ(g_chan_nr, valueof(ts_RSL_ChanMode_SIGN(false))));
5135
5136 /* modify key to break proper encryption */
5137 g_pars.encr.key := f_rnd_octstring(8);
5138 var RSL_IE ei := valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := g_pars.encr}));
5139 rsl.ies := rsl.ies & { ei };
5140 RSL.send(rsl);
5141
5142 timer T0 := 1.0;
5143 T0.start;
5144 /* Expect RSL MODIFY ACK */
5145 alt {
5146 [] RSL.receive(tr_RSL_MODE_MODIFY_ACK(g_chan_nr)) {}
5147 [] RSL.receive(tr_RSL_MODE_MODIFY_NACK(g_chan_nr, ?)) {
5148 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,"MODE MODIFY NACK");
5149 }
5150 [] T0.timeout {
5151 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for MODE MODIFY (N)ACK");
5152 }
5153 }
5154
5155 var octetstring l3msg := f_rnd_octstring(15);
5156 timer T1 := 3.0;
5157 /* Send UI frame from MS, do not expect it to arrive as RLL UNITDATA IND on Abis
5158 due to broken encryption */
5159 f_tx_lapdm(ts_LAPDm_UI(link_id.sapi, cr_MO_CMD, l3msg), link_id);
5160 T1.start;
5161 alt {
5162 [] RSL.receive(tr_RSL_UNITDATA_IND(g_chan_nr, link_id, l3msg)) {
5163 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "BTS shouldn't be able to decrypt after key change")
5164 }
5165 [] T1.timeout {
5166 setverdict(pass);
5167 }
5168 }
5169
5170 /* release the channel */
5171 f_rsl_chan_deact();
5172 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5173 f_rslem_unregister(0, g_chan_nr);
5174}
5175testcase TC_rsl_modify_encr() runs on test_CT {
5176 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5177 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5178 f_testmatrix_each_chan(pars, refers(f_TC_rsl_modify_encr));
5179}
Harald Weltee613f962018-04-18 22:38:16 +02005180
5181/* Test unencrypted channel activation followed by explicit ENCR CMD later */
5182function f_TC_encr_cmd(charstring id) runs on ConnHdlr {
5183 /* L3 payload doesn't matter, as it is passed transparently */
5184 var BIT3 l3_alg_id := f_alg_id_to_l3(g_pars.encr.alg_id);
5185 var octetstring l3 := enc_PDU_ML3_NW_MS(valueof(ts_RRM_CiphModeCmd(l3_alg_id)));
5186 var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
5187
5188 f_l1_tune(L1CTL);
5189
5190 /* first establish a dedicated channel in the clear */
5191 f_est_dchan(false);
5192
5193 /* Establish ABM */
5194 f_est_rll_mo(link_id.sapi, link_id, '23420815'O);
5195
5196 /* then send the RSL ENCR CMD with an actual RR CIPH MOD CMD inside */
5197 RSL.send(ts_RSL_ENCR_CMD(g_chan_nr, link_id, g_pars.encr.alg_id, g_pars.encr.key, l3));
5198 /* expect the L3 to arrive still unencrypted on the MS side */
5199 f_l1_exp_lapdm(tr_LAPDm_I(link_id.sapi, cr_MT_CMD, ?, ?, ?, l3));
5200
5201 /* configure L1 to apply ciphering */
5202 var uint8_t alg_id := f_alg_id_to_l1ctl(g_pars.encr.alg_id);
5203 f_L1CTL_CRYPTO_REQ(L1CTL, g_pars.chan_nr, alg_id, g_pars.encr.key);
5204
Vadim Yanitskiy4d78a702018-10-03 03:59:34 +07005205 /* send first ciphered I-frame in response and expect it on RSL */
5206 f_data_mo(link_id, true, 1, 0, '0a0b0c0d'O, exp_sacch := true);
Harald Weltee613f962018-04-18 22:38:16 +02005207
5208 /* now the BTS code should have detected the first properly encrypted uplink I-frame,
5209 * and hence enable encryption also on the downlink */
5210
5211 /* expect bi-directional communication work in encrypted mode */
5212 f_unitdata_mo(link_id, f_rnd_octstring(15));
5213 f_unitdata_mt(link_id, f_rnd_octstring(15));
5214
5215 /* release the channel */
5216 f_rsl_chan_deact();
5217 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
5218 f_rslem_unregister(0, g_chan_nr);
5219}
5220testcase TC_encr_cmd_a51() runs on test_CT {
5221 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5222 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_1, f_rnd_octstring(8)));
5223 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
5224}
5225testcase TC_encr_cmd_a52() runs on test_CT {
5226 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5227 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_2, f_rnd_octstring(8)));
5228 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
5229}
5230testcase TC_encr_cmd_a53() runs on test_CT {
5231 var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
5232 pars.encr := valueof(ts_RSL_IE_EncrInfo(RSL_ALG_ID_A5_3, f_rnd_octstring(8)));
5233 f_testmatrix_each_chan(pars, refers(f_TC_encr_cmd));
5234}
5235
5236private function f_assert_lapdm(octetstring enc, template LapdmFrame exp_match, charstring name := "") {
5237 var LapdmFrame lf;
5238 var octetstring reenc;
5239
5240 /* decode the LAPDm frame */
5241 if (ischosen(exp_match.ab)) {
5242 lf.ab := dec_LapdmFrameAB(enc);
5243 } else {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005244 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unsupported frame type");
Harald Weltee613f962018-04-18 22:38:16 +02005245 }
5246
5247 /* check if decoder result matches expectation */
5248 if (not match(lf, exp_match)) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005249 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": decoded LAPDm doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02005250 } else {
5251 log(name, ": matched");
5252 setverdict(pass);
5253 }
5254
5255 /* test if re-encoded frame equals original input */
5256 reenc := enc_LapdmFrame(lf);
5257 if (enc != reenc) {
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005258 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str(name, ": re-encoded LAPDm frame doesn't match"));
Harald Weltee613f962018-04-18 22:38:16 +02005259 } else {
5260 setverdict(pass);
5261 }
5262}
5263
5264testcase TC_lapdm_selftest() runs on test_CT {
5265 f_assert_lapdm('030301'O, tr_LAPDm_UI(0, true, ''O), "ui_s0_empty");
5266 f_assert_lapdm('0F0301'O, tr_LAPDm_UI(3, true, ''O), "ui_s3_empty");
5267 f_assert_lapdm('013F01'O, tr_LAPDm_SABM(0, false, true, ''O), "sabm_s0_empty");
5268 f_assert_lapdm('013F1123420815'O, tr_LAPDm_SABM(0, false, true, '23420815'O), "sabm_s0_l3");
5269 f_assert_lapdm('03E101'O, tr_LAPDm_RR(0, true, false, 7), "rr_s0_7");
5270 f_assert_lapdm('03000d063505'O, tr_LAPDm_I(0, true, false, 0, 0, '063505'O), "I/0/0");
5271 f_assert_lapdm('03e00d063505'O, tr_LAPDm_I(0, true, false, 7, 0, '063505'O), "I/7/0");
5272}
5273
Stefan Sperling4880be42018-08-07 18:12:59 +02005274/***********************************************************************
5275 * DTX Related (see GSM 05.08, section 8.3)
5276 ***********************************************************************/
5277
5278/* XXX These functions must be kept in sync with g_AllChannels defined on test_CT. */
5279function f_g_chan_is_tchf() runs on ConnHdlr return boolean {
5280 return (g_chan_nr == valueof(ts_RslChanNr_Bm(1)) or
5281 g_chan_nr == valueof(ts_RslChanNr_Bm(2)) or
5282 g_chan_nr == valueof(ts_RslChanNr_Bm(3)) or
5283 g_chan_nr == valueof(ts_RslChanNr_Bm(4)));
5284}
5285function f_g_chan_is_tchh() runs on ConnHdlr return boolean {
5286 return (g_chan_nr == valueof(ts_RslChanNr_Lm(5,0)) or
5287 g_chan_nr == valueof(ts_RslChanNr_Lm(5,1)));
5288}
5289function f_g_chan_is_sdcch4() runs on ConnHdlr return boolean {
5290 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,0)) or
5291 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,1)) or
5292 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,2)) or
5293 g_chan_nr == valueof(ts_RslChanNr_SDCCH4(0,3)));
5294}
5295function f_g_chan_is_sdcch8() runs on ConnHdlr return boolean {
5296 return (g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,0)) or
5297 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,1)) or
5298 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,2)) or
5299 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,3)) or
5300 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,4)) or
5301 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,5)) or
5302 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,6)) or
5303 g_chan_nr == valueof(ts_RslChanNr_SDCCH8(6,7)));
5304}
5305
5306function f_test_l2_fill_frames(boolean dtxd) runs on ConnHdlr {
5307 var L1ctlDlMessage dl;
5308 var octetstring l2_fill_frame := '0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O;
5309 var octetstring l2_fill_frame_sacch := substr(l2_fill_frame, 0, lengthof(l2_fill_frame) - 2);
5310 var GsmFrameNumber first_fn;
5311 var boolean is_first_frame := true;
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005312 var integer nfill_frames_sacch := 0;
5313 var integer nfill_frames_nonsacch := 0;
5314 var integer expected_fill_frames := 10000; /* initial value causes test failure if not overridden */
Stefan Sperling4880be42018-08-07 18:12:59 +02005315 /* Frames numbers (mod 104) for which a fill frame is expected on TCHF if DTX is enabled. */
5316 var Integers required_tdma_frames_dtx_tchf := { 52, 53, 54, 55, 56, 57, 58, 59 };
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005317 const integer frame_dtx_tchf_mod := 104;
5318 /* Frame numbers (mod 104) for which a fill frame is expected at the L1SAP level,
5319 * which operates in terms of blocks rather than frames. */
5320 var Integers required_tdma_blocks_dtx_tchf := { 52, 56 };
5321 const integer block_dtx_tchf_mod := 26;
Stefan Sperling4880be42018-08-07 18:12:59 +02005322 timer T := 5.0;
5323
5324 f_l1_tune(L1CTL);
5325 RSL.clear;
5326 L1CTL.clear;
5327
5328 /* activate TCHF signalling channel */
5329 f_est_dchan(false);
5330
5331 T.start;
5332 alt {
5333 [] L1CTL.receive(tr_L1CTL_DATA_IND(g_chan_nr, ?)) -> value dl {
5334 var GsmFrameNumber fn := dl.dl_info.frame_nr;
5335 var octetstring l2 := dl.payload.data_ind.payload;
5336
5337 if (is_first_frame) {
5338 is_first_frame := false;
5339 first_fn := dl.dl_info.frame_nr;
5340 }
5341
5342 if (dl.dl_info.link_id.c == SACCH) {
5343 l2 := substr(l2, 2, lengthof(l2) - 2); /* remove L1 header */
5344 if (not match(l2_fill_frame_sacch, l2)) {
5345 repeat;
5346 }
5347 } else if (not match(l2_fill_frame, l2)) {
5348 repeat;
5349 }
5350
5351 if (dtxd) {
5352 if (not f_g_chan_is_tchf()) {
5353 T.stop;
5354 f_rsl_chan_deact();
5355 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005356 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received fill frame on non-TCH/F channel; DTX is only allowed on TCH/F!");
Stefan Sperling4880be42018-08-07 18:12:59 +02005357 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005358 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005359 T.stop;
5360 f_rsl_chan_deact();
5361 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005362
5363 /* With DTX enabled we can expect at least 3 fill frames for every 104 frames.
5364 * 2 SACCH, 1 TCH/F */
5365 expected_fill_frames := 3;
5366
5367 if (nfill_frames_sacch + nfill_frames_nonsacch < expected_fill_frames) {
5368 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
5369 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005370 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02005371 } else {
5372 setverdict(pass);
5373 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005374 } else {
5375 if (dl.dl_info.link_id.c == SACCH) {
5376 nfill_frames_sacch := nfill_frames_sacch + 1;
Stefan Sperling4880be42018-08-07 18:12:59 +02005377 repeat;
5378 }
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005379 /* On DTX TCH/F channels, fill frames occur only for specific frame numbers mod 104.
5380 * Furthermore, the L1SAP layer gives us frame numbers for the start of a block so
5381 * we should only see the subset of frames numbers which correspond to a block boundary.
5382 * TCH/F blocks are defined to start at 0,4,8,13,17,21 (modulo 26) */
5383 for (var integer i := 0; i < lengthof(required_tdma_blocks_dtx_tchf); i := i + 1) {
5384 if (fn mod frame_dtx_tchf_mod == required_tdma_blocks_dtx_tchf[i]) {
5385 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
5386 repeat;
5387 }
5388 }
5389 log("Received DTX TCH fill frame with bad frame number: ", fn,
5390 " (mod ", frame_dtx_tchf_mod, ": ", fn mod frame_dtx_tchf_mod, ")",
5391 " (mod ", block_dtx_tchf_mod, ": ", fn mod block_dtx_tchf_mod, ")");
5392 f_rsl_chan_deact();
5393 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005394 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected L2 fill frame received on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02005395 }
Stefan Sperling4880be42018-08-07 18:12:59 +02005396 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005397 if (dl.dl_info.link_id.c == SACCH) {
5398 nfill_frames_sacch := nfill_frames_sacch + 1;
5399 } else {
5400 nfill_frames_nonsacch := nfill_frames_nonsacch + 1;
5401 }
5402 if (fn > first_fn + frame_dtx_tchf_mod) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005403 T.stop;
5404 if (f_g_chan_is_tchf()) {
5405 /* Without DTX we can expect 25 fill frames for every 104 frames.
5406 * (24 FACCH + 1 SACCH filling) */
5407 expected_fill_frames := 25;
5408 } else if (f_g_chan_is_tchh()) {
5409 /* We can expect 2 fill frames for every 104 frames. */
5410 expected_fill_frames := 2;
5411 } else if (f_g_chan_is_sdcch4() or f_g_chan_is_sdcch8()) {
5412 /* We can expect 5 fill frames for every 104 frames. */
5413 expected_fill_frames := 5;
5414 } else {
5415 f_rsl_chan_deact();
5416 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005417 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown channel type");
Stefan Sperling4880be42018-08-07 18:12:59 +02005418 }
5419
5420 f_rsl_chan_deact();
5421 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005422
5423 if (nfill_frames_sacch + nfill_frames_nonsacch >= expected_fill_frames) {
Stefan Sperling4880be42018-08-07 18:12:59 +02005424 setverdict(pass);
5425 } else {
Stefan Sperling91d4c9d2018-08-09 20:03:08 +02005426 log("received only ", nfill_frames_sacch, "+", nfill_frames_nonsacch,
5427 " (SACCH+other) out of ", expected_fill_frames, " expected fill frames");
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not enough fill frames received");
Stefan Sperling4880be42018-08-07 18:12:59 +02005429 }
5430 } else {
5431 repeat;
5432 }
5433 }
5434 }
5435 [] L1CTL.receive { repeat; }
5436 [] T.timeout {
5437 f_rsl_chan_deact();
5438 f_L1CTL_DM_REL_REQ(L1CTL, g_chan_nr);
Daniel Willmann0fcc4d32018-10-23 20:32:19 +02005439 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for L2 fill frames on Um");
Stefan Sperling4880be42018-08-07 18:12:59 +02005440 }
5441 }
5442}
5443
5444function f_TC_tch_sign_l2_fill_frame(charstring id) runs on ConnHdlr {
5445 f_test_l2_fill_frames(false);
5446}
5447
5448function f_TC_tch_sign_l2_fill_frame_dtxd(charstring id) runs on ConnHdlr {
5449 f_test_l2_fill_frames(true);
5450}
5451
5452function f_tch_sign_l2_fill_frame(boolean dtxd) runs on test_CT {
5453 var ConnHdlr vc_conn;
5454 var ConnHdlrPars pars;
5455 pars.t_guard := 60.0;
Harald Welte10474062019-05-30 16:48:17 +02005456 f_init();
Stefan Sperling4880be42018-08-07 18:12:59 +02005457 for (var integer i := 0; i < sizeof(g_AllChannels); i := i + 1) {
5458 pars := valueof(t_Pars(g_AllChannels[i], ts_RSL_ChanMode_SIGN(dtxd)));
5459 if (dtxd) {
5460 if (i >= 4) { /* DTX is only allowed on TCH/F */
5461 break;
5462 }
5463 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame_dtxd), pars);
5464 } else {
5465 vc_conn := f_start_handler(refers(f_TC_tch_sign_l2_fill_frame), pars);
5466 }
5467 vc_conn.done;
5468 }
5469}
5470
5471/* Verify that L2 fill frames are sent on TCH in signaling mode if
5472 * there is nothing to transmit while DTX is disabled on downlink. */
5473testcase TC_tch_sign_l2_fill_frame() runs on test_CT {
5474 f_tch_sign_l2_fill_frame(false);
5475}
5476
5477/* Verify that particular L2 fill frames are sent on TCH in signaling mode if
5478 * there is nothing to transmit while DTX is enabled on downlink. */
5479testcase TC_tch_sign_l2_fill_frame_dtxd() runs on test_CT {
5480 f_tch_sign_l2_fill_frame(true);
5481}
Harald Welte0472ab42018-03-12 15:02:26 +01005482
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005483testcase TC_chopped_ipa_ping() runs on test_CT {
5484 IPA_Testing.f_run_TC_chopped_ipa_ping(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
5485}
5486
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005487testcase TC_chopped_ipa_payload() runs on test_CT {
5488 IPA_Testing.f_run_TC_chopped_ipa_payload(mp_rsl_ip, mp_rsl_port, LISTEN_FOR_CLIENT);
5489}
5490
Harald Welte0472ab42018-03-12 15:02:26 +01005491/* test generation of RLL ERR IND based on Um errors (TS 48.058 3.9) */
5492/* protocol error as per 44.006 */
5493/* link layer failure (repetition of I-frame N200 times without ACK */
5494/* repetition of SABM or DISC N200 times without ACK */
5495/* receptiom of SABM in multi-frame established state */
5496
5497
Harald Welte68e495b2018-02-25 00:05:57 +01005498/* TODO Areas:
5499
5500* channel activation
5501** with BS_Power / MS_Power, bypassing power control loop
5502** on primary vs. secondary TRX
Harald Welte68e495b2018-02-25 00:05:57 +01005503** with timing advance from initial activation on
5504* mode modify
5505** encryption
5506** multirate
5507* check DEACTIVATE SACCH
Harald Welte68e495b2018-02-25 00:05:57 +01005508** unsupported algorithm
5509* handover detection
Harald Welte68e495b2018-02-25 00:05:57 +01005510* BS Power Control
5511* Physical Context
Harald Welte68e495b2018-02-25 00:05:57 +01005512* RF resource ind
Harald Welte68e495b2018-02-25 00:05:57 +01005513* error handling
Harald Welte68e495b2018-02-25 00:05:57 +01005514** IE duplicated?
Harald Welte883340c2018-02-28 18:59:29 +01005515* PCU interface
Harald Welte883340c2018-02-28 18:59:29 +01005516** DATA_IND from BTS->PCU
5517** verification of PCU-originated DATA_REQ arrival on Um/MS side
Harald Welte68e495b2018-02-25 00:05:57 +01005518
5519*/
Harald Welte70767382018-02-21 12:16:40 +01005520
5521control {
5522 execute( TC_chan_act_stress() );
5523 execute( TC_chan_act_react() );
5524 execute( TC_chan_deact_not_active() );
5525 execute( TC_chan_act_wrong_nr() );
Harald Welte629cc6b2018-03-11 17:19:05 +01005526 execute( TC_deact_sacch() );
Harald Welteea17b912018-03-11 22:29:31 +01005527 execute( TC_sacch_filling() );
5528 execute( TC_sacch_info_mod() );
Harald Welte075d84c2018-03-12 13:07:24 +01005529 execute( TC_sacch_multi() );
Harald Welte55700662018-03-12 13:15:43 +01005530 execute( TC_sacch_multi_chg() );
Harald Weltec8d363c2019-05-19 20:36:48 +02005531 execute( TC_sacch_chan_act() );
Harald Welte8b01c792019-05-19 22:51:25 +02005532 execute( TC_sacch_chan_act_ho_async() );
5533 execute( TC_sacch_chan_act_ho_sync() );
Harald Welte8c24c2b2018-02-26 08:31:31 +01005534 execute( TC_rach_content() );
5535 execute( TC_rach_count() );
Harald Welte54a2a2d2018-02-26 09:14:05 +01005536 execute( TC_rach_max_ta() );
Vadim Yanitskiy7c2c10c2019-05-31 20:42:01 +07005537 execute( TC_ho_rach() );
Harald Welte3453ab42019-05-24 21:19:58 +02005538 execute( TC_rach_load_idle_thresh0() );
5539 execute( TC_rach_load_idle_below_thresh() );
5540 execute( TC_rach_load_count() );
Harald Welte70767382018-02-21 12:16:40 +01005541 execute( TC_meas_res_sign_tchf() );
5542 execute( TC_meas_res_sign_tchh() );
5543 execute( TC_meas_res_sign_sdcch4() );
5544 execute( TC_meas_res_sign_sdcch8() );
Harald Welte685d5982018-02-27 20:42:05 +01005545 execute( TC_meas_res_sign_tchh_toa256() );
Philipp Maier4d1e9c92018-12-20 11:11:56 +01005546 execute( TC_rsl_ms_pwr_ctrl() );
Eric Wilde57e1a62019-05-28 13:30:55 +02005547 execute( TC_rsl_chan_initial_ms_pwr() );
Eric Wild6833cc92019-05-23 19:34:44 +02005548 execute( TC_rsl_chan_initial_ta() );
Eric Wildf1827a72019-05-28 17:37:35 +02005549 execute( TC_rsl_modify_encr() );
Harald Welte70767382018-02-21 12:16:40 +01005550 execute( TC_conn_fail_crit() );
Harald Welte68e495b2018-02-25 00:05:57 +01005551 execute( TC_paging_imsi_80percent() );
5552 execute( TC_paging_tmsi_80percent() );
5553 execute( TC_paging_imsi_200percent() );
5554 execute( TC_paging_tmsi_200percent() );
Harald Welte01d982c2018-02-25 01:31:40 +01005555 execute( TC_rsl_protocol_error() );
5556 execute( TC_rsl_mand_ie_error() );
5557 execute( TC_rsl_ie_content_error() );
Harald Welte48494ca2018-02-25 16:59:50 +01005558 execute( TC_si_sched_default() );
Harald Welte0cae4552018-03-09 22:20:26 +01005559 execute( TC_si_sched_1() );
Harald Welte48494ca2018-02-25 16:59:50 +01005560 execute( TC_si_sched_2bis() );
5561 execute( TC_si_sched_2ter() );
5562 execute( TC_si_sched_2ter_2bis() );
5563 execute( TC_si_sched_2quater() );
5564 execute( TC_si_sched_13() );
5565 execute( TC_si_sched_13_2bis_2ter_2quater() );
Harald Weltea871a382018-02-25 02:03:14 +01005566 execute( TC_ipa_dlcx_not_active() );
Harald Weltea3f1df92018-02-25 12:49:55 +01005567 execute( TC_ipa_crcx_twice_not_active() );
5568 execute( TC_ipa_crcx_mdcx_dlcx_not_active() );
Harald Welte3ae11da2018-02-25 13:36:06 +01005569 execute( TC_ipa_crcx_mdcx_mdcx_dlcx_not_active() );
Harald Welte9912eb52018-02-25 13:30:15 +01005570 execute( TC_ipa_crcx_sdcch_not_active() );
Harald Welte883340c2018-02-28 18:59:29 +01005571
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005572 if (mp_pcu_socket != "") {
5573 execute( TC_pcu_act_req() );
5574 execute( TC_pcu_act_req_wrong_ts() );
5575 execute( TC_pcu_act_req_wrong_bts() );
5576 execute( TC_pcu_act_req_wrong_trx() );
5577 execute( TC_pcu_deact_req() );
5578 execute( TC_pcu_deact_req_wrong_ts() );
5579 execute( TC_pcu_ver_si13() );
Harald Weltead033dc2019-05-25 17:28:16 +02005580 if (mp_l1_supports_gprs) {
5581 execute( TC_pcu_data_req_pdtch() );
5582 execute( TC_pcu_data_req_ptcch() );
Harald Welte7162a612019-05-26 12:56:09 +02005583 execute( TC_pcu_data_req_wrong_bts() );
5584 execute( TC_pcu_data_req_wrong_trx() );
5585 execute( TC_pcu_data_req_wrong_ts() );
5586 execute( TC_pcu_data_req_ts_inactive() );
Harald Weltead033dc2019-05-25 17:28:16 +02005587 }
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005588 execute( TC_pcu_data_req_agch() );
Harald Welte928622b2019-05-26 13:22:59 +02005589 execute( TC_pcu_data_req_pch() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005590 execute( TC_pcu_data_req_imm_ass_pch() );
5591 execute( TC_pcu_rach_content() );
Vadim Yanitskiy51cbc102019-04-22 06:37:30 +07005592 execute( TC_pcu_ext_rach_content() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005593 execute( TC_pcu_paging_from_rsl() );
Harald Welted66c9b82019-05-25 09:03:15 +02005594 execute( TC_pcu_time_ind() );
Harald Welte4832c862019-05-25 14:57:18 +02005595 execute( TC_pcu_rts_req() );
Harald Welte07bd2d22019-05-25 11:03:30 +02005596 execute( TC_pcu_oml_alert() );
Harald Welteeaa9a862019-05-26 23:01:08 +02005597 execute( TC_pcu_rr_suspend() );
Harald Weltea2e0e942019-05-27 18:12:53 +02005598 execute( TC_pcu_socket_connect_multi() );
Harald Weltec8effb72019-05-27 18:23:04 +02005599 execute( TC_pcu_socket_reconnect() );
Harald Weltebe030482019-05-27 22:29:35 +02005600 execute( TC_pcu_socket_noconnect_nosi3gprs() );
5601 execute( TC_pcu_socket_connect_si3gprs() );
5602 execute( TC_pcu_socket_disconnect_nosi3gprs() );
Pau Espin Pedrola14a8af2018-11-20 13:12:22 +01005603 } else {
5604 log("PCU socket path not available, skipping PCU tests");
5605 }
Harald Welte3d04ae62018-04-04 20:29:05 +02005606
5607 execute( TC_dyn_osmo_pdch_act_deact() );
5608 execute( TC_dyn_osmo_pdch_unsol_deact() );
5609 execute( TC_dyn_osmo_pdch_double_act() );
5610 execute( TC_dyn_osmo_pdch_tchf_act() );
5611 execute( TC_dyn_osmo_pdch_tchh_act() );
Harald Welte9bbbfb52018-04-05 09:33:19 +02005612 execute( TC_dyn_ipa_pdch_act_deact() );
5613 execute( TC_dyn_ipa_pdch_tchf_act() );
5614 execute( TC_dyn_ipa_pdch_tchf_act_pdch_act_nack() );
5615 execute( TC_dyn_ipa_pdch_act_tchf_act_nack() );
Harald Welte0472ab42018-03-12 15:02:26 +01005616
5617 execute( TC_rll_est_ind() );
5618 execute( TC_rll_est_req_DCCH_3() );
5619 execute( TC_rll_est_req_ACCH_3() );
5620 execute( TC_rll_rel_ind_DCCH_0() );
5621 execute( TC_rll_rel_ind_DCCH_3() );
5622 execute( TC_rll_rel_ind_ACCH_0() );
5623 execute( TC_rll_rel_ind_ACCH_3() );
5624 execute( TC_rll_rel_req() );
5625 execute( TC_rll_unit_data_req_DCCH() );
5626 execute( TC_rll_unit_data_req_ACCH() );
5627 execute( TC_rll_unit_data_ind_DCCH() );
5628 execute( TC_rll_unit_data_ind_ACCH() );
Harald Weltee613f962018-04-18 22:38:16 +02005629
5630 execute( TC_chan_act_a51() );
5631 execute( TC_chan_act_a52() );
5632 execute( TC_chan_act_a53() );
5633 execute( TC_encr_cmd_a51() );
5634 execute( TC_encr_cmd_a52() );
5635 execute( TC_encr_cmd_a53() );
5636
Harald Welteee25aae2019-05-19 14:32:37 +02005637 execute( TC_err_rep_wrong_mdisc() );
5638 execute( TC_err_rep_wrong_msg_type() );
5639 execute( TC_err_rep_wrong_sequence() );
5640
Harald Weltee613f962018-04-18 22:38:16 +02005641 execute( TC_lapdm_selftest() );
Stefan Sperling4880be42018-08-07 18:12:59 +02005642
5643 execute( TC_tch_sign_l2_fill_frame() );
5644 execute( TC_tch_sign_l2_fill_frame_dtxd() );
Stefan Sperling0ec1c262018-10-15 15:12:52 +02005645
5646 execute( TC_chopped_ipa_ping() );
Stefan Sperlingaa1e60f2018-10-15 16:34:07 +02005647 execute( TC_chopped_ipa_payload() );
Harald Welte70767382018-02-21 12:16:40 +01005648}
5649
5650
5651}